Annotation of loncom/interface/domainprefs.pm, revision 1.276
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.276 ! raeburn 4: # $Id: domainprefs.pm,v 1.275 2016/07/25 19:50:30 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.271 raeburn 106: (official, unofficial, community, textbook, and placement).
107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.275 raeburn 172: use LONCAPA::SSL;
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.267 raeburn 177: use Time::HiRes qw( sleep );
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
218: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 219: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 220: 'requestauthor','selfenrollment','inststatus',
1.275 raeburn 221: 'ltitools','ssl'],$dom);
1.43 raeburn 222: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 223: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 224: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 225: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 226: 'serverstatuses','helpsettings','coursedefaults',
1.275 raeburn 227: 'ltitools','selfenrollment','usersessions','ssl');
1.171 raeburn 228: my %existing;
229: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
230: %existing = %{$domconfig{'loadbalancing'}};
231: }
232: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 233: push(@prefs_order,'loadbalancing');
234: }
1.30 raeburn 235: my %prefs = (
236: 'rolecolors' =>
237: { text => 'Default color schemes',
1.67 raeburn 238: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 239: header => [{col1 => 'Student Settings',
240: col2 => '',},
241: {col1 => 'Coordinator Settings',
242: col2 => '',},
243: {col1 => 'Author Settings',
244: col2 => '',},
245: {col1 => 'Administrator Settings',
246: col2 => '',}],
1.230 raeburn 247: print => \&print_rolecolors,
248: modify => \&modify_rolecolors,
1.30 raeburn 249: },
1.110 raeburn 250: 'login' =>
1.30 raeburn 251: { text => 'Log-in page options',
1.67 raeburn 252: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 253: header => [{col1 => 'Log-in Page Items',
254: col2 => '',},
255: {col1 => 'Log-in Help',
1.256 raeburn 256: col2 => 'Value'},
257: {col1 => 'Custom HTML in document head',
1.168 raeburn 258: col2 => 'Value'}],
1.230 raeburn 259: print => \&print_login,
260: modify => \&modify_login,
1.30 raeburn 261: },
1.43 raeburn 262: 'defaults' =>
1.236 raeburn 263: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 264: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 265: header => [{col1 => 'Setting',
1.236 raeburn 266: col2 => 'Value'},
267: {col1 => 'Institutional user types',
268: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.197 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.213 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.230 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.227 bisitz 297: col2 => 'Updatable user data'}],
1.230 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.230 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
310: { text => 'Institutional directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 312: header => [{col1 => 'Setting',
313: col2 => 'Value',}],
1.230 raeburn 314: print => \&print_directorysrch,
315: modify => \&modify_directorysrch,
1.30 raeburn 316: },
317: 'contacts' =>
318: { text => 'Contact Information',
1.67 raeburn 319: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 320: header => [{col1 => 'Setting',
321: col2 => 'Value',}],
1.230 raeburn 322: print => \&print_contacts,
323: modify => \&modify_contacts,
1.30 raeburn 324: },
325: 'usercreation' =>
326: { text => 'User creation',
1.67 raeburn 327: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 328: header => [{col1 => 'Format rule type',
329: col2 => 'Format rules in force'},
1.34 raeburn 330: {col1 => 'User account creation',
331: col2 => 'Usernames which may be created',},
1.30 raeburn 332: {col1 => 'Context',
1.43 raeburn 333: col2 => 'Assignable authentication types'}],
1.230 raeburn 334: print => \&print_usercreation,
335: modify => \&modify_usercreation,
1.30 raeburn 336: },
1.224 raeburn 337: 'selfcreation' =>
338: { text => 'Users self-creating accounts',
339: help => 'Domain_Configuration_Self_Creation',
340: header => [{col1 => 'Self-creation with institutional username',
341: col2 => 'Enabled?'},
342: {col1 => 'Institutional user type (login/SSO self-creation)',
343: col2 => 'Information user can enter'},
344: {col1 => 'Self-creation with e-mail as username',
345: col2 => 'Settings'}],
1.230 raeburn 346: print => \&print_selfcreation,
347: modify => \&modify_selfcreation,
1.224 raeburn 348: },
1.69 raeburn 349: 'usermodification' =>
1.33 raeburn 350: { text => 'User modification',
1.67 raeburn 351: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 352: header => [{col1 => 'Target user has role',
1.227 bisitz 353: col2 => 'User information updatable in author context'},
1.33 raeburn 354: {col1 => 'Target user has role',
1.227 bisitz 355: col2 => 'User information updatable in course context'}],
1.230 raeburn 356: print => \&print_usermodification,
357: modify => \&modify_usermodification,
1.33 raeburn 358: },
1.69 raeburn 359: 'scantron' =>
1.95 www 360: { text => 'Bubblesheet format file',
1.67 raeburn 361: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 362: header => [ {col1 => 'Item',
363: col2 => '',
364: }],
1.230 raeburn 365: print => \&print_scantron,
366: modify => \&modify_scantron,
1.46 raeburn 367: },
1.86 raeburn 368: 'requestcourses' =>
369: {text => 'Request creation of courses',
370: help => 'Domain_Configuration_Request_Courses',
371: header => [{col1 => 'User affiliation',
1.102 raeburn 372: col2 => 'Availability/Processing of requests',},
373: {col1 => 'Setting',
1.216 raeburn 374: col2 => 'Value'},
375: {col1 => 'Available textbooks',
1.235 raeburn 376: col2 => ''},
1.242 raeburn 377: {col1 => 'Available templates',
378: col2 => ''},
1.235 raeburn 379: {col1 => 'Validation (not official courses)',
380: col2 => 'Value'},],
1.230 raeburn 381: print => \&print_quotas,
382: modify => \&modify_quotas,
1.86 raeburn 383: },
1.163 raeburn 384: 'requestauthor' =>
1.223 bisitz 385: {text => 'Request Authoring Space',
1.163 raeburn 386: help => 'Domain_Configuration_Request_Author',
387: header => [{col1 => 'User affiliation',
388: col2 => 'Availability/Processing of requests',},
389: {col1 => 'Setting',
390: col2 => 'Value'}],
1.230 raeburn 391: print => \&print_quotas,
392: modify => \&modify_quotas,
1.163 raeburn 393: },
1.69 raeburn 394: 'coursecategories' =>
1.120 raeburn 395: { text => 'Cataloging of courses/communities',
1.67 raeburn 396: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 397: header => [{col1 => 'Catalog type/availability',
398: col2 => '',},
399: {col1 => 'Category settings for standard catalog',
1.57 raeburn 400: col2 => '',},
401: {col1 => 'Categories',
402: col2 => '',
403: }],
1.230 raeburn 404: print => \&print_coursecategories,
405: modify => \&modify_coursecategories,
1.69 raeburn 406: },
407: 'serverstatuses' =>
1.77 raeburn 408: {text => 'Access to server status pages',
1.69 raeburn 409: help => 'Domain_Configuration_Server_Status',
410: header => [{col1 => 'Status Page',
411: col2 => 'Other named users',
412: col3 => 'Specific IPs',
413: }],
1.230 raeburn 414: print => \&print_serverstatuses,
415: modify => \&modify_serverstatuses,
1.69 raeburn 416: },
1.118 jms 417: 'helpsettings' =>
418: {text => 'Help page settings',
419: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 420: header => [{col1 => 'Help Settings (logged-in users)',
421: col2 => 'Value'}],
1.230 raeburn 422: print => \&print_helpsettings,
423: modify => \&modify_helpsettings,
1.118 jms 424: },
1.121 raeburn 425: 'coursedefaults' =>
426: {text => 'Course/Community defaults',
427: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 428: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
429: col2 => 'Value',},
430: {col1 => 'Defaults which can be overridden for each course by a DC',
431: col2 => 'Value',},],
1.230 raeburn 432: print => \&print_coursedefaults,
433: modify => \&modify_coursedefaults,
1.121 raeburn 434: },
1.231 raeburn 435: 'selfenrollment' =>
436: {text => 'Self-enrollment in Course/Community',
437: help => 'Domain_Configuration_Selfenrollment',
438: header => [{col1 => 'Configuration Rights',
439: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
440: {col1 => 'Defaults',
441: col2 => 'Value'},
442: {col1 => 'Self-enrollment validation (optional)',
443: col2 => 'Value'},],
444: print => \&print_selfenrollment,
445: modify => \&modify_selfenrollment,
446: },
1.120 raeburn 447: 'privacy' =>
448: {text => 'User Privacy',
449: help => 'Domain_Configuration_User_Privacy',
450: header => [{col1 => 'Setting',
451: col2 => 'Value',}],
1.230 raeburn 452: print => \&print_privacy,
453: modify => \&modify_privacy,
1.120 raeburn 454: },
1.141 raeburn 455: 'usersessions' =>
1.145 raeburn 456: {text => 'User session hosting/offloading',
1.137 raeburn 457: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 458: header => [{col1 => 'Domain server',
459: col2 => 'Servers to offload sessions to when busy'},
460: {col1 => 'Hosting of users from other domains',
1.137 raeburn 461: col2 => 'Rules'},
462: {col1 => "Hosting domain's own users elsewhere",
463: col2 => 'Rules'}],
1.230 raeburn 464: print => \&print_usersessions,
465: modify => \&modify_usersessions,
1.137 raeburn 466: },
1.150 raeburn 467: 'loadbalancing' =>
1.185 raeburn 468: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 469: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 470: header => [{col1 => 'Balancers',
1.150 raeburn 471: col2 => 'Default destinations',
1.183 bisitz 472: col3 => 'User affiliation',
1.150 raeburn 473: col4 => 'Overrides'},
474: ],
1.230 raeburn 475: print => \&print_loadbalancing,
476: modify => \&modify_loadbalancing,
1.150 raeburn 477: },
1.267 raeburn 478: 'ltitools' =>
479: {text => 'External Tools (LTI)',
480: help => 'Domain_configuration_LTI_Tools',
481: header => [{col1 => 'Setting',
482: col2 => 'Value',}],
483: print => \&print_ltitools,
484: modify => \&modify_ltitools,
485: },
1.275 raeburn 486: 'ssl' =>
487: {text => 'LON-CAPA Network (SSL)',
488: help => 'Domain_Configuration_Network_SSL',
489: header => [{col1 => 'Server',
490: col2 => 'Certificate Status'},
491: {col1 => 'Connections to other servers',
492: col2 => 'Rules'},
493: {col1 => "Replicating domain's published content",
494: col2 => 'Rules'}],
495: print => \&print_ssl,
496: modify => \&modify_ssl,
497: },
1.3 raeburn 498: );
1.110 raeburn 499: if (keys(%servers) > 1) {
500: $prefs{'login'} = { text => 'Log-in page options',
501: help => 'Domain_Configuration_Login_Page',
502: header => [{col1 => 'Log-in Service',
503: col2 => 'Server Setting',},
504: {col1 => 'Log-in Page Items',
1.168 raeburn 505: col2 => ''},
506: {col1 => 'Log-in Help',
1.256 raeburn 507: col2 => 'Value'},
508: {col1 => 'Custom HTML in document head',
1.168 raeburn 509: col2 => 'Value'}],
1.230 raeburn 510: print => \&print_login,
511: modify => \&modify_login,
1.110 raeburn 512: };
513: }
1.174 foxr 514:
1.6 raeburn 515: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 516: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 517: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 518: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 519: text=>"Settings to display/modify"});
1.9 raeburn 520: my $confname = $dom.'-domainconfig';
1.174 foxr 521:
1.3 raeburn 522: if ($phase eq 'process') {
1.212 raeburn 523: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
524: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 525: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 526: $r->rflush();
1.212 raeburn 527: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 528: }
1.30 raeburn 529: } elsif ($phase eq 'display') {
1.192 raeburn 530: my $js = &recaptcha_js().
1.236 raeburn 531: &toggle_display_js();
1.171 raeburn 532: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 533: my ($othertitle,$usertypes,$types) =
534: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 535: $js .= &lonbalance_targets_js($dom,$types,\%servers,
536: $domconfig{'loadbalancing'}).
1.170 raeburn 537: &new_spares_js().
538: &common_domprefs_js().
539: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 540: }
1.216 raeburn 541: if (grep(/^requestcourses$/,@actions)) {
542: my $javascript_validations;
543: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
544: $js .= <<END;
545: <script type="text/javascript">
546: $javascript_validations
547: </script>
548: $coursebrowserjs
549: END
550: }
1.150 raeburn 551: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 552: } else {
1.180 raeburn 553: # check if domconfig user exists for the domain.
554: my $servadm = $r->dir_config('lonAdmEMail');
555: my ($configuserok,$author_ok,$switchserver) =
556: &config_check($dom,$confname,$servadm);
557: unless ($configuserok eq 'ok') {
1.181 raeburn 558: &Apache::lonconfigsettings::print_header($r,$phase,$context);
559: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 560: $confname).
1.181 raeburn 561: '<br />'
562: );
1.180 raeburn 563: if ($switchserver) {
1.181 raeburn 564: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
565: '<br />'.
566: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
567: '<br />'.
568: &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).
569: '<br />'.
570: &mt('To do that now, use the following link: [_1]',$switchserver)
571: );
572: } else {
573: $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.').
574: '<br />'.
575: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
576: );
1.180 raeburn 577: }
578: $r->print(&Apache::loncommon::end_page());
579: return OK;
580: }
1.21 raeburn 581: if (keys(%domconfig) == 0) {
582: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 583: my @ids=&Apache::lonnet::current_machine_ids();
584: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 585: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 586: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 587: my $custom_img_count = 0;
588: foreach my $img (@loginimages) {
589: if ($designhash{$dom.'.login.'.$img} ne '') {
590: $custom_img_count ++;
591: }
592: }
593: foreach my $role (@roles) {
594: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
595: $custom_img_count ++;
596: }
597: }
598: if ($custom_img_count > 0) {
1.94 raeburn 599: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 600: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 601: $r->print(
602: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
603: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
604: &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 />'.
605: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
606: if ($switch_server) {
1.30 raeburn 607: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 608: }
1.91 raeburn 609: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 610: return OK;
611: }
612: }
613: }
1.91 raeburn 614: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 615: }
616: return OK;
617: }
618:
619: sub process_changes {
1.205 raeburn 620: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 621: my %domconfig;
622: if (ref($values) eq 'HASH') {
623: %domconfig = %{$values};
624: }
1.3 raeburn 625: my $output;
626: if ($action eq 'login') {
1.205 raeburn 627: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 628: } elsif ($action eq 'rolecolors') {
1.9 raeburn 629: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 630: $lastactref,%domconfig);
1.3 raeburn 631: } elsif ($action eq 'quotas') {
1.216 raeburn 632: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 633: } elsif ($action eq 'autoenroll') {
1.205 raeburn 634: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 635: } elsif ($action eq 'autoupdate') {
636: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 637: } elsif ($action eq 'autocreate') {
638: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 639: } elsif ($action eq 'directorysrch') {
640: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 641: } elsif ($action eq 'usercreation') {
1.28 raeburn 642: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 643: } elsif ($action eq 'selfcreation') {
644: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 645: } elsif ($action eq 'usermodification') {
646: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 647: } elsif ($action eq 'contacts') {
1.205 raeburn 648: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 649: } elsif ($action eq 'defaults') {
1.212 raeburn 650: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 651: } elsif ($action eq 'scantron') {
1.205 raeburn 652: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 653: } elsif ($action eq 'coursecategories') {
1.239 raeburn 654: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 655: } elsif ($action eq 'serverstatuses') {
656: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 657: } elsif ($action eq 'requestcourses') {
1.216 raeburn 658: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 659: } elsif ($action eq 'requestauthor') {
1.216 raeburn 660: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 661: } elsif ($action eq 'helpsettings') {
1.122 jms 662: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 663: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 664: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 665: } elsif ($action eq 'selfenrollment') {
666: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 667: } elsif ($action eq 'usersessions') {
1.212 raeburn 668: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 669: } elsif ($action eq 'loadbalancing') {
670: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 671: } elsif ($action eq 'ltitools') {
672: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 673: } elsif ($action eq 'ssl') {
674: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.3 raeburn 675: }
676: return $output;
677: }
678:
679: sub print_config_box {
1.9 raeburn 680: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 681: my $rowtotal = 0;
1.49 raeburn 682: my $output;
683: if ($action eq 'coursecategories') {
684: $output = &coursecategories_javascript($settings);
1.236 raeburn 685: } elsif ($action eq 'defaults') {
686: $output = &defaults_javascript($settings);
1.91 raeburn 687: }
1.236 raeburn 688: $output .=
1.30 raeburn 689: '<table class="LC_nested_outer">
1.3 raeburn 690: <tr>
1.66 raeburn 691: <th align="left" valign="middle"><span class="LC_nobreak">'.
692: &mt($item->{text}).' '.
693: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
694: '</tr>';
1.30 raeburn 695: $rowtotal ++;
1.110 raeburn 696: my $numheaders = 1;
697: if (ref($item->{'header'}) eq 'ARRAY') {
698: $numheaders = scalar(@{$item->{'header'}});
699: }
700: if ($numheaders > 1) {
1.64 raeburn 701: my $colspan = '';
1.145 raeburn 702: my $rightcolspan = '';
1.238 raeburn 703: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.256 raeburn 704: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 705: $colspan = ' colspan="2"';
706: }
1.145 raeburn 707: if ($action eq 'usersessions') {
708: $rightcolspan = ' colspan="3"';
709: }
1.30 raeburn 710: $output .= '
1.3 raeburn 711: <tr>
712: <td>
713: <table class="LC_nested">
714: <tr class="LC_info_row">
1.59 bisitz 715: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 716: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 717: </tr>';
1.69 raeburn 718: $rowtotal ++;
1.230 raeburn 719: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 720: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.275 raeburn 721: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl')) {
1.230 raeburn 722: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 723: } elsif ($action eq 'coursecategories') {
1.230 raeburn 724: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 725: } elsif ($action eq 'login') {
1.256 raeburn 726: if ($numheaders == 4) {
1.168 raeburn 727: $colspan = ' colspan="2"';
728: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
729: } else {
730: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
731: }
1.230 raeburn 732: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 733: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 734: } elsif ($action eq 'rolecolors') {
1.30 raeburn 735: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 736: }
1.30 raeburn 737: $output .= '
1.6 raeburn 738: </table>
739: </td>
740: </tr>
741: <tr>
742: <td>
743: <table class="LC_nested">
744: <tr class="LC_info_row">
1.230 raeburn 745: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 746: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 747: </tr>';
748: $rowtotal ++;
1.230 raeburn 749: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
750: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 751: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
752: ($action eq 'ssl')) {
1.238 raeburn 753: if ($action eq 'coursecategories') {
754: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
755: $colspan = ' colspan="2"';
756: } else {
757: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
758: }
759: $output .= '
1.63 raeburn 760: </table>
761: </td>
762: </tr>
763: <tr>
764: <td>
765: <table class="LC_nested">
766: <tr class="LC_info_row">
767: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 768: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 769: </tr>'."\n";
770: if ($action eq 'coursecategories') {
771: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
772: } else {
773: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
774: }
1.63 raeburn 775: $rowtotal ++;
1.236 raeburn 776: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
777: ($action eq 'defaults')) {
1.230 raeburn 778: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 779: } elsif ($action eq 'login') {
1.256 raeburn 780: if ($numheaders == 4) {
1.168 raeburn 781: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
782: </table>
783: </td>
784: </tr>
785: <tr>
786: <td>
787: <table class="LC_nested">
788: <tr class="LC_info_row">
789: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 790: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 791: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
792: $rowtotal ++;
793: } else {
794: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
795: }
1.256 raeburn 796: $output .= '
797: </table>
798: </td>
799: </tr>
800: <tr>
801: <td>
802: <table class="LC_nested">
803: <tr class="LC_info_row">';
804: if ($numheaders == 4) {
805: $output .= '
806: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
807: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
808: </tr>';
809: } else {
810: $output .= '
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
812: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
813: </tr>';
814: }
815: $rowtotal ++;
816: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 817: } elsif ($action eq 'requestcourses') {
1.247 raeburn 818: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
819: $rowtotal ++;
820: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 821: </table>
822: </td>
823: </tr>
824: <tr>
825: <td>
826: <table class="LC_nested">
827: <tr class="LC_info_row">
828: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
829: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 830: &textbookcourses_javascript($settings).
831: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
832: </table>
833: </td>
834: </tr>
835: <tr>
836: <td>
837: <table class="LC_nested">
838: <tr class="LC_info_row">
839: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
840: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
841: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 842: </table>
843: </td>
844: </tr>
845: <tr>
846: <td>
847: <table class="LC_nested">
848: <tr class="LC_info_row">
1.242 raeburn 849: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
850: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 851: </tr>'.
852: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 853: } elsif ($action eq 'requestauthor') {
854: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 855: $rowtotal ++;
1.122 jms 856: } elsif ($action eq 'rolecolors') {
1.30 raeburn 857: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 858: </table>
859: </td>
860: </tr>
861: <tr>
862: <td>
863: <table class="LC_nested">
864: <tr class="LC_info_row">
1.69 raeburn 865: <td class="LC_left_item"'.$colspan.' valign="top">'.
866: &mt($item->{'header'}->[2]->{'col1'}).'</td>
867: <td class="LC_right_item" valign="top">'.
868: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 869: </tr>'.
1.30 raeburn 870: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 871: </table>
872: </td>
873: </tr>
874: <tr>
875: <td>
876: <table class="LC_nested">
877: <tr class="LC_info_row">
1.59 bisitz 878: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
879: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 880: </tr>'.
1.30 raeburn 881: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
882: $rowtotal += 2;
1.6 raeburn 883: }
1.3 raeburn 884: } else {
1.30 raeburn 885: $output .= '
1.3 raeburn 886: <tr>
887: <td>
888: <table class="LC_nested">
1.30 raeburn 889: <tr class="LC_info_row">';
1.24 raeburn 890: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 891: $output .= '
1.59 bisitz 892: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 893: } elsif ($action eq 'serverstatuses') {
894: $output .= '
895: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
896: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
897:
1.6 raeburn 898: } else {
1.30 raeburn 899: $output .= '
1.69 raeburn 900: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
901: }
1.72 raeburn 902: if (defined($item->{'header'}->[0]->{'col3'})) {
903: $output .= '<td class="LC_left_item" valign="top">'.
904: &mt($item->{'header'}->[0]->{'col2'});
905: if ($action eq 'serverstatuses') {
906: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
907: }
1.69 raeburn 908: } else {
909: $output .= '<td class="LC_right_item" valign="top">'.
910: &mt($item->{'header'}->[0]->{'col2'});
911: }
912: $output .= '</td>';
913: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 914: if (defined($item->{'header'}->[0]->{'col4'})) {
915: $output .= '<td class="LC_left_item" valign="top">'.
916: &mt($item->{'header'}->[0]->{'col3'});
917: } else {
918: $output .= '<td class="LC_right_item" valign="top">'.
919: &mt($item->{'header'}->[0]->{'col3'});
920: }
1.69 raeburn 921: if ($action eq 'serverstatuses') {
922: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
923: }
924: $output .= '</td>';
1.6 raeburn 925: }
1.150 raeburn 926: if ($item->{'header'}->[0]->{'col4'}) {
927: $output .= '<td class="LC_right_item" valign="top">'.
928: &mt($item->{'header'}->[0]->{'col4'});
929: }
1.69 raeburn 930: $output .= '</tr>';
1.48 raeburn 931: $rowtotal ++;
1.168 raeburn 932: if ($action eq 'quotas') {
1.86 raeburn 933: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 934: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.267 raeburn 935: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
936: ($action eq 'ltitools')) {
1.230 raeburn 937: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 938: } elsif ($action eq 'scantron') {
939: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 940: } elsif ($action eq 'helpsettings') {
1.168 raeburn 941: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 942: }
1.3 raeburn 943: }
1.30 raeburn 944: $output .= '
1.3 raeburn 945: </table>
946: </td>
947: </tr>
1.30 raeburn 948: </table><br />';
949: return ($output,$rowtotal);
1.1 raeburn 950: }
951:
1.3 raeburn 952: sub print_login {
1.168 raeburn 953: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 954: my ($css_class,$datatable);
1.6 raeburn 955: my %choices = &login_choices();
1.110 raeburn 956:
1.168 raeburn 957: if ($caller eq 'service') {
1.149 raeburn 958: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 959: my $choice = $choices{'disallowlogin'};
960: $css_class = ' class="LC_odd_row"';
1.128 raeburn 961: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 962: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 963: '<th>'.$choices{'server'}.'</th>'.
964: '<th>'.$choices{'serverpath'}.'</th>'.
965: '<th>'.$choices{'custompath'}.'</th>'.
966: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 967: my %disallowed;
968: if (ref($settings) eq 'HASH') {
969: if (ref($settings->{'loginvia'}) eq 'HASH') {
970: %disallowed = %{$settings->{'loginvia'}};
971: }
972: }
973: foreach my $lonhost (sort(keys(%servers))) {
974: my $direct = 'selected="selected"';
1.128 raeburn 975: if (ref($disallowed{$lonhost}) eq 'HASH') {
976: if ($disallowed{$lonhost}{'server'} ne '') {
977: $direct = '';
978: }
1.110 raeburn 979: }
1.115 raeburn 980: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 981: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 982: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
983: '</option>';
1.184 raeburn 984: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 985: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 986: my $selected = '';
1.128 raeburn 987: if (ref($disallowed{$lonhost}) eq 'HASH') {
988: if ($hostid eq $disallowed{$lonhost}{'server'}) {
989: $selected = 'selected="selected"';
990: }
1.110 raeburn 991: }
992: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
993: $servers{$hostid}.'</option>';
994: }
1.128 raeburn 995: $datatable .= '</select></td>'.
996: '<td><select name="'.$lonhost.'_serverpath">';
997: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
998: my $pathname = $path;
999: if ($path eq 'custom') {
1000: $pathname = &mt('Custom Path').' ->';
1001: }
1002: my $selected = '';
1003: if (ref($disallowed{$lonhost}) eq 'HASH') {
1004: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1005: $selected = 'selected="selected"';
1006: }
1007: } elsif ($path eq '') {
1008: $selected = 'selected="selected"';
1009: }
1010: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1011: }
1012: $datatable .= '</select></td>';
1013: my ($custom,$exempt);
1014: if (ref($disallowed{$lonhost}) eq 'HASH') {
1015: $custom = $disallowed{$lonhost}{'custompath'};
1016: $exempt = $disallowed{$lonhost}{'exempt'};
1017: }
1018: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1019: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1020: '</tr>';
1.110 raeburn 1021: }
1022: $datatable .= '</table></td></tr>';
1023: return $datatable;
1.168 raeburn 1024: } elsif ($caller eq 'page') {
1025: my %defaultchecked = (
1026: 'coursecatalog' => 'on',
1.188 raeburn 1027: 'helpdesk' => 'on',
1.168 raeburn 1028: 'adminmail' => 'off',
1029: 'newuser' => 'off',
1030: );
1.188 raeburn 1031: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1032: my (%checkedon,%checkedoff);
1.42 raeburn 1033: foreach my $item (@toggles) {
1.168 raeburn 1034: if ($defaultchecked{$item} eq 'on') {
1035: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1036: $checkedoff{$item} = ' ';
1.168 raeburn 1037: } elsif ($defaultchecked{$item} eq 'off') {
1038: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1039: $checkedon{$item} = ' ';
1040: }
1.1 raeburn 1041: }
1.168 raeburn 1042: my @images = ('img','logo','domlogo','login');
1043: my @logintext = ('textcol','bgcol');
1044: my @bgs = ('pgbg','mainbg','sidebg');
1045: my @links = ('link','alink','vlink');
1046: my %designhash = &Apache::loncommon::get_domainconf($dom);
1047: my %defaultdesign = %Apache::loncommon::defaultdesign;
1048: my (%is_custom,%designs);
1049: my %defaults = (
1050: font => $defaultdesign{'login.font'},
1051: );
1.6 raeburn 1052: foreach my $item (@images) {
1.168 raeburn 1053: $defaults{$item} = $defaultdesign{'login.'.$item};
1054: $defaults{'showlogo'}{$item} = 1;
1055: }
1056: foreach my $item (@bgs) {
1057: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1058: }
1.41 raeburn 1059: foreach my $item (@logintext) {
1.168 raeburn 1060: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1061: }
1.168 raeburn 1062: foreach my $item (@links) {
1063: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1064: }
1.168 raeburn 1065: if (ref($settings) eq 'HASH') {
1066: foreach my $item (@toggles) {
1067: if ($settings->{$item} eq '1') {
1068: $checkedon{$item} = ' checked="checked" ';
1069: $checkedoff{$item} = ' ';
1070: } elsif ($settings->{$item} eq '0') {
1071: $checkedoff{$item} = ' checked="checked" ';
1072: $checkedon{$item} = ' ';
1073: }
1074: }
1075: foreach my $item (@images) {
1076: if (defined($settings->{$item})) {
1077: $designs{$item} = $settings->{$item};
1078: $is_custom{$item} = 1;
1079: }
1080: if (defined($settings->{'showlogo'}{$item})) {
1081: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1082: }
1083: }
1084: foreach my $item (@logintext) {
1085: if ($settings->{$item} ne '') {
1086: $designs{'logintext'}{$item} = $settings->{$item};
1087: $is_custom{$item} = 1;
1088: }
1089: }
1090: if ($settings->{'font'} ne '') {
1091: $designs{'font'} = $settings->{'font'};
1092: $is_custom{'font'} = 1;
1093: }
1094: foreach my $item (@bgs) {
1095: if ($settings->{$item} ne '') {
1096: $designs{'bgs'}{$item} = $settings->{$item};
1097: $is_custom{$item} = 1;
1098: }
1099: }
1100: foreach my $item (@links) {
1101: if ($settings->{$item} ne '') {
1102: $designs{'links'}{$item} = $settings->{$item};
1103: $is_custom{$item} = 1;
1104: }
1105: }
1106: } else {
1107: if ($designhash{$dom.'.login.font'} ne '') {
1108: $designs{'font'} = $designhash{$dom.'.login.font'};
1109: $is_custom{'font'} = 1;
1110: }
1111: foreach my $item (@images) {
1112: if ($designhash{$dom.'.login.'.$item} ne '') {
1113: $designs{$item} = $designhash{$dom.'.login.'.$item};
1114: $is_custom{$item} = 1;
1115: }
1116: }
1117: foreach my $item (@bgs) {
1118: if ($designhash{$dom.'.login.'.$item} ne '') {
1119: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1120: $is_custom{$item} = 1;
1121: }
1.6 raeburn 1122: }
1.168 raeburn 1123: foreach my $item (@links) {
1124: if ($designhash{$dom.'.login.'.$item} ne '') {
1125: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1126: $is_custom{$item} = 1;
1127: }
1.6 raeburn 1128: }
1129: }
1.168 raeburn 1130: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1131: logo => 'Institution Logo',
1132: domlogo => 'Domain Logo',
1133: login => 'Login box');
1134: my $itemcount = 1;
1135: foreach my $item (@toggles) {
1136: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1137: $datatable .=
1138: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1139: '</td><td>'.
1140: '<span class="LC_nobreak"><label><input type="radio" name="'.
1141: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1142: '</label> <label><input type="radio" name="'.$item.'"'.
1143: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1144: '</tr>';
1145: $itemcount ++;
1.6 raeburn 1146: }
1.168 raeburn 1147: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1148: $datatable .= '</tr></table></td></tr>';
1149: } elsif ($caller eq 'help') {
1150: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1151: my $switchserver = &check_switchserver($dom,$confname);
1152: my $itemcount = 1;
1153: $defaulturl = '/adm/loginproblems.html';
1154: $defaulttype = 'default';
1155: %lt = &Apache::lonlocal::texthash (
1156: del => 'Delete?',
1157: rep => 'Replace:',
1158: upl => 'Upload:',
1159: default => 'Default',
1160: custom => 'Custom',
1161: );
1162: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1163: my @currlangs;
1164: if (ref($settings) eq 'HASH') {
1165: if (ref($settings->{'helpurl'}) eq 'HASH') {
1166: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1167: next if ($settings->{'helpurl'}{$key} eq '');
1168: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1169: $type{$key} = 'custom';
1170: unless ($key eq 'nolang') {
1171: push(@currlangs,$key);
1172: }
1173: }
1174: } elsif ($settings->{'helpurl'} ne '') {
1175: $type{'nolang'} = 'custom';
1176: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1177: }
1178: }
1.168 raeburn 1179: foreach my $lang ('nolang',sort(@currlangs)) {
1180: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1181: $datatable .= '<tr'.$css_class.'>';
1182: if ($url{$lang} eq '') {
1183: $url{$lang} = $defaulturl;
1184: }
1185: if ($type{$lang} eq '') {
1186: $type{$lang} = $defaulttype;
1187: }
1188: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1189: if ($lang eq 'nolang') {
1190: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1191: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1192: } else {
1193: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1194: $langchoices{$lang},
1195: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1196: }
1197: $datatable .= '</span></td>'."\n".
1198: '<td class="LC_left_item">';
1199: if ($type{$lang} eq 'custom') {
1200: $datatable .= '<span class="LC_nobreak"><label>'.
1201: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1202: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1203: } else {
1204: $datatable .= $lt{'upl'};
1205: }
1206: $datatable .='<br />';
1207: if ($switchserver) {
1208: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1209: } else {
1210: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1211: }
1.168 raeburn 1212: $datatable .= '</td></tr>';
1213: $itemcount ++;
1.6 raeburn 1214: }
1.168 raeburn 1215: my @addlangs;
1216: foreach my $lang (sort(keys(%langchoices))) {
1217: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1218: push(@addlangs,$lang);
1219: }
1220: if (@addlangs > 0) {
1221: my %toadd;
1222: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1223: $toadd{''} = &mt('Select');
1224: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1225: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1226: &mt('Add log-in help page for a specific language:').' '.
1227: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1228: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1229: if ($switchserver) {
1230: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1231: } else {
1232: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1233: }
1.168 raeburn 1234: $datatable .= '</td></tr>';
1.169 raeburn 1235: $itemcount ++;
1.6 raeburn 1236: }
1.169 raeburn 1237: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1238: } elsif ($caller eq 'headtag') {
1239: my %domservers = &Apache::lonnet::get_servers($dom);
1240: my $choice = $choices{'headtag'};
1241: $css_class = ' class="LC_odd_row"';
1242: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1243: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1244: '<th>'.$choices{'current'}.'</th>'.
1245: '<th>'.$choices{'action'}.'</th>'.
1246: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1247: my (%currurls,%currexempt);
1248: if (ref($settings) eq 'HASH') {
1249: if (ref($settings->{'headtag'}) eq 'HASH') {
1250: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1251: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1252: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1253: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1254: }
1255: }
1256: }
1257: }
1258: my %lt = &Apache::lonlocal::texthash(
1259: del => 'Delete?',
1260: rep => 'Replace:',
1261: upl => 'Upload:',
1262: curr => 'View contents',
1263: none => 'None',
1264: );
1265: my $switchserver = &check_switchserver($dom,$confname);
1266: foreach my $lonhost (sort(keys(%domservers))) {
1267: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1268: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1269: if ($currurls{$lonhost}) {
1270: $datatable .= '<td class="LC_right_item"><a href="'.
1271: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1272: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1273: '">'.$lt{'curr'}.'</a></td>'.
1274: '<td><span class="LC_nobreak"><label>'.
1275: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1276: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1277: } else {
1278: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1279: }
1280: $datatable .='<br />';
1281: if ($switchserver) {
1282: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1283: } else {
1284: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1285: }
1286: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1287: }
1288: $datatable .= '</table></td></tr>';
1.1 raeburn 1289: }
1.6 raeburn 1290: return $datatable;
1291: }
1292:
1293: sub login_choices {
1294: my %choices =
1295: &Apache::lonlocal::texthash (
1.116 bisitz 1296: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1297: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1298: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1299: disallowlogin => "Login page requests redirected",
1300: hostid => "Server",
1.128 raeburn 1301: server => "Redirect to:",
1302: serverpath => "Path",
1303: custompath => "Custom",
1304: exempt => "Exempt IP(s)",
1.110 raeburn 1305: directlogin => "No redirect",
1306: newuser => "Link to create a user account",
1307: img => "Header",
1308: logo => "Main Logo",
1309: domlogo => "Domain Logo",
1310: login => "Log-in Header",
1311: textcol => "Text color",
1312: bgcol => "Box color",
1313: bgs => "Background colors",
1314: links => "Link colors",
1315: font => "Font color",
1316: pgbg => "Header",
1317: mainbg => "Page",
1318: sidebg => "Login box",
1319: link => "Link",
1320: alink => "Active link",
1321: vlink => "Visited link",
1.256 raeburn 1322: headtag => "Custom markup",
1323: action => "Action",
1324: current => "Current",
1.6 raeburn 1325: );
1326: return %choices;
1327: }
1328:
1329: sub print_rolecolors {
1.30 raeburn 1330: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1331: my %choices = &color_font_choices();
1332: my @bgs = ('pgbg','tabbg','sidebg');
1333: my @links = ('link','alink','vlink');
1334: my @images = ('img');
1335: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1336: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1337: my %defaultdesign = %Apache::loncommon::defaultdesign;
1338: my (%is_custom,%designs);
1.200 raeburn 1339: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1340: if (ref($settings) eq 'HASH') {
1341: if (ref($settings->{$role}) eq 'HASH') {
1342: if ($settings->{$role}->{'img'} ne '') {
1343: $designs{'img'} = $settings->{$role}->{'img'};
1344: $is_custom{'img'} = 1;
1345: }
1346: if ($settings->{$role}->{'font'} ne '') {
1347: $designs{'font'} = $settings->{$role}->{'font'};
1348: $is_custom{'font'} = 1;
1349: }
1.97 tempelho 1350: if ($settings->{$role}->{'fontmenu'} ne '') {
1351: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1352: $is_custom{'fontmenu'} = 1;
1353: }
1.6 raeburn 1354: foreach my $item (@bgs) {
1355: if ($settings->{$role}->{$item} ne '') {
1356: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1357: $is_custom{$item} = 1;
1358: }
1359: }
1360: foreach my $item (@links) {
1361: if ($settings->{$role}->{$item} ne '') {
1362: $designs{'links'}{$item} = $settings->{$role}->{$item};
1363: $is_custom{$item} = 1;
1364: }
1365: }
1366: }
1367: } else {
1368: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1369: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1370: $is_custom{'img'} = 1;
1371: }
1.97 tempelho 1372: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1373: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1374: $is_custom{'fontmenu'} = 1;
1375: }
1.6 raeburn 1376: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1377: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1378: $is_custom{'font'} = 1;
1379: }
1380: foreach my $item (@bgs) {
1381: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1382: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1383: $is_custom{$item} = 1;
1384:
1385: }
1386: }
1387: foreach my $item (@links) {
1388: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1389: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1390: $is_custom{$item} = 1;
1391: }
1392: }
1393: }
1394: my $itemcount = 1;
1.30 raeburn 1395: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1396: $datatable .= '</tr></table></td></tr>';
1397: return $datatable;
1398: }
1399:
1.200 raeburn 1400: sub role_defaults {
1401: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1402: my %defaults;
1403: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1404: return %defaults;
1405: }
1406: my %defaultdesign = %Apache::loncommon::defaultdesign;
1407: if ($role eq 'login') {
1408: %defaults = (
1409: font => $defaultdesign{$role.'.font'},
1410: );
1411: if (ref($logintext) eq 'ARRAY') {
1412: foreach my $item (@{$logintext}) {
1413: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1414: }
1415: }
1416: foreach my $item (@{$images}) {
1417: $defaults{'showlogo'}{$item} = 1;
1418: }
1419: } else {
1420: %defaults = (
1421: img => $defaultdesign{$role.'.img'},
1422: font => $defaultdesign{$role.'.font'},
1423: fontmenu => $defaultdesign{$role.'.fontmenu'},
1424: );
1425: }
1426: foreach my $item (@{$bgs}) {
1427: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1428: }
1429: foreach my $item (@{$links}) {
1430: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1431: }
1432: foreach my $item (@{$images}) {
1433: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1434: }
1435: return %defaults;
1436: }
1437:
1.6 raeburn 1438: sub display_color_options {
1.9 raeburn 1439: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1440: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1441: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1442: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1443: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1444: '<td>'.$choices->{'font'}.'</td>';
1445: if (!$is_custom->{'font'}) {
1.30 raeburn 1446: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1447: } else {
1448: $datatable .= '<td> </td>';
1449: }
1.174 foxr 1450: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1451:
1.8 raeburn 1452: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1453: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1454: ' value="'.$current_color.'" /> '.
1.174 foxr 1455: ' </td></tr>';
1.107 raeburn 1456: unless ($role eq 'login') {
1457: $datatable .= '<tr'.$css_class.'>'.
1458: '<td>'.$choices->{'fontmenu'}.'</td>';
1459: if (!$is_custom->{'fontmenu'}) {
1460: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1461: } else {
1462: $datatable .= '<td> </td>';
1463: }
1.202 raeburn 1464: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1465: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1466: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1467: '<input class="colorchooser" type="text" size="10" name="'
1468: .$role.'_fontmenu"'.
1469: ' value="'.$current_color.'" /> '.
1470: ' </td></tr>';
1.97 tempelho 1471: }
1.9 raeburn 1472: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1473: foreach my $img (@{$images}) {
1.18 albertel 1474: $itemcount ++;
1.6 raeburn 1475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1476: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1477: '<td>'.$choices->{$img};
1.41 raeburn 1478: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1479: if ($role eq 'login') {
1480: if ($img eq 'login') {
1481: $login_hdr_pick =
1.135 bisitz 1482: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1483: $logincolors =
1484: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1485: $designs,$defaults);
1.70 raeburn 1486: } elsif ($img ne 'domlogo') {
1487: $datatable.= &logo_display_options($img,$defaults,$designs);
1488: }
1489: }
1490: $datatable .= '</td>';
1.6 raeburn 1491: if ($designs->{$img} ne '') {
1492: $imgfile = $designs->{$img};
1.18 albertel 1493: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1494: } else {
1495: $imgfile = $defaults->{$img};
1496: }
1497: if ($imgfile) {
1.9 raeburn 1498: my ($showfile,$fullsize);
1499: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1500: my $urldir = $1;
1501: my $filename = $2;
1502: my @info = &Apache::lonnet::stat_file($designs->{$img});
1503: if (@info) {
1504: my $thumbfile = 'tn-'.$filename;
1505: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1506: if (@thumb) {
1507: $showfile = $urldir.'/'.$thumbfile;
1508: } else {
1509: $showfile = $imgfile;
1510: }
1511: } else {
1512: $showfile = '';
1513: }
1514: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1515: $showfile = $imgfile;
1.6 raeburn 1516: my $imgdir = $1;
1517: my $filename = $2;
1.159 raeburn 1518: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1519: $showfile = "/$imgdir/tn-".$filename;
1520: } else {
1.159 raeburn 1521: my $input = $londocroot.$imgfile;
1522: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1523: if (!-e $output) {
1.9 raeburn 1524: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1525: my ($fullwidth,$fullheight) = &check_dimensions($input);
1526: if ($fullwidth ne '' && $fullheight ne '') {
1527: if ($fullwidth > $width && $fullheight > $height) {
1528: my $size = $width.'x'.$height;
1529: system("convert -sample $size $input $output");
1.159 raeburn 1530: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1531: }
1532: }
1.6 raeburn 1533: }
1534: }
1.16 raeburn 1535: }
1.6 raeburn 1536: if ($showfile) {
1.40 raeburn 1537: if ($showfile =~ m{^/(adm|res)/}) {
1538: if ($showfile =~ m{^/res/}) {
1539: my $local_showfile =
1540: &Apache::lonnet::filelocation('',$showfile);
1541: &Apache::lonnet::repcopy($local_showfile);
1542: }
1543: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1544: }
1545: if ($imgfile) {
1546: if ($imgfile =~ m{^/(adm|res)/}) {
1547: if ($imgfile =~ m{^/res/}) {
1548: my $local_imgfile =
1549: &Apache::lonnet::filelocation('',$imgfile);
1550: &Apache::lonnet::repcopy($local_imgfile);
1551: }
1552: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1553: } else {
1554: $fullsize = $imgfile;
1555: }
1556: }
1.41 raeburn 1557: $datatable .= '<td>';
1558: if ($img eq 'login') {
1.135 bisitz 1559: $datatable .= $login_hdr_pick;
1560: }
1.41 raeburn 1561: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1562: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1563: } else {
1.201 raeburn 1564: $datatable .= '<td> </td><td class="LC_left_item">'.
1565: &mt('Upload:').'<br />';
1.6 raeburn 1566: }
1567: } else {
1.201 raeburn 1568: $datatable .= '<td> </td><td class="LC_left_item">'.
1569: &mt('Upload:').'<br />';
1.6 raeburn 1570: }
1.9 raeburn 1571: if ($switchserver) {
1572: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1573: } else {
1.135 bisitz 1574: if ($img ne 'login') { # suppress file selection for Log-in header
1575: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1576: }
1.9 raeburn 1577: }
1578: $datatable .= '</td></tr>';
1.6 raeburn 1579: }
1580: $itemcount ++;
1581: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1582: $datatable .= '<tr'.$css_class.'>'.
1583: '<td>'.$choices->{'bgs'}.'</td>';
1584: my $bgs_def;
1585: foreach my $item (@{$bgs}) {
1586: if (!$is_custom->{$item}) {
1.70 raeburn 1587: $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 1588: }
1589: }
1590: if ($bgs_def) {
1.8 raeburn 1591: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1592: } else {
1593: $datatable .= '<td> </td>';
1594: }
1595: $datatable .= '<td class="LC_right_item">'.
1596: '<table border="0"><tr>';
1.174 foxr 1597:
1.6 raeburn 1598: foreach my $item (@{$bgs}) {
1.201 raeburn 1599: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1600: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1601: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1602: $datatable .= ' ';
1.6 raeburn 1603: }
1.174 foxr 1604: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1605: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1606: }
1607: $datatable .= '</tr></table></td></tr>';
1608: $itemcount ++;
1609: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1610: $datatable .= '<tr'.$css_class.'>'.
1611: '<td>'.$choices->{'links'}.'</td>';
1612: my $links_def;
1613: foreach my $item (@{$links}) {
1614: if (!$is_custom->{$item}) {
1.30 raeburn 1615: $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 1616: }
1617: }
1618: if ($links_def) {
1.8 raeburn 1619: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1620: } else {
1621: $datatable .= '<td> </td>';
1622: }
1623: $datatable .= '<td class="LC_right_item">'.
1624: '<table border="0"><tr>';
1625: foreach my $item (@{$links}) {
1.234 raeburn 1626: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1627: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1628: if ($designs->{'links'}{$item}) {
1.174 foxr 1629: $datatable.=' ';
1.6 raeburn 1630: }
1.174 foxr 1631: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1632: '" /></td>';
1633: }
1.30 raeburn 1634: $$rowtotal += $itemcount;
1.3 raeburn 1635: return $datatable;
1636: }
1637:
1.70 raeburn 1638: sub logo_display_options {
1639: my ($img,$defaults,$designs) = @_;
1640: my $checkedon;
1641: if (ref($defaults) eq 'HASH') {
1642: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1643: if ($defaults->{'showlogo'}{$img}) {
1644: $checkedon = 'checked="checked" ';
1645: }
1646: }
1647: }
1648: if (ref($designs) eq 'HASH') {
1649: if (ref($designs->{'showlogo'}) eq 'HASH') {
1650: if (defined($designs->{'showlogo'}{$img})) {
1651: if ($designs->{'showlogo'}{$img} == 0) {
1652: $checkedon = '';
1653: } elsif ($designs->{'showlogo'}{$img} == 1) {
1654: $checkedon = 'checked="checked" ';
1655: }
1656: }
1657: }
1658: }
1659: return '<br /><label> <input type="checkbox" name="'.
1660: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1661: &mt('show').'</label>'."\n";
1662: }
1663:
1.41 raeburn 1664: sub login_header_options {
1.135 bisitz 1665: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1666: my $output = '';
1.41 raeburn 1667: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1668: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1669: if (!$is_custom->{'textcol'}) {
1670: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1671: ' ';
1672: }
1673: if (!$is_custom->{'bgcol'}) {
1674: $output .= $choices->{'bgcol'}.': '.
1675: '<span id="css_'.$role.'_font" style="background-color: '.
1676: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1677: }
1678: $output .= '<br />';
1679: }
1680: $output .='<br />';
1681: return $output;
1682: }
1683:
1684: sub login_text_colors {
1.201 raeburn 1685: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1686: my $color_menu = '<table border="0"><tr>';
1687: foreach my $item (@{$logintext}) {
1.201 raeburn 1688: $color_menu .= '<td align="center">'.$choices->{$item};
1689: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1690: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1691: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1692: }
1693: $color_menu .= '</tr></table><br />';
1694: return $color_menu;
1695: }
1696:
1697: sub image_changes {
1698: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1699: my $output;
1.135 bisitz 1700: if ($img eq 'login') {
1701: # suppress image for Log-in header
1702: } elsif (!$is_custom) {
1.70 raeburn 1703: if ($img ne 'domlogo') {
1.41 raeburn 1704: $output .= &mt('Default image:').'<br />';
1705: } else {
1706: $output .= &mt('Default in use:').'<br />';
1707: }
1708: }
1.135 bisitz 1709: if ($img eq 'login') { # suppress image for Log-in header
1710: $output .= '<td>'.$logincolors;
1.41 raeburn 1711: } else {
1.135 bisitz 1712: if ($img_import) {
1713: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1714: }
1715: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1716: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1717: if ($is_custom) {
1718: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1719: '<input type="checkbox" name="'.
1720: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1721: '</label> '.&mt('Replace:').'</span><br />';
1722: } else {
1.201 raeburn 1723: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1724: }
1.41 raeburn 1725: }
1726: return $output;
1727: }
1728:
1.3 raeburn 1729: sub print_quotas {
1.86 raeburn 1730: my ($dom,$settings,$rowtotal,$action) = @_;
1731: my $context;
1732: if ($action eq 'quotas') {
1733: $context = 'tools';
1734: } else {
1735: $context = $action;
1736: }
1.197 raeburn 1737: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1738: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1739: my $typecount = 0;
1.101 raeburn 1740: my ($css_class,%titles);
1.86 raeburn 1741: if ($context eq 'requestcourses') {
1.271 raeburn 1742: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1743: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1744: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1745: %titles = &courserequest_titles();
1.163 raeburn 1746: } elsif ($context eq 'requestauthor') {
1747: @usertools = ('author');
1748: @options = ('norequest','approval','automatic');
1.210 raeburn 1749: %titles = &authorrequest_titles();
1.86 raeburn 1750: } else {
1.162 raeburn 1751: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1752: %titles = &tool_titles();
1.86 raeburn 1753: }
1.26 raeburn 1754: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1755: foreach my $type (@{$types}) {
1.197 raeburn 1756: my ($currdefquota,$currauthorquota);
1.163 raeburn 1757: unless (($context eq 'requestcourses') ||
1758: ($context eq 'requestauthor')) {
1.86 raeburn 1759: if (ref($settings) eq 'HASH') {
1760: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1761: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1762: } else {
1763: $currdefquota = $settings->{$type};
1764: }
1.197 raeburn 1765: if (ref($settings->{authorquota}) eq 'HASH') {
1766: $currauthorquota = $settings->{authorquota}->{$type};
1767: }
1.78 raeburn 1768: }
1.72 raeburn 1769: }
1.3 raeburn 1770: if (defined($usertypes->{$type})) {
1771: $typecount ++;
1772: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1773: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1774: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1775: '<td class="LC_left_item">';
1.101 raeburn 1776: if ($context eq 'requestcourses') {
1777: $datatable .= '<table><tr>';
1778: }
1779: my %cell;
1.72 raeburn 1780: foreach my $item (@usertools) {
1.101 raeburn 1781: if ($context eq 'requestcourses') {
1782: my ($curroption,$currlimit);
1783: if (ref($settings) eq 'HASH') {
1784: if (ref($settings->{$item}) eq 'HASH') {
1785: $curroption = $settings->{$item}->{$type};
1786: if ($curroption =~ /^autolimit=(\d*)$/) {
1787: $currlimit = $1;
1788: }
1789: }
1790: }
1791: if (!$curroption) {
1792: $curroption = 'norequest';
1793: }
1794: $datatable .= '<th>'.$titles{$item}.'</th>';
1795: foreach my $option (@options) {
1796: my $val = $option;
1797: if ($option eq 'norequest') {
1798: $val = 0;
1799: }
1800: if ($option eq 'validate') {
1801: my $canvalidate = 0;
1802: if (ref($validations{$item}) eq 'HASH') {
1803: if ($validations{$item}{$type}) {
1804: $canvalidate = 1;
1805: }
1806: }
1807: next if (!$canvalidate);
1808: }
1809: my $checked = '';
1810: if ($option eq $curroption) {
1811: $checked = ' checked="checked"';
1812: } elsif ($option eq 'autolimit') {
1813: if ($curroption =~ /^autolimit/) {
1814: $checked = ' checked="checked"';
1815: }
1816: }
1817: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1818: '<input type="radio" name="crsreq_'.$item.
1819: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1820: $titles{$option}.'</label>';
1.101 raeburn 1821: if ($option eq 'autolimit') {
1.127 raeburn 1822: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1823: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1824: 'value="'.$currlimit.'" />';
1.101 raeburn 1825: }
1.127 raeburn 1826: $cell{$item} .= '</span> ';
1.103 raeburn 1827: if ($option eq 'autolimit') {
1.127 raeburn 1828: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1829: }
1.101 raeburn 1830: }
1.163 raeburn 1831: } elsif ($context eq 'requestauthor') {
1832: my $curroption;
1833: if (ref($settings) eq 'HASH') {
1834: $curroption = $settings->{$type};
1835: }
1836: if (!$curroption) {
1837: $curroption = 'norequest';
1838: }
1839: foreach my $option (@options) {
1840: my $val = $option;
1841: if ($option eq 'norequest') {
1842: $val = 0;
1843: }
1844: my $checked = '';
1845: if ($option eq $curroption) {
1846: $checked = ' checked="checked"';
1847: }
1848: $datatable .= '<span class="LC_nobreak"><label>'.
1849: '<input type="radio" name="authorreq_'.$type.
1850: '" value="'.$val.'"'.$checked.' />'.
1851: $titles{$option}.'</label></span> ';
1852: }
1.101 raeburn 1853: } else {
1854: my $checked = 'checked="checked" ';
1855: if (ref($settings) eq 'HASH') {
1856: if (ref($settings->{$item}) eq 'HASH') {
1857: if ($settings->{$item}->{$type} == 0) {
1858: $checked = '';
1859: } elsif ($settings->{$item}->{$type} == 1) {
1860: $checked = 'checked="checked" ';
1861: }
1.78 raeburn 1862: }
1.72 raeburn 1863: }
1.101 raeburn 1864: $datatable .= '<span class="LC_nobreak"><label>'.
1865: '<input type="checkbox" name="'.$context.'_'.$item.
1866: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1867: '</label></span> ';
1.72 raeburn 1868: }
1.101 raeburn 1869: }
1870: if ($context eq 'requestcourses') {
1871: $datatable .= '</tr><tr>';
1872: foreach my $item (@usertools) {
1.106 raeburn 1873: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1874: }
1875: $datatable .= '</tr></table>';
1.72 raeburn 1876: }
1.86 raeburn 1877: $datatable .= '</td>';
1.163 raeburn 1878: unless (($context eq 'requestcourses') ||
1879: ($context eq 'requestauthor')) {
1.86 raeburn 1880: $datatable .=
1.197 raeburn 1881: '<td class="LC_right_item">'.
1882: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1883: '<input type="text" name="quota_'.$type.
1.72 raeburn 1884: '" value="'.$currdefquota.
1.197 raeburn 1885: '" size="5" /></span>'.(' ' x 2).
1886: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1887: '<input type="text" name="authorquota_'.$type.
1888: '" value="'.$currauthorquota.
1889: '" size="5" /></span></td>';
1.86 raeburn 1890: }
1891: $datatable .= '</tr>';
1.3 raeburn 1892: }
1893: }
1894: }
1.163 raeburn 1895: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1896: $defaultquota = '20';
1.197 raeburn 1897: $authorquota = '500';
1.86 raeburn 1898: if (ref($settings) eq 'HASH') {
1899: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1900: $defaultquota = $settings->{'defaultquota'}->{'default'};
1901: } elsif (defined($settings->{'default'})) {
1902: $defaultquota = $settings->{'default'};
1903: }
1.197 raeburn 1904: if (ref($settings->{'authorquota'}) eq 'HASH') {
1905: $authorquota = $settings->{'authorquota'}->{'default'};
1906: }
1.3 raeburn 1907: }
1908: }
1909: $typecount ++;
1910: $css_class = $typecount%2?' class="LC_odd_row"':'';
1911: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1912: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1913: '<td class="LC_left_item">';
1.101 raeburn 1914: if ($context eq 'requestcourses') {
1915: $datatable .= '<table><tr>';
1916: }
1917: my %defcell;
1.72 raeburn 1918: foreach my $item (@usertools) {
1.101 raeburn 1919: if ($context eq 'requestcourses') {
1920: my ($curroption,$currlimit);
1921: if (ref($settings) eq 'HASH') {
1922: if (ref($settings->{$item}) eq 'HASH') {
1923: $curroption = $settings->{$item}->{'default'};
1924: if ($curroption =~ /^autolimit=(\d*)$/) {
1925: $currlimit = $1;
1926: }
1927: }
1928: }
1929: if (!$curroption) {
1930: $curroption = 'norequest';
1931: }
1932: $datatable .= '<th>'.$titles{$item}.'</th>';
1933: foreach my $option (@options) {
1934: my $val = $option;
1935: if ($option eq 'norequest') {
1936: $val = 0;
1937: }
1938: if ($option eq 'validate') {
1939: my $canvalidate = 0;
1940: if (ref($validations{$item}) eq 'HASH') {
1941: if ($validations{$item}{'default'}) {
1942: $canvalidate = 1;
1943: }
1944: }
1945: next if (!$canvalidate);
1946: }
1947: my $checked = '';
1948: if ($option eq $curroption) {
1949: $checked = ' checked="checked"';
1950: } elsif ($option eq 'autolimit') {
1951: if ($curroption =~ /^autolimit/) {
1952: $checked = ' checked="checked"';
1953: }
1954: }
1955: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1956: '<input type="radio" name="crsreq_'.$item.
1957: '_default" value="'.$val.'"'.$checked.' />'.
1958: $titles{$option}.'</label>';
1959: if ($option eq 'autolimit') {
1.127 raeburn 1960: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1961: $item.'_limit_default" size="1" '.
1962: 'value="'.$currlimit.'" />';
1963: }
1.127 raeburn 1964: $defcell{$item} .= '</span> ';
1.104 raeburn 1965: if ($option eq 'autolimit') {
1.127 raeburn 1966: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1967: }
1.101 raeburn 1968: }
1.163 raeburn 1969: } elsif ($context eq 'requestauthor') {
1970: my $curroption;
1971: if (ref($settings) eq 'HASH') {
1.172 raeburn 1972: $curroption = $settings->{'default'};
1.163 raeburn 1973: }
1974: if (!$curroption) {
1975: $curroption = 'norequest';
1976: }
1977: foreach my $option (@options) {
1978: my $val = $option;
1979: if ($option eq 'norequest') {
1980: $val = 0;
1981: }
1982: my $checked = '';
1983: if ($option eq $curroption) {
1984: $checked = ' checked="checked"';
1985: }
1986: $datatable .= '<span class="LC_nobreak"><label>'.
1987: '<input type="radio" name="authorreq_default"'.
1988: ' value="'.$val.'"'.$checked.' />'.
1989: $titles{$option}.'</label></span> ';
1990: }
1.101 raeburn 1991: } else {
1992: my $checked = 'checked="checked" ';
1993: if (ref($settings) eq 'HASH') {
1994: if (ref($settings->{$item}) eq 'HASH') {
1995: if ($settings->{$item}->{'default'} == 0) {
1996: $checked = '';
1997: } elsif ($settings->{$item}->{'default'} == 1) {
1998: $checked = 'checked="checked" ';
1999: }
1.78 raeburn 2000: }
1.72 raeburn 2001: }
1.101 raeburn 2002: $datatable .= '<span class="LC_nobreak"><label>'.
2003: '<input type="checkbox" name="'.$context.'_'.$item.
2004: '" value="default" '.$checked.'/>'.$titles{$item}.
2005: '</label></span> ';
2006: }
2007: }
2008: if ($context eq 'requestcourses') {
2009: $datatable .= '</tr><tr>';
2010: foreach my $item (@usertools) {
1.106 raeburn 2011: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2012: }
1.101 raeburn 2013: $datatable .= '</tr></table>';
1.72 raeburn 2014: }
1.86 raeburn 2015: $datatable .= '</td>';
1.163 raeburn 2016: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2017: $datatable .= '<td class="LC_right_item">'.
2018: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2019: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2020: $defaultquota.'" size="5" /></span>'.(' ' x2).
2021: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2022: '<input type="text" name="authorquota" value="'.
2023: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2024: }
2025: $datatable .= '</tr>';
1.72 raeburn 2026: $typecount ++;
2027: $css_class = $typecount%2?' class="LC_odd_row"':'';
2028: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2029: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2030: if ($context eq 'requestcourses') {
1.109 raeburn 2031: $datatable .= &mt('(overrides affiliation, if set)').
2032: '</td>'.
2033: '<td class="LC_left_item">'.
2034: '<table><tr>';
1.101 raeburn 2035: } else {
1.109 raeburn 2036: $datatable .= &mt('(overrides affiliation, if checked)').
2037: '</td>'.
2038: '<td class="LC_left_item" colspan="2">'.
2039: '<br />';
1.101 raeburn 2040: }
2041: my %advcell;
1.72 raeburn 2042: foreach my $item (@usertools) {
1.101 raeburn 2043: if ($context eq 'requestcourses') {
2044: my ($curroption,$currlimit);
2045: if (ref($settings) eq 'HASH') {
2046: if (ref($settings->{$item}) eq 'HASH') {
2047: $curroption = $settings->{$item}->{'_LC_adv'};
2048: if ($curroption =~ /^autolimit=(\d*)$/) {
2049: $currlimit = $1;
2050: }
2051: }
2052: }
2053: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2054: my $checked = '';
2055: if ($curroption eq '') {
2056: $checked = ' checked="checked"';
2057: }
2058: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2059: '<input type="radio" name="crsreq_'.$item.
2060: '__LC_adv" value=""'.$checked.' />'.
2061: &mt('No override set').'</label></span> ';
1.101 raeburn 2062: foreach my $option (@options) {
2063: my $val = $option;
2064: if ($option eq 'norequest') {
2065: $val = 0;
2066: }
2067: if ($option eq 'validate') {
2068: my $canvalidate = 0;
2069: if (ref($validations{$item}) eq 'HASH') {
2070: if ($validations{$item}{'_LC_adv'}) {
2071: $canvalidate = 1;
2072: }
2073: }
2074: next if (!$canvalidate);
2075: }
2076: my $checked = '';
1.104 raeburn 2077: if ($val eq $curroption) {
1.101 raeburn 2078: $checked = ' checked="checked"';
2079: } elsif ($option eq 'autolimit') {
2080: if ($curroption =~ /^autolimit/) {
2081: $checked = ' checked="checked"';
2082: }
2083: }
2084: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2085: '<input type="radio" name="crsreq_'.$item.
2086: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2087: $titles{$option}.'</label>';
2088: if ($option eq 'autolimit') {
1.127 raeburn 2089: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2090: $item.'_limit__LC_adv" size="1" '.
2091: 'value="'.$currlimit.'" />';
2092: }
1.127 raeburn 2093: $advcell{$item} .= '</span> ';
1.104 raeburn 2094: if ($option eq 'autolimit') {
1.127 raeburn 2095: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2096: }
1.101 raeburn 2097: }
1.163 raeburn 2098: } elsif ($context eq 'requestauthor') {
2099: my $curroption;
2100: if (ref($settings) eq 'HASH') {
2101: $curroption = $settings->{'_LC_adv'};
2102: }
2103: my $checked = '';
2104: if ($curroption eq '') {
2105: $checked = ' checked="checked"';
2106: }
2107: $datatable .= '<span class="LC_nobreak"><label>'.
2108: '<input type="radio" name="authorreq__LC_adv"'.
2109: ' value=""'.$checked.' />'.
2110: &mt('No override set').'</label></span> ';
2111: foreach my $option (@options) {
2112: my $val = $option;
2113: if ($option eq 'norequest') {
2114: $val = 0;
2115: }
2116: my $checked = '';
2117: if ($val eq $curroption) {
2118: $checked = ' checked="checked"';
2119: }
2120: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2121: '<input type="radio" name="authorreq__LC_adv"'.
2122: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2123: $titles{$option}.'</label></span> ';
2124: }
1.101 raeburn 2125: } else {
2126: my $checked = 'checked="checked" ';
2127: if (ref($settings) eq 'HASH') {
2128: if (ref($settings->{$item}) eq 'HASH') {
2129: if ($settings->{$item}->{'_LC_adv'} == 0) {
2130: $checked = '';
2131: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2132: $checked = 'checked="checked" ';
2133: }
1.79 raeburn 2134: }
1.72 raeburn 2135: }
1.101 raeburn 2136: $datatable .= '<span class="LC_nobreak"><label>'.
2137: '<input type="checkbox" name="'.$context.'_'.$item.
2138: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2139: '</label></span> ';
2140: }
2141: }
2142: if ($context eq 'requestcourses') {
2143: $datatable .= '</tr><tr>';
2144: foreach my $item (@usertools) {
1.106 raeburn 2145: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2146: }
1.101 raeburn 2147: $datatable .= '</tr></table>';
1.72 raeburn 2148: }
1.98 raeburn 2149: $datatable .= '</td></tr>';
1.30 raeburn 2150: $$rowtotal += $typecount;
1.3 raeburn 2151: return $datatable;
2152: }
2153:
1.163 raeburn 2154: sub print_requestmail {
2155: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2156: my ($now,$datatable,%currapp);
1.102 raeburn 2157: $now = time;
2158: if (ref($settings) eq 'HASH') {
2159: if (ref($settings->{'notify'}) eq 'HASH') {
2160: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2161: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2162: }
2163: }
2164: }
1.191 raeburn 2165: my $numinrow = 2;
1.224 raeburn 2166: my $css_class;
2167: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2168: my $text;
2169: if ($action eq 'requestcourses') {
2170: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2171: } elsif ($action eq 'requestauthor') {
2172: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2173: } else {
1.224 raeburn 2174: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2175: }
1.224 raeburn 2176: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2177: ' <td>'.$text.'</td>'.
1.102 raeburn 2178: ' <td class="LC_left_item">';
1.191 raeburn 2179: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2180: $action.'notifyapproval',%currapp);
1.191 raeburn 2181: if ($numdc > 0) {
2182: $datatable .= $table;
1.102 raeburn 2183: } else {
2184: $datatable .= &mt('There are no active Domain Coordinators');
2185: }
2186: $datatable .='</td></tr>';
2187: return $datatable;
2188: }
2189:
1.216 raeburn 2190: sub print_studentcode {
2191: my ($settings,$rowtotal) = @_;
2192: my $rownum = 0;
1.218 raeburn 2193: my ($output,%current);
1.271 raeburn 2194: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2195: if (ref($settings) eq 'HASH') {
2196: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2197: foreach my $type (@crstypes) {
2198: $current{$type} = $settings->{'uniquecode'}{$type};
2199: }
1.218 raeburn 2200: }
2201: }
2202: $output .= '<tr>'.
2203: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2204: '<td class="LC_left_item">';
2205: foreach my $type (@crstypes) {
2206: my $check = ' ';
2207: if ($current{$type}) {
2208: $check = ' checked="checked" ';
2209: }
2210: $output .= '<span class="LC_nobreak"><label>'.
2211: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2212: &mt($type).'</label></span>'.(' 'x2).' ';
2213: }
2214: $output .= '</td></tr>';
2215: $$rowtotal ++;
2216: return $output;
1.216 raeburn 2217: }
2218:
2219: sub print_textbookcourses {
1.242 raeburn 2220: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2221: my $rownum = 0;
2222: my $css_class;
2223: my $itemcount = 1;
2224: my $maxnum = 0;
2225: my $bookshash;
2226: if (ref($settings) eq 'HASH') {
1.242 raeburn 2227: $bookshash = $settings->{$type};
1.216 raeburn 2228: }
2229: my %ordered;
2230: if (ref($bookshash) eq 'HASH') {
2231: foreach my $item (keys(%{$bookshash})) {
2232: if (ref($bookshash->{$item}) eq 'HASH') {
2233: my $num = $bookshash->{$item}{'order'};
2234: $ordered{$num} = $item;
2235: }
2236: }
2237: }
2238: my $confname = $dom.'-domainconfig';
2239: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2240: my $maxnum = scalar(keys(%ordered));
2241: my $datatable;
1.216 raeburn 2242: if (keys(%ordered)) {
2243: my @items = sort { $a <=> $b } keys(%ordered);
2244: for (my $i=0; $i<@items; $i++) {
2245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2246: my $key = $ordered{$items[$i]};
2247: my %coursehash=&Apache::lonnet::coursedescription($key);
2248: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2249: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2250: if (ref($bookshash->{$key}) eq 'HASH') {
2251: $subject = $bookshash->{$key}->{'subject'};
2252: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2253: if ($type eq 'textbooks') {
1.243 raeburn 2254: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2255: $author = $bookshash->{$key}->{'author'};
2256: $image = $bookshash->{$key}->{'image'};
2257: if ($image ne '') {
2258: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2259: my $imagethumb = "$path/tn-".$imagefile;
2260: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2261: }
1.216 raeburn 2262: }
2263: }
1.242 raeburn 2264: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2265: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2266: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2267: for (my $k=0; $k<=$maxnum; $k++) {
2268: my $vpos = $k+1;
2269: my $selstr;
2270: if ($k == $i) {
2271: $selstr = ' selected="selected" ';
2272: }
2273: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2274: }
2275: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2276: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2277: &mt('Delete?').'</label></span></td>'.
2278: '<td colspan="2">'.
1.242 raeburn 2279: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2280: (' 'x2).
1.242 raeburn 2281: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2282: if ($type eq 'textbooks') {
2283: $datatable .= (' 'x2).
1.243 raeburn 2284: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2285: (' 'x2).
1.242 raeburn 2286: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2287: (' 'x2).
2288: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2289: if ($image) {
1.267 raeburn 2290: $datatable .= $imgsrc.
1.242 raeburn 2291: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2292: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2293: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2294: }
2295: if ($switchserver) {
2296: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2297: } else {
2298: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2299: }
1.216 raeburn 2300: }
1.242 raeburn 2301: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2302: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2303: $coursetitle.'</span></td></tr>'."\n";
2304: $itemcount ++;
2305: }
2306: }
2307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2308: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2309: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2310: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2311: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2312: for (my $k=0; $k<$maxnum+1; $k++) {
2313: my $vpos = $k+1;
2314: my $selstr;
2315: if ($k == $maxnum) {
2316: $selstr = ' selected="selected" ';
2317: }
2318: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2319: }
2320: $datatable .= '</select> '."\n".
1.242 raeburn 2321: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2322: '<td colspan="2">'.
1.242 raeburn 2323: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2324: (' 'x2).
1.242 raeburn 2325: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2326: (' 'x2);
2327: if ($type eq 'textbooks') {
1.243 raeburn 2328: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2329: (' 'x2).
2330: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2331: (' 'x2).
2332: '<span class="LC_nobreak">'.&mt('Image:').' ';
2333: if ($switchserver) {
2334: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2335: } else {
2336: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2337: }
1.216 raeburn 2338: }
2339: $datatable .= '</span>'."\n".
2340: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2341: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2342: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2343: &Apache::loncommon::selectcourse_link
1.242 raeburn 2344: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2345: '</span></td>'."\n".
2346: '</tr>'."\n";
2347: $itemcount ++;
2348: return $datatable;
2349: }
2350:
1.217 raeburn 2351: sub textbookcourses_javascript {
1.242 raeburn 2352: my ($settings) = @_;
2353: return unless(ref($settings) eq 'HASH');
2354: my (%ordered,%total,%jstext);
2355: foreach my $type ('textbooks','templates') {
2356: $total{$type} = 0;
2357: if (ref($settings->{$type}) eq 'HASH') {
2358: foreach my $item (keys(%{$settings->{$type}})) {
2359: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2360: my $num = $settings->{$type}->{$item}{'order'};
2361: $ordered{$type}{$num} = $item;
2362: }
2363: }
2364: $total{$type} = scalar(keys(%{$settings->{$type}}));
2365: }
2366: my @jsarray = ();
2367: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2368: push(@jsarray,$ordered{$type}{$item});
2369: }
2370: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2371: }
2372: return <<"ENDSCRIPT";
2373: <script type="text/javascript">
2374: // <![CDATA[
1.242 raeburn 2375: function reorderBooks(form,item,caller) {
1.217 raeburn 2376: var changedVal;
1.242 raeburn 2377: $jstext{'textbooks'};
2378: $jstext{'templates'};
2379: var newpos;
2380: var maxh;
2381: if (caller == 'textbooks') {
2382: newpos = 'textbooks_addbook_pos';
2383: maxh = 1 + $total{'textbooks'};
2384: } else {
2385: newpos = 'templates_addbook_pos';
2386: maxh = 1 + $total{'templates'};
2387: }
1.217 raeburn 2388: var current = new Array;
2389: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2390: if (item == newpos) {
2391: changedVal = newitemVal;
2392: } else {
2393: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2394: current[newitemVal] = newpos;
2395: }
1.242 raeburn 2396: if (caller == 'textbooks') {
2397: for (var i=0; i<textbooks.length; i++) {
2398: var elementName = 'textbooks_'+textbooks[i];
2399: if (elementName != item) {
2400: if (form.elements[elementName]) {
2401: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2402: current[currVal] = elementName;
2403: }
2404: }
2405: }
2406: }
2407: if (caller == 'templates') {
2408: for (var i=0; i<templates.length; i++) {
2409: var elementName = 'templates_'+templates[i];
2410: if (elementName != item) {
2411: if (form.elements[elementName]) {
2412: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2413: current[currVal] = elementName;
2414: }
1.217 raeburn 2415: }
2416: }
2417: }
2418: var oldVal;
2419: for (var j=0; j<maxh; j++) {
2420: if (current[j] == undefined) {
2421: oldVal = j;
2422: }
2423: }
2424: if (oldVal < changedVal) {
2425: for (var k=oldVal+1; k<=changedVal ; k++) {
2426: var elementName = current[k];
2427: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2428: }
2429: } else {
2430: for (var k=changedVal; k<oldVal; k++) {
2431: var elementName = current[k];
2432: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2433: }
2434: }
2435: return;
2436: }
2437:
2438: // ]]>
2439: </script>
2440:
2441: ENDSCRIPT
2442: }
2443:
1.267 raeburn 2444: sub ltitools_javascript {
2445: my ($settings) = @_;
2446: return unless(ref($settings) eq 'HASH');
2447: my (%ordered,$total,%jstext);
2448: $total = 0;
2449: foreach my $item (keys(%{$settings})) {
2450: if (ref($settings->{$item}) eq 'HASH') {
2451: my $num = $settings->{$item}{'order'};
2452: $ordered{$num} = $item;
2453: }
2454: }
2455: $total = scalar(keys(%{$settings}));
2456: my @jsarray = ();
2457: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2458: push(@jsarray,$ordered{$item});
2459: }
2460: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2461: return <<"ENDSCRIPT";
2462: <script type="text/javascript">
2463: // <![CDATA[
2464: function reorderLTI(form,item) {
2465: var changedVal;
2466: $jstext
2467: var newpos = 'ltitools_add_pos';
2468: var maxh = 1 + $total;
2469: var current = new Array;
2470: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2471: if (item == newpos) {
2472: changedVal = newitemVal;
2473: } else {
2474: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2475: current[newitemVal] = newpos;
2476: }
2477: for (var i=0; i<ltitools.length; i++) {
2478: var elementName = 'ltitools_'+ltitools[i];
2479: if (elementName != item) {
2480: if (form.elements[elementName]) {
2481: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2482: current[currVal] = elementName;
2483: }
2484: }
2485: }
2486: var oldVal;
2487: for (var j=0; j<maxh; j++) {
2488: if (current[j] == undefined) {
2489: oldVal = j;
2490: }
2491: }
2492: if (oldVal < changedVal) {
2493: for (var k=oldVal+1; k<=changedVal ; k++) {
2494: var elementName = current[k];
2495: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2496: }
2497: } else {
2498: for (var k=changedVal; k<oldVal; k++) {
2499: var elementName = current[k];
2500: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2501: }
2502: }
2503: return;
2504: }
2505:
2506: // ]]>
2507: </script>
2508:
2509: ENDSCRIPT
2510: }
2511:
1.3 raeburn 2512: sub print_autoenroll {
1.30 raeburn 2513: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2514: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2515: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2516: if (ref($settings) eq 'HASH') {
2517: if (exists($settings->{'run'})) {
2518: if ($settings->{'run'} eq '0') {
2519: $runoff = ' checked="checked" ';
2520: $runon = ' ';
2521: } else {
2522: $runon = ' checked="checked" ';
2523: $runoff = ' ';
2524: }
2525: } else {
2526: if ($autorun) {
2527: $runon = ' checked="checked" ';
2528: $runoff = ' ';
2529: } else {
2530: $runoff = ' checked="checked" ';
2531: $runon = ' ';
2532: }
2533: }
1.129 raeburn 2534: if (exists($settings->{'co-owners'})) {
2535: if ($settings->{'co-owners'} eq '0') {
2536: $coownersoff = ' checked="checked" ';
2537: $coownerson = ' ';
2538: } else {
2539: $coownerson = ' checked="checked" ';
2540: $coownersoff = ' ';
2541: }
2542: } else {
2543: $coownersoff = ' checked="checked" ';
2544: $coownerson = ' ';
2545: }
1.3 raeburn 2546: if (exists($settings->{'sender_domain'})) {
2547: $defdom = $settings->{'sender_domain'};
2548: }
1.274 raeburn 2549: if (exists($settings->{'autofailsafe'})) {
2550: $failsafe = $settings->{'autofailsafe'};
2551: }
1.14 raeburn 2552: } else {
2553: if ($autorun) {
2554: $runon = ' checked="checked" ';
2555: $runoff = ' ';
2556: } else {
2557: $runoff = ' checked="checked" ';
2558: $runon = ' ';
2559: }
1.3 raeburn 2560: }
2561: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2562: my $notif_sender;
2563: if (ref($settings) eq 'HASH') {
2564: $notif_sender = $settings->{'sender_uname'};
2565: }
1.3 raeburn 2566: my $datatable='<tr class="LC_odd_row">'.
2567: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2568: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2569: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2570: $runon.' value="1" />'.&mt('Yes').'</label> '.
2571: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2572: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2573: '</tr><tr>'.
2574: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2575: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2576: &mt('username').': '.
2577: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2578: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2579: ': '.$domform.'</span></td></tr>'.
2580: '<tr class="LC_odd_row">'.
2581: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2582: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2583: '<input type="radio" name="autoassign_coowners"'.
2584: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2585: '<label><input type="radio" name="autoassign_coowners"'.
2586: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2587: '</tr><tr>'.
2588: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2589: '<td class="LC_right_item"><span class="LC_nobreak">'.
2590: '<input type="text" name="autoenroll_failsafe"'.
2591: ' value="'.$failsafe.'" size="4" /></td></tr>';
2592: $$rowtotal += 4;
1.3 raeburn 2593: return $datatable;
2594: }
2595:
2596: sub print_autoupdate {
1.30 raeburn 2597: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2598: my $datatable;
2599: if ($position eq 'top') {
2600: my $updateon = ' ';
2601: my $updateoff = ' checked="checked" ';
2602: my $classlistson = ' ';
2603: my $classlistsoff = ' checked="checked" ';
2604: if (ref($settings) eq 'HASH') {
2605: if ($settings->{'run'} eq '1') {
2606: $updateon = $updateoff;
2607: $updateoff = ' ';
2608: }
2609: if ($settings->{'classlists'} eq '1') {
2610: $classlistson = $classlistsoff;
2611: $classlistsoff = ' ';
2612: }
2613: }
2614: my %title = (
2615: run => 'Auto-update active?',
2616: classlists => 'Update information in classlists?',
2617: );
2618: $datatable = '<tr class="LC_odd_row">'.
2619: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2620: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2621: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2622: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2623: '<label><input type="radio" name="autoupdate_run"'.
2624: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2625: '</tr><tr>'.
2626: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2627: '<td class="LC_right_item"><span class="LC_nobreak">'.
2628: '<label><input type="radio" name="classlists"'.
2629: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2630: '<label><input type="radio" name="classlists"'.
2631: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2632: '</tr>';
1.30 raeburn 2633: $$rowtotal += 2;
1.131 raeburn 2634: } elsif ($position eq 'middle') {
2635: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2636: my $numinrow = 3;
2637: my $locknamesettings;
2638: $datatable .= &insttypes_row($settings,$types,$usertypes,
2639: $dom,$numinrow,$othertitle,
2640: 'lockablenames');
2641: $$rowtotal ++;
1.3 raeburn 2642: } else {
1.44 raeburn 2643: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2644: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2645: 'permanentemail','id');
1.33 raeburn 2646: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2647: my $numrows = 0;
1.26 raeburn 2648: if (ref($types) eq 'ARRAY') {
2649: if (@{$types} > 0) {
2650: $datatable =
2651: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2652: \@fields,$types,\$numrows);
1.30 raeburn 2653: $$rowtotal += @{$types};
1.26 raeburn 2654: }
1.3 raeburn 2655: }
2656: $datatable .=
2657: &usertype_update_row($settings,{'default' => $othertitle},
2658: \%fieldtitles,\@fields,['default'],
2659: \$numrows);
1.30 raeburn 2660: $$rowtotal ++;
1.3 raeburn 2661: }
2662: return $datatable;
2663: }
2664:
1.125 raeburn 2665: sub print_autocreate {
2666: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2667: my (%createon,%createoff,%currhash);
1.125 raeburn 2668: my @types = ('xml','req');
2669: if (ref($settings) eq 'HASH') {
2670: foreach my $item (@types) {
2671: $createoff{$item} = ' checked="checked" ';
2672: $createon{$item} = ' ';
2673: if (exists($settings->{$item})) {
2674: if ($settings->{$item}) {
2675: $createon{$item} = ' checked="checked" ';
2676: $createoff{$item} = ' ';
2677: }
2678: }
2679: }
1.210 raeburn 2680: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2681: $currhash{$settings->{'xmldc'}} = 1;
2682: }
1.125 raeburn 2683: } else {
2684: foreach my $item (@types) {
2685: $createoff{$item} = ' checked="checked" ';
2686: $createon{$item} = ' ';
2687: }
2688: }
2689: $$rowtotal += 2;
1.191 raeburn 2690: my $numinrow = 2;
1.125 raeburn 2691: my $datatable='<tr class="LC_odd_row">'.
2692: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2693: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2694: '<input type="radio" name="autocreate_xml"'.
2695: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2696: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2697: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2698: '</td></tr><tr>'.
2699: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2700: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2701: '<input type="radio" name="autocreate_req"'.
2702: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2703: '<label><input type="radio" name="autocreate_req"'.
2704: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2705: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2706: 'autocreate_xmldc',%currhash);
1.247 raeburn 2707: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2708: if ($numdc > 1) {
1.247 raeburn 2709: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2710: '</td><td class="LC_left_item">';
1.125 raeburn 2711: } else {
1.247 raeburn 2712: $datatable .= &mt('Course creation processed as:').
2713: '</td><td class="LC_right_item">';
1.125 raeburn 2714: }
1.247 raeburn 2715: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2716: $$rowtotal += $rows;
1.125 raeburn 2717: return $datatable;
2718: }
2719:
1.23 raeburn 2720: sub print_directorysrch {
1.30 raeburn 2721: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2722: my $srchon = ' ';
2723: my $srchoff = ' checked="checked" ';
1.25 raeburn 2724: my ($exacton,$containson,$beginson);
1.24 raeburn 2725: my $localon = ' ';
2726: my $localoff = ' checked="checked" ';
1.23 raeburn 2727: if (ref($settings) eq 'HASH') {
2728: if ($settings->{'available'} eq '1') {
2729: $srchon = $srchoff;
2730: $srchoff = ' ';
2731: }
1.24 raeburn 2732: if ($settings->{'localonly'} eq '1') {
2733: $localon = $localoff;
2734: $localoff = ' ';
2735: }
1.25 raeburn 2736: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2737: foreach my $type (@{$settings->{'searchtypes'}}) {
2738: if ($type eq 'exact') {
2739: $exacton = ' checked="checked" ';
2740: } elsif ($type eq 'contains') {
2741: $containson = ' checked="checked" ';
2742: } elsif ($type eq 'begins') {
2743: $beginson = ' checked="checked" ';
2744: }
2745: }
2746: } else {
2747: if ($settings->{'searchtypes'} eq 'exact') {
2748: $exacton = ' checked="checked" ';
2749: } elsif ($settings->{'searchtypes'} eq 'contains') {
2750: $containson = ' checked="checked" ';
2751: } elsif ($settings->{'searchtypes'} eq 'specify') {
2752: $exacton = ' checked="checked" ';
2753: $containson = ' checked="checked" ';
2754: }
1.23 raeburn 2755: }
2756: }
2757: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2758: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2759:
2760: my $numinrow = 4;
1.26 raeburn 2761: my $cansrchrow = 0;
1.23 raeburn 2762: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2763: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2764: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2765: '<input type="radio" name="dirsrch_available"'.
2766: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2767: '<label><input type="radio" name="dirsrch_available"'.
2768: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2769: '</tr><tr>'.
1.30 raeburn 2770: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2771: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2772: '<input type="radio" name="dirsrch_localonly"'.
2773: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2774: '<label><input type="radio" name="dirsrch_localonly"'.
2775: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2776: '</tr>';
1.30 raeburn 2777: $$rowtotal += 2;
1.26 raeburn 2778: if (ref($usertypes) eq 'HASH') {
2779: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2780: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2781: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2782: $cansrchrow = 1;
2783: }
2784: }
2785: if ($cansrchrow) {
1.30 raeburn 2786: $$rowtotal ++;
1.26 raeburn 2787: $datatable .= '<tr>';
2788: } else {
2789: $datatable .= '<tr class="LC_odd_row">';
2790: }
1.30 raeburn 2791: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2792: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2793: foreach my $title (@{$titleorder}) {
2794: if (defined($searchtitles->{$title})) {
2795: my $check = ' ';
1.93 raeburn 2796: if (ref($settings) eq 'HASH') {
1.39 raeburn 2797: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2798: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2799: $check = ' checked="checked" ';
2800: }
1.25 raeburn 2801: }
2802: }
2803: $datatable .= '<td class="LC_left_item">'.
2804: '<span class="LC_nobreak"><label>'.
2805: '<input type="checkbox" name="searchby" '.
2806: 'value="'.$title.'"'.$check.'/>'.
2807: $searchtitles->{$title}.'</label></span></td>';
2808: }
2809: }
1.26 raeburn 2810: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2811: $$rowtotal ++;
1.26 raeburn 2812: if ($cansrchrow) {
2813: $datatable .= '<tr class="LC_odd_row">';
2814: } else {
2815: $datatable .= '<tr>';
2816: }
1.30 raeburn 2817: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2818: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2819: '<span class="LC_nobreak"><label>'.
2820: '<input type="checkbox" name="searchtypes" '.
2821: $exacton.' value="exact" />'.&mt('Exact match').
2822: '</label> '.
2823: '<label><input type="checkbox" name="searchtypes" '.
2824: $beginson.' value="begins" />'.&mt('Begins with').
2825: '</label> '.
2826: '<label><input type="checkbox" name="searchtypes" '.
2827: $containson.' value="contains" />'.&mt('Contains').
2828: '</label></span></td></tr>';
1.30 raeburn 2829: $$rowtotal ++;
1.25 raeburn 2830: return $datatable;
2831: }
2832:
1.28 raeburn 2833: sub print_contacts {
1.30 raeburn 2834: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2835: my $datatable;
2836: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2837: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2838: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2839: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2840: foreach my $type (@mailings) {
2841: $otheremails{$type} = '';
2842: }
1.134 raeburn 2843: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2844: if (ref($settings) eq 'HASH') {
2845: foreach my $item (@contacts) {
2846: if (exists($settings->{$item})) {
2847: $to{$item} = $settings->{$item};
2848: }
2849: }
2850: foreach my $type (@mailings) {
2851: if (exists($settings->{$type})) {
2852: if (ref($settings->{$type}) eq 'HASH') {
2853: foreach my $item (@contacts) {
2854: if ($settings->{$type}{$item}) {
2855: $checked{$type}{$item} = ' checked="checked" ';
2856: }
2857: }
2858: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2859: if ($type eq 'helpdeskmail') {
2860: $bccemails{$type} = $settings->{$type}{'bcc'};
2861: }
1.28 raeburn 2862: }
1.89 raeburn 2863: } elsif ($type eq 'lonstatusmail') {
2864: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2865: }
2866: }
2867: } else {
2868: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2869: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2870: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2871: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2872: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2873: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2874: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2875: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2876: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2877: }
2878: my ($titles,$short_titles) = &contact_titles();
2879: my $rownum = 0;
2880: my $css_class;
2881: foreach my $item (@contacts) {
1.69 raeburn 2882: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2883: $datatable .= '<tr'.$css_class.'>'.
2884: '<td><span class="LC_nobreak">'.$titles->{$item}.
2885: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2886: '<input type="text" name="'.$item.'" value="'.
2887: $to{$item}.'" /></td></tr>';
1.203 raeburn 2888: $rownum ++;
1.28 raeburn 2889: }
2890: foreach my $type (@mailings) {
1.69 raeburn 2891: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2892: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2893: '<td><span class="LC_nobreak">'.
2894: $titles->{$type}.': </span></td>'.
1.28 raeburn 2895: '<td class="LC_left_item">'.
2896: '<span class="LC_nobreak">';
2897: foreach my $item (@contacts) {
2898: $datatable .= '<label>'.
2899: '<input type="checkbox" name="'.$type.'"'.
2900: $checked{$type}{$item}.
2901: ' value="'.$item.'" />'.$short_titles->{$item}.
2902: '</label> ';
2903: }
2904: $datatable .= '</span><br />'.&mt('Others').': '.
2905: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2906: 'value="'.$otheremails{$type}.'" />';
2907: if ($type eq 'helpdeskmail') {
1.136 raeburn 2908: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2909: '<input type="text" name="'.$type.'_bcc" '.
2910: 'value="'.$bccemails{$type}.'" />';
2911: }
2912: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2913: $rownum ++;
1.28 raeburn 2914: }
1.203 raeburn 2915: my %choices;
2916: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2917: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2918: &mt('LON-CAPA core group - MSU'),600,500));
2919: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2920: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2921: &mt('LON-CAPA core group - MSU'),600,500));
2922: my @toggles = ('reporterrors','reportupdates');
2923: my %defaultchecked = ('reporterrors' => 'on',
2924: 'reportupdates' => 'on');
2925: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2926: \%choices,$rownum);
2927: $datatable .= $reports;
1.30 raeburn 2928: $$rowtotal += $rownum;
1.28 raeburn 2929: return $datatable;
2930: }
2931:
1.118 jms 2932: sub print_helpsettings {
1.168 raeburn 2933: my ($dom,$confname,$settings,$rowtotal) = @_;
2934: my ($datatable,$itemcount);
1.166 raeburn 2935: $itemcount = 1;
1.168 raeburn 2936: my (%choices,%defaultchecked,@toggles);
2937: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2938: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2939: &mt('LON-CAPA bug tracker'),600,500));
2940: %defaultchecked = ('submitbugs' => 'on');
2941: @toggles = ('submitbugs',);
1.166 raeburn 2942:
1.168 raeburn 2943: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2944: \%choices,$itemcount);
1.166 raeburn 2945: return $datatable;
1.121 raeburn 2946: }
2947:
2948: sub radiobutton_prefs {
1.192 raeburn 2949: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 2950: $additional,$align) = @_;
1.121 raeburn 2951: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2952: (ref($choices) eq 'HASH'));
2953:
1.170 raeburn 2954: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2955:
2956: foreach my $item (@{$toggles}) {
2957: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2958: $checkedon{$item} = ' checked="checked" ';
2959: $checkedoff{$item} = ' ';
1.121 raeburn 2960: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2961: $checkedoff{$item} = ' checked="checked" ';
2962: $checkedon{$item} = ' ';
2963: }
2964: }
2965: if (ref($settings) eq 'HASH') {
1.121 raeburn 2966: foreach my $item (@{$toggles}) {
1.118 jms 2967: if ($settings->{$item} eq '1') {
2968: $checkedon{$item} = ' checked="checked" ';
2969: $checkedoff{$item} = ' ';
2970: } elsif ($settings->{$item} eq '0') {
2971: $checkedoff{$item} = ' checked="checked" ';
2972: $checkedon{$item} = ' ';
2973: }
2974: }
1.121 raeburn 2975: }
1.192 raeburn 2976: if ($onclick) {
2977: $onclick = ' onclick="'.$onclick.'"';
2978: }
1.121 raeburn 2979: foreach my $item (@{$toggles}) {
1.118 jms 2980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2981: $datatable .=
1.192 raeburn 2982: '<tr'.$css_class.'><td valign="top">'.
2983: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 2984: '</span></td>';
2985: if ($align eq 'left') {
2986: $datatable .= '<td class="LC_left_item">';
2987: } else {
2988: $datatable .= '<td class="LC_right_item">';
2989: }
2990: $datatable .=
2991: '<span class="LC_nobreak">'.
1.118 jms 2992: '<label><input type="radio" name="'.
1.192 raeburn 2993: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2994: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2995: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2996: '</span>'.$additional.
2997: '</td>'.
1.118 jms 2998: '</tr>';
2999: $itemcount ++;
1.121 raeburn 3000: }
3001: return ($datatable,$itemcount);
3002: }
3003:
1.267 raeburn 3004: sub print_ltitools {
3005: my ($dom,$settings,$rowtotal) = @_;
3006: my $rownum = 0;
3007: my $css_class;
3008: my $itemcount = 1;
3009: my $maxnum = 0;
3010: my %ordered;
3011: if (ref($settings) eq 'HASH') {
3012: foreach my $item (keys(%{$settings})) {
3013: if (ref($settings->{$item}) eq 'HASH') {
3014: my $num = $settings->{$item}{'order'};
3015: $ordered{$num} = $item;
3016: }
3017: }
3018: }
3019: my $confname = $dom.'-domainconfig';
3020: my $switchserver = &check_switchserver($dom,$confname);
3021: my $maxnum = scalar(keys(%ordered));
3022: my $datatable = <itools_javascript($settings);
3023: my %lt = <itools_names();
3024: my @courseroles = ('cc','in','ta','ep','st');
3025: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3026: my @fields = ('fullname','firstname','lastname','email','user','roles');
3027: if (keys(%ordered)) {
3028: my @items = sort { $a <=> $b } keys(%ordered);
3029: for (my $i=0; $i<@items; $i++) {
3030: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3031: my $item = $ordered{$items[$i]};
3032: my ($title,$key,$secret,$url,$imgsrc,$version);
3033: if (ref($settings->{$item}) eq 'HASH') {
3034: $title = $settings->{$item}->{'title'};
3035: $url = $settings->{$item}->{'url'};
3036: $key = $settings->{$item}->{'key'};
3037: $secret = $settings->{$item}->{'secret'};
3038: my $image = $settings->{$item}->{'image'};
3039: if ($image ne '') {
3040: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3041: }
3042: }
3043: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3044: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3045: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3046: for (my $k=0; $k<=$maxnum; $k++) {
3047: my $vpos = $k+1;
3048: my $selstr;
3049: if ($k == $i) {
3050: $selstr = ' selected="selected" ';
3051: }
3052: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3053: }
3054: $datatable .= '</select>'.(' 'x2).
3055: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3056: &mt('Delete?').'</label></span></td>'.
3057: '<td colspan="2">'.
3058: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3059: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3060: (' 'x2).
3061: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3062: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3063: (' 'x2).
3064: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3065: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3066: '<br /><br />'.
3067: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3068: ' value="'.$url.'" /></span>'.
3069: (' 'x2).
3070: '<span class="LC_nobreak">'.$lt{'key'}.
3071: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3072: (' 'x2).
3073: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3074: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3075: '<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>'.
3076: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3077: '</fieldset>'.
3078: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3079: '<span class="LC_nobreak">'.&mt('Display target:');
3080: my %currdisp;
3081: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3082: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3083: $currdisp{'window'} = ' checked="checked"';
3084: } else {
3085: $currdisp{'iframe'} = ' checked="checked"';
3086: }
3087: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3088: $currdisp{'width'} = $1;
3089: }
3090: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3091: $currdisp{'height'} = $1;
3092: }
3093: } else {
3094: $currdisp{'iframe'} = ' checked="checked"';
3095: }
3096: foreach my $disp ('iframe','window') {
3097: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3098: $lt{$disp}.'</label>'.(' 'x2);
3099: }
3100: $datatable .= (' 'x4);
3101: foreach my $dimen ('width','height') {
3102: $datatable .= '<label>'.$lt{$dimen}.' '.
3103: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3104: (' 'x2);
3105: }
3106: $datatable .= '<br />';
3107: foreach my $extra ('passback','roster') {
3108: my $checkedon = '';
3109: my $checkedoff = ' checked="checked"';
3110: if ($settings->{$item}->{$extra}) {
3111: $checkedon = $checkedoff;
3112: $checkedoff = '';
3113: }
3114: $datatable .= $lt{$extra}.' '.
3115: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3116: &mt('Yes').'</label>'.(' 'x2).
3117: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3118: &mt('No').'</label>'.(' 'x4);
3119: }
3120: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3121: if ($imgsrc) {
3122: $datatable .= $imgsrc.
3123: '<label><input type="checkbox" name="ltitools_image_del"'.
3124: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3125: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3126: } else {
3127: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3128: }
3129: if ($switchserver) {
3130: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3131: } else {
3132: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3133: }
3134: $datatable .= '</span></fieldset>';
3135: my (%checkedfields,%rolemaps);
3136: if (ref($settings->{$item}) eq 'HASH') {
3137: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3138: %checkedfields = %{$settings->{$item}->{'fields'}};
3139: }
3140: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3141: %rolemaps = %{$settings->{$item}->{'roles'}};
3142: $checkedfields{'roles'} = 1;
3143: }
3144: }
3145: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3146: '<span class="LC_nobreak">';
3147: foreach my $field (@fields) {
3148: my $checked;
3149: if ($checkedfields{$field}) {
3150: $checked = ' checked="checked"';
3151: }
3152: $datatable .= '<label>'.
3153: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3154: $lt{$field}.'</label>'.(' ' x2);
3155: }
3156: $datatable .= '</span></fieldset>'.
3157: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3158: foreach my $role (@courseroles) {
3159: my ($selected,$selectnone);
3160: if (!$rolemaps{$role}) {
3161: $selectnone = ' selected="selected"';
3162: }
3163: $datatable .= '<td align="center">'.
3164: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3165: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3166: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3167: foreach my $ltirole (@ltiroles) {
3168: unless ($selectnone) {
3169: if ($rolemaps{$role} eq $ltirole) {
3170: $selected = ' selected="selected"';
3171: } else {
3172: $selected = '';
3173: }
3174: }
3175: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3176: }
3177: $datatable .= '</select></td>';
3178: }
1.273 raeburn 3179: $datatable .= '</tr></table></fieldset>';
3180: my %courseconfig;
3181: if (ref($settings->{$item}) eq 'HASH') {
3182: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3183: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3184: }
3185: }
3186: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3187: foreach my $item ('label','title','target') {
3188: my $checked;
3189: if ($courseconfig{$item}) {
3190: $checked = ' checked="checked"';
3191: }
3192: $datatable .= '<label>'.
3193: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3194: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3195: }
3196: $datatable .= '</span></fieldset>'.
1.267 raeburn 3197: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3198: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3199: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3200: my %custom = %{$settings->{$item}->{'custom'}};
3201: if (keys(%custom) > 0) {
3202: foreach my $key (sort(keys(%custom))) {
3203: $datatable .= '<tr><td><span class="LC_nobreak">'.
3204: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3205: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3206: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3207: ' value="'.$custom{$key}.'" /></td></tr>';
3208: }
3209: }
3210: }
3211: $datatable .= '<tr><td><span class="LC_nobreak">'.
3212: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3213: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3214: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3215: $datatable .= '</table></fieldset></td></tr>'."\n";
3216: $itemcount ++;
3217: }
3218: }
3219: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3220: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3221: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3222: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3223: '<select name="ltitools_add_pos"'.$chgstr.'>';
3224: for (my $k=0; $k<$maxnum+1; $k++) {
3225: my $vpos = $k+1;
3226: my $selstr;
3227: if ($k == $maxnum) {
3228: $selstr = ' selected="selected" ';
3229: }
3230: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3231: }
3232: $datatable .= '</select> '."\n".
3233: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3234: '<td colspan="2">'.
3235: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3236: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3237: (' 'x2).
3238: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3239: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3240: (' 'x2).
3241: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3242: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3243: '<br />'.
3244: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3245: (' 'x2).
3246: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3247: (' 'x2).
3248: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3249: '<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".
3250: '</fieldset>'.
3251: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3252: '<span class="LC_nobreak">'.&mt('Display target:');
3253: my %defaultdisp;
3254: $defaultdisp{'iframe'} = ' checked="checked"';
3255: foreach my $disp ('iframe','window') {
3256: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3257: $lt{$disp}.'</label>'.(' 'x2);
3258: }
3259: $datatable .= (' 'x4);
3260: foreach my $dimen ('width','height') {
3261: $datatable .= '<label>'.$lt{$dimen}.' '.
3262: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3263: (' 'x2);
3264: }
3265: $datatable .= '<br />';
3266: foreach my $extra ('passback','roster') {
3267: $datatable .= $lt{$extra}.' '.
3268: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3269: &mt('Yes').'</label>'.(' 'x2).
3270: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3271: &mt('No').'</label>'.(' 'x4);
3272: }
3273: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3274: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3275: if ($switchserver) {
3276: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3277: } else {
3278: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3279: }
3280: $datatable .= '</span></fieldset>'.
3281: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3282: '<span class="LC_nobreak">';
3283: foreach my $field (@fields) {
3284: $datatable .= '<label>'.
3285: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3286: $lt{$field}.'</label>'.(' ' x2);
3287: }
3288: $datatable .= '</span></fieldset>'.
3289: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3290: foreach my $role (@courseroles) {
3291: my ($checked,$checkednone);
3292: $datatable .= '<td align="center">'.
3293: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3294: '<select name="ltitools_add_roles_'.$role.'">'.
3295: '<option value="" selected="selected">'.&mt('Select').'</option>';
3296: foreach my $ltirole (@ltiroles) {
3297: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3298: }
3299: $datatable .= '</select></td>';
3300: }
3301: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3302: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3303: foreach my $item ('label','title','target') {
3304: $datatable .= '<label>'.
3305: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3306: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3307: }
3308: $datatable .= '</span></fieldset>'.
1.267 raeburn 3309: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3310: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3311: '<tr><td><span class="LC_nobreak">'.
3312: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3313: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3314: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3315: '</table></fieldset></td></tr>'."\n".
3316: '</td>'."\n".
3317: '</tr>'."\n";
3318: $itemcount ++;
3319: return $datatable;
3320: }
3321:
3322: sub ltitools_names {
3323: my %lt = &Apache::lonlocal::texthash(
3324: 'title' => 'Title',
3325: 'version' => 'Version',
3326: 'msgtype' => 'Message Type',
3327: 'url' => 'URL',
3328: 'key' => 'Key',
3329: 'secret' => 'Secret',
3330: 'icon' => 'Icon',
3331: 'user' => 'Username:domain',
3332: 'fullname' => 'Full Name',
3333: 'firstname' => 'First Name',
3334: 'lastname' => 'Last Name',
3335: 'email' => 'E-mail',
3336: 'roles' => 'Role',
3337: 'window' => 'Window/Tab',
3338: 'iframe' => 'iFrame',
3339: 'height' => 'Height',
3340: 'width' => 'Width',
3341: 'passback' => 'Tool can return grades:',
3342: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 3343: 'crstarget' => 'Display target',
3344: 'crslabel' => 'Course label',
3345: 'crstitle' => 'Course title',
1.267 raeburn 3346: );
3347: return %lt;
3348: }
3349:
1.121 raeburn 3350: sub print_coursedefaults {
1.139 raeburn 3351: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3352: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3353: my $itemcount = 1;
1.192 raeburn 3354: my %choices = &Apache::lonlocal::texthash (
3355: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3356: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3357: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3358: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3359: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3360: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3361: postsubmit => 'Disable submit button/keypress following student submission',
1.276 ! raeburn 3362: canclone => "People who may clone a course (besides course's owner and coordinators)",
! 3363: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 3364: );
1.198 raeburn 3365: my %staticdefaults = (
3366: anonsurvey_threshold => 10,
3367: uploadquota => 500,
1.257 raeburn 3368: postsubmit => 60,
1.276 ! raeburn 3369: mysqltables => 172800,
1.198 raeburn 3370: );
1.139 raeburn 3371: if ($position eq 'top') {
1.257 raeburn 3372: %defaultchecked = (
3373: 'canuse_pdfforms' => 'off',
3374: 'uselcmath' => 'on',
3375: 'usejsme' => 'on',
1.264 raeburn 3376: 'canclone' => 'none',
1.257 raeburn 3377: );
3378: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3379: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3380: \%choices,$itemcount);
1.264 raeburn 3381: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3382: $datatable .=
3383: '<tr'.$css_class.'><td valign="top">'.
3384: '<span class="LC_nobreak">'.$choices{'canclone'}.
3385: '</span></td><td class="LC_left_item">';
3386: my $currcanclone = 'none';
3387: my $onclick;
3388: my @cloneoptions = ('none','domain');
3389: my %clonetitles = (
3390: none => 'No additional course requesters',
3391: domain => "Any course requester in course's domain",
3392: instcode => 'Course requests for official courses ...',
3393: );
3394: my (%codedefaults,@code_order,@posscodes);
3395: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3396: \@code_order) eq 'ok') {
3397: if (@code_order > 0) {
3398: push(@cloneoptions,'instcode');
3399: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3400: }
3401: }
3402: if (ref($settings) eq 'HASH') {
3403: if ($settings->{'canclone'}) {
3404: if (ref($settings->{'canclone'}) eq 'HASH') {
3405: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3406: if (@code_order > 0) {
3407: $currcanclone = 'instcode';
3408: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3409: }
3410: }
3411: } elsif ($settings->{'canclone'} eq 'domain') {
3412: $currcanclone = $settings->{'canclone'};
3413: }
3414: }
3415: }
3416: foreach my $option (@cloneoptions) {
3417: my ($checked,$additional);
3418: if ($currcanclone eq $option) {
3419: $checked = ' checked="checked"';
3420: }
3421: if ($option eq 'instcode') {
3422: if (@code_order) {
3423: my $show = 'none';
3424: if ($checked) {
3425: $show = 'block';
3426: }
3427: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3428: &mt('Institutional codes for new and cloned course have identical:').
3429: '<br />';
3430: foreach my $item (@code_order) {
3431: my $codechk;
3432: if ($checked) {
3433: if (grep(/^\Q$item\E$/,@posscodes)) {
3434: $codechk = ' checked="checked"';
3435: }
3436: }
3437: $additional .= '<label>'.
3438: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3439: $item.'</label>';
3440: }
3441: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3442: }
3443: }
3444: $datatable .=
3445: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3446: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3447: '</label> '.$additional.'</span><br />';
3448: }
3449: $datatable .= '</td>'.
3450: '</tr>';
3451: $itemcount ++;
1.139 raeburn 3452: } else {
3453: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 ! raeburn 3454: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 3455: my $currusecredits = 0;
1.257 raeburn 3456: my $postsubmitclient = 1;
1.271 raeburn 3457: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3458: if (ref($settings) eq 'HASH') {
3459: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3460: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3461: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3462: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3463: }
3464: }
1.192 raeburn 3465: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3466: foreach my $type (@types) {
3467: next if ($type eq 'community');
3468: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3469: if ($defcredits{$type} ne '') {
3470: $currusecredits = 1;
3471: }
3472: }
3473: }
3474: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3475: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3476: $postsubmitclient = 0;
3477: foreach my $type (@types) {
3478: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3479: }
3480: } else {
3481: foreach my $type (@types) {
3482: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3483: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3484: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3485: } else {
3486: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3487: }
3488: } else {
3489: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3490: }
3491: }
3492: }
3493: } else {
3494: foreach my $type (@types) {
3495: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3496: }
3497: }
1.276 ! raeburn 3498: if (ref($settings->{'mysqltables'}) eq 'HASH') {
! 3499: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
! 3500: $currmysql{$type} = $settings->{'mysqltables'}{$type};
! 3501: }
! 3502: } else {
! 3503: foreach my $type (@types) {
! 3504: $currmysql{$type} = $staticdefaults{'mysqltables'};
! 3505: }
! 3506: }
1.258 raeburn 3507: } else {
3508: foreach my $type (@types) {
3509: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3510: }
1.139 raeburn 3511: }
3512: if (!$currdefresponder) {
1.198 raeburn 3513: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3514: } elsif ($currdefresponder < 1) {
3515: $currdefresponder = 1;
3516: }
1.198 raeburn 3517: foreach my $type (@types) {
3518: if ($curruploadquota{$type} eq '') {
3519: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3520: }
3521: }
1.139 raeburn 3522: $datatable .=
1.192 raeburn 3523: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3524: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3525: '</span></td>'.
3526: '<td class="LC_right_item"><span class="LC_nobreak">'.
3527: '<input type="text" name="anonsurvey_threshold"'.
3528: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3529: '</td></tr>'."\n";
3530: $itemcount ++;
3531: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3532: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3533: $choices{'uploadquota'}.
3534: '</span></td>'.
3535: '<td align="right" class="LC_right_item">'.
3536: '<table><tr>';
1.198 raeburn 3537: foreach my $type (@types) {
3538: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3539: '<input type="text" name="uploadquota_'.$type.'"'.
3540: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3541: }
3542: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3543: $itemcount ++;
1.236 raeburn 3544: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3545: my $display = 'none';
1.192 raeburn 3546: if ($currusecredits) {
3547: $display = 'block';
3548: }
3549: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3550: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3551: foreach my $type (@types) {
3552: next if ($type eq 'community');
3553: $additional .= '<td align="center">'.&mt($type).'<br />'.
3554: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3555: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3556: }
3557: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3558: %defaultchecked = ('coursecredits' => 'off');
3559: @toggles = ('coursecredits');
3560: my $current = {
3561: 'coursecredits' => $currusecredits,
3562: };
3563: (my $table,$itemcount) =
3564: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3565: \%choices,$itemcount,$onclick,$additional,'left');
3566: $datatable .= $table;
3567: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3568: my $display = 'none';
3569: if ($postsubmitclient) {
3570: $display = 'block';
3571: }
3572: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3573: &mt('Number of seconds submit is disabled').'<br />'.
3574: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3575: '<table><tr>';
1.257 raeburn 3576: foreach my $type (@types) {
3577: $additional .= '<td align="center">'.&mt($type).'<br />'.
3578: '<input type="text" name="'.$type.'_timeout" value="'.
3579: $deftimeout{$type}.'" size="5" /></td>';
3580: }
3581: $additional .= '</tr></table></div>'."\n";
3582: %defaultchecked = ('postsubmit' => 'on');
3583: @toggles = ('postsubmit');
3584: my $current = {
3585: 'postsubmit' => $postsubmitclient,
3586: };
3587: ($table,$itemcount) =
3588: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3589: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3590: $datatable .= $table;
1.276 ! raeburn 3591: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 3592: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
! 3593: $choices{'mysqltables'}.
! 3594: '</span></td>'.
! 3595: '<td align="right" class="LC_right_item">'.
! 3596: '<table><tr>';
! 3597: foreach my $type (@types) {
! 3598: $datatable .= '<td align="center">'.&mt($type).'<br />'.
! 3599: '<input type="text" name="mysqltables_'.$type.'"'.
! 3600: ' value="'.$currmysql{$type}.'" size="5" /></td>';
! 3601: }
! 3602: $datatable .= '</tr></table></td></tr>'."\n";
! 3603: $itemcount ++;
! 3604:
1.139 raeburn 3605: }
1.192 raeburn 3606: $$rowtotal += $itemcount;
1.121 raeburn 3607: return $datatable;
1.118 jms 3608: }
3609:
1.231 raeburn 3610: sub print_selfenrollment {
3611: my ($position,$dom,$settings,$rowtotal) = @_;
3612: my ($css_class,$datatable);
3613: my $itemcount = 1;
1.271 raeburn 3614: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3615: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3616: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3617: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3618: my @rows;
3619: my $key;
3620: if ($position eq 'top') {
3621: $key = 'admin';
3622: if (ref($rowsref) eq 'ARRAY') {
3623: @rows = @{$rowsref};
3624: }
3625: } elsif ($position eq 'middle') {
3626: $key = 'default';
3627: @rows = ('types','registered','approval','limit');
3628: }
3629: foreach my $row (@rows) {
3630: if (defined($titlesref->{$row})) {
3631: $itemcount ++;
3632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3633: $datatable .= '<tr'.$css_class.'>'.
3634: '<td>'.$titlesref->{$row}.'</td>'.
3635: '<td class="LC_left_item">'.
3636: '<table><tr>';
3637: my (%current,%currentcap);
3638: if (ref($settings) eq 'HASH') {
3639: if (ref($settings->{$key}) eq 'HASH') {
3640: foreach my $type (@types) {
3641: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3642: $current{$type} = $settings->{$key}->{$type}->{$row};
3643: }
3644: if (($row eq 'limit') && ($key eq 'default')) {
3645: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3646: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3647: }
3648: }
3649: }
3650: }
3651: }
3652: my %roles = (
3653: '0' => &Apache::lonnet::plaintext('dc'),
3654: );
3655:
3656: foreach my $type (@types) {
3657: unless (($row eq 'registered') && ($key eq 'default')) {
3658: $datatable .= '<th>'.&mt($type).'</th>';
3659: }
3660: }
3661: unless (($row eq 'registered') && ($key eq 'default')) {
3662: $datatable .= '</tr><tr>';
3663: }
3664: foreach my $type (@types) {
3665: if ($type eq 'community') {
3666: $roles{'1'} = &mt('Community personnel');
3667: } else {
3668: $roles{'1'} = &mt('Course personnel');
3669: }
3670: $datatable .= '<td style="vertical-align: top">';
3671: if ($position eq 'top') {
3672: my %checked;
3673: if ($current{$type} eq '0') {
3674: $checked{'0'} = ' checked="checked"';
3675: } else {
3676: $checked{'1'} = ' checked="checked"';
3677: }
3678: foreach my $role ('1','0') {
3679: $datatable .= '<span class="LC_nobreak"><label>'.
3680: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3681: 'value="'.$role.'"'.$checked{$role}.' />'.
3682: $roles{$role}.'</label></span> ';
3683: }
3684: } else {
3685: if ($row eq 'types') {
3686: my %checked;
3687: if ($current{$type} =~ /^(all|dom)$/) {
3688: $checked{$1} = ' checked="checked"';
3689: } else {
3690: $checked{''} = ' checked="checked"';
3691: }
3692: foreach my $val ('','dom','all') {
3693: $datatable .= '<span class="LC_nobreak"><label>'.
3694: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3695: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3696: }
3697: } elsif ($row eq 'registered') {
3698: my %checked;
3699: if ($current{$type} eq '1') {
3700: $checked{'1'} = ' checked="checked"';
3701: } else {
3702: $checked{'0'} = ' checked="checked"';
3703: }
3704: foreach my $val ('0','1') {
3705: $datatable .= '<span class="LC_nobreak"><label>'.
3706: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3707: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3708: }
3709: } elsif ($row eq 'approval') {
3710: my %checked;
3711: if ($current{$type} =~ /^([12])$/) {
3712: $checked{$1} = ' checked="checked"';
3713: } else {
3714: $checked{'0'} = ' checked="checked"';
3715: }
3716: for my $val (0..2) {
3717: $datatable .= '<span class="LC_nobreak"><label>'.
3718: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3719: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3720: }
3721: } elsif ($row eq 'limit') {
3722: my %checked;
3723: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3724: $checked{$1} = ' checked="checked"';
3725: } else {
3726: $checked{'none'} = ' checked="checked"';
3727: }
3728: my $cap;
3729: if ($currentcap{$type} =~ /^\d+$/) {
3730: $cap = $currentcap{$type};
3731: }
3732: foreach my $val ('none','allstudents','selfenrolled') {
3733: $datatable .= '<span class="LC_nobreak"><label>'.
3734: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3735: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3736: }
3737: $datatable .= '<br />'.
3738: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3739: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3740: '</span>';
3741: }
3742: }
3743: $datatable .= '</td>';
3744: }
3745: $datatable .= '</tr>';
3746: }
3747: $datatable .= '</table></td></tr>';
3748: }
3749: } elsif ($position eq 'bottom') {
1.235 raeburn 3750: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3751: }
3752: $$rowtotal += $itemcount;
3753: return $datatable;
3754: }
3755:
3756: sub print_validation_rows {
3757: my ($caller,$dom,$settings,$rowtotal) = @_;
3758: my ($itemsref,$namesref,$fieldsref);
3759: if ($caller eq 'selfenroll') {
3760: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3761: } elsif ($caller eq 'requestcourses') {
3762: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3763: }
3764: my %currvalidation;
3765: if (ref($settings) eq 'HASH') {
3766: if (ref($settings->{'validation'}) eq 'HASH') {
3767: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3768: }
1.235 raeburn 3769: }
3770: my $datatable;
3771: my $itemcount = 0;
3772: foreach my $item (@{$itemsref}) {
3773: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3774: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3775: $namesref->{$item}.
3776: '</span></td>'.
3777: '<td class="LC_left_item">';
3778: if (($item eq 'url') || ($item eq 'button')) {
3779: $datatable .= '<span class="LC_nobreak">'.
3780: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3781: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3782: } elsif ($item eq 'fields') {
3783: my @currfields;
3784: if (ref($currvalidation{$item}) eq 'ARRAY') {
3785: @currfields = @{$currvalidation{$item}};
3786: }
3787: foreach my $field (@{$fieldsref}) {
3788: my $check = '';
3789: if (grep(/^\Q$field\E$/,@currfields)) {
3790: $check = ' checked="checked"';
3791: }
3792: $datatable .= '<span class="LC_nobreak"><label>'.
3793: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3794: ' value="'.$field.'"'.$check.' />'.$field.
3795: '</label></span> ';
3796: }
3797: } elsif ($item eq 'markup') {
3798: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3799: $currvalidation{$item}.
1.231 raeburn 3800: '</textarea>';
1.235 raeburn 3801: }
3802: $datatable .= '</td></tr>'."\n";
3803: if (ref($rowtotal)) {
1.231 raeburn 3804: $itemcount ++;
3805: }
3806: }
1.235 raeburn 3807: if ($caller eq 'requestcourses') {
3808: my %currhash;
1.248 raeburn 3809: if (ref($settings) eq 'HASH') {
3810: if (ref($settings->{'validation'}) eq 'HASH') {
3811: if ($settings->{'validation'}{'dc'} ne '') {
3812: $currhash{$settings->{'validation'}{'dc'}} = 1;
3813: }
1.235 raeburn 3814: }
3815: }
3816: my $numinrow = 2;
3817: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3818: 'validationdc',%currhash);
1.247 raeburn 3819: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3820: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3821: if ($numdc > 1) {
1.247 raeburn 3822: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3823: } else {
1.247 raeburn 3824: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3825: }
1.247 raeburn 3826: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3827: $itemcount ++;
3828: }
3829: if (ref($rowtotal)) {
3830: $$rowtotal += $itemcount;
3831: }
1.231 raeburn 3832: return $datatable;
3833: }
3834:
1.137 raeburn 3835: sub print_usersessions {
3836: my ($position,$dom,$settings,$rowtotal) = @_;
3837: my ($css_class,$datatable,%checked,%choices);
1.275 raeburn 3838: my (%by_ip,%by_location,@intdoms,@instdoms);
3839: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 3840:
3841: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3842: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3843: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3844: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3845: my $itemcount = 1;
3846: if ($position eq 'top') {
1.152 raeburn 3847: if (keys(%serverhomes) > 1) {
1.145 raeburn 3848: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3849: my $curroffloadnow;
3850: if (ref($settings) eq 'HASH') {
3851: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3852: $curroffloadnow = $settings->{'offloadnow'};
3853: }
3854: }
3855: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3856: } else {
1.140 raeburn 3857: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3858: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3859: }
1.137 raeburn 3860: } else {
1.145 raeburn 3861: if (keys(%by_location) == 0) {
3862: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3863: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3864: } else {
3865: my %lt = &usersession_titles();
3866: my $numinrow = 5;
3867: my $prefix;
3868: my @types;
3869: if ($position eq 'bottom') {
3870: $prefix = 'remote';
3871: @types = ('version','excludedomain','includedomain');
3872: } else {
3873: $prefix = 'hosted';
3874: @types = ('excludedomain','includedomain');
3875: }
3876: my (%current,%checkedon,%checkedoff);
3877: my @lcversions = &Apache::lonnet::all_loncaparevs();
3878: my @locations = sort(keys(%by_location));
3879: foreach my $type (@types) {
3880: $checkedon{$type} = '';
3881: $checkedoff{$type} = ' checked="checked"';
3882: }
3883: if (ref($settings) eq 'HASH') {
3884: if (ref($settings->{$prefix}) eq 'HASH') {
3885: foreach my $key (keys(%{$settings->{$prefix}})) {
3886: $current{$key} = $settings->{$prefix}{$key};
3887: if ($key eq 'version') {
3888: if ($current{$key} ne '') {
3889: $checkedon{$key} = ' checked="checked"';
3890: $checkedoff{$key} = '';
3891: }
3892: } elsif (ref($current{$key}) eq 'ARRAY') {
3893: $checkedon{$key} = ' checked="checked"';
3894: $checkedoff{$key} = '';
3895: }
1.137 raeburn 3896: }
3897: }
3898: }
1.145 raeburn 3899: foreach my $type (@types) {
3900: next if ($type ne 'version' && !@locations);
3901: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3902: $datatable .= '<tr'.$css_class.'>
3903: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3904: <span class="LC_nobreak">
3905: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3906: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3907: if ($type eq 'version') {
3908: my $selector = '<select name="'.$prefix.'_version">';
3909: foreach my $version (@lcversions) {
3910: my $selected = '';
3911: if ($current{'version'} eq $version) {
3912: $selected = ' selected="selected"';
3913: }
3914: $selector .= ' <option value="'.$version.'"'.
3915: $selected.'>'.$version.'</option>';
3916: }
3917: $selector .= '</select> ';
3918: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3919: } else {
3920: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3921: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3922: ' />'.(' 'x2).
3923: '<input type="button" value="'.&mt('uncheck all').'" '.
3924: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3925: "\n".
3926: '</div><div><table>';
3927: my $rem;
3928: for (my $i=0; $i<@locations; $i++) {
3929: my ($showloc,$value,$checkedtype);
3930: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3931: my $ip = $by_location{$locations[$i]}->[0];
3932: if (ref($by_ip{$ip}) eq 'ARRAY') {
3933: $value = join(':',@{$by_ip{$ip}});
3934: $showloc = join(', ',@{$by_ip{$ip}});
3935: if (ref($current{$type}) eq 'ARRAY') {
3936: foreach my $loc (@{$by_ip{$ip}}) {
3937: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3938: $checkedtype = ' checked="checked"';
3939: last;
3940: }
3941: }
1.138 raeburn 3942: }
3943: }
3944: }
1.145 raeburn 3945: $rem = $i%($numinrow);
3946: if ($rem == 0) {
3947: if ($i > 0) {
3948: $datatable .= '</tr>';
3949: }
3950: $datatable .= '<tr>';
3951: }
3952: $datatable .= '<td class="LC_left_item">'.
3953: '<span class="LC_nobreak"><label>'.
3954: '<input type="checkbox" name="'.$prefix.'_'.$type.
3955: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3956: '</label></span></td>';
1.137 raeburn 3957: }
1.145 raeburn 3958: $rem = @locations%($numinrow);
3959: my $colsleft = $numinrow - $rem;
3960: if ($colsleft > 1 ) {
3961: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3962: ' </td>';
3963: } elsif ($colsleft == 1) {
3964: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3965: }
1.145 raeburn 3966: $datatable .= '</tr></table>';
1.137 raeburn 3967: }
1.145 raeburn 3968: $datatable .= '</td></tr>';
3969: $itemcount ++;
1.137 raeburn 3970: }
3971: }
3972: }
3973: $$rowtotal += $itemcount;
3974: return $datatable;
3975: }
3976:
1.275 raeburn 3977: sub print_ssl {
3978: my ($position,$dom,$settings,$rowtotal) = @_;
3979: my ($css_class,$datatable);
3980: my $lonhost = '';
3981: my $itemcount = 1;
3982: if ($position eq 'top') {
3983: my %domservers = &Apache::lonnet::get_servers($dom);
3984: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3985: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
3986: &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs').
3987: '</td></tr>';
3988: $itemcount ++;
3989: } else {
3990: my %titles = &ssl_titles();
3991: my (%by_ip,%by_location,@intdoms,@instdoms);
3992: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
3993: my @alldoms = &Apache::lonnet::all_domains();
3994: my %serverhomes = %Apache::lonnet::serverhomeIDs;
3995: my @domservers = &Apache::lonnet::get_servers($dom);
3996: my %servers = &Apache::lonnet::internet_dom_servers($dom);
3997: my %altids = &id_for_thisdom(%servers);
3998: if ($position eq 'middle') {
3999: foreach my $type ('dom','intdom','other') {
4000: my %checked;
4001: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4002: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4003: '<td class="LC_right_item">';
4004: my $skip;
4005: if ($type eq 'dom') {
4006: unless (keys(%servers) > 1) {
4007: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4008: $skip = 1;
4009: }
4010: }
4011: if ($type eq 'intdom') {
4012: unless (@instdoms > 1) {
4013: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4014: $skip = 1;
4015: }
4016: } elsif ($type eq 'other') {
4017: if (keys(%by_location) == 0) {
4018: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4019: $skip = 1;
4020: }
4021: }
4022: unless ($skip) {
4023: $checked{'yes'} = ' checked="checked"';
4024: if (ref($settings) eq 'HASH') {
4025: if (ref($settings->{'connect'}) eq 'HASH') {
4026: if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
4027: $checked{$1} = $checked{'yes'};
4028: delete($checked{'yes'});
4029: }
4030: }
4031: }
4032: foreach my $option ('no','yes','req') {
4033: $datatable .= '<span class="LC_nobreak"><label>'.
4034: '<input type="radio" name="connect_'.$type.'" '.
4035: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4036: '</label></span>'.(' 'x2);
4037: }
4038: }
4039: $datatable .= '</td></tr>';
4040: $itemcount ++;
4041: }
4042: } else {
4043: my $numinrow = 5;
4044: my $prefix = 'replication';
4045: my @types = ('certreq','nocertreq');
4046: my (%current,%checkedon,%checkedoff);
4047: my @locations = sort(keys(%by_location));
4048: foreach my $type (@types) {
4049: $checkedon{$type} = '';
4050: $checkedoff{$type} = ' checked="checked"';
4051: }
4052: if (ref($settings) eq 'HASH') {
4053: if (ref($settings->{$prefix}) eq 'HASH') {
4054: foreach my $key (keys(%{$settings->{$prefix}})) {
4055: $current{$key} = $settings->{$prefix}{$key};
4056: if (ref($current{$key}) eq 'ARRAY') {
4057: $checkedon{$key} = ' checked="checked"';
4058: $checkedoff{$key} = '';
4059: }
4060: }
4061: }
4062: }
4063: if (@locations > 0) {
4064: foreach my $type (@types) {
4065: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4066: $datatable .= '<tr'.$css_class.'>
4067: <td><span class="LC_nobreak LC_right_item">'.$titles{$type}.'</span><br />
4068: <span class="LC_nobreak">
4069: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4070: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>
4071: <div><input type="button" value="'.&mt('check all').'" '.
4072: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4073: ' />'.(' 'x2)."\n".
4074: '<input type="button" value="'.&mt('uncheck all').'" '.
4075: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4076: "\n".
4077: '</div><div><table>';
4078: my $rem;
4079: for (my $i=0; $i<@locations; $i++) {
4080: my ($showloc,$value,$checkedtype);
4081: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4082: my $ip = $by_location{$locations[$i]}->[0];
4083: if (ref($by_ip{$ip}) eq 'ARRAY') {
4084: $value = join(':',@{$by_ip{$ip}});
4085: $showloc = join(', ',@{$by_ip{$ip}});
4086: if (ref($current{$type}) eq 'ARRAY') {
4087: foreach my $loc (@{$by_ip{$ip}}) {
4088: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4089: $checkedtype = ' checked="checked"';
4090: last;
4091: }
4092: }
4093: }
4094: }
4095: }
4096: $rem = $i%($numinrow);
4097: if ($rem == 0) {
4098: if ($i > 0) {
4099: $datatable .= '</tr>';
4100: }
4101: $datatable .= '<tr>';
4102: }
4103: $datatable .= '<td class="LC_left_item">'.
4104: '<span class="LC_nobreak"><label>'.
4105: '<input type="checkbox" name="'.$prefix.'_'.$type.
4106: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4107: '</label></span></td>';
4108: }
4109: $rem = @locations%($numinrow);
4110: my $colsleft = $numinrow - $rem;
4111: if ($colsleft > 1 ) {
4112: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4113: ' </td>';
4114: } elsif ($colsleft == 1) {
4115: $datatable .= '<td class="LC_left_item"> </td>';
4116: }
4117: $datatable .= '</tr></table></td></tr>';
4118: $itemcount ++;
4119: }
4120: } else {
4121: $datatable .= '<tr'.$css_class.'><td>'.&mt('Nothing to set here, as there are no other institutions').'</td></tr>';
4122: $itemcount ++;
4123: }
4124: }
4125: }
4126: $$rowtotal += $itemcount;
4127: return $datatable;
4128: }
4129:
4130: sub ssl_titles {
4131: return &Apache::lonlocal::texthash (
4132: dom => 'LON-CAPA servers/VMs from same domain',
4133: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4134: other => 'External LON-CAPA servers/VMs',
4135: connect => 'Connections to other servers',
4136: replication => 'Replicating content to other institutions',
4137: certreq => 'Client certificate required, but specific domains exempt',
4138: nocertreq => 'No client certificate required, except for specific domains',
4139: no => 'SSL not used',
4140: yes => 'SSL Optional (used if available)',
4141: req => 'SSL Required',
4142: );
4143: }
4144:
1.138 raeburn 4145: sub build_location_hashes {
1.275 raeburn 4146: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4147: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4148: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4149: my %iphost = &Apache::lonnet::get_iphost();
4150: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4151: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4152: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4153: foreach my $id (@{$iphost{$primary_ip}}) {
4154: my $intdom = &Apache::lonnet::internet_dom($id);
4155: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4156: push(@{$intdoms},$intdom);
4157: }
4158: }
4159: }
4160: foreach my $ip (keys(%iphost)) {
4161: if (ref($iphost{$ip}) eq 'ARRAY') {
4162: foreach my $id (@{$iphost{$ip}}) {
4163: my $location = &Apache::lonnet::internet_dom($id);
4164: if ($location) {
1.275 raeburn 4165: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4166: my $dom = &Apache::lonnet::host_domain($id);
4167: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4168: push(@{$instdoms},$dom);
4169: }
4170: next;
4171: }
1.138 raeburn 4172: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4173: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4174: push(@{$by_ip->{$ip}},$location);
4175: }
4176: } else {
4177: $by_ip->{$ip} = [$location];
4178: }
4179: }
4180: }
4181: }
4182: }
4183: foreach my $ip (sort(keys(%{$by_ip}))) {
4184: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4185: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4186: my $first = $by_ip->{$ip}->[0];
4187: if (ref($by_location->{$first}) eq 'ARRAY') {
4188: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4189: push(@{$by_location->{$first}},$ip);
4190: }
4191: } else {
4192: $by_location->{$first} = [$ip];
4193: }
4194: }
4195: }
4196: return;
4197: }
4198:
1.145 raeburn 4199: sub current_offloads_to {
4200: my ($dom,$settings,$servers) = @_;
4201: my (%spareid,%otherdomconfigs);
1.152 raeburn 4202: if (ref($servers) eq 'HASH') {
1.145 raeburn 4203: foreach my $lonhost (sort(keys(%{$servers}))) {
4204: my $gotspares;
1.152 raeburn 4205: if (ref($settings) eq 'HASH') {
4206: if (ref($settings->{'spares'}) eq 'HASH') {
4207: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4208: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4209: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4210: $gotspares = 1;
4211: }
1.145 raeburn 4212: }
4213: }
4214: unless ($gotspares) {
4215: my $gotspares;
4216: my $serverhomeID =
4217: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4218: my $serverhomedom =
4219: &Apache::lonnet::host_domain($serverhomeID);
4220: if ($serverhomedom ne $dom) {
4221: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4222: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4223: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4224: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4225: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4226: $gotspares = 1;
4227: }
4228: }
4229: } else {
4230: $otherdomconfigs{$serverhomedom} =
4231: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4232: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4233: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4234: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4235: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4236: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4237: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4238: $gotspares = 1;
4239: }
4240: }
4241: }
4242: }
4243: }
4244: }
4245: }
4246: unless ($gotspares) {
4247: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4248: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4249: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4250: } else {
4251: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4252: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4253: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4254: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4255: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4256: } else {
1.150 raeburn 4257: my %what = (
4258: spareid => 1,
4259: );
4260: my ($result,$returnhash) =
4261: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4262: if ($result eq 'ok') {
4263: if (ref($returnhash) eq 'HASH') {
4264: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4265: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4266: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4267: }
4268: }
1.145 raeburn 4269: }
4270: }
4271: }
4272: }
4273: }
4274: }
4275: return %spareid;
4276: }
4277:
4278: sub spares_row {
1.261 raeburn 4279: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4280: my $css_class;
4281: my $numinrow = 4;
4282: my $itemcount = 1;
4283: my $datatable;
1.152 raeburn 4284: my %typetitles = &sparestype_titles();
4285: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4286: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4287: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4288: my ($othercontrol,$serverdom);
4289: if ($serverhome ne $server) {
4290: $serverdom = &Apache::lonnet::host_domain($serverhome);
4291: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4292: } else {
4293: $serverdom = &Apache::lonnet::host_domain($server);
4294: if ($serverdom ne $dom) {
4295: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4296: }
4297: }
4298: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4299: my $checkednow;
4300: if (ref($curroffloadnow) eq 'HASH') {
4301: if ($curroffloadnow->{$server}) {
4302: $checkednow = ' checked="checked"';
4303: }
4304: }
1.145 raeburn 4305: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4306: $datatable .= '<tr'.$css_class.'>
4307: <td rowspan="2">
1.183 bisitz 4308: <span class="LC_nobreak">'.
4309: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4310: ,'<b>'.$server.'</b>').'</span><br />'.
4311: '<span class="LC_nobreak">'."\n".
4312: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4313: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4314: "\n";
1.145 raeburn 4315: my (%current,%canselect);
1.152 raeburn 4316: my @choices =
4317: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4318: foreach my $type ('primary','default') {
4319: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4320: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4321: my @spares = @{$spareid->{$server}{$type}};
4322: if (@spares > 0) {
1.152 raeburn 4323: if ($othercontrol) {
4324: $current{$type} = join(', ',@spares);
4325: } else {
4326: $current{$type} .= '<table>';
4327: my $numspares = scalar(@spares);
4328: for (my $i=0; $i<@spares; $i++) {
4329: my $rem = $i%($numinrow);
4330: if ($rem == 0) {
4331: if ($i > 0) {
4332: $current{$type} .= '</tr>';
4333: }
4334: $current{$type} .= '<tr>';
1.145 raeburn 4335: }
1.152 raeburn 4336: $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'".');" /> '.
4337: $spareid->{$server}{$type}[$i].
4338: '</label></td>'."\n";
4339: }
4340: my $rem = @spares%($numinrow);
4341: my $colsleft = $numinrow - $rem;
4342: if ($colsleft > 1 ) {
4343: $current{$type} .= '<td colspan="'.$colsleft.
4344: '" class="LC_left_item">'.
4345: ' </td>';
4346: } elsif ($colsleft == 1) {
4347: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4348: }
1.152 raeburn 4349: $current{$type} .= '</tr></table>';
1.150 raeburn 4350: }
1.145 raeburn 4351: }
4352: }
4353: if ($current{$type} eq '') {
4354: $current{$type} = &mt('None specified');
4355: }
1.152 raeburn 4356: if ($othercontrol) {
4357: if ($type eq 'primary') {
4358: $canselect{$type} = $othercontrol;
4359: }
4360: } else {
4361: $canselect{$type} =
4362: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4363: '<select name="newspare_'.$type.'_'.$server.'" '.
4364: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4365: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4366: if (@choices > 0) {
4367: foreach my $lonhost (@choices) {
4368: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4369: }
4370: }
4371: $canselect{$type} .= '</select>'."\n";
4372: }
4373: } else {
4374: $current{$type} = &mt('Could not be determined');
4375: if ($type eq 'primary') {
4376: $canselect{$type} = $othercontrol;
4377: }
1.145 raeburn 4378: }
1.152 raeburn 4379: if ($type eq 'default') {
4380: $datatable .= '<tr'.$css_class.'>';
4381: }
4382: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4383: '<td>'.$current{$type}.'</td>'."\n".
4384: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4385: }
4386: $itemcount ++;
4387: }
4388: }
4389: $$rowtotal += $itemcount;
4390: return $datatable;
4391: }
4392:
1.152 raeburn 4393: sub possible_newspares {
4394: my ($server,$currspares,$serverhomes,$altids) = @_;
4395: my $serverhostname = &Apache::lonnet::hostname($server);
4396: my %excluded;
4397: if ($serverhostname ne '') {
4398: %excluded = (
4399: $serverhostname => 1,
4400: );
4401: }
4402: if (ref($currspares) eq 'HASH') {
4403: foreach my $type (keys(%{$currspares})) {
4404: if (ref($currspares->{$type}) eq 'ARRAY') {
4405: if (@{$currspares->{$type}} > 0) {
4406: foreach my $curr (@{$currspares->{$type}}) {
4407: my $hostname = &Apache::lonnet::hostname($curr);
4408: $excluded{$hostname} = 1;
4409: }
4410: }
4411: }
4412: }
4413: }
4414: my @choices;
4415: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4416: if (keys(%{$serverhomes}) > 1) {
4417: foreach my $name (sort(keys(%{$serverhomes}))) {
4418: unless ($excluded{$name}) {
4419: if (exists($altids->{$serverhomes->{$name}})) {
4420: push(@choices,$altids->{$serverhomes->{$name}});
4421: } else {
4422: push(@choices,$serverhomes->{$name});
1.145 raeburn 4423: }
4424: }
4425: }
4426: }
4427: }
1.152 raeburn 4428: return sort(@choices);
1.145 raeburn 4429: }
4430:
1.150 raeburn 4431: sub print_loadbalancing {
4432: my ($dom,$settings,$rowtotal) = @_;
4433: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4434: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4435: my $numinrow = 1;
4436: my $datatable;
4437: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4438: my (%currbalancer,%currtargets,%currrules,%existing);
4439: if (ref($settings) eq 'HASH') {
4440: %existing = %{$settings};
4441: }
4442: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4443: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4444: \%currtargets,\%currrules);
1.150 raeburn 4445: } else {
4446: return;
4447: }
4448: my ($othertitle,$usertypes,$types) =
4449: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4450: my $rownum = 8;
1.150 raeburn 4451: if (ref($types) eq 'ARRAY') {
4452: $rownum += scalar(@{$types});
4453: }
1.171 raeburn 4454: my @css_class = ('LC_odd_row','LC_even_row');
4455: my $balnum = 0;
4456: my $islast;
4457: my (@toshow,$disabledtext);
4458: if (keys(%currbalancer) > 0) {
4459: @toshow = sort(keys(%currbalancer));
4460: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4461: push(@toshow,'');
4462: }
4463: } else {
4464: @toshow = ('');
4465: $disabledtext = &mt('No existing load balancer');
4466: }
4467: foreach my $lonhost (@toshow) {
4468: if ($balnum == scalar(@toshow)-1) {
4469: $islast = 1;
4470: } else {
4471: $islast = 0;
4472: }
4473: my $cssidx = $balnum%2;
4474: my $targets_div_style = 'display: none';
4475: my $disabled_div_style = 'display: block';
4476: my $homedom_div_style = 'display: none';
4477: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4478: '<td rowspan="'.$rownum.'" valign="top">'.
4479: '<p>';
4480: if ($lonhost eq '') {
1.210 raeburn 4481: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4482: if (keys(%currbalancer) > 0) {
4483: $datatable .= &mt('Add balancer:');
4484: } else {
4485: $datatable .= &mt('Enable balancer:');
4486: }
4487: $datatable .= ' '.
4488: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4489: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4490: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4491: '<option value="" selected="selected">'.&mt('None').
4492: '</option>'."\n";
4493: foreach my $server (sort(keys(%servers))) {
4494: next if ($currbalancer{$server});
4495: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4496: }
1.210 raeburn 4497: $datatable .=
1.171 raeburn 4498: '</select>'."\n".
4499: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4500: } else {
4501: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4502: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4503: &mt('Stop balancing').'</label>'.
4504: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4505: $targets_div_style = 'display: block';
4506: $disabled_div_style = 'display: none';
4507: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4508: $homedom_div_style = 'display: block';
4509: }
4510: }
4511: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4512: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4513: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4514: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4515: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4516: my @sparestypes = ('primary','default');
4517: my %typetitles = &sparestype_titles();
4518: foreach my $sparetype (@sparestypes) {
4519: my $targettable;
4520: for (my $i=0; $i<$numspares; $i++) {
4521: my $checked;
4522: if (ref($currtargets{$lonhost}) eq 'HASH') {
4523: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4524: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4525: $checked = ' checked="checked"';
4526: }
4527: }
4528: }
4529: my ($chkboxval,$disabled);
4530: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4531: $chkboxval = $spares[$i];
4532: }
4533: if (exists($currbalancer{$spares[$i]})) {
4534: $disabled = ' disabled="disabled"';
4535: }
1.210 raeburn 4536: $targettable .=
1.253 raeburn 4537: '<td><span class="LC_nobreak"><label>'.
4538: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4539: $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 4540: '</span></label></span></td>';
1.171 raeburn 4541: my $rem = $i%($numinrow);
4542: if ($rem == 0) {
4543: if (($i > 0) && ($i < $numspares-1)) {
4544: $targettable .= '</tr>';
4545: }
4546: if ($i < $numspares-1) {
4547: $targettable .= '<tr>';
1.150 raeburn 4548: }
4549: }
4550: }
1.171 raeburn 4551: if ($targettable ne '') {
4552: my $rem = $numspares%($numinrow);
4553: my $colsleft = $numinrow - $rem;
4554: if ($colsleft > 1 ) {
4555: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4556: ' </td>';
4557: } elsif ($colsleft == 1) {
4558: $targettable .= '<td class="LC_left_item"> </td>';
4559: }
4560: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4561: '<table><tr>'.$targettable.'</tr></table><br />';
4562: }
4563: }
4564: $datatable .= '</div></td></tr>'.
4565: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4566: $othertitle,$usertypes,$types,\%servers,
4567: \%currbalancer,$lonhost,
4568: $targets_div_style,$homedom_div_style,
4569: $css_class[$cssidx],$balnum,$islast);
4570: $$rowtotal += $rownum;
4571: $balnum ++;
4572: }
4573: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4574: return $datatable;
4575: }
4576:
4577: sub get_loadbalancers_config {
4578: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4579: return unless ((ref($servers) eq 'HASH') &&
4580: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4581: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4582: if (keys(%{$existing}) > 0) {
4583: my $oldlonhost;
4584: foreach my $key (sort(keys(%{$existing}))) {
4585: if ($key eq 'lonhost') {
4586: $oldlonhost = $existing->{'lonhost'};
4587: $currbalancer->{$oldlonhost} = 1;
4588: } elsif ($key eq 'targets') {
4589: if ($oldlonhost) {
4590: $currtargets->{$oldlonhost} = $existing->{'targets'};
4591: }
4592: } elsif ($key eq 'rules') {
4593: if ($oldlonhost) {
4594: $currrules->{$oldlonhost} = $existing->{'rules'};
4595: }
4596: } elsif (ref($existing->{$key}) eq 'HASH') {
4597: $currbalancer->{$key} = 1;
4598: $currtargets->{$key} = $existing->{$key}{'targets'};
4599: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4600: }
4601: }
1.171 raeburn 4602: } else {
4603: my ($balancerref,$targetsref) =
4604: &Apache::lonnet::get_lonbalancer_config($servers);
4605: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4606: foreach my $server (sort(keys(%{$balancerref}))) {
4607: $currbalancer->{$server} = 1;
4608: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4609: }
4610: }
4611: }
1.171 raeburn 4612: return;
1.150 raeburn 4613: }
4614:
4615: sub loadbalancing_rules {
4616: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4617: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4618: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4619: my $output;
1.171 raeburn 4620: my $num = 0;
1.210 raeburn 4621: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4622: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4623: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4624: foreach my $type (@{$alltypes}) {
1.171 raeburn 4625: $num ++;
1.150 raeburn 4626: my $current;
4627: if (ref($currrules) eq 'HASH') {
4628: $current = $currrules->{$type};
4629: }
1.253 raeburn 4630: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4631: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4632: $current = '';
4633: }
4634: }
4635: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4636: $servers,$currbalancer,$lonhost,$dom,
4637: $targets_div_style,$homedom_div_style,
4638: $css_class,$balnum,$num,$islast);
1.150 raeburn 4639: }
4640: }
4641: return $output;
4642: }
4643:
4644: sub loadbalancing_titles {
4645: my ($dom,$intdom,$usertypes,$types) = @_;
4646: my %othertypes = (
4647: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4648: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4649: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4650: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4651: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4652: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4653: );
1.209 raeburn 4654: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4655: if (ref($types) eq 'ARRAY') {
4656: unshift(@alltypes,@{$types},'default');
4657: }
4658: my %titles;
4659: foreach my $type (@alltypes) {
4660: if ($type =~ /^_LC_/) {
4661: $titles{$type} = $othertypes{$type};
4662: } elsif ($type eq 'default') {
4663: $titles{$type} = &mt('All users from [_1]',$dom);
4664: if (ref($types) eq 'ARRAY') {
4665: if (@{$types} > 0) {
4666: $titles{$type} = &mt('Other users from [_1]',$dom);
4667: }
4668: }
4669: } elsif (ref($usertypes) eq 'HASH') {
4670: $titles{$type} = $usertypes->{$type};
4671: }
4672: }
4673: return (\@alltypes,\%othertypes,\%titles);
4674: }
4675:
4676: sub loadbalance_rule_row {
1.171 raeburn 4677: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4678: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4679: my @rulenames;
1.150 raeburn 4680: my %ruletitles = &offloadtype_text();
1.209 raeburn 4681: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4682: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4683: } else {
1.209 raeburn 4684: @rulenames = ('default','homeserver');
4685: if ($type eq '_LC_external') {
4686: push(@rulenames,'externalbalancer');
4687: } else {
4688: push(@rulenames,'specific');
4689: }
4690: push(@rulenames,'none');
1.150 raeburn 4691: }
4692: my $style = $targets_div_style;
1.253 raeburn 4693: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4694: $style = $homedom_div_style;
4695: }
1.171 raeburn 4696: my $space;
4697: if ($islast && $num == 1) {
4698: $space = '<div display="inline-block"> </div>';
4699: }
1.210 raeburn 4700: my $output =
1.171 raeburn 4701: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4702: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4703: '<td valaign="top">'.$space.
4704: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4705: for (my $i=0; $i<@rulenames; $i++) {
4706: my $rule = $rulenames[$i];
4707: my ($checked,$extra);
4708: if ($rulenames[$i] eq 'default') {
4709: $rule = '';
4710: }
4711: if ($rulenames[$i] eq 'specific') {
4712: if (ref($servers) eq 'HASH') {
4713: my $default;
4714: if (($current ne '') && (exists($servers->{$current}))) {
4715: $checked = ' checked="checked"';
4716: }
4717: unless ($checked) {
4718: $default = ' selected="selected"';
4719: }
1.210 raeburn 4720: $extra =
1.171 raeburn 4721: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4722: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4723: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4724: '<option value=""'.$default.'></option>'."\n";
4725: foreach my $server (sort(keys(%{$servers}))) {
4726: if (ref($currbalancer) eq 'HASH') {
4727: next if (exists($currbalancer->{$server}));
4728: }
1.150 raeburn 4729: my $selected;
1.171 raeburn 4730: if ($server eq $current) {
1.150 raeburn 4731: $selected = ' selected="selected"';
4732: }
1.171 raeburn 4733: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4734: }
4735: $extra .= '</select>';
4736: }
4737: } elsif ($rule eq $current) {
4738: $checked = ' checked="checked"';
4739: }
4740: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4741: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4742: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4743: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4744: ')"'.$checked.' /> ';
4745: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4746: $output .= $ruletitles{'particular'};
4747: } else {
4748: $output .= $ruletitles{$rulenames[$i]};
4749: }
4750: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4751: }
4752: $output .= '</div></td></tr>'."\n";
4753: return $output;
4754: }
4755:
4756: sub offloadtype_text {
4757: my %ruletitles = &Apache::lonlocal::texthash (
4758: 'default' => 'Offloads to default destinations',
4759: 'homeserver' => "Offloads to user's home server",
4760: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4761: 'specific' => 'Offloads to specific server',
1.161 raeburn 4762: 'none' => 'No offload',
1.209 raeburn 4763: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4764: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4765: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4766: );
4767: return %ruletitles;
4768: }
4769:
4770: sub sparestype_titles {
4771: my %typestitles = &Apache::lonlocal::texthash (
4772: 'primary' => 'primary',
4773: 'default' => 'default',
4774: );
4775: return %typestitles;
4776: }
4777:
1.28 raeburn 4778: sub contact_titles {
4779: my %titles = &Apache::lonlocal::texthash (
4780: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4781: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4782: 'errormail' => 'Error reports to be e-mailed to',
4783: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4784: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4785: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4786: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4787: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4788: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4789: );
4790: my %short_titles = &Apache::lonlocal::texthash (
4791: adminemail => 'Admin E-mail address',
4792: supportemail => 'Support E-mail',
4793: );
4794: return (\%titles,\%short_titles);
4795: }
4796:
1.72 raeburn 4797: sub tool_titles {
4798: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4799: aboutme => 'Personal web page',
1.86 raeburn 4800: blog => 'Blog',
1.162 raeburn 4801: webdav => 'WebDAV',
1.86 raeburn 4802: portfolio => 'Portfolio',
1.88 bisitz 4803: official => 'Official courses (with institutional codes)',
4804: unofficial => 'Unofficial courses',
1.98 raeburn 4805: community => 'Communities',
1.216 raeburn 4806: textbook => 'Textbook courses',
1.271 raeburn 4807: placement => 'Placement tests',
1.86 raeburn 4808: );
1.72 raeburn 4809: return %titles;
4810: }
4811:
1.101 raeburn 4812: sub courserequest_titles {
4813: my %titles = &Apache::lonlocal::texthash (
4814: official => 'Official',
4815: unofficial => 'Unofficial',
4816: community => 'Communities',
1.216 raeburn 4817: textbook => 'Textbook',
1.271 raeburn 4818: placement => 'Placement tests',
1.101 raeburn 4819: norequest => 'Not allowed',
1.104 raeburn 4820: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4821: validate => 'With validation',
4822: autolimit => 'Numerical limit',
1.103 raeburn 4823: unlimited => '(blank for unlimited)',
1.101 raeburn 4824: );
4825: return %titles;
4826: }
4827:
1.163 raeburn 4828: sub authorrequest_titles {
4829: my %titles = &Apache::lonlocal::texthash (
4830: norequest => 'Not allowed',
4831: approval => 'Approval by Dom. Coord.',
4832: automatic => 'Automatic approval',
4833: );
4834: return %titles;
1.210 raeburn 4835: }
1.163 raeburn 4836:
1.101 raeburn 4837: sub courserequest_conditions {
4838: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4839: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4840: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4841: );
4842: return %conditions;
4843: }
4844:
4845:
1.27 raeburn 4846: sub print_usercreation {
1.30 raeburn 4847: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4848: my $numinrow = 4;
1.28 raeburn 4849: my $datatable;
4850: if ($position eq 'top') {
1.30 raeburn 4851: $$rowtotal ++;
1.34 raeburn 4852: my $rowcount = 0;
1.32 raeburn 4853: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4854: if (ref($rules) eq 'HASH') {
4855: if (keys(%{$rules}) > 0) {
1.32 raeburn 4856: $datatable .= &user_formats_row('username',$settings,$rules,
4857: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4858: $$rowtotal ++;
1.32 raeburn 4859: $rowcount ++;
4860: }
4861: }
4862: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4863: if (ref($idrules) eq 'HASH') {
4864: if (keys(%{$idrules}) > 0) {
4865: $datatable .= &user_formats_row('id',$settings,$idrules,
4866: $idruleorder,$numinrow,$rowcount);
4867: $$rowtotal ++;
4868: $rowcount ++;
1.28 raeburn 4869: }
4870: }
1.39 raeburn 4871: if ($rowcount == 0) {
4872: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4873: $$rowtotal ++;
4874: $rowcount ++;
4875: }
1.34 raeburn 4876: } elsif ($position eq 'middle') {
1.224 raeburn 4877: my @creators = ('author','course','requestcrs');
1.37 raeburn 4878: my ($rules,$ruleorder) =
4879: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4880: my %lt = &usercreation_types();
4881: my %checked;
4882: if (ref($settings) eq 'HASH') {
4883: if (ref($settings->{'cancreate'}) eq 'HASH') {
4884: foreach my $item (@creators) {
4885: $checked{$item} = $settings->{'cancreate'}{$item};
4886: }
4887: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4888: foreach my $item (@creators) {
4889: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4890: $checked{$item} = 'none';
4891: }
4892: }
4893: }
4894: }
4895: my $rownum = 0;
4896: foreach my $item (@creators) {
4897: $rownum ++;
1.224 raeburn 4898: if ($checked{$item} eq '') {
4899: $checked{$item} = 'any';
1.34 raeburn 4900: }
4901: my $css_class;
4902: if ($rownum%2) {
4903: $css_class = '';
4904: } else {
4905: $css_class = ' class="LC_odd_row" ';
4906: }
4907: $datatable .= '<tr'.$css_class.'>'.
4908: '<td><span class="LC_nobreak">'.$lt{$item}.
4909: '</span></td><td align="right">';
1.224 raeburn 4910: my @options = ('any');
4911: if (ref($rules) eq 'HASH') {
4912: if (keys(%{$rules}) > 0) {
4913: push(@options,('official','unofficial'));
1.37 raeburn 4914: }
4915: }
1.224 raeburn 4916: push(@options,'none');
1.37 raeburn 4917: foreach my $option (@options) {
1.50 raeburn 4918: my $type = 'radio';
1.34 raeburn 4919: my $check = ' ';
1.224 raeburn 4920: if ($checked{$item} eq $option) {
4921: $check = ' checked="checked" ';
1.34 raeburn 4922: }
4923: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4924: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4925: $item.'" value="'.$option.'"'.$check.'/> '.
4926: $lt{$option}.'</label> </span>';
4927: }
4928: $datatable .= '</td></tr>';
4929: }
1.28 raeburn 4930: } else {
4931: my @contexts = ('author','course','domain');
4932: my @authtypes = ('int','krb4','krb5','loc');
4933: my %checked;
4934: if (ref($settings) eq 'HASH') {
4935: if (ref($settings->{'authtypes'}) eq 'HASH') {
4936: foreach my $item (@contexts) {
4937: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4938: foreach my $auth (@authtypes) {
4939: if ($settings->{'authtypes'}{$item}{$auth}) {
4940: $checked{$item}{$auth} = ' checked="checked" ';
4941: }
4942: }
4943: }
4944: }
1.27 raeburn 4945: }
1.35 raeburn 4946: } else {
4947: foreach my $item (@contexts) {
1.36 raeburn 4948: foreach my $auth (@authtypes) {
1.35 raeburn 4949: $checked{$item}{$auth} = ' checked="checked" ';
4950: }
4951: }
1.27 raeburn 4952: }
1.28 raeburn 4953: my %title = &context_names();
4954: my %authname = &authtype_names();
4955: my $rownum = 0;
4956: my $css_class;
4957: foreach my $item (@contexts) {
4958: if ($rownum%2) {
4959: $css_class = '';
4960: } else {
4961: $css_class = ' class="LC_odd_row" ';
4962: }
1.30 raeburn 4963: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4964: '<td>'.$title{$item}.
4965: '</td><td class="LC_left_item">'.
4966: '<span class="LC_nobreak">';
4967: foreach my $auth (@authtypes) {
4968: $datatable .= '<label>'.
4969: '<input type="checkbox" name="'.$item.'_auth" '.
4970: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4971: $authname{$auth}.'</label> ';
4972: }
4973: $datatable .= '</span></td></tr>';
4974: $rownum ++;
1.27 raeburn 4975: }
1.30 raeburn 4976: $$rowtotal += $rownum;
1.27 raeburn 4977: }
4978: return $datatable;
4979: }
4980:
1.224 raeburn 4981: sub print_selfcreation {
4982: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4983: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4984: if (ref($settings) eq 'HASH') {
4985: if (ref($settings->{'cancreate'}) eq 'HASH') {
4986: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4987: if (ref($createsettings) eq 'HASH') {
4988: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4989: @selfcreate = @{$createsettings->{'selfcreate'}};
4990: } elsif ($createsettings->{'selfcreate'} ne '') {
4991: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4992: @selfcreate = ('email','login','sso');
4993: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4994: @selfcreate = ($createsettings->{'selfcreate'});
4995: }
4996: }
4997: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4998: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4999: }
5000: }
5001: }
5002: }
5003: my %radiohash;
5004: my $numinrow = 4;
5005: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5006: if ($position eq 'top') {
5007: my %choices = &Apache::lonlocal::texthash (
5008: cancreate_login => 'Institutional Login',
5009: cancreate_sso => 'Institutional Single Sign On',
5010: );
5011: my @toggles = sort(keys(%choices));
5012: my %defaultchecked = (
5013: 'cancreate_login' => 'off',
5014: 'cancreate_sso' => 'off',
5015: );
1.228 raeburn 5016: my ($onclick,$itemcount);
1.224 raeburn 5017: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5018: \%choices,$itemcount,$onclick);
1.228 raeburn 5019: $$rowtotal += $itemcount;
5020:
1.224 raeburn 5021: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5022:
5023: if (ref($usertypes) eq 'HASH') {
5024: if (keys(%{$usertypes}) > 0) {
5025: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5026: $dom,$numinrow,$othertitle,
1.228 raeburn 5027: 'statustocreate',$$rowtotal);
1.224 raeburn 5028: $$rowtotal ++;
5029: }
5030: }
1.240 raeburn 5031: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5032: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5033: $fieldtitles{'inststatus'} = &mt('Institutional status');
5034: my $rem;
5035: my $numperrow = 2;
5036: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5037: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5038: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5039: '<td class="LC_left_item">'."\n".
5040: '<table><tr><td>'."\n";
5041: for (my $i=0; $i<@fields; $i++) {
5042: $rem = $i%($numperrow);
5043: if ($rem == 0) {
5044: if ($i > 0) {
5045: $datatable .= '</tr>';
5046: }
5047: $datatable .= '<tr>';
5048: }
5049: my $currval;
1.248 raeburn 5050: if (ref($createsettings) eq 'HASH') {
5051: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5052: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5053: }
1.240 raeburn 5054: }
5055: $datatable .= '<td class="LC_left_item">'.
5056: '<span class="LC_nobreak">'.
5057: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5058: 'value="'.$currval.'" size="10" /> '.
5059: $fieldtitles{$fields[$i]}.'</span></td>';
5060: }
5061: my $colsleft = $numperrow - $rem;
5062: if ($colsleft > 1 ) {
5063: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5064: ' </td>';
5065: } elsif ($colsleft == 1) {
5066: $datatable .= '<td class="LC_left_item"> </td>';
5067: }
5068: $datatable .= '</tr></table></td></tr>';
5069: $$rowtotal ++;
1.224 raeburn 5070: } elsif ($position eq 'middle') {
5071: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5072: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5073: $usertypes->{'default'} = $othertitle;
5074: if (ref($types) eq 'ARRAY') {
5075: push(@{$types},'default');
5076: $usertypes->{'default'} = $othertitle;
5077: foreach my $status (@{$types}) {
5078: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5079: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5080: $$rowtotal ++;
1.224 raeburn 5081: }
5082: }
5083: } else {
1.236 raeburn 5084: my %choices = &Apache::lonlocal::texthash (
5085: cancreate_email => 'E-mail address as username',
5086: );
5087: my @toggles = sort(keys(%choices));
5088: my %defaultchecked = (
5089: 'cancreate_email' => 'off',
5090: );
5091: my $itemcount = 0;
5092: my $display = 'none';
5093: if (grep(/^\Qemail\E$/,@selfcreate)) {
5094: $display = 'block';
5095: }
5096: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5097: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5098: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5099: my $usertypes = {};
5100: my $order = [];
5101: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5102: $usertypes = $domdefaults{'inststatustypes'};
5103: $order = $domdefaults{'inststatusguest'};
5104: }
5105: if (ref($order) eq 'ARRAY') {
5106: push(@{$order},'default');
5107: if (@{$order} > 1) {
5108: $usertypes->{'default'} = &mt('Other users');
5109: $additional .= '<table><tr>';
5110: foreach my $status (@{$order}) {
5111: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5112: }
5113: $additional .= '</tr><tr>';
5114: foreach my $status (@{$order}) {
5115: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5116: }
1.236 raeburn 5117: $additional .= '</tr></table>';
1.224 raeburn 5118: } else {
1.236 raeburn 5119: $usertypes->{'default'} = &mt('All users');
5120: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5121: }
5122: }
1.236 raeburn 5123: $additional .= '</div>'."\n";
5124:
5125: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5126: \%choices,$$rowtotal,$onclick,$additional);
5127: $$rowtotal ++;
1.236 raeburn 5128: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5129: $$rowtotal ++;
1.224 raeburn 5130: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5131: $numinrow = 1;
1.236 raeburn 5132: if (ref($order) eq 'ARRAY') {
5133: foreach my $status (@{$order}) {
1.228 raeburn 5134: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5135: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5136: $$rowtotal ++;
5137: }
5138: }
1.224 raeburn 5139: my ($emailrules,$emailruleorder) =
5140: &Apache::lonnet::inst_userrules($dom,'email');
5141: if (ref($emailrules) eq 'HASH') {
5142: if (keys(%{$emailrules}) > 0) {
5143: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5144: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5145: $$rowtotal ++;
5146: }
5147: }
1.228 raeburn 5148: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5149: }
5150: return $datatable;
5151: }
5152:
1.236 raeburn 5153: sub email_as_username {
5154: my ($rowtotal,$processing,$type) = @_;
5155: my %choices =
5156: &Apache::lonlocal::texthash (
5157: automatic => 'Automatic approval',
5158: approval => 'Queued for approval',
5159: );
5160: my $output;
5161: foreach my $option ('automatic','approval') {
5162: my $checked;
5163: if (ref($processing) eq 'HASH') {
5164: if ($type eq '') {
5165: if (!exists($processing->{'default'})) {
5166: if ($option eq 'automatic') {
5167: $checked = ' checked="checked"';
5168: }
5169: } else {
5170: if ($processing->{'default'} eq $option) {
5171: $checked = ' checked="checked"';
5172: }
5173: }
5174: } else {
5175: if (!exists($processing->{$type})) {
5176: if ($option eq 'automatic') {
5177: $checked = ' checked="checked"';
5178: }
5179: } else {
5180: if ($processing->{$type} eq $option) {
5181: $checked = ' checked="checked"';
5182: }
5183: }
5184: }
5185: } elsif ($option eq 'automatic') {
5186: $checked = ' checked="checked"';
5187: }
5188: my $name = 'cancreate_emailprocess';
5189: if (($type ne '') && ($type ne 'default')) {
5190: $name .= '_'.$type;
5191: }
5192: $output .= '<span class="LC_nobreak"><label>'.
5193: '<input type="radio" name="'.$name.'"'.
5194: $checked.' value="'.$option.'" />'.
5195: $choices{$option}.'</label></span>';
5196: if ($type eq '') {
5197: $output .= ' ';
5198: } else {
5199: $output .= '<br />';
5200: }
5201: }
5202: $$rowtotal ++;
5203: return $output;
5204: }
5205:
1.165 raeburn 5206: sub captcha_choice {
1.169 raeburn 5207: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5208: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5209: $vertext,$currver);
1.165 raeburn 5210: my %lt = &captcha_phrases();
5211: $keyentry = 'hidden';
5212: if ($context eq 'cancreate') {
1.224 raeburn 5213: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5214: } elsif ($context eq 'login') {
5215: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5216: }
5217: if (ref($settings) eq 'HASH') {
5218: if ($settings->{'captcha'}) {
5219: $checked{$settings->{'captcha'}} = ' checked="checked"';
5220: } else {
5221: $checked{'original'} = ' checked="checked"';
5222: }
5223: if ($settings->{'captcha'} eq 'recaptcha') {
5224: $pubtext = $lt{'pub'};
5225: $privtext = $lt{'priv'};
5226: $keyentry = 'text';
1.269 raeburn 5227: $vertext = $lt{'ver'};
5228: $currver = $settings->{'recaptchaversion'};
5229: if ($currver ne '2') {
5230: $currver = 1;
5231: }
1.165 raeburn 5232: }
5233: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5234: $currpub = $settings->{'recaptchakeys'}{'public'};
5235: $currpriv = $settings->{'recaptchakeys'}{'private'};
5236: }
5237: } else {
5238: $checked{'original'} = ' checked="checked"';
5239: }
1.169 raeburn 5240: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5241: my $output = '<tr'.$css_class.'>'.
5242: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5243: '<table><tr><td>'."\n";
5244: foreach my $option ('original','recaptcha','notused') {
5245: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5246: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5247: $lt{$option}.'</label></span>';
5248: unless ($option eq 'notused') {
5249: $output .= (' 'x2)."\n";
5250: }
5251: }
5252: #
5253: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5254: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5255: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5256: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5257: #
1.165 raeburn 5258: $output .= '</td></tr>'."\n".
5259: '<tr><td>'."\n".
5260: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5261: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5262: $currpub.'" size="40" /></span><br />'."\n".
5263: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5264: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5265: $currpriv.'" size="40" /></span><br />'.
5266: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5267: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5268: $currver.'" size="3" /></span><br />'.
5269: '</td></tr></table>'."\n".
1.165 raeburn 5270: '</td></tr>';
5271: return $output;
5272: }
5273:
1.32 raeburn 5274: sub user_formats_row {
5275: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5276: my $output;
5277: my %text = (
5278: 'username' => 'new usernames',
5279: 'id' => 'IDs',
1.45 raeburn 5280: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5281: );
5282: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5283: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5284: '<td><span class="LC_nobreak">';
5285: if ($type eq 'email') {
5286: $output .= &mt("Formats disallowed for $text{$type}: ");
5287: } else {
5288: $output .= &mt("Format rules to check for $text{$type}: ");
5289: }
5290: $output .= '</span></td>'.
5291: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5292: my $rem;
5293: if (ref($ruleorder) eq 'ARRAY') {
5294: for (my $i=0; $i<@{$ruleorder}; $i++) {
5295: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5296: my $rem = $i%($numinrow);
5297: if ($rem == 0) {
5298: if ($i > 0) {
5299: $output .= '</tr>';
5300: }
5301: $output .= '<tr>';
5302: }
5303: my $check = ' ';
1.39 raeburn 5304: if (ref($settings) eq 'HASH') {
5305: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5306: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5307: $check = ' checked="checked" ';
5308: }
1.27 raeburn 5309: }
5310: }
5311: $output .= '<td class="LC_left_item">'.
5312: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5313: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5314: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5315: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5316: }
5317: }
5318: $rem = @{$ruleorder}%($numinrow);
5319: }
5320: my $colsleft = $numinrow - $rem;
5321: if ($colsleft > 1 ) {
5322: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5323: ' </td>';
5324: } elsif ($colsleft == 1) {
5325: $output .= '<td class="LC_left_item"> </td>';
5326: }
5327: $output .= '</tr></table></td></tr>';
5328: return $output;
5329: }
5330:
1.34 raeburn 5331: sub usercreation_types {
5332: my %lt = &Apache::lonlocal::texthash (
5333: author => 'When adding a co-author',
5334: course => 'When adding a user to a course',
1.100 raeburn 5335: requestcrs => 'When requesting a course',
1.34 raeburn 5336: any => 'Any',
5337: official => 'Institutional only ',
5338: unofficial => 'Non-institutional only',
5339: none => 'None',
5340: );
5341: return %lt;
1.48 raeburn 5342: }
1.34 raeburn 5343:
1.224 raeburn 5344: sub selfcreation_types {
5345: my %lt = &Apache::lonlocal::texthash (
5346: selfcreate => 'User creates own account',
5347: any => 'Any',
5348: official => 'Institutional only ',
5349: unofficial => 'Non-institutional only',
5350: email => 'E-mail address',
5351: login => 'Institutional Login',
5352: sso => 'SSO',
5353: );
5354: }
5355:
1.28 raeburn 5356: sub authtype_names {
5357: my %lt = &Apache::lonlocal::texthash(
5358: int => 'Internal',
5359: krb4 => 'Kerberos 4',
5360: krb5 => 'Kerberos 5',
5361: loc => 'Local',
5362: );
5363: return %lt;
5364: }
5365:
5366: sub context_names {
5367: my %context_title = &Apache::lonlocal::texthash(
5368: author => 'Creating users when an Author',
5369: course => 'Creating users when in a course',
5370: domain => 'Creating users when a Domain Coordinator',
5371: );
5372: return %context_title;
5373: }
5374:
1.33 raeburn 5375: sub print_usermodification {
5376: my ($position,$dom,$settings,$rowtotal) = @_;
5377: my $numinrow = 4;
5378: my ($context,$datatable,$rowcount);
5379: if ($position eq 'top') {
5380: $rowcount = 0;
5381: $context = 'author';
5382: foreach my $role ('ca','aa') {
5383: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5384: $numinrow,$rowcount);
5385: $$rowtotal ++;
5386: $rowcount ++;
5387: }
1.230 raeburn 5388: } elsif ($position eq 'bottom') {
1.33 raeburn 5389: $context = 'course';
5390: $rowcount = 0;
5391: foreach my $role ('st','ep','ta','in','cr') {
5392: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5393: $numinrow,$rowcount);
5394: $$rowtotal ++;
5395: $rowcount ++;
5396: }
5397: }
5398: return $datatable;
5399: }
5400:
1.43 raeburn 5401: sub print_defaults {
1.236 raeburn 5402: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5403: my $rownum = 0;
5404: my ($datatable,$css_class);
1.236 raeburn 5405: if ($position eq 'top') {
5406: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5407: 'datelocale_def','portal_def');
5408: my %defaults;
5409: if (ref($settings) eq 'HASH') {
5410: %defaults = %{$settings};
1.43 raeburn 5411: } else {
1.236 raeburn 5412: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5413: foreach my $item (@items) {
5414: $defaults{$item} = $domdefaults{$item};
5415: }
1.43 raeburn 5416: }
1.236 raeburn 5417: my $titles = &defaults_titles($dom);
5418: foreach my $item (@items) {
5419: if ($rownum%2) {
5420: $css_class = '';
5421: } else {
5422: $css_class = ' class="LC_odd_row" ';
5423: }
5424: $datatable .= '<tr'.$css_class.'>'.
5425: '<td><span class="LC_nobreak">'.$titles->{$item}.
5426: '</span></td><td class="LC_right_item" colspan="3">';
5427: if ($item eq 'auth_def') {
5428: my @authtypes = ('internal','krb4','krb5','localauth');
5429: my %shortauth = (
5430: internal => 'int',
5431: krb4 => 'krb4',
5432: krb5 => 'krb5',
5433: localauth => 'loc'
5434: );
5435: my %authnames = &authtype_names();
5436: foreach my $auth (@authtypes) {
5437: my $checked = ' ';
5438: if ($defaults{$item} eq $auth) {
5439: $checked = ' checked="checked" ';
5440: }
5441: $datatable .= '<label><input type="radio" name="'.$item.
5442: '" value="'.$auth.'"'.$checked.'/>'.
5443: $authnames{$shortauth{$auth}}.'</label> ';
5444: }
5445: } elsif ($item eq 'timezone_def') {
5446: my $includeempty = 1;
5447: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5448: } elsif ($item eq 'datelocale_def') {
5449: my $includeempty = 1;
5450: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5451: } elsif ($item eq 'lang_def') {
1.263 raeburn 5452: my $includeempty = 1;
5453: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5454: } else {
5455: my $size;
5456: if ($item eq 'portal_def') {
5457: $size = ' size="25"';
5458: }
5459: $datatable .= '<input type="text" name="'.$item.'" value="'.
5460: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5461: }
1.236 raeburn 5462: $datatable .= '</td></tr>';
5463: $rownum ++;
5464: }
5465: } else {
5466: my (%defaults);
5467: if (ref($settings) eq 'HASH') {
5468: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5469: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5470: my $maxnum = @{$settings->{'inststatusorder'}};
5471: for (my $i=0; $i<$maxnum; $i++) {
5472: $css_class = $rownum%2?' class="LC_odd_row"':'';
5473: my $item = $settings->{'inststatusorder'}->[$i];
5474: my $title = $settings->{'inststatustypes'}->{$item};
5475: my $guestok;
5476: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5477: $guestok = 1;
5478: }
5479: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5480: $datatable .= '<tr'.$css_class.'>'.
5481: '<td><span class="LC_nobreak">'.
5482: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5483: for (my $k=0; $k<=$maxnum; $k++) {
5484: my $vpos = $k+1;
5485: my $selstr;
5486: if ($k == $i) {
5487: $selstr = ' selected="selected" ';
5488: }
5489: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5490: }
5491: my ($checkedon,$checkedoff);
5492: $checkedoff = ' checked="checked"';
5493: if ($guestok) {
5494: $checkedon = $checkedoff;
5495: $checkedoff = '';
5496: }
5497: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5498: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5499: &mt('delete').'</span></td>'.
5500: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5501: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5502: '</span></td>'.
5503: '<td class="LC_right_item"><span class="LC_nobreak">'.
5504: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5505: &mt('Yes').'</label>'.(' 'x2).
5506: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5507: &mt('No').'</label></span></td></tr>';
5508: }
5509: $css_class = $rownum%2?' class="LC_odd_row"':'';
5510: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5511: $datatable .= '<tr '.$css_class.'>'.
5512: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5513: for (my $k=0; $k<=$maxnum; $k++) {
5514: my $vpos = $k+1;
5515: my $selstr;
5516: if ($k == $maxnum) {
5517: $selstr = ' selected="selected" ';
5518: }
5519: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5520: }
5521: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5522: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5523: ' '.&mt('(new)').
5524: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5525: &mt('Name displayed:').
5526: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5527: '<td class="LC_right_item"><span class="LC_nobreak">'.
5528: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5529: &mt('Yes').'</label>'.(' 'x2).
5530: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5531: &mt('No').'</label></span></td></tr>';
5532: '</tr>'."\n";
5533: $rownum ++;
1.141 raeburn 5534: }
1.43 raeburn 5535: }
5536: }
5537: $$rowtotal += $rownum;
5538: return $datatable;
5539: }
5540:
1.168 raeburn 5541: sub get_languages_hash {
5542: my %langchoices;
5543: foreach my $id (&Apache::loncommon::languageids()) {
5544: my $code = &Apache::loncommon::supportedlanguagecode($id);
5545: if ($code ne '') {
5546: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5547: }
5548: }
5549: return %langchoices;
5550: }
5551:
1.43 raeburn 5552: sub defaults_titles {
1.141 raeburn 5553: my ($dom) = @_;
1.43 raeburn 5554: my %titles = &Apache::lonlocal::texthash (
5555: 'auth_def' => 'Default authentication type',
5556: 'auth_arg_def' => 'Default authentication argument',
5557: 'lang_def' => 'Default language',
1.54 raeburn 5558: 'timezone_def' => 'Default timezone',
1.68 raeburn 5559: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5560: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5561: );
1.141 raeburn 5562: if ($dom) {
5563: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5564: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5565: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5566: $protocol = 'http' if ($protocol ne 'https');
5567: if ($uint_dom) {
5568: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5569: $uint_dom);
5570: }
5571: }
1.43 raeburn 5572: return (\%titles);
5573: }
5574:
1.46 raeburn 5575: sub print_scantronformat {
5576: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5577: my $itemcount = 1;
1.60 raeburn 5578: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5579: %confhash);
1.46 raeburn 5580: my $switchserver = &check_switchserver($dom,$confname);
5581: my %lt = &Apache::lonlocal::texthash (
1.95 www 5582: default => 'Default bubblesheet format file error',
5583: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5584: );
5585: my %scantronfiles = (
5586: default => 'default.tab',
5587: custom => 'custom.tab',
5588: );
5589: foreach my $key (keys(%scantronfiles)) {
5590: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5591: .$scantronfiles{$key};
5592: }
5593: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5594: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5595: if (!$switchserver) {
5596: my $servadm = $r->dir_config('lonAdmEMail');
5597: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5598: if ($configuserok eq 'ok') {
5599: if ($author_ok eq 'ok') {
5600: my %legacyfile = (
5601: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5602: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5603: );
5604: my %md5chk;
5605: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5606: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5607: chomp($md5chk{$type});
1.46 raeburn 5608: }
5609: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5610: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5611: ($scantronurls{$type},my $error) =
1.46 raeburn 5612: &legacy_scantronformat($r,$dom,$confname,
5613: $type,$legacyfile{$type},
5614: $scantronurls{$type},
5615: $scantronfiles{$type});
1.60 raeburn 5616: if ($error ne '') {
5617: $error{$type} = $error;
5618: }
5619: }
5620: if (keys(%error) == 0) {
5621: $is_custom = 1;
5622: $confhash{'scantron'}{'scantronformat'} =
5623: $scantronurls{'custom'};
5624: my $putresult =
5625: &Apache::lonnet::put_dom('configuration',
5626: \%confhash,$dom);
5627: if ($putresult ne 'ok') {
5628: $error{'custom'} =
5629: '<span class="LC_error">'.
5630: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5631: }
1.46 raeburn 5632: }
5633: } else {
1.60 raeburn 5634: ($scantronurls{'default'},my $error) =
1.46 raeburn 5635: &legacy_scantronformat($r,$dom,$confname,
5636: 'default',$legacyfile{'default'},
5637: $scantronurls{'default'},
5638: $scantronfiles{'default'});
1.60 raeburn 5639: if ($error eq '') {
5640: $confhash{'scantron'}{'scantronformat'} = '';
5641: my $putresult =
5642: &Apache::lonnet::put_dom('configuration',
5643: \%confhash,$dom);
5644: if ($putresult ne 'ok') {
5645: $error{'default'} =
5646: '<span class="LC_error">'.
5647: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5648: }
5649: } else {
5650: $error{'default'} = $error;
5651: }
1.46 raeburn 5652: }
5653: }
5654: }
5655: } else {
1.95 www 5656: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5657: }
5658: }
5659: if (ref($settings) eq 'HASH') {
5660: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5661: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5662: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5663: $scantronurl = '';
5664: } else {
5665: $scantronurl = $settings->{'scantronformat'};
5666: }
5667: $is_custom = 1;
5668: } else {
5669: $scantronurl = $scantronurls{'default'};
5670: }
5671: } else {
1.60 raeburn 5672: if ($is_custom) {
5673: $scantronurl = $scantronurls{'custom'};
5674: } else {
5675: $scantronurl = $scantronurls{'default'};
5676: }
1.46 raeburn 5677: }
5678: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5679: $datatable .= '<tr'.$css_class.'>';
5680: if (!$is_custom) {
1.65 raeburn 5681: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5682: '<span class="LC_nobreak">';
1.46 raeburn 5683: if ($scantronurl) {
1.199 raeburn 5684: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5685: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5686: } else {
5687: $datatable = &mt('File unavailable for display');
5688: }
1.65 raeburn 5689: $datatable .= '</span></td>';
1.60 raeburn 5690: if (keys(%error) == 0) {
5691: $datatable .= '<td valign="bottom">';
5692: if (!$switchserver) {
5693: $datatable .= &mt('Upload:').'<br />';
5694: }
5695: } else {
5696: my $errorstr;
5697: foreach my $key (sort(keys(%error))) {
5698: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5699: }
5700: $datatable .= '<td>'.$errorstr;
5701: }
1.46 raeburn 5702: } else {
5703: if (keys(%error) > 0) {
5704: my $errorstr;
5705: foreach my $key (sort(keys(%error))) {
5706: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5707: }
1.60 raeburn 5708: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5709: } elsif ($scantronurl) {
1.199 raeburn 5710: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5711: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5712: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5713: $link.
5714: '<label><input type="checkbox" name="scantronformat_del"'.
5715: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5716: '<td><span class="LC_nobreak"> '.
5717: &mt('Replace:').'</span><br />';
1.46 raeburn 5718: }
5719: }
5720: if (keys(%error) == 0) {
5721: if ($switchserver) {
5722: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5723: } else {
1.65 raeburn 5724: $datatable .='<span class="LC_nobreak"> '.
5725: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5726: }
5727: }
5728: $datatable .= '</td></tr>';
5729: $$rowtotal ++;
5730: return $datatable;
5731: }
5732:
5733: sub legacy_scantronformat {
5734: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5735: my ($url,$error);
5736: my @statinfo = &Apache::lonnet::stat_file($newurl);
5737: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5738: (my $result,$url) =
5739: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5740: '','',$newfile);
5741: if ($result ne 'ok') {
1.130 raeburn 5742: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5743: }
5744: }
5745: return ($url,$error);
5746: }
1.43 raeburn 5747:
1.49 raeburn 5748: sub print_coursecategories {
1.57 raeburn 5749: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5750: my $datatable;
5751: if ($position eq 'top') {
1.238 raeburn 5752: my (%checked);
5753: my @catitems = ('unauth','auth');
5754: my @cattypes = ('std','domonly','codesrch','none');
5755: $checked{'unauth'} = 'std';
5756: $checked{'auth'} = 'std';
5757: if (ref($settings) eq 'HASH') {
5758: foreach my $type (@cattypes) {
5759: if ($type eq $settings->{'unauth'}) {
5760: $checked{'unauth'} = $type;
5761: }
5762: if ($type eq $settings->{'auth'}) {
5763: $checked{'auth'} = $type;
5764: }
5765: }
5766: }
5767: my %lt = &Apache::lonlocal::texthash (
5768: unauth => 'Catalog type for unauthenticated users',
5769: auth => 'Catalog type for authenticated users',
5770: none => 'No catalog',
5771: std => 'Standard catalog',
5772: domonly => 'Domain-only catalog',
5773: codesrch => "Code search form",
5774: );
5775: my $itemcount = 0;
5776: foreach my $item (@catitems) {
5777: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5778: $datatable .= '<tr '.$css_class.'>'.
5779: '<td>'.$lt{$item}.'</td>'.
5780: '<td class="LC_right_item"><span class="LC_nobreak">';
5781: foreach my $type (@cattypes) {
5782: my $ischecked;
5783: if ($checked{$item} eq $type) {
5784: $ischecked=' checked="checked"';
5785: }
5786: $datatable .= '<label>'.
5787: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5788: ' />'.$lt{$type}.'</label> ';
5789: }
5790: $datatable .= '</td></tr>';
5791: $itemcount ++;
5792: }
5793: $$rowtotal += $itemcount;
5794: } elsif ($position eq 'middle') {
1.57 raeburn 5795: my $toggle_cats_crs = ' ';
5796: my $toggle_cats_dom = ' checked="checked" ';
5797: my $can_cat_crs = ' ';
5798: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5799: my $toggle_catscomm_comm = ' ';
5800: my $toggle_catscomm_dom = ' checked="checked" ';
5801: my $can_catcomm_comm = ' ';
5802: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 5803: my $toggle_catsplace_place = ' ';
5804: my $toggle_catsplace_dom = ' checked="checked" ';
5805: my $can_catplace_place = ' ';
5806: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 5807:
1.57 raeburn 5808: if (ref($settings) eq 'HASH') {
5809: if ($settings->{'togglecats'} eq 'crs') {
5810: $toggle_cats_crs = $toggle_cats_dom;
5811: $toggle_cats_dom = ' ';
5812: }
5813: if ($settings->{'categorize'} eq 'crs') {
5814: $can_cat_crs = $can_cat_dom;
5815: $can_cat_dom = ' ';
5816: }
1.120 raeburn 5817: if ($settings->{'togglecatscomm'} eq 'comm') {
5818: $toggle_catscomm_comm = $toggle_catscomm_dom;
5819: $toggle_catscomm_dom = ' ';
5820: }
5821: if ($settings->{'categorizecomm'} eq 'comm') {
5822: $can_catcomm_comm = $can_catcomm_dom;
5823: $can_catcomm_dom = ' ';
5824: }
1.272 raeburn 5825: if ($settings->{'togglecatsplace'} eq 'place') {
5826: $toggle_catsplace_place = $toggle_catsplace_dom;
5827: $toggle_catsplace_dom = ' ';
5828: }
5829: if ($settings->{'categorizeplace'} eq 'place') {
5830: $can_catplace_place = $can_catplace_dom;
5831: $can_catplace_dom = ' ';
5832: }
1.57 raeburn 5833: }
5834: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 5835: togglecats => 'Show/Hide a course in catalog',
5836: togglecatscomm => 'Show/Hide a community in catalog',
5837: togglecatsplace => 'Show/Hide a placement test in catalog',
5838: categorize => 'Assign a category to a course',
5839: categorizecomm => 'Assign a category to a community',
5840: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 5841: );
5842: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 5843: dom => 'Set in Domain',
5844: crs => 'Set in Course',
5845: comm => 'Set in Community',
5846: place => 'Set in Placement Test',
1.57 raeburn 5847: );
5848: $datatable = '<tr class="LC_odd_row">'.
5849: '<td>'.$title{'togglecats'}.'</td>'.
5850: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5851: '<input type="radio" name="togglecats"'.
5852: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5853: '<label><input type="radio" name="togglecats"'.
5854: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5855: '</tr><tr>'.
5856: '<td>'.$title{'categorize'}.'</td>'.
5857: '<td class="LC_right_item"><span class="LC_nobreak">'.
5858: '<label><input type="radio" name="categorize"'.
5859: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5860: '<label><input type="radio" name="categorize"'.
5861: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5862: '</tr><tr class="LC_odd_row">'.
5863: '<td>'.$title{'togglecatscomm'}.'</td>'.
5864: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5865: '<input type="radio" name="togglecatscomm"'.
5866: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5867: '<label><input type="radio" name="togglecatscomm"'.
5868: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5869: '</tr><tr>'.
5870: '<td>'.$title{'categorizecomm'}.'</td>'.
5871: '<td class="LC_right_item"><span class="LC_nobreak">'.
5872: '<label><input type="radio" name="categorizecomm"'.
5873: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5874: '<label><input type="radio" name="categorizecomm"'.
5875: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 5876: '</tr><tr>'.
5877: '<td>'.$title{'togglecatsplace'}.'</td>'.
5878: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5879: '<input type="radio" name="togglecatsplace"'.
5880: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5881: '<label><input type="radio" name="togglecatscomm"'.
5882: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
5883: '</tr><tr>'.
5884: '<td>'.$title{'categorizeplace'}.'</td>'.
5885: '<td class="LC_right_item"><span class="LC_nobreak">'.
5886: '<label><input type="radio" name="categorizeplace"'.
5887: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5888: '<label><input type="radio" name="categorizeplace"'.
5889: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 5890: '</tr>';
1.272 raeburn 5891: $$rowtotal += 6;
1.57 raeburn 5892: } else {
5893: my $css_class;
5894: my $itemcount = 1;
5895: my $cathash;
5896: if (ref($settings) eq 'HASH') {
5897: $cathash = $settings->{'cats'};
5898: }
5899: if (ref($cathash) eq 'HASH') {
5900: my (@cats,@trails,%allitems,%idx,@jsarray);
5901: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5902: \%allitems,\%idx,\@jsarray);
5903: my $maxdepth = scalar(@cats);
5904: my $colattrib = '';
5905: if ($maxdepth > 2) {
5906: $colattrib = ' colspan="2" ';
5907: }
5908: my @path;
5909: if (@cats > 0) {
5910: if (ref($cats[0]) eq 'ARRAY') {
5911: my $numtop = @{$cats[0]};
5912: my $maxnum = $numtop;
1.120 raeburn 5913: my %default_names = (
5914: instcode => &mt('Official courses'),
5915: communities => &mt('Communities'),
1.272 raeburn 5916: placement => &mt('Placement Tests'),
1.120 raeburn 5917: );
5918:
5919: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5920: ($cathash->{'instcode::0'} eq '') ||
5921: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 5922: ($cathash->{'communities::0'} eq '') ||
5923: (!grep(/^placement$/,@{$cats[0]})) ||
5924: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 5925: $maxnum ++;
5926: }
5927: my $lastidx;
5928: for (my $i=0; $i<$numtop; $i++) {
5929: my $parent = $cats[0][$i];
5930: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5931: my $item = &escape($parent).'::0';
5932: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5933: $lastidx = $idx{$item};
5934: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5935: .'<select name="'.$item.'"'.$chgstr.'>';
5936: for (my $k=0; $k<=$maxnum; $k++) {
5937: my $vpos = $k+1;
5938: my $selstr;
5939: if ($k == $i) {
5940: $selstr = ' selected="selected" ';
5941: }
5942: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5943: }
1.214 raeburn 5944: $datatable .= '</select></span></td><td>';
1.272 raeburn 5945: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 5946: $datatable .= '<span class="LC_nobreak">'
5947: .$default_names{$parent}.'</span>';
5948: if ($parent eq 'instcode') {
5949: $datatable .= '<br /><span class="LC_nobreak">('
5950: .&mt('with institutional codes')
5951: .')</span></td><td'.$colattrib.'>';
5952: } else {
5953: $datatable .= '<table><tr><td>';
5954: }
5955: $datatable .= '<span class="LC_nobreak">'
5956: .'<label><input type="radio" name="'
5957: .$parent.'" value="1" checked="checked" />'
5958: .&mt('Display').'</label>';
5959: if ($parent eq 'instcode') {
5960: $datatable .= ' ';
5961: } else {
5962: $datatable .= '</span></td></tr><tr><td>'
5963: .'<span class="LC_nobreak">';
5964: }
5965: $datatable .= '<label><input type="radio" name="'
5966: .$parent.'" value="0" />'
5967: .&mt('Do not display').'</label></span>';
1.272 raeburn 5968: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 5969: $datatable .= '</td></tr></table>';
5970: }
5971: $datatable .= '</td>';
1.57 raeburn 5972: } else {
5973: $datatable .= $parent
1.214 raeburn 5974: .' <span class="LC_nobreak"><label>'
5975: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5976: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5977: }
5978: my $depth = 1;
5979: push(@path,$parent);
5980: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5981: pop(@path);
5982: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5983: $itemcount ++;
5984: }
1.48 raeburn 5985: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5986: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5987: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5988: for (my $k=0; $k<=$maxnum; $k++) {
5989: my $vpos = $k+1;
5990: my $selstr;
1.57 raeburn 5991: if ($k == $numtop) {
1.48 raeburn 5992: $selstr = ' selected="selected" ';
5993: }
5994: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5995: }
1.59 bisitz 5996: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5997: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5998: .'</tr>'."\n";
1.48 raeburn 5999: $itemcount ++;
1.272 raeburn 6000: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6001: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6002: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6003: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6004: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6005: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6006: for (my $k=0; $k<=$maxnum; $k++) {
6007: my $vpos = $k+1;
6008: my $selstr;
6009: if ($k == $maxnum) {
6010: $selstr = ' selected="selected" ';
6011: }
6012: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6013: }
1.120 raeburn 6014: $datatable .= '</select></span></td>'.
6015: '<td><span class="LC_nobreak">'.
6016: $default_names{$default}.'</span>';
6017: if ($default eq 'instcode') {
6018: $datatable .= '<br /><span class="LC_nobreak">('
6019: .&mt('with institutional codes').')</span>';
6020: }
6021: $datatable .= '</td>'
6022: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6023: .&mt('Display').'</label> '
6024: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6025: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6026: }
6027: }
6028: }
1.57 raeburn 6029: } else {
6030: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6031: }
6032: } else {
1.238 raeburn 6033: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6034: .&initialize_categories($itemcount);
1.48 raeburn 6035: }
1.57 raeburn 6036: $$rowtotal += $itemcount;
1.48 raeburn 6037: }
6038: return $datatable;
6039: }
6040:
1.69 raeburn 6041: sub print_serverstatuses {
6042: my ($dom,$settings,$rowtotal) = @_;
6043: my $datatable;
6044: my @pages = &serverstatus_pages();
6045: my (%namedaccess,%machineaccess);
6046: foreach my $type (@pages) {
6047: $namedaccess{$type} = '';
6048: $machineaccess{$type}= '';
6049: }
6050: if (ref($settings) eq 'HASH') {
6051: foreach my $type (@pages) {
6052: if (exists($settings->{$type})) {
6053: if (ref($settings->{$type}) eq 'HASH') {
6054: foreach my $key (keys(%{$settings->{$type}})) {
6055: if ($key eq 'namedusers') {
6056: $namedaccess{$type} = $settings->{$type}->{$key};
6057: } elsif ($key eq 'machines') {
6058: $machineaccess{$type} = $settings->{$type}->{$key};
6059: }
6060: }
6061: }
6062: }
6063: }
6064: }
1.81 raeburn 6065: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6066: my $rownum = 0;
6067: my $css_class;
6068: foreach my $type (@pages) {
6069: $rownum ++;
6070: $css_class = $rownum%2?' class="LC_odd_row"':'';
6071: $datatable .= '<tr'.$css_class.'>'.
6072: '<td><span class="LC_nobreak">'.
6073: $titles->{$type}.'</span></td>'.
6074: '<td class="LC_left_item">'.
6075: '<input type="text" name="'.$type.'_namedusers" '.
6076: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6077: '<td class="LC_right_item">'.
6078: '<span class="LC_nobreak">'.
6079: '<input type="text" name="'.$type.'_machines" '.
6080: 'value="'.$machineaccess{$type}.'" size="10" />'.
6081: '</td></tr>'."\n";
6082: }
6083: $$rowtotal += $rownum;
6084: return $datatable;
6085: }
6086:
6087: sub serverstatus_pages {
6088: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6089: 'checksums','clusterstatus','certstatus','metadata_keywords',
6090: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6091: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6092: }
6093:
1.236 raeburn 6094: sub defaults_javascript {
6095: my ($settings) = @_;
1.248 raeburn 6096: return unless (ref($settings) eq 'HASH');
1.236 raeburn 6097: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6098: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6099: if ($maxnum eq '') {
6100: $maxnum = 0;
6101: }
6102: $maxnum ++;
1.249 raeburn 6103: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6104: return <<"ENDSCRIPT";
6105: <script type="text/javascript">
6106: // <![CDATA[
6107: function reorderTypes(form,caller) {
6108: var changedVal;
6109: $jstext
6110: var newpos = 'addinststatus_pos';
6111: var current = new Array;
6112: var maxh = $maxnum;
6113: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6114: var oldVal;
6115: if (caller == newpos) {
6116: changedVal = newitemVal;
6117: } else {
6118: var curritem = 'inststatus_pos_'+caller;
6119: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6120: current[newitemVal] = newpos;
6121: }
6122: for (var i=0; i<inststatuses.length; i++) {
6123: if (inststatuses[i] != caller) {
6124: var elementName = 'inststatus_pos_'+inststatuses[i];
6125: if (form.elements[elementName]) {
6126: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6127: current[currVal] = elementName;
6128: }
6129: }
6130: }
6131: for (var j=0; j<maxh; j++) {
6132: if (current[j] == undefined) {
6133: oldVal = j;
6134: }
6135: }
6136: if (oldVal < changedVal) {
6137: for (var k=oldVal+1; k<=changedVal ; k++) {
6138: var elementName = current[k];
6139: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6140: }
6141: } else {
6142: for (var k=changedVal; k<oldVal; k++) {
6143: var elementName = current[k];
6144: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6145: }
6146: }
6147: return;
6148: }
6149:
6150: // ]]>
6151: </script>
6152:
6153: ENDSCRIPT
6154: }
6155: }
6156:
1.49 raeburn 6157: sub coursecategories_javascript {
6158: my ($settings) = @_;
1.57 raeburn 6159: my ($output,$jstext,$cathash);
1.49 raeburn 6160: if (ref($settings) eq 'HASH') {
1.57 raeburn 6161: $cathash = $settings->{'cats'};
6162: }
6163: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6164: my (@cats,@jsarray,%idx);
1.57 raeburn 6165: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6166: if (@jsarray > 0) {
6167: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6168: for (my $i=0; $i<@jsarray; $i++) {
6169: if (ref($jsarray[$i]) eq 'ARRAY') {
6170: my $catstr = join('","',@{$jsarray[$i]});
6171: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6172: }
6173: }
6174: }
6175: } else {
6176: $jstext = ' var categories = Array(1);'."\n".
6177: ' categories[0] = Array("instcode_pos");'."\n";
6178: }
1.237 bisitz 6179: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6180: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 6181: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 6182: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6183: &js_escape(\$instcode_reserved);
6184: &js_escape(\$communities_reserved);
1.272 raeburn 6185: &js_escape(\$placement_reserved);
1.265 damieng 6186: &js_escape(\$choose_again);
1.49 raeburn 6187: $output = <<"ENDSCRIPT";
6188: <script type="text/javascript">
1.109 raeburn 6189: // <![CDATA[
1.49 raeburn 6190: function reorderCats(form,parent,item,idx) {
6191: var changedVal;
6192: $jstext
6193: var newpos = 'addcategory_pos';
6194: if (parent == '') {
6195: var has_instcode = 0;
6196: var maxtop = categories[idx].length;
6197: for (var j=0; j<maxtop; j++) {
6198: if (categories[idx][j] == 'instcode::0') {
6199: has_instcode == 1;
6200: }
6201: }
6202: if (has_instcode == 0) {
6203: categories[idx][maxtop] = 'instcode_pos';
6204: }
6205: } else {
6206: newpos += '_'+parent;
6207: }
6208: var maxh = 1 + categories[idx].length;
6209: var current = new Array;
6210: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6211: if (item == newpos) {
6212: changedVal = newitemVal;
6213: } else {
6214: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6215: current[newitemVal] = newpos;
6216: }
6217: for (var i=0; i<categories[idx].length; i++) {
6218: var elementName = categories[idx][i];
6219: if (elementName != item) {
6220: if (form.elements[elementName]) {
6221: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6222: current[currVal] = elementName;
6223: }
6224: }
6225: }
6226: var oldVal;
6227: for (var j=0; j<maxh; j++) {
6228: if (current[j] == undefined) {
6229: oldVal = j;
6230: }
6231: }
6232: if (oldVal < changedVal) {
6233: for (var k=oldVal+1; k<=changedVal ; k++) {
6234: var elementName = current[k];
6235: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6236: }
6237: } else {
6238: for (var k=changedVal; k<oldVal; k++) {
6239: var elementName = current[k];
6240: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6241: }
6242: }
6243: return;
6244: }
1.120 raeburn 6245:
6246: function categoryCheck(form) {
6247: if (form.elements['addcategory_name'].value == 'instcode') {
6248: alert('$instcode_reserved\\n$choose_again');
6249: return false;
6250: }
6251: if (form.elements['addcategory_name'].value == 'communities') {
6252: alert('$communities_reserved\\n$choose_again');
6253: return false;
6254: }
1.272 raeburn 6255: if (form.elements['addcategory_name'].value == 'placement') {
6256: alert('$placement_reserved\\n$choose_again');
6257: return false;
6258: }
1.120 raeburn 6259: return true;
6260: }
6261:
1.109 raeburn 6262: // ]]>
1.49 raeburn 6263: </script>
6264:
6265: ENDSCRIPT
6266: return $output;
6267: }
6268:
1.48 raeburn 6269: sub initialize_categories {
6270: my ($itemcount) = @_;
1.120 raeburn 6271: my ($datatable,$css_class,$chgstr);
6272: my %default_names = (
6273: instcode => 'Official courses (with institutional codes)',
6274: communities => 'Communities',
1.272 raeburn 6275: placement => 'Placement Tests',
1.120 raeburn 6276: );
6277: my $select0 = ' selected="selected"';
6278: my $select1 = '';
1.272 raeburn 6279: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6281: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 6282: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 6283: $select1 = $select0;
6284: $select0 = '';
6285: }
6286: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6287: .'<select name="'.$default.'_pos">'
6288: .'<option value="0"'.$select0.'>1</option>'
6289: .'<option value="1"'.$select1.'>2</option>'
6290: .'<option value="2">3</option></select> '
6291: .$default_names{$default}
6292: .'</span></td><td><span class="LC_nobreak">'
6293: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6294: .&mt('Display').'</label> <label>'
6295: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6296: .'</label></span></td></tr>';
1.120 raeburn 6297: $itemcount ++;
6298: }
1.48 raeburn 6299: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6300: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6301: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6302: .'<select name="addcategory_pos"'.$chgstr.'>'
6303: .'<option value="0">1</option>'
6304: .'<option value="1">2</option>'
6305: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6306: .&mt('Add category').'</td><td>'.&mt('Name:')
6307: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6308: return $datatable;
6309: }
6310:
6311: sub build_category_rows {
1.49 raeburn 6312: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6313: my ($text,$name,$item,$chgstr);
1.48 raeburn 6314: if (ref($cats) eq 'ARRAY') {
6315: my $maxdepth = scalar(@{$cats});
6316: if (ref($cats->[$depth]) eq 'HASH') {
6317: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6318: my $numchildren = @{$cats->[$depth]{$parent}};
6319: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6320: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6321: my ($idxnum,$parent_name,$parent_item);
6322: my $higher = $depth - 1;
6323: if ($higher == 0) {
6324: $parent_name = &escape($parent).'::'.$higher;
6325: } else {
6326: if (ref($path) eq 'ARRAY') {
6327: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6328: }
6329: }
6330: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6331: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6332: if ($j < $numchildren) {
1.48 raeburn 6333: $name = $cats->[$depth]{$parent}[$j];
6334: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6335: $idxnum = $idx->{$item};
6336: } else {
6337: $name = $parent_name;
6338: $item = $parent_item;
1.48 raeburn 6339: }
1.49 raeburn 6340: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6341: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6342: for (my $i=0; $i<=$numchildren; $i++) {
6343: my $vpos = $i+1;
6344: my $selstr;
6345: if ($j == $i) {
6346: $selstr = ' selected="selected" ';
6347: }
6348: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6349: }
6350: $text .= '</select> ';
6351: if ($j < $numchildren) {
6352: my $deeper = $depth+1;
6353: $text .= $name.' '
6354: .'<label><input type="checkbox" name="deletecategory" value="'
6355: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6356: if(ref($path) eq 'ARRAY') {
6357: push(@{$path},$name);
1.49 raeburn 6358: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6359: pop(@{$path});
6360: }
6361: } else {
1.59 bisitz 6362: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6363: if ($j == $numchildren) {
6364: $text .= $name;
6365: } else {
6366: $text .= $item;
6367: }
6368: $text .= '" value="" />';
6369: }
6370: $text .= '</td></tr>';
6371: }
6372: $text .= '</table></td>';
6373: } else {
6374: my $higher = $depth-1;
6375: if ($higher == 0) {
6376: $name = &escape($parent).'::'.$higher;
6377: } else {
6378: if (ref($path) eq 'ARRAY') {
6379: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6380: }
6381: }
6382: my $colspan;
6383: if ($parent ne 'instcode') {
6384: $colspan = $maxdepth - $depth - 1;
6385: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6386: }
6387: }
6388: }
6389: }
6390: return $text;
6391: }
6392:
1.33 raeburn 6393: sub modifiable_userdata_row {
1.228 raeburn 6394: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6395: my ($role,$rolename,$statustype);
6396: $role = $item;
1.224 raeburn 6397: if ($context eq 'cancreate') {
1.228 raeburn 6398: if ($item =~ /^emailusername_(.+)$/) {
6399: $statustype = $1;
6400: $role = 'emailusername';
6401: if (ref($usertypes) eq 'HASH') {
6402: if ($usertypes->{$statustype}) {
6403: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6404: } else {
6405: $rolename = &mt('Data provided by user');
6406: }
6407: }
1.224 raeburn 6408: }
6409: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6410: if (ref($usertypes) eq 'HASH') {
6411: $rolename = $usertypes->{$role};
6412: } else {
6413: $rolename = $role;
6414: }
1.33 raeburn 6415: } else {
1.63 raeburn 6416: if ($role eq 'cr') {
6417: $rolename = &mt('Custom role');
6418: } else {
6419: $rolename = &Apache::lonnet::plaintext($role);
6420: }
1.33 raeburn 6421: }
1.224 raeburn 6422: my (@fields,%fieldtitles);
6423: if (ref($fieldsref) eq 'ARRAY') {
6424: @fields = @{$fieldsref};
6425: } else {
6426: @fields = ('lastname','firstname','middlename','generation',
6427: 'permanentemail','id');
6428: }
6429: if ((ref($titlesref) eq 'HASH')) {
6430: %fieldtitles = %{$titlesref};
6431: } else {
6432: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6433: }
1.33 raeburn 6434: my $output;
6435: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6436: $output = '<tr '.$css_class.'>'.
6437: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6438: '<td class="LC_left_item" colspan="2"><table>';
6439: my $rem;
6440: my %checks;
6441: if (ref($settings) eq 'HASH') {
6442: if (ref($settings->{$context}) eq 'HASH') {
6443: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6444: my $hashref = $settings->{$context}->{$role};
6445: if ($role eq 'emailusername') {
6446: if ($statustype) {
6447: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6448: $hashref = $settings->{$context}->{$role}->{$statustype};
6449: if (ref($hashref) eq 'HASH') {
6450: foreach my $field (@fields) {
6451: if ($hashref->{$field}) {
6452: $checks{$field} = $hashref->{$field};
6453: }
6454: }
6455: }
6456: }
6457: }
6458: } else {
6459: if (ref($hashref) eq 'HASH') {
6460: foreach my $field (@fields) {
6461: if ($hashref->{$field}) {
6462: $checks{$field} = ' checked="checked" ';
6463: }
6464: }
1.33 raeburn 6465: }
6466: }
6467: }
6468: }
6469: }
1.228 raeburn 6470:
1.33 raeburn 6471: for (my $i=0; $i<@fields; $i++) {
6472: my $rem = $i%($numinrow);
6473: if ($rem == 0) {
6474: if ($i > 0) {
6475: $output .= '</tr>';
6476: }
6477: $output .= '<tr>';
6478: }
6479: my $check = ' ';
1.228 raeburn 6480: unless ($role eq 'emailusername') {
6481: if (exists($checks{$fields[$i]})) {
6482: $check = $checks{$fields[$i]}
6483: } else {
6484: if ($role eq 'st') {
6485: if (ref($settings) ne 'HASH') {
6486: $check = ' checked="checked" ';
6487: }
1.33 raeburn 6488: }
6489: }
6490: }
6491: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6492: '<span class="LC_nobreak">';
6493: if ($role eq 'emailusername') {
6494: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6495: $checks{$fields[$i]} = 'omit';
6496: }
6497: foreach my $option ('required','optional','omit') {
6498: my $checked='';
6499: if ($checks{$fields[$i]} eq $option) {
6500: $checked='checked="checked" ';
6501: }
6502: $output .= '<label>'.
6503: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6504: &mt($option).'</label>'.(' ' x2);
6505: }
6506: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6507: } else {
6508: $output .= '<label>'.
6509: '<input type="checkbox" name="canmodify_'.$role.'" '.
6510: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6511: '</label>';
6512: }
6513: $output .= '</span></td>';
1.33 raeburn 6514: $rem = @fields%($numinrow);
6515: }
6516: my $colsleft = $numinrow - $rem;
6517: if ($colsleft > 1 ) {
6518: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6519: ' </td>';
6520: } elsif ($colsleft == 1) {
6521: $output .= '<td class="LC_left_item"> </td>';
6522: }
6523: $output .= '</tr></table></td></tr>';
6524: return $output;
6525: }
1.28 raeburn 6526:
1.93 raeburn 6527: sub insttypes_row {
1.224 raeburn 6528: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6529: my %lt = &Apache::lonlocal::texthash (
6530: cansearch => 'Users allowed to search',
6531: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6532: lockablenames => 'User preference to lock name',
1.93 raeburn 6533: );
6534: my $showdom;
6535: if ($context eq 'cansearch') {
6536: $showdom = ' ('.$dom.')';
6537: }
1.165 raeburn 6538: my $class = 'LC_left_item';
6539: if ($context eq 'statustocreate') {
6540: $class = 'LC_right_item';
6541: }
1.224 raeburn 6542: my $css_class = ' class="LC_odd_row"';
6543: if ($rownum ne '') {
6544: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6545: }
6546: my $output = '<tr'.$css_class.'>'.
6547: '<td>'.$lt{$context}.$showdom.
6548: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6549: my $rem;
6550: if (ref($types) eq 'ARRAY') {
6551: for (my $i=0; $i<@{$types}; $i++) {
6552: if (defined($usertypes->{$types->[$i]})) {
6553: my $rem = $i%($numinrow);
6554: if ($rem == 0) {
6555: if ($i > 0) {
6556: $output .= '</tr>';
6557: }
6558: $output .= '<tr>';
1.23 raeburn 6559: }
1.26 raeburn 6560: my $check = ' ';
1.99 raeburn 6561: if (ref($settings) eq 'HASH') {
6562: if (ref($settings->{$context}) eq 'ARRAY') {
6563: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6564: $check = ' checked="checked" ';
6565: }
6566: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6567: $check = ' checked="checked" ';
6568: }
1.23 raeburn 6569: }
1.26 raeburn 6570: $output .= '<td class="LC_left_item">'.
6571: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6572: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6573: 'value="'.$types->[$i].'"'.$check.'/>'.
6574: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6575: }
6576: }
1.26 raeburn 6577: $rem = @{$types}%($numinrow);
1.23 raeburn 6578: }
6579: my $colsleft = $numinrow - $rem;
1.131 raeburn 6580: if (($rem == 0) && (@{$types} > 0)) {
6581: $output .= '<tr>';
6582: }
1.23 raeburn 6583: if ($colsleft > 1) {
1.25 raeburn 6584: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6585: } else {
1.25 raeburn 6586: $output .= '<td class="LC_left_item">';
1.23 raeburn 6587: }
6588: my $defcheck = ' ';
1.99 raeburn 6589: if (ref($settings) eq 'HASH') {
6590: if (ref($settings->{$context}) eq 'ARRAY') {
6591: if (grep(/^default$/,@{$settings->{$context}})) {
6592: $defcheck = ' checked="checked" ';
6593: }
6594: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6595: $defcheck = ' checked="checked" ';
6596: }
1.23 raeburn 6597: }
1.25 raeburn 6598: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6599: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6600: 'value="default"'.$defcheck.'/>'.
6601: $othertitle.'</label></span></td>'.
6602: '</tr></table></td></tr>';
6603: return $output;
1.23 raeburn 6604: }
6605:
6606: sub sorted_searchtitles {
6607: my %searchtitles = &Apache::lonlocal::texthash(
6608: 'uname' => 'username',
6609: 'lastname' => 'last name',
6610: 'lastfirst' => 'last name, first name',
6611: );
6612: my @titleorder = ('uname','lastname','lastfirst');
6613: return (\%searchtitles,\@titleorder);
6614: }
6615:
1.25 raeburn 6616: sub sorted_searchtypes {
6617: my %srchtypes_desc = (
6618: exact => 'is exact match',
6619: contains => 'contains ..',
6620: begins => 'begins with ..',
6621: );
6622: my @srchtypeorder = ('exact','begins','contains');
6623: return (\%srchtypes_desc,\@srchtypeorder);
6624: }
6625:
1.3 raeburn 6626: sub usertype_update_row {
6627: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6628: my $datatable;
6629: my $numinrow = 4;
6630: foreach my $type (@{$types}) {
6631: if (defined($usertypes->{$type})) {
6632: $$rownums ++;
6633: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6634: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6635: '</td><td class="LC_left_item"><table>';
6636: for (my $i=0; $i<@{$fields}; $i++) {
6637: my $rem = $i%($numinrow);
6638: if ($rem == 0) {
6639: if ($i > 0) {
6640: $datatable .= '</tr>';
6641: }
6642: $datatable .= '<tr>';
6643: }
6644: my $check = ' ';
1.39 raeburn 6645: if (ref($settings) eq 'HASH') {
6646: if (ref($settings->{'fields'}) eq 'HASH') {
6647: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6648: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6649: $check = ' checked="checked" ';
6650: }
1.3 raeburn 6651: }
6652: }
6653: }
6654:
6655: if ($i == @{$fields}-1) {
6656: my $colsleft = $numinrow - $rem;
6657: if ($colsleft > 1) {
6658: $datatable .= '<td colspan="'.$colsleft.'">';
6659: } else {
6660: $datatable .= '<td>';
6661: }
6662: } else {
6663: $datatable .= '<td>';
6664: }
1.8 raeburn 6665: $datatable .= '<span class="LC_nobreak"><label>'.
6666: '<input type="checkbox" name="updateable_'.$type.
6667: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6668: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6669: }
6670: $datatable .= '</tr></table></td></tr>';
6671: }
6672: }
6673: return $datatable;
1.1 raeburn 6674: }
6675:
6676: sub modify_login {
1.205 raeburn 6677: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6678: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6679: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6680: %title = ( coursecatalog => 'Display course catalog',
6681: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6682: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6683: newuser => 'Link for visitors to create a user account',
6684: loginheader => 'Log-in box header');
6685: @offon = ('off','on');
1.112 raeburn 6686: if (ref($domconfig{login}) eq 'HASH') {
6687: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6688: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6689: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6690: }
6691: }
6692: }
1.9 raeburn 6693: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6694: \%domconfig,\%loginhash);
1.188 raeburn 6695: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6696: foreach my $item (@toggles) {
6697: $loginhash{login}{$item} = $env{'form.'.$item};
6698: }
1.41 raeburn 6699: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6700: if (ref($colchanges{'login'}) eq 'HASH') {
6701: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6702: \%loginhash);
6703: }
1.110 raeburn 6704:
1.149 raeburn 6705: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6706: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6707: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6708: if (keys(%servers) > 1) {
6709: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6710: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6711: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6712: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6713: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6714: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6715: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6716: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6717: $changes{'loginvia'}{$lonhost} = 1;
6718: } else {
6719: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6720: $changes{'loginvia'}{$lonhost} = 1;
6721: }
6722: } else {
6723: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6724: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6725: $changes{'loginvia'}{$lonhost} = 1;
6726: }
6727: }
6728: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6729: foreach my $item (@loginvia_attribs) {
6730: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6731: }
6732: } else {
6733: foreach my $item (@loginvia_attribs) {
6734: my $new = $env{'form.'.$lonhost.'_'.$item};
6735: if (($item eq 'serverpath') && ($new eq 'custom')) {
6736: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6737: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6738: $new = '/';
6739: }
6740: }
6741: if (($item eq 'custompath') &&
6742: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6743: $new = '';
6744: }
6745: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6746: $changes{'loginvia'}{$lonhost} = 1;
6747: }
6748: if ($item eq 'exempt') {
1.256 raeburn 6749: $new = &check_exempt_addresses($new);
1.128 raeburn 6750: }
6751: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6752: }
6753: }
1.112 raeburn 6754: } else {
1.128 raeburn 6755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6757: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6758: foreach my $item (@loginvia_attribs) {
6759: my $new = $env{'form.'.$lonhost.'_'.$item};
6760: if (($item eq 'serverpath') && ($new eq 'custom')) {
6761: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6762: $new = '/';
6763: }
6764: }
6765: if (($item eq 'custompath') &&
6766: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6767: $new = '';
6768: }
6769: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6770: }
1.110 raeburn 6771: }
6772: }
6773: }
6774: }
1.119 raeburn 6775:
1.168 raeburn 6776: my $servadm = $r->dir_config('lonAdmEMail');
6777: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6778: if (ref($domconfig{'login'}) eq 'HASH') {
6779: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6780: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6781: if ($lang eq 'nolang') {
6782: push(@currlangs,$lang);
6783: } elsif (defined($langchoices{$lang})) {
6784: push(@currlangs,$lang);
6785: } else {
6786: next;
6787: }
6788: }
6789: }
6790: }
6791: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6792: if (@currlangs > 0) {
6793: foreach my $lang (@currlangs) {
6794: if (grep(/^\Q$lang\E$/,@delurls)) {
6795: $changes{'helpurl'}{$lang} = 1;
6796: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6797: $changes{'helpurl'}{$lang} = 1;
6798: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6799: push(@newlangs,$lang);
6800: } else {
6801: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6802: }
6803: }
6804: }
6805: unless (grep(/^nolang$/,@currlangs)) {
6806: if ($env{'form.loginhelpurl_nolang.filename'}) {
6807: $changes{'helpurl'}{'nolang'} = 1;
6808: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6809: push(@newlangs,'nolang');
6810: }
6811: }
6812: if ($env{'form.loginhelpurl_add_lang'}) {
6813: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6814: ($env{'form.loginhelpurl_add_file.filename'})) {
6815: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6816: $addedfile = $env{'form.loginhelpurl_add_lang'};
6817: }
6818: }
6819: if ((@newlangs > 0) || ($addedfile)) {
6820: my $error;
6821: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6822: if ($configuserok eq 'ok') {
6823: if ($switchserver) {
6824: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6825: } elsif ($author_ok eq 'ok') {
6826: my @allnew = @newlangs;
6827: if ($addedfile ne '') {
6828: push(@allnew,$addedfile);
6829: }
6830: foreach my $lang (@allnew) {
6831: my $formelem = 'loginhelpurl_'.$lang;
6832: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6833: $formelem = 'loginhelpurl_add_file';
6834: }
6835: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6836: "help/$lang",'','',$newfile{$lang});
6837: if ($result eq 'ok') {
6838: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6839: $changes{'helpurl'}{$lang} = 1;
6840: } else {
6841: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6842: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6843: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6844: (!grep(/^\Q$lang\E$/,@delurls))) {
6845: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6846: }
6847: }
6848: }
6849: } else {
6850: $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);
6851: }
6852: } else {
6853: $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);
6854: }
6855: if ($error) {
6856: &Apache::lonnet::logthis($error);
6857: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6858: }
6859: }
1.256 raeburn 6860:
6861: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6862: if (ref($domconfig{'login'}) eq 'HASH') {
6863: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6864: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6865: if ($domservers{$lonhost}) {
6866: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6867: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6868: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6869: }
6870: }
6871: }
6872: }
6873: }
6874: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6875: foreach my $lonhost (sort(keys(%domservers))) {
6876: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6877: $changes{'headtag'}{$lonhost} = 1;
6878: } else {
6879: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6880: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6881: }
6882: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6883: push(@newhosts,$lonhost);
6884: } elsif ($currheadtagurls{$lonhost}) {
6885: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6886: if ($currexempt{$lonhost}) {
6887: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6888: $changes{'headtag'}{$lonhost} = 1;
6889: }
6890: } elsif ($possexempt{$lonhost}) {
6891: $changes{'headtag'}{$lonhost} = 1;
6892: }
6893: if ($possexempt{$lonhost}) {
6894: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6895: }
6896: }
6897: }
6898: }
6899: if (@newhosts) {
6900: my $error;
6901: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6902: if ($configuserok eq 'ok') {
6903: if ($switchserver) {
6904: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6905: } elsif ($author_ok eq 'ok') {
6906: foreach my $lonhost (@newhosts) {
6907: my $formelem = 'loginheadtag_'.$lonhost;
6908: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6909: "login/headtag/$lonhost",'','',
6910: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6911: if ($result eq 'ok') {
6912: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6913: $changes{'headtag'}{$lonhost} = 1;
6914: if ($possexempt{$lonhost}) {
6915: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6916: }
6917: } else {
6918: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6919: $newheadtagurls{$lonhost},$result);
6920: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6921: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6922: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6923: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6924: }
6925: }
6926: }
6927: } else {
6928: $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);
6929: }
6930: } else {
6931: $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);
6932: }
6933: if ($error) {
6934: &Apache::lonnet::logthis($error);
6935: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6936: }
6937: }
1.169 raeburn 6938: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6939:
6940: my $defaulthelpfile = '/adm/loginproblems.html';
6941: my $defaulttext = &mt('Default in use');
6942:
1.1 raeburn 6943: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6944: $dom);
6945: if ($putresult eq 'ok') {
1.188 raeburn 6946: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6947: my %defaultchecked = (
6948: 'coursecatalog' => 'on',
1.188 raeburn 6949: 'helpdesk' => 'on',
1.42 raeburn 6950: 'adminmail' => 'off',
1.43 raeburn 6951: 'newuser' => 'off',
1.42 raeburn 6952: );
1.55 raeburn 6953: if (ref($domconfig{'login'}) eq 'HASH') {
6954: foreach my $item (@toggles) {
6955: if ($defaultchecked{$item} eq 'on') {
6956: if (($domconfig{'login'}{$item} eq '0') &&
6957: ($env{'form.'.$item} eq '1')) {
6958: $changes{$item} = 1;
6959: } elsif (($domconfig{'login'}{$item} eq '' ||
6960: $domconfig{'login'}{$item} eq '1') &&
6961: ($env{'form.'.$item} eq '0')) {
6962: $changes{$item} = 1;
6963: }
6964: } elsif ($defaultchecked{$item} eq 'off') {
6965: if (($domconfig{'login'}{$item} eq '1') &&
6966: ($env{'form.'.$item} eq '0')) {
6967: $changes{$item} = 1;
6968: } elsif (($domconfig{'login'}{$item} eq '' ||
6969: $domconfig{'login'}{$item} eq '0') &&
6970: ($env{'form.'.$item} eq '1')) {
6971: $changes{$item} = 1;
6972: }
1.42 raeburn 6973: }
6974: }
1.41 raeburn 6975: }
1.6 raeburn 6976: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6977: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6978: if (ref($lastactref) eq 'HASH') {
6979: $lastactref->{'domainconfig'} = 1;
6980: }
1.1 raeburn 6981: $resulttext = &mt('Changes made:').'<ul>';
6982: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6983: if ($item eq 'loginvia') {
1.112 raeburn 6984: if (ref($changes{$item}) eq 'HASH') {
6985: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6986: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6987: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6988: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6989: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6990: $protocol = 'http' if ($protocol ne 'https');
6991: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6992:
6993: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6994: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6995: } else {
6996: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6997: }
6998: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6999: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7000: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7001: }
7002: $resulttext .= '</li>';
7003: } else {
7004: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7005: }
1.112 raeburn 7006: } else {
1.128 raeburn 7007: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7008: }
7009: }
1.128 raeburn 7010: $resulttext .= '</ul></li>';
1.112 raeburn 7011: }
1.168 raeburn 7012: } elsif ($item eq 'helpurl') {
7013: if (ref($changes{$item}) eq 'HASH') {
7014: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7015: if (grep(/^\Q$lang\E$/,@delurls)) {
7016: my ($chg,$link);
7017: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7018: if ($lang eq 'nolang') {
7019: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7020: } else {
7021: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7022: }
7023: $resulttext .= '<li>'.$chg.'</li>';
7024: } else {
7025: my $chg;
7026: if ($lang eq 'nolang') {
7027: $chg = &mt('custom log-in help file for no preferred language');
7028: } else {
7029: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7030: }
7031: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7032: $loginhash{'login'}{'helpurl'}{$lang}.
7033: '?inhibitmenu=yes',$chg,600,500).
7034: '</li>';
7035: }
7036: }
7037: }
1.256 raeburn 7038: } elsif ($item eq 'headtag') {
7039: if (ref($changes{$item}) eq 'HASH') {
7040: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7041: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7042: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7043: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7044: $resulttext .= '<li><a href="'.
7045: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7046: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7047: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7048: if ($possexempt{$lonhost}) {
7049: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7050: } else {
7051: $resulttext .= &mt('included for any client IP');
7052: }
7053: $resulttext .= '</li>';
7054: }
7055: }
7056: }
1.169 raeburn 7057: } elsif ($item eq 'captcha') {
7058: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7059: my $chgtxt;
1.169 raeburn 7060: if ($loginhash{'login'}{$item} eq 'notused') {
7061: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7062: } else {
7063: my %captchas = &captcha_phrases();
7064: if ($captchas{$loginhash{'login'}{$item}}) {
7065: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7066: } else {
7067: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7068: }
7069: }
7070: $resulttext .= '<li>'.$chgtxt.'</li>';
7071: }
7072: } elsif ($item eq 'recaptchakeys') {
7073: if (ref($loginhash{'login'}) eq 'HASH') {
7074: my ($privkey,$pubkey);
7075: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7076: $pubkey = $loginhash{'login'}{$item}{'public'};
7077: $privkey = $loginhash{'login'}{$item}{'private'};
7078: }
7079: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7080: if (!$pubkey) {
7081: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7082: } else {
7083: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7084: }
7085: if (!$privkey) {
7086: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7087: } else {
1.251 raeburn 7088: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7089: }
7090: $chgtxt .= '</ul>';
7091: $resulttext .= '<li>'.$chgtxt.'</li>';
7092: }
1.269 raeburn 7093: } elsif ($item eq 'recaptchaversion') {
7094: if (ref($loginhash{'login'}) eq 'HASH') {
7095: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7096: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7097: '</li>';
7098: }
7099: }
1.41 raeburn 7100: } else {
7101: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7102: }
1.1 raeburn 7103: }
1.6 raeburn 7104: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7105: } else {
7106: $resulttext = &mt('No changes made to log-in page settings');
7107: }
7108: } else {
1.11 albertel 7109: $resulttext = '<span class="LC_error">'.
7110: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7111: }
1.6 raeburn 7112: if ($errors) {
1.9 raeburn 7113: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7114: $errors.'</ul>';
7115: }
7116: return $resulttext;
7117: }
7118:
1.256 raeburn 7119:
7120: sub check_exempt_addresses {
7121: my ($iplist) = @_;
7122: $iplist =~ s/^\s+//;
7123: $iplist =~ s/\s+$//;
7124: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7125: my (@okips,$new);
7126: foreach my $ip (@poss_ips) {
7127: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7128: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7129: push(@okips,$ip);
7130: }
7131: }
7132: }
7133: if (@okips > 0) {
7134: $new = join(',',@okips);
7135: } else {
7136: $new = '';
7137: }
7138: return $new;
7139: }
7140:
1.6 raeburn 7141: sub color_font_choices {
7142: my %choices =
7143: &Apache::lonlocal::texthash (
7144: img => "Header",
7145: bgs => "Background colors",
7146: links => "Link colors",
1.55 raeburn 7147: images => "Images",
1.6 raeburn 7148: font => "Font color",
1.201 raeburn 7149: fontmenu => "Font menu",
1.76 raeburn 7150: pgbg => "Page",
1.6 raeburn 7151: tabbg => "Header",
7152: sidebg => "Border",
7153: link => "Link",
7154: alink => "Active link",
7155: vlink => "Visited link",
7156: );
7157: return %choices;
7158: }
7159:
7160: sub modify_rolecolors {
1.205 raeburn 7161: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7162: my ($resulttext,%rolehash);
7163: $rolehash{'rolecolors'} = {};
1.55 raeburn 7164: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7165: if ($domconfig{'rolecolors'} eq '') {
7166: $domconfig{'rolecolors'} = {};
7167: }
7168: }
1.9 raeburn 7169: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7170: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7171: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7172: $dom);
7173: if ($putresult eq 'ok') {
7174: if (keys(%changes) > 0) {
1.41 raeburn 7175: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7176: if (ref($lastactref) eq 'HASH') {
7177: $lastactref->{'domainconfig'} = 1;
7178: }
1.6 raeburn 7179: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7180: $rolehash{'rolecolors'});
7181: } else {
7182: $resulttext = &mt('No changes made to default color schemes');
7183: }
7184: } else {
1.11 albertel 7185: $resulttext = '<span class="LC_error">'.
7186: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7187: }
7188: if ($errors) {
7189: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7190: $errors.'</ul>';
7191: }
7192: return $resulttext;
7193: }
7194:
7195: sub modify_colors {
1.9 raeburn 7196: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7197: my (%changes,%choices);
1.51 raeburn 7198: my @bgs;
1.6 raeburn 7199: my @links = ('link','alink','vlink');
1.41 raeburn 7200: my @logintext;
1.6 raeburn 7201: my @images;
7202: my $servadm = $r->dir_config('lonAdmEMail');
7203: my $errors;
1.200 raeburn 7204: my %defaults;
1.6 raeburn 7205: foreach my $role (@{$roles}) {
7206: if ($role eq 'login') {
1.12 raeburn 7207: %choices = &login_choices();
1.41 raeburn 7208: @logintext = ('textcol','bgcol');
1.12 raeburn 7209: } else {
7210: %choices = &color_font_choices();
7211: }
7212: if ($role eq 'login') {
1.41 raeburn 7213: @images = ('img','logo','domlogo','login');
1.51 raeburn 7214: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7215: } else {
7216: @images = ('img');
1.200 raeburn 7217: @bgs = ('pgbg','tabbg','sidebg');
7218: }
7219: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7220: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7221: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7222: }
7223: if ($role eq 'login') {
7224: foreach my $item (@logintext) {
1.234 raeburn 7225: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7226: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7227: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7228: }
7229: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 7230: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7231: }
7232: }
7233: } else {
1.234 raeburn 7234: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7235: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7236: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7237: }
7238: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 7239: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7240: }
1.6 raeburn 7241: }
1.200 raeburn 7242: foreach my $item (@bgs) {
1.234 raeburn 7243: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7244: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7245: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7246: }
7247: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 7248: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7249: }
7250: }
7251: foreach my $item (@links) {
1.234 raeburn 7252: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7253: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7254: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7255: }
7256: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 7257: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7258: }
1.6 raeburn 7259: }
1.46 raeburn 7260: my ($configuserok,$author_ok,$switchserver) =
7261: &config_check($dom,$confname,$servadm);
1.9 raeburn 7262: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7263: if (ref($domconfig->{$role}) ne 'HASH') {
7264: $domconfig->{$role} = {};
7265: }
1.8 raeburn 7266: foreach my $img (@images) {
1.70 raeburn 7267: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7268: if (defined($env{'form.login_showlogo_'.$img})) {
7269: $confhash->{$role}{'showlogo'}{$img} = 1;
7270: } else {
7271: $confhash->{$role}{'showlogo'}{$img} = 0;
7272: }
7273: }
1.18 albertel 7274: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7275: && !defined($domconfig->{$role}{$img})
7276: && !$env{'form.'.$role.'_del_'.$img}
7277: && $env{'form.'.$role.'_import_'.$img}) {
7278: # import the old configured image from the .tab setting
7279: # if they haven't provided a new one
7280: $domconfig->{$role}{$img} =
7281: $env{'form.'.$role.'_import_'.$img};
7282: }
1.6 raeburn 7283: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7284: my $error;
1.6 raeburn 7285: if ($configuserok eq 'ok') {
1.9 raeburn 7286: if ($switchserver) {
1.12 raeburn 7287: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7288: } else {
7289: if ($author_ok eq 'ok') {
7290: my ($result,$logourl) =
7291: &publishlogo($r,'upload',$role.'_'.$img,
7292: $dom,$confname,$img,$width,$height);
7293: if ($result eq 'ok') {
7294: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7295: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7296: } else {
1.12 raeburn 7297: $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 7298: }
7299: } else {
1.46 raeburn 7300: $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 7301: }
7302: }
7303: } else {
1.46 raeburn 7304: $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 7305: }
7306: if ($error) {
1.8 raeburn 7307: &Apache::lonnet::logthis($error);
1.11 albertel 7308: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7309: }
7310: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7311: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7312: my $error;
7313: if ($configuserok eq 'ok') {
7314: # is confname an author?
7315: if ($switchserver eq '') {
7316: if ($author_ok eq 'ok') {
7317: my ($result,$logourl) =
7318: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7319: $dom,$confname,$img,$width,$height);
7320: if ($result eq 'ok') {
7321: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7322: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7323: }
7324: }
7325: }
7326: }
1.6 raeburn 7327: }
7328: }
7329: }
7330: if (ref($domconfig) eq 'HASH') {
7331: if (ref($domconfig->{$role}) eq 'HASH') {
7332: foreach my $img (@images) {
7333: if ($domconfig->{$role}{$img} ne '') {
7334: if ($env{'form.'.$role.'_del_'.$img}) {
7335: $confhash->{$role}{$img} = '';
1.12 raeburn 7336: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7337: } else {
1.9 raeburn 7338: if ($confhash->{$role}{$img} eq '') {
7339: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7340: }
1.6 raeburn 7341: }
7342: } else {
7343: if ($env{'form.'.$role.'_del_'.$img}) {
7344: $confhash->{$role}{$img} = '';
1.12 raeburn 7345: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7346: }
7347: }
1.70 raeburn 7348: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7349: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7350: if ($confhash->{$role}{'showlogo'}{$img} ne
7351: $domconfig->{$role}{'showlogo'}{$img}) {
7352: $changes{$role}{'showlogo'}{$img} = 1;
7353: }
7354: } else {
7355: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7356: $changes{$role}{'showlogo'}{$img} = 1;
7357: }
7358: }
7359: }
7360: }
1.6 raeburn 7361: if ($domconfig->{$role}{'font'} ne '') {
7362: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7363: $changes{$role}{'font'} = 1;
7364: }
7365: } else {
7366: if ($confhash->{$role}{'font'}) {
7367: $changes{$role}{'font'} = 1;
7368: }
7369: }
1.107 raeburn 7370: if ($role ne 'login') {
7371: if ($domconfig->{$role}{'fontmenu'} ne '') {
7372: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7373: $changes{$role}{'fontmenu'} = 1;
7374: }
7375: } else {
7376: if ($confhash->{$role}{'fontmenu'}) {
7377: $changes{$role}{'fontmenu'} = 1;
7378: }
1.97 tempelho 7379: }
7380: }
1.6 raeburn 7381: foreach my $item (@bgs) {
7382: if ($domconfig->{$role}{$item} ne '') {
7383: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7384: $changes{$role}{'bgs'}{$item} = 1;
7385: }
7386: } else {
7387: if ($confhash->{$role}{$item}) {
7388: $changes{$role}{'bgs'}{$item} = 1;
7389: }
7390: }
7391: }
7392: foreach my $item (@links) {
7393: if ($domconfig->{$role}{$item} ne '') {
7394: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7395: $changes{$role}{'links'}{$item} = 1;
7396: }
7397: } else {
7398: if ($confhash->{$role}{$item}) {
7399: $changes{$role}{'links'}{$item} = 1;
7400: }
7401: }
7402: }
1.41 raeburn 7403: foreach my $item (@logintext) {
7404: if ($domconfig->{$role}{$item} ne '') {
7405: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7406: $changes{$role}{'logintext'}{$item} = 1;
7407: }
7408: } else {
7409: if ($confhash->{$role}{$item}) {
7410: $changes{$role}{'logintext'}{$item} = 1;
7411: }
7412: }
7413: }
1.6 raeburn 7414: } else {
7415: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7416: \@logintext,$confhash,\%changes);
1.6 raeburn 7417: }
7418: } else {
7419: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7420: \@logintext,$confhash,\%changes);
1.6 raeburn 7421: }
7422: }
7423: return ($errors,%changes);
7424: }
7425:
1.46 raeburn 7426: sub config_check {
7427: my ($dom,$confname,$servadm) = @_;
7428: my ($configuserok,$author_ok,$switchserver,%currroles);
7429: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7430: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7431: $confname,$servadm);
7432: if ($configuserok eq 'ok') {
7433: $switchserver = &check_switchserver($dom,$confname);
7434: if ($switchserver eq '') {
7435: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7436: }
7437: }
7438: return ($configuserok,$author_ok,$switchserver);
7439: }
7440:
1.6 raeburn 7441: sub default_change_checker {
1.41 raeburn 7442: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7443: foreach my $item (@{$links}) {
7444: if ($confhash->{$role}{$item}) {
7445: $changes->{$role}{'links'}{$item} = 1;
7446: }
7447: }
7448: foreach my $item (@{$bgs}) {
7449: if ($confhash->{$role}{$item}) {
7450: $changes->{$role}{'bgs'}{$item} = 1;
7451: }
7452: }
1.41 raeburn 7453: foreach my $item (@{$logintext}) {
7454: if ($confhash->{$role}{$item}) {
7455: $changes->{$role}{'logintext'}{$item} = 1;
7456: }
7457: }
1.6 raeburn 7458: foreach my $img (@{$images}) {
7459: if ($env{'form.'.$role.'_del_'.$img}) {
7460: $confhash->{$role}{$img} = '';
1.12 raeburn 7461: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7462: }
1.70 raeburn 7463: if ($role eq 'login') {
7464: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7465: $changes->{$role}{'showlogo'}{$img} = 1;
7466: }
7467: }
1.6 raeburn 7468: }
7469: if ($confhash->{$role}{'font'}) {
7470: $changes->{$role}{'font'} = 1;
7471: }
1.48 raeburn 7472: }
1.6 raeburn 7473:
7474: sub display_colorchgs {
7475: my ($dom,$changes,$roles,$confhash) = @_;
7476: my (%choices,$resulttext);
7477: if (!grep(/^login$/,@{$roles})) {
7478: $resulttext = &mt('Changes made:').'<br />';
7479: }
7480: foreach my $role (@{$roles}) {
7481: if ($role eq 'login') {
7482: %choices = &login_choices();
7483: } else {
7484: %choices = &color_font_choices();
7485: }
7486: if (ref($changes->{$role}) eq 'HASH') {
7487: if ($role ne 'login') {
7488: $resulttext .= '<h4>'.&mt($role).'</h4>';
7489: }
7490: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7491: if ($role ne 'login') {
7492: $resulttext .= '<ul>';
7493: }
7494: if (ref($changes->{$role}{$key}) eq 'HASH') {
7495: if ($role ne 'login') {
7496: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7497: }
7498: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7499: if (($role eq 'login') && ($key eq 'showlogo')) {
7500: if ($confhash->{$role}{$key}{$item}) {
7501: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7502: } else {
7503: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7504: }
7505: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7506: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7507: } else {
1.12 raeburn 7508: my $newitem = $confhash->{$role}{$item};
7509: if ($key eq 'images') {
7510: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7511: }
7512: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7513: }
7514: }
7515: if ($role ne 'login') {
7516: $resulttext .= '</ul></li>';
7517: }
7518: } else {
7519: if ($confhash->{$role}{$key} eq '') {
7520: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7521: } else {
7522: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7523: }
7524: }
7525: if ($role ne 'login') {
7526: $resulttext .= '</ul>';
7527: }
7528: }
7529: }
7530: }
1.3 raeburn 7531: return $resulttext;
1.1 raeburn 7532: }
7533:
1.9 raeburn 7534: sub thumb_dimensions {
7535: return ('200','50');
7536: }
7537:
1.16 raeburn 7538: sub check_dimensions {
7539: my ($inputfile) = @_;
7540: my ($fullwidth,$fullheight);
7541: if ($inputfile =~ m|^[/\w.\-]+$|) {
7542: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7543: my $imageinfo = <PIPE>;
7544: if (!close(PIPE)) {
7545: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7546: }
7547: chomp($imageinfo);
7548: my ($fullsize) =
1.21 raeburn 7549: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7550: if ($fullsize) {
7551: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7552: }
7553: }
7554: }
7555: return ($fullwidth,$fullheight);
7556: }
7557:
1.9 raeburn 7558: sub check_configuser {
7559: my ($uhome,$dom,$confname,$servadm) = @_;
7560: my ($configuserok,%currroles);
7561: if ($uhome eq 'no_host') {
7562: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7563: my $configpass = &LONCAPA::Enrollment::create_password();
7564: $configuserok =
7565: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7566: $configpass,'','','','','',undef,$servadm);
7567: } else {
7568: $configuserok = 'ok';
7569: %currroles =
7570: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7571: }
7572: return ($configuserok,%currroles);
7573: }
7574:
7575: sub check_authorstatus {
7576: my ($dom,$confname,%currroles) = @_;
7577: my $author_ok;
1.40 raeburn 7578: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7579: my $start = time;
7580: my $end = 0;
7581: $author_ok =
7582: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7583: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7584: } else {
7585: $author_ok = 'ok';
7586: }
7587: return $author_ok;
7588: }
7589:
7590: sub publishlogo {
1.46 raeburn 7591: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7592: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7593: if ($action eq 'upload') {
7594: $fname=$env{'form.'.$formname.'.filename'};
7595: chop($env{'form.'.$formname});
7596: } else {
7597: ($fname) = ($formname =~ /([^\/]+)$/);
7598: }
1.46 raeburn 7599: if ($savefileas ne '') {
7600: $fname = $savefileas;
7601: }
1.9 raeburn 7602: $fname=&Apache::lonnet::clean_filename($fname);
7603: # See if there is anything left
7604: unless ($fname) { return ('error: no uploaded file'); }
7605: $fname="$subdir/$fname";
1.210 raeburn 7606: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7607: my $filepath="$docroot/priv";
7608: my $relpath = "$dom/$confname";
1.9 raeburn 7609: my ($fnamepath,$file,$fetchthumb);
7610: $file=$fname;
7611: if ($fname=~m|/|) {
7612: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7613: }
1.164 raeburn 7614: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7615: my $count;
1.164 raeburn 7616: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7617: $filepath.="/$parts[$count]";
7618: if ((-e $filepath)!=1) {
7619: mkdir($filepath,02770);
7620: }
7621: }
7622: # Check for bad extension and disallow upload
7623: if ($file=~/\.(\w+)$/ &&
7624: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7625: $output =
1.207 bisitz 7626: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7627: } elsif ($file=~/\.(\w+)$/ &&
7628: !defined(&Apache::loncommon::fileembstyle($1))) {
7629: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7630: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7631: $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 7632: } elsif (-d "$filepath/$file") {
1.195 bisitz 7633: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7634: } else {
7635: my $source = $filepath.'/'.$file;
7636: my $logfile;
7637: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7638: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7639: }
7640: print $logfile
7641: "\n================= Publish ".localtime()." ================\n".
7642: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7643: # Save the file
7644: if (!open(FH,'>'.$source)) {
7645: &Apache::lonnet::logthis('Failed to create '.$source);
7646: return (&mt('Failed to create file'));
7647: }
7648: if ($action eq 'upload') {
7649: if (!print FH ($env{'form.'.$formname})) {
7650: &Apache::lonnet::logthis('Failed to write to '.$source);
7651: return (&mt('Failed to write file'));
7652: }
7653: } else {
7654: my $original = &Apache::lonnet::filelocation('',$formname);
7655: if(!copy($original,$source)) {
7656: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7657: return (&mt('Failed to write file'));
7658: }
7659: }
7660: close(FH);
7661: chmod(0660, $source); # Permissions to rw-rw---.
7662:
7663: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7664: my $copyfile=$targetdir.'/'.$file;
7665:
7666: my @parts=split(/\//,$targetdir);
7667: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7668: for (my $count=5;$count<=$#parts;$count++) {
7669: $path.="/$parts[$count]";
7670: if (!-e $path) {
7671: print $logfile "\nCreating directory ".$path;
7672: mkdir($path,02770);
7673: }
7674: }
7675: my $versionresult;
7676: if (-e $copyfile) {
7677: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7678: } else {
7679: $versionresult = 'ok';
7680: }
7681: if ($versionresult eq 'ok') {
7682: if (copy($source,$copyfile)) {
7683: print $logfile "\nCopied original source to ".$copyfile."\n";
7684: $output = 'ok';
7685: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7686: push(@{$modified_urls},[$copyfile,$source]);
7687: my $metaoutput =
7688: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7689: unless ($registered_cleanup) {
7690: my $handlers = $r->get_handlers('PerlCleanupHandler');
7691: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7692: $registered_cleanup=1;
7693: }
1.9 raeburn 7694: } else {
7695: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7696: $output = &mt('Failed to copy file to RES space').", $!";
7697: }
7698: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7699: my $inputfile = $filepath.'/'.$file;
7700: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7701: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7702: if ($fullwidth ne '' && $fullheight ne '') {
7703: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7704: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7705: system("convert -sample $thumbsize $inputfile $outfile");
7706: chmod(0660, $filepath.'/tn-'.$file);
7707: if (-e $outfile) {
7708: my $copyfile=$targetdir.'/tn-'.$file;
7709: if (copy($outfile,$copyfile)) {
7710: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7711: my $thumb_metaoutput =
7712: &write_metadata($dom,$confname,$formname,
7713: $targetdir,'tn-'.$file,$logfile);
7714: push(@{$modified_urls},[$copyfile,$outfile]);
7715: unless ($registered_cleanup) {
7716: my $handlers = $r->get_handlers('PerlCleanupHandler');
7717: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7718: $registered_cleanup=1;
7719: }
1.267 raeburn 7720: $madethumb = 1;
1.16 raeburn 7721: } else {
7722: print $logfile "\nUnable to write ".$copyfile.
7723: ':'.$!."\n";
7724: }
7725: }
1.9 raeburn 7726: }
7727: }
7728: }
7729: } else {
7730: $output = $versionresult;
7731: }
7732: }
1.267 raeburn 7733: return ($output,$logourl,$madethumb);
1.9 raeburn 7734: }
7735:
7736: sub logo_versioning {
7737: my ($targetdir,$file,$logfile) = @_;
7738: my $target = $targetdir.'/'.$file;
7739: my ($maxversion,$fn,$extn,$output);
7740: $maxversion = 0;
7741: if ($file =~ /^(.+)\.(\w+)$/) {
7742: $fn=$1;
7743: $extn=$2;
7744: }
7745: opendir(DIR,$targetdir);
7746: while (my $filename=readdir(DIR)) {
7747: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7748: $maxversion=($1>$maxversion)?$1:$maxversion;
7749: }
7750: }
7751: $maxversion++;
7752: print $logfile "\nCreating old version ".$maxversion."\n";
7753: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7754: if (copy($target,$copyfile)) {
7755: print $logfile "Copied old target to ".$copyfile."\n";
7756: $copyfile=$copyfile.'.meta';
7757: if (copy($target.'.meta',$copyfile)) {
7758: print $logfile "Copied old target metadata to ".$copyfile."\n";
7759: $output = 'ok';
7760: } else {
7761: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7762: $output = &mt('Failed to copy old meta').", $!, ";
7763: }
7764: } else {
7765: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7766: $output = &mt('Failed to copy old target').", $!, ";
7767: }
7768: return $output;
7769: }
7770:
7771: sub write_metadata {
7772: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7773: my (%metadatafields,%metadatakeys,$output);
7774: $metadatafields{'title'}=$formname;
7775: $metadatafields{'creationdate'}=time;
7776: $metadatafields{'lastrevisiondate'}=time;
7777: $metadatafields{'copyright'}='public';
7778: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7779: $env{'user.domain'};
7780: $metadatafields{'authorspace'}=$confname.':'.$dom;
7781: $metadatafields{'domain'}=$dom;
7782: {
7783: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7784: my $mfh;
1.155 raeburn 7785: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7786: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7787: unless ($_=~/\./) {
7788: my $unikey=$_;
7789: $unikey=~/^([A-Za-z]+)/;
7790: my $tag=$1;
7791: $tag=~tr/A-Z/a-z/;
7792: print $mfh "\n\<$tag";
7793: foreach (split(/\,/,$metadatakeys{$unikey})) {
7794: my $value=$metadatafields{$unikey.'.'.$_};
7795: $value=~s/\"/\'\'/g;
7796: print $mfh ' '.$_.'="'.$value.'"';
7797: }
7798: print $mfh '>'.
7799: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7800: .'</'.$tag.'>';
7801: }
7802: }
7803: $output = 'ok';
7804: print $logfile "\nWrote metadata";
7805: close($mfh);
7806: } else {
7807: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7808: $output = &mt('Could not write metadata');
7809: }
7810: }
1.155 raeburn 7811: return $output;
7812: }
7813:
7814: sub notifysubscribed {
7815: foreach my $targetsource (@{$modified_urls}){
7816: next unless (ref($targetsource) eq 'ARRAY');
7817: my ($target,$source)=@{$targetsource};
7818: if ($source ne '') {
7819: if (open(my $logfh,'>>'.$source.'.log')) {
7820: print $logfh "\nCleanup phase: Notifications\n";
7821: my @subscribed=&subscribed_hosts($target);
7822: foreach my $subhost (@subscribed) {
7823: print $logfh "\nNotifying host ".$subhost.':';
7824: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7825: print $logfh $reply;
7826: }
7827: my @subscribedmeta=&subscribed_hosts("$target.meta");
7828: foreach my $subhost (@subscribedmeta) {
7829: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7830: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7831: $subhost);
7832: print $logfh $reply;
7833: }
7834: print $logfh "\n============ Done ============\n";
1.160 raeburn 7835: close($logfh);
1.155 raeburn 7836: }
7837: }
7838: }
7839: return OK;
7840: }
7841:
7842: sub subscribed_hosts {
7843: my ($target) = @_;
7844: my @subscribed;
7845: if (open(my $fh,"<$target.subscription")) {
7846: while (my $subline=<$fh>) {
7847: if ($subline =~ /^($match_lonid):/) {
7848: my $host = $1;
7849: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7850: unless (grep(/^\Q$host\E$/,@subscribed)) {
7851: push(@subscribed,$host);
7852: }
7853: }
7854: }
7855: }
7856: }
7857: return @subscribed;
1.9 raeburn 7858: }
7859:
7860: sub check_switchserver {
7861: my ($dom,$confname) = @_;
7862: my ($allowed,$switchserver);
7863: my $home = &Apache::lonnet::homeserver($confname,$dom);
7864: if ($home eq 'no_host') {
7865: $home = &Apache::lonnet::domain($dom,'primary');
7866: }
7867: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7868: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7869: if (!$allowed) {
1.180 raeburn 7870: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7871: }
7872: return $switchserver;
7873: }
7874:
1.1 raeburn 7875: sub modify_quotas {
1.216 raeburn 7876: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7877: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7878: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7879: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7880: $validationfieldsref);
1.86 raeburn 7881: if ($action eq 'quotas') {
7882: $context = 'tools';
1.163 raeburn 7883: } else {
1.86 raeburn 7884: $context = $action;
7885: }
7886: if ($context eq 'requestcourses') {
1.271 raeburn 7887: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7888: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7889: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7890: %titles = &courserequest_titles();
7891: $toolregexp = join('|',@usertools);
7892: %conditions = &courserequest_conditions();
1.216 raeburn 7893: $confname = $dom.'-domainconfig';
7894: my $servadm = $r->dir_config('lonAdmEMail');
7895: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7896: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7897: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7898: } elsif ($context eq 'requestauthor') {
7899: @usertools = ('author');
7900: %titles = &authorrequest_titles();
1.86 raeburn 7901: } else {
1.162 raeburn 7902: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7903: %titles = &tool_titles();
1.86 raeburn 7904: }
1.212 raeburn 7905: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7906: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7907: foreach my $key (keys(%env)) {
1.101 raeburn 7908: if ($context eq 'requestcourses') {
7909: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7910: my $item = $1;
7911: my $type = $2;
7912: if ($type =~ /^limit_(.+)/) {
7913: $limithash{$item}{$1} = $env{$key};
7914: } else {
7915: $confhash{$item}{$type} = $env{$key};
7916: }
7917: }
1.163 raeburn 7918: } elsif ($context eq 'requestauthor') {
7919: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7920: $confhash{$1} = $env{$key};
7921: }
1.101 raeburn 7922: } else {
1.86 raeburn 7923: if ($key =~ /^form\.quota_(.+)$/) {
7924: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7925: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7926: $confhash{'authorquota'}{$1} = $env{$key};
7927: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7928: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7929: }
1.72 raeburn 7930: }
7931: }
1.163 raeburn 7932: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7933: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7934: @approvalnotify = sort(@approvalnotify);
7935: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 7936: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 7937: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7938: foreach my $type (@hasuniquecode) {
7939: if (grep(/^\Q$type\E$/,@crstypes)) {
7940: $confhash{'uniquecode'}{$type} = 1;
7941: }
1.216 raeburn 7942: }
1.242 raeburn 7943: my (%newbook,%allpos);
1.216 raeburn 7944: if ($context eq 'requestcourses') {
1.242 raeburn 7945: foreach my $type ('textbooks','templates') {
7946: @{$allpos{$type}} = ();
7947: my $invalid;
7948: if ($type eq 'textbooks') {
7949: $invalid = &mt('Invalid LON-CAPA course for textbook');
7950: } else {
7951: $invalid = &mt('Invalid LON-CAPA course for template');
7952: }
7953: if ($env{'form.'.$type.'_addbook'}) {
7954: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7955: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7956: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7957: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7958: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7959: } else {
7960: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7961: my $position = $env{'form.'.$type.'_addbook_pos'};
7962: $position =~ s/\D+//g;
7963: if ($position ne '') {
7964: $allpos{$type}[$position] = $newbook{$type};
7965: }
1.216 raeburn 7966: }
1.242 raeburn 7967: } else {
7968: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 7969: }
7970: }
1.242 raeburn 7971: }
1.216 raeburn 7972: }
1.102 raeburn 7973: if (ref($domconfig{$action}) eq 'HASH') {
7974: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7975: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7976: $changes{'notify'}{'approval'} = 1;
7977: }
7978: } else {
1.144 raeburn 7979: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7980: $changes{'notify'}{'approval'} = 1;
7981: }
7982: }
1.218 raeburn 7983: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7984: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7985: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7986: unless ($confhash{'uniquecode'}{$crstype}) {
7987: $changes{'uniquecode'} = 1;
7988: }
7989: }
7990: unless ($changes{'uniquecode'}) {
7991: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7992: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7993: $changes{'uniquecode'} = 1;
7994: }
7995: }
7996: }
7997: } else {
7998: $changes{'uniquecode'} = 1;
7999: }
8000: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8001: $changes{'uniquecode'} = 1;
1.216 raeburn 8002: }
8003: if ($context eq 'requestcourses') {
1.242 raeburn 8004: foreach my $type ('textbooks','templates') {
8005: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8006: my %deletions;
8007: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8008: if (@todelete) {
8009: map { $deletions{$_} = 1; } @todelete;
8010: }
8011: my %imgdeletions;
8012: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8013: if (@todeleteimages) {
8014: map { $imgdeletions{$_} = 1; } @todeleteimages;
8015: }
8016: my $maxnum = $env{'form.'.$type.'_maxnum'};
8017: for (my $i=0; $i<=$maxnum; $i++) {
8018: my $itemid = $env{'form.'.$type.'_id_'.$i};
8019: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8020: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8021: if ($deletions{$key}) {
8022: if ($domconfig{$action}{$type}{$key}{'image'}) {
8023: #FIXME need to obsolete item in RES space
8024: }
8025: next;
8026: } else {
8027: my $newpos = $env{'form.'.$itemid};
8028: $newpos =~ s/\D+//g;
1.243 raeburn 8029: foreach my $item ('subject','title','publisher','author') {
8030: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8031: ($type eq 'templates'));
1.242 raeburn 8032: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8033: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8034: $changes{$type}{$key} = 1;
8035: }
8036: }
8037: $allpos{$type}[$newpos] = $key;
8038: }
8039: if ($imgdeletions{$key}) {
8040: $changes{$type}{$key} = 1;
1.216 raeburn 8041: #FIXME need to obsolete item in RES space
1.242 raeburn 8042: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8043: my ($cdom,$cnum) = split(/_/,$key);
8044: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8045: $cdom,$cnum,$type,$configuserok,
8046: $switchserver,$author_ok);
8047: if ($imgurl) {
8048: $confhash{$type}{$key}{'image'} = $imgurl;
8049: $changes{$type}{$key} = 1;
1.216 raeburn 8050: }
1.242 raeburn 8051: if ($error) {
8052: &Apache::lonnet::logthis($error);
8053: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8054: }
8055: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8056: $confhash{$type}{$key}{'image'} =
8057: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8058: }
8059: }
8060: }
8061: }
8062: }
8063: }
1.102 raeburn 8064: } else {
1.144 raeburn 8065: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8066: $changes{'notify'}{'approval'} = 1;
8067: }
1.218 raeburn 8068: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8069: $changes{'uniquecode'} = 1;
8070: }
8071: }
8072: if ($context eq 'requestcourses') {
1.242 raeburn 8073: foreach my $type ('textbooks','templates') {
8074: if ($newbook{$type}) {
8075: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8076: foreach my $item ('subject','title','publisher','author') {
8077: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8078: ($type eq 'template'));
1.242 raeburn 8079: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8080: if ($env{'form.'.$type.'_addbook_'.$item}) {
8081: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8082: }
8083: }
8084: if ($type eq 'textbooks') {
8085: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8086: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8087: my ($imageurl,$error) =
8088: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8089: $configuserok,$switchserver,$author_ok);
8090: if ($imageurl) {
8091: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8092: }
8093: if ($error) {
8094: &Apache::lonnet::logthis($error);
8095: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8096: }
8097: }
1.216 raeburn 8098: }
8099: }
1.242 raeburn 8100: if (@{$allpos{$type}} > 0) {
8101: my $idx = 0;
8102: foreach my $item (@{$allpos{$type}}) {
8103: if ($item ne '') {
8104: $confhash{$type}{$item}{'order'} = $idx;
8105: if (ref($domconfig{$action}) eq 'HASH') {
8106: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8107: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8108: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8109: $changes{$type}{$item} = 1;
8110: }
1.216 raeburn 8111: }
8112: }
8113: }
1.242 raeburn 8114: $idx ++;
1.216 raeburn 8115: }
8116: }
8117: }
8118: }
1.235 raeburn 8119: if (ref($validationitemsref) eq 'ARRAY') {
8120: foreach my $item (@{$validationitemsref}) {
8121: if ($item eq 'fields') {
8122: my @changed;
8123: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8124: if (@{$confhash{'validation'}{$item}} > 0) {
8125: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8126: }
1.266 raeburn 8127: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8128: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8129: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8130: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8131: $domconfig{'requestcourses'}{'validation'}{$item});
8132: } else {
8133: @changed = @{$confhash{'validation'}{$item}};
8134: }
1.235 raeburn 8135: } else {
8136: @changed = @{$confhash{'validation'}{$item}};
8137: }
8138: } else {
8139: @changed = @{$confhash{'validation'}{$item}};
8140: }
8141: if (@changed) {
8142: if ($confhash{'validation'}{$item}) {
8143: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8144: } else {
8145: $changes{'validation'}{$item} = &mt('None');
8146: }
8147: }
8148: } else {
8149: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8150: if ($item eq 'markup') {
8151: if ($env{'form.requestcourses_validation_'.$item}) {
8152: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8153: }
8154: }
1.266 raeburn 8155: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8156: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8157: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8158: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8159: }
8160: } else {
8161: if ($confhash{'validation'}{$item} ne '') {
8162: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8163: }
1.235 raeburn 8164: }
8165: } else {
8166: if ($confhash{'validation'}{$item} ne '') {
8167: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8168: }
8169: }
8170: }
8171: }
8172: }
8173: if ($env{'form.validationdc'}) {
8174: my $newval = $env{'form.validationdc'};
8175: my %domcoords = &get_active_dcs($dom);
8176: if (exists($domcoords{$newval})) {
8177: $confhash{'validation'}{'dc'} = $newval;
8178: }
8179: }
8180: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 8181: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8182: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8183: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8184: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8185: if ($confhash{'validation'}{'dc'} eq '') {
8186: $changes{'validation'}{'dc'} = &mt('None');
8187: } else {
8188: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8189: }
1.235 raeburn 8190: }
1.266 raeburn 8191: } elsif ($confhash{'validation'}{'dc'} ne '') {
8192: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 8193: }
8194: } elsif ($confhash{'validation'}{'dc'} ne '') {
8195: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8196: }
8197: } elsif ($confhash{'validation'}{'dc'} ne '') {
8198: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 8199: }
8200: } else {
8201: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8202: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8203: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8204: $changes{'validation'}{'dc'} = &mt('None');
8205: }
8206: }
1.235 raeburn 8207: }
8208: }
1.102 raeburn 8209: }
8210: } else {
1.86 raeburn 8211: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 8212: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8213: }
1.72 raeburn 8214: foreach my $item (@usertools) {
8215: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8216: my $unset;
1.101 raeburn 8217: if ($context eq 'requestcourses') {
1.104 raeburn 8218: $unset = '0';
8219: if ($type eq '_LC_adv') {
8220: $unset = '';
8221: }
1.101 raeburn 8222: if ($confhash{$item}{$type} eq 'autolimit') {
8223: $confhash{$item}{$type} .= '=';
8224: unless ($limithash{$item}{$type} =~ /\D/) {
8225: $confhash{$item}{$type} .= $limithash{$item}{$type};
8226: }
8227: }
1.163 raeburn 8228: } elsif ($context eq 'requestauthor') {
8229: $unset = '0';
8230: if ($type eq '_LC_adv') {
8231: $unset = '';
8232: }
1.72 raeburn 8233: } else {
1.101 raeburn 8234: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8235: $confhash{$item}{$type} = 1;
8236: } else {
8237: $confhash{$item}{$type} = 0;
8238: }
1.72 raeburn 8239: }
1.86 raeburn 8240: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 8241: if ($action eq 'requestauthor') {
8242: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8243: $changes{$type} = 1;
8244: }
8245: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8246: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8247: $changes{$item}{$type} = 1;
8248: }
8249: } else {
8250: if ($context eq 'requestcourses') {
1.104 raeburn 8251: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8252: $changes{$item}{$type} = 1;
8253: }
8254: } else {
8255: if (!$confhash{$item}{$type}) {
8256: $changes{$item}{$type} = 1;
8257: }
8258: }
8259: }
8260: } else {
8261: if ($context eq 'requestcourses') {
1.104 raeburn 8262: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8263: $changes{$item}{$type} = 1;
8264: }
1.163 raeburn 8265: } elsif ($context eq 'requestauthor') {
8266: if ($confhash{$type} ne $unset) {
8267: $changes{$type} = 1;
8268: }
1.72 raeburn 8269: } else {
8270: if (!$confhash{$item}{$type}) {
8271: $changes{$item}{$type} = 1;
8272: }
8273: }
8274: }
1.1 raeburn 8275: }
8276: }
1.163 raeburn 8277: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8278: if (ref($domconfig{'quotas'}) eq 'HASH') {
8279: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8280: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8281: if (exists($confhash{'defaultquota'}{$key})) {
8282: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8283: $changes{'defaultquota'}{$key} = 1;
8284: }
8285: } else {
8286: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8287: }
8288: }
1.86 raeburn 8289: } else {
8290: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8291: if (exists($confhash{'defaultquota'}{$key})) {
8292: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8293: $changes{'defaultquota'}{$key} = 1;
8294: }
8295: } else {
8296: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8297: }
1.1 raeburn 8298: }
8299: }
1.197 raeburn 8300: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8301: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8302: if (exists($confhash{'authorquota'}{$key})) {
8303: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8304: $changes{'authorquota'}{$key} = 1;
8305: }
8306: } else {
8307: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8308: }
8309: }
8310: }
1.1 raeburn 8311: }
1.86 raeburn 8312: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8313: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8314: if (ref($domconfig{'quotas'}) eq 'HASH') {
8315: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8316: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8317: $changes{'defaultquota'}{$key} = 1;
8318: }
8319: } else {
8320: if (!exists($domconfig{'quotas'}{$key})) {
8321: $changes{'defaultquota'}{$key} = 1;
8322: }
1.72 raeburn 8323: }
8324: } else {
1.86 raeburn 8325: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8326: }
1.1 raeburn 8327: }
8328: }
1.197 raeburn 8329: if (ref($confhash{'authorquota'}) eq 'HASH') {
8330: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8331: if (ref($domconfig{'quotas'}) eq 'HASH') {
8332: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8333: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8334: $changes{'authorquota'}{$key} = 1;
8335: }
8336: } else {
8337: $changes{'authorquota'}{$key} = 1;
8338: }
8339: } else {
8340: $changes{'authorquota'}{$key} = 1;
8341: }
8342: }
8343: }
1.1 raeburn 8344: }
1.72 raeburn 8345:
1.163 raeburn 8346: if ($context eq 'requestauthor') {
8347: $domdefaults{'requestauthor'} = \%confhash;
8348: } else {
8349: foreach my $key (keys(%confhash)) {
1.242 raeburn 8350: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8351: $domdefaults{$key} = $confhash{$key};
8352: }
1.163 raeburn 8353: }
1.72 raeburn 8354: }
1.163 raeburn 8355:
1.1 raeburn 8356: my %quotahash = (
1.86 raeburn 8357: $action => { %confhash }
1.1 raeburn 8358: );
8359: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8360: $dom);
8361: if ($putresult eq 'ok') {
8362: if (keys(%changes) > 0) {
1.72 raeburn 8363: my $cachetime = 24*60*60;
8364: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8365: if (ref($lastactref) eq 'HASH') {
8366: $lastactref->{'domdefaults'} = 1;
8367: }
1.1 raeburn 8368: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8369: unless (($context eq 'requestcourses') ||
1.163 raeburn 8370: ($context eq 'requestauthor')) {
1.86 raeburn 8371: if (ref($changes{'defaultquota'}) eq 'HASH') {
8372: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8373: foreach my $type (@{$types},'default') {
8374: if (defined($changes{'defaultquota'}{$type})) {
8375: my $typetitle = $usertypes->{$type};
8376: if ($type eq 'default') {
8377: $typetitle = $othertitle;
8378: }
1.213 raeburn 8379: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8380: }
8381: }
1.86 raeburn 8382: $resulttext .= '</ul></li>';
1.72 raeburn 8383: }
1.197 raeburn 8384: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8385: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8386: foreach my $type (@{$types},'default') {
8387: if (defined($changes{'authorquota'}{$type})) {
8388: my $typetitle = $usertypes->{$type};
8389: if ($type eq 'default') {
8390: $typetitle = $othertitle;
8391: }
1.213 raeburn 8392: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8393: }
8394: }
8395: $resulttext .= '</ul></li>';
8396: }
1.72 raeburn 8397: }
1.80 raeburn 8398: my %newenv;
1.72 raeburn 8399: foreach my $item (@usertools) {
1.163 raeburn 8400: my (%haschgs,%inconf);
8401: if ($context eq 'requestauthor') {
8402: %haschgs = %changes;
1.210 raeburn 8403: %inconf = %confhash;
1.163 raeburn 8404: } else {
8405: if (ref($changes{$item}) eq 'HASH') {
8406: %haschgs = %{$changes{$item}};
8407: }
8408: if (ref($confhash{$item}) eq 'HASH') {
8409: %inconf = %{$confhash{$item}};
8410: }
8411: }
8412: if (keys(%haschgs) > 0) {
1.80 raeburn 8413: my $newacc =
8414: &Apache::lonnet::usertools_access($env{'user.name'},
8415: $env{'user.domain'},
1.86 raeburn 8416: $item,'reload',$context);
1.210 raeburn 8417: if (($context eq 'requestcourses') ||
1.163 raeburn 8418: ($context eq 'requestauthor')) {
1.108 raeburn 8419: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8420: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8421: }
8422: } else {
8423: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8424: $newenv{'environment.availabletools.'.$item} = $newacc;
8425: }
1.80 raeburn 8426: }
1.163 raeburn 8427: unless ($context eq 'requestauthor') {
8428: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8429: }
1.72 raeburn 8430: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8431: if ($haschgs{$type}) {
1.72 raeburn 8432: my $typetitle = $usertypes->{$type};
8433: if ($type eq 'default') {
8434: $typetitle = $othertitle;
8435: } elsif ($type eq '_LC_adv') {
8436: $typetitle = 'LON-CAPA Advanced Users';
8437: }
1.163 raeburn 8438: if ($inconf{$type}) {
1.101 raeburn 8439: if ($context eq 'requestcourses') {
8440: my $cond;
1.163 raeburn 8441: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8442: if ($1 eq '') {
8443: $cond = &mt('(Automatic processing of any request).');
8444: } else {
8445: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8446: }
8447: } else {
1.163 raeburn 8448: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8449: }
8450: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8451: } elsif ($context eq 'requestauthor') {
8452: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8453: $titles{$inconf{$type}},$typetitle);
8454:
1.101 raeburn 8455: } else {
8456: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8457: }
1.72 raeburn 8458: } else {
1.104 raeburn 8459: if ($type eq '_LC_adv') {
1.163 raeburn 8460: if ($inconf{$type} eq '0') {
1.104 raeburn 8461: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8462: } else {
8463: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8464: }
8465: } else {
8466: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8467: }
1.72 raeburn 8468: }
8469: }
1.26 raeburn 8470: }
1.163 raeburn 8471: unless ($context eq 'requestauthor') {
8472: $resulttext .= '</ul></li>';
8473: }
1.26 raeburn 8474: }
1.1 raeburn 8475: }
1.163 raeburn 8476: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8477: if (ref($changes{'notify'}) eq 'HASH') {
8478: if ($changes{'notify'}{'approval'}) {
8479: if (ref($confhash{'notify'}) eq 'HASH') {
8480: if ($confhash{'notify'}{'approval'}) {
8481: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8482: } else {
1.163 raeburn 8483: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8484: }
8485: }
8486: }
8487: }
8488: }
1.216 raeburn 8489: if ($action eq 'requestcourses') {
8490: my @offon = ('off','on');
8491: if ($changes{'uniquecode'}) {
1.218 raeburn 8492: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8493: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8494: $resulttext .= '<li>'.
8495: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8496: '</li>';
8497: } else {
8498: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8499: '</li>';
8500: }
1.216 raeburn 8501: }
1.242 raeburn 8502: foreach my $type ('textbooks','templates') {
8503: if (ref($changes{$type}) eq 'HASH') {
8504: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8505: foreach my $key (sort(keys(%{$changes{$type}}))) {
8506: my %coursehash = &Apache::lonnet::coursedescription($key);
8507: my $coursetitle = $coursehash{'description'};
8508: my $position = $confhash{$type}{$key}{'order'} + 1;
8509: $resulttext .= '<li>';
1.243 raeburn 8510: foreach my $item ('subject','title','publisher','author') {
8511: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8512: ($type eq 'templates'));
1.242 raeburn 8513: my $name = $item.':';
8514: $name =~ s/^(\w)/\U$1/;
8515: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8516: }
8517: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8518: if ($type eq 'textbooks') {
8519: if ($confhash{$type}{$key}{'image'}) {
8520: $resulttext .= ' '.&mt('Image: [_1]',
8521: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8522: ' alt="Textbook cover" />').'<br />';
8523: }
8524: }
8525: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8526: }
1.242 raeburn 8527: $resulttext .= '</ul></li>';
1.216 raeburn 8528: }
8529: }
1.235 raeburn 8530: if (ref($changes{'validation'}) eq 'HASH') {
8531: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8532: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8533: foreach my $item (@{$validationitemsref}) {
8534: if (exists($changes{'validation'}{$item})) {
8535: if ($item eq 'markup') {
8536: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8537: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8538: } else {
8539: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8540: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8541: }
8542: }
8543: }
8544: if (exists($changes{'validation'}{'dc'})) {
8545: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8546: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8547: }
8548: }
8549: }
1.216 raeburn 8550: }
1.1 raeburn 8551: $resulttext .= '</ul>';
1.80 raeburn 8552: if (keys(%newenv)) {
8553: &Apache::lonnet::appenv(\%newenv);
8554: }
1.1 raeburn 8555: } else {
1.86 raeburn 8556: if ($context eq 'requestcourses') {
8557: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8558: } elsif ($context eq 'requestauthor') {
8559: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8560: } else {
1.90 weissno 8561: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8562: }
1.1 raeburn 8563: }
8564: } else {
1.11 albertel 8565: $resulttext = '<span class="LC_error">'.
8566: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8567: }
1.216 raeburn 8568: if ($errors) {
8569: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8570: '<ul>'.$errors.'</ul></p>';
8571: }
1.3 raeburn 8572: return $resulttext;
1.1 raeburn 8573: }
8574:
1.216 raeburn 8575: sub process_textbook_image {
1.242 raeburn 8576: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8577: my $filename = $env{'form.'.$caller.'.filename'};
8578: my ($error,$url);
8579: my ($width,$height) = (50,50);
8580: if ($configuserok eq 'ok') {
8581: if ($switchserver) {
8582: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8583: $switchserver);
8584: } elsif ($author_ok eq 'ok') {
8585: my ($result,$imageurl) =
8586: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8587: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8588: if ($result eq 'ok') {
8589: $url = $imageurl;
8590: } else {
8591: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8592: }
8593: } else {
8594: $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);
8595: }
8596: } else {
8597: $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);
8598: }
8599: return ($url,$error);
8600: }
8601:
1.267 raeburn 8602: sub modify_ltitools {
8603: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8604: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8605: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8606: my $confname = $dom.'-domainconfig';
8607: my $servadm = $r->dir_config('lonAdmEMail');
8608: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8609: my (%posslti,%possfield);
8610: my @courseroles = ('cc','in','ta','ep','st');
8611: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8612: map { $posslti{$_} = 1; } @ltiroles;
8613: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8614: map { $possfield{$_} = 1; } @allfields;
8615: my %lt = <itools_names();
8616: if ($env{'form.ltitools_add'}) {
8617: my $title = $env{'form.ltitools_add_title'};
8618: $title =~ s/(`)/'/g;
8619: ($newid,my $error) = &get_ltitools_id($dom,$title);
8620: if ($newid) {
8621: my $position = $env{'form.ltitools_add_pos'};
8622: $position =~ s/\D+//g;
8623: if ($position ne '') {
8624: $allpos[$position] = $newid;
8625: }
8626: $changes{$newid} = 1;
8627: foreach my $item ('title','url','key','secret') {
8628: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8629: if ($env{'form.ltitools_add_'.$item}) {
8630: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8631: }
8632: }
8633: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8634: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8635: }
8636: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8637: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8638: }
8639: foreach my $item ('width','height') {
8640: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8641: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8642: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8643: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8644: }
8645: }
8646: if ($env{'form.ltitools_add_target'} eq 'window') {
8647: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8648: } else {
8649: $confhash{$newid}{'display'}{'target'} = 'iframe';
8650: }
8651: foreach my $item ('passback','roster') {
8652: if ($env{'form.ltitools_add_'.$item}) {
8653: $confhash{$newid}{$item} = 1;
8654: }
8655: }
8656: if ($env{'form.ltitools_add_image.filename'} ne '') {
8657: my ($imageurl,$error) =
8658: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8659: $configuserok,$switchserver,$author_ok);
8660: if ($imageurl) {
8661: $confhash{$newid}{'image'} = $imageurl;
8662: }
8663: if ($error) {
8664: &Apache::lonnet::logthis($error);
8665: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8666: }
8667: }
8668: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8669: foreach my $field (@fields) {
8670: if ($possfield{$field}) {
8671: if ($field eq 'roles') {
8672: foreach my $role (@courseroles) {
8673: my $choice = $env{'form.ltitools_add_roles_'.$role};
8674: if (($choice ne '') && ($posslti{$choice})) {
8675: $confhash{$newid}{'roles'}{$role} = $choice;
8676: if ($role eq 'cc') {
8677: $confhash{$newid}{'roles'}{'co'} = $choice;
8678: }
8679: }
8680: }
8681: } else {
8682: $confhash{$newid}{'fields'}{$field} = 1;
8683: }
8684: }
8685: }
1.273 raeburn 8686: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
8687: foreach my $item (@courseconfig) {
8688: $confhash{$newid}{'crsconf'}{$item} = 1;
8689: }
1.267 raeburn 8690: if ($env{'form.ltitools_add_custom'}) {
8691: my $name = $env{'form.ltitools_add_custom_name'};
8692: my $value = $env{'form.ltitools_add_custom_value'};
8693: $value =~ s/(`)/'/g;
8694: $name =~ s/(`)/'/g;
8695: $confhash{$newid}{'custom'}{$name} = $value;
8696: }
8697: } else {
8698: my $error = &mt('Failed to acquire unique ID for new external tool');
8699: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8700: }
8701: }
8702: if (ref($domconfig{$action}) eq 'HASH') {
8703: my %deletions;
8704: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8705: if (@todelete) {
8706: map { $deletions{$_} = 1; } @todelete;
8707: }
8708: my %customadds;
8709: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8710: if (@newcustom) {
8711: map { $customadds{$_} = 1; } @newcustom;
8712: }
8713: my %imgdeletions;
8714: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8715: if (@todeleteimages) {
8716: map { $imgdeletions{$_} = 1; } @todeleteimages;
8717: }
8718: my $maxnum = $env{'form.ltitools_maxnum'};
8719: for (my $i=0; $i<=$maxnum; $i++) {
8720: my $itemid = $env{'form.ltitools_id_'.$i};
8721: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8722: if ($deletions{$itemid}) {
8723: if ($domconfig{$action}{$itemid}{'image'}) {
8724: #FIXME need to obsolete item in RES space
8725: }
8726: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8727: next;
8728: } else {
8729: my $newpos = $env{'form.ltitools_'.$itemid};
8730: $newpos =~ s/\D+//g;
8731: foreach my $item ('title','url','key','secret') {
8732: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8733: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8734: $changes{$itemid} = 1;
8735: }
8736: }
8737: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8738: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8739: }
8740: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8741: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8742: }
8743: foreach my $size ('width','height') {
8744: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8745: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8746: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8747: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8748: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8749: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8750: $changes{$itemid} = 1;
8751: }
8752: } else {
8753: $changes{$itemid} = 1;
8754: }
8755: }
8756: }
8757: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8758: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8759: } else {
8760: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8761: }
8762: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8763: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8764: $changes{$itemid} = 1;
8765: }
8766: } else {
8767: $changes{$itemid} = 1;
8768: }
8769: foreach my $extra ('passback','roster') {
8770: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8771: $confhash{$itemid}{$extra} = 1;
8772: }
8773: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8774: $changes{$itemid} = 1;
8775: }
8776: }
1.273 raeburn 8777: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
8778: foreach my $item ('label','title','target') {
8779: if (grep(/^\Q$item\E$/,@courseconfig)) {
8780: $confhash{$itemid}{'crsconf'}{$item} = 1;
8781: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
8782: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
8783: $changes{$itemid} = 1;
8784: }
8785: } else {
8786: $changes{$itemid} = 1;
8787: }
8788: }
8789: }
1.267 raeburn 8790: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8791: foreach my $field (@fields) {
8792: if ($possfield{$field}) {
8793: if ($field eq 'roles') {
8794: foreach my $role (@courseroles) {
8795: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8796: if (($choice ne '') && ($posslti{$choice})) {
8797: $confhash{$itemid}{'roles'}{$role} = $choice;
8798: if ($role eq 'cc') {
8799: $confhash{$itemid}{'roles'}{'co'} = $choice;
8800: }
8801: }
8802: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8803: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8804: $changes{$itemid} = 1;
8805: }
8806: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8807: $changes{$itemid} = 1;
8808: }
8809: }
8810: } else {
8811: $confhash{$itemid}{'fields'}{$field} = 1;
8812: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8813: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8814: $changes{$itemid} = 1;
8815: }
8816: } else {
8817: $changes{$itemid} = 1;
8818: }
8819: }
8820: }
8821: }
8822: $allpos[$newpos] = $itemid;
8823: }
8824: if ($imgdeletions{$itemid}) {
8825: $changes{$itemid} = 1;
8826: #FIXME need to obsolete item in RES space
8827: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8828: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8829: $itemid,$configuserok,$switchserver,
8830: $author_ok);
8831: if ($imgurl) {
8832: $confhash{$itemid}{'image'} = $imgurl;
8833: $changes{$itemid} = 1;
8834: }
8835: if ($error) {
8836: &Apache::lonnet::logthis($error);
8837: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8838: }
8839: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8840: $confhash{$itemid}{'image'} =
8841: $domconfig{$action}{$itemid}{'image'};
8842: }
8843: if ($customadds{$i}) {
8844: my $name = $env{'form.ltitools_custom_name_'.$i};
8845: $name =~ s/(`)/'/g;
8846: $name =~ s/^\s+//;
8847: $name =~ s/\s+$//;
8848: my $value = $env{'form.ltitools_custom_value_'.$i};
8849: $value =~ s/(`)/'/g;
8850: $value =~ s/^\s+//;
8851: $value =~ s/\s+$//;
8852: if ($name ne '') {
8853: $confhash{$itemid}{'custom'}{$name} = $value;
8854: $changes{$itemid} = 1;
8855: }
8856: }
8857: my %customdels;
8858: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8859: if (@customdeletions) {
8860: $changes{$itemid} = 1;
8861: }
8862: map { $customdels{$_} = 1; } @customdeletions;
8863: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8864: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8865: unless ($customdels{$key}) {
8866: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8867: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8868: }
8869: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8870: $changes{$itemid} = 1;
8871: }
8872: }
8873: }
8874: }
8875: unless ($changes{$itemid}) {
8876: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8877: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8878: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8879: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8880: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8881: $changes{$itemid} = 1;
8882: last;
8883: }
8884: }
8885: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8886: $changes{$itemid} = 1;
8887: }
8888: }
8889: last if ($changes{$itemid});
8890: }
8891: }
8892: }
8893: }
8894: }
8895: if (@allpos > 0) {
8896: my $idx = 0;
8897: foreach my $itemid (@allpos) {
8898: if ($itemid ne '') {
8899: $confhash{$itemid}{'order'} = $idx;
8900: if (ref($domconfig{$action}) eq 'HASH') {
8901: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8902: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8903: $changes{$itemid} = 1;
8904: }
8905: }
8906: }
8907: $idx ++;
8908: }
8909: }
8910: }
8911: my %ltitoolshash = (
8912: $action => { %confhash }
8913: );
8914: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8915: $dom);
8916: if ($putresult eq 'ok') {
8917: if (keys(%changes) > 0) {
8918: my $cachetime = 24*60*60;
8919: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8920: if (ref($lastactref) eq 'HASH') {
8921: $lastactref->{'ltitools'} = 1;
8922: }
8923: $resulttext = &mt('Changes made:').'<ul>';
8924: my %bynum;
8925: foreach my $itemid (sort(keys(%changes))) {
8926: my $position = $confhash{$itemid}{'order'};
8927: $bynum{$position} = $itemid;
8928: }
8929: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8930: my $itemid = $bynum{$pos};
8931: if (ref($confhash{$itemid}) ne 'HASH') {
8932: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8933: } else {
8934: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8935: if ($confhash{$itemid}{'image'}) {
8936: $resulttext .= ' '.
8937: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8938: ' alt="'.&mt('Tool Provider icon').'" />';
8939: }
8940: $resulttext .= '</li><ul>';
8941: my $position = $pos + 1;
8942: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8943: foreach my $item ('version','msgtype','url','key') {
8944: if ($confhash{$itemid}{$item} ne '') {
8945: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8946: }
8947: }
8948: if ($confhash{$itemid}{'secret'} ne '') {
8949: $resulttext .= '<li>'.$lt{'secret'}.': ';
8950: my $num = length($confhash{$itemid}{'secret'});
8951: $resulttext .= ('*'x$num).'</li>';
8952: }
1.273 raeburn 8953: $resulttext .= '<li>'.&mt('Configurable in course:');
8954: my @possconfig = ('label','title','target');
8955: my $numconfig = 0;
8956: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
8957: foreach my $item (@possconfig) {
8958: if ($confhash{$itemid}{'crsconf'}{$item}) {
8959: $numconfig ++;
8960: $resulttext .= ' '.$lt{'crs'.$item};
8961: }
8962: }
8963: }
8964: if (!$numconfig) {
8965: $resulttext .= &mt('None');
8966: }
8967: $resulttext .= '</li>';
1.267 raeburn 8968: foreach my $item ('passback','roster') {
8969: $resulttext .= '<li>'.$lt{$item}.' ';
8970: if ($confhash{$itemid}{$item}) {
8971: $resulttext .= &mt('Yes');
8972: } else {
8973: $resulttext .= &mt('No');
8974: }
8975: $resulttext .= '</li>';
8976: }
8977: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
8978: my $displaylist;
8979: if ($confhash{$itemid}{'display'}{'target'}) {
8980: $displaylist = &mt('Display target').': '.
8981: $confhash{$itemid}{'display'}{'target'}.',';
8982: }
8983: foreach my $size ('width','height') {
8984: if ($confhash{$itemid}{'display'}{$size}) {
8985: $displaylist .= (' 'x2).$lt{$size}.': '.
8986: $confhash{$itemid}{'display'}{$size}.',';
8987: }
8988: }
8989: if ($displaylist) {
8990: $displaylist =~ s/,$//;
8991: $resulttext .= '<li>'.$displaylist.'</li>';
8992: }
8993: }
8994: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
8995: my $fieldlist;
8996: foreach my $field (@allfields) {
8997: if ($confhash{$itemid}{'fields'}{$field}) {
8998: $fieldlist .= (' 'x2).$lt{$field}.',';
8999: }
9000: }
9001: if ($fieldlist) {
9002: $fieldlist =~ s/,$//;
9003: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9004: }
9005: }
9006: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9007: my $rolemaps;
9008: foreach my $role (@courseroles) {
9009: if ($confhash{$itemid}{'roles'}{$role}) {
9010: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9011: $confhash{$itemid}{'roles'}{$role}.',';
9012: }
9013: }
9014: if ($rolemaps) {
9015: $rolemaps =~ s/,$//;
9016: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9017: }
9018: }
9019: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9020: my $customlist;
9021: if (keys(%{$confhash{$itemid}{'custom'}})) {
9022: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9023: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9024: }
9025: }
9026: if ($customlist) {
9027: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9028: }
9029: }
9030: $resulttext .= '</ul></li>';
9031: }
9032: }
9033: $resulttext .= '</ul>';
9034: } else {
9035: $resulttext = &mt('No changes made.');
9036: }
9037: } else {
9038: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9039: }
9040: if ($errors) {
9041: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9042: $errors.'</ul>';
9043: }
9044: return $resulttext;
9045: }
9046:
9047: sub process_ltitools_image {
9048: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9049: my $filename = $env{'form.'.$caller.'.filename'};
9050: my ($error,$url);
9051: my ($width,$height) = (21,21);
9052: if ($configuserok eq 'ok') {
9053: if ($switchserver) {
9054: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9055: $switchserver);
9056: } elsif ($author_ok eq 'ok') {
9057: my ($result,$imageurl,$madethumb) =
9058: &publishlogo($r,'upload',$caller,$dom,$confname,
9059: "ltitools/$itemid/icon",$width,$height);
9060: if ($result eq 'ok') {
9061: if ($madethumb) {
9062: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9063: my $imagethumb = "$path/tn-".$imagefile;
9064: $url = $imagethumb;
9065: } else {
9066: $url = $imageurl;
9067: }
9068: } else {
9069: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9070: }
9071: } else {
9072: $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);
9073: }
9074: } else {
9075: $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);
9076: }
9077: return ($url,$error);
9078: }
9079:
9080: sub get_ltitools_id {
9081: my ($cdom,$title) = @_;
9082: # get lock on ltitools db
9083: my $lockhash = {
9084: lock => $env{'user.name'}.
9085: ':'.$env{'user.domain'},
9086: };
9087: my $tries = 0;
9088: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9089: my ($id,$error);
9090:
9091: while (($gotlock ne 'ok') && ($tries<10)) {
9092: $tries ++;
9093: sleep (0.1);
9094: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9095: }
9096: if ($gotlock eq 'ok') {
9097: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9098: if ($currids{'lock'}) {
9099: delete($currids{'lock'});
9100: if (keys(%currids)) {
9101: my @curr = sort { $a <=> $b } keys(%currids);
9102: if ($curr[-1] =~ /^\d+$/) {
9103: $id = 1 + $curr[-1];
9104: }
9105: } else {
9106: $id = 1;
9107: }
9108: if ($id) {
9109: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9110: $error = 'nostore';
9111: }
9112: } else {
9113: $error = 'nonumber';
9114: }
9115: }
9116: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9117: } else {
9118: $error = 'nolock';
9119: }
9120: return ($id,$error);
9121: }
9122:
1.3 raeburn 9123: sub modify_autoenroll {
1.205 raeburn 9124: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9125: my ($resulttext,%changes);
9126: my %currautoenroll;
9127: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9128: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9129: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9130: }
9131: }
9132: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9133: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9134: sender => 'Sender for notification messages',
1.274 raeburn 9135: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9136: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9137: my @offon = ('off','on');
1.17 raeburn 9138: my $sender_uname = $env{'form.sender_uname'};
9139: my $sender_domain = $env{'form.sender_domain'};
9140: if ($sender_domain eq '') {
9141: $sender_uname = '';
9142: } elsif ($sender_uname eq '') {
9143: $sender_domain = '';
9144: }
1.129 raeburn 9145: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9146: my $failsafe = $env{'form.autoenroll_failsafe'};
9147: $failsafe =~ s{^\s+|\s+$}{}g;
9148: if ($failsafe =~ /\D/) {
9149: undef($failsafe);
9150: }
1.1 raeburn 9151: my %autoenrollhash = (
1.129 raeburn 9152: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9153: 'sender_uname' => $sender_uname,
9154: 'sender_domain' => $sender_domain,
9155: 'co-owners' => $coowners,
1.274 raeburn 9156: 'autofailsafe' => $failsafe,
1.1 raeburn 9157: }
9158: );
1.4 raeburn 9159: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9160: $dom);
1.1 raeburn 9161: if ($putresult eq 'ok') {
9162: if (exists($currautoenroll{'run'})) {
9163: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9164: $changes{'run'} = 1;
9165: }
9166: } elsif ($autorun) {
9167: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9168: $changes{'run'} = 1;
1.1 raeburn 9169: }
9170: }
1.17 raeburn 9171: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9172: $changes{'sender'} = 1;
9173: }
1.17 raeburn 9174: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9175: $changes{'sender'} = 1;
9176: }
1.129 raeburn 9177: if ($currautoenroll{'co-owners'} ne '') {
9178: if ($currautoenroll{'co-owners'} ne $coowners) {
9179: $changes{'coowners'} = 1;
9180: }
9181: } elsif ($coowners) {
9182: $changes{'coowners'} = 1;
1.274 raeburn 9183: }
9184: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9185: $changes{'autofailsafe'} = 1;
9186: }
1.1 raeburn 9187: if (keys(%changes) > 0) {
9188: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9189: if ($changes{'run'}) {
1.1 raeburn 9190: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9191: }
9192: if ($changes{'sender'}) {
1.17 raeburn 9193: if ($sender_uname eq '' || $sender_domain eq '') {
9194: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9195: } else {
9196: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9197: }
1.1 raeburn 9198: }
1.129 raeburn 9199: if ($changes{'coowners'}) {
9200: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9201: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9202: if (ref($lastactref) eq 'HASH') {
9203: $lastactref->{'domainconfig'} = 1;
9204: }
1.129 raeburn 9205: }
1.274 raeburn 9206: if ($changes{'autofailsafe'}) {
9207: if ($failsafe ne '') {
9208: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
9209: } else {
9210: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
9211: }
9212: &Apache::lonnet::get_domain_defaults($dom,1);
9213: if (ref($lastactref) eq 'HASH') {
9214: $lastactref->{'domdefaults'} = 1;
9215: }
9216: }
1.1 raeburn 9217: $resulttext .= '</ul>';
9218: } else {
9219: $resulttext = &mt('No changes made to auto-enrollment settings');
9220: }
9221: } else {
1.11 albertel 9222: $resulttext = '<span class="LC_error">'.
9223: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9224: }
1.3 raeburn 9225: return $resulttext;
1.1 raeburn 9226: }
9227:
9228: sub modify_autoupdate {
1.3 raeburn 9229: my ($dom,%domconfig) = @_;
1.1 raeburn 9230: my ($resulttext,%currautoupdate,%fields,%changes);
9231: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9232: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9233: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9234: }
9235: }
9236: my @offon = ('off','on');
9237: my %title = &Apache::lonlocal::texthash (
9238: run => 'Auto-update:',
9239: classlists => 'Updates to user information in classlists?'
9240: );
1.44 raeburn 9241: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9242: my %fieldtitles = &Apache::lonlocal::texthash (
9243: id => 'Student/Employee ID',
1.20 raeburn 9244: permanentemail => 'E-mail address',
1.1 raeburn 9245: lastname => 'Last Name',
9246: firstname => 'First Name',
9247: middlename => 'Middle Name',
1.132 raeburn 9248: generation => 'Generation',
1.1 raeburn 9249: );
1.142 raeburn 9250: $othertitle = &mt('All users');
1.1 raeburn 9251: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9252: $othertitle = &mt('Other users');
1.1 raeburn 9253: }
9254: foreach my $key (keys(%env)) {
9255: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9256: my ($usertype,$item) = ($1,$2);
9257: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9258: if ($usertype eq 'default') {
9259: push(@{$fields{$1}},$2);
9260: } elsif (ref($types) eq 'ARRAY') {
9261: if (grep(/^\Q$usertype\E$/,@{$types})) {
9262: push(@{$fields{$1}},$2);
9263: }
9264: }
9265: }
1.1 raeburn 9266: }
9267: }
1.131 raeburn 9268: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9269: @lockablenames = sort(@lockablenames);
9270: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9271: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9272: if (@changed) {
9273: $changes{'lockablenames'} = 1;
9274: }
9275: } else {
9276: if (@lockablenames) {
9277: $changes{'lockablenames'} = 1;
9278: }
9279: }
1.1 raeburn 9280: my %updatehash = (
9281: autoupdate => { run => $env{'form.autoupdate_run'},
9282: classlists => $env{'form.classlists'},
9283: fields => {%fields},
1.131 raeburn 9284: lockablenames => \@lockablenames,
1.1 raeburn 9285: }
9286: );
9287: foreach my $key (keys(%currautoupdate)) {
9288: if (($key eq 'run') || ($key eq 'classlists')) {
9289: if (exists($updatehash{autoupdate}{$key})) {
9290: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9291: $changes{$key} = 1;
9292: }
9293: }
9294: } elsif ($key eq 'fields') {
9295: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9296: foreach my $item (@{$types},'default') {
1.1 raeburn 9297: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9298: my $change = 0;
9299: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9300: if (!exists($fields{$item})) {
9301: $change = 1;
1.132 raeburn 9302: last;
1.1 raeburn 9303: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9304: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9305: $change = 1;
1.132 raeburn 9306: last;
1.1 raeburn 9307: }
9308: }
9309: }
9310: if ($change) {
9311: push(@{$changes{$key}},$item);
9312: }
1.26 raeburn 9313: }
1.1 raeburn 9314: }
9315: }
1.131 raeburn 9316: } elsif ($key eq 'lockablenames') {
9317: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9318: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9319: if (@changed) {
9320: $changes{'lockablenames'} = 1;
9321: }
9322: } else {
9323: if (@lockablenames) {
9324: $changes{'lockablenames'} = 1;
9325: }
9326: }
9327: }
9328: }
9329: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9330: if (@lockablenames) {
9331: $changes{'lockablenames'} = 1;
1.1 raeburn 9332: }
9333: }
1.26 raeburn 9334: foreach my $item (@{$types},'default') {
9335: if (defined($fields{$item})) {
9336: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9337: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9338: my $change = 0;
9339: if (ref($fields{$item}) eq 'ARRAY') {
9340: foreach my $type (@{$fields{$item}}) {
9341: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9342: $change = 1;
9343: last;
9344: }
9345: }
9346: }
9347: if ($change) {
9348: push(@{$changes{'fields'}},$item);
9349: }
9350: } else {
1.26 raeburn 9351: push(@{$changes{'fields'}},$item);
9352: }
9353: } else {
9354: push(@{$changes{'fields'}},$item);
1.1 raeburn 9355: }
9356: }
9357: }
9358: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9359: $dom);
9360: if ($putresult eq 'ok') {
9361: if (keys(%changes) > 0) {
9362: $resulttext = &mt('Changes made:').'<ul>';
9363: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9364: if ($key eq 'lockablenames') {
9365: $resulttext .= '<li>';
9366: if (@lockablenames) {
9367: $usertypes->{'default'} = $othertitle;
9368: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9369: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9370: } else {
9371: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9372: }
9373: $resulttext .= '</li>';
9374: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9375: foreach my $item (@{$changes{$key}}) {
9376: my @newvalues;
9377: foreach my $type (@{$fields{$item}}) {
9378: push(@newvalues,$fieldtitles{$type});
9379: }
1.3 raeburn 9380: my $newvaluestr;
9381: if (@newvalues > 0) {
9382: $newvaluestr = join(', ',@newvalues);
9383: } else {
9384: $newvaluestr = &mt('none');
1.6 raeburn 9385: }
1.1 raeburn 9386: if ($item eq 'default') {
1.26 raeburn 9387: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9388: } else {
1.26 raeburn 9389: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9390: }
9391: }
9392: } else {
9393: my $newvalue;
9394: if ($key eq 'run') {
9395: $newvalue = $offon[$env{'form.autoupdate_run'}];
9396: } else {
9397: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9398: }
1.1 raeburn 9399: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9400: }
9401: }
9402: $resulttext .= '</ul>';
9403: } else {
1.3 raeburn 9404: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9405: }
9406: } else {
1.11 albertel 9407: $resulttext = '<span class="LC_error">'.
9408: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9409: }
1.3 raeburn 9410: return $resulttext;
1.1 raeburn 9411: }
9412:
1.125 raeburn 9413: sub modify_autocreate {
9414: my ($dom,%domconfig) = @_;
9415: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9416: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9417: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9418: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9419: }
9420: }
9421: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9422: req => 'Auto-creation of validated requests for official courses',
9423: xmldc => 'Identity of course creator of courses from XML files',
9424: );
9425: my @types = ('xml','req');
9426: foreach my $item (@types) {
9427: $newvals{$item} = $env{'form.autocreate_'.$item};
9428: $newvals{$item} =~ s/\D//g;
9429: $newvals{$item} = 0 if ($newvals{$item} eq '');
9430: }
9431: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9432: my %domcoords = &get_active_dcs($dom);
9433: unless (exists($domcoords{$newvals{'xmldc'}})) {
9434: $newvals{'xmldc'} = '';
9435: }
9436: %autocreatehash = (
9437: autocreate => { xml => $newvals{'xml'},
9438: req => $newvals{'req'},
9439: }
9440: );
9441: if ($newvals{'xmldc'} ne '') {
9442: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9443: }
9444: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9445: $dom);
9446: if ($putresult eq 'ok') {
9447: my @items = @types;
9448: if ($newvals{'xml'}) {
9449: push(@items,'xmldc');
9450: }
9451: foreach my $item (@items) {
9452: if (exists($currautocreate{$item})) {
9453: if ($currautocreate{$item} ne $newvals{$item}) {
9454: $changes{$item} = 1;
9455: }
9456: } elsif ($newvals{$item}) {
9457: $changes{$item} = 1;
9458: }
9459: }
9460: if (keys(%changes) > 0) {
9461: my @offon = ('off','on');
9462: $resulttext = &mt('Changes made:').'<ul>';
9463: foreach my $item (@types) {
9464: if ($changes{$item}) {
9465: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9466: $resulttext .= '<li>'.
9467: &mt("$title{$item} set to [_1]$newtxt [_2]",
9468: '<b>','</b>').
9469: '</li>';
1.125 raeburn 9470: }
9471: }
9472: if ($changes{'xmldc'}) {
9473: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9474: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9475: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9476: }
9477: $resulttext .= '</ul>';
9478: } else {
9479: $resulttext = &mt('No changes made to auto-creation settings');
9480: }
9481: } else {
9482: $resulttext = '<span class="LC_error">'.
9483: &mt('An error occurred: [_1]',$putresult).'</span>';
9484: }
9485: return $resulttext;
9486: }
9487:
1.23 raeburn 9488: sub modify_directorysrch {
9489: my ($dom,%domconfig) = @_;
9490: my ($resulttext,%changes);
9491: my %currdirsrch;
9492: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9493: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9494: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9495: }
9496: }
9497: my %title = ( available => 'Directory search available',
1.24 raeburn 9498: localonly => 'Other domains can search',
1.23 raeburn 9499: searchby => 'Search types',
9500: searchtypes => 'Search latitude');
9501: my @offon = ('off','on');
1.24 raeburn 9502: my @otherdoms = ('Yes','No');
1.23 raeburn 9503:
1.25 raeburn 9504: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9505: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9506: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9507:
1.44 raeburn 9508: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9509: if (keys(%{$usertypes}) == 0) {
9510: @cansearch = ('default');
9511: } else {
9512: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9513: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9514: if (!grep(/^\Q$type\E$/,@cansearch)) {
9515: push(@{$changes{'cansearch'}},$type);
9516: }
1.23 raeburn 9517: }
1.26 raeburn 9518: foreach my $type (@cansearch) {
9519: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9520: push(@{$changes{'cansearch'}},$type);
9521: }
1.23 raeburn 9522: }
1.26 raeburn 9523: } else {
9524: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9525: }
9526: }
9527:
9528: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9529: foreach my $by (@{$currdirsrch{'searchby'}}) {
9530: if (!grep(/^\Q$by\E$/,@searchby)) {
9531: push(@{$changes{'searchby'}},$by);
9532: }
9533: }
9534: foreach my $by (@searchby) {
9535: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9536: push(@{$changes{'searchby'}},$by);
9537: }
9538: }
9539: } else {
9540: push(@{$changes{'searchby'}},@searchby);
9541: }
1.25 raeburn 9542:
9543: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9544: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9545: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9546: push(@{$changes{'searchtypes'}},$type);
9547: }
9548: }
9549: foreach my $type (@searchtypes) {
9550: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9551: push(@{$changes{'searchtypes'}},$type);
9552: }
9553: }
9554: } else {
9555: if (exists($currdirsrch{'searchtypes'})) {
9556: foreach my $type (@searchtypes) {
9557: if ($type ne $currdirsrch{'searchtypes'}) {
9558: push(@{$changes{'searchtypes'}},$type);
9559: }
9560: }
9561: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9562: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9563: }
9564: } else {
9565: push(@{$changes{'searchtypes'}},@searchtypes);
9566: }
9567: }
9568:
1.23 raeburn 9569: my %dirsrch_hash = (
9570: directorysrch => { available => $env{'form.dirsrch_available'},
9571: cansearch => \@cansearch,
1.24 raeburn 9572: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 9573: searchby => \@searchby,
1.25 raeburn 9574: searchtypes => \@searchtypes,
1.23 raeburn 9575: }
9576: );
9577: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9578: $dom);
9579: if ($putresult eq 'ok') {
9580: if (exists($currdirsrch{'available'})) {
9581: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9582: $changes{'available'} = 1;
9583: }
9584: } else {
9585: if ($env{'form.dirsrch_available'} eq '1') {
9586: $changes{'available'} = 1;
9587: }
9588: }
1.24 raeburn 9589: if (exists($currdirsrch{'localonly'})) {
9590: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
9591: $changes{'localonly'} = 1;
9592: }
9593: } else {
9594: if ($env{'form.dirsrch_localonly'} eq '1') {
9595: $changes{'localonly'} = 1;
9596: }
9597: }
1.23 raeburn 9598: if (keys(%changes) > 0) {
9599: $resulttext = &mt('Changes made:').'<ul>';
9600: if ($changes{'available'}) {
9601: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9602: }
1.24 raeburn 9603: if ($changes{'localonly'}) {
9604: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
9605: }
9606:
1.23 raeburn 9607: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9608: my $chgtext;
1.26 raeburn 9609: if (ref($usertypes) eq 'HASH') {
9610: if (keys(%{$usertypes}) > 0) {
9611: foreach my $type (@{$types}) {
9612: if (grep(/^\Q$type\E$/,@cansearch)) {
9613: $chgtext .= $usertypes->{$type}.'; ';
9614: }
9615: }
9616: if (grep(/^default$/,@cansearch)) {
9617: $chgtext .= $othertitle;
9618: } else {
9619: $chgtext =~ s/\; $//;
9620: }
1.210 raeburn 9621: $resulttext .=
1.178 raeburn 9622: '<li>'.
9623: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9624: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9625: '</li>';
1.23 raeburn 9626: }
9627: }
9628: }
9629: if (ref($changes{'searchby'}) eq 'ARRAY') {
9630: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9631: my $chgtext;
9632: foreach my $type (@{$titleorder}) {
9633: if (grep(/^\Q$type\E$/,@searchby)) {
9634: if (defined($searchtitles->{$type})) {
9635: $chgtext .= $searchtitles->{$type}.'; ';
9636: }
9637: }
9638: }
9639: $chgtext =~ s/\; $//;
9640: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9641: }
1.25 raeburn 9642: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9643: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9644: my $chgtext;
9645: foreach my $type (@{$srchtypeorder}) {
9646: if (grep(/^\Q$type\E$/,@searchtypes)) {
9647: if (defined($srchtypes_desc->{$type})) {
9648: $chgtext .= $srchtypes_desc->{$type}.'; ';
9649: }
9650: }
9651: }
9652: $chgtext =~ s/\; $//;
1.178 raeburn 9653: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9654: }
9655: $resulttext .= '</ul>';
9656: } else {
9657: $resulttext = &mt('No changes made to institution directory search settings');
9658: }
9659: } else {
9660: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9661: &mt('An error occurred: [_1]',$putresult).'</span>';
9662: }
9663: return $resulttext;
9664: }
9665:
1.28 raeburn 9666: sub modify_contacts {
1.205 raeburn 9667: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9668: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9669: if (ref($domconfig{'contacts'}) eq 'HASH') {
9670: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9671: $currsetting{$key} = $domconfig{'contacts'}{$key};
9672: }
9673: }
1.134 raeburn 9674: my (%others,%to,%bcc);
1.28 raeburn 9675: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9676: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9677: 'requestsmail','updatesmail','idconflictsmail');
9678: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9679: foreach my $type (@mailings) {
9680: @{$newsetting{$type}} =
9681: &Apache::loncommon::get_env_multiple('form.'.$type);
9682: foreach my $item (@contacts) {
9683: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9684: $contacts_hash{contacts}{$type}{$item} = 1;
9685: } else {
9686: $contacts_hash{contacts}{$type}{$item} = 0;
9687: }
9688: }
9689: $others{$type} = $env{'form.'.$type.'_others'};
9690: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9691: if ($type eq 'helpdeskmail') {
9692: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9693: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9694: }
1.28 raeburn 9695: }
9696: foreach my $item (@contacts) {
9697: $to{$item} = $env{'form.'.$item};
9698: $contacts_hash{'contacts'}{$item} = $to{$item};
9699: }
1.203 raeburn 9700: foreach my $item (@toggles) {
9701: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9702: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9703: }
9704: }
1.28 raeburn 9705: if (keys(%currsetting) > 0) {
9706: foreach my $item (@contacts) {
9707: if ($to{$item} ne $currsetting{$item}) {
9708: $changes{$item} = 1;
9709: }
9710: }
9711: foreach my $type (@mailings) {
9712: foreach my $item (@contacts) {
9713: if (ref($currsetting{$type}) eq 'HASH') {
9714: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9715: push(@{$changes{$type}},$item);
9716: }
9717: } else {
9718: push(@{$changes{$type}},@{$newsetting{$type}});
9719: }
9720: }
9721: if ($others{$type} ne $currsetting{$type}{'others'}) {
9722: push(@{$changes{$type}},'others');
9723: }
1.134 raeburn 9724: if ($type eq 'helpdeskmail') {
9725: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9726: push(@{$changes{$type}},'bcc');
9727: }
9728: }
1.28 raeburn 9729: }
9730: } else {
9731: my %default;
9732: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9733: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9734: $default{'errormail'} = 'adminemail';
9735: $default{'packagesmail'} = 'adminemail';
9736: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9737: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9738: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9739: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9740: foreach my $item (@contacts) {
9741: if ($to{$item} ne $default{$item}) {
9742: $changes{$item} = 1;
1.203 raeburn 9743: }
1.28 raeburn 9744: }
9745: foreach my $type (@mailings) {
9746: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9747:
9748: push(@{$changes{$type}},@{$newsetting{$type}});
9749: }
9750: if ($others{$type} ne '') {
9751: push(@{$changes{$type}},'others');
1.134 raeburn 9752: }
9753: if ($type eq 'helpdeskmail') {
9754: if ($bcc{$type} ne '') {
9755: push(@{$changes{$type}},'bcc');
9756: }
9757: }
1.28 raeburn 9758: }
9759: }
1.203 raeburn 9760: foreach my $item (@toggles) {
9761: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9762: $changes{$item} = 1;
9763: } elsif ((!$env{'form.'.$item}) &&
9764: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9765: $changes{$item} = 1;
9766: }
9767: }
1.28 raeburn 9768: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9769: $dom);
9770: if ($putresult eq 'ok') {
9771: if (keys(%changes) > 0) {
1.205 raeburn 9772: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9773: if (ref($lastactref) eq 'HASH') {
9774: $lastactref->{'domainconfig'} = 1;
9775: }
1.28 raeburn 9776: my ($titles,$short_titles) = &contact_titles();
9777: $resulttext = &mt('Changes made:').'<ul>';
9778: foreach my $item (@contacts) {
9779: if ($changes{$item}) {
9780: $resulttext .= '<li>'.$titles->{$item}.
9781: &mt(' set to: ').
9782: '<span class="LC_cusr_emph">'.
9783: $to{$item}.'</span></li>';
9784: }
9785: }
9786: foreach my $type (@mailings) {
9787: if (ref($changes{$type}) eq 'ARRAY') {
9788: $resulttext .= '<li>'.$titles->{$type}.': ';
9789: my @text;
9790: foreach my $item (@{$newsetting{$type}}) {
9791: push(@text,$short_titles->{$item});
9792: }
9793: if ($others{$type} ne '') {
9794: push(@text,$others{$type});
9795: }
9796: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9797: join(', ',@text).'</span>';
9798: if ($type eq 'helpdeskmail') {
9799: if ($bcc{$type} ne '') {
9800: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9801: }
9802: }
9803: $resulttext .= '</li>';
1.28 raeburn 9804: }
9805: }
1.203 raeburn 9806: my @offon = ('off','on');
9807: if ($changes{'reporterrors'}) {
9808: $resulttext .= '<li>'.
9809: &mt('E-mail error reports to [_1] set to "'.
9810: $offon[$env{'form.reporterrors'}].'".',
9811: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9812: &mt('LON-CAPA core group - MSU'),600,500)).
9813: '</li>';
9814: }
9815: if ($changes{'reportupdates'}) {
9816: $resulttext .= '<li>'.
9817: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9818: $offon[$env{'form.reportupdates'}].'".',
9819: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9820: &mt('LON-CAPA core group - MSU'),600,500)).
9821: '</li>';
9822: }
1.28 raeburn 9823: $resulttext .= '</ul>';
9824: } else {
1.34 raeburn 9825: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9826: }
9827: } else {
9828: $resulttext = '<span class="LC_error">'.
9829: &mt('An error occurred: [_1].',$putresult).'</span>';
9830: }
9831: return $resulttext;
9832: }
9833:
9834: sub modify_usercreation {
1.27 raeburn 9835: my ($dom,%domconfig) = @_;
1.224 raeburn 9836: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9837: my $warningmsg;
1.27 raeburn 9838: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9839: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9840: if ($key eq 'cancreate') {
9841: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9842: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9843: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9844: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9845: ($item eq 'recaptchaversion')) {
1.224 raeburn 9846: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9847: } else {
9848: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9849: }
9850: }
9851: }
9852: } elsif ($key eq 'email_rule') {
9853: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9854: } else {
9855: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9856: }
1.27 raeburn 9857: }
9858: }
9859: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9860: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9861: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9862: foreach my $item(@contexts) {
1.224 raeburn 9863: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9864: }
1.34 raeburn 9865: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9866: foreach my $item (@contexts) {
1.224 raeburn 9867: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9868: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9869: }
1.27 raeburn 9870: }
1.34 raeburn 9871: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9872: foreach my $item (@contexts) {
1.43 raeburn 9873: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9874: if ($cancreate{$item} ne 'any') {
9875: push(@{$changes{'cancreate'}},$item);
9876: }
9877: } else {
9878: if ($cancreate{$item} ne 'none') {
9879: push(@{$changes{'cancreate'}},$item);
9880: }
1.27 raeburn 9881: }
9882: }
9883: } else {
1.43 raeburn 9884: foreach my $item (@contexts) {
1.34 raeburn 9885: push(@{$changes{'cancreate'}},$item);
9886: }
1.27 raeburn 9887: }
1.34 raeburn 9888:
1.27 raeburn 9889: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9890: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9891: if (!grep(/^\Q$type\E$/,@username_rule)) {
9892: push(@{$changes{'username_rule'}},$type);
9893: }
9894: }
9895: foreach my $type (@username_rule) {
9896: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9897: push(@{$changes{'username_rule'}},$type);
9898: }
9899: }
9900: } else {
9901: push(@{$changes{'username_rule'}},@username_rule);
9902: }
9903:
1.32 raeburn 9904: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9905: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9906: if (!grep(/^\Q$type\E$/,@id_rule)) {
9907: push(@{$changes{'id_rule'}},$type);
9908: }
9909: }
9910: foreach my $type (@id_rule) {
9911: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9912: push(@{$changes{'id_rule'}},$type);
9913: }
9914: }
9915: } else {
9916: push(@{$changes{'id_rule'}},@id_rule);
9917: }
9918:
1.43 raeburn 9919: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9920: my @authtypes = ('int','krb4','krb5','loc');
9921: my %authhash;
1.43 raeburn 9922: foreach my $item (@authen_contexts) {
1.28 raeburn 9923: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9924: foreach my $auth (@authtypes) {
9925: if (grep(/^\Q$auth\E$/,@authallowed)) {
9926: $authhash{$item}{$auth} = 1;
9927: } else {
9928: $authhash{$item}{$auth} = 0;
9929: }
9930: }
9931: }
9932: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9933: foreach my $item (@authen_contexts) {
1.28 raeburn 9934: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9935: foreach my $auth (@authtypes) {
9936: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9937: push(@{$changes{'authtypes'}},$item);
9938: last;
9939: }
9940: }
9941: }
9942: }
9943: } else {
1.43 raeburn 9944: foreach my $item (@authen_contexts) {
1.28 raeburn 9945: push(@{$changes{'authtypes'}},$item);
9946: }
9947: }
9948:
1.224 raeburn 9949: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9950: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9951: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9952: $save_usercreate{'id_rule'} = \@id_rule;
9953: $save_usercreate{'username_rule'} = \@username_rule,
9954: $save_usercreate{'authtypes'} = \%authhash;
9955:
1.27 raeburn 9956: my %usercreation_hash = (
1.224 raeburn 9957: usercreation => \%save_usercreate,
9958: );
1.27 raeburn 9959:
9960: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9961: $dom);
1.50 raeburn 9962:
1.224 raeburn 9963: if ($putresult eq 'ok') {
9964: if (keys(%changes) > 0) {
9965: $resulttext = &mt('Changes made:').'<ul>';
9966: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9967: my %lt = &usercreation_types();
9968: foreach my $type (@{$changes{'cancreate'}}) {
9969: my $chgtext = $lt{$type}.', ';
9970: if ($cancreate{$type} eq 'none') {
9971: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9972: } elsif ($cancreate{$type} eq 'any') {
9973: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9974: } elsif ($cancreate{$type} eq 'official') {
9975: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9976: } elsif ($cancreate{$type} eq 'unofficial') {
9977: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9978: }
9979: $resulttext .= '<li>'.$chgtext.'</li>';
9980: }
9981: }
9982: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9983: my ($rules,$ruleorder) =
9984: &Apache::lonnet::inst_userrules($dom,'username');
9985: my $chgtext = '<ul>';
9986: foreach my $type (@username_rule) {
9987: if (ref($rules->{$type}) eq 'HASH') {
9988: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9989: }
9990: }
9991: $chgtext .= '</ul>';
9992: if (@username_rule > 0) {
9993: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9994: } else {
9995: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9996: }
9997: }
9998: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9999: my ($idrules,$idruleorder) =
10000: &Apache::lonnet::inst_userrules($dom,'id');
10001: my $chgtext = '<ul>';
10002: foreach my $type (@id_rule) {
10003: if (ref($idrules->{$type}) eq 'HASH') {
10004: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10005: }
10006: }
10007: $chgtext .= '</ul>';
10008: if (@id_rule > 0) {
10009: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10010: } else {
10011: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10012: }
10013: }
10014: my %authname = &authtype_names();
10015: my %context_title = &context_names();
10016: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10017: my $chgtext = '<ul>';
10018: foreach my $type (@{$changes{'authtypes'}}) {
10019: my @allowed;
10020: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10021: foreach my $auth (@authtypes) {
10022: if ($authhash{$type}{$auth}) {
10023: push(@allowed,$authname{$auth});
10024: }
10025: }
10026: if (@allowed > 0) {
10027: $chgtext .= join(', ',@allowed).'</li>';
10028: } else {
10029: $chgtext .= &mt('none').'</li>';
10030: }
10031: }
10032: $chgtext .= '</ul>';
10033: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10034: $resulttext .= '</li>';
10035: }
10036: $resulttext .= '</ul>';
10037: } else {
10038: $resulttext = &mt('No changes made to user creation settings');
10039: }
10040: } else {
10041: $resulttext = '<span class="LC_error">'.
10042: &mt('An error occurred: [_1]',$putresult).'</span>';
10043: }
10044: if ($warningmsg ne '') {
10045: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10046: }
10047: return $resulttext;
10048: }
10049:
10050: sub modify_selfcreation {
10051: my ($dom,%domconfig) = @_;
10052: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
10053: my (%save_usercreate,%save_usermodify);
1.228 raeburn 10054: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10055: if (ref($types) eq 'ARRAY') {
10056: $usertypes->{'default'} = $othertitle;
10057: push(@{$types},'default');
10058: }
1.224 raeburn 10059: #
10060: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10061: #
10062: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10063: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10064: if ($key eq 'cancreate') {
10065: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10066: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10067: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
10068: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 10069: ($item eq 'recaptchaversion') ||
1.236 raeburn 10070: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 10071: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 10072: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10073: } else {
10074: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10075: }
10076: }
10077: }
10078: } elsif ($key eq 'email_rule') {
10079: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10080: } else {
10081: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10082: }
10083: }
10084: }
10085: #
10086: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10087: #
10088: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10089: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10090: if ($key eq 'selfcreate') {
10091: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10092: } else {
10093: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10094: }
10095: }
10096: }
10097:
10098: my @contexts = ('selfcreate');
10099: @{$cancreate{'selfcreate'}} = ();
10100: %{$cancreate{'emailusername'}} = ();
10101: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 10102: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 10103: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 10104: my %selfcreatetypes = (
10105: sso => 'users authenticated by institutional single sign on',
10106: login => 'users authenticated by institutional log-in',
1.236 raeburn 10107: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 10108: );
1.224 raeburn 10109: #
10110: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10111: # is permitted.
10112: #
1.236 raeburn 10113:
10114: my @statuses;
10115: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10116: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
10117: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
10118: }
10119: }
10120: push(@statuses,'default');
10121:
1.228 raeburn 10122: foreach my $item ('login','sso','email') {
1.224 raeburn 10123: if ($item eq 'email') {
1.236 raeburn 10124: if ($env{'form.cancreate_email'}) {
1.224 raeburn 10125: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 10126: push(@contexts,'selfcreateprocessing');
10127: foreach my $type (@statuses) {
10128: if ($type eq 'default') {
10129: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
10130: } else {
10131: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10132: }
10133: }
1.224 raeburn 10134: }
10135: } else {
10136: if ($env{'form.cancreate_'.$item}) {
10137: push(@{$cancreate{'selfcreate'}},$item);
10138: }
10139: }
10140: }
10141: my (@email_rule,%userinfo,%savecaptcha);
10142: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10143: #
1.228 raeburn 10144: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10145: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 10146: #
1.236 raeburn 10147:
1.244 raeburn 10148: if ($env{'form.cancreate_email'}) {
1.228 raeburn 10149: push(@contexts,'emailusername');
10150: if (ref($types) eq 'ARRAY') {
10151: foreach my $type (@{$types}) {
10152: if (ref($infofields) eq 'ARRAY') {
10153: foreach my $field (@{$infofields}) {
10154: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10155: $cancreate{'emailusername'}{$type}{$field} = $1;
10156: }
10157: }
1.224 raeburn 10158: }
10159: }
10160: }
10161: #
10162: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
10163: # queued requests for self-creation of account using e-mail address as username
10164: #
10165:
10166: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10167: @approvalnotify = sort(@approvalnotify);
10168: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10169: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10170: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10171: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10172: push(@{$changes{'cancreate'}},'notify');
10173: }
10174: } else {
10175: if ($cancreate{'notify'}{'approval'}) {
10176: push(@{$changes{'cancreate'}},'notify');
10177: }
10178: }
10179: } elsif ($cancreate{'notify'}{'approval'}) {
10180: push(@{$changes{'cancreate'}},'notify');
10181: }
10182:
10183: #
10184: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
10185: #
10186: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
10187: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10188: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10189: if (@{$curr_usercreation{'email_rule'}} > 0) {
10190: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
10191: if (!grep(/^\Q$type\E$/,@email_rule)) {
10192: push(@{$changes{'email_rule'}},$type);
10193: }
10194: }
10195: }
10196: if (@email_rule > 0) {
10197: foreach my $type (@email_rule) {
10198: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
10199: push(@{$changes{'email_rule'}},$type);
10200: }
10201: }
10202: }
10203: } elsif (@email_rule > 0) {
10204: push(@{$changes{'email_rule'}},@email_rule);
10205: }
10206: }
10207: #
1.236 raeburn 10208: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 10209: # institutional log-in.
10210: #
10211: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10212: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10213: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10214: ($domdefaults{'auth_def'} eq 'localauth'))) {
10215: $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.').' '.
10216: &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.');
10217: }
10218: }
10219: my @fields = ('lastname','firstname','middlename','generation',
10220: 'permanentemail','id');
1.240 raeburn 10221: my @shibfields = (@fields,'inststatus');
1.224 raeburn 10222: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10223: #
10224: # Where usernames may created for institutional log-in and/or institutional single sign on:
10225: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10226: # may self-create accounts
10227: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10228: # which the user may supply, if institutional data is unavailable.
10229: #
10230: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10231: if (ref($types) eq 'ARRAY') {
1.228 raeburn 10232: if (@{$types} > 1) {
1.224 raeburn 10233: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10234: push(@contexts,'statustocreate');
10235: } else {
10236: undef($cancreate{'statustocreate'});
10237: }
10238: foreach my $type (@{$types}) {
10239: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10240: foreach my $field (@fields) {
10241: if (grep(/^\Q$field\E$/,@modifiable)) {
10242: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10243: } else {
10244: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10245: }
10246: }
10247: }
10248: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10249: foreach my $type (@{$types}) {
10250: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10251: foreach my $field (@fields) {
10252: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10253: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10254: push(@{$changes{'selfcreate'}},$type);
10255: last;
10256: }
10257: }
10258: }
10259: }
10260: } else {
10261: foreach my $type (@{$types}) {
10262: push(@{$changes{'selfcreate'}},$type);
10263: }
10264: }
10265: }
1.240 raeburn 10266: foreach my $field (@shibfields) {
10267: if ($env{'form.shibenv_'.$field} ne '') {
10268: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10269: }
10270: }
10271: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10272: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10273: foreach my $field (@shibfields) {
10274: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10275: push(@{$changes{'cancreate'}},'shibenv');
10276: }
10277: }
10278: } else {
10279: foreach my $field (@shibfields) {
10280: if ($env{'form.shibenv_'.$field}) {
10281: push(@{$changes{'cancreate'}},'shibenv');
10282: last;
10283: }
10284: }
10285: }
10286: }
1.224 raeburn 10287: }
10288: foreach my $item (@contexts) {
10289: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10290: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10291: if (ref($cancreate{$item}) eq 'ARRAY') {
10292: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10293: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10294: push(@{$changes{'cancreate'}},$item);
10295: }
10296: }
10297: }
10298: }
10299: if (ref($cancreate{$item}) eq 'ARRAY') {
10300: foreach my $type (@{$cancreate{$item}}) {
10301: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10302: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10303: push(@{$changes{'cancreate'}},$item);
10304: }
10305: }
10306: }
10307: }
10308: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10309: if (ref($cancreate{$item}) eq 'HASH') {
10310: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 10311: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10312: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10313: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10314: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10315: push(@{$changes{'cancreate'}},$item);
10316: }
10317: }
10318: }
1.236 raeburn 10319: } elsif ($item eq 'selfcreateprocessing') {
10320: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10321: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10322: push(@{$changes{'cancreate'}},$item);
10323: }
10324: }
1.228 raeburn 10325: } else {
10326: if (!$cancreate{$item}{$curr}) {
10327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10328: push(@{$changes{'cancreate'}},$item);
10329: }
1.224 raeburn 10330: }
10331: }
10332: }
10333: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 10334: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10335: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10336: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10337: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10338: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10339: push(@{$changes{'cancreate'}},$item);
10340: }
10341: }
10342: } else {
10343: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10344: push(@{$changes{'cancreate'}},$item);
10345: }
10346: }
10347: }
1.236 raeburn 10348: } elsif ($item eq 'selfcreateprocessing') {
10349: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10350: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10351: push(@{$changes{'cancreate'}},$item);
10352: }
10353: }
1.228 raeburn 10354: } else {
10355: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10356: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10357: push(@{$changes{'cancreate'}},$item);
10358: }
1.224 raeburn 10359: }
10360: }
10361: }
10362: }
10363: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10364: if (ref($cancreate{$item}) eq 'ARRAY') {
10365: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10366: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10367: push(@{$changes{'cancreate'}},$item);
10368: }
10369: }
10370: } elsif (ref($cancreate{$item}) eq 'HASH') {
10371: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10372: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10373: push(@{$changes{'cancreate'}},$item);
10374: }
10375: }
10376: }
10377: } elsif ($item eq 'emailusername') {
1.228 raeburn 10378: if (ref($cancreate{$item}) eq 'HASH') {
10379: foreach my $type (keys(%{$cancreate{$item}})) {
10380: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10381: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10382: if ($cancreate{$item}{$type}{$field}) {
10383: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10384: push(@{$changes{'cancreate'}},$item);
10385: }
10386: last;
10387: }
10388: }
10389: }
10390: }
1.224 raeburn 10391: }
10392: }
10393: }
10394: #
10395: # Populate %save_usercreate hash with updates to self-creation configuration.
10396: #
10397: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10398: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10399: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10400: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10401: if (ref($cancreate{'notify'}) eq 'HASH') {
10402: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10403: }
1.236 raeburn 10404: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10405: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10406: }
1.224 raeburn 10407: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10408: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10409: }
1.240 raeburn 10410: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10411: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10412: }
1.224 raeburn 10413: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10414: $save_usercreate{'emailrule'} = \@email_rule;
10415:
10416: my %userconfig_hash = (
10417: usercreation => \%save_usercreate,
10418: usermodification => \%save_usermodify,
10419: );
10420: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10421: $dom);
10422: #
10423: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10424: #
1.27 raeburn 10425: if ($putresult eq 'ok') {
10426: if (keys(%changes) > 0) {
10427: $resulttext = &mt('Changes made:').'<ul>';
10428: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10429: my %lt = &selfcreation_types();
1.34 raeburn 10430: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10431: my $chgtext;
1.45 raeburn 10432: if ($type eq 'selfcreate') {
1.50 raeburn 10433: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10434: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10435: } else {
1.224 raeburn 10436: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10437: '<ul>';
1.50 raeburn 10438: foreach my $case (@{$cancreate{$type}}) {
10439: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10440: }
10441: $chgtext .= '</ul>';
1.100 raeburn 10442: if (ref($cancreate{$type}) eq 'ARRAY') {
10443: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10444: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10445: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10446: $chgtext .= '<br />'.
10447: '<span class="LC_warning">'.
10448: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10449: '</span>';
1.100 raeburn 10450: }
10451: }
10452: }
10453: }
1.43 raeburn 10454: }
1.240 raeburn 10455: } elsif ($type eq 'shibenv') {
10456: if (keys(%{$cancreate{$type}}) == 0) {
10457: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10458: } else {
10459: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10460: '<ul>';
10461: foreach my $field (@shibfields) {
10462: next if ($cancreate{$type}{$field} eq '');
10463: if ($field eq 'inststatus') {
10464: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10465: } else {
10466: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10467: }
10468: }
10469: $chgtext .= '</ul>';
10470: }
1.93 raeburn 10471: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10472: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10473: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10474: if (@{$cancreate{'selfcreate'}} > 0) {
10475: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10476: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10477: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10478: $chgtext .= '<br />'.
10479: '<span class="LC_warning">'.
10480: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10481: '</span>';
10482: }
1.96 raeburn 10483: } elsif (ref($usertypes) eq 'HASH') {
10484: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10485: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10486: } else {
10487: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10488: }
10489: $chgtext .= '<ul>';
10490: foreach my $case (@{$cancreate{$type}}) {
10491: if ($case eq 'default') {
10492: $chgtext .= '<li>'.$othertitle.'</li>';
10493: } else {
10494: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10495: }
10496: }
1.100 raeburn 10497: $chgtext .= '</ul>';
10498: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10499: $chgtext .= '<br /><span class="LC_warning">'.
10500: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10501: '</span>';
1.100 raeburn 10502: }
10503: }
10504: } else {
10505: if (@{$cancreate{$type}} == 0) {
10506: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10507: } else {
10508: $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 10509: }
10510: }
10511: }
1.236 raeburn 10512: } elsif ($type eq 'selfcreateprocessing') {
10513: my %choices = &Apache::lonlocal::texthash (
10514: automatic => 'Automatic approval',
10515: approval => 'Queued for approval',
10516: );
10517: if (@statuses > 1) {
10518: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10519: '<ul>';
10520: foreach my $type (@statuses) {
10521: if ($type eq 'default') {
10522: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10523: } else {
10524: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10525: }
10526: }
10527: $chgtext .= '</ul>';
10528: } else {
10529: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10530: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10531: }
1.165 raeburn 10532: } elsif ($type eq 'captcha') {
1.224 raeburn 10533: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10534: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10535: } else {
10536: my %captchas = &captcha_phrases();
1.224 raeburn 10537: if ($captchas{$savecaptcha{$type}}) {
10538: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10539: } else {
1.210 raeburn 10540: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10541: }
10542: }
10543: } elsif ($type eq 'recaptchakeys') {
10544: my ($privkey,$pubkey);
1.224 raeburn 10545: if (ref($savecaptcha{$type}) eq 'HASH') {
10546: $pubkey = $savecaptcha{$type}{'public'};
10547: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10548: }
10549: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10550: if (!$pubkey) {
10551: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10552: } else {
10553: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10554: }
10555: if (!$privkey) {
10556: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10557: } else {
10558: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10559: }
10560: $chgtext .= '</ul>';
1.269 raeburn 10561: } elsif ($type eq 'recaptchaversion') {
10562: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10563: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10564: }
1.224 raeburn 10565: } elsif ($type eq 'emailusername') {
10566: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10567: if (ref($types) eq 'ARRAY') {
10568: foreach my $type (@{$types}) {
10569: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10570: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10571: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10572: '<ul>';
10573: foreach my $field (@{$infofields}) {
10574: if ($cancreate{'emailusername'}{$type}{$field}) {
10575: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10576: }
10577: }
1.245 raeburn 10578: $chgtext .= '</ul>';
10579: } else {
10580: $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 10581: }
10582: } else {
1.245 raeburn 10583: $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 10584: }
10585: }
10586: }
10587: }
10588: } elsif ($type eq 'notify') {
10589: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10590: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10591: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10592: if ($cancreate{'notify'}{'approval'}) {
10593: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10594: }
10595: }
1.43 raeburn 10596: }
1.34 raeburn 10597: }
1.224 raeburn 10598: if ($chgtext) {
10599: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10600: }
10601: }
10602: }
1.43 raeburn 10603: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10604: my ($emailrules,$emailruleorder) =
10605: &Apache::lonnet::inst_userrules($dom,'email');
10606: my $chgtext = '<ul>';
10607: foreach my $type (@email_rule) {
10608: if (ref($emailrules->{$type}) eq 'HASH') {
10609: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10610: }
10611: }
10612: $chgtext .= '</ul>';
10613: if (@email_rule > 0) {
1.224 raeburn 10614: $resulttext .= '<li>'.
10615: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10616: $chgtext.
10617: '</li>';
1.43 raeburn 10618: } else {
1.224 raeburn 10619: $resulttext .= '<li>'.
10620: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10621: '</li>';
1.43 raeburn 10622: }
10623: }
1.224 raeburn 10624: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10625: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10626: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10627: foreach my $type (@{$changes{'selfcreate'}}) {
10628: my $typename = $type;
10629: if (ref($usertypes) eq 'HASH') {
10630: if ($usertypes->{$type} ne '') {
10631: $typename = $usertypes->{$type};
10632: }
10633: }
10634: my @modifiable;
10635: $resulttext .= '<li>'.
10636: &mt('Self-creation of account by users with status: [_1]',
10637: '<span class="LC_cusr_emph">'.$typename.'</span>').
10638: ' - '.&mt('modifiable fields (if institutional data blank): ');
10639: foreach my $field (@fields) {
10640: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10641: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10642: }
10643: }
1.224 raeburn 10644: if (@modifiable > 0) {
10645: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10646: } else {
1.224 raeburn 10647: $resulttext .= &mt('none');
1.43 raeburn 10648: }
1.224 raeburn 10649: $resulttext .= '</li>';
1.28 raeburn 10650: }
1.224 raeburn 10651: $resulttext .= '</ul></li>';
1.28 raeburn 10652: }
1.27 raeburn 10653: $resulttext .= '</ul>';
10654: } else {
1.224 raeburn 10655: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10656: }
10657: } else {
10658: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10659: &mt('An error occurred: [_1]',$putresult).'</span>';
10660: }
1.43 raeburn 10661: if ($warningmsg ne '') {
10662: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10663: }
1.23 raeburn 10664: return $resulttext;
10665: }
10666:
1.165 raeburn 10667: sub process_captcha {
10668: my ($container,$changes,$newsettings,$current) = @_;
10669: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10670: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10671: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10672: $newsettings->{'captcha'} = 'original';
10673: }
10674: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10675: if ($container eq 'cancreate') {
1.169 raeburn 10676: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10677: push(@{$changes->{'cancreate'}},'captcha');
10678: } elsif (!defined($changes->{'cancreate'})) {
10679: $changes->{'cancreate'} = ['captcha'];
10680: }
10681: } else {
10682: $changes->{'captcha'} = 1;
1.165 raeburn 10683: }
10684: }
1.269 raeburn 10685: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10686: if ($newsettings->{'captcha'} eq 'recaptcha') {
10687: $newpub = $env{'form.'.$container.'_recaptchapub'};
10688: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10689: $newpub =~ s/[^\w\-]//g;
10690: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10691: $newsettings->{'recaptchakeys'} = {
10692: public => $newpub,
10693: private => $newpriv,
10694: };
1.269 raeburn 10695: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10696: $newversion =~ s/\D//g;
10697: if ($newversion ne '2') {
10698: $newversion = 1;
10699: }
10700: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10701: }
10702: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10703: $currpub = $current->{'recaptchakeys'}{'public'};
10704: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10705: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10706: $newsettings->{'recaptchakeys'} = {
10707: public => '',
10708: private => '',
10709: }
10710: }
1.165 raeburn 10711: }
1.269 raeburn 10712: if ($current->{'captcha'} eq 'recaptcha') {
10713: $currversion = $current->{'recaptchaversion'};
10714: if ($currversion ne '2') {
10715: $currversion = 1;
10716: }
10717: }
10718: if ($currversion ne $newversion) {
10719: if ($container eq 'cancreate') {
10720: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10721: push(@{$changes->{'cancreate'}},'recaptchaversion');
10722: } elsif (!defined($changes->{'cancreate'})) {
10723: $changes->{'cancreate'} = ['recaptchaversion'];
10724: }
10725: } else {
10726: $changes->{'recaptchaversion'} = 1;
10727: }
10728: }
1.165 raeburn 10729: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10730: if ($container eq 'cancreate') {
10731: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10732: push(@{$changes->{'cancreate'}},'recaptchakeys');
10733: } elsif (!defined($changes->{'cancreate'})) {
10734: $changes->{'cancreate'} = ['recaptchakeys'];
10735: }
10736: } else {
1.210 raeburn 10737: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10738: }
10739: }
10740: return;
10741: }
10742:
1.33 raeburn 10743: sub modify_usermodification {
10744: my ($dom,%domconfig) = @_;
1.224 raeburn 10745: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10746: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10747: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10748: if ($key eq 'selfcreate') {
10749: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10750: } else {
10751: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10752: }
1.33 raeburn 10753: }
10754: }
1.224 raeburn 10755: my @contexts = ('author','course');
1.33 raeburn 10756: my %context_title = (
10757: author => 'In author context',
10758: course => 'In course context',
10759: );
10760: my @fields = ('lastname','firstname','middlename','generation',
10761: 'permanentemail','id');
10762: my %roles = (
10763: author => ['ca','aa'],
10764: course => ['st','ep','ta','in','cr'],
10765: );
10766: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10767: foreach my $context (@contexts) {
10768: foreach my $role (@{$roles{$context}}) {
10769: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10770: foreach my $item (@fields) {
10771: if (grep(/^\Q$item\E$/,@modifiable)) {
10772: $modifyhash{$context}{$role}{$item} = 1;
10773: } else {
10774: $modifyhash{$context}{$role}{$item} = 0;
10775: }
10776: }
10777: }
10778: if (ref($curr_usermodification{$context}) eq 'HASH') {
10779: foreach my $role (@{$roles{$context}}) {
10780: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10781: foreach my $field (@fields) {
10782: if ($modifyhash{$context}{$role}{$field} ne
10783: $curr_usermodification{$context}{$role}{$field}) {
10784: push(@{$changes{$context}},$role);
10785: last;
10786: }
10787: }
10788: }
10789: }
10790: } else {
10791: foreach my $context (@contexts) {
10792: foreach my $role (@{$roles{$context}}) {
10793: push(@{$changes{$context}},$role);
10794: }
10795: }
10796: }
10797: }
10798: my %usermodification_hash = (
10799: usermodification => \%modifyhash,
10800: );
10801: my $putresult = &Apache::lonnet::put_dom('configuration',
10802: \%usermodification_hash,$dom);
10803: if ($putresult eq 'ok') {
10804: if (keys(%changes) > 0) {
10805: $resulttext = &mt('Changes made: ').'<ul>';
10806: foreach my $context (@contexts) {
10807: if (ref($changes{$context}) eq 'ARRAY') {
10808: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10809: if (ref($changes{$context}) eq 'ARRAY') {
10810: foreach my $role (@{$changes{$context}}) {
10811: my $rolename;
1.224 raeburn 10812: if ($role eq 'cr') {
10813: $rolename = &mt('Custom');
1.33 raeburn 10814: } else {
1.224 raeburn 10815: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10816: }
10817: my @modifiable;
1.224 raeburn 10818: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10819: foreach my $field (@fields) {
10820: if ($modifyhash{$context}{$role}{$field}) {
10821: push(@modifiable,$fieldtitles{$field});
10822: }
10823: }
10824: if (@modifiable > 0) {
10825: $resulttext .= join(', ',@modifiable);
10826: } else {
10827: $resulttext .= &mt('none');
10828: }
10829: $resulttext .= '</li>';
10830: }
10831: $resulttext .= '</ul></li>';
10832: }
10833: }
10834: }
10835: $resulttext .= '</ul>';
10836: } else {
10837: $resulttext = &mt('No changes made to user modification settings');
10838: }
10839: } else {
10840: $resulttext = '<span class="LC_error">'.
10841: &mt('An error occurred: [_1]',$putresult).'</span>';
10842: }
10843: return $resulttext;
10844: }
10845:
1.43 raeburn 10846: sub modify_defaults {
1.212 raeburn 10847: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10848: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10849: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10850: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10851: my @authtypes = ('internal','krb4','krb5','localauth');
10852: foreach my $item (@items) {
10853: $newvalues{$item} = $env{'form.'.$item};
10854: if ($item eq 'auth_def') {
10855: if ($newvalues{$item} ne '') {
10856: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10857: push(@errors,$item);
10858: }
10859: }
10860: } elsif ($item eq 'lang_def') {
10861: if ($newvalues{$item} ne '') {
10862: if ($newvalues{$item} =~ /^(\w+)/) {
10863: my $langcode = $1;
1.103 raeburn 10864: if ($langcode ne 'x_chef') {
10865: if (code2language($langcode) eq '') {
10866: push(@errors,$item);
10867: }
1.43 raeburn 10868: }
10869: } else {
10870: push(@errors,$item);
10871: }
10872: }
1.54 raeburn 10873: } elsif ($item eq 'timezone_def') {
10874: if ($newvalues{$item} ne '') {
1.62 raeburn 10875: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10876: push(@errors,$item);
10877: }
10878: }
1.68 raeburn 10879: } elsif ($item eq 'datelocale_def') {
10880: if ($newvalues{$item} ne '') {
10881: my @datelocale_ids = DateTime::Locale->ids();
10882: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10883: push(@errors,$item);
10884: }
10885: }
1.141 raeburn 10886: } elsif ($item eq 'portal_def') {
10887: if ($newvalues{$item} ne '') {
10888: 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])\/?$/) {
10889: push(@errors,$item);
10890: }
10891: }
1.43 raeburn 10892: }
10893: if (grep(/^\Q$item\E$/,@errors)) {
10894: $newvalues{$item} = $domdefaults{$item};
10895: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10896: $changes{$item} = 1;
10897: }
1.72 raeburn 10898: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10899: }
10900: my %defaults_hash = (
1.72 raeburn 10901: defaults => \%newvalues,
10902: );
1.43 raeburn 10903: my $title = &defaults_titles();
1.236 raeburn 10904:
10905: my $currinststatus;
10906: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10907: $currinststatus = $domconfig{'inststatus'};
10908: } else {
10909: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10910: $currinststatus = {
10911: inststatustypes => $usertypes,
10912: inststatusorder => $types,
10913: inststatusguest => [],
10914: };
10915: }
10916: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10917: my @allpos;
10918: my %guests;
10919: my %alltypes;
10920: my ($currtitles,$currguests,$currorder);
10921: if (ref($currinststatus) eq 'HASH') {
10922: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10923: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10924: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10925: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10926: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10927: }
10928: }
10929: unless (grep(/^\Q$type\E$/,@todelete)) {
10930: my $position = $env{'form.inststatus_pos_'.$type};
10931: $position =~ s/\D+//g;
10932: $allpos[$position] = $type;
10933: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10934: $alltypes{$type} =~ s/`//g;
10935: if ($env{'form.inststatus_guest_'.$type}) {
10936: $guests{$type} = 1;
10937: }
10938: }
10939: }
10940: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10941: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10942: }
10943: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10944: $currtitles =~ s/,$//;
10945: }
10946: }
10947: if ($env{'form.addinststatus'}) {
10948: my $newtype = $env{'form.addinststatus'};
10949: $newtype =~ s/\W//g;
10950: unless (exists($alltypes{$newtype})) {
10951: if ($env{'form.addinststatus_guest'}) {
10952: $guests{$newtype} = 1;
10953: }
10954: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10955: $alltypes{$newtype} =~ s/`//g;
10956: my $position = $env{'form.addinststatus_pos'};
10957: $position =~ s/\D+//g;
10958: if ($position ne '') {
10959: $allpos[$position] = $newtype;
10960: }
10961: }
10962: }
10963: my (@orderedstatus,@orderedguests);
10964: foreach my $type (@allpos) {
10965: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10966: push(@orderedstatus,$type);
10967: if ($guests{$type}) {
10968: push(@orderedguests,$type);
10969: }
10970: }
10971: }
10972: foreach my $type (keys(%alltypes)) {
10973: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10974: delete($alltypes{$type});
10975: }
10976: }
10977: $defaults_hash{'inststatus'} = {
10978: inststatustypes => \%alltypes,
10979: inststatusorder => \@orderedstatus,
10980: inststatusguest => \@orderedguests,
10981: };
10982: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10983: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10984: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10985: }
10986: }
10987: if ($currorder ne join(',',@orderedstatus)) {
10988: $changes{'inststatus'}{'inststatusorder'} = 1;
10989: }
10990: if ($currguests ne join(',',@orderedguests)) {
10991: $changes{'inststatus'}{'inststatusguest'} = 1;
10992: }
10993: my $newtitles;
10994: foreach my $item (@orderedstatus) {
10995: $newtitles .= $alltypes{$item}.',';
10996: }
10997: $newtitles =~ s/,$//;
10998: if ($currtitles ne $newtitles) {
10999: $changes{'inststatus'}{'inststatustypes'} = 1;
11000: }
1.43 raeburn 11001: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11002: $dom);
11003: if ($putresult eq 'ok') {
11004: if (keys(%changes) > 0) {
11005: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 11006: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11007: 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";
11008: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 11009: if ($item eq 'inststatus') {
11010: if (ref($changes{'inststatus'}) eq 'HASH') {
11011: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
11012: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11013: foreach my $type (@orderedstatus) {
11014: $resulttext .= $alltypes{$type}.', ';
11015: }
11016: $resulttext =~ s/, $//;
11017: $resulttext .= '</li>';
11018: }
11019: if ($changes{'inststatus'}{'inststatusguest'}) {
11020: $resulttext .= '<li>';
11021: if (@orderedguests) {
11022: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
11023: foreach my $type (@orderedguests) {
11024: $resulttext .= $alltypes{$type}.', ';
11025: }
11026: $resulttext =~ s/, $//;
11027: } else {
11028: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
11029: }
11030: $resulttext .= '</li>';
11031: }
11032: }
11033: } else {
11034: my $value = $env{'form.'.$item};
11035: if ($value eq '') {
11036: $value = &mt('none');
11037: } elsif ($item eq 'auth_def') {
11038: my %authnames = &authtype_names();
11039: my %shortauth = (
11040: internal => 'int',
11041: krb4 => 'krb4',
11042: krb5 => 'krb5',
11043: localauth => 'loc',
11044: );
11045: $value = $authnames{$shortauth{$value}};
11046: }
11047: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11048: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11049: }
11050: }
11051: $resulttext .= '</ul>';
11052: $mailmsgtext .= "\n";
11053: my $cachetime = 24*60*60;
1.72 raeburn 11054: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11055: if (ref($lastactref) eq 'HASH') {
11056: $lastactref->{'domdefaults'} = 1;
11057: }
1.68 raeburn 11058: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 11059: my $notify = 1;
11060: if (ref($domconfig{'contacts'}) eq 'HASH') {
11061: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11062: $notify = 0;
11063: }
11064: }
11065: if ($notify) {
11066: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11067: "LON-CAPA Domain Settings Change - $dom",
11068: $mailmsgtext);
11069: }
1.54 raeburn 11070: }
1.43 raeburn 11071: } else {
1.54 raeburn 11072: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11073: }
11074: } else {
11075: $resulttext = '<span class="LC_error">'.
11076: &mt('An error occurred: [_1]',$putresult).'</span>';
11077: }
11078: if (@errors > 0) {
11079: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11080: foreach my $item (@errors) {
11081: $resulttext .= ' "'.$title->{$item}.'",';
11082: }
11083: $resulttext =~ s/,$//;
11084: }
11085: return $resulttext;
11086: }
11087:
1.46 raeburn 11088: sub modify_scantron {
1.205 raeburn 11089: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11090: my ($resulttext,%confhash,%changes,$errors);
11091: my $custom = 'custom.tab';
11092: my $default = 'default.tab';
11093: my $servadm = $r->dir_config('lonAdmEMail');
11094: my ($configuserok,$author_ok,$switchserver) =
11095: &config_check($dom,$confname,$servadm);
11096: if ($env{'form.scantronformat.filename'} ne '') {
11097: my $error;
11098: if ($configuserok eq 'ok') {
11099: if ($switchserver) {
1.130 raeburn 11100: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11101: } else {
11102: if ($author_ok eq 'ok') {
11103: my ($result,$scantronurl) =
11104: &publishlogo($r,'upload','scantronformat',$dom,
11105: $confname,'scantron','','',$custom);
11106: if ($result eq 'ok') {
11107: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11108: $changes{'scantronformat'} = 1;
1.46 raeburn 11109: } else {
11110: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11111: }
11112: } else {
11113: $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);
11114: }
11115: }
11116: } else {
11117: $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);
11118: }
11119: if ($error) {
11120: &Apache::lonnet::logthis($error);
11121: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11122: }
11123: }
1.48 raeburn 11124: if (ref($domconfig{'scantron'}) eq 'HASH') {
11125: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11126: if ($env{'form.scantronformat_del'}) {
11127: $confhash{'scantron'}{'scantronformat'} = '';
11128: $changes{'scantronformat'} = 1;
1.46 raeburn 11129: }
11130: }
11131: }
11132: if (keys(%confhash) > 0) {
11133: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11134: $dom);
11135: if ($putresult eq 'ok') {
11136: if (keys(%changes) > 0) {
1.48 raeburn 11137: if (ref($confhash{'scantron'}) eq 'HASH') {
11138: $resulttext = &mt('Changes made:').'<ul>';
11139: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11140: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11141: } else {
1.130 raeburn 11142: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11143: }
1.48 raeburn 11144: $resulttext .= '</ul>';
11145: } else {
1.130 raeburn 11146: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11147: }
11148: $resulttext .= '</ul>';
11149: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11150: if (ref($lastactref) eq 'HASH') {
11151: $lastactref->{'domainconfig'} = 1;
11152: }
1.46 raeburn 11153: } else {
1.130 raeburn 11154: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11155: }
11156: } else {
11157: $resulttext = '<span class="LC_error">'.
11158: &mt('An error occurred: [_1]',$putresult).'</span>';
11159: }
11160: } else {
1.130 raeburn 11161: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11162: }
11163: if ($errors) {
11164: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11165: $errors.'</ul>';
11166: }
11167: return $resulttext;
11168: }
11169:
1.48 raeburn 11170: sub modify_coursecategories {
1.239 raeburn 11171: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11172: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11173: $cathash);
1.48 raeburn 11174: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 11175: my @catitems = ('unauth','auth');
11176: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11177: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11178: $cathash = $domconfig{'coursecategories'}{'cats'};
11179: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11180: $changes{'togglecats'} = 1;
11181: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11182: }
11183: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11184: $changes{'categorize'} = 1;
11185: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11186: }
1.120 raeburn 11187: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11188: $changes{'togglecatscomm'} = 1;
11189: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11190: }
11191: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11192: $changes{'categorizecomm'} = 1;
11193: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 11194:
11195: }
11196: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
11197: $changes{'togglecatsplace'} = 1;
11198: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
11199: }
11200: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
11201: $changes{'categorizeplace'} = 1;
11202: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 11203: }
1.238 raeburn 11204: foreach my $item (@catitems) {
11205: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11206: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11207: $changes{$item} = 1;
11208: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11209: }
11210: }
11211: }
1.57 raeburn 11212: } else {
11213: $changes{'togglecats'} = 1;
11214: $changes{'categorize'} = 1;
1.124 raeburn 11215: $changes{'togglecatscomm'} = 1;
11216: $changes{'categorizecomm'} = 1;
1.272 raeburn 11217: $changes{'togglecatsplace'} = 1;
11218: $changes{'categorizeplace'} = 1;
1.87 raeburn 11219: $domconfig{'coursecategories'} = {
11220: togglecats => $env{'form.togglecats'},
11221: categorize => $env{'form.categorize'},
1.124 raeburn 11222: togglecatscomm => $env{'form.togglecatscomm'},
11223: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 11224: togglecatsplace => $env{'form.togglecatsplace'},
11225: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 11226: };
1.238 raeburn 11227: foreach my $item (@catitems) {
11228: if ($env{'form.coursecat_'.$item} ne 'std') {
11229: $changes{$item} = 1;
11230: }
11231: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11232: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11233: }
11234: }
1.57 raeburn 11235: }
11236: if (ref($cathash) eq 'HASH') {
11237: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11238: push (@deletecategory,'instcode::0');
11239: }
1.120 raeburn 11240: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11241: push(@deletecategory,'communities::0');
11242: }
1.272 raeburn 11243: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
11244: push(@deletecategory,'placement::0');
11245: }
1.48 raeburn 11246: }
1.57 raeburn 11247: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11248: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11249: if (@deletecategory > 0) {
11250: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11251: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11252: foreach my $item (@deletecategory) {
1.57 raeburn 11253: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11254: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11255: $deletions{$item} = 1;
1.57 raeburn 11256: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11257: }
11258: }
11259: }
1.57 raeburn 11260: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11261: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11262: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11263: $reorderings{$item} = 1;
1.57 raeburn 11264: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11265: }
11266: if ($env{'form.addcategory_name_'.$item} ne '') {
11267: my $newcat = $env{'form.addcategory_name_'.$item};
11268: my $newdepth = $depth+1;
11269: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11270: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11271: $adds{$newitem} = 1;
11272: }
11273: if ($env{'form.subcat_'.$item} ne '') {
11274: my $newcat = $env{'form.subcat_'.$item};
11275: my $newdepth = $depth+1;
11276: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11277: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11278: $adds{$newitem} = 1;
11279: }
11280: }
11281: }
11282: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11283: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11284: my $newitem = 'instcode::0';
1.57 raeburn 11285: if ($cathash->{$newitem} eq '') {
11286: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11287: $adds{$newitem} = 1;
11288: }
11289: } else {
11290: my $newitem = 'instcode::0';
1.57 raeburn 11291: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11292: $adds{$newitem} = 1;
11293: }
11294: }
1.120 raeburn 11295: if ($env{'form.communities'} eq '1') {
11296: if (ref($cathash) eq 'HASH') {
11297: my $newitem = 'communities::0';
11298: if ($cathash->{$newitem} eq '') {
11299: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11300: $adds{$newitem} = 1;
11301: }
11302: } else {
11303: my $newitem = 'communities::0';
11304: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11305: $adds{$newitem} = 1;
11306: }
11307: }
1.272 raeburn 11308: if ($env{'form.placement'} eq '1') {
11309: if (ref($cathash) eq 'HASH') {
11310: my $newitem = 'placement::0';
11311: if ($cathash->{$newitem} eq '') {
11312: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11313: $adds{$newitem} = 1;
11314: }
11315: } else {
11316: my $newitem = 'placement::0';
11317: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
11318: $adds{$newitem} = 1;
11319: }
11320: }
1.48 raeburn 11321: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11322: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 11323: ($env{'form.addcategory_name'} ne 'communities') &&
11324: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 11325: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11326: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11327: $adds{$newitem} = 1;
11328: }
1.48 raeburn 11329: }
1.57 raeburn 11330: my $putresult;
1.48 raeburn 11331: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11332: if (keys(%deletions) > 0) {
11333: foreach my $key (keys(%deletions)) {
11334: if ($predelallitems{$key} ne '') {
11335: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11336: }
11337: }
11338: }
11339: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11340: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11341: if (ref($chkcats[0]) eq 'ARRAY') {
11342: my $depth = 0;
11343: my $chg = 0;
11344: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11345: my $name = $chkcats[0][$i];
11346: my $item;
11347: if ($name eq '') {
11348: $chg ++;
11349: } else {
11350: $item = &escape($name).'::0';
11351: if ($chg) {
1.57 raeburn 11352: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11353: }
11354: $depth ++;
1.57 raeburn 11355: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11356: $depth --;
11357: }
11358: }
11359: }
1.57 raeburn 11360: }
11361: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11362: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11363: if ($putresult eq 'ok') {
1.57 raeburn 11364: my %title = (
1.120 raeburn 11365: togglecats => 'Show/Hide a course in catalog',
11366: categorize => 'Assign a category to a course',
11367: togglecatscomm => 'Show/Hide a community in catalog',
11368: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11369: );
11370: my %level = (
1.120 raeburn 11371: dom => 'set in Domain ("Modify Course/Community")',
11372: crs => 'set in Course ("Course Configuration")',
11373: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11374: none => 'No catalog',
11375: std => 'Standard catalog',
11376: domonly => 'Domain-only catalog',
11377: codesrch => 'Code search form',
1.57 raeburn 11378: );
1.48 raeburn 11379: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11380: if ($changes{'togglecats'}) {
11381: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11382: }
11383: if ($changes{'categorize'}) {
11384: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11385: }
1.120 raeburn 11386: if ($changes{'togglecatscomm'}) {
11387: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11388: }
11389: if ($changes{'categorizecomm'}) {
11390: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11391: }
1.238 raeburn 11392: if ($changes{'unauth'}) {
11393: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11394: }
11395: if ($changes{'auth'}) {
11396: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11397: }
1.57 raeburn 11398: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11399: my $cathash;
11400: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11401: $cathash = $domconfig{'coursecategories'}{'cats'};
11402: } else {
11403: $cathash = {};
11404: }
11405: my (@cats,@trails,%allitems);
11406: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11407: if (keys(%deletions) > 0) {
11408: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11409: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11410: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11411: }
11412: $resulttext .= '</ul></li>';
11413: }
11414: if (keys(%reorderings) > 0) {
11415: my %sort_by_trail;
11416: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11417: foreach my $key (keys(%reorderings)) {
11418: if ($allitems{$key} ne '') {
11419: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11420: }
1.48 raeburn 11421: }
1.57 raeburn 11422: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11423: $resulttext .= '<li>'.$trails[$trail].'</li>';
11424: }
11425: $resulttext .= '</ul></li>';
1.48 raeburn 11426: }
1.57 raeburn 11427: if (keys(%adds) > 0) {
11428: my %sort_by_trail;
11429: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11430: foreach my $key (keys(%adds)) {
11431: if ($allitems{$key} ne '') {
11432: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11433: }
11434: }
11435: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11436: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11437: }
1.57 raeburn 11438: $resulttext .= '</ul></li>';
1.48 raeburn 11439: }
11440: }
11441: $resulttext .= '</ul>';
1.239 raeburn 11442: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11443: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11444: if ($changes{'auth'}) {
11445: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11446: }
11447: if ($changes{'unauth'}) {
11448: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11449: }
11450: my $cachetime = 24*60*60;
11451: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11452: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11453: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11454: }
11455: }
1.48 raeburn 11456: } else {
11457: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11458: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11459: }
11460: } else {
1.120 raeburn 11461: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11462: }
11463: return $resulttext;
11464: }
11465:
1.69 raeburn 11466: sub modify_serverstatuses {
11467: my ($dom,%domconfig) = @_;
11468: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11469: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11470: %currserverstatus = %{$domconfig{'serverstatuses'}};
11471: }
11472: my @pages = &serverstatus_pages();
11473: foreach my $type (@pages) {
11474: $newserverstatus{$type}{'namedusers'} = '';
11475: $newserverstatus{$type}{'machines'} = '';
11476: if (defined($env{'form.'.$type.'_namedusers'})) {
11477: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11478: my @okusers;
11479: foreach my $user (@users) {
11480: my ($uname,$udom) = split(/:/,$user);
11481: if (($udom =~ /^$match_domain$/) &&
11482: (&Apache::lonnet::domain($udom)) &&
11483: ($uname =~ /^$match_username$/)) {
11484: if (!grep(/^\Q$user\E/,@okusers)) {
11485: push(@okusers,$user);
11486: }
11487: }
11488: }
11489: if (@okusers > 0) {
11490: @okusers = sort(@okusers);
11491: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11492: }
11493: }
11494: if (defined($env{'form.'.$type.'_machines'})) {
11495: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11496: my @okmachines;
11497: foreach my $ip (@machines) {
11498: my @parts = split(/\./,$ip);
11499: next if (@parts < 4);
11500: my $badip = 0;
11501: for (my $i=0; $i<4; $i++) {
11502: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11503: $badip = 1;
11504: last;
11505: }
11506: }
11507: if (!$badip) {
11508: push(@okmachines,$ip);
11509: }
11510: }
11511: @okmachines = sort(@okmachines);
11512: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11513: }
11514: }
11515: my %serverstatushash = (
11516: serverstatuses => \%newserverstatus,
11517: );
11518: foreach my $type (@pages) {
1.83 raeburn 11519: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11520: my (@current,@new);
1.83 raeburn 11521: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11522: if ($currserverstatus{$type}{$setting} ne '') {
11523: @current = split(/,/,$currserverstatus{$type}{$setting});
11524: }
11525: }
11526: if ($newserverstatus{$type}{$setting} ne '') {
11527: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11528: }
11529: if (@current > 0) {
11530: if (@new > 0) {
11531: foreach my $item (@current) {
11532: if (!grep(/^\Q$item\E$/,@new)) {
11533: $changes{$type}{$setting} = 1;
1.82 raeburn 11534: last;
11535: }
11536: }
1.84 raeburn 11537: foreach my $item (@new) {
11538: if (!grep(/^\Q$item\E$/,@current)) {
11539: $changes{$type}{$setting} = 1;
11540: last;
1.82 raeburn 11541: }
11542: }
11543: } else {
1.83 raeburn 11544: $changes{$type}{$setting} = 1;
1.69 raeburn 11545: }
1.83 raeburn 11546: } elsif (@new > 0) {
11547: $changes{$type}{$setting} = 1;
1.69 raeburn 11548: }
11549: }
11550: }
11551: if (keys(%changes) > 0) {
1.81 raeburn 11552: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11553: my $putresult = &Apache::lonnet::put_dom('configuration',
11554: \%serverstatushash,$dom);
11555: if ($putresult eq 'ok') {
11556: $resulttext .= &mt('Changes made:').'<ul>';
11557: foreach my $type (@pages) {
1.84 raeburn 11558: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11559: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11560: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11561: if ($newserverstatus{$type}{'namedusers'} eq '') {
11562: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11563: } else {
11564: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11565: }
1.84 raeburn 11566: }
11567: if ($changes{$type}{'machines'}) {
1.69 raeburn 11568: if ($newserverstatus{$type}{'machines'} eq '') {
11569: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11570: } else {
11571: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11572: }
11573:
11574: }
11575: $resulttext .= '</ul></li>';
11576: }
11577: }
11578: $resulttext .= '</ul>';
11579: } else {
11580: $resulttext = '<span class="LC_error">'.
11581: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11582:
11583: }
11584: } else {
11585: $resulttext = &mt('No changes made to access to server status pages');
11586: }
11587: return $resulttext;
11588: }
11589:
1.118 jms 11590: sub modify_helpsettings {
1.122 jms 11591: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11592: my ($resulttext,$errors,%changes,%helphash);
11593: my %defaultchecked = ('submitbugs' => 'on');
11594: my @offon = ('off','on');
1.118 jms 11595: my @toggles = ('submitbugs');
11596: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11597: foreach my $item (@toggles) {
1.166 raeburn 11598: if ($defaultchecked{$item} eq 'on') {
11599: if ($domconfig{'helpsettings'}{$item} eq '') {
11600: if ($env{'form.'.$item} eq '0') {
11601: $changes{$item} = 1;
11602: }
11603: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11604: $changes{$item} = 1;
11605: }
11606: } elsif ($defaultchecked{$item} eq 'off') {
11607: if ($domconfig{'helpsettings'}{$item} eq '') {
11608: if ($env{'form.'.$item} eq '1') {
11609: $changes{$item} = 1;
11610: }
11611: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11612: $changes{$item} = 1;
11613: }
11614: }
1.210 raeburn 11615: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11616: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11617: }
11618: }
1.118 jms 11619: }
1.123 jms 11620: my $putresult;
11621: if (keys(%changes) > 0) {
1.166 raeburn 11622: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11623: if ($putresult eq 'ok') {
1.166 raeburn 11624: $resulttext = &mt('Changes made:').'<ul>';
11625: foreach my $item (sort(keys(%changes))) {
11626: if ($item eq 'submitbugs') {
11627: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11628: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11629: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11630: }
11631: }
11632: $resulttext .= '</ul>';
11633: } else {
11634: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11635: $errors .= '<li><span class="LC_error">'.
11636: &mt('An error occurred storing the settings: [_1]',
11637: $putresult).'</span></li>';
1.166 raeburn 11638: }
1.118 jms 11639: }
11640: if ($errors) {
1.168 raeburn 11641: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11642: $errors.'</ul>';
11643: }
11644: return $resulttext;
11645: }
11646:
1.121 raeburn 11647: sub modify_coursedefaults {
1.212 raeburn 11648: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11649: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11650: my %defaultchecked = (
11651: 'canuse_pdfforms' => 'off',
11652: 'uselcmath' => 'on',
11653: 'usejsme' => 'on'
11654: );
11655: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11656: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 ! raeburn 11657: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
! 11658: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
! 11659: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 11660: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11661: my %staticdefaults = (
11662: anonsurvey_threshold => 10,
11663: uploadquota => 500,
1.257 raeburn 11664: postsubmit => 60,
1.276 ! raeburn 11665: mysqltables => 172800,
1.198 raeburn 11666: );
1.121 raeburn 11667:
11668: $defaultshash{'coursedefaults'} = {};
11669:
11670: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11671: if ($domconfig{'coursedefaults'} eq '') {
11672: $domconfig{'coursedefaults'} = {};
11673: }
11674: }
11675:
11676: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11677: foreach my $item (@toggles) {
11678: if ($defaultchecked{$item} eq 'on') {
11679: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11680: ($env{'form.'.$item} eq '0')) {
11681: $changes{$item} = 1;
1.192 raeburn 11682: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11683: $changes{$item} = 1;
11684: }
11685: } elsif ($defaultchecked{$item} eq 'off') {
11686: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11687: ($env{'form.'.$item} eq '1')) {
11688: $changes{$item} = 1;
11689: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11690: $changes{$item} = 1;
11691: }
11692: }
11693: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11694: }
1.198 raeburn 11695: foreach my $item (@numbers) {
11696: my ($currdef,$newdef);
1.208 raeburn 11697: $newdef = $env{'form.'.$item};
1.198 raeburn 11698: if ($item eq 'anonsurvey_threshold') {
11699: $currdef = $domconfig{'coursedefaults'}{$item};
11700: $newdef =~ s/\D//g;
11701: if ($newdef eq '' || $newdef < 1) {
11702: $newdef = 1;
11703: }
11704: $defaultshash{'coursedefaults'}{$item} = $newdef;
11705: } else {
1.276 ! raeburn 11706: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
! 11707: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
! 11708: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 11709: }
11710: $newdef =~ s/[^\w.\-]//g;
1.276 ! raeburn 11711: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 11712: }
11713: if ($currdef ne $newdef) {
11714: my $staticdef;
11715: if ($item eq 'anonsurvey_threshold') {
11716: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11717: $changes{$item} = 1;
11718: }
1.276 ! raeburn 11719: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
! 11720: my $setting = $1;
! 11721: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
! 11722: $changes{$setting} = 1;
1.198 raeburn 11723: }
11724: }
1.139 raeburn 11725: }
11726: }
1.264 raeburn 11727: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11728: my @currclonecode;
11729: if (ref($currclone) eq 'HASH') {
11730: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11731: @currclonecode = @{$currclone->{'instcode'}};
11732: }
11733: }
11734: my $newclone;
11735: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11736: $newclone = $env{'form.canclone'};
11737: }
11738: if ($newclone eq 'instcode') {
11739: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11740: my (%codedefaults,@code_order,@clonecode);
11741: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11742: \@code_order);
11743: foreach my $item (@code_order) {
11744: if (grep(/^\Q$item\E$/,@newcodes)) {
11745: push(@clonecode,$item);
11746: }
11747: }
11748: if (@clonecode) {
11749: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11750: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11751: if (@diffs) {
11752: $changes{'canclone'} = 1;
11753: }
11754: } else {
11755: $newclone eq '';
11756: }
11757: } elsif ($newclone ne '') {
11758: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11759: }
11760: if ($newclone ne $currclone) {
11761: $changes{'canclone'} = 1;
11762: }
1.257 raeburn 11763: my %credits;
11764: foreach my $type (@types) {
11765: unless ($type eq 'community') {
11766: $credits{$type} = $env{'form.'.$type.'_credits'};
11767: $credits{$type} =~ s/[^\d.]+//g;
11768: }
11769: }
11770: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11771: ($env{'form.coursecredits'} eq '1')) {
11772: $changes{'coursecredits'} = 1;
11773: foreach my $type (keys(%credits)) {
11774: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11775: }
11776: } else {
11777: if ($env{'form.coursecredits'} eq '1') {
11778: foreach my $type (@types) {
11779: unless ($type eq 'community') {
11780: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11781: $changes{'coursecredits'} = 1;
11782: }
11783: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11784: }
11785: }
11786: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11787: foreach my $type (@types) {
11788: unless ($type eq 'community') {
11789: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11790: $changes{'coursecredits'} = 1;
11791: last;
11792: }
11793: }
11794: }
11795: }
11796: }
11797: if ($env{'form.postsubmit'} eq '1') {
11798: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11799: my %currtimeout;
11800: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11801: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11802: $changes{'postsubmit'} = 1;
11803: }
11804: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11805: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11806: }
11807: } else {
11808: $changes{'postsubmit'} = 1;
11809: }
11810: foreach my $type (@types) {
11811: my $timeout = $env{'form.'.$type.'_timeout'};
11812: $timeout =~ s/\D//g;
11813: if ($timeout == $staticdefaults{'postsubmit'}) {
11814: $timeout = '';
11815: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11816: $timeout = '0';
11817: }
11818: unless ($timeout eq '') {
11819: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11820: }
11821: if (exists($currtimeout{$type})) {
11822: if ($timeout ne $currtimeout{$type}) {
11823: $changes{'postsubmit'} = 1;
11824: }
11825: } elsif ($timeout ne '') {
11826: $changes{'postsubmit'} = 1;
11827: }
11828: }
11829: } else {
11830: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11831: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11832: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11833: $changes{'postsubmit'} = 1;
11834: }
11835: } else {
11836: $changes{'postsubmit'} = 1;
11837: }
1.192 raeburn 11838: }
1.121 raeburn 11839: }
11840: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11841: $dom);
11842: if ($putresult eq 'ok') {
11843: if (keys(%changes) > 0) {
1.213 raeburn 11844: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11845: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11846: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 ! raeburn 11847: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 11848: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11849: if ($changes{$item}) {
11850: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11851: }
11852: }
1.192 raeburn 11853: if ($changes{'coursecredits'}) {
11854: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11855: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11856: $domdefaults{$type.'credits'} =
11857: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11858: }
11859: }
11860: }
11861: if ($changes{'postsubmit'}) {
11862: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11863: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11864: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11865: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11866: $domdefaults{$type.'postsubtimeout'} =
11867: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11868: }
11869: }
1.192 raeburn 11870: }
11871: }
1.198 raeburn 11872: if ($changes{'uploadquota'}) {
11873: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11874: foreach my $type (@types) {
11875: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11876: }
11877: }
11878: }
1.264 raeburn 11879: if ($changes{'canclone'}) {
11880: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11881: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11882: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11883: if (@clonecodes) {
11884: $domdefaults{'canclone'} = join('+',@clonecodes);
11885: }
11886: }
11887: } else {
11888: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11889: }
11890: }
1.121 raeburn 11891: my $cachetime = 24*60*60;
11892: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11893: if (ref($lastactref) eq 'HASH') {
11894: $lastactref->{'domdefaults'} = 1;
11895: }
1.121 raeburn 11896: }
11897: $resulttext = &mt('Changes made:').'<ul>';
11898: foreach my $item (sort(keys(%changes))) {
11899: if ($item eq 'canuse_pdfforms') {
11900: if ($env{'form.'.$item} eq '1') {
11901: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11902: } else {
11903: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11904: }
1.257 raeburn 11905: } elsif ($item eq 'uselcmath') {
11906: if ($env{'form.'.$item} eq '1') {
11907: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11908: } else {
11909: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11910: }
11911: } elsif ($item eq 'usejsme') {
11912: if ($env{'form.'.$item} eq '1') {
11913: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11914: } else {
11915: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11916: }
1.139 raeburn 11917: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 11918: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 11919: } elsif ($item eq 'uploadquota') {
11920: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11921: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11922: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11923: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 11924: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 11925: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 11926: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11927: '</ul>'.
11928: '</li>';
11929: } else {
11930: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11931: }
1.276 ! raeburn 11932: } elsif ($item eq 'mysqltables') {
! 11933: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
! 11934: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
! 11935: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
! 11936: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
! 11937: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
! 11938: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
! 11939: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
! 11940: '</ul>'.
! 11941: '</li>';
! 11942: } else {
! 11943: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
! 11944: }
1.257 raeburn 11945: } elsif ($item eq 'postsubmit') {
11946: if ($domdefaults{'postsubmit'} eq 'off') {
11947: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11948: } else {
11949: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11950: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11951: $resulttext .= &mt('durations:').'<ul>';
11952: foreach my $type (@types) {
11953: $resulttext .= '<li>';
11954: my $timeout;
11955: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11956: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11957: }
11958: my $display;
11959: if ($timeout eq '0') {
11960: $display = &mt('unlimited');
11961: } elsif ($timeout eq '') {
11962: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11963: } else {
11964: $display = &mt('[quant,_1,second]',$timeout);
11965: }
11966: if ($type eq 'community') {
11967: $resulttext .= &mt('Communities');
11968: } elsif ($type eq 'official') {
11969: $resulttext .= &mt('Official courses');
11970: } elsif ($type eq 'unofficial') {
11971: $resulttext .= &mt('Unofficial courses');
11972: } elsif ($type eq 'textbook') {
11973: $resulttext .= &mt('Textbook courses');
1.271 raeburn 11974: } elsif ($type eq 'placement') {
11975: $resulttext .= &mt('Placement tests');
1.257 raeburn 11976: }
11977: $resulttext .= ' -- '.$display.'</li>';
11978: }
11979: $resulttext .= '</ul>';
11980: }
11981: $resulttext .= '</li>';
11982: }
1.192 raeburn 11983: } elsif ($item eq 'coursecredits') {
11984: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11985: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 11986: ($domdefaults{'unofficialcredits'} eq '') &&
11987: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 11988: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11989: } else {
11990: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11991: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11992: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 11993: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 11994: '</ul>'.
11995: '</li>';
11996: }
11997: } else {
11998: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11999: }
1.264 raeburn 12000: } elsif ($item eq 'canclone') {
12001: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12002: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12003: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12004: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12005: }
12006: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12007: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12008: } else {
12009: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12010: }
1.140 raeburn 12011: }
1.121 raeburn 12012: }
12013: $resulttext .= '</ul>';
12014: } else {
12015: $resulttext = &mt('No changes made to course defaults');
12016: }
12017: } else {
12018: $resulttext = '<span class="LC_error">'.
12019: &mt('An error occurred: [_1]',$putresult).'</span>';
12020: }
12021: return $resulttext;
12022: }
12023:
1.231 raeburn 12024: sub modify_selfenrollment {
12025: my ($dom,$lastactref,%domconfig) = @_;
12026: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 12027: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 12028: my %titles = &tool_titles();
1.232 raeburn 12029: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12030: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 12031: $ordered{'default'} = ['types','registered','approval','limit'];
12032:
12033: my (%roles,%shown,%toplevel);
12034: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12035:
12036: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12037: if ($domconfig{'selfenrollment'} eq '') {
12038: $domconfig{'selfenrollment'} = {};
12039: }
12040: }
12041: %toplevel = (
12042: admin => 'Configuration Rights',
12043: default => 'Default settings',
12044: validation => 'Validation of self-enrollment requests',
12045: );
1.233 raeburn 12046: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 12047:
12048: if (ref($ordered{'admin'}) eq 'ARRAY') {
12049: foreach my $item (@{$ordered{'admin'}}) {
12050: foreach my $type (@types) {
12051: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12052: $selfenrollhash{'admin'}{$type}{$item} = 1;
12053: } else {
12054: $selfenrollhash{'admin'}{$type}{$item} = 0;
12055: }
12056: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12057: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12058: if ($selfenrollhash{'admin'}{$type}{$item} ne
12059: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12060: push(@{$changes{'admin'}{$type}},$item);
12061: }
12062: } else {
12063: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12064: push(@{$changes{'admin'}{$type}},$item);
12065: }
12066: }
12067: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12068: push(@{$changes{'admin'}{$type}},$item);
12069: }
12070: }
12071: }
12072: }
12073:
12074: foreach my $item (@{$ordered{'default'}}) {
12075: foreach my $type (@types) {
12076: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12077: if ($item eq 'types') {
12078: unless (($value eq 'all') || ($value eq 'dom')) {
12079: $value = '';
12080: }
12081: } elsif ($item eq 'registered') {
12082: unless ($value eq '1') {
12083: $value = 0;
12084: }
12085: } elsif ($item eq 'approval') {
12086: unless ($value =~ /^[012]$/) {
12087: $value = 0;
12088: }
12089: } else {
12090: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12091: $value = 'none';
12092: }
12093: }
12094: $selfenrollhash{'default'}{$type}{$item} = $value;
12095: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12096: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12097: if ($selfenrollhash{'default'}{$type}{$item} ne
12098: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12099: push(@{$changes{'default'}{$type}},$item);
12100: }
12101: } else {
12102: push(@{$changes{'default'}{$type}},$item);
12103: }
12104: } else {
12105: push(@{$changes{'default'}{$type}},$item);
12106: }
12107: if ($item eq 'limit') {
12108: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12109: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12110: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12111: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12112: }
12113: } else {
12114: $selfenrollhash{'default'}{$type}{'cap'} = '';
12115: }
12116: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12117: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12118: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12119: push(@{$changes{'default'}{$type}},'cap');
12120: }
12121: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12122: push(@{$changes{'default'}{$type}},'cap');
12123: }
12124: }
12125: }
12126: }
12127:
12128: foreach my $item (@{$itemsref}) {
12129: if ($item eq 'fields') {
12130: my @changed;
12131: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12132: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12133: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12134: }
12135: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12136: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12137: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12138: $domconfig{'selfenrollment'}{'validation'}{$item});
12139: } else {
12140: @changed = @{$selfenrollhash{'validation'}{$item}};
12141: }
12142: } else {
12143: @changed = @{$selfenrollhash{'validation'}{$item}};
12144: }
12145: if (@changed) {
12146: if ($selfenrollhash{'validation'}{$item}) {
12147: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12148: } else {
12149: $changes{'validation'}{$item} = &mt('None');
12150: }
12151: }
12152: } else {
12153: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12154: if ($item eq 'markup') {
12155: if ($env{'form.selfenroll_validation_'.$item}) {
12156: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12157: }
12158: }
12159: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12160: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12161: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12162: }
12163: }
12164: }
12165: }
12166:
12167: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12168: $dom);
12169: if ($putresult eq 'ok') {
12170: if (keys(%changes) > 0) {
12171: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12172: $resulttext = &mt('Changes made:').'<ul>';
12173: foreach my $key ('admin','default','validation') {
12174: if (ref($changes{$key}) eq 'HASH') {
12175: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12176: if ($key eq 'validation') {
12177: foreach my $item (@{$itemsref}) {
12178: if (exists($changes{$key}{$item})) {
12179: if ($item eq 'markup') {
12180: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12181: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12182: } else {
12183: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12184: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12185: }
12186: }
12187: }
12188: } else {
12189: foreach my $type (@types) {
12190: if ($type eq 'community') {
12191: $roles{'1'} = &mt('Community personnel');
12192: } else {
12193: $roles{'1'} = &mt('Course personnel');
12194: }
12195: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 12196: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12197: if ($key eq 'admin') {
12198: my @mgrdc = ();
12199: if (ref($ordered{$key}) eq 'ARRAY') {
12200: foreach my $item (@{$ordered{'admin'}}) {
12201: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12202: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12203: push(@mgrdc,$item);
12204: }
12205: }
12206: }
12207: if (@mgrdc) {
12208: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12209: } else {
12210: delete($domdefaults{$type.'selfenrolladmdc'});
12211: }
12212: }
12213: } else {
12214: if (ref($ordered{$key}) eq 'ARRAY') {
12215: foreach my $item (@{$ordered{$key}}) {
12216: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12217: $domdefaults{$type.'selfenroll'.$item} =
12218: $selfenrollhash{$key}{$type}{$item};
12219: }
12220: }
12221: }
12222: }
12223: }
1.231 raeburn 12224: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12225: foreach my $item (@{$ordered{$key}}) {
12226: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12227: $resulttext .= '<li>';
12228: if ($key eq 'admin') {
12229: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12230: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12231: } else {
12232: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12233: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12234: }
12235: $resulttext .= '</li>';
12236: }
12237: }
12238: $resulttext .= '</ul></li>';
12239: }
12240: }
12241: $resulttext .= '</ul></li>';
12242: }
12243: }
1.232 raeburn 12244: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12245: my $cachetime = 24*60*60;
12246: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12247: if (ref($lastactref) eq 'HASH') {
12248: $lastactref->{'domdefaults'} = 1;
12249: }
12250: }
1.231 raeburn 12251: }
12252: $resulttext .= '</ul>';
12253: } else {
12254: $resulttext = &mt('No changes made to self-enrollment settings');
12255: }
12256: } else {
12257: $resulttext = '<span class="LC_error">'.
12258: &mt('An error occurred: [_1]',$putresult).'</span>';
12259: }
12260: return $resulttext;
12261: }
12262:
1.137 raeburn 12263: sub modify_usersessions {
1.212 raeburn 12264: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12265: my @hostingtypes = ('version','excludedomain','includedomain');
12266: my @offloadtypes = ('primary','default');
12267: my %types = (
12268: remote => \@hostingtypes,
12269: hosted => \@hostingtypes,
12270: spares => \@offloadtypes,
12271: );
12272: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12273: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 12274: my (%by_ip,%by_location,@intdoms,@instdoms);
12275: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 12276: my @locations = sort(keys(%by_location));
1.137 raeburn 12277: my (%defaultshash,%changes);
12278: foreach my $prefix (@prefixes) {
12279: $defaultshash{'usersessions'}{$prefix} = {};
12280: }
1.212 raeburn 12281: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12282: my $resulttext;
1.138 raeburn 12283: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12284: foreach my $prefix (@prefixes) {
1.145 raeburn 12285: next if ($prefix eq 'spares');
12286: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12287: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12288: if ($type eq 'version') {
12289: my $value = $env{'form.'.$prefix.'_'.$type};
12290: my $okvalue;
12291: if ($value ne '') {
12292: if (grep(/^\Q$value\E$/,@lcversions)) {
12293: $okvalue = $value;
12294: }
12295: }
12296: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12297: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12298: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12299: if ($inuse == 0) {
12300: $changes{$prefix}{$type} = 1;
12301: } else {
12302: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12303: $changes{$prefix}{$type} = 1;
12304: }
12305: if ($okvalue ne '') {
12306: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12307: }
12308: }
12309: } else {
12310: if (($inuse == 1) && ($okvalue ne '')) {
12311: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12312: $changes{$prefix}{$type} = 1;
12313: }
12314: }
12315: } else {
12316: if (($inuse == 1) && ($okvalue ne '')) {
12317: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12318: $changes{$prefix}{$type} = 1;
12319: }
12320: }
12321: } else {
12322: if (($inuse == 1) && ($okvalue ne '')) {
12323: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12324: $changes{$prefix}{$type} = 1;
12325: }
12326: }
12327: } else {
12328: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12329: my @okvals;
12330: foreach my $val (@vals) {
1.138 raeburn 12331: if ($val =~ /:/) {
12332: my @items = split(/:/,$val);
12333: foreach my $item (@items) {
12334: if (ref($by_location{$item}) eq 'ARRAY') {
12335: push(@okvals,$item);
12336: }
12337: }
12338: } else {
12339: if (ref($by_location{$val}) eq 'ARRAY') {
12340: push(@okvals,$val);
12341: }
1.137 raeburn 12342: }
12343: }
12344: @okvals = sort(@okvals);
12345: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12346: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12347: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12348: if ($inuse == 0) {
12349: $changes{$prefix}{$type} = 1;
12350: } else {
12351: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12352: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12353: if (@changed > 0) {
12354: $changes{$prefix}{$type} = 1;
12355: }
12356: }
12357: } else {
12358: if ($inuse == 1) {
12359: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12360: $changes{$prefix}{$type} = 1;
12361: }
12362: }
12363: } else {
12364: if ($inuse == 1) {
12365: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12366: $changes{$prefix}{$type} = 1;
12367: }
12368: }
12369: } else {
12370: if ($inuse == 1) {
12371: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12372: $changes{$prefix}{$type} = 1;
12373: }
12374: }
12375: }
12376: }
12377: }
1.145 raeburn 12378:
12379: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12380: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12381: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12382: my $savespares;
12383:
12384: foreach my $lonhost (sort(keys(%servers))) {
12385: my $serverhomeID =
12386: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12387: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12388: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12389: my %spareschg;
12390: foreach my $type (@{$types{'spares'}}) {
12391: my @okspares;
12392: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12393: foreach my $server (@checked) {
1.152 raeburn 12394: if (&Apache::lonnet::hostname($server) ne '') {
12395: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12396: unless (grep(/^\Q$server\E$/,@okspares)) {
12397: push(@okspares,$server);
12398: }
1.145 raeburn 12399: }
12400: }
12401: }
12402: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12403: my $newspare;
1.152 raeburn 12404: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12405: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12406: $newspare = $new;
12407: }
12408: }
1.152 raeburn 12409: my @spares;
12410: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12411: @spares = sort(@okspares,$newspare);
12412: } else {
12413: @spares = sort(@okspares);
12414: }
12415: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12416: if (ref($spareid{$lonhost}) eq 'HASH') {
12417: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12418: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12419: if (@diffs > 0) {
12420: $spareschg{$type} = 1;
12421: }
12422: }
12423: }
12424: }
12425: if (keys(%spareschg) > 0) {
12426: $changes{'spares'}{$lonhost} = \%spareschg;
12427: }
12428: }
1.261 raeburn 12429: $defaultshash{'usersessions'}{'offloadnow'} = {};
12430: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12431: my @okoffload;
12432: if (@offloadnow) {
12433: foreach my $server (@offloadnow) {
12434: if (&Apache::lonnet::hostname($server) ne '') {
12435: unless (grep(/^\Q$server\E$/,@okoffload)) {
12436: push(@okoffload,$server);
12437: }
12438: }
12439: }
12440: if (@okoffload) {
12441: foreach my $lonhost (@okoffload) {
12442: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12443: }
12444: }
12445: }
1.145 raeburn 12446: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12447: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12448: if (ref($changes{'spares'}) eq 'HASH') {
12449: if (keys(%{$changes{'spares'}}) > 0) {
12450: $savespares = 1;
12451: }
12452: }
12453: } else {
12454: $savespares = 1;
12455: }
1.261 raeburn 12456: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12457: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12458: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12459: $changes{'offloadnow'} = 1;
12460: last;
12461: }
12462: }
12463: unless ($changes{'offloadnow'}) {
12464: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12465: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12466: $changes{'offloadnow'} = 1;
12467: last;
12468: }
12469: }
12470: }
12471: } elsif (@okoffload) {
12472: $changes{'offloadnow'} = 1;
12473: }
12474: } elsif (@okoffload) {
12475: $changes{'offloadnow'} = 1;
1.145 raeburn 12476: }
1.147 raeburn 12477: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12478: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12479: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12480: $dom);
12481: if ($putresult eq 'ok') {
12482: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12483: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12484: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12485: }
12486: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12487: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12488: }
1.261 raeburn 12489: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12490: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12491: }
1.137 raeburn 12492: }
12493: my $cachetime = 24*60*60;
12494: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12495: if (ref($lastactref) eq 'HASH') {
12496: $lastactref->{'domdefaults'} = 1;
12497: }
1.147 raeburn 12498: if (keys(%changes) > 0) {
12499: my %lt = &usersession_titles();
12500: $resulttext = &mt('Changes made:').'<ul>';
12501: foreach my $prefix (@prefixes) {
12502: if (ref($changes{$prefix}) eq 'HASH') {
12503: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12504: if ($prefix eq 'spares') {
12505: if (ref($changes{$prefix}) eq 'HASH') {
12506: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12507: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12508: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12509: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12510: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12511: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12512: foreach my $type (@{$types{$prefix}}) {
12513: if ($changes{$prefix}{$lonhost}{$type}) {
12514: my $offloadto = &mt('None');
12515: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12516: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12517: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12518: }
1.145 raeburn 12519: }
1.147 raeburn 12520: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12521: }
1.137 raeburn 12522: }
12523: }
1.147 raeburn 12524: $resulttext .= '</li>';
1.137 raeburn 12525: }
12526: }
1.147 raeburn 12527: } else {
12528: foreach my $type (@{$types{$prefix}}) {
12529: if (defined($changes{$prefix}{$type})) {
12530: my $newvalue;
12531: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12532: if (ref($defaultshash{'usersessions'}{$prefix})) {
12533: if ($type eq 'version') {
12534: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12535: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12536: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12537: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12538: }
1.145 raeburn 12539: }
12540: }
12541: }
1.147 raeburn 12542: if ($newvalue eq '') {
12543: if ($type eq 'version') {
12544: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12545: } else {
12546: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12547: }
1.145 raeburn 12548: } else {
1.147 raeburn 12549: if ($type eq 'version') {
12550: $newvalue .= ' '.&mt('(or later)');
12551: }
12552: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12553: }
1.137 raeburn 12554: }
12555: }
12556: }
1.147 raeburn 12557: $resulttext .= '</ul>';
1.137 raeburn 12558: }
12559: }
1.261 raeburn 12560: if ($changes{'offloadnow'}) {
12561: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12562: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12563: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12564: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12565: $resulttext .= '<li>'.$lonhost.'</li>';
12566: }
12567: $resulttext .= '</ul>';
12568: } else {
12569: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12570: }
12571: } else {
12572: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12573: }
12574: }
1.147 raeburn 12575: $resulttext .= '</ul>';
12576: } else {
12577: $resulttext = $nochgmsg;
1.137 raeburn 12578: }
12579: } else {
12580: $resulttext = '<span class="LC_error">'.
12581: &mt('An error occurred: [_1]',$putresult).'</span>';
12582: }
12583: } else {
1.147 raeburn 12584: $resulttext = $nochgmsg;
1.137 raeburn 12585: }
12586: return $resulttext;
12587: }
12588:
1.275 raeburn 12589: sub modify_ssl {
12590: my ($dom,$lastactref,%domconfig) = @_;
12591: my (%by_ip,%by_location,@intdoms,@instdoms);
12592: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
12593: my @locations = sort(keys(%by_location));
12594: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12595: my (%defaultshash,%changes);
12596: my $action = 'ssl';
12597: my @prefixes = ('connect','replication');
12598: foreach my $prefix (@prefixes) {
12599: $defaultshash{$action}{$prefix} = {};
12600: }
12601: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12602: my $resulttext;
12603: my %iphost = &Apache::lonnet::get_iphost();
12604: my @reptypes = ('certreq','nocertreq');
12605: my @connecttypes = ('dom','intdom','other');
12606: my %types = (
12607: connect => \@connecttypes,
12608: replication => \@reptypes,
12609: );
12610: my $action = 'ssl';
12611: foreach my $prefix (sort(keys(%types))) {
12612: foreach my $type (@{$types{$prefix}}) {
12613: if ($prefix eq 'connect') {
12614: my $value = 'yes';
12615: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
12616: $value = $env{'form.'.$prefix.'_'.$type};
12617: }
12618: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12619: if ($domconfig{$action}{$prefix}{$type} ne '') {
12620: if ($value ne $domconfig{$action}{$prefix}{$type}) {
12621: $changes{$prefix}{$type} = 1;
12622: }
12623: $defaultshash{$action}{$prefix}{$type} = $value;
12624: } else {
12625: $defaultshash{$action}{$prefix}{$type} = $value;
12626: $changes{$prefix}{$type} = 1;
12627: }
12628: } else {
12629: $defaultshash{$action}{$prefix}{$type} = $value;
12630: $changes{$prefix}{$type} = 1;
12631: }
12632: if (($type eq 'dom') && (keys(%servers) == 1)) {
12633: delete($changes{$prefix}{$type});
12634: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
12635: delete($changes{$prefix}{$type});
12636: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
12637: delete($changes{$prefix}{$type});
12638: }
12639: } elsif ($prefix eq 'replication') {
12640: if (@locations > 0) {
12641: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12642: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12643: my @okvals;
12644: foreach my $val (@vals) {
12645: if ($val =~ /:/) {
12646: my @items = split(/:/,$val);
12647: foreach my $item (@items) {
12648: if (ref($by_location{$item}) eq 'ARRAY') {
12649: push(@okvals,$item);
12650: }
12651: }
12652: } else {
12653: if (ref($by_location{$val}) eq 'ARRAY') {
12654: push(@okvals,$val);
12655: }
12656: }
12657: }
12658: @okvals = sort(@okvals);
12659: if (ref($domconfig{$action}) eq 'HASH') {
12660: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
12661: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
12662: if ($inuse == 0) {
12663: $changes{$prefix}{$type} = 1;
12664: } else {
12665: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12666: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
12667: if (@changed > 0) {
12668: $changes{$prefix}{$type} = 1;
12669: }
12670: }
12671: } else {
12672: if ($inuse == 1) {
12673: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12674: $changes{$prefix}{$type} = 1;
12675: }
12676: }
12677: } else {
12678: if ($inuse == 1) {
12679: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12680: $changes{$prefix}{$type} = 1;
12681: }
12682: }
12683: } else {
12684: if ($inuse == 1) {
12685: $defaultshash{$action}{$prefix}{$type} = \@okvals;
12686: $changes{$prefix}{$type} = 1;
12687: }
12688: }
12689: }
12690: }
12691: }
12692: }
12693: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
12694: if (keys(%changes) > 0) {
12695: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12696: $dom);
12697: if ($putresult eq 'ok') {
12698: if (ref($defaultshash{$action}) eq 'HASH') {
12699: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
12700: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
12701: }
12702: if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
12703: $domdefaults{'connect'} = $domconfig{$action}{'connect'};
12704: }
12705: }
12706: my $cachetime = 24*60*60;
12707: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12708: if (ref($lastactref) eq 'HASH') {
12709: $lastactref->{'domdefaults'} = 1;
12710: }
12711: if (keys(%changes) > 0) {
12712: my %titles = &ssl_titles();
12713: $resulttext = &mt('Changes made:').'<ul>';
12714: foreach my $prefix (@prefixes) {
12715: if (ref($changes{$prefix}) eq 'HASH') {
12716: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
12717: foreach my $type (@{$types{$prefix}}) {
12718: if (defined($changes{$prefix}{$type})) {
12719: my $newvalue;
12720: if (ref($defaultshash{$action}) eq 'HASH') {
12721: if (ref($defaultshash{$action}{$prefix})) {
12722: if ($prefix eq 'connect') {
12723: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
12724: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
12725: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
12726: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
12727: }
12728: }
12729: }
12730: if ($newvalue eq '') {
12731: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
12732: } else {
12733: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
12734: }
12735: }
12736: }
12737: }
12738: $resulttext .= '</ul>';
12739: }
12740: }
12741: } else {
12742: $resulttext = $nochgmsg;
12743: }
12744: } else {
12745: $resulttext = '<span class="LC_error">'.
12746: &mt('An error occurred: [_1]',$putresult).'</span>';
12747: }
12748: } else {
12749: $resulttext = $nochgmsg;
12750: }
12751: return $resulttext;
12752: }
12753:
1.150 raeburn 12754: sub modify_loadbalancing {
12755: my ($dom,%domconfig) = @_;
12756: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12757: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12758: my ($othertitle,$usertypes,$types) =
12759: &Apache::loncommon::sorted_inst_types($dom);
12760: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12761: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12762: my @sparestypes = ('primary','default');
12763: my %typetitles = &sparestype_titles();
12764: my $resulttext;
1.171 raeburn 12765: my (%currbalancer,%currtargets,%currrules,%existing);
12766: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12767: %existing = %{$domconfig{'loadbalancing'}};
12768: }
12769: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12770: \%currtargets,\%currrules);
12771: my ($saveloadbalancing,%defaultshash,%changes);
12772: my ($alltypes,$othertypes,$titles) =
12773: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12774: my %ruletitles = &offloadtype_text();
12775: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12776: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12777: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12778: if ($balancer eq '') {
12779: next;
12780: }
1.210 raeburn 12781: if (!exists($servers{$balancer})) {
1.171 raeburn 12782: if (exists($currbalancer{$balancer})) {
12783: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12784: }
1.171 raeburn 12785: next;
12786: }
12787: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12788: push(@{$changes{'delete'}},$balancer);
12789: next;
12790: }
12791: if (!exists($currbalancer{$balancer})) {
12792: push(@{$changes{'add'}},$balancer);
12793: }
12794: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12795: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12796: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12797: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12798: $saveloadbalancing = 1;
12799: }
12800: foreach my $sparetype (@sparestypes) {
12801: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12802: my @offloadto;
12803: foreach my $target (@targets) {
12804: if (($servers{$target}) && ($target ne $balancer)) {
12805: if ($sparetype eq 'default') {
12806: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12807: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12808: }
12809: }
1.171 raeburn 12810: unless(grep(/^\Q$target\E$/,@offloadto)) {
12811: push(@offloadto,$target);
12812: }
1.150 raeburn 12813: }
1.171 raeburn 12814: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12815: }
12816: }
1.171 raeburn 12817: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12818: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12819: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12820: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12821: if (@targetdiffs > 0) {
1.171 raeburn 12822: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12823: }
1.171 raeburn 12824: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12825: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12826: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12827: }
12828: }
12829: }
12830: } else {
1.171 raeburn 12831: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 12832: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12833: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12834: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12835: $changes{'curr'}{$balancer}{'targets'} = 1;
12836: }
1.150 raeburn 12837: }
12838: }
1.210 raeburn 12839: }
1.150 raeburn 12840: }
12841: my $ishomedom;
1.171 raeburn 12842: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12843: $ishomedom = 1;
1.150 raeburn 12844: }
12845: if (ref($alltypes) eq 'ARRAY') {
12846: foreach my $type (@{$alltypes}) {
12847: my $rule;
1.210 raeburn 12848: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12849: (!$ishomedom)) {
1.171 raeburn 12850: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12851: }
12852: if ($rule eq 'specific') {
1.255 raeburn 12853: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12854: if (exists($servers{$specifiedhost})) {
12855: $rule = $specifiedhost;
12856: }
1.150 raeburn 12857: }
1.171 raeburn 12858: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12859: if (ref($currrules{$balancer}) eq 'HASH') {
12860: if ($rule ne $currrules{$balancer}{$type}) {
12861: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12862: }
12863: } elsif ($rule ne '') {
1.171 raeburn 12864: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12865: }
12866: }
12867: }
1.171 raeburn 12868: }
12869: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12870: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12871: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12872: $defaultshash{'loadbalancing'} = {};
12873: }
12874: my $putresult = &Apache::lonnet::put_dom('configuration',
12875: \%defaultshash,$dom);
12876: if ($putresult eq 'ok') {
12877: if (keys(%changes) > 0) {
1.252 raeburn 12878: my %toupdate;
1.171 raeburn 12879: if (ref($changes{'delete'}) eq 'ARRAY') {
12880: foreach my $balancer (sort(@{$changes{'delete'}})) {
12881: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 12882: $toupdate{$balancer} = 1;
1.150 raeburn 12883: }
1.171 raeburn 12884: }
12885: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 12886: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 12887: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 12888: $toupdate{$balancer} = 1;
1.171 raeburn 12889: }
12890: }
12891: if (ref($changes{'curr'}) eq 'HASH') {
12892: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 12893: $toupdate{$balancer} = 1;
1.171 raeburn 12894: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12895: if ($changes{'curr'}{$balancer}{'targets'}) {
12896: my %offloadstr;
12897: foreach my $sparetype (@sparestypes) {
12898: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12899: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12900: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12901: }
12902: }
1.150 raeburn 12903: }
1.171 raeburn 12904: if (keys(%offloadstr) == 0) {
12905: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12906: } else {
1.171 raeburn 12907: my $showoffload;
12908: foreach my $sparetype (@sparestypes) {
12909: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12910: if (defined($offloadstr{$sparetype})) {
12911: $showoffload .= $offloadstr{$sparetype};
12912: } else {
12913: $showoffload .= &mt('None');
12914: }
12915: $showoffload .= (' 'x3);
12916: }
12917: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12918: }
12919: }
12920: }
1.171 raeburn 12921: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12922: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12923: foreach my $type (@{$alltypes}) {
12924: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12925: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12926: my $balancetext;
12927: if ($rule eq '') {
12928: $balancetext = $ruletitles{'default'};
1.209 raeburn 12929: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 12930: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12931: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 12932: foreach my $sparetype (@sparestypes) {
12933: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12934: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12935: }
12936: }
1.253 raeburn 12937: foreach my $item (@{$alltypes}) {
12938: next if ($item =~ /^_LC_ipchange/);
12939: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12940: if ($hasrule eq 'homeserver') {
12941: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12942: } else {
12943: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12944: if ($servers{$hasrule}) {
12945: $toupdate{$hasrule} = 1;
12946: }
12947: }
12948: }
12949: }
1.254 raeburn 12950: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12951: $balancetext = $ruletitles{$rule};
12952: } else {
12953: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12954: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12955: if ($receiver) {
12956: $toupdate{$receiver};
12957: }
12958: }
12959: } else {
12960: $balancetext = $ruletitles{$rule};
1.252 raeburn 12961: }
1.171 raeburn 12962: } else {
12963: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12964: }
1.210 raeburn 12965: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12966: }
12967: }
12968: }
12969: }
1.252 raeburn 12970: if (keys(%toupdate)) {
12971: my %thismachine;
12972: my $updatedhere;
12973: my $cachetime = 60*60*24;
12974: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12975: foreach my $lonhost (keys(%toupdate)) {
12976: if ($thismachine{$lonhost}) {
12977: unless ($updatedhere) {
12978: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12979: $defaultshash{'loadbalancing'},
12980: $cachetime);
12981: $updatedhere = 1;
12982: }
12983: } else {
12984: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12985: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12986: }
12987: }
12988: }
1.150 raeburn 12989: }
1.171 raeburn 12990: }
12991: if ($resulttext ne '') {
12992: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12993: } else {
12994: $resulttext = $nochgmsg;
12995: }
12996: } else {
1.171 raeburn 12997: $resulttext = $nochgmsg;
1.150 raeburn 12998: }
12999: } else {
1.171 raeburn 13000: $resulttext = '<span class="LC_error">'.
13001: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13002: }
13003: } else {
1.171 raeburn 13004: $resulttext = $nochgmsg;
1.150 raeburn 13005: }
13006: return $resulttext;
13007: }
13008:
1.48 raeburn 13009: sub recurse_check {
13010: my ($chkcats,$categories,$depth,$name) = @_;
13011: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13012: my $chg = 0;
13013: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13014: my $category = $chkcats->[$depth]{$name}[$j];
13015: my $item;
13016: if ($category eq '') {
13017: $chg ++;
13018: } else {
13019: my $deeper = $depth + 1;
13020: $item = &escape($category).':'.&escape($name).':'.$depth;
13021: if ($chg) {
13022: $categories->{$item} -= $chg;
13023: }
13024: &recurse_check($chkcats,$categories,$deeper,$category);
13025: $deeper --;
13026: }
13027: }
13028: }
13029: return;
13030: }
13031:
13032: sub recurse_cat_deletes {
13033: my ($item,$coursecategories,$deletions) = @_;
13034: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13035: my $subdepth = $depth + 1;
13036: if (ref($coursecategories) eq 'HASH') {
13037: foreach my $subitem (keys(%{$coursecategories})) {
13038: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13039: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13040: delete($coursecategories->{$subitem});
13041: $deletions->{$subitem} = 1;
13042: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 13043: }
1.48 raeburn 13044: }
13045: }
13046: return;
13047: }
13048:
1.125 raeburn 13049: sub get_active_dcs {
13050: my ($dom) = @_;
1.191 raeburn 13051: my $now = time;
13052: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 13053: my %domcoords;
13054: my $numdcs = 0;
13055: foreach my $server (keys(%dompersonnel)) {
13056: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
13057: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 13058: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 13059: }
13060: }
13061: return %domcoords;
13062: }
13063:
13064: sub active_dc_picker {
1.191 raeburn 13065: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 13066: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 13067: my @domcoord = keys(%domcoords);
13068: if (keys(%currhash)) {
13069: foreach my $dc (keys(%currhash)) {
13070: unless (exists($domcoords{$dc})) {
13071: push(@domcoord,$dc);
13072: }
13073: }
13074: }
13075: @domcoord = sort(@domcoord);
1.210 raeburn 13076: my $numdcs = scalar(@domcoord);
1.191 raeburn 13077: my $rows = 0;
13078: my $table;
1.125 raeburn 13079: if ($numdcs > 1) {
1.191 raeburn 13080: $table = '<table>';
13081: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13082: my $rem = $i%($numinrow);
13083: if ($rem == 0) {
13084: if ($i > 0) {
1.191 raeburn 13085: $table .= '</tr>';
1.125 raeburn 13086: }
1.191 raeburn 13087: $table .= '<tr>';
13088: $rows ++;
1.125 raeburn 13089: }
1.191 raeburn 13090: my $check = '';
13091: if ($inputtype eq 'radio') {
13092: if (keys(%currhash) == 0) {
13093: if (!$i) {
13094: $check = ' checked="checked"';
13095: }
13096: } elsif (exists($currhash{$domcoord[$i]})) {
13097: $check = ' checked="checked"';
13098: }
13099: } else {
13100: if (exists($currhash{$domcoord[$i]})) {
13101: $check = ' checked="checked"';
1.125 raeburn 13102: }
13103: }
1.191 raeburn 13104: if ($i == @domcoord - 1) {
1.125 raeburn 13105: my $colsleft = $numinrow - $rem;
13106: if ($colsleft > 1) {
1.191 raeburn 13107: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13108: } else {
1.191 raeburn 13109: $table .= '<td class="LC_left_item">';
1.125 raeburn 13110: }
13111: } else {
1.191 raeburn 13112: $table .= '<td class="LC_left_item">';
13113: }
13114: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13115: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13116: $table .= '<span class="LC_nobreak"><label>'.
13117: '<input type="'.$inputtype.'" name="'.$name.'"'.
13118: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13119: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 13120: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 13121: }
1.219 raeburn 13122: $table .= '</label></span></td>';
1.191 raeburn 13123: }
13124: $table .= '</tr></table>';
13125: } elsif ($numdcs == 1) {
1.219 raeburn 13126: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13127: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 13128: if ($inputtype eq 'radio') {
1.247 raeburn 13129: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 13130: if ($user ne $dcname.':'.$dcdom) {
13131: $table .= ' ('.$dcname.':'.$dcdom.')';
13132: }
1.191 raeburn 13133: } else {
13134: my $check;
13135: if (exists($currhash{$domcoord[0]})) {
13136: $check = ' checked="checked"';
1.125 raeburn 13137: }
1.247 raeburn 13138: $table = '<span class="LC_nobreak"><label>'.
13139: '<input type="checkbox" name="'.$name.'" '.
13140: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 13141: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 13142: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 13143: }
1.220 raeburn 13144: $table .= '</label></span>';
1.191 raeburn 13145: $rows ++;
1.125 raeburn 13146: }
13147: }
1.191 raeburn 13148: return ($numdcs,$table,$rows);
1.125 raeburn 13149: }
13150:
1.137 raeburn 13151: sub usersession_titles {
13152: return &Apache::lonlocal::texthash(
13153: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13154: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13155: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13156: version => 'LON-CAPA version requirement',
1.138 raeburn 13157: excludedomain => 'Allow all, but exclude specific domains',
13158: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13159: primary => 'Primary (checked first)',
1.154 raeburn 13160: default => 'Default',
1.137 raeburn 13161: );
13162: }
13163:
1.152 raeburn 13164: sub id_for_thisdom {
13165: my (%servers) = @_;
13166: my %altids;
13167: foreach my $server (keys(%servers)) {
13168: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13169: if ($serverhome ne $server) {
13170: $altids{$serverhome} = $server;
13171: }
13172: }
13173: return %altids;
13174: }
13175:
1.150 raeburn 13176: sub count_servers {
13177: my ($currbalancer,%servers) = @_;
13178: my (@spares,$numspares);
13179: foreach my $lonhost (sort(keys(%servers))) {
13180: next if ($currbalancer eq $lonhost);
13181: push(@spares,$lonhost);
13182: }
13183: if ($currbalancer) {
13184: $numspares = scalar(@spares);
13185: } else {
13186: $numspares = scalar(@spares) - 1;
13187: }
13188: return ($numspares,@spares);
13189: }
13190:
13191: sub lonbalance_targets_js {
1.171 raeburn 13192: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13193: my $select = &mt('Select');
13194: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13195: if (ref($servers) eq 'HASH') {
13196: $alltargets = join("','",sort(keys(%{$servers})));
13197: my @homedoms;
13198: foreach my $server (sort(keys(%{$servers}))) {
13199: if (&Apache::lonnet::host_domain($server) eq $dom) {
13200: push(@homedoms,'1');
13201: } else {
13202: push(@homedoms,'0');
13203: }
13204: }
13205: $allishome = join("','",@homedoms);
13206: }
13207: if (ref($types) eq 'ARRAY') {
13208: if (@{$types} > 0) {
13209: @alltypes = @{$types};
13210: }
13211: }
13212: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13213: $allinsttypes = join("','",@alltypes);
1.171 raeburn 13214: my (%currbalancer,%currtargets,%currrules,%existing);
13215: if (ref($settings) eq 'HASH') {
13216: %existing = %{$settings};
13217: }
13218: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13219: \%currtargets,\%currrules);
1.210 raeburn 13220: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13221: return <<"END";
13222:
13223: <script type="text/javascript">
13224: // <![CDATA[
13225:
1.171 raeburn 13226: currBalancers = new Array('$balancers');
13227:
13228: function toggleTargets(balnum) {
13229: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13230: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13231: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13232: var prevbalancer = prevhostitem.value;
13233: var baltotal = document.getElementById('loadbalancing_total').value;
13234: prevhostitem.value = balancer;
13235: if (prevbalancer != '') {
13236: var prevIdx = currBalancers.indexOf(prevbalancer);
13237: if (prevIdx != -1) {
13238: currBalancers.splice(prevIdx,1);
13239: }
13240: }
1.150 raeburn 13241: if (balancer == '') {
1.171 raeburn 13242: hideSpares(balnum);
1.150 raeburn 13243: } else {
1.171 raeburn 13244: var currIdx = currBalancers.indexOf(balancer);
13245: if (currIdx == -1) {
13246: currBalancers.push(balancer);
13247: }
1.150 raeburn 13248: var homedoms = new Array('$allishome');
1.171 raeburn 13249: var ishomedom = homedoms[lonhostitem.selectedIndex];
13250: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13251: }
1.171 raeburn 13252: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13253: return;
13254: }
13255:
1.171 raeburn 13256: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13257: var alltargets = new Array('$alltargets');
13258: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13259: var offloadtypes = new Array('primary','default');
13260:
1.171 raeburn 13261: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13262: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13263:
1.151 raeburn 13264: for (var i=0; i<offloadtypes.length; i++) {
13265: var count = 0;
13266: for (var j=0; j<alltargets.length; j++) {
13267: if (alltargets[j] != balancer) {
1.171 raeburn 13268: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13269: item.value = alltargets[j];
13270: item.style.textAlign='left';
13271: item.style.textFace='normal';
13272: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13273: if (currBalancers.indexOf(alltargets[j]) == -1) {
13274: item.disabled = '';
13275: } else {
13276: item.disabled = 'disabled';
13277: item.checked = false;
13278: }
1.151 raeburn 13279: count ++;
13280: }
1.150 raeburn 13281: }
13282: }
1.151 raeburn 13283: for (var k=0; k<insttypes.length; k++) {
13284: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13285: if (ishomedom == 1) {
1.171 raeburn 13286: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13287: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13288: } else {
1.171 raeburn 13289: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13290: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13291: }
13292: } else {
1.171 raeburn 13293: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13294: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13295: }
1.151 raeburn 13296: if ((insttypes[k] != '_LC_external') &&
13297: ((insttypes[k] != '_LC_internetdom') ||
13298: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 13299: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13300: item.options.length = 0;
13301: item.options[0] = new Option("","",true,true);
1.210 raeburn 13302: var idx = 0;
1.151 raeburn 13303: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 13304: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13305: idx ++;
13306: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13307: }
13308: }
13309: }
13310: }
13311: return;
13312: }
13313:
1.171 raeburn 13314: function hideSpares(balnum) {
1.150 raeburn 13315: var alltargets = new Array('$alltargets');
13316: var insttypes = new Array('$allinsttypes');
13317: var offloadtypes = new Array('primary','default');
13318:
1.171 raeburn 13319: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13320: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13321:
13322: var total = alltargets.length - 1;
13323: for (var i=0; i<offloadtypes; i++) {
13324: for (var j=0; j<total; j++) {
1.171 raeburn 13325: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13326: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13327: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13328: }
1.150 raeburn 13329: }
13330: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 13331: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13332: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13333: if (insttypes[k] != '_LC_external') {
1.171 raeburn 13334: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13335: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13336: }
13337: }
13338: return;
13339: }
13340:
1.171 raeburn 13341: function checkOffloads(item,balnum,type) {
1.150 raeburn 13342: var alltargets = new Array('$alltargets');
13343: var offloadtypes = new Array('primary','default');
13344: if (item.checked) {
13345: var total = alltargets.length - 1;
13346: var other;
13347: if (type == offloadtypes[0]) {
1.151 raeburn 13348: other = offloadtypes[1];
1.150 raeburn 13349: } else {
1.151 raeburn 13350: other = offloadtypes[0];
1.150 raeburn 13351: }
13352: for (var i=0; i<total; i++) {
1.171 raeburn 13353: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13354: if (server == item.value) {
1.171 raeburn 13355: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13356: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13357: }
13358: }
13359: }
13360: }
13361: return;
13362: }
13363:
1.171 raeburn 13364: function singleServerToggle(balnum,type) {
13365: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13366: if (offloadtoSelIdx == 0) {
1.171 raeburn 13367: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13368: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13369:
13370: } else {
1.171 raeburn 13371: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13372: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13373: }
13374: return;
13375: }
13376:
1.171 raeburn 13377: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13378: if (type == '_LC_external') {
1.171 raeburn 13379: return;
1.150 raeburn 13380: }
1.171 raeburn 13381: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13382: for (var i=0; i<typesRules.length; i++) {
13383: if (formname.elements[typesRules[i]].checked) {
13384: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 13385: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13386: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13387: } else {
1.171 raeburn 13388: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13389: }
13390: }
13391: }
13392: return;
13393: }
13394:
13395: function balancerDeleteChange(balnum) {
13396: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13397: var baltotal = document.getElementById('loadbalancing_total').value;
13398: var addtarget;
13399: var removetarget;
13400: var action = 'delete';
13401: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13402: var lonhost = hostitem.value;
13403: var currIdx = currBalancers.indexOf(lonhost);
13404: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13405: if (currIdx != -1) {
13406: currBalancers.splice(currIdx,1);
13407: }
13408: addtarget = lonhost;
13409: } else {
13410: if (currIdx == -1) {
13411: currBalancers.push(lonhost);
13412: }
13413: removetarget = lonhost;
13414: action = 'undelete';
13415: }
13416: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13417: }
13418: return;
13419: }
13420:
13421: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13422: if (baltotal > 1) {
13423: var offloadtypes = new Array('primary','default');
13424: var alltargets = new Array('$alltargets');
13425: var insttypes = new Array('$allinsttypes');
13426: for (var i=0; i<baltotal; i++) {
13427: if (i != balnum) {
13428: for (var j=0; j<offloadtypes.length; j++) {
13429: var total = alltargets.length - 1;
13430: for (var k=0; k<total; k++) {
13431: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13432: var server = serveritem.value;
13433: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13434: if (server == addtarget) {
13435: serveritem.disabled = '';
13436: }
13437: }
13438: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13439: if (server == removetarget) {
13440: serveritem.disabled = 'disabled';
13441: serveritem.checked = false;
13442: }
13443: }
13444: }
13445: }
13446: for (var j=0; j<insttypes.length; j++) {
13447: if (insttypes[j] != '_LC_external') {
13448: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13449: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13450: var currSel = singleserver.selectedIndex;
13451: var currVal = singleserver.options[currSel].value;
13452: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13453: var numoptions = singleserver.options.length;
13454: var needsnew = 1;
13455: for (var k=0; k<numoptions; k++) {
13456: if (singleserver.options[k] == addtarget) {
13457: needsnew = 0;
13458: break;
13459: }
13460: }
13461: if (needsnew == 1) {
13462: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13463: }
13464: }
13465: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13466: singleserver.options.length = 0;
13467: if ((currVal) && (currVal != removetarget)) {
13468: singleserver.options[0] = new Option("","",false,false);
13469: } else {
13470: singleserver.options[0] = new Option("","",true,true);
13471: }
13472: var idx = 0;
13473: for (var m=0; m<alltargets.length; m++) {
13474: if (currBalancers.indexOf(alltargets[m]) == -1) {
13475: idx ++;
13476: if (currVal == alltargets[m]) {
13477: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13478: } else {
13479: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13480: }
13481: }
13482: }
13483: }
13484: }
13485: }
13486: }
1.150 raeburn 13487: }
13488: }
13489: }
13490: return;
13491: }
13492:
1.152 raeburn 13493: // ]]>
13494: </script>
13495:
13496: END
13497: }
13498:
13499: sub new_spares_js {
13500: my @sparestypes = ('primary','default');
13501: my $types = join("','",@sparestypes);
13502: my $select = &mt('Select');
13503: return <<"END";
13504:
13505: <script type="text/javascript">
13506: // <![CDATA[
13507:
13508: function updateNewSpares(formname,lonhost) {
13509: var types = new Array('$types');
13510: var include = new Array();
13511: var exclude = new Array();
13512: for (var i=0; i<types.length; i++) {
13513: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13514: for (var j=0; j<spareboxes.length; j++) {
13515: if (formname.elements[spareboxes[j]].checked) {
13516: exclude.push(formname.elements[spareboxes[j]].value);
13517: } else {
13518: include.push(formname.elements[spareboxes[j]].value);
13519: }
13520: }
13521: }
13522: for (var i=0; i<types.length; i++) {
13523: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13524: var selIdx = newSpare.selectedIndex;
13525: var currnew = newSpare.options[selIdx].value;
13526: var okSpares = new Array();
13527: for (var j=0; j<newSpare.options.length; j++) {
13528: var possible = newSpare.options[j].value;
13529: if (possible != '') {
13530: if (exclude.indexOf(possible) == -1) {
13531: okSpares.push(possible);
13532: } else {
13533: if (currnew == possible) {
13534: selIdx = 0;
13535: }
13536: }
13537: }
13538: }
13539: for (var k=0; k<include.length; k++) {
13540: if (okSpares.indexOf(include[k]) == -1) {
13541: okSpares.push(include[k]);
13542: }
13543: }
13544: okSpares.sort();
13545: newSpare.options.length = 0;
13546: if (selIdx == 0) {
13547: newSpare.options[0] = new Option("$select","",true,true);
13548: } else {
13549: newSpare.options[0] = new Option("$select","",false,false);
13550: }
13551: for (var m=0; m<okSpares.length; m++) {
13552: var idx = m+1;
13553: var selThis = 0;
13554: if (selIdx != 0) {
13555: if (okSpares[m] == currnew) {
13556: selThis = 1;
13557: }
13558: }
13559: if (selThis == 1) {
13560: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13561: } else {
13562: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13563: }
13564: }
13565: }
13566: return;
13567: }
13568:
13569: function checkNewSpares(lonhost,type) {
13570: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13571: var chosen = newSpare.options[newSpare.selectedIndex].value;
13572: if (chosen != '') {
13573: var othertype;
13574: var othernewSpare;
13575: if (type == 'primary') {
13576: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13577: }
13578: if (type == 'default') {
13579: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13580: }
13581: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13582: othernewSpare.selectedIndex = 0;
13583: }
13584: }
13585: return;
13586: }
13587:
13588: // ]]>
13589: </script>
13590:
13591: END
13592:
13593: }
13594:
13595: sub common_domprefs_js {
13596: return <<"END";
13597:
13598: <script type="text/javascript">
13599: // <![CDATA[
13600:
1.150 raeburn 13601: function getIndicesByName(formname,item) {
1.152 raeburn 13602: var group = new Array();
1.150 raeburn 13603: for (var i=0;i<formname.elements.length;i++) {
13604: if (formname.elements[i].name == item) {
1.152 raeburn 13605: group.push(formname.elements[i].id);
1.150 raeburn 13606: }
13607: }
1.152 raeburn 13608: return group;
1.150 raeburn 13609: }
13610:
13611: // ]]>
13612: </script>
13613:
13614: END
1.152 raeburn 13615:
1.150 raeburn 13616: }
13617:
1.165 raeburn 13618: sub recaptcha_js {
13619: my %lt = &captcha_phrases();
13620: return <<"END";
13621:
13622: <script type="text/javascript">
13623: // <![CDATA[
13624:
13625: function updateCaptcha(caller,context) {
13626: var privitem;
13627: var pubitem;
13628: var privtext;
13629: var pubtext;
1.269 raeburn 13630: var versionitem;
13631: var versiontext;
1.165 raeburn 13632: if (document.getElementById(context+'_recaptchapub')) {
13633: pubitem = document.getElementById(context+'_recaptchapub');
13634: } else {
13635: return;
13636: }
13637: if (document.getElementById(context+'_recaptchapriv')) {
13638: privitem = document.getElementById(context+'_recaptchapriv');
13639: } else {
13640: return;
13641: }
13642: if (document.getElementById(context+'_recaptchapubtxt')) {
13643: pubtext = document.getElementById(context+'_recaptchapubtxt');
13644: } else {
13645: return;
13646: }
13647: if (document.getElementById(context+'_recaptchaprivtxt')) {
13648: privtext = document.getElementById(context+'_recaptchaprivtxt');
13649: } else {
13650: return;
13651: }
1.269 raeburn 13652: if (document.getElementById(context+'_recaptchaversion')) {
13653: versionitem = document.getElementById(context+'_recaptchaversion');
13654: } else {
13655: return;
13656: }
13657: if (document.getElementById(context+'_recaptchavertxt')) {
13658: versiontext = document.getElementById(context+'_recaptchavertxt');
13659: } else {
13660: return;
13661: }
1.165 raeburn 13662: if (caller.checked) {
13663: if (caller.value == 'recaptcha') {
13664: pubitem.type = 'text';
13665: privitem.type = 'text';
13666: pubitem.size = '40';
13667: privitem.size = '40';
13668: pubtext.innerHTML = "$lt{'pub'}";
13669: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13670: versionitem.type = 'text';
13671: versionitem.size = '3';
13672: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13673: } else {
13674: pubitem.type = 'hidden';
13675: privitem.type = 'hidden';
1.269 raeburn 13676: versionitem.type = 'hidden';
1.165 raeburn 13677: pubtext.innerHTML = '';
13678: privtext.innerHTML = '';
1.269 raeburn 13679: versiontext.innerHTML = '';
1.165 raeburn 13680: }
13681: }
13682: return;
13683: }
13684:
13685: // ]]>
13686: </script>
13687:
13688: END
13689:
13690: }
13691:
1.236 raeburn 13692: sub toggle_display_js {
1.192 raeburn 13693: return <<"END";
13694:
13695: <script type="text/javascript">
13696: // <![CDATA[
13697:
1.236 raeburn 13698: function toggleDisplay(domForm,caller) {
13699: if (document.getElementById(caller)) {
13700: var divitem = document.getElementById(caller);
13701: var optionsElement = domForm.coursecredits;
1.264 raeburn 13702: var checkval = 1;
13703: var dispval = 'block';
1.236 raeburn 13704: if (caller == 'emailoptions') {
13705: optionsElement = domForm.cancreate_email;
13706: }
1.257 raeburn 13707: if (caller == 'studentsubmission') {
13708: optionsElement = domForm.postsubmit;
13709: }
1.264 raeburn 13710: if (caller == 'cloneinstcode') {
13711: optionsElement = domForm.canclone;
13712: checkval = 'instcode';
13713: }
1.236 raeburn 13714: if (optionsElement.length) {
1.192 raeburn 13715: var currval;
1.236 raeburn 13716: for (var i=0; i<optionsElement.length; i++) {
13717: if (optionsElement[i].checked) {
13718: currval = optionsElement[i].value;
1.192 raeburn 13719: }
13720: }
1.264 raeburn 13721: if (currval == checkval) {
13722: divitem.style.display = dispval;
1.192 raeburn 13723: } else {
1.236 raeburn 13724: divitem.style.display = 'none';
1.192 raeburn 13725: }
13726: }
13727: }
13728: return;
13729: }
13730:
13731: // ]]>
13732: </script>
13733:
13734: END
13735:
13736: }
13737:
1.165 raeburn 13738: sub captcha_phrases {
13739: return &Apache::lonlocal::texthash (
13740: priv => 'Private key',
13741: pub => 'Public key',
13742: original => 'original (CAPTCHA)',
13743: recaptcha => 'successor (ReCAPTCHA)',
13744: notused => 'unused',
1.269 raeburn 13745: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13746: );
13747: }
13748:
1.205 raeburn 13749: sub devalidate_remote_domconfs {
1.212 raeburn 13750: my ($dom,$cachekeys) = @_;
13751: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13752: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13753: my %thismachine;
13754: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13755: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13756: if (keys(%servers)) {
1.205 raeburn 13757: foreach my $server (keys(%servers)) {
13758: next if ($thismachine{$server});
1.212 raeburn 13759: my @cached;
13760: foreach my $name (@posscached) {
13761: if ($cachekeys->{$name}) {
13762: push(@cached,&escape($name).':'.&escape($dom));
13763: }
13764: }
13765: if (@cached) {
13766: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13767: }
1.205 raeburn 13768: }
13769: }
13770: return;
13771: }
13772:
1.3 raeburn 13773: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>