Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.76
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.76! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.75 2016/10/25 12:54:25 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.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 222: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 223: 'serverstatuses','helpsettings','coursedefaults',
224: 'selfenrollment','usersessions');
1.160.6.7 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.160.6.37 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
1.160.6.56 raeburn 253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 255: col2 => 'Value'}],
1.160.6.37 raeburn 256: print => \&print_login,
257: modify => \&modify_login,
1.30 raeburn 258: },
1.43 raeburn 259: 'defaults' =>
1.160.6.40 raeburn 260: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 261: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 262: header => [{col1 => 'Setting',
1.160.6.40 raeburn 263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 266: print => \&print_defaults,
267: modify => \&modify_defaults,
1.43 raeburn 268: },
1.30 raeburn 269: 'quotas' =>
1.160.6.20 raeburn 270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 271: help => 'Domain_Configuration_Quotas',
1.77 raeburn 272: header => [{col1 => 'User affiliation',
1.72 raeburn 273: col2 => 'Available tools',
1.160.6.28 raeburn 274: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 275: print => \&print_quotas,
276: modify => \&modify_quotas,
1.30 raeburn 277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
1.67 raeburn 280: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
1.160.6.37 raeburn 283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
1.30 raeburn 285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
1.67 raeburn 288: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
1.131 raeburn 291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
1.43 raeburn 293: {col1 => 'User population',
1.160.6.35 raeburn 294: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
1.30 raeburn 297: },
1.125 raeburn 298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
1.160.6.37 raeburn 303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
1.125 raeburn 305: },
1.30 raeburn 306: 'directorysrch' =>
1.160.6.72 raeburn 307: { text => 'Directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 309: header => [{col1 => 'Institutional Directory Setting',
310: col2 => 'Value',},
311: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 312: col2 => 'Value',}],
1.160.6.37 raeburn 313: print => \&print_directorysrch,
314: modify => \&modify_directorysrch,
1.30 raeburn 315: },
316: 'contacts' =>
317: { text => 'Contact Information',
1.67 raeburn 318: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 319: header => [{col1 => 'Setting',
320: col2 => 'Value',}],
1.160.6.37 raeburn 321: print => \&print_contacts,
322: modify => \&modify_contacts,
1.30 raeburn 323: },
324: 'usercreation' =>
325: { text => 'User creation',
1.67 raeburn 326: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 327: header => [{col1 => 'Format rule type',
328: col2 => 'Format rules in force'},
1.34 raeburn 329: {col1 => 'User account creation',
330: col2 => 'Usernames which may be created',},
1.30 raeburn 331: {col1 => 'Context',
1.43 raeburn 332: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 333: print => \&print_usercreation,
334: modify => \&modify_usercreation,
1.30 raeburn 335: },
1.160.6.34 raeburn 336: 'selfcreation' =>
337: { text => 'Users self-creating accounts',
338: help => 'Domain_Configuration_Self_Creation',
339: header => [{col1 => 'Self-creation with institutional username',
340: col2 => 'Enabled?'},
341: {col1 => 'Institutional user type (login/SSO self-creation)',
342: col2 => 'Information user can enter'},
343: {col1 => 'Self-creation with e-mail as username',
344: col2 => 'Settings'}],
1.160.6.37 raeburn 345: print => \&print_selfcreation,
346: modify => \&modify_selfcreation,
1.160.6.34 raeburn 347: },
1.69 raeburn 348: 'usermodification' =>
1.33 raeburn 349: { text => 'User modification',
1.67 raeburn 350: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 351: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 352: col2 => 'User information updatable in author context'},
1.33 raeburn 353: {col1 => 'Target user has role',
1.160.6.35 raeburn 354: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 355: print => \&print_usermodification,
356: modify => \&modify_usermodification,
1.33 raeburn 357: },
1.69 raeburn 358: 'scantron' =>
1.95 www 359: { text => 'Bubblesheet format file',
1.67 raeburn 360: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 361: header => [ {col1 => 'Item',
362: col2 => '',
363: }],
1.160.6.37 raeburn 364: print => \&print_scantron,
365: modify => \&modify_scantron,
1.46 raeburn 366: },
1.86 raeburn 367: 'requestcourses' =>
368: {text => 'Request creation of courses',
369: help => 'Domain_Configuration_Request_Courses',
370: header => [{col1 => 'User affiliation',
1.102 raeburn 371: col2 => 'Availability/Processing of requests',},
372: {col1 => 'Setting',
1.160.6.30 raeburn 373: col2 => 'Value'},
374: {col1 => 'Available textbooks',
1.160.6.39 raeburn 375: col2 => ''},
1.160.6.46 raeburn 376: {col1 => 'Available templates',
377: col2 => ''},
1.160.6.39 raeburn 378: {col1 => 'Validation (not official courses)',
379: col2 => 'Value'},],
1.160.6.37 raeburn 380: print => \&print_quotas,
381: modify => \&modify_quotas,
1.86 raeburn 382: },
1.160.6.5 raeburn 383: 'requestauthor' =>
1.160.6.34 raeburn 384: {text => 'Request Authoring Space',
1.160.6.5 raeburn 385: help => 'Domain_Configuration_Request_Author',
386: header => [{col1 => 'User affiliation',
387: col2 => 'Availability/Processing of requests',},
388: {col1 => 'Setting',
389: col2 => 'Value'}],
1.160.6.37 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.160.6.5 raeburn 392: },
1.69 raeburn 393: 'coursecategories' =>
1.120 raeburn 394: { text => 'Cataloging of courses/communities',
1.67 raeburn 395: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 396: header => [{col1 => 'Catalog type/availability',
397: col2 => '',},
398: {col1 => 'Category settings for standard catalog',
1.57 raeburn 399: col2 => '',},
400: {col1 => 'Categories',
401: col2 => '',
402: }],
1.160.6.37 raeburn 403: print => \&print_coursecategories,
404: modify => \&modify_coursecategories,
1.69 raeburn 405: },
406: 'serverstatuses' =>
1.77 raeburn 407: {text => 'Access to server status pages',
1.69 raeburn 408: help => 'Domain_Configuration_Server_Status',
409: header => [{col1 => 'Status Page',
410: col2 => 'Other named users',
411: col3 => 'Specific IPs',
412: }],
1.160.6.37 raeburn 413: print => \&print_serverstatuses,
414: modify => \&modify_serverstatuses,
1.69 raeburn 415: },
1.160.6.73 raeburn 416: 'helpsettings' =>
417: {text => 'Support settings',
418: help => 'Domain_Configuration_Help_Settings',
419: header => [{col1 => 'Help Page Settings (logged-in users)',
420: col2 => 'Value'},
421: {col1 => 'Helpdesk Roles',
422: col2 => 'Settings'},],
423: print => \&print_helpsettings,
424: modify => \&modify_helpsettings,
425: },
1.160.6.39 raeburn 426: 'coursedefaults' =>
1.160.6.16 raeburn 427: {text => 'Course/Community defaults',
428: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 429: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
430: col2 => 'Value',},
431: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 432: col2 => 'Value',},],
1.160.6.37 raeburn 433: print => \&print_coursedefaults,
434: modify => \&modify_coursedefaults,
435: },
1.160.6.39 raeburn 436: 'selfenrollment' =>
1.160.6.37 raeburn 437: {text => 'Self-enrollment in Course/Community',
438: help => 'Domain_Configuration_Selfenrollment',
439: header => [{col1 => 'Configuration Rights',
440: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
441: {col1 => 'Defaults',
442: col2 => 'Value'},
443: {col1 => 'Self-enrollment validation (optional)',
444: col2 => 'Value'},],
445: print => \&print_selfenrollment,
446: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 447: },
1.141 raeburn 448: 'usersessions' =>
1.145 raeburn 449: {text => 'User session hosting/offloading',
1.137 raeburn 450: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 451: header => [{col1 => 'Domain server',
452: col2 => 'Servers to offload sessions to when busy'},
453: {col1 => 'Hosting of users from other domains',
1.137 raeburn 454: col2 => 'Rules'},
455: {col1 => "Hosting domain's own users elsewhere",
456: col2 => 'Rules'}],
1.160.6.37 raeburn 457: print => \&print_usersessions,
458: modify => \&modify_usersessions,
1.137 raeburn 459: },
1.150 raeburn 460: 'loadbalancing' =>
1.160.6.7 raeburn 461: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 462: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 463: header => [{col1 => 'Balancers',
1.150 raeburn 464: col2 => 'Default destinations',
1.160.6.13 raeburn 465: col3 => 'User affiliation',
1.150 raeburn 466: col4 => 'Overrides'},
467: ],
1.160.6.37 raeburn 468: print => \&print_loadbalancing,
469: modify => \&modify_loadbalancing,
1.150 raeburn 470: },
1.3 raeburn 471: );
1.110 raeburn 472: if (keys(%servers) > 1) {
473: $prefs{'login'} = { text => 'Log-in page options',
474: help => 'Domain_Configuration_Login_Page',
475: header => [{col1 => 'Log-in Service',
476: col2 => 'Server Setting',},
477: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 478: col2 => ''},
479: {col1 => 'Log-in Help',
1.160.6.56 raeburn 480: col2 => 'Value'},
481: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 482: col2 => 'Value'}],
1.160.6.37 raeburn 483: print => \&print_login,
484: modify => \&modify_login,
1.110 raeburn 485: };
486: }
1.160.6.13 raeburn 487:
1.6 raeburn 488: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 489: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 490: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 491: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 492: text=>"Settings to display/modify"});
1.9 raeburn 493: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 494:
1.3 raeburn 495: if ($phase eq 'process') {
1.160.6.27 raeburn 496: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
497: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 498: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 499: $r->rflush();
1.160.6.27 raeburn 500: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 501: }
1.30 raeburn 502: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 503: my $js = &recaptcha_js().
1.160.6.40 raeburn 504: &toggle_display_js();
1.160.6.7 raeburn 505: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 506: my ($othertitle,$usertypes,$types) =
507: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 508: $js .= &lonbalance_targets_js($dom,$types,\%servers,
509: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 510: &new_spares_js().
511: &common_domprefs_js().
512: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 513: }
1.160.6.30 raeburn 514: if (grep(/^requestcourses$/,@actions)) {
515: my $javascript_validations;
516: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
517: $js .= <<END;
518: <script type="text/javascript">
519: $javascript_validations
520: </script>
521: $coursebrowserjs
522: END
523: }
1.150 raeburn 524: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 525: } else {
1.160.6.11 raeburn 526: # check if domconfig user exists for the domain.
527: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 528: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 529: &config_check($dom,$confname,$servadm);
530: unless ($configuserok eq 'ok') {
531: &Apache::lonconfigsettings::print_header($r,$phase,$context);
532: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
533: $confname).
534: '<br />'
535: );
536: if ($switchserver) {
537: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
538: '<br />'.
539: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
540: '<br />'.
541: &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).
542: '<br />'.
543: &mt('To do that now, use the following link: [_1]',$switchserver)
544: );
545: } else {
546: $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.').
547: '<br />'.
548: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
549: );
550: }
551: $r->print(&Apache::loncommon::end_page());
552: return OK;
553: }
1.21 raeburn 554: if (keys(%domconfig) == 0) {
555: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 556: my @ids=&Apache::lonnet::current_machine_ids();
557: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 558: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 559: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 560: my $custom_img_count = 0;
561: foreach my $img (@loginimages) {
562: if ($designhash{$dom.'.login.'.$img} ne '') {
563: $custom_img_count ++;
564: }
565: }
566: foreach my $role (@roles) {
567: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
568: $custom_img_count ++;
569: }
570: }
571: if ($custom_img_count > 0) {
1.94 raeburn 572: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 573: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 574: $r->print(
575: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
576: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
577: &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 />'.
578: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
579: if ($switch_server) {
1.30 raeburn 580: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 581: }
1.91 raeburn 582: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 583: return OK;
584: }
585: }
586: }
1.91 raeburn 587: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 588: }
589: return OK;
590: }
591:
592: sub process_changes {
1.160.6.24 raeburn 593: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 594: my %domconfig;
595: if (ref($values) eq 'HASH') {
596: %domconfig = %{$values};
597: }
1.3 raeburn 598: my $output;
599: if ($action eq 'login') {
1.160.6.24 raeburn 600: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 601: } elsif ($action eq 'rolecolors') {
1.9 raeburn 602: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 603: $lastactref,%domconfig);
1.3 raeburn 604: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 605: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 606: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 607: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 608: } elsif ($action eq 'autoupdate') {
609: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 610: } elsif ($action eq 'autocreate') {
611: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 612: } elsif ($action eq 'directorysrch') {
613: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 614: } elsif ($action eq 'usercreation') {
1.28 raeburn 615: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 616: } elsif ($action eq 'selfcreation') {
617: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 618: } elsif ($action eq 'usermodification') {
619: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 620: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 621: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 622: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 623: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 624: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 625: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 626: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 627: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 628: } elsif ($action eq 'serverstatuses') {
629: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 630: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 631: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 632: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 633: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 634: } elsif ($action eq 'helpsettings') {
635: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.160.6.16 raeburn 636: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 637: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 638: } elsif ($action eq 'selfenrollment') {
639: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 640: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 641: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 642: } elsif ($action eq 'loadbalancing') {
643: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 644: }
645: return $output;
646: }
647:
648: sub print_config_box {
1.9 raeburn 649: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 650: my $rowtotal = 0;
1.49 raeburn 651: my $output;
652: if ($action eq 'coursecategories') {
653: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 654: } elsif ($action eq 'defaults') {
655: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 656: } elsif ($action eq 'helpsettings') {
657: my (%privs,%levelscurrent);
658: my %full=();
659: my %levels=(
660: course => {},
661: domain => {},
662: system => {},
663: );
664: my $context = 'domain';
665: my $crstype = 'Course';
666: my $formname = 'display';
667: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
668: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
669: $output =
670: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
671: \@templateroles);
1.91 raeburn 672: }
1.160.6.40 raeburn 673: $output .=
1.30 raeburn 674: '<table class="LC_nested_outer">
1.3 raeburn 675: <tr>
1.66 raeburn 676: <th align="left" valign="middle"><span class="LC_nobreak">'.
677: &mt($item->{text}).' '.
678: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
679: '</tr>';
1.30 raeburn 680: $rowtotal ++;
1.110 raeburn 681: my $numheaders = 1;
682: if (ref($item->{'header'}) eq 'ARRAY') {
683: $numheaders = scalar(@{$item->{'header'}});
684: }
685: if ($numheaders > 1) {
1.64 raeburn 686: my $colspan = '';
1.145 raeburn 687: my $rightcolspan = '';
1.160.6.42 raeburn 688: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 689: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 690: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 691: $colspan = ' colspan="2"';
692: }
1.145 raeburn 693: if ($action eq 'usersessions') {
694: $rightcolspan = ' colspan="3"';
695: }
1.30 raeburn 696: $output .= '
1.3 raeburn 697: <tr>
698: <td>
699: <table class="LC_nested">
700: <tr class="LC_info_row">
1.59 bisitz 701: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 702: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 703: </tr>';
1.69 raeburn 704: $rowtotal ++;
1.160.6.37 raeburn 705: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 706: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 707: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
708: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 709: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 710: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 711: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 712: } elsif ($action eq 'login') {
1.160.6.56 raeburn 713: if ($numheaders == 4) {
1.160.6.5 raeburn 714: $colspan = ' colspan="2"';
715: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
716: } else {
717: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
718: }
1.160.6.37 raeburn 719: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 720: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 721: } elsif ($action eq 'rolecolors') {
1.30 raeburn 722: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 723: }
1.30 raeburn 724: $output .= '
1.6 raeburn 725: </table>
726: </td>
727: </tr>
728: <tr>
729: <td>
730: <table class="LC_nested">
731: <tr class="LC_info_row">
1.160.6.37 raeburn 732: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 733: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 734: </tr>';
735: $rowtotal ++;
1.160.6.37 raeburn 736: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
737: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 738: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
739: if ($action eq 'coursecategories') {
740: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
741: $colspan = ' colspan="2"';
742: } else {
743: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
744: }
745: $output .= '
1.63 raeburn 746: </table>
747: </td>
748: </tr>
749: <tr>
750: <td>
751: <table class="LC_nested">
752: <tr class="LC_info_row">
753: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 754: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 755: </tr>'."\n";
756: if ($action eq 'coursecategories') {
757: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
758: } else {
759: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
760: }
1.63 raeburn 761: $rowtotal ++;
1.160.6.57 raeburn 762: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 763: ($action eq 'defaults') || ($action eq 'directorysrch') ||
764: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 765: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 766: } elsif ($action eq 'login') {
1.160.6.56 raeburn 767: if ($numheaders == 4) {
1.160.6.5 raeburn 768: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
769: </table>
770: </td>
771: </tr>
772: <tr>
773: <td>
774: <table class="LC_nested">
775: <tr class="LC_info_row">
776: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 777: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 778: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
779: $rowtotal ++;
780: } else {
781: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
782: }
1.160.6.56 raeburn 783: $output .= '
784: </table>
785: </td>
786: </tr>
787: <tr>
788: <td>
789: <table class="LC_nested">
790: <tr class="LC_info_row">';
791: if ($numheaders == 4) {
792: $output .= '
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
794: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
795: </tr>';
796: } else {
797: $output .= '
798: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
799: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
800: </tr>';
801: }
802: $rowtotal ++;
803: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 804: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 805: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
806: $rowtotal ++;
807: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 808: </table>
809: </td>
810: </tr>
811: <tr>
812: <td>
813: <table class="LC_nested">
814: <tr class="LC_info_row">
815: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
816: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 817: &textbookcourses_javascript($settings).
818: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
819: </table>
820: </td>
821: </tr>
822: <tr>
823: <td>
824: <table class="LC_nested">
825: <tr class="LC_info_row">
826: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
827: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
828: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 829: </table>
830: </td>
831: </tr>
832: <tr>
833: <td>
834: <table class="LC_nested">
835: <tr class="LC_info_row">
1.160.6.46 raeburn 836: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
837: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 838: </tr>'.
839: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 840: } elsif ($action eq 'requestauthor') {
841: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 842: $rowtotal ++;
1.122 jms 843: } elsif ($action eq 'rolecolors') {
1.30 raeburn 844: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 845: </table>
846: </td>
847: </tr>
848: <tr>
849: <td>
850: <table class="LC_nested">
851: <tr class="LC_info_row">
1.69 raeburn 852: <td class="LC_left_item"'.$colspan.' valign="top">'.
853: &mt($item->{'header'}->[2]->{'col1'}).'</td>
854: <td class="LC_right_item" valign="top">'.
855: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 856: </tr>'.
1.30 raeburn 857: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 858: </table>
859: </td>
860: </tr>
861: <tr>
862: <td>
863: <table class="LC_nested">
864: <tr class="LC_info_row">
1.59 bisitz 865: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
866: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 867: </tr>'.
1.30 raeburn 868: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
869: $rowtotal += 2;
1.6 raeburn 870: }
1.3 raeburn 871: } else {
1.30 raeburn 872: $output .= '
1.3 raeburn 873: <tr>
874: <td>
875: <table class="LC_nested">
1.30 raeburn 876: <tr class="LC_info_row">';
1.160.6.72 raeburn 877: if ($action eq 'login') {
1.30 raeburn 878: $output .= '
1.59 bisitz 879: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 880: } elsif ($action eq 'serverstatuses') {
881: $output .= '
882: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
883: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
884:
1.6 raeburn 885: } else {
1.30 raeburn 886: $output .= '
1.69 raeburn 887: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
888: }
1.72 raeburn 889: if (defined($item->{'header'}->[0]->{'col3'})) {
890: $output .= '<td class="LC_left_item" valign="top">'.
891: &mt($item->{'header'}->[0]->{'col2'});
892: if ($action eq 'serverstatuses') {
893: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
894: }
1.69 raeburn 895: } else {
896: $output .= '<td class="LC_right_item" valign="top">'.
897: &mt($item->{'header'}->[0]->{'col2'});
898: }
899: $output .= '</td>';
900: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 901: if (defined($item->{'header'}->[0]->{'col4'})) {
902: $output .= '<td class="LC_left_item" valign="top">'.
903: &mt($item->{'header'}->[0]->{'col3'});
904: } else {
905: $output .= '<td class="LC_right_item" valign="top">'.
906: &mt($item->{'header'}->[0]->{'col3'});
907: }
1.69 raeburn 908: if ($action eq 'serverstatuses') {
909: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
910: }
911: $output .= '</td>';
1.6 raeburn 912: }
1.150 raeburn 913: if ($item->{'header'}->[0]->{'col4'}) {
914: $output .= '<td class="LC_right_item" valign="top">'.
915: &mt($item->{'header'}->[0]->{'col4'});
916: }
1.69 raeburn 917: $output .= '</tr>';
1.48 raeburn 918: $rowtotal ++;
1.160.6.5 raeburn 919: if ($action eq 'quotas') {
1.86 raeburn 920: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 921: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
922: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
923: ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 924: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 925: } elsif ($action eq 'scantron') {
926: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 927: }
1.3 raeburn 928: }
1.30 raeburn 929: $output .= '
1.3 raeburn 930: </table>
931: </td>
932: </tr>
1.30 raeburn 933: </table><br />';
934: return ($output,$rowtotal);
1.1 raeburn 935: }
936:
1.3 raeburn 937: sub print_login {
1.160.6.5 raeburn 938: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 939: my ($css_class,$datatable);
1.6 raeburn 940: my %choices = &login_choices();
1.110 raeburn 941:
1.160.6.5 raeburn 942: if ($caller eq 'service') {
1.149 raeburn 943: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 944: my $choice = $choices{'disallowlogin'};
945: $css_class = ' class="LC_odd_row"';
1.128 raeburn 946: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 947: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 948: '<th>'.$choices{'server'}.'</th>'.
949: '<th>'.$choices{'serverpath'}.'</th>'.
950: '<th>'.$choices{'custompath'}.'</th>'.
951: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 952: my %disallowed;
953: if (ref($settings) eq 'HASH') {
954: if (ref($settings->{'loginvia'}) eq 'HASH') {
955: %disallowed = %{$settings->{'loginvia'}};
956: }
957: }
958: foreach my $lonhost (sort(keys(%servers))) {
959: my $direct = 'selected="selected"';
1.128 raeburn 960: if (ref($disallowed{$lonhost}) eq 'HASH') {
961: if ($disallowed{$lonhost}{'server'} ne '') {
962: $direct = '';
963: }
1.110 raeburn 964: }
1.115 raeburn 965: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 966: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 967: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
968: '</option>';
1.160.6.13 raeburn 969: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 970: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 971: my $selected = '';
1.128 raeburn 972: if (ref($disallowed{$lonhost}) eq 'HASH') {
973: if ($hostid eq $disallowed{$lonhost}{'server'}) {
974: $selected = 'selected="selected"';
975: }
1.110 raeburn 976: }
977: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
978: $servers{$hostid}.'</option>';
979: }
1.128 raeburn 980: $datatable .= '</select></td>'.
981: '<td><select name="'.$lonhost.'_serverpath">';
982: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
983: my $pathname = $path;
984: if ($path eq 'custom') {
985: $pathname = &mt('Custom Path').' ->';
986: }
987: my $selected = '';
988: if (ref($disallowed{$lonhost}) eq 'HASH') {
989: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
990: $selected = 'selected="selected"';
991: }
992: } elsif ($path eq '') {
993: $selected = 'selected="selected"';
994: }
995: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
996: }
997: $datatable .= '</select></td>';
998: my ($custom,$exempt);
999: if (ref($disallowed{$lonhost}) eq 'HASH') {
1000: $custom = $disallowed{$lonhost}{'custompath'};
1001: $exempt = $disallowed{$lonhost}{'exempt'};
1002: }
1003: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1004: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1005: '</tr>';
1.110 raeburn 1006: }
1007: $datatable .= '</table></td></tr>';
1008: return $datatable;
1.160.6.5 raeburn 1009: } elsif ($caller eq 'page') {
1010: my %defaultchecked = (
1011: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1012: 'helpdesk' => 'on',
1.160.6.5 raeburn 1013: 'adminmail' => 'off',
1014: 'newuser' => 'off',
1015: );
1.160.6.14 raeburn 1016: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1017: my (%checkedon,%checkedoff);
1.42 raeburn 1018: foreach my $item (@toggles) {
1.160.6.5 raeburn 1019: if ($defaultchecked{$item} eq 'on') {
1020: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1021: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1022: } elsif ($defaultchecked{$item} eq 'off') {
1023: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1024: $checkedon{$item} = ' ';
1025: }
1.1 raeburn 1026: }
1.160.6.5 raeburn 1027: my @images = ('img','logo','domlogo','login');
1028: my @logintext = ('textcol','bgcol');
1029: my @bgs = ('pgbg','mainbg','sidebg');
1030: my @links = ('link','alink','vlink');
1031: my %designhash = &Apache::loncommon::get_domainconf($dom);
1032: my %defaultdesign = %Apache::loncommon::defaultdesign;
1033: my (%is_custom,%designs);
1034: my %defaults = (
1035: font => $defaultdesign{'login.font'},
1036: );
1.6 raeburn 1037: foreach my $item (@images) {
1.160.6.5 raeburn 1038: $defaults{$item} = $defaultdesign{'login.'.$item};
1039: $defaults{'showlogo'}{$item} = 1;
1040: }
1041: foreach my $item (@bgs) {
1042: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1043: }
1.41 raeburn 1044: foreach my $item (@logintext) {
1.160.6.5 raeburn 1045: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1046: }
1.160.6.5 raeburn 1047: foreach my $item (@links) {
1048: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1049: }
1.160.6.5 raeburn 1050: if (ref($settings) eq 'HASH') {
1051: foreach my $item (@toggles) {
1052: if ($settings->{$item} eq '1') {
1053: $checkedon{$item} = ' checked="checked" ';
1054: $checkedoff{$item} = ' ';
1055: } elsif ($settings->{$item} eq '0') {
1056: $checkedoff{$item} = ' checked="checked" ';
1057: $checkedon{$item} = ' ';
1058: }
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: foreach my $item (@images) {
1061: if (defined($settings->{$item})) {
1062: $designs{$item} = $settings->{$item};
1063: $is_custom{$item} = 1;
1064: }
1065: if (defined($settings->{'showlogo'}{$item})) {
1066: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1067: }
1068: }
1069: foreach my $item (@logintext) {
1070: if ($settings->{$item} ne '') {
1071: $designs{'logintext'}{$item} = $settings->{$item};
1072: $is_custom{$item} = 1;
1073: }
1074: }
1075: if ($settings->{'font'} ne '') {
1076: $designs{'font'} = $settings->{'font'};
1077: $is_custom{'font'} = 1;
1078: }
1079: foreach my $item (@bgs) {
1080: if ($settings->{$item} ne '') {
1081: $designs{'bgs'}{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: }
1085: foreach my $item (@links) {
1086: if ($settings->{$item} ne '') {
1087: $designs{'links'}{$item} = $settings->{$item};
1088: $is_custom{$item} = 1;
1089: }
1090: }
1091: } else {
1092: if ($designhash{$dom.'.login.font'} ne '') {
1093: $designs{'font'} = $designhash{$dom.'.login.font'};
1094: $is_custom{'font'} = 1;
1095: }
1096: foreach my $item (@images) {
1097: if ($designhash{$dom.'.login.'.$item} ne '') {
1098: $designs{$item} = $designhash{$dom.'.login.'.$item};
1099: $is_custom{$item} = 1;
1100: }
1101: }
1102: foreach my $item (@bgs) {
1103: if ($designhash{$dom.'.login.'.$item} ne '') {
1104: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1105: $is_custom{$item} = 1;
1106: }
1107: }
1108: foreach my $item (@links) {
1109: if ($designhash{$dom.'.login.'.$item} ne '') {
1110: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1111: $is_custom{$item} = 1;
1112: }
1.6 raeburn 1113: }
1114: }
1.160.6.5 raeburn 1115: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1116: logo => 'Institution Logo',
1117: domlogo => 'Domain Logo',
1118: login => 'Login box');
1119: my $itemcount = 1;
1120: foreach my $item (@toggles) {
1121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1122: $datatable .=
1123: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1124: '</td><td>'.
1125: '<span class="LC_nobreak"><label><input type="radio" name="'.
1126: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1127: '</label> <label><input type="radio" name="'.$item.'"'.
1128: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1129: '</tr>';
1130: $itemcount ++;
1.6 raeburn 1131: }
1.160.6.5 raeburn 1132: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1133: $datatable .= '</tr></table></td></tr>';
1134: } elsif ($caller eq 'help') {
1135: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1136: my $switchserver = &check_switchserver($dom,$confname);
1137: my $itemcount = 1;
1138: $defaulturl = '/adm/loginproblems.html';
1139: $defaulttype = 'default';
1140: %lt = &Apache::lonlocal::texthash (
1141: del => 'Delete?',
1142: rep => 'Replace:',
1143: upl => 'Upload:',
1144: default => 'Default',
1145: custom => 'Custom',
1146: );
1147: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1148: my @currlangs;
1149: if (ref($settings) eq 'HASH') {
1150: if (ref($settings->{'helpurl'}) eq 'HASH') {
1151: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1152: next if ($settings->{'helpurl'}{$key} eq '');
1153: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1154: $type{$key} = 'custom';
1155: unless ($key eq 'nolang') {
1156: push(@currlangs,$key);
1157: }
1158: }
1159: } elsif ($settings->{'helpurl'} ne '') {
1160: $type{'nolang'} = 'custom';
1161: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1162: }
1163: }
1.160.6.5 raeburn 1164: foreach my $lang ('nolang',sort(@currlangs)) {
1165: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1166: $datatable .= '<tr'.$css_class.'>';
1167: if ($url{$lang} eq '') {
1168: $url{$lang} = $defaulturl;
1169: }
1170: if ($type{$lang} eq '') {
1171: $type{$lang} = $defaulttype;
1172: }
1173: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1174: if ($lang eq 'nolang') {
1175: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1176: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1177: } else {
1178: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1179: $langchoices{$lang},
1180: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1181: }
1182: $datatable .= '</span></td>'."\n".
1183: '<td class="LC_left_item">';
1184: if ($type{$lang} eq 'custom') {
1185: $datatable .= '<span class="LC_nobreak"><label>'.
1186: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1187: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1188: } else {
1189: $datatable .= $lt{'upl'};
1190: }
1191: $datatable .='<br />';
1192: if ($switchserver) {
1193: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1194: } else {
1195: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1196: }
1.160.6.5 raeburn 1197: $datatable .= '</td></tr>';
1198: $itemcount ++;
1.6 raeburn 1199: }
1.160.6.5 raeburn 1200: my @addlangs;
1201: foreach my $lang (sort(keys(%langchoices))) {
1202: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1203: push(@addlangs,$lang);
1204: }
1205: if (@addlangs > 0) {
1206: my %toadd;
1207: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1208: $toadd{''} = &mt('Select');
1209: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1210: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1211: &mt('Add log-in help page for a specific language:').' '.
1212: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1213: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1214: if ($switchserver) {
1215: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1216: } else {
1217: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1218: }
1.160.6.5 raeburn 1219: $datatable .= '</td></tr>';
1220: $itemcount ++;
1.6 raeburn 1221: }
1.160.6.5 raeburn 1222: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1223: } elsif ($caller eq 'headtag') {
1224: my %domservers = &Apache::lonnet::get_servers($dom);
1225: my $choice = $choices{'headtag'};
1226: $css_class = ' class="LC_odd_row"';
1227: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1228: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1229: '<th>'.$choices{'current'}.'</th>'.
1230: '<th>'.$choices{'action'}.'</th>'.
1231: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1232: my (%currurls,%currexempt);
1233: if (ref($settings) eq 'HASH') {
1234: if (ref($settings->{'headtag'}) eq 'HASH') {
1235: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1236: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1237: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1238: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1239: }
1240: }
1241: }
1242: }
1243: my %lt = &Apache::lonlocal::texthash(
1244: del => 'Delete?',
1245: rep => 'Replace:',
1246: upl => 'Upload:',
1247: curr => 'View contents',
1248: none => 'None',
1249: );
1250: my $switchserver = &check_switchserver($dom,$confname);
1251: foreach my $lonhost (sort(keys(%domservers))) {
1252: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1253: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1254: if ($currurls{$lonhost}) {
1255: $datatable .= '<td class="LC_right_item"><a href="'.
1256: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1257: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1258: '">'.$lt{'curr'}.'</a></td>'.
1259: '<td><span class="LC_nobreak"><label>'.
1260: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1261: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1262: } else {
1263: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1264: }
1265: $datatable .='<br />';
1266: if ($switchserver) {
1267: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1268: } else {
1269: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1270: }
1271: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1272: }
1273: $datatable .= '</table></td></tr>';
1.1 raeburn 1274: }
1.6 raeburn 1275: return $datatable;
1276: }
1277:
1278: sub login_choices {
1279: my %choices =
1280: &Apache::lonlocal::texthash (
1.116 bisitz 1281: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1282: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1283: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1284: disallowlogin => "Login page requests redirected",
1285: hostid => "Server",
1.128 raeburn 1286: server => "Redirect to:",
1287: serverpath => "Path",
1288: custompath => "Custom",
1289: exempt => "Exempt IP(s)",
1.110 raeburn 1290: directlogin => "No redirect",
1291: newuser => "Link to create a user account",
1292: img => "Header",
1293: logo => "Main Logo",
1294: domlogo => "Domain Logo",
1295: login => "Log-in Header",
1296: textcol => "Text color",
1297: bgcol => "Box color",
1298: bgs => "Background colors",
1299: links => "Link colors",
1300: font => "Font color",
1301: pgbg => "Header",
1302: mainbg => "Page",
1303: sidebg => "Login box",
1304: link => "Link",
1305: alink => "Active link",
1306: vlink => "Visited link",
1.160.6.56 raeburn 1307: headtag => "Custom markup",
1308: action => "Action",
1309: current => "Current",
1.6 raeburn 1310: );
1311: return %choices;
1312: }
1313:
1314: sub print_rolecolors {
1.30 raeburn 1315: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1316: my %choices = &color_font_choices();
1317: my @bgs = ('pgbg','tabbg','sidebg');
1318: my @links = ('link','alink','vlink');
1319: my @images = ('img');
1320: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1321: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1322: my %defaultdesign = %Apache::loncommon::defaultdesign;
1323: my (%is_custom,%designs);
1.160.6.22 raeburn 1324: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1325: if (ref($settings) eq 'HASH') {
1326: if (ref($settings->{$role}) eq 'HASH') {
1327: if ($settings->{$role}->{'img'} ne '') {
1328: $designs{'img'} = $settings->{$role}->{'img'};
1329: $is_custom{'img'} = 1;
1330: }
1331: if ($settings->{$role}->{'font'} ne '') {
1332: $designs{'font'} = $settings->{$role}->{'font'};
1333: $is_custom{'font'} = 1;
1334: }
1.97 tempelho 1335: if ($settings->{$role}->{'fontmenu'} ne '') {
1336: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1337: $is_custom{'fontmenu'} = 1;
1338: }
1.6 raeburn 1339: foreach my $item (@bgs) {
1340: if ($settings->{$role}->{$item} ne '') {
1341: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1342: $is_custom{$item} = 1;
1343: }
1344: }
1345: foreach my $item (@links) {
1346: if ($settings->{$role}->{$item} ne '') {
1347: $designs{'links'}{$item} = $settings->{$role}->{$item};
1348: $is_custom{$item} = 1;
1349: }
1350: }
1351: }
1352: } else {
1353: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1354: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1355: $is_custom{'img'} = 1;
1356: }
1.97 tempelho 1357: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1358: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1359: $is_custom{'fontmenu'} = 1;
1360: }
1.6 raeburn 1361: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1362: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1363: $is_custom{'font'} = 1;
1364: }
1365: foreach my $item (@bgs) {
1366: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1367: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1368: $is_custom{$item} = 1;
1369:
1370: }
1371: }
1372: foreach my $item (@links) {
1373: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1374: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1375: $is_custom{$item} = 1;
1376: }
1377: }
1378: }
1379: my $itemcount = 1;
1.30 raeburn 1380: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1381: $datatable .= '</tr></table></td></tr>';
1382: return $datatable;
1383: }
1384:
1.160.6.22 raeburn 1385: sub role_defaults {
1386: my ($role,$bgs,$links,$images,$logintext) = @_;
1387: my %defaults;
1388: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1389: return %defaults;
1390: }
1391: my %defaultdesign = %Apache::loncommon::defaultdesign;
1392: if ($role eq 'login') {
1393: %defaults = (
1394: font => $defaultdesign{$role.'.font'},
1395: );
1396: if (ref($logintext) eq 'ARRAY') {
1397: foreach my $item (@{$logintext}) {
1398: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1399: }
1400: }
1401: foreach my $item (@{$images}) {
1402: $defaults{'showlogo'}{$item} = 1;
1403: }
1404: } else {
1405: %defaults = (
1406: img => $defaultdesign{$role.'.img'},
1407: font => $defaultdesign{$role.'.font'},
1408: fontmenu => $defaultdesign{$role.'.fontmenu'},
1409: );
1410: }
1411: foreach my $item (@{$bgs}) {
1412: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1413: }
1414: foreach my $item (@{$links}) {
1415: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1416: }
1417: foreach my $item (@{$images}) {
1418: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1419: }
1420: return %defaults;
1421: }
1422:
1.6 raeburn 1423: sub display_color_options {
1.9 raeburn 1424: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1425: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1426: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1427: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1428: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1429: '<td>'.$choices->{'font'}.'</td>';
1430: if (!$is_custom->{'font'}) {
1.30 raeburn 1431: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1432: } else {
1433: $datatable .= '<td> </td>';
1434: }
1.160.6.9 raeburn 1435: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1436:
1.8 raeburn 1437: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1438: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1439: ' value="'.$current_color.'" /> '.
1440: ' </td></tr>';
1.107 raeburn 1441: unless ($role eq 'login') {
1442: $datatable .= '<tr'.$css_class.'>'.
1443: '<td>'.$choices->{'fontmenu'}.'</td>';
1444: if (!$is_custom->{'fontmenu'}) {
1445: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1446: } else {
1447: $datatable .= '<td> </td>';
1448: }
1.160.6.22 raeburn 1449: $current_color = $designs->{'fontmenu'} ?
1450: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1451: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1452: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1453: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1454: ' value="'.$current_color.'" /> '.
1455: ' </td></tr>';
1.97 tempelho 1456: }
1.9 raeburn 1457: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1458: foreach my $img (@{$images}) {
1.18 albertel 1459: $itemcount ++;
1.6 raeburn 1460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1461: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1462: '<td>'.$choices->{$img};
1.41 raeburn 1463: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1464: if ($role eq 'login') {
1465: if ($img eq 'login') {
1466: $login_hdr_pick =
1.135 bisitz 1467: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1468: $logincolors =
1469: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1470: $designs,$defaults);
1.70 raeburn 1471: } elsif ($img ne 'domlogo') {
1472: $datatable.= &logo_display_options($img,$defaults,$designs);
1473: }
1474: }
1475: $datatable .= '</td>';
1.6 raeburn 1476: if ($designs->{$img} ne '') {
1477: $imgfile = $designs->{$img};
1.18 albertel 1478: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1479: } else {
1480: $imgfile = $defaults->{$img};
1481: }
1482: if ($imgfile) {
1.9 raeburn 1483: my ($showfile,$fullsize);
1484: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1485: my $urldir = $1;
1486: my $filename = $2;
1487: my @info = &Apache::lonnet::stat_file($designs->{$img});
1488: if (@info) {
1489: my $thumbfile = 'tn-'.$filename;
1490: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1491: if (@thumb) {
1492: $showfile = $urldir.'/'.$thumbfile;
1493: } else {
1494: $showfile = $imgfile;
1495: }
1496: } else {
1497: $showfile = '';
1498: }
1499: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1500: $showfile = $imgfile;
1.6 raeburn 1501: my $imgdir = $1;
1502: my $filename = $2;
1.159 raeburn 1503: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1504: $showfile = "/$imgdir/tn-".$filename;
1505: } else {
1.159 raeburn 1506: my $input = $londocroot.$imgfile;
1507: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1508: if (!-e $output) {
1.9 raeburn 1509: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1510: my ($fullwidth,$fullheight) = &check_dimensions($input);
1511: if ($fullwidth ne '' && $fullheight ne '') {
1512: if ($fullwidth > $width && $fullheight > $height) {
1513: my $size = $width.'x'.$height;
1514: system("convert -sample $size $input $output");
1.159 raeburn 1515: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1516: }
1517: }
1.6 raeburn 1518: }
1519: }
1.16 raeburn 1520: }
1.6 raeburn 1521: if ($showfile) {
1.40 raeburn 1522: if ($showfile =~ m{^/(adm|res)/}) {
1523: if ($showfile =~ m{^/res/}) {
1524: my $local_showfile =
1525: &Apache::lonnet::filelocation('',$showfile);
1526: &Apache::lonnet::repcopy($local_showfile);
1527: }
1528: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1529: }
1530: if ($imgfile) {
1531: if ($imgfile =~ m{^/(adm|res)/}) {
1532: if ($imgfile =~ m{^/res/}) {
1533: my $local_imgfile =
1534: &Apache::lonnet::filelocation('',$imgfile);
1535: &Apache::lonnet::repcopy($local_imgfile);
1536: }
1537: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1538: } else {
1539: $fullsize = $imgfile;
1540: }
1541: }
1.41 raeburn 1542: $datatable .= '<td>';
1543: if ($img eq 'login') {
1.135 bisitz 1544: $datatable .= $login_hdr_pick;
1545: }
1.41 raeburn 1546: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1547: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1548: } else {
1.160.6.22 raeburn 1549: $datatable .= '<td> </td><td class="LC_left_item">'.
1550: &mt('Upload:').'<br />';
1.6 raeburn 1551: }
1552: } else {
1.160.6.22 raeburn 1553: $datatable .= '<td> </td><td class="LC_left_item">'.
1554: &mt('Upload:').'<br />';
1.6 raeburn 1555: }
1.9 raeburn 1556: if ($switchserver) {
1557: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1558: } else {
1.135 bisitz 1559: if ($img ne 'login') { # suppress file selection for Log-in header
1560: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1561: }
1.9 raeburn 1562: }
1563: $datatable .= '</td></tr>';
1.6 raeburn 1564: }
1565: $itemcount ++;
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: $datatable .= '<tr'.$css_class.'>'.
1568: '<td>'.$choices->{'bgs'}.'</td>';
1569: my $bgs_def;
1570: foreach my $item (@{$bgs}) {
1571: if (!$is_custom->{$item}) {
1.70 raeburn 1572: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1573: }
1574: }
1575: if ($bgs_def) {
1.8 raeburn 1576: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1580: $datatable .= '<td class="LC_right_item">'.
1581: '<table border="0"><tr>';
1.160.6.13 raeburn 1582:
1.6 raeburn 1583: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1584: $datatable .= '<td align="center">'.$choices->{$item};
1585: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1586: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1587: $datatable .= ' ';
1.6 raeburn 1588: }
1.160.6.9 raeburn 1589: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1590: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1591: }
1592: $datatable .= '</tr></table></td></tr>';
1593: $itemcount ++;
1594: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1595: $datatable .= '<tr'.$css_class.'>'.
1596: '<td>'.$choices->{'links'}.'</td>';
1597: my $links_def;
1598: foreach my $item (@{$links}) {
1599: if (!$is_custom->{$item}) {
1.30 raeburn 1600: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1601: }
1602: }
1603: if ($links_def) {
1.8 raeburn 1604: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1605: } else {
1606: $datatable .= '<td> </td>';
1607: }
1608: $datatable .= '<td class="LC_right_item">'.
1609: '<table border="0"><tr>';
1610: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1611: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1612: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1613: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1614: $datatable.=' ';
1.6 raeburn 1615: }
1.160.6.9 raeburn 1616: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1617: '" /></td>';
1618: }
1.30 raeburn 1619: $$rowtotal += $itemcount;
1.3 raeburn 1620: return $datatable;
1621: }
1622:
1.70 raeburn 1623: sub logo_display_options {
1624: my ($img,$defaults,$designs) = @_;
1625: my $checkedon;
1626: if (ref($defaults) eq 'HASH') {
1627: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1628: if ($defaults->{'showlogo'}{$img}) {
1629: $checkedon = 'checked="checked" ';
1630: }
1631: }
1632: }
1633: if (ref($designs) eq 'HASH') {
1634: if (ref($designs->{'showlogo'}) eq 'HASH') {
1635: if (defined($designs->{'showlogo'}{$img})) {
1636: if ($designs->{'showlogo'}{$img} == 0) {
1637: $checkedon = '';
1638: } elsif ($designs->{'showlogo'}{$img} == 1) {
1639: $checkedon = 'checked="checked" ';
1640: }
1641: }
1642: }
1643: }
1644: return '<br /><label> <input type="checkbox" name="'.
1645: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1646: &mt('show').'</label>'."\n";
1647: }
1648:
1.41 raeburn 1649: sub login_header_options {
1.135 bisitz 1650: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1651: my $output = '';
1.41 raeburn 1652: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1653: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1654: if (!$is_custom->{'textcol'}) {
1655: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1656: ' ';
1657: }
1658: if (!$is_custom->{'bgcol'}) {
1659: $output .= $choices->{'bgcol'}.': '.
1660: '<span id="css_'.$role.'_font" style="background-color: '.
1661: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1662: }
1663: $output .= '<br />';
1664: }
1665: $output .='<br />';
1666: return $output;
1667: }
1668:
1669: sub login_text_colors {
1.160.6.22 raeburn 1670: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1671: my $color_menu = '<table border="0"><tr>';
1672: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1673: $color_menu .= '<td align="center">'.$choices->{$item};
1674: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1675: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1676: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1677: }
1678: $color_menu .= '</tr></table><br />';
1679: return $color_menu;
1680: }
1681:
1682: sub image_changes {
1683: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1684: my $output;
1.135 bisitz 1685: if ($img eq 'login') {
1686: # suppress image for Log-in header
1687: } elsif (!$is_custom) {
1.70 raeburn 1688: if ($img ne 'domlogo') {
1.41 raeburn 1689: $output .= &mt('Default image:').'<br />';
1690: } else {
1691: $output .= &mt('Default in use:').'<br />';
1692: }
1693: }
1.135 bisitz 1694: if ($img eq 'login') { # suppress image for Log-in header
1695: $output .= '<td>'.$logincolors;
1.41 raeburn 1696: } else {
1.135 bisitz 1697: if ($img_import) {
1698: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1699: }
1700: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1701: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1702: if ($is_custom) {
1703: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1704: '<input type="checkbox" name="'.
1705: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1706: '</label> '.&mt('Replace:').'</span><br />';
1707: } else {
1.160.6.22 raeburn 1708: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1709: }
1.41 raeburn 1710: }
1711: return $output;
1712: }
1713:
1.3 raeburn 1714: sub print_quotas {
1.86 raeburn 1715: my ($dom,$settings,$rowtotal,$action) = @_;
1716: my $context;
1717: if ($action eq 'quotas') {
1718: $context = 'tools';
1719: } else {
1720: $context = $action;
1721: }
1.160.6.20 raeburn 1722: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1724: my $typecount = 0;
1.101 raeburn 1725: my ($css_class,%titles);
1.86 raeburn 1726: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1727: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1728: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1729: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1730: %titles = &courserequest_titles();
1.160.6.5 raeburn 1731: } elsif ($context eq 'requestauthor') {
1732: @usertools = ('author');
1733: @options = ('norequest','approval','automatic');
1734: %titles = &authorrequest_titles();
1.86 raeburn 1735: } else {
1.160.6.4 raeburn 1736: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1737: %titles = &tool_titles();
1.86 raeburn 1738: }
1.26 raeburn 1739: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1740: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1741: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1742: unless (($context eq 'requestcourses') ||
1743: ($context eq 'requestauthor')) {
1.86 raeburn 1744: if (ref($settings) eq 'HASH') {
1745: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1746: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1747: } else {
1748: $currdefquota = $settings->{$type};
1749: }
1.160.6.20 raeburn 1750: if (ref($settings->{authorquota}) eq 'HASH') {
1751: $currauthorquota = $settings->{authorquota}->{$type};
1752: }
1.78 raeburn 1753: }
1.72 raeburn 1754: }
1.3 raeburn 1755: if (defined($usertypes->{$type})) {
1756: $typecount ++;
1757: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1758: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1759: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1760: '<td class="LC_left_item">';
1.101 raeburn 1761: if ($context eq 'requestcourses') {
1762: $datatable .= '<table><tr>';
1763: }
1764: my %cell;
1.72 raeburn 1765: foreach my $item (@usertools) {
1.101 raeburn 1766: if ($context eq 'requestcourses') {
1767: my ($curroption,$currlimit);
1768: if (ref($settings) eq 'HASH') {
1769: if (ref($settings->{$item}) eq 'HASH') {
1770: $curroption = $settings->{$item}->{$type};
1771: if ($curroption =~ /^autolimit=(\d*)$/) {
1772: $currlimit = $1;
1773: }
1774: }
1775: }
1776: if (!$curroption) {
1777: $curroption = 'norequest';
1778: }
1779: $datatable .= '<th>'.$titles{$item}.'</th>';
1780: foreach my $option (@options) {
1781: my $val = $option;
1782: if ($option eq 'norequest') {
1783: $val = 0;
1784: }
1785: if ($option eq 'validate') {
1786: my $canvalidate = 0;
1787: if (ref($validations{$item}) eq 'HASH') {
1788: if ($validations{$item}{$type}) {
1789: $canvalidate = 1;
1790: }
1791: }
1792: next if (!$canvalidate);
1793: }
1794: my $checked = '';
1795: if ($option eq $curroption) {
1796: $checked = ' checked="checked"';
1797: } elsif ($option eq 'autolimit') {
1798: if ($curroption =~ /^autolimit/) {
1799: $checked = ' checked="checked"';
1800: }
1801: }
1802: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1803: '<input type="radio" name="crsreq_'.$item.
1804: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1805: $titles{$option}.'</label>';
1.101 raeburn 1806: if ($option eq 'autolimit') {
1.127 raeburn 1807: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1808: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1809: 'value="'.$currlimit.'" />';
1.101 raeburn 1810: }
1.127 raeburn 1811: $cell{$item} .= '</span> ';
1.103 raeburn 1812: if ($option eq 'autolimit') {
1.127 raeburn 1813: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1814: }
1.101 raeburn 1815: }
1.160.6.5 raeburn 1816: } elsif ($context eq 'requestauthor') {
1817: my $curroption;
1818: if (ref($settings) eq 'HASH') {
1819: $curroption = $settings->{$type};
1820: }
1821: if (!$curroption) {
1822: $curroption = 'norequest';
1823: }
1824: foreach my $option (@options) {
1825: my $val = $option;
1826: if ($option eq 'norequest') {
1827: $val = 0;
1828: }
1829: my $checked = '';
1830: if ($option eq $curroption) {
1831: $checked = ' checked="checked"';
1832: }
1833: $datatable .= '<span class="LC_nobreak"><label>'.
1834: '<input type="radio" name="authorreq_'.$type.
1835: '" value="'.$val.'"'.$checked.' />'.
1836: $titles{$option}.'</label></span> ';
1837: }
1.101 raeburn 1838: } else {
1839: my $checked = 'checked="checked" ';
1840: if (ref($settings) eq 'HASH') {
1841: if (ref($settings->{$item}) eq 'HASH') {
1842: if ($settings->{$item}->{$type} == 0) {
1843: $checked = '';
1844: } elsif ($settings->{$item}->{$type} == 1) {
1845: $checked = 'checked="checked" ';
1846: }
1.78 raeburn 1847: }
1.72 raeburn 1848: }
1.101 raeburn 1849: $datatable .= '<span class="LC_nobreak"><label>'.
1850: '<input type="checkbox" name="'.$context.'_'.$item.
1851: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1852: '</label></span> ';
1.72 raeburn 1853: }
1.101 raeburn 1854: }
1855: if ($context eq 'requestcourses') {
1856: $datatable .= '</tr><tr>';
1857: foreach my $item (@usertools) {
1.106 raeburn 1858: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1859: }
1860: $datatable .= '</tr></table>';
1.72 raeburn 1861: }
1.86 raeburn 1862: $datatable .= '</td>';
1.160.6.5 raeburn 1863: unless (($context eq 'requestcourses') ||
1864: ($context eq 'requestauthor')) {
1.86 raeburn 1865: $datatable .=
1.160.6.20 raeburn 1866: '<td class="LC_right_item">'.
1867: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1868: '<input type="text" name="quota_'.$type.
1.72 raeburn 1869: '" value="'.$currdefquota.
1.160.6.20 raeburn 1870: '" size="5" /></span>'.(' ' x 2).
1871: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1872: '<input type="text" name="authorquota_'.$type.
1873: '" value="'.$currauthorquota.
1874: '" size="5" /></span></td>';
1.86 raeburn 1875: }
1876: $datatable .= '</tr>';
1.3 raeburn 1877: }
1878: }
1879: }
1.160.6.5 raeburn 1880: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1881: $defaultquota = '20';
1.160.6.20 raeburn 1882: $authorquota = '500';
1.86 raeburn 1883: if (ref($settings) eq 'HASH') {
1884: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1885: $defaultquota = $settings->{'defaultquota'}->{'default'};
1886: } elsif (defined($settings->{'default'})) {
1887: $defaultquota = $settings->{'default'};
1888: }
1.160.6.20 raeburn 1889: if (ref($settings->{'authorquota'}) eq 'HASH') {
1890: $authorquota = $settings->{'authorquota'}->{'default'};
1891: }
1.3 raeburn 1892: }
1893: }
1894: $typecount ++;
1895: $css_class = $typecount%2?' class="LC_odd_row"':'';
1896: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1897: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1898: '<td class="LC_left_item">';
1.101 raeburn 1899: if ($context eq 'requestcourses') {
1900: $datatable .= '<table><tr>';
1901: }
1902: my %defcell;
1.72 raeburn 1903: foreach my $item (@usertools) {
1.101 raeburn 1904: if ($context eq 'requestcourses') {
1905: my ($curroption,$currlimit);
1906: if (ref($settings) eq 'HASH') {
1907: if (ref($settings->{$item}) eq 'HASH') {
1908: $curroption = $settings->{$item}->{'default'};
1909: if ($curroption =~ /^autolimit=(\d*)$/) {
1910: $currlimit = $1;
1911: }
1912: }
1913: }
1914: if (!$curroption) {
1915: $curroption = 'norequest';
1916: }
1917: $datatable .= '<th>'.$titles{$item}.'</th>';
1918: foreach my $option (@options) {
1919: my $val = $option;
1920: if ($option eq 'norequest') {
1921: $val = 0;
1922: }
1923: if ($option eq 'validate') {
1924: my $canvalidate = 0;
1925: if (ref($validations{$item}) eq 'HASH') {
1926: if ($validations{$item}{'default'}) {
1927: $canvalidate = 1;
1928: }
1929: }
1930: next if (!$canvalidate);
1931: }
1932: my $checked = '';
1933: if ($option eq $curroption) {
1934: $checked = ' checked="checked"';
1935: } elsif ($option eq 'autolimit') {
1936: if ($curroption =~ /^autolimit/) {
1937: $checked = ' checked="checked"';
1938: }
1939: }
1940: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1941: '<input type="radio" name="crsreq_'.$item.
1942: '_default" value="'.$val.'"'.$checked.' />'.
1943: $titles{$option}.'</label>';
1944: if ($option eq 'autolimit') {
1.127 raeburn 1945: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1946: $item.'_limit_default" size="1" '.
1947: 'value="'.$currlimit.'" />';
1948: }
1.127 raeburn 1949: $defcell{$item} .= '</span> ';
1.104 raeburn 1950: if ($option eq 'autolimit') {
1.127 raeburn 1951: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1952: }
1.101 raeburn 1953: }
1.160.6.5 raeburn 1954: } elsif ($context eq 'requestauthor') {
1955: my $curroption;
1956: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1957: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1958: }
1959: if (!$curroption) {
1960: $curroption = 'norequest';
1961: }
1962: foreach my $option (@options) {
1963: my $val = $option;
1964: if ($option eq 'norequest') {
1965: $val = 0;
1966: }
1967: my $checked = '';
1968: if ($option eq $curroption) {
1969: $checked = ' checked="checked"';
1970: }
1971: $datatable .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="authorreq_default"'.
1973: ' value="'.$val.'"'.$checked.' />'.
1974: $titles{$option}.'</label></span> ';
1975: }
1.101 raeburn 1976: } else {
1977: my $checked = 'checked="checked" ';
1978: if (ref($settings) eq 'HASH') {
1979: if (ref($settings->{$item}) eq 'HASH') {
1980: if ($settings->{$item}->{'default'} == 0) {
1981: $checked = '';
1982: } elsif ($settings->{$item}->{'default'} == 1) {
1983: $checked = 'checked="checked" ';
1984: }
1.78 raeburn 1985: }
1.72 raeburn 1986: }
1.101 raeburn 1987: $datatable .= '<span class="LC_nobreak"><label>'.
1988: '<input type="checkbox" name="'.$context.'_'.$item.
1989: '" value="default" '.$checked.'/>'.$titles{$item}.
1990: '</label></span> ';
1991: }
1992: }
1993: if ($context eq 'requestcourses') {
1994: $datatable .= '</tr><tr>';
1995: foreach my $item (@usertools) {
1.106 raeburn 1996: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1997: }
1.101 raeburn 1998: $datatable .= '</tr></table>';
1.72 raeburn 1999: }
1.86 raeburn 2000: $datatable .= '</td>';
1.160.6.5 raeburn 2001: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2002: $datatable .= '<td class="LC_right_item">'.
2003: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2004: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2005: $defaultquota.'" size="5" /></span>'.(' ' x2).
2006: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2007: '<input type="text" name="authorquota" value="'.
2008: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2009: }
2010: $datatable .= '</tr>';
1.72 raeburn 2011: $typecount ++;
2012: $css_class = $typecount%2?' class="LC_odd_row"':'';
2013: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2014: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2015: if ($context eq 'requestcourses') {
1.109 raeburn 2016: $datatable .= &mt('(overrides affiliation, if set)').
2017: '</td>'.
2018: '<td class="LC_left_item">'.
2019: '<table><tr>';
1.101 raeburn 2020: } else {
1.109 raeburn 2021: $datatable .= &mt('(overrides affiliation, if checked)').
2022: '</td>'.
2023: '<td class="LC_left_item" colspan="2">'.
2024: '<br />';
1.101 raeburn 2025: }
2026: my %advcell;
1.72 raeburn 2027: foreach my $item (@usertools) {
1.101 raeburn 2028: if ($context eq 'requestcourses') {
2029: my ($curroption,$currlimit);
2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$item}) eq 'HASH') {
2032: $curroption = $settings->{$item}->{'_LC_adv'};
2033: if ($curroption =~ /^autolimit=(\d*)$/) {
2034: $currlimit = $1;
2035: }
2036: }
2037: }
2038: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2039: my $checked = '';
2040: if ($curroption eq '') {
2041: $checked = ' checked="checked"';
2042: }
2043: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2044: '<input type="radio" name="crsreq_'.$item.
2045: '__LC_adv" value=""'.$checked.' />'.
2046: &mt('No override set').'</label></span> ';
1.101 raeburn 2047: foreach my $option (@options) {
2048: my $val = $option;
2049: if ($option eq 'norequest') {
2050: $val = 0;
2051: }
2052: if ($option eq 'validate') {
2053: my $canvalidate = 0;
2054: if (ref($validations{$item}) eq 'HASH') {
2055: if ($validations{$item}{'_LC_adv'}) {
2056: $canvalidate = 1;
2057: }
2058: }
2059: next if (!$canvalidate);
2060: }
2061: my $checked = '';
1.104 raeburn 2062: if ($val eq $curroption) {
1.101 raeburn 2063: $checked = ' checked="checked"';
2064: } elsif ($option eq 'autolimit') {
2065: if ($curroption =~ /^autolimit/) {
2066: $checked = ' checked="checked"';
2067: }
2068: }
2069: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2070: '<input type="radio" name="crsreq_'.$item.
2071: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2072: $titles{$option}.'</label>';
2073: if ($option eq 'autolimit') {
1.127 raeburn 2074: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2075: $item.'_limit__LC_adv" size="1" '.
2076: 'value="'.$currlimit.'" />';
2077: }
1.127 raeburn 2078: $advcell{$item} .= '</span> ';
1.104 raeburn 2079: if ($option eq 'autolimit') {
1.127 raeburn 2080: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2081: }
1.101 raeburn 2082: }
1.160.6.5 raeburn 2083: } elsif ($context eq 'requestauthor') {
2084: my $curroption;
2085: if (ref($settings) eq 'HASH') {
2086: $curroption = $settings->{'_LC_adv'};
2087: }
2088: my $checked = '';
2089: if ($curroption eq '') {
2090: $checked = ' checked="checked"';
2091: }
2092: $datatable .= '<span class="LC_nobreak"><label>'.
2093: '<input type="radio" name="authorreq__LC_adv"'.
2094: ' value=""'.$checked.' />'.
2095: &mt('No override set').'</label></span> ';
2096: foreach my $option (@options) {
2097: my $val = $option;
2098: if ($option eq 'norequest') {
2099: $val = 0;
2100: }
2101: my $checked = '';
2102: if ($val eq $curroption) {
2103: $checked = ' checked="checked"';
2104: }
2105: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2106: '<input type="radio" name="authorreq__LC_adv"'.
2107: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2108: $titles{$option}.'</label></span> ';
2109: }
1.101 raeburn 2110: } else {
2111: my $checked = 'checked="checked" ';
2112: if (ref($settings) eq 'HASH') {
2113: if (ref($settings->{$item}) eq 'HASH') {
2114: if ($settings->{$item}->{'_LC_adv'} == 0) {
2115: $checked = '';
2116: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2117: $checked = 'checked="checked" ';
2118: }
1.79 raeburn 2119: }
1.72 raeburn 2120: }
1.101 raeburn 2121: $datatable .= '<span class="LC_nobreak"><label>'.
2122: '<input type="checkbox" name="'.$context.'_'.$item.
2123: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2124: '</label></span> ';
2125: }
2126: }
2127: if ($context eq 'requestcourses') {
2128: $datatable .= '</tr><tr>';
2129: foreach my $item (@usertools) {
1.106 raeburn 2130: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2131: }
1.101 raeburn 2132: $datatable .= '</tr></table>';
1.72 raeburn 2133: }
1.98 raeburn 2134: $datatable .= '</td></tr>';
1.30 raeburn 2135: $$rowtotal += $typecount;
1.3 raeburn 2136: return $datatable;
2137: }
2138:
1.160.6.5 raeburn 2139: sub print_requestmail {
2140: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2141: my ($now,$datatable,%currapp);
1.102 raeburn 2142: $now = time;
2143: if (ref($settings) eq 'HASH') {
2144: if (ref($settings->{'notify'}) eq 'HASH') {
2145: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2146: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2147: }
2148: }
2149: }
1.160.6.16 raeburn 2150: my $numinrow = 2;
1.160.6.34 raeburn 2151: my $css_class;
2152: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2153: my $text;
2154: if ($action eq 'requestcourses') {
2155: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2156: } elsif ($action eq 'requestauthor') {
2157: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2158: } else {
1.160.6.34 raeburn 2159: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2160: }
1.160.6.34 raeburn 2161: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2162: ' <td>'.$text.'</td>'.
1.102 raeburn 2163: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2164: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2165: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2166: if ($numdc > 0) {
2167: $datatable .= $table;
1.102 raeburn 2168: } else {
2169: $datatable .= &mt('There are no active Domain Coordinators');
2170: }
2171: $datatable .='</td></tr>';
2172: return $datatable;
2173: }
2174:
1.160.6.30 raeburn 2175: sub print_studentcode {
2176: my ($settings,$rowtotal) = @_;
2177: my $rownum = 0;
2178: my ($output,%current);
2179: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2180: if (ref($settings) eq 'HASH') {
2181: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2182: foreach my $type (@crstypes) {
2183: $current{$type} = $settings->{'uniquecode'}{$type};
2184: }
1.160.6.30 raeburn 2185: }
2186: }
2187: $output .= '<tr>'.
2188: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2189: '<td class="LC_left_item">';
2190: foreach my $type (@crstypes) {
2191: my $check = ' ';
2192: if ($current{$type}) {
2193: $check = ' checked="checked" ';
2194: }
2195: $output .= '<span class="LC_nobreak"><label>'.
2196: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2197: &mt($type).'</label></span>'.(' 'x2).' ';
2198: }
2199: $output .= '</td></tr>';
2200: $$rowtotal ++;
2201: return $output;
2202: }
2203:
2204: sub print_textbookcourses {
1.160.6.46 raeburn 2205: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2206: my $rownum = 0;
2207: my $css_class;
2208: my $itemcount = 1;
2209: my $maxnum = 0;
2210: my $bookshash;
2211: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2212: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2213: }
2214: my %ordered;
2215: if (ref($bookshash) eq 'HASH') {
2216: foreach my $item (keys(%{$bookshash})) {
2217: if (ref($bookshash->{$item}) eq 'HASH') {
2218: my $num = $bookshash->{$item}{'order'};
2219: $ordered{$num} = $item;
2220: }
2221: }
2222: }
2223: my $confname = $dom.'-domainconfig';
2224: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2225: my $maxnum = scalar(keys(%ordered));
2226: my $datatable;
1.160.6.30 raeburn 2227: if (keys(%ordered)) {
2228: my @items = sort { $a <=> $b } keys(%ordered);
2229: for (my $i=0; $i<@items; $i++) {
2230: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2231: my $key = $ordered{$items[$i]};
2232: my %coursehash=&Apache::lonnet::coursedescription($key);
2233: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2234: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2235: if (ref($bookshash->{$key}) eq 'HASH') {
2236: $subject = $bookshash->{$key}->{'subject'};
2237: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2238: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2239: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2240: $author = $bookshash->{$key}->{'author'};
2241: $image = $bookshash->{$key}->{'image'};
2242: if ($image ne '') {
2243: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2244: my $imagethumb = "$path/tn-".$imagefile;
2245: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2246: }
1.160.6.30 raeburn 2247: }
2248: }
1.160.6.46 raeburn 2249: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2250: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2251: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2252: for (my $k=0; $k<=$maxnum; $k++) {
2253: my $vpos = $k+1;
2254: my $selstr;
2255: if ($k == $i) {
2256: $selstr = ' selected="selected" ';
2257: }
2258: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2259: }
2260: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2261: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2262: &mt('Delete?').'</label></span></td>'.
2263: '<td colspan="2">'.
1.160.6.46 raeburn 2264: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2265: (' 'x2).
1.160.6.46 raeburn 2266: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2267: if ($type eq 'textbooks') {
2268: $datatable .= (' 'x2).
1.160.6.47 raeburn 2269: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2270: (' 'x2).
1.160.6.46 raeburn 2271: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2272: (' 'x2).
2273: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2274: if ($image) {
2275: $datatable .= '<span class="LC_nobreak">'.
2276: $imgsrc.
2277: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2278: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2279: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2280: }
2281: if ($switchserver) {
2282: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2283: } else {
2284: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2285: }
1.160.6.30 raeburn 2286: }
1.160.6.46 raeburn 2287: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2288: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2289: $coursetitle.'</span></td></tr>'."\n";
2290: $itemcount ++;
2291: }
2292: }
2293: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2294: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2295: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2296: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2297: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2298: for (my $k=0; $k<$maxnum+1; $k++) {
2299: my $vpos = $k+1;
2300: my $selstr;
2301: if ($k == $maxnum) {
2302: $selstr = ' selected="selected" ';
2303: }
2304: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2305: }
2306: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2307: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2308: '<td colspan="2">'.
1.160.6.46 raeburn 2309: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2310: (' 'x2).
1.160.6.46 raeburn 2311: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2312: (' 'x2);
2313: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2314: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2315: (' 'x2).
2316: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2317: (' 'x2).
2318: '<span class="LC_nobreak">'.&mt('Image:').' ';
2319: if ($switchserver) {
2320: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2321: } else {
2322: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2323: }
1.160.6.30 raeburn 2324: }
2325: $datatable .= '</span>'."\n".
2326: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2327: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2328: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2329: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2330: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2331: '</span></td>'."\n".
2332: '</tr>'."\n";
2333: $itemcount ++;
2334: return $datatable;
2335: }
2336:
2337: sub textbookcourses_javascript {
1.160.6.46 raeburn 2338: my ($settings) = @_;
2339: return unless(ref($settings) eq 'HASH');
2340: my (%ordered,%total,%jstext);
2341: foreach my $type ('textbooks','templates') {
2342: $total{$type} = 0;
2343: if (ref($settings->{$type}) eq 'HASH') {
2344: foreach my $item (keys(%{$settings->{$type}})) {
2345: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2346: my $num = $settings->{$type}->{$item}{'order'};
2347: $ordered{$type}{$num} = $item;
2348: }
2349: }
2350: $total{$type} = scalar(keys(%{$settings->{$type}}));
2351: }
2352: my @jsarray = ();
2353: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2354: push(@jsarray,$ordered{$type}{$item});
2355: }
2356: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2357: }
2358: return <<"ENDSCRIPT";
2359: <script type="text/javascript">
2360: // <![CDATA[
1.160.6.46 raeburn 2361: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2362: var changedVal;
1.160.6.46 raeburn 2363: $jstext{'textbooks'};
2364: $jstext{'templates'};
2365: var newpos;
2366: var maxh;
2367: if (caller == 'textbooks') {
2368: newpos = 'textbooks_addbook_pos';
2369: maxh = 1 + $total{'textbooks'};
2370: } else {
2371: newpos = 'templates_addbook_pos';
2372: maxh = 1 + $total{'templates'};
2373: }
1.160.6.30 raeburn 2374: var current = new Array;
2375: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2376: if (item == newpos) {
2377: changedVal = newitemVal;
2378: } else {
2379: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2380: current[newitemVal] = newpos;
2381: }
1.160.6.46 raeburn 2382: if (caller == 'textbooks') {
2383: for (var i=0; i<textbooks.length; i++) {
2384: var elementName = 'textbooks_'+textbooks[i];
2385: if (elementName != item) {
2386: if (form.elements[elementName]) {
2387: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2388: current[currVal] = elementName;
2389: }
2390: }
2391: }
2392: }
2393: if (caller == 'templates') {
2394: for (var i=0; i<templates.length; i++) {
2395: var elementName = 'templates_'+templates[i];
2396: if (elementName != item) {
2397: if (form.elements[elementName]) {
2398: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2399: current[currVal] = elementName;
2400: }
1.160.6.30 raeburn 2401: }
2402: }
2403: }
2404: var oldVal;
2405: for (var j=0; j<maxh; j++) {
2406: if (current[j] == undefined) {
2407: oldVal = j;
2408: }
2409: }
2410: if (oldVal < changedVal) {
2411: for (var k=oldVal+1; k<=changedVal ; k++) {
2412: var elementName = current[k];
2413: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2414: }
2415: } else {
2416: for (var k=changedVal; k<oldVal; k++) {
2417: var elementName = current[k];
2418: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2419: }
2420: }
2421: return;
2422: }
2423:
2424: // ]]>
2425: </script>
2426:
2427: ENDSCRIPT
2428: }
2429:
1.3 raeburn 2430: sub print_autoenroll {
1.30 raeburn 2431: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2432: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2433: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2434: if (ref($settings) eq 'HASH') {
2435: if (exists($settings->{'run'})) {
2436: if ($settings->{'run'} eq '0') {
2437: $runoff = ' checked="checked" ';
2438: $runon = ' ';
2439: } else {
2440: $runon = ' checked="checked" ';
2441: $runoff = ' ';
2442: }
2443: } else {
2444: if ($autorun) {
2445: $runon = ' checked="checked" ';
2446: $runoff = ' ';
2447: } else {
2448: $runoff = ' checked="checked" ';
2449: $runon = ' ';
2450: }
2451: }
1.129 raeburn 2452: if (exists($settings->{'co-owners'})) {
2453: if ($settings->{'co-owners'} eq '0') {
2454: $coownersoff = ' checked="checked" ';
2455: $coownerson = ' ';
2456: } else {
2457: $coownerson = ' checked="checked" ';
2458: $coownersoff = ' ';
2459: }
2460: } else {
2461: $coownersoff = ' checked="checked" ';
2462: $coownerson = ' ';
2463: }
1.3 raeburn 2464: if (exists($settings->{'sender_domain'})) {
2465: $defdom = $settings->{'sender_domain'};
2466: }
1.160.6.68 raeburn 2467: if (exists($settings->{'autofailsafe'})) {
2468: $failsafe = $settings->{'autofailsafe'};
2469: }
1.14 raeburn 2470: } else {
2471: if ($autorun) {
2472: $runon = ' checked="checked" ';
2473: $runoff = ' ';
2474: } else {
2475: $runoff = ' checked="checked" ';
2476: $runon = ' ';
2477: }
1.3 raeburn 2478: }
2479: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2480: my $notif_sender;
2481: if (ref($settings) eq 'HASH') {
2482: $notif_sender = $settings->{'sender_uname'};
2483: }
1.3 raeburn 2484: my $datatable='<tr class="LC_odd_row">'.
2485: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2486: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2487: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2488: $runon.' value="1" />'.&mt('Yes').'</label> '.
2489: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2490: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2491: '</tr><tr>'.
2492: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2493: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2494: &mt('username').': '.
2495: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2496: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2497: ': '.$domform.'</span></td></tr>'.
2498: '<tr class="LC_odd_row">'.
2499: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2500: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2501: '<input type="radio" name="autoassign_coowners"'.
2502: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2503: '<label><input type="radio" name="autoassign_coowners"'.
2504: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2505: '</tr><tr>'.
2506: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2507: '<td class="LC_right_item"><span class="LC_nobreak">'.
2508: '<input type="text" name="autoenroll_failsafe"'.
2509: ' value="'.$failsafe.'" size="4" /></td></tr>';
2510: $$rowtotal += 4;
1.3 raeburn 2511: return $datatable;
2512: }
2513:
2514: sub print_autoupdate {
1.30 raeburn 2515: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2516: my $datatable;
2517: if ($position eq 'top') {
2518: my $updateon = ' ';
2519: my $updateoff = ' checked="checked" ';
2520: my $classlistson = ' ';
2521: my $classlistsoff = ' checked="checked" ';
2522: if (ref($settings) eq 'HASH') {
2523: if ($settings->{'run'} eq '1') {
2524: $updateon = $updateoff;
2525: $updateoff = ' ';
2526: }
2527: if ($settings->{'classlists'} eq '1') {
2528: $classlistson = $classlistsoff;
2529: $classlistsoff = ' ';
2530: }
2531: }
2532: my %title = (
2533: run => 'Auto-update active?',
2534: classlists => 'Update information in classlists?',
2535: );
2536: $datatable = '<tr class="LC_odd_row">'.
2537: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2538: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2539: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2540: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2541: '<label><input type="radio" name="autoupdate_run"'.
2542: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2543: '</tr><tr>'.
2544: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2545: '<td class="LC_right_item"><span class="LC_nobreak">'.
2546: '<label><input type="radio" name="classlists"'.
2547: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2548: '<label><input type="radio" name="classlists"'.
2549: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2550: '</tr>';
1.30 raeburn 2551: $$rowtotal += 2;
1.131 raeburn 2552: } elsif ($position eq 'middle') {
2553: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2554: my $numinrow = 3;
2555: my $locknamesettings;
2556: $datatable .= &insttypes_row($settings,$types,$usertypes,
2557: $dom,$numinrow,$othertitle,
2558: 'lockablenames');
2559: $$rowtotal ++;
1.3 raeburn 2560: } else {
1.44 raeburn 2561: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2562: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2563: 'permanentemail','id');
1.33 raeburn 2564: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2565: my $numrows = 0;
1.26 raeburn 2566: if (ref($types) eq 'ARRAY') {
2567: if (@{$types} > 0) {
2568: $datatable =
2569: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2570: \@fields,$types,\$numrows);
1.30 raeburn 2571: $$rowtotal += @{$types};
1.26 raeburn 2572: }
1.3 raeburn 2573: }
2574: $datatable .=
2575: &usertype_update_row($settings,{'default' => $othertitle},
2576: \%fieldtitles,\@fields,['default'],
2577: \$numrows);
1.30 raeburn 2578: $$rowtotal ++;
1.3 raeburn 2579: }
2580: return $datatable;
2581: }
2582:
1.125 raeburn 2583: sub print_autocreate {
2584: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2585: my (%createon,%createoff,%currhash);
1.125 raeburn 2586: my @types = ('xml','req');
2587: if (ref($settings) eq 'HASH') {
2588: foreach my $item (@types) {
2589: $createoff{$item} = ' checked="checked" ';
2590: $createon{$item} = ' ';
2591: if (exists($settings->{$item})) {
2592: if ($settings->{$item}) {
2593: $createon{$item} = ' checked="checked" ';
2594: $createoff{$item} = ' ';
2595: }
2596: }
2597: }
1.160.6.16 raeburn 2598: if ($settings->{'xmldc'} ne '') {
2599: $currhash{$settings->{'xmldc'}} = 1;
2600: }
1.125 raeburn 2601: } else {
2602: foreach my $item (@types) {
2603: $createoff{$item} = ' checked="checked" ';
2604: $createon{$item} = ' ';
2605: }
2606: }
2607: $$rowtotal += 2;
1.160.6.16 raeburn 2608: my $numinrow = 2;
1.125 raeburn 2609: my $datatable='<tr class="LC_odd_row">'.
2610: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2611: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2612: '<input type="radio" name="autocreate_xml"'.
2613: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2614: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2615: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2616: '</td></tr><tr>'.
2617: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2618: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2619: '<input type="radio" name="autocreate_req"'.
2620: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2621: '<label><input type="radio" name="autocreate_req"'.
2622: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2623: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2624: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2625: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2626: if ($numdc > 1) {
1.160.6.50 raeburn 2627: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2628: '</td><td class="LC_left_item">';
1.125 raeburn 2629: } else {
1.160.6.50 raeburn 2630: $datatable .= &mt('Course creation processed as:').
2631: '</td><td class="LC_right_item">';
1.125 raeburn 2632: }
1.160.6.50 raeburn 2633: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2634: $$rowtotal += $rows;
1.125 raeburn 2635: return $datatable;
2636: }
2637:
1.23 raeburn 2638: sub print_directorysrch {
1.160.6.72 raeburn 2639: my ($position,$dom,$settings,$rowtotal) = @_;
2640: my $datatable;
2641: if ($position eq 'top') {
2642: my $instsrchon = ' ';
2643: my $instsrchoff = ' checked="checked" ';
2644: my ($exacton,$containson,$beginson);
2645: my $instlocalon = ' ';
2646: my $instlocaloff = ' checked="checked" ';
2647: if (ref($settings) eq 'HASH') {
2648: if ($settings->{'available'} eq '1') {
2649: $instsrchon = $instsrchoff;
2650: $instsrchoff = ' ';
2651: }
2652: if ($settings->{'localonly'} eq '1') {
2653: $instlocalon = $instlocaloff;
2654: $instlocaloff = ' ';
2655: }
2656: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2657: foreach my $type (@{$settings->{'searchtypes'}}) {
2658: if ($type eq 'exact') {
2659: $exacton = ' checked="checked" ';
2660: } elsif ($type eq 'contains') {
2661: $containson = ' checked="checked" ';
2662: } elsif ($type eq 'begins') {
2663: $beginson = ' checked="checked" ';
2664: }
2665: }
2666: } else {
2667: if ($settings->{'searchtypes'} eq 'exact') {
2668: $exacton = ' checked="checked" ';
2669: } elsif ($settings->{'searchtypes'} eq 'contains') {
2670: $containson = ' checked="checked" ';
2671: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2672: $exacton = ' checked="checked" ';
2673: $containson = ' checked="checked" ';
2674: }
2675: }
1.23 raeburn 2676: }
1.160.6.72 raeburn 2677: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2678: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2679:
1.160.6.72 raeburn 2680: my $numinrow = 4;
2681: my $cansrchrow = 0;
2682: $datatable='<tr class="LC_odd_row">'.
2683: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2684: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2685: '<input type="radio" name="dirsrch_available"'.
2686: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2687: '<label><input type="radio" name="dirsrch_available"'.
2688: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2689: '</tr><tr>'.
2690: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2691: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2692: '<input type="radio" name="dirsrch_instlocalonly"'.
2693: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2694: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2695: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2696: '</tr>';
2697: $$rowtotal += 2;
2698: if (ref($usertypes) eq 'HASH') {
2699: if (keys(%{$usertypes}) > 0) {
2700: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2701: $numinrow,$othertitle,'cansearch');
2702: $cansrchrow = 1;
2703: }
1.26 raeburn 2704: }
1.160.6.72 raeburn 2705: if ($cansrchrow) {
2706: $$rowtotal ++;
2707: $datatable .= '<tr>';
2708: } else {
2709: $datatable .= '<tr class="LC_odd_row">';
2710: }
2711: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2712: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2713: foreach my $title (@{$titleorder}) {
2714: if (defined($searchtitles->{$title})) {
2715: my $check = ' ';
2716: if (ref($settings) eq 'HASH') {
2717: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2718: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2719: $check = ' checked="checked" ';
2720: }
1.39 raeburn 2721: }
1.25 raeburn 2722: }
1.160.6.72 raeburn 2723: $datatable .= '<td class="LC_left_item">'.
2724: '<span class="LC_nobreak"><label>'.
2725: '<input type="checkbox" name="searchby" '.
2726: 'value="'.$title.'"'.$check.'/>'.
2727: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2728: }
2729: }
1.160.6.72 raeburn 2730: $datatable .= '</tr></table></td></tr>';
2731: $$rowtotal ++;
2732: if ($cansrchrow) {
2733: $datatable .= '<tr class="LC_odd_row">';
2734: } else {
2735: $datatable .= '<tr>';
2736: }
2737: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2738: '<td class="LC_left_item" colspan="2">'.
2739: '<span class="LC_nobreak"><label>'.
2740: '<input type="checkbox" name="searchtypes" '.
2741: $exacton.' value="exact" />'.&mt('Exact match').
2742: '</label> '.
2743: '<label><input type="checkbox" name="searchtypes" '.
2744: $beginson.' value="begins" />'.&mt('Begins with').
2745: '</label> '.
2746: '<label><input type="checkbox" name="searchtypes" '.
2747: $containson.' value="contains" />'.&mt('Contains').
2748: '</label></span></td></tr>';
2749: $$rowtotal ++;
1.26 raeburn 2750: } else {
1.160.6.72 raeburn 2751: my $domsrchon = ' checked="checked" ';
2752: my $domsrchoff = ' ';
2753: my $domlocalon = ' ';
2754: my $domlocaloff = ' checked="checked" ';
2755: if (ref($settings) eq 'HASH') {
2756: if ($settings->{'lclocalonly'} eq '1') {
2757: $domlocalon = $domlocaloff;
2758: $domlocaloff = ' ';
2759: }
2760: if ($settings->{'lcavailable'} eq '0') {
2761: $domsrchoff = $domsrchon;
2762: $domsrchon = ' ';
2763: }
2764: }
2765: $datatable='<tr class="LC_odd_row">'.
2766: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2767: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2768: '<input type="radio" name="dirsrch_domavailable"'.
2769: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2770: '<label><input type="radio" name="dirsrch_domavailable"'.
2771: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2772: '</tr><tr>'.
2773: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2774: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2775: '<input type="radio" name="dirsrch_domlocalonly"'.
2776: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2777: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2778: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2779: '</tr>';
2780: $$rowtotal += 2;
1.26 raeburn 2781: }
1.25 raeburn 2782: return $datatable;
2783: }
2784:
1.28 raeburn 2785: sub print_contacts {
1.30 raeburn 2786: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2787: my $datatable;
2788: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2789: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2790: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2791: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2792: foreach my $type (@mailings) {
2793: $otheremails{$type} = '';
2794: }
1.134 raeburn 2795: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2796: if (ref($settings) eq 'HASH') {
2797: foreach my $item (@contacts) {
2798: if (exists($settings->{$item})) {
2799: $to{$item} = $settings->{$item};
2800: }
2801: }
2802: foreach my $type (@mailings) {
2803: if (exists($settings->{$type})) {
2804: if (ref($settings->{$type}) eq 'HASH') {
2805: foreach my $item (@contacts) {
2806: if ($settings->{$type}{$item}) {
2807: $checked{$type}{$item} = ' checked="checked" ';
2808: }
2809: }
2810: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2811: if ($type eq 'helpdeskmail') {
2812: $bccemails{$type} = $settings->{$type}{'bcc'};
2813: }
1.28 raeburn 2814: }
1.89 raeburn 2815: } elsif ($type eq 'lonstatusmail') {
2816: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2817: }
2818: }
2819: } else {
2820: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2821: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2822: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2823: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2824: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2825: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2826: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2827: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2828: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2829: }
2830: my ($titles,$short_titles) = &contact_titles();
2831: my $rownum = 0;
2832: my $css_class;
2833: foreach my $item (@contacts) {
1.69 raeburn 2834: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2835: $datatable .= '<tr'.$css_class.'>'.
2836: '<td><span class="LC_nobreak">'.$titles->{$item}.
2837: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2838: '<input type="text" name="'.$item.'" value="'.
2839: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2840: $rownum ++;
1.28 raeburn 2841: }
2842: foreach my $type (@mailings) {
1.69 raeburn 2843: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2844: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2845: '<td><span class="LC_nobreak">'.
2846: $titles->{$type}.': </span></td>'.
1.28 raeburn 2847: '<td class="LC_left_item">'.
2848: '<span class="LC_nobreak">';
2849: foreach my $item (@contacts) {
2850: $datatable .= '<label>'.
2851: '<input type="checkbox" name="'.$type.'"'.
2852: $checked{$type}{$item}.
2853: ' value="'.$item.'" />'.$short_titles->{$item}.
2854: '</label> ';
2855: }
2856: $datatable .= '</span><br />'.&mt('Others').': '.
2857: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2858: 'value="'.$otheremails{$type}.'" />';
2859: if ($type eq 'helpdeskmail') {
1.136 raeburn 2860: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2861: '<input type="text" name="'.$type.'_bcc" '.
2862: 'value="'.$bccemails{$type}.'" />';
2863: }
2864: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2865: $rownum ++;
1.28 raeburn 2866: }
1.160.6.23 raeburn 2867: my %choices;
2868: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2869: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2870: &mt('LON-CAPA core group - MSU'),600,500));
2871: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2872: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2873: &mt('LON-CAPA core group - MSU'),600,500));
2874: my @toggles = ('reporterrors','reportupdates');
2875: my %defaultchecked = ('reporterrors' => 'on',
2876: 'reportupdates' => 'on');
2877: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2878: \%choices,$rownum);
2879: $datatable .= $reports;
1.30 raeburn 2880: $$rowtotal += $rownum;
1.28 raeburn 2881: return $datatable;
2882: }
2883:
1.118 jms 2884: sub print_helpsettings {
1.160.6.73 raeburn 2885: my ($position,$dom,$settings,$rowtotal) = @_;
2886: my $confname = $dom.'-domainconfig';
1.160.6.5 raeburn 2887: my ($datatable,$itemcount);
1.160.6.73 raeburn 2888: if ($position eq 'top') {
2889: $itemcount = 1;
2890: my (%choices,%defaultchecked,@toggles);
2891: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2892: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2893: &mt('LON-CAPA bug tracker'),600,500));
2894: %defaultchecked = ('submitbugs' => 'on');
2895: @toggles = ('submitbugs');
2896: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2897: \%choices,$itemcount);
2898: $$rowtotal ++;
2899: } else {
2900: my $css_class;
2901: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
2902: my %customroles;
2903: foreach my $key (keys(%existing)) {
2904: if ($key=~/^rolesdef\_(\w+)$/) {
2905: my $rolename = $1;
2906: my %privs;
2907: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
2908: $customroles{$rolename} = \%privs;
2909: }
2910: }
2911: my $count = 0;
2912: my $context = 'domprefs';
2913: my $crstype = 'Course';
2914: foreach my $role (sort(keys(%customroles))) {
2915: my $prefix = 'custhelp'.$count;
2916: my %full=();
2917: my %levels= (
2918: course => {},
2919: domain => {},
2920: system => {},
2921: );
2922: my %levelscurrent=(
2923: course => {},
2924: domain => {},
2925: system => {},
2926: );
2927: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
2928: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
2929: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2930: $datatable .= '<tr '.$css_class.'><td><label>'.
2931: '<input type="checkbox" name="modifycusthelp" value="'.$count.'" />'.
2932: '<input type="hidden" name="custhelprole'.$count.'" value="'.$role.'" />'.
2933: &mt('Modify').'</label></td>'.
2934: '<td>'.&mt('Existing helpdesk role:').' '.
2935: '<b>'.$role.'</b><br />'.
2936: &Apache::lonuserutils::custom_role_header($context,$crstype,
2937: \@templateroles,$prefix).
2938: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
2939: \%levelscurrent,$prefix).
2940: '<br /></td>';
2941: $count ++;
2942: $itemcount ++;
2943: }
2944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2945: my $newcust = 'custhelp'.$count;
2946: my (%privs,%levelscurrent);
2947: my %full=();
2948: my %levels= (
2949: course => {},
2950: domain => {},
2951: system => {},
2952: );
2953: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
2954: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
2955: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><label>'.
2956: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
2957: '</label></span></td>'.
2958: '<td><span class="LC_nobreak">'.
2959: '<b>'.&mt('Name of new helpdesk role:').'</b> '.
2960: '<input type="text" size="20" name="newcusthelpname" value="" />'.
2961: '</span><br />'.
2962: &Apache::lonuserutils::custom_role_header($context,$crstype,
2963: \@templateroles,$newcust).
2964: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
2965: \%levelscurrent,$newcust).
2966: '<br /><br />'.
2967: '</td></tr>';
2968: $count ++;
2969: $$rowtotal += $count;
2970: }
1.160.6.5 raeburn 2971: return $datatable;
1.121 raeburn 2972: }
2973:
2974: sub radiobutton_prefs {
1.160.6.16 raeburn 2975: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2976: $additional,$align) = @_;
1.121 raeburn 2977: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2978: (ref($choices) eq 'HASH'));
2979:
2980: my (%checkedon,%checkedoff,$datatable,$css_class);
2981:
2982: foreach my $item (@{$toggles}) {
2983: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2984: $checkedon{$item} = ' checked="checked" ';
2985: $checkedoff{$item} = ' ';
1.121 raeburn 2986: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2987: $checkedoff{$item} = ' checked="checked" ';
2988: $checkedon{$item} = ' ';
2989: }
2990: }
2991: if (ref($settings) eq 'HASH') {
1.121 raeburn 2992: foreach my $item (@{$toggles}) {
1.118 jms 2993: if ($settings->{$item} eq '1') {
2994: $checkedon{$item} = ' checked="checked" ';
2995: $checkedoff{$item} = ' ';
2996: } elsif ($settings->{$item} eq '0') {
2997: $checkedoff{$item} = ' checked="checked" ';
2998: $checkedon{$item} = ' ';
2999: }
3000: }
1.121 raeburn 3001: }
1.160.6.16 raeburn 3002: if ($onclick) {
3003: $onclick = ' onclick="'.$onclick.'"';
3004: }
1.121 raeburn 3005: foreach my $item (@{$toggles}) {
1.118 jms 3006: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3007: $datatable .=
1.160.6.16 raeburn 3008: '<tr'.$css_class.'><td valign="top">'.
3009: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3010: '</span></td>';
3011: if ($align eq 'left') {
3012: $datatable .= '<td class="LC_left_item">';
3013: } else {
3014: $datatable .= '<td class="LC_right_item">';
3015: }
3016: $datatable .=
3017: '<span class="LC_nobreak">'.
1.118 jms 3018: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3019: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3020: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3021: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3022: '</span>'.$additional.
3023: '</td>'.
1.118 jms 3024: '</tr>';
3025: $itemcount ++;
1.121 raeburn 3026: }
3027: return ($datatable,$itemcount);
3028: }
3029:
3030: sub print_coursedefaults {
1.139 raeburn 3031: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3032: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3033: my $itemcount = 1;
1.160.6.16 raeburn 3034: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3035: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3036: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3037: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3038: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3039: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3040: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3041: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3042: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3043: );
1.160.6.21 raeburn 3044: my %staticdefaults = (
3045: anonsurvey_threshold => 10,
3046: uploadquota => 500,
1.160.6.57 raeburn 3047: postsubmit => 60,
1.160.6.70 raeburn 3048: mysqltables => 172800,
1.160.6.21 raeburn 3049: );
1.139 raeburn 3050: if ($position eq 'top') {
1.160.6.57 raeburn 3051: %defaultchecked = (
3052: 'uselcmath' => 'on',
3053: 'usejsme' => 'on',
1.160.6.64 raeburn 3054: 'canclone' => 'none',
1.160.6.57 raeburn 3055: );
3056: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3057: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3058: \%choices,$itemcount);
1.160.6.64 raeburn 3059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3060: $datatable .=
3061: '<tr'.$css_class.'><td valign="top">'.
3062: '<span class="LC_nobreak">'.$choices{'canclone'}.
3063: '</span></td><td class="LC_left_item">';
3064: my $currcanclone = 'none';
3065: my $onclick;
3066: my @cloneoptions = ('none','domain');
3067: my %clonetitles = (
3068: none => 'No additional course requesters',
3069: domain => "Any course requester in course's domain",
3070: instcode => 'Course requests for official courses ...',
3071: );
3072: my (%codedefaults,@code_order,@posscodes);
3073: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3074: \@code_order) eq 'ok') {
3075: if (@code_order > 0) {
3076: push(@cloneoptions,'instcode');
3077: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3078: }
3079: }
3080: if (ref($settings) eq 'HASH') {
3081: if ($settings->{'canclone'}) {
3082: if (ref($settings->{'canclone'}) eq 'HASH') {
3083: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3084: if (@code_order > 0) {
3085: $currcanclone = 'instcode';
3086: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3087: }
3088: }
3089: } elsif ($settings->{'canclone'} eq 'domain') {
3090: $currcanclone = $settings->{'canclone'};
3091: }
3092: }
3093: }
3094: foreach my $option (@cloneoptions) {
3095: my ($checked,$additional);
3096: if ($currcanclone eq $option) {
3097: $checked = ' checked="checked"';
3098: }
3099: if ($option eq 'instcode') {
3100: if (@code_order) {
3101: my $show = 'none';
3102: if ($checked) {
3103: $show = 'block';
3104: }
3105: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3106: &mt('Institutional codes for new and cloned course have identical:').
3107: '<br />';
3108: foreach my $item (@code_order) {
3109: my $codechk;
3110: if ($checked) {
3111: if (grep(/^\Q$item\E$/,@posscodes)) {
3112: $codechk = ' checked="checked"';
3113: }
3114: }
3115: $additional .= '<label>'.
3116: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3117: $item.'</label>';
3118: }
3119: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3120: }
3121: }
3122: $datatable .=
3123: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3124: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3125: '</label> '.$additional.'</span><br />';
3126: }
3127: $datatable .= '</td>'.
3128: '</tr>';
3129: $itemcount ++;
1.139 raeburn 3130: } else {
3131: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3132: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3133: my $currusecredits = 0;
1.160.6.57 raeburn 3134: my $postsubmitclient = 1;
1.160.6.30 raeburn 3135: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3136: if (ref($settings) eq 'HASH') {
3137: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3138: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3139: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3140: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3141: }
3142: }
1.160.6.16 raeburn 3143: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3144: foreach my $type (@types) {
3145: next if ($type eq 'community');
3146: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3147: if ($defcredits{$type} ne '') {
3148: $currusecredits = 1;
3149: }
3150: }
3151: }
3152: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3153: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3154: $postsubmitclient = 0;
3155: foreach my $type (@types) {
3156: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3157: }
3158: } else {
3159: foreach my $type (@types) {
3160: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3161: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3162: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3163: } else {
3164: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3165: }
3166: } else {
3167: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3168: }
3169: }
3170: }
3171: } else {
3172: foreach my $type (@types) {
3173: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3174: }
3175: }
1.160.6.70 raeburn 3176: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3177: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3178: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3179: }
3180: } else {
3181: foreach my $type (@types) {
3182: $currmysql{$type} = $staticdefaults{'mysqltables'};
3183: }
3184: }
1.160.6.58 raeburn 3185: } else {
3186: foreach my $type (@types) {
3187: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3188: }
1.139 raeburn 3189: }
3190: if (!$currdefresponder) {
1.160.6.21 raeburn 3191: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3192: } elsif ($currdefresponder < 1) {
3193: $currdefresponder = 1;
3194: }
1.160.6.21 raeburn 3195: foreach my $type (@types) {
3196: if ($curruploadquota{$type} eq '') {
3197: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3198: }
3199: }
1.139 raeburn 3200: $datatable .=
1.160.6.16 raeburn 3201: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3202: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3203: '</span></td>'.
3204: '<td class="LC_right_item"><span class="LC_nobreak">'.
3205: '<input type="text" name="anonsurvey_threshold"'.
3206: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3207: '</td></tr>'."\n";
3208: $itemcount ++;
3209: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3210: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3211: $choices{'uploadquota'}.
3212: '</span></td>'.
3213: '<td align="right" class="LC_right_item">'.
3214: '<table><tr>';
1.160.6.21 raeburn 3215: foreach my $type (@types) {
3216: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3217: '<input type="text" name="uploadquota_'.$type.'"'.
3218: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3219: }
3220: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3221: $itemcount ++;
1.160.6.40 raeburn 3222: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3223: my $display = 'none';
3224: if ($currusecredits) {
3225: $display = 'block';
3226: }
3227: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3228: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3229: foreach my $type (@types) {
3230: next if ($type eq 'community');
3231: $additional .= '<td align="center">'.&mt($type).'<br />'.
3232: '<input type="text" name="'.$type.'_credits"'.
3233: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3234: }
3235: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3236: %defaultchecked = ('coursecredits' => 'off');
3237: @toggles = ('coursecredits');
3238: my $current = {
3239: 'coursecredits' => $currusecredits,
3240: };
3241: (my $table,$itemcount) =
3242: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3243: \%choices,$itemcount,$onclick,$additional,'left');
3244: $datatable .= $table;
3245: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3246: my $display = 'none';
3247: if ($postsubmitclient) {
3248: $display = 'block';
3249: }
3250: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3251: &mt('Number of seconds submit is disabled').'<br />'.
3252: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3253: '<table><tr>';
1.160.6.57 raeburn 3254: foreach my $type (@types) {
3255: $additional .= '<td align="center">'.&mt($type).'<br />'.
3256: '<input type="text" name="'.$type.'_timeout" value="'.
3257: $deftimeout{$type}.'" size="5" /></td>';
3258: }
3259: $additional .= '</tr></table></div>'."\n";
3260: %defaultchecked = ('postsubmit' => 'on');
3261: @toggles = ('postsubmit');
1.160.6.70 raeburn 3262: $current = {
3263: 'postsubmit' => $postsubmitclient,
3264: };
1.160.6.57 raeburn 3265: ($table,$itemcount) =
3266: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3267: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3268: $datatable .= $table;
1.160.6.70 raeburn 3269: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3270: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3271: $choices{'mysqltables'}.
3272: '</span></td>'.
3273: '<td align="right" class="LC_right_item">'.
3274: '<table><tr>';
3275: foreach my $type (@types) {
3276: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3277: '<input type="text" name="mysqltables_'.$type.'"'.
3278: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3279: }
3280: $datatable .= '</tr></table></td></tr>'."\n";
3281: $itemcount ++;
3282:
1.160.6.37 raeburn 3283: }
3284: $$rowtotal += $itemcount;
3285: return $datatable;
3286: }
3287:
3288: sub print_selfenrollment {
3289: my ($position,$dom,$settings,$rowtotal) = @_;
3290: my ($css_class,$datatable);
3291: my $itemcount = 1;
3292: my @types = ('official','unofficial','community','textbook');
3293: if (($position eq 'top') || ($position eq 'middle')) {
3294: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3295: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3296: my @rows;
3297: my $key;
3298: if ($position eq 'top') {
3299: $key = 'admin';
3300: if (ref($rowsref) eq 'ARRAY') {
3301: @rows = @{$rowsref};
3302: }
3303: } elsif ($position eq 'middle') {
3304: $key = 'default';
3305: @rows = ('types','registered','approval','limit');
3306: }
3307: foreach my $row (@rows) {
3308: if (defined($titlesref->{$row})) {
3309: $itemcount ++;
3310: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3311: $datatable .= '<tr'.$css_class.'>'.
3312: '<td>'.$titlesref->{$row}.'</td>'.
3313: '<td class="LC_left_item">'.
3314: '<table><tr>';
3315: my (%current,%currentcap);
3316: if (ref($settings) eq 'HASH') {
3317: if (ref($settings->{$key}) eq 'HASH') {
3318: foreach my $type (@types) {
3319: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3320: $current{$type} = $settings->{$key}->{$type}->{$row};
3321: }
3322: if (($row eq 'limit') && ($key eq 'default')) {
3323: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3324: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3325: }
3326: }
3327: }
3328: }
3329: }
3330: my %roles = (
3331: '0' => &Apache::lonnet::plaintext('dc'),
3332: );
3333:
3334: foreach my $type (@types) {
3335: unless (($row eq 'registered') && ($key eq 'default')) {
3336: $datatable .= '<th>'.&mt($type).'</th>';
3337: }
3338: }
3339: unless (($row eq 'registered') && ($key eq 'default')) {
3340: $datatable .= '</tr><tr>';
3341: }
3342: foreach my $type (@types) {
3343: if ($type eq 'community') {
3344: $roles{'1'} = &mt('Community personnel');
3345: } else {
3346: $roles{'1'} = &mt('Course personnel');
3347: }
3348: $datatable .= '<td style="vertical-align: top">';
3349: if ($position eq 'top') {
3350: my %checked;
3351: if ($current{$type} eq '0') {
3352: $checked{'0'} = ' checked="checked"';
3353: } else {
3354: $checked{'1'} = ' checked="checked"';
3355: }
3356: foreach my $role ('1','0') {
3357: $datatable .= '<span class="LC_nobreak"><label>'.
3358: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3359: 'value="'.$role.'"'.$checked{$role}.' />'.
3360: $roles{$role}.'</label></span> ';
3361: }
3362: } else {
3363: if ($row eq 'types') {
3364: my %checked;
3365: if ($current{$type} =~ /^(all|dom)$/) {
3366: $checked{$1} = ' checked="checked"';
3367: } else {
3368: $checked{''} = ' checked="checked"';
3369: }
3370: foreach my $val ('','dom','all') {
3371: $datatable .= '<span class="LC_nobreak"><label>'.
3372: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3373: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3374: }
3375: } elsif ($row eq 'registered') {
3376: my %checked;
3377: if ($current{$type} eq '1') {
3378: $checked{'1'} = ' checked="checked"';
3379: } else {
3380: $checked{'0'} = ' checked="checked"';
3381: }
3382: foreach my $val ('0','1') {
3383: $datatable .= '<span class="LC_nobreak"><label>'.
3384: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3385: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3386: }
3387: } elsif ($row eq 'approval') {
3388: my %checked;
3389: if ($current{$type} =~ /^([12])$/) {
3390: $checked{$1} = ' checked="checked"';
3391: } else {
3392: $checked{'0'} = ' checked="checked"';
3393: }
3394: for my $val (0..2) {
3395: $datatable .= '<span class="LC_nobreak"><label>'.
3396: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3397: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3398: }
3399: } elsif ($row eq 'limit') {
3400: my %checked;
3401: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3402: $checked{$1} = ' checked="checked"';
3403: } else {
3404: $checked{'none'} = ' checked="checked"';
3405: }
3406: my $cap;
3407: if ($currentcap{$type} =~ /^\d+$/) {
3408: $cap = $currentcap{$type};
3409: }
3410: foreach my $val ('none','allstudents','selfenrolled') {
3411: $datatable .= '<span class="LC_nobreak"><label>'.
3412: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3413: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3414: }
3415: $datatable .= '<br />'.
3416: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3417: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3418: '</span>';
3419: }
3420: }
3421: $datatable .= '</td>';
3422: }
3423: $datatable .= '</tr>';
3424: }
3425: $datatable .= '</table></td></tr>';
3426: }
3427: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3428: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3429: }
3430: $$rowtotal += $itemcount;
3431: return $datatable;
3432: }
3433:
3434: sub print_validation_rows {
3435: my ($caller,$dom,$settings,$rowtotal) = @_;
3436: my ($itemsref,$namesref,$fieldsref);
3437: if ($caller eq 'selfenroll') {
3438: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3439: } elsif ($caller eq 'requestcourses') {
3440: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3441: }
3442: my %currvalidation;
3443: if (ref($settings) eq 'HASH') {
3444: if (ref($settings->{'validation'}) eq 'HASH') {
3445: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3446: }
1.160.6.39 raeburn 3447: }
3448: my $datatable;
3449: my $itemcount = 0;
3450: foreach my $item (@{$itemsref}) {
3451: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3452: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3453: $namesref->{$item}.
3454: '</span></td>'.
3455: '<td class="LC_left_item">';
3456: if (($item eq 'url') || ($item eq 'button')) {
3457: $datatable .= '<span class="LC_nobreak">'.
3458: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3459: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3460: } elsif ($item eq 'fields') {
3461: my @currfields;
3462: if (ref($currvalidation{$item}) eq 'ARRAY') {
3463: @currfields = @{$currvalidation{$item}};
3464: }
3465: foreach my $field (@{$fieldsref}) {
3466: my $check = '';
3467: if (grep(/^\Q$field\E$/,@currfields)) {
3468: $check = ' checked="checked"';
3469: }
3470: $datatable .= '<span class="LC_nobreak"><label>'.
3471: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3472: ' value="'.$field.'"'.$check.' />'.$field.
3473: '</label></span> ';
3474: }
3475: } elsif ($item eq 'markup') {
3476: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3477: $currvalidation{$item}.
1.160.6.37 raeburn 3478: '</textarea>';
1.160.6.39 raeburn 3479: }
3480: $datatable .= '</td></tr>'."\n";
3481: if (ref($rowtotal)) {
1.160.6.37 raeburn 3482: $itemcount ++;
3483: }
1.139 raeburn 3484: }
1.160.6.39 raeburn 3485: if ($caller eq 'requestcourses') {
3486: my %currhash;
1.160.6.51 raeburn 3487: if (ref($settings) eq 'HASH') {
3488: if (ref($settings->{'validation'}) eq 'HASH') {
3489: if ($settings->{'validation'}{'dc'} ne '') {
3490: $currhash{$settings->{'validation'}{'dc'}} = 1;
3491: }
1.160.6.39 raeburn 3492: }
3493: }
3494: my $numinrow = 2;
3495: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3496: 'validationdc',%currhash);
1.160.6.50 raeburn 3497: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3498: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3499: if ($numdc > 1) {
1.160.6.50 raeburn 3500: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3501: } else {
1.160.6.50 raeburn 3502: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3503: }
1.160.6.50 raeburn 3504: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3505: $itemcount ++;
3506: }
3507: if (ref($rowtotal)) {
3508: $$rowtotal += $itemcount;
3509: }
1.121 raeburn 3510: return $datatable;
1.118 jms 3511: }
3512:
1.137 raeburn 3513: sub print_usersessions {
3514: my ($position,$dom,$settings,$rowtotal) = @_;
3515: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3516: my (%by_ip,%by_location,@intdoms);
3517: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3518:
3519: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3520: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3521: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3522: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3523: my $itemcount = 1;
3524: if ($position eq 'top') {
1.152 raeburn 3525: if (keys(%serverhomes) > 1) {
1.145 raeburn 3526: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3527: my $curroffloadnow;
3528: if (ref($settings) eq 'HASH') {
3529: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3530: $curroffloadnow = $settings->{'offloadnow'};
3531: }
3532: }
3533: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3534: } else {
1.140 raeburn 3535: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3536: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3537: }
1.137 raeburn 3538: } else {
1.145 raeburn 3539: if (keys(%by_location) == 0) {
3540: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3541: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3542: } else {
3543: my %lt = &usersession_titles();
3544: my $numinrow = 5;
3545: my $prefix;
3546: my @types;
3547: if ($position eq 'bottom') {
3548: $prefix = 'remote';
3549: @types = ('version','excludedomain','includedomain');
3550: } else {
3551: $prefix = 'hosted';
3552: @types = ('excludedomain','includedomain');
3553: }
3554: my (%current,%checkedon,%checkedoff);
3555: my @lcversions = &Apache::lonnet::all_loncaparevs();
3556: my @locations = sort(keys(%by_location));
3557: foreach my $type (@types) {
3558: $checkedon{$type} = '';
3559: $checkedoff{$type} = ' checked="checked"';
3560: }
3561: if (ref($settings) eq 'HASH') {
3562: if (ref($settings->{$prefix}) eq 'HASH') {
3563: foreach my $key (keys(%{$settings->{$prefix}})) {
3564: $current{$key} = $settings->{$prefix}{$key};
3565: if ($key eq 'version') {
3566: if ($current{$key} ne '') {
3567: $checkedon{$key} = ' checked="checked"';
3568: $checkedoff{$key} = '';
3569: }
3570: } elsif (ref($current{$key}) eq 'ARRAY') {
3571: $checkedon{$key} = ' checked="checked"';
3572: $checkedoff{$key} = '';
3573: }
1.137 raeburn 3574: }
3575: }
3576: }
1.145 raeburn 3577: foreach my $type (@types) {
3578: next if ($type ne 'version' && !@locations);
3579: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3580: $datatable .= '<tr'.$css_class.'>
3581: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3582: <span class="LC_nobreak">
3583: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3584: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3585: if ($type eq 'version') {
3586: my $selector = '<select name="'.$prefix.'_version">';
3587: foreach my $version (@lcversions) {
3588: my $selected = '';
3589: if ($current{'version'} eq $version) {
3590: $selected = ' selected="selected"';
3591: }
3592: $selector .= ' <option value="'.$version.'"'.
3593: $selected.'>'.$version.'</option>';
3594: }
3595: $selector .= '</select> ';
3596: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3597: } else {
3598: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3599: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3600: ' />'.(' 'x2).
3601: '<input type="button" value="'.&mt('uncheck all').'" '.
3602: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3603: "\n".
3604: '</div><div><table>';
3605: my $rem;
3606: for (my $i=0; $i<@locations; $i++) {
3607: my ($showloc,$value,$checkedtype);
3608: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3609: my $ip = $by_location{$locations[$i]}->[0];
3610: if (ref($by_ip{$ip}) eq 'ARRAY') {
3611: $value = join(':',@{$by_ip{$ip}});
3612: $showloc = join(', ',@{$by_ip{$ip}});
3613: if (ref($current{$type}) eq 'ARRAY') {
3614: foreach my $loc (@{$by_ip{$ip}}) {
3615: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3616: $checkedtype = ' checked="checked"';
3617: last;
3618: }
3619: }
1.138 raeburn 3620: }
3621: }
3622: }
1.145 raeburn 3623: $rem = $i%($numinrow);
3624: if ($rem == 0) {
3625: if ($i > 0) {
3626: $datatable .= '</tr>';
3627: }
3628: $datatable .= '<tr>';
3629: }
3630: $datatable .= '<td class="LC_left_item">'.
3631: '<span class="LC_nobreak"><label>'.
3632: '<input type="checkbox" name="'.$prefix.'_'.$type.
3633: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3634: '</label></span></td>';
1.137 raeburn 3635: }
1.145 raeburn 3636: $rem = @locations%($numinrow);
3637: my $colsleft = $numinrow - $rem;
3638: if ($colsleft > 1 ) {
3639: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3640: ' </td>';
3641: } elsif ($colsleft == 1) {
3642: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3643: }
1.145 raeburn 3644: $datatable .= '</tr></table>';
1.137 raeburn 3645: }
1.145 raeburn 3646: $datatable .= '</td></tr>';
3647: $itemcount ++;
1.137 raeburn 3648: }
3649: }
3650: }
3651: $$rowtotal += $itemcount;
3652: return $datatable;
3653: }
3654:
1.138 raeburn 3655: sub build_location_hashes {
3656: my ($intdoms,$by_ip,$by_location) = @_;
3657: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3658: (ref($by_location) eq 'HASH'));
3659: my %iphost = &Apache::lonnet::get_iphost();
3660: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3661: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3662: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3663: foreach my $id (@{$iphost{$primary_ip}}) {
3664: my $intdom = &Apache::lonnet::internet_dom($id);
3665: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3666: push(@{$intdoms},$intdom);
3667: }
3668: }
3669: }
3670: foreach my $ip (keys(%iphost)) {
3671: if (ref($iphost{$ip}) eq 'ARRAY') {
3672: foreach my $id (@{$iphost{$ip}}) {
3673: my $location = &Apache::lonnet::internet_dom($id);
3674: if ($location) {
3675: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3676: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3677: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3678: push(@{$by_ip->{$ip}},$location);
3679: }
3680: } else {
3681: $by_ip->{$ip} = [$location];
3682: }
3683: }
3684: }
3685: }
3686: }
3687: foreach my $ip (sort(keys(%{$by_ip}))) {
3688: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3689: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3690: my $first = $by_ip->{$ip}->[0];
3691: if (ref($by_location->{$first}) eq 'ARRAY') {
3692: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3693: push(@{$by_location->{$first}},$ip);
3694: }
3695: } else {
3696: $by_location->{$first} = [$ip];
3697: }
3698: }
3699: }
3700: return;
3701: }
3702:
1.145 raeburn 3703: sub current_offloads_to {
3704: my ($dom,$settings,$servers) = @_;
3705: my (%spareid,%otherdomconfigs);
1.152 raeburn 3706: if (ref($servers) eq 'HASH') {
1.145 raeburn 3707: foreach my $lonhost (sort(keys(%{$servers}))) {
3708: my $gotspares;
1.152 raeburn 3709: if (ref($settings) eq 'HASH') {
3710: if (ref($settings->{'spares'}) eq 'HASH') {
3711: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3712: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3713: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3714: $gotspares = 1;
3715: }
1.145 raeburn 3716: }
3717: }
3718: unless ($gotspares) {
3719: my $gotspares;
3720: my $serverhomeID =
3721: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3722: my $serverhomedom =
3723: &Apache::lonnet::host_domain($serverhomeID);
3724: if ($serverhomedom ne $dom) {
3725: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3726: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3727: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3728: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3729: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3730: $gotspares = 1;
3731: }
3732: }
3733: } else {
3734: $otherdomconfigs{$serverhomedom} =
3735: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3736: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3737: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3738: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3739: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3740: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3741: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3742: $gotspares = 1;
3743: }
3744: }
3745: }
3746: }
3747: }
3748: }
3749: }
3750: unless ($gotspares) {
3751: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3752: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3753: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3754: } else {
3755: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3756: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3757: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3758: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3759: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3760: } else {
1.150 raeburn 3761: my %what = (
3762: spareid => 1,
3763: );
3764: my ($result,$returnhash) =
3765: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3766: if ($result eq 'ok') {
3767: if (ref($returnhash) eq 'HASH') {
3768: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3769: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3770: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3771: }
3772: }
1.145 raeburn 3773: }
3774: }
3775: }
3776: }
3777: }
3778: }
3779: return %spareid;
3780: }
3781:
3782: sub spares_row {
1.160.6.61 raeburn 3783: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 3784: my $css_class;
3785: my $numinrow = 4;
3786: my $itemcount = 1;
3787: my $datatable;
1.152 raeburn 3788: my %typetitles = &sparestype_titles();
3789: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3790: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3791: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3792: my ($othercontrol,$serverdom);
3793: if ($serverhome ne $server) {
3794: $serverdom = &Apache::lonnet::host_domain($serverhome);
3795: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3796: } else {
3797: $serverdom = &Apache::lonnet::host_domain($server);
3798: if ($serverdom ne $dom) {
3799: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3800: }
3801: }
3802: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 3803: my $checkednow;
3804: if (ref($curroffloadnow) eq 'HASH') {
3805: if ($curroffloadnow->{$server}) {
3806: $checkednow = ' checked="checked"';
3807: }
3808: }
1.145 raeburn 3809: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3810: $datatable .= '<tr'.$css_class.'>
3811: <td rowspan="2">
1.160.6.13 raeburn 3812: <span class="LC_nobreak">'.
3813: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 3814: ,'<b>'.$server.'</b>').'</span><br />'.
3815: '<span class="LC_nobreak">'."\n".
3816: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
3817: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 3818: "\n";
1.145 raeburn 3819: my (%current,%canselect);
1.152 raeburn 3820: my @choices =
3821: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3822: foreach my $type ('primary','default') {
3823: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3824: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3825: my @spares = @{$spareid->{$server}{$type}};
3826: if (@spares > 0) {
1.152 raeburn 3827: if ($othercontrol) {
3828: $current{$type} = join(', ',@spares);
3829: } else {
3830: $current{$type} .= '<table>';
3831: my $numspares = scalar(@spares);
3832: for (my $i=0; $i<@spares; $i++) {
3833: my $rem = $i%($numinrow);
3834: if ($rem == 0) {
3835: if ($i > 0) {
3836: $current{$type} .= '</tr>';
3837: }
3838: $current{$type} .= '<tr>';
1.145 raeburn 3839: }
1.152 raeburn 3840: $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'".');" /> '.
3841: $spareid->{$server}{$type}[$i].
3842: '</label></td>'."\n";
3843: }
3844: my $rem = @spares%($numinrow);
3845: my $colsleft = $numinrow - $rem;
3846: if ($colsleft > 1 ) {
3847: $current{$type} .= '<td colspan="'.$colsleft.
3848: '" class="LC_left_item">'.
3849: ' </td>';
3850: } elsif ($colsleft == 1) {
3851: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3852: }
1.152 raeburn 3853: $current{$type} .= '</tr></table>';
1.150 raeburn 3854: }
1.145 raeburn 3855: }
3856: }
3857: if ($current{$type} eq '') {
3858: $current{$type} = &mt('None specified');
3859: }
1.152 raeburn 3860: if ($othercontrol) {
3861: if ($type eq 'primary') {
3862: $canselect{$type} = $othercontrol;
3863: }
3864: } else {
3865: $canselect{$type} =
3866: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3867: '<select name="newspare_'.$type.'_'.$server.'" '.
3868: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3869: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3870: if (@choices > 0) {
3871: foreach my $lonhost (@choices) {
3872: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3873: }
3874: }
3875: $canselect{$type} .= '</select>'."\n";
3876: }
3877: } else {
3878: $current{$type} = &mt('Could not be determined');
3879: if ($type eq 'primary') {
3880: $canselect{$type} = $othercontrol;
3881: }
1.145 raeburn 3882: }
1.152 raeburn 3883: if ($type eq 'default') {
3884: $datatable .= '<tr'.$css_class.'>';
3885: }
3886: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3887: '<td>'.$current{$type}.'</td>'."\n".
3888: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3889: }
3890: $itemcount ++;
3891: }
3892: }
3893: $$rowtotal += $itemcount;
3894: return $datatable;
3895: }
3896:
1.152 raeburn 3897: sub possible_newspares {
3898: my ($server,$currspares,$serverhomes,$altids) = @_;
3899: my $serverhostname = &Apache::lonnet::hostname($server);
3900: my %excluded;
3901: if ($serverhostname ne '') {
3902: %excluded = (
3903: $serverhostname => 1,
3904: );
3905: }
3906: if (ref($currspares) eq 'HASH') {
3907: foreach my $type (keys(%{$currspares})) {
3908: if (ref($currspares->{$type}) eq 'ARRAY') {
3909: if (@{$currspares->{$type}} > 0) {
3910: foreach my $curr (@{$currspares->{$type}}) {
3911: my $hostname = &Apache::lonnet::hostname($curr);
3912: $excluded{$hostname} = 1;
3913: }
3914: }
3915: }
3916: }
3917: }
3918: my @choices;
3919: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3920: if (keys(%{$serverhomes}) > 1) {
3921: foreach my $name (sort(keys(%{$serverhomes}))) {
3922: unless ($excluded{$name}) {
3923: if (exists($altids->{$serverhomes->{$name}})) {
3924: push(@choices,$altids->{$serverhomes->{$name}});
3925: } else {
3926: push(@choices,$serverhomes->{$name});
1.145 raeburn 3927: }
3928: }
3929: }
3930: }
3931: }
1.152 raeburn 3932: return sort(@choices);
1.145 raeburn 3933: }
3934:
1.150 raeburn 3935: sub print_loadbalancing {
3936: my ($dom,$settings,$rowtotal) = @_;
3937: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3938: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3939: my $numinrow = 1;
3940: my $datatable;
3941: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3942: my (%currbalancer,%currtargets,%currrules,%existing);
3943: if (ref($settings) eq 'HASH') {
3944: %existing = %{$settings};
3945: }
3946: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3947: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3948: \%currtargets,\%currrules);
1.150 raeburn 3949: } else {
3950: return;
3951: }
3952: my ($othertitle,$usertypes,$types) =
3953: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3954: my $rownum = 8;
1.150 raeburn 3955: if (ref($types) eq 'ARRAY') {
3956: $rownum += scalar(@{$types});
3957: }
1.160.6.7 raeburn 3958: my @css_class = ('LC_odd_row','LC_even_row');
3959: my $balnum = 0;
3960: my $islast;
3961: my (@toshow,$disabledtext);
3962: if (keys(%currbalancer) > 0) {
3963: @toshow = sort(keys(%currbalancer));
3964: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3965: push(@toshow,'');
3966: }
3967: } else {
3968: @toshow = ('');
3969: $disabledtext = &mt('No existing load balancer');
3970: }
3971: foreach my $lonhost (@toshow) {
3972: if ($balnum == scalar(@toshow)-1) {
3973: $islast = 1;
3974: } else {
3975: $islast = 0;
3976: }
3977: my $cssidx = $balnum%2;
3978: my $targets_div_style = 'display: none';
3979: my $disabled_div_style = 'display: block';
3980: my $homedom_div_style = 'display: none';
3981: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3982: '<td rowspan="'.$rownum.'" valign="top">'.
3983: '<p>';
3984: if ($lonhost eq '') {
3985: $datatable .= '<span class="LC_nobreak">';
3986: if (keys(%currbalancer) > 0) {
3987: $datatable .= &mt('Add balancer:');
3988: } else {
3989: $datatable .= &mt('Enable balancer:');
3990: }
3991: $datatable .= ' '.
3992: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3993: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3994: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3995: '<option value="" selected="selected">'.&mt('None').
3996: '</option>'."\n";
3997: foreach my $server (sort(keys(%servers))) {
3998: next if ($currbalancer{$server});
3999: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4000: }
4001: $datatable .=
4002: '</select>'."\n".
4003: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4004: } else {
4005: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4006: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4007: &mt('Stop balancing').'</label>'.
4008: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4009: $targets_div_style = 'display: block';
4010: $disabled_div_style = 'display: none';
4011: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4012: $homedom_div_style = 'display: block';
4013: }
4014: }
4015: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4016: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4017: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4018: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4019: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4020: my @sparestypes = ('primary','default');
4021: my %typetitles = &sparestype_titles();
1.160.6.76! raeburn 4022: my %hostherechecked = (
! 4023: no => ' checked="checked"',
! 4024: );
1.160.6.7 raeburn 4025: foreach my $sparetype (@sparestypes) {
4026: my $targettable;
4027: for (my $i=0; $i<$numspares; $i++) {
4028: my $checked;
4029: if (ref($currtargets{$lonhost}) eq 'HASH') {
4030: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4031: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4032: $checked = ' checked="checked"';
4033: }
4034: }
4035: }
4036: my ($chkboxval,$disabled);
4037: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4038: $chkboxval = $spares[$i];
4039: }
4040: if (exists($currbalancer{$spares[$i]})) {
4041: $disabled = ' disabled="disabled"';
4042: }
4043: $targettable .=
1.160.6.55 raeburn 4044: '<td><span class="LC_nobreak"><label>'.
4045: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4046: $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 4047: '</span></label></span></td>';
1.160.6.7 raeburn 4048: my $rem = $i%($numinrow);
4049: if ($rem == 0) {
4050: if (($i > 0) && ($i < $numspares-1)) {
4051: $targettable .= '</tr>';
4052: }
4053: if ($i < $numspares-1) {
4054: $targettable .= '<tr>';
1.150 raeburn 4055: }
4056: }
4057: }
1.160.6.7 raeburn 4058: if ($targettable ne '') {
4059: my $rem = $numspares%($numinrow);
4060: my $colsleft = $numinrow - $rem;
4061: if ($colsleft > 1 ) {
4062: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4063: ' </td>';
4064: } elsif ($colsleft == 1) {
4065: $targettable .= '<td class="LC_left_item"> </td>';
4066: }
4067: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4068: '<table><tr>'.$targettable.'</tr></table><br />';
4069: }
1.160.6.76! raeburn 4070: $hostherechecked{$sparetype} = '';
! 4071: if (ref($currtargets{$lonhost}) eq 'HASH') {
! 4072: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
! 4073: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
! 4074: $hostherechecked{$sparetype} = ' checked="checked"';
! 4075: $hostherechecked{'no'} = '';
! 4076: }
! 4077: }
! 4078: }
! 4079: }
! 4080: $datatable .= &mt('Hosting on balancer itself').'<br />'.
! 4081: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
! 4082: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
! 4083: foreach my $sparetype (@sparestypes) {
! 4084: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
! 4085: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
! 4086: '</i></label><br />';
1.160.6.7 raeburn 4087: }
4088: $datatable .= '</div></td></tr>'.
4089: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4090: $othertitle,$usertypes,$types,\%servers,
4091: \%currbalancer,$lonhost,
4092: $targets_div_style,$homedom_div_style,
4093: $css_class[$cssidx],$balnum,$islast);
4094: $$rowtotal += $rownum;
4095: $balnum ++;
4096: }
4097: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4098: return $datatable;
4099: }
4100:
4101: sub get_loadbalancers_config {
4102: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4103: return unless ((ref($servers) eq 'HASH') &&
4104: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4105: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4106: if (keys(%{$existing}) > 0) {
4107: my $oldlonhost;
4108: foreach my $key (sort(keys(%{$existing}))) {
4109: if ($key eq 'lonhost') {
4110: $oldlonhost = $existing->{'lonhost'};
4111: $currbalancer->{$oldlonhost} = 1;
4112: } elsif ($key eq 'targets') {
4113: if ($oldlonhost) {
4114: $currtargets->{$oldlonhost} = $existing->{'targets'};
4115: }
4116: } elsif ($key eq 'rules') {
4117: if ($oldlonhost) {
4118: $currrules->{$oldlonhost} = $existing->{'rules'};
4119: }
4120: } elsif (ref($existing->{$key}) eq 'HASH') {
4121: $currbalancer->{$key} = 1;
4122: $currtargets->{$key} = $existing->{$key}{'targets'};
4123: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4124: }
4125: }
1.160.6.7 raeburn 4126: } else {
4127: my ($balancerref,$targetsref) =
4128: &Apache::lonnet::get_lonbalancer_config($servers);
4129: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4130: foreach my $server (sort(keys(%{$balancerref}))) {
4131: $currbalancer->{$server} = 1;
4132: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4133: }
4134: }
4135: }
1.160.6.7 raeburn 4136: return;
1.150 raeburn 4137: }
4138:
4139: sub loadbalancing_rules {
4140: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4141: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4142: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4143: my $output;
1.160.6.7 raeburn 4144: my $num = 0;
4145: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4146: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4147: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4148: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4149: $num ++;
1.150 raeburn 4150: my $current;
4151: if (ref($currrules) eq 'HASH') {
4152: $current = $currrules->{$type};
4153: }
1.160.6.55 raeburn 4154: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4155: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4156: $current = '';
4157: }
4158: }
4159: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4160: $servers,$currbalancer,$lonhost,$dom,
4161: $targets_div_style,$homedom_div_style,
4162: $css_class,$balnum,$num,$islast);
1.150 raeburn 4163: }
4164: }
4165: return $output;
4166: }
4167:
4168: sub loadbalancing_titles {
4169: my ($dom,$intdom,$usertypes,$types) = @_;
4170: my %othertypes = (
4171: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4172: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4173: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4174: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4175: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4176: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4177: );
1.160.6.26 raeburn 4178: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4179: if (ref($types) eq 'ARRAY') {
4180: unshift(@alltypes,@{$types},'default');
4181: }
4182: my %titles;
4183: foreach my $type (@alltypes) {
4184: if ($type =~ /^_LC_/) {
4185: $titles{$type} = $othertypes{$type};
4186: } elsif ($type eq 'default') {
4187: $titles{$type} = &mt('All users from [_1]',$dom);
4188: if (ref($types) eq 'ARRAY') {
4189: if (@{$types} > 0) {
4190: $titles{$type} = &mt('Other users from [_1]',$dom);
4191: }
4192: }
4193: } elsif (ref($usertypes) eq 'HASH') {
4194: $titles{$type} = $usertypes->{$type};
4195: }
4196: }
4197: return (\@alltypes,\%othertypes,\%titles);
4198: }
4199:
4200: sub loadbalance_rule_row {
1.160.6.7 raeburn 4201: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4202: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4203: my @rulenames;
1.150 raeburn 4204: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4205: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4206: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4207: } else {
1.160.6.26 raeburn 4208: @rulenames = ('default','homeserver');
4209: if ($type eq '_LC_external') {
4210: push(@rulenames,'externalbalancer');
4211: } else {
4212: push(@rulenames,'specific');
4213: }
4214: push(@rulenames,'none');
1.150 raeburn 4215: }
4216: my $style = $targets_div_style;
1.160.6.55 raeburn 4217: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4218: $style = $homedom_div_style;
4219: }
1.160.6.7 raeburn 4220: my $space;
4221: if ($islast && $num == 1) {
4222: $space = '<div display="inline-block"> </div>';
4223: }
4224: my $output =
4225: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4226: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4227: '<td valaign="top">'.$space.
4228: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4229: for (my $i=0; $i<@rulenames; $i++) {
4230: my $rule = $rulenames[$i];
4231: my ($checked,$extra);
4232: if ($rulenames[$i] eq 'default') {
4233: $rule = '';
4234: }
4235: if ($rulenames[$i] eq 'specific') {
4236: if (ref($servers) eq 'HASH') {
4237: my $default;
4238: if (($current ne '') && (exists($servers->{$current}))) {
4239: $checked = ' checked="checked"';
4240: }
4241: unless ($checked) {
4242: $default = ' selected="selected"';
4243: }
1.160.6.7 raeburn 4244: $extra =
4245: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4246: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4247: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4248: '<option value=""'.$default.'></option>'."\n";
4249: foreach my $server (sort(keys(%{$servers}))) {
4250: if (ref($currbalancer) eq 'HASH') {
4251: next if (exists($currbalancer->{$server}));
4252: }
1.150 raeburn 4253: my $selected;
1.160.6.7 raeburn 4254: if ($server eq $current) {
1.150 raeburn 4255: $selected = ' selected="selected"';
4256: }
1.160.6.7 raeburn 4257: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4258: }
4259: $extra .= '</select>';
4260: }
4261: } elsif ($rule eq $current) {
4262: $checked = ' checked="checked"';
4263: }
4264: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4265: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4266: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4267: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4268: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4269: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4270: $output .= $ruletitles{'particular'};
4271: } else {
4272: $output .= $ruletitles{$rulenames[$i]};
4273: }
4274: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4275: }
4276: $output .= '</div></td></tr>'."\n";
4277: return $output;
4278: }
4279:
4280: sub offloadtype_text {
4281: my %ruletitles = &Apache::lonlocal::texthash (
4282: 'default' => 'Offloads to default destinations',
4283: 'homeserver' => "Offloads to user's home server",
4284: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4285: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4286: 'none' => 'No offload',
1.160.6.26 raeburn 4287: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4288: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4289: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4290: );
4291: return %ruletitles;
4292: }
4293:
4294: sub sparestype_titles {
4295: my %typestitles = &Apache::lonlocal::texthash (
4296: 'primary' => 'primary',
4297: 'default' => 'default',
4298: );
4299: return %typestitles;
4300: }
4301:
1.28 raeburn 4302: sub contact_titles {
4303: my %titles = &Apache::lonlocal::texthash (
4304: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4305: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4306: 'errormail' => 'Error reports to be e-mailed to',
4307: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4308: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4309: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4310: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4311: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4312: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4313: );
4314: my %short_titles = &Apache::lonlocal::texthash (
4315: adminemail => 'Admin E-mail address',
4316: supportemail => 'Support E-mail',
4317: );
4318: return (\%titles,\%short_titles);
4319: }
4320:
1.72 raeburn 4321: sub tool_titles {
4322: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4323: aboutme => 'Personal web page',
1.86 raeburn 4324: blog => 'Blog',
1.160.6.4 raeburn 4325: webdav => 'WebDAV',
1.86 raeburn 4326: portfolio => 'Portfolio',
1.88 bisitz 4327: official => 'Official courses (with institutional codes)',
4328: unofficial => 'Unofficial courses',
1.98 raeburn 4329: community => 'Communities',
1.160.6.30 raeburn 4330: textbook => 'Textbook courses',
1.86 raeburn 4331: );
1.72 raeburn 4332: return %titles;
4333: }
4334:
1.101 raeburn 4335: sub courserequest_titles {
4336: my %titles = &Apache::lonlocal::texthash (
4337: official => 'Official',
4338: unofficial => 'Unofficial',
4339: community => 'Communities',
1.160.6.30 raeburn 4340: textbook => 'Textbook',
1.101 raeburn 4341: norequest => 'Not allowed',
1.104 raeburn 4342: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4343: validate => 'With validation',
4344: autolimit => 'Numerical limit',
1.103 raeburn 4345: unlimited => '(blank for unlimited)',
1.101 raeburn 4346: );
4347: return %titles;
4348: }
4349:
1.160.6.5 raeburn 4350: sub authorrequest_titles {
4351: my %titles = &Apache::lonlocal::texthash (
4352: norequest => 'Not allowed',
4353: approval => 'Approval by Dom. Coord.',
4354: automatic => 'Automatic approval',
4355: );
4356: return %titles;
4357: }
4358:
1.101 raeburn 4359: sub courserequest_conditions {
4360: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4361: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4362: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4363: );
4364: return %conditions;
4365: }
4366:
4367:
1.27 raeburn 4368: sub print_usercreation {
1.30 raeburn 4369: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4370: my $numinrow = 4;
1.28 raeburn 4371: my $datatable;
4372: if ($position eq 'top') {
1.30 raeburn 4373: $$rowtotal ++;
1.34 raeburn 4374: my $rowcount = 0;
1.32 raeburn 4375: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4376: if (ref($rules) eq 'HASH') {
4377: if (keys(%{$rules}) > 0) {
1.32 raeburn 4378: $datatable .= &user_formats_row('username',$settings,$rules,
4379: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4380: $$rowtotal ++;
1.32 raeburn 4381: $rowcount ++;
4382: }
4383: }
4384: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4385: if (ref($idrules) eq 'HASH') {
4386: if (keys(%{$idrules}) > 0) {
4387: $datatable .= &user_formats_row('id',$settings,$idrules,
4388: $idruleorder,$numinrow,$rowcount);
4389: $$rowtotal ++;
4390: $rowcount ++;
1.28 raeburn 4391: }
4392: }
1.39 raeburn 4393: if ($rowcount == 0) {
4394: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4395: $$rowtotal ++;
4396: $rowcount ++;
4397: }
1.34 raeburn 4398: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4399: my @creators = ('author','course','requestcrs');
1.37 raeburn 4400: my ($rules,$ruleorder) =
4401: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4402: my %lt = &usercreation_types();
4403: my %checked;
4404: if (ref($settings) eq 'HASH') {
4405: if (ref($settings->{'cancreate'}) eq 'HASH') {
4406: foreach my $item (@creators) {
4407: $checked{$item} = $settings->{'cancreate'}{$item};
4408: }
4409: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4410: foreach my $item (@creators) {
4411: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4412: $checked{$item} = 'none';
4413: }
4414: }
4415: }
4416: }
4417: my $rownum = 0;
4418: foreach my $item (@creators) {
4419: $rownum ++;
1.160.6.34 raeburn 4420: if ($checked{$item} eq '') {
4421: $checked{$item} = 'any';
1.34 raeburn 4422: }
4423: my $css_class;
4424: if ($rownum%2) {
4425: $css_class = '';
4426: } else {
4427: $css_class = ' class="LC_odd_row" ';
4428: }
4429: $datatable .= '<tr'.$css_class.'>'.
4430: '<td><span class="LC_nobreak">'.$lt{$item}.
4431: '</span></td><td align="right">';
1.160.6.34 raeburn 4432: my @options = ('any');
4433: if (ref($rules) eq 'HASH') {
4434: if (keys(%{$rules}) > 0) {
4435: push(@options,('official','unofficial'));
1.37 raeburn 4436: }
4437: }
1.160.6.34 raeburn 4438: push(@options,'none');
1.37 raeburn 4439: foreach my $option (@options) {
1.50 raeburn 4440: my $type = 'radio';
1.34 raeburn 4441: my $check = ' ';
1.160.6.34 raeburn 4442: if ($checked{$item} eq $option) {
4443: $check = ' checked="checked" ';
1.34 raeburn 4444: }
4445: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4446: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4447: $item.'" value="'.$option.'"'.$check.'/> '.
4448: $lt{$option}.'</label> </span>';
4449: }
4450: $datatable .= '</td></tr>';
4451: }
1.28 raeburn 4452: } else {
4453: my @contexts = ('author','course','domain');
4454: my @authtypes = ('int','krb4','krb5','loc');
4455: my %checked;
4456: if (ref($settings) eq 'HASH') {
4457: if (ref($settings->{'authtypes'}) eq 'HASH') {
4458: foreach my $item (@contexts) {
4459: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4460: foreach my $auth (@authtypes) {
4461: if ($settings->{'authtypes'}{$item}{$auth}) {
4462: $checked{$item}{$auth} = ' checked="checked" ';
4463: }
4464: }
4465: }
4466: }
1.27 raeburn 4467: }
1.35 raeburn 4468: } else {
4469: foreach my $item (@contexts) {
1.36 raeburn 4470: foreach my $auth (@authtypes) {
1.35 raeburn 4471: $checked{$item}{$auth} = ' checked="checked" ';
4472: }
4473: }
1.27 raeburn 4474: }
1.28 raeburn 4475: my %title = &context_names();
4476: my %authname = &authtype_names();
4477: my $rownum = 0;
4478: my $css_class;
4479: foreach my $item (@contexts) {
4480: if ($rownum%2) {
4481: $css_class = '';
4482: } else {
4483: $css_class = ' class="LC_odd_row" ';
4484: }
1.30 raeburn 4485: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4486: '<td>'.$title{$item}.
4487: '</td><td class="LC_left_item">'.
4488: '<span class="LC_nobreak">';
4489: foreach my $auth (@authtypes) {
4490: $datatable .= '<label>'.
4491: '<input type="checkbox" name="'.$item.'_auth" '.
4492: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4493: $authname{$auth}.'</label> ';
4494: }
4495: $datatable .= '</span></td></tr>';
4496: $rownum ++;
1.27 raeburn 4497: }
1.30 raeburn 4498: $$rowtotal += $rownum;
1.27 raeburn 4499: }
4500: return $datatable;
4501: }
4502:
1.160.6.34 raeburn 4503: sub print_selfcreation {
4504: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4505: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4506: if (ref($settings) eq 'HASH') {
4507: if (ref($settings->{'cancreate'}) eq 'HASH') {
4508: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4509: if (ref($createsettings) eq 'HASH') {
4510: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4511: @selfcreate = @{$createsettings->{'selfcreate'}};
4512: } elsif ($createsettings->{'selfcreate'} ne '') {
4513: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4514: @selfcreate = ('email','login','sso');
4515: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4516: @selfcreate = ($createsettings->{'selfcreate'});
4517: }
4518: }
4519: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4520: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4521: }
4522: }
4523: }
4524: }
4525: my %radiohash;
4526: my $numinrow = 4;
4527: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4528: if ($position eq 'top') {
4529: my %choices = &Apache::lonlocal::texthash (
4530: cancreate_login => 'Institutional Login',
4531: cancreate_sso => 'Institutional Single Sign On',
4532: );
4533: my @toggles = sort(keys(%choices));
4534: my %defaultchecked = (
4535: 'cancreate_login' => 'off',
4536: 'cancreate_sso' => 'off',
4537: );
1.160.6.35 raeburn 4538: my ($onclick,$itemcount);
1.160.6.34 raeburn 4539: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4540: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4541: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4542:
1.160.6.34 raeburn 4543: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4544:
4545: if (ref($usertypes) eq 'HASH') {
4546: if (keys(%{$usertypes}) > 0) {
4547: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4548: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4549: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4550: $$rowtotal ++;
4551: }
4552: }
1.160.6.44 raeburn 4553: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4554: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4555: $fieldtitles{'inststatus'} = &mt('Institutional status');
4556: my $rem;
4557: my $numperrow = 2;
4558: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4559: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4560: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4561: '<td class="LC_left_item">'."\n".
4562: '<table><tr><td>'."\n";
4563: for (my $i=0; $i<@fields; $i++) {
4564: $rem = $i%($numperrow);
4565: if ($rem == 0) {
4566: if ($i > 0) {
4567: $datatable .= '</tr>';
4568: }
4569: $datatable .= '<tr>';
4570: }
4571: my $currval;
1.160.6.51 raeburn 4572: if (ref($createsettings) eq 'HASH') {
4573: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4574: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4575: }
1.160.6.44 raeburn 4576: }
4577: $datatable .= '<td class="LC_left_item">'.
4578: '<span class="LC_nobreak">'.
4579: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4580: 'value="'.$currval.'" size="10" /> '.
4581: $fieldtitles{$fields[$i]}.'</span></td>';
4582: }
4583: my $colsleft = $numperrow - $rem;
4584: if ($colsleft > 1 ) {
4585: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4586: ' </td>';
4587: } elsif ($colsleft == 1) {
4588: $datatable .= '<td class="LC_left_item"> </td>';
4589: }
4590: $datatable .= '</tr></table></td></tr>';
4591: $$rowtotal ++;
1.160.6.34 raeburn 4592: } elsif ($position eq 'middle') {
4593: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4594: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4595: $usertypes->{'default'} = $othertitle;
4596: if (ref($types) eq 'ARRAY') {
4597: push(@{$types},'default');
4598: $usertypes->{'default'} = $othertitle;
4599: foreach my $status (@{$types}) {
4600: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4601: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4602: $$rowtotal ++;
1.160.6.34 raeburn 4603: }
4604: }
4605: } else {
1.160.6.40 raeburn 4606: my %choices = &Apache::lonlocal::texthash (
4607: cancreate_email => 'E-mail address as username',
4608: );
4609: my @toggles = sort(keys(%choices));
4610: my %defaultchecked = (
4611: 'cancreate_email' => 'off',
4612: );
4613: my $itemcount = 0;
4614: my $display = 'none';
4615: if (grep(/^\Qemail\E$/,@selfcreate)) {
4616: $display = 'block';
4617: }
4618: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4619: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4620: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4621: my $usertypes = {};
4622: my $order = [];
4623: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4624: $usertypes = $domdefaults{'inststatustypes'};
4625: $order = $domdefaults{'inststatusguest'};
4626: }
4627: if (ref($order) eq 'ARRAY') {
4628: push(@{$order},'default');
4629: if (@{$order} > 1) {
4630: $usertypes->{'default'} = &mt('Other users');
4631: $additional .= '<table><tr>';
4632: foreach my $status (@{$order}) {
4633: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4634: }
4635: $additional .= '</tr><tr>';
4636: foreach my $status (@{$order}) {
4637: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4638: }
1.160.6.40 raeburn 4639: $additional .= '</tr></table>';
1.160.6.34 raeburn 4640: } else {
1.160.6.40 raeburn 4641: $usertypes->{'default'} = &mt('All users');
4642: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4643: }
4644: }
1.160.6.40 raeburn 4645: $additional .= '</div>'."\n";
4646:
4647: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4648: \%choices,$$rowtotal,$onclick,$additional);
4649: $$rowtotal ++;
1.160.6.40 raeburn 4650: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4651: $$rowtotal ++;
1.160.6.35 raeburn 4652: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4653: $numinrow = 1;
1.160.6.40 raeburn 4654: if (ref($order) eq 'ARRAY') {
4655: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4656: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4657: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4658: $$rowtotal ++;
4659: }
4660: }
1.160.6.34 raeburn 4661: my ($emailrules,$emailruleorder) =
4662: &Apache::lonnet::inst_userrules($dom,'email');
4663: if (ref($emailrules) eq 'HASH') {
4664: if (keys(%{$emailrules}) > 0) {
4665: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4666: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4667: $$rowtotal ++;
4668: }
4669: }
1.160.6.35 raeburn 4670: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4671: }
4672: return $datatable;
4673: }
4674:
1.160.6.40 raeburn 4675: sub email_as_username {
4676: my ($rowtotal,$processing,$type) = @_;
4677: my %choices =
4678: &Apache::lonlocal::texthash (
4679: automatic => 'Automatic approval',
4680: approval => 'Queued for approval',
4681: );
4682: my $output;
4683: foreach my $option ('automatic','approval') {
4684: my $checked;
4685: if (ref($processing) eq 'HASH') {
4686: if ($type eq '') {
4687: if (!exists($processing->{'default'})) {
4688: if ($option eq 'automatic') {
4689: $checked = ' checked="checked"';
4690: }
4691: } else {
4692: if ($processing->{'default'} eq $option) {
4693: $checked = ' checked="checked"';
4694: }
4695: }
4696: } else {
4697: if (!exists($processing->{$type})) {
4698: if ($option eq 'automatic') {
4699: $checked = ' checked="checked"';
4700: }
4701: } else {
4702: if ($processing->{$type} eq $option) {
4703: $checked = ' checked="checked"';
4704: }
4705: }
4706: }
4707: } elsif ($option eq 'automatic') {
4708: $checked = ' checked="checked"';
4709: }
4710: my $name = 'cancreate_emailprocess';
4711: if (($type ne '') && ($type ne 'default')) {
4712: $name .= '_'.$type;
4713: }
4714: $output .= '<span class="LC_nobreak"><label>'.
4715: '<input type="radio" name="'.$name.'"'.
4716: $checked.' value="'.$option.'" />'.
4717: $choices{$option}.'</label></span>';
4718: if ($type eq '') {
4719: $output .= ' ';
4720: } else {
4721: $output .= '<br />';
4722: }
4723: }
4724: $$rowtotal ++;
4725: return $output;
4726: }
4727:
1.160.6.5 raeburn 4728: sub captcha_choice {
4729: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 4730: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4731: $vertext,$currver);
1.160.6.5 raeburn 4732: my %lt = &captcha_phrases();
4733: $keyentry = 'hidden';
4734: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4735: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4736: } elsif ($context eq 'login') {
4737: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4738: }
4739: if (ref($settings) eq 'HASH') {
4740: if ($settings->{'captcha'}) {
4741: $checked{$settings->{'captcha'}} = ' checked="checked"';
4742: } else {
4743: $checked{'original'} = ' checked="checked"';
4744: }
4745: if ($settings->{'captcha'} eq 'recaptcha') {
4746: $pubtext = $lt{'pub'};
4747: $privtext = $lt{'priv'};
4748: $keyentry = 'text';
1.160.6.69 raeburn 4749: $vertext = $lt{'ver'};
4750: $currver = $settings->{'recaptchaversion'};
4751: if ($currver ne '2') {
4752: $currver = 1;
4753: }
1.160.6.5 raeburn 4754: }
4755: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4756: $currpub = $settings->{'recaptchakeys'}{'public'};
4757: $currpriv = $settings->{'recaptchakeys'}{'private'};
4758: }
4759: } else {
4760: $checked{'original'} = ' checked="checked"';
4761: }
4762: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4763: my $output = '<tr'.$css_class.'>'.
4764: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4765: '<table><tr><td>'."\n";
4766: foreach my $option ('original','recaptcha','notused') {
4767: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4768: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4769: $lt{$option}.'</label></span>';
4770: unless ($option eq 'notused') {
4771: $output .= (' 'x2)."\n";
4772: }
4773: }
4774: #
4775: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4776: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4777: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4778: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4779: #
4780: $output .= '</td></tr>'."\n".
4781: '<tr><td>'."\n".
4782: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4783: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4784: $currpub.'" size="40" /></span><br />'."\n".
4785: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4786: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 4787: $currpriv.'" size="40" /></span><br />'.
4788: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
4789: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
4790: $currver.'" size="3" /></span><br />'.
4791: '</td></tr></table>'."\n".
1.160.6.5 raeburn 4792: '</td></tr>';
4793: return $output;
4794: }
4795:
1.32 raeburn 4796: sub user_formats_row {
4797: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4798: my $output;
4799: my %text = (
4800: 'username' => 'new usernames',
4801: 'id' => 'IDs',
1.45 raeburn 4802: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4803: );
4804: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4805: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4806: '<td><span class="LC_nobreak">';
4807: if ($type eq 'email') {
4808: $output .= &mt("Formats disallowed for $text{$type}: ");
4809: } else {
4810: $output .= &mt("Format rules to check for $text{$type}: ");
4811: }
4812: $output .= '</span></td>'.
4813: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4814: my $rem;
4815: if (ref($ruleorder) eq 'ARRAY') {
4816: for (my $i=0; $i<@{$ruleorder}; $i++) {
4817: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4818: my $rem = $i%($numinrow);
4819: if ($rem == 0) {
4820: if ($i > 0) {
4821: $output .= '</tr>';
4822: }
4823: $output .= '<tr>';
4824: }
4825: my $check = ' ';
1.39 raeburn 4826: if (ref($settings) eq 'HASH') {
4827: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4828: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4829: $check = ' checked="checked" ';
4830: }
1.27 raeburn 4831: }
4832: }
4833: $output .= '<td class="LC_left_item">'.
4834: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4835: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4836: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4837: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4838: }
4839: }
4840: $rem = @{$ruleorder}%($numinrow);
4841: }
4842: my $colsleft = $numinrow - $rem;
4843: if ($colsleft > 1 ) {
4844: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4845: ' </td>';
4846: } elsif ($colsleft == 1) {
4847: $output .= '<td class="LC_left_item"> </td>';
4848: }
4849: $output .= '</tr></table></td></tr>';
4850: return $output;
4851: }
4852:
1.34 raeburn 4853: sub usercreation_types {
4854: my %lt = &Apache::lonlocal::texthash (
4855: author => 'When adding a co-author',
4856: course => 'When adding a user to a course',
1.100 raeburn 4857: requestcrs => 'When requesting a course',
1.34 raeburn 4858: any => 'Any',
4859: official => 'Institutional only ',
4860: unofficial => 'Non-institutional only',
4861: none => 'None',
4862: );
4863: return %lt;
1.48 raeburn 4864: }
1.34 raeburn 4865:
1.160.6.34 raeburn 4866: sub selfcreation_types {
4867: my %lt = &Apache::lonlocal::texthash (
4868: selfcreate => 'User creates own account',
4869: any => 'Any',
4870: official => 'Institutional only ',
4871: unofficial => 'Non-institutional only',
4872: email => 'E-mail address',
4873: login => 'Institutional Login',
4874: sso => 'SSO',
4875: );
4876: }
4877:
1.28 raeburn 4878: sub authtype_names {
4879: my %lt = &Apache::lonlocal::texthash(
4880: int => 'Internal',
4881: krb4 => 'Kerberos 4',
4882: krb5 => 'Kerberos 5',
4883: loc => 'Local',
4884: );
4885: return %lt;
4886: }
4887:
4888: sub context_names {
4889: my %context_title = &Apache::lonlocal::texthash(
4890: author => 'Creating users when an Author',
4891: course => 'Creating users when in a course',
4892: domain => 'Creating users when a Domain Coordinator',
4893: );
4894: return %context_title;
4895: }
4896:
1.33 raeburn 4897: sub print_usermodification {
4898: my ($position,$dom,$settings,$rowtotal) = @_;
4899: my $numinrow = 4;
4900: my ($context,$datatable,$rowcount);
4901: if ($position eq 'top') {
4902: $rowcount = 0;
4903: $context = 'author';
4904: foreach my $role ('ca','aa') {
4905: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4906: $numinrow,$rowcount);
4907: $$rowtotal ++;
4908: $rowcount ++;
4909: }
1.160.6.37 raeburn 4910: } elsif ($position eq 'bottom') {
1.33 raeburn 4911: $context = 'course';
4912: $rowcount = 0;
4913: foreach my $role ('st','ep','ta','in','cr') {
4914: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4915: $numinrow,$rowcount);
4916: $$rowtotal ++;
4917: $rowcount ++;
4918: }
4919: }
4920: return $datatable;
4921: }
4922:
1.43 raeburn 4923: sub print_defaults {
1.160.6.40 raeburn 4924: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4925: my $rownum = 0;
4926: my ($datatable,$css_class);
1.160.6.40 raeburn 4927: if ($position eq 'top') {
4928: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4929: 'datelocale_def','portal_def');
4930: my %defaults;
4931: if (ref($settings) eq 'HASH') {
4932: %defaults = %{$settings};
1.43 raeburn 4933: } else {
1.160.6.40 raeburn 4934: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4935: foreach my $item (@items) {
4936: $defaults{$item} = $domdefaults{$item};
4937: }
1.43 raeburn 4938: }
1.160.6.40 raeburn 4939: my $titles = &defaults_titles($dom);
4940: foreach my $item (@items) {
4941: if ($rownum%2) {
4942: $css_class = '';
4943: } else {
4944: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4945: }
1.160.6.40 raeburn 4946: $datatable .= '<tr'.$css_class.'>'.
4947: '<td><span class="LC_nobreak">'.$titles->{$item}.
4948: '</span></td><td class="LC_right_item" colspan="3">';
4949: if ($item eq 'auth_def') {
4950: my @authtypes = ('internal','krb4','krb5','localauth');
4951: my %shortauth = (
4952: internal => 'int',
4953: krb4 => 'krb4',
4954: krb5 => 'krb5',
4955: localauth => 'loc'
4956: );
4957: my %authnames = &authtype_names();
4958: foreach my $auth (@authtypes) {
4959: my $checked = ' ';
4960: if ($defaults{$item} eq $auth) {
4961: $checked = ' checked="checked" ';
4962: }
4963: $datatable .= '<label><input type="radio" name="'.$item.
4964: '" value="'.$auth.'"'.$checked.'/>'.
4965: $authnames{$shortauth{$auth}}.'</label> ';
4966: }
4967: } elsif ($item eq 'timezone_def') {
4968: my $includeempty = 1;
4969: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4970: } elsif ($item eq 'datelocale_def') {
4971: my $includeempty = 1;
4972: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4973: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 4974: my $includeempty = 1;
4975: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 4976: } else {
4977: my $size;
4978: if ($item eq 'portal_def') {
4979: $size = ' size="25"';
4980: }
4981: $datatable .= '<input type="text" name="'.$item.'" value="'.
4982: $defaults{$item}.'"'.$size.' />';
4983: }
4984: $datatable .= '</td></tr>';
4985: $rownum ++;
4986: }
4987: } else {
4988: my (%defaults);
4989: if (ref($settings) eq 'HASH') {
4990: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4991: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4992: my $maxnum = @{$settings->{'inststatusorder'}};
4993: for (my $i=0; $i<$maxnum; $i++) {
4994: $css_class = $rownum%2?' class="LC_odd_row"':'';
4995: my $item = $settings->{'inststatusorder'}->[$i];
4996: my $title = $settings->{'inststatustypes'}->{$item};
4997: my $guestok;
4998: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4999: $guestok = 1;
5000: }
5001: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5002: $datatable .= '<tr'.$css_class.'>'.
5003: '<td><span class="LC_nobreak">'.
5004: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5005: for (my $k=0; $k<=$maxnum; $k++) {
5006: my $vpos = $k+1;
5007: my $selstr;
5008: if ($k == $i) {
5009: $selstr = ' selected="selected" ';
5010: }
5011: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5012: }
5013: my ($checkedon,$checkedoff);
5014: $checkedoff = ' checked="checked"';
5015: if ($guestok) {
5016: $checkedon = $checkedoff;
5017: $checkedoff = '';
5018: }
5019: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5020: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5021: &mt('delete').'</span></td>'.
5022: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5023: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5024: '</span></td>'.
5025: '<td class="LC_right_item"><span class="LC_nobreak">'.
5026: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5027: &mt('Yes').'</label>'.(' 'x2).
5028: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5029: &mt('No').'</label></span></td></tr>';
5030: }
5031: $css_class = $rownum%2?' class="LC_odd_row"':'';
5032: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5033: $datatable .= '<tr '.$css_class.'>'.
5034: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5035: for (my $k=0; $k<=$maxnum; $k++) {
5036: my $vpos = $k+1;
5037: my $selstr;
5038: if ($k == $maxnum) {
5039: $selstr = ' selected="selected" ';
5040: }
5041: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5042: }
5043: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5044: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5045: ' '.&mt('(new)').
5046: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5047: &mt('Name displayed:').
5048: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5049: '<td class="LC_right_item"><span class="LC_nobreak">'.
5050: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5051: &mt('Yes').'</label>'.(' 'x2).
5052: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5053: &mt('No').'</label></span></td></tr>';
5054: '</tr>'."\n";
5055: $rownum ++;
1.141 raeburn 5056: }
1.43 raeburn 5057: }
5058: }
5059: $$rowtotal += $rownum;
5060: return $datatable;
5061: }
5062:
1.160.6.5 raeburn 5063: sub get_languages_hash {
5064: my %langchoices;
5065: foreach my $id (&Apache::loncommon::languageids()) {
5066: my $code = &Apache::loncommon::supportedlanguagecode($id);
5067: if ($code ne '') {
5068: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5069: }
5070: }
5071: return %langchoices;
5072: }
5073:
1.43 raeburn 5074: sub defaults_titles {
1.141 raeburn 5075: my ($dom) = @_;
1.43 raeburn 5076: my %titles = &Apache::lonlocal::texthash (
5077: 'auth_def' => 'Default authentication type',
5078: 'auth_arg_def' => 'Default authentication argument',
5079: 'lang_def' => 'Default language',
1.54 raeburn 5080: 'timezone_def' => 'Default timezone',
1.68 raeburn 5081: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5082: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5083: );
1.141 raeburn 5084: if ($dom) {
5085: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5086: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5087: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5088: $protocol = 'http' if ($protocol ne 'https');
5089: if ($uint_dom) {
5090: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5091: $uint_dom);
5092: }
5093: }
1.43 raeburn 5094: return (\%titles);
5095: }
5096:
1.46 raeburn 5097: sub print_scantronformat {
5098: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5099: my $itemcount = 1;
1.60 raeburn 5100: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5101: %confhash);
1.46 raeburn 5102: my $switchserver = &check_switchserver($dom,$confname);
5103: my %lt = &Apache::lonlocal::texthash (
1.95 www 5104: default => 'Default bubblesheet format file error',
5105: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5106: );
5107: my %scantronfiles = (
5108: default => 'default.tab',
5109: custom => 'custom.tab',
5110: );
5111: foreach my $key (keys(%scantronfiles)) {
5112: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5113: .$scantronfiles{$key};
5114: }
5115: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5116: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5117: if (!$switchserver) {
5118: my $servadm = $r->dir_config('lonAdmEMail');
5119: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5120: if ($configuserok eq 'ok') {
5121: if ($author_ok eq 'ok') {
5122: my %legacyfile = (
5123: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5124: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5125: );
5126: my %md5chk;
5127: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5128: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5129: chomp($md5chk{$type});
1.46 raeburn 5130: }
5131: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5132: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5133: ($scantronurls{$type},my $error) =
1.46 raeburn 5134: &legacy_scantronformat($r,$dom,$confname,
5135: $type,$legacyfile{$type},
5136: $scantronurls{$type},
5137: $scantronfiles{$type});
1.60 raeburn 5138: if ($error ne '') {
5139: $error{$type} = $error;
5140: }
5141: }
5142: if (keys(%error) == 0) {
5143: $is_custom = 1;
5144: $confhash{'scantron'}{'scantronformat'} =
5145: $scantronurls{'custom'};
5146: my $putresult =
5147: &Apache::lonnet::put_dom('configuration',
5148: \%confhash,$dom);
5149: if ($putresult ne 'ok') {
5150: $error{'custom'} =
5151: '<span class="LC_error">'.
5152: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5153: }
1.46 raeburn 5154: }
5155: } else {
1.60 raeburn 5156: ($scantronurls{'default'},my $error) =
1.46 raeburn 5157: &legacy_scantronformat($r,$dom,$confname,
5158: 'default',$legacyfile{'default'},
5159: $scantronurls{'default'},
5160: $scantronfiles{'default'});
1.60 raeburn 5161: if ($error eq '') {
5162: $confhash{'scantron'}{'scantronformat'} = '';
5163: my $putresult =
5164: &Apache::lonnet::put_dom('configuration',
5165: \%confhash,$dom);
5166: if ($putresult ne 'ok') {
5167: $error{'default'} =
5168: '<span class="LC_error">'.
5169: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5170: }
5171: } else {
5172: $error{'default'} = $error;
5173: }
1.46 raeburn 5174: }
5175: }
5176: }
5177: } else {
1.95 www 5178: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5179: }
5180: }
5181: if (ref($settings) eq 'HASH') {
5182: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5183: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5184: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5185: $scantronurl = '';
5186: } else {
5187: $scantronurl = $settings->{'scantronformat'};
5188: }
5189: $is_custom = 1;
5190: } else {
5191: $scantronurl = $scantronurls{'default'};
5192: }
5193: } else {
1.60 raeburn 5194: if ($is_custom) {
5195: $scantronurl = $scantronurls{'custom'};
5196: } else {
5197: $scantronurl = $scantronurls{'default'};
5198: }
1.46 raeburn 5199: }
5200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5201: $datatable .= '<tr'.$css_class.'>';
5202: if (!$is_custom) {
1.65 raeburn 5203: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5204: '<span class="LC_nobreak">';
1.46 raeburn 5205: if ($scantronurl) {
1.160.6.21 raeburn 5206: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5207: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5208: } else {
5209: $datatable = &mt('File unavailable for display');
5210: }
1.65 raeburn 5211: $datatable .= '</span></td>';
1.60 raeburn 5212: if (keys(%error) == 0) {
5213: $datatable .= '<td valign="bottom">';
5214: if (!$switchserver) {
5215: $datatable .= &mt('Upload:').'<br />';
5216: }
5217: } else {
5218: my $errorstr;
5219: foreach my $key (sort(keys(%error))) {
5220: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5221: }
5222: $datatable .= '<td>'.$errorstr;
5223: }
1.46 raeburn 5224: } else {
5225: if (keys(%error) > 0) {
5226: my $errorstr;
5227: foreach my $key (sort(keys(%error))) {
5228: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5229: }
1.60 raeburn 5230: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5231: } elsif ($scantronurl) {
1.160.6.26 raeburn 5232: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5233: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5234: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5235: $link.
5236: '<label><input type="checkbox" name="scantronformat_del"'.
5237: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5238: '<td><span class="LC_nobreak"> '.
5239: &mt('Replace:').'</span><br />';
1.46 raeburn 5240: }
5241: }
5242: if (keys(%error) == 0) {
5243: if ($switchserver) {
5244: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5245: } else {
1.65 raeburn 5246: $datatable .='<span class="LC_nobreak"> '.
5247: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5248: }
5249: }
5250: $datatable .= '</td></tr>';
5251: $$rowtotal ++;
5252: return $datatable;
5253: }
5254:
5255: sub legacy_scantronformat {
5256: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5257: my ($url,$error);
5258: my @statinfo = &Apache::lonnet::stat_file($newurl);
5259: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5260: (my $result,$url) =
5261: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5262: '','',$newfile);
5263: if ($result ne 'ok') {
1.130 raeburn 5264: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5265: }
5266: }
5267: return ($url,$error);
5268: }
1.43 raeburn 5269:
1.49 raeburn 5270: sub print_coursecategories {
1.57 raeburn 5271: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5272: my $datatable;
5273: if ($position eq 'top') {
1.160.6.42 raeburn 5274: my (%checked);
5275: my @catitems = ('unauth','auth');
5276: my @cattypes = ('std','domonly','codesrch','none');
5277: $checked{'unauth'} = 'std';
5278: $checked{'auth'} = 'std';
5279: if (ref($settings) eq 'HASH') {
5280: foreach my $type (@cattypes) {
5281: if ($type eq $settings->{'unauth'}) {
5282: $checked{'unauth'} = $type;
5283: }
5284: if ($type eq $settings->{'auth'}) {
5285: $checked{'auth'} = $type;
5286: }
5287: }
5288: }
5289: my %lt = &Apache::lonlocal::texthash (
5290: unauth => 'Catalog type for unauthenticated users',
5291: auth => 'Catalog type for authenticated users',
5292: none => 'No catalog',
5293: std => 'Standard catalog',
5294: domonly => 'Domain-only catalog',
5295: codesrch => "Code search form",
5296: );
5297: my $itemcount = 0;
5298: foreach my $item (@catitems) {
5299: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5300: $datatable .= '<tr '.$css_class.'>'.
5301: '<td>'.$lt{$item}.'</td>'.
5302: '<td class="LC_right_item"><span class="LC_nobreak">';
5303: foreach my $type (@cattypes) {
5304: my $ischecked;
5305: if ($checked{$item} eq $type) {
5306: $ischecked=' checked="checked"';
5307: }
5308: $datatable .= '<label>'.
5309: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5310: ' />'.$lt{$type}.'</label> ';
5311: }
5312: $datatable .= '</td></tr>';
5313: $itemcount ++;
5314: }
5315: $$rowtotal += $itemcount;
5316: } elsif ($position eq 'middle') {
1.57 raeburn 5317: my $toggle_cats_crs = ' ';
5318: my $toggle_cats_dom = ' checked="checked" ';
5319: my $can_cat_crs = ' ';
5320: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5321: my $toggle_catscomm_comm = ' ';
5322: my $toggle_catscomm_dom = ' checked="checked" ';
5323: my $can_catcomm_comm = ' ';
5324: my $can_catcomm_dom = ' checked="checked" ';
5325:
1.57 raeburn 5326: if (ref($settings) eq 'HASH') {
5327: if ($settings->{'togglecats'} eq 'crs') {
5328: $toggle_cats_crs = $toggle_cats_dom;
5329: $toggle_cats_dom = ' ';
5330: }
5331: if ($settings->{'categorize'} eq 'crs') {
5332: $can_cat_crs = $can_cat_dom;
5333: $can_cat_dom = ' ';
5334: }
1.120 raeburn 5335: if ($settings->{'togglecatscomm'} eq 'comm') {
5336: $toggle_catscomm_comm = $toggle_catscomm_dom;
5337: $toggle_catscomm_dom = ' ';
5338: }
5339: if ($settings->{'categorizecomm'} eq 'comm') {
5340: $can_catcomm_comm = $can_catcomm_dom;
5341: $can_catcomm_dom = ' ';
5342: }
1.57 raeburn 5343: }
5344: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5345: togglecats => 'Show/Hide a course in catalog',
5346: togglecatscomm => 'Show/Hide a community in catalog',
5347: categorize => 'Assign a category to a course',
5348: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5349: );
5350: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5351: dom => 'Set in Domain',
5352: crs => 'Set in Course',
5353: comm => 'Set in Community',
1.57 raeburn 5354: );
5355: $datatable = '<tr class="LC_odd_row">'.
5356: '<td>'.$title{'togglecats'}.'</td>'.
5357: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5358: '<input type="radio" name="togglecats"'.
5359: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5360: '<label><input type="radio" name="togglecats"'.
5361: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5362: '</tr><tr>'.
5363: '<td>'.$title{'categorize'}.'</td>'.
5364: '<td class="LC_right_item"><span class="LC_nobreak">'.
5365: '<label><input type="radio" name="categorize"'.
5366: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5367: '<label><input type="radio" name="categorize"'.
5368: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5369: '</tr><tr class="LC_odd_row">'.
5370: '<td>'.$title{'togglecatscomm'}.'</td>'.
5371: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5372: '<input type="radio" name="togglecatscomm"'.
5373: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5374: '<label><input type="radio" name="togglecatscomm"'.
5375: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5376: '</tr><tr>'.
5377: '<td>'.$title{'categorizecomm'}.'</td>'.
5378: '<td class="LC_right_item"><span class="LC_nobreak">'.
5379: '<label><input type="radio" name="categorizecomm"'.
5380: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5381: '<label><input type="radio" name="categorizecomm"'.
5382: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5383: '</tr>';
1.120 raeburn 5384: $$rowtotal += 4;
1.57 raeburn 5385: } else {
5386: my $css_class;
5387: my $itemcount = 1;
5388: my $cathash;
5389: if (ref($settings) eq 'HASH') {
5390: $cathash = $settings->{'cats'};
5391: }
5392: if (ref($cathash) eq 'HASH') {
5393: my (@cats,@trails,%allitems,%idx,@jsarray);
5394: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5395: \%allitems,\%idx,\@jsarray);
5396: my $maxdepth = scalar(@cats);
5397: my $colattrib = '';
5398: if ($maxdepth > 2) {
5399: $colattrib = ' colspan="2" ';
5400: }
5401: my @path;
5402: if (@cats > 0) {
5403: if (ref($cats[0]) eq 'ARRAY') {
5404: my $numtop = @{$cats[0]};
5405: my $maxnum = $numtop;
1.120 raeburn 5406: my %default_names = (
5407: instcode => &mt('Official courses'),
5408: communities => &mt('Communities'),
5409: );
5410:
5411: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5412: ($cathash->{'instcode::0'} eq '') ||
5413: (!grep(/^communities$/,@{$cats[0]})) ||
5414: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5415: $maxnum ++;
5416: }
5417: my $lastidx;
5418: for (my $i=0; $i<$numtop; $i++) {
5419: my $parent = $cats[0][$i];
5420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5421: my $item = &escape($parent).'::0';
5422: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5423: $lastidx = $idx{$item};
5424: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5425: .'<select name="'.$item.'"'.$chgstr.'>';
5426: for (my $k=0; $k<=$maxnum; $k++) {
5427: my $vpos = $k+1;
5428: my $selstr;
5429: if ($k == $i) {
5430: $selstr = ' selected="selected" ';
5431: }
5432: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5433: }
1.160.6.29 raeburn 5434: $datatable .= '</select></span></td><td>';
1.120 raeburn 5435: if ($parent eq 'instcode' || $parent eq 'communities') {
5436: $datatable .= '<span class="LC_nobreak">'
5437: .$default_names{$parent}.'</span>';
5438: if ($parent eq 'instcode') {
5439: $datatable .= '<br /><span class="LC_nobreak">('
5440: .&mt('with institutional codes')
5441: .')</span></td><td'.$colattrib.'>';
5442: } else {
5443: $datatable .= '<table><tr><td>';
5444: }
5445: $datatable .= '<span class="LC_nobreak">'
5446: .'<label><input type="radio" name="'
5447: .$parent.'" value="1" checked="checked" />'
5448: .&mt('Display').'</label>';
5449: if ($parent eq 'instcode') {
5450: $datatable .= ' ';
5451: } else {
5452: $datatable .= '</span></td></tr><tr><td>'
5453: .'<span class="LC_nobreak">';
5454: }
5455: $datatable .= '<label><input type="radio" name="'
5456: .$parent.'" value="0" />'
5457: .&mt('Do not display').'</label></span>';
5458: if ($parent eq 'communities') {
5459: $datatable .= '</td></tr></table>';
5460: }
5461: $datatable .= '</td>';
1.57 raeburn 5462: } else {
5463: $datatable .= $parent
1.160.6.29 raeburn 5464: .' <span class="LC_nobreak"><label>'
5465: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5466: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5467: }
5468: my $depth = 1;
5469: push(@path,$parent);
5470: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5471: pop(@path);
5472: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5473: $itemcount ++;
5474: }
1.48 raeburn 5475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5476: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5477: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5478: for (my $k=0; $k<=$maxnum; $k++) {
5479: my $vpos = $k+1;
5480: my $selstr;
1.57 raeburn 5481: if ($k == $numtop) {
1.48 raeburn 5482: $selstr = ' selected="selected" ';
5483: }
5484: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5485: }
1.59 bisitz 5486: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5487: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5488: .'</tr>'."\n";
1.48 raeburn 5489: $itemcount ++;
1.120 raeburn 5490: foreach my $default ('instcode','communities') {
5491: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5493: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5494: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5495: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5496: for (my $k=0; $k<=$maxnum; $k++) {
5497: my $vpos = $k+1;
5498: my $selstr;
5499: if ($k == $maxnum) {
5500: $selstr = ' selected="selected" ';
5501: }
5502: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5503: }
1.120 raeburn 5504: $datatable .= '</select></span></td>'.
5505: '<td><span class="LC_nobreak">'.
5506: $default_names{$default}.'</span>';
5507: if ($default eq 'instcode') {
5508: $datatable .= '<br /><span class="LC_nobreak">('
5509: .&mt('with institutional codes').')</span>';
5510: }
5511: $datatable .= '</td>'
5512: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5513: .&mt('Display').'</label> '
5514: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5515: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5516: }
5517: }
5518: }
1.57 raeburn 5519: } else {
5520: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5521: }
5522: } else {
1.160.6.42 raeburn 5523: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5524: .&initialize_categories($itemcount);
1.48 raeburn 5525: }
1.57 raeburn 5526: $$rowtotal += $itemcount;
1.48 raeburn 5527: }
5528: return $datatable;
5529: }
5530:
1.69 raeburn 5531: sub print_serverstatuses {
5532: my ($dom,$settings,$rowtotal) = @_;
5533: my $datatable;
5534: my @pages = &serverstatus_pages();
5535: my (%namedaccess,%machineaccess);
5536: foreach my $type (@pages) {
5537: $namedaccess{$type} = '';
5538: $machineaccess{$type}= '';
5539: }
5540: if (ref($settings) eq 'HASH') {
5541: foreach my $type (@pages) {
5542: if (exists($settings->{$type})) {
5543: if (ref($settings->{$type}) eq 'HASH') {
5544: foreach my $key (keys(%{$settings->{$type}})) {
5545: if ($key eq 'namedusers') {
5546: $namedaccess{$type} = $settings->{$type}->{$key};
5547: } elsif ($key eq 'machines') {
5548: $machineaccess{$type} = $settings->{$type}->{$key};
5549: }
5550: }
5551: }
5552: }
5553: }
5554: }
1.81 raeburn 5555: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5556: my $rownum = 0;
5557: my $css_class;
5558: foreach my $type (@pages) {
5559: $rownum ++;
5560: $css_class = $rownum%2?' class="LC_odd_row"':'';
5561: $datatable .= '<tr'.$css_class.'>'.
5562: '<td><span class="LC_nobreak">'.
5563: $titles->{$type}.'</span></td>'.
5564: '<td class="LC_left_item">'.
5565: '<input type="text" name="'.$type.'_namedusers" '.
5566: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5567: '<td class="LC_right_item">'.
5568: '<span class="LC_nobreak">'.
5569: '<input type="text" name="'.$type.'_machines" '.
5570: 'value="'.$machineaccess{$type}.'" size="10" />'.
5571: '</td></tr>'."\n";
5572: }
5573: $$rowtotal += $rownum;
5574: return $datatable;
5575: }
5576:
5577: sub serverstatus_pages {
5578: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5579: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5580: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 5581: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5582: }
5583:
1.160.6.40 raeburn 5584: sub defaults_javascript {
5585: my ($settings) = @_;
1.160.6.51 raeburn 5586: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5587: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5588: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5589: if ($maxnum eq '') {
5590: $maxnum = 0;
5591: }
5592: $maxnum ++;
1.160.6.51 raeburn 5593: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5594: return <<"ENDSCRIPT";
5595: <script type="text/javascript">
5596: // <![CDATA[
5597: function reorderTypes(form,caller) {
5598: var changedVal;
5599: $jstext
5600: var newpos = 'addinststatus_pos';
5601: var current = new Array;
5602: var maxh = $maxnum;
5603: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5604: var oldVal;
5605: if (caller == newpos) {
5606: changedVal = newitemVal;
5607: } else {
5608: var curritem = 'inststatus_pos_'+caller;
5609: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5610: current[newitemVal] = newpos;
5611: }
5612: for (var i=0; i<inststatuses.length; i++) {
5613: if (inststatuses[i] != caller) {
5614: var elementName = 'inststatus_pos_'+inststatuses[i];
5615: if (form.elements[elementName]) {
5616: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5617: current[currVal] = elementName;
5618: }
5619: }
5620: }
5621: for (var j=0; j<maxh; j++) {
5622: if (current[j] == undefined) {
5623: oldVal = j;
5624: }
5625: }
5626: if (oldVal < changedVal) {
5627: for (var k=oldVal+1; k<=changedVal ; k++) {
5628: var elementName = current[k];
5629: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5630: }
5631: } else {
5632: for (var k=changedVal; k<oldVal; k++) {
5633: var elementName = current[k];
5634: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5635: }
5636: }
5637: return;
5638: }
5639:
5640: // ]]>
5641: </script>
5642:
5643: ENDSCRIPT
5644: }
5645: }
5646:
1.49 raeburn 5647: sub coursecategories_javascript {
5648: my ($settings) = @_;
1.57 raeburn 5649: my ($output,$jstext,$cathash);
1.49 raeburn 5650: if (ref($settings) eq 'HASH') {
1.57 raeburn 5651: $cathash = $settings->{'cats'};
5652: }
5653: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5654: my (@cats,@jsarray,%idx);
1.57 raeburn 5655: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5656: if (@jsarray > 0) {
5657: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5658: for (my $i=0; $i<@jsarray; $i++) {
5659: if (ref($jsarray[$i]) eq 'ARRAY') {
5660: my $catstr = join('","',@{$jsarray[$i]});
5661: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5662: }
5663: }
5664: }
5665: } else {
5666: $jstext = ' var categories = Array(1);'."\n".
5667: ' categories[0] = Array("instcode_pos");'."\n";
5668: }
1.160.6.42 raeburn 5669: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5670: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 5671: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5672: &js_escape(\$instcode_reserved);
5673: &js_escape(\$communities_reserved);
5674: &js_escape(\$choose_again);
1.49 raeburn 5675: $output = <<"ENDSCRIPT";
5676: <script type="text/javascript">
1.109 raeburn 5677: // <![CDATA[
1.49 raeburn 5678: function reorderCats(form,parent,item,idx) {
5679: var changedVal;
5680: $jstext
5681: var newpos = 'addcategory_pos';
5682: if (parent == '') {
5683: var has_instcode = 0;
5684: var maxtop = categories[idx].length;
5685: for (var j=0; j<maxtop; j++) {
5686: if (categories[idx][j] == 'instcode::0') {
5687: has_instcode == 1;
5688: }
5689: }
5690: if (has_instcode == 0) {
5691: categories[idx][maxtop] = 'instcode_pos';
5692: }
5693: } else {
5694: newpos += '_'+parent;
5695: }
5696: var maxh = 1 + categories[idx].length;
5697: var current = new Array;
5698: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5699: if (item == newpos) {
5700: changedVal = newitemVal;
5701: } else {
5702: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5703: current[newitemVal] = newpos;
5704: }
5705: for (var i=0; i<categories[idx].length; i++) {
5706: var elementName = categories[idx][i];
5707: if (elementName != item) {
5708: if (form.elements[elementName]) {
5709: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5710: current[currVal] = elementName;
5711: }
5712: }
5713: }
5714: var oldVal;
5715: for (var j=0; j<maxh; j++) {
5716: if (current[j] == undefined) {
5717: oldVal = j;
5718: }
5719: }
5720: if (oldVal < changedVal) {
5721: for (var k=oldVal+1; k<=changedVal ; k++) {
5722: var elementName = current[k];
5723: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5724: }
5725: } else {
5726: for (var k=changedVal; k<oldVal; k++) {
5727: var elementName = current[k];
5728: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5729: }
5730: }
5731: return;
5732: }
1.120 raeburn 5733:
5734: function categoryCheck(form) {
5735: if (form.elements['addcategory_name'].value == 'instcode') {
5736: alert('$instcode_reserved\\n$choose_again');
5737: return false;
5738: }
5739: if (form.elements['addcategory_name'].value == 'communities') {
5740: alert('$communities_reserved\\n$choose_again');
5741: return false;
5742: }
5743: return true;
5744: }
5745:
1.109 raeburn 5746: // ]]>
1.49 raeburn 5747: </script>
5748:
5749: ENDSCRIPT
5750: return $output;
5751: }
5752:
1.48 raeburn 5753: sub initialize_categories {
5754: my ($itemcount) = @_;
1.120 raeburn 5755: my ($datatable,$css_class,$chgstr);
5756: my %default_names = (
5757: instcode => 'Official courses (with institutional codes)',
5758: communities => 'Communities',
5759: );
5760: my $select0 = ' selected="selected"';
5761: my $select1 = '';
5762: foreach my $default ('instcode','communities') {
5763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5764: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5765: if ($default eq 'communities') {
5766: $select1 = $select0;
5767: $select0 = '';
5768: }
5769: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5770: .'<select name="'.$default.'_pos">'
5771: .'<option value="0"'.$select0.'>1</option>'
5772: .'<option value="1"'.$select1.'>2</option>'
5773: .'<option value="2">3</option></select> '
5774: .$default_names{$default}
5775: .'</span></td><td><span class="LC_nobreak">'
5776: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5777: .&mt('Display').'</label> <label>'
5778: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5779: .'</label></span></td></tr>';
1.120 raeburn 5780: $itemcount ++;
5781: }
1.48 raeburn 5782: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5783: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5784: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5785: .'<select name="addcategory_pos"'.$chgstr.'>'
5786: .'<option value="0">1</option>'
5787: .'<option value="1">2</option>'
5788: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5789: .&mt('Add category').'</td><td>'.&mt('Name:')
5790: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5791: return $datatable;
5792: }
5793:
5794: sub build_category_rows {
1.49 raeburn 5795: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5796: my ($text,$name,$item,$chgstr);
1.48 raeburn 5797: if (ref($cats) eq 'ARRAY') {
5798: my $maxdepth = scalar(@{$cats});
5799: if (ref($cats->[$depth]) eq 'HASH') {
5800: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5801: my $numchildren = @{$cats->[$depth]{$parent}};
5802: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5803: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5804: my ($idxnum,$parent_name,$parent_item);
5805: my $higher = $depth - 1;
5806: if ($higher == 0) {
5807: $parent_name = &escape($parent).'::'.$higher;
5808: } else {
5809: if (ref($path) eq 'ARRAY') {
5810: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5811: }
5812: }
5813: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5814: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5815: if ($j < $numchildren) {
1.48 raeburn 5816: $name = $cats->[$depth]{$parent}[$j];
5817: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5818: $idxnum = $idx->{$item};
5819: } else {
5820: $name = $parent_name;
5821: $item = $parent_item;
1.48 raeburn 5822: }
1.49 raeburn 5823: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5824: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5825: for (my $i=0; $i<=$numchildren; $i++) {
5826: my $vpos = $i+1;
5827: my $selstr;
5828: if ($j == $i) {
5829: $selstr = ' selected="selected" ';
5830: }
5831: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5832: }
5833: $text .= '</select> ';
5834: if ($j < $numchildren) {
5835: my $deeper = $depth+1;
5836: $text .= $name.' '
5837: .'<label><input type="checkbox" name="deletecategory" value="'
5838: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5839: if(ref($path) eq 'ARRAY') {
5840: push(@{$path},$name);
1.49 raeburn 5841: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5842: pop(@{$path});
5843: }
5844: } else {
1.59 bisitz 5845: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5846: if ($j == $numchildren) {
5847: $text .= $name;
5848: } else {
5849: $text .= $item;
5850: }
5851: $text .= '" value="" />';
5852: }
5853: $text .= '</td></tr>';
5854: }
5855: $text .= '</table></td>';
5856: } else {
5857: my $higher = $depth-1;
5858: if ($higher == 0) {
5859: $name = &escape($parent).'::'.$higher;
5860: } else {
5861: if (ref($path) eq 'ARRAY') {
5862: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5863: }
5864: }
5865: my $colspan;
5866: if ($parent ne 'instcode') {
5867: $colspan = $maxdepth - $depth - 1;
5868: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5869: }
5870: }
5871: }
5872: }
5873: return $text;
5874: }
5875:
1.33 raeburn 5876: sub modifiable_userdata_row {
1.160.6.35 raeburn 5877: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5878: my ($role,$rolename,$statustype);
5879: $role = $item;
1.160.6.34 raeburn 5880: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5881: if ($item =~ /^emailusername_(.+)$/) {
5882: $statustype = $1;
5883: $role = 'emailusername';
5884: if (ref($usertypes) eq 'HASH') {
5885: if ($usertypes->{$statustype}) {
5886: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5887: } else {
5888: $rolename = &mt('Data provided by user');
5889: }
5890: }
1.160.6.34 raeburn 5891: }
5892: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5893: if (ref($usertypes) eq 'HASH') {
5894: $rolename = $usertypes->{$role};
5895: } else {
5896: $rolename = $role;
5897: }
1.33 raeburn 5898: } else {
1.63 raeburn 5899: if ($role eq 'cr') {
5900: $rolename = &mt('Custom role');
5901: } else {
5902: $rolename = &Apache::lonnet::plaintext($role);
5903: }
1.33 raeburn 5904: }
1.160.6.34 raeburn 5905: my (@fields,%fieldtitles);
5906: if (ref($fieldsref) eq 'ARRAY') {
5907: @fields = @{$fieldsref};
5908: } else {
5909: @fields = ('lastname','firstname','middlename','generation',
5910: 'permanentemail','id');
5911: }
5912: if ((ref($titlesref) eq 'HASH')) {
5913: %fieldtitles = %{$titlesref};
5914: } else {
5915: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5916: }
1.33 raeburn 5917: my $output;
5918: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5919: $output = '<tr '.$css_class.'>'.
5920: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5921: '<td class="LC_left_item" colspan="2"><table>';
5922: my $rem;
5923: my %checks;
5924: if (ref($settings) eq 'HASH') {
5925: if (ref($settings->{$context}) eq 'HASH') {
5926: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5927: my $hashref = $settings->{$context}->{$role};
5928: if ($role eq 'emailusername') {
5929: if ($statustype) {
5930: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5931: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5932: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5933: foreach my $field (@fields) {
5934: if ($hashref->{$field}) {
5935: $checks{$field} = $hashref->{$field};
5936: }
5937: }
5938: }
5939: }
5940: }
5941: } else {
5942: if (ref($hashref) eq 'HASH') {
5943: foreach my $field (@fields) {
5944: if ($hashref->{$field}) {
5945: $checks{$field} = ' checked="checked" ';
5946: }
5947: }
1.33 raeburn 5948: }
5949: }
5950: }
5951: }
5952: }
1.160.6.39 raeburn 5953:
1.33 raeburn 5954: for (my $i=0; $i<@fields; $i++) {
5955: my $rem = $i%($numinrow);
5956: if ($rem == 0) {
5957: if ($i > 0) {
5958: $output .= '</tr>';
5959: }
5960: $output .= '<tr>';
5961: }
5962: my $check = ' ';
1.160.6.35 raeburn 5963: unless ($role eq 'emailusername') {
5964: if (exists($checks{$fields[$i]})) {
5965: $check = $checks{$fields[$i]}
5966: } else {
5967: if ($role eq 'st') {
5968: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5969: $check = ' checked="checked" ';
1.160.6.35 raeburn 5970: }
1.33 raeburn 5971: }
5972: }
5973: }
5974: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5975: '<span class="LC_nobreak">';
5976: if ($role eq 'emailusername') {
5977: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5978: $checks{$fields[$i]} = 'omit';
5979: }
5980: foreach my $option ('required','optional','omit') {
5981: my $checked='';
5982: if ($checks{$fields[$i]} eq $option) {
5983: $checked='checked="checked" ';
5984: }
5985: $output .= '<label>'.
5986: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5987: &mt($option).'</label>'.(' ' x2);
5988: }
5989: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5990: } else {
5991: $output .= '<label>'.
5992: '<input type="checkbox" name="canmodify_'.$role.'" '.
5993: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5994: '</label>';
5995: }
5996: $output .= '</span></td>';
1.33 raeburn 5997: $rem = @fields%($numinrow);
5998: }
5999: my $colsleft = $numinrow - $rem;
6000: if ($colsleft > 1 ) {
6001: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6002: ' </td>';
6003: } elsif ($colsleft == 1) {
6004: $output .= '<td class="LC_left_item"> </td>';
6005: }
6006: $output .= '</tr></table></td></tr>';
6007: return $output;
6008: }
1.28 raeburn 6009:
1.93 raeburn 6010: sub insttypes_row {
1.160.6.34 raeburn 6011: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6012: my %lt = &Apache::lonlocal::texthash (
6013: cansearch => 'Users allowed to search',
6014: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6015: lockablenames => 'User preference to lock name',
1.93 raeburn 6016: );
6017: my $showdom;
6018: if ($context eq 'cansearch') {
6019: $showdom = ' ('.$dom.')';
6020: }
1.160.6.5 raeburn 6021: my $class = 'LC_left_item';
6022: if ($context eq 'statustocreate') {
6023: $class = 'LC_right_item';
6024: }
1.160.6.34 raeburn 6025: my $css_class = ' class="LC_odd_row"';
6026: if ($rownum ne '') {
6027: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6028: }
6029: my $output = '<tr'.$css_class.'>'.
6030: '<td>'.$lt{$context}.$showdom.
6031: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6032: my $rem;
6033: if (ref($types) eq 'ARRAY') {
6034: for (my $i=0; $i<@{$types}; $i++) {
6035: if (defined($usertypes->{$types->[$i]})) {
6036: my $rem = $i%($numinrow);
6037: if ($rem == 0) {
6038: if ($i > 0) {
6039: $output .= '</tr>';
6040: }
6041: $output .= '<tr>';
1.23 raeburn 6042: }
1.26 raeburn 6043: my $check = ' ';
1.99 raeburn 6044: if (ref($settings) eq 'HASH') {
6045: if (ref($settings->{$context}) eq 'ARRAY') {
6046: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6047: $check = ' checked="checked" ';
6048: }
6049: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6050: $check = ' checked="checked" ';
6051: }
1.23 raeburn 6052: }
1.26 raeburn 6053: $output .= '<td class="LC_left_item">'.
6054: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6055: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6056: 'value="'.$types->[$i].'"'.$check.'/>'.
6057: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6058: }
6059: }
1.26 raeburn 6060: $rem = @{$types}%($numinrow);
1.23 raeburn 6061: }
6062: my $colsleft = $numinrow - $rem;
1.131 raeburn 6063: if (($rem == 0) && (@{$types} > 0)) {
6064: $output .= '<tr>';
6065: }
1.23 raeburn 6066: if ($colsleft > 1) {
1.25 raeburn 6067: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6068: } else {
1.25 raeburn 6069: $output .= '<td class="LC_left_item">';
1.23 raeburn 6070: }
6071: my $defcheck = ' ';
1.99 raeburn 6072: if (ref($settings) eq 'HASH') {
6073: if (ref($settings->{$context}) eq 'ARRAY') {
6074: if (grep(/^default$/,@{$settings->{$context}})) {
6075: $defcheck = ' checked="checked" ';
6076: }
6077: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6078: $defcheck = ' checked="checked" ';
6079: }
1.23 raeburn 6080: }
1.25 raeburn 6081: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6082: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6083: 'value="default"'.$defcheck.'/>'.
6084: $othertitle.'</label></span></td>'.
6085: '</tr></table></td></tr>';
6086: return $output;
1.23 raeburn 6087: }
6088:
6089: sub sorted_searchtitles {
6090: my %searchtitles = &Apache::lonlocal::texthash(
6091: 'uname' => 'username',
6092: 'lastname' => 'last name',
6093: 'lastfirst' => 'last name, first name',
6094: );
6095: my @titleorder = ('uname','lastname','lastfirst');
6096: return (\%searchtitles,\@titleorder);
6097: }
6098:
1.25 raeburn 6099: sub sorted_searchtypes {
6100: my %srchtypes_desc = (
6101: exact => 'is exact match',
6102: contains => 'contains ..',
6103: begins => 'begins with ..',
6104: );
6105: my @srchtypeorder = ('exact','begins','contains');
6106: return (\%srchtypes_desc,\@srchtypeorder);
6107: }
6108:
1.3 raeburn 6109: sub usertype_update_row {
6110: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6111: my $datatable;
6112: my $numinrow = 4;
6113: foreach my $type (@{$types}) {
6114: if (defined($usertypes->{$type})) {
6115: $$rownums ++;
6116: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6117: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6118: '</td><td class="LC_left_item"><table>';
6119: for (my $i=0; $i<@{$fields}; $i++) {
6120: my $rem = $i%($numinrow);
6121: if ($rem == 0) {
6122: if ($i > 0) {
6123: $datatable .= '</tr>';
6124: }
6125: $datatable .= '<tr>';
6126: }
6127: my $check = ' ';
1.39 raeburn 6128: if (ref($settings) eq 'HASH') {
6129: if (ref($settings->{'fields'}) eq 'HASH') {
6130: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6131: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6132: $check = ' checked="checked" ';
6133: }
1.3 raeburn 6134: }
6135: }
6136: }
6137:
6138: if ($i == @{$fields}-1) {
6139: my $colsleft = $numinrow - $rem;
6140: if ($colsleft > 1) {
6141: $datatable .= '<td colspan="'.$colsleft.'">';
6142: } else {
6143: $datatable .= '<td>';
6144: }
6145: } else {
6146: $datatable .= '<td>';
6147: }
1.8 raeburn 6148: $datatable .= '<span class="LC_nobreak"><label>'.
6149: '<input type="checkbox" name="updateable_'.$type.
6150: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6151: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6152: }
6153: $datatable .= '</tr></table></td></tr>';
6154: }
6155: }
6156: return $datatable;
1.1 raeburn 6157: }
6158:
6159: sub modify_login {
1.160.6.24 raeburn 6160: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6161: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6162: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6163: %title = ( coursecatalog => 'Display course catalog',
6164: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6165: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6166: newuser => 'Link for visitors to create a user account',
6167: loginheader => 'Log-in box header');
6168: @offon = ('off','on');
1.112 raeburn 6169: if (ref($domconfig{login}) eq 'HASH') {
6170: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6171: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6172: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6173: }
6174: }
6175: }
1.9 raeburn 6176: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6177: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6178: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6179: foreach my $item (@toggles) {
6180: $loginhash{login}{$item} = $env{'form.'.$item};
6181: }
1.41 raeburn 6182: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6183: if (ref($colchanges{'login'}) eq 'HASH') {
6184: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6185: \%loginhash);
6186: }
1.110 raeburn 6187:
1.149 raeburn 6188: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6189: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6190: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6191: if (keys(%servers) > 1) {
6192: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6193: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6194: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6195: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6196: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6197: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6198: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6199: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6200: $changes{'loginvia'}{$lonhost} = 1;
6201: } else {
6202: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6203: $changes{'loginvia'}{$lonhost} = 1;
6204: }
6205: } else {
6206: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6207: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6208: $changes{'loginvia'}{$lonhost} = 1;
6209: }
6210: }
6211: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6212: foreach my $item (@loginvia_attribs) {
6213: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6214: }
6215: } else {
6216: foreach my $item (@loginvia_attribs) {
6217: my $new = $env{'form.'.$lonhost.'_'.$item};
6218: if (($item eq 'serverpath') && ($new eq 'custom')) {
6219: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6220: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6221: $new = '/';
6222: }
6223: }
6224: if (($item eq 'custompath') &&
6225: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6226: $new = '';
6227: }
6228: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6229: $changes{'loginvia'}{$lonhost} = 1;
6230: }
6231: if ($item eq 'exempt') {
1.160.6.56 raeburn 6232: $new = &check_exempt_addresses($new);
1.128 raeburn 6233: }
6234: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6235: }
6236: }
1.112 raeburn 6237: } else {
1.128 raeburn 6238: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6239: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6240: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6241: foreach my $item (@loginvia_attribs) {
6242: my $new = $env{'form.'.$lonhost.'_'.$item};
6243: if (($item eq 'serverpath') && ($new eq 'custom')) {
6244: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6245: $new = '/';
6246: }
6247: }
6248: if (($item eq 'custompath') &&
6249: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6250: $new = '';
6251: }
6252: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6253: }
1.110 raeburn 6254: }
6255: }
6256: }
6257: }
1.119 raeburn 6258:
1.160.6.5 raeburn 6259: my $servadm = $r->dir_config('lonAdmEMail');
6260: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6261: if (ref($domconfig{'login'}) eq 'HASH') {
6262: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6263: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6264: if ($lang eq 'nolang') {
6265: push(@currlangs,$lang);
6266: } elsif (defined($langchoices{$lang})) {
6267: push(@currlangs,$lang);
6268: } else {
6269: next;
6270: }
6271: }
6272: }
6273: }
6274: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6275: if (@currlangs > 0) {
6276: foreach my $lang (@currlangs) {
6277: if (grep(/^\Q$lang\E$/,@delurls)) {
6278: $changes{'helpurl'}{$lang} = 1;
6279: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6280: $changes{'helpurl'}{$lang} = 1;
6281: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6282: push(@newlangs,$lang);
6283: } else {
6284: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6285: }
6286: }
6287: }
6288: unless (grep(/^nolang$/,@currlangs)) {
6289: if ($env{'form.loginhelpurl_nolang.filename'}) {
6290: $changes{'helpurl'}{'nolang'} = 1;
6291: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6292: push(@newlangs,'nolang');
6293: }
6294: }
6295: if ($env{'form.loginhelpurl_add_lang'}) {
6296: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6297: ($env{'form.loginhelpurl_add_file.filename'})) {
6298: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6299: $addedfile = $env{'form.loginhelpurl_add_lang'};
6300: }
6301: }
6302: if ((@newlangs > 0) || ($addedfile)) {
6303: my $error;
6304: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6305: if ($configuserok eq 'ok') {
6306: if ($switchserver) {
6307: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6308: } elsif ($author_ok eq 'ok') {
6309: my @allnew = @newlangs;
6310: if ($addedfile ne '') {
6311: push(@allnew,$addedfile);
6312: }
6313: foreach my $lang (@allnew) {
6314: my $formelem = 'loginhelpurl_'.$lang;
6315: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6316: $formelem = 'loginhelpurl_add_file';
6317: }
6318: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6319: "help/$lang",'','',$newfile{$lang});
6320: if ($result eq 'ok') {
6321: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6322: $changes{'helpurl'}{$lang} = 1;
6323: } else {
6324: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6325: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6326: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6327: (!grep(/^\Q$lang\E$/,@delurls))) {
6328:
6329: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6330: }
6331: }
6332: }
6333: } else {
6334: $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);
6335: }
6336: } else {
6337: $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);
6338: }
6339: if ($error) {
6340: &Apache::lonnet::logthis($error);
6341: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6342: }
6343: }
1.160.6.56 raeburn 6344:
6345: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6346: if (ref($domconfig{'login'}) eq 'HASH') {
6347: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6348: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6349: if ($domservers{$lonhost}) {
6350: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6351: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6352: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6353: }
6354: }
6355: }
6356: }
6357: }
6358: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6359: foreach my $lonhost (sort(keys(%domservers))) {
6360: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6361: $changes{'headtag'}{$lonhost} = 1;
6362: } else {
6363: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6364: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6365: }
6366: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6367: push(@newhosts,$lonhost);
6368: } elsif ($currheadtagurls{$lonhost}) {
6369: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6370: if ($currexempt{$lonhost}) {
6371: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6372: $changes{'headtag'}{$lonhost} = 1;
6373: }
6374: } elsif ($possexempt{$lonhost}) {
6375: $changes{'headtag'}{$lonhost} = 1;
6376: }
6377: if ($possexempt{$lonhost}) {
6378: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6379: }
6380: }
6381: }
6382: }
6383: if (@newhosts) {
6384: my $error;
6385: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6386: if ($configuserok eq 'ok') {
6387: if ($switchserver) {
6388: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6389: } elsif ($author_ok eq 'ok') {
6390: foreach my $lonhost (@newhosts) {
6391: my $formelem = 'loginheadtag_'.$lonhost;
6392: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6393: "login/headtag/$lonhost",'','',
6394: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6395: if ($result eq 'ok') {
6396: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6397: $changes{'headtag'}{$lonhost} = 1;
6398: if ($possexempt{$lonhost}) {
6399: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6400: }
6401: } else {
6402: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6403: $newheadtagurls{$lonhost},$result);
6404: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6405: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6406: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6407: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6408: }
6409: }
6410: }
6411: } else {
6412: $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);
6413: }
6414: } else {
6415: $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);
6416: }
6417: if ($error) {
6418: &Apache::lonnet::logthis($error);
6419: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6420: }
6421: }
6422:
1.160.6.5 raeburn 6423: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6424:
6425: my $defaulthelpfile = '/adm/loginproblems.html';
6426: my $defaulttext = &mt('Default in use');
6427:
1.1 raeburn 6428: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6429: $dom);
6430: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6431: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6432: my %defaultchecked = (
6433: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6434: 'helpdesk' => 'on',
1.42 raeburn 6435: 'adminmail' => 'off',
1.43 raeburn 6436: 'newuser' => 'off',
1.42 raeburn 6437: );
1.55 raeburn 6438: if (ref($domconfig{'login'}) eq 'HASH') {
6439: foreach my $item (@toggles) {
6440: if ($defaultchecked{$item} eq 'on') {
6441: if (($domconfig{'login'}{$item} eq '0') &&
6442: ($env{'form.'.$item} eq '1')) {
6443: $changes{$item} = 1;
6444: } elsif (($domconfig{'login'}{$item} eq '' ||
6445: $domconfig{'login'}{$item} eq '1') &&
6446: ($env{'form.'.$item} eq '0')) {
6447: $changes{$item} = 1;
6448: }
6449: } elsif ($defaultchecked{$item} eq 'off') {
6450: if (($domconfig{'login'}{$item} eq '1') &&
6451: ($env{'form.'.$item} eq '0')) {
6452: $changes{$item} = 1;
6453: } elsif (($domconfig{'login'}{$item} eq '' ||
6454: $domconfig{'login'}{$item} eq '0') &&
6455: ($env{'form.'.$item} eq '1')) {
6456: $changes{$item} = 1;
6457: }
1.42 raeburn 6458: }
6459: }
1.41 raeburn 6460: }
1.6 raeburn 6461: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6462: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6463: if (ref($lastactref) eq 'HASH') {
6464: $lastactref->{'domainconfig'} = 1;
6465: }
1.1 raeburn 6466: $resulttext = &mt('Changes made:').'<ul>';
6467: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6468: if ($item eq 'loginvia') {
1.112 raeburn 6469: if (ref($changes{$item}) eq 'HASH') {
6470: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6471: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6472: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6473: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6474: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6475: $protocol = 'http' if ($protocol ne 'https');
6476: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6477:
6478: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6479: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6480: } else {
6481: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6482: }
6483: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6484: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6485: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6486: }
6487: $resulttext .= '</li>';
6488: } else {
6489: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6490: }
1.112 raeburn 6491: } else {
1.128 raeburn 6492: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6493: }
6494: }
1.128 raeburn 6495: $resulttext .= '</ul></li>';
1.112 raeburn 6496: }
1.160.6.5 raeburn 6497: } elsif ($item eq 'helpurl') {
6498: if (ref($changes{$item}) eq 'HASH') {
6499: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6500: if (grep(/^\Q$lang\E$/,@delurls)) {
6501: my ($chg,$link);
6502: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6503: if ($lang eq 'nolang') {
6504: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6505: } else {
6506: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6507: }
6508: $resulttext .= '<li>'.$chg.'</li>';
6509: } else {
6510: my $chg;
6511: if ($lang eq 'nolang') {
6512: $chg = &mt('custom log-in help file for no preferred language');
6513: } else {
6514: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6515: }
6516: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6517: $loginhash{'login'}{'helpurl'}{$lang}.
6518: '?inhibitmenu=yes',$chg,600,500).
6519: '</li>';
6520: }
6521: }
6522: }
1.160.6.56 raeburn 6523: } elsif ($item eq 'headtag') {
6524: if (ref($changes{$item}) eq 'HASH') {
6525: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6526: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6527: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6528: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6529: $resulttext .= '<li><a href="'.
6530: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6531: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6532: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6533: if ($possexempt{$lonhost}) {
6534: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6535: } else {
6536: $resulttext .= &mt('included for any client IP');
6537: }
6538: $resulttext .= '</li>';
6539: }
6540: }
6541: }
1.160.6.5 raeburn 6542: } elsif ($item eq 'captcha') {
6543: if (ref($loginhash{'login'}) eq 'HASH') {
6544: my $chgtxt;
6545: if ($loginhash{'login'}{$item} eq 'notused') {
6546: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6547: } else {
6548: my %captchas = &captcha_phrases();
6549: if ($captchas{$loginhash{'login'}{$item}}) {
6550: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6551: } else {
6552: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6553: }
6554: }
6555: $resulttext .= '<li>'.$chgtxt.'</li>';
6556: }
6557: } elsif ($item eq 'recaptchakeys') {
6558: if (ref($loginhash{'login'}) eq 'HASH') {
6559: my ($privkey,$pubkey);
6560: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6561: $pubkey = $loginhash{'login'}{$item}{'public'};
6562: $privkey = $loginhash{'login'}{$item}{'private'};
6563: }
6564: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6565: if (!$pubkey) {
6566: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6567: } else {
6568: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6569: }
6570: if (!$privkey) {
6571: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6572: } else {
1.160.6.53 raeburn 6573: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6574: }
6575: $chgtxt .= '</ul>';
6576: $resulttext .= '<li>'.$chgtxt.'</li>';
6577: }
1.160.6.69 raeburn 6578: } elsif ($item eq 'recaptchaversion') {
6579: if (ref($loginhash{'login'}) eq 'HASH') {
6580: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
6581: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
6582: '</li>';
6583: }
6584: }
1.41 raeburn 6585: } else {
6586: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6587: }
1.1 raeburn 6588: }
1.6 raeburn 6589: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6590: } else {
6591: $resulttext = &mt('No changes made to log-in page settings');
6592: }
6593: } else {
1.11 albertel 6594: $resulttext = '<span class="LC_error">'.
6595: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6596: }
1.6 raeburn 6597: if ($errors) {
1.9 raeburn 6598: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6599: $errors.'</ul>';
6600: }
6601: return $resulttext;
6602: }
6603:
1.160.6.56 raeburn 6604: sub check_exempt_addresses {
6605: my ($iplist) = @_;
6606: $iplist =~ s/^\s+//;
6607: $iplist =~ s/\s+$//;
6608: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6609: my (@okips,$new);
6610: foreach my $ip (@poss_ips) {
6611: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6612: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6613: push(@okips,$ip);
6614: }
6615: }
6616: }
6617: if (@okips > 0) {
6618: $new = join(',',@okips);
6619: } else {
6620: $new = '';
6621: }
6622: return $new;
6623: }
6624:
1.6 raeburn 6625: sub color_font_choices {
6626: my %choices =
6627: &Apache::lonlocal::texthash (
6628: img => "Header",
6629: bgs => "Background colors",
6630: links => "Link colors",
1.55 raeburn 6631: images => "Images",
1.6 raeburn 6632: font => "Font color",
1.160.6.22 raeburn 6633: fontmenu => "Font menu",
1.76 raeburn 6634: pgbg => "Page",
1.6 raeburn 6635: tabbg => "Header",
6636: sidebg => "Border",
6637: link => "Link",
6638: alink => "Active link",
6639: vlink => "Visited link",
6640: );
6641: return %choices;
6642: }
6643:
6644: sub modify_rolecolors {
1.160.6.24 raeburn 6645: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6646: my ($resulttext,%rolehash);
6647: $rolehash{'rolecolors'} = {};
1.55 raeburn 6648: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6649: if ($domconfig{'rolecolors'} eq '') {
6650: $domconfig{'rolecolors'} = {};
6651: }
6652: }
1.9 raeburn 6653: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6654: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6655: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6656: $dom);
6657: if ($putresult eq 'ok') {
6658: if (keys(%changes) > 0) {
1.41 raeburn 6659: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6660: if (ref($lastactref) eq 'HASH') {
6661: $lastactref->{'domainconfig'} = 1;
6662: }
1.6 raeburn 6663: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6664: $rolehash{'rolecolors'});
6665: } else {
6666: $resulttext = &mt('No changes made to default color schemes');
6667: }
6668: } else {
1.11 albertel 6669: $resulttext = '<span class="LC_error">'.
6670: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6671: }
6672: if ($errors) {
6673: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6674: $errors.'</ul>';
6675: }
6676: return $resulttext;
6677: }
6678:
6679: sub modify_colors {
1.9 raeburn 6680: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6681: my (%changes,%choices);
1.51 raeburn 6682: my @bgs;
1.6 raeburn 6683: my @links = ('link','alink','vlink');
1.41 raeburn 6684: my @logintext;
1.6 raeburn 6685: my @images;
6686: my $servadm = $r->dir_config('lonAdmEMail');
6687: my $errors;
1.160.6.22 raeburn 6688: my %defaults;
1.6 raeburn 6689: foreach my $role (@{$roles}) {
6690: if ($role eq 'login') {
1.12 raeburn 6691: %choices = &login_choices();
1.41 raeburn 6692: @logintext = ('textcol','bgcol');
1.12 raeburn 6693: } else {
6694: %choices = &color_font_choices();
6695: }
6696: if ($role eq 'login') {
1.41 raeburn 6697: @images = ('img','logo','domlogo','login');
1.51 raeburn 6698: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6699: } else {
6700: @images = ('img');
1.160.6.22 raeburn 6701: @bgs = ('pgbg','tabbg','sidebg');
6702: }
6703: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6704: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6705: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6706: }
6707: if ($role eq 'login') {
6708: foreach my $item (@logintext) {
1.160.6.39 raeburn 6709: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6710: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6711: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6712: }
6713: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6714: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6715: }
6716: }
6717: } else {
1.160.6.39 raeburn 6718: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6719: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6720: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6721: }
6722: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6723: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6724: }
1.6 raeburn 6725: }
1.160.6.22 raeburn 6726: foreach my $item (@bgs) {
1.160.6.39 raeburn 6727: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6728: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6729: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6730: }
6731: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6732: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6733: }
6734: }
6735: foreach my $item (@links) {
1.160.6.39 raeburn 6736: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6737: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6738: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6739: }
6740: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6741: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6742: }
1.6 raeburn 6743: }
1.46 raeburn 6744: my ($configuserok,$author_ok,$switchserver) =
6745: &config_check($dom,$confname,$servadm);
1.9 raeburn 6746: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6747: if (ref($domconfig->{$role}) ne 'HASH') {
6748: $domconfig->{$role} = {};
6749: }
1.8 raeburn 6750: foreach my $img (@images) {
1.70 raeburn 6751: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6752: if (defined($env{'form.login_showlogo_'.$img})) {
6753: $confhash->{$role}{'showlogo'}{$img} = 1;
6754: } else {
6755: $confhash->{$role}{'showlogo'}{$img} = 0;
6756: }
6757: }
1.18 albertel 6758: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6759: && !defined($domconfig->{$role}{$img})
6760: && !$env{'form.'.$role.'_del_'.$img}
6761: && $env{'form.'.$role.'_import_'.$img}) {
6762: # import the old configured image from the .tab setting
6763: # if they haven't provided a new one
6764: $domconfig->{$role}{$img} =
6765: $env{'form.'.$role.'_import_'.$img};
6766: }
1.6 raeburn 6767: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6768: my $error;
1.6 raeburn 6769: if ($configuserok eq 'ok') {
1.9 raeburn 6770: if ($switchserver) {
1.12 raeburn 6771: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6772: } else {
6773: if ($author_ok eq 'ok') {
6774: my ($result,$logourl) =
6775: &publishlogo($r,'upload',$role.'_'.$img,
6776: $dom,$confname,$img,$width,$height);
6777: if ($result eq 'ok') {
6778: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6779: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6780: } else {
1.12 raeburn 6781: $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 6782: }
6783: } else {
1.46 raeburn 6784: $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 6785: }
6786: }
6787: } else {
1.46 raeburn 6788: $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 6789: }
6790: if ($error) {
1.8 raeburn 6791: &Apache::lonnet::logthis($error);
1.11 albertel 6792: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6793: }
6794: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6795: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6796: my $error;
6797: if ($configuserok eq 'ok') {
6798: # is confname an author?
6799: if ($switchserver eq '') {
6800: if ($author_ok eq 'ok') {
6801: my ($result,$logourl) =
6802: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6803: $dom,$confname,$img,$width,$height);
6804: if ($result eq 'ok') {
6805: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6806: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6807: }
6808: }
6809: }
6810: }
1.6 raeburn 6811: }
6812: }
6813: }
6814: if (ref($domconfig) eq 'HASH') {
6815: if (ref($domconfig->{$role}) eq 'HASH') {
6816: foreach my $img (@images) {
6817: if ($domconfig->{$role}{$img} ne '') {
6818: if ($env{'form.'.$role.'_del_'.$img}) {
6819: $confhash->{$role}{$img} = '';
1.12 raeburn 6820: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6821: } else {
1.9 raeburn 6822: if ($confhash->{$role}{$img} eq '') {
6823: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6824: }
1.6 raeburn 6825: }
6826: } else {
6827: if ($env{'form.'.$role.'_del_'.$img}) {
6828: $confhash->{$role}{$img} = '';
1.12 raeburn 6829: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6830: }
6831: }
1.70 raeburn 6832: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6833: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6834: if ($confhash->{$role}{'showlogo'}{$img} ne
6835: $domconfig->{$role}{'showlogo'}{$img}) {
6836: $changes{$role}{'showlogo'}{$img} = 1;
6837: }
6838: } else {
6839: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6840: $changes{$role}{'showlogo'}{$img} = 1;
6841: }
6842: }
6843: }
6844: }
1.6 raeburn 6845: if ($domconfig->{$role}{'font'} ne '') {
6846: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6847: $changes{$role}{'font'} = 1;
6848: }
6849: } else {
6850: if ($confhash->{$role}{'font'}) {
6851: $changes{$role}{'font'} = 1;
6852: }
6853: }
1.107 raeburn 6854: if ($role ne 'login') {
6855: if ($domconfig->{$role}{'fontmenu'} ne '') {
6856: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6857: $changes{$role}{'fontmenu'} = 1;
6858: }
6859: } else {
6860: if ($confhash->{$role}{'fontmenu'}) {
6861: $changes{$role}{'fontmenu'} = 1;
6862: }
1.97 tempelho 6863: }
6864: }
1.6 raeburn 6865: foreach my $item (@bgs) {
6866: if ($domconfig->{$role}{$item} ne '') {
6867: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6868: $changes{$role}{'bgs'}{$item} = 1;
6869: }
6870: } else {
6871: if ($confhash->{$role}{$item}) {
6872: $changes{$role}{'bgs'}{$item} = 1;
6873: }
6874: }
6875: }
6876: foreach my $item (@links) {
6877: if ($domconfig->{$role}{$item} ne '') {
6878: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6879: $changes{$role}{'links'}{$item} = 1;
6880: }
6881: } else {
6882: if ($confhash->{$role}{$item}) {
6883: $changes{$role}{'links'}{$item} = 1;
6884: }
6885: }
6886: }
1.41 raeburn 6887: foreach my $item (@logintext) {
6888: if ($domconfig->{$role}{$item} ne '') {
6889: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6890: $changes{$role}{'logintext'}{$item} = 1;
6891: }
6892: } else {
6893: if ($confhash->{$role}{$item}) {
6894: $changes{$role}{'logintext'}{$item} = 1;
6895: }
6896: }
6897: }
1.6 raeburn 6898: } else {
6899: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6900: \@logintext,$confhash,\%changes);
1.6 raeburn 6901: }
6902: } else {
6903: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6904: \@logintext,$confhash,\%changes);
1.6 raeburn 6905: }
6906: }
6907: return ($errors,%changes);
6908: }
6909:
1.46 raeburn 6910: sub config_check {
6911: my ($dom,$confname,$servadm) = @_;
6912: my ($configuserok,$author_ok,$switchserver,%currroles);
6913: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6914: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6915: $confname,$servadm);
6916: if ($configuserok eq 'ok') {
6917: $switchserver = &check_switchserver($dom,$confname);
6918: if ($switchserver eq '') {
6919: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6920: }
6921: }
6922: return ($configuserok,$author_ok,$switchserver);
6923: }
6924:
1.6 raeburn 6925: sub default_change_checker {
1.41 raeburn 6926: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6927: foreach my $item (@{$links}) {
6928: if ($confhash->{$role}{$item}) {
6929: $changes->{$role}{'links'}{$item} = 1;
6930: }
6931: }
6932: foreach my $item (@{$bgs}) {
6933: if ($confhash->{$role}{$item}) {
6934: $changes->{$role}{'bgs'}{$item} = 1;
6935: }
6936: }
1.41 raeburn 6937: foreach my $item (@{$logintext}) {
6938: if ($confhash->{$role}{$item}) {
6939: $changes->{$role}{'logintext'}{$item} = 1;
6940: }
6941: }
1.6 raeburn 6942: foreach my $img (@{$images}) {
6943: if ($env{'form.'.$role.'_del_'.$img}) {
6944: $confhash->{$role}{$img} = '';
1.12 raeburn 6945: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6946: }
1.70 raeburn 6947: if ($role eq 'login') {
6948: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6949: $changes->{$role}{'showlogo'}{$img} = 1;
6950: }
6951: }
1.6 raeburn 6952: }
6953: if ($confhash->{$role}{'font'}) {
6954: $changes->{$role}{'font'} = 1;
6955: }
1.48 raeburn 6956: }
1.6 raeburn 6957:
6958: sub display_colorchgs {
6959: my ($dom,$changes,$roles,$confhash) = @_;
6960: my (%choices,$resulttext);
6961: if (!grep(/^login$/,@{$roles})) {
6962: $resulttext = &mt('Changes made:').'<br />';
6963: }
6964: foreach my $role (@{$roles}) {
6965: if ($role eq 'login') {
6966: %choices = &login_choices();
6967: } else {
6968: %choices = &color_font_choices();
6969: }
6970: if (ref($changes->{$role}) eq 'HASH') {
6971: if ($role ne 'login') {
6972: $resulttext .= '<h4>'.&mt($role).'</h4>';
6973: }
6974: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6975: if ($role ne 'login') {
6976: $resulttext .= '<ul>';
6977: }
6978: if (ref($changes->{$role}{$key}) eq 'HASH') {
6979: if ($role ne 'login') {
6980: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6981: }
6982: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6983: if (($role eq 'login') && ($key eq 'showlogo')) {
6984: if ($confhash->{$role}{$key}{$item}) {
6985: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6986: } else {
6987: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6988: }
6989: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6990: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6991: } else {
1.12 raeburn 6992: my $newitem = $confhash->{$role}{$item};
6993: if ($key eq 'images') {
6994: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6995: }
6996: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6997: }
6998: }
6999: if ($role ne 'login') {
7000: $resulttext .= '</ul></li>';
7001: }
7002: } else {
7003: if ($confhash->{$role}{$key} eq '') {
7004: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7005: } else {
7006: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7007: }
7008: }
7009: if ($role ne 'login') {
7010: $resulttext .= '</ul>';
7011: }
7012: }
7013: }
7014: }
1.3 raeburn 7015: return $resulttext;
1.1 raeburn 7016: }
7017:
1.9 raeburn 7018: sub thumb_dimensions {
7019: return ('200','50');
7020: }
7021:
1.16 raeburn 7022: sub check_dimensions {
7023: my ($inputfile) = @_;
7024: my ($fullwidth,$fullheight);
7025: if ($inputfile =~ m|^[/\w.\-]+$|) {
7026: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7027: my $imageinfo = <PIPE>;
7028: if (!close(PIPE)) {
7029: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7030: }
7031: chomp($imageinfo);
7032: my ($fullsize) =
1.21 raeburn 7033: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7034: if ($fullsize) {
7035: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7036: }
7037: }
7038: }
7039: return ($fullwidth,$fullheight);
7040: }
7041:
1.9 raeburn 7042: sub check_configuser {
7043: my ($uhome,$dom,$confname,$servadm) = @_;
7044: my ($configuserok,%currroles);
7045: if ($uhome eq 'no_host') {
7046: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7047: my $configpass = &LONCAPA::Enrollment::create_password();
7048: $configuserok =
7049: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7050: $configpass,'','','','','',undef,$servadm);
7051: } else {
7052: $configuserok = 'ok';
7053: %currroles =
7054: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7055: }
7056: return ($configuserok,%currroles);
7057: }
7058:
7059: sub check_authorstatus {
7060: my ($dom,$confname,%currroles) = @_;
7061: my $author_ok;
1.40 raeburn 7062: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7063: my $start = time;
7064: my $end = 0;
7065: $author_ok =
7066: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7067: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7068: } else {
7069: $author_ok = 'ok';
7070: }
7071: return $author_ok;
7072: }
7073:
7074: sub publishlogo {
1.46 raeburn 7075: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7076: my ($output,$fname,$logourl);
7077: if ($action eq 'upload') {
7078: $fname=$env{'form.'.$formname.'.filename'};
7079: chop($env{'form.'.$formname});
7080: } else {
7081: ($fname) = ($formname =~ /([^\/]+)$/);
7082: }
1.46 raeburn 7083: if ($savefileas ne '') {
7084: $fname = $savefileas;
7085: }
1.9 raeburn 7086: $fname=&Apache::lonnet::clean_filename($fname);
7087: # See if there is anything left
7088: unless ($fname) { return ('error: no uploaded file'); }
7089: $fname="$subdir/$fname";
1.160.6.5 raeburn 7090: my $docroot=$r->dir_config('lonDocRoot');
7091: my $filepath="$docroot/priv";
7092: my $relpath = "$dom/$confname";
1.9 raeburn 7093: my ($fnamepath,$file,$fetchthumb);
7094: $file=$fname;
7095: if ($fname=~m|/|) {
7096: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7097: }
1.160.6.26 raeburn 7098: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7099: my $count;
1.160.6.5 raeburn 7100: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7101: $filepath.="/$parts[$count]";
7102: if ((-e $filepath)!=1) {
7103: mkdir($filepath,02770);
7104: }
7105: }
7106: # Check for bad extension and disallow upload
7107: if ($file=~/\.(\w+)$/ &&
7108: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7109: $output =
1.160.6.25 raeburn 7110: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7111: } elsif ($file=~/\.(\w+)$/ &&
7112: !defined(&Apache::loncommon::fileembstyle($1))) {
7113: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7114: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7115: $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 7116: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7117: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7118: } else {
7119: my $source = $filepath.'/'.$file;
7120: my $logfile;
7121: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7122: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7123: }
7124: print $logfile
7125: "\n================= Publish ".localtime()." ================\n".
7126: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7127: # Save the file
7128: if (!open(FH,'>'.$source)) {
7129: &Apache::lonnet::logthis('Failed to create '.$source);
7130: return (&mt('Failed to create file'));
7131: }
7132: if ($action eq 'upload') {
7133: if (!print FH ($env{'form.'.$formname})) {
7134: &Apache::lonnet::logthis('Failed to write to '.$source);
7135: return (&mt('Failed to write file'));
7136: }
7137: } else {
7138: my $original = &Apache::lonnet::filelocation('',$formname);
7139: if(!copy($original,$source)) {
7140: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7141: return (&mt('Failed to write file'));
7142: }
7143: }
7144: close(FH);
7145: chmod(0660, $source); # Permissions to rw-rw---.
7146:
7147: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7148: my $copyfile=$targetdir.'/'.$file;
7149:
7150: my @parts=split(/\//,$targetdir);
7151: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7152: for (my $count=5;$count<=$#parts;$count++) {
7153: $path.="/$parts[$count]";
7154: if (!-e $path) {
7155: print $logfile "\nCreating directory ".$path;
7156: mkdir($path,02770);
7157: }
7158: }
7159: my $versionresult;
7160: if (-e $copyfile) {
7161: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7162: } else {
7163: $versionresult = 'ok';
7164: }
7165: if ($versionresult eq 'ok') {
7166: if (copy($source,$copyfile)) {
7167: print $logfile "\nCopied original source to ".$copyfile."\n";
7168: $output = 'ok';
7169: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7170: push(@{$modified_urls},[$copyfile,$source]);
7171: my $metaoutput =
7172: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7173: unless ($registered_cleanup) {
7174: my $handlers = $r->get_handlers('PerlCleanupHandler');
7175: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7176: $registered_cleanup=1;
7177: }
1.9 raeburn 7178: } else {
7179: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7180: $output = &mt('Failed to copy file to RES space').", $!";
7181: }
7182: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7183: my $inputfile = $filepath.'/'.$file;
7184: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7185: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7186: if ($fullwidth ne '' && $fullheight ne '') {
7187: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7188: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7189: system("convert -sample $thumbsize $inputfile $outfile");
7190: chmod(0660, $filepath.'/tn-'.$file);
7191: if (-e $outfile) {
7192: my $copyfile=$targetdir.'/tn-'.$file;
7193: if (copy($outfile,$copyfile)) {
7194: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7195: my $thumb_metaoutput =
7196: &write_metadata($dom,$confname,$formname,
7197: $targetdir,'tn-'.$file,$logfile);
7198: push(@{$modified_urls},[$copyfile,$outfile]);
7199: unless ($registered_cleanup) {
7200: my $handlers = $r->get_handlers('PerlCleanupHandler');
7201: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7202: $registered_cleanup=1;
7203: }
1.16 raeburn 7204: } else {
7205: print $logfile "\nUnable to write ".$copyfile.
7206: ':'.$!."\n";
7207: }
7208: }
1.9 raeburn 7209: }
7210: }
7211: }
7212: } else {
7213: $output = $versionresult;
7214: }
7215: }
7216: return ($output,$logourl);
7217: }
7218:
7219: sub logo_versioning {
7220: my ($targetdir,$file,$logfile) = @_;
7221: my $target = $targetdir.'/'.$file;
7222: my ($maxversion,$fn,$extn,$output);
7223: $maxversion = 0;
7224: if ($file =~ /^(.+)\.(\w+)$/) {
7225: $fn=$1;
7226: $extn=$2;
7227: }
7228: opendir(DIR,$targetdir);
7229: while (my $filename=readdir(DIR)) {
7230: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7231: $maxversion=($1>$maxversion)?$1:$maxversion;
7232: }
7233: }
7234: $maxversion++;
7235: print $logfile "\nCreating old version ".$maxversion."\n";
7236: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7237: if (copy($target,$copyfile)) {
7238: print $logfile "Copied old target to ".$copyfile."\n";
7239: $copyfile=$copyfile.'.meta';
7240: if (copy($target.'.meta',$copyfile)) {
7241: print $logfile "Copied old target metadata to ".$copyfile."\n";
7242: $output = 'ok';
7243: } else {
7244: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7245: $output = &mt('Failed to copy old meta').", $!, ";
7246: }
7247: } else {
7248: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7249: $output = &mt('Failed to copy old target').", $!, ";
7250: }
7251: return $output;
7252: }
7253:
7254: sub write_metadata {
7255: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7256: my (%metadatafields,%metadatakeys,$output);
7257: $metadatafields{'title'}=$formname;
7258: $metadatafields{'creationdate'}=time;
7259: $metadatafields{'lastrevisiondate'}=time;
7260: $metadatafields{'copyright'}='public';
7261: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7262: $env{'user.domain'};
7263: $metadatafields{'authorspace'}=$confname.':'.$dom;
7264: $metadatafields{'domain'}=$dom;
7265: {
7266: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7267: my $mfh;
1.155 raeburn 7268: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7269: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7270: unless ($_=~/\./) {
7271: my $unikey=$_;
7272: $unikey=~/^([A-Za-z]+)/;
7273: my $tag=$1;
7274: $tag=~tr/A-Z/a-z/;
7275: print $mfh "\n\<$tag";
7276: foreach (split(/\,/,$metadatakeys{$unikey})) {
7277: my $value=$metadatafields{$unikey.'.'.$_};
7278: $value=~s/\"/\'\'/g;
7279: print $mfh ' '.$_.'="'.$value.'"';
7280: }
7281: print $mfh '>'.
7282: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7283: .'</'.$tag.'>';
7284: }
7285: }
7286: $output = 'ok';
7287: print $logfile "\nWrote metadata";
7288: close($mfh);
7289: } else {
7290: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7291: $output = &mt('Could not write metadata');
7292: }
7293: }
1.155 raeburn 7294: return $output;
7295: }
7296:
7297: sub notifysubscribed {
7298: foreach my $targetsource (@{$modified_urls}){
7299: next unless (ref($targetsource) eq 'ARRAY');
7300: my ($target,$source)=@{$targetsource};
7301: if ($source ne '') {
7302: if (open(my $logfh,'>>'.$source.'.log')) {
7303: print $logfh "\nCleanup phase: Notifications\n";
7304: my @subscribed=&subscribed_hosts($target);
7305: foreach my $subhost (@subscribed) {
7306: print $logfh "\nNotifying host ".$subhost.':';
7307: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7308: print $logfh $reply;
7309: }
7310: my @subscribedmeta=&subscribed_hosts("$target.meta");
7311: foreach my $subhost (@subscribedmeta) {
7312: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7313: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7314: $subhost);
7315: print $logfh $reply;
7316: }
7317: print $logfh "\n============ Done ============\n";
1.160 raeburn 7318: close($logfh);
1.155 raeburn 7319: }
7320: }
7321: }
7322: return OK;
7323: }
7324:
7325: sub subscribed_hosts {
7326: my ($target) = @_;
7327: my @subscribed;
7328: if (open(my $fh,"<$target.subscription")) {
7329: while (my $subline=<$fh>) {
7330: if ($subline =~ /^($match_lonid):/) {
7331: my $host = $1;
7332: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7333: unless (grep(/^\Q$host\E$/,@subscribed)) {
7334: push(@subscribed,$host);
7335: }
7336: }
7337: }
7338: }
7339: }
7340: return @subscribed;
1.9 raeburn 7341: }
7342:
7343: sub check_switchserver {
7344: my ($dom,$confname) = @_;
7345: my ($allowed,$switchserver);
7346: my $home = &Apache::lonnet::homeserver($confname,$dom);
7347: if ($home eq 'no_host') {
7348: $home = &Apache::lonnet::domain($dom,'primary');
7349: }
7350: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7351: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7352: if (!$allowed) {
1.160.6.11 raeburn 7353: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7354: }
7355: return $switchserver;
7356: }
7357:
1.1 raeburn 7358: sub modify_quotas {
1.160.6.30 raeburn 7359: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7360: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7361: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7362: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7363: $validationfieldsref);
1.86 raeburn 7364: if ($action eq 'quotas') {
7365: $context = 'tools';
1.160.6.26 raeburn 7366: } else {
1.86 raeburn 7367: $context = $action;
7368: }
7369: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7370: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7371: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7372: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7373: %titles = &courserequest_titles();
7374: $toolregexp = join('|',@usertools);
7375: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7376: $confname = $dom.'-domainconfig';
7377: my $servadm = $r->dir_config('lonAdmEMail');
7378: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7379: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7380: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7381: } elsif ($context eq 'requestauthor') {
7382: @usertools = ('author');
7383: %titles = &authorrequest_titles();
1.86 raeburn 7384: } else {
1.160.6.4 raeburn 7385: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7386: %titles = &tool_titles();
1.86 raeburn 7387: }
1.160.6.27 raeburn 7388: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7389: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7390: foreach my $key (keys(%env)) {
1.101 raeburn 7391: if ($context eq 'requestcourses') {
7392: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7393: my $item = $1;
7394: my $type = $2;
7395: if ($type =~ /^limit_(.+)/) {
7396: $limithash{$item}{$1} = $env{$key};
7397: } else {
7398: $confhash{$item}{$type} = $env{$key};
7399: }
7400: }
1.160.6.5 raeburn 7401: } elsif ($context eq 'requestauthor') {
7402: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7403: $confhash{$1} = $env{$key};
7404: }
1.101 raeburn 7405: } else {
1.86 raeburn 7406: if ($key =~ /^form\.quota_(.+)$/) {
7407: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7408: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7409: $confhash{'authorquota'}{$1} = $env{$key};
7410: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7411: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7412: }
1.72 raeburn 7413: }
7414: }
1.160.6.5 raeburn 7415: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7416: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7417: @approvalnotify = sort(@approvalnotify);
7418: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7419: my @crstypes = ('official','unofficial','community','textbook');
7420: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7421: foreach my $type (@hasuniquecode) {
7422: if (grep(/^\Q$type\E$/,@crstypes)) {
7423: $confhash{'uniquecode'}{$type} = 1;
7424: }
7425: }
1.160.6.46 raeburn 7426: my (%newbook,%allpos);
1.160.6.30 raeburn 7427: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7428: foreach my $type ('textbooks','templates') {
7429: @{$allpos{$type}} = ();
7430: my $invalid;
7431: if ($type eq 'textbooks') {
7432: $invalid = &mt('Invalid LON-CAPA course for textbook');
7433: } else {
7434: $invalid = &mt('Invalid LON-CAPA course for template');
7435: }
7436: if ($env{'form.'.$type.'_addbook'}) {
7437: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7438: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7439: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7440: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7441: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7442: } else {
7443: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7444: my $position = $env{'form.'.$type.'_addbook_pos'};
7445: $position =~ s/\D+//g;
7446: if ($position ne '') {
7447: $allpos{$type}[$position] = $newbook{$type};
7448: }
1.160.6.30 raeburn 7449: }
1.160.6.46 raeburn 7450: } else {
7451: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7452: }
7453: }
1.160.6.46 raeburn 7454: }
1.160.6.30 raeburn 7455: }
1.102 raeburn 7456: if (ref($domconfig{$action}) eq 'HASH') {
7457: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7458: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7459: $changes{'notify'}{'approval'} = 1;
7460: }
7461: } else {
1.144 raeburn 7462: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7463: $changes{'notify'}{'approval'} = 1;
7464: }
7465: }
1.160.6.30 raeburn 7466: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7467: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7468: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7469: unless ($confhash{'uniquecode'}{$crstype}) {
7470: $changes{'uniquecode'} = 1;
7471: }
7472: }
7473: unless ($changes{'uniquecode'}) {
7474: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7475: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7476: $changes{'uniquecode'} = 1;
7477: }
7478: }
7479: }
7480: } else {
7481: $changes{'uniquecode'} = 1;
7482: }
7483: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7484: $changes{'uniquecode'} = 1;
7485: }
7486: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7487: foreach my $type ('textbooks','templates') {
7488: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7489: my %deletions;
7490: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7491: if (@todelete) {
7492: map { $deletions{$_} = 1; } @todelete;
7493: }
7494: my %imgdeletions;
7495: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7496: if (@todeleteimages) {
7497: map { $imgdeletions{$_} = 1; } @todeleteimages;
7498: }
7499: my $maxnum = $env{'form.'.$type.'_maxnum'};
7500: for (my $i=0; $i<=$maxnum; $i++) {
7501: my $itemid = $env{'form.'.$type.'_id_'.$i};
7502: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7503: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7504: if ($deletions{$key}) {
7505: if ($domconfig{$action}{$type}{$key}{'image'}) {
7506: #FIXME need to obsolete item in RES space
7507: }
7508: next;
7509: } else {
7510: my $newpos = $env{'form.'.$itemid};
7511: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7512: foreach my $item ('subject','title','publisher','author') {
7513: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7514: ($type eq 'templates'));
1.160.6.46 raeburn 7515: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7516: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7517: $changes{$type}{$key} = 1;
7518: }
7519: }
7520: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7521: }
1.160.6.46 raeburn 7522: if ($imgdeletions{$key}) {
7523: $changes{$type}{$key} = 1;
7524: #FIXME need to obsolete item in RES space
7525: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7526: my ($cdom,$cnum) = split(/_/,$key);
7527: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7528: $cdom,$cnum,$type,$configuserok,
7529: $switchserver,$author_ok);
7530: if ($imgurl) {
7531: $confhash{$type}{$key}{'image'} = $imgurl;
7532: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7533: }
1.160.6.46 raeburn 7534: if ($error) {
7535: &Apache::lonnet::logthis($error);
7536: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7537: }
7538: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7539: $confhash{$type}{$key}{'image'} =
7540: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7541: }
7542: }
7543: }
7544: }
7545: }
7546: }
1.102 raeburn 7547: } else {
1.144 raeburn 7548: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7549: $changes{'notify'}{'approval'} = 1;
7550: }
1.160.6.30 raeburn 7551: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7552: $changes{'uniquecode'} = 1;
7553: }
7554: }
7555: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7556: foreach my $type ('textbooks','templates') {
7557: if ($newbook{$type}) {
7558: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7559: foreach my $item ('subject','title','publisher','author') {
7560: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7561: ($type eq 'template'));
1.160.6.46 raeburn 7562: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7563: if ($env{'form.'.$type.'_addbook_'.$item}) {
7564: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7565: }
7566: }
7567: if ($type eq 'textbooks') {
7568: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7569: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7570: my ($imageurl,$error) =
7571: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7572: $configuserok,$switchserver,$author_ok);
7573: if ($imageurl) {
7574: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7575: }
7576: if ($error) {
7577: &Apache::lonnet::logthis($error);
7578: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7579: }
7580: }
1.160.6.30 raeburn 7581: }
7582: }
1.160.6.46 raeburn 7583: if (@{$allpos{$type}} > 0) {
7584: my $idx = 0;
7585: foreach my $item (@{$allpos{$type}}) {
7586: if ($item ne '') {
7587: $confhash{$type}{$item}{'order'} = $idx;
7588: if (ref($domconfig{$action}) eq 'HASH') {
7589: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7590: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7591: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7592: $changes{$type}{$item} = 1;
7593: }
1.160.6.30 raeburn 7594: }
7595: }
7596: }
1.160.6.46 raeburn 7597: $idx ++;
1.160.6.30 raeburn 7598: }
7599: }
7600: }
7601: }
1.160.6.39 raeburn 7602: if (ref($validationitemsref) eq 'ARRAY') {
7603: foreach my $item (@{$validationitemsref}) {
7604: if ($item eq 'fields') {
7605: my @changed;
7606: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7607: if (@{$confhash{'validation'}{$item}} > 0) {
7608: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7609: }
1.160.6.65 raeburn 7610: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7611: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7612: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7613: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7614: $domconfig{'requestcourses'}{'validation'}{$item});
7615: } else {
7616: @changed = @{$confhash{'validation'}{$item}};
7617: }
1.160.6.39 raeburn 7618: } else {
7619: @changed = @{$confhash{'validation'}{$item}};
7620: }
7621: } else {
7622: @changed = @{$confhash{'validation'}{$item}};
7623: }
7624: if (@changed) {
7625: if ($confhash{'validation'}{$item}) {
7626: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7627: } else {
7628: $changes{'validation'}{$item} = &mt('None');
7629: }
7630: }
7631: } else {
7632: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7633: if ($item eq 'markup') {
7634: if ($env{'form.requestcourses_validation_'.$item}) {
7635: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7636: }
7637: }
1.160.6.65 raeburn 7638: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7639: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7640: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7641: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7642: }
7643: } else {
7644: if ($confhash{'validation'}{$item} ne '') {
7645: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7646: }
1.160.6.39 raeburn 7647: }
7648: } else {
7649: if ($confhash{'validation'}{$item} ne '') {
7650: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7651: }
7652: }
7653: }
7654: }
7655: }
7656: if ($env{'form.validationdc'}) {
7657: my $newval = $env{'form.validationdc'};
7658: my %domcoords = &get_active_dcs($dom);
7659: if (exists($domcoords{$newval})) {
7660: $confhash{'validation'}{'dc'} = $newval;
7661: }
7662: }
7663: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 7664: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7665: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7666: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7667: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7668: if ($confhash{'validation'}{'dc'} eq '') {
7669: $changes{'validation'}{'dc'} = &mt('None');
7670: } else {
7671: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7672: }
1.160.6.39 raeburn 7673: }
1.160.6.65 raeburn 7674: } elsif ($confhash{'validation'}{'dc'} ne '') {
7675: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 7676: }
7677: } elsif ($confhash{'validation'}{'dc'} ne '') {
7678: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7679: }
7680: } elsif ($confhash{'validation'}{'dc'} ne '') {
7681: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7682: }
1.160.6.65 raeburn 7683: } else {
7684: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7685: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7686: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7687: $changes{'validation'}{'dc'} = &mt('None');
7688: }
7689: }
1.160.6.39 raeburn 7690: }
7691: }
1.102 raeburn 7692: }
7693: } else {
1.86 raeburn 7694: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7695: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7696: }
1.72 raeburn 7697: foreach my $item (@usertools) {
7698: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7699: my $unset;
1.101 raeburn 7700: if ($context eq 'requestcourses') {
1.104 raeburn 7701: $unset = '0';
7702: if ($type eq '_LC_adv') {
7703: $unset = '';
7704: }
1.101 raeburn 7705: if ($confhash{$item}{$type} eq 'autolimit') {
7706: $confhash{$item}{$type} .= '=';
7707: unless ($limithash{$item}{$type} =~ /\D/) {
7708: $confhash{$item}{$type} .= $limithash{$item}{$type};
7709: }
7710: }
1.160.6.5 raeburn 7711: } elsif ($context eq 'requestauthor') {
7712: $unset = '0';
7713: if ($type eq '_LC_adv') {
7714: $unset = '';
7715: }
1.72 raeburn 7716: } else {
1.101 raeburn 7717: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7718: $confhash{$item}{$type} = 1;
7719: } else {
7720: $confhash{$item}{$type} = 0;
7721: }
1.72 raeburn 7722: }
1.86 raeburn 7723: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7724: if ($action eq 'requestauthor') {
7725: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7726: $changes{$type} = 1;
7727: }
7728: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7729: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7730: $changes{$item}{$type} = 1;
7731: }
7732: } else {
7733: if ($context eq 'requestcourses') {
1.104 raeburn 7734: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7735: $changes{$item}{$type} = 1;
7736: }
7737: } else {
7738: if (!$confhash{$item}{$type}) {
7739: $changes{$item}{$type} = 1;
7740: }
7741: }
7742: }
7743: } else {
7744: if ($context eq 'requestcourses') {
1.104 raeburn 7745: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7746: $changes{$item}{$type} = 1;
7747: }
1.160.6.5 raeburn 7748: } elsif ($context eq 'requestauthor') {
7749: if ($confhash{$type} ne $unset) {
7750: $changes{$type} = 1;
7751: }
1.72 raeburn 7752: } else {
7753: if (!$confhash{$item}{$type}) {
7754: $changes{$item}{$type} = 1;
7755: }
7756: }
7757: }
1.1 raeburn 7758: }
7759: }
1.160.6.5 raeburn 7760: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7761: if (ref($domconfig{'quotas'}) eq 'HASH') {
7762: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7763: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7764: if (exists($confhash{'defaultquota'}{$key})) {
7765: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7766: $changes{'defaultquota'}{$key} = 1;
7767: }
7768: } else {
7769: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7770: }
7771: }
1.86 raeburn 7772: } else {
7773: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7774: if (exists($confhash{'defaultquota'}{$key})) {
7775: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7776: $changes{'defaultquota'}{$key} = 1;
7777: }
7778: } else {
7779: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7780: }
1.1 raeburn 7781: }
7782: }
1.160.6.20 raeburn 7783: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7784: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7785: if (exists($confhash{'authorquota'}{$key})) {
7786: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7787: $changes{'authorquota'}{$key} = 1;
7788: }
7789: } else {
7790: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7791: }
7792: }
7793: }
1.1 raeburn 7794: }
1.86 raeburn 7795: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7796: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7797: if (ref($domconfig{'quotas'}) eq 'HASH') {
7798: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7799: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7800: $changes{'defaultquota'}{$key} = 1;
7801: }
7802: } else {
7803: if (!exists($domconfig{'quotas'}{$key})) {
7804: $changes{'defaultquota'}{$key} = 1;
7805: }
1.72 raeburn 7806: }
7807: } else {
1.86 raeburn 7808: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7809: }
1.1 raeburn 7810: }
7811: }
1.160.6.20 raeburn 7812: if (ref($confhash{'authorquota'}) eq 'HASH') {
7813: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7814: if (ref($domconfig{'quotas'}) eq 'HASH') {
7815: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7816: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7817: $changes{'authorquota'}{$key} = 1;
7818: }
7819: } else {
7820: $changes{'authorquota'}{$key} = 1;
7821: }
7822: } else {
7823: $changes{'authorquota'}{$key} = 1;
7824: }
7825: }
7826: }
1.1 raeburn 7827: }
1.72 raeburn 7828:
1.160.6.5 raeburn 7829: if ($context eq 'requestauthor') {
7830: $domdefaults{'requestauthor'} = \%confhash;
7831: } else {
7832: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7833: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7834: $domdefaults{$key} = $confhash{$key};
7835: }
1.160.6.5 raeburn 7836: }
1.72 raeburn 7837: }
1.160.6.5 raeburn 7838:
1.1 raeburn 7839: my %quotahash = (
1.86 raeburn 7840: $action => { %confhash }
1.1 raeburn 7841: );
7842: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7843: $dom);
7844: if ($putresult eq 'ok') {
7845: if (keys(%changes) > 0) {
1.72 raeburn 7846: my $cachetime = 24*60*60;
7847: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7848: if (ref($lastactref) eq 'HASH') {
7849: $lastactref->{'domdefaults'} = 1;
7850: }
1.1 raeburn 7851: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7852: unless (($context eq 'requestcourses') ||
7853: ($context eq 'requestauthor')) {
1.86 raeburn 7854: if (ref($changes{'defaultquota'}) eq 'HASH') {
7855: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7856: foreach my $type (@{$types},'default') {
7857: if (defined($changes{'defaultquota'}{$type})) {
7858: my $typetitle = $usertypes->{$type};
7859: if ($type eq 'default') {
7860: $typetitle = $othertitle;
7861: }
1.160.6.28 raeburn 7862: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7863: }
7864: }
1.86 raeburn 7865: $resulttext .= '</ul></li>';
1.72 raeburn 7866: }
1.160.6.20 raeburn 7867: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7868: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7869: foreach my $type (@{$types},'default') {
7870: if (defined($changes{'authorquota'}{$type})) {
7871: my $typetitle = $usertypes->{$type};
7872: if ($type eq 'default') {
7873: $typetitle = $othertitle;
7874: }
1.160.6.28 raeburn 7875: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7876: }
7877: }
7878: $resulttext .= '</ul></li>';
7879: }
1.72 raeburn 7880: }
1.80 raeburn 7881: my %newenv;
1.72 raeburn 7882: foreach my $item (@usertools) {
1.160.6.5 raeburn 7883: my (%haschgs,%inconf);
7884: if ($context eq 'requestauthor') {
7885: %haschgs = %changes;
7886: %inconf = %confhash;
7887: } else {
7888: if (ref($changes{$item}) eq 'HASH') {
7889: %haschgs = %{$changes{$item}};
7890: }
7891: if (ref($confhash{$item}) eq 'HASH') {
7892: %inconf = %{$confhash{$item}};
7893: }
7894: }
7895: if (keys(%haschgs) > 0) {
1.80 raeburn 7896: my $newacc =
7897: &Apache::lonnet::usertools_access($env{'user.name'},
7898: $env{'user.domain'},
1.86 raeburn 7899: $item,'reload',$context);
1.160.6.5 raeburn 7900: if (($context eq 'requestcourses') ||
7901: ($context eq 'requestauthor')) {
1.108 raeburn 7902: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7903: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7904: }
7905: } else {
7906: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7907: $newenv{'environment.availabletools.'.$item} = $newacc;
7908: }
1.80 raeburn 7909: }
1.160.6.5 raeburn 7910: unless ($context eq 'requestauthor') {
7911: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7912: }
1.72 raeburn 7913: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7914: if ($haschgs{$type}) {
1.72 raeburn 7915: my $typetitle = $usertypes->{$type};
7916: if ($type eq 'default') {
7917: $typetitle = $othertitle;
7918: } elsif ($type eq '_LC_adv') {
7919: $typetitle = 'LON-CAPA Advanced Users';
7920: }
1.160.6.5 raeburn 7921: if ($inconf{$type}) {
1.101 raeburn 7922: if ($context eq 'requestcourses') {
7923: my $cond;
1.160.6.5 raeburn 7924: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7925: if ($1 eq '') {
7926: $cond = &mt('(Automatic processing of any request).');
7927: } else {
7928: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7929: }
7930: } else {
1.160.6.5 raeburn 7931: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7932: }
7933: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7934: } elsif ($context eq 'requestauthor') {
7935: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7936: $titles{$inconf{$type}},$typetitle);
7937:
1.101 raeburn 7938: } else {
7939: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7940: }
1.72 raeburn 7941: } else {
1.104 raeburn 7942: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7943: if ($inconf{$type} eq '0') {
1.104 raeburn 7944: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7945: } else {
7946: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7947: }
7948: } else {
7949: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7950: }
1.72 raeburn 7951: }
7952: }
1.26 raeburn 7953: }
1.160.6.5 raeburn 7954: unless ($context eq 'requestauthor') {
7955: $resulttext .= '</ul></li>';
7956: }
1.26 raeburn 7957: }
1.1 raeburn 7958: }
1.160.6.5 raeburn 7959: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7960: if (ref($changes{'notify'}) eq 'HASH') {
7961: if ($changes{'notify'}{'approval'}) {
7962: if (ref($confhash{'notify'}) eq 'HASH') {
7963: if ($confhash{'notify'}{'approval'}) {
7964: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7965: } else {
1.160.6.5 raeburn 7966: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7967: }
7968: }
7969: }
7970: }
7971: }
1.160.6.30 raeburn 7972: if ($action eq 'requestcourses') {
7973: my @offon = ('off','on');
7974: if ($changes{'uniquecode'}) {
7975: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7976: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7977: $resulttext .= '<li>'.
7978: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7979: '</li>';
7980: } else {
7981: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7982: '</li>';
7983: }
7984: }
1.160.6.46 raeburn 7985: foreach my $type ('textbooks','templates') {
7986: if (ref($changes{$type}) eq 'HASH') {
7987: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7988: foreach my $key (sort(keys(%{$changes{$type}}))) {
7989: my %coursehash = &Apache::lonnet::coursedescription($key);
7990: my $coursetitle = $coursehash{'description'};
7991: my $position = $confhash{$type}{$key}{'order'} + 1;
7992: $resulttext .= '<li>';
1.160.6.47 raeburn 7993: foreach my $item ('subject','title','publisher','author') {
7994: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7995: ($type eq 'templates'));
1.160.6.46 raeburn 7996: my $name = $item.':';
7997: $name =~ s/^(\w)/\U$1/;
7998: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7999: }
8000: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8001: if ($type eq 'textbooks') {
8002: if ($confhash{$type}{$key}{'image'}) {
8003: $resulttext .= ' '.&mt('Image: [_1]',
8004: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8005: ' alt="Textbook cover" />').'<br />';
8006: }
8007: }
8008: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8009: }
1.160.6.46 raeburn 8010: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8011: }
8012: }
1.160.6.39 raeburn 8013: if (ref($changes{'validation'}) eq 'HASH') {
8014: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8015: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8016: foreach my $item (@{$validationitemsref}) {
8017: if (exists($changes{'validation'}{$item})) {
8018: if ($item eq 'markup') {
8019: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8020: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8021: } else {
8022: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8023: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8024: }
8025: }
8026: }
8027: if (exists($changes{'validation'}{'dc'})) {
8028: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8029: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8030: }
8031: }
8032: }
1.160.6.30 raeburn 8033: }
1.1 raeburn 8034: $resulttext .= '</ul>';
1.80 raeburn 8035: if (keys(%newenv)) {
8036: &Apache::lonnet::appenv(\%newenv);
8037: }
1.1 raeburn 8038: } else {
1.86 raeburn 8039: if ($context eq 'requestcourses') {
8040: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8041: } elsif ($context eq 'requestauthor') {
8042: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8043: } else {
1.90 weissno 8044: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8045: }
1.1 raeburn 8046: }
8047: } else {
1.11 albertel 8048: $resulttext = '<span class="LC_error">'.
8049: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8050: }
1.160.6.30 raeburn 8051: if ($errors) {
8052: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8053: '<ul>'.$errors.'</ul></p>';
8054: }
1.3 raeburn 8055: return $resulttext;
1.1 raeburn 8056: }
8057:
1.160.6.30 raeburn 8058: sub process_textbook_image {
1.160.6.46 raeburn 8059: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8060: my $filename = $env{'form.'.$caller.'.filename'};
8061: my ($error,$url);
8062: my ($width,$height) = (50,50);
8063: if ($configuserok eq 'ok') {
8064: if ($switchserver) {
8065: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8066: $switchserver);
8067: } elsif ($author_ok eq 'ok') {
8068: my ($result,$imageurl) =
8069: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 8070: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8071: if ($result eq 'ok') {
8072: $url = $imageurl;
8073: } else {
8074: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8075: }
8076: } else {
8077: $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);
8078: }
8079: } else {
8080: $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);
8081: }
8082: return ($url,$error);
8083: }
8084:
1.3 raeburn 8085: sub modify_autoenroll {
1.160.6.24 raeburn 8086: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8087: my ($resulttext,%changes);
8088: my %currautoenroll;
8089: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8090: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8091: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8092: }
8093: }
8094: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8095: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8096: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8097: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8098: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8099: my @offon = ('off','on');
1.17 raeburn 8100: my $sender_uname = $env{'form.sender_uname'};
8101: my $sender_domain = $env{'form.sender_domain'};
8102: if ($sender_domain eq '') {
8103: $sender_uname = '';
8104: } elsif ($sender_uname eq '') {
8105: $sender_domain = '';
8106: }
1.129 raeburn 8107: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8108: my $failsafe = $env{'form.autoenroll_failsafe'};
8109: $failsafe =~ s{^\s+|\s+$}{}g;
8110: if ($failsafe =~ /\D/) {
8111: undef($failsafe);
8112: }
1.1 raeburn 8113: my %autoenrollhash = (
1.129 raeburn 8114: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8115: 'sender_uname' => $sender_uname,
8116: 'sender_domain' => $sender_domain,
8117: 'co-owners' => $coowners,
1.160.6.68 raeburn 8118: 'autofailsafe' => $failsafe,
1.1 raeburn 8119: }
8120: );
1.4 raeburn 8121: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8122: $dom);
1.1 raeburn 8123: if ($putresult eq 'ok') {
8124: if (exists($currautoenroll{'run'})) {
8125: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8126: $changes{'run'} = 1;
8127: }
8128: } elsif ($autorun) {
8129: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8130: $changes{'run'} = 1;
1.1 raeburn 8131: }
8132: }
1.17 raeburn 8133: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8134: $changes{'sender'} = 1;
8135: }
1.17 raeburn 8136: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8137: $changes{'sender'} = 1;
8138: }
1.129 raeburn 8139: if ($currautoenroll{'co-owners'} ne '') {
8140: if ($currautoenroll{'co-owners'} ne $coowners) {
8141: $changes{'coowners'} = 1;
8142: }
8143: } elsif ($coowners) {
8144: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8145: }
8146: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8147: $changes{'autofailsafe'} = 1;
8148: }
1.1 raeburn 8149: if (keys(%changes) > 0) {
8150: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8151: if ($changes{'run'}) {
1.1 raeburn 8152: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8153: }
8154: if ($changes{'sender'}) {
1.17 raeburn 8155: if ($sender_uname eq '' || $sender_domain eq '') {
8156: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8157: } else {
8158: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8159: }
1.1 raeburn 8160: }
1.129 raeburn 8161: if ($changes{'coowners'}) {
8162: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8163: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8164: if (ref($lastactref) eq 'HASH') {
8165: $lastactref->{'domainconfig'} = 1;
8166: }
1.129 raeburn 8167: }
1.160.6.68 raeburn 8168: if ($changes{'autofailsafe'}) {
8169: if ($failsafe ne '') {
8170: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
8171: } else {
8172: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
8173: }
8174: &Apache::lonnet::get_domain_defaults($dom,1);
8175: if (ref($lastactref) eq 'HASH') {
8176: $lastactref->{'domdefaults'} = 1;
8177: }
8178: }
1.1 raeburn 8179: $resulttext .= '</ul>';
8180: } else {
8181: $resulttext = &mt('No changes made to auto-enrollment settings');
8182: }
8183: } else {
1.11 albertel 8184: $resulttext = '<span class="LC_error">'.
8185: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8186: }
1.3 raeburn 8187: return $resulttext;
1.1 raeburn 8188: }
8189:
8190: sub modify_autoupdate {
1.3 raeburn 8191: my ($dom,%domconfig) = @_;
1.1 raeburn 8192: my ($resulttext,%currautoupdate,%fields,%changes);
8193: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8194: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8195: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8196: }
8197: }
8198: my @offon = ('off','on');
8199: my %title = &Apache::lonlocal::texthash (
8200: run => 'Auto-update:',
8201: classlists => 'Updates to user information in classlists?'
8202: );
1.44 raeburn 8203: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8204: my %fieldtitles = &Apache::lonlocal::texthash (
8205: id => 'Student/Employee ID',
1.20 raeburn 8206: permanentemail => 'E-mail address',
1.1 raeburn 8207: lastname => 'Last Name',
8208: firstname => 'First Name',
8209: middlename => 'Middle Name',
1.132 raeburn 8210: generation => 'Generation',
1.1 raeburn 8211: );
1.142 raeburn 8212: $othertitle = &mt('All users');
1.1 raeburn 8213: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8214: $othertitle = &mt('Other users');
1.1 raeburn 8215: }
8216: foreach my $key (keys(%env)) {
8217: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8218: my ($usertype,$item) = ($1,$2);
8219: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8220: if ($usertype eq 'default') {
8221: push(@{$fields{$1}},$2);
8222: } elsif (ref($types) eq 'ARRAY') {
8223: if (grep(/^\Q$usertype\E$/,@{$types})) {
8224: push(@{$fields{$1}},$2);
8225: }
8226: }
8227: }
1.1 raeburn 8228: }
8229: }
1.131 raeburn 8230: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8231: @lockablenames = sort(@lockablenames);
8232: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8233: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8234: if (@changed) {
8235: $changes{'lockablenames'} = 1;
8236: }
8237: } else {
8238: if (@lockablenames) {
8239: $changes{'lockablenames'} = 1;
8240: }
8241: }
1.1 raeburn 8242: my %updatehash = (
8243: autoupdate => { run => $env{'form.autoupdate_run'},
8244: classlists => $env{'form.classlists'},
8245: fields => {%fields},
1.131 raeburn 8246: lockablenames => \@lockablenames,
1.1 raeburn 8247: }
8248: );
8249: foreach my $key (keys(%currautoupdate)) {
8250: if (($key eq 'run') || ($key eq 'classlists')) {
8251: if (exists($updatehash{autoupdate}{$key})) {
8252: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8253: $changes{$key} = 1;
8254: }
8255: }
8256: } elsif ($key eq 'fields') {
8257: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8258: foreach my $item (@{$types},'default') {
1.1 raeburn 8259: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8260: my $change = 0;
8261: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8262: if (!exists($fields{$item})) {
8263: $change = 1;
1.132 raeburn 8264: last;
1.1 raeburn 8265: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8266: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8267: $change = 1;
1.132 raeburn 8268: last;
1.1 raeburn 8269: }
8270: }
8271: }
8272: if ($change) {
8273: push(@{$changes{$key}},$item);
8274: }
1.26 raeburn 8275: }
1.1 raeburn 8276: }
8277: }
1.131 raeburn 8278: } elsif ($key eq 'lockablenames') {
8279: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8280: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8281: if (@changed) {
8282: $changes{'lockablenames'} = 1;
8283: }
8284: } else {
8285: if (@lockablenames) {
8286: $changes{'lockablenames'} = 1;
8287: }
8288: }
8289: }
8290: }
8291: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8292: if (@lockablenames) {
8293: $changes{'lockablenames'} = 1;
1.1 raeburn 8294: }
8295: }
1.26 raeburn 8296: foreach my $item (@{$types},'default') {
8297: if (defined($fields{$item})) {
8298: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8299: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8300: my $change = 0;
8301: if (ref($fields{$item}) eq 'ARRAY') {
8302: foreach my $type (@{$fields{$item}}) {
8303: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8304: $change = 1;
8305: last;
8306: }
8307: }
8308: }
8309: if ($change) {
8310: push(@{$changes{'fields'}},$item);
8311: }
8312: } else {
1.26 raeburn 8313: push(@{$changes{'fields'}},$item);
8314: }
8315: } else {
8316: push(@{$changes{'fields'}},$item);
1.1 raeburn 8317: }
8318: }
8319: }
8320: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8321: $dom);
8322: if ($putresult eq 'ok') {
8323: if (keys(%changes) > 0) {
8324: $resulttext = &mt('Changes made:').'<ul>';
8325: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8326: if ($key eq 'lockablenames') {
8327: $resulttext .= '<li>';
8328: if (@lockablenames) {
8329: $usertypes->{'default'} = $othertitle;
8330: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8331: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8332: } else {
8333: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8334: }
8335: $resulttext .= '</li>';
8336: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8337: foreach my $item (@{$changes{$key}}) {
8338: my @newvalues;
8339: foreach my $type (@{$fields{$item}}) {
8340: push(@newvalues,$fieldtitles{$type});
8341: }
1.3 raeburn 8342: my $newvaluestr;
8343: if (@newvalues > 0) {
8344: $newvaluestr = join(', ',@newvalues);
8345: } else {
8346: $newvaluestr = &mt('none');
1.6 raeburn 8347: }
1.1 raeburn 8348: if ($item eq 'default') {
1.26 raeburn 8349: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8350: } else {
1.26 raeburn 8351: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8352: }
8353: }
8354: } else {
8355: my $newvalue;
8356: if ($key eq 'run') {
8357: $newvalue = $offon[$env{'form.autoupdate_run'}];
8358: } else {
8359: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8360: }
1.1 raeburn 8361: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8362: }
8363: }
8364: $resulttext .= '</ul>';
8365: } else {
1.3 raeburn 8366: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8367: }
8368: } else {
1.11 albertel 8369: $resulttext = '<span class="LC_error">'.
8370: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8371: }
1.3 raeburn 8372: return $resulttext;
1.1 raeburn 8373: }
8374:
1.125 raeburn 8375: sub modify_autocreate {
8376: my ($dom,%domconfig) = @_;
8377: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8378: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8379: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8380: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8381: }
8382: }
8383: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8384: req => 'Auto-creation of validated requests for official courses',
8385: xmldc => 'Identity of course creator of courses from XML files',
8386: );
8387: my @types = ('xml','req');
8388: foreach my $item (@types) {
8389: $newvals{$item} = $env{'form.autocreate_'.$item};
8390: $newvals{$item} =~ s/\D//g;
8391: $newvals{$item} = 0 if ($newvals{$item} eq '');
8392: }
8393: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8394: my %domcoords = &get_active_dcs($dom);
8395: unless (exists($domcoords{$newvals{'xmldc'}})) {
8396: $newvals{'xmldc'} = '';
8397: }
8398: %autocreatehash = (
8399: autocreate => { xml => $newvals{'xml'},
8400: req => $newvals{'req'},
8401: }
8402: );
8403: if ($newvals{'xmldc'} ne '') {
8404: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8405: }
8406: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8407: $dom);
8408: if ($putresult eq 'ok') {
8409: my @items = @types;
8410: if ($newvals{'xml'}) {
8411: push(@items,'xmldc');
8412: }
8413: foreach my $item (@items) {
8414: if (exists($currautocreate{$item})) {
8415: if ($currautocreate{$item} ne $newvals{$item}) {
8416: $changes{$item} = 1;
8417: }
8418: } elsif ($newvals{$item}) {
8419: $changes{$item} = 1;
8420: }
8421: }
8422: if (keys(%changes) > 0) {
8423: my @offon = ('off','on');
8424: $resulttext = &mt('Changes made:').'<ul>';
8425: foreach my $item (@types) {
8426: if ($changes{$item}) {
8427: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8428: $resulttext .= '<li>'.
8429: &mt("$title{$item} set to [_1]$newtxt [_2]",
8430: '<b>','</b>').
8431: '</li>';
1.125 raeburn 8432: }
8433: }
8434: if ($changes{'xmldc'}) {
8435: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8436: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8437: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8438: }
8439: $resulttext .= '</ul>';
8440: } else {
8441: $resulttext = &mt('No changes made to auto-creation settings');
8442: }
8443: } else {
8444: $resulttext = '<span class="LC_error">'.
8445: &mt('An error occurred: [_1]',$putresult).'</span>';
8446: }
8447: return $resulttext;
8448: }
8449:
1.23 raeburn 8450: sub modify_directorysrch {
8451: my ($dom,%domconfig) = @_;
8452: my ($resulttext,%changes);
8453: my %currdirsrch;
8454: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8455: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8456: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8457: }
8458: }
1.160.6.72 raeburn 8459: my %title = ( available => 'Institutional directory search available',
8460: localonly => 'Other domains can search institution',
8461: lcavailable => 'LON-CAPA directory search available',
8462: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 8463: searchby => 'Search types',
8464: searchtypes => 'Search latitude');
8465: my @offon = ('off','on');
1.24 raeburn 8466: my @otherdoms = ('Yes','No');
1.23 raeburn 8467:
1.25 raeburn 8468: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8469: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8470: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8471:
1.44 raeburn 8472: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8473: if (keys(%{$usertypes}) == 0) {
8474: @cansearch = ('default');
8475: } else {
8476: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8477: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8478: if (!grep(/^\Q$type\E$/,@cansearch)) {
8479: push(@{$changes{'cansearch'}},$type);
8480: }
1.23 raeburn 8481: }
1.26 raeburn 8482: foreach my $type (@cansearch) {
8483: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8484: push(@{$changes{'cansearch'}},$type);
8485: }
1.23 raeburn 8486: }
1.26 raeburn 8487: } else {
8488: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8489: }
8490: }
8491:
8492: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8493: foreach my $by (@{$currdirsrch{'searchby'}}) {
8494: if (!grep(/^\Q$by\E$/,@searchby)) {
8495: push(@{$changes{'searchby'}},$by);
8496: }
8497: }
8498: foreach my $by (@searchby) {
8499: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8500: push(@{$changes{'searchby'}},$by);
8501: }
8502: }
8503: } else {
8504: push(@{$changes{'searchby'}},@searchby);
8505: }
1.25 raeburn 8506:
8507: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8508: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8509: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8510: push(@{$changes{'searchtypes'}},$type);
8511: }
8512: }
8513: foreach my $type (@searchtypes) {
8514: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8515: push(@{$changes{'searchtypes'}},$type);
8516: }
8517: }
8518: } else {
8519: if (exists($currdirsrch{'searchtypes'})) {
8520: foreach my $type (@searchtypes) {
8521: if ($type ne $currdirsrch{'searchtypes'}) {
8522: push(@{$changes{'searchtypes'}},$type);
8523: }
8524: }
8525: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8526: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8527: }
8528: } else {
8529: push(@{$changes{'searchtypes'}},@searchtypes);
8530: }
8531: }
8532:
1.23 raeburn 8533: my %dirsrch_hash = (
8534: directorysrch => { available => $env{'form.dirsrch_available'},
8535: cansearch => \@cansearch,
1.160.6.72 raeburn 8536: localonly => $env{'form.dirsrch_instlocalonly'},
8537: lclocalonly => $env{'form.dirsrch_domlocalonly'},
8538: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 8539: searchby => \@searchby,
1.25 raeburn 8540: searchtypes => \@searchtypes,
1.23 raeburn 8541: }
8542: );
8543: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8544: $dom);
8545: if ($putresult eq 'ok') {
8546: if (exists($currdirsrch{'available'})) {
8547: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8548: $changes{'available'} = 1;
8549: }
8550: } else {
8551: if ($env{'form.dirsrch_available'} eq '1') {
8552: $changes{'available'} = 1;
8553: }
8554: }
1.160.6.72 raeburn 8555: if (exists($currdirsrch{'lcavailable'})) {
8556: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
8557: $changes{'lcavailable'} = 1;
1.24 raeburn 8558: }
8559: } else {
1.160.6.72 raeburn 8560: if ($env{'form.dirsrch_lcavailable'} eq '1') {
8561: $changes{'lcavailable'} = 1;
8562: }
8563: }
8564: if (exists($currdirsrch{'localonly'})) {
8565: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 8566: $changes{'localonly'} = 1;
8567: }
1.160.6.72 raeburn 8568: } else {
8569: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
8570: $changes{'localonly'} = 1;
8571: }
8572: }
8573: if (exists($currdirsrch{'lclocalonly'})) {
8574: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
8575: $changes{'lclocalonly'} = 1;
8576: }
8577: } else {
8578: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
8579: $changes{'lclocalonly'} = 1;
8580: }
1.24 raeburn 8581: }
1.23 raeburn 8582: if (keys(%changes) > 0) {
8583: $resulttext = &mt('Changes made:').'<ul>';
8584: if ($changes{'available'}) {
8585: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8586: }
1.160.6.72 raeburn 8587: if ($changes{'lcavailable'}) {
8588: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
8589: }
1.24 raeburn 8590: if ($changes{'localonly'}) {
1.160.6.72 raeburn 8591: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
8592: }
8593: if ($changes{'lclocalonly'}) {
8594: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 8595: }
1.23 raeburn 8596: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8597: my $chgtext;
1.26 raeburn 8598: if (ref($usertypes) eq 'HASH') {
8599: if (keys(%{$usertypes}) > 0) {
8600: foreach my $type (@{$types}) {
8601: if (grep(/^\Q$type\E$/,@cansearch)) {
8602: $chgtext .= $usertypes->{$type}.'; ';
8603: }
8604: }
8605: if (grep(/^default$/,@cansearch)) {
8606: $chgtext .= $othertitle;
8607: } else {
8608: $chgtext =~ s/\; $//;
8609: }
1.160.6.13 raeburn 8610: $resulttext .=
8611: '<li>'.
8612: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8613: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8614: '</li>';
1.23 raeburn 8615: }
8616: }
8617: }
8618: if (ref($changes{'searchby'}) eq 'ARRAY') {
8619: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8620: my $chgtext;
8621: foreach my $type (@{$titleorder}) {
8622: if (grep(/^\Q$type\E$/,@searchby)) {
8623: if (defined($searchtitles->{$type})) {
8624: $chgtext .= $searchtitles->{$type}.'; ';
8625: }
8626: }
8627: }
8628: $chgtext =~ s/\; $//;
8629: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8630: }
1.25 raeburn 8631: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8632: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8633: my $chgtext;
8634: foreach my $type (@{$srchtypeorder}) {
8635: if (grep(/^\Q$type\E$/,@searchtypes)) {
8636: if (defined($srchtypes_desc->{$type})) {
8637: $chgtext .= $srchtypes_desc->{$type}.'; ';
8638: }
8639: }
8640: }
8641: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8642: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8643: }
8644: $resulttext .= '</ul>';
8645: } else {
1.160.6.72 raeburn 8646: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 8647: }
8648: } else {
8649: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8650: &mt('An error occurred: [_1]',$putresult).'</span>';
8651: }
8652: return $resulttext;
8653: }
8654:
1.28 raeburn 8655: sub modify_contacts {
1.160.6.24 raeburn 8656: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8657: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8658: if (ref($domconfig{'contacts'}) eq 'HASH') {
8659: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8660: $currsetting{$key} = $domconfig{'contacts'}{$key};
8661: }
8662: }
1.134 raeburn 8663: my (%others,%to,%bcc);
1.28 raeburn 8664: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8665: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8666: 'requestsmail','updatesmail','idconflictsmail');
8667: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8668: foreach my $type (@mailings) {
8669: @{$newsetting{$type}} =
8670: &Apache::loncommon::get_env_multiple('form.'.$type);
8671: foreach my $item (@contacts) {
8672: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8673: $contacts_hash{contacts}{$type}{$item} = 1;
8674: } else {
8675: $contacts_hash{contacts}{$type}{$item} = 0;
8676: }
8677: }
8678: $others{$type} = $env{'form.'.$type.'_others'};
8679: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8680: if ($type eq 'helpdeskmail') {
8681: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8682: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8683: }
1.28 raeburn 8684: }
8685: foreach my $item (@contacts) {
8686: $to{$item} = $env{'form.'.$item};
8687: $contacts_hash{'contacts'}{$item} = $to{$item};
8688: }
1.160.6.23 raeburn 8689: foreach my $item (@toggles) {
8690: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8691: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8692: }
8693: }
1.28 raeburn 8694: if (keys(%currsetting) > 0) {
8695: foreach my $item (@contacts) {
8696: if ($to{$item} ne $currsetting{$item}) {
8697: $changes{$item} = 1;
8698: }
8699: }
8700: foreach my $type (@mailings) {
8701: foreach my $item (@contacts) {
8702: if (ref($currsetting{$type}) eq 'HASH') {
8703: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8704: push(@{$changes{$type}},$item);
8705: }
8706: } else {
8707: push(@{$changes{$type}},@{$newsetting{$type}});
8708: }
8709: }
8710: if ($others{$type} ne $currsetting{$type}{'others'}) {
8711: push(@{$changes{$type}},'others');
8712: }
1.134 raeburn 8713: if ($type eq 'helpdeskmail') {
8714: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8715: push(@{$changes{$type}},'bcc');
8716: }
8717: }
1.28 raeburn 8718: }
8719: } else {
8720: my %default;
8721: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8722: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8723: $default{'errormail'} = 'adminemail';
8724: $default{'packagesmail'} = 'adminemail';
8725: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8726: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8727: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8728: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8729: foreach my $item (@contacts) {
8730: if ($to{$item} ne $default{$item}) {
8731: $changes{$item} = 1;
1.160.6.23 raeburn 8732: }
1.28 raeburn 8733: }
8734: foreach my $type (@mailings) {
8735: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8736:
8737: push(@{$changes{$type}},@{$newsetting{$type}});
8738: }
8739: if ($others{$type} ne '') {
8740: push(@{$changes{$type}},'others');
1.134 raeburn 8741: }
8742: if ($type eq 'helpdeskmail') {
8743: if ($bcc{$type} ne '') {
8744: push(@{$changes{$type}},'bcc');
8745: }
8746: }
1.28 raeburn 8747: }
8748: }
1.160.6.23 raeburn 8749: foreach my $item (@toggles) {
8750: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8751: $changes{$item} = 1;
8752: } elsif ((!$env{'form.'.$item}) &&
8753: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8754: $changes{$item} = 1;
8755: }
8756: }
1.28 raeburn 8757: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8758: $dom);
8759: if ($putresult eq 'ok') {
8760: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8761: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8762: if (ref($lastactref) eq 'HASH') {
8763: $lastactref->{'domainconfig'} = 1;
8764: }
1.28 raeburn 8765: my ($titles,$short_titles) = &contact_titles();
8766: $resulttext = &mt('Changes made:').'<ul>';
8767: foreach my $item (@contacts) {
8768: if ($changes{$item}) {
8769: $resulttext .= '<li>'.$titles->{$item}.
8770: &mt(' set to: ').
8771: '<span class="LC_cusr_emph">'.
8772: $to{$item}.'</span></li>';
8773: }
8774: }
8775: foreach my $type (@mailings) {
8776: if (ref($changes{$type}) eq 'ARRAY') {
8777: $resulttext .= '<li>'.$titles->{$type}.': ';
8778: my @text;
8779: foreach my $item (@{$newsetting{$type}}) {
8780: push(@text,$short_titles->{$item});
8781: }
8782: if ($others{$type} ne '') {
8783: push(@text,$others{$type});
8784: }
8785: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8786: join(', ',@text).'</span>';
8787: if ($type eq 'helpdeskmail') {
8788: if ($bcc{$type} ne '') {
8789: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8790: }
8791: }
8792: $resulttext .= '</li>';
1.28 raeburn 8793: }
8794: }
1.160.6.23 raeburn 8795: my @offon = ('off','on');
8796: if ($changes{'reporterrors'}) {
8797: $resulttext .= '<li>'.
8798: &mt('E-mail error reports to [_1] set to "'.
8799: $offon[$env{'form.reporterrors'}].'".',
8800: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8801: &mt('LON-CAPA core group - MSU'),600,500)).
8802: '</li>';
8803: }
8804: if ($changes{'reportupdates'}) {
8805: $resulttext .= '<li>'.
8806: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8807: $offon[$env{'form.reportupdates'}].'".',
8808: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8809: &mt('LON-CAPA core group - MSU'),600,500)).
8810: '</li>';
8811: }
1.28 raeburn 8812: $resulttext .= '</ul>';
8813: } else {
1.34 raeburn 8814: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8815: }
8816: } else {
8817: $resulttext = '<span class="LC_error">'.
8818: &mt('An error occurred: [_1].',$putresult).'</span>';
8819: }
8820: return $resulttext;
8821: }
8822:
8823: sub modify_usercreation {
1.27 raeburn 8824: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8825: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8826: my $warningmsg;
1.27 raeburn 8827: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8828: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8829: if ($key eq 'cancreate') {
8830: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8831: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8832: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 8833: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8834: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 8835: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8836: } else {
8837: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8838: }
1.50 raeburn 8839: }
1.43 raeburn 8840: }
1.160.6.34 raeburn 8841: } elsif ($key eq 'email_rule') {
8842: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8843: } else {
8844: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8845: }
8846: }
1.34 raeburn 8847: }
1.160.6.34 raeburn 8848: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8849: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8850: my @contexts = ('author','course','requestcrs');
8851: foreach my $item(@contexts) {
8852: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8853: }
1.34 raeburn 8854: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8855: foreach my $item (@contexts) {
1.160.6.34 raeburn 8856: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8857: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8858: }
1.27 raeburn 8859: }
1.34 raeburn 8860: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8861: foreach my $item (@contexts) {
1.43 raeburn 8862: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8863: if ($cancreate{$item} ne 'any') {
8864: push(@{$changes{'cancreate'}},$item);
8865: }
8866: } else {
8867: if ($cancreate{$item} ne 'none') {
8868: push(@{$changes{'cancreate'}},$item);
8869: }
1.27 raeburn 8870: }
8871: }
8872: } else {
1.43 raeburn 8873: foreach my $item (@contexts) {
1.34 raeburn 8874: push(@{$changes{'cancreate'}},$item);
8875: }
1.27 raeburn 8876: }
1.34 raeburn 8877:
1.27 raeburn 8878: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8879: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8880: if (!grep(/^\Q$type\E$/,@username_rule)) {
8881: push(@{$changes{'username_rule'}},$type);
8882: }
8883: }
8884: foreach my $type (@username_rule) {
8885: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8886: push(@{$changes{'username_rule'}},$type);
8887: }
8888: }
8889: } else {
8890: push(@{$changes{'username_rule'}},@username_rule);
8891: }
8892:
1.32 raeburn 8893: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8894: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8895: if (!grep(/^\Q$type\E$/,@id_rule)) {
8896: push(@{$changes{'id_rule'}},$type);
8897: }
8898: }
8899: foreach my $type (@id_rule) {
8900: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8901: push(@{$changes{'id_rule'}},$type);
8902: }
8903: }
8904: } else {
8905: push(@{$changes{'id_rule'}},@id_rule);
8906: }
8907:
1.43 raeburn 8908: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8909: my @authtypes = ('int','krb4','krb5','loc');
8910: my %authhash;
1.43 raeburn 8911: foreach my $item (@authen_contexts) {
1.28 raeburn 8912: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8913: foreach my $auth (@authtypes) {
8914: if (grep(/^\Q$auth\E$/,@authallowed)) {
8915: $authhash{$item}{$auth} = 1;
8916: } else {
8917: $authhash{$item}{$auth} = 0;
8918: }
8919: }
8920: }
8921: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8922: foreach my $item (@authen_contexts) {
1.28 raeburn 8923: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8924: foreach my $auth (@authtypes) {
8925: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8926: push(@{$changes{'authtypes'}},$item);
8927: last;
8928: }
8929: }
8930: }
8931: }
8932: } else {
1.43 raeburn 8933: foreach my $item (@authen_contexts) {
1.28 raeburn 8934: push(@{$changes{'authtypes'}},$item);
8935: }
8936: }
8937:
1.160.6.34 raeburn 8938: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8939: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8940: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8941: $save_usercreate{'id_rule'} = \@id_rule;
8942: $save_usercreate{'username_rule'} = \@username_rule,
8943: $save_usercreate{'authtypes'} = \%authhash;
8944:
1.27 raeburn 8945: my %usercreation_hash = (
1.160.6.34 raeburn 8946: usercreation => \%save_usercreate,
8947: );
1.27 raeburn 8948:
8949: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8950: $dom);
1.50 raeburn 8951:
1.160.6.34 raeburn 8952: if ($putresult eq 'ok') {
8953: if (keys(%changes) > 0) {
8954: $resulttext = &mt('Changes made:').'<ul>';
8955: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8956: my %lt = &usercreation_types();
8957: foreach my $type (@{$changes{'cancreate'}}) {
8958: my $chgtext = $lt{$type}.', ';
8959: if ($cancreate{$type} eq 'none') {
8960: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8961: } elsif ($cancreate{$type} eq 'any') {
8962: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8963: } elsif ($cancreate{$type} eq 'official') {
8964: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8965: } elsif ($cancreate{$type} eq 'unofficial') {
8966: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8967: }
8968: $resulttext .= '<li>'.$chgtext.'</li>';
8969: }
8970: }
8971: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8972: my ($rules,$ruleorder) =
8973: &Apache::lonnet::inst_userrules($dom,'username');
8974: my $chgtext = '<ul>';
8975: foreach my $type (@username_rule) {
8976: if (ref($rules->{$type}) eq 'HASH') {
8977: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8978: }
8979: }
8980: $chgtext .= '</ul>';
8981: if (@username_rule > 0) {
8982: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8983: } else {
8984: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8985: }
8986: }
8987: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8988: my ($idrules,$idruleorder) =
8989: &Apache::lonnet::inst_userrules($dom,'id');
8990: my $chgtext = '<ul>';
8991: foreach my $type (@id_rule) {
8992: if (ref($idrules->{$type}) eq 'HASH') {
8993: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8994: }
8995: }
8996: $chgtext .= '</ul>';
8997: if (@id_rule > 0) {
8998: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8999: } else {
9000: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9001: }
9002: }
9003: my %authname = &authtype_names();
9004: my %context_title = &context_names();
9005: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9006: my $chgtext = '<ul>';
9007: foreach my $type (@{$changes{'authtypes'}}) {
9008: my @allowed;
9009: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9010: foreach my $auth (@authtypes) {
9011: if ($authhash{$type}{$auth}) {
9012: push(@allowed,$authname{$auth});
9013: }
9014: }
9015: if (@allowed > 0) {
9016: $chgtext .= join(', ',@allowed).'</li>';
9017: } else {
9018: $chgtext .= &mt('none').'</li>';
9019: }
9020: }
9021: $chgtext .= '</ul>';
9022: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9023: $resulttext .= '</li>';
9024: }
9025: $resulttext .= '</ul>';
9026: } else {
9027: $resulttext = &mt('No changes made to user creation settings');
9028: }
9029: } else {
9030: $resulttext = '<span class="LC_error">'.
9031: &mt('An error occurred: [_1]',$putresult).'</span>';
9032: }
9033: if ($warningmsg ne '') {
9034: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9035: }
9036: return $resulttext;
9037: }
9038:
9039: sub modify_selfcreation {
9040: my ($dom,%domconfig) = @_;
9041: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9042: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9043: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9044: if (ref($types) eq 'ARRAY') {
9045: $usertypes->{'default'} = $othertitle;
9046: push(@{$types},'default');
9047: }
1.160.6.34 raeburn 9048: #
9049: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9050: #
9051: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9052: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9053: if ($key eq 'cancreate') {
9054: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9055: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9056: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9057: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9058: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9059: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9060: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9061: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9062: } else {
9063: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9064: }
9065: }
9066: }
9067: } elsif ($key eq 'email_rule') {
9068: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9069: } else {
9070: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9071: }
9072: }
9073: }
9074: #
9075: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9076: #
9077: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9078: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9079: if ($key eq 'selfcreate') {
9080: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9081: } else {
9082: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9083: }
9084: }
9085: }
9086:
9087: my @contexts = ('selfcreate');
9088: @{$cancreate{'selfcreate'}} = ();
9089: %{$cancreate{'emailusername'}} = ();
9090: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9091: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9092: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9093: my %selfcreatetypes = (
9094: sso => 'users authenticated by institutional single sign on',
9095: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9096: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9097: );
1.160.6.34 raeburn 9098: #
9099: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9100: # is permitted.
9101: #
1.160.6.40 raeburn 9102:
9103: my @statuses;
9104: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9105: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9106: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9107: }
9108: }
9109: push(@statuses,'default');
9110:
1.160.6.35 raeburn 9111: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9112: if ($item eq 'email') {
1.160.6.40 raeburn 9113: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9114: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9115: push(@contexts,'selfcreateprocessing');
9116: foreach my $type (@statuses) {
9117: if ($type eq 'default') {
9118: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9119: } else {
9120: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9121: }
9122: }
1.160.6.34 raeburn 9123: }
9124: } else {
9125: if ($env{'form.cancreate_'.$item}) {
9126: push(@{$cancreate{'selfcreate'}},$item);
9127: }
9128: }
9129: }
9130: my (@email_rule,%userinfo,%savecaptcha);
9131: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9132: #
1.160.6.35 raeburn 9133: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9134: # 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 9135: #
1.160.6.40 raeburn 9136:
1.160.6.48 raeburn 9137: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9138: push(@contexts,'emailusername');
1.160.6.35 raeburn 9139: if (ref($types) eq 'ARRAY') {
9140: foreach my $type (@{$types}) {
9141: if (ref($infofields) eq 'ARRAY') {
9142: foreach my $field (@{$infofields}) {
9143: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9144: $cancreate{'emailusername'}{$type}{$field} = $1;
9145: }
9146: }
1.160.6.34 raeburn 9147: }
9148: }
9149: }
9150: #
9151: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9152: # queued requests for self-creation of account using e-mail address as username
9153: #
9154:
9155: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9156: @approvalnotify = sort(@approvalnotify);
9157: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9158: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9159: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9160: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9161: push(@{$changes{'cancreate'}},'notify');
9162: }
9163: } else {
9164: if ($cancreate{'notify'}{'approval'}) {
9165: push(@{$changes{'cancreate'}},'notify');
9166: }
9167: }
9168: } elsif ($cancreate{'notify'}{'approval'}) {
9169: push(@{$changes{'cancreate'}},'notify');
9170: }
9171:
9172: #
9173: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9174: #
9175: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9176: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9177: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9178: if (@{$curr_usercreation{'email_rule'}} > 0) {
9179: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9180: if (!grep(/^\Q$type\E$/,@email_rule)) {
9181: push(@{$changes{'email_rule'}},$type);
9182: }
9183: }
9184: }
9185: if (@email_rule > 0) {
9186: foreach my $type (@email_rule) {
9187: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9188: push(@{$changes{'email_rule'}},$type);
9189: }
9190: }
9191: }
9192: } elsif (@email_rule > 0) {
9193: push(@{$changes{'email_rule'}},@email_rule);
9194: }
9195: }
9196: #
1.160.6.40 raeburn 9197: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9198: # institutional log-in.
9199: #
9200: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9201: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9202: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9203: ($domdefaults{'auth_def'} eq 'localauth'))) {
9204: $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.').' '.
9205: &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.');
9206: }
9207: }
9208: my @fields = ('lastname','firstname','middlename','generation',
9209: 'permanentemail','id');
1.160.6.44 raeburn 9210: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9211: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9212: #
9213: # Where usernames may created for institutional log-in and/or institutional single sign on:
9214: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9215: # may self-create accounts
9216: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9217: # which the user may supply, if institutional data is unavailable.
9218: #
9219: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9220: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9221: if (@{$types} > 1) {
1.160.6.34 raeburn 9222: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9223: push(@contexts,'statustocreate');
9224: } else {
9225: undef($cancreate{'statustocreate'});
9226: }
9227: foreach my $type (@{$types}) {
9228: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9229: foreach my $field (@fields) {
9230: if (grep(/^\Q$field\E$/,@modifiable)) {
9231: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9232: } else {
9233: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9234: }
9235: }
9236: }
9237: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9238: foreach my $type (@{$types}) {
9239: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9240: foreach my $field (@fields) {
9241: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9242: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9243: push(@{$changes{'selfcreate'}},$type);
9244: last;
9245: }
9246: }
9247: }
9248: }
9249: } else {
9250: foreach my $type (@{$types}) {
9251: push(@{$changes{'selfcreate'}},$type);
9252: }
9253: }
9254: }
1.160.6.44 raeburn 9255: foreach my $field (@shibfields) {
9256: if ($env{'form.shibenv_'.$field} ne '') {
9257: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9258: }
9259: }
9260: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9261: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9262: foreach my $field (@shibfields) {
9263: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9264: push(@{$changes{'cancreate'}},'shibenv');
9265: }
9266: }
9267: } else {
9268: foreach my $field (@shibfields) {
9269: if ($env{'form.shibenv_'.$field}) {
9270: push(@{$changes{'cancreate'}},'shibenv');
9271: last;
9272: }
9273: }
9274: }
9275: }
1.160.6.34 raeburn 9276: }
9277: foreach my $item (@contexts) {
9278: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9279: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9280: if (ref($cancreate{$item}) eq 'ARRAY') {
9281: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9282: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9283: push(@{$changes{'cancreate'}},$item);
9284: }
9285: }
9286: }
9287: }
9288: if (ref($cancreate{$item}) eq 'ARRAY') {
9289: foreach my $type (@{$cancreate{$item}}) {
9290: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9291: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9292: push(@{$changes{'cancreate'}},$item);
9293: }
9294: }
9295: }
9296: }
9297: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9298: if (ref($cancreate{$item}) eq 'HASH') {
9299: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 9300: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9301: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9302: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9303: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9304: push(@{$changes{'cancreate'}},$item);
9305: }
9306: }
9307: }
1.160.6.40 raeburn 9308: } elsif ($item eq 'selfcreateprocessing') {
9309: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9310: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9311: push(@{$changes{'cancreate'}},$item);
9312: }
9313: }
1.160.6.35 raeburn 9314: } else {
9315: if (!$cancreate{$item}{$curr}) {
9316: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9317: push(@{$changes{'cancreate'}},$item);
9318: }
1.160.6.34 raeburn 9319: }
9320: }
9321: }
9322: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 9323: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9324: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9325: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9326: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9328: push(@{$changes{'cancreate'}},$item);
9329: }
9330: }
9331: } else {
9332: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9333: push(@{$changes{'cancreate'}},$item);
9334: }
9335: }
9336: }
1.160.6.40 raeburn 9337: } elsif ($item eq 'selfcreateprocessing') {
9338: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9339: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9340: push(@{$changes{'cancreate'}},$item);
9341: }
9342: }
1.160.6.35 raeburn 9343: } else {
9344: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9345: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9346: push(@{$changes{'cancreate'}},$item);
9347: }
1.160.6.34 raeburn 9348: }
9349: }
9350: }
9351: }
9352: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9353: if (ref($cancreate{$item}) eq 'ARRAY') {
9354: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9355: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9356: push(@{$changes{'cancreate'}},$item);
9357: }
9358: }
9359: } elsif (ref($cancreate{$item}) eq 'HASH') {
9360: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9361: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9362: push(@{$changes{'cancreate'}},$item);
9363: }
9364: }
9365: }
9366: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9367: if (ref($cancreate{$item}) eq 'HASH') {
9368: foreach my $type (keys(%{$cancreate{$item}})) {
9369: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9370: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9371: if ($cancreate{$item}{$type}{$field}) {
9372: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9373: push(@{$changes{'cancreate'}},$item);
9374: }
9375: last;
9376: }
9377: }
9378: }
9379: }
1.160.6.34 raeburn 9380: }
9381: }
9382: }
9383: #
9384: # Populate %save_usercreate hash with updates to self-creation configuration.
9385: #
9386: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9387: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 9388: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 9389: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9390: if (ref($cancreate{'notify'}) eq 'HASH') {
9391: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9392: }
1.160.6.40 raeburn 9393: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9394: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9395: }
1.160.6.34 raeburn 9396: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9397: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9398: }
1.160.6.44 raeburn 9399: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9400: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9401: }
1.160.6.34 raeburn 9402: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9403: $save_usercreate{'emailrule'} = \@email_rule;
9404:
9405: my %userconfig_hash = (
9406: usercreation => \%save_usercreate,
9407: usermodification => \%save_usermodify,
9408: );
9409: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9410: $dom);
9411: #
9412: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9413: #
1.27 raeburn 9414: if ($putresult eq 'ok') {
9415: if (keys(%changes) > 0) {
9416: $resulttext = &mt('Changes made:').'<ul>';
9417: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9418: my %lt = &selfcreation_types();
1.34 raeburn 9419: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9420: my $chgtext;
1.45 raeburn 9421: if ($type eq 'selfcreate') {
1.50 raeburn 9422: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9423: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9424: } else {
1.160.6.34 raeburn 9425: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9426: '<ul>';
1.50 raeburn 9427: foreach my $case (@{$cancreate{$type}}) {
9428: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9429: }
9430: $chgtext .= '</ul>';
1.100 raeburn 9431: if (ref($cancreate{$type}) eq 'ARRAY') {
9432: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9433: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9434: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9435: $chgtext .= '<br />'.
9436: '<span class="LC_warning">'.
9437: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9438: '</span>';
1.100 raeburn 9439: }
9440: }
9441: }
9442: }
1.43 raeburn 9443: }
1.160.6.44 raeburn 9444: } elsif ($type eq 'shibenv') {
9445: if (keys(%{$cancreate{$type}}) == 0) {
9446: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9447: } else {
9448: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9449: '<ul>';
9450: foreach my $field (@shibfields) {
9451: next if ($cancreate{$type}{$field} eq '');
9452: if ($field eq 'inststatus') {
9453: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9454: } else {
9455: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9456: }
9457: }
9458: $chgtext .= '</ul>';
9459: }
1.93 raeburn 9460: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9461: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9462: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9463: if (@{$cancreate{'selfcreate'}} > 0) {
9464: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9465: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9466: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9467: $chgtext .= '<br />'.
9468: '<span class="LC_warning">'.
9469: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9470: '</span>';
9471: }
1.96 raeburn 9472: } elsif (ref($usertypes) eq 'HASH') {
9473: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9474: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9475: } else {
9476: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9477: }
9478: $chgtext .= '<ul>';
9479: foreach my $case (@{$cancreate{$type}}) {
9480: if ($case eq 'default') {
9481: $chgtext .= '<li>'.$othertitle.'</li>';
9482: } else {
9483: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9484: }
9485: }
1.100 raeburn 9486: $chgtext .= '</ul>';
9487: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9488: $chgtext .= '<br /><span class="LC_warning">'.
9489: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9490: '</span>';
1.100 raeburn 9491: }
9492: }
9493: } else {
9494: if (@{$cancreate{$type}} == 0) {
9495: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9496: } else {
9497: $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 9498: }
9499: }
9500: }
1.160.6.40 raeburn 9501: } elsif ($type eq 'selfcreateprocessing') {
9502: my %choices = &Apache::lonlocal::texthash (
9503: automatic => 'Automatic approval',
9504: approval => 'Queued for approval',
9505: );
9506: if (@statuses > 1) {
9507: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9508: '<ul>';
9509: foreach my $type (@statuses) {
9510: if ($type eq 'default') {
9511: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9512: } else {
9513: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9514: }
9515: }
9516: $chgtext .= '</ul>';
9517: } else {
9518: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9519: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9520: }
1.160.6.5 raeburn 9521: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9522: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9523: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9524: } else {
9525: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9526: if ($captchas{$savecaptcha{$type}}) {
9527: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9528: } else {
9529: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9530: }
9531: }
9532: } elsif ($type eq 'recaptchakeys') {
9533: my ($privkey,$pubkey);
1.160.6.34 raeburn 9534: if (ref($savecaptcha{$type}) eq 'HASH') {
9535: $pubkey = $savecaptcha{$type}{'public'};
9536: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9537: }
9538: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9539: if (!$pubkey) {
9540: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9541: } else {
9542: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9543: }
9544: if (!$privkey) {
9545: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9546: } else {
9547: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9548: }
9549: $chgtext .= '</ul>';
1.160.6.69 raeburn 9550: } elsif ($type eq 'recaptchaversion') {
9551: if ($savecaptcha{'captcha'} eq 'recaptcha') {
9552: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
9553: }
1.160.6.34 raeburn 9554: } elsif ($type eq 'emailusername') {
9555: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9556: if (ref($types) eq 'ARRAY') {
9557: foreach my $type (@{$types}) {
9558: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9559: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9560: $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 9561: '<ul>';
9562: foreach my $field (@{$infofields}) {
9563: if ($cancreate{'emailusername'}{$type}{$field}) {
9564: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9565: }
9566: }
1.160.6.50 raeburn 9567: $chgtext .= '</ul>';
9568: } else {
9569: $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 9570: }
9571: } else {
1.160.6.50 raeburn 9572: $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 9573: }
9574: }
9575: }
9576: }
9577: } elsif ($type eq 'notify') {
9578: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9579: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9580: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9581: if ($cancreate{'notify'}{'approval'}) {
9582: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9583: }
9584: }
1.43 raeburn 9585: }
1.34 raeburn 9586: }
1.160.6.34 raeburn 9587: if ($chgtext) {
9588: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9589: }
9590: }
9591: }
1.43 raeburn 9592: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9593: my ($emailrules,$emailruleorder) =
9594: &Apache::lonnet::inst_userrules($dom,'email');
9595: my $chgtext = '<ul>';
9596: foreach my $type (@email_rule) {
9597: if (ref($emailrules->{$type}) eq 'HASH') {
9598: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9599: }
9600: }
9601: $chgtext .= '</ul>';
9602: if (@email_rule > 0) {
1.160.6.34 raeburn 9603: $resulttext .= '<li>'.
9604: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9605: $chgtext.
9606: '</li>';
1.43 raeburn 9607: } else {
1.160.6.34 raeburn 9608: $resulttext .= '<li>'.
9609: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9610: '</li>';
1.43 raeburn 9611: }
9612: }
1.160.6.34 raeburn 9613: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9614: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9615: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9616: foreach my $type (@{$changes{'selfcreate'}}) {
9617: my $typename = $type;
9618: if (ref($usertypes) eq 'HASH') {
9619: if ($usertypes->{$type} ne '') {
9620: $typename = $usertypes->{$type};
1.28 raeburn 9621: }
9622: }
1.160.6.34 raeburn 9623: my @modifiable;
9624: $resulttext .= '<li>'.
9625: &mt('Self-creation of account by users with status: [_1]',
9626: '<span class="LC_cusr_emph">'.$typename.'</span>').
9627: ' - '.&mt('modifiable fields (if institutional data blank): ');
9628: foreach my $field (@fields) {
9629: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9630: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9631: }
9632: }
9633: if (@modifiable > 0) {
9634: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9635: } else {
1.160.6.34 raeburn 9636: $resulttext .= &mt('none');
1.43 raeburn 9637: }
1.160.6.34 raeburn 9638: $resulttext .= '</li>';
1.28 raeburn 9639: }
1.160.6.34 raeburn 9640: $resulttext .= '</ul></li>';
1.28 raeburn 9641: }
1.27 raeburn 9642: $resulttext .= '</ul>';
9643: } else {
1.160.6.34 raeburn 9644: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9645: }
9646: } else {
9647: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9648: &mt('An error occurred: [_1]',$putresult).'</span>';
9649: }
1.43 raeburn 9650: if ($warningmsg ne '') {
9651: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9652: }
1.23 raeburn 9653: return $resulttext;
9654: }
9655:
1.160.6.5 raeburn 9656: sub process_captcha {
9657: my ($container,$changes,$newsettings,$current) = @_;
9658: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9659: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9660: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9661: $newsettings->{'captcha'} = 'original';
9662: }
9663: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9664: if ($container eq 'cancreate') {
9665: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9666: push(@{$changes->{'cancreate'}},'captcha');
9667: } elsif (!defined($changes->{'cancreate'})) {
9668: $changes->{'cancreate'} = ['captcha'];
9669: }
9670: } else {
9671: $changes->{'captcha'} = 1;
9672: }
9673: }
1.160.6.69 raeburn 9674: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 9675: if ($newsettings->{'captcha'} eq 'recaptcha') {
9676: $newpub = $env{'form.'.$container.'_recaptchapub'};
9677: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9678: $newpub =~ s/[^\w\-]//g;
9679: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9680: $newsettings->{'recaptchakeys'} = {
9681: public => $newpub,
9682: private => $newpriv,
9683: };
1.160.6.69 raeburn 9684: $newversion = $env{'form.'.$container.'_recaptchaversion'};
9685: $newversion =~ s/\D//g;
9686: if ($newversion ne '2') {
9687: $newversion = 1;
9688: }
9689: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 9690: }
9691: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9692: $currpub = $current->{'recaptchakeys'}{'public'};
9693: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9694: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9695: $newsettings->{'recaptchakeys'} = {
9696: public => '',
9697: private => '',
9698: }
9699: }
1.160.6.5 raeburn 9700: }
1.160.6.69 raeburn 9701: if ($current->{'captcha'} eq 'recaptcha') {
9702: $currversion = $current->{'recaptchaversion'};
9703: if ($currversion ne '2') {
9704: $currversion = 1;
9705: }
9706: }
9707: if ($currversion ne $newversion) {
9708: if ($container eq 'cancreate') {
9709: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9710: push(@{$changes->{'cancreate'}},'recaptchaversion');
9711: } elsif (!defined($changes->{'cancreate'})) {
9712: $changes->{'cancreate'} = ['recaptchaversion'];
9713: }
9714: } else {
9715: $changes->{'recaptchaversion'} = 1;
9716: }
9717: }
1.160.6.5 raeburn 9718: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9719: if ($container eq 'cancreate') {
9720: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9721: push(@{$changes->{'cancreate'}},'recaptchakeys');
9722: } elsif (!defined($changes->{'cancreate'})) {
9723: $changes->{'cancreate'} = ['recaptchakeys'];
9724: }
9725: } else {
9726: $changes->{'recaptchakeys'} = 1;
9727: }
9728: }
9729: return;
9730: }
9731:
1.33 raeburn 9732: sub modify_usermodification {
9733: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9734: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9735: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9736: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9737: if ($key eq 'selfcreate') {
9738: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9739: } else {
9740: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9741: }
1.33 raeburn 9742: }
9743: }
1.160.6.34 raeburn 9744: my @contexts = ('author','course');
1.33 raeburn 9745: my %context_title = (
9746: author => 'In author context',
9747: course => 'In course context',
9748: );
9749: my @fields = ('lastname','firstname','middlename','generation',
9750: 'permanentemail','id');
9751: my %roles = (
9752: author => ['ca','aa'],
9753: course => ['st','ep','ta','in','cr'],
9754: );
9755: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9756: foreach my $context (@contexts) {
9757: foreach my $role (@{$roles{$context}}) {
9758: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9759: foreach my $item (@fields) {
9760: if (grep(/^\Q$item\E$/,@modifiable)) {
9761: $modifyhash{$context}{$role}{$item} = 1;
9762: } else {
9763: $modifyhash{$context}{$role}{$item} = 0;
9764: }
9765: }
9766: }
9767: if (ref($curr_usermodification{$context}) eq 'HASH') {
9768: foreach my $role (@{$roles{$context}}) {
9769: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9770: foreach my $field (@fields) {
9771: if ($modifyhash{$context}{$role}{$field} ne
9772: $curr_usermodification{$context}{$role}{$field}) {
9773: push(@{$changes{$context}},$role);
9774: last;
9775: }
9776: }
9777: }
9778: }
9779: } else {
9780: foreach my $context (@contexts) {
9781: foreach my $role (@{$roles{$context}}) {
9782: push(@{$changes{$context}},$role);
9783: }
9784: }
9785: }
9786: }
9787: my %usermodification_hash = (
9788: usermodification => \%modifyhash,
9789: );
9790: my $putresult = &Apache::lonnet::put_dom('configuration',
9791: \%usermodification_hash,$dom);
9792: if ($putresult eq 'ok') {
9793: if (keys(%changes) > 0) {
9794: $resulttext = &mt('Changes made: ').'<ul>';
9795: foreach my $context (@contexts) {
9796: if (ref($changes{$context}) eq 'ARRAY') {
9797: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9798: if (ref($changes{$context}) eq 'ARRAY') {
9799: foreach my $role (@{$changes{$context}}) {
9800: my $rolename;
1.160.6.34 raeburn 9801: if ($role eq 'cr') {
9802: $rolename = &mt('Custom');
1.33 raeburn 9803: } else {
1.160.6.34 raeburn 9804: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9805: }
9806: my @modifiable;
1.160.6.34 raeburn 9807: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9808: foreach my $field (@fields) {
9809: if ($modifyhash{$context}{$role}{$field}) {
9810: push(@modifiable,$fieldtitles{$field});
9811: }
9812: }
9813: if (@modifiable > 0) {
9814: $resulttext .= join(', ',@modifiable);
9815: } else {
9816: $resulttext .= &mt('none');
9817: }
9818: $resulttext .= '</li>';
9819: }
9820: $resulttext .= '</ul></li>';
9821: }
9822: }
9823: }
9824: $resulttext .= '</ul>';
9825: } else {
9826: $resulttext = &mt('No changes made to user modification settings');
9827: }
9828: } else {
9829: $resulttext = '<span class="LC_error">'.
9830: &mt('An error occurred: [_1]',$putresult).'</span>';
9831: }
9832: return $resulttext;
9833: }
9834:
1.43 raeburn 9835: sub modify_defaults {
1.160.6.27 raeburn 9836: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9837: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9838: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9839: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9840: my @authtypes = ('internal','krb4','krb5','localauth');
9841: foreach my $item (@items) {
9842: $newvalues{$item} = $env{'form.'.$item};
9843: if ($item eq 'auth_def') {
9844: if ($newvalues{$item} ne '') {
9845: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9846: push(@errors,$item);
9847: }
9848: }
9849: } elsif ($item eq 'lang_def') {
9850: if ($newvalues{$item} ne '') {
9851: if ($newvalues{$item} =~ /^(\w+)/) {
9852: my $langcode = $1;
1.103 raeburn 9853: if ($langcode ne 'x_chef') {
9854: if (code2language($langcode) eq '') {
9855: push(@errors,$item);
9856: }
1.43 raeburn 9857: }
9858: } else {
9859: push(@errors,$item);
9860: }
9861: }
1.54 raeburn 9862: } elsif ($item eq 'timezone_def') {
9863: if ($newvalues{$item} ne '') {
1.62 raeburn 9864: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9865: push(@errors,$item);
9866: }
9867: }
1.68 raeburn 9868: } elsif ($item eq 'datelocale_def') {
9869: if ($newvalues{$item} ne '') {
9870: my @datelocale_ids = DateTime::Locale->ids();
9871: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9872: push(@errors,$item);
9873: }
9874: }
1.141 raeburn 9875: } elsif ($item eq 'portal_def') {
9876: if ($newvalues{$item} ne '') {
9877: 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])\/?$/) {
9878: push(@errors,$item);
9879: }
9880: }
1.43 raeburn 9881: }
9882: if (grep(/^\Q$item\E$/,@errors)) {
9883: $newvalues{$item} = $domdefaults{$item};
9884: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9885: $changes{$item} = 1;
9886: }
1.72 raeburn 9887: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9888: }
9889: my %defaults_hash = (
1.72 raeburn 9890: defaults => \%newvalues,
9891: );
1.43 raeburn 9892: my $title = &defaults_titles();
1.160.6.40 raeburn 9893:
9894: my $currinststatus;
9895: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9896: $currinststatus = $domconfig{'inststatus'};
9897: } else {
9898: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9899: $currinststatus = {
9900: inststatustypes => $usertypes,
9901: inststatusorder => $types,
9902: inststatusguest => [],
9903: };
9904: }
9905: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9906: my @allpos;
9907: my %guests;
9908: my %alltypes;
9909: my ($currtitles,$currguests,$currorder);
9910: if (ref($currinststatus) eq 'HASH') {
9911: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9912: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9913: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9914: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9915: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9916: }
9917: }
9918: unless (grep(/^\Q$type\E$/,@todelete)) {
9919: my $position = $env{'form.inststatus_pos_'.$type};
9920: $position =~ s/\D+//g;
9921: $allpos[$position] = $type;
9922: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9923: $alltypes{$type} =~ s/`//g;
9924: if ($env{'form.inststatus_guest_'.$type}) {
9925: $guests{$type} = 1;
9926: }
9927: }
9928: }
9929: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9930: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9931: }
9932: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9933: $currtitles =~ s/,$//;
9934: }
9935: }
9936: if ($env{'form.addinststatus'}) {
9937: my $newtype = $env{'form.addinststatus'};
9938: $newtype =~ s/\W//g;
9939: unless (exists($alltypes{$newtype})) {
9940: if ($env{'form.addinststatus_guest'}) {
9941: $guests{$newtype} = 1;
9942: }
9943: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9944: $alltypes{$newtype} =~ s/`//g;
9945: my $position = $env{'form.addinststatus_pos'};
9946: $position =~ s/\D+//g;
9947: if ($position ne '') {
9948: $allpos[$position] = $newtype;
9949: }
9950: }
9951: }
9952: my (@orderedstatus,@orderedguests);
9953: foreach my $type (@allpos) {
9954: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9955: push(@orderedstatus,$type);
9956: if ($guests{$type}) {
9957: push(@orderedguests,$type);
9958: }
9959: }
9960: }
9961: foreach my $type (keys(%alltypes)) {
9962: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9963: delete($alltypes{$type});
9964: }
9965: }
9966: $defaults_hash{'inststatus'} = {
9967: inststatustypes => \%alltypes,
9968: inststatusorder => \@orderedstatus,
9969: inststatusguest => \@orderedguests,
9970: };
9971: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9972: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9973: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9974: }
9975: }
9976: if ($currorder ne join(',',@orderedstatus)) {
9977: $changes{'inststatus'}{'inststatusorder'} = 1;
9978: }
9979: if ($currguests ne join(',',@orderedguests)) {
9980: $changes{'inststatus'}{'inststatusguest'} = 1;
9981: }
9982: my $newtitles;
9983: foreach my $item (@orderedstatus) {
9984: $newtitles .= $alltypes{$item}.',';
9985: }
9986: $newtitles =~ s/,$//;
9987: if ($currtitles ne $newtitles) {
9988: $changes{'inststatus'}{'inststatustypes'} = 1;
9989: }
1.43 raeburn 9990: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9991: $dom);
9992: if ($putresult eq 'ok') {
9993: if (keys(%changes) > 0) {
9994: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9995: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9996: 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";
9997: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9998: if ($item eq 'inststatus') {
9999: if (ref($changes{'inststatus'}) eq 'HASH') {
10000: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10001: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10002: foreach my $type (@orderedstatus) {
10003: $resulttext .= $alltypes{$type}.', ';
10004: }
10005: $resulttext =~ s/, $//;
10006: $resulttext .= '</li>';
10007: }
10008: if ($changes{'inststatus'}{'inststatusguest'}) {
10009: $resulttext .= '<li>';
10010: if (@orderedguests) {
10011: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10012: foreach my $type (@orderedguests) {
10013: $resulttext .= $alltypes{$type}.', ';
10014: }
10015: $resulttext =~ s/, $//;
10016: } else {
10017: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10018: }
10019: $resulttext .= '</li>';
10020: }
10021: }
10022: } else {
10023: my $value = $env{'form.'.$item};
10024: if ($value eq '') {
10025: $value = &mt('none');
10026: } elsif ($item eq 'auth_def') {
10027: my %authnames = &authtype_names();
10028: my %shortauth = (
10029: internal => 'int',
10030: krb4 => 'krb4',
10031: krb5 => 'krb5',
10032: localauth => 'loc',
10033: );
10034: $value = $authnames{$shortauth{$value}};
10035: }
10036: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10037: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10038: }
10039: }
10040: $resulttext .= '</ul>';
10041: $mailmsgtext .= "\n";
10042: my $cachetime = 24*60*60;
1.72 raeburn 10043: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10044: if (ref($lastactref) eq 'HASH') {
10045: $lastactref->{'domdefaults'} = 1;
10046: }
1.68 raeburn 10047: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10048: my $notify = 1;
10049: if (ref($domconfig{'contacts'}) eq 'HASH') {
10050: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10051: $notify = 0;
10052: }
10053: }
10054: if ($notify) {
10055: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10056: "LON-CAPA Domain Settings Change - $dom",
10057: $mailmsgtext);
10058: }
1.54 raeburn 10059: }
1.43 raeburn 10060: } else {
1.54 raeburn 10061: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10062: }
10063: } else {
10064: $resulttext = '<span class="LC_error">'.
10065: &mt('An error occurred: [_1]',$putresult).'</span>';
10066: }
10067: if (@errors > 0) {
10068: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10069: foreach my $item (@errors) {
10070: $resulttext .= ' "'.$title->{$item}.'",';
10071: }
10072: $resulttext =~ s/,$//;
10073: }
10074: return $resulttext;
10075: }
10076:
1.46 raeburn 10077: sub modify_scantron {
1.160.6.24 raeburn 10078: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10079: my ($resulttext,%confhash,%changes,$errors);
10080: my $custom = 'custom.tab';
10081: my $default = 'default.tab';
10082: my $servadm = $r->dir_config('lonAdmEMail');
10083: my ($configuserok,$author_ok,$switchserver) =
10084: &config_check($dom,$confname,$servadm);
10085: if ($env{'form.scantronformat.filename'} ne '') {
10086: my $error;
10087: if ($configuserok eq 'ok') {
10088: if ($switchserver) {
1.130 raeburn 10089: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10090: } else {
10091: if ($author_ok eq 'ok') {
10092: my ($result,$scantronurl) =
10093: &publishlogo($r,'upload','scantronformat',$dom,
10094: $confname,'scantron','','',$custom);
10095: if ($result eq 'ok') {
10096: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10097: $changes{'scantronformat'} = 1;
1.46 raeburn 10098: } else {
10099: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10100: }
10101: } else {
10102: $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);
10103: }
10104: }
10105: } else {
10106: $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);
10107: }
10108: if ($error) {
10109: &Apache::lonnet::logthis($error);
10110: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10111: }
10112: }
1.48 raeburn 10113: if (ref($domconfig{'scantron'}) eq 'HASH') {
10114: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10115: if ($env{'form.scantronformat_del'}) {
10116: $confhash{'scantron'}{'scantronformat'} = '';
10117: $changes{'scantronformat'} = 1;
1.46 raeburn 10118: }
10119: }
10120: }
10121: if (keys(%confhash) > 0) {
10122: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10123: $dom);
10124: if ($putresult eq 'ok') {
10125: if (keys(%changes) > 0) {
1.48 raeburn 10126: if (ref($confhash{'scantron'}) eq 'HASH') {
10127: $resulttext = &mt('Changes made:').'<ul>';
10128: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10129: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10130: } else {
1.130 raeburn 10131: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10132: }
1.48 raeburn 10133: $resulttext .= '</ul>';
10134: } else {
1.130 raeburn 10135: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10136: }
10137: $resulttext .= '</ul>';
10138: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10139: if (ref($lastactref) eq 'HASH') {
10140: $lastactref->{'domainconfig'} = 1;
10141: }
1.46 raeburn 10142: } else {
1.130 raeburn 10143: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10144: }
10145: } else {
10146: $resulttext = '<span class="LC_error">'.
10147: &mt('An error occurred: [_1]',$putresult).'</span>';
10148: }
10149: } else {
1.130 raeburn 10150: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10151: }
10152: if ($errors) {
10153: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10154: $errors.'</ul>';
10155: }
10156: return $resulttext;
10157: }
10158:
1.48 raeburn 10159: sub modify_coursecategories {
1.160.6.43 raeburn 10160: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10161: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10162: $cathash);
1.48 raeburn 10163: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10164: my @catitems = ('unauth','auth');
10165: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10166: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10167: $cathash = $domconfig{'coursecategories'}{'cats'};
10168: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10169: $changes{'togglecats'} = 1;
10170: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10171: }
10172: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10173: $changes{'categorize'} = 1;
10174: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10175: }
1.120 raeburn 10176: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10177: $changes{'togglecatscomm'} = 1;
10178: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10179: }
10180: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10181: $changes{'categorizecomm'} = 1;
10182: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10183: }
1.160.6.42 raeburn 10184: foreach my $item (@catitems) {
10185: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10186: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10187: $changes{$item} = 1;
10188: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10189: }
10190: }
10191: }
1.57 raeburn 10192: } else {
10193: $changes{'togglecats'} = 1;
10194: $changes{'categorize'} = 1;
1.124 raeburn 10195: $changes{'togglecatscomm'} = 1;
10196: $changes{'categorizecomm'} = 1;
1.87 raeburn 10197: $domconfig{'coursecategories'} = {
10198: togglecats => $env{'form.togglecats'},
10199: categorize => $env{'form.categorize'},
1.124 raeburn 10200: togglecatscomm => $env{'form.togglecatscomm'},
10201: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10202: };
1.160.6.42 raeburn 10203: foreach my $item (@catitems) {
10204: if ($env{'form.coursecat_'.$item} ne 'std') {
10205: $changes{$item} = 1;
10206: }
10207: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10208: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10209: }
10210: }
1.57 raeburn 10211: }
10212: if (ref($cathash) eq 'HASH') {
10213: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10214: push (@deletecategory,'instcode::0');
10215: }
1.120 raeburn 10216: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10217: push(@deletecategory,'communities::0');
10218: }
1.48 raeburn 10219: }
1.57 raeburn 10220: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10221: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10222: if (@deletecategory > 0) {
10223: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10224: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10225: foreach my $item (@deletecategory) {
1.57 raeburn 10226: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10227: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10228: $deletions{$item} = 1;
1.57 raeburn 10229: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10230: }
10231: }
10232: }
1.57 raeburn 10233: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10234: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10235: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10236: $reorderings{$item} = 1;
1.57 raeburn 10237: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10238: }
10239: if ($env{'form.addcategory_name_'.$item} ne '') {
10240: my $newcat = $env{'form.addcategory_name_'.$item};
10241: my $newdepth = $depth+1;
10242: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10243: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10244: $adds{$newitem} = 1;
10245: }
10246: if ($env{'form.subcat_'.$item} ne '') {
10247: my $newcat = $env{'form.subcat_'.$item};
10248: my $newdepth = $depth+1;
10249: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10250: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10251: $adds{$newitem} = 1;
10252: }
10253: }
10254: }
10255: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10256: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10257: my $newitem = 'instcode::0';
1.57 raeburn 10258: if ($cathash->{$newitem} eq '') {
10259: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10260: $adds{$newitem} = 1;
10261: }
10262: } else {
10263: my $newitem = 'instcode::0';
1.57 raeburn 10264: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10265: $adds{$newitem} = 1;
10266: }
10267: }
1.120 raeburn 10268: if ($env{'form.communities'} eq '1') {
10269: if (ref($cathash) eq 'HASH') {
10270: my $newitem = 'communities::0';
10271: if ($cathash->{$newitem} eq '') {
10272: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10273: $adds{$newitem} = 1;
10274: }
10275: } else {
10276: my $newitem = 'communities::0';
10277: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10278: $adds{$newitem} = 1;
10279: }
10280: }
1.48 raeburn 10281: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10282: if (($env{'form.addcategory_name'} ne 'instcode') &&
10283: ($env{'form.addcategory_name'} ne 'communities')) {
10284: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10285: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10286: $adds{$newitem} = 1;
10287: }
1.48 raeburn 10288: }
1.57 raeburn 10289: my $putresult;
1.48 raeburn 10290: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10291: if (keys(%deletions) > 0) {
10292: foreach my $key (keys(%deletions)) {
10293: if ($predelallitems{$key} ne '') {
10294: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10295: }
10296: }
10297: }
10298: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10299: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10300: if (ref($chkcats[0]) eq 'ARRAY') {
10301: my $depth = 0;
10302: my $chg = 0;
10303: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10304: my $name = $chkcats[0][$i];
10305: my $item;
10306: if ($name eq '') {
10307: $chg ++;
10308: } else {
10309: $item = &escape($name).'::0';
10310: if ($chg) {
1.57 raeburn 10311: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10312: }
10313: $depth ++;
1.57 raeburn 10314: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10315: $depth --;
10316: }
10317: }
10318: }
1.57 raeburn 10319: }
10320: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10321: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10322: if ($putresult eq 'ok') {
1.57 raeburn 10323: my %title = (
1.120 raeburn 10324: togglecats => 'Show/Hide a course in catalog',
10325: categorize => 'Assign a category to a course',
10326: togglecatscomm => 'Show/Hide a community in catalog',
10327: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10328: );
10329: my %level = (
1.120 raeburn 10330: dom => 'set in Domain ("Modify Course/Community")',
10331: crs => 'set in Course ("Course Configuration")',
10332: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 10333: none => 'No catalog',
10334: std => 'Standard catalog',
10335: domonly => 'Domain-only catalog',
10336: codesrch => 'Code search form',
1.57 raeburn 10337: );
1.48 raeburn 10338: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 10339: if ($changes{'togglecats'}) {
10340: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
10341: }
10342: if ($changes{'categorize'}) {
10343: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 10344: }
1.120 raeburn 10345: if ($changes{'togglecatscomm'}) {
10346: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
10347: }
10348: if ($changes{'categorizecomm'}) {
10349: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
10350: }
1.160.6.42 raeburn 10351: if ($changes{'unauth'}) {
10352: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
10353: }
10354: if ($changes{'auth'}) {
10355: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
10356: }
1.57 raeburn 10357: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10358: my $cathash;
10359: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10360: $cathash = $domconfig{'coursecategories'}{'cats'};
10361: } else {
10362: $cathash = {};
10363: }
10364: my (@cats,@trails,%allitems);
10365: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10366: if (keys(%deletions) > 0) {
10367: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10368: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10369: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10370: }
10371: $resulttext .= '</ul></li>';
10372: }
10373: if (keys(%reorderings) > 0) {
10374: my %sort_by_trail;
10375: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10376: foreach my $key (keys(%reorderings)) {
10377: if ($allitems{$key} ne '') {
10378: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10379: }
1.48 raeburn 10380: }
1.57 raeburn 10381: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10382: $resulttext .= '<li>'.$trails[$trail].'</li>';
10383: }
10384: $resulttext .= '</ul></li>';
1.48 raeburn 10385: }
1.57 raeburn 10386: if (keys(%adds) > 0) {
10387: my %sort_by_trail;
10388: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10389: foreach my $key (keys(%adds)) {
10390: if ($allitems{$key} ne '') {
10391: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10392: }
10393: }
10394: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10395: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10396: }
1.57 raeburn 10397: $resulttext .= '</ul></li>';
1.48 raeburn 10398: }
10399: }
10400: $resulttext .= '</ul>';
1.160.6.43 raeburn 10401: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10402: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10403: if ($changes{'auth'}) {
10404: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10405: }
10406: if ($changes{'unauth'}) {
10407: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10408: }
10409: my $cachetime = 24*60*60;
10410: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10411: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10412: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10413: }
10414: }
1.48 raeburn 10415: } else {
10416: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10417: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10418: }
10419: } else {
1.120 raeburn 10420: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10421: }
10422: return $resulttext;
10423: }
10424:
1.69 raeburn 10425: sub modify_serverstatuses {
10426: my ($dom,%domconfig) = @_;
10427: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10428: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10429: %currserverstatus = %{$domconfig{'serverstatuses'}};
10430: }
10431: my @pages = &serverstatus_pages();
10432: foreach my $type (@pages) {
10433: $newserverstatus{$type}{'namedusers'} = '';
10434: $newserverstatus{$type}{'machines'} = '';
10435: if (defined($env{'form.'.$type.'_namedusers'})) {
10436: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10437: my @okusers;
10438: foreach my $user (@users) {
10439: my ($uname,$udom) = split(/:/,$user);
10440: if (($udom =~ /^$match_domain$/) &&
10441: (&Apache::lonnet::domain($udom)) &&
10442: ($uname =~ /^$match_username$/)) {
10443: if (!grep(/^\Q$user\E/,@okusers)) {
10444: push(@okusers,$user);
10445: }
10446: }
10447: }
10448: if (@okusers > 0) {
10449: @okusers = sort(@okusers);
10450: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10451: }
10452: }
10453: if (defined($env{'form.'.$type.'_machines'})) {
10454: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10455: my @okmachines;
10456: foreach my $ip (@machines) {
10457: my @parts = split(/\./,$ip);
10458: next if (@parts < 4);
10459: my $badip = 0;
10460: for (my $i=0; $i<4; $i++) {
10461: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10462: $badip = 1;
10463: last;
10464: }
10465: }
10466: if (!$badip) {
10467: push(@okmachines,$ip);
10468: }
10469: }
10470: @okmachines = sort(@okmachines);
10471: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10472: }
10473: }
10474: my %serverstatushash = (
10475: serverstatuses => \%newserverstatus,
10476: );
10477: foreach my $type (@pages) {
1.83 raeburn 10478: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10479: my (@current,@new);
1.83 raeburn 10480: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10481: if ($currserverstatus{$type}{$setting} ne '') {
10482: @current = split(/,/,$currserverstatus{$type}{$setting});
10483: }
10484: }
10485: if ($newserverstatus{$type}{$setting} ne '') {
10486: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10487: }
10488: if (@current > 0) {
10489: if (@new > 0) {
10490: foreach my $item (@current) {
10491: if (!grep(/^\Q$item\E$/,@new)) {
10492: $changes{$type}{$setting} = 1;
1.82 raeburn 10493: last;
10494: }
10495: }
1.84 raeburn 10496: foreach my $item (@new) {
10497: if (!grep(/^\Q$item\E$/,@current)) {
10498: $changes{$type}{$setting} = 1;
10499: last;
1.82 raeburn 10500: }
10501: }
10502: } else {
1.83 raeburn 10503: $changes{$type}{$setting} = 1;
1.69 raeburn 10504: }
1.83 raeburn 10505: } elsif (@new > 0) {
10506: $changes{$type}{$setting} = 1;
1.69 raeburn 10507: }
10508: }
10509: }
10510: if (keys(%changes) > 0) {
1.81 raeburn 10511: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10512: my $putresult = &Apache::lonnet::put_dom('configuration',
10513: \%serverstatushash,$dom);
10514: if ($putresult eq 'ok') {
10515: $resulttext .= &mt('Changes made:').'<ul>';
10516: foreach my $type (@pages) {
1.84 raeburn 10517: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10518: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10519: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10520: if ($newserverstatus{$type}{'namedusers'} eq '') {
10521: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10522: } else {
10523: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10524: }
1.84 raeburn 10525: }
10526: if ($changes{$type}{'machines'}) {
1.69 raeburn 10527: if ($newserverstatus{$type}{'machines'} eq '') {
10528: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10529: } else {
10530: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10531: }
10532:
10533: }
10534: $resulttext .= '</ul></li>';
10535: }
10536: }
10537: $resulttext .= '</ul>';
10538: } else {
10539: $resulttext = '<span class="LC_error">'.
10540: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10541:
10542: }
10543: } else {
10544: $resulttext = &mt('No changes made to access to server status pages');
10545: }
10546: return $resulttext;
10547: }
10548:
1.118 jms 10549: sub modify_helpsettings {
1.122 jms 10550: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10551: my ($resulttext,$errors,%changes,%helphash);
10552: my %defaultchecked = ('submitbugs' => 'on');
10553: my @offon = ('off','on');
1.118 jms 10554: my @toggles = ('submitbugs');
1.160.6.73 raeburn 10555: my %current = ('submitbugs' => '');
1.118 jms 10556: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 10557: %current = %{$domconfig{'helpsettings'}};
10558: }
10559: foreach my $item (@toggles) {
10560: if ($defaultchecked{$item} eq 'on') {
10561: if ($current{$item} eq '') {
10562: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 10563: $changes{$item} = 1;
10564: }
1.160.6.73 raeburn 10565: } elsif ($current{$item} ne $env{'form.'.$item}) {
10566: $changes{$item} = 1;
10567: }
10568: } elsif ($defaultchecked{$item} eq 'off') {
10569: if ($current{$item} eq '') {
10570: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 10571: $changes{$item} = 1;
10572: }
1.160.6.73 raeburn 10573: } elsif ($current{$item} ne $env{'form.'.$item}) {
10574: $changes{$item} = 1;
10575: }
10576: }
10577: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10578: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10579: }
10580: }
10581:
10582: my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp');
10583: my $confname = $dom.'-domainconfig';
10584: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
10585: if (@modify) {
10586: foreach my $num (@modify) {
10587: my $rolename = $env{'form.custhelprole'.$num};
10588: if ($rolename ne '') {
10589: if (exists($existing{'rolesdef_'.$rolename})) {
10590: my $prefix = 'custhelp'.$num;
10591: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
10592: my %currprivs;
10593: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
10594: split(/\_/,$existing{'rolesdef_'.$rolename});
10595: foreach my $level ('c','d','s') {
10596: if ($newprivs{$level} ne $currprivs{$level}) {
10597: $changes{'customrole'}{$rolename} = 1;
10598: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
10599: $newprivs{'c'},$confname,$dom);
10600: last;
10601: }
10602: }
10603: }
1.160.6.26 raeburn 10604: }
1.160.6.73 raeburn 10605: }
10606: }
10607: if ($env{'form.newcusthelp'} ne '') {
10608: my $prefix = 'custhelp'.$env{'form.newcusthelp'};
10609: my $rolename = $env{'form.newcusthelpname'};
10610: $rolename=~s/[^A-Za-z0-9]//gs;
10611: if ($rolename ne '') {
10612: unless(exists($existing{'rolesdef_'.$rolename})) {
1.160.6.75 raeburn 10613: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
10614: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
10615: $newprivs{'c'},$confname,$dom);
1.160.6.73 raeburn 10616: if ($result eq 'ok') {
10617: $changes{'newcustomrole'} = $rolename;
10618: } else {
1.160.6.75 raeburn 10619: $errors .= '<li><span class="LC_error">'.
10620: &mt('An error occurred storing the new custom role: [_1]',
10621: $result).'</span></li>';
1.160.6.73 raeburn 10622: }
1.122 jms 10623: }
10624: }
1.118 jms 10625: }
1.160.6.73 raeburn 10626:
1.123 jms 10627: my $putresult;
10628: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10629: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10630: if ($putresult eq 'ok') {
10631: $resulttext = &mt('Changes made:').'<ul>';
10632: foreach my $item (sort(keys(%changes))) {
10633: if ($item eq 'submitbugs') {
10634: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10635: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10636: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 10637: } elsif ($item eq 'customrole') {
10638: if (ref($changes{'customrole'}) eq 'HASH') {
10639: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
10640: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
10641: $role).'</li>';
10642: }
10643: }
10644: } elsif ($item eq 'newcustomrole') {
10645: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
10646: $changes{'newcustomrole'}).'</li>';
1.160.6.5 raeburn 10647: }
10648: }
10649: $resulttext .= '</ul>';
10650: } else {
10651: $resulttext = &mt('No changes made to help settings');
10652: $errors .= '<li><span class="LC_error">'.
10653: &mt('An error occurred storing the settings: [_1]',
10654: $putresult).'</span></li>';
10655: }
1.118 jms 10656: }
10657: if ($errors) {
1.160.6.5 raeburn 10658: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10659: $errors.'</ul>';
10660: }
10661: return $resulttext;
10662: }
10663:
1.121 raeburn 10664: sub modify_coursedefaults {
1.160.6.27 raeburn 10665: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10666: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10667: my %defaultchecked = (
10668: 'uselcmath' => 'on',
10669: 'usejsme' => 'on'
10670: );
10671: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10672: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 10673: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
10674: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 10675: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10676: my %staticdefaults = (
10677: anonsurvey_threshold => 10,
10678: uploadquota => 500,
1.160.6.57 raeburn 10679: postsubmit => 60,
1.160.6.70 raeburn 10680: mysqltables => 172800,
1.160.6.21 raeburn 10681: );
1.121 raeburn 10682:
10683: $defaultshash{'coursedefaults'} = {};
10684:
10685: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10686: if ($domconfig{'coursedefaults'} eq '') {
10687: $domconfig{'coursedefaults'} = {};
10688: }
10689: }
10690:
10691: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10692: foreach my $item (@toggles) {
10693: if ($defaultchecked{$item} eq 'on') {
10694: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10695: ($env{'form.'.$item} eq '0')) {
10696: $changes{$item} = 1;
1.160.6.16 raeburn 10697: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10698: $changes{$item} = 1;
10699: }
10700: } elsif ($defaultchecked{$item} eq 'off') {
10701: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10702: ($env{'form.'.$item} eq '1')) {
10703: $changes{$item} = 1;
10704: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10705: $changes{$item} = 1;
10706: }
10707: }
10708: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10709: }
1.160.6.21 raeburn 10710: foreach my $item (@numbers) {
10711: my ($currdef,$newdef);
1.160.6.26 raeburn 10712: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10713: if ($item eq 'anonsurvey_threshold') {
10714: $currdef = $domconfig{'coursedefaults'}{$item};
10715: $newdef =~ s/\D//g;
10716: if ($newdef eq '' || $newdef < 1) {
10717: $newdef = 1;
10718: }
10719: $defaultshash{'coursedefaults'}{$item} = $newdef;
10720: } else {
1.160.6.70 raeburn 10721: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
10722: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
10723: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 10724: }
10725: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 10726: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 10727: }
10728: if ($currdef ne $newdef) {
10729: my $staticdef;
10730: if ($item eq 'anonsurvey_threshold') {
10731: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10732: $changes{$item} = 1;
10733: }
1.160.6.70 raeburn 10734: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
10735: my $setting = $1;
10736: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
10737: $changes{$setting} = 1;
1.160.6.21 raeburn 10738: }
10739: }
1.139 raeburn 10740: }
10741: }
1.160.6.64 raeburn 10742: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
10743: my @currclonecode;
10744: if (ref($currclone) eq 'HASH') {
10745: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
10746: @currclonecode = @{$currclone->{'instcode'}};
10747: }
10748: }
10749: my $newclone;
10750: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
10751: $newclone = $env{'form.canclone'};
10752: }
10753: if ($newclone eq 'instcode') {
10754: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
10755: my (%codedefaults,@code_order,@clonecode);
10756: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
10757: \@code_order);
10758: foreach my $item (@code_order) {
10759: if (grep(/^\Q$item\E$/,@newcodes)) {
10760: push(@clonecode,$item);
10761: }
10762: }
10763: if (@clonecode) {
10764: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
10765: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
10766: if (@diffs) {
10767: $changes{'canclone'} = 1;
10768: }
10769: } else {
10770: $newclone eq '';
10771: }
10772: } elsif ($newclone ne '') {
10773: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
10774: }
10775: if ($newclone ne $currclone) {
10776: $changes{'canclone'} = 1;
10777: }
1.160.6.57 raeburn 10778: my %credits;
10779: foreach my $type (@types) {
10780: unless ($type eq 'community') {
10781: $credits{$type} = $env{'form.'.$type.'_credits'};
10782: $credits{$type} =~ s/[^\d.]+//g;
10783: }
10784: }
10785: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10786: ($env{'form.coursecredits'} eq '1')) {
10787: $changes{'coursecredits'} = 1;
10788: foreach my $type (keys(%credits)) {
10789: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10790: }
10791: } else {
10792: if ($env{'form.coursecredits'} eq '1') {
10793: foreach my $type (@types) {
10794: unless ($type eq 'community') {
10795: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10796: $changes{'coursecredits'} = 1;
10797: }
10798: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10799: }
10800: }
10801: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10802: foreach my $type (@types) {
10803: unless ($type eq 'community') {
10804: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10805: $changes{'coursecredits'} = 1;
10806: last;
10807: }
10808: }
10809: }
10810: }
10811: }
10812: if ($env{'form.postsubmit'} eq '1') {
10813: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10814: my %currtimeout;
10815: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10816: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10817: $changes{'postsubmit'} = 1;
10818: }
10819: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10820: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10821: }
10822: } else {
10823: $changes{'postsubmit'} = 1;
10824: }
10825: foreach my $type (@types) {
10826: my $timeout = $env{'form.'.$type.'_timeout'};
10827: $timeout =~ s/\D//g;
10828: if ($timeout == $staticdefaults{'postsubmit'}) {
10829: $timeout = '';
10830: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10831: $timeout = '0';
10832: }
10833: unless ($timeout eq '') {
10834: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10835: }
10836: if (exists($currtimeout{$type})) {
10837: if ($timeout ne $currtimeout{$type}) {
10838: $changes{'postsubmit'} = 1;
10839: }
10840: } elsif ($timeout ne '') {
10841: $changes{'postsubmit'} = 1;
10842: }
10843: }
10844: } else {
10845: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10846: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10847: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10848: $changes{'postsubmit'} = 1;
10849: }
10850: } else {
10851: $changes{'postsubmit'} = 1;
10852: }
1.160.6.16 raeburn 10853: }
1.121 raeburn 10854: }
10855: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10856: $dom);
10857: if ($putresult eq 'ok') {
10858: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10859: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10860: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 10861: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 10862: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 10863: foreach my $item ('uselcmath','usejsme') {
10864: if ($changes{$item}) {
10865: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10866: }
1.160.6.16 raeburn 10867: }
10868: if ($changes{'coursecredits'}) {
10869: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10870: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10871: $domdefaults{$type.'credits'} =
10872: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10873: }
10874: }
10875: }
10876: if ($changes{'postsubmit'}) {
10877: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10878: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10879: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10880: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10881: $domdefaults{$type.'postsubtimeout'} =
10882: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10883: }
10884: }
1.160.6.16 raeburn 10885: }
10886: }
1.160.6.21 raeburn 10887: if ($changes{'uploadquota'}) {
10888: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10889: foreach my $type (@types) {
10890: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10891: }
10892: }
10893: }
1.160.6.64 raeburn 10894: if ($changes{'canclone'}) {
10895: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10896: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10897: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
10898: if (@clonecodes) {
10899: $domdefaults{'canclone'} = join('+',@clonecodes);
10900: }
10901: }
10902: } else {
10903: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
10904: }
10905: }
1.121 raeburn 10906: my $cachetime = 24*60*60;
10907: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10908: if (ref($lastactref) eq 'HASH') {
10909: $lastactref->{'domdefaults'} = 1;
10910: }
1.121 raeburn 10911: }
10912: $resulttext = &mt('Changes made:').'<ul>';
10913: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10914: if ($item eq 'uselcmath') {
1.121 raeburn 10915: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10916: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10917: } else {
1.160.6.57 raeburn 10918: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10919: }
10920: } elsif ($item eq 'usejsme') {
10921: if ($env{'form.'.$item} eq '1') {
10922: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10923: } else {
10924: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10925: }
1.139 raeburn 10926: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10927: $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 10928: } elsif ($item eq 'uploadquota') {
10929: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10930: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10931: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10932: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10933: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10934:
1.160.6.21 raeburn 10935: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10936: '</ul>'.
10937: '</li>';
10938: } else {
10939: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10940: }
1.160.6.70 raeburn 10941: } elsif ($item eq 'mysqltables') {
10942: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
10943: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
10944: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
10945: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
10946: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
10947: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
10948: '</ul>'.
10949: '</li>';
10950: } else {
10951: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
10952: }
1.160.6.57 raeburn 10953: } elsif ($item eq 'postsubmit') {
10954: if ($domdefaults{'postsubmit'} eq 'off') {
10955: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10956: } else {
10957: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10958: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10959: $resulttext .= &mt('durations:').'<ul>';
10960: foreach my $type (@types) {
10961: $resulttext .= '<li>';
10962: my $timeout;
10963: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10964: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10965: }
10966: my $display;
10967: if ($timeout eq '0') {
10968: $display = &mt('unlimited');
10969: } elsif ($timeout eq '') {
10970: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10971: } else {
10972: $display = &mt('[quant,_1,second]',$timeout);
10973: }
10974: if ($type eq 'community') {
10975: $resulttext .= &mt('Communities');
10976: } elsif ($type eq 'official') {
10977: $resulttext .= &mt('Official courses');
10978: } elsif ($type eq 'unofficial') {
10979: $resulttext .= &mt('Unofficial courses');
10980: } elsif ($type eq 'textbook') {
10981: $resulttext .= &mt('Textbook courses');
10982: }
10983: $resulttext .= ' -- '.$display.'</li>';
10984: }
10985: $resulttext .= '</ul>';
10986: }
10987: $resulttext .= '</li>';
10988: }
1.160.6.16 raeburn 10989: } elsif ($item eq 'coursecredits') {
10990: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10991: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10992: ($domdefaults{'unofficialcredits'} eq '') &&
10993: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10994: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10995: } else {
10996: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10997: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10998: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10999: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 11000: '</ul>'.
11001: '</li>';
11002: }
11003: } else {
11004: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11005: }
1.160.6.64 raeburn 11006: } elsif ($item eq 'canclone') {
11007: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11008: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11009: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11010: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11011: }
11012: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11013: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11014: } else {
11015: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11016: }
1.140 raeburn 11017: }
1.121 raeburn 11018: }
11019: $resulttext .= '</ul>';
11020: } else {
11021: $resulttext = &mt('No changes made to course defaults');
11022: }
11023: } else {
11024: $resulttext = '<span class="LC_error">'.
11025: &mt('An error occurred: [_1]',$putresult).'</span>';
11026: }
11027: return $resulttext;
11028: }
11029:
1.160.6.37 raeburn 11030: sub modify_selfenrollment {
11031: my ($dom,$lastactref,%domconfig) = @_;
11032: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
11033: my @types = ('official','unofficial','community','textbook');
11034: my %titles = &tool_titles();
11035: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11036: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
11037: $ordered{'default'} = ['types','registered','approval','limit'];
11038:
11039: my (%roles,%shown,%toplevel);
11040: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11041:
11042: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11043: if ($domconfig{'selfenrollment'} eq '') {
11044: $domconfig{'selfenrollment'} = {};
11045: }
11046: }
11047: %toplevel = (
11048: admin => 'Configuration Rights',
11049: default => 'Default settings',
11050: validation => 'Validation of self-enrollment requests',
11051: );
11052: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
11053:
11054: if (ref($ordered{'admin'}) eq 'ARRAY') {
11055: foreach my $item (@{$ordered{'admin'}}) {
11056: foreach my $type (@types) {
11057: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
11058: $selfenrollhash{'admin'}{$type}{$item} = 1;
11059: } else {
11060: $selfenrollhash{'admin'}{$type}{$item} = 0;
11061: }
11062: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
11063: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
11064: if ($selfenrollhash{'admin'}{$type}{$item} ne
11065: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
11066: push(@{$changes{'admin'}{$type}},$item);
11067: }
11068: } else {
11069: if (!$selfenrollhash{'admin'}{$type}{$item}) {
11070: push(@{$changes{'admin'}{$type}},$item);
11071: }
11072: }
11073: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
11074: push(@{$changes{'admin'}{$type}},$item);
11075: }
11076: }
11077: }
11078: }
11079:
11080: foreach my $item (@{$ordered{'default'}}) {
11081: foreach my $type (@types) {
11082: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
11083: if ($item eq 'types') {
11084: unless (($value eq 'all') || ($value eq 'dom')) {
11085: $value = '';
11086: }
11087: } elsif ($item eq 'registered') {
11088: unless ($value eq '1') {
11089: $value = 0;
11090: }
11091: } elsif ($item eq 'approval') {
11092: unless ($value =~ /^[012]$/) {
11093: $value = 0;
11094: }
11095: } else {
11096: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11097: $value = 'none';
11098: }
11099: }
11100: $selfenrollhash{'default'}{$type}{$item} = $value;
11101: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
11102: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11103: if ($selfenrollhash{'default'}{$type}{$item} ne
11104: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
11105: push(@{$changes{'default'}{$type}},$item);
11106: }
11107: } else {
11108: push(@{$changes{'default'}{$type}},$item);
11109: }
11110: } else {
11111: push(@{$changes{'default'}{$type}},$item);
11112: }
11113: if ($item eq 'limit') {
11114: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11115: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
11116: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
11117: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
11118: }
11119: } else {
11120: $selfenrollhash{'default'}{$type}{'cap'} = '';
11121: }
11122: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11123: if ($selfenrollhash{'default'}{$type}{'cap'} ne
11124: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
11125: push(@{$changes{'default'}{$type}},'cap');
11126: }
11127: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
11128: push(@{$changes{'default'}{$type}},'cap');
11129: }
11130: }
11131: }
11132: }
11133:
11134: foreach my $item (@{$itemsref}) {
11135: if ($item eq 'fields') {
11136: my @changed;
11137: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
11138: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
11139: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
11140: }
11141: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11142: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
11143: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
11144: $domconfig{'selfenrollment'}{'validation'}{$item});
11145: } else {
11146: @changed = @{$selfenrollhash{'validation'}{$item}};
11147: }
11148: } else {
11149: @changed = @{$selfenrollhash{'validation'}{$item}};
11150: }
11151: if (@changed) {
11152: if ($selfenrollhash{'validation'}{$item}) {
11153: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
11154: } else {
11155: $changes{'validation'}{$item} = &mt('None');
11156: }
11157: }
11158: } else {
11159: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
11160: if ($item eq 'markup') {
11161: if ($env{'form.selfenroll_validation_'.$item}) {
11162: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11163: }
11164: }
11165: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11166: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
11167: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
11168: }
11169: }
11170: }
11171: }
11172:
11173: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
11174: $dom);
11175: if ($putresult eq 'ok') {
11176: if (keys(%changes) > 0) {
11177: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11178: $resulttext = &mt('Changes made:').'<ul>';
11179: foreach my $key ('admin','default','validation') {
11180: if (ref($changes{$key}) eq 'HASH') {
11181: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11182: if ($key eq 'validation') {
11183: foreach my $item (@{$itemsref}) {
11184: if (exists($changes{$key}{$item})) {
11185: if ($item eq 'markup') {
11186: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11187: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11188: } else {
11189: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11190: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11191: }
11192: }
11193: }
11194: } else {
11195: foreach my $type (@types) {
11196: if ($type eq 'community') {
11197: $roles{'1'} = &mt('Community personnel');
11198: } else {
11199: $roles{'1'} = &mt('Course personnel');
11200: }
11201: if (ref($changes{$key}{$type}) eq 'ARRAY') {
11202: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11203: if ($key eq 'admin') {
11204: my @mgrdc = ();
11205: if (ref($ordered{$key}) eq 'ARRAY') {
11206: foreach my $item (@{$ordered{'admin'}}) {
11207: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11208: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11209: push(@mgrdc,$item);
11210: }
11211: }
11212: }
11213: if (@mgrdc) {
11214: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11215: } else {
11216: delete($domdefaults{$type.'selfenrolladmdc'});
11217: }
11218: }
11219: } else {
11220: if (ref($ordered{$key}) eq 'ARRAY') {
11221: foreach my $item (@{$ordered{$key}}) {
11222: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11223: $domdefaults{$type.'selfenroll'.$item} =
11224: $selfenrollhash{$key}{$type}{$item};
11225: }
11226: }
11227: }
11228: }
11229: }
11230: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11231: foreach my $item (@{$ordered{$key}}) {
11232: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11233: $resulttext .= '<li>';
11234: if ($key eq 'admin') {
11235: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11236: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
11237: } else {
11238: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
11239: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
11240: }
11241: $resulttext .= '</li>';
11242: }
11243: }
11244: $resulttext .= '</ul></li>';
11245: }
11246: }
11247: $resulttext .= '</ul></li>';
11248: }
11249: }
11250: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
11251: my $cachetime = 24*60*60;
11252: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11253: if (ref($lastactref) eq 'HASH') {
11254: $lastactref->{'domdefaults'} = 1;
11255: }
11256: }
11257: }
11258: $resulttext .= '</ul>';
11259: } else {
11260: $resulttext = &mt('No changes made to self-enrollment settings');
11261: }
11262: } else {
11263: $resulttext = '<span class="LC_error">'.
11264: &mt('An error occurred: [_1]',$putresult).'</span>';
11265: }
11266: return $resulttext;
11267: }
11268:
1.137 raeburn 11269: sub modify_usersessions {
1.160.6.27 raeburn 11270: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 11271: my @hostingtypes = ('version','excludedomain','includedomain');
11272: my @offloadtypes = ('primary','default');
11273: my %types = (
11274: remote => \@hostingtypes,
11275: hosted => \@hostingtypes,
11276: spares => \@offloadtypes,
11277: );
11278: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 11279: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 11280: my (%by_ip,%by_location,@intdoms);
11281: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
11282: my @locations = sort(keys(%by_location));
1.137 raeburn 11283: my (%defaultshash,%changes);
11284: foreach my $prefix (@prefixes) {
11285: $defaultshash{'usersessions'}{$prefix} = {};
11286: }
1.160.6.27 raeburn 11287: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11288: my $resulttext;
1.138 raeburn 11289: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11290: foreach my $prefix (@prefixes) {
1.145 raeburn 11291: next if ($prefix eq 'spares');
11292: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11293: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11294: if ($type eq 'version') {
11295: my $value = $env{'form.'.$prefix.'_'.$type};
11296: my $okvalue;
11297: if ($value ne '') {
11298: if (grep(/^\Q$value\E$/,@lcversions)) {
11299: $okvalue = $value;
11300: }
11301: }
11302: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11303: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11304: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11305: if ($inuse == 0) {
11306: $changes{$prefix}{$type} = 1;
11307: } else {
11308: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11309: $changes{$prefix}{$type} = 1;
11310: }
11311: if ($okvalue ne '') {
11312: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11313: }
11314: }
11315: } else {
11316: if (($inuse == 1) && ($okvalue ne '')) {
11317: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11318: $changes{$prefix}{$type} = 1;
11319: }
11320: }
11321: } else {
11322: if (($inuse == 1) && ($okvalue ne '')) {
11323: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11324: $changes{$prefix}{$type} = 1;
11325: }
11326: }
11327: } else {
11328: if (($inuse == 1) && ($okvalue ne '')) {
11329: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11330: $changes{$prefix}{$type} = 1;
11331: }
11332: }
11333: } else {
11334: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11335: my @okvals;
11336: foreach my $val (@vals) {
1.138 raeburn 11337: if ($val =~ /:/) {
11338: my @items = split(/:/,$val);
11339: foreach my $item (@items) {
11340: if (ref($by_location{$item}) eq 'ARRAY') {
11341: push(@okvals,$item);
11342: }
11343: }
11344: } else {
11345: if (ref($by_location{$val}) eq 'ARRAY') {
11346: push(@okvals,$val);
11347: }
1.137 raeburn 11348: }
11349: }
11350: @okvals = sort(@okvals);
11351: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11352: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11353: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11354: if ($inuse == 0) {
11355: $changes{$prefix}{$type} = 1;
11356: } else {
11357: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11358: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11359: if (@changed > 0) {
11360: $changes{$prefix}{$type} = 1;
11361: }
11362: }
11363: } else {
11364: if ($inuse == 1) {
11365: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11366: $changes{$prefix}{$type} = 1;
11367: }
11368: }
11369: } else {
11370: if ($inuse == 1) {
11371: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11372: $changes{$prefix}{$type} = 1;
11373: }
11374: }
11375: } else {
11376: if ($inuse == 1) {
11377: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11378: $changes{$prefix}{$type} = 1;
11379: }
11380: }
11381: }
11382: }
11383: }
1.145 raeburn 11384:
11385: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11386: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11387: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11388: my $savespares;
11389:
11390: foreach my $lonhost (sort(keys(%servers))) {
11391: my $serverhomeID =
11392: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11393: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11394: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11395: my %spareschg;
11396: foreach my $type (@{$types{'spares'}}) {
11397: my @okspares;
11398: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
11399: foreach my $server (@checked) {
1.152 raeburn 11400: if (&Apache::lonnet::hostname($server) ne '') {
11401: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
11402: unless (grep(/^\Q$server\E$/,@okspares)) {
11403: push(@okspares,$server);
11404: }
1.145 raeburn 11405: }
11406: }
11407: }
11408: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
11409: my $newspare;
1.152 raeburn 11410: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
11411: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 11412: $newspare = $new;
11413: }
11414: }
1.152 raeburn 11415: my @spares;
11416: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
11417: @spares = sort(@okspares,$newspare);
11418: } else {
11419: @spares = sort(@okspares);
11420: }
11421: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 11422: if (ref($spareid{$lonhost}) eq 'HASH') {
11423: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 11424: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 11425: if (@diffs > 0) {
11426: $spareschg{$type} = 1;
11427: }
11428: }
11429: }
11430: }
11431: if (keys(%spareschg) > 0) {
11432: $changes{'spares'}{$lonhost} = \%spareschg;
11433: }
11434: }
1.160.6.61 raeburn 11435: $defaultshash{'usersessions'}{'offloadnow'} = {};
11436: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
11437: my @okoffload;
11438: if (@offloadnow) {
11439: foreach my $server (@offloadnow) {
11440: if (&Apache::lonnet::hostname($server) ne '') {
11441: unless (grep(/^\Q$server\E$/,@okoffload)) {
11442: push(@okoffload,$server);
11443: }
11444: }
11445: }
11446: if (@okoffload) {
11447: foreach my $lonhost (@okoffload) {
11448: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
11449: }
11450: }
11451: }
1.145 raeburn 11452: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11453: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
11454: if (ref($changes{'spares'}) eq 'HASH') {
11455: if (keys(%{$changes{'spares'}}) > 0) {
11456: $savespares = 1;
11457: }
11458: }
11459: } else {
11460: $savespares = 1;
11461: }
1.160.6.61 raeburn 11462: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
11463: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
11464: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
11465: $changes{'offloadnow'} = 1;
11466: last;
11467: }
11468: }
11469: unless ($changes{'offloadnow'}) {
11470: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
11471: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
11472: $changes{'offloadnow'} = 1;
11473: last;
11474: }
11475: }
11476: }
11477: } elsif (@okoffload) {
11478: $changes{'offloadnow'} = 1;
11479: }
11480: } elsif (@okoffload) {
11481: $changes{'offloadnow'} = 1;
1.145 raeburn 11482: }
1.147 raeburn 11483: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11484: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 11485: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11486: $dom);
11487: if ($putresult eq 'ok') {
11488: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11489: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11490: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11491: }
11492: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11493: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11494: }
1.160.6.61 raeburn 11495: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11496: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11497: }
1.137 raeburn 11498: }
11499: my $cachetime = 24*60*60;
11500: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11501: if (ref($lastactref) eq 'HASH') {
11502: $lastactref->{'domdefaults'} = 1;
11503: }
1.147 raeburn 11504: if (keys(%changes) > 0) {
11505: my %lt = &usersession_titles();
11506: $resulttext = &mt('Changes made:').'<ul>';
11507: foreach my $prefix (@prefixes) {
11508: if (ref($changes{$prefix}) eq 'HASH') {
11509: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11510: if ($prefix eq 'spares') {
11511: if (ref($changes{$prefix}) eq 'HASH') {
11512: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11513: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 11514: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 11515: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11516: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 11517: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11518: foreach my $type (@{$types{$prefix}}) {
11519: if ($changes{$prefix}{$lonhost}{$type}) {
11520: my $offloadto = &mt('None');
11521: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11522: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11523: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11524: }
1.145 raeburn 11525: }
1.147 raeburn 11526: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 11527: }
1.137 raeburn 11528: }
11529: }
1.147 raeburn 11530: $resulttext .= '</li>';
1.137 raeburn 11531: }
11532: }
1.147 raeburn 11533: } else {
11534: foreach my $type (@{$types{$prefix}}) {
11535: if (defined($changes{$prefix}{$type})) {
11536: my $newvalue;
11537: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11538: if (ref($defaultshash{'usersessions'}{$prefix})) {
11539: if ($type eq 'version') {
11540: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11541: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11542: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11543: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11544: }
1.145 raeburn 11545: }
11546: }
11547: }
1.147 raeburn 11548: if ($newvalue eq '') {
11549: if ($type eq 'version') {
11550: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11551: } else {
11552: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11553: }
1.145 raeburn 11554: } else {
1.147 raeburn 11555: if ($type eq 'version') {
11556: $newvalue .= ' '.&mt('(or later)');
11557: }
11558: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11559: }
1.137 raeburn 11560: }
11561: }
11562: }
1.147 raeburn 11563: $resulttext .= '</ul>';
1.137 raeburn 11564: }
11565: }
1.160.6.61 raeburn 11566: if ($changes{'offloadnow'}) {
11567: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11568: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11569: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11570: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11571: $resulttext .= '<li>'.$lonhost.'</li>';
11572: }
11573: $resulttext .= '</ul>';
11574: } else {
11575: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11576: }
11577: } else {
11578: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11579: }
11580: }
1.147 raeburn 11581: $resulttext .= '</ul>';
11582: } else {
11583: $resulttext = $nochgmsg;
1.137 raeburn 11584: }
11585: } else {
11586: $resulttext = '<span class="LC_error">'.
11587: &mt('An error occurred: [_1]',$putresult).'</span>';
11588: }
11589: } else {
1.147 raeburn 11590: $resulttext = $nochgmsg;
1.137 raeburn 11591: }
11592: return $resulttext;
11593: }
11594:
1.150 raeburn 11595: sub modify_loadbalancing {
11596: my ($dom,%domconfig) = @_;
11597: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11598: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11599: my ($othertitle,$usertypes,$types) =
11600: &Apache::loncommon::sorted_inst_types($dom);
11601: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11602: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11603: my @sparestypes = ('primary','default');
11604: my %typetitles = &sparestype_titles();
11605: my $resulttext;
1.160.6.7 raeburn 11606: my (%currbalancer,%currtargets,%currrules,%existing);
11607: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11608: %existing = %{$domconfig{'loadbalancing'}};
11609: }
11610: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11611: \%currtargets,\%currrules);
11612: my ($saveloadbalancing,%defaultshash,%changes);
11613: my ($alltypes,$othertypes,$titles) =
11614: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11615: my %ruletitles = &offloadtype_text();
11616: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11617: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11618: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11619: if ($balancer eq '') {
11620: next;
11621: }
11622: if (!exists($servers{$balancer})) {
11623: if (exists($currbalancer{$balancer})) {
11624: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11625: }
1.160.6.7 raeburn 11626: next;
11627: }
11628: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11629: push(@{$changes{'delete'}},$balancer);
11630: next;
11631: }
11632: if (!exists($currbalancer{$balancer})) {
11633: push(@{$changes{'add'}},$balancer);
11634: }
11635: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11636: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11637: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11638: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11639: $saveloadbalancing = 1;
11640: }
11641: foreach my $sparetype (@sparestypes) {
11642: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11643: my @offloadto;
11644: foreach my $target (@targets) {
11645: if (($servers{$target}) && ($target ne $balancer)) {
11646: if ($sparetype eq 'default') {
11647: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11648: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11649: }
11650: }
1.160.6.7 raeburn 11651: unless(grep(/^\Q$target\E$/,@offloadto)) {
11652: push(@offloadto,$target);
11653: }
1.150 raeburn 11654: }
11655: }
1.160.6.76! raeburn 11656: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
! 11657: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
! 11658: push(@offloadto,$balancer);
! 11659: }
! 11660: }
! 11661: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11662: }
1.160.6.7 raeburn 11663: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11664: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11665: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11666: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11667: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11668: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11669: }
1.160.6.7 raeburn 11670: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11671: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11672: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11673: }
11674: }
11675: }
11676: } else {
1.160.6.7 raeburn 11677: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11678: foreach my $sparetype (@sparestypes) {
11679: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11680: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11681: $changes{'curr'}{$balancer}{'targets'} = 1;
11682: }
1.150 raeburn 11683: }
11684: }
1.160.6.7 raeburn 11685: }
1.150 raeburn 11686: }
11687: my $ishomedom;
1.160.6.7 raeburn 11688: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11689: $ishomedom = 1;
1.150 raeburn 11690: }
11691: if (ref($alltypes) eq 'ARRAY') {
11692: foreach my $type (@{$alltypes}) {
11693: my $rule;
1.160.6.7 raeburn 11694: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11695: (!$ishomedom)) {
1.160.6.7 raeburn 11696: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11697: }
11698: if ($rule eq 'specific') {
1.160.6.55 raeburn 11699: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11700: if (exists($servers{$specifiedhost})) {
11701: $rule = $specifiedhost;
11702: }
1.150 raeburn 11703: }
1.160.6.7 raeburn 11704: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11705: if (ref($currrules{$balancer}) eq 'HASH') {
11706: if ($rule ne $currrules{$balancer}{$type}) {
11707: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11708: }
11709: } elsif ($rule ne '') {
1.160.6.7 raeburn 11710: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11711: }
11712: }
11713: }
1.160.6.7 raeburn 11714: }
11715: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11716: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11717: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11718: $defaultshash{'loadbalancing'} = {};
11719: }
11720: my $putresult = &Apache::lonnet::put_dom('configuration',
11721: \%defaultshash,$dom);
11722: if ($putresult eq 'ok') {
11723: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11724: my %toupdate;
1.160.6.7 raeburn 11725: if (ref($changes{'delete'}) eq 'ARRAY') {
11726: foreach my $balancer (sort(@{$changes{'delete'}})) {
11727: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11728: $toupdate{$balancer} = 1;
1.150 raeburn 11729: }
1.160.6.7 raeburn 11730: }
11731: if (ref($changes{'add'}) eq 'ARRAY') {
11732: foreach my $balancer (sort(@{$changes{'add'}})) {
11733: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11734: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11735: }
11736: }
11737: if (ref($changes{'curr'}) eq 'HASH') {
11738: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11739: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11740: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11741: if ($changes{'curr'}{$balancer}{'targets'}) {
11742: my %offloadstr;
11743: foreach my $sparetype (@sparestypes) {
11744: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11745: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11746: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11747: }
11748: }
1.150 raeburn 11749: }
1.160.6.7 raeburn 11750: if (keys(%offloadstr) == 0) {
11751: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11752: } else {
1.160.6.7 raeburn 11753: my $showoffload;
11754: foreach my $sparetype (@sparestypes) {
11755: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11756: if (defined($offloadstr{$sparetype})) {
11757: $showoffload .= $offloadstr{$sparetype};
11758: } else {
11759: $showoffload .= &mt('None');
11760: }
11761: $showoffload .= (' 'x3);
11762: }
11763: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11764: }
11765: }
11766: }
1.160.6.7 raeburn 11767: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11768: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11769: foreach my $type (@{$alltypes}) {
11770: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11771: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11772: my $balancetext;
11773: if ($rule eq '') {
11774: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11775: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11776: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11777: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11778: foreach my $sparetype (@sparestypes) {
11779: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11780: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11781: }
11782: }
1.160.6.55 raeburn 11783: foreach my $item (@{$alltypes}) {
11784: next if ($item =~ /^_LC_ipchange/);
11785: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11786: if ($hasrule eq 'homeserver') {
11787: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11788: } else {
11789: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11790: if ($servers{$hasrule}) {
11791: $toupdate{$hasrule} = 1;
11792: }
11793: }
11794: }
11795: }
11796: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11797: $balancetext = $ruletitles{$rule};
11798: } else {
11799: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11800: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11801: if ($receiver) {
11802: $toupdate{$receiver};
11803: }
11804: }
11805: } else {
11806: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11807: }
1.160.6.7 raeburn 11808: } else {
11809: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11810: }
1.160.6.26 raeburn 11811: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11812: }
11813: }
11814: }
11815: }
1.160.6.54 raeburn 11816: if (keys(%toupdate)) {
11817: my %thismachine;
11818: my $updatedhere;
11819: my $cachetime = 60*60*24;
11820: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11821: foreach my $lonhost (keys(%toupdate)) {
11822: if ($thismachine{$lonhost}) {
11823: unless ($updatedhere) {
11824: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11825: $defaultshash{'loadbalancing'},
11826: $cachetime);
11827: $updatedhere = 1;
11828: }
11829: } else {
11830: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11831: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11832: }
11833: }
11834: }
1.150 raeburn 11835: }
1.160.6.7 raeburn 11836: }
11837: if ($resulttext ne '') {
11838: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11839: } else {
11840: $resulttext = $nochgmsg;
11841: }
11842: } else {
1.160.6.7 raeburn 11843: $resulttext = $nochgmsg;
1.150 raeburn 11844: }
11845: } else {
1.160.6.7 raeburn 11846: $resulttext = '<span class="LC_error">'.
11847: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11848: }
11849: } else {
1.160.6.7 raeburn 11850: $resulttext = $nochgmsg;
1.150 raeburn 11851: }
11852: return $resulttext;
11853: }
11854:
1.48 raeburn 11855: sub recurse_check {
11856: my ($chkcats,$categories,$depth,$name) = @_;
11857: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11858: my $chg = 0;
11859: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11860: my $category = $chkcats->[$depth]{$name}[$j];
11861: my $item;
11862: if ($category eq '') {
11863: $chg ++;
11864: } else {
11865: my $deeper = $depth + 1;
11866: $item = &escape($category).':'.&escape($name).':'.$depth;
11867: if ($chg) {
11868: $categories->{$item} -= $chg;
11869: }
11870: &recurse_check($chkcats,$categories,$deeper,$category);
11871: $deeper --;
11872: }
11873: }
11874: }
11875: return;
11876: }
11877:
11878: sub recurse_cat_deletes {
11879: my ($item,$coursecategories,$deletions) = @_;
11880: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11881: my $subdepth = $depth + 1;
11882: if (ref($coursecategories) eq 'HASH') {
11883: foreach my $subitem (keys(%{$coursecategories})) {
11884: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11885: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11886: delete($coursecategories->{$subitem});
11887: $deletions->{$subitem} = 1;
11888: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11889: }
1.48 raeburn 11890: }
11891: }
11892: return;
11893: }
11894:
1.125 raeburn 11895: sub get_active_dcs {
11896: my ($dom) = @_;
1.160.6.16 raeburn 11897: my $now = time;
11898: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11899: my %domcoords;
11900: my $numdcs = 0;
11901: foreach my $server (keys(%dompersonnel)) {
11902: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11903: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11904: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11905: }
11906: }
11907: return %domcoords;
11908: }
11909:
11910: sub active_dc_picker {
1.160.6.16 raeburn 11911: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11912: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11913: my @domcoord = keys(%domcoords);
11914: if (keys(%currhash)) {
11915: foreach my $dc (keys(%currhash)) {
11916: unless (exists($domcoords{$dc})) {
11917: push(@domcoord,$dc);
11918: }
11919: }
11920: }
11921: @domcoord = sort(@domcoord);
11922: my $numdcs = scalar(@domcoord);
11923: my $rows = 0;
11924: my $table;
1.125 raeburn 11925: if ($numdcs > 1) {
1.160.6.16 raeburn 11926: $table = '<table>';
11927: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11928: my $rem = $i%($numinrow);
11929: if ($rem == 0) {
11930: if ($i > 0) {
1.160.6.16 raeburn 11931: $table .= '</tr>';
1.125 raeburn 11932: }
1.160.6.16 raeburn 11933: $table .= '<tr>';
11934: $rows ++;
1.125 raeburn 11935: }
1.160.6.16 raeburn 11936: my $check = '';
11937: if ($inputtype eq 'radio') {
11938: if (keys(%currhash) == 0) {
11939: if (!$i) {
11940: $check = ' checked="checked"';
11941: }
11942: } elsif (exists($currhash{$domcoord[$i]})) {
11943: $check = ' checked="checked"';
11944: }
11945: } else {
11946: if (exists($currhash{$domcoord[$i]})) {
11947: $check = ' checked="checked"';
1.125 raeburn 11948: }
11949: }
1.160.6.16 raeburn 11950: if ($i == @domcoord - 1) {
1.125 raeburn 11951: my $colsleft = $numinrow - $rem;
11952: if ($colsleft > 1) {
1.160.6.16 raeburn 11953: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11954: } else {
1.160.6.16 raeburn 11955: $table .= '<td class="LC_left_item">';
1.125 raeburn 11956: }
11957: } else {
1.160.6.16 raeburn 11958: $table .= '<td class="LC_left_item">';
11959: }
11960: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11961: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11962: $table .= '<span class="LC_nobreak"><label>'.
11963: '<input type="'.$inputtype.'" name="'.$name.'"'.
11964: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11965: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11966: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11967: }
1.160.6.33 raeburn 11968: $table .= '</label></span></td>';
1.125 raeburn 11969: }
1.160.6.16 raeburn 11970: $table .= '</tr></table>';
11971: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11972: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11973: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11974: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11975: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11976: if ($user ne $dcname.':'.$dcdom) {
11977: $table .= ' ('.$dcname.':'.$dcdom.')';
11978: }
1.160.6.16 raeburn 11979: } else {
11980: my $check;
11981: if (exists($currhash{$domcoord[0]})) {
11982: $check = ' checked="checked"';
11983: }
1.160.6.50 raeburn 11984: $table = '<span class="LC_nobreak"><label>'.
11985: '<input type="checkbox" name="'.$name.'" '.
11986: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11987: if ($user ne $dcname.':'.$dcdom) {
11988: $table .= ' ('.$dcname.':'.$dcdom.')';
11989: }
11990: $table .= '</label></span>';
1.160.6.16 raeburn 11991: $rows ++;
11992: }
1.125 raeburn 11993: }
1.160.6.16 raeburn 11994: return ($numdcs,$table,$rows);
1.125 raeburn 11995: }
11996:
1.137 raeburn 11997: sub usersession_titles {
11998: return &Apache::lonlocal::texthash(
11999: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12000: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12001: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12002: version => 'LON-CAPA version requirement',
1.138 raeburn 12003: excludedomain => 'Allow all, but exclude specific domains',
12004: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12005: primary => 'Primary (checked first)',
1.154 raeburn 12006: default => 'Default',
1.137 raeburn 12007: );
12008: }
12009:
1.152 raeburn 12010: sub id_for_thisdom {
12011: my (%servers) = @_;
12012: my %altids;
12013: foreach my $server (keys(%servers)) {
12014: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12015: if ($serverhome ne $server) {
12016: $altids{$serverhome} = $server;
12017: }
12018: }
12019: return %altids;
12020: }
12021:
1.150 raeburn 12022: sub count_servers {
12023: my ($currbalancer,%servers) = @_;
12024: my (@spares,$numspares);
12025: foreach my $lonhost (sort(keys(%servers))) {
12026: next if ($currbalancer eq $lonhost);
12027: push(@spares,$lonhost);
12028: }
12029: if ($currbalancer) {
12030: $numspares = scalar(@spares);
12031: } else {
12032: $numspares = scalar(@spares) - 1;
12033: }
12034: return ($numspares,@spares);
12035: }
12036:
12037: sub lonbalance_targets_js {
1.160.6.7 raeburn 12038: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 12039: my $select = &mt('Select');
12040: my ($alltargets,$allishome,$allinsttypes,@alltypes);
12041: if (ref($servers) eq 'HASH') {
12042: $alltargets = join("','",sort(keys(%{$servers})));
12043: my @homedoms;
12044: foreach my $server (sort(keys(%{$servers}))) {
12045: if (&Apache::lonnet::host_domain($server) eq $dom) {
12046: push(@homedoms,'1');
12047: } else {
12048: push(@homedoms,'0');
12049: }
12050: }
12051: $allishome = join("','",@homedoms);
12052: }
12053: if (ref($types) eq 'ARRAY') {
12054: if (@{$types} > 0) {
12055: @alltypes = @{$types};
12056: }
12057: }
12058: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
12059: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 12060: my (%currbalancer,%currtargets,%currrules,%existing);
12061: if (ref($settings) eq 'HASH') {
12062: %existing = %{$settings};
12063: }
12064: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
12065: \%currtargets,\%currrules);
12066: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 12067: return <<"END";
12068:
12069: <script type="text/javascript">
12070: // <![CDATA[
12071:
1.160.6.7 raeburn 12072: currBalancers = new Array('$balancers');
12073:
12074: function toggleTargets(balnum) {
12075: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12076: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
12077: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
12078: var prevbalancer = prevhostitem.value;
12079: var baltotal = document.getElementById('loadbalancing_total').value;
12080: prevhostitem.value = balancer;
12081: if (prevbalancer != '') {
12082: var prevIdx = currBalancers.indexOf(prevbalancer);
12083: if (prevIdx != -1) {
12084: currBalancers.splice(prevIdx,1);
12085: }
12086: }
1.150 raeburn 12087: if (balancer == '') {
1.160.6.7 raeburn 12088: hideSpares(balnum);
1.150 raeburn 12089: } else {
1.160.6.7 raeburn 12090: var currIdx = currBalancers.indexOf(balancer);
12091: if (currIdx == -1) {
12092: currBalancers.push(balancer);
12093: }
1.150 raeburn 12094: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 12095: var ishomedom = homedoms[lonhostitem.selectedIndex];
12096: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 12097: }
1.160.6.7 raeburn 12098: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 12099: return;
12100: }
12101:
1.160.6.7 raeburn 12102: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 12103: var alltargets = new Array('$alltargets');
12104: var insttypes = new Array('$allinsttypes');
1.151 raeburn 12105: var offloadtypes = new Array('primary','default');
12106:
1.160.6.7 raeburn 12107: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
12108: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 12109:
1.151 raeburn 12110: for (var i=0; i<offloadtypes.length; i++) {
12111: var count = 0;
12112: for (var j=0; j<alltargets.length; j++) {
12113: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 12114: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
12115: item.value = alltargets[j];
12116: item.style.textAlign='left';
12117: item.style.textFace='normal';
12118: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
12119: if (currBalancers.indexOf(alltargets[j]) == -1) {
12120: item.disabled = '';
12121: } else {
12122: item.disabled = 'disabled';
12123: item.checked = false;
12124: }
1.151 raeburn 12125: count ++;
12126: }
1.150 raeburn 12127: }
12128: }
1.151 raeburn 12129: for (var k=0; k<insttypes.length; k++) {
12130: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 12131: if (ishomedom == 1) {
1.160.6.7 raeburn 12132: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12133: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12134: } else {
1.160.6.7 raeburn 12135: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12136: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 12137: }
12138: } else {
1.160.6.7 raeburn 12139: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12140: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12141: }
1.151 raeburn 12142: if ((insttypes[k] != '_LC_external') &&
12143: ((insttypes[k] != '_LC_internetdom') ||
12144: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 12145: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
12146: item.options.length = 0;
12147: item.options[0] = new Option("","",true,true);
12148: var idx = 0;
1.151 raeburn 12149: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 12150: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
12151: idx ++;
12152: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 12153: }
12154: }
12155: }
12156: }
12157: return;
12158: }
12159:
1.160.6.7 raeburn 12160: function hideSpares(balnum) {
1.150 raeburn 12161: var alltargets = new Array('$alltargets');
12162: var insttypes = new Array('$allinsttypes');
12163: var offloadtypes = new Array('primary','default');
12164:
1.160.6.7 raeburn 12165: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
12166: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 12167:
12168: var total = alltargets.length - 1;
12169: for (var i=0; i<offloadtypes; i++) {
12170: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 12171: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
12172: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
12173: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 12174: }
1.150 raeburn 12175: }
12176: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 12177: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12178: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 12179: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 12180: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
12181: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 12182: }
12183: }
12184: return;
12185: }
12186:
1.160.6.7 raeburn 12187: function checkOffloads(item,balnum,type) {
1.150 raeburn 12188: var alltargets = new Array('$alltargets');
12189: var offloadtypes = new Array('primary','default');
12190: if (item.checked) {
12191: var total = alltargets.length - 1;
12192: var other;
12193: if (type == offloadtypes[0]) {
1.151 raeburn 12194: other = offloadtypes[1];
1.150 raeburn 12195: } else {
1.151 raeburn 12196: other = offloadtypes[0];
1.150 raeburn 12197: }
12198: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 12199: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 12200: if (server == item.value) {
1.160.6.7 raeburn 12201: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12202: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 12203: }
12204: }
12205: }
12206: }
12207: return;
12208: }
12209:
1.160.6.7 raeburn 12210: function singleServerToggle(balnum,type) {
12211: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 12212: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 12213: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12214: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12215:
12216: } else {
1.160.6.7 raeburn 12217: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12218: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 12219: }
12220: return;
12221: }
12222:
1.160.6.7 raeburn 12223: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 12224: if (type == '_LC_external') {
1.160.6.26 raeburn 12225: return;
1.150 raeburn 12226: }
1.160.6.7 raeburn 12227: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 12228: for (var i=0; i<typesRules.length; i++) {
12229: if (formname.elements[typesRules[i]].checked) {
12230: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 12231: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12232: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12233: } else {
1.160.6.7 raeburn 12234: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12235: }
12236: }
12237: }
12238: return;
12239: }
12240:
12241: function balancerDeleteChange(balnum) {
12242: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12243: var baltotal = document.getElementById('loadbalancing_total').value;
12244: var addtarget;
12245: var removetarget;
12246: var action = 'delete';
12247: if (document.getElementById('loadbalancing_delete_'+balnum)) {
12248: var lonhost = hostitem.value;
12249: var currIdx = currBalancers.indexOf(lonhost);
12250: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
12251: if (currIdx != -1) {
12252: currBalancers.splice(currIdx,1);
12253: }
12254: addtarget = lonhost;
12255: } else {
12256: if (currIdx == -1) {
12257: currBalancers.push(lonhost);
12258: }
12259: removetarget = lonhost;
12260: action = 'undelete';
12261: }
12262: balancerChange(balnum,baltotal,action,addtarget,removetarget);
12263: }
12264: return;
12265: }
12266:
12267: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
12268: if (baltotal > 1) {
12269: var offloadtypes = new Array('primary','default');
12270: var alltargets = new Array('$alltargets');
12271: var insttypes = new Array('$allinsttypes');
12272: for (var i=0; i<baltotal; i++) {
12273: if (i != balnum) {
12274: for (var j=0; j<offloadtypes.length; j++) {
12275: var total = alltargets.length - 1;
12276: for (var k=0; k<total; k++) {
12277: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
12278: var server = serveritem.value;
12279: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12280: if (server == addtarget) {
12281: serveritem.disabled = '';
12282: }
12283: }
12284: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12285: if (server == removetarget) {
12286: serveritem.disabled = 'disabled';
12287: serveritem.checked = false;
12288: }
12289: }
12290: }
12291: }
12292: for (var j=0; j<insttypes.length; j++) {
12293: if (insttypes[j] != '_LC_external') {
12294: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12295: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12296: var currSel = singleserver.selectedIndex;
12297: var currVal = singleserver.options[currSel].value;
12298: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12299: var numoptions = singleserver.options.length;
12300: var needsnew = 1;
12301: for (var k=0; k<numoptions; k++) {
12302: if (singleserver.options[k] == addtarget) {
12303: needsnew = 0;
12304: break;
12305: }
12306: }
12307: if (needsnew == 1) {
12308: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12309: }
12310: }
12311: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12312: singleserver.options.length = 0;
12313: if ((currVal) && (currVal != removetarget)) {
12314: singleserver.options[0] = new Option("","",false,false);
12315: } else {
12316: singleserver.options[0] = new Option("","",true,true);
12317: }
12318: var idx = 0;
12319: for (var m=0; m<alltargets.length; m++) {
12320: if (currBalancers.indexOf(alltargets[m]) == -1) {
12321: idx ++;
12322: if (currVal == alltargets[m]) {
12323: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12324: } else {
12325: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12326: }
12327: }
12328: }
12329: }
12330: }
12331: }
12332: }
1.150 raeburn 12333: }
12334: }
12335: }
12336: return;
12337: }
12338:
1.152 raeburn 12339: // ]]>
12340: </script>
12341:
12342: END
12343: }
12344:
12345: sub new_spares_js {
12346: my @sparestypes = ('primary','default');
12347: my $types = join("','",@sparestypes);
12348: my $select = &mt('Select');
12349: return <<"END";
12350:
12351: <script type="text/javascript">
12352: // <![CDATA[
12353:
12354: function updateNewSpares(formname,lonhost) {
12355: var types = new Array('$types');
12356: var include = new Array();
12357: var exclude = new Array();
12358: for (var i=0; i<types.length; i++) {
12359: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12360: for (var j=0; j<spareboxes.length; j++) {
12361: if (formname.elements[spareboxes[j]].checked) {
12362: exclude.push(formname.elements[spareboxes[j]].value);
12363: } else {
12364: include.push(formname.elements[spareboxes[j]].value);
12365: }
12366: }
12367: }
12368: for (var i=0; i<types.length; i++) {
12369: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12370: var selIdx = newSpare.selectedIndex;
12371: var currnew = newSpare.options[selIdx].value;
12372: var okSpares = new Array();
12373: for (var j=0; j<newSpare.options.length; j++) {
12374: var possible = newSpare.options[j].value;
12375: if (possible != '') {
12376: if (exclude.indexOf(possible) == -1) {
12377: okSpares.push(possible);
12378: } else {
12379: if (currnew == possible) {
12380: selIdx = 0;
12381: }
12382: }
12383: }
12384: }
12385: for (var k=0; k<include.length; k++) {
12386: if (okSpares.indexOf(include[k]) == -1) {
12387: okSpares.push(include[k]);
12388: }
12389: }
12390: okSpares.sort();
12391: newSpare.options.length = 0;
12392: if (selIdx == 0) {
12393: newSpare.options[0] = new Option("$select","",true,true);
12394: } else {
12395: newSpare.options[0] = new Option("$select","",false,false);
12396: }
12397: for (var m=0; m<okSpares.length; m++) {
12398: var idx = m+1;
12399: var selThis = 0;
12400: if (selIdx != 0) {
12401: if (okSpares[m] == currnew) {
12402: selThis = 1;
12403: }
12404: }
12405: if (selThis == 1) {
12406: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
12407: } else {
12408: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
12409: }
12410: }
12411: }
12412: return;
12413: }
12414:
12415: function checkNewSpares(lonhost,type) {
12416: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
12417: var chosen = newSpare.options[newSpare.selectedIndex].value;
12418: if (chosen != '') {
12419: var othertype;
12420: var othernewSpare;
12421: if (type == 'primary') {
12422: othernewSpare = document.getElementById('newspare_default_'+lonhost);
12423: }
12424: if (type == 'default') {
12425: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
12426: }
12427: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
12428: othernewSpare.selectedIndex = 0;
12429: }
12430: }
12431: return;
12432: }
12433:
12434: // ]]>
12435: </script>
12436:
12437: END
12438:
12439: }
12440:
12441: sub common_domprefs_js {
12442: return <<"END";
12443:
12444: <script type="text/javascript">
12445: // <![CDATA[
12446:
1.150 raeburn 12447: function getIndicesByName(formname,item) {
1.152 raeburn 12448: var group = new Array();
1.150 raeburn 12449: for (var i=0;i<formname.elements.length;i++) {
12450: if (formname.elements[i].name == item) {
1.152 raeburn 12451: group.push(formname.elements[i].id);
1.150 raeburn 12452: }
12453: }
1.152 raeburn 12454: return group;
1.150 raeburn 12455: }
12456:
12457: // ]]>
12458: </script>
12459:
12460: END
1.152 raeburn 12461:
1.150 raeburn 12462: }
12463:
1.160.6.5 raeburn 12464: sub recaptcha_js {
12465: my %lt = &captcha_phrases();
12466: return <<"END";
12467:
12468: <script type="text/javascript">
12469: // <![CDATA[
12470:
12471: function updateCaptcha(caller,context) {
12472: var privitem;
12473: var pubitem;
12474: var privtext;
12475: var pubtext;
1.160.6.69 raeburn 12476: var versionitem;
12477: var versiontext;
1.160.6.5 raeburn 12478: if (document.getElementById(context+'_recaptchapub')) {
12479: pubitem = document.getElementById(context+'_recaptchapub');
12480: } else {
12481: return;
12482: }
12483: if (document.getElementById(context+'_recaptchapriv')) {
12484: privitem = document.getElementById(context+'_recaptchapriv');
12485: } else {
12486: return;
12487: }
12488: if (document.getElementById(context+'_recaptchapubtxt')) {
12489: pubtext = document.getElementById(context+'_recaptchapubtxt');
12490: } else {
12491: return;
12492: }
12493: if (document.getElementById(context+'_recaptchaprivtxt')) {
12494: privtext = document.getElementById(context+'_recaptchaprivtxt');
12495: } else {
12496: return;
12497: }
1.160.6.69 raeburn 12498: if (document.getElementById(context+'_recaptchaversion')) {
12499: versionitem = document.getElementById(context+'_recaptchaversion');
12500: } else {
12501: return;
12502: }
12503: if (document.getElementById(context+'_recaptchavertxt')) {
12504: versiontext = document.getElementById(context+'_recaptchavertxt');
12505: } else {
12506: return;
12507: }
1.160.6.5 raeburn 12508: if (caller.checked) {
12509: if (caller.value == 'recaptcha') {
12510: pubitem.type = 'text';
12511: privitem.type = 'text';
12512: pubitem.size = '40';
12513: privitem.size = '40';
12514: pubtext.innerHTML = "$lt{'pub'}";
12515: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 12516: versionitem.type = 'text';
12517: versionitem.size = '3';
12518: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 12519: } else {
12520: pubitem.type = 'hidden';
12521: privitem.type = 'hidden';
1.160.6.69 raeburn 12522: versionitem.type = 'hidden';
1.160.6.5 raeburn 12523: pubtext.innerHTML = '';
12524: privtext.innerHTML = '';
1.160.6.69 raeburn 12525: versiontext.innerHTML = '';
1.160.6.5 raeburn 12526: }
12527: }
12528: return;
12529: }
12530:
12531: // ]]>
12532: </script>
12533:
12534: END
12535:
12536: }
12537:
1.160.6.40 raeburn 12538: sub toggle_display_js {
1.160.6.16 raeburn 12539: return <<"END";
12540:
12541: <script type="text/javascript">
12542: // <![CDATA[
12543:
1.160.6.40 raeburn 12544: function toggleDisplay(domForm,caller) {
12545: if (document.getElementById(caller)) {
12546: var divitem = document.getElementById(caller);
12547: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 12548: var checkval = 1;
12549: var dispval = 'block';
1.160.6.40 raeburn 12550: if (caller == 'emailoptions') {
12551: optionsElement = domForm.cancreate_email;
12552: }
1.160.6.57 raeburn 12553: if (caller == 'studentsubmission') {
12554: optionsElement = domForm.postsubmit;
12555: }
1.160.6.64 raeburn 12556: if (caller == 'cloneinstcode') {
12557: optionsElement = domForm.canclone;
12558: checkval = 'instcode';
12559: }
1.160.6.40 raeburn 12560: if (optionsElement.length) {
1.160.6.16 raeburn 12561: var currval;
1.160.6.40 raeburn 12562: for (var i=0; i<optionsElement.length; i++) {
12563: if (optionsElement[i].checked) {
12564: currval = optionsElement[i].value;
1.160.6.16 raeburn 12565: }
12566: }
1.160.6.64 raeburn 12567: if (currval == checkval) {
12568: divitem.style.display = dispval;
1.160.6.16 raeburn 12569: } else {
1.160.6.40 raeburn 12570: divitem.style.display = 'none';
1.160.6.16 raeburn 12571: }
12572: }
12573: }
12574: return;
12575: }
12576:
12577: // ]]>
12578: </script>
12579:
12580: END
12581:
12582: }
12583:
1.160.6.5 raeburn 12584: sub captcha_phrases {
12585: return &Apache::lonlocal::texthash (
12586: priv => 'Private key',
12587: pub => 'Public key',
12588: original => 'original (CAPTCHA)',
12589: recaptcha => 'successor (ReCAPTCHA)',
12590: notused => 'unused',
1.160.6.69 raeburn 12591: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 12592: );
12593: }
12594:
1.160.6.24 raeburn 12595: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 12596: my ($dom,$cachekeys) = @_;
12597: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 12598: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12599: my %thismachine;
12600: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 12601: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 12602: if (keys(%servers)) {
1.160.6.24 raeburn 12603: foreach my $server (keys(%servers)) {
12604: next if ($thismachine{$server});
1.160.6.27 raeburn 12605: my @cached;
12606: foreach my $name (@posscached) {
12607: if ($cachekeys->{$name}) {
12608: push(@cached,&escape($name).':'.&escape($dom));
12609: }
12610: }
12611: if (@cached) {
12612: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12613: }
1.160.6.24 raeburn 12614: }
12615: }
12616: return;
12617: }
12618:
1.3 raeburn 12619: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>