Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.68
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.68! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.67 2016/08/05 20:12:25 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 216: 'serverstatuses','requestcourses','coursedefaults',
1.160.6.38 raeburn 217: 'usersessions','loadbalancing','requestauthor',
1.160.6.40 raeburn 218: '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.41 raeburn 223: 'serverstatuses','coursedefaults','selfenrollment',
1.160.6.37 raeburn 224: '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' =>
307: { text => 'Institutional directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 309: header => [{col1 => 'Setting',
310: col2 => 'Value',}],
1.160.6.37 raeburn 311: print => \&print_directorysrch,
312: modify => \&modify_directorysrch,
1.30 raeburn 313: },
314: 'contacts' =>
315: { text => 'Contact Information',
1.67 raeburn 316: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 317: header => [{col1 => 'Setting',
318: col2 => 'Value',}],
1.160.6.37 raeburn 319: print => \&print_contacts,
320: modify => \&modify_contacts,
1.30 raeburn 321: },
322: 'usercreation' =>
323: { text => 'User creation',
1.67 raeburn 324: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 325: header => [{col1 => 'Format rule type',
326: col2 => 'Format rules in force'},
1.34 raeburn 327: {col1 => 'User account creation',
328: col2 => 'Usernames which may be created',},
1.30 raeburn 329: {col1 => 'Context',
1.43 raeburn 330: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 331: print => \&print_usercreation,
332: modify => \&modify_usercreation,
1.30 raeburn 333: },
1.160.6.34 raeburn 334: 'selfcreation' =>
335: { text => 'Users self-creating accounts',
336: help => 'Domain_Configuration_Self_Creation',
337: header => [{col1 => 'Self-creation with institutional username',
338: col2 => 'Enabled?'},
339: {col1 => 'Institutional user type (login/SSO self-creation)',
340: col2 => 'Information user can enter'},
341: {col1 => 'Self-creation with e-mail as username',
342: col2 => 'Settings'}],
1.160.6.37 raeburn 343: print => \&print_selfcreation,
344: modify => \&modify_selfcreation,
1.160.6.34 raeburn 345: },
1.69 raeburn 346: 'usermodification' =>
1.33 raeburn 347: { text => 'User modification',
1.67 raeburn 348: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 349: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 350: col2 => 'User information updatable in author context'},
1.33 raeburn 351: {col1 => 'Target user has role',
1.160.6.35 raeburn 352: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 353: print => \&print_usermodification,
354: modify => \&modify_usermodification,
1.33 raeburn 355: },
1.69 raeburn 356: 'scantron' =>
1.95 www 357: { text => 'Bubblesheet format file',
1.67 raeburn 358: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 359: header => [ {col1 => 'Item',
360: col2 => '',
361: }],
1.160.6.37 raeburn 362: print => \&print_scantron,
363: modify => \&modify_scantron,
1.46 raeburn 364: },
1.86 raeburn 365: 'requestcourses' =>
366: {text => 'Request creation of courses',
367: help => 'Domain_Configuration_Request_Courses',
368: header => [{col1 => 'User affiliation',
1.102 raeburn 369: col2 => 'Availability/Processing of requests',},
370: {col1 => 'Setting',
1.160.6.30 raeburn 371: col2 => 'Value'},
372: {col1 => 'Available textbooks',
1.160.6.39 raeburn 373: col2 => ''},
1.160.6.46 raeburn 374: {col1 => 'Available templates',
375: col2 => ''},
1.160.6.39 raeburn 376: {col1 => 'Validation (not official courses)',
377: col2 => 'Value'},],
1.160.6.37 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.86 raeburn 380: },
1.160.6.5 raeburn 381: 'requestauthor' =>
1.160.6.34 raeburn 382: {text => 'Request Authoring Space',
1.160.6.5 raeburn 383: help => 'Domain_Configuration_Request_Author',
384: header => [{col1 => 'User affiliation',
385: col2 => 'Availability/Processing of requests',},
386: {col1 => 'Setting',
387: col2 => 'Value'}],
1.160.6.37 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.160.6.5 raeburn 390: },
1.69 raeburn 391: 'coursecategories' =>
1.120 raeburn 392: { text => 'Cataloging of courses/communities',
1.67 raeburn 393: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 394: header => [{col1 => 'Catalog type/availability',
395: col2 => '',},
396: {col1 => 'Category settings for standard catalog',
1.57 raeburn 397: col2 => '',},
398: {col1 => 'Categories',
399: col2 => '',
400: }],
1.160.6.37 raeburn 401: print => \&print_coursecategories,
402: modify => \&modify_coursecategories,
1.69 raeburn 403: },
404: 'serverstatuses' =>
1.77 raeburn 405: {text => 'Access to server status pages',
1.69 raeburn 406: help => 'Domain_Configuration_Server_Status',
407: header => [{col1 => 'Status Page',
408: col2 => 'Other named users',
409: col3 => 'Specific IPs',
410: }],
1.160.6.37 raeburn 411: print => \&print_serverstatuses,
412: modify => \&modify_serverstatuses,
1.69 raeburn 413: },
1.160.6.39 raeburn 414: 'coursedefaults' =>
1.160.6.16 raeburn 415: {text => 'Course/Community defaults',
416: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 417: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
418: col2 => 'Value',},
419: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 420: col2 => 'Value',},],
1.160.6.37 raeburn 421: print => \&print_coursedefaults,
422: modify => \&modify_coursedefaults,
423: },
1.160.6.39 raeburn 424: 'selfenrollment' =>
1.160.6.37 raeburn 425: {text => 'Self-enrollment in Course/Community',
426: help => 'Domain_Configuration_Selfenrollment',
427: header => [{col1 => 'Configuration Rights',
428: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
429: {col1 => 'Defaults',
430: col2 => 'Value'},
431: {col1 => 'Self-enrollment validation (optional)',
432: col2 => 'Value'},],
433: print => \&print_selfenrollment,
434: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 435: },
1.141 raeburn 436: 'usersessions' =>
1.145 raeburn 437: {text => 'User session hosting/offloading',
1.137 raeburn 438: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 439: header => [{col1 => 'Domain server',
440: col2 => 'Servers to offload sessions to when busy'},
441: {col1 => 'Hosting of users from other domains',
1.137 raeburn 442: col2 => 'Rules'},
443: {col1 => "Hosting domain's own users elsewhere",
444: col2 => 'Rules'}],
1.160.6.37 raeburn 445: print => \&print_usersessions,
446: modify => \&modify_usersessions,
1.137 raeburn 447: },
1.150 raeburn 448: 'loadbalancing' =>
1.160.6.7 raeburn 449: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 450: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 451: header => [{col1 => 'Balancers',
1.150 raeburn 452: col2 => 'Default destinations',
1.160.6.13 raeburn 453: col3 => 'User affiliation',
1.150 raeburn 454: col4 => 'Overrides'},
455: ],
1.160.6.37 raeburn 456: print => \&print_loadbalancing,
457: modify => \&modify_loadbalancing,
1.150 raeburn 458: },
1.3 raeburn 459: );
1.110 raeburn 460: if (keys(%servers) > 1) {
461: $prefs{'login'} = { text => 'Log-in page options',
462: help => 'Domain_Configuration_Login_Page',
463: header => [{col1 => 'Log-in Service',
464: col2 => 'Server Setting',},
465: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 466: col2 => ''},
467: {col1 => 'Log-in Help',
1.160.6.56 raeburn 468: col2 => 'Value'},
469: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 470: col2 => 'Value'}],
1.160.6.37 raeburn 471: print => \&print_login,
472: modify => \&modify_login,
1.110 raeburn 473: };
474: }
1.160.6.13 raeburn 475:
1.6 raeburn 476: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 477: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 478: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 479: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 480: text=>"Settings to display/modify"});
1.9 raeburn 481: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 482:
1.3 raeburn 483: if ($phase eq 'process') {
1.160.6.27 raeburn 484: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
485: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 486: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 487: $r->rflush();
1.160.6.27 raeburn 488: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 489: }
1.30 raeburn 490: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 491: my $js = &recaptcha_js().
1.160.6.40 raeburn 492: &toggle_display_js();
1.160.6.7 raeburn 493: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 494: my ($othertitle,$usertypes,$types) =
495: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 496: $js .= &lonbalance_targets_js($dom,$types,\%servers,
497: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 498: &new_spares_js().
499: &common_domprefs_js().
500: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 501: }
1.160.6.30 raeburn 502: if (grep(/^requestcourses$/,@actions)) {
503: my $javascript_validations;
504: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
505: $js .= <<END;
506: <script type="text/javascript">
507: $javascript_validations
508: </script>
509: $coursebrowserjs
510: END
511: }
1.150 raeburn 512: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 513: } else {
1.160.6.11 raeburn 514: # check if domconfig user exists for the domain.
515: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 516: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 517: &config_check($dom,$confname,$servadm);
518: unless ($configuserok eq 'ok') {
519: &Apache::lonconfigsettings::print_header($r,$phase,$context);
520: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
521: $confname).
522: '<br />'
523: );
524: if ($switchserver) {
525: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
526: '<br />'.
527: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
528: '<br />'.
529: &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).
530: '<br />'.
531: &mt('To do that now, use the following link: [_1]',$switchserver)
532: );
533: } else {
534: $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.').
535: '<br />'.
536: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
537: );
538: }
539: $r->print(&Apache::loncommon::end_page());
540: return OK;
541: }
1.21 raeburn 542: if (keys(%domconfig) == 0) {
543: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 544: my @ids=&Apache::lonnet::current_machine_ids();
545: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 546: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 547: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 548: my $custom_img_count = 0;
549: foreach my $img (@loginimages) {
550: if ($designhash{$dom.'.login.'.$img} ne '') {
551: $custom_img_count ++;
552: }
553: }
554: foreach my $role (@roles) {
555: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
556: $custom_img_count ++;
557: }
558: }
559: if ($custom_img_count > 0) {
1.94 raeburn 560: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 561: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 562: $r->print(
563: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
564: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
565: &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 />'.
566: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
567: if ($switch_server) {
1.30 raeburn 568: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 569: }
1.91 raeburn 570: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 571: return OK;
572: }
573: }
574: }
1.91 raeburn 575: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 576: }
577: return OK;
578: }
579:
580: sub process_changes {
1.160.6.24 raeburn 581: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 582: my %domconfig;
583: if (ref($values) eq 'HASH') {
584: %domconfig = %{$values};
585: }
1.3 raeburn 586: my $output;
587: if ($action eq 'login') {
1.160.6.24 raeburn 588: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 589: } elsif ($action eq 'rolecolors') {
1.9 raeburn 590: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 591: $lastactref,%domconfig);
1.3 raeburn 592: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 593: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 594: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 595: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 596: } elsif ($action eq 'autoupdate') {
597: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 598: } elsif ($action eq 'autocreate') {
599: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 600: } elsif ($action eq 'directorysrch') {
601: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 602: } elsif ($action eq 'usercreation') {
1.28 raeburn 603: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 604: } elsif ($action eq 'selfcreation') {
605: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 606: } elsif ($action eq 'usermodification') {
607: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 608: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 609: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 610: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 611: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 612: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 613: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 614: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 615: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 616: } elsif ($action eq 'serverstatuses') {
617: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 618: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 619: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 620: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 621: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 622: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 623: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 624: } elsif ($action eq 'selfenrollment') {
625: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 626: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 627: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 628: } elsif ($action eq 'loadbalancing') {
629: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 630: }
631: return $output;
632: }
633:
634: sub print_config_box {
1.9 raeburn 635: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 636: my $rowtotal = 0;
1.49 raeburn 637: my $output;
638: if ($action eq 'coursecategories') {
639: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 640: } elsif ($action eq 'defaults') {
641: $output = &defaults_javascript($settings);
1.91 raeburn 642: }
1.160.6.40 raeburn 643: $output .=
1.30 raeburn 644: '<table class="LC_nested_outer">
1.3 raeburn 645: <tr>
1.66 raeburn 646: <th align="left" valign="middle"><span class="LC_nobreak">'.
647: &mt($item->{text}).' '.
648: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
649: '</tr>';
1.30 raeburn 650: $rowtotal ++;
1.110 raeburn 651: my $numheaders = 1;
652: if (ref($item->{'header'}) eq 'ARRAY') {
653: $numheaders = scalar(@{$item->{'header'}});
654: }
655: if ($numheaders > 1) {
1.64 raeburn 656: my $colspan = '';
1.145 raeburn 657: my $rightcolspan = '';
1.160.6.42 raeburn 658: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.56 raeburn 659: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 660: $colspan = ' colspan="2"';
661: }
1.145 raeburn 662: if ($action eq 'usersessions') {
663: $rightcolspan = ' colspan="3"';
664: }
1.30 raeburn 665: $output .= '
1.3 raeburn 666: <tr>
667: <td>
668: <table class="LC_nested">
669: <tr class="LC_info_row">
1.59 bisitz 670: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 671: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 672: </tr>';
1.69 raeburn 673: $rowtotal ++;
1.160.6.37 raeburn 674: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 675: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.40 raeburn 676: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 677: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 678: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 679: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 680: } elsif ($action eq 'login') {
1.160.6.56 raeburn 681: if ($numheaders == 4) {
1.160.6.5 raeburn 682: $colspan = ' colspan="2"';
683: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
684: } else {
685: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
686: }
1.160.6.37 raeburn 687: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 688: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 689: } elsif ($action eq 'rolecolors') {
1.30 raeburn 690: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 691: }
1.30 raeburn 692: $output .= '
1.6 raeburn 693: </table>
694: </td>
695: </tr>
696: <tr>
697: <td>
698: <table class="LC_nested">
699: <tr class="LC_info_row">
1.160.6.37 raeburn 700: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 701: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 702: </tr>';
703: $rowtotal ++;
1.160.6.37 raeburn 704: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
705: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 706: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
707: if ($action eq 'coursecategories') {
708: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
709: $colspan = ' colspan="2"';
710: } else {
711: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
712: }
713: $output .= '
1.63 raeburn 714: </table>
715: </td>
716: </tr>
717: <tr>
718: <td>
719: <table class="LC_nested">
720: <tr class="LC_info_row">
721: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 722: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 723: </tr>'."\n";
724: if ($action eq 'coursecategories') {
725: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
726: } else {
727: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
728: }
1.63 raeburn 729: $rowtotal ++;
1.160.6.57 raeburn 730: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
731: ($action eq 'defaults')) {
1.160.6.37 raeburn 732: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 733: } elsif ($action eq 'login') {
1.160.6.56 raeburn 734: if ($numheaders == 4) {
1.160.6.5 raeburn 735: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
736: </table>
737: </td>
738: </tr>
739: <tr>
740: <td>
741: <table class="LC_nested">
742: <tr class="LC_info_row">
743: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 744: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 745: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
746: $rowtotal ++;
747: } else {
748: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
749: }
1.160.6.56 raeburn 750: $output .= '
751: </table>
752: </td>
753: </tr>
754: <tr>
755: <td>
756: <table class="LC_nested">
757: <tr class="LC_info_row">';
758: if ($numheaders == 4) {
759: $output .= '
760: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
761: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
762: </tr>';
763: } else {
764: $output .= '
765: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
766: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
767: </tr>';
768: }
769: $rowtotal ++;
770: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 771: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 772: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
773: $rowtotal ++;
774: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
782: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
783: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 784: &textbookcourses_javascript($settings).
785: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
794: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
795: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 796: </table>
797: </td>
798: </tr>
799: <tr>
800: <td>
801: <table class="LC_nested">
802: <tr class="LC_info_row">
1.160.6.46 raeburn 803: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
804: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 805: </tr>'.
806: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 807: } elsif ($action eq 'requestauthor') {
808: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 809: $rowtotal ++;
1.122 jms 810: } elsif ($action eq 'rolecolors') {
1.30 raeburn 811: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.69 raeburn 819: <td class="LC_left_item"'.$colspan.' valign="top">'.
820: &mt($item->{'header'}->[2]->{'col1'}).'</td>
821: <td class="LC_right_item" valign="top">'.
822: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 823: </tr>'.
1.30 raeburn 824: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 825: </table>
826: </td>
827: </tr>
828: <tr>
829: <td>
830: <table class="LC_nested">
831: <tr class="LC_info_row">
1.59 bisitz 832: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
833: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 834: </tr>'.
1.30 raeburn 835: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
836: $rowtotal += 2;
1.6 raeburn 837: }
1.3 raeburn 838: } else {
1.30 raeburn 839: $output .= '
1.3 raeburn 840: <tr>
841: <td>
842: <table class="LC_nested">
1.30 raeburn 843: <tr class="LC_info_row">';
1.24 raeburn 844: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 845: $output .= '
1.59 bisitz 846: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 847: } elsif ($action eq 'serverstatuses') {
848: $output .= '
849: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
850: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
851:
1.6 raeburn 852: } else {
1.30 raeburn 853: $output .= '
1.69 raeburn 854: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
855: }
1.72 raeburn 856: if (defined($item->{'header'}->[0]->{'col3'})) {
857: $output .= '<td class="LC_left_item" valign="top">'.
858: &mt($item->{'header'}->[0]->{'col2'});
859: if ($action eq 'serverstatuses') {
860: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
861: }
1.69 raeburn 862: } else {
863: $output .= '<td class="LC_right_item" valign="top">'.
864: &mt($item->{'header'}->[0]->{'col2'});
865: }
866: $output .= '</td>';
867: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 868: if (defined($item->{'header'}->[0]->{'col4'})) {
869: $output .= '<td class="LC_left_item" valign="top">'.
870: &mt($item->{'header'}->[0]->{'col3'});
871: } else {
872: $output .= '<td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col3'});
874: }
1.69 raeburn 875: if ($action eq 'serverstatuses') {
876: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
877: }
878: $output .= '</td>';
1.6 raeburn 879: }
1.150 raeburn 880: if ($item->{'header'}->[0]->{'col4'}) {
881: $output .= '<td class="LC_right_item" valign="top">'.
882: &mt($item->{'header'}->[0]->{'col4'});
883: }
1.69 raeburn 884: $output .= '</tr>';
1.48 raeburn 885: $rowtotal ++;
1.160.6.5 raeburn 886: if ($action eq 'quotas') {
1.86 raeburn 887: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 888: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 889: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 890: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 891: } elsif ($action eq 'scantron') {
892: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 893: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 894: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 895: }
1.3 raeburn 896: }
1.30 raeburn 897: $output .= '
1.3 raeburn 898: </table>
899: </td>
900: </tr>
1.30 raeburn 901: </table><br />';
902: return ($output,$rowtotal);
1.1 raeburn 903: }
904:
1.3 raeburn 905: sub print_login {
1.160.6.5 raeburn 906: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 907: my ($css_class,$datatable);
1.6 raeburn 908: my %choices = &login_choices();
1.110 raeburn 909:
1.160.6.5 raeburn 910: if ($caller eq 'service') {
1.149 raeburn 911: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 912: my $choice = $choices{'disallowlogin'};
913: $css_class = ' class="LC_odd_row"';
1.128 raeburn 914: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 915: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 916: '<th>'.$choices{'server'}.'</th>'.
917: '<th>'.$choices{'serverpath'}.'</th>'.
918: '<th>'.$choices{'custompath'}.'</th>'.
919: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 920: my %disallowed;
921: if (ref($settings) eq 'HASH') {
922: if (ref($settings->{'loginvia'}) eq 'HASH') {
923: %disallowed = %{$settings->{'loginvia'}};
924: }
925: }
926: foreach my $lonhost (sort(keys(%servers))) {
927: my $direct = 'selected="selected"';
1.128 raeburn 928: if (ref($disallowed{$lonhost}) eq 'HASH') {
929: if ($disallowed{$lonhost}{'server'} ne '') {
930: $direct = '';
931: }
1.110 raeburn 932: }
1.115 raeburn 933: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 934: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 935: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
936: '</option>';
1.160.6.13 raeburn 937: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 938: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 939: my $selected = '';
1.128 raeburn 940: if (ref($disallowed{$lonhost}) eq 'HASH') {
941: if ($hostid eq $disallowed{$lonhost}{'server'}) {
942: $selected = 'selected="selected"';
943: }
1.110 raeburn 944: }
945: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
946: $servers{$hostid}.'</option>';
947: }
1.128 raeburn 948: $datatable .= '</select></td>'.
949: '<td><select name="'.$lonhost.'_serverpath">';
950: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
951: my $pathname = $path;
952: if ($path eq 'custom') {
953: $pathname = &mt('Custom Path').' ->';
954: }
955: my $selected = '';
956: if (ref($disallowed{$lonhost}) eq 'HASH') {
957: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
958: $selected = 'selected="selected"';
959: }
960: } elsif ($path eq '') {
961: $selected = 'selected="selected"';
962: }
963: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
964: }
965: $datatable .= '</select></td>';
966: my ($custom,$exempt);
967: if (ref($disallowed{$lonhost}) eq 'HASH') {
968: $custom = $disallowed{$lonhost}{'custompath'};
969: $exempt = $disallowed{$lonhost}{'exempt'};
970: }
971: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
972: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
973: '</tr>';
1.110 raeburn 974: }
975: $datatable .= '</table></td></tr>';
976: return $datatable;
1.160.6.5 raeburn 977: } elsif ($caller eq 'page') {
978: my %defaultchecked = (
979: 'coursecatalog' => 'on',
1.160.6.14 raeburn 980: 'helpdesk' => 'on',
1.160.6.5 raeburn 981: 'adminmail' => 'off',
982: 'newuser' => 'off',
983: );
1.160.6.14 raeburn 984: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 985: my (%checkedon,%checkedoff);
1.42 raeburn 986: foreach my $item (@toggles) {
1.160.6.5 raeburn 987: if ($defaultchecked{$item} eq 'on') {
988: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 989: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 990: } elsif ($defaultchecked{$item} eq 'off') {
991: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 992: $checkedon{$item} = ' ';
993: }
1.1 raeburn 994: }
1.160.6.5 raeburn 995: my @images = ('img','logo','domlogo','login');
996: my @logintext = ('textcol','bgcol');
997: my @bgs = ('pgbg','mainbg','sidebg');
998: my @links = ('link','alink','vlink');
999: my %designhash = &Apache::loncommon::get_domainconf($dom);
1000: my %defaultdesign = %Apache::loncommon::defaultdesign;
1001: my (%is_custom,%designs);
1002: my %defaults = (
1003: font => $defaultdesign{'login.font'},
1004: );
1.6 raeburn 1005: foreach my $item (@images) {
1.160.6.5 raeburn 1006: $defaults{$item} = $defaultdesign{'login.'.$item};
1007: $defaults{'showlogo'}{$item} = 1;
1008: }
1009: foreach my $item (@bgs) {
1010: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1011: }
1.41 raeburn 1012: foreach my $item (@logintext) {
1.160.6.5 raeburn 1013: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1014: }
1.160.6.5 raeburn 1015: foreach my $item (@links) {
1016: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1017: }
1.160.6.5 raeburn 1018: if (ref($settings) eq 'HASH') {
1019: foreach my $item (@toggles) {
1020: if ($settings->{$item} eq '1') {
1021: $checkedon{$item} = ' checked="checked" ';
1022: $checkedoff{$item} = ' ';
1023: } elsif ($settings->{$item} eq '0') {
1024: $checkedoff{$item} = ' checked="checked" ';
1025: $checkedon{$item} = ' ';
1026: }
1.6 raeburn 1027: }
1.160.6.5 raeburn 1028: foreach my $item (@images) {
1029: if (defined($settings->{$item})) {
1030: $designs{$item} = $settings->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: if (defined($settings->{'showlogo'}{$item})) {
1034: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1035: }
1036: }
1037: foreach my $item (@logintext) {
1038: if ($settings->{$item} ne '') {
1039: $designs{'logintext'}{$item} = $settings->{$item};
1040: $is_custom{$item} = 1;
1041: }
1042: }
1043: if ($settings->{'font'} ne '') {
1044: $designs{'font'} = $settings->{'font'};
1045: $is_custom{'font'} = 1;
1046: }
1047: foreach my $item (@bgs) {
1048: if ($settings->{$item} ne '') {
1049: $designs{'bgs'}{$item} = $settings->{$item};
1050: $is_custom{$item} = 1;
1051: }
1052: }
1053: foreach my $item (@links) {
1054: if ($settings->{$item} ne '') {
1055: $designs{'links'}{$item} = $settings->{$item};
1056: $is_custom{$item} = 1;
1057: }
1058: }
1059: } else {
1060: if ($designhash{$dom.'.login.font'} ne '') {
1061: $designs{'font'} = $designhash{$dom.'.login.font'};
1062: $is_custom{'font'} = 1;
1063: }
1064: foreach my $item (@images) {
1065: if ($designhash{$dom.'.login.'.$item} ne '') {
1066: $designs{$item} = $designhash{$dom.'.login.'.$item};
1067: $is_custom{$item} = 1;
1068: }
1069: }
1070: foreach my $item (@bgs) {
1071: if ($designhash{$dom.'.login.'.$item} ne '') {
1072: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1073: $is_custom{$item} = 1;
1074: }
1075: }
1076: foreach my $item (@links) {
1077: if ($designhash{$dom.'.login.'.$item} ne '') {
1078: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1079: $is_custom{$item} = 1;
1080: }
1.6 raeburn 1081: }
1082: }
1.160.6.5 raeburn 1083: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1084: logo => 'Institution Logo',
1085: domlogo => 'Domain Logo',
1086: login => 'Login box');
1087: my $itemcount = 1;
1088: foreach my $item (@toggles) {
1089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1090: $datatable .=
1091: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1092: '</td><td>'.
1093: '<span class="LC_nobreak"><label><input type="radio" name="'.
1094: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1095: '</label> <label><input type="radio" name="'.$item.'"'.
1096: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1097: '</tr>';
1098: $itemcount ++;
1.6 raeburn 1099: }
1.160.6.5 raeburn 1100: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1101: $datatable .= '</tr></table></td></tr>';
1102: } elsif ($caller eq 'help') {
1103: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1104: my $switchserver = &check_switchserver($dom,$confname);
1105: my $itemcount = 1;
1106: $defaulturl = '/adm/loginproblems.html';
1107: $defaulttype = 'default';
1108: %lt = &Apache::lonlocal::texthash (
1109: del => 'Delete?',
1110: rep => 'Replace:',
1111: upl => 'Upload:',
1112: default => 'Default',
1113: custom => 'Custom',
1114: );
1115: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1116: my @currlangs;
1117: if (ref($settings) eq 'HASH') {
1118: if (ref($settings->{'helpurl'}) eq 'HASH') {
1119: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1120: next if ($settings->{'helpurl'}{$key} eq '');
1121: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1122: $type{$key} = 'custom';
1123: unless ($key eq 'nolang') {
1124: push(@currlangs,$key);
1125: }
1126: }
1127: } elsif ($settings->{'helpurl'} ne '') {
1128: $type{'nolang'} = 'custom';
1129: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1130: }
1131: }
1.160.6.5 raeburn 1132: foreach my $lang ('nolang',sort(@currlangs)) {
1133: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1134: $datatable .= '<tr'.$css_class.'>';
1135: if ($url{$lang} eq '') {
1136: $url{$lang} = $defaulturl;
1137: }
1138: if ($type{$lang} eq '') {
1139: $type{$lang} = $defaulttype;
1140: }
1141: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1142: if ($lang eq 'nolang') {
1143: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1144: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1145: } else {
1146: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1147: $langchoices{$lang},
1148: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1149: }
1150: $datatable .= '</span></td>'."\n".
1151: '<td class="LC_left_item">';
1152: if ($type{$lang} eq 'custom') {
1153: $datatable .= '<span class="LC_nobreak"><label>'.
1154: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1155: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1156: } else {
1157: $datatable .= $lt{'upl'};
1158: }
1159: $datatable .='<br />';
1160: if ($switchserver) {
1161: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1162: } else {
1163: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1164: }
1.160.6.5 raeburn 1165: $datatable .= '</td></tr>';
1166: $itemcount ++;
1.6 raeburn 1167: }
1.160.6.5 raeburn 1168: my @addlangs;
1169: foreach my $lang (sort(keys(%langchoices))) {
1170: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1171: push(@addlangs,$lang);
1172: }
1173: if (@addlangs > 0) {
1174: my %toadd;
1175: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1176: $toadd{''} = &mt('Select');
1177: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1178: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1179: &mt('Add log-in help page for a specific language:').' '.
1180: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1181: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1182: if ($switchserver) {
1183: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1184: } else {
1185: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1186: }
1.160.6.5 raeburn 1187: $datatable .= '</td></tr>';
1188: $itemcount ++;
1.6 raeburn 1189: }
1.160.6.5 raeburn 1190: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1191: } elsif ($caller eq 'headtag') {
1192: my %domservers = &Apache::lonnet::get_servers($dom);
1193: my $choice = $choices{'headtag'};
1194: $css_class = ' class="LC_odd_row"';
1195: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1196: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1197: '<th>'.$choices{'current'}.'</th>'.
1198: '<th>'.$choices{'action'}.'</th>'.
1199: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1200: my (%currurls,%currexempt);
1201: if (ref($settings) eq 'HASH') {
1202: if (ref($settings->{'headtag'}) eq 'HASH') {
1203: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1204: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1205: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1206: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1207: }
1208: }
1209: }
1210: }
1211: my %lt = &Apache::lonlocal::texthash(
1212: del => 'Delete?',
1213: rep => 'Replace:',
1214: upl => 'Upload:',
1215: curr => 'View contents',
1216: none => 'None',
1217: );
1218: my $switchserver = &check_switchserver($dom,$confname);
1219: foreach my $lonhost (sort(keys(%domservers))) {
1220: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1221: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1222: if ($currurls{$lonhost}) {
1223: $datatable .= '<td class="LC_right_item"><a href="'.
1224: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1225: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1226: '">'.$lt{'curr'}.'</a></td>'.
1227: '<td><span class="LC_nobreak"><label>'.
1228: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1229: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1230: } else {
1231: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1232: }
1233: $datatable .='<br />';
1234: if ($switchserver) {
1235: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1236: } else {
1237: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1238: }
1239: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1240: }
1241: $datatable .= '</table></td></tr>';
1.1 raeburn 1242: }
1.6 raeburn 1243: return $datatable;
1244: }
1245:
1246: sub login_choices {
1247: my %choices =
1248: &Apache::lonlocal::texthash (
1.116 bisitz 1249: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1250: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1251: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1252: disallowlogin => "Login page requests redirected",
1253: hostid => "Server",
1.128 raeburn 1254: server => "Redirect to:",
1255: serverpath => "Path",
1256: custompath => "Custom",
1257: exempt => "Exempt IP(s)",
1.110 raeburn 1258: directlogin => "No redirect",
1259: newuser => "Link to create a user account",
1260: img => "Header",
1261: logo => "Main Logo",
1262: domlogo => "Domain Logo",
1263: login => "Log-in Header",
1264: textcol => "Text color",
1265: bgcol => "Box color",
1266: bgs => "Background colors",
1267: links => "Link colors",
1268: font => "Font color",
1269: pgbg => "Header",
1270: mainbg => "Page",
1271: sidebg => "Login box",
1272: link => "Link",
1273: alink => "Active link",
1274: vlink => "Visited link",
1.160.6.56 raeburn 1275: headtag => "Custom markup",
1276: action => "Action",
1277: current => "Current",
1.6 raeburn 1278: );
1279: return %choices;
1280: }
1281:
1282: sub print_rolecolors {
1.30 raeburn 1283: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1284: my %choices = &color_font_choices();
1285: my @bgs = ('pgbg','tabbg','sidebg');
1286: my @links = ('link','alink','vlink');
1287: my @images = ('img');
1288: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1289: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1290: my %defaultdesign = %Apache::loncommon::defaultdesign;
1291: my (%is_custom,%designs);
1.160.6.22 raeburn 1292: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1293: if (ref($settings) eq 'HASH') {
1294: if (ref($settings->{$role}) eq 'HASH') {
1295: if ($settings->{$role}->{'img'} ne '') {
1296: $designs{'img'} = $settings->{$role}->{'img'};
1297: $is_custom{'img'} = 1;
1298: }
1299: if ($settings->{$role}->{'font'} ne '') {
1300: $designs{'font'} = $settings->{$role}->{'font'};
1301: $is_custom{'font'} = 1;
1302: }
1.97 tempelho 1303: if ($settings->{$role}->{'fontmenu'} ne '') {
1304: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1305: $is_custom{'fontmenu'} = 1;
1306: }
1.6 raeburn 1307: foreach my $item (@bgs) {
1308: if ($settings->{$role}->{$item} ne '') {
1309: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1310: $is_custom{$item} = 1;
1311: }
1312: }
1313: foreach my $item (@links) {
1314: if ($settings->{$role}->{$item} ne '') {
1315: $designs{'links'}{$item} = $settings->{$role}->{$item};
1316: $is_custom{$item} = 1;
1317: }
1318: }
1319: }
1320: } else {
1321: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1322: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1323: $is_custom{'img'} = 1;
1324: }
1.97 tempelho 1325: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1326: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1327: $is_custom{'fontmenu'} = 1;
1328: }
1.6 raeburn 1329: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1330: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1331: $is_custom{'font'} = 1;
1332: }
1333: foreach my $item (@bgs) {
1334: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1335: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1336: $is_custom{$item} = 1;
1337:
1338: }
1339: }
1340: foreach my $item (@links) {
1341: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1342: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1343: $is_custom{$item} = 1;
1344: }
1345: }
1346: }
1347: my $itemcount = 1;
1.30 raeburn 1348: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1349: $datatable .= '</tr></table></td></tr>';
1350: return $datatable;
1351: }
1352:
1.160.6.22 raeburn 1353: sub role_defaults {
1354: my ($role,$bgs,$links,$images,$logintext) = @_;
1355: my %defaults;
1356: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1357: return %defaults;
1358: }
1359: my %defaultdesign = %Apache::loncommon::defaultdesign;
1360: if ($role eq 'login') {
1361: %defaults = (
1362: font => $defaultdesign{$role.'.font'},
1363: );
1364: if (ref($logintext) eq 'ARRAY') {
1365: foreach my $item (@{$logintext}) {
1366: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1367: }
1368: }
1369: foreach my $item (@{$images}) {
1370: $defaults{'showlogo'}{$item} = 1;
1371: }
1372: } else {
1373: %defaults = (
1374: img => $defaultdesign{$role.'.img'},
1375: font => $defaultdesign{$role.'.font'},
1376: fontmenu => $defaultdesign{$role.'.fontmenu'},
1377: );
1378: }
1379: foreach my $item (@{$bgs}) {
1380: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1381: }
1382: foreach my $item (@{$links}) {
1383: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1384: }
1385: foreach my $item (@{$images}) {
1386: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1387: }
1388: return %defaults;
1389: }
1390:
1.6 raeburn 1391: sub display_color_options {
1.9 raeburn 1392: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1393: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1394: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1395: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1396: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1397: '<td>'.$choices->{'font'}.'</td>';
1398: if (!$is_custom->{'font'}) {
1.30 raeburn 1399: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1400: } else {
1401: $datatable .= '<td> </td>';
1402: }
1.160.6.9 raeburn 1403: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1404:
1.8 raeburn 1405: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1406: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1407: ' value="'.$current_color.'" /> '.
1408: ' </td></tr>';
1.107 raeburn 1409: unless ($role eq 'login') {
1410: $datatable .= '<tr'.$css_class.'>'.
1411: '<td>'.$choices->{'fontmenu'}.'</td>';
1412: if (!$is_custom->{'fontmenu'}) {
1413: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1414: } else {
1415: $datatable .= '<td> </td>';
1416: }
1.160.6.22 raeburn 1417: $current_color = $designs->{'fontmenu'} ?
1418: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1419: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1420: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1421: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1422: ' value="'.$current_color.'" /> '.
1423: ' </td></tr>';
1.97 tempelho 1424: }
1.9 raeburn 1425: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1426: foreach my $img (@{$images}) {
1.18 albertel 1427: $itemcount ++;
1.6 raeburn 1428: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1429: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1430: '<td>'.$choices->{$img};
1.41 raeburn 1431: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1432: if ($role eq 'login') {
1433: if ($img eq 'login') {
1434: $login_hdr_pick =
1.135 bisitz 1435: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1436: $logincolors =
1437: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1438: $designs,$defaults);
1.70 raeburn 1439: } elsif ($img ne 'domlogo') {
1440: $datatable.= &logo_display_options($img,$defaults,$designs);
1441: }
1442: }
1443: $datatable .= '</td>';
1.6 raeburn 1444: if ($designs->{$img} ne '') {
1445: $imgfile = $designs->{$img};
1.18 albertel 1446: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1447: } else {
1448: $imgfile = $defaults->{$img};
1449: }
1450: if ($imgfile) {
1.9 raeburn 1451: my ($showfile,$fullsize);
1452: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1453: my $urldir = $1;
1454: my $filename = $2;
1455: my @info = &Apache::lonnet::stat_file($designs->{$img});
1456: if (@info) {
1457: my $thumbfile = 'tn-'.$filename;
1458: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1459: if (@thumb) {
1460: $showfile = $urldir.'/'.$thumbfile;
1461: } else {
1462: $showfile = $imgfile;
1463: }
1464: } else {
1465: $showfile = '';
1466: }
1467: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1468: $showfile = $imgfile;
1.6 raeburn 1469: my $imgdir = $1;
1470: my $filename = $2;
1.159 raeburn 1471: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1472: $showfile = "/$imgdir/tn-".$filename;
1473: } else {
1.159 raeburn 1474: my $input = $londocroot.$imgfile;
1475: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1476: if (!-e $output) {
1.9 raeburn 1477: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1478: my ($fullwidth,$fullheight) = &check_dimensions($input);
1479: if ($fullwidth ne '' && $fullheight ne '') {
1480: if ($fullwidth > $width && $fullheight > $height) {
1481: my $size = $width.'x'.$height;
1482: system("convert -sample $size $input $output");
1.159 raeburn 1483: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1484: }
1485: }
1.6 raeburn 1486: }
1487: }
1.16 raeburn 1488: }
1.6 raeburn 1489: if ($showfile) {
1.40 raeburn 1490: if ($showfile =~ m{^/(adm|res)/}) {
1491: if ($showfile =~ m{^/res/}) {
1492: my $local_showfile =
1493: &Apache::lonnet::filelocation('',$showfile);
1494: &Apache::lonnet::repcopy($local_showfile);
1495: }
1496: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1497: }
1498: if ($imgfile) {
1499: if ($imgfile =~ m{^/(adm|res)/}) {
1500: if ($imgfile =~ m{^/res/}) {
1501: my $local_imgfile =
1502: &Apache::lonnet::filelocation('',$imgfile);
1503: &Apache::lonnet::repcopy($local_imgfile);
1504: }
1505: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1506: } else {
1507: $fullsize = $imgfile;
1508: }
1509: }
1.41 raeburn 1510: $datatable .= '<td>';
1511: if ($img eq 'login') {
1.135 bisitz 1512: $datatable .= $login_hdr_pick;
1513: }
1.41 raeburn 1514: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1515: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1516: } else {
1.160.6.22 raeburn 1517: $datatable .= '<td> </td><td class="LC_left_item">'.
1518: &mt('Upload:').'<br />';
1.6 raeburn 1519: }
1520: } else {
1.160.6.22 raeburn 1521: $datatable .= '<td> </td><td class="LC_left_item">'.
1522: &mt('Upload:').'<br />';
1.6 raeburn 1523: }
1.9 raeburn 1524: if ($switchserver) {
1525: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1526: } else {
1.135 bisitz 1527: if ($img ne 'login') { # suppress file selection for Log-in header
1528: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1529: }
1.9 raeburn 1530: }
1531: $datatable .= '</td></tr>';
1.6 raeburn 1532: }
1533: $itemcount ++;
1534: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1535: $datatable .= '<tr'.$css_class.'>'.
1536: '<td>'.$choices->{'bgs'}.'</td>';
1537: my $bgs_def;
1538: foreach my $item (@{$bgs}) {
1539: if (!$is_custom->{$item}) {
1.70 raeburn 1540: $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 1541: }
1542: }
1543: if ($bgs_def) {
1.8 raeburn 1544: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1545: } else {
1546: $datatable .= '<td> </td>';
1547: }
1548: $datatable .= '<td class="LC_right_item">'.
1549: '<table border="0"><tr>';
1.160.6.13 raeburn 1550:
1.6 raeburn 1551: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1552: $datatable .= '<td align="center">'.$choices->{$item};
1553: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1554: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1555: $datatable .= ' ';
1.6 raeburn 1556: }
1.160.6.9 raeburn 1557: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1558: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1559: }
1560: $datatable .= '</tr></table></td></tr>';
1561: $itemcount ++;
1562: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1563: $datatable .= '<tr'.$css_class.'>'.
1564: '<td>'.$choices->{'links'}.'</td>';
1565: my $links_def;
1566: foreach my $item (@{$links}) {
1567: if (!$is_custom->{$item}) {
1.30 raeburn 1568: $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 1569: }
1570: }
1571: if ($links_def) {
1.8 raeburn 1572: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1573: } else {
1574: $datatable .= '<td> </td>';
1575: }
1576: $datatable .= '<td class="LC_right_item">'.
1577: '<table border="0"><tr>';
1578: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1579: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1580: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1581: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1582: $datatable.=' ';
1.6 raeburn 1583: }
1.160.6.9 raeburn 1584: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1585: '" /></td>';
1586: }
1.30 raeburn 1587: $$rowtotal += $itemcount;
1.3 raeburn 1588: return $datatable;
1589: }
1590:
1.70 raeburn 1591: sub logo_display_options {
1592: my ($img,$defaults,$designs) = @_;
1593: my $checkedon;
1594: if (ref($defaults) eq 'HASH') {
1595: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1596: if ($defaults->{'showlogo'}{$img}) {
1597: $checkedon = 'checked="checked" ';
1598: }
1599: }
1600: }
1601: if (ref($designs) eq 'HASH') {
1602: if (ref($designs->{'showlogo'}) eq 'HASH') {
1603: if (defined($designs->{'showlogo'}{$img})) {
1604: if ($designs->{'showlogo'}{$img} == 0) {
1605: $checkedon = '';
1606: } elsif ($designs->{'showlogo'}{$img} == 1) {
1607: $checkedon = 'checked="checked" ';
1608: }
1609: }
1610: }
1611: }
1612: return '<br /><label> <input type="checkbox" name="'.
1613: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1614: &mt('show').'</label>'."\n";
1615: }
1616:
1.41 raeburn 1617: sub login_header_options {
1.135 bisitz 1618: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1619: my $output = '';
1.41 raeburn 1620: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1621: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1622: if (!$is_custom->{'textcol'}) {
1623: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1624: ' ';
1625: }
1626: if (!$is_custom->{'bgcol'}) {
1627: $output .= $choices->{'bgcol'}.': '.
1628: '<span id="css_'.$role.'_font" style="background-color: '.
1629: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1630: }
1631: $output .= '<br />';
1632: }
1633: $output .='<br />';
1634: return $output;
1635: }
1636:
1637: sub login_text_colors {
1.160.6.22 raeburn 1638: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1639: my $color_menu = '<table border="0"><tr>';
1640: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1641: $color_menu .= '<td align="center">'.$choices->{$item};
1642: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1643: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1644: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1645: }
1646: $color_menu .= '</tr></table><br />';
1647: return $color_menu;
1648: }
1649:
1650: sub image_changes {
1651: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1652: my $output;
1.135 bisitz 1653: if ($img eq 'login') {
1654: # suppress image for Log-in header
1655: } elsif (!$is_custom) {
1.70 raeburn 1656: if ($img ne 'domlogo') {
1.41 raeburn 1657: $output .= &mt('Default image:').'<br />';
1658: } else {
1659: $output .= &mt('Default in use:').'<br />';
1660: }
1661: }
1.135 bisitz 1662: if ($img eq 'login') { # suppress image for Log-in header
1663: $output .= '<td>'.$logincolors;
1.41 raeburn 1664: } else {
1.135 bisitz 1665: if ($img_import) {
1666: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1667: }
1668: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1669: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1670: if ($is_custom) {
1671: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1672: '<input type="checkbox" name="'.
1673: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1674: '</label> '.&mt('Replace:').'</span><br />';
1675: } else {
1.160.6.22 raeburn 1676: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1677: }
1.41 raeburn 1678: }
1679: return $output;
1680: }
1681:
1.3 raeburn 1682: sub print_quotas {
1.86 raeburn 1683: my ($dom,$settings,$rowtotal,$action) = @_;
1684: my $context;
1685: if ($action eq 'quotas') {
1686: $context = 'tools';
1687: } else {
1688: $context = $action;
1689: }
1.160.6.20 raeburn 1690: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1691: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1692: my $typecount = 0;
1.101 raeburn 1693: my ($css_class,%titles);
1.86 raeburn 1694: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1695: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1696: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1697: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1698: %titles = &courserequest_titles();
1.160.6.5 raeburn 1699: } elsif ($context eq 'requestauthor') {
1700: @usertools = ('author');
1701: @options = ('norequest','approval','automatic');
1702: %titles = &authorrequest_titles();
1.86 raeburn 1703: } else {
1.160.6.4 raeburn 1704: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1705: %titles = &tool_titles();
1.86 raeburn 1706: }
1.26 raeburn 1707: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1708: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1709: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1710: unless (($context eq 'requestcourses') ||
1711: ($context eq 'requestauthor')) {
1.86 raeburn 1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1714: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1715: } else {
1716: $currdefquota = $settings->{$type};
1717: }
1.160.6.20 raeburn 1718: if (ref($settings->{authorquota}) eq 'HASH') {
1719: $currauthorquota = $settings->{authorquota}->{$type};
1720: }
1.78 raeburn 1721: }
1.72 raeburn 1722: }
1.3 raeburn 1723: if (defined($usertypes->{$type})) {
1724: $typecount ++;
1725: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1726: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1727: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1728: '<td class="LC_left_item">';
1.101 raeburn 1729: if ($context eq 'requestcourses') {
1730: $datatable .= '<table><tr>';
1731: }
1732: my %cell;
1.72 raeburn 1733: foreach my $item (@usertools) {
1.101 raeburn 1734: if ($context eq 'requestcourses') {
1735: my ($curroption,$currlimit);
1736: if (ref($settings) eq 'HASH') {
1737: if (ref($settings->{$item}) eq 'HASH') {
1738: $curroption = $settings->{$item}->{$type};
1739: if ($curroption =~ /^autolimit=(\d*)$/) {
1740: $currlimit = $1;
1741: }
1742: }
1743: }
1744: if (!$curroption) {
1745: $curroption = 'norequest';
1746: }
1747: $datatable .= '<th>'.$titles{$item}.'</th>';
1748: foreach my $option (@options) {
1749: my $val = $option;
1750: if ($option eq 'norequest') {
1751: $val = 0;
1752: }
1753: if ($option eq 'validate') {
1754: my $canvalidate = 0;
1755: if (ref($validations{$item}) eq 'HASH') {
1756: if ($validations{$item}{$type}) {
1757: $canvalidate = 1;
1758: }
1759: }
1760: next if (!$canvalidate);
1761: }
1762: my $checked = '';
1763: if ($option eq $curroption) {
1764: $checked = ' checked="checked"';
1765: } elsif ($option eq 'autolimit') {
1766: if ($curroption =~ /^autolimit/) {
1767: $checked = ' checked="checked"';
1768: }
1769: }
1770: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1771: '<input type="radio" name="crsreq_'.$item.
1772: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1773: $titles{$option}.'</label>';
1.101 raeburn 1774: if ($option eq 'autolimit') {
1.127 raeburn 1775: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1776: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1777: 'value="'.$currlimit.'" />';
1.101 raeburn 1778: }
1.127 raeburn 1779: $cell{$item} .= '</span> ';
1.103 raeburn 1780: if ($option eq 'autolimit') {
1.127 raeburn 1781: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1782: }
1.101 raeburn 1783: }
1.160.6.5 raeburn 1784: } elsif ($context eq 'requestauthor') {
1785: my $curroption;
1786: if (ref($settings) eq 'HASH') {
1787: $curroption = $settings->{$type};
1788: }
1789: if (!$curroption) {
1790: $curroption = 'norequest';
1791: }
1792: foreach my $option (@options) {
1793: my $val = $option;
1794: if ($option eq 'norequest') {
1795: $val = 0;
1796: }
1797: my $checked = '';
1798: if ($option eq $curroption) {
1799: $checked = ' checked="checked"';
1800: }
1801: $datatable .= '<span class="LC_nobreak"><label>'.
1802: '<input type="radio" name="authorreq_'.$type.
1803: '" value="'.$val.'"'.$checked.' />'.
1804: $titles{$option}.'</label></span> ';
1805: }
1.101 raeburn 1806: } else {
1807: my $checked = 'checked="checked" ';
1808: if (ref($settings) eq 'HASH') {
1809: if (ref($settings->{$item}) eq 'HASH') {
1810: if ($settings->{$item}->{$type} == 0) {
1811: $checked = '';
1812: } elsif ($settings->{$item}->{$type} == 1) {
1813: $checked = 'checked="checked" ';
1814: }
1.78 raeburn 1815: }
1.72 raeburn 1816: }
1.101 raeburn 1817: $datatable .= '<span class="LC_nobreak"><label>'.
1818: '<input type="checkbox" name="'.$context.'_'.$item.
1819: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1820: '</label></span> ';
1.72 raeburn 1821: }
1.101 raeburn 1822: }
1823: if ($context eq 'requestcourses') {
1824: $datatable .= '</tr><tr>';
1825: foreach my $item (@usertools) {
1.106 raeburn 1826: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1827: }
1828: $datatable .= '</tr></table>';
1.72 raeburn 1829: }
1.86 raeburn 1830: $datatable .= '</td>';
1.160.6.5 raeburn 1831: unless (($context eq 'requestcourses') ||
1832: ($context eq 'requestauthor')) {
1.86 raeburn 1833: $datatable .=
1.160.6.20 raeburn 1834: '<td class="LC_right_item">'.
1835: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1836: '<input type="text" name="quota_'.$type.
1.72 raeburn 1837: '" value="'.$currdefquota.
1.160.6.20 raeburn 1838: '" size="5" /></span>'.(' ' x 2).
1839: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1840: '<input type="text" name="authorquota_'.$type.
1841: '" value="'.$currauthorquota.
1842: '" size="5" /></span></td>';
1.86 raeburn 1843: }
1844: $datatable .= '</tr>';
1.3 raeburn 1845: }
1846: }
1847: }
1.160.6.5 raeburn 1848: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1849: $defaultquota = '20';
1.160.6.20 raeburn 1850: $authorquota = '500';
1.86 raeburn 1851: if (ref($settings) eq 'HASH') {
1852: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1853: $defaultquota = $settings->{'defaultquota'}->{'default'};
1854: } elsif (defined($settings->{'default'})) {
1855: $defaultquota = $settings->{'default'};
1856: }
1.160.6.20 raeburn 1857: if (ref($settings->{'authorquota'}) eq 'HASH') {
1858: $authorquota = $settings->{'authorquota'}->{'default'};
1859: }
1.3 raeburn 1860: }
1861: }
1862: $typecount ++;
1863: $css_class = $typecount%2?' class="LC_odd_row"':'';
1864: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1865: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1866: '<td class="LC_left_item">';
1.101 raeburn 1867: if ($context eq 'requestcourses') {
1868: $datatable .= '<table><tr>';
1869: }
1870: my %defcell;
1.72 raeburn 1871: foreach my $item (@usertools) {
1.101 raeburn 1872: if ($context eq 'requestcourses') {
1873: my ($curroption,$currlimit);
1874: if (ref($settings) eq 'HASH') {
1875: if (ref($settings->{$item}) eq 'HASH') {
1876: $curroption = $settings->{$item}->{'default'};
1877: if ($curroption =~ /^autolimit=(\d*)$/) {
1878: $currlimit = $1;
1879: }
1880: }
1881: }
1882: if (!$curroption) {
1883: $curroption = 'norequest';
1884: }
1885: $datatable .= '<th>'.$titles{$item}.'</th>';
1886: foreach my $option (@options) {
1887: my $val = $option;
1888: if ($option eq 'norequest') {
1889: $val = 0;
1890: }
1891: if ($option eq 'validate') {
1892: my $canvalidate = 0;
1893: if (ref($validations{$item}) eq 'HASH') {
1894: if ($validations{$item}{'default'}) {
1895: $canvalidate = 1;
1896: }
1897: }
1898: next if (!$canvalidate);
1899: }
1900: my $checked = '';
1901: if ($option eq $curroption) {
1902: $checked = ' checked="checked"';
1903: } elsif ($option eq 'autolimit') {
1904: if ($curroption =~ /^autolimit/) {
1905: $checked = ' checked="checked"';
1906: }
1907: }
1908: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1909: '<input type="radio" name="crsreq_'.$item.
1910: '_default" value="'.$val.'"'.$checked.' />'.
1911: $titles{$option}.'</label>';
1912: if ($option eq 'autolimit') {
1.127 raeburn 1913: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1914: $item.'_limit_default" size="1" '.
1915: 'value="'.$currlimit.'" />';
1916: }
1.127 raeburn 1917: $defcell{$item} .= '</span> ';
1.104 raeburn 1918: if ($option eq 'autolimit') {
1.127 raeburn 1919: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1920: }
1.101 raeburn 1921: }
1.160.6.5 raeburn 1922: } elsif ($context eq 'requestauthor') {
1923: my $curroption;
1924: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1925: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1926: }
1927: if (!$curroption) {
1928: $curroption = 'norequest';
1929: }
1930: foreach my $option (@options) {
1931: my $val = $option;
1932: if ($option eq 'norequest') {
1933: $val = 0;
1934: }
1935: my $checked = '';
1936: if ($option eq $curroption) {
1937: $checked = ' checked="checked"';
1938: }
1939: $datatable .= '<span class="LC_nobreak"><label>'.
1940: '<input type="radio" name="authorreq_default"'.
1941: ' value="'.$val.'"'.$checked.' />'.
1942: $titles{$option}.'</label></span> ';
1943: }
1.101 raeburn 1944: } else {
1945: my $checked = 'checked="checked" ';
1946: if (ref($settings) eq 'HASH') {
1947: if (ref($settings->{$item}) eq 'HASH') {
1948: if ($settings->{$item}->{'default'} == 0) {
1949: $checked = '';
1950: } elsif ($settings->{$item}->{'default'} == 1) {
1951: $checked = 'checked="checked" ';
1952: }
1.78 raeburn 1953: }
1.72 raeburn 1954: }
1.101 raeburn 1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="checkbox" name="'.$context.'_'.$item.
1957: '" value="default" '.$checked.'/>'.$titles{$item}.
1958: '</label></span> ';
1959: }
1960: }
1961: if ($context eq 'requestcourses') {
1962: $datatable .= '</tr><tr>';
1963: foreach my $item (@usertools) {
1.106 raeburn 1964: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1965: }
1.101 raeburn 1966: $datatable .= '</tr></table>';
1.72 raeburn 1967: }
1.86 raeburn 1968: $datatable .= '</td>';
1.160.6.5 raeburn 1969: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1970: $datatable .= '<td class="LC_right_item">'.
1971: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1972: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1973: $defaultquota.'" size="5" /></span>'.(' ' x2).
1974: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1975: '<input type="text" name="authorquota" value="'.
1976: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1977: }
1978: $datatable .= '</tr>';
1.72 raeburn 1979: $typecount ++;
1980: $css_class = $typecount%2?' class="LC_odd_row"':'';
1981: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1982: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1983: if ($context eq 'requestcourses') {
1.109 raeburn 1984: $datatable .= &mt('(overrides affiliation, if set)').
1985: '</td>'.
1986: '<td class="LC_left_item">'.
1987: '<table><tr>';
1.101 raeburn 1988: } else {
1.109 raeburn 1989: $datatable .= &mt('(overrides affiliation, if checked)').
1990: '</td>'.
1991: '<td class="LC_left_item" colspan="2">'.
1992: '<br />';
1.101 raeburn 1993: }
1994: my %advcell;
1.72 raeburn 1995: foreach my $item (@usertools) {
1.101 raeburn 1996: if ($context eq 'requestcourses') {
1997: my ($curroption,$currlimit);
1998: if (ref($settings) eq 'HASH') {
1999: if (ref($settings->{$item}) eq 'HASH') {
2000: $curroption = $settings->{$item}->{'_LC_adv'};
2001: if ($curroption =~ /^autolimit=(\d*)$/) {
2002: $currlimit = $1;
2003: }
2004: }
2005: }
2006: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2007: my $checked = '';
2008: if ($curroption eq '') {
2009: $checked = ' checked="checked"';
2010: }
2011: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2012: '<input type="radio" name="crsreq_'.$item.
2013: '__LC_adv" value=""'.$checked.' />'.
2014: &mt('No override set').'</label></span> ';
1.101 raeburn 2015: foreach my $option (@options) {
2016: my $val = $option;
2017: if ($option eq 'norequest') {
2018: $val = 0;
2019: }
2020: if ($option eq 'validate') {
2021: my $canvalidate = 0;
2022: if (ref($validations{$item}) eq 'HASH') {
2023: if ($validations{$item}{'_LC_adv'}) {
2024: $canvalidate = 1;
2025: }
2026: }
2027: next if (!$canvalidate);
2028: }
2029: my $checked = '';
1.104 raeburn 2030: if ($val eq $curroption) {
1.101 raeburn 2031: $checked = ' checked="checked"';
2032: } elsif ($option eq 'autolimit') {
2033: if ($curroption =~ /^autolimit/) {
2034: $checked = ' checked="checked"';
2035: }
2036: }
2037: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2038: '<input type="radio" name="crsreq_'.$item.
2039: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2040: $titles{$option}.'</label>';
2041: if ($option eq 'autolimit') {
1.127 raeburn 2042: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2043: $item.'_limit__LC_adv" size="1" '.
2044: 'value="'.$currlimit.'" />';
2045: }
1.127 raeburn 2046: $advcell{$item} .= '</span> ';
1.104 raeburn 2047: if ($option eq 'autolimit') {
1.127 raeburn 2048: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2049: }
1.101 raeburn 2050: }
1.160.6.5 raeburn 2051: } elsif ($context eq 'requestauthor') {
2052: my $curroption;
2053: if (ref($settings) eq 'HASH') {
2054: $curroption = $settings->{'_LC_adv'};
2055: }
2056: my $checked = '';
2057: if ($curroption eq '') {
2058: $checked = ' checked="checked"';
2059: }
2060: $datatable .= '<span class="LC_nobreak"><label>'.
2061: '<input type="radio" name="authorreq__LC_adv"'.
2062: ' value=""'.$checked.' />'.
2063: &mt('No override set').'</label></span> ';
2064: foreach my $option (@options) {
2065: my $val = $option;
2066: if ($option eq 'norequest') {
2067: $val = 0;
2068: }
2069: my $checked = '';
2070: if ($val eq $curroption) {
2071: $checked = ' checked="checked"';
2072: }
2073: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2074: '<input type="radio" name="authorreq__LC_adv"'.
2075: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2076: $titles{$option}.'</label></span> ';
2077: }
1.101 raeburn 2078: } else {
2079: my $checked = 'checked="checked" ';
2080: if (ref($settings) eq 'HASH') {
2081: if (ref($settings->{$item}) eq 'HASH') {
2082: if ($settings->{$item}->{'_LC_adv'} == 0) {
2083: $checked = '';
2084: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2085: $checked = 'checked="checked" ';
2086: }
1.79 raeburn 2087: }
1.72 raeburn 2088: }
1.101 raeburn 2089: $datatable .= '<span class="LC_nobreak"><label>'.
2090: '<input type="checkbox" name="'.$context.'_'.$item.
2091: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2092: '</label></span> ';
2093: }
2094: }
2095: if ($context eq 'requestcourses') {
2096: $datatable .= '</tr><tr>';
2097: foreach my $item (@usertools) {
1.106 raeburn 2098: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2099: }
1.101 raeburn 2100: $datatable .= '</tr></table>';
1.72 raeburn 2101: }
1.98 raeburn 2102: $datatable .= '</td></tr>';
1.30 raeburn 2103: $$rowtotal += $typecount;
1.3 raeburn 2104: return $datatable;
2105: }
2106:
1.160.6.5 raeburn 2107: sub print_requestmail {
2108: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2109: my ($now,$datatable,%currapp);
1.102 raeburn 2110: $now = time;
2111: if (ref($settings) eq 'HASH') {
2112: if (ref($settings->{'notify'}) eq 'HASH') {
2113: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2114: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2115: }
2116: }
2117: }
1.160.6.16 raeburn 2118: my $numinrow = 2;
1.160.6.34 raeburn 2119: my $css_class;
2120: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2121: my $text;
2122: if ($action eq 'requestcourses') {
2123: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2124: } elsif ($action eq 'requestauthor') {
2125: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2126: } else {
1.160.6.34 raeburn 2127: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2128: }
1.160.6.34 raeburn 2129: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2130: ' <td>'.$text.'</td>'.
1.102 raeburn 2131: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2132: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2133: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2134: if ($numdc > 0) {
2135: $datatable .= $table;
1.102 raeburn 2136: } else {
2137: $datatable .= &mt('There are no active Domain Coordinators');
2138: }
2139: $datatable .='</td></tr>';
2140: return $datatable;
2141: }
2142:
1.160.6.30 raeburn 2143: sub print_studentcode {
2144: my ($settings,$rowtotal) = @_;
2145: my $rownum = 0;
2146: my ($output,%current);
2147: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2148: if (ref($settings) eq 'HASH') {
2149: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2150: foreach my $type (@crstypes) {
2151: $current{$type} = $settings->{'uniquecode'}{$type};
2152: }
1.160.6.30 raeburn 2153: }
2154: }
2155: $output .= '<tr>'.
2156: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2157: '<td class="LC_left_item">';
2158: foreach my $type (@crstypes) {
2159: my $check = ' ';
2160: if ($current{$type}) {
2161: $check = ' checked="checked" ';
2162: }
2163: $output .= '<span class="LC_nobreak"><label>'.
2164: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2165: &mt($type).'</label></span>'.(' 'x2).' ';
2166: }
2167: $output .= '</td></tr>';
2168: $$rowtotal ++;
2169: return $output;
2170: }
2171:
2172: sub print_textbookcourses {
1.160.6.46 raeburn 2173: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2174: my $rownum = 0;
2175: my $css_class;
2176: my $itemcount = 1;
2177: my $maxnum = 0;
2178: my $bookshash;
2179: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2180: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2181: }
2182: my %ordered;
2183: if (ref($bookshash) eq 'HASH') {
2184: foreach my $item (keys(%{$bookshash})) {
2185: if (ref($bookshash->{$item}) eq 'HASH') {
2186: my $num = $bookshash->{$item}{'order'};
2187: $ordered{$num} = $item;
2188: }
2189: }
2190: }
2191: my $confname = $dom.'-domainconfig';
2192: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2193: my $maxnum = scalar(keys(%ordered));
2194: my $datatable;
1.160.6.30 raeburn 2195: if (keys(%ordered)) {
2196: my @items = sort { $a <=> $b } keys(%ordered);
2197: for (my $i=0; $i<@items; $i++) {
2198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2199: my $key = $ordered{$items[$i]};
2200: my %coursehash=&Apache::lonnet::coursedescription($key);
2201: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2202: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2203: if (ref($bookshash->{$key}) eq 'HASH') {
2204: $subject = $bookshash->{$key}->{'subject'};
2205: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2206: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2207: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2208: $author = $bookshash->{$key}->{'author'};
2209: $image = $bookshash->{$key}->{'image'};
2210: if ($image ne '') {
2211: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2212: my $imagethumb = "$path/tn-".$imagefile;
2213: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2214: }
1.160.6.30 raeburn 2215: }
2216: }
1.160.6.46 raeburn 2217: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2218: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2219: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2220: for (my $k=0; $k<=$maxnum; $k++) {
2221: my $vpos = $k+1;
2222: my $selstr;
2223: if ($k == $i) {
2224: $selstr = ' selected="selected" ';
2225: }
2226: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2227: }
2228: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2229: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2230: &mt('Delete?').'</label></span></td>'.
2231: '<td colspan="2">'.
1.160.6.46 raeburn 2232: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2233: (' 'x2).
1.160.6.46 raeburn 2234: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2235: if ($type eq 'textbooks') {
2236: $datatable .= (' 'x2).
1.160.6.47 raeburn 2237: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2238: (' 'x2).
1.160.6.46 raeburn 2239: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2240: (' 'x2).
2241: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2242: if ($image) {
2243: $datatable .= '<span class="LC_nobreak">'.
2244: $imgsrc.
2245: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2246: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2247: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2248: }
2249: if ($switchserver) {
2250: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2251: } else {
2252: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2253: }
1.160.6.30 raeburn 2254: }
1.160.6.46 raeburn 2255: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2256: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2257: $coursetitle.'</span></td></tr>'."\n";
2258: $itemcount ++;
2259: }
2260: }
2261: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2262: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2263: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2264: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2265: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2266: for (my $k=0; $k<$maxnum+1; $k++) {
2267: my $vpos = $k+1;
2268: my $selstr;
2269: if ($k == $maxnum) {
2270: $selstr = ' selected="selected" ';
2271: }
2272: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2273: }
2274: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2275: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2276: '<td colspan="2">'.
1.160.6.46 raeburn 2277: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2278: (' 'x2).
1.160.6.46 raeburn 2279: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2280: (' 'x2);
2281: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2282: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2283: (' 'x2).
2284: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2285: (' 'x2).
2286: '<span class="LC_nobreak">'.&mt('Image:').' ';
2287: if ($switchserver) {
2288: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2289: } else {
2290: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2291: }
1.160.6.30 raeburn 2292: }
2293: $datatable .= '</span>'."\n".
2294: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2295: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2296: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2297: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2298: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2299: '</span></td>'."\n".
2300: '</tr>'."\n";
2301: $itemcount ++;
2302: return $datatable;
2303: }
2304:
2305: sub textbookcourses_javascript {
1.160.6.46 raeburn 2306: my ($settings) = @_;
2307: return unless(ref($settings) eq 'HASH');
2308: my (%ordered,%total,%jstext);
2309: foreach my $type ('textbooks','templates') {
2310: $total{$type} = 0;
2311: if (ref($settings->{$type}) eq 'HASH') {
2312: foreach my $item (keys(%{$settings->{$type}})) {
2313: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2314: my $num = $settings->{$type}->{$item}{'order'};
2315: $ordered{$type}{$num} = $item;
2316: }
2317: }
2318: $total{$type} = scalar(keys(%{$settings->{$type}}));
2319: }
2320: my @jsarray = ();
2321: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2322: push(@jsarray,$ordered{$type}{$item});
2323: }
2324: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2325: }
2326: return <<"ENDSCRIPT";
2327: <script type="text/javascript">
2328: // <![CDATA[
1.160.6.46 raeburn 2329: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2330: var changedVal;
1.160.6.46 raeburn 2331: $jstext{'textbooks'};
2332: $jstext{'templates'};
2333: var newpos;
2334: var maxh;
2335: if (caller == 'textbooks') {
2336: newpos = 'textbooks_addbook_pos';
2337: maxh = 1 + $total{'textbooks'};
2338: } else {
2339: newpos = 'templates_addbook_pos';
2340: maxh = 1 + $total{'templates'};
2341: }
1.160.6.30 raeburn 2342: var current = new Array;
2343: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2344: if (item == newpos) {
2345: changedVal = newitemVal;
2346: } else {
2347: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2348: current[newitemVal] = newpos;
2349: }
1.160.6.46 raeburn 2350: if (caller == 'textbooks') {
2351: for (var i=0; i<textbooks.length; i++) {
2352: var elementName = 'textbooks_'+textbooks[i];
2353: if (elementName != item) {
2354: if (form.elements[elementName]) {
2355: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2356: current[currVal] = elementName;
2357: }
2358: }
2359: }
2360: }
2361: if (caller == 'templates') {
2362: for (var i=0; i<templates.length; i++) {
2363: var elementName = 'templates_'+templates[i];
2364: if (elementName != item) {
2365: if (form.elements[elementName]) {
2366: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2367: current[currVal] = elementName;
2368: }
1.160.6.30 raeburn 2369: }
2370: }
2371: }
2372: var oldVal;
2373: for (var j=0; j<maxh; j++) {
2374: if (current[j] == undefined) {
2375: oldVal = j;
2376: }
2377: }
2378: if (oldVal < changedVal) {
2379: for (var k=oldVal+1; k<=changedVal ; k++) {
2380: var elementName = current[k];
2381: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2382: }
2383: } else {
2384: for (var k=changedVal; k<oldVal; k++) {
2385: var elementName = current[k];
2386: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2387: }
2388: }
2389: return;
2390: }
2391:
2392: // ]]>
2393: </script>
2394:
2395: ENDSCRIPT
2396: }
2397:
1.3 raeburn 2398: sub print_autoenroll {
1.30 raeburn 2399: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2400: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68! raeburn 2401: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2402: if (ref($settings) eq 'HASH') {
2403: if (exists($settings->{'run'})) {
2404: if ($settings->{'run'} eq '0') {
2405: $runoff = ' checked="checked" ';
2406: $runon = ' ';
2407: } else {
2408: $runon = ' checked="checked" ';
2409: $runoff = ' ';
2410: }
2411: } else {
2412: if ($autorun) {
2413: $runon = ' checked="checked" ';
2414: $runoff = ' ';
2415: } else {
2416: $runoff = ' checked="checked" ';
2417: $runon = ' ';
2418: }
2419: }
1.129 raeburn 2420: if (exists($settings->{'co-owners'})) {
2421: if ($settings->{'co-owners'} eq '0') {
2422: $coownersoff = ' checked="checked" ';
2423: $coownerson = ' ';
2424: } else {
2425: $coownerson = ' checked="checked" ';
2426: $coownersoff = ' ';
2427: }
2428: } else {
2429: $coownersoff = ' checked="checked" ';
2430: $coownerson = ' ';
2431: }
1.3 raeburn 2432: if (exists($settings->{'sender_domain'})) {
2433: $defdom = $settings->{'sender_domain'};
2434: }
1.160.6.68! raeburn 2435: if (exists($settings->{'autofailsafe'})) {
! 2436: $failsafe = $settings->{'autofailsafe'};
! 2437: }
1.14 raeburn 2438: } else {
2439: if ($autorun) {
2440: $runon = ' checked="checked" ';
2441: $runoff = ' ';
2442: } else {
2443: $runoff = ' checked="checked" ';
2444: $runon = ' ';
2445: }
1.3 raeburn 2446: }
2447: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2448: my $notif_sender;
2449: if (ref($settings) eq 'HASH') {
2450: $notif_sender = $settings->{'sender_uname'};
2451: }
1.3 raeburn 2452: my $datatable='<tr class="LC_odd_row">'.
2453: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2454: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2455: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2456: $runon.' value="1" />'.&mt('Yes').'</label> '.
2457: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2458: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2459: '</tr><tr>'.
2460: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2461: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2462: &mt('username').': '.
2463: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2464: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2465: ': '.$domform.'</span></td></tr>'.
2466: '<tr class="LC_odd_row">'.
2467: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2468: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2469: '<input type="radio" name="autoassign_coowners"'.
2470: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2471: '<label><input type="radio" name="autoassign_coowners"'.
2472: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68! raeburn 2473: '</tr><tr>'.
! 2474: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
! 2475: '<td class="LC_right_item"><span class="LC_nobreak">'.
! 2476: '<input type="text" name="autoenroll_failsafe"'.
! 2477: ' value="'.$failsafe.'" size="4" /></td></tr>';
! 2478: $$rowtotal += 4;
1.3 raeburn 2479: return $datatable;
2480: }
2481:
2482: sub print_autoupdate {
1.30 raeburn 2483: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2484: my $datatable;
2485: if ($position eq 'top') {
2486: my $updateon = ' ';
2487: my $updateoff = ' checked="checked" ';
2488: my $classlistson = ' ';
2489: my $classlistsoff = ' checked="checked" ';
2490: if (ref($settings) eq 'HASH') {
2491: if ($settings->{'run'} eq '1') {
2492: $updateon = $updateoff;
2493: $updateoff = ' ';
2494: }
2495: if ($settings->{'classlists'} eq '1') {
2496: $classlistson = $classlistsoff;
2497: $classlistsoff = ' ';
2498: }
2499: }
2500: my %title = (
2501: run => 'Auto-update active?',
2502: classlists => 'Update information in classlists?',
2503: );
2504: $datatable = '<tr class="LC_odd_row">'.
2505: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2506: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2507: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2508: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2509: '<label><input type="radio" name="autoupdate_run"'.
2510: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2511: '</tr><tr>'.
2512: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2513: '<td class="LC_right_item"><span class="LC_nobreak">'.
2514: '<label><input type="radio" name="classlists"'.
2515: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2516: '<label><input type="radio" name="classlists"'.
2517: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2518: '</tr>';
1.30 raeburn 2519: $$rowtotal += 2;
1.131 raeburn 2520: } elsif ($position eq 'middle') {
2521: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2522: my $numinrow = 3;
2523: my $locknamesettings;
2524: $datatable .= &insttypes_row($settings,$types,$usertypes,
2525: $dom,$numinrow,$othertitle,
2526: 'lockablenames');
2527: $$rowtotal ++;
1.3 raeburn 2528: } else {
1.44 raeburn 2529: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2530: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2531: 'permanentemail','id');
1.33 raeburn 2532: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2533: my $numrows = 0;
1.26 raeburn 2534: if (ref($types) eq 'ARRAY') {
2535: if (@{$types} > 0) {
2536: $datatable =
2537: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2538: \@fields,$types,\$numrows);
1.30 raeburn 2539: $$rowtotal += @{$types};
1.26 raeburn 2540: }
1.3 raeburn 2541: }
2542: $datatable .=
2543: &usertype_update_row($settings,{'default' => $othertitle},
2544: \%fieldtitles,\@fields,['default'],
2545: \$numrows);
1.30 raeburn 2546: $$rowtotal ++;
1.3 raeburn 2547: }
2548: return $datatable;
2549: }
2550:
1.125 raeburn 2551: sub print_autocreate {
2552: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2553: my (%createon,%createoff,%currhash);
1.125 raeburn 2554: my @types = ('xml','req');
2555: if (ref($settings) eq 'HASH') {
2556: foreach my $item (@types) {
2557: $createoff{$item} = ' checked="checked" ';
2558: $createon{$item} = ' ';
2559: if (exists($settings->{$item})) {
2560: if ($settings->{$item}) {
2561: $createon{$item} = ' checked="checked" ';
2562: $createoff{$item} = ' ';
2563: }
2564: }
2565: }
1.160.6.16 raeburn 2566: if ($settings->{'xmldc'} ne '') {
2567: $currhash{$settings->{'xmldc'}} = 1;
2568: }
1.125 raeburn 2569: } else {
2570: foreach my $item (@types) {
2571: $createoff{$item} = ' checked="checked" ';
2572: $createon{$item} = ' ';
2573: }
2574: }
2575: $$rowtotal += 2;
1.160.6.16 raeburn 2576: my $numinrow = 2;
1.125 raeburn 2577: my $datatable='<tr class="LC_odd_row">'.
2578: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2579: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2580: '<input type="radio" name="autocreate_xml"'.
2581: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2582: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2583: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2584: '</td></tr><tr>'.
2585: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2586: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2587: '<input type="radio" name="autocreate_req"'.
2588: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2589: '<label><input type="radio" name="autocreate_req"'.
2590: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2591: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2592: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2593: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2594: if ($numdc > 1) {
1.160.6.50 raeburn 2595: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2596: '</td><td class="LC_left_item">';
1.125 raeburn 2597: } else {
1.160.6.50 raeburn 2598: $datatable .= &mt('Course creation processed as:').
2599: '</td><td class="LC_right_item">';
1.125 raeburn 2600: }
1.160.6.50 raeburn 2601: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2602: $$rowtotal += $rows;
1.125 raeburn 2603: return $datatable;
2604: }
2605:
1.23 raeburn 2606: sub print_directorysrch {
1.30 raeburn 2607: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2608: my $srchon = ' ';
2609: my $srchoff = ' checked="checked" ';
1.25 raeburn 2610: my ($exacton,$containson,$beginson);
1.24 raeburn 2611: my $localon = ' ';
2612: my $localoff = ' checked="checked" ';
1.23 raeburn 2613: if (ref($settings) eq 'HASH') {
2614: if ($settings->{'available'} eq '1') {
2615: $srchon = $srchoff;
2616: $srchoff = ' ';
2617: }
1.24 raeburn 2618: if ($settings->{'localonly'} eq '1') {
2619: $localon = $localoff;
2620: $localoff = ' ';
2621: }
1.25 raeburn 2622: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2623: foreach my $type (@{$settings->{'searchtypes'}}) {
2624: if ($type eq 'exact') {
2625: $exacton = ' checked="checked" ';
2626: } elsif ($type eq 'contains') {
2627: $containson = ' checked="checked" ';
2628: } elsif ($type eq 'begins') {
2629: $beginson = ' checked="checked" ';
2630: }
2631: }
2632: } else {
2633: if ($settings->{'searchtypes'} eq 'exact') {
2634: $exacton = ' checked="checked" ';
2635: } elsif ($settings->{'searchtypes'} eq 'contains') {
2636: $containson = ' checked="checked" ';
2637: } elsif ($settings->{'searchtypes'} eq 'specify') {
2638: $exacton = ' checked="checked" ';
2639: $containson = ' checked="checked" ';
2640: }
1.23 raeburn 2641: }
2642: }
2643: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2644: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2645:
2646: my $numinrow = 4;
1.26 raeburn 2647: my $cansrchrow = 0;
1.23 raeburn 2648: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2649: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2650: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2651: '<input type="radio" name="dirsrch_available"'.
2652: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2653: '<label><input type="radio" name="dirsrch_available"'.
2654: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2655: '</tr><tr>'.
1.30 raeburn 2656: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2657: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2658: '<input type="radio" name="dirsrch_localonly"'.
2659: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2660: '<label><input type="radio" name="dirsrch_localonly"'.
2661: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2662: '</tr>';
1.30 raeburn 2663: $$rowtotal += 2;
1.26 raeburn 2664: if (ref($usertypes) eq 'HASH') {
2665: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2666: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2667: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2668: $cansrchrow = 1;
2669: }
2670: }
2671: if ($cansrchrow) {
1.30 raeburn 2672: $$rowtotal ++;
1.26 raeburn 2673: $datatable .= '<tr>';
2674: } else {
2675: $datatable .= '<tr class="LC_odd_row">';
2676: }
1.30 raeburn 2677: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2678: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2679: foreach my $title (@{$titleorder}) {
2680: if (defined($searchtitles->{$title})) {
2681: my $check = ' ';
1.93 raeburn 2682: if (ref($settings) eq 'HASH') {
1.39 raeburn 2683: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2684: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2685: $check = ' checked="checked" ';
2686: }
1.25 raeburn 2687: }
2688: }
2689: $datatable .= '<td class="LC_left_item">'.
2690: '<span class="LC_nobreak"><label>'.
2691: '<input type="checkbox" name="searchby" '.
2692: 'value="'.$title.'"'.$check.'/>'.
2693: $searchtitles->{$title}.'</label></span></td>';
2694: }
2695: }
1.26 raeburn 2696: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2697: $$rowtotal ++;
1.26 raeburn 2698: if ($cansrchrow) {
2699: $datatable .= '<tr class="LC_odd_row">';
2700: } else {
2701: $datatable .= '<tr>';
2702: }
1.30 raeburn 2703: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2704: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2705: '<span class="LC_nobreak"><label>'.
2706: '<input type="checkbox" name="searchtypes" '.
2707: $exacton.' value="exact" />'.&mt('Exact match').
2708: '</label> '.
2709: '<label><input type="checkbox" name="searchtypes" '.
2710: $beginson.' value="begins" />'.&mt('Begins with').
2711: '</label> '.
2712: '<label><input type="checkbox" name="searchtypes" '.
2713: $containson.' value="contains" />'.&mt('Contains').
2714: '</label></span></td></tr>';
1.30 raeburn 2715: $$rowtotal ++;
1.25 raeburn 2716: return $datatable;
2717: }
2718:
1.28 raeburn 2719: sub print_contacts {
1.30 raeburn 2720: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2721: my $datatable;
2722: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2723: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2724: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2725: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2726: foreach my $type (@mailings) {
2727: $otheremails{$type} = '';
2728: }
1.134 raeburn 2729: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2730: if (ref($settings) eq 'HASH') {
2731: foreach my $item (@contacts) {
2732: if (exists($settings->{$item})) {
2733: $to{$item} = $settings->{$item};
2734: }
2735: }
2736: foreach my $type (@mailings) {
2737: if (exists($settings->{$type})) {
2738: if (ref($settings->{$type}) eq 'HASH') {
2739: foreach my $item (@contacts) {
2740: if ($settings->{$type}{$item}) {
2741: $checked{$type}{$item} = ' checked="checked" ';
2742: }
2743: }
2744: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2745: if ($type eq 'helpdeskmail') {
2746: $bccemails{$type} = $settings->{$type}{'bcc'};
2747: }
1.28 raeburn 2748: }
1.89 raeburn 2749: } elsif ($type eq 'lonstatusmail') {
2750: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2751: }
2752: }
2753: } else {
2754: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2755: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2756: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2757: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2758: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2759: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2760: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2761: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2762: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2763: }
2764: my ($titles,$short_titles) = &contact_titles();
2765: my $rownum = 0;
2766: my $css_class;
2767: foreach my $item (@contacts) {
1.69 raeburn 2768: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2769: $datatable .= '<tr'.$css_class.'>'.
2770: '<td><span class="LC_nobreak">'.$titles->{$item}.
2771: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2772: '<input type="text" name="'.$item.'" value="'.
2773: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2774: $rownum ++;
1.28 raeburn 2775: }
2776: foreach my $type (@mailings) {
1.69 raeburn 2777: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2778: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2779: '<td><span class="LC_nobreak">'.
2780: $titles->{$type}.': </span></td>'.
1.28 raeburn 2781: '<td class="LC_left_item">'.
2782: '<span class="LC_nobreak">';
2783: foreach my $item (@contacts) {
2784: $datatable .= '<label>'.
2785: '<input type="checkbox" name="'.$type.'"'.
2786: $checked{$type}{$item}.
2787: ' value="'.$item.'" />'.$short_titles->{$item}.
2788: '</label> ';
2789: }
2790: $datatable .= '</span><br />'.&mt('Others').': '.
2791: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2792: 'value="'.$otheremails{$type}.'" />';
2793: if ($type eq 'helpdeskmail') {
1.136 raeburn 2794: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2795: '<input type="text" name="'.$type.'_bcc" '.
2796: 'value="'.$bccemails{$type}.'" />';
2797: }
2798: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2799: $rownum ++;
1.28 raeburn 2800: }
1.160.6.23 raeburn 2801: my %choices;
2802: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2803: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2804: &mt('LON-CAPA core group - MSU'),600,500));
2805: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2806: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2807: &mt('LON-CAPA core group - MSU'),600,500));
2808: my @toggles = ('reporterrors','reportupdates');
2809: my %defaultchecked = ('reporterrors' => 'on',
2810: 'reportupdates' => 'on');
2811: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2812: \%choices,$rownum);
2813: $datatable .= $reports;
1.30 raeburn 2814: $$rowtotal += $rownum;
1.28 raeburn 2815: return $datatable;
2816: }
2817:
1.118 jms 2818: sub print_helpsettings {
1.160.6.5 raeburn 2819: my ($dom,$confname,$settings,$rowtotal) = @_;
2820: my ($datatable,$itemcount);
2821: $itemcount = 1;
2822: my (%choices,%defaultchecked,@toggles);
2823: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2824: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2825: &mt('LON-CAPA bug tracker'),600,500));
2826: %defaultchecked = ('submitbugs' => 'on');
2827: @toggles = ('submitbugs',);
1.122 jms 2828:
1.160.6.5 raeburn 2829: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2830: \%choices,$itemcount);
2831: return $datatable;
1.121 raeburn 2832: }
2833:
2834: sub radiobutton_prefs {
1.160.6.16 raeburn 2835: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2836: $additional,$align) = @_;
1.121 raeburn 2837: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2838: (ref($choices) eq 'HASH'));
2839:
2840: my (%checkedon,%checkedoff,$datatable,$css_class);
2841:
2842: foreach my $item (@{$toggles}) {
2843: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2844: $checkedon{$item} = ' checked="checked" ';
2845: $checkedoff{$item} = ' ';
1.121 raeburn 2846: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2847: $checkedoff{$item} = ' checked="checked" ';
2848: $checkedon{$item} = ' ';
2849: }
2850: }
2851: if (ref($settings) eq 'HASH') {
1.121 raeburn 2852: foreach my $item (@{$toggles}) {
1.118 jms 2853: if ($settings->{$item} eq '1') {
2854: $checkedon{$item} = ' checked="checked" ';
2855: $checkedoff{$item} = ' ';
2856: } elsif ($settings->{$item} eq '0') {
2857: $checkedoff{$item} = ' checked="checked" ';
2858: $checkedon{$item} = ' ';
2859: }
2860: }
1.121 raeburn 2861: }
1.160.6.16 raeburn 2862: if ($onclick) {
2863: $onclick = ' onclick="'.$onclick.'"';
2864: }
1.121 raeburn 2865: foreach my $item (@{$toggles}) {
1.118 jms 2866: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2867: $datatable .=
1.160.6.16 raeburn 2868: '<tr'.$css_class.'><td valign="top">'.
2869: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 2870: '</span></td>';
2871: if ($align eq 'left') {
2872: $datatable .= '<td class="LC_left_item">';
2873: } else {
2874: $datatable .= '<td class="LC_right_item">';
2875: }
2876: $datatable .=
2877: '<span class="LC_nobreak">'.
1.118 jms 2878: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2879: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2880: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2881: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2882: '</span>'.$additional.
2883: '</td>'.
1.118 jms 2884: '</tr>';
2885: $itemcount ++;
1.121 raeburn 2886: }
2887: return ($datatable,$itemcount);
2888: }
2889:
2890: sub print_coursedefaults {
1.139 raeburn 2891: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2892: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2893: my $itemcount = 1;
1.160.6.16 raeburn 2894: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 2895: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2896: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2897: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 2898: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2899: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2900: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 2901: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.16 raeburn 2902: );
1.160.6.21 raeburn 2903: my %staticdefaults = (
2904: anonsurvey_threshold => 10,
2905: uploadquota => 500,
1.160.6.57 raeburn 2906: postsubmit => 60,
1.160.6.21 raeburn 2907: );
1.139 raeburn 2908: if ($position eq 'top') {
1.160.6.57 raeburn 2909: %defaultchecked = (
2910: 'uselcmath' => 'on',
2911: 'usejsme' => 'on',
1.160.6.64 raeburn 2912: 'canclone' => 'none',
1.160.6.57 raeburn 2913: );
2914: @toggles = ('uselcmath','usejsme');
1.139 raeburn 2915: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 2916: \%choices,$itemcount);
1.160.6.64 raeburn 2917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2918: $datatable .=
2919: '<tr'.$css_class.'><td valign="top">'.
2920: '<span class="LC_nobreak">'.$choices{'canclone'}.
2921: '</span></td><td class="LC_left_item">';
2922: my $currcanclone = 'none';
2923: my $onclick;
2924: my @cloneoptions = ('none','domain');
2925: my %clonetitles = (
2926: none => 'No additional course requesters',
2927: domain => "Any course requester in course's domain",
2928: instcode => 'Course requests for official courses ...',
2929: );
2930: my (%codedefaults,@code_order,@posscodes);
2931: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
2932: \@code_order) eq 'ok') {
2933: if (@code_order > 0) {
2934: push(@cloneoptions,'instcode');
2935: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
2936: }
2937: }
2938: if (ref($settings) eq 'HASH') {
2939: if ($settings->{'canclone'}) {
2940: if (ref($settings->{'canclone'}) eq 'HASH') {
2941: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
2942: if (@code_order > 0) {
2943: $currcanclone = 'instcode';
2944: @posscodes = @{$settings->{'canclone'}{'instcode'}};
2945: }
2946: }
2947: } elsif ($settings->{'canclone'} eq 'domain') {
2948: $currcanclone = $settings->{'canclone'};
2949: }
2950: }
2951: }
2952: foreach my $option (@cloneoptions) {
2953: my ($checked,$additional);
2954: if ($currcanclone eq $option) {
2955: $checked = ' checked="checked"';
2956: }
2957: if ($option eq 'instcode') {
2958: if (@code_order) {
2959: my $show = 'none';
2960: if ($checked) {
2961: $show = 'block';
2962: }
2963: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
2964: &mt('Institutional codes for new and cloned course have identical:').
2965: '<br />';
2966: foreach my $item (@code_order) {
2967: my $codechk;
2968: if ($checked) {
2969: if (grep(/^\Q$item\E$/,@posscodes)) {
2970: $codechk = ' checked="checked"';
2971: }
2972: }
2973: $additional .= '<label>'.
2974: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
2975: $item.'</label>';
2976: }
2977: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
2978: }
2979: }
2980: $datatable .=
2981: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
2982: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
2983: '</label> '.$additional.'</span><br />';
2984: }
2985: $datatable .= '</td>'.
2986: '</tr>';
2987: $itemcount ++;
1.139 raeburn 2988: } else {
2989: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.57 raeburn 2990: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.160.6.16 raeburn 2991: my $currusecredits = 0;
1.160.6.57 raeburn 2992: my $postsubmitclient = 1;
1.160.6.30 raeburn 2993: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2994: if (ref($settings) eq 'HASH') {
2995: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2996: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2997: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2998: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2999: }
3000: }
1.160.6.16 raeburn 3001: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3002: foreach my $type (@types) {
3003: next if ($type eq 'community');
3004: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3005: if ($defcredits{$type} ne '') {
3006: $currusecredits = 1;
3007: }
3008: }
3009: }
3010: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3011: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3012: $postsubmitclient = 0;
3013: foreach my $type (@types) {
3014: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3015: }
3016: } else {
3017: foreach my $type (@types) {
3018: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3019: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3020: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3021: } else {
3022: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3023: }
3024: } else {
3025: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3026: }
3027: }
3028: }
3029: } else {
3030: foreach my $type (@types) {
3031: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3032: }
3033: }
1.160.6.58 raeburn 3034: } else {
3035: foreach my $type (@types) {
3036: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3037: }
1.139 raeburn 3038: }
3039: if (!$currdefresponder) {
1.160.6.21 raeburn 3040: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3041: } elsif ($currdefresponder < 1) {
3042: $currdefresponder = 1;
3043: }
1.160.6.21 raeburn 3044: foreach my $type (@types) {
3045: if ($curruploadquota{$type} eq '') {
3046: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3047: }
3048: }
1.139 raeburn 3049: $datatable .=
1.160.6.16 raeburn 3050: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3051: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3052: '</span></td>'.
3053: '<td class="LC_right_item"><span class="LC_nobreak">'.
3054: '<input type="text" name="anonsurvey_threshold"'.
3055: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3056: '</td></tr>'."\n";
3057: $itemcount ++;
3058: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3059: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3060: $choices{'uploadquota'}.
3061: '</span></td>'.
3062: '<td align="right" class="LC_right_item">'.
3063: '<table><tr>';
1.160.6.21 raeburn 3064: foreach my $type (@types) {
3065: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3066: '<input type="text" name="uploadquota_'.$type.'"'.
3067: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3068: }
3069: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3070: $itemcount ++;
1.160.6.40 raeburn 3071: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3072: my $display = 'none';
3073: if ($currusecredits) {
3074: $display = 'block';
3075: }
3076: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3077: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3078: foreach my $type (@types) {
3079: next if ($type eq 'community');
3080: $additional .= '<td align="center">'.&mt($type).'<br />'.
3081: '<input type="text" name="'.$type.'_credits"'.
3082: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3083: }
3084: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3085: %defaultchecked = ('coursecredits' => 'off');
3086: @toggles = ('coursecredits');
3087: my $current = {
3088: 'coursecredits' => $currusecredits,
3089: };
3090: (my $table,$itemcount) =
3091: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3092: \%choices,$itemcount,$onclick,$additional,'left');
3093: $datatable .= $table;
3094: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3095: my $display = 'none';
3096: if ($postsubmitclient) {
3097: $display = 'block';
3098: }
3099: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3100: &mt('Number of seconds submit is disabled').'<br />'.
3101: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3102: '<table><tr>';
1.160.6.57 raeburn 3103: foreach my $type (@types) {
3104: $additional .= '<td align="center">'.&mt($type).'<br />'.
3105: '<input type="text" name="'.$type.'_timeout" value="'.
3106: $deftimeout{$type}.'" size="5" /></td>';
3107: }
3108: $additional .= '</tr></table></div>'."\n";
3109: %defaultchecked = ('postsubmit' => 'on');
3110: @toggles = ('postsubmit');
3111: my $current = {
3112: 'postsubmit' => $postsubmitclient,
3113: };
3114: ($table,$itemcount) =
3115: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3116: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3117: $datatable .= $table;
1.160.6.37 raeburn 3118: }
3119: $$rowtotal += $itemcount;
3120: return $datatable;
3121: }
3122:
3123: sub print_selfenrollment {
3124: my ($position,$dom,$settings,$rowtotal) = @_;
3125: my ($css_class,$datatable);
3126: my $itemcount = 1;
3127: my @types = ('official','unofficial','community','textbook');
3128: if (($position eq 'top') || ($position eq 'middle')) {
3129: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3130: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3131: my @rows;
3132: my $key;
3133: if ($position eq 'top') {
3134: $key = 'admin';
3135: if (ref($rowsref) eq 'ARRAY') {
3136: @rows = @{$rowsref};
3137: }
3138: } elsif ($position eq 'middle') {
3139: $key = 'default';
3140: @rows = ('types','registered','approval','limit');
3141: }
3142: foreach my $row (@rows) {
3143: if (defined($titlesref->{$row})) {
3144: $itemcount ++;
3145: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3146: $datatable .= '<tr'.$css_class.'>'.
3147: '<td>'.$titlesref->{$row}.'</td>'.
3148: '<td class="LC_left_item">'.
3149: '<table><tr>';
3150: my (%current,%currentcap);
3151: if (ref($settings) eq 'HASH') {
3152: if (ref($settings->{$key}) eq 'HASH') {
3153: foreach my $type (@types) {
3154: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3155: $current{$type} = $settings->{$key}->{$type}->{$row};
3156: }
3157: if (($row eq 'limit') && ($key eq 'default')) {
3158: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3159: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3160: }
3161: }
3162: }
3163: }
3164: }
3165: my %roles = (
3166: '0' => &Apache::lonnet::plaintext('dc'),
3167: );
3168:
3169: foreach my $type (@types) {
3170: unless (($row eq 'registered') && ($key eq 'default')) {
3171: $datatable .= '<th>'.&mt($type).'</th>';
3172: }
3173: }
3174: unless (($row eq 'registered') && ($key eq 'default')) {
3175: $datatable .= '</tr><tr>';
3176: }
3177: foreach my $type (@types) {
3178: if ($type eq 'community') {
3179: $roles{'1'} = &mt('Community personnel');
3180: } else {
3181: $roles{'1'} = &mt('Course personnel');
3182: }
3183: $datatable .= '<td style="vertical-align: top">';
3184: if ($position eq 'top') {
3185: my %checked;
3186: if ($current{$type} eq '0') {
3187: $checked{'0'} = ' checked="checked"';
3188: } else {
3189: $checked{'1'} = ' checked="checked"';
3190: }
3191: foreach my $role ('1','0') {
3192: $datatable .= '<span class="LC_nobreak"><label>'.
3193: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3194: 'value="'.$role.'"'.$checked{$role}.' />'.
3195: $roles{$role}.'</label></span> ';
3196: }
3197: } else {
3198: if ($row eq 'types') {
3199: my %checked;
3200: if ($current{$type} =~ /^(all|dom)$/) {
3201: $checked{$1} = ' checked="checked"';
3202: } else {
3203: $checked{''} = ' checked="checked"';
3204: }
3205: foreach my $val ('','dom','all') {
3206: $datatable .= '<span class="LC_nobreak"><label>'.
3207: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3208: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3209: }
3210: } elsif ($row eq 'registered') {
3211: my %checked;
3212: if ($current{$type} eq '1') {
3213: $checked{'1'} = ' checked="checked"';
3214: } else {
3215: $checked{'0'} = ' checked="checked"';
3216: }
3217: foreach my $val ('0','1') {
3218: $datatable .= '<span class="LC_nobreak"><label>'.
3219: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3220: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3221: }
3222: } elsif ($row eq 'approval') {
3223: my %checked;
3224: if ($current{$type} =~ /^([12])$/) {
3225: $checked{$1} = ' checked="checked"';
3226: } else {
3227: $checked{'0'} = ' checked="checked"';
3228: }
3229: for my $val (0..2) {
3230: $datatable .= '<span class="LC_nobreak"><label>'.
3231: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3232: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3233: }
3234: } elsif ($row eq 'limit') {
3235: my %checked;
3236: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3237: $checked{$1} = ' checked="checked"';
3238: } else {
3239: $checked{'none'} = ' checked="checked"';
3240: }
3241: my $cap;
3242: if ($currentcap{$type} =~ /^\d+$/) {
3243: $cap = $currentcap{$type};
3244: }
3245: foreach my $val ('none','allstudents','selfenrolled') {
3246: $datatable .= '<span class="LC_nobreak"><label>'.
3247: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3248: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3249: }
3250: $datatable .= '<br />'.
3251: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3252: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3253: '</span>';
3254: }
3255: }
3256: $datatable .= '</td>';
3257: }
3258: $datatable .= '</tr>';
3259: }
3260: $datatable .= '</table></td></tr>';
3261: }
3262: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3263: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3264: }
3265: $$rowtotal += $itemcount;
3266: return $datatable;
3267: }
3268:
3269: sub print_validation_rows {
3270: my ($caller,$dom,$settings,$rowtotal) = @_;
3271: my ($itemsref,$namesref,$fieldsref);
3272: if ($caller eq 'selfenroll') {
3273: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3274: } elsif ($caller eq 'requestcourses') {
3275: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3276: }
3277: my %currvalidation;
3278: if (ref($settings) eq 'HASH') {
3279: if (ref($settings->{'validation'}) eq 'HASH') {
3280: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3281: }
1.160.6.39 raeburn 3282: }
3283: my $datatable;
3284: my $itemcount = 0;
3285: foreach my $item (@{$itemsref}) {
3286: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3287: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3288: $namesref->{$item}.
3289: '</span></td>'.
3290: '<td class="LC_left_item">';
3291: if (($item eq 'url') || ($item eq 'button')) {
3292: $datatable .= '<span class="LC_nobreak">'.
3293: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3294: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3295: } elsif ($item eq 'fields') {
3296: my @currfields;
3297: if (ref($currvalidation{$item}) eq 'ARRAY') {
3298: @currfields = @{$currvalidation{$item}};
3299: }
3300: foreach my $field (@{$fieldsref}) {
3301: my $check = '';
3302: if (grep(/^\Q$field\E$/,@currfields)) {
3303: $check = ' checked="checked"';
3304: }
3305: $datatable .= '<span class="LC_nobreak"><label>'.
3306: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3307: ' value="'.$field.'"'.$check.' />'.$field.
3308: '</label></span> ';
3309: }
3310: } elsif ($item eq 'markup') {
3311: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3312: $currvalidation{$item}.
1.160.6.37 raeburn 3313: '</textarea>';
1.160.6.39 raeburn 3314: }
3315: $datatable .= '</td></tr>'."\n";
3316: if (ref($rowtotal)) {
1.160.6.37 raeburn 3317: $itemcount ++;
3318: }
1.139 raeburn 3319: }
1.160.6.39 raeburn 3320: if ($caller eq 'requestcourses') {
3321: my %currhash;
1.160.6.51 raeburn 3322: if (ref($settings) eq 'HASH') {
3323: if (ref($settings->{'validation'}) eq 'HASH') {
3324: if ($settings->{'validation'}{'dc'} ne '') {
3325: $currhash{$settings->{'validation'}{'dc'}} = 1;
3326: }
1.160.6.39 raeburn 3327: }
3328: }
3329: my $numinrow = 2;
3330: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3331: 'validationdc',%currhash);
1.160.6.50 raeburn 3332: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3333: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3334: if ($numdc > 1) {
1.160.6.50 raeburn 3335: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3336: } else {
1.160.6.50 raeburn 3337: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3338: }
1.160.6.50 raeburn 3339: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3340: $itemcount ++;
3341: }
3342: if (ref($rowtotal)) {
3343: $$rowtotal += $itemcount;
3344: }
1.121 raeburn 3345: return $datatable;
1.118 jms 3346: }
3347:
1.137 raeburn 3348: sub print_usersessions {
3349: my ($position,$dom,$settings,$rowtotal) = @_;
3350: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3351: my (%by_ip,%by_location,@intdoms);
3352: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3353:
3354: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3355: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3356: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3357: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3358: my $itemcount = 1;
3359: if ($position eq 'top') {
1.152 raeburn 3360: if (keys(%serverhomes) > 1) {
1.145 raeburn 3361: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3362: my $curroffloadnow;
3363: if (ref($settings) eq 'HASH') {
3364: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3365: $curroffloadnow = $settings->{'offloadnow'};
3366: }
3367: }
3368: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3369: } else {
1.140 raeburn 3370: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3371: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3372: }
1.137 raeburn 3373: } else {
1.145 raeburn 3374: if (keys(%by_location) == 0) {
3375: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3376: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3377: } else {
3378: my %lt = &usersession_titles();
3379: my $numinrow = 5;
3380: my $prefix;
3381: my @types;
3382: if ($position eq 'bottom') {
3383: $prefix = 'remote';
3384: @types = ('version','excludedomain','includedomain');
3385: } else {
3386: $prefix = 'hosted';
3387: @types = ('excludedomain','includedomain');
3388: }
3389: my (%current,%checkedon,%checkedoff);
3390: my @lcversions = &Apache::lonnet::all_loncaparevs();
3391: my @locations = sort(keys(%by_location));
3392: foreach my $type (@types) {
3393: $checkedon{$type} = '';
3394: $checkedoff{$type} = ' checked="checked"';
3395: }
3396: if (ref($settings) eq 'HASH') {
3397: if (ref($settings->{$prefix}) eq 'HASH') {
3398: foreach my $key (keys(%{$settings->{$prefix}})) {
3399: $current{$key} = $settings->{$prefix}{$key};
3400: if ($key eq 'version') {
3401: if ($current{$key} ne '') {
3402: $checkedon{$key} = ' checked="checked"';
3403: $checkedoff{$key} = '';
3404: }
3405: } elsif (ref($current{$key}) eq 'ARRAY') {
3406: $checkedon{$key} = ' checked="checked"';
3407: $checkedoff{$key} = '';
3408: }
1.137 raeburn 3409: }
3410: }
3411: }
1.145 raeburn 3412: foreach my $type (@types) {
3413: next if ($type ne 'version' && !@locations);
3414: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3415: $datatable .= '<tr'.$css_class.'>
3416: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3417: <span class="LC_nobreak">
3418: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3419: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3420: if ($type eq 'version') {
3421: my $selector = '<select name="'.$prefix.'_version">';
3422: foreach my $version (@lcversions) {
3423: my $selected = '';
3424: if ($current{'version'} eq $version) {
3425: $selected = ' selected="selected"';
3426: }
3427: $selector .= ' <option value="'.$version.'"'.
3428: $selected.'>'.$version.'</option>';
3429: }
3430: $selector .= '</select> ';
3431: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3432: } else {
3433: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3434: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3435: ' />'.(' 'x2).
3436: '<input type="button" value="'.&mt('uncheck all').'" '.
3437: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3438: "\n".
3439: '</div><div><table>';
3440: my $rem;
3441: for (my $i=0; $i<@locations; $i++) {
3442: my ($showloc,$value,$checkedtype);
3443: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3444: my $ip = $by_location{$locations[$i]}->[0];
3445: if (ref($by_ip{$ip}) eq 'ARRAY') {
3446: $value = join(':',@{$by_ip{$ip}});
3447: $showloc = join(', ',@{$by_ip{$ip}});
3448: if (ref($current{$type}) eq 'ARRAY') {
3449: foreach my $loc (@{$by_ip{$ip}}) {
3450: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3451: $checkedtype = ' checked="checked"';
3452: last;
3453: }
3454: }
1.138 raeburn 3455: }
3456: }
3457: }
1.145 raeburn 3458: $rem = $i%($numinrow);
3459: if ($rem == 0) {
3460: if ($i > 0) {
3461: $datatable .= '</tr>';
3462: }
3463: $datatable .= '<tr>';
3464: }
3465: $datatable .= '<td class="LC_left_item">'.
3466: '<span class="LC_nobreak"><label>'.
3467: '<input type="checkbox" name="'.$prefix.'_'.$type.
3468: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3469: '</label></span></td>';
1.137 raeburn 3470: }
1.145 raeburn 3471: $rem = @locations%($numinrow);
3472: my $colsleft = $numinrow - $rem;
3473: if ($colsleft > 1 ) {
3474: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3475: ' </td>';
3476: } elsif ($colsleft == 1) {
3477: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3478: }
1.145 raeburn 3479: $datatable .= '</tr></table>';
1.137 raeburn 3480: }
1.145 raeburn 3481: $datatable .= '</td></tr>';
3482: $itemcount ++;
1.137 raeburn 3483: }
3484: }
3485: }
3486: $$rowtotal += $itemcount;
3487: return $datatable;
3488: }
3489:
1.138 raeburn 3490: sub build_location_hashes {
3491: my ($intdoms,$by_ip,$by_location) = @_;
3492: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3493: (ref($by_location) eq 'HASH'));
3494: my %iphost = &Apache::lonnet::get_iphost();
3495: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3496: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3497: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3498: foreach my $id (@{$iphost{$primary_ip}}) {
3499: my $intdom = &Apache::lonnet::internet_dom($id);
3500: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3501: push(@{$intdoms},$intdom);
3502: }
3503: }
3504: }
3505: foreach my $ip (keys(%iphost)) {
3506: if (ref($iphost{$ip}) eq 'ARRAY') {
3507: foreach my $id (@{$iphost{$ip}}) {
3508: my $location = &Apache::lonnet::internet_dom($id);
3509: if ($location) {
3510: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3511: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3512: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3513: push(@{$by_ip->{$ip}},$location);
3514: }
3515: } else {
3516: $by_ip->{$ip} = [$location];
3517: }
3518: }
3519: }
3520: }
3521: }
3522: foreach my $ip (sort(keys(%{$by_ip}))) {
3523: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3524: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3525: my $first = $by_ip->{$ip}->[0];
3526: if (ref($by_location->{$first}) eq 'ARRAY') {
3527: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3528: push(@{$by_location->{$first}},$ip);
3529: }
3530: } else {
3531: $by_location->{$first} = [$ip];
3532: }
3533: }
3534: }
3535: return;
3536: }
3537:
1.145 raeburn 3538: sub current_offloads_to {
3539: my ($dom,$settings,$servers) = @_;
3540: my (%spareid,%otherdomconfigs);
1.152 raeburn 3541: if (ref($servers) eq 'HASH') {
1.145 raeburn 3542: foreach my $lonhost (sort(keys(%{$servers}))) {
3543: my $gotspares;
1.152 raeburn 3544: if (ref($settings) eq 'HASH') {
3545: if (ref($settings->{'spares'}) eq 'HASH') {
3546: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3547: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3548: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3549: $gotspares = 1;
3550: }
1.145 raeburn 3551: }
3552: }
3553: unless ($gotspares) {
3554: my $gotspares;
3555: my $serverhomeID =
3556: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3557: my $serverhomedom =
3558: &Apache::lonnet::host_domain($serverhomeID);
3559: if ($serverhomedom ne $dom) {
3560: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3561: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3562: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3563: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3564: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3565: $gotspares = 1;
3566: }
3567: }
3568: } else {
3569: $otherdomconfigs{$serverhomedom} =
3570: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3571: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3572: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3573: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3574: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3575: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3576: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3577: $gotspares = 1;
3578: }
3579: }
3580: }
3581: }
3582: }
3583: }
3584: }
3585: unless ($gotspares) {
3586: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3587: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3588: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3589: } else {
3590: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3591: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3592: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3593: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3594: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3595: } else {
1.150 raeburn 3596: my %what = (
3597: spareid => 1,
3598: );
3599: my ($result,$returnhash) =
3600: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3601: if ($result eq 'ok') {
3602: if (ref($returnhash) eq 'HASH') {
3603: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3604: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3605: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3606: }
3607: }
1.145 raeburn 3608: }
3609: }
3610: }
3611: }
3612: }
3613: }
3614: return %spareid;
3615: }
3616:
3617: sub spares_row {
1.160.6.61 raeburn 3618: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 3619: my $css_class;
3620: my $numinrow = 4;
3621: my $itemcount = 1;
3622: my $datatable;
1.152 raeburn 3623: my %typetitles = &sparestype_titles();
3624: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3625: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3626: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3627: my ($othercontrol,$serverdom);
3628: if ($serverhome ne $server) {
3629: $serverdom = &Apache::lonnet::host_domain($serverhome);
3630: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3631: } else {
3632: $serverdom = &Apache::lonnet::host_domain($server);
3633: if ($serverdom ne $dom) {
3634: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3635: }
3636: }
3637: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 3638: my $checkednow;
3639: if (ref($curroffloadnow) eq 'HASH') {
3640: if ($curroffloadnow->{$server}) {
3641: $checkednow = ' checked="checked"';
3642: }
3643: }
1.145 raeburn 3644: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3645: $datatable .= '<tr'.$css_class.'>
3646: <td rowspan="2">
1.160.6.13 raeburn 3647: <span class="LC_nobreak">'.
3648: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 3649: ,'<b>'.$server.'</b>').'</span><br />'.
3650: '<span class="LC_nobreak">'."\n".
3651: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
3652: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 3653: "\n";
1.145 raeburn 3654: my (%current,%canselect);
1.152 raeburn 3655: my @choices =
3656: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3657: foreach my $type ('primary','default') {
3658: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3659: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3660: my @spares = @{$spareid->{$server}{$type}};
3661: if (@spares > 0) {
1.152 raeburn 3662: if ($othercontrol) {
3663: $current{$type} = join(', ',@spares);
3664: } else {
3665: $current{$type} .= '<table>';
3666: my $numspares = scalar(@spares);
3667: for (my $i=0; $i<@spares; $i++) {
3668: my $rem = $i%($numinrow);
3669: if ($rem == 0) {
3670: if ($i > 0) {
3671: $current{$type} .= '</tr>';
3672: }
3673: $current{$type} .= '<tr>';
1.145 raeburn 3674: }
1.152 raeburn 3675: $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'".');" /> '.
3676: $spareid->{$server}{$type}[$i].
3677: '</label></td>'."\n";
3678: }
3679: my $rem = @spares%($numinrow);
3680: my $colsleft = $numinrow - $rem;
3681: if ($colsleft > 1 ) {
3682: $current{$type} .= '<td colspan="'.$colsleft.
3683: '" class="LC_left_item">'.
3684: ' </td>';
3685: } elsif ($colsleft == 1) {
3686: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3687: }
1.152 raeburn 3688: $current{$type} .= '</tr></table>';
1.150 raeburn 3689: }
1.145 raeburn 3690: }
3691: }
3692: if ($current{$type} eq '') {
3693: $current{$type} = &mt('None specified');
3694: }
1.152 raeburn 3695: if ($othercontrol) {
3696: if ($type eq 'primary') {
3697: $canselect{$type} = $othercontrol;
3698: }
3699: } else {
3700: $canselect{$type} =
3701: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3702: '<select name="newspare_'.$type.'_'.$server.'" '.
3703: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3704: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3705: if (@choices > 0) {
3706: foreach my $lonhost (@choices) {
3707: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3708: }
3709: }
3710: $canselect{$type} .= '</select>'."\n";
3711: }
3712: } else {
3713: $current{$type} = &mt('Could not be determined');
3714: if ($type eq 'primary') {
3715: $canselect{$type} = $othercontrol;
3716: }
1.145 raeburn 3717: }
1.152 raeburn 3718: if ($type eq 'default') {
3719: $datatable .= '<tr'.$css_class.'>';
3720: }
3721: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3722: '<td>'.$current{$type}.'</td>'."\n".
3723: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3724: }
3725: $itemcount ++;
3726: }
3727: }
3728: $$rowtotal += $itemcount;
3729: return $datatable;
3730: }
3731:
1.152 raeburn 3732: sub possible_newspares {
3733: my ($server,$currspares,$serverhomes,$altids) = @_;
3734: my $serverhostname = &Apache::lonnet::hostname($server);
3735: my %excluded;
3736: if ($serverhostname ne '') {
3737: %excluded = (
3738: $serverhostname => 1,
3739: );
3740: }
3741: if (ref($currspares) eq 'HASH') {
3742: foreach my $type (keys(%{$currspares})) {
3743: if (ref($currspares->{$type}) eq 'ARRAY') {
3744: if (@{$currspares->{$type}} > 0) {
3745: foreach my $curr (@{$currspares->{$type}}) {
3746: my $hostname = &Apache::lonnet::hostname($curr);
3747: $excluded{$hostname} = 1;
3748: }
3749: }
3750: }
3751: }
3752: }
3753: my @choices;
3754: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3755: if (keys(%{$serverhomes}) > 1) {
3756: foreach my $name (sort(keys(%{$serverhomes}))) {
3757: unless ($excluded{$name}) {
3758: if (exists($altids->{$serverhomes->{$name}})) {
3759: push(@choices,$altids->{$serverhomes->{$name}});
3760: } else {
3761: push(@choices,$serverhomes->{$name});
1.145 raeburn 3762: }
3763: }
3764: }
3765: }
3766: }
1.152 raeburn 3767: return sort(@choices);
1.145 raeburn 3768: }
3769:
1.150 raeburn 3770: sub print_loadbalancing {
3771: my ($dom,$settings,$rowtotal) = @_;
3772: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3773: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3774: my $numinrow = 1;
3775: my $datatable;
3776: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3777: my (%currbalancer,%currtargets,%currrules,%existing);
3778: if (ref($settings) eq 'HASH') {
3779: %existing = %{$settings};
3780: }
3781: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3782: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3783: \%currtargets,\%currrules);
1.150 raeburn 3784: } else {
3785: return;
3786: }
3787: my ($othertitle,$usertypes,$types) =
3788: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3789: my $rownum = 8;
1.150 raeburn 3790: if (ref($types) eq 'ARRAY') {
3791: $rownum += scalar(@{$types});
3792: }
1.160.6.7 raeburn 3793: my @css_class = ('LC_odd_row','LC_even_row');
3794: my $balnum = 0;
3795: my $islast;
3796: my (@toshow,$disabledtext);
3797: if (keys(%currbalancer) > 0) {
3798: @toshow = sort(keys(%currbalancer));
3799: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3800: push(@toshow,'');
3801: }
3802: } else {
3803: @toshow = ('');
3804: $disabledtext = &mt('No existing load balancer');
3805: }
3806: foreach my $lonhost (@toshow) {
3807: if ($balnum == scalar(@toshow)-1) {
3808: $islast = 1;
3809: } else {
3810: $islast = 0;
3811: }
3812: my $cssidx = $balnum%2;
3813: my $targets_div_style = 'display: none';
3814: my $disabled_div_style = 'display: block';
3815: my $homedom_div_style = 'display: none';
3816: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3817: '<td rowspan="'.$rownum.'" valign="top">'.
3818: '<p>';
3819: if ($lonhost eq '') {
3820: $datatable .= '<span class="LC_nobreak">';
3821: if (keys(%currbalancer) > 0) {
3822: $datatable .= &mt('Add balancer:');
3823: } else {
3824: $datatable .= &mt('Enable balancer:');
3825: }
3826: $datatable .= ' '.
3827: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3828: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3829: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3830: '<option value="" selected="selected">'.&mt('None').
3831: '</option>'."\n";
3832: foreach my $server (sort(keys(%servers))) {
3833: next if ($currbalancer{$server});
3834: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3835: }
3836: $datatable .=
3837: '</select>'."\n".
3838: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3839: } else {
3840: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3841: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3842: &mt('Stop balancing').'</label>'.
3843: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3844: $targets_div_style = 'display: block';
3845: $disabled_div_style = 'display: none';
3846: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3847: $homedom_div_style = 'display: block';
3848: }
3849: }
3850: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3851: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3852: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3853: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3854: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3855: my @sparestypes = ('primary','default');
3856: my %typetitles = &sparestype_titles();
3857: foreach my $sparetype (@sparestypes) {
3858: my $targettable;
3859: for (my $i=0; $i<$numspares; $i++) {
3860: my $checked;
3861: if (ref($currtargets{$lonhost}) eq 'HASH') {
3862: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3863: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3864: $checked = ' checked="checked"';
3865: }
3866: }
3867: }
3868: my ($chkboxval,$disabled);
3869: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3870: $chkboxval = $spares[$i];
3871: }
3872: if (exists($currbalancer{$spares[$i]})) {
3873: $disabled = ' disabled="disabled"';
3874: }
3875: $targettable .=
1.160.6.55 raeburn 3876: '<td><span class="LC_nobreak"><label>'.
3877: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 3878: $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 3879: '</span></label></span></td>';
1.160.6.7 raeburn 3880: my $rem = $i%($numinrow);
3881: if ($rem == 0) {
3882: if (($i > 0) && ($i < $numspares-1)) {
3883: $targettable .= '</tr>';
3884: }
3885: if ($i < $numspares-1) {
3886: $targettable .= '<tr>';
1.150 raeburn 3887: }
3888: }
3889: }
1.160.6.7 raeburn 3890: if ($targettable ne '') {
3891: my $rem = $numspares%($numinrow);
3892: my $colsleft = $numinrow - $rem;
3893: if ($colsleft > 1 ) {
3894: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3895: ' </td>';
3896: } elsif ($colsleft == 1) {
3897: $targettable .= '<td class="LC_left_item"> </td>';
3898: }
3899: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3900: '<table><tr>'.$targettable.'</tr></table><br />';
3901: }
3902: }
3903: $datatable .= '</div></td></tr>'.
3904: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3905: $othertitle,$usertypes,$types,\%servers,
3906: \%currbalancer,$lonhost,
3907: $targets_div_style,$homedom_div_style,
3908: $css_class[$cssidx],$balnum,$islast);
3909: $$rowtotal += $rownum;
3910: $balnum ++;
3911: }
3912: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3913: return $datatable;
3914: }
3915:
3916: sub get_loadbalancers_config {
3917: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3918: return unless ((ref($servers) eq 'HASH') &&
3919: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3920: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3921: if (keys(%{$existing}) > 0) {
3922: my $oldlonhost;
3923: foreach my $key (sort(keys(%{$existing}))) {
3924: if ($key eq 'lonhost') {
3925: $oldlonhost = $existing->{'lonhost'};
3926: $currbalancer->{$oldlonhost} = 1;
3927: } elsif ($key eq 'targets') {
3928: if ($oldlonhost) {
3929: $currtargets->{$oldlonhost} = $existing->{'targets'};
3930: }
3931: } elsif ($key eq 'rules') {
3932: if ($oldlonhost) {
3933: $currrules->{$oldlonhost} = $existing->{'rules'};
3934: }
3935: } elsif (ref($existing->{$key}) eq 'HASH') {
3936: $currbalancer->{$key} = 1;
3937: $currtargets->{$key} = $existing->{$key}{'targets'};
3938: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3939: }
3940: }
1.160.6.7 raeburn 3941: } else {
3942: my ($balancerref,$targetsref) =
3943: &Apache::lonnet::get_lonbalancer_config($servers);
3944: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3945: foreach my $server (sort(keys(%{$balancerref}))) {
3946: $currbalancer->{$server} = 1;
3947: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3948: }
3949: }
3950: }
1.160.6.7 raeburn 3951: return;
1.150 raeburn 3952: }
3953:
3954: sub loadbalancing_rules {
3955: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3956: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3957: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3958: my $output;
1.160.6.7 raeburn 3959: my $num = 0;
3960: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3961: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3962: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3963: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3964: $num ++;
1.150 raeburn 3965: my $current;
3966: if (ref($currrules) eq 'HASH') {
3967: $current = $currrules->{$type};
3968: }
1.160.6.55 raeburn 3969: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3970: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3971: $current = '';
3972: }
3973: }
3974: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3975: $servers,$currbalancer,$lonhost,$dom,
3976: $targets_div_style,$homedom_div_style,
3977: $css_class,$balnum,$num,$islast);
1.150 raeburn 3978: }
3979: }
3980: return $output;
3981: }
3982:
3983: sub loadbalancing_titles {
3984: my ($dom,$intdom,$usertypes,$types) = @_;
3985: my %othertypes = (
3986: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3987: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3988: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3989: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3990: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3991: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3992: );
1.160.6.26 raeburn 3993: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3994: if (ref($types) eq 'ARRAY') {
3995: unshift(@alltypes,@{$types},'default');
3996: }
3997: my %titles;
3998: foreach my $type (@alltypes) {
3999: if ($type =~ /^_LC_/) {
4000: $titles{$type} = $othertypes{$type};
4001: } elsif ($type eq 'default') {
4002: $titles{$type} = &mt('All users from [_1]',$dom);
4003: if (ref($types) eq 'ARRAY') {
4004: if (@{$types} > 0) {
4005: $titles{$type} = &mt('Other users from [_1]',$dom);
4006: }
4007: }
4008: } elsif (ref($usertypes) eq 'HASH') {
4009: $titles{$type} = $usertypes->{$type};
4010: }
4011: }
4012: return (\@alltypes,\%othertypes,\%titles);
4013: }
4014:
4015: sub loadbalance_rule_row {
1.160.6.7 raeburn 4016: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4017: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4018: my @rulenames;
1.150 raeburn 4019: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4020: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4021: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4022: } else {
1.160.6.26 raeburn 4023: @rulenames = ('default','homeserver');
4024: if ($type eq '_LC_external') {
4025: push(@rulenames,'externalbalancer');
4026: } else {
4027: push(@rulenames,'specific');
4028: }
4029: push(@rulenames,'none');
1.150 raeburn 4030: }
4031: my $style = $targets_div_style;
1.160.6.55 raeburn 4032: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4033: $style = $homedom_div_style;
4034: }
1.160.6.7 raeburn 4035: my $space;
4036: if ($islast && $num == 1) {
4037: $space = '<div display="inline-block"> </div>';
4038: }
4039: my $output =
4040: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4041: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4042: '<td valaign="top">'.$space.
4043: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4044: for (my $i=0; $i<@rulenames; $i++) {
4045: my $rule = $rulenames[$i];
4046: my ($checked,$extra);
4047: if ($rulenames[$i] eq 'default') {
4048: $rule = '';
4049: }
4050: if ($rulenames[$i] eq 'specific') {
4051: if (ref($servers) eq 'HASH') {
4052: my $default;
4053: if (($current ne '') && (exists($servers->{$current}))) {
4054: $checked = ' checked="checked"';
4055: }
4056: unless ($checked) {
4057: $default = ' selected="selected"';
4058: }
1.160.6.7 raeburn 4059: $extra =
4060: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4061: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4062: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4063: '<option value=""'.$default.'></option>'."\n";
4064: foreach my $server (sort(keys(%{$servers}))) {
4065: if (ref($currbalancer) eq 'HASH') {
4066: next if (exists($currbalancer->{$server}));
4067: }
1.150 raeburn 4068: my $selected;
1.160.6.7 raeburn 4069: if ($server eq $current) {
1.150 raeburn 4070: $selected = ' selected="selected"';
4071: }
1.160.6.7 raeburn 4072: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4073: }
4074: $extra .= '</select>';
4075: }
4076: } elsif ($rule eq $current) {
4077: $checked = ' checked="checked"';
4078: }
4079: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4080: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4081: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4082: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4083: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4084: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4085: $output .= $ruletitles{'particular'};
4086: } else {
4087: $output .= $ruletitles{$rulenames[$i]};
4088: }
4089: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4090: }
4091: $output .= '</div></td></tr>'."\n";
4092: return $output;
4093: }
4094:
4095: sub offloadtype_text {
4096: my %ruletitles = &Apache::lonlocal::texthash (
4097: 'default' => 'Offloads to default destinations',
4098: 'homeserver' => "Offloads to user's home server",
4099: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4100: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4101: 'none' => 'No offload',
1.160.6.26 raeburn 4102: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4103: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4104: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4105: );
4106: return %ruletitles;
4107: }
4108:
4109: sub sparestype_titles {
4110: my %typestitles = &Apache::lonlocal::texthash (
4111: 'primary' => 'primary',
4112: 'default' => 'default',
4113: );
4114: return %typestitles;
4115: }
4116:
1.28 raeburn 4117: sub contact_titles {
4118: my %titles = &Apache::lonlocal::texthash (
4119: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4120: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4121: 'errormail' => 'Error reports to be e-mailed to',
4122: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4123: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4124: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4125: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4126: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4127: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4128: );
4129: my %short_titles = &Apache::lonlocal::texthash (
4130: adminemail => 'Admin E-mail address',
4131: supportemail => 'Support E-mail',
4132: );
4133: return (\%titles,\%short_titles);
4134: }
4135:
1.72 raeburn 4136: sub tool_titles {
4137: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4138: aboutme => 'Personal web page',
1.86 raeburn 4139: blog => 'Blog',
1.160.6.4 raeburn 4140: webdav => 'WebDAV',
1.86 raeburn 4141: portfolio => 'Portfolio',
1.88 bisitz 4142: official => 'Official courses (with institutional codes)',
4143: unofficial => 'Unofficial courses',
1.98 raeburn 4144: community => 'Communities',
1.160.6.30 raeburn 4145: textbook => 'Textbook courses',
1.86 raeburn 4146: );
1.72 raeburn 4147: return %titles;
4148: }
4149:
1.101 raeburn 4150: sub courserequest_titles {
4151: my %titles = &Apache::lonlocal::texthash (
4152: official => 'Official',
4153: unofficial => 'Unofficial',
4154: community => 'Communities',
1.160.6.30 raeburn 4155: textbook => 'Textbook',
1.101 raeburn 4156: norequest => 'Not allowed',
1.104 raeburn 4157: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4158: validate => 'With validation',
4159: autolimit => 'Numerical limit',
1.103 raeburn 4160: unlimited => '(blank for unlimited)',
1.101 raeburn 4161: );
4162: return %titles;
4163: }
4164:
1.160.6.5 raeburn 4165: sub authorrequest_titles {
4166: my %titles = &Apache::lonlocal::texthash (
4167: norequest => 'Not allowed',
4168: approval => 'Approval by Dom. Coord.',
4169: automatic => 'Automatic approval',
4170: );
4171: return %titles;
4172: }
4173:
1.101 raeburn 4174: sub courserequest_conditions {
4175: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4176: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4177: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4178: );
4179: return %conditions;
4180: }
4181:
4182:
1.27 raeburn 4183: sub print_usercreation {
1.30 raeburn 4184: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4185: my $numinrow = 4;
1.28 raeburn 4186: my $datatable;
4187: if ($position eq 'top') {
1.30 raeburn 4188: $$rowtotal ++;
1.34 raeburn 4189: my $rowcount = 0;
1.32 raeburn 4190: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4191: if (ref($rules) eq 'HASH') {
4192: if (keys(%{$rules}) > 0) {
1.32 raeburn 4193: $datatable .= &user_formats_row('username',$settings,$rules,
4194: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4195: $$rowtotal ++;
1.32 raeburn 4196: $rowcount ++;
4197: }
4198: }
4199: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4200: if (ref($idrules) eq 'HASH') {
4201: if (keys(%{$idrules}) > 0) {
4202: $datatable .= &user_formats_row('id',$settings,$idrules,
4203: $idruleorder,$numinrow,$rowcount);
4204: $$rowtotal ++;
4205: $rowcount ++;
1.28 raeburn 4206: }
4207: }
1.39 raeburn 4208: if ($rowcount == 0) {
4209: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4210: $$rowtotal ++;
4211: $rowcount ++;
4212: }
1.34 raeburn 4213: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4214: my @creators = ('author','course','requestcrs');
1.37 raeburn 4215: my ($rules,$ruleorder) =
4216: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4217: my %lt = &usercreation_types();
4218: my %checked;
4219: if (ref($settings) eq 'HASH') {
4220: if (ref($settings->{'cancreate'}) eq 'HASH') {
4221: foreach my $item (@creators) {
4222: $checked{$item} = $settings->{'cancreate'}{$item};
4223: }
4224: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4225: foreach my $item (@creators) {
4226: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4227: $checked{$item} = 'none';
4228: }
4229: }
4230: }
4231: }
4232: my $rownum = 0;
4233: foreach my $item (@creators) {
4234: $rownum ++;
1.160.6.34 raeburn 4235: if ($checked{$item} eq '') {
4236: $checked{$item} = 'any';
1.34 raeburn 4237: }
4238: my $css_class;
4239: if ($rownum%2) {
4240: $css_class = '';
4241: } else {
4242: $css_class = ' class="LC_odd_row" ';
4243: }
4244: $datatable .= '<tr'.$css_class.'>'.
4245: '<td><span class="LC_nobreak">'.$lt{$item}.
4246: '</span></td><td align="right">';
1.160.6.34 raeburn 4247: my @options = ('any');
4248: if (ref($rules) eq 'HASH') {
4249: if (keys(%{$rules}) > 0) {
4250: push(@options,('official','unofficial'));
1.37 raeburn 4251: }
4252: }
1.160.6.34 raeburn 4253: push(@options,'none');
1.37 raeburn 4254: foreach my $option (@options) {
1.50 raeburn 4255: my $type = 'radio';
1.34 raeburn 4256: my $check = ' ';
1.160.6.34 raeburn 4257: if ($checked{$item} eq $option) {
4258: $check = ' checked="checked" ';
1.34 raeburn 4259: }
4260: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4261: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4262: $item.'" value="'.$option.'"'.$check.'/> '.
4263: $lt{$option}.'</label> </span>';
4264: }
4265: $datatable .= '</td></tr>';
4266: }
1.28 raeburn 4267: } else {
4268: my @contexts = ('author','course','domain');
4269: my @authtypes = ('int','krb4','krb5','loc');
4270: my %checked;
4271: if (ref($settings) eq 'HASH') {
4272: if (ref($settings->{'authtypes'}) eq 'HASH') {
4273: foreach my $item (@contexts) {
4274: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4275: foreach my $auth (@authtypes) {
4276: if ($settings->{'authtypes'}{$item}{$auth}) {
4277: $checked{$item}{$auth} = ' checked="checked" ';
4278: }
4279: }
4280: }
4281: }
1.27 raeburn 4282: }
1.35 raeburn 4283: } else {
4284: foreach my $item (@contexts) {
1.36 raeburn 4285: foreach my $auth (@authtypes) {
1.35 raeburn 4286: $checked{$item}{$auth} = ' checked="checked" ';
4287: }
4288: }
1.27 raeburn 4289: }
1.28 raeburn 4290: my %title = &context_names();
4291: my %authname = &authtype_names();
4292: my $rownum = 0;
4293: my $css_class;
4294: foreach my $item (@contexts) {
4295: if ($rownum%2) {
4296: $css_class = '';
4297: } else {
4298: $css_class = ' class="LC_odd_row" ';
4299: }
1.30 raeburn 4300: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4301: '<td>'.$title{$item}.
4302: '</td><td class="LC_left_item">'.
4303: '<span class="LC_nobreak">';
4304: foreach my $auth (@authtypes) {
4305: $datatable .= '<label>'.
4306: '<input type="checkbox" name="'.$item.'_auth" '.
4307: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4308: $authname{$auth}.'</label> ';
4309: }
4310: $datatable .= '</span></td></tr>';
4311: $rownum ++;
1.27 raeburn 4312: }
1.30 raeburn 4313: $$rowtotal += $rownum;
1.27 raeburn 4314: }
4315: return $datatable;
4316: }
4317:
1.160.6.34 raeburn 4318: sub print_selfcreation {
4319: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4320: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4321: if (ref($settings) eq 'HASH') {
4322: if (ref($settings->{'cancreate'}) eq 'HASH') {
4323: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4324: if (ref($createsettings) eq 'HASH') {
4325: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4326: @selfcreate = @{$createsettings->{'selfcreate'}};
4327: } elsif ($createsettings->{'selfcreate'} ne '') {
4328: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4329: @selfcreate = ('email','login','sso');
4330: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4331: @selfcreate = ($createsettings->{'selfcreate'});
4332: }
4333: }
4334: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4335: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4336: }
4337: }
4338: }
4339: }
4340: my %radiohash;
4341: my $numinrow = 4;
4342: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4343: if ($position eq 'top') {
4344: my %choices = &Apache::lonlocal::texthash (
4345: cancreate_login => 'Institutional Login',
4346: cancreate_sso => 'Institutional Single Sign On',
4347: );
4348: my @toggles = sort(keys(%choices));
4349: my %defaultchecked = (
4350: 'cancreate_login' => 'off',
4351: 'cancreate_sso' => 'off',
4352: );
1.160.6.35 raeburn 4353: my ($onclick,$itemcount);
1.160.6.34 raeburn 4354: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4355: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4356: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4357:
1.160.6.34 raeburn 4358: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4359:
4360: if (ref($usertypes) eq 'HASH') {
4361: if (keys(%{$usertypes}) > 0) {
4362: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4363: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4364: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4365: $$rowtotal ++;
4366: }
4367: }
1.160.6.44 raeburn 4368: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4369: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4370: $fieldtitles{'inststatus'} = &mt('Institutional status');
4371: my $rem;
4372: my $numperrow = 2;
4373: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4374: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4375: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4376: '<td class="LC_left_item">'."\n".
4377: '<table><tr><td>'."\n";
4378: for (my $i=0; $i<@fields; $i++) {
4379: $rem = $i%($numperrow);
4380: if ($rem == 0) {
4381: if ($i > 0) {
4382: $datatable .= '</tr>';
4383: }
4384: $datatable .= '<tr>';
4385: }
4386: my $currval;
1.160.6.51 raeburn 4387: if (ref($createsettings) eq 'HASH') {
4388: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4389: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4390: }
1.160.6.44 raeburn 4391: }
4392: $datatable .= '<td class="LC_left_item">'.
4393: '<span class="LC_nobreak">'.
4394: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4395: 'value="'.$currval.'" size="10" /> '.
4396: $fieldtitles{$fields[$i]}.'</span></td>';
4397: }
4398: my $colsleft = $numperrow - $rem;
4399: if ($colsleft > 1 ) {
4400: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4401: ' </td>';
4402: } elsif ($colsleft == 1) {
4403: $datatable .= '<td class="LC_left_item"> </td>';
4404: }
4405: $datatable .= '</tr></table></td></tr>';
4406: $$rowtotal ++;
1.160.6.34 raeburn 4407: } elsif ($position eq 'middle') {
4408: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4409: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4410: $usertypes->{'default'} = $othertitle;
4411: if (ref($types) eq 'ARRAY') {
4412: push(@{$types},'default');
4413: $usertypes->{'default'} = $othertitle;
4414: foreach my $status (@{$types}) {
4415: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4416: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4417: $$rowtotal ++;
1.160.6.34 raeburn 4418: }
4419: }
4420: } else {
1.160.6.40 raeburn 4421: my %choices = &Apache::lonlocal::texthash (
4422: cancreate_email => 'E-mail address as username',
4423: );
4424: my @toggles = sort(keys(%choices));
4425: my %defaultchecked = (
4426: 'cancreate_email' => 'off',
4427: );
4428: my $itemcount = 0;
4429: my $display = 'none';
4430: if (grep(/^\Qemail\E$/,@selfcreate)) {
4431: $display = 'block';
4432: }
4433: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4434: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4435: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4436: my $usertypes = {};
4437: my $order = [];
4438: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4439: $usertypes = $domdefaults{'inststatustypes'};
4440: $order = $domdefaults{'inststatusguest'};
4441: }
4442: if (ref($order) eq 'ARRAY') {
4443: push(@{$order},'default');
4444: if (@{$order} > 1) {
4445: $usertypes->{'default'} = &mt('Other users');
4446: $additional .= '<table><tr>';
4447: foreach my $status (@{$order}) {
4448: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4449: }
4450: $additional .= '</tr><tr>';
4451: foreach my $status (@{$order}) {
4452: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4453: }
1.160.6.40 raeburn 4454: $additional .= '</tr></table>';
1.160.6.34 raeburn 4455: } else {
1.160.6.40 raeburn 4456: $usertypes->{'default'} = &mt('All users');
4457: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4458: }
4459: }
1.160.6.40 raeburn 4460: $additional .= '</div>'."\n";
4461:
4462: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4463: \%choices,$$rowtotal,$onclick,$additional);
4464: $$rowtotal ++;
1.160.6.40 raeburn 4465: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4466: $$rowtotal ++;
1.160.6.35 raeburn 4467: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4468: $numinrow = 1;
1.160.6.40 raeburn 4469: if (ref($order) eq 'ARRAY') {
4470: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4471: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4472: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4473: $$rowtotal ++;
4474: }
4475: }
1.160.6.34 raeburn 4476: my ($emailrules,$emailruleorder) =
4477: &Apache::lonnet::inst_userrules($dom,'email');
4478: if (ref($emailrules) eq 'HASH') {
4479: if (keys(%{$emailrules}) > 0) {
4480: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4481: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4482: $$rowtotal ++;
4483: }
4484: }
1.160.6.35 raeburn 4485: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4486: }
4487: return $datatable;
4488: }
4489:
1.160.6.40 raeburn 4490: sub email_as_username {
4491: my ($rowtotal,$processing,$type) = @_;
4492: my %choices =
4493: &Apache::lonlocal::texthash (
4494: automatic => 'Automatic approval',
4495: approval => 'Queued for approval',
4496: );
4497: my $output;
4498: foreach my $option ('automatic','approval') {
4499: my $checked;
4500: if (ref($processing) eq 'HASH') {
4501: if ($type eq '') {
4502: if (!exists($processing->{'default'})) {
4503: if ($option eq 'automatic') {
4504: $checked = ' checked="checked"';
4505: }
4506: } else {
4507: if ($processing->{'default'} eq $option) {
4508: $checked = ' checked="checked"';
4509: }
4510: }
4511: } else {
4512: if (!exists($processing->{$type})) {
4513: if ($option eq 'automatic') {
4514: $checked = ' checked="checked"';
4515: }
4516: } else {
4517: if ($processing->{$type} eq $option) {
4518: $checked = ' checked="checked"';
4519: }
4520: }
4521: }
4522: } elsif ($option eq 'automatic') {
4523: $checked = ' checked="checked"';
4524: }
4525: my $name = 'cancreate_emailprocess';
4526: if (($type ne '') && ($type ne 'default')) {
4527: $name .= '_'.$type;
4528: }
4529: $output .= '<span class="LC_nobreak"><label>'.
4530: '<input type="radio" name="'.$name.'"'.
4531: $checked.' value="'.$option.'" />'.
4532: $choices{$option}.'</label></span>';
4533: if ($type eq '') {
4534: $output .= ' ';
4535: } else {
4536: $output .= '<br />';
4537: }
4538: }
4539: $$rowtotal ++;
4540: return $output;
4541: }
4542:
1.160.6.5 raeburn 4543: sub captcha_choice {
4544: my ($context,$settings,$itemcount) = @_;
4545: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4546: my %lt = &captcha_phrases();
4547: $keyentry = 'hidden';
4548: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4549: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4550: } elsif ($context eq 'login') {
4551: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4552: }
4553: if (ref($settings) eq 'HASH') {
4554: if ($settings->{'captcha'}) {
4555: $checked{$settings->{'captcha'}} = ' checked="checked"';
4556: } else {
4557: $checked{'original'} = ' checked="checked"';
4558: }
4559: if ($settings->{'captcha'} eq 'recaptcha') {
4560: $pubtext = $lt{'pub'};
4561: $privtext = $lt{'priv'};
4562: $keyentry = 'text';
4563: }
4564: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4565: $currpub = $settings->{'recaptchakeys'}{'public'};
4566: $currpriv = $settings->{'recaptchakeys'}{'private'};
4567: }
4568: } else {
4569: $checked{'original'} = ' checked="checked"';
4570: }
4571: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4572: my $output = '<tr'.$css_class.'>'.
4573: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4574: '<table><tr><td>'."\n";
4575: foreach my $option ('original','recaptcha','notused') {
4576: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4577: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4578: $lt{$option}.'</label></span>';
4579: unless ($option eq 'notused') {
4580: $output .= (' 'x2)."\n";
4581: }
4582: }
4583: #
4584: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4585: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4586: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4587: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4588: #
4589: $output .= '</td></tr>'."\n".
4590: '<tr><td>'."\n".
4591: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4592: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4593: $currpub.'" size="40" /></span><br />'."\n".
4594: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4595: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4596: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4597: '</td></tr>';
4598: return $output;
4599: }
4600:
1.32 raeburn 4601: sub user_formats_row {
4602: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4603: my $output;
4604: my %text = (
4605: 'username' => 'new usernames',
4606: 'id' => 'IDs',
1.45 raeburn 4607: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4608: );
4609: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4610: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4611: '<td><span class="LC_nobreak">';
4612: if ($type eq 'email') {
4613: $output .= &mt("Formats disallowed for $text{$type}: ");
4614: } else {
4615: $output .= &mt("Format rules to check for $text{$type}: ");
4616: }
4617: $output .= '</span></td>'.
4618: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4619: my $rem;
4620: if (ref($ruleorder) eq 'ARRAY') {
4621: for (my $i=0; $i<@{$ruleorder}; $i++) {
4622: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4623: my $rem = $i%($numinrow);
4624: if ($rem == 0) {
4625: if ($i > 0) {
4626: $output .= '</tr>';
4627: }
4628: $output .= '<tr>';
4629: }
4630: my $check = ' ';
1.39 raeburn 4631: if (ref($settings) eq 'HASH') {
4632: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4633: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4634: $check = ' checked="checked" ';
4635: }
1.27 raeburn 4636: }
4637: }
4638: $output .= '<td class="LC_left_item">'.
4639: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4640: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4641: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4642: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4643: }
4644: }
4645: $rem = @{$ruleorder}%($numinrow);
4646: }
4647: my $colsleft = $numinrow - $rem;
4648: if ($colsleft > 1 ) {
4649: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4650: ' </td>';
4651: } elsif ($colsleft == 1) {
4652: $output .= '<td class="LC_left_item"> </td>';
4653: }
4654: $output .= '</tr></table></td></tr>';
4655: return $output;
4656: }
4657:
1.34 raeburn 4658: sub usercreation_types {
4659: my %lt = &Apache::lonlocal::texthash (
4660: author => 'When adding a co-author',
4661: course => 'When adding a user to a course',
1.100 raeburn 4662: requestcrs => 'When requesting a course',
1.34 raeburn 4663: any => 'Any',
4664: official => 'Institutional only ',
4665: unofficial => 'Non-institutional only',
4666: none => 'None',
4667: );
4668: return %lt;
1.48 raeburn 4669: }
1.34 raeburn 4670:
1.160.6.34 raeburn 4671: sub selfcreation_types {
4672: my %lt = &Apache::lonlocal::texthash (
4673: selfcreate => 'User creates own account',
4674: any => 'Any',
4675: official => 'Institutional only ',
4676: unofficial => 'Non-institutional only',
4677: email => 'E-mail address',
4678: login => 'Institutional Login',
4679: sso => 'SSO',
4680: );
4681: }
4682:
1.28 raeburn 4683: sub authtype_names {
4684: my %lt = &Apache::lonlocal::texthash(
4685: int => 'Internal',
4686: krb4 => 'Kerberos 4',
4687: krb5 => 'Kerberos 5',
4688: loc => 'Local',
4689: );
4690: return %lt;
4691: }
4692:
4693: sub context_names {
4694: my %context_title = &Apache::lonlocal::texthash(
4695: author => 'Creating users when an Author',
4696: course => 'Creating users when in a course',
4697: domain => 'Creating users when a Domain Coordinator',
4698: );
4699: return %context_title;
4700: }
4701:
1.33 raeburn 4702: sub print_usermodification {
4703: my ($position,$dom,$settings,$rowtotal) = @_;
4704: my $numinrow = 4;
4705: my ($context,$datatable,$rowcount);
4706: if ($position eq 'top') {
4707: $rowcount = 0;
4708: $context = 'author';
4709: foreach my $role ('ca','aa') {
4710: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4711: $numinrow,$rowcount);
4712: $$rowtotal ++;
4713: $rowcount ++;
4714: }
1.160.6.37 raeburn 4715: } elsif ($position eq 'bottom') {
1.33 raeburn 4716: $context = 'course';
4717: $rowcount = 0;
4718: foreach my $role ('st','ep','ta','in','cr') {
4719: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4720: $numinrow,$rowcount);
4721: $$rowtotal ++;
4722: $rowcount ++;
4723: }
4724: }
4725: return $datatable;
4726: }
4727:
1.43 raeburn 4728: sub print_defaults {
1.160.6.40 raeburn 4729: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4730: my $rownum = 0;
4731: my ($datatable,$css_class);
1.160.6.40 raeburn 4732: if ($position eq 'top') {
4733: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4734: 'datelocale_def','portal_def');
4735: my %defaults;
4736: if (ref($settings) eq 'HASH') {
4737: %defaults = %{$settings};
1.43 raeburn 4738: } else {
1.160.6.40 raeburn 4739: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4740: foreach my $item (@items) {
4741: $defaults{$item} = $domdefaults{$item};
4742: }
1.43 raeburn 4743: }
1.160.6.40 raeburn 4744: my $titles = &defaults_titles($dom);
4745: foreach my $item (@items) {
4746: if ($rownum%2) {
4747: $css_class = '';
4748: } else {
4749: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4750: }
1.160.6.40 raeburn 4751: $datatable .= '<tr'.$css_class.'>'.
4752: '<td><span class="LC_nobreak">'.$titles->{$item}.
4753: '</span></td><td class="LC_right_item" colspan="3">';
4754: if ($item eq 'auth_def') {
4755: my @authtypes = ('internal','krb4','krb5','localauth');
4756: my %shortauth = (
4757: internal => 'int',
4758: krb4 => 'krb4',
4759: krb5 => 'krb5',
4760: localauth => 'loc'
4761: );
4762: my %authnames = &authtype_names();
4763: foreach my $auth (@authtypes) {
4764: my $checked = ' ';
4765: if ($defaults{$item} eq $auth) {
4766: $checked = ' checked="checked" ';
4767: }
4768: $datatable .= '<label><input type="radio" name="'.$item.
4769: '" value="'.$auth.'"'.$checked.'/>'.
4770: $authnames{$shortauth{$auth}}.'</label> ';
4771: }
4772: } elsif ($item eq 'timezone_def') {
4773: my $includeempty = 1;
4774: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4775: } elsif ($item eq 'datelocale_def') {
4776: my $includeempty = 1;
4777: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4778: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 4779: my $includeempty = 1;
4780: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 4781: } else {
4782: my $size;
4783: if ($item eq 'portal_def') {
4784: $size = ' size="25"';
4785: }
4786: $datatable .= '<input type="text" name="'.$item.'" value="'.
4787: $defaults{$item}.'"'.$size.' />';
4788: }
4789: $datatable .= '</td></tr>';
4790: $rownum ++;
4791: }
4792: } else {
4793: my (%defaults);
4794: if (ref($settings) eq 'HASH') {
4795: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4796: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4797: my $maxnum = @{$settings->{'inststatusorder'}};
4798: for (my $i=0; $i<$maxnum; $i++) {
4799: $css_class = $rownum%2?' class="LC_odd_row"':'';
4800: my $item = $settings->{'inststatusorder'}->[$i];
4801: my $title = $settings->{'inststatustypes'}->{$item};
4802: my $guestok;
4803: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4804: $guestok = 1;
4805: }
4806: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4807: $datatable .= '<tr'.$css_class.'>'.
4808: '<td><span class="LC_nobreak">'.
4809: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4810: for (my $k=0; $k<=$maxnum; $k++) {
4811: my $vpos = $k+1;
4812: my $selstr;
4813: if ($k == $i) {
4814: $selstr = ' selected="selected" ';
4815: }
4816: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4817: }
4818: my ($checkedon,$checkedoff);
4819: $checkedoff = ' checked="checked"';
4820: if ($guestok) {
4821: $checkedon = $checkedoff;
4822: $checkedoff = '';
4823: }
4824: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4825: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4826: &mt('delete').'</span></td>'.
4827: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4828: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4829: '</span></td>'.
4830: '<td class="LC_right_item"><span class="LC_nobreak">'.
4831: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4832: &mt('Yes').'</label>'.(' 'x2).
4833: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4834: &mt('No').'</label></span></td></tr>';
4835: }
4836: $css_class = $rownum%2?' class="LC_odd_row"':'';
4837: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4838: $datatable .= '<tr '.$css_class.'>'.
4839: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4840: for (my $k=0; $k<=$maxnum; $k++) {
4841: my $vpos = $k+1;
4842: my $selstr;
4843: if ($k == $maxnum) {
4844: $selstr = ' selected="selected" ';
4845: }
4846: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4847: }
4848: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 4849: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 4850: ' '.&mt('(new)').
4851: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4852: &mt('Name displayed:').
4853: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4854: '<td class="LC_right_item"><span class="LC_nobreak">'.
4855: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4856: &mt('Yes').'</label>'.(' 'x2).
4857: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4858: &mt('No').'</label></span></td></tr>';
4859: '</tr>'."\n";
4860: $rownum ++;
1.141 raeburn 4861: }
1.43 raeburn 4862: }
4863: }
4864: $$rowtotal += $rownum;
4865: return $datatable;
4866: }
4867:
1.160.6.5 raeburn 4868: sub get_languages_hash {
4869: my %langchoices;
4870: foreach my $id (&Apache::loncommon::languageids()) {
4871: my $code = &Apache::loncommon::supportedlanguagecode($id);
4872: if ($code ne '') {
4873: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4874: }
4875: }
4876: return %langchoices;
4877: }
4878:
1.43 raeburn 4879: sub defaults_titles {
1.141 raeburn 4880: my ($dom) = @_;
1.43 raeburn 4881: my %titles = &Apache::lonlocal::texthash (
4882: 'auth_def' => 'Default authentication type',
4883: 'auth_arg_def' => 'Default authentication argument',
4884: 'lang_def' => 'Default language',
1.54 raeburn 4885: 'timezone_def' => 'Default timezone',
1.68 raeburn 4886: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4887: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4888: );
1.141 raeburn 4889: if ($dom) {
4890: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4891: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4892: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4893: $protocol = 'http' if ($protocol ne 'https');
4894: if ($uint_dom) {
4895: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4896: $uint_dom);
4897: }
4898: }
1.43 raeburn 4899: return (\%titles);
4900: }
4901:
1.46 raeburn 4902: sub print_scantronformat {
4903: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4904: my $itemcount = 1;
1.60 raeburn 4905: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4906: %confhash);
1.46 raeburn 4907: my $switchserver = &check_switchserver($dom,$confname);
4908: my %lt = &Apache::lonlocal::texthash (
1.95 www 4909: default => 'Default bubblesheet format file error',
4910: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4911: );
4912: my %scantronfiles = (
4913: default => 'default.tab',
4914: custom => 'custom.tab',
4915: );
4916: foreach my $key (keys(%scantronfiles)) {
4917: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4918: .$scantronfiles{$key};
4919: }
4920: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4921: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4922: if (!$switchserver) {
4923: my $servadm = $r->dir_config('lonAdmEMail');
4924: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4925: if ($configuserok eq 'ok') {
4926: if ($author_ok eq 'ok') {
4927: my %legacyfile = (
4928: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4929: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4930: );
4931: my %md5chk;
4932: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4933: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4934: chomp($md5chk{$type});
1.46 raeburn 4935: }
4936: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4937: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4938: ($scantronurls{$type},my $error) =
1.46 raeburn 4939: &legacy_scantronformat($r,$dom,$confname,
4940: $type,$legacyfile{$type},
4941: $scantronurls{$type},
4942: $scantronfiles{$type});
1.60 raeburn 4943: if ($error ne '') {
4944: $error{$type} = $error;
4945: }
4946: }
4947: if (keys(%error) == 0) {
4948: $is_custom = 1;
4949: $confhash{'scantron'}{'scantronformat'} =
4950: $scantronurls{'custom'};
4951: my $putresult =
4952: &Apache::lonnet::put_dom('configuration',
4953: \%confhash,$dom);
4954: if ($putresult ne 'ok') {
4955: $error{'custom'} =
4956: '<span class="LC_error">'.
4957: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4958: }
1.46 raeburn 4959: }
4960: } else {
1.60 raeburn 4961: ($scantronurls{'default'},my $error) =
1.46 raeburn 4962: &legacy_scantronformat($r,$dom,$confname,
4963: 'default',$legacyfile{'default'},
4964: $scantronurls{'default'},
4965: $scantronfiles{'default'});
1.60 raeburn 4966: if ($error eq '') {
4967: $confhash{'scantron'}{'scantronformat'} = '';
4968: my $putresult =
4969: &Apache::lonnet::put_dom('configuration',
4970: \%confhash,$dom);
4971: if ($putresult ne 'ok') {
4972: $error{'default'} =
4973: '<span class="LC_error">'.
4974: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4975: }
4976: } else {
4977: $error{'default'} = $error;
4978: }
1.46 raeburn 4979: }
4980: }
4981: }
4982: } else {
1.95 www 4983: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4984: }
4985: }
4986: if (ref($settings) eq 'HASH') {
4987: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4988: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4989: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4990: $scantronurl = '';
4991: } else {
4992: $scantronurl = $settings->{'scantronformat'};
4993: }
4994: $is_custom = 1;
4995: } else {
4996: $scantronurl = $scantronurls{'default'};
4997: }
4998: } else {
1.60 raeburn 4999: if ($is_custom) {
5000: $scantronurl = $scantronurls{'custom'};
5001: } else {
5002: $scantronurl = $scantronurls{'default'};
5003: }
1.46 raeburn 5004: }
5005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5006: $datatable .= '<tr'.$css_class.'>';
5007: if (!$is_custom) {
1.65 raeburn 5008: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5009: '<span class="LC_nobreak">';
1.46 raeburn 5010: if ($scantronurl) {
1.160.6.21 raeburn 5011: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5012: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5013: } else {
5014: $datatable = &mt('File unavailable for display');
5015: }
1.65 raeburn 5016: $datatable .= '</span></td>';
1.60 raeburn 5017: if (keys(%error) == 0) {
5018: $datatable .= '<td valign="bottom">';
5019: if (!$switchserver) {
5020: $datatable .= &mt('Upload:').'<br />';
5021: }
5022: } else {
5023: my $errorstr;
5024: foreach my $key (sort(keys(%error))) {
5025: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5026: }
5027: $datatable .= '<td>'.$errorstr;
5028: }
1.46 raeburn 5029: } else {
5030: if (keys(%error) > 0) {
5031: my $errorstr;
5032: foreach my $key (sort(keys(%error))) {
5033: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5034: }
1.60 raeburn 5035: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5036: } elsif ($scantronurl) {
1.160.6.26 raeburn 5037: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5038: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5039: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5040: $link.
5041: '<label><input type="checkbox" name="scantronformat_del"'.
5042: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5043: '<td><span class="LC_nobreak"> '.
5044: &mt('Replace:').'</span><br />';
1.46 raeburn 5045: }
5046: }
5047: if (keys(%error) == 0) {
5048: if ($switchserver) {
5049: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5050: } else {
1.65 raeburn 5051: $datatable .='<span class="LC_nobreak"> '.
5052: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5053: }
5054: }
5055: $datatable .= '</td></tr>';
5056: $$rowtotal ++;
5057: return $datatable;
5058: }
5059:
5060: sub legacy_scantronformat {
5061: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5062: my ($url,$error);
5063: my @statinfo = &Apache::lonnet::stat_file($newurl);
5064: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5065: (my $result,$url) =
5066: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5067: '','',$newfile);
5068: if ($result ne 'ok') {
1.130 raeburn 5069: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5070: }
5071: }
5072: return ($url,$error);
5073: }
1.43 raeburn 5074:
1.49 raeburn 5075: sub print_coursecategories {
1.57 raeburn 5076: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5077: my $datatable;
5078: if ($position eq 'top') {
1.160.6.42 raeburn 5079: my (%checked);
5080: my @catitems = ('unauth','auth');
5081: my @cattypes = ('std','domonly','codesrch','none');
5082: $checked{'unauth'} = 'std';
5083: $checked{'auth'} = 'std';
5084: if (ref($settings) eq 'HASH') {
5085: foreach my $type (@cattypes) {
5086: if ($type eq $settings->{'unauth'}) {
5087: $checked{'unauth'} = $type;
5088: }
5089: if ($type eq $settings->{'auth'}) {
5090: $checked{'auth'} = $type;
5091: }
5092: }
5093: }
5094: my %lt = &Apache::lonlocal::texthash (
5095: unauth => 'Catalog type for unauthenticated users',
5096: auth => 'Catalog type for authenticated users',
5097: none => 'No catalog',
5098: std => 'Standard catalog',
5099: domonly => 'Domain-only catalog',
5100: codesrch => "Code search form",
5101: );
5102: my $itemcount = 0;
5103: foreach my $item (@catitems) {
5104: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5105: $datatable .= '<tr '.$css_class.'>'.
5106: '<td>'.$lt{$item}.'</td>'.
5107: '<td class="LC_right_item"><span class="LC_nobreak">';
5108: foreach my $type (@cattypes) {
5109: my $ischecked;
5110: if ($checked{$item} eq $type) {
5111: $ischecked=' checked="checked"';
5112: }
5113: $datatable .= '<label>'.
5114: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5115: ' />'.$lt{$type}.'</label> ';
5116: }
5117: $datatable .= '</td></tr>';
5118: $itemcount ++;
5119: }
5120: $$rowtotal += $itemcount;
5121: } elsif ($position eq 'middle') {
1.57 raeburn 5122: my $toggle_cats_crs = ' ';
5123: my $toggle_cats_dom = ' checked="checked" ';
5124: my $can_cat_crs = ' ';
5125: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5126: my $toggle_catscomm_comm = ' ';
5127: my $toggle_catscomm_dom = ' checked="checked" ';
5128: my $can_catcomm_comm = ' ';
5129: my $can_catcomm_dom = ' checked="checked" ';
5130:
1.57 raeburn 5131: if (ref($settings) eq 'HASH') {
5132: if ($settings->{'togglecats'} eq 'crs') {
5133: $toggle_cats_crs = $toggle_cats_dom;
5134: $toggle_cats_dom = ' ';
5135: }
5136: if ($settings->{'categorize'} eq 'crs') {
5137: $can_cat_crs = $can_cat_dom;
5138: $can_cat_dom = ' ';
5139: }
1.120 raeburn 5140: if ($settings->{'togglecatscomm'} eq 'comm') {
5141: $toggle_catscomm_comm = $toggle_catscomm_dom;
5142: $toggle_catscomm_dom = ' ';
5143: }
5144: if ($settings->{'categorizecomm'} eq 'comm') {
5145: $can_catcomm_comm = $can_catcomm_dom;
5146: $can_catcomm_dom = ' ';
5147: }
1.57 raeburn 5148: }
5149: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5150: togglecats => 'Show/Hide a course in catalog',
5151: togglecatscomm => 'Show/Hide a community in catalog',
5152: categorize => 'Assign a category to a course',
5153: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5154: );
5155: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5156: dom => 'Set in Domain',
5157: crs => 'Set in Course',
5158: comm => 'Set in Community',
1.57 raeburn 5159: );
5160: $datatable = '<tr class="LC_odd_row">'.
5161: '<td>'.$title{'togglecats'}.'</td>'.
5162: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5163: '<input type="radio" name="togglecats"'.
5164: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5165: '<label><input type="radio" name="togglecats"'.
5166: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5167: '</tr><tr>'.
5168: '<td>'.$title{'categorize'}.'</td>'.
5169: '<td class="LC_right_item"><span class="LC_nobreak">'.
5170: '<label><input type="radio" name="categorize"'.
5171: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5172: '<label><input type="radio" name="categorize"'.
5173: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5174: '</tr><tr class="LC_odd_row">'.
5175: '<td>'.$title{'togglecatscomm'}.'</td>'.
5176: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5177: '<input type="radio" name="togglecatscomm"'.
5178: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5179: '<label><input type="radio" name="togglecatscomm"'.
5180: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5181: '</tr><tr>'.
5182: '<td>'.$title{'categorizecomm'}.'</td>'.
5183: '<td class="LC_right_item"><span class="LC_nobreak">'.
5184: '<label><input type="radio" name="categorizecomm"'.
5185: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5186: '<label><input type="radio" name="categorizecomm"'.
5187: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5188: '</tr>';
1.120 raeburn 5189: $$rowtotal += 4;
1.57 raeburn 5190: } else {
5191: my $css_class;
5192: my $itemcount = 1;
5193: my $cathash;
5194: if (ref($settings) eq 'HASH') {
5195: $cathash = $settings->{'cats'};
5196: }
5197: if (ref($cathash) eq 'HASH') {
5198: my (@cats,@trails,%allitems,%idx,@jsarray);
5199: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5200: \%allitems,\%idx,\@jsarray);
5201: my $maxdepth = scalar(@cats);
5202: my $colattrib = '';
5203: if ($maxdepth > 2) {
5204: $colattrib = ' colspan="2" ';
5205: }
5206: my @path;
5207: if (@cats > 0) {
5208: if (ref($cats[0]) eq 'ARRAY') {
5209: my $numtop = @{$cats[0]};
5210: my $maxnum = $numtop;
1.120 raeburn 5211: my %default_names = (
5212: instcode => &mt('Official courses'),
5213: communities => &mt('Communities'),
5214: );
5215:
5216: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5217: ($cathash->{'instcode::0'} eq '') ||
5218: (!grep(/^communities$/,@{$cats[0]})) ||
5219: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5220: $maxnum ++;
5221: }
5222: my $lastidx;
5223: for (my $i=0; $i<$numtop; $i++) {
5224: my $parent = $cats[0][$i];
5225: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5226: my $item = &escape($parent).'::0';
5227: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5228: $lastidx = $idx{$item};
5229: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5230: .'<select name="'.$item.'"'.$chgstr.'>';
5231: for (my $k=0; $k<=$maxnum; $k++) {
5232: my $vpos = $k+1;
5233: my $selstr;
5234: if ($k == $i) {
5235: $selstr = ' selected="selected" ';
5236: }
5237: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5238: }
1.160.6.29 raeburn 5239: $datatable .= '</select></span></td><td>';
1.120 raeburn 5240: if ($parent eq 'instcode' || $parent eq 'communities') {
5241: $datatable .= '<span class="LC_nobreak">'
5242: .$default_names{$parent}.'</span>';
5243: if ($parent eq 'instcode') {
5244: $datatable .= '<br /><span class="LC_nobreak">('
5245: .&mt('with institutional codes')
5246: .')</span></td><td'.$colattrib.'>';
5247: } else {
5248: $datatable .= '<table><tr><td>';
5249: }
5250: $datatable .= '<span class="LC_nobreak">'
5251: .'<label><input type="radio" name="'
5252: .$parent.'" value="1" checked="checked" />'
5253: .&mt('Display').'</label>';
5254: if ($parent eq 'instcode') {
5255: $datatable .= ' ';
5256: } else {
5257: $datatable .= '</span></td></tr><tr><td>'
5258: .'<span class="LC_nobreak">';
5259: }
5260: $datatable .= '<label><input type="radio" name="'
5261: .$parent.'" value="0" />'
5262: .&mt('Do not display').'</label></span>';
5263: if ($parent eq 'communities') {
5264: $datatable .= '</td></tr></table>';
5265: }
5266: $datatable .= '</td>';
1.57 raeburn 5267: } else {
5268: $datatable .= $parent
1.160.6.29 raeburn 5269: .' <span class="LC_nobreak"><label>'
5270: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5271: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5272: }
5273: my $depth = 1;
5274: push(@path,$parent);
5275: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5276: pop(@path);
5277: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5278: $itemcount ++;
5279: }
1.48 raeburn 5280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5281: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5282: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5283: for (my $k=0; $k<=$maxnum; $k++) {
5284: my $vpos = $k+1;
5285: my $selstr;
1.57 raeburn 5286: if ($k == $numtop) {
1.48 raeburn 5287: $selstr = ' selected="selected" ';
5288: }
5289: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5290: }
1.59 bisitz 5291: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5292: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5293: .'</tr>'."\n";
1.48 raeburn 5294: $itemcount ++;
1.120 raeburn 5295: foreach my $default ('instcode','communities') {
5296: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5297: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5298: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5299: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5300: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5301: for (my $k=0; $k<=$maxnum; $k++) {
5302: my $vpos = $k+1;
5303: my $selstr;
5304: if ($k == $maxnum) {
5305: $selstr = ' selected="selected" ';
5306: }
5307: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5308: }
1.120 raeburn 5309: $datatable .= '</select></span></td>'.
5310: '<td><span class="LC_nobreak">'.
5311: $default_names{$default}.'</span>';
5312: if ($default eq 'instcode') {
5313: $datatable .= '<br /><span class="LC_nobreak">('
5314: .&mt('with institutional codes').')</span>';
5315: }
5316: $datatable .= '</td>'
5317: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5318: .&mt('Display').'</label> '
5319: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5320: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5321: }
5322: }
5323: }
1.57 raeburn 5324: } else {
5325: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5326: }
5327: } else {
1.160.6.42 raeburn 5328: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5329: .&initialize_categories($itemcount);
1.48 raeburn 5330: }
1.57 raeburn 5331: $$rowtotal += $itemcount;
1.48 raeburn 5332: }
5333: return $datatable;
5334: }
5335:
1.69 raeburn 5336: sub print_serverstatuses {
5337: my ($dom,$settings,$rowtotal) = @_;
5338: my $datatable;
5339: my @pages = &serverstatus_pages();
5340: my (%namedaccess,%machineaccess);
5341: foreach my $type (@pages) {
5342: $namedaccess{$type} = '';
5343: $machineaccess{$type}= '';
5344: }
5345: if (ref($settings) eq 'HASH') {
5346: foreach my $type (@pages) {
5347: if (exists($settings->{$type})) {
5348: if (ref($settings->{$type}) eq 'HASH') {
5349: foreach my $key (keys(%{$settings->{$type}})) {
5350: if ($key eq 'namedusers') {
5351: $namedaccess{$type} = $settings->{$type}->{$key};
5352: } elsif ($key eq 'machines') {
5353: $machineaccess{$type} = $settings->{$type}->{$key};
5354: }
5355: }
5356: }
5357: }
5358: }
5359: }
1.81 raeburn 5360: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5361: my $rownum = 0;
5362: my $css_class;
5363: foreach my $type (@pages) {
5364: $rownum ++;
5365: $css_class = $rownum%2?' class="LC_odd_row"':'';
5366: $datatable .= '<tr'.$css_class.'>'.
5367: '<td><span class="LC_nobreak">'.
5368: $titles->{$type}.'</span></td>'.
5369: '<td class="LC_left_item">'.
5370: '<input type="text" name="'.$type.'_namedusers" '.
5371: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5372: '<td class="LC_right_item">'.
5373: '<span class="LC_nobreak">'.
5374: '<input type="text" name="'.$type.'_machines" '.
5375: 'value="'.$machineaccess{$type}.'" size="10" />'.
5376: '</td></tr>'."\n";
5377: }
5378: $$rowtotal += $rownum;
5379: return $datatable;
5380: }
5381:
5382: sub serverstatus_pages {
5383: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5384: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5385: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 5386: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5387: }
5388:
1.160.6.40 raeburn 5389: sub defaults_javascript {
5390: my ($settings) = @_;
1.160.6.51 raeburn 5391: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5392: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5393: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5394: if ($maxnum eq '') {
5395: $maxnum = 0;
5396: }
5397: $maxnum ++;
1.160.6.51 raeburn 5398: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5399: return <<"ENDSCRIPT";
5400: <script type="text/javascript">
5401: // <![CDATA[
5402: function reorderTypes(form,caller) {
5403: var changedVal;
5404: $jstext
5405: var newpos = 'addinststatus_pos';
5406: var current = new Array;
5407: var maxh = $maxnum;
5408: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5409: var oldVal;
5410: if (caller == newpos) {
5411: changedVal = newitemVal;
5412: } else {
5413: var curritem = 'inststatus_pos_'+caller;
5414: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5415: current[newitemVal] = newpos;
5416: }
5417: for (var i=0; i<inststatuses.length; i++) {
5418: if (inststatuses[i] != caller) {
5419: var elementName = 'inststatus_pos_'+inststatuses[i];
5420: if (form.elements[elementName]) {
5421: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5422: current[currVal] = elementName;
5423: }
5424: }
5425: }
5426: for (var j=0; j<maxh; j++) {
5427: if (current[j] == undefined) {
5428: oldVal = j;
5429: }
5430: }
5431: if (oldVal < changedVal) {
5432: for (var k=oldVal+1; k<=changedVal ; k++) {
5433: var elementName = current[k];
5434: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5435: }
5436: } else {
5437: for (var k=changedVal; k<oldVal; k++) {
5438: var elementName = current[k];
5439: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5440: }
5441: }
5442: return;
5443: }
5444:
5445: // ]]>
5446: </script>
5447:
5448: ENDSCRIPT
5449: }
5450: }
5451:
1.49 raeburn 5452: sub coursecategories_javascript {
5453: my ($settings) = @_;
1.57 raeburn 5454: my ($output,$jstext,$cathash);
1.49 raeburn 5455: if (ref($settings) eq 'HASH') {
1.57 raeburn 5456: $cathash = $settings->{'cats'};
5457: }
5458: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5459: my (@cats,@jsarray,%idx);
1.57 raeburn 5460: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5461: if (@jsarray > 0) {
5462: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5463: for (my $i=0; $i<@jsarray; $i++) {
5464: if (ref($jsarray[$i]) eq 'ARRAY') {
5465: my $catstr = join('","',@{$jsarray[$i]});
5466: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5467: }
5468: }
5469: }
5470: } else {
5471: $jstext = ' var categories = Array(1);'."\n".
5472: ' categories[0] = Array("instcode_pos");'."\n";
5473: }
1.160.6.42 raeburn 5474: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5475: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 5476: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5477: &js_escape(\$instcode_reserved);
5478: &js_escape(\$communities_reserved);
5479: &js_escape(\$choose_again);
1.49 raeburn 5480: $output = <<"ENDSCRIPT";
5481: <script type="text/javascript">
1.109 raeburn 5482: // <![CDATA[
1.49 raeburn 5483: function reorderCats(form,parent,item,idx) {
5484: var changedVal;
5485: $jstext
5486: var newpos = 'addcategory_pos';
5487: if (parent == '') {
5488: var has_instcode = 0;
5489: var maxtop = categories[idx].length;
5490: for (var j=0; j<maxtop; j++) {
5491: if (categories[idx][j] == 'instcode::0') {
5492: has_instcode == 1;
5493: }
5494: }
5495: if (has_instcode == 0) {
5496: categories[idx][maxtop] = 'instcode_pos';
5497: }
5498: } else {
5499: newpos += '_'+parent;
5500: }
5501: var maxh = 1 + categories[idx].length;
5502: var current = new Array;
5503: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5504: if (item == newpos) {
5505: changedVal = newitemVal;
5506: } else {
5507: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5508: current[newitemVal] = newpos;
5509: }
5510: for (var i=0; i<categories[idx].length; i++) {
5511: var elementName = categories[idx][i];
5512: if (elementName != item) {
5513: if (form.elements[elementName]) {
5514: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5515: current[currVal] = elementName;
5516: }
5517: }
5518: }
5519: var oldVal;
5520: for (var j=0; j<maxh; j++) {
5521: if (current[j] == undefined) {
5522: oldVal = j;
5523: }
5524: }
5525: if (oldVal < changedVal) {
5526: for (var k=oldVal+1; k<=changedVal ; k++) {
5527: var elementName = current[k];
5528: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5529: }
5530: } else {
5531: for (var k=changedVal; k<oldVal; k++) {
5532: var elementName = current[k];
5533: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5534: }
5535: }
5536: return;
5537: }
1.120 raeburn 5538:
5539: function categoryCheck(form) {
5540: if (form.elements['addcategory_name'].value == 'instcode') {
5541: alert('$instcode_reserved\\n$choose_again');
5542: return false;
5543: }
5544: if (form.elements['addcategory_name'].value == 'communities') {
5545: alert('$communities_reserved\\n$choose_again');
5546: return false;
5547: }
5548: return true;
5549: }
5550:
1.109 raeburn 5551: // ]]>
1.49 raeburn 5552: </script>
5553:
5554: ENDSCRIPT
5555: return $output;
5556: }
5557:
1.48 raeburn 5558: sub initialize_categories {
5559: my ($itemcount) = @_;
1.120 raeburn 5560: my ($datatable,$css_class,$chgstr);
5561: my %default_names = (
5562: instcode => 'Official courses (with institutional codes)',
5563: communities => 'Communities',
5564: );
5565: my $select0 = ' selected="selected"';
5566: my $select1 = '';
5567: foreach my $default ('instcode','communities') {
5568: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5569: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5570: if ($default eq 'communities') {
5571: $select1 = $select0;
5572: $select0 = '';
5573: }
5574: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5575: .'<select name="'.$default.'_pos">'
5576: .'<option value="0"'.$select0.'>1</option>'
5577: .'<option value="1"'.$select1.'>2</option>'
5578: .'<option value="2">3</option></select> '
5579: .$default_names{$default}
5580: .'</span></td><td><span class="LC_nobreak">'
5581: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5582: .&mt('Display').'</label> <label>'
5583: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5584: .'</label></span></td></tr>';
1.120 raeburn 5585: $itemcount ++;
5586: }
1.48 raeburn 5587: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5588: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5589: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5590: .'<select name="addcategory_pos"'.$chgstr.'>'
5591: .'<option value="0">1</option>'
5592: .'<option value="1">2</option>'
5593: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5594: .&mt('Add category').'</td><td>'.&mt('Name:')
5595: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5596: return $datatable;
5597: }
5598:
5599: sub build_category_rows {
1.49 raeburn 5600: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5601: my ($text,$name,$item,$chgstr);
1.48 raeburn 5602: if (ref($cats) eq 'ARRAY') {
5603: my $maxdepth = scalar(@{$cats});
5604: if (ref($cats->[$depth]) eq 'HASH') {
5605: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5606: my $numchildren = @{$cats->[$depth]{$parent}};
5607: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5608: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5609: my ($idxnum,$parent_name,$parent_item);
5610: my $higher = $depth - 1;
5611: if ($higher == 0) {
5612: $parent_name = &escape($parent).'::'.$higher;
5613: } else {
5614: if (ref($path) eq 'ARRAY') {
5615: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5616: }
5617: }
5618: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5619: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5620: if ($j < $numchildren) {
1.48 raeburn 5621: $name = $cats->[$depth]{$parent}[$j];
5622: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5623: $idxnum = $idx->{$item};
5624: } else {
5625: $name = $parent_name;
5626: $item = $parent_item;
1.48 raeburn 5627: }
1.49 raeburn 5628: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5629: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5630: for (my $i=0; $i<=$numchildren; $i++) {
5631: my $vpos = $i+1;
5632: my $selstr;
5633: if ($j == $i) {
5634: $selstr = ' selected="selected" ';
5635: }
5636: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5637: }
5638: $text .= '</select> ';
5639: if ($j < $numchildren) {
5640: my $deeper = $depth+1;
5641: $text .= $name.' '
5642: .'<label><input type="checkbox" name="deletecategory" value="'
5643: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5644: if(ref($path) eq 'ARRAY') {
5645: push(@{$path},$name);
1.49 raeburn 5646: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5647: pop(@{$path});
5648: }
5649: } else {
1.59 bisitz 5650: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5651: if ($j == $numchildren) {
5652: $text .= $name;
5653: } else {
5654: $text .= $item;
5655: }
5656: $text .= '" value="" />';
5657: }
5658: $text .= '</td></tr>';
5659: }
5660: $text .= '</table></td>';
5661: } else {
5662: my $higher = $depth-1;
5663: if ($higher == 0) {
5664: $name = &escape($parent).'::'.$higher;
5665: } else {
5666: if (ref($path) eq 'ARRAY') {
5667: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5668: }
5669: }
5670: my $colspan;
5671: if ($parent ne 'instcode') {
5672: $colspan = $maxdepth - $depth - 1;
5673: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5674: }
5675: }
5676: }
5677: }
5678: return $text;
5679: }
5680:
1.33 raeburn 5681: sub modifiable_userdata_row {
1.160.6.35 raeburn 5682: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5683: my ($role,$rolename,$statustype);
5684: $role = $item;
1.160.6.34 raeburn 5685: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5686: if ($item =~ /^emailusername_(.+)$/) {
5687: $statustype = $1;
5688: $role = 'emailusername';
5689: if (ref($usertypes) eq 'HASH') {
5690: if ($usertypes->{$statustype}) {
5691: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5692: } else {
5693: $rolename = &mt('Data provided by user');
5694: }
5695: }
1.160.6.34 raeburn 5696: }
5697: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5698: if (ref($usertypes) eq 'HASH') {
5699: $rolename = $usertypes->{$role};
5700: } else {
5701: $rolename = $role;
5702: }
1.33 raeburn 5703: } else {
1.63 raeburn 5704: if ($role eq 'cr') {
5705: $rolename = &mt('Custom role');
5706: } else {
5707: $rolename = &Apache::lonnet::plaintext($role);
5708: }
1.33 raeburn 5709: }
1.160.6.34 raeburn 5710: my (@fields,%fieldtitles);
5711: if (ref($fieldsref) eq 'ARRAY') {
5712: @fields = @{$fieldsref};
5713: } else {
5714: @fields = ('lastname','firstname','middlename','generation',
5715: 'permanentemail','id');
5716: }
5717: if ((ref($titlesref) eq 'HASH')) {
5718: %fieldtitles = %{$titlesref};
5719: } else {
5720: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5721: }
1.33 raeburn 5722: my $output;
5723: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5724: $output = '<tr '.$css_class.'>'.
5725: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5726: '<td class="LC_left_item" colspan="2"><table>';
5727: my $rem;
5728: my %checks;
5729: if (ref($settings) eq 'HASH') {
5730: if (ref($settings->{$context}) eq 'HASH') {
5731: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5732: my $hashref = $settings->{$context}->{$role};
5733: if ($role eq 'emailusername') {
5734: if ($statustype) {
5735: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5736: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5737: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5738: foreach my $field (@fields) {
5739: if ($hashref->{$field}) {
5740: $checks{$field} = $hashref->{$field};
5741: }
5742: }
5743: }
5744: }
5745: }
5746: } else {
5747: if (ref($hashref) eq 'HASH') {
5748: foreach my $field (@fields) {
5749: if ($hashref->{$field}) {
5750: $checks{$field} = ' checked="checked" ';
5751: }
5752: }
1.33 raeburn 5753: }
5754: }
5755: }
5756: }
5757: }
1.160.6.39 raeburn 5758:
1.33 raeburn 5759: for (my $i=0; $i<@fields; $i++) {
5760: my $rem = $i%($numinrow);
5761: if ($rem == 0) {
5762: if ($i > 0) {
5763: $output .= '</tr>';
5764: }
5765: $output .= '<tr>';
5766: }
5767: my $check = ' ';
1.160.6.35 raeburn 5768: unless ($role eq 'emailusername') {
5769: if (exists($checks{$fields[$i]})) {
5770: $check = $checks{$fields[$i]}
5771: } else {
5772: if ($role eq 'st') {
5773: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5774: $check = ' checked="checked" ';
1.160.6.35 raeburn 5775: }
1.33 raeburn 5776: }
5777: }
5778: }
5779: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5780: '<span class="LC_nobreak">';
5781: if ($role eq 'emailusername') {
5782: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5783: $checks{$fields[$i]} = 'omit';
5784: }
5785: foreach my $option ('required','optional','omit') {
5786: my $checked='';
5787: if ($checks{$fields[$i]} eq $option) {
5788: $checked='checked="checked" ';
5789: }
5790: $output .= '<label>'.
5791: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5792: &mt($option).'</label>'.(' ' x2);
5793: }
5794: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5795: } else {
5796: $output .= '<label>'.
5797: '<input type="checkbox" name="canmodify_'.$role.'" '.
5798: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5799: '</label>';
5800: }
5801: $output .= '</span></td>';
1.33 raeburn 5802: $rem = @fields%($numinrow);
5803: }
5804: my $colsleft = $numinrow - $rem;
5805: if ($colsleft > 1 ) {
5806: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5807: ' </td>';
5808: } elsif ($colsleft == 1) {
5809: $output .= '<td class="LC_left_item"> </td>';
5810: }
5811: $output .= '</tr></table></td></tr>';
5812: return $output;
5813: }
1.28 raeburn 5814:
1.93 raeburn 5815: sub insttypes_row {
1.160.6.34 raeburn 5816: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5817: my %lt = &Apache::lonlocal::texthash (
5818: cansearch => 'Users allowed to search',
5819: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5820: lockablenames => 'User preference to lock name',
1.93 raeburn 5821: );
5822: my $showdom;
5823: if ($context eq 'cansearch') {
5824: $showdom = ' ('.$dom.')';
5825: }
1.160.6.5 raeburn 5826: my $class = 'LC_left_item';
5827: if ($context eq 'statustocreate') {
5828: $class = 'LC_right_item';
5829: }
1.160.6.34 raeburn 5830: my $css_class = ' class="LC_odd_row"';
5831: if ($rownum ne '') {
5832: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5833: }
5834: my $output = '<tr'.$css_class.'>'.
5835: '<td>'.$lt{$context}.$showdom.
5836: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5837: my $rem;
5838: if (ref($types) eq 'ARRAY') {
5839: for (my $i=0; $i<@{$types}; $i++) {
5840: if (defined($usertypes->{$types->[$i]})) {
5841: my $rem = $i%($numinrow);
5842: if ($rem == 0) {
5843: if ($i > 0) {
5844: $output .= '</tr>';
5845: }
5846: $output .= '<tr>';
1.23 raeburn 5847: }
1.26 raeburn 5848: my $check = ' ';
1.99 raeburn 5849: if (ref($settings) eq 'HASH') {
5850: if (ref($settings->{$context}) eq 'ARRAY') {
5851: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5852: $check = ' checked="checked" ';
5853: }
5854: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5855: $check = ' checked="checked" ';
5856: }
1.23 raeburn 5857: }
1.26 raeburn 5858: $output .= '<td class="LC_left_item">'.
5859: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5860: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5861: 'value="'.$types->[$i].'"'.$check.'/>'.
5862: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5863: }
5864: }
1.26 raeburn 5865: $rem = @{$types}%($numinrow);
1.23 raeburn 5866: }
5867: my $colsleft = $numinrow - $rem;
1.131 raeburn 5868: if (($rem == 0) && (@{$types} > 0)) {
5869: $output .= '<tr>';
5870: }
1.23 raeburn 5871: if ($colsleft > 1) {
1.25 raeburn 5872: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5873: } else {
1.25 raeburn 5874: $output .= '<td class="LC_left_item">';
1.23 raeburn 5875: }
5876: my $defcheck = ' ';
1.99 raeburn 5877: if (ref($settings) eq 'HASH') {
5878: if (ref($settings->{$context}) eq 'ARRAY') {
5879: if (grep(/^default$/,@{$settings->{$context}})) {
5880: $defcheck = ' checked="checked" ';
5881: }
5882: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5883: $defcheck = ' checked="checked" ';
5884: }
1.23 raeburn 5885: }
1.25 raeburn 5886: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5887: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5888: 'value="default"'.$defcheck.'/>'.
5889: $othertitle.'</label></span></td>'.
5890: '</tr></table></td></tr>';
5891: return $output;
1.23 raeburn 5892: }
5893:
5894: sub sorted_searchtitles {
5895: my %searchtitles = &Apache::lonlocal::texthash(
5896: 'uname' => 'username',
5897: 'lastname' => 'last name',
5898: 'lastfirst' => 'last name, first name',
5899: );
5900: my @titleorder = ('uname','lastname','lastfirst');
5901: return (\%searchtitles,\@titleorder);
5902: }
5903:
1.25 raeburn 5904: sub sorted_searchtypes {
5905: my %srchtypes_desc = (
5906: exact => 'is exact match',
5907: contains => 'contains ..',
5908: begins => 'begins with ..',
5909: );
5910: my @srchtypeorder = ('exact','begins','contains');
5911: return (\%srchtypes_desc,\@srchtypeorder);
5912: }
5913:
1.3 raeburn 5914: sub usertype_update_row {
5915: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5916: my $datatable;
5917: my $numinrow = 4;
5918: foreach my $type (@{$types}) {
5919: if (defined($usertypes->{$type})) {
5920: $$rownums ++;
5921: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5922: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5923: '</td><td class="LC_left_item"><table>';
5924: for (my $i=0; $i<@{$fields}; $i++) {
5925: my $rem = $i%($numinrow);
5926: if ($rem == 0) {
5927: if ($i > 0) {
5928: $datatable .= '</tr>';
5929: }
5930: $datatable .= '<tr>';
5931: }
5932: my $check = ' ';
1.39 raeburn 5933: if (ref($settings) eq 'HASH') {
5934: if (ref($settings->{'fields'}) eq 'HASH') {
5935: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5936: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5937: $check = ' checked="checked" ';
5938: }
1.3 raeburn 5939: }
5940: }
5941: }
5942:
5943: if ($i == @{$fields}-1) {
5944: my $colsleft = $numinrow - $rem;
5945: if ($colsleft > 1) {
5946: $datatable .= '<td colspan="'.$colsleft.'">';
5947: } else {
5948: $datatable .= '<td>';
5949: }
5950: } else {
5951: $datatable .= '<td>';
5952: }
1.8 raeburn 5953: $datatable .= '<span class="LC_nobreak"><label>'.
5954: '<input type="checkbox" name="updateable_'.$type.
5955: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5956: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5957: }
5958: $datatable .= '</tr></table></td></tr>';
5959: }
5960: }
5961: return $datatable;
1.1 raeburn 5962: }
5963:
5964: sub modify_login {
1.160.6.24 raeburn 5965: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5966: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5967: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5968: %title = ( coursecatalog => 'Display course catalog',
5969: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5970: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5971: newuser => 'Link for visitors to create a user account',
5972: loginheader => 'Log-in box header');
5973: @offon = ('off','on');
1.112 raeburn 5974: if (ref($domconfig{login}) eq 'HASH') {
5975: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5976: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5977: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5978: }
5979: }
5980: }
1.9 raeburn 5981: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5982: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5983: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5984: foreach my $item (@toggles) {
5985: $loginhash{login}{$item} = $env{'form.'.$item};
5986: }
1.41 raeburn 5987: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5988: if (ref($colchanges{'login'}) eq 'HASH') {
5989: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5990: \%loginhash);
5991: }
1.110 raeburn 5992:
1.149 raeburn 5993: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 5994: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 5995: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5996: if (keys(%servers) > 1) {
5997: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5998: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5999: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6000: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6001: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6002: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6003: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6004: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6005: $changes{'loginvia'}{$lonhost} = 1;
6006: } else {
6007: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6008: $changes{'loginvia'}{$lonhost} = 1;
6009: }
6010: } else {
6011: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6012: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6013: $changes{'loginvia'}{$lonhost} = 1;
6014: }
6015: }
6016: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6017: foreach my $item (@loginvia_attribs) {
6018: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6019: }
6020: } else {
6021: foreach my $item (@loginvia_attribs) {
6022: my $new = $env{'form.'.$lonhost.'_'.$item};
6023: if (($item eq 'serverpath') && ($new eq 'custom')) {
6024: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6025: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6026: $new = '/';
6027: }
6028: }
6029: if (($item eq 'custompath') &&
6030: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6031: $new = '';
6032: }
6033: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6034: $changes{'loginvia'}{$lonhost} = 1;
6035: }
6036: if ($item eq 'exempt') {
1.160.6.56 raeburn 6037: $new = &check_exempt_addresses($new);
1.128 raeburn 6038: }
6039: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6040: }
6041: }
1.112 raeburn 6042: } else {
1.128 raeburn 6043: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6044: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6045: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6046: foreach my $item (@loginvia_attribs) {
6047: my $new = $env{'form.'.$lonhost.'_'.$item};
6048: if (($item eq 'serverpath') && ($new eq 'custom')) {
6049: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6050: $new = '/';
6051: }
6052: }
6053: if (($item eq 'custompath') &&
6054: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6055: $new = '';
6056: }
6057: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6058: }
1.110 raeburn 6059: }
6060: }
6061: }
6062: }
1.119 raeburn 6063:
1.160.6.5 raeburn 6064: my $servadm = $r->dir_config('lonAdmEMail');
6065: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6066: if (ref($domconfig{'login'}) eq 'HASH') {
6067: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6068: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6069: if ($lang eq 'nolang') {
6070: push(@currlangs,$lang);
6071: } elsif (defined($langchoices{$lang})) {
6072: push(@currlangs,$lang);
6073: } else {
6074: next;
6075: }
6076: }
6077: }
6078: }
6079: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6080: if (@currlangs > 0) {
6081: foreach my $lang (@currlangs) {
6082: if (grep(/^\Q$lang\E$/,@delurls)) {
6083: $changes{'helpurl'}{$lang} = 1;
6084: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6085: $changes{'helpurl'}{$lang} = 1;
6086: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6087: push(@newlangs,$lang);
6088: } else {
6089: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6090: }
6091: }
6092: }
6093: unless (grep(/^nolang$/,@currlangs)) {
6094: if ($env{'form.loginhelpurl_nolang.filename'}) {
6095: $changes{'helpurl'}{'nolang'} = 1;
6096: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6097: push(@newlangs,'nolang');
6098: }
6099: }
6100: if ($env{'form.loginhelpurl_add_lang'}) {
6101: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6102: ($env{'form.loginhelpurl_add_file.filename'})) {
6103: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6104: $addedfile = $env{'form.loginhelpurl_add_lang'};
6105: }
6106: }
6107: if ((@newlangs > 0) || ($addedfile)) {
6108: my $error;
6109: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6110: if ($configuserok eq 'ok') {
6111: if ($switchserver) {
6112: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6113: } elsif ($author_ok eq 'ok') {
6114: my @allnew = @newlangs;
6115: if ($addedfile ne '') {
6116: push(@allnew,$addedfile);
6117: }
6118: foreach my $lang (@allnew) {
6119: my $formelem = 'loginhelpurl_'.$lang;
6120: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6121: $formelem = 'loginhelpurl_add_file';
6122: }
6123: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6124: "help/$lang",'','',$newfile{$lang});
6125: if ($result eq 'ok') {
6126: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6127: $changes{'helpurl'}{$lang} = 1;
6128: } else {
6129: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6130: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6131: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6132: (!grep(/^\Q$lang\E$/,@delurls))) {
6133:
6134: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6135: }
6136: }
6137: }
6138: } else {
6139: $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);
6140: }
6141: } else {
6142: $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);
6143: }
6144: if ($error) {
6145: &Apache::lonnet::logthis($error);
6146: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6147: }
6148: }
1.160.6.56 raeburn 6149:
6150: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6151: if (ref($domconfig{'login'}) eq 'HASH') {
6152: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6153: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6154: if ($domservers{$lonhost}) {
6155: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6156: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.67 raeburn 6157: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'}
1.160.6.56 raeburn 6158: }
6159: }
6160: }
6161: }
6162: }
6163: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6164: foreach my $lonhost (sort(keys(%domservers))) {
6165: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6166: $changes{'headtag'}{$lonhost} = 1;
6167: } else {
6168: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6169: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6170: }
6171: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6172: push(@newhosts,$lonhost);
6173: } elsif ($currheadtagurls{$lonhost}) {
6174: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6175: if ($currexempt{$lonhost}) {
6176: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6177: $changes{'headtag'}{$lonhost} = 1;
6178: }
6179: } elsif ($possexempt{$lonhost}) {
6180: $changes{'headtag'}{$lonhost} = 1;
6181: }
6182: if ($possexempt{$lonhost}) {
6183: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6184: }
6185: }
6186: }
6187: }
6188: if (@newhosts) {
6189: my $error;
6190: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6191: if ($configuserok eq 'ok') {
6192: if ($switchserver) {
6193: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6194: } elsif ($author_ok eq 'ok') {
6195: foreach my $lonhost (@newhosts) {
6196: my $formelem = 'loginheadtag_'.$lonhost;
6197: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6198: "login/headtag/$lonhost",'','',
6199: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6200: if ($result eq 'ok') {
6201: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6202: $changes{'headtag'}{$lonhost} = 1;
6203: if ($possexempt{$lonhost}) {
6204: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6205: }
6206: } else {
6207: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6208: $newheadtagurls{$lonhost},$result);
6209: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6210: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6211: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6212: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6213: }
6214: }
6215: }
6216: } else {
6217: $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);
6218: }
6219: } else {
6220: $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);
6221: }
6222: if ($error) {
6223: &Apache::lonnet::logthis($error);
6224: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6225: }
6226: }
6227:
1.160.6.5 raeburn 6228: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6229:
6230: my $defaulthelpfile = '/adm/loginproblems.html';
6231: my $defaulttext = &mt('Default in use');
6232:
1.1 raeburn 6233: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6234: $dom);
6235: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6236: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6237: my %defaultchecked = (
6238: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6239: 'helpdesk' => 'on',
1.42 raeburn 6240: 'adminmail' => 'off',
1.43 raeburn 6241: 'newuser' => 'off',
1.42 raeburn 6242: );
1.55 raeburn 6243: if (ref($domconfig{'login'}) eq 'HASH') {
6244: foreach my $item (@toggles) {
6245: if ($defaultchecked{$item} eq 'on') {
6246: if (($domconfig{'login'}{$item} eq '0') &&
6247: ($env{'form.'.$item} eq '1')) {
6248: $changes{$item} = 1;
6249: } elsif (($domconfig{'login'}{$item} eq '' ||
6250: $domconfig{'login'}{$item} eq '1') &&
6251: ($env{'form.'.$item} eq '0')) {
6252: $changes{$item} = 1;
6253: }
6254: } elsif ($defaultchecked{$item} eq 'off') {
6255: if (($domconfig{'login'}{$item} eq '1') &&
6256: ($env{'form.'.$item} eq '0')) {
6257: $changes{$item} = 1;
6258: } elsif (($domconfig{'login'}{$item} eq '' ||
6259: $domconfig{'login'}{$item} eq '0') &&
6260: ($env{'form.'.$item} eq '1')) {
6261: $changes{$item} = 1;
6262: }
1.42 raeburn 6263: }
6264: }
1.41 raeburn 6265: }
1.6 raeburn 6266: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6267: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6268: if (ref($lastactref) eq 'HASH') {
6269: $lastactref->{'domainconfig'} = 1;
6270: }
1.1 raeburn 6271: $resulttext = &mt('Changes made:').'<ul>';
6272: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6273: if ($item eq 'loginvia') {
1.112 raeburn 6274: if (ref($changes{$item}) eq 'HASH') {
6275: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6276: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6277: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6278: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6279: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6280: $protocol = 'http' if ($protocol ne 'https');
6281: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6282:
6283: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6284: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6285: } else {
6286: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6287: }
6288: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6289: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6290: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6291: }
6292: $resulttext .= '</li>';
6293: } else {
6294: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6295: }
1.112 raeburn 6296: } else {
1.128 raeburn 6297: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6298: }
6299: }
1.128 raeburn 6300: $resulttext .= '</ul></li>';
1.112 raeburn 6301: }
1.160.6.5 raeburn 6302: } elsif ($item eq 'helpurl') {
6303: if (ref($changes{$item}) eq 'HASH') {
6304: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6305: if (grep(/^\Q$lang\E$/,@delurls)) {
6306: my ($chg,$link);
6307: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6308: if ($lang eq 'nolang') {
6309: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6310: } else {
6311: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6312: }
6313: $resulttext .= '<li>'.$chg.'</li>';
6314: } else {
6315: my $chg;
6316: if ($lang eq 'nolang') {
6317: $chg = &mt('custom log-in help file for no preferred language');
6318: } else {
6319: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6320: }
6321: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6322: $loginhash{'login'}{'helpurl'}{$lang}.
6323: '?inhibitmenu=yes',$chg,600,500).
6324: '</li>';
6325: }
6326: }
6327: }
1.160.6.56 raeburn 6328: } elsif ($item eq 'headtag') {
6329: if (ref($changes{$item}) eq 'HASH') {
6330: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6331: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6332: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6333: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6334: $resulttext .= '<li><a href="'.
6335: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6336: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6337: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6338: if ($possexempt{$lonhost}) {
6339: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6340: } else {
6341: $resulttext .= &mt('included for any client IP');
6342: }
6343: $resulttext .= '</li>';
6344: }
6345: }
6346: }
1.160.6.5 raeburn 6347: } elsif ($item eq 'captcha') {
6348: if (ref($loginhash{'login'}) eq 'HASH') {
6349: my $chgtxt;
6350: if ($loginhash{'login'}{$item} eq 'notused') {
6351: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6352: } else {
6353: my %captchas = &captcha_phrases();
6354: if ($captchas{$loginhash{'login'}{$item}}) {
6355: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6356: } else {
6357: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6358: }
6359: }
6360: $resulttext .= '<li>'.$chgtxt.'</li>';
6361: }
6362: } elsif ($item eq 'recaptchakeys') {
6363: if (ref($loginhash{'login'}) eq 'HASH') {
6364: my ($privkey,$pubkey);
6365: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6366: $pubkey = $loginhash{'login'}{$item}{'public'};
6367: $privkey = $loginhash{'login'}{$item}{'private'};
6368: }
6369: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6370: if (!$pubkey) {
6371: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6372: } else {
6373: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6374: }
6375: if (!$privkey) {
6376: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6377: } else {
1.160.6.53 raeburn 6378: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6379: }
6380: $chgtxt .= '</ul>';
6381: $resulttext .= '<li>'.$chgtxt.'</li>';
6382: }
1.41 raeburn 6383: } else {
6384: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6385: }
1.1 raeburn 6386: }
1.6 raeburn 6387: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6388: } else {
6389: $resulttext = &mt('No changes made to log-in page settings');
6390: }
6391: } else {
1.11 albertel 6392: $resulttext = '<span class="LC_error">'.
6393: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6394: }
1.6 raeburn 6395: if ($errors) {
1.9 raeburn 6396: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6397: $errors.'</ul>';
6398: }
6399: return $resulttext;
6400: }
6401:
1.160.6.56 raeburn 6402: sub check_exempt_addresses {
6403: my ($iplist) = @_;
6404: $iplist =~ s/^\s+//;
6405: $iplist =~ s/\s+$//;
6406: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6407: my (@okips,$new);
6408: foreach my $ip (@poss_ips) {
6409: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6410: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6411: push(@okips,$ip);
6412: }
6413: }
6414: }
6415: if (@okips > 0) {
6416: $new = join(',',@okips);
6417: } else {
6418: $new = '';
6419: }
6420: return $new;
6421: }
6422:
1.6 raeburn 6423: sub color_font_choices {
6424: my %choices =
6425: &Apache::lonlocal::texthash (
6426: img => "Header",
6427: bgs => "Background colors",
6428: links => "Link colors",
1.55 raeburn 6429: images => "Images",
1.6 raeburn 6430: font => "Font color",
1.160.6.22 raeburn 6431: fontmenu => "Font menu",
1.76 raeburn 6432: pgbg => "Page",
1.6 raeburn 6433: tabbg => "Header",
6434: sidebg => "Border",
6435: link => "Link",
6436: alink => "Active link",
6437: vlink => "Visited link",
6438: );
6439: return %choices;
6440: }
6441:
6442: sub modify_rolecolors {
1.160.6.24 raeburn 6443: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6444: my ($resulttext,%rolehash);
6445: $rolehash{'rolecolors'} = {};
1.55 raeburn 6446: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6447: if ($domconfig{'rolecolors'} eq '') {
6448: $domconfig{'rolecolors'} = {};
6449: }
6450: }
1.9 raeburn 6451: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6452: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6453: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6454: $dom);
6455: if ($putresult eq 'ok') {
6456: if (keys(%changes) > 0) {
1.41 raeburn 6457: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6458: if (ref($lastactref) eq 'HASH') {
6459: $lastactref->{'domainconfig'} = 1;
6460: }
1.6 raeburn 6461: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6462: $rolehash{'rolecolors'});
6463: } else {
6464: $resulttext = &mt('No changes made to default color schemes');
6465: }
6466: } else {
1.11 albertel 6467: $resulttext = '<span class="LC_error">'.
6468: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6469: }
6470: if ($errors) {
6471: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6472: $errors.'</ul>';
6473: }
6474: return $resulttext;
6475: }
6476:
6477: sub modify_colors {
1.9 raeburn 6478: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6479: my (%changes,%choices);
1.51 raeburn 6480: my @bgs;
1.6 raeburn 6481: my @links = ('link','alink','vlink');
1.41 raeburn 6482: my @logintext;
1.6 raeburn 6483: my @images;
6484: my $servadm = $r->dir_config('lonAdmEMail');
6485: my $errors;
1.160.6.22 raeburn 6486: my %defaults;
1.6 raeburn 6487: foreach my $role (@{$roles}) {
6488: if ($role eq 'login') {
1.12 raeburn 6489: %choices = &login_choices();
1.41 raeburn 6490: @logintext = ('textcol','bgcol');
1.12 raeburn 6491: } else {
6492: %choices = &color_font_choices();
6493: }
6494: if ($role eq 'login') {
1.41 raeburn 6495: @images = ('img','logo','domlogo','login');
1.51 raeburn 6496: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6497: } else {
6498: @images = ('img');
1.160.6.22 raeburn 6499: @bgs = ('pgbg','tabbg','sidebg');
6500: }
6501: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6502: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6503: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6504: }
6505: if ($role eq 'login') {
6506: foreach my $item (@logintext) {
1.160.6.39 raeburn 6507: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6508: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6509: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6510: }
6511: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6512: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6513: }
6514: }
6515: } else {
1.160.6.39 raeburn 6516: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6517: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6518: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6519: }
6520: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6521: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6522: }
1.6 raeburn 6523: }
1.160.6.22 raeburn 6524: foreach my $item (@bgs) {
1.160.6.39 raeburn 6525: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6526: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6527: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6528: }
6529: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6530: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6531: }
6532: }
6533: foreach my $item (@links) {
1.160.6.39 raeburn 6534: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6535: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6536: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6537: }
6538: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6539: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6540: }
1.6 raeburn 6541: }
1.46 raeburn 6542: my ($configuserok,$author_ok,$switchserver) =
6543: &config_check($dom,$confname,$servadm);
1.9 raeburn 6544: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6545: if (ref($domconfig->{$role}) ne 'HASH') {
6546: $domconfig->{$role} = {};
6547: }
1.8 raeburn 6548: foreach my $img (@images) {
1.70 raeburn 6549: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6550: if (defined($env{'form.login_showlogo_'.$img})) {
6551: $confhash->{$role}{'showlogo'}{$img} = 1;
6552: } else {
6553: $confhash->{$role}{'showlogo'}{$img} = 0;
6554: }
6555: }
1.18 albertel 6556: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6557: && !defined($domconfig->{$role}{$img})
6558: && !$env{'form.'.$role.'_del_'.$img}
6559: && $env{'form.'.$role.'_import_'.$img}) {
6560: # import the old configured image from the .tab setting
6561: # if they haven't provided a new one
6562: $domconfig->{$role}{$img} =
6563: $env{'form.'.$role.'_import_'.$img};
6564: }
1.6 raeburn 6565: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6566: my $error;
1.6 raeburn 6567: if ($configuserok eq 'ok') {
1.9 raeburn 6568: if ($switchserver) {
1.12 raeburn 6569: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6570: } else {
6571: if ($author_ok eq 'ok') {
6572: my ($result,$logourl) =
6573: &publishlogo($r,'upload',$role.'_'.$img,
6574: $dom,$confname,$img,$width,$height);
6575: if ($result eq 'ok') {
6576: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6577: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6578: } else {
1.12 raeburn 6579: $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 6580: }
6581: } else {
1.46 raeburn 6582: $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 6583: }
6584: }
6585: } else {
1.46 raeburn 6586: $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 6587: }
6588: if ($error) {
1.8 raeburn 6589: &Apache::lonnet::logthis($error);
1.11 albertel 6590: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6591: }
6592: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6593: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6594: my $error;
6595: if ($configuserok eq 'ok') {
6596: # is confname an author?
6597: if ($switchserver eq '') {
6598: if ($author_ok eq 'ok') {
6599: my ($result,$logourl) =
6600: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6601: $dom,$confname,$img,$width,$height);
6602: if ($result eq 'ok') {
6603: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6604: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6605: }
6606: }
6607: }
6608: }
1.6 raeburn 6609: }
6610: }
6611: }
6612: if (ref($domconfig) eq 'HASH') {
6613: if (ref($domconfig->{$role}) eq 'HASH') {
6614: foreach my $img (@images) {
6615: if ($domconfig->{$role}{$img} ne '') {
6616: if ($env{'form.'.$role.'_del_'.$img}) {
6617: $confhash->{$role}{$img} = '';
1.12 raeburn 6618: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6619: } else {
1.9 raeburn 6620: if ($confhash->{$role}{$img} eq '') {
6621: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6622: }
1.6 raeburn 6623: }
6624: } else {
6625: if ($env{'form.'.$role.'_del_'.$img}) {
6626: $confhash->{$role}{$img} = '';
1.12 raeburn 6627: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6628: }
6629: }
1.70 raeburn 6630: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6631: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6632: if ($confhash->{$role}{'showlogo'}{$img} ne
6633: $domconfig->{$role}{'showlogo'}{$img}) {
6634: $changes{$role}{'showlogo'}{$img} = 1;
6635: }
6636: } else {
6637: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6638: $changes{$role}{'showlogo'}{$img} = 1;
6639: }
6640: }
6641: }
6642: }
1.6 raeburn 6643: if ($domconfig->{$role}{'font'} ne '') {
6644: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6645: $changes{$role}{'font'} = 1;
6646: }
6647: } else {
6648: if ($confhash->{$role}{'font'}) {
6649: $changes{$role}{'font'} = 1;
6650: }
6651: }
1.107 raeburn 6652: if ($role ne 'login') {
6653: if ($domconfig->{$role}{'fontmenu'} ne '') {
6654: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6655: $changes{$role}{'fontmenu'} = 1;
6656: }
6657: } else {
6658: if ($confhash->{$role}{'fontmenu'}) {
6659: $changes{$role}{'fontmenu'} = 1;
6660: }
1.97 tempelho 6661: }
6662: }
1.6 raeburn 6663: foreach my $item (@bgs) {
6664: if ($domconfig->{$role}{$item} ne '') {
6665: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6666: $changes{$role}{'bgs'}{$item} = 1;
6667: }
6668: } else {
6669: if ($confhash->{$role}{$item}) {
6670: $changes{$role}{'bgs'}{$item} = 1;
6671: }
6672: }
6673: }
6674: foreach my $item (@links) {
6675: if ($domconfig->{$role}{$item} ne '') {
6676: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6677: $changes{$role}{'links'}{$item} = 1;
6678: }
6679: } else {
6680: if ($confhash->{$role}{$item}) {
6681: $changes{$role}{'links'}{$item} = 1;
6682: }
6683: }
6684: }
1.41 raeburn 6685: foreach my $item (@logintext) {
6686: if ($domconfig->{$role}{$item} ne '') {
6687: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6688: $changes{$role}{'logintext'}{$item} = 1;
6689: }
6690: } else {
6691: if ($confhash->{$role}{$item}) {
6692: $changes{$role}{'logintext'}{$item} = 1;
6693: }
6694: }
6695: }
1.6 raeburn 6696: } else {
6697: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6698: \@logintext,$confhash,\%changes);
1.6 raeburn 6699: }
6700: } else {
6701: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6702: \@logintext,$confhash,\%changes);
1.6 raeburn 6703: }
6704: }
6705: return ($errors,%changes);
6706: }
6707:
1.46 raeburn 6708: sub config_check {
6709: my ($dom,$confname,$servadm) = @_;
6710: my ($configuserok,$author_ok,$switchserver,%currroles);
6711: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6712: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6713: $confname,$servadm);
6714: if ($configuserok eq 'ok') {
6715: $switchserver = &check_switchserver($dom,$confname);
6716: if ($switchserver eq '') {
6717: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6718: }
6719: }
6720: return ($configuserok,$author_ok,$switchserver);
6721: }
6722:
1.6 raeburn 6723: sub default_change_checker {
1.41 raeburn 6724: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6725: foreach my $item (@{$links}) {
6726: if ($confhash->{$role}{$item}) {
6727: $changes->{$role}{'links'}{$item} = 1;
6728: }
6729: }
6730: foreach my $item (@{$bgs}) {
6731: if ($confhash->{$role}{$item}) {
6732: $changes->{$role}{'bgs'}{$item} = 1;
6733: }
6734: }
1.41 raeburn 6735: foreach my $item (@{$logintext}) {
6736: if ($confhash->{$role}{$item}) {
6737: $changes->{$role}{'logintext'}{$item} = 1;
6738: }
6739: }
1.6 raeburn 6740: foreach my $img (@{$images}) {
6741: if ($env{'form.'.$role.'_del_'.$img}) {
6742: $confhash->{$role}{$img} = '';
1.12 raeburn 6743: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6744: }
1.70 raeburn 6745: if ($role eq 'login') {
6746: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6747: $changes->{$role}{'showlogo'}{$img} = 1;
6748: }
6749: }
1.6 raeburn 6750: }
6751: if ($confhash->{$role}{'font'}) {
6752: $changes->{$role}{'font'} = 1;
6753: }
1.48 raeburn 6754: }
1.6 raeburn 6755:
6756: sub display_colorchgs {
6757: my ($dom,$changes,$roles,$confhash) = @_;
6758: my (%choices,$resulttext);
6759: if (!grep(/^login$/,@{$roles})) {
6760: $resulttext = &mt('Changes made:').'<br />';
6761: }
6762: foreach my $role (@{$roles}) {
6763: if ($role eq 'login') {
6764: %choices = &login_choices();
6765: } else {
6766: %choices = &color_font_choices();
6767: }
6768: if (ref($changes->{$role}) eq 'HASH') {
6769: if ($role ne 'login') {
6770: $resulttext .= '<h4>'.&mt($role).'</h4>';
6771: }
6772: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6773: if ($role ne 'login') {
6774: $resulttext .= '<ul>';
6775: }
6776: if (ref($changes->{$role}{$key}) eq 'HASH') {
6777: if ($role ne 'login') {
6778: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6779: }
6780: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6781: if (($role eq 'login') && ($key eq 'showlogo')) {
6782: if ($confhash->{$role}{$key}{$item}) {
6783: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6784: } else {
6785: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6786: }
6787: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6788: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6789: } else {
1.12 raeburn 6790: my $newitem = $confhash->{$role}{$item};
6791: if ($key eq 'images') {
6792: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6793: }
6794: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6795: }
6796: }
6797: if ($role ne 'login') {
6798: $resulttext .= '</ul></li>';
6799: }
6800: } else {
6801: if ($confhash->{$role}{$key} eq '') {
6802: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6803: } else {
6804: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6805: }
6806: }
6807: if ($role ne 'login') {
6808: $resulttext .= '</ul>';
6809: }
6810: }
6811: }
6812: }
1.3 raeburn 6813: return $resulttext;
1.1 raeburn 6814: }
6815:
1.9 raeburn 6816: sub thumb_dimensions {
6817: return ('200','50');
6818: }
6819:
1.16 raeburn 6820: sub check_dimensions {
6821: my ($inputfile) = @_;
6822: my ($fullwidth,$fullheight);
6823: if ($inputfile =~ m|^[/\w.\-]+$|) {
6824: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6825: my $imageinfo = <PIPE>;
6826: if (!close(PIPE)) {
6827: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6828: }
6829: chomp($imageinfo);
6830: my ($fullsize) =
1.21 raeburn 6831: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6832: if ($fullsize) {
6833: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6834: }
6835: }
6836: }
6837: return ($fullwidth,$fullheight);
6838: }
6839:
1.9 raeburn 6840: sub check_configuser {
6841: my ($uhome,$dom,$confname,$servadm) = @_;
6842: my ($configuserok,%currroles);
6843: if ($uhome eq 'no_host') {
6844: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6845: my $configpass = &LONCAPA::Enrollment::create_password();
6846: $configuserok =
6847: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6848: $configpass,'','','','','',undef,$servadm);
6849: } else {
6850: $configuserok = 'ok';
6851: %currroles =
6852: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6853: }
6854: return ($configuserok,%currroles);
6855: }
6856:
6857: sub check_authorstatus {
6858: my ($dom,$confname,%currroles) = @_;
6859: my $author_ok;
1.40 raeburn 6860: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6861: my $start = time;
6862: my $end = 0;
6863: $author_ok =
6864: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6865: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6866: } else {
6867: $author_ok = 'ok';
6868: }
6869: return $author_ok;
6870: }
6871:
6872: sub publishlogo {
1.46 raeburn 6873: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6874: my ($output,$fname,$logourl);
6875: if ($action eq 'upload') {
6876: $fname=$env{'form.'.$formname.'.filename'};
6877: chop($env{'form.'.$formname});
6878: } else {
6879: ($fname) = ($formname =~ /([^\/]+)$/);
6880: }
1.46 raeburn 6881: if ($savefileas ne '') {
6882: $fname = $savefileas;
6883: }
1.9 raeburn 6884: $fname=&Apache::lonnet::clean_filename($fname);
6885: # See if there is anything left
6886: unless ($fname) { return ('error: no uploaded file'); }
6887: $fname="$subdir/$fname";
1.160.6.5 raeburn 6888: my $docroot=$r->dir_config('lonDocRoot');
6889: my $filepath="$docroot/priv";
6890: my $relpath = "$dom/$confname";
1.9 raeburn 6891: my ($fnamepath,$file,$fetchthumb);
6892: $file=$fname;
6893: if ($fname=~m|/|) {
6894: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6895: }
1.160.6.26 raeburn 6896: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6897: my $count;
1.160.6.5 raeburn 6898: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6899: $filepath.="/$parts[$count]";
6900: if ((-e $filepath)!=1) {
6901: mkdir($filepath,02770);
6902: }
6903: }
6904: # Check for bad extension and disallow upload
6905: if ($file=~/\.(\w+)$/ &&
6906: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6907: $output =
1.160.6.25 raeburn 6908: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6909: } elsif ($file=~/\.(\w+)$/ &&
6910: !defined(&Apache::loncommon::fileembstyle($1))) {
6911: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6912: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6913: $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 6914: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6915: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6916: } else {
6917: my $source = $filepath.'/'.$file;
6918: my $logfile;
6919: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6920: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6921: }
6922: print $logfile
6923: "\n================= Publish ".localtime()." ================\n".
6924: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6925: # Save the file
6926: if (!open(FH,'>'.$source)) {
6927: &Apache::lonnet::logthis('Failed to create '.$source);
6928: return (&mt('Failed to create file'));
6929: }
6930: if ($action eq 'upload') {
6931: if (!print FH ($env{'form.'.$formname})) {
6932: &Apache::lonnet::logthis('Failed to write to '.$source);
6933: return (&mt('Failed to write file'));
6934: }
6935: } else {
6936: my $original = &Apache::lonnet::filelocation('',$formname);
6937: if(!copy($original,$source)) {
6938: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6939: return (&mt('Failed to write file'));
6940: }
6941: }
6942: close(FH);
6943: chmod(0660, $source); # Permissions to rw-rw---.
6944:
6945: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6946: my $copyfile=$targetdir.'/'.$file;
6947:
6948: my @parts=split(/\//,$targetdir);
6949: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6950: for (my $count=5;$count<=$#parts;$count++) {
6951: $path.="/$parts[$count]";
6952: if (!-e $path) {
6953: print $logfile "\nCreating directory ".$path;
6954: mkdir($path,02770);
6955: }
6956: }
6957: my $versionresult;
6958: if (-e $copyfile) {
6959: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6960: } else {
6961: $versionresult = 'ok';
6962: }
6963: if ($versionresult eq 'ok') {
6964: if (copy($source,$copyfile)) {
6965: print $logfile "\nCopied original source to ".$copyfile."\n";
6966: $output = 'ok';
6967: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6968: push(@{$modified_urls},[$copyfile,$source]);
6969: my $metaoutput =
6970: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6971: unless ($registered_cleanup) {
6972: my $handlers = $r->get_handlers('PerlCleanupHandler');
6973: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6974: $registered_cleanup=1;
6975: }
1.9 raeburn 6976: } else {
6977: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6978: $output = &mt('Failed to copy file to RES space').", $!";
6979: }
6980: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6981: my $inputfile = $filepath.'/'.$file;
6982: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6983: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6984: if ($fullwidth ne '' && $fullheight ne '') {
6985: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6986: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6987: system("convert -sample $thumbsize $inputfile $outfile");
6988: chmod(0660, $filepath.'/tn-'.$file);
6989: if (-e $outfile) {
6990: my $copyfile=$targetdir.'/tn-'.$file;
6991: if (copy($outfile,$copyfile)) {
6992: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6993: my $thumb_metaoutput =
6994: &write_metadata($dom,$confname,$formname,
6995: $targetdir,'tn-'.$file,$logfile);
6996: push(@{$modified_urls},[$copyfile,$outfile]);
6997: unless ($registered_cleanup) {
6998: my $handlers = $r->get_handlers('PerlCleanupHandler');
6999: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7000: $registered_cleanup=1;
7001: }
1.16 raeburn 7002: } else {
7003: print $logfile "\nUnable to write ".$copyfile.
7004: ':'.$!."\n";
7005: }
7006: }
1.9 raeburn 7007: }
7008: }
7009: }
7010: } else {
7011: $output = $versionresult;
7012: }
7013: }
7014: return ($output,$logourl);
7015: }
7016:
7017: sub logo_versioning {
7018: my ($targetdir,$file,$logfile) = @_;
7019: my $target = $targetdir.'/'.$file;
7020: my ($maxversion,$fn,$extn,$output);
7021: $maxversion = 0;
7022: if ($file =~ /^(.+)\.(\w+)$/) {
7023: $fn=$1;
7024: $extn=$2;
7025: }
7026: opendir(DIR,$targetdir);
7027: while (my $filename=readdir(DIR)) {
7028: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7029: $maxversion=($1>$maxversion)?$1:$maxversion;
7030: }
7031: }
7032: $maxversion++;
7033: print $logfile "\nCreating old version ".$maxversion."\n";
7034: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7035: if (copy($target,$copyfile)) {
7036: print $logfile "Copied old target to ".$copyfile."\n";
7037: $copyfile=$copyfile.'.meta';
7038: if (copy($target.'.meta',$copyfile)) {
7039: print $logfile "Copied old target metadata to ".$copyfile."\n";
7040: $output = 'ok';
7041: } else {
7042: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7043: $output = &mt('Failed to copy old meta').", $!, ";
7044: }
7045: } else {
7046: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7047: $output = &mt('Failed to copy old target').", $!, ";
7048: }
7049: return $output;
7050: }
7051:
7052: sub write_metadata {
7053: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7054: my (%metadatafields,%metadatakeys,$output);
7055: $metadatafields{'title'}=$formname;
7056: $metadatafields{'creationdate'}=time;
7057: $metadatafields{'lastrevisiondate'}=time;
7058: $metadatafields{'copyright'}='public';
7059: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7060: $env{'user.domain'};
7061: $metadatafields{'authorspace'}=$confname.':'.$dom;
7062: $metadatafields{'domain'}=$dom;
7063: {
7064: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7065: my $mfh;
1.155 raeburn 7066: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7067: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7068: unless ($_=~/\./) {
7069: my $unikey=$_;
7070: $unikey=~/^([A-Za-z]+)/;
7071: my $tag=$1;
7072: $tag=~tr/A-Z/a-z/;
7073: print $mfh "\n\<$tag";
7074: foreach (split(/\,/,$metadatakeys{$unikey})) {
7075: my $value=$metadatafields{$unikey.'.'.$_};
7076: $value=~s/\"/\'\'/g;
7077: print $mfh ' '.$_.'="'.$value.'"';
7078: }
7079: print $mfh '>'.
7080: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7081: .'</'.$tag.'>';
7082: }
7083: }
7084: $output = 'ok';
7085: print $logfile "\nWrote metadata";
7086: close($mfh);
7087: } else {
7088: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7089: $output = &mt('Could not write metadata');
7090: }
7091: }
1.155 raeburn 7092: return $output;
7093: }
7094:
7095: sub notifysubscribed {
7096: foreach my $targetsource (@{$modified_urls}){
7097: next unless (ref($targetsource) eq 'ARRAY');
7098: my ($target,$source)=@{$targetsource};
7099: if ($source ne '') {
7100: if (open(my $logfh,'>>'.$source.'.log')) {
7101: print $logfh "\nCleanup phase: Notifications\n";
7102: my @subscribed=&subscribed_hosts($target);
7103: foreach my $subhost (@subscribed) {
7104: print $logfh "\nNotifying host ".$subhost.':';
7105: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7106: print $logfh $reply;
7107: }
7108: my @subscribedmeta=&subscribed_hosts("$target.meta");
7109: foreach my $subhost (@subscribedmeta) {
7110: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7111: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7112: $subhost);
7113: print $logfh $reply;
7114: }
7115: print $logfh "\n============ Done ============\n";
1.160 raeburn 7116: close($logfh);
1.155 raeburn 7117: }
7118: }
7119: }
7120: return OK;
7121: }
7122:
7123: sub subscribed_hosts {
7124: my ($target) = @_;
7125: my @subscribed;
7126: if (open(my $fh,"<$target.subscription")) {
7127: while (my $subline=<$fh>) {
7128: if ($subline =~ /^($match_lonid):/) {
7129: my $host = $1;
7130: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7131: unless (grep(/^\Q$host\E$/,@subscribed)) {
7132: push(@subscribed,$host);
7133: }
7134: }
7135: }
7136: }
7137: }
7138: return @subscribed;
1.9 raeburn 7139: }
7140:
7141: sub check_switchserver {
7142: my ($dom,$confname) = @_;
7143: my ($allowed,$switchserver);
7144: my $home = &Apache::lonnet::homeserver($confname,$dom);
7145: if ($home eq 'no_host') {
7146: $home = &Apache::lonnet::domain($dom,'primary');
7147: }
7148: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7149: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7150: if (!$allowed) {
1.160.6.11 raeburn 7151: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7152: }
7153: return $switchserver;
7154: }
7155:
1.1 raeburn 7156: sub modify_quotas {
1.160.6.30 raeburn 7157: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7158: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7159: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7160: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7161: $validationfieldsref);
1.86 raeburn 7162: if ($action eq 'quotas') {
7163: $context = 'tools';
1.160.6.26 raeburn 7164: } else {
1.86 raeburn 7165: $context = $action;
7166: }
7167: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7168: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7169: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7170: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7171: %titles = &courserequest_titles();
7172: $toolregexp = join('|',@usertools);
7173: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7174: $confname = $dom.'-domainconfig';
7175: my $servadm = $r->dir_config('lonAdmEMail');
7176: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7177: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7178: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7179: } elsif ($context eq 'requestauthor') {
7180: @usertools = ('author');
7181: %titles = &authorrequest_titles();
1.86 raeburn 7182: } else {
1.160.6.4 raeburn 7183: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7184: %titles = &tool_titles();
1.86 raeburn 7185: }
1.160.6.27 raeburn 7186: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7187: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7188: foreach my $key (keys(%env)) {
1.101 raeburn 7189: if ($context eq 'requestcourses') {
7190: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7191: my $item = $1;
7192: my $type = $2;
7193: if ($type =~ /^limit_(.+)/) {
7194: $limithash{$item}{$1} = $env{$key};
7195: } else {
7196: $confhash{$item}{$type} = $env{$key};
7197: }
7198: }
1.160.6.5 raeburn 7199: } elsif ($context eq 'requestauthor') {
7200: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7201: $confhash{$1} = $env{$key};
7202: }
1.101 raeburn 7203: } else {
1.86 raeburn 7204: if ($key =~ /^form\.quota_(.+)$/) {
7205: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7206: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7207: $confhash{'authorquota'}{$1} = $env{$key};
7208: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7209: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7210: }
1.72 raeburn 7211: }
7212: }
1.160.6.5 raeburn 7213: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7214: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7215: @approvalnotify = sort(@approvalnotify);
7216: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7217: my @crstypes = ('official','unofficial','community','textbook');
7218: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7219: foreach my $type (@hasuniquecode) {
7220: if (grep(/^\Q$type\E$/,@crstypes)) {
7221: $confhash{'uniquecode'}{$type} = 1;
7222: }
7223: }
1.160.6.46 raeburn 7224: my (%newbook,%allpos);
1.160.6.30 raeburn 7225: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7226: foreach my $type ('textbooks','templates') {
7227: @{$allpos{$type}} = ();
7228: my $invalid;
7229: if ($type eq 'textbooks') {
7230: $invalid = &mt('Invalid LON-CAPA course for textbook');
7231: } else {
7232: $invalid = &mt('Invalid LON-CAPA course for template');
7233: }
7234: if ($env{'form.'.$type.'_addbook'}) {
7235: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7236: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7237: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7238: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7239: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7240: } else {
7241: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7242: my $position = $env{'form.'.$type.'_addbook_pos'};
7243: $position =~ s/\D+//g;
7244: if ($position ne '') {
7245: $allpos{$type}[$position] = $newbook{$type};
7246: }
1.160.6.30 raeburn 7247: }
1.160.6.46 raeburn 7248: } else {
7249: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7250: }
7251: }
1.160.6.46 raeburn 7252: }
1.160.6.30 raeburn 7253: }
1.102 raeburn 7254: if (ref($domconfig{$action}) eq 'HASH') {
7255: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7256: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7257: $changes{'notify'}{'approval'} = 1;
7258: }
7259: } else {
1.144 raeburn 7260: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7261: $changes{'notify'}{'approval'} = 1;
7262: }
7263: }
1.160.6.30 raeburn 7264: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7265: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7266: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7267: unless ($confhash{'uniquecode'}{$crstype}) {
7268: $changes{'uniquecode'} = 1;
7269: }
7270: }
7271: unless ($changes{'uniquecode'}) {
7272: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7273: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7274: $changes{'uniquecode'} = 1;
7275: }
7276: }
7277: }
7278: } else {
7279: $changes{'uniquecode'} = 1;
7280: }
7281: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7282: $changes{'uniquecode'} = 1;
7283: }
7284: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7285: foreach my $type ('textbooks','templates') {
7286: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7287: my %deletions;
7288: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7289: if (@todelete) {
7290: map { $deletions{$_} = 1; } @todelete;
7291: }
7292: my %imgdeletions;
7293: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7294: if (@todeleteimages) {
7295: map { $imgdeletions{$_} = 1; } @todeleteimages;
7296: }
7297: my $maxnum = $env{'form.'.$type.'_maxnum'};
7298: for (my $i=0; $i<=$maxnum; $i++) {
7299: my $itemid = $env{'form.'.$type.'_id_'.$i};
7300: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7301: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7302: if ($deletions{$key}) {
7303: if ($domconfig{$action}{$type}{$key}{'image'}) {
7304: #FIXME need to obsolete item in RES space
7305: }
7306: next;
7307: } else {
7308: my $newpos = $env{'form.'.$itemid};
7309: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7310: foreach my $item ('subject','title','publisher','author') {
7311: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7312: ($type eq 'templates'));
1.160.6.46 raeburn 7313: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7314: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7315: $changes{$type}{$key} = 1;
7316: }
7317: }
7318: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7319: }
1.160.6.46 raeburn 7320: if ($imgdeletions{$key}) {
7321: $changes{$type}{$key} = 1;
7322: #FIXME need to obsolete item in RES space
7323: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7324: my ($cdom,$cnum) = split(/_/,$key);
7325: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7326: $cdom,$cnum,$type,$configuserok,
7327: $switchserver,$author_ok);
7328: if ($imgurl) {
7329: $confhash{$type}{$key}{'image'} = $imgurl;
7330: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7331: }
1.160.6.46 raeburn 7332: if ($error) {
7333: &Apache::lonnet::logthis($error);
7334: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7335: }
7336: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7337: $confhash{$type}{$key}{'image'} =
7338: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7339: }
7340: }
7341: }
7342: }
7343: }
7344: }
1.102 raeburn 7345: } else {
1.144 raeburn 7346: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7347: $changes{'notify'}{'approval'} = 1;
7348: }
1.160.6.30 raeburn 7349: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7350: $changes{'uniquecode'} = 1;
7351: }
7352: }
7353: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7354: foreach my $type ('textbooks','templates') {
7355: if ($newbook{$type}) {
7356: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7357: foreach my $item ('subject','title','publisher','author') {
7358: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7359: ($type eq 'template'));
1.160.6.46 raeburn 7360: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7361: if ($env{'form.'.$type.'_addbook_'.$item}) {
7362: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7363: }
7364: }
7365: if ($type eq 'textbooks') {
7366: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7367: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7368: my ($imageurl,$error) =
7369: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7370: $configuserok,$switchserver,$author_ok);
7371: if ($imageurl) {
7372: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7373: }
7374: if ($error) {
7375: &Apache::lonnet::logthis($error);
7376: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7377: }
7378: }
1.160.6.30 raeburn 7379: }
7380: }
1.160.6.46 raeburn 7381: if (@{$allpos{$type}} > 0) {
7382: my $idx = 0;
7383: foreach my $item (@{$allpos{$type}}) {
7384: if ($item ne '') {
7385: $confhash{$type}{$item}{'order'} = $idx;
7386: if (ref($domconfig{$action}) eq 'HASH') {
7387: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7388: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7389: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7390: $changes{$type}{$item} = 1;
7391: }
1.160.6.30 raeburn 7392: }
7393: }
7394: }
1.160.6.46 raeburn 7395: $idx ++;
1.160.6.30 raeburn 7396: }
7397: }
7398: }
7399: }
1.160.6.39 raeburn 7400: if (ref($validationitemsref) eq 'ARRAY') {
7401: foreach my $item (@{$validationitemsref}) {
7402: if ($item eq 'fields') {
7403: my @changed;
7404: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7405: if (@{$confhash{'validation'}{$item}} > 0) {
7406: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7407: }
1.160.6.65 raeburn 7408: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7409: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7410: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7411: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7412: $domconfig{'requestcourses'}{'validation'}{$item});
7413: } else {
7414: @changed = @{$confhash{'validation'}{$item}};
7415: }
1.160.6.39 raeburn 7416: } else {
7417: @changed = @{$confhash{'validation'}{$item}};
7418: }
7419: } else {
7420: @changed = @{$confhash{'validation'}{$item}};
7421: }
7422: if (@changed) {
7423: if ($confhash{'validation'}{$item}) {
7424: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7425: } else {
7426: $changes{'validation'}{$item} = &mt('None');
7427: }
7428: }
7429: } else {
7430: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7431: if ($item eq 'markup') {
7432: if ($env{'form.requestcourses_validation_'.$item}) {
7433: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7434: }
7435: }
1.160.6.65 raeburn 7436: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7437: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7438: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7439: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7440: }
7441: } else {
7442: if ($confhash{'validation'}{$item} ne '') {
7443: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7444: }
1.160.6.39 raeburn 7445: }
7446: } else {
7447: if ($confhash{'validation'}{$item} ne '') {
7448: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7449: }
7450: }
7451: }
7452: }
7453: }
7454: if ($env{'form.validationdc'}) {
7455: my $newval = $env{'form.validationdc'};
7456: my %domcoords = &get_active_dcs($dom);
7457: if (exists($domcoords{$newval})) {
7458: $confhash{'validation'}{'dc'} = $newval;
7459: }
7460: }
7461: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 7462: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7463: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7464: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7465: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7466: if ($confhash{'validation'}{'dc'} eq '') {
7467: $changes{'validation'}{'dc'} = &mt('None');
7468: } else {
7469: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7470: }
1.160.6.39 raeburn 7471: }
1.160.6.65 raeburn 7472: } elsif ($confhash{'validation'}{'dc'} ne '') {
7473: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 7474: }
7475: } elsif ($confhash{'validation'}{'dc'} ne '') {
7476: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7477: }
7478: } elsif ($confhash{'validation'}{'dc'} ne '') {
7479: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7480: }
1.160.6.65 raeburn 7481: } else {
7482: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7483: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7484: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7485: $changes{'validation'}{'dc'} = &mt('None');
7486: }
7487: }
1.160.6.39 raeburn 7488: }
7489: }
1.102 raeburn 7490: }
7491: } else {
1.86 raeburn 7492: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7493: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7494: }
1.72 raeburn 7495: foreach my $item (@usertools) {
7496: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7497: my $unset;
1.101 raeburn 7498: if ($context eq 'requestcourses') {
1.104 raeburn 7499: $unset = '0';
7500: if ($type eq '_LC_adv') {
7501: $unset = '';
7502: }
1.101 raeburn 7503: if ($confhash{$item}{$type} eq 'autolimit') {
7504: $confhash{$item}{$type} .= '=';
7505: unless ($limithash{$item}{$type} =~ /\D/) {
7506: $confhash{$item}{$type} .= $limithash{$item}{$type};
7507: }
7508: }
1.160.6.5 raeburn 7509: } elsif ($context eq 'requestauthor') {
7510: $unset = '0';
7511: if ($type eq '_LC_adv') {
7512: $unset = '';
7513: }
1.72 raeburn 7514: } else {
1.101 raeburn 7515: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7516: $confhash{$item}{$type} = 1;
7517: } else {
7518: $confhash{$item}{$type} = 0;
7519: }
1.72 raeburn 7520: }
1.86 raeburn 7521: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7522: if ($action eq 'requestauthor') {
7523: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7524: $changes{$type} = 1;
7525: }
7526: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7527: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7528: $changes{$item}{$type} = 1;
7529: }
7530: } else {
7531: if ($context eq 'requestcourses') {
1.104 raeburn 7532: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7533: $changes{$item}{$type} = 1;
7534: }
7535: } else {
7536: if (!$confhash{$item}{$type}) {
7537: $changes{$item}{$type} = 1;
7538: }
7539: }
7540: }
7541: } else {
7542: if ($context eq 'requestcourses') {
1.104 raeburn 7543: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7544: $changes{$item}{$type} = 1;
7545: }
1.160.6.5 raeburn 7546: } elsif ($context eq 'requestauthor') {
7547: if ($confhash{$type} ne $unset) {
7548: $changes{$type} = 1;
7549: }
1.72 raeburn 7550: } else {
7551: if (!$confhash{$item}{$type}) {
7552: $changes{$item}{$type} = 1;
7553: }
7554: }
7555: }
1.1 raeburn 7556: }
7557: }
1.160.6.5 raeburn 7558: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7559: if (ref($domconfig{'quotas'}) eq 'HASH') {
7560: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7561: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7562: if (exists($confhash{'defaultquota'}{$key})) {
7563: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7564: $changes{'defaultquota'}{$key} = 1;
7565: }
7566: } else {
7567: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7568: }
7569: }
1.86 raeburn 7570: } else {
7571: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7572: if (exists($confhash{'defaultquota'}{$key})) {
7573: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7574: $changes{'defaultquota'}{$key} = 1;
7575: }
7576: } else {
7577: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7578: }
1.1 raeburn 7579: }
7580: }
1.160.6.20 raeburn 7581: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7582: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7583: if (exists($confhash{'authorquota'}{$key})) {
7584: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7585: $changes{'authorquota'}{$key} = 1;
7586: }
7587: } else {
7588: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7589: }
7590: }
7591: }
1.1 raeburn 7592: }
1.86 raeburn 7593: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7594: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7595: if (ref($domconfig{'quotas'}) eq 'HASH') {
7596: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7597: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7598: $changes{'defaultquota'}{$key} = 1;
7599: }
7600: } else {
7601: if (!exists($domconfig{'quotas'}{$key})) {
7602: $changes{'defaultquota'}{$key} = 1;
7603: }
1.72 raeburn 7604: }
7605: } else {
1.86 raeburn 7606: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7607: }
1.1 raeburn 7608: }
7609: }
1.160.6.20 raeburn 7610: if (ref($confhash{'authorquota'}) eq 'HASH') {
7611: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7612: if (ref($domconfig{'quotas'}) eq 'HASH') {
7613: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7614: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7615: $changes{'authorquota'}{$key} = 1;
7616: }
7617: } else {
7618: $changes{'authorquota'}{$key} = 1;
7619: }
7620: } else {
7621: $changes{'authorquota'}{$key} = 1;
7622: }
7623: }
7624: }
1.1 raeburn 7625: }
1.72 raeburn 7626:
1.160.6.5 raeburn 7627: if ($context eq 'requestauthor') {
7628: $domdefaults{'requestauthor'} = \%confhash;
7629: } else {
7630: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7631: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7632: $domdefaults{$key} = $confhash{$key};
7633: }
1.160.6.5 raeburn 7634: }
1.72 raeburn 7635: }
1.160.6.5 raeburn 7636:
1.1 raeburn 7637: my %quotahash = (
1.86 raeburn 7638: $action => { %confhash }
1.1 raeburn 7639: );
7640: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7641: $dom);
7642: if ($putresult eq 'ok') {
7643: if (keys(%changes) > 0) {
1.72 raeburn 7644: my $cachetime = 24*60*60;
7645: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7646: if (ref($lastactref) eq 'HASH') {
7647: $lastactref->{'domdefaults'} = 1;
7648: }
1.1 raeburn 7649: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7650: unless (($context eq 'requestcourses') ||
7651: ($context eq 'requestauthor')) {
1.86 raeburn 7652: if (ref($changes{'defaultquota'}) eq 'HASH') {
7653: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7654: foreach my $type (@{$types},'default') {
7655: if (defined($changes{'defaultquota'}{$type})) {
7656: my $typetitle = $usertypes->{$type};
7657: if ($type eq 'default') {
7658: $typetitle = $othertitle;
7659: }
1.160.6.28 raeburn 7660: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7661: }
7662: }
1.86 raeburn 7663: $resulttext .= '</ul></li>';
1.72 raeburn 7664: }
1.160.6.20 raeburn 7665: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7666: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7667: foreach my $type (@{$types},'default') {
7668: if (defined($changes{'authorquota'}{$type})) {
7669: my $typetitle = $usertypes->{$type};
7670: if ($type eq 'default') {
7671: $typetitle = $othertitle;
7672: }
1.160.6.28 raeburn 7673: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7674: }
7675: }
7676: $resulttext .= '</ul></li>';
7677: }
1.72 raeburn 7678: }
1.80 raeburn 7679: my %newenv;
1.72 raeburn 7680: foreach my $item (@usertools) {
1.160.6.5 raeburn 7681: my (%haschgs,%inconf);
7682: if ($context eq 'requestauthor') {
7683: %haschgs = %changes;
7684: %inconf = %confhash;
7685: } else {
7686: if (ref($changes{$item}) eq 'HASH') {
7687: %haschgs = %{$changes{$item}};
7688: }
7689: if (ref($confhash{$item}) eq 'HASH') {
7690: %inconf = %{$confhash{$item}};
7691: }
7692: }
7693: if (keys(%haschgs) > 0) {
1.80 raeburn 7694: my $newacc =
7695: &Apache::lonnet::usertools_access($env{'user.name'},
7696: $env{'user.domain'},
1.86 raeburn 7697: $item,'reload',$context);
1.160.6.5 raeburn 7698: if (($context eq 'requestcourses') ||
7699: ($context eq 'requestauthor')) {
1.108 raeburn 7700: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7701: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7702: }
7703: } else {
7704: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7705: $newenv{'environment.availabletools.'.$item} = $newacc;
7706: }
1.80 raeburn 7707: }
1.160.6.5 raeburn 7708: unless ($context eq 'requestauthor') {
7709: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7710: }
1.72 raeburn 7711: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7712: if ($haschgs{$type}) {
1.72 raeburn 7713: my $typetitle = $usertypes->{$type};
7714: if ($type eq 'default') {
7715: $typetitle = $othertitle;
7716: } elsif ($type eq '_LC_adv') {
7717: $typetitle = 'LON-CAPA Advanced Users';
7718: }
1.160.6.5 raeburn 7719: if ($inconf{$type}) {
1.101 raeburn 7720: if ($context eq 'requestcourses') {
7721: my $cond;
1.160.6.5 raeburn 7722: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7723: if ($1 eq '') {
7724: $cond = &mt('(Automatic processing of any request).');
7725: } else {
7726: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7727: }
7728: } else {
1.160.6.5 raeburn 7729: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7730: }
7731: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7732: } elsif ($context eq 'requestauthor') {
7733: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7734: $titles{$inconf{$type}},$typetitle);
7735:
1.101 raeburn 7736: } else {
7737: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7738: }
1.72 raeburn 7739: } else {
1.104 raeburn 7740: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7741: if ($inconf{$type} eq '0') {
1.104 raeburn 7742: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7743: } else {
7744: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7745: }
7746: } else {
7747: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7748: }
1.72 raeburn 7749: }
7750: }
1.26 raeburn 7751: }
1.160.6.5 raeburn 7752: unless ($context eq 'requestauthor') {
7753: $resulttext .= '</ul></li>';
7754: }
1.26 raeburn 7755: }
1.1 raeburn 7756: }
1.160.6.5 raeburn 7757: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7758: if (ref($changes{'notify'}) eq 'HASH') {
7759: if ($changes{'notify'}{'approval'}) {
7760: if (ref($confhash{'notify'}) eq 'HASH') {
7761: if ($confhash{'notify'}{'approval'}) {
7762: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7763: } else {
1.160.6.5 raeburn 7764: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7765: }
7766: }
7767: }
7768: }
7769: }
1.160.6.30 raeburn 7770: if ($action eq 'requestcourses') {
7771: my @offon = ('off','on');
7772: if ($changes{'uniquecode'}) {
7773: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7774: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7775: $resulttext .= '<li>'.
7776: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7777: '</li>';
7778: } else {
7779: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7780: '</li>';
7781: }
7782: }
1.160.6.46 raeburn 7783: foreach my $type ('textbooks','templates') {
7784: if (ref($changes{$type}) eq 'HASH') {
7785: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7786: foreach my $key (sort(keys(%{$changes{$type}}))) {
7787: my %coursehash = &Apache::lonnet::coursedescription($key);
7788: my $coursetitle = $coursehash{'description'};
7789: my $position = $confhash{$type}{$key}{'order'} + 1;
7790: $resulttext .= '<li>';
1.160.6.47 raeburn 7791: foreach my $item ('subject','title','publisher','author') {
7792: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7793: ($type eq 'templates'));
1.160.6.46 raeburn 7794: my $name = $item.':';
7795: $name =~ s/^(\w)/\U$1/;
7796: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7797: }
7798: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7799: if ($type eq 'textbooks') {
7800: if ($confhash{$type}{$key}{'image'}) {
7801: $resulttext .= ' '.&mt('Image: [_1]',
7802: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7803: ' alt="Textbook cover" />').'<br />';
7804: }
7805: }
7806: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7807: }
1.160.6.46 raeburn 7808: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7809: }
7810: }
1.160.6.39 raeburn 7811: if (ref($changes{'validation'}) eq 'HASH') {
7812: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7813: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7814: foreach my $item (@{$validationitemsref}) {
7815: if (exists($changes{'validation'}{$item})) {
7816: if ($item eq 'markup') {
7817: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7818: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7819: } else {
7820: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7821: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7822: }
7823: }
7824: }
7825: if (exists($changes{'validation'}{'dc'})) {
7826: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7827: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7828: }
7829: }
7830: }
1.160.6.30 raeburn 7831: }
1.1 raeburn 7832: $resulttext .= '</ul>';
1.80 raeburn 7833: if (keys(%newenv)) {
7834: &Apache::lonnet::appenv(\%newenv);
7835: }
1.1 raeburn 7836: } else {
1.86 raeburn 7837: if ($context eq 'requestcourses') {
7838: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7839: } elsif ($context eq 'requestauthor') {
7840: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7841: } else {
1.90 weissno 7842: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7843: }
1.1 raeburn 7844: }
7845: } else {
1.11 albertel 7846: $resulttext = '<span class="LC_error">'.
7847: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7848: }
1.160.6.30 raeburn 7849: if ($errors) {
7850: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7851: '<ul>'.$errors.'</ul></p>';
7852: }
1.3 raeburn 7853: return $resulttext;
1.1 raeburn 7854: }
7855:
1.160.6.30 raeburn 7856: sub process_textbook_image {
1.160.6.46 raeburn 7857: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7858: my $filename = $env{'form.'.$caller.'.filename'};
7859: my ($error,$url);
7860: my ($width,$height) = (50,50);
7861: if ($configuserok eq 'ok') {
7862: if ($switchserver) {
7863: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7864: $switchserver);
7865: } elsif ($author_ok eq 'ok') {
7866: my ($result,$imageurl) =
7867: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7868: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7869: if ($result eq 'ok') {
7870: $url = $imageurl;
7871: } else {
7872: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7873: }
7874: } else {
7875: $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);
7876: }
7877: } else {
7878: $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);
7879: }
7880: return ($url,$error);
7881: }
7882:
1.3 raeburn 7883: sub modify_autoenroll {
1.160.6.24 raeburn 7884: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7885: my ($resulttext,%changes);
7886: my %currautoenroll;
7887: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7888: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7889: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7890: }
7891: }
7892: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7893: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7894: sender => 'Sender for notification messages',
1.160.6.68! raeburn 7895: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
! 7896: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 7897: my @offon = ('off','on');
1.17 raeburn 7898: my $sender_uname = $env{'form.sender_uname'};
7899: my $sender_domain = $env{'form.sender_domain'};
7900: if ($sender_domain eq '') {
7901: $sender_uname = '';
7902: } elsif ($sender_uname eq '') {
7903: $sender_domain = '';
7904: }
1.129 raeburn 7905: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68! raeburn 7906: my $failsafe = $env{'form.autoenroll_failsafe'};
! 7907: $failsafe =~ s{^\s+|\s+$}{}g;
! 7908: if ($failsafe =~ /\D/) {
! 7909: undef($failsafe);
! 7910: }
1.1 raeburn 7911: my %autoenrollhash = (
1.129 raeburn 7912: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7913: 'sender_uname' => $sender_uname,
7914: 'sender_domain' => $sender_domain,
7915: 'co-owners' => $coowners,
1.160.6.68! raeburn 7916: 'autofailsafe' => $failsafe,
1.1 raeburn 7917: }
7918: );
1.4 raeburn 7919: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7920: $dom);
1.1 raeburn 7921: if ($putresult eq 'ok') {
7922: if (exists($currautoenroll{'run'})) {
7923: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7924: $changes{'run'} = 1;
7925: }
7926: } elsif ($autorun) {
7927: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7928: $changes{'run'} = 1;
1.1 raeburn 7929: }
7930: }
1.17 raeburn 7931: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7932: $changes{'sender'} = 1;
7933: }
1.17 raeburn 7934: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7935: $changes{'sender'} = 1;
7936: }
1.129 raeburn 7937: if ($currautoenroll{'co-owners'} ne '') {
7938: if ($currautoenroll{'co-owners'} ne $coowners) {
7939: $changes{'coowners'} = 1;
7940: }
7941: } elsif ($coowners) {
7942: $changes{'coowners'} = 1;
1.160.6.68! raeburn 7943: }
! 7944: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
! 7945: $changes{'autofailsafe'} = 1;
! 7946: }
1.1 raeburn 7947: if (keys(%changes) > 0) {
7948: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7949: if ($changes{'run'}) {
1.1 raeburn 7950: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7951: }
7952: if ($changes{'sender'}) {
1.17 raeburn 7953: if ($sender_uname eq '' || $sender_domain eq '') {
7954: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7955: } else {
7956: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7957: }
1.1 raeburn 7958: }
1.129 raeburn 7959: if ($changes{'coowners'}) {
7960: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7961: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7962: if (ref($lastactref) eq 'HASH') {
7963: $lastactref->{'domainconfig'} = 1;
7964: }
1.129 raeburn 7965: }
1.160.6.68! raeburn 7966: if ($changes{'autofailsafe'}) {
! 7967: if ($failsafe ne '') {
! 7968: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
! 7969: } else {
! 7970: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
! 7971: }
! 7972: &Apache::lonnet::get_domain_defaults($dom,1);
! 7973: if (ref($lastactref) eq 'HASH') {
! 7974: $lastactref->{'domdefaults'} = 1;
! 7975: }
! 7976: }
1.1 raeburn 7977: $resulttext .= '</ul>';
7978: } else {
7979: $resulttext = &mt('No changes made to auto-enrollment settings');
7980: }
7981: } else {
1.11 albertel 7982: $resulttext = '<span class="LC_error">'.
7983: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7984: }
1.3 raeburn 7985: return $resulttext;
1.1 raeburn 7986: }
7987:
7988: sub modify_autoupdate {
1.3 raeburn 7989: my ($dom,%domconfig) = @_;
1.1 raeburn 7990: my ($resulttext,%currautoupdate,%fields,%changes);
7991: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7992: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7993: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7994: }
7995: }
7996: my @offon = ('off','on');
7997: my %title = &Apache::lonlocal::texthash (
7998: run => 'Auto-update:',
7999: classlists => 'Updates to user information in classlists?'
8000: );
1.44 raeburn 8001: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8002: my %fieldtitles = &Apache::lonlocal::texthash (
8003: id => 'Student/Employee ID',
1.20 raeburn 8004: permanentemail => 'E-mail address',
1.1 raeburn 8005: lastname => 'Last Name',
8006: firstname => 'First Name',
8007: middlename => 'Middle Name',
1.132 raeburn 8008: generation => 'Generation',
1.1 raeburn 8009: );
1.142 raeburn 8010: $othertitle = &mt('All users');
1.1 raeburn 8011: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8012: $othertitle = &mt('Other users');
1.1 raeburn 8013: }
8014: foreach my $key (keys(%env)) {
8015: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8016: my ($usertype,$item) = ($1,$2);
8017: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8018: if ($usertype eq 'default') {
8019: push(@{$fields{$1}},$2);
8020: } elsif (ref($types) eq 'ARRAY') {
8021: if (grep(/^\Q$usertype\E$/,@{$types})) {
8022: push(@{$fields{$1}},$2);
8023: }
8024: }
8025: }
1.1 raeburn 8026: }
8027: }
1.131 raeburn 8028: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8029: @lockablenames = sort(@lockablenames);
8030: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8031: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8032: if (@changed) {
8033: $changes{'lockablenames'} = 1;
8034: }
8035: } else {
8036: if (@lockablenames) {
8037: $changes{'lockablenames'} = 1;
8038: }
8039: }
1.1 raeburn 8040: my %updatehash = (
8041: autoupdate => { run => $env{'form.autoupdate_run'},
8042: classlists => $env{'form.classlists'},
8043: fields => {%fields},
1.131 raeburn 8044: lockablenames => \@lockablenames,
1.1 raeburn 8045: }
8046: );
8047: foreach my $key (keys(%currautoupdate)) {
8048: if (($key eq 'run') || ($key eq 'classlists')) {
8049: if (exists($updatehash{autoupdate}{$key})) {
8050: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8051: $changes{$key} = 1;
8052: }
8053: }
8054: } elsif ($key eq 'fields') {
8055: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8056: foreach my $item (@{$types},'default') {
1.1 raeburn 8057: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8058: my $change = 0;
8059: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8060: if (!exists($fields{$item})) {
8061: $change = 1;
1.132 raeburn 8062: last;
1.1 raeburn 8063: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8064: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8065: $change = 1;
1.132 raeburn 8066: last;
1.1 raeburn 8067: }
8068: }
8069: }
8070: if ($change) {
8071: push(@{$changes{$key}},$item);
8072: }
1.26 raeburn 8073: }
1.1 raeburn 8074: }
8075: }
1.131 raeburn 8076: } elsif ($key eq 'lockablenames') {
8077: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8078: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8079: if (@changed) {
8080: $changes{'lockablenames'} = 1;
8081: }
8082: } else {
8083: if (@lockablenames) {
8084: $changes{'lockablenames'} = 1;
8085: }
8086: }
8087: }
8088: }
8089: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8090: if (@lockablenames) {
8091: $changes{'lockablenames'} = 1;
1.1 raeburn 8092: }
8093: }
1.26 raeburn 8094: foreach my $item (@{$types},'default') {
8095: if (defined($fields{$item})) {
8096: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8097: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8098: my $change = 0;
8099: if (ref($fields{$item}) eq 'ARRAY') {
8100: foreach my $type (@{$fields{$item}}) {
8101: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8102: $change = 1;
8103: last;
8104: }
8105: }
8106: }
8107: if ($change) {
8108: push(@{$changes{'fields'}},$item);
8109: }
8110: } else {
1.26 raeburn 8111: push(@{$changes{'fields'}},$item);
8112: }
8113: } else {
8114: push(@{$changes{'fields'}},$item);
1.1 raeburn 8115: }
8116: }
8117: }
8118: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8119: $dom);
8120: if ($putresult eq 'ok') {
8121: if (keys(%changes) > 0) {
8122: $resulttext = &mt('Changes made:').'<ul>';
8123: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8124: if ($key eq 'lockablenames') {
8125: $resulttext .= '<li>';
8126: if (@lockablenames) {
8127: $usertypes->{'default'} = $othertitle;
8128: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8129: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8130: } else {
8131: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8132: }
8133: $resulttext .= '</li>';
8134: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8135: foreach my $item (@{$changes{$key}}) {
8136: my @newvalues;
8137: foreach my $type (@{$fields{$item}}) {
8138: push(@newvalues,$fieldtitles{$type});
8139: }
1.3 raeburn 8140: my $newvaluestr;
8141: if (@newvalues > 0) {
8142: $newvaluestr = join(', ',@newvalues);
8143: } else {
8144: $newvaluestr = &mt('none');
1.6 raeburn 8145: }
1.1 raeburn 8146: if ($item eq 'default') {
1.26 raeburn 8147: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8148: } else {
1.26 raeburn 8149: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8150: }
8151: }
8152: } else {
8153: my $newvalue;
8154: if ($key eq 'run') {
8155: $newvalue = $offon[$env{'form.autoupdate_run'}];
8156: } else {
8157: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8158: }
1.1 raeburn 8159: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8160: }
8161: }
8162: $resulttext .= '</ul>';
8163: } else {
1.3 raeburn 8164: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8165: }
8166: } else {
1.11 albertel 8167: $resulttext = '<span class="LC_error">'.
8168: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8169: }
1.3 raeburn 8170: return $resulttext;
1.1 raeburn 8171: }
8172:
1.125 raeburn 8173: sub modify_autocreate {
8174: my ($dom,%domconfig) = @_;
8175: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8176: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8177: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8178: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8179: }
8180: }
8181: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8182: req => 'Auto-creation of validated requests for official courses',
8183: xmldc => 'Identity of course creator of courses from XML files',
8184: );
8185: my @types = ('xml','req');
8186: foreach my $item (@types) {
8187: $newvals{$item} = $env{'form.autocreate_'.$item};
8188: $newvals{$item} =~ s/\D//g;
8189: $newvals{$item} = 0 if ($newvals{$item} eq '');
8190: }
8191: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8192: my %domcoords = &get_active_dcs($dom);
8193: unless (exists($domcoords{$newvals{'xmldc'}})) {
8194: $newvals{'xmldc'} = '';
8195: }
8196: %autocreatehash = (
8197: autocreate => { xml => $newvals{'xml'},
8198: req => $newvals{'req'},
8199: }
8200: );
8201: if ($newvals{'xmldc'} ne '') {
8202: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8203: }
8204: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8205: $dom);
8206: if ($putresult eq 'ok') {
8207: my @items = @types;
8208: if ($newvals{'xml'}) {
8209: push(@items,'xmldc');
8210: }
8211: foreach my $item (@items) {
8212: if (exists($currautocreate{$item})) {
8213: if ($currautocreate{$item} ne $newvals{$item}) {
8214: $changes{$item} = 1;
8215: }
8216: } elsif ($newvals{$item}) {
8217: $changes{$item} = 1;
8218: }
8219: }
8220: if (keys(%changes) > 0) {
8221: my @offon = ('off','on');
8222: $resulttext = &mt('Changes made:').'<ul>';
8223: foreach my $item (@types) {
8224: if ($changes{$item}) {
8225: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8226: $resulttext .= '<li>'.
8227: &mt("$title{$item} set to [_1]$newtxt [_2]",
8228: '<b>','</b>').
8229: '</li>';
1.125 raeburn 8230: }
8231: }
8232: if ($changes{'xmldc'}) {
8233: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8234: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8235: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8236: }
8237: $resulttext .= '</ul>';
8238: } else {
8239: $resulttext = &mt('No changes made to auto-creation settings');
8240: }
8241: } else {
8242: $resulttext = '<span class="LC_error">'.
8243: &mt('An error occurred: [_1]',$putresult).'</span>';
8244: }
8245: return $resulttext;
8246: }
8247:
1.23 raeburn 8248: sub modify_directorysrch {
8249: my ($dom,%domconfig) = @_;
8250: my ($resulttext,%changes);
8251: my %currdirsrch;
8252: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8253: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8254: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8255: }
8256: }
8257: my %title = ( available => 'Directory search available',
1.24 raeburn 8258: localonly => 'Other domains can search',
1.23 raeburn 8259: searchby => 'Search types',
8260: searchtypes => 'Search latitude');
8261: my @offon = ('off','on');
1.24 raeburn 8262: my @otherdoms = ('Yes','No');
1.23 raeburn 8263:
1.25 raeburn 8264: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8265: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8266: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8267:
1.44 raeburn 8268: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8269: if (keys(%{$usertypes}) == 0) {
8270: @cansearch = ('default');
8271: } else {
8272: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8273: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8274: if (!grep(/^\Q$type\E$/,@cansearch)) {
8275: push(@{$changes{'cansearch'}},$type);
8276: }
1.23 raeburn 8277: }
1.26 raeburn 8278: foreach my $type (@cansearch) {
8279: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8280: push(@{$changes{'cansearch'}},$type);
8281: }
1.23 raeburn 8282: }
1.26 raeburn 8283: } else {
8284: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8285: }
8286: }
8287:
8288: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8289: foreach my $by (@{$currdirsrch{'searchby'}}) {
8290: if (!grep(/^\Q$by\E$/,@searchby)) {
8291: push(@{$changes{'searchby'}},$by);
8292: }
8293: }
8294: foreach my $by (@searchby) {
8295: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8296: push(@{$changes{'searchby'}},$by);
8297: }
8298: }
8299: } else {
8300: push(@{$changes{'searchby'}},@searchby);
8301: }
1.25 raeburn 8302:
8303: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8304: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8305: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8306: push(@{$changes{'searchtypes'}},$type);
8307: }
8308: }
8309: foreach my $type (@searchtypes) {
8310: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8311: push(@{$changes{'searchtypes'}},$type);
8312: }
8313: }
8314: } else {
8315: if (exists($currdirsrch{'searchtypes'})) {
8316: foreach my $type (@searchtypes) {
8317: if ($type ne $currdirsrch{'searchtypes'}) {
8318: push(@{$changes{'searchtypes'}},$type);
8319: }
8320: }
8321: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8322: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8323: }
8324: } else {
8325: push(@{$changes{'searchtypes'}},@searchtypes);
8326: }
8327: }
8328:
1.23 raeburn 8329: my %dirsrch_hash = (
8330: directorysrch => { available => $env{'form.dirsrch_available'},
8331: cansearch => \@cansearch,
1.24 raeburn 8332: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8333: searchby => \@searchby,
1.25 raeburn 8334: searchtypes => \@searchtypes,
1.23 raeburn 8335: }
8336: );
8337: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8338: $dom);
8339: if ($putresult eq 'ok') {
8340: if (exists($currdirsrch{'available'})) {
8341: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8342: $changes{'available'} = 1;
8343: }
8344: } else {
8345: if ($env{'form.dirsrch_available'} eq '1') {
8346: $changes{'available'} = 1;
8347: }
8348: }
1.24 raeburn 8349: if (exists($currdirsrch{'localonly'})) {
8350: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8351: $changes{'localonly'} = 1;
8352: }
8353: } else {
8354: if ($env{'form.dirsrch_localonly'} eq '1') {
8355: $changes{'localonly'} = 1;
8356: }
8357: }
1.23 raeburn 8358: if (keys(%changes) > 0) {
8359: $resulttext = &mt('Changes made:').'<ul>';
8360: if ($changes{'available'}) {
8361: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8362: }
1.24 raeburn 8363: if ($changes{'localonly'}) {
8364: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8365: }
8366:
1.23 raeburn 8367: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8368: my $chgtext;
1.26 raeburn 8369: if (ref($usertypes) eq 'HASH') {
8370: if (keys(%{$usertypes}) > 0) {
8371: foreach my $type (@{$types}) {
8372: if (grep(/^\Q$type\E$/,@cansearch)) {
8373: $chgtext .= $usertypes->{$type}.'; ';
8374: }
8375: }
8376: if (grep(/^default$/,@cansearch)) {
8377: $chgtext .= $othertitle;
8378: } else {
8379: $chgtext =~ s/\; $//;
8380: }
1.160.6.13 raeburn 8381: $resulttext .=
8382: '<li>'.
8383: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8384: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8385: '</li>';
1.23 raeburn 8386: }
8387: }
8388: }
8389: if (ref($changes{'searchby'}) eq 'ARRAY') {
8390: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8391: my $chgtext;
8392: foreach my $type (@{$titleorder}) {
8393: if (grep(/^\Q$type\E$/,@searchby)) {
8394: if (defined($searchtitles->{$type})) {
8395: $chgtext .= $searchtitles->{$type}.'; ';
8396: }
8397: }
8398: }
8399: $chgtext =~ s/\; $//;
8400: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8401: }
1.25 raeburn 8402: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8403: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8404: my $chgtext;
8405: foreach my $type (@{$srchtypeorder}) {
8406: if (grep(/^\Q$type\E$/,@searchtypes)) {
8407: if (defined($srchtypes_desc->{$type})) {
8408: $chgtext .= $srchtypes_desc->{$type}.'; ';
8409: }
8410: }
8411: }
8412: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8413: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8414: }
8415: $resulttext .= '</ul>';
8416: } else {
8417: $resulttext = &mt('No changes made to institution directory search settings');
8418: }
8419: } else {
8420: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8421: &mt('An error occurred: [_1]',$putresult).'</span>';
8422: }
8423: return $resulttext;
8424: }
8425:
1.28 raeburn 8426: sub modify_contacts {
1.160.6.24 raeburn 8427: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8428: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8429: if (ref($domconfig{'contacts'}) eq 'HASH') {
8430: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8431: $currsetting{$key} = $domconfig{'contacts'}{$key};
8432: }
8433: }
1.134 raeburn 8434: my (%others,%to,%bcc);
1.28 raeburn 8435: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8436: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8437: 'requestsmail','updatesmail','idconflictsmail');
8438: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8439: foreach my $type (@mailings) {
8440: @{$newsetting{$type}} =
8441: &Apache::loncommon::get_env_multiple('form.'.$type);
8442: foreach my $item (@contacts) {
8443: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8444: $contacts_hash{contacts}{$type}{$item} = 1;
8445: } else {
8446: $contacts_hash{contacts}{$type}{$item} = 0;
8447: }
8448: }
8449: $others{$type} = $env{'form.'.$type.'_others'};
8450: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8451: if ($type eq 'helpdeskmail') {
8452: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8453: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8454: }
1.28 raeburn 8455: }
8456: foreach my $item (@contacts) {
8457: $to{$item} = $env{'form.'.$item};
8458: $contacts_hash{'contacts'}{$item} = $to{$item};
8459: }
1.160.6.23 raeburn 8460: foreach my $item (@toggles) {
8461: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8462: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8463: }
8464: }
1.28 raeburn 8465: if (keys(%currsetting) > 0) {
8466: foreach my $item (@contacts) {
8467: if ($to{$item} ne $currsetting{$item}) {
8468: $changes{$item} = 1;
8469: }
8470: }
8471: foreach my $type (@mailings) {
8472: foreach my $item (@contacts) {
8473: if (ref($currsetting{$type}) eq 'HASH') {
8474: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8475: push(@{$changes{$type}},$item);
8476: }
8477: } else {
8478: push(@{$changes{$type}},@{$newsetting{$type}});
8479: }
8480: }
8481: if ($others{$type} ne $currsetting{$type}{'others'}) {
8482: push(@{$changes{$type}},'others');
8483: }
1.134 raeburn 8484: if ($type eq 'helpdeskmail') {
8485: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8486: push(@{$changes{$type}},'bcc');
8487: }
8488: }
1.28 raeburn 8489: }
8490: } else {
8491: my %default;
8492: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8493: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8494: $default{'errormail'} = 'adminemail';
8495: $default{'packagesmail'} = 'adminemail';
8496: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8497: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8498: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8499: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8500: foreach my $item (@contacts) {
8501: if ($to{$item} ne $default{$item}) {
8502: $changes{$item} = 1;
1.160.6.23 raeburn 8503: }
1.28 raeburn 8504: }
8505: foreach my $type (@mailings) {
8506: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8507:
8508: push(@{$changes{$type}},@{$newsetting{$type}});
8509: }
8510: if ($others{$type} ne '') {
8511: push(@{$changes{$type}},'others');
1.134 raeburn 8512: }
8513: if ($type eq 'helpdeskmail') {
8514: if ($bcc{$type} ne '') {
8515: push(@{$changes{$type}},'bcc');
8516: }
8517: }
1.28 raeburn 8518: }
8519: }
1.160.6.23 raeburn 8520: foreach my $item (@toggles) {
8521: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8522: $changes{$item} = 1;
8523: } elsif ((!$env{'form.'.$item}) &&
8524: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8525: $changes{$item} = 1;
8526: }
8527: }
1.28 raeburn 8528: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8529: $dom);
8530: if ($putresult eq 'ok') {
8531: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8532: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8533: if (ref($lastactref) eq 'HASH') {
8534: $lastactref->{'domainconfig'} = 1;
8535: }
1.28 raeburn 8536: my ($titles,$short_titles) = &contact_titles();
8537: $resulttext = &mt('Changes made:').'<ul>';
8538: foreach my $item (@contacts) {
8539: if ($changes{$item}) {
8540: $resulttext .= '<li>'.$titles->{$item}.
8541: &mt(' set to: ').
8542: '<span class="LC_cusr_emph">'.
8543: $to{$item}.'</span></li>';
8544: }
8545: }
8546: foreach my $type (@mailings) {
8547: if (ref($changes{$type}) eq 'ARRAY') {
8548: $resulttext .= '<li>'.$titles->{$type}.': ';
8549: my @text;
8550: foreach my $item (@{$newsetting{$type}}) {
8551: push(@text,$short_titles->{$item});
8552: }
8553: if ($others{$type} ne '') {
8554: push(@text,$others{$type});
8555: }
8556: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8557: join(', ',@text).'</span>';
8558: if ($type eq 'helpdeskmail') {
8559: if ($bcc{$type} ne '') {
8560: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8561: }
8562: }
8563: $resulttext .= '</li>';
1.28 raeburn 8564: }
8565: }
1.160.6.23 raeburn 8566: my @offon = ('off','on');
8567: if ($changes{'reporterrors'}) {
8568: $resulttext .= '<li>'.
8569: &mt('E-mail error reports to [_1] set to "'.
8570: $offon[$env{'form.reporterrors'}].'".',
8571: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8572: &mt('LON-CAPA core group - MSU'),600,500)).
8573: '</li>';
8574: }
8575: if ($changes{'reportupdates'}) {
8576: $resulttext .= '<li>'.
8577: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8578: $offon[$env{'form.reportupdates'}].'".',
8579: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8580: &mt('LON-CAPA core group - MSU'),600,500)).
8581: '</li>';
8582: }
1.28 raeburn 8583: $resulttext .= '</ul>';
8584: } else {
1.34 raeburn 8585: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8586: }
8587: } else {
8588: $resulttext = '<span class="LC_error">'.
8589: &mt('An error occurred: [_1].',$putresult).'</span>';
8590: }
8591: return $resulttext;
8592: }
8593:
8594: sub modify_usercreation {
1.27 raeburn 8595: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8596: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8597: my $warningmsg;
1.27 raeburn 8598: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8599: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8600: if ($key eq 'cancreate') {
8601: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8602: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8603: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8604: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8605: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8606: } else {
8607: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8608: }
1.50 raeburn 8609: }
1.43 raeburn 8610: }
1.160.6.34 raeburn 8611: } elsif ($key eq 'email_rule') {
8612: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8613: } else {
8614: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8615: }
8616: }
1.34 raeburn 8617: }
1.160.6.34 raeburn 8618: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8619: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8620: my @contexts = ('author','course','requestcrs');
8621: foreach my $item(@contexts) {
8622: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8623: }
1.34 raeburn 8624: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8625: foreach my $item (@contexts) {
1.160.6.34 raeburn 8626: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8627: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8628: }
1.27 raeburn 8629: }
1.34 raeburn 8630: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8631: foreach my $item (@contexts) {
1.43 raeburn 8632: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8633: if ($cancreate{$item} ne 'any') {
8634: push(@{$changes{'cancreate'}},$item);
8635: }
8636: } else {
8637: if ($cancreate{$item} ne 'none') {
8638: push(@{$changes{'cancreate'}},$item);
8639: }
1.27 raeburn 8640: }
8641: }
8642: } else {
1.43 raeburn 8643: foreach my $item (@contexts) {
1.34 raeburn 8644: push(@{$changes{'cancreate'}},$item);
8645: }
1.27 raeburn 8646: }
1.34 raeburn 8647:
1.27 raeburn 8648: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8649: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8650: if (!grep(/^\Q$type\E$/,@username_rule)) {
8651: push(@{$changes{'username_rule'}},$type);
8652: }
8653: }
8654: foreach my $type (@username_rule) {
8655: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8656: push(@{$changes{'username_rule'}},$type);
8657: }
8658: }
8659: } else {
8660: push(@{$changes{'username_rule'}},@username_rule);
8661: }
8662:
1.32 raeburn 8663: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8664: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8665: if (!grep(/^\Q$type\E$/,@id_rule)) {
8666: push(@{$changes{'id_rule'}},$type);
8667: }
8668: }
8669: foreach my $type (@id_rule) {
8670: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8671: push(@{$changes{'id_rule'}},$type);
8672: }
8673: }
8674: } else {
8675: push(@{$changes{'id_rule'}},@id_rule);
8676: }
8677:
1.43 raeburn 8678: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8679: my @authtypes = ('int','krb4','krb5','loc');
8680: my %authhash;
1.43 raeburn 8681: foreach my $item (@authen_contexts) {
1.28 raeburn 8682: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8683: foreach my $auth (@authtypes) {
8684: if (grep(/^\Q$auth\E$/,@authallowed)) {
8685: $authhash{$item}{$auth} = 1;
8686: } else {
8687: $authhash{$item}{$auth} = 0;
8688: }
8689: }
8690: }
8691: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8692: foreach my $item (@authen_contexts) {
1.28 raeburn 8693: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8694: foreach my $auth (@authtypes) {
8695: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8696: push(@{$changes{'authtypes'}},$item);
8697: last;
8698: }
8699: }
8700: }
8701: }
8702: } else {
1.43 raeburn 8703: foreach my $item (@authen_contexts) {
1.28 raeburn 8704: push(@{$changes{'authtypes'}},$item);
8705: }
8706: }
8707:
1.160.6.34 raeburn 8708: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8709: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8710: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8711: $save_usercreate{'id_rule'} = \@id_rule;
8712: $save_usercreate{'username_rule'} = \@username_rule,
8713: $save_usercreate{'authtypes'} = \%authhash;
8714:
1.27 raeburn 8715: my %usercreation_hash = (
1.160.6.34 raeburn 8716: usercreation => \%save_usercreate,
8717: );
1.27 raeburn 8718:
8719: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8720: $dom);
1.50 raeburn 8721:
1.160.6.34 raeburn 8722: if ($putresult eq 'ok') {
8723: if (keys(%changes) > 0) {
8724: $resulttext = &mt('Changes made:').'<ul>';
8725: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8726: my %lt = &usercreation_types();
8727: foreach my $type (@{$changes{'cancreate'}}) {
8728: my $chgtext = $lt{$type}.', ';
8729: if ($cancreate{$type} eq 'none') {
8730: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8731: } elsif ($cancreate{$type} eq 'any') {
8732: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8733: } elsif ($cancreate{$type} eq 'official') {
8734: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8735: } elsif ($cancreate{$type} eq 'unofficial') {
8736: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8737: }
8738: $resulttext .= '<li>'.$chgtext.'</li>';
8739: }
8740: }
8741: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8742: my ($rules,$ruleorder) =
8743: &Apache::lonnet::inst_userrules($dom,'username');
8744: my $chgtext = '<ul>';
8745: foreach my $type (@username_rule) {
8746: if (ref($rules->{$type}) eq 'HASH') {
8747: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8748: }
8749: }
8750: $chgtext .= '</ul>';
8751: if (@username_rule > 0) {
8752: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8753: } else {
8754: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8755: }
8756: }
8757: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8758: my ($idrules,$idruleorder) =
8759: &Apache::lonnet::inst_userrules($dom,'id');
8760: my $chgtext = '<ul>';
8761: foreach my $type (@id_rule) {
8762: if (ref($idrules->{$type}) eq 'HASH') {
8763: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8764: }
8765: }
8766: $chgtext .= '</ul>';
8767: if (@id_rule > 0) {
8768: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8769: } else {
8770: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8771: }
8772: }
8773: my %authname = &authtype_names();
8774: my %context_title = &context_names();
8775: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8776: my $chgtext = '<ul>';
8777: foreach my $type (@{$changes{'authtypes'}}) {
8778: my @allowed;
8779: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8780: foreach my $auth (@authtypes) {
8781: if ($authhash{$type}{$auth}) {
8782: push(@allowed,$authname{$auth});
8783: }
8784: }
8785: if (@allowed > 0) {
8786: $chgtext .= join(', ',@allowed).'</li>';
8787: } else {
8788: $chgtext .= &mt('none').'</li>';
8789: }
8790: }
8791: $chgtext .= '</ul>';
8792: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8793: $resulttext .= '</li>';
8794: }
8795: $resulttext .= '</ul>';
8796: } else {
8797: $resulttext = &mt('No changes made to user creation settings');
8798: }
8799: } else {
8800: $resulttext = '<span class="LC_error">'.
8801: &mt('An error occurred: [_1]',$putresult).'</span>';
8802: }
8803: if ($warningmsg ne '') {
8804: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8805: }
8806: return $resulttext;
8807: }
8808:
8809: sub modify_selfcreation {
8810: my ($dom,%domconfig) = @_;
8811: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8812: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8813: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8814: if (ref($types) eq 'ARRAY') {
8815: $usertypes->{'default'} = $othertitle;
8816: push(@{$types},'default');
8817: }
1.160.6.34 raeburn 8818: #
8819: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8820: #
8821: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8822: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8823: if ($key eq 'cancreate') {
8824: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8825: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8826: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8827: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8828: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8829: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8830: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8831: } else {
8832: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8833: }
8834: }
8835: }
8836: } elsif ($key eq 'email_rule') {
8837: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8838: } else {
8839: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8840: }
8841: }
8842: }
8843: #
8844: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8845: #
8846: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8847: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8848: if ($key eq 'selfcreate') {
8849: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8850: } else {
8851: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8852: }
8853: }
8854: }
8855:
8856: my @contexts = ('selfcreate');
8857: @{$cancreate{'selfcreate'}} = ();
8858: %{$cancreate{'emailusername'}} = ();
8859: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8860: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8861: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8862: my %selfcreatetypes = (
8863: sso => 'users authenticated by institutional single sign on',
8864: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8865: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8866: );
1.160.6.34 raeburn 8867: #
8868: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8869: # is permitted.
8870: #
1.160.6.40 raeburn 8871:
8872: my @statuses;
8873: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8874: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8875: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8876: }
8877: }
8878: push(@statuses,'default');
8879:
1.160.6.35 raeburn 8880: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8881: if ($item eq 'email') {
1.160.6.40 raeburn 8882: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8883: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8884: push(@contexts,'selfcreateprocessing');
8885: foreach my $type (@statuses) {
8886: if ($type eq 'default') {
8887: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8888: } else {
8889: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8890: }
8891: }
1.160.6.34 raeburn 8892: }
8893: } else {
8894: if ($env{'form.cancreate_'.$item}) {
8895: push(@{$cancreate{'selfcreate'}},$item);
8896: }
8897: }
8898: }
8899: my (@email_rule,%userinfo,%savecaptcha);
8900: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8901: #
1.160.6.35 raeburn 8902: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8903: # 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 8904: #
1.160.6.40 raeburn 8905:
1.160.6.48 raeburn 8906: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8907: push(@contexts,'emailusername');
1.160.6.35 raeburn 8908: if (ref($types) eq 'ARRAY') {
8909: foreach my $type (@{$types}) {
8910: if (ref($infofields) eq 'ARRAY') {
8911: foreach my $field (@{$infofields}) {
8912: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8913: $cancreate{'emailusername'}{$type}{$field} = $1;
8914: }
8915: }
1.160.6.34 raeburn 8916: }
8917: }
8918: }
8919: #
8920: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8921: # queued requests for self-creation of account using e-mail address as username
8922: #
8923:
8924: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8925: @approvalnotify = sort(@approvalnotify);
8926: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8927: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8928: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8929: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8930: push(@{$changes{'cancreate'}},'notify');
8931: }
8932: } else {
8933: if ($cancreate{'notify'}{'approval'}) {
8934: push(@{$changes{'cancreate'}},'notify');
8935: }
8936: }
8937: } elsif ($cancreate{'notify'}{'approval'}) {
8938: push(@{$changes{'cancreate'}},'notify');
8939: }
8940:
8941: #
8942: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8943: #
8944: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8945: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8946: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8947: if (@{$curr_usercreation{'email_rule'}} > 0) {
8948: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8949: if (!grep(/^\Q$type\E$/,@email_rule)) {
8950: push(@{$changes{'email_rule'}},$type);
8951: }
8952: }
8953: }
8954: if (@email_rule > 0) {
8955: foreach my $type (@email_rule) {
8956: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8957: push(@{$changes{'email_rule'}},$type);
8958: }
8959: }
8960: }
8961: } elsif (@email_rule > 0) {
8962: push(@{$changes{'email_rule'}},@email_rule);
8963: }
8964: }
8965: #
1.160.6.40 raeburn 8966: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8967: # institutional log-in.
8968: #
8969: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8970: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8971: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8972: ($domdefaults{'auth_def'} eq 'localauth'))) {
8973: $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.').' '.
8974: &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.');
8975: }
8976: }
8977: my @fields = ('lastname','firstname','middlename','generation',
8978: 'permanentemail','id');
1.160.6.44 raeburn 8979: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8980: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8981: #
8982: # Where usernames may created for institutional log-in and/or institutional single sign on:
8983: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8984: # may self-create accounts
8985: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8986: # which the user may supply, if institutional data is unavailable.
8987: #
8988: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8989: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8990: if (@{$types} > 1) {
1.160.6.34 raeburn 8991: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8992: push(@contexts,'statustocreate');
8993: } else {
8994: undef($cancreate{'statustocreate'});
8995: }
8996: foreach my $type (@{$types}) {
8997: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8998: foreach my $field (@fields) {
8999: if (grep(/^\Q$field\E$/,@modifiable)) {
9000: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9001: } else {
9002: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9003: }
9004: }
9005: }
9006: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9007: foreach my $type (@{$types}) {
9008: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9009: foreach my $field (@fields) {
9010: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9011: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9012: push(@{$changes{'selfcreate'}},$type);
9013: last;
9014: }
9015: }
9016: }
9017: }
9018: } else {
9019: foreach my $type (@{$types}) {
9020: push(@{$changes{'selfcreate'}},$type);
9021: }
9022: }
9023: }
1.160.6.44 raeburn 9024: foreach my $field (@shibfields) {
9025: if ($env{'form.shibenv_'.$field} ne '') {
9026: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9027: }
9028: }
9029: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9030: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9031: foreach my $field (@shibfields) {
9032: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9033: push(@{$changes{'cancreate'}},'shibenv');
9034: }
9035: }
9036: } else {
9037: foreach my $field (@shibfields) {
9038: if ($env{'form.shibenv_'.$field}) {
9039: push(@{$changes{'cancreate'}},'shibenv');
9040: last;
9041: }
9042: }
9043: }
9044: }
1.160.6.34 raeburn 9045: }
9046: foreach my $item (@contexts) {
9047: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9048: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9049: if (ref($cancreate{$item}) eq 'ARRAY') {
9050: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9051: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9052: push(@{$changes{'cancreate'}},$item);
9053: }
9054: }
9055: }
9056: }
9057: if (ref($cancreate{$item}) eq 'ARRAY') {
9058: foreach my $type (@{$cancreate{$item}}) {
9059: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9060: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9061: push(@{$changes{'cancreate'}},$item);
9062: }
9063: }
9064: }
9065: }
9066: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9067: if (ref($cancreate{$item}) eq 'HASH') {
9068: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 9069: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9070: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9071: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9072: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9073: push(@{$changes{'cancreate'}},$item);
9074: }
9075: }
9076: }
1.160.6.40 raeburn 9077: } elsif ($item eq 'selfcreateprocessing') {
9078: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9079: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9080: push(@{$changes{'cancreate'}},$item);
9081: }
9082: }
1.160.6.35 raeburn 9083: } else {
9084: if (!$cancreate{$item}{$curr}) {
9085: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9086: push(@{$changes{'cancreate'}},$item);
9087: }
1.160.6.34 raeburn 9088: }
9089: }
9090: }
9091: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 9092: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9093: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9094: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9095: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9096: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9097: push(@{$changes{'cancreate'}},$item);
9098: }
9099: }
9100: } else {
9101: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9102: push(@{$changes{'cancreate'}},$item);
9103: }
9104: }
9105: }
1.160.6.40 raeburn 9106: } elsif ($item eq 'selfcreateprocessing') {
9107: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9108: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9109: push(@{$changes{'cancreate'}},$item);
9110: }
9111: }
1.160.6.35 raeburn 9112: } else {
9113: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9114: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9115: push(@{$changes{'cancreate'}},$item);
9116: }
1.160.6.34 raeburn 9117: }
9118: }
9119: }
9120: }
9121: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9122: if (ref($cancreate{$item}) eq 'ARRAY') {
9123: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9124: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9125: push(@{$changes{'cancreate'}},$item);
9126: }
9127: }
9128: } elsif (ref($cancreate{$item}) eq 'HASH') {
9129: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9130: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9131: push(@{$changes{'cancreate'}},$item);
9132: }
9133: }
9134: }
9135: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9136: if (ref($cancreate{$item}) eq 'HASH') {
9137: foreach my $type (keys(%{$cancreate{$item}})) {
9138: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9139: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9140: if ($cancreate{$item}{$type}{$field}) {
9141: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9142: push(@{$changes{'cancreate'}},$item);
9143: }
9144: last;
9145: }
9146: }
9147: }
9148: }
1.160.6.34 raeburn 9149: }
9150: }
9151: }
9152: #
9153: # Populate %save_usercreate hash with updates to self-creation configuration.
9154: #
9155: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9156: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
9157: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9158: if (ref($cancreate{'notify'}) eq 'HASH') {
9159: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9160: }
1.160.6.40 raeburn 9161: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9162: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9163: }
1.160.6.34 raeburn 9164: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9165: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9166: }
1.160.6.44 raeburn 9167: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9168: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9169: }
1.160.6.34 raeburn 9170: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9171: $save_usercreate{'emailrule'} = \@email_rule;
9172:
9173: my %userconfig_hash = (
9174: usercreation => \%save_usercreate,
9175: usermodification => \%save_usermodify,
9176: );
9177: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9178: $dom);
9179: #
9180: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9181: #
1.27 raeburn 9182: if ($putresult eq 'ok') {
9183: if (keys(%changes) > 0) {
9184: $resulttext = &mt('Changes made:').'<ul>';
9185: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9186: my %lt = &selfcreation_types();
1.34 raeburn 9187: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9188: my $chgtext;
1.45 raeburn 9189: if ($type eq 'selfcreate') {
1.50 raeburn 9190: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9191: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9192: } else {
1.160.6.34 raeburn 9193: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9194: '<ul>';
1.50 raeburn 9195: foreach my $case (@{$cancreate{$type}}) {
9196: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9197: }
9198: $chgtext .= '</ul>';
1.100 raeburn 9199: if (ref($cancreate{$type}) eq 'ARRAY') {
9200: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9201: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9202: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9203: $chgtext .= '<br />'.
9204: '<span class="LC_warning">'.
9205: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9206: '</span>';
1.100 raeburn 9207: }
9208: }
9209: }
9210: }
1.43 raeburn 9211: }
1.160.6.44 raeburn 9212: } elsif ($type eq 'shibenv') {
9213: if (keys(%{$cancreate{$type}}) == 0) {
9214: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9215: } else {
9216: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9217: '<ul>';
9218: foreach my $field (@shibfields) {
9219: next if ($cancreate{$type}{$field} eq '');
9220: if ($field eq 'inststatus') {
9221: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9222: } else {
9223: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9224: }
9225: }
9226: $chgtext .= '</ul>';
9227: }
1.93 raeburn 9228: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9229: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9230: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9231: if (@{$cancreate{'selfcreate'}} > 0) {
9232: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9233: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9234: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9235: $chgtext .= '<br />'.
9236: '<span class="LC_warning">'.
9237: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9238: '</span>';
9239: }
1.96 raeburn 9240: } elsif (ref($usertypes) eq 'HASH') {
9241: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9242: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9243: } else {
9244: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9245: }
9246: $chgtext .= '<ul>';
9247: foreach my $case (@{$cancreate{$type}}) {
9248: if ($case eq 'default') {
9249: $chgtext .= '<li>'.$othertitle.'</li>';
9250: } else {
9251: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9252: }
9253: }
1.100 raeburn 9254: $chgtext .= '</ul>';
9255: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9256: $chgtext .= '<br /><span class="LC_warning">'.
9257: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9258: '</span>';
1.100 raeburn 9259: }
9260: }
9261: } else {
9262: if (@{$cancreate{$type}} == 0) {
9263: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9264: } else {
9265: $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 9266: }
9267: }
9268: }
1.160.6.40 raeburn 9269: } elsif ($type eq 'selfcreateprocessing') {
9270: my %choices = &Apache::lonlocal::texthash (
9271: automatic => 'Automatic approval',
9272: approval => 'Queued for approval',
9273: );
9274: if (@statuses > 1) {
9275: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9276: '<ul>';
9277: foreach my $type (@statuses) {
9278: if ($type eq 'default') {
9279: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9280: } else {
9281: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9282: }
9283: }
9284: $chgtext .= '</ul>';
9285: } else {
9286: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9287: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9288: }
1.160.6.5 raeburn 9289: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9290: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9291: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9292: } else {
9293: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9294: if ($captchas{$savecaptcha{$type}}) {
9295: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9296: } else {
9297: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9298: }
9299: }
9300: } elsif ($type eq 'recaptchakeys') {
9301: my ($privkey,$pubkey);
1.160.6.34 raeburn 9302: if (ref($savecaptcha{$type}) eq 'HASH') {
9303: $pubkey = $savecaptcha{$type}{'public'};
9304: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9305: }
9306: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9307: if (!$pubkey) {
9308: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9309: } else {
9310: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9311: }
9312: if (!$privkey) {
9313: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9314: } else {
9315: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9316: }
9317: $chgtext .= '</ul>';
1.160.6.34 raeburn 9318: } elsif ($type eq 'emailusername') {
9319: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9320: if (ref($types) eq 'ARRAY') {
9321: foreach my $type (@{$types}) {
9322: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9323: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9324: $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 9325: '<ul>';
9326: foreach my $field (@{$infofields}) {
9327: if ($cancreate{'emailusername'}{$type}{$field}) {
9328: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9329: }
9330: }
1.160.6.50 raeburn 9331: $chgtext .= '</ul>';
9332: } else {
9333: $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 9334: }
9335: } else {
1.160.6.50 raeburn 9336: $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 9337: }
9338: }
9339: }
9340: }
9341: } elsif ($type eq 'notify') {
9342: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9343: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9344: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9345: if ($cancreate{'notify'}{'approval'}) {
9346: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9347: }
9348: }
1.43 raeburn 9349: }
1.34 raeburn 9350: }
1.160.6.34 raeburn 9351: if ($chgtext) {
9352: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9353: }
9354: }
9355: }
1.43 raeburn 9356: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9357: my ($emailrules,$emailruleorder) =
9358: &Apache::lonnet::inst_userrules($dom,'email');
9359: my $chgtext = '<ul>';
9360: foreach my $type (@email_rule) {
9361: if (ref($emailrules->{$type}) eq 'HASH') {
9362: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9363: }
9364: }
9365: $chgtext .= '</ul>';
9366: if (@email_rule > 0) {
1.160.6.34 raeburn 9367: $resulttext .= '<li>'.
9368: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9369: $chgtext.
9370: '</li>';
1.43 raeburn 9371: } else {
1.160.6.34 raeburn 9372: $resulttext .= '<li>'.
9373: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9374: '</li>';
1.43 raeburn 9375: }
9376: }
1.160.6.34 raeburn 9377: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9378: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9379: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9380: foreach my $type (@{$changes{'selfcreate'}}) {
9381: my $typename = $type;
9382: if (ref($usertypes) eq 'HASH') {
9383: if ($usertypes->{$type} ne '') {
9384: $typename = $usertypes->{$type};
1.28 raeburn 9385: }
9386: }
1.160.6.34 raeburn 9387: my @modifiable;
9388: $resulttext .= '<li>'.
9389: &mt('Self-creation of account by users with status: [_1]',
9390: '<span class="LC_cusr_emph">'.$typename.'</span>').
9391: ' - '.&mt('modifiable fields (if institutional data blank): ');
9392: foreach my $field (@fields) {
9393: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9394: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9395: }
9396: }
9397: if (@modifiable > 0) {
9398: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9399: } else {
1.160.6.34 raeburn 9400: $resulttext .= &mt('none');
1.43 raeburn 9401: }
1.160.6.34 raeburn 9402: $resulttext .= '</li>';
1.28 raeburn 9403: }
1.160.6.34 raeburn 9404: $resulttext .= '</ul></li>';
1.28 raeburn 9405: }
1.27 raeburn 9406: $resulttext .= '</ul>';
9407: } else {
1.160.6.34 raeburn 9408: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9409: }
9410: } else {
9411: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9412: &mt('An error occurred: [_1]',$putresult).'</span>';
9413: }
1.43 raeburn 9414: if ($warningmsg ne '') {
9415: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9416: }
1.23 raeburn 9417: return $resulttext;
9418: }
9419:
1.160.6.5 raeburn 9420: sub process_captcha {
9421: my ($container,$changes,$newsettings,$current) = @_;
9422: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9423: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9424: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9425: $newsettings->{'captcha'} = 'original';
9426: }
9427: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9428: if ($container eq 'cancreate') {
9429: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9430: push(@{$changes->{'cancreate'}},'captcha');
9431: } elsif (!defined($changes->{'cancreate'})) {
9432: $changes->{'cancreate'} = ['captcha'];
9433: }
9434: } else {
9435: $changes->{'captcha'} = 1;
9436: }
9437: }
9438: my ($newpub,$newpriv,$currpub,$currpriv);
9439: if ($newsettings->{'captcha'} eq 'recaptcha') {
9440: $newpub = $env{'form.'.$container.'_recaptchapub'};
9441: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9442: $newpub =~ s/[^\w\-]//g;
9443: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9444: $newsettings->{'recaptchakeys'} = {
9445: public => $newpub,
9446: private => $newpriv,
9447: };
9448: }
9449: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9450: $currpub = $current->{'recaptchakeys'}{'public'};
9451: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9452: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9453: $newsettings->{'recaptchakeys'} = {
9454: public => '',
9455: private => '',
9456: }
9457: }
1.160.6.5 raeburn 9458: }
9459: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9460: if ($container eq 'cancreate') {
9461: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9462: push(@{$changes->{'cancreate'}},'recaptchakeys');
9463: } elsif (!defined($changes->{'cancreate'})) {
9464: $changes->{'cancreate'} = ['recaptchakeys'];
9465: }
9466: } else {
9467: $changes->{'recaptchakeys'} = 1;
9468: }
9469: }
9470: return;
9471: }
9472:
1.33 raeburn 9473: sub modify_usermodification {
9474: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9475: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9476: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9477: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9478: if ($key eq 'selfcreate') {
9479: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9480: } else {
9481: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9482: }
1.33 raeburn 9483: }
9484: }
1.160.6.34 raeburn 9485: my @contexts = ('author','course');
1.33 raeburn 9486: my %context_title = (
9487: author => 'In author context',
9488: course => 'In course context',
9489: );
9490: my @fields = ('lastname','firstname','middlename','generation',
9491: 'permanentemail','id');
9492: my %roles = (
9493: author => ['ca','aa'],
9494: course => ['st','ep','ta','in','cr'],
9495: );
9496: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9497: foreach my $context (@contexts) {
9498: foreach my $role (@{$roles{$context}}) {
9499: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9500: foreach my $item (@fields) {
9501: if (grep(/^\Q$item\E$/,@modifiable)) {
9502: $modifyhash{$context}{$role}{$item} = 1;
9503: } else {
9504: $modifyhash{$context}{$role}{$item} = 0;
9505: }
9506: }
9507: }
9508: if (ref($curr_usermodification{$context}) eq 'HASH') {
9509: foreach my $role (@{$roles{$context}}) {
9510: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9511: foreach my $field (@fields) {
9512: if ($modifyhash{$context}{$role}{$field} ne
9513: $curr_usermodification{$context}{$role}{$field}) {
9514: push(@{$changes{$context}},$role);
9515: last;
9516: }
9517: }
9518: }
9519: }
9520: } else {
9521: foreach my $context (@contexts) {
9522: foreach my $role (@{$roles{$context}}) {
9523: push(@{$changes{$context}},$role);
9524: }
9525: }
9526: }
9527: }
9528: my %usermodification_hash = (
9529: usermodification => \%modifyhash,
9530: );
9531: my $putresult = &Apache::lonnet::put_dom('configuration',
9532: \%usermodification_hash,$dom);
9533: if ($putresult eq 'ok') {
9534: if (keys(%changes) > 0) {
9535: $resulttext = &mt('Changes made: ').'<ul>';
9536: foreach my $context (@contexts) {
9537: if (ref($changes{$context}) eq 'ARRAY') {
9538: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9539: if (ref($changes{$context}) eq 'ARRAY') {
9540: foreach my $role (@{$changes{$context}}) {
9541: my $rolename;
1.160.6.34 raeburn 9542: if ($role eq 'cr') {
9543: $rolename = &mt('Custom');
1.33 raeburn 9544: } else {
1.160.6.34 raeburn 9545: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9546: }
9547: my @modifiable;
1.160.6.34 raeburn 9548: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9549: foreach my $field (@fields) {
9550: if ($modifyhash{$context}{$role}{$field}) {
9551: push(@modifiable,$fieldtitles{$field});
9552: }
9553: }
9554: if (@modifiable > 0) {
9555: $resulttext .= join(', ',@modifiable);
9556: } else {
9557: $resulttext .= &mt('none');
9558: }
9559: $resulttext .= '</li>';
9560: }
9561: $resulttext .= '</ul></li>';
9562: }
9563: }
9564: }
9565: $resulttext .= '</ul>';
9566: } else {
9567: $resulttext = &mt('No changes made to user modification settings');
9568: }
9569: } else {
9570: $resulttext = '<span class="LC_error">'.
9571: &mt('An error occurred: [_1]',$putresult).'</span>';
9572: }
9573: return $resulttext;
9574: }
9575:
1.43 raeburn 9576: sub modify_defaults {
1.160.6.27 raeburn 9577: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9578: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9580: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9581: my @authtypes = ('internal','krb4','krb5','localauth');
9582: foreach my $item (@items) {
9583: $newvalues{$item} = $env{'form.'.$item};
9584: if ($item eq 'auth_def') {
9585: if ($newvalues{$item} ne '') {
9586: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9587: push(@errors,$item);
9588: }
9589: }
9590: } elsif ($item eq 'lang_def') {
9591: if ($newvalues{$item} ne '') {
9592: if ($newvalues{$item} =~ /^(\w+)/) {
9593: my $langcode = $1;
1.103 raeburn 9594: if ($langcode ne 'x_chef') {
9595: if (code2language($langcode) eq '') {
9596: push(@errors,$item);
9597: }
1.43 raeburn 9598: }
9599: } else {
9600: push(@errors,$item);
9601: }
9602: }
1.54 raeburn 9603: } elsif ($item eq 'timezone_def') {
9604: if ($newvalues{$item} ne '') {
1.62 raeburn 9605: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9606: push(@errors,$item);
9607: }
9608: }
1.68 raeburn 9609: } elsif ($item eq 'datelocale_def') {
9610: if ($newvalues{$item} ne '') {
9611: my @datelocale_ids = DateTime::Locale->ids();
9612: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9613: push(@errors,$item);
9614: }
9615: }
1.141 raeburn 9616: } elsif ($item eq 'portal_def') {
9617: if ($newvalues{$item} ne '') {
9618: 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])\/?$/) {
9619: push(@errors,$item);
9620: }
9621: }
1.43 raeburn 9622: }
9623: if (grep(/^\Q$item\E$/,@errors)) {
9624: $newvalues{$item} = $domdefaults{$item};
9625: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9626: $changes{$item} = 1;
9627: }
1.72 raeburn 9628: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9629: }
9630: my %defaults_hash = (
1.72 raeburn 9631: defaults => \%newvalues,
9632: );
1.43 raeburn 9633: my $title = &defaults_titles();
1.160.6.40 raeburn 9634:
9635: my $currinststatus;
9636: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9637: $currinststatus = $domconfig{'inststatus'};
9638: } else {
9639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9640: $currinststatus = {
9641: inststatustypes => $usertypes,
9642: inststatusorder => $types,
9643: inststatusguest => [],
9644: };
9645: }
9646: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9647: my @allpos;
9648: my %guests;
9649: my %alltypes;
9650: my ($currtitles,$currguests,$currorder);
9651: if (ref($currinststatus) eq 'HASH') {
9652: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9653: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9654: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9655: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9656: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9657: }
9658: }
9659: unless (grep(/^\Q$type\E$/,@todelete)) {
9660: my $position = $env{'form.inststatus_pos_'.$type};
9661: $position =~ s/\D+//g;
9662: $allpos[$position] = $type;
9663: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9664: $alltypes{$type} =~ s/`//g;
9665: if ($env{'form.inststatus_guest_'.$type}) {
9666: $guests{$type} = 1;
9667: }
9668: }
9669: }
9670: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9671: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9672: }
9673: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9674: $currtitles =~ s/,$//;
9675: }
9676: }
9677: if ($env{'form.addinststatus'}) {
9678: my $newtype = $env{'form.addinststatus'};
9679: $newtype =~ s/\W//g;
9680: unless (exists($alltypes{$newtype})) {
9681: if ($env{'form.addinststatus_guest'}) {
9682: $guests{$newtype} = 1;
9683: }
9684: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9685: $alltypes{$newtype} =~ s/`//g;
9686: my $position = $env{'form.addinststatus_pos'};
9687: $position =~ s/\D+//g;
9688: if ($position ne '') {
9689: $allpos[$position] = $newtype;
9690: }
9691: }
9692: }
9693: my (@orderedstatus,@orderedguests);
9694: foreach my $type (@allpos) {
9695: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9696: push(@orderedstatus,$type);
9697: if ($guests{$type}) {
9698: push(@orderedguests,$type);
9699: }
9700: }
9701: }
9702: foreach my $type (keys(%alltypes)) {
9703: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9704: delete($alltypes{$type});
9705: }
9706: }
9707: $defaults_hash{'inststatus'} = {
9708: inststatustypes => \%alltypes,
9709: inststatusorder => \@orderedstatus,
9710: inststatusguest => \@orderedguests,
9711: };
9712: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9713: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9714: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9715: }
9716: }
9717: if ($currorder ne join(',',@orderedstatus)) {
9718: $changes{'inststatus'}{'inststatusorder'} = 1;
9719: }
9720: if ($currguests ne join(',',@orderedguests)) {
9721: $changes{'inststatus'}{'inststatusguest'} = 1;
9722: }
9723: my $newtitles;
9724: foreach my $item (@orderedstatus) {
9725: $newtitles .= $alltypes{$item}.',';
9726: }
9727: $newtitles =~ s/,$//;
9728: if ($currtitles ne $newtitles) {
9729: $changes{'inststatus'}{'inststatustypes'} = 1;
9730: }
1.43 raeburn 9731: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9732: $dom);
9733: if ($putresult eq 'ok') {
9734: if (keys(%changes) > 0) {
9735: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9736: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9737: 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";
9738: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9739: if ($item eq 'inststatus') {
9740: if (ref($changes{'inststatus'}) eq 'HASH') {
9741: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9742: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9743: foreach my $type (@orderedstatus) {
9744: $resulttext .= $alltypes{$type}.', ';
9745: }
9746: $resulttext =~ s/, $//;
9747: $resulttext .= '</li>';
9748: }
9749: if ($changes{'inststatus'}{'inststatusguest'}) {
9750: $resulttext .= '<li>';
9751: if (@orderedguests) {
9752: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9753: foreach my $type (@orderedguests) {
9754: $resulttext .= $alltypes{$type}.', ';
9755: }
9756: $resulttext =~ s/, $//;
9757: } else {
9758: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9759: }
9760: $resulttext .= '</li>';
9761: }
9762: }
9763: } else {
9764: my $value = $env{'form.'.$item};
9765: if ($value eq '') {
9766: $value = &mt('none');
9767: } elsif ($item eq 'auth_def') {
9768: my %authnames = &authtype_names();
9769: my %shortauth = (
9770: internal => 'int',
9771: krb4 => 'krb4',
9772: krb5 => 'krb5',
9773: localauth => 'loc',
9774: );
9775: $value = $authnames{$shortauth{$value}};
9776: }
9777: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9778: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9779: }
9780: }
9781: $resulttext .= '</ul>';
9782: $mailmsgtext .= "\n";
9783: my $cachetime = 24*60*60;
1.72 raeburn 9784: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9785: if (ref($lastactref) eq 'HASH') {
9786: $lastactref->{'domdefaults'} = 1;
9787: }
1.68 raeburn 9788: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9789: my $notify = 1;
9790: if (ref($domconfig{'contacts'}) eq 'HASH') {
9791: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9792: $notify = 0;
9793: }
9794: }
9795: if ($notify) {
9796: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9797: "LON-CAPA Domain Settings Change - $dom",
9798: $mailmsgtext);
9799: }
1.54 raeburn 9800: }
1.43 raeburn 9801: } else {
1.54 raeburn 9802: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9803: }
9804: } else {
9805: $resulttext = '<span class="LC_error">'.
9806: &mt('An error occurred: [_1]',$putresult).'</span>';
9807: }
9808: if (@errors > 0) {
9809: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9810: foreach my $item (@errors) {
9811: $resulttext .= ' "'.$title->{$item}.'",';
9812: }
9813: $resulttext =~ s/,$//;
9814: }
9815: return $resulttext;
9816: }
9817:
1.46 raeburn 9818: sub modify_scantron {
1.160.6.24 raeburn 9819: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9820: my ($resulttext,%confhash,%changes,$errors);
9821: my $custom = 'custom.tab';
9822: my $default = 'default.tab';
9823: my $servadm = $r->dir_config('lonAdmEMail');
9824: my ($configuserok,$author_ok,$switchserver) =
9825: &config_check($dom,$confname,$servadm);
9826: if ($env{'form.scantronformat.filename'} ne '') {
9827: my $error;
9828: if ($configuserok eq 'ok') {
9829: if ($switchserver) {
1.130 raeburn 9830: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9831: } else {
9832: if ($author_ok eq 'ok') {
9833: my ($result,$scantronurl) =
9834: &publishlogo($r,'upload','scantronformat',$dom,
9835: $confname,'scantron','','',$custom);
9836: if ($result eq 'ok') {
9837: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9838: $changes{'scantronformat'} = 1;
1.46 raeburn 9839: } else {
9840: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9841: }
9842: } else {
9843: $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);
9844: }
9845: }
9846: } else {
9847: $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);
9848: }
9849: if ($error) {
9850: &Apache::lonnet::logthis($error);
9851: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9852: }
9853: }
1.48 raeburn 9854: if (ref($domconfig{'scantron'}) eq 'HASH') {
9855: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9856: if ($env{'form.scantronformat_del'}) {
9857: $confhash{'scantron'}{'scantronformat'} = '';
9858: $changes{'scantronformat'} = 1;
1.46 raeburn 9859: }
9860: }
9861: }
9862: if (keys(%confhash) > 0) {
9863: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9864: $dom);
9865: if ($putresult eq 'ok') {
9866: if (keys(%changes) > 0) {
1.48 raeburn 9867: if (ref($confhash{'scantron'}) eq 'HASH') {
9868: $resulttext = &mt('Changes made:').'<ul>';
9869: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9870: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9871: } else {
1.130 raeburn 9872: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9873: }
1.48 raeburn 9874: $resulttext .= '</ul>';
9875: } else {
1.130 raeburn 9876: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9877: }
9878: $resulttext .= '</ul>';
9879: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9880: if (ref($lastactref) eq 'HASH') {
9881: $lastactref->{'domainconfig'} = 1;
9882: }
1.46 raeburn 9883: } else {
1.130 raeburn 9884: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9885: }
9886: } else {
9887: $resulttext = '<span class="LC_error">'.
9888: &mt('An error occurred: [_1]',$putresult).'</span>';
9889: }
9890: } else {
1.130 raeburn 9891: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9892: }
9893: if ($errors) {
9894: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9895: $errors.'</ul>';
9896: }
9897: return $resulttext;
9898: }
9899:
1.48 raeburn 9900: sub modify_coursecategories {
1.160.6.43 raeburn 9901: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9902: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9903: $cathash);
1.48 raeburn 9904: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9905: my @catitems = ('unauth','auth');
9906: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9907: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9908: $cathash = $domconfig{'coursecategories'}{'cats'};
9909: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9910: $changes{'togglecats'} = 1;
9911: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9912: }
9913: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9914: $changes{'categorize'} = 1;
9915: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9916: }
1.120 raeburn 9917: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9918: $changes{'togglecatscomm'} = 1;
9919: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9920: }
9921: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9922: $changes{'categorizecomm'} = 1;
9923: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9924: }
1.160.6.42 raeburn 9925: foreach my $item (@catitems) {
9926: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9927: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9928: $changes{$item} = 1;
9929: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9930: }
9931: }
9932: }
1.57 raeburn 9933: } else {
9934: $changes{'togglecats'} = 1;
9935: $changes{'categorize'} = 1;
1.124 raeburn 9936: $changes{'togglecatscomm'} = 1;
9937: $changes{'categorizecomm'} = 1;
1.87 raeburn 9938: $domconfig{'coursecategories'} = {
9939: togglecats => $env{'form.togglecats'},
9940: categorize => $env{'form.categorize'},
1.124 raeburn 9941: togglecatscomm => $env{'form.togglecatscomm'},
9942: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9943: };
1.160.6.42 raeburn 9944: foreach my $item (@catitems) {
9945: if ($env{'form.coursecat_'.$item} ne 'std') {
9946: $changes{$item} = 1;
9947: }
9948: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9949: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9950: }
9951: }
1.57 raeburn 9952: }
9953: if (ref($cathash) eq 'HASH') {
9954: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9955: push (@deletecategory,'instcode::0');
9956: }
1.120 raeburn 9957: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9958: push(@deletecategory,'communities::0');
9959: }
1.48 raeburn 9960: }
1.57 raeburn 9961: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9962: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9963: if (@deletecategory > 0) {
9964: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9965: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9966: foreach my $item (@deletecategory) {
1.57 raeburn 9967: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9968: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9969: $deletions{$item} = 1;
1.57 raeburn 9970: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9971: }
9972: }
9973: }
1.57 raeburn 9974: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9975: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9976: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9977: $reorderings{$item} = 1;
1.57 raeburn 9978: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9979: }
9980: if ($env{'form.addcategory_name_'.$item} ne '') {
9981: my $newcat = $env{'form.addcategory_name_'.$item};
9982: my $newdepth = $depth+1;
9983: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9984: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9985: $adds{$newitem} = 1;
9986: }
9987: if ($env{'form.subcat_'.$item} ne '') {
9988: my $newcat = $env{'form.subcat_'.$item};
9989: my $newdepth = $depth+1;
9990: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9991: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9992: $adds{$newitem} = 1;
9993: }
9994: }
9995: }
9996: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9997: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9998: my $newitem = 'instcode::0';
1.57 raeburn 9999: if ($cathash->{$newitem} eq '') {
10000: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10001: $adds{$newitem} = 1;
10002: }
10003: } else {
10004: my $newitem = 'instcode::0';
1.57 raeburn 10005: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10006: $adds{$newitem} = 1;
10007: }
10008: }
1.120 raeburn 10009: if ($env{'form.communities'} eq '1') {
10010: if (ref($cathash) eq 'HASH') {
10011: my $newitem = 'communities::0';
10012: if ($cathash->{$newitem} eq '') {
10013: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10014: $adds{$newitem} = 1;
10015: }
10016: } else {
10017: my $newitem = 'communities::0';
10018: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10019: $adds{$newitem} = 1;
10020: }
10021: }
1.48 raeburn 10022: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10023: if (($env{'form.addcategory_name'} ne 'instcode') &&
10024: ($env{'form.addcategory_name'} ne 'communities')) {
10025: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10026: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10027: $adds{$newitem} = 1;
10028: }
1.48 raeburn 10029: }
1.57 raeburn 10030: my $putresult;
1.48 raeburn 10031: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10032: if (keys(%deletions) > 0) {
10033: foreach my $key (keys(%deletions)) {
10034: if ($predelallitems{$key} ne '') {
10035: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10036: }
10037: }
10038: }
10039: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10040: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10041: if (ref($chkcats[0]) eq 'ARRAY') {
10042: my $depth = 0;
10043: my $chg = 0;
10044: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10045: my $name = $chkcats[0][$i];
10046: my $item;
10047: if ($name eq '') {
10048: $chg ++;
10049: } else {
10050: $item = &escape($name).'::0';
10051: if ($chg) {
1.57 raeburn 10052: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10053: }
10054: $depth ++;
1.57 raeburn 10055: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10056: $depth --;
10057: }
10058: }
10059: }
1.57 raeburn 10060: }
10061: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10062: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10063: if ($putresult eq 'ok') {
1.57 raeburn 10064: my %title = (
1.120 raeburn 10065: togglecats => 'Show/Hide a course in catalog',
10066: categorize => 'Assign a category to a course',
10067: togglecatscomm => 'Show/Hide a community in catalog',
10068: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10069: );
10070: my %level = (
1.120 raeburn 10071: dom => 'set in Domain ("Modify Course/Community")',
10072: crs => 'set in Course ("Course Configuration")',
10073: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 10074: none => 'No catalog',
10075: std => 'Standard catalog',
10076: domonly => 'Domain-only catalog',
10077: codesrch => 'Code search form',
1.57 raeburn 10078: );
1.48 raeburn 10079: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 10080: if ($changes{'togglecats'}) {
10081: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
10082: }
10083: if ($changes{'categorize'}) {
10084: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 10085: }
1.120 raeburn 10086: if ($changes{'togglecatscomm'}) {
10087: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
10088: }
10089: if ($changes{'categorizecomm'}) {
10090: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
10091: }
1.160.6.42 raeburn 10092: if ($changes{'unauth'}) {
10093: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
10094: }
10095: if ($changes{'auth'}) {
10096: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
10097: }
1.57 raeburn 10098: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10099: my $cathash;
10100: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10101: $cathash = $domconfig{'coursecategories'}{'cats'};
10102: } else {
10103: $cathash = {};
10104: }
10105: my (@cats,@trails,%allitems);
10106: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10107: if (keys(%deletions) > 0) {
10108: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10109: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10110: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10111: }
10112: $resulttext .= '</ul></li>';
10113: }
10114: if (keys(%reorderings) > 0) {
10115: my %sort_by_trail;
10116: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10117: foreach my $key (keys(%reorderings)) {
10118: if ($allitems{$key} ne '') {
10119: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10120: }
1.48 raeburn 10121: }
1.57 raeburn 10122: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10123: $resulttext .= '<li>'.$trails[$trail].'</li>';
10124: }
10125: $resulttext .= '</ul></li>';
1.48 raeburn 10126: }
1.57 raeburn 10127: if (keys(%adds) > 0) {
10128: my %sort_by_trail;
10129: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10130: foreach my $key (keys(%adds)) {
10131: if ($allitems{$key} ne '') {
10132: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10133: }
10134: }
10135: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10136: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10137: }
1.57 raeburn 10138: $resulttext .= '</ul></li>';
1.48 raeburn 10139: }
10140: }
10141: $resulttext .= '</ul>';
1.160.6.43 raeburn 10142: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10144: if ($changes{'auth'}) {
10145: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10146: }
10147: if ($changes{'unauth'}) {
10148: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10149: }
10150: my $cachetime = 24*60*60;
10151: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10152: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10153: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10154: }
10155: }
1.48 raeburn 10156: } else {
10157: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10158: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10159: }
10160: } else {
1.120 raeburn 10161: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10162: }
10163: return $resulttext;
10164: }
10165:
1.69 raeburn 10166: sub modify_serverstatuses {
10167: my ($dom,%domconfig) = @_;
10168: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10169: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10170: %currserverstatus = %{$domconfig{'serverstatuses'}};
10171: }
10172: my @pages = &serverstatus_pages();
10173: foreach my $type (@pages) {
10174: $newserverstatus{$type}{'namedusers'} = '';
10175: $newserverstatus{$type}{'machines'} = '';
10176: if (defined($env{'form.'.$type.'_namedusers'})) {
10177: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10178: my @okusers;
10179: foreach my $user (@users) {
10180: my ($uname,$udom) = split(/:/,$user);
10181: if (($udom =~ /^$match_domain$/) &&
10182: (&Apache::lonnet::domain($udom)) &&
10183: ($uname =~ /^$match_username$/)) {
10184: if (!grep(/^\Q$user\E/,@okusers)) {
10185: push(@okusers,$user);
10186: }
10187: }
10188: }
10189: if (@okusers > 0) {
10190: @okusers = sort(@okusers);
10191: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10192: }
10193: }
10194: if (defined($env{'form.'.$type.'_machines'})) {
10195: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10196: my @okmachines;
10197: foreach my $ip (@machines) {
10198: my @parts = split(/\./,$ip);
10199: next if (@parts < 4);
10200: my $badip = 0;
10201: for (my $i=0; $i<4; $i++) {
10202: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10203: $badip = 1;
10204: last;
10205: }
10206: }
10207: if (!$badip) {
10208: push(@okmachines,$ip);
10209: }
10210: }
10211: @okmachines = sort(@okmachines);
10212: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10213: }
10214: }
10215: my %serverstatushash = (
10216: serverstatuses => \%newserverstatus,
10217: );
10218: foreach my $type (@pages) {
1.83 raeburn 10219: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10220: my (@current,@new);
1.83 raeburn 10221: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10222: if ($currserverstatus{$type}{$setting} ne '') {
10223: @current = split(/,/,$currserverstatus{$type}{$setting});
10224: }
10225: }
10226: if ($newserverstatus{$type}{$setting} ne '') {
10227: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10228: }
10229: if (@current > 0) {
10230: if (@new > 0) {
10231: foreach my $item (@current) {
10232: if (!grep(/^\Q$item\E$/,@new)) {
10233: $changes{$type}{$setting} = 1;
1.82 raeburn 10234: last;
10235: }
10236: }
1.84 raeburn 10237: foreach my $item (@new) {
10238: if (!grep(/^\Q$item\E$/,@current)) {
10239: $changes{$type}{$setting} = 1;
10240: last;
1.82 raeburn 10241: }
10242: }
10243: } else {
1.83 raeburn 10244: $changes{$type}{$setting} = 1;
1.69 raeburn 10245: }
1.83 raeburn 10246: } elsif (@new > 0) {
10247: $changes{$type}{$setting} = 1;
1.69 raeburn 10248: }
10249: }
10250: }
10251: if (keys(%changes) > 0) {
1.81 raeburn 10252: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10253: my $putresult = &Apache::lonnet::put_dom('configuration',
10254: \%serverstatushash,$dom);
10255: if ($putresult eq 'ok') {
10256: $resulttext .= &mt('Changes made:').'<ul>';
10257: foreach my $type (@pages) {
1.84 raeburn 10258: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10259: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10260: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10261: if ($newserverstatus{$type}{'namedusers'} eq '') {
10262: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10263: } else {
10264: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10265: }
1.84 raeburn 10266: }
10267: if ($changes{$type}{'machines'}) {
1.69 raeburn 10268: if ($newserverstatus{$type}{'machines'} eq '') {
10269: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10270: } else {
10271: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10272: }
10273:
10274: }
10275: $resulttext .= '</ul></li>';
10276: }
10277: }
10278: $resulttext .= '</ul>';
10279: } else {
10280: $resulttext = '<span class="LC_error">'.
10281: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10282:
10283: }
10284: } else {
10285: $resulttext = &mt('No changes made to access to server status pages');
10286: }
10287: return $resulttext;
10288: }
10289:
1.118 jms 10290: sub modify_helpsettings {
1.122 jms 10291: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10292: my ($resulttext,$errors,%changes,%helphash);
10293: my %defaultchecked = ('submitbugs' => 'on');
10294: my @offon = ('off','on');
1.118 jms 10295: my @toggles = ('submitbugs');
10296: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10297: foreach my $item (@toggles) {
1.160.6.5 raeburn 10298: if ($defaultchecked{$item} eq 'on') {
10299: if ($domconfig{'helpsettings'}{$item} eq '') {
10300: if ($env{'form.'.$item} eq '0') {
10301: $changes{$item} = 1;
10302: }
10303: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10304: $changes{$item} = 1;
10305: }
10306: } elsif ($defaultchecked{$item} eq 'off') {
10307: if ($domconfig{'helpsettings'}{$item} eq '') {
10308: if ($env{'form.'.$item} eq '1') {
10309: $changes{$item} = 1;
10310: }
10311: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10312: $changes{$item} = 1;
10313: }
1.160.6.26 raeburn 10314: }
1.160.6.5 raeburn 10315: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10316: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 10317: }
10318: }
1.118 jms 10319: }
1.123 jms 10320: my $putresult;
10321: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10322: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10323: if ($putresult eq 'ok') {
10324: $resulttext = &mt('Changes made:').'<ul>';
10325: foreach my $item (sort(keys(%changes))) {
10326: if ($item eq 'submitbugs') {
10327: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10328: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10329: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10330: }
10331: }
10332: $resulttext .= '</ul>';
10333: } else {
10334: $resulttext = &mt('No changes made to help settings');
10335: $errors .= '<li><span class="LC_error">'.
10336: &mt('An error occurred storing the settings: [_1]',
10337: $putresult).'</span></li>';
10338: }
1.118 jms 10339: }
10340: if ($errors) {
1.160.6.5 raeburn 10341: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10342: $errors.'</ul>';
10343: }
10344: return $resulttext;
10345: }
10346:
1.121 raeburn 10347: sub modify_coursedefaults {
1.160.6.27 raeburn 10348: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10349: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10350: my %defaultchecked = (
10351: 'uselcmath' => 'on',
10352: 'usejsme' => 'on'
10353: );
10354: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10355: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 10356: 'uploadquota_community','uploadquota_textbook');
10357: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10358: my %staticdefaults = (
10359: anonsurvey_threshold => 10,
10360: uploadquota => 500,
1.160.6.57 raeburn 10361: postsubmit => 60,
1.160.6.21 raeburn 10362: );
1.121 raeburn 10363:
10364: $defaultshash{'coursedefaults'} = {};
10365:
10366: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10367: if ($domconfig{'coursedefaults'} eq '') {
10368: $domconfig{'coursedefaults'} = {};
10369: }
10370: }
10371:
10372: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10373: foreach my $item (@toggles) {
10374: if ($defaultchecked{$item} eq 'on') {
10375: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10376: ($env{'form.'.$item} eq '0')) {
10377: $changes{$item} = 1;
1.160.6.16 raeburn 10378: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10379: $changes{$item} = 1;
10380: }
10381: } elsif ($defaultchecked{$item} eq 'off') {
10382: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10383: ($env{'form.'.$item} eq '1')) {
10384: $changes{$item} = 1;
10385: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10386: $changes{$item} = 1;
10387: }
10388: }
10389: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10390: }
1.160.6.21 raeburn 10391: foreach my $item (@numbers) {
10392: my ($currdef,$newdef);
1.160.6.26 raeburn 10393: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10394: if ($item eq 'anonsurvey_threshold') {
10395: $currdef = $domconfig{'coursedefaults'}{$item};
10396: $newdef =~ s/\D//g;
10397: if ($newdef eq '' || $newdef < 1) {
10398: $newdef = 1;
10399: }
10400: $defaultshash{'coursedefaults'}{$item} = $newdef;
10401: } else {
10402: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10403: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10404: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10405: }
10406: $newdef =~ s/[^\w.\-]//g;
10407: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10408: }
10409: if ($currdef ne $newdef) {
10410: my $staticdef;
10411: if ($item eq 'anonsurvey_threshold') {
10412: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10413: $changes{$item} = 1;
10414: }
10415: } else {
10416: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10417: $changes{'uploadquota'} = 1;
10418: }
10419: }
1.139 raeburn 10420: }
10421: }
1.160.6.64 raeburn 10422: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
10423: my @currclonecode;
10424: if (ref($currclone) eq 'HASH') {
10425: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
10426: @currclonecode = @{$currclone->{'instcode'}};
10427: }
10428: }
10429: my $newclone;
10430: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
10431: $newclone = $env{'form.canclone'};
10432: }
10433: if ($newclone eq 'instcode') {
10434: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
10435: my (%codedefaults,@code_order,@clonecode);
10436: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
10437: \@code_order);
10438: foreach my $item (@code_order) {
10439: if (grep(/^\Q$item\E$/,@newcodes)) {
10440: push(@clonecode,$item);
10441: }
10442: }
10443: if (@clonecode) {
10444: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
10445: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
10446: if (@diffs) {
10447: $changes{'canclone'} = 1;
10448: }
10449: } else {
10450: $newclone eq '';
10451: }
10452: } elsif ($newclone ne '') {
10453: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
10454: }
10455: if ($newclone ne $currclone) {
10456: $changes{'canclone'} = 1;
10457: }
1.160.6.57 raeburn 10458: my %credits;
10459: foreach my $type (@types) {
10460: unless ($type eq 'community') {
10461: $credits{$type} = $env{'form.'.$type.'_credits'};
10462: $credits{$type} =~ s/[^\d.]+//g;
10463: }
10464: }
10465: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10466: ($env{'form.coursecredits'} eq '1')) {
10467: $changes{'coursecredits'} = 1;
10468: foreach my $type (keys(%credits)) {
10469: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10470: }
10471: } else {
10472: if ($env{'form.coursecredits'} eq '1') {
10473: foreach my $type (@types) {
10474: unless ($type eq 'community') {
10475: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10476: $changes{'coursecredits'} = 1;
10477: }
10478: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10479: }
10480: }
10481: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10482: foreach my $type (@types) {
10483: unless ($type eq 'community') {
10484: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10485: $changes{'coursecredits'} = 1;
10486: last;
10487: }
10488: }
10489: }
10490: }
10491: }
10492: if ($env{'form.postsubmit'} eq '1') {
10493: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10494: my %currtimeout;
10495: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10496: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10497: $changes{'postsubmit'} = 1;
10498: }
10499: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10500: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10501: }
10502: } else {
10503: $changes{'postsubmit'} = 1;
10504: }
10505: foreach my $type (@types) {
10506: my $timeout = $env{'form.'.$type.'_timeout'};
10507: $timeout =~ s/\D//g;
10508: if ($timeout == $staticdefaults{'postsubmit'}) {
10509: $timeout = '';
10510: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10511: $timeout = '0';
10512: }
10513: unless ($timeout eq '') {
10514: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10515: }
10516: if (exists($currtimeout{$type})) {
10517: if ($timeout ne $currtimeout{$type}) {
10518: $changes{'postsubmit'} = 1;
10519: }
10520: } elsif ($timeout ne '') {
10521: $changes{'postsubmit'} = 1;
10522: }
10523: }
10524: } else {
10525: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10526: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10527: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10528: $changes{'postsubmit'} = 1;
10529: }
10530: } else {
10531: $changes{'postsubmit'} = 1;
10532: }
1.160.6.16 raeburn 10533: }
1.121 raeburn 10534: }
10535: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10536: $dom);
10537: if ($putresult eq 'ok') {
10538: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10539: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10540: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 10541: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
10542: ($changes{'canclone'})) {
1.160.6.57 raeburn 10543: foreach my $item ('uselcmath','usejsme') {
10544: if ($changes{$item}) {
10545: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10546: }
1.160.6.16 raeburn 10547: }
10548: if ($changes{'coursecredits'}) {
10549: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10550: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10551: $domdefaults{$type.'credits'} =
10552: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10553: }
10554: }
10555: }
10556: if ($changes{'postsubmit'}) {
10557: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10558: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10559: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10560: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10561: $domdefaults{$type.'postsubtimeout'} =
10562: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10563: }
10564: }
1.160.6.16 raeburn 10565: }
10566: }
1.160.6.21 raeburn 10567: if ($changes{'uploadquota'}) {
10568: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10569: foreach my $type (@types) {
10570: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10571: }
10572: }
10573: }
1.160.6.64 raeburn 10574: if ($changes{'canclone'}) {
10575: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10576: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10577: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
10578: if (@clonecodes) {
10579: $domdefaults{'canclone'} = join('+',@clonecodes);
10580: }
10581: }
10582: } else {
10583: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
10584: }
10585: }
1.121 raeburn 10586: my $cachetime = 24*60*60;
10587: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10588: if (ref($lastactref) eq 'HASH') {
10589: $lastactref->{'domdefaults'} = 1;
10590: }
1.121 raeburn 10591: }
10592: $resulttext = &mt('Changes made:').'<ul>';
10593: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10594: if ($item eq 'uselcmath') {
1.121 raeburn 10595: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10596: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10597: } else {
1.160.6.57 raeburn 10598: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10599: }
10600: } elsif ($item eq 'usejsme') {
10601: if ($env{'form.'.$item} eq '1') {
10602: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10603: } else {
10604: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10605: }
1.139 raeburn 10606: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10607: $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 10608: } elsif ($item eq 'uploadquota') {
10609: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10610: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10611: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10612: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10613: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10614:
1.160.6.21 raeburn 10615: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10616: '</ul>'.
10617: '</li>';
10618: } else {
10619: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10620: }
1.160.6.57 raeburn 10621: } elsif ($item eq 'postsubmit') {
10622: if ($domdefaults{'postsubmit'} eq 'off') {
10623: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10624: } else {
10625: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10626: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10627: $resulttext .= &mt('durations:').'<ul>';
10628: foreach my $type (@types) {
10629: $resulttext .= '<li>';
10630: my $timeout;
10631: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10632: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10633: }
10634: my $display;
10635: if ($timeout eq '0') {
10636: $display = &mt('unlimited');
10637: } elsif ($timeout eq '') {
10638: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10639: } else {
10640: $display = &mt('[quant,_1,second]',$timeout);
10641: }
10642: if ($type eq 'community') {
10643: $resulttext .= &mt('Communities');
10644: } elsif ($type eq 'official') {
10645: $resulttext .= &mt('Official courses');
10646: } elsif ($type eq 'unofficial') {
10647: $resulttext .= &mt('Unofficial courses');
10648: } elsif ($type eq 'textbook') {
10649: $resulttext .= &mt('Textbook courses');
10650: }
10651: $resulttext .= ' -- '.$display.'</li>';
10652: }
10653: $resulttext .= '</ul>';
10654: }
10655: $resulttext .= '</li>';
10656: }
1.160.6.16 raeburn 10657: } elsif ($item eq 'coursecredits') {
10658: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10659: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10660: ($domdefaults{'unofficialcredits'} eq '') &&
10661: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10662: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10663: } else {
10664: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10665: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10666: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10667: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10668: '</ul>'.
10669: '</li>';
10670: }
10671: } else {
10672: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10673: }
1.160.6.64 raeburn 10674: } elsif ($item eq 'canclone') {
10675: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10676: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10677: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
10678: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
10679: }
10680: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
10681: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
10682: } else {
10683: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
10684: }
1.140 raeburn 10685: }
1.121 raeburn 10686: }
10687: $resulttext .= '</ul>';
10688: } else {
10689: $resulttext = &mt('No changes made to course defaults');
10690: }
10691: } else {
10692: $resulttext = '<span class="LC_error">'.
10693: &mt('An error occurred: [_1]',$putresult).'</span>';
10694: }
10695: return $resulttext;
10696: }
10697:
1.160.6.37 raeburn 10698: sub modify_selfenrollment {
10699: my ($dom,$lastactref,%domconfig) = @_;
10700: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10701: my @types = ('official','unofficial','community','textbook');
10702: my %titles = &tool_titles();
10703: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10704: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10705: $ordered{'default'} = ['types','registered','approval','limit'];
10706:
10707: my (%roles,%shown,%toplevel);
10708: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10709:
10710: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10711: if ($domconfig{'selfenrollment'} eq '') {
10712: $domconfig{'selfenrollment'} = {};
10713: }
10714: }
10715: %toplevel = (
10716: admin => 'Configuration Rights',
10717: default => 'Default settings',
10718: validation => 'Validation of self-enrollment requests',
10719: );
10720: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10721:
10722: if (ref($ordered{'admin'}) eq 'ARRAY') {
10723: foreach my $item (@{$ordered{'admin'}}) {
10724: foreach my $type (@types) {
10725: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10726: $selfenrollhash{'admin'}{$type}{$item} = 1;
10727: } else {
10728: $selfenrollhash{'admin'}{$type}{$item} = 0;
10729: }
10730: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10731: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10732: if ($selfenrollhash{'admin'}{$type}{$item} ne
10733: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10734: push(@{$changes{'admin'}{$type}},$item);
10735: }
10736: } else {
10737: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10738: push(@{$changes{'admin'}{$type}},$item);
10739: }
10740: }
10741: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10742: push(@{$changes{'admin'}{$type}},$item);
10743: }
10744: }
10745: }
10746: }
10747:
10748: foreach my $item (@{$ordered{'default'}}) {
10749: foreach my $type (@types) {
10750: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10751: if ($item eq 'types') {
10752: unless (($value eq 'all') || ($value eq 'dom')) {
10753: $value = '';
10754: }
10755: } elsif ($item eq 'registered') {
10756: unless ($value eq '1') {
10757: $value = 0;
10758: }
10759: } elsif ($item eq 'approval') {
10760: unless ($value =~ /^[012]$/) {
10761: $value = 0;
10762: }
10763: } else {
10764: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10765: $value = 'none';
10766: }
10767: }
10768: $selfenrollhash{'default'}{$type}{$item} = $value;
10769: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10770: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10771: if ($selfenrollhash{'default'}{$type}{$item} ne
10772: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10773: push(@{$changes{'default'}{$type}},$item);
10774: }
10775: } else {
10776: push(@{$changes{'default'}{$type}},$item);
10777: }
10778: } else {
10779: push(@{$changes{'default'}{$type}},$item);
10780: }
10781: if ($item eq 'limit') {
10782: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10783: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10784: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10785: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10786: }
10787: } else {
10788: $selfenrollhash{'default'}{$type}{'cap'} = '';
10789: }
10790: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10791: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10792: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10793: push(@{$changes{'default'}{$type}},'cap');
10794: }
10795: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10796: push(@{$changes{'default'}{$type}},'cap');
10797: }
10798: }
10799: }
10800: }
10801:
10802: foreach my $item (@{$itemsref}) {
10803: if ($item eq 'fields') {
10804: my @changed;
10805: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10806: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10807: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10808: }
10809: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10810: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10811: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10812: $domconfig{'selfenrollment'}{'validation'}{$item});
10813: } else {
10814: @changed = @{$selfenrollhash{'validation'}{$item}};
10815: }
10816: } else {
10817: @changed = @{$selfenrollhash{'validation'}{$item}};
10818: }
10819: if (@changed) {
10820: if ($selfenrollhash{'validation'}{$item}) {
10821: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10822: } else {
10823: $changes{'validation'}{$item} = &mt('None');
10824: }
10825: }
10826: } else {
10827: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10828: if ($item eq 'markup') {
10829: if ($env{'form.selfenroll_validation_'.$item}) {
10830: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10831: }
10832: }
10833: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10834: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10835: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10836: }
10837: }
10838: }
10839: }
10840:
10841: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10842: $dom);
10843: if ($putresult eq 'ok') {
10844: if (keys(%changes) > 0) {
10845: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10846: $resulttext = &mt('Changes made:').'<ul>';
10847: foreach my $key ('admin','default','validation') {
10848: if (ref($changes{$key}) eq 'HASH') {
10849: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10850: if ($key eq 'validation') {
10851: foreach my $item (@{$itemsref}) {
10852: if (exists($changes{$key}{$item})) {
10853: if ($item eq 'markup') {
10854: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10855: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10856: } else {
10857: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10858: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10859: }
10860: }
10861: }
10862: } else {
10863: foreach my $type (@types) {
10864: if ($type eq 'community') {
10865: $roles{'1'} = &mt('Community personnel');
10866: } else {
10867: $roles{'1'} = &mt('Course personnel');
10868: }
10869: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10870: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10871: if ($key eq 'admin') {
10872: my @mgrdc = ();
10873: if (ref($ordered{$key}) eq 'ARRAY') {
10874: foreach my $item (@{$ordered{'admin'}}) {
10875: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10876: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10877: push(@mgrdc,$item);
10878: }
10879: }
10880: }
10881: if (@mgrdc) {
10882: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10883: } else {
10884: delete($domdefaults{$type.'selfenrolladmdc'});
10885: }
10886: }
10887: } else {
10888: if (ref($ordered{$key}) eq 'ARRAY') {
10889: foreach my $item (@{$ordered{$key}}) {
10890: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10891: $domdefaults{$type.'selfenroll'.$item} =
10892: $selfenrollhash{$key}{$type}{$item};
10893: }
10894: }
10895: }
10896: }
10897: }
10898: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10899: foreach my $item (@{$ordered{$key}}) {
10900: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10901: $resulttext .= '<li>';
10902: if ($key eq 'admin') {
10903: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10904: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10905: } else {
10906: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10907: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10908: }
10909: $resulttext .= '</li>';
10910: }
10911: }
10912: $resulttext .= '</ul></li>';
10913: }
10914: }
10915: $resulttext .= '</ul></li>';
10916: }
10917: }
10918: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10919: my $cachetime = 24*60*60;
10920: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10921: if (ref($lastactref) eq 'HASH') {
10922: $lastactref->{'domdefaults'} = 1;
10923: }
10924: }
10925: }
10926: $resulttext .= '</ul>';
10927: } else {
10928: $resulttext = &mt('No changes made to self-enrollment settings');
10929: }
10930: } else {
10931: $resulttext = '<span class="LC_error">'.
10932: &mt('An error occurred: [_1]',$putresult).'</span>';
10933: }
10934: return $resulttext;
10935: }
10936:
1.137 raeburn 10937: sub modify_usersessions {
1.160.6.27 raeburn 10938: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10939: my @hostingtypes = ('version','excludedomain','includedomain');
10940: my @offloadtypes = ('primary','default');
10941: my %types = (
10942: remote => \@hostingtypes,
10943: hosted => \@hostingtypes,
10944: spares => \@offloadtypes,
10945: );
10946: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10947: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10948: my (%by_ip,%by_location,@intdoms);
10949: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10950: my @locations = sort(keys(%by_location));
1.137 raeburn 10951: my (%defaultshash,%changes);
10952: foreach my $prefix (@prefixes) {
10953: $defaultshash{'usersessions'}{$prefix} = {};
10954: }
1.160.6.27 raeburn 10955: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10956: my $resulttext;
1.138 raeburn 10957: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10958: foreach my $prefix (@prefixes) {
1.145 raeburn 10959: next if ($prefix eq 'spares');
10960: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10961: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10962: if ($type eq 'version') {
10963: my $value = $env{'form.'.$prefix.'_'.$type};
10964: my $okvalue;
10965: if ($value ne '') {
10966: if (grep(/^\Q$value\E$/,@lcversions)) {
10967: $okvalue = $value;
10968: }
10969: }
10970: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10971: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10972: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10973: if ($inuse == 0) {
10974: $changes{$prefix}{$type} = 1;
10975: } else {
10976: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10977: $changes{$prefix}{$type} = 1;
10978: }
10979: if ($okvalue ne '') {
10980: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10981: }
10982: }
10983: } else {
10984: if (($inuse == 1) && ($okvalue ne '')) {
10985: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10986: $changes{$prefix}{$type} = 1;
10987: }
10988: }
10989: } else {
10990: if (($inuse == 1) && ($okvalue ne '')) {
10991: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10992: $changes{$prefix}{$type} = 1;
10993: }
10994: }
10995: } else {
10996: if (($inuse == 1) && ($okvalue ne '')) {
10997: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10998: $changes{$prefix}{$type} = 1;
10999: }
11000: }
11001: } else {
11002: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11003: my @okvals;
11004: foreach my $val (@vals) {
1.138 raeburn 11005: if ($val =~ /:/) {
11006: my @items = split(/:/,$val);
11007: foreach my $item (@items) {
11008: if (ref($by_location{$item}) eq 'ARRAY') {
11009: push(@okvals,$item);
11010: }
11011: }
11012: } else {
11013: if (ref($by_location{$val}) eq 'ARRAY') {
11014: push(@okvals,$val);
11015: }
1.137 raeburn 11016: }
11017: }
11018: @okvals = sort(@okvals);
11019: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11020: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11021: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11022: if ($inuse == 0) {
11023: $changes{$prefix}{$type} = 1;
11024: } else {
11025: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11026: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11027: if (@changed > 0) {
11028: $changes{$prefix}{$type} = 1;
11029: }
11030: }
11031: } else {
11032: if ($inuse == 1) {
11033: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11034: $changes{$prefix}{$type} = 1;
11035: }
11036: }
11037: } else {
11038: if ($inuse == 1) {
11039: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11040: $changes{$prefix}{$type} = 1;
11041: }
11042: }
11043: } else {
11044: if ($inuse == 1) {
11045: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11046: $changes{$prefix}{$type} = 1;
11047: }
11048: }
11049: }
11050: }
11051: }
1.145 raeburn 11052:
11053: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11054: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11055: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11056: my $savespares;
11057:
11058: foreach my $lonhost (sort(keys(%servers))) {
11059: my $serverhomeID =
11060: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11061: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11062: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11063: my %spareschg;
11064: foreach my $type (@{$types{'spares'}}) {
11065: my @okspares;
11066: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
11067: foreach my $server (@checked) {
1.152 raeburn 11068: if (&Apache::lonnet::hostname($server) ne '') {
11069: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
11070: unless (grep(/^\Q$server\E$/,@okspares)) {
11071: push(@okspares,$server);
11072: }
1.145 raeburn 11073: }
11074: }
11075: }
11076: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
11077: my $newspare;
1.152 raeburn 11078: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
11079: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 11080: $newspare = $new;
11081: }
11082: }
1.152 raeburn 11083: my @spares;
11084: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
11085: @spares = sort(@okspares,$newspare);
11086: } else {
11087: @spares = sort(@okspares);
11088: }
11089: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 11090: if (ref($spareid{$lonhost}) eq 'HASH') {
11091: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 11092: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 11093: if (@diffs > 0) {
11094: $spareschg{$type} = 1;
11095: }
11096: }
11097: }
11098: }
11099: if (keys(%spareschg) > 0) {
11100: $changes{'spares'}{$lonhost} = \%spareschg;
11101: }
11102: }
1.160.6.61 raeburn 11103: $defaultshash{'usersessions'}{'offloadnow'} = {};
11104: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
11105: my @okoffload;
11106: if (@offloadnow) {
11107: foreach my $server (@offloadnow) {
11108: if (&Apache::lonnet::hostname($server) ne '') {
11109: unless (grep(/^\Q$server\E$/,@okoffload)) {
11110: push(@okoffload,$server);
11111: }
11112: }
11113: }
11114: if (@okoffload) {
11115: foreach my $lonhost (@okoffload) {
11116: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
11117: }
11118: }
11119: }
1.145 raeburn 11120: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11121: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
11122: if (ref($changes{'spares'}) eq 'HASH') {
11123: if (keys(%{$changes{'spares'}}) > 0) {
11124: $savespares = 1;
11125: }
11126: }
11127: } else {
11128: $savespares = 1;
11129: }
1.160.6.61 raeburn 11130: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
11131: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
11132: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
11133: $changes{'offloadnow'} = 1;
11134: last;
11135: }
11136: }
11137: unless ($changes{'offloadnow'}) {
11138: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
11139: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
11140: $changes{'offloadnow'} = 1;
11141: last;
11142: }
11143: }
11144: }
11145: } elsif (@okoffload) {
11146: $changes{'offloadnow'} = 1;
11147: }
11148: } elsif (@okoffload) {
11149: $changes{'offloadnow'} = 1;
1.145 raeburn 11150: }
1.147 raeburn 11151: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11152: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 11153: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11154: $dom);
11155: if ($putresult eq 'ok') {
11156: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11157: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11158: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11159: }
11160: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11161: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11162: }
1.160.6.61 raeburn 11163: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11164: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11165: }
1.137 raeburn 11166: }
11167: my $cachetime = 24*60*60;
11168: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11169: if (ref($lastactref) eq 'HASH') {
11170: $lastactref->{'domdefaults'} = 1;
11171: }
1.147 raeburn 11172: if (keys(%changes) > 0) {
11173: my %lt = &usersession_titles();
11174: $resulttext = &mt('Changes made:').'<ul>';
11175: foreach my $prefix (@prefixes) {
11176: if (ref($changes{$prefix}) eq 'HASH') {
11177: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11178: if ($prefix eq 'spares') {
11179: if (ref($changes{$prefix}) eq 'HASH') {
11180: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11181: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 11182: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 11183: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11184: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 11185: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11186: foreach my $type (@{$types{$prefix}}) {
11187: if ($changes{$prefix}{$lonhost}{$type}) {
11188: my $offloadto = &mt('None');
11189: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11190: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11191: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11192: }
1.145 raeburn 11193: }
1.147 raeburn 11194: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 11195: }
1.137 raeburn 11196: }
11197: }
1.147 raeburn 11198: $resulttext .= '</li>';
1.137 raeburn 11199: }
11200: }
1.147 raeburn 11201: } else {
11202: foreach my $type (@{$types{$prefix}}) {
11203: if (defined($changes{$prefix}{$type})) {
11204: my $newvalue;
11205: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11206: if (ref($defaultshash{'usersessions'}{$prefix})) {
11207: if ($type eq 'version') {
11208: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11209: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11210: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11211: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11212: }
1.145 raeburn 11213: }
11214: }
11215: }
1.147 raeburn 11216: if ($newvalue eq '') {
11217: if ($type eq 'version') {
11218: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11219: } else {
11220: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11221: }
1.145 raeburn 11222: } else {
1.147 raeburn 11223: if ($type eq 'version') {
11224: $newvalue .= ' '.&mt('(or later)');
11225: }
11226: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11227: }
1.137 raeburn 11228: }
11229: }
11230: }
1.147 raeburn 11231: $resulttext .= '</ul>';
1.137 raeburn 11232: }
11233: }
1.160.6.61 raeburn 11234: if ($changes{'offloadnow'}) {
11235: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11236: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11237: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11238: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11239: $resulttext .= '<li>'.$lonhost.'</li>';
11240: }
11241: $resulttext .= '</ul>';
11242: } else {
11243: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11244: }
11245: } else {
11246: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11247: }
11248: }
1.147 raeburn 11249: $resulttext .= '</ul>';
11250: } else {
11251: $resulttext = $nochgmsg;
1.137 raeburn 11252: }
11253: } else {
11254: $resulttext = '<span class="LC_error">'.
11255: &mt('An error occurred: [_1]',$putresult).'</span>';
11256: }
11257: } else {
1.147 raeburn 11258: $resulttext = $nochgmsg;
1.137 raeburn 11259: }
11260: return $resulttext;
11261: }
11262:
1.150 raeburn 11263: sub modify_loadbalancing {
11264: my ($dom,%domconfig) = @_;
11265: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11266: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11267: my ($othertitle,$usertypes,$types) =
11268: &Apache::loncommon::sorted_inst_types($dom);
11269: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11270: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11271: my @sparestypes = ('primary','default');
11272: my %typetitles = &sparestype_titles();
11273: my $resulttext;
1.160.6.7 raeburn 11274: my (%currbalancer,%currtargets,%currrules,%existing);
11275: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11276: %existing = %{$domconfig{'loadbalancing'}};
11277: }
11278: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11279: \%currtargets,\%currrules);
11280: my ($saveloadbalancing,%defaultshash,%changes);
11281: my ($alltypes,$othertypes,$titles) =
11282: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11283: my %ruletitles = &offloadtype_text();
11284: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11285: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11286: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11287: if ($balancer eq '') {
11288: next;
11289: }
11290: if (!exists($servers{$balancer})) {
11291: if (exists($currbalancer{$balancer})) {
11292: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11293: }
1.160.6.7 raeburn 11294: next;
11295: }
11296: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11297: push(@{$changes{'delete'}},$balancer);
11298: next;
11299: }
11300: if (!exists($currbalancer{$balancer})) {
11301: push(@{$changes{'add'}},$balancer);
11302: }
11303: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11304: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11305: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11306: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11307: $saveloadbalancing = 1;
11308: }
11309: foreach my $sparetype (@sparestypes) {
11310: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11311: my @offloadto;
11312: foreach my $target (@targets) {
11313: if (($servers{$target}) && ($target ne $balancer)) {
11314: if ($sparetype eq 'default') {
11315: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11316: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11317: }
11318: }
1.160.6.7 raeburn 11319: unless(grep(/^\Q$target\E$/,@offloadto)) {
11320: push(@offloadto,$target);
11321: }
1.150 raeburn 11322: }
1.160.6.7 raeburn 11323: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11324: }
11325: }
1.160.6.7 raeburn 11326: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11327: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11328: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11329: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11330: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11331: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11332: }
1.160.6.7 raeburn 11333: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11334: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11335: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11336: }
11337: }
11338: }
11339: } else {
1.160.6.7 raeburn 11340: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11341: foreach my $sparetype (@sparestypes) {
11342: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11343: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11344: $changes{'curr'}{$balancer}{'targets'} = 1;
11345: }
1.150 raeburn 11346: }
11347: }
1.160.6.7 raeburn 11348: }
1.150 raeburn 11349: }
11350: my $ishomedom;
1.160.6.7 raeburn 11351: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11352: $ishomedom = 1;
1.150 raeburn 11353: }
11354: if (ref($alltypes) eq 'ARRAY') {
11355: foreach my $type (@{$alltypes}) {
11356: my $rule;
1.160.6.7 raeburn 11357: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11358: (!$ishomedom)) {
1.160.6.7 raeburn 11359: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11360: }
11361: if ($rule eq 'specific') {
1.160.6.55 raeburn 11362: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11363: if (exists($servers{$specifiedhost})) {
11364: $rule = $specifiedhost;
11365: }
1.150 raeburn 11366: }
1.160.6.7 raeburn 11367: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11368: if (ref($currrules{$balancer}) eq 'HASH') {
11369: if ($rule ne $currrules{$balancer}{$type}) {
11370: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11371: }
11372: } elsif ($rule ne '') {
1.160.6.7 raeburn 11373: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11374: }
11375: }
11376: }
1.160.6.7 raeburn 11377: }
11378: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11379: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11380: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11381: $defaultshash{'loadbalancing'} = {};
11382: }
11383: my $putresult = &Apache::lonnet::put_dom('configuration',
11384: \%defaultshash,$dom);
11385: if ($putresult eq 'ok') {
11386: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11387: my %toupdate;
1.160.6.7 raeburn 11388: if (ref($changes{'delete'}) eq 'ARRAY') {
11389: foreach my $balancer (sort(@{$changes{'delete'}})) {
11390: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11391: $toupdate{$balancer} = 1;
1.150 raeburn 11392: }
1.160.6.7 raeburn 11393: }
11394: if (ref($changes{'add'}) eq 'ARRAY') {
11395: foreach my $balancer (sort(@{$changes{'add'}})) {
11396: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11397: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11398: }
11399: }
11400: if (ref($changes{'curr'}) eq 'HASH') {
11401: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11402: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11403: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11404: if ($changes{'curr'}{$balancer}{'targets'}) {
11405: my %offloadstr;
11406: foreach my $sparetype (@sparestypes) {
11407: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11408: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11409: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11410: }
11411: }
1.150 raeburn 11412: }
1.160.6.7 raeburn 11413: if (keys(%offloadstr) == 0) {
11414: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11415: } else {
1.160.6.7 raeburn 11416: my $showoffload;
11417: foreach my $sparetype (@sparestypes) {
11418: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11419: if (defined($offloadstr{$sparetype})) {
11420: $showoffload .= $offloadstr{$sparetype};
11421: } else {
11422: $showoffload .= &mt('None');
11423: }
11424: $showoffload .= (' 'x3);
11425: }
11426: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11427: }
11428: }
11429: }
1.160.6.7 raeburn 11430: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11431: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11432: foreach my $type (@{$alltypes}) {
11433: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11434: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11435: my $balancetext;
11436: if ($rule eq '') {
11437: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11438: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11439: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11440: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11441: foreach my $sparetype (@sparestypes) {
11442: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11443: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11444: }
11445: }
1.160.6.55 raeburn 11446: foreach my $item (@{$alltypes}) {
11447: next if ($item =~ /^_LC_ipchange/);
11448: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11449: if ($hasrule eq 'homeserver') {
11450: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11451: } else {
11452: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11453: if ($servers{$hasrule}) {
11454: $toupdate{$hasrule} = 1;
11455: }
11456: }
11457: }
11458: }
11459: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11460: $balancetext = $ruletitles{$rule};
11461: } else {
11462: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11463: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11464: if ($receiver) {
11465: $toupdate{$receiver};
11466: }
11467: }
11468: } else {
11469: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11470: }
1.160.6.7 raeburn 11471: } else {
11472: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11473: }
1.160.6.26 raeburn 11474: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11475: }
11476: }
11477: }
11478: }
1.160.6.54 raeburn 11479: if (keys(%toupdate)) {
11480: my %thismachine;
11481: my $updatedhere;
11482: my $cachetime = 60*60*24;
11483: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11484: foreach my $lonhost (keys(%toupdate)) {
11485: if ($thismachine{$lonhost}) {
11486: unless ($updatedhere) {
11487: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11488: $defaultshash{'loadbalancing'},
11489: $cachetime);
11490: $updatedhere = 1;
11491: }
11492: } else {
11493: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11494: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11495: }
11496: }
11497: }
1.150 raeburn 11498: }
1.160.6.7 raeburn 11499: }
11500: if ($resulttext ne '') {
11501: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11502: } else {
11503: $resulttext = $nochgmsg;
11504: }
11505: } else {
1.160.6.7 raeburn 11506: $resulttext = $nochgmsg;
1.150 raeburn 11507: }
11508: } else {
1.160.6.7 raeburn 11509: $resulttext = '<span class="LC_error">'.
11510: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11511: }
11512: } else {
1.160.6.7 raeburn 11513: $resulttext = $nochgmsg;
1.150 raeburn 11514: }
11515: return $resulttext;
11516: }
11517:
1.48 raeburn 11518: sub recurse_check {
11519: my ($chkcats,$categories,$depth,$name) = @_;
11520: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11521: my $chg = 0;
11522: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11523: my $category = $chkcats->[$depth]{$name}[$j];
11524: my $item;
11525: if ($category eq '') {
11526: $chg ++;
11527: } else {
11528: my $deeper = $depth + 1;
11529: $item = &escape($category).':'.&escape($name).':'.$depth;
11530: if ($chg) {
11531: $categories->{$item} -= $chg;
11532: }
11533: &recurse_check($chkcats,$categories,$deeper,$category);
11534: $deeper --;
11535: }
11536: }
11537: }
11538: return;
11539: }
11540:
11541: sub recurse_cat_deletes {
11542: my ($item,$coursecategories,$deletions) = @_;
11543: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11544: my $subdepth = $depth + 1;
11545: if (ref($coursecategories) eq 'HASH') {
11546: foreach my $subitem (keys(%{$coursecategories})) {
11547: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11548: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11549: delete($coursecategories->{$subitem});
11550: $deletions->{$subitem} = 1;
11551: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11552: }
1.48 raeburn 11553: }
11554: }
11555: return;
11556: }
11557:
1.125 raeburn 11558: sub get_active_dcs {
11559: my ($dom) = @_;
1.160.6.16 raeburn 11560: my $now = time;
11561: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11562: my %domcoords;
11563: my $numdcs = 0;
11564: foreach my $server (keys(%dompersonnel)) {
11565: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11566: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11567: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11568: }
11569: }
11570: return %domcoords;
11571: }
11572:
11573: sub active_dc_picker {
1.160.6.16 raeburn 11574: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11575: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11576: my @domcoord = keys(%domcoords);
11577: if (keys(%currhash)) {
11578: foreach my $dc (keys(%currhash)) {
11579: unless (exists($domcoords{$dc})) {
11580: push(@domcoord,$dc);
11581: }
11582: }
11583: }
11584: @domcoord = sort(@domcoord);
11585: my $numdcs = scalar(@domcoord);
11586: my $rows = 0;
11587: my $table;
1.125 raeburn 11588: if ($numdcs > 1) {
1.160.6.16 raeburn 11589: $table = '<table>';
11590: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11591: my $rem = $i%($numinrow);
11592: if ($rem == 0) {
11593: if ($i > 0) {
1.160.6.16 raeburn 11594: $table .= '</tr>';
1.125 raeburn 11595: }
1.160.6.16 raeburn 11596: $table .= '<tr>';
11597: $rows ++;
1.125 raeburn 11598: }
1.160.6.16 raeburn 11599: my $check = '';
11600: if ($inputtype eq 'radio') {
11601: if (keys(%currhash) == 0) {
11602: if (!$i) {
11603: $check = ' checked="checked"';
11604: }
11605: } elsif (exists($currhash{$domcoord[$i]})) {
11606: $check = ' checked="checked"';
11607: }
11608: } else {
11609: if (exists($currhash{$domcoord[$i]})) {
11610: $check = ' checked="checked"';
1.125 raeburn 11611: }
11612: }
1.160.6.16 raeburn 11613: if ($i == @domcoord - 1) {
1.125 raeburn 11614: my $colsleft = $numinrow - $rem;
11615: if ($colsleft > 1) {
1.160.6.16 raeburn 11616: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11617: } else {
1.160.6.16 raeburn 11618: $table .= '<td class="LC_left_item">';
1.125 raeburn 11619: }
11620: } else {
1.160.6.16 raeburn 11621: $table .= '<td class="LC_left_item">';
11622: }
11623: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11624: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11625: $table .= '<span class="LC_nobreak"><label>'.
11626: '<input type="'.$inputtype.'" name="'.$name.'"'.
11627: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11628: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11629: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11630: }
1.160.6.33 raeburn 11631: $table .= '</label></span></td>';
1.125 raeburn 11632: }
1.160.6.16 raeburn 11633: $table .= '</tr></table>';
11634: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11635: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11636: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11637: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11638: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11639: if ($user ne $dcname.':'.$dcdom) {
11640: $table .= ' ('.$dcname.':'.$dcdom.')';
11641: }
1.160.6.16 raeburn 11642: } else {
11643: my $check;
11644: if (exists($currhash{$domcoord[0]})) {
11645: $check = ' checked="checked"';
11646: }
1.160.6.50 raeburn 11647: $table = '<span class="LC_nobreak"><label>'.
11648: '<input type="checkbox" name="'.$name.'" '.
11649: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11650: if ($user ne $dcname.':'.$dcdom) {
11651: $table .= ' ('.$dcname.':'.$dcdom.')';
11652: }
11653: $table .= '</label></span>';
1.160.6.16 raeburn 11654: $rows ++;
11655: }
1.125 raeburn 11656: }
1.160.6.16 raeburn 11657: return ($numdcs,$table,$rows);
1.125 raeburn 11658: }
11659:
1.137 raeburn 11660: sub usersession_titles {
11661: return &Apache::lonlocal::texthash(
11662: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11663: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11664: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11665: version => 'LON-CAPA version requirement',
1.138 raeburn 11666: excludedomain => 'Allow all, but exclude specific domains',
11667: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11668: primary => 'Primary (checked first)',
1.154 raeburn 11669: default => 'Default',
1.137 raeburn 11670: );
11671: }
11672:
1.152 raeburn 11673: sub id_for_thisdom {
11674: my (%servers) = @_;
11675: my %altids;
11676: foreach my $server (keys(%servers)) {
11677: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11678: if ($serverhome ne $server) {
11679: $altids{$serverhome} = $server;
11680: }
11681: }
11682: return %altids;
11683: }
11684:
1.150 raeburn 11685: sub count_servers {
11686: my ($currbalancer,%servers) = @_;
11687: my (@spares,$numspares);
11688: foreach my $lonhost (sort(keys(%servers))) {
11689: next if ($currbalancer eq $lonhost);
11690: push(@spares,$lonhost);
11691: }
11692: if ($currbalancer) {
11693: $numspares = scalar(@spares);
11694: } else {
11695: $numspares = scalar(@spares) - 1;
11696: }
11697: return ($numspares,@spares);
11698: }
11699:
11700: sub lonbalance_targets_js {
1.160.6.7 raeburn 11701: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11702: my $select = &mt('Select');
11703: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11704: if (ref($servers) eq 'HASH') {
11705: $alltargets = join("','",sort(keys(%{$servers})));
11706: my @homedoms;
11707: foreach my $server (sort(keys(%{$servers}))) {
11708: if (&Apache::lonnet::host_domain($server) eq $dom) {
11709: push(@homedoms,'1');
11710: } else {
11711: push(@homedoms,'0');
11712: }
11713: }
11714: $allishome = join("','",@homedoms);
11715: }
11716: if (ref($types) eq 'ARRAY') {
11717: if (@{$types} > 0) {
11718: @alltypes = @{$types};
11719: }
11720: }
11721: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11722: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11723: my (%currbalancer,%currtargets,%currrules,%existing);
11724: if (ref($settings) eq 'HASH') {
11725: %existing = %{$settings};
11726: }
11727: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11728: \%currtargets,\%currrules);
11729: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11730: return <<"END";
11731:
11732: <script type="text/javascript">
11733: // <![CDATA[
11734:
1.160.6.7 raeburn 11735: currBalancers = new Array('$balancers');
11736:
11737: function toggleTargets(balnum) {
11738: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11739: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11740: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11741: var prevbalancer = prevhostitem.value;
11742: var baltotal = document.getElementById('loadbalancing_total').value;
11743: prevhostitem.value = balancer;
11744: if (prevbalancer != '') {
11745: var prevIdx = currBalancers.indexOf(prevbalancer);
11746: if (prevIdx != -1) {
11747: currBalancers.splice(prevIdx,1);
11748: }
11749: }
1.150 raeburn 11750: if (balancer == '') {
1.160.6.7 raeburn 11751: hideSpares(balnum);
1.150 raeburn 11752: } else {
1.160.6.7 raeburn 11753: var currIdx = currBalancers.indexOf(balancer);
11754: if (currIdx == -1) {
11755: currBalancers.push(balancer);
11756: }
1.150 raeburn 11757: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11758: var ishomedom = homedoms[lonhostitem.selectedIndex];
11759: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11760: }
1.160.6.7 raeburn 11761: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11762: return;
11763: }
11764:
1.160.6.7 raeburn 11765: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11766: var alltargets = new Array('$alltargets');
11767: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11768: var offloadtypes = new Array('primary','default');
11769:
1.160.6.7 raeburn 11770: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11771: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11772:
1.151 raeburn 11773: for (var i=0; i<offloadtypes.length; i++) {
11774: var count = 0;
11775: for (var j=0; j<alltargets.length; j++) {
11776: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11777: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11778: item.value = alltargets[j];
11779: item.style.textAlign='left';
11780: item.style.textFace='normal';
11781: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11782: if (currBalancers.indexOf(alltargets[j]) == -1) {
11783: item.disabled = '';
11784: } else {
11785: item.disabled = 'disabled';
11786: item.checked = false;
11787: }
1.151 raeburn 11788: count ++;
11789: }
1.150 raeburn 11790: }
11791: }
1.151 raeburn 11792: for (var k=0; k<insttypes.length; k++) {
11793: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11794: if (ishomedom == 1) {
1.160.6.7 raeburn 11795: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11796: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11797: } else {
1.160.6.7 raeburn 11798: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11799: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11800: }
11801: } else {
1.160.6.7 raeburn 11802: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11803: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11804: }
1.151 raeburn 11805: if ((insttypes[k] != '_LC_external') &&
11806: ((insttypes[k] != '_LC_internetdom') ||
11807: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11808: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11809: item.options.length = 0;
11810: item.options[0] = new Option("","",true,true);
11811: var idx = 0;
1.151 raeburn 11812: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11813: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11814: idx ++;
11815: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11816: }
11817: }
11818: }
11819: }
11820: return;
11821: }
11822:
1.160.6.7 raeburn 11823: function hideSpares(balnum) {
1.150 raeburn 11824: var alltargets = new Array('$alltargets');
11825: var insttypes = new Array('$allinsttypes');
11826: var offloadtypes = new Array('primary','default');
11827:
1.160.6.7 raeburn 11828: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11829: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11830:
11831: var total = alltargets.length - 1;
11832: for (var i=0; i<offloadtypes; i++) {
11833: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11834: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11835: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11836: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11837: }
1.150 raeburn 11838: }
11839: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11840: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11841: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11842: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11843: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11844: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11845: }
11846: }
11847: return;
11848: }
11849:
1.160.6.7 raeburn 11850: function checkOffloads(item,balnum,type) {
1.150 raeburn 11851: var alltargets = new Array('$alltargets');
11852: var offloadtypes = new Array('primary','default');
11853: if (item.checked) {
11854: var total = alltargets.length - 1;
11855: var other;
11856: if (type == offloadtypes[0]) {
1.151 raeburn 11857: other = offloadtypes[1];
1.150 raeburn 11858: } else {
1.151 raeburn 11859: other = offloadtypes[0];
1.150 raeburn 11860: }
11861: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11862: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11863: if (server == item.value) {
1.160.6.7 raeburn 11864: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11865: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11866: }
11867: }
11868: }
11869: }
11870: return;
11871: }
11872:
1.160.6.7 raeburn 11873: function singleServerToggle(balnum,type) {
11874: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11875: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11876: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11877: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11878:
11879: } else {
1.160.6.7 raeburn 11880: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11881: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11882: }
11883: return;
11884: }
11885:
1.160.6.7 raeburn 11886: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11887: if (type == '_LC_external') {
1.160.6.26 raeburn 11888: return;
1.150 raeburn 11889: }
1.160.6.7 raeburn 11890: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11891: for (var i=0; i<typesRules.length; i++) {
11892: if (formname.elements[typesRules[i]].checked) {
11893: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11894: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11895: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11896: } else {
1.160.6.7 raeburn 11897: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11898: }
11899: }
11900: }
11901: return;
11902: }
11903:
11904: function balancerDeleteChange(balnum) {
11905: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11906: var baltotal = document.getElementById('loadbalancing_total').value;
11907: var addtarget;
11908: var removetarget;
11909: var action = 'delete';
11910: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11911: var lonhost = hostitem.value;
11912: var currIdx = currBalancers.indexOf(lonhost);
11913: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11914: if (currIdx != -1) {
11915: currBalancers.splice(currIdx,1);
11916: }
11917: addtarget = lonhost;
11918: } else {
11919: if (currIdx == -1) {
11920: currBalancers.push(lonhost);
11921: }
11922: removetarget = lonhost;
11923: action = 'undelete';
11924: }
11925: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11926: }
11927: return;
11928: }
11929:
11930: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11931: if (baltotal > 1) {
11932: var offloadtypes = new Array('primary','default');
11933: var alltargets = new Array('$alltargets');
11934: var insttypes = new Array('$allinsttypes');
11935: for (var i=0; i<baltotal; i++) {
11936: if (i != balnum) {
11937: for (var j=0; j<offloadtypes.length; j++) {
11938: var total = alltargets.length - 1;
11939: for (var k=0; k<total; k++) {
11940: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11941: var server = serveritem.value;
11942: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11943: if (server == addtarget) {
11944: serveritem.disabled = '';
11945: }
11946: }
11947: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11948: if (server == removetarget) {
11949: serveritem.disabled = 'disabled';
11950: serveritem.checked = false;
11951: }
11952: }
11953: }
11954: }
11955: for (var j=0; j<insttypes.length; j++) {
11956: if (insttypes[j] != '_LC_external') {
11957: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11958: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11959: var currSel = singleserver.selectedIndex;
11960: var currVal = singleserver.options[currSel].value;
11961: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11962: var numoptions = singleserver.options.length;
11963: var needsnew = 1;
11964: for (var k=0; k<numoptions; k++) {
11965: if (singleserver.options[k] == addtarget) {
11966: needsnew = 0;
11967: break;
11968: }
11969: }
11970: if (needsnew == 1) {
11971: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11972: }
11973: }
11974: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11975: singleserver.options.length = 0;
11976: if ((currVal) && (currVal != removetarget)) {
11977: singleserver.options[0] = new Option("","",false,false);
11978: } else {
11979: singleserver.options[0] = new Option("","",true,true);
11980: }
11981: var idx = 0;
11982: for (var m=0; m<alltargets.length; m++) {
11983: if (currBalancers.indexOf(alltargets[m]) == -1) {
11984: idx ++;
11985: if (currVal == alltargets[m]) {
11986: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11987: } else {
11988: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11989: }
11990: }
11991: }
11992: }
11993: }
11994: }
11995: }
1.150 raeburn 11996: }
11997: }
11998: }
11999: return;
12000: }
12001:
1.152 raeburn 12002: // ]]>
12003: </script>
12004:
12005: END
12006: }
12007:
12008: sub new_spares_js {
12009: my @sparestypes = ('primary','default');
12010: my $types = join("','",@sparestypes);
12011: my $select = &mt('Select');
12012: return <<"END";
12013:
12014: <script type="text/javascript">
12015: // <![CDATA[
12016:
12017: function updateNewSpares(formname,lonhost) {
12018: var types = new Array('$types');
12019: var include = new Array();
12020: var exclude = new Array();
12021: for (var i=0; i<types.length; i++) {
12022: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12023: for (var j=0; j<spareboxes.length; j++) {
12024: if (formname.elements[spareboxes[j]].checked) {
12025: exclude.push(formname.elements[spareboxes[j]].value);
12026: } else {
12027: include.push(formname.elements[spareboxes[j]].value);
12028: }
12029: }
12030: }
12031: for (var i=0; i<types.length; i++) {
12032: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12033: var selIdx = newSpare.selectedIndex;
12034: var currnew = newSpare.options[selIdx].value;
12035: var okSpares = new Array();
12036: for (var j=0; j<newSpare.options.length; j++) {
12037: var possible = newSpare.options[j].value;
12038: if (possible != '') {
12039: if (exclude.indexOf(possible) == -1) {
12040: okSpares.push(possible);
12041: } else {
12042: if (currnew == possible) {
12043: selIdx = 0;
12044: }
12045: }
12046: }
12047: }
12048: for (var k=0; k<include.length; k++) {
12049: if (okSpares.indexOf(include[k]) == -1) {
12050: okSpares.push(include[k]);
12051: }
12052: }
12053: okSpares.sort();
12054: newSpare.options.length = 0;
12055: if (selIdx == 0) {
12056: newSpare.options[0] = new Option("$select","",true,true);
12057: } else {
12058: newSpare.options[0] = new Option("$select","",false,false);
12059: }
12060: for (var m=0; m<okSpares.length; m++) {
12061: var idx = m+1;
12062: var selThis = 0;
12063: if (selIdx != 0) {
12064: if (okSpares[m] == currnew) {
12065: selThis = 1;
12066: }
12067: }
12068: if (selThis == 1) {
12069: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
12070: } else {
12071: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
12072: }
12073: }
12074: }
12075: return;
12076: }
12077:
12078: function checkNewSpares(lonhost,type) {
12079: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
12080: var chosen = newSpare.options[newSpare.selectedIndex].value;
12081: if (chosen != '') {
12082: var othertype;
12083: var othernewSpare;
12084: if (type == 'primary') {
12085: othernewSpare = document.getElementById('newspare_default_'+lonhost);
12086: }
12087: if (type == 'default') {
12088: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
12089: }
12090: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
12091: othernewSpare.selectedIndex = 0;
12092: }
12093: }
12094: return;
12095: }
12096:
12097: // ]]>
12098: </script>
12099:
12100: END
12101:
12102: }
12103:
12104: sub common_domprefs_js {
12105: return <<"END";
12106:
12107: <script type="text/javascript">
12108: // <![CDATA[
12109:
1.150 raeburn 12110: function getIndicesByName(formname,item) {
1.152 raeburn 12111: var group = new Array();
1.150 raeburn 12112: for (var i=0;i<formname.elements.length;i++) {
12113: if (formname.elements[i].name == item) {
1.152 raeburn 12114: group.push(formname.elements[i].id);
1.150 raeburn 12115: }
12116: }
1.152 raeburn 12117: return group;
1.150 raeburn 12118: }
12119:
12120: // ]]>
12121: </script>
12122:
12123: END
1.152 raeburn 12124:
1.150 raeburn 12125: }
12126:
1.160.6.5 raeburn 12127: sub recaptcha_js {
12128: my %lt = &captcha_phrases();
12129: return <<"END";
12130:
12131: <script type="text/javascript">
12132: // <![CDATA[
12133:
12134: function updateCaptcha(caller,context) {
12135: var privitem;
12136: var pubitem;
12137: var privtext;
12138: var pubtext;
12139: if (document.getElementById(context+'_recaptchapub')) {
12140: pubitem = document.getElementById(context+'_recaptchapub');
12141: } else {
12142: return;
12143: }
12144: if (document.getElementById(context+'_recaptchapriv')) {
12145: privitem = document.getElementById(context+'_recaptchapriv');
12146: } else {
12147: return;
12148: }
12149: if (document.getElementById(context+'_recaptchapubtxt')) {
12150: pubtext = document.getElementById(context+'_recaptchapubtxt');
12151: } else {
12152: return;
12153: }
12154: if (document.getElementById(context+'_recaptchaprivtxt')) {
12155: privtext = document.getElementById(context+'_recaptchaprivtxt');
12156: } else {
12157: return;
12158: }
12159: if (caller.checked) {
12160: if (caller.value == 'recaptcha') {
12161: pubitem.type = 'text';
12162: privitem.type = 'text';
12163: pubitem.size = '40';
12164: privitem.size = '40';
12165: pubtext.innerHTML = "$lt{'pub'}";
12166: privtext.innerHTML = "$lt{'priv'}";
12167: } else {
12168: pubitem.type = 'hidden';
12169: privitem.type = 'hidden';
12170: pubtext.innerHTML = '';
12171: privtext.innerHTML = '';
12172: }
12173: }
12174: return;
12175: }
12176:
12177: // ]]>
12178: </script>
12179:
12180: END
12181:
12182: }
12183:
1.160.6.40 raeburn 12184: sub toggle_display_js {
1.160.6.16 raeburn 12185: return <<"END";
12186:
12187: <script type="text/javascript">
12188: // <![CDATA[
12189:
1.160.6.40 raeburn 12190: function toggleDisplay(domForm,caller) {
12191: if (document.getElementById(caller)) {
12192: var divitem = document.getElementById(caller);
12193: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 12194: var checkval = 1;
12195: var dispval = 'block';
1.160.6.40 raeburn 12196: if (caller == 'emailoptions') {
12197: optionsElement = domForm.cancreate_email;
12198: }
1.160.6.57 raeburn 12199: if (caller == 'studentsubmission') {
12200: optionsElement = domForm.postsubmit;
12201: }
1.160.6.64 raeburn 12202: if (caller == 'cloneinstcode') {
12203: optionsElement = domForm.canclone;
12204: checkval = 'instcode';
12205: }
1.160.6.40 raeburn 12206: if (optionsElement.length) {
1.160.6.16 raeburn 12207: var currval;
1.160.6.40 raeburn 12208: for (var i=0; i<optionsElement.length; i++) {
12209: if (optionsElement[i].checked) {
12210: currval = optionsElement[i].value;
1.160.6.16 raeburn 12211: }
12212: }
1.160.6.64 raeburn 12213: if (currval == checkval) {
12214: divitem.style.display = dispval;
1.160.6.16 raeburn 12215: } else {
1.160.6.40 raeburn 12216: divitem.style.display = 'none';
1.160.6.16 raeburn 12217: }
12218: }
12219: }
12220: return;
12221: }
12222:
12223: // ]]>
12224: </script>
12225:
12226: END
12227:
12228: }
12229:
1.160.6.5 raeburn 12230: sub captcha_phrases {
12231: return &Apache::lonlocal::texthash (
12232: priv => 'Private key',
12233: pub => 'Public key',
12234: original => 'original (CAPTCHA)',
12235: recaptcha => 'successor (ReCAPTCHA)',
12236: notused => 'unused',
12237: );
12238: }
12239:
1.160.6.24 raeburn 12240: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 12241: my ($dom,$cachekeys) = @_;
12242: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 12243: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12244: my %thismachine;
12245: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 12246: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 12247: if (keys(%servers)) {
1.160.6.24 raeburn 12248: foreach my $server (keys(%servers)) {
12249: next if ($thismachine{$server});
1.160.6.27 raeburn 12250: my @cached;
12251: foreach my $name (@posscached) {
12252: if ($cachekeys->{$name}) {
12253: push(@cached,&escape($name).':'.&escape($dom));
12254: }
12255: }
12256: if (@cached) {
12257: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12258: }
1.160.6.24 raeburn 12259: }
12260: }
12261: return;
12262: }
12263:
1.3 raeburn 12264: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>