Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.74
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.74! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.73 2016/10/24 04:01:16 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();
4022: foreach my $sparetype (@sparestypes) {
4023: my $targettable;
4024: for (my $i=0; $i<$numspares; $i++) {
4025: my $checked;
4026: if (ref($currtargets{$lonhost}) eq 'HASH') {
4027: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4028: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4029: $checked = ' checked="checked"';
4030: }
4031: }
4032: }
4033: my ($chkboxval,$disabled);
4034: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4035: $chkboxval = $spares[$i];
4036: }
4037: if (exists($currbalancer{$spares[$i]})) {
4038: $disabled = ' disabled="disabled"';
4039: }
4040: $targettable .=
1.160.6.55 raeburn 4041: '<td><span class="LC_nobreak"><label>'.
4042: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4043: $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 4044: '</span></label></span></td>';
1.160.6.7 raeburn 4045: my $rem = $i%($numinrow);
4046: if ($rem == 0) {
4047: if (($i > 0) && ($i < $numspares-1)) {
4048: $targettable .= '</tr>';
4049: }
4050: if ($i < $numspares-1) {
4051: $targettable .= '<tr>';
1.150 raeburn 4052: }
4053: }
4054: }
1.160.6.7 raeburn 4055: if ($targettable ne '') {
4056: my $rem = $numspares%($numinrow);
4057: my $colsleft = $numinrow - $rem;
4058: if ($colsleft > 1 ) {
4059: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4060: ' </td>';
4061: } elsif ($colsleft == 1) {
4062: $targettable .= '<td class="LC_left_item"> </td>';
4063: }
4064: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4065: '<table><tr>'.$targettable.'</tr></table><br />';
4066: }
4067: }
4068: $datatable .= '</div></td></tr>'.
4069: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4070: $othertitle,$usertypes,$types,\%servers,
4071: \%currbalancer,$lonhost,
4072: $targets_div_style,$homedom_div_style,
4073: $css_class[$cssidx],$balnum,$islast);
4074: $$rowtotal += $rownum;
4075: $balnum ++;
4076: }
4077: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4078: return $datatable;
4079: }
4080:
4081: sub get_loadbalancers_config {
4082: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4083: return unless ((ref($servers) eq 'HASH') &&
4084: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4085: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4086: if (keys(%{$existing}) > 0) {
4087: my $oldlonhost;
4088: foreach my $key (sort(keys(%{$existing}))) {
4089: if ($key eq 'lonhost') {
4090: $oldlonhost = $existing->{'lonhost'};
4091: $currbalancer->{$oldlonhost} = 1;
4092: } elsif ($key eq 'targets') {
4093: if ($oldlonhost) {
4094: $currtargets->{$oldlonhost} = $existing->{'targets'};
4095: }
4096: } elsif ($key eq 'rules') {
4097: if ($oldlonhost) {
4098: $currrules->{$oldlonhost} = $existing->{'rules'};
4099: }
4100: } elsif (ref($existing->{$key}) eq 'HASH') {
4101: $currbalancer->{$key} = 1;
4102: $currtargets->{$key} = $existing->{$key}{'targets'};
4103: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4104: }
4105: }
1.160.6.7 raeburn 4106: } else {
4107: my ($balancerref,$targetsref) =
4108: &Apache::lonnet::get_lonbalancer_config($servers);
4109: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4110: foreach my $server (sort(keys(%{$balancerref}))) {
4111: $currbalancer->{$server} = 1;
4112: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4113: }
4114: }
4115: }
1.160.6.7 raeburn 4116: return;
1.150 raeburn 4117: }
4118:
4119: sub loadbalancing_rules {
4120: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4121: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4122: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4123: my $output;
1.160.6.7 raeburn 4124: my $num = 0;
4125: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4126: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4127: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4128: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4129: $num ++;
1.150 raeburn 4130: my $current;
4131: if (ref($currrules) eq 'HASH') {
4132: $current = $currrules->{$type};
4133: }
1.160.6.55 raeburn 4134: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4135: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4136: $current = '';
4137: }
4138: }
4139: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4140: $servers,$currbalancer,$lonhost,$dom,
4141: $targets_div_style,$homedom_div_style,
4142: $css_class,$balnum,$num,$islast);
1.150 raeburn 4143: }
4144: }
4145: return $output;
4146: }
4147:
4148: sub loadbalancing_titles {
4149: my ($dom,$intdom,$usertypes,$types) = @_;
4150: my %othertypes = (
4151: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4152: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4153: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4154: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4155: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4156: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4157: );
1.160.6.26 raeburn 4158: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4159: if (ref($types) eq 'ARRAY') {
4160: unshift(@alltypes,@{$types},'default');
4161: }
4162: my %titles;
4163: foreach my $type (@alltypes) {
4164: if ($type =~ /^_LC_/) {
4165: $titles{$type} = $othertypes{$type};
4166: } elsif ($type eq 'default') {
4167: $titles{$type} = &mt('All users from [_1]',$dom);
4168: if (ref($types) eq 'ARRAY') {
4169: if (@{$types} > 0) {
4170: $titles{$type} = &mt('Other users from [_1]',$dom);
4171: }
4172: }
4173: } elsif (ref($usertypes) eq 'HASH') {
4174: $titles{$type} = $usertypes->{$type};
4175: }
4176: }
4177: return (\@alltypes,\%othertypes,\%titles);
4178: }
4179:
4180: sub loadbalance_rule_row {
1.160.6.7 raeburn 4181: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4182: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4183: my @rulenames;
1.150 raeburn 4184: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4185: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4186: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4187: } else {
1.160.6.26 raeburn 4188: @rulenames = ('default','homeserver');
4189: if ($type eq '_LC_external') {
4190: push(@rulenames,'externalbalancer');
4191: } else {
4192: push(@rulenames,'specific');
4193: }
4194: push(@rulenames,'none');
1.150 raeburn 4195: }
4196: my $style = $targets_div_style;
1.160.6.55 raeburn 4197: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4198: $style = $homedom_div_style;
4199: }
1.160.6.7 raeburn 4200: my $space;
4201: if ($islast && $num == 1) {
4202: $space = '<div display="inline-block"> </div>';
4203: }
4204: my $output =
4205: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4206: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4207: '<td valaign="top">'.$space.
4208: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4209: for (my $i=0; $i<@rulenames; $i++) {
4210: my $rule = $rulenames[$i];
4211: my ($checked,$extra);
4212: if ($rulenames[$i] eq 'default') {
4213: $rule = '';
4214: }
4215: if ($rulenames[$i] eq 'specific') {
4216: if (ref($servers) eq 'HASH') {
4217: my $default;
4218: if (($current ne '') && (exists($servers->{$current}))) {
4219: $checked = ' checked="checked"';
4220: }
4221: unless ($checked) {
4222: $default = ' selected="selected"';
4223: }
1.160.6.7 raeburn 4224: $extra =
4225: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4226: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4227: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4228: '<option value=""'.$default.'></option>'."\n";
4229: foreach my $server (sort(keys(%{$servers}))) {
4230: if (ref($currbalancer) eq 'HASH') {
4231: next if (exists($currbalancer->{$server}));
4232: }
1.150 raeburn 4233: my $selected;
1.160.6.7 raeburn 4234: if ($server eq $current) {
1.150 raeburn 4235: $selected = ' selected="selected"';
4236: }
1.160.6.7 raeburn 4237: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4238: }
4239: $extra .= '</select>';
4240: }
4241: } elsif ($rule eq $current) {
4242: $checked = ' checked="checked"';
4243: }
4244: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4245: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4246: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4247: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4248: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4249: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4250: $output .= $ruletitles{'particular'};
4251: } else {
4252: $output .= $ruletitles{$rulenames[$i]};
4253: }
4254: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4255: }
4256: $output .= '</div></td></tr>'."\n";
4257: return $output;
4258: }
4259:
4260: sub offloadtype_text {
4261: my %ruletitles = &Apache::lonlocal::texthash (
4262: 'default' => 'Offloads to default destinations',
4263: 'homeserver' => "Offloads to user's home server",
4264: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4265: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4266: 'none' => 'No offload',
1.160.6.26 raeburn 4267: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4268: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4269: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4270: );
4271: return %ruletitles;
4272: }
4273:
4274: sub sparestype_titles {
4275: my %typestitles = &Apache::lonlocal::texthash (
4276: 'primary' => 'primary',
4277: 'default' => 'default',
4278: );
4279: return %typestitles;
4280: }
4281:
1.28 raeburn 4282: sub contact_titles {
4283: my %titles = &Apache::lonlocal::texthash (
4284: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4285: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4286: 'errormail' => 'Error reports to be e-mailed to',
4287: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4288: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4289: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4290: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4291: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4292: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4293: );
4294: my %short_titles = &Apache::lonlocal::texthash (
4295: adminemail => 'Admin E-mail address',
4296: supportemail => 'Support E-mail',
4297: );
4298: return (\%titles,\%short_titles);
4299: }
4300:
1.72 raeburn 4301: sub tool_titles {
4302: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4303: aboutme => 'Personal web page',
1.86 raeburn 4304: blog => 'Blog',
1.160.6.4 raeburn 4305: webdav => 'WebDAV',
1.86 raeburn 4306: portfolio => 'Portfolio',
1.88 bisitz 4307: official => 'Official courses (with institutional codes)',
4308: unofficial => 'Unofficial courses',
1.98 raeburn 4309: community => 'Communities',
1.160.6.30 raeburn 4310: textbook => 'Textbook courses',
1.86 raeburn 4311: );
1.72 raeburn 4312: return %titles;
4313: }
4314:
1.101 raeburn 4315: sub courserequest_titles {
4316: my %titles = &Apache::lonlocal::texthash (
4317: official => 'Official',
4318: unofficial => 'Unofficial',
4319: community => 'Communities',
1.160.6.30 raeburn 4320: textbook => 'Textbook',
1.101 raeburn 4321: norequest => 'Not allowed',
1.104 raeburn 4322: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4323: validate => 'With validation',
4324: autolimit => 'Numerical limit',
1.103 raeburn 4325: unlimited => '(blank for unlimited)',
1.101 raeburn 4326: );
4327: return %titles;
4328: }
4329:
1.160.6.5 raeburn 4330: sub authorrequest_titles {
4331: my %titles = &Apache::lonlocal::texthash (
4332: norequest => 'Not allowed',
4333: approval => 'Approval by Dom. Coord.',
4334: automatic => 'Automatic approval',
4335: );
4336: return %titles;
4337: }
4338:
1.101 raeburn 4339: sub courserequest_conditions {
4340: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4341: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4342: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4343: );
4344: return %conditions;
4345: }
4346:
4347:
1.27 raeburn 4348: sub print_usercreation {
1.30 raeburn 4349: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4350: my $numinrow = 4;
1.28 raeburn 4351: my $datatable;
4352: if ($position eq 'top') {
1.30 raeburn 4353: $$rowtotal ++;
1.34 raeburn 4354: my $rowcount = 0;
1.32 raeburn 4355: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4356: if (ref($rules) eq 'HASH') {
4357: if (keys(%{$rules}) > 0) {
1.32 raeburn 4358: $datatable .= &user_formats_row('username',$settings,$rules,
4359: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4360: $$rowtotal ++;
1.32 raeburn 4361: $rowcount ++;
4362: }
4363: }
4364: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4365: if (ref($idrules) eq 'HASH') {
4366: if (keys(%{$idrules}) > 0) {
4367: $datatable .= &user_formats_row('id',$settings,$idrules,
4368: $idruleorder,$numinrow,$rowcount);
4369: $$rowtotal ++;
4370: $rowcount ++;
1.28 raeburn 4371: }
4372: }
1.39 raeburn 4373: if ($rowcount == 0) {
4374: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4375: $$rowtotal ++;
4376: $rowcount ++;
4377: }
1.34 raeburn 4378: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4379: my @creators = ('author','course','requestcrs');
1.37 raeburn 4380: my ($rules,$ruleorder) =
4381: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4382: my %lt = &usercreation_types();
4383: my %checked;
4384: if (ref($settings) eq 'HASH') {
4385: if (ref($settings->{'cancreate'}) eq 'HASH') {
4386: foreach my $item (@creators) {
4387: $checked{$item} = $settings->{'cancreate'}{$item};
4388: }
4389: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4390: foreach my $item (@creators) {
4391: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4392: $checked{$item} = 'none';
4393: }
4394: }
4395: }
4396: }
4397: my $rownum = 0;
4398: foreach my $item (@creators) {
4399: $rownum ++;
1.160.6.34 raeburn 4400: if ($checked{$item} eq '') {
4401: $checked{$item} = 'any';
1.34 raeburn 4402: }
4403: my $css_class;
4404: if ($rownum%2) {
4405: $css_class = '';
4406: } else {
4407: $css_class = ' class="LC_odd_row" ';
4408: }
4409: $datatable .= '<tr'.$css_class.'>'.
4410: '<td><span class="LC_nobreak">'.$lt{$item}.
4411: '</span></td><td align="right">';
1.160.6.34 raeburn 4412: my @options = ('any');
4413: if (ref($rules) eq 'HASH') {
4414: if (keys(%{$rules}) > 0) {
4415: push(@options,('official','unofficial'));
1.37 raeburn 4416: }
4417: }
1.160.6.34 raeburn 4418: push(@options,'none');
1.37 raeburn 4419: foreach my $option (@options) {
1.50 raeburn 4420: my $type = 'radio';
1.34 raeburn 4421: my $check = ' ';
1.160.6.34 raeburn 4422: if ($checked{$item} eq $option) {
4423: $check = ' checked="checked" ';
1.34 raeburn 4424: }
4425: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4426: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4427: $item.'" value="'.$option.'"'.$check.'/> '.
4428: $lt{$option}.'</label> </span>';
4429: }
4430: $datatable .= '</td></tr>';
4431: }
1.28 raeburn 4432: } else {
4433: my @contexts = ('author','course','domain');
4434: my @authtypes = ('int','krb4','krb5','loc');
4435: my %checked;
4436: if (ref($settings) eq 'HASH') {
4437: if (ref($settings->{'authtypes'}) eq 'HASH') {
4438: foreach my $item (@contexts) {
4439: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4440: foreach my $auth (@authtypes) {
4441: if ($settings->{'authtypes'}{$item}{$auth}) {
4442: $checked{$item}{$auth} = ' checked="checked" ';
4443: }
4444: }
4445: }
4446: }
1.27 raeburn 4447: }
1.35 raeburn 4448: } else {
4449: foreach my $item (@contexts) {
1.36 raeburn 4450: foreach my $auth (@authtypes) {
1.35 raeburn 4451: $checked{$item}{$auth} = ' checked="checked" ';
4452: }
4453: }
1.27 raeburn 4454: }
1.28 raeburn 4455: my %title = &context_names();
4456: my %authname = &authtype_names();
4457: my $rownum = 0;
4458: my $css_class;
4459: foreach my $item (@contexts) {
4460: if ($rownum%2) {
4461: $css_class = '';
4462: } else {
4463: $css_class = ' class="LC_odd_row" ';
4464: }
1.30 raeburn 4465: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4466: '<td>'.$title{$item}.
4467: '</td><td class="LC_left_item">'.
4468: '<span class="LC_nobreak">';
4469: foreach my $auth (@authtypes) {
4470: $datatable .= '<label>'.
4471: '<input type="checkbox" name="'.$item.'_auth" '.
4472: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4473: $authname{$auth}.'</label> ';
4474: }
4475: $datatable .= '</span></td></tr>';
4476: $rownum ++;
1.27 raeburn 4477: }
1.30 raeburn 4478: $$rowtotal += $rownum;
1.27 raeburn 4479: }
4480: return $datatable;
4481: }
4482:
1.160.6.34 raeburn 4483: sub print_selfcreation {
4484: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4485: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4486: if (ref($settings) eq 'HASH') {
4487: if (ref($settings->{'cancreate'}) eq 'HASH') {
4488: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4489: if (ref($createsettings) eq 'HASH') {
4490: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4491: @selfcreate = @{$createsettings->{'selfcreate'}};
4492: } elsif ($createsettings->{'selfcreate'} ne '') {
4493: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4494: @selfcreate = ('email','login','sso');
4495: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4496: @selfcreate = ($createsettings->{'selfcreate'});
4497: }
4498: }
4499: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4500: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4501: }
4502: }
4503: }
4504: }
4505: my %radiohash;
4506: my $numinrow = 4;
4507: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4508: if ($position eq 'top') {
4509: my %choices = &Apache::lonlocal::texthash (
4510: cancreate_login => 'Institutional Login',
4511: cancreate_sso => 'Institutional Single Sign On',
4512: );
4513: my @toggles = sort(keys(%choices));
4514: my %defaultchecked = (
4515: 'cancreate_login' => 'off',
4516: 'cancreate_sso' => 'off',
4517: );
1.160.6.35 raeburn 4518: my ($onclick,$itemcount);
1.160.6.34 raeburn 4519: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4520: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4521: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4522:
1.160.6.34 raeburn 4523: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4524:
4525: if (ref($usertypes) eq 'HASH') {
4526: if (keys(%{$usertypes}) > 0) {
4527: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4528: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4529: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4530: $$rowtotal ++;
4531: }
4532: }
1.160.6.44 raeburn 4533: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4534: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4535: $fieldtitles{'inststatus'} = &mt('Institutional status');
4536: my $rem;
4537: my $numperrow = 2;
4538: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4539: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4540: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4541: '<td class="LC_left_item">'."\n".
4542: '<table><tr><td>'."\n";
4543: for (my $i=0; $i<@fields; $i++) {
4544: $rem = $i%($numperrow);
4545: if ($rem == 0) {
4546: if ($i > 0) {
4547: $datatable .= '</tr>';
4548: }
4549: $datatable .= '<tr>';
4550: }
4551: my $currval;
1.160.6.51 raeburn 4552: if (ref($createsettings) eq 'HASH') {
4553: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4554: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4555: }
1.160.6.44 raeburn 4556: }
4557: $datatable .= '<td class="LC_left_item">'.
4558: '<span class="LC_nobreak">'.
4559: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4560: 'value="'.$currval.'" size="10" /> '.
4561: $fieldtitles{$fields[$i]}.'</span></td>';
4562: }
4563: my $colsleft = $numperrow - $rem;
4564: if ($colsleft > 1 ) {
4565: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4566: ' </td>';
4567: } elsif ($colsleft == 1) {
4568: $datatable .= '<td class="LC_left_item"> </td>';
4569: }
4570: $datatable .= '</tr></table></td></tr>';
4571: $$rowtotal ++;
1.160.6.34 raeburn 4572: } elsif ($position eq 'middle') {
4573: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4574: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4575: $usertypes->{'default'} = $othertitle;
4576: if (ref($types) eq 'ARRAY') {
4577: push(@{$types},'default');
4578: $usertypes->{'default'} = $othertitle;
4579: foreach my $status (@{$types}) {
4580: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4581: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4582: $$rowtotal ++;
1.160.6.34 raeburn 4583: }
4584: }
4585: } else {
1.160.6.40 raeburn 4586: my %choices = &Apache::lonlocal::texthash (
4587: cancreate_email => 'E-mail address as username',
4588: );
4589: my @toggles = sort(keys(%choices));
4590: my %defaultchecked = (
4591: 'cancreate_email' => 'off',
4592: );
4593: my $itemcount = 0;
4594: my $display = 'none';
4595: if (grep(/^\Qemail\E$/,@selfcreate)) {
4596: $display = 'block';
4597: }
4598: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4599: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4600: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4601: my $usertypes = {};
4602: my $order = [];
4603: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4604: $usertypes = $domdefaults{'inststatustypes'};
4605: $order = $domdefaults{'inststatusguest'};
4606: }
4607: if (ref($order) eq 'ARRAY') {
4608: push(@{$order},'default');
4609: if (@{$order} > 1) {
4610: $usertypes->{'default'} = &mt('Other users');
4611: $additional .= '<table><tr>';
4612: foreach my $status (@{$order}) {
4613: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4614: }
4615: $additional .= '</tr><tr>';
4616: foreach my $status (@{$order}) {
4617: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4618: }
1.160.6.40 raeburn 4619: $additional .= '</tr></table>';
1.160.6.34 raeburn 4620: } else {
1.160.6.40 raeburn 4621: $usertypes->{'default'} = &mt('All users');
4622: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4623: }
4624: }
1.160.6.40 raeburn 4625: $additional .= '</div>'."\n";
4626:
4627: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4628: \%choices,$$rowtotal,$onclick,$additional);
4629: $$rowtotal ++;
1.160.6.40 raeburn 4630: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4631: $$rowtotal ++;
1.160.6.35 raeburn 4632: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4633: $numinrow = 1;
1.160.6.40 raeburn 4634: if (ref($order) eq 'ARRAY') {
4635: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4636: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4637: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4638: $$rowtotal ++;
4639: }
4640: }
1.160.6.34 raeburn 4641: my ($emailrules,$emailruleorder) =
4642: &Apache::lonnet::inst_userrules($dom,'email');
4643: if (ref($emailrules) eq 'HASH') {
4644: if (keys(%{$emailrules}) > 0) {
4645: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4646: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4647: $$rowtotal ++;
4648: }
4649: }
1.160.6.35 raeburn 4650: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4651: }
4652: return $datatable;
4653: }
4654:
1.160.6.40 raeburn 4655: sub email_as_username {
4656: my ($rowtotal,$processing,$type) = @_;
4657: my %choices =
4658: &Apache::lonlocal::texthash (
4659: automatic => 'Automatic approval',
4660: approval => 'Queued for approval',
4661: );
4662: my $output;
4663: foreach my $option ('automatic','approval') {
4664: my $checked;
4665: if (ref($processing) eq 'HASH') {
4666: if ($type eq '') {
4667: if (!exists($processing->{'default'})) {
4668: if ($option eq 'automatic') {
4669: $checked = ' checked="checked"';
4670: }
4671: } else {
4672: if ($processing->{'default'} eq $option) {
4673: $checked = ' checked="checked"';
4674: }
4675: }
4676: } else {
4677: if (!exists($processing->{$type})) {
4678: if ($option eq 'automatic') {
4679: $checked = ' checked="checked"';
4680: }
4681: } else {
4682: if ($processing->{$type} eq $option) {
4683: $checked = ' checked="checked"';
4684: }
4685: }
4686: }
4687: } elsif ($option eq 'automatic') {
4688: $checked = ' checked="checked"';
4689: }
4690: my $name = 'cancreate_emailprocess';
4691: if (($type ne '') && ($type ne 'default')) {
4692: $name .= '_'.$type;
4693: }
4694: $output .= '<span class="LC_nobreak"><label>'.
4695: '<input type="radio" name="'.$name.'"'.
4696: $checked.' value="'.$option.'" />'.
4697: $choices{$option}.'</label></span>';
4698: if ($type eq '') {
4699: $output .= ' ';
4700: } else {
4701: $output .= '<br />';
4702: }
4703: }
4704: $$rowtotal ++;
4705: return $output;
4706: }
4707:
1.160.6.5 raeburn 4708: sub captcha_choice {
4709: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 4710: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4711: $vertext,$currver);
1.160.6.5 raeburn 4712: my %lt = &captcha_phrases();
4713: $keyentry = 'hidden';
4714: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4715: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4716: } elsif ($context eq 'login') {
4717: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4718: }
4719: if (ref($settings) eq 'HASH') {
4720: if ($settings->{'captcha'}) {
4721: $checked{$settings->{'captcha'}} = ' checked="checked"';
4722: } else {
4723: $checked{'original'} = ' checked="checked"';
4724: }
4725: if ($settings->{'captcha'} eq 'recaptcha') {
4726: $pubtext = $lt{'pub'};
4727: $privtext = $lt{'priv'};
4728: $keyentry = 'text';
1.160.6.69 raeburn 4729: $vertext = $lt{'ver'};
4730: $currver = $settings->{'recaptchaversion'};
4731: if ($currver ne '2') {
4732: $currver = 1;
4733: }
1.160.6.5 raeburn 4734: }
4735: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4736: $currpub = $settings->{'recaptchakeys'}{'public'};
4737: $currpriv = $settings->{'recaptchakeys'}{'private'};
4738: }
4739: } else {
4740: $checked{'original'} = ' checked="checked"';
4741: }
4742: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4743: my $output = '<tr'.$css_class.'>'.
4744: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4745: '<table><tr><td>'."\n";
4746: foreach my $option ('original','recaptcha','notused') {
4747: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4748: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4749: $lt{$option}.'</label></span>';
4750: unless ($option eq 'notused') {
4751: $output .= (' 'x2)."\n";
4752: }
4753: }
4754: #
4755: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4756: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4757: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4758: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4759: #
4760: $output .= '</td></tr>'."\n".
4761: '<tr><td>'."\n".
4762: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4763: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4764: $currpub.'" size="40" /></span><br />'."\n".
4765: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4766: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 4767: $currpriv.'" size="40" /></span><br />'.
4768: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
4769: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
4770: $currver.'" size="3" /></span><br />'.
4771: '</td></tr></table>'."\n".
1.160.6.5 raeburn 4772: '</td></tr>';
4773: return $output;
4774: }
4775:
1.32 raeburn 4776: sub user_formats_row {
4777: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4778: my $output;
4779: my %text = (
4780: 'username' => 'new usernames',
4781: 'id' => 'IDs',
1.45 raeburn 4782: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4783: );
4784: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4785: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4786: '<td><span class="LC_nobreak">';
4787: if ($type eq 'email') {
4788: $output .= &mt("Formats disallowed for $text{$type}: ");
4789: } else {
4790: $output .= &mt("Format rules to check for $text{$type}: ");
4791: }
4792: $output .= '</span></td>'.
4793: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4794: my $rem;
4795: if (ref($ruleorder) eq 'ARRAY') {
4796: for (my $i=0; $i<@{$ruleorder}; $i++) {
4797: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4798: my $rem = $i%($numinrow);
4799: if ($rem == 0) {
4800: if ($i > 0) {
4801: $output .= '</tr>';
4802: }
4803: $output .= '<tr>';
4804: }
4805: my $check = ' ';
1.39 raeburn 4806: if (ref($settings) eq 'HASH') {
4807: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4808: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4809: $check = ' checked="checked" ';
4810: }
1.27 raeburn 4811: }
4812: }
4813: $output .= '<td class="LC_left_item">'.
4814: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4815: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4816: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4817: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4818: }
4819: }
4820: $rem = @{$ruleorder}%($numinrow);
4821: }
4822: my $colsleft = $numinrow - $rem;
4823: if ($colsleft > 1 ) {
4824: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4825: ' </td>';
4826: } elsif ($colsleft == 1) {
4827: $output .= '<td class="LC_left_item"> </td>';
4828: }
4829: $output .= '</tr></table></td></tr>';
4830: return $output;
4831: }
4832:
1.34 raeburn 4833: sub usercreation_types {
4834: my %lt = &Apache::lonlocal::texthash (
4835: author => 'When adding a co-author',
4836: course => 'When adding a user to a course',
1.100 raeburn 4837: requestcrs => 'When requesting a course',
1.34 raeburn 4838: any => 'Any',
4839: official => 'Institutional only ',
4840: unofficial => 'Non-institutional only',
4841: none => 'None',
4842: );
4843: return %lt;
1.48 raeburn 4844: }
1.34 raeburn 4845:
1.160.6.34 raeburn 4846: sub selfcreation_types {
4847: my %lt = &Apache::lonlocal::texthash (
4848: selfcreate => 'User creates own account',
4849: any => 'Any',
4850: official => 'Institutional only ',
4851: unofficial => 'Non-institutional only',
4852: email => 'E-mail address',
4853: login => 'Institutional Login',
4854: sso => 'SSO',
4855: );
4856: }
4857:
1.28 raeburn 4858: sub authtype_names {
4859: my %lt = &Apache::lonlocal::texthash(
4860: int => 'Internal',
4861: krb4 => 'Kerberos 4',
4862: krb5 => 'Kerberos 5',
4863: loc => 'Local',
4864: );
4865: return %lt;
4866: }
4867:
4868: sub context_names {
4869: my %context_title = &Apache::lonlocal::texthash(
4870: author => 'Creating users when an Author',
4871: course => 'Creating users when in a course',
4872: domain => 'Creating users when a Domain Coordinator',
4873: );
4874: return %context_title;
4875: }
4876:
1.33 raeburn 4877: sub print_usermodification {
4878: my ($position,$dom,$settings,$rowtotal) = @_;
4879: my $numinrow = 4;
4880: my ($context,$datatable,$rowcount);
4881: if ($position eq 'top') {
4882: $rowcount = 0;
4883: $context = 'author';
4884: foreach my $role ('ca','aa') {
4885: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4886: $numinrow,$rowcount);
4887: $$rowtotal ++;
4888: $rowcount ++;
4889: }
1.160.6.37 raeburn 4890: } elsif ($position eq 'bottom') {
1.33 raeburn 4891: $context = 'course';
4892: $rowcount = 0;
4893: foreach my $role ('st','ep','ta','in','cr') {
4894: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4895: $numinrow,$rowcount);
4896: $$rowtotal ++;
4897: $rowcount ++;
4898: }
4899: }
4900: return $datatable;
4901: }
4902:
1.43 raeburn 4903: sub print_defaults {
1.160.6.40 raeburn 4904: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4905: my $rownum = 0;
4906: my ($datatable,$css_class);
1.160.6.40 raeburn 4907: if ($position eq 'top') {
4908: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4909: 'datelocale_def','portal_def');
4910: my %defaults;
4911: if (ref($settings) eq 'HASH') {
4912: %defaults = %{$settings};
1.43 raeburn 4913: } else {
1.160.6.40 raeburn 4914: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4915: foreach my $item (@items) {
4916: $defaults{$item} = $domdefaults{$item};
4917: }
1.43 raeburn 4918: }
1.160.6.40 raeburn 4919: my $titles = &defaults_titles($dom);
4920: foreach my $item (@items) {
4921: if ($rownum%2) {
4922: $css_class = '';
4923: } else {
4924: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4925: }
1.160.6.40 raeburn 4926: $datatable .= '<tr'.$css_class.'>'.
4927: '<td><span class="LC_nobreak">'.$titles->{$item}.
4928: '</span></td><td class="LC_right_item" colspan="3">';
4929: if ($item eq 'auth_def') {
4930: my @authtypes = ('internal','krb4','krb5','localauth');
4931: my %shortauth = (
4932: internal => 'int',
4933: krb4 => 'krb4',
4934: krb5 => 'krb5',
4935: localauth => 'loc'
4936: );
4937: my %authnames = &authtype_names();
4938: foreach my $auth (@authtypes) {
4939: my $checked = ' ';
4940: if ($defaults{$item} eq $auth) {
4941: $checked = ' checked="checked" ';
4942: }
4943: $datatable .= '<label><input type="radio" name="'.$item.
4944: '" value="'.$auth.'"'.$checked.'/>'.
4945: $authnames{$shortauth{$auth}}.'</label> ';
4946: }
4947: } elsif ($item eq 'timezone_def') {
4948: my $includeempty = 1;
4949: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4950: } elsif ($item eq 'datelocale_def') {
4951: my $includeempty = 1;
4952: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4953: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 4954: my $includeempty = 1;
4955: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 4956: } else {
4957: my $size;
4958: if ($item eq 'portal_def') {
4959: $size = ' size="25"';
4960: }
4961: $datatable .= '<input type="text" name="'.$item.'" value="'.
4962: $defaults{$item}.'"'.$size.' />';
4963: }
4964: $datatable .= '</td></tr>';
4965: $rownum ++;
4966: }
4967: } else {
4968: my (%defaults);
4969: if (ref($settings) eq 'HASH') {
4970: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4971: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4972: my $maxnum = @{$settings->{'inststatusorder'}};
4973: for (my $i=0; $i<$maxnum; $i++) {
4974: $css_class = $rownum%2?' class="LC_odd_row"':'';
4975: my $item = $settings->{'inststatusorder'}->[$i];
4976: my $title = $settings->{'inststatustypes'}->{$item};
4977: my $guestok;
4978: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4979: $guestok = 1;
4980: }
4981: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4982: $datatable .= '<tr'.$css_class.'>'.
4983: '<td><span class="LC_nobreak">'.
4984: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4985: for (my $k=0; $k<=$maxnum; $k++) {
4986: my $vpos = $k+1;
4987: my $selstr;
4988: if ($k == $i) {
4989: $selstr = ' selected="selected" ';
4990: }
4991: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4992: }
4993: my ($checkedon,$checkedoff);
4994: $checkedoff = ' checked="checked"';
4995: if ($guestok) {
4996: $checkedon = $checkedoff;
4997: $checkedoff = '';
4998: }
4999: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5000: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5001: &mt('delete').'</span></td>'.
5002: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5003: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5004: '</span></td>'.
5005: '<td class="LC_right_item"><span class="LC_nobreak">'.
5006: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5007: &mt('Yes').'</label>'.(' 'x2).
5008: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5009: &mt('No').'</label></span></td></tr>';
5010: }
5011: $css_class = $rownum%2?' class="LC_odd_row"':'';
5012: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5013: $datatable .= '<tr '.$css_class.'>'.
5014: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5015: for (my $k=0; $k<=$maxnum; $k++) {
5016: my $vpos = $k+1;
5017: my $selstr;
5018: if ($k == $maxnum) {
5019: $selstr = ' selected="selected" ';
5020: }
5021: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5022: }
5023: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5024: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5025: ' '.&mt('(new)').
5026: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5027: &mt('Name displayed:').
5028: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5029: '<td class="LC_right_item"><span class="LC_nobreak">'.
5030: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5031: &mt('Yes').'</label>'.(' 'x2).
5032: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5033: &mt('No').'</label></span></td></tr>';
5034: '</tr>'."\n";
5035: $rownum ++;
1.141 raeburn 5036: }
1.43 raeburn 5037: }
5038: }
5039: $$rowtotal += $rownum;
5040: return $datatable;
5041: }
5042:
1.160.6.5 raeburn 5043: sub get_languages_hash {
5044: my %langchoices;
5045: foreach my $id (&Apache::loncommon::languageids()) {
5046: my $code = &Apache::loncommon::supportedlanguagecode($id);
5047: if ($code ne '') {
5048: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5049: }
5050: }
5051: return %langchoices;
5052: }
5053:
1.43 raeburn 5054: sub defaults_titles {
1.141 raeburn 5055: my ($dom) = @_;
1.43 raeburn 5056: my %titles = &Apache::lonlocal::texthash (
5057: 'auth_def' => 'Default authentication type',
5058: 'auth_arg_def' => 'Default authentication argument',
5059: 'lang_def' => 'Default language',
1.54 raeburn 5060: 'timezone_def' => 'Default timezone',
1.68 raeburn 5061: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5062: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5063: );
1.141 raeburn 5064: if ($dom) {
5065: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5066: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5067: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5068: $protocol = 'http' if ($protocol ne 'https');
5069: if ($uint_dom) {
5070: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5071: $uint_dom);
5072: }
5073: }
1.43 raeburn 5074: return (\%titles);
5075: }
5076:
1.46 raeburn 5077: sub print_scantronformat {
5078: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5079: my $itemcount = 1;
1.60 raeburn 5080: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5081: %confhash);
1.46 raeburn 5082: my $switchserver = &check_switchserver($dom,$confname);
5083: my %lt = &Apache::lonlocal::texthash (
1.95 www 5084: default => 'Default bubblesheet format file error',
5085: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5086: );
5087: my %scantronfiles = (
5088: default => 'default.tab',
5089: custom => 'custom.tab',
5090: );
5091: foreach my $key (keys(%scantronfiles)) {
5092: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5093: .$scantronfiles{$key};
5094: }
5095: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5096: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5097: if (!$switchserver) {
5098: my $servadm = $r->dir_config('lonAdmEMail');
5099: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5100: if ($configuserok eq 'ok') {
5101: if ($author_ok eq 'ok') {
5102: my %legacyfile = (
5103: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5104: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5105: );
5106: my %md5chk;
5107: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5108: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5109: chomp($md5chk{$type});
1.46 raeburn 5110: }
5111: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5112: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5113: ($scantronurls{$type},my $error) =
1.46 raeburn 5114: &legacy_scantronformat($r,$dom,$confname,
5115: $type,$legacyfile{$type},
5116: $scantronurls{$type},
5117: $scantronfiles{$type});
1.60 raeburn 5118: if ($error ne '') {
5119: $error{$type} = $error;
5120: }
5121: }
5122: if (keys(%error) == 0) {
5123: $is_custom = 1;
5124: $confhash{'scantron'}{'scantronformat'} =
5125: $scantronurls{'custom'};
5126: my $putresult =
5127: &Apache::lonnet::put_dom('configuration',
5128: \%confhash,$dom);
5129: if ($putresult ne 'ok') {
5130: $error{'custom'} =
5131: '<span class="LC_error">'.
5132: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5133: }
1.46 raeburn 5134: }
5135: } else {
1.60 raeburn 5136: ($scantronurls{'default'},my $error) =
1.46 raeburn 5137: &legacy_scantronformat($r,$dom,$confname,
5138: 'default',$legacyfile{'default'},
5139: $scantronurls{'default'},
5140: $scantronfiles{'default'});
1.60 raeburn 5141: if ($error eq '') {
5142: $confhash{'scantron'}{'scantronformat'} = '';
5143: my $putresult =
5144: &Apache::lonnet::put_dom('configuration',
5145: \%confhash,$dom);
5146: if ($putresult ne 'ok') {
5147: $error{'default'} =
5148: '<span class="LC_error">'.
5149: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5150: }
5151: } else {
5152: $error{'default'} = $error;
5153: }
1.46 raeburn 5154: }
5155: }
5156: }
5157: } else {
1.95 www 5158: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5159: }
5160: }
5161: if (ref($settings) eq 'HASH') {
5162: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5163: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5164: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5165: $scantronurl = '';
5166: } else {
5167: $scantronurl = $settings->{'scantronformat'};
5168: }
5169: $is_custom = 1;
5170: } else {
5171: $scantronurl = $scantronurls{'default'};
5172: }
5173: } else {
1.60 raeburn 5174: if ($is_custom) {
5175: $scantronurl = $scantronurls{'custom'};
5176: } else {
5177: $scantronurl = $scantronurls{'default'};
5178: }
1.46 raeburn 5179: }
5180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5181: $datatable .= '<tr'.$css_class.'>';
5182: if (!$is_custom) {
1.65 raeburn 5183: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5184: '<span class="LC_nobreak">';
1.46 raeburn 5185: if ($scantronurl) {
1.160.6.21 raeburn 5186: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5187: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5188: } else {
5189: $datatable = &mt('File unavailable for display');
5190: }
1.65 raeburn 5191: $datatable .= '</span></td>';
1.60 raeburn 5192: if (keys(%error) == 0) {
5193: $datatable .= '<td valign="bottom">';
5194: if (!$switchserver) {
5195: $datatable .= &mt('Upload:').'<br />';
5196: }
5197: } else {
5198: my $errorstr;
5199: foreach my $key (sort(keys(%error))) {
5200: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5201: }
5202: $datatable .= '<td>'.$errorstr;
5203: }
1.46 raeburn 5204: } else {
5205: if (keys(%error) > 0) {
5206: my $errorstr;
5207: foreach my $key (sort(keys(%error))) {
5208: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5209: }
1.60 raeburn 5210: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5211: } elsif ($scantronurl) {
1.160.6.26 raeburn 5212: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5213: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5214: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5215: $link.
5216: '<label><input type="checkbox" name="scantronformat_del"'.
5217: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5218: '<td><span class="LC_nobreak"> '.
5219: &mt('Replace:').'</span><br />';
1.46 raeburn 5220: }
5221: }
5222: if (keys(%error) == 0) {
5223: if ($switchserver) {
5224: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5225: } else {
1.65 raeburn 5226: $datatable .='<span class="LC_nobreak"> '.
5227: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5228: }
5229: }
5230: $datatable .= '</td></tr>';
5231: $$rowtotal ++;
5232: return $datatable;
5233: }
5234:
5235: sub legacy_scantronformat {
5236: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5237: my ($url,$error);
5238: my @statinfo = &Apache::lonnet::stat_file($newurl);
5239: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5240: (my $result,$url) =
5241: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5242: '','',$newfile);
5243: if ($result ne 'ok') {
1.130 raeburn 5244: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5245: }
5246: }
5247: return ($url,$error);
5248: }
1.43 raeburn 5249:
1.49 raeburn 5250: sub print_coursecategories {
1.57 raeburn 5251: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5252: my $datatable;
5253: if ($position eq 'top') {
1.160.6.42 raeburn 5254: my (%checked);
5255: my @catitems = ('unauth','auth');
5256: my @cattypes = ('std','domonly','codesrch','none');
5257: $checked{'unauth'} = 'std';
5258: $checked{'auth'} = 'std';
5259: if (ref($settings) eq 'HASH') {
5260: foreach my $type (@cattypes) {
5261: if ($type eq $settings->{'unauth'}) {
5262: $checked{'unauth'} = $type;
5263: }
5264: if ($type eq $settings->{'auth'}) {
5265: $checked{'auth'} = $type;
5266: }
5267: }
5268: }
5269: my %lt = &Apache::lonlocal::texthash (
5270: unauth => 'Catalog type for unauthenticated users',
5271: auth => 'Catalog type for authenticated users',
5272: none => 'No catalog',
5273: std => 'Standard catalog',
5274: domonly => 'Domain-only catalog',
5275: codesrch => "Code search form",
5276: );
5277: my $itemcount = 0;
5278: foreach my $item (@catitems) {
5279: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5280: $datatable .= '<tr '.$css_class.'>'.
5281: '<td>'.$lt{$item}.'</td>'.
5282: '<td class="LC_right_item"><span class="LC_nobreak">';
5283: foreach my $type (@cattypes) {
5284: my $ischecked;
5285: if ($checked{$item} eq $type) {
5286: $ischecked=' checked="checked"';
5287: }
5288: $datatable .= '<label>'.
5289: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5290: ' />'.$lt{$type}.'</label> ';
5291: }
5292: $datatable .= '</td></tr>';
5293: $itemcount ++;
5294: }
5295: $$rowtotal += $itemcount;
5296: } elsif ($position eq 'middle') {
1.57 raeburn 5297: my $toggle_cats_crs = ' ';
5298: my $toggle_cats_dom = ' checked="checked" ';
5299: my $can_cat_crs = ' ';
5300: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5301: my $toggle_catscomm_comm = ' ';
5302: my $toggle_catscomm_dom = ' checked="checked" ';
5303: my $can_catcomm_comm = ' ';
5304: my $can_catcomm_dom = ' checked="checked" ';
5305:
1.57 raeburn 5306: if (ref($settings) eq 'HASH') {
5307: if ($settings->{'togglecats'} eq 'crs') {
5308: $toggle_cats_crs = $toggle_cats_dom;
5309: $toggle_cats_dom = ' ';
5310: }
5311: if ($settings->{'categorize'} eq 'crs') {
5312: $can_cat_crs = $can_cat_dom;
5313: $can_cat_dom = ' ';
5314: }
1.120 raeburn 5315: if ($settings->{'togglecatscomm'} eq 'comm') {
5316: $toggle_catscomm_comm = $toggle_catscomm_dom;
5317: $toggle_catscomm_dom = ' ';
5318: }
5319: if ($settings->{'categorizecomm'} eq 'comm') {
5320: $can_catcomm_comm = $can_catcomm_dom;
5321: $can_catcomm_dom = ' ';
5322: }
1.57 raeburn 5323: }
5324: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5325: togglecats => 'Show/Hide a course in catalog',
5326: togglecatscomm => 'Show/Hide a community in catalog',
5327: categorize => 'Assign a category to a course',
5328: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5329: );
5330: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5331: dom => 'Set in Domain',
5332: crs => 'Set in Course',
5333: comm => 'Set in Community',
1.57 raeburn 5334: );
5335: $datatable = '<tr class="LC_odd_row">'.
5336: '<td>'.$title{'togglecats'}.'</td>'.
5337: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5338: '<input type="radio" name="togglecats"'.
5339: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5340: '<label><input type="radio" name="togglecats"'.
5341: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5342: '</tr><tr>'.
5343: '<td>'.$title{'categorize'}.'</td>'.
5344: '<td class="LC_right_item"><span class="LC_nobreak">'.
5345: '<label><input type="radio" name="categorize"'.
5346: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5347: '<label><input type="radio" name="categorize"'.
5348: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5349: '</tr><tr class="LC_odd_row">'.
5350: '<td>'.$title{'togglecatscomm'}.'</td>'.
5351: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5352: '<input type="radio" name="togglecatscomm"'.
5353: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5354: '<label><input type="radio" name="togglecatscomm"'.
5355: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5356: '</tr><tr>'.
5357: '<td>'.$title{'categorizecomm'}.'</td>'.
5358: '<td class="LC_right_item"><span class="LC_nobreak">'.
5359: '<label><input type="radio" name="categorizecomm"'.
5360: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5361: '<label><input type="radio" name="categorizecomm"'.
5362: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5363: '</tr>';
1.120 raeburn 5364: $$rowtotal += 4;
1.57 raeburn 5365: } else {
5366: my $css_class;
5367: my $itemcount = 1;
5368: my $cathash;
5369: if (ref($settings) eq 'HASH') {
5370: $cathash = $settings->{'cats'};
5371: }
5372: if (ref($cathash) eq 'HASH') {
5373: my (@cats,@trails,%allitems,%idx,@jsarray);
5374: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5375: \%allitems,\%idx,\@jsarray);
5376: my $maxdepth = scalar(@cats);
5377: my $colattrib = '';
5378: if ($maxdepth > 2) {
5379: $colattrib = ' colspan="2" ';
5380: }
5381: my @path;
5382: if (@cats > 0) {
5383: if (ref($cats[0]) eq 'ARRAY') {
5384: my $numtop = @{$cats[0]};
5385: my $maxnum = $numtop;
1.120 raeburn 5386: my %default_names = (
5387: instcode => &mt('Official courses'),
5388: communities => &mt('Communities'),
5389: );
5390:
5391: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5392: ($cathash->{'instcode::0'} eq '') ||
5393: (!grep(/^communities$/,@{$cats[0]})) ||
5394: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5395: $maxnum ++;
5396: }
5397: my $lastidx;
5398: for (my $i=0; $i<$numtop; $i++) {
5399: my $parent = $cats[0][$i];
5400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5401: my $item = &escape($parent).'::0';
5402: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5403: $lastidx = $idx{$item};
5404: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5405: .'<select name="'.$item.'"'.$chgstr.'>';
5406: for (my $k=0; $k<=$maxnum; $k++) {
5407: my $vpos = $k+1;
5408: my $selstr;
5409: if ($k == $i) {
5410: $selstr = ' selected="selected" ';
5411: }
5412: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5413: }
1.160.6.29 raeburn 5414: $datatable .= '</select></span></td><td>';
1.120 raeburn 5415: if ($parent eq 'instcode' || $parent eq 'communities') {
5416: $datatable .= '<span class="LC_nobreak">'
5417: .$default_names{$parent}.'</span>';
5418: if ($parent eq 'instcode') {
5419: $datatable .= '<br /><span class="LC_nobreak">('
5420: .&mt('with institutional codes')
5421: .')</span></td><td'.$colattrib.'>';
5422: } else {
5423: $datatable .= '<table><tr><td>';
5424: }
5425: $datatable .= '<span class="LC_nobreak">'
5426: .'<label><input type="radio" name="'
5427: .$parent.'" value="1" checked="checked" />'
5428: .&mt('Display').'</label>';
5429: if ($parent eq 'instcode') {
5430: $datatable .= ' ';
5431: } else {
5432: $datatable .= '</span></td></tr><tr><td>'
5433: .'<span class="LC_nobreak">';
5434: }
5435: $datatable .= '<label><input type="radio" name="'
5436: .$parent.'" value="0" />'
5437: .&mt('Do not display').'</label></span>';
5438: if ($parent eq 'communities') {
5439: $datatable .= '</td></tr></table>';
5440: }
5441: $datatable .= '</td>';
1.57 raeburn 5442: } else {
5443: $datatable .= $parent
1.160.6.29 raeburn 5444: .' <span class="LC_nobreak"><label>'
5445: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5446: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5447: }
5448: my $depth = 1;
5449: push(@path,$parent);
5450: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5451: pop(@path);
5452: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5453: $itemcount ++;
5454: }
1.48 raeburn 5455: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5456: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5457: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5458: for (my $k=0; $k<=$maxnum; $k++) {
5459: my $vpos = $k+1;
5460: my $selstr;
1.57 raeburn 5461: if ($k == $numtop) {
1.48 raeburn 5462: $selstr = ' selected="selected" ';
5463: }
5464: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5465: }
1.59 bisitz 5466: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5467: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5468: .'</tr>'."\n";
1.48 raeburn 5469: $itemcount ++;
1.120 raeburn 5470: foreach my $default ('instcode','communities') {
5471: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5472: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5473: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5474: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5475: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5476: for (my $k=0; $k<=$maxnum; $k++) {
5477: my $vpos = $k+1;
5478: my $selstr;
5479: if ($k == $maxnum) {
5480: $selstr = ' selected="selected" ';
5481: }
5482: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5483: }
1.120 raeburn 5484: $datatable .= '</select></span></td>'.
5485: '<td><span class="LC_nobreak">'.
5486: $default_names{$default}.'</span>';
5487: if ($default eq 'instcode') {
5488: $datatable .= '<br /><span class="LC_nobreak">('
5489: .&mt('with institutional codes').')</span>';
5490: }
5491: $datatable .= '</td>'
5492: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5493: .&mt('Display').'</label> '
5494: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5495: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5496: }
5497: }
5498: }
1.57 raeburn 5499: } else {
5500: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5501: }
5502: } else {
1.160.6.42 raeburn 5503: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5504: .&initialize_categories($itemcount);
1.48 raeburn 5505: }
1.57 raeburn 5506: $$rowtotal += $itemcount;
1.48 raeburn 5507: }
5508: return $datatable;
5509: }
5510:
1.69 raeburn 5511: sub print_serverstatuses {
5512: my ($dom,$settings,$rowtotal) = @_;
5513: my $datatable;
5514: my @pages = &serverstatus_pages();
5515: my (%namedaccess,%machineaccess);
5516: foreach my $type (@pages) {
5517: $namedaccess{$type} = '';
5518: $machineaccess{$type}= '';
5519: }
5520: if (ref($settings) eq 'HASH') {
5521: foreach my $type (@pages) {
5522: if (exists($settings->{$type})) {
5523: if (ref($settings->{$type}) eq 'HASH') {
5524: foreach my $key (keys(%{$settings->{$type}})) {
5525: if ($key eq 'namedusers') {
5526: $namedaccess{$type} = $settings->{$type}->{$key};
5527: } elsif ($key eq 'machines') {
5528: $machineaccess{$type} = $settings->{$type}->{$key};
5529: }
5530: }
5531: }
5532: }
5533: }
5534: }
1.81 raeburn 5535: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5536: my $rownum = 0;
5537: my $css_class;
5538: foreach my $type (@pages) {
5539: $rownum ++;
5540: $css_class = $rownum%2?' class="LC_odd_row"':'';
5541: $datatable .= '<tr'.$css_class.'>'.
5542: '<td><span class="LC_nobreak">'.
5543: $titles->{$type}.'</span></td>'.
5544: '<td class="LC_left_item">'.
5545: '<input type="text" name="'.$type.'_namedusers" '.
5546: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5547: '<td class="LC_right_item">'.
5548: '<span class="LC_nobreak">'.
5549: '<input type="text" name="'.$type.'_machines" '.
5550: 'value="'.$machineaccess{$type}.'" size="10" />'.
5551: '</td></tr>'."\n";
5552: }
5553: $$rowtotal += $rownum;
5554: return $datatable;
5555: }
5556:
5557: sub serverstatus_pages {
5558: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5559: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5560: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 5561: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5562: }
5563:
1.160.6.40 raeburn 5564: sub defaults_javascript {
5565: my ($settings) = @_;
1.160.6.51 raeburn 5566: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5567: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5568: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5569: if ($maxnum eq '') {
5570: $maxnum = 0;
5571: }
5572: $maxnum ++;
1.160.6.51 raeburn 5573: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5574: return <<"ENDSCRIPT";
5575: <script type="text/javascript">
5576: // <![CDATA[
5577: function reorderTypes(form,caller) {
5578: var changedVal;
5579: $jstext
5580: var newpos = 'addinststatus_pos';
5581: var current = new Array;
5582: var maxh = $maxnum;
5583: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5584: var oldVal;
5585: if (caller == newpos) {
5586: changedVal = newitemVal;
5587: } else {
5588: var curritem = 'inststatus_pos_'+caller;
5589: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5590: current[newitemVal] = newpos;
5591: }
5592: for (var i=0; i<inststatuses.length; i++) {
5593: if (inststatuses[i] != caller) {
5594: var elementName = 'inststatus_pos_'+inststatuses[i];
5595: if (form.elements[elementName]) {
5596: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5597: current[currVal] = elementName;
5598: }
5599: }
5600: }
5601: for (var j=0; j<maxh; j++) {
5602: if (current[j] == undefined) {
5603: oldVal = j;
5604: }
5605: }
5606: if (oldVal < changedVal) {
5607: for (var k=oldVal+1; k<=changedVal ; k++) {
5608: var elementName = current[k];
5609: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5610: }
5611: } else {
5612: for (var k=changedVal; k<oldVal; k++) {
5613: var elementName = current[k];
5614: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5615: }
5616: }
5617: return;
5618: }
5619:
5620: // ]]>
5621: </script>
5622:
5623: ENDSCRIPT
5624: }
5625: }
5626:
1.49 raeburn 5627: sub coursecategories_javascript {
5628: my ($settings) = @_;
1.57 raeburn 5629: my ($output,$jstext,$cathash);
1.49 raeburn 5630: if (ref($settings) eq 'HASH') {
1.57 raeburn 5631: $cathash = $settings->{'cats'};
5632: }
5633: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5634: my (@cats,@jsarray,%idx);
1.57 raeburn 5635: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5636: if (@jsarray > 0) {
5637: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5638: for (my $i=0; $i<@jsarray; $i++) {
5639: if (ref($jsarray[$i]) eq 'ARRAY') {
5640: my $catstr = join('","',@{$jsarray[$i]});
5641: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5642: }
5643: }
5644: }
5645: } else {
5646: $jstext = ' var categories = Array(1);'."\n".
5647: ' categories[0] = Array("instcode_pos");'."\n";
5648: }
1.160.6.42 raeburn 5649: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5650: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 5651: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5652: &js_escape(\$instcode_reserved);
5653: &js_escape(\$communities_reserved);
5654: &js_escape(\$choose_again);
1.49 raeburn 5655: $output = <<"ENDSCRIPT";
5656: <script type="text/javascript">
1.109 raeburn 5657: // <![CDATA[
1.49 raeburn 5658: function reorderCats(form,parent,item,idx) {
5659: var changedVal;
5660: $jstext
5661: var newpos = 'addcategory_pos';
5662: if (parent == '') {
5663: var has_instcode = 0;
5664: var maxtop = categories[idx].length;
5665: for (var j=0; j<maxtop; j++) {
5666: if (categories[idx][j] == 'instcode::0') {
5667: has_instcode == 1;
5668: }
5669: }
5670: if (has_instcode == 0) {
5671: categories[idx][maxtop] = 'instcode_pos';
5672: }
5673: } else {
5674: newpos += '_'+parent;
5675: }
5676: var maxh = 1 + categories[idx].length;
5677: var current = new Array;
5678: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5679: if (item == newpos) {
5680: changedVal = newitemVal;
5681: } else {
5682: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5683: current[newitemVal] = newpos;
5684: }
5685: for (var i=0; i<categories[idx].length; i++) {
5686: var elementName = categories[idx][i];
5687: if (elementName != item) {
5688: if (form.elements[elementName]) {
5689: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5690: current[currVal] = elementName;
5691: }
5692: }
5693: }
5694: var oldVal;
5695: for (var j=0; j<maxh; j++) {
5696: if (current[j] == undefined) {
5697: oldVal = j;
5698: }
5699: }
5700: if (oldVal < changedVal) {
5701: for (var k=oldVal+1; k<=changedVal ; k++) {
5702: var elementName = current[k];
5703: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5704: }
5705: } else {
5706: for (var k=changedVal; k<oldVal; k++) {
5707: var elementName = current[k];
5708: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5709: }
5710: }
5711: return;
5712: }
1.120 raeburn 5713:
5714: function categoryCheck(form) {
5715: if (form.elements['addcategory_name'].value == 'instcode') {
5716: alert('$instcode_reserved\\n$choose_again');
5717: return false;
5718: }
5719: if (form.elements['addcategory_name'].value == 'communities') {
5720: alert('$communities_reserved\\n$choose_again');
5721: return false;
5722: }
5723: return true;
5724: }
5725:
1.109 raeburn 5726: // ]]>
1.49 raeburn 5727: </script>
5728:
5729: ENDSCRIPT
5730: return $output;
5731: }
5732:
1.48 raeburn 5733: sub initialize_categories {
5734: my ($itemcount) = @_;
1.120 raeburn 5735: my ($datatable,$css_class,$chgstr);
5736: my %default_names = (
5737: instcode => 'Official courses (with institutional codes)',
5738: communities => 'Communities',
5739: );
5740: my $select0 = ' selected="selected"';
5741: my $select1 = '';
5742: foreach my $default ('instcode','communities') {
5743: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5744: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5745: if ($default eq 'communities') {
5746: $select1 = $select0;
5747: $select0 = '';
5748: }
5749: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5750: .'<select name="'.$default.'_pos">'
5751: .'<option value="0"'.$select0.'>1</option>'
5752: .'<option value="1"'.$select1.'>2</option>'
5753: .'<option value="2">3</option></select> '
5754: .$default_names{$default}
5755: .'</span></td><td><span class="LC_nobreak">'
5756: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5757: .&mt('Display').'</label> <label>'
5758: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5759: .'</label></span></td></tr>';
1.120 raeburn 5760: $itemcount ++;
5761: }
1.48 raeburn 5762: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5763: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5764: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5765: .'<select name="addcategory_pos"'.$chgstr.'>'
5766: .'<option value="0">1</option>'
5767: .'<option value="1">2</option>'
5768: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5769: .&mt('Add category').'</td><td>'.&mt('Name:')
5770: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5771: return $datatable;
5772: }
5773:
5774: sub build_category_rows {
1.49 raeburn 5775: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5776: my ($text,$name,$item,$chgstr);
1.48 raeburn 5777: if (ref($cats) eq 'ARRAY') {
5778: my $maxdepth = scalar(@{$cats});
5779: if (ref($cats->[$depth]) eq 'HASH') {
5780: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5781: my $numchildren = @{$cats->[$depth]{$parent}};
5782: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5783: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5784: my ($idxnum,$parent_name,$parent_item);
5785: my $higher = $depth - 1;
5786: if ($higher == 0) {
5787: $parent_name = &escape($parent).'::'.$higher;
5788: } else {
5789: if (ref($path) eq 'ARRAY') {
5790: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5791: }
5792: }
5793: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5794: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5795: if ($j < $numchildren) {
1.48 raeburn 5796: $name = $cats->[$depth]{$parent}[$j];
5797: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5798: $idxnum = $idx->{$item};
5799: } else {
5800: $name = $parent_name;
5801: $item = $parent_item;
1.48 raeburn 5802: }
1.49 raeburn 5803: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5804: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5805: for (my $i=0; $i<=$numchildren; $i++) {
5806: my $vpos = $i+1;
5807: my $selstr;
5808: if ($j == $i) {
5809: $selstr = ' selected="selected" ';
5810: }
5811: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5812: }
5813: $text .= '</select> ';
5814: if ($j < $numchildren) {
5815: my $deeper = $depth+1;
5816: $text .= $name.' '
5817: .'<label><input type="checkbox" name="deletecategory" value="'
5818: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5819: if(ref($path) eq 'ARRAY') {
5820: push(@{$path},$name);
1.49 raeburn 5821: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5822: pop(@{$path});
5823: }
5824: } else {
1.59 bisitz 5825: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5826: if ($j == $numchildren) {
5827: $text .= $name;
5828: } else {
5829: $text .= $item;
5830: }
5831: $text .= '" value="" />';
5832: }
5833: $text .= '</td></tr>';
5834: }
5835: $text .= '</table></td>';
5836: } else {
5837: my $higher = $depth-1;
5838: if ($higher == 0) {
5839: $name = &escape($parent).'::'.$higher;
5840: } else {
5841: if (ref($path) eq 'ARRAY') {
5842: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5843: }
5844: }
5845: my $colspan;
5846: if ($parent ne 'instcode') {
5847: $colspan = $maxdepth - $depth - 1;
5848: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5849: }
5850: }
5851: }
5852: }
5853: return $text;
5854: }
5855:
1.33 raeburn 5856: sub modifiable_userdata_row {
1.160.6.35 raeburn 5857: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5858: my ($role,$rolename,$statustype);
5859: $role = $item;
1.160.6.34 raeburn 5860: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5861: if ($item =~ /^emailusername_(.+)$/) {
5862: $statustype = $1;
5863: $role = 'emailusername';
5864: if (ref($usertypes) eq 'HASH') {
5865: if ($usertypes->{$statustype}) {
5866: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5867: } else {
5868: $rolename = &mt('Data provided by user');
5869: }
5870: }
1.160.6.34 raeburn 5871: }
5872: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5873: if (ref($usertypes) eq 'HASH') {
5874: $rolename = $usertypes->{$role};
5875: } else {
5876: $rolename = $role;
5877: }
1.33 raeburn 5878: } else {
1.63 raeburn 5879: if ($role eq 'cr') {
5880: $rolename = &mt('Custom role');
5881: } else {
5882: $rolename = &Apache::lonnet::plaintext($role);
5883: }
1.33 raeburn 5884: }
1.160.6.34 raeburn 5885: my (@fields,%fieldtitles);
5886: if (ref($fieldsref) eq 'ARRAY') {
5887: @fields = @{$fieldsref};
5888: } else {
5889: @fields = ('lastname','firstname','middlename','generation',
5890: 'permanentemail','id');
5891: }
5892: if ((ref($titlesref) eq 'HASH')) {
5893: %fieldtitles = %{$titlesref};
5894: } else {
5895: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5896: }
1.33 raeburn 5897: my $output;
5898: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5899: $output = '<tr '.$css_class.'>'.
5900: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5901: '<td class="LC_left_item" colspan="2"><table>';
5902: my $rem;
5903: my %checks;
5904: if (ref($settings) eq 'HASH') {
5905: if (ref($settings->{$context}) eq 'HASH') {
5906: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5907: my $hashref = $settings->{$context}->{$role};
5908: if ($role eq 'emailusername') {
5909: if ($statustype) {
5910: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5911: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5912: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5913: foreach my $field (@fields) {
5914: if ($hashref->{$field}) {
5915: $checks{$field} = $hashref->{$field};
5916: }
5917: }
5918: }
5919: }
5920: }
5921: } else {
5922: if (ref($hashref) eq 'HASH') {
5923: foreach my $field (@fields) {
5924: if ($hashref->{$field}) {
5925: $checks{$field} = ' checked="checked" ';
5926: }
5927: }
1.33 raeburn 5928: }
5929: }
5930: }
5931: }
5932: }
1.160.6.39 raeburn 5933:
1.33 raeburn 5934: for (my $i=0; $i<@fields; $i++) {
5935: my $rem = $i%($numinrow);
5936: if ($rem == 0) {
5937: if ($i > 0) {
5938: $output .= '</tr>';
5939: }
5940: $output .= '<tr>';
5941: }
5942: my $check = ' ';
1.160.6.35 raeburn 5943: unless ($role eq 'emailusername') {
5944: if (exists($checks{$fields[$i]})) {
5945: $check = $checks{$fields[$i]}
5946: } else {
5947: if ($role eq 'st') {
5948: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5949: $check = ' checked="checked" ';
1.160.6.35 raeburn 5950: }
1.33 raeburn 5951: }
5952: }
5953: }
5954: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5955: '<span class="LC_nobreak">';
5956: if ($role eq 'emailusername') {
5957: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5958: $checks{$fields[$i]} = 'omit';
5959: }
5960: foreach my $option ('required','optional','omit') {
5961: my $checked='';
5962: if ($checks{$fields[$i]} eq $option) {
5963: $checked='checked="checked" ';
5964: }
5965: $output .= '<label>'.
5966: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5967: &mt($option).'</label>'.(' ' x2);
5968: }
5969: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5970: } else {
5971: $output .= '<label>'.
5972: '<input type="checkbox" name="canmodify_'.$role.'" '.
5973: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5974: '</label>';
5975: }
5976: $output .= '</span></td>';
1.33 raeburn 5977: $rem = @fields%($numinrow);
5978: }
5979: my $colsleft = $numinrow - $rem;
5980: if ($colsleft > 1 ) {
5981: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5982: ' </td>';
5983: } elsif ($colsleft == 1) {
5984: $output .= '<td class="LC_left_item"> </td>';
5985: }
5986: $output .= '</tr></table></td></tr>';
5987: return $output;
5988: }
1.28 raeburn 5989:
1.93 raeburn 5990: sub insttypes_row {
1.160.6.34 raeburn 5991: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5992: my %lt = &Apache::lonlocal::texthash (
5993: cansearch => 'Users allowed to search',
5994: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5995: lockablenames => 'User preference to lock name',
1.93 raeburn 5996: );
5997: my $showdom;
5998: if ($context eq 'cansearch') {
5999: $showdom = ' ('.$dom.')';
6000: }
1.160.6.5 raeburn 6001: my $class = 'LC_left_item';
6002: if ($context eq 'statustocreate') {
6003: $class = 'LC_right_item';
6004: }
1.160.6.34 raeburn 6005: my $css_class = ' class="LC_odd_row"';
6006: if ($rownum ne '') {
6007: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6008: }
6009: my $output = '<tr'.$css_class.'>'.
6010: '<td>'.$lt{$context}.$showdom.
6011: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6012: my $rem;
6013: if (ref($types) eq 'ARRAY') {
6014: for (my $i=0; $i<@{$types}; $i++) {
6015: if (defined($usertypes->{$types->[$i]})) {
6016: my $rem = $i%($numinrow);
6017: if ($rem == 0) {
6018: if ($i > 0) {
6019: $output .= '</tr>';
6020: }
6021: $output .= '<tr>';
1.23 raeburn 6022: }
1.26 raeburn 6023: my $check = ' ';
1.99 raeburn 6024: if (ref($settings) eq 'HASH') {
6025: if (ref($settings->{$context}) eq 'ARRAY') {
6026: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6027: $check = ' checked="checked" ';
6028: }
6029: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6030: $check = ' checked="checked" ';
6031: }
1.23 raeburn 6032: }
1.26 raeburn 6033: $output .= '<td class="LC_left_item">'.
6034: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6035: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6036: 'value="'.$types->[$i].'"'.$check.'/>'.
6037: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6038: }
6039: }
1.26 raeburn 6040: $rem = @{$types}%($numinrow);
1.23 raeburn 6041: }
6042: my $colsleft = $numinrow - $rem;
1.131 raeburn 6043: if (($rem == 0) && (@{$types} > 0)) {
6044: $output .= '<tr>';
6045: }
1.23 raeburn 6046: if ($colsleft > 1) {
1.25 raeburn 6047: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6048: } else {
1.25 raeburn 6049: $output .= '<td class="LC_left_item">';
1.23 raeburn 6050: }
6051: my $defcheck = ' ';
1.99 raeburn 6052: if (ref($settings) eq 'HASH') {
6053: if (ref($settings->{$context}) eq 'ARRAY') {
6054: if (grep(/^default$/,@{$settings->{$context}})) {
6055: $defcheck = ' checked="checked" ';
6056: }
6057: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6058: $defcheck = ' checked="checked" ';
6059: }
1.23 raeburn 6060: }
1.25 raeburn 6061: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6062: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6063: 'value="default"'.$defcheck.'/>'.
6064: $othertitle.'</label></span></td>'.
6065: '</tr></table></td></tr>';
6066: return $output;
1.23 raeburn 6067: }
6068:
6069: sub sorted_searchtitles {
6070: my %searchtitles = &Apache::lonlocal::texthash(
6071: 'uname' => 'username',
6072: 'lastname' => 'last name',
6073: 'lastfirst' => 'last name, first name',
6074: );
6075: my @titleorder = ('uname','lastname','lastfirst');
6076: return (\%searchtitles,\@titleorder);
6077: }
6078:
1.25 raeburn 6079: sub sorted_searchtypes {
6080: my %srchtypes_desc = (
6081: exact => 'is exact match',
6082: contains => 'contains ..',
6083: begins => 'begins with ..',
6084: );
6085: my @srchtypeorder = ('exact','begins','contains');
6086: return (\%srchtypes_desc,\@srchtypeorder);
6087: }
6088:
1.3 raeburn 6089: sub usertype_update_row {
6090: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6091: my $datatable;
6092: my $numinrow = 4;
6093: foreach my $type (@{$types}) {
6094: if (defined($usertypes->{$type})) {
6095: $$rownums ++;
6096: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6097: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6098: '</td><td class="LC_left_item"><table>';
6099: for (my $i=0; $i<@{$fields}; $i++) {
6100: my $rem = $i%($numinrow);
6101: if ($rem == 0) {
6102: if ($i > 0) {
6103: $datatable .= '</tr>';
6104: }
6105: $datatable .= '<tr>';
6106: }
6107: my $check = ' ';
1.39 raeburn 6108: if (ref($settings) eq 'HASH') {
6109: if (ref($settings->{'fields'}) eq 'HASH') {
6110: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6111: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6112: $check = ' checked="checked" ';
6113: }
1.3 raeburn 6114: }
6115: }
6116: }
6117:
6118: if ($i == @{$fields}-1) {
6119: my $colsleft = $numinrow - $rem;
6120: if ($colsleft > 1) {
6121: $datatable .= '<td colspan="'.$colsleft.'">';
6122: } else {
6123: $datatable .= '<td>';
6124: }
6125: } else {
6126: $datatable .= '<td>';
6127: }
1.8 raeburn 6128: $datatable .= '<span class="LC_nobreak"><label>'.
6129: '<input type="checkbox" name="updateable_'.$type.
6130: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6131: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6132: }
6133: $datatable .= '</tr></table></td></tr>';
6134: }
6135: }
6136: return $datatable;
1.1 raeburn 6137: }
6138:
6139: sub modify_login {
1.160.6.24 raeburn 6140: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6141: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6142: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6143: %title = ( coursecatalog => 'Display course catalog',
6144: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6145: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6146: newuser => 'Link for visitors to create a user account',
6147: loginheader => 'Log-in box header');
6148: @offon = ('off','on');
1.112 raeburn 6149: if (ref($domconfig{login}) eq 'HASH') {
6150: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6151: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6152: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6153: }
6154: }
6155: }
1.9 raeburn 6156: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6157: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6158: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6159: foreach my $item (@toggles) {
6160: $loginhash{login}{$item} = $env{'form.'.$item};
6161: }
1.41 raeburn 6162: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6163: if (ref($colchanges{'login'}) eq 'HASH') {
6164: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6165: \%loginhash);
6166: }
1.110 raeburn 6167:
1.149 raeburn 6168: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6169: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6170: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6171: if (keys(%servers) > 1) {
6172: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6173: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6174: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6175: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6176: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6177: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6178: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6179: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6180: $changes{'loginvia'}{$lonhost} = 1;
6181: } else {
6182: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6183: $changes{'loginvia'}{$lonhost} = 1;
6184: }
6185: } else {
6186: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6187: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6188: $changes{'loginvia'}{$lonhost} = 1;
6189: }
6190: }
6191: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6192: foreach my $item (@loginvia_attribs) {
6193: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6194: }
6195: } else {
6196: foreach my $item (@loginvia_attribs) {
6197: my $new = $env{'form.'.$lonhost.'_'.$item};
6198: if (($item eq 'serverpath') && ($new eq 'custom')) {
6199: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6200: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6201: $new = '/';
6202: }
6203: }
6204: if (($item eq 'custompath') &&
6205: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6206: $new = '';
6207: }
6208: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6209: $changes{'loginvia'}{$lonhost} = 1;
6210: }
6211: if ($item eq 'exempt') {
1.160.6.56 raeburn 6212: $new = &check_exempt_addresses($new);
1.128 raeburn 6213: }
6214: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6215: }
6216: }
1.112 raeburn 6217: } else {
1.128 raeburn 6218: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6219: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6220: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6221: foreach my $item (@loginvia_attribs) {
6222: my $new = $env{'form.'.$lonhost.'_'.$item};
6223: if (($item eq 'serverpath') && ($new eq 'custom')) {
6224: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6225: $new = '/';
6226: }
6227: }
6228: if (($item eq 'custompath') &&
6229: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6230: $new = '';
6231: }
6232: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6233: }
1.110 raeburn 6234: }
6235: }
6236: }
6237: }
1.119 raeburn 6238:
1.160.6.5 raeburn 6239: my $servadm = $r->dir_config('lonAdmEMail');
6240: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6241: if (ref($domconfig{'login'}) eq 'HASH') {
6242: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6243: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6244: if ($lang eq 'nolang') {
6245: push(@currlangs,$lang);
6246: } elsif (defined($langchoices{$lang})) {
6247: push(@currlangs,$lang);
6248: } else {
6249: next;
6250: }
6251: }
6252: }
6253: }
6254: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6255: if (@currlangs > 0) {
6256: foreach my $lang (@currlangs) {
6257: if (grep(/^\Q$lang\E$/,@delurls)) {
6258: $changes{'helpurl'}{$lang} = 1;
6259: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6260: $changes{'helpurl'}{$lang} = 1;
6261: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6262: push(@newlangs,$lang);
6263: } else {
6264: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6265: }
6266: }
6267: }
6268: unless (grep(/^nolang$/,@currlangs)) {
6269: if ($env{'form.loginhelpurl_nolang.filename'}) {
6270: $changes{'helpurl'}{'nolang'} = 1;
6271: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6272: push(@newlangs,'nolang');
6273: }
6274: }
6275: if ($env{'form.loginhelpurl_add_lang'}) {
6276: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6277: ($env{'form.loginhelpurl_add_file.filename'})) {
6278: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6279: $addedfile = $env{'form.loginhelpurl_add_lang'};
6280: }
6281: }
6282: if ((@newlangs > 0) || ($addedfile)) {
6283: my $error;
6284: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6285: if ($configuserok eq 'ok') {
6286: if ($switchserver) {
6287: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6288: } elsif ($author_ok eq 'ok') {
6289: my @allnew = @newlangs;
6290: if ($addedfile ne '') {
6291: push(@allnew,$addedfile);
6292: }
6293: foreach my $lang (@allnew) {
6294: my $formelem = 'loginhelpurl_'.$lang;
6295: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6296: $formelem = 'loginhelpurl_add_file';
6297: }
6298: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6299: "help/$lang",'','',$newfile{$lang});
6300: if ($result eq 'ok') {
6301: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6302: $changes{'helpurl'}{$lang} = 1;
6303: } else {
6304: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6305: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6306: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6307: (!grep(/^\Q$lang\E$/,@delurls))) {
6308:
6309: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6310: }
6311: }
6312: }
6313: } else {
6314: $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);
6315: }
6316: } else {
6317: $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);
6318: }
6319: if ($error) {
6320: &Apache::lonnet::logthis($error);
6321: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6322: }
6323: }
1.160.6.56 raeburn 6324:
6325: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6326: if (ref($domconfig{'login'}) eq 'HASH') {
6327: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6328: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6329: if ($domservers{$lonhost}) {
6330: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6331: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6332: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6333: }
6334: }
6335: }
6336: }
6337: }
6338: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6339: foreach my $lonhost (sort(keys(%domservers))) {
6340: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6341: $changes{'headtag'}{$lonhost} = 1;
6342: } else {
6343: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6344: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6345: }
6346: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6347: push(@newhosts,$lonhost);
6348: } elsif ($currheadtagurls{$lonhost}) {
6349: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6350: if ($currexempt{$lonhost}) {
6351: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6352: $changes{'headtag'}{$lonhost} = 1;
6353: }
6354: } elsif ($possexempt{$lonhost}) {
6355: $changes{'headtag'}{$lonhost} = 1;
6356: }
6357: if ($possexempt{$lonhost}) {
6358: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6359: }
6360: }
6361: }
6362: }
6363: if (@newhosts) {
6364: my $error;
6365: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6366: if ($configuserok eq 'ok') {
6367: if ($switchserver) {
6368: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6369: } elsif ($author_ok eq 'ok') {
6370: foreach my $lonhost (@newhosts) {
6371: my $formelem = 'loginheadtag_'.$lonhost;
6372: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6373: "login/headtag/$lonhost",'','',
6374: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6375: if ($result eq 'ok') {
6376: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6377: $changes{'headtag'}{$lonhost} = 1;
6378: if ($possexempt{$lonhost}) {
6379: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6380: }
6381: } else {
6382: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6383: $newheadtagurls{$lonhost},$result);
6384: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6385: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6386: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6387: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6388: }
6389: }
6390: }
6391: } else {
6392: $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);
6393: }
6394: } else {
6395: $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);
6396: }
6397: if ($error) {
6398: &Apache::lonnet::logthis($error);
6399: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6400: }
6401: }
6402:
1.160.6.5 raeburn 6403: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6404:
6405: my $defaulthelpfile = '/adm/loginproblems.html';
6406: my $defaulttext = &mt('Default in use');
6407:
1.1 raeburn 6408: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6409: $dom);
6410: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6411: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6412: my %defaultchecked = (
6413: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6414: 'helpdesk' => 'on',
1.42 raeburn 6415: 'adminmail' => 'off',
1.43 raeburn 6416: 'newuser' => 'off',
1.42 raeburn 6417: );
1.55 raeburn 6418: if (ref($domconfig{'login'}) eq 'HASH') {
6419: foreach my $item (@toggles) {
6420: if ($defaultchecked{$item} eq 'on') {
6421: if (($domconfig{'login'}{$item} eq '0') &&
6422: ($env{'form.'.$item} eq '1')) {
6423: $changes{$item} = 1;
6424: } elsif (($domconfig{'login'}{$item} eq '' ||
6425: $domconfig{'login'}{$item} eq '1') &&
6426: ($env{'form.'.$item} eq '0')) {
6427: $changes{$item} = 1;
6428: }
6429: } elsif ($defaultchecked{$item} eq 'off') {
6430: if (($domconfig{'login'}{$item} eq '1') &&
6431: ($env{'form.'.$item} eq '0')) {
6432: $changes{$item} = 1;
6433: } elsif (($domconfig{'login'}{$item} eq '' ||
6434: $domconfig{'login'}{$item} eq '0') &&
6435: ($env{'form.'.$item} eq '1')) {
6436: $changes{$item} = 1;
6437: }
1.42 raeburn 6438: }
6439: }
1.41 raeburn 6440: }
1.6 raeburn 6441: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6442: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6443: if (ref($lastactref) eq 'HASH') {
6444: $lastactref->{'domainconfig'} = 1;
6445: }
1.1 raeburn 6446: $resulttext = &mt('Changes made:').'<ul>';
6447: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6448: if ($item eq 'loginvia') {
1.112 raeburn 6449: if (ref($changes{$item}) eq 'HASH') {
6450: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6451: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6452: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6453: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6454: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6455: $protocol = 'http' if ($protocol ne 'https');
6456: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6457:
6458: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6459: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6460: } else {
6461: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6462: }
6463: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6464: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6465: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6466: }
6467: $resulttext .= '</li>';
6468: } else {
6469: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6470: }
1.112 raeburn 6471: } else {
1.128 raeburn 6472: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6473: }
6474: }
1.128 raeburn 6475: $resulttext .= '</ul></li>';
1.112 raeburn 6476: }
1.160.6.5 raeburn 6477: } elsif ($item eq 'helpurl') {
6478: if (ref($changes{$item}) eq 'HASH') {
6479: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6480: if (grep(/^\Q$lang\E$/,@delurls)) {
6481: my ($chg,$link);
6482: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6483: if ($lang eq 'nolang') {
6484: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6485: } else {
6486: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6487: }
6488: $resulttext .= '<li>'.$chg.'</li>';
6489: } else {
6490: my $chg;
6491: if ($lang eq 'nolang') {
6492: $chg = &mt('custom log-in help file for no preferred language');
6493: } else {
6494: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6495: }
6496: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6497: $loginhash{'login'}{'helpurl'}{$lang}.
6498: '?inhibitmenu=yes',$chg,600,500).
6499: '</li>';
6500: }
6501: }
6502: }
1.160.6.56 raeburn 6503: } elsif ($item eq 'headtag') {
6504: if (ref($changes{$item}) eq 'HASH') {
6505: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6506: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6507: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6508: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6509: $resulttext .= '<li><a href="'.
6510: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6511: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6512: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6513: if ($possexempt{$lonhost}) {
6514: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6515: } else {
6516: $resulttext .= &mt('included for any client IP');
6517: }
6518: $resulttext .= '</li>';
6519: }
6520: }
6521: }
1.160.6.5 raeburn 6522: } elsif ($item eq 'captcha') {
6523: if (ref($loginhash{'login'}) eq 'HASH') {
6524: my $chgtxt;
6525: if ($loginhash{'login'}{$item} eq 'notused') {
6526: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6527: } else {
6528: my %captchas = &captcha_phrases();
6529: if ($captchas{$loginhash{'login'}{$item}}) {
6530: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6531: } else {
6532: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6533: }
6534: }
6535: $resulttext .= '<li>'.$chgtxt.'</li>';
6536: }
6537: } elsif ($item eq 'recaptchakeys') {
6538: if (ref($loginhash{'login'}) eq 'HASH') {
6539: my ($privkey,$pubkey);
6540: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6541: $pubkey = $loginhash{'login'}{$item}{'public'};
6542: $privkey = $loginhash{'login'}{$item}{'private'};
6543: }
6544: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6545: if (!$pubkey) {
6546: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6547: } else {
6548: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6549: }
6550: if (!$privkey) {
6551: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6552: } else {
1.160.6.53 raeburn 6553: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6554: }
6555: $chgtxt .= '</ul>';
6556: $resulttext .= '<li>'.$chgtxt.'</li>';
6557: }
1.160.6.69 raeburn 6558: } elsif ($item eq 'recaptchaversion') {
6559: if (ref($loginhash{'login'}) eq 'HASH') {
6560: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
6561: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
6562: '</li>';
6563: }
6564: }
1.41 raeburn 6565: } else {
6566: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6567: }
1.1 raeburn 6568: }
1.6 raeburn 6569: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6570: } else {
6571: $resulttext = &mt('No changes made to log-in page settings');
6572: }
6573: } else {
1.11 albertel 6574: $resulttext = '<span class="LC_error">'.
6575: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6576: }
1.6 raeburn 6577: if ($errors) {
1.9 raeburn 6578: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6579: $errors.'</ul>';
6580: }
6581: return $resulttext;
6582: }
6583:
1.160.6.56 raeburn 6584: sub check_exempt_addresses {
6585: my ($iplist) = @_;
6586: $iplist =~ s/^\s+//;
6587: $iplist =~ s/\s+$//;
6588: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6589: my (@okips,$new);
6590: foreach my $ip (@poss_ips) {
6591: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6592: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6593: push(@okips,$ip);
6594: }
6595: }
6596: }
6597: if (@okips > 0) {
6598: $new = join(',',@okips);
6599: } else {
6600: $new = '';
6601: }
6602: return $new;
6603: }
6604:
1.6 raeburn 6605: sub color_font_choices {
6606: my %choices =
6607: &Apache::lonlocal::texthash (
6608: img => "Header",
6609: bgs => "Background colors",
6610: links => "Link colors",
1.55 raeburn 6611: images => "Images",
1.6 raeburn 6612: font => "Font color",
1.160.6.22 raeburn 6613: fontmenu => "Font menu",
1.76 raeburn 6614: pgbg => "Page",
1.6 raeburn 6615: tabbg => "Header",
6616: sidebg => "Border",
6617: link => "Link",
6618: alink => "Active link",
6619: vlink => "Visited link",
6620: );
6621: return %choices;
6622: }
6623:
6624: sub modify_rolecolors {
1.160.6.24 raeburn 6625: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6626: my ($resulttext,%rolehash);
6627: $rolehash{'rolecolors'} = {};
1.55 raeburn 6628: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6629: if ($domconfig{'rolecolors'} eq '') {
6630: $domconfig{'rolecolors'} = {};
6631: }
6632: }
1.9 raeburn 6633: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6634: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6635: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6636: $dom);
6637: if ($putresult eq 'ok') {
6638: if (keys(%changes) > 0) {
1.41 raeburn 6639: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6640: if (ref($lastactref) eq 'HASH') {
6641: $lastactref->{'domainconfig'} = 1;
6642: }
1.6 raeburn 6643: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6644: $rolehash{'rolecolors'});
6645: } else {
6646: $resulttext = &mt('No changes made to default color schemes');
6647: }
6648: } else {
1.11 albertel 6649: $resulttext = '<span class="LC_error">'.
6650: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6651: }
6652: if ($errors) {
6653: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6654: $errors.'</ul>';
6655: }
6656: return $resulttext;
6657: }
6658:
6659: sub modify_colors {
1.9 raeburn 6660: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6661: my (%changes,%choices);
1.51 raeburn 6662: my @bgs;
1.6 raeburn 6663: my @links = ('link','alink','vlink');
1.41 raeburn 6664: my @logintext;
1.6 raeburn 6665: my @images;
6666: my $servadm = $r->dir_config('lonAdmEMail');
6667: my $errors;
1.160.6.22 raeburn 6668: my %defaults;
1.6 raeburn 6669: foreach my $role (@{$roles}) {
6670: if ($role eq 'login') {
1.12 raeburn 6671: %choices = &login_choices();
1.41 raeburn 6672: @logintext = ('textcol','bgcol');
1.12 raeburn 6673: } else {
6674: %choices = &color_font_choices();
6675: }
6676: if ($role eq 'login') {
1.41 raeburn 6677: @images = ('img','logo','domlogo','login');
1.51 raeburn 6678: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6679: } else {
6680: @images = ('img');
1.160.6.22 raeburn 6681: @bgs = ('pgbg','tabbg','sidebg');
6682: }
6683: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6684: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6685: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6686: }
6687: if ($role eq 'login') {
6688: foreach my $item (@logintext) {
1.160.6.39 raeburn 6689: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6690: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6691: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6692: }
6693: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6694: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6695: }
6696: }
6697: } else {
1.160.6.39 raeburn 6698: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6699: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6700: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6701: }
6702: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6703: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6704: }
1.6 raeburn 6705: }
1.160.6.22 raeburn 6706: foreach my $item (@bgs) {
1.160.6.39 raeburn 6707: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6708: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6709: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6710: }
6711: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6712: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6713: }
6714: }
6715: foreach my $item (@links) {
1.160.6.39 raeburn 6716: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6717: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6718: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6719: }
6720: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6721: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6722: }
1.6 raeburn 6723: }
1.46 raeburn 6724: my ($configuserok,$author_ok,$switchserver) =
6725: &config_check($dom,$confname,$servadm);
1.9 raeburn 6726: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6727: if (ref($domconfig->{$role}) ne 'HASH') {
6728: $domconfig->{$role} = {};
6729: }
1.8 raeburn 6730: foreach my $img (@images) {
1.70 raeburn 6731: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6732: if (defined($env{'form.login_showlogo_'.$img})) {
6733: $confhash->{$role}{'showlogo'}{$img} = 1;
6734: } else {
6735: $confhash->{$role}{'showlogo'}{$img} = 0;
6736: }
6737: }
1.18 albertel 6738: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6739: && !defined($domconfig->{$role}{$img})
6740: && !$env{'form.'.$role.'_del_'.$img}
6741: && $env{'form.'.$role.'_import_'.$img}) {
6742: # import the old configured image from the .tab setting
6743: # if they haven't provided a new one
6744: $domconfig->{$role}{$img} =
6745: $env{'form.'.$role.'_import_'.$img};
6746: }
1.6 raeburn 6747: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6748: my $error;
1.6 raeburn 6749: if ($configuserok eq 'ok') {
1.9 raeburn 6750: if ($switchserver) {
1.12 raeburn 6751: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6752: } else {
6753: if ($author_ok eq 'ok') {
6754: my ($result,$logourl) =
6755: &publishlogo($r,'upload',$role.'_'.$img,
6756: $dom,$confname,$img,$width,$height);
6757: if ($result eq 'ok') {
6758: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6759: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6760: } else {
1.12 raeburn 6761: $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 6762: }
6763: } else {
1.46 raeburn 6764: $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 6765: }
6766: }
6767: } else {
1.46 raeburn 6768: $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 6769: }
6770: if ($error) {
1.8 raeburn 6771: &Apache::lonnet::logthis($error);
1.11 albertel 6772: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6773: }
6774: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6775: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6776: my $error;
6777: if ($configuserok eq 'ok') {
6778: # is confname an author?
6779: if ($switchserver eq '') {
6780: if ($author_ok eq 'ok') {
6781: my ($result,$logourl) =
6782: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6783: $dom,$confname,$img,$width,$height);
6784: if ($result eq 'ok') {
6785: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6786: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6787: }
6788: }
6789: }
6790: }
1.6 raeburn 6791: }
6792: }
6793: }
6794: if (ref($domconfig) eq 'HASH') {
6795: if (ref($domconfig->{$role}) eq 'HASH') {
6796: foreach my $img (@images) {
6797: if ($domconfig->{$role}{$img} ne '') {
6798: if ($env{'form.'.$role.'_del_'.$img}) {
6799: $confhash->{$role}{$img} = '';
1.12 raeburn 6800: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6801: } else {
1.9 raeburn 6802: if ($confhash->{$role}{$img} eq '') {
6803: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6804: }
1.6 raeburn 6805: }
6806: } else {
6807: if ($env{'form.'.$role.'_del_'.$img}) {
6808: $confhash->{$role}{$img} = '';
1.12 raeburn 6809: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6810: }
6811: }
1.70 raeburn 6812: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6813: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6814: if ($confhash->{$role}{'showlogo'}{$img} ne
6815: $domconfig->{$role}{'showlogo'}{$img}) {
6816: $changes{$role}{'showlogo'}{$img} = 1;
6817: }
6818: } else {
6819: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6820: $changes{$role}{'showlogo'}{$img} = 1;
6821: }
6822: }
6823: }
6824: }
1.6 raeburn 6825: if ($domconfig->{$role}{'font'} ne '') {
6826: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6827: $changes{$role}{'font'} = 1;
6828: }
6829: } else {
6830: if ($confhash->{$role}{'font'}) {
6831: $changes{$role}{'font'} = 1;
6832: }
6833: }
1.107 raeburn 6834: if ($role ne 'login') {
6835: if ($domconfig->{$role}{'fontmenu'} ne '') {
6836: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6837: $changes{$role}{'fontmenu'} = 1;
6838: }
6839: } else {
6840: if ($confhash->{$role}{'fontmenu'}) {
6841: $changes{$role}{'fontmenu'} = 1;
6842: }
1.97 tempelho 6843: }
6844: }
1.6 raeburn 6845: foreach my $item (@bgs) {
6846: if ($domconfig->{$role}{$item} ne '') {
6847: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6848: $changes{$role}{'bgs'}{$item} = 1;
6849: }
6850: } else {
6851: if ($confhash->{$role}{$item}) {
6852: $changes{$role}{'bgs'}{$item} = 1;
6853: }
6854: }
6855: }
6856: foreach my $item (@links) {
6857: if ($domconfig->{$role}{$item} ne '') {
6858: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6859: $changes{$role}{'links'}{$item} = 1;
6860: }
6861: } else {
6862: if ($confhash->{$role}{$item}) {
6863: $changes{$role}{'links'}{$item} = 1;
6864: }
6865: }
6866: }
1.41 raeburn 6867: foreach my $item (@logintext) {
6868: if ($domconfig->{$role}{$item} ne '') {
6869: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6870: $changes{$role}{'logintext'}{$item} = 1;
6871: }
6872: } else {
6873: if ($confhash->{$role}{$item}) {
6874: $changes{$role}{'logintext'}{$item} = 1;
6875: }
6876: }
6877: }
1.6 raeburn 6878: } else {
6879: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6880: \@logintext,$confhash,\%changes);
1.6 raeburn 6881: }
6882: } else {
6883: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6884: \@logintext,$confhash,\%changes);
1.6 raeburn 6885: }
6886: }
6887: return ($errors,%changes);
6888: }
6889:
1.46 raeburn 6890: sub config_check {
6891: my ($dom,$confname,$servadm) = @_;
6892: my ($configuserok,$author_ok,$switchserver,%currroles);
6893: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6894: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6895: $confname,$servadm);
6896: if ($configuserok eq 'ok') {
6897: $switchserver = &check_switchserver($dom,$confname);
6898: if ($switchserver eq '') {
6899: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6900: }
6901: }
6902: return ($configuserok,$author_ok,$switchserver);
6903: }
6904:
1.6 raeburn 6905: sub default_change_checker {
1.41 raeburn 6906: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6907: foreach my $item (@{$links}) {
6908: if ($confhash->{$role}{$item}) {
6909: $changes->{$role}{'links'}{$item} = 1;
6910: }
6911: }
6912: foreach my $item (@{$bgs}) {
6913: if ($confhash->{$role}{$item}) {
6914: $changes->{$role}{'bgs'}{$item} = 1;
6915: }
6916: }
1.41 raeburn 6917: foreach my $item (@{$logintext}) {
6918: if ($confhash->{$role}{$item}) {
6919: $changes->{$role}{'logintext'}{$item} = 1;
6920: }
6921: }
1.6 raeburn 6922: foreach my $img (@{$images}) {
6923: if ($env{'form.'.$role.'_del_'.$img}) {
6924: $confhash->{$role}{$img} = '';
1.12 raeburn 6925: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6926: }
1.70 raeburn 6927: if ($role eq 'login') {
6928: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6929: $changes->{$role}{'showlogo'}{$img} = 1;
6930: }
6931: }
1.6 raeburn 6932: }
6933: if ($confhash->{$role}{'font'}) {
6934: $changes->{$role}{'font'} = 1;
6935: }
1.48 raeburn 6936: }
1.6 raeburn 6937:
6938: sub display_colorchgs {
6939: my ($dom,$changes,$roles,$confhash) = @_;
6940: my (%choices,$resulttext);
6941: if (!grep(/^login$/,@{$roles})) {
6942: $resulttext = &mt('Changes made:').'<br />';
6943: }
6944: foreach my $role (@{$roles}) {
6945: if ($role eq 'login') {
6946: %choices = &login_choices();
6947: } else {
6948: %choices = &color_font_choices();
6949: }
6950: if (ref($changes->{$role}) eq 'HASH') {
6951: if ($role ne 'login') {
6952: $resulttext .= '<h4>'.&mt($role).'</h4>';
6953: }
6954: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6955: if ($role ne 'login') {
6956: $resulttext .= '<ul>';
6957: }
6958: if (ref($changes->{$role}{$key}) eq 'HASH') {
6959: if ($role ne 'login') {
6960: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6961: }
6962: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6963: if (($role eq 'login') && ($key eq 'showlogo')) {
6964: if ($confhash->{$role}{$key}{$item}) {
6965: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6966: } else {
6967: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6968: }
6969: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6970: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6971: } else {
1.12 raeburn 6972: my $newitem = $confhash->{$role}{$item};
6973: if ($key eq 'images') {
6974: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6975: }
6976: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6977: }
6978: }
6979: if ($role ne 'login') {
6980: $resulttext .= '</ul></li>';
6981: }
6982: } else {
6983: if ($confhash->{$role}{$key} eq '') {
6984: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6985: } else {
6986: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6987: }
6988: }
6989: if ($role ne 'login') {
6990: $resulttext .= '</ul>';
6991: }
6992: }
6993: }
6994: }
1.3 raeburn 6995: return $resulttext;
1.1 raeburn 6996: }
6997:
1.9 raeburn 6998: sub thumb_dimensions {
6999: return ('200','50');
7000: }
7001:
1.16 raeburn 7002: sub check_dimensions {
7003: my ($inputfile) = @_;
7004: my ($fullwidth,$fullheight);
7005: if ($inputfile =~ m|^[/\w.\-]+$|) {
7006: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7007: my $imageinfo = <PIPE>;
7008: if (!close(PIPE)) {
7009: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7010: }
7011: chomp($imageinfo);
7012: my ($fullsize) =
1.21 raeburn 7013: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7014: if ($fullsize) {
7015: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7016: }
7017: }
7018: }
7019: return ($fullwidth,$fullheight);
7020: }
7021:
1.9 raeburn 7022: sub check_configuser {
7023: my ($uhome,$dom,$confname,$servadm) = @_;
7024: my ($configuserok,%currroles);
7025: if ($uhome eq 'no_host') {
7026: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7027: my $configpass = &LONCAPA::Enrollment::create_password();
7028: $configuserok =
7029: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7030: $configpass,'','','','','',undef,$servadm);
7031: } else {
7032: $configuserok = 'ok';
7033: %currroles =
7034: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7035: }
7036: return ($configuserok,%currroles);
7037: }
7038:
7039: sub check_authorstatus {
7040: my ($dom,$confname,%currroles) = @_;
7041: my $author_ok;
1.40 raeburn 7042: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7043: my $start = time;
7044: my $end = 0;
7045: $author_ok =
7046: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7047: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7048: } else {
7049: $author_ok = 'ok';
7050: }
7051: return $author_ok;
7052: }
7053:
7054: sub publishlogo {
1.46 raeburn 7055: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7056: my ($output,$fname,$logourl);
7057: if ($action eq 'upload') {
7058: $fname=$env{'form.'.$formname.'.filename'};
7059: chop($env{'form.'.$formname});
7060: } else {
7061: ($fname) = ($formname =~ /([^\/]+)$/);
7062: }
1.46 raeburn 7063: if ($savefileas ne '') {
7064: $fname = $savefileas;
7065: }
1.9 raeburn 7066: $fname=&Apache::lonnet::clean_filename($fname);
7067: # See if there is anything left
7068: unless ($fname) { return ('error: no uploaded file'); }
7069: $fname="$subdir/$fname";
1.160.6.5 raeburn 7070: my $docroot=$r->dir_config('lonDocRoot');
7071: my $filepath="$docroot/priv";
7072: my $relpath = "$dom/$confname";
1.9 raeburn 7073: my ($fnamepath,$file,$fetchthumb);
7074: $file=$fname;
7075: if ($fname=~m|/|) {
7076: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7077: }
1.160.6.26 raeburn 7078: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7079: my $count;
1.160.6.5 raeburn 7080: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7081: $filepath.="/$parts[$count]";
7082: if ((-e $filepath)!=1) {
7083: mkdir($filepath,02770);
7084: }
7085: }
7086: # Check for bad extension and disallow upload
7087: if ($file=~/\.(\w+)$/ &&
7088: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7089: $output =
1.160.6.25 raeburn 7090: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7091: } elsif ($file=~/\.(\w+)$/ &&
7092: !defined(&Apache::loncommon::fileembstyle($1))) {
7093: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7094: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7095: $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 7096: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7097: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7098: } else {
7099: my $source = $filepath.'/'.$file;
7100: my $logfile;
7101: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7102: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7103: }
7104: print $logfile
7105: "\n================= Publish ".localtime()." ================\n".
7106: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7107: # Save the file
7108: if (!open(FH,'>'.$source)) {
7109: &Apache::lonnet::logthis('Failed to create '.$source);
7110: return (&mt('Failed to create file'));
7111: }
7112: if ($action eq 'upload') {
7113: if (!print FH ($env{'form.'.$formname})) {
7114: &Apache::lonnet::logthis('Failed to write to '.$source);
7115: return (&mt('Failed to write file'));
7116: }
7117: } else {
7118: my $original = &Apache::lonnet::filelocation('',$formname);
7119: if(!copy($original,$source)) {
7120: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7121: return (&mt('Failed to write file'));
7122: }
7123: }
7124: close(FH);
7125: chmod(0660, $source); # Permissions to rw-rw---.
7126:
7127: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7128: my $copyfile=$targetdir.'/'.$file;
7129:
7130: my @parts=split(/\//,$targetdir);
7131: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7132: for (my $count=5;$count<=$#parts;$count++) {
7133: $path.="/$parts[$count]";
7134: if (!-e $path) {
7135: print $logfile "\nCreating directory ".$path;
7136: mkdir($path,02770);
7137: }
7138: }
7139: my $versionresult;
7140: if (-e $copyfile) {
7141: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7142: } else {
7143: $versionresult = 'ok';
7144: }
7145: if ($versionresult eq 'ok') {
7146: if (copy($source,$copyfile)) {
7147: print $logfile "\nCopied original source to ".$copyfile."\n";
7148: $output = 'ok';
7149: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7150: push(@{$modified_urls},[$copyfile,$source]);
7151: my $metaoutput =
7152: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7153: unless ($registered_cleanup) {
7154: my $handlers = $r->get_handlers('PerlCleanupHandler');
7155: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7156: $registered_cleanup=1;
7157: }
1.9 raeburn 7158: } else {
7159: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7160: $output = &mt('Failed to copy file to RES space').", $!";
7161: }
7162: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7163: my $inputfile = $filepath.'/'.$file;
7164: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7165: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7166: if ($fullwidth ne '' && $fullheight ne '') {
7167: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7168: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7169: system("convert -sample $thumbsize $inputfile $outfile");
7170: chmod(0660, $filepath.'/tn-'.$file);
7171: if (-e $outfile) {
7172: my $copyfile=$targetdir.'/tn-'.$file;
7173: if (copy($outfile,$copyfile)) {
7174: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7175: my $thumb_metaoutput =
7176: &write_metadata($dom,$confname,$formname,
7177: $targetdir,'tn-'.$file,$logfile);
7178: push(@{$modified_urls},[$copyfile,$outfile]);
7179: unless ($registered_cleanup) {
7180: my $handlers = $r->get_handlers('PerlCleanupHandler');
7181: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7182: $registered_cleanup=1;
7183: }
1.16 raeburn 7184: } else {
7185: print $logfile "\nUnable to write ".$copyfile.
7186: ':'.$!."\n";
7187: }
7188: }
1.9 raeburn 7189: }
7190: }
7191: }
7192: } else {
7193: $output = $versionresult;
7194: }
7195: }
7196: return ($output,$logourl);
7197: }
7198:
7199: sub logo_versioning {
7200: my ($targetdir,$file,$logfile) = @_;
7201: my $target = $targetdir.'/'.$file;
7202: my ($maxversion,$fn,$extn,$output);
7203: $maxversion = 0;
7204: if ($file =~ /^(.+)\.(\w+)$/) {
7205: $fn=$1;
7206: $extn=$2;
7207: }
7208: opendir(DIR,$targetdir);
7209: while (my $filename=readdir(DIR)) {
7210: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7211: $maxversion=($1>$maxversion)?$1:$maxversion;
7212: }
7213: }
7214: $maxversion++;
7215: print $logfile "\nCreating old version ".$maxversion."\n";
7216: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7217: if (copy($target,$copyfile)) {
7218: print $logfile "Copied old target to ".$copyfile."\n";
7219: $copyfile=$copyfile.'.meta';
7220: if (copy($target.'.meta',$copyfile)) {
7221: print $logfile "Copied old target metadata to ".$copyfile."\n";
7222: $output = 'ok';
7223: } else {
7224: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7225: $output = &mt('Failed to copy old meta').", $!, ";
7226: }
7227: } else {
7228: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7229: $output = &mt('Failed to copy old target').", $!, ";
7230: }
7231: return $output;
7232: }
7233:
7234: sub write_metadata {
7235: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7236: my (%metadatafields,%metadatakeys,$output);
7237: $metadatafields{'title'}=$formname;
7238: $metadatafields{'creationdate'}=time;
7239: $metadatafields{'lastrevisiondate'}=time;
7240: $metadatafields{'copyright'}='public';
7241: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7242: $env{'user.domain'};
7243: $metadatafields{'authorspace'}=$confname.':'.$dom;
7244: $metadatafields{'domain'}=$dom;
7245: {
7246: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7247: my $mfh;
1.155 raeburn 7248: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7249: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7250: unless ($_=~/\./) {
7251: my $unikey=$_;
7252: $unikey=~/^([A-Za-z]+)/;
7253: my $tag=$1;
7254: $tag=~tr/A-Z/a-z/;
7255: print $mfh "\n\<$tag";
7256: foreach (split(/\,/,$metadatakeys{$unikey})) {
7257: my $value=$metadatafields{$unikey.'.'.$_};
7258: $value=~s/\"/\'\'/g;
7259: print $mfh ' '.$_.'="'.$value.'"';
7260: }
7261: print $mfh '>'.
7262: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7263: .'</'.$tag.'>';
7264: }
7265: }
7266: $output = 'ok';
7267: print $logfile "\nWrote metadata";
7268: close($mfh);
7269: } else {
7270: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7271: $output = &mt('Could not write metadata');
7272: }
7273: }
1.155 raeburn 7274: return $output;
7275: }
7276:
7277: sub notifysubscribed {
7278: foreach my $targetsource (@{$modified_urls}){
7279: next unless (ref($targetsource) eq 'ARRAY');
7280: my ($target,$source)=@{$targetsource};
7281: if ($source ne '') {
7282: if (open(my $logfh,'>>'.$source.'.log')) {
7283: print $logfh "\nCleanup phase: Notifications\n";
7284: my @subscribed=&subscribed_hosts($target);
7285: foreach my $subhost (@subscribed) {
7286: print $logfh "\nNotifying host ".$subhost.':';
7287: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7288: print $logfh $reply;
7289: }
7290: my @subscribedmeta=&subscribed_hosts("$target.meta");
7291: foreach my $subhost (@subscribedmeta) {
7292: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7293: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7294: $subhost);
7295: print $logfh $reply;
7296: }
7297: print $logfh "\n============ Done ============\n";
1.160 raeburn 7298: close($logfh);
1.155 raeburn 7299: }
7300: }
7301: }
7302: return OK;
7303: }
7304:
7305: sub subscribed_hosts {
7306: my ($target) = @_;
7307: my @subscribed;
7308: if (open(my $fh,"<$target.subscription")) {
7309: while (my $subline=<$fh>) {
7310: if ($subline =~ /^($match_lonid):/) {
7311: my $host = $1;
7312: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7313: unless (grep(/^\Q$host\E$/,@subscribed)) {
7314: push(@subscribed,$host);
7315: }
7316: }
7317: }
7318: }
7319: }
7320: return @subscribed;
1.9 raeburn 7321: }
7322:
7323: sub check_switchserver {
7324: my ($dom,$confname) = @_;
7325: my ($allowed,$switchserver);
7326: my $home = &Apache::lonnet::homeserver($confname,$dom);
7327: if ($home eq 'no_host') {
7328: $home = &Apache::lonnet::domain($dom,'primary');
7329: }
7330: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7331: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7332: if (!$allowed) {
1.160.6.11 raeburn 7333: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7334: }
7335: return $switchserver;
7336: }
7337:
1.1 raeburn 7338: sub modify_quotas {
1.160.6.30 raeburn 7339: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7340: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7341: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7342: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7343: $validationfieldsref);
1.86 raeburn 7344: if ($action eq 'quotas') {
7345: $context = 'tools';
1.160.6.26 raeburn 7346: } else {
1.86 raeburn 7347: $context = $action;
7348: }
7349: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7350: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7351: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7352: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7353: %titles = &courserequest_titles();
7354: $toolregexp = join('|',@usertools);
7355: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7356: $confname = $dom.'-domainconfig';
7357: my $servadm = $r->dir_config('lonAdmEMail');
7358: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7359: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7360: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7361: } elsif ($context eq 'requestauthor') {
7362: @usertools = ('author');
7363: %titles = &authorrequest_titles();
1.86 raeburn 7364: } else {
1.160.6.4 raeburn 7365: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7366: %titles = &tool_titles();
1.86 raeburn 7367: }
1.160.6.27 raeburn 7368: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7369: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7370: foreach my $key (keys(%env)) {
1.101 raeburn 7371: if ($context eq 'requestcourses') {
7372: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7373: my $item = $1;
7374: my $type = $2;
7375: if ($type =~ /^limit_(.+)/) {
7376: $limithash{$item}{$1} = $env{$key};
7377: } else {
7378: $confhash{$item}{$type} = $env{$key};
7379: }
7380: }
1.160.6.5 raeburn 7381: } elsif ($context eq 'requestauthor') {
7382: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7383: $confhash{$1} = $env{$key};
7384: }
1.101 raeburn 7385: } else {
1.86 raeburn 7386: if ($key =~ /^form\.quota_(.+)$/) {
7387: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7388: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7389: $confhash{'authorquota'}{$1} = $env{$key};
7390: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7391: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7392: }
1.72 raeburn 7393: }
7394: }
1.160.6.5 raeburn 7395: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7396: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7397: @approvalnotify = sort(@approvalnotify);
7398: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7399: my @crstypes = ('official','unofficial','community','textbook');
7400: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7401: foreach my $type (@hasuniquecode) {
7402: if (grep(/^\Q$type\E$/,@crstypes)) {
7403: $confhash{'uniquecode'}{$type} = 1;
7404: }
7405: }
1.160.6.46 raeburn 7406: my (%newbook,%allpos);
1.160.6.30 raeburn 7407: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7408: foreach my $type ('textbooks','templates') {
7409: @{$allpos{$type}} = ();
7410: my $invalid;
7411: if ($type eq 'textbooks') {
7412: $invalid = &mt('Invalid LON-CAPA course for textbook');
7413: } else {
7414: $invalid = &mt('Invalid LON-CAPA course for template');
7415: }
7416: if ($env{'form.'.$type.'_addbook'}) {
7417: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7418: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7419: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7420: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7421: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7422: } else {
7423: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7424: my $position = $env{'form.'.$type.'_addbook_pos'};
7425: $position =~ s/\D+//g;
7426: if ($position ne '') {
7427: $allpos{$type}[$position] = $newbook{$type};
7428: }
1.160.6.30 raeburn 7429: }
1.160.6.46 raeburn 7430: } else {
7431: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7432: }
7433: }
1.160.6.46 raeburn 7434: }
1.160.6.30 raeburn 7435: }
1.102 raeburn 7436: if (ref($domconfig{$action}) eq 'HASH') {
7437: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7438: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7439: $changes{'notify'}{'approval'} = 1;
7440: }
7441: } else {
1.144 raeburn 7442: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7443: $changes{'notify'}{'approval'} = 1;
7444: }
7445: }
1.160.6.30 raeburn 7446: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7447: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7448: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7449: unless ($confhash{'uniquecode'}{$crstype}) {
7450: $changes{'uniquecode'} = 1;
7451: }
7452: }
7453: unless ($changes{'uniquecode'}) {
7454: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7455: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7456: $changes{'uniquecode'} = 1;
7457: }
7458: }
7459: }
7460: } else {
7461: $changes{'uniquecode'} = 1;
7462: }
7463: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7464: $changes{'uniquecode'} = 1;
7465: }
7466: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7467: foreach my $type ('textbooks','templates') {
7468: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7469: my %deletions;
7470: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7471: if (@todelete) {
7472: map { $deletions{$_} = 1; } @todelete;
7473: }
7474: my %imgdeletions;
7475: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7476: if (@todeleteimages) {
7477: map { $imgdeletions{$_} = 1; } @todeleteimages;
7478: }
7479: my $maxnum = $env{'form.'.$type.'_maxnum'};
7480: for (my $i=0; $i<=$maxnum; $i++) {
7481: my $itemid = $env{'form.'.$type.'_id_'.$i};
7482: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7483: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7484: if ($deletions{$key}) {
7485: if ($domconfig{$action}{$type}{$key}{'image'}) {
7486: #FIXME need to obsolete item in RES space
7487: }
7488: next;
7489: } else {
7490: my $newpos = $env{'form.'.$itemid};
7491: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7492: foreach my $item ('subject','title','publisher','author') {
7493: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7494: ($type eq 'templates'));
1.160.6.46 raeburn 7495: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7496: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7497: $changes{$type}{$key} = 1;
7498: }
7499: }
7500: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7501: }
1.160.6.46 raeburn 7502: if ($imgdeletions{$key}) {
7503: $changes{$type}{$key} = 1;
7504: #FIXME need to obsolete item in RES space
7505: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7506: my ($cdom,$cnum) = split(/_/,$key);
7507: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7508: $cdom,$cnum,$type,$configuserok,
7509: $switchserver,$author_ok);
7510: if ($imgurl) {
7511: $confhash{$type}{$key}{'image'} = $imgurl;
7512: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7513: }
1.160.6.46 raeburn 7514: if ($error) {
7515: &Apache::lonnet::logthis($error);
7516: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7517: }
7518: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7519: $confhash{$type}{$key}{'image'} =
7520: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7521: }
7522: }
7523: }
7524: }
7525: }
7526: }
1.102 raeburn 7527: } else {
1.144 raeburn 7528: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7529: $changes{'notify'}{'approval'} = 1;
7530: }
1.160.6.30 raeburn 7531: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7532: $changes{'uniquecode'} = 1;
7533: }
7534: }
7535: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7536: foreach my $type ('textbooks','templates') {
7537: if ($newbook{$type}) {
7538: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7539: foreach my $item ('subject','title','publisher','author') {
7540: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7541: ($type eq 'template'));
1.160.6.46 raeburn 7542: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7543: if ($env{'form.'.$type.'_addbook_'.$item}) {
7544: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7545: }
7546: }
7547: if ($type eq 'textbooks') {
7548: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7549: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7550: my ($imageurl,$error) =
7551: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7552: $configuserok,$switchserver,$author_ok);
7553: if ($imageurl) {
7554: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7555: }
7556: if ($error) {
7557: &Apache::lonnet::logthis($error);
7558: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7559: }
7560: }
1.160.6.30 raeburn 7561: }
7562: }
1.160.6.46 raeburn 7563: if (@{$allpos{$type}} > 0) {
7564: my $idx = 0;
7565: foreach my $item (@{$allpos{$type}}) {
7566: if ($item ne '') {
7567: $confhash{$type}{$item}{'order'} = $idx;
7568: if (ref($domconfig{$action}) eq 'HASH') {
7569: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7570: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7571: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7572: $changes{$type}{$item} = 1;
7573: }
1.160.6.30 raeburn 7574: }
7575: }
7576: }
1.160.6.46 raeburn 7577: $idx ++;
1.160.6.30 raeburn 7578: }
7579: }
7580: }
7581: }
1.160.6.39 raeburn 7582: if (ref($validationitemsref) eq 'ARRAY') {
7583: foreach my $item (@{$validationitemsref}) {
7584: if ($item eq 'fields') {
7585: my @changed;
7586: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7587: if (@{$confhash{'validation'}{$item}} > 0) {
7588: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7589: }
1.160.6.65 raeburn 7590: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7591: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7592: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7593: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7594: $domconfig{'requestcourses'}{'validation'}{$item});
7595: } else {
7596: @changed = @{$confhash{'validation'}{$item}};
7597: }
1.160.6.39 raeburn 7598: } else {
7599: @changed = @{$confhash{'validation'}{$item}};
7600: }
7601: } else {
7602: @changed = @{$confhash{'validation'}{$item}};
7603: }
7604: if (@changed) {
7605: if ($confhash{'validation'}{$item}) {
7606: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7607: } else {
7608: $changes{'validation'}{$item} = &mt('None');
7609: }
7610: }
7611: } else {
7612: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7613: if ($item eq 'markup') {
7614: if ($env{'form.requestcourses_validation_'.$item}) {
7615: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7616: }
7617: }
1.160.6.65 raeburn 7618: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7619: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7620: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7621: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7622: }
7623: } else {
7624: if ($confhash{'validation'}{$item} ne '') {
7625: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7626: }
1.160.6.39 raeburn 7627: }
7628: } else {
7629: if ($confhash{'validation'}{$item} ne '') {
7630: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7631: }
7632: }
7633: }
7634: }
7635: }
7636: if ($env{'form.validationdc'}) {
7637: my $newval = $env{'form.validationdc'};
7638: my %domcoords = &get_active_dcs($dom);
7639: if (exists($domcoords{$newval})) {
7640: $confhash{'validation'}{'dc'} = $newval;
7641: }
7642: }
7643: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 7644: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7645: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7646: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7647: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7648: if ($confhash{'validation'}{'dc'} eq '') {
7649: $changes{'validation'}{'dc'} = &mt('None');
7650: } else {
7651: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7652: }
1.160.6.39 raeburn 7653: }
1.160.6.65 raeburn 7654: } elsif ($confhash{'validation'}{'dc'} ne '') {
7655: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 7656: }
7657: } elsif ($confhash{'validation'}{'dc'} ne '') {
7658: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7659: }
7660: } elsif ($confhash{'validation'}{'dc'} ne '') {
7661: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7662: }
1.160.6.65 raeburn 7663: } else {
7664: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7665: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7666: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7667: $changes{'validation'}{'dc'} = &mt('None');
7668: }
7669: }
1.160.6.39 raeburn 7670: }
7671: }
1.102 raeburn 7672: }
7673: } else {
1.86 raeburn 7674: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7675: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7676: }
1.72 raeburn 7677: foreach my $item (@usertools) {
7678: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7679: my $unset;
1.101 raeburn 7680: if ($context eq 'requestcourses') {
1.104 raeburn 7681: $unset = '0';
7682: if ($type eq '_LC_adv') {
7683: $unset = '';
7684: }
1.101 raeburn 7685: if ($confhash{$item}{$type} eq 'autolimit') {
7686: $confhash{$item}{$type} .= '=';
7687: unless ($limithash{$item}{$type} =~ /\D/) {
7688: $confhash{$item}{$type} .= $limithash{$item}{$type};
7689: }
7690: }
1.160.6.5 raeburn 7691: } elsif ($context eq 'requestauthor') {
7692: $unset = '0';
7693: if ($type eq '_LC_adv') {
7694: $unset = '';
7695: }
1.72 raeburn 7696: } else {
1.101 raeburn 7697: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7698: $confhash{$item}{$type} = 1;
7699: } else {
7700: $confhash{$item}{$type} = 0;
7701: }
1.72 raeburn 7702: }
1.86 raeburn 7703: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7704: if ($action eq 'requestauthor') {
7705: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7706: $changes{$type} = 1;
7707: }
7708: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7709: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7710: $changes{$item}{$type} = 1;
7711: }
7712: } else {
7713: if ($context eq 'requestcourses') {
1.104 raeburn 7714: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7715: $changes{$item}{$type} = 1;
7716: }
7717: } else {
7718: if (!$confhash{$item}{$type}) {
7719: $changes{$item}{$type} = 1;
7720: }
7721: }
7722: }
7723: } else {
7724: if ($context eq 'requestcourses') {
1.104 raeburn 7725: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7726: $changes{$item}{$type} = 1;
7727: }
1.160.6.5 raeburn 7728: } elsif ($context eq 'requestauthor') {
7729: if ($confhash{$type} ne $unset) {
7730: $changes{$type} = 1;
7731: }
1.72 raeburn 7732: } else {
7733: if (!$confhash{$item}{$type}) {
7734: $changes{$item}{$type} = 1;
7735: }
7736: }
7737: }
1.1 raeburn 7738: }
7739: }
1.160.6.5 raeburn 7740: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7741: if (ref($domconfig{'quotas'}) eq 'HASH') {
7742: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7743: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7744: if (exists($confhash{'defaultquota'}{$key})) {
7745: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7746: $changes{'defaultquota'}{$key} = 1;
7747: }
7748: } else {
7749: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7750: }
7751: }
1.86 raeburn 7752: } else {
7753: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7754: if (exists($confhash{'defaultquota'}{$key})) {
7755: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7756: $changes{'defaultquota'}{$key} = 1;
7757: }
7758: } else {
7759: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7760: }
1.1 raeburn 7761: }
7762: }
1.160.6.20 raeburn 7763: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7764: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7765: if (exists($confhash{'authorquota'}{$key})) {
7766: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7767: $changes{'authorquota'}{$key} = 1;
7768: }
7769: } else {
7770: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7771: }
7772: }
7773: }
1.1 raeburn 7774: }
1.86 raeburn 7775: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7776: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7777: if (ref($domconfig{'quotas'}) eq 'HASH') {
7778: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7779: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7780: $changes{'defaultquota'}{$key} = 1;
7781: }
7782: } else {
7783: if (!exists($domconfig{'quotas'}{$key})) {
7784: $changes{'defaultquota'}{$key} = 1;
7785: }
1.72 raeburn 7786: }
7787: } else {
1.86 raeburn 7788: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7789: }
1.1 raeburn 7790: }
7791: }
1.160.6.20 raeburn 7792: if (ref($confhash{'authorquota'}) eq 'HASH') {
7793: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7794: if (ref($domconfig{'quotas'}) eq 'HASH') {
7795: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7796: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7797: $changes{'authorquota'}{$key} = 1;
7798: }
7799: } else {
7800: $changes{'authorquota'}{$key} = 1;
7801: }
7802: } else {
7803: $changes{'authorquota'}{$key} = 1;
7804: }
7805: }
7806: }
1.1 raeburn 7807: }
1.72 raeburn 7808:
1.160.6.5 raeburn 7809: if ($context eq 'requestauthor') {
7810: $domdefaults{'requestauthor'} = \%confhash;
7811: } else {
7812: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7813: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7814: $domdefaults{$key} = $confhash{$key};
7815: }
1.160.6.5 raeburn 7816: }
1.72 raeburn 7817: }
1.160.6.5 raeburn 7818:
1.1 raeburn 7819: my %quotahash = (
1.86 raeburn 7820: $action => { %confhash }
1.1 raeburn 7821: );
7822: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7823: $dom);
7824: if ($putresult eq 'ok') {
7825: if (keys(%changes) > 0) {
1.72 raeburn 7826: my $cachetime = 24*60*60;
7827: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7828: if (ref($lastactref) eq 'HASH') {
7829: $lastactref->{'domdefaults'} = 1;
7830: }
1.1 raeburn 7831: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7832: unless (($context eq 'requestcourses') ||
7833: ($context eq 'requestauthor')) {
1.86 raeburn 7834: if (ref($changes{'defaultquota'}) eq 'HASH') {
7835: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7836: foreach my $type (@{$types},'default') {
7837: if (defined($changes{'defaultquota'}{$type})) {
7838: my $typetitle = $usertypes->{$type};
7839: if ($type eq 'default') {
7840: $typetitle = $othertitle;
7841: }
1.160.6.28 raeburn 7842: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7843: }
7844: }
1.86 raeburn 7845: $resulttext .= '</ul></li>';
1.72 raeburn 7846: }
1.160.6.20 raeburn 7847: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7848: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7849: foreach my $type (@{$types},'default') {
7850: if (defined($changes{'authorquota'}{$type})) {
7851: my $typetitle = $usertypes->{$type};
7852: if ($type eq 'default') {
7853: $typetitle = $othertitle;
7854: }
1.160.6.28 raeburn 7855: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7856: }
7857: }
7858: $resulttext .= '</ul></li>';
7859: }
1.72 raeburn 7860: }
1.80 raeburn 7861: my %newenv;
1.72 raeburn 7862: foreach my $item (@usertools) {
1.160.6.5 raeburn 7863: my (%haschgs,%inconf);
7864: if ($context eq 'requestauthor') {
7865: %haschgs = %changes;
7866: %inconf = %confhash;
7867: } else {
7868: if (ref($changes{$item}) eq 'HASH') {
7869: %haschgs = %{$changes{$item}};
7870: }
7871: if (ref($confhash{$item}) eq 'HASH') {
7872: %inconf = %{$confhash{$item}};
7873: }
7874: }
7875: if (keys(%haschgs) > 0) {
1.80 raeburn 7876: my $newacc =
7877: &Apache::lonnet::usertools_access($env{'user.name'},
7878: $env{'user.domain'},
1.86 raeburn 7879: $item,'reload',$context);
1.160.6.5 raeburn 7880: if (($context eq 'requestcourses') ||
7881: ($context eq 'requestauthor')) {
1.108 raeburn 7882: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7883: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7884: }
7885: } else {
7886: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7887: $newenv{'environment.availabletools.'.$item} = $newacc;
7888: }
1.80 raeburn 7889: }
1.160.6.5 raeburn 7890: unless ($context eq 'requestauthor') {
7891: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7892: }
1.72 raeburn 7893: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7894: if ($haschgs{$type}) {
1.72 raeburn 7895: my $typetitle = $usertypes->{$type};
7896: if ($type eq 'default') {
7897: $typetitle = $othertitle;
7898: } elsif ($type eq '_LC_adv') {
7899: $typetitle = 'LON-CAPA Advanced Users';
7900: }
1.160.6.5 raeburn 7901: if ($inconf{$type}) {
1.101 raeburn 7902: if ($context eq 'requestcourses') {
7903: my $cond;
1.160.6.5 raeburn 7904: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7905: if ($1 eq '') {
7906: $cond = &mt('(Automatic processing of any request).');
7907: } else {
7908: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7909: }
7910: } else {
1.160.6.5 raeburn 7911: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7912: }
7913: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7914: } elsif ($context eq 'requestauthor') {
7915: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7916: $titles{$inconf{$type}},$typetitle);
7917:
1.101 raeburn 7918: } else {
7919: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7920: }
1.72 raeburn 7921: } else {
1.104 raeburn 7922: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7923: if ($inconf{$type} eq '0') {
1.104 raeburn 7924: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7925: } else {
7926: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7927: }
7928: } else {
7929: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7930: }
1.72 raeburn 7931: }
7932: }
1.26 raeburn 7933: }
1.160.6.5 raeburn 7934: unless ($context eq 'requestauthor') {
7935: $resulttext .= '</ul></li>';
7936: }
1.26 raeburn 7937: }
1.1 raeburn 7938: }
1.160.6.5 raeburn 7939: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7940: if (ref($changes{'notify'}) eq 'HASH') {
7941: if ($changes{'notify'}{'approval'}) {
7942: if (ref($confhash{'notify'}) eq 'HASH') {
7943: if ($confhash{'notify'}{'approval'}) {
7944: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7945: } else {
1.160.6.5 raeburn 7946: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7947: }
7948: }
7949: }
7950: }
7951: }
1.160.6.30 raeburn 7952: if ($action eq 'requestcourses') {
7953: my @offon = ('off','on');
7954: if ($changes{'uniquecode'}) {
7955: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7956: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7957: $resulttext .= '<li>'.
7958: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7959: '</li>';
7960: } else {
7961: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7962: '</li>';
7963: }
7964: }
1.160.6.46 raeburn 7965: foreach my $type ('textbooks','templates') {
7966: if (ref($changes{$type}) eq 'HASH') {
7967: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7968: foreach my $key (sort(keys(%{$changes{$type}}))) {
7969: my %coursehash = &Apache::lonnet::coursedescription($key);
7970: my $coursetitle = $coursehash{'description'};
7971: my $position = $confhash{$type}{$key}{'order'} + 1;
7972: $resulttext .= '<li>';
1.160.6.47 raeburn 7973: foreach my $item ('subject','title','publisher','author') {
7974: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7975: ($type eq 'templates'));
1.160.6.46 raeburn 7976: my $name = $item.':';
7977: $name =~ s/^(\w)/\U$1/;
7978: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7979: }
7980: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7981: if ($type eq 'textbooks') {
7982: if ($confhash{$type}{$key}{'image'}) {
7983: $resulttext .= ' '.&mt('Image: [_1]',
7984: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7985: ' alt="Textbook cover" />').'<br />';
7986: }
7987: }
7988: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7989: }
1.160.6.46 raeburn 7990: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7991: }
7992: }
1.160.6.39 raeburn 7993: if (ref($changes{'validation'}) eq 'HASH') {
7994: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7995: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7996: foreach my $item (@{$validationitemsref}) {
7997: if (exists($changes{'validation'}{$item})) {
7998: if ($item eq 'markup') {
7999: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8000: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8001: } else {
8002: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8003: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8004: }
8005: }
8006: }
8007: if (exists($changes{'validation'}{'dc'})) {
8008: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8009: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8010: }
8011: }
8012: }
1.160.6.30 raeburn 8013: }
1.1 raeburn 8014: $resulttext .= '</ul>';
1.80 raeburn 8015: if (keys(%newenv)) {
8016: &Apache::lonnet::appenv(\%newenv);
8017: }
1.1 raeburn 8018: } else {
1.86 raeburn 8019: if ($context eq 'requestcourses') {
8020: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8021: } elsif ($context eq 'requestauthor') {
8022: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8023: } else {
1.90 weissno 8024: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8025: }
1.1 raeburn 8026: }
8027: } else {
1.11 albertel 8028: $resulttext = '<span class="LC_error">'.
8029: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8030: }
1.160.6.30 raeburn 8031: if ($errors) {
8032: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8033: '<ul>'.$errors.'</ul></p>';
8034: }
1.3 raeburn 8035: return $resulttext;
1.1 raeburn 8036: }
8037:
1.160.6.30 raeburn 8038: sub process_textbook_image {
1.160.6.46 raeburn 8039: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8040: my $filename = $env{'form.'.$caller.'.filename'};
8041: my ($error,$url);
8042: my ($width,$height) = (50,50);
8043: if ($configuserok eq 'ok') {
8044: if ($switchserver) {
8045: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8046: $switchserver);
8047: } elsif ($author_ok eq 'ok') {
8048: my ($result,$imageurl) =
8049: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 8050: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8051: if ($result eq 'ok') {
8052: $url = $imageurl;
8053: } else {
8054: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8055: }
8056: } else {
8057: $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);
8058: }
8059: } else {
8060: $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);
8061: }
8062: return ($url,$error);
8063: }
8064:
1.3 raeburn 8065: sub modify_autoenroll {
1.160.6.24 raeburn 8066: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8067: my ($resulttext,%changes);
8068: my %currautoenroll;
8069: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8070: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8071: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8072: }
8073: }
8074: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8075: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8076: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8077: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8078: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8079: my @offon = ('off','on');
1.17 raeburn 8080: my $sender_uname = $env{'form.sender_uname'};
8081: my $sender_domain = $env{'form.sender_domain'};
8082: if ($sender_domain eq '') {
8083: $sender_uname = '';
8084: } elsif ($sender_uname eq '') {
8085: $sender_domain = '';
8086: }
1.129 raeburn 8087: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8088: my $failsafe = $env{'form.autoenroll_failsafe'};
8089: $failsafe =~ s{^\s+|\s+$}{}g;
8090: if ($failsafe =~ /\D/) {
8091: undef($failsafe);
8092: }
1.1 raeburn 8093: my %autoenrollhash = (
1.129 raeburn 8094: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8095: 'sender_uname' => $sender_uname,
8096: 'sender_domain' => $sender_domain,
8097: 'co-owners' => $coowners,
1.160.6.68 raeburn 8098: 'autofailsafe' => $failsafe,
1.1 raeburn 8099: }
8100: );
1.4 raeburn 8101: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8102: $dom);
1.1 raeburn 8103: if ($putresult eq 'ok') {
8104: if (exists($currautoenroll{'run'})) {
8105: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8106: $changes{'run'} = 1;
8107: }
8108: } elsif ($autorun) {
8109: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8110: $changes{'run'} = 1;
1.1 raeburn 8111: }
8112: }
1.17 raeburn 8113: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8114: $changes{'sender'} = 1;
8115: }
1.17 raeburn 8116: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8117: $changes{'sender'} = 1;
8118: }
1.129 raeburn 8119: if ($currautoenroll{'co-owners'} ne '') {
8120: if ($currautoenroll{'co-owners'} ne $coowners) {
8121: $changes{'coowners'} = 1;
8122: }
8123: } elsif ($coowners) {
8124: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8125: }
8126: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8127: $changes{'autofailsafe'} = 1;
8128: }
1.1 raeburn 8129: if (keys(%changes) > 0) {
8130: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8131: if ($changes{'run'}) {
1.1 raeburn 8132: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8133: }
8134: if ($changes{'sender'}) {
1.17 raeburn 8135: if ($sender_uname eq '' || $sender_domain eq '') {
8136: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8137: } else {
8138: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8139: }
1.1 raeburn 8140: }
1.129 raeburn 8141: if ($changes{'coowners'}) {
8142: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8143: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8144: if (ref($lastactref) eq 'HASH') {
8145: $lastactref->{'domainconfig'} = 1;
8146: }
1.129 raeburn 8147: }
1.160.6.68 raeburn 8148: if ($changes{'autofailsafe'}) {
8149: if ($failsafe ne '') {
8150: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
8151: } else {
8152: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
8153: }
8154: &Apache::lonnet::get_domain_defaults($dom,1);
8155: if (ref($lastactref) eq 'HASH') {
8156: $lastactref->{'domdefaults'} = 1;
8157: }
8158: }
1.1 raeburn 8159: $resulttext .= '</ul>';
8160: } else {
8161: $resulttext = &mt('No changes made to auto-enrollment settings');
8162: }
8163: } else {
1.11 albertel 8164: $resulttext = '<span class="LC_error">'.
8165: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8166: }
1.3 raeburn 8167: return $resulttext;
1.1 raeburn 8168: }
8169:
8170: sub modify_autoupdate {
1.3 raeburn 8171: my ($dom,%domconfig) = @_;
1.1 raeburn 8172: my ($resulttext,%currautoupdate,%fields,%changes);
8173: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8174: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8175: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8176: }
8177: }
8178: my @offon = ('off','on');
8179: my %title = &Apache::lonlocal::texthash (
8180: run => 'Auto-update:',
8181: classlists => 'Updates to user information in classlists?'
8182: );
1.44 raeburn 8183: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8184: my %fieldtitles = &Apache::lonlocal::texthash (
8185: id => 'Student/Employee ID',
1.20 raeburn 8186: permanentemail => 'E-mail address',
1.1 raeburn 8187: lastname => 'Last Name',
8188: firstname => 'First Name',
8189: middlename => 'Middle Name',
1.132 raeburn 8190: generation => 'Generation',
1.1 raeburn 8191: );
1.142 raeburn 8192: $othertitle = &mt('All users');
1.1 raeburn 8193: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8194: $othertitle = &mt('Other users');
1.1 raeburn 8195: }
8196: foreach my $key (keys(%env)) {
8197: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8198: my ($usertype,$item) = ($1,$2);
8199: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8200: if ($usertype eq 'default') {
8201: push(@{$fields{$1}},$2);
8202: } elsif (ref($types) eq 'ARRAY') {
8203: if (grep(/^\Q$usertype\E$/,@{$types})) {
8204: push(@{$fields{$1}},$2);
8205: }
8206: }
8207: }
1.1 raeburn 8208: }
8209: }
1.131 raeburn 8210: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8211: @lockablenames = sort(@lockablenames);
8212: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8213: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8214: if (@changed) {
8215: $changes{'lockablenames'} = 1;
8216: }
8217: } else {
8218: if (@lockablenames) {
8219: $changes{'lockablenames'} = 1;
8220: }
8221: }
1.1 raeburn 8222: my %updatehash = (
8223: autoupdate => { run => $env{'form.autoupdate_run'},
8224: classlists => $env{'form.classlists'},
8225: fields => {%fields},
1.131 raeburn 8226: lockablenames => \@lockablenames,
1.1 raeburn 8227: }
8228: );
8229: foreach my $key (keys(%currautoupdate)) {
8230: if (($key eq 'run') || ($key eq 'classlists')) {
8231: if (exists($updatehash{autoupdate}{$key})) {
8232: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8233: $changes{$key} = 1;
8234: }
8235: }
8236: } elsif ($key eq 'fields') {
8237: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8238: foreach my $item (@{$types},'default') {
1.1 raeburn 8239: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8240: my $change = 0;
8241: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8242: if (!exists($fields{$item})) {
8243: $change = 1;
1.132 raeburn 8244: last;
1.1 raeburn 8245: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8246: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8247: $change = 1;
1.132 raeburn 8248: last;
1.1 raeburn 8249: }
8250: }
8251: }
8252: if ($change) {
8253: push(@{$changes{$key}},$item);
8254: }
1.26 raeburn 8255: }
1.1 raeburn 8256: }
8257: }
1.131 raeburn 8258: } elsif ($key eq 'lockablenames') {
8259: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8260: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8261: if (@changed) {
8262: $changes{'lockablenames'} = 1;
8263: }
8264: } else {
8265: if (@lockablenames) {
8266: $changes{'lockablenames'} = 1;
8267: }
8268: }
8269: }
8270: }
8271: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8272: if (@lockablenames) {
8273: $changes{'lockablenames'} = 1;
1.1 raeburn 8274: }
8275: }
1.26 raeburn 8276: foreach my $item (@{$types},'default') {
8277: if (defined($fields{$item})) {
8278: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8279: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8280: my $change = 0;
8281: if (ref($fields{$item}) eq 'ARRAY') {
8282: foreach my $type (@{$fields{$item}}) {
8283: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8284: $change = 1;
8285: last;
8286: }
8287: }
8288: }
8289: if ($change) {
8290: push(@{$changes{'fields'}},$item);
8291: }
8292: } else {
1.26 raeburn 8293: push(@{$changes{'fields'}},$item);
8294: }
8295: } else {
8296: push(@{$changes{'fields'}},$item);
1.1 raeburn 8297: }
8298: }
8299: }
8300: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8301: $dom);
8302: if ($putresult eq 'ok') {
8303: if (keys(%changes) > 0) {
8304: $resulttext = &mt('Changes made:').'<ul>';
8305: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8306: if ($key eq 'lockablenames') {
8307: $resulttext .= '<li>';
8308: if (@lockablenames) {
8309: $usertypes->{'default'} = $othertitle;
8310: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8311: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8312: } else {
8313: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8314: }
8315: $resulttext .= '</li>';
8316: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8317: foreach my $item (@{$changes{$key}}) {
8318: my @newvalues;
8319: foreach my $type (@{$fields{$item}}) {
8320: push(@newvalues,$fieldtitles{$type});
8321: }
1.3 raeburn 8322: my $newvaluestr;
8323: if (@newvalues > 0) {
8324: $newvaluestr = join(', ',@newvalues);
8325: } else {
8326: $newvaluestr = &mt('none');
1.6 raeburn 8327: }
1.1 raeburn 8328: if ($item eq 'default') {
1.26 raeburn 8329: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8330: } else {
1.26 raeburn 8331: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8332: }
8333: }
8334: } else {
8335: my $newvalue;
8336: if ($key eq 'run') {
8337: $newvalue = $offon[$env{'form.autoupdate_run'}];
8338: } else {
8339: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8340: }
1.1 raeburn 8341: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8342: }
8343: }
8344: $resulttext .= '</ul>';
8345: } else {
1.3 raeburn 8346: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8347: }
8348: } else {
1.11 albertel 8349: $resulttext = '<span class="LC_error">'.
8350: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8351: }
1.3 raeburn 8352: return $resulttext;
1.1 raeburn 8353: }
8354:
1.125 raeburn 8355: sub modify_autocreate {
8356: my ($dom,%domconfig) = @_;
8357: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8358: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8359: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8360: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8361: }
8362: }
8363: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8364: req => 'Auto-creation of validated requests for official courses',
8365: xmldc => 'Identity of course creator of courses from XML files',
8366: );
8367: my @types = ('xml','req');
8368: foreach my $item (@types) {
8369: $newvals{$item} = $env{'form.autocreate_'.$item};
8370: $newvals{$item} =~ s/\D//g;
8371: $newvals{$item} = 0 if ($newvals{$item} eq '');
8372: }
8373: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8374: my %domcoords = &get_active_dcs($dom);
8375: unless (exists($domcoords{$newvals{'xmldc'}})) {
8376: $newvals{'xmldc'} = '';
8377: }
8378: %autocreatehash = (
8379: autocreate => { xml => $newvals{'xml'},
8380: req => $newvals{'req'},
8381: }
8382: );
8383: if ($newvals{'xmldc'} ne '') {
8384: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8385: }
8386: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8387: $dom);
8388: if ($putresult eq 'ok') {
8389: my @items = @types;
8390: if ($newvals{'xml'}) {
8391: push(@items,'xmldc');
8392: }
8393: foreach my $item (@items) {
8394: if (exists($currautocreate{$item})) {
8395: if ($currautocreate{$item} ne $newvals{$item}) {
8396: $changes{$item} = 1;
8397: }
8398: } elsif ($newvals{$item}) {
8399: $changes{$item} = 1;
8400: }
8401: }
8402: if (keys(%changes) > 0) {
8403: my @offon = ('off','on');
8404: $resulttext = &mt('Changes made:').'<ul>';
8405: foreach my $item (@types) {
8406: if ($changes{$item}) {
8407: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8408: $resulttext .= '<li>'.
8409: &mt("$title{$item} set to [_1]$newtxt [_2]",
8410: '<b>','</b>').
8411: '</li>';
1.125 raeburn 8412: }
8413: }
8414: if ($changes{'xmldc'}) {
8415: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8416: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8417: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8418: }
8419: $resulttext .= '</ul>';
8420: } else {
8421: $resulttext = &mt('No changes made to auto-creation settings');
8422: }
8423: } else {
8424: $resulttext = '<span class="LC_error">'.
8425: &mt('An error occurred: [_1]',$putresult).'</span>';
8426: }
8427: return $resulttext;
8428: }
8429:
1.23 raeburn 8430: sub modify_directorysrch {
8431: my ($dom,%domconfig) = @_;
8432: my ($resulttext,%changes);
8433: my %currdirsrch;
8434: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8435: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8436: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8437: }
8438: }
1.160.6.72 raeburn 8439: my %title = ( available => 'Institutional directory search available',
8440: localonly => 'Other domains can search institution',
8441: lcavailable => 'LON-CAPA directory search available',
8442: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 8443: searchby => 'Search types',
8444: searchtypes => 'Search latitude');
8445: my @offon = ('off','on');
1.24 raeburn 8446: my @otherdoms = ('Yes','No');
1.23 raeburn 8447:
1.25 raeburn 8448: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8449: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8450: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8451:
1.44 raeburn 8452: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8453: if (keys(%{$usertypes}) == 0) {
8454: @cansearch = ('default');
8455: } else {
8456: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8457: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8458: if (!grep(/^\Q$type\E$/,@cansearch)) {
8459: push(@{$changes{'cansearch'}},$type);
8460: }
1.23 raeburn 8461: }
1.26 raeburn 8462: foreach my $type (@cansearch) {
8463: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8464: push(@{$changes{'cansearch'}},$type);
8465: }
1.23 raeburn 8466: }
1.26 raeburn 8467: } else {
8468: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8469: }
8470: }
8471:
8472: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8473: foreach my $by (@{$currdirsrch{'searchby'}}) {
8474: if (!grep(/^\Q$by\E$/,@searchby)) {
8475: push(@{$changes{'searchby'}},$by);
8476: }
8477: }
8478: foreach my $by (@searchby) {
8479: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8480: push(@{$changes{'searchby'}},$by);
8481: }
8482: }
8483: } else {
8484: push(@{$changes{'searchby'}},@searchby);
8485: }
1.25 raeburn 8486:
8487: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8488: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8489: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8490: push(@{$changes{'searchtypes'}},$type);
8491: }
8492: }
8493: foreach my $type (@searchtypes) {
8494: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8495: push(@{$changes{'searchtypes'}},$type);
8496: }
8497: }
8498: } else {
8499: if (exists($currdirsrch{'searchtypes'})) {
8500: foreach my $type (@searchtypes) {
8501: if ($type ne $currdirsrch{'searchtypes'}) {
8502: push(@{$changes{'searchtypes'}},$type);
8503: }
8504: }
8505: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8506: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8507: }
8508: } else {
8509: push(@{$changes{'searchtypes'}},@searchtypes);
8510: }
8511: }
8512:
1.23 raeburn 8513: my %dirsrch_hash = (
8514: directorysrch => { available => $env{'form.dirsrch_available'},
8515: cansearch => \@cansearch,
1.160.6.72 raeburn 8516: localonly => $env{'form.dirsrch_instlocalonly'},
8517: lclocalonly => $env{'form.dirsrch_domlocalonly'},
8518: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 8519: searchby => \@searchby,
1.25 raeburn 8520: searchtypes => \@searchtypes,
1.23 raeburn 8521: }
8522: );
8523: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8524: $dom);
8525: if ($putresult eq 'ok') {
8526: if (exists($currdirsrch{'available'})) {
8527: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8528: $changes{'available'} = 1;
8529: }
8530: } else {
8531: if ($env{'form.dirsrch_available'} eq '1') {
8532: $changes{'available'} = 1;
8533: }
8534: }
1.160.6.72 raeburn 8535: if (exists($currdirsrch{'lcavailable'})) {
8536: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
8537: $changes{'lcavailable'} = 1;
1.24 raeburn 8538: }
8539: } else {
1.160.6.72 raeburn 8540: if ($env{'form.dirsrch_lcavailable'} eq '1') {
8541: $changes{'lcavailable'} = 1;
8542: }
8543: }
8544: if (exists($currdirsrch{'localonly'})) {
8545: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 8546: $changes{'localonly'} = 1;
8547: }
1.160.6.72 raeburn 8548: } else {
8549: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
8550: $changes{'localonly'} = 1;
8551: }
8552: }
8553: if (exists($currdirsrch{'lclocalonly'})) {
8554: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
8555: $changes{'lclocalonly'} = 1;
8556: }
8557: } else {
8558: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
8559: $changes{'lclocalonly'} = 1;
8560: }
1.24 raeburn 8561: }
1.23 raeburn 8562: if (keys(%changes) > 0) {
8563: $resulttext = &mt('Changes made:').'<ul>';
8564: if ($changes{'available'}) {
8565: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8566: }
1.160.6.72 raeburn 8567: if ($changes{'lcavailable'}) {
8568: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
8569: }
1.24 raeburn 8570: if ($changes{'localonly'}) {
1.160.6.72 raeburn 8571: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
8572: }
8573: if ($changes{'lclocalonly'}) {
8574: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 8575: }
1.23 raeburn 8576: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8577: my $chgtext;
1.26 raeburn 8578: if (ref($usertypes) eq 'HASH') {
8579: if (keys(%{$usertypes}) > 0) {
8580: foreach my $type (@{$types}) {
8581: if (grep(/^\Q$type\E$/,@cansearch)) {
8582: $chgtext .= $usertypes->{$type}.'; ';
8583: }
8584: }
8585: if (grep(/^default$/,@cansearch)) {
8586: $chgtext .= $othertitle;
8587: } else {
8588: $chgtext =~ s/\; $//;
8589: }
1.160.6.13 raeburn 8590: $resulttext .=
8591: '<li>'.
8592: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8593: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8594: '</li>';
1.23 raeburn 8595: }
8596: }
8597: }
8598: if (ref($changes{'searchby'}) eq 'ARRAY') {
8599: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8600: my $chgtext;
8601: foreach my $type (@{$titleorder}) {
8602: if (grep(/^\Q$type\E$/,@searchby)) {
8603: if (defined($searchtitles->{$type})) {
8604: $chgtext .= $searchtitles->{$type}.'; ';
8605: }
8606: }
8607: }
8608: $chgtext =~ s/\; $//;
8609: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8610: }
1.25 raeburn 8611: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8612: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8613: my $chgtext;
8614: foreach my $type (@{$srchtypeorder}) {
8615: if (grep(/^\Q$type\E$/,@searchtypes)) {
8616: if (defined($srchtypes_desc->{$type})) {
8617: $chgtext .= $srchtypes_desc->{$type}.'; ';
8618: }
8619: }
8620: }
8621: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8622: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8623: }
8624: $resulttext .= '</ul>';
8625: } else {
1.160.6.72 raeburn 8626: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 8627: }
8628: } else {
8629: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8630: &mt('An error occurred: [_1]',$putresult).'</span>';
8631: }
8632: return $resulttext;
8633: }
8634:
1.28 raeburn 8635: sub modify_contacts {
1.160.6.24 raeburn 8636: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8637: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8638: if (ref($domconfig{'contacts'}) eq 'HASH') {
8639: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8640: $currsetting{$key} = $domconfig{'contacts'}{$key};
8641: }
8642: }
1.134 raeburn 8643: my (%others,%to,%bcc);
1.28 raeburn 8644: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8645: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8646: 'requestsmail','updatesmail','idconflictsmail');
8647: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8648: foreach my $type (@mailings) {
8649: @{$newsetting{$type}} =
8650: &Apache::loncommon::get_env_multiple('form.'.$type);
8651: foreach my $item (@contacts) {
8652: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8653: $contacts_hash{contacts}{$type}{$item} = 1;
8654: } else {
8655: $contacts_hash{contacts}{$type}{$item} = 0;
8656: }
8657: }
8658: $others{$type} = $env{'form.'.$type.'_others'};
8659: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8660: if ($type eq 'helpdeskmail') {
8661: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8662: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8663: }
1.28 raeburn 8664: }
8665: foreach my $item (@contacts) {
8666: $to{$item} = $env{'form.'.$item};
8667: $contacts_hash{'contacts'}{$item} = $to{$item};
8668: }
1.160.6.23 raeburn 8669: foreach my $item (@toggles) {
8670: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8671: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8672: }
8673: }
1.28 raeburn 8674: if (keys(%currsetting) > 0) {
8675: foreach my $item (@contacts) {
8676: if ($to{$item} ne $currsetting{$item}) {
8677: $changes{$item} = 1;
8678: }
8679: }
8680: foreach my $type (@mailings) {
8681: foreach my $item (@contacts) {
8682: if (ref($currsetting{$type}) eq 'HASH') {
8683: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8684: push(@{$changes{$type}},$item);
8685: }
8686: } else {
8687: push(@{$changes{$type}},@{$newsetting{$type}});
8688: }
8689: }
8690: if ($others{$type} ne $currsetting{$type}{'others'}) {
8691: push(@{$changes{$type}},'others');
8692: }
1.134 raeburn 8693: if ($type eq 'helpdeskmail') {
8694: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8695: push(@{$changes{$type}},'bcc');
8696: }
8697: }
1.28 raeburn 8698: }
8699: } else {
8700: my %default;
8701: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8702: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8703: $default{'errormail'} = 'adminemail';
8704: $default{'packagesmail'} = 'adminemail';
8705: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8706: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8707: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8708: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8709: foreach my $item (@contacts) {
8710: if ($to{$item} ne $default{$item}) {
8711: $changes{$item} = 1;
1.160.6.23 raeburn 8712: }
1.28 raeburn 8713: }
8714: foreach my $type (@mailings) {
8715: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8716:
8717: push(@{$changes{$type}},@{$newsetting{$type}});
8718: }
8719: if ($others{$type} ne '') {
8720: push(@{$changes{$type}},'others');
1.134 raeburn 8721: }
8722: if ($type eq 'helpdeskmail') {
8723: if ($bcc{$type} ne '') {
8724: push(@{$changes{$type}},'bcc');
8725: }
8726: }
1.28 raeburn 8727: }
8728: }
1.160.6.23 raeburn 8729: foreach my $item (@toggles) {
8730: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8731: $changes{$item} = 1;
8732: } elsif ((!$env{'form.'.$item}) &&
8733: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8734: $changes{$item} = 1;
8735: }
8736: }
1.28 raeburn 8737: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8738: $dom);
8739: if ($putresult eq 'ok') {
8740: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8741: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8742: if (ref($lastactref) eq 'HASH') {
8743: $lastactref->{'domainconfig'} = 1;
8744: }
1.28 raeburn 8745: my ($titles,$short_titles) = &contact_titles();
8746: $resulttext = &mt('Changes made:').'<ul>';
8747: foreach my $item (@contacts) {
8748: if ($changes{$item}) {
8749: $resulttext .= '<li>'.$titles->{$item}.
8750: &mt(' set to: ').
8751: '<span class="LC_cusr_emph">'.
8752: $to{$item}.'</span></li>';
8753: }
8754: }
8755: foreach my $type (@mailings) {
8756: if (ref($changes{$type}) eq 'ARRAY') {
8757: $resulttext .= '<li>'.$titles->{$type}.': ';
8758: my @text;
8759: foreach my $item (@{$newsetting{$type}}) {
8760: push(@text,$short_titles->{$item});
8761: }
8762: if ($others{$type} ne '') {
8763: push(@text,$others{$type});
8764: }
8765: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8766: join(', ',@text).'</span>';
8767: if ($type eq 'helpdeskmail') {
8768: if ($bcc{$type} ne '') {
8769: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8770: }
8771: }
8772: $resulttext .= '</li>';
1.28 raeburn 8773: }
8774: }
1.160.6.23 raeburn 8775: my @offon = ('off','on');
8776: if ($changes{'reporterrors'}) {
8777: $resulttext .= '<li>'.
8778: &mt('E-mail error reports to [_1] set to "'.
8779: $offon[$env{'form.reporterrors'}].'".',
8780: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8781: &mt('LON-CAPA core group - MSU'),600,500)).
8782: '</li>';
8783: }
8784: if ($changes{'reportupdates'}) {
8785: $resulttext .= '<li>'.
8786: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8787: $offon[$env{'form.reportupdates'}].'".',
8788: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8789: &mt('LON-CAPA core group - MSU'),600,500)).
8790: '</li>';
8791: }
1.28 raeburn 8792: $resulttext .= '</ul>';
8793: } else {
1.34 raeburn 8794: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8795: }
8796: } else {
8797: $resulttext = '<span class="LC_error">'.
8798: &mt('An error occurred: [_1].',$putresult).'</span>';
8799: }
8800: return $resulttext;
8801: }
8802:
8803: sub modify_usercreation {
1.27 raeburn 8804: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8805: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8806: my $warningmsg;
1.27 raeburn 8807: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8808: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8809: if ($key eq 'cancreate') {
8810: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8811: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8812: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 8813: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8814: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 8815: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8816: } else {
8817: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8818: }
1.50 raeburn 8819: }
1.43 raeburn 8820: }
1.160.6.34 raeburn 8821: } elsif ($key eq 'email_rule') {
8822: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8823: } else {
8824: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8825: }
8826: }
1.34 raeburn 8827: }
1.160.6.34 raeburn 8828: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8829: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8830: my @contexts = ('author','course','requestcrs');
8831: foreach my $item(@contexts) {
8832: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8833: }
1.34 raeburn 8834: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8835: foreach my $item (@contexts) {
1.160.6.34 raeburn 8836: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8837: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8838: }
1.27 raeburn 8839: }
1.34 raeburn 8840: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8841: foreach my $item (@contexts) {
1.43 raeburn 8842: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8843: if ($cancreate{$item} ne 'any') {
8844: push(@{$changes{'cancreate'}},$item);
8845: }
8846: } else {
8847: if ($cancreate{$item} ne 'none') {
8848: push(@{$changes{'cancreate'}},$item);
8849: }
1.27 raeburn 8850: }
8851: }
8852: } else {
1.43 raeburn 8853: foreach my $item (@contexts) {
1.34 raeburn 8854: push(@{$changes{'cancreate'}},$item);
8855: }
1.27 raeburn 8856: }
1.34 raeburn 8857:
1.27 raeburn 8858: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8859: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8860: if (!grep(/^\Q$type\E$/,@username_rule)) {
8861: push(@{$changes{'username_rule'}},$type);
8862: }
8863: }
8864: foreach my $type (@username_rule) {
8865: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8866: push(@{$changes{'username_rule'}},$type);
8867: }
8868: }
8869: } else {
8870: push(@{$changes{'username_rule'}},@username_rule);
8871: }
8872:
1.32 raeburn 8873: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8874: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8875: if (!grep(/^\Q$type\E$/,@id_rule)) {
8876: push(@{$changes{'id_rule'}},$type);
8877: }
8878: }
8879: foreach my $type (@id_rule) {
8880: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8881: push(@{$changes{'id_rule'}},$type);
8882: }
8883: }
8884: } else {
8885: push(@{$changes{'id_rule'}},@id_rule);
8886: }
8887:
1.43 raeburn 8888: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8889: my @authtypes = ('int','krb4','krb5','loc');
8890: my %authhash;
1.43 raeburn 8891: foreach my $item (@authen_contexts) {
1.28 raeburn 8892: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8893: foreach my $auth (@authtypes) {
8894: if (grep(/^\Q$auth\E$/,@authallowed)) {
8895: $authhash{$item}{$auth} = 1;
8896: } else {
8897: $authhash{$item}{$auth} = 0;
8898: }
8899: }
8900: }
8901: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8902: foreach my $item (@authen_contexts) {
1.28 raeburn 8903: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8904: foreach my $auth (@authtypes) {
8905: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8906: push(@{$changes{'authtypes'}},$item);
8907: last;
8908: }
8909: }
8910: }
8911: }
8912: } else {
1.43 raeburn 8913: foreach my $item (@authen_contexts) {
1.28 raeburn 8914: push(@{$changes{'authtypes'}},$item);
8915: }
8916: }
8917:
1.160.6.34 raeburn 8918: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8919: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8920: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8921: $save_usercreate{'id_rule'} = \@id_rule;
8922: $save_usercreate{'username_rule'} = \@username_rule,
8923: $save_usercreate{'authtypes'} = \%authhash;
8924:
1.27 raeburn 8925: my %usercreation_hash = (
1.160.6.34 raeburn 8926: usercreation => \%save_usercreate,
8927: );
1.27 raeburn 8928:
8929: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8930: $dom);
1.50 raeburn 8931:
1.160.6.34 raeburn 8932: if ($putresult eq 'ok') {
8933: if (keys(%changes) > 0) {
8934: $resulttext = &mt('Changes made:').'<ul>';
8935: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8936: my %lt = &usercreation_types();
8937: foreach my $type (@{$changes{'cancreate'}}) {
8938: my $chgtext = $lt{$type}.', ';
8939: if ($cancreate{$type} eq 'none') {
8940: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8941: } elsif ($cancreate{$type} eq 'any') {
8942: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8943: } elsif ($cancreate{$type} eq 'official') {
8944: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8945: } elsif ($cancreate{$type} eq 'unofficial') {
8946: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8947: }
8948: $resulttext .= '<li>'.$chgtext.'</li>';
8949: }
8950: }
8951: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8952: my ($rules,$ruleorder) =
8953: &Apache::lonnet::inst_userrules($dom,'username');
8954: my $chgtext = '<ul>';
8955: foreach my $type (@username_rule) {
8956: if (ref($rules->{$type}) eq 'HASH') {
8957: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8958: }
8959: }
8960: $chgtext .= '</ul>';
8961: if (@username_rule > 0) {
8962: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8963: } else {
8964: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8965: }
8966: }
8967: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8968: my ($idrules,$idruleorder) =
8969: &Apache::lonnet::inst_userrules($dom,'id');
8970: my $chgtext = '<ul>';
8971: foreach my $type (@id_rule) {
8972: if (ref($idrules->{$type}) eq 'HASH') {
8973: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8974: }
8975: }
8976: $chgtext .= '</ul>';
8977: if (@id_rule > 0) {
8978: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8979: } else {
8980: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8981: }
8982: }
8983: my %authname = &authtype_names();
8984: my %context_title = &context_names();
8985: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8986: my $chgtext = '<ul>';
8987: foreach my $type (@{$changes{'authtypes'}}) {
8988: my @allowed;
8989: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8990: foreach my $auth (@authtypes) {
8991: if ($authhash{$type}{$auth}) {
8992: push(@allowed,$authname{$auth});
8993: }
8994: }
8995: if (@allowed > 0) {
8996: $chgtext .= join(', ',@allowed).'</li>';
8997: } else {
8998: $chgtext .= &mt('none').'</li>';
8999: }
9000: }
9001: $chgtext .= '</ul>';
9002: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9003: $resulttext .= '</li>';
9004: }
9005: $resulttext .= '</ul>';
9006: } else {
9007: $resulttext = &mt('No changes made to user creation settings');
9008: }
9009: } else {
9010: $resulttext = '<span class="LC_error">'.
9011: &mt('An error occurred: [_1]',$putresult).'</span>';
9012: }
9013: if ($warningmsg ne '') {
9014: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9015: }
9016: return $resulttext;
9017: }
9018:
9019: sub modify_selfcreation {
9020: my ($dom,%domconfig) = @_;
9021: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9022: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9023: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9024: if (ref($types) eq 'ARRAY') {
9025: $usertypes->{'default'} = $othertitle;
9026: push(@{$types},'default');
9027: }
1.160.6.34 raeburn 9028: #
9029: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9030: #
9031: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9032: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9033: if ($key eq 'cancreate') {
9034: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9035: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9036: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9037: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9038: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9039: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9040: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9041: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9042: } else {
9043: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9044: }
9045: }
9046: }
9047: } elsif ($key eq 'email_rule') {
9048: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9049: } else {
9050: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9051: }
9052: }
9053: }
9054: #
9055: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9056: #
9057: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9058: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9059: if ($key eq 'selfcreate') {
9060: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9061: } else {
9062: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9063: }
9064: }
9065: }
9066:
9067: my @contexts = ('selfcreate');
9068: @{$cancreate{'selfcreate'}} = ();
9069: %{$cancreate{'emailusername'}} = ();
9070: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9071: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9072: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9073: my %selfcreatetypes = (
9074: sso => 'users authenticated by institutional single sign on',
9075: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9076: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9077: );
1.160.6.34 raeburn 9078: #
9079: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9080: # is permitted.
9081: #
1.160.6.40 raeburn 9082:
9083: my @statuses;
9084: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9085: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9086: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9087: }
9088: }
9089: push(@statuses,'default');
9090:
1.160.6.35 raeburn 9091: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9092: if ($item eq 'email') {
1.160.6.40 raeburn 9093: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9094: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9095: push(@contexts,'selfcreateprocessing');
9096: foreach my $type (@statuses) {
9097: if ($type eq 'default') {
9098: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9099: } else {
9100: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9101: }
9102: }
1.160.6.34 raeburn 9103: }
9104: } else {
9105: if ($env{'form.cancreate_'.$item}) {
9106: push(@{$cancreate{'selfcreate'}},$item);
9107: }
9108: }
9109: }
9110: my (@email_rule,%userinfo,%savecaptcha);
9111: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9112: #
1.160.6.35 raeburn 9113: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9114: # 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 9115: #
1.160.6.40 raeburn 9116:
1.160.6.48 raeburn 9117: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9118: push(@contexts,'emailusername');
1.160.6.35 raeburn 9119: if (ref($types) eq 'ARRAY') {
9120: foreach my $type (@{$types}) {
9121: if (ref($infofields) eq 'ARRAY') {
9122: foreach my $field (@{$infofields}) {
9123: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9124: $cancreate{'emailusername'}{$type}{$field} = $1;
9125: }
9126: }
1.160.6.34 raeburn 9127: }
9128: }
9129: }
9130: #
9131: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9132: # queued requests for self-creation of account using e-mail address as username
9133: #
9134:
9135: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9136: @approvalnotify = sort(@approvalnotify);
9137: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9138: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9139: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9140: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9141: push(@{$changes{'cancreate'}},'notify');
9142: }
9143: } else {
9144: if ($cancreate{'notify'}{'approval'}) {
9145: push(@{$changes{'cancreate'}},'notify');
9146: }
9147: }
9148: } elsif ($cancreate{'notify'}{'approval'}) {
9149: push(@{$changes{'cancreate'}},'notify');
9150: }
9151:
9152: #
9153: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9154: #
9155: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9156: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9157: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9158: if (@{$curr_usercreation{'email_rule'}} > 0) {
9159: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9160: if (!grep(/^\Q$type\E$/,@email_rule)) {
9161: push(@{$changes{'email_rule'}},$type);
9162: }
9163: }
9164: }
9165: if (@email_rule > 0) {
9166: foreach my $type (@email_rule) {
9167: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9168: push(@{$changes{'email_rule'}},$type);
9169: }
9170: }
9171: }
9172: } elsif (@email_rule > 0) {
9173: push(@{$changes{'email_rule'}},@email_rule);
9174: }
9175: }
9176: #
1.160.6.40 raeburn 9177: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9178: # institutional log-in.
9179: #
9180: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9181: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9182: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9183: ($domdefaults{'auth_def'} eq 'localauth'))) {
9184: $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.').' '.
9185: &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.');
9186: }
9187: }
9188: my @fields = ('lastname','firstname','middlename','generation',
9189: 'permanentemail','id');
1.160.6.44 raeburn 9190: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9191: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9192: #
9193: # Where usernames may created for institutional log-in and/or institutional single sign on:
9194: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9195: # may self-create accounts
9196: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9197: # which the user may supply, if institutional data is unavailable.
9198: #
9199: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9200: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9201: if (@{$types} > 1) {
1.160.6.34 raeburn 9202: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9203: push(@contexts,'statustocreate');
9204: } else {
9205: undef($cancreate{'statustocreate'});
9206: }
9207: foreach my $type (@{$types}) {
9208: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9209: foreach my $field (@fields) {
9210: if (grep(/^\Q$field\E$/,@modifiable)) {
9211: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9212: } else {
9213: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9214: }
9215: }
9216: }
9217: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9218: foreach my $type (@{$types}) {
9219: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9220: foreach my $field (@fields) {
9221: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9222: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9223: push(@{$changes{'selfcreate'}},$type);
9224: last;
9225: }
9226: }
9227: }
9228: }
9229: } else {
9230: foreach my $type (@{$types}) {
9231: push(@{$changes{'selfcreate'}},$type);
9232: }
9233: }
9234: }
1.160.6.44 raeburn 9235: foreach my $field (@shibfields) {
9236: if ($env{'form.shibenv_'.$field} ne '') {
9237: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9238: }
9239: }
9240: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9241: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9242: foreach my $field (@shibfields) {
9243: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9244: push(@{$changes{'cancreate'}},'shibenv');
9245: }
9246: }
9247: } else {
9248: foreach my $field (@shibfields) {
9249: if ($env{'form.shibenv_'.$field}) {
9250: push(@{$changes{'cancreate'}},'shibenv');
9251: last;
9252: }
9253: }
9254: }
9255: }
1.160.6.34 raeburn 9256: }
9257: foreach my $item (@contexts) {
9258: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9259: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9260: if (ref($cancreate{$item}) eq 'ARRAY') {
9261: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9262: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9263: push(@{$changes{'cancreate'}},$item);
9264: }
9265: }
9266: }
9267: }
9268: if (ref($cancreate{$item}) eq 'ARRAY') {
9269: foreach my $type (@{$cancreate{$item}}) {
9270: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9271: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9272: push(@{$changes{'cancreate'}},$item);
9273: }
9274: }
9275: }
9276: }
9277: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9278: if (ref($cancreate{$item}) eq 'HASH') {
9279: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 9280: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9281: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9282: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9283: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9284: push(@{$changes{'cancreate'}},$item);
9285: }
9286: }
9287: }
1.160.6.40 raeburn 9288: } elsif ($item eq 'selfcreateprocessing') {
9289: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9290: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9291: push(@{$changes{'cancreate'}},$item);
9292: }
9293: }
1.160.6.35 raeburn 9294: } else {
9295: if (!$cancreate{$item}{$curr}) {
9296: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9297: push(@{$changes{'cancreate'}},$item);
9298: }
1.160.6.34 raeburn 9299: }
9300: }
9301: }
9302: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 9303: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9304: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9305: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9306: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9307: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9308: push(@{$changes{'cancreate'}},$item);
9309: }
9310: }
9311: } else {
9312: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9313: push(@{$changes{'cancreate'}},$item);
9314: }
9315: }
9316: }
1.160.6.40 raeburn 9317: } elsif ($item eq 'selfcreateprocessing') {
9318: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9319: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9320: push(@{$changes{'cancreate'}},$item);
9321: }
9322: }
1.160.6.35 raeburn 9323: } else {
9324: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9325: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9326: push(@{$changes{'cancreate'}},$item);
9327: }
1.160.6.34 raeburn 9328: }
9329: }
9330: }
9331: }
9332: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9333: if (ref($cancreate{$item}) eq 'ARRAY') {
9334: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9335: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9336: push(@{$changes{'cancreate'}},$item);
9337: }
9338: }
9339: } elsif (ref($cancreate{$item}) eq 'HASH') {
9340: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9341: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9342: push(@{$changes{'cancreate'}},$item);
9343: }
9344: }
9345: }
9346: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9347: if (ref($cancreate{$item}) eq 'HASH') {
9348: foreach my $type (keys(%{$cancreate{$item}})) {
9349: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9350: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9351: if ($cancreate{$item}{$type}{$field}) {
9352: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9353: push(@{$changes{'cancreate'}},$item);
9354: }
9355: last;
9356: }
9357: }
9358: }
9359: }
1.160.6.34 raeburn 9360: }
9361: }
9362: }
9363: #
9364: # Populate %save_usercreate hash with updates to self-creation configuration.
9365: #
9366: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9367: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 9368: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 9369: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9370: if (ref($cancreate{'notify'}) eq 'HASH') {
9371: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9372: }
1.160.6.40 raeburn 9373: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9374: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9375: }
1.160.6.34 raeburn 9376: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9377: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9378: }
1.160.6.44 raeburn 9379: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9380: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9381: }
1.160.6.34 raeburn 9382: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9383: $save_usercreate{'emailrule'} = \@email_rule;
9384:
9385: my %userconfig_hash = (
9386: usercreation => \%save_usercreate,
9387: usermodification => \%save_usermodify,
9388: );
9389: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9390: $dom);
9391: #
9392: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9393: #
1.27 raeburn 9394: if ($putresult eq 'ok') {
9395: if (keys(%changes) > 0) {
9396: $resulttext = &mt('Changes made:').'<ul>';
9397: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9398: my %lt = &selfcreation_types();
1.34 raeburn 9399: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9400: my $chgtext;
1.45 raeburn 9401: if ($type eq 'selfcreate') {
1.50 raeburn 9402: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9403: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9404: } else {
1.160.6.34 raeburn 9405: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9406: '<ul>';
1.50 raeburn 9407: foreach my $case (@{$cancreate{$type}}) {
9408: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9409: }
9410: $chgtext .= '</ul>';
1.100 raeburn 9411: if (ref($cancreate{$type}) eq 'ARRAY') {
9412: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9413: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9414: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9415: $chgtext .= '<br />'.
9416: '<span class="LC_warning">'.
9417: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9418: '</span>';
1.100 raeburn 9419: }
9420: }
9421: }
9422: }
1.43 raeburn 9423: }
1.160.6.44 raeburn 9424: } elsif ($type eq 'shibenv') {
9425: if (keys(%{$cancreate{$type}}) == 0) {
9426: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9427: } else {
9428: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9429: '<ul>';
9430: foreach my $field (@shibfields) {
9431: next if ($cancreate{$type}{$field} eq '');
9432: if ($field eq 'inststatus') {
9433: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9434: } else {
9435: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9436: }
9437: }
9438: $chgtext .= '</ul>';
9439: }
1.93 raeburn 9440: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9441: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9442: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9443: if (@{$cancreate{'selfcreate'}} > 0) {
9444: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9445: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9446: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9447: $chgtext .= '<br />'.
9448: '<span class="LC_warning">'.
9449: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9450: '</span>';
9451: }
1.96 raeburn 9452: } elsif (ref($usertypes) eq 'HASH') {
9453: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9454: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9455: } else {
9456: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9457: }
9458: $chgtext .= '<ul>';
9459: foreach my $case (@{$cancreate{$type}}) {
9460: if ($case eq 'default') {
9461: $chgtext .= '<li>'.$othertitle.'</li>';
9462: } else {
9463: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9464: }
9465: }
1.100 raeburn 9466: $chgtext .= '</ul>';
9467: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9468: $chgtext .= '<br /><span class="LC_warning">'.
9469: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9470: '</span>';
1.100 raeburn 9471: }
9472: }
9473: } else {
9474: if (@{$cancreate{$type}} == 0) {
9475: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9476: } else {
9477: $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 9478: }
9479: }
9480: }
1.160.6.40 raeburn 9481: } elsif ($type eq 'selfcreateprocessing') {
9482: my %choices = &Apache::lonlocal::texthash (
9483: automatic => 'Automatic approval',
9484: approval => 'Queued for approval',
9485: );
9486: if (@statuses > 1) {
9487: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9488: '<ul>';
9489: foreach my $type (@statuses) {
9490: if ($type eq 'default') {
9491: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9492: } else {
9493: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9494: }
9495: }
9496: $chgtext .= '</ul>';
9497: } else {
9498: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9499: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9500: }
1.160.6.5 raeburn 9501: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9502: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9503: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9504: } else {
9505: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9506: if ($captchas{$savecaptcha{$type}}) {
9507: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9508: } else {
9509: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9510: }
9511: }
9512: } elsif ($type eq 'recaptchakeys') {
9513: my ($privkey,$pubkey);
1.160.6.34 raeburn 9514: if (ref($savecaptcha{$type}) eq 'HASH') {
9515: $pubkey = $savecaptcha{$type}{'public'};
9516: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9517: }
9518: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9519: if (!$pubkey) {
9520: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9521: } else {
9522: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9523: }
9524: if (!$privkey) {
9525: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9526: } else {
9527: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9528: }
9529: $chgtext .= '</ul>';
1.160.6.69 raeburn 9530: } elsif ($type eq 'recaptchaversion') {
9531: if ($savecaptcha{'captcha'} eq 'recaptcha') {
9532: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
9533: }
1.160.6.34 raeburn 9534: } elsif ($type eq 'emailusername') {
9535: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9536: if (ref($types) eq 'ARRAY') {
9537: foreach my $type (@{$types}) {
9538: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9539: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9540: $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 9541: '<ul>';
9542: foreach my $field (@{$infofields}) {
9543: if ($cancreate{'emailusername'}{$type}{$field}) {
9544: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9545: }
9546: }
1.160.6.50 raeburn 9547: $chgtext .= '</ul>';
9548: } else {
9549: $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 9550: }
9551: } else {
1.160.6.50 raeburn 9552: $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 9553: }
9554: }
9555: }
9556: }
9557: } elsif ($type eq 'notify') {
9558: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9559: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9560: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9561: if ($cancreate{'notify'}{'approval'}) {
9562: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9563: }
9564: }
1.43 raeburn 9565: }
1.34 raeburn 9566: }
1.160.6.34 raeburn 9567: if ($chgtext) {
9568: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9569: }
9570: }
9571: }
1.43 raeburn 9572: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9573: my ($emailrules,$emailruleorder) =
9574: &Apache::lonnet::inst_userrules($dom,'email');
9575: my $chgtext = '<ul>';
9576: foreach my $type (@email_rule) {
9577: if (ref($emailrules->{$type}) eq 'HASH') {
9578: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9579: }
9580: }
9581: $chgtext .= '</ul>';
9582: if (@email_rule > 0) {
1.160.6.34 raeburn 9583: $resulttext .= '<li>'.
9584: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9585: $chgtext.
9586: '</li>';
1.43 raeburn 9587: } else {
1.160.6.34 raeburn 9588: $resulttext .= '<li>'.
9589: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9590: '</li>';
1.43 raeburn 9591: }
9592: }
1.160.6.34 raeburn 9593: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9594: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9595: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9596: foreach my $type (@{$changes{'selfcreate'}}) {
9597: my $typename = $type;
9598: if (ref($usertypes) eq 'HASH') {
9599: if ($usertypes->{$type} ne '') {
9600: $typename = $usertypes->{$type};
1.28 raeburn 9601: }
9602: }
1.160.6.34 raeburn 9603: my @modifiable;
9604: $resulttext .= '<li>'.
9605: &mt('Self-creation of account by users with status: [_1]',
9606: '<span class="LC_cusr_emph">'.$typename.'</span>').
9607: ' - '.&mt('modifiable fields (if institutional data blank): ');
9608: foreach my $field (@fields) {
9609: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9610: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9611: }
9612: }
9613: if (@modifiable > 0) {
9614: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9615: } else {
1.160.6.34 raeburn 9616: $resulttext .= &mt('none');
1.43 raeburn 9617: }
1.160.6.34 raeburn 9618: $resulttext .= '</li>';
1.28 raeburn 9619: }
1.160.6.34 raeburn 9620: $resulttext .= '</ul></li>';
1.28 raeburn 9621: }
1.27 raeburn 9622: $resulttext .= '</ul>';
9623: } else {
1.160.6.34 raeburn 9624: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9625: }
9626: } else {
9627: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9628: &mt('An error occurred: [_1]',$putresult).'</span>';
9629: }
1.43 raeburn 9630: if ($warningmsg ne '') {
9631: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9632: }
1.23 raeburn 9633: return $resulttext;
9634: }
9635:
1.160.6.5 raeburn 9636: sub process_captcha {
9637: my ($container,$changes,$newsettings,$current) = @_;
9638: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9639: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9640: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9641: $newsettings->{'captcha'} = 'original';
9642: }
9643: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9644: if ($container eq 'cancreate') {
9645: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9646: push(@{$changes->{'cancreate'}},'captcha');
9647: } elsif (!defined($changes->{'cancreate'})) {
9648: $changes->{'cancreate'} = ['captcha'];
9649: }
9650: } else {
9651: $changes->{'captcha'} = 1;
9652: }
9653: }
1.160.6.69 raeburn 9654: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 9655: if ($newsettings->{'captcha'} eq 'recaptcha') {
9656: $newpub = $env{'form.'.$container.'_recaptchapub'};
9657: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9658: $newpub =~ s/[^\w\-]//g;
9659: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9660: $newsettings->{'recaptchakeys'} = {
9661: public => $newpub,
9662: private => $newpriv,
9663: };
1.160.6.69 raeburn 9664: $newversion = $env{'form.'.$container.'_recaptchaversion'};
9665: $newversion =~ s/\D//g;
9666: if ($newversion ne '2') {
9667: $newversion = 1;
9668: }
9669: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 9670: }
9671: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9672: $currpub = $current->{'recaptchakeys'}{'public'};
9673: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9674: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9675: $newsettings->{'recaptchakeys'} = {
9676: public => '',
9677: private => '',
9678: }
9679: }
1.160.6.5 raeburn 9680: }
1.160.6.69 raeburn 9681: if ($current->{'captcha'} eq 'recaptcha') {
9682: $currversion = $current->{'recaptchaversion'};
9683: if ($currversion ne '2') {
9684: $currversion = 1;
9685: }
9686: }
9687: if ($currversion ne $newversion) {
9688: if ($container eq 'cancreate') {
9689: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9690: push(@{$changes->{'cancreate'}},'recaptchaversion');
9691: } elsif (!defined($changes->{'cancreate'})) {
9692: $changes->{'cancreate'} = ['recaptchaversion'];
9693: }
9694: } else {
9695: $changes->{'recaptchaversion'} = 1;
9696: }
9697: }
1.160.6.5 raeburn 9698: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9699: if ($container eq 'cancreate') {
9700: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9701: push(@{$changes->{'cancreate'}},'recaptchakeys');
9702: } elsif (!defined($changes->{'cancreate'})) {
9703: $changes->{'cancreate'} = ['recaptchakeys'];
9704: }
9705: } else {
9706: $changes->{'recaptchakeys'} = 1;
9707: }
9708: }
9709: return;
9710: }
9711:
1.33 raeburn 9712: sub modify_usermodification {
9713: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9714: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9715: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9716: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9717: if ($key eq 'selfcreate') {
9718: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9719: } else {
9720: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9721: }
1.33 raeburn 9722: }
9723: }
1.160.6.34 raeburn 9724: my @contexts = ('author','course');
1.33 raeburn 9725: my %context_title = (
9726: author => 'In author context',
9727: course => 'In course context',
9728: );
9729: my @fields = ('lastname','firstname','middlename','generation',
9730: 'permanentemail','id');
9731: my %roles = (
9732: author => ['ca','aa'],
9733: course => ['st','ep','ta','in','cr'],
9734: );
9735: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9736: foreach my $context (@contexts) {
9737: foreach my $role (@{$roles{$context}}) {
9738: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9739: foreach my $item (@fields) {
9740: if (grep(/^\Q$item\E$/,@modifiable)) {
9741: $modifyhash{$context}{$role}{$item} = 1;
9742: } else {
9743: $modifyhash{$context}{$role}{$item} = 0;
9744: }
9745: }
9746: }
9747: if (ref($curr_usermodification{$context}) eq 'HASH') {
9748: foreach my $role (@{$roles{$context}}) {
9749: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9750: foreach my $field (@fields) {
9751: if ($modifyhash{$context}{$role}{$field} ne
9752: $curr_usermodification{$context}{$role}{$field}) {
9753: push(@{$changes{$context}},$role);
9754: last;
9755: }
9756: }
9757: }
9758: }
9759: } else {
9760: foreach my $context (@contexts) {
9761: foreach my $role (@{$roles{$context}}) {
9762: push(@{$changes{$context}},$role);
9763: }
9764: }
9765: }
9766: }
9767: my %usermodification_hash = (
9768: usermodification => \%modifyhash,
9769: );
9770: my $putresult = &Apache::lonnet::put_dom('configuration',
9771: \%usermodification_hash,$dom);
9772: if ($putresult eq 'ok') {
9773: if (keys(%changes) > 0) {
9774: $resulttext = &mt('Changes made: ').'<ul>';
9775: foreach my $context (@contexts) {
9776: if (ref($changes{$context}) eq 'ARRAY') {
9777: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9778: if (ref($changes{$context}) eq 'ARRAY') {
9779: foreach my $role (@{$changes{$context}}) {
9780: my $rolename;
1.160.6.34 raeburn 9781: if ($role eq 'cr') {
9782: $rolename = &mt('Custom');
1.33 raeburn 9783: } else {
1.160.6.34 raeburn 9784: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9785: }
9786: my @modifiable;
1.160.6.34 raeburn 9787: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9788: foreach my $field (@fields) {
9789: if ($modifyhash{$context}{$role}{$field}) {
9790: push(@modifiable,$fieldtitles{$field});
9791: }
9792: }
9793: if (@modifiable > 0) {
9794: $resulttext .= join(', ',@modifiable);
9795: } else {
9796: $resulttext .= &mt('none');
9797: }
9798: $resulttext .= '</li>';
9799: }
9800: $resulttext .= '</ul></li>';
9801: }
9802: }
9803: }
9804: $resulttext .= '</ul>';
9805: } else {
9806: $resulttext = &mt('No changes made to user modification settings');
9807: }
9808: } else {
9809: $resulttext = '<span class="LC_error">'.
9810: &mt('An error occurred: [_1]',$putresult).'</span>';
9811: }
9812: return $resulttext;
9813: }
9814:
1.43 raeburn 9815: sub modify_defaults {
1.160.6.27 raeburn 9816: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9817: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9818: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9819: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9820: my @authtypes = ('internal','krb4','krb5','localauth');
9821: foreach my $item (@items) {
9822: $newvalues{$item} = $env{'form.'.$item};
9823: if ($item eq 'auth_def') {
9824: if ($newvalues{$item} ne '') {
9825: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9826: push(@errors,$item);
9827: }
9828: }
9829: } elsif ($item eq 'lang_def') {
9830: if ($newvalues{$item} ne '') {
9831: if ($newvalues{$item} =~ /^(\w+)/) {
9832: my $langcode = $1;
1.103 raeburn 9833: if ($langcode ne 'x_chef') {
9834: if (code2language($langcode) eq '') {
9835: push(@errors,$item);
9836: }
1.43 raeburn 9837: }
9838: } else {
9839: push(@errors,$item);
9840: }
9841: }
1.54 raeburn 9842: } elsif ($item eq 'timezone_def') {
9843: if ($newvalues{$item} ne '') {
1.62 raeburn 9844: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9845: push(@errors,$item);
9846: }
9847: }
1.68 raeburn 9848: } elsif ($item eq 'datelocale_def') {
9849: if ($newvalues{$item} ne '') {
9850: my @datelocale_ids = DateTime::Locale->ids();
9851: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9852: push(@errors,$item);
9853: }
9854: }
1.141 raeburn 9855: } elsif ($item eq 'portal_def') {
9856: if ($newvalues{$item} ne '') {
9857: 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])\/?$/) {
9858: push(@errors,$item);
9859: }
9860: }
1.43 raeburn 9861: }
9862: if (grep(/^\Q$item\E$/,@errors)) {
9863: $newvalues{$item} = $domdefaults{$item};
9864: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9865: $changes{$item} = 1;
9866: }
1.72 raeburn 9867: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9868: }
9869: my %defaults_hash = (
1.72 raeburn 9870: defaults => \%newvalues,
9871: );
1.43 raeburn 9872: my $title = &defaults_titles();
1.160.6.40 raeburn 9873:
9874: my $currinststatus;
9875: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9876: $currinststatus = $domconfig{'inststatus'};
9877: } else {
9878: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9879: $currinststatus = {
9880: inststatustypes => $usertypes,
9881: inststatusorder => $types,
9882: inststatusguest => [],
9883: };
9884: }
9885: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9886: my @allpos;
9887: my %guests;
9888: my %alltypes;
9889: my ($currtitles,$currguests,$currorder);
9890: if (ref($currinststatus) eq 'HASH') {
9891: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9892: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9893: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9894: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9895: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9896: }
9897: }
9898: unless (grep(/^\Q$type\E$/,@todelete)) {
9899: my $position = $env{'form.inststatus_pos_'.$type};
9900: $position =~ s/\D+//g;
9901: $allpos[$position] = $type;
9902: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9903: $alltypes{$type} =~ s/`//g;
9904: if ($env{'form.inststatus_guest_'.$type}) {
9905: $guests{$type} = 1;
9906: }
9907: }
9908: }
9909: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9910: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9911: }
9912: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9913: $currtitles =~ s/,$//;
9914: }
9915: }
9916: if ($env{'form.addinststatus'}) {
9917: my $newtype = $env{'form.addinststatus'};
9918: $newtype =~ s/\W//g;
9919: unless (exists($alltypes{$newtype})) {
9920: if ($env{'form.addinststatus_guest'}) {
9921: $guests{$newtype} = 1;
9922: }
9923: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9924: $alltypes{$newtype} =~ s/`//g;
9925: my $position = $env{'form.addinststatus_pos'};
9926: $position =~ s/\D+//g;
9927: if ($position ne '') {
9928: $allpos[$position] = $newtype;
9929: }
9930: }
9931: }
9932: my (@orderedstatus,@orderedguests);
9933: foreach my $type (@allpos) {
9934: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9935: push(@orderedstatus,$type);
9936: if ($guests{$type}) {
9937: push(@orderedguests,$type);
9938: }
9939: }
9940: }
9941: foreach my $type (keys(%alltypes)) {
9942: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9943: delete($alltypes{$type});
9944: }
9945: }
9946: $defaults_hash{'inststatus'} = {
9947: inststatustypes => \%alltypes,
9948: inststatusorder => \@orderedstatus,
9949: inststatusguest => \@orderedguests,
9950: };
9951: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9952: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9953: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9954: }
9955: }
9956: if ($currorder ne join(',',@orderedstatus)) {
9957: $changes{'inststatus'}{'inststatusorder'} = 1;
9958: }
9959: if ($currguests ne join(',',@orderedguests)) {
9960: $changes{'inststatus'}{'inststatusguest'} = 1;
9961: }
9962: my $newtitles;
9963: foreach my $item (@orderedstatus) {
9964: $newtitles .= $alltypes{$item}.',';
9965: }
9966: $newtitles =~ s/,$//;
9967: if ($currtitles ne $newtitles) {
9968: $changes{'inststatus'}{'inststatustypes'} = 1;
9969: }
1.43 raeburn 9970: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9971: $dom);
9972: if ($putresult eq 'ok') {
9973: if (keys(%changes) > 0) {
9974: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9975: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9976: 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";
9977: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9978: if ($item eq 'inststatus') {
9979: if (ref($changes{'inststatus'}) eq 'HASH') {
9980: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9981: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9982: foreach my $type (@orderedstatus) {
9983: $resulttext .= $alltypes{$type}.', ';
9984: }
9985: $resulttext =~ s/, $//;
9986: $resulttext .= '</li>';
9987: }
9988: if ($changes{'inststatus'}{'inststatusguest'}) {
9989: $resulttext .= '<li>';
9990: if (@orderedguests) {
9991: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9992: foreach my $type (@orderedguests) {
9993: $resulttext .= $alltypes{$type}.', ';
9994: }
9995: $resulttext =~ s/, $//;
9996: } else {
9997: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9998: }
9999: $resulttext .= '</li>';
10000: }
10001: }
10002: } else {
10003: my $value = $env{'form.'.$item};
10004: if ($value eq '') {
10005: $value = &mt('none');
10006: } elsif ($item eq 'auth_def') {
10007: my %authnames = &authtype_names();
10008: my %shortauth = (
10009: internal => 'int',
10010: krb4 => 'krb4',
10011: krb5 => 'krb5',
10012: localauth => 'loc',
10013: );
10014: $value = $authnames{$shortauth{$value}};
10015: }
10016: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10017: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10018: }
10019: }
10020: $resulttext .= '</ul>';
10021: $mailmsgtext .= "\n";
10022: my $cachetime = 24*60*60;
1.72 raeburn 10023: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10024: if (ref($lastactref) eq 'HASH') {
10025: $lastactref->{'domdefaults'} = 1;
10026: }
1.68 raeburn 10027: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10028: my $notify = 1;
10029: if (ref($domconfig{'contacts'}) eq 'HASH') {
10030: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10031: $notify = 0;
10032: }
10033: }
10034: if ($notify) {
10035: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10036: "LON-CAPA Domain Settings Change - $dom",
10037: $mailmsgtext);
10038: }
1.54 raeburn 10039: }
1.43 raeburn 10040: } else {
1.54 raeburn 10041: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10042: }
10043: } else {
10044: $resulttext = '<span class="LC_error">'.
10045: &mt('An error occurred: [_1]',$putresult).'</span>';
10046: }
10047: if (@errors > 0) {
10048: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10049: foreach my $item (@errors) {
10050: $resulttext .= ' "'.$title->{$item}.'",';
10051: }
10052: $resulttext =~ s/,$//;
10053: }
10054: return $resulttext;
10055: }
10056:
1.46 raeburn 10057: sub modify_scantron {
1.160.6.24 raeburn 10058: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10059: my ($resulttext,%confhash,%changes,$errors);
10060: my $custom = 'custom.tab';
10061: my $default = 'default.tab';
10062: my $servadm = $r->dir_config('lonAdmEMail');
10063: my ($configuserok,$author_ok,$switchserver) =
10064: &config_check($dom,$confname,$servadm);
10065: if ($env{'form.scantronformat.filename'} ne '') {
10066: my $error;
10067: if ($configuserok eq 'ok') {
10068: if ($switchserver) {
1.130 raeburn 10069: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10070: } else {
10071: if ($author_ok eq 'ok') {
10072: my ($result,$scantronurl) =
10073: &publishlogo($r,'upload','scantronformat',$dom,
10074: $confname,'scantron','','',$custom);
10075: if ($result eq 'ok') {
10076: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10077: $changes{'scantronformat'} = 1;
1.46 raeburn 10078: } else {
10079: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10080: }
10081: } else {
10082: $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);
10083: }
10084: }
10085: } else {
10086: $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);
10087: }
10088: if ($error) {
10089: &Apache::lonnet::logthis($error);
10090: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10091: }
10092: }
1.48 raeburn 10093: if (ref($domconfig{'scantron'}) eq 'HASH') {
10094: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10095: if ($env{'form.scantronformat_del'}) {
10096: $confhash{'scantron'}{'scantronformat'} = '';
10097: $changes{'scantronformat'} = 1;
1.46 raeburn 10098: }
10099: }
10100: }
10101: if (keys(%confhash) > 0) {
10102: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10103: $dom);
10104: if ($putresult eq 'ok') {
10105: if (keys(%changes) > 0) {
1.48 raeburn 10106: if (ref($confhash{'scantron'}) eq 'HASH') {
10107: $resulttext = &mt('Changes made:').'<ul>';
10108: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10109: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10110: } else {
1.130 raeburn 10111: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10112: }
1.48 raeburn 10113: $resulttext .= '</ul>';
10114: } else {
1.130 raeburn 10115: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10116: }
10117: $resulttext .= '</ul>';
10118: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10119: if (ref($lastactref) eq 'HASH') {
10120: $lastactref->{'domainconfig'} = 1;
10121: }
1.46 raeburn 10122: } else {
1.130 raeburn 10123: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10124: }
10125: } else {
10126: $resulttext = '<span class="LC_error">'.
10127: &mt('An error occurred: [_1]',$putresult).'</span>';
10128: }
10129: } else {
1.130 raeburn 10130: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10131: }
10132: if ($errors) {
10133: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10134: $errors.'</ul>';
10135: }
10136: return $resulttext;
10137: }
10138:
1.48 raeburn 10139: sub modify_coursecategories {
1.160.6.43 raeburn 10140: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10141: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10142: $cathash);
1.48 raeburn 10143: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10144: my @catitems = ('unauth','auth');
10145: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10146: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10147: $cathash = $domconfig{'coursecategories'}{'cats'};
10148: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10149: $changes{'togglecats'} = 1;
10150: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10151: }
10152: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10153: $changes{'categorize'} = 1;
10154: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10155: }
1.120 raeburn 10156: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10157: $changes{'togglecatscomm'} = 1;
10158: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10159: }
10160: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10161: $changes{'categorizecomm'} = 1;
10162: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10163: }
1.160.6.42 raeburn 10164: foreach my $item (@catitems) {
10165: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10166: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10167: $changes{$item} = 1;
10168: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10169: }
10170: }
10171: }
1.57 raeburn 10172: } else {
10173: $changes{'togglecats'} = 1;
10174: $changes{'categorize'} = 1;
1.124 raeburn 10175: $changes{'togglecatscomm'} = 1;
10176: $changes{'categorizecomm'} = 1;
1.87 raeburn 10177: $domconfig{'coursecategories'} = {
10178: togglecats => $env{'form.togglecats'},
10179: categorize => $env{'form.categorize'},
1.124 raeburn 10180: togglecatscomm => $env{'form.togglecatscomm'},
10181: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10182: };
1.160.6.42 raeburn 10183: foreach my $item (@catitems) {
10184: if ($env{'form.coursecat_'.$item} ne 'std') {
10185: $changes{$item} = 1;
10186: }
10187: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10188: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10189: }
10190: }
1.57 raeburn 10191: }
10192: if (ref($cathash) eq 'HASH') {
10193: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10194: push (@deletecategory,'instcode::0');
10195: }
1.120 raeburn 10196: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10197: push(@deletecategory,'communities::0');
10198: }
1.48 raeburn 10199: }
1.57 raeburn 10200: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10201: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10202: if (@deletecategory > 0) {
10203: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10204: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10205: foreach my $item (@deletecategory) {
1.57 raeburn 10206: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10207: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10208: $deletions{$item} = 1;
1.57 raeburn 10209: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10210: }
10211: }
10212: }
1.57 raeburn 10213: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10214: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10215: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10216: $reorderings{$item} = 1;
1.57 raeburn 10217: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10218: }
10219: if ($env{'form.addcategory_name_'.$item} ne '') {
10220: my $newcat = $env{'form.addcategory_name_'.$item};
10221: my $newdepth = $depth+1;
10222: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10223: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10224: $adds{$newitem} = 1;
10225: }
10226: if ($env{'form.subcat_'.$item} ne '') {
10227: my $newcat = $env{'form.subcat_'.$item};
10228: my $newdepth = $depth+1;
10229: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10230: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10231: $adds{$newitem} = 1;
10232: }
10233: }
10234: }
10235: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10236: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10237: my $newitem = 'instcode::0';
1.57 raeburn 10238: if ($cathash->{$newitem} eq '') {
10239: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10240: $adds{$newitem} = 1;
10241: }
10242: } else {
10243: my $newitem = 'instcode::0';
1.57 raeburn 10244: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10245: $adds{$newitem} = 1;
10246: }
10247: }
1.120 raeburn 10248: if ($env{'form.communities'} eq '1') {
10249: if (ref($cathash) eq 'HASH') {
10250: my $newitem = 'communities::0';
10251: if ($cathash->{$newitem} eq '') {
10252: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10253: $adds{$newitem} = 1;
10254: }
10255: } else {
10256: my $newitem = 'communities::0';
10257: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10258: $adds{$newitem} = 1;
10259: }
10260: }
1.48 raeburn 10261: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10262: if (($env{'form.addcategory_name'} ne 'instcode') &&
10263: ($env{'form.addcategory_name'} ne 'communities')) {
10264: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10265: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10266: $adds{$newitem} = 1;
10267: }
1.48 raeburn 10268: }
1.57 raeburn 10269: my $putresult;
1.48 raeburn 10270: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10271: if (keys(%deletions) > 0) {
10272: foreach my $key (keys(%deletions)) {
10273: if ($predelallitems{$key} ne '') {
10274: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10275: }
10276: }
10277: }
10278: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10279: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10280: if (ref($chkcats[0]) eq 'ARRAY') {
10281: my $depth = 0;
10282: my $chg = 0;
10283: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10284: my $name = $chkcats[0][$i];
10285: my $item;
10286: if ($name eq '') {
10287: $chg ++;
10288: } else {
10289: $item = &escape($name).'::0';
10290: if ($chg) {
1.57 raeburn 10291: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10292: }
10293: $depth ++;
1.57 raeburn 10294: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10295: $depth --;
10296: }
10297: }
10298: }
1.57 raeburn 10299: }
10300: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10301: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10302: if ($putresult eq 'ok') {
1.57 raeburn 10303: my %title = (
1.120 raeburn 10304: togglecats => 'Show/Hide a course in catalog',
10305: categorize => 'Assign a category to a course',
10306: togglecatscomm => 'Show/Hide a community in catalog',
10307: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10308: );
10309: my %level = (
1.120 raeburn 10310: dom => 'set in Domain ("Modify Course/Community")',
10311: crs => 'set in Course ("Course Configuration")',
10312: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 10313: none => 'No catalog',
10314: std => 'Standard catalog',
10315: domonly => 'Domain-only catalog',
10316: codesrch => 'Code search form',
1.57 raeburn 10317: );
1.48 raeburn 10318: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 10319: if ($changes{'togglecats'}) {
10320: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
10321: }
10322: if ($changes{'categorize'}) {
10323: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 10324: }
1.120 raeburn 10325: if ($changes{'togglecatscomm'}) {
10326: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
10327: }
10328: if ($changes{'categorizecomm'}) {
10329: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
10330: }
1.160.6.42 raeburn 10331: if ($changes{'unauth'}) {
10332: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
10333: }
10334: if ($changes{'auth'}) {
10335: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
10336: }
1.57 raeburn 10337: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10338: my $cathash;
10339: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10340: $cathash = $domconfig{'coursecategories'}{'cats'};
10341: } else {
10342: $cathash = {};
10343: }
10344: my (@cats,@trails,%allitems);
10345: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10346: if (keys(%deletions) > 0) {
10347: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10348: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10349: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10350: }
10351: $resulttext .= '</ul></li>';
10352: }
10353: if (keys(%reorderings) > 0) {
10354: my %sort_by_trail;
10355: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10356: foreach my $key (keys(%reorderings)) {
10357: if ($allitems{$key} ne '') {
10358: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10359: }
1.48 raeburn 10360: }
1.57 raeburn 10361: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10362: $resulttext .= '<li>'.$trails[$trail].'</li>';
10363: }
10364: $resulttext .= '</ul></li>';
1.48 raeburn 10365: }
1.57 raeburn 10366: if (keys(%adds) > 0) {
10367: my %sort_by_trail;
10368: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10369: foreach my $key (keys(%adds)) {
10370: if ($allitems{$key} ne '') {
10371: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10372: }
10373: }
10374: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10375: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10376: }
1.57 raeburn 10377: $resulttext .= '</ul></li>';
1.48 raeburn 10378: }
10379: }
10380: $resulttext .= '</ul>';
1.160.6.43 raeburn 10381: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10382: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10383: if ($changes{'auth'}) {
10384: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10385: }
10386: if ($changes{'unauth'}) {
10387: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10388: }
10389: my $cachetime = 24*60*60;
10390: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10391: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10392: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10393: }
10394: }
1.48 raeburn 10395: } else {
10396: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10397: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10398: }
10399: } else {
1.120 raeburn 10400: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10401: }
10402: return $resulttext;
10403: }
10404:
1.69 raeburn 10405: sub modify_serverstatuses {
10406: my ($dom,%domconfig) = @_;
10407: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10408: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10409: %currserverstatus = %{$domconfig{'serverstatuses'}};
10410: }
10411: my @pages = &serverstatus_pages();
10412: foreach my $type (@pages) {
10413: $newserverstatus{$type}{'namedusers'} = '';
10414: $newserverstatus{$type}{'machines'} = '';
10415: if (defined($env{'form.'.$type.'_namedusers'})) {
10416: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10417: my @okusers;
10418: foreach my $user (@users) {
10419: my ($uname,$udom) = split(/:/,$user);
10420: if (($udom =~ /^$match_domain$/) &&
10421: (&Apache::lonnet::domain($udom)) &&
10422: ($uname =~ /^$match_username$/)) {
10423: if (!grep(/^\Q$user\E/,@okusers)) {
10424: push(@okusers,$user);
10425: }
10426: }
10427: }
10428: if (@okusers > 0) {
10429: @okusers = sort(@okusers);
10430: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10431: }
10432: }
10433: if (defined($env{'form.'.$type.'_machines'})) {
10434: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10435: my @okmachines;
10436: foreach my $ip (@machines) {
10437: my @parts = split(/\./,$ip);
10438: next if (@parts < 4);
10439: my $badip = 0;
10440: for (my $i=0; $i<4; $i++) {
10441: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10442: $badip = 1;
10443: last;
10444: }
10445: }
10446: if (!$badip) {
10447: push(@okmachines,$ip);
10448: }
10449: }
10450: @okmachines = sort(@okmachines);
10451: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10452: }
10453: }
10454: my %serverstatushash = (
10455: serverstatuses => \%newserverstatus,
10456: );
10457: foreach my $type (@pages) {
1.83 raeburn 10458: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10459: my (@current,@new);
1.83 raeburn 10460: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10461: if ($currserverstatus{$type}{$setting} ne '') {
10462: @current = split(/,/,$currserverstatus{$type}{$setting});
10463: }
10464: }
10465: if ($newserverstatus{$type}{$setting} ne '') {
10466: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10467: }
10468: if (@current > 0) {
10469: if (@new > 0) {
10470: foreach my $item (@current) {
10471: if (!grep(/^\Q$item\E$/,@new)) {
10472: $changes{$type}{$setting} = 1;
1.82 raeburn 10473: last;
10474: }
10475: }
1.84 raeburn 10476: foreach my $item (@new) {
10477: if (!grep(/^\Q$item\E$/,@current)) {
10478: $changes{$type}{$setting} = 1;
10479: last;
1.82 raeburn 10480: }
10481: }
10482: } else {
1.83 raeburn 10483: $changes{$type}{$setting} = 1;
1.69 raeburn 10484: }
1.83 raeburn 10485: } elsif (@new > 0) {
10486: $changes{$type}{$setting} = 1;
1.69 raeburn 10487: }
10488: }
10489: }
10490: if (keys(%changes) > 0) {
1.81 raeburn 10491: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10492: my $putresult = &Apache::lonnet::put_dom('configuration',
10493: \%serverstatushash,$dom);
10494: if ($putresult eq 'ok') {
10495: $resulttext .= &mt('Changes made:').'<ul>';
10496: foreach my $type (@pages) {
1.84 raeburn 10497: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10498: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10499: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10500: if ($newserverstatus{$type}{'namedusers'} eq '') {
10501: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10502: } else {
10503: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10504: }
1.84 raeburn 10505: }
10506: if ($changes{$type}{'machines'}) {
1.69 raeburn 10507: if ($newserverstatus{$type}{'machines'} eq '') {
10508: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10509: } else {
10510: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10511: }
10512:
10513: }
10514: $resulttext .= '</ul></li>';
10515: }
10516: }
10517: $resulttext .= '</ul>';
10518: } else {
10519: $resulttext = '<span class="LC_error">'.
10520: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10521:
10522: }
10523: } else {
10524: $resulttext = &mt('No changes made to access to server status pages');
10525: }
10526: return $resulttext;
10527: }
10528:
1.118 jms 10529: sub modify_helpsettings {
1.122 jms 10530: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10531: my ($resulttext,$errors,%changes,%helphash);
10532: my %defaultchecked = ('submitbugs' => 'on');
10533: my @offon = ('off','on');
1.118 jms 10534: my @toggles = ('submitbugs');
1.160.6.73 raeburn 10535: my %current = ('submitbugs' => '');
1.118 jms 10536: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 10537: %current = %{$domconfig{'helpsettings'}};
10538: }
10539: foreach my $item (@toggles) {
10540: if ($defaultchecked{$item} eq 'on') {
10541: if ($current{$item} eq '') {
10542: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 10543: $changes{$item} = 1;
10544: }
1.160.6.73 raeburn 10545: } elsif ($current{$item} ne $env{'form.'.$item}) {
10546: $changes{$item} = 1;
10547: }
10548: } elsif ($defaultchecked{$item} eq 'off') {
10549: if ($current{$item} eq '') {
10550: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 10551: $changes{$item} = 1;
10552: }
1.160.6.73 raeburn 10553: } elsif ($current{$item} ne $env{'form.'.$item}) {
10554: $changes{$item} = 1;
10555: }
10556: }
10557: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10558: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10559: }
10560: }
10561:
10562: my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp');
10563: my $confname = $dom.'-domainconfig';
10564: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
10565: if (@modify) {
10566: foreach my $num (@modify) {
10567: my $rolename = $env{'form.custhelprole'.$num};
10568: if ($rolename ne '') {
10569: if (exists($existing{'rolesdef_'.$rolename})) {
10570: my $prefix = 'custhelp'.$num;
10571: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
10572: my %currprivs;
10573: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
10574: split(/\_/,$existing{'rolesdef_'.$rolename});
10575: foreach my $level ('c','d','s') {
10576: if ($newprivs{$level} ne $currprivs{$level}) {
10577: $changes{'customrole'}{$rolename} = 1;
10578: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
10579: $newprivs{'c'},$confname,$dom);
10580: last;
10581: }
10582: }
10583: }
1.160.6.26 raeburn 10584: }
1.160.6.73 raeburn 10585: }
10586: }
10587: if ($env{'form.newcusthelp'} ne '') {
10588: my $prefix = 'custhelp'.$env{'form.newcusthelp'};
10589: my $rolename = $env{'form.newcusthelpname'};
10590: $rolename=~s/[^A-Za-z0-9]//gs;
10591: if ($rolename ne '') {
10592: unless(exists($existing{'rolesdef_'.$rolename})) {
10593: my $errmsg;
10594: my $result = &Apache::lonuserutils::store_custom_role($rolename,$prefix,
10595: $confname,$dom);
10596: if ($result eq 'ok') {
10597: $changes{'newcustomrole'} = $rolename;
10598: } else {
10599: $errmsg = ': '.$result;
10600: }
1.122 jms 10601: }
10602: }
1.118 jms 10603: }
1.160.6.73 raeburn 10604:
1.123 jms 10605: my $putresult;
10606: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10607: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10608: if ($putresult eq 'ok') {
10609: $resulttext = &mt('Changes made:').'<ul>';
10610: foreach my $item (sort(keys(%changes))) {
10611: if ($item eq 'submitbugs') {
10612: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10613: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10614: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 10615: } elsif ($item eq 'customrole') {
10616: if (ref($changes{'customrole'}) eq 'HASH') {
10617: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
10618: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
10619: $role).'</li>';
10620: }
10621: }
10622: } elsif ($item eq 'newcustomrole') {
10623: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
10624: $changes{'newcustomrole'}).'</li>';
1.160.6.5 raeburn 10625: }
10626: }
10627: $resulttext .= '</ul>';
10628: } else {
10629: $resulttext = &mt('No changes made to help settings');
10630: $errors .= '<li><span class="LC_error">'.
10631: &mt('An error occurred storing the settings: [_1]',
10632: $putresult).'</span></li>';
10633: }
1.118 jms 10634: }
10635: if ($errors) {
1.160.6.5 raeburn 10636: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10637: $errors.'</ul>';
10638: }
10639: return $resulttext;
10640: }
10641:
1.121 raeburn 10642: sub modify_coursedefaults {
1.160.6.27 raeburn 10643: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10644: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10645: my %defaultchecked = (
10646: 'uselcmath' => 'on',
10647: 'usejsme' => 'on'
10648: );
10649: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10650: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 10651: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
10652: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 10653: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10654: my %staticdefaults = (
10655: anonsurvey_threshold => 10,
10656: uploadquota => 500,
1.160.6.57 raeburn 10657: postsubmit => 60,
1.160.6.70 raeburn 10658: mysqltables => 172800,
1.160.6.21 raeburn 10659: );
1.121 raeburn 10660:
10661: $defaultshash{'coursedefaults'} = {};
10662:
10663: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10664: if ($domconfig{'coursedefaults'} eq '') {
10665: $domconfig{'coursedefaults'} = {};
10666: }
10667: }
10668:
10669: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10670: foreach my $item (@toggles) {
10671: if ($defaultchecked{$item} eq 'on') {
10672: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10673: ($env{'form.'.$item} eq '0')) {
10674: $changes{$item} = 1;
1.160.6.16 raeburn 10675: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10676: $changes{$item} = 1;
10677: }
10678: } elsif ($defaultchecked{$item} eq 'off') {
10679: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10680: ($env{'form.'.$item} eq '1')) {
10681: $changes{$item} = 1;
10682: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10683: $changes{$item} = 1;
10684: }
10685: }
10686: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10687: }
1.160.6.21 raeburn 10688: foreach my $item (@numbers) {
10689: my ($currdef,$newdef);
1.160.6.26 raeburn 10690: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10691: if ($item eq 'anonsurvey_threshold') {
10692: $currdef = $domconfig{'coursedefaults'}{$item};
10693: $newdef =~ s/\D//g;
10694: if ($newdef eq '' || $newdef < 1) {
10695: $newdef = 1;
10696: }
10697: $defaultshash{'coursedefaults'}{$item} = $newdef;
10698: } else {
1.160.6.70 raeburn 10699: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
10700: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
10701: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 10702: }
10703: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 10704: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 10705: }
10706: if ($currdef ne $newdef) {
10707: my $staticdef;
10708: if ($item eq 'anonsurvey_threshold') {
10709: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10710: $changes{$item} = 1;
10711: }
1.160.6.70 raeburn 10712: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
10713: my $setting = $1;
10714: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
10715: $changes{$setting} = 1;
1.160.6.21 raeburn 10716: }
10717: }
1.139 raeburn 10718: }
10719: }
1.160.6.64 raeburn 10720: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
10721: my @currclonecode;
10722: if (ref($currclone) eq 'HASH') {
10723: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
10724: @currclonecode = @{$currclone->{'instcode'}};
10725: }
10726: }
10727: my $newclone;
10728: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
10729: $newclone = $env{'form.canclone'};
10730: }
10731: if ($newclone eq 'instcode') {
10732: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
10733: my (%codedefaults,@code_order,@clonecode);
10734: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
10735: \@code_order);
10736: foreach my $item (@code_order) {
10737: if (grep(/^\Q$item\E$/,@newcodes)) {
10738: push(@clonecode,$item);
10739: }
10740: }
10741: if (@clonecode) {
10742: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
10743: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
10744: if (@diffs) {
10745: $changes{'canclone'} = 1;
10746: }
10747: } else {
10748: $newclone eq '';
10749: }
10750: } elsif ($newclone ne '') {
10751: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
10752: }
10753: if ($newclone ne $currclone) {
10754: $changes{'canclone'} = 1;
10755: }
1.160.6.57 raeburn 10756: my %credits;
10757: foreach my $type (@types) {
10758: unless ($type eq 'community') {
10759: $credits{$type} = $env{'form.'.$type.'_credits'};
10760: $credits{$type} =~ s/[^\d.]+//g;
10761: }
10762: }
10763: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10764: ($env{'form.coursecredits'} eq '1')) {
10765: $changes{'coursecredits'} = 1;
10766: foreach my $type (keys(%credits)) {
10767: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10768: }
10769: } else {
10770: if ($env{'form.coursecredits'} eq '1') {
10771: foreach my $type (@types) {
10772: unless ($type eq 'community') {
10773: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10774: $changes{'coursecredits'} = 1;
10775: }
10776: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10777: }
10778: }
10779: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10780: foreach my $type (@types) {
10781: unless ($type eq 'community') {
10782: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10783: $changes{'coursecredits'} = 1;
10784: last;
10785: }
10786: }
10787: }
10788: }
10789: }
10790: if ($env{'form.postsubmit'} eq '1') {
10791: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10792: my %currtimeout;
10793: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10794: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10795: $changes{'postsubmit'} = 1;
10796: }
10797: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10798: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10799: }
10800: } else {
10801: $changes{'postsubmit'} = 1;
10802: }
10803: foreach my $type (@types) {
10804: my $timeout = $env{'form.'.$type.'_timeout'};
10805: $timeout =~ s/\D//g;
10806: if ($timeout == $staticdefaults{'postsubmit'}) {
10807: $timeout = '';
10808: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10809: $timeout = '0';
10810: }
10811: unless ($timeout eq '') {
10812: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10813: }
10814: if (exists($currtimeout{$type})) {
10815: if ($timeout ne $currtimeout{$type}) {
10816: $changes{'postsubmit'} = 1;
10817: }
10818: } elsif ($timeout ne '') {
10819: $changes{'postsubmit'} = 1;
10820: }
10821: }
10822: } else {
10823: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10824: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10825: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10826: $changes{'postsubmit'} = 1;
10827: }
10828: } else {
10829: $changes{'postsubmit'} = 1;
10830: }
1.160.6.16 raeburn 10831: }
1.121 raeburn 10832: }
10833: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10834: $dom);
10835: if ($putresult eq 'ok') {
10836: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10837: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10838: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 10839: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 10840: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 10841: foreach my $item ('uselcmath','usejsme') {
10842: if ($changes{$item}) {
10843: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10844: }
1.160.6.16 raeburn 10845: }
10846: if ($changes{'coursecredits'}) {
10847: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10848: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10849: $domdefaults{$type.'credits'} =
10850: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10851: }
10852: }
10853: }
10854: if ($changes{'postsubmit'}) {
10855: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10856: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10857: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10858: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10859: $domdefaults{$type.'postsubtimeout'} =
10860: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10861: }
10862: }
1.160.6.16 raeburn 10863: }
10864: }
1.160.6.21 raeburn 10865: if ($changes{'uploadquota'}) {
10866: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10867: foreach my $type (@types) {
10868: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10869: }
10870: }
10871: }
1.160.6.64 raeburn 10872: if ($changes{'canclone'}) {
10873: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10874: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10875: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
10876: if (@clonecodes) {
10877: $domdefaults{'canclone'} = join('+',@clonecodes);
10878: }
10879: }
10880: } else {
10881: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
10882: }
10883: }
1.121 raeburn 10884: my $cachetime = 24*60*60;
10885: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10886: if (ref($lastactref) eq 'HASH') {
10887: $lastactref->{'domdefaults'} = 1;
10888: }
1.121 raeburn 10889: }
10890: $resulttext = &mt('Changes made:').'<ul>';
10891: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10892: if ($item eq 'uselcmath') {
1.121 raeburn 10893: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10894: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10895: } else {
1.160.6.57 raeburn 10896: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10897: }
10898: } elsif ($item eq 'usejsme') {
10899: if ($env{'form.'.$item} eq '1') {
10900: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10901: } else {
10902: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10903: }
1.139 raeburn 10904: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10905: $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 10906: } elsif ($item eq 'uploadquota') {
10907: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10908: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10909: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10910: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10911: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10912:
1.160.6.21 raeburn 10913: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10914: '</ul>'.
10915: '</li>';
10916: } else {
10917: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10918: }
1.160.6.70 raeburn 10919: } elsif ($item eq 'mysqltables') {
10920: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
10921: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
10922: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
10923: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
10924: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
10925: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
10926: '</ul>'.
10927: '</li>';
10928: } else {
10929: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
10930: }
1.160.6.57 raeburn 10931: } elsif ($item eq 'postsubmit') {
10932: if ($domdefaults{'postsubmit'} eq 'off') {
10933: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10934: } else {
10935: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10936: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10937: $resulttext .= &mt('durations:').'<ul>';
10938: foreach my $type (@types) {
10939: $resulttext .= '<li>';
10940: my $timeout;
10941: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10942: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10943: }
10944: my $display;
10945: if ($timeout eq '0') {
10946: $display = &mt('unlimited');
10947: } elsif ($timeout eq '') {
10948: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10949: } else {
10950: $display = &mt('[quant,_1,second]',$timeout);
10951: }
10952: if ($type eq 'community') {
10953: $resulttext .= &mt('Communities');
10954: } elsif ($type eq 'official') {
10955: $resulttext .= &mt('Official courses');
10956: } elsif ($type eq 'unofficial') {
10957: $resulttext .= &mt('Unofficial courses');
10958: } elsif ($type eq 'textbook') {
10959: $resulttext .= &mt('Textbook courses');
10960: }
10961: $resulttext .= ' -- '.$display.'</li>';
10962: }
10963: $resulttext .= '</ul>';
10964: }
10965: $resulttext .= '</li>';
10966: }
1.160.6.16 raeburn 10967: } elsif ($item eq 'coursecredits') {
10968: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10969: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10970: ($domdefaults{'unofficialcredits'} eq '') &&
10971: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10972: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10973: } else {
10974: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10975: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10976: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10977: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10978: '</ul>'.
10979: '</li>';
10980: }
10981: } else {
10982: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10983: }
1.160.6.64 raeburn 10984: } elsif ($item eq 'canclone') {
10985: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10986: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10987: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
10988: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
10989: }
10990: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
10991: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
10992: } else {
10993: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
10994: }
1.140 raeburn 10995: }
1.121 raeburn 10996: }
10997: $resulttext .= '</ul>';
10998: } else {
10999: $resulttext = &mt('No changes made to course defaults');
11000: }
11001: } else {
11002: $resulttext = '<span class="LC_error">'.
11003: &mt('An error occurred: [_1]',$putresult).'</span>';
11004: }
11005: return $resulttext;
11006: }
11007:
1.160.6.37 raeburn 11008: sub modify_selfenrollment {
11009: my ($dom,$lastactref,%domconfig) = @_;
11010: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
11011: my @types = ('official','unofficial','community','textbook');
11012: my %titles = &tool_titles();
11013: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11014: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
11015: $ordered{'default'} = ['types','registered','approval','limit'];
11016:
11017: my (%roles,%shown,%toplevel);
11018: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11019:
11020: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11021: if ($domconfig{'selfenrollment'} eq '') {
11022: $domconfig{'selfenrollment'} = {};
11023: }
11024: }
11025: %toplevel = (
11026: admin => 'Configuration Rights',
11027: default => 'Default settings',
11028: validation => 'Validation of self-enrollment requests',
11029: );
11030: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
11031:
11032: if (ref($ordered{'admin'}) eq 'ARRAY') {
11033: foreach my $item (@{$ordered{'admin'}}) {
11034: foreach my $type (@types) {
11035: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
11036: $selfenrollhash{'admin'}{$type}{$item} = 1;
11037: } else {
11038: $selfenrollhash{'admin'}{$type}{$item} = 0;
11039: }
11040: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
11041: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
11042: if ($selfenrollhash{'admin'}{$type}{$item} ne
11043: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
11044: push(@{$changes{'admin'}{$type}},$item);
11045: }
11046: } else {
11047: if (!$selfenrollhash{'admin'}{$type}{$item}) {
11048: push(@{$changes{'admin'}{$type}},$item);
11049: }
11050: }
11051: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
11052: push(@{$changes{'admin'}{$type}},$item);
11053: }
11054: }
11055: }
11056: }
11057:
11058: foreach my $item (@{$ordered{'default'}}) {
11059: foreach my $type (@types) {
11060: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
11061: if ($item eq 'types') {
11062: unless (($value eq 'all') || ($value eq 'dom')) {
11063: $value = '';
11064: }
11065: } elsif ($item eq 'registered') {
11066: unless ($value eq '1') {
11067: $value = 0;
11068: }
11069: } elsif ($item eq 'approval') {
11070: unless ($value =~ /^[012]$/) {
11071: $value = 0;
11072: }
11073: } else {
11074: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11075: $value = 'none';
11076: }
11077: }
11078: $selfenrollhash{'default'}{$type}{$item} = $value;
11079: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
11080: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11081: if ($selfenrollhash{'default'}{$type}{$item} ne
11082: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
11083: push(@{$changes{'default'}{$type}},$item);
11084: }
11085: } else {
11086: push(@{$changes{'default'}{$type}},$item);
11087: }
11088: } else {
11089: push(@{$changes{'default'}{$type}},$item);
11090: }
11091: if ($item eq 'limit') {
11092: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11093: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
11094: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
11095: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
11096: }
11097: } else {
11098: $selfenrollhash{'default'}{$type}{'cap'} = '';
11099: }
11100: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11101: if ($selfenrollhash{'default'}{$type}{'cap'} ne
11102: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
11103: push(@{$changes{'default'}{$type}},'cap');
11104: }
11105: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
11106: push(@{$changes{'default'}{$type}},'cap');
11107: }
11108: }
11109: }
11110: }
11111:
11112: foreach my $item (@{$itemsref}) {
11113: if ($item eq 'fields') {
11114: my @changed;
11115: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
11116: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
11117: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
11118: }
11119: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11120: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
11121: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
11122: $domconfig{'selfenrollment'}{'validation'}{$item});
11123: } else {
11124: @changed = @{$selfenrollhash{'validation'}{$item}};
11125: }
11126: } else {
11127: @changed = @{$selfenrollhash{'validation'}{$item}};
11128: }
11129: if (@changed) {
11130: if ($selfenrollhash{'validation'}{$item}) {
11131: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
11132: } else {
11133: $changes{'validation'}{$item} = &mt('None');
11134: }
11135: }
11136: } else {
11137: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
11138: if ($item eq 'markup') {
11139: if ($env{'form.selfenroll_validation_'.$item}) {
11140: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11141: }
11142: }
11143: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11144: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
11145: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
11146: }
11147: }
11148: }
11149: }
11150:
11151: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
11152: $dom);
11153: if ($putresult eq 'ok') {
11154: if (keys(%changes) > 0) {
11155: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11156: $resulttext = &mt('Changes made:').'<ul>';
11157: foreach my $key ('admin','default','validation') {
11158: if (ref($changes{$key}) eq 'HASH') {
11159: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11160: if ($key eq 'validation') {
11161: foreach my $item (@{$itemsref}) {
11162: if (exists($changes{$key}{$item})) {
11163: if ($item eq 'markup') {
11164: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11165: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11166: } else {
11167: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11168: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11169: }
11170: }
11171: }
11172: } else {
11173: foreach my $type (@types) {
11174: if ($type eq 'community') {
11175: $roles{'1'} = &mt('Community personnel');
11176: } else {
11177: $roles{'1'} = &mt('Course personnel');
11178: }
11179: if (ref($changes{$key}{$type}) eq 'ARRAY') {
11180: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11181: if ($key eq 'admin') {
11182: my @mgrdc = ();
11183: if (ref($ordered{$key}) eq 'ARRAY') {
11184: foreach my $item (@{$ordered{'admin'}}) {
11185: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11186: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11187: push(@mgrdc,$item);
11188: }
11189: }
11190: }
11191: if (@mgrdc) {
11192: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11193: } else {
11194: delete($domdefaults{$type.'selfenrolladmdc'});
11195: }
11196: }
11197: } else {
11198: if (ref($ordered{$key}) eq 'ARRAY') {
11199: foreach my $item (@{$ordered{$key}}) {
11200: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11201: $domdefaults{$type.'selfenroll'.$item} =
11202: $selfenrollhash{$key}{$type}{$item};
11203: }
11204: }
11205: }
11206: }
11207: }
11208: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11209: foreach my $item (@{$ordered{$key}}) {
11210: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11211: $resulttext .= '<li>';
11212: if ($key eq 'admin') {
11213: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11214: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
11215: } else {
11216: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
11217: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
11218: }
11219: $resulttext .= '</li>';
11220: }
11221: }
11222: $resulttext .= '</ul></li>';
11223: }
11224: }
11225: $resulttext .= '</ul></li>';
11226: }
11227: }
11228: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
11229: my $cachetime = 24*60*60;
11230: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11231: if (ref($lastactref) eq 'HASH') {
11232: $lastactref->{'domdefaults'} = 1;
11233: }
11234: }
11235: }
11236: $resulttext .= '</ul>';
11237: } else {
11238: $resulttext = &mt('No changes made to self-enrollment settings');
11239: }
11240: } else {
11241: $resulttext = '<span class="LC_error">'.
11242: &mt('An error occurred: [_1]',$putresult).'</span>';
11243: }
11244: return $resulttext;
11245: }
11246:
1.137 raeburn 11247: sub modify_usersessions {
1.160.6.27 raeburn 11248: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 11249: my @hostingtypes = ('version','excludedomain','includedomain');
11250: my @offloadtypes = ('primary','default');
11251: my %types = (
11252: remote => \@hostingtypes,
11253: hosted => \@hostingtypes,
11254: spares => \@offloadtypes,
11255: );
11256: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 11257: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 11258: my (%by_ip,%by_location,@intdoms);
11259: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
11260: my @locations = sort(keys(%by_location));
1.137 raeburn 11261: my (%defaultshash,%changes);
11262: foreach my $prefix (@prefixes) {
11263: $defaultshash{'usersessions'}{$prefix} = {};
11264: }
1.160.6.27 raeburn 11265: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11266: my $resulttext;
1.138 raeburn 11267: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11268: foreach my $prefix (@prefixes) {
1.145 raeburn 11269: next if ($prefix eq 'spares');
11270: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11271: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11272: if ($type eq 'version') {
11273: my $value = $env{'form.'.$prefix.'_'.$type};
11274: my $okvalue;
11275: if ($value ne '') {
11276: if (grep(/^\Q$value\E$/,@lcversions)) {
11277: $okvalue = $value;
11278: }
11279: }
11280: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11281: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11282: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11283: if ($inuse == 0) {
11284: $changes{$prefix}{$type} = 1;
11285: } else {
11286: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11287: $changes{$prefix}{$type} = 1;
11288: }
11289: if ($okvalue ne '') {
11290: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11291: }
11292: }
11293: } else {
11294: if (($inuse == 1) && ($okvalue ne '')) {
11295: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11296: $changes{$prefix}{$type} = 1;
11297: }
11298: }
11299: } else {
11300: if (($inuse == 1) && ($okvalue ne '')) {
11301: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11302: $changes{$prefix}{$type} = 1;
11303: }
11304: }
11305: } else {
11306: if (($inuse == 1) && ($okvalue ne '')) {
11307: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11308: $changes{$prefix}{$type} = 1;
11309: }
11310: }
11311: } else {
11312: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11313: my @okvals;
11314: foreach my $val (@vals) {
1.138 raeburn 11315: if ($val =~ /:/) {
11316: my @items = split(/:/,$val);
11317: foreach my $item (@items) {
11318: if (ref($by_location{$item}) eq 'ARRAY') {
11319: push(@okvals,$item);
11320: }
11321: }
11322: } else {
11323: if (ref($by_location{$val}) eq 'ARRAY') {
11324: push(@okvals,$val);
11325: }
1.137 raeburn 11326: }
11327: }
11328: @okvals = sort(@okvals);
11329: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11330: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11331: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11332: if ($inuse == 0) {
11333: $changes{$prefix}{$type} = 1;
11334: } else {
11335: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11336: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11337: if (@changed > 0) {
11338: $changes{$prefix}{$type} = 1;
11339: }
11340: }
11341: } else {
11342: if ($inuse == 1) {
11343: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11344: $changes{$prefix}{$type} = 1;
11345: }
11346: }
11347: } else {
11348: if ($inuse == 1) {
11349: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11350: $changes{$prefix}{$type} = 1;
11351: }
11352: }
11353: } else {
11354: if ($inuse == 1) {
11355: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11356: $changes{$prefix}{$type} = 1;
11357: }
11358: }
11359: }
11360: }
11361: }
1.145 raeburn 11362:
11363: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11364: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11365: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11366: my $savespares;
11367:
11368: foreach my $lonhost (sort(keys(%servers))) {
11369: my $serverhomeID =
11370: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11371: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11372: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11373: my %spareschg;
11374: foreach my $type (@{$types{'spares'}}) {
11375: my @okspares;
11376: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
11377: foreach my $server (@checked) {
1.152 raeburn 11378: if (&Apache::lonnet::hostname($server) ne '') {
11379: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
11380: unless (grep(/^\Q$server\E$/,@okspares)) {
11381: push(@okspares,$server);
11382: }
1.145 raeburn 11383: }
11384: }
11385: }
11386: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
11387: my $newspare;
1.152 raeburn 11388: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
11389: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 11390: $newspare = $new;
11391: }
11392: }
1.152 raeburn 11393: my @spares;
11394: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
11395: @spares = sort(@okspares,$newspare);
11396: } else {
11397: @spares = sort(@okspares);
11398: }
11399: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 11400: if (ref($spareid{$lonhost}) eq 'HASH') {
11401: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 11402: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 11403: if (@diffs > 0) {
11404: $spareschg{$type} = 1;
11405: }
11406: }
11407: }
11408: }
11409: if (keys(%spareschg) > 0) {
11410: $changes{'spares'}{$lonhost} = \%spareschg;
11411: }
11412: }
1.160.6.61 raeburn 11413: $defaultshash{'usersessions'}{'offloadnow'} = {};
11414: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
11415: my @okoffload;
11416: if (@offloadnow) {
11417: foreach my $server (@offloadnow) {
11418: if (&Apache::lonnet::hostname($server) ne '') {
11419: unless (grep(/^\Q$server\E$/,@okoffload)) {
11420: push(@okoffload,$server);
11421: }
11422: }
11423: }
11424: if (@okoffload) {
11425: foreach my $lonhost (@okoffload) {
11426: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
11427: }
11428: }
11429: }
1.145 raeburn 11430: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11431: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
11432: if (ref($changes{'spares'}) eq 'HASH') {
11433: if (keys(%{$changes{'spares'}}) > 0) {
11434: $savespares = 1;
11435: }
11436: }
11437: } else {
11438: $savespares = 1;
11439: }
1.160.6.61 raeburn 11440: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
11441: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
11442: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
11443: $changes{'offloadnow'} = 1;
11444: last;
11445: }
11446: }
11447: unless ($changes{'offloadnow'}) {
11448: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
11449: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
11450: $changes{'offloadnow'} = 1;
11451: last;
11452: }
11453: }
11454: }
11455: } elsif (@okoffload) {
11456: $changes{'offloadnow'} = 1;
11457: }
11458: } elsif (@okoffload) {
11459: $changes{'offloadnow'} = 1;
1.145 raeburn 11460: }
1.147 raeburn 11461: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11462: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 11463: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11464: $dom);
11465: if ($putresult eq 'ok') {
11466: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11467: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11468: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11469: }
11470: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11471: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11472: }
1.160.6.61 raeburn 11473: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11474: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11475: }
1.137 raeburn 11476: }
11477: my $cachetime = 24*60*60;
11478: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11479: if (ref($lastactref) eq 'HASH') {
11480: $lastactref->{'domdefaults'} = 1;
11481: }
1.147 raeburn 11482: if (keys(%changes) > 0) {
11483: my %lt = &usersession_titles();
11484: $resulttext = &mt('Changes made:').'<ul>';
11485: foreach my $prefix (@prefixes) {
11486: if (ref($changes{$prefix}) eq 'HASH') {
11487: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11488: if ($prefix eq 'spares') {
11489: if (ref($changes{$prefix}) eq 'HASH') {
11490: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11491: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 11492: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 11493: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11494: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 11495: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11496: foreach my $type (@{$types{$prefix}}) {
11497: if ($changes{$prefix}{$lonhost}{$type}) {
11498: my $offloadto = &mt('None');
11499: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11500: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11501: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11502: }
1.145 raeburn 11503: }
1.147 raeburn 11504: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 11505: }
1.137 raeburn 11506: }
11507: }
1.147 raeburn 11508: $resulttext .= '</li>';
1.137 raeburn 11509: }
11510: }
1.147 raeburn 11511: } else {
11512: foreach my $type (@{$types{$prefix}}) {
11513: if (defined($changes{$prefix}{$type})) {
11514: my $newvalue;
11515: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11516: if (ref($defaultshash{'usersessions'}{$prefix})) {
11517: if ($type eq 'version') {
11518: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11519: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11520: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11521: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11522: }
1.145 raeburn 11523: }
11524: }
11525: }
1.147 raeburn 11526: if ($newvalue eq '') {
11527: if ($type eq 'version') {
11528: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11529: } else {
11530: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11531: }
1.145 raeburn 11532: } else {
1.147 raeburn 11533: if ($type eq 'version') {
11534: $newvalue .= ' '.&mt('(or later)');
11535: }
11536: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11537: }
1.137 raeburn 11538: }
11539: }
11540: }
1.147 raeburn 11541: $resulttext .= '</ul>';
1.137 raeburn 11542: }
11543: }
1.160.6.61 raeburn 11544: if ($changes{'offloadnow'}) {
11545: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11546: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11547: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11548: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11549: $resulttext .= '<li>'.$lonhost.'</li>';
11550: }
11551: $resulttext .= '</ul>';
11552: } else {
11553: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11554: }
11555: } else {
11556: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11557: }
11558: }
1.147 raeburn 11559: $resulttext .= '</ul>';
11560: } else {
11561: $resulttext = $nochgmsg;
1.137 raeburn 11562: }
11563: } else {
11564: $resulttext = '<span class="LC_error">'.
11565: &mt('An error occurred: [_1]',$putresult).'</span>';
11566: }
11567: } else {
1.147 raeburn 11568: $resulttext = $nochgmsg;
1.137 raeburn 11569: }
11570: return $resulttext;
11571: }
11572:
1.150 raeburn 11573: sub modify_loadbalancing {
11574: my ($dom,%domconfig) = @_;
11575: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11576: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11577: my ($othertitle,$usertypes,$types) =
11578: &Apache::loncommon::sorted_inst_types($dom);
11579: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11580: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11581: my @sparestypes = ('primary','default');
11582: my %typetitles = &sparestype_titles();
11583: my $resulttext;
1.160.6.7 raeburn 11584: my (%currbalancer,%currtargets,%currrules,%existing);
11585: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11586: %existing = %{$domconfig{'loadbalancing'}};
11587: }
11588: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11589: \%currtargets,\%currrules);
11590: my ($saveloadbalancing,%defaultshash,%changes);
11591: my ($alltypes,$othertypes,$titles) =
11592: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11593: my %ruletitles = &offloadtype_text();
11594: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11595: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11596: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11597: if ($balancer eq '') {
11598: next;
11599: }
11600: if (!exists($servers{$balancer})) {
11601: if (exists($currbalancer{$balancer})) {
11602: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11603: }
1.160.6.7 raeburn 11604: next;
11605: }
11606: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11607: push(@{$changes{'delete'}},$balancer);
11608: next;
11609: }
11610: if (!exists($currbalancer{$balancer})) {
11611: push(@{$changes{'add'}},$balancer);
11612: }
11613: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11614: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11615: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11616: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11617: $saveloadbalancing = 1;
11618: }
11619: foreach my $sparetype (@sparestypes) {
11620: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11621: my @offloadto;
11622: foreach my $target (@targets) {
11623: if (($servers{$target}) && ($target ne $balancer)) {
11624: if ($sparetype eq 'default') {
11625: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11626: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11627: }
11628: }
1.160.6.7 raeburn 11629: unless(grep(/^\Q$target\E$/,@offloadto)) {
11630: push(@offloadto,$target);
11631: }
1.150 raeburn 11632: }
1.160.6.7 raeburn 11633: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11634: }
11635: }
1.160.6.7 raeburn 11636: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11637: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11638: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11639: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11640: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11641: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11642: }
1.160.6.7 raeburn 11643: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11644: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11645: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11646: }
11647: }
11648: }
11649: } else {
1.160.6.7 raeburn 11650: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11651: foreach my $sparetype (@sparestypes) {
11652: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11653: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11654: $changes{'curr'}{$balancer}{'targets'} = 1;
11655: }
1.150 raeburn 11656: }
11657: }
1.160.6.7 raeburn 11658: }
1.150 raeburn 11659: }
11660: my $ishomedom;
1.160.6.7 raeburn 11661: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11662: $ishomedom = 1;
1.150 raeburn 11663: }
11664: if (ref($alltypes) eq 'ARRAY') {
11665: foreach my $type (@{$alltypes}) {
11666: my $rule;
1.160.6.7 raeburn 11667: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11668: (!$ishomedom)) {
1.160.6.7 raeburn 11669: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11670: }
11671: if ($rule eq 'specific') {
1.160.6.55 raeburn 11672: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11673: if (exists($servers{$specifiedhost})) {
11674: $rule = $specifiedhost;
11675: }
1.150 raeburn 11676: }
1.160.6.7 raeburn 11677: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11678: if (ref($currrules{$balancer}) eq 'HASH') {
11679: if ($rule ne $currrules{$balancer}{$type}) {
11680: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11681: }
11682: } elsif ($rule ne '') {
1.160.6.7 raeburn 11683: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11684: }
11685: }
11686: }
1.160.6.7 raeburn 11687: }
11688: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11689: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11690: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11691: $defaultshash{'loadbalancing'} = {};
11692: }
11693: my $putresult = &Apache::lonnet::put_dom('configuration',
11694: \%defaultshash,$dom);
11695: if ($putresult eq 'ok') {
11696: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11697: my %toupdate;
1.160.6.7 raeburn 11698: if (ref($changes{'delete'}) eq 'ARRAY') {
11699: foreach my $balancer (sort(@{$changes{'delete'}})) {
11700: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11701: $toupdate{$balancer} = 1;
1.150 raeburn 11702: }
1.160.6.7 raeburn 11703: }
11704: if (ref($changes{'add'}) eq 'ARRAY') {
11705: foreach my $balancer (sort(@{$changes{'add'}})) {
11706: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11707: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11708: }
11709: }
11710: if (ref($changes{'curr'}) eq 'HASH') {
11711: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11712: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11713: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11714: if ($changes{'curr'}{$balancer}{'targets'}) {
11715: my %offloadstr;
11716: foreach my $sparetype (@sparestypes) {
11717: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11718: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11719: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11720: }
11721: }
1.150 raeburn 11722: }
1.160.6.7 raeburn 11723: if (keys(%offloadstr) == 0) {
11724: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11725: } else {
1.160.6.7 raeburn 11726: my $showoffload;
11727: foreach my $sparetype (@sparestypes) {
11728: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11729: if (defined($offloadstr{$sparetype})) {
11730: $showoffload .= $offloadstr{$sparetype};
11731: } else {
11732: $showoffload .= &mt('None');
11733: }
11734: $showoffload .= (' 'x3);
11735: }
11736: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11737: }
11738: }
11739: }
1.160.6.7 raeburn 11740: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11741: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11742: foreach my $type (@{$alltypes}) {
11743: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11744: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11745: my $balancetext;
11746: if ($rule eq '') {
11747: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11748: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11749: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11750: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11751: foreach my $sparetype (@sparestypes) {
11752: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11753: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11754: }
11755: }
1.160.6.55 raeburn 11756: foreach my $item (@{$alltypes}) {
11757: next if ($item =~ /^_LC_ipchange/);
11758: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11759: if ($hasrule eq 'homeserver') {
11760: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11761: } else {
11762: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11763: if ($servers{$hasrule}) {
11764: $toupdate{$hasrule} = 1;
11765: }
11766: }
11767: }
11768: }
11769: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11770: $balancetext = $ruletitles{$rule};
11771: } else {
11772: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11773: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11774: if ($receiver) {
11775: $toupdate{$receiver};
11776: }
11777: }
11778: } else {
11779: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11780: }
1.160.6.7 raeburn 11781: } else {
11782: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11783: }
1.160.6.26 raeburn 11784: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11785: }
11786: }
11787: }
11788: }
1.160.6.54 raeburn 11789: if (keys(%toupdate)) {
11790: my %thismachine;
11791: my $updatedhere;
11792: my $cachetime = 60*60*24;
11793: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11794: foreach my $lonhost (keys(%toupdate)) {
11795: if ($thismachine{$lonhost}) {
11796: unless ($updatedhere) {
11797: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11798: $defaultshash{'loadbalancing'},
11799: $cachetime);
11800: $updatedhere = 1;
11801: }
11802: } else {
11803: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11804: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11805: }
11806: }
11807: }
1.150 raeburn 11808: }
1.160.6.7 raeburn 11809: }
11810: if ($resulttext ne '') {
11811: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11812: } else {
11813: $resulttext = $nochgmsg;
11814: }
11815: } else {
1.160.6.7 raeburn 11816: $resulttext = $nochgmsg;
1.150 raeburn 11817: }
11818: } else {
1.160.6.7 raeburn 11819: $resulttext = '<span class="LC_error">'.
11820: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11821: }
11822: } else {
1.160.6.7 raeburn 11823: $resulttext = $nochgmsg;
1.150 raeburn 11824: }
11825: return $resulttext;
11826: }
11827:
1.48 raeburn 11828: sub recurse_check {
11829: my ($chkcats,$categories,$depth,$name) = @_;
11830: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11831: my $chg = 0;
11832: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11833: my $category = $chkcats->[$depth]{$name}[$j];
11834: my $item;
11835: if ($category eq '') {
11836: $chg ++;
11837: } else {
11838: my $deeper = $depth + 1;
11839: $item = &escape($category).':'.&escape($name).':'.$depth;
11840: if ($chg) {
11841: $categories->{$item} -= $chg;
11842: }
11843: &recurse_check($chkcats,$categories,$deeper,$category);
11844: $deeper --;
11845: }
11846: }
11847: }
11848: return;
11849: }
11850:
11851: sub recurse_cat_deletes {
11852: my ($item,$coursecategories,$deletions) = @_;
11853: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11854: my $subdepth = $depth + 1;
11855: if (ref($coursecategories) eq 'HASH') {
11856: foreach my $subitem (keys(%{$coursecategories})) {
11857: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11858: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11859: delete($coursecategories->{$subitem});
11860: $deletions->{$subitem} = 1;
11861: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11862: }
1.48 raeburn 11863: }
11864: }
11865: return;
11866: }
11867:
1.125 raeburn 11868: sub get_active_dcs {
11869: my ($dom) = @_;
1.160.6.16 raeburn 11870: my $now = time;
11871: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11872: my %domcoords;
11873: my $numdcs = 0;
11874: foreach my $server (keys(%dompersonnel)) {
11875: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11876: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11877: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11878: }
11879: }
11880: return %domcoords;
11881: }
11882:
11883: sub active_dc_picker {
1.160.6.16 raeburn 11884: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11885: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11886: my @domcoord = keys(%domcoords);
11887: if (keys(%currhash)) {
11888: foreach my $dc (keys(%currhash)) {
11889: unless (exists($domcoords{$dc})) {
11890: push(@domcoord,$dc);
11891: }
11892: }
11893: }
11894: @domcoord = sort(@domcoord);
11895: my $numdcs = scalar(@domcoord);
11896: my $rows = 0;
11897: my $table;
1.125 raeburn 11898: if ($numdcs > 1) {
1.160.6.16 raeburn 11899: $table = '<table>';
11900: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11901: my $rem = $i%($numinrow);
11902: if ($rem == 0) {
11903: if ($i > 0) {
1.160.6.16 raeburn 11904: $table .= '</tr>';
1.125 raeburn 11905: }
1.160.6.16 raeburn 11906: $table .= '<tr>';
11907: $rows ++;
1.125 raeburn 11908: }
1.160.6.16 raeburn 11909: my $check = '';
11910: if ($inputtype eq 'radio') {
11911: if (keys(%currhash) == 0) {
11912: if (!$i) {
11913: $check = ' checked="checked"';
11914: }
11915: } elsif (exists($currhash{$domcoord[$i]})) {
11916: $check = ' checked="checked"';
11917: }
11918: } else {
11919: if (exists($currhash{$domcoord[$i]})) {
11920: $check = ' checked="checked"';
1.125 raeburn 11921: }
11922: }
1.160.6.16 raeburn 11923: if ($i == @domcoord - 1) {
1.125 raeburn 11924: my $colsleft = $numinrow - $rem;
11925: if ($colsleft > 1) {
1.160.6.16 raeburn 11926: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11927: } else {
1.160.6.16 raeburn 11928: $table .= '<td class="LC_left_item">';
1.125 raeburn 11929: }
11930: } else {
1.160.6.16 raeburn 11931: $table .= '<td class="LC_left_item">';
11932: }
11933: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11934: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11935: $table .= '<span class="LC_nobreak"><label>'.
11936: '<input type="'.$inputtype.'" name="'.$name.'"'.
11937: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11938: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11939: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11940: }
1.160.6.33 raeburn 11941: $table .= '</label></span></td>';
1.125 raeburn 11942: }
1.160.6.16 raeburn 11943: $table .= '</tr></table>';
11944: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11945: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11946: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11947: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11948: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11949: if ($user ne $dcname.':'.$dcdom) {
11950: $table .= ' ('.$dcname.':'.$dcdom.')';
11951: }
1.160.6.16 raeburn 11952: } else {
11953: my $check;
11954: if (exists($currhash{$domcoord[0]})) {
11955: $check = ' checked="checked"';
11956: }
1.160.6.50 raeburn 11957: $table = '<span class="LC_nobreak"><label>'.
11958: '<input type="checkbox" name="'.$name.'" '.
11959: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11960: if ($user ne $dcname.':'.$dcdom) {
11961: $table .= ' ('.$dcname.':'.$dcdom.')';
11962: }
11963: $table .= '</label></span>';
1.160.6.16 raeburn 11964: $rows ++;
11965: }
1.125 raeburn 11966: }
1.160.6.16 raeburn 11967: return ($numdcs,$table,$rows);
1.125 raeburn 11968: }
11969:
1.137 raeburn 11970: sub usersession_titles {
11971: return &Apache::lonlocal::texthash(
11972: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11973: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11974: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11975: version => 'LON-CAPA version requirement',
1.138 raeburn 11976: excludedomain => 'Allow all, but exclude specific domains',
11977: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11978: primary => 'Primary (checked first)',
1.154 raeburn 11979: default => 'Default',
1.137 raeburn 11980: );
11981: }
11982:
1.152 raeburn 11983: sub id_for_thisdom {
11984: my (%servers) = @_;
11985: my %altids;
11986: foreach my $server (keys(%servers)) {
11987: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11988: if ($serverhome ne $server) {
11989: $altids{$serverhome} = $server;
11990: }
11991: }
11992: return %altids;
11993: }
11994:
1.150 raeburn 11995: sub count_servers {
11996: my ($currbalancer,%servers) = @_;
11997: my (@spares,$numspares);
11998: foreach my $lonhost (sort(keys(%servers))) {
11999: next if ($currbalancer eq $lonhost);
12000: push(@spares,$lonhost);
12001: }
12002: if ($currbalancer) {
12003: $numspares = scalar(@spares);
12004: } else {
12005: $numspares = scalar(@spares) - 1;
12006: }
12007: return ($numspares,@spares);
12008: }
12009:
12010: sub lonbalance_targets_js {
1.160.6.7 raeburn 12011: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 12012: my $select = &mt('Select');
12013: my ($alltargets,$allishome,$allinsttypes,@alltypes);
12014: if (ref($servers) eq 'HASH') {
12015: $alltargets = join("','",sort(keys(%{$servers})));
12016: my @homedoms;
12017: foreach my $server (sort(keys(%{$servers}))) {
12018: if (&Apache::lonnet::host_domain($server) eq $dom) {
12019: push(@homedoms,'1');
12020: } else {
12021: push(@homedoms,'0');
12022: }
12023: }
12024: $allishome = join("','",@homedoms);
12025: }
12026: if (ref($types) eq 'ARRAY') {
12027: if (@{$types} > 0) {
12028: @alltypes = @{$types};
12029: }
12030: }
12031: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
12032: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 12033: my (%currbalancer,%currtargets,%currrules,%existing);
12034: if (ref($settings) eq 'HASH') {
12035: %existing = %{$settings};
12036: }
12037: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
12038: \%currtargets,\%currrules);
12039: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 12040: return <<"END";
12041:
12042: <script type="text/javascript">
12043: // <![CDATA[
12044:
1.160.6.7 raeburn 12045: currBalancers = new Array('$balancers');
12046:
12047: function toggleTargets(balnum) {
12048: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12049: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
12050: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
12051: var prevbalancer = prevhostitem.value;
12052: var baltotal = document.getElementById('loadbalancing_total').value;
12053: prevhostitem.value = balancer;
12054: if (prevbalancer != '') {
12055: var prevIdx = currBalancers.indexOf(prevbalancer);
12056: if (prevIdx != -1) {
12057: currBalancers.splice(prevIdx,1);
12058: }
12059: }
1.150 raeburn 12060: if (balancer == '') {
1.160.6.7 raeburn 12061: hideSpares(balnum);
1.150 raeburn 12062: } else {
1.160.6.7 raeburn 12063: var currIdx = currBalancers.indexOf(balancer);
12064: if (currIdx == -1) {
12065: currBalancers.push(balancer);
12066: }
1.150 raeburn 12067: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 12068: var ishomedom = homedoms[lonhostitem.selectedIndex];
12069: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 12070: }
1.160.6.7 raeburn 12071: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 12072: return;
12073: }
12074:
1.160.6.7 raeburn 12075: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 12076: var alltargets = new Array('$alltargets');
12077: var insttypes = new Array('$allinsttypes');
1.151 raeburn 12078: var offloadtypes = new Array('primary','default');
12079:
1.160.6.7 raeburn 12080: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
12081: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 12082:
1.151 raeburn 12083: for (var i=0; i<offloadtypes.length; i++) {
12084: var count = 0;
12085: for (var j=0; j<alltargets.length; j++) {
12086: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 12087: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
12088: item.value = alltargets[j];
12089: item.style.textAlign='left';
12090: item.style.textFace='normal';
12091: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
12092: if (currBalancers.indexOf(alltargets[j]) == -1) {
12093: item.disabled = '';
12094: } else {
12095: item.disabled = 'disabled';
12096: item.checked = false;
12097: }
1.151 raeburn 12098: count ++;
12099: }
1.150 raeburn 12100: }
12101: }
1.151 raeburn 12102: for (var k=0; k<insttypes.length; k++) {
12103: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 12104: if (ishomedom == 1) {
1.160.6.7 raeburn 12105: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12106: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12107: } else {
1.160.6.7 raeburn 12108: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12109: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 12110: }
12111: } else {
1.160.6.7 raeburn 12112: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12113: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12114: }
1.151 raeburn 12115: if ((insttypes[k] != '_LC_external') &&
12116: ((insttypes[k] != '_LC_internetdom') ||
12117: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 12118: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
12119: item.options.length = 0;
12120: item.options[0] = new Option("","",true,true);
12121: var idx = 0;
1.151 raeburn 12122: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 12123: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
12124: idx ++;
12125: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 12126: }
12127: }
12128: }
12129: }
12130: return;
12131: }
12132:
1.160.6.7 raeburn 12133: function hideSpares(balnum) {
1.150 raeburn 12134: var alltargets = new Array('$alltargets');
12135: var insttypes = new Array('$allinsttypes');
12136: var offloadtypes = new Array('primary','default');
12137:
1.160.6.7 raeburn 12138: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
12139: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 12140:
12141: var total = alltargets.length - 1;
12142: for (var i=0; i<offloadtypes; i++) {
12143: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 12144: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
12145: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
12146: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 12147: }
1.150 raeburn 12148: }
12149: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 12150: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12151: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 12152: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 12153: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
12154: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 12155: }
12156: }
12157: return;
12158: }
12159:
1.160.6.7 raeburn 12160: function checkOffloads(item,balnum,type) {
1.150 raeburn 12161: var alltargets = new Array('$alltargets');
12162: var offloadtypes = new Array('primary','default');
12163: if (item.checked) {
12164: var total = alltargets.length - 1;
12165: var other;
12166: if (type == offloadtypes[0]) {
1.151 raeburn 12167: other = offloadtypes[1];
1.150 raeburn 12168: } else {
1.151 raeburn 12169: other = offloadtypes[0];
1.150 raeburn 12170: }
12171: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 12172: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 12173: if (server == item.value) {
1.160.6.7 raeburn 12174: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12175: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 12176: }
12177: }
12178: }
12179: }
12180: return;
12181: }
12182:
1.160.6.7 raeburn 12183: function singleServerToggle(balnum,type) {
12184: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 12185: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 12186: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12187: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12188:
12189: } else {
1.160.6.7 raeburn 12190: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12191: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 12192: }
12193: return;
12194: }
12195:
1.160.6.7 raeburn 12196: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 12197: if (type == '_LC_external') {
1.160.6.26 raeburn 12198: return;
1.150 raeburn 12199: }
1.160.6.7 raeburn 12200: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 12201: for (var i=0; i<typesRules.length; i++) {
12202: if (formname.elements[typesRules[i]].checked) {
12203: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 12204: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12205: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12206: } else {
1.160.6.7 raeburn 12207: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12208: }
12209: }
12210: }
12211: return;
12212: }
12213:
12214: function balancerDeleteChange(balnum) {
12215: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12216: var baltotal = document.getElementById('loadbalancing_total').value;
12217: var addtarget;
12218: var removetarget;
12219: var action = 'delete';
12220: if (document.getElementById('loadbalancing_delete_'+balnum)) {
12221: var lonhost = hostitem.value;
12222: var currIdx = currBalancers.indexOf(lonhost);
12223: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
12224: if (currIdx != -1) {
12225: currBalancers.splice(currIdx,1);
12226: }
12227: addtarget = lonhost;
12228: } else {
12229: if (currIdx == -1) {
12230: currBalancers.push(lonhost);
12231: }
12232: removetarget = lonhost;
12233: action = 'undelete';
12234: }
12235: balancerChange(balnum,baltotal,action,addtarget,removetarget);
12236: }
12237: return;
12238: }
12239:
12240: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
12241: if (baltotal > 1) {
12242: var offloadtypes = new Array('primary','default');
12243: var alltargets = new Array('$alltargets');
12244: var insttypes = new Array('$allinsttypes');
12245: for (var i=0; i<baltotal; i++) {
12246: if (i != balnum) {
12247: for (var j=0; j<offloadtypes.length; j++) {
12248: var total = alltargets.length - 1;
12249: for (var k=0; k<total; k++) {
12250: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
12251: var server = serveritem.value;
12252: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12253: if (server == addtarget) {
12254: serveritem.disabled = '';
12255: }
12256: }
12257: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12258: if (server == removetarget) {
12259: serveritem.disabled = 'disabled';
12260: serveritem.checked = false;
12261: }
12262: }
12263: }
12264: }
12265: for (var j=0; j<insttypes.length; j++) {
12266: if (insttypes[j] != '_LC_external') {
12267: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12268: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12269: var currSel = singleserver.selectedIndex;
12270: var currVal = singleserver.options[currSel].value;
12271: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12272: var numoptions = singleserver.options.length;
12273: var needsnew = 1;
12274: for (var k=0; k<numoptions; k++) {
12275: if (singleserver.options[k] == addtarget) {
12276: needsnew = 0;
12277: break;
12278: }
12279: }
12280: if (needsnew == 1) {
12281: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12282: }
12283: }
12284: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12285: singleserver.options.length = 0;
12286: if ((currVal) && (currVal != removetarget)) {
12287: singleserver.options[0] = new Option("","",false,false);
12288: } else {
12289: singleserver.options[0] = new Option("","",true,true);
12290: }
12291: var idx = 0;
12292: for (var m=0; m<alltargets.length; m++) {
12293: if (currBalancers.indexOf(alltargets[m]) == -1) {
12294: idx ++;
12295: if (currVal == alltargets[m]) {
12296: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12297: } else {
12298: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12299: }
12300: }
12301: }
12302: }
12303: }
12304: }
12305: }
1.150 raeburn 12306: }
12307: }
12308: }
12309: return;
12310: }
12311:
1.152 raeburn 12312: // ]]>
12313: </script>
12314:
12315: END
12316: }
12317:
12318: sub new_spares_js {
12319: my @sparestypes = ('primary','default');
12320: my $types = join("','",@sparestypes);
12321: my $select = &mt('Select');
12322: return <<"END";
12323:
12324: <script type="text/javascript">
12325: // <![CDATA[
12326:
12327: function updateNewSpares(formname,lonhost) {
12328: var types = new Array('$types');
12329: var include = new Array();
12330: var exclude = new Array();
12331: for (var i=0; i<types.length; i++) {
12332: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12333: for (var j=0; j<spareboxes.length; j++) {
12334: if (formname.elements[spareboxes[j]].checked) {
12335: exclude.push(formname.elements[spareboxes[j]].value);
12336: } else {
12337: include.push(formname.elements[spareboxes[j]].value);
12338: }
12339: }
12340: }
12341: for (var i=0; i<types.length; i++) {
12342: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12343: var selIdx = newSpare.selectedIndex;
12344: var currnew = newSpare.options[selIdx].value;
12345: var okSpares = new Array();
12346: for (var j=0; j<newSpare.options.length; j++) {
12347: var possible = newSpare.options[j].value;
12348: if (possible != '') {
12349: if (exclude.indexOf(possible) == -1) {
12350: okSpares.push(possible);
12351: } else {
12352: if (currnew == possible) {
12353: selIdx = 0;
12354: }
12355: }
12356: }
12357: }
12358: for (var k=0; k<include.length; k++) {
12359: if (okSpares.indexOf(include[k]) == -1) {
12360: okSpares.push(include[k]);
12361: }
12362: }
12363: okSpares.sort();
12364: newSpare.options.length = 0;
12365: if (selIdx == 0) {
12366: newSpare.options[0] = new Option("$select","",true,true);
12367: } else {
12368: newSpare.options[0] = new Option("$select","",false,false);
12369: }
12370: for (var m=0; m<okSpares.length; m++) {
12371: var idx = m+1;
12372: var selThis = 0;
12373: if (selIdx != 0) {
12374: if (okSpares[m] == currnew) {
12375: selThis = 1;
12376: }
12377: }
12378: if (selThis == 1) {
12379: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
12380: } else {
12381: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
12382: }
12383: }
12384: }
12385: return;
12386: }
12387:
12388: function checkNewSpares(lonhost,type) {
12389: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
12390: var chosen = newSpare.options[newSpare.selectedIndex].value;
12391: if (chosen != '') {
12392: var othertype;
12393: var othernewSpare;
12394: if (type == 'primary') {
12395: othernewSpare = document.getElementById('newspare_default_'+lonhost);
12396: }
12397: if (type == 'default') {
12398: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
12399: }
12400: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
12401: othernewSpare.selectedIndex = 0;
12402: }
12403: }
12404: return;
12405: }
12406:
12407: // ]]>
12408: </script>
12409:
12410: END
12411:
12412: }
12413:
12414: sub common_domprefs_js {
12415: return <<"END";
12416:
12417: <script type="text/javascript">
12418: // <![CDATA[
12419:
1.150 raeburn 12420: function getIndicesByName(formname,item) {
1.152 raeburn 12421: var group = new Array();
1.150 raeburn 12422: for (var i=0;i<formname.elements.length;i++) {
12423: if (formname.elements[i].name == item) {
1.152 raeburn 12424: group.push(formname.elements[i].id);
1.150 raeburn 12425: }
12426: }
1.152 raeburn 12427: return group;
1.150 raeburn 12428: }
12429:
12430: // ]]>
12431: </script>
12432:
12433: END
1.152 raeburn 12434:
1.150 raeburn 12435: }
12436:
1.160.6.5 raeburn 12437: sub recaptcha_js {
12438: my %lt = &captcha_phrases();
12439: return <<"END";
12440:
12441: <script type="text/javascript">
12442: // <![CDATA[
12443:
12444: function updateCaptcha(caller,context) {
12445: var privitem;
12446: var pubitem;
12447: var privtext;
12448: var pubtext;
1.160.6.69 raeburn 12449: var versionitem;
12450: var versiontext;
1.160.6.5 raeburn 12451: if (document.getElementById(context+'_recaptchapub')) {
12452: pubitem = document.getElementById(context+'_recaptchapub');
12453: } else {
12454: return;
12455: }
12456: if (document.getElementById(context+'_recaptchapriv')) {
12457: privitem = document.getElementById(context+'_recaptchapriv');
12458: } else {
12459: return;
12460: }
12461: if (document.getElementById(context+'_recaptchapubtxt')) {
12462: pubtext = document.getElementById(context+'_recaptchapubtxt');
12463: } else {
12464: return;
12465: }
12466: if (document.getElementById(context+'_recaptchaprivtxt')) {
12467: privtext = document.getElementById(context+'_recaptchaprivtxt');
12468: } else {
12469: return;
12470: }
1.160.6.69 raeburn 12471: if (document.getElementById(context+'_recaptchaversion')) {
12472: versionitem = document.getElementById(context+'_recaptchaversion');
12473: } else {
12474: return;
12475: }
12476: if (document.getElementById(context+'_recaptchavertxt')) {
12477: versiontext = document.getElementById(context+'_recaptchavertxt');
12478: } else {
12479: return;
12480: }
1.160.6.5 raeburn 12481: if (caller.checked) {
12482: if (caller.value == 'recaptcha') {
12483: pubitem.type = 'text';
12484: privitem.type = 'text';
12485: pubitem.size = '40';
12486: privitem.size = '40';
12487: pubtext.innerHTML = "$lt{'pub'}";
12488: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 12489: versionitem.type = 'text';
12490: versionitem.size = '3';
12491: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 12492: } else {
12493: pubitem.type = 'hidden';
12494: privitem.type = 'hidden';
1.160.6.69 raeburn 12495: versionitem.type = 'hidden';
1.160.6.5 raeburn 12496: pubtext.innerHTML = '';
12497: privtext.innerHTML = '';
1.160.6.69 raeburn 12498: versiontext.innerHTML = '';
1.160.6.5 raeburn 12499: }
12500: }
12501: return;
12502: }
12503:
12504: // ]]>
12505: </script>
12506:
12507: END
12508:
12509: }
12510:
1.160.6.40 raeburn 12511: sub toggle_display_js {
1.160.6.16 raeburn 12512: return <<"END";
12513:
12514: <script type="text/javascript">
12515: // <![CDATA[
12516:
1.160.6.40 raeburn 12517: function toggleDisplay(domForm,caller) {
12518: if (document.getElementById(caller)) {
12519: var divitem = document.getElementById(caller);
12520: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 12521: var checkval = 1;
12522: var dispval = 'block';
1.160.6.40 raeburn 12523: if (caller == 'emailoptions') {
12524: optionsElement = domForm.cancreate_email;
12525: }
1.160.6.57 raeburn 12526: if (caller == 'studentsubmission') {
12527: optionsElement = domForm.postsubmit;
12528: }
1.160.6.64 raeburn 12529: if (caller == 'cloneinstcode') {
12530: optionsElement = domForm.canclone;
12531: checkval = 'instcode';
12532: }
1.160.6.40 raeburn 12533: if (optionsElement.length) {
1.160.6.16 raeburn 12534: var currval;
1.160.6.40 raeburn 12535: for (var i=0; i<optionsElement.length; i++) {
12536: if (optionsElement[i].checked) {
12537: currval = optionsElement[i].value;
1.160.6.16 raeburn 12538: }
12539: }
1.160.6.64 raeburn 12540: if (currval == checkval) {
12541: divitem.style.display = dispval;
1.160.6.16 raeburn 12542: } else {
1.160.6.40 raeburn 12543: divitem.style.display = 'none';
1.160.6.16 raeburn 12544: }
12545: }
12546: }
12547: return;
12548: }
12549:
12550: // ]]>
12551: </script>
12552:
12553: END
12554:
12555: }
12556:
1.160.6.5 raeburn 12557: sub captcha_phrases {
12558: return &Apache::lonlocal::texthash (
12559: priv => 'Private key',
12560: pub => 'Public key',
12561: original => 'original (CAPTCHA)',
12562: recaptcha => 'successor (ReCAPTCHA)',
12563: notused => 'unused',
1.160.6.69 raeburn 12564: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 12565: );
12566: }
12567:
1.160.6.24 raeburn 12568: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 12569: my ($dom,$cachekeys) = @_;
12570: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 12571: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12572: my %thismachine;
12573: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 12574: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 12575: if (keys(%servers)) {
1.160.6.24 raeburn 12576: foreach my $server (keys(%servers)) {
12577: next if ($thismachine{$server});
1.160.6.27 raeburn 12578: my @cached;
12579: foreach my $name (@posscached) {
12580: if ($cachekeys->{$name}) {
12581: push(@cached,&escape($name).':'.&escape($dom));
12582: }
12583: }
12584: if (@cached) {
12585: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12586: }
1.160.6.24 raeburn 12587: }
12588: }
12589: return;
12590: }
12591:
1.3 raeburn 12592: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>