Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.73
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.73! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.72 2016/09/18 19:24:14 raeburn Exp $
1.160.6.40 raeburn 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.160.6.13 raeburn 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.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 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.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 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.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.73! raeburn 216: 'serverstatuses','requestcourses','helpsettings',
! 217: 'coursedefaults','usersessions','loadbalancing',
! 218: 'requestauthor','selfenrollment','inststatus'],$dom);
1.160.6.40 raeburn 219: 'selfenrollment','inststatus'],$dom);
1.43 raeburn 220: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73! raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
! 225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
265: {col1 => 'Institutional user types',
266: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 267: print => \&print_defaults,
268: modify => \&modify_defaults,
1.43 raeburn 269: },
1.30 raeburn 270: 'quotas' =>
1.160.6.20 raeburn 271: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 272: help => 'Domain_Configuration_Quotas',
1.77 raeburn 273: header => [{col1 => 'User affiliation',
1.72 raeburn 274: col2 => 'Available tools',
1.160.6.28 raeburn 275: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 276: print => \&print_quotas,
277: modify => \&modify_quotas,
1.30 raeburn 278: },
279: 'autoenroll' =>
280: { text => 'Auto-enrollment settings',
1.67 raeburn 281: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 282: header => [{col1 => 'Configuration setting',
283: col2 => 'Value(s)'}],
1.160.6.37 raeburn 284: print => \&print_autoenroll,
285: modify => \&modify_autoenroll,
1.30 raeburn 286: },
287: 'autoupdate' =>
288: { text => 'Auto-update settings',
1.67 raeburn 289: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 290: header => [{col1 => 'Setting',
291: col2 => 'Value',},
1.131 raeburn 292: {col1 => 'Setting',
293: col2 => 'Affiliation'},
1.43 raeburn 294: {col1 => 'User population',
1.160.6.35 raeburn 295: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 296: print => \&print_autoupdate,
297: modify => \&modify_autoupdate,
1.30 raeburn 298: },
1.125 raeburn 299: 'autocreate' =>
300: { text => 'Auto-course creation settings',
301: help => 'Domain_Configuration_Auto_Creation',
302: header => [{col1 => 'Configuration Setting',
303: col2 => 'Value',}],
1.160.6.37 raeburn 304: print => \&print_autocreate,
305: modify => \&modify_autocreate,
1.125 raeburn 306: },
1.30 raeburn 307: 'directorysrch' =>
1.160.6.72 raeburn 308: { text => 'Directory searches',
1.67 raeburn 309: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 310: header => [{col1 => 'Institutional Directory Setting',
311: col2 => 'Value',},
312: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 313: col2 => 'Value',}],
1.160.6.37 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.160.6.37 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.160.6.37 raeburn 334: print => \&print_usercreation,
335: modify => \&modify_usercreation,
1.30 raeburn 336: },
1.160.6.34 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.160.6.37 raeburn 346: print => \&print_selfcreation,
347: modify => \&modify_selfcreation,
1.160.6.34 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.160.6.35 raeburn 353: col2 => 'User information updatable in author context'},
1.33 raeburn 354: {col1 => 'Target user has role',
1.160.6.35 raeburn 355: col2 => 'User information updatable in course context'}],
1.160.6.37 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.160.6.37 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.160.6.30 raeburn 374: col2 => 'Value'},
375: {col1 => 'Available textbooks',
1.160.6.39 raeburn 376: col2 => ''},
1.160.6.46 raeburn 377: {col1 => 'Available templates',
378: col2 => ''},
1.160.6.39 raeburn 379: {col1 => 'Validation (not official courses)',
380: col2 => 'Value'},],
1.160.6.37 raeburn 381: print => \&print_quotas,
382: modify => \&modify_quotas,
1.86 raeburn 383: },
1.160.6.5 raeburn 384: 'requestauthor' =>
1.160.6.34 raeburn 385: {text => 'Request Authoring Space',
1.160.6.5 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.160.6.37 raeburn 391: print => \&print_quotas,
392: modify => \&modify_quotas,
1.160.6.5 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.160.6.42 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.160.6.37 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.160.6.37 raeburn 414: print => \&print_serverstatuses,
415: modify => \&modify_serverstatuses,
1.69 raeburn 416: },
1.160.6.73! raeburn 417: 'helpsettings' =>
! 418: {text => 'Support settings',
! 419: help => 'Domain_Configuration_Help_Settings',
! 420: header => [{col1 => 'Help Page Settings (logged-in users)',
! 421: col2 => 'Value'},
! 422: {col1 => 'Helpdesk Roles',
! 423: col2 => 'Settings'},],
! 424: print => \&print_helpsettings,
! 425: modify => \&modify_helpsettings,
! 426: },
1.160.6.39 raeburn 427: 'coursedefaults' =>
1.160.6.16 raeburn 428: {text => 'Course/Community defaults',
429: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 430: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
431: col2 => 'Value',},
432: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 433: col2 => 'Value',},],
1.160.6.37 raeburn 434: print => \&print_coursedefaults,
435: modify => \&modify_coursedefaults,
436: },
1.160.6.39 raeburn 437: 'selfenrollment' =>
1.160.6.37 raeburn 438: {text => 'Self-enrollment in Course/Community',
439: help => 'Domain_Configuration_Selfenrollment',
440: header => [{col1 => 'Configuration Rights',
441: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
442: {col1 => 'Defaults',
443: col2 => 'Value'},
444: {col1 => 'Self-enrollment validation (optional)',
445: col2 => 'Value'},],
446: print => \&print_selfenrollment,
447: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 448: },
1.141 raeburn 449: 'usersessions' =>
1.145 raeburn 450: {text => 'User session hosting/offloading',
1.137 raeburn 451: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 452: header => [{col1 => 'Domain server',
453: col2 => 'Servers to offload sessions to when busy'},
454: {col1 => 'Hosting of users from other domains',
1.137 raeburn 455: col2 => 'Rules'},
456: {col1 => "Hosting domain's own users elsewhere",
457: col2 => 'Rules'}],
1.160.6.37 raeburn 458: print => \&print_usersessions,
459: modify => \&modify_usersessions,
1.137 raeburn 460: },
1.150 raeburn 461: 'loadbalancing' =>
1.160.6.7 raeburn 462: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 463: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 464: header => [{col1 => 'Balancers',
1.150 raeburn 465: col2 => 'Default destinations',
1.160.6.13 raeburn 466: col3 => 'User affiliation',
1.150 raeburn 467: col4 => 'Overrides'},
468: ],
1.160.6.37 raeburn 469: print => \&print_loadbalancing,
470: modify => \&modify_loadbalancing,
1.150 raeburn 471: },
1.3 raeburn 472: );
1.110 raeburn 473: if (keys(%servers) > 1) {
474: $prefs{'login'} = { text => 'Log-in page options',
475: help => 'Domain_Configuration_Login_Page',
476: header => [{col1 => 'Log-in Service',
477: col2 => 'Server Setting',},
478: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 479: col2 => ''},
480: {col1 => 'Log-in Help',
1.160.6.56 raeburn 481: col2 => 'Value'},
482: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 483: col2 => 'Value'}],
1.160.6.37 raeburn 484: print => \&print_login,
485: modify => \&modify_login,
1.110 raeburn 486: };
487: }
1.160.6.13 raeburn 488:
1.6 raeburn 489: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 490: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 491: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 492: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 493: text=>"Settings to display/modify"});
1.9 raeburn 494: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 495:
1.3 raeburn 496: if ($phase eq 'process') {
1.160.6.27 raeburn 497: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
498: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 499: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 500: $r->rflush();
1.160.6.27 raeburn 501: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 502: }
1.30 raeburn 503: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 504: my $js = &recaptcha_js().
1.160.6.40 raeburn 505: &toggle_display_js();
1.160.6.7 raeburn 506: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 507: my ($othertitle,$usertypes,$types) =
508: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 509: $js .= &lonbalance_targets_js($dom,$types,\%servers,
510: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 511: &new_spares_js().
512: &common_domprefs_js().
513: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 514: }
1.160.6.30 raeburn 515: if (grep(/^requestcourses$/,@actions)) {
516: my $javascript_validations;
517: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
518: $js .= <<END;
519: <script type="text/javascript">
520: $javascript_validations
521: </script>
522: $coursebrowserjs
523: END
524: }
1.150 raeburn 525: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 526: } else {
1.160.6.11 raeburn 527: # check if domconfig user exists for the domain.
528: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 529: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 530: &config_check($dom,$confname,$servadm);
531: unless ($configuserok eq 'ok') {
532: &Apache::lonconfigsettings::print_header($r,$phase,$context);
533: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
534: $confname).
535: '<br />'
536: );
537: if ($switchserver) {
538: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
539: '<br />'.
540: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
541: '<br />'.
542: &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).
543: '<br />'.
544: &mt('To do that now, use the following link: [_1]',$switchserver)
545: );
546: } else {
547: $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.').
548: '<br />'.
549: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
550: );
551: }
552: $r->print(&Apache::loncommon::end_page());
553: return OK;
554: }
1.21 raeburn 555: if (keys(%domconfig) == 0) {
556: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 557: my @ids=&Apache::lonnet::current_machine_ids();
558: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 559: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 560: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 561: my $custom_img_count = 0;
562: foreach my $img (@loginimages) {
563: if ($designhash{$dom.'.login.'.$img} ne '') {
564: $custom_img_count ++;
565: }
566: }
567: foreach my $role (@roles) {
568: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
569: $custom_img_count ++;
570: }
571: }
572: if ($custom_img_count > 0) {
1.94 raeburn 573: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 574: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 575: $r->print(
576: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
577: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
578: &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 />'.
579: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
580: if ($switch_server) {
1.30 raeburn 581: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 582: }
1.91 raeburn 583: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 584: return OK;
585: }
586: }
587: }
1.91 raeburn 588: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 589: }
590: return OK;
591: }
592:
593: sub process_changes {
1.160.6.24 raeburn 594: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 595: my %domconfig;
596: if (ref($values) eq 'HASH') {
597: %domconfig = %{$values};
598: }
1.3 raeburn 599: my $output;
600: if ($action eq 'login') {
1.160.6.24 raeburn 601: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 602: } elsif ($action eq 'rolecolors') {
1.9 raeburn 603: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 604: $lastactref,%domconfig);
1.3 raeburn 605: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 606: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 607: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 608: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 609: } elsif ($action eq 'autoupdate') {
610: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 611: } elsif ($action eq 'autocreate') {
612: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 613: } elsif ($action eq 'directorysrch') {
614: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 615: } elsif ($action eq 'usercreation') {
1.28 raeburn 616: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 617: } elsif ($action eq 'selfcreation') {
618: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 619: } elsif ($action eq 'usermodification') {
620: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 621: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 622: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 623: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 624: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 625: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 626: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 627: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 628: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 629: } elsif ($action eq 'serverstatuses') {
630: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 631: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 632: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 633: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 634: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73! raeburn 635: } elsif ($action eq 'helpsettings') {
! 636: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.160.6.16 raeburn 637: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 638: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 639: } elsif ($action eq 'selfenrollment') {
640: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 641: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 642: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 643: } elsif ($action eq 'loadbalancing') {
644: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 645: }
646: return $output;
647: }
648:
649: sub print_config_box {
1.9 raeburn 650: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 651: my $rowtotal = 0;
1.49 raeburn 652: my $output;
653: if ($action eq 'coursecategories') {
654: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 655: } elsif ($action eq 'defaults') {
656: $output = &defaults_javascript($settings);
1.160.6.73! raeburn 657: } elsif ($action eq 'helpsettings') {
! 658: my (%privs,%levelscurrent);
! 659: my %full=();
! 660: my %levels=(
! 661: course => {},
! 662: domain => {},
! 663: system => {},
! 664: );
! 665: my $context = 'domain';
! 666: my $crstype = 'Course';
! 667: my $formname = 'display';
! 668: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
! 669: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
! 670: $output =
! 671: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
! 672: \@templateroles);
1.91 raeburn 673: }
1.160.6.40 raeburn 674: $output .=
1.30 raeburn 675: '<table class="LC_nested_outer">
1.3 raeburn 676: <tr>
1.66 raeburn 677: <th align="left" valign="middle"><span class="LC_nobreak">'.
678: &mt($item->{text}).' '.
679: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
680: '</tr>';
1.30 raeburn 681: $rowtotal ++;
1.110 raeburn 682: my $numheaders = 1;
683: if (ref($item->{'header'}) eq 'ARRAY') {
684: $numheaders = scalar(@{$item->{'header'}});
685: }
686: if ($numheaders > 1) {
1.64 raeburn 687: my $colspan = '';
1.145 raeburn 688: my $rightcolspan = '';
1.160.6.42 raeburn 689: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 690: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 691: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 692: $colspan = ' colspan="2"';
693: }
1.145 raeburn 694: if ($action eq 'usersessions') {
695: $rightcolspan = ' colspan="3"';
696: }
1.30 raeburn 697: $output .= '
1.3 raeburn 698: <tr>
699: <td>
700: <table class="LC_nested">
701: <tr class="LC_info_row">
1.59 bisitz 702: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 703: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 704: </tr>';
1.69 raeburn 705: $rowtotal ++;
1.160.6.37 raeburn 706: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 707: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73! raeburn 708: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
! 709: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 710: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 711: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 712: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 713: } elsif ($action eq 'login') {
1.160.6.56 raeburn 714: if ($numheaders == 4) {
1.160.6.5 raeburn 715: $colspan = ' colspan="2"';
716: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
717: } else {
718: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
719: }
1.160.6.37 raeburn 720: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 721: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 722: } elsif ($action eq 'rolecolors') {
1.30 raeburn 723: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 724: }
1.30 raeburn 725: $output .= '
1.6 raeburn 726: </table>
727: </td>
728: </tr>
729: <tr>
730: <td>
731: <table class="LC_nested">
732: <tr class="LC_info_row">
1.160.6.37 raeburn 733: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 734: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 735: </tr>';
736: $rowtotal ++;
1.160.6.37 raeburn 737: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
738: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 739: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
740: if ($action eq 'coursecategories') {
741: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
742: $colspan = ' colspan="2"';
743: } else {
744: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
745: }
746: $output .= '
1.63 raeburn 747: </table>
748: </td>
749: </tr>
750: <tr>
751: <td>
752: <table class="LC_nested">
753: <tr class="LC_info_row">
754: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 755: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 756: </tr>'."\n";
757: if ($action eq 'coursecategories') {
758: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
759: } else {
760: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
761: }
1.63 raeburn 762: $rowtotal ++;
1.160.6.57 raeburn 763: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73! raeburn 764: ($action eq 'defaults') || ($action eq 'directorysrch') ||
! 765: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 766: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 767: } elsif ($action eq 'login') {
1.160.6.56 raeburn 768: if ($numheaders == 4) {
1.160.6.5 raeburn 769: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
770: </table>
771: </td>
772: </tr>
773: <tr>
774: <td>
775: <table class="LC_nested">
776: <tr class="LC_info_row">
777: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 778: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 779: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
780: $rowtotal ++;
781: } else {
782: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
783: }
1.160.6.56 raeburn 784: $output .= '
785: </table>
786: </td>
787: </tr>
788: <tr>
789: <td>
790: <table class="LC_nested">
791: <tr class="LC_info_row">';
792: if ($numheaders == 4) {
793: $output .= '
794: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
795: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
796: </tr>';
797: } else {
798: $output .= '
799: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
800: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
801: </tr>';
802: }
803: $rowtotal ++;
804: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 805: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 806: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
807: $rowtotal ++;
808: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 809: </table>
810: </td>
811: </tr>
812: <tr>
813: <td>
814: <table class="LC_nested">
815: <tr class="LC_info_row">
816: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
817: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 818: &textbookcourses_javascript($settings).
819: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
820: </table>
821: </td>
822: </tr>
823: <tr>
824: <td>
825: <table class="LC_nested">
826: <tr class="LC_info_row">
827: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
828: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
829: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 830: </table>
831: </td>
832: </tr>
833: <tr>
834: <td>
835: <table class="LC_nested">
836: <tr class="LC_info_row">
1.160.6.46 raeburn 837: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
838: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 839: </tr>'.
840: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 841: } elsif ($action eq 'requestauthor') {
842: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 843: $rowtotal ++;
1.122 jms 844: } elsif ($action eq 'rolecolors') {
1.30 raeburn 845: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 846: </table>
847: </td>
848: </tr>
849: <tr>
850: <td>
851: <table class="LC_nested">
852: <tr class="LC_info_row">
1.69 raeburn 853: <td class="LC_left_item"'.$colspan.' valign="top">'.
854: &mt($item->{'header'}->[2]->{'col1'}).'</td>
855: <td class="LC_right_item" valign="top">'.
856: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 857: </tr>'.
1.30 raeburn 858: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 859: </table>
860: </td>
861: </tr>
862: <tr>
863: <td>
864: <table class="LC_nested">
865: <tr class="LC_info_row">
1.59 bisitz 866: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
867: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 868: </tr>'.
1.30 raeburn 869: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
870: $rowtotal += 2;
1.6 raeburn 871: }
1.3 raeburn 872: } else {
1.30 raeburn 873: $output .= '
1.3 raeburn 874: <tr>
875: <td>
876: <table class="LC_nested">
1.30 raeburn 877: <tr class="LC_info_row">';
1.160.6.72 raeburn 878: if ($action eq 'login') {
1.30 raeburn 879: $output .= '
1.59 bisitz 880: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 881: } elsif ($action eq 'serverstatuses') {
882: $output .= '
883: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
884: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
885:
1.6 raeburn 886: } else {
1.30 raeburn 887: $output .= '
1.69 raeburn 888: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
889: }
1.72 raeburn 890: if (defined($item->{'header'}->[0]->{'col3'})) {
891: $output .= '<td class="LC_left_item" valign="top">'.
892: &mt($item->{'header'}->[0]->{'col2'});
893: if ($action eq 'serverstatuses') {
894: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
895: }
1.69 raeburn 896: } else {
897: $output .= '<td class="LC_right_item" valign="top">'.
898: &mt($item->{'header'}->[0]->{'col2'});
899: }
900: $output .= '</td>';
901: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 902: if (defined($item->{'header'}->[0]->{'col4'})) {
903: $output .= '<td class="LC_left_item" valign="top">'.
904: &mt($item->{'header'}->[0]->{'col3'});
905: } else {
906: $output .= '<td class="LC_right_item" valign="top">'.
907: &mt($item->{'header'}->[0]->{'col3'});
908: }
1.69 raeburn 909: if ($action eq 'serverstatuses') {
910: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
911: }
912: $output .= '</td>';
1.6 raeburn 913: }
1.150 raeburn 914: if ($item->{'header'}->[0]->{'col4'}) {
915: $output .= '<td class="LC_right_item" valign="top">'.
916: &mt($item->{'header'}->[0]->{'col4'});
917: }
1.69 raeburn 918: $output .= '</tr>';
1.48 raeburn 919: $rowtotal ++;
1.160.6.5 raeburn 920: if ($action eq 'quotas') {
1.86 raeburn 921: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 922: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
923: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
924: ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 925: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 926: } elsif ($action eq 'scantron') {
927: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 928: }
1.3 raeburn 929: }
1.30 raeburn 930: $output .= '
1.3 raeburn 931: </table>
932: </td>
933: </tr>
1.30 raeburn 934: </table><br />';
935: return ($output,$rowtotal);
1.1 raeburn 936: }
937:
1.3 raeburn 938: sub print_login {
1.160.6.5 raeburn 939: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 940: my ($css_class,$datatable);
1.6 raeburn 941: my %choices = &login_choices();
1.110 raeburn 942:
1.160.6.5 raeburn 943: if ($caller eq 'service') {
1.149 raeburn 944: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 945: my $choice = $choices{'disallowlogin'};
946: $css_class = ' class="LC_odd_row"';
1.128 raeburn 947: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 948: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 949: '<th>'.$choices{'server'}.'</th>'.
950: '<th>'.$choices{'serverpath'}.'</th>'.
951: '<th>'.$choices{'custompath'}.'</th>'.
952: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 953: my %disallowed;
954: if (ref($settings) eq 'HASH') {
955: if (ref($settings->{'loginvia'}) eq 'HASH') {
956: %disallowed = %{$settings->{'loginvia'}};
957: }
958: }
959: foreach my $lonhost (sort(keys(%servers))) {
960: my $direct = 'selected="selected"';
1.128 raeburn 961: if (ref($disallowed{$lonhost}) eq 'HASH') {
962: if ($disallowed{$lonhost}{'server'} ne '') {
963: $direct = '';
964: }
1.110 raeburn 965: }
1.115 raeburn 966: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 967: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 968: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
969: '</option>';
1.160.6.13 raeburn 970: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 971: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 972: my $selected = '';
1.128 raeburn 973: if (ref($disallowed{$lonhost}) eq 'HASH') {
974: if ($hostid eq $disallowed{$lonhost}{'server'}) {
975: $selected = 'selected="selected"';
976: }
1.110 raeburn 977: }
978: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
979: $servers{$hostid}.'</option>';
980: }
1.128 raeburn 981: $datatable .= '</select></td>'.
982: '<td><select name="'.$lonhost.'_serverpath">';
983: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
984: my $pathname = $path;
985: if ($path eq 'custom') {
986: $pathname = &mt('Custom Path').' ->';
987: }
988: my $selected = '';
989: if (ref($disallowed{$lonhost}) eq 'HASH') {
990: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
991: $selected = 'selected="selected"';
992: }
993: } elsif ($path eq '') {
994: $selected = 'selected="selected"';
995: }
996: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
997: }
998: $datatable .= '</select></td>';
999: my ($custom,$exempt);
1000: if (ref($disallowed{$lonhost}) eq 'HASH') {
1001: $custom = $disallowed{$lonhost}{'custompath'};
1002: $exempt = $disallowed{$lonhost}{'exempt'};
1003: }
1004: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1005: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1006: '</tr>';
1.110 raeburn 1007: }
1008: $datatable .= '</table></td></tr>';
1009: return $datatable;
1.160.6.5 raeburn 1010: } elsif ($caller eq 'page') {
1011: my %defaultchecked = (
1012: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1013: 'helpdesk' => 'on',
1.160.6.5 raeburn 1014: 'adminmail' => 'off',
1015: 'newuser' => 'off',
1016: );
1.160.6.14 raeburn 1017: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1018: my (%checkedon,%checkedoff);
1.42 raeburn 1019: foreach my $item (@toggles) {
1.160.6.5 raeburn 1020: if ($defaultchecked{$item} eq 'on') {
1021: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1022: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1023: } elsif ($defaultchecked{$item} eq 'off') {
1024: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1025: $checkedon{$item} = ' ';
1026: }
1.1 raeburn 1027: }
1.160.6.5 raeburn 1028: my @images = ('img','logo','domlogo','login');
1029: my @logintext = ('textcol','bgcol');
1030: my @bgs = ('pgbg','mainbg','sidebg');
1031: my @links = ('link','alink','vlink');
1032: my %designhash = &Apache::loncommon::get_domainconf($dom);
1033: my %defaultdesign = %Apache::loncommon::defaultdesign;
1034: my (%is_custom,%designs);
1035: my %defaults = (
1036: font => $defaultdesign{'login.font'},
1037: );
1.6 raeburn 1038: foreach my $item (@images) {
1.160.6.5 raeburn 1039: $defaults{$item} = $defaultdesign{'login.'.$item};
1040: $defaults{'showlogo'}{$item} = 1;
1041: }
1042: foreach my $item (@bgs) {
1043: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1044: }
1.41 raeburn 1045: foreach my $item (@logintext) {
1.160.6.5 raeburn 1046: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1047: }
1.160.6.5 raeburn 1048: foreach my $item (@links) {
1049: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1050: }
1.160.6.5 raeburn 1051: if (ref($settings) eq 'HASH') {
1052: foreach my $item (@toggles) {
1053: if ($settings->{$item} eq '1') {
1054: $checkedon{$item} = ' checked="checked" ';
1055: $checkedoff{$item} = ' ';
1056: } elsif ($settings->{$item} eq '0') {
1057: $checkedoff{$item} = ' checked="checked" ';
1058: $checkedon{$item} = ' ';
1059: }
1.6 raeburn 1060: }
1.160.6.5 raeburn 1061: foreach my $item (@images) {
1062: if (defined($settings->{$item})) {
1063: $designs{$item} = $settings->{$item};
1064: $is_custom{$item} = 1;
1065: }
1066: if (defined($settings->{'showlogo'}{$item})) {
1067: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1068: }
1069: }
1070: foreach my $item (@logintext) {
1071: if ($settings->{$item} ne '') {
1072: $designs{'logintext'}{$item} = $settings->{$item};
1073: $is_custom{$item} = 1;
1074: }
1075: }
1076: if ($settings->{'font'} ne '') {
1077: $designs{'font'} = $settings->{'font'};
1078: $is_custom{'font'} = 1;
1079: }
1080: foreach my $item (@bgs) {
1081: if ($settings->{$item} ne '') {
1082: $designs{'bgs'}{$item} = $settings->{$item};
1083: $is_custom{$item} = 1;
1084: }
1085: }
1086: foreach my $item (@links) {
1087: if ($settings->{$item} ne '') {
1088: $designs{'links'}{$item} = $settings->{$item};
1089: $is_custom{$item} = 1;
1090: }
1091: }
1092: } else {
1093: if ($designhash{$dom.'.login.font'} ne '') {
1094: $designs{'font'} = $designhash{$dom.'.login.font'};
1095: $is_custom{'font'} = 1;
1096: }
1097: foreach my $item (@images) {
1098: if ($designhash{$dom.'.login.'.$item} ne '') {
1099: $designs{$item} = $designhash{$dom.'.login.'.$item};
1100: $is_custom{$item} = 1;
1101: }
1102: }
1103: foreach my $item (@bgs) {
1104: if ($designhash{$dom.'.login.'.$item} ne '') {
1105: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1106: $is_custom{$item} = 1;
1107: }
1108: }
1109: foreach my $item (@links) {
1110: if ($designhash{$dom.'.login.'.$item} ne '') {
1111: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1112: $is_custom{$item} = 1;
1113: }
1.6 raeburn 1114: }
1115: }
1.160.6.5 raeburn 1116: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1117: logo => 'Institution Logo',
1118: domlogo => 'Domain Logo',
1119: login => 'Login box');
1120: my $itemcount = 1;
1121: foreach my $item (@toggles) {
1122: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1123: $datatable .=
1124: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1125: '</td><td>'.
1126: '<span class="LC_nobreak"><label><input type="radio" name="'.
1127: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1128: '</label> <label><input type="radio" name="'.$item.'"'.
1129: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1130: '</tr>';
1131: $itemcount ++;
1.6 raeburn 1132: }
1.160.6.5 raeburn 1133: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1134: $datatable .= '</tr></table></td></tr>';
1135: } elsif ($caller eq 'help') {
1136: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1137: my $switchserver = &check_switchserver($dom,$confname);
1138: my $itemcount = 1;
1139: $defaulturl = '/adm/loginproblems.html';
1140: $defaulttype = 'default';
1141: %lt = &Apache::lonlocal::texthash (
1142: del => 'Delete?',
1143: rep => 'Replace:',
1144: upl => 'Upload:',
1145: default => 'Default',
1146: custom => 'Custom',
1147: );
1148: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1149: my @currlangs;
1150: if (ref($settings) eq 'HASH') {
1151: if (ref($settings->{'helpurl'}) eq 'HASH') {
1152: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1153: next if ($settings->{'helpurl'}{$key} eq '');
1154: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1155: $type{$key} = 'custom';
1156: unless ($key eq 'nolang') {
1157: push(@currlangs,$key);
1158: }
1159: }
1160: } elsif ($settings->{'helpurl'} ne '') {
1161: $type{'nolang'} = 'custom';
1162: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1163: }
1164: }
1.160.6.5 raeburn 1165: foreach my $lang ('nolang',sort(@currlangs)) {
1166: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1167: $datatable .= '<tr'.$css_class.'>';
1168: if ($url{$lang} eq '') {
1169: $url{$lang} = $defaulturl;
1170: }
1171: if ($type{$lang} eq '') {
1172: $type{$lang} = $defaulttype;
1173: }
1174: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1175: if ($lang eq 'nolang') {
1176: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1177: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1178: } else {
1179: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1180: $langchoices{$lang},
1181: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1182: }
1183: $datatable .= '</span></td>'."\n".
1184: '<td class="LC_left_item">';
1185: if ($type{$lang} eq 'custom') {
1186: $datatable .= '<span class="LC_nobreak"><label>'.
1187: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1188: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1189: } else {
1190: $datatable .= $lt{'upl'};
1191: }
1192: $datatable .='<br />';
1193: if ($switchserver) {
1194: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1195: } else {
1196: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1197: }
1.160.6.5 raeburn 1198: $datatable .= '</td></tr>';
1199: $itemcount ++;
1.6 raeburn 1200: }
1.160.6.5 raeburn 1201: my @addlangs;
1202: foreach my $lang (sort(keys(%langchoices))) {
1203: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1204: push(@addlangs,$lang);
1205: }
1206: if (@addlangs > 0) {
1207: my %toadd;
1208: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1209: $toadd{''} = &mt('Select');
1210: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1211: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1212: &mt('Add log-in help page for a specific language:').' '.
1213: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1214: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1215: if ($switchserver) {
1216: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1217: } else {
1218: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1219: }
1.160.6.5 raeburn 1220: $datatable .= '</td></tr>';
1221: $itemcount ++;
1.6 raeburn 1222: }
1.160.6.5 raeburn 1223: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1224: } elsif ($caller eq 'headtag') {
1225: my %domservers = &Apache::lonnet::get_servers($dom);
1226: my $choice = $choices{'headtag'};
1227: $css_class = ' class="LC_odd_row"';
1228: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1229: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1230: '<th>'.$choices{'current'}.'</th>'.
1231: '<th>'.$choices{'action'}.'</th>'.
1232: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1233: my (%currurls,%currexempt);
1234: if (ref($settings) eq 'HASH') {
1235: if (ref($settings->{'headtag'}) eq 'HASH') {
1236: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1237: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1238: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1239: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1240: }
1241: }
1242: }
1243: }
1244: my %lt = &Apache::lonlocal::texthash(
1245: del => 'Delete?',
1246: rep => 'Replace:',
1247: upl => 'Upload:',
1248: curr => 'View contents',
1249: none => 'None',
1250: );
1251: my $switchserver = &check_switchserver($dom,$confname);
1252: foreach my $lonhost (sort(keys(%domservers))) {
1253: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1254: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1255: if ($currurls{$lonhost}) {
1256: $datatable .= '<td class="LC_right_item"><a href="'.
1257: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1258: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1259: '">'.$lt{'curr'}.'</a></td>'.
1260: '<td><span class="LC_nobreak"><label>'.
1261: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1262: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1263: } else {
1264: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1265: }
1266: $datatable .='<br />';
1267: if ($switchserver) {
1268: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1269: } else {
1270: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1271: }
1272: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1273: }
1274: $datatable .= '</table></td></tr>';
1.1 raeburn 1275: }
1.6 raeburn 1276: return $datatable;
1277: }
1278:
1279: sub login_choices {
1280: my %choices =
1281: &Apache::lonlocal::texthash (
1.116 bisitz 1282: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1283: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1284: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1285: disallowlogin => "Login page requests redirected",
1286: hostid => "Server",
1.128 raeburn 1287: server => "Redirect to:",
1288: serverpath => "Path",
1289: custompath => "Custom",
1290: exempt => "Exempt IP(s)",
1.110 raeburn 1291: directlogin => "No redirect",
1292: newuser => "Link to create a user account",
1293: img => "Header",
1294: logo => "Main Logo",
1295: domlogo => "Domain Logo",
1296: login => "Log-in Header",
1297: textcol => "Text color",
1298: bgcol => "Box color",
1299: bgs => "Background colors",
1300: links => "Link colors",
1301: font => "Font color",
1302: pgbg => "Header",
1303: mainbg => "Page",
1304: sidebg => "Login box",
1305: link => "Link",
1306: alink => "Active link",
1307: vlink => "Visited link",
1.160.6.56 raeburn 1308: headtag => "Custom markup",
1309: action => "Action",
1310: current => "Current",
1.6 raeburn 1311: );
1312: return %choices;
1313: }
1314:
1315: sub print_rolecolors {
1.30 raeburn 1316: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1317: my %choices = &color_font_choices();
1318: my @bgs = ('pgbg','tabbg','sidebg');
1319: my @links = ('link','alink','vlink');
1320: my @images = ('img');
1321: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1322: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1323: my %defaultdesign = %Apache::loncommon::defaultdesign;
1324: my (%is_custom,%designs);
1.160.6.22 raeburn 1325: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1326: if (ref($settings) eq 'HASH') {
1327: if (ref($settings->{$role}) eq 'HASH') {
1328: if ($settings->{$role}->{'img'} ne '') {
1329: $designs{'img'} = $settings->{$role}->{'img'};
1330: $is_custom{'img'} = 1;
1331: }
1332: if ($settings->{$role}->{'font'} ne '') {
1333: $designs{'font'} = $settings->{$role}->{'font'};
1334: $is_custom{'font'} = 1;
1335: }
1.97 tempelho 1336: if ($settings->{$role}->{'fontmenu'} ne '') {
1337: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1338: $is_custom{'fontmenu'} = 1;
1339: }
1.6 raeburn 1340: foreach my $item (@bgs) {
1341: if ($settings->{$role}->{$item} ne '') {
1342: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1343: $is_custom{$item} = 1;
1344: }
1345: }
1346: foreach my $item (@links) {
1347: if ($settings->{$role}->{$item} ne '') {
1348: $designs{'links'}{$item} = $settings->{$role}->{$item};
1349: $is_custom{$item} = 1;
1350: }
1351: }
1352: }
1353: } else {
1354: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1355: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1356: $is_custom{'img'} = 1;
1357: }
1.97 tempelho 1358: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1359: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1360: $is_custom{'fontmenu'} = 1;
1361: }
1.6 raeburn 1362: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1363: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1364: $is_custom{'font'} = 1;
1365: }
1366: foreach my $item (@bgs) {
1367: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1368: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1369: $is_custom{$item} = 1;
1370:
1371: }
1372: }
1373: foreach my $item (@links) {
1374: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1375: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1376: $is_custom{$item} = 1;
1377: }
1378: }
1379: }
1380: my $itemcount = 1;
1.30 raeburn 1381: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1382: $datatable .= '</tr></table></td></tr>';
1383: return $datatable;
1384: }
1385:
1.160.6.22 raeburn 1386: sub role_defaults {
1387: my ($role,$bgs,$links,$images,$logintext) = @_;
1388: my %defaults;
1389: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1390: return %defaults;
1391: }
1392: my %defaultdesign = %Apache::loncommon::defaultdesign;
1393: if ($role eq 'login') {
1394: %defaults = (
1395: font => $defaultdesign{$role.'.font'},
1396: );
1397: if (ref($logintext) eq 'ARRAY') {
1398: foreach my $item (@{$logintext}) {
1399: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1400: }
1401: }
1402: foreach my $item (@{$images}) {
1403: $defaults{'showlogo'}{$item} = 1;
1404: }
1405: } else {
1406: %defaults = (
1407: img => $defaultdesign{$role.'.img'},
1408: font => $defaultdesign{$role.'.font'},
1409: fontmenu => $defaultdesign{$role.'.fontmenu'},
1410: );
1411: }
1412: foreach my $item (@{$bgs}) {
1413: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1414: }
1415: foreach my $item (@{$links}) {
1416: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1417: }
1418: foreach my $item (@{$images}) {
1419: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1420: }
1421: return %defaults;
1422: }
1423:
1.6 raeburn 1424: sub display_color_options {
1.9 raeburn 1425: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1426: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1427: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1428: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1429: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1430: '<td>'.$choices->{'font'}.'</td>';
1431: if (!$is_custom->{'font'}) {
1.30 raeburn 1432: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1433: } else {
1434: $datatable .= '<td> </td>';
1435: }
1.160.6.9 raeburn 1436: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1437:
1.8 raeburn 1438: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1439: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1440: ' value="'.$current_color.'" /> '.
1441: ' </td></tr>';
1.107 raeburn 1442: unless ($role eq 'login') {
1443: $datatable .= '<tr'.$css_class.'>'.
1444: '<td>'.$choices->{'fontmenu'}.'</td>';
1445: if (!$is_custom->{'fontmenu'}) {
1446: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1447: } else {
1448: $datatable .= '<td> </td>';
1449: }
1.160.6.22 raeburn 1450: $current_color = $designs->{'fontmenu'} ?
1451: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1452: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1453: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1454: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1455: ' value="'.$current_color.'" /> '.
1456: ' </td></tr>';
1.97 tempelho 1457: }
1.9 raeburn 1458: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1459: foreach my $img (@{$images}) {
1.18 albertel 1460: $itemcount ++;
1.6 raeburn 1461: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1462: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1463: '<td>'.$choices->{$img};
1.41 raeburn 1464: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1465: if ($role eq 'login') {
1466: if ($img eq 'login') {
1467: $login_hdr_pick =
1.135 bisitz 1468: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1469: $logincolors =
1470: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1471: $designs,$defaults);
1.70 raeburn 1472: } elsif ($img ne 'domlogo') {
1473: $datatable.= &logo_display_options($img,$defaults,$designs);
1474: }
1475: }
1476: $datatable .= '</td>';
1.6 raeburn 1477: if ($designs->{$img} ne '') {
1478: $imgfile = $designs->{$img};
1.18 albertel 1479: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1480: } else {
1481: $imgfile = $defaults->{$img};
1482: }
1483: if ($imgfile) {
1.9 raeburn 1484: my ($showfile,$fullsize);
1485: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1486: my $urldir = $1;
1487: my $filename = $2;
1488: my @info = &Apache::lonnet::stat_file($designs->{$img});
1489: if (@info) {
1490: my $thumbfile = 'tn-'.$filename;
1491: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1492: if (@thumb) {
1493: $showfile = $urldir.'/'.$thumbfile;
1494: } else {
1495: $showfile = $imgfile;
1496: }
1497: } else {
1498: $showfile = '';
1499: }
1500: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1501: $showfile = $imgfile;
1.6 raeburn 1502: my $imgdir = $1;
1503: my $filename = $2;
1.159 raeburn 1504: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1505: $showfile = "/$imgdir/tn-".$filename;
1506: } else {
1.159 raeburn 1507: my $input = $londocroot.$imgfile;
1508: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1509: if (!-e $output) {
1.9 raeburn 1510: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1511: my ($fullwidth,$fullheight) = &check_dimensions($input);
1512: if ($fullwidth ne '' && $fullheight ne '') {
1513: if ($fullwidth > $width && $fullheight > $height) {
1514: my $size = $width.'x'.$height;
1515: system("convert -sample $size $input $output");
1.159 raeburn 1516: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1517: }
1518: }
1.6 raeburn 1519: }
1520: }
1.16 raeburn 1521: }
1.6 raeburn 1522: if ($showfile) {
1.40 raeburn 1523: if ($showfile =~ m{^/(adm|res)/}) {
1524: if ($showfile =~ m{^/res/}) {
1525: my $local_showfile =
1526: &Apache::lonnet::filelocation('',$showfile);
1527: &Apache::lonnet::repcopy($local_showfile);
1528: }
1529: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1530: }
1531: if ($imgfile) {
1532: if ($imgfile =~ m{^/(adm|res)/}) {
1533: if ($imgfile =~ m{^/res/}) {
1534: my $local_imgfile =
1535: &Apache::lonnet::filelocation('',$imgfile);
1536: &Apache::lonnet::repcopy($local_imgfile);
1537: }
1538: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1539: } else {
1540: $fullsize = $imgfile;
1541: }
1542: }
1.41 raeburn 1543: $datatable .= '<td>';
1544: if ($img eq 'login') {
1.135 bisitz 1545: $datatable .= $login_hdr_pick;
1546: }
1.41 raeburn 1547: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1548: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1549: } else {
1.160.6.22 raeburn 1550: $datatable .= '<td> </td><td class="LC_left_item">'.
1551: &mt('Upload:').'<br />';
1.6 raeburn 1552: }
1553: } else {
1.160.6.22 raeburn 1554: $datatable .= '<td> </td><td class="LC_left_item">'.
1555: &mt('Upload:').'<br />';
1.6 raeburn 1556: }
1.9 raeburn 1557: if ($switchserver) {
1558: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1559: } else {
1.135 bisitz 1560: if ($img ne 'login') { # suppress file selection for Log-in header
1561: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1562: }
1.9 raeburn 1563: }
1564: $datatable .= '</td></tr>';
1.6 raeburn 1565: }
1566: $itemcount ++;
1567: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1568: $datatable .= '<tr'.$css_class.'>'.
1569: '<td>'.$choices->{'bgs'}.'</td>';
1570: my $bgs_def;
1571: foreach my $item (@{$bgs}) {
1572: if (!$is_custom->{$item}) {
1.70 raeburn 1573: $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 1574: }
1575: }
1576: if ($bgs_def) {
1.8 raeburn 1577: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1578: } else {
1579: $datatable .= '<td> </td>';
1580: }
1581: $datatable .= '<td class="LC_right_item">'.
1582: '<table border="0"><tr>';
1.160.6.13 raeburn 1583:
1.6 raeburn 1584: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1585: $datatable .= '<td align="center">'.$choices->{$item};
1586: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1587: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1588: $datatable .= ' ';
1.6 raeburn 1589: }
1.160.6.9 raeburn 1590: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1591: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1592: }
1593: $datatable .= '</tr></table></td></tr>';
1594: $itemcount ++;
1595: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1596: $datatable .= '<tr'.$css_class.'>'.
1597: '<td>'.$choices->{'links'}.'</td>';
1598: my $links_def;
1599: foreach my $item (@{$links}) {
1600: if (!$is_custom->{$item}) {
1.30 raeburn 1601: $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 1602: }
1603: }
1604: if ($links_def) {
1.8 raeburn 1605: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1606: } else {
1607: $datatable .= '<td> </td>';
1608: }
1609: $datatable .= '<td class="LC_right_item">'.
1610: '<table border="0"><tr>';
1611: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1612: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1613: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1614: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1615: $datatable.=' ';
1.6 raeburn 1616: }
1.160.6.9 raeburn 1617: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1618: '" /></td>';
1619: }
1.30 raeburn 1620: $$rowtotal += $itemcount;
1.3 raeburn 1621: return $datatable;
1622: }
1623:
1.70 raeburn 1624: sub logo_display_options {
1625: my ($img,$defaults,$designs) = @_;
1626: my $checkedon;
1627: if (ref($defaults) eq 'HASH') {
1628: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1629: if ($defaults->{'showlogo'}{$img}) {
1630: $checkedon = 'checked="checked" ';
1631: }
1632: }
1633: }
1634: if (ref($designs) eq 'HASH') {
1635: if (ref($designs->{'showlogo'}) eq 'HASH') {
1636: if (defined($designs->{'showlogo'}{$img})) {
1637: if ($designs->{'showlogo'}{$img} == 0) {
1638: $checkedon = '';
1639: } elsif ($designs->{'showlogo'}{$img} == 1) {
1640: $checkedon = 'checked="checked" ';
1641: }
1642: }
1643: }
1644: }
1645: return '<br /><label> <input type="checkbox" name="'.
1646: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1647: &mt('show').'</label>'."\n";
1648: }
1649:
1.41 raeburn 1650: sub login_header_options {
1.135 bisitz 1651: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1652: my $output = '';
1.41 raeburn 1653: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1654: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1655: if (!$is_custom->{'textcol'}) {
1656: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1657: ' ';
1658: }
1659: if (!$is_custom->{'bgcol'}) {
1660: $output .= $choices->{'bgcol'}.': '.
1661: '<span id="css_'.$role.'_font" style="background-color: '.
1662: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1663: }
1664: $output .= '<br />';
1665: }
1666: $output .='<br />';
1667: return $output;
1668: }
1669:
1670: sub login_text_colors {
1.160.6.22 raeburn 1671: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1672: my $color_menu = '<table border="0"><tr>';
1673: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1674: $color_menu .= '<td align="center">'.$choices->{$item};
1675: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1676: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1677: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1678: }
1679: $color_menu .= '</tr></table><br />';
1680: return $color_menu;
1681: }
1682:
1683: sub image_changes {
1684: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1685: my $output;
1.135 bisitz 1686: if ($img eq 'login') {
1687: # suppress image for Log-in header
1688: } elsif (!$is_custom) {
1.70 raeburn 1689: if ($img ne 'domlogo') {
1.41 raeburn 1690: $output .= &mt('Default image:').'<br />';
1691: } else {
1692: $output .= &mt('Default in use:').'<br />';
1693: }
1694: }
1.135 bisitz 1695: if ($img eq 'login') { # suppress image for Log-in header
1696: $output .= '<td>'.$logincolors;
1.41 raeburn 1697: } else {
1.135 bisitz 1698: if ($img_import) {
1699: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1700: }
1701: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1702: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1703: if ($is_custom) {
1704: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1705: '<input type="checkbox" name="'.
1706: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1707: '</label> '.&mt('Replace:').'</span><br />';
1708: } else {
1.160.6.22 raeburn 1709: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1710: }
1.41 raeburn 1711: }
1712: return $output;
1713: }
1714:
1.3 raeburn 1715: sub print_quotas {
1.86 raeburn 1716: my ($dom,$settings,$rowtotal,$action) = @_;
1717: my $context;
1718: if ($action eq 'quotas') {
1719: $context = 'tools';
1720: } else {
1721: $context = $action;
1722: }
1.160.6.20 raeburn 1723: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1724: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1725: my $typecount = 0;
1.101 raeburn 1726: my ($css_class,%titles);
1.86 raeburn 1727: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1728: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1729: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1730: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1731: %titles = &courserequest_titles();
1.160.6.5 raeburn 1732: } elsif ($context eq 'requestauthor') {
1733: @usertools = ('author');
1734: @options = ('norequest','approval','automatic');
1735: %titles = &authorrequest_titles();
1.86 raeburn 1736: } else {
1.160.6.4 raeburn 1737: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1738: %titles = &tool_titles();
1.86 raeburn 1739: }
1.26 raeburn 1740: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1741: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1742: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1743: unless (($context eq 'requestcourses') ||
1744: ($context eq 'requestauthor')) {
1.86 raeburn 1745: if (ref($settings) eq 'HASH') {
1746: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1747: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1748: } else {
1749: $currdefquota = $settings->{$type};
1750: }
1.160.6.20 raeburn 1751: if (ref($settings->{authorquota}) eq 'HASH') {
1752: $currauthorquota = $settings->{authorquota}->{$type};
1753: }
1.78 raeburn 1754: }
1.72 raeburn 1755: }
1.3 raeburn 1756: if (defined($usertypes->{$type})) {
1757: $typecount ++;
1758: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1759: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1760: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1761: '<td class="LC_left_item">';
1.101 raeburn 1762: if ($context eq 'requestcourses') {
1763: $datatable .= '<table><tr>';
1764: }
1765: my %cell;
1.72 raeburn 1766: foreach my $item (@usertools) {
1.101 raeburn 1767: if ($context eq 'requestcourses') {
1768: my ($curroption,$currlimit);
1769: if (ref($settings) eq 'HASH') {
1770: if (ref($settings->{$item}) eq 'HASH') {
1771: $curroption = $settings->{$item}->{$type};
1772: if ($curroption =~ /^autolimit=(\d*)$/) {
1773: $currlimit = $1;
1774: }
1775: }
1776: }
1777: if (!$curroption) {
1778: $curroption = 'norequest';
1779: }
1780: $datatable .= '<th>'.$titles{$item}.'</th>';
1781: foreach my $option (@options) {
1782: my $val = $option;
1783: if ($option eq 'norequest') {
1784: $val = 0;
1785: }
1786: if ($option eq 'validate') {
1787: my $canvalidate = 0;
1788: if (ref($validations{$item}) eq 'HASH') {
1789: if ($validations{$item}{$type}) {
1790: $canvalidate = 1;
1791: }
1792: }
1793: next if (!$canvalidate);
1794: }
1795: my $checked = '';
1796: if ($option eq $curroption) {
1797: $checked = ' checked="checked"';
1798: } elsif ($option eq 'autolimit') {
1799: if ($curroption =~ /^autolimit/) {
1800: $checked = ' checked="checked"';
1801: }
1802: }
1803: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1804: '<input type="radio" name="crsreq_'.$item.
1805: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1806: $titles{$option}.'</label>';
1.101 raeburn 1807: if ($option eq 'autolimit') {
1.127 raeburn 1808: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1809: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1810: 'value="'.$currlimit.'" />';
1.101 raeburn 1811: }
1.127 raeburn 1812: $cell{$item} .= '</span> ';
1.103 raeburn 1813: if ($option eq 'autolimit') {
1.127 raeburn 1814: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1815: }
1.101 raeburn 1816: }
1.160.6.5 raeburn 1817: } elsif ($context eq 'requestauthor') {
1818: my $curroption;
1819: if (ref($settings) eq 'HASH') {
1820: $curroption = $settings->{$type};
1821: }
1822: if (!$curroption) {
1823: $curroption = 'norequest';
1824: }
1825: foreach my $option (@options) {
1826: my $val = $option;
1827: if ($option eq 'norequest') {
1828: $val = 0;
1829: }
1830: my $checked = '';
1831: if ($option eq $curroption) {
1832: $checked = ' checked="checked"';
1833: }
1834: $datatable .= '<span class="LC_nobreak"><label>'.
1835: '<input type="radio" name="authorreq_'.$type.
1836: '" value="'.$val.'"'.$checked.' />'.
1837: $titles{$option}.'</label></span> ';
1838: }
1.101 raeburn 1839: } else {
1840: my $checked = 'checked="checked" ';
1841: if (ref($settings) eq 'HASH') {
1842: if (ref($settings->{$item}) eq 'HASH') {
1843: if ($settings->{$item}->{$type} == 0) {
1844: $checked = '';
1845: } elsif ($settings->{$item}->{$type} == 1) {
1846: $checked = 'checked="checked" ';
1847: }
1.78 raeburn 1848: }
1.72 raeburn 1849: }
1.101 raeburn 1850: $datatable .= '<span class="LC_nobreak"><label>'.
1851: '<input type="checkbox" name="'.$context.'_'.$item.
1852: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1853: '</label></span> ';
1.72 raeburn 1854: }
1.101 raeburn 1855: }
1856: if ($context eq 'requestcourses') {
1857: $datatable .= '</tr><tr>';
1858: foreach my $item (@usertools) {
1.106 raeburn 1859: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1860: }
1861: $datatable .= '</tr></table>';
1.72 raeburn 1862: }
1.86 raeburn 1863: $datatable .= '</td>';
1.160.6.5 raeburn 1864: unless (($context eq 'requestcourses') ||
1865: ($context eq 'requestauthor')) {
1.86 raeburn 1866: $datatable .=
1.160.6.20 raeburn 1867: '<td class="LC_right_item">'.
1868: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1869: '<input type="text" name="quota_'.$type.
1.72 raeburn 1870: '" value="'.$currdefquota.
1.160.6.20 raeburn 1871: '" size="5" /></span>'.(' ' x 2).
1872: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1873: '<input type="text" name="authorquota_'.$type.
1874: '" value="'.$currauthorquota.
1875: '" size="5" /></span></td>';
1.86 raeburn 1876: }
1877: $datatable .= '</tr>';
1.3 raeburn 1878: }
1879: }
1880: }
1.160.6.5 raeburn 1881: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1882: $defaultquota = '20';
1.160.6.20 raeburn 1883: $authorquota = '500';
1.86 raeburn 1884: if (ref($settings) eq 'HASH') {
1885: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1886: $defaultquota = $settings->{'defaultquota'}->{'default'};
1887: } elsif (defined($settings->{'default'})) {
1888: $defaultquota = $settings->{'default'};
1889: }
1.160.6.20 raeburn 1890: if (ref($settings->{'authorquota'}) eq 'HASH') {
1891: $authorquota = $settings->{'authorquota'}->{'default'};
1892: }
1.3 raeburn 1893: }
1894: }
1895: $typecount ++;
1896: $css_class = $typecount%2?' class="LC_odd_row"':'';
1897: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1898: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1899: '<td class="LC_left_item">';
1.101 raeburn 1900: if ($context eq 'requestcourses') {
1901: $datatable .= '<table><tr>';
1902: }
1903: my %defcell;
1.72 raeburn 1904: foreach my $item (@usertools) {
1.101 raeburn 1905: if ($context eq 'requestcourses') {
1906: my ($curroption,$currlimit);
1907: if (ref($settings) eq 'HASH') {
1908: if (ref($settings->{$item}) eq 'HASH') {
1909: $curroption = $settings->{$item}->{'default'};
1910: if ($curroption =~ /^autolimit=(\d*)$/) {
1911: $currlimit = $1;
1912: }
1913: }
1914: }
1915: if (!$curroption) {
1916: $curroption = 'norequest';
1917: }
1918: $datatable .= '<th>'.$titles{$item}.'</th>';
1919: foreach my $option (@options) {
1920: my $val = $option;
1921: if ($option eq 'norequest') {
1922: $val = 0;
1923: }
1924: if ($option eq 'validate') {
1925: my $canvalidate = 0;
1926: if (ref($validations{$item}) eq 'HASH') {
1927: if ($validations{$item}{'default'}) {
1928: $canvalidate = 1;
1929: }
1930: }
1931: next if (!$canvalidate);
1932: }
1933: my $checked = '';
1934: if ($option eq $curroption) {
1935: $checked = ' checked="checked"';
1936: } elsif ($option eq 'autolimit') {
1937: if ($curroption =~ /^autolimit/) {
1938: $checked = ' checked="checked"';
1939: }
1940: }
1941: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1942: '<input type="radio" name="crsreq_'.$item.
1943: '_default" value="'.$val.'"'.$checked.' />'.
1944: $titles{$option}.'</label>';
1945: if ($option eq 'autolimit') {
1.127 raeburn 1946: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1947: $item.'_limit_default" size="1" '.
1948: 'value="'.$currlimit.'" />';
1949: }
1.127 raeburn 1950: $defcell{$item} .= '</span> ';
1.104 raeburn 1951: if ($option eq 'autolimit') {
1.127 raeburn 1952: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1953: }
1.101 raeburn 1954: }
1.160.6.5 raeburn 1955: } elsif ($context eq 'requestauthor') {
1956: my $curroption;
1957: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1958: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1959: }
1960: if (!$curroption) {
1961: $curroption = 'norequest';
1962: }
1963: foreach my $option (@options) {
1964: my $val = $option;
1965: if ($option eq 'norequest') {
1966: $val = 0;
1967: }
1968: my $checked = '';
1969: if ($option eq $curroption) {
1970: $checked = ' checked="checked"';
1971: }
1972: $datatable .= '<span class="LC_nobreak"><label>'.
1973: '<input type="radio" name="authorreq_default"'.
1974: ' value="'.$val.'"'.$checked.' />'.
1975: $titles{$option}.'</label></span> ';
1976: }
1.101 raeburn 1977: } else {
1978: my $checked = 'checked="checked" ';
1979: if (ref($settings) eq 'HASH') {
1980: if (ref($settings->{$item}) eq 'HASH') {
1981: if ($settings->{$item}->{'default'} == 0) {
1982: $checked = '';
1983: } elsif ($settings->{$item}->{'default'} == 1) {
1984: $checked = 'checked="checked" ';
1985: }
1.78 raeburn 1986: }
1.72 raeburn 1987: }
1.101 raeburn 1988: $datatable .= '<span class="LC_nobreak"><label>'.
1989: '<input type="checkbox" name="'.$context.'_'.$item.
1990: '" value="default" '.$checked.'/>'.$titles{$item}.
1991: '</label></span> ';
1992: }
1993: }
1994: if ($context eq 'requestcourses') {
1995: $datatable .= '</tr><tr>';
1996: foreach my $item (@usertools) {
1.106 raeburn 1997: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1998: }
1.101 raeburn 1999: $datatable .= '</tr></table>';
1.72 raeburn 2000: }
1.86 raeburn 2001: $datatable .= '</td>';
1.160.6.5 raeburn 2002: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2003: $datatable .= '<td class="LC_right_item">'.
2004: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2005: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2006: $defaultquota.'" size="5" /></span>'.(' ' x2).
2007: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2008: '<input type="text" name="authorquota" value="'.
2009: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2010: }
2011: $datatable .= '</tr>';
1.72 raeburn 2012: $typecount ++;
2013: $css_class = $typecount%2?' class="LC_odd_row"':'';
2014: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2015: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2016: if ($context eq 'requestcourses') {
1.109 raeburn 2017: $datatable .= &mt('(overrides affiliation, if set)').
2018: '</td>'.
2019: '<td class="LC_left_item">'.
2020: '<table><tr>';
1.101 raeburn 2021: } else {
1.109 raeburn 2022: $datatable .= &mt('(overrides affiliation, if checked)').
2023: '</td>'.
2024: '<td class="LC_left_item" colspan="2">'.
2025: '<br />';
1.101 raeburn 2026: }
2027: my %advcell;
1.72 raeburn 2028: foreach my $item (@usertools) {
1.101 raeburn 2029: if ($context eq 'requestcourses') {
2030: my ($curroption,$currlimit);
2031: if (ref($settings) eq 'HASH') {
2032: if (ref($settings->{$item}) eq 'HASH') {
2033: $curroption = $settings->{$item}->{'_LC_adv'};
2034: if ($curroption =~ /^autolimit=(\d*)$/) {
2035: $currlimit = $1;
2036: }
2037: }
2038: }
2039: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2040: my $checked = '';
2041: if ($curroption eq '') {
2042: $checked = ' checked="checked"';
2043: }
2044: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2045: '<input type="radio" name="crsreq_'.$item.
2046: '__LC_adv" value=""'.$checked.' />'.
2047: &mt('No override set').'</label></span> ';
1.101 raeburn 2048: foreach my $option (@options) {
2049: my $val = $option;
2050: if ($option eq 'norequest') {
2051: $val = 0;
2052: }
2053: if ($option eq 'validate') {
2054: my $canvalidate = 0;
2055: if (ref($validations{$item}) eq 'HASH') {
2056: if ($validations{$item}{'_LC_adv'}) {
2057: $canvalidate = 1;
2058: }
2059: }
2060: next if (!$canvalidate);
2061: }
2062: my $checked = '';
1.104 raeburn 2063: if ($val eq $curroption) {
1.101 raeburn 2064: $checked = ' checked="checked"';
2065: } elsif ($option eq 'autolimit') {
2066: if ($curroption =~ /^autolimit/) {
2067: $checked = ' checked="checked"';
2068: }
2069: }
2070: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2071: '<input type="radio" name="crsreq_'.$item.
2072: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2073: $titles{$option}.'</label>';
2074: if ($option eq 'autolimit') {
1.127 raeburn 2075: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2076: $item.'_limit__LC_adv" size="1" '.
2077: 'value="'.$currlimit.'" />';
2078: }
1.127 raeburn 2079: $advcell{$item} .= '</span> ';
1.104 raeburn 2080: if ($option eq 'autolimit') {
1.127 raeburn 2081: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2082: }
1.101 raeburn 2083: }
1.160.6.5 raeburn 2084: } elsif ($context eq 'requestauthor') {
2085: my $curroption;
2086: if (ref($settings) eq 'HASH') {
2087: $curroption = $settings->{'_LC_adv'};
2088: }
2089: my $checked = '';
2090: if ($curroption eq '') {
2091: $checked = ' checked="checked"';
2092: }
2093: $datatable .= '<span class="LC_nobreak"><label>'.
2094: '<input type="radio" name="authorreq__LC_adv"'.
2095: ' value=""'.$checked.' />'.
2096: &mt('No override set').'</label></span> ';
2097: foreach my $option (@options) {
2098: my $val = $option;
2099: if ($option eq 'norequest') {
2100: $val = 0;
2101: }
2102: my $checked = '';
2103: if ($val eq $curroption) {
2104: $checked = ' checked="checked"';
2105: }
2106: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2107: '<input type="radio" name="authorreq__LC_adv"'.
2108: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2109: $titles{$option}.'</label></span> ';
2110: }
1.101 raeburn 2111: } else {
2112: my $checked = 'checked="checked" ';
2113: if (ref($settings) eq 'HASH') {
2114: if (ref($settings->{$item}) eq 'HASH') {
2115: if ($settings->{$item}->{'_LC_adv'} == 0) {
2116: $checked = '';
2117: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2118: $checked = 'checked="checked" ';
2119: }
1.79 raeburn 2120: }
1.72 raeburn 2121: }
1.101 raeburn 2122: $datatable .= '<span class="LC_nobreak"><label>'.
2123: '<input type="checkbox" name="'.$context.'_'.$item.
2124: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2125: '</label></span> ';
2126: }
2127: }
2128: if ($context eq 'requestcourses') {
2129: $datatable .= '</tr><tr>';
2130: foreach my $item (@usertools) {
1.106 raeburn 2131: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2132: }
1.101 raeburn 2133: $datatable .= '</tr></table>';
1.72 raeburn 2134: }
1.98 raeburn 2135: $datatable .= '</td></tr>';
1.30 raeburn 2136: $$rowtotal += $typecount;
1.3 raeburn 2137: return $datatable;
2138: }
2139:
1.160.6.5 raeburn 2140: sub print_requestmail {
2141: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2142: my ($now,$datatable,%currapp);
1.102 raeburn 2143: $now = time;
2144: if (ref($settings) eq 'HASH') {
2145: if (ref($settings->{'notify'}) eq 'HASH') {
2146: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2147: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2148: }
2149: }
2150: }
1.160.6.16 raeburn 2151: my $numinrow = 2;
1.160.6.34 raeburn 2152: my $css_class;
2153: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2154: my $text;
2155: if ($action eq 'requestcourses') {
2156: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2157: } elsif ($action eq 'requestauthor') {
2158: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2159: } else {
1.160.6.34 raeburn 2160: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2161: }
1.160.6.34 raeburn 2162: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2163: ' <td>'.$text.'</td>'.
1.102 raeburn 2164: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2165: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2166: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2167: if ($numdc > 0) {
2168: $datatable .= $table;
1.102 raeburn 2169: } else {
2170: $datatable .= &mt('There are no active Domain Coordinators');
2171: }
2172: $datatable .='</td></tr>';
2173: return $datatable;
2174: }
2175:
1.160.6.30 raeburn 2176: sub print_studentcode {
2177: my ($settings,$rowtotal) = @_;
2178: my $rownum = 0;
2179: my ($output,%current);
2180: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2181: if (ref($settings) eq 'HASH') {
2182: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2183: foreach my $type (@crstypes) {
2184: $current{$type} = $settings->{'uniquecode'}{$type};
2185: }
1.160.6.30 raeburn 2186: }
2187: }
2188: $output .= '<tr>'.
2189: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2190: '<td class="LC_left_item">';
2191: foreach my $type (@crstypes) {
2192: my $check = ' ';
2193: if ($current{$type}) {
2194: $check = ' checked="checked" ';
2195: }
2196: $output .= '<span class="LC_nobreak"><label>'.
2197: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2198: &mt($type).'</label></span>'.(' 'x2).' ';
2199: }
2200: $output .= '</td></tr>';
2201: $$rowtotal ++;
2202: return $output;
2203: }
2204:
2205: sub print_textbookcourses {
1.160.6.46 raeburn 2206: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2207: my $rownum = 0;
2208: my $css_class;
2209: my $itemcount = 1;
2210: my $maxnum = 0;
2211: my $bookshash;
2212: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2213: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2214: }
2215: my %ordered;
2216: if (ref($bookshash) eq 'HASH') {
2217: foreach my $item (keys(%{$bookshash})) {
2218: if (ref($bookshash->{$item}) eq 'HASH') {
2219: my $num = $bookshash->{$item}{'order'};
2220: $ordered{$num} = $item;
2221: }
2222: }
2223: }
2224: my $confname = $dom.'-domainconfig';
2225: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2226: my $maxnum = scalar(keys(%ordered));
2227: my $datatable;
1.160.6.30 raeburn 2228: if (keys(%ordered)) {
2229: my @items = sort { $a <=> $b } keys(%ordered);
2230: for (my $i=0; $i<@items; $i++) {
2231: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2232: my $key = $ordered{$items[$i]};
2233: my %coursehash=&Apache::lonnet::coursedescription($key);
2234: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2235: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2236: if (ref($bookshash->{$key}) eq 'HASH') {
2237: $subject = $bookshash->{$key}->{'subject'};
2238: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2239: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2240: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2241: $author = $bookshash->{$key}->{'author'};
2242: $image = $bookshash->{$key}->{'image'};
2243: if ($image ne '') {
2244: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2245: my $imagethumb = "$path/tn-".$imagefile;
2246: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2247: }
1.160.6.30 raeburn 2248: }
2249: }
1.160.6.46 raeburn 2250: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2251: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2252: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2253: for (my $k=0; $k<=$maxnum; $k++) {
2254: my $vpos = $k+1;
2255: my $selstr;
2256: if ($k == $i) {
2257: $selstr = ' selected="selected" ';
2258: }
2259: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2260: }
2261: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2262: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2263: &mt('Delete?').'</label></span></td>'.
2264: '<td colspan="2">'.
1.160.6.46 raeburn 2265: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2266: (' 'x2).
1.160.6.46 raeburn 2267: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2268: if ($type eq 'textbooks') {
2269: $datatable .= (' 'x2).
1.160.6.47 raeburn 2270: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2271: (' 'x2).
1.160.6.46 raeburn 2272: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2273: (' 'x2).
2274: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2275: if ($image) {
2276: $datatable .= '<span class="LC_nobreak">'.
2277: $imgsrc.
2278: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2279: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2280: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2281: }
2282: if ($switchserver) {
2283: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2284: } else {
2285: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2286: }
1.160.6.30 raeburn 2287: }
1.160.6.46 raeburn 2288: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2289: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2290: $coursetitle.'</span></td></tr>'."\n";
2291: $itemcount ++;
2292: }
2293: }
2294: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2295: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2296: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2297: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2298: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2299: for (my $k=0; $k<$maxnum+1; $k++) {
2300: my $vpos = $k+1;
2301: my $selstr;
2302: if ($k == $maxnum) {
2303: $selstr = ' selected="selected" ';
2304: }
2305: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2306: }
2307: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2308: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2309: '<td colspan="2">'.
1.160.6.46 raeburn 2310: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2311: (' 'x2).
1.160.6.46 raeburn 2312: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2313: (' 'x2);
2314: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2315: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2316: (' 'x2).
2317: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2318: (' 'x2).
2319: '<span class="LC_nobreak">'.&mt('Image:').' ';
2320: if ($switchserver) {
2321: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2322: } else {
2323: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2324: }
1.160.6.30 raeburn 2325: }
2326: $datatable .= '</span>'."\n".
2327: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2328: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2329: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2330: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2331: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2332: '</span></td>'."\n".
2333: '</tr>'."\n";
2334: $itemcount ++;
2335: return $datatable;
2336: }
2337:
2338: sub textbookcourses_javascript {
1.160.6.46 raeburn 2339: my ($settings) = @_;
2340: return unless(ref($settings) eq 'HASH');
2341: my (%ordered,%total,%jstext);
2342: foreach my $type ('textbooks','templates') {
2343: $total{$type} = 0;
2344: if (ref($settings->{$type}) eq 'HASH') {
2345: foreach my $item (keys(%{$settings->{$type}})) {
2346: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2347: my $num = $settings->{$type}->{$item}{'order'};
2348: $ordered{$type}{$num} = $item;
2349: }
2350: }
2351: $total{$type} = scalar(keys(%{$settings->{$type}}));
2352: }
2353: my @jsarray = ();
2354: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2355: push(@jsarray,$ordered{$type}{$item});
2356: }
2357: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2358: }
2359: return <<"ENDSCRIPT";
2360: <script type="text/javascript">
2361: // <![CDATA[
1.160.6.46 raeburn 2362: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2363: var changedVal;
1.160.6.46 raeburn 2364: $jstext{'textbooks'};
2365: $jstext{'templates'};
2366: var newpos;
2367: var maxh;
2368: if (caller == 'textbooks') {
2369: newpos = 'textbooks_addbook_pos';
2370: maxh = 1 + $total{'textbooks'};
2371: } else {
2372: newpos = 'templates_addbook_pos';
2373: maxh = 1 + $total{'templates'};
2374: }
1.160.6.30 raeburn 2375: var current = new Array;
2376: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2377: if (item == newpos) {
2378: changedVal = newitemVal;
2379: } else {
2380: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2381: current[newitemVal] = newpos;
2382: }
1.160.6.46 raeburn 2383: if (caller == 'textbooks') {
2384: for (var i=0; i<textbooks.length; i++) {
2385: var elementName = 'textbooks_'+textbooks[i];
2386: if (elementName != item) {
2387: if (form.elements[elementName]) {
2388: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2389: current[currVal] = elementName;
2390: }
2391: }
2392: }
2393: }
2394: if (caller == 'templates') {
2395: for (var i=0; i<templates.length; i++) {
2396: var elementName = 'templates_'+templates[i];
2397: if (elementName != item) {
2398: if (form.elements[elementName]) {
2399: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2400: current[currVal] = elementName;
2401: }
1.160.6.30 raeburn 2402: }
2403: }
2404: }
2405: var oldVal;
2406: for (var j=0; j<maxh; j++) {
2407: if (current[j] == undefined) {
2408: oldVal = j;
2409: }
2410: }
2411: if (oldVal < changedVal) {
2412: for (var k=oldVal+1; k<=changedVal ; k++) {
2413: var elementName = current[k];
2414: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2415: }
2416: } else {
2417: for (var k=changedVal; k<oldVal; k++) {
2418: var elementName = current[k];
2419: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2420: }
2421: }
2422: return;
2423: }
2424:
2425: // ]]>
2426: </script>
2427:
2428: ENDSCRIPT
2429: }
2430:
1.3 raeburn 2431: sub print_autoenroll {
1.30 raeburn 2432: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2433: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2434: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2435: if (ref($settings) eq 'HASH') {
2436: if (exists($settings->{'run'})) {
2437: if ($settings->{'run'} eq '0') {
2438: $runoff = ' checked="checked" ';
2439: $runon = ' ';
2440: } else {
2441: $runon = ' checked="checked" ';
2442: $runoff = ' ';
2443: }
2444: } else {
2445: if ($autorun) {
2446: $runon = ' checked="checked" ';
2447: $runoff = ' ';
2448: } else {
2449: $runoff = ' checked="checked" ';
2450: $runon = ' ';
2451: }
2452: }
1.129 raeburn 2453: if (exists($settings->{'co-owners'})) {
2454: if ($settings->{'co-owners'} eq '0') {
2455: $coownersoff = ' checked="checked" ';
2456: $coownerson = ' ';
2457: } else {
2458: $coownerson = ' checked="checked" ';
2459: $coownersoff = ' ';
2460: }
2461: } else {
2462: $coownersoff = ' checked="checked" ';
2463: $coownerson = ' ';
2464: }
1.3 raeburn 2465: if (exists($settings->{'sender_domain'})) {
2466: $defdom = $settings->{'sender_domain'};
2467: }
1.160.6.68 raeburn 2468: if (exists($settings->{'autofailsafe'})) {
2469: $failsafe = $settings->{'autofailsafe'};
2470: }
1.14 raeburn 2471: } else {
2472: if ($autorun) {
2473: $runon = ' checked="checked" ';
2474: $runoff = ' ';
2475: } else {
2476: $runoff = ' checked="checked" ';
2477: $runon = ' ';
2478: }
1.3 raeburn 2479: }
2480: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2481: my $notif_sender;
2482: if (ref($settings) eq 'HASH') {
2483: $notif_sender = $settings->{'sender_uname'};
2484: }
1.3 raeburn 2485: my $datatable='<tr class="LC_odd_row">'.
2486: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2487: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2488: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2489: $runon.' value="1" />'.&mt('Yes').'</label> '.
2490: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2491: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2492: '</tr><tr>'.
2493: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2494: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2495: &mt('username').': '.
2496: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2497: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2498: ': '.$domform.'</span></td></tr>'.
2499: '<tr class="LC_odd_row">'.
2500: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2501: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2502: '<input type="radio" name="autoassign_coowners"'.
2503: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2504: '<label><input type="radio" name="autoassign_coowners"'.
2505: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2506: '</tr><tr>'.
2507: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2508: '<td class="LC_right_item"><span class="LC_nobreak">'.
2509: '<input type="text" name="autoenroll_failsafe"'.
2510: ' value="'.$failsafe.'" size="4" /></td></tr>';
2511: $$rowtotal += 4;
1.3 raeburn 2512: return $datatable;
2513: }
2514:
2515: sub print_autoupdate {
1.30 raeburn 2516: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2517: my $datatable;
2518: if ($position eq 'top') {
2519: my $updateon = ' ';
2520: my $updateoff = ' checked="checked" ';
2521: my $classlistson = ' ';
2522: my $classlistsoff = ' checked="checked" ';
2523: if (ref($settings) eq 'HASH') {
2524: if ($settings->{'run'} eq '1') {
2525: $updateon = $updateoff;
2526: $updateoff = ' ';
2527: }
2528: if ($settings->{'classlists'} eq '1') {
2529: $classlistson = $classlistsoff;
2530: $classlistsoff = ' ';
2531: }
2532: }
2533: my %title = (
2534: run => 'Auto-update active?',
2535: classlists => 'Update information in classlists?',
2536: );
2537: $datatable = '<tr class="LC_odd_row">'.
2538: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2539: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2540: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2541: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2542: '<label><input type="radio" name="autoupdate_run"'.
2543: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2544: '</tr><tr>'.
2545: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2546: '<td class="LC_right_item"><span class="LC_nobreak">'.
2547: '<label><input type="radio" name="classlists"'.
2548: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2549: '<label><input type="radio" name="classlists"'.
2550: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2551: '</tr>';
1.30 raeburn 2552: $$rowtotal += 2;
1.131 raeburn 2553: } elsif ($position eq 'middle') {
2554: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2555: my $numinrow = 3;
2556: my $locknamesettings;
2557: $datatable .= &insttypes_row($settings,$types,$usertypes,
2558: $dom,$numinrow,$othertitle,
2559: 'lockablenames');
2560: $$rowtotal ++;
1.3 raeburn 2561: } else {
1.44 raeburn 2562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2563: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2564: 'permanentemail','id');
1.33 raeburn 2565: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2566: my $numrows = 0;
1.26 raeburn 2567: if (ref($types) eq 'ARRAY') {
2568: if (@{$types} > 0) {
2569: $datatable =
2570: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2571: \@fields,$types,\$numrows);
1.30 raeburn 2572: $$rowtotal += @{$types};
1.26 raeburn 2573: }
1.3 raeburn 2574: }
2575: $datatable .=
2576: &usertype_update_row($settings,{'default' => $othertitle},
2577: \%fieldtitles,\@fields,['default'],
2578: \$numrows);
1.30 raeburn 2579: $$rowtotal ++;
1.3 raeburn 2580: }
2581: return $datatable;
2582: }
2583:
1.125 raeburn 2584: sub print_autocreate {
2585: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2586: my (%createon,%createoff,%currhash);
1.125 raeburn 2587: my @types = ('xml','req');
2588: if (ref($settings) eq 'HASH') {
2589: foreach my $item (@types) {
2590: $createoff{$item} = ' checked="checked" ';
2591: $createon{$item} = ' ';
2592: if (exists($settings->{$item})) {
2593: if ($settings->{$item}) {
2594: $createon{$item} = ' checked="checked" ';
2595: $createoff{$item} = ' ';
2596: }
2597: }
2598: }
1.160.6.16 raeburn 2599: if ($settings->{'xmldc'} ne '') {
2600: $currhash{$settings->{'xmldc'}} = 1;
2601: }
1.125 raeburn 2602: } else {
2603: foreach my $item (@types) {
2604: $createoff{$item} = ' checked="checked" ';
2605: $createon{$item} = ' ';
2606: }
2607: }
2608: $$rowtotal += 2;
1.160.6.16 raeburn 2609: my $numinrow = 2;
1.125 raeburn 2610: my $datatable='<tr class="LC_odd_row">'.
2611: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2612: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2613: '<input type="radio" name="autocreate_xml"'.
2614: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2615: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2616: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2617: '</td></tr><tr>'.
2618: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2619: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2620: '<input type="radio" name="autocreate_req"'.
2621: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2622: '<label><input type="radio" name="autocreate_req"'.
2623: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2624: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2625: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2626: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2627: if ($numdc > 1) {
1.160.6.50 raeburn 2628: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2629: '</td><td class="LC_left_item">';
1.125 raeburn 2630: } else {
1.160.6.50 raeburn 2631: $datatable .= &mt('Course creation processed as:').
2632: '</td><td class="LC_right_item">';
1.125 raeburn 2633: }
1.160.6.50 raeburn 2634: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2635: $$rowtotal += $rows;
1.125 raeburn 2636: return $datatable;
2637: }
2638:
1.23 raeburn 2639: sub print_directorysrch {
1.160.6.72 raeburn 2640: my ($position,$dom,$settings,$rowtotal) = @_;
2641: my $datatable;
2642: if ($position eq 'top') {
2643: my $instsrchon = ' ';
2644: my $instsrchoff = ' checked="checked" ';
2645: my ($exacton,$containson,$beginson);
2646: my $instlocalon = ' ';
2647: my $instlocaloff = ' checked="checked" ';
2648: if (ref($settings) eq 'HASH') {
2649: if ($settings->{'available'} eq '1') {
2650: $instsrchon = $instsrchoff;
2651: $instsrchoff = ' ';
2652: }
2653: if ($settings->{'localonly'} eq '1') {
2654: $instlocalon = $instlocaloff;
2655: $instlocaloff = ' ';
2656: }
2657: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2658: foreach my $type (@{$settings->{'searchtypes'}}) {
2659: if ($type eq 'exact') {
2660: $exacton = ' checked="checked" ';
2661: } elsif ($type eq 'contains') {
2662: $containson = ' checked="checked" ';
2663: } elsif ($type eq 'begins') {
2664: $beginson = ' checked="checked" ';
2665: }
2666: }
2667: } else {
2668: if ($settings->{'searchtypes'} eq 'exact') {
2669: $exacton = ' checked="checked" ';
2670: } elsif ($settings->{'searchtypes'} eq 'contains') {
2671: $containson = ' checked="checked" ';
2672: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2673: $exacton = ' checked="checked" ';
2674: $containson = ' checked="checked" ';
2675: }
2676: }
1.23 raeburn 2677: }
1.160.6.72 raeburn 2678: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2679: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2680:
1.160.6.72 raeburn 2681: my $numinrow = 4;
2682: my $cansrchrow = 0;
2683: $datatable='<tr class="LC_odd_row">'.
2684: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2685: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2686: '<input type="radio" name="dirsrch_available"'.
2687: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2688: '<label><input type="radio" name="dirsrch_available"'.
2689: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2690: '</tr><tr>'.
2691: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2692: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2693: '<input type="radio" name="dirsrch_instlocalonly"'.
2694: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2695: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2696: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2697: '</tr>';
2698: $$rowtotal += 2;
2699: if (ref($usertypes) eq 'HASH') {
2700: if (keys(%{$usertypes}) > 0) {
2701: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2702: $numinrow,$othertitle,'cansearch');
2703: $cansrchrow = 1;
2704: }
1.26 raeburn 2705: }
1.160.6.72 raeburn 2706: if ($cansrchrow) {
2707: $$rowtotal ++;
2708: $datatable .= '<tr>';
2709: } else {
2710: $datatable .= '<tr class="LC_odd_row">';
2711: }
2712: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2713: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2714: foreach my $title (@{$titleorder}) {
2715: if (defined($searchtitles->{$title})) {
2716: my $check = ' ';
2717: if (ref($settings) eq 'HASH') {
2718: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2719: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2720: $check = ' checked="checked" ';
2721: }
1.39 raeburn 2722: }
1.25 raeburn 2723: }
1.160.6.72 raeburn 2724: $datatable .= '<td class="LC_left_item">'.
2725: '<span class="LC_nobreak"><label>'.
2726: '<input type="checkbox" name="searchby" '.
2727: 'value="'.$title.'"'.$check.'/>'.
2728: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2729: }
2730: }
1.160.6.72 raeburn 2731: $datatable .= '</tr></table></td></tr>';
2732: $$rowtotal ++;
2733: if ($cansrchrow) {
2734: $datatable .= '<tr class="LC_odd_row">';
2735: } else {
2736: $datatable .= '<tr>';
2737: }
2738: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2739: '<td class="LC_left_item" colspan="2">'.
2740: '<span class="LC_nobreak"><label>'.
2741: '<input type="checkbox" name="searchtypes" '.
2742: $exacton.' value="exact" />'.&mt('Exact match').
2743: '</label> '.
2744: '<label><input type="checkbox" name="searchtypes" '.
2745: $beginson.' value="begins" />'.&mt('Begins with').
2746: '</label> '.
2747: '<label><input type="checkbox" name="searchtypes" '.
2748: $containson.' value="contains" />'.&mt('Contains').
2749: '</label></span></td></tr>';
2750: $$rowtotal ++;
1.26 raeburn 2751: } else {
1.160.6.72 raeburn 2752: my $domsrchon = ' checked="checked" ';
2753: my $domsrchoff = ' ';
2754: my $domlocalon = ' ';
2755: my $domlocaloff = ' checked="checked" ';
2756: if (ref($settings) eq 'HASH') {
2757: if ($settings->{'lclocalonly'} eq '1') {
2758: $domlocalon = $domlocaloff;
2759: $domlocaloff = ' ';
2760: }
2761: if ($settings->{'lcavailable'} eq '0') {
2762: $domsrchoff = $domsrchon;
2763: $domsrchon = ' ';
2764: }
2765: }
2766: $datatable='<tr class="LC_odd_row">'.
2767: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2768: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2769: '<input type="radio" name="dirsrch_domavailable"'.
2770: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2771: '<label><input type="radio" name="dirsrch_domavailable"'.
2772: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2773: '</tr><tr>'.
2774: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2775: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2776: '<input type="radio" name="dirsrch_domlocalonly"'.
2777: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2778: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2779: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2780: '</tr>';
2781: $$rowtotal += 2;
1.26 raeburn 2782: }
1.25 raeburn 2783: return $datatable;
2784: }
2785:
1.28 raeburn 2786: sub print_contacts {
1.30 raeburn 2787: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2788: my $datatable;
2789: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2790: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2791: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2792: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2793: foreach my $type (@mailings) {
2794: $otheremails{$type} = '';
2795: }
1.134 raeburn 2796: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2797: if (ref($settings) eq 'HASH') {
2798: foreach my $item (@contacts) {
2799: if (exists($settings->{$item})) {
2800: $to{$item} = $settings->{$item};
2801: }
2802: }
2803: foreach my $type (@mailings) {
2804: if (exists($settings->{$type})) {
2805: if (ref($settings->{$type}) eq 'HASH') {
2806: foreach my $item (@contacts) {
2807: if ($settings->{$type}{$item}) {
2808: $checked{$type}{$item} = ' checked="checked" ';
2809: }
2810: }
2811: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2812: if ($type eq 'helpdeskmail') {
2813: $bccemails{$type} = $settings->{$type}{'bcc'};
2814: }
1.28 raeburn 2815: }
1.89 raeburn 2816: } elsif ($type eq 'lonstatusmail') {
2817: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2818: }
2819: }
2820: } else {
2821: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2822: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2823: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2824: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2825: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2826: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2827: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2828: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2829: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2830: }
2831: my ($titles,$short_titles) = &contact_titles();
2832: my $rownum = 0;
2833: my $css_class;
2834: foreach my $item (@contacts) {
1.69 raeburn 2835: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2836: $datatable .= '<tr'.$css_class.'>'.
2837: '<td><span class="LC_nobreak">'.$titles->{$item}.
2838: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2839: '<input type="text" name="'.$item.'" value="'.
2840: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2841: $rownum ++;
1.28 raeburn 2842: }
2843: foreach my $type (@mailings) {
1.69 raeburn 2844: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2845: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2846: '<td><span class="LC_nobreak">'.
2847: $titles->{$type}.': </span></td>'.
1.28 raeburn 2848: '<td class="LC_left_item">'.
2849: '<span class="LC_nobreak">';
2850: foreach my $item (@contacts) {
2851: $datatable .= '<label>'.
2852: '<input type="checkbox" name="'.$type.'"'.
2853: $checked{$type}{$item}.
2854: ' value="'.$item.'" />'.$short_titles->{$item}.
2855: '</label> ';
2856: }
2857: $datatable .= '</span><br />'.&mt('Others').': '.
2858: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2859: 'value="'.$otheremails{$type}.'" />';
2860: if ($type eq 'helpdeskmail') {
1.136 raeburn 2861: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2862: '<input type="text" name="'.$type.'_bcc" '.
2863: 'value="'.$bccemails{$type}.'" />';
2864: }
2865: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2866: $rownum ++;
1.28 raeburn 2867: }
1.160.6.23 raeburn 2868: my %choices;
2869: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2870: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2871: &mt('LON-CAPA core group - MSU'),600,500));
2872: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2873: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2874: &mt('LON-CAPA core group - MSU'),600,500));
2875: my @toggles = ('reporterrors','reportupdates');
2876: my %defaultchecked = ('reporterrors' => 'on',
2877: 'reportupdates' => 'on');
2878: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2879: \%choices,$rownum);
2880: $datatable .= $reports;
1.30 raeburn 2881: $$rowtotal += $rownum;
1.28 raeburn 2882: return $datatable;
2883: }
2884:
1.118 jms 2885: sub print_helpsettings {
1.160.6.73! raeburn 2886: my ($position,$dom,$settings,$rowtotal) = @_;
! 2887: my $confname = $dom.'-domainconfig';
1.160.6.5 raeburn 2888: my ($datatable,$itemcount);
1.160.6.73! raeburn 2889: if ($position eq 'top') {
! 2890: $itemcount = 1;
! 2891: my (%choices,%defaultchecked,@toggles);
! 2892: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
! 2893: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
! 2894: &mt('LON-CAPA bug tracker'),600,500));
! 2895: %defaultchecked = ('submitbugs' => 'on');
! 2896: @toggles = ('submitbugs');
! 2897: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
! 2898: \%choices,$itemcount);
! 2899: $$rowtotal ++;
! 2900: } else {
! 2901: my $css_class;
! 2902: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
! 2903: my %customroles;
! 2904: foreach my $key (keys(%existing)) {
! 2905: if ($key=~/^rolesdef\_(\w+)$/) {
! 2906: my $rolename = $1;
! 2907: my %privs;
! 2908: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
! 2909: $customroles{$rolename} = \%privs;
! 2910: }
! 2911: }
! 2912: my $count = 0;
! 2913: my $context = 'domprefs';
! 2914: my $crstype = 'Course';
! 2915: foreach my $role (sort(keys(%customroles))) {
! 2916: my $prefix = 'custhelp'.$count;
! 2917: my %full=();
! 2918: my %levels= (
! 2919: course => {},
! 2920: domain => {},
! 2921: system => {},
! 2922: );
! 2923: my %levelscurrent=(
! 2924: course => {},
! 2925: domain => {},
! 2926: system => {},
! 2927: );
! 2928: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
! 2929: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
! 2930: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 2931: $datatable .= '<tr '.$css_class.'><td><label>'.
! 2932: '<input type="checkbox" name="modifycusthelp" value="'.$count.'" />'.
! 2933: '<input type="hidden" name="custhelprole'.$count.'" value="'.$role.'" />'.
! 2934: &mt('Modify').'</label></td>'.
! 2935: '<td>'.&mt('Existing helpdesk role:').' '.
! 2936: '<b>'.$role.'</b><br />'.
! 2937: &Apache::lonuserutils::custom_role_header($context,$crstype,
! 2938: \@templateroles,$prefix).
! 2939: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
! 2940: \%levelscurrent,$prefix).
! 2941: '<br /></td>';
! 2942: $count ++;
! 2943: $itemcount ++;
! 2944: }
! 2945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 2946: my $newcust = 'custhelp'.$count;
! 2947: my (%privs,%levelscurrent);
! 2948: my %full=();
! 2949: my %levels= (
! 2950: course => {},
! 2951: domain => {},
! 2952: system => {},
! 2953: );
! 2954: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
! 2955: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
! 2956: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><label>'.
! 2957: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
! 2958: '</label></span></td>'.
! 2959: '<td><span class="LC_nobreak">'.
! 2960: '<b>'.&mt('Name of new helpdesk role:').'</b> '.
! 2961: '<input type="text" size="20" name="newcusthelpname" value="" />'.
! 2962: '</span><br />'.
! 2963: &Apache::lonuserutils::custom_role_header($context,$crstype,
! 2964: \@templateroles,$newcust).
! 2965: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
! 2966: \%levelscurrent,$newcust).
! 2967: '<br /><br />'.
! 2968: '</td></tr>';
! 2969: $count ++;
! 2970: $$rowtotal += $count;
! 2971: }
1.160.6.5 raeburn 2972: return $datatable;
1.121 raeburn 2973: }
2974:
2975: sub radiobutton_prefs {
1.160.6.16 raeburn 2976: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2977: $additional,$align) = @_;
1.121 raeburn 2978: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2979: (ref($choices) eq 'HASH'));
2980:
2981: my (%checkedon,%checkedoff,$datatable,$css_class);
2982:
2983: foreach my $item (@{$toggles}) {
2984: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2985: $checkedon{$item} = ' checked="checked" ';
2986: $checkedoff{$item} = ' ';
1.121 raeburn 2987: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2988: $checkedoff{$item} = ' checked="checked" ';
2989: $checkedon{$item} = ' ';
2990: }
2991: }
2992: if (ref($settings) eq 'HASH') {
1.121 raeburn 2993: foreach my $item (@{$toggles}) {
1.118 jms 2994: if ($settings->{$item} eq '1') {
2995: $checkedon{$item} = ' checked="checked" ';
2996: $checkedoff{$item} = ' ';
2997: } elsif ($settings->{$item} eq '0') {
2998: $checkedoff{$item} = ' checked="checked" ';
2999: $checkedon{$item} = ' ';
3000: }
3001: }
1.121 raeburn 3002: }
1.160.6.16 raeburn 3003: if ($onclick) {
3004: $onclick = ' onclick="'.$onclick.'"';
3005: }
1.121 raeburn 3006: foreach my $item (@{$toggles}) {
1.118 jms 3007: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3008: $datatable .=
1.160.6.16 raeburn 3009: '<tr'.$css_class.'><td valign="top">'.
3010: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3011: '</span></td>';
3012: if ($align eq 'left') {
3013: $datatable .= '<td class="LC_left_item">';
3014: } else {
3015: $datatable .= '<td class="LC_right_item">';
3016: }
3017: $datatable .=
3018: '<span class="LC_nobreak">'.
1.118 jms 3019: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3020: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3021: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3022: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3023: '</span>'.$additional.
3024: '</td>'.
1.118 jms 3025: '</tr>';
3026: $itemcount ++;
1.121 raeburn 3027: }
3028: return ($datatable,$itemcount);
3029: }
3030:
3031: sub print_coursedefaults {
1.139 raeburn 3032: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3033: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3034: my $itemcount = 1;
1.160.6.16 raeburn 3035: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3036: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3037: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3038: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3039: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3040: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3041: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3042: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3043: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3044: );
1.160.6.21 raeburn 3045: my %staticdefaults = (
3046: anonsurvey_threshold => 10,
3047: uploadquota => 500,
1.160.6.57 raeburn 3048: postsubmit => 60,
1.160.6.70 raeburn 3049: mysqltables => 172800,
1.160.6.21 raeburn 3050: );
1.139 raeburn 3051: if ($position eq 'top') {
1.160.6.57 raeburn 3052: %defaultchecked = (
3053: 'uselcmath' => 'on',
3054: 'usejsme' => 'on',
1.160.6.64 raeburn 3055: 'canclone' => 'none',
1.160.6.57 raeburn 3056: );
3057: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3058: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3059: \%choices,$itemcount);
1.160.6.64 raeburn 3060: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3061: $datatable .=
3062: '<tr'.$css_class.'><td valign="top">'.
3063: '<span class="LC_nobreak">'.$choices{'canclone'}.
3064: '</span></td><td class="LC_left_item">';
3065: my $currcanclone = 'none';
3066: my $onclick;
3067: my @cloneoptions = ('none','domain');
3068: my %clonetitles = (
3069: none => 'No additional course requesters',
3070: domain => "Any course requester in course's domain",
3071: instcode => 'Course requests for official courses ...',
3072: );
3073: my (%codedefaults,@code_order,@posscodes);
3074: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3075: \@code_order) eq 'ok') {
3076: if (@code_order > 0) {
3077: push(@cloneoptions,'instcode');
3078: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3079: }
3080: }
3081: if (ref($settings) eq 'HASH') {
3082: if ($settings->{'canclone'}) {
3083: if (ref($settings->{'canclone'}) eq 'HASH') {
3084: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3085: if (@code_order > 0) {
3086: $currcanclone = 'instcode';
3087: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3088: }
3089: }
3090: } elsif ($settings->{'canclone'} eq 'domain') {
3091: $currcanclone = $settings->{'canclone'};
3092: }
3093: }
3094: }
3095: foreach my $option (@cloneoptions) {
3096: my ($checked,$additional);
3097: if ($currcanclone eq $option) {
3098: $checked = ' checked="checked"';
3099: }
3100: if ($option eq 'instcode') {
3101: if (@code_order) {
3102: my $show = 'none';
3103: if ($checked) {
3104: $show = 'block';
3105: }
3106: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3107: &mt('Institutional codes for new and cloned course have identical:').
3108: '<br />';
3109: foreach my $item (@code_order) {
3110: my $codechk;
3111: if ($checked) {
3112: if (grep(/^\Q$item\E$/,@posscodes)) {
3113: $codechk = ' checked="checked"';
3114: }
3115: }
3116: $additional .= '<label>'.
3117: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3118: $item.'</label>';
3119: }
3120: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3121: }
3122: }
3123: $datatable .=
3124: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3125: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3126: '</label> '.$additional.'</span><br />';
3127: }
3128: $datatable .= '</td>'.
3129: '</tr>';
3130: $itemcount ++;
1.139 raeburn 3131: } else {
3132: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3133: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3134: my $currusecredits = 0;
1.160.6.57 raeburn 3135: my $postsubmitclient = 1;
1.160.6.30 raeburn 3136: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3137: if (ref($settings) eq 'HASH') {
3138: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3139: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3140: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3141: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3142: }
3143: }
1.160.6.16 raeburn 3144: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3145: foreach my $type (@types) {
3146: next if ($type eq 'community');
3147: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3148: if ($defcredits{$type} ne '') {
3149: $currusecredits = 1;
3150: }
3151: }
3152: }
3153: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3154: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3155: $postsubmitclient = 0;
3156: foreach my $type (@types) {
3157: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3158: }
3159: } else {
3160: foreach my $type (@types) {
3161: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3162: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3163: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3164: } else {
3165: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3166: }
3167: } else {
3168: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3169: }
3170: }
3171: }
3172: } else {
3173: foreach my $type (@types) {
3174: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3175: }
3176: }
1.160.6.70 raeburn 3177: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3178: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3179: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3180: }
3181: } else {
3182: foreach my $type (@types) {
3183: $currmysql{$type} = $staticdefaults{'mysqltables'};
3184: }
3185: }
1.160.6.58 raeburn 3186: } else {
3187: foreach my $type (@types) {
3188: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3189: }
1.139 raeburn 3190: }
3191: if (!$currdefresponder) {
1.160.6.21 raeburn 3192: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3193: } elsif ($currdefresponder < 1) {
3194: $currdefresponder = 1;
3195: }
1.160.6.21 raeburn 3196: foreach my $type (@types) {
3197: if ($curruploadquota{$type} eq '') {
3198: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3199: }
3200: }
1.139 raeburn 3201: $datatable .=
1.160.6.16 raeburn 3202: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3203: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3204: '</span></td>'.
3205: '<td class="LC_right_item"><span class="LC_nobreak">'.
3206: '<input type="text" name="anonsurvey_threshold"'.
3207: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3208: '</td></tr>'."\n";
3209: $itemcount ++;
3210: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3211: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3212: $choices{'uploadquota'}.
3213: '</span></td>'.
3214: '<td align="right" class="LC_right_item">'.
3215: '<table><tr>';
1.160.6.21 raeburn 3216: foreach my $type (@types) {
3217: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3218: '<input type="text" name="uploadquota_'.$type.'"'.
3219: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3220: }
3221: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3222: $itemcount ++;
1.160.6.40 raeburn 3223: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3224: my $display = 'none';
3225: if ($currusecredits) {
3226: $display = 'block';
3227: }
3228: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3229: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3230: foreach my $type (@types) {
3231: next if ($type eq 'community');
3232: $additional .= '<td align="center">'.&mt($type).'<br />'.
3233: '<input type="text" name="'.$type.'_credits"'.
3234: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3235: }
3236: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3237: %defaultchecked = ('coursecredits' => 'off');
3238: @toggles = ('coursecredits');
3239: my $current = {
3240: 'coursecredits' => $currusecredits,
3241: };
3242: (my $table,$itemcount) =
3243: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3244: \%choices,$itemcount,$onclick,$additional,'left');
3245: $datatable .= $table;
3246: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3247: my $display = 'none';
3248: if ($postsubmitclient) {
3249: $display = 'block';
3250: }
3251: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3252: &mt('Number of seconds submit is disabled').'<br />'.
3253: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3254: '<table><tr>';
1.160.6.57 raeburn 3255: foreach my $type (@types) {
3256: $additional .= '<td align="center">'.&mt($type).'<br />'.
3257: '<input type="text" name="'.$type.'_timeout" value="'.
3258: $deftimeout{$type}.'" size="5" /></td>';
3259: }
3260: $additional .= '</tr></table></div>'."\n";
3261: %defaultchecked = ('postsubmit' => 'on');
3262: @toggles = ('postsubmit');
1.160.6.70 raeburn 3263: $current = {
3264: 'postsubmit' => $postsubmitclient,
3265: };
1.160.6.57 raeburn 3266: ($table,$itemcount) =
3267: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3268: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3269: $datatable .= $table;
1.160.6.70 raeburn 3270: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3271: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3272: $choices{'mysqltables'}.
3273: '</span></td>'.
3274: '<td align="right" class="LC_right_item">'.
3275: '<table><tr>';
3276: foreach my $type (@types) {
3277: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3278: '<input type="text" name="mysqltables_'.$type.'"'.
3279: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3280: }
3281: $datatable .= '</tr></table></td></tr>'."\n";
3282: $itemcount ++;
3283:
1.160.6.37 raeburn 3284: }
3285: $$rowtotal += $itemcount;
3286: return $datatable;
3287: }
3288:
3289: sub print_selfenrollment {
3290: my ($position,$dom,$settings,$rowtotal) = @_;
3291: my ($css_class,$datatable);
3292: my $itemcount = 1;
3293: my @types = ('official','unofficial','community','textbook');
3294: if (($position eq 'top') || ($position eq 'middle')) {
3295: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3296: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3297: my @rows;
3298: my $key;
3299: if ($position eq 'top') {
3300: $key = 'admin';
3301: if (ref($rowsref) eq 'ARRAY') {
3302: @rows = @{$rowsref};
3303: }
3304: } elsif ($position eq 'middle') {
3305: $key = 'default';
3306: @rows = ('types','registered','approval','limit');
3307: }
3308: foreach my $row (@rows) {
3309: if (defined($titlesref->{$row})) {
3310: $itemcount ++;
3311: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3312: $datatable .= '<tr'.$css_class.'>'.
3313: '<td>'.$titlesref->{$row}.'</td>'.
3314: '<td class="LC_left_item">'.
3315: '<table><tr>';
3316: my (%current,%currentcap);
3317: if (ref($settings) eq 'HASH') {
3318: if (ref($settings->{$key}) eq 'HASH') {
3319: foreach my $type (@types) {
3320: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3321: $current{$type} = $settings->{$key}->{$type}->{$row};
3322: }
3323: if (($row eq 'limit') && ($key eq 'default')) {
3324: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3325: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3326: }
3327: }
3328: }
3329: }
3330: }
3331: my %roles = (
3332: '0' => &Apache::lonnet::plaintext('dc'),
3333: );
3334:
3335: foreach my $type (@types) {
3336: unless (($row eq 'registered') && ($key eq 'default')) {
3337: $datatable .= '<th>'.&mt($type).'</th>';
3338: }
3339: }
3340: unless (($row eq 'registered') && ($key eq 'default')) {
3341: $datatable .= '</tr><tr>';
3342: }
3343: foreach my $type (@types) {
3344: if ($type eq 'community') {
3345: $roles{'1'} = &mt('Community personnel');
3346: } else {
3347: $roles{'1'} = &mt('Course personnel');
3348: }
3349: $datatable .= '<td style="vertical-align: top">';
3350: if ($position eq 'top') {
3351: my %checked;
3352: if ($current{$type} eq '0') {
3353: $checked{'0'} = ' checked="checked"';
3354: } else {
3355: $checked{'1'} = ' checked="checked"';
3356: }
3357: foreach my $role ('1','0') {
3358: $datatable .= '<span class="LC_nobreak"><label>'.
3359: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3360: 'value="'.$role.'"'.$checked{$role}.' />'.
3361: $roles{$role}.'</label></span> ';
3362: }
3363: } else {
3364: if ($row eq 'types') {
3365: my %checked;
3366: if ($current{$type} =~ /^(all|dom)$/) {
3367: $checked{$1} = ' checked="checked"';
3368: } else {
3369: $checked{''} = ' checked="checked"';
3370: }
3371: foreach my $val ('','dom','all') {
3372: $datatable .= '<span class="LC_nobreak"><label>'.
3373: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3374: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3375: }
3376: } elsif ($row eq 'registered') {
3377: my %checked;
3378: if ($current{$type} eq '1') {
3379: $checked{'1'} = ' checked="checked"';
3380: } else {
3381: $checked{'0'} = ' checked="checked"';
3382: }
3383: foreach my $val ('0','1') {
3384: $datatable .= '<span class="LC_nobreak"><label>'.
3385: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3386: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3387: }
3388: } elsif ($row eq 'approval') {
3389: my %checked;
3390: if ($current{$type} =~ /^([12])$/) {
3391: $checked{$1} = ' checked="checked"';
3392: } else {
3393: $checked{'0'} = ' checked="checked"';
3394: }
3395: for my $val (0..2) {
3396: $datatable .= '<span class="LC_nobreak"><label>'.
3397: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3398: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3399: }
3400: } elsif ($row eq 'limit') {
3401: my %checked;
3402: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3403: $checked{$1} = ' checked="checked"';
3404: } else {
3405: $checked{'none'} = ' checked="checked"';
3406: }
3407: my $cap;
3408: if ($currentcap{$type} =~ /^\d+$/) {
3409: $cap = $currentcap{$type};
3410: }
3411: foreach my $val ('none','allstudents','selfenrolled') {
3412: $datatable .= '<span class="LC_nobreak"><label>'.
3413: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3414: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3415: }
3416: $datatable .= '<br />'.
3417: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3418: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3419: '</span>';
3420: }
3421: }
3422: $datatable .= '</td>';
3423: }
3424: $datatable .= '</tr>';
3425: }
3426: $datatable .= '</table></td></tr>';
3427: }
3428: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3429: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3430: }
3431: $$rowtotal += $itemcount;
3432: return $datatable;
3433: }
3434:
3435: sub print_validation_rows {
3436: my ($caller,$dom,$settings,$rowtotal) = @_;
3437: my ($itemsref,$namesref,$fieldsref);
3438: if ($caller eq 'selfenroll') {
3439: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3440: } elsif ($caller eq 'requestcourses') {
3441: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3442: }
3443: my %currvalidation;
3444: if (ref($settings) eq 'HASH') {
3445: if (ref($settings->{'validation'}) eq 'HASH') {
3446: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3447: }
1.160.6.39 raeburn 3448: }
3449: my $datatable;
3450: my $itemcount = 0;
3451: foreach my $item (@{$itemsref}) {
3452: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3453: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3454: $namesref->{$item}.
3455: '</span></td>'.
3456: '<td class="LC_left_item">';
3457: if (($item eq 'url') || ($item eq 'button')) {
3458: $datatable .= '<span class="LC_nobreak">'.
3459: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3460: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3461: } elsif ($item eq 'fields') {
3462: my @currfields;
3463: if (ref($currvalidation{$item}) eq 'ARRAY') {
3464: @currfields = @{$currvalidation{$item}};
3465: }
3466: foreach my $field (@{$fieldsref}) {
3467: my $check = '';
3468: if (grep(/^\Q$field\E$/,@currfields)) {
3469: $check = ' checked="checked"';
3470: }
3471: $datatable .= '<span class="LC_nobreak"><label>'.
3472: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3473: ' value="'.$field.'"'.$check.' />'.$field.
3474: '</label></span> ';
3475: }
3476: } elsif ($item eq 'markup') {
3477: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3478: $currvalidation{$item}.
1.160.6.37 raeburn 3479: '</textarea>';
1.160.6.39 raeburn 3480: }
3481: $datatable .= '</td></tr>'."\n";
3482: if (ref($rowtotal)) {
1.160.6.37 raeburn 3483: $itemcount ++;
3484: }
1.139 raeburn 3485: }
1.160.6.39 raeburn 3486: if ($caller eq 'requestcourses') {
3487: my %currhash;
1.160.6.51 raeburn 3488: if (ref($settings) eq 'HASH') {
3489: if (ref($settings->{'validation'}) eq 'HASH') {
3490: if ($settings->{'validation'}{'dc'} ne '') {
3491: $currhash{$settings->{'validation'}{'dc'}} = 1;
3492: }
1.160.6.39 raeburn 3493: }
3494: }
3495: my $numinrow = 2;
3496: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3497: 'validationdc',%currhash);
1.160.6.50 raeburn 3498: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3499: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3500: if ($numdc > 1) {
1.160.6.50 raeburn 3501: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3502: } else {
1.160.6.50 raeburn 3503: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3504: }
1.160.6.50 raeburn 3505: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3506: $itemcount ++;
3507: }
3508: if (ref($rowtotal)) {
3509: $$rowtotal += $itemcount;
3510: }
1.121 raeburn 3511: return $datatable;
1.118 jms 3512: }
3513:
1.137 raeburn 3514: sub print_usersessions {
3515: my ($position,$dom,$settings,$rowtotal) = @_;
3516: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3517: my (%by_ip,%by_location,@intdoms);
3518: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3519:
3520: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3521: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3522: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3523: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3524: my $itemcount = 1;
3525: if ($position eq 'top') {
1.152 raeburn 3526: if (keys(%serverhomes) > 1) {
1.145 raeburn 3527: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3528: my $curroffloadnow;
3529: if (ref($settings) eq 'HASH') {
3530: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3531: $curroffloadnow = $settings->{'offloadnow'};
3532: }
3533: }
3534: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3535: } else {
1.140 raeburn 3536: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3537: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3538: }
1.137 raeburn 3539: } else {
1.145 raeburn 3540: if (keys(%by_location) == 0) {
3541: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3542: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3543: } else {
3544: my %lt = &usersession_titles();
3545: my $numinrow = 5;
3546: my $prefix;
3547: my @types;
3548: if ($position eq 'bottom') {
3549: $prefix = 'remote';
3550: @types = ('version','excludedomain','includedomain');
3551: } else {
3552: $prefix = 'hosted';
3553: @types = ('excludedomain','includedomain');
3554: }
3555: my (%current,%checkedon,%checkedoff);
3556: my @lcversions = &Apache::lonnet::all_loncaparevs();
3557: my @locations = sort(keys(%by_location));
3558: foreach my $type (@types) {
3559: $checkedon{$type} = '';
3560: $checkedoff{$type} = ' checked="checked"';
3561: }
3562: if (ref($settings) eq 'HASH') {
3563: if (ref($settings->{$prefix}) eq 'HASH') {
3564: foreach my $key (keys(%{$settings->{$prefix}})) {
3565: $current{$key} = $settings->{$prefix}{$key};
3566: if ($key eq 'version') {
3567: if ($current{$key} ne '') {
3568: $checkedon{$key} = ' checked="checked"';
3569: $checkedoff{$key} = '';
3570: }
3571: } elsif (ref($current{$key}) eq 'ARRAY') {
3572: $checkedon{$key} = ' checked="checked"';
3573: $checkedoff{$key} = '';
3574: }
1.137 raeburn 3575: }
3576: }
3577: }
1.145 raeburn 3578: foreach my $type (@types) {
3579: next if ($type ne 'version' && !@locations);
3580: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3581: $datatable .= '<tr'.$css_class.'>
3582: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3583: <span class="LC_nobreak">
3584: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3585: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3586: if ($type eq 'version') {
3587: my $selector = '<select name="'.$prefix.'_version">';
3588: foreach my $version (@lcversions) {
3589: my $selected = '';
3590: if ($current{'version'} eq $version) {
3591: $selected = ' selected="selected"';
3592: }
3593: $selector .= ' <option value="'.$version.'"'.
3594: $selected.'>'.$version.'</option>';
3595: }
3596: $selector .= '</select> ';
3597: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3598: } else {
3599: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3600: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3601: ' />'.(' 'x2).
3602: '<input type="button" value="'.&mt('uncheck all').'" '.
3603: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3604: "\n".
3605: '</div><div><table>';
3606: my $rem;
3607: for (my $i=0; $i<@locations; $i++) {
3608: my ($showloc,$value,$checkedtype);
3609: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3610: my $ip = $by_location{$locations[$i]}->[0];
3611: if (ref($by_ip{$ip}) eq 'ARRAY') {
3612: $value = join(':',@{$by_ip{$ip}});
3613: $showloc = join(', ',@{$by_ip{$ip}});
3614: if (ref($current{$type}) eq 'ARRAY') {
3615: foreach my $loc (@{$by_ip{$ip}}) {
3616: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3617: $checkedtype = ' checked="checked"';
3618: last;
3619: }
3620: }
1.138 raeburn 3621: }
3622: }
3623: }
1.145 raeburn 3624: $rem = $i%($numinrow);
3625: if ($rem == 0) {
3626: if ($i > 0) {
3627: $datatable .= '</tr>';
3628: }
3629: $datatable .= '<tr>';
3630: }
3631: $datatable .= '<td class="LC_left_item">'.
3632: '<span class="LC_nobreak"><label>'.
3633: '<input type="checkbox" name="'.$prefix.'_'.$type.
3634: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3635: '</label></span></td>';
1.137 raeburn 3636: }
1.145 raeburn 3637: $rem = @locations%($numinrow);
3638: my $colsleft = $numinrow - $rem;
3639: if ($colsleft > 1 ) {
3640: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3641: ' </td>';
3642: } elsif ($colsleft == 1) {
3643: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3644: }
1.145 raeburn 3645: $datatable .= '</tr></table>';
1.137 raeburn 3646: }
1.145 raeburn 3647: $datatable .= '</td></tr>';
3648: $itemcount ++;
1.137 raeburn 3649: }
3650: }
3651: }
3652: $$rowtotal += $itemcount;
3653: return $datatable;
3654: }
3655:
1.138 raeburn 3656: sub build_location_hashes {
3657: my ($intdoms,$by_ip,$by_location) = @_;
3658: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3659: (ref($by_location) eq 'HASH'));
3660: my %iphost = &Apache::lonnet::get_iphost();
3661: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3662: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3663: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3664: foreach my $id (@{$iphost{$primary_ip}}) {
3665: my $intdom = &Apache::lonnet::internet_dom($id);
3666: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3667: push(@{$intdoms},$intdom);
3668: }
3669: }
3670: }
3671: foreach my $ip (keys(%iphost)) {
3672: if (ref($iphost{$ip}) eq 'ARRAY') {
3673: foreach my $id (@{$iphost{$ip}}) {
3674: my $location = &Apache::lonnet::internet_dom($id);
3675: if ($location) {
3676: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3677: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3678: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3679: push(@{$by_ip->{$ip}},$location);
3680: }
3681: } else {
3682: $by_ip->{$ip} = [$location];
3683: }
3684: }
3685: }
3686: }
3687: }
3688: foreach my $ip (sort(keys(%{$by_ip}))) {
3689: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3690: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3691: my $first = $by_ip->{$ip}->[0];
3692: if (ref($by_location->{$first}) eq 'ARRAY') {
3693: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3694: push(@{$by_location->{$first}},$ip);
3695: }
3696: } else {
3697: $by_location->{$first} = [$ip];
3698: }
3699: }
3700: }
3701: return;
3702: }
3703:
1.145 raeburn 3704: sub current_offloads_to {
3705: my ($dom,$settings,$servers) = @_;
3706: my (%spareid,%otherdomconfigs);
1.152 raeburn 3707: if (ref($servers) eq 'HASH') {
1.145 raeburn 3708: foreach my $lonhost (sort(keys(%{$servers}))) {
3709: my $gotspares;
1.152 raeburn 3710: if (ref($settings) eq 'HASH') {
3711: if (ref($settings->{'spares'}) eq 'HASH') {
3712: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3713: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3714: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3715: $gotspares = 1;
3716: }
1.145 raeburn 3717: }
3718: }
3719: unless ($gotspares) {
3720: my $gotspares;
3721: my $serverhomeID =
3722: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3723: my $serverhomedom =
3724: &Apache::lonnet::host_domain($serverhomeID);
3725: if ($serverhomedom ne $dom) {
3726: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3727: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3728: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3729: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3730: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3731: $gotspares = 1;
3732: }
3733: }
3734: } else {
3735: $otherdomconfigs{$serverhomedom} =
3736: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3737: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3738: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3739: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3740: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3741: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3742: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3743: $gotspares = 1;
3744: }
3745: }
3746: }
3747: }
3748: }
3749: }
3750: }
3751: unless ($gotspares) {
3752: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3753: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3754: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3755: } else {
3756: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3757: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3758: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3759: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3760: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3761: } else {
1.150 raeburn 3762: my %what = (
3763: spareid => 1,
3764: );
3765: my ($result,$returnhash) =
3766: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3767: if ($result eq 'ok') {
3768: if (ref($returnhash) eq 'HASH') {
3769: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3770: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3771: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3772: }
3773: }
1.145 raeburn 3774: }
3775: }
3776: }
3777: }
3778: }
3779: }
3780: return %spareid;
3781: }
3782:
3783: sub spares_row {
1.160.6.61 raeburn 3784: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 3785: my $css_class;
3786: my $numinrow = 4;
3787: my $itemcount = 1;
3788: my $datatable;
1.152 raeburn 3789: my %typetitles = &sparestype_titles();
3790: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3791: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3792: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3793: my ($othercontrol,$serverdom);
3794: if ($serverhome ne $server) {
3795: $serverdom = &Apache::lonnet::host_domain($serverhome);
3796: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3797: } else {
3798: $serverdom = &Apache::lonnet::host_domain($server);
3799: if ($serverdom ne $dom) {
3800: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3801: }
3802: }
3803: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 3804: my $checkednow;
3805: if (ref($curroffloadnow) eq 'HASH') {
3806: if ($curroffloadnow->{$server}) {
3807: $checkednow = ' checked="checked"';
3808: }
3809: }
1.145 raeburn 3810: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3811: $datatable .= '<tr'.$css_class.'>
3812: <td rowspan="2">
1.160.6.13 raeburn 3813: <span class="LC_nobreak">'.
3814: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 3815: ,'<b>'.$server.'</b>').'</span><br />'.
3816: '<span class="LC_nobreak">'."\n".
3817: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
3818: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 3819: "\n";
1.145 raeburn 3820: my (%current,%canselect);
1.152 raeburn 3821: my @choices =
3822: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3823: foreach my $type ('primary','default') {
3824: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3825: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3826: my @spares = @{$spareid->{$server}{$type}};
3827: if (@spares > 0) {
1.152 raeburn 3828: if ($othercontrol) {
3829: $current{$type} = join(', ',@spares);
3830: } else {
3831: $current{$type} .= '<table>';
3832: my $numspares = scalar(@spares);
3833: for (my $i=0; $i<@spares; $i++) {
3834: my $rem = $i%($numinrow);
3835: if ($rem == 0) {
3836: if ($i > 0) {
3837: $current{$type} .= '</tr>';
3838: }
3839: $current{$type} .= '<tr>';
1.145 raeburn 3840: }
1.152 raeburn 3841: $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'".');" /> '.
3842: $spareid->{$server}{$type}[$i].
3843: '</label></td>'."\n";
3844: }
3845: my $rem = @spares%($numinrow);
3846: my $colsleft = $numinrow - $rem;
3847: if ($colsleft > 1 ) {
3848: $current{$type} .= '<td colspan="'.$colsleft.
3849: '" class="LC_left_item">'.
3850: ' </td>';
3851: } elsif ($colsleft == 1) {
3852: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3853: }
1.152 raeburn 3854: $current{$type} .= '</tr></table>';
1.150 raeburn 3855: }
1.145 raeburn 3856: }
3857: }
3858: if ($current{$type} eq '') {
3859: $current{$type} = &mt('None specified');
3860: }
1.152 raeburn 3861: if ($othercontrol) {
3862: if ($type eq 'primary') {
3863: $canselect{$type} = $othercontrol;
3864: }
3865: } else {
3866: $canselect{$type} =
3867: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3868: '<select name="newspare_'.$type.'_'.$server.'" '.
3869: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3870: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3871: if (@choices > 0) {
3872: foreach my $lonhost (@choices) {
3873: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3874: }
3875: }
3876: $canselect{$type} .= '</select>'."\n";
3877: }
3878: } else {
3879: $current{$type} = &mt('Could not be determined');
3880: if ($type eq 'primary') {
3881: $canselect{$type} = $othercontrol;
3882: }
1.145 raeburn 3883: }
1.152 raeburn 3884: if ($type eq 'default') {
3885: $datatable .= '<tr'.$css_class.'>';
3886: }
3887: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3888: '<td>'.$current{$type}.'</td>'."\n".
3889: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3890: }
3891: $itemcount ++;
3892: }
3893: }
3894: $$rowtotal += $itemcount;
3895: return $datatable;
3896: }
3897:
1.152 raeburn 3898: sub possible_newspares {
3899: my ($server,$currspares,$serverhomes,$altids) = @_;
3900: my $serverhostname = &Apache::lonnet::hostname($server);
3901: my %excluded;
3902: if ($serverhostname ne '') {
3903: %excluded = (
3904: $serverhostname => 1,
3905: );
3906: }
3907: if (ref($currspares) eq 'HASH') {
3908: foreach my $type (keys(%{$currspares})) {
3909: if (ref($currspares->{$type}) eq 'ARRAY') {
3910: if (@{$currspares->{$type}} > 0) {
3911: foreach my $curr (@{$currspares->{$type}}) {
3912: my $hostname = &Apache::lonnet::hostname($curr);
3913: $excluded{$hostname} = 1;
3914: }
3915: }
3916: }
3917: }
3918: }
3919: my @choices;
3920: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3921: if (keys(%{$serverhomes}) > 1) {
3922: foreach my $name (sort(keys(%{$serverhomes}))) {
3923: unless ($excluded{$name}) {
3924: if (exists($altids->{$serverhomes->{$name}})) {
3925: push(@choices,$altids->{$serverhomes->{$name}});
3926: } else {
3927: push(@choices,$serverhomes->{$name});
1.145 raeburn 3928: }
3929: }
3930: }
3931: }
3932: }
1.152 raeburn 3933: return sort(@choices);
1.145 raeburn 3934: }
3935:
1.150 raeburn 3936: sub print_loadbalancing {
3937: my ($dom,$settings,$rowtotal) = @_;
3938: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3939: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3940: my $numinrow = 1;
3941: my $datatable;
3942: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3943: my (%currbalancer,%currtargets,%currrules,%existing);
3944: if (ref($settings) eq 'HASH') {
3945: %existing = %{$settings};
3946: }
3947: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3948: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3949: \%currtargets,\%currrules);
1.150 raeburn 3950: } else {
3951: return;
3952: }
3953: my ($othertitle,$usertypes,$types) =
3954: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3955: my $rownum = 8;
1.150 raeburn 3956: if (ref($types) eq 'ARRAY') {
3957: $rownum += scalar(@{$types});
3958: }
1.160.6.7 raeburn 3959: my @css_class = ('LC_odd_row','LC_even_row');
3960: my $balnum = 0;
3961: my $islast;
3962: my (@toshow,$disabledtext);
3963: if (keys(%currbalancer) > 0) {
3964: @toshow = sort(keys(%currbalancer));
3965: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3966: push(@toshow,'');
3967: }
3968: } else {
3969: @toshow = ('');
3970: $disabledtext = &mt('No existing load balancer');
3971: }
3972: foreach my $lonhost (@toshow) {
3973: if ($balnum == scalar(@toshow)-1) {
3974: $islast = 1;
3975: } else {
3976: $islast = 0;
3977: }
3978: my $cssidx = $balnum%2;
3979: my $targets_div_style = 'display: none';
3980: my $disabled_div_style = 'display: block';
3981: my $homedom_div_style = 'display: none';
3982: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3983: '<td rowspan="'.$rownum.'" valign="top">'.
3984: '<p>';
3985: if ($lonhost eq '') {
3986: $datatable .= '<span class="LC_nobreak">';
3987: if (keys(%currbalancer) > 0) {
3988: $datatable .= &mt('Add balancer:');
3989: } else {
3990: $datatable .= &mt('Enable balancer:');
3991: }
3992: $datatable .= ' '.
3993: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3994: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3995: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3996: '<option value="" selected="selected">'.&mt('None').
3997: '</option>'."\n";
3998: foreach my $server (sort(keys(%servers))) {
3999: next if ($currbalancer{$server});
4000: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4001: }
4002: $datatable .=
4003: '</select>'."\n".
4004: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4005: } else {
4006: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4007: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4008: &mt('Stop balancing').'</label>'.
4009: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4010: $targets_div_style = 'display: block';
4011: $disabled_div_style = 'display: none';
4012: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4013: $homedom_div_style = 'display: block';
4014: }
4015: }
4016: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4017: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4018: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4019: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4020: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4021: my @sparestypes = ('primary','default');
4022: my %typetitles = &sparestype_titles();
4023: foreach my $sparetype (@sparestypes) {
4024: my $targettable;
4025: for (my $i=0; $i<$numspares; $i++) {
4026: my $checked;
4027: if (ref($currtargets{$lonhost}) eq 'HASH') {
4028: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4029: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4030: $checked = ' checked="checked"';
4031: }
4032: }
4033: }
4034: my ($chkboxval,$disabled);
4035: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4036: $chkboxval = $spares[$i];
4037: }
4038: if (exists($currbalancer{$spares[$i]})) {
4039: $disabled = ' disabled="disabled"';
4040: }
4041: $targettable .=
1.160.6.55 raeburn 4042: '<td><span class="LC_nobreak"><label>'.
4043: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4044: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 4045: '</span></label></span></td>';
1.160.6.7 raeburn 4046: my $rem = $i%($numinrow);
4047: if ($rem == 0) {
4048: if (($i > 0) && ($i < $numspares-1)) {
4049: $targettable .= '</tr>';
4050: }
4051: if ($i < $numspares-1) {
4052: $targettable .= '<tr>';
1.150 raeburn 4053: }
4054: }
4055: }
1.160.6.7 raeburn 4056: if ($targettable ne '') {
4057: my $rem = $numspares%($numinrow);
4058: my $colsleft = $numinrow - $rem;
4059: if ($colsleft > 1 ) {
4060: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4061: ' </td>';
4062: } elsif ($colsleft == 1) {
4063: $targettable .= '<td class="LC_left_item"> </td>';
4064: }
4065: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4066: '<table><tr>'.$targettable.'</tr></table><br />';
4067: }
4068: }
4069: $datatable .= '</div></td></tr>'.
4070: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4071: $othertitle,$usertypes,$types,\%servers,
4072: \%currbalancer,$lonhost,
4073: $targets_div_style,$homedom_div_style,
4074: $css_class[$cssidx],$balnum,$islast);
4075: $$rowtotal += $rownum;
4076: $balnum ++;
4077: }
4078: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4079: return $datatable;
4080: }
4081:
4082: sub get_loadbalancers_config {
4083: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4084: return unless ((ref($servers) eq 'HASH') &&
4085: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4086: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4087: if (keys(%{$existing}) > 0) {
4088: my $oldlonhost;
4089: foreach my $key (sort(keys(%{$existing}))) {
4090: if ($key eq 'lonhost') {
4091: $oldlonhost = $existing->{'lonhost'};
4092: $currbalancer->{$oldlonhost} = 1;
4093: } elsif ($key eq 'targets') {
4094: if ($oldlonhost) {
4095: $currtargets->{$oldlonhost} = $existing->{'targets'};
4096: }
4097: } elsif ($key eq 'rules') {
4098: if ($oldlonhost) {
4099: $currrules->{$oldlonhost} = $existing->{'rules'};
4100: }
4101: } elsif (ref($existing->{$key}) eq 'HASH') {
4102: $currbalancer->{$key} = 1;
4103: $currtargets->{$key} = $existing->{$key}{'targets'};
4104: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4105: }
4106: }
1.160.6.7 raeburn 4107: } else {
4108: my ($balancerref,$targetsref) =
4109: &Apache::lonnet::get_lonbalancer_config($servers);
4110: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4111: foreach my $server (sort(keys(%{$balancerref}))) {
4112: $currbalancer->{$server} = 1;
4113: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4114: }
4115: }
4116: }
1.160.6.7 raeburn 4117: return;
1.150 raeburn 4118: }
4119:
4120: sub loadbalancing_rules {
4121: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4122: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4123: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4124: my $output;
1.160.6.7 raeburn 4125: my $num = 0;
4126: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4127: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4128: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4129: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4130: $num ++;
1.150 raeburn 4131: my $current;
4132: if (ref($currrules) eq 'HASH') {
4133: $current = $currrules->{$type};
4134: }
1.160.6.55 raeburn 4135: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4136: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4137: $current = '';
4138: }
4139: }
4140: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4141: $servers,$currbalancer,$lonhost,$dom,
4142: $targets_div_style,$homedom_div_style,
4143: $css_class,$balnum,$num,$islast);
1.150 raeburn 4144: }
4145: }
4146: return $output;
4147: }
4148:
4149: sub loadbalancing_titles {
4150: my ($dom,$intdom,$usertypes,$types) = @_;
4151: my %othertypes = (
4152: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4153: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4154: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4155: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4156: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4157: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4158: );
1.160.6.26 raeburn 4159: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4160: if (ref($types) eq 'ARRAY') {
4161: unshift(@alltypes,@{$types},'default');
4162: }
4163: my %titles;
4164: foreach my $type (@alltypes) {
4165: if ($type =~ /^_LC_/) {
4166: $titles{$type} = $othertypes{$type};
4167: } elsif ($type eq 'default') {
4168: $titles{$type} = &mt('All users from [_1]',$dom);
4169: if (ref($types) eq 'ARRAY') {
4170: if (@{$types} > 0) {
4171: $titles{$type} = &mt('Other users from [_1]',$dom);
4172: }
4173: }
4174: } elsif (ref($usertypes) eq 'HASH') {
4175: $titles{$type} = $usertypes->{$type};
4176: }
4177: }
4178: return (\@alltypes,\%othertypes,\%titles);
4179: }
4180:
4181: sub loadbalance_rule_row {
1.160.6.7 raeburn 4182: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4183: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4184: my @rulenames;
1.150 raeburn 4185: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4186: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4187: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4188: } else {
1.160.6.26 raeburn 4189: @rulenames = ('default','homeserver');
4190: if ($type eq '_LC_external') {
4191: push(@rulenames,'externalbalancer');
4192: } else {
4193: push(@rulenames,'specific');
4194: }
4195: push(@rulenames,'none');
1.150 raeburn 4196: }
4197: my $style = $targets_div_style;
1.160.6.55 raeburn 4198: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4199: $style = $homedom_div_style;
4200: }
1.160.6.7 raeburn 4201: my $space;
4202: if ($islast && $num == 1) {
4203: $space = '<div display="inline-block"> </div>';
4204: }
4205: my $output =
4206: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4207: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4208: '<td valaign="top">'.$space.
4209: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4210: for (my $i=0; $i<@rulenames; $i++) {
4211: my $rule = $rulenames[$i];
4212: my ($checked,$extra);
4213: if ($rulenames[$i] eq 'default') {
4214: $rule = '';
4215: }
4216: if ($rulenames[$i] eq 'specific') {
4217: if (ref($servers) eq 'HASH') {
4218: my $default;
4219: if (($current ne '') && (exists($servers->{$current}))) {
4220: $checked = ' checked="checked"';
4221: }
4222: unless ($checked) {
4223: $default = ' selected="selected"';
4224: }
1.160.6.7 raeburn 4225: $extra =
4226: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4227: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4228: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4229: '<option value=""'.$default.'></option>'."\n";
4230: foreach my $server (sort(keys(%{$servers}))) {
4231: if (ref($currbalancer) eq 'HASH') {
4232: next if (exists($currbalancer->{$server}));
4233: }
1.150 raeburn 4234: my $selected;
1.160.6.7 raeburn 4235: if ($server eq $current) {
1.150 raeburn 4236: $selected = ' selected="selected"';
4237: }
1.160.6.7 raeburn 4238: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4239: }
4240: $extra .= '</select>';
4241: }
4242: } elsif ($rule eq $current) {
4243: $checked = ' checked="checked"';
4244: }
4245: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4246: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4247: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4248: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4249: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4250: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4251: $output .= $ruletitles{'particular'};
4252: } else {
4253: $output .= $ruletitles{$rulenames[$i]};
4254: }
4255: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4256: }
4257: $output .= '</div></td></tr>'."\n";
4258: return $output;
4259: }
4260:
4261: sub offloadtype_text {
4262: my %ruletitles = &Apache::lonlocal::texthash (
4263: 'default' => 'Offloads to default destinations',
4264: 'homeserver' => "Offloads to user's home server",
4265: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4266: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4267: 'none' => 'No offload',
1.160.6.26 raeburn 4268: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4269: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4270: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4271: );
4272: return %ruletitles;
4273: }
4274:
4275: sub sparestype_titles {
4276: my %typestitles = &Apache::lonlocal::texthash (
4277: 'primary' => 'primary',
4278: 'default' => 'default',
4279: );
4280: return %typestitles;
4281: }
4282:
1.28 raeburn 4283: sub contact_titles {
4284: my %titles = &Apache::lonlocal::texthash (
4285: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4286: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4287: 'errormail' => 'Error reports to be e-mailed to',
4288: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4289: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4290: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4291: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4292: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4293: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4294: );
4295: my %short_titles = &Apache::lonlocal::texthash (
4296: adminemail => 'Admin E-mail address',
4297: supportemail => 'Support E-mail',
4298: );
4299: return (\%titles,\%short_titles);
4300: }
4301:
1.72 raeburn 4302: sub tool_titles {
4303: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4304: aboutme => 'Personal web page',
1.86 raeburn 4305: blog => 'Blog',
1.160.6.4 raeburn 4306: webdav => 'WebDAV',
1.86 raeburn 4307: portfolio => 'Portfolio',
1.88 bisitz 4308: official => 'Official courses (with institutional codes)',
4309: unofficial => 'Unofficial courses',
1.98 raeburn 4310: community => 'Communities',
1.160.6.30 raeburn 4311: textbook => 'Textbook courses',
1.86 raeburn 4312: );
1.72 raeburn 4313: return %titles;
4314: }
4315:
1.101 raeburn 4316: sub courserequest_titles {
4317: my %titles = &Apache::lonlocal::texthash (
4318: official => 'Official',
4319: unofficial => 'Unofficial',
4320: community => 'Communities',
1.160.6.30 raeburn 4321: textbook => 'Textbook',
1.101 raeburn 4322: norequest => 'Not allowed',
1.104 raeburn 4323: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4324: validate => 'With validation',
4325: autolimit => 'Numerical limit',
1.103 raeburn 4326: unlimited => '(blank for unlimited)',
1.101 raeburn 4327: );
4328: return %titles;
4329: }
4330:
1.160.6.5 raeburn 4331: sub authorrequest_titles {
4332: my %titles = &Apache::lonlocal::texthash (
4333: norequest => 'Not allowed',
4334: approval => 'Approval by Dom. Coord.',
4335: automatic => 'Automatic approval',
4336: );
4337: return %titles;
4338: }
4339:
1.101 raeburn 4340: sub courserequest_conditions {
4341: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4342: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4343: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4344: );
4345: return %conditions;
4346: }
4347:
4348:
1.27 raeburn 4349: sub print_usercreation {
1.30 raeburn 4350: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4351: my $numinrow = 4;
1.28 raeburn 4352: my $datatable;
4353: if ($position eq 'top') {
1.30 raeburn 4354: $$rowtotal ++;
1.34 raeburn 4355: my $rowcount = 0;
1.32 raeburn 4356: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4357: if (ref($rules) eq 'HASH') {
4358: if (keys(%{$rules}) > 0) {
1.32 raeburn 4359: $datatable .= &user_formats_row('username',$settings,$rules,
4360: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4361: $$rowtotal ++;
1.32 raeburn 4362: $rowcount ++;
4363: }
4364: }
4365: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4366: if (ref($idrules) eq 'HASH') {
4367: if (keys(%{$idrules}) > 0) {
4368: $datatable .= &user_formats_row('id',$settings,$idrules,
4369: $idruleorder,$numinrow,$rowcount);
4370: $$rowtotal ++;
4371: $rowcount ++;
1.28 raeburn 4372: }
4373: }
1.39 raeburn 4374: if ($rowcount == 0) {
4375: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4376: $$rowtotal ++;
4377: $rowcount ++;
4378: }
1.34 raeburn 4379: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4380: my @creators = ('author','course','requestcrs');
1.37 raeburn 4381: my ($rules,$ruleorder) =
4382: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4383: my %lt = &usercreation_types();
4384: my %checked;
4385: if (ref($settings) eq 'HASH') {
4386: if (ref($settings->{'cancreate'}) eq 'HASH') {
4387: foreach my $item (@creators) {
4388: $checked{$item} = $settings->{'cancreate'}{$item};
4389: }
4390: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4391: foreach my $item (@creators) {
4392: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4393: $checked{$item} = 'none';
4394: }
4395: }
4396: }
4397: }
4398: my $rownum = 0;
4399: foreach my $item (@creators) {
4400: $rownum ++;
1.160.6.34 raeburn 4401: if ($checked{$item} eq '') {
4402: $checked{$item} = 'any';
1.34 raeburn 4403: }
4404: my $css_class;
4405: if ($rownum%2) {
4406: $css_class = '';
4407: } else {
4408: $css_class = ' class="LC_odd_row" ';
4409: }
4410: $datatable .= '<tr'.$css_class.'>'.
4411: '<td><span class="LC_nobreak">'.$lt{$item}.
4412: '</span></td><td align="right">';
1.160.6.34 raeburn 4413: my @options = ('any');
4414: if (ref($rules) eq 'HASH') {
4415: if (keys(%{$rules}) > 0) {
4416: push(@options,('official','unofficial'));
1.37 raeburn 4417: }
4418: }
1.160.6.34 raeburn 4419: push(@options,'none');
1.37 raeburn 4420: foreach my $option (@options) {
1.50 raeburn 4421: my $type = 'radio';
1.34 raeburn 4422: my $check = ' ';
1.160.6.34 raeburn 4423: if ($checked{$item} eq $option) {
4424: $check = ' checked="checked" ';
1.34 raeburn 4425: }
4426: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4427: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4428: $item.'" value="'.$option.'"'.$check.'/> '.
4429: $lt{$option}.'</label> </span>';
4430: }
4431: $datatable .= '</td></tr>';
4432: }
1.28 raeburn 4433: } else {
4434: my @contexts = ('author','course','domain');
4435: my @authtypes = ('int','krb4','krb5','loc');
4436: my %checked;
4437: if (ref($settings) eq 'HASH') {
4438: if (ref($settings->{'authtypes'}) eq 'HASH') {
4439: foreach my $item (@contexts) {
4440: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4441: foreach my $auth (@authtypes) {
4442: if ($settings->{'authtypes'}{$item}{$auth}) {
4443: $checked{$item}{$auth} = ' checked="checked" ';
4444: }
4445: }
4446: }
4447: }
1.27 raeburn 4448: }
1.35 raeburn 4449: } else {
4450: foreach my $item (@contexts) {
1.36 raeburn 4451: foreach my $auth (@authtypes) {
1.35 raeburn 4452: $checked{$item}{$auth} = ' checked="checked" ';
4453: }
4454: }
1.27 raeburn 4455: }
1.28 raeburn 4456: my %title = &context_names();
4457: my %authname = &authtype_names();
4458: my $rownum = 0;
4459: my $css_class;
4460: foreach my $item (@contexts) {
4461: if ($rownum%2) {
4462: $css_class = '';
4463: } else {
4464: $css_class = ' class="LC_odd_row" ';
4465: }
1.30 raeburn 4466: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4467: '<td>'.$title{$item}.
4468: '</td><td class="LC_left_item">'.
4469: '<span class="LC_nobreak">';
4470: foreach my $auth (@authtypes) {
4471: $datatable .= '<label>'.
4472: '<input type="checkbox" name="'.$item.'_auth" '.
4473: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4474: $authname{$auth}.'</label> ';
4475: }
4476: $datatable .= '</span></td></tr>';
4477: $rownum ++;
1.27 raeburn 4478: }
1.30 raeburn 4479: $$rowtotal += $rownum;
1.27 raeburn 4480: }
4481: return $datatable;
4482: }
4483:
1.160.6.34 raeburn 4484: sub print_selfcreation {
4485: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4486: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4487: if (ref($settings) eq 'HASH') {
4488: if (ref($settings->{'cancreate'}) eq 'HASH') {
4489: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4490: if (ref($createsettings) eq 'HASH') {
4491: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4492: @selfcreate = @{$createsettings->{'selfcreate'}};
4493: } elsif ($createsettings->{'selfcreate'} ne '') {
4494: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4495: @selfcreate = ('email','login','sso');
4496: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4497: @selfcreate = ($createsettings->{'selfcreate'});
4498: }
4499: }
4500: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4501: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4502: }
4503: }
4504: }
4505: }
4506: my %radiohash;
4507: my $numinrow = 4;
4508: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4509: if ($position eq 'top') {
4510: my %choices = &Apache::lonlocal::texthash (
4511: cancreate_login => 'Institutional Login',
4512: cancreate_sso => 'Institutional Single Sign On',
4513: );
4514: my @toggles = sort(keys(%choices));
4515: my %defaultchecked = (
4516: 'cancreate_login' => 'off',
4517: 'cancreate_sso' => 'off',
4518: );
1.160.6.35 raeburn 4519: my ($onclick,$itemcount);
1.160.6.34 raeburn 4520: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4521: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4522: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4523:
1.160.6.34 raeburn 4524: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4525:
4526: if (ref($usertypes) eq 'HASH') {
4527: if (keys(%{$usertypes}) > 0) {
4528: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4529: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4530: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4531: $$rowtotal ++;
4532: }
4533: }
1.160.6.44 raeburn 4534: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4535: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4536: $fieldtitles{'inststatus'} = &mt('Institutional status');
4537: my $rem;
4538: my $numperrow = 2;
4539: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4540: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4541: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4542: '<td class="LC_left_item">'."\n".
4543: '<table><tr><td>'."\n";
4544: for (my $i=0; $i<@fields; $i++) {
4545: $rem = $i%($numperrow);
4546: if ($rem == 0) {
4547: if ($i > 0) {
4548: $datatable .= '</tr>';
4549: }
4550: $datatable .= '<tr>';
4551: }
4552: my $currval;
1.160.6.51 raeburn 4553: if (ref($createsettings) eq 'HASH') {
4554: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4555: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4556: }
1.160.6.44 raeburn 4557: }
4558: $datatable .= '<td class="LC_left_item">'.
4559: '<span class="LC_nobreak">'.
4560: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4561: 'value="'.$currval.'" size="10" /> '.
4562: $fieldtitles{$fields[$i]}.'</span></td>';
4563: }
4564: my $colsleft = $numperrow - $rem;
4565: if ($colsleft > 1 ) {
4566: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4567: ' </td>';
4568: } elsif ($colsleft == 1) {
4569: $datatable .= '<td class="LC_left_item"> </td>';
4570: }
4571: $datatable .= '</tr></table></td></tr>';
4572: $$rowtotal ++;
1.160.6.34 raeburn 4573: } elsif ($position eq 'middle') {
4574: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4575: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4576: $usertypes->{'default'} = $othertitle;
4577: if (ref($types) eq 'ARRAY') {
4578: push(@{$types},'default');
4579: $usertypes->{'default'} = $othertitle;
4580: foreach my $status (@{$types}) {
4581: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4582: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4583: $$rowtotal ++;
1.160.6.34 raeburn 4584: }
4585: }
4586: } else {
1.160.6.40 raeburn 4587: my %choices = &Apache::lonlocal::texthash (
4588: cancreate_email => 'E-mail address as username',
4589: );
4590: my @toggles = sort(keys(%choices));
4591: my %defaultchecked = (
4592: 'cancreate_email' => 'off',
4593: );
4594: my $itemcount = 0;
4595: my $display = 'none';
4596: if (grep(/^\Qemail\E$/,@selfcreate)) {
4597: $display = 'block';
4598: }
4599: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4600: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4601: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4602: my $usertypes = {};
4603: my $order = [];
4604: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4605: $usertypes = $domdefaults{'inststatustypes'};
4606: $order = $domdefaults{'inststatusguest'};
4607: }
4608: if (ref($order) eq 'ARRAY') {
4609: push(@{$order},'default');
4610: if (@{$order} > 1) {
4611: $usertypes->{'default'} = &mt('Other users');
4612: $additional .= '<table><tr>';
4613: foreach my $status (@{$order}) {
4614: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4615: }
4616: $additional .= '</tr><tr>';
4617: foreach my $status (@{$order}) {
4618: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4619: }
1.160.6.40 raeburn 4620: $additional .= '</tr></table>';
1.160.6.34 raeburn 4621: } else {
1.160.6.40 raeburn 4622: $usertypes->{'default'} = &mt('All users');
4623: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4624: }
4625: }
1.160.6.40 raeburn 4626: $additional .= '</div>'."\n";
4627:
4628: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4629: \%choices,$$rowtotal,$onclick,$additional);
4630: $$rowtotal ++;
1.160.6.40 raeburn 4631: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4632: $$rowtotal ++;
1.160.6.35 raeburn 4633: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4634: $numinrow = 1;
1.160.6.40 raeburn 4635: if (ref($order) eq 'ARRAY') {
4636: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4637: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4638: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4639: $$rowtotal ++;
4640: }
4641: }
1.160.6.34 raeburn 4642: my ($emailrules,$emailruleorder) =
4643: &Apache::lonnet::inst_userrules($dom,'email');
4644: if (ref($emailrules) eq 'HASH') {
4645: if (keys(%{$emailrules}) > 0) {
4646: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4647: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4648: $$rowtotal ++;
4649: }
4650: }
1.160.6.35 raeburn 4651: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4652: }
4653: return $datatable;
4654: }
4655:
1.160.6.40 raeburn 4656: sub email_as_username {
4657: my ($rowtotal,$processing,$type) = @_;
4658: my %choices =
4659: &Apache::lonlocal::texthash (
4660: automatic => 'Automatic approval',
4661: approval => 'Queued for approval',
4662: );
4663: my $output;
4664: foreach my $option ('automatic','approval') {
4665: my $checked;
4666: if (ref($processing) eq 'HASH') {
4667: if ($type eq '') {
4668: if (!exists($processing->{'default'})) {
4669: if ($option eq 'automatic') {
4670: $checked = ' checked="checked"';
4671: }
4672: } else {
4673: if ($processing->{'default'} eq $option) {
4674: $checked = ' checked="checked"';
4675: }
4676: }
4677: } else {
4678: if (!exists($processing->{$type})) {
4679: if ($option eq 'automatic') {
4680: $checked = ' checked="checked"';
4681: }
4682: } else {
4683: if ($processing->{$type} eq $option) {
4684: $checked = ' checked="checked"';
4685: }
4686: }
4687: }
4688: } elsif ($option eq 'automatic') {
4689: $checked = ' checked="checked"';
4690: }
4691: my $name = 'cancreate_emailprocess';
4692: if (($type ne '') && ($type ne 'default')) {
4693: $name .= '_'.$type;
4694: }
4695: $output .= '<span class="LC_nobreak"><label>'.
4696: '<input type="radio" name="'.$name.'"'.
4697: $checked.' value="'.$option.'" />'.
4698: $choices{$option}.'</label></span>';
4699: if ($type eq '') {
4700: $output .= ' ';
4701: } else {
4702: $output .= '<br />';
4703: }
4704: }
4705: $$rowtotal ++;
4706: return $output;
4707: }
4708:
1.160.6.5 raeburn 4709: sub captcha_choice {
4710: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 4711: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4712: $vertext,$currver);
1.160.6.5 raeburn 4713: my %lt = &captcha_phrases();
4714: $keyentry = 'hidden';
4715: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4716: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4717: } elsif ($context eq 'login') {
4718: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4719: }
4720: if (ref($settings) eq 'HASH') {
4721: if ($settings->{'captcha'}) {
4722: $checked{$settings->{'captcha'}} = ' checked="checked"';
4723: } else {
4724: $checked{'original'} = ' checked="checked"';
4725: }
4726: if ($settings->{'captcha'} eq 'recaptcha') {
4727: $pubtext = $lt{'pub'};
4728: $privtext = $lt{'priv'};
4729: $keyentry = 'text';
1.160.6.69 raeburn 4730: $vertext = $lt{'ver'};
4731: $currver = $settings->{'recaptchaversion'};
4732: if ($currver ne '2') {
4733: $currver = 1;
4734: }
1.160.6.5 raeburn 4735: }
4736: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4737: $currpub = $settings->{'recaptchakeys'}{'public'};
4738: $currpriv = $settings->{'recaptchakeys'}{'private'};
4739: }
4740: } else {
4741: $checked{'original'} = ' checked="checked"';
4742: }
4743: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4744: my $output = '<tr'.$css_class.'>'.
4745: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4746: '<table><tr><td>'."\n";
4747: foreach my $option ('original','recaptcha','notused') {
4748: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4749: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4750: $lt{$option}.'</label></span>';
4751: unless ($option eq 'notused') {
4752: $output .= (' 'x2)."\n";
4753: }
4754: }
4755: #
4756: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4757: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4758: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4759: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4760: #
4761: $output .= '</td></tr>'."\n".
4762: '<tr><td>'."\n".
4763: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4764: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4765: $currpub.'" size="40" /></span><br />'."\n".
4766: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4767: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 4768: $currpriv.'" size="40" /></span><br />'.
4769: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
4770: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
4771: $currver.'" size="3" /></span><br />'.
4772: '</td></tr></table>'."\n".
1.160.6.5 raeburn 4773: '</td></tr>';
4774: return $output;
4775: }
4776:
1.32 raeburn 4777: sub user_formats_row {
4778: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4779: my $output;
4780: my %text = (
4781: 'username' => 'new usernames',
4782: 'id' => 'IDs',
1.45 raeburn 4783: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4784: );
4785: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4786: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4787: '<td><span class="LC_nobreak">';
4788: if ($type eq 'email') {
4789: $output .= &mt("Formats disallowed for $text{$type}: ");
4790: } else {
4791: $output .= &mt("Format rules to check for $text{$type}: ");
4792: }
4793: $output .= '</span></td>'.
4794: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4795: my $rem;
4796: if (ref($ruleorder) eq 'ARRAY') {
4797: for (my $i=0; $i<@{$ruleorder}; $i++) {
4798: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4799: my $rem = $i%($numinrow);
4800: if ($rem == 0) {
4801: if ($i > 0) {
4802: $output .= '</tr>';
4803: }
4804: $output .= '<tr>';
4805: }
4806: my $check = ' ';
1.39 raeburn 4807: if (ref($settings) eq 'HASH') {
4808: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4809: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4810: $check = ' checked="checked" ';
4811: }
1.27 raeburn 4812: }
4813: }
4814: $output .= '<td class="LC_left_item">'.
4815: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4816: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4817: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4818: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4819: }
4820: }
4821: $rem = @{$ruleorder}%($numinrow);
4822: }
4823: my $colsleft = $numinrow - $rem;
4824: if ($colsleft > 1 ) {
4825: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4826: ' </td>';
4827: } elsif ($colsleft == 1) {
4828: $output .= '<td class="LC_left_item"> </td>';
4829: }
4830: $output .= '</tr></table></td></tr>';
4831: return $output;
4832: }
4833:
1.34 raeburn 4834: sub usercreation_types {
4835: my %lt = &Apache::lonlocal::texthash (
4836: author => 'When adding a co-author',
4837: course => 'When adding a user to a course',
1.100 raeburn 4838: requestcrs => 'When requesting a course',
1.34 raeburn 4839: any => 'Any',
4840: official => 'Institutional only ',
4841: unofficial => 'Non-institutional only',
4842: none => 'None',
4843: );
4844: return %lt;
1.48 raeburn 4845: }
1.34 raeburn 4846:
1.160.6.34 raeburn 4847: sub selfcreation_types {
4848: my %lt = &Apache::lonlocal::texthash (
4849: selfcreate => 'User creates own account',
4850: any => 'Any',
4851: official => 'Institutional only ',
4852: unofficial => 'Non-institutional only',
4853: email => 'E-mail address',
4854: login => 'Institutional Login',
4855: sso => 'SSO',
4856: );
4857: }
4858:
1.28 raeburn 4859: sub authtype_names {
4860: my %lt = &Apache::lonlocal::texthash(
4861: int => 'Internal',
4862: krb4 => 'Kerberos 4',
4863: krb5 => 'Kerberos 5',
4864: loc => 'Local',
4865: );
4866: return %lt;
4867: }
4868:
4869: sub context_names {
4870: my %context_title = &Apache::lonlocal::texthash(
4871: author => 'Creating users when an Author',
4872: course => 'Creating users when in a course',
4873: domain => 'Creating users when a Domain Coordinator',
4874: );
4875: return %context_title;
4876: }
4877:
1.33 raeburn 4878: sub print_usermodification {
4879: my ($position,$dom,$settings,$rowtotal) = @_;
4880: my $numinrow = 4;
4881: my ($context,$datatable,$rowcount);
4882: if ($position eq 'top') {
4883: $rowcount = 0;
4884: $context = 'author';
4885: foreach my $role ('ca','aa') {
4886: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4887: $numinrow,$rowcount);
4888: $$rowtotal ++;
4889: $rowcount ++;
4890: }
1.160.6.37 raeburn 4891: } elsif ($position eq 'bottom') {
1.33 raeburn 4892: $context = 'course';
4893: $rowcount = 0;
4894: foreach my $role ('st','ep','ta','in','cr') {
4895: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4896: $numinrow,$rowcount);
4897: $$rowtotal ++;
4898: $rowcount ++;
4899: }
4900: }
4901: return $datatable;
4902: }
4903:
1.43 raeburn 4904: sub print_defaults {
1.160.6.40 raeburn 4905: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4906: my $rownum = 0;
4907: my ($datatable,$css_class);
1.160.6.40 raeburn 4908: if ($position eq 'top') {
4909: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4910: 'datelocale_def','portal_def');
4911: my %defaults;
4912: if (ref($settings) eq 'HASH') {
4913: %defaults = %{$settings};
1.43 raeburn 4914: } else {
1.160.6.40 raeburn 4915: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4916: foreach my $item (@items) {
4917: $defaults{$item} = $domdefaults{$item};
4918: }
1.43 raeburn 4919: }
1.160.6.40 raeburn 4920: my $titles = &defaults_titles($dom);
4921: foreach my $item (@items) {
4922: if ($rownum%2) {
4923: $css_class = '';
4924: } else {
4925: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4926: }
1.160.6.40 raeburn 4927: $datatable .= '<tr'.$css_class.'>'.
4928: '<td><span class="LC_nobreak">'.$titles->{$item}.
4929: '</span></td><td class="LC_right_item" colspan="3">';
4930: if ($item eq 'auth_def') {
4931: my @authtypes = ('internal','krb4','krb5','localauth');
4932: my %shortauth = (
4933: internal => 'int',
4934: krb4 => 'krb4',
4935: krb5 => 'krb5',
4936: localauth => 'loc'
4937: );
4938: my %authnames = &authtype_names();
4939: foreach my $auth (@authtypes) {
4940: my $checked = ' ';
4941: if ($defaults{$item} eq $auth) {
4942: $checked = ' checked="checked" ';
4943: }
4944: $datatable .= '<label><input type="radio" name="'.$item.
4945: '" value="'.$auth.'"'.$checked.'/>'.
4946: $authnames{$shortauth{$auth}}.'</label> ';
4947: }
4948: } elsif ($item eq 'timezone_def') {
4949: my $includeempty = 1;
4950: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4951: } elsif ($item eq 'datelocale_def') {
4952: my $includeempty = 1;
4953: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4954: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 4955: my $includeempty = 1;
4956: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 4957: } else {
4958: my $size;
4959: if ($item eq 'portal_def') {
4960: $size = ' size="25"';
4961: }
4962: $datatable .= '<input type="text" name="'.$item.'" value="'.
4963: $defaults{$item}.'"'.$size.' />';
4964: }
4965: $datatable .= '</td></tr>';
4966: $rownum ++;
4967: }
4968: } else {
4969: my (%defaults);
4970: if (ref($settings) eq 'HASH') {
4971: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4972: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4973: my $maxnum = @{$settings->{'inststatusorder'}};
4974: for (my $i=0; $i<$maxnum; $i++) {
4975: $css_class = $rownum%2?' class="LC_odd_row"':'';
4976: my $item = $settings->{'inststatusorder'}->[$i];
4977: my $title = $settings->{'inststatustypes'}->{$item};
4978: my $guestok;
4979: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4980: $guestok = 1;
4981: }
4982: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4983: $datatable .= '<tr'.$css_class.'>'.
4984: '<td><span class="LC_nobreak">'.
4985: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4986: for (my $k=0; $k<=$maxnum; $k++) {
4987: my $vpos = $k+1;
4988: my $selstr;
4989: if ($k == $i) {
4990: $selstr = ' selected="selected" ';
4991: }
4992: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4993: }
4994: my ($checkedon,$checkedoff);
4995: $checkedoff = ' checked="checked"';
4996: if ($guestok) {
4997: $checkedon = $checkedoff;
4998: $checkedoff = '';
4999: }
5000: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5001: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5002: &mt('delete').'</span></td>'.
5003: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5004: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5005: '</span></td>'.
5006: '<td class="LC_right_item"><span class="LC_nobreak">'.
5007: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5008: &mt('Yes').'</label>'.(' 'x2).
5009: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5010: &mt('No').'</label></span></td></tr>';
5011: }
5012: $css_class = $rownum%2?' class="LC_odd_row"':'';
5013: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5014: $datatable .= '<tr '.$css_class.'>'.
5015: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5016: for (my $k=0; $k<=$maxnum; $k++) {
5017: my $vpos = $k+1;
5018: my $selstr;
5019: if ($k == $maxnum) {
5020: $selstr = ' selected="selected" ';
5021: }
5022: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5023: }
5024: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5025: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5026: ' '.&mt('(new)').
5027: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5028: &mt('Name displayed:').
5029: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5030: '<td class="LC_right_item"><span class="LC_nobreak">'.
5031: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5032: &mt('Yes').'</label>'.(' 'x2).
5033: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5034: &mt('No').'</label></span></td></tr>';
5035: '</tr>'."\n";
5036: $rownum ++;
1.141 raeburn 5037: }
1.43 raeburn 5038: }
5039: }
5040: $$rowtotal += $rownum;
5041: return $datatable;
5042: }
5043:
1.160.6.5 raeburn 5044: sub get_languages_hash {
5045: my %langchoices;
5046: foreach my $id (&Apache::loncommon::languageids()) {
5047: my $code = &Apache::loncommon::supportedlanguagecode($id);
5048: if ($code ne '') {
5049: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5050: }
5051: }
5052: return %langchoices;
5053: }
5054:
1.43 raeburn 5055: sub defaults_titles {
1.141 raeburn 5056: my ($dom) = @_;
1.43 raeburn 5057: my %titles = &Apache::lonlocal::texthash (
5058: 'auth_def' => 'Default authentication type',
5059: 'auth_arg_def' => 'Default authentication argument',
5060: 'lang_def' => 'Default language',
1.54 raeburn 5061: 'timezone_def' => 'Default timezone',
1.68 raeburn 5062: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5063: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5064: );
1.141 raeburn 5065: if ($dom) {
5066: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5067: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5068: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5069: $protocol = 'http' if ($protocol ne 'https');
5070: if ($uint_dom) {
5071: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5072: $uint_dom);
5073: }
5074: }
1.43 raeburn 5075: return (\%titles);
5076: }
5077:
1.46 raeburn 5078: sub print_scantronformat {
5079: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5080: my $itemcount = 1;
1.60 raeburn 5081: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5082: %confhash);
1.46 raeburn 5083: my $switchserver = &check_switchserver($dom,$confname);
5084: my %lt = &Apache::lonlocal::texthash (
1.95 www 5085: default => 'Default bubblesheet format file error',
5086: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5087: );
5088: my %scantronfiles = (
5089: default => 'default.tab',
5090: custom => 'custom.tab',
5091: );
5092: foreach my $key (keys(%scantronfiles)) {
5093: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5094: .$scantronfiles{$key};
5095: }
5096: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5097: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5098: if (!$switchserver) {
5099: my $servadm = $r->dir_config('lonAdmEMail');
5100: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5101: if ($configuserok eq 'ok') {
5102: if ($author_ok eq 'ok') {
5103: my %legacyfile = (
5104: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5105: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5106: );
5107: my %md5chk;
5108: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5109: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5110: chomp($md5chk{$type});
1.46 raeburn 5111: }
5112: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5113: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5114: ($scantronurls{$type},my $error) =
1.46 raeburn 5115: &legacy_scantronformat($r,$dom,$confname,
5116: $type,$legacyfile{$type},
5117: $scantronurls{$type},
5118: $scantronfiles{$type});
1.60 raeburn 5119: if ($error ne '') {
5120: $error{$type} = $error;
5121: }
5122: }
5123: if (keys(%error) == 0) {
5124: $is_custom = 1;
5125: $confhash{'scantron'}{'scantronformat'} =
5126: $scantronurls{'custom'};
5127: my $putresult =
5128: &Apache::lonnet::put_dom('configuration',
5129: \%confhash,$dom);
5130: if ($putresult ne 'ok') {
5131: $error{'custom'} =
5132: '<span class="LC_error">'.
5133: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5134: }
1.46 raeburn 5135: }
5136: } else {
1.60 raeburn 5137: ($scantronurls{'default'},my $error) =
1.46 raeburn 5138: &legacy_scantronformat($r,$dom,$confname,
5139: 'default',$legacyfile{'default'},
5140: $scantronurls{'default'},
5141: $scantronfiles{'default'});
1.60 raeburn 5142: if ($error eq '') {
5143: $confhash{'scantron'}{'scantronformat'} = '';
5144: my $putresult =
5145: &Apache::lonnet::put_dom('configuration',
5146: \%confhash,$dom);
5147: if ($putresult ne 'ok') {
5148: $error{'default'} =
5149: '<span class="LC_error">'.
5150: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5151: }
5152: } else {
5153: $error{'default'} = $error;
5154: }
1.46 raeburn 5155: }
5156: }
5157: }
5158: } else {
1.95 www 5159: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5160: }
5161: }
5162: if (ref($settings) eq 'HASH') {
5163: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5164: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5165: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5166: $scantronurl = '';
5167: } else {
5168: $scantronurl = $settings->{'scantronformat'};
5169: }
5170: $is_custom = 1;
5171: } else {
5172: $scantronurl = $scantronurls{'default'};
5173: }
5174: } else {
1.60 raeburn 5175: if ($is_custom) {
5176: $scantronurl = $scantronurls{'custom'};
5177: } else {
5178: $scantronurl = $scantronurls{'default'};
5179: }
1.46 raeburn 5180: }
5181: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5182: $datatable .= '<tr'.$css_class.'>';
5183: if (!$is_custom) {
1.65 raeburn 5184: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5185: '<span class="LC_nobreak">';
1.46 raeburn 5186: if ($scantronurl) {
1.160.6.21 raeburn 5187: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5188: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5189: } else {
5190: $datatable = &mt('File unavailable for display');
5191: }
1.65 raeburn 5192: $datatable .= '</span></td>';
1.60 raeburn 5193: if (keys(%error) == 0) {
5194: $datatable .= '<td valign="bottom">';
5195: if (!$switchserver) {
5196: $datatable .= &mt('Upload:').'<br />';
5197: }
5198: } else {
5199: my $errorstr;
5200: foreach my $key (sort(keys(%error))) {
5201: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5202: }
5203: $datatable .= '<td>'.$errorstr;
5204: }
1.46 raeburn 5205: } else {
5206: if (keys(%error) > 0) {
5207: my $errorstr;
5208: foreach my $key (sort(keys(%error))) {
5209: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5210: }
1.60 raeburn 5211: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5212: } elsif ($scantronurl) {
1.160.6.26 raeburn 5213: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5214: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5215: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5216: $link.
5217: '<label><input type="checkbox" name="scantronformat_del"'.
5218: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5219: '<td><span class="LC_nobreak"> '.
5220: &mt('Replace:').'</span><br />';
1.46 raeburn 5221: }
5222: }
5223: if (keys(%error) == 0) {
5224: if ($switchserver) {
5225: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5226: } else {
1.65 raeburn 5227: $datatable .='<span class="LC_nobreak"> '.
5228: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5229: }
5230: }
5231: $datatable .= '</td></tr>';
5232: $$rowtotal ++;
5233: return $datatable;
5234: }
5235:
5236: sub legacy_scantronformat {
5237: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5238: my ($url,$error);
5239: my @statinfo = &Apache::lonnet::stat_file($newurl);
5240: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5241: (my $result,$url) =
5242: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5243: '','',$newfile);
5244: if ($result ne 'ok') {
1.130 raeburn 5245: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5246: }
5247: }
5248: return ($url,$error);
5249: }
1.43 raeburn 5250:
1.49 raeburn 5251: sub print_coursecategories {
1.57 raeburn 5252: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5253: my $datatable;
5254: if ($position eq 'top') {
1.160.6.42 raeburn 5255: my (%checked);
5256: my @catitems = ('unauth','auth');
5257: my @cattypes = ('std','domonly','codesrch','none');
5258: $checked{'unauth'} = 'std';
5259: $checked{'auth'} = 'std';
5260: if (ref($settings) eq 'HASH') {
5261: foreach my $type (@cattypes) {
5262: if ($type eq $settings->{'unauth'}) {
5263: $checked{'unauth'} = $type;
5264: }
5265: if ($type eq $settings->{'auth'}) {
5266: $checked{'auth'} = $type;
5267: }
5268: }
5269: }
5270: my %lt = &Apache::lonlocal::texthash (
5271: unauth => 'Catalog type for unauthenticated users',
5272: auth => 'Catalog type for authenticated users',
5273: none => 'No catalog',
5274: std => 'Standard catalog',
5275: domonly => 'Domain-only catalog',
5276: codesrch => "Code search form",
5277: );
5278: my $itemcount = 0;
5279: foreach my $item (@catitems) {
5280: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5281: $datatable .= '<tr '.$css_class.'>'.
5282: '<td>'.$lt{$item}.'</td>'.
5283: '<td class="LC_right_item"><span class="LC_nobreak">';
5284: foreach my $type (@cattypes) {
5285: my $ischecked;
5286: if ($checked{$item} eq $type) {
5287: $ischecked=' checked="checked"';
5288: }
5289: $datatable .= '<label>'.
5290: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5291: ' />'.$lt{$type}.'</label> ';
5292: }
5293: $datatable .= '</td></tr>';
5294: $itemcount ++;
5295: }
5296: $$rowtotal += $itemcount;
5297: } elsif ($position eq 'middle') {
1.57 raeburn 5298: my $toggle_cats_crs = ' ';
5299: my $toggle_cats_dom = ' checked="checked" ';
5300: my $can_cat_crs = ' ';
5301: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5302: my $toggle_catscomm_comm = ' ';
5303: my $toggle_catscomm_dom = ' checked="checked" ';
5304: my $can_catcomm_comm = ' ';
5305: my $can_catcomm_dom = ' checked="checked" ';
5306:
1.57 raeburn 5307: if (ref($settings) eq 'HASH') {
5308: if ($settings->{'togglecats'} eq 'crs') {
5309: $toggle_cats_crs = $toggle_cats_dom;
5310: $toggle_cats_dom = ' ';
5311: }
5312: if ($settings->{'categorize'} eq 'crs') {
5313: $can_cat_crs = $can_cat_dom;
5314: $can_cat_dom = ' ';
5315: }
1.120 raeburn 5316: if ($settings->{'togglecatscomm'} eq 'comm') {
5317: $toggle_catscomm_comm = $toggle_catscomm_dom;
5318: $toggle_catscomm_dom = ' ';
5319: }
5320: if ($settings->{'categorizecomm'} eq 'comm') {
5321: $can_catcomm_comm = $can_catcomm_dom;
5322: $can_catcomm_dom = ' ';
5323: }
1.57 raeburn 5324: }
5325: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5326: togglecats => 'Show/Hide a course in catalog',
5327: togglecatscomm => 'Show/Hide a community in catalog',
5328: categorize => 'Assign a category to a course',
5329: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5330: );
5331: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5332: dom => 'Set in Domain',
5333: crs => 'Set in Course',
5334: comm => 'Set in Community',
1.57 raeburn 5335: );
5336: $datatable = '<tr class="LC_odd_row">'.
5337: '<td>'.$title{'togglecats'}.'</td>'.
5338: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5339: '<input type="radio" name="togglecats"'.
5340: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5341: '<label><input type="radio" name="togglecats"'.
5342: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5343: '</tr><tr>'.
5344: '<td>'.$title{'categorize'}.'</td>'.
5345: '<td class="LC_right_item"><span class="LC_nobreak">'.
5346: '<label><input type="radio" name="categorize"'.
5347: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5348: '<label><input type="radio" name="categorize"'.
5349: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5350: '</tr><tr class="LC_odd_row">'.
5351: '<td>'.$title{'togglecatscomm'}.'</td>'.
5352: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5353: '<input type="radio" name="togglecatscomm"'.
5354: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5355: '<label><input type="radio" name="togglecatscomm"'.
5356: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5357: '</tr><tr>'.
5358: '<td>'.$title{'categorizecomm'}.'</td>'.
5359: '<td class="LC_right_item"><span class="LC_nobreak">'.
5360: '<label><input type="radio" name="categorizecomm"'.
5361: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5362: '<label><input type="radio" name="categorizecomm"'.
5363: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5364: '</tr>';
1.120 raeburn 5365: $$rowtotal += 4;
1.57 raeburn 5366: } else {
5367: my $css_class;
5368: my $itemcount = 1;
5369: my $cathash;
5370: if (ref($settings) eq 'HASH') {
5371: $cathash = $settings->{'cats'};
5372: }
5373: if (ref($cathash) eq 'HASH') {
5374: my (@cats,@trails,%allitems,%idx,@jsarray);
5375: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5376: \%allitems,\%idx,\@jsarray);
5377: my $maxdepth = scalar(@cats);
5378: my $colattrib = '';
5379: if ($maxdepth > 2) {
5380: $colattrib = ' colspan="2" ';
5381: }
5382: my @path;
5383: if (@cats > 0) {
5384: if (ref($cats[0]) eq 'ARRAY') {
5385: my $numtop = @{$cats[0]};
5386: my $maxnum = $numtop;
1.120 raeburn 5387: my %default_names = (
5388: instcode => &mt('Official courses'),
5389: communities => &mt('Communities'),
5390: );
5391:
5392: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5393: ($cathash->{'instcode::0'} eq '') ||
5394: (!grep(/^communities$/,@{$cats[0]})) ||
5395: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5396: $maxnum ++;
5397: }
5398: my $lastidx;
5399: for (my $i=0; $i<$numtop; $i++) {
5400: my $parent = $cats[0][$i];
5401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5402: my $item = &escape($parent).'::0';
5403: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5404: $lastidx = $idx{$item};
5405: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5406: .'<select name="'.$item.'"'.$chgstr.'>';
5407: for (my $k=0; $k<=$maxnum; $k++) {
5408: my $vpos = $k+1;
5409: my $selstr;
5410: if ($k == $i) {
5411: $selstr = ' selected="selected" ';
5412: }
5413: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5414: }
1.160.6.29 raeburn 5415: $datatable .= '</select></span></td><td>';
1.120 raeburn 5416: if ($parent eq 'instcode' || $parent eq 'communities') {
5417: $datatable .= '<span class="LC_nobreak">'
5418: .$default_names{$parent}.'</span>';
5419: if ($parent eq 'instcode') {
5420: $datatable .= '<br /><span class="LC_nobreak">('
5421: .&mt('with institutional codes')
5422: .')</span></td><td'.$colattrib.'>';
5423: } else {
5424: $datatable .= '<table><tr><td>';
5425: }
5426: $datatable .= '<span class="LC_nobreak">'
5427: .'<label><input type="radio" name="'
5428: .$parent.'" value="1" checked="checked" />'
5429: .&mt('Display').'</label>';
5430: if ($parent eq 'instcode') {
5431: $datatable .= ' ';
5432: } else {
5433: $datatable .= '</span></td></tr><tr><td>'
5434: .'<span class="LC_nobreak">';
5435: }
5436: $datatable .= '<label><input type="radio" name="'
5437: .$parent.'" value="0" />'
5438: .&mt('Do not display').'</label></span>';
5439: if ($parent eq 'communities') {
5440: $datatable .= '</td></tr></table>';
5441: }
5442: $datatable .= '</td>';
1.57 raeburn 5443: } else {
5444: $datatable .= $parent
1.160.6.29 raeburn 5445: .' <span class="LC_nobreak"><label>'
5446: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5447: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5448: }
5449: my $depth = 1;
5450: push(@path,$parent);
5451: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5452: pop(@path);
5453: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5454: $itemcount ++;
5455: }
1.48 raeburn 5456: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5457: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5458: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5459: for (my $k=0; $k<=$maxnum; $k++) {
5460: my $vpos = $k+1;
5461: my $selstr;
1.57 raeburn 5462: if ($k == $numtop) {
1.48 raeburn 5463: $selstr = ' selected="selected" ';
5464: }
5465: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5466: }
1.59 bisitz 5467: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5468: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5469: .'</tr>'."\n";
1.48 raeburn 5470: $itemcount ++;
1.120 raeburn 5471: foreach my $default ('instcode','communities') {
5472: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5474: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5475: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5476: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5477: for (my $k=0; $k<=$maxnum; $k++) {
5478: my $vpos = $k+1;
5479: my $selstr;
5480: if ($k == $maxnum) {
5481: $selstr = ' selected="selected" ';
5482: }
5483: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5484: }
1.120 raeburn 5485: $datatable .= '</select></span></td>'.
5486: '<td><span class="LC_nobreak">'.
5487: $default_names{$default}.'</span>';
5488: if ($default eq 'instcode') {
5489: $datatable .= '<br /><span class="LC_nobreak">('
5490: .&mt('with institutional codes').')</span>';
5491: }
5492: $datatable .= '</td>'
5493: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5494: .&mt('Display').'</label> '
5495: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5496: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5497: }
5498: }
5499: }
1.57 raeburn 5500: } else {
5501: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5502: }
5503: } else {
1.160.6.42 raeburn 5504: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5505: .&initialize_categories($itemcount);
1.48 raeburn 5506: }
1.57 raeburn 5507: $$rowtotal += $itemcount;
1.48 raeburn 5508: }
5509: return $datatable;
5510: }
5511:
1.69 raeburn 5512: sub print_serverstatuses {
5513: my ($dom,$settings,$rowtotal) = @_;
5514: my $datatable;
5515: my @pages = &serverstatus_pages();
5516: my (%namedaccess,%machineaccess);
5517: foreach my $type (@pages) {
5518: $namedaccess{$type} = '';
5519: $machineaccess{$type}= '';
5520: }
5521: if (ref($settings) eq 'HASH') {
5522: foreach my $type (@pages) {
5523: if (exists($settings->{$type})) {
5524: if (ref($settings->{$type}) eq 'HASH') {
5525: foreach my $key (keys(%{$settings->{$type}})) {
5526: if ($key eq 'namedusers') {
5527: $namedaccess{$type} = $settings->{$type}->{$key};
5528: } elsif ($key eq 'machines') {
5529: $machineaccess{$type} = $settings->{$type}->{$key};
5530: }
5531: }
5532: }
5533: }
5534: }
5535: }
1.81 raeburn 5536: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5537: my $rownum = 0;
5538: my $css_class;
5539: foreach my $type (@pages) {
5540: $rownum ++;
5541: $css_class = $rownum%2?' class="LC_odd_row"':'';
5542: $datatable .= '<tr'.$css_class.'>'.
5543: '<td><span class="LC_nobreak">'.
5544: $titles->{$type}.'</span></td>'.
5545: '<td class="LC_left_item">'.
5546: '<input type="text" name="'.$type.'_namedusers" '.
5547: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5548: '<td class="LC_right_item">'.
5549: '<span class="LC_nobreak">'.
5550: '<input type="text" name="'.$type.'_machines" '.
5551: 'value="'.$machineaccess{$type}.'" size="10" />'.
5552: '</td></tr>'."\n";
5553: }
5554: $$rowtotal += $rownum;
5555: return $datatable;
5556: }
5557:
5558: sub serverstatus_pages {
5559: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5560: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5561: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 5562: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5563: }
5564:
1.160.6.40 raeburn 5565: sub defaults_javascript {
5566: my ($settings) = @_;
1.160.6.51 raeburn 5567: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5568: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5569: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5570: if ($maxnum eq '') {
5571: $maxnum = 0;
5572: }
5573: $maxnum ++;
1.160.6.51 raeburn 5574: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5575: return <<"ENDSCRIPT";
5576: <script type="text/javascript">
5577: // <![CDATA[
5578: function reorderTypes(form,caller) {
5579: var changedVal;
5580: $jstext
5581: var newpos = 'addinststatus_pos';
5582: var current = new Array;
5583: var maxh = $maxnum;
5584: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5585: var oldVal;
5586: if (caller == newpos) {
5587: changedVal = newitemVal;
5588: } else {
5589: var curritem = 'inststatus_pos_'+caller;
5590: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5591: current[newitemVal] = newpos;
5592: }
5593: for (var i=0; i<inststatuses.length; i++) {
5594: if (inststatuses[i] != caller) {
5595: var elementName = 'inststatus_pos_'+inststatuses[i];
5596: if (form.elements[elementName]) {
5597: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5598: current[currVal] = elementName;
5599: }
5600: }
5601: }
5602: for (var j=0; j<maxh; j++) {
5603: if (current[j] == undefined) {
5604: oldVal = j;
5605: }
5606: }
5607: if (oldVal < changedVal) {
5608: for (var k=oldVal+1; k<=changedVal ; k++) {
5609: var elementName = current[k];
5610: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5611: }
5612: } else {
5613: for (var k=changedVal; k<oldVal; k++) {
5614: var elementName = current[k];
5615: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5616: }
5617: }
5618: return;
5619: }
5620:
5621: // ]]>
5622: </script>
5623:
5624: ENDSCRIPT
5625: }
5626: }
5627:
1.49 raeburn 5628: sub coursecategories_javascript {
5629: my ($settings) = @_;
1.57 raeburn 5630: my ($output,$jstext,$cathash);
1.49 raeburn 5631: if (ref($settings) eq 'HASH') {
1.57 raeburn 5632: $cathash = $settings->{'cats'};
5633: }
5634: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5635: my (@cats,@jsarray,%idx);
1.57 raeburn 5636: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5637: if (@jsarray > 0) {
5638: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5639: for (my $i=0; $i<@jsarray; $i++) {
5640: if (ref($jsarray[$i]) eq 'ARRAY') {
5641: my $catstr = join('","',@{$jsarray[$i]});
5642: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5643: }
5644: }
5645: }
5646: } else {
5647: $jstext = ' var categories = Array(1);'."\n".
5648: ' categories[0] = Array("instcode_pos");'."\n";
5649: }
1.160.6.42 raeburn 5650: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5651: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 5652: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5653: &js_escape(\$instcode_reserved);
5654: &js_escape(\$communities_reserved);
5655: &js_escape(\$choose_again);
1.49 raeburn 5656: $output = <<"ENDSCRIPT";
5657: <script type="text/javascript">
1.109 raeburn 5658: // <![CDATA[
1.49 raeburn 5659: function reorderCats(form,parent,item,idx) {
5660: var changedVal;
5661: $jstext
5662: var newpos = 'addcategory_pos';
5663: if (parent == '') {
5664: var has_instcode = 0;
5665: var maxtop = categories[idx].length;
5666: for (var j=0; j<maxtop; j++) {
5667: if (categories[idx][j] == 'instcode::0') {
5668: has_instcode == 1;
5669: }
5670: }
5671: if (has_instcode == 0) {
5672: categories[idx][maxtop] = 'instcode_pos';
5673: }
5674: } else {
5675: newpos += '_'+parent;
5676: }
5677: var maxh = 1 + categories[idx].length;
5678: var current = new Array;
5679: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5680: if (item == newpos) {
5681: changedVal = newitemVal;
5682: } else {
5683: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5684: current[newitemVal] = newpos;
5685: }
5686: for (var i=0; i<categories[idx].length; i++) {
5687: var elementName = categories[idx][i];
5688: if (elementName != item) {
5689: if (form.elements[elementName]) {
5690: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5691: current[currVal] = elementName;
5692: }
5693: }
5694: }
5695: var oldVal;
5696: for (var j=0; j<maxh; j++) {
5697: if (current[j] == undefined) {
5698: oldVal = j;
5699: }
5700: }
5701: if (oldVal < changedVal) {
5702: for (var k=oldVal+1; k<=changedVal ; k++) {
5703: var elementName = current[k];
5704: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5705: }
5706: } else {
5707: for (var k=changedVal; k<oldVal; k++) {
5708: var elementName = current[k];
5709: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5710: }
5711: }
5712: return;
5713: }
1.120 raeburn 5714:
5715: function categoryCheck(form) {
5716: if (form.elements['addcategory_name'].value == 'instcode') {
5717: alert('$instcode_reserved\\n$choose_again');
5718: return false;
5719: }
5720: if (form.elements['addcategory_name'].value == 'communities') {
5721: alert('$communities_reserved\\n$choose_again');
5722: return false;
5723: }
5724: return true;
5725: }
5726:
1.109 raeburn 5727: // ]]>
1.49 raeburn 5728: </script>
5729:
5730: ENDSCRIPT
5731: return $output;
5732: }
5733:
1.48 raeburn 5734: sub initialize_categories {
5735: my ($itemcount) = @_;
1.120 raeburn 5736: my ($datatable,$css_class,$chgstr);
5737: my %default_names = (
5738: instcode => 'Official courses (with institutional codes)',
5739: communities => 'Communities',
5740: );
5741: my $select0 = ' selected="selected"';
5742: my $select1 = '';
5743: foreach my $default ('instcode','communities') {
5744: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5745: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5746: if ($default eq 'communities') {
5747: $select1 = $select0;
5748: $select0 = '';
5749: }
5750: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5751: .'<select name="'.$default.'_pos">'
5752: .'<option value="0"'.$select0.'>1</option>'
5753: .'<option value="1"'.$select1.'>2</option>'
5754: .'<option value="2">3</option></select> '
5755: .$default_names{$default}
5756: .'</span></td><td><span class="LC_nobreak">'
5757: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5758: .&mt('Display').'</label> <label>'
5759: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5760: .'</label></span></td></tr>';
1.120 raeburn 5761: $itemcount ++;
5762: }
1.48 raeburn 5763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5764: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5765: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5766: .'<select name="addcategory_pos"'.$chgstr.'>'
5767: .'<option value="0">1</option>'
5768: .'<option value="1">2</option>'
5769: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5770: .&mt('Add category').'</td><td>'.&mt('Name:')
5771: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5772: return $datatable;
5773: }
5774:
5775: sub build_category_rows {
1.49 raeburn 5776: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5777: my ($text,$name,$item,$chgstr);
1.48 raeburn 5778: if (ref($cats) eq 'ARRAY') {
5779: my $maxdepth = scalar(@{$cats});
5780: if (ref($cats->[$depth]) eq 'HASH') {
5781: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5782: my $numchildren = @{$cats->[$depth]{$parent}};
5783: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5784: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5785: my ($idxnum,$parent_name,$parent_item);
5786: my $higher = $depth - 1;
5787: if ($higher == 0) {
5788: $parent_name = &escape($parent).'::'.$higher;
5789: } else {
5790: if (ref($path) eq 'ARRAY') {
5791: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5792: }
5793: }
5794: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5795: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5796: if ($j < $numchildren) {
1.48 raeburn 5797: $name = $cats->[$depth]{$parent}[$j];
5798: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5799: $idxnum = $idx->{$item};
5800: } else {
5801: $name = $parent_name;
5802: $item = $parent_item;
1.48 raeburn 5803: }
1.49 raeburn 5804: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5805: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5806: for (my $i=0; $i<=$numchildren; $i++) {
5807: my $vpos = $i+1;
5808: my $selstr;
5809: if ($j == $i) {
5810: $selstr = ' selected="selected" ';
5811: }
5812: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5813: }
5814: $text .= '</select> ';
5815: if ($j < $numchildren) {
5816: my $deeper = $depth+1;
5817: $text .= $name.' '
5818: .'<label><input type="checkbox" name="deletecategory" value="'
5819: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5820: if(ref($path) eq 'ARRAY') {
5821: push(@{$path},$name);
1.49 raeburn 5822: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5823: pop(@{$path});
5824: }
5825: } else {
1.59 bisitz 5826: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5827: if ($j == $numchildren) {
5828: $text .= $name;
5829: } else {
5830: $text .= $item;
5831: }
5832: $text .= '" value="" />';
5833: }
5834: $text .= '</td></tr>';
5835: }
5836: $text .= '</table></td>';
5837: } else {
5838: my $higher = $depth-1;
5839: if ($higher == 0) {
5840: $name = &escape($parent).'::'.$higher;
5841: } else {
5842: if (ref($path) eq 'ARRAY') {
5843: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5844: }
5845: }
5846: my $colspan;
5847: if ($parent ne 'instcode') {
5848: $colspan = $maxdepth - $depth - 1;
5849: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5850: }
5851: }
5852: }
5853: }
5854: return $text;
5855: }
5856:
1.33 raeburn 5857: sub modifiable_userdata_row {
1.160.6.35 raeburn 5858: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5859: my ($role,$rolename,$statustype);
5860: $role = $item;
1.160.6.34 raeburn 5861: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5862: if ($item =~ /^emailusername_(.+)$/) {
5863: $statustype = $1;
5864: $role = 'emailusername';
5865: if (ref($usertypes) eq 'HASH') {
5866: if ($usertypes->{$statustype}) {
5867: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5868: } else {
5869: $rolename = &mt('Data provided by user');
5870: }
5871: }
1.160.6.34 raeburn 5872: }
5873: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5874: if (ref($usertypes) eq 'HASH') {
5875: $rolename = $usertypes->{$role};
5876: } else {
5877: $rolename = $role;
5878: }
1.33 raeburn 5879: } else {
1.63 raeburn 5880: if ($role eq 'cr') {
5881: $rolename = &mt('Custom role');
5882: } else {
5883: $rolename = &Apache::lonnet::plaintext($role);
5884: }
1.33 raeburn 5885: }
1.160.6.34 raeburn 5886: my (@fields,%fieldtitles);
5887: if (ref($fieldsref) eq 'ARRAY') {
5888: @fields = @{$fieldsref};
5889: } else {
5890: @fields = ('lastname','firstname','middlename','generation',
5891: 'permanentemail','id');
5892: }
5893: if ((ref($titlesref) eq 'HASH')) {
5894: %fieldtitles = %{$titlesref};
5895: } else {
5896: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5897: }
1.33 raeburn 5898: my $output;
5899: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5900: $output = '<tr '.$css_class.'>'.
5901: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5902: '<td class="LC_left_item" colspan="2"><table>';
5903: my $rem;
5904: my %checks;
5905: if (ref($settings) eq 'HASH') {
5906: if (ref($settings->{$context}) eq 'HASH') {
5907: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5908: my $hashref = $settings->{$context}->{$role};
5909: if ($role eq 'emailusername') {
5910: if ($statustype) {
5911: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5912: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5913: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5914: foreach my $field (@fields) {
5915: if ($hashref->{$field}) {
5916: $checks{$field} = $hashref->{$field};
5917: }
5918: }
5919: }
5920: }
5921: }
5922: } else {
5923: if (ref($hashref) eq 'HASH') {
5924: foreach my $field (@fields) {
5925: if ($hashref->{$field}) {
5926: $checks{$field} = ' checked="checked" ';
5927: }
5928: }
1.33 raeburn 5929: }
5930: }
5931: }
5932: }
5933: }
1.160.6.39 raeburn 5934:
1.33 raeburn 5935: for (my $i=0; $i<@fields; $i++) {
5936: my $rem = $i%($numinrow);
5937: if ($rem == 0) {
5938: if ($i > 0) {
5939: $output .= '</tr>';
5940: }
5941: $output .= '<tr>';
5942: }
5943: my $check = ' ';
1.160.6.35 raeburn 5944: unless ($role eq 'emailusername') {
5945: if (exists($checks{$fields[$i]})) {
5946: $check = $checks{$fields[$i]}
5947: } else {
5948: if ($role eq 'st') {
5949: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5950: $check = ' checked="checked" ';
1.160.6.35 raeburn 5951: }
1.33 raeburn 5952: }
5953: }
5954: }
5955: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5956: '<span class="LC_nobreak">';
5957: if ($role eq 'emailusername') {
5958: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5959: $checks{$fields[$i]} = 'omit';
5960: }
5961: foreach my $option ('required','optional','omit') {
5962: my $checked='';
5963: if ($checks{$fields[$i]} eq $option) {
5964: $checked='checked="checked" ';
5965: }
5966: $output .= '<label>'.
5967: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5968: &mt($option).'</label>'.(' ' x2);
5969: }
5970: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5971: } else {
5972: $output .= '<label>'.
5973: '<input type="checkbox" name="canmodify_'.$role.'" '.
5974: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5975: '</label>';
5976: }
5977: $output .= '</span></td>';
1.33 raeburn 5978: $rem = @fields%($numinrow);
5979: }
5980: my $colsleft = $numinrow - $rem;
5981: if ($colsleft > 1 ) {
5982: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5983: ' </td>';
5984: } elsif ($colsleft == 1) {
5985: $output .= '<td class="LC_left_item"> </td>';
5986: }
5987: $output .= '</tr></table></td></tr>';
5988: return $output;
5989: }
1.28 raeburn 5990:
1.93 raeburn 5991: sub insttypes_row {
1.160.6.34 raeburn 5992: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5993: my %lt = &Apache::lonlocal::texthash (
5994: cansearch => 'Users allowed to search',
5995: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5996: lockablenames => 'User preference to lock name',
1.93 raeburn 5997: );
5998: my $showdom;
5999: if ($context eq 'cansearch') {
6000: $showdom = ' ('.$dom.')';
6001: }
1.160.6.5 raeburn 6002: my $class = 'LC_left_item';
6003: if ($context eq 'statustocreate') {
6004: $class = 'LC_right_item';
6005: }
1.160.6.34 raeburn 6006: my $css_class = ' class="LC_odd_row"';
6007: if ($rownum ne '') {
6008: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6009: }
6010: my $output = '<tr'.$css_class.'>'.
6011: '<td>'.$lt{$context}.$showdom.
6012: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6013: my $rem;
6014: if (ref($types) eq 'ARRAY') {
6015: for (my $i=0; $i<@{$types}; $i++) {
6016: if (defined($usertypes->{$types->[$i]})) {
6017: my $rem = $i%($numinrow);
6018: if ($rem == 0) {
6019: if ($i > 0) {
6020: $output .= '</tr>';
6021: }
6022: $output .= '<tr>';
1.23 raeburn 6023: }
1.26 raeburn 6024: my $check = ' ';
1.99 raeburn 6025: if (ref($settings) eq 'HASH') {
6026: if (ref($settings->{$context}) eq 'ARRAY') {
6027: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6028: $check = ' checked="checked" ';
6029: }
6030: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6031: $check = ' checked="checked" ';
6032: }
1.23 raeburn 6033: }
1.26 raeburn 6034: $output .= '<td class="LC_left_item">'.
6035: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6036: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6037: 'value="'.$types->[$i].'"'.$check.'/>'.
6038: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6039: }
6040: }
1.26 raeburn 6041: $rem = @{$types}%($numinrow);
1.23 raeburn 6042: }
6043: my $colsleft = $numinrow - $rem;
1.131 raeburn 6044: if (($rem == 0) && (@{$types} > 0)) {
6045: $output .= '<tr>';
6046: }
1.23 raeburn 6047: if ($colsleft > 1) {
1.25 raeburn 6048: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6049: } else {
1.25 raeburn 6050: $output .= '<td class="LC_left_item">';
1.23 raeburn 6051: }
6052: my $defcheck = ' ';
1.99 raeburn 6053: if (ref($settings) eq 'HASH') {
6054: if (ref($settings->{$context}) eq 'ARRAY') {
6055: if (grep(/^default$/,@{$settings->{$context}})) {
6056: $defcheck = ' checked="checked" ';
6057: }
6058: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6059: $defcheck = ' checked="checked" ';
6060: }
1.23 raeburn 6061: }
1.25 raeburn 6062: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6063: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6064: 'value="default"'.$defcheck.'/>'.
6065: $othertitle.'</label></span></td>'.
6066: '</tr></table></td></tr>';
6067: return $output;
1.23 raeburn 6068: }
6069:
6070: sub sorted_searchtitles {
6071: my %searchtitles = &Apache::lonlocal::texthash(
6072: 'uname' => 'username',
6073: 'lastname' => 'last name',
6074: 'lastfirst' => 'last name, first name',
6075: );
6076: my @titleorder = ('uname','lastname','lastfirst');
6077: return (\%searchtitles,\@titleorder);
6078: }
6079:
1.25 raeburn 6080: sub sorted_searchtypes {
6081: my %srchtypes_desc = (
6082: exact => 'is exact match',
6083: contains => 'contains ..',
6084: begins => 'begins with ..',
6085: );
6086: my @srchtypeorder = ('exact','begins','contains');
6087: return (\%srchtypes_desc,\@srchtypeorder);
6088: }
6089:
1.3 raeburn 6090: sub usertype_update_row {
6091: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6092: my $datatable;
6093: my $numinrow = 4;
6094: foreach my $type (@{$types}) {
6095: if (defined($usertypes->{$type})) {
6096: $$rownums ++;
6097: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6098: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6099: '</td><td class="LC_left_item"><table>';
6100: for (my $i=0; $i<@{$fields}; $i++) {
6101: my $rem = $i%($numinrow);
6102: if ($rem == 0) {
6103: if ($i > 0) {
6104: $datatable .= '</tr>';
6105: }
6106: $datatable .= '<tr>';
6107: }
6108: my $check = ' ';
1.39 raeburn 6109: if (ref($settings) eq 'HASH') {
6110: if (ref($settings->{'fields'}) eq 'HASH') {
6111: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6112: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6113: $check = ' checked="checked" ';
6114: }
1.3 raeburn 6115: }
6116: }
6117: }
6118:
6119: if ($i == @{$fields}-1) {
6120: my $colsleft = $numinrow - $rem;
6121: if ($colsleft > 1) {
6122: $datatable .= '<td colspan="'.$colsleft.'">';
6123: } else {
6124: $datatable .= '<td>';
6125: }
6126: } else {
6127: $datatable .= '<td>';
6128: }
1.8 raeburn 6129: $datatable .= '<span class="LC_nobreak"><label>'.
6130: '<input type="checkbox" name="updateable_'.$type.
6131: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6132: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6133: }
6134: $datatable .= '</tr></table></td></tr>';
6135: }
6136: }
6137: return $datatable;
1.1 raeburn 6138: }
6139:
6140: sub modify_login {
1.160.6.24 raeburn 6141: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6142: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6143: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6144: %title = ( coursecatalog => 'Display course catalog',
6145: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6146: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6147: newuser => 'Link for visitors to create a user account',
6148: loginheader => 'Log-in box header');
6149: @offon = ('off','on');
1.112 raeburn 6150: if (ref($domconfig{login}) eq 'HASH') {
6151: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6152: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6153: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6154: }
6155: }
6156: }
1.9 raeburn 6157: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6158: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6159: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6160: foreach my $item (@toggles) {
6161: $loginhash{login}{$item} = $env{'form.'.$item};
6162: }
1.41 raeburn 6163: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6164: if (ref($colchanges{'login'}) eq 'HASH') {
6165: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6166: \%loginhash);
6167: }
1.110 raeburn 6168:
1.149 raeburn 6169: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6170: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6171: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6172: if (keys(%servers) > 1) {
6173: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6174: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6175: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6176: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6177: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6178: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6179: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6180: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6181: $changes{'loginvia'}{$lonhost} = 1;
6182: } else {
6183: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6184: $changes{'loginvia'}{$lonhost} = 1;
6185: }
6186: } else {
6187: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6188: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6189: $changes{'loginvia'}{$lonhost} = 1;
6190: }
6191: }
6192: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6193: foreach my $item (@loginvia_attribs) {
6194: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6195: }
6196: } else {
6197: foreach my $item (@loginvia_attribs) {
6198: my $new = $env{'form.'.$lonhost.'_'.$item};
6199: if (($item eq 'serverpath') && ($new eq 'custom')) {
6200: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6201: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6202: $new = '/';
6203: }
6204: }
6205: if (($item eq 'custompath') &&
6206: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6207: $new = '';
6208: }
6209: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6210: $changes{'loginvia'}{$lonhost} = 1;
6211: }
6212: if ($item eq 'exempt') {
1.160.6.56 raeburn 6213: $new = &check_exempt_addresses($new);
1.128 raeburn 6214: }
6215: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6216: }
6217: }
1.112 raeburn 6218: } else {
1.128 raeburn 6219: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6220: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6221: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6222: foreach my $item (@loginvia_attribs) {
6223: my $new = $env{'form.'.$lonhost.'_'.$item};
6224: if (($item eq 'serverpath') && ($new eq 'custom')) {
6225: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6226: $new = '/';
6227: }
6228: }
6229: if (($item eq 'custompath') &&
6230: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6231: $new = '';
6232: }
6233: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6234: }
1.110 raeburn 6235: }
6236: }
6237: }
6238: }
1.119 raeburn 6239:
1.160.6.5 raeburn 6240: my $servadm = $r->dir_config('lonAdmEMail');
6241: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6242: if (ref($domconfig{'login'}) eq 'HASH') {
6243: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6244: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6245: if ($lang eq 'nolang') {
6246: push(@currlangs,$lang);
6247: } elsif (defined($langchoices{$lang})) {
6248: push(@currlangs,$lang);
6249: } else {
6250: next;
6251: }
6252: }
6253: }
6254: }
6255: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6256: if (@currlangs > 0) {
6257: foreach my $lang (@currlangs) {
6258: if (grep(/^\Q$lang\E$/,@delurls)) {
6259: $changes{'helpurl'}{$lang} = 1;
6260: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6261: $changes{'helpurl'}{$lang} = 1;
6262: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6263: push(@newlangs,$lang);
6264: } else {
6265: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6266: }
6267: }
6268: }
6269: unless (grep(/^nolang$/,@currlangs)) {
6270: if ($env{'form.loginhelpurl_nolang.filename'}) {
6271: $changes{'helpurl'}{'nolang'} = 1;
6272: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6273: push(@newlangs,'nolang');
6274: }
6275: }
6276: if ($env{'form.loginhelpurl_add_lang'}) {
6277: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6278: ($env{'form.loginhelpurl_add_file.filename'})) {
6279: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6280: $addedfile = $env{'form.loginhelpurl_add_lang'};
6281: }
6282: }
6283: if ((@newlangs > 0) || ($addedfile)) {
6284: my $error;
6285: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6286: if ($configuserok eq 'ok') {
6287: if ($switchserver) {
6288: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6289: } elsif ($author_ok eq 'ok') {
6290: my @allnew = @newlangs;
6291: if ($addedfile ne '') {
6292: push(@allnew,$addedfile);
6293: }
6294: foreach my $lang (@allnew) {
6295: my $formelem = 'loginhelpurl_'.$lang;
6296: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6297: $formelem = 'loginhelpurl_add_file';
6298: }
6299: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6300: "help/$lang",'','',$newfile{$lang});
6301: if ($result eq 'ok') {
6302: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6303: $changes{'helpurl'}{$lang} = 1;
6304: } else {
6305: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6306: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6307: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6308: (!grep(/^\Q$lang\E$/,@delurls))) {
6309:
6310: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6311: }
6312: }
6313: }
6314: } else {
6315: $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);
6316: }
6317: } else {
6318: $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);
6319: }
6320: if ($error) {
6321: &Apache::lonnet::logthis($error);
6322: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6323: }
6324: }
1.160.6.56 raeburn 6325:
6326: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6327: if (ref($domconfig{'login'}) eq 'HASH') {
6328: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6329: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6330: if ($domservers{$lonhost}) {
6331: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6332: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73! raeburn 6333: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6334: }
6335: }
6336: }
6337: }
6338: }
6339: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6340: foreach my $lonhost (sort(keys(%domservers))) {
6341: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6342: $changes{'headtag'}{$lonhost} = 1;
6343: } else {
6344: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6345: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6346: }
6347: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6348: push(@newhosts,$lonhost);
6349: } elsif ($currheadtagurls{$lonhost}) {
6350: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6351: if ($currexempt{$lonhost}) {
6352: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6353: $changes{'headtag'}{$lonhost} = 1;
6354: }
6355: } elsif ($possexempt{$lonhost}) {
6356: $changes{'headtag'}{$lonhost} = 1;
6357: }
6358: if ($possexempt{$lonhost}) {
6359: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6360: }
6361: }
6362: }
6363: }
6364: if (@newhosts) {
6365: my $error;
6366: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6367: if ($configuserok eq 'ok') {
6368: if ($switchserver) {
6369: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6370: } elsif ($author_ok eq 'ok') {
6371: foreach my $lonhost (@newhosts) {
6372: my $formelem = 'loginheadtag_'.$lonhost;
6373: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6374: "login/headtag/$lonhost",'','',
6375: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6376: if ($result eq 'ok') {
6377: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6378: $changes{'headtag'}{$lonhost} = 1;
6379: if ($possexempt{$lonhost}) {
6380: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6381: }
6382: } else {
6383: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6384: $newheadtagurls{$lonhost},$result);
6385: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6386: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6387: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6388: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6389: }
6390: }
6391: }
6392: } else {
6393: $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);
6394: }
6395: } else {
6396: $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);
6397: }
6398: if ($error) {
6399: &Apache::lonnet::logthis($error);
6400: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6401: }
6402: }
6403:
1.160.6.5 raeburn 6404: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6405:
6406: my $defaulthelpfile = '/adm/loginproblems.html';
6407: my $defaulttext = &mt('Default in use');
6408:
1.1 raeburn 6409: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6410: $dom);
6411: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6412: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6413: my %defaultchecked = (
6414: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6415: 'helpdesk' => 'on',
1.42 raeburn 6416: 'adminmail' => 'off',
1.43 raeburn 6417: 'newuser' => 'off',
1.42 raeburn 6418: );
1.55 raeburn 6419: if (ref($domconfig{'login'}) eq 'HASH') {
6420: foreach my $item (@toggles) {
6421: if ($defaultchecked{$item} eq 'on') {
6422: if (($domconfig{'login'}{$item} eq '0') &&
6423: ($env{'form.'.$item} eq '1')) {
6424: $changes{$item} = 1;
6425: } elsif (($domconfig{'login'}{$item} eq '' ||
6426: $domconfig{'login'}{$item} eq '1') &&
6427: ($env{'form.'.$item} eq '0')) {
6428: $changes{$item} = 1;
6429: }
6430: } elsif ($defaultchecked{$item} eq 'off') {
6431: if (($domconfig{'login'}{$item} eq '1') &&
6432: ($env{'form.'.$item} eq '0')) {
6433: $changes{$item} = 1;
6434: } elsif (($domconfig{'login'}{$item} eq '' ||
6435: $domconfig{'login'}{$item} eq '0') &&
6436: ($env{'form.'.$item} eq '1')) {
6437: $changes{$item} = 1;
6438: }
1.42 raeburn 6439: }
6440: }
1.41 raeburn 6441: }
1.6 raeburn 6442: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6443: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6444: if (ref($lastactref) eq 'HASH') {
6445: $lastactref->{'domainconfig'} = 1;
6446: }
1.1 raeburn 6447: $resulttext = &mt('Changes made:').'<ul>';
6448: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6449: if ($item eq 'loginvia') {
1.112 raeburn 6450: if (ref($changes{$item}) eq 'HASH') {
6451: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6452: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6453: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6454: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6455: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6456: $protocol = 'http' if ($protocol ne 'https');
6457: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6458:
6459: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6460: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6461: } else {
6462: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6463: }
6464: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6465: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6466: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6467: }
6468: $resulttext .= '</li>';
6469: } else {
6470: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6471: }
1.112 raeburn 6472: } else {
1.128 raeburn 6473: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6474: }
6475: }
1.128 raeburn 6476: $resulttext .= '</ul></li>';
1.112 raeburn 6477: }
1.160.6.5 raeburn 6478: } elsif ($item eq 'helpurl') {
6479: if (ref($changes{$item}) eq 'HASH') {
6480: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6481: if (grep(/^\Q$lang\E$/,@delurls)) {
6482: my ($chg,$link);
6483: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6484: if ($lang eq 'nolang') {
6485: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6486: } else {
6487: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6488: }
6489: $resulttext .= '<li>'.$chg.'</li>';
6490: } else {
6491: my $chg;
6492: if ($lang eq 'nolang') {
6493: $chg = &mt('custom log-in help file for no preferred language');
6494: } else {
6495: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6496: }
6497: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6498: $loginhash{'login'}{'helpurl'}{$lang}.
6499: '?inhibitmenu=yes',$chg,600,500).
6500: '</li>';
6501: }
6502: }
6503: }
1.160.6.56 raeburn 6504: } elsif ($item eq 'headtag') {
6505: if (ref($changes{$item}) eq 'HASH') {
6506: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6507: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6508: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6509: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6510: $resulttext .= '<li><a href="'.
6511: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6512: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6513: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6514: if ($possexempt{$lonhost}) {
6515: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6516: } else {
6517: $resulttext .= &mt('included for any client IP');
6518: }
6519: $resulttext .= '</li>';
6520: }
6521: }
6522: }
1.160.6.5 raeburn 6523: } elsif ($item eq 'captcha') {
6524: if (ref($loginhash{'login'}) eq 'HASH') {
6525: my $chgtxt;
6526: if ($loginhash{'login'}{$item} eq 'notused') {
6527: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6528: } else {
6529: my %captchas = &captcha_phrases();
6530: if ($captchas{$loginhash{'login'}{$item}}) {
6531: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6532: } else {
6533: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6534: }
6535: }
6536: $resulttext .= '<li>'.$chgtxt.'</li>';
6537: }
6538: } elsif ($item eq 'recaptchakeys') {
6539: if (ref($loginhash{'login'}) eq 'HASH') {
6540: my ($privkey,$pubkey);
6541: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6542: $pubkey = $loginhash{'login'}{$item}{'public'};
6543: $privkey = $loginhash{'login'}{$item}{'private'};
6544: }
6545: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6546: if (!$pubkey) {
6547: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6548: } else {
6549: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6550: }
6551: if (!$privkey) {
6552: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6553: } else {
1.160.6.53 raeburn 6554: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6555: }
6556: $chgtxt .= '</ul>';
6557: $resulttext .= '<li>'.$chgtxt.'</li>';
6558: }
1.160.6.69 raeburn 6559: } elsif ($item eq 'recaptchaversion') {
6560: if (ref($loginhash{'login'}) eq 'HASH') {
6561: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
6562: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
6563: '</li>';
6564: }
6565: }
1.41 raeburn 6566: } else {
6567: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6568: }
1.1 raeburn 6569: }
1.6 raeburn 6570: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6571: } else {
6572: $resulttext = &mt('No changes made to log-in page settings');
6573: }
6574: } else {
1.11 albertel 6575: $resulttext = '<span class="LC_error">'.
6576: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6577: }
1.6 raeburn 6578: if ($errors) {
1.9 raeburn 6579: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6580: $errors.'</ul>';
6581: }
6582: return $resulttext;
6583: }
6584:
1.160.6.56 raeburn 6585: sub check_exempt_addresses {
6586: my ($iplist) = @_;
6587: $iplist =~ s/^\s+//;
6588: $iplist =~ s/\s+$//;
6589: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6590: my (@okips,$new);
6591: foreach my $ip (@poss_ips) {
6592: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6593: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6594: push(@okips,$ip);
6595: }
6596: }
6597: }
6598: if (@okips > 0) {
6599: $new = join(',',@okips);
6600: } else {
6601: $new = '';
6602: }
6603: return $new;
6604: }
6605:
1.6 raeburn 6606: sub color_font_choices {
6607: my %choices =
6608: &Apache::lonlocal::texthash (
6609: img => "Header",
6610: bgs => "Background colors",
6611: links => "Link colors",
1.55 raeburn 6612: images => "Images",
1.6 raeburn 6613: font => "Font color",
1.160.6.22 raeburn 6614: fontmenu => "Font menu",
1.76 raeburn 6615: pgbg => "Page",
1.6 raeburn 6616: tabbg => "Header",
6617: sidebg => "Border",
6618: link => "Link",
6619: alink => "Active link",
6620: vlink => "Visited link",
6621: );
6622: return %choices;
6623: }
6624:
6625: sub modify_rolecolors {
1.160.6.24 raeburn 6626: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6627: my ($resulttext,%rolehash);
6628: $rolehash{'rolecolors'} = {};
1.55 raeburn 6629: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6630: if ($domconfig{'rolecolors'} eq '') {
6631: $domconfig{'rolecolors'} = {};
6632: }
6633: }
1.9 raeburn 6634: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6635: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6636: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6637: $dom);
6638: if ($putresult eq 'ok') {
6639: if (keys(%changes) > 0) {
1.41 raeburn 6640: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6641: if (ref($lastactref) eq 'HASH') {
6642: $lastactref->{'domainconfig'} = 1;
6643: }
1.6 raeburn 6644: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6645: $rolehash{'rolecolors'});
6646: } else {
6647: $resulttext = &mt('No changes made to default color schemes');
6648: }
6649: } else {
1.11 albertel 6650: $resulttext = '<span class="LC_error">'.
6651: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6652: }
6653: if ($errors) {
6654: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6655: $errors.'</ul>';
6656: }
6657: return $resulttext;
6658: }
6659:
6660: sub modify_colors {
1.9 raeburn 6661: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6662: my (%changes,%choices);
1.51 raeburn 6663: my @bgs;
1.6 raeburn 6664: my @links = ('link','alink','vlink');
1.41 raeburn 6665: my @logintext;
1.6 raeburn 6666: my @images;
6667: my $servadm = $r->dir_config('lonAdmEMail');
6668: my $errors;
1.160.6.22 raeburn 6669: my %defaults;
1.6 raeburn 6670: foreach my $role (@{$roles}) {
6671: if ($role eq 'login') {
1.12 raeburn 6672: %choices = &login_choices();
1.41 raeburn 6673: @logintext = ('textcol','bgcol');
1.12 raeburn 6674: } else {
6675: %choices = &color_font_choices();
6676: }
6677: if ($role eq 'login') {
1.41 raeburn 6678: @images = ('img','logo','domlogo','login');
1.51 raeburn 6679: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6680: } else {
6681: @images = ('img');
1.160.6.22 raeburn 6682: @bgs = ('pgbg','tabbg','sidebg');
6683: }
6684: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6685: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6686: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6687: }
6688: if ($role eq 'login') {
6689: foreach my $item (@logintext) {
1.160.6.39 raeburn 6690: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6691: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6692: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6693: }
6694: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6695: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6696: }
6697: }
6698: } else {
1.160.6.39 raeburn 6699: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6700: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6701: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6702: }
6703: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6704: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6705: }
1.6 raeburn 6706: }
1.160.6.22 raeburn 6707: foreach my $item (@bgs) {
1.160.6.39 raeburn 6708: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6709: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6710: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6711: }
6712: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6713: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6714: }
6715: }
6716: foreach my $item (@links) {
1.160.6.39 raeburn 6717: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6718: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6719: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6720: }
6721: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6722: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6723: }
1.6 raeburn 6724: }
1.46 raeburn 6725: my ($configuserok,$author_ok,$switchserver) =
6726: &config_check($dom,$confname,$servadm);
1.9 raeburn 6727: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6728: if (ref($domconfig->{$role}) ne 'HASH') {
6729: $domconfig->{$role} = {};
6730: }
1.8 raeburn 6731: foreach my $img (@images) {
1.70 raeburn 6732: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6733: if (defined($env{'form.login_showlogo_'.$img})) {
6734: $confhash->{$role}{'showlogo'}{$img} = 1;
6735: } else {
6736: $confhash->{$role}{'showlogo'}{$img} = 0;
6737: }
6738: }
1.18 albertel 6739: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6740: && !defined($domconfig->{$role}{$img})
6741: && !$env{'form.'.$role.'_del_'.$img}
6742: && $env{'form.'.$role.'_import_'.$img}) {
6743: # import the old configured image from the .tab setting
6744: # if they haven't provided a new one
6745: $domconfig->{$role}{$img} =
6746: $env{'form.'.$role.'_import_'.$img};
6747: }
1.6 raeburn 6748: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6749: my $error;
1.6 raeburn 6750: if ($configuserok eq 'ok') {
1.9 raeburn 6751: if ($switchserver) {
1.12 raeburn 6752: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6753: } else {
6754: if ($author_ok eq 'ok') {
6755: my ($result,$logourl) =
6756: &publishlogo($r,'upload',$role.'_'.$img,
6757: $dom,$confname,$img,$width,$height);
6758: if ($result eq 'ok') {
6759: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6760: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6761: } else {
1.12 raeburn 6762: $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 6763: }
6764: } else {
1.46 raeburn 6765: $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 6766: }
6767: }
6768: } else {
1.46 raeburn 6769: $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 6770: }
6771: if ($error) {
1.8 raeburn 6772: &Apache::lonnet::logthis($error);
1.11 albertel 6773: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6774: }
6775: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6776: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6777: my $error;
6778: if ($configuserok eq 'ok') {
6779: # is confname an author?
6780: if ($switchserver eq '') {
6781: if ($author_ok eq 'ok') {
6782: my ($result,$logourl) =
6783: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6784: $dom,$confname,$img,$width,$height);
6785: if ($result eq 'ok') {
6786: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6787: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6788: }
6789: }
6790: }
6791: }
1.6 raeburn 6792: }
6793: }
6794: }
6795: if (ref($domconfig) eq 'HASH') {
6796: if (ref($domconfig->{$role}) eq 'HASH') {
6797: foreach my $img (@images) {
6798: if ($domconfig->{$role}{$img} ne '') {
6799: if ($env{'form.'.$role.'_del_'.$img}) {
6800: $confhash->{$role}{$img} = '';
1.12 raeburn 6801: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6802: } else {
1.9 raeburn 6803: if ($confhash->{$role}{$img} eq '') {
6804: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6805: }
1.6 raeburn 6806: }
6807: } else {
6808: if ($env{'form.'.$role.'_del_'.$img}) {
6809: $confhash->{$role}{$img} = '';
1.12 raeburn 6810: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6811: }
6812: }
1.70 raeburn 6813: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6814: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6815: if ($confhash->{$role}{'showlogo'}{$img} ne
6816: $domconfig->{$role}{'showlogo'}{$img}) {
6817: $changes{$role}{'showlogo'}{$img} = 1;
6818: }
6819: } else {
6820: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6821: $changes{$role}{'showlogo'}{$img} = 1;
6822: }
6823: }
6824: }
6825: }
1.6 raeburn 6826: if ($domconfig->{$role}{'font'} ne '') {
6827: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6828: $changes{$role}{'font'} = 1;
6829: }
6830: } else {
6831: if ($confhash->{$role}{'font'}) {
6832: $changes{$role}{'font'} = 1;
6833: }
6834: }
1.107 raeburn 6835: if ($role ne 'login') {
6836: if ($domconfig->{$role}{'fontmenu'} ne '') {
6837: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6838: $changes{$role}{'fontmenu'} = 1;
6839: }
6840: } else {
6841: if ($confhash->{$role}{'fontmenu'}) {
6842: $changes{$role}{'fontmenu'} = 1;
6843: }
1.97 tempelho 6844: }
6845: }
1.6 raeburn 6846: foreach my $item (@bgs) {
6847: if ($domconfig->{$role}{$item} ne '') {
6848: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6849: $changes{$role}{'bgs'}{$item} = 1;
6850: }
6851: } else {
6852: if ($confhash->{$role}{$item}) {
6853: $changes{$role}{'bgs'}{$item} = 1;
6854: }
6855: }
6856: }
6857: foreach my $item (@links) {
6858: if ($domconfig->{$role}{$item} ne '') {
6859: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6860: $changes{$role}{'links'}{$item} = 1;
6861: }
6862: } else {
6863: if ($confhash->{$role}{$item}) {
6864: $changes{$role}{'links'}{$item} = 1;
6865: }
6866: }
6867: }
1.41 raeburn 6868: foreach my $item (@logintext) {
6869: if ($domconfig->{$role}{$item} ne '') {
6870: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6871: $changes{$role}{'logintext'}{$item} = 1;
6872: }
6873: } else {
6874: if ($confhash->{$role}{$item}) {
6875: $changes{$role}{'logintext'}{$item} = 1;
6876: }
6877: }
6878: }
1.6 raeburn 6879: } else {
6880: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6881: \@logintext,$confhash,\%changes);
1.6 raeburn 6882: }
6883: } else {
6884: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6885: \@logintext,$confhash,\%changes);
1.6 raeburn 6886: }
6887: }
6888: return ($errors,%changes);
6889: }
6890:
1.46 raeburn 6891: sub config_check {
6892: my ($dom,$confname,$servadm) = @_;
6893: my ($configuserok,$author_ok,$switchserver,%currroles);
6894: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6895: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6896: $confname,$servadm);
6897: if ($configuserok eq 'ok') {
6898: $switchserver = &check_switchserver($dom,$confname);
6899: if ($switchserver eq '') {
6900: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6901: }
6902: }
6903: return ($configuserok,$author_ok,$switchserver);
6904: }
6905:
1.6 raeburn 6906: sub default_change_checker {
1.41 raeburn 6907: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6908: foreach my $item (@{$links}) {
6909: if ($confhash->{$role}{$item}) {
6910: $changes->{$role}{'links'}{$item} = 1;
6911: }
6912: }
6913: foreach my $item (@{$bgs}) {
6914: if ($confhash->{$role}{$item}) {
6915: $changes->{$role}{'bgs'}{$item} = 1;
6916: }
6917: }
1.41 raeburn 6918: foreach my $item (@{$logintext}) {
6919: if ($confhash->{$role}{$item}) {
6920: $changes->{$role}{'logintext'}{$item} = 1;
6921: }
6922: }
1.6 raeburn 6923: foreach my $img (@{$images}) {
6924: if ($env{'form.'.$role.'_del_'.$img}) {
6925: $confhash->{$role}{$img} = '';
1.12 raeburn 6926: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6927: }
1.70 raeburn 6928: if ($role eq 'login') {
6929: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6930: $changes->{$role}{'showlogo'}{$img} = 1;
6931: }
6932: }
1.6 raeburn 6933: }
6934: if ($confhash->{$role}{'font'}) {
6935: $changes->{$role}{'font'} = 1;
6936: }
1.48 raeburn 6937: }
1.6 raeburn 6938:
6939: sub display_colorchgs {
6940: my ($dom,$changes,$roles,$confhash) = @_;
6941: my (%choices,$resulttext);
6942: if (!grep(/^login$/,@{$roles})) {
6943: $resulttext = &mt('Changes made:').'<br />';
6944: }
6945: foreach my $role (@{$roles}) {
6946: if ($role eq 'login') {
6947: %choices = &login_choices();
6948: } else {
6949: %choices = &color_font_choices();
6950: }
6951: if (ref($changes->{$role}) eq 'HASH') {
6952: if ($role ne 'login') {
6953: $resulttext .= '<h4>'.&mt($role).'</h4>';
6954: }
6955: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6956: if ($role ne 'login') {
6957: $resulttext .= '<ul>';
6958: }
6959: if (ref($changes->{$role}{$key}) eq 'HASH') {
6960: if ($role ne 'login') {
6961: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6962: }
6963: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6964: if (($role eq 'login') && ($key eq 'showlogo')) {
6965: if ($confhash->{$role}{$key}{$item}) {
6966: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6967: } else {
6968: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6969: }
6970: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6971: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6972: } else {
1.12 raeburn 6973: my $newitem = $confhash->{$role}{$item};
6974: if ($key eq 'images') {
6975: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6976: }
6977: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6978: }
6979: }
6980: if ($role ne 'login') {
6981: $resulttext .= '</ul></li>';
6982: }
6983: } else {
6984: if ($confhash->{$role}{$key} eq '') {
6985: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6986: } else {
6987: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6988: }
6989: }
6990: if ($role ne 'login') {
6991: $resulttext .= '</ul>';
6992: }
6993: }
6994: }
6995: }
1.3 raeburn 6996: return $resulttext;
1.1 raeburn 6997: }
6998:
1.9 raeburn 6999: sub thumb_dimensions {
7000: return ('200','50');
7001: }
7002:
1.16 raeburn 7003: sub check_dimensions {
7004: my ($inputfile) = @_;
7005: my ($fullwidth,$fullheight);
7006: if ($inputfile =~ m|^[/\w.\-]+$|) {
7007: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7008: my $imageinfo = <PIPE>;
7009: if (!close(PIPE)) {
7010: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7011: }
7012: chomp($imageinfo);
7013: my ($fullsize) =
1.21 raeburn 7014: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7015: if ($fullsize) {
7016: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7017: }
7018: }
7019: }
7020: return ($fullwidth,$fullheight);
7021: }
7022:
1.9 raeburn 7023: sub check_configuser {
7024: my ($uhome,$dom,$confname,$servadm) = @_;
7025: my ($configuserok,%currroles);
7026: if ($uhome eq 'no_host') {
7027: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7028: my $configpass = &LONCAPA::Enrollment::create_password();
7029: $configuserok =
7030: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7031: $configpass,'','','','','',undef,$servadm);
7032: } else {
7033: $configuserok = 'ok';
7034: %currroles =
7035: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7036: }
7037: return ($configuserok,%currroles);
7038: }
7039:
7040: sub check_authorstatus {
7041: my ($dom,$confname,%currroles) = @_;
7042: my $author_ok;
1.40 raeburn 7043: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7044: my $start = time;
7045: my $end = 0;
7046: $author_ok =
7047: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7048: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7049: } else {
7050: $author_ok = 'ok';
7051: }
7052: return $author_ok;
7053: }
7054:
7055: sub publishlogo {
1.46 raeburn 7056: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7057: my ($output,$fname,$logourl);
7058: if ($action eq 'upload') {
7059: $fname=$env{'form.'.$formname.'.filename'};
7060: chop($env{'form.'.$formname});
7061: } else {
7062: ($fname) = ($formname =~ /([^\/]+)$/);
7063: }
1.46 raeburn 7064: if ($savefileas ne '') {
7065: $fname = $savefileas;
7066: }
1.9 raeburn 7067: $fname=&Apache::lonnet::clean_filename($fname);
7068: # See if there is anything left
7069: unless ($fname) { return ('error: no uploaded file'); }
7070: $fname="$subdir/$fname";
1.160.6.5 raeburn 7071: my $docroot=$r->dir_config('lonDocRoot');
7072: my $filepath="$docroot/priv";
7073: my $relpath = "$dom/$confname";
1.9 raeburn 7074: my ($fnamepath,$file,$fetchthumb);
7075: $file=$fname;
7076: if ($fname=~m|/|) {
7077: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7078: }
1.160.6.26 raeburn 7079: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7080: my $count;
1.160.6.5 raeburn 7081: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7082: $filepath.="/$parts[$count]";
7083: if ((-e $filepath)!=1) {
7084: mkdir($filepath,02770);
7085: }
7086: }
7087: # Check for bad extension and disallow upload
7088: if ($file=~/\.(\w+)$/ &&
7089: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7090: $output =
1.160.6.25 raeburn 7091: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7092: } elsif ($file=~/\.(\w+)$/ &&
7093: !defined(&Apache::loncommon::fileembstyle($1))) {
7094: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7095: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7096: $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 7097: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7098: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7099: } else {
7100: my $source = $filepath.'/'.$file;
7101: my $logfile;
7102: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7103: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7104: }
7105: print $logfile
7106: "\n================= Publish ".localtime()." ================\n".
7107: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7108: # Save the file
7109: if (!open(FH,'>'.$source)) {
7110: &Apache::lonnet::logthis('Failed to create '.$source);
7111: return (&mt('Failed to create file'));
7112: }
7113: if ($action eq 'upload') {
7114: if (!print FH ($env{'form.'.$formname})) {
7115: &Apache::lonnet::logthis('Failed to write to '.$source);
7116: return (&mt('Failed to write file'));
7117: }
7118: } else {
7119: my $original = &Apache::lonnet::filelocation('',$formname);
7120: if(!copy($original,$source)) {
7121: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7122: return (&mt('Failed to write file'));
7123: }
7124: }
7125: close(FH);
7126: chmod(0660, $source); # Permissions to rw-rw---.
7127:
7128: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7129: my $copyfile=$targetdir.'/'.$file;
7130:
7131: my @parts=split(/\//,$targetdir);
7132: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7133: for (my $count=5;$count<=$#parts;$count++) {
7134: $path.="/$parts[$count]";
7135: if (!-e $path) {
7136: print $logfile "\nCreating directory ".$path;
7137: mkdir($path,02770);
7138: }
7139: }
7140: my $versionresult;
7141: if (-e $copyfile) {
7142: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7143: } else {
7144: $versionresult = 'ok';
7145: }
7146: if ($versionresult eq 'ok') {
7147: if (copy($source,$copyfile)) {
7148: print $logfile "\nCopied original source to ".$copyfile."\n";
7149: $output = 'ok';
7150: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7151: push(@{$modified_urls},[$copyfile,$source]);
7152: my $metaoutput =
7153: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7154: unless ($registered_cleanup) {
7155: my $handlers = $r->get_handlers('PerlCleanupHandler');
7156: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7157: $registered_cleanup=1;
7158: }
1.9 raeburn 7159: } else {
7160: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7161: $output = &mt('Failed to copy file to RES space').", $!";
7162: }
7163: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7164: my $inputfile = $filepath.'/'.$file;
7165: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7166: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7167: if ($fullwidth ne '' && $fullheight ne '') {
7168: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7169: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7170: system("convert -sample $thumbsize $inputfile $outfile");
7171: chmod(0660, $filepath.'/tn-'.$file);
7172: if (-e $outfile) {
7173: my $copyfile=$targetdir.'/tn-'.$file;
7174: if (copy($outfile,$copyfile)) {
7175: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7176: my $thumb_metaoutput =
7177: &write_metadata($dom,$confname,$formname,
7178: $targetdir,'tn-'.$file,$logfile);
7179: push(@{$modified_urls},[$copyfile,$outfile]);
7180: unless ($registered_cleanup) {
7181: my $handlers = $r->get_handlers('PerlCleanupHandler');
7182: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7183: $registered_cleanup=1;
7184: }
1.16 raeburn 7185: } else {
7186: print $logfile "\nUnable to write ".$copyfile.
7187: ':'.$!."\n";
7188: }
7189: }
1.9 raeburn 7190: }
7191: }
7192: }
7193: } else {
7194: $output = $versionresult;
7195: }
7196: }
7197: return ($output,$logourl);
7198: }
7199:
7200: sub logo_versioning {
7201: my ($targetdir,$file,$logfile) = @_;
7202: my $target = $targetdir.'/'.$file;
7203: my ($maxversion,$fn,$extn,$output);
7204: $maxversion = 0;
7205: if ($file =~ /^(.+)\.(\w+)$/) {
7206: $fn=$1;
7207: $extn=$2;
7208: }
7209: opendir(DIR,$targetdir);
7210: while (my $filename=readdir(DIR)) {
7211: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7212: $maxversion=($1>$maxversion)?$1:$maxversion;
7213: }
7214: }
7215: $maxversion++;
7216: print $logfile "\nCreating old version ".$maxversion."\n";
7217: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7218: if (copy($target,$copyfile)) {
7219: print $logfile "Copied old target to ".$copyfile."\n";
7220: $copyfile=$copyfile.'.meta';
7221: if (copy($target.'.meta',$copyfile)) {
7222: print $logfile "Copied old target metadata to ".$copyfile."\n";
7223: $output = 'ok';
7224: } else {
7225: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7226: $output = &mt('Failed to copy old meta').", $!, ";
7227: }
7228: } else {
7229: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7230: $output = &mt('Failed to copy old target').", $!, ";
7231: }
7232: return $output;
7233: }
7234:
7235: sub write_metadata {
7236: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7237: my (%metadatafields,%metadatakeys,$output);
7238: $metadatafields{'title'}=$formname;
7239: $metadatafields{'creationdate'}=time;
7240: $metadatafields{'lastrevisiondate'}=time;
7241: $metadatafields{'copyright'}='public';
7242: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7243: $env{'user.domain'};
7244: $metadatafields{'authorspace'}=$confname.':'.$dom;
7245: $metadatafields{'domain'}=$dom;
7246: {
7247: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7248: my $mfh;
1.155 raeburn 7249: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7250: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7251: unless ($_=~/\./) {
7252: my $unikey=$_;
7253: $unikey=~/^([A-Za-z]+)/;
7254: my $tag=$1;
7255: $tag=~tr/A-Z/a-z/;
7256: print $mfh "\n\<$tag";
7257: foreach (split(/\,/,$metadatakeys{$unikey})) {
7258: my $value=$metadatafields{$unikey.'.'.$_};
7259: $value=~s/\"/\'\'/g;
7260: print $mfh ' '.$_.'="'.$value.'"';
7261: }
7262: print $mfh '>'.
7263: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7264: .'</'.$tag.'>';
7265: }
7266: }
7267: $output = 'ok';
7268: print $logfile "\nWrote metadata";
7269: close($mfh);
7270: } else {
7271: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7272: $output = &mt('Could not write metadata');
7273: }
7274: }
1.155 raeburn 7275: return $output;
7276: }
7277:
7278: sub notifysubscribed {
7279: foreach my $targetsource (@{$modified_urls}){
7280: next unless (ref($targetsource) eq 'ARRAY');
7281: my ($target,$source)=@{$targetsource};
7282: if ($source ne '') {
7283: if (open(my $logfh,'>>'.$source.'.log')) {
7284: print $logfh "\nCleanup phase: Notifications\n";
7285: my @subscribed=&subscribed_hosts($target);
7286: foreach my $subhost (@subscribed) {
7287: print $logfh "\nNotifying host ".$subhost.':';
7288: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7289: print $logfh $reply;
7290: }
7291: my @subscribedmeta=&subscribed_hosts("$target.meta");
7292: foreach my $subhost (@subscribedmeta) {
7293: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7294: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7295: $subhost);
7296: print $logfh $reply;
7297: }
7298: print $logfh "\n============ Done ============\n";
1.160 raeburn 7299: close($logfh);
1.155 raeburn 7300: }
7301: }
7302: }
7303: return OK;
7304: }
7305:
7306: sub subscribed_hosts {
7307: my ($target) = @_;
7308: my @subscribed;
7309: if (open(my $fh,"<$target.subscription")) {
7310: while (my $subline=<$fh>) {
7311: if ($subline =~ /^($match_lonid):/) {
7312: my $host = $1;
7313: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7314: unless (grep(/^\Q$host\E$/,@subscribed)) {
7315: push(@subscribed,$host);
7316: }
7317: }
7318: }
7319: }
7320: }
7321: return @subscribed;
1.9 raeburn 7322: }
7323:
7324: sub check_switchserver {
7325: my ($dom,$confname) = @_;
7326: my ($allowed,$switchserver);
7327: my $home = &Apache::lonnet::homeserver($confname,$dom);
7328: if ($home eq 'no_host') {
7329: $home = &Apache::lonnet::domain($dom,'primary');
7330: }
7331: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7332: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7333: if (!$allowed) {
1.160.6.11 raeburn 7334: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7335: }
7336: return $switchserver;
7337: }
7338:
1.1 raeburn 7339: sub modify_quotas {
1.160.6.30 raeburn 7340: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7341: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7342: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7343: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7344: $validationfieldsref);
1.86 raeburn 7345: if ($action eq 'quotas') {
7346: $context = 'tools';
1.160.6.26 raeburn 7347: } else {
1.86 raeburn 7348: $context = $action;
7349: }
7350: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7351: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7352: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7353: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7354: %titles = &courserequest_titles();
7355: $toolregexp = join('|',@usertools);
7356: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7357: $confname = $dom.'-domainconfig';
7358: my $servadm = $r->dir_config('lonAdmEMail');
7359: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7360: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7361: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7362: } elsif ($context eq 'requestauthor') {
7363: @usertools = ('author');
7364: %titles = &authorrequest_titles();
1.86 raeburn 7365: } else {
1.160.6.4 raeburn 7366: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7367: %titles = &tool_titles();
1.86 raeburn 7368: }
1.160.6.27 raeburn 7369: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7370: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7371: foreach my $key (keys(%env)) {
1.101 raeburn 7372: if ($context eq 'requestcourses') {
7373: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7374: my $item = $1;
7375: my $type = $2;
7376: if ($type =~ /^limit_(.+)/) {
7377: $limithash{$item}{$1} = $env{$key};
7378: } else {
7379: $confhash{$item}{$type} = $env{$key};
7380: }
7381: }
1.160.6.5 raeburn 7382: } elsif ($context eq 'requestauthor') {
7383: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7384: $confhash{$1} = $env{$key};
7385: }
1.101 raeburn 7386: } else {
1.86 raeburn 7387: if ($key =~ /^form\.quota_(.+)$/) {
7388: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7389: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7390: $confhash{'authorquota'}{$1} = $env{$key};
7391: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7392: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7393: }
1.72 raeburn 7394: }
7395: }
1.160.6.5 raeburn 7396: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7397: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7398: @approvalnotify = sort(@approvalnotify);
7399: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7400: my @crstypes = ('official','unofficial','community','textbook');
7401: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7402: foreach my $type (@hasuniquecode) {
7403: if (grep(/^\Q$type\E$/,@crstypes)) {
7404: $confhash{'uniquecode'}{$type} = 1;
7405: }
7406: }
1.160.6.46 raeburn 7407: my (%newbook,%allpos);
1.160.6.30 raeburn 7408: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7409: foreach my $type ('textbooks','templates') {
7410: @{$allpos{$type}} = ();
7411: my $invalid;
7412: if ($type eq 'textbooks') {
7413: $invalid = &mt('Invalid LON-CAPA course for textbook');
7414: } else {
7415: $invalid = &mt('Invalid LON-CAPA course for template');
7416: }
7417: if ($env{'form.'.$type.'_addbook'}) {
7418: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7419: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7420: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7421: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7422: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7423: } else {
7424: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7425: my $position = $env{'form.'.$type.'_addbook_pos'};
7426: $position =~ s/\D+//g;
7427: if ($position ne '') {
7428: $allpos{$type}[$position] = $newbook{$type};
7429: }
1.160.6.30 raeburn 7430: }
1.160.6.46 raeburn 7431: } else {
7432: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7433: }
7434: }
1.160.6.46 raeburn 7435: }
1.160.6.30 raeburn 7436: }
1.102 raeburn 7437: if (ref($domconfig{$action}) eq 'HASH') {
7438: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7439: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7440: $changes{'notify'}{'approval'} = 1;
7441: }
7442: } else {
1.144 raeburn 7443: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7444: $changes{'notify'}{'approval'} = 1;
7445: }
7446: }
1.160.6.30 raeburn 7447: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7448: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7449: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7450: unless ($confhash{'uniquecode'}{$crstype}) {
7451: $changes{'uniquecode'} = 1;
7452: }
7453: }
7454: unless ($changes{'uniquecode'}) {
7455: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7456: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7457: $changes{'uniquecode'} = 1;
7458: }
7459: }
7460: }
7461: } else {
7462: $changes{'uniquecode'} = 1;
7463: }
7464: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7465: $changes{'uniquecode'} = 1;
7466: }
7467: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7468: foreach my $type ('textbooks','templates') {
7469: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7470: my %deletions;
7471: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7472: if (@todelete) {
7473: map { $deletions{$_} = 1; } @todelete;
7474: }
7475: my %imgdeletions;
7476: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7477: if (@todeleteimages) {
7478: map { $imgdeletions{$_} = 1; } @todeleteimages;
7479: }
7480: my $maxnum = $env{'form.'.$type.'_maxnum'};
7481: for (my $i=0; $i<=$maxnum; $i++) {
7482: my $itemid = $env{'form.'.$type.'_id_'.$i};
7483: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7484: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7485: if ($deletions{$key}) {
7486: if ($domconfig{$action}{$type}{$key}{'image'}) {
7487: #FIXME need to obsolete item in RES space
7488: }
7489: next;
7490: } else {
7491: my $newpos = $env{'form.'.$itemid};
7492: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7493: foreach my $item ('subject','title','publisher','author') {
7494: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7495: ($type eq 'templates'));
1.160.6.46 raeburn 7496: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7497: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7498: $changes{$type}{$key} = 1;
7499: }
7500: }
7501: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7502: }
1.160.6.46 raeburn 7503: if ($imgdeletions{$key}) {
7504: $changes{$type}{$key} = 1;
7505: #FIXME need to obsolete item in RES space
7506: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7507: my ($cdom,$cnum) = split(/_/,$key);
7508: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7509: $cdom,$cnum,$type,$configuserok,
7510: $switchserver,$author_ok);
7511: if ($imgurl) {
7512: $confhash{$type}{$key}{'image'} = $imgurl;
7513: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7514: }
1.160.6.46 raeburn 7515: if ($error) {
7516: &Apache::lonnet::logthis($error);
7517: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7518: }
7519: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7520: $confhash{$type}{$key}{'image'} =
7521: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7522: }
7523: }
7524: }
7525: }
7526: }
7527: }
1.102 raeburn 7528: } else {
1.144 raeburn 7529: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7530: $changes{'notify'}{'approval'} = 1;
7531: }
1.160.6.30 raeburn 7532: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7533: $changes{'uniquecode'} = 1;
7534: }
7535: }
7536: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7537: foreach my $type ('textbooks','templates') {
7538: if ($newbook{$type}) {
7539: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7540: foreach my $item ('subject','title','publisher','author') {
7541: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7542: ($type eq 'template'));
1.160.6.46 raeburn 7543: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7544: if ($env{'form.'.$type.'_addbook_'.$item}) {
7545: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7546: }
7547: }
7548: if ($type eq 'textbooks') {
7549: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7550: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7551: my ($imageurl,$error) =
7552: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7553: $configuserok,$switchserver,$author_ok);
7554: if ($imageurl) {
7555: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7556: }
7557: if ($error) {
7558: &Apache::lonnet::logthis($error);
7559: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7560: }
7561: }
1.160.6.30 raeburn 7562: }
7563: }
1.160.6.46 raeburn 7564: if (@{$allpos{$type}} > 0) {
7565: my $idx = 0;
7566: foreach my $item (@{$allpos{$type}}) {
7567: if ($item ne '') {
7568: $confhash{$type}{$item}{'order'} = $idx;
7569: if (ref($domconfig{$action}) eq 'HASH') {
7570: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7571: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7572: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7573: $changes{$type}{$item} = 1;
7574: }
1.160.6.30 raeburn 7575: }
7576: }
7577: }
1.160.6.46 raeburn 7578: $idx ++;
1.160.6.30 raeburn 7579: }
7580: }
7581: }
7582: }
1.160.6.39 raeburn 7583: if (ref($validationitemsref) eq 'ARRAY') {
7584: foreach my $item (@{$validationitemsref}) {
7585: if ($item eq 'fields') {
7586: my @changed;
7587: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7588: if (@{$confhash{'validation'}{$item}} > 0) {
7589: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7590: }
1.160.6.65 raeburn 7591: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7592: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7593: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7594: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7595: $domconfig{'requestcourses'}{'validation'}{$item});
7596: } else {
7597: @changed = @{$confhash{'validation'}{$item}};
7598: }
1.160.6.39 raeburn 7599: } else {
7600: @changed = @{$confhash{'validation'}{$item}};
7601: }
7602: } else {
7603: @changed = @{$confhash{'validation'}{$item}};
7604: }
7605: if (@changed) {
7606: if ($confhash{'validation'}{$item}) {
7607: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7608: } else {
7609: $changes{'validation'}{$item} = &mt('None');
7610: }
7611: }
7612: } else {
7613: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7614: if ($item eq 'markup') {
7615: if ($env{'form.requestcourses_validation_'.$item}) {
7616: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7617: }
7618: }
1.160.6.65 raeburn 7619: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7620: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7621: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7622: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7623: }
7624: } else {
7625: if ($confhash{'validation'}{$item} ne '') {
7626: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7627: }
1.160.6.39 raeburn 7628: }
7629: } else {
7630: if ($confhash{'validation'}{$item} ne '') {
7631: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7632: }
7633: }
7634: }
7635: }
7636: }
7637: if ($env{'form.validationdc'}) {
7638: my $newval = $env{'form.validationdc'};
7639: my %domcoords = &get_active_dcs($dom);
7640: if (exists($domcoords{$newval})) {
7641: $confhash{'validation'}{'dc'} = $newval;
7642: }
7643: }
7644: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 7645: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7646: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7647: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7648: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7649: if ($confhash{'validation'}{'dc'} eq '') {
7650: $changes{'validation'}{'dc'} = &mt('None');
7651: } else {
7652: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7653: }
1.160.6.39 raeburn 7654: }
1.160.6.65 raeburn 7655: } elsif ($confhash{'validation'}{'dc'} ne '') {
7656: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 7657: }
7658: } elsif ($confhash{'validation'}{'dc'} ne '') {
7659: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7660: }
7661: } elsif ($confhash{'validation'}{'dc'} ne '') {
7662: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7663: }
1.160.6.65 raeburn 7664: } else {
7665: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7666: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7667: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7668: $changes{'validation'}{'dc'} = &mt('None');
7669: }
7670: }
1.160.6.39 raeburn 7671: }
7672: }
1.102 raeburn 7673: }
7674: } else {
1.86 raeburn 7675: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7676: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7677: }
1.72 raeburn 7678: foreach my $item (@usertools) {
7679: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7680: my $unset;
1.101 raeburn 7681: if ($context eq 'requestcourses') {
1.104 raeburn 7682: $unset = '0';
7683: if ($type eq '_LC_adv') {
7684: $unset = '';
7685: }
1.101 raeburn 7686: if ($confhash{$item}{$type} eq 'autolimit') {
7687: $confhash{$item}{$type} .= '=';
7688: unless ($limithash{$item}{$type} =~ /\D/) {
7689: $confhash{$item}{$type} .= $limithash{$item}{$type};
7690: }
7691: }
1.160.6.5 raeburn 7692: } elsif ($context eq 'requestauthor') {
7693: $unset = '0';
7694: if ($type eq '_LC_adv') {
7695: $unset = '';
7696: }
1.72 raeburn 7697: } else {
1.101 raeburn 7698: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7699: $confhash{$item}{$type} = 1;
7700: } else {
7701: $confhash{$item}{$type} = 0;
7702: }
1.72 raeburn 7703: }
1.86 raeburn 7704: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7705: if ($action eq 'requestauthor') {
7706: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7707: $changes{$type} = 1;
7708: }
7709: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7710: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7711: $changes{$item}{$type} = 1;
7712: }
7713: } else {
7714: if ($context eq 'requestcourses') {
1.104 raeburn 7715: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7716: $changes{$item}{$type} = 1;
7717: }
7718: } else {
7719: if (!$confhash{$item}{$type}) {
7720: $changes{$item}{$type} = 1;
7721: }
7722: }
7723: }
7724: } else {
7725: if ($context eq 'requestcourses') {
1.104 raeburn 7726: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7727: $changes{$item}{$type} = 1;
7728: }
1.160.6.5 raeburn 7729: } elsif ($context eq 'requestauthor') {
7730: if ($confhash{$type} ne $unset) {
7731: $changes{$type} = 1;
7732: }
1.72 raeburn 7733: } else {
7734: if (!$confhash{$item}{$type}) {
7735: $changes{$item}{$type} = 1;
7736: }
7737: }
7738: }
1.1 raeburn 7739: }
7740: }
1.160.6.5 raeburn 7741: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7742: if (ref($domconfig{'quotas'}) eq 'HASH') {
7743: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7744: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7745: if (exists($confhash{'defaultquota'}{$key})) {
7746: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7747: $changes{'defaultquota'}{$key} = 1;
7748: }
7749: } else {
7750: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7751: }
7752: }
1.86 raeburn 7753: } else {
7754: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7755: if (exists($confhash{'defaultquota'}{$key})) {
7756: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7757: $changes{'defaultquota'}{$key} = 1;
7758: }
7759: } else {
7760: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7761: }
1.1 raeburn 7762: }
7763: }
1.160.6.20 raeburn 7764: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7765: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7766: if (exists($confhash{'authorquota'}{$key})) {
7767: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7768: $changes{'authorquota'}{$key} = 1;
7769: }
7770: } else {
7771: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7772: }
7773: }
7774: }
1.1 raeburn 7775: }
1.86 raeburn 7776: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7777: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7778: if (ref($domconfig{'quotas'}) eq 'HASH') {
7779: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7780: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7781: $changes{'defaultquota'}{$key} = 1;
7782: }
7783: } else {
7784: if (!exists($domconfig{'quotas'}{$key})) {
7785: $changes{'defaultquota'}{$key} = 1;
7786: }
1.72 raeburn 7787: }
7788: } else {
1.86 raeburn 7789: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7790: }
1.1 raeburn 7791: }
7792: }
1.160.6.20 raeburn 7793: if (ref($confhash{'authorquota'}) eq 'HASH') {
7794: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7795: if (ref($domconfig{'quotas'}) eq 'HASH') {
7796: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7797: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7798: $changes{'authorquota'}{$key} = 1;
7799: }
7800: } else {
7801: $changes{'authorquota'}{$key} = 1;
7802: }
7803: } else {
7804: $changes{'authorquota'}{$key} = 1;
7805: }
7806: }
7807: }
1.1 raeburn 7808: }
1.72 raeburn 7809:
1.160.6.5 raeburn 7810: if ($context eq 'requestauthor') {
7811: $domdefaults{'requestauthor'} = \%confhash;
7812: } else {
7813: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7814: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7815: $domdefaults{$key} = $confhash{$key};
7816: }
1.160.6.5 raeburn 7817: }
1.72 raeburn 7818: }
1.160.6.5 raeburn 7819:
1.1 raeburn 7820: my %quotahash = (
1.86 raeburn 7821: $action => { %confhash }
1.1 raeburn 7822: );
7823: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7824: $dom);
7825: if ($putresult eq 'ok') {
7826: if (keys(%changes) > 0) {
1.72 raeburn 7827: my $cachetime = 24*60*60;
7828: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7829: if (ref($lastactref) eq 'HASH') {
7830: $lastactref->{'domdefaults'} = 1;
7831: }
1.1 raeburn 7832: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7833: unless (($context eq 'requestcourses') ||
7834: ($context eq 'requestauthor')) {
1.86 raeburn 7835: if (ref($changes{'defaultquota'}) eq 'HASH') {
7836: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7837: foreach my $type (@{$types},'default') {
7838: if (defined($changes{'defaultquota'}{$type})) {
7839: my $typetitle = $usertypes->{$type};
7840: if ($type eq 'default') {
7841: $typetitle = $othertitle;
7842: }
1.160.6.28 raeburn 7843: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7844: }
7845: }
1.86 raeburn 7846: $resulttext .= '</ul></li>';
1.72 raeburn 7847: }
1.160.6.20 raeburn 7848: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7849: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7850: foreach my $type (@{$types},'default') {
7851: if (defined($changes{'authorquota'}{$type})) {
7852: my $typetitle = $usertypes->{$type};
7853: if ($type eq 'default') {
7854: $typetitle = $othertitle;
7855: }
1.160.6.28 raeburn 7856: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7857: }
7858: }
7859: $resulttext .= '</ul></li>';
7860: }
1.72 raeburn 7861: }
1.80 raeburn 7862: my %newenv;
1.72 raeburn 7863: foreach my $item (@usertools) {
1.160.6.5 raeburn 7864: my (%haschgs,%inconf);
7865: if ($context eq 'requestauthor') {
7866: %haschgs = %changes;
7867: %inconf = %confhash;
7868: } else {
7869: if (ref($changes{$item}) eq 'HASH') {
7870: %haschgs = %{$changes{$item}};
7871: }
7872: if (ref($confhash{$item}) eq 'HASH') {
7873: %inconf = %{$confhash{$item}};
7874: }
7875: }
7876: if (keys(%haschgs) > 0) {
1.80 raeburn 7877: my $newacc =
7878: &Apache::lonnet::usertools_access($env{'user.name'},
7879: $env{'user.domain'},
1.86 raeburn 7880: $item,'reload',$context);
1.160.6.5 raeburn 7881: if (($context eq 'requestcourses') ||
7882: ($context eq 'requestauthor')) {
1.108 raeburn 7883: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7884: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7885: }
7886: } else {
7887: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7888: $newenv{'environment.availabletools.'.$item} = $newacc;
7889: }
1.80 raeburn 7890: }
1.160.6.5 raeburn 7891: unless ($context eq 'requestauthor') {
7892: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7893: }
1.72 raeburn 7894: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7895: if ($haschgs{$type}) {
1.72 raeburn 7896: my $typetitle = $usertypes->{$type};
7897: if ($type eq 'default') {
7898: $typetitle = $othertitle;
7899: } elsif ($type eq '_LC_adv') {
7900: $typetitle = 'LON-CAPA Advanced Users';
7901: }
1.160.6.5 raeburn 7902: if ($inconf{$type}) {
1.101 raeburn 7903: if ($context eq 'requestcourses') {
7904: my $cond;
1.160.6.5 raeburn 7905: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7906: if ($1 eq '') {
7907: $cond = &mt('(Automatic processing of any request).');
7908: } else {
7909: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7910: }
7911: } else {
1.160.6.5 raeburn 7912: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7913: }
7914: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7915: } elsif ($context eq 'requestauthor') {
7916: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7917: $titles{$inconf{$type}},$typetitle);
7918:
1.101 raeburn 7919: } else {
7920: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7921: }
1.72 raeburn 7922: } else {
1.104 raeburn 7923: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7924: if ($inconf{$type} eq '0') {
1.104 raeburn 7925: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7926: } else {
7927: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7928: }
7929: } else {
7930: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7931: }
1.72 raeburn 7932: }
7933: }
1.26 raeburn 7934: }
1.160.6.5 raeburn 7935: unless ($context eq 'requestauthor') {
7936: $resulttext .= '</ul></li>';
7937: }
1.26 raeburn 7938: }
1.1 raeburn 7939: }
1.160.6.5 raeburn 7940: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7941: if (ref($changes{'notify'}) eq 'HASH') {
7942: if ($changes{'notify'}{'approval'}) {
7943: if (ref($confhash{'notify'}) eq 'HASH') {
7944: if ($confhash{'notify'}{'approval'}) {
7945: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7946: } else {
1.160.6.5 raeburn 7947: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7948: }
7949: }
7950: }
7951: }
7952: }
1.160.6.30 raeburn 7953: if ($action eq 'requestcourses') {
7954: my @offon = ('off','on');
7955: if ($changes{'uniquecode'}) {
7956: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7957: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7958: $resulttext .= '<li>'.
7959: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7960: '</li>';
7961: } else {
7962: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7963: '</li>';
7964: }
7965: }
1.160.6.46 raeburn 7966: foreach my $type ('textbooks','templates') {
7967: if (ref($changes{$type}) eq 'HASH') {
7968: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7969: foreach my $key (sort(keys(%{$changes{$type}}))) {
7970: my %coursehash = &Apache::lonnet::coursedescription($key);
7971: my $coursetitle = $coursehash{'description'};
7972: my $position = $confhash{$type}{$key}{'order'} + 1;
7973: $resulttext .= '<li>';
1.160.6.47 raeburn 7974: foreach my $item ('subject','title','publisher','author') {
7975: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7976: ($type eq 'templates'));
1.160.6.46 raeburn 7977: my $name = $item.':';
7978: $name =~ s/^(\w)/\U$1/;
7979: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7980: }
7981: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7982: if ($type eq 'textbooks') {
7983: if ($confhash{$type}{$key}{'image'}) {
7984: $resulttext .= ' '.&mt('Image: [_1]',
7985: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7986: ' alt="Textbook cover" />').'<br />';
7987: }
7988: }
7989: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7990: }
1.160.6.46 raeburn 7991: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7992: }
7993: }
1.160.6.39 raeburn 7994: if (ref($changes{'validation'}) eq 'HASH') {
7995: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7996: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7997: foreach my $item (@{$validationitemsref}) {
7998: if (exists($changes{'validation'}{$item})) {
7999: if ($item eq 'markup') {
8000: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8001: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8002: } else {
8003: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8004: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8005: }
8006: }
8007: }
8008: if (exists($changes{'validation'}{'dc'})) {
8009: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8010: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8011: }
8012: }
8013: }
1.160.6.30 raeburn 8014: }
1.1 raeburn 8015: $resulttext .= '</ul>';
1.80 raeburn 8016: if (keys(%newenv)) {
8017: &Apache::lonnet::appenv(\%newenv);
8018: }
1.1 raeburn 8019: } else {
1.86 raeburn 8020: if ($context eq 'requestcourses') {
8021: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8022: } elsif ($context eq 'requestauthor') {
8023: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8024: } else {
1.90 weissno 8025: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8026: }
1.1 raeburn 8027: }
8028: } else {
1.11 albertel 8029: $resulttext = '<span class="LC_error">'.
8030: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8031: }
1.160.6.30 raeburn 8032: if ($errors) {
8033: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8034: '<ul>'.$errors.'</ul></p>';
8035: }
1.3 raeburn 8036: return $resulttext;
1.1 raeburn 8037: }
8038:
1.160.6.30 raeburn 8039: sub process_textbook_image {
1.160.6.46 raeburn 8040: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8041: my $filename = $env{'form.'.$caller.'.filename'};
8042: my ($error,$url);
8043: my ($width,$height) = (50,50);
8044: if ($configuserok eq 'ok') {
8045: if ($switchserver) {
8046: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8047: $switchserver);
8048: } elsif ($author_ok eq 'ok') {
8049: my ($result,$imageurl) =
8050: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 8051: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8052: if ($result eq 'ok') {
8053: $url = $imageurl;
8054: } else {
8055: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8056: }
8057: } else {
8058: $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);
8059: }
8060: } else {
8061: $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);
8062: }
8063: return ($url,$error);
8064: }
8065:
1.3 raeburn 8066: sub modify_autoenroll {
1.160.6.24 raeburn 8067: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8068: my ($resulttext,%changes);
8069: my %currautoenroll;
8070: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8071: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8072: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8073: }
8074: }
8075: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8076: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8077: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8078: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8079: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8080: my @offon = ('off','on');
1.17 raeburn 8081: my $sender_uname = $env{'form.sender_uname'};
8082: my $sender_domain = $env{'form.sender_domain'};
8083: if ($sender_domain eq '') {
8084: $sender_uname = '';
8085: } elsif ($sender_uname eq '') {
8086: $sender_domain = '';
8087: }
1.129 raeburn 8088: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8089: my $failsafe = $env{'form.autoenroll_failsafe'};
8090: $failsafe =~ s{^\s+|\s+$}{}g;
8091: if ($failsafe =~ /\D/) {
8092: undef($failsafe);
8093: }
1.1 raeburn 8094: my %autoenrollhash = (
1.129 raeburn 8095: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8096: 'sender_uname' => $sender_uname,
8097: 'sender_domain' => $sender_domain,
8098: 'co-owners' => $coowners,
1.160.6.68 raeburn 8099: 'autofailsafe' => $failsafe,
1.1 raeburn 8100: }
8101: );
1.4 raeburn 8102: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8103: $dom);
1.1 raeburn 8104: if ($putresult eq 'ok') {
8105: if (exists($currautoenroll{'run'})) {
8106: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8107: $changes{'run'} = 1;
8108: }
8109: } elsif ($autorun) {
8110: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8111: $changes{'run'} = 1;
1.1 raeburn 8112: }
8113: }
1.17 raeburn 8114: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8115: $changes{'sender'} = 1;
8116: }
1.17 raeburn 8117: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8118: $changes{'sender'} = 1;
8119: }
1.129 raeburn 8120: if ($currautoenroll{'co-owners'} ne '') {
8121: if ($currautoenroll{'co-owners'} ne $coowners) {
8122: $changes{'coowners'} = 1;
8123: }
8124: } elsif ($coowners) {
8125: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8126: }
8127: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8128: $changes{'autofailsafe'} = 1;
8129: }
1.1 raeburn 8130: if (keys(%changes) > 0) {
8131: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8132: if ($changes{'run'}) {
1.1 raeburn 8133: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8134: }
8135: if ($changes{'sender'}) {
1.17 raeburn 8136: if ($sender_uname eq '' || $sender_domain eq '') {
8137: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8138: } else {
8139: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8140: }
1.1 raeburn 8141: }
1.129 raeburn 8142: if ($changes{'coowners'}) {
8143: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8144: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8145: if (ref($lastactref) eq 'HASH') {
8146: $lastactref->{'domainconfig'} = 1;
8147: }
1.129 raeburn 8148: }
1.160.6.68 raeburn 8149: if ($changes{'autofailsafe'}) {
8150: if ($failsafe ne '') {
8151: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
8152: } else {
8153: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
8154: }
8155: &Apache::lonnet::get_domain_defaults($dom,1);
8156: if (ref($lastactref) eq 'HASH') {
8157: $lastactref->{'domdefaults'} = 1;
8158: }
8159: }
1.1 raeburn 8160: $resulttext .= '</ul>';
8161: } else {
8162: $resulttext = &mt('No changes made to auto-enrollment settings');
8163: }
8164: } else {
1.11 albertel 8165: $resulttext = '<span class="LC_error">'.
8166: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8167: }
1.3 raeburn 8168: return $resulttext;
1.1 raeburn 8169: }
8170:
8171: sub modify_autoupdate {
1.3 raeburn 8172: my ($dom,%domconfig) = @_;
1.1 raeburn 8173: my ($resulttext,%currautoupdate,%fields,%changes);
8174: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8175: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8176: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8177: }
8178: }
8179: my @offon = ('off','on');
8180: my %title = &Apache::lonlocal::texthash (
8181: run => 'Auto-update:',
8182: classlists => 'Updates to user information in classlists?'
8183: );
1.44 raeburn 8184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8185: my %fieldtitles = &Apache::lonlocal::texthash (
8186: id => 'Student/Employee ID',
1.20 raeburn 8187: permanentemail => 'E-mail address',
1.1 raeburn 8188: lastname => 'Last Name',
8189: firstname => 'First Name',
8190: middlename => 'Middle Name',
1.132 raeburn 8191: generation => 'Generation',
1.1 raeburn 8192: );
1.142 raeburn 8193: $othertitle = &mt('All users');
1.1 raeburn 8194: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8195: $othertitle = &mt('Other users');
1.1 raeburn 8196: }
8197: foreach my $key (keys(%env)) {
8198: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8199: my ($usertype,$item) = ($1,$2);
8200: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8201: if ($usertype eq 'default') {
8202: push(@{$fields{$1}},$2);
8203: } elsif (ref($types) eq 'ARRAY') {
8204: if (grep(/^\Q$usertype\E$/,@{$types})) {
8205: push(@{$fields{$1}},$2);
8206: }
8207: }
8208: }
1.1 raeburn 8209: }
8210: }
1.131 raeburn 8211: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8212: @lockablenames = sort(@lockablenames);
8213: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8214: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8215: if (@changed) {
8216: $changes{'lockablenames'} = 1;
8217: }
8218: } else {
8219: if (@lockablenames) {
8220: $changes{'lockablenames'} = 1;
8221: }
8222: }
1.1 raeburn 8223: my %updatehash = (
8224: autoupdate => { run => $env{'form.autoupdate_run'},
8225: classlists => $env{'form.classlists'},
8226: fields => {%fields},
1.131 raeburn 8227: lockablenames => \@lockablenames,
1.1 raeburn 8228: }
8229: );
8230: foreach my $key (keys(%currautoupdate)) {
8231: if (($key eq 'run') || ($key eq 'classlists')) {
8232: if (exists($updatehash{autoupdate}{$key})) {
8233: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8234: $changes{$key} = 1;
8235: }
8236: }
8237: } elsif ($key eq 'fields') {
8238: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8239: foreach my $item (@{$types},'default') {
1.1 raeburn 8240: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8241: my $change = 0;
8242: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8243: if (!exists($fields{$item})) {
8244: $change = 1;
1.132 raeburn 8245: last;
1.1 raeburn 8246: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8247: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8248: $change = 1;
1.132 raeburn 8249: last;
1.1 raeburn 8250: }
8251: }
8252: }
8253: if ($change) {
8254: push(@{$changes{$key}},$item);
8255: }
1.26 raeburn 8256: }
1.1 raeburn 8257: }
8258: }
1.131 raeburn 8259: } elsif ($key eq 'lockablenames') {
8260: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8261: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8262: if (@changed) {
8263: $changes{'lockablenames'} = 1;
8264: }
8265: } else {
8266: if (@lockablenames) {
8267: $changes{'lockablenames'} = 1;
8268: }
8269: }
8270: }
8271: }
8272: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8273: if (@lockablenames) {
8274: $changes{'lockablenames'} = 1;
1.1 raeburn 8275: }
8276: }
1.26 raeburn 8277: foreach my $item (@{$types},'default') {
8278: if (defined($fields{$item})) {
8279: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8280: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8281: my $change = 0;
8282: if (ref($fields{$item}) eq 'ARRAY') {
8283: foreach my $type (@{$fields{$item}}) {
8284: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8285: $change = 1;
8286: last;
8287: }
8288: }
8289: }
8290: if ($change) {
8291: push(@{$changes{'fields'}},$item);
8292: }
8293: } else {
1.26 raeburn 8294: push(@{$changes{'fields'}},$item);
8295: }
8296: } else {
8297: push(@{$changes{'fields'}},$item);
1.1 raeburn 8298: }
8299: }
8300: }
8301: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8302: $dom);
8303: if ($putresult eq 'ok') {
8304: if (keys(%changes) > 0) {
8305: $resulttext = &mt('Changes made:').'<ul>';
8306: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8307: if ($key eq 'lockablenames') {
8308: $resulttext .= '<li>';
8309: if (@lockablenames) {
8310: $usertypes->{'default'} = $othertitle;
8311: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8312: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8313: } else {
8314: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8315: }
8316: $resulttext .= '</li>';
8317: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8318: foreach my $item (@{$changes{$key}}) {
8319: my @newvalues;
8320: foreach my $type (@{$fields{$item}}) {
8321: push(@newvalues,$fieldtitles{$type});
8322: }
1.3 raeburn 8323: my $newvaluestr;
8324: if (@newvalues > 0) {
8325: $newvaluestr = join(', ',@newvalues);
8326: } else {
8327: $newvaluestr = &mt('none');
1.6 raeburn 8328: }
1.1 raeburn 8329: if ($item eq 'default') {
1.26 raeburn 8330: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8331: } else {
1.26 raeburn 8332: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8333: }
8334: }
8335: } else {
8336: my $newvalue;
8337: if ($key eq 'run') {
8338: $newvalue = $offon[$env{'form.autoupdate_run'}];
8339: } else {
8340: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8341: }
1.1 raeburn 8342: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8343: }
8344: }
8345: $resulttext .= '</ul>';
8346: } else {
1.3 raeburn 8347: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8348: }
8349: } else {
1.11 albertel 8350: $resulttext = '<span class="LC_error">'.
8351: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8352: }
1.3 raeburn 8353: return $resulttext;
1.1 raeburn 8354: }
8355:
1.125 raeburn 8356: sub modify_autocreate {
8357: my ($dom,%domconfig) = @_;
8358: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8359: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8360: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8361: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8362: }
8363: }
8364: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8365: req => 'Auto-creation of validated requests for official courses',
8366: xmldc => 'Identity of course creator of courses from XML files',
8367: );
8368: my @types = ('xml','req');
8369: foreach my $item (@types) {
8370: $newvals{$item} = $env{'form.autocreate_'.$item};
8371: $newvals{$item} =~ s/\D//g;
8372: $newvals{$item} = 0 if ($newvals{$item} eq '');
8373: }
8374: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8375: my %domcoords = &get_active_dcs($dom);
8376: unless (exists($domcoords{$newvals{'xmldc'}})) {
8377: $newvals{'xmldc'} = '';
8378: }
8379: %autocreatehash = (
8380: autocreate => { xml => $newvals{'xml'},
8381: req => $newvals{'req'},
8382: }
8383: );
8384: if ($newvals{'xmldc'} ne '') {
8385: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8386: }
8387: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8388: $dom);
8389: if ($putresult eq 'ok') {
8390: my @items = @types;
8391: if ($newvals{'xml'}) {
8392: push(@items,'xmldc');
8393: }
8394: foreach my $item (@items) {
8395: if (exists($currautocreate{$item})) {
8396: if ($currautocreate{$item} ne $newvals{$item}) {
8397: $changes{$item} = 1;
8398: }
8399: } elsif ($newvals{$item}) {
8400: $changes{$item} = 1;
8401: }
8402: }
8403: if (keys(%changes) > 0) {
8404: my @offon = ('off','on');
8405: $resulttext = &mt('Changes made:').'<ul>';
8406: foreach my $item (@types) {
8407: if ($changes{$item}) {
8408: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8409: $resulttext .= '<li>'.
8410: &mt("$title{$item} set to [_1]$newtxt [_2]",
8411: '<b>','</b>').
8412: '</li>';
1.125 raeburn 8413: }
8414: }
8415: if ($changes{'xmldc'}) {
8416: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8417: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8418: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8419: }
8420: $resulttext .= '</ul>';
8421: } else {
8422: $resulttext = &mt('No changes made to auto-creation settings');
8423: }
8424: } else {
8425: $resulttext = '<span class="LC_error">'.
8426: &mt('An error occurred: [_1]',$putresult).'</span>';
8427: }
8428: return $resulttext;
8429: }
8430:
1.23 raeburn 8431: sub modify_directorysrch {
8432: my ($dom,%domconfig) = @_;
8433: my ($resulttext,%changes);
8434: my %currdirsrch;
8435: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8436: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8437: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8438: }
8439: }
1.160.6.72 raeburn 8440: my %title = ( available => 'Institutional directory search available',
8441: localonly => 'Other domains can search institution',
8442: lcavailable => 'LON-CAPA directory search available',
8443: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 8444: searchby => 'Search types',
8445: searchtypes => 'Search latitude');
8446: my @offon = ('off','on');
1.24 raeburn 8447: my @otherdoms = ('Yes','No');
1.23 raeburn 8448:
1.25 raeburn 8449: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8450: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8451: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8452:
1.44 raeburn 8453: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8454: if (keys(%{$usertypes}) == 0) {
8455: @cansearch = ('default');
8456: } else {
8457: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8458: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8459: if (!grep(/^\Q$type\E$/,@cansearch)) {
8460: push(@{$changes{'cansearch'}},$type);
8461: }
1.23 raeburn 8462: }
1.26 raeburn 8463: foreach my $type (@cansearch) {
8464: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8465: push(@{$changes{'cansearch'}},$type);
8466: }
1.23 raeburn 8467: }
1.26 raeburn 8468: } else {
8469: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8470: }
8471: }
8472:
8473: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8474: foreach my $by (@{$currdirsrch{'searchby'}}) {
8475: if (!grep(/^\Q$by\E$/,@searchby)) {
8476: push(@{$changes{'searchby'}},$by);
8477: }
8478: }
8479: foreach my $by (@searchby) {
8480: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8481: push(@{$changes{'searchby'}},$by);
8482: }
8483: }
8484: } else {
8485: push(@{$changes{'searchby'}},@searchby);
8486: }
1.25 raeburn 8487:
8488: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8489: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8490: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8491: push(@{$changes{'searchtypes'}},$type);
8492: }
8493: }
8494: foreach my $type (@searchtypes) {
8495: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8496: push(@{$changes{'searchtypes'}},$type);
8497: }
8498: }
8499: } else {
8500: if (exists($currdirsrch{'searchtypes'})) {
8501: foreach my $type (@searchtypes) {
8502: if ($type ne $currdirsrch{'searchtypes'}) {
8503: push(@{$changes{'searchtypes'}},$type);
8504: }
8505: }
8506: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8507: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8508: }
8509: } else {
8510: push(@{$changes{'searchtypes'}},@searchtypes);
8511: }
8512: }
8513:
1.23 raeburn 8514: my %dirsrch_hash = (
8515: directorysrch => { available => $env{'form.dirsrch_available'},
8516: cansearch => \@cansearch,
1.160.6.72 raeburn 8517: localonly => $env{'form.dirsrch_instlocalonly'},
8518: lclocalonly => $env{'form.dirsrch_domlocalonly'},
8519: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 8520: searchby => \@searchby,
1.25 raeburn 8521: searchtypes => \@searchtypes,
1.23 raeburn 8522: }
8523: );
8524: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8525: $dom);
8526: if ($putresult eq 'ok') {
8527: if (exists($currdirsrch{'available'})) {
8528: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8529: $changes{'available'} = 1;
8530: }
8531: } else {
8532: if ($env{'form.dirsrch_available'} eq '1') {
8533: $changes{'available'} = 1;
8534: }
8535: }
1.160.6.72 raeburn 8536: if (exists($currdirsrch{'lcavailable'})) {
8537: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
8538: $changes{'lcavailable'} = 1;
1.24 raeburn 8539: }
8540: } else {
1.160.6.72 raeburn 8541: if ($env{'form.dirsrch_lcavailable'} eq '1') {
8542: $changes{'lcavailable'} = 1;
8543: }
8544: }
8545: if (exists($currdirsrch{'localonly'})) {
8546: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 8547: $changes{'localonly'} = 1;
8548: }
1.160.6.72 raeburn 8549: } else {
8550: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
8551: $changes{'localonly'} = 1;
8552: }
8553: }
8554: if (exists($currdirsrch{'lclocalonly'})) {
8555: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
8556: $changes{'lclocalonly'} = 1;
8557: }
8558: } else {
8559: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
8560: $changes{'lclocalonly'} = 1;
8561: }
1.24 raeburn 8562: }
1.23 raeburn 8563: if (keys(%changes) > 0) {
8564: $resulttext = &mt('Changes made:').'<ul>';
8565: if ($changes{'available'}) {
8566: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8567: }
1.160.6.72 raeburn 8568: if ($changes{'lcavailable'}) {
8569: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
8570: }
1.24 raeburn 8571: if ($changes{'localonly'}) {
1.160.6.72 raeburn 8572: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
8573: }
8574: if ($changes{'lclocalonly'}) {
8575: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 8576: }
1.23 raeburn 8577: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8578: my $chgtext;
1.26 raeburn 8579: if (ref($usertypes) eq 'HASH') {
8580: if (keys(%{$usertypes}) > 0) {
8581: foreach my $type (@{$types}) {
8582: if (grep(/^\Q$type\E$/,@cansearch)) {
8583: $chgtext .= $usertypes->{$type}.'; ';
8584: }
8585: }
8586: if (grep(/^default$/,@cansearch)) {
8587: $chgtext .= $othertitle;
8588: } else {
8589: $chgtext =~ s/\; $//;
8590: }
1.160.6.13 raeburn 8591: $resulttext .=
8592: '<li>'.
8593: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8594: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8595: '</li>';
1.23 raeburn 8596: }
8597: }
8598: }
8599: if (ref($changes{'searchby'}) eq 'ARRAY') {
8600: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8601: my $chgtext;
8602: foreach my $type (@{$titleorder}) {
8603: if (grep(/^\Q$type\E$/,@searchby)) {
8604: if (defined($searchtitles->{$type})) {
8605: $chgtext .= $searchtitles->{$type}.'; ';
8606: }
8607: }
8608: }
8609: $chgtext =~ s/\; $//;
8610: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8611: }
1.25 raeburn 8612: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8613: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8614: my $chgtext;
8615: foreach my $type (@{$srchtypeorder}) {
8616: if (grep(/^\Q$type\E$/,@searchtypes)) {
8617: if (defined($srchtypes_desc->{$type})) {
8618: $chgtext .= $srchtypes_desc->{$type}.'; ';
8619: }
8620: }
8621: }
8622: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8623: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8624: }
8625: $resulttext .= '</ul>';
8626: } else {
1.160.6.72 raeburn 8627: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 8628: }
8629: } else {
8630: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8631: &mt('An error occurred: [_1]',$putresult).'</span>';
8632: }
8633: return $resulttext;
8634: }
8635:
1.28 raeburn 8636: sub modify_contacts {
1.160.6.24 raeburn 8637: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8638: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8639: if (ref($domconfig{'contacts'}) eq 'HASH') {
8640: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8641: $currsetting{$key} = $domconfig{'contacts'}{$key};
8642: }
8643: }
1.134 raeburn 8644: my (%others,%to,%bcc);
1.28 raeburn 8645: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8646: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8647: 'requestsmail','updatesmail','idconflictsmail');
8648: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8649: foreach my $type (@mailings) {
8650: @{$newsetting{$type}} =
8651: &Apache::loncommon::get_env_multiple('form.'.$type);
8652: foreach my $item (@contacts) {
8653: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8654: $contacts_hash{contacts}{$type}{$item} = 1;
8655: } else {
8656: $contacts_hash{contacts}{$type}{$item} = 0;
8657: }
8658: }
8659: $others{$type} = $env{'form.'.$type.'_others'};
8660: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8661: if ($type eq 'helpdeskmail') {
8662: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8663: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8664: }
1.28 raeburn 8665: }
8666: foreach my $item (@contacts) {
8667: $to{$item} = $env{'form.'.$item};
8668: $contacts_hash{'contacts'}{$item} = $to{$item};
8669: }
1.160.6.23 raeburn 8670: foreach my $item (@toggles) {
8671: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8672: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8673: }
8674: }
1.28 raeburn 8675: if (keys(%currsetting) > 0) {
8676: foreach my $item (@contacts) {
8677: if ($to{$item} ne $currsetting{$item}) {
8678: $changes{$item} = 1;
8679: }
8680: }
8681: foreach my $type (@mailings) {
8682: foreach my $item (@contacts) {
8683: if (ref($currsetting{$type}) eq 'HASH') {
8684: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8685: push(@{$changes{$type}},$item);
8686: }
8687: } else {
8688: push(@{$changes{$type}},@{$newsetting{$type}});
8689: }
8690: }
8691: if ($others{$type} ne $currsetting{$type}{'others'}) {
8692: push(@{$changes{$type}},'others');
8693: }
1.134 raeburn 8694: if ($type eq 'helpdeskmail') {
8695: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8696: push(@{$changes{$type}},'bcc');
8697: }
8698: }
1.28 raeburn 8699: }
8700: } else {
8701: my %default;
8702: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8703: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8704: $default{'errormail'} = 'adminemail';
8705: $default{'packagesmail'} = 'adminemail';
8706: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8707: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8708: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8709: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8710: foreach my $item (@contacts) {
8711: if ($to{$item} ne $default{$item}) {
8712: $changes{$item} = 1;
1.160.6.23 raeburn 8713: }
1.28 raeburn 8714: }
8715: foreach my $type (@mailings) {
8716: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8717:
8718: push(@{$changes{$type}},@{$newsetting{$type}});
8719: }
8720: if ($others{$type} ne '') {
8721: push(@{$changes{$type}},'others');
1.134 raeburn 8722: }
8723: if ($type eq 'helpdeskmail') {
8724: if ($bcc{$type} ne '') {
8725: push(@{$changes{$type}},'bcc');
8726: }
8727: }
1.28 raeburn 8728: }
8729: }
1.160.6.23 raeburn 8730: foreach my $item (@toggles) {
8731: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8732: $changes{$item} = 1;
8733: } elsif ((!$env{'form.'.$item}) &&
8734: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8735: $changes{$item} = 1;
8736: }
8737: }
1.28 raeburn 8738: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8739: $dom);
8740: if ($putresult eq 'ok') {
8741: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8742: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8743: if (ref($lastactref) eq 'HASH') {
8744: $lastactref->{'domainconfig'} = 1;
8745: }
1.28 raeburn 8746: my ($titles,$short_titles) = &contact_titles();
8747: $resulttext = &mt('Changes made:').'<ul>';
8748: foreach my $item (@contacts) {
8749: if ($changes{$item}) {
8750: $resulttext .= '<li>'.$titles->{$item}.
8751: &mt(' set to: ').
8752: '<span class="LC_cusr_emph">'.
8753: $to{$item}.'</span></li>';
8754: }
8755: }
8756: foreach my $type (@mailings) {
8757: if (ref($changes{$type}) eq 'ARRAY') {
8758: $resulttext .= '<li>'.$titles->{$type}.': ';
8759: my @text;
8760: foreach my $item (@{$newsetting{$type}}) {
8761: push(@text,$short_titles->{$item});
8762: }
8763: if ($others{$type} ne '') {
8764: push(@text,$others{$type});
8765: }
8766: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8767: join(', ',@text).'</span>';
8768: if ($type eq 'helpdeskmail') {
8769: if ($bcc{$type} ne '') {
8770: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8771: }
8772: }
8773: $resulttext .= '</li>';
1.28 raeburn 8774: }
8775: }
1.160.6.23 raeburn 8776: my @offon = ('off','on');
8777: if ($changes{'reporterrors'}) {
8778: $resulttext .= '<li>'.
8779: &mt('E-mail error reports to [_1] set to "'.
8780: $offon[$env{'form.reporterrors'}].'".',
8781: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8782: &mt('LON-CAPA core group - MSU'),600,500)).
8783: '</li>';
8784: }
8785: if ($changes{'reportupdates'}) {
8786: $resulttext .= '<li>'.
8787: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8788: $offon[$env{'form.reportupdates'}].'".',
8789: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8790: &mt('LON-CAPA core group - MSU'),600,500)).
8791: '</li>';
8792: }
1.28 raeburn 8793: $resulttext .= '</ul>';
8794: } else {
1.34 raeburn 8795: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8796: }
8797: } else {
8798: $resulttext = '<span class="LC_error">'.
8799: &mt('An error occurred: [_1].',$putresult).'</span>';
8800: }
8801: return $resulttext;
8802: }
8803:
8804: sub modify_usercreation {
1.27 raeburn 8805: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8806: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8807: my $warningmsg;
1.27 raeburn 8808: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8809: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8810: if ($key eq 'cancreate') {
8811: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8812: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8813: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 8814: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8815: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 8816: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8817: } else {
8818: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8819: }
1.50 raeburn 8820: }
1.43 raeburn 8821: }
1.160.6.34 raeburn 8822: } elsif ($key eq 'email_rule') {
8823: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8824: } else {
8825: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8826: }
8827: }
1.34 raeburn 8828: }
1.160.6.34 raeburn 8829: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8830: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8831: my @contexts = ('author','course','requestcrs');
8832: foreach my $item(@contexts) {
8833: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8834: }
1.34 raeburn 8835: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8836: foreach my $item (@contexts) {
1.160.6.34 raeburn 8837: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8838: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8839: }
1.27 raeburn 8840: }
1.34 raeburn 8841: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8842: foreach my $item (@contexts) {
1.43 raeburn 8843: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8844: if ($cancreate{$item} ne 'any') {
8845: push(@{$changes{'cancreate'}},$item);
8846: }
8847: } else {
8848: if ($cancreate{$item} ne 'none') {
8849: push(@{$changes{'cancreate'}},$item);
8850: }
1.27 raeburn 8851: }
8852: }
8853: } else {
1.43 raeburn 8854: foreach my $item (@contexts) {
1.34 raeburn 8855: push(@{$changes{'cancreate'}},$item);
8856: }
1.27 raeburn 8857: }
1.34 raeburn 8858:
1.27 raeburn 8859: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8860: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8861: if (!grep(/^\Q$type\E$/,@username_rule)) {
8862: push(@{$changes{'username_rule'}},$type);
8863: }
8864: }
8865: foreach my $type (@username_rule) {
8866: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8867: push(@{$changes{'username_rule'}},$type);
8868: }
8869: }
8870: } else {
8871: push(@{$changes{'username_rule'}},@username_rule);
8872: }
8873:
1.32 raeburn 8874: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8875: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8876: if (!grep(/^\Q$type\E$/,@id_rule)) {
8877: push(@{$changes{'id_rule'}},$type);
8878: }
8879: }
8880: foreach my $type (@id_rule) {
8881: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8882: push(@{$changes{'id_rule'}},$type);
8883: }
8884: }
8885: } else {
8886: push(@{$changes{'id_rule'}},@id_rule);
8887: }
8888:
1.43 raeburn 8889: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8890: my @authtypes = ('int','krb4','krb5','loc');
8891: my %authhash;
1.43 raeburn 8892: foreach my $item (@authen_contexts) {
1.28 raeburn 8893: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8894: foreach my $auth (@authtypes) {
8895: if (grep(/^\Q$auth\E$/,@authallowed)) {
8896: $authhash{$item}{$auth} = 1;
8897: } else {
8898: $authhash{$item}{$auth} = 0;
8899: }
8900: }
8901: }
8902: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8903: foreach my $item (@authen_contexts) {
1.28 raeburn 8904: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8905: foreach my $auth (@authtypes) {
8906: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8907: push(@{$changes{'authtypes'}},$item);
8908: last;
8909: }
8910: }
8911: }
8912: }
8913: } else {
1.43 raeburn 8914: foreach my $item (@authen_contexts) {
1.28 raeburn 8915: push(@{$changes{'authtypes'}},$item);
8916: }
8917: }
8918:
1.160.6.34 raeburn 8919: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8920: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8921: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8922: $save_usercreate{'id_rule'} = \@id_rule;
8923: $save_usercreate{'username_rule'} = \@username_rule,
8924: $save_usercreate{'authtypes'} = \%authhash;
8925:
1.27 raeburn 8926: my %usercreation_hash = (
1.160.6.34 raeburn 8927: usercreation => \%save_usercreate,
8928: );
1.27 raeburn 8929:
8930: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8931: $dom);
1.50 raeburn 8932:
1.160.6.34 raeburn 8933: if ($putresult eq 'ok') {
8934: if (keys(%changes) > 0) {
8935: $resulttext = &mt('Changes made:').'<ul>';
8936: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8937: my %lt = &usercreation_types();
8938: foreach my $type (@{$changes{'cancreate'}}) {
8939: my $chgtext = $lt{$type}.', ';
8940: if ($cancreate{$type} eq 'none') {
8941: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8942: } elsif ($cancreate{$type} eq 'any') {
8943: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8944: } elsif ($cancreate{$type} eq 'official') {
8945: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8946: } elsif ($cancreate{$type} eq 'unofficial') {
8947: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8948: }
8949: $resulttext .= '<li>'.$chgtext.'</li>';
8950: }
8951: }
8952: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8953: my ($rules,$ruleorder) =
8954: &Apache::lonnet::inst_userrules($dom,'username');
8955: my $chgtext = '<ul>';
8956: foreach my $type (@username_rule) {
8957: if (ref($rules->{$type}) eq 'HASH') {
8958: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8959: }
8960: }
8961: $chgtext .= '</ul>';
8962: if (@username_rule > 0) {
8963: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8964: } else {
8965: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8966: }
8967: }
8968: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8969: my ($idrules,$idruleorder) =
8970: &Apache::lonnet::inst_userrules($dom,'id');
8971: my $chgtext = '<ul>';
8972: foreach my $type (@id_rule) {
8973: if (ref($idrules->{$type}) eq 'HASH') {
8974: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8975: }
8976: }
8977: $chgtext .= '</ul>';
8978: if (@id_rule > 0) {
8979: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8980: } else {
8981: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8982: }
8983: }
8984: my %authname = &authtype_names();
8985: my %context_title = &context_names();
8986: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8987: my $chgtext = '<ul>';
8988: foreach my $type (@{$changes{'authtypes'}}) {
8989: my @allowed;
8990: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8991: foreach my $auth (@authtypes) {
8992: if ($authhash{$type}{$auth}) {
8993: push(@allowed,$authname{$auth});
8994: }
8995: }
8996: if (@allowed > 0) {
8997: $chgtext .= join(', ',@allowed).'</li>';
8998: } else {
8999: $chgtext .= &mt('none').'</li>';
9000: }
9001: }
9002: $chgtext .= '</ul>';
9003: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9004: $resulttext .= '</li>';
9005: }
9006: $resulttext .= '</ul>';
9007: } else {
9008: $resulttext = &mt('No changes made to user creation settings');
9009: }
9010: } else {
9011: $resulttext = '<span class="LC_error">'.
9012: &mt('An error occurred: [_1]',$putresult).'</span>';
9013: }
9014: if ($warningmsg ne '') {
9015: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9016: }
9017: return $resulttext;
9018: }
9019:
9020: sub modify_selfcreation {
9021: my ($dom,%domconfig) = @_;
9022: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9023: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9024: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9025: if (ref($types) eq 'ARRAY') {
9026: $usertypes->{'default'} = $othertitle;
9027: push(@{$types},'default');
9028: }
1.160.6.34 raeburn 9029: #
9030: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9031: #
9032: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9033: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9034: if ($key eq 'cancreate') {
9035: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9036: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9037: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9038: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9039: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9040: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9041: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9042: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9043: } else {
9044: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9045: }
9046: }
9047: }
9048: } elsif ($key eq 'email_rule') {
9049: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9050: } else {
9051: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9052: }
9053: }
9054: }
9055: #
9056: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9057: #
9058: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9059: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9060: if ($key eq 'selfcreate') {
9061: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9062: } else {
9063: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9064: }
9065: }
9066: }
9067:
9068: my @contexts = ('selfcreate');
9069: @{$cancreate{'selfcreate'}} = ();
9070: %{$cancreate{'emailusername'}} = ();
9071: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9072: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9073: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9074: my %selfcreatetypes = (
9075: sso => 'users authenticated by institutional single sign on',
9076: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9077: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9078: );
1.160.6.34 raeburn 9079: #
9080: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9081: # is permitted.
9082: #
1.160.6.40 raeburn 9083:
9084: my @statuses;
9085: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9086: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9087: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9088: }
9089: }
9090: push(@statuses,'default');
9091:
1.160.6.35 raeburn 9092: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9093: if ($item eq 'email') {
1.160.6.40 raeburn 9094: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9095: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9096: push(@contexts,'selfcreateprocessing');
9097: foreach my $type (@statuses) {
9098: if ($type eq 'default') {
9099: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9100: } else {
9101: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9102: }
9103: }
1.160.6.34 raeburn 9104: }
9105: } else {
9106: if ($env{'form.cancreate_'.$item}) {
9107: push(@{$cancreate{'selfcreate'}},$item);
9108: }
9109: }
9110: }
9111: my (@email_rule,%userinfo,%savecaptcha);
9112: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9113: #
1.160.6.35 raeburn 9114: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9115: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 9116: #
1.160.6.40 raeburn 9117:
1.160.6.48 raeburn 9118: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9119: push(@contexts,'emailusername');
1.160.6.35 raeburn 9120: if (ref($types) eq 'ARRAY') {
9121: foreach my $type (@{$types}) {
9122: if (ref($infofields) eq 'ARRAY') {
9123: foreach my $field (@{$infofields}) {
9124: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9125: $cancreate{'emailusername'}{$type}{$field} = $1;
9126: }
9127: }
1.160.6.34 raeburn 9128: }
9129: }
9130: }
9131: #
9132: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9133: # queued requests for self-creation of account using e-mail address as username
9134: #
9135:
9136: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9137: @approvalnotify = sort(@approvalnotify);
9138: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9139: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9140: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9141: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9142: push(@{$changes{'cancreate'}},'notify');
9143: }
9144: } else {
9145: if ($cancreate{'notify'}{'approval'}) {
9146: push(@{$changes{'cancreate'}},'notify');
9147: }
9148: }
9149: } elsif ($cancreate{'notify'}{'approval'}) {
9150: push(@{$changes{'cancreate'}},'notify');
9151: }
9152:
9153: #
9154: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9155: #
9156: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9157: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9158: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9159: if (@{$curr_usercreation{'email_rule'}} > 0) {
9160: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9161: if (!grep(/^\Q$type\E$/,@email_rule)) {
9162: push(@{$changes{'email_rule'}},$type);
9163: }
9164: }
9165: }
9166: if (@email_rule > 0) {
9167: foreach my $type (@email_rule) {
9168: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9169: push(@{$changes{'email_rule'}},$type);
9170: }
9171: }
9172: }
9173: } elsif (@email_rule > 0) {
9174: push(@{$changes{'email_rule'}},@email_rule);
9175: }
9176: }
9177: #
1.160.6.40 raeburn 9178: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9179: # institutional log-in.
9180: #
9181: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9182: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9183: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9184: ($domdefaults{'auth_def'} eq 'localauth'))) {
9185: $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.').' '.
9186: &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.');
9187: }
9188: }
9189: my @fields = ('lastname','firstname','middlename','generation',
9190: 'permanentemail','id');
1.160.6.44 raeburn 9191: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9192: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9193: #
9194: # Where usernames may created for institutional log-in and/or institutional single sign on:
9195: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9196: # may self-create accounts
9197: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9198: # which the user may supply, if institutional data is unavailable.
9199: #
9200: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9201: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9202: if (@{$types} > 1) {
1.160.6.34 raeburn 9203: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9204: push(@contexts,'statustocreate');
9205: } else {
9206: undef($cancreate{'statustocreate'});
9207: }
9208: foreach my $type (@{$types}) {
9209: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9210: foreach my $field (@fields) {
9211: if (grep(/^\Q$field\E$/,@modifiable)) {
9212: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9213: } else {
9214: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9215: }
9216: }
9217: }
9218: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9219: foreach my $type (@{$types}) {
9220: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9221: foreach my $field (@fields) {
9222: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9223: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9224: push(@{$changes{'selfcreate'}},$type);
9225: last;
9226: }
9227: }
9228: }
9229: }
9230: } else {
9231: foreach my $type (@{$types}) {
9232: push(@{$changes{'selfcreate'}},$type);
9233: }
9234: }
9235: }
1.160.6.44 raeburn 9236: foreach my $field (@shibfields) {
9237: if ($env{'form.shibenv_'.$field} ne '') {
9238: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9239: }
9240: }
9241: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9242: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9243: foreach my $field (@shibfields) {
9244: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9245: push(@{$changes{'cancreate'}},'shibenv');
9246: }
9247: }
9248: } else {
9249: foreach my $field (@shibfields) {
9250: if ($env{'form.shibenv_'.$field}) {
9251: push(@{$changes{'cancreate'}},'shibenv');
9252: last;
9253: }
9254: }
9255: }
9256: }
1.160.6.34 raeburn 9257: }
9258: foreach my $item (@contexts) {
9259: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9260: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9261: if (ref($cancreate{$item}) eq 'ARRAY') {
9262: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9263: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9264: push(@{$changes{'cancreate'}},$item);
9265: }
9266: }
9267: }
9268: }
9269: if (ref($cancreate{$item}) eq 'ARRAY') {
9270: foreach my $type (@{$cancreate{$item}}) {
9271: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9272: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9273: push(@{$changes{'cancreate'}},$item);
9274: }
9275: }
9276: }
9277: }
9278: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9279: if (ref($cancreate{$item}) eq 'HASH') {
9280: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 9281: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9282: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9283: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9284: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9285: push(@{$changes{'cancreate'}},$item);
9286: }
9287: }
9288: }
1.160.6.40 raeburn 9289: } elsif ($item eq 'selfcreateprocessing') {
9290: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9291: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9292: push(@{$changes{'cancreate'}},$item);
9293: }
9294: }
1.160.6.35 raeburn 9295: } else {
9296: if (!$cancreate{$item}{$curr}) {
9297: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9298: push(@{$changes{'cancreate'}},$item);
9299: }
1.160.6.34 raeburn 9300: }
9301: }
9302: }
9303: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 9304: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9305: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9306: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9307: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9308: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9309: push(@{$changes{'cancreate'}},$item);
9310: }
9311: }
9312: } else {
9313: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9314: push(@{$changes{'cancreate'}},$item);
9315: }
9316: }
9317: }
1.160.6.40 raeburn 9318: } elsif ($item eq 'selfcreateprocessing') {
9319: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9320: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9321: push(@{$changes{'cancreate'}},$item);
9322: }
9323: }
1.160.6.35 raeburn 9324: } else {
9325: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9326: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9327: push(@{$changes{'cancreate'}},$item);
9328: }
1.160.6.34 raeburn 9329: }
9330: }
9331: }
9332: }
9333: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9334: if (ref($cancreate{$item}) eq 'ARRAY') {
9335: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9336: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9337: push(@{$changes{'cancreate'}},$item);
9338: }
9339: }
9340: } elsif (ref($cancreate{$item}) eq 'HASH') {
9341: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9342: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9343: push(@{$changes{'cancreate'}},$item);
9344: }
9345: }
9346: }
9347: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9348: if (ref($cancreate{$item}) eq 'HASH') {
9349: foreach my $type (keys(%{$cancreate{$item}})) {
9350: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9351: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9352: if ($cancreate{$item}{$type}{$field}) {
9353: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9354: push(@{$changes{'cancreate'}},$item);
9355: }
9356: last;
9357: }
9358: }
9359: }
9360: }
1.160.6.34 raeburn 9361: }
9362: }
9363: }
9364: #
9365: # Populate %save_usercreate hash with updates to self-creation configuration.
9366: #
9367: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9368: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 9369: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 9370: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9371: if (ref($cancreate{'notify'}) eq 'HASH') {
9372: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9373: }
1.160.6.40 raeburn 9374: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9375: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9376: }
1.160.6.34 raeburn 9377: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9378: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9379: }
1.160.6.44 raeburn 9380: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9381: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9382: }
1.160.6.34 raeburn 9383: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9384: $save_usercreate{'emailrule'} = \@email_rule;
9385:
9386: my %userconfig_hash = (
9387: usercreation => \%save_usercreate,
9388: usermodification => \%save_usermodify,
9389: );
9390: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9391: $dom);
9392: #
9393: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9394: #
1.27 raeburn 9395: if ($putresult eq 'ok') {
9396: if (keys(%changes) > 0) {
9397: $resulttext = &mt('Changes made:').'<ul>';
9398: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9399: my %lt = &selfcreation_types();
1.34 raeburn 9400: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9401: my $chgtext;
1.45 raeburn 9402: if ($type eq 'selfcreate') {
1.50 raeburn 9403: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9404: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9405: } else {
1.160.6.34 raeburn 9406: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9407: '<ul>';
1.50 raeburn 9408: foreach my $case (@{$cancreate{$type}}) {
9409: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9410: }
9411: $chgtext .= '</ul>';
1.100 raeburn 9412: if (ref($cancreate{$type}) eq 'ARRAY') {
9413: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9414: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9415: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9416: $chgtext .= '<br />'.
9417: '<span class="LC_warning">'.
9418: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9419: '</span>';
1.100 raeburn 9420: }
9421: }
9422: }
9423: }
1.43 raeburn 9424: }
1.160.6.44 raeburn 9425: } elsif ($type eq 'shibenv') {
9426: if (keys(%{$cancreate{$type}}) == 0) {
9427: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9428: } else {
9429: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9430: '<ul>';
9431: foreach my $field (@shibfields) {
9432: next if ($cancreate{$type}{$field} eq '');
9433: if ($field eq 'inststatus') {
9434: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9435: } else {
9436: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9437: }
9438: }
9439: $chgtext .= '</ul>';
9440: }
1.93 raeburn 9441: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9442: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9443: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9444: if (@{$cancreate{'selfcreate'}} > 0) {
9445: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9446: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9447: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9448: $chgtext .= '<br />'.
9449: '<span class="LC_warning">'.
9450: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9451: '</span>';
9452: }
1.96 raeburn 9453: } elsif (ref($usertypes) eq 'HASH') {
9454: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9455: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9456: } else {
9457: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9458: }
9459: $chgtext .= '<ul>';
9460: foreach my $case (@{$cancreate{$type}}) {
9461: if ($case eq 'default') {
9462: $chgtext .= '<li>'.$othertitle.'</li>';
9463: } else {
9464: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9465: }
9466: }
1.100 raeburn 9467: $chgtext .= '</ul>';
9468: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9469: $chgtext .= '<br /><span class="LC_warning">'.
9470: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9471: '</span>';
1.100 raeburn 9472: }
9473: }
9474: } else {
9475: if (@{$cancreate{$type}} == 0) {
9476: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9477: } else {
9478: $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 9479: }
9480: }
9481: }
1.160.6.40 raeburn 9482: } elsif ($type eq 'selfcreateprocessing') {
9483: my %choices = &Apache::lonlocal::texthash (
9484: automatic => 'Automatic approval',
9485: approval => 'Queued for approval',
9486: );
9487: if (@statuses > 1) {
9488: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9489: '<ul>';
9490: foreach my $type (@statuses) {
9491: if ($type eq 'default') {
9492: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9493: } else {
9494: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9495: }
9496: }
9497: $chgtext .= '</ul>';
9498: } else {
9499: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9500: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9501: }
1.160.6.5 raeburn 9502: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9503: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9504: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9505: } else {
9506: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9507: if ($captchas{$savecaptcha{$type}}) {
9508: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9509: } else {
9510: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9511: }
9512: }
9513: } elsif ($type eq 'recaptchakeys') {
9514: my ($privkey,$pubkey);
1.160.6.34 raeburn 9515: if (ref($savecaptcha{$type}) eq 'HASH') {
9516: $pubkey = $savecaptcha{$type}{'public'};
9517: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9518: }
9519: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9520: if (!$pubkey) {
9521: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9522: } else {
9523: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9524: }
9525: if (!$privkey) {
9526: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9527: } else {
9528: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9529: }
9530: $chgtext .= '</ul>';
1.160.6.69 raeburn 9531: } elsif ($type eq 'recaptchaversion') {
9532: if ($savecaptcha{'captcha'} eq 'recaptcha') {
9533: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
9534: }
1.160.6.34 raeburn 9535: } elsif ($type eq 'emailusername') {
9536: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9537: if (ref($types) eq 'ARRAY') {
9538: foreach my $type (@{$types}) {
9539: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9540: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9541: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 9542: '<ul>';
9543: foreach my $field (@{$infofields}) {
9544: if ($cancreate{'emailusername'}{$type}{$field}) {
9545: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9546: }
9547: }
1.160.6.50 raeburn 9548: $chgtext .= '</ul>';
9549: } else {
9550: $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.160.6.35 raeburn 9551: }
9552: } else {
1.160.6.50 raeburn 9553: $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.160.6.34 raeburn 9554: }
9555: }
9556: }
9557: }
9558: } elsif ($type eq 'notify') {
9559: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9560: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9561: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9562: if ($cancreate{'notify'}{'approval'}) {
9563: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9564: }
9565: }
1.43 raeburn 9566: }
1.34 raeburn 9567: }
1.160.6.34 raeburn 9568: if ($chgtext) {
9569: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9570: }
9571: }
9572: }
1.43 raeburn 9573: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9574: my ($emailrules,$emailruleorder) =
9575: &Apache::lonnet::inst_userrules($dom,'email');
9576: my $chgtext = '<ul>';
9577: foreach my $type (@email_rule) {
9578: if (ref($emailrules->{$type}) eq 'HASH') {
9579: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9580: }
9581: }
9582: $chgtext .= '</ul>';
9583: if (@email_rule > 0) {
1.160.6.34 raeburn 9584: $resulttext .= '<li>'.
9585: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9586: $chgtext.
9587: '</li>';
1.43 raeburn 9588: } else {
1.160.6.34 raeburn 9589: $resulttext .= '<li>'.
9590: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9591: '</li>';
1.43 raeburn 9592: }
9593: }
1.160.6.34 raeburn 9594: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9595: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9596: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9597: foreach my $type (@{$changes{'selfcreate'}}) {
9598: my $typename = $type;
9599: if (ref($usertypes) eq 'HASH') {
9600: if ($usertypes->{$type} ne '') {
9601: $typename = $usertypes->{$type};
1.28 raeburn 9602: }
9603: }
1.160.6.34 raeburn 9604: my @modifiable;
9605: $resulttext .= '<li>'.
9606: &mt('Self-creation of account by users with status: [_1]',
9607: '<span class="LC_cusr_emph">'.$typename.'</span>').
9608: ' - '.&mt('modifiable fields (if institutional data blank): ');
9609: foreach my $field (@fields) {
9610: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9611: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9612: }
9613: }
9614: if (@modifiable > 0) {
9615: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9616: } else {
1.160.6.34 raeburn 9617: $resulttext .= &mt('none');
1.43 raeburn 9618: }
1.160.6.34 raeburn 9619: $resulttext .= '</li>';
1.28 raeburn 9620: }
1.160.6.34 raeburn 9621: $resulttext .= '</ul></li>';
1.28 raeburn 9622: }
1.27 raeburn 9623: $resulttext .= '</ul>';
9624: } else {
1.160.6.34 raeburn 9625: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9626: }
9627: } else {
9628: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9629: &mt('An error occurred: [_1]',$putresult).'</span>';
9630: }
1.43 raeburn 9631: if ($warningmsg ne '') {
9632: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9633: }
1.23 raeburn 9634: return $resulttext;
9635: }
9636:
1.160.6.5 raeburn 9637: sub process_captcha {
9638: my ($container,$changes,$newsettings,$current) = @_;
9639: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9640: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9641: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9642: $newsettings->{'captcha'} = 'original';
9643: }
9644: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9645: if ($container eq 'cancreate') {
9646: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9647: push(@{$changes->{'cancreate'}},'captcha');
9648: } elsif (!defined($changes->{'cancreate'})) {
9649: $changes->{'cancreate'} = ['captcha'];
9650: }
9651: } else {
9652: $changes->{'captcha'} = 1;
9653: }
9654: }
1.160.6.69 raeburn 9655: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 9656: if ($newsettings->{'captcha'} eq 'recaptcha') {
9657: $newpub = $env{'form.'.$container.'_recaptchapub'};
9658: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9659: $newpub =~ s/[^\w\-]//g;
9660: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9661: $newsettings->{'recaptchakeys'} = {
9662: public => $newpub,
9663: private => $newpriv,
9664: };
1.160.6.69 raeburn 9665: $newversion = $env{'form.'.$container.'_recaptchaversion'};
9666: $newversion =~ s/\D//g;
9667: if ($newversion ne '2') {
9668: $newversion = 1;
9669: }
9670: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 9671: }
9672: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9673: $currpub = $current->{'recaptchakeys'}{'public'};
9674: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9675: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9676: $newsettings->{'recaptchakeys'} = {
9677: public => '',
9678: private => '',
9679: }
9680: }
1.160.6.5 raeburn 9681: }
1.160.6.69 raeburn 9682: if ($current->{'captcha'} eq 'recaptcha') {
9683: $currversion = $current->{'recaptchaversion'};
9684: if ($currversion ne '2') {
9685: $currversion = 1;
9686: }
9687: }
9688: if ($currversion ne $newversion) {
9689: if ($container eq 'cancreate') {
9690: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9691: push(@{$changes->{'cancreate'}},'recaptchaversion');
9692: } elsif (!defined($changes->{'cancreate'})) {
9693: $changes->{'cancreate'} = ['recaptchaversion'];
9694: }
9695: } else {
9696: $changes->{'recaptchaversion'} = 1;
9697: }
9698: }
1.160.6.5 raeburn 9699: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9700: if ($container eq 'cancreate') {
9701: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9702: push(@{$changes->{'cancreate'}},'recaptchakeys');
9703: } elsif (!defined($changes->{'cancreate'})) {
9704: $changes->{'cancreate'} = ['recaptchakeys'];
9705: }
9706: } else {
9707: $changes->{'recaptchakeys'} = 1;
9708: }
9709: }
9710: return;
9711: }
9712:
1.33 raeburn 9713: sub modify_usermodification {
9714: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9715: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9716: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9717: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9718: if ($key eq 'selfcreate') {
9719: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9720: } else {
9721: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9722: }
1.33 raeburn 9723: }
9724: }
1.160.6.34 raeburn 9725: my @contexts = ('author','course');
1.33 raeburn 9726: my %context_title = (
9727: author => 'In author context',
9728: course => 'In course context',
9729: );
9730: my @fields = ('lastname','firstname','middlename','generation',
9731: 'permanentemail','id');
9732: my %roles = (
9733: author => ['ca','aa'],
9734: course => ['st','ep','ta','in','cr'],
9735: );
9736: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9737: foreach my $context (@contexts) {
9738: foreach my $role (@{$roles{$context}}) {
9739: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9740: foreach my $item (@fields) {
9741: if (grep(/^\Q$item\E$/,@modifiable)) {
9742: $modifyhash{$context}{$role}{$item} = 1;
9743: } else {
9744: $modifyhash{$context}{$role}{$item} = 0;
9745: }
9746: }
9747: }
9748: if (ref($curr_usermodification{$context}) eq 'HASH') {
9749: foreach my $role (@{$roles{$context}}) {
9750: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9751: foreach my $field (@fields) {
9752: if ($modifyhash{$context}{$role}{$field} ne
9753: $curr_usermodification{$context}{$role}{$field}) {
9754: push(@{$changes{$context}},$role);
9755: last;
9756: }
9757: }
9758: }
9759: }
9760: } else {
9761: foreach my $context (@contexts) {
9762: foreach my $role (@{$roles{$context}}) {
9763: push(@{$changes{$context}},$role);
9764: }
9765: }
9766: }
9767: }
9768: my %usermodification_hash = (
9769: usermodification => \%modifyhash,
9770: );
9771: my $putresult = &Apache::lonnet::put_dom('configuration',
9772: \%usermodification_hash,$dom);
9773: if ($putresult eq 'ok') {
9774: if (keys(%changes) > 0) {
9775: $resulttext = &mt('Changes made: ').'<ul>';
9776: foreach my $context (@contexts) {
9777: if (ref($changes{$context}) eq 'ARRAY') {
9778: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9779: if (ref($changes{$context}) eq 'ARRAY') {
9780: foreach my $role (@{$changes{$context}}) {
9781: my $rolename;
1.160.6.34 raeburn 9782: if ($role eq 'cr') {
9783: $rolename = &mt('Custom');
1.33 raeburn 9784: } else {
1.160.6.34 raeburn 9785: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9786: }
9787: my @modifiable;
1.160.6.34 raeburn 9788: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9789: foreach my $field (@fields) {
9790: if ($modifyhash{$context}{$role}{$field}) {
9791: push(@modifiable,$fieldtitles{$field});
9792: }
9793: }
9794: if (@modifiable > 0) {
9795: $resulttext .= join(', ',@modifiable);
9796: } else {
9797: $resulttext .= &mt('none');
9798: }
9799: $resulttext .= '</li>';
9800: }
9801: $resulttext .= '</ul></li>';
9802: }
9803: }
9804: }
9805: $resulttext .= '</ul>';
9806: } else {
9807: $resulttext = &mt('No changes made to user modification settings');
9808: }
9809: } else {
9810: $resulttext = '<span class="LC_error">'.
9811: &mt('An error occurred: [_1]',$putresult).'</span>';
9812: }
9813: return $resulttext;
9814: }
9815:
1.43 raeburn 9816: sub modify_defaults {
1.160.6.27 raeburn 9817: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9818: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9819: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9820: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9821: my @authtypes = ('internal','krb4','krb5','localauth');
9822: foreach my $item (@items) {
9823: $newvalues{$item} = $env{'form.'.$item};
9824: if ($item eq 'auth_def') {
9825: if ($newvalues{$item} ne '') {
9826: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9827: push(@errors,$item);
9828: }
9829: }
9830: } elsif ($item eq 'lang_def') {
9831: if ($newvalues{$item} ne '') {
9832: if ($newvalues{$item} =~ /^(\w+)/) {
9833: my $langcode = $1;
1.103 raeburn 9834: if ($langcode ne 'x_chef') {
9835: if (code2language($langcode) eq '') {
9836: push(@errors,$item);
9837: }
1.43 raeburn 9838: }
9839: } else {
9840: push(@errors,$item);
9841: }
9842: }
1.54 raeburn 9843: } elsif ($item eq 'timezone_def') {
9844: if ($newvalues{$item} ne '') {
1.62 raeburn 9845: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9846: push(@errors,$item);
9847: }
9848: }
1.68 raeburn 9849: } elsif ($item eq 'datelocale_def') {
9850: if ($newvalues{$item} ne '') {
9851: my @datelocale_ids = DateTime::Locale->ids();
9852: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9853: push(@errors,$item);
9854: }
9855: }
1.141 raeburn 9856: } elsif ($item eq 'portal_def') {
9857: if ($newvalues{$item} ne '') {
9858: 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])\/?$/) {
9859: push(@errors,$item);
9860: }
9861: }
1.43 raeburn 9862: }
9863: if (grep(/^\Q$item\E$/,@errors)) {
9864: $newvalues{$item} = $domdefaults{$item};
9865: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9866: $changes{$item} = 1;
9867: }
1.72 raeburn 9868: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9869: }
9870: my %defaults_hash = (
1.72 raeburn 9871: defaults => \%newvalues,
9872: );
1.43 raeburn 9873: my $title = &defaults_titles();
1.160.6.40 raeburn 9874:
9875: my $currinststatus;
9876: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9877: $currinststatus = $domconfig{'inststatus'};
9878: } else {
9879: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9880: $currinststatus = {
9881: inststatustypes => $usertypes,
9882: inststatusorder => $types,
9883: inststatusguest => [],
9884: };
9885: }
9886: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9887: my @allpos;
9888: my %guests;
9889: my %alltypes;
9890: my ($currtitles,$currguests,$currorder);
9891: if (ref($currinststatus) eq 'HASH') {
9892: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9893: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9894: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9895: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9896: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9897: }
9898: }
9899: unless (grep(/^\Q$type\E$/,@todelete)) {
9900: my $position = $env{'form.inststatus_pos_'.$type};
9901: $position =~ s/\D+//g;
9902: $allpos[$position] = $type;
9903: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9904: $alltypes{$type} =~ s/`//g;
9905: if ($env{'form.inststatus_guest_'.$type}) {
9906: $guests{$type} = 1;
9907: }
9908: }
9909: }
9910: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9911: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9912: }
9913: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9914: $currtitles =~ s/,$//;
9915: }
9916: }
9917: if ($env{'form.addinststatus'}) {
9918: my $newtype = $env{'form.addinststatus'};
9919: $newtype =~ s/\W//g;
9920: unless (exists($alltypes{$newtype})) {
9921: if ($env{'form.addinststatus_guest'}) {
9922: $guests{$newtype} = 1;
9923: }
9924: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9925: $alltypes{$newtype} =~ s/`//g;
9926: my $position = $env{'form.addinststatus_pos'};
9927: $position =~ s/\D+//g;
9928: if ($position ne '') {
9929: $allpos[$position] = $newtype;
9930: }
9931: }
9932: }
9933: my (@orderedstatus,@orderedguests);
9934: foreach my $type (@allpos) {
9935: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9936: push(@orderedstatus,$type);
9937: if ($guests{$type}) {
9938: push(@orderedguests,$type);
9939: }
9940: }
9941: }
9942: foreach my $type (keys(%alltypes)) {
9943: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9944: delete($alltypes{$type});
9945: }
9946: }
9947: $defaults_hash{'inststatus'} = {
9948: inststatustypes => \%alltypes,
9949: inststatusorder => \@orderedstatus,
9950: inststatusguest => \@orderedguests,
9951: };
9952: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9953: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9954: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9955: }
9956: }
9957: if ($currorder ne join(',',@orderedstatus)) {
9958: $changes{'inststatus'}{'inststatusorder'} = 1;
9959: }
9960: if ($currguests ne join(',',@orderedguests)) {
9961: $changes{'inststatus'}{'inststatusguest'} = 1;
9962: }
9963: my $newtitles;
9964: foreach my $item (@orderedstatus) {
9965: $newtitles .= $alltypes{$item}.',';
9966: }
9967: $newtitles =~ s/,$//;
9968: if ($currtitles ne $newtitles) {
9969: $changes{'inststatus'}{'inststatustypes'} = 1;
9970: }
1.43 raeburn 9971: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9972: $dom);
9973: if ($putresult eq 'ok') {
9974: if (keys(%changes) > 0) {
9975: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9976: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9977: 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";
9978: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9979: if ($item eq 'inststatus') {
9980: if (ref($changes{'inststatus'}) eq 'HASH') {
9981: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9982: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9983: foreach my $type (@orderedstatus) {
9984: $resulttext .= $alltypes{$type}.', ';
9985: }
9986: $resulttext =~ s/, $//;
9987: $resulttext .= '</li>';
9988: }
9989: if ($changes{'inststatus'}{'inststatusguest'}) {
9990: $resulttext .= '<li>';
9991: if (@orderedguests) {
9992: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9993: foreach my $type (@orderedguests) {
9994: $resulttext .= $alltypes{$type}.', ';
9995: }
9996: $resulttext =~ s/, $//;
9997: } else {
9998: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9999: }
10000: $resulttext .= '</li>';
10001: }
10002: }
10003: } else {
10004: my $value = $env{'form.'.$item};
10005: if ($value eq '') {
10006: $value = &mt('none');
10007: } elsif ($item eq 'auth_def') {
10008: my %authnames = &authtype_names();
10009: my %shortauth = (
10010: internal => 'int',
10011: krb4 => 'krb4',
10012: krb5 => 'krb5',
10013: localauth => 'loc',
10014: );
10015: $value = $authnames{$shortauth{$value}};
10016: }
10017: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10018: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10019: }
10020: }
10021: $resulttext .= '</ul>';
10022: $mailmsgtext .= "\n";
10023: my $cachetime = 24*60*60;
1.72 raeburn 10024: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10025: if (ref($lastactref) eq 'HASH') {
10026: $lastactref->{'domdefaults'} = 1;
10027: }
1.68 raeburn 10028: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10029: my $notify = 1;
10030: if (ref($domconfig{'contacts'}) eq 'HASH') {
10031: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10032: $notify = 0;
10033: }
10034: }
10035: if ($notify) {
10036: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10037: "LON-CAPA Domain Settings Change - $dom",
10038: $mailmsgtext);
10039: }
1.54 raeburn 10040: }
1.43 raeburn 10041: } else {
1.54 raeburn 10042: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10043: }
10044: } else {
10045: $resulttext = '<span class="LC_error">'.
10046: &mt('An error occurred: [_1]',$putresult).'</span>';
10047: }
10048: if (@errors > 0) {
10049: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10050: foreach my $item (@errors) {
10051: $resulttext .= ' "'.$title->{$item}.'",';
10052: }
10053: $resulttext =~ s/,$//;
10054: }
10055: return $resulttext;
10056: }
10057:
1.46 raeburn 10058: sub modify_scantron {
1.160.6.24 raeburn 10059: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10060: my ($resulttext,%confhash,%changes,$errors);
10061: my $custom = 'custom.tab';
10062: my $default = 'default.tab';
10063: my $servadm = $r->dir_config('lonAdmEMail');
10064: my ($configuserok,$author_ok,$switchserver) =
10065: &config_check($dom,$confname,$servadm);
10066: if ($env{'form.scantronformat.filename'} ne '') {
10067: my $error;
10068: if ($configuserok eq 'ok') {
10069: if ($switchserver) {
1.130 raeburn 10070: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10071: } else {
10072: if ($author_ok eq 'ok') {
10073: my ($result,$scantronurl) =
10074: &publishlogo($r,'upload','scantronformat',$dom,
10075: $confname,'scantron','','',$custom);
10076: if ($result eq 'ok') {
10077: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10078: $changes{'scantronformat'} = 1;
1.46 raeburn 10079: } else {
10080: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10081: }
10082: } else {
10083: $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);
10084: }
10085: }
10086: } else {
10087: $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);
10088: }
10089: if ($error) {
10090: &Apache::lonnet::logthis($error);
10091: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10092: }
10093: }
1.48 raeburn 10094: if (ref($domconfig{'scantron'}) eq 'HASH') {
10095: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10096: if ($env{'form.scantronformat_del'}) {
10097: $confhash{'scantron'}{'scantronformat'} = '';
10098: $changes{'scantronformat'} = 1;
1.46 raeburn 10099: }
10100: }
10101: }
10102: if (keys(%confhash) > 0) {
10103: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10104: $dom);
10105: if ($putresult eq 'ok') {
10106: if (keys(%changes) > 0) {
1.48 raeburn 10107: if (ref($confhash{'scantron'}) eq 'HASH') {
10108: $resulttext = &mt('Changes made:').'<ul>';
10109: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10110: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10111: } else {
1.130 raeburn 10112: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10113: }
1.48 raeburn 10114: $resulttext .= '</ul>';
10115: } else {
1.130 raeburn 10116: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10117: }
10118: $resulttext .= '</ul>';
10119: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10120: if (ref($lastactref) eq 'HASH') {
10121: $lastactref->{'domainconfig'} = 1;
10122: }
1.46 raeburn 10123: } else {
1.130 raeburn 10124: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10125: }
10126: } else {
10127: $resulttext = '<span class="LC_error">'.
10128: &mt('An error occurred: [_1]',$putresult).'</span>';
10129: }
10130: } else {
1.130 raeburn 10131: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10132: }
10133: if ($errors) {
10134: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10135: $errors.'</ul>';
10136: }
10137: return $resulttext;
10138: }
10139:
1.48 raeburn 10140: sub modify_coursecategories {
1.160.6.43 raeburn 10141: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10142: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10143: $cathash);
1.48 raeburn 10144: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10145: my @catitems = ('unauth','auth');
10146: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10147: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10148: $cathash = $domconfig{'coursecategories'}{'cats'};
10149: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10150: $changes{'togglecats'} = 1;
10151: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10152: }
10153: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10154: $changes{'categorize'} = 1;
10155: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10156: }
1.120 raeburn 10157: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10158: $changes{'togglecatscomm'} = 1;
10159: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10160: }
10161: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10162: $changes{'categorizecomm'} = 1;
10163: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10164: }
1.160.6.42 raeburn 10165: foreach my $item (@catitems) {
10166: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10167: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10168: $changes{$item} = 1;
10169: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10170: }
10171: }
10172: }
1.57 raeburn 10173: } else {
10174: $changes{'togglecats'} = 1;
10175: $changes{'categorize'} = 1;
1.124 raeburn 10176: $changes{'togglecatscomm'} = 1;
10177: $changes{'categorizecomm'} = 1;
1.87 raeburn 10178: $domconfig{'coursecategories'} = {
10179: togglecats => $env{'form.togglecats'},
10180: categorize => $env{'form.categorize'},
1.124 raeburn 10181: togglecatscomm => $env{'form.togglecatscomm'},
10182: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10183: };
1.160.6.42 raeburn 10184: foreach my $item (@catitems) {
10185: if ($env{'form.coursecat_'.$item} ne 'std') {
10186: $changes{$item} = 1;
10187: }
10188: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10189: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10190: }
10191: }
1.57 raeburn 10192: }
10193: if (ref($cathash) eq 'HASH') {
10194: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10195: push (@deletecategory,'instcode::0');
10196: }
1.120 raeburn 10197: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10198: push(@deletecategory,'communities::0');
10199: }
1.48 raeburn 10200: }
1.57 raeburn 10201: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10202: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10203: if (@deletecategory > 0) {
10204: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10205: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10206: foreach my $item (@deletecategory) {
1.57 raeburn 10207: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10208: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10209: $deletions{$item} = 1;
1.57 raeburn 10210: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10211: }
10212: }
10213: }
1.57 raeburn 10214: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10215: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10216: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10217: $reorderings{$item} = 1;
1.57 raeburn 10218: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10219: }
10220: if ($env{'form.addcategory_name_'.$item} ne '') {
10221: my $newcat = $env{'form.addcategory_name_'.$item};
10222: my $newdepth = $depth+1;
10223: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10224: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10225: $adds{$newitem} = 1;
10226: }
10227: if ($env{'form.subcat_'.$item} ne '') {
10228: my $newcat = $env{'form.subcat_'.$item};
10229: my $newdepth = $depth+1;
10230: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10231: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10232: $adds{$newitem} = 1;
10233: }
10234: }
10235: }
10236: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10237: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10238: my $newitem = 'instcode::0';
1.57 raeburn 10239: if ($cathash->{$newitem} eq '') {
10240: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10241: $adds{$newitem} = 1;
10242: }
10243: } else {
10244: my $newitem = 'instcode::0';
1.57 raeburn 10245: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10246: $adds{$newitem} = 1;
10247: }
10248: }
1.120 raeburn 10249: if ($env{'form.communities'} eq '1') {
10250: if (ref($cathash) eq 'HASH') {
10251: my $newitem = 'communities::0';
10252: if ($cathash->{$newitem} eq '') {
10253: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10254: $adds{$newitem} = 1;
10255: }
10256: } else {
10257: my $newitem = 'communities::0';
10258: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10259: $adds{$newitem} = 1;
10260: }
10261: }
1.48 raeburn 10262: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10263: if (($env{'form.addcategory_name'} ne 'instcode') &&
10264: ($env{'form.addcategory_name'} ne 'communities')) {
10265: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10266: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10267: $adds{$newitem} = 1;
10268: }
1.48 raeburn 10269: }
1.57 raeburn 10270: my $putresult;
1.48 raeburn 10271: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10272: if (keys(%deletions) > 0) {
10273: foreach my $key (keys(%deletions)) {
10274: if ($predelallitems{$key} ne '') {
10275: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10276: }
10277: }
10278: }
10279: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10280: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10281: if (ref($chkcats[0]) eq 'ARRAY') {
10282: my $depth = 0;
10283: my $chg = 0;
10284: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10285: my $name = $chkcats[0][$i];
10286: my $item;
10287: if ($name eq '') {
10288: $chg ++;
10289: } else {
10290: $item = &escape($name).'::0';
10291: if ($chg) {
1.57 raeburn 10292: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10293: }
10294: $depth ++;
1.57 raeburn 10295: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10296: $depth --;
10297: }
10298: }
10299: }
1.57 raeburn 10300: }
10301: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10302: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10303: if ($putresult eq 'ok') {
1.57 raeburn 10304: my %title = (
1.120 raeburn 10305: togglecats => 'Show/Hide a course in catalog',
10306: categorize => 'Assign a category to a course',
10307: togglecatscomm => 'Show/Hide a community in catalog',
10308: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10309: );
10310: my %level = (
1.120 raeburn 10311: dom => 'set in Domain ("Modify Course/Community")',
10312: crs => 'set in Course ("Course Configuration")',
10313: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 10314: none => 'No catalog',
10315: std => 'Standard catalog',
10316: domonly => 'Domain-only catalog',
10317: codesrch => 'Code search form',
1.57 raeburn 10318: );
1.48 raeburn 10319: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 10320: if ($changes{'togglecats'}) {
10321: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
10322: }
10323: if ($changes{'categorize'}) {
10324: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 10325: }
1.120 raeburn 10326: if ($changes{'togglecatscomm'}) {
10327: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
10328: }
10329: if ($changes{'categorizecomm'}) {
10330: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
10331: }
1.160.6.42 raeburn 10332: if ($changes{'unauth'}) {
10333: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
10334: }
10335: if ($changes{'auth'}) {
10336: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
10337: }
1.57 raeburn 10338: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10339: my $cathash;
10340: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10341: $cathash = $domconfig{'coursecategories'}{'cats'};
10342: } else {
10343: $cathash = {};
10344: }
10345: my (@cats,@trails,%allitems);
10346: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10347: if (keys(%deletions) > 0) {
10348: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10349: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10350: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10351: }
10352: $resulttext .= '</ul></li>';
10353: }
10354: if (keys(%reorderings) > 0) {
10355: my %sort_by_trail;
10356: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10357: foreach my $key (keys(%reorderings)) {
10358: if ($allitems{$key} ne '') {
10359: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10360: }
1.48 raeburn 10361: }
1.57 raeburn 10362: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10363: $resulttext .= '<li>'.$trails[$trail].'</li>';
10364: }
10365: $resulttext .= '</ul></li>';
1.48 raeburn 10366: }
1.57 raeburn 10367: if (keys(%adds) > 0) {
10368: my %sort_by_trail;
10369: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10370: foreach my $key (keys(%adds)) {
10371: if ($allitems{$key} ne '') {
10372: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10373: }
10374: }
10375: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10376: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10377: }
1.57 raeburn 10378: $resulttext .= '</ul></li>';
1.48 raeburn 10379: }
10380: }
10381: $resulttext .= '</ul>';
1.160.6.43 raeburn 10382: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10383: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10384: if ($changes{'auth'}) {
10385: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10386: }
10387: if ($changes{'unauth'}) {
10388: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10389: }
10390: my $cachetime = 24*60*60;
10391: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10392: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10393: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10394: }
10395: }
1.48 raeburn 10396: } else {
10397: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10398: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10399: }
10400: } else {
1.120 raeburn 10401: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10402: }
10403: return $resulttext;
10404: }
10405:
1.69 raeburn 10406: sub modify_serverstatuses {
10407: my ($dom,%domconfig) = @_;
10408: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10409: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10410: %currserverstatus = %{$domconfig{'serverstatuses'}};
10411: }
10412: my @pages = &serverstatus_pages();
10413: foreach my $type (@pages) {
10414: $newserverstatus{$type}{'namedusers'} = '';
10415: $newserverstatus{$type}{'machines'} = '';
10416: if (defined($env{'form.'.$type.'_namedusers'})) {
10417: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10418: my @okusers;
10419: foreach my $user (@users) {
10420: my ($uname,$udom) = split(/:/,$user);
10421: if (($udom =~ /^$match_domain$/) &&
10422: (&Apache::lonnet::domain($udom)) &&
10423: ($uname =~ /^$match_username$/)) {
10424: if (!grep(/^\Q$user\E/,@okusers)) {
10425: push(@okusers,$user);
10426: }
10427: }
10428: }
10429: if (@okusers > 0) {
10430: @okusers = sort(@okusers);
10431: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10432: }
10433: }
10434: if (defined($env{'form.'.$type.'_machines'})) {
10435: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10436: my @okmachines;
10437: foreach my $ip (@machines) {
10438: my @parts = split(/\./,$ip);
10439: next if (@parts < 4);
10440: my $badip = 0;
10441: for (my $i=0; $i<4; $i++) {
10442: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10443: $badip = 1;
10444: last;
10445: }
10446: }
10447: if (!$badip) {
10448: push(@okmachines,$ip);
10449: }
10450: }
10451: @okmachines = sort(@okmachines);
10452: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10453: }
10454: }
10455: my %serverstatushash = (
10456: serverstatuses => \%newserverstatus,
10457: );
10458: foreach my $type (@pages) {
1.83 raeburn 10459: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10460: my (@current,@new);
1.83 raeburn 10461: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10462: if ($currserverstatus{$type}{$setting} ne '') {
10463: @current = split(/,/,$currserverstatus{$type}{$setting});
10464: }
10465: }
10466: if ($newserverstatus{$type}{$setting} ne '') {
10467: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10468: }
10469: if (@current > 0) {
10470: if (@new > 0) {
10471: foreach my $item (@current) {
10472: if (!grep(/^\Q$item\E$/,@new)) {
10473: $changes{$type}{$setting} = 1;
1.82 raeburn 10474: last;
10475: }
10476: }
1.84 raeburn 10477: foreach my $item (@new) {
10478: if (!grep(/^\Q$item\E$/,@current)) {
10479: $changes{$type}{$setting} = 1;
10480: last;
1.82 raeburn 10481: }
10482: }
10483: } else {
1.83 raeburn 10484: $changes{$type}{$setting} = 1;
1.69 raeburn 10485: }
1.83 raeburn 10486: } elsif (@new > 0) {
10487: $changes{$type}{$setting} = 1;
1.69 raeburn 10488: }
10489: }
10490: }
10491: if (keys(%changes) > 0) {
1.81 raeburn 10492: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10493: my $putresult = &Apache::lonnet::put_dom('configuration',
10494: \%serverstatushash,$dom);
10495: if ($putresult eq 'ok') {
10496: $resulttext .= &mt('Changes made:').'<ul>';
10497: foreach my $type (@pages) {
1.84 raeburn 10498: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10499: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10500: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10501: if ($newserverstatus{$type}{'namedusers'} eq '') {
10502: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10503: } else {
10504: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10505: }
1.84 raeburn 10506: }
10507: if ($changes{$type}{'machines'}) {
1.69 raeburn 10508: if ($newserverstatus{$type}{'machines'} eq '') {
10509: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10510: } else {
10511: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10512: }
10513:
10514: }
10515: $resulttext .= '</ul></li>';
10516: }
10517: }
10518: $resulttext .= '</ul>';
10519: } else {
10520: $resulttext = '<span class="LC_error">'.
10521: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10522:
10523: }
10524: } else {
10525: $resulttext = &mt('No changes made to access to server status pages');
10526: }
10527: return $resulttext;
10528: }
10529:
1.118 jms 10530: sub modify_helpsettings {
1.122 jms 10531: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10532: my ($resulttext,$errors,%changes,%helphash);
10533: my %defaultchecked = ('submitbugs' => 'on');
10534: my @offon = ('off','on');
1.118 jms 10535: my @toggles = ('submitbugs');
1.160.6.73! raeburn 10536: my %current = ('submitbugs' => '');
1.118 jms 10537: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73! raeburn 10538: %current = %{$domconfig{'helpsettings'}};
! 10539: }
! 10540: foreach my $item (@toggles) {
! 10541: if ($defaultchecked{$item} eq 'on') {
! 10542: if ($current{$item} eq '') {
! 10543: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 10544: $changes{$item} = 1;
10545: }
1.160.6.73! raeburn 10546: } elsif ($current{$item} ne $env{'form.'.$item}) {
! 10547: $changes{$item} = 1;
! 10548: }
! 10549: } elsif ($defaultchecked{$item} eq 'off') {
! 10550: if ($current{$item} eq '') {
! 10551: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 10552: $changes{$item} = 1;
10553: }
1.160.6.73! raeburn 10554: } elsif ($current{$item} ne $env{'form.'.$item}) {
! 10555: $changes{$item} = 1;
! 10556: }
! 10557: }
! 10558: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
! 10559: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
! 10560: }
! 10561: }
! 10562:
! 10563: my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp');
! 10564: my $confname = $dom.'-domainconfig';
! 10565: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
! 10566: if (@modify) {
! 10567: foreach my $num (@modify) {
! 10568: my $rolename = $env{'form.custhelprole'.$num};
! 10569: if ($rolename ne '') {
! 10570: if (exists($existing{'rolesdef_'.$rolename})) {
! 10571: my $prefix = 'custhelp'.$num;
! 10572: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
! 10573: my %currprivs;
! 10574: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
! 10575: split(/\_/,$existing{'rolesdef_'.$rolename});
! 10576: foreach my $level ('c','d','s') {
! 10577: if ($newprivs{$level} ne $currprivs{$level}) {
! 10578: $changes{'customrole'}{$rolename} = 1;
! 10579: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
! 10580: $newprivs{'c'},$confname,$dom);
! 10581: last;
! 10582: }
! 10583: }
! 10584: }
1.160.6.26 raeburn 10585: }
1.160.6.73! raeburn 10586: }
! 10587: }
! 10588: if ($env{'form.newcusthelp'} ne '') {
! 10589: my $prefix = 'custhelp'.$env{'form.newcusthelp'};
! 10590: my $rolename = $env{'form.newcusthelpname'};
! 10591: $rolename=~s/[^A-Za-z0-9]//gs;
! 10592: if ($rolename ne '') {
! 10593: unless(exists($existing{'rolesdef_'.$rolename})) {
! 10594: my $errmsg;
! 10595: my $result = &Apache::lonuserutils::store_custom_role($rolename,$prefix,
! 10596: $confname,$dom);
! 10597: if ($result eq 'ok') {
! 10598: $changes{'newcustomrole'} = $rolename;
! 10599: } else {
! 10600: $errmsg = ': '.$result;
! 10601: }
1.122 jms 10602: }
10603: }
1.118 jms 10604: }
1.160.6.73! raeburn 10605:
1.123 jms 10606: my $putresult;
10607: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10608: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10609: if ($putresult eq 'ok') {
10610: $resulttext = &mt('Changes made:').'<ul>';
10611: foreach my $item (sort(keys(%changes))) {
10612: if ($item eq 'submitbugs') {
10613: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10614: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10615: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73! raeburn 10616: } elsif ($item eq 'customrole') {
! 10617: if (ref($changes{'customrole'}) eq 'HASH') {
! 10618: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
! 10619: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
! 10620: $role).'</li>';
! 10621: }
! 10622: }
! 10623: } elsif ($item eq 'newcustomrole') {
! 10624: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
! 10625: $changes{'newcustomrole'}).'</li>';
1.160.6.5 raeburn 10626: }
10627: }
10628: $resulttext .= '</ul>';
10629: } else {
10630: $resulttext = &mt('No changes made to help settings');
10631: $errors .= '<li><span class="LC_error">'.
10632: &mt('An error occurred storing the settings: [_1]',
10633: $putresult).'</span></li>';
10634: }
1.118 jms 10635: }
10636: if ($errors) {
1.160.6.5 raeburn 10637: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10638: $errors.'</ul>';
10639: }
10640: return $resulttext;
10641: }
10642:
1.121 raeburn 10643: sub modify_coursedefaults {
1.160.6.27 raeburn 10644: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10645: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10646: my %defaultchecked = (
10647: 'uselcmath' => 'on',
10648: 'usejsme' => 'on'
10649: );
10650: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10651: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 10652: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
10653: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 10654: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10655: my %staticdefaults = (
10656: anonsurvey_threshold => 10,
10657: uploadquota => 500,
1.160.6.57 raeburn 10658: postsubmit => 60,
1.160.6.70 raeburn 10659: mysqltables => 172800,
1.160.6.21 raeburn 10660: );
1.121 raeburn 10661:
10662: $defaultshash{'coursedefaults'} = {};
10663:
10664: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10665: if ($domconfig{'coursedefaults'} eq '') {
10666: $domconfig{'coursedefaults'} = {};
10667: }
10668: }
10669:
10670: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10671: foreach my $item (@toggles) {
10672: if ($defaultchecked{$item} eq 'on') {
10673: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10674: ($env{'form.'.$item} eq '0')) {
10675: $changes{$item} = 1;
1.160.6.16 raeburn 10676: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10677: $changes{$item} = 1;
10678: }
10679: } elsif ($defaultchecked{$item} eq 'off') {
10680: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10681: ($env{'form.'.$item} eq '1')) {
10682: $changes{$item} = 1;
10683: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10684: $changes{$item} = 1;
10685: }
10686: }
10687: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10688: }
1.160.6.21 raeburn 10689: foreach my $item (@numbers) {
10690: my ($currdef,$newdef);
1.160.6.26 raeburn 10691: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10692: if ($item eq 'anonsurvey_threshold') {
10693: $currdef = $domconfig{'coursedefaults'}{$item};
10694: $newdef =~ s/\D//g;
10695: if ($newdef eq '' || $newdef < 1) {
10696: $newdef = 1;
10697: }
10698: $defaultshash{'coursedefaults'}{$item} = $newdef;
10699: } else {
1.160.6.70 raeburn 10700: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
10701: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
10702: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 10703: }
10704: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 10705: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 10706: }
10707: if ($currdef ne $newdef) {
10708: my $staticdef;
10709: if ($item eq 'anonsurvey_threshold') {
10710: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10711: $changes{$item} = 1;
10712: }
1.160.6.70 raeburn 10713: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
10714: my $setting = $1;
10715: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
10716: $changes{$setting} = 1;
1.160.6.21 raeburn 10717: }
10718: }
1.139 raeburn 10719: }
10720: }
1.160.6.64 raeburn 10721: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
10722: my @currclonecode;
10723: if (ref($currclone) eq 'HASH') {
10724: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
10725: @currclonecode = @{$currclone->{'instcode'}};
10726: }
10727: }
10728: my $newclone;
10729: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
10730: $newclone = $env{'form.canclone'};
10731: }
10732: if ($newclone eq 'instcode') {
10733: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
10734: my (%codedefaults,@code_order,@clonecode);
10735: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
10736: \@code_order);
10737: foreach my $item (@code_order) {
10738: if (grep(/^\Q$item\E$/,@newcodes)) {
10739: push(@clonecode,$item);
10740: }
10741: }
10742: if (@clonecode) {
10743: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
10744: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
10745: if (@diffs) {
10746: $changes{'canclone'} = 1;
10747: }
10748: } else {
10749: $newclone eq '';
10750: }
10751: } elsif ($newclone ne '') {
10752: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
10753: }
10754: if ($newclone ne $currclone) {
10755: $changes{'canclone'} = 1;
10756: }
1.160.6.57 raeburn 10757: my %credits;
10758: foreach my $type (@types) {
10759: unless ($type eq 'community') {
10760: $credits{$type} = $env{'form.'.$type.'_credits'};
10761: $credits{$type} =~ s/[^\d.]+//g;
10762: }
10763: }
10764: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10765: ($env{'form.coursecredits'} eq '1')) {
10766: $changes{'coursecredits'} = 1;
10767: foreach my $type (keys(%credits)) {
10768: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10769: }
10770: } else {
10771: if ($env{'form.coursecredits'} eq '1') {
10772: foreach my $type (@types) {
10773: unless ($type eq 'community') {
10774: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10775: $changes{'coursecredits'} = 1;
10776: }
10777: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10778: }
10779: }
10780: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10781: foreach my $type (@types) {
10782: unless ($type eq 'community') {
10783: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10784: $changes{'coursecredits'} = 1;
10785: last;
10786: }
10787: }
10788: }
10789: }
10790: }
10791: if ($env{'form.postsubmit'} eq '1') {
10792: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10793: my %currtimeout;
10794: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10795: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10796: $changes{'postsubmit'} = 1;
10797: }
10798: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10799: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10800: }
10801: } else {
10802: $changes{'postsubmit'} = 1;
10803: }
10804: foreach my $type (@types) {
10805: my $timeout = $env{'form.'.$type.'_timeout'};
10806: $timeout =~ s/\D//g;
10807: if ($timeout == $staticdefaults{'postsubmit'}) {
10808: $timeout = '';
10809: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10810: $timeout = '0';
10811: }
10812: unless ($timeout eq '') {
10813: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10814: }
10815: if (exists($currtimeout{$type})) {
10816: if ($timeout ne $currtimeout{$type}) {
10817: $changes{'postsubmit'} = 1;
10818: }
10819: } elsif ($timeout ne '') {
10820: $changes{'postsubmit'} = 1;
10821: }
10822: }
10823: } else {
10824: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10825: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10826: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10827: $changes{'postsubmit'} = 1;
10828: }
10829: } else {
10830: $changes{'postsubmit'} = 1;
10831: }
1.160.6.16 raeburn 10832: }
1.121 raeburn 10833: }
10834: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10835: $dom);
10836: if ($putresult eq 'ok') {
10837: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10838: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10839: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 10840: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 10841: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 10842: foreach my $item ('uselcmath','usejsme') {
10843: if ($changes{$item}) {
10844: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10845: }
1.160.6.16 raeburn 10846: }
10847: if ($changes{'coursecredits'}) {
10848: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10849: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10850: $domdefaults{$type.'credits'} =
10851: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10852: }
10853: }
10854: }
10855: if ($changes{'postsubmit'}) {
10856: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10857: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10858: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10859: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10860: $domdefaults{$type.'postsubtimeout'} =
10861: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10862: }
10863: }
1.160.6.16 raeburn 10864: }
10865: }
1.160.6.21 raeburn 10866: if ($changes{'uploadquota'}) {
10867: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10868: foreach my $type (@types) {
10869: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10870: }
10871: }
10872: }
1.160.6.64 raeburn 10873: if ($changes{'canclone'}) {
10874: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10875: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10876: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
10877: if (@clonecodes) {
10878: $domdefaults{'canclone'} = join('+',@clonecodes);
10879: }
10880: }
10881: } else {
10882: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
10883: }
10884: }
1.121 raeburn 10885: my $cachetime = 24*60*60;
10886: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10887: if (ref($lastactref) eq 'HASH') {
10888: $lastactref->{'domdefaults'} = 1;
10889: }
1.121 raeburn 10890: }
10891: $resulttext = &mt('Changes made:').'<ul>';
10892: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10893: if ($item eq 'uselcmath') {
1.121 raeburn 10894: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10895: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10896: } else {
1.160.6.57 raeburn 10897: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10898: }
10899: } elsif ($item eq 'usejsme') {
10900: if ($env{'form.'.$item} eq '1') {
10901: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10902: } else {
10903: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10904: }
1.139 raeburn 10905: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10906: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 10907: } elsif ($item eq 'uploadquota') {
10908: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10909: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10910: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10911: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10912: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10913:
1.160.6.21 raeburn 10914: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10915: '</ul>'.
10916: '</li>';
10917: } else {
10918: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10919: }
1.160.6.70 raeburn 10920: } elsif ($item eq 'mysqltables') {
10921: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
10922: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
10923: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
10924: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
10925: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
10926: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
10927: '</ul>'.
10928: '</li>';
10929: } else {
10930: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
10931: }
1.160.6.57 raeburn 10932: } elsif ($item eq 'postsubmit') {
10933: if ($domdefaults{'postsubmit'} eq 'off') {
10934: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10935: } else {
10936: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10937: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10938: $resulttext .= &mt('durations:').'<ul>';
10939: foreach my $type (@types) {
10940: $resulttext .= '<li>';
10941: my $timeout;
10942: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10943: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10944: }
10945: my $display;
10946: if ($timeout eq '0') {
10947: $display = &mt('unlimited');
10948: } elsif ($timeout eq '') {
10949: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10950: } else {
10951: $display = &mt('[quant,_1,second]',$timeout);
10952: }
10953: if ($type eq 'community') {
10954: $resulttext .= &mt('Communities');
10955: } elsif ($type eq 'official') {
10956: $resulttext .= &mt('Official courses');
10957: } elsif ($type eq 'unofficial') {
10958: $resulttext .= &mt('Unofficial courses');
10959: } elsif ($type eq 'textbook') {
10960: $resulttext .= &mt('Textbook courses');
10961: }
10962: $resulttext .= ' -- '.$display.'</li>';
10963: }
10964: $resulttext .= '</ul>';
10965: }
10966: $resulttext .= '</li>';
10967: }
1.160.6.16 raeburn 10968: } elsif ($item eq 'coursecredits') {
10969: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10970: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10971: ($domdefaults{'unofficialcredits'} eq '') &&
10972: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10973: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10974: } else {
10975: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10976: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10977: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10978: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10979: '</ul>'.
10980: '</li>';
10981: }
10982: } else {
10983: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10984: }
1.160.6.64 raeburn 10985: } elsif ($item eq 'canclone') {
10986: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10987: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10988: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
10989: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
10990: }
10991: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
10992: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
10993: } else {
10994: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
10995: }
1.140 raeburn 10996: }
1.121 raeburn 10997: }
10998: $resulttext .= '</ul>';
10999: } else {
11000: $resulttext = &mt('No changes made to course defaults');
11001: }
11002: } else {
11003: $resulttext = '<span class="LC_error">'.
11004: &mt('An error occurred: [_1]',$putresult).'</span>';
11005: }
11006: return $resulttext;
11007: }
11008:
1.160.6.37 raeburn 11009: sub modify_selfenrollment {
11010: my ($dom,$lastactref,%domconfig) = @_;
11011: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
11012: my @types = ('official','unofficial','community','textbook');
11013: my %titles = &tool_titles();
11014: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11015: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
11016: $ordered{'default'} = ['types','registered','approval','limit'];
11017:
11018: my (%roles,%shown,%toplevel);
11019: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11020:
11021: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11022: if ($domconfig{'selfenrollment'} eq '') {
11023: $domconfig{'selfenrollment'} = {};
11024: }
11025: }
11026: %toplevel = (
11027: admin => 'Configuration Rights',
11028: default => 'Default settings',
11029: validation => 'Validation of self-enrollment requests',
11030: );
11031: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
11032:
11033: if (ref($ordered{'admin'}) eq 'ARRAY') {
11034: foreach my $item (@{$ordered{'admin'}}) {
11035: foreach my $type (@types) {
11036: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
11037: $selfenrollhash{'admin'}{$type}{$item} = 1;
11038: } else {
11039: $selfenrollhash{'admin'}{$type}{$item} = 0;
11040: }
11041: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
11042: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
11043: if ($selfenrollhash{'admin'}{$type}{$item} ne
11044: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
11045: push(@{$changes{'admin'}{$type}},$item);
11046: }
11047: } else {
11048: if (!$selfenrollhash{'admin'}{$type}{$item}) {
11049: push(@{$changes{'admin'}{$type}},$item);
11050: }
11051: }
11052: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
11053: push(@{$changes{'admin'}{$type}},$item);
11054: }
11055: }
11056: }
11057: }
11058:
11059: foreach my $item (@{$ordered{'default'}}) {
11060: foreach my $type (@types) {
11061: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
11062: if ($item eq 'types') {
11063: unless (($value eq 'all') || ($value eq 'dom')) {
11064: $value = '';
11065: }
11066: } elsif ($item eq 'registered') {
11067: unless ($value eq '1') {
11068: $value = 0;
11069: }
11070: } elsif ($item eq 'approval') {
11071: unless ($value =~ /^[012]$/) {
11072: $value = 0;
11073: }
11074: } else {
11075: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11076: $value = 'none';
11077: }
11078: }
11079: $selfenrollhash{'default'}{$type}{$item} = $value;
11080: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
11081: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11082: if ($selfenrollhash{'default'}{$type}{$item} ne
11083: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
11084: push(@{$changes{'default'}{$type}},$item);
11085: }
11086: } else {
11087: push(@{$changes{'default'}{$type}},$item);
11088: }
11089: } else {
11090: push(@{$changes{'default'}{$type}},$item);
11091: }
11092: if ($item eq 'limit') {
11093: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11094: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
11095: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
11096: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
11097: }
11098: } else {
11099: $selfenrollhash{'default'}{$type}{'cap'} = '';
11100: }
11101: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11102: if ($selfenrollhash{'default'}{$type}{'cap'} ne
11103: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
11104: push(@{$changes{'default'}{$type}},'cap');
11105: }
11106: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
11107: push(@{$changes{'default'}{$type}},'cap');
11108: }
11109: }
11110: }
11111: }
11112:
11113: foreach my $item (@{$itemsref}) {
11114: if ($item eq 'fields') {
11115: my @changed;
11116: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
11117: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
11118: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
11119: }
11120: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11121: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
11122: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
11123: $domconfig{'selfenrollment'}{'validation'}{$item});
11124: } else {
11125: @changed = @{$selfenrollhash{'validation'}{$item}};
11126: }
11127: } else {
11128: @changed = @{$selfenrollhash{'validation'}{$item}};
11129: }
11130: if (@changed) {
11131: if ($selfenrollhash{'validation'}{$item}) {
11132: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
11133: } else {
11134: $changes{'validation'}{$item} = &mt('None');
11135: }
11136: }
11137: } else {
11138: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
11139: if ($item eq 'markup') {
11140: if ($env{'form.selfenroll_validation_'.$item}) {
11141: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11142: }
11143: }
11144: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11145: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
11146: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
11147: }
11148: }
11149: }
11150: }
11151:
11152: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
11153: $dom);
11154: if ($putresult eq 'ok') {
11155: if (keys(%changes) > 0) {
11156: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11157: $resulttext = &mt('Changes made:').'<ul>';
11158: foreach my $key ('admin','default','validation') {
11159: if (ref($changes{$key}) eq 'HASH') {
11160: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11161: if ($key eq 'validation') {
11162: foreach my $item (@{$itemsref}) {
11163: if (exists($changes{$key}{$item})) {
11164: if ($item eq 'markup') {
11165: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11166: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11167: } else {
11168: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11169: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11170: }
11171: }
11172: }
11173: } else {
11174: foreach my $type (@types) {
11175: if ($type eq 'community') {
11176: $roles{'1'} = &mt('Community personnel');
11177: } else {
11178: $roles{'1'} = &mt('Course personnel');
11179: }
11180: if (ref($changes{$key}{$type}) eq 'ARRAY') {
11181: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11182: if ($key eq 'admin') {
11183: my @mgrdc = ();
11184: if (ref($ordered{$key}) eq 'ARRAY') {
11185: foreach my $item (@{$ordered{'admin'}}) {
11186: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11187: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11188: push(@mgrdc,$item);
11189: }
11190: }
11191: }
11192: if (@mgrdc) {
11193: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11194: } else {
11195: delete($domdefaults{$type.'selfenrolladmdc'});
11196: }
11197: }
11198: } else {
11199: if (ref($ordered{$key}) eq 'ARRAY') {
11200: foreach my $item (@{$ordered{$key}}) {
11201: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11202: $domdefaults{$type.'selfenroll'.$item} =
11203: $selfenrollhash{$key}{$type}{$item};
11204: }
11205: }
11206: }
11207: }
11208: }
11209: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11210: foreach my $item (@{$ordered{$key}}) {
11211: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11212: $resulttext .= '<li>';
11213: if ($key eq 'admin') {
11214: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11215: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
11216: } else {
11217: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
11218: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
11219: }
11220: $resulttext .= '</li>';
11221: }
11222: }
11223: $resulttext .= '</ul></li>';
11224: }
11225: }
11226: $resulttext .= '</ul></li>';
11227: }
11228: }
11229: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
11230: my $cachetime = 24*60*60;
11231: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11232: if (ref($lastactref) eq 'HASH') {
11233: $lastactref->{'domdefaults'} = 1;
11234: }
11235: }
11236: }
11237: $resulttext .= '</ul>';
11238: } else {
11239: $resulttext = &mt('No changes made to self-enrollment settings');
11240: }
11241: } else {
11242: $resulttext = '<span class="LC_error">'.
11243: &mt('An error occurred: [_1]',$putresult).'</span>';
11244: }
11245: return $resulttext;
11246: }
11247:
1.137 raeburn 11248: sub modify_usersessions {
1.160.6.27 raeburn 11249: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 11250: my @hostingtypes = ('version','excludedomain','includedomain');
11251: my @offloadtypes = ('primary','default');
11252: my %types = (
11253: remote => \@hostingtypes,
11254: hosted => \@hostingtypes,
11255: spares => \@offloadtypes,
11256: );
11257: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 11258: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 11259: my (%by_ip,%by_location,@intdoms);
11260: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
11261: my @locations = sort(keys(%by_location));
1.137 raeburn 11262: my (%defaultshash,%changes);
11263: foreach my $prefix (@prefixes) {
11264: $defaultshash{'usersessions'}{$prefix} = {};
11265: }
1.160.6.27 raeburn 11266: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11267: my $resulttext;
1.138 raeburn 11268: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11269: foreach my $prefix (@prefixes) {
1.145 raeburn 11270: next if ($prefix eq 'spares');
11271: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11272: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11273: if ($type eq 'version') {
11274: my $value = $env{'form.'.$prefix.'_'.$type};
11275: my $okvalue;
11276: if ($value ne '') {
11277: if (grep(/^\Q$value\E$/,@lcversions)) {
11278: $okvalue = $value;
11279: }
11280: }
11281: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11282: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11283: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11284: if ($inuse == 0) {
11285: $changes{$prefix}{$type} = 1;
11286: } else {
11287: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11288: $changes{$prefix}{$type} = 1;
11289: }
11290: if ($okvalue ne '') {
11291: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11292: }
11293: }
11294: } else {
11295: if (($inuse == 1) && ($okvalue ne '')) {
11296: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11297: $changes{$prefix}{$type} = 1;
11298: }
11299: }
11300: } else {
11301: if (($inuse == 1) && ($okvalue ne '')) {
11302: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11303: $changes{$prefix}{$type} = 1;
11304: }
11305: }
11306: } else {
11307: if (($inuse == 1) && ($okvalue ne '')) {
11308: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11309: $changes{$prefix}{$type} = 1;
11310: }
11311: }
11312: } else {
11313: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11314: my @okvals;
11315: foreach my $val (@vals) {
1.138 raeburn 11316: if ($val =~ /:/) {
11317: my @items = split(/:/,$val);
11318: foreach my $item (@items) {
11319: if (ref($by_location{$item}) eq 'ARRAY') {
11320: push(@okvals,$item);
11321: }
11322: }
11323: } else {
11324: if (ref($by_location{$val}) eq 'ARRAY') {
11325: push(@okvals,$val);
11326: }
1.137 raeburn 11327: }
11328: }
11329: @okvals = sort(@okvals);
11330: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11331: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11332: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11333: if ($inuse == 0) {
11334: $changes{$prefix}{$type} = 1;
11335: } else {
11336: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11337: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11338: if (@changed > 0) {
11339: $changes{$prefix}{$type} = 1;
11340: }
11341: }
11342: } else {
11343: if ($inuse == 1) {
11344: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11345: $changes{$prefix}{$type} = 1;
11346: }
11347: }
11348: } else {
11349: if ($inuse == 1) {
11350: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11351: $changes{$prefix}{$type} = 1;
11352: }
11353: }
11354: } else {
11355: if ($inuse == 1) {
11356: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11357: $changes{$prefix}{$type} = 1;
11358: }
11359: }
11360: }
11361: }
11362: }
1.145 raeburn 11363:
11364: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11365: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11366: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11367: my $savespares;
11368:
11369: foreach my $lonhost (sort(keys(%servers))) {
11370: my $serverhomeID =
11371: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11372: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11373: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11374: my %spareschg;
11375: foreach my $type (@{$types{'spares'}}) {
11376: my @okspares;
11377: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
11378: foreach my $server (@checked) {
1.152 raeburn 11379: if (&Apache::lonnet::hostname($server) ne '') {
11380: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
11381: unless (grep(/^\Q$server\E$/,@okspares)) {
11382: push(@okspares,$server);
11383: }
1.145 raeburn 11384: }
11385: }
11386: }
11387: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
11388: my $newspare;
1.152 raeburn 11389: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
11390: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 11391: $newspare = $new;
11392: }
11393: }
1.152 raeburn 11394: my @spares;
11395: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
11396: @spares = sort(@okspares,$newspare);
11397: } else {
11398: @spares = sort(@okspares);
11399: }
11400: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 11401: if (ref($spareid{$lonhost}) eq 'HASH') {
11402: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 11403: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 11404: if (@diffs > 0) {
11405: $spareschg{$type} = 1;
11406: }
11407: }
11408: }
11409: }
11410: if (keys(%spareschg) > 0) {
11411: $changes{'spares'}{$lonhost} = \%spareschg;
11412: }
11413: }
1.160.6.61 raeburn 11414: $defaultshash{'usersessions'}{'offloadnow'} = {};
11415: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
11416: my @okoffload;
11417: if (@offloadnow) {
11418: foreach my $server (@offloadnow) {
11419: if (&Apache::lonnet::hostname($server) ne '') {
11420: unless (grep(/^\Q$server\E$/,@okoffload)) {
11421: push(@okoffload,$server);
11422: }
11423: }
11424: }
11425: if (@okoffload) {
11426: foreach my $lonhost (@okoffload) {
11427: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
11428: }
11429: }
11430: }
1.145 raeburn 11431: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11432: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
11433: if (ref($changes{'spares'}) eq 'HASH') {
11434: if (keys(%{$changes{'spares'}}) > 0) {
11435: $savespares = 1;
11436: }
11437: }
11438: } else {
11439: $savespares = 1;
11440: }
1.160.6.61 raeburn 11441: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
11442: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
11443: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
11444: $changes{'offloadnow'} = 1;
11445: last;
11446: }
11447: }
11448: unless ($changes{'offloadnow'}) {
11449: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
11450: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
11451: $changes{'offloadnow'} = 1;
11452: last;
11453: }
11454: }
11455: }
11456: } elsif (@okoffload) {
11457: $changes{'offloadnow'} = 1;
11458: }
11459: } elsif (@okoffload) {
11460: $changes{'offloadnow'} = 1;
1.145 raeburn 11461: }
1.147 raeburn 11462: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11463: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 11464: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11465: $dom);
11466: if ($putresult eq 'ok') {
11467: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11468: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11469: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11470: }
11471: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11472: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11473: }
1.160.6.61 raeburn 11474: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11475: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11476: }
1.137 raeburn 11477: }
11478: my $cachetime = 24*60*60;
11479: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11480: if (ref($lastactref) eq 'HASH') {
11481: $lastactref->{'domdefaults'} = 1;
11482: }
1.147 raeburn 11483: if (keys(%changes) > 0) {
11484: my %lt = &usersession_titles();
11485: $resulttext = &mt('Changes made:').'<ul>';
11486: foreach my $prefix (@prefixes) {
11487: if (ref($changes{$prefix}) eq 'HASH') {
11488: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11489: if ($prefix eq 'spares') {
11490: if (ref($changes{$prefix}) eq 'HASH') {
11491: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11492: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 11493: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 11494: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11495: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 11496: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11497: foreach my $type (@{$types{$prefix}}) {
11498: if ($changes{$prefix}{$lonhost}{$type}) {
11499: my $offloadto = &mt('None');
11500: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11501: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11502: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11503: }
1.145 raeburn 11504: }
1.147 raeburn 11505: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 11506: }
1.137 raeburn 11507: }
11508: }
1.147 raeburn 11509: $resulttext .= '</li>';
1.137 raeburn 11510: }
11511: }
1.147 raeburn 11512: } else {
11513: foreach my $type (@{$types{$prefix}}) {
11514: if (defined($changes{$prefix}{$type})) {
11515: my $newvalue;
11516: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11517: if (ref($defaultshash{'usersessions'}{$prefix})) {
11518: if ($type eq 'version') {
11519: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11520: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11521: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11522: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11523: }
1.145 raeburn 11524: }
11525: }
11526: }
1.147 raeburn 11527: if ($newvalue eq '') {
11528: if ($type eq 'version') {
11529: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11530: } else {
11531: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11532: }
1.145 raeburn 11533: } else {
1.147 raeburn 11534: if ($type eq 'version') {
11535: $newvalue .= ' '.&mt('(or later)');
11536: }
11537: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11538: }
1.137 raeburn 11539: }
11540: }
11541: }
1.147 raeburn 11542: $resulttext .= '</ul>';
1.137 raeburn 11543: }
11544: }
1.160.6.61 raeburn 11545: if ($changes{'offloadnow'}) {
11546: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11547: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11548: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11549: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11550: $resulttext .= '<li>'.$lonhost.'</li>';
11551: }
11552: $resulttext .= '</ul>';
11553: } else {
11554: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11555: }
11556: } else {
11557: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11558: }
11559: }
1.147 raeburn 11560: $resulttext .= '</ul>';
11561: } else {
11562: $resulttext = $nochgmsg;
1.137 raeburn 11563: }
11564: } else {
11565: $resulttext = '<span class="LC_error">'.
11566: &mt('An error occurred: [_1]',$putresult).'</span>';
11567: }
11568: } else {
1.147 raeburn 11569: $resulttext = $nochgmsg;
1.137 raeburn 11570: }
11571: return $resulttext;
11572: }
11573:
1.150 raeburn 11574: sub modify_loadbalancing {
11575: my ($dom,%domconfig) = @_;
11576: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11577: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11578: my ($othertitle,$usertypes,$types) =
11579: &Apache::loncommon::sorted_inst_types($dom);
11580: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11581: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11582: my @sparestypes = ('primary','default');
11583: my %typetitles = &sparestype_titles();
11584: my $resulttext;
1.160.6.7 raeburn 11585: my (%currbalancer,%currtargets,%currrules,%existing);
11586: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11587: %existing = %{$domconfig{'loadbalancing'}};
11588: }
11589: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11590: \%currtargets,\%currrules);
11591: my ($saveloadbalancing,%defaultshash,%changes);
11592: my ($alltypes,$othertypes,$titles) =
11593: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11594: my %ruletitles = &offloadtype_text();
11595: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11596: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11597: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11598: if ($balancer eq '') {
11599: next;
11600: }
11601: if (!exists($servers{$balancer})) {
11602: if (exists($currbalancer{$balancer})) {
11603: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11604: }
1.160.6.7 raeburn 11605: next;
11606: }
11607: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11608: push(@{$changes{'delete'}},$balancer);
11609: next;
11610: }
11611: if (!exists($currbalancer{$balancer})) {
11612: push(@{$changes{'add'}},$balancer);
11613: }
11614: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11615: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11616: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11617: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11618: $saveloadbalancing = 1;
11619: }
11620: foreach my $sparetype (@sparestypes) {
11621: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11622: my @offloadto;
11623: foreach my $target (@targets) {
11624: if (($servers{$target}) && ($target ne $balancer)) {
11625: if ($sparetype eq 'default') {
11626: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11627: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11628: }
11629: }
1.160.6.7 raeburn 11630: unless(grep(/^\Q$target\E$/,@offloadto)) {
11631: push(@offloadto,$target);
11632: }
1.150 raeburn 11633: }
1.160.6.7 raeburn 11634: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11635: }
11636: }
1.160.6.7 raeburn 11637: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11638: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11639: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11640: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11641: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11642: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11643: }
1.160.6.7 raeburn 11644: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11645: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11646: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11647: }
11648: }
11649: }
11650: } else {
1.160.6.7 raeburn 11651: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11652: foreach my $sparetype (@sparestypes) {
11653: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11654: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11655: $changes{'curr'}{$balancer}{'targets'} = 1;
11656: }
1.150 raeburn 11657: }
11658: }
1.160.6.7 raeburn 11659: }
1.150 raeburn 11660: }
11661: my $ishomedom;
1.160.6.7 raeburn 11662: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11663: $ishomedom = 1;
1.150 raeburn 11664: }
11665: if (ref($alltypes) eq 'ARRAY') {
11666: foreach my $type (@{$alltypes}) {
11667: my $rule;
1.160.6.7 raeburn 11668: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11669: (!$ishomedom)) {
1.160.6.7 raeburn 11670: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11671: }
11672: if ($rule eq 'specific') {
1.160.6.55 raeburn 11673: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11674: if (exists($servers{$specifiedhost})) {
11675: $rule = $specifiedhost;
11676: }
1.150 raeburn 11677: }
1.160.6.7 raeburn 11678: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11679: if (ref($currrules{$balancer}) eq 'HASH') {
11680: if ($rule ne $currrules{$balancer}{$type}) {
11681: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11682: }
11683: } elsif ($rule ne '') {
1.160.6.7 raeburn 11684: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11685: }
11686: }
11687: }
1.160.6.7 raeburn 11688: }
11689: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11690: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11691: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11692: $defaultshash{'loadbalancing'} = {};
11693: }
11694: my $putresult = &Apache::lonnet::put_dom('configuration',
11695: \%defaultshash,$dom);
11696: if ($putresult eq 'ok') {
11697: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11698: my %toupdate;
1.160.6.7 raeburn 11699: if (ref($changes{'delete'}) eq 'ARRAY') {
11700: foreach my $balancer (sort(@{$changes{'delete'}})) {
11701: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11702: $toupdate{$balancer} = 1;
1.150 raeburn 11703: }
1.160.6.7 raeburn 11704: }
11705: if (ref($changes{'add'}) eq 'ARRAY') {
11706: foreach my $balancer (sort(@{$changes{'add'}})) {
11707: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11708: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11709: }
11710: }
11711: if (ref($changes{'curr'}) eq 'HASH') {
11712: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11713: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11714: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11715: if ($changes{'curr'}{$balancer}{'targets'}) {
11716: my %offloadstr;
11717: foreach my $sparetype (@sparestypes) {
11718: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11719: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11720: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11721: }
11722: }
1.150 raeburn 11723: }
1.160.6.7 raeburn 11724: if (keys(%offloadstr) == 0) {
11725: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11726: } else {
1.160.6.7 raeburn 11727: my $showoffload;
11728: foreach my $sparetype (@sparestypes) {
11729: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11730: if (defined($offloadstr{$sparetype})) {
11731: $showoffload .= $offloadstr{$sparetype};
11732: } else {
11733: $showoffload .= &mt('None');
11734: }
11735: $showoffload .= (' 'x3);
11736: }
11737: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11738: }
11739: }
11740: }
1.160.6.7 raeburn 11741: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11742: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11743: foreach my $type (@{$alltypes}) {
11744: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11745: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11746: my $balancetext;
11747: if ($rule eq '') {
11748: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11749: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11750: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11751: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11752: foreach my $sparetype (@sparestypes) {
11753: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11754: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11755: }
11756: }
1.160.6.55 raeburn 11757: foreach my $item (@{$alltypes}) {
11758: next if ($item =~ /^_LC_ipchange/);
11759: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11760: if ($hasrule eq 'homeserver') {
11761: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11762: } else {
11763: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11764: if ($servers{$hasrule}) {
11765: $toupdate{$hasrule} = 1;
11766: }
11767: }
11768: }
11769: }
11770: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11771: $balancetext = $ruletitles{$rule};
11772: } else {
11773: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11774: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11775: if ($receiver) {
11776: $toupdate{$receiver};
11777: }
11778: }
11779: } else {
11780: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11781: }
1.160.6.7 raeburn 11782: } else {
11783: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11784: }
1.160.6.26 raeburn 11785: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11786: }
11787: }
11788: }
11789: }
1.160.6.54 raeburn 11790: if (keys(%toupdate)) {
11791: my %thismachine;
11792: my $updatedhere;
11793: my $cachetime = 60*60*24;
11794: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11795: foreach my $lonhost (keys(%toupdate)) {
11796: if ($thismachine{$lonhost}) {
11797: unless ($updatedhere) {
11798: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11799: $defaultshash{'loadbalancing'},
11800: $cachetime);
11801: $updatedhere = 1;
11802: }
11803: } else {
11804: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11805: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11806: }
11807: }
11808: }
1.150 raeburn 11809: }
1.160.6.7 raeburn 11810: }
11811: if ($resulttext ne '') {
11812: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11813: } else {
11814: $resulttext = $nochgmsg;
11815: }
11816: } else {
1.160.6.7 raeburn 11817: $resulttext = $nochgmsg;
1.150 raeburn 11818: }
11819: } else {
1.160.6.7 raeburn 11820: $resulttext = '<span class="LC_error">'.
11821: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11822: }
11823: } else {
1.160.6.7 raeburn 11824: $resulttext = $nochgmsg;
1.150 raeburn 11825: }
11826: return $resulttext;
11827: }
11828:
1.48 raeburn 11829: sub recurse_check {
11830: my ($chkcats,$categories,$depth,$name) = @_;
11831: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11832: my $chg = 0;
11833: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11834: my $category = $chkcats->[$depth]{$name}[$j];
11835: my $item;
11836: if ($category eq '') {
11837: $chg ++;
11838: } else {
11839: my $deeper = $depth + 1;
11840: $item = &escape($category).':'.&escape($name).':'.$depth;
11841: if ($chg) {
11842: $categories->{$item} -= $chg;
11843: }
11844: &recurse_check($chkcats,$categories,$deeper,$category);
11845: $deeper --;
11846: }
11847: }
11848: }
11849: return;
11850: }
11851:
11852: sub recurse_cat_deletes {
11853: my ($item,$coursecategories,$deletions) = @_;
11854: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11855: my $subdepth = $depth + 1;
11856: if (ref($coursecategories) eq 'HASH') {
11857: foreach my $subitem (keys(%{$coursecategories})) {
11858: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11859: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11860: delete($coursecategories->{$subitem});
11861: $deletions->{$subitem} = 1;
11862: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11863: }
1.48 raeburn 11864: }
11865: }
11866: return;
11867: }
11868:
1.125 raeburn 11869: sub get_active_dcs {
11870: my ($dom) = @_;
1.160.6.16 raeburn 11871: my $now = time;
11872: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11873: my %domcoords;
11874: my $numdcs = 0;
11875: foreach my $server (keys(%dompersonnel)) {
11876: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11877: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11878: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11879: }
11880: }
11881: return %domcoords;
11882: }
11883:
11884: sub active_dc_picker {
1.160.6.16 raeburn 11885: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11886: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11887: my @domcoord = keys(%domcoords);
11888: if (keys(%currhash)) {
11889: foreach my $dc (keys(%currhash)) {
11890: unless (exists($domcoords{$dc})) {
11891: push(@domcoord,$dc);
11892: }
11893: }
11894: }
11895: @domcoord = sort(@domcoord);
11896: my $numdcs = scalar(@domcoord);
11897: my $rows = 0;
11898: my $table;
1.125 raeburn 11899: if ($numdcs > 1) {
1.160.6.16 raeburn 11900: $table = '<table>';
11901: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11902: my $rem = $i%($numinrow);
11903: if ($rem == 0) {
11904: if ($i > 0) {
1.160.6.16 raeburn 11905: $table .= '</tr>';
1.125 raeburn 11906: }
1.160.6.16 raeburn 11907: $table .= '<tr>';
11908: $rows ++;
1.125 raeburn 11909: }
1.160.6.16 raeburn 11910: my $check = '';
11911: if ($inputtype eq 'radio') {
11912: if (keys(%currhash) == 0) {
11913: if (!$i) {
11914: $check = ' checked="checked"';
11915: }
11916: } elsif (exists($currhash{$domcoord[$i]})) {
11917: $check = ' checked="checked"';
11918: }
11919: } else {
11920: if (exists($currhash{$domcoord[$i]})) {
11921: $check = ' checked="checked"';
1.125 raeburn 11922: }
11923: }
1.160.6.16 raeburn 11924: if ($i == @domcoord - 1) {
1.125 raeburn 11925: my $colsleft = $numinrow - $rem;
11926: if ($colsleft > 1) {
1.160.6.16 raeburn 11927: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11928: } else {
1.160.6.16 raeburn 11929: $table .= '<td class="LC_left_item">';
1.125 raeburn 11930: }
11931: } else {
1.160.6.16 raeburn 11932: $table .= '<td class="LC_left_item">';
11933: }
11934: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11935: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11936: $table .= '<span class="LC_nobreak"><label>'.
11937: '<input type="'.$inputtype.'" name="'.$name.'"'.
11938: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11939: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11940: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11941: }
1.160.6.33 raeburn 11942: $table .= '</label></span></td>';
1.125 raeburn 11943: }
1.160.6.16 raeburn 11944: $table .= '</tr></table>';
11945: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11946: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11947: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11948: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11949: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11950: if ($user ne $dcname.':'.$dcdom) {
11951: $table .= ' ('.$dcname.':'.$dcdom.')';
11952: }
1.160.6.16 raeburn 11953: } else {
11954: my $check;
11955: if (exists($currhash{$domcoord[0]})) {
11956: $check = ' checked="checked"';
11957: }
1.160.6.50 raeburn 11958: $table = '<span class="LC_nobreak"><label>'.
11959: '<input type="checkbox" name="'.$name.'" '.
11960: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11961: if ($user ne $dcname.':'.$dcdom) {
11962: $table .= ' ('.$dcname.':'.$dcdom.')';
11963: }
11964: $table .= '</label></span>';
1.160.6.16 raeburn 11965: $rows ++;
11966: }
1.125 raeburn 11967: }
1.160.6.16 raeburn 11968: return ($numdcs,$table,$rows);
1.125 raeburn 11969: }
11970:
1.137 raeburn 11971: sub usersession_titles {
11972: return &Apache::lonlocal::texthash(
11973: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11974: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11975: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11976: version => 'LON-CAPA version requirement',
1.138 raeburn 11977: excludedomain => 'Allow all, but exclude specific domains',
11978: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11979: primary => 'Primary (checked first)',
1.154 raeburn 11980: default => 'Default',
1.137 raeburn 11981: );
11982: }
11983:
1.152 raeburn 11984: sub id_for_thisdom {
11985: my (%servers) = @_;
11986: my %altids;
11987: foreach my $server (keys(%servers)) {
11988: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11989: if ($serverhome ne $server) {
11990: $altids{$serverhome} = $server;
11991: }
11992: }
11993: return %altids;
11994: }
11995:
1.150 raeburn 11996: sub count_servers {
11997: my ($currbalancer,%servers) = @_;
11998: my (@spares,$numspares);
11999: foreach my $lonhost (sort(keys(%servers))) {
12000: next if ($currbalancer eq $lonhost);
12001: push(@spares,$lonhost);
12002: }
12003: if ($currbalancer) {
12004: $numspares = scalar(@spares);
12005: } else {
12006: $numspares = scalar(@spares) - 1;
12007: }
12008: return ($numspares,@spares);
12009: }
12010:
12011: sub lonbalance_targets_js {
1.160.6.7 raeburn 12012: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 12013: my $select = &mt('Select');
12014: my ($alltargets,$allishome,$allinsttypes,@alltypes);
12015: if (ref($servers) eq 'HASH') {
12016: $alltargets = join("','",sort(keys(%{$servers})));
12017: my @homedoms;
12018: foreach my $server (sort(keys(%{$servers}))) {
12019: if (&Apache::lonnet::host_domain($server) eq $dom) {
12020: push(@homedoms,'1');
12021: } else {
12022: push(@homedoms,'0');
12023: }
12024: }
12025: $allishome = join("','",@homedoms);
12026: }
12027: if (ref($types) eq 'ARRAY') {
12028: if (@{$types} > 0) {
12029: @alltypes = @{$types};
12030: }
12031: }
12032: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
12033: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 12034: my (%currbalancer,%currtargets,%currrules,%existing);
12035: if (ref($settings) eq 'HASH') {
12036: %existing = %{$settings};
12037: }
12038: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
12039: \%currtargets,\%currrules);
12040: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 12041: return <<"END";
12042:
12043: <script type="text/javascript">
12044: // <![CDATA[
12045:
1.160.6.7 raeburn 12046: currBalancers = new Array('$balancers');
12047:
12048: function toggleTargets(balnum) {
12049: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12050: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
12051: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
12052: var prevbalancer = prevhostitem.value;
12053: var baltotal = document.getElementById('loadbalancing_total').value;
12054: prevhostitem.value = balancer;
12055: if (prevbalancer != '') {
12056: var prevIdx = currBalancers.indexOf(prevbalancer);
12057: if (prevIdx != -1) {
12058: currBalancers.splice(prevIdx,1);
12059: }
12060: }
1.150 raeburn 12061: if (balancer == '') {
1.160.6.7 raeburn 12062: hideSpares(balnum);
1.150 raeburn 12063: } else {
1.160.6.7 raeburn 12064: var currIdx = currBalancers.indexOf(balancer);
12065: if (currIdx == -1) {
12066: currBalancers.push(balancer);
12067: }
1.150 raeburn 12068: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 12069: var ishomedom = homedoms[lonhostitem.selectedIndex];
12070: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 12071: }
1.160.6.7 raeburn 12072: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 12073: return;
12074: }
12075:
1.160.6.7 raeburn 12076: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 12077: var alltargets = new Array('$alltargets');
12078: var insttypes = new Array('$allinsttypes');
1.151 raeburn 12079: var offloadtypes = new Array('primary','default');
12080:
1.160.6.7 raeburn 12081: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
12082: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 12083:
1.151 raeburn 12084: for (var i=0; i<offloadtypes.length; i++) {
12085: var count = 0;
12086: for (var j=0; j<alltargets.length; j++) {
12087: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 12088: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
12089: item.value = alltargets[j];
12090: item.style.textAlign='left';
12091: item.style.textFace='normal';
12092: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
12093: if (currBalancers.indexOf(alltargets[j]) == -1) {
12094: item.disabled = '';
12095: } else {
12096: item.disabled = 'disabled';
12097: item.checked = false;
12098: }
1.151 raeburn 12099: count ++;
12100: }
1.150 raeburn 12101: }
12102: }
1.151 raeburn 12103: for (var k=0; k<insttypes.length; k++) {
12104: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 12105: if (ishomedom == 1) {
1.160.6.7 raeburn 12106: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12107: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12108: } else {
1.160.6.7 raeburn 12109: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12110: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 12111: }
12112: } else {
1.160.6.7 raeburn 12113: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12114: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12115: }
1.151 raeburn 12116: if ((insttypes[k] != '_LC_external') &&
12117: ((insttypes[k] != '_LC_internetdom') ||
12118: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 12119: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
12120: item.options.length = 0;
12121: item.options[0] = new Option("","",true,true);
12122: var idx = 0;
1.151 raeburn 12123: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 12124: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
12125: idx ++;
12126: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 12127: }
12128: }
12129: }
12130: }
12131: return;
12132: }
12133:
1.160.6.7 raeburn 12134: function hideSpares(balnum) {
1.150 raeburn 12135: var alltargets = new Array('$alltargets');
12136: var insttypes = new Array('$allinsttypes');
12137: var offloadtypes = new Array('primary','default');
12138:
1.160.6.7 raeburn 12139: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
12140: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 12141:
12142: var total = alltargets.length - 1;
12143: for (var i=0; i<offloadtypes; i++) {
12144: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 12145: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
12146: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
12147: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 12148: }
1.150 raeburn 12149: }
12150: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 12151: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12152: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 12153: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 12154: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
12155: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 12156: }
12157: }
12158: return;
12159: }
12160:
1.160.6.7 raeburn 12161: function checkOffloads(item,balnum,type) {
1.150 raeburn 12162: var alltargets = new Array('$alltargets');
12163: var offloadtypes = new Array('primary','default');
12164: if (item.checked) {
12165: var total = alltargets.length - 1;
12166: var other;
12167: if (type == offloadtypes[0]) {
1.151 raeburn 12168: other = offloadtypes[1];
1.150 raeburn 12169: } else {
1.151 raeburn 12170: other = offloadtypes[0];
1.150 raeburn 12171: }
12172: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 12173: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 12174: if (server == item.value) {
1.160.6.7 raeburn 12175: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12176: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 12177: }
12178: }
12179: }
12180: }
12181: return;
12182: }
12183:
1.160.6.7 raeburn 12184: function singleServerToggle(balnum,type) {
12185: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 12186: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 12187: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12188: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12189:
12190: } else {
1.160.6.7 raeburn 12191: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12192: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 12193: }
12194: return;
12195: }
12196:
1.160.6.7 raeburn 12197: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 12198: if (type == '_LC_external') {
1.160.6.26 raeburn 12199: return;
1.150 raeburn 12200: }
1.160.6.7 raeburn 12201: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 12202: for (var i=0; i<typesRules.length; i++) {
12203: if (formname.elements[typesRules[i]].checked) {
12204: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 12205: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12206: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12207: } else {
1.160.6.7 raeburn 12208: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12209: }
12210: }
12211: }
12212: return;
12213: }
12214:
12215: function balancerDeleteChange(balnum) {
12216: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12217: var baltotal = document.getElementById('loadbalancing_total').value;
12218: var addtarget;
12219: var removetarget;
12220: var action = 'delete';
12221: if (document.getElementById('loadbalancing_delete_'+balnum)) {
12222: var lonhost = hostitem.value;
12223: var currIdx = currBalancers.indexOf(lonhost);
12224: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
12225: if (currIdx != -1) {
12226: currBalancers.splice(currIdx,1);
12227: }
12228: addtarget = lonhost;
12229: } else {
12230: if (currIdx == -1) {
12231: currBalancers.push(lonhost);
12232: }
12233: removetarget = lonhost;
12234: action = 'undelete';
12235: }
12236: balancerChange(balnum,baltotal,action,addtarget,removetarget);
12237: }
12238: return;
12239: }
12240:
12241: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
12242: if (baltotal > 1) {
12243: var offloadtypes = new Array('primary','default');
12244: var alltargets = new Array('$alltargets');
12245: var insttypes = new Array('$allinsttypes');
12246: for (var i=0; i<baltotal; i++) {
12247: if (i != balnum) {
12248: for (var j=0; j<offloadtypes.length; j++) {
12249: var total = alltargets.length - 1;
12250: for (var k=0; k<total; k++) {
12251: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
12252: var server = serveritem.value;
12253: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12254: if (server == addtarget) {
12255: serveritem.disabled = '';
12256: }
12257: }
12258: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12259: if (server == removetarget) {
12260: serveritem.disabled = 'disabled';
12261: serveritem.checked = false;
12262: }
12263: }
12264: }
12265: }
12266: for (var j=0; j<insttypes.length; j++) {
12267: if (insttypes[j] != '_LC_external') {
12268: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12269: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12270: var currSel = singleserver.selectedIndex;
12271: var currVal = singleserver.options[currSel].value;
12272: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12273: var numoptions = singleserver.options.length;
12274: var needsnew = 1;
12275: for (var k=0; k<numoptions; k++) {
12276: if (singleserver.options[k] == addtarget) {
12277: needsnew = 0;
12278: break;
12279: }
12280: }
12281: if (needsnew == 1) {
12282: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12283: }
12284: }
12285: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12286: singleserver.options.length = 0;
12287: if ((currVal) && (currVal != removetarget)) {
12288: singleserver.options[0] = new Option("","",false,false);
12289: } else {
12290: singleserver.options[0] = new Option("","",true,true);
12291: }
12292: var idx = 0;
12293: for (var m=0; m<alltargets.length; m++) {
12294: if (currBalancers.indexOf(alltargets[m]) == -1) {
12295: idx ++;
12296: if (currVal == alltargets[m]) {
12297: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12298: } else {
12299: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12300: }
12301: }
12302: }
12303: }
12304: }
12305: }
12306: }
1.150 raeburn 12307: }
12308: }
12309: }
12310: return;
12311: }
12312:
1.152 raeburn 12313: // ]]>
12314: </script>
12315:
12316: END
12317: }
12318:
12319: sub new_spares_js {
12320: my @sparestypes = ('primary','default');
12321: my $types = join("','",@sparestypes);
12322: my $select = &mt('Select');
12323: return <<"END";
12324:
12325: <script type="text/javascript">
12326: // <![CDATA[
12327:
12328: function updateNewSpares(formname,lonhost) {
12329: var types = new Array('$types');
12330: var include = new Array();
12331: var exclude = new Array();
12332: for (var i=0; i<types.length; i++) {
12333: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12334: for (var j=0; j<spareboxes.length; j++) {
12335: if (formname.elements[spareboxes[j]].checked) {
12336: exclude.push(formname.elements[spareboxes[j]].value);
12337: } else {
12338: include.push(formname.elements[spareboxes[j]].value);
12339: }
12340: }
12341: }
12342: for (var i=0; i<types.length; i++) {
12343: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12344: var selIdx = newSpare.selectedIndex;
12345: var currnew = newSpare.options[selIdx].value;
12346: var okSpares = new Array();
12347: for (var j=0; j<newSpare.options.length; j++) {
12348: var possible = newSpare.options[j].value;
12349: if (possible != '') {
12350: if (exclude.indexOf(possible) == -1) {
12351: okSpares.push(possible);
12352: } else {
12353: if (currnew == possible) {
12354: selIdx = 0;
12355: }
12356: }
12357: }
12358: }
12359: for (var k=0; k<include.length; k++) {
12360: if (okSpares.indexOf(include[k]) == -1) {
12361: okSpares.push(include[k]);
12362: }
12363: }
12364: okSpares.sort();
12365: newSpare.options.length = 0;
12366: if (selIdx == 0) {
12367: newSpare.options[0] = new Option("$select","",true,true);
12368: } else {
12369: newSpare.options[0] = new Option("$select","",false,false);
12370: }
12371: for (var m=0; m<okSpares.length; m++) {
12372: var idx = m+1;
12373: var selThis = 0;
12374: if (selIdx != 0) {
12375: if (okSpares[m] == currnew) {
12376: selThis = 1;
12377: }
12378: }
12379: if (selThis == 1) {
12380: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
12381: } else {
12382: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
12383: }
12384: }
12385: }
12386: return;
12387: }
12388:
12389: function checkNewSpares(lonhost,type) {
12390: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
12391: var chosen = newSpare.options[newSpare.selectedIndex].value;
12392: if (chosen != '') {
12393: var othertype;
12394: var othernewSpare;
12395: if (type == 'primary') {
12396: othernewSpare = document.getElementById('newspare_default_'+lonhost);
12397: }
12398: if (type == 'default') {
12399: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
12400: }
12401: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
12402: othernewSpare.selectedIndex = 0;
12403: }
12404: }
12405: return;
12406: }
12407:
12408: // ]]>
12409: </script>
12410:
12411: END
12412:
12413: }
12414:
12415: sub common_domprefs_js {
12416: return <<"END";
12417:
12418: <script type="text/javascript">
12419: // <![CDATA[
12420:
1.150 raeburn 12421: function getIndicesByName(formname,item) {
1.152 raeburn 12422: var group = new Array();
1.150 raeburn 12423: for (var i=0;i<formname.elements.length;i++) {
12424: if (formname.elements[i].name == item) {
1.152 raeburn 12425: group.push(formname.elements[i].id);
1.150 raeburn 12426: }
12427: }
1.152 raeburn 12428: return group;
1.150 raeburn 12429: }
12430:
12431: // ]]>
12432: </script>
12433:
12434: END
1.152 raeburn 12435:
1.150 raeburn 12436: }
12437:
1.160.6.5 raeburn 12438: sub recaptcha_js {
12439: my %lt = &captcha_phrases();
12440: return <<"END";
12441:
12442: <script type="text/javascript">
12443: // <![CDATA[
12444:
12445: function updateCaptcha(caller,context) {
12446: var privitem;
12447: var pubitem;
12448: var privtext;
12449: var pubtext;
1.160.6.69 raeburn 12450: var versionitem;
12451: var versiontext;
1.160.6.5 raeburn 12452: if (document.getElementById(context+'_recaptchapub')) {
12453: pubitem = document.getElementById(context+'_recaptchapub');
12454: } else {
12455: return;
12456: }
12457: if (document.getElementById(context+'_recaptchapriv')) {
12458: privitem = document.getElementById(context+'_recaptchapriv');
12459: } else {
12460: return;
12461: }
12462: if (document.getElementById(context+'_recaptchapubtxt')) {
12463: pubtext = document.getElementById(context+'_recaptchapubtxt');
12464: } else {
12465: return;
12466: }
12467: if (document.getElementById(context+'_recaptchaprivtxt')) {
12468: privtext = document.getElementById(context+'_recaptchaprivtxt');
12469: } else {
12470: return;
12471: }
1.160.6.69 raeburn 12472: if (document.getElementById(context+'_recaptchaversion')) {
12473: versionitem = document.getElementById(context+'_recaptchaversion');
12474: } else {
12475: return;
12476: }
12477: if (document.getElementById(context+'_recaptchavertxt')) {
12478: versiontext = document.getElementById(context+'_recaptchavertxt');
12479: } else {
12480: return;
12481: }
1.160.6.5 raeburn 12482: if (caller.checked) {
12483: if (caller.value == 'recaptcha') {
12484: pubitem.type = 'text';
12485: privitem.type = 'text';
12486: pubitem.size = '40';
12487: privitem.size = '40';
12488: pubtext.innerHTML = "$lt{'pub'}";
12489: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 12490: versionitem.type = 'text';
12491: versionitem.size = '3';
12492: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 12493: } else {
12494: pubitem.type = 'hidden';
12495: privitem.type = 'hidden';
1.160.6.69 raeburn 12496: versionitem.type = 'hidden';
1.160.6.5 raeburn 12497: pubtext.innerHTML = '';
12498: privtext.innerHTML = '';
1.160.6.69 raeburn 12499: versiontext.innerHTML = '';
1.160.6.5 raeburn 12500: }
12501: }
12502: return;
12503: }
12504:
12505: // ]]>
12506: </script>
12507:
12508: END
12509:
12510: }
12511:
1.160.6.40 raeburn 12512: sub toggle_display_js {
1.160.6.16 raeburn 12513: return <<"END";
12514:
12515: <script type="text/javascript">
12516: // <![CDATA[
12517:
1.160.6.40 raeburn 12518: function toggleDisplay(domForm,caller) {
12519: if (document.getElementById(caller)) {
12520: var divitem = document.getElementById(caller);
12521: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 12522: var checkval = 1;
12523: var dispval = 'block';
1.160.6.40 raeburn 12524: if (caller == 'emailoptions') {
12525: optionsElement = domForm.cancreate_email;
12526: }
1.160.6.57 raeburn 12527: if (caller == 'studentsubmission') {
12528: optionsElement = domForm.postsubmit;
12529: }
1.160.6.64 raeburn 12530: if (caller == 'cloneinstcode') {
12531: optionsElement = domForm.canclone;
12532: checkval = 'instcode';
12533: }
1.160.6.40 raeburn 12534: if (optionsElement.length) {
1.160.6.16 raeburn 12535: var currval;
1.160.6.40 raeburn 12536: for (var i=0; i<optionsElement.length; i++) {
12537: if (optionsElement[i].checked) {
12538: currval = optionsElement[i].value;
1.160.6.16 raeburn 12539: }
12540: }
1.160.6.64 raeburn 12541: if (currval == checkval) {
12542: divitem.style.display = dispval;
1.160.6.16 raeburn 12543: } else {
1.160.6.40 raeburn 12544: divitem.style.display = 'none';
1.160.6.16 raeburn 12545: }
12546: }
12547: }
12548: return;
12549: }
12550:
12551: // ]]>
12552: </script>
12553:
12554: END
12555:
12556: }
12557:
1.160.6.5 raeburn 12558: sub captcha_phrases {
12559: return &Apache::lonlocal::texthash (
12560: priv => 'Private key',
12561: pub => 'Public key',
12562: original => 'original (CAPTCHA)',
12563: recaptcha => 'successor (ReCAPTCHA)',
12564: notused => 'unused',
1.160.6.69 raeburn 12565: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 12566: );
12567: }
12568:
1.160.6.24 raeburn 12569: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 12570: my ($dom,$cachekeys) = @_;
12571: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 12572: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12573: my %thismachine;
12574: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 12575: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 12576: if (keys(%servers)) {
1.160.6.24 raeburn 12577: foreach my $server (keys(%servers)) {
12578: next if ($thismachine{$server});
1.160.6.27 raeburn 12579: my @cached;
12580: foreach my $name (@posscached) {
12581: if ($cachekeys->{$name}) {
12582: push(@cached,&escape($name).':'.&escape($dom));
12583: }
12584: }
12585: if (@cached) {
12586: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12587: }
1.160.6.24 raeburn 12588: }
12589: }
12590: return;
12591: }
12592:
1.3 raeburn 12593: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>