Annotation of loncom/interface/domainprefs.pm, revision 1.232
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.232 ! raeburn 4: # $Id: domainprefs.pm,v 1.231 2014/03/29 20:35:21 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 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.232 ! raeburn 167: use Apache::lonuserutils();
1.69 raeburn 168: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 169: use LONCAPA::Enrollment;
1.81 raeburn 170: use LONCAPA::lonauthcgi();
1.9 raeburn 171: use File::Copy;
1.43 raeburn 172: use Locale::Language;
1.62 raeburn 173: use DateTime::TimeZone;
1.68 raeburn 174: use DateTime::Locale;
1.1 raeburn 175:
1.155 raeburn 176: my $registered_cleanup;
177: my $modified_urls;
178:
1.1 raeburn 179: sub handler {
180: my $r=shift;
181: if ($r->header_only) {
182: &Apache::loncommon::content_type($r,'text/html');
183: $r->send_http_header;
184: return OK;
185: }
186:
1.91 raeburn 187: my $context = 'domain';
1.1 raeburn 188: my $dom = $env{'request.role.domain'};
1.5 albertel 189: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 190: if (&Apache::lonnet::allowed('mau',$dom)) {
191: &Apache::loncommon::content_type($r,'text/html');
192: $r->send_http_header;
193: } else {
194: $env{'user.error.msg'}=
195: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
196: return HTTP_NOT_ACCEPTABLE;
197: }
1.155 raeburn 198:
199: $registered_cleanup=0;
200: @{$modified_urls}=();
201:
1.1 raeburn 202: &Apache::lonhtmlcommon::clear_breadcrumbs();
203: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 204: ['phase','actions']);
1.30 raeburn 205: my $phase = 'pickactions';
1.3 raeburn 206: if ( exists($env{'form.phase'}) ) {
207: $phase = $env{'form.phase'};
208: }
1.150 raeburn 209: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 210: my %domconfig =
1.6 raeburn 211: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 212: 'quotas','autoenroll','autoupdate','autocreate',
213: 'directorysrch','usercreation','usermodification',
214: 'contacts','defaults','scantron','coursecategories',
215: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 216: 'coursedefaults','usersessions','loadbalancing',
1.231 raeburn 217: 'requestauthor','selfenrollment'],$dom);
1.43 raeburn 218: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 219: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 220: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 221: 'requestcourses','requestauthor','coursecategories',
222: 'serverstatuses','helpsettings',
1.231 raeburn 223: 'coursedefaults','selfenrollment','usersessions');
1.171 raeburn 224: my %existing;
225: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
226: %existing = %{$domconfig{'loadbalancing'}};
227: }
228: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 229: push(@prefs_order,'loadbalancing');
230: }
1.30 raeburn 231: my %prefs = (
232: 'rolecolors' =>
233: { text => 'Default color schemes',
1.67 raeburn 234: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 235: header => [{col1 => 'Student Settings',
236: col2 => '',},
237: {col1 => 'Coordinator Settings',
238: col2 => '',},
239: {col1 => 'Author Settings',
240: col2 => '',},
241: {col1 => 'Administrator Settings',
242: col2 => '',}],
1.230 raeburn 243: print => \&print_rolecolors,
244: modify => \&modify_rolecolors,
1.30 raeburn 245: },
1.110 raeburn 246: 'login' =>
1.30 raeburn 247: { text => 'Log-in page options',
1.67 raeburn 248: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 249: header => [{col1 => 'Log-in Page Items',
250: col2 => '',},
251: {col1 => 'Log-in Help',
252: col2 => 'Value'}],
1.230 raeburn 253: print => \&print_login,
254: modify => \&modify_login,
1.30 raeburn 255: },
1.43 raeburn 256: 'defaults' =>
1.141 raeburn 257: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 258: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 259: header => [{col1 => 'Setting',
260: col2 => 'Value'}],
1.230 raeburn 261: print => \&print_defaults,
262: modify => \&modify_defaults,
1.43 raeburn 263: },
1.30 raeburn 264: 'quotas' =>
1.197 raeburn 265: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 266: help => 'Domain_Configuration_Quotas',
1.77 raeburn 267: header => [{col1 => 'User affiliation',
1.72 raeburn 268: col2 => 'Available tools',
1.213 raeburn 269: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 270: print => \&print_quotas,
271: modify => \&modify_quotas,
1.30 raeburn 272: },
273: 'autoenroll' =>
274: { text => 'Auto-enrollment settings',
1.67 raeburn 275: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 276: header => [{col1 => 'Configuration setting',
277: col2 => 'Value(s)'}],
1.230 raeburn 278: print => \&print_autoenroll,
279: modify => \&modify_autoenroll,
1.30 raeburn 280: },
281: 'autoupdate' =>
282: { text => 'Auto-update settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 284: header => [{col1 => 'Setting',
285: col2 => 'Value',},
1.131 raeburn 286: {col1 => 'Setting',
287: col2 => 'Affiliation'},
1.43 raeburn 288: {col1 => 'User population',
1.227 bisitz 289: col2 => 'Updatable user data'}],
1.230 raeburn 290: print => \&print_autoupdate,
291: modify => \&modify_autoupdate,
1.30 raeburn 292: },
1.125 raeburn 293: 'autocreate' =>
294: { text => 'Auto-course creation settings',
295: help => 'Domain_Configuration_Auto_Creation',
296: header => [{col1 => 'Configuration Setting',
297: col2 => 'Value',}],
1.230 raeburn 298: print => \&print_autocreate,
299: modify => \&modify_autocreate,
1.125 raeburn 300: },
1.30 raeburn 301: 'directorysrch' =>
302: { text => 'Institutional directory searches',
1.67 raeburn 303: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 304: header => [{col1 => 'Setting',
305: col2 => 'Value',}],
1.230 raeburn 306: print => \&print_directorysrch,
307: modify => \&modify_directorysrch,
1.30 raeburn 308: },
309: 'contacts' =>
310: { text => 'Contact Information',
1.67 raeburn 311: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 312: header => [{col1 => 'Setting',
313: col2 => 'Value',}],
1.230 raeburn 314: print => \&print_contacts,
315: modify => \&modify_contacts,
1.30 raeburn 316: },
317: 'usercreation' =>
318: { text => 'User creation',
1.67 raeburn 319: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 320: header => [{col1 => 'Format rule type',
321: col2 => 'Format rules in force'},
1.34 raeburn 322: {col1 => 'User account creation',
323: col2 => 'Usernames which may be created',},
1.30 raeburn 324: {col1 => 'Context',
1.43 raeburn 325: col2 => 'Assignable authentication types'}],
1.230 raeburn 326: print => \&print_usercreation,
327: modify => \&modify_usercreation,
1.30 raeburn 328: },
1.224 raeburn 329: 'selfcreation' =>
330: { text => 'Users self-creating accounts',
331: help => 'Domain_Configuration_Self_Creation',
332: header => [{col1 => 'Self-creation with institutional username',
333: col2 => 'Enabled?'},
334: {col1 => 'Institutional user type (login/SSO self-creation)',
335: col2 => 'Information user can enter'},
336: {col1 => 'Self-creation with e-mail as username',
337: col2 => 'Settings'}],
1.230 raeburn 338: print => \&print_selfcreation,
339: modify => \&modify_selfcreation,
1.224 raeburn 340: },
1.69 raeburn 341: 'usermodification' =>
1.33 raeburn 342: { text => 'User modification',
1.67 raeburn 343: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 344: header => [{col1 => 'Target user has role',
1.227 bisitz 345: col2 => 'User information updatable in author context'},
1.33 raeburn 346: {col1 => 'Target user has role',
1.227 bisitz 347: col2 => 'User information updatable in course context'}],
1.230 raeburn 348: print => \&print_usermodification,
349: modify => \&modify_usermodification,
1.33 raeburn 350: },
1.69 raeburn 351: 'scantron' =>
1.95 www 352: { text => 'Bubblesheet format file',
1.67 raeburn 353: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 354: header => [ {col1 => 'Item',
355: col2 => '',
356: }],
1.230 raeburn 357: print => \&print_scantron,
358: modify => \&modify_scantron,
1.46 raeburn 359: },
1.86 raeburn 360: 'requestcourses' =>
361: {text => 'Request creation of courses',
362: help => 'Domain_Configuration_Request_Courses',
363: header => [{col1 => 'User affiliation',
1.102 raeburn 364: col2 => 'Availability/Processing of requests',},
365: {col1 => 'Setting',
1.216 raeburn 366: col2 => 'Value'},
367: {col1 => 'Available textbooks',
368: col2 => ''}],
1.230 raeburn 369: print => \&print_quotas,
370: modify => \&modify_quotas,
1.86 raeburn 371: },
1.163 raeburn 372: 'requestauthor' =>
1.223 bisitz 373: {text => 'Request Authoring Space',
1.163 raeburn 374: help => 'Domain_Configuration_Request_Author',
375: header => [{col1 => 'User affiliation',
376: col2 => 'Availability/Processing of requests',},
377: {col1 => 'Setting',
378: col2 => 'Value'}],
1.230 raeburn 379: print => \&print_quotas,
380: modify => \&modify_quotas,
1.163 raeburn 381: },
1.69 raeburn 382: 'coursecategories' =>
1.120 raeburn 383: { text => 'Cataloging of courses/communities',
1.67 raeburn 384: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 385: header => [{col1 => 'Category settings',
1.57 raeburn 386: col2 => '',},
387: {col1 => 'Categories',
388: col2 => '',
389: }],
1.230 raeburn 390: print => \&print_coursecategories,
391: modify => \&modify_coursecategories,
1.69 raeburn 392: },
393: 'serverstatuses' =>
1.77 raeburn 394: {text => 'Access to server status pages',
1.69 raeburn 395: help => 'Domain_Configuration_Server_Status',
396: header => [{col1 => 'Status Page',
397: col2 => 'Other named users',
398: col3 => 'Specific IPs',
399: }],
1.230 raeburn 400: print => \&print_serverstatuses,
401: modify => \&modify_serverstatuses,
1.69 raeburn 402: },
1.118 jms 403: 'helpsettings' =>
404: {text => 'Help page settings',
405: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 406: header => [{col1 => 'Help Settings (logged-in users)',
407: col2 => 'Value'}],
1.230 raeburn 408: print => \&print_helpsettings,
409: modify => \&modify_helpsettings,
1.118 jms 410: },
1.121 raeburn 411: 'coursedefaults' =>
412: {text => 'Course/Community defaults',
413: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 414: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
415: col2 => 'Value',},
416: {col1 => 'Defaults which can be overridden for each course by a DC',
417: col2 => 'Value',},],
1.230 raeburn 418: print => \&print_coursedefaults,
419: modify => \&modify_coursedefaults,
1.121 raeburn 420: },
1.231 raeburn 421: 'selfenrollment' =>
422: {text => 'Self-enrollment in Course/Community',
423: help => 'Domain_Configuration_Selfenrollment',
424: header => [{col1 => 'Configuration Rights',
425: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
426: {col1 => 'Defaults',
427: col2 => 'Value'},
428: {col1 => 'Self-enrollment validation (optional)',
429: col2 => 'Value'},],
430: print => \&print_selfenrollment,
431: modify => \&modify_selfenrollment,
432: },
1.120 raeburn 433: 'privacy' =>
434: {text => 'User Privacy',
435: help => 'Domain_Configuration_User_Privacy',
436: header => [{col1 => 'Setting',
437: col2 => 'Value',}],
1.230 raeburn 438: print => \&print_privacy,
439: modify => \&modify_privacy,
1.120 raeburn 440: },
1.141 raeburn 441: 'usersessions' =>
1.145 raeburn 442: {text => 'User session hosting/offloading',
1.137 raeburn 443: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 444: header => [{col1 => 'Domain server',
445: col2 => 'Servers to offload sessions to when busy'},
446: {col1 => 'Hosting of users from other domains',
1.137 raeburn 447: col2 => 'Rules'},
448: {col1 => "Hosting domain's own users elsewhere",
449: col2 => 'Rules'}],
1.230 raeburn 450: print => \&print_usersessions,
451: modify => \&modify_usersessions,
1.137 raeburn 452: },
1.150 raeburn 453: 'loadbalancing' =>
1.185 raeburn 454: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 455: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 456: header => [{col1 => 'Balancers',
1.150 raeburn 457: col2 => 'Default destinations',
1.183 bisitz 458: col3 => 'User affiliation',
1.150 raeburn 459: col4 => 'Overrides'},
460: ],
1.230 raeburn 461: print => \&print_loadbalancing,
462: modify => \&modify_loadbalancing,
1.150 raeburn 463: },
1.3 raeburn 464: );
1.110 raeburn 465: if (keys(%servers) > 1) {
466: $prefs{'login'} = { text => 'Log-in page options',
467: help => 'Domain_Configuration_Login_Page',
468: header => [{col1 => 'Log-in Service',
469: col2 => 'Server Setting',},
470: {col1 => 'Log-in Page Items',
1.168 raeburn 471: col2 => ''},
472: {col1 => 'Log-in Help',
473: col2 => 'Value'}],
1.230 raeburn 474: print => \&print_login,
475: modify => \&modify_login,
1.110 raeburn 476: };
477: }
1.174 foxr 478:
1.6 raeburn 479: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 480: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 481: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 482: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 483: text=>"Settings to display/modify"});
1.9 raeburn 484: my $confname = $dom.'-domainconfig';
1.174 foxr 485:
1.3 raeburn 486: if ($phase eq 'process') {
1.212 raeburn 487: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
488: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 489: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 490: $r->rflush();
1.212 raeburn 491: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 492: }
1.30 raeburn 493: } elsif ($phase eq 'display') {
1.192 raeburn 494: my $js = &recaptcha_js().
495: &credits_js();
1.171 raeburn 496: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 497: my ($othertitle,$usertypes,$types) =
498: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 499: $js .= &lonbalance_targets_js($dom,$types,\%servers,
500: $domconfig{'loadbalancing'}).
1.170 raeburn 501: &new_spares_js().
502: &common_domprefs_js().
503: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 504: }
1.216 raeburn 505: if (grep(/^requestcourses$/,@actions)) {
506: my $javascript_validations;
507: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
508: $js .= <<END;
509: <script type="text/javascript">
510: $javascript_validations
511: </script>
512: $coursebrowserjs
513: END
514: }
1.150 raeburn 515: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 516: } else {
1.180 raeburn 517: # check if domconfig user exists for the domain.
518: my $servadm = $r->dir_config('lonAdmEMail');
519: my ($configuserok,$author_ok,$switchserver) =
520: &config_check($dom,$confname,$servadm);
521: unless ($configuserok eq 'ok') {
1.181 raeburn 522: &Apache::lonconfigsettings::print_header($r,$phase,$context);
523: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 524: $confname).
1.181 raeburn 525: '<br />'
526: );
1.180 raeburn 527: if ($switchserver) {
1.181 raeburn 528: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
529: '<br />'.
530: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
531: '<br />'.
532: &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).
533: '<br />'.
534: &mt('To do that now, use the following link: [_1]',$switchserver)
535: );
536: } else {
537: $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.').
538: '<br />'.
539: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
540: );
1.180 raeburn 541: }
542: $r->print(&Apache::loncommon::end_page());
543: return OK;
544: }
1.21 raeburn 545: if (keys(%domconfig) == 0) {
546: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 547: my @ids=&Apache::lonnet::current_machine_ids();
548: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 549: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 550: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 551: my $custom_img_count = 0;
552: foreach my $img (@loginimages) {
553: if ($designhash{$dom.'.login.'.$img} ne '') {
554: $custom_img_count ++;
555: }
556: }
557: foreach my $role (@roles) {
558: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
559: $custom_img_count ++;
560: }
561: }
562: if ($custom_img_count > 0) {
1.94 raeburn 563: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 564: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 565: $r->print(
566: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
567: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
568: &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 />'.
569: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
570: if ($switch_server) {
1.30 raeburn 571: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 572: }
1.91 raeburn 573: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 574: return OK;
575: }
576: }
577: }
1.91 raeburn 578: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 579: }
580: return OK;
581: }
582:
583: sub process_changes {
1.205 raeburn 584: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 585: my %domconfig;
586: if (ref($values) eq 'HASH') {
587: %domconfig = %{$values};
588: }
1.3 raeburn 589: my $output;
590: if ($action eq 'login') {
1.205 raeburn 591: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 592: } elsif ($action eq 'rolecolors') {
1.9 raeburn 593: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 594: $lastactref,%domconfig);
1.3 raeburn 595: } elsif ($action eq 'quotas') {
1.216 raeburn 596: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 597: } elsif ($action eq 'autoenroll') {
1.205 raeburn 598: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 599: } elsif ($action eq 'autoupdate') {
600: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 601: } elsif ($action eq 'autocreate') {
602: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 603: } elsif ($action eq 'directorysrch') {
604: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 605: } elsif ($action eq 'usercreation') {
1.28 raeburn 606: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 607: } elsif ($action eq 'selfcreation') {
608: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 609: } elsif ($action eq 'usermodification') {
610: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 611: } elsif ($action eq 'contacts') {
1.205 raeburn 612: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 613: } elsif ($action eq 'defaults') {
1.212 raeburn 614: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 615: } elsif ($action eq 'scantron') {
1.205 raeburn 616: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 617: } elsif ($action eq 'coursecategories') {
618: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 619: } elsif ($action eq 'serverstatuses') {
620: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 621: } elsif ($action eq 'requestcourses') {
1.216 raeburn 622: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 623: } elsif ($action eq 'requestauthor') {
1.216 raeburn 624: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 625: } elsif ($action eq 'helpsettings') {
1.122 jms 626: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 627: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 628: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 629: } elsif ($action eq 'selfenrollment') {
630: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 631: } elsif ($action eq 'usersessions') {
1.212 raeburn 632: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 633: } elsif ($action eq 'loadbalancing') {
634: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 635: }
636: return $output;
637: }
638:
639: sub print_config_box {
1.9 raeburn 640: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 641: my $rowtotal = 0;
1.49 raeburn 642: my $output;
643: if ($action eq 'coursecategories') {
644: $output = &coursecategories_javascript($settings);
1.91 raeburn 645: }
1.49 raeburn 646: $output .=
1.30 raeburn 647: '<table class="LC_nested_outer">
1.3 raeburn 648: <tr>
1.66 raeburn 649: <th align="left" valign="middle"><span class="LC_nobreak">'.
650: &mt($item->{text}).' '.
651: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
652: '</tr>';
1.30 raeburn 653: $rowtotal ++;
1.110 raeburn 654: my $numheaders = 1;
655: if (ref($item->{'header'}) eq 'ARRAY') {
656: $numheaders = scalar(@{$item->{'header'}});
657: }
658: if ($numheaders > 1) {
1.64 raeburn 659: my $colspan = '';
1.145 raeburn 660: my $rightcolspan = '';
1.210 raeburn 661: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 662: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 663: $colspan = ' colspan="2"';
664: }
1.145 raeburn 665: if ($action eq 'usersessions') {
666: $rightcolspan = ' colspan="3"';
667: }
1.30 raeburn 668: $output .= '
1.3 raeburn 669: <tr>
670: <td>
671: <table class="LC_nested">
672: <tr class="LC_info_row">
1.59 bisitz 673: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 674: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 675: </tr>';
1.69 raeburn 676: $rowtotal ++;
1.230 raeburn 677: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
678: ($action eq 'usermodification') || ($action eq 'coursedefaults') ||
679: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
680: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 681: } elsif ($action eq 'coursecategories') {
1.230 raeburn 682: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 683: } elsif ($action eq 'login') {
1.168 raeburn 684: if ($numheaders == 3) {
685: $colspan = ' colspan="2"';
686: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
687: } else {
688: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
689: }
1.230 raeburn 690: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 691: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 692: } elsif ($action eq 'rolecolors') {
1.30 raeburn 693: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 694: }
1.30 raeburn 695: $output .= '
1.6 raeburn 696: </table>
697: </td>
698: </tr>
699: <tr>
700: <td>
701: <table class="LC_nested">
702: <tr class="LC_info_row">
1.230 raeburn 703: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 704: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 705: </tr>';
706: $rowtotal ++;
1.230 raeburn 707: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
708: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
709: ($action eq 'usersessions')) {
710: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 711: </table>
712: </td>
713: </tr>
714: <tr>
715: <td>
716: <table class="LC_nested">
717: <tr class="LC_info_row">
718: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 719: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.230 raeburn 720: </tr>'."\n".
721: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 722: $rowtotal ++;
1.230 raeburn 723: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults')) {
724: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.57 raeburn 725: } elsif ($action eq 'coursecategories') {
726: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 727: } elsif ($action eq 'login') {
1.168 raeburn 728: if ($numheaders == 3) {
729: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
730: </table>
731: </td>
732: </tr>
733: <tr>
734: <td>
735: <table class="LC_nested">
736: <tr class="LC_info_row">
737: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 738: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 739: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
740: $rowtotal ++;
741: } else {
742: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
743: }
1.102 raeburn 744: } elsif ($action eq 'requestcourses') {
1.216 raeburn 745: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
746: &print_studentcode($settings,\$rowtotal).'
747: </table>
748: </td>
749: </tr>
750: <tr>
751: <td>
752: <table class="LC_nested">
753: <tr class="LC_info_row">
754: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
755: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
756: &print_textbookcourses($dom,$settings,\$rowtotal);
1.163 raeburn 757: } elsif ($action eq 'requestauthor') {
758: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 759: } elsif ($action eq 'rolecolors') {
1.30 raeburn 760: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 761: </table>
762: </td>
763: </tr>
764: <tr>
765: <td>
766: <table class="LC_nested">
767: <tr class="LC_info_row">
1.69 raeburn 768: <td class="LC_left_item"'.$colspan.' valign="top">'.
769: &mt($item->{'header'}->[2]->{'col1'}).'</td>
770: <td class="LC_right_item" valign="top">'.
771: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 772: </tr>'.
1.30 raeburn 773: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 774: </table>
775: </td>
776: </tr>
777: <tr>
778: <td>
779: <table class="LC_nested">
780: <tr class="LC_info_row">
1.59 bisitz 781: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
782: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 783: </tr>'.
1.30 raeburn 784: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
785: $rowtotal += 2;
1.6 raeburn 786: }
1.3 raeburn 787: } else {
1.30 raeburn 788: $output .= '
1.3 raeburn 789: <tr>
790: <td>
791: <table class="LC_nested">
1.30 raeburn 792: <tr class="LC_info_row">';
1.24 raeburn 793: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 794: $output .= '
1.59 bisitz 795: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 796: } elsif ($action eq 'serverstatuses') {
797: $output .= '
798: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
799: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
800:
1.6 raeburn 801: } else {
1.30 raeburn 802: $output .= '
1.69 raeburn 803: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
804: }
1.72 raeburn 805: if (defined($item->{'header'}->[0]->{'col3'})) {
806: $output .= '<td class="LC_left_item" valign="top">'.
807: &mt($item->{'header'}->[0]->{'col2'});
808: if ($action eq 'serverstatuses') {
809: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
810: }
1.69 raeburn 811: } else {
812: $output .= '<td class="LC_right_item" valign="top">'.
813: &mt($item->{'header'}->[0]->{'col2'});
814: }
815: $output .= '</td>';
816: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 817: if (defined($item->{'header'}->[0]->{'col4'})) {
818: $output .= '<td class="LC_left_item" valign="top">'.
819: &mt($item->{'header'}->[0]->{'col3'});
820: } else {
821: $output .= '<td class="LC_right_item" valign="top">'.
822: &mt($item->{'header'}->[0]->{'col3'});
823: }
1.69 raeburn 824: if ($action eq 'serverstatuses') {
825: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
826: }
827: $output .= '</td>';
1.6 raeburn 828: }
1.150 raeburn 829: if ($item->{'header'}->[0]->{'col4'}) {
830: $output .= '<td class="LC_right_item" valign="top">'.
831: &mt($item->{'header'}->[0]->{'col4'});
832: }
1.69 raeburn 833: $output .= '</tr>';
1.48 raeburn 834: $rowtotal ++;
1.168 raeburn 835: if ($action eq 'quotas') {
1.86 raeburn 836: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 837: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
838: ($action eq 'contacts') || ($action eq 'defaults') || ($action eq 'serverstatuses') ||
839: ($action eq 'loadbalancing')) {
840: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 841: } elsif ($action eq 'scantron') {
842: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 843: } elsif ($action eq 'helpsettings') {
1.168 raeburn 844: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 845: }
1.3 raeburn 846: }
1.30 raeburn 847: $output .= '
1.3 raeburn 848: </table>
849: </td>
850: </tr>
1.30 raeburn 851: </table><br />';
852: return ($output,$rowtotal);
1.1 raeburn 853: }
854:
1.3 raeburn 855: sub print_login {
1.168 raeburn 856: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 857: my ($css_class,$datatable);
1.6 raeburn 858: my %choices = &login_choices();
1.110 raeburn 859:
1.168 raeburn 860: if ($caller eq 'service') {
1.149 raeburn 861: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 862: my $choice = $choices{'disallowlogin'};
863: $css_class = ' class="LC_odd_row"';
1.128 raeburn 864: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 865: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 866: '<th>'.$choices{'server'}.'</th>'.
867: '<th>'.$choices{'serverpath'}.'</th>'.
868: '<th>'.$choices{'custompath'}.'</th>'.
869: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 870: my %disallowed;
871: if (ref($settings) eq 'HASH') {
872: if (ref($settings->{'loginvia'}) eq 'HASH') {
873: %disallowed = %{$settings->{'loginvia'}};
874: }
875: }
876: foreach my $lonhost (sort(keys(%servers))) {
877: my $direct = 'selected="selected"';
1.128 raeburn 878: if (ref($disallowed{$lonhost}) eq 'HASH') {
879: if ($disallowed{$lonhost}{'server'} ne '') {
880: $direct = '';
881: }
1.110 raeburn 882: }
1.115 raeburn 883: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 884: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 885: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
886: '</option>';
1.184 raeburn 887: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 888: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 889: my $selected = '';
1.128 raeburn 890: if (ref($disallowed{$lonhost}) eq 'HASH') {
891: if ($hostid eq $disallowed{$lonhost}{'server'}) {
892: $selected = 'selected="selected"';
893: }
1.110 raeburn 894: }
895: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
896: $servers{$hostid}.'</option>';
897: }
1.128 raeburn 898: $datatable .= '</select></td>'.
899: '<td><select name="'.$lonhost.'_serverpath">';
900: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
901: my $pathname = $path;
902: if ($path eq 'custom') {
903: $pathname = &mt('Custom Path').' ->';
904: }
905: my $selected = '';
906: if (ref($disallowed{$lonhost}) eq 'HASH') {
907: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
908: $selected = 'selected="selected"';
909: }
910: } elsif ($path eq '') {
911: $selected = 'selected="selected"';
912: }
913: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
914: }
915: $datatable .= '</select></td>';
916: my ($custom,$exempt);
917: if (ref($disallowed{$lonhost}) eq 'HASH') {
918: $custom = $disallowed{$lonhost}{'custompath'};
919: $exempt = $disallowed{$lonhost}{'exempt'};
920: }
921: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
922: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
923: '</tr>';
1.110 raeburn 924: }
925: $datatable .= '</table></td></tr>';
926: return $datatable;
1.168 raeburn 927: } elsif ($caller eq 'page') {
928: my %defaultchecked = (
929: 'coursecatalog' => 'on',
1.188 raeburn 930: 'helpdesk' => 'on',
1.168 raeburn 931: 'adminmail' => 'off',
932: 'newuser' => 'off',
933: );
1.188 raeburn 934: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 935: my (%checkedon,%checkedoff);
1.42 raeburn 936: foreach my $item (@toggles) {
1.168 raeburn 937: if ($defaultchecked{$item} eq 'on') {
938: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 939: $checkedoff{$item} = ' ';
1.168 raeburn 940: } elsif ($defaultchecked{$item} eq 'off') {
941: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 942: $checkedon{$item} = ' ';
943: }
1.1 raeburn 944: }
1.168 raeburn 945: my @images = ('img','logo','domlogo','login');
946: my @logintext = ('textcol','bgcol');
947: my @bgs = ('pgbg','mainbg','sidebg');
948: my @links = ('link','alink','vlink');
949: my %designhash = &Apache::loncommon::get_domainconf($dom);
950: my %defaultdesign = %Apache::loncommon::defaultdesign;
951: my (%is_custom,%designs);
952: my %defaults = (
953: font => $defaultdesign{'login.font'},
954: );
1.6 raeburn 955: foreach my $item (@images) {
1.168 raeburn 956: $defaults{$item} = $defaultdesign{'login.'.$item};
957: $defaults{'showlogo'}{$item} = 1;
958: }
959: foreach my $item (@bgs) {
960: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 961: }
1.41 raeburn 962: foreach my $item (@logintext) {
1.168 raeburn 963: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 964: }
1.168 raeburn 965: foreach my $item (@links) {
966: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 967: }
1.168 raeburn 968: if (ref($settings) eq 'HASH') {
969: foreach my $item (@toggles) {
970: if ($settings->{$item} eq '1') {
971: $checkedon{$item} = ' checked="checked" ';
972: $checkedoff{$item} = ' ';
973: } elsif ($settings->{$item} eq '0') {
974: $checkedoff{$item} = ' checked="checked" ';
975: $checkedon{$item} = ' ';
976: }
977: }
978: foreach my $item (@images) {
979: if (defined($settings->{$item})) {
980: $designs{$item} = $settings->{$item};
981: $is_custom{$item} = 1;
982: }
983: if (defined($settings->{'showlogo'}{$item})) {
984: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
985: }
986: }
987: foreach my $item (@logintext) {
988: if ($settings->{$item} ne '') {
989: $designs{'logintext'}{$item} = $settings->{$item};
990: $is_custom{$item} = 1;
991: }
992: }
993: if ($settings->{'font'} ne '') {
994: $designs{'font'} = $settings->{'font'};
995: $is_custom{'font'} = 1;
996: }
997: foreach my $item (@bgs) {
998: if ($settings->{$item} ne '') {
999: $designs{'bgs'}{$item} = $settings->{$item};
1000: $is_custom{$item} = 1;
1001: }
1002: }
1003: foreach my $item (@links) {
1004: if ($settings->{$item} ne '') {
1005: $designs{'links'}{$item} = $settings->{$item};
1006: $is_custom{$item} = 1;
1007: }
1008: }
1009: } else {
1010: if ($designhash{$dom.'.login.font'} ne '') {
1011: $designs{'font'} = $designhash{$dom.'.login.font'};
1012: $is_custom{'font'} = 1;
1013: }
1014: foreach my $item (@images) {
1015: if ($designhash{$dom.'.login.'.$item} ne '') {
1016: $designs{$item} = $designhash{$dom.'.login.'.$item};
1017: $is_custom{$item} = 1;
1018: }
1019: }
1020: foreach my $item (@bgs) {
1021: if ($designhash{$dom.'.login.'.$item} ne '') {
1022: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1023: $is_custom{$item} = 1;
1024: }
1.6 raeburn 1025: }
1.168 raeburn 1026: foreach my $item (@links) {
1027: if ($designhash{$dom.'.login.'.$item} ne '') {
1028: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1029: $is_custom{$item} = 1;
1030: }
1.6 raeburn 1031: }
1032: }
1.168 raeburn 1033: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1034: logo => 'Institution Logo',
1035: domlogo => 'Domain Logo',
1036: login => 'Login box');
1037: my $itemcount = 1;
1038: foreach my $item (@toggles) {
1039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1040: $datatable .=
1041: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1042: '</td><td>'.
1043: '<span class="LC_nobreak"><label><input type="radio" name="'.
1044: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1045: '</label> <label><input type="radio" name="'.$item.'"'.
1046: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1047: '</tr>';
1048: $itemcount ++;
1.6 raeburn 1049: }
1.168 raeburn 1050: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1051: $datatable .= '</tr></table></td></tr>';
1052: } elsif ($caller eq 'help') {
1053: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1054: my $switchserver = &check_switchserver($dom,$confname);
1055: my $itemcount = 1;
1056: $defaulturl = '/adm/loginproblems.html';
1057: $defaulttype = 'default';
1058: %lt = &Apache::lonlocal::texthash (
1059: del => 'Delete?',
1060: rep => 'Replace:',
1061: upl => 'Upload:',
1062: default => 'Default',
1063: custom => 'Custom',
1064: );
1065: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1066: my @currlangs;
1067: if (ref($settings) eq 'HASH') {
1068: if (ref($settings->{'helpurl'}) eq 'HASH') {
1069: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1070: next if ($settings->{'helpurl'}{$key} eq '');
1071: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1072: $type{$key} = 'custom';
1073: unless ($key eq 'nolang') {
1074: push(@currlangs,$key);
1075: }
1076: }
1077: } elsif ($settings->{'helpurl'} ne '') {
1078: $type{'nolang'} = 'custom';
1079: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1080: }
1081: }
1.168 raeburn 1082: foreach my $lang ('nolang',sort(@currlangs)) {
1083: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1084: $datatable .= '<tr'.$css_class.'>';
1085: if ($url{$lang} eq '') {
1086: $url{$lang} = $defaulturl;
1087: }
1088: if ($type{$lang} eq '') {
1089: $type{$lang} = $defaulttype;
1090: }
1091: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1092: if ($lang eq 'nolang') {
1093: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1094: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1095: } else {
1096: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1097: $langchoices{$lang},
1098: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1099: }
1100: $datatable .= '</span></td>'."\n".
1101: '<td class="LC_left_item">';
1102: if ($type{$lang} eq 'custom') {
1103: $datatable .= '<span class="LC_nobreak"><label>'.
1104: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1105: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1106: } else {
1107: $datatable .= $lt{'upl'};
1108: }
1109: $datatable .='<br />';
1110: if ($switchserver) {
1111: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1112: } else {
1113: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1114: }
1.168 raeburn 1115: $datatable .= '</td></tr>';
1116: $itemcount ++;
1.6 raeburn 1117: }
1.168 raeburn 1118: my @addlangs;
1119: foreach my $lang (sort(keys(%langchoices))) {
1120: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1121: push(@addlangs,$lang);
1122: }
1123: if (@addlangs > 0) {
1124: my %toadd;
1125: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1126: $toadd{''} = &mt('Select');
1127: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1128: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1129: &mt('Add log-in help page for a specific language:').' '.
1130: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1131: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1132: if ($switchserver) {
1133: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1134: } else {
1135: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1136: }
1.168 raeburn 1137: $datatable .= '</td></tr>';
1.169 raeburn 1138: $itemcount ++;
1.6 raeburn 1139: }
1.169 raeburn 1140: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1141: }
1.6 raeburn 1142: return $datatable;
1143: }
1144:
1145: sub login_choices {
1146: my %choices =
1147: &Apache::lonlocal::texthash (
1.116 bisitz 1148: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1149: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1150: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1151: disallowlogin => "Login page requests redirected",
1152: hostid => "Server",
1.128 raeburn 1153: server => "Redirect to:",
1154: serverpath => "Path",
1155: custompath => "Custom",
1156: exempt => "Exempt IP(s)",
1.110 raeburn 1157: directlogin => "No redirect",
1158: newuser => "Link to create a user account",
1159: img => "Header",
1160: logo => "Main Logo",
1161: domlogo => "Domain Logo",
1162: login => "Log-in Header",
1163: textcol => "Text color",
1164: bgcol => "Box color",
1165: bgs => "Background colors",
1166: links => "Link colors",
1167: font => "Font color",
1168: pgbg => "Header",
1169: mainbg => "Page",
1170: sidebg => "Login box",
1171: link => "Link",
1172: alink => "Active link",
1173: vlink => "Visited link",
1.6 raeburn 1174: );
1175: return %choices;
1176: }
1177:
1178: sub print_rolecolors {
1.30 raeburn 1179: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1180: my %choices = &color_font_choices();
1181: my @bgs = ('pgbg','tabbg','sidebg');
1182: my @links = ('link','alink','vlink');
1183: my @images = ('img');
1184: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1185: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1186: my %defaultdesign = %Apache::loncommon::defaultdesign;
1187: my (%is_custom,%designs);
1.200 raeburn 1188: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1189: if (ref($settings) eq 'HASH') {
1190: if (ref($settings->{$role}) eq 'HASH') {
1191: if ($settings->{$role}->{'img'} ne '') {
1192: $designs{'img'} = $settings->{$role}->{'img'};
1193: $is_custom{'img'} = 1;
1194: }
1195: if ($settings->{$role}->{'font'} ne '') {
1196: $designs{'font'} = $settings->{$role}->{'font'};
1197: $is_custom{'font'} = 1;
1198: }
1.97 tempelho 1199: if ($settings->{$role}->{'fontmenu'} ne '') {
1200: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1201: $is_custom{'fontmenu'} = 1;
1202: }
1.6 raeburn 1203: foreach my $item (@bgs) {
1204: if ($settings->{$role}->{$item} ne '') {
1205: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1206: $is_custom{$item} = 1;
1207: }
1208: }
1209: foreach my $item (@links) {
1210: if ($settings->{$role}->{$item} ne '') {
1211: $designs{'links'}{$item} = $settings->{$role}->{$item};
1212: $is_custom{$item} = 1;
1213: }
1214: }
1215: }
1216: } else {
1217: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1218: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1219: $is_custom{'img'} = 1;
1220: }
1.97 tempelho 1221: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1222: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1223: $is_custom{'fontmenu'} = 1;
1224: }
1.6 raeburn 1225: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1226: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1227: $is_custom{'font'} = 1;
1228: }
1229: foreach my $item (@bgs) {
1230: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1231: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1232: $is_custom{$item} = 1;
1233:
1234: }
1235: }
1236: foreach my $item (@links) {
1237: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1238: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1239: $is_custom{$item} = 1;
1240: }
1241: }
1242: }
1243: my $itemcount = 1;
1.30 raeburn 1244: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1245: $datatable .= '</tr></table></td></tr>';
1246: return $datatable;
1247: }
1248:
1.200 raeburn 1249: sub role_defaults {
1250: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1251: my %defaults;
1252: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1253: return %defaults;
1254: }
1255: my %defaultdesign = %Apache::loncommon::defaultdesign;
1256: if ($role eq 'login') {
1257: %defaults = (
1258: font => $defaultdesign{$role.'.font'},
1259: );
1260: if (ref($logintext) eq 'ARRAY') {
1261: foreach my $item (@{$logintext}) {
1262: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1263: }
1264: }
1265: foreach my $item (@{$images}) {
1266: $defaults{'showlogo'}{$item} = 1;
1267: }
1268: } else {
1269: %defaults = (
1270: img => $defaultdesign{$role.'.img'},
1271: font => $defaultdesign{$role.'.font'},
1272: fontmenu => $defaultdesign{$role.'.fontmenu'},
1273: );
1274: }
1275: foreach my $item (@{$bgs}) {
1276: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1277: }
1278: foreach my $item (@{$links}) {
1279: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1280: }
1281: foreach my $item (@{$images}) {
1282: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1283: }
1284: return %defaults;
1285: }
1286:
1.6 raeburn 1287: sub display_color_options {
1.9 raeburn 1288: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1289: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1290: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1291: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1292: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1293: '<td>'.$choices->{'font'}.'</td>';
1294: if (!$is_custom->{'font'}) {
1.30 raeburn 1295: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1296: } else {
1297: $datatable .= '<td> </td>';
1298: }
1.174 foxr 1299: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1300:
1.8 raeburn 1301: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1302: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1303: ' value="'.$current_color.'" /> '.
1.174 foxr 1304: ' </td></tr>';
1.107 raeburn 1305: unless ($role eq 'login') {
1306: $datatable .= '<tr'.$css_class.'>'.
1307: '<td>'.$choices->{'fontmenu'}.'</td>';
1308: if (!$is_custom->{'fontmenu'}) {
1309: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1310: } else {
1311: $datatable .= '<td> </td>';
1312: }
1.202 raeburn 1313: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1314: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1315: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1316: '<input class="colorchooser" type="text" size="10" name="'
1317: .$role.'_fontmenu"'.
1318: ' value="'.$current_color.'" /> '.
1319: ' </td></tr>';
1.97 tempelho 1320: }
1.9 raeburn 1321: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1322: foreach my $img (@{$images}) {
1.18 albertel 1323: $itemcount ++;
1.6 raeburn 1324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1325: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1326: '<td>'.$choices->{$img};
1.41 raeburn 1327: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1328: if ($role eq 'login') {
1329: if ($img eq 'login') {
1330: $login_hdr_pick =
1.135 bisitz 1331: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1332: $logincolors =
1333: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1334: $designs,$defaults);
1.70 raeburn 1335: } elsif ($img ne 'domlogo') {
1336: $datatable.= &logo_display_options($img,$defaults,$designs);
1337: }
1338: }
1339: $datatable .= '</td>';
1.6 raeburn 1340: if ($designs->{$img} ne '') {
1341: $imgfile = $designs->{$img};
1.18 albertel 1342: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1343: } else {
1344: $imgfile = $defaults->{$img};
1345: }
1346: if ($imgfile) {
1.9 raeburn 1347: my ($showfile,$fullsize);
1348: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1349: my $urldir = $1;
1350: my $filename = $2;
1351: my @info = &Apache::lonnet::stat_file($designs->{$img});
1352: if (@info) {
1353: my $thumbfile = 'tn-'.$filename;
1354: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1355: if (@thumb) {
1356: $showfile = $urldir.'/'.$thumbfile;
1357: } else {
1358: $showfile = $imgfile;
1359: }
1360: } else {
1361: $showfile = '';
1362: }
1363: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1364: $showfile = $imgfile;
1.6 raeburn 1365: my $imgdir = $1;
1366: my $filename = $2;
1.159 raeburn 1367: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1368: $showfile = "/$imgdir/tn-".$filename;
1369: } else {
1.159 raeburn 1370: my $input = $londocroot.$imgfile;
1371: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1372: if (!-e $output) {
1.9 raeburn 1373: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1374: my ($fullwidth,$fullheight) = &check_dimensions($input);
1375: if ($fullwidth ne '' && $fullheight ne '') {
1376: if ($fullwidth > $width && $fullheight > $height) {
1377: my $size = $width.'x'.$height;
1378: system("convert -sample $size $input $output");
1.159 raeburn 1379: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1380: }
1381: }
1.6 raeburn 1382: }
1383: }
1.16 raeburn 1384: }
1.6 raeburn 1385: if ($showfile) {
1.40 raeburn 1386: if ($showfile =~ m{^/(adm|res)/}) {
1387: if ($showfile =~ m{^/res/}) {
1388: my $local_showfile =
1389: &Apache::lonnet::filelocation('',$showfile);
1390: &Apache::lonnet::repcopy($local_showfile);
1391: }
1392: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1393: }
1394: if ($imgfile) {
1395: if ($imgfile =~ m{^/(adm|res)/}) {
1396: if ($imgfile =~ m{^/res/}) {
1397: my $local_imgfile =
1398: &Apache::lonnet::filelocation('',$imgfile);
1399: &Apache::lonnet::repcopy($local_imgfile);
1400: }
1401: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1402: } else {
1403: $fullsize = $imgfile;
1404: }
1405: }
1.41 raeburn 1406: $datatable .= '<td>';
1407: if ($img eq 'login') {
1.135 bisitz 1408: $datatable .= $login_hdr_pick;
1409: }
1.41 raeburn 1410: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1411: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1412: } else {
1.201 raeburn 1413: $datatable .= '<td> </td><td class="LC_left_item">'.
1414: &mt('Upload:').'<br />';
1.6 raeburn 1415: }
1416: } else {
1.201 raeburn 1417: $datatable .= '<td> </td><td class="LC_left_item">'.
1418: &mt('Upload:').'<br />';
1.6 raeburn 1419: }
1.9 raeburn 1420: if ($switchserver) {
1421: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1422: } else {
1.135 bisitz 1423: if ($img ne 'login') { # suppress file selection for Log-in header
1424: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1425: }
1.9 raeburn 1426: }
1427: $datatable .= '</td></tr>';
1.6 raeburn 1428: }
1429: $itemcount ++;
1430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1431: $datatable .= '<tr'.$css_class.'>'.
1432: '<td>'.$choices->{'bgs'}.'</td>';
1433: my $bgs_def;
1434: foreach my $item (@{$bgs}) {
1435: if (!$is_custom->{$item}) {
1.70 raeburn 1436: $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 1437: }
1438: }
1439: if ($bgs_def) {
1.8 raeburn 1440: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1441: } else {
1442: $datatable .= '<td> </td>';
1443: }
1444: $datatable .= '<td class="LC_right_item">'.
1445: '<table border="0"><tr>';
1.174 foxr 1446:
1.6 raeburn 1447: foreach my $item (@{$bgs}) {
1.201 raeburn 1448: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1449: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1450: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1451: $datatable .= ' ';
1.6 raeburn 1452: }
1.174 foxr 1453: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1454: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1455: }
1456: $datatable .= '</tr></table></td></tr>';
1457: $itemcount ++;
1458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1459: $datatable .= '<tr'.$css_class.'>'.
1460: '<td>'.$choices->{'links'}.'</td>';
1461: my $links_def;
1462: foreach my $item (@{$links}) {
1463: if (!$is_custom->{$item}) {
1.30 raeburn 1464: $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 1465: }
1466: }
1467: if ($links_def) {
1.8 raeburn 1468: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1469: } else {
1470: $datatable .= '<td> </td>';
1471: }
1472: $datatable .= '<td class="LC_right_item">'.
1473: '<table border="0"><tr>';
1474: foreach my $item (@{$links}) {
1.174 foxr 1475: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1476: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1477: if ($designs->{'links'}{$item}) {
1.174 foxr 1478: $datatable.=' ';
1.6 raeburn 1479: }
1.174 foxr 1480: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1481: '" /></td>';
1482: }
1.30 raeburn 1483: $$rowtotal += $itemcount;
1.3 raeburn 1484: return $datatable;
1485: }
1486:
1.70 raeburn 1487: sub logo_display_options {
1488: my ($img,$defaults,$designs) = @_;
1489: my $checkedon;
1490: if (ref($defaults) eq 'HASH') {
1491: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1492: if ($defaults->{'showlogo'}{$img}) {
1493: $checkedon = 'checked="checked" ';
1494: }
1495: }
1496: }
1497: if (ref($designs) eq 'HASH') {
1498: if (ref($designs->{'showlogo'}) eq 'HASH') {
1499: if (defined($designs->{'showlogo'}{$img})) {
1500: if ($designs->{'showlogo'}{$img} == 0) {
1501: $checkedon = '';
1502: } elsif ($designs->{'showlogo'}{$img} == 1) {
1503: $checkedon = 'checked="checked" ';
1504: }
1505: }
1506: }
1507: }
1508: return '<br /><label> <input type="checkbox" name="'.
1509: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1510: &mt('show').'</label>'."\n";
1511: }
1512:
1.41 raeburn 1513: sub login_header_options {
1.135 bisitz 1514: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1515: my $output = '';
1.41 raeburn 1516: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1517: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1518: if (!$is_custom->{'textcol'}) {
1519: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1520: ' ';
1521: }
1522: if (!$is_custom->{'bgcol'}) {
1523: $output .= $choices->{'bgcol'}.': '.
1524: '<span id="css_'.$role.'_font" style="background-color: '.
1525: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1526: }
1527: $output .= '<br />';
1528: }
1529: $output .='<br />';
1530: return $output;
1531: }
1532:
1533: sub login_text_colors {
1.201 raeburn 1534: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1535: my $color_menu = '<table border="0"><tr>';
1536: foreach my $item (@{$logintext}) {
1.201 raeburn 1537: $color_menu .= '<td align="center">'.$choices->{$item};
1538: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1539: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1540: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1541: }
1542: $color_menu .= '</tr></table><br />';
1543: return $color_menu;
1544: }
1545:
1546: sub image_changes {
1547: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1548: my $output;
1.135 bisitz 1549: if ($img eq 'login') {
1550: # suppress image for Log-in header
1551: } elsif (!$is_custom) {
1.70 raeburn 1552: if ($img ne 'domlogo') {
1.41 raeburn 1553: $output .= &mt('Default image:').'<br />';
1554: } else {
1555: $output .= &mt('Default in use:').'<br />';
1556: }
1557: }
1.135 bisitz 1558: if ($img eq 'login') { # suppress image for Log-in header
1559: $output .= '<td>'.$logincolors;
1.41 raeburn 1560: } else {
1.135 bisitz 1561: if ($img_import) {
1562: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1563: }
1564: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1565: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1566: if ($is_custom) {
1567: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1568: '<input type="checkbox" name="'.
1569: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1570: '</label> '.&mt('Replace:').'</span><br />';
1571: } else {
1.201 raeburn 1572: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1573: }
1.41 raeburn 1574: }
1575: return $output;
1576: }
1577:
1.3 raeburn 1578: sub print_quotas {
1.86 raeburn 1579: my ($dom,$settings,$rowtotal,$action) = @_;
1580: my $context;
1581: if ($action eq 'quotas') {
1582: $context = 'tools';
1583: } else {
1584: $context = $action;
1585: }
1.197 raeburn 1586: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1587: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1588: my $typecount = 0;
1.101 raeburn 1589: my ($css_class,%titles);
1.86 raeburn 1590: if ($context eq 'requestcourses') {
1.216 raeburn 1591: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1592: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1593: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1594: %titles = &courserequest_titles();
1.163 raeburn 1595: } elsif ($context eq 'requestauthor') {
1596: @usertools = ('author');
1597: @options = ('norequest','approval','automatic');
1.210 raeburn 1598: %titles = &authorrequest_titles();
1.86 raeburn 1599: } else {
1.162 raeburn 1600: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1601: %titles = &tool_titles();
1.86 raeburn 1602: }
1.26 raeburn 1603: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1604: foreach my $type (@{$types}) {
1.197 raeburn 1605: my ($currdefquota,$currauthorquota);
1.163 raeburn 1606: unless (($context eq 'requestcourses') ||
1607: ($context eq 'requestauthor')) {
1.86 raeburn 1608: if (ref($settings) eq 'HASH') {
1609: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1610: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1611: } else {
1612: $currdefquota = $settings->{$type};
1613: }
1.197 raeburn 1614: if (ref($settings->{authorquota}) eq 'HASH') {
1615: $currauthorquota = $settings->{authorquota}->{$type};
1616: }
1.78 raeburn 1617: }
1.72 raeburn 1618: }
1.3 raeburn 1619: if (defined($usertypes->{$type})) {
1620: $typecount ++;
1621: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1622: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1623: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1624: '<td class="LC_left_item">';
1.101 raeburn 1625: if ($context eq 'requestcourses') {
1626: $datatable .= '<table><tr>';
1627: }
1628: my %cell;
1.72 raeburn 1629: foreach my $item (@usertools) {
1.101 raeburn 1630: if ($context eq 'requestcourses') {
1631: my ($curroption,$currlimit);
1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{$item}) eq 'HASH') {
1634: $curroption = $settings->{$item}->{$type};
1635: if ($curroption =~ /^autolimit=(\d*)$/) {
1636: $currlimit = $1;
1637: }
1638: }
1639: }
1640: if (!$curroption) {
1641: $curroption = 'norequest';
1642: }
1643: $datatable .= '<th>'.$titles{$item}.'</th>';
1644: foreach my $option (@options) {
1645: my $val = $option;
1646: if ($option eq 'norequest') {
1647: $val = 0;
1648: }
1649: if ($option eq 'validate') {
1650: my $canvalidate = 0;
1651: if (ref($validations{$item}) eq 'HASH') {
1652: if ($validations{$item}{$type}) {
1653: $canvalidate = 1;
1654: }
1655: }
1656: next if (!$canvalidate);
1657: }
1658: my $checked = '';
1659: if ($option eq $curroption) {
1660: $checked = ' checked="checked"';
1661: } elsif ($option eq 'autolimit') {
1662: if ($curroption =~ /^autolimit/) {
1663: $checked = ' checked="checked"';
1664: }
1665: }
1666: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1667: '<input type="radio" name="crsreq_'.$item.
1668: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1669: $titles{$option}.'</label>';
1.101 raeburn 1670: if ($option eq 'autolimit') {
1.127 raeburn 1671: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1672: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1673: 'value="'.$currlimit.'" />';
1.101 raeburn 1674: }
1.127 raeburn 1675: $cell{$item} .= '</span> ';
1.103 raeburn 1676: if ($option eq 'autolimit') {
1.127 raeburn 1677: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1678: }
1.101 raeburn 1679: }
1.163 raeburn 1680: } elsif ($context eq 'requestauthor') {
1681: my $curroption;
1682: if (ref($settings) eq 'HASH') {
1683: $curroption = $settings->{$type};
1684: }
1685: if (!$curroption) {
1686: $curroption = 'norequest';
1687: }
1688: foreach my $option (@options) {
1689: my $val = $option;
1690: if ($option eq 'norequest') {
1691: $val = 0;
1692: }
1693: my $checked = '';
1694: if ($option eq $curroption) {
1695: $checked = ' checked="checked"';
1696: }
1697: $datatable .= '<span class="LC_nobreak"><label>'.
1698: '<input type="radio" name="authorreq_'.$type.
1699: '" value="'.$val.'"'.$checked.' />'.
1700: $titles{$option}.'</label></span> ';
1701: }
1.101 raeburn 1702: } else {
1703: my $checked = 'checked="checked" ';
1704: if (ref($settings) eq 'HASH') {
1705: if (ref($settings->{$item}) eq 'HASH') {
1706: if ($settings->{$item}->{$type} == 0) {
1707: $checked = '';
1708: } elsif ($settings->{$item}->{$type} == 1) {
1709: $checked = 'checked="checked" ';
1710: }
1.78 raeburn 1711: }
1.72 raeburn 1712: }
1.101 raeburn 1713: $datatable .= '<span class="LC_nobreak"><label>'.
1714: '<input type="checkbox" name="'.$context.'_'.$item.
1715: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1716: '</label></span> ';
1.72 raeburn 1717: }
1.101 raeburn 1718: }
1719: if ($context eq 'requestcourses') {
1720: $datatable .= '</tr><tr>';
1721: foreach my $item (@usertools) {
1.106 raeburn 1722: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1723: }
1724: $datatable .= '</tr></table>';
1.72 raeburn 1725: }
1.86 raeburn 1726: $datatable .= '</td>';
1.163 raeburn 1727: unless (($context eq 'requestcourses') ||
1728: ($context eq 'requestauthor')) {
1.86 raeburn 1729: $datatable .=
1.197 raeburn 1730: '<td class="LC_right_item">'.
1731: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1732: '<input type="text" name="quota_'.$type.
1.72 raeburn 1733: '" value="'.$currdefquota.
1.197 raeburn 1734: '" size="5" /></span>'.(' ' x 2).
1735: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1736: '<input type="text" name="authorquota_'.$type.
1737: '" value="'.$currauthorquota.
1738: '" size="5" /></span></td>';
1.86 raeburn 1739: }
1740: $datatable .= '</tr>';
1.3 raeburn 1741: }
1742: }
1743: }
1.163 raeburn 1744: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1745: $defaultquota = '20';
1.197 raeburn 1746: $authorquota = '500';
1.86 raeburn 1747: if (ref($settings) eq 'HASH') {
1748: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1749: $defaultquota = $settings->{'defaultquota'}->{'default'};
1750: } elsif (defined($settings->{'default'})) {
1751: $defaultquota = $settings->{'default'};
1752: }
1.197 raeburn 1753: if (ref($settings->{'authorquota'}) eq 'HASH') {
1754: $authorquota = $settings->{'authorquota'}->{'default'};
1755: }
1.3 raeburn 1756: }
1757: }
1758: $typecount ++;
1759: $css_class = $typecount%2?' class="LC_odd_row"':'';
1760: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1761: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1762: '<td class="LC_left_item">';
1.101 raeburn 1763: if ($context eq 'requestcourses') {
1764: $datatable .= '<table><tr>';
1765: }
1766: my %defcell;
1.72 raeburn 1767: foreach my $item (@usertools) {
1.101 raeburn 1768: if ($context eq 'requestcourses') {
1769: my ($curroption,$currlimit);
1770: if (ref($settings) eq 'HASH') {
1771: if (ref($settings->{$item}) eq 'HASH') {
1772: $curroption = $settings->{$item}->{'default'};
1773: if ($curroption =~ /^autolimit=(\d*)$/) {
1774: $currlimit = $1;
1775: }
1776: }
1777: }
1778: if (!$curroption) {
1779: $curroption = 'norequest';
1780: }
1781: $datatable .= '<th>'.$titles{$item}.'</th>';
1782: foreach my $option (@options) {
1783: my $val = $option;
1784: if ($option eq 'norequest') {
1785: $val = 0;
1786: }
1787: if ($option eq 'validate') {
1788: my $canvalidate = 0;
1789: if (ref($validations{$item}) eq 'HASH') {
1790: if ($validations{$item}{'default'}) {
1791: $canvalidate = 1;
1792: }
1793: }
1794: next if (!$canvalidate);
1795: }
1796: my $checked = '';
1797: if ($option eq $curroption) {
1798: $checked = ' checked="checked"';
1799: } elsif ($option eq 'autolimit') {
1800: if ($curroption =~ /^autolimit/) {
1801: $checked = ' checked="checked"';
1802: }
1803: }
1804: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1805: '<input type="radio" name="crsreq_'.$item.
1806: '_default" value="'.$val.'"'.$checked.' />'.
1807: $titles{$option}.'</label>';
1808: if ($option eq 'autolimit') {
1.127 raeburn 1809: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1810: $item.'_limit_default" size="1" '.
1811: 'value="'.$currlimit.'" />';
1812: }
1.127 raeburn 1813: $defcell{$item} .= '</span> ';
1.104 raeburn 1814: if ($option eq 'autolimit') {
1.127 raeburn 1815: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1816: }
1.101 raeburn 1817: }
1.163 raeburn 1818: } elsif ($context eq 'requestauthor') {
1819: my $curroption;
1820: if (ref($settings) eq 'HASH') {
1.172 raeburn 1821: $curroption = $settings->{'default'};
1.163 raeburn 1822: }
1823: if (!$curroption) {
1824: $curroption = 'norequest';
1825: }
1826: foreach my $option (@options) {
1827: my $val = $option;
1828: if ($option eq 'norequest') {
1829: $val = 0;
1830: }
1831: my $checked = '';
1832: if ($option eq $curroption) {
1833: $checked = ' checked="checked"';
1834: }
1835: $datatable .= '<span class="LC_nobreak"><label>'.
1836: '<input type="radio" name="authorreq_default"'.
1837: ' value="'.$val.'"'.$checked.' />'.
1838: $titles{$option}.'</label></span> ';
1839: }
1.101 raeburn 1840: } else {
1841: my $checked = 'checked="checked" ';
1842: if (ref($settings) eq 'HASH') {
1843: if (ref($settings->{$item}) eq 'HASH') {
1844: if ($settings->{$item}->{'default'} == 0) {
1845: $checked = '';
1846: } elsif ($settings->{$item}->{'default'} == 1) {
1847: $checked = 'checked="checked" ';
1848: }
1.78 raeburn 1849: }
1.72 raeburn 1850: }
1.101 raeburn 1851: $datatable .= '<span class="LC_nobreak"><label>'.
1852: '<input type="checkbox" name="'.$context.'_'.$item.
1853: '" value="default" '.$checked.'/>'.$titles{$item}.
1854: '</label></span> ';
1855: }
1856: }
1857: if ($context eq 'requestcourses') {
1858: $datatable .= '</tr><tr>';
1859: foreach my $item (@usertools) {
1.106 raeburn 1860: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1861: }
1.101 raeburn 1862: $datatable .= '</tr></table>';
1.72 raeburn 1863: }
1.86 raeburn 1864: $datatable .= '</td>';
1.163 raeburn 1865: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1866: $datatable .= '<td class="LC_right_item">'.
1867: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1868: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1869: $defaultquota.'" size="5" /></span>'.(' ' x2).
1870: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1871: '<input type="text" name="authorquota" value="'.
1872: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1873: }
1874: $datatable .= '</tr>';
1.72 raeburn 1875: $typecount ++;
1876: $css_class = $typecount%2?' class="LC_odd_row"':'';
1877: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1878: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1879: if ($context eq 'requestcourses') {
1.109 raeburn 1880: $datatable .= &mt('(overrides affiliation, if set)').
1881: '</td>'.
1882: '<td class="LC_left_item">'.
1883: '<table><tr>';
1.101 raeburn 1884: } else {
1.109 raeburn 1885: $datatable .= &mt('(overrides affiliation, if checked)').
1886: '</td>'.
1887: '<td class="LC_left_item" colspan="2">'.
1888: '<br />';
1.101 raeburn 1889: }
1890: my %advcell;
1.72 raeburn 1891: foreach my $item (@usertools) {
1.101 raeburn 1892: if ($context eq 'requestcourses') {
1893: my ($curroption,$currlimit);
1894: if (ref($settings) eq 'HASH') {
1895: if (ref($settings->{$item}) eq 'HASH') {
1896: $curroption = $settings->{$item}->{'_LC_adv'};
1897: if ($curroption =~ /^autolimit=(\d*)$/) {
1898: $currlimit = $1;
1899: }
1900: }
1901: }
1902: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1903: my $checked = '';
1904: if ($curroption eq '') {
1905: $checked = ' checked="checked"';
1906: }
1907: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1908: '<input type="radio" name="crsreq_'.$item.
1909: '__LC_adv" value=""'.$checked.' />'.
1910: &mt('No override set').'</label></span> ';
1.101 raeburn 1911: foreach my $option (@options) {
1912: my $val = $option;
1913: if ($option eq 'norequest') {
1914: $val = 0;
1915: }
1916: if ($option eq 'validate') {
1917: my $canvalidate = 0;
1918: if (ref($validations{$item}) eq 'HASH') {
1919: if ($validations{$item}{'_LC_adv'}) {
1920: $canvalidate = 1;
1921: }
1922: }
1923: next if (!$canvalidate);
1924: }
1925: my $checked = '';
1.104 raeburn 1926: if ($val eq $curroption) {
1.101 raeburn 1927: $checked = ' checked="checked"';
1928: } elsif ($option eq 'autolimit') {
1929: if ($curroption =~ /^autolimit/) {
1930: $checked = ' checked="checked"';
1931: }
1932: }
1933: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1934: '<input type="radio" name="crsreq_'.$item.
1935: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1936: $titles{$option}.'</label>';
1937: if ($option eq 'autolimit') {
1.127 raeburn 1938: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1939: $item.'_limit__LC_adv" size="1" '.
1940: 'value="'.$currlimit.'" />';
1941: }
1.127 raeburn 1942: $advcell{$item} .= '</span> ';
1.104 raeburn 1943: if ($option eq 'autolimit') {
1.127 raeburn 1944: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1945: }
1.101 raeburn 1946: }
1.163 raeburn 1947: } elsif ($context eq 'requestauthor') {
1948: my $curroption;
1949: if (ref($settings) eq 'HASH') {
1950: $curroption = $settings->{'_LC_adv'};
1951: }
1952: my $checked = '';
1953: if ($curroption eq '') {
1954: $checked = ' checked="checked"';
1955: }
1956: $datatable .= '<span class="LC_nobreak"><label>'.
1957: '<input type="radio" name="authorreq__LC_adv"'.
1958: ' value=""'.$checked.' />'.
1959: &mt('No override set').'</label></span> ';
1960: foreach my $option (@options) {
1961: my $val = $option;
1962: if ($option eq 'norequest') {
1963: $val = 0;
1964: }
1965: my $checked = '';
1966: if ($val eq $curroption) {
1967: $checked = ' checked="checked"';
1968: }
1969: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1970: '<input type="radio" name="authorreq__LC_adv"'.
1971: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1972: $titles{$option}.'</label></span> ';
1973: }
1.101 raeburn 1974: } else {
1975: my $checked = 'checked="checked" ';
1976: if (ref($settings) eq 'HASH') {
1977: if (ref($settings->{$item}) eq 'HASH') {
1978: if ($settings->{$item}->{'_LC_adv'} == 0) {
1979: $checked = '';
1980: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1981: $checked = 'checked="checked" ';
1982: }
1.79 raeburn 1983: }
1.72 raeburn 1984: }
1.101 raeburn 1985: $datatable .= '<span class="LC_nobreak"><label>'.
1986: '<input type="checkbox" name="'.$context.'_'.$item.
1987: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1988: '</label></span> ';
1989: }
1990: }
1991: if ($context eq 'requestcourses') {
1992: $datatable .= '</tr><tr>';
1993: foreach my $item (@usertools) {
1.106 raeburn 1994: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1995: }
1.101 raeburn 1996: $datatable .= '</tr></table>';
1.72 raeburn 1997: }
1.98 raeburn 1998: $datatable .= '</td></tr>';
1.30 raeburn 1999: $$rowtotal += $typecount;
1.3 raeburn 2000: return $datatable;
2001: }
2002:
1.163 raeburn 2003: sub print_requestmail {
2004: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2005: my ($now,$datatable,%currapp);
1.102 raeburn 2006: $now = time;
2007: if (ref($settings) eq 'HASH') {
2008: if (ref($settings->{'notify'}) eq 'HASH') {
2009: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2010: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2011: }
2012: }
2013: }
1.191 raeburn 2014: my $numinrow = 2;
1.224 raeburn 2015: my $css_class;
2016: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2017: my $text;
2018: if ($action eq 'requestcourses') {
2019: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2020: } elsif ($action eq 'requestauthor') {
2021: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2022: } else {
1.224 raeburn 2023: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2024: }
1.224 raeburn 2025: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2026: ' <td>'.$text.'</td>'.
1.102 raeburn 2027: ' <td class="LC_left_item">';
1.191 raeburn 2028: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2029: $action.'notifyapproval',%currapp);
1.191 raeburn 2030: if ($numdc > 0) {
2031: $datatable .= $table;
1.102 raeburn 2032: } else {
2033: $datatable .= &mt('There are no active Domain Coordinators');
2034: }
2035: $datatable .='</td></tr>';
2036: $$rowtotal += $rows;
2037: return $datatable;
2038: }
2039:
1.216 raeburn 2040: sub print_studentcode {
2041: my ($settings,$rowtotal) = @_;
2042: my $rownum = 0;
1.218 raeburn 2043: my ($output,%current);
2044: my @crstypes = ('official','unofficial','community','textbook');
2045: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2046: foreach my $type (@crstypes) {
2047: $current{$type} = $settings->{'uniquecode'}{$type};
2048: }
2049: }
2050: $output .= '<tr>'.
2051: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2052: '<td class="LC_left_item">';
2053: foreach my $type (@crstypes) {
2054: my $check = ' ';
2055: if ($current{$type}) {
2056: $check = ' checked="checked" ';
2057: }
2058: $output .= '<span class="LC_nobreak"><label>'.
2059: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2060: &mt($type).'</label></span>'.(' 'x2).' ';
2061: }
2062: $output .= '</td></tr>';
2063: $$rowtotal ++;
2064: return $output;
1.216 raeburn 2065: }
2066:
2067: sub print_textbookcourses {
2068: my ($dom,$settings,$rowtotal) = @_;
2069: my $rownum = 0;
2070: my $css_class;
2071: my $itemcount = 1;
2072: my $maxnum = 0;
2073: my $bookshash;
2074: if (ref($settings) eq 'HASH') {
2075: $bookshash = $settings->{'textbooks'};
2076: }
2077: my %ordered;
2078: if (ref($bookshash) eq 'HASH') {
2079: foreach my $item (keys(%{$bookshash})) {
2080: if (ref($bookshash->{$item}) eq 'HASH') {
2081: my $num = $bookshash->{$item}{'order'};
2082: $ordered{$num} = $item;
2083: }
2084: }
2085: }
2086: my $confname = $dom.'-domainconfig';
2087: my $switchserver = &check_switchserver($dom,$confname);
2088: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2089: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2090: if (keys(%ordered)) {
2091: my @items = sort { $a <=> $b } keys(%ordered);
2092: for (my $i=0; $i<@items; $i++) {
2093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2094: my $key = $ordered{$items[$i]};
2095: my %coursehash=&Apache::lonnet::coursedescription($key);
2096: my $coursetitle = $coursehash{'description'};
2097: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2098: if (ref($bookshash->{$key}) eq 'HASH') {
2099: $subject = $bookshash->{$key}->{'subject'};
2100: $title = $bookshash->{$key}->{'title'};
2101: $author = $bookshash->{$key}->{'author'};
2102: $image = $bookshash->{$key}->{'image'};
2103: if ($image ne '') {
2104: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2105: my $imagethumb = "$path/tn-".$imagefile;
2106: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2107: }
2108: }
1.217 raeburn 2109: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2110: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2111: .'<select name="'.$key.'"'.$chgstr.'>';
2112: for (my $k=0; $k<=$maxnum; $k++) {
2113: my $vpos = $k+1;
2114: my $selstr;
2115: if ($k == $i) {
2116: $selstr = ' selected="selected" ';
2117: }
2118: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2119: }
2120: $datatable .= '</select>'.(' 'x2).
2121: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2122: &mt('Delete?').'</label></span></td>'.
2123: '<td colspan="2">'.
2124: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2125: (' 'x2).
2126: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2127: (' 'x2).
2128: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2129: (' 'x2).
2130: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2131: if ($image) {
2132: $datatable .= '<span class="LC_nobreak">'.
2133: $imgsrc.
2134: '<label><input type="checkbox" name="book_image_del"'.
2135: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2136: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2137: }
2138: if ($switchserver) {
2139: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2140: } else {
2141: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2142: }
2143: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2144: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2145: $coursetitle.'</span></td></tr>'."\n";
2146: $itemcount ++;
2147: }
2148: }
2149: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2150: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2151: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2152: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2153: '<select name="addbook_pos"'.$chgstr.'>';
2154: for (my $k=0; $k<$maxnum+1; $k++) {
2155: my $vpos = $k+1;
2156: my $selstr;
2157: if ($k == $maxnum) {
2158: $selstr = ' selected="selected" ';
2159: }
2160: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2161: }
2162: $datatable .= '</select> '."\n".
2163: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2164: '<td colspan="2">'.
2165: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2166: (' 'x2).
2167: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2168: (' 'x2).
2169: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2170: (' 'x2).
2171: '<span class="LC_nobreak">'.&mt('Image:').' ';
2172: if ($switchserver) {
2173: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2174: } else {
2175: $datatable .= '<input type="file" name="addbook_image" value="" />';
2176: }
2177: $datatable .= '</span>'."\n".
2178: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2179: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2180: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2181: &Apache::loncommon::selectcourse_link
2182: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2183: '</span></td>'."\n".
2184: '</tr>'."\n";
2185: $itemcount ++;
2186: return $datatable;
2187: }
2188:
1.217 raeburn 2189: sub textbookcourses_javascript {
2190: my ($textbooks) = @_;
2191: return unless(ref($textbooks) eq 'HASH');
2192: my $num = scalar(keys(%{$textbooks}));
2193: my @jsarray;
2194: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2195: push(@jsarray,$textbooks->{$item});
2196: }
2197: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2198: return <<"ENDSCRIPT";
2199: <script type="text/javascript">
2200: // <![CDATA[
2201: function reorderBooks(form,item) {
2202: var changedVal;
2203: $jstext
2204: var newpos = 'addbook_pos';
2205: var current = new Array;
2206: var maxh = 1 + $num;
2207: var current = new Array;
2208: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2209: if (item == newpos) {
2210: changedVal = newitemVal;
2211: } else {
2212: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2213: current[newitemVal] = newpos;
2214: }
2215: for (var i=0; i<textbooks.length; i++) {
2216: var elementName = textbooks[i];
2217: if (elementName != item) {
2218: if (form.elements[elementName]) {
2219: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2220: current[currVal] = elementName;
2221: }
2222: }
2223: }
2224: var oldVal;
2225: for (var j=0; j<maxh; j++) {
2226: if (current[j] == undefined) {
2227: oldVal = j;
2228: }
2229: }
2230: if (oldVal < changedVal) {
2231: for (var k=oldVal+1; k<=changedVal ; k++) {
2232: var elementName = current[k];
2233: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2234: }
2235: } else {
2236: for (var k=changedVal; k<oldVal; k++) {
2237: var elementName = current[k];
2238: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2239: }
2240: }
2241: return;
2242: }
2243:
2244: // ]]>
2245: </script>
2246:
2247: ENDSCRIPT
2248: }
2249:
1.3 raeburn 2250: sub print_autoenroll {
1.30 raeburn 2251: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2252: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2253: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2254: if (ref($settings) eq 'HASH') {
2255: if (exists($settings->{'run'})) {
2256: if ($settings->{'run'} eq '0') {
2257: $runoff = ' checked="checked" ';
2258: $runon = ' ';
2259: } else {
2260: $runon = ' checked="checked" ';
2261: $runoff = ' ';
2262: }
2263: } else {
2264: if ($autorun) {
2265: $runon = ' checked="checked" ';
2266: $runoff = ' ';
2267: } else {
2268: $runoff = ' checked="checked" ';
2269: $runon = ' ';
2270: }
2271: }
1.129 raeburn 2272: if (exists($settings->{'co-owners'})) {
2273: if ($settings->{'co-owners'} eq '0') {
2274: $coownersoff = ' checked="checked" ';
2275: $coownerson = ' ';
2276: } else {
2277: $coownerson = ' checked="checked" ';
2278: $coownersoff = ' ';
2279: }
2280: } else {
2281: $coownersoff = ' checked="checked" ';
2282: $coownerson = ' ';
2283: }
1.3 raeburn 2284: if (exists($settings->{'sender_domain'})) {
2285: $defdom = $settings->{'sender_domain'};
2286: }
1.14 raeburn 2287: } else {
2288: if ($autorun) {
2289: $runon = ' checked="checked" ';
2290: $runoff = ' ';
2291: } else {
2292: $runoff = ' checked="checked" ';
2293: $runon = ' ';
2294: }
1.3 raeburn 2295: }
2296: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2297: my $notif_sender;
2298: if (ref($settings) eq 'HASH') {
2299: $notif_sender = $settings->{'sender_uname'};
2300: }
1.3 raeburn 2301: my $datatable='<tr class="LC_odd_row">'.
2302: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2303: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2304: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2305: $runon.' value="1" />'.&mt('Yes').'</label> '.
2306: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2307: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2308: '</tr><tr>'.
2309: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2310: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2311: &mt('username').': '.
2312: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2313: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2314: ': '.$domform.'</span></td></tr>'.
2315: '<tr class="LC_odd_row">'.
2316: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2317: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2318: '<input type="radio" name="autoassign_coowners"'.
2319: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2320: '<label><input type="radio" name="autoassign_coowners"'.
2321: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2322: '</tr>';
2323: $$rowtotal += 3;
1.3 raeburn 2324: return $datatable;
2325: }
2326:
2327: sub print_autoupdate {
1.30 raeburn 2328: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2329: my $datatable;
2330: if ($position eq 'top') {
2331: my $updateon = ' ';
2332: my $updateoff = ' checked="checked" ';
2333: my $classlistson = ' ';
2334: my $classlistsoff = ' checked="checked" ';
2335: if (ref($settings) eq 'HASH') {
2336: if ($settings->{'run'} eq '1') {
2337: $updateon = $updateoff;
2338: $updateoff = ' ';
2339: }
2340: if ($settings->{'classlists'} eq '1') {
2341: $classlistson = $classlistsoff;
2342: $classlistsoff = ' ';
2343: }
2344: }
2345: my %title = (
2346: run => 'Auto-update active?',
2347: classlists => 'Update information in classlists?',
2348: );
2349: $datatable = '<tr class="LC_odd_row">'.
2350: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2351: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2352: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2353: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2354: '<label><input type="radio" name="autoupdate_run"'.
2355: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2356: '</tr><tr>'.
2357: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2358: '<td class="LC_right_item"><span class="LC_nobreak">'.
2359: '<label><input type="radio" name="classlists"'.
2360: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2361: '<label><input type="radio" name="classlists"'.
2362: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2363: '</tr>';
1.30 raeburn 2364: $$rowtotal += 2;
1.131 raeburn 2365: } elsif ($position eq 'middle') {
2366: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2367: my $numinrow = 3;
2368: my $locknamesettings;
2369: $datatable .= &insttypes_row($settings,$types,$usertypes,
2370: $dom,$numinrow,$othertitle,
2371: 'lockablenames');
2372: $$rowtotal ++;
1.3 raeburn 2373: } else {
1.44 raeburn 2374: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2375: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2376: 'permanentemail','id');
1.33 raeburn 2377: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2378: my $numrows = 0;
1.26 raeburn 2379: if (ref($types) eq 'ARRAY') {
2380: if (@{$types} > 0) {
2381: $datatable =
2382: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2383: \@fields,$types,\$numrows);
1.30 raeburn 2384: $$rowtotal += @{$types};
1.26 raeburn 2385: }
1.3 raeburn 2386: }
2387: $datatable .=
2388: &usertype_update_row($settings,{'default' => $othertitle},
2389: \%fieldtitles,\@fields,['default'],
2390: \$numrows);
1.30 raeburn 2391: $$rowtotal ++;
1.3 raeburn 2392: }
2393: return $datatable;
2394: }
2395:
1.125 raeburn 2396: sub print_autocreate {
2397: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2398: my (%createon,%createoff,%currhash);
1.125 raeburn 2399: my @types = ('xml','req');
2400: if (ref($settings) eq 'HASH') {
2401: foreach my $item (@types) {
2402: $createoff{$item} = ' checked="checked" ';
2403: $createon{$item} = ' ';
2404: if (exists($settings->{$item})) {
2405: if ($settings->{$item}) {
2406: $createon{$item} = ' checked="checked" ';
2407: $createoff{$item} = ' ';
2408: }
2409: }
2410: }
1.210 raeburn 2411: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2412: $currhash{$settings->{'xmldc'}} = 1;
2413: }
1.125 raeburn 2414: } else {
2415: foreach my $item (@types) {
2416: $createoff{$item} = ' checked="checked" ';
2417: $createon{$item} = ' ';
2418: }
2419: }
2420: $$rowtotal += 2;
1.191 raeburn 2421: my $numinrow = 2;
1.125 raeburn 2422: my $datatable='<tr class="LC_odd_row">'.
2423: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2424: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2425: '<input type="radio" name="autocreate_xml"'.
2426: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2427: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2428: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2429: '</td></tr><tr>'.
2430: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2431: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2432: '<input type="radio" name="autocreate_req"'.
2433: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2434: '<label><input type="radio" name="autocreate_req"'.
2435: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2436: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2437: 'autocreate_xmldc',%currhash);
1.125 raeburn 2438: if ($numdc > 1) {
1.143 raeburn 2439: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2440: &mt('Course creation processed as: (choose Dom. Coord.)').
2441: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2442: } else {
1.143 raeburn 2443: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2444: }
1.191 raeburn 2445: $$rowtotal += $rows;
1.125 raeburn 2446: return $datatable;
2447: }
2448:
1.23 raeburn 2449: sub print_directorysrch {
1.30 raeburn 2450: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2451: my $srchon = ' ';
2452: my $srchoff = ' checked="checked" ';
1.25 raeburn 2453: my ($exacton,$containson,$beginson);
1.24 raeburn 2454: my $localon = ' ';
2455: my $localoff = ' checked="checked" ';
1.23 raeburn 2456: if (ref($settings) eq 'HASH') {
2457: if ($settings->{'available'} eq '1') {
2458: $srchon = $srchoff;
2459: $srchoff = ' ';
2460: }
1.24 raeburn 2461: if ($settings->{'localonly'} eq '1') {
2462: $localon = $localoff;
2463: $localoff = ' ';
2464: }
1.25 raeburn 2465: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2466: foreach my $type (@{$settings->{'searchtypes'}}) {
2467: if ($type eq 'exact') {
2468: $exacton = ' checked="checked" ';
2469: } elsif ($type eq 'contains') {
2470: $containson = ' checked="checked" ';
2471: } elsif ($type eq 'begins') {
2472: $beginson = ' checked="checked" ';
2473: }
2474: }
2475: } else {
2476: if ($settings->{'searchtypes'} eq 'exact') {
2477: $exacton = ' checked="checked" ';
2478: } elsif ($settings->{'searchtypes'} eq 'contains') {
2479: $containson = ' checked="checked" ';
2480: } elsif ($settings->{'searchtypes'} eq 'specify') {
2481: $exacton = ' checked="checked" ';
2482: $containson = ' checked="checked" ';
2483: }
1.23 raeburn 2484: }
2485: }
2486: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2487: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2488:
2489: my $numinrow = 4;
1.26 raeburn 2490: my $cansrchrow = 0;
1.23 raeburn 2491: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2492: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2493: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2494: '<input type="radio" name="dirsrch_available"'.
2495: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2496: '<label><input type="radio" name="dirsrch_available"'.
2497: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2498: '</tr><tr>'.
1.30 raeburn 2499: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2500: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2501: '<input type="radio" name="dirsrch_localonly"'.
2502: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2503: '<label><input type="radio" name="dirsrch_localonly"'.
2504: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2505: '</tr>';
1.30 raeburn 2506: $$rowtotal += 2;
1.26 raeburn 2507: if (ref($usertypes) eq 'HASH') {
2508: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2509: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2510: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2511: $cansrchrow = 1;
2512: }
2513: }
2514: if ($cansrchrow) {
1.30 raeburn 2515: $$rowtotal ++;
1.26 raeburn 2516: $datatable .= '<tr>';
2517: } else {
2518: $datatable .= '<tr class="LC_odd_row">';
2519: }
1.30 raeburn 2520: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2521: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2522: foreach my $title (@{$titleorder}) {
2523: if (defined($searchtitles->{$title})) {
2524: my $check = ' ';
1.93 raeburn 2525: if (ref($settings) eq 'HASH') {
1.39 raeburn 2526: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2527: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2528: $check = ' checked="checked" ';
2529: }
1.25 raeburn 2530: }
2531: }
2532: $datatable .= '<td class="LC_left_item">'.
2533: '<span class="LC_nobreak"><label>'.
2534: '<input type="checkbox" name="searchby" '.
2535: 'value="'.$title.'"'.$check.'/>'.
2536: $searchtitles->{$title}.'</label></span></td>';
2537: }
2538: }
1.26 raeburn 2539: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2540: $$rowtotal ++;
1.26 raeburn 2541: if ($cansrchrow) {
2542: $datatable .= '<tr class="LC_odd_row">';
2543: } else {
2544: $datatable .= '<tr>';
2545: }
1.30 raeburn 2546: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2547: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2548: '<span class="LC_nobreak"><label>'.
2549: '<input type="checkbox" name="searchtypes" '.
2550: $exacton.' value="exact" />'.&mt('Exact match').
2551: '</label> '.
2552: '<label><input type="checkbox" name="searchtypes" '.
2553: $beginson.' value="begins" />'.&mt('Begins with').
2554: '</label> '.
2555: '<label><input type="checkbox" name="searchtypes" '.
2556: $containson.' value="contains" />'.&mt('Contains').
2557: '</label></span></td></tr>';
1.30 raeburn 2558: $$rowtotal ++;
1.25 raeburn 2559: return $datatable;
2560: }
2561:
1.28 raeburn 2562: sub print_contacts {
1.30 raeburn 2563: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2564: my $datatable;
2565: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2566: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2567: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2568: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2569: foreach my $type (@mailings) {
2570: $otheremails{$type} = '';
2571: }
1.134 raeburn 2572: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2573: if (ref($settings) eq 'HASH') {
2574: foreach my $item (@contacts) {
2575: if (exists($settings->{$item})) {
2576: $to{$item} = $settings->{$item};
2577: }
2578: }
2579: foreach my $type (@mailings) {
2580: if (exists($settings->{$type})) {
2581: if (ref($settings->{$type}) eq 'HASH') {
2582: foreach my $item (@contacts) {
2583: if ($settings->{$type}{$item}) {
2584: $checked{$type}{$item} = ' checked="checked" ';
2585: }
2586: }
2587: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2588: if ($type eq 'helpdeskmail') {
2589: $bccemails{$type} = $settings->{$type}{'bcc'};
2590: }
1.28 raeburn 2591: }
1.89 raeburn 2592: } elsif ($type eq 'lonstatusmail') {
2593: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2594: }
2595: }
2596: } else {
2597: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2598: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2599: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2600: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2601: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2602: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2603: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2604: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2605: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2606: }
2607: my ($titles,$short_titles) = &contact_titles();
2608: my $rownum = 0;
2609: my $css_class;
2610: foreach my $item (@contacts) {
1.69 raeburn 2611: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2612: $datatable .= '<tr'.$css_class.'>'.
2613: '<td><span class="LC_nobreak">'.$titles->{$item}.
2614: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2615: '<input type="text" name="'.$item.'" value="'.
2616: $to{$item}.'" /></td></tr>';
1.203 raeburn 2617: $rownum ++;
1.28 raeburn 2618: }
2619: foreach my $type (@mailings) {
1.69 raeburn 2620: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2621: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2622: '<td><span class="LC_nobreak">'.
2623: $titles->{$type}.': </span></td>'.
1.28 raeburn 2624: '<td class="LC_left_item">'.
2625: '<span class="LC_nobreak">';
2626: foreach my $item (@contacts) {
2627: $datatable .= '<label>'.
2628: '<input type="checkbox" name="'.$type.'"'.
2629: $checked{$type}{$item}.
2630: ' value="'.$item.'" />'.$short_titles->{$item}.
2631: '</label> ';
2632: }
2633: $datatable .= '</span><br />'.&mt('Others').': '.
2634: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2635: 'value="'.$otheremails{$type}.'" />';
2636: if ($type eq 'helpdeskmail') {
1.136 raeburn 2637: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2638: '<input type="text" name="'.$type.'_bcc" '.
2639: 'value="'.$bccemails{$type}.'" />';
2640: }
2641: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2642: $rownum ++;
1.28 raeburn 2643: }
1.203 raeburn 2644: my %choices;
2645: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2646: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2647: &mt('LON-CAPA core group - MSU'),600,500));
2648: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2649: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2650: &mt('LON-CAPA core group - MSU'),600,500));
2651: my @toggles = ('reporterrors','reportupdates');
2652: my %defaultchecked = ('reporterrors' => 'on',
2653: 'reportupdates' => 'on');
2654: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2655: \%choices,$rownum);
2656: $datatable .= $reports;
1.30 raeburn 2657: $$rowtotal += $rownum;
1.28 raeburn 2658: return $datatable;
2659: }
2660:
1.118 jms 2661: sub print_helpsettings {
1.168 raeburn 2662: my ($dom,$confname,$settings,$rowtotal) = @_;
2663: my ($datatable,$itemcount);
1.166 raeburn 2664: $itemcount = 1;
1.168 raeburn 2665: my (%choices,%defaultchecked,@toggles);
2666: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2667: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2668: &mt('LON-CAPA bug tracker'),600,500));
2669: %defaultchecked = ('submitbugs' => 'on');
2670: @toggles = ('submitbugs',);
1.166 raeburn 2671:
1.168 raeburn 2672: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2673: \%choices,$itemcount);
1.166 raeburn 2674: return $datatable;
1.121 raeburn 2675: }
2676:
2677: sub radiobutton_prefs {
1.192 raeburn 2678: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2679: $additional) = @_;
1.121 raeburn 2680: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2681: (ref($choices) eq 'HASH'));
2682:
1.170 raeburn 2683: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2684:
2685: foreach my $item (@{$toggles}) {
2686: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2687: $checkedon{$item} = ' checked="checked" ';
2688: $checkedoff{$item} = ' ';
1.121 raeburn 2689: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2690: $checkedoff{$item} = ' checked="checked" ';
2691: $checkedon{$item} = ' ';
2692: }
2693: }
2694: if (ref($settings) eq 'HASH') {
1.121 raeburn 2695: foreach my $item (@{$toggles}) {
1.118 jms 2696: if ($settings->{$item} eq '1') {
2697: $checkedon{$item} = ' checked="checked" ';
2698: $checkedoff{$item} = ' ';
2699: } elsif ($settings->{$item} eq '0') {
2700: $checkedoff{$item} = ' checked="checked" ';
2701: $checkedon{$item} = ' ';
2702: }
2703: }
1.121 raeburn 2704: }
1.192 raeburn 2705: if ($onclick) {
2706: $onclick = ' onclick="'.$onclick.'"';
2707: }
1.121 raeburn 2708: foreach my $item (@{$toggles}) {
1.118 jms 2709: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2710: $datatable .=
1.192 raeburn 2711: '<tr'.$css_class.'><td valign="top">'.
2712: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2713: '</span></td>'.
2714: '<td class="LC_right_item"><span class="LC_nobreak">'.
2715: '<label><input type="radio" name="'.
1.192 raeburn 2716: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2717: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2718: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2719: '</span>'.$additional.
2720: '</td>'.
1.118 jms 2721: '</tr>';
2722: $itemcount ++;
1.121 raeburn 2723: }
2724: return ($datatable,$itemcount);
2725: }
2726:
2727: sub print_coursedefaults {
1.139 raeburn 2728: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2729: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2730: my $itemcount = 1;
1.192 raeburn 2731: my %choices = &Apache::lonlocal::texthash (
2732: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2733: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2734: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2735: coursecredits => 'Credits can be specified for courses',
2736: );
1.198 raeburn 2737: my %staticdefaults = (
2738: anonsurvey_threshold => 10,
2739: uploadquota => 500,
2740: );
1.139 raeburn 2741: if ($position eq 'top') {
2742: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2743: @toggles = ('canuse_pdfforms');
1.139 raeburn 2744: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2745: \%choices,$itemcount);
1.139 raeburn 2746: } else {
2747: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2748: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2749: %curruploadquota);
1.192 raeburn 2750: my $currusecredits = 0;
1.216 raeburn 2751: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2752: if (ref($settings) eq 'HASH') {
2753: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2754: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2755: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2756: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2757: }
2758: }
1.192 raeburn 2759: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2760: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2761: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2762: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2763: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2764: ($def_textbook_credits ne '')) {
1.192 raeburn 2765: $currusecredits = 1;
2766: }
2767: }
1.139 raeburn 2768: }
2769: if (!$currdefresponder) {
1.198 raeburn 2770: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2771: } elsif ($currdefresponder < 1) {
2772: $currdefresponder = 1;
2773: }
1.198 raeburn 2774: foreach my $type (@types) {
2775: if ($curruploadquota{$type} eq '') {
2776: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2777: }
2778: }
1.139 raeburn 2779: $datatable .=
1.192 raeburn 2780: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2781: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2782: '</span></td>'.
2783: '<td class="LC_right_item"><span class="LC_nobreak">'.
2784: '<input type="text" name="anonsurvey_threshold"'.
2785: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2786: '</td></tr>'."\n";
2787: $itemcount ++;
2788: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2789: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2790: $choices{'uploadquota'}.
2791: '</span></td>'.
2792: '<td align="right" class="LC_right_item">'.
2793: '<table><tr>';
1.198 raeburn 2794: foreach my $type (@types) {
2795: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2796: '<input type="text" name="uploadquota_'.$type.'"'.
2797: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2798: }
2799: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2800: $itemcount ++;
1.192 raeburn 2801: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2802: my $display = 'none';
1.192 raeburn 2803: if ($currusecredits) {
2804: $display = 'block';
2805: }
2806: my $additional = '<div id="credits" style="display: '.$display.'">'.
2807: '<span class="LC_nobreak">'.
2808: &mt('Default credits for official courses [_1]',
2809: '<input type="text" name="official_credits" value="'.
2810: $def_official_credits.'" size="3" />').
2811: '</span><br />'.
2812: '<span class="LC_nobreak">'.
2813: &mt('Default credits for unofficial courses [_1]',
2814: '<input type="text" name="unofficial_credits" value="'.
2815: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2816: '</span><br />'.
2817: '<span class="LC_nobreak">'.
2818: &mt('Default credits for textbook courses [_1]',
2819: '<input type="text" name="textbook_credits" value="'.
2820: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2821: '</span></div>'."\n";
2822: %defaultchecked = ('coursecredits' => 'off');
2823: @toggles = ('coursecredits');
2824: my $current = {
2825: 'coursecredits' => $currusecredits,
2826: };
2827: (my $table,$itemcount) =
2828: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2829: \%choices,$itemcount,$onclick,$additional);
2830: $datatable .= $table;
1.230 raeburn 2831: $itemcount ++;
1.139 raeburn 2832: }
1.192 raeburn 2833: $$rowtotal += $itemcount;
1.121 raeburn 2834: return $datatable;
1.118 jms 2835: }
2836:
1.231 raeburn 2837: sub print_selfenrollment {
2838: my ($position,$dom,$settings,$rowtotal) = @_;
2839: my ($css_class,$datatable);
2840: my $itemcount = 1;
2841: my @types = ('official','unofficial','community','textbook');
2842: if (($position eq 'top') || ($position eq 'middle')) {
1.232 ! raeburn 2843: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
! 2844: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 2845: my @rows;
2846: my $key;
2847: if ($position eq 'top') {
2848: $key = 'admin';
2849: if (ref($rowsref) eq 'ARRAY') {
2850: @rows = @{$rowsref};
2851: }
2852: } elsif ($position eq 'middle') {
2853: $key = 'default';
2854: @rows = ('types','registered','approval','limit');
2855: }
2856: foreach my $row (@rows) {
2857: if (defined($titlesref->{$row})) {
2858: $itemcount ++;
2859: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2860: $datatable .= '<tr'.$css_class.'>'.
2861: '<td>'.$titlesref->{$row}.'</td>'.
2862: '<td class="LC_left_item">'.
2863: '<table><tr>';
2864: my (%current,%currentcap);
2865: if (ref($settings) eq 'HASH') {
2866: if (ref($settings->{$key}) eq 'HASH') {
2867: foreach my $type (@types) {
2868: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2869: $current{$type} = $settings->{$key}->{$type}->{$row};
2870: }
2871: if (($row eq 'limit') && ($key eq 'default')) {
2872: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2873: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2874: }
2875: }
2876: }
2877: }
2878: }
2879: my %roles = (
2880: '0' => &Apache::lonnet::plaintext('dc'),
2881: );
2882:
2883: foreach my $type (@types) {
2884: unless (($row eq 'registered') && ($key eq 'default')) {
2885: $datatable .= '<th>'.&mt($type).'</th>';
2886: }
2887: }
2888: unless (($row eq 'registered') && ($key eq 'default')) {
2889: $datatable .= '</tr><tr>';
2890: }
2891: foreach my $type (@types) {
2892: if ($type eq 'community') {
2893: $roles{'1'} = &mt('Community personnel');
2894: } else {
2895: $roles{'1'} = &mt('Course personnel');
2896: }
2897: $datatable .= '<td style="vertical-align: top">';
2898: if ($position eq 'top') {
2899: my %checked;
2900: if ($current{$type} eq '0') {
2901: $checked{'0'} = ' checked="checked"';
2902: } else {
2903: $checked{'1'} = ' checked="checked"';
2904: }
2905: foreach my $role ('1','0') {
2906: $datatable .= '<span class="LC_nobreak"><label>'.
2907: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2908: 'value="'.$role.'"'.$checked{$role}.' />'.
2909: $roles{$role}.'</label></span> ';
2910: }
2911: } else {
2912: if ($row eq 'types') {
2913: my %checked;
2914: if ($current{$type} =~ /^(all|dom)$/) {
2915: $checked{$1} = ' checked="checked"';
2916: } else {
2917: $checked{''} = ' checked="checked"';
2918: }
2919: foreach my $val ('','dom','all') {
2920: $datatable .= '<span class="LC_nobreak"><label>'.
2921: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2922: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2923: }
2924: } elsif ($row eq 'registered') {
2925: my %checked;
2926: if ($current{$type} eq '1') {
2927: $checked{'1'} = ' checked="checked"';
2928: } else {
2929: $checked{'0'} = ' checked="checked"';
2930: }
2931: foreach my $val ('0','1') {
2932: $datatable .= '<span class="LC_nobreak"><label>'.
2933: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2934: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2935: }
2936: } elsif ($row eq 'approval') {
2937: my %checked;
2938: if ($current{$type} =~ /^([12])$/) {
2939: $checked{$1} = ' checked="checked"';
2940: } else {
2941: $checked{'0'} = ' checked="checked"';
2942: }
2943: for my $val (0..2) {
2944: $datatable .= '<span class="LC_nobreak"><label>'.
2945: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2946: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2947: }
2948: } elsif ($row eq 'limit') {
2949: my %checked;
2950: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
2951: $checked{$1} = ' checked="checked"';
2952: } else {
2953: $checked{'none'} = ' checked="checked"';
2954: }
2955: my $cap;
2956: if ($currentcap{$type} =~ /^\d+$/) {
2957: $cap = $currentcap{$type};
2958: }
2959: foreach my $val ('none','allstudents','selfenrolled') {
2960: $datatable .= '<span class="LC_nobreak"><label>'.
2961: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2962: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2963: }
2964: $datatable .= '<br />'.
2965: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
2966: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
2967: '</span>';
2968: }
2969: }
2970: $datatable .= '</td>';
2971: }
2972: $datatable .= '</tr>';
2973: }
2974: $datatable .= '</table></td></tr>';
2975: }
2976: } elsif ($position eq 'bottom') {
2977: my ($itemsref,$namesref,$fieldsref) = &selfenroll_validation_types();
2978: my %currvalidation;
2979: if (ref($settings) eq 'HASH') {
2980: if (ref($settings->{'validation'}) eq 'HASH') {
2981: %currvalidation = %{$settings->{'validation'}};
2982: }
2983: }
2984: foreach my $item (@{$itemsref}) {
2985: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2986: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2987: $namesref->{$item}.
2988: '</span></td>'.
2989: '<td class="LC_left_item">';
2990: if (($item eq 'url') || ($item eq 'button')) {
2991: $datatable .= '<span class="LC_nobreak">'.
2992: '<input type="text" name="selfenroll_validation_'.$item.'"'.
2993: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
2994: } elsif ($item eq 'fields') {
2995: my @currfields;
2996: if (ref($currvalidation{$item}) eq 'ARRAY') {
2997: @currfields = @{$currvalidation{$item}};
2998: }
2999: foreach my $field (@{$fieldsref}) {
3000: my $check = '';
3001: if (grep(/^\Q$field\E$/,@currfields)) {
3002: $check = ' checked="checked"';
3003: }
3004: $datatable .= '<span class="LC_nobreak"><label>'.
3005: '<input type="checkbox" name="selfenroll_validation_fields"'.
3006: ' value="'.$field.'"'.$check.' />'.$field.
3007: '</label></span> ';
3008: }
3009: } elsif ($item eq 'markup') {
3010: $datatable .= '<textarea name="selfenroll_validation_markup" cols="50" rows="5" wrap="soft">'.
3011: $currvalidation{$item}.
3012: '</textarea>';
3013: }
3014: $datatable .= '</td></tr>'."\n";
3015: $itemcount ++;
3016: }
3017: }
3018: $$rowtotal += $itemcount;
3019: return $datatable;
3020: }
3021:
1.137 raeburn 3022: sub print_usersessions {
3023: my ($position,$dom,$settings,$rowtotal) = @_;
3024: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3025: my (%by_ip,%by_location,@intdoms);
3026: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3027:
3028: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3029: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3030: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3031: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3032: my $itemcount = 1;
3033: if ($position eq 'top') {
1.152 raeburn 3034: if (keys(%serverhomes) > 1) {
1.145 raeburn 3035: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3036: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3037: } else {
1.140 raeburn 3038: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3039: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3040: }
1.137 raeburn 3041: } else {
1.145 raeburn 3042: if (keys(%by_location) == 0) {
3043: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3044: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3045: } else {
3046: my %lt = &usersession_titles();
3047: my $numinrow = 5;
3048: my $prefix;
3049: my @types;
3050: if ($position eq 'bottom') {
3051: $prefix = 'remote';
3052: @types = ('version','excludedomain','includedomain');
3053: } else {
3054: $prefix = 'hosted';
3055: @types = ('excludedomain','includedomain');
3056: }
3057: my (%current,%checkedon,%checkedoff);
3058: my @lcversions = &Apache::lonnet::all_loncaparevs();
3059: my @locations = sort(keys(%by_location));
3060: foreach my $type (@types) {
3061: $checkedon{$type} = '';
3062: $checkedoff{$type} = ' checked="checked"';
3063: }
3064: if (ref($settings) eq 'HASH') {
3065: if (ref($settings->{$prefix}) eq 'HASH') {
3066: foreach my $key (keys(%{$settings->{$prefix}})) {
3067: $current{$key} = $settings->{$prefix}{$key};
3068: if ($key eq 'version') {
3069: if ($current{$key} ne '') {
3070: $checkedon{$key} = ' checked="checked"';
3071: $checkedoff{$key} = '';
3072: }
3073: } elsif (ref($current{$key}) eq 'ARRAY') {
3074: $checkedon{$key} = ' checked="checked"';
3075: $checkedoff{$key} = '';
3076: }
1.137 raeburn 3077: }
3078: }
3079: }
1.145 raeburn 3080: foreach my $type (@types) {
3081: next if ($type ne 'version' && !@locations);
3082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3083: $datatable .= '<tr'.$css_class.'>
3084: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3085: <span class="LC_nobreak">
3086: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3087: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3088: if ($type eq 'version') {
3089: my $selector = '<select name="'.$prefix.'_version">';
3090: foreach my $version (@lcversions) {
3091: my $selected = '';
3092: if ($current{'version'} eq $version) {
3093: $selected = ' selected="selected"';
3094: }
3095: $selector .= ' <option value="'.$version.'"'.
3096: $selected.'>'.$version.'</option>';
3097: }
3098: $selector .= '</select> ';
3099: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3100: } else {
3101: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3102: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3103: ' />'.(' 'x2).
3104: '<input type="button" value="'.&mt('uncheck all').'" '.
3105: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3106: "\n".
3107: '</div><div><table>';
3108: my $rem;
3109: for (my $i=0; $i<@locations; $i++) {
3110: my ($showloc,$value,$checkedtype);
3111: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3112: my $ip = $by_location{$locations[$i]}->[0];
3113: if (ref($by_ip{$ip}) eq 'ARRAY') {
3114: $value = join(':',@{$by_ip{$ip}});
3115: $showloc = join(', ',@{$by_ip{$ip}});
3116: if (ref($current{$type}) eq 'ARRAY') {
3117: foreach my $loc (@{$by_ip{$ip}}) {
3118: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3119: $checkedtype = ' checked="checked"';
3120: last;
3121: }
3122: }
1.138 raeburn 3123: }
3124: }
3125: }
1.145 raeburn 3126: $rem = $i%($numinrow);
3127: if ($rem == 0) {
3128: if ($i > 0) {
3129: $datatable .= '</tr>';
3130: }
3131: $datatable .= '<tr>';
3132: }
3133: $datatable .= '<td class="LC_left_item">'.
3134: '<span class="LC_nobreak"><label>'.
3135: '<input type="checkbox" name="'.$prefix.'_'.$type.
3136: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3137: '</label></span></td>';
1.137 raeburn 3138: }
1.145 raeburn 3139: $rem = @locations%($numinrow);
3140: my $colsleft = $numinrow - $rem;
3141: if ($colsleft > 1 ) {
3142: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3143: ' </td>';
3144: } elsif ($colsleft == 1) {
3145: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3146: }
1.145 raeburn 3147: $datatable .= '</tr></table>';
1.137 raeburn 3148: }
1.145 raeburn 3149: $datatable .= '</td></tr>';
3150: $itemcount ++;
1.137 raeburn 3151: }
3152: }
3153: }
3154: $$rowtotal += $itemcount;
3155: return $datatable;
3156: }
3157:
1.138 raeburn 3158: sub build_location_hashes {
3159: my ($intdoms,$by_ip,$by_location) = @_;
3160: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3161: (ref($by_location) eq 'HASH'));
3162: my %iphost = &Apache::lonnet::get_iphost();
3163: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3164: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3165: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3166: foreach my $id (@{$iphost{$primary_ip}}) {
3167: my $intdom = &Apache::lonnet::internet_dom($id);
3168: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3169: push(@{$intdoms},$intdom);
3170: }
3171: }
3172: }
3173: foreach my $ip (keys(%iphost)) {
3174: if (ref($iphost{$ip}) eq 'ARRAY') {
3175: foreach my $id (@{$iphost{$ip}}) {
3176: my $location = &Apache::lonnet::internet_dom($id);
3177: if ($location) {
3178: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3179: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3180: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3181: push(@{$by_ip->{$ip}},$location);
3182: }
3183: } else {
3184: $by_ip->{$ip} = [$location];
3185: }
3186: }
3187: }
3188: }
3189: }
3190: foreach my $ip (sort(keys(%{$by_ip}))) {
3191: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3192: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3193: my $first = $by_ip->{$ip}->[0];
3194: if (ref($by_location->{$first}) eq 'ARRAY') {
3195: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3196: push(@{$by_location->{$first}},$ip);
3197: }
3198: } else {
3199: $by_location->{$first} = [$ip];
3200: }
3201: }
3202: }
3203: return;
3204: }
3205:
1.145 raeburn 3206: sub current_offloads_to {
3207: my ($dom,$settings,$servers) = @_;
3208: my (%spareid,%otherdomconfigs);
1.152 raeburn 3209: if (ref($servers) eq 'HASH') {
1.145 raeburn 3210: foreach my $lonhost (sort(keys(%{$servers}))) {
3211: my $gotspares;
1.152 raeburn 3212: if (ref($settings) eq 'HASH') {
3213: if (ref($settings->{'spares'}) eq 'HASH') {
3214: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3215: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3216: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3217: $gotspares = 1;
3218: }
1.145 raeburn 3219: }
3220: }
3221: unless ($gotspares) {
3222: my $gotspares;
3223: my $serverhomeID =
3224: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3225: my $serverhomedom =
3226: &Apache::lonnet::host_domain($serverhomeID);
3227: if ($serverhomedom ne $dom) {
3228: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3229: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3230: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3231: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3232: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3233: $gotspares = 1;
3234: }
3235: }
3236: } else {
3237: $otherdomconfigs{$serverhomedom} =
3238: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3239: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3240: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3241: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3242: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3243: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3244: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3245: $gotspares = 1;
3246: }
3247: }
3248: }
3249: }
3250: }
3251: }
3252: }
3253: unless ($gotspares) {
3254: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3255: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3256: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3257: } else {
3258: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3259: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3260: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3261: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3262: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3263: } else {
1.150 raeburn 3264: my %what = (
3265: spareid => 1,
3266: );
3267: my ($result,$returnhash) =
3268: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3269: if ($result eq 'ok') {
3270: if (ref($returnhash) eq 'HASH') {
3271: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3272: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3273: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3274: }
3275: }
1.145 raeburn 3276: }
3277: }
3278: }
3279: }
3280: }
3281: }
3282: return %spareid;
3283: }
3284:
3285: sub spares_row {
1.152 raeburn 3286: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3287: my $css_class;
3288: my $numinrow = 4;
3289: my $itemcount = 1;
3290: my $datatable;
1.152 raeburn 3291: my %typetitles = &sparestype_titles();
3292: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3293: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3294: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3295: my ($othercontrol,$serverdom);
3296: if ($serverhome ne $server) {
3297: $serverdom = &Apache::lonnet::host_domain($serverhome);
3298: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3299: } else {
3300: $serverdom = &Apache::lonnet::host_domain($server);
3301: if ($serverdom ne $dom) {
3302: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3303: }
3304: }
3305: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3306: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3307: $datatable .= '<tr'.$css_class.'>
3308: <td rowspan="2">
1.183 bisitz 3309: <span class="LC_nobreak">'.
3310: &mt('[_1] when busy, offloads to:'
3311: ,'<b>'.$server.'</b>').
3312: "\n";
1.145 raeburn 3313: my (%current,%canselect);
1.152 raeburn 3314: my @choices =
3315: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3316: foreach my $type ('primary','default') {
3317: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3318: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3319: my @spares = @{$spareid->{$server}{$type}};
3320: if (@spares > 0) {
1.152 raeburn 3321: if ($othercontrol) {
3322: $current{$type} = join(', ',@spares);
3323: } else {
3324: $current{$type} .= '<table>';
3325: my $numspares = scalar(@spares);
3326: for (my $i=0; $i<@spares; $i++) {
3327: my $rem = $i%($numinrow);
3328: if ($rem == 0) {
3329: if ($i > 0) {
3330: $current{$type} .= '</tr>';
3331: }
3332: $current{$type} .= '<tr>';
1.145 raeburn 3333: }
1.152 raeburn 3334: $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'".');" /> '.
3335: $spareid->{$server}{$type}[$i].
3336: '</label></td>'."\n";
3337: }
3338: my $rem = @spares%($numinrow);
3339: my $colsleft = $numinrow - $rem;
3340: if ($colsleft > 1 ) {
3341: $current{$type} .= '<td colspan="'.$colsleft.
3342: '" class="LC_left_item">'.
3343: ' </td>';
3344: } elsif ($colsleft == 1) {
3345: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3346: }
1.152 raeburn 3347: $current{$type} .= '</tr></table>';
1.150 raeburn 3348: }
1.145 raeburn 3349: }
3350: }
3351: if ($current{$type} eq '') {
3352: $current{$type} = &mt('None specified');
3353: }
1.152 raeburn 3354: if ($othercontrol) {
3355: if ($type eq 'primary') {
3356: $canselect{$type} = $othercontrol;
3357: }
3358: } else {
3359: $canselect{$type} =
3360: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3361: '<select name="newspare_'.$type.'_'.$server.'" '.
3362: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3363: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3364: if (@choices > 0) {
3365: foreach my $lonhost (@choices) {
3366: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3367: }
3368: }
3369: $canselect{$type} .= '</select>'."\n";
3370: }
3371: } else {
3372: $current{$type} = &mt('Could not be determined');
3373: if ($type eq 'primary') {
3374: $canselect{$type} = $othercontrol;
3375: }
1.145 raeburn 3376: }
1.152 raeburn 3377: if ($type eq 'default') {
3378: $datatable .= '<tr'.$css_class.'>';
3379: }
3380: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3381: '<td>'.$current{$type}.'</td>'."\n".
3382: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3383: }
3384: $itemcount ++;
3385: }
3386: }
3387: $$rowtotal += $itemcount;
3388: return $datatable;
3389: }
3390:
1.152 raeburn 3391: sub possible_newspares {
3392: my ($server,$currspares,$serverhomes,$altids) = @_;
3393: my $serverhostname = &Apache::lonnet::hostname($server);
3394: my %excluded;
3395: if ($serverhostname ne '') {
3396: %excluded = (
3397: $serverhostname => 1,
3398: );
3399: }
3400: if (ref($currspares) eq 'HASH') {
3401: foreach my $type (keys(%{$currspares})) {
3402: if (ref($currspares->{$type}) eq 'ARRAY') {
3403: if (@{$currspares->{$type}} > 0) {
3404: foreach my $curr (@{$currspares->{$type}}) {
3405: my $hostname = &Apache::lonnet::hostname($curr);
3406: $excluded{$hostname} = 1;
3407: }
3408: }
3409: }
3410: }
3411: }
3412: my @choices;
3413: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3414: if (keys(%{$serverhomes}) > 1) {
3415: foreach my $name (sort(keys(%{$serverhomes}))) {
3416: unless ($excluded{$name}) {
3417: if (exists($altids->{$serverhomes->{$name}})) {
3418: push(@choices,$altids->{$serverhomes->{$name}});
3419: } else {
3420: push(@choices,$serverhomes->{$name});
1.145 raeburn 3421: }
3422: }
3423: }
3424: }
3425: }
1.152 raeburn 3426: return sort(@choices);
1.145 raeburn 3427: }
3428:
1.150 raeburn 3429: sub print_loadbalancing {
3430: my ($dom,$settings,$rowtotal) = @_;
3431: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3432: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3433: my $numinrow = 1;
3434: my $datatable;
3435: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3436: my (%currbalancer,%currtargets,%currrules,%existing);
3437: if (ref($settings) eq 'HASH') {
3438: %existing = %{$settings};
3439: }
3440: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3441: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3442: \%currtargets,\%currrules);
1.150 raeburn 3443: } else {
3444: return;
3445: }
3446: my ($othertitle,$usertypes,$types) =
3447: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3448: my $rownum = 8;
1.150 raeburn 3449: if (ref($types) eq 'ARRAY') {
3450: $rownum += scalar(@{$types});
3451: }
1.171 raeburn 3452: my @css_class = ('LC_odd_row','LC_even_row');
3453: my $balnum = 0;
3454: my $islast;
3455: my (@toshow,$disabledtext);
3456: if (keys(%currbalancer) > 0) {
3457: @toshow = sort(keys(%currbalancer));
3458: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3459: push(@toshow,'');
3460: }
3461: } else {
3462: @toshow = ('');
3463: $disabledtext = &mt('No existing load balancer');
3464: }
3465: foreach my $lonhost (@toshow) {
3466: if ($balnum == scalar(@toshow)-1) {
3467: $islast = 1;
3468: } else {
3469: $islast = 0;
3470: }
3471: my $cssidx = $balnum%2;
3472: my $targets_div_style = 'display: none';
3473: my $disabled_div_style = 'display: block';
3474: my $homedom_div_style = 'display: none';
3475: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3476: '<td rowspan="'.$rownum.'" valign="top">'.
3477: '<p>';
3478: if ($lonhost eq '') {
1.210 raeburn 3479: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3480: if (keys(%currbalancer) > 0) {
3481: $datatable .= &mt('Add balancer:');
3482: } else {
3483: $datatable .= &mt('Enable balancer:');
3484: }
3485: $datatable .= ' '.
3486: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3487: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3488: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3489: '<option value="" selected="selected">'.&mt('None').
3490: '</option>'."\n";
3491: foreach my $server (sort(keys(%servers))) {
3492: next if ($currbalancer{$server});
3493: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3494: }
1.210 raeburn 3495: $datatable .=
1.171 raeburn 3496: '</select>'."\n".
3497: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3498: } else {
3499: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3500: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3501: &mt('Stop balancing').'</label>'.
3502: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3503: $targets_div_style = 'display: block';
3504: $disabled_div_style = 'display: none';
3505: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3506: $homedom_div_style = 'display: block';
3507: }
3508: }
3509: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3510: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3511: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3512: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3513: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3514: my @sparestypes = ('primary','default');
3515: my %typetitles = &sparestype_titles();
3516: foreach my $sparetype (@sparestypes) {
3517: my $targettable;
3518: for (my $i=0; $i<$numspares; $i++) {
3519: my $checked;
3520: if (ref($currtargets{$lonhost}) eq 'HASH') {
3521: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3522: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3523: $checked = ' checked="checked"';
3524: }
3525: }
3526: }
3527: my ($chkboxval,$disabled);
3528: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3529: $chkboxval = $spares[$i];
3530: }
3531: if (exists($currbalancer{$spares[$i]})) {
3532: $disabled = ' disabled="disabled"';
3533: }
1.210 raeburn 3534: $targettable .=
1.171 raeburn 3535: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3536: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3537: '</span></label></td>';
3538: my $rem = $i%($numinrow);
3539: if ($rem == 0) {
3540: if (($i > 0) && ($i < $numspares-1)) {
3541: $targettable .= '</tr>';
3542: }
3543: if ($i < $numspares-1) {
3544: $targettable .= '<tr>';
1.150 raeburn 3545: }
3546: }
3547: }
1.171 raeburn 3548: if ($targettable ne '') {
3549: my $rem = $numspares%($numinrow);
3550: my $colsleft = $numinrow - $rem;
3551: if ($colsleft > 1 ) {
3552: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3553: ' </td>';
3554: } elsif ($colsleft == 1) {
3555: $targettable .= '<td class="LC_left_item"> </td>';
3556: }
3557: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3558: '<table><tr>'.$targettable.'</tr></table><br />';
3559: }
3560: }
3561: $datatable .= '</div></td></tr>'.
3562: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3563: $othertitle,$usertypes,$types,\%servers,
3564: \%currbalancer,$lonhost,
3565: $targets_div_style,$homedom_div_style,
3566: $css_class[$cssidx],$balnum,$islast);
3567: $$rowtotal += $rownum;
3568: $balnum ++;
3569: }
3570: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3571: return $datatable;
3572: }
3573:
3574: sub get_loadbalancers_config {
3575: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3576: return unless ((ref($servers) eq 'HASH') &&
3577: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3578: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3579: if (keys(%{$existing}) > 0) {
3580: my $oldlonhost;
3581: foreach my $key (sort(keys(%{$existing}))) {
3582: if ($key eq 'lonhost') {
3583: $oldlonhost = $existing->{'lonhost'};
3584: $currbalancer->{$oldlonhost} = 1;
3585: } elsif ($key eq 'targets') {
3586: if ($oldlonhost) {
3587: $currtargets->{$oldlonhost} = $existing->{'targets'};
3588: }
3589: } elsif ($key eq 'rules') {
3590: if ($oldlonhost) {
3591: $currrules->{$oldlonhost} = $existing->{'rules'};
3592: }
3593: } elsif (ref($existing->{$key}) eq 'HASH') {
3594: $currbalancer->{$key} = 1;
3595: $currtargets->{$key} = $existing->{$key}{'targets'};
3596: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3597: }
3598: }
1.171 raeburn 3599: } else {
3600: my ($balancerref,$targetsref) =
3601: &Apache::lonnet::get_lonbalancer_config($servers);
3602: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3603: foreach my $server (sort(keys(%{$balancerref}))) {
3604: $currbalancer->{$server} = 1;
3605: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3606: }
3607: }
3608: }
1.171 raeburn 3609: return;
1.150 raeburn 3610: }
3611:
3612: sub loadbalancing_rules {
3613: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3614: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3615: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3616: my $output;
1.171 raeburn 3617: my $num = 0;
1.210 raeburn 3618: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3619: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3620: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3621: foreach my $type (@{$alltypes}) {
1.171 raeburn 3622: $num ++;
1.150 raeburn 3623: my $current;
3624: if (ref($currrules) eq 'HASH') {
3625: $current = $currrules->{$type};
3626: }
1.209 raeburn 3627: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3628: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3629: $current = '';
3630: }
3631: }
3632: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3633: $servers,$currbalancer,$lonhost,$dom,
3634: $targets_div_style,$homedom_div_style,
3635: $css_class,$balnum,$num,$islast);
1.150 raeburn 3636: }
3637: }
3638: return $output;
3639: }
3640:
3641: sub loadbalancing_titles {
3642: my ($dom,$intdom,$usertypes,$types) = @_;
3643: my %othertypes = (
3644: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3645: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3646: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3647: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3648: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3649: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3650: );
1.209 raeburn 3651: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3652: if (ref($types) eq 'ARRAY') {
3653: unshift(@alltypes,@{$types},'default');
3654: }
3655: my %titles;
3656: foreach my $type (@alltypes) {
3657: if ($type =~ /^_LC_/) {
3658: $titles{$type} = $othertypes{$type};
3659: } elsif ($type eq 'default') {
3660: $titles{$type} = &mt('All users from [_1]',$dom);
3661: if (ref($types) eq 'ARRAY') {
3662: if (@{$types} > 0) {
3663: $titles{$type} = &mt('Other users from [_1]',$dom);
3664: }
3665: }
3666: } elsif (ref($usertypes) eq 'HASH') {
3667: $titles{$type} = $usertypes->{$type};
3668: }
3669: }
3670: return (\@alltypes,\%othertypes,\%titles);
3671: }
3672:
3673: sub loadbalance_rule_row {
1.171 raeburn 3674: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3675: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3676: my @rulenames;
1.150 raeburn 3677: my %ruletitles = &offloadtype_text();
1.209 raeburn 3678: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3679: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3680: } else {
1.209 raeburn 3681: @rulenames = ('default','homeserver');
3682: if ($type eq '_LC_external') {
3683: push(@rulenames,'externalbalancer');
3684: } else {
3685: push(@rulenames,'specific');
3686: }
3687: push(@rulenames,'none');
1.150 raeburn 3688: }
3689: my $style = $targets_div_style;
1.209 raeburn 3690: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3691: $style = $homedom_div_style;
3692: }
1.171 raeburn 3693: my $space;
3694: if ($islast && $num == 1) {
3695: $space = '<div display="inline-block"> </div>';
3696: }
1.210 raeburn 3697: my $output =
1.171 raeburn 3698: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3699: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3700: '<td valaign="top">'.$space.
3701: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3702: for (my $i=0; $i<@rulenames; $i++) {
3703: my $rule = $rulenames[$i];
3704: my ($checked,$extra);
3705: if ($rulenames[$i] eq 'default') {
3706: $rule = '';
3707: }
3708: if ($rulenames[$i] eq 'specific') {
3709: if (ref($servers) eq 'HASH') {
3710: my $default;
3711: if (($current ne '') && (exists($servers->{$current}))) {
3712: $checked = ' checked="checked"';
3713: }
3714: unless ($checked) {
3715: $default = ' selected="selected"';
3716: }
1.210 raeburn 3717: $extra =
1.171 raeburn 3718: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3719: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3720: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3721: '<option value=""'.$default.'></option>'."\n";
3722: foreach my $server (sort(keys(%{$servers}))) {
3723: if (ref($currbalancer) eq 'HASH') {
3724: next if (exists($currbalancer->{$server}));
3725: }
1.150 raeburn 3726: my $selected;
1.171 raeburn 3727: if ($server eq $current) {
1.150 raeburn 3728: $selected = ' selected="selected"';
3729: }
1.171 raeburn 3730: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3731: }
3732: $extra .= '</select>';
3733: }
3734: } elsif ($rule eq $current) {
3735: $checked = ' checked="checked"';
3736: }
3737: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3738: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3739: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3740: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3741: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3742: '</label>'.$extra.'</span><br />'."\n";
3743: }
3744: $output .= '</div></td></tr>'."\n";
3745: return $output;
3746: }
3747:
3748: sub offloadtype_text {
3749: my %ruletitles = &Apache::lonlocal::texthash (
3750: 'default' => 'Offloads to default destinations',
3751: 'homeserver' => "Offloads to user's home server",
3752: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3753: 'specific' => 'Offloads to specific server',
1.161 raeburn 3754: 'none' => 'No offload',
1.209 raeburn 3755: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3756: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3757: );
3758: return %ruletitles;
3759: }
3760:
3761: sub sparestype_titles {
3762: my %typestitles = &Apache::lonlocal::texthash (
3763: 'primary' => 'primary',
3764: 'default' => 'default',
3765: );
3766: return %typestitles;
3767: }
3768:
1.28 raeburn 3769: sub contact_titles {
3770: my %titles = &Apache::lonlocal::texthash (
3771: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3772: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3773: 'errormail' => 'Error reports to be e-mailed to',
3774: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3775: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3776: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3777: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3778: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3779: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3780: );
3781: my %short_titles = &Apache::lonlocal::texthash (
3782: adminemail => 'Admin E-mail address',
3783: supportemail => 'Support E-mail',
3784: );
3785: return (\%titles,\%short_titles);
3786: }
3787:
1.72 raeburn 3788: sub tool_titles {
3789: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3790: aboutme => 'Personal web page',
1.86 raeburn 3791: blog => 'Blog',
1.162 raeburn 3792: webdav => 'WebDAV',
1.86 raeburn 3793: portfolio => 'Portfolio',
1.88 bisitz 3794: official => 'Official courses (with institutional codes)',
3795: unofficial => 'Unofficial courses',
1.98 raeburn 3796: community => 'Communities',
1.216 raeburn 3797: textbook => 'Textbook courses',
1.86 raeburn 3798: );
1.72 raeburn 3799: return %titles;
3800: }
3801:
1.101 raeburn 3802: sub courserequest_titles {
3803: my %titles = &Apache::lonlocal::texthash (
3804: official => 'Official',
3805: unofficial => 'Unofficial',
3806: community => 'Communities',
1.216 raeburn 3807: textbook => 'Textbook',
1.101 raeburn 3808: norequest => 'Not allowed',
1.104 raeburn 3809: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3810: validate => 'With validation',
3811: autolimit => 'Numerical limit',
1.103 raeburn 3812: unlimited => '(blank for unlimited)',
1.101 raeburn 3813: );
3814: return %titles;
3815: }
3816:
1.163 raeburn 3817: sub authorrequest_titles {
3818: my %titles = &Apache::lonlocal::texthash (
3819: norequest => 'Not allowed',
3820: approval => 'Approval by Dom. Coord.',
3821: automatic => 'Automatic approval',
3822: );
3823: return %titles;
1.210 raeburn 3824: }
1.163 raeburn 3825:
1.101 raeburn 3826: sub courserequest_conditions {
3827: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3828: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3829: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3830: );
3831: return %conditions;
3832: }
3833:
3834:
1.27 raeburn 3835: sub print_usercreation {
1.30 raeburn 3836: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3837: my $numinrow = 4;
1.28 raeburn 3838: my $datatable;
3839: if ($position eq 'top') {
1.30 raeburn 3840: $$rowtotal ++;
1.34 raeburn 3841: my $rowcount = 0;
1.32 raeburn 3842: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3843: if (ref($rules) eq 'HASH') {
3844: if (keys(%{$rules}) > 0) {
1.32 raeburn 3845: $datatable .= &user_formats_row('username',$settings,$rules,
3846: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3847: $$rowtotal ++;
1.32 raeburn 3848: $rowcount ++;
3849: }
3850: }
3851: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3852: if (ref($idrules) eq 'HASH') {
3853: if (keys(%{$idrules}) > 0) {
3854: $datatable .= &user_formats_row('id',$settings,$idrules,
3855: $idruleorder,$numinrow,$rowcount);
3856: $$rowtotal ++;
3857: $rowcount ++;
1.28 raeburn 3858: }
3859: }
1.39 raeburn 3860: if ($rowcount == 0) {
3861: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3862: $$rowtotal ++;
3863: $rowcount ++;
3864: }
1.34 raeburn 3865: } elsif ($position eq 'middle') {
1.224 raeburn 3866: my @creators = ('author','course','requestcrs');
1.37 raeburn 3867: my ($rules,$ruleorder) =
3868: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3869: my %lt = &usercreation_types();
3870: my %checked;
3871: if (ref($settings) eq 'HASH') {
3872: if (ref($settings->{'cancreate'}) eq 'HASH') {
3873: foreach my $item (@creators) {
3874: $checked{$item} = $settings->{'cancreate'}{$item};
3875: }
3876: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3877: foreach my $item (@creators) {
3878: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3879: $checked{$item} = 'none';
3880: }
3881: }
3882: }
3883: }
3884: my $rownum = 0;
3885: foreach my $item (@creators) {
3886: $rownum ++;
1.224 raeburn 3887: if ($checked{$item} eq '') {
3888: $checked{$item} = 'any';
1.34 raeburn 3889: }
3890: my $css_class;
3891: if ($rownum%2) {
3892: $css_class = '';
3893: } else {
3894: $css_class = ' class="LC_odd_row" ';
3895: }
3896: $datatable .= '<tr'.$css_class.'>'.
3897: '<td><span class="LC_nobreak">'.$lt{$item}.
3898: '</span></td><td align="right">';
1.224 raeburn 3899: my @options = ('any');
3900: if (ref($rules) eq 'HASH') {
3901: if (keys(%{$rules}) > 0) {
3902: push(@options,('official','unofficial'));
1.37 raeburn 3903: }
3904: }
1.224 raeburn 3905: push(@options,'none');
1.37 raeburn 3906: foreach my $option (@options) {
1.50 raeburn 3907: my $type = 'radio';
1.34 raeburn 3908: my $check = ' ';
1.224 raeburn 3909: if ($checked{$item} eq $option) {
3910: $check = ' checked="checked" ';
1.34 raeburn 3911: }
3912: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3913: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3914: $item.'" value="'.$option.'"'.$check.'/> '.
3915: $lt{$option}.'</label> </span>';
3916: }
3917: $datatable .= '</td></tr>';
3918: }
1.28 raeburn 3919: } else {
3920: my @contexts = ('author','course','domain');
3921: my @authtypes = ('int','krb4','krb5','loc');
3922: my %checked;
3923: if (ref($settings) eq 'HASH') {
3924: if (ref($settings->{'authtypes'}) eq 'HASH') {
3925: foreach my $item (@contexts) {
3926: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3927: foreach my $auth (@authtypes) {
3928: if ($settings->{'authtypes'}{$item}{$auth}) {
3929: $checked{$item}{$auth} = ' checked="checked" ';
3930: }
3931: }
3932: }
3933: }
1.27 raeburn 3934: }
1.35 raeburn 3935: } else {
3936: foreach my $item (@contexts) {
1.36 raeburn 3937: foreach my $auth (@authtypes) {
1.35 raeburn 3938: $checked{$item}{$auth} = ' checked="checked" ';
3939: }
3940: }
1.27 raeburn 3941: }
1.28 raeburn 3942: my %title = &context_names();
3943: my %authname = &authtype_names();
3944: my $rownum = 0;
3945: my $css_class;
3946: foreach my $item (@contexts) {
3947: if ($rownum%2) {
3948: $css_class = '';
3949: } else {
3950: $css_class = ' class="LC_odd_row" ';
3951: }
1.30 raeburn 3952: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3953: '<td>'.$title{$item}.
3954: '</td><td class="LC_left_item">'.
3955: '<span class="LC_nobreak">';
3956: foreach my $auth (@authtypes) {
3957: $datatable .= '<label>'.
3958: '<input type="checkbox" name="'.$item.'_auth" '.
3959: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3960: $authname{$auth}.'</label> ';
3961: }
3962: $datatable .= '</span></td></tr>';
3963: $rownum ++;
1.27 raeburn 3964: }
1.30 raeburn 3965: $$rowtotal += $rownum;
1.27 raeburn 3966: }
3967: return $datatable;
3968: }
3969:
1.224 raeburn 3970: sub print_selfcreation {
3971: my ($position,$dom,$settings,$rowtotal) = @_;
3972: my (@selfcreate,$createsettings,$datatable);
3973: if (ref($settings) eq 'HASH') {
3974: if (ref($settings->{'cancreate'}) eq 'HASH') {
3975: $createsettings = $settings->{'cancreate'};
3976: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3977: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3978: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3979: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3980: @selfcreate = ('email','login','sso');
3981: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3982: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3983: }
3984: }
3985: }
3986: }
3987: my %radiohash;
3988: my $numinrow = 4;
3989: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
3990: if ($position eq 'top') {
3991: my %choices = &Apache::lonlocal::texthash (
3992: cancreate_login => 'Institutional Login',
3993: cancreate_sso => 'Institutional Single Sign On',
3994: );
3995: my @toggles = sort(keys(%choices));
3996: my %defaultchecked = (
3997: 'cancreate_login' => 'off',
3998: 'cancreate_sso' => 'off',
3999: );
1.228 raeburn 4000: my ($onclick,$itemcount);
1.224 raeburn 4001: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4002: \%choices,$itemcount,$onclick);
1.228 raeburn 4003: $$rowtotal += $itemcount;
4004:
1.224 raeburn 4005: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4006:
4007: if (ref($usertypes) eq 'HASH') {
4008: if (keys(%{$usertypes}) > 0) {
4009: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4010: $dom,$numinrow,$othertitle,
1.228 raeburn 4011: 'statustocreate',$$rowtotal);
1.224 raeburn 4012: $$rowtotal ++;
4013: }
4014: }
4015: } elsif ($position eq 'middle') {
4016: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4017: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4018: $usertypes->{'default'} = $othertitle;
4019: if (ref($types) eq 'ARRAY') {
4020: push(@{$types},'default');
4021: $usertypes->{'default'} = $othertitle;
4022: foreach my $status (@{$types}) {
4023: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4024: $numinrow,$$rowtotal,$usertypes);
1.224 raeburn 4025: $$rowtotal ++;
4026: }
4027: }
4028: } else {
1.228 raeburn 4029: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
1.224 raeburn 4030: my %choices =
4031: &Apache::lonlocal::texthash(
4032: email => 'Approved automatically',
4033: emailapproval => 'Queued for approval by DC',
4034: off => 'Not enabled',
4035: );
4036: $datatable .= '<tr'.$css_class.'>'.
4037: '<td>'.&mt('E-mail address as username').
4038: '</td><td class="LC_left_item">'.
4039: '<span class="LC_nobreak">';
4040: foreach my $option ('email','emailapproval','off') {
4041: my $checked;
4042: if ($option eq 'email') {
4043: if ($radiohash{'cancreate_email'}) {
4044: $checked = 'checked="checked"';
4045: }
4046: } elsif ($option eq 'emailapproval') {
4047: if ($radiohash{'cancreate_emailapproval'}) {
4048: $checked = 'checked="checked"';
4049: }
4050: } else {
4051: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
4052: $checked = 'checked="checked"';
4053: }
4054: }
4055: $datatable .= '<label>'.
4056: '<input type="radio" name="cancreate_email" '.
4057: $checked.' value="'.$option.'" />'.
4058: $choices{$option}.'</label> ';
4059: }
4060: $$rowtotal ++;
4061: $datatable .= '</span></td></tr>'.
4062: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4063: $$rowtotal ++;
1.224 raeburn 4064: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4065: $numinrow = 1;
4066: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4067: $usertypes->{'default'} = $othertitle;
4068: if (ref($types) eq 'ARRAY') {
4069: push(@{$types},'default');
4070: $usertypes->{'default'} = $othertitle;
4071: foreach my $status (@{$types}) {
4072: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4073: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4074: $$rowtotal ++;
4075: }
4076: }
1.224 raeburn 4077: my ($emailrules,$emailruleorder) =
4078: &Apache::lonnet::inst_userrules($dom,'email');
4079: if (ref($emailrules) eq 'HASH') {
4080: if (keys(%{$emailrules}) > 0) {
4081: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4082: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4083: $$rowtotal ++;
4084: }
4085: }
1.228 raeburn 4086: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4087: }
4088: return $datatable;
4089: }
4090:
1.165 raeburn 4091: sub captcha_choice {
1.169 raeburn 4092: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4093: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4094: my %lt = &captcha_phrases();
4095: $keyentry = 'hidden';
4096: if ($context eq 'cancreate') {
1.224 raeburn 4097: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4098: } elsif ($context eq 'login') {
4099: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4100: }
4101: if (ref($settings) eq 'HASH') {
4102: if ($settings->{'captcha'}) {
4103: $checked{$settings->{'captcha'}} = ' checked="checked"';
4104: } else {
4105: $checked{'original'} = ' checked="checked"';
4106: }
4107: if ($settings->{'captcha'} eq 'recaptcha') {
4108: $pubtext = $lt{'pub'};
4109: $privtext = $lt{'priv'};
4110: $keyentry = 'text';
4111: }
4112: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4113: $currpub = $settings->{'recaptchakeys'}{'public'};
4114: $currpriv = $settings->{'recaptchakeys'}{'private'};
4115: }
4116: } else {
4117: $checked{'original'} = ' checked="checked"';
4118: }
1.169 raeburn 4119: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4120: my $output = '<tr'.$css_class.'>'.
4121: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4122: '<table><tr><td>'."\n";
4123: foreach my $option ('original','recaptcha','notused') {
4124: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4125: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4126: $lt{$option}.'</label></span>';
4127: unless ($option eq 'notused') {
4128: $output .= (' 'x2)."\n";
4129: }
4130: }
4131: #
4132: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4133: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4134: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4135: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4136: #
1.165 raeburn 4137: $output .= '</td></tr>'."\n".
4138: '<tr><td>'."\n".
4139: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4140: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4141: $currpub.'" size="40" /></span><br />'."\n".
4142: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4143: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4144: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4145: '</td></tr>';
4146: return $output;
4147: }
4148:
1.32 raeburn 4149: sub user_formats_row {
4150: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4151: my $output;
4152: my %text = (
4153: 'username' => 'new usernames',
4154: 'id' => 'IDs',
1.45 raeburn 4155: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4156: );
4157: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4158: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4159: '<td><span class="LC_nobreak">';
4160: if ($type eq 'email') {
4161: $output .= &mt("Formats disallowed for $text{$type}: ");
4162: } else {
4163: $output .= &mt("Format rules to check for $text{$type}: ");
4164: }
4165: $output .= '</span></td>'.
4166: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4167: my $rem;
4168: if (ref($ruleorder) eq 'ARRAY') {
4169: for (my $i=0; $i<@{$ruleorder}; $i++) {
4170: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4171: my $rem = $i%($numinrow);
4172: if ($rem == 0) {
4173: if ($i > 0) {
4174: $output .= '</tr>';
4175: }
4176: $output .= '<tr>';
4177: }
4178: my $check = ' ';
1.39 raeburn 4179: if (ref($settings) eq 'HASH') {
4180: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4181: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4182: $check = ' checked="checked" ';
4183: }
1.27 raeburn 4184: }
4185: }
4186: $output .= '<td class="LC_left_item">'.
4187: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4188: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4189: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4190: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4191: }
4192: }
4193: $rem = @{$ruleorder}%($numinrow);
4194: }
4195: my $colsleft = $numinrow - $rem;
4196: if ($colsleft > 1 ) {
4197: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4198: ' </td>';
4199: } elsif ($colsleft == 1) {
4200: $output .= '<td class="LC_left_item"> </td>';
4201: }
4202: $output .= '</tr></table></td></tr>';
4203: return $output;
4204: }
4205:
1.34 raeburn 4206: sub usercreation_types {
4207: my %lt = &Apache::lonlocal::texthash (
4208: author => 'When adding a co-author',
4209: course => 'When adding a user to a course',
1.100 raeburn 4210: requestcrs => 'When requesting a course',
1.34 raeburn 4211: any => 'Any',
4212: official => 'Institutional only ',
4213: unofficial => 'Non-institutional only',
4214: none => 'None',
4215: );
4216: return %lt;
1.48 raeburn 4217: }
1.34 raeburn 4218:
1.224 raeburn 4219: sub selfcreation_types {
4220: my %lt = &Apache::lonlocal::texthash (
4221: selfcreate => 'User creates own account',
4222: any => 'Any',
4223: official => 'Institutional only ',
4224: unofficial => 'Non-institutional only',
4225: email => 'E-mail address',
4226: login => 'Institutional Login',
4227: sso => 'SSO',
4228: );
4229: }
4230:
1.28 raeburn 4231: sub authtype_names {
4232: my %lt = &Apache::lonlocal::texthash(
4233: int => 'Internal',
4234: krb4 => 'Kerberos 4',
4235: krb5 => 'Kerberos 5',
4236: loc => 'Local',
4237: );
4238: return %lt;
4239: }
4240:
4241: sub context_names {
4242: my %context_title = &Apache::lonlocal::texthash(
4243: author => 'Creating users when an Author',
4244: course => 'Creating users when in a course',
4245: domain => 'Creating users when a Domain Coordinator',
4246: );
4247: return %context_title;
4248: }
4249:
1.33 raeburn 4250: sub print_usermodification {
4251: my ($position,$dom,$settings,$rowtotal) = @_;
4252: my $numinrow = 4;
4253: my ($context,$datatable,$rowcount);
4254: if ($position eq 'top') {
4255: $rowcount = 0;
4256: $context = 'author';
4257: foreach my $role ('ca','aa') {
4258: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4259: $numinrow,$rowcount);
4260: $$rowtotal ++;
4261: $rowcount ++;
4262: }
1.230 raeburn 4263: } elsif ($position eq 'bottom') {
1.33 raeburn 4264: $context = 'course';
4265: $rowcount = 0;
4266: foreach my $role ('st','ep','ta','in','cr') {
4267: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4268: $numinrow,$rowcount);
4269: $$rowtotal ++;
4270: $rowcount ++;
4271: }
4272: }
4273: return $datatable;
4274: }
4275:
1.43 raeburn 4276: sub print_defaults {
1.212 raeburn 4277: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4278: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4279: 'datelocale_def','portal_def');
1.212 raeburn 4280: my %defaults;
4281: if (ref($settings) eq 'HASH') {
1.213 raeburn 4282: %defaults = %{$settings};
1.212 raeburn 4283: } else {
4284: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4285: foreach my $item (@items) {
4286: $defaults{$item} = $domdefaults{$item};
4287: }
4288: }
1.141 raeburn 4289: my $titles = &defaults_titles($dom);
1.43 raeburn 4290: my $rownum = 0;
4291: my ($datatable,$css_class);
4292: foreach my $item (@items) {
4293: if ($rownum%2) {
4294: $css_class = '';
4295: } else {
4296: $css_class = ' class="LC_odd_row" ';
4297: }
4298: $datatable .= '<tr'.$css_class.'>'.
4299: '<td><span class="LC_nobreak">'.$titles->{$item}.
4300: '</span></td><td class="LC_right_item">';
4301: if ($item eq 'auth_def') {
4302: my @authtypes = ('internal','krb4','krb5','localauth');
4303: my %shortauth = (
4304: internal => 'int',
4305: krb4 => 'krb4',
4306: krb5 => 'krb5',
4307: localauth => 'loc'
4308: );
4309: my %authnames = &authtype_names();
4310: foreach my $auth (@authtypes) {
4311: my $checked = ' ';
1.212 raeburn 4312: if ($defaults{$item} eq $auth) {
1.43 raeburn 4313: $checked = ' checked="checked" ';
4314: }
4315: $datatable .= '<label><input type="radio" name="'.$item.
4316: '" value="'.$auth.'"'.$checked.'/>'.
4317: $authnames{$shortauth{$auth}}.'</label> ';
4318: }
1.54 raeburn 4319: } elsif ($item eq 'timezone_def') {
4320: my $includeempty = 1;
1.212 raeburn 4321: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4322: } elsif ($item eq 'datelocale_def') {
4323: my $includeempty = 1;
1.212 raeburn 4324: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4325: } elsif ($item eq 'lang_def') {
1.168 raeburn 4326: my %langchoices = &get_languages_hash();
4327: $langchoices{''} = 'No language preference';
1.167 raeburn 4328: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4329: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4330: \%langchoices);
1.43 raeburn 4331: } else {
1.141 raeburn 4332: my $size;
4333: if ($item eq 'portal_def') {
4334: $size = ' size="25"';
4335: }
1.43 raeburn 4336: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4337: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4338: }
4339: $datatable .= '</td></tr>';
4340: $rownum ++;
4341: }
4342: $$rowtotal += $rownum;
4343: return $datatable;
4344: }
4345:
1.168 raeburn 4346: sub get_languages_hash {
4347: my %langchoices;
4348: foreach my $id (&Apache::loncommon::languageids()) {
4349: my $code = &Apache::loncommon::supportedlanguagecode($id);
4350: if ($code ne '') {
4351: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4352: }
4353: }
4354: return %langchoices;
4355: }
4356:
1.43 raeburn 4357: sub defaults_titles {
1.141 raeburn 4358: my ($dom) = @_;
1.43 raeburn 4359: my %titles = &Apache::lonlocal::texthash (
4360: 'auth_def' => 'Default authentication type',
4361: 'auth_arg_def' => 'Default authentication argument',
4362: 'lang_def' => 'Default language',
1.54 raeburn 4363: 'timezone_def' => 'Default timezone',
1.68 raeburn 4364: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4365: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4366: );
1.141 raeburn 4367: if ($dom) {
4368: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4369: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4370: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4371: $protocol = 'http' if ($protocol ne 'https');
4372: if ($uint_dom) {
4373: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4374: $uint_dom);
4375: }
4376: }
1.43 raeburn 4377: return (\%titles);
4378: }
4379:
1.46 raeburn 4380: sub print_scantronformat {
4381: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4382: my $itemcount = 1;
1.60 raeburn 4383: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4384: %confhash);
1.46 raeburn 4385: my $switchserver = &check_switchserver($dom,$confname);
4386: my %lt = &Apache::lonlocal::texthash (
1.95 www 4387: default => 'Default bubblesheet format file error',
4388: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4389: );
4390: my %scantronfiles = (
4391: default => 'default.tab',
4392: custom => 'custom.tab',
4393: );
4394: foreach my $key (keys(%scantronfiles)) {
4395: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4396: .$scantronfiles{$key};
4397: }
4398: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4399: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4400: if (!$switchserver) {
4401: my $servadm = $r->dir_config('lonAdmEMail');
4402: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4403: if ($configuserok eq 'ok') {
4404: if ($author_ok eq 'ok') {
4405: my %legacyfile = (
4406: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4407: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4408: );
4409: my %md5chk;
4410: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4411: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4412: chomp($md5chk{$type});
1.46 raeburn 4413: }
4414: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4415: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4416: ($scantronurls{$type},my $error) =
1.46 raeburn 4417: &legacy_scantronformat($r,$dom,$confname,
4418: $type,$legacyfile{$type},
4419: $scantronurls{$type},
4420: $scantronfiles{$type});
1.60 raeburn 4421: if ($error ne '') {
4422: $error{$type} = $error;
4423: }
4424: }
4425: if (keys(%error) == 0) {
4426: $is_custom = 1;
4427: $confhash{'scantron'}{'scantronformat'} =
4428: $scantronurls{'custom'};
4429: my $putresult =
4430: &Apache::lonnet::put_dom('configuration',
4431: \%confhash,$dom);
4432: if ($putresult ne 'ok') {
4433: $error{'custom'} =
4434: '<span class="LC_error">'.
4435: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4436: }
1.46 raeburn 4437: }
4438: } else {
1.60 raeburn 4439: ($scantronurls{'default'},my $error) =
1.46 raeburn 4440: &legacy_scantronformat($r,$dom,$confname,
4441: 'default',$legacyfile{'default'},
4442: $scantronurls{'default'},
4443: $scantronfiles{'default'});
1.60 raeburn 4444: if ($error eq '') {
4445: $confhash{'scantron'}{'scantronformat'} = '';
4446: my $putresult =
4447: &Apache::lonnet::put_dom('configuration',
4448: \%confhash,$dom);
4449: if ($putresult ne 'ok') {
4450: $error{'default'} =
4451: '<span class="LC_error">'.
4452: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4453: }
4454: } else {
4455: $error{'default'} = $error;
4456: }
1.46 raeburn 4457: }
4458: }
4459: }
4460: } else {
1.95 www 4461: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4462: }
4463: }
4464: if (ref($settings) eq 'HASH') {
4465: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4466: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4467: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4468: $scantronurl = '';
4469: } else {
4470: $scantronurl = $settings->{'scantronformat'};
4471: }
4472: $is_custom = 1;
4473: } else {
4474: $scantronurl = $scantronurls{'default'};
4475: }
4476: } else {
1.60 raeburn 4477: if ($is_custom) {
4478: $scantronurl = $scantronurls{'custom'};
4479: } else {
4480: $scantronurl = $scantronurls{'default'};
4481: }
1.46 raeburn 4482: }
4483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4484: $datatable .= '<tr'.$css_class.'>';
4485: if (!$is_custom) {
1.65 raeburn 4486: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4487: '<span class="LC_nobreak">';
1.46 raeburn 4488: if ($scantronurl) {
1.199 raeburn 4489: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4490: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4491: } else {
4492: $datatable = &mt('File unavailable for display');
4493: }
1.65 raeburn 4494: $datatable .= '</span></td>';
1.60 raeburn 4495: if (keys(%error) == 0) {
4496: $datatable .= '<td valign="bottom">';
4497: if (!$switchserver) {
4498: $datatable .= &mt('Upload:').'<br />';
4499: }
4500: } else {
4501: my $errorstr;
4502: foreach my $key (sort(keys(%error))) {
4503: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4504: }
4505: $datatable .= '<td>'.$errorstr;
4506: }
1.46 raeburn 4507: } else {
4508: if (keys(%error) > 0) {
4509: my $errorstr;
4510: foreach my $key (sort(keys(%error))) {
4511: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4512: }
1.60 raeburn 4513: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4514: } elsif ($scantronurl) {
1.199 raeburn 4515: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4516: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4517: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4518: $link.
4519: '<label><input type="checkbox" name="scantronformat_del"'.
4520: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4521: '<td><span class="LC_nobreak"> '.
4522: &mt('Replace:').'</span><br />';
1.46 raeburn 4523: }
4524: }
4525: if (keys(%error) == 0) {
4526: if ($switchserver) {
4527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4528: } else {
1.65 raeburn 4529: $datatable .='<span class="LC_nobreak"> '.
4530: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4531: }
4532: }
4533: $datatable .= '</td></tr>';
4534: $$rowtotal ++;
4535: return $datatable;
4536: }
4537:
4538: sub legacy_scantronformat {
4539: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4540: my ($url,$error);
4541: my @statinfo = &Apache::lonnet::stat_file($newurl);
4542: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4543: (my $result,$url) =
4544: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4545: '','',$newfile);
4546: if ($result ne 'ok') {
1.130 raeburn 4547: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4548: }
4549: }
4550: return ($url,$error);
4551: }
1.43 raeburn 4552:
1.49 raeburn 4553: sub print_coursecategories {
1.57 raeburn 4554: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4555: my $datatable;
4556: if ($position eq 'top') {
4557: my $toggle_cats_crs = ' ';
4558: my $toggle_cats_dom = ' checked="checked" ';
4559: my $can_cat_crs = ' ';
4560: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4561: my $toggle_catscomm_comm = ' ';
4562: my $toggle_catscomm_dom = ' checked="checked" ';
4563: my $can_catcomm_comm = ' ';
4564: my $can_catcomm_dom = ' checked="checked" ';
4565:
1.57 raeburn 4566: if (ref($settings) eq 'HASH') {
4567: if ($settings->{'togglecats'} eq 'crs') {
4568: $toggle_cats_crs = $toggle_cats_dom;
4569: $toggle_cats_dom = ' ';
4570: }
4571: if ($settings->{'categorize'} eq 'crs') {
4572: $can_cat_crs = $can_cat_dom;
4573: $can_cat_dom = ' ';
4574: }
1.120 raeburn 4575: if ($settings->{'togglecatscomm'} eq 'comm') {
4576: $toggle_catscomm_comm = $toggle_catscomm_dom;
4577: $toggle_catscomm_dom = ' ';
4578: }
4579: if ($settings->{'categorizecomm'} eq 'comm') {
4580: $can_catcomm_comm = $can_catcomm_dom;
4581: $can_catcomm_dom = ' ';
4582: }
1.57 raeburn 4583: }
4584: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4585: togglecats => 'Show/Hide a course in catalog',
4586: togglecatscomm => 'Show/Hide a community in catalog',
4587: categorize => 'Assign a category to a course',
4588: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4589: );
4590: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4591: dom => 'Set in Domain',
4592: crs => 'Set in Course',
4593: comm => 'Set in Community',
1.57 raeburn 4594: );
4595: $datatable = '<tr class="LC_odd_row">'.
4596: '<td>'.$title{'togglecats'}.'</td>'.
4597: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4598: '<input type="radio" name="togglecats"'.
4599: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4600: '<label><input type="radio" name="togglecats"'.
4601: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4602: '</tr><tr>'.
4603: '<td>'.$title{'categorize'}.'</td>'.
4604: '<td class="LC_right_item"><span class="LC_nobreak">'.
4605: '<label><input type="radio" name="categorize"'.
4606: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4607: '<label><input type="radio" name="categorize"'.
4608: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4609: '</tr><tr class="LC_odd_row">'.
4610: '<td>'.$title{'togglecatscomm'}.'</td>'.
4611: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4612: '<input type="radio" name="togglecatscomm"'.
4613: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4614: '<label><input type="radio" name="togglecatscomm"'.
4615: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4616: '</tr><tr>'.
4617: '<td>'.$title{'categorizecomm'}.'</td>'.
4618: '<td class="LC_right_item"><span class="LC_nobreak">'.
4619: '<label><input type="radio" name="categorizecomm"'.
4620: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4621: '<label><input type="radio" name="categorizecomm"'.
4622: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4623: '</tr>';
1.120 raeburn 4624: $$rowtotal += 4;
1.57 raeburn 4625: } else {
4626: my $css_class;
4627: my $itemcount = 1;
4628: my $cathash;
4629: if (ref($settings) eq 'HASH') {
4630: $cathash = $settings->{'cats'};
4631: }
4632: if (ref($cathash) eq 'HASH') {
4633: my (@cats,@trails,%allitems,%idx,@jsarray);
4634: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4635: \%allitems,\%idx,\@jsarray);
4636: my $maxdepth = scalar(@cats);
4637: my $colattrib = '';
4638: if ($maxdepth > 2) {
4639: $colattrib = ' colspan="2" ';
4640: }
4641: my @path;
4642: if (@cats > 0) {
4643: if (ref($cats[0]) eq 'ARRAY') {
4644: my $numtop = @{$cats[0]};
4645: my $maxnum = $numtop;
1.120 raeburn 4646: my %default_names = (
4647: instcode => &mt('Official courses'),
4648: communities => &mt('Communities'),
4649: );
4650:
4651: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4652: ($cathash->{'instcode::0'} eq '') ||
4653: (!grep(/^communities$/,@{$cats[0]})) ||
4654: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4655: $maxnum ++;
4656: }
4657: my $lastidx;
4658: for (my $i=0; $i<$numtop; $i++) {
4659: my $parent = $cats[0][$i];
4660: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4661: my $item = &escape($parent).'::0';
4662: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4663: $lastidx = $idx{$item};
4664: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4665: .'<select name="'.$item.'"'.$chgstr.'>';
4666: for (my $k=0; $k<=$maxnum; $k++) {
4667: my $vpos = $k+1;
4668: my $selstr;
4669: if ($k == $i) {
4670: $selstr = ' selected="selected" ';
4671: }
4672: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4673: }
1.214 raeburn 4674: $datatable .= '</select></span></td><td>';
1.120 raeburn 4675: if ($parent eq 'instcode' || $parent eq 'communities') {
4676: $datatable .= '<span class="LC_nobreak">'
4677: .$default_names{$parent}.'</span>';
4678: if ($parent eq 'instcode') {
4679: $datatable .= '<br /><span class="LC_nobreak">('
4680: .&mt('with institutional codes')
4681: .')</span></td><td'.$colattrib.'>';
4682: } else {
4683: $datatable .= '<table><tr><td>';
4684: }
4685: $datatable .= '<span class="LC_nobreak">'
4686: .'<label><input type="radio" name="'
4687: .$parent.'" value="1" checked="checked" />'
4688: .&mt('Display').'</label>';
4689: if ($parent eq 'instcode') {
4690: $datatable .= ' ';
4691: } else {
4692: $datatable .= '</span></td></tr><tr><td>'
4693: .'<span class="LC_nobreak">';
4694: }
4695: $datatable .= '<label><input type="radio" name="'
4696: .$parent.'" value="0" />'
4697: .&mt('Do not display').'</label></span>';
4698: if ($parent eq 'communities') {
4699: $datatable .= '</td></tr></table>';
4700: }
4701: $datatable .= '</td>';
1.57 raeburn 4702: } else {
4703: $datatable .= $parent
1.214 raeburn 4704: .' <span class="LC_nobreak"><label>'
4705: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4706: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4707: }
4708: my $depth = 1;
4709: push(@path,$parent);
4710: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4711: pop(@path);
4712: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4713: $itemcount ++;
4714: }
1.48 raeburn 4715: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4716: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4717: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4718: for (my $k=0; $k<=$maxnum; $k++) {
4719: my $vpos = $k+1;
4720: my $selstr;
1.57 raeburn 4721: if ($k == $numtop) {
1.48 raeburn 4722: $selstr = ' selected="selected" ';
4723: }
4724: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4725: }
1.59 bisitz 4726: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4727: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4728: .'</tr>'."\n";
1.48 raeburn 4729: $itemcount ++;
1.120 raeburn 4730: foreach my $default ('instcode','communities') {
4731: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4732: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4733: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4734: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4735: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4736: for (my $k=0; $k<=$maxnum; $k++) {
4737: my $vpos = $k+1;
4738: my $selstr;
4739: if ($k == $maxnum) {
4740: $selstr = ' selected="selected" ';
4741: }
4742: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4743: }
1.120 raeburn 4744: $datatable .= '</select></span></td>'.
4745: '<td><span class="LC_nobreak">'.
4746: $default_names{$default}.'</span>';
4747: if ($default eq 'instcode') {
4748: $datatable .= '<br /><span class="LC_nobreak">('
4749: .&mt('with institutional codes').')</span>';
4750: }
4751: $datatable .= '</td>'
4752: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4753: .&mt('Display').'</label> '
4754: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4755: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4756: }
4757: }
4758: }
1.57 raeburn 4759: } else {
4760: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4761: }
4762: } else {
1.57 raeburn 4763: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4764: .&initialize_categories($itemcount);
1.48 raeburn 4765: }
1.57 raeburn 4766: $$rowtotal += $itemcount;
1.48 raeburn 4767: }
4768: return $datatable;
4769: }
4770:
1.69 raeburn 4771: sub print_serverstatuses {
4772: my ($dom,$settings,$rowtotal) = @_;
4773: my $datatable;
4774: my @pages = &serverstatus_pages();
4775: my (%namedaccess,%machineaccess);
4776: foreach my $type (@pages) {
4777: $namedaccess{$type} = '';
4778: $machineaccess{$type}= '';
4779: }
4780: if (ref($settings) eq 'HASH') {
4781: foreach my $type (@pages) {
4782: if (exists($settings->{$type})) {
4783: if (ref($settings->{$type}) eq 'HASH') {
4784: foreach my $key (keys(%{$settings->{$type}})) {
4785: if ($key eq 'namedusers') {
4786: $namedaccess{$type} = $settings->{$type}->{$key};
4787: } elsif ($key eq 'machines') {
4788: $machineaccess{$type} = $settings->{$type}->{$key};
4789: }
4790: }
4791: }
4792: }
4793: }
4794: }
1.81 raeburn 4795: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4796: my $rownum = 0;
4797: my $css_class;
4798: foreach my $type (@pages) {
4799: $rownum ++;
4800: $css_class = $rownum%2?' class="LC_odd_row"':'';
4801: $datatable .= '<tr'.$css_class.'>'.
4802: '<td><span class="LC_nobreak">'.
4803: $titles->{$type}.'</span></td>'.
4804: '<td class="LC_left_item">'.
4805: '<input type="text" name="'.$type.'_namedusers" '.
4806: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4807: '<td class="LC_right_item">'.
4808: '<span class="LC_nobreak">'.
4809: '<input type="text" name="'.$type.'_machines" '.
4810: 'value="'.$machineaccess{$type}.'" size="10" />'.
4811: '</td></tr>'."\n";
4812: }
4813: $$rowtotal += $rownum;
4814: return $datatable;
4815: }
4816:
4817: sub serverstatus_pages {
4818: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4819: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 4820: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 4821: 'uniquecodes','diskusage');
1.69 raeburn 4822: }
4823:
1.49 raeburn 4824: sub coursecategories_javascript {
4825: my ($settings) = @_;
1.57 raeburn 4826: my ($output,$jstext,$cathash);
1.49 raeburn 4827: if (ref($settings) eq 'HASH') {
1.57 raeburn 4828: $cathash = $settings->{'cats'};
4829: }
4830: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4831: my (@cats,@jsarray,%idx);
1.57 raeburn 4832: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4833: if (@jsarray > 0) {
4834: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4835: for (my $i=0; $i<@jsarray; $i++) {
4836: if (ref($jsarray[$i]) eq 'ARRAY') {
4837: my $catstr = join('","',@{$jsarray[$i]});
4838: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4839: }
4840: }
4841: }
4842: } else {
4843: $jstext = ' var categories = Array(1);'."\n".
4844: ' categories[0] = Array("instcode_pos");'."\n";
4845: }
1.120 raeburn 4846: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4847: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4848: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4849: $output = <<"ENDSCRIPT";
4850: <script type="text/javascript">
1.109 raeburn 4851: // <![CDATA[
1.49 raeburn 4852: function reorderCats(form,parent,item,idx) {
4853: var changedVal;
4854: $jstext
4855: var newpos = 'addcategory_pos';
4856: var current = new Array;
4857: if (parent == '') {
4858: var has_instcode = 0;
4859: var maxtop = categories[idx].length;
4860: for (var j=0; j<maxtop; j++) {
4861: if (categories[idx][j] == 'instcode::0') {
4862: has_instcode == 1;
4863: }
4864: }
4865: if (has_instcode == 0) {
4866: categories[idx][maxtop] = 'instcode_pos';
4867: }
4868: } else {
4869: newpos += '_'+parent;
4870: }
4871: var maxh = 1 + categories[idx].length;
4872: var current = new Array;
4873: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4874: if (item == newpos) {
4875: changedVal = newitemVal;
4876: } else {
4877: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4878: current[newitemVal] = newpos;
4879: }
4880: for (var i=0; i<categories[idx].length; i++) {
4881: var elementName = categories[idx][i];
4882: if (elementName != item) {
4883: if (form.elements[elementName]) {
4884: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4885: current[currVal] = elementName;
4886: }
4887: }
4888: }
4889: var oldVal;
4890: for (var j=0; j<maxh; j++) {
4891: if (current[j] == undefined) {
4892: oldVal = j;
4893: }
4894: }
4895: if (oldVal < changedVal) {
4896: for (var k=oldVal+1; k<=changedVal ; k++) {
4897: var elementName = current[k];
4898: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4899: }
4900: } else {
4901: for (var k=changedVal; k<oldVal; k++) {
4902: var elementName = current[k];
4903: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4904: }
4905: }
4906: return;
4907: }
1.120 raeburn 4908:
4909: function categoryCheck(form) {
4910: if (form.elements['addcategory_name'].value == 'instcode') {
4911: alert('$instcode_reserved\\n$choose_again');
4912: return false;
4913: }
4914: if (form.elements['addcategory_name'].value == 'communities') {
4915: alert('$communities_reserved\\n$choose_again');
4916: return false;
4917: }
4918: return true;
4919: }
4920:
1.109 raeburn 4921: // ]]>
1.49 raeburn 4922: </script>
4923:
4924: ENDSCRIPT
4925: return $output;
4926: }
4927:
1.48 raeburn 4928: sub initialize_categories {
4929: my ($itemcount) = @_;
1.120 raeburn 4930: my ($datatable,$css_class,$chgstr);
4931: my %default_names = (
4932: instcode => 'Official courses (with institutional codes)',
4933: communities => 'Communities',
4934: );
4935: my $select0 = ' selected="selected"';
4936: my $select1 = '';
4937: foreach my $default ('instcode','communities') {
4938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4939: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4940: if ($default eq 'communities') {
4941: $select1 = $select0;
4942: $select0 = '';
4943: }
4944: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4945: .'<select name="'.$default.'_pos">'
4946: .'<option value="0"'.$select0.'>1</option>'
4947: .'<option value="1"'.$select1.'>2</option>'
4948: .'<option value="2">3</option></select> '
4949: .$default_names{$default}
4950: .'</span></td><td><span class="LC_nobreak">'
4951: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4952: .&mt('Display').'</label> <label>'
4953: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4954: .'</label></span></td></tr>';
1.120 raeburn 4955: $itemcount ++;
4956: }
1.48 raeburn 4957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4958: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4959: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4960: .'<select name="addcategory_pos"'.$chgstr.'>'
4961: .'<option value="0">1</option>'
4962: .'<option value="1">2</option>'
4963: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4964: .&mt('Add category').'</td><td>'.&mt('Name:')
4965: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4966: return $datatable;
4967: }
4968:
4969: sub build_category_rows {
1.49 raeburn 4970: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4971: my ($text,$name,$item,$chgstr);
1.48 raeburn 4972: if (ref($cats) eq 'ARRAY') {
4973: my $maxdepth = scalar(@{$cats});
4974: if (ref($cats->[$depth]) eq 'HASH') {
4975: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4976: my $numchildren = @{$cats->[$depth]{$parent}};
4977: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4978: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4979: my ($idxnum,$parent_name,$parent_item);
4980: my $higher = $depth - 1;
4981: if ($higher == 0) {
4982: $parent_name = &escape($parent).'::'.$higher;
4983: } else {
4984: if (ref($path) eq 'ARRAY') {
4985: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4986: }
4987: }
4988: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4989: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4990: if ($j < $numchildren) {
1.48 raeburn 4991: $name = $cats->[$depth]{$parent}[$j];
4992: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4993: $idxnum = $idx->{$item};
4994: } else {
4995: $name = $parent_name;
4996: $item = $parent_item;
1.48 raeburn 4997: }
1.49 raeburn 4998: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4999: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5000: for (my $i=0; $i<=$numchildren; $i++) {
5001: my $vpos = $i+1;
5002: my $selstr;
5003: if ($j == $i) {
5004: $selstr = ' selected="selected" ';
5005: }
5006: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5007: }
5008: $text .= '</select> ';
5009: if ($j < $numchildren) {
5010: my $deeper = $depth+1;
5011: $text .= $name.' '
5012: .'<label><input type="checkbox" name="deletecategory" value="'
5013: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5014: if(ref($path) eq 'ARRAY') {
5015: push(@{$path},$name);
1.49 raeburn 5016: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5017: pop(@{$path});
5018: }
5019: } else {
1.59 bisitz 5020: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5021: if ($j == $numchildren) {
5022: $text .= $name;
5023: } else {
5024: $text .= $item;
5025: }
5026: $text .= '" value="" />';
5027: }
5028: $text .= '</td></tr>';
5029: }
5030: $text .= '</table></td>';
5031: } else {
5032: my $higher = $depth-1;
5033: if ($higher == 0) {
5034: $name = &escape($parent).'::'.$higher;
5035: } else {
5036: if (ref($path) eq 'ARRAY') {
5037: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5038: }
5039: }
5040: my $colspan;
5041: if ($parent ne 'instcode') {
5042: $colspan = $maxdepth - $depth - 1;
5043: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5044: }
5045: }
5046: }
5047: }
5048: return $text;
5049: }
5050:
1.33 raeburn 5051: sub modifiable_userdata_row {
1.228 raeburn 5052: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5053: my ($role,$rolename,$statustype);
5054: $role = $item;
1.224 raeburn 5055: if ($context eq 'cancreate') {
1.228 raeburn 5056: if ($item =~ /^emailusername_(.+)$/) {
5057: $statustype = $1;
5058: $role = 'emailusername';
5059: if (ref($usertypes) eq 'HASH') {
5060: if ($usertypes->{$statustype}) {
5061: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5062: } else {
5063: $rolename = &mt('Data provided by user');
5064: }
5065: }
1.224 raeburn 5066: }
5067: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5068: if (ref($usertypes) eq 'HASH') {
5069: $rolename = $usertypes->{$role};
5070: } else {
5071: $rolename = $role;
5072: }
1.33 raeburn 5073: } else {
1.63 raeburn 5074: if ($role eq 'cr') {
5075: $rolename = &mt('Custom role');
5076: } else {
5077: $rolename = &Apache::lonnet::plaintext($role);
5078: }
1.33 raeburn 5079: }
1.224 raeburn 5080: my (@fields,%fieldtitles);
5081: if (ref($fieldsref) eq 'ARRAY') {
5082: @fields = @{$fieldsref};
5083: } else {
5084: @fields = ('lastname','firstname','middlename','generation',
5085: 'permanentemail','id');
5086: }
5087: if ((ref($titlesref) eq 'HASH')) {
5088: %fieldtitles = %{$titlesref};
5089: } else {
5090: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5091: }
1.33 raeburn 5092: my $output;
5093: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5094: $output = '<tr '.$css_class.'>'.
5095: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5096: '<td class="LC_left_item" colspan="2"><table>';
5097: my $rem;
5098: my %checks;
5099: if (ref($settings) eq 'HASH') {
5100: if (ref($settings->{$context}) eq 'HASH') {
5101: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5102: my $hashref = $settings->{$context}->{$role};
5103: if ($role eq 'emailusername') {
5104: if ($statustype) {
5105: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5106: $hashref = $settings->{$context}->{$role}->{$statustype};
5107: if (ref($hashref) eq 'HASH') {
5108: foreach my $field (@fields) {
5109: if ($hashref->{$field}) {
5110: $checks{$field} = $hashref->{$field};
5111: }
5112: }
5113: }
5114: }
5115: }
5116: } else {
5117: if (ref($hashref) eq 'HASH') {
5118: foreach my $field (@fields) {
5119: if ($hashref->{$field}) {
5120: $checks{$field} = ' checked="checked" ';
5121: }
5122: }
1.33 raeburn 5123: }
5124: }
5125: }
5126: }
5127: }
1.228 raeburn 5128:
1.33 raeburn 5129: for (my $i=0; $i<@fields; $i++) {
5130: my $rem = $i%($numinrow);
5131: if ($rem == 0) {
5132: if ($i > 0) {
5133: $output .= '</tr>';
5134: }
5135: $output .= '<tr>';
5136: }
5137: my $check = ' ';
1.228 raeburn 5138: unless ($role eq 'emailusername') {
5139: if (exists($checks{$fields[$i]})) {
5140: $check = $checks{$fields[$i]}
5141: } else {
5142: if ($role eq 'st') {
5143: if (ref($settings) ne 'HASH') {
5144: $check = ' checked="checked" ';
5145: }
1.33 raeburn 5146: }
5147: }
5148: }
5149: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5150: '<span class="LC_nobreak">';
5151: if ($role eq 'emailusername') {
5152: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5153: $checks{$fields[$i]} = 'omit';
5154: }
5155: foreach my $option ('required','optional','omit') {
5156: my $checked='';
5157: if ($checks{$fields[$i]} eq $option) {
5158: $checked='checked="checked" ';
5159: }
5160: $output .= '<label>'.
5161: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5162: &mt($option).'</label>'.(' ' x2);
5163: }
5164: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5165: } else {
5166: $output .= '<label>'.
5167: '<input type="checkbox" name="canmodify_'.$role.'" '.
5168: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5169: '</label>';
5170: }
5171: $output .= '</span></td>';
1.33 raeburn 5172: $rem = @fields%($numinrow);
5173: }
5174: my $colsleft = $numinrow - $rem;
5175: if ($colsleft > 1 ) {
5176: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5177: ' </td>';
5178: } elsif ($colsleft == 1) {
5179: $output .= '<td class="LC_left_item"> </td>';
5180: }
5181: $output .= '</tr></table></td></tr>';
5182: return $output;
5183: }
1.28 raeburn 5184:
1.93 raeburn 5185: sub insttypes_row {
1.224 raeburn 5186: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5187: my %lt = &Apache::lonlocal::texthash (
5188: cansearch => 'Users allowed to search',
5189: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5190: lockablenames => 'User preference to lock name',
1.93 raeburn 5191: );
5192: my $showdom;
5193: if ($context eq 'cansearch') {
5194: $showdom = ' ('.$dom.')';
5195: }
1.165 raeburn 5196: my $class = 'LC_left_item';
5197: if ($context eq 'statustocreate') {
5198: $class = 'LC_right_item';
5199: }
1.224 raeburn 5200: my $css_class = ' class="LC_odd_row"';
5201: if ($rownum ne '') {
5202: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5203: }
5204: my $output = '<tr'.$css_class.'>'.
5205: '<td>'.$lt{$context}.$showdom.
5206: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5207: my $rem;
5208: if (ref($types) eq 'ARRAY') {
5209: for (my $i=0; $i<@{$types}; $i++) {
5210: if (defined($usertypes->{$types->[$i]})) {
5211: my $rem = $i%($numinrow);
5212: if ($rem == 0) {
5213: if ($i > 0) {
5214: $output .= '</tr>';
5215: }
5216: $output .= '<tr>';
1.23 raeburn 5217: }
1.26 raeburn 5218: my $check = ' ';
1.99 raeburn 5219: if (ref($settings) eq 'HASH') {
5220: if (ref($settings->{$context}) eq 'ARRAY') {
5221: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5222: $check = ' checked="checked" ';
5223: }
5224: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5225: $check = ' checked="checked" ';
5226: }
1.23 raeburn 5227: }
1.26 raeburn 5228: $output .= '<td class="LC_left_item">'.
5229: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5230: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5231: 'value="'.$types->[$i].'"'.$check.'/>'.
5232: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5233: }
5234: }
1.26 raeburn 5235: $rem = @{$types}%($numinrow);
1.23 raeburn 5236: }
5237: my $colsleft = $numinrow - $rem;
1.131 raeburn 5238: if (($rem == 0) && (@{$types} > 0)) {
5239: $output .= '<tr>';
5240: }
1.23 raeburn 5241: if ($colsleft > 1) {
1.25 raeburn 5242: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5243: } else {
1.25 raeburn 5244: $output .= '<td class="LC_left_item">';
1.23 raeburn 5245: }
5246: my $defcheck = ' ';
1.99 raeburn 5247: if (ref($settings) eq 'HASH') {
5248: if (ref($settings->{$context}) eq 'ARRAY') {
5249: if (grep(/^default$/,@{$settings->{$context}})) {
5250: $defcheck = ' checked="checked" ';
5251: }
5252: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5253: $defcheck = ' checked="checked" ';
5254: }
1.23 raeburn 5255: }
1.25 raeburn 5256: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5257: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5258: 'value="default"'.$defcheck.'/>'.
5259: $othertitle.'</label></span></td>'.
5260: '</tr></table></td></tr>';
5261: return $output;
1.23 raeburn 5262: }
5263:
5264: sub sorted_searchtitles {
5265: my %searchtitles = &Apache::lonlocal::texthash(
5266: 'uname' => 'username',
5267: 'lastname' => 'last name',
5268: 'lastfirst' => 'last name, first name',
5269: );
5270: my @titleorder = ('uname','lastname','lastfirst');
5271: return (\%searchtitles,\@titleorder);
5272: }
5273:
1.25 raeburn 5274: sub sorted_searchtypes {
5275: my %srchtypes_desc = (
5276: exact => 'is exact match',
5277: contains => 'contains ..',
5278: begins => 'begins with ..',
5279: );
5280: my @srchtypeorder = ('exact','begins','contains');
5281: return (\%srchtypes_desc,\@srchtypeorder);
5282: }
5283:
1.3 raeburn 5284: sub usertype_update_row {
5285: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5286: my $datatable;
5287: my $numinrow = 4;
5288: foreach my $type (@{$types}) {
5289: if (defined($usertypes->{$type})) {
5290: $$rownums ++;
5291: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5292: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5293: '</td><td class="LC_left_item"><table>';
5294: for (my $i=0; $i<@{$fields}; $i++) {
5295: my $rem = $i%($numinrow);
5296: if ($rem == 0) {
5297: if ($i > 0) {
5298: $datatable .= '</tr>';
5299: }
5300: $datatable .= '<tr>';
5301: }
5302: my $check = ' ';
1.39 raeburn 5303: if (ref($settings) eq 'HASH') {
5304: if (ref($settings->{'fields'}) eq 'HASH') {
5305: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5306: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5307: $check = ' checked="checked" ';
5308: }
1.3 raeburn 5309: }
5310: }
5311: }
5312:
5313: if ($i == @{$fields}-1) {
5314: my $colsleft = $numinrow - $rem;
5315: if ($colsleft > 1) {
5316: $datatable .= '<td colspan="'.$colsleft.'">';
5317: } else {
5318: $datatable .= '<td>';
5319: }
5320: } else {
5321: $datatable .= '<td>';
5322: }
1.8 raeburn 5323: $datatable .= '<span class="LC_nobreak"><label>'.
5324: '<input type="checkbox" name="updateable_'.$type.
5325: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5326: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5327: }
5328: $datatable .= '</tr></table></td></tr>';
5329: }
5330: }
5331: return $datatable;
1.1 raeburn 5332: }
5333:
5334: sub modify_login {
1.205 raeburn 5335: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5336: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5337: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5338: %title = ( coursecatalog => 'Display course catalog',
5339: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5340: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5341: newuser => 'Link for visitors to create a user account',
5342: loginheader => 'Log-in box header');
5343: @offon = ('off','on');
1.112 raeburn 5344: if (ref($domconfig{login}) eq 'HASH') {
5345: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5346: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5347: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5348: }
5349: }
5350: }
1.9 raeburn 5351: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5352: \%domconfig,\%loginhash);
1.188 raeburn 5353: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5354: foreach my $item (@toggles) {
5355: $loginhash{login}{$item} = $env{'form.'.$item};
5356: }
1.41 raeburn 5357: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5358: if (ref($colchanges{'login'}) eq 'HASH') {
5359: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5360: \%loginhash);
5361: }
1.110 raeburn 5362:
1.149 raeburn 5363: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5364: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5365: if (keys(%servers) > 1) {
5366: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5367: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5368: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5369: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5370: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5371: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5372: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5373: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5374: $changes{'loginvia'}{$lonhost} = 1;
5375: } else {
5376: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5377: $changes{'loginvia'}{$lonhost} = 1;
5378: }
5379: } else {
5380: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5381: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5382: $changes{'loginvia'}{$lonhost} = 1;
5383: }
5384: }
5385: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5386: foreach my $item (@loginvia_attribs) {
5387: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5388: }
5389: } else {
5390: foreach my $item (@loginvia_attribs) {
5391: my $new = $env{'form.'.$lonhost.'_'.$item};
5392: if (($item eq 'serverpath') && ($new eq 'custom')) {
5393: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5394: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5395: $new = '/';
5396: }
5397: }
5398: if (($item eq 'custompath') &&
5399: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5400: $new = '';
5401: }
5402: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5403: $changes{'loginvia'}{$lonhost} = 1;
5404: }
5405: if ($item eq 'exempt') {
5406: $new =~ s/^\s+//;
5407: $new =~ s/\s+$//;
5408: my @poss_ips = split(/\s*[,:]\s*/,$new);
5409: my @okips;
5410: foreach my $ip (@poss_ips) {
5411: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5412: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5413: push(@okips,$ip);
5414: }
5415: }
5416: }
5417: if (@okips > 0) {
5418: $new = join(',',@okips);
5419: } else {
5420: $new = '';
5421: }
5422: }
5423: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5424: }
5425: }
1.112 raeburn 5426: } else {
1.128 raeburn 5427: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5428: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5429: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5430: foreach my $item (@loginvia_attribs) {
5431: my $new = $env{'form.'.$lonhost.'_'.$item};
5432: if (($item eq 'serverpath') && ($new eq 'custom')) {
5433: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5434: $new = '/';
5435: }
5436: }
5437: if (($item eq 'custompath') &&
5438: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5439: $new = '';
5440: }
5441: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5442: }
1.110 raeburn 5443: }
5444: }
5445: }
5446: }
1.119 raeburn 5447:
1.168 raeburn 5448: my $servadm = $r->dir_config('lonAdmEMail');
5449: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5450: if (ref($domconfig{'login'}) eq 'HASH') {
5451: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5452: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5453: if ($lang eq 'nolang') {
5454: push(@currlangs,$lang);
5455: } elsif (defined($langchoices{$lang})) {
5456: push(@currlangs,$lang);
5457: } else {
5458: next;
5459: }
5460: }
5461: }
5462: }
5463: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5464: if (@currlangs > 0) {
5465: foreach my $lang (@currlangs) {
5466: if (grep(/^\Q$lang\E$/,@delurls)) {
5467: $changes{'helpurl'}{$lang} = 1;
5468: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5469: $changes{'helpurl'}{$lang} = 1;
5470: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5471: push(@newlangs,$lang);
5472: } else {
5473: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5474: }
5475: }
5476: }
5477: unless (grep(/^nolang$/,@currlangs)) {
5478: if ($env{'form.loginhelpurl_nolang.filename'}) {
5479: $changes{'helpurl'}{'nolang'} = 1;
5480: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5481: push(@newlangs,'nolang');
5482: }
5483: }
5484: if ($env{'form.loginhelpurl_add_lang'}) {
5485: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5486: ($env{'form.loginhelpurl_add_file.filename'})) {
5487: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5488: $addedfile = $env{'form.loginhelpurl_add_lang'};
5489: }
5490: }
5491: if ((@newlangs > 0) || ($addedfile)) {
5492: my $error;
5493: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5494: if ($configuserok eq 'ok') {
5495: if ($switchserver) {
5496: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5497: } elsif ($author_ok eq 'ok') {
5498: my @allnew = @newlangs;
5499: if ($addedfile ne '') {
5500: push(@allnew,$addedfile);
5501: }
5502: foreach my $lang (@allnew) {
5503: my $formelem = 'loginhelpurl_'.$lang;
5504: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5505: $formelem = 'loginhelpurl_add_file';
5506: }
5507: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5508: "help/$lang",'','',$newfile{$lang});
5509: if ($result eq 'ok') {
5510: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5511: $changes{'helpurl'}{$lang} = 1;
5512: } else {
5513: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5514: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5515: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5516: (!grep(/^\Q$lang\E$/,@delurls))) {
5517:
5518: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5519: }
5520: }
5521: }
5522: } else {
5523: $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);
5524: }
5525: } else {
5526: $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);
5527: }
5528: if ($error) {
5529: &Apache::lonnet::logthis($error);
5530: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5531: }
5532: }
1.169 raeburn 5533: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5534:
5535: my $defaulthelpfile = '/adm/loginproblems.html';
5536: my $defaulttext = &mt('Default in use');
5537:
1.1 raeburn 5538: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5539: $dom);
5540: if ($putresult eq 'ok') {
1.188 raeburn 5541: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5542: my %defaultchecked = (
5543: 'coursecatalog' => 'on',
1.188 raeburn 5544: 'helpdesk' => 'on',
1.42 raeburn 5545: 'adminmail' => 'off',
1.43 raeburn 5546: 'newuser' => 'off',
1.42 raeburn 5547: );
1.55 raeburn 5548: if (ref($domconfig{'login'}) eq 'HASH') {
5549: foreach my $item (@toggles) {
5550: if ($defaultchecked{$item} eq 'on') {
5551: if (($domconfig{'login'}{$item} eq '0') &&
5552: ($env{'form.'.$item} eq '1')) {
5553: $changes{$item} = 1;
5554: } elsif (($domconfig{'login'}{$item} eq '' ||
5555: $domconfig{'login'}{$item} eq '1') &&
5556: ($env{'form.'.$item} eq '0')) {
5557: $changes{$item} = 1;
5558: }
5559: } elsif ($defaultchecked{$item} eq 'off') {
5560: if (($domconfig{'login'}{$item} eq '1') &&
5561: ($env{'form.'.$item} eq '0')) {
5562: $changes{$item} = 1;
5563: } elsif (($domconfig{'login'}{$item} eq '' ||
5564: $domconfig{'login'}{$item} eq '0') &&
5565: ($env{'form.'.$item} eq '1')) {
5566: $changes{$item} = 1;
5567: }
1.42 raeburn 5568: }
5569: }
1.41 raeburn 5570: }
1.6 raeburn 5571: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5572: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5573: if (ref($lastactref) eq 'HASH') {
5574: $lastactref->{'domainconfig'} = 1;
5575: }
1.1 raeburn 5576: $resulttext = &mt('Changes made:').'<ul>';
5577: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5578: if ($item eq 'loginvia') {
1.112 raeburn 5579: if (ref($changes{$item}) eq 'HASH') {
5580: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5581: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5582: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5583: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5584: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5585: $protocol = 'http' if ($protocol ne 'https');
5586: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5587:
5588: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5589: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5590: } else {
5591: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5592: }
5593: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5594: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5595: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5596: }
5597: $resulttext .= '</li>';
5598: } else {
5599: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5600: }
1.112 raeburn 5601: } else {
1.128 raeburn 5602: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5603: }
5604: }
1.128 raeburn 5605: $resulttext .= '</ul></li>';
1.112 raeburn 5606: }
1.168 raeburn 5607: } elsif ($item eq 'helpurl') {
5608: if (ref($changes{$item}) eq 'HASH') {
5609: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5610: if (grep(/^\Q$lang\E$/,@delurls)) {
5611: my ($chg,$link);
5612: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5613: if ($lang eq 'nolang') {
5614: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5615: } else {
5616: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5617: }
5618: $resulttext .= '<li>'.$chg.'</li>';
5619: } else {
5620: my $chg;
5621: if ($lang eq 'nolang') {
5622: $chg = &mt('custom log-in help file for no preferred language');
5623: } else {
5624: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5625: }
5626: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5627: $loginhash{'login'}{'helpurl'}{$lang}.
5628: '?inhibitmenu=yes',$chg,600,500).
5629: '</li>';
5630: }
5631: }
5632: }
1.169 raeburn 5633: } elsif ($item eq 'captcha') {
5634: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5635: my $chgtxt;
1.169 raeburn 5636: if ($loginhash{'login'}{$item} eq 'notused') {
5637: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5638: } else {
5639: my %captchas = &captcha_phrases();
5640: if ($captchas{$loginhash{'login'}{$item}}) {
5641: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5642: } else {
5643: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5644: }
5645: }
5646: $resulttext .= '<li>'.$chgtxt.'</li>';
5647: }
5648: } elsif ($item eq 'recaptchakeys') {
5649: if (ref($loginhash{'login'}) eq 'HASH') {
5650: my ($privkey,$pubkey);
5651: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5652: $pubkey = $loginhash{'login'}{$item}{'public'};
5653: $privkey = $loginhash{'login'}{$item}{'private'};
5654: }
5655: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5656: if (!$pubkey) {
5657: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5658: } else {
5659: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5660: }
5661: if (!$privkey) {
5662: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5663: } else {
5664: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5665: }
5666: $chgtxt .= '</ul>';
5667: $resulttext .= '<li>'.$chgtxt.'</li>';
5668: }
1.41 raeburn 5669: } else {
5670: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5671: }
1.1 raeburn 5672: }
1.6 raeburn 5673: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5674: } else {
5675: $resulttext = &mt('No changes made to log-in page settings');
5676: }
5677: } else {
1.11 albertel 5678: $resulttext = '<span class="LC_error">'.
5679: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5680: }
1.6 raeburn 5681: if ($errors) {
1.9 raeburn 5682: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5683: $errors.'</ul>';
5684: }
5685: return $resulttext;
5686: }
5687:
5688: sub color_font_choices {
5689: my %choices =
5690: &Apache::lonlocal::texthash (
5691: img => "Header",
5692: bgs => "Background colors",
5693: links => "Link colors",
1.55 raeburn 5694: images => "Images",
1.6 raeburn 5695: font => "Font color",
1.201 raeburn 5696: fontmenu => "Font menu",
1.76 raeburn 5697: pgbg => "Page",
1.6 raeburn 5698: tabbg => "Header",
5699: sidebg => "Border",
5700: link => "Link",
5701: alink => "Active link",
5702: vlink => "Visited link",
5703: );
5704: return %choices;
5705: }
5706:
5707: sub modify_rolecolors {
1.205 raeburn 5708: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5709: my ($resulttext,%rolehash);
5710: $rolehash{'rolecolors'} = {};
1.55 raeburn 5711: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5712: if ($domconfig{'rolecolors'} eq '') {
5713: $domconfig{'rolecolors'} = {};
5714: }
5715: }
1.9 raeburn 5716: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5717: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5718: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5719: $dom);
5720: if ($putresult eq 'ok') {
5721: if (keys(%changes) > 0) {
1.41 raeburn 5722: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5723: if (ref($lastactref) eq 'HASH') {
5724: $lastactref->{'domainconfig'} = 1;
5725: }
1.6 raeburn 5726: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5727: $rolehash{'rolecolors'});
5728: } else {
5729: $resulttext = &mt('No changes made to default color schemes');
5730: }
5731: } else {
1.11 albertel 5732: $resulttext = '<span class="LC_error">'.
5733: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5734: }
5735: if ($errors) {
5736: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5737: $errors.'</ul>';
5738: }
5739: return $resulttext;
5740: }
5741:
5742: sub modify_colors {
1.9 raeburn 5743: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5744: my (%changes,%choices);
1.51 raeburn 5745: my @bgs;
1.6 raeburn 5746: my @links = ('link','alink','vlink');
1.41 raeburn 5747: my @logintext;
1.6 raeburn 5748: my @images;
5749: my $servadm = $r->dir_config('lonAdmEMail');
5750: my $errors;
1.200 raeburn 5751: my %defaults;
1.6 raeburn 5752: foreach my $role (@{$roles}) {
5753: if ($role eq 'login') {
1.12 raeburn 5754: %choices = &login_choices();
1.41 raeburn 5755: @logintext = ('textcol','bgcol');
1.12 raeburn 5756: } else {
5757: %choices = &color_font_choices();
5758: }
5759: if ($role eq 'login') {
1.41 raeburn 5760: @images = ('img','logo','domlogo','login');
1.51 raeburn 5761: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5762: } else {
5763: @images = ('img');
1.200 raeburn 5764: @bgs = ('pgbg','tabbg','sidebg');
5765: }
5766: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5767: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5768: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5769: }
5770: if ($role eq 'login') {
5771: foreach my $item (@logintext) {
5772: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5773: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5774: }
5775: }
5776: } else {
5777: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5778: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5779: }
1.6 raeburn 5780: }
1.200 raeburn 5781: foreach my $item (@bgs) {
5782: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5783: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5784: }
5785: }
5786: foreach my $item (@links) {
5787: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5788: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5789: }
1.6 raeburn 5790: }
1.46 raeburn 5791: my ($configuserok,$author_ok,$switchserver) =
5792: &config_check($dom,$confname,$servadm);
1.9 raeburn 5793: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5794: if (ref($domconfig->{$role}) ne 'HASH') {
5795: $domconfig->{$role} = {};
5796: }
1.8 raeburn 5797: foreach my $img (@images) {
1.70 raeburn 5798: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5799: if (defined($env{'form.login_showlogo_'.$img})) {
5800: $confhash->{$role}{'showlogo'}{$img} = 1;
5801: } else {
5802: $confhash->{$role}{'showlogo'}{$img} = 0;
5803: }
5804: }
1.18 albertel 5805: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5806: && !defined($domconfig->{$role}{$img})
5807: && !$env{'form.'.$role.'_del_'.$img}
5808: && $env{'form.'.$role.'_import_'.$img}) {
5809: # import the old configured image from the .tab setting
5810: # if they haven't provided a new one
5811: $domconfig->{$role}{$img} =
5812: $env{'form.'.$role.'_import_'.$img};
5813: }
1.6 raeburn 5814: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5815: my $error;
1.6 raeburn 5816: if ($configuserok eq 'ok') {
1.9 raeburn 5817: if ($switchserver) {
1.12 raeburn 5818: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5819: } else {
5820: if ($author_ok eq 'ok') {
5821: my ($result,$logourl) =
5822: &publishlogo($r,'upload',$role.'_'.$img,
5823: $dom,$confname,$img,$width,$height);
5824: if ($result eq 'ok') {
5825: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5826: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5827: } else {
1.12 raeburn 5828: $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 5829: }
5830: } else {
1.46 raeburn 5831: $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 5832: }
5833: }
5834: } else {
1.46 raeburn 5835: $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 5836: }
5837: if ($error) {
1.8 raeburn 5838: &Apache::lonnet::logthis($error);
1.11 albertel 5839: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5840: }
5841: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5842: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5843: my $error;
5844: if ($configuserok eq 'ok') {
5845: # is confname an author?
5846: if ($switchserver eq '') {
5847: if ($author_ok eq 'ok') {
5848: my ($result,$logourl) =
5849: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5850: $dom,$confname,$img,$width,$height);
5851: if ($result eq 'ok') {
5852: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5853: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5854: }
5855: }
5856: }
5857: }
1.6 raeburn 5858: }
5859: }
5860: }
5861: if (ref($domconfig) eq 'HASH') {
5862: if (ref($domconfig->{$role}) eq 'HASH') {
5863: foreach my $img (@images) {
5864: if ($domconfig->{$role}{$img} ne '') {
5865: if ($env{'form.'.$role.'_del_'.$img}) {
5866: $confhash->{$role}{$img} = '';
1.12 raeburn 5867: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5868: } else {
1.9 raeburn 5869: if ($confhash->{$role}{$img} eq '') {
5870: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5871: }
1.6 raeburn 5872: }
5873: } else {
5874: if ($env{'form.'.$role.'_del_'.$img}) {
5875: $confhash->{$role}{$img} = '';
1.12 raeburn 5876: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5877: }
5878: }
1.70 raeburn 5879: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5880: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5881: if ($confhash->{$role}{'showlogo'}{$img} ne
5882: $domconfig->{$role}{'showlogo'}{$img}) {
5883: $changes{$role}{'showlogo'}{$img} = 1;
5884: }
5885: } else {
5886: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5887: $changes{$role}{'showlogo'}{$img} = 1;
5888: }
5889: }
5890: }
5891: }
1.6 raeburn 5892: if ($domconfig->{$role}{'font'} ne '') {
5893: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5894: $changes{$role}{'font'} = 1;
5895: }
5896: } else {
5897: if ($confhash->{$role}{'font'}) {
5898: $changes{$role}{'font'} = 1;
5899: }
5900: }
1.107 raeburn 5901: if ($role ne 'login') {
5902: if ($domconfig->{$role}{'fontmenu'} ne '') {
5903: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5904: $changes{$role}{'fontmenu'} = 1;
5905: }
5906: } else {
5907: if ($confhash->{$role}{'fontmenu'}) {
5908: $changes{$role}{'fontmenu'} = 1;
5909: }
1.97 tempelho 5910: }
5911: }
1.6 raeburn 5912: foreach my $item (@bgs) {
5913: if ($domconfig->{$role}{$item} ne '') {
5914: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5915: $changes{$role}{'bgs'}{$item} = 1;
5916: }
5917: } else {
5918: if ($confhash->{$role}{$item}) {
5919: $changes{$role}{'bgs'}{$item} = 1;
5920: }
5921: }
5922: }
5923: foreach my $item (@links) {
5924: if ($domconfig->{$role}{$item} ne '') {
5925: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5926: $changes{$role}{'links'}{$item} = 1;
5927: }
5928: } else {
5929: if ($confhash->{$role}{$item}) {
5930: $changes{$role}{'links'}{$item} = 1;
5931: }
5932: }
5933: }
1.41 raeburn 5934: foreach my $item (@logintext) {
5935: if ($domconfig->{$role}{$item} ne '') {
5936: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5937: $changes{$role}{'logintext'}{$item} = 1;
5938: }
5939: } else {
5940: if ($confhash->{$role}{$item}) {
5941: $changes{$role}{'logintext'}{$item} = 1;
5942: }
5943: }
5944: }
1.6 raeburn 5945: } else {
5946: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5947: \@logintext,$confhash,\%changes);
1.6 raeburn 5948: }
5949: } else {
5950: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5951: \@logintext,$confhash,\%changes);
1.6 raeburn 5952: }
5953: }
5954: return ($errors,%changes);
5955: }
5956:
1.46 raeburn 5957: sub config_check {
5958: my ($dom,$confname,$servadm) = @_;
5959: my ($configuserok,$author_ok,$switchserver,%currroles);
5960: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5961: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5962: $confname,$servadm);
5963: if ($configuserok eq 'ok') {
5964: $switchserver = &check_switchserver($dom,$confname);
5965: if ($switchserver eq '') {
5966: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5967: }
5968: }
5969: return ($configuserok,$author_ok,$switchserver);
5970: }
5971:
1.6 raeburn 5972: sub default_change_checker {
1.41 raeburn 5973: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5974: foreach my $item (@{$links}) {
5975: if ($confhash->{$role}{$item}) {
5976: $changes->{$role}{'links'}{$item} = 1;
5977: }
5978: }
5979: foreach my $item (@{$bgs}) {
5980: if ($confhash->{$role}{$item}) {
5981: $changes->{$role}{'bgs'}{$item} = 1;
5982: }
5983: }
1.41 raeburn 5984: foreach my $item (@{$logintext}) {
5985: if ($confhash->{$role}{$item}) {
5986: $changes->{$role}{'logintext'}{$item} = 1;
5987: }
5988: }
1.6 raeburn 5989: foreach my $img (@{$images}) {
5990: if ($env{'form.'.$role.'_del_'.$img}) {
5991: $confhash->{$role}{$img} = '';
1.12 raeburn 5992: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5993: }
1.70 raeburn 5994: if ($role eq 'login') {
5995: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5996: $changes->{$role}{'showlogo'}{$img} = 1;
5997: }
5998: }
1.6 raeburn 5999: }
6000: if ($confhash->{$role}{'font'}) {
6001: $changes->{$role}{'font'} = 1;
6002: }
1.48 raeburn 6003: }
1.6 raeburn 6004:
6005: sub display_colorchgs {
6006: my ($dom,$changes,$roles,$confhash) = @_;
6007: my (%choices,$resulttext);
6008: if (!grep(/^login$/,@{$roles})) {
6009: $resulttext = &mt('Changes made:').'<br />';
6010: }
6011: foreach my $role (@{$roles}) {
6012: if ($role eq 'login') {
6013: %choices = &login_choices();
6014: } else {
6015: %choices = &color_font_choices();
6016: }
6017: if (ref($changes->{$role}) eq 'HASH') {
6018: if ($role ne 'login') {
6019: $resulttext .= '<h4>'.&mt($role).'</h4>';
6020: }
6021: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6022: if ($role ne 'login') {
6023: $resulttext .= '<ul>';
6024: }
6025: if (ref($changes->{$role}{$key}) eq 'HASH') {
6026: if ($role ne 'login') {
6027: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6028: }
6029: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6030: if (($role eq 'login') && ($key eq 'showlogo')) {
6031: if ($confhash->{$role}{$key}{$item}) {
6032: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6033: } else {
6034: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6035: }
6036: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6037: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6038: } else {
1.12 raeburn 6039: my $newitem = $confhash->{$role}{$item};
6040: if ($key eq 'images') {
6041: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6042: }
6043: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6044: }
6045: }
6046: if ($role ne 'login') {
6047: $resulttext .= '</ul></li>';
6048: }
6049: } else {
6050: if ($confhash->{$role}{$key} eq '') {
6051: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6052: } else {
6053: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6054: }
6055: }
6056: if ($role ne 'login') {
6057: $resulttext .= '</ul>';
6058: }
6059: }
6060: }
6061: }
1.3 raeburn 6062: return $resulttext;
1.1 raeburn 6063: }
6064:
1.9 raeburn 6065: sub thumb_dimensions {
6066: return ('200','50');
6067: }
6068:
1.16 raeburn 6069: sub check_dimensions {
6070: my ($inputfile) = @_;
6071: my ($fullwidth,$fullheight);
6072: if ($inputfile =~ m|^[/\w.\-]+$|) {
6073: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6074: my $imageinfo = <PIPE>;
6075: if (!close(PIPE)) {
6076: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6077: }
6078: chomp($imageinfo);
6079: my ($fullsize) =
1.21 raeburn 6080: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6081: if ($fullsize) {
6082: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6083: }
6084: }
6085: }
6086: return ($fullwidth,$fullheight);
6087: }
6088:
1.9 raeburn 6089: sub check_configuser {
6090: my ($uhome,$dom,$confname,$servadm) = @_;
6091: my ($configuserok,%currroles);
6092: if ($uhome eq 'no_host') {
6093: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6094: my $configpass = &LONCAPA::Enrollment::create_password();
6095: $configuserok =
6096: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6097: $configpass,'','','','','',undef,$servadm);
6098: } else {
6099: $configuserok = 'ok';
6100: %currroles =
6101: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6102: }
6103: return ($configuserok,%currroles);
6104: }
6105:
6106: sub check_authorstatus {
6107: my ($dom,$confname,%currroles) = @_;
6108: my $author_ok;
1.40 raeburn 6109: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6110: my $start = time;
6111: my $end = 0;
6112: $author_ok =
6113: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6114: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6115: } else {
6116: $author_ok = 'ok';
6117: }
6118: return $author_ok;
6119: }
6120:
6121: sub publishlogo {
1.46 raeburn 6122: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6123: my ($output,$fname,$logourl);
6124: if ($action eq 'upload') {
6125: $fname=$env{'form.'.$formname.'.filename'};
6126: chop($env{'form.'.$formname});
6127: } else {
6128: ($fname) = ($formname =~ /([^\/]+)$/);
6129: }
1.46 raeburn 6130: if ($savefileas ne '') {
6131: $fname = $savefileas;
6132: }
1.9 raeburn 6133: $fname=&Apache::lonnet::clean_filename($fname);
6134: # See if there is anything left
6135: unless ($fname) { return ('error: no uploaded file'); }
6136: $fname="$subdir/$fname";
1.210 raeburn 6137: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6138: my $filepath="$docroot/priv";
6139: my $relpath = "$dom/$confname";
1.9 raeburn 6140: my ($fnamepath,$file,$fetchthumb);
6141: $file=$fname;
6142: if ($fname=~m|/|) {
6143: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6144: }
1.164 raeburn 6145: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6146: my $count;
1.164 raeburn 6147: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6148: $filepath.="/$parts[$count]";
6149: if ((-e $filepath)!=1) {
6150: mkdir($filepath,02770);
6151: }
6152: }
6153: # Check for bad extension and disallow upload
6154: if ($file=~/\.(\w+)$/ &&
6155: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6156: $output =
1.207 bisitz 6157: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6158: } elsif ($file=~/\.(\w+)$/ &&
6159: !defined(&Apache::loncommon::fileembstyle($1))) {
6160: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6161: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6162: $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 6163: } elsif (-d "$filepath/$file") {
1.195 bisitz 6164: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6165: } else {
6166: my $source = $filepath.'/'.$file;
6167: my $logfile;
6168: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6169: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6170: }
6171: print $logfile
6172: "\n================= Publish ".localtime()." ================\n".
6173: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6174: # Save the file
6175: if (!open(FH,'>'.$source)) {
6176: &Apache::lonnet::logthis('Failed to create '.$source);
6177: return (&mt('Failed to create file'));
6178: }
6179: if ($action eq 'upload') {
6180: if (!print FH ($env{'form.'.$formname})) {
6181: &Apache::lonnet::logthis('Failed to write to '.$source);
6182: return (&mt('Failed to write file'));
6183: }
6184: } else {
6185: my $original = &Apache::lonnet::filelocation('',$formname);
6186: if(!copy($original,$source)) {
6187: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6188: return (&mt('Failed to write file'));
6189: }
6190: }
6191: close(FH);
6192: chmod(0660, $source); # Permissions to rw-rw---.
6193:
6194: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6195: my $copyfile=$targetdir.'/'.$file;
6196:
6197: my @parts=split(/\//,$targetdir);
6198: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6199: for (my $count=5;$count<=$#parts;$count++) {
6200: $path.="/$parts[$count]";
6201: if (!-e $path) {
6202: print $logfile "\nCreating directory ".$path;
6203: mkdir($path,02770);
6204: }
6205: }
6206: my $versionresult;
6207: if (-e $copyfile) {
6208: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6209: } else {
6210: $versionresult = 'ok';
6211: }
6212: if ($versionresult eq 'ok') {
6213: if (copy($source,$copyfile)) {
6214: print $logfile "\nCopied original source to ".$copyfile."\n";
6215: $output = 'ok';
6216: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6217: push(@{$modified_urls},[$copyfile,$source]);
6218: my $metaoutput =
6219: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6220: unless ($registered_cleanup) {
6221: my $handlers = $r->get_handlers('PerlCleanupHandler');
6222: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6223: $registered_cleanup=1;
6224: }
1.9 raeburn 6225: } else {
6226: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6227: $output = &mt('Failed to copy file to RES space').", $!";
6228: }
6229: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6230: my $inputfile = $filepath.'/'.$file;
6231: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6232: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6233: if ($fullwidth ne '' && $fullheight ne '') {
6234: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6235: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6236: system("convert -sample $thumbsize $inputfile $outfile");
6237: chmod(0660, $filepath.'/tn-'.$file);
6238: if (-e $outfile) {
6239: my $copyfile=$targetdir.'/tn-'.$file;
6240: if (copy($outfile,$copyfile)) {
6241: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6242: my $thumb_metaoutput =
6243: &write_metadata($dom,$confname,$formname,
6244: $targetdir,'tn-'.$file,$logfile);
6245: push(@{$modified_urls},[$copyfile,$outfile]);
6246: unless ($registered_cleanup) {
6247: my $handlers = $r->get_handlers('PerlCleanupHandler');
6248: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6249: $registered_cleanup=1;
6250: }
1.16 raeburn 6251: } else {
6252: print $logfile "\nUnable to write ".$copyfile.
6253: ':'.$!."\n";
6254: }
6255: }
1.9 raeburn 6256: }
6257: }
6258: }
6259: } else {
6260: $output = $versionresult;
6261: }
6262: }
6263: return ($output,$logourl);
6264: }
6265:
6266: sub logo_versioning {
6267: my ($targetdir,$file,$logfile) = @_;
6268: my $target = $targetdir.'/'.$file;
6269: my ($maxversion,$fn,$extn,$output);
6270: $maxversion = 0;
6271: if ($file =~ /^(.+)\.(\w+)$/) {
6272: $fn=$1;
6273: $extn=$2;
6274: }
6275: opendir(DIR,$targetdir);
6276: while (my $filename=readdir(DIR)) {
6277: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6278: $maxversion=($1>$maxversion)?$1:$maxversion;
6279: }
6280: }
6281: $maxversion++;
6282: print $logfile "\nCreating old version ".$maxversion."\n";
6283: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6284: if (copy($target,$copyfile)) {
6285: print $logfile "Copied old target to ".$copyfile."\n";
6286: $copyfile=$copyfile.'.meta';
6287: if (copy($target.'.meta',$copyfile)) {
6288: print $logfile "Copied old target metadata to ".$copyfile."\n";
6289: $output = 'ok';
6290: } else {
6291: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6292: $output = &mt('Failed to copy old meta').", $!, ";
6293: }
6294: } else {
6295: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6296: $output = &mt('Failed to copy old target').", $!, ";
6297: }
6298: return $output;
6299: }
6300:
6301: sub write_metadata {
6302: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6303: my (%metadatafields,%metadatakeys,$output);
6304: $metadatafields{'title'}=$formname;
6305: $metadatafields{'creationdate'}=time;
6306: $metadatafields{'lastrevisiondate'}=time;
6307: $metadatafields{'copyright'}='public';
6308: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6309: $env{'user.domain'};
6310: $metadatafields{'authorspace'}=$confname.':'.$dom;
6311: $metadatafields{'domain'}=$dom;
6312: {
6313: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6314: my $mfh;
1.155 raeburn 6315: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6316: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6317: unless ($_=~/\./) {
6318: my $unikey=$_;
6319: $unikey=~/^([A-Za-z]+)/;
6320: my $tag=$1;
6321: $tag=~tr/A-Z/a-z/;
6322: print $mfh "\n\<$tag";
6323: foreach (split(/\,/,$metadatakeys{$unikey})) {
6324: my $value=$metadatafields{$unikey.'.'.$_};
6325: $value=~s/\"/\'\'/g;
6326: print $mfh ' '.$_.'="'.$value.'"';
6327: }
6328: print $mfh '>'.
6329: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6330: .'</'.$tag.'>';
6331: }
6332: }
6333: $output = 'ok';
6334: print $logfile "\nWrote metadata";
6335: close($mfh);
6336: } else {
6337: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6338: $output = &mt('Could not write metadata');
6339: }
6340: }
1.155 raeburn 6341: return $output;
6342: }
6343:
6344: sub notifysubscribed {
6345: foreach my $targetsource (@{$modified_urls}){
6346: next unless (ref($targetsource) eq 'ARRAY');
6347: my ($target,$source)=@{$targetsource};
6348: if ($source ne '') {
6349: if (open(my $logfh,'>>'.$source.'.log')) {
6350: print $logfh "\nCleanup phase: Notifications\n";
6351: my @subscribed=&subscribed_hosts($target);
6352: foreach my $subhost (@subscribed) {
6353: print $logfh "\nNotifying host ".$subhost.':';
6354: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6355: print $logfh $reply;
6356: }
6357: my @subscribedmeta=&subscribed_hosts("$target.meta");
6358: foreach my $subhost (@subscribedmeta) {
6359: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6360: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6361: $subhost);
6362: print $logfh $reply;
6363: }
6364: print $logfh "\n============ Done ============\n";
1.160 raeburn 6365: close($logfh);
1.155 raeburn 6366: }
6367: }
6368: }
6369: return OK;
6370: }
6371:
6372: sub subscribed_hosts {
6373: my ($target) = @_;
6374: my @subscribed;
6375: if (open(my $fh,"<$target.subscription")) {
6376: while (my $subline=<$fh>) {
6377: if ($subline =~ /^($match_lonid):/) {
6378: my $host = $1;
6379: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6380: unless (grep(/^\Q$host\E$/,@subscribed)) {
6381: push(@subscribed,$host);
6382: }
6383: }
6384: }
6385: }
6386: }
6387: return @subscribed;
1.9 raeburn 6388: }
6389:
6390: sub check_switchserver {
6391: my ($dom,$confname) = @_;
6392: my ($allowed,$switchserver);
6393: my $home = &Apache::lonnet::homeserver($confname,$dom);
6394: if ($home eq 'no_host') {
6395: $home = &Apache::lonnet::domain($dom,'primary');
6396: }
6397: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6398: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6399: if (!$allowed) {
1.180 raeburn 6400: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6401: }
6402: return $switchserver;
6403: }
6404:
1.1 raeburn 6405: sub modify_quotas {
1.216 raeburn 6406: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6407: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6408: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
6409: $author_ok,$switchserver,$errors);
1.86 raeburn 6410: if ($action eq 'quotas') {
6411: $context = 'tools';
1.163 raeburn 6412: } else {
1.86 raeburn 6413: $context = $action;
6414: }
6415: if ($context eq 'requestcourses') {
1.216 raeburn 6416: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6417: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6418: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6419: %titles = &courserequest_titles();
6420: $toolregexp = join('|',@usertools);
6421: %conditions = &courserequest_conditions();
1.216 raeburn 6422: $confname = $dom.'-domainconfig';
6423: my $servadm = $r->dir_config('lonAdmEMail');
6424: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163 raeburn 6425: } elsif ($context eq 'requestauthor') {
6426: @usertools = ('author');
6427: %titles = &authorrequest_titles();
1.86 raeburn 6428: } else {
1.162 raeburn 6429: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6430: %titles = &tool_titles();
1.86 raeburn 6431: }
1.212 raeburn 6432: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6433: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6434: foreach my $key (keys(%env)) {
1.101 raeburn 6435: if ($context eq 'requestcourses') {
6436: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6437: my $item = $1;
6438: my $type = $2;
6439: if ($type =~ /^limit_(.+)/) {
6440: $limithash{$item}{$1} = $env{$key};
6441: } else {
6442: $confhash{$item}{$type} = $env{$key};
6443: }
6444: }
1.163 raeburn 6445: } elsif ($context eq 'requestauthor') {
6446: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6447: $confhash{$1} = $env{$key};
6448: }
1.101 raeburn 6449: } else {
1.86 raeburn 6450: if ($key =~ /^form\.quota_(.+)$/) {
6451: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6452: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6453: $confhash{'authorquota'}{$1} = $env{$key};
6454: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6455: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6456: }
1.72 raeburn 6457: }
6458: }
1.163 raeburn 6459: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6460: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6461: @approvalnotify = sort(@approvalnotify);
6462: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6463: my @crstypes = ('official','unofficial','community','textbook');
6464: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6465: foreach my $type (@hasuniquecode) {
6466: if (grep(/^\Q$type\E$/,@crstypes)) {
6467: $confhash{'uniquecode'}{$type} = 1;
6468: }
1.216 raeburn 6469: }
6470: my ($newbook,@allpos);
6471: if ($context eq 'requestcourses') {
6472: if ($env{'form.addbook'}) {
6473: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6474: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6475: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6476: $env{'form.addbook_cdom'}) eq 'no_host') {
6477: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6478: '</span></li>';
6479: } else {
6480: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6481: my $position = $env{'form.addbook_pos'};
6482: $position =~ s/\D+//g;
6483: if ($position ne '') {
6484: $allpos[$position] = $newbook;
6485: }
6486: }
6487: } else {
6488: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6489: '</span></li>';
6490: }
6491: }
6492: }
1.102 raeburn 6493: if (ref($domconfig{$action}) eq 'HASH') {
6494: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6495: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6496: $changes{'notify'}{'approval'} = 1;
6497: }
6498: } else {
1.144 raeburn 6499: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6500: $changes{'notify'}{'approval'} = 1;
6501: }
6502: }
1.218 raeburn 6503: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6504: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6505: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6506: unless ($confhash{'uniquecode'}{$crstype}) {
6507: $changes{'uniquecode'} = 1;
6508: }
6509: }
6510: unless ($changes{'uniquecode'}) {
6511: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6512: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6513: $changes{'uniquecode'} = 1;
6514: }
6515: }
6516: }
6517: } else {
6518: $changes{'uniquecode'} = 1;
6519: }
6520: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6521: $changes{'uniquecode'} = 1;
1.216 raeburn 6522: }
6523: if ($context eq 'requestcourses') {
6524: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6525: my %deletions;
6526: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6527: if (@todelete) {
6528: map { $deletions{$_} = 1; } @todelete;
6529: }
6530: my %imgdeletions;
6531: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6532: if (@todeleteimages) {
6533: map { $imgdeletions{$_} = 1; } @todeleteimages;
6534: }
6535: my $maxnum = $env{'form.book_maxnum'};
6536: for (my $i=0; $i<=$maxnum; $i++) {
6537: my $key = $env{'form.book_id_'.$i};
6538: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6539: if ($deletions{$key}) {
6540: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6541: #FIXME need to obsolete item in RES space
6542: }
6543: next;
6544: } else {
6545: my $newpos = $env{'form.'.$key};
6546: $newpos =~ s/\D+//g;
6547: foreach my $item ('subject','title','author') {
6548: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6549: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6550: $changes{'textbooks'}{$key} = 1;
6551: }
6552: }
6553: $allpos[$newpos] = $key;
6554: }
6555: if ($imgdeletions{$key}) {
6556: $changes{'textbooks'}{$key} = 1;
6557: #FIXME need to obsolete item in RES space
6558: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6559: my ($cdom,$cnum) = split(/_/,$key);
6560: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6561: $cdom,$cnum,$configuserok,
6562: $switchserver,$author_ok);
6563: if ($imgurl) {
6564: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6565: $changes{'textbooks'}{$key} = 1;
6566: }
6567: if ($error) {
6568: &Apache::lonnet::logthis($error);
6569: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6570: }
6571: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6572: $confhash{'textbooks'}{$key}{'image'} =
6573: $domconfig{$action}{'textbooks'}{$key}{'image'};
6574: }
6575: }
6576: }
6577: }
6578: }
1.102 raeburn 6579: } else {
1.144 raeburn 6580: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6581: $changes{'notify'}{'approval'} = 1;
6582: }
1.218 raeburn 6583: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6584: $changes{'uniquecode'} = 1;
6585: }
6586: }
6587: if ($context eq 'requestcourses') {
6588: if ($newbook) {
6589: $changes{'textbooks'}{$newbook} = 1;
6590: foreach my $item ('subject','title','author') {
6591: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6592: if ($env{'form.addbook_'.$item}) {
6593: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6594: }
6595: }
6596: if ($env{'form.addbook_image.filename'} ne '') {
6597: my ($cdom,$cnum) = split(/_/,$newbook);
6598: my ($imageurl,$error) =
6599: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6600: $switchserver,$author_ok);
6601: if ($imageurl) {
6602: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6603: }
6604: if ($error) {
6605: &Apache::lonnet::logthis($error);
6606: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6607: }
6608: }
6609: }
6610: if (@allpos > 0) {
6611: my $idx = 0;
6612: foreach my $item (@allpos) {
6613: if ($item ne '') {
6614: $confhash{'textbooks'}{$item}{'order'} = $idx;
6615: if (ref($domconfig{$action}) eq 'HASH') {
6616: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6617: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6618: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6619: $changes{'textbooks'}{$item} = 1;
6620: }
6621: }
6622: }
6623: }
6624: $idx ++;
6625: }
6626: }
6627: }
1.102 raeburn 6628: }
6629: } else {
1.86 raeburn 6630: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6631: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6632: }
1.72 raeburn 6633: foreach my $item (@usertools) {
6634: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6635: my $unset;
1.101 raeburn 6636: if ($context eq 'requestcourses') {
1.104 raeburn 6637: $unset = '0';
6638: if ($type eq '_LC_adv') {
6639: $unset = '';
6640: }
1.101 raeburn 6641: if ($confhash{$item}{$type} eq 'autolimit') {
6642: $confhash{$item}{$type} .= '=';
6643: unless ($limithash{$item}{$type} =~ /\D/) {
6644: $confhash{$item}{$type} .= $limithash{$item}{$type};
6645: }
6646: }
1.163 raeburn 6647: } elsif ($context eq 'requestauthor') {
6648: $unset = '0';
6649: if ($type eq '_LC_adv') {
6650: $unset = '';
6651: }
1.72 raeburn 6652: } else {
1.101 raeburn 6653: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6654: $confhash{$item}{$type} = 1;
6655: } else {
6656: $confhash{$item}{$type} = 0;
6657: }
1.72 raeburn 6658: }
1.86 raeburn 6659: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6660: if ($action eq 'requestauthor') {
6661: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6662: $changes{$type} = 1;
6663: }
6664: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6665: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6666: $changes{$item}{$type} = 1;
6667: }
6668: } else {
6669: if ($context eq 'requestcourses') {
1.104 raeburn 6670: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6671: $changes{$item}{$type} = 1;
6672: }
6673: } else {
6674: if (!$confhash{$item}{$type}) {
6675: $changes{$item}{$type} = 1;
6676: }
6677: }
6678: }
6679: } else {
6680: if ($context eq 'requestcourses') {
1.104 raeburn 6681: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6682: $changes{$item}{$type} = 1;
6683: }
1.163 raeburn 6684: } elsif ($context eq 'requestauthor') {
6685: if ($confhash{$type} ne $unset) {
6686: $changes{$type} = 1;
6687: }
1.72 raeburn 6688: } else {
6689: if (!$confhash{$item}{$type}) {
6690: $changes{$item}{$type} = 1;
6691: }
6692: }
6693: }
1.1 raeburn 6694: }
6695: }
1.163 raeburn 6696: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6697: if (ref($domconfig{'quotas'}) eq 'HASH') {
6698: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6699: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6700: if (exists($confhash{'defaultquota'}{$key})) {
6701: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6702: $changes{'defaultquota'}{$key} = 1;
6703: }
6704: } else {
6705: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6706: }
6707: }
1.86 raeburn 6708: } else {
6709: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6710: if (exists($confhash{'defaultquota'}{$key})) {
6711: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6712: $changes{'defaultquota'}{$key} = 1;
6713: }
6714: } else {
6715: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6716: }
1.1 raeburn 6717: }
6718: }
1.197 raeburn 6719: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6720: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6721: if (exists($confhash{'authorquota'}{$key})) {
6722: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6723: $changes{'authorquota'}{$key} = 1;
6724: }
6725: } else {
6726: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6727: }
6728: }
6729: }
1.1 raeburn 6730: }
1.86 raeburn 6731: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6732: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6733: if (ref($domconfig{'quotas'}) eq 'HASH') {
6734: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6735: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6736: $changes{'defaultquota'}{$key} = 1;
6737: }
6738: } else {
6739: if (!exists($domconfig{'quotas'}{$key})) {
6740: $changes{'defaultquota'}{$key} = 1;
6741: }
1.72 raeburn 6742: }
6743: } else {
1.86 raeburn 6744: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6745: }
1.1 raeburn 6746: }
6747: }
1.197 raeburn 6748: if (ref($confhash{'authorquota'}) eq 'HASH') {
6749: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6750: if (ref($domconfig{'quotas'}) eq 'HASH') {
6751: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6752: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6753: $changes{'authorquota'}{$key} = 1;
6754: }
6755: } else {
6756: $changes{'authorquota'}{$key} = 1;
6757: }
6758: } else {
6759: $changes{'authorquota'}{$key} = 1;
6760: }
6761: }
6762: }
1.1 raeburn 6763: }
1.72 raeburn 6764:
1.163 raeburn 6765: if ($context eq 'requestauthor') {
6766: $domdefaults{'requestauthor'} = \%confhash;
6767: } else {
6768: foreach my $key (keys(%confhash)) {
1.216 raeburn 6769: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6770: $domdefaults{$key} = $confhash{$key};
6771: }
1.163 raeburn 6772: }
1.72 raeburn 6773: }
1.163 raeburn 6774:
1.1 raeburn 6775: my %quotahash = (
1.86 raeburn 6776: $action => { %confhash }
1.1 raeburn 6777: );
6778: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6779: $dom);
6780: if ($putresult eq 'ok') {
6781: if (keys(%changes) > 0) {
1.72 raeburn 6782: my $cachetime = 24*60*60;
6783: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6784: if (ref($lastactref) eq 'HASH') {
6785: $lastactref->{'domdefaults'} = 1;
6786: }
1.1 raeburn 6787: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6788: unless (($context eq 'requestcourses') ||
1.163 raeburn 6789: ($context eq 'requestauthor')) {
1.86 raeburn 6790: if (ref($changes{'defaultquota'}) eq 'HASH') {
6791: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6792: foreach my $type (@{$types},'default') {
6793: if (defined($changes{'defaultquota'}{$type})) {
6794: my $typetitle = $usertypes->{$type};
6795: if ($type eq 'default') {
6796: $typetitle = $othertitle;
6797: }
1.213 raeburn 6798: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6799: }
6800: }
1.86 raeburn 6801: $resulttext .= '</ul></li>';
1.72 raeburn 6802: }
1.197 raeburn 6803: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 6804: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 6805: foreach my $type (@{$types},'default') {
6806: if (defined($changes{'authorquota'}{$type})) {
6807: my $typetitle = $usertypes->{$type};
6808: if ($type eq 'default') {
6809: $typetitle = $othertitle;
6810: }
1.213 raeburn 6811: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6812: }
6813: }
6814: $resulttext .= '</ul></li>';
6815: }
1.72 raeburn 6816: }
1.80 raeburn 6817: my %newenv;
1.72 raeburn 6818: foreach my $item (@usertools) {
1.163 raeburn 6819: my (%haschgs,%inconf);
6820: if ($context eq 'requestauthor') {
6821: %haschgs = %changes;
1.210 raeburn 6822: %inconf = %confhash;
1.163 raeburn 6823: } else {
6824: if (ref($changes{$item}) eq 'HASH') {
6825: %haschgs = %{$changes{$item}};
6826: }
6827: if (ref($confhash{$item}) eq 'HASH') {
6828: %inconf = %{$confhash{$item}};
6829: }
6830: }
6831: if (keys(%haschgs) > 0) {
1.80 raeburn 6832: my $newacc =
6833: &Apache::lonnet::usertools_access($env{'user.name'},
6834: $env{'user.domain'},
1.86 raeburn 6835: $item,'reload',$context);
1.210 raeburn 6836: if (($context eq 'requestcourses') ||
1.163 raeburn 6837: ($context eq 'requestauthor')) {
1.108 raeburn 6838: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6839: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6840: }
6841: } else {
6842: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6843: $newenv{'environment.availabletools.'.$item} = $newacc;
6844: }
1.80 raeburn 6845: }
1.163 raeburn 6846: unless ($context eq 'requestauthor') {
6847: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6848: }
1.72 raeburn 6849: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6850: if ($haschgs{$type}) {
1.72 raeburn 6851: my $typetitle = $usertypes->{$type};
6852: if ($type eq 'default') {
6853: $typetitle = $othertitle;
6854: } elsif ($type eq '_LC_adv') {
6855: $typetitle = 'LON-CAPA Advanced Users';
6856: }
1.163 raeburn 6857: if ($inconf{$type}) {
1.101 raeburn 6858: if ($context eq 'requestcourses') {
6859: my $cond;
1.163 raeburn 6860: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6861: if ($1 eq '') {
6862: $cond = &mt('(Automatic processing of any request).');
6863: } else {
6864: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6865: }
6866: } else {
1.163 raeburn 6867: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6868: }
6869: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6870: } elsif ($context eq 'requestauthor') {
6871: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6872: $titles{$inconf{$type}},$typetitle);
6873:
1.101 raeburn 6874: } else {
6875: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6876: }
1.72 raeburn 6877: } else {
1.104 raeburn 6878: if ($type eq '_LC_adv') {
1.163 raeburn 6879: if ($inconf{$type} eq '0') {
1.104 raeburn 6880: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6881: } else {
6882: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6883: }
6884: } else {
6885: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6886: }
1.72 raeburn 6887: }
6888: }
1.26 raeburn 6889: }
1.163 raeburn 6890: unless ($context eq 'requestauthor') {
6891: $resulttext .= '</ul></li>';
6892: }
1.26 raeburn 6893: }
1.1 raeburn 6894: }
1.163 raeburn 6895: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6896: if (ref($changes{'notify'}) eq 'HASH') {
6897: if ($changes{'notify'}{'approval'}) {
6898: if (ref($confhash{'notify'}) eq 'HASH') {
6899: if ($confhash{'notify'}{'approval'}) {
6900: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6901: } else {
1.163 raeburn 6902: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6903: }
6904: }
6905: }
6906: }
6907: }
1.216 raeburn 6908: if ($action eq 'requestcourses') {
6909: my @offon = ('off','on');
6910: if ($changes{'uniquecode'}) {
1.218 raeburn 6911: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6912: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
6913: $resulttext .= '<li>'.
6914: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
6915: '</li>';
6916: } else {
6917: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
6918: '</li>';
6919: }
1.216 raeburn 6920: }
6921: if (ref($changes{'textbooks'}) eq 'HASH') {
6922: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
6923: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
6924: my %coursehash = &Apache::lonnet::coursedescription($key);
6925: my $coursetitle = $coursehash{'description'};
6926: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
6927: $resulttext .= '<li>';
6928: foreach my $item ('subject','title','author') {
6929: my $name = $item.':';
6930: $name =~ s/^(\w)/\U$1/;
6931: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
6932: }
6933: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
6934: if ($confhash{'textbooks'}{$key}{'image'}) {
6935: $resulttext .= ' '.&mt('Image: [_1]',
6936: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
6937: ' alt="Textbook cover" />').'<br />';
6938: }
6939: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
6940: }
6941: $resulttext .= '</ul></li>';
6942: }
6943: }
1.1 raeburn 6944: $resulttext .= '</ul>';
1.80 raeburn 6945: if (keys(%newenv)) {
6946: &Apache::lonnet::appenv(\%newenv);
6947: }
1.1 raeburn 6948: } else {
1.86 raeburn 6949: if ($context eq 'requestcourses') {
6950: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6951: } elsif ($context eq 'requestauthor') {
6952: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6953: } else {
1.90 weissno 6954: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6955: }
1.1 raeburn 6956: }
6957: } else {
1.11 albertel 6958: $resulttext = '<span class="LC_error">'.
6959: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6960: }
1.216 raeburn 6961: if ($errors) {
6962: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
6963: '<ul>'.$errors.'</ul></p>';
6964: }
1.3 raeburn 6965: return $resulttext;
1.1 raeburn 6966: }
6967:
1.216 raeburn 6968: sub process_textbook_image {
6969: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
6970: my $filename = $env{'form.'.$caller.'.filename'};
6971: my ($error,$url);
6972: my ($width,$height) = (50,50);
6973: if ($configuserok eq 'ok') {
6974: if ($switchserver) {
6975: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
6976: $switchserver);
6977: } elsif ($author_ok eq 'ok') {
6978: my ($result,$imageurl) =
6979: &publishlogo($r,'upload',$caller,$dom,$confname,
6980: "textbooks/$dom/$cnum/cover",$width,$height);
6981: if ($result eq 'ok') {
6982: $url = $imageurl;
6983: } else {
6984: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
6985: }
6986: } else {
6987: $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);
6988: }
6989: } else {
6990: $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);
6991: }
6992: return ($url,$error);
6993: }
6994:
1.3 raeburn 6995: sub modify_autoenroll {
1.205 raeburn 6996: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6997: my ($resulttext,%changes);
6998: my %currautoenroll;
6999: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7000: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7001: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7002: }
7003: }
7004: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7005: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7006: sender => 'Sender for notification messages',
7007: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7008: my @offon = ('off','on');
1.17 raeburn 7009: my $sender_uname = $env{'form.sender_uname'};
7010: my $sender_domain = $env{'form.sender_domain'};
7011: if ($sender_domain eq '') {
7012: $sender_uname = '';
7013: } elsif ($sender_uname eq '') {
7014: $sender_domain = '';
7015: }
1.129 raeburn 7016: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7017: my %autoenrollhash = (
1.129 raeburn 7018: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7019: 'sender_uname' => $sender_uname,
7020: 'sender_domain' => $sender_domain,
7021: 'co-owners' => $coowners,
1.1 raeburn 7022: }
7023: );
1.4 raeburn 7024: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7025: $dom);
1.1 raeburn 7026: if ($putresult eq 'ok') {
7027: if (exists($currautoenroll{'run'})) {
7028: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7029: $changes{'run'} = 1;
7030: }
7031: } elsif ($autorun) {
7032: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7033: $changes{'run'} = 1;
1.1 raeburn 7034: }
7035: }
1.17 raeburn 7036: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7037: $changes{'sender'} = 1;
7038: }
1.17 raeburn 7039: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7040: $changes{'sender'} = 1;
7041: }
1.129 raeburn 7042: if ($currautoenroll{'co-owners'} ne '') {
7043: if ($currautoenroll{'co-owners'} ne $coowners) {
7044: $changes{'coowners'} = 1;
7045: }
7046: } elsif ($coowners) {
7047: $changes{'coowners'} = 1;
7048: }
1.1 raeburn 7049: if (keys(%changes) > 0) {
7050: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7051: if ($changes{'run'}) {
1.1 raeburn 7052: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7053: }
7054: if ($changes{'sender'}) {
1.17 raeburn 7055: if ($sender_uname eq '' || $sender_domain eq '') {
7056: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7057: } else {
7058: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7059: }
1.1 raeburn 7060: }
1.129 raeburn 7061: if ($changes{'coowners'}) {
7062: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7063: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7064: if (ref($lastactref) eq 'HASH') {
7065: $lastactref->{'domainconfig'} = 1;
7066: }
1.129 raeburn 7067: }
1.1 raeburn 7068: $resulttext .= '</ul>';
7069: } else {
7070: $resulttext = &mt('No changes made to auto-enrollment settings');
7071: }
7072: } else {
1.11 albertel 7073: $resulttext = '<span class="LC_error">'.
7074: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7075: }
1.3 raeburn 7076: return $resulttext;
1.1 raeburn 7077: }
7078:
7079: sub modify_autoupdate {
1.3 raeburn 7080: my ($dom,%domconfig) = @_;
1.1 raeburn 7081: my ($resulttext,%currautoupdate,%fields,%changes);
7082: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7083: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7084: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7085: }
7086: }
7087: my @offon = ('off','on');
7088: my %title = &Apache::lonlocal::texthash (
7089: run => 'Auto-update:',
7090: classlists => 'Updates to user information in classlists?'
7091: );
1.44 raeburn 7092: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7093: my %fieldtitles = &Apache::lonlocal::texthash (
7094: id => 'Student/Employee ID',
1.20 raeburn 7095: permanentemail => 'E-mail address',
1.1 raeburn 7096: lastname => 'Last Name',
7097: firstname => 'First Name',
7098: middlename => 'Middle Name',
1.132 raeburn 7099: generation => 'Generation',
1.1 raeburn 7100: );
1.142 raeburn 7101: $othertitle = &mt('All users');
1.1 raeburn 7102: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7103: $othertitle = &mt('Other users');
1.1 raeburn 7104: }
7105: foreach my $key (keys(%env)) {
7106: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7107: my ($usertype,$item) = ($1,$2);
7108: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7109: if ($usertype eq 'default') {
7110: push(@{$fields{$1}},$2);
7111: } elsif (ref($types) eq 'ARRAY') {
7112: if (grep(/^\Q$usertype\E$/,@{$types})) {
7113: push(@{$fields{$1}},$2);
7114: }
7115: }
7116: }
1.1 raeburn 7117: }
7118: }
1.131 raeburn 7119: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7120: @lockablenames = sort(@lockablenames);
7121: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7122: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7123: if (@changed) {
7124: $changes{'lockablenames'} = 1;
7125: }
7126: } else {
7127: if (@lockablenames) {
7128: $changes{'lockablenames'} = 1;
7129: }
7130: }
1.1 raeburn 7131: my %updatehash = (
7132: autoupdate => { run => $env{'form.autoupdate_run'},
7133: classlists => $env{'form.classlists'},
7134: fields => {%fields},
1.131 raeburn 7135: lockablenames => \@lockablenames,
1.1 raeburn 7136: }
7137: );
7138: foreach my $key (keys(%currautoupdate)) {
7139: if (($key eq 'run') || ($key eq 'classlists')) {
7140: if (exists($updatehash{autoupdate}{$key})) {
7141: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7142: $changes{$key} = 1;
7143: }
7144: }
7145: } elsif ($key eq 'fields') {
7146: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7147: foreach my $item (@{$types},'default') {
1.1 raeburn 7148: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7149: my $change = 0;
7150: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7151: if (!exists($fields{$item})) {
7152: $change = 1;
1.132 raeburn 7153: last;
1.1 raeburn 7154: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7155: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7156: $change = 1;
1.132 raeburn 7157: last;
1.1 raeburn 7158: }
7159: }
7160: }
7161: if ($change) {
7162: push(@{$changes{$key}},$item);
7163: }
1.26 raeburn 7164: }
1.1 raeburn 7165: }
7166: }
1.131 raeburn 7167: } elsif ($key eq 'lockablenames') {
7168: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7169: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7170: if (@changed) {
7171: $changes{'lockablenames'} = 1;
7172: }
7173: } else {
7174: if (@lockablenames) {
7175: $changes{'lockablenames'} = 1;
7176: }
7177: }
7178: }
7179: }
7180: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7181: if (@lockablenames) {
7182: $changes{'lockablenames'} = 1;
1.1 raeburn 7183: }
7184: }
1.26 raeburn 7185: foreach my $item (@{$types},'default') {
7186: if (defined($fields{$item})) {
7187: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7188: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7189: my $change = 0;
7190: if (ref($fields{$item}) eq 'ARRAY') {
7191: foreach my $type (@{$fields{$item}}) {
7192: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7193: $change = 1;
7194: last;
7195: }
7196: }
7197: }
7198: if ($change) {
7199: push(@{$changes{'fields'}},$item);
7200: }
7201: } else {
1.26 raeburn 7202: push(@{$changes{'fields'}},$item);
7203: }
7204: } else {
7205: push(@{$changes{'fields'}},$item);
1.1 raeburn 7206: }
7207: }
7208: }
7209: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7210: $dom);
7211: if ($putresult eq 'ok') {
7212: if (keys(%changes) > 0) {
7213: $resulttext = &mt('Changes made:').'<ul>';
7214: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7215: if ($key eq 'lockablenames') {
7216: $resulttext .= '<li>';
7217: if (@lockablenames) {
7218: $usertypes->{'default'} = $othertitle;
7219: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7220: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7221: } else {
7222: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7223: }
7224: $resulttext .= '</li>';
7225: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7226: foreach my $item (@{$changes{$key}}) {
7227: my @newvalues;
7228: foreach my $type (@{$fields{$item}}) {
7229: push(@newvalues,$fieldtitles{$type});
7230: }
1.3 raeburn 7231: my $newvaluestr;
7232: if (@newvalues > 0) {
7233: $newvaluestr = join(', ',@newvalues);
7234: } else {
7235: $newvaluestr = &mt('none');
1.6 raeburn 7236: }
1.1 raeburn 7237: if ($item eq 'default') {
1.26 raeburn 7238: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7239: } else {
1.26 raeburn 7240: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7241: }
7242: }
7243: } else {
7244: my $newvalue;
7245: if ($key eq 'run') {
7246: $newvalue = $offon[$env{'form.autoupdate_run'}];
7247: } else {
7248: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7249: }
1.1 raeburn 7250: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7251: }
7252: }
7253: $resulttext .= '</ul>';
7254: } else {
1.3 raeburn 7255: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7256: }
7257: } else {
1.11 albertel 7258: $resulttext = '<span class="LC_error">'.
7259: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7260: }
1.3 raeburn 7261: return $resulttext;
1.1 raeburn 7262: }
7263:
1.125 raeburn 7264: sub modify_autocreate {
7265: my ($dom,%domconfig) = @_;
7266: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7267: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7268: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7269: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7270: }
7271: }
7272: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7273: req => 'Auto-creation of validated requests for official courses',
7274: xmldc => 'Identity of course creator of courses from XML files',
7275: );
7276: my @types = ('xml','req');
7277: foreach my $item (@types) {
7278: $newvals{$item} = $env{'form.autocreate_'.$item};
7279: $newvals{$item} =~ s/\D//g;
7280: $newvals{$item} = 0 if ($newvals{$item} eq '');
7281: }
7282: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7283: my %domcoords = &get_active_dcs($dom);
7284: unless (exists($domcoords{$newvals{'xmldc'}})) {
7285: $newvals{'xmldc'} = '';
7286: }
7287: %autocreatehash = (
7288: autocreate => { xml => $newvals{'xml'},
7289: req => $newvals{'req'},
7290: }
7291: );
7292: if ($newvals{'xmldc'} ne '') {
7293: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7294: }
7295: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7296: $dom);
7297: if ($putresult eq 'ok') {
7298: my @items = @types;
7299: if ($newvals{'xml'}) {
7300: push(@items,'xmldc');
7301: }
7302: foreach my $item (@items) {
7303: if (exists($currautocreate{$item})) {
7304: if ($currautocreate{$item} ne $newvals{$item}) {
7305: $changes{$item} = 1;
7306: }
7307: } elsif ($newvals{$item}) {
7308: $changes{$item} = 1;
7309: }
7310: }
7311: if (keys(%changes) > 0) {
7312: my @offon = ('off','on');
7313: $resulttext = &mt('Changes made:').'<ul>';
7314: foreach my $item (@types) {
7315: if ($changes{$item}) {
7316: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7317: $resulttext .= '<li>'.
7318: &mt("$title{$item} set to [_1]$newtxt [_2]",
7319: '<b>','</b>').
7320: '</li>';
1.125 raeburn 7321: }
7322: }
7323: if ($changes{'xmldc'}) {
7324: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7325: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7326: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7327: }
7328: $resulttext .= '</ul>';
7329: } else {
7330: $resulttext = &mt('No changes made to auto-creation settings');
7331: }
7332: } else {
7333: $resulttext = '<span class="LC_error">'.
7334: &mt('An error occurred: [_1]',$putresult).'</span>';
7335: }
7336: return $resulttext;
7337: }
7338:
1.23 raeburn 7339: sub modify_directorysrch {
7340: my ($dom,%domconfig) = @_;
7341: my ($resulttext,%changes);
7342: my %currdirsrch;
7343: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7344: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7345: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7346: }
7347: }
7348: my %title = ( available => 'Directory search available',
1.24 raeburn 7349: localonly => 'Other domains can search',
1.23 raeburn 7350: searchby => 'Search types',
7351: searchtypes => 'Search latitude');
7352: my @offon = ('off','on');
1.24 raeburn 7353: my @otherdoms = ('Yes','No');
1.23 raeburn 7354:
1.25 raeburn 7355: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7356: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7357: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7358:
1.44 raeburn 7359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7360: if (keys(%{$usertypes}) == 0) {
7361: @cansearch = ('default');
7362: } else {
7363: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7364: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7365: if (!grep(/^\Q$type\E$/,@cansearch)) {
7366: push(@{$changes{'cansearch'}},$type);
7367: }
1.23 raeburn 7368: }
1.26 raeburn 7369: foreach my $type (@cansearch) {
7370: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7371: push(@{$changes{'cansearch'}},$type);
7372: }
1.23 raeburn 7373: }
1.26 raeburn 7374: } else {
7375: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7376: }
7377: }
7378:
7379: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7380: foreach my $by (@{$currdirsrch{'searchby'}}) {
7381: if (!grep(/^\Q$by\E$/,@searchby)) {
7382: push(@{$changes{'searchby'}},$by);
7383: }
7384: }
7385: foreach my $by (@searchby) {
7386: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7387: push(@{$changes{'searchby'}},$by);
7388: }
7389: }
7390: } else {
7391: push(@{$changes{'searchby'}},@searchby);
7392: }
1.25 raeburn 7393:
7394: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7395: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7396: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7397: push(@{$changes{'searchtypes'}},$type);
7398: }
7399: }
7400: foreach my $type (@searchtypes) {
7401: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7402: push(@{$changes{'searchtypes'}},$type);
7403: }
7404: }
7405: } else {
7406: if (exists($currdirsrch{'searchtypes'})) {
7407: foreach my $type (@searchtypes) {
7408: if ($type ne $currdirsrch{'searchtypes'}) {
7409: push(@{$changes{'searchtypes'}},$type);
7410: }
7411: }
7412: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7413: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7414: }
7415: } else {
7416: push(@{$changes{'searchtypes'}},@searchtypes);
7417: }
7418: }
7419:
1.23 raeburn 7420: my %dirsrch_hash = (
7421: directorysrch => { available => $env{'form.dirsrch_available'},
7422: cansearch => \@cansearch,
1.24 raeburn 7423: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7424: searchby => \@searchby,
1.25 raeburn 7425: searchtypes => \@searchtypes,
1.23 raeburn 7426: }
7427: );
7428: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7429: $dom);
7430: if ($putresult eq 'ok') {
7431: if (exists($currdirsrch{'available'})) {
7432: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7433: $changes{'available'} = 1;
7434: }
7435: } else {
7436: if ($env{'form.dirsrch_available'} eq '1') {
7437: $changes{'available'} = 1;
7438: }
7439: }
1.24 raeburn 7440: if (exists($currdirsrch{'localonly'})) {
7441: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7442: $changes{'localonly'} = 1;
7443: }
7444: } else {
7445: if ($env{'form.dirsrch_localonly'} eq '1') {
7446: $changes{'localonly'} = 1;
7447: }
7448: }
1.23 raeburn 7449: if (keys(%changes) > 0) {
7450: $resulttext = &mt('Changes made:').'<ul>';
7451: if ($changes{'available'}) {
7452: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7453: }
1.24 raeburn 7454: if ($changes{'localonly'}) {
7455: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7456: }
7457:
1.23 raeburn 7458: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7459: my $chgtext;
1.26 raeburn 7460: if (ref($usertypes) eq 'HASH') {
7461: if (keys(%{$usertypes}) > 0) {
7462: foreach my $type (@{$types}) {
7463: if (grep(/^\Q$type\E$/,@cansearch)) {
7464: $chgtext .= $usertypes->{$type}.'; ';
7465: }
7466: }
7467: if (grep(/^default$/,@cansearch)) {
7468: $chgtext .= $othertitle;
7469: } else {
7470: $chgtext =~ s/\; $//;
7471: }
1.210 raeburn 7472: $resulttext .=
1.178 raeburn 7473: '<li>'.
7474: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7475: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7476: '</li>';
1.23 raeburn 7477: }
7478: }
7479: }
7480: if (ref($changes{'searchby'}) eq 'ARRAY') {
7481: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7482: my $chgtext;
7483: foreach my $type (@{$titleorder}) {
7484: if (grep(/^\Q$type\E$/,@searchby)) {
7485: if (defined($searchtitles->{$type})) {
7486: $chgtext .= $searchtitles->{$type}.'; ';
7487: }
7488: }
7489: }
7490: $chgtext =~ s/\; $//;
7491: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7492: }
1.25 raeburn 7493: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7494: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7495: my $chgtext;
7496: foreach my $type (@{$srchtypeorder}) {
7497: if (grep(/^\Q$type\E$/,@searchtypes)) {
7498: if (defined($srchtypes_desc->{$type})) {
7499: $chgtext .= $srchtypes_desc->{$type}.'; ';
7500: }
7501: }
7502: }
7503: $chgtext =~ s/\; $//;
1.178 raeburn 7504: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7505: }
7506: $resulttext .= '</ul>';
7507: } else {
7508: $resulttext = &mt('No changes made to institution directory search settings');
7509: }
7510: } else {
7511: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7512: &mt('An error occurred: [_1]',$putresult).'</span>';
7513: }
7514: return $resulttext;
7515: }
7516:
1.28 raeburn 7517: sub modify_contacts {
1.205 raeburn 7518: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7519: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7520: if (ref($domconfig{'contacts'}) eq 'HASH') {
7521: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7522: $currsetting{$key} = $domconfig{'contacts'}{$key};
7523: }
7524: }
1.134 raeburn 7525: my (%others,%to,%bcc);
1.28 raeburn 7526: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7527: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7528: 'requestsmail','updatesmail','idconflictsmail');
7529: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7530: foreach my $type (@mailings) {
7531: @{$newsetting{$type}} =
7532: &Apache::loncommon::get_env_multiple('form.'.$type);
7533: foreach my $item (@contacts) {
7534: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7535: $contacts_hash{contacts}{$type}{$item} = 1;
7536: } else {
7537: $contacts_hash{contacts}{$type}{$item} = 0;
7538: }
7539: }
7540: $others{$type} = $env{'form.'.$type.'_others'};
7541: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7542: if ($type eq 'helpdeskmail') {
7543: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7544: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7545: }
1.28 raeburn 7546: }
7547: foreach my $item (@contacts) {
7548: $to{$item} = $env{'form.'.$item};
7549: $contacts_hash{'contacts'}{$item} = $to{$item};
7550: }
1.203 raeburn 7551: foreach my $item (@toggles) {
7552: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7553: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7554: }
7555: }
1.28 raeburn 7556: if (keys(%currsetting) > 0) {
7557: foreach my $item (@contacts) {
7558: if ($to{$item} ne $currsetting{$item}) {
7559: $changes{$item} = 1;
7560: }
7561: }
7562: foreach my $type (@mailings) {
7563: foreach my $item (@contacts) {
7564: if (ref($currsetting{$type}) eq 'HASH') {
7565: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7566: push(@{$changes{$type}},$item);
7567: }
7568: } else {
7569: push(@{$changes{$type}},@{$newsetting{$type}});
7570: }
7571: }
7572: if ($others{$type} ne $currsetting{$type}{'others'}) {
7573: push(@{$changes{$type}},'others');
7574: }
1.134 raeburn 7575: if ($type eq 'helpdeskmail') {
7576: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7577: push(@{$changes{$type}},'bcc');
7578: }
7579: }
1.28 raeburn 7580: }
7581: } else {
7582: my %default;
7583: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7584: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7585: $default{'errormail'} = 'adminemail';
7586: $default{'packagesmail'} = 'adminemail';
7587: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7588: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7589: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7590: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7591: foreach my $item (@contacts) {
7592: if ($to{$item} ne $default{$item}) {
7593: $changes{$item} = 1;
1.203 raeburn 7594: }
1.28 raeburn 7595: }
7596: foreach my $type (@mailings) {
7597: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7598:
7599: push(@{$changes{$type}},@{$newsetting{$type}});
7600: }
7601: if ($others{$type} ne '') {
7602: push(@{$changes{$type}},'others');
1.134 raeburn 7603: }
7604: if ($type eq 'helpdeskmail') {
7605: if ($bcc{$type} ne '') {
7606: push(@{$changes{$type}},'bcc');
7607: }
7608: }
1.28 raeburn 7609: }
7610: }
1.203 raeburn 7611: foreach my $item (@toggles) {
7612: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7613: $changes{$item} = 1;
7614: } elsif ((!$env{'form.'.$item}) &&
7615: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7616: $changes{$item} = 1;
7617: }
7618: }
1.28 raeburn 7619: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7620: $dom);
7621: if ($putresult eq 'ok') {
7622: if (keys(%changes) > 0) {
1.205 raeburn 7623: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7624: if (ref($lastactref) eq 'HASH') {
7625: $lastactref->{'domainconfig'} = 1;
7626: }
1.28 raeburn 7627: my ($titles,$short_titles) = &contact_titles();
7628: $resulttext = &mt('Changes made:').'<ul>';
7629: foreach my $item (@contacts) {
7630: if ($changes{$item}) {
7631: $resulttext .= '<li>'.$titles->{$item}.
7632: &mt(' set to: ').
7633: '<span class="LC_cusr_emph">'.
7634: $to{$item}.'</span></li>';
7635: }
7636: }
7637: foreach my $type (@mailings) {
7638: if (ref($changes{$type}) eq 'ARRAY') {
7639: $resulttext .= '<li>'.$titles->{$type}.': ';
7640: my @text;
7641: foreach my $item (@{$newsetting{$type}}) {
7642: push(@text,$short_titles->{$item});
7643: }
7644: if ($others{$type} ne '') {
7645: push(@text,$others{$type});
7646: }
7647: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7648: join(', ',@text).'</span>';
7649: if ($type eq 'helpdeskmail') {
7650: if ($bcc{$type} ne '') {
7651: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7652: }
7653: }
7654: $resulttext .= '</li>';
1.28 raeburn 7655: }
7656: }
1.203 raeburn 7657: my @offon = ('off','on');
7658: if ($changes{'reporterrors'}) {
7659: $resulttext .= '<li>'.
7660: &mt('E-mail error reports to [_1] set to "'.
7661: $offon[$env{'form.reporterrors'}].'".',
7662: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7663: &mt('LON-CAPA core group - MSU'),600,500)).
7664: '</li>';
7665: }
7666: if ($changes{'reportupdates'}) {
7667: $resulttext .= '<li>'.
7668: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7669: $offon[$env{'form.reportupdates'}].'".',
7670: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7671: &mt('LON-CAPA core group - MSU'),600,500)).
7672: '</li>';
7673: }
1.28 raeburn 7674: $resulttext .= '</ul>';
7675: } else {
1.34 raeburn 7676: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7677: }
7678: } else {
7679: $resulttext = '<span class="LC_error">'.
7680: &mt('An error occurred: [_1].',$putresult).'</span>';
7681: }
7682: return $resulttext;
7683: }
7684:
7685: sub modify_usercreation {
1.27 raeburn 7686: my ($dom,%domconfig) = @_;
1.224 raeburn 7687: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7688: my $warningmsg;
1.27 raeburn 7689: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7690: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 7691: if ($key eq 'cancreate') {
7692: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7693: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7694: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7695: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
7696: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7697: } else {
7698: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7699: }
7700: }
7701: }
7702: } elsif ($key eq 'email_rule') {
7703: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7704: } else {
7705: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7706: }
1.27 raeburn 7707: }
7708: }
7709: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7710: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 7711: my @contexts = ('author','course','requestcrs');
1.34 raeburn 7712: foreach my $item(@contexts) {
1.224 raeburn 7713: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7714: }
1.34 raeburn 7715: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7716: foreach my $item (@contexts) {
1.224 raeburn 7717: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7718: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7719: }
1.27 raeburn 7720: }
1.34 raeburn 7721: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7722: foreach my $item (@contexts) {
1.43 raeburn 7723: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7724: if ($cancreate{$item} ne 'any') {
7725: push(@{$changes{'cancreate'}},$item);
7726: }
7727: } else {
7728: if ($cancreate{$item} ne 'none') {
7729: push(@{$changes{'cancreate'}},$item);
7730: }
1.27 raeburn 7731: }
7732: }
7733: } else {
1.43 raeburn 7734: foreach my $item (@contexts) {
1.34 raeburn 7735: push(@{$changes{'cancreate'}},$item);
7736: }
1.27 raeburn 7737: }
1.34 raeburn 7738:
1.27 raeburn 7739: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7740: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7741: if (!grep(/^\Q$type\E$/,@username_rule)) {
7742: push(@{$changes{'username_rule'}},$type);
7743: }
7744: }
7745: foreach my $type (@username_rule) {
7746: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7747: push(@{$changes{'username_rule'}},$type);
7748: }
7749: }
7750: } else {
7751: push(@{$changes{'username_rule'}},@username_rule);
7752: }
7753:
1.32 raeburn 7754: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7755: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7756: if (!grep(/^\Q$type\E$/,@id_rule)) {
7757: push(@{$changes{'id_rule'}},$type);
7758: }
7759: }
7760: foreach my $type (@id_rule) {
7761: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7762: push(@{$changes{'id_rule'}},$type);
7763: }
7764: }
7765: } else {
7766: push(@{$changes{'id_rule'}},@id_rule);
7767: }
7768:
1.43 raeburn 7769: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7770: my @authtypes = ('int','krb4','krb5','loc');
7771: my %authhash;
1.43 raeburn 7772: foreach my $item (@authen_contexts) {
1.28 raeburn 7773: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7774: foreach my $auth (@authtypes) {
7775: if (grep(/^\Q$auth\E$/,@authallowed)) {
7776: $authhash{$item}{$auth} = 1;
7777: } else {
7778: $authhash{$item}{$auth} = 0;
7779: }
7780: }
7781: }
7782: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7783: foreach my $item (@authen_contexts) {
1.28 raeburn 7784: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7785: foreach my $auth (@authtypes) {
7786: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7787: push(@{$changes{'authtypes'}},$item);
7788: last;
7789: }
7790: }
7791: }
7792: }
7793: } else {
1.43 raeburn 7794: foreach my $item (@authen_contexts) {
1.28 raeburn 7795: push(@{$changes{'authtypes'}},$item);
7796: }
7797: }
7798:
1.224 raeburn 7799: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
7800: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
7801: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
7802: $save_usercreate{'id_rule'} = \@id_rule;
7803: $save_usercreate{'username_rule'} = \@username_rule,
7804: $save_usercreate{'authtypes'} = \%authhash;
7805:
1.27 raeburn 7806: my %usercreation_hash = (
1.224 raeburn 7807: usercreation => \%save_usercreate,
7808: );
1.27 raeburn 7809:
7810: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7811: $dom);
1.50 raeburn 7812:
1.224 raeburn 7813: if ($putresult eq 'ok') {
7814: if (keys(%changes) > 0) {
7815: $resulttext = &mt('Changes made:').'<ul>';
7816: if (ref($changes{'cancreate'}) eq 'ARRAY') {
7817: my %lt = &usercreation_types();
7818: foreach my $type (@{$changes{'cancreate'}}) {
7819: my $chgtext = $lt{$type}.', ';
7820: if ($cancreate{$type} eq 'none') {
7821: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7822: } elsif ($cancreate{$type} eq 'any') {
7823: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7824: } elsif ($cancreate{$type} eq 'official') {
7825: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7826: } elsif ($cancreate{$type} eq 'unofficial') {
7827: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7828: }
7829: $resulttext .= '<li>'.$chgtext.'</li>';
7830: }
7831: }
7832: if (ref($changes{'username_rule'}) eq 'ARRAY') {
7833: my ($rules,$ruleorder) =
7834: &Apache::lonnet::inst_userrules($dom,'username');
7835: my $chgtext = '<ul>';
7836: foreach my $type (@username_rule) {
7837: if (ref($rules->{$type}) eq 'HASH') {
7838: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7839: }
7840: }
7841: $chgtext .= '</ul>';
7842: if (@username_rule > 0) {
7843: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7844: } else {
7845: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
7846: }
7847: }
7848: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7849: my ($idrules,$idruleorder) =
7850: &Apache::lonnet::inst_userrules($dom,'id');
7851: my $chgtext = '<ul>';
7852: foreach my $type (@id_rule) {
7853: if (ref($idrules->{$type}) eq 'HASH') {
7854: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7855: }
7856: }
7857: $chgtext .= '</ul>';
7858: if (@id_rule > 0) {
7859: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7860: } else {
7861: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7862: }
7863: }
7864: my %authname = &authtype_names();
7865: my %context_title = &context_names();
7866: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7867: my $chgtext = '<ul>';
7868: foreach my $type (@{$changes{'authtypes'}}) {
7869: my @allowed;
7870: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7871: foreach my $auth (@authtypes) {
7872: if ($authhash{$type}{$auth}) {
7873: push(@allowed,$authname{$auth});
7874: }
7875: }
7876: if (@allowed > 0) {
7877: $chgtext .= join(', ',@allowed).'</li>';
7878: } else {
7879: $chgtext .= &mt('none').'</li>';
7880: }
7881: }
7882: $chgtext .= '</ul>';
7883: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7884: $resulttext .= '</li>';
7885: }
7886: $resulttext .= '</ul>';
7887: } else {
7888: $resulttext = &mt('No changes made to user creation settings');
7889: }
7890: } else {
7891: $resulttext = '<span class="LC_error">'.
7892: &mt('An error occurred: [_1]',$putresult).'</span>';
7893: }
7894: if ($warningmsg ne '') {
7895: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7896: }
7897: return $resulttext;
7898: }
7899:
7900: sub modify_selfcreation {
7901: my ($dom,%domconfig) = @_;
7902: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
7903: my (%save_usercreate,%save_usermodify);
1.228 raeburn 7904: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7905: if (ref($types) eq 'ARRAY') {
7906: $usertypes->{'default'} = $othertitle;
7907: push(@{$types},'default');
7908: }
1.224 raeburn 7909: #
7910: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
7911: #
7912: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7913: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
7914: if ($key eq 'cancreate') {
7915: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7916: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7917: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7918: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
7919: ($item eq 'emailusername') || ($item eq 'notify')) {
7920: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7921: } else {
7922: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7923: }
7924: }
7925: }
7926: } elsif ($key eq 'email_rule') {
7927: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7928: } else {
7929: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7930: }
7931: }
7932: }
7933: #
7934: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
7935: #
7936: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7937: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7938: if ($key eq 'selfcreate') {
7939: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
7940: } else {
7941: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
7942: }
7943: }
7944: }
7945:
7946: my @contexts = ('selfcreate');
7947: @{$cancreate{'selfcreate'}} = ();
7948: %{$cancreate{'emailusername'}} = ();
7949: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 7950: my %selfcreatetypes = (
7951: sso => 'users authenticated by institutional single sign on',
7952: login => 'users authenticated by institutional log-in',
1.224 raeburn 7953: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
7954: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 7955: );
1.224 raeburn 7956: #
7957: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
7958: # is permitted.
7959: #
1.228 raeburn 7960: foreach my $item ('login','sso','email') {
1.224 raeburn 7961: if ($item eq 'email') {
7962: if ($env{'form.cancreate_email'} eq 'email') {
7963: push(@{$cancreate{'selfcreate'}},'email');
7964: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
7965: push(@{$cancreate{'selfcreate'}},'emailapproval');
7966: }
7967: } else {
7968: if ($env{'form.cancreate_'.$item}) {
7969: push(@{$cancreate{'selfcreate'}},$item);
7970: }
7971: }
7972: }
7973: my (@email_rule,%userinfo,%savecaptcha);
7974: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7975: #
1.228 raeburn 7976: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
7977: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 7978: #
7979: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
1.228 raeburn 7980: push(@contexts,'emailusername');
7981: if (ref($types) eq 'ARRAY') {
7982: foreach my $type (@{$types}) {
7983: if (ref($infofields) eq 'ARRAY') {
7984: foreach my $field (@{$infofields}) {
7985: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
7986: $cancreate{'emailusername'}{$type}{$field} = $1;
7987: }
7988: }
1.224 raeburn 7989: }
7990: }
7991: }
7992: #
7993: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
7994: # queued requests for self-creation of account using e-mail address as username
7995: #
7996:
7997: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
7998: @approvalnotify = sort(@approvalnotify);
7999: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8000: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8001: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8002: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8003: push(@{$changes{'cancreate'}},'notify');
8004: }
8005: } else {
8006: if ($cancreate{'notify'}{'approval'}) {
8007: push(@{$changes{'cancreate'}},'notify');
8008: }
8009: }
8010: } elsif ($cancreate{'notify'}{'approval'}) {
8011: push(@{$changes{'cancreate'}},'notify');
8012: }
8013:
8014: #
8015: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8016: #
8017: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8018: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8019: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8020: if (@{$curr_usercreation{'email_rule'}} > 0) {
8021: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8022: if (!grep(/^\Q$type\E$/,@email_rule)) {
8023: push(@{$changes{'email_rule'}},$type);
8024: }
8025: }
8026: }
8027: if (@email_rule > 0) {
8028: foreach my $type (@email_rule) {
8029: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8030: push(@{$changes{'email_rule'}},$type);
8031: }
8032: }
8033: }
8034: } elsif (@email_rule > 0) {
8035: push(@{$changes{'email_rule'}},@email_rule);
8036: }
8037: }
8038: #
8039: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
8040: # institutional log-in.
8041: #
8042: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8043: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8044: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8045: ($domdefaults{'auth_def'} eq 'localauth'))) {
8046: $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.').' '.
8047: &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.');
8048: }
8049: }
8050: my @fields = ('lastname','firstname','middlename','generation',
8051: 'permanentemail','id');
8052: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8053: #
8054: # Where usernames may created for institutional log-in and/or institutional single sign on:
8055: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8056: # may self-create accounts
8057: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8058: # which the user may supply, if institutional data is unavailable.
8059: #
8060: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8061: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8062: if (@{$types} > 1) {
1.224 raeburn 8063: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8064: push(@contexts,'statustocreate');
8065: } else {
8066: undef($cancreate{'statustocreate'});
8067: }
8068: foreach my $type (@{$types}) {
8069: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8070: foreach my $field (@fields) {
8071: if (grep(/^\Q$field\E$/,@modifiable)) {
8072: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8073: } else {
8074: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8075: }
8076: }
8077: }
8078: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8079: foreach my $type (@{$types}) {
8080: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8081: foreach my $field (@fields) {
8082: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8083: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8084: push(@{$changes{'selfcreate'}},$type);
8085: last;
8086: }
8087: }
8088: }
8089: }
8090: } else {
8091: foreach my $type (@{$types}) {
8092: push(@{$changes{'selfcreate'}},$type);
8093: }
8094: }
8095: }
8096: }
8097: foreach my $item (@contexts) {
8098: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8099: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8100: if (ref($cancreate{$item}) eq 'ARRAY') {
8101: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8102: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8103: push(@{$changes{'cancreate'}},$item);
8104: }
8105: }
8106: }
8107: }
8108: if (ref($cancreate{$item}) eq 'ARRAY') {
8109: foreach my $type (@{$cancreate{$item}}) {
8110: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8111: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8112: push(@{$changes{'cancreate'}},$item);
8113: }
8114: }
8115: }
8116: }
8117: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8118: if (ref($cancreate{$item}) eq 'HASH') {
8119: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8120: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8121: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8122: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8123: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8124: push(@{$changes{'cancreate'}},$item);
8125: }
8126: }
8127: }
8128: } else {
8129: if (!$cancreate{$item}{$curr}) {
8130: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8131: push(@{$changes{'cancreate'}},$item);
8132: }
1.224 raeburn 8133: }
8134: }
8135: }
8136: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8137: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8138: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8139: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8140: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8141: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8142: push(@{$changes{'cancreate'}},$item);
8143: }
8144: }
8145: } else {
8146: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8147: push(@{$changes{'cancreate'}},$item);
8148: }
8149: }
8150: }
8151: } else {
8152: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8153: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8154: push(@{$changes{'cancreate'}},$item);
8155: }
1.224 raeburn 8156: }
8157: }
8158: }
8159: }
8160: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8161: if (ref($cancreate{$item}) eq 'ARRAY') {
8162: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8163: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8164: push(@{$changes{'cancreate'}},$item);
8165: }
8166: }
8167: } elsif (ref($cancreate{$item}) eq 'HASH') {
8168: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8169: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8170: push(@{$changes{'cancreate'}},$item);
8171: }
8172: }
8173: }
8174: } elsif ($item eq 'emailusername') {
1.228 raeburn 8175: if (ref($cancreate{$item}) eq 'HASH') {
8176: foreach my $type (keys(%{$cancreate{$item}})) {
8177: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8178: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8179: if ($cancreate{$item}{$type}{$field}) {
8180: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8181: push(@{$changes{'cancreate'}},$item);
8182: }
8183: last;
8184: }
8185: }
8186: }
8187: }
1.224 raeburn 8188: }
8189: }
8190: }
8191: #
8192: # Populate %save_usercreate hash with updates to self-creation configuration.
8193: #
8194: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8195: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8196: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8197: if (ref($cancreate{'notify'}) eq 'HASH') {
8198: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8199: }
8200: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8201: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8202: }
8203: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8204: $save_usercreate{'emailrule'} = \@email_rule;
8205:
8206: my %userconfig_hash = (
8207: usercreation => \%save_usercreate,
8208: usermodification => \%save_usermodify,
8209: );
8210: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8211: $dom);
8212: #
8213: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8214: #
1.27 raeburn 8215: if ($putresult eq 'ok') {
8216: if (keys(%changes) > 0) {
8217: $resulttext = &mt('Changes made:').'<ul>';
8218: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8219: my %lt = &selfcreation_types();
1.34 raeburn 8220: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8221: my $chgtext;
1.45 raeburn 8222: if ($type eq 'selfcreate') {
1.50 raeburn 8223: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8224: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8225: } else {
1.224 raeburn 8226: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8227: '<ul>';
1.50 raeburn 8228: foreach my $case (@{$cancreate{$type}}) {
8229: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8230: }
8231: $chgtext .= '</ul>';
1.100 raeburn 8232: if (ref($cancreate{$type}) eq 'ARRAY') {
8233: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8234: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8235: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8236: $chgtext .= '<br />'.
8237: '<span class="LC_warning">'.
8238: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8239: '</span>';
1.100 raeburn 8240: }
8241: }
8242: }
8243: }
1.43 raeburn 8244: }
1.93 raeburn 8245: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8246: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8247: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8248: if (@{$cancreate{'selfcreate'}} > 0) {
8249: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8250: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8251: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8252: $chgtext .= '<br />'.
8253: '<span class="LC_warning">'.
8254: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8255: '</span>';
8256: }
1.96 raeburn 8257: } elsif (ref($usertypes) eq 'HASH') {
8258: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8259: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8260: } else {
8261: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8262: }
8263: $chgtext .= '<ul>';
8264: foreach my $case (@{$cancreate{$type}}) {
8265: if ($case eq 'default') {
8266: $chgtext .= '<li>'.$othertitle.'</li>';
8267: } else {
8268: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8269: }
8270: }
1.100 raeburn 8271: $chgtext .= '</ul>';
8272: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8273: $chgtext .= '<br /><span class="LC_warning">'.
8274: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8275: '</span>';
1.100 raeburn 8276: }
8277: }
8278: } else {
8279: if (@{$cancreate{$type}} == 0) {
8280: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8281: } else {
8282: $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 8283: }
8284: }
8285: }
1.165 raeburn 8286: } elsif ($type eq 'captcha') {
1.224 raeburn 8287: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8288: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8289: } else {
8290: my %captchas = &captcha_phrases();
1.224 raeburn 8291: if ($captchas{$savecaptcha{$type}}) {
8292: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8293: } else {
1.210 raeburn 8294: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8295: }
8296: }
8297: } elsif ($type eq 'recaptchakeys') {
8298: my ($privkey,$pubkey);
1.224 raeburn 8299: if (ref($savecaptcha{$type}) eq 'HASH') {
8300: $pubkey = $savecaptcha{$type}{'public'};
8301: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8302: }
8303: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8304: if (!$pubkey) {
8305: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8306: } else {
8307: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8308: }
8309: if (!$privkey) {
8310: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8311: } else {
8312: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8313: }
8314: $chgtext .= '</ul>';
1.224 raeburn 8315: } elsif ($type eq 'emailusername') {
8316: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8317: if (ref($types) eq 'ARRAY') {
8318: foreach my $type (@{$types}) {
8319: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8320: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8321: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8322: '<ul>';
8323: foreach my $field (@{$infofields}) {
8324: if ($cancreate{'emailusername'}{$type}{$field}) {
8325: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8326: }
8327: }
8328: }
8329: $chgtext .= '</ul>';
8330: } else {
8331: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',$usertypes->{$type}).'<br />';
1.224 raeburn 8332: }
8333: }
8334: }
8335: }
8336: } elsif ($type eq 'notify') {
8337: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8338: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8339: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8340: if ($cancreate{'notify'}{'approval'}) {
8341: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8342: }
8343: }
1.43 raeburn 8344: }
1.34 raeburn 8345: }
1.224 raeburn 8346: if ($chgtext) {
8347: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8348: }
8349: }
8350: }
1.43 raeburn 8351: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8352: my ($emailrules,$emailruleorder) =
8353: &Apache::lonnet::inst_userrules($dom,'email');
8354: my $chgtext = '<ul>';
8355: foreach my $type (@email_rule) {
8356: if (ref($emailrules->{$type}) eq 'HASH') {
8357: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8358: }
8359: }
8360: $chgtext .= '</ul>';
8361: if (@email_rule > 0) {
1.224 raeburn 8362: $resulttext .= '<li>'.
8363: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8364: $chgtext.
8365: '</li>';
1.43 raeburn 8366: } else {
1.224 raeburn 8367: $resulttext .= '<li>'.
8368: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8369: '</li>';
1.43 raeburn 8370: }
8371: }
1.224 raeburn 8372: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8373: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8374: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8375: foreach my $type (@{$changes{'selfcreate'}}) {
8376: my $typename = $type;
8377: if (ref($usertypes) eq 'HASH') {
8378: if ($usertypes->{$type} ne '') {
8379: $typename = $usertypes->{$type};
8380: }
8381: }
8382: my @modifiable;
8383: $resulttext .= '<li>'.
8384: &mt('Self-creation of account by users with status: [_1]',
8385: '<span class="LC_cusr_emph">'.$typename.'</span>').
8386: ' - '.&mt('modifiable fields (if institutional data blank): ');
8387: foreach my $field (@fields) {
8388: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8389: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8390: }
8391: }
1.224 raeburn 8392: if (@modifiable > 0) {
8393: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8394: } else {
1.224 raeburn 8395: $resulttext .= &mt('none');
1.43 raeburn 8396: }
1.224 raeburn 8397: $resulttext .= '</li>';
1.28 raeburn 8398: }
1.224 raeburn 8399: $resulttext .= '</ul></li>';
1.28 raeburn 8400: }
1.27 raeburn 8401: $resulttext .= '</ul>';
8402: } else {
1.224 raeburn 8403: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8404: }
8405: } else {
8406: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8407: &mt('An error occurred: [_1]',$putresult).'</span>';
8408: }
1.43 raeburn 8409: if ($warningmsg ne '') {
8410: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8411: }
1.23 raeburn 8412: return $resulttext;
8413: }
8414:
1.165 raeburn 8415: sub process_captcha {
8416: my ($container,$changes,$newsettings,$current) = @_;
8417: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8418: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8419: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8420: $newsettings->{'captcha'} = 'original';
8421: }
8422: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8423: if ($container eq 'cancreate') {
1.169 raeburn 8424: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8425: push(@{$changes->{'cancreate'}},'captcha');
8426: } elsif (!defined($changes->{'cancreate'})) {
8427: $changes->{'cancreate'} = ['captcha'];
8428: }
8429: } else {
8430: $changes->{'captcha'} = 1;
1.165 raeburn 8431: }
8432: }
8433: my ($newpub,$newpriv,$currpub,$currpriv);
8434: if ($newsettings->{'captcha'} eq 'recaptcha') {
8435: $newpub = $env{'form.'.$container.'_recaptchapub'};
8436: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8437: $newpub =~ s/\W//g;
8438: $newpriv =~ s/\W//g;
8439: $newsettings->{'recaptchakeys'} = {
8440: public => $newpub,
8441: private => $newpriv,
8442: };
1.165 raeburn 8443: }
8444: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8445: $currpub = $current->{'recaptchakeys'}{'public'};
8446: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8447: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8448: $newsettings->{'recaptchakeys'} = {
8449: public => '',
8450: private => '',
8451: }
8452: }
1.165 raeburn 8453: }
8454: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8455: if ($container eq 'cancreate') {
8456: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8457: push(@{$changes->{'cancreate'}},'recaptchakeys');
8458: } elsif (!defined($changes->{'cancreate'})) {
8459: $changes->{'cancreate'} = ['recaptchakeys'];
8460: }
8461: } else {
1.210 raeburn 8462: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8463: }
8464: }
8465: return;
8466: }
8467:
1.33 raeburn 8468: sub modify_usermodification {
8469: my ($dom,%domconfig) = @_;
1.224 raeburn 8470: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8471: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8472: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 8473: if ($key eq 'selfcreate') {
8474: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8475: } else {
8476: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8477: }
1.33 raeburn 8478: }
8479: }
1.224 raeburn 8480: my @contexts = ('author','course');
1.33 raeburn 8481: my %context_title = (
8482: author => 'In author context',
8483: course => 'In course context',
8484: );
8485: my @fields = ('lastname','firstname','middlename','generation',
8486: 'permanentemail','id');
8487: my %roles = (
8488: author => ['ca','aa'],
8489: course => ['st','ep','ta','in','cr'],
8490: );
8491: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8492: foreach my $context (@contexts) {
8493: foreach my $role (@{$roles{$context}}) {
8494: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8495: foreach my $item (@fields) {
8496: if (grep(/^\Q$item\E$/,@modifiable)) {
8497: $modifyhash{$context}{$role}{$item} = 1;
8498: } else {
8499: $modifyhash{$context}{$role}{$item} = 0;
8500: }
8501: }
8502: }
8503: if (ref($curr_usermodification{$context}) eq 'HASH') {
8504: foreach my $role (@{$roles{$context}}) {
8505: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8506: foreach my $field (@fields) {
8507: if ($modifyhash{$context}{$role}{$field} ne
8508: $curr_usermodification{$context}{$role}{$field}) {
8509: push(@{$changes{$context}},$role);
8510: last;
8511: }
8512: }
8513: }
8514: }
8515: } else {
8516: foreach my $context (@contexts) {
8517: foreach my $role (@{$roles{$context}}) {
8518: push(@{$changes{$context}},$role);
8519: }
8520: }
8521: }
8522: }
8523: my %usermodification_hash = (
8524: usermodification => \%modifyhash,
8525: );
8526: my $putresult = &Apache::lonnet::put_dom('configuration',
8527: \%usermodification_hash,$dom);
8528: if ($putresult eq 'ok') {
8529: if (keys(%changes) > 0) {
8530: $resulttext = &mt('Changes made: ').'<ul>';
8531: foreach my $context (@contexts) {
8532: if (ref($changes{$context}) eq 'ARRAY') {
8533: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8534: if (ref($changes{$context}) eq 'ARRAY') {
8535: foreach my $role (@{$changes{$context}}) {
8536: my $rolename;
1.224 raeburn 8537: if ($role eq 'cr') {
8538: $rolename = &mt('Custom');
1.33 raeburn 8539: } else {
1.224 raeburn 8540: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8541: }
8542: my @modifiable;
1.224 raeburn 8543: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8544: foreach my $field (@fields) {
8545: if ($modifyhash{$context}{$role}{$field}) {
8546: push(@modifiable,$fieldtitles{$field});
8547: }
8548: }
8549: if (@modifiable > 0) {
8550: $resulttext .= join(', ',@modifiable);
8551: } else {
8552: $resulttext .= &mt('none');
8553: }
8554: $resulttext .= '</li>';
8555: }
8556: $resulttext .= '</ul></li>';
8557: }
8558: }
8559: }
8560: $resulttext .= '</ul>';
8561: } else {
8562: $resulttext = &mt('No changes made to user modification settings');
8563: }
8564: } else {
8565: $resulttext = '<span class="LC_error">'.
8566: &mt('An error occurred: [_1]',$putresult).'</span>';
8567: }
8568: return $resulttext;
8569: }
8570:
1.43 raeburn 8571: sub modify_defaults {
1.212 raeburn 8572: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8573: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 8574: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8575: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8576: my @authtypes = ('internal','krb4','krb5','localauth');
8577: foreach my $item (@items) {
8578: $newvalues{$item} = $env{'form.'.$item};
8579: if ($item eq 'auth_def') {
8580: if ($newvalues{$item} ne '') {
8581: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8582: push(@errors,$item);
8583: }
8584: }
8585: } elsif ($item eq 'lang_def') {
8586: if ($newvalues{$item} ne '') {
8587: if ($newvalues{$item} =~ /^(\w+)/) {
8588: my $langcode = $1;
1.103 raeburn 8589: if ($langcode ne 'x_chef') {
8590: if (code2language($langcode) eq '') {
8591: push(@errors,$item);
8592: }
1.43 raeburn 8593: }
8594: } else {
8595: push(@errors,$item);
8596: }
8597: }
1.54 raeburn 8598: } elsif ($item eq 'timezone_def') {
8599: if ($newvalues{$item} ne '') {
1.62 raeburn 8600: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8601: push(@errors,$item);
8602: }
8603: }
1.68 raeburn 8604: } elsif ($item eq 'datelocale_def') {
8605: if ($newvalues{$item} ne '') {
8606: my @datelocale_ids = DateTime::Locale->ids();
8607: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8608: push(@errors,$item);
8609: }
8610: }
1.141 raeburn 8611: } elsif ($item eq 'portal_def') {
8612: if ($newvalues{$item} ne '') {
8613: 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])\/?$/) {
8614: push(@errors,$item);
8615: }
8616: }
1.43 raeburn 8617: }
8618: if (grep(/^\Q$item\E$/,@errors)) {
8619: $newvalues{$item} = $domdefaults{$item};
8620: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8621: $changes{$item} = 1;
8622: }
1.72 raeburn 8623: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8624: }
8625: my %defaults_hash = (
1.72 raeburn 8626: defaults => \%newvalues,
8627: );
1.43 raeburn 8628: my $title = &defaults_titles();
8629: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8630: $dom);
8631: if ($putresult eq 'ok') {
8632: if (keys(%changes) > 0) {
8633: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 8634: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8635: 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";
8636: foreach my $item (sort(keys(%changes))) {
8637: my $value = $env{'form.'.$item};
8638: if ($value eq '') {
8639: $value = &mt('none');
8640: } elsif ($item eq 'auth_def') {
8641: my %authnames = &authtype_names();
8642: my %shortauth = (
8643: internal => 'int',
8644: krb4 => 'krb4',
8645: krb5 => 'krb5',
8646: localauth => 'loc',
8647: );
8648: $value = $authnames{$shortauth{$value}};
8649: }
8650: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8651: $mailmsgtext .= "$title->{$item} set to $value\n";
8652: }
8653: $resulttext .= '</ul>';
8654: $mailmsgtext .= "\n";
8655: my $cachetime = 24*60*60;
1.72 raeburn 8656: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8657: if (ref($lastactref) eq 'HASH') {
8658: $lastactref->{'domdefaults'} = 1;
8659: }
1.68 raeburn 8660: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8661: my $notify = 1;
8662: if (ref($domconfig{'contacts'}) eq 'HASH') {
8663: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8664: $notify = 0;
8665: }
8666: }
8667: if ($notify) {
8668: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8669: "LON-CAPA Domain Settings Change - $dom",
8670: $mailmsgtext);
8671: }
1.54 raeburn 8672: }
1.43 raeburn 8673: } else {
1.54 raeburn 8674: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8675: }
8676: } else {
8677: $resulttext = '<span class="LC_error">'.
8678: &mt('An error occurred: [_1]',$putresult).'</span>';
8679: }
8680: if (@errors > 0) {
8681: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8682: foreach my $item (@errors) {
8683: $resulttext .= ' "'.$title->{$item}.'",';
8684: }
8685: $resulttext =~ s/,$//;
8686: }
8687: return $resulttext;
8688: }
8689:
1.46 raeburn 8690: sub modify_scantron {
1.205 raeburn 8691: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8692: my ($resulttext,%confhash,%changes,$errors);
8693: my $custom = 'custom.tab';
8694: my $default = 'default.tab';
8695: my $servadm = $r->dir_config('lonAdmEMail');
8696: my ($configuserok,$author_ok,$switchserver) =
8697: &config_check($dom,$confname,$servadm);
8698: if ($env{'form.scantronformat.filename'} ne '') {
8699: my $error;
8700: if ($configuserok eq 'ok') {
8701: if ($switchserver) {
1.130 raeburn 8702: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8703: } else {
8704: if ($author_ok eq 'ok') {
8705: my ($result,$scantronurl) =
8706: &publishlogo($r,'upload','scantronformat',$dom,
8707: $confname,'scantron','','',$custom);
8708: if ($result eq 'ok') {
8709: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8710: $changes{'scantronformat'} = 1;
1.46 raeburn 8711: } else {
8712: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8713: }
8714: } else {
8715: $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);
8716: }
8717: }
8718: } else {
8719: $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);
8720: }
8721: if ($error) {
8722: &Apache::lonnet::logthis($error);
8723: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8724: }
8725: }
1.48 raeburn 8726: if (ref($domconfig{'scantron'}) eq 'HASH') {
8727: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8728: if ($env{'form.scantronformat_del'}) {
8729: $confhash{'scantron'}{'scantronformat'} = '';
8730: $changes{'scantronformat'} = 1;
1.46 raeburn 8731: }
8732: }
8733: }
8734: if (keys(%confhash) > 0) {
8735: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8736: $dom);
8737: if ($putresult eq 'ok') {
8738: if (keys(%changes) > 0) {
1.48 raeburn 8739: if (ref($confhash{'scantron'}) eq 'HASH') {
8740: $resulttext = &mt('Changes made:').'<ul>';
8741: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8742: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8743: } else {
1.130 raeburn 8744: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8745: }
1.48 raeburn 8746: $resulttext .= '</ul>';
8747: } else {
1.130 raeburn 8748: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8749: }
8750: $resulttext .= '</ul>';
8751: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8752: if (ref($lastactref) eq 'HASH') {
8753: $lastactref->{'domainconfig'} = 1;
8754: }
1.46 raeburn 8755: } else {
1.130 raeburn 8756: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8757: }
8758: } else {
8759: $resulttext = '<span class="LC_error">'.
8760: &mt('An error occurred: [_1]',$putresult).'</span>';
8761: }
8762: } else {
1.130 raeburn 8763: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8764: }
8765: if ($errors) {
8766: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8767: $errors.'</ul>';
8768: }
8769: return $resulttext;
8770: }
8771:
1.48 raeburn 8772: sub modify_coursecategories {
8773: my ($dom,%domconfig) = @_;
1.57 raeburn 8774: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8775: $cathash);
1.48 raeburn 8776: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8777: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8778: $cathash = $domconfig{'coursecategories'}{'cats'};
8779: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8780: $changes{'togglecats'} = 1;
8781: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8782: }
8783: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8784: $changes{'categorize'} = 1;
8785: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8786: }
1.120 raeburn 8787: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8788: $changes{'togglecatscomm'} = 1;
8789: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8790: }
8791: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8792: $changes{'categorizecomm'} = 1;
8793: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8794: }
1.57 raeburn 8795: } else {
8796: $changes{'togglecats'} = 1;
8797: $changes{'categorize'} = 1;
1.124 raeburn 8798: $changes{'togglecatscomm'} = 1;
8799: $changes{'categorizecomm'} = 1;
1.87 raeburn 8800: $domconfig{'coursecategories'} = {
8801: togglecats => $env{'form.togglecats'},
8802: categorize => $env{'form.categorize'},
1.124 raeburn 8803: togglecatscomm => $env{'form.togglecatscomm'},
8804: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8805: };
1.57 raeburn 8806: }
8807: if (ref($cathash) eq 'HASH') {
8808: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8809: push (@deletecategory,'instcode::0');
8810: }
1.120 raeburn 8811: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8812: push(@deletecategory,'communities::0');
8813: }
1.48 raeburn 8814: }
1.57 raeburn 8815: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8816: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8817: if (@deletecategory > 0) {
8818: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8819: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8820: foreach my $item (@deletecategory) {
1.57 raeburn 8821: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8822: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8823: $deletions{$item} = 1;
1.57 raeburn 8824: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8825: }
8826: }
8827: }
1.57 raeburn 8828: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8829: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8830: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8831: $reorderings{$item} = 1;
1.57 raeburn 8832: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8833: }
8834: if ($env{'form.addcategory_name_'.$item} ne '') {
8835: my $newcat = $env{'form.addcategory_name_'.$item};
8836: my $newdepth = $depth+1;
8837: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8838: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 8839: $adds{$newitem} = 1;
8840: }
8841: if ($env{'form.subcat_'.$item} ne '') {
8842: my $newcat = $env{'form.subcat_'.$item};
8843: my $newdepth = $depth+1;
8844: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 8845: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 8846: $adds{$newitem} = 1;
8847: }
8848: }
8849: }
8850: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 8851: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8852: my $newitem = 'instcode::0';
1.57 raeburn 8853: if ($cathash->{$newitem} eq '') {
8854: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8855: $adds{$newitem} = 1;
8856: }
8857: } else {
8858: my $newitem = 'instcode::0';
1.57 raeburn 8859: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 8860: $adds{$newitem} = 1;
8861: }
8862: }
1.120 raeburn 8863: if ($env{'form.communities'} eq '1') {
8864: if (ref($cathash) eq 'HASH') {
8865: my $newitem = 'communities::0';
8866: if ($cathash->{$newitem} eq '') {
8867: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8868: $adds{$newitem} = 1;
8869: }
8870: } else {
8871: my $newitem = 'communities::0';
8872: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
8873: $adds{$newitem} = 1;
8874: }
8875: }
1.48 raeburn 8876: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 8877: if (($env{'form.addcategory_name'} ne 'instcode') &&
8878: ($env{'form.addcategory_name'} ne 'communities')) {
8879: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
8880: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
8881: $adds{$newitem} = 1;
8882: }
1.48 raeburn 8883: }
1.57 raeburn 8884: my $putresult;
1.48 raeburn 8885: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8886: if (keys(%deletions) > 0) {
8887: foreach my $key (keys(%deletions)) {
8888: if ($predelallitems{$key} ne '') {
8889: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
8890: }
8891: }
8892: }
8893: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 8894: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 8895: if (ref($chkcats[0]) eq 'ARRAY') {
8896: my $depth = 0;
8897: my $chg = 0;
8898: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
8899: my $name = $chkcats[0][$i];
8900: my $item;
8901: if ($name eq '') {
8902: $chg ++;
8903: } else {
8904: $item = &escape($name).'::0';
8905: if ($chg) {
1.57 raeburn 8906: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 8907: }
8908: $depth ++;
1.57 raeburn 8909: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 8910: $depth --;
8911: }
8912: }
8913: }
1.57 raeburn 8914: }
8915: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8916: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 8917: if ($putresult eq 'ok') {
1.57 raeburn 8918: my %title = (
1.120 raeburn 8919: togglecats => 'Show/Hide a course in catalog',
8920: categorize => 'Assign a category to a course',
8921: togglecatscomm => 'Show/Hide a community in catalog',
8922: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8923: );
8924: my %level = (
1.120 raeburn 8925: dom => 'set in Domain ("Modify Course/Community")',
8926: crs => 'set in Course ("Course Configuration")',
8927: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 8928: );
1.48 raeburn 8929: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 8930: if ($changes{'togglecats'}) {
8931: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
8932: }
8933: if ($changes{'categorize'}) {
8934: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 8935: }
1.120 raeburn 8936: if ($changes{'togglecatscomm'}) {
8937: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
8938: }
8939: if ($changes{'categorizecomm'}) {
8940: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
8941: }
1.57 raeburn 8942: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
8943: my $cathash;
8944: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
8945: $cathash = $domconfig{'coursecategories'}{'cats'};
8946: } else {
8947: $cathash = {};
8948: }
8949: my (@cats,@trails,%allitems);
8950: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
8951: if (keys(%deletions) > 0) {
8952: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
8953: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
8954: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
8955: }
8956: $resulttext .= '</ul></li>';
8957: }
8958: if (keys(%reorderings) > 0) {
8959: my %sort_by_trail;
8960: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
8961: foreach my $key (keys(%reorderings)) {
8962: if ($allitems{$key} ne '') {
8963: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8964: }
1.48 raeburn 8965: }
1.57 raeburn 8966: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8967: $resulttext .= '<li>'.$trails[$trail].'</li>';
8968: }
8969: $resulttext .= '</ul></li>';
1.48 raeburn 8970: }
1.57 raeburn 8971: if (keys(%adds) > 0) {
8972: my %sort_by_trail;
8973: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
8974: foreach my $key (keys(%adds)) {
8975: if ($allitems{$key} ne '') {
8976: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
8977: }
8978: }
8979: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
8980: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 8981: }
1.57 raeburn 8982: $resulttext .= '</ul></li>';
1.48 raeburn 8983: }
8984: }
8985: $resulttext .= '</ul>';
8986: } else {
8987: $resulttext = '<span class="LC_error">'.
1.57 raeburn 8988: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 8989: }
8990: } else {
1.120 raeburn 8991: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 8992: }
8993: return $resulttext;
8994: }
8995:
1.69 raeburn 8996: sub modify_serverstatuses {
8997: my ($dom,%domconfig) = @_;
8998: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
8999: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9000: %currserverstatus = %{$domconfig{'serverstatuses'}};
9001: }
9002: my @pages = &serverstatus_pages();
9003: foreach my $type (@pages) {
9004: $newserverstatus{$type}{'namedusers'} = '';
9005: $newserverstatus{$type}{'machines'} = '';
9006: if (defined($env{'form.'.$type.'_namedusers'})) {
9007: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9008: my @okusers;
9009: foreach my $user (@users) {
9010: my ($uname,$udom) = split(/:/,$user);
9011: if (($udom =~ /^$match_domain$/) &&
9012: (&Apache::lonnet::domain($udom)) &&
9013: ($uname =~ /^$match_username$/)) {
9014: if (!grep(/^\Q$user\E/,@okusers)) {
9015: push(@okusers,$user);
9016: }
9017: }
9018: }
9019: if (@okusers > 0) {
9020: @okusers = sort(@okusers);
9021: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9022: }
9023: }
9024: if (defined($env{'form.'.$type.'_machines'})) {
9025: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9026: my @okmachines;
9027: foreach my $ip (@machines) {
9028: my @parts = split(/\./,$ip);
9029: next if (@parts < 4);
9030: my $badip = 0;
9031: for (my $i=0; $i<4; $i++) {
9032: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9033: $badip = 1;
9034: last;
9035: }
9036: }
9037: if (!$badip) {
9038: push(@okmachines,$ip);
9039: }
9040: }
9041: @okmachines = sort(@okmachines);
9042: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9043: }
9044: }
9045: my %serverstatushash = (
9046: serverstatuses => \%newserverstatus,
9047: );
9048: foreach my $type (@pages) {
1.83 raeburn 9049: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9050: my (@current,@new);
1.83 raeburn 9051: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9052: if ($currserverstatus{$type}{$setting} ne '') {
9053: @current = split(/,/,$currserverstatus{$type}{$setting});
9054: }
9055: }
9056: if ($newserverstatus{$type}{$setting} ne '') {
9057: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9058: }
9059: if (@current > 0) {
9060: if (@new > 0) {
9061: foreach my $item (@current) {
9062: if (!grep(/^\Q$item\E$/,@new)) {
9063: $changes{$type}{$setting} = 1;
1.82 raeburn 9064: last;
9065: }
9066: }
1.84 raeburn 9067: foreach my $item (@new) {
9068: if (!grep(/^\Q$item\E$/,@current)) {
9069: $changes{$type}{$setting} = 1;
9070: last;
1.82 raeburn 9071: }
9072: }
9073: } else {
1.83 raeburn 9074: $changes{$type}{$setting} = 1;
1.69 raeburn 9075: }
1.83 raeburn 9076: } elsif (@new > 0) {
9077: $changes{$type}{$setting} = 1;
1.69 raeburn 9078: }
9079: }
9080: }
9081: if (keys(%changes) > 0) {
1.81 raeburn 9082: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9083: my $putresult = &Apache::lonnet::put_dom('configuration',
9084: \%serverstatushash,$dom);
9085: if ($putresult eq 'ok') {
9086: $resulttext .= &mt('Changes made:').'<ul>';
9087: foreach my $type (@pages) {
1.84 raeburn 9088: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9089: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9090: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9091: if ($newserverstatus{$type}{'namedusers'} eq '') {
9092: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9093: } else {
9094: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9095: }
1.84 raeburn 9096: }
9097: if ($changes{$type}{'machines'}) {
1.69 raeburn 9098: if ($newserverstatus{$type}{'machines'} eq '') {
9099: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9100: } else {
9101: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9102: }
9103:
9104: }
9105: $resulttext .= '</ul></li>';
9106: }
9107: }
9108: $resulttext .= '</ul>';
9109: } else {
9110: $resulttext = '<span class="LC_error">'.
9111: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9112:
9113: }
9114: } else {
9115: $resulttext = &mt('No changes made to access to server status pages');
9116: }
9117: return $resulttext;
9118: }
9119:
1.118 jms 9120: sub modify_helpsettings {
1.122 jms 9121: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9122: my ($resulttext,$errors,%changes,%helphash);
9123: my %defaultchecked = ('submitbugs' => 'on');
9124: my @offon = ('off','on');
1.118 jms 9125: my @toggles = ('submitbugs');
9126: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9127: foreach my $item (@toggles) {
1.166 raeburn 9128: if ($defaultchecked{$item} eq 'on') {
9129: if ($domconfig{'helpsettings'}{$item} eq '') {
9130: if ($env{'form.'.$item} eq '0') {
9131: $changes{$item} = 1;
9132: }
9133: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9134: $changes{$item} = 1;
9135: }
9136: } elsif ($defaultchecked{$item} eq 'off') {
9137: if ($domconfig{'helpsettings'}{$item} eq '') {
9138: if ($env{'form.'.$item} eq '1') {
9139: $changes{$item} = 1;
9140: }
9141: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9142: $changes{$item} = 1;
9143: }
9144: }
1.210 raeburn 9145: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9146: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9147: }
9148: }
1.118 jms 9149: }
1.123 jms 9150: my $putresult;
9151: if (keys(%changes) > 0) {
1.166 raeburn 9152: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9153: if ($putresult eq 'ok') {
1.166 raeburn 9154: $resulttext = &mt('Changes made:').'<ul>';
9155: foreach my $item (sort(keys(%changes))) {
9156: if ($item eq 'submitbugs') {
9157: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9158: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9159: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9160: }
9161: }
9162: $resulttext .= '</ul>';
9163: } else {
9164: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9165: $errors .= '<li><span class="LC_error">'.
9166: &mt('An error occurred storing the settings: [_1]',
9167: $putresult).'</span></li>';
1.166 raeburn 9168: }
1.118 jms 9169: }
9170: if ($errors) {
1.168 raeburn 9171: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9172: $errors.'</ul>';
9173: }
9174: return $resulttext;
9175: }
9176:
1.121 raeburn 9177: sub modify_coursedefaults {
1.212 raeburn 9178: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9179: my ($resulttext,$errors,%changes,%defaultshash);
9180: my %defaultchecked = ('canuse_pdfforms' => 'off');
9181: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9182: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9183: 'uploadquota_community','uploadquota_textbook');
9184: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9185: my %staticdefaults = (
9186: anonsurvey_threshold => 10,
9187: uploadquota => 500,
9188: );
1.121 raeburn 9189:
9190: $defaultshash{'coursedefaults'} = {};
9191:
9192: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9193: if ($domconfig{'coursedefaults'} eq '') {
9194: $domconfig{'coursedefaults'} = {};
9195: }
9196: }
9197:
9198: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9199: foreach my $item (@toggles) {
9200: if ($defaultchecked{$item} eq 'on') {
9201: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9202: ($env{'form.'.$item} eq '0')) {
9203: $changes{$item} = 1;
1.192 raeburn 9204: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9205: $changes{$item} = 1;
9206: }
9207: } elsif ($defaultchecked{$item} eq 'off') {
9208: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9209: ($env{'form.'.$item} eq '1')) {
9210: $changes{$item} = 1;
9211: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9212: $changes{$item} = 1;
9213: }
9214: }
9215: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9216: }
1.198 raeburn 9217: foreach my $item (@numbers) {
9218: my ($currdef,$newdef);
1.208 raeburn 9219: $newdef = $env{'form.'.$item};
1.198 raeburn 9220: if ($item eq 'anonsurvey_threshold') {
9221: $currdef = $domconfig{'coursedefaults'}{$item};
9222: $newdef =~ s/\D//g;
9223: if ($newdef eq '' || $newdef < 1) {
9224: $newdef = 1;
9225: }
9226: $defaultshash{'coursedefaults'}{$item} = $newdef;
9227: } else {
9228: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9229: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9230: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9231: }
9232: $newdef =~ s/[^\w.\-]//g;
9233: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9234: }
9235: if ($currdef ne $newdef) {
9236: my $staticdef;
9237: if ($item eq 'anonsurvey_threshold') {
9238: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9239: $changes{$item} = 1;
9240: }
9241: } else {
9242: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9243: $changes{'uploadquota'} = 1;
9244: }
9245: }
1.139 raeburn 9246: }
9247: }
1.231 raeburn 9248:
1.192 raeburn 9249: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 9250: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 9251: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 9252: $unofficialcreds =~ s/[^\d.]+//g;
9253: my $textbookcreds = $env{'form.textbook_credits'};
9254: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 9255: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9256: ($env{'form.coursecredits'} eq '1')) {
9257: $changes{'coursecredits'} = 1;
9258: } else {
9259: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 9260: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9261: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 9262: $changes{'coursecredits'} = 1;
9263: }
9264: }
9265: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9266: official => $officialcreds,
9267: unofficial => $unofficialcreds,
1.216 raeburn 9268: textbook => $textbookcreds,
1.192 raeburn 9269: }
1.121 raeburn 9270: }
9271: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9272: $dom);
9273: if ($putresult eq 'ok') {
9274: if (keys(%changes) > 0) {
1.213 raeburn 9275: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 9276: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 9277: ($changes{'uploadquota'})) {
1.192 raeburn 9278: if ($changes{'canuse_pdfforms'}) {
9279: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9280: }
9281: if ($changes{'coursecredits'}) {
9282: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9283: $domdefaults{'officialcredits'} =
9284: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9285: $domdefaults{'unofficialcredits'} =
9286: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 9287: $domdefaults{'textbookcredits'} =
9288: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9289: }
9290: }
1.198 raeburn 9291: if ($changes{'uploadquota'}) {
9292: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9293: foreach my $type (@types) {
9294: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9295: }
9296: }
9297: }
1.121 raeburn 9298: my $cachetime = 24*60*60;
9299: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9300: if (ref($lastactref) eq 'HASH') {
9301: $lastactref->{'domdefaults'} = 1;
9302: }
1.121 raeburn 9303: }
9304: $resulttext = &mt('Changes made:').'<ul>';
9305: foreach my $item (sort(keys(%changes))) {
9306: if ($item eq 'canuse_pdfforms') {
9307: if ($env{'form.'.$item} eq '1') {
9308: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9309: } else {
9310: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9311: }
1.139 raeburn 9312: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9313: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9314: } elsif ($item eq 'uploadquota') {
9315: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9316: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9317: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9318: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9319: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9320:
1.198 raeburn 9321: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9322: '</ul>'.
9323: '</li>';
9324: } else {
9325: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9326: }
1.192 raeburn 9327: } elsif ($item eq 'coursecredits') {
9328: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9329: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9330: ($domdefaults{'unofficialcredits'} eq '') &&
9331: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9332: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9333: } else {
9334: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9335: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9336: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9337: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9338: '</ul>'.
9339: '</li>';
9340: }
9341: } else {
9342: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9343: }
1.140 raeburn 9344: }
1.121 raeburn 9345: }
9346: $resulttext .= '</ul>';
9347: } else {
9348: $resulttext = &mt('No changes made to course defaults');
9349: }
9350: } else {
9351: $resulttext = '<span class="LC_error">'.
9352: &mt('An error occurred: [_1]',$putresult).'</span>';
9353: }
9354: return $resulttext;
9355: }
9356:
1.231 raeburn 9357: sub modify_selfenrollment {
9358: my ($dom,$lastactref,%domconfig) = @_;
9359: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
9360: my @types = ('official','unofficial','community','textbook');
9361: my %titles = &tool_titles();
1.232 ! raeburn 9362: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
! 9363: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 9364: $ordered{'default'} = ['types','registered','approval','limit'];
9365:
9366: my (%roles,%shown,%toplevel);
9367: $roles{'0'} = &Apache::lonnet::plaintext('dc');
9368:
9369: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
9370: if ($domconfig{'selfenrollment'} eq '') {
9371: $domconfig{'selfenrollment'} = {};
9372: }
9373: }
9374: %toplevel = (
9375: admin => 'Configuration Rights',
9376: default => 'Default settings',
9377: validation => 'Validation of self-enrollment requests',
9378: );
9379: my ($itemsref,$namesref,$fieldsref) = &selfenroll_validation_types();
9380:
9381: if (ref($ordered{'admin'}) eq 'ARRAY') {
9382: foreach my $item (@{$ordered{'admin'}}) {
9383: foreach my $type (@types) {
9384: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
9385: $selfenrollhash{'admin'}{$type}{$item} = 1;
9386: } else {
9387: $selfenrollhash{'admin'}{$type}{$item} = 0;
9388: }
9389: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
9390: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
9391: if ($selfenrollhash{'admin'}{$type}{$item} ne
9392: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
9393: push(@{$changes{'admin'}{$type}},$item);
9394: }
9395: } else {
9396: if (!$selfenrollhash{'admin'}{$type}{$item}) {
9397: push(@{$changes{'admin'}{$type}},$item);
9398: }
9399: }
9400: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
9401: push(@{$changes{'admin'}{$type}},$item);
9402: }
9403: }
9404: }
9405: }
9406:
9407: foreach my $item (@{$ordered{'default'}}) {
9408: foreach my $type (@types) {
9409: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
9410: if ($item eq 'types') {
9411: unless (($value eq 'all') || ($value eq 'dom')) {
9412: $value = '';
9413: }
9414: } elsif ($item eq 'registered') {
9415: unless ($value eq '1') {
9416: $value = 0;
9417: }
9418: } elsif ($item eq 'approval') {
9419: unless ($value =~ /^[012]$/) {
9420: $value = 0;
9421: }
9422: } else {
9423: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9424: $value = 'none';
9425: }
9426: }
9427: $selfenrollhash{'default'}{$type}{$item} = $value;
9428: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
9429: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9430: if ($selfenrollhash{'default'}{$type}{$item} ne
9431: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
9432: push(@{$changes{'default'}{$type}},$item);
9433: }
9434: } else {
9435: push(@{$changes{'default'}{$type}},$item);
9436: }
9437: } else {
9438: push(@{$changes{'default'}{$type}},$item);
9439: }
9440: if ($item eq 'limit') {
9441: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9442: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
9443: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
9444: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
9445: }
9446: } else {
9447: $selfenrollhash{'default'}{$type}{'cap'} = '';
9448: }
9449: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9450: if ($selfenrollhash{'default'}{$type}{'cap'} ne
9451: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
9452: push(@{$changes{'default'}{$type}},'cap');
9453: }
9454: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
9455: push(@{$changes{'default'}{$type}},'cap');
9456: }
9457: }
9458: }
9459: }
9460:
9461: foreach my $item (@{$itemsref}) {
9462: if ($item eq 'fields') {
9463: my @changed;
9464: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
9465: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
9466: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
9467: }
9468: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
9469: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
9470: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
9471: $domconfig{'selfenrollment'}{'validation'}{$item});
9472: } else {
9473: @changed = @{$selfenrollhash{'validation'}{$item}};
9474: }
9475: } else {
9476: @changed = @{$selfenrollhash{'validation'}{$item}};
9477: }
9478: if (@changed) {
9479: if ($selfenrollhash{'validation'}{$item}) {
9480: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
9481: } else {
9482: $changes{'validation'}{$item} = &mt('None');
9483: }
9484: }
9485: } else {
9486: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
9487: if ($item eq 'markup') {
9488: if ($env{'form.selfenroll_validation_'.$item}) {
9489: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9490: }
9491: }
9492: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
9493: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
9494: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
9495: }
9496: }
9497: }
9498: }
9499:
9500: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
9501: $dom);
9502: if ($putresult eq 'ok') {
9503: if (keys(%changes) > 0) {
9504: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9505: $resulttext = &mt('Changes made:').'<ul>';
9506: foreach my $key ('admin','default','validation') {
9507: if (ref($changes{$key}) eq 'HASH') {
9508: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
9509: if ($key eq 'validation') {
9510: foreach my $item (@{$itemsref}) {
9511: if (exists($changes{$key}{$item})) {
9512: if ($item eq 'markup') {
9513: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
9514: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
9515: } else {
9516: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
9517: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
9518: }
9519: }
9520: }
9521: } else {
9522: foreach my $type (@types) {
9523: if ($type eq 'community') {
9524: $roles{'1'} = &mt('Community personnel');
9525: } else {
9526: $roles{'1'} = &mt('Course personnel');
9527: }
9528: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 ! raeburn 9529: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
! 9530: if ($key eq 'admin') {
! 9531: my @mgrdc = ();
! 9532: if (ref($ordered{$key}) eq 'ARRAY') {
! 9533: foreach my $item (@{$ordered{'admin'}}) {
! 9534: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
! 9535: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
! 9536: push(@mgrdc,$item);
! 9537: }
! 9538: }
! 9539: }
! 9540: if (@mgrdc) {
! 9541: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
! 9542: } else {
! 9543: delete($domdefaults{$type.'selfenrolladmdc'});
! 9544: }
! 9545: }
! 9546: } else {
! 9547: if (ref($ordered{$key}) eq 'ARRAY') {
! 9548: foreach my $item (@{$ordered{$key}}) {
! 9549: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
! 9550: $domdefaults{$type.'selfenroll'.$item} =
! 9551: $selfenrollhash{$key}{$type}{$item};
! 9552: }
! 9553: }
! 9554: }
! 9555: }
! 9556: }
1.231 raeburn 9557: $resulttext .= '<li>'.$titles{$type}.'<ul>';
9558: foreach my $item (@{$ordered{$key}}) {
9559: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
9560: $resulttext .= '<li>';
9561: if ($key eq 'admin') {
9562: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
9563: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
9564: } else {
9565: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
9566: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
9567: }
9568: $resulttext .= '</li>';
9569: }
9570: }
9571: $resulttext .= '</ul></li>';
9572: }
9573: }
9574: $resulttext .= '</ul></li>';
9575: }
9576: }
1.232 ! raeburn 9577: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
! 9578: my $cachetime = 24*60*60;
! 9579: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 9580: if (ref($lastactref) eq 'HASH') {
! 9581: $lastactref->{'domdefaults'} = 1;
! 9582: }
! 9583: }
1.231 raeburn 9584: }
9585: $resulttext .= '</ul>';
9586: } else {
9587: $resulttext = &mt('No changes made to self-enrollment settings');
9588: }
9589: } else {
9590: $resulttext = '<span class="LC_error">'.
9591: &mt('An error occurred: [_1]',$putresult).'</span>';
9592: }
9593: return $resulttext;
9594: }
9595:
1.137 raeburn 9596: sub modify_usersessions {
1.212 raeburn 9597: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9598: my @hostingtypes = ('version','excludedomain','includedomain');
9599: my @offloadtypes = ('primary','default');
9600: my %types = (
9601: remote => \@hostingtypes,
9602: hosted => \@hostingtypes,
9603: spares => \@offloadtypes,
9604: );
9605: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9606: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9607: my (%by_ip,%by_location,@intdoms);
9608: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9609: my @locations = sort(keys(%by_location));
1.137 raeburn 9610: my (%defaultshash,%changes);
9611: foreach my $prefix (@prefixes) {
9612: $defaultshash{'usersessions'}{$prefix} = {};
9613: }
1.212 raeburn 9614: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9615: my $resulttext;
1.138 raeburn 9616: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9617: foreach my $prefix (@prefixes) {
1.145 raeburn 9618: next if ($prefix eq 'spares');
9619: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9620: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9621: if ($type eq 'version') {
9622: my $value = $env{'form.'.$prefix.'_'.$type};
9623: my $okvalue;
9624: if ($value ne '') {
9625: if (grep(/^\Q$value\E$/,@lcversions)) {
9626: $okvalue = $value;
9627: }
9628: }
9629: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9630: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9631: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9632: if ($inuse == 0) {
9633: $changes{$prefix}{$type} = 1;
9634: } else {
9635: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9636: $changes{$prefix}{$type} = 1;
9637: }
9638: if ($okvalue ne '') {
9639: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9640: }
9641: }
9642: } else {
9643: if (($inuse == 1) && ($okvalue ne '')) {
9644: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9645: $changes{$prefix}{$type} = 1;
9646: }
9647: }
9648: } else {
9649: if (($inuse == 1) && ($okvalue ne '')) {
9650: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9651: $changes{$prefix}{$type} = 1;
9652: }
9653: }
9654: } else {
9655: if (($inuse == 1) && ($okvalue ne '')) {
9656: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9657: $changes{$prefix}{$type} = 1;
9658: }
9659: }
9660: } else {
9661: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9662: my @okvals;
9663: foreach my $val (@vals) {
1.138 raeburn 9664: if ($val =~ /:/) {
9665: my @items = split(/:/,$val);
9666: foreach my $item (@items) {
9667: if (ref($by_location{$item}) eq 'ARRAY') {
9668: push(@okvals,$item);
9669: }
9670: }
9671: } else {
9672: if (ref($by_location{$val}) eq 'ARRAY') {
9673: push(@okvals,$val);
9674: }
1.137 raeburn 9675: }
9676: }
9677: @okvals = sort(@okvals);
9678: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9679: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9680: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9681: if ($inuse == 0) {
9682: $changes{$prefix}{$type} = 1;
9683: } else {
9684: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9685: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9686: if (@changed > 0) {
9687: $changes{$prefix}{$type} = 1;
9688: }
9689: }
9690: } else {
9691: if ($inuse == 1) {
9692: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9693: $changes{$prefix}{$type} = 1;
9694: }
9695: }
9696: } else {
9697: if ($inuse == 1) {
9698: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9699: $changes{$prefix}{$type} = 1;
9700: }
9701: }
9702: } else {
9703: if ($inuse == 1) {
9704: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9705: $changes{$prefix}{$type} = 1;
9706: }
9707: }
9708: }
9709: }
9710: }
1.145 raeburn 9711:
9712: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9713: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9714: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9715: my $savespares;
9716:
9717: foreach my $lonhost (sort(keys(%servers))) {
9718: my $serverhomeID =
9719: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9720: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9721: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9722: my %spareschg;
9723: foreach my $type (@{$types{'spares'}}) {
9724: my @okspares;
9725: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9726: foreach my $server (@checked) {
1.152 raeburn 9727: if (&Apache::lonnet::hostname($server) ne '') {
9728: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9729: unless (grep(/^\Q$server\E$/,@okspares)) {
9730: push(@okspares,$server);
9731: }
1.145 raeburn 9732: }
9733: }
9734: }
9735: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9736: my $newspare;
1.152 raeburn 9737: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9738: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9739: $newspare = $new;
9740: }
9741: }
1.152 raeburn 9742: my @spares;
9743: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9744: @spares = sort(@okspares,$newspare);
9745: } else {
9746: @spares = sort(@okspares);
9747: }
9748: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9749: if (ref($spareid{$lonhost}) eq 'HASH') {
9750: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9751: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9752: if (@diffs > 0) {
9753: $spareschg{$type} = 1;
9754: }
9755: }
9756: }
9757: }
9758: if (keys(%spareschg) > 0) {
9759: $changes{'spares'}{$lonhost} = \%spareschg;
9760: }
9761: }
9762:
9763: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9764: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9765: if (ref($changes{'spares'}) eq 'HASH') {
9766: if (keys(%{$changes{'spares'}}) > 0) {
9767: $savespares = 1;
9768: }
9769: }
9770: } else {
9771: $savespares = 1;
9772: }
9773: }
9774:
1.147 raeburn 9775: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9776: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9777: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9778: $dom);
9779: if ($putresult eq 'ok') {
9780: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9781: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9782: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9783: }
9784: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9785: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9786: }
9787: }
9788: my $cachetime = 24*60*60;
9789: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9790: if (ref($lastactref) eq 'HASH') {
9791: $lastactref->{'domdefaults'} = 1;
9792: }
1.147 raeburn 9793: if (keys(%changes) > 0) {
9794: my %lt = &usersession_titles();
9795: $resulttext = &mt('Changes made:').'<ul>';
9796: foreach my $prefix (@prefixes) {
9797: if (ref($changes{$prefix}) eq 'HASH') {
9798: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9799: if ($prefix eq 'spares') {
9800: if (ref($changes{$prefix}) eq 'HASH') {
9801: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9802: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9803: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 9804: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9805: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9806: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9807: foreach my $type (@{$types{$prefix}}) {
9808: if ($changes{$prefix}{$lonhost}{$type}) {
9809: my $offloadto = &mt('None');
9810: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9811: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9812: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9813: }
1.145 raeburn 9814: }
1.147 raeburn 9815: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9816: }
1.137 raeburn 9817: }
9818: }
1.147 raeburn 9819: $resulttext .= '</li>';
1.137 raeburn 9820: }
9821: }
1.147 raeburn 9822: } else {
9823: foreach my $type (@{$types{$prefix}}) {
9824: if (defined($changes{$prefix}{$type})) {
9825: my $newvalue;
9826: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9827: if (ref($defaultshash{'usersessions'}{$prefix})) {
9828: if ($type eq 'version') {
9829: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9830: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9831: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9832: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9833: }
1.145 raeburn 9834: }
9835: }
9836: }
1.147 raeburn 9837: if ($newvalue eq '') {
9838: if ($type eq 'version') {
9839: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
9840: } else {
9841: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
9842: }
1.145 raeburn 9843: } else {
1.147 raeburn 9844: if ($type eq 'version') {
9845: $newvalue .= ' '.&mt('(or later)');
9846: }
9847: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 9848: }
1.137 raeburn 9849: }
9850: }
9851: }
1.147 raeburn 9852: $resulttext .= '</ul>';
1.137 raeburn 9853: }
9854: }
1.147 raeburn 9855: $resulttext .= '</ul>';
9856: } else {
9857: $resulttext = $nochgmsg;
1.137 raeburn 9858: }
9859: } else {
9860: $resulttext = '<span class="LC_error">'.
9861: &mt('An error occurred: [_1]',$putresult).'</span>';
9862: }
9863: } else {
1.147 raeburn 9864: $resulttext = $nochgmsg;
1.137 raeburn 9865: }
9866: return $resulttext;
9867: }
9868:
1.150 raeburn 9869: sub modify_loadbalancing {
9870: my ($dom,%domconfig) = @_;
9871: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9872: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9873: my ($othertitle,$usertypes,$types) =
9874: &Apache::loncommon::sorted_inst_types($dom);
9875: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9876: my @sparestypes = ('primary','default');
9877: my %typetitles = &sparestype_titles();
9878: my $resulttext;
1.171 raeburn 9879: my (%currbalancer,%currtargets,%currrules,%existing);
9880: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9881: %existing = %{$domconfig{'loadbalancing'}};
9882: }
9883: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
9884: \%currtargets,\%currrules);
9885: my ($saveloadbalancing,%defaultshash,%changes);
9886: my ($alltypes,$othertypes,$titles) =
9887: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9888: my %ruletitles = &offloadtype_text();
9889: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
9890: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
9891: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
9892: if ($balancer eq '') {
9893: next;
9894: }
1.210 raeburn 9895: if (!exists($servers{$balancer})) {
1.171 raeburn 9896: if (exists($currbalancer{$balancer})) {
9897: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 9898: }
1.171 raeburn 9899: next;
9900: }
9901: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
9902: push(@{$changes{'delete'}},$balancer);
9903: next;
9904: }
9905: if (!exists($currbalancer{$balancer})) {
9906: push(@{$changes{'add'}},$balancer);
9907: }
9908: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
9909: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
9910: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
9911: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
9912: $saveloadbalancing = 1;
9913: }
9914: foreach my $sparetype (@sparestypes) {
9915: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
9916: my @offloadto;
9917: foreach my $target (@targets) {
9918: if (($servers{$target}) && ($target ne $balancer)) {
9919: if ($sparetype eq 'default') {
9920: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
9921: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 9922: }
9923: }
1.171 raeburn 9924: unless(grep(/^\Q$target\E$/,@offloadto)) {
9925: push(@offloadto,$target);
9926: }
1.150 raeburn 9927: }
1.171 raeburn 9928: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 9929: }
9930: }
1.171 raeburn 9931: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 9932: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9933: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
9934: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 9935: if (@targetdiffs > 0) {
1.171 raeburn 9936: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9937: }
1.171 raeburn 9938: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9939: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9940: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 9941: }
9942: }
9943: }
9944: } else {
1.171 raeburn 9945: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 9946: foreach my $sparetype (@sparestypes) {
1.171 raeburn 9947: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
9948: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
9949: $changes{'curr'}{$balancer}{'targets'} = 1;
9950: }
1.150 raeburn 9951: }
9952: }
1.210 raeburn 9953: }
1.150 raeburn 9954: }
9955: my $ishomedom;
1.171 raeburn 9956: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
9957: $ishomedom = 1;
1.150 raeburn 9958: }
9959: if (ref($alltypes) eq 'ARRAY') {
9960: foreach my $type (@{$alltypes}) {
9961: my $rule;
1.210 raeburn 9962: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 9963: (!$ishomedom)) {
1.171 raeburn 9964: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
9965: }
9966: if ($rule eq 'specific') {
9967: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 9968: }
1.171 raeburn 9969: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
9970: if (ref($currrules{$balancer}) eq 'HASH') {
9971: if ($rule ne $currrules{$balancer}{$type}) {
9972: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9973: }
9974: } elsif ($rule ne '') {
1.171 raeburn 9975: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 9976: }
9977: }
9978: }
1.171 raeburn 9979: }
9980: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
9981: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
9982: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
9983: $defaultshash{'loadbalancing'} = {};
9984: }
9985: my $putresult = &Apache::lonnet::put_dom('configuration',
9986: \%defaultshash,$dom);
9987: if ($putresult eq 'ok') {
9988: if (keys(%changes) > 0) {
9989: if (ref($changes{'delete'}) eq 'ARRAY') {
9990: foreach my $balancer (sort(@{$changes{'delete'}})) {
9991: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 9992: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
9993: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 9994: }
1.171 raeburn 9995: }
9996: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 9997: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 9998: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
9999: }
10000: }
10001: if (ref($changes{'curr'}) eq 'HASH') {
10002: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10003: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10004: if ($changes{'curr'}{$balancer}{'targets'}) {
10005: my %offloadstr;
10006: foreach my $sparetype (@sparestypes) {
10007: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10008: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10009: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10010: }
10011: }
1.150 raeburn 10012: }
1.171 raeburn 10013: if (keys(%offloadstr) == 0) {
10014: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10015: } else {
1.171 raeburn 10016: my $showoffload;
10017: foreach my $sparetype (@sparestypes) {
10018: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10019: if (defined($offloadstr{$sparetype})) {
10020: $showoffload .= $offloadstr{$sparetype};
10021: } else {
10022: $showoffload .= &mt('None');
10023: }
10024: $showoffload .= (' 'x3);
10025: }
10026: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10027: }
10028: }
10029: }
1.171 raeburn 10030: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10031: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10032: foreach my $type (@{$alltypes}) {
10033: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10034: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10035: my $balancetext;
10036: if ($rule eq '') {
10037: $balancetext = $ruletitles{'default'};
1.209 raeburn 10038: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10039: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 10040: $balancetext = $ruletitles{$rule};
10041: } else {
10042: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10043: }
1.210 raeburn 10044: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10045: }
10046: }
10047: }
10048: }
1.215 raeburn 10049: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 10050: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10051: }
1.171 raeburn 10052: }
10053: if ($resulttext ne '') {
10054: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10055: } else {
10056: $resulttext = $nochgmsg;
10057: }
10058: } else {
1.171 raeburn 10059: $resulttext = $nochgmsg;
1.150 raeburn 10060: }
10061: } else {
1.171 raeburn 10062: $resulttext = '<span class="LC_error">'.
10063: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10064: }
10065: } else {
1.171 raeburn 10066: $resulttext = $nochgmsg;
1.150 raeburn 10067: }
10068: return $resulttext;
10069: }
10070:
1.48 raeburn 10071: sub recurse_check {
10072: my ($chkcats,$categories,$depth,$name) = @_;
10073: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10074: my $chg = 0;
10075: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10076: my $category = $chkcats->[$depth]{$name}[$j];
10077: my $item;
10078: if ($category eq '') {
10079: $chg ++;
10080: } else {
10081: my $deeper = $depth + 1;
10082: $item = &escape($category).':'.&escape($name).':'.$depth;
10083: if ($chg) {
10084: $categories->{$item} -= $chg;
10085: }
10086: &recurse_check($chkcats,$categories,$deeper,$category);
10087: $deeper --;
10088: }
10089: }
10090: }
10091: return;
10092: }
10093:
10094: sub recurse_cat_deletes {
10095: my ($item,$coursecategories,$deletions) = @_;
10096: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10097: my $subdepth = $depth + 1;
10098: if (ref($coursecategories) eq 'HASH') {
10099: foreach my $subitem (keys(%{$coursecategories})) {
10100: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10101: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10102: delete($coursecategories->{$subitem});
10103: $deletions->{$subitem} = 1;
10104: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10105: }
1.48 raeburn 10106: }
10107: }
10108: return;
10109: }
10110:
1.125 raeburn 10111: sub get_active_dcs {
10112: my ($dom) = @_;
1.191 raeburn 10113: my $now = time;
10114: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10115: my %domcoords;
10116: my $numdcs = 0;
10117: foreach my $server (keys(%dompersonnel)) {
10118: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10119: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10120: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10121: }
10122: }
10123: return %domcoords;
10124: }
10125:
10126: sub active_dc_picker {
1.191 raeburn 10127: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 10128: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10129: my @domcoord = keys(%domcoords);
10130: if (keys(%currhash)) {
10131: foreach my $dc (keys(%currhash)) {
10132: unless (exists($domcoords{$dc})) {
10133: push(@domcoord,$dc);
10134: }
10135: }
10136: }
10137: @domcoord = sort(@domcoord);
1.210 raeburn 10138: my $numdcs = scalar(@domcoord);
1.191 raeburn 10139: my $rows = 0;
10140: my $table;
1.125 raeburn 10141: if ($numdcs > 1) {
1.191 raeburn 10142: $table = '<table>';
10143: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10144: my $rem = $i%($numinrow);
10145: if ($rem == 0) {
10146: if ($i > 0) {
1.191 raeburn 10147: $table .= '</tr>';
1.125 raeburn 10148: }
1.191 raeburn 10149: $table .= '<tr>';
10150: $rows ++;
1.125 raeburn 10151: }
1.191 raeburn 10152: my $check = '';
10153: if ($inputtype eq 'radio') {
10154: if (keys(%currhash) == 0) {
10155: if (!$i) {
10156: $check = ' checked="checked"';
10157: }
10158: } elsif (exists($currhash{$domcoord[$i]})) {
10159: $check = ' checked="checked"';
10160: }
10161: } else {
10162: if (exists($currhash{$domcoord[$i]})) {
10163: $check = ' checked="checked"';
1.125 raeburn 10164: }
10165: }
1.191 raeburn 10166: if ($i == @domcoord - 1) {
1.125 raeburn 10167: my $colsleft = $numinrow - $rem;
10168: if ($colsleft > 1) {
1.191 raeburn 10169: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10170: } else {
1.191 raeburn 10171: $table .= '<td class="LC_left_item">';
1.125 raeburn 10172: }
10173: } else {
1.191 raeburn 10174: $table .= '<td class="LC_left_item">';
10175: }
10176: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10177: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10178: $table .= '<span class="LC_nobreak"><label>'.
10179: '<input type="'.$inputtype.'" name="'.$name.'"'.
10180: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10181: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 10182: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 10183: }
1.219 raeburn 10184: $table .= '</label></span></td>';
1.191 raeburn 10185: }
10186: $table .= '</tr></table>';
10187: } elsif ($numdcs == 1) {
1.219 raeburn 10188: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10189: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 10190: if ($inputtype eq 'radio') {
1.219 raeburn 10191: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10192: if ($user ne $dcname.':'.$dcdom) {
10193: $table .= ' ('.$dcname.':'.$dcdom.')';
10194: }
1.191 raeburn 10195: } else {
10196: my $check;
10197: if (exists($currhash{$domcoord[0]})) {
10198: $check = ' checked="checked"';
1.125 raeburn 10199: }
1.219 raeburn 10200: $table .= '<span class="LC_nobreak"><label>'.
10201: '<input type="checkbox" name="'.$name.'" '.
10202: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10203: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 10204: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 10205: }
1.220 raeburn 10206: $table .= '</label></span>';
1.191 raeburn 10207: $rows ++;
1.125 raeburn 10208: }
10209: }
1.191 raeburn 10210: return ($numdcs,$table,$rows);
1.125 raeburn 10211: }
10212:
1.137 raeburn 10213: sub usersession_titles {
10214: return &Apache::lonlocal::texthash(
10215: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10216: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10217: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10218: version => 'LON-CAPA version requirement',
1.138 raeburn 10219: excludedomain => 'Allow all, but exclude specific domains',
10220: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10221: primary => 'Primary (checked first)',
1.154 raeburn 10222: default => 'Default',
1.137 raeburn 10223: );
10224: }
10225:
1.152 raeburn 10226: sub id_for_thisdom {
10227: my (%servers) = @_;
10228: my %altids;
10229: foreach my $server (keys(%servers)) {
10230: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10231: if ($serverhome ne $server) {
10232: $altids{$serverhome} = $server;
10233: }
10234: }
10235: return %altids;
10236: }
10237:
1.150 raeburn 10238: sub count_servers {
10239: my ($currbalancer,%servers) = @_;
10240: my (@spares,$numspares);
10241: foreach my $lonhost (sort(keys(%servers))) {
10242: next if ($currbalancer eq $lonhost);
10243: push(@spares,$lonhost);
10244: }
10245: if ($currbalancer) {
10246: $numspares = scalar(@spares);
10247: } else {
10248: $numspares = scalar(@spares) - 1;
10249: }
10250: return ($numspares,@spares);
10251: }
10252:
10253: sub lonbalance_targets_js {
1.171 raeburn 10254: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 10255: my $select = &mt('Select');
10256: my ($alltargets,$allishome,$allinsttypes,@alltypes);
10257: if (ref($servers) eq 'HASH') {
10258: $alltargets = join("','",sort(keys(%{$servers})));
10259: my @homedoms;
10260: foreach my $server (sort(keys(%{$servers}))) {
10261: if (&Apache::lonnet::host_domain($server) eq $dom) {
10262: push(@homedoms,'1');
10263: } else {
10264: push(@homedoms,'0');
10265: }
10266: }
10267: $allishome = join("','",@homedoms);
10268: }
10269: if (ref($types) eq 'ARRAY') {
10270: if (@{$types} > 0) {
10271: @alltypes = @{$types};
10272: }
10273: }
10274: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
10275: $allinsttypes = join("','",@alltypes);
1.171 raeburn 10276: my (%currbalancer,%currtargets,%currrules,%existing);
10277: if (ref($settings) eq 'HASH') {
10278: %existing = %{$settings};
10279: }
10280: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
10281: \%currtargets,\%currrules);
1.210 raeburn 10282: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 10283: return <<"END";
10284:
10285: <script type="text/javascript">
10286: // <![CDATA[
10287:
1.171 raeburn 10288: currBalancers = new Array('$balancers');
10289:
10290: function toggleTargets(balnum) {
10291: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10292: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
10293: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
10294: var prevbalancer = prevhostitem.value;
10295: var baltotal = document.getElementById('loadbalancing_total').value;
10296: prevhostitem.value = balancer;
10297: if (prevbalancer != '') {
10298: var prevIdx = currBalancers.indexOf(prevbalancer);
10299: if (prevIdx != -1) {
10300: currBalancers.splice(prevIdx,1);
10301: }
10302: }
1.150 raeburn 10303: if (balancer == '') {
1.171 raeburn 10304: hideSpares(balnum);
1.150 raeburn 10305: } else {
1.171 raeburn 10306: var currIdx = currBalancers.indexOf(balancer);
10307: if (currIdx == -1) {
10308: currBalancers.push(balancer);
10309: }
1.150 raeburn 10310: var homedoms = new Array('$allishome');
1.171 raeburn 10311: var ishomedom = homedoms[lonhostitem.selectedIndex];
10312: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 10313: }
1.171 raeburn 10314: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 10315: return;
10316: }
10317:
1.171 raeburn 10318: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 10319: var alltargets = new Array('$alltargets');
10320: var insttypes = new Array('$allinsttypes');
1.151 raeburn 10321: var offloadtypes = new Array('primary','default');
10322:
1.171 raeburn 10323: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
10324: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 10325:
1.151 raeburn 10326: for (var i=0; i<offloadtypes.length; i++) {
10327: var count = 0;
10328: for (var j=0; j<alltargets.length; j++) {
10329: if (alltargets[j] != balancer) {
1.171 raeburn 10330: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
10331: item.value = alltargets[j];
10332: item.style.textAlign='left';
10333: item.style.textFace='normal';
10334: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
10335: if (currBalancers.indexOf(alltargets[j]) == -1) {
10336: item.disabled = '';
10337: } else {
10338: item.disabled = 'disabled';
10339: item.checked = false;
10340: }
1.151 raeburn 10341: count ++;
10342: }
1.150 raeburn 10343: }
10344: }
1.151 raeburn 10345: for (var k=0; k<insttypes.length; k++) {
10346: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 10347: if (ishomedom == 1) {
1.171 raeburn 10348: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10349: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10350: } else {
1.171 raeburn 10351: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10352: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 10353: }
10354: } else {
1.171 raeburn 10355: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10356: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10357: }
1.151 raeburn 10358: if ((insttypes[k] != '_LC_external') &&
10359: ((insttypes[k] != '_LC_internetdom') ||
10360: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 10361: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
10362: item.options.length = 0;
10363: item.options[0] = new Option("","",true,true);
1.210 raeburn 10364: var idx = 0;
1.151 raeburn 10365: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 10366: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
10367: idx ++;
10368: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 10369: }
10370: }
10371: }
10372: }
10373: return;
10374: }
10375:
1.171 raeburn 10376: function hideSpares(balnum) {
1.150 raeburn 10377: var alltargets = new Array('$alltargets');
10378: var insttypes = new Array('$allinsttypes');
10379: var offloadtypes = new Array('primary','default');
10380:
1.171 raeburn 10381: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
10382: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 10383:
10384: var total = alltargets.length - 1;
10385: for (var i=0; i<offloadtypes; i++) {
10386: for (var j=0; j<total; j++) {
1.171 raeburn 10387: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
10388: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
10389: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 10390: }
1.150 raeburn 10391: }
10392: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 10393: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10394: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 10395: if (insttypes[k] != '_LC_external') {
1.171 raeburn 10396: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
10397: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 10398: }
10399: }
10400: return;
10401: }
10402:
1.171 raeburn 10403: function checkOffloads(item,balnum,type) {
1.150 raeburn 10404: var alltargets = new Array('$alltargets');
10405: var offloadtypes = new Array('primary','default');
10406: if (item.checked) {
10407: var total = alltargets.length - 1;
10408: var other;
10409: if (type == offloadtypes[0]) {
1.151 raeburn 10410: other = offloadtypes[1];
1.150 raeburn 10411: } else {
1.151 raeburn 10412: other = offloadtypes[0];
1.150 raeburn 10413: }
10414: for (var i=0; i<total; i++) {
1.171 raeburn 10415: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 10416: if (server == item.value) {
1.171 raeburn 10417: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
10418: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 10419: }
10420: }
10421: }
10422: }
10423: return;
10424: }
10425:
1.171 raeburn 10426: function singleServerToggle(balnum,type) {
10427: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 10428: if (offloadtoSelIdx == 0) {
1.171 raeburn 10429: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
10430: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10431:
10432: } else {
1.171 raeburn 10433: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
10434: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 10435: }
10436: return;
10437: }
10438:
1.171 raeburn 10439: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 10440: if (type == '_LC_external') {
1.171 raeburn 10441: return;
1.150 raeburn 10442: }
1.171 raeburn 10443: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 10444: for (var i=0; i<typesRules.length; i++) {
10445: if (formname.elements[typesRules[i]].checked) {
10446: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 10447: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
10448: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10449: } else {
1.171 raeburn 10450: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10451: }
10452: }
10453: }
10454: return;
10455: }
10456:
10457: function balancerDeleteChange(balnum) {
10458: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10459: var baltotal = document.getElementById('loadbalancing_total').value;
10460: var addtarget;
10461: var removetarget;
10462: var action = 'delete';
10463: if (document.getElementById('loadbalancing_delete_'+balnum)) {
10464: var lonhost = hostitem.value;
10465: var currIdx = currBalancers.indexOf(lonhost);
10466: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
10467: if (currIdx != -1) {
10468: currBalancers.splice(currIdx,1);
10469: }
10470: addtarget = lonhost;
10471: } else {
10472: if (currIdx == -1) {
10473: currBalancers.push(lonhost);
10474: }
10475: removetarget = lonhost;
10476: action = 'undelete';
10477: }
10478: balancerChange(balnum,baltotal,action,addtarget,removetarget);
10479: }
10480: return;
10481: }
10482:
10483: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
10484: if (baltotal > 1) {
10485: var offloadtypes = new Array('primary','default');
10486: var alltargets = new Array('$alltargets');
10487: var insttypes = new Array('$allinsttypes');
10488: for (var i=0; i<baltotal; i++) {
10489: if (i != balnum) {
10490: for (var j=0; j<offloadtypes.length; j++) {
10491: var total = alltargets.length - 1;
10492: for (var k=0; k<total; k++) {
10493: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
10494: var server = serveritem.value;
10495: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10496: if (server == addtarget) {
10497: serveritem.disabled = '';
10498: }
10499: }
10500: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10501: if (server == removetarget) {
10502: serveritem.disabled = 'disabled';
10503: serveritem.checked = false;
10504: }
10505: }
10506: }
10507: }
10508: for (var j=0; j<insttypes.length; j++) {
10509: if (insttypes[j] != '_LC_external') {
10510: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
10511: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
10512: var currSel = singleserver.selectedIndex;
10513: var currVal = singleserver.options[currSel].value;
10514: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10515: var numoptions = singleserver.options.length;
10516: var needsnew = 1;
10517: for (var k=0; k<numoptions; k++) {
10518: if (singleserver.options[k] == addtarget) {
10519: needsnew = 0;
10520: break;
10521: }
10522: }
10523: if (needsnew == 1) {
10524: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
10525: }
10526: }
10527: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10528: singleserver.options.length = 0;
10529: if ((currVal) && (currVal != removetarget)) {
10530: singleserver.options[0] = new Option("","",false,false);
10531: } else {
10532: singleserver.options[0] = new Option("","",true,true);
10533: }
10534: var idx = 0;
10535: for (var m=0; m<alltargets.length; m++) {
10536: if (currBalancers.indexOf(alltargets[m]) == -1) {
10537: idx ++;
10538: if (currVal == alltargets[m]) {
10539: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
10540: } else {
10541: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10542: }
10543: }
10544: }
10545: }
10546: }
10547: }
10548: }
1.150 raeburn 10549: }
10550: }
10551: }
10552: return;
10553: }
10554:
1.152 raeburn 10555: // ]]>
10556: </script>
10557:
10558: END
10559: }
10560:
10561: sub new_spares_js {
10562: my @sparestypes = ('primary','default');
10563: my $types = join("','",@sparestypes);
10564: my $select = &mt('Select');
10565: return <<"END";
10566:
10567: <script type="text/javascript">
10568: // <![CDATA[
10569:
10570: function updateNewSpares(formname,lonhost) {
10571: var types = new Array('$types');
10572: var include = new Array();
10573: var exclude = new Array();
10574: for (var i=0; i<types.length; i++) {
10575: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10576: for (var j=0; j<spareboxes.length; j++) {
10577: if (formname.elements[spareboxes[j]].checked) {
10578: exclude.push(formname.elements[spareboxes[j]].value);
10579: } else {
10580: include.push(formname.elements[spareboxes[j]].value);
10581: }
10582: }
10583: }
10584: for (var i=0; i<types.length; i++) {
10585: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10586: var selIdx = newSpare.selectedIndex;
10587: var currnew = newSpare.options[selIdx].value;
10588: var okSpares = new Array();
10589: for (var j=0; j<newSpare.options.length; j++) {
10590: var possible = newSpare.options[j].value;
10591: if (possible != '') {
10592: if (exclude.indexOf(possible) == -1) {
10593: okSpares.push(possible);
10594: } else {
10595: if (currnew == possible) {
10596: selIdx = 0;
10597: }
10598: }
10599: }
10600: }
10601: for (var k=0; k<include.length; k++) {
10602: if (okSpares.indexOf(include[k]) == -1) {
10603: okSpares.push(include[k]);
10604: }
10605: }
10606: okSpares.sort();
10607: newSpare.options.length = 0;
10608: if (selIdx == 0) {
10609: newSpare.options[0] = new Option("$select","",true,true);
10610: } else {
10611: newSpare.options[0] = new Option("$select","",false,false);
10612: }
10613: for (var m=0; m<okSpares.length; m++) {
10614: var idx = m+1;
10615: var selThis = 0;
10616: if (selIdx != 0) {
10617: if (okSpares[m] == currnew) {
10618: selThis = 1;
10619: }
10620: }
10621: if (selThis == 1) {
10622: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10623: } else {
10624: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10625: }
10626: }
10627: }
10628: return;
10629: }
10630:
10631: function checkNewSpares(lonhost,type) {
10632: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10633: var chosen = newSpare.options[newSpare.selectedIndex].value;
10634: if (chosen != '') {
10635: var othertype;
10636: var othernewSpare;
10637: if (type == 'primary') {
10638: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10639: }
10640: if (type == 'default') {
10641: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10642: }
10643: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10644: othernewSpare.selectedIndex = 0;
10645: }
10646: }
10647: return;
10648: }
10649:
10650: // ]]>
10651: </script>
10652:
10653: END
10654:
10655: }
10656:
10657: sub common_domprefs_js {
10658: return <<"END";
10659:
10660: <script type="text/javascript">
10661: // <![CDATA[
10662:
1.150 raeburn 10663: function getIndicesByName(formname,item) {
1.152 raeburn 10664: var group = new Array();
1.150 raeburn 10665: for (var i=0;i<formname.elements.length;i++) {
10666: if (formname.elements[i].name == item) {
1.152 raeburn 10667: group.push(formname.elements[i].id);
1.150 raeburn 10668: }
10669: }
1.152 raeburn 10670: return group;
1.150 raeburn 10671: }
10672:
10673: // ]]>
10674: </script>
10675:
10676: END
1.152 raeburn 10677:
1.150 raeburn 10678: }
10679:
1.165 raeburn 10680: sub recaptcha_js {
10681: my %lt = &captcha_phrases();
10682: return <<"END";
10683:
10684: <script type="text/javascript">
10685: // <![CDATA[
10686:
10687: function updateCaptcha(caller,context) {
10688: var privitem;
10689: var pubitem;
10690: var privtext;
10691: var pubtext;
10692: if (document.getElementById(context+'_recaptchapub')) {
10693: pubitem = document.getElementById(context+'_recaptchapub');
10694: } else {
10695: return;
10696: }
10697: if (document.getElementById(context+'_recaptchapriv')) {
10698: privitem = document.getElementById(context+'_recaptchapriv');
10699: } else {
10700: return;
10701: }
10702: if (document.getElementById(context+'_recaptchapubtxt')) {
10703: pubtext = document.getElementById(context+'_recaptchapubtxt');
10704: } else {
10705: return;
10706: }
10707: if (document.getElementById(context+'_recaptchaprivtxt')) {
10708: privtext = document.getElementById(context+'_recaptchaprivtxt');
10709: } else {
10710: return;
10711: }
10712: if (caller.checked) {
10713: if (caller.value == 'recaptcha') {
10714: pubitem.type = 'text';
10715: privitem.type = 'text';
10716: pubitem.size = '40';
10717: privitem.size = '40';
10718: pubtext.innerHTML = "$lt{'pub'}";
10719: privtext.innerHTML = "$lt{'priv'}";
10720: } else {
10721: pubitem.type = 'hidden';
10722: privitem.type = 'hidden';
10723: pubtext.innerHTML = '';
10724: privtext.innerHTML = '';
10725: }
10726: }
10727: return;
10728: }
10729:
10730: // ]]>
10731: </script>
10732:
10733: END
10734:
10735: }
10736:
1.192 raeburn 10737: sub credits_js {
10738: return <<"END";
10739:
10740: <script type="text/javascript">
10741: // <![CDATA[
10742:
10743: function toggleCredits(domForm) {
10744: if (document.getElementById('credits')) {
10745: creditsitem = document.getElementById('credits');
10746: var creditsLength = domForm.coursecredits.length;
10747: if (creditsLength) {
10748: var currval;
10749: for (var i=0; i<creditsLength; i++) {
10750: if (domForm.coursecredits[i].checked) {
10751: currval = domForm.coursecredits[i].value;
10752: }
10753: }
10754: if (currval == 1) {
10755: creditsitem.style.display = 'block';
10756: } else {
10757: creditsitem.style.display = 'none';
10758: }
10759: }
10760: }
10761: return;
10762: }
10763:
10764: // ]]>
10765: </script>
10766:
10767: END
10768:
10769: }
10770:
1.165 raeburn 10771: sub captcha_phrases {
10772: return &Apache::lonlocal::texthash (
10773: priv => 'Private key',
10774: pub => 'Public key',
10775: original => 'original (CAPTCHA)',
10776: recaptcha => 'successor (ReCAPTCHA)',
10777: notused => 'unused',
10778: );
10779: }
10780:
1.205 raeburn 10781: sub devalidate_remote_domconfs {
1.212 raeburn 10782: my ($dom,$cachekeys) = @_;
10783: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 10784: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10785: my %thismachine;
10786: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 10787: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 10788: if (keys(%servers) > 1) {
10789: foreach my $server (keys(%servers)) {
10790: next if ($thismachine{$server});
1.212 raeburn 10791: my @cached;
10792: foreach my $name (@posscached) {
10793: if ($cachekeys->{$name}) {
10794: push(@cached,&escape($name).':'.&escape($dom));
10795: }
10796: }
10797: if (@cached) {
10798: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10799: }
1.205 raeburn 10800: }
10801: }
10802: return;
10803: }
10804:
1.3 raeburn 10805: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>