Annotation of loncom/interface/domainprefs.pm, revision 1.270
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.270 ! raeburn 4: # $Id: domainprefs.pm,v 1.269 2016/02/19 02:39:07 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.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.216 raeburn 1727: @usertools = ('official','unofficial','community','textbook');
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);
2179: my @crstypes = ('official','unofficial','community','textbook');
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.216 raeburn 3406: my @types = ('official','unofficial','community','textbook');
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;
3540: my @types = ('official','unofficial','community','textbook');
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.86 raeburn 4559: );
1.72 raeburn 4560: return %titles;
4561: }
4562:
1.101 raeburn 4563: sub courserequest_titles {
4564: my %titles = &Apache::lonlocal::texthash (
4565: official => 'Official',
4566: unofficial => 'Unofficial',
4567: community => 'Communities',
1.216 raeburn 4568: textbook => 'Textbook',
1.101 raeburn 4569: norequest => 'Not allowed',
1.104 raeburn 4570: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4571: validate => 'With validation',
4572: autolimit => 'Numerical limit',
1.103 raeburn 4573: unlimited => '(blank for unlimited)',
1.101 raeburn 4574: );
4575: return %titles;
4576: }
4577:
1.163 raeburn 4578: sub authorrequest_titles {
4579: my %titles = &Apache::lonlocal::texthash (
4580: norequest => 'Not allowed',
4581: approval => 'Approval by Dom. Coord.',
4582: automatic => 'Automatic approval',
4583: );
4584: return %titles;
1.210 raeburn 4585: }
1.163 raeburn 4586:
1.101 raeburn 4587: sub courserequest_conditions {
4588: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4589: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4590: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4591: );
4592: return %conditions;
4593: }
4594:
4595:
1.27 raeburn 4596: sub print_usercreation {
1.30 raeburn 4597: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4598: my $numinrow = 4;
1.28 raeburn 4599: my $datatable;
4600: if ($position eq 'top') {
1.30 raeburn 4601: $$rowtotal ++;
1.34 raeburn 4602: my $rowcount = 0;
1.32 raeburn 4603: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4604: if (ref($rules) eq 'HASH') {
4605: if (keys(%{$rules}) > 0) {
1.32 raeburn 4606: $datatable .= &user_formats_row('username',$settings,$rules,
4607: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4608: $$rowtotal ++;
1.32 raeburn 4609: $rowcount ++;
4610: }
4611: }
4612: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4613: if (ref($idrules) eq 'HASH') {
4614: if (keys(%{$idrules}) > 0) {
4615: $datatable .= &user_formats_row('id',$settings,$idrules,
4616: $idruleorder,$numinrow,$rowcount);
4617: $$rowtotal ++;
4618: $rowcount ++;
1.28 raeburn 4619: }
4620: }
1.39 raeburn 4621: if ($rowcount == 0) {
4622: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4623: $$rowtotal ++;
4624: $rowcount ++;
4625: }
1.34 raeburn 4626: } elsif ($position eq 'middle') {
1.224 raeburn 4627: my @creators = ('author','course','requestcrs');
1.37 raeburn 4628: my ($rules,$ruleorder) =
4629: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4630: my %lt = &usercreation_types();
4631: my %checked;
4632: if (ref($settings) eq 'HASH') {
4633: if (ref($settings->{'cancreate'}) eq 'HASH') {
4634: foreach my $item (@creators) {
4635: $checked{$item} = $settings->{'cancreate'}{$item};
4636: }
4637: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4638: foreach my $item (@creators) {
4639: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4640: $checked{$item} = 'none';
4641: }
4642: }
4643: }
4644: }
4645: my $rownum = 0;
4646: foreach my $item (@creators) {
4647: $rownum ++;
1.224 raeburn 4648: if ($checked{$item} eq '') {
4649: $checked{$item} = 'any';
1.34 raeburn 4650: }
4651: my $css_class;
4652: if ($rownum%2) {
4653: $css_class = '';
4654: } else {
4655: $css_class = ' class="LC_odd_row" ';
4656: }
4657: $datatable .= '<tr'.$css_class.'>'.
4658: '<td><span class="LC_nobreak">'.$lt{$item}.
4659: '</span></td><td align="right">';
1.224 raeburn 4660: my @options = ('any');
4661: if (ref($rules) eq 'HASH') {
4662: if (keys(%{$rules}) > 0) {
4663: push(@options,('official','unofficial'));
1.37 raeburn 4664: }
4665: }
1.224 raeburn 4666: push(@options,'none');
1.37 raeburn 4667: foreach my $option (@options) {
1.50 raeburn 4668: my $type = 'radio';
1.34 raeburn 4669: my $check = ' ';
1.224 raeburn 4670: if ($checked{$item} eq $option) {
4671: $check = ' checked="checked" ';
1.34 raeburn 4672: }
4673: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4674: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4675: $item.'" value="'.$option.'"'.$check.'/> '.
4676: $lt{$option}.'</label> </span>';
4677: }
4678: $datatable .= '</td></tr>';
4679: }
1.28 raeburn 4680: } else {
4681: my @contexts = ('author','course','domain');
4682: my @authtypes = ('int','krb4','krb5','loc');
4683: my %checked;
4684: if (ref($settings) eq 'HASH') {
4685: if (ref($settings->{'authtypes'}) eq 'HASH') {
4686: foreach my $item (@contexts) {
4687: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4688: foreach my $auth (@authtypes) {
4689: if ($settings->{'authtypes'}{$item}{$auth}) {
4690: $checked{$item}{$auth} = ' checked="checked" ';
4691: }
4692: }
4693: }
4694: }
1.27 raeburn 4695: }
1.35 raeburn 4696: } else {
4697: foreach my $item (@contexts) {
1.36 raeburn 4698: foreach my $auth (@authtypes) {
1.35 raeburn 4699: $checked{$item}{$auth} = ' checked="checked" ';
4700: }
4701: }
1.27 raeburn 4702: }
1.28 raeburn 4703: my %title = &context_names();
4704: my %authname = &authtype_names();
4705: my $rownum = 0;
4706: my $css_class;
4707: foreach my $item (@contexts) {
4708: if ($rownum%2) {
4709: $css_class = '';
4710: } else {
4711: $css_class = ' class="LC_odd_row" ';
4712: }
1.30 raeburn 4713: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4714: '<td>'.$title{$item}.
4715: '</td><td class="LC_left_item">'.
4716: '<span class="LC_nobreak">';
4717: foreach my $auth (@authtypes) {
4718: $datatable .= '<label>'.
4719: '<input type="checkbox" name="'.$item.'_auth" '.
4720: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4721: $authname{$auth}.'</label> ';
4722: }
4723: $datatable .= '</span></td></tr>';
4724: $rownum ++;
1.27 raeburn 4725: }
1.30 raeburn 4726: $$rowtotal += $rownum;
1.27 raeburn 4727: }
4728: return $datatable;
4729: }
4730:
1.224 raeburn 4731: sub print_selfcreation {
4732: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4733: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4734: if (ref($settings) eq 'HASH') {
4735: if (ref($settings->{'cancreate'}) eq 'HASH') {
4736: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4737: if (ref($createsettings) eq 'HASH') {
4738: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4739: @selfcreate = @{$createsettings->{'selfcreate'}};
4740: } elsif ($createsettings->{'selfcreate'} ne '') {
4741: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4742: @selfcreate = ('email','login','sso');
4743: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4744: @selfcreate = ($createsettings->{'selfcreate'});
4745: }
4746: }
4747: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4748: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4749: }
4750: }
4751: }
4752: }
4753: my %radiohash;
4754: my $numinrow = 4;
4755: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4756: if ($position eq 'top') {
4757: my %choices = &Apache::lonlocal::texthash (
4758: cancreate_login => 'Institutional Login',
4759: cancreate_sso => 'Institutional Single Sign On',
4760: );
4761: my @toggles = sort(keys(%choices));
4762: my %defaultchecked = (
4763: 'cancreate_login' => 'off',
4764: 'cancreate_sso' => 'off',
4765: );
1.228 raeburn 4766: my ($onclick,$itemcount);
1.224 raeburn 4767: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4768: \%choices,$itemcount,$onclick);
1.228 raeburn 4769: $$rowtotal += $itemcount;
4770:
1.224 raeburn 4771: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4772:
4773: if (ref($usertypes) eq 'HASH') {
4774: if (keys(%{$usertypes}) > 0) {
4775: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4776: $dom,$numinrow,$othertitle,
1.228 raeburn 4777: 'statustocreate',$$rowtotal);
1.224 raeburn 4778: $$rowtotal ++;
4779: }
4780: }
1.240 raeburn 4781: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4782: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4783: $fieldtitles{'inststatus'} = &mt('Institutional status');
4784: my $rem;
4785: my $numperrow = 2;
4786: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4787: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4788: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4789: '<td class="LC_left_item">'."\n".
4790: '<table><tr><td>'."\n";
4791: for (my $i=0; $i<@fields; $i++) {
4792: $rem = $i%($numperrow);
4793: if ($rem == 0) {
4794: if ($i > 0) {
4795: $datatable .= '</tr>';
4796: }
4797: $datatable .= '<tr>';
4798: }
4799: my $currval;
1.248 raeburn 4800: if (ref($createsettings) eq 'HASH') {
4801: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4802: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4803: }
1.240 raeburn 4804: }
4805: $datatable .= '<td class="LC_left_item">'.
4806: '<span class="LC_nobreak">'.
4807: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4808: 'value="'.$currval.'" size="10" /> '.
4809: $fieldtitles{$fields[$i]}.'</span></td>';
4810: }
4811: my $colsleft = $numperrow - $rem;
4812: if ($colsleft > 1 ) {
4813: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4814: ' </td>';
4815: } elsif ($colsleft == 1) {
4816: $datatable .= '<td class="LC_left_item"> </td>';
4817: }
4818: $datatable .= '</tr></table></td></tr>';
4819: $$rowtotal ++;
1.224 raeburn 4820: } elsif ($position eq 'middle') {
4821: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4822: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4823: $usertypes->{'default'} = $othertitle;
4824: if (ref($types) eq 'ARRAY') {
4825: push(@{$types},'default');
4826: $usertypes->{'default'} = $othertitle;
4827: foreach my $status (@{$types}) {
4828: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4829: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4830: $$rowtotal ++;
1.224 raeburn 4831: }
4832: }
4833: } else {
1.236 raeburn 4834: my %choices = &Apache::lonlocal::texthash (
4835: cancreate_email => 'E-mail address as username',
4836: );
4837: my @toggles = sort(keys(%choices));
4838: my %defaultchecked = (
4839: 'cancreate_email' => 'off',
4840: );
4841: my $itemcount = 0;
4842: my $display = 'none';
4843: if (grep(/^\Qemail\E$/,@selfcreate)) {
4844: $display = 'block';
4845: }
4846: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4847: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4848: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4849: my $usertypes = {};
4850: my $order = [];
4851: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4852: $usertypes = $domdefaults{'inststatustypes'};
4853: $order = $domdefaults{'inststatusguest'};
4854: }
4855: if (ref($order) eq 'ARRAY') {
4856: push(@{$order},'default');
4857: if (@{$order} > 1) {
4858: $usertypes->{'default'} = &mt('Other users');
4859: $additional .= '<table><tr>';
4860: foreach my $status (@{$order}) {
4861: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4862: }
4863: $additional .= '</tr><tr>';
4864: foreach my $status (@{$order}) {
4865: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4866: }
1.236 raeburn 4867: $additional .= '</tr></table>';
1.224 raeburn 4868: } else {
1.236 raeburn 4869: $usertypes->{'default'} = &mt('All users');
4870: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4871: }
4872: }
1.236 raeburn 4873: $additional .= '</div>'."\n";
4874:
4875: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4876: \%choices,$$rowtotal,$onclick,$additional);
4877: $$rowtotal ++;
1.236 raeburn 4878: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4879: $$rowtotal ++;
1.224 raeburn 4880: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4881: $numinrow = 1;
1.236 raeburn 4882: if (ref($order) eq 'ARRAY') {
4883: foreach my $status (@{$order}) {
1.228 raeburn 4884: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4885: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4886: $$rowtotal ++;
4887: }
4888: }
1.224 raeburn 4889: my ($emailrules,$emailruleorder) =
4890: &Apache::lonnet::inst_userrules($dom,'email');
4891: if (ref($emailrules) eq 'HASH') {
4892: if (keys(%{$emailrules}) > 0) {
4893: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4894: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4895: $$rowtotal ++;
4896: }
4897: }
1.228 raeburn 4898: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4899: }
4900: return $datatable;
4901: }
4902:
1.236 raeburn 4903: sub email_as_username {
4904: my ($rowtotal,$processing,$type) = @_;
4905: my %choices =
4906: &Apache::lonlocal::texthash (
4907: automatic => 'Automatic approval',
4908: approval => 'Queued for approval',
4909: );
4910: my $output;
4911: foreach my $option ('automatic','approval') {
4912: my $checked;
4913: if (ref($processing) eq 'HASH') {
4914: if ($type eq '') {
4915: if (!exists($processing->{'default'})) {
4916: if ($option eq 'automatic') {
4917: $checked = ' checked="checked"';
4918: }
4919: } else {
4920: if ($processing->{'default'} eq $option) {
4921: $checked = ' checked="checked"';
4922: }
4923: }
4924: } else {
4925: if (!exists($processing->{$type})) {
4926: if ($option eq 'automatic') {
4927: $checked = ' checked="checked"';
4928: }
4929: } else {
4930: if ($processing->{$type} eq $option) {
4931: $checked = ' checked="checked"';
4932: }
4933: }
4934: }
4935: } elsif ($option eq 'automatic') {
4936: $checked = ' checked="checked"';
4937: }
4938: my $name = 'cancreate_emailprocess';
4939: if (($type ne '') && ($type ne 'default')) {
4940: $name .= '_'.$type;
4941: }
4942: $output .= '<span class="LC_nobreak"><label>'.
4943: '<input type="radio" name="'.$name.'"'.
4944: $checked.' value="'.$option.'" />'.
4945: $choices{$option}.'</label></span>';
4946: if ($type eq '') {
4947: $output .= ' ';
4948: } else {
4949: $output .= '<br />';
4950: }
4951: }
4952: $$rowtotal ++;
4953: return $output;
4954: }
4955:
1.165 raeburn 4956: sub captcha_choice {
1.169 raeburn 4957: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 4958: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4959: $vertext,$currver);
1.165 raeburn 4960: my %lt = &captcha_phrases();
4961: $keyentry = 'hidden';
4962: if ($context eq 'cancreate') {
1.224 raeburn 4963: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4964: } elsif ($context eq 'login') {
4965: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4966: }
4967: if (ref($settings) eq 'HASH') {
4968: if ($settings->{'captcha'}) {
4969: $checked{$settings->{'captcha'}} = ' checked="checked"';
4970: } else {
4971: $checked{'original'} = ' checked="checked"';
4972: }
4973: if ($settings->{'captcha'} eq 'recaptcha') {
4974: $pubtext = $lt{'pub'};
4975: $privtext = $lt{'priv'};
4976: $keyentry = 'text';
1.269 raeburn 4977: $vertext = $lt{'ver'};
4978: $currver = $settings->{'recaptchaversion'};
4979: if ($currver ne '2') {
4980: $currver = 1;
4981: }
1.165 raeburn 4982: }
4983: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4984: $currpub = $settings->{'recaptchakeys'}{'public'};
4985: $currpriv = $settings->{'recaptchakeys'}{'private'};
4986: }
4987: } else {
4988: $checked{'original'} = ' checked="checked"';
4989: }
1.169 raeburn 4990: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4991: my $output = '<tr'.$css_class.'>'.
4992: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4993: '<table><tr><td>'."\n";
4994: foreach my $option ('original','recaptcha','notused') {
4995: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4996: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4997: $lt{$option}.'</label></span>';
4998: unless ($option eq 'notused') {
4999: $output .= (' 'x2)."\n";
5000: }
5001: }
5002: #
5003: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5004: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5005: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5006: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5007: #
1.165 raeburn 5008: $output .= '</td></tr>'."\n".
5009: '<tr><td>'."\n".
5010: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5011: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5012: $currpub.'" size="40" /></span><br />'."\n".
5013: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5014: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5015: $currpriv.'" size="40" /></span><br />'.
5016: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5017: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5018: $currver.'" size="3" /></span><br />'.
5019: '</td></tr></table>'."\n".
1.165 raeburn 5020: '</td></tr>';
5021: return $output;
5022: }
5023:
1.32 raeburn 5024: sub user_formats_row {
5025: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5026: my $output;
5027: my %text = (
5028: 'username' => 'new usernames',
5029: 'id' => 'IDs',
1.45 raeburn 5030: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5031: );
5032: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5033: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5034: '<td><span class="LC_nobreak">';
5035: if ($type eq 'email') {
5036: $output .= &mt("Formats disallowed for $text{$type}: ");
5037: } else {
5038: $output .= &mt("Format rules to check for $text{$type}: ");
5039: }
5040: $output .= '</span></td>'.
5041: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5042: my $rem;
5043: if (ref($ruleorder) eq 'ARRAY') {
5044: for (my $i=0; $i<@{$ruleorder}; $i++) {
5045: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5046: my $rem = $i%($numinrow);
5047: if ($rem == 0) {
5048: if ($i > 0) {
5049: $output .= '</tr>';
5050: }
5051: $output .= '<tr>';
5052: }
5053: my $check = ' ';
1.39 raeburn 5054: if (ref($settings) eq 'HASH') {
5055: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5056: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5057: $check = ' checked="checked" ';
5058: }
1.27 raeburn 5059: }
5060: }
5061: $output .= '<td class="LC_left_item">'.
5062: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5063: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5064: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5065: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5066: }
5067: }
5068: $rem = @{$ruleorder}%($numinrow);
5069: }
5070: my $colsleft = $numinrow - $rem;
5071: if ($colsleft > 1 ) {
5072: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5073: ' </td>';
5074: } elsif ($colsleft == 1) {
5075: $output .= '<td class="LC_left_item"> </td>';
5076: }
5077: $output .= '</tr></table></td></tr>';
5078: return $output;
5079: }
5080:
1.34 raeburn 5081: sub usercreation_types {
5082: my %lt = &Apache::lonlocal::texthash (
5083: author => 'When adding a co-author',
5084: course => 'When adding a user to a course',
1.100 raeburn 5085: requestcrs => 'When requesting a course',
1.34 raeburn 5086: any => 'Any',
5087: official => 'Institutional only ',
5088: unofficial => 'Non-institutional only',
5089: none => 'None',
5090: );
5091: return %lt;
1.48 raeburn 5092: }
1.34 raeburn 5093:
1.224 raeburn 5094: sub selfcreation_types {
5095: my %lt = &Apache::lonlocal::texthash (
5096: selfcreate => 'User creates own account',
5097: any => 'Any',
5098: official => 'Institutional only ',
5099: unofficial => 'Non-institutional only',
5100: email => 'E-mail address',
5101: login => 'Institutional Login',
5102: sso => 'SSO',
5103: );
5104: }
5105:
1.28 raeburn 5106: sub authtype_names {
5107: my %lt = &Apache::lonlocal::texthash(
5108: int => 'Internal',
5109: krb4 => 'Kerberos 4',
5110: krb5 => 'Kerberos 5',
5111: loc => 'Local',
5112: );
5113: return %lt;
5114: }
5115:
5116: sub context_names {
5117: my %context_title = &Apache::lonlocal::texthash(
5118: author => 'Creating users when an Author',
5119: course => 'Creating users when in a course',
5120: domain => 'Creating users when a Domain Coordinator',
5121: );
5122: return %context_title;
5123: }
5124:
1.33 raeburn 5125: sub print_usermodification {
5126: my ($position,$dom,$settings,$rowtotal) = @_;
5127: my $numinrow = 4;
5128: my ($context,$datatable,$rowcount);
5129: if ($position eq 'top') {
5130: $rowcount = 0;
5131: $context = 'author';
5132: foreach my $role ('ca','aa') {
5133: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5134: $numinrow,$rowcount);
5135: $$rowtotal ++;
5136: $rowcount ++;
5137: }
1.230 raeburn 5138: } elsif ($position eq 'bottom') {
1.33 raeburn 5139: $context = 'course';
5140: $rowcount = 0;
5141: foreach my $role ('st','ep','ta','in','cr') {
5142: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5143: $numinrow,$rowcount);
5144: $$rowtotal ++;
5145: $rowcount ++;
5146: }
5147: }
5148: return $datatable;
5149: }
5150:
1.43 raeburn 5151: sub print_defaults {
1.236 raeburn 5152: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5153: my $rownum = 0;
5154: my ($datatable,$css_class);
1.236 raeburn 5155: if ($position eq 'top') {
5156: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5157: 'datelocale_def','portal_def');
5158: my %defaults;
5159: if (ref($settings) eq 'HASH') {
5160: %defaults = %{$settings};
1.43 raeburn 5161: } else {
1.236 raeburn 5162: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5163: foreach my $item (@items) {
5164: $defaults{$item} = $domdefaults{$item};
5165: }
1.43 raeburn 5166: }
1.236 raeburn 5167: my $titles = &defaults_titles($dom);
5168: foreach my $item (@items) {
5169: if ($rownum%2) {
5170: $css_class = '';
5171: } else {
5172: $css_class = ' class="LC_odd_row" ';
5173: }
5174: $datatable .= '<tr'.$css_class.'>'.
5175: '<td><span class="LC_nobreak">'.$titles->{$item}.
5176: '</span></td><td class="LC_right_item" colspan="3">';
5177: if ($item eq 'auth_def') {
5178: my @authtypes = ('internal','krb4','krb5','localauth');
5179: my %shortauth = (
5180: internal => 'int',
5181: krb4 => 'krb4',
5182: krb5 => 'krb5',
5183: localauth => 'loc'
5184: );
5185: my %authnames = &authtype_names();
5186: foreach my $auth (@authtypes) {
5187: my $checked = ' ';
5188: if ($defaults{$item} eq $auth) {
5189: $checked = ' checked="checked" ';
5190: }
5191: $datatable .= '<label><input type="radio" name="'.$item.
5192: '" value="'.$auth.'"'.$checked.'/>'.
5193: $authnames{$shortauth{$auth}}.'</label> ';
5194: }
5195: } elsif ($item eq 'timezone_def') {
5196: my $includeempty = 1;
5197: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5198: } elsif ($item eq 'datelocale_def') {
5199: my $includeempty = 1;
5200: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5201: } elsif ($item eq 'lang_def') {
1.263 raeburn 5202: my $includeempty = 1;
5203: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5204: } else {
5205: my $size;
5206: if ($item eq 'portal_def') {
5207: $size = ' size="25"';
5208: }
5209: $datatable .= '<input type="text" name="'.$item.'" value="'.
5210: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5211: }
1.236 raeburn 5212: $datatable .= '</td></tr>';
5213: $rownum ++;
5214: }
5215: } else {
5216: my (%defaults);
5217: if (ref($settings) eq 'HASH') {
5218: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5219: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5220: my $maxnum = @{$settings->{'inststatusorder'}};
5221: for (my $i=0; $i<$maxnum; $i++) {
5222: $css_class = $rownum%2?' class="LC_odd_row"':'';
5223: my $item = $settings->{'inststatusorder'}->[$i];
5224: my $title = $settings->{'inststatustypes'}->{$item};
5225: my $guestok;
5226: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5227: $guestok = 1;
5228: }
5229: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5230: $datatable .= '<tr'.$css_class.'>'.
5231: '<td><span class="LC_nobreak">'.
5232: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5233: for (my $k=0; $k<=$maxnum; $k++) {
5234: my $vpos = $k+1;
5235: my $selstr;
5236: if ($k == $i) {
5237: $selstr = ' selected="selected" ';
5238: }
5239: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5240: }
5241: my ($checkedon,$checkedoff);
5242: $checkedoff = ' checked="checked"';
5243: if ($guestok) {
5244: $checkedon = $checkedoff;
5245: $checkedoff = '';
5246: }
5247: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5248: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5249: &mt('delete').'</span></td>'.
5250: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5251: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5252: '</span></td>'.
5253: '<td class="LC_right_item"><span class="LC_nobreak">'.
5254: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5255: &mt('Yes').'</label>'.(' 'x2).
5256: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5257: &mt('No').'</label></span></td></tr>';
5258: }
5259: $css_class = $rownum%2?' class="LC_odd_row"':'';
5260: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5261: $datatable .= '<tr '.$css_class.'>'.
5262: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5263: for (my $k=0; $k<=$maxnum; $k++) {
5264: my $vpos = $k+1;
5265: my $selstr;
5266: if ($k == $maxnum) {
5267: $selstr = ' selected="selected" ';
5268: }
5269: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5270: }
5271: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5272: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5273: ' '.&mt('(new)').
5274: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5275: &mt('Name displayed:').
5276: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5277: '<td class="LC_right_item"><span class="LC_nobreak">'.
5278: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5279: &mt('Yes').'</label>'.(' 'x2).
5280: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5281: &mt('No').'</label></span></td></tr>';
5282: '</tr>'."\n";
5283: $rownum ++;
1.141 raeburn 5284: }
1.43 raeburn 5285: }
5286: }
5287: $$rowtotal += $rownum;
5288: return $datatable;
5289: }
5290:
1.168 raeburn 5291: sub get_languages_hash {
5292: my %langchoices;
5293: foreach my $id (&Apache::loncommon::languageids()) {
5294: my $code = &Apache::loncommon::supportedlanguagecode($id);
5295: if ($code ne '') {
5296: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5297: }
5298: }
5299: return %langchoices;
5300: }
5301:
1.43 raeburn 5302: sub defaults_titles {
1.141 raeburn 5303: my ($dom) = @_;
1.43 raeburn 5304: my %titles = &Apache::lonlocal::texthash (
5305: 'auth_def' => 'Default authentication type',
5306: 'auth_arg_def' => 'Default authentication argument',
5307: 'lang_def' => 'Default language',
1.54 raeburn 5308: 'timezone_def' => 'Default timezone',
1.68 raeburn 5309: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5310: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5311: );
1.141 raeburn 5312: if ($dom) {
5313: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5314: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5315: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5316: $protocol = 'http' if ($protocol ne 'https');
5317: if ($uint_dom) {
5318: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5319: $uint_dom);
5320: }
5321: }
1.43 raeburn 5322: return (\%titles);
5323: }
5324:
1.46 raeburn 5325: sub print_scantronformat {
5326: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5327: my $itemcount = 1;
1.60 raeburn 5328: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5329: %confhash);
1.46 raeburn 5330: my $switchserver = &check_switchserver($dom,$confname);
5331: my %lt = &Apache::lonlocal::texthash (
1.95 www 5332: default => 'Default bubblesheet format file error',
5333: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5334: );
5335: my %scantronfiles = (
5336: default => 'default.tab',
5337: custom => 'custom.tab',
5338: );
5339: foreach my $key (keys(%scantronfiles)) {
5340: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5341: .$scantronfiles{$key};
5342: }
5343: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5344: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5345: if (!$switchserver) {
5346: my $servadm = $r->dir_config('lonAdmEMail');
5347: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5348: if ($configuserok eq 'ok') {
5349: if ($author_ok eq 'ok') {
5350: my %legacyfile = (
5351: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5352: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5353: );
5354: my %md5chk;
5355: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5356: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5357: chomp($md5chk{$type});
1.46 raeburn 5358: }
5359: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5360: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5361: ($scantronurls{$type},my $error) =
1.46 raeburn 5362: &legacy_scantronformat($r,$dom,$confname,
5363: $type,$legacyfile{$type},
5364: $scantronurls{$type},
5365: $scantronfiles{$type});
1.60 raeburn 5366: if ($error ne '') {
5367: $error{$type} = $error;
5368: }
5369: }
5370: if (keys(%error) == 0) {
5371: $is_custom = 1;
5372: $confhash{'scantron'}{'scantronformat'} =
5373: $scantronurls{'custom'};
5374: my $putresult =
5375: &Apache::lonnet::put_dom('configuration',
5376: \%confhash,$dom);
5377: if ($putresult ne 'ok') {
5378: $error{'custom'} =
5379: '<span class="LC_error">'.
5380: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5381: }
1.46 raeburn 5382: }
5383: } else {
1.60 raeburn 5384: ($scantronurls{'default'},my $error) =
1.46 raeburn 5385: &legacy_scantronformat($r,$dom,$confname,
5386: 'default',$legacyfile{'default'},
5387: $scantronurls{'default'},
5388: $scantronfiles{'default'});
1.60 raeburn 5389: if ($error eq '') {
5390: $confhash{'scantron'}{'scantronformat'} = '';
5391: my $putresult =
5392: &Apache::lonnet::put_dom('configuration',
5393: \%confhash,$dom);
5394: if ($putresult ne 'ok') {
5395: $error{'default'} =
5396: '<span class="LC_error">'.
5397: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5398: }
5399: } else {
5400: $error{'default'} = $error;
5401: }
1.46 raeburn 5402: }
5403: }
5404: }
5405: } else {
1.95 www 5406: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5407: }
5408: }
5409: if (ref($settings) eq 'HASH') {
5410: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5411: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5412: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5413: $scantronurl = '';
5414: } else {
5415: $scantronurl = $settings->{'scantronformat'};
5416: }
5417: $is_custom = 1;
5418: } else {
5419: $scantronurl = $scantronurls{'default'};
5420: }
5421: } else {
1.60 raeburn 5422: if ($is_custom) {
5423: $scantronurl = $scantronurls{'custom'};
5424: } else {
5425: $scantronurl = $scantronurls{'default'};
5426: }
1.46 raeburn 5427: }
5428: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5429: $datatable .= '<tr'.$css_class.'>';
5430: if (!$is_custom) {
1.65 raeburn 5431: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5432: '<span class="LC_nobreak">';
1.46 raeburn 5433: if ($scantronurl) {
1.199 raeburn 5434: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5435: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5436: } else {
5437: $datatable = &mt('File unavailable for display');
5438: }
1.65 raeburn 5439: $datatable .= '</span></td>';
1.60 raeburn 5440: if (keys(%error) == 0) {
5441: $datatable .= '<td valign="bottom">';
5442: if (!$switchserver) {
5443: $datatable .= &mt('Upload:').'<br />';
5444: }
5445: } else {
5446: my $errorstr;
5447: foreach my $key (sort(keys(%error))) {
5448: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5449: }
5450: $datatable .= '<td>'.$errorstr;
5451: }
1.46 raeburn 5452: } else {
5453: if (keys(%error) > 0) {
5454: my $errorstr;
5455: foreach my $key (sort(keys(%error))) {
5456: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5457: }
1.60 raeburn 5458: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5459: } elsif ($scantronurl) {
1.199 raeburn 5460: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5461: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5462: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5463: $link.
5464: '<label><input type="checkbox" name="scantronformat_del"'.
5465: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5466: '<td><span class="LC_nobreak"> '.
5467: &mt('Replace:').'</span><br />';
1.46 raeburn 5468: }
5469: }
5470: if (keys(%error) == 0) {
5471: if ($switchserver) {
5472: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5473: } else {
1.65 raeburn 5474: $datatable .='<span class="LC_nobreak"> '.
5475: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5476: }
5477: }
5478: $datatable .= '</td></tr>';
5479: $$rowtotal ++;
5480: return $datatable;
5481: }
5482:
5483: sub legacy_scantronformat {
5484: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5485: my ($url,$error);
5486: my @statinfo = &Apache::lonnet::stat_file($newurl);
5487: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5488: (my $result,$url) =
5489: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5490: '','',$newfile);
5491: if ($result ne 'ok') {
1.130 raeburn 5492: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5493: }
5494: }
5495: return ($url,$error);
5496: }
1.43 raeburn 5497:
1.49 raeburn 5498: sub print_coursecategories {
1.57 raeburn 5499: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5500: my $datatable;
5501: if ($position eq 'top') {
1.238 raeburn 5502: my (%checked);
5503: my @catitems = ('unauth','auth');
5504: my @cattypes = ('std','domonly','codesrch','none');
5505: $checked{'unauth'} = 'std';
5506: $checked{'auth'} = 'std';
5507: if (ref($settings) eq 'HASH') {
5508: foreach my $type (@cattypes) {
5509: if ($type eq $settings->{'unauth'}) {
5510: $checked{'unauth'} = $type;
5511: }
5512: if ($type eq $settings->{'auth'}) {
5513: $checked{'auth'} = $type;
5514: }
5515: }
5516: }
5517: my %lt = &Apache::lonlocal::texthash (
5518: unauth => 'Catalog type for unauthenticated users',
5519: auth => 'Catalog type for authenticated users',
5520: none => 'No catalog',
5521: std => 'Standard catalog',
5522: domonly => 'Domain-only catalog',
5523: codesrch => "Code search form",
5524: );
5525: my $itemcount = 0;
5526: foreach my $item (@catitems) {
5527: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5528: $datatable .= '<tr '.$css_class.'>'.
5529: '<td>'.$lt{$item}.'</td>'.
5530: '<td class="LC_right_item"><span class="LC_nobreak">';
5531: foreach my $type (@cattypes) {
5532: my $ischecked;
5533: if ($checked{$item} eq $type) {
5534: $ischecked=' checked="checked"';
5535: }
5536: $datatable .= '<label>'.
5537: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5538: ' />'.$lt{$type}.'</label> ';
5539: }
5540: $datatable .= '</td></tr>';
5541: $itemcount ++;
5542: }
5543: $$rowtotal += $itemcount;
5544: } elsif ($position eq 'middle') {
1.57 raeburn 5545: my $toggle_cats_crs = ' ';
5546: my $toggle_cats_dom = ' checked="checked" ';
5547: my $can_cat_crs = ' ';
5548: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5549: my $toggle_catscomm_comm = ' ';
5550: my $toggle_catscomm_dom = ' checked="checked" ';
5551: my $can_catcomm_comm = ' ';
5552: my $can_catcomm_dom = ' checked="checked" ';
5553:
1.57 raeburn 5554: if (ref($settings) eq 'HASH') {
5555: if ($settings->{'togglecats'} eq 'crs') {
5556: $toggle_cats_crs = $toggle_cats_dom;
5557: $toggle_cats_dom = ' ';
5558: }
5559: if ($settings->{'categorize'} eq 'crs') {
5560: $can_cat_crs = $can_cat_dom;
5561: $can_cat_dom = ' ';
5562: }
1.120 raeburn 5563: if ($settings->{'togglecatscomm'} eq 'comm') {
5564: $toggle_catscomm_comm = $toggle_catscomm_dom;
5565: $toggle_catscomm_dom = ' ';
5566: }
5567: if ($settings->{'categorizecomm'} eq 'comm') {
5568: $can_catcomm_comm = $can_catcomm_dom;
5569: $can_catcomm_dom = ' ';
5570: }
1.57 raeburn 5571: }
5572: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5573: togglecats => 'Show/Hide a course in catalog',
5574: togglecatscomm => 'Show/Hide a community in catalog',
5575: categorize => 'Assign a category to a course',
5576: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5577: );
5578: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5579: dom => 'Set in Domain',
5580: crs => 'Set in Course',
5581: comm => 'Set in Community',
1.57 raeburn 5582: );
5583: $datatable = '<tr class="LC_odd_row">'.
5584: '<td>'.$title{'togglecats'}.'</td>'.
5585: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5586: '<input type="radio" name="togglecats"'.
5587: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5588: '<label><input type="radio" name="togglecats"'.
5589: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5590: '</tr><tr>'.
5591: '<td>'.$title{'categorize'}.'</td>'.
5592: '<td class="LC_right_item"><span class="LC_nobreak">'.
5593: '<label><input type="radio" name="categorize"'.
5594: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5595: '<label><input type="radio" name="categorize"'.
5596: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5597: '</tr><tr class="LC_odd_row">'.
5598: '<td>'.$title{'togglecatscomm'}.'</td>'.
5599: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5600: '<input type="radio" name="togglecatscomm"'.
5601: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5602: '<label><input type="radio" name="togglecatscomm"'.
5603: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5604: '</tr><tr>'.
5605: '<td>'.$title{'categorizecomm'}.'</td>'.
5606: '<td class="LC_right_item"><span class="LC_nobreak">'.
5607: '<label><input type="radio" name="categorizecomm"'.
5608: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5609: '<label><input type="radio" name="categorizecomm"'.
5610: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5611: '</tr>';
1.120 raeburn 5612: $$rowtotal += 4;
1.57 raeburn 5613: } else {
5614: my $css_class;
5615: my $itemcount = 1;
5616: my $cathash;
5617: if (ref($settings) eq 'HASH') {
5618: $cathash = $settings->{'cats'};
5619: }
5620: if (ref($cathash) eq 'HASH') {
5621: my (@cats,@trails,%allitems,%idx,@jsarray);
5622: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5623: \%allitems,\%idx,\@jsarray);
5624: my $maxdepth = scalar(@cats);
5625: my $colattrib = '';
5626: if ($maxdepth > 2) {
5627: $colattrib = ' colspan="2" ';
5628: }
5629: my @path;
5630: if (@cats > 0) {
5631: if (ref($cats[0]) eq 'ARRAY') {
5632: my $numtop = @{$cats[0]};
5633: my $maxnum = $numtop;
1.120 raeburn 5634: my %default_names = (
5635: instcode => &mt('Official courses'),
5636: communities => &mt('Communities'),
5637: );
5638:
5639: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5640: ($cathash->{'instcode::0'} eq '') ||
5641: (!grep(/^communities$/,@{$cats[0]})) ||
5642: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5643: $maxnum ++;
5644: }
5645: my $lastidx;
5646: for (my $i=0; $i<$numtop; $i++) {
5647: my $parent = $cats[0][$i];
5648: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5649: my $item = &escape($parent).'::0';
5650: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5651: $lastidx = $idx{$item};
5652: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5653: .'<select name="'.$item.'"'.$chgstr.'>';
5654: for (my $k=0; $k<=$maxnum; $k++) {
5655: my $vpos = $k+1;
5656: my $selstr;
5657: if ($k == $i) {
5658: $selstr = ' selected="selected" ';
5659: }
5660: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5661: }
1.214 raeburn 5662: $datatable .= '</select></span></td><td>';
1.120 raeburn 5663: if ($parent eq 'instcode' || $parent eq 'communities') {
5664: $datatable .= '<span class="LC_nobreak">'
5665: .$default_names{$parent}.'</span>';
5666: if ($parent eq 'instcode') {
5667: $datatable .= '<br /><span class="LC_nobreak">('
5668: .&mt('with institutional codes')
5669: .')</span></td><td'.$colattrib.'>';
5670: } else {
5671: $datatable .= '<table><tr><td>';
5672: }
5673: $datatable .= '<span class="LC_nobreak">'
5674: .'<label><input type="radio" name="'
5675: .$parent.'" value="1" checked="checked" />'
5676: .&mt('Display').'</label>';
5677: if ($parent eq 'instcode') {
5678: $datatable .= ' ';
5679: } else {
5680: $datatable .= '</span></td></tr><tr><td>'
5681: .'<span class="LC_nobreak">';
5682: }
5683: $datatable .= '<label><input type="radio" name="'
5684: .$parent.'" value="0" />'
5685: .&mt('Do not display').'</label></span>';
5686: if ($parent eq 'communities') {
5687: $datatable .= '</td></tr></table>';
5688: }
5689: $datatable .= '</td>';
1.57 raeburn 5690: } else {
5691: $datatable .= $parent
1.214 raeburn 5692: .' <span class="LC_nobreak"><label>'
5693: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5694: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5695: }
5696: my $depth = 1;
5697: push(@path,$parent);
5698: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5699: pop(@path);
5700: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5701: $itemcount ++;
5702: }
1.48 raeburn 5703: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5704: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5705: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5706: for (my $k=0; $k<=$maxnum; $k++) {
5707: my $vpos = $k+1;
5708: my $selstr;
1.57 raeburn 5709: if ($k == $numtop) {
1.48 raeburn 5710: $selstr = ' selected="selected" ';
5711: }
5712: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5713: }
1.59 bisitz 5714: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5715: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5716: .'</tr>'."\n";
1.48 raeburn 5717: $itemcount ++;
1.120 raeburn 5718: foreach my $default ('instcode','communities') {
5719: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5720: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5721: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5722: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5723: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5724: for (my $k=0; $k<=$maxnum; $k++) {
5725: my $vpos = $k+1;
5726: my $selstr;
5727: if ($k == $maxnum) {
5728: $selstr = ' selected="selected" ';
5729: }
5730: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5731: }
1.120 raeburn 5732: $datatable .= '</select></span></td>'.
5733: '<td><span class="LC_nobreak">'.
5734: $default_names{$default}.'</span>';
5735: if ($default eq 'instcode') {
5736: $datatable .= '<br /><span class="LC_nobreak">('
5737: .&mt('with institutional codes').')</span>';
5738: }
5739: $datatable .= '</td>'
5740: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5741: .&mt('Display').'</label> '
5742: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5743: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5744: }
5745: }
5746: }
1.57 raeburn 5747: } else {
5748: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5749: }
5750: } else {
1.238 raeburn 5751: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5752: .&initialize_categories($itemcount);
1.48 raeburn 5753: }
1.57 raeburn 5754: $$rowtotal += $itemcount;
1.48 raeburn 5755: }
5756: return $datatable;
5757: }
5758:
1.69 raeburn 5759: sub print_serverstatuses {
5760: my ($dom,$settings,$rowtotal) = @_;
5761: my $datatable;
5762: my @pages = &serverstatus_pages();
5763: my (%namedaccess,%machineaccess);
5764: foreach my $type (@pages) {
5765: $namedaccess{$type} = '';
5766: $machineaccess{$type}= '';
5767: }
5768: if (ref($settings) eq 'HASH') {
5769: foreach my $type (@pages) {
5770: if (exists($settings->{$type})) {
5771: if (ref($settings->{$type}) eq 'HASH') {
5772: foreach my $key (keys(%{$settings->{$type}})) {
5773: if ($key eq 'namedusers') {
5774: $namedaccess{$type} = $settings->{$type}->{$key};
5775: } elsif ($key eq 'machines') {
5776: $machineaccess{$type} = $settings->{$type}->{$key};
5777: }
5778: }
5779: }
5780: }
5781: }
5782: }
1.81 raeburn 5783: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5784: my $rownum = 0;
5785: my $css_class;
5786: foreach my $type (@pages) {
5787: $rownum ++;
5788: $css_class = $rownum%2?' class="LC_odd_row"':'';
5789: $datatable .= '<tr'.$css_class.'>'.
5790: '<td><span class="LC_nobreak">'.
5791: $titles->{$type}.'</span></td>'.
5792: '<td class="LC_left_item">'.
5793: '<input type="text" name="'.$type.'_namedusers" '.
5794: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5795: '<td class="LC_right_item">'.
5796: '<span class="LC_nobreak">'.
5797: '<input type="text" name="'.$type.'_machines" '.
5798: 'value="'.$machineaccess{$type}.'" size="10" />'.
5799: '</td></tr>'."\n";
5800: }
5801: $$rowtotal += $rownum;
5802: return $datatable;
5803: }
5804:
5805: sub serverstatus_pages {
5806: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5807: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5808: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.262 raeburn 5809: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5810: }
5811:
1.236 raeburn 5812: sub defaults_javascript {
5813: my ($settings) = @_;
1.248 raeburn 5814: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5815: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5816: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5817: if ($maxnum eq '') {
5818: $maxnum = 0;
5819: }
5820: $maxnum ++;
1.249 raeburn 5821: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5822: return <<"ENDSCRIPT";
5823: <script type="text/javascript">
5824: // <![CDATA[
5825: function reorderTypes(form,caller) {
5826: var changedVal;
5827: $jstext
5828: var newpos = 'addinststatus_pos';
5829: var current = new Array;
5830: var maxh = $maxnum;
5831: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5832: var oldVal;
5833: if (caller == newpos) {
5834: changedVal = newitemVal;
5835: } else {
5836: var curritem = 'inststatus_pos_'+caller;
5837: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5838: current[newitemVal] = newpos;
5839: }
5840: for (var i=0; i<inststatuses.length; i++) {
5841: if (inststatuses[i] != caller) {
5842: var elementName = 'inststatus_pos_'+inststatuses[i];
5843: if (form.elements[elementName]) {
5844: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5845: current[currVal] = elementName;
5846: }
5847: }
5848: }
5849: for (var j=0; j<maxh; j++) {
5850: if (current[j] == undefined) {
5851: oldVal = j;
5852: }
5853: }
5854: if (oldVal < changedVal) {
5855: for (var k=oldVal+1; k<=changedVal ; k++) {
5856: var elementName = current[k];
5857: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5858: }
5859: } else {
5860: for (var k=changedVal; k<oldVal; k++) {
5861: var elementName = current[k];
5862: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5863: }
5864: }
5865: return;
5866: }
5867:
5868: // ]]>
5869: </script>
5870:
5871: ENDSCRIPT
5872: }
5873: }
5874:
1.49 raeburn 5875: sub coursecategories_javascript {
5876: my ($settings) = @_;
1.57 raeburn 5877: my ($output,$jstext,$cathash);
1.49 raeburn 5878: if (ref($settings) eq 'HASH') {
1.57 raeburn 5879: $cathash = $settings->{'cats'};
5880: }
5881: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5882: my (@cats,@jsarray,%idx);
1.57 raeburn 5883: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5884: if (@jsarray > 0) {
5885: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5886: for (my $i=0; $i<@jsarray; $i++) {
5887: if (ref($jsarray[$i]) eq 'ARRAY') {
5888: my $catstr = join('","',@{$jsarray[$i]});
5889: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5890: }
5891: }
5892: }
5893: } else {
5894: $jstext = ' var categories = Array(1);'."\n".
5895: ' categories[0] = Array("instcode_pos");'."\n";
5896: }
1.237 bisitz 5897: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5898: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.265 damieng 5899: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5900: &js_escape(\$instcode_reserved);
5901: &js_escape(\$communities_reserved);
5902: &js_escape(\$choose_again);
1.49 raeburn 5903: $output = <<"ENDSCRIPT";
5904: <script type="text/javascript">
1.109 raeburn 5905: // <![CDATA[
1.49 raeburn 5906: function reorderCats(form,parent,item,idx) {
5907: var changedVal;
5908: $jstext
5909: var newpos = 'addcategory_pos';
5910: if (parent == '') {
5911: var has_instcode = 0;
5912: var maxtop = categories[idx].length;
5913: for (var j=0; j<maxtop; j++) {
5914: if (categories[idx][j] == 'instcode::0') {
5915: has_instcode == 1;
5916: }
5917: }
5918: if (has_instcode == 0) {
5919: categories[idx][maxtop] = 'instcode_pos';
5920: }
5921: } else {
5922: newpos += '_'+parent;
5923: }
5924: var maxh = 1 + categories[idx].length;
5925: var current = new Array;
5926: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5927: if (item == newpos) {
5928: changedVal = newitemVal;
5929: } else {
5930: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5931: current[newitemVal] = newpos;
5932: }
5933: for (var i=0; i<categories[idx].length; i++) {
5934: var elementName = categories[idx][i];
5935: if (elementName != item) {
5936: if (form.elements[elementName]) {
5937: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5938: current[currVal] = elementName;
5939: }
5940: }
5941: }
5942: var oldVal;
5943: for (var j=0; j<maxh; j++) {
5944: if (current[j] == undefined) {
5945: oldVal = j;
5946: }
5947: }
5948: if (oldVal < changedVal) {
5949: for (var k=oldVal+1; k<=changedVal ; k++) {
5950: var elementName = current[k];
5951: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5952: }
5953: } else {
5954: for (var k=changedVal; k<oldVal; k++) {
5955: var elementName = current[k];
5956: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5957: }
5958: }
5959: return;
5960: }
1.120 raeburn 5961:
5962: function categoryCheck(form) {
5963: if (form.elements['addcategory_name'].value == 'instcode') {
5964: alert('$instcode_reserved\\n$choose_again');
5965: return false;
5966: }
5967: if (form.elements['addcategory_name'].value == 'communities') {
5968: alert('$communities_reserved\\n$choose_again');
5969: return false;
5970: }
5971: return true;
5972: }
5973:
1.109 raeburn 5974: // ]]>
1.49 raeburn 5975: </script>
5976:
5977: ENDSCRIPT
5978: return $output;
5979: }
5980:
1.48 raeburn 5981: sub initialize_categories {
5982: my ($itemcount) = @_;
1.120 raeburn 5983: my ($datatable,$css_class,$chgstr);
5984: my %default_names = (
5985: instcode => 'Official courses (with institutional codes)',
5986: communities => 'Communities',
5987: );
5988: my $select0 = ' selected="selected"';
5989: my $select1 = '';
5990: foreach my $default ('instcode','communities') {
5991: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5992: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5993: if ($default eq 'communities') {
5994: $select1 = $select0;
5995: $select0 = '';
5996: }
5997: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5998: .'<select name="'.$default.'_pos">'
5999: .'<option value="0"'.$select0.'>1</option>'
6000: .'<option value="1"'.$select1.'>2</option>'
6001: .'<option value="2">3</option></select> '
6002: .$default_names{$default}
6003: .'</span></td><td><span class="LC_nobreak">'
6004: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6005: .&mt('Display').'</label> <label>'
6006: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6007: .'</label></span></td></tr>';
1.120 raeburn 6008: $itemcount ++;
6009: }
1.48 raeburn 6010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6011: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6012: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6013: .'<select name="addcategory_pos"'.$chgstr.'>'
6014: .'<option value="0">1</option>'
6015: .'<option value="1">2</option>'
6016: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6017: .&mt('Add category').'</td><td>'.&mt('Name:')
6018: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6019: return $datatable;
6020: }
6021:
6022: sub build_category_rows {
1.49 raeburn 6023: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6024: my ($text,$name,$item,$chgstr);
1.48 raeburn 6025: if (ref($cats) eq 'ARRAY') {
6026: my $maxdepth = scalar(@{$cats});
6027: if (ref($cats->[$depth]) eq 'HASH') {
6028: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6029: my $numchildren = @{$cats->[$depth]{$parent}};
6030: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6031: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6032: my ($idxnum,$parent_name,$parent_item);
6033: my $higher = $depth - 1;
6034: if ($higher == 0) {
6035: $parent_name = &escape($parent).'::'.$higher;
6036: } else {
6037: if (ref($path) eq 'ARRAY') {
6038: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6039: }
6040: }
6041: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6042: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6043: if ($j < $numchildren) {
1.48 raeburn 6044: $name = $cats->[$depth]{$parent}[$j];
6045: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6046: $idxnum = $idx->{$item};
6047: } else {
6048: $name = $parent_name;
6049: $item = $parent_item;
1.48 raeburn 6050: }
1.49 raeburn 6051: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6052: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6053: for (my $i=0; $i<=$numchildren; $i++) {
6054: my $vpos = $i+1;
6055: my $selstr;
6056: if ($j == $i) {
6057: $selstr = ' selected="selected" ';
6058: }
6059: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6060: }
6061: $text .= '</select> ';
6062: if ($j < $numchildren) {
6063: my $deeper = $depth+1;
6064: $text .= $name.' '
6065: .'<label><input type="checkbox" name="deletecategory" value="'
6066: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6067: if(ref($path) eq 'ARRAY') {
6068: push(@{$path},$name);
1.49 raeburn 6069: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6070: pop(@{$path});
6071: }
6072: } else {
1.59 bisitz 6073: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6074: if ($j == $numchildren) {
6075: $text .= $name;
6076: } else {
6077: $text .= $item;
6078: }
6079: $text .= '" value="" />';
6080: }
6081: $text .= '</td></tr>';
6082: }
6083: $text .= '</table></td>';
6084: } else {
6085: my $higher = $depth-1;
6086: if ($higher == 0) {
6087: $name = &escape($parent).'::'.$higher;
6088: } else {
6089: if (ref($path) eq 'ARRAY') {
6090: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6091: }
6092: }
6093: my $colspan;
6094: if ($parent ne 'instcode') {
6095: $colspan = $maxdepth - $depth - 1;
6096: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6097: }
6098: }
6099: }
6100: }
6101: return $text;
6102: }
6103:
1.33 raeburn 6104: sub modifiable_userdata_row {
1.228 raeburn 6105: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6106: my ($role,$rolename,$statustype);
6107: $role = $item;
1.224 raeburn 6108: if ($context eq 'cancreate') {
1.228 raeburn 6109: if ($item =~ /^emailusername_(.+)$/) {
6110: $statustype = $1;
6111: $role = 'emailusername';
6112: if (ref($usertypes) eq 'HASH') {
6113: if ($usertypes->{$statustype}) {
6114: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6115: } else {
6116: $rolename = &mt('Data provided by user');
6117: }
6118: }
1.224 raeburn 6119: }
6120: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6121: if (ref($usertypes) eq 'HASH') {
6122: $rolename = $usertypes->{$role};
6123: } else {
6124: $rolename = $role;
6125: }
1.33 raeburn 6126: } else {
1.63 raeburn 6127: if ($role eq 'cr') {
6128: $rolename = &mt('Custom role');
6129: } else {
6130: $rolename = &Apache::lonnet::plaintext($role);
6131: }
1.33 raeburn 6132: }
1.224 raeburn 6133: my (@fields,%fieldtitles);
6134: if (ref($fieldsref) eq 'ARRAY') {
6135: @fields = @{$fieldsref};
6136: } else {
6137: @fields = ('lastname','firstname','middlename','generation',
6138: 'permanentemail','id');
6139: }
6140: if ((ref($titlesref) eq 'HASH')) {
6141: %fieldtitles = %{$titlesref};
6142: } else {
6143: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6144: }
1.33 raeburn 6145: my $output;
6146: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6147: $output = '<tr '.$css_class.'>'.
6148: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6149: '<td class="LC_left_item" colspan="2"><table>';
6150: my $rem;
6151: my %checks;
6152: if (ref($settings) eq 'HASH') {
6153: if (ref($settings->{$context}) eq 'HASH') {
6154: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6155: my $hashref = $settings->{$context}->{$role};
6156: if ($role eq 'emailusername') {
6157: if ($statustype) {
6158: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6159: $hashref = $settings->{$context}->{$role}->{$statustype};
6160: if (ref($hashref) eq 'HASH') {
6161: foreach my $field (@fields) {
6162: if ($hashref->{$field}) {
6163: $checks{$field} = $hashref->{$field};
6164: }
6165: }
6166: }
6167: }
6168: }
6169: } else {
6170: if (ref($hashref) eq 'HASH') {
6171: foreach my $field (@fields) {
6172: if ($hashref->{$field}) {
6173: $checks{$field} = ' checked="checked" ';
6174: }
6175: }
1.33 raeburn 6176: }
6177: }
6178: }
6179: }
6180: }
1.228 raeburn 6181:
1.33 raeburn 6182: for (my $i=0; $i<@fields; $i++) {
6183: my $rem = $i%($numinrow);
6184: if ($rem == 0) {
6185: if ($i > 0) {
6186: $output .= '</tr>';
6187: }
6188: $output .= '<tr>';
6189: }
6190: my $check = ' ';
1.228 raeburn 6191: unless ($role eq 'emailusername') {
6192: if (exists($checks{$fields[$i]})) {
6193: $check = $checks{$fields[$i]}
6194: } else {
6195: if ($role eq 'st') {
6196: if (ref($settings) ne 'HASH') {
6197: $check = ' checked="checked" ';
6198: }
1.33 raeburn 6199: }
6200: }
6201: }
6202: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6203: '<span class="LC_nobreak">';
6204: if ($role eq 'emailusername') {
6205: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6206: $checks{$fields[$i]} = 'omit';
6207: }
6208: foreach my $option ('required','optional','omit') {
6209: my $checked='';
6210: if ($checks{$fields[$i]} eq $option) {
6211: $checked='checked="checked" ';
6212: }
6213: $output .= '<label>'.
6214: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6215: &mt($option).'</label>'.(' ' x2);
6216: }
6217: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6218: } else {
6219: $output .= '<label>'.
6220: '<input type="checkbox" name="canmodify_'.$role.'" '.
6221: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6222: '</label>';
6223: }
6224: $output .= '</span></td>';
1.33 raeburn 6225: $rem = @fields%($numinrow);
6226: }
6227: my $colsleft = $numinrow - $rem;
6228: if ($colsleft > 1 ) {
6229: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6230: ' </td>';
6231: } elsif ($colsleft == 1) {
6232: $output .= '<td class="LC_left_item"> </td>';
6233: }
6234: $output .= '</tr></table></td></tr>';
6235: return $output;
6236: }
1.28 raeburn 6237:
1.93 raeburn 6238: sub insttypes_row {
1.224 raeburn 6239: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6240: my %lt = &Apache::lonlocal::texthash (
6241: cansearch => 'Users allowed to search',
6242: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6243: lockablenames => 'User preference to lock name',
1.93 raeburn 6244: );
6245: my $showdom;
6246: if ($context eq 'cansearch') {
6247: $showdom = ' ('.$dom.')';
6248: }
1.165 raeburn 6249: my $class = 'LC_left_item';
6250: if ($context eq 'statustocreate') {
6251: $class = 'LC_right_item';
6252: }
1.224 raeburn 6253: my $css_class = ' class="LC_odd_row"';
6254: if ($rownum ne '') {
6255: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6256: }
6257: my $output = '<tr'.$css_class.'>'.
6258: '<td>'.$lt{$context}.$showdom.
6259: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6260: my $rem;
6261: if (ref($types) eq 'ARRAY') {
6262: for (my $i=0; $i<@{$types}; $i++) {
6263: if (defined($usertypes->{$types->[$i]})) {
6264: my $rem = $i%($numinrow);
6265: if ($rem == 0) {
6266: if ($i > 0) {
6267: $output .= '</tr>';
6268: }
6269: $output .= '<tr>';
1.23 raeburn 6270: }
1.26 raeburn 6271: my $check = ' ';
1.99 raeburn 6272: if (ref($settings) eq 'HASH') {
6273: if (ref($settings->{$context}) eq 'ARRAY') {
6274: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6275: $check = ' checked="checked" ';
6276: }
6277: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6278: $check = ' checked="checked" ';
6279: }
1.23 raeburn 6280: }
1.26 raeburn 6281: $output .= '<td class="LC_left_item">'.
6282: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6283: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6284: 'value="'.$types->[$i].'"'.$check.'/>'.
6285: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6286: }
6287: }
1.26 raeburn 6288: $rem = @{$types}%($numinrow);
1.23 raeburn 6289: }
6290: my $colsleft = $numinrow - $rem;
1.131 raeburn 6291: if (($rem == 0) && (@{$types} > 0)) {
6292: $output .= '<tr>';
6293: }
1.23 raeburn 6294: if ($colsleft > 1) {
1.25 raeburn 6295: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6296: } else {
1.25 raeburn 6297: $output .= '<td class="LC_left_item">';
1.23 raeburn 6298: }
6299: my $defcheck = ' ';
1.99 raeburn 6300: if (ref($settings) eq 'HASH') {
6301: if (ref($settings->{$context}) eq 'ARRAY') {
6302: if (grep(/^default$/,@{$settings->{$context}})) {
6303: $defcheck = ' checked="checked" ';
6304: }
6305: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6306: $defcheck = ' checked="checked" ';
6307: }
1.23 raeburn 6308: }
1.25 raeburn 6309: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6310: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6311: 'value="default"'.$defcheck.'/>'.
6312: $othertitle.'</label></span></td>'.
6313: '</tr></table></td></tr>';
6314: return $output;
1.23 raeburn 6315: }
6316:
6317: sub sorted_searchtitles {
6318: my %searchtitles = &Apache::lonlocal::texthash(
6319: 'uname' => 'username',
6320: 'lastname' => 'last name',
6321: 'lastfirst' => 'last name, first name',
6322: );
6323: my @titleorder = ('uname','lastname','lastfirst');
6324: return (\%searchtitles,\@titleorder);
6325: }
6326:
1.25 raeburn 6327: sub sorted_searchtypes {
6328: my %srchtypes_desc = (
6329: exact => 'is exact match',
6330: contains => 'contains ..',
6331: begins => 'begins with ..',
6332: );
6333: my @srchtypeorder = ('exact','begins','contains');
6334: return (\%srchtypes_desc,\@srchtypeorder);
6335: }
6336:
1.3 raeburn 6337: sub usertype_update_row {
6338: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6339: my $datatable;
6340: my $numinrow = 4;
6341: foreach my $type (@{$types}) {
6342: if (defined($usertypes->{$type})) {
6343: $$rownums ++;
6344: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6345: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6346: '</td><td class="LC_left_item"><table>';
6347: for (my $i=0; $i<@{$fields}; $i++) {
6348: my $rem = $i%($numinrow);
6349: if ($rem == 0) {
6350: if ($i > 0) {
6351: $datatable .= '</tr>';
6352: }
6353: $datatable .= '<tr>';
6354: }
6355: my $check = ' ';
1.39 raeburn 6356: if (ref($settings) eq 'HASH') {
6357: if (ref($settings->{'fields'}) eq 'HASH') {
6358: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6359: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6360: $check = ' checked="checked" ';
6361: }
1.3 raeburn 6362: }
6363: }
6364: }
6365:
6366: if ($i == @{$fields}-1) {
6367: my $colsleft = $numinrow - $rem;
6368: if ($colsleft > 1) {
6369: $datatable .= '<td colspan="'.$colsleft.'">';
6370: } else {
6371: $datatable .= '<td>';
6372: }
6373: } else {
6374: $datatable .= '<td>';
6375: }
1.8 raeburn 6376: $datatable .= '<span class="LC_nobreak"><label>'.
6377: '<input type="checkbox" name="updateable_'.$type.
6378: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6379: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6380: }
6381: $datatable .= '</tr></table></td></tr>';
6382: }
6383: }
6384: return $datatable;
1.1 raeburn 6385: }
6386:
6387: sub modify_login {
1.205 raeburn 6388: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6389: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6390: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6391: %title = ( coursecatalog => 'Display course catalog',
6392: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6393: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6394: newuser => 'Link for visitors to create a user account',
6395: loginheader => 'Log-in box header');
6396: @offon = ('off','on');
1.112 raeburn 6397: if (ref($domconfig{login}) eq 'HASH') {
6398: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6399: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6400: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6401: }
6402: }
6403: }
1.9 raeburn 6404: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6405: \%domconfig,\%loginhash);
1.188 raeburn 6406: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6407: foreach my $item (@toggles) {
6408: $loginhash{login}{$item} = $env{'form.'.$item};
6409: }
1.41 raeburn 6410: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6411: if (ref($colchanges{'login'}) eq 'HASH') {
6412: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6413: \%loginhash);
6414: }
1.110 raeburn 6415:
1.149 raeburn 6416: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6417: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6418: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6419: if (keys(%servers) > 1) {
6420: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6421: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6422: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6423: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6424: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6425: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6426: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6427: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6428: $changes{'loginvia'}{$lonhost} = 1;
6429: } else {
6430: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6431: $changes{'loginvia'}{$lonhost} = 1;
6432: }
6433: } else {
6434: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6435: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6436: $changes{'loginvia'}{$lonhost} = 1;
6437: }
6438: }
6439: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6440: foreach my $item (@loginvia_attribs) {
6441: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6442: }
6443: } else {
6444: foreach my $item (@loginvia_attribs) {
6445: my $new = $env{'form.'.$lonhost.'_'.$item};
6446: if (($item eq 'serverpath') && ($new eq 'custom')) {
6447: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6448: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6449: $new = '/';
6450: }
6451: }
6452: if (($item eq 'custompath') &&
6453: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6454: $new = '';
6455: }
6456: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6457: $changes{'loginvia'}{$lonhost} = 1;
6458: }
6459: if ($item eq 'exempt') {
1.256 raeburn 6460: $new = &check_exempt_addresses($new);
1.128 raeburn 6461: }
6462: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6463: }
6464: }
1.112 raeburn 6465: } else {
1.128 raeburn 6466: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6467: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6468: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6469: foreach my $item (@loginvia_attribs) {
6470: my $new = $env{'form.'.$lonhost.'_'.$item};
6471: if (($item eq 'serverpath') && ($new eq 'custom')) {
6472: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6473: $new = '/';
6474: }
6475: }
6476: if (($item eq 'custompath') &&
6477: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6478: $new = '';
6479: }
6480: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6481: }
1.110 raeburn 6482: }
6483: }
6484: }
6485: }
1.119 raeburn 6486:
1.168 raeburn 6487: my $servadm = $r->dir_config('lonAdmEMail');
6488: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6489: if (ref($domconfig{'login'}) eq 'HASH') {
6490: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6491: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6492: if ($lang eq 'nolang') {
6493: push(@currlangs,$lang);
6494: } elsif (defined($langchoices{$lang})) {
6495: push(@currlangs,$lang);
6496: } else {
6497: next;
6498: }
6499: }
6500: }
6501: }
6502: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6503: if (@currlangs > 0) {
6504: foreach my $lang (@currlangs) {
6505: if (grep(/^\Q$lang\E$/,@delurls)) {
6506: $changes{'helpurl'}{$lang} = 1;
6507: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6508: $changes{'helpurl'}{$lang} = 1;
6509: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6510: push(@newlangs,$lang);
6511: } else {
6512: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6513: }
6514: }
6515: }
6516: unless (grep(/^nolang$/,@currlangs)) {
6517: if ($env{'form.loginhelpurl_nolang.filename'}) {
6518: $changes{'helpurl'}{'nolang'} = 1;
6519: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6520: push(@newlangs,'nolang');
6521: }
6522: }
6523: if ($env{'form.loginhelpurl_add_lang'}) {
6524: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6525: ($env{'form.loginhelpurl_add_file.filename'})) {
6526: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6527: $addedfile = $env{'form.loginhelpurl_add_lang'};
6528: }
6529: }
6530: if ((@newlangs > 0) || ($addedfile)) {
6531: my $error;
6532: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6533: if ($configuserok eq 'ok') {
6534: if ($switchserver) {
6535: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6536: } elsif ($author_ok eq 'ok') {
6537: my @allnew = @newlangs;
6538: if ($addedfile ne '') {
6539: push(@allnew,$addedfile);
6540: }
6541: foreach my $lang (@allnew) {
6542: my $formelem = 'loginhelpurl_'.$lang;
6543: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6544: $formelem = 'loginhelpurl_add_file';
6545: }
6546: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6547: "help/$lang",'','',$newfile{$lang});
6548: if ($result eq 'ok') {
6549: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6550: $changes{'helpurl'}{$lang} = 1;
6551: } else {
6552: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6553: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6554: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6555: (!grep(/^\Q$lang\E$/,@delurls))) {
6556: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6557: }
6558: }
6559: }
6560: } else {
6561: $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);
6562: }
6563: } else {
6564: $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);
6565: }
6566: if ($error) {
6567: &Apache::lonnet::logthis($error);
6568: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6569: }
6570: }
1.256 raeburn 6571:
6572: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6573: if (ref($domconfig{'login'}) eq 'HASH') {
6574: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6575: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6576: if ($domservers{$lonhost}) {
6577: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6578: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6579: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6580: }
6581: }
6582: }
6583: }
6584: }
6585: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6586: foreach my $lonhost (sort(keys(%domservers))) {
6587: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6588: $changes{'headtag'}{$lonhost} = 1;
6589: } else {
6590: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6591: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6592: }
6593: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6594: push(@newhosts,$lonhost);
6595: } elsif ($currheadtagurls{$lonhost}) {
6596: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6597: if ($currexempt{$lonhost}) {
6598: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6599: $changes{'headtag'}{$lonhost} = 1;
6600: }
6601: } elsif ($possexempt{$lonhost}) {
6602: $changes{'headtag'}{$lonhost} = 1;
6603: }
6604: if ($possexempt{$lonhost}) {
6605: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6606: }
6607: }
6608: }
6609: }
6610: if (@newhosts) {
6611: my $error;
6612: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6613: if ($configuserok eq 'ok') {
6614: if ($switchserver) {
6615: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6616: } elsif ($author_ok eq 'ok') {
6617: foreach my $lonhost (@newhosts) {
6618: my $formelem = 'loginheadtag_'.$lonhost;
6619: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6620: "login/headtag/$lonhost",'','',
6621: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6622: if ($result eq 'ok') {
6623: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6624: $changes{'headtag'}{$lonhost} = 1;
6625: if ($possexempt{$lonhost}) {
6626: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6627: }
6628: } else {
6629: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6630: $newheadtagurls{$lonhost},$result);
6631: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6632: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6633: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6634: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6635: }
6636: }
6637: }
6638: } else {
6639: $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);
6640: }
6641: } else {
6642: $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);
6643: }
6644: if ($error) {
6645: &Apache::lonnet::logthis($error);
6646: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6647: }
6648: }
1.169 raeburn 6649: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6650:
6651: my $defaulthelpfile = '/adm/loginproblems.html';
6652: my $defaulttext = &mt('Default in use');
6653:
1.1 raeburn 6654: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6655: $dom);
6656: if ($putresult eq 'ok') {
1.188 raeburn 6657: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6658: my %defaultchecked = (
6659: 'coursecatalog' => 'on',
1.188 raeburn 6660: 'helpdesk' => 'on',
1.42 raeburn 6661: 'adminmail' => 'off',
1.43 raeburn 6662: 'newuser' => 'off',
1.42 raeburn 6663: );
1.55 raeburn 6664: if (ref($domconfig{'login'}) eq 'HASH') {
6665: foreach my $item (@toggles) {
6666: if ($defaultchecked{$item} eq 'on') {
6667: if (($domconfig{'login'}{$item} eq '0') &&
6668: ($env{'form.'.$item} eq '1')) {
6669: $changes{$item} = 1;
6670: } elsif (($domconfig{'login'}{$item} eq '' ||
6671: $domconfig{'login'}{$item} eq '1') &&
6672: ($env{'form.'.$item} eq '0')) {
6673: $changes{$item} = 1;
6674: }
6675: } elsif ($defaultchecked{$item} eq 'off') {
6676: if (($domconfig{'login'}{$item} eq '1') &&
6677: ($env{'form.'.$item} eq '0')) {
6678: $changes{$item} = 1;
6679: } elsif (($domconfig{'login'}{$item} eq '' ||
6680: $domconfig{'login'}{$item} eq '0') &&
6681: ($env{'form.'.$item} eq '1')) {
6682: $changes{$item} = 1;
6683: }
1.42 raeburn 6684: }
6685: }
1.41 raeburn 6686: }
1.6 raeburn 6687: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6688: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6689: if (ref($lastactref) eq 'HASH') {
6690: $lastactref->{'domainconfig'} = 1;
6691: }
1.1 raeburn 6692: $resulttext = &mt('Changes made:').'<ul>';
6693: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6694: if ($item eq 'loginvia') {
1.112 raeburn 6695: if (ref($changes{$item}) eq 'HASH') {
6696: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6697: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6698: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6699: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6700: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6701: $protocol = 'http' if ($protocol ne 'https');
6702: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6703:
6704: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6705: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6706: } else {
6707: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6708: }
6709: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6710: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6711: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6712: }
6713: $resulttext .= '</li>';
6714: } else {
6715: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6716: }
1.112 raeburn 6717: } else {
1.128 raeburn 6718: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6719: }
6720: }
1.128 raeburn 6721: $resulttext .= '</ul></li>';
1.112 raeburn 6722: }
1.168 raeburn 6723: } elsif ($item eq 'helpurl') {
6724: if (ref($changes{$item}) eq 'HASH') {
6725: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6726: if (grep(/^\Q$lang\E$/,@delurls)) {
6727: my ($chg,$link);
6728: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6729: if ($lang eq 'nolang') {
6730: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6731: } else {
6732: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6733: }
6734: $resulttext .= '<li>'.$chg.'</li>';
6735: } else {
6736: my $chg;
6737: if ($lang eq 'nolang') {
6738: $chg = &mt('custom log-in help file for no preferred language');
6739: } else {
6740: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6741: }
6742: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6743: $loginhash{'login'}{'helpurl'}{$lang}.
6744: '?inhibitmenu=yes',$chg,600,500).
6745: '</li>';
6746: }
6747: }
6748: }
1.256 raeburn 6749: } elsif ($item eq 'headtag') {
6750: if (ref($changes{$item}) eq 'HASH') {
6751: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6752: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6753: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6754: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6755: $resulttext .= '<li><a href="'.
6756: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6757: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6758: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6759: if ($possexempt{$lonhost}) {
6760: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6761: } else {
6762: $resulttext .= &mt('included for any client IP');
6763: }
6764: $resulttext .= '</li>';
6765: }
6766: }
6767: }
1.169 raeburn 6768: } elsif ($item eq 'captcha') {
6769: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6770: my $chgtxt;
1.169 raeburn 6771: if ($loginhash{'login'}{$item} eq 'notused') {
6772: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6773: } else {
6774: my %captchas = &captcha_phrases();
6775: if ($captchas{$loginhash{'login'}{$item}}) {
6776: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6777: } else {
6778: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6779: }
6780: }
6781: $resulttext .= '<li>'.$chgtxt.'</li>';
6782: }
6783: } elsif ($item eq 'recaptchakeys') {
6784: if (ref($loginhash{'login'}) eq 'HASH') {
6785: my ($privkey,$pubkey);
6786: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6787: $pubkey = $loginhash{'login'}{$item}{'public'};
6788: $privkey = $loginhash{'login'}{$item}{'private'};
6789: }
6790: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6791: if (!$pubkey) {
6792: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6793: } else {
6794: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6795: }
6796: if (!$privkey) {
6797: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6798: } else {
1.251 raeburn 6799: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6800: }
6801: $chgtxt .= '</ul>';
6802: $resulttext .= '<li>'.$chgtxt.'</li>';
6803: }
1.269 raeburn 6804: } elsif ($item eq 'recaptchaversion') {
6805: if (ref($loginhash{'login'}) eq 'HASH') {
6806: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 ! raeburn 6807: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 6808: '</li>';
6809: }
6810: }
1.41 raeburn 6811: } else {
6812: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6813: }
1.1 raeburn 6814: }
1.6 raeburn 6815: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6816: } else {
6817: $resulttext = &mt('No changes made to log-in page settings');
6818: }
6819: } else {
1.11 albertel 6820: $resulttext = '<span class="LC_error">'.
6821: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6822: }
1.6 raeburn 6823: if ($errors) {
1.9 raeburn 6824: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6825: $errors.'</ul>';
6826: }
6827: return $resulttext;
6828: }
6829:
1.256 raeburn 6830:
6831: sub check_exempt_addresses {
6832: my ($iplist) = @_;
6833: $iplist =~ s/^\s+//;
6834: $iplist =~ s/\s+$//;
6835: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6836: my (@okips,$new);
6837: foreach my $ip (@poss_ips) {
6838: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6839: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6840: push(@okips,$ip);
6841: }
6842: }
6843: }
6844: if (@okips > 0) {
6845: $new = join(',',@okips);
6846: } else {
6847: $new = '';
6848: }
6849: return $new;
6850: }
6851:
1.6 raeburn 6852: sub color_font_choices {
6853: my %choices =
6854: &Apache::lonlocal::texthash (
6855: img => "Header",
6856: bgs => "Background colors",
6857: links => "Link colors",
1.55 raeburn 6858: images => "Images",
1.6 raeburn 6859: font => "Font color",
1.201 raeburn 6860: fontmenu => "Font menu",
1.76 raeburn 6861: pgbg => "Page",
1.6 raeburn 6862: tabbg => "Header",
6863: sidebg => "Border",
6864: link => "Link",
6865: alink => "Active link",
6866: vlink => "Visited link",
6867: );
6868: return %choices;
6869: }
6870:
6871: sub modify_rolecolors {
1.205 raeburn 6872: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6873: my ($resulttext,%rolehash);
6874: $rolehash{'rolecolors'} = {};
1.55 raeburn 6875: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6876: if ($domconfig{'rolecolors'} eq '') {
6877: $domconfig{'rolecolors'} = {};
6878: }
6879: }
1.9 raeburn 6880: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6881: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6882: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6883: $dom);
6884: if ($putresult eq 'ok') {
6885: if (keys(%changes) > 0) {
1.41 raeburn 6886: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6887: if (ref($lastactref) eq 'HASH') {
6888: $lastactref->{'domainconfig'} = 1;
6889: }
1.6 raeburn 6890: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6891: $rolehash{'rolecolors'});
6892: } else {
6893: $resulttext = &mt('No changes made to default color schemes');
6894: }
6895: } else {
1.11 albertel 6896: $resulttext = '<span class="LC_error">'.
6897: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6898: }
6899: if ($errors) {
6900: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6901: $errors.'</ul>';
6902: }
6903: return $resulttext;
6904: }
6905:
6906: sub modify_colors {
1.9 raeburn 6907: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6908: my (%changes,%choices);
1.51 raeburn 6909: my @bgs;
1.6 raeburn 6910: my @links = ('link','alink','vlink');
1.41 raeburn 6911: my @logintext;
1.6 raeburn 6912: my @images;
6913: my $servadm = $r->dir_config('lonAdmEMail');
6914: my $errors;
1.200 raeburn 6915: my %defaults;
1.6 raeburn 6916: foreach my $role (@{$roles}) {
6917: if ($role eq 'login') {
1.12 raeburn 6918: %choices = &login_choices();
1.41 raeburn 6919: @logintext = ('textcol','bgcol');
1.12 raeburn 6920: } else {
6921: %choices = &color_font_choices();
6922: }
6923: if ($role eq 'login') {
1.41 raeburn 6924: @images = ('img','logo','domlogo','login');
1.51 raeburn 6925: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6926: } else {
6927: @images = ('img');
1.200 raeburn 6928: @bgs = ('pgbg','tabbg','sidebg');
6929: }
6930: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6931: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6932: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6933: }
6934: if ($role eq 'login') {
6935: foreach my $item (@logintext) {
1.234 raeburn 6936: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6937: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6938: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6939: }
6940: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6941: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6942: }
6943: }
6944: } else {
1.234 raeburn 6945: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6946: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6947: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6948: }
6949: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6950: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6951: }
1.6 raeburn 6952: }
1.200 raeburn 6953: foreach my $item (@bgs) {
1.234 raeburn 6954: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6955: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6956: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6957: }
6958: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6959: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6960: }
6961: }
6962: foreach my $item (@links) {
1.234 raeburn 6963: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6964: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6965: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6966: }
6967: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6968: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6969: }
1.6 raeburn 6970: }
1.46 raeburn 6971: my ($configuserok,$author_ok,$switchserver) =
6972: &config_check($dom,$confname,$servadm);
1.9 raeburn 6973: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6974: if (ref($domconfig->{$role}) ne 'HASH') {
6975: $domconfig->{$role} = {};
6976: }
1.8 raeburn 6977: foreach my $img (@images) {
1.70 raeburn 6978: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6979: if (defined($env{'form.login_showlogo_'.$img})) {
6980: $confhash->{$role}{'showlogo'}{$img} = 1;
6981: } else {
6982: $confhash->{$role}{'showlogo'}{$img} = 0;
6983: }
6984: }
1.18 albertel 6985: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6986: && !defined($domconfig->{$role}{$img})
6987: && !$env{'form.'.$role.'_del_'.$img}
6988: && $env{'form.'.$role.'_import_'.$img}) {
6989: # import the old configured image from the .tab setting
6990: # if they haven't provided a new one
6991: $domconfig->{$role}{$img} =
6992: $env{'form.'.$role.'_import_'.$img};
6993: }
1.6 raeburn 6994: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6995: my $error;
1.6 raeburn 6996: if ($configuserok eq 'ok') {
1.9 raeburn 6997: if ($switchserver) {
1.12 raeburn 6998: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6999: } else {
7000: if ($author_ok eq 'ok') {
7001: my ($result,$logourl) =
7002: &publishlogo($r,'upload',$role.'_'.$img,
7003: $dom,$confname,$img,$width,$height);
7004: if ($result eq 'ok') {
7005: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7006: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7007: } else {
1.12 raeburn 7008: $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 7009: }
7010: } else {
1.46 raeburn 7011: $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 7012: }
7013: }
7014: } else {
1.46 raeburn 7015: $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 7016: }
7017: if ($error) {
1.8 raeburn 7018: &Apache::lonnet::logthis($error);
1.11 albertel 7019: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7020: }
7021: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7022: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7023: my $error;
7024: if ($configuserok eq 'ok') {
7025: # is confname an author?
7026: if ($switchserver eq '') {
7027: if ($author_ok eq 'ok') {
7028: my ($result,$logourl) =
7029: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7030: $dom,$confname,$img,$width,$height);
7031: if ($result eq 'ok') {
7032: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7033: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7034: }
7035: }
7036: }
7037: }
1.6 raeburn 7038: }
7039: }
7040: }
7041: if (ref($domconfig) eq 'HASH') {
7042: if (ref($domconfig->{$role}) eq 'HASH') {
7043: foreach my $img (@images) {
7044: if ($domconfig->{$role}{$img} ne '') {
7045: if ($env{'form.'.$role.'_del_'.$img}) {
7046: $confhash->{$role}{$img} = '';
1.12 raeburn 7047: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7048: } else {
1.9 raeburn 7049: if ($confhash->{$role}{$img} eq '') {
7050: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7051: }
1.6 raeburn 7052: }
7053: } else {
7054: if ($env{'form.'.$role.'_del_'.$img}) {
7055: $confhash->{$role}{$img} = '';
1.12 raeburn 7056: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7057: }
7058: }
1.70 raeburn 7059: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7060: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7061: if ($confhash->{$role}{'showlogo'}{$img} ne
7062: $domconfig->{$role}{'showlogo'}{$img}) {
7063: $changes{$role}{'showlogo'}{$img} = 1;
7064: }
7065: } else {
7066: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7067: $changes{$role}{'showlogo'}{$img} = 1;
7068: }
7069: }
7070: }
7071: }
1.6 raeburn 7072: if ($domconfig->{$role}{'font'} ne '') {
7073: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7074: $changes{$role}{'font'} = 1;
7075: }
7076: } else {
7077: if ($confhash->{$role}{'font'}) {
7078: $changes{$role}{'font'} = 1;
7079: }
7080: }
1.107 raeburn 7081: if ($role ne 'login') {
7082: if ($domconfig->{$role}{'fontmenu'} ne '') {
7083: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7084: $changes{$role}{'fontmenu'} = 1;
7085: }
7086: } else {
7087: if ($confhash->{$role}{'fontmenu'}) {
7088: $changes{$role}{'fontmenu'} = 1;
7089: }
1.97 tempelho 7090: }
7091: }
1.6 raeburn 7092: foreach my $item (@bgs) {
7093: if ($domconfig->{$role}{$item} ne '') {
7094: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7095: $changes{$role}{'bgs'}{$item} = 1;
7096: }
7097: } else {
7098: if ($confhash->{$role}{$item}) {
7099: $changes{$role}{'bgs'}{$item} = 1;
7100: }
7101: }
7102: }
7103: foreach my $item (@links) {
7104: if ($domconfig->{$role}{$item} ne '') {
7105: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7106: $changes{$role}{'links'}{$item} = 1;
7107: }
7108: } else {
7109: if ($confhash->{$role}{$item}) {
7110: $changes{$role}{'links'}{$item} = 1;
7111: }
7112: }
7113: }
1.41 raeburn 7114: foreach my $item (@logintext) {
7115: if ($domconfig->{$role}{$item} ne '') {
7116: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7117: $changes{$role}{'logintext'}{$item} = 1;
7118: }
7119: } else {
7120: if ($confhash->{$role}{$item}) {
7121: $changes{$role}{'logintext'}{$item} = 1;
7122: }
7123: }
7124: }
1.6 raeburn 7125: } else {
7126: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7127: \@logintext,$confhash,\%changes);
1.6 raeburn 7128: }
7129: } else {
7130: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7131: \@logintext,$confhash,\%changes);
1.6 raeburn 7132: }
7133: }
7134: return ($errors,%changes);
7135: }
7136:
1.46 raeburn 7137: sub config_check {
7138: my ($dom,$confname,$servadm) = @_;
7139: my ($configuserok,$author_ok,$switchserver,%currroles);
7140: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7141: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7142: $confname,$servadm);
7143: if ($configuserok eq 'ok') {
7144: $switchserver = &check_switchserver($dom,$confname);
7145: if ($switchserver eq '') {
7146: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7147: }
7148: }
7149: return ($configuserok,$author_ok,$switchserver);
7150: }
7151:
1.6 raeburn 7152: sub default_change_checker {
1.41 raeburn 7153: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7154: foreach my $item (@{$links}) {
7155: if ($confhash->{$role}{$item}) {
7156: $changes->{$role}{'links'}{$item} = 1;
7157: }
7158: }
7159: foreach my $item (@{$bgs}) {
7160: if ($confhash->{$role}{$item}) {
7161: $changes->{$role}{'bgs'}{$item} = 1;
7162: }
7163: }
1.41 raeburn 7164: foreach my $item (@{$logintext}) {
7165: if ($confhash->{$role}{$item}) {
7166: $changes->{$role}{'logintext'}{$item} = 1;
7167: }
7168: }
1.6 raeburn 7169: foreach my $img (@{$images}) {
7170: if ($env{'form.'.$role.'_del_'.$img}) {
7171: $confhash->{$role}{$img} = '';
1.12 raeburn 7172: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7173: }
1.70 raeburn 7174: if ($role eq 'login') {
7175: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7176: $changes->{$role}{'showlogo'}{$img} = 1;
7177: }
7178: }
1.6 raeburn 7179: }
7180: if ($confhash->{$role}{'font'}) {
7181: $changes->{$role}{'font'} = 1;
7182: }
1.48 raeburn 7183: }
1.6 raeburn 7184:
7185: sub display_colorchgs {
7186: my ($dom,$changes,$roles,$confhash) = @_;
7187: my (%choices,$resulttext);
7188: if (!grep(/^login$/,@{$roles})) {
7189: $resulttext = &mt('Changes made:').'<br />';
7190: }
7191: foreach my $role (@{$roles}) {
7192: if ($role eq 'login') {
7193: %choices = &login_choices();
7194: } else {
7195: %choices = &color_font_choices();
7196: }
7197: if (ref($changes->{$role}) eq 'HASH') {
7198: if ($role ne 'login') {
7199: $resulttext .= '<h4>'.&mt($role).'</h4>';
7200: }
7201: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7202: if ($role ne 'login') {
7203: $resulttext .= '<ul>';
7204: }
7205: if (ref($changes->{$role}{$key}) eq 'HASH') {
7206: if ($role ne 'login') {
7207: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7208: }
7209: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7210: if (($role eq 'login') && ($key eq 'showlogo')) {
7211: if ($confhash->{$role}{$key}{$item}) {
7212: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7213: } else {
7214: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7215: }
7216: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7217: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7218: } else {
1.12 raeburn 7219: my $newitem = $confhash->{$role}{$item};
7220: if ($key eq 'images') {
7221: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7222: }
7223: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7224: }
7225: }
7226: if ($role ne 'login') {
7227: $resulttext .= '</ul></li>';
7228: }
7229: } else {
7230: if ($confhash->{$role}{$key} eq '') {
7231: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7232: } else {
7233: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7234: }
7235: }
7236: if ($role ne 'login') {
7237: $resulttext .= '</ul>';
7238: }
7239: }
7240: }
7241: }
1.3 raeburn 7242: return $resulttext;
1.1 raeburn 7243: }
7244:
1.9 raeburn 7245: sub thumb_dimensions {
7246: return ('200','50');
7247: }
7248:
1.16 raeburn 7249: sub check_dimensions {
7250: my ($inputfile) = @_;
7251: my ($fullwidth,$fullheight);
7252: if ($inputfile =~ m|^[/\w.\-]+$|) {
7253: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7254: my $imageinfo = <PIPE>;
7255: if (!close(PIPE)) {
7256: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7257: }
7258: chomp($imageinfo);
7259: my ($fullsize) =
1.21 raeburn 7260: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7261: if ($fullsize) {
7262: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7263: }
7264: }
7265: }
7266: return ($fullwidth,$fullheight);
7267: }
7268:
1.9 raeburn 7269: sub check_configuser {
7270: my ($uhome,$dom,$confname,$servadm) = @_;
7271: my ($configuserok,%currroles);
7272: if ($uhome eq 'no_host') {
7273: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7274: my $configpass = &LONCAPA::Enrollment::create_password();
7275: $configuserok =
7276: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7277: $configpass,'','','','','',undef,$servadm);
7278: } else {
7279: $configuserok = 'ok';
7280: %currroles =
7281: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7282: }
7283: return ($configuserok,%currroles);
7284: }
7285:
7286: sub check_authorstatus {
7287: my ($dom,$confname,%currroles) = @_;
7288: my $author_ok;
1.40 raeburn 7289: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7290: my $start = time;
7291: my $end = 0;
7292: $author_ok =
7293: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7294: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7295: } else {
7296: $author_ok = 'ok';
7297: }
7298: return $author_ok;
7299: }
7300:
7301: sub publishlogo {
1.46 raeburn 7302: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7303: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7304: if ($action eq 'upload') {
7305: $fname=$env{'form.'.$formname.'.filename'};
7306: chop($env{'form.'.$formname});
7307: } else {
7308: ($fname) = ($formname =~ /([^\/]+)$/);
7309: }
1.46 raeburn 7310: if ($savefileas ne '') {
7311: $fname = $savefileas;
7312: }
1.9 raeburn 7313: $fname=&Apache::lonnet::clean_filename($fname);
7314: # See if there is anything left
7315: unless ($fname) { return ('error: no uploaded file'); }
7316: $fname="$subdir/$fname";
1.210 raeburn 7317: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7318: my $filepath="$docroot/priv";
7319: my $relpath = "$dom/$confname";
1.9 raeburn 7320: my ($fnamepath,$file,$fetchthumb);
7321: $file=$fname;
7322: if ($fname=~m|/|) {
7323: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7324: }
1.164 raeburn 7325: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7326: my $count;
1.164 raeburn 7327: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7328: $filepath.="/$parts[$count]";
7329: if ((-e $filepath)!=1) {
7330: mkdir($filepath,02770);
7331: }
7332: }
7333: # Check for bad extension and disallow upload
7334: if ($file=~/\.(\w+)$/ &&
7335: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7336: $output =
1.207 bisitz 7337: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7338: } elsif ($file=~/\.(\w+)$/ &&
7339: !defined(&Apache::loncommon::fileembstyle($1))) {
7340: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7341: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7342: $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 7343: } elsif (-d "$filepath/$file") {
1.195 bisitz 7344: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7345: } else {
7346: my $source = $filepath.'/'.$file;
7347: my $logfile;
7348: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7349: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7350: }
7351: print $logfile
7352: "\n================= Publish ".localtime()." ================\n".
7353: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7354: # Save the file
7355: if (!open(FH,'>'.$source)) {
7356: &Apache::lonnet::logthis('Failed to create '.$source);
7357: return (&mt('Failed to create file'));
7358: }
7359: if ($action eq 'upload') {
7360: if (!print FH ($env{'form.'.$formname})) {
7361: &Apache::lonnet::logthis('Failed to write to '.$source);
7362: return (&mt('Failed to write file'));
7363: }
7364: } else {
7365: my $original = &Apache::lonnet::filelocation('',$formname);
7366: if(!copy($original,$source)) {
7367: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7368: return (&mt('Failed to write file'));
7369: }
7370: }
7371: close(FH);
7372: chmod(0660, $source); # Permissions to rw-rw---.
7373:
7374: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7375: my $copyfile=$targetdir.'/'.$file;
7376:
7377: my @parts=split(/\//,$targetdir);
7378: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7379: for (my $count=5;$count<=$#parts;$count++) {
7380: $path.="/$parts[$count]";
7381: if (!-e $path) {
7382: print $logfile "\nCreating directory ".$path;
7383: mkdir($path,02770);
7384: }
7385: }
7386: my $versionresult;
7387: if (-e $copyfile) {
7388: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7389: } else {
7390: $versionresult = 'ok';
7391: }
7392: if ($versionresult eq 'ok') {
7393: if (copy($source,$copyfile)) {
7394: print $logfile "\nCopied original source to ".$copyfile."\n";
7395: $output = 'ok';
7396: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7397: push(@{$modified_urls},[$copyfile,$source]);
7398: my $metaoutput =
7399: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7400: unless ($registered_cleanup) {
7401: my $handlers = $r->get_handlers('PerlCleanupHandler');
7402: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7403: $registered_cleanup=1;
7404: }
1.9 raeburn 7405: } else {
7406: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7407: $output = &mt('Failed to copy file to RES space').", $!";
7408: }
7409: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7410: my $inputfile = $filepath.'/'.$file;
7411: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7412: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7413: if ($fullwidth ne '' && $fullheight ne '') {
7414: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7415: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7416: system("convert -sample $thumbsize $inputfile $outfile");
7417: chmod(0660, $filepath.'/tn-'.$file);
7418: if (-e $outfile) {
7419: my $copyfile=$targetdir.'/tn-'.$file;
7420: if (copy($outfile,$copyfile)) {
7421: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7422: my $thumb_metaoutput =
7423: &write_metadata($dom,$confname,$formname,
7424: $targetdir,'tn-'.$file,$logfile);
7425: push(@{$modified_urls},[$copyfile,$outfile]);
7426: unless ($registered_cleanup) {
7427: my $handlers = $r->get_handlers('PerlCleanupHandler');
7428: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7429: $registered_cleanup=1;
7430: }
1.267 raeburn 7431: $madethumb = 1;
1.16 raeburn 7432: } else {
7433: print $logfile "\nUnable to write ".$copyfile.
7434: ':'.$!."\n";
7435: }
7436: }
1.9 raeburn 7437: }
7438: }
7439: }
7440: } else {
7441: $output = $versionresult;
7442: }
7443: }
1.267 raeburn 7444: return ($output,$logourl,$madethumb);
1.9 raeburn 7445: }
7446:
7447: sub logo_versioning {
7448: my ($targetdir,$file,$logfile) = @_;
7449: my $target = $targetdir.'/'.$file;
7450: my ($maxversion,$fn,$extn,$output);
7451: $maxversion = 0;
7452: if ($file =~ /^(.+)\.(\w+)$/) {
7453: $fn=$1;
7454: $extn=$2;
7455: }
7456: opendir(DIR,$targetdir);
7457: while (my $filename=readdir(DIR)) {
7458: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7459: $maxversion=($1>$maxversion)?$1:$maxversion;
7460: }
7461: }
7462: $maxversion++;
7463: print $logfile "\nCreating old version ".$maxversion."\n";
7464: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7465: if (copy($target,$copyfile)) {
7466: print $logfile "Copied old target to ".$copyfile."\n";
7467: $copyfile=$copyfile.'.meta';
7468: if (copy($target.'.meta',$copyfile)) {
7469: print $logfile "Copied old target metadata to ".$copyfile."\n";
7470: $output = 'ok';
7471: } else {
7472: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7473: $output = &mt('Failed to copy old meta').", $!, ";
7474: }
7475: } else {
7476: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7477: $output = &mt('Failed to copy old target').", $!, ";
7478: }
7479: return $output;
7480: }
7481:
7482: sub write_metadata {
7483: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7484: my (%metadatafields,%metadatakeys,$output);
7485: $metadatafields{'title'}=$formname;
7486: $metadatafields{'creationdate'}=time;
7487: $metadatafields{'lastrevisiondate'}=time;
7488: $metadatafields{'copyright'}='public';
7489: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7490: $env{'user.domain'};
7491: $metadatafields{'authorspace'}=$confname.':'.$dom;
7492: $metadatafields{'domain'}=$dom;
7493: {
7494: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7495: my $mfh;
1.155 raeburn 7496: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7497: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7498: unless ($_=~/\./) {
7499: my $unikey=$_;
7500: $unikey=~/^([A-Za-z]+)/;
7501: my $tag=$1;
7502: $tag=~tr/A-Z/a-z/;
7503: print $mfh "\n\<$tag";
7504: foreach (split(/\,/,$metadatakeys{$unikey})) {
7505: my $value=$metadatafields{$unikey.'.'.$_};
7506: $value=~s/\"/\'\'/g;
7507: print $mfh ' '.$_.'="'.$value.'"';
7508: }
7509: print $mfh '>'.
7510: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7511: .'</'.$tag.'>';
7512: }
7513: }
7514: $output = 'ok';
7515: print $logfile "\nWrote metadata";
7516: close($mfh);
7517: } else {
7518: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7519: $output = &mt('Could not write metadata');
7520: }
7521: }
1.155 raeburn 7522: return $output;
7523: }
7524:
7525: sub notifysubscribed {
7526: foreach my $targetsource (@{$modified_urls}){
7527: next unless (ref($targetsource) eq 'ARRAY');
7528: my ($target,$source)=@{$targetsource};
7529: if ($source ne '') {
7530: if (open(my $logfh,'>>'.$source.'.log')) {
7531: print $logfh "\nCleanup phase: Notifications\n";
7532: my @subscribed=&subscribed_hosts($target);
7533: foreach my $subhost (@subscribed) {
7534: print $logfh "\nNotifying host ".$subhost.':';
7535: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7536: print $logfh $reply;
7537: }
7538: my @subscribedmeta=&subscribed_hosts("$target.meta");
7539: foreach my $subhost (@subscribedmeta) {
7540: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7541: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7542: $subhost);
7543: print $logfh $reply;
7544: }
7545: print $logfh "\n============ Done ============\n";
1.160 raeburn 7546: close($logfh);
1.155 raeburn 7547: }
7548: }
7549: }
7550: return OK;
7551: }
7552:
7553: sub subscribed_hosts {
7554: my ($target) = @_;
7555: my @subscribed;
7556: if (open(my $fh,"<$target.subscription")) {
7557: while (my $subline=<$fh>) {
7558: if ($subline =~ /^($match_lonid):/) {
7559: my $host = $1;
7560: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7561: unless (grep(/^\Q$host\E$/,@subscribed)) {
7562: push(@subscribed,$host);
7563: }
7564: }
7565: }
7566: }
7567: }
7568: return @subscribed;
1.9 raeburn 7569: }
7570:
7571: sub check_switchserver {
7572: my ($dom,$confname) = @_;
7573: my ($allowed,$switchserver);
7574: my $home = &Apache::lonnet::homeserver($confname,$dom);
7575: if ($home eq 'no_host') {
7576: $home = &Apache::lonnet::domain($dom,'primary');
7577: }
7578: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7579: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7580: if (!$allowed) {
1.180 raeburn 7581: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7582: }
7583: return $switchserver;
7584: }
7585:
1.1 raeburn 7586: sub modify_quotas {
1.216 raeburn 7587: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7588: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7589: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7590: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7591: $validationfieldsref);
1.86 raeburn 7592: if ($action eq 'quotas') {
7593: $context = 'tools';
1.163 raeburn 7594: } else {
1.86 raeburn 7595: $context = $action;
7596: }
7597: if ($context eq 'requestcourses') {
1.216 raeburn 7598: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7599: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7600: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7601: %titles = &courserequest_titles();
7602: $toolregexp = join('|',@usertools);
7603: %conditions = &courserequest_conditions();
1.216 raeburn 7604: $confname = $dom.'-domainconfig';
7605: my $servadm = $r->dir_config('lonAdmEMail');
7606: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7607: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7608: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7609: } elsif ($context eq 'requestauthor') {
7610: @usertools = ('author');
7611: %titles = &authorrequest_titles();
1.86 raeburn 7612: } else {
1.162 raeburn 7613: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7614: %titles = &tool_titles();
1.86 raeburn 7615: }
1.212 raeburn 7616: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7617: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7618: foreach my $key (keys(%env)) {
1.101 raeburn 7619: if ($context eq 'requestcourses') {
7620: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7621: my $item = $1;
7622: my $type = $2;
7623: if ($type =~ /^limit_(.+)/) {
7624: $limithash{$item}{$1} = $env{$key};
7625: } else {
7626: $confhash{$item}{$type} = $env{$key};
7627: }
7628: }
1.163 raeburn 7629: } elsif ($context eq 'requestauthor') {
7630: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7631: $confhash{$1} = $env{$key};
7632: }
1.101 raeburn 7633: } else {
1.86 raeburn 7634: if ($key =~ /^form\.quota_(.+)$/) {
7635: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7636: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7637: $confhash{'authorquota'}{$1} = $env{$key};
7638: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7639: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7640: }
1.72 raeburn 7641: }
7642: }
1.163 raeburn 7643: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7644: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7645: @approvalnotify = sort(@approvalnotify);
7646: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 7647: my @crstypes = ('official','unofficial','community','textbook');
7648: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7649: foreach my $type (@hasuniquecode) {
7650: if (grep(/^\Q$type\E$/,@crstypes)) {
7651: $confhash{'uniquecode'}{$type} = 1;
7652: }
1.216 raeburn 7653: }
1.242 raeburn 7654: my (%newbook,%allpos);
1.216 raeburn 7655: if ($context eq 'requestcourses') {
1.242 raeburn 7656: foreach my $type ('textbooks','templates') {
7657: @{$allpos{$type}} = ();
7658: my $invalid;
7659: if ($type eq 'textbooks') {
7660: $invalid = &mt('Invalid LON-CAPA course for textbook');
7661: } else {
7662: $invalid = &mt('Invalid LON-CAPA course for template');
7663: }
7664: if ($env{'form.'.$type.'_addbook'}) {
7665: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7666: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7667: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7668: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7669: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7670: } else {
7671: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7672: my $position = $env{'form.'.$type.'_addbook_pos'};
7673: $position =~ s/\D+//g;
7674: if ($position ne '') {
7675: $allpos{$type}[$position] = $newbook{$type};
7676: }
1.216 raeburn 7677: }
1.242 raeburn 7678: } else {
7679: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 7680: }
7681: }
1.242 raeburn 7682: }
1.216 raeburn 7683: }
1.102 raeburn 7684: if (ref($domconfig{$action}) eq 'HASH') {
7685: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7686: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7687: $changes{'notify'}{'approval'} = 1;
7688: }
7689: } else {
1.144 raeburn 7690: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7691: $changes{'notify'}{'approval'} = 1;
7692: }
7693: }
1.218 raeburn 7694: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7695: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7696: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7697: unless ($confhash{'uniquecode'}{$crstype}) {
7698: $changes{'uniquecode'} = 1;
7699: }
7700: }
7701: unless ($changes{'uniquecode'}) {
7702: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7703: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7704: $changes{'uniquecode'} = 1;
7705: }
7706: }
7707: }
7708: } else {
7709: $changes{'uniquecode'} = 1;
7710: }
7711: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7712: $changes{'uniquecode'} = 1;
1.216 raeburn 7713: }
7714: if ($context eq 'requestcourses') {
1.242 raeburn 7715: foreach my $type ('textbooks','templates') {
7716: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7717: my %deletions;
7718: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7719: if (@todelete) {
7720: map { $deletions{$_} = 1; } @todelete;
7721: }
7722: my %imgdeletions;
7723: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7724: if (@todeleteimages) {
7725: map { $imgdeletions{$_} = 1; } @todeleteimages;
7726: }
7727: my $maxnum = $env{'form.'.$type.'_maxnum'};
7728: for (my $i=0; $i<=$maxnum; $i++) {
7729: my $itemid = $env{'form.'.$type.'_id_'.$i};
7730: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7731: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7732: if ($deletions{$key}) {
7733: if ($domconfig{$action}{$type}{$key}{'image'}) {
7734: #FIXME need to obsolete item in RES space
7735: }
7736: next;
7737: } else {
7738: my $newpos = $env{'form.'.$itemid};
7739: $newpos =~ s/\D+//g;
1.243 raeburn 7740: foreach my $item ('subject','title','publisher','author') {
7741: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7742: ($type eq 'templates'));
1.242 raeburn 7743: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7744: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7745: $changes{$type}{$key} = 1;
7746: }
7747: }
7748: $allpos{$type}[$newpos] = $key;
7749: }
7750: if ($imgdeletions{$key}) {
7751: $changes{$type}{$key} = 1;
1.216 raeburn 7752: #FIXME need to obsolete item in RES space
1.242 raeburn 7753: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7754: my ($cdom,$cnum) = split(/_/,$key);
7755: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7756: $cdom,$cnum,$type,$configuserok,
7757: $switchserver,$author_ok);
7758: if ($imgurl) {
7759: $confhash{$type}{$key}{'image'} = $imgurl;
7760: $changes{$type}{$key} = 1;
1.216 raeburn 7761: }
1.242 raeburn 7762: if ($error) {
7763: &Apache::lonnet::logthis($error);
7764: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7765: }
7766: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7767: $confhash{$type}{$key}{'image'} =
7768: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7769: }
7770: }
7771: }
7772: }
7773: }
7774: }
1.102 raeburn 7775: } else {
1.144 raeburn 7776: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7777: $changes{'notify'}{'approval'} = 1;
7778: }
1.218 raeburn 7779: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7780: $changes{'uniquecode'} = 1;
7781: }
7782: }
7783: if ($context eq 'requestcourses') {
1.242 raeburn 7784: foreach my $type ('textbooks','templates') {
7785: if ($newbook{$type}) {
7786: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7787: foreach my $item ('subject','title','publisher','author') {
7788: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7789: ($type eq 'template'));
1.242 raeburn 7790: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7791: if ($env{'form.'.$type.'_addbook_'.$item}) {
7792: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7793: }
7794: }
7795: if ($type eq 'textbooks') {
7796: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7797: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7798: my ($imageurl,$error) =
7799: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7800: $configuserok,$switchserver,$author_ok);
7801: if ($imageurl) {
7802: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7803: }
7804: if ($error) {
7805: &Apache::lonnet::logthis($error);
7806: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7807: }
7808: }
1.216 raeburn 7809: }
7810: }
1.242 raeburn 7811: if (@{$allpos{$type}} > 0) {
7812: my $idx = 0;
7813: foreach my $item (@{$allpos{$type}}) {
7814: if ($item ne '') {
7815: $confhash{$type}{$item}{'order'} = $idx;
7816: if (ref($domconfig{$action}) eq 'HASH') {
7817: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7818: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7819: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7820: $changes{$type}{$item} = 1;
7821: }
1.216 raeburn 7822: }
7823: }
7824: }
1.242 raeburn 7825: $idx ++;
1.216 raeburn 7826: }
7827: }
7828: }
7829: }
1.235 raeburn 7830: if (ref($validationitemsref) eq 'ARRAY') {
7831: foreach my $item (@{$validationitemsref}) {
7832: if ($item eq 'fields') {
7833: my @changed;
7834: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7835: if (@{$confhash{'validation'}{$item}} > 0) {
7836: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7837: }
1.266 raeburn 7838: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7839: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7840: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7841: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7842: $domconfig{'requestcourses'}{'validation'}{$item});
7843: } else {
7844: @changed = @{$confhash{'validation'}{$item}};
7845: }
1.235 raeburn 7846: } else {
7847: @changed = @{$confhash{'validation'}{$item}};
7848: }
7849: } else {
7850: @changed = @{$confhash{'validation'}{$item}};
7851: }
7852: if (@changed) {
7853: if ($confhash{'validation'}{$item}) {
7854: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7855: } else {
7856: $changes{'validation'}{$item} = &mt('None');
7857: }
7858: }
7859: } else {
7860: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7861: if ($item eq 'markup') {
7862: if ($env{'form.requestcourses_validation_'.$item}) {
7863: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7864: }
7865: }
1.266 raeburn 7866: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7867: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7868: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7869: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7870: }
7871: } else {
7872: if ($confhash{'validation'}{$item} ne '') {
7873: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7874: }
1.235 raeburn 7875: }
7876: } else {
7877: if ($confhash{'validation'}{$item} ne '') {
7878: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7879: }
7880: }
7881: }
7882: }
7883: }
7884: if ($env{'form.validationdc'}) {
7885: my $newval = $env{'form.validationdc'};
7886: my %domcoords = &get_active_dcs($dom);
7887: if (exists($domcoords{$newval})) {
7888: $confhash{'validation'}{'dc'} = $newval;
7889: }
7890: }
7891: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 7892: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7893: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7894: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7895: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7896: if ($confhash{'validation'}{'dc'} eq '') {
7897: $changes{'validation'}{'dc'} = &mt('None');
7898: } else {
7899: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7900: }
1.235 raeburn 7901: }
1.266 raeburn 7902: } elsif ($confhash{'validation'}{'dc'} ne '') {
7903: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 7904: }
7905: } elsif ($confhash{'validation'}{'dc'} ne '') {
7906: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7907: }
7908: } elsif ($confhash{'validation'}{'dc'} ne '') {
7909: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 7910: }
7911: } else {
7912: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7913: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7914: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7915: $changes{'validation'}{'dc'} = &mt('None');
7916: }
7917: }
1.235 raeburn 7918: }
7919: }
1.102 raeburn 7920: }
7921: } else {
1.86 raeburn 7922: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7923: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7924: }
1.72 raeburn 7925: foreach my $item (@usertools) {
7926: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7927: my $unset;
1.101 raeburn 7928: if ($context eq 'requestcourses') {
1.104 raeburn 7929: $unset = '0';
7930: if ($type eq '_LC_adv') {
7931: $unset = '';
7932: }
1.101 raeburn 7933: if ($confhash{$item}{$type} eq 'autolimit') {
7934: $confhash{$item}{$type} .= '=';
7935: unless ($limithash{$item}{$type} =~ /\D/) {
7936: $confhash{$item}{$type} .= $limithash{$item}{$type};
7937: }
7938: }
1.163 raeburn 7939: } elsif ($context eq 'requestauthor') {
7940: $unset = '0';
7941: if ($type eq '_LC_adv') {
7942: $unset = '';
7943: }
1.72 raeburn 7944: } else {
1.101 raeburn 7945: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7946: $confhash{$item}{$type} = 1;
7947: } else {
7948: $confhash{$item}{$type} = 0;
7949: }
1.72 raeburn 7950: }
1.86 raeburn 7951: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7952: if ($action eq 'requestauthor') {
7953: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7954: $changes{$type} = 1;
7955: }
7956: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7957: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7958: $changes{$item}{$type} = 1;
7959: }
7960: } else {
7961: if ($context eq 'requestcourses') {
1.104 raeburn 7962: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7963: $changes{$item}{$type} = 1;
7964: }
7965: } else {
7966: if (!$confhash{$item}{$type}) {
7967: $changes{$item}{$type} = 1;
7968: }
7969: }
7970: }
7971: } else {
7972: if ($context eq 'requestcourses') {
1.104 raeburn 7973: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7974: $changes{$item}{$type} = 1;
7975: }
1.163 raeburn 7976: } elsif ($context eq 'requestauthor') {
7977: if ($confhash{$type} ne $unset) {
7978: $changes{$type} = 1;
7979: }
1.72 raeburn 7980: } else {
7981: if (!$confhash{$item}{$type}) {
7982: $changes{$item}{$type} = 1;
7983: }
7984: }
7985: }
1.1 raeburn 7986: }
7987: }
1.163 raeburn 7988: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7989: if (ref($domconfig{'quotas'}) eq 'HASH') {
7990: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7991: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7992: if (exists($confhash{'defaultquota'}{$key})) {
7993: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7994: $changes{'defaultquota'}{$key} = 1;
7995: }
7996: } else {
7997: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7998: }
7999: }
1.86 raeburn 8000: } else {
8001: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8002: if (exists($confhash{'defaultquota'}{$key})) {
8003: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8004: $changes{'defaultquota'}{$key} = 1;
8005: }
8006: } else {
8007: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8008: }
1.1 raeburn 8009: }
8010: }
1.197 raeburn 8011: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8012: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8013: if (exists($confhash{'authorquota'}{$key})) {
8014: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8015: $changes{'authorquota'}{$key} = 1;
8016: }
8017: } else {
8018: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8019: }
8020: }
8021: }
1.1 raeburn 8022: }
1.86 raeburn 8023: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8024: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8025: if (ref($domconfig{'quotas'}) eq 'HASH') {
8026: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8027: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8028: $changes{'defaultquota'}{$key} = 1;
8029: }
8030: } else {
8031: if (!exists($domconfig{'quotas'}{$key})) {
8032: $changes{'defaultquota'}{$key} = 1;
8033: }
1.72 raeburn 8034: }
8035: } else {
1.86 raeburn 8036: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8037: }
1.1 raeburn 8038: }
8039: }
1.197 raeburn 8040: if (ref($confhash{'authorquota'}) eq 'HASH') {
8041: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8042: if (ref($domconfig{'quotas'}) eq 'HASH') {
8043: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8044: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8045: $changes{'authorquota'}{$key} = 1;
8046: }
8047: } else {
8048: $changes{'authorquota'}{$key} = 1;
8049: }
8050: } else {
8051: $changes{'authorquota'}{$key} = 1;
8052: }
8053: }
8054: }
1.1 raeburn 8055: }
1.72 raeburn 8056:
1.163 raeburn 8057: if ($context eq 'requestauthor') {
8058: $domdefaults{'requestauthor'} = \%confhash;
8059: } else {
8060: foreach my $key (keys(%confhash)) {
1.242 raeburn 8061: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8062: $domdefaults{$key} = $confhash{$key};
8063: }
1.163 raeburn 8064: }
1.72 raeburn 8065: }
1.163 raeburn 8066:
1.1 raeburn 8067: my %quotahash = (
1.86 raeburn 8068: $action => { %confhash }
1.1 raeburn 8069: );
8070: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8071: $dom);
8072: if ($putresult eq 'ok') {
8073: if (keys(%changes) > 0) {
1.72 raeburn 8074: my $cachetime = 24*60*60;
8075: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8076: if (ref($lastactref) eq 'HASH') {
8077: $lastactref->{'domdefaults'} = 1;
8078: }
1.1 raeburn 8079: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8080: unless (($context eq 'requestcourses') ||
1.163 raeburn 8081: ($context eq 'requestauthor')) {
1.86 raeburn 8082: if (ref($changes{'defaultquota'}) eq 'HASH') {
8083: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8084: foreach my $type (@{$types},'default') {
8085: if (defined($changes{'defaultquota'}{$type})) {
8086: my $typetitle = $usertypes->{$type};
8087: if ($type eq 'default') {
8088: $typetitle = $othertitle;
8089: }
1.213 raeburn 8090: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8091: }
8092: }
1.86 raeburn 8093: $resulttext .= '</ul></li>';
1.72 raeburn 8094: }
1.197 raeburn 8095: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8096: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8097: foreach my $type (@{$types},'default') {
8098: if (defined($changes{'authorquota'}{$type})) {
8099: my $typetitle = $usertypes->{$type};
8100: if ($type eq 'default') {
8101: $typetitle = $othertitle;
8102: }
1.213 raeburn 8103: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8104: }
8105: }
8106: $resulttext .= '</ul></li>';
8107: }
1.72 raeburn 8108: }
1.80 raeburn 8109: my %newenv;
1.72 raeburn 8110: foreach my $item (@usertools) {
1.163 raeburn 8111: my (%haschgs,%inconf);
8112: if ($context eq 'requestauthor') {
8113: %haschgs = %changes;
1.210 raeburn 8114: %inconf = %confhash;
1.163 raeburn 8115: } else {
8116: if (ref($changes{$item}) eq 'HASH') {
8117: %haschgs = %{$changes{$item}};
8118: }
8119: if (ref($confhash{$item}) eq 'HASH') {
8120: %inconf = %{$confhash{$item}};
8121: }
8122: }
8123: if (keys(%haschgs) > 0) {
1.80 raeburn 8124: my $newacc =
8125: &Apache::lonnet::usertools_access($env{'user.name'},
8126: $env{'user.domain'},
1.86 raeburn 8127: $item,'reload',$context);
1.210 raeburn 8128: if (($context eq 'requestcourses') ||
1.163 raeburn 8129: ($context eq 'requestauthor')) {
1.108 raeburn 8130: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8131: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8132: }
8133: } else {
8134: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8135: $newenv{'environment.availabletools.'.$item} = $newacc;
8136: }
1.80 raeburn 8137: }
1.163 raeburn 8138: unless ($context eq 'requestauthor') {
8139: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8140: }
1.72 raeburn 8141: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8142: if ($haschgs{$type}) {
1.72 raeburn 8143: my $typetitle = $usertypes->{$type};
8144: if ($type eq 'default') {
8145: $typetitle = $othertitle;
8146: } elsif ($type eq '_LC_adv') {
8147: $typetitle = 'LON-CAPA Advanced Users';
8148: }
1.163 raeburn 8149: if ($inconf{$type}) {
1.101 raeburn 8150: if ($context eq 'requestcourses') {
8151: my $cond;
1.163 raeburn 8152: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8153: if ($1 eq '') {
8154: $cond = &mt('(Automatic processing of any request).');
8155: } else {
8156: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8157: }
8158: } else {
1.163 raeburn 8159: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8160: }
8161: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8162: } elsif ($context eq 'requestauthor') {
8163: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8164: $titles{$inconf{$type}},$typetitle);
8165:
1.101 raeburn 8166: } else {
8167: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8168: }
1.72 raeburn 8169: } else {
1.104 raeburn 8170: if ($type eq '_LC_adv') {
1.163 raeburn 8171: if ($inconf{$type} eq '0') {
1.104 raeburn 8172: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8173: } else {
8174: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8175: }
8176: } else {
8177: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8178: }
1.72 raeburn 8179: }
8180: }
1.26 raeburn 8181: }
1.163 raeburn 8182: unless ($context eq 'requestauthor') {
8183: $resulttext .= '</ul></li>';
8184: }
1.26 raeburn 8185: }
1.1 raeburn 8186: }
1.163 raeburn 8187: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8188: if (ref($changes{'notify'}) eq 'HASH') {
8189: if ($changes{'notify'}{'approval'}) {
8190: if (ref($confhash{'notify'}) eq 'HASH') {
8191: if ($confhash{'notify'}{'approval'}) {
8192: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8193: } else {
1.163 raeburn 8194: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8195: }
8196: }
8197: }
8198: }
8199: }
1.216 raeburn 8200: if ($action eq 'requestcourses') {
8201: my @offon = ('off','on');
8202: if ($changes{'uniquecode'}) {
1.218 raeburn 8203: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8204: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8205: $resulttext .= '<li>'.
8206: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8207: '</li>';
8208: } else {
8209: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8210: '</li>';
8211: }
1.216 raeburn 8212: }
1.242 raeburn 8213: foreach my $type ('textbooks','templates') {
8214: if (ref($changes{$type}) eq 'HASH') {
8215: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8216: foreach my $key (sort(keys(%{$changes{$type}}))) {
8217: my %coursehash = &Apache::lonnet::coursedescription($key);
8218: my $coursetitle = $coursehash{'description'};
8219: my $position = $confhash{$type}{$key}{'order'} + 1;
8220: $resulttext .= '<li>';
1.243 raeburn 8221: foreach my $item ('subject','title','publisher','author') {
8222: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8223: ($type eq 'templates'));
1.242 raeburn 8224: my $name = $item.':';
8225: $name =~ s/^(\w)/\U$1/;
8226: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8227: }
8228: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8229: if ($type eq 'textbooks') {
8230: if ($confhash{$type}{$key}{'image'}) {
8231: $resulttext .= ' '.&mt('Image: [_1]',
8232: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8233: ' alt="Textbook cover" />').'<br />';
8234: }
8235: }
8236: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8237: }
1.242 raeburn 8238: $resulttext .= '</ul></li>';
1.216 raeburn 8239: }
8240: }
1.235 raeburn 8241: if (ref($changes{'validation'}) eq 'HASH') {
8242: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8243: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8244: foreach my $item (@{$validationitemsref}) {
8245: if (exists($changes{'validation'}{$item})) {
8246: if ($item eq 'markup') {
8247: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8248: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8249: } else {
8250: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8251: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8252: }
8253: }
8254: }
8255: if (exists($changes{'validation'}{'dc'})) {
8256: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8257: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8258: }
8259: }
8260: }
1.216 raeburn 8261: }
1.1 raeburn 8262: $resulttext .= '</ul>';
1.80 raeburn 8263: if (keys(%newenv)) {
8264: &Apache::lonnet::appenv(\%newenv);
8265: }
1.1 raeburn 8266: } else {
1.86 raeburn 8267: if ($context eq 'requestcourses') {
8268: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8269: } elsif ($context eq 'requestauthor') {
8270: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8271: } else {
1.90 weissno 8272: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8273: }
1.1 raeburn 8274: }
8275: } else {
1.11 albertel 8276: $resulttext = '<span class="LC_error">'.
8277: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8278: }
1.216 raeburn 8279: if ($errors) {
8280: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8281: '<ul>'.$errors.'</ul></p>';
8282: }
1.3 raeburn 8283: return $resulttext;
1.1 raeburn 8284: }
8285:
1.216 raeburn 8286: sub process_textbook_image {
1.242 raeburn 8287: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8288: my $filename = $env{'form.'.$caller.'.filename'};
8289: my ($error,$url);
8290: my ($width,$height) = (50,50);
8291: if ($configuserok eq 'ok') {
8292: if ($switchserver) {
8293: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8294: $switchserver);
8295: } elsif ($author_ok eq 'ok') {
8296: my ($result,$imageurl) =
8297: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8298: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8299: if ($result eq 'ok') {
8300: $url = $imageurl;
8301: } else {
8302: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8303: }
8304: } else {
8305: $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);
8306: }
8307: } else {
8308: $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);
8309: }
8310: return ($url,$error);
8311: }
8312:
1.267 raeburn 8313: sub modify_ltitools {
8314: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8315: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8316: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8317: my $confname = $dom.'-domainconfig';
8318: my $servadm = $r->dir_config('lonAdmEMail');
8319: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8320: my (%posslti,%possfield);
8321: my @courseroles = ('cc','in','ta','ep','st');
8322: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8323: map { $posslti{$_} = 1; } @ltiroles;
8324: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8325: map { $possfield{$_} = 1; } @allfields;
8326: my %lt = <itools_names();
8327: if ($env{'form.ltitools_add'}) {
8328: my $title = $env{'form.ltitools_add_title'};
8329: $title =~ s/(`)/'/g;
8330: ($newid,my $error) = &get_ltitools_id($dom,$title);
8331: if ($newid) {
8332: my $position = $env{'form.ltitools_add_pos'};
8333: $position =~ s/\D+//g;
8334: if ($position ne '') {
8335: $allpos[$position] = $newid;
8336: }
8337: $changes{$newid} = 1;
8338: foreach my $item ('title','url','key','secret') {
8339: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8340: if ($env{'form.ltitools_add_'.$item}) {
8341: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8342: }
8343: }
8344: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8345: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8346: }
8347: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8348: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8349: }
8350: foreach my $item ('width','height') {
8351: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8352: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8353: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8354: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8355: }
8356: }
8357: if ($env{'form.ltitools_add_target'} eq 'window') {
8358: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8359: } else {
8360: $confhash{$newid}{'display'}{'target'} = 'iframe';
8361: }
8362: foreach my $item ('passback','roster') {
8363: if ($env{'form.ltitools_add_'.$item}) {
8364: $confhash{$newid}{$item} = 1;
8365: }
8366: }
8367: if ($env{'form.ltitools_add_image.filename'} ne '') {
8368: my ($imageurl,$error) =
8369: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8370: $configuserok,$switchserver,$author_ok);
8371: if ($imageurl) {
8372: $confhash{$newid}{'image'} = $imageurl;
8373: }
8374: if ($error) {
8375: &Apache::lonnet::logthis($error);
8376: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8377: }
8378: }
8379: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8380: foreach my $field (@fields) {
8381: if ($possfield{$field}) {
8382: if ($field eq 'roles') {
8383: foreach my $role (@courseroles) {
8384: my $choice = $env{'form.ltitools_add_roles_'.$role};
8385: if (($choice ne '') && ($posslti{$choice})) {
8386: $confhash{$newid}{'roles'}{$role} = $choice;
8387: if ($role eq 'cc') {
8388: $confhash{$newid}{'roles'}{'co'} = $choice;
8389: }
8390: }
8391: }
8392: } else {
8393: $confhash{$newid}{'fields'}{$field} = 1;
8394: }
8395: }
8396: }
8397: if ($env{'form.ltitools_add_custom'}) {
8398: my $name = $env{'form.ltitools_add_custom_name'};
8399: my $value = $env{'form.ltitools_add_custom_value'};
8400: $value =~ s/(`)/'/g;
8401: $name =~ s/(`)/'/g;
8402: $confhash{$newid}{'custom'}{$name} = $value;
8403: }
8404: } else {
8405: my $error = &mt('Failed to acquire unique ID for new external tool');
8406: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8407: }
8408: }
8409: if (ref($domconfig{$action}) eq 'HASH') {
8410: my %deletions;
8411: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8412: if (@todelete) {
8413: map { $deletions{$_} = 1; } @todelete;
8414: }
8415: my %customadds;
8416: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8417: if (@newcustom) {
8418: map { $customadds{$_} = 1; } @newcustom;
8419: }
8420: my %imgdeletions;
8421: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8422: if (@todeleteimages) {
8423: map { $imgdeletions{$_} = 1; } @todeleteimages;
8424: }
8425: my $maxnum = $env{'form.ltitools_maxnum'};
8426: for (my $i=0; $i<=$maxnum; $i++) {
8427: my $itemid = $env{'form.ltitools_id_'.$i};
8428: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8429: if ($deletions{$itemid}) {
8430: if ($domconfig{$action}{$itemid}{'image'}) {
8431: #FIXME need to obsolete item in RES space
8432: }
8433: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8434: next;
8435: } else {
8436: my $newpos = $env{'form.ltitools_'.$itemid};
8437: $newpos =~ s/\D+//g;
8438: foreach my $item ('title','url','key','secret') {
8439: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8440: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8441: $changes{$itemid} = 1;
8442: }
8443: }
8444: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8445: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8446: }
8447: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8448: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8449: }
8450: foreach my $size ('width','height') {
8451: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8452: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8453: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8454: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8455: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8456: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8457: $changes{$itemid} = 1;
8458: }
8459: } else {
8460: $changes{$itemid} = 1;
8461: }
8462: }
8463: }
8464: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8465: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8466: } else {
8467: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8468: }
8469: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8470: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8471: $changes{$itemid} = 1;
8472: }
8473: } else {
8474: $changes{$itemid} = 1;
8475: }
8476: foreach my $extra ('passback','roster') {
8477: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8478: $confhash{$itemid}{$extra} = 1;
8479: }
8480: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8481: $changes{$itemid} = 1;
8482: }
8483: }
8484: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8485: foreach my $field (@fields) {
8486: if ($possfield{$field}) {
8487: if ($field eq 'roles') {
8488: foreach my $role (@courseroles) {
8489: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8490: if (($choice ne '') && ($posslti{$choice})) {
8491: $confhash{$itemid}{'roles'}{$role} = $choice;
8492: if ($role eq 'cc') {
8493: $confhash{$itemid}{'roles'}{'co'} = $choice;
8494: }
8495: }
8496: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8497: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8498: $changes{$itemid} = 1;
8499: }
8500: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8501: $changes{$itemid} = 1;
8502: }
8503: }
8504: } else {
8505: $confhash{$itemid}{'fields'}{$field} = 1;
8506: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8507: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8508: $changes{$itemid} = 1;
8509: }
8510: } else {
8511: $changes{$itemid} = 1;
8512: }
8513: }
8514: }
8515: }
8516: $allpos[$newpos] = $itemid;
8517: }
8518: if ($imgdeletions{$itemid}) {
8519: $changes{$itemid} = 1;
8520: #FIXME need to obsolete item in RES space
8521: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8522: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8523: $itemid,$configuserok,$switchserver,
8524: $author_ok);
8525: if ($imgurl) {
8526: $confhash{$itemid}{'image'} = $imgurl;
8527: $changes{$itemid} = 1;
8528: }
8529: if ($error) {
8530: &Apache::lonnet::logthis($error);
8531: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8532: }
8533: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8534: $confhash{$itemid}{'image'} =
8535: $domconfig{$action}{$itemid}{'image'};
8536: }
8537: if ($customadds{$i}) {
8538: my $name = $env{'form.ltitools_custom_name_'.$i};
8539: $name =~ s/(`)/'/g;
8540: $name =~ s/^\s+//;
8541: $name =~ s/\s+$//;
8542: my $value = $env{'form.ltitools_custom_value_'.$i};
8543: $value =~ s/(`)/'/g;
8544: $value =~ s/^\s+//;
8545: $value =~ s/\s+$//;
8546: if ($name ne '') {
8547: $confhash{$itemid}{'custom'}{$name} = $value;
8548: $changes{$itemid} = 1;
8549: }
8550: }
8551: my %customdels;
8552: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8553: if (@customdeletions) {
8554: $changes{$itemid} = 1;
8555: }
8556: map { $customdels{$_} = 1; } @customdeletions;
8557: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8558: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8559: unless ($customdels{$key}) {
8560: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8561: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8562: }
8563: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8564: $changes{$itemid} = 1;
8565: }
8566: }
8567: }
8568: }
8569: unless ($changes{$itemid}) {
8570: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8571: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8572: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8573: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8574: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8575: $changes{$itemid} = 1;
8576: last;
8577: }
8578: }
8579: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8580: $changes{$itemid} = 1;
8581: }
8582: }
8583: last if ($changes{$itemid});
8584: }
8585: }
8586: }
8587: }
8588: }
8589: if (@allpos > 0) {
8590: my $idx = 0;
8591: foreach my $itemid (@allpos) {
8592: if ($itemid ne '') {
8593: $confhash{$itemid}{'order'} = $idx;
8594: if (ref($domconfig{$action}) eq 'HASH') {
8595: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8596: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8597: $changes{$itemid} = 1;
8598: }
8599: }
8600: }
8601: $idx ++;
8602: }
8603: }
8604: }
8605: my %ltitoolshash = (
8606: $action => { %confhash }
8607: );
8608: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8609: $dom);
8610: if ($putresult eq 'ok') {
8611: if (keys(%changes) > 0) {
8612: my $cachetime = 24*60*60;
8613: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8614: if (ref($lastactref) eq 'HASH') {
8615: $lastactref->{'ltitools'} = 1;
8616: }
8617: $resulttext = &mt('Changes made:').'<ul>';
8618: my %bynum;
8619: foreach my $itemid (sort(keys(%changes))) {
8620: my $position = $confhash{$itemid}{'order'};
8621: $bynum{$position} = $itemid;
8622: }
8623: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8624: my $itemid = $bynum{$pos};
8625: if (ref($confhash{$itemid}) ne 'HASH') {
8626: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8627: } else {
8628: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8629: if ($confhash{$itemid}{'image'}) {
8630: $resulttext .= ' '.
8631: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8632: ' alt="'.&mt('Tool Provider icon').'" />';
8633: }
8634: $resulttext .= '</li><ul>';
8635: my $position = $pos + 1;
8636: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8637: foreach my $item ('version','msgtype','url','key') {
8638: if ($confhash{$itemid}{$item} ne '') {
8639: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8640: }
8641: }
8642: if ($confhash{$itemid}{'secret'} ne '') {
8643: $resulttext .= '<li>'.$lt{'secret'}.': ';
8644: my $num = length($confhash{$itemid}{'secret'});
8645: $resulttext .= ('*'x$num).'</li>';
8646: }
8647: foreach my $item ('passback','roster') {
8648: $resulttext .= '<li>'.$lt{$item}.' ';
8649: if ($confhash{$itemid}{$item}) {
8650: $resulttext .= &mt('Yes');
8651: } else {
8652: $resulttext .= &mt('No');
8653: }
8654: $resulttext .= '</li>';
8655: }
8656: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
8657: my $displaylist;
8658: if ($confhash{$itemid}{'display'}{'target'}) {
8659: $displaylist = &mt('Display target').': '.
8660: $confhash{$itemid}{'display'}{'target'}.',';
8661: }
8662: foreach my $size ('width','height') {
8663: if ($confhash{$itemid}{'display'}{$size}) {
8664: $displaylist .= (' 'x2).$lt{$size}.': '.
8665: $confhash{$itemid}{'display'}{$size}.',';
8666: }
8667: }
8668: if ($displaylist) {
8669: $displaylist =~ s/,$//;
8670: $resulttext .= '<li>'.$displaylist.'</li>';
8671: }
8672: }
8673: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
8674: my $fieldlist;
8675: foreach my $field (@allfields) {
8676: if ($confhash{$itemid}{'fields'}{$field}) {
8677: $fieldlist .= (' 'x2).$lt{$field}.',';
8678: }
8679: }
8680: if ($fieldlist) {
8681: $fieldlist =~ s/,$//;
8682: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
8683: }
8684: }
8685: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
8686: my $rolemaps;
8687: foreach my $role (@courseroles) {
8688: if ($confhash{$itemid}{'roles'}{$role}) {
8689: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
8690: $confhash{$itemid}{'roles'}{$role}.',';
8691: }
8692: }
8693: if ($rolemaps) {
8694: $rolemaps =~ s/,$//;
8695: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
8696: }
8697: }
8698: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
8699: my $customlist;
8700: if (keys(%{$confhash{$itemid}{'custom'}})) {
8701: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
8702: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
8703: }
8704: }
8705: if ($customlist) {
8706: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
8707: }
8708: }
8709: $resulttext .= '</ul></li>';
8710: }
8711: }
8712: $resulttext .= '</ul>';
8713: } else {
8714: $resulttext = &mt('No changes made.');
8715: }
8716: } else {
8717: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
8718: }
8719: if ($errors) {
8720: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8721: $errors.'</ul>';
8722: }
8723: return $resulttext;
8724: }
8725:
8726: sub process_ltitools_image {
8727: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
8728: my $filename = $env{'form.'.$caller.'.filename'};
8729: my ($error,$url);
8730: my ($width,$height) = (21,21);
8731: if ($configuserok eq 'ok') {
8732: if ($switchserver) {
8733: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
8734: $switchserver);
8735: } elsif ($author_ok eq 'ok') {
8736: my ($result,$imageurl,$madethumb) =
8737: &publishlogo($r,'upload',$caller,$dom,$confname,
8738: "ltitools/$itemid/icon",$width,$height);
8739: if ($result eq 'ok') {
8740: if ($madethumb) {
8741: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
8742: my $imagethumb = "$path/tn-".$imagefile;
8743: $url = $imagethumb;
8744: } else {
8745: $url = $imageurl;
8746: }
8747: } else {
8748: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8749: }
8750: } else {
8751: $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);
8752: }
8753: } else {
8754: $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);
8755: }
8756: return ($url,$error);
8757: }
8758:
8759: sub get_ltitools_id {
8760: my ($cdom,$title) = @_;
8761: # get lock on ltitools db
8762: my $lockhash = {
8763: lock => $env{'user.name'}.
8764: ':'.$env{'user.domain'},
8765: };
8766: my $tries = 0;
8767: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
8768: my ($id,$error);
8769:
8770: while (($gotlock ne 'ok') && ($tries<10)) {
8771: $tries ++;
8772: sleep (0.1);
8773: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
8774: }
8775: if ($gotlock eq 'ok') {
8776: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
8777: if ($currids{'lock'}) {
8778: delete($currids{'lock'});
8779: if (keys(%currids)) {
8780: my @curr = sort { $a <=> $b } keys(%currids);
8781: if ($curr[-1] =~ /^\d+$/) {
8782: $id = 1 + $curr[-1];
8783: }
8784: } else {
8785: $id = 1;
8786: }
8787: if ($id) {
8788: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
8789: $error = 'nostore';
8790: }
8791: } else {
8792: $error = 'nonumber';
8793: }
8794: }
8795: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
8796: } else {
8797: $error = 'nolock';
8798: }
8799: return ($id,$error);
8800: }
8801:
1.3 raeburn 8802: sub modify_autoenroll {
1.205 raeburn 8803: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8804: my ($resulttext,%changes);
8805: my %currautoenroll;
8806: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8807: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8808: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8809: }
8810: }
8811: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8812: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8813: sender => 'Sender for notification messages',
8814: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 8815: my @offon = ('off','on');
1.17 raeburn 8816: my $sender_uname = $env{'form.sender_uname'};
8817: my $sender_domain = $env{'form.sender_domain'};
8818: if ($sender_domain eq '') {
8819: $sender_uname = '';
8820: } elsif ($sender_uname eq '') {
8821: $sender_domain = '';
8822: }
1.129 raeburn 8823: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 8824: my %autoenrollhash = (
1.129 raeburn 8825: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8826: 'sender_uname' => $sender_uname,
8827: 'sender_domain' => $sender_domain,
8828: 'co-owners' => $coowners,
1.1 raeburn 8829: }
8830: );
1.4 raeburn 8831: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8832: $dom);
1.1 raeburn 8833: if ($putresult eq 'ok') {
8834: if (exists($currautoenroll{'run'})) {
8835: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8836: $changes{'run'} = 1;
8837: }
8838: } elsif ($autorun) {
8839: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8840: $changes{'run'} = 1;
1.1 raeburn 8841: }
8842: }
1.17 raeburn 8843: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8844: $changes{'sender'} = 1;
8845: }
1.17 raeburn 8846: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8847: $changes{'sender'} = 1;
8848: }
1.129 raeburn 8849: if ($currautoenroll{'co-owners'} ne '') {
8850: if ($currautoenroll{'co-owners'} ne $coowners) {
8851: $changes{'coowners'} = 1;
8852: }
8853: } elsif ($coowners) {
8854: $changes{'coowners'} = 1;
8855: }
1.1 raeburn 8856: if (keys(%changes) > 0) {
8857: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8858: if ($changes{'run'}) {
1.1 raeburn 8859: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8860: }
8861: if ($changes{'sender'}) {
1.17 raeburn 8862: if ($sender_uname eq '' || $sender_domain eq '') {
8863: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8864: } else {
8865: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8866: }
1.1 raeburn 8867: }
1.129 raeburn 8868: if ($changes{'coowners'}) {
8869: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8870: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8871: if (ref($lastactref) eq 'HASH') {
8872: $lastactref->{'domainconfig'} = 1;
8873: }
1.129 raeburn 8874: }
1.1 raeburn 8875: $resulttext .= '</ul>';
8876: } else {
8877: $resulttext = &mt('No changes made to auto-enrollment settings');
8878: }
8879: } else {
1.11 albertel 8880: $resulttext = '<span class="LC_error">'.
8881: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8882: }
1.3 raeburn 8883: return $resulttext;
1.1 raeburn 8884: }
8885:
8886: sub modify_autoupdate {
1.3 raeburn 8887: my ($dom,%domconfig) = @_;
1.1 raeburn 8888: my ($resulttext,%currautoupdate,%fields,%changes);
8889: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8890: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8891: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8892: }
8893: }
8894: my @offon = ('off','on');
8895: my %title = &Apache::lonlocal::texthash (
8896: run => 'Auto-update:',
8897: classlists => 'Updates to user information in classlists?'
8898: );
1.44 raeburn 8899: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8900: my %fieldtitles = &Apache::lonlocal::texthash (
8901: id => 'Student/Employee ID',
1.20 raeburn 8902: permanentemail => 'E-mail address',
1.1 raeburn 8903: lastname => 'Last Name',
8904: firstname => 'First Name',
8905: middlename => 'Middle Name',
1.132 raeburn 8906: generation => 'Generation',
1.1 raeburn 8907: );
1.142 raeburn 8908: $othertitle = &mt('All users');
1.1 raeburn 8909: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8910: $othertitle = &mt('Other users');
1.1 raeburn 8911: }
8912: foreach my $key (keys(%env)) {
8913: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8914: my ($usertype,$item) = ($1,$2);
8915: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8916: if ($usertype eq 'default') {
8917: push(@{$fields{$1}},$2);
8918: } elsif (ref($types) eq 'ARRAY') {
8919: if (grep(/^\Q$usertype\E$/,@{$types})) {
8920: push(@{$fields{$1}},$2);
8921: }
8922: }
8923: }
1.1 raeburn 8924: }
8925: }
1.131 raeburn 8926: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8927: @lockablenames = sort(@lockablenames);
8928: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8929: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8930: if (@changed) {
8931: $changes{'lockablenames'} = 1;
8932: }
8933: } else {
8934: if (@lockablenames) {
8935: $changes{'lockablenames'} = 1;
8936: }
8937: }
1.1 raeburn 8938: my %updatehash = (
8939: autoupdate => { run => $env{'form.autoupdate_run'},
8940: classlists => $env{'form.classlists'},
8941: fields => {%fields},
1.131 raeburn 8942: lockablenames => \@lockablenames,
1.1 raeburn 8943: }
8944: );
8945: foreach my $key (keys(%currautoupdate)) {
8946: if (($key eq 'run') || ($key eq 'classlists')) {
8947: if (exists($updatehash{autoupdate}{$key})) {
8948: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8949: $changes{$key} = 1;
8950: }
8951: }
8952: } elsif ($key eq 'fields') {
8953: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8954: foreach my $item (@{$types},'default') {
1.1 raeburn 8955: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8956: my $change = 0;
8957: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8958: if (!exists($fields{$item})) {
8959: $change = 1;
1.132 raeburn 8960: last;
1.1 raeburn 8961: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8962: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8963: $change = 1;
1.132 raeburn 8964: last;
1.1 raeburn 8965: }
8966: }
8967: }
8968: if ($change) {
8969: push(@{$changes{$key}},$item);
8970: }
1.26 raeburn 8971: }
1.1 raeburn 8972: }
8973: }
1.131 raeburn 8974: } elsif ($key eq 'lockablenames') {
8975: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8976: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8977: if (@changed) {
8978: $changes{'lockablenames'} = 1;
8979: }
8980: } else {
8981: if (@lockablenames) {
8982: $changes{'lockablenames'} = 1;
8983: }
8984: }
8985: }
8986: }
8987: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8988: if (@lockablenames) {
8989: $changes{'lockablenames'} = 1;
1.1 raeburn 8990: }
8991: }
1.26 raeburn 8992: foreach my $item (@{$types},'default') {
8993: if (defined($fields{$item})) {
8994: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8995: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8996: my $change = 0;
8997: if (ref($fields{$item}) eq 'ARRAY') {
8998: foreach my $type (@{$fields{$item}}) {
8999: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9000: $change = 1;
9001: last;
9002: }
9003: }
9004: }
9005: if ($change) {
9006: push(@{$changes{'fields'}},$item);
9007: }
9008: } else {
1.26 raeburn 9009: push(@{$changes{'fields'}},$item);
9010: }
9011: } else {
9012: push(@{$changes{'fields'}},$item);
1.1 raeburn 9013: }
9014: }
9015: }
9016: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9017: $dom);
9018: if ($putresult eq 'ok') {
9019: if (keys(%changes) > 0) {
9020: $resulttext = &mt('Changes made:').'<ul>';
9021: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9022: if ($key eq 'lockablenames') {
9023: $resulttext .= '<li>';
9024: if (@lockablenames) {
9025: $usertypes->{'default'} = $othertitle;
9026: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9027: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9028: } else {
9029: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9030: }
9031: $resulttext .= '</li>';
9032: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9033: foreach my $item (@{$changes{$key}}) {
9034: my @newvalues;
9035: foreach my $type (@{$fields{$item}}) {
9036: push(@newvalues,$fieldtitles{$type});
9037: }
1.3 raeburn 9038: my $newvaluestr;
9039: if (@newvalues > 0) {
9040: $newvaluestr = join(', ',@newvalues);
9041: } else {
9042: $newvaluestr = &mt('none');
1.6 raeburn 9043: }
1.1 raeburn 9044: if ($item eq 'default') {
1.26 raeburn 9045: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9046: } else {
1.26 raeburn 9047: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9048: }
9049: }
9050: } else {
9051: my $newvalue;
9052: if ($key eq 'run') {
9053: $newvalue = $offon[$env{'form.autoupdate_run'}];
9054: } else {
9055: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9056: }
1.1 raeburn 9057: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9058: }
9059: }
9060: $resulttext .= '</ul>';
9061: } else {
1.3 raeburn 9062: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9063: }
9064: } else {
1.11 albertel 9065: $resulttext = '<span class="LC_error">'.
9066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9067: }
1.3 raeburn 9068: return $resulttext;
1.1 raeburn 9069: }
9070:
1.125 raeburn 9071: sub modify_autocreate {
9072: my ($dom,%domconfig) = @_;
9073: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9074: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9075: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9076: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9077: }
9078: }
9079: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9080: req => 'Auto-creation of validated requests for official courses',
9081: xmldc => 'Identity of course creator of courses from XML files',
9082: );
9083: my @types = ('xml','req');
9084: foreach my $item (@types) {
9085: $newvals{$item} = $env{'form.autocreate_'.$item};
9086: $newvals{$item} =~ s/\D//g;
9087: $newvals{$item} = 0 if ($newvals{$item} eq '');
9088: }
9089: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9090: my %domcoords = &get_active_dcs($dom);
9091: unless (exists($domcoords{$newvals{'xmldc'}})) {
9092: $newvals{'xmldc'} = '';
9093: }
9094: %autocreatehash = (
9095: autocreate => { xml => $newvals{'xml'},
9096: req => $newvals{'req'},
9097: }
9098: );
9099: if ($newvals{'xmldc'} ne '') {
9100: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9101: }
9102: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9103: $dom);
9104: if ($putresult eq 'ok') {
9105: my @items = @types;
9106: if ($newvals{'xml'}) {
9107: push(@items,'xmldc');
9108: }
9109: foreach my $item (@items) {
9110: if (exists($currautocreate{$item})) {
9111: if ($currautocreate{$item} ne $newvals{$item}) {
9112: $changes{$item} = 1;
9113: }
9114: } elsif ($newvals{$item}) {
9115: $changes{$item} = 1;
9116: }
9117: }
9118: if (keys(%changes) > 0) {
9119: my @offon = ('off','on');
9120: $resulttext = &mt('Changes made:').'<ul>';
9121: foreach my $item (@types) {
9122: if ($changes{$item}) {
9123: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9124: $resulttext .= '<li>'.
9125: &mt("$title{$item} set to [_1]$newtxt [_2]",
9126: '<b>','</b>').
9127: '</li>';
1.125 raeburn 9128: }
9129: }
9130: if ($changes{'xmldc'}) {
9131: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9132: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9133: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9134: }
9135: $resulttext .= '</ul>';
9136: } else {
9137: $resulttext = &mt('No changes made to auto-creation settings');
9138: }
9139: } else {
9140: $resulttext = '<span class="LC_error">'.
9141: &mt('An error occurred: [_1]',$putresult).'</span>';
9142: }
9143: return $resulttext;
9144: }
9145:
1.23 raeburn 9146: sub modify_directorysrch {
9147: my ($dom,%domconfig) = @_;
9148: my ($resulttext,%changes);
9149: my %currdirsrch;
9150: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9151: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9152: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9153: }
9154: }
9155: my %title = ( available => 'Directory search available',
1.24 raeburn 9156: localonly => 'Other domains can search',
1.23 raeburn 9157: searchby => 'Search types',
9158: searchtypes => 'Search latitude');
9159: my @offon = ('off','on');
1.24 raeburn 9160: my @otherdoms = ('Yes','No');
1.23 raeburn 9161:
1.25 raeburn 9162: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9163: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9164: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9165:
1.44 raeburn 9166: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9167: if (keys(%{$usertypes}) == 0) {
9168: @cansearch = ('default');
9169: } else {
9170: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9171: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9172: if (!grep(/^\Q$type\E$/,@cansearch)) {
9173: push(@{$changes{'cansearch'}},$type);
9174: }
1.23 raeburn 9175: }
1.26 raeburn 9176: foreach my $type (@cansearch) {
9177: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9178: push(@{$changes{'cansearch'}},$type);
9179: }
1.23 raeburn 9180: }
1.26 raeburn 9181: } else {
9182: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9183: }
9184: }
9185:
9186: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9187: foreach my $by (@{$currdirsrch{'searchby'}}) {
9188: if (!grep(/^\Q$by\E$/,@searchby)) {
9189: push(@{$changes{'searchby'}},$by);
9190: }
9191: }
9192: foreach my $by (@searchby) {
9193: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9194: push(@{$changes{'searchby'}},$by);
9195: }
9196: }
9197: } else {
9198: push(@{$changes{'searchby'}},@searchby);
9199: }
1.25 raeburn 9200:
9201: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9202: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9203: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9204: push(@{$changes{'searchtypes'}},$type);
9205: }
9206: }
9207: foreach my $type (@searchtypes) {
9208: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9209: push(@{$changes{'searchtypes'}},$type);
9210: }
9211: }
9212: } else {
9213: if (exists($currdirsrch{'searchtypes'})) {
9214: foreach my $type (@searchtypes) {
9215: if ($type ne $currdirsrch{'searchtypes'}) {
9216: push(@{$changes{'searchtypes'}},$type);
9217: }
9218: }
9219: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9220: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9221: }
9222: } else {
9223: push(@{$changes{'searchtypes'}},@searchtypes);
9224: }
9225: }
9226:
1.23 raeburn 9227: my %dirsrch_hash = (
9228: directorysrch => { available => $env{'form.dirsrch_available'},
9229: cansearch => \@cansearch,
1.24 raeburn 9230: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 9231: searchby => \@searchby,
1.25 raeburn 9232: searchtypes => \@searchtypes,
1.23 raeburn 9233: }
9234: );
9235: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9236: $dom);
9237: if ($putresult eq 'ok') {
9238: if (exists($currdirsrch{'available'})) {
9239: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9240: $changes{'available'} = 1;
9241: }
9242: } else {
9243: if ($env{'form.dirsrch_available'} eq '1') {
9244: $changes{'available'} = 1;
9245: }
9246: }
1.24 raeburn 9247: if (exists($currdirsrch{'localonly'})) {
9248: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
9249: $changes{'localonly'} = 1;
9250: }
9251: } else {
9252: if ($env{'form.dirsrch_localonly'} eq '1') {
9253: $changes{'localonly'} = 1;
9254: }
9255: }
1.23 raeburn 9256: if (keys(%changes) > 0) {
9257: $resulttext = &mt('Changes made:').'<ul>';
9258: if ($changes{'available'}) {
9259: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9260: }
1.24 raeburn 9261: if ($changes{'localonly'}) {
9262: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
9263: }
9264:
1.23 raeburn 9265: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9266: my $chgtext;
1.26 raeburn 9267: if (ref($usertypes) eq 'HASH') {
9268: if (keys(%{$usertypes}) > 0) {
9269: foreach my $type (@{$types}) {
9270: if (grep(/^\Q$type\E$/,@cansearch)) {
9271: $chgtext .= $usertypes->{$type}.'; ';
9272: }
9273: }
9274: if (grep(/^default$/,@cansearch)) {
9275: $chgtext .= $othertitle;
9276: } else {
9277: $chgtext =~ s/\; $//;
9278: }
1.210 raeburn 9279: $resulttext .=
1.178 raeburn 9280: '<li>'.
9281: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9282: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9283: '</li>';
1.23 raeburn 9284: }
9285: }
9286: }
9287: if (ref($changes{'searchby'}) eq 'ARRAY') {
9288: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9289: my $chgtext;
9290: foreach my $type (@{$titleorder}) {
9291: if (grep(/^\Q$type\E$/,@searchby)) {
9292: if (defined($searchtitles->{$type})) {
9293: $chgtext .= $searchtitles->{$type}.'; ';
9294: }
9295: }
9296: }
9297: $chgtext =~ s/\; $//;
9298: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9299: }
1.25 raeburn 9300: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9301: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9302: my $chgtext;
9303: foreach my $type (@{$srchtypeorder}) {
9304: if (grep(/^\Q$type\E$/,@searchtypes)) {
9305: if (defined($srchtypes_desc->{$type})) {
9306: $chgtext .= $srchtypes_desc->{$type}.'; ';
9307: }
9308: }
9309: }
9310: $chgtext =~ s/\; $//;
1.178 raeburn 9311: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9312: }
9313: $resulttext .= '</ul>';
9314: } else {
9315: $resulttext = &mt('No changes made to institution directory search settings');
9316: }
9317: } else {
9318: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9319: &mt('An error occurred: [_1]',$putresult).'</span>';
9320: }
9321: return $resulttext;
9322: }
9323:
1.28 raeburn 9324: sub modify_contacts {
1.205 raeburn 9325: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9326: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9327: if (ref($domconfig{'contacts'}) eq 'HASH') {
9328: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9329: $currsetting{$key} = $domconfig{'contacts'}{$key};
9330: }
9331: }
1.134 raeburn 9332: my (%others,%to,%bcc);
1.28 raeburn 9333: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9334: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9335: 'requestsmail','updatesmail','idconflictsmail');
9336: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9337: foreach my $type (@mailings) {
9338: @{$newsetting{$type}} =
9339: &Apache::loncommon::get_env_multiple('form.'.$type);
9340: foreach my $item (@contacts) {
9341: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9342: $contacts_hash{contacts}{$type}{$item} = 1;
9343: } else {
9344: $contacts_hash{contacts}{$type}{$item} = 0;
9345: }
9346: }
9347: $others{$type} = $env{'form.'.$type.'_others'};
9348: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9349: if ($type eq 'helpdeskmail') {
9350: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9351: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9352: }
1.28 raeburn 9353: }
9354: foreach my $item (@contacts) {
9355: $to{$item} = $env{'form.'.$item};
9356: $contacts_hash{'contacts'}{$item} = $to{$item};
9357: }
1.203 raeburn 9358: foreach my $item (@toggles) {
9359: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9360: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9361: }
9362: }
1.28 raeburn 9363: if (keys(%currsetting) > 0) {
9364: foreach my $item (@contacts) {
9365: if ($to{$item} ne $currsetting{$item}) {
9366: $changes{$item} = 1;
9367: }
9368: }
9369: foreach my $type (@mailings) {
9370: foreach my $item (@contacts) {
9371: if (ref($currsetting{$type}) eq 'HASH') {
9372: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9373: push(@{$changes{$type}},$item);
9374: }
9375: } else {
9376: push(@{$changes{$type}},@{$newsetting{$type}});
9377: }
9378: }
9379: if ($others{$type} ne $currsetting{$type}{'others'}) {
9380: push(@{$changes{$type}},'others');
9381: }
1.134 raeburn 9382: if ($type eq 'helpdeskmail') {
9383: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9384: push(@{$changes{$type}},'bcc');
9385: }
9386: }
1.28 raeburn 9387: }
9388: } else {
9389: my %default;
9390: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9391: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9392: $default{'errormail'} = 'adminemail';
9393: $default{'packagesmail'} = 'adminemail';
9394: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9395: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9396: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9397: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9398: foreach my $item (@contacts) {
9399: if ($to{$item} ne $default{$item}) {
9400: $changes{$item} = 1;
1.203 raeburn 9401: }
1.28 raeburn 9402: }
9403: foreach my $type (@mailings) {
9404: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9405:
9406: push(@{$changes{$type}},@{$newsetting{$type}});
9407: }
9408: if ($others{$type} ne '') {
9409: push(@{$changes{$type}},'others');
1.134 raeburn 9410: }
9411: if ($type eq 'helpdeskmail') {
9412: if ($bcc{$type} ne '') {
9413: push(@{$changes{$type}},'bcc');
9414: }
9415: }
1.28 raeburn 9416: }
9417: }
1.203 raeburn 9418: foreach my $item (@toggles) {
9419: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9420: $changes{$item} = 1;
9421: } elsif ((!$env{'form.'.$item}) &&
9422: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9423: $changes{$item} = 1;
9424: }
9425: }
1.28 raeburn 9426: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9427: $dom);
9428: if ($putresult eq 'ok') {
9429: if (keys(%changes) > 0) {
1.205 raeburn 9430: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9431: if (ref($lastactref) eq 'HASH') {
9432: $lastactref->{'domainconfig'} = 1;
9433: }
1.28 raeburn 9434: my ($titles,$short_titles) = &contact_titles();
9435: $resulttext = &mt('Changes made:').'<ul>';
9436: foreach my $item (@contacts) {
9437: if ($changes{$item}) {
9438: $resulttext .= '<li>'.$titles->{$item}.
9439: &mt(' set to: ').
9440: '<span class="LC_cusr_emph">'.
9441: $to{$item}.'</span></li>';
9442: }
9443: }
9444: foreach my $type (@mailings) {
9445: if (ref($changes{$type}) eq 'ARRAY') {
9446: $resulttext .= '<li>'.$titles->{$type}.': ';
9447: my @text;
9448: foreach my $item (@{$newsetting{$type}}) {
9449: push(@text,$short_titles->{$item});
9450: }
9451: if ($others{$type} ne '') {
9452: push(@text,$others{$type});
9453: }
9454: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9455: join(', ',@text).'</span>';
9456: if ($type eq 'helpdeskmail') {
9457: if ($bcc{$type} ne '') {
9458: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9459: }
9460: }
9461: $resulttext .= '</li>';
1.28 raeburn 9462: }
9463: }
1.203 raeburn 9464: my @offon = ('off','on');
9465: if ($changes{'reporterrors'}) {
9466: $resulttext .= '<li>'.
9467: &mt('E-mail error reports to [_1] set to "'.
9468: $offon[$env{'form.reporterrors'}].'".',
9469: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9470: &mt('LON-CAPA core group - MSU'),600,500)).
9471: '</li>';
9472: }
9473: if ($changes{'reportupdates'}) {
9474: $resulttext .= '<li>'.
9475: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9476: $offon[$env{'form.reportupdates'}].'".',
9477: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9478: &mt('LON-CAPA core group - MSU'),600,500)).
9479: '</li>';
9480: }
1.28 raeburn 9481: $resulttext .= '</ul>';
9482: } else {
1.34 raeburn 9483: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9484: }
9485: } else {
9486: $resulttext = '<span class="LC_error">'.
9487: &mt('An error occurred: [_1].',$putresult).'</span>';
9488: }
9489: return $resulttext;
9490: }
9491:
9492: sub modify_usercreation {
1.27 raeburn 9493: my ($dom,%domconfig) = @_;
1.224 raeburn 9494: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9495: my $warningmsg;
1.27 raeburn 9496: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9497: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9498: if ($key eq 'cancreate') {
9499: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9500: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9501: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9502: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9503: ($item eq 'recaptchaversion')) {
1.224 raeburn 9504: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9505: } else {
9506: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9507: }
9508: }
9509: }
9510: } elsif ($key eq 'email_rule') {
9511: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9512: } else {
9513: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9514: }
1.27 raeburn 9515: }
9516: }
9517: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9518: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9519: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9520: foreach my $item(@contexts) {
1.224 raeburn 9521: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9522: }
1.34 raeburn 9523: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9524: foreach my $item (@contexts) {
1.224 raeburn 9525: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9526: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9527: }
1.27 raeburn 9528: }
1.34 raeburn 9529: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9530: foreach my $item (@contexts) {
1.43 raeburn 9531: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9532: if ($cancreate{$item} ne 'any') {
9533: push(@{$changes{'cancreate'}},$item);
9534: }
9535: } else {
9536: if ($cancreate{$item} ne 'none') {
9537: push(@{$changes{'cancreate'}},$item);
9538: }
1.27 raeburn 9539: }
9540: }
9541: } else {
1.43 raeburn 9542: foreach my $item (@contexts) {
1.34 raeburn 9543: push(@{$changes{'cancreate'}},$item);
9544: }
1.27 raeburn 9545: }
1.34 raeburn 9546:
1.27 raeburn 9547: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9548: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9549: if (!grep(/^\Q$type\E$/,@username_rule)) {
9550: push(@{$changes{'username_rule'}},$type);
9551: }
9552: }
9553: foreach my $type (@username_rule) {
9554: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9555: push(@{$changes{'username_rule'}},$type);
9556: }
9557: }
9558: } else {
9559: push(@{$changes{'username_rule'}},@username_rule);
9560: }
9561:
1.32 raeburn 9562: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9563: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9564: if (!grep(/^\Q$type\E$/,@id_rule)) {
9565: push(@{$changes{'id_rule'}},$type);
9566: }
9567: }
9568: foreach my $type (@id_rule) {
9569: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9570: push(@{$changes{'id_rule'}},$type);
9571: }
9572: }
9573: } else {
9574: push(@{$changes{'id_rule'}},@id_rule);
9575: }
9576:
1.43 raeburn 9577: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9578: my @authtypes = ('int','krb4','krb5','loc');
9579: my %authhash;
1.43 raeburn 9580: foreach my $item (@authen_contexts) {
1.28 raeburn 9581: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9582: foreach my $auth (@authtypes) {
9583: if (grep(/^\Q$auth\E$/,@authallowed)) {
9584: $authhash{$item}{$auth} = 1;
9585: } else {
9586: $authhash{$item}{$auth} = 0;
9587: }
9588: }
9589: }
9590: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9591: foreach my $item (@authen_contexts) {
1.28 raeburn 9592: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9593: foreach my $auth (@authtypes) {
9594: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9595: push(@{$changes{'authtypes'}},$item);
9596: last;
9597: }
9598: }
9599: }
9600: }
9601: } else {
1.43 raeburn 9602: foreach my $item (@authen_contexts) {
1.28 raeburn 9603: push(@{$changes{'authtypes'}},$item);
9604: }
9605: }
9606:
1.224 raeburn 9607: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9608: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9609: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9610: $save_usercreate{'id_rule'} = \@id_rule;
9611: $save_usercreate{'username_rule'} = \@username_rule,
9612: $save_usercreate{'authtypes'} = \%authhash;
9613:
1.27 raeburn 9614: my %usercreation_hash = (
1.224 raeburn 9615: usercreation => \%save_usercreate,
9616: );
1.27 raeburn 9617:
9618: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9619: $dom);
1.50 raeburn 9620:
1.224 raeburn 9621: if ($putresult eq 'ok') {
9622: if (keys(%changes) > 0) {
9623: $resulttext = &mt('Changes made:').'<ul>';
9624: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9625: my %lt = &usercreation_types();
9626: foreach my $type (@{$changes{'cancreate'}}) {
9627: my $chgtext = $lt{$type}.', ';
9628: if ($cancreate{$type} eq 'none') {
9629: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9630: } elsif ($cancreate{$type} eq 'any') {
9631: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9632: } elsif ($cancreate{$type} eq 'official') {
9633: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9634: } elsif ($cancreate{$type} eq 'unofficial') {
9635: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9636: }
9637: $resulttext .= '<li>'.$chgtext.'</li>';
9638: }
9639: }
9640: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9641: my ($rules,$ruleorder) =
9642: &Apache::lonnet::inst_userrules($dom,'username');
9643: my $chgtext = '<ul>';
9644: foreach my $type (@username_rule) {
9645: if (ref($rules->{$type}) eq 'HASH') {
9646: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9647: }
9648: }
9649: $chgtext .= '</ul>';
9650: if (@username_rule > 0) {
9651: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9652: } else {
9653: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9654: }
9655: }
9656: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9657: my ($idrules,$idruleorder) =
9658: &Apache::lonnet::inst_userrules($dom,'id');
9659: my $chgtext = '<ul>';
9660: foreach my $type (@id_rule) {
9661: if (ref($idrules->{$type}) eq 'HASH') {
9662: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9663: }
9664: }
9665: $chgtext .= '</ul>';
9666: if (@id_rule > 0) {
9667: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9668: } else {
9669: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9670: }
9671: }
9672: my %authname = &authtype_names();
9673: my %context_title = &context_names();
9674: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9675: my $chgtext = '<ul>';
9676: foreach my $type (@{$changes{'authtypes'}}) {
9677: my @allowed;
9678: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9679: foreach my $auth (@authtypes) {
9680: if ($authhash{$type}{$auth}) {
9681: push(@allowed,$authname{$auth});
9682: }
9683: }
9684: if (@allowed > 0) {
9685: $chgtext .= join(', ',@allowed).'</li>';
9686: } else {
9687: $chgtext .= &mt('none').'</li>';
9688: }
9689: }
9690: $chgtext .= '</ul>';
9691: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9692: $resulttext .= '</li>';
9693: }
9694: $resulttext .= '</ul>';
9695: } else {
9696: $resulttext = &mt('No changes made to user creation settings');
9697: }
9698: } else {
9699: $resulttext = '<span class="LC_error">'.
9700: &mt('An error occurred: [_1]',$putresult).'</span>';
9701: }
9702: if ($warningmsg ne '') {
9703: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9704: }
9705: return $resulttext;
9706: }
9707:
9708: sub modify_selfcreation {
9709: my ($dom,%domconfig) = @_;
9710: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9711: my (%save_usercreate,%save_usermodify);
1.228 raeburn 9712: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9713: if (ref($types) eq 'ARRAY') {
9714: $usertypes->{'default'} = $othertitle;
9715: push(@{$types},'default');
9716: }
1.224 raeburn 9717: #
9718: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9719: #
9720: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9721: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9722: if ($key eq 'cancreate') {
9723: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9724: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9725: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9726: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 9727: ($item eq 'recaptchaversion') ||
1.236 raeburn 9728: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 9729: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 9730: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9731: } else {
9732: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9733: }
9734: }
9735: }
9736: } elsif ($key eq 'email_rule') {
9737: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9738: } else {
9739: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9740: }
9741: }
9742: }
9743: #
9744: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9745: #
9746: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9747: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9748: if ($key eq 'selfcreate') {
9749: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9750: } else {
9751: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9752: }
9753: }
9754: }
9755:
9756: my @contexts = ('selfcreate');
9757: @{$cancreate{'selfcreate'}} = ();
9758: %{$cancreate{'emailusername'}} = ();
9759: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 9760: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 9761: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9762: my %selfcreatetypes = (
9763: sso => 'users authenticated by institutional single sign on',
9764: login => 'users authenticated by institutional log-in',
1.236 raeburn 9765: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9766: );
1.224 raeburn 9767: #
9768: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9769: # is permitted.
9770: #
1.236 raeburn 9771:
9772: my @statuses;
9773: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9774: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9775: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9776: }
9777: }
9778: push(@statuses,'default');
9779:
1.228 raeburn 9780: foreach my $item ('login','sso','email') {
1.224 raeburn 9781: if ($item eq 'email') {
1.236 raeburn 9782: if ($env{'form.cancreate_email'}) {
1.224 raeburn 9783: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 9784: push(@contexts,'selfcreateprocessing');
9785: foreach my $type (@statuses) {
9786: if ($type eq 'default') {
9787: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9788: } else {
9789: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9790: }
9791: }
1.224 raeburn 9792: }
9793: } else {
9794: if ($env{'form.cancreate_'.$item}) {
9795: push(@{$cancreate{'selfcreate'}},$item);
9796: }
9797: }
9798: }
9799: my (@email_rule,%userinfo,%savecaptcha);
9800: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9801: #
1.228 raeburn 9802: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9803: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 9804: #
1.236 raeburn 9805:
1.244 raeburn 9806: if ($env{'form.cancreate_email'}) {
1.228 raeburn 9807: push(@contexts,'emailusername');
9808: if (ref($types) eq 'ARRAY') {
9809: foreach my $type (@{$types}) {
9810: if (ref($infofields) eq 'ARRAY') {
9811: foreach my $field (@{$infofields}) {
9812: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9813: $cancreate{'emailusername'}{$type}{$field} = $1;
9814: }
9815: }
1.224 raeburn 9816: }
9817: }
9818: }
9819: #
9820: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9821: # queued requests for self-creation of account using e-mail address as username
9822: #
9823:
9824: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9825: @approvalnotify = sort(@approvalnotify);
9826: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9827: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9828: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9829: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9830: push(@{$changes{'cancreate'}},'notify');
9831: }
9832: } else {
9833: if ($cancreate{'notify'}{'approval'}) {
9834: push(@{$changes{'cancreate'}},'notify');
9835: }
9836: }
9837: } elsif ($cancreate{'notify'}{'approval'}) {
9838: push(@{$changes{'cancreate'}},'notify');
9839: }
9840:
9841: #
9842: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9843: #
9844: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9845: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9846: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9847: if (@{$curr_usercreation{'email_rule'}} > 0) {
9848: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9849: if (!grep(/^\Q$type\E$/,@email_rule)) {
9850: push(@{$changes{'email_rule'}},$type);
9851: }
9852: }
9853: }
9854: if (@email_rule > 0) {
9855: foreach my $type (@email_rule) {
9856: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9857: push(@{$changes{'email_rule'}},$type);
9858: }
9859: }
9860: }
9861: } elsif (@email_rule > 0) {
9862: push(@{$changes{'email_rule'}},@email_rule);
9863: }
9864: }
9865: #
1.236 raeburn 9866: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 9867: # institutional log-in.
9868: #
9869: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9870: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9871: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9872: ($domdefaults{'auth_def'} eq 'localauth'))) {
9873: $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.').' '.
9874: &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.');
9875: }
9876: }
9877: my @fields = ('lastname','firstname','middlename','generation',
9878: 'permanentemail','id');
1.240 raeburn 9879: my @shibfields = (@fields,'inststatus');
1.224 raeburn 9880: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9881: #
9882: # Where usernames may created for institutional log-in and/or institutional single sign on:
9883: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9884: # may self-create accounts
9885: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9886: # which the user may supply, if institutional data is unavailable.
9887: #
9888: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9889: if (ref($types) eq 'ARRAY') {
1.228 raeburn 9890: if (@{$types} > 1) {
1.224 raeburn 9891: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9892: push(@contexts,'statustocreate');
9893: } else {
9894: undef($cancreate{'statustocreate'});
9895: }
9896: foreach my $type (@{$types}) {
9897: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9898: foreach my $field (@fields) {
9899: if (grep(/^\Q$field\E$/,@modifiable)) {
9900: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9901: } else {
9902: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9903: }
9904: }
9905: }
9906: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9907: foreach my $type (@{$types}) {
9908: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9909: foreach my $field (@fields) {
9910: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9911: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9912: push(@{$changes{'selfcreate'}},$type);
9913: last;
9914: }
9915: }
9916: }
9917: }
9918: } else {
9919: foreach my $type (@{$types}) {
9920: push(@{$changes{'selfcreate'}},$type);
9921: }
9922: }
9923: }
1.240 raeburn 9924: foreach my $field (@shibfields) {
9925: if ($env{'form.shibenv_'.$field} ne '') {
9926: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9927: }
9928: }
9929: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9930: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9931: foreach my $field (@shibfields) {
9932: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9933: push(@{$changes{'cancreate'}},'shibenv');
9934: }
9935: }
9936: } else {
9937: foreach my $field (@shibfields) {
9938: if ($env{'form.shibenv_'.$field}) {
9939: push(@{$changes{'cancreate'}},'shibenv');
9940: last;
9941: }
9942: }
9943: }
9944: }
1.224 raeburn 9945: }
9946: foreach my $item (@contexts) {
9947: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9948: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9949: if (ref($cancreate{$item}) eq 'ARRAY') {
9950: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9951: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9952: push(@{$changes{'cancreate'}},$item);
9953: }
9954: }
9955: }
9956: }
9957: if (ref($cancreate{$item}) eq 'ARRAY') {
9958: foreach my $type (@{$cancreate{$item}}) {
9959: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9960: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9961: push(@{$changes{'cancreate'}},$item);
9962: }
9963: }
9964: }
9965: }
9966: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9967: if (ref($cancreate{$item}) eq 'HASH') {
9968: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 9969: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9970: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9971: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9972: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9973: push(@{$changes{'cancreate'}},$item);
9974: }
9975: }
9976: }
1.236 raeburn 9977: } elsif ($item eq 'selfcreateprocessing') {
9978: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9979: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9980: push(@{$changes{'cancreate'}},$item);
9981: }
9982: }
1.228 raeburn 9983: } else {
9984: if (!$cancreate{$item}{$curr}) {
9985: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9986: push(@{$changes{'cancreate'}},$item);
9987: }
1.224 raeburn 9988: }
9989: }
9990: }
9991: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 9992: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9993: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9994: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9995: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9996: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9997: push(@{$changes{'cancreate'}},$item);
9998: }
9999: }
10000: } else {
10001: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10002: push(@{$changes{'cancreate'}},$item);
10003: }
10004: }
10005: }
1.236 raeburn 10006: } elsif ($item eq 'selfcreateprocessing') {
10007: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10008: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10009: push(@{$changes{'cancreate'}},$item);
10010: }
10011: }
1.228 raeburn 10012: } else {
10013: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10014: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10015: push(@{$changes{'cancreate'}},$item);
10016: }
1.224 raeburn 10017: }
10018: }
10019: }
10020: }
10021: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10022: if (ref($cancreate{$item}) eq 'ARRAY') {
10023: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10024: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10025: push(@{$changes{'cancreate'}},$item);
10026: }
10027: }
10028: } elsif (ref($cancreate{$item}) eq 'HASH') {
10029: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10030: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10031: push(@{$changes{'cancreate'}},$item);
10032: }
10033: }
10034: }
10035: } elsif ($item eq 'emailusername') {
1.228 raeburn 10036: if (ref($cancreate{$item}) eq 'HASH') {
10037: foreach my $type (keys(%{$cancreate{$item}})) {
10038: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10039: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10040: if ($cancreate{$item}{$type}{$field}) {
10041: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10042: push(@{$changes{'cancreate'}},$item);
10043: }
10044: last;
10045: }
10046: }
10047: }
10048: }
1.224 raeburn 10049: }
10050: }
10051: }
10052: #
10053: # Populate %save_usercreate hash with updates to self-creation configuration.
10054: #
10055: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10056: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10057: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10058: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10059: if (ref($cancreate{'notify'}) eq 'HASH') {
10060: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10061: }
1.236 raeburn 10062: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10063: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10064: }
1.224 raeburn 10065: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10066: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10067: }
1.240 raeburn 10068: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10069: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10070: }
1.224 raeburn 10071: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10072: $save_usercreate{'emailrule'} = \@email_rule;
10073:
10074: my %userconfig_hash = (
10075: usercreation => \%save_usercreate,
10076: usermodification => \%save_usermodify,
10077: );
10078: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10079: $dom);
10080: #
10081: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10082: #
1.27 raeburn 10083: if ($putresult eq 'ok') {
10084: if (keys(%changes) > 0) {
10085: $resulttext = &mt('Changes made:').'<ul>';
10086: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10087: my %lt = &selfcreation_types();
1.34 raeburn 10088: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10089: my $chgtext;
1.45 raeburn 10090: if ($type eq 'selfcreate') {
1.50 raeburn 10091: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10092: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10093: } else {
1.224 raeburn 10094: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10095: '<ul>';
1.50 raeburn 10096: foreach my $case (@{$cancreate{$type}}) {
10097: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10098: }
10099: $chgtext .= '</ul>';
1.100 raeburn 10100: if (ref($cancreate{$type}) eq 'ARRAY') {
10101: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10102: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10103: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10104: $chgtext .= '<br />'.
10105: '<span class="LC_warning">'.
10106: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10107: '</span>';
1.100 raeburn 10108: }
10109: }
10110: }
10111: }
1.43 raeburn 10112: }
1.240 raeburn 10113: } elsif ($type eq 'shibenv') {
10114: if (keys(%{$cancreate{$type}}) == 0) {
10115: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10116: } else {
10117: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10118: '<ul>';
10119: foreach my $field (@shibfields) {
10120: next if ($cancreate{$type}{$field} eq '');
10121: if ($field eq 'inststatus') {
10122: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10123: } else {
10124: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10125: }
10126: }
10127: $chgtext .= '</ul>';
10128: }
1.93 raeburn 10129: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10130: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10131: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10132: if (@{$cancreate{'selfcreate'}} > 0) {
10133: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10134: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10135: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10136: $chgtext .= '<br />'.
10137: '<span class="LC_warning">'.
10138: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10139: '</span>';
10140: }
1.96 raeburn 10141: } elsif (ref($usertypes) eq 'HASH') {
10142: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10143: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10144: } else {
10145: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10146: }
10147: $chgtext .= '<ul>';
10148: foreach my $case (@{$cancreate{$type}}) {
10149: if ($case eq 'default') {
10150: $chgtext .= '<li>'.$othertitle.'</li>';
10151: } else {
10152: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10153: }
10154: }
1.100 raeburn 10155: $chgtext .= '</ul>';
10156: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10157: $chgtext .= '<br /><span class="LC_warning">'.
10158: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10159: '</span>';
1.100 raeburn 10160: }
10161: }
10162: } else {
10163: if (@{$cancreate{$type}} == 0) {
10164: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10165: } else {
10166: $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 10167: }
10168: }
10169: }
1.236 raeburn 10170: } elsif ($type eq 'selfcreateprocessing') {
10171: my %choices = &Apache::lonlocal::texthash (
10172: automatic => 'Automatic approval',
10173: approval => 'Queued for approval',
10174: );
10175: if (@statuses > 1) {
10176: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10177: '<ul>';
10178: foreach my $type (@statuses) {
10179: if ($type eq 'default') {
10180: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10181: } else {
10182: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10183: }
10184: }
10185: $chgtext .= '</ul>';
10186: } else {
10187: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10188: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10189: }
1.165 raeburn 10190: } elsif ($type eq 'captcha') {
1.224 raeburn 10191: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10192: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10193: } else {
10194: my %captchas = &captcha_phrases();
1.224 raeburn 10195: if ($captchas{$savecaptcha{$type}}) {
10196: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10197: } else {
1.210 raeburn 10198: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10199: }
10200: }
10201: } elsif ($type eq 'recaptchakeys') {
10202: my ($privkey,$pubkey);
1.224 raeburn 10203: if (ref($savecaptcha{$type}) eq 'HASH') {
10204: $pubkey = $savecaptcha{$type}{'public'};
10205: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10206: }
10207: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10208: if (!$pubkey) {
10209: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10210: } else {
10211: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10212: }
10213: if (!$privkey) {
10214: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10215: } else {
10216: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10217: }
10218: $chgtext .= '</ul>';
1.269 raeburn 10219: } elsif ($type eq 'recaptchaversion') {
10220: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 ! raeburn 10221: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10222: }
1.224 raeburn 10223: } elsif ($type eq 'emailusername') {
10224: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10225: if (ref($types) eq 'ARRAY') {
10226: foreach my $type (@{$types}) {
10227: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10228: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10229: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10230: '<ul>';
10231: foreach my $field (@{$infofields}) {
10232: if ($cancreate{'emailusername'}{$type}{$field}) {
10233: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10234: }
10235: }
1.245 raeburn 10236: $chgtext .= '</ul>';
10237: } else {
10238: $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 10239: }
10240: } else {
1.245 raeburn 10241: $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 10242: }
10243: }
10244: }
10245: }
10246: } elsif ($type eq 'notify') {
10247: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10248: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10249: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10250: if ($cancreate{'notify'}{'approval'}) {
10251: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10252: }
10253: }
1.43 raeburn 10254: }
1.34 raeburn 10255: }
1.224 raeburn 10256: if ($chgtext) {
10257: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10258: }
10259: }
10260: }
1.43 raeburn 10261: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10262: my ($emailrules,$emailruleorder) =
10263: &Apache::lonnet::inst_userrules($dom,'email');
10264: my $chgtext = '<ul>';
10265: foreach my $type (@email_rule) {
10266: if (ref($emailrules->{$type}) eq 'HASH') {
10267: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10268: }
10269: }
10270: $chgtext .= '</ul>';
10271: if (@email_rule > 0) {
1.224 raeburn 10272: $resulttext .= '<li>'.
10273: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10274: $chgtext.
10275: '</li>';
1.43 raeburn 10276: } else {
1.224 raeburn 10277: $resulttext .= '<li>'.
10278: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10279: '</li>';
1.43 raeburn 10280: }
10281: }
1.224 raeburn 10282: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10283: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10284: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10285: foreach my $type (@{$changes{'selfcreate'}}) {
10286: my $typename = $type;
10287: if (ref($usertypes) eq 'HASH') {
10288: if ($usertypes->{$type} ne '') {
10289: $typename = $usertypes->{$type};
10290: }
10291: }
10292: my @modifiable;
10293: $resulttext .= '<li>'.
10294: &mt('Self-creation of account by users with status: [_1]',
10295: '<span class="LC_cusr_emph">'.$typename.'</span>').
10296: ' - '.&mt('modifiable fields (if institutional data blank): ');
10297: foreach my $field (@fields) {
10298: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10299: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10300: }
10301: }
1.224 raeburn 10302: if (@modifiable > 0) {
10303: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10304: } else {
1.224 raeburn 10305: $resulttext .= &mt('none');
1.43 raeburn 10306: }
1.224 raeburn 10307: $resulttext .= '</li>';
1.28 raeburn 10308: }
1.224 raeburn 10309: $resulttext .= '</ul></li>';
1.28 raeburn 10310: }
1.27 raeburn 10311: $resulttext .= '</ul>';
10312: } else {
1.224 raeburn 10313: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10314: }
10315: } else {
10316: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10317: &mt('An error occurred: [_1]',$putresult).'</span>';
10318: }
1.43 raeburn 10319: if ($warningmsg ne '') {
10320: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10321: }
1.23 raeburn 10322: return $resulttext;
10323: }
10324:
1.165 raeburn 10325: sub process_captcha {
10326: my ($container,$changes,$newsettings,$current) = @_;
10327: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10328: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10329: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10330: $newsettings->{'captcha'} = 'original';
10331: }
10332: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10333: if ($container eq 'cancreate') {
1.169 raeburn 10334: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10335: push(@{$changes->{'cancreate'}},'captcha');
10336: } elsif (!defined($changes->{'cancreate'})) {
10337: $changes->{'cancreate'} = ['captcha'];
10338: }
10339: } else {
10340: $changes->{'captcha'} = 1;
1.165 raeburn 10341: }
10342: }
1.269 raeburn 10343: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10344: if ($newsettings->{'captcha'} eq 'recaptcha') {
10345: $newpub = $env{'form.'.$container.'_recaptchapub'};
10346: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10347: $newpub =~ s/[^\w\-]//g;
10348: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10349: $newsettings->{'recaptchakeys'} = {
10350: public => $newpub,
10351: private => $newpriv,
10352: };
1.269 raeburn 10353: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10354: $newversion =~ s/\D//g;
10355: if ($newversion ne '2') {
10356: $newversion = 1;
10357: }
10358: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10359: }
10360: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10361: $currpub = $current->{'recaptchakeys'}{'public'};
10362: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10363: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10364: $newsettings->{'recaptchakeys'} = {
10365: public => '',
10366: private => '',
10367: }
10368: }
1.165 raeburn 10369: }
1.269 raeburn 10370: if ($current->{'captcha'} eq 'recaptcha') {
10371: $currversion = $current->{'recaptchaversion'};
10372: if ($currversion ne '2') {
10373: $currversion = 1;
10374: }
10375: }
10376: if ($currversion ne $newversion) {
10377: if ($container eq 'cancreate') {
10378: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10379: push(@{$changes->{'cancreate'}},'recaptchaversion');
10380: } elsif (!defined($changes->{'cancreate'})) {
10381: $changes->{'cancreate'} = ['recaptchaversion'];
10382: }
10383: } else {
10384: $changes->{'recaptchaversion'} = 1;
10385: }
10386: }
1.165 raeburn 10387: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10388: if ($container eq 'cancreate') {
10389: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10390: push(@{$changes->{'cancreate'}},'recaptchakeys');
10391: } elsif (!defined($changes->{'cancreate'})) {
10392: $changes->{'cancreate'} = ['recaptchakeys'];
10393: }
10394: } else {
1.210 raeburn 10395: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10396: }
10397: }
10398: return;
10399: }
10400:
1.33 raeburn 10401: sub modify_usermodification {
10402: my ($dom,%domconfig) = @_;
1.224 raeburn 10403: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10404: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10405: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10406: if ($key eq 'selfcreate') {
10407: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10408: } else {
10409: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10410: }
1.33 raeburn 10411: }
10412: }
1.224 raeburn 10413: my @contexts = ('author','course');
1.33 raeburn 10414: my %context_title = (
10415: author => 'In author context',
10416: course => 'In course context',
10417: );
10418: my @fields = ('lastname','firstname','middlename','generation',
10419: 'permanentemail','id');
10420: my %roles = (
10421: author => ['ca','aa'],
10422: course => ['st','ep','ta','in','cr'],
10423: );
10424: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10425: foreach my $context (@contexts) {
10426: foreach my $role (@{$roles{$context}}) {
10427: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10428: foreach my $item (@fields) {
10429: if (grep(/^\Q$item\E$/,@modifiable)) {
10430: $modifyhash{$context}{$role}{$item} = 1;
10431: } else {
10432: $modifyhash{$context}{$role}{$item} = 0;
10433: }
10434: }
10435: }
10436: if (ref($curr_usermodification{$context}) eq 'HASH') {
10437: foreach my $role (@{$roles{$context}}) {
10438: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10439: foreach my $field (@fields) {
10440: if ($modifyhash{$context}{$role}{$field} ne
10441: $curr_usermodification{$context}{$role}{$field}) {
10442: push(@{$changes{$context}},$role);
10443: last;
10444: }
10445: }
10446: }
10447: }
10448: } else {
10449: foreach my $context (@contexts) {
10450: foreach my $role (@{$roles{$context}}) {
10451: push(@{$changes{$context}},$role);
10452: }
10453: }
10454: }
10455: }
10456: my %usermodification_hash = (
10457: usermodification => \%modifyhash,
10458: );
10459: my $putresult = &Apache::lonnet::put_dom('configuration',
10460: \%usermodification_hash,$dom);
10461: if ($putresult eq 'ok') {
10462: if (keys(%changes) > 0) {
10463: $resulttext = &mt('Changes made: ').'<ul>';
10464: foreach my $context (@contexts) {
10465: if (ref($changes{$context}) eq 'ARRAY') {
10466: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10467: if (ref($changes{$context}) eq 'ARRAY') {
10468: foreach my $role (@{$changes{$context}}) {
10469: my $rolename;
1.224 raeburn 10470: if ($role eq 'cr') {
10471: $rolename = &mt('Custom');
1.33 raeburn 10472: } else {
1.224 raeburn 10473: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10474: }
10475: my @modifiable;
1.224 raeburn 10476: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10477: foreach my $field (@fields) {
10478: if ($modifyhash{$context}{$role}{$field}) {
10479: push(@modifiable,$fieldtitles{$field});
10480: }
10481: }
10482: if (@modifiable > 0) {
10483: $resulttext .= join(', ',@modifiable);
10484: } else {
10485: $resulttext .= &mt('none');
10486: }
10487: $resulttext .= '</li>';
10488: }
10489: $resulttext .= '</ul></li>';
10490: }
10491: }
10492: }
10493: $resulttext .= '</ul>';
10494: } else {
10495: $resulttext = &mt('No changes made to user modification settings');
10496: }
10497: } else {
10498: $resulttext = '<span class="LC_error">'.
10499: &mt('An error occurred: [_1]',$putresult).'</span>';
10500: }
10501: return $resulttext;
10502: }
10503:
1.43 raeburn 10504: sub modify_defaults {
1.212 raeburn 10505: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10506: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10507: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10508: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10509: my @authtypes = ('internal','krb4','krb5','localauth');
10510: foreach my $item (@items) {
10511: $newvalues{$item} = $env{'form.'.$item};
10512: if ($item eq 'auth_def') {
10513: if ($newvalues{$item} ne '') {
10514: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10515: push(@errors,$item);
10516: }
10517: }
10518: } elsif ($item eq 'lang_def') {
10519: if ($newvalues{$item} ne '') {
10520: if ($newvalues{$item} =~ /^(\w+)/) {
10521: my $langcode = $1;
1.103 raeburn 10522: if ($langcode ne 'x_chef') {
10523: if (code2language($langcode) eq '') {
10524: push(@errors,$item);
10525: }
1.43 raeburn 10526: }
10527: } else {
10528: push(@errors,$item);
10529: }
10530: }
1.54 raeburn 10531: } elsif ($item eq 'timezone_def') {
10532: if ($newvalues{$item} ne '') {
1.62 raeburn 10533: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10534: push(@errors,$item);
10535: }
10536: }
1.68 raeburn 10537: } elsif ($item eq 'datelocale_def') {
10538: if ($newvalues{$item} ne '') {
10539: my @datelocale_ids = DateTime::Locale->ids();
10540: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10541: push(@errors,$item);
10542: }
10543: }
1.141 raeburn 10544: } elsif ($item eq 'portal_def') {
10545: if ($newvalues{$item} ne '') {
10546: 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])\/?$/) {
10547: push(@errors,$item);
10548: }
10549: }
1.43 raeburn 10550: }
10551: if (grep(/^\Q$item\E$/,@errors)) {
10552: $newvalues{$item} = $domdefaults{$item};
10553: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10554: $changes{$item} = 1;
10555: }
1.72 raeburn 10556: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10557: }
10558: my %defaults_hash = (
1.72 raeburn 10559: defaults => \%newvalues,
10560: );
1.43 raeburn 10561: my $title = &defaults_titles();
1.236 raeburn 10562:
10563: my $currinststatus;
10564: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10565: $currinststatus = $domconfig{'inststatus'};
10566: } else {
10567: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10568: $currinststatus = {
10569: inststatustypes => $usertypes,
10570: inststatusorder => $types,
10571: inststatusguest => [],
10572: };
10573: }
10574: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10575: my @allpos;
10576: my %guests;
10577: my %alltypes;
10578: my ($currtitles,$currguests,$currorder);
10579: if (ref($currinststatus) eq 'HASH') {
10580: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10581: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10582: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10583: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10584: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10585: }
10586: }
10587: unless (grep(/^\Q$type\E$/,@todelete)) {
10588: my $position = $env{'form.inststatus_pos_'.$type};
10589: $position =~ s/\D+//g;
10590: $allpos[$position] = $type;
10591: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10592: $alltypes{$type} =~ s/`//g;
10593: if ($env{'form.inststatus_guest_'.$type}) {
10594: $guests{$type} = 1;
10595: }
10596: }
10597: }
10598: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10599: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10600: }
10601: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10602: $currtitles =~ s/,$//;
10603: }
10604: }
10605: if ($env{'form.addinststatus'}) {
10606: my $newtype = $env{'form.addinststatus'};
10607: $newtype =~ s/\W//g;
10608: unless (exists($alltypes{$newtype})) {
10609: if ($env{'form.addinststatus_guest'}) {
10610: $guests{$newtype} = 1;
10611: }
10612: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10613: $alltypes{$newtype} =~ s/`//g;
10614: my $position = $env{'form.addinststatus_pos'};
10615: $position =~ s/\D+//g;
10616: if ($position ne '') {
10617: $allpos[$position] = $newtype;
10618: }
10619: }
10620: }
10621: my (@orderedstatus,@orderedguests);
10622: foreach my $type (@allpos) {
10623: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10624: push(@orderedstatus,$type);
10625: if ($guests{$type}) {
10626: push(@orderedguests,$type);
10627: }
10628: }
10629: }
10630: foreach my $type (keys(%alltypes)) {
10631: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10632: delete($alltypes{$type});
10633: }
10634: }
10635: $defaults_hash{'inststatus'} = {
10636: inststatustypes => \%alltypes,
10637: inststatusorder => \@orderedstatus,
10638: inststatusguest => \@orderedguests,
10639: };
10640: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10641: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10642: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10643: }
10644: }
10645: if ($currorder ne join(',',@orderedstatus)) {
10646: $changes{'inststatus'}{'inststatusorder'} = 1;
10647: }
10648: if ($currguests ne join(',',@orderedguests)) {
10649: $changes{'inststatus'}{'inststatusguest'} = 1;
10650: }
10651: my $newtitles;
10652: foreach my $item (@orderedstatus) {
10653: $newtitles .= $alltypes{$item}.',';
10654: }
10655: $newtitles =~ s/,$//;
10656: if ($currtitles ne $newtitles) {
10657: $changes{'inststatus'}{'inststatustypes'} = 1;
10658: }
1.43 raeburn 10659: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10660: $dom);
10661: if ($putresult eq 'ok') {
10662: if (keys(%changes) > 0) {
10663: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 10664: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10665: 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";
10666: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 10667: if ($item eq 'inststatus') {
10668: if (ref($changes{'inststatus'}) eq 'HASH') {
10669: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10670: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10671: foreach my $type (@orderedstatus) {
10672: $resulttext .= $alltypes{$type}.', ';
10673: }
10674: $resulttext =~ s/, $//;
10675: $resulttext .= '</li>';
10676: }
10677: if ($changes{'inststatus'}{'inststatusguest'}) {
10678: $resulttext .= '<li>';
10679: if (@orderedguests) {
10680: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10681: foreach my $type (@orderedguests) {
10682: $resulttext .= $alltypes{$type}.', ';
10683: }
10684: $resulttext =~ s/, $//;
10685: } else {
10686: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10687: }
10688: $resulttext .= '</li>';
10689: }
10690: }
10691: } else {
10692: my $value = $env{'form.'.$item};
10693: if ($value eq '') {
10694: $value = &mt('none');
10695: } elsif ($item eq 'auth_def') {
10696: my %authnames = &authtype_names();
10697: my %shortauth = (
10698: internal => 'int',
10699: krb4 => 'krb4',
10700: krb5 => 'krb5',
10701: localauth => 'loc',
10702: );
10703: $value = $authnames{$shortauth{$value}};
10704: }
10705: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10706: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10707: }
10708: }
10709: $resulttext .= '</ul>';
10710: $mailmsgtext .= "\n";
10711: my $cachetime = 24*60*60;
1.72 raeburn 10712: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10713: if (ref($lastactref) eq 'HASH') {
10714: $lastactref->{'domdefaults'} = 1;
10715: }
1.68 raeburn 10716: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 10717: my $notify = 1;
10718: if (ref($domconfig{'contacts'}) eq 'HASH') {
10719: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10720: $notify = 0;
10721: }
10722: }
10723: if ($notify) {
10724: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10725: "LON-CAPA Domain Settings Change - $dom",
10726: $mailmsgtext);
10727: }
1.54 raeburn 10728: }
1.43 raeburn 10729: } else {
1.54 raeburn 10730: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10731: }
10732: } else {
10733: $resulttext = '<span class="LC_error">'.
10734: &mt('An error occurred: [_1]',$putresult).'</span>';
10735: }
10736: if (@errors > 0) {
10737: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10738: foreach my $item (@errors) {
10739: $resulttext .= ' "'.$title->{$item}.'",';
10740: }
10741: $resulttext =~ s/,$//;
10742: }
10743: return $resulttext;
10744: }
10745:
1.46 raeburn 10746: sub modify_scantron {
1.205 raeburn 10747: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10748: my ($resulttext,%confhash,%changes,$errors);
10749: my $custom = 'custom.tab';
10750: my $default = 'default.tab';
10751: my $servadm = $r->dir_config('lonAdmEMail');
10752: my ($configuserok,$author_ok,$switchserver) =
10753: &config_check($dom,$confname,$servadm);
10754: if ($env{'form.scantronformat.filename'} ne '') {
10755: my $error;
10756: if ($configuserok eq 'ok') {
10757: if ($switchserver) {
1.130 raeburn 10758: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10759: } else {
10760: if ($author_ok eq 'ok') {
10761: my ($result,$scantronurl) =
10762: &publishlogo($r,'upload','scantronformat',$dom,
10763: $confname,'scantron','','',$custom);
10764: if ($result eq 'ok') {
10765: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10766: $changes{'scantronformat'} = 1;
1.46 raeburn 10767: } else {
10768: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10769: }
10770: } else {
10771: $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);
10772: }
10773: }
10774: } else {
10775: $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);
10776: }
10777: if ($error) {
10778: &Apache::lonnet::logthis($error);
10779: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10780: }
10781: }
1.48 raeburn 10782: if (ref($domconfig{'scantron'}) eq 'HASH') {
10783: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10784: if ($env{'form.scantronformat_del'}) {
10785: $confhash{'scantron'}{'scantronformat'} = '';
10786: $changes{'scantronformat'} = 1;
1.46 raeburn 10787: }
10788: }
10789: }
10790: if (keys(%confhash) > 0) {
10791: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10792: $dom);
10793: if ($putresult eq 'ok') {
10794: if (keys(%changes) > 0) {
1.48 raeburn 10795: if (ref($confhash{'scantron'}) eq 'HASH') {
10796: $resulttext = &mt('Changes made:').'<ul>';
10797: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10798: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10799: } else {
1.130 raeburn 10800: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10801: }
1.48 raeburn 10802: $resulttext .= '</ul>';
10803: } else {
1.130 raeburn 10804: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10805: }
10806: $resulttext .= '</ul>';
10807: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10808: if (ref($lastactref) eq 'HASH') {
10809: $lastactref->{'domainconfig'} = 1;
10810: }
1.46 raeburn 10811: } else {
1.130 raeburn 10812: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10813: }
10814: } else {
10815: $resulttext = '<span class="LC_error">'.
10816: &mt('An error occurred: [_1]',$putresult).'</span>';
10817: }
10818: } else {
1.130 raeburn 10819: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10820: }
10821: if ($errors) {
10822: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10823: $errors.'</ul>';
10824: }
10825: return $resulttext;
10826: }
10827:
1.48 raeburn 10828: sub modify_coursecategories {
1.239 raeburn 10829: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10830: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10831: $cathash);
1.48 raeburn 10832: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 10833: my @catitems = ('unauth','auth');
10834: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10835: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10836: $cathash = $domconfig{'coursecategories'}{'cats'};
10837: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10838: $changes{'togglecats'} = 1;
10839: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10840: }
10841: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10842: $changes{'categorize'} = 1;
10843: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10844: }
1.120 raeburn 10845: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10846: $changes{'togglecatscomm'} = 1;
10847: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10848: }
10849: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10850: $changes{'categorizecomm'} = 1;
10851: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10852: }
1.238 raeburn 10853: foreach my $item (@catitems) {
10854: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10855: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10856: $changes{$item} = 1;
10857: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10858: }
10859: }
10860: }
1.57 raeburn 10861: } else {
10862: $changes{'togglecats'} = 1;
10863: $changes{'categorize'} = 1;
1.124 raeburn 10864: $changes{'togglecatscomm'} = 1;
10865: $changes{'categorizecomm'} = 1;
1.87 raeburn 10866: $domconfig{'coursecategories'} = {
10867: togglecats => $env{'form.togglecats'},
10868: categorize => $env{'form.categorize'},
1.124 raeburn 10869: togglecatscomm => $env{'form.togglecatscomm'},
10870: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10871: };
1.238 raeburn 10872: foreach my $item (@catitems) {
10873: if ($env{'form.coursecat_'.$item} ne 'std') {
10874: $changes{$item} = 1;
10875: }
10876: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10877: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10878: }
10879: }
1.57 raeburn 10880: }
10881: if (ref($cathash) eq 'HASH') {
10882: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10883: push (@deletecategory,'instcode::0');
10884: }
1.120 raeburn 10885: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10886: push(@deletecategory,'communities::0');
10887: }
1.48 raeburn 10888: }
1.57 raeburn 10889: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10890: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10891: if (@deletecategory > 0) {
10892: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10893: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10894: foreach my $item (@deletecategory) {
1.57 raeburn 10895: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10896: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10897: $deletions{$item} = 1;
1.57 raeburn 10898: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10899: }
10900: }
10901: }
1.57 raeburn 10902: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10903: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10904: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10905: $reorderings{$item} = 1;
1.57 raeburn 10906: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10907: }
10908: if ($env{'form.addcategory_name_'.$item} ne '') {
10909: my $newcat = $env{'form.addcategory_name_'.$item};
10910: my $newdepth = $depth+1;
10911: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10912: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10913: $adds{$newitem} = 1;
10914: }
10915: if ($env{'form.subcat_'.$item} ne '') {
10916: my $newcat = $env{'form.subcat_'.$item};
10917: my $newdepth = $depth+1;
10918: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10919: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10920: $adds{$newitem} = 1;
10921: }
10922: }
10923: }
10924: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10925: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10926: my $newitem = 'instcode::0';
1.57 raeburn 10927: if ($cathash->{$newitem} eq '') {
10928: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10929: $adds{$newitem} = 1;
10930: }
10931: } else {
10932: my $newitem = 'instcode::0';
1.57 raeburn 10933: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10934: $adds{$newitem} = 1;
10935: }
10936: }
1.120 raeburn 10937: if ($env{'form.communities'} eq '1') {
10938: if (ref($cathash) eq 'HASH') {
10939: my $newitem = 'communities::0';
10940: if ($cathash->{$newitem} eq '') {
10941: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10942: $adds{$newitem} = 1;
10943: }
10944: } else {
10945: my $newitem = 'communities::0';
10946: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10947: $adds{$newitem} = 1;
10948: }
10949: }
1.48 raeburn 10950: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10951: if (($env{'form.addcategory_name'} ne 'instcode') &&
10952: ($env{'form.addcategory_name'} ne 'communities')) {
10953: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10954: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10955: $adds{$newitem} = 1;
10956: }
1.48 raeburn 10957: }
1.57 raeburn 10958: my $putresult;
1.48 raeburn 10959: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10960: if (keys(%deletions) > 0) {
10961: foreach my $key (keys(%deletions)) {
10962: if ($predelallitems{$key} ne '') {
10963: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10964: }
10965: }
10966: }
10967: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10968: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10969: if (ref($chkcats[0]) eq 'ARRAY') {
10970: my $depth = 0;
10971: my $chg = 0;
10972: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10973: my $name = $chkcats[0][$i];
10974: my $item;
10975: if ($name eq '') {
10976: $chg ++;
10977: } else {
10978: $item = &escape($name).'::0';
10979: if ($chg) {
1.57 raeburn 10980: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10981: }
10982: $depth ++;
1.57 raeburn 10983: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10984: $depth --;
10985: }
10986: }
10987: }
1.57 raeburn 10988: }
10989: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10990: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10991: if ($putresult eq 'ok') {
1.57 raeburn 10992: my %title = (
1.120 raeburn 10993: togglecats => 'Show/Hide a course in catalog',
10994: categorize => 'Assign a category to a course',
10995: togglecatscomm => 'Show/Hide a community in catalog',
10996: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10997: );
10998: my %level = (
1.120 raeburn 10999: dom => 'set in Domain ("Modify Course/Community")',
11000: crs => 'set in Course ("Course Configuration")',
11001: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11002: none => 'No catalog',
11003: std => 'Standard catalog',
11004: domonly => 'Domain-only catalog',
11005: codesrch => 'Code search form',
1.57 raeburn 11006: );
1.48 raeburn 11007: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11008: if ($changes{'togglecats'}) {
11009: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11010: }
11011: if ($changes{'categorize'}) {
11012: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11013: }
1.120 raeburn 11014: if ($changes{'togglecatscomm'}) {
11015: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11016: }
11017: if ($changes{'categorizecomm'}) {
11018: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11019: }
1.238 raeburn 11020: if ($changes{'unauth'}) {
11021: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11022: }
11023: if ($changes{'auth'}) {
11024: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11025: }
1.57 raeburn 11026: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11027: my $cathash;
11028: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11029: $cathash = $domconfig{'coursecategories'}{'cats'};
11030: } else {
11031: $cathash = {};
11032: }
11033: my (@cats,@trails,%allitems);
11034: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11035: if (keys(%deletions) > 0) {
11036: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11037: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11038: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11039: }
11040: $resulttext .= '</ul></li>';
11041: }
11042: if (keys(%reorderings) > 0) {
11043: my %sort_by_trail;
11044: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11045: foreach my $key (keys(%reorderings)) {
11046: if ($allitems{$key} ne '') {
11047: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11048: }
1.48 raeburn 11049: }
1.57 raeburn 11050: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11051: $resulttext .= '<li>'.$trails[$trail].'</li>';
11052: }
11053: $resulttext .= '</ul></li>';
1.48 raeburn 11054: }
1.57 raeburn 11055: if (keys(%adds) > 0) {
11056: my %sort_by_trail;
11057: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11058: foreach my $key (keys(%adds)) {
11059: if ($allitems{$key} ne '') {
11060: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11061: }
11062: }
11063: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11064: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11065: }
1.57 raeburn 11066: $resulttext .= '</ul></li>';
1.48 raeburn 11067: }
11068: }
11069: $resulttext .= '</ul>';
1.239 raeburn 11070: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11071: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11072: if ($changes{'auth'}) {
11073: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11074: }
11075: if ($changes{'unauth'}) {
11076: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11077: }
11078: my $cachetime = 24*60*60;
11079: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11080: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11081: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11082: }
11083: }
1.48 raeburn 11084: } else {
11085: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11086: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11087: }
11088: } else {
1.120 raeburn 11089: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11090: }
11091: return $resulttext;
11092: }
11093:
1.69 raeburn 11094: sub modify_serverstatuses {
11095: my ($dom,%domconfig) = @_;
11096: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11097: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11098: %currserverstatus = %{$domconfig{'serverstatuses'}};
11099: }
11100: my @pages = &serverstatus_pages();
11101: foreach my $type (@pages) {
11102: $newserverstatus{$type}{'namedusers'} = '';
11103: $newserverstatus{$type}{'machines'} = '';
11104: if (defined($env{'form.'.$type.'_namedusers'})) {
11105: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11106: my @okusers;
11107: foreach my $user (@users) {
11108: my ($uname,$udom) = split(/:/,$user);
11109: if (($udom =~ /^$match_domain$/) &&
11110: (&Apache::lonnet::domain($udom)) &&
11111: ($uname =~ /^$match_username$/)) {
11112: if (!grep(/^\Q$user\E/,@okusers)) {
11113: push(@okusers,$user);
11114: }
11115: }
11116: }
11117: if (@okusers > 0) {
11118: @okusers = sort(@okusers);
11119: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11120: }
11121: }
11122: if (defined($env{'form.'.$type.'_machines'})) {
11123: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11124: my @okmachines;
11125: foreach my $ip (@machines) {
11126: my @parts = split(/\./,$ip);
11127: next if (@parts < 4);
11128: my $badip = 0;
11129: for (my $i=0; $i<4; $i++) {
11130: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11131: $badip = 1;
11132: last;
11133: }
11134: }
11135: if (!$badip) {
11136: push(@okmachines,$ip);
11137: }
11138: }
11139: @okmachines = sort(@okmachines);
11140: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11141: }
11142: }
11143: my %serverstatushash = (
11144: serverstatuses => \%newserverstatus,
11145: );
11146: foreach my $type (@pages) {
1.83 raeburn 11147: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11148: my (@current,@new);
1.83 raeburn 11149: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11150: if ($currserverstatus{$type}{$setting} ne '') {
11151: @current = split(/,/,$currserverstatus{$type}{$setting});
11152: }
11153: }
11154: if ($newserverstatus{$type}{$setting} ne '') {
11155: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11156: }
11157: if (@current > 0) {
11158: if (@new > 0) {
11159: foreach my $item (@current) {
11160: if (!grep(/^\Q$item\E$/,@new)) {
11161: $changes{$type}{$setting} = 1;
1.82 raeburn 11162: last;
11163: }
11164: }
1.84 raeburn 11165: foreach my $item (@new) {
11166: if (!grep(/^\Q$item\E$/,@current)) {
11167: $changes{$type}{$setting} = 1;
11168: last;
1.82 raeburn 11169: }
11170: }
11171: } else {
1.83 raeburn 11172: $changes{$type}{$setting} = 1;
1.69 raeburn 11173: }
1.83 raeburn 11174: } elsif (@new > 0) {
11175: $changes{$type}{$setting} = 1;
1.69 raeburn 11176: }
11177: }
11178: }
11179: if (keys(%changes) > 0) {
1.81 raeburn 11180: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11181: my $putresult = &Apache::lonnet::put_dom('configuration',
11182: \%serverstatushash,$dom);
11183: if ($putresult eq 'ok') {
11184: $resulttext .= &mt('Changes made:').'<ul>';
11185: foreach my $type (@pages) {
1.84 raeburn 11186: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11187: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11188: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11189: if ($newserverstatus{$type}{'namedusers'} eq '') {
11190: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11191: } else {
11192: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11193: }
1.84 raeburn 11194: }
11195: if ($changes{$type}{'machines'}) {
1.69 raeburn 11196: if ($newserverstatus{$type}{'machines'} eq '') {
11197: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11198: } else {
11199: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11200: }
11201:
11202: }
11203: $resulttext .= '</ul></li>';
11204: }
11205: }
11206: $resulttext .= '</ul>';
11207: } else {
11208: $resulttext = '<span class="LC_error">'.
11209: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11210:
11211: }
11212: } else {
11213: $resulttext = &mt('No changes made to access to server status pages');
11214: }
11215: return $resulttext;
11216: }
11217:
1.118 jms 11218: sub modify_helpsettings {
1.122 jms 11219: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11220: my ($resulttext,$errors,%changes,%helphash);
11221: my %defaultchecked = ('submitbugs' => 'on');
11222: my @offon = ('off','on');
1.118 jms 11223: my @toggles = ('submitbugs');
11224: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11225: foreach my $item (@toggles) {
1.166 raeburn 11226: if ($defaultchecked{$item} eq 'on') {
11227: if ($domconfig{'helpsettings'}{$item} eq '') {
11228: if ($env{'form.'.$item} eq '0') {
11229: $changes{$item} = 1;
11230: }
11231: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11232: $changes{$item} = 1;
11233: }
11234: } elsif ($defaultchecked{$item} eq 'off') {
11235: if ($domconfig{'helpsettings'}{$item} eq '') {
11236: if ($env{'form.'.$item} eq '1') {
11237: $changes{$item} = 1;
11238: }
11239: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11240: $changes{$item} = 1;
11241: }
11242: }
1.210 raeburn 11243: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11244: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11245: }
11246: }
1.118 jms 11247: }
1.123 jms 11248: my $putresult;
11249: if (keys(%changes) > 0) {
1.166 raeburn 11250: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11251: if ($putresult eq 'ok') {
1.166 raeburn 11252: $resulttext = &mt('Changes made:').'<ul>';
11253: foreach my $item (sort(keys(%changes))) {
11254: if ($item eq 'submitbugs') {
11255: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11256: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11257: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11258: }
11259: }
11260: $resulttext .= '</ul>';
11261: } else {
11262: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11263: $errors .= '<li><span class="LC_error">'.
11264: &mt('An error occurred storing the settings: [_1]',
11265: $putresult).'</span></li>';
1.166 raeburn 11266: }
1.118 jms 11267: }
11268: if ($errors) {
1.168 raeburn 11269: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11270: $errors.'</ul>';
11271: }
11272: return $resulttext;
11273: }
11274:
1.121 raeburn 11275: sub modify_coursedefaults {
1.212 raeburn 11276: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11277: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11278: my %defaultchecked = (
11279: 'canuse_pdfforms' => 'off',
11280: 'uselcmath' => 'on',
11281: 'usejsme' => 'on'
11282: );
11283: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11284: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 11285: 'uploadquota_community','uploadquota_textbook');
11286: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 11287: my %staticdefaults = (
11288: anonsurvey_threshold => 10,
11289: uploadquota => 500,
1.257 raeburn 11290: postsubmit => 60,
1.198 raeburn 11291: );
1.121 raeburn 11292:
11293: $defaultshash{'coursedefaults'} = {};
11294:
11295: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11296: if ($domconfig{'coursedefaults'} eq '') {
11297: $domconfig{'coursedefaults'} = {};
11298: }
11299: }
11300:
11301: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11302: foreach my $item (@toggles) {
11303: if ($defaultchecked{$item} eq 'on') {
11304: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11305: ($env{'form.'.$item} eq '0')) {
11306: $changes{$item} = 1;
1.192 raeburn 11307: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11308: $changes{$item} = 1;
11309: }
11310: } elsif ($defaultchecked{$item} eq 'off') {
11311: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11312: ($env{'form.'.$item} eq '1')) {
11313: $changes{$item} = 1;
11314: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11315: $changes{$item} = 1;
11316: }
11317: }
11318: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11319: }
1.198 raeburn 11320: foreach my $item (@numbers) {
11321: my ($currdef,$newdef);
1.208 raeburn 11322: $newdef = $env{'form.'.$item};
1.198 raeburn 11323: if ($item eq 'anonsurvey_threshold') {
11324: $currdef = $domconfig{'coursedefaults'}{$item};
11325: $newdef =~ s/\D//g;
11326: if ($newdef eq '' || $newdef < 1) {
11327: $newdef = 1;
11328: }
11329: $defaultshash{'coursedefaults'}{$item} = $newdef;
11330: } else {
11331: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
11332: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11333: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
11334: }
11335: $newdef =~ s/[^\w.\-]//g;
11336: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
11337: }
11338: if ($currdef ne $newdef) {
11339: my $staticdef;
11340: if ($item eq 'anonsurvey_threshold') {
11341: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11342: $changes{$item} = 1;
11343: }
11344: } else {
11345: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
11346: $changes{'uploadquota'} = 1;
11347: }
11348: }
1.139 raeburn 11349: }
11350: }
1.264 raeburn 11351: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11352: my @currclonecode;
11353: if (ref($currclone) eq 'HASH') {
11354: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11355: @currclonecode = @{$currclone->{'instcode'}};
11356: }
11357: }
11358: my $newclone;
11359: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11360: $newclone = $env{'form.canclone'};
11361: }
11362: if ($newclone eq 'instcode') {
11363: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11364: my (%codedefaults,@code_order,@clonecode);
11365: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11366: \@code_order);
11367: foreach my $item (@code_order) {
11368: if (grep(/^\Q$item\E$/,@newcodes)) {
11369: push(@clonecode,$item);
11370: }
11371: }
11372: if (@clonecode) {
11373: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11374: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11375: if (@diffs) {
11376: $changes{'canclone'} = 1;
11377: }
11378: } else {
11379: $newclone eq '';
11380: }
11381: } elsif ($newclone ne '') {
11382: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11383: }
11384: if ($newclone ne $currclone) {
11385: $changes{'canclone'} = 1;
11386: }
1.257 raeburn 11387: my %credits;
11388: foreach my $type (@types) {
11389: unless ($type eq 'community') {
11390: $credits{$type} = $env{'form.'.$type.'_credits'};
11391: $credits{$type} =~ s/[^\d.]+//g;
11392: }
11393: }
11394: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11395: ($env{'form.coursecredits'} eq '1')) {
11396: $changes{'coursecredits'} = 1;
11397: foreach my $type (keys(%credits)) {
11398: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11399: }
11400: } else {
11401: if ($env{'form.coursecredits'} eq '1') {
11402: foreach my $type (@types) {
11403: unless ($type eq 'community') {
11404: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11405: $changes{'coursecredits'} = 1;
11406: }
11407: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11408: }
11409: }
11410: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11411: foreach my $type (@types) {
11412: unless ($type eq 'community') {
11413: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11414: $changes{'coursecredits'} = 1;
11415: last;
11416: }
11417: }
11418: }
11419: }
11420: }
11421: if ($env{'form.postsubmit'} eq '1') {
11422: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11423: my %currtimeout;
11424: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11425: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11426: $changes{'postsubmit'} = 1;
11427: }
11428: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11429: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11430: }
11431: } else {
11432: $changes{'postsubmit'} = 1;
11433: }
11434: foreach my $type (@types) {
11435: my $timeout = $env{'form.'.$type.'_timeout'};
11436: $timeout =~ s/\D//g;
11437: if ($timeout == $staticdefaults{'postsubmit'}) {
11438: $timeout = '';
11439: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11440: $timeout = '0';
11441: }
11442: unless ($timeout eq '') {
11443: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11444: }
11445: if (exists($currtimeout{$type})) {
11446: if ($timeout ne $currtimeout{$type}) {
11447: $changes{'postsubmit'} = 1;
11448: }
11449: } elsif ($timeout ne '') {
11450: $changes{'postsubmit'} = 1;
11451: }
11452: }
11453: } else {
11454: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11455: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11456: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11457: $changes{'postsubmit'} = 1;
11458: }
11459: } else {
11460: $changes{'postsubmit'} = 1;
11461: }
1.192 raeburn 11462: }
1.121 raeburn 11463: }
11464: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11465: $dom);
11466: if ($putresult eq 'ok') {
11467: if (keys(%changes) > 0) {
1.213 raeburn 11468: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11469: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11470: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
11471: ($changes{'canclone'})) {
1.257 raeburn 11472: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11473: if ($changes{$item}) {
11474: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11475: }
11476: }
1.192 raeburn 11477: if ($changes{'coursecredits'}) {
11478: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11479: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11480: $domdefaults{$type.'credits'} =
11481: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11482: }
11483: }
11484: }
11485: if ($changes{'postsubmit'}) {
11486: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11487: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11488: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11489: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11490: $domdefaults{$type.'postsubtimeout'} =
11491: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11492: }
11493: }
1.192 raeburn 11494: }
11495: }
1.198 raeburn 11496: if ($changes{'uploadquota'}) {
11497: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11498: foreach my $type (@types) {
11499: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11500: }
11501: }
11502: }
1.264 raeburn 11503: if ($changes{'canclone'}) {
11504: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11505: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11506: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11507: if (@clonecodes) {
11508: $domdefaults{'canclone'} = join('+',@clonecodes);
11509: }
11510: }
11511: } else {
11512: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11513: }
11514: }
1.121 raeburn 11515: my $cachetime = 24*60*60;
11516: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11517: if (ref($lastactref) eq 'HASH') {
11518: $lastactref->{'domdefaults'} = 1;
11519: }
1.121 raeburn 11520: }
11521: $resulttext = &mt('Changes made:').'<ul>';
11522: foreach my $item (sort(keys(%changes))) {
11523: if ($item eq 'canuse_pdfforms') {
11524: if ($env{'form.'.$item} eq '1') {
11525: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11526: } else {
11527: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11528: }
1.257 raeburn 11529: } elsif ($item eq 'uselcmath') {
11530: if ($env{'form.'.$item} eq '1') {
11531: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11532: } else {
11533: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11534: }
11535: } elsif ($item eq 'usejsme') {
11536: if ($env{'form.'.$item} eq '1') {
11537: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11538: } else {
11539: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11540: }
1.139 raeburn 11541: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 11542: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 11543: } elsif ($item eq 'uploadquota') {
11544: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11545: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11546: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11547: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 11548: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11549:
1.198 raeburn 11550: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11551: '</ul>'.
11552: '</li>';
11553: } else {
11554: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11555: }
1.257 raeburn 11556: } elsif ($item eq 'postsubmit') {
11557: if ($domdefaults{'postsubmit'} eq 'off') {
11558: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11559: } else {
11560: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11561: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11562: $resulttext .= &mt('durations:').'<ul>';
11563: foreach my $type (@types) {
11564: $resulttext .= '<li>';
11565: my $timeout;
11566: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11567: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11568: }
11569: my $display;
11570: if ($timeout eq '0') {
11571: $display = &mt('unlimited');
11572: } elsif ($timeout eq '') {
11573: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11574: } else {
11575: $display = &mt('[quant,_1,second]',$timeout);
11576: }
11577: if ($type eq 'community') {
11578: $resulttext .= &mt('Communities');
11579: } elsif ($type eq 'official') {
11580: $resulttext .= &mt('Official courses');
11581: } elsif ($type eq 'unofficial') {
11582: $resulttext .= &mt('Unofficial courses');
11583: } elsif ($type eq 'textbook') {
11584: $resulttext .= &mt('Textbook courses');
11585: }
11586: $resulttext .= ' -- '.$display.'</li>';
11587: }
11588: $resulttext .= '</ul>';
11589: }
11590: $resulttext .= '</li>';
11591: }
1.192 raeburn 11592: } elsif ($item eq 'coursecredits') {
11593: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11594: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 11595: ($domdefaults{'unofficialcredits'} eq '') &&
11596: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 11597: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11598: } else {
11599: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11600: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11601: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 11602: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 11603: '</ul>'.
11604: '</li>';
11605: }
11606: } else {
11607: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11608: }
1.264 raeburn 11609: } elsif ($item eq 'canclone') {
11610: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11611: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11612: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11613: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11614: }
11615: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11616: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11617: } else {
11618: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11619: }
1.140 raeburn 11620: }
1.121 raeburn 11621: }
11622: $resulttext .= '</ul>';
11623: } else {
11624: $resulttext = &mt('No changes made to course defaults');
11625: }
11626: } else {
11627: $resulttext = '<span class="LC_error">'.
11628: &mt('An error occurred: [_1]',$putresult).'</span>';
11629: }
11630: return $resulttext;
11631: }
11632:
1.231 raeburn 11633: sub modify_selfenrollment {
11634: my ($dom,$lastactref,%domconfig) = @_;
11635: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
11636: my @types = ('official','unofficial','community','textbook');
11637: my %titles = &tool_titles();
1.232 raeburn 11638: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11639: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 11640: $ordered{'default'} = ['types','registered','approval','limit'];
11641:
11642: my (%roles,%shown,%toplevel);
11643: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11644:
11645: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11646: if ($domconfig{'selfenrollment'} eq '') {
11647: $domconfig{'selfenrollment'} = {};
11648: }
11649: }
11650: %toplevel = (
11651: admin => 'Configuration Rights',
11652: default => 'Default settings',
11653: validation => 'Validation of self-enrollment requests',
11654: );
1.233 raeburn 11655: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 11656:
11657: if (ref($ordered{'admin'}) eq 'ARRAY') {
11658: foreach my $item (@{$ordered{'admin'}}) {
11659: foreach my $type (@types) {
11660: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
11661: $selfenrollhash{'admin'}{$type}{$item} = 1;
11662: } else {
11663: $selfenrollhash{'admin'}{$type}{$item} = 0;
11664: }
11665: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
11666: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
11667: if ($selfenrollhash{'admin'}{$type}{$item} ne
11668: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
11669: push(@{$changes{'admin'}{$type}},$item);
11670: }
11671: } else {
11672: if (!$selfenrollhash{'admin'}{$type}{$item}) {
11673: push(@{$changes{'admin'}{$type}},$item);
11674: }
11675: }
11676: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
11677: push(@{$changes{'admin'}{$type}},$item);
11678: }
11679: }
11680: }
11681: }
11682:
11683: foreach my $item (@{$ordered{'default'}}) {
11684: foreach my $type (@types) {
11685: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
11686: if ($item eq 'types') {
11687: unless (($value eq 'all') || ($value eq 'dom')) {
11688: $value = '';
11689: }
11690: } elsif ($item eq 'registered') {
11691: unless ($value eq '1') {
11692: $value = 0;
11693: }
11694: } elsif ($item eq 'approval') {
11695: unless ($value =~ /^[012]$/) {
11696: $value = 0;
11697: }
11698: } else {
11699: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11700: $value = 'none';
11701: }
11702: }
11703: $selfenrollhash{'default'}{$type}{$item} = $value;
11704: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
11705: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11706: if ($selfenrollhash{'default'}{$type}{$item} ne
11707: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
11708: push(@{$changes{'default'}{$type}},$item);
11709: }
11710: } else {
11711: push(@{$changes{'default'}{$type}},$item);
11712: }
11713: } else {
11714: push(@{$changes{'default'}{$type}},$item);
11715: }
11716: if ($item eq 'limit') {
11717: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11718: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
11719: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
11720: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
11721: }
11722: } else {
11723: $selfenrollhash{'default'}{$type}{'cap'} = '';
11724: }
11725: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11726: if ($selfenrollhash{'default'}{$type}{'cap'} ne
11727: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
11728: push(@{$changes{'default'}{$type}},'cap');
11729: }
11730: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
11731: push(@{$changes{'default'}{$type}},'cap');
11732: }
11733: }
11734: }
11735: }
11736:
11737: foreach my $item (@{$itemsref}) {
11738: if ($item eq 'fields') {
11739: my @changed;
11740: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
11741: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
11742: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
11743: }
11744: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11745: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
11746: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
11747: $domconfig{'selfenrollment'}{'validation'}{$item});
11748: } else {
11749: @changed = @{$selfenrollhash{'validation'}{$item}};
11750: }
11751: } else {
11752: @changed = @{$selfenrollhash{'validation'}{$item}};
11753: }
11754: if (@changed) {
11755: if ($selfenrollhash{'validation'}{$item}) {
11756: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
11757: } else {
11758: $changes{'validation'}{$item} = &mt('None');
11759: }
11760: }
11761: } else {
11762: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
11763: if ($item eq 'markup') {
11764: if ($env{'form.selfenroll_validation_'.$item}) {
11765: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11766: }
11767: }
11768: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11769: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
11770: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
11771: }
11772: }
11773: }
11774: }
11775:
11776: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
11777: $dom);
11778: if ($putresult eq 'ok') {
11779: if (keys(%changes) > 0) {
11780: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11781: $resulttext = &mt('Changes made:').'<ul>';
11782: foreach my $key ('admin','default','validation') {
11783: if (ref($changes{$key}) eq 'HASH') {
11784: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11785: if ($key eq 'validation') {
11786: foreach my $item (@{$itemsref}) {
11787: if (exists($changes{$key}{$item})) {
11788: if ($item eq 'markup') {
11789: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11790: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11791: } else {
11792: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11793: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11794: }
11795: }
11796: }
11797: } else {
11798: foreach my $type (@types) {
11799: if ($type eq 'community') {
11800: $roles{'1'} = &mt('Community personnel');
11801: } else {
11802: $roles{'1'} = &mt('Course personnel');
11803: }
11804: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 11805: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11806: if ($key eq 'admin') {
11807: my @mgrdc = ();
11808: if (ref($ordered{$key}) eq 'ARRAY') {
11809: foreach my $item (@{$ordered{'admin'}}) {
11810: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11811: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11812: push(@mgrdc,$item);
11813: }
11814: }
11815: }
11816: if (@mgrdc) {
11817: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11818: } else {
11819: delete($domdefaults{$type.'selfenrolladmdc'});
11820: }
11821: }
11822: } else {
11823: if (ref($ordered{$key}) eq 'ARRAY') {
11824: foreach my $item (@{$ordered{$key}}) {
11825: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11826: $domdefaults{$type.'selfenroll'.$item} =
11827: $selfenrollhash{$key}{$type}{$item};
11828: }
11829: }
11830: }
11831: }
11832: }
1.231 raeburn 11833: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11834: foreach my $item (@{$ordered{$key}}) {
11835: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11836: $resulttext .= '<li>';
11837: if ($key eq 'admin') {
11838: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11839: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
11840: } else {
11841: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
11842: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
11843: }
11844: $resulttext .= '</li>';
11845: }
11846: }
11847: $resulttext .= '</ul></li>';
11848: }
11849: }
11850: $resulttext .= '</ul></li>';
11851: }
11852: }
1.232 raeburn 11853: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
11854: my $cachetime = 24*60*60;
11855: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11856: if (ref($lastactref) eq 'HASH') {
11857: $lastactref->{'domdefaults'} = 1;
11858: }
11859: }
1.231 raeburn 11860: }
11861: $resulttext .= '</ul>';
11862: } else {
11863: $resulttext = &mt('No changes made to self-enrollment settings');
11864: }
11865: } else {
11866: $resulttext = '<span class="LC_error">'.
11867: &mt('An error occurred: [_1]',$putresult).'</span>';
11868: }
11869: return $resulttext;
11870: }
11871:
1.137 raeburn 11872: sub modify_usersessions {
1.212 raeburn 11873: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 11874: my @hostingtypes = ('version','excludedomain','includedomain');
11875: my @offloadtypes = ('primary','default');
11876: my %types = (
11877: remote => \@hostingtypes,
11878: hosted => \@hostingtypes,
11879: spares => \@offloadtypes,
11880: );
11881: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 11882: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 11883: my (%by_ip,%by_location,@intdoms);
11884: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
11885: my @locations = sort(keys(%by_location));
1.137 raeburn 11886: my (%defaultshash,%changes);
11887: foreach my $prefix (@prefixes) {
11888: $defaultshash{'usersessions'}{$prefix} = {};
11889: }
1.212 raeburn 11890: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11891: my $resulttext;
1.138 raeburn 11892: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11893: foreach my $prefix (@prefixes) {
1.145 raeburn 11894: next if ($prefix eq 'spares');
11895: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11896: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11897: if ($type eq 'version') {
11898: my $value = $env{'form.'.$prefix.'_'.$type};
11899: my $okvalue;
11900: if ($value ne '') {
11901: if (grep(/^\Q$value\E$/,@lcversions)) {
11902: $okvalue = $value;
11903: }
11904: }
11905: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11906: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11907: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11908: if ($inuse == 0) {
11909: $changes{$prefix}{$type} = 1;
11910: } else {
11911: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11912: $changes{$prefix}{$type} = 1;
11913: }
11914: if ($okvalue ne '') {
11915: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11916: }
11917: }
11918: } else {
11919: if (($inuse == 1) && ($okvalue ne '')) {
11920: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11921: $changes{$prefix}{$type} = 1;
11922: }
11923: }
11924: } else {
11925: if (($inuse == 1) && ($okvalue ne '')) {
11926: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11927: $changes{$prefix}{$type} = 1;
11928: }
11929: }
11930: } else {
11931: if (($inuse == 1) && ($okvalue ne '')) {
11932: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11933: $changes{$prefix}{$type} = 1;
11934: }
11935: }
11936: } else {
11937: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11938: my @okvals;
11939: foreach my $val (@vals) {
1.138 raeburn 11940: if ($val =~ /:/) {
11941: my @items = split(/:/,$val);
11942: foreach my $item (@items) {
11943: if (ref($by_location{$item}) eq 'ARRAY') {
11944: push(@okvals,$item);
11945: }
11946: }
11947: } else {
11948: if (ref($by_location{$val}) eq 'ARRAY') {
11949: push(@okvals,$val);
11950: }
1.137 raeburn 11951: }
11952: }
11953: @okvals = sort(@okvals);
11954: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11955: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11956: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11957: if ($inuse == 0) {
11958: $changes{$prefix}{$type} = 1;
11959: } else {
11960: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11961: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11962: if (@changed > 0) {
11963: $changes{$prefix}{$type} = 1;
11964: }
11965: }
11966: } else {
11967: if ($inuse == 1) {
11968: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11969: $changes{$prefix}{$type} = 1;
11970: }
11971: }
11972: } else {
11973: if ($inuse == 1) {
11974: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11975: $changes{$prefix}{$type} = 1;
11976: }
11977: }
11978: } else {
11979: if ($inuse == 1) {
11980: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11981: $changes{$prefix}{$type} = 1;
11982: }
11983: }
11984: }
11985: }
11986: }
1.145 raeburn 11987:
11988: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11989: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11990: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11991: my $savespares;
11992:
11993: foreach my $lonhost (sort(keys(%servers))) {
11994: my $serverhomeID =
11995: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11996: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11997: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11998: my %spareschg;
11999: foreach my $type (@{$types{'spares'}}) {
12000: my @okspares;
12001: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12002: foreach my $server (@checked) {
1.152 raeburn 12003: if (&Apache::lonnet::hostname($server) ne '') {
12004: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12005: unless (grep(/^\Q$server\E$/,@okspares)) {
12006: push(@okspares,$server);
12007: }
1.145 raeburn 12008: }
12009: }
12010: }
12011: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12012: my $newspare;
1.152 raeburn 12013: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12014: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12015: $newspare = $new;
12016: }
12017: }
1.152 raeburn 12018: my @spares;
12019: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12020: @spares = sort(@okspares,$newspare);
12021: } else {
12022: @spares = sort(@okspares);
12023: }
12024: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12025: if (ref($spareid{$lonhost}) eq 'HASH') {
12026: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12027: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12028: if (@diffs > 0) {
12029: $spareschg{$type} = 1;
12030: }
12031: }
12032: }
12033: }
12034: if (keys(%spareschg) > 0) {
12035: $changes{'spares'}{$lonhost} = \%spareschg;
12036: }
12037: }
1.261 raeburn 12038: $defaultshash{'usersessions'}{'offloadnow'} = {};
12039: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12040: my @okoffload;
12041: if (@offloadnow) {
12042: foreach my $server (@offloadnow) {
12043: if (&Apache::lonnet::hostname($server) ne '') {
12044: unless (grep(/^\Q$server\E$/,@okoffload)) {
12045: push(@okoffload,$server);
12046: }
12047: }
12048: }
12049: if (@okoffload) {
12050: foreach my $lonhost (@okoffload) {
12051: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12052: }
12053: }
12054: }
1.145 raeburn 12055: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12056: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12057: if (ref($changes{'spares'}) eq 'HASH') {
12058: if (keys(%{$changes{'spares'}}) > 0) {
12059: $savespares = 1;
12060: }
12061: }
12062: } else {
12063: $savespares = 1;
12064: }
1.261 raeburn 12065: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12066: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12067: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12068: $changes{'offloadnow'} = 1;
12069: last;
12070: }
12071: }
12072: unless ($changes{'offloadnow'}) {
12073: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12074: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12075: $changes{'offloadnow'} = 1;
12076: last;
12077: }
12078: }
12079: }
12080: } elsif (@okoffload) {
12081: $changes{'offloadnow'} = 1;
12082: }
12083: } elsif (@okoffload) {
12084: $changes{'offloadnow'} = 1;
1.145 raeburn 12085: }
1.147 raeburn 12086: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12087: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12088: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12089: $dom);
12090: if ($putresult eq 'ok') {
12091: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12092: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12093: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12094: }
12095: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12096: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12097: }
1.261 raeburn 12098: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12099: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12100: }
1.137 raeburn 12101: }
12102: my $cachetime = 24*60*60;
12103: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12104: if (ref($lastactref) eq 'HASH') {
12105: $lastactref->{'domdefaults'} = 1;
12106: }
1.147 raeburn 12107: if (keys(%changes) > 0) {
12108: my %lt = &usersession_titles();
12109: $resulttext = &mt('Changes made:').'<ul>';
12110: foreach my $prefix (@prefixes) {
12111: if (ref($changes{$prefix}) eq 'HASH') {
12112: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12113: if ($prefix eq 'spares') {
12114: if (ref($changes{$prefix}) eq 'HASH') {
12115: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12116: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12117: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12118: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12119: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12120: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12121: foreach my $type (@{$types{$prefix}}) {
12122: if ($changes{$prefix}{$lonhost}{$type}) {
12123: my $offloadto = &mt('None');
12124: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12125: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12126: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12127: }
1.145 raeburn 12128: }
1.147 raeburn 12129: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12130: }
1.137 raeburn 12131: }
12132: }
1.147 raeburn 12133: $resulttext .= '</li>';
1.137 raeburn 12134: }
12135: }
1.147 raeburn 12136: } else {
12137: foreach my $type (@{$types{$prefix}}) {
12138: if (defined($changes{$prefix}{$type})) {
12139: my $newvalue;
12140: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12141: if (ref($defaultshash{'usersessions'}{$prefix})) {
12142: if ($type eq 'version') {
12143: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12144: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12145: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12146: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12147: }
1.145 raeburn 12148: }
12149: }
12150: }
1.147 raeburn 12151: if ($newvalue eq '') {
12152: if ($type eq 'version') {
12153: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12154: } else {
12155: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12156: }
1.145 raeburn 12157: } else {
1.147 raeburn 12158: if ($type eq 'version') {
12159: $newvalue .= ' '.&mt('(or later)');
12160: }
12161: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12162: }
1.137 raeburn 12163: }
12164: }
12165: }
1.147 raeburn 12166: $resulttext .= '</ul>';
1.137 raeburn 12167: }
12168: }
1.261 raeburn 12169: if ($changes{'offloadnow'}) {
12170: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12171: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12172: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12173: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12174: $resulttext .= '<li>'.$lonhost.'</li>';
12175: }
12176: $resulttext .= '</ul>';
12177: } else {
12178: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12179: }
12180: } else {
12181: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12182: }
12183: }
1.147 raeburn 12184: $resulttext .= '</ul>';
12185: } else {
12186: $resulttext = $nochgmsg;
1.137 raeburn 12187: }
12188: } else {
12189: $resulttext = '<span class="LC_error">'.
12190: &mt('An error occurred: [_1]',$putresult).'</span>';
12191: }
12192: } else {
1.147 raeburn 12193: $resulttext = $nochgmsg;
1.137 raeburn 12194: }
12195: return $resulttext;
12196: }
12197:
1.150 raeburn 12198: sub modify_loadbalancing {
12199: my ($dom,%domconfig) = @_;
12200: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12201: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12202: my ($othertitle,$usertypes,$types) =
12203: &Apache::loncommon::sorted_inst_types($dom);
12204: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12205: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12206: my @sparestypes = ('primary','default');
12207: my %typetitles = &sparestype_titles();
12208: my $resulttext;
1.171 raeburn 12209: my (%currbalancer,%currtargets,%currrules,%existing);
12210: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12211: %existing = %{$domconfig{'loadbalancing'}};
12212: }
12213: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12214: \%currtargets,\%currrules);
12215: my ($saveloadbalancing,%defaultshash,%changes);
12216: my ($alltypes,$othertypes,$titles) =
12217: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12218: my %ruletitles = &offloadtype_text();
12219: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12220: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12221: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12222: if ($balancer eq '') {
12223: next;
12224: }
1.210 raeburn 12225: if (!exists($servers{$balancer})) {
1.171 raeburn 12226: if (exists($currbalancer{$balancer})) {
12227: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12228: }
1.171 raeburn 12229: next;
12230: }
12231: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12232: push(@{$changes{'delete'}},$balancer);
12233: next;
12234: }
12235: if (!exists($currbalancer{$balancer})) {
12236: push(@{$changes{'add'}},$balancer);
12237: }
12238: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12239: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12240: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12241: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12242: $saveloadbalancing = 1;
12243: }
12244: foreach my $sparetype (@sparestypes) {
12245: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12246: my @offloadto;
12247: foreach my $target (@targets) {
12248: if (($servers{$target}) && ($target ne $balancer)) {
12249: if ($sparetype eq 'default') {
12250: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12251: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12252: }
12253: }
1.171 raeburn 12254: unless(grep(/^\Q$target\E$/,@offloadto)) {
12255: push(@offloadto,$target);
12256: }
1.150 raeburn 12257: }
1.171 raeburn 12258: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12259: }
12260: }
1.171 raeburn 12261: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12262: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12263: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12264: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12265: if (@targetdiffs > 0) {
1.171 raeburn 12266: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12267: }
1.171 raeburn 12268: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12269: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12270: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12271: }
12272: }
12273: }
12274: } else {
1.171 raeburn 12275: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 12276: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12277: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12278: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12279: $changes{'curr'}{$balancer}{'targets'} = 1;
12280: }
1.150 raeburn 12281: }
12282: }
1.210 raeburn 12283: }
1.150 raeburn 12284: }
12285: my $ishomedom;
1.171 raeburn 12286: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12287: $ishomedom = 1;
1.150 raeburn 12288: }
12289: if (ref($alltypes) eq 'ARRAY') {
12290: foreach my $type (@{$alltypes}) {
12291: my $rule;
1.210 raeburn 12292: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12293: (!$ishomedom)) {
1.171 raeburn 12294: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12295: }
12296: if ($rule eq 'specific') {
1.255 raeburn 12297: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12298: if (exists($servers{$specifiedhost})) {
12299: $rule = $specifiedhost;
12300: }
1.150 raeburn 12301: }
1.171 raeburn 12302: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12303: if (ref($currrules{$balancer}) eq 'HASH') {
12304: if ($rule ne $currrules{$balancer}{$type}) {
12305: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12306: }
12307: } elsif ($rule ne '') {
1.171 raeburn 12308: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12309: }
12310: }
12311: }
1.171 raeburn 12312: }
12313: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12314: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12315: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12316: $defaultshash{'loadbalancing'} = {};
12317: }
12318: my $putresult = &Apache::lonnet::put_dom('configuration',
12319: \%defaultshash,$dom);
12320: if ($putresult eq 'ok') {
12321: if (keys(%changes) > 0) {
1.252 raeburn 12322: my %toupdate;
1.171 raeburn 12323: if (ref($changes{'delete'}) eq 'ARRAY') {
12324: foreach my $balancer (sort(@{$changes{'delete'}})) {
12325: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 12326: $toupdate{$balancer} = 1;
1.150 raeburn 12327: }
1.171 raeburn 12328: }
12329: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 12330: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 12331: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 12332: $toupdate{$balancer} = 1;
1.171 raeburn 12333: }
12334: }
12335: if (ref($changes{'curr'}) eq 'HASH') {
12336: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 12337: $toupdate{$balancer} = 1;
1.171 raeburn 12338: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12339: if ($changes{'curr'}{$balancer}{'targets'}) {
12340: my %offloadstr;
12341: foreach my $sparetype (@sparestypes) {
12342: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12343: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12344: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12345: }
12346: }
1.150 raeburn 12347: }
1.171 raeburn 12348: if (keys(%offloadstr) == 0) {
12349: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12350: } else {
1.171 raeburn 12351: my $showoffload;
12352: foreach my $sparetype (@sparestypes) {
12353: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12354: if (defined($offloadstr{$sparetype})) {
12355: $showoffload .= $offloadstr{$sparetype};
12356: } else {
12357: $showoffload .= &mt('None');
12358: }
12359: $showoffload .= (' 'x3);
12360: }
12361: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12362: }
12363: }
12364: }
1.171 raeburn 12365: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12366: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12367: foreach my $type (@{$alltypes}) {
12368: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12369: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12370: my $balancetext;
12371: if ($rule eq '') {
12372: $balancetext = $ruletitles{'default'};
1.209 raeburn 12373: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 12374: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12375: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 12376: foreach my $sparetype (@sparestypes) {
12377: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12378: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12379: }
12380: }
1.253 raeburn 12381: foreach my $item (@{$alltypes}) {
12382: next if ($item =~ /^_LC_ipchange/);
12383: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12384: if ($hasrule eq 'homeserver') {
12385: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12386: } else {
12387: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12388: if ($servers{$hasrule}) {
12389: $toupdate{$hasrule} = 1;
12390: }
12391: }
12392: }
12393: }
1.254 raeburn 12394: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12395: $balancetext = $ruletitles{$rule};
12396: } else {
12397: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12398: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12399: if ($receiver) {
12400: $toupdate{$receiver};
12401: }
12402: }
12403: } else {
12404: $balancetext = $ruletitles{$rule};
1.252 raeburn 12405: }
1.171 raeburn 12406: } else {
12407: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12408: }
1.210 raeburn 12409: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12410: }
12411: }
12412: }
12413: }
1.252 raeburn 12414: if (keys(%toupdate)) {
12415: my %thismachine;
12416: my $updatedhere;
12417: my $cachetime = 60*60*24;
12418: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12419: foreach my $lonhost (keys(%toupdate)) {
12420: if ($thismachine{$lonhost}) {
12421: unless ($updatedhere) {
12422: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12423: $defaultshash{'loadbalancing'},
12424: $cachetime);
12425: $updatedhere = 1;
12426: }
12427: } else {
12428: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12429: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12430: }
12431: }
12432: }
1.150 raeburn 12433: }
1.171 raeburn 12434: }
12435: if ($resulttext ne '') {
12436: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12437: } else {
12438: $resulttext = $nochgmsg;
12439: }
12440: } else {
1.171 raeburn 12441: $resulttext = $nochgmsg;
1.150 raeburn 12442: }
12443: } else {
1.171 raeburn 12444: $resulttext = '<span class="LC_error">'.
12445: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12446: }
12447: } else {
1.171 raeburn 12448: $resulttext = $nochgmsg;
1.150 raeburn 12449: }
12450: return $resulttext;
12451: }
12452:
1.48 raeburn 12453: sub recurse_check {
12454: my ($chkcats,$categories,$depth,$name) = @_;
12455: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12456: my $chg = 0;
12457: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12458: my $category = $chkcats->[$depth]{$name}[$j];
12459: my $item;
12460: if ($category eq '') {
12461: $chg ++;
12462: } else {
12463: my $deeper = $depth + 1;
12464: $item = &escape($category).':'.&escape($name).':'.$depth;
12465: if ($chg) {
12466: $categories->{$item} -= $chg;
12467: }
12468: &recurse_check($chkcats,$categories,$deeper,$category);
12469: $deeper --;
12470: }
12471: }
12472: }
12473: return;
12474: }
12475:
12476: sub recurse_cat_deletes {
12477: my ($item,$coursecategories,$deletions) = @_;
12478: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12479: my $subdepth = $depth + 1;
12480: if (ref($coursecategories) eq 'HASH') {
12481: foreach my $subitem (keys(%{$coursecategories})) {
12482: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12483: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12484: delete($coursecategories->{$subitem});
12485: $deletions->{$subitem} = 1;
12486: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 12487: }
1.48 raeburn 12488: }
12489: }
12490: return;
12491: }
12492:
1.125 raeburn 12493: sub get_active_dcs {
12494: my ($dom) = @_;
1.191 raeburn 12495: my $now = time;
12496: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 12497: my %domcoords;
12498: my $numdcs = 0;
12499: foreach my $server (keys(%dompersonnel)) {
12500: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
12501: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 12502: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 12503: }
12504: }
12505: return %domcoords;
12506: }
12507:
12508: sub active_dc_picker {
1.191 raeburn 12509: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 12510: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 12511: my @domcoord = keys(%domcoords);
12512: if (keys(%currhash)) {
12513: foreach my $dc (keys(%currhash)) {
12514: unless (exists($domcoords{$dc})) {
12515: push(@domcoord,$dc);
12516: }
12517: }
12518: }
12519: @domcoord = sort(@domcoord);
1.210 raeburn 12520: my $numdcs = scalar(@domcoord);
1.191 raeburn 12521: my $rows = 0;
12522: my $table;
1.125 raeburn 12523: if ($numdcs > 1) {
1.191 raeburn 12524: $table = '<table>';
12525: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12526: my $rem = $i%($numinrow);
12527: if ($rem == 0) {
12528: if ($i > 0) {
1.191 raeburn 12529: $table .= '</tr>';
1.125 raeburn 12530: }
1.191 raeburn 12531: $table .= '<tr>';
12532: $rows ++;
1.125 raeburn 12533: }
1.191 raeburn 12534: my $check = '';
12535: if ($inputtype eq 'radio') {
12536: if (keys(%currhash) == 0) {
12537: if (!$i) {
12538: $check = ' checked="checked"';
12539: }
12540: } elsif (exists($currhash{$domcoord[$i]})) {
12541: $check = ' checked="checked"';
12542: }
12543: } else {
12544: if (exists($currhash{$domcoord[$i]})) {
12545: $check = ' checked="checked"';
1.125 raeburn 12546: }
12547: }
1.191 raeburn 12548: if ($i == @domcoord - 1) {
1.125 raeburn 12549: my $colsleft = $numinrow - $rem;
12550: if ($colsleft > 1) {
1.191 raeburn 12551: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12552: } else {
1.191 raeburn 12553: $table .= '<td class="LC_left_item">';
1.125 raeburn 12554: }
12555: } else {
1.191 raeburn 12556: $table .= '<td class="LC_left_item">';
12557: }
12558: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12559: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12560: $table .= '<span class="LC_nobreak"><label>'.
12561: '<input type="'.$inputtype.'" name="'.$name.'"'.
12562: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12563: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 12564: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 12565: }
1.219 raeburn 12566: $table .= '</label></span></td>';
1.191 raeburn 12567: }
12568: $table .= '</tr></table>';
12569: } elsif ($numdcs == 1) {
1.219 raeburn 12570: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12571: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 12572: if ($inputtype eq 'radio') {
1.247 raeburn 12573: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 12574: if ($user ne $dcname.':'.$dcdom) {
12575: $table .= ' ('.$dcname.':'.$dcdom.')';
12576: }
1.191 raeburn 12577: } else {
12578: my $check;
12579: if (exists($currhash{$domcoord[0]})) {
12580: $check = ' checked="checked"';
1.125 raeburn 12581: }
1.247 raeburn 12582: $table = '<span class="LC_nobreak"><label>'.
12583: '<input type="checkbox" name="'.$name.'" '.
12584: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 12585: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 12586: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 12587: }
1.220 raeburn 12588: $table .= '</label></span>';
1.191 raeburn 12589: $rows ++;
1.125 raeburn 12590: }
12591: }
1.191 raeburn 12592: return ($numdcs,$table,$rows);
1.125 raeburn 12593: }
12594:
1.137 raeburn 12595: sub usersession_titles {
12596: return &Apache::lonlocal::texthash(
12597: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12598: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12599: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12600: version => 'LON-CAPA version requirement',
1.138 raeburn 12601: excludedomain => 'Allow all, but exclude specific domains',
12602: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12603: primary => 'Primary (checked first)',
1.154 raeburn 12604: default => 'Default',
1.137 raeburn 12605: );
12606: }
12607:
1.152 raeburn 12608: sub id_for_thisdom {
12609: my (%servers) = @_;
12610: my %altids;
12611: foreach my $server (keys(%servers)) {
12612: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12613: if ($serverhome ne $server) {
12614: $altids{$serverhome} = $server;
12615: }
12616: }
12617: return %altids;
12618: }
12619:
1.150 raeburn 12620: sub count_servers {
12621: my ($currbalancer,%servers) = @_;
12622: my (@spares,$numspares);
12623: foreach my $lonhost (sort(keys(%servers))) {
12624: next if ($currbalancer eq $lonhost);
12625: push(@spares,$lonhost);
12626: }
12627: if ($currbalancer) {
12628: $numspares = scalar(@spares);
12629: } else {
12630: $numspares = scalar(@spares) - 1;
12631: }
12632: return ($numspares,@spares);
12633: }
12634:
12635: sub lonbalance_targets_js {
1.171 raeburn 12636: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 12637: my $select = &mt('Select');
12638: my ($alltargets,$allishome,$allinsttypes,@alltypes);
12639: if (ref($servers) eq 'HASH') {
12640: $alltargets = join("','",sort(keys(%{$servers})));
12641: my @homedoms;
12642: foreach my $server (sort(keys(%{$servers}))) {
12643: if (&Apache::lonnet::host_domain($server) eq $dom) {
12644: push(@homedoms,'1');
12645: } else {
12646: push(@homedoms,'0');
12647: }
12648: }
12649: $allishome = join("','",@homedoms);
12650: }
12651: if (ref($types) eq 'ARRAY') {
12652: if (@{$types} > 0) {
12653: @alltypes = @{$types};
12654: }
12655: }
12656: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
12657: $allinsttypes = join("','",@alltypes);
1.171 raeburn 12658: my (%currbalancer,%currtargets,%currrules,%existing);
12659: if (ref($settings) eq 'HASH') {
12660: %existing = %{$settings};
12661: }
12662: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
12663: \%currtargets,\%currrules);
1.210 raeburn 12664: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 12665: return <<"END";
12666:
12667: <script type="text/javascript">
12668: // <![CDATA[
12669:
1.171 raeburn 12670: currBalancers = new Array('$balancers');
12671:
12672: function toggleTargets(balnum) {
12673: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12674: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
12675: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
12676: var prevbalancer = prevhostitem.value;
12677: var baltotal = document.getElementById('loadbalancing_total').value;
12678: prevhostitem.value = balancer;
12679: if (prevbalancer != '') {
12680: var prevIdx = currBalancers.indexOf(prevbalancer);
12681: if (prevIdx != -1) {
12682: currBalancers.splice(prevIdx,1);
12683: }
12684: }
1.150 raeburn 12685: if (balancer == '') {
1.171 raeburn 12686: hideSpares(balnum);
1.150 raeburn 12687: } else {
1.171 raeburn 12688: var currIdx = currBalancers.indexOf(balancer);
12689: if (currIdx == -1) {
12690: currBalancers.push(balancer);
12691: }
1.150 raeburn 12692: var homedoms = new Array('$allishome');
1.171 raeburn 12693: var ishomedom = homedoms[lonhostitem.selectedIndex];
12694: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 12695: }
1.171 raeburn 12696: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 12697: return;
12698: }
12699:
1.171 raeburn 12700: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 12701: var alltargets = new Array('$alltargets');
12702: var insttypes = new Array('$allinsttypes');
1.151 raeburn 12703: var offloadtypes = new Array('primary','default');
12704:
1.171 raeburn 12705: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
12706: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 12707:
1.151 raeburn 12708: for (var i=0; i<offloadtypes.length; i++) {
12709: var count = 0;
12710: for (var j=0; j<alltargets.length; j++) {
12711: if (alltargets[j] != balancer) {
1.171 raeburn 12712: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
12713: item.value = alltargets[j];
12714: item.style.textAlign='left';
12715: item.style.textFace='normal';
12716: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
12717: if (currBalancers.indexOf(alltargets[j]) == -1) {
12718: item.disabled = '';
12719: } else {
12720: item.disabled = 'disabled';
12721: item.checked = false;
12722: }
1.151 raeburn 12723: count ++;
12724: }
1.150 raeburn 12725: }
12726: }
1.151 raeburn 12727: for (var k=0; k<insttypes.length; k++) {
12728: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 12729: if (ishomedom == 1) {
1.171 raeburn 12730: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12731: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12732: } else {
1.171 raeburn 12733: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12734: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 12735: }
12736: } else {
1.171 raeburn 12737: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12738: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12739: }
1.151 raeburn 12740: if ((insttypes[k] != '_LC_external') &&
12741: ((insttypes[k] != '_LC_internetdom') ||
12742: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 12743: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
12744: item.options.length = 0;
12745: item.options[0] = new Option("","",true,true);
1.210 raeburn 12746: var idx = 0;
1.151 raeburn 12747: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 12748: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
12749: idx ++;
12750: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 12751: }
12752: }
12753: }
12754: }
12755: return;
12756: }
12757:
1.171 raeburn 12758: function hideSpares(balnum) {
1.150 raeburn 12759: var alltargets = new Array('$alltargets');
12760: var insttypes = new Array('$allinsttypes');
12761: var offloadtypes = new Array('primary','default');
12762:
1.171 raeburn 12763: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
12764: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 12765:
12766: var total = alltargets.length - 1;
12767: for (var i=0; i<offloadtypes; i++) {
12768: for (var j=0; j<total; j++) {
1.171 raeburn 12769: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
12770: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
12771: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 12772: }
1.150 raeburn 12773: }
12774: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 12775: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12776: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 12777: if (insttypes[k] != '_LC_external') {
1.171 raeburn 12778: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
12779: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 12780: }
12781: }
12782: return;
12783: }
12784:
1.171 raeburn 12785: function checkOffloads(item,balnum,type) {
1.150 raeburn 12786: var alltargets = new Array('$alltargets');
12787: var offloadtypes = new Array('primary','default');
12788: if (item.checked) {
12789: var total = alltargets.length - 1;
12790: var other;
12791: if (type == offloadtypes[0]) {
1.151 raeburn 12792: other = offloadtypes[1];
1.150 raeburn 12793: } else {
1.151 raeburn 12794: other = offloadtypes[0];
1.150 raeburn 12795: }
12796: for (var i=0; i<total; i++) {
1.171 raeburn 12797: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 12798: if (server == item.value) {
1.171 raeburn 12799: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12800: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 12801: }
12802: }
12803: }
12804: }
12805: return;
12806: }
12807:
1.171 raeburn 12808: function singleServerToggle(balnum,type) {
12809: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 12810: if (offloadtoSelIdx == 0) {
1.171 raeburn 12811: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12812: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12813:
12814: } else {
1.171 raeburn 12815: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12816: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 12817: }
12818: return;
12819: }
12820:
1.171 raeburn 12821: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 12822: if (type == '_LC_external') {
1.171 raeburn 12823: return;
1.150 raeburn 12824: }
1.171 raeburn 12825: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 12826: for (var i=0; i<typesRules.length; i++) {
12827: if (formname.elements[typesRules[i]].checked) {
12828: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 12829: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12830: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12831: } else {
1.171 raeburn 12832: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12833: }
12834: }
12835: }
12836: return;
12837: }
12838:
12839: function balancerDeleteChange(balnum) {
12840: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12841: var baltotal = document.getElementById('loadbalancing_total').value;
12842: var addtarget;
12843: var removetarget;
12844: var action = 'delete';
12845: if (document.getElementById('loadbalancing_delete_'+balnum)) {
12846: var lonhost = hostitem.value;
12847: var currIdx = currBalancers.indexOf(lonhost);
12848: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
12849: if (currIdx != -1) {
12850: currBalancers.splice(currIdx,1);
12851: }
12852: addtarget = lonhost;
12853: } else {
12854: if (currIdx == -1) {
12855: currBalancers.push(lonhost);
12856: }
12857: removetarget = lonhost;
12858: action = 'undelete';
12859: }
12860: balancerChange(balnum,baltotal,action,addtarget,removetarget);
12861: }
12862: return;
12863: }
12864:
12865: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
12866: if (baltotal > 1) {
12867: var offloadtypes = new Array('primary','default');
12868: var alltargets = new Array('$alltargets');
12869: var insttypes = new Array('$allinsttypes');
12870: for (var i=0; i<baltotal; i++) {
12871: if (i != balnum) {
12872: for (var j=0; j<offloadtypes.length; j++) {
12873: var total = alltargets.length - 1;
12874: for (var k=0; k<total; k++) {
12875: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
12876: var server = serveritem.value;
12877: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12878: if (server == addtarget) {
12879: serveritem.disabled = '';
12880: }
12881: }
12882: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12883: if (server == removetarget) {
12884: serveritem.disabled = 'disabled';
12885: serveritem.checked = false;
12886: }
12887: }
12888: }
12889: }
12890: for (var j=0; j<insttypes.length; j++) {
12891: if (insttypes[j] != '_LC_external') {
12892: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12893: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12894: var currSel = singleserver.selectedIndex;
12895: var currVal = singleserver.options[currSel].value;
12896: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12897: var numoptions = singleserver.options.length;
12898: var needsnew = 1;
12899: for (var k=0; k<numoptions; k++) {
12900: if (singleserver.options[k] == addtarget) {
12901: needsnew = 0;
12902: break;
12903: }
12904: }
12905: if (needsnew == 1) {
12906: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12907: }
12908: }
12909: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12910: singleserver.options.length = 0;
12911: if ((currVal) && (currVal != removetarget)) {
12912: singleserver.options[0] = new Option("","",false,false);
12913: } else {
12914: singleserver.options[0] = new Option("","",true,true);
12915: }
12916: var idx = 0;
12917: for (var m=0; m<alltargets.length; m++) {
12918: if (currBalancers.indexOf(alltargets[m]) == -1) {
12919: idx ++;
12920: if (currVal == alltargets[m]) {
12921: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12922: } else {
12923: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12924: }
12925: }
12926: }
12927: }
12928: }
12929: }
12930: }
1.150 raeburn 12931: }
12932: }
12933: }
12934: return;
12935: }
12936:
1.152 raeburn 12937: // ]]>
12938: </script>
12939:
12940: END
12941: }
12942:
12943: sub new_spares_js {
12944: my @sparestypes = ('primary','default');
12945: my $types = join("','",@sparestypes);
12946: my $select = &mt('Select');
12947: return <<"END";
12948:
12949: <script type="text/javascript">
12950: // <![CDATA[
12951:
12952: function updateNewSpares(formname,lonhost) {
12953: var types = new Array('$types');
12954: var include = new Array();
12955: var exclude = new Array();
12956: for (var i=0; i<types.length; i++) {
12957: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12958: for (var j=0; j<spareboxes.length; j++) {
12959: if (formname.elements[spareboxes[j]].checked) {
12960: exclude.push(formname.elements[spareboxes[j]].value);
12961: } else {
12962: include.push(formname.elements[spareboxes[j]].value);
12963: }
12964: }
12965: }
12966: for (var i=0; i<types.length; i++) {
12967: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12968: var selIdx = newSpare.selectedIndex;
12969: var currnew = newSpare.options[selIdx].value;
12970: var okSpares = new Array();
12971: for (var j=0; j<newSpare.options.length; j++) {
12972: var possible = newSpare.options[j].value;
12973: if (possible != '') {
12974: if (exclude.indexOf(possible) == -1) {
12975: okSpares.push(possible);
12976: } else {
12977: if (currnew == possible) {
12978: selIdx = 0;
12979: }
12980: }
12981: }
12982: }
12983: for (var k=0; k<include.length; k++) {
12984: if (okSpares.indexOf(include[k]) == -1) {
12985: okSpares.push(include[k]);
12986: }
12987: }
12988: okSpares.sort();
12989: newSpare.options.length = 0;
12990: if (selIdx == 0) {
12991: newSpare.options[0] = new Option("$select","",true,true);
12992: } else {
12993: newSpare.options[0] = new Option("$select","",false,false);
12994: }
12995: for (var m=0; m<okSpares.length; m++) {
12996: var idx = m+1;
12997: var selThis = 0;
12998: if (selIdx != 0) {
12999: if (okSpares[m] == currnew) {
13000: selThis = 1;
13001: }
13002: }
13003: if (selThis == 1) {
13004: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13005: } else {
13006: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13007: }
13008: }
13009: }
13010: return;
13011: }
13012:
13013: function checkNewSpares(lonhost,type) {
13014: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13015: var chosen = newSpare.options[newSpare.selectedIndex].value;
13016: if (chosen != '') {
13017: var othertype;
13018: var othernewSpare;
13019: if (type == 'primary') {
13020: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13021: }
13022: if (type == 'default') {
13023: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13024: }
13025: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13026: othernewSpare.selectedIndex = 0;
13027: }
13028: }
13029: return;
13030: }
13031:
13032: // ]]>
13033: </script>
13034:
13035: END
13036:
13037: }
13038:
13039: sub common_domprefs_js {
13040: return <<"END";
13041:
13042: <script type="text/javascript">
13043: // <![CDATA[
13044:
1.150 raeburn 13045: function getIndicesByName(formname,item) {
1.152 raeburn 13046: var group = new Array();
1.150 raeburn 13047: for (var i=0;i<formname.elements.length;i++) {
13048: if (formname.elements[i].name == item) {
1.152 raeburn 13049: group.push(formname.elements[i].id);
1.150 raeburn 13050: }
13051: }
1.152 raeburn 13052: return group;
1.150 raeburn 13053: }
13054:
13055: // ]]>
13056: </script>
13057:
13058: END
1.152 raeburn 13059:
1.150 raeburn 13060: }
13061:
1.165 raeburn 13062: sub recaptcha_js {
13063: my %lt = &captcha_phrases();
13064: return <<"END";
13065:
13066: <script type="text/javascript">
13067: // <![CDATA[
13068:
13069: function updateCaptcha(caller,context) {
13070: var privitem;
13071: var pubitem;
13072: var privtext;
13073: var pubtext;
1.269 raeburn 13074: var versionitem;
13075: var versiontext;
1.165 raeburn 13076: if (document.getElementById(context+'_recaptchapub')) {
13077: pubitem = document.getElementById(context+'_recaptchapub');
13078: } else {
13079: return;
13080: }
13081: if (document.getElementById(context+'_recaptchapriv')) {
13082: privitem = document.getElementById(context+'_recaptchapriv');
13083: } else {
13084: return;
13085: }
13086: if (document.getElementById(context+'_recaptchapubtxt')) {
13087: pubtext = document.getElementById(context+'_recaptchapubtxt');
13088: } else {
13089: return;
13090: }
13091: if (document.getElementById(context+'_recaptchaprivtxt')) {
13092: privtext = document.getElementById(context+'_recaptchaprivtxt');
13093: } else {
13094: return;
13095: }
1.269 raeburn 13096: if (document.getElementById(context+'_recaptchaversion')) {
13097: versionitem = document.getElementById(context+'_recaptchaversion');
13098: } else {
13099: return;
13100: }
13101: if (document.getElementById(context+'_recaptchavertxt')) {
13102: versiontext = document.getElementById(context+'_recaptchavertxt');
13103: } else {
13104: return;
13105: }
1.165 raeburn 13106: if (caller.checked) {
13107: if (caller.value == 'recaptcha') {
13108: pubitem.type = 'text';
13109: privitem.type = 'text';
13110: pubitem.size = '40';
13111: privitem.size = '40';
13112: pubtext.innerHTML = "$lt{'pub'}";
13113: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13114: versionitem.type = 'text';
13115: versionitem.size = '3';
13116: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13117: } else {
13118: pubitem.type = 'hidden';
13119: privitem.type = 'hidden';
1.269 raeburn 13120: versionitem.type = 'hidden';
1.165 raeburn 13121: pubtext.innerHTML = '';
13122: privtext.innerHTML = '';
1.269 raeburn 13123: versiontext.innerHTML = '';
1.165 raeburn 13124: }
13125: }
13126: return;
13127: }
13128:
13129: // ]]>
13130: </script>
13131:
13132: END
13133:
13134: }
13135:
1.236 raeburn 13136: sub toggle_display_js {
1.192 raeburn 13137: return <<"END";
13138:
13139: <script type="text/javascript">
13140: // <![CDATA[
13141:
1.236 raeburn 13142: function toggleDisplay(domForm,caller) {
13143: if (document.getElementById(caller)) {
13144: var divitem = document.getElementById(caller);
13145: var optionsElement = domForm.coursecredits;
1.264 raeburn 13146: var checkval = 1;
13147: var dispval = 'block';
1.236 raeburn 13148: if (caller == 'emailoptions') {
13149: optionsElement = domForm.cancreate_email;
13150: }
1.257 raeburn 13151: if (caller == 'studentsubmission') {
13152: optionsElement = domForm.postsubmit;
13153: }
1.264 raeburn 13154: if (caller == 'cloneinstcode') {
13155: optionsElement = domForm.canclone;
13156: checkval = 'instcode';
13157: }
1.236 raeburn 13158: if (optionsElement.length) {
1.192 raeburn 13159: var currval;
1.236 raeburn 13160: for (var i=0; i<optionsElement.length; i++) {
13161: if (optionsElement[i].checked) {
13162: currval = optionsElement[i].value;
1.192 raeburn 13163: }
13164: }
1.264 raeburn 13165: if (currval == checkval) {
13166: divitem.style.display = dispval;
1.192 raeburn 13167: } else {
1.236 raeburn 13168: divitem.style.display = 'none';
1.192 raeburn 13169: }
13170: }
13171: }
13172: return;
13173: }
13174:
13175: // ]]>
13176: </script>
13177:
13178: END
13179:
13180: }
13181:
1.165 raeburn 13182: sub captcha_phrases {
13183: return &Apache::lonlocal::texthash (
13184: priv => 'Private key',
13185: pub => 'Public key',
13186: original => 'original (CAPTCHA)',
13187: recaptcha => 'successor (ReCAPTCHA)',
13188: notused => 'unused',
1.269 raeburn 13189: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13190: );
13191: }
13192:
1.205 raeburn 13193: sub devalidate_remote_domconfs {
1.212 raeburn 13194: my ($dom,$cachekeys) = @_;
13195: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13196: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13197: my %thismachine;
13198: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13199: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13200: if (keys(%servers)) {
1.205 raeburn 13201: foreach my $server (keys(%servers)) {
13202: next if ($thismachine{$server});
1.212 raeburn 13203: my @cached;
13204: foreach my $name (@posscached) {
13205: if ($cachekeys->{$name}) {
13206: push(@cached,&escape($name).':'.&escape($dom));
13207: }
13208: }
13209: if (@cached) {
13210: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13211: }
1.205 raeburn 13212: }
13213: }
13214: return;
13215: }
13216:
1.3 raeburn 13217: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>