Annotation of loncom/interface/domainprefs.pm, revision 1.252
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.252 ! raeburn 4: # $Id: domainprefs.pm,v 1.251 2014/08/06 17:16:29 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.235 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
216: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 217: 'coursedefaults','usersessions','loadbalancing',
1.236 raeburn 218: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 222: 'requestcourses','requestauthor','coursecategories',
223: 'serverstatuses','helpsettings',
1.231 raeburn 224: 'coursedefaults','selfenrollment','usersessions');
1.171 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.230 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
253: col2 => 'Value'}],
1.230 raeburn 254: print => \&print_login,
255: modify => \&modify_login,
1.30 raeburn 256: },
1.43 raeburn 257: 'defaults' =>
1.236 raeburn 258: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 259: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 260: header => [{col1 => 'Setting',
1.236 raeburn 261: col2 => 'Value'},
262: {col1 => 'Institutional user types',
263: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 264: print => \&print_defaults,
265: modify => \&modify_defaults,
1.43 raeburn 266: },
1.30 raeburn 267: 'quotas' =>
1.197 raeburn 268: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 269: help => 'Domain_Configuration_Quotas',
1.77 raeburn 270: header => [{col1 => 'User affiliation',
1.72 raeburn 271: col2 => 'Available tools',
1.213 raeburn 272: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 273: print => \&print_quotas,
274: modify => \&modify_quotas,
1.30 raeburn 275: },
276: 'autoenroll' =>
277: { text => 'Auto-enrollment settings',
1.67 raeburn 278: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 279: header => [{col1 => 'Configuration setting',
280: col2 => 'Value(s)'}],
1.230 raeburn 281: print => \&print_autoenroll,
282: modify => \&modify_autoenroll,
1.30 raeburn 283: },
284: 'autoupdate' =>
285: { text => 'Auto-update settings',
1.67 raeburn 286: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 287: header => [{col1 => 'Setting',
288: col2 => 'Value',},
1.131 raeburn 289: {col1 => 'Setting',
290: col2 => 'Affiliation'},
1.43 raeburn 291: {col1 => 'User population',
1.227 bisitz 292: col2 => 'Updatable user data'}],
1.230 raeburn 293: print => \&print_autoupdate,
294: modify => \&modify_autoupdate,
1.30 raeburn 295: },
1.125 raeburn 296: 'autocreate' =>
297: { text => 'Auto-course creation settings',
298: help => 'Domain_Configuration_Auto_Creation',
299: header => [{col1 => 'Configuration Setting',
300: col2 => 'Value',}],
1.230 raeburn 301: print => \&print_autocreate,
302: modify => \&modify_autocreate,
1.125 raeburn 303: },
1.30 raeburn 304: 'directorysrch' =>
305: { text => 'Institutional directory searches',
1.67 raeburn 306: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 307: header => [{col1 => 'Setting',
308: col2 => 'Value',}],
1.230 raeburn 309: print => \&print_directorysrch,
310: modify => \&modify_directorysrch,
1.30 raeburn 311: },
312: 'contacts' =>
313: { text => 'Contact Information',
1.67 raeburn 314: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 315: header => [{col1 => 'Setting',
316: col2 => 'Value',}],
1.230 raeburn 317: print => \&print_contacts,
318: modify => \&modify_contacts,
1.30 raeburn 319: },
320: 'usercreation' =>
321: { text => 'User creation',
1.67 raeburn 322: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 323: header => [{col1 => 'Format rule type',
324: col2 => 'Format rules in force'},
1.34 raeburn 325: {col1 => 'User account creation',
326: col2 => 'Usernames which may be created',},
1.30 raeburn 327: {col1 => 'Context',
1.43 raeburn 328: col2 => 'Assignable authentication types'}],
1.230 raeburn 329: print => \&print_usercreation,
330: modify => \&modify_usercreation,
1.30 raeburn 331: },
1.224 raeburn 332: 'selfcreation' =>
333: { text => 'Users self-creating accounts',
334: help => 'Domain_Configuration_Self_Creation',
335: header => [{col1 => 'Self-creation with institutional username',
336: col2 => 'Enabled?'},
337: {col1 => 'Institutional user type (login/SSO self-creation)',
338: col2 => 'Information user can enter'},
339: {col1 => 'Self-creation with e-mail as username',
340: col2 => 'Settings'}],
1.230 raeburn 341: print => \&print_selfcreation,
342: modify => \&modify_selfcreation,
1.224 raeburn 343: },
1.69 raeburn 344: 'usermodification' =>
1.33 raeburn 345: { text => 'User modification',
1.67 raeburn 346: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 347: header => [{col1 => 'Target user has role',
1.227 bisitz 348: col2 => 'User information updatable in author context'},
1.33 raeburn 349: {col1 => 'Target user has role',
1.227 bisitz 350: col2 => 'User information updatable in course context'}],
1.230 raeburn 351: print => \&print_usermodification,
352: modify => \&modify_usermodification,
1.33 raeburn 353: },
1.69 raeburn 354: 'scantron' =>
1.95 www 355: { text => 'Bubblesheet format file',
1.67 raeburn 356: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 357: header => [ {col1 => 'Item',
358: col2 => '',
359: }],
1.230 raeburn 360: print => \&print_scantron,
361: modify => \&modify_scantron,
1.46 raeburn 362: },
1.86 raeburn 363: 'requestcourses' =>
364: {text => 'Request creation of courses',
365: help => 'Domain_Configuration_Request_Courses',
366: header => [{col1 => 'User affiliation',
1.102 raeburn 367: col2 => 'Availability/Processing of requests',},
368: {col1 => 'Setting',
1.216 raeburn 369: col2 => 'Value'},
370: {col1 => 'Available textbooks',
1.235 raeburn 371: col2 => ''},
1.242 raeburn 372: {col1 => 'Available templates',
373: col2 => ''},
1.235 raeburn 374: {col1 => 'Validation (not official courses)',
375: col2 => 'Value'},],
1.230 raeburn 376: print => \&print_quotas,
377: modify => \&modify_quotas,
1.86 raeburn 378: },
1.163 raeburn 379: 'requestauthor' =>
1.223 bisitz 380: {text => 'Request Authoring Space',
1.163 raeburn 381: help => 'Domain_Configuration_Request_Author',
382: header => [{col1 => 'User affiliation',
383: col2 => 'Availability/Processing of requests',},
384: {col1 => 'Setting',
385: col2 => 'Value'}],
1.230 raeburn 386: print => \&print_quotas,
387: modify => \&modify_quotas,
1.163 raeburn 388: },
1.69 raeburn 389: 'coursecategories' =>
1.120 raeburn 390: { text => 'Cataloging of courses/communities',
1.67 raeburn 391: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 392: header => [{col1 => 'Catalog type/availability',
393: col2 => '',},
394: {col1 => 'Category settings for standard catalog',
1.57 raeburn 395: col2 => '',},
396: {col1 => 'Categories',
397: col2 => '',
398: }],
1.230 raeburn 399: print => \&print_coursecategories,
400: modify => \&modify_coursecategories,
1.69 raeburn 401: },
402: 'serverstatuses' =>
1.77 raeburn 403: {text => 'Access to server status pages',
1.69 raeburn 404: help => 'Domain_Configuration_Server_Status',
405: header => [{col1 => 'Status Page',
406: col2 => 'Other named users',
407: col3 => 'Specific IPs',
408: }],
1.230 raeburn 409: print => \&print_serverstatuses,
410: modify => \&modify_serverstatuses,
1.69 raeburn 411: },
1.118 jms 412: 'helpsettings' =>
413: {text => 'Help page settings',
414: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 415: header => [{col1 => 'Help Settings (logged-in users)',
416: col2 => 'Value'}],
1.230 raeburn 417: print => \&print_helpsettings,
418: modify => \&modify_helpsettings,
1.118 jms 419: },
1.121 raeburn 420: 'coursedefaults' =>
421: {text => 'Course/Community defaults',
422: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 423: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
424: col2 => 'Value',},
425: {col1 => 'Defaults which can be overridden for each course by a DC',
426: col2 => 'Value',},],
1.230 raeburn 427: print => \&print_coursedefaults,
428: modify => \&modify_coursedefaults,
1.121 raeburn 429: },
1.231 raeburn 430: 'selfenrollment' =>
431: {text => 'Self-enrollment in Course/Community',
432: help => 'Domain_Configuration_Selfenrollment',
433: header => [{col1 => 'Configuration Rights',
434: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
435: {col1 => 'Defaults',
436: col2 => 'Value'},
437: {col1 => 'Self-enrollment validation (optional)',
438: col2 => 'Value'},],
439: print => \&print_selfenrollment,
440: modify => \&modify_selfenrollment,
441: },
1.120 raeburn 442: 'privacy' =>
443: {text => 'User Privacy',
444: help => 'Domain_Configuration_User_Privacy',
445: header => [{col1 => 'Setting',
446: col2 => 'Value',}],
1.230 raeburn 447: print => \&print_privacy,
448: modify => \&modify_privacy,
1.120 raeburn 449: },
1.141 raeburn 450: 'usersessions' =>
1.145 raeburn 451: {text => 'User session hosting/offloading',
1.137 raeburn 452: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 453: header => [{col1 => 'Domain server',
454: col2 => 'Servers to offload sessions to when busy'},
455: {col1 => 'Hosting of users from other domains',
1.137 raeburn 456: col2 => 'Rules'},
457: {col1 => "Hosting domain's own users elsewhere",
458: col2 => 'Rules'}],
1.230 raeburn 459: print => \&print_usersessions,
460: modify => \&modify_usersessions,
1.137 raeburn 461: },
1.150 raeburn 462: 'loadbalancing' =>
1.185 raeburn 463: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 464: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 465: header => [{col1 => 'Balancers',
1.150 raeburn 466: col2 => 'Default destinations',
1.183 bisitz 467: col3 => 'User affiliation',
1.150 raeburn 468: col4 => 'Overrides'},
469: ],
1.230 raeburn 470: print => \&print_loadbalancing,
471: modify => \&modify_loadbalancing,
1.150 raeburn 472: },
1.3 raeburn 473: );
1.110 raeburn 474: if (keys(%servers) > 1) {
475: $prefs{'login'} = { text => 'Log-in page options',
476: help => 'Domain_Configuration_Login_Page',
477: header => [{col1 => 'Log-in Service',
478: col2 => 'Server Setting',},
479: {col1 => 'Log-in Page Items',
1.168 raeburn 480: col2 => ''},
481: {col1 => 'Log-in Help',
482: col2 => 'Value'}],
1.230 raeburn 483: print => \&print_login,
484: modify => \&modify_login,
1.110 raeburn 485: };
486: }
1.174 foxr 487:
1.6 raeburn 488: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 489: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 490: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 491: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 492: text=>"Settings to display/modify"});
1.9 raeburn 493: my $confname = $dom.'-domainconfig';
1.174 foxr 494:
1.3 raeburn 495: if ($phase eq 'process') {
1.212 raeburn 496: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
497: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 498: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 499: $r->rflush();
1.212 raeburn 500: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 501: }
1.30 raeburn 502: } elsif ($phase eq 'display') {
1.192 raeburn 503: my $js = &recaptcha_js().
1.236 raeburn 504: &toggle_display_js();
1.171 raeburn 505: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 506: my ($othertitle,$usertypes,$types) =
507: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 508: $js .= &lonbalance_targets_js($dom,$types,\%servers,
509: $domconfig{'loadbalancing'}).
1.170 raeburn 510: &new_spares_js().
511: &common_domprefs_js().
512: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 513: }
1.216 raeburn 514: if (grep(/^requestcourses$/,@actions)) {
515: my $javascript_validations;
516: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
517: $js .= <<END;
518: <script type="text/javascript">
519: $javascript_validations
520: </script>
521: $coursebrowserjs
522: END
523: }
1.150 raeburn 524: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 525: } else {
1.180 raeburn 526: # check if domconfig user exists for the domain.
527: my $servadm = $r->dir_config('lonAdmEMail');
528: my ($configuserok,$author_ok,$switchserver) =
529: &config_check($dom,$confname,$servadm);
530: unless ($configuserok eq 'ok') {
1.181 raeburn 531: &Apache::lonconfigsettings::print_header($r,$phase,$context);
532: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 533: $confname).
1.181 raeburn 534: '<br />'
535: );
1.180 raeburn 536: if ($switchserver) {
1.181 raeburn 537: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
538: '<br />'.
539: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
540: '<br />'.
541: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
542: '<br />'.
543: &mt('To do that now, use the following link: [_1]',$switchserver)
544: );
545: } else {
546: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
547: '<br />'.
548: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
549: );
1.180 raeburn 550: }
551: $r->print(&Apache::loncommon::end_page());
552: return OK;
553: }
1.21 raeburn 554: if (keys(%domconfig) == 0) {
555: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 556: my @ids=&Apache::lonnet::current_machine_ids();
557: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 558: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 559: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 560: my $custom_img_count = 0;
561: foreach my $img (@loginimages) {
562: if ($designhash{$dom.'.login.'.$img} ne '') {
563: $custom_img_count ++;
564: }
565: }
566: foreach my $role (@roles) {
567: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
568: $custom_img_count ++;
569: }
570: }
571: if ($custom_img_count > 0) {
1.94 raeburn 572: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 573: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 574: $r->print(
575: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
576: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
577: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
578: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
579: if ($switch_server) {
1.30 raeburn 580: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 581: }
1.91 raeburn 582: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 583: return OK;
584: }
585: }
586: }
1.91 raeburn 587: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 588: }
589: return OK;
590: }
591:
592: sub process_changes {
1.205 raeburn 593: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 594: my %domconfig;
595: if (ref($values) eq 'HASH') {
596: %domconfig = %{$values};
597: }
1.3 raeburn 598: my $output;
599: if ($action eq 'login') {
1.205 raeburn 600: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 601: } elsif ($action eq 'rolecolors') {
1.9 raeburn 602: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 603: $lastactref,%domconfig);
1.3 raeburn 604: } elsif ($action eq 'quotas') {
1.216 raeburn 605: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 606: } elsif ($action eq 'autoenroll') {
1.205 raeburn 607: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 608: } elsif ($action eq 'autoupdate') {
609: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 610: } elsif ($action eq 'autocreate') {
611: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 612: } elsif ($action eq 'directorysrch') {
613: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 614: } elsif ($action eq 'usercreation') {
1.28 raeburn 615: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 616: } elsif ($action eq 'selfcreation') {
617: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 618: } elsif ($action eq 'usermodification') {
619: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 620: } elsif ($action eq 'contacts') {
1.205 raeburn 621: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 622: } elsif ($action eq 'defaults') {
1.212 raeburn 623: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 624: } elsif ($action eq 'scantron') {
1.205 raeburn 625: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 626: } elsif ($action eq 'coursecategories') {
1.239 raeburn 627: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 628: } elsif ($action eq 'serverstatuses') {
629: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 630: } elsif ($action eq 'requestcourses') {
1.216 raeburn 631: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 632: } elsif ($action eq 'requestauthor') {
1.216 raeburn 633: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 634: } elsif ($action eq 'helpsettings') {
1.122 jms 635: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 636: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 637: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 638: } elsif ($action eq 'selfenrollment') {
639: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 640: } elsif ($action eq 'usersessions') {
1.212 raeburn 641: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 642: } elsif ($action eq 'loadbalancing') {
643: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 644: }
645: return $output;
646: }
647:
648: sub print_config_box {
1.9 raeburn 649: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 650: my $rowtotal = 0;
1.49 raeburn 651: my $output;
652: if ($action eq 'coursecategories') {
653: $output = &coursecategories_javascript($settings);
1.236 raeburn 654: } elsif ($action eq 'defaults') {
655: $output = &defaults_javascript($settings);
1.91 raeburn 656: }
1.236 raeburn 657: $output .=
1.30 raeburn 658: '<table class="LC_nested_outer">
1.3 raeburn 659: <tr>
1.66 raeburn 660: <th align="left" valign="middle"><span class="LC_nobreak">'.
661: &mt($item->{text}).' '.
662: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
663: '</tr>';
1.30 raeburn 664: $rowtotal ++;
1.110 raeburn 665: my $numheaders = 1;
666: if (ref($item->{'header'}) eq 'ARRAY') {
667: $numheaders = scalar(@{$item->{'header'}});
668: }
669: if ($numheaders > 1) {
1.64 raeburn 670: my $colspan = '';
1.145 raeburn 671: my $rightcolspan = '';
1.238 raeburn 672: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.168 raeburn 673: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 674: $colspan = ' colspan="2"';
675: }
1.145 raeburn 676: if ($action eq 'usersessions') {
677: $rightcolspan = ' colspan="3"';
678: }
1.30 raeburn 679: $output .= '
1.3 raeburn 680: <tr>
681: <td>
682: <table class="LC_nested">
683: <tr class="LC_info_row">
1.59 bisitz 684: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 685: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 686: </tr>';
1.69 raeburn 687: $rowtotal ++;
1.230 raeburn 688: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 689: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.230 raeburn 690: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
691: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 692: } elsif ($action eq 'coursecategories') {
1.230 raeburn 693: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 694: } elsif ($action eq 'login') {
1.168 raeburn 695: if ($numheaders == 3) {
696: $colspan = ' colspan="2"';
697: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
698: } else {
699: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
700: }
1.230 raeburn 701: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 702: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 703: } elsif ($action eq 'rolecolors') {
1.30 raeburn 704: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 705: }
1.30 raeburn 706: $output .= '
1.6 raeburn 707: </table>
708: </td>
709: </tr>
710: <tr>
711: <td>
712: <table class="LC_nested">
713: <tr class="LC_info_row">
1.230 raeburn 714: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 715: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 716: </tr>';
717: $rowtotal ++;
1.230 raeburn 718: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
719: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.238 raeburn 720: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
721: if ($action eq 'coursecategories') {
722: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
723: $colspan = ' colspan="2"';
724: } else {
725: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
726: }
727: $output .= '
1.63 raeburn 728: </table>
729: </td>
730: </tr>
731: <tr>
732: <td>
733: <table class="LC_nested">
734: <tr class="LC_info_row">
735: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 736: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 737: </tr>'."\n";
738: if ($action eq 'coursecategories') {
739: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
740: } else {
741: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
742: }
1.63 raeburn 743: $rowtotal ++;
1.236 raeburn 744: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
745: ($action eq 'defaults')) {
1.230 raeburn 746: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 747: } elsif ($action eq 'login') {
1.168 raeburn 748: if ($numheaders == 3) {
749: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
757: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 758: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 759: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
760: $rowtotal ++;
761: } else {
762: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
763: }
1.102 raeburn 764: } elsif ($action eq 'requestcourses') {
1.247 raeburn 765: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
766: $rowtotal ++;
767: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 768: </table>
769: </td>
770: </tr>
771: <tr>
772: <td>
773: <table class="LC_nested">
774: <tr class="LC_info_row">
775: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
776: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 777: &textbookcourses_javascript($settings).
778: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
779: </table>
780: </td>
781: </tr>
782: <tr>
783: <td>
784: <table class="LC_nested">
785: <tr class="LC_info_row">
786: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
787: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
788: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 789: </table>
790: </td>
791: </tr>
792: <tr>
793: <td>
794: <table class="LC_nested">
795: <tr class="LC_info_row">
1.242 raeburn 796: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
797: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 798: </tr>'.
799: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 800: } elsif ($action eq 'requestauthor') {
801: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 802: $rowtotal ++;
1.122 jms 803: } elsif ($action eq 'rolecolors') {
1.30 raeburn 804: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 805: </table>
806: </td>
807: </tr>
808: <tr>
809: <td>
810: <table class="LC_nested">
811: <tr class="LC_info_row">
1.69 raeburn 812: <td class="LC_left_item"'.$colspan.' valign="top">'.
813: &mt($item->{'header'}->[2]->{'col1'}).'</td>
814: <td class="LC_right_item" valign="top">'.
815: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 816: </tr>'.
1.30 raeburn 817: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 818: </table>
819: </td>
820: </tr>
821: <tr>
822: <td>
823: <table class="LC_nested">
824: <tr class="LC_info_row">
1.59 bisitz 825: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
826: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 827: </tr>'.
1.30 raeburn 828: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
829: $rowtotal += 2;
1.6 raeburn 830: }
1.3 raeburn 831: } else {
1.30 raeburn 832: $output .= '
1.3 raeburn 833: <tr>
834: <td>
835: <table class="LC_nested">
1.30 raeburn 836: <tr class="LC_info_row">';
1.24 raeburn 837: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 838: $output .= '
1.59 bisitz 839: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 840: } elsif ($action eq 'serverstatuses') {
841: $output .= '
842: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
843: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
844:
1.6 raeburn 845: } else {
1.30 raeburn 846: $output .= '
1.69 raeburn 847: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
848: }
1.72 raeburn 849: if (defined($item->{'header'}->[0]->{'col3'})) {
850: $output .= '<td class="LC_left_item" valign="top">'.
851: &mt($item->{'header'}->[0]->{'col2'});
852: if ($action eq 'serverstatuses') {
853: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
854: }
1.69 raeburn 855: } else {
856: $output .= '<td class="LC_right_item" valign="top">'.
857: &mt($item->{'header'}->[0]->{'col2'});
858: }
859: $output .= '</td>';
860: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 861: if (defined($item->{'header'}->[0]->{'col4'})) {
862: $output .= '<td class="LC_left_item" valign="top">'.
863: &mt($item->{'header'}->[0]->{'col3'});
864: } else {
865: $output .= '<td class="LC_right_item" valign="top">'.
866: &mt($item->{'header'}->[0]->{'col3'});
867: }
1.69 raeburn 868: if ($action eq 'serverstatuses') {
869: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
870: }
871: $output .= '</td>';
1.6 raeburn 872: }
1.150 raeburn 873: if ($item->{'header'}->[0]->{'col4'}) {
874: $output .= '<td class="LC_right_item" valign="top">'.
875: &mt($item->{'header'}->[0]->{'col4'});
876: }
1.69 raeburn 877: $output .= '</tr>';
1.48 raeburn 878: $rowtotal ++;
1.168 raeburn 879: if ($action eq 'quotas') {
1.86 raeburn 880: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 881: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.236 raeburn 882: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.230 raeburn 883: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 884: } elsif ($action eq 'scantron') {
885: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 886: } elsif ($action eq 'helpsettings') {
1.168 raeburn 887: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 888: }
1.3 raeburn 889: }
1.30 raeburn 890: $output .= '
1.3 raeburn 891: </table>
892: </td>
893: </tr>
1.30 raeburn 894: </table><br />';
895: return ($output,$rowtotal);
1.1 raeburn 896: }
897:
1.3 raeburn 898: sub print_login {
1.168 raeburn 899: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 900: my ($css_class,$datatable);
1.6 raeburn 901: my %choices = &login_choices();
1.110 raeburn 902:
1.168 raeburn 903: if ($caller eq 'service') {
1.149 raeburn 904: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 905: my $choice = $choices{'disallowlogin'};
906: $css_class = ' class="LC_odd_row"';
1.128 raeburn 907: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 908: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 909: '<th>'.$choices{'server'}.'</th>'.
910: '<th>'.$choices{'serverpath'}.'</th>'.
911: '<th>'.$choices{'custompath'}.'</th>'.
912: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 913: my %disallowed;
914: if (ref($settings) eq 'HASH') {
915: if (ref($settings->{'loginvia'}) eq 'HASH') {
916: %disallowed = %{$settings->{'loginvia'}};
917: }
918: }
919: foreach my $lonhost (sort(keys(%servers))) {
920: my $direct = 'selected="selected"';
1.128 raeburn 921: if (ref($disallowed{$lonhost}) eq 'HASH') {
922: if ($disallowed{$lonhost}{'server'} ne '') {
923: $direct = '';
924: }
1.110 raeburn 925: }
1.115 raeburn 926: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 927: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 928: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
929: '</option>';
1.184 raeburn 930: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 931: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 932: my $selected = '';
1.128 raeburn 933: if (ref($disallowed{$lonhost}) eq 'HASH') {
934: if ($hostid eq $disallowed{$lonhost}{'server'}) {
935: $selected = 'selected="selected"';
936: }
1.110 raeburn 937: }
938: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
939: $servers{$hostid}.'</option>';
940: }
1.128 raeburn 941: $datatable .= '</select></td>'.
942: '<td><select name="'.$lonhost.'_serverpath">';
943: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
944: my $pathname = $path;
945: if ($path eq 'custom') {
946: $pathname = &mt('Custom Path').' ->';
947: }
948: my $selected = '';
949: if (ref($disallowed{$lonhost}) eq 'HASH') {
950: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
951: $selected = 'selected="selected"';
952: }
953: } elsif ($path eq '') {
954: $selected = 'selected="selected"';
955: }
956: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
957: }
958: $datatable .= '</select></td>';
959: my ($custom,$exempt);
960: if (ref($disallowed{$lonhost}) eq 'HASH') {
961: $custom = $disallowed{$lonhost}{'custompath'};
962: $exempt = $disallowed{$lonhost}{'exempt'};
963: }
964: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
965: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
966: '</tr>';
1.110 raeburn 967: }
968: $datatable .= '</table></td></tr>';
969: return $datatable;
1.168 raeburn 970: } elsif ($caller eq 'page') {
971: my %defaultchecked = (
972: 'coursecatalog' => 'on',
1.188 raeburn 973: 'helpdesk' => 'on',
1.168 raeburn 974: 'adminmail' => 'off',
975: 'newuser' => 'off',
976: );
1.188 raeburn 977: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 978: my (%checkedon,%checkedoff);
1.42 raeburn 979: foreach my $item (@toggles) {
1.168 raeburn 980: if ($defaultchecked{$item} eq 'on') {
981: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 982: $checkedoff{$item} = ' ';
1.168 raeburn 983: } elsif ($defaultchecked{$item} eq 'off') {
984: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 985: $checkedon{$item} = ' ';
986: }
1.1 raeburn 987: }
1.168 raeburn 988: my @images = ('img','logo','domlogo','login');
989: my @logintext = ('textcol','bgcol');
990: my @bgs = ('pgbg','mainbg','sidebg');
991: my @links = ('link','alink','vlink');
992: my %designhash = &Apache::loncommon::get_domainconf($dom);
993: my %defaultdesign = %Apache::loncommon::defaultdesign;
994: my (%is_custom,%designs);
995: my %defaults = (
996: font => $defaultdesign{'login.font'},
997: );
1.6 raeburn 998: foreach my $item (@images) {
1.168 raeburn 999: $defaults{$item} = $defaultdesign{'login.'.$item};
1000: $defaults{'showlogo'}{$item} = 1;
1001: }
1002: foreach my $item (@bgs) {
1003: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1004: }
1.41 raeburn 1005: foreach my $item (@logintext) {
1.168 raeburn 1006: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1007: }
1.168 raeburn 1008: foreach my $item (@links) {
1009: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1010: }
1.168 raeburn 1011: if (ref($settings) eq 'HASH') {
1012: foreach my $item (@toggles) {
1013: if ($settings->{$item} eq '1') {
1014: $checkedon{$item} = ' checked="checked" ';
1015: $checkedoff{$item} = ' ';
1016: } elsif ($settings->{$item} eq '0') {
1017: $checkedoff{$item} = ' checked="checked" ';
1018: $checkedon{$item} = ' ';
1019: }
1020: }
1021: foreach my $item (@images) {
1022: if (defined($settings->{$item})) {
1023: $designs{$item} = $settings->{$item};
1024: $is_custom{$item} = 1;
1025: }
1026: if (defined($settings->{'showlogo'}{$item})) {
1027: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1028: }
1029: }
1030: foreach my $item (@logintext) {
1031: if ($settings->{$item} ne '') {
1032: $designs{'logintext'}{$item} = $settings->{$item};
1033: $is_custom{$item} = 1;
1034: }
1035: }
1036: if ($settings->{'font'} ne '') {
1037: $designs{'font'} = $settings->{'font'};
1038: $is_custom{'font'} = 1;
1039: }
1040: foreach my $item (@bgs) {
1041: if ($settings->{$item} ne '') {
1042: $designs{'bgs'}{$item} = $settings->{$item};
1043: $is_custom{$item} = 1;
1044: }
1045: }
1046: foreach my $item (@links) {
1047: if ($settings->{$item} ne '') {
1048: $designs{'links'}{$item} = $settings->{$item};
1049: $is_custom{$item} = 1;
1050: }
1051: }
1052: } else {
1053: if ($designhash{$dom.'.login.font'} ne '') {
1054: $designs{'font'} = $designhash{$dom.'.login.font'};
1055: $is_custom{'font'} = 1;
1056: }
1057: foreach my $item (@images) {
1058: if ($designhash{$dom.'.login.'.$item} ne '') {
1059: $designs{$item} = $designhash{$dom.'.login.'.$item};
1060: $is_custom{$item} = 1;
1061: }
1062: }
1063: foreach my $item (@bgs) {
1064: if ($designhash{$dom.'.login.'.$item} ne '') {
1065: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1066: $is_custom{$item} = 1;
1067: }
1.6 raeburn 1068: }
1.168 raeburn 1069: foreach my $item (@links) {
1070: if ($designhash{$dom.'.login.'.$item} ne '') {
1071: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1072: $is_custom{$item} = 1;
1073: }
1.6 raeburn 1074: }
1075: }
1.168 raeburn 1076: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1077: logo => 'Institution Logo',
1078: domlogo => 'Domain Logo',
1079: login => 'Login box');
1080: my $itemcount = 1;
1081: foreach my $item (@toggles) {
1082: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1083: $datatable .=
1084: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1085: '</td><td>'.
1086: '<span class="LC_nobreak"><label><input type="radio" name="'.
1087: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1088: '</label> <label><input type="radio" name="'.$item.'"'.
1089: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1090: '</tr>';
1091: $itemcount ++;
1.6 raeburn 1092: }
1.168 raeburn 1093: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1094: $datatable .= '</tr></table></td></tr>';
1095: } elsif ($caller eq 'help') {
1096: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1097: my $switchserver = &check_switchserver($dom,$confname);
1098: my $itemcount = 1;
1099: $defaulturl = '/adm/loginproblems.html';
1100: $defaulttype = 'default';
1101: %lt = &Apache::lonlocal::texthash (
1102: del => 'Delete?',
1103: rep => 'Replace:',
1104: upl => 'Upload:',
1105: default => 'Default',
1106: custom => 'Custom',
1107: );
1108: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1109: my @currlangs;
1110: if (ref($settings) eq 'HASH') {
1111: if (ref($settings->{'helpurl'}) eq 'HASH') {
1112: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1113: next if ($settings->{'helpurl'}{$key} eq '');
1114: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1115: $type{$key} = 'custom';
1116: unless ($key eq 'nolang') {
1117: push(@currlangs,$key);
1118: }
1119: }
1120: } elsif ($settings->{'helpurl'} ne '') {
1121: $type{'nolang'} = 'custom';
1122: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1123: }
1124: }
1.168 raeburn 1125: foreach my $lang ('nolang',sort(@currlangs)) {
1126: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1127: $datatable .= '<tr'.$css_class.'>';
1128: if ($url{$lang} eq '') {
1129: $url{$lang} = $defaulturl;
1130: }
1131: if ($type{$lang} eq '') {
1132: $type{$lang} = $defaulttype;
1133: }
1134: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1135: if ($lang eq 'nolang') {
1136: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1137: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1138: } else {
1139: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1140: $langchoices{$lang},
1141: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1142: }
1143: $datatable .= '</span></td>'."\n".
1144: '<td class="LC_left_item">';
1145: if ($type{$lang} eq 'custom') {
1146: $datatable .= '<span class="LC_nobreak"><label>'.
1147: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1148: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1149: } else {
1150: $datatable .= $lt{'upl'};
1151: }
1152: $datatable .='<br />';
1153: if ($switchserver) {
1154: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1155: } else {
1156: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1157: }
1.168 raeburn 1158: $datatable .= '</td></tr>';
1159: $itemcount ++;
1.6 raeburn 1160: }
1.168 raeburn 1161: my @addlangs;
1162: foreach my $lang (sort(keys(%langchoices))) {
1163: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1164: push(@addlangs,$lang);
1165: }
1166: if (@addlangs > 0) {
1167: my %toadd;
1168: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1169: $toadd{''} = &mt('Select');
1170: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1171: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1172: &mt('Add log-in help page for a specific language:').' '.
1173: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1174: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1175: if ($switchserver) {
1176: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1177: } else {
1178: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1179: }
1.168 raeburn 1180: $datatable .= '</td></tr>';
1.169 raeburn 1181: $itemcount ++;
1.6 raeburn 1182: }
1.169 raeburn 1183: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1184: }
1.6 raeburn 1185: return $datatable;
1186: }
1187:
1188: sub login_choices {
1189: my %choices =
1190: &Apache::lonlocal::texthash (
1.116 bisitz 1191: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1192: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1193: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1194: disallowlogin => "Login page requests redirected",
1195: hostid => "Server",
1.128 raeburn 1196: server => "Redirect to:",
1197: serverpath => "Path",
1198: custompath => "Custom",
1199: exempt => "Exempt IP(s)",
1.110 raeburn 1200: directlogin => "No redirect",
1201: newuser => "Link to create a user account",
1202: img => "Header",
1203: logo => "Main Logo",
1204: domlogo => "Domain Logo",
1205: login => "Log-in Header",
1206: textcol => "Text color",
1207: bgcol => "Box color",
1208: bgs => "Background colors",
1209: links => "Link colors",
1210: font => "Font color",
1211: pgbg => "Header",
1212: mainbg => "Page",
1213: sidebg => "Login box",
1214: link => "Link",
1215: alink => "Active link",
1216: vlink => "Visited link",
1.6 raeburn 1217: );
1218: return %choices;
1219: }
1220:
1221: sub print_rolecolors {
1.30 raeburn 1222: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1223: my %choices = &color_font_choices();
1224: my @bgs = ('pgbg','tabbg','sidebg');
1225: my @links = ('link','alink','vlink');
1226: my @images = ('img');
1227: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1228: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1229: my %defaultdesign = %Apache::loncommon::defaultdesign;
1230: my (%is_custom,%designs);
1.200 raeburn 1231: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1232: if (ref($settings) eq 'HASH') {
1233: if (ref($settings->{$role}) eq 'HASH') {
1234: if ($settings->{$role}->{'img'} ne '') {
1235: $designs{'img'} = $settings->{$role}->{'img'};
1236: $is_custom{'img'} = 1;
1237: }
1238: if ($settings->{$role}->{'font'} ne '') {
1239: $designs{'font'} = $settings->{$role}->{'font'};
1240: $is_custom{'font'} = 1;
1241: }
1.97 tempelho 1242: if ($settings->{$role}->{'fontmenu'} ne '') {
1243: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1244: $is_custom{'fontmenu'} = 1;
1245: }
1.6 raeburn 1246: foreach my $item (@bgs) {
1247: if ($settings->{$role}->{$item} ne '') {
1248: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1249: $is_custom{$item} = 1;
1250: }
1251: }
1252: foreach my $item (@links) {
1253: if ($settings->{$role}->{$item} ne '') {
1254: $designs{'links'}{$item} = $settings->{$role}->{$item};
1255: $is_custom{$item} = 1;
1256: }
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1261: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1262: $is_custom{'img'} = 1;
1263: }
1.97 tempelho 1264: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1265: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1266: $is_custom{'fontmenu'} = 1;
1267: }
1.6 raeburn 1268: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1269: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1270: $is_custom{'font'} = 1;
1271: }
1272: foreach my $item (@bgs) {
1273: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1274: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1275: $is_custom{$item} = 1;
1276:
1277: }
1278: }
1279: foreach my $item (@links) {
1280: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1281: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1282: $is_custom{$item} = 1;
1283: }
1284: }
1285: }
1286: my $itemcount = 1;
1.30 raeburn 1287: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1288: $datatable .= '</tr></table></td></tr>';
1289: return $datatable;
1290: }
1291:
1.200 raeburn 1292: sub role_defaults {
1293: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1294: my %defaults;
1295: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1296: return %defaults;
1297: }
1298: my %defaultdesign = %Apache::loncommon::defaultdesign;
1299: if ($role eq 'login') {
1300: %defaults = (
1301: font => $defaultdesign{$role.'.font'},
1302: );
1303: if (ref($logintext) eq 'ARRAY') {
1304: foreach my $item (@{$logintext}) {
1305: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1306: }
1307: }
1308: foreach my $item (@{$images}) {
1309: $defaults{'showlogo'}{$item} = 1;
1310: }
1311: } else {
1312: %defaults = (
1313: img => $defaultdesign{$role.'.img'},
1314: font => $defaultdesign{$role.'.font'},
1315: fontmenu => $defaultdesign{$role.'.fontmenu'},
1316: );
1317: }
1318: foreach my $item (@{$bgs}) {
1319: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1320: }
1321: foreach my $item (@{$links}) {
1322: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1323: }
1324: foreach my $item (@{$images}) {
1325: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1326: }
1327: return %defaults;
1328: }
1329:
1.6 raeburn 1330: sub display_color_options {
1.9 raeburn 1331: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1332: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1333: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1334: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1335: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1336: '<td>'.$choices->{'font'}.'</td>';
1337: if (!$is_custom->{'font'}) {
1.30 raeburn 1338: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1339: } else {
1340: $datatable .= '<td> </td>';
1341: }
1.174 foxr 1342: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1343:
1.8 raeburn 1344: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1345: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1346: ' value="'.$current_color.'" /> '.
1.174 foxr 1347: ' </td></tr>';
1.107 raeburn 1348: unless ($role eq 'login') {
1349: $datatable .= '<tr'.$css_class.'>'.
1350: '<td>'.$choices->{'fontmenu'}.'</td>';
1351: if (!$is_custom->{'fontmenu'}) {
1352: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1353: } else {
1354: $datatable .= '<td> </td>';
1355: }
1.202 raeburn 1356: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1357: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1358: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1359: '<input class="colorchooser" type="text" size="10" name="'
1360: .$role.'_fontmenu"'.
1361: ' value="'.$current_color.'" /> '.
1362: ' </td></tr>';
1.97 tempelho 1363: }
1.9 raeburn 1364: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1365: foreach my $img (@{$images}) {
1.18 albertel 1366: $itemcount ++;
1.6 raeburn 1367: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1368: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1369: '<td>'.$choices->{$img};
1.41 raeburn 1370: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1371: if ($role eq 'login') {
1372: if ($img eq 'login') {
1373: $login_hdr_pick =
1.135 bisitz 1374: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1375: $logincolors =
1376: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1377: $designs,$defaults);
1.70 raeburn 1378: } elsif ($img ne 'domlogo') {
1379: $datatable.= &logo_display_options($img,$defaults,$designs);
1380: }
1381: }
1382: $datatable .= '</td>';
1.6 raeburn 1383: if ($designs->{$img} ne '') {
1384: $imgfile = $designs->{$img};
1.18 albertel 1385: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1386: } else {
1387: $imgfile = $defaults->{$img};
1388: }
1389: if ($imgfile) {
1.9 raeburn 1390: my ($showfile,$fullsize);
1391: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1392: my $urldir = $1;
1393: my $filename = $2;
1394: my @info = &Apache::lonnet::stat_file($designs->{$img});
1395: if (@info) {
1396: my $thumbfile = 'tn-'.$filename;
1397: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1398: if (@thumb) {
1399: $showfile = $urldir.'/'.$thumbfile;
1400: } else {
1401: $showfile = $imgfile;
1402: }
1403: } else {
1404: $showfile = '';
1405: }
1406: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1407: $showfile = $imgfile;
1.6 raeburn 1408: my $imgdir = $1;
1409: my $filename = $2;
1.159 raeburn 1410: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1411: $showfile = "/$imgdir/tn-".$filename;
1412: } else {
1.159 raeburn 1413: my $input = $londocroot.$imgfile;
1414: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1415: if (!-e $output) {
1.9 raeburn 1416: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1417: my ($fullwidth,$fullheight) = &check_dimensions($input);
1418: if ($fullwidth ne '' && $fullheight ne '') {
1419: if ($fullwidth > $width && $fullheight > $height) {
1420: my $size = $width.'x'.$height;
1421: system("convert -sample $size $input $output");
1.159 raeburn 1422: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1423: }
1424: }
1.6 raeburn 1425: }
1426: }
1.16 raeburn 1427: }
1.6 raeburn 1428: if ($showfile) {
1.40 raeburn 1429: if ($showfile =~ m{^/(adm|res)/}) {
1430: if ($showfile =~ m{^/res/}) {
1431: my $local_showfile =
1432: &Apache::lonnet::filelocation('',$showfile);
1433: &Apache::lonnet::repcopy($local_showfile);
1434: }
1435: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1436: }
1437: if ($imgfile) {
1438: if ($imgfile =~ m{^/(adm|res)/}) {
1439: if ($imgfile =~ m{^/res/}) {
1440: my $local_imgfile =
1441: &Apache::lonnet::filelocation('',$imgfile);
1442: &Apache::lonnet::repcopy($local_imgfile);
1443: }
1444: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1445: } else {
1446: $fullsize = $imgfile;
1447: }
1448: }
1.41 raeburn 1449: $datatable .= '<td>';
1450: if ($img eq 'login') {
1.135 bisitz 1451: $datatable .= $login_hdr_pick;
1452: }
1.41 raeburn 1453: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1454: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1455: } else {
1.201 raeburn 1456: $datatable .= '<td> </td><td class="LC_left_item">'.
1457: &mt('Upload:').'<br />';
1.6 raeburn 1458: }
1459: } else {
1.201 raeburn 1460: $datatable .= '<td> </td><td class="LC_left_item">'.
1461: &mt('Upload:').'<br />';
1.6 raeburn 1462: }
1.9 raeburn 1463: if ($switchserver) {
1464: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1465: } else {
1.135 bisitz 1466: if ($img ne 'login') { # suppress file selection for Log-in header
1467: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1468: }
1.9 raeburn 1469: }
1470: $datatable .= '</td></tr>';
1.6 raeburn 1471: }
1472: $itemcount ++;
1473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1474: $datatable .= '<tr'.$css_class.'>'.
1475: '<td>'.$choices->{'bgs'}.'</td>';
1476: my $bgs_def;
1477: foreach my $item (@{$bgs}) {
1478: if (!$is_custom->{$item}) {
1.70 raeburn 1479: $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 1480: }
1481: }
1482: if ($bgs_def) {
1.8 raeburn 1483: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1484: } else {
1485: $datatable .= '<td> </td>';
1486: }
1487: $datatable .= '<td class="LC_right_item">'.
1488: '<table border="0"><tr>';
1.174 foxr 1489:
1.6 raeburn 1490: foreach my $item (@{$bgs}) {
1.201 raeburn 1491: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1492: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1493: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1494: $datatable .= ' ';
1.6 raeburn 1495: }
1.174 foxr 1496: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1497: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1498: }
1499: $datatable .= '</tr></table></td></tr>';
1500: $itemcount ++;
1501: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1502: $datatable .= '<tr'.$css_class.'>'.
1503: '<td>'.$choices->{'links'}.'</td>';
1504: my $links_def;
1505: foreach my $item (@{$links}) {
1506: if (!$is_custom->{$item}) {
1.30 raeburn 1507: $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 1508: }
1509: }
1510: if ($links_def) {
1.8 raeburn 1511: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1512: } else {
1513: $datatable .= '<td> </td>';
1514: }
1515: $datatable .= '<td class="LC_right_item">'.
1516: '<table border="0"><tr>';
1517: foreach my $item (@{$links}) {
1.234 raeburn 1518: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1519: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1520: if ($designs->{'links'}{$item}) {
1.174 foxr 1521: $datatable.=' ';
1.6 raeburn 1522: }
1.174 foxr 1523: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1524: '" /></td>';
1525: }
1.30 raeburn 1526: $$rowtotal += $itemcount;
1.3 raeburn 1527: return $datatable;
1528: }
1529:
1.70 raeburn 1530: sub logo_display_options {
1531: my ($img,$defaults,$designs) = @_;
1532: my $checkedon;
1533: if (ref($defaults) eq 'HASH') {
1534: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1535: if ($defaults->{'showlogo'}{$img}) {
1536: $checkedon = 'checked="checked" ';
1537: }
1538: }
1539: }
1540: if (ref($designs) eq 'HASH') {
1541: if (ref($designs->{'showlogo'}) eq 'HASH') {
1542: if (defined($designs->{'showlogo'}{$img})) {
1543: if ($designs->{'showlogo'}{$img} == 0) {
1544: $checkedon = '';
1545: } elsif ($designs->{'showlogo'}{$img} == 1) {
1546: $checkedon = 'checked="checked" ';
1547: }
1548: }
1549: }
1550: }
1551: return '<br /><label> <input type="checkbox" name="'.
1552: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1553: &mt('show').'</label>'."\n";
1554: }
1555:
1.41 raeburn 1556: sub login_header_options {
1.135 bisitz 1557: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1558: my $output = '';
1.41 raeburn 1559: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1560: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1561: if (!$is_custom->{'textcol'}) {
1562: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1563: ' ';
1564: }
1565: if (!$is_custom->{'bgcol'}) {
1566: $output .= $choices->{'bgcol'}.': '.
1567: '<span id="css_'.$role.'_font" style="background-color: '.
1568: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1569: }
1570: $output .= '<br />';
1571: }
1572: $output .='<br />';
1573: return $output;
1574: }
1575:
1576: sub login_text_colors {
1.201 raeburn 1577: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1578: my $color_menu = '<table border="0"><tr>';
1579: foreach my $item (@{$logintext}) {
1.201 raeburn 1580: $color_menu .= '<td align="center">'.$choices->{$item};
1581: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1582: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1583: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1584: }
1585: $color_menu .= '</tr></table><br />';
1586: return $color_menu;
1587: }
1588:
1589: sub image_changes {
1590: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1591: my $output;
1.135 bisitz 1592: if ($img eq 'login') {
1593: # suppress image for Log-in header
1594: } elsif (!$is_custom) {
1.70 raeburn 1595: if ($img ne 'domlogo') {
1.41 raeburn 1596: $output .= &mt('Default image:').'<br />';
1597: } else {
1598: $output .= &mt('Default in use:').'<br />';
1599: }
1600: }
1.135 bisitz 1601: if ($img eq 'login') { # suppress image for Log-in header
1602: $output .= '<td>'.$logincolors;
1.41 raeburn 1603: } else {
1.135 bisitz 1604: if ($img_import) {
1605: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1606: }
1607: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1608: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1609: if ($is_custom) {
1610: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1611: '<input type="checkbox" name="'.
1612: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1613: '</label> '.&mt('Replace:').'</span><br />';
1614: } else {
1.201 raeburn 1615: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1616: }
1.41 raeburn 1617: }
1618: return $output;
1619: }
1620:
1.3 raeburn 1621: sub print_quotas {
1.86 raeburn 1622: my ($dom,$settings,$rowtotal,$action) = @_;
1623: my $context;
1624: if ($action eq 'quotas') {
1625: $context = 'tools';
1626: } else {
1627: $context = $action;
1628: }
1.197 raeburn 1629: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1630: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1631: my $typecount = 0;
1.101 raeburn 1632: my ($css_class,%titles);
1.86 raeburn 1633: if ($context eq 'requestcourses') {
1.216 raeburn 1634: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1635: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1636: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1637: %titles = &courserequest_titles();
1.163 raeburn 1638: } elsif ($context eq 'requestauthor') {
1639: @usertools = ('author');
1640: @options = ('norequest','approval','automatic');
1.210 raeburn 1641: %titles = &authorrequest_titles();
1.86 raeburn 1642: } else {
1.162 raeburn 1643: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1644: %titles = &tool_titles();
1.86 raeburn 1645: }
1.26 raeburn 1646: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1647: foreach my $type (@{$types}) {
1.197 raeburn 1648: my ($currdefquota,$currauthorquota);
1.163 raeburn 1649: unless (($context eq 'requestcourses') ||
1650: ($context eq 'requestauthor')) {
1.86 raeburn 1651: if (ref($settings) eq 'HASH') {
1652: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1653: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1654: } else {
1655: $currdefquota = $settings->{$type};
1656: }
1.197 raeburn 1657: if (ref($settings->{authorquota}) eq 'HASH') {
1658: $currauthorquota = $settings->{authorquota}->{$type};
1659: }
1.78 raeburn 1660: }
1.72 raeburn 1661: }
1.3 raeburn 1662: if (defined($usertypes->{$type})) {
1663: $typecount ++;
1664: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1665: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1666: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1667: '<td class="LC_left_item">';
1.101 raeburn 1668: if ($context eq 'requestcourses') {
1669: $datatable .= '<table><tr>';
1670: }
1671: my %cell;
1.72 raeburn 1672: foreach my $item (@usertools) {
1.101 raeburn 1673: if ($context eq 'requestcourses') {
1674: my ($curroption,$currlimit);
1675: if (ref($settings) eq 'HASH') {
1676: if (ref($settings->{$item}) eq 'HASH') {
1677: $curroption = $settings->{$item}->{$type};
1678: if ($curroption =~ /^autolimit=(\d*)$/) {
1679: $currlimit = $1;
1680: }
1681: }
1682: }
1683: if (!$curroption) {
1684: $curroption = 'norequest';
1685: }
1686: $datatable .= '<th>'.$titles{$item}.'</th>';
1687: foreach my $option (@options) {
1688: my $val = $option;
1689: if ($option eq 'norequest') {
1690: $val = 0;
1691: }
1692: if ($option eq 'validate') {
1693: my $canvalidate = 0;
1694: if (ref($validations{$item}) eq 'HASH') {
1695: if ($validations{$item}{$type}) {
1696: $canvalidate = 1;
1697: }
1698: }
1699: next if (!$canvalidate);
1700: }
1701: my $checked = '';
1702: if ($option eq $curroption) {
1703: $checked = ' checked="checked"';
1704: } elsif ($option eq 'autolimit') {
1705: if ($curroption =~ /^autolimit/) {
1706: $checked = ' checked="checked"';
1707: }
1708: }
1709: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1710: '<input type="radio" name="crsreq_'.$item.
1711: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1712: $titles{$option}.'</label>';
1.101 raeburn 1713: if ($option eq 'autolimit') {
1.127 raeburn 1714: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1715: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1716: 'value="'.$currlimit.'" />';
1.101 raeburn 1717: }
1.127 raeburn 1718: $cell{$item} .= '</span> ';
1.103 raeburn 1719: if ($option eq 'autolimit') {
1.127 raeburn 1720: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1721: }
1.101 raeburn 1722: }
1.163 raeburn 1723: } elsif ($context eq 'requestauthor') {
1724: my $curroption;
1725: if (ref($settings) eq 'HASH') {
1726: $curroption = $settings->{$type};
1727: }
1728: if (!$curroption) {
1729: $curroption = 'norequest';
1730: }
1731: foreach my $option (@options) {
1732: my $val = $option;
1733: if ($option eq 'norequest') {
1734: $val = 0;
1735: }
1736: my $checked = '';
1737: if ($option eq $curroption) {
1738: $checked = ' checked="checked"';
1739: }
1740: $datatable .= '<span class="LC_nobreak"><label>'.
1741: '<input type="radio" name="authorreq_'.$type.
1742: '" value="'.$val.'"'.$checked.' />'.
1743: $titles{$option}.'</label></span> ';
1744: }
1.101 raeburn 1745: } else {
1746: my $checked = 'checked="checked" ';
1747: if (ref($settings) eq 'HASH') {
1748: if (ref($settings->{$item}) eq 'HASH') {
1749: if ($settings->{$item}->{$type} == 0) {
1750: $checked = '';
1751: } elsif ($settings->{$item}->{$type} == 1) {
1752: $checked = 'checked="checked" ';
1753: }
1.78 raeburn 1754: }
1.72 raeburn 1755: }
1.101 raeburn 1756: $datatable .= '<span class="LC_nobreak"><label>'.
1757: '<input type="checkbox" name="'.$context.'_'.$item.
1758: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1759: '</label></span> ';
1.72 raeburn 1760: }
1.101 raeburn 1761: }
1762: if ($context eq 'requestcourses') {
1763: $datatable .= '</tr><tr>';
1764: foreach my $item (@usertools) {
1.106 raeburn 1765: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1766: }
1767: $datatable .= '</tr></table>';
1.72 raeburn 1768: }
1.86 raeburn 1769: $datatable .= '</td>';
1.163 raeburn 1770: unless (($context eq 'requestcourses') ||
1771: ($context eq 'requestauthor')) {
1.86 raeburn 1772: $datatable .=
1.197 raeburn 1773: '<td class="LC_right_item">'.
1774: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1775: '<input type="text" name="quota_'.$type.
1.72 raeburn 1776: '" value="'.$currdefquota.
1.197 raeburn 1777: '" size="5" /></span>'.(' ' x 2).
1778: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1779: '<input type="text" name="authorquota_'.$type.
1780: '" value="'.$currauthorquota.
1781: '" size="5" /></span></td>';
1.86 raeburn 1782: }
1783: $datatable .= '</tr>';
1.3 raeburn 1784: }
1785: }
1786: }
1.163 raeburn 1787: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1788: $defaultquota = '20';
1.197 raeburn 1789: $authorquota = '500';
1.86 raeburn 1790: if (ref($settings) eq 'HASH') {
1791: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1792: $defaultquota = $settings->{'defaultquota'}->{'default'};
1793: } elsif (defined($settings->{'default'})) {
1794: $defaultquota = $settings->{'default'};
1795: }
1.197 raeburn 1796: if (ref($settings->{'authorquota'}) eq 'HASH') {
1797: $authorquota = $settings->{'authorquota'}->{'default'};
1798: }
1.3 raeburn 1799: }
1800: }
1801: $typecount ++;
1802: $css_class = $typecount%2?' class="LC_odd_row"':'';
1803: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1804: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1805: '<td class="LC_left_item">';
1.101 raeburn 1806: if ($context eq 'requestcourses') {
1807: $datatable .= '<table><tr>';
1808: }
1809: my %defcell;
1.72 raeburn 1810: foreach my $item (@usertools) {
1.101 raeburn 1811: if ($context eq 'requestcourses') {
1812: my ($curroption,$currlimit);
1813: if (ref($settings) eq 'HASH') {
1814: if (ref($settings->{$item}) eq 'HASH') {
1815: $curroption = $settings->{$item}->{'default'};
1816: if ($curroption =~ /^autolimit=(\d*)$/) {
1817: $currlimit = $1;
1818: }
1819: }
1820: }
1821: if (!$curroption) {
1822: $curroption = 'norequest';
1823: }
1824: $datatable .= '<th>'.$titles{$item}.'</th>';
1825: foreach my $option (@options) {
1826: my $val = $option;
1827: if ($option eq 'norequest') {
1828: $val = 0;
1829: }
1830: if ($option eq 'validate') {
1831: my $canvalidate = 0;
1832: if (ref($validations{$item}) eq 'HASH') {
1833: if ($validations{$item}{'default'}) {
1834: $canvalidate = 1;
1835: }
1836: }
1837: next if (!$canvalidate);
1838: }
1839: my $checked = '';
1840: if ($option eq $curroption) {
1841: $checked = ' checked="checked"';
1842: } elsif ($option eq 'autolimit') {
1843: if ($curroption =~ /^autolimit/) {
1844: $checked = ' checked="checked"';
1845: }
1846: }
1847: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1848: '<input type="radio" name="crsreq_'.$item.
1849: '_default" value="'.$val.'"'.$checked.' />'.
1850: $titles{$option}.'</label>';
1851: if ($option eq 'autolimit') {
1.127 raeburn 1852: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1853: $item.'_limit_default" size="1" '.
1854: 'value="'.$currlimit.'" />';
1855: }
1.127 raeburn 1856: $defcell{$item} .= '</span> ';
1.104 raeburn 1857: if ($option eq 'autolimit') {
1.127 raeburn 1858: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1859: }
1.101 raeburn 1860: }
1.163 raeburn 1861: } elsif ($context eq 'requestauthor') {
1862: my $curroption;
1863: if (ref($settings) eq 'HASH') {
1.172 raeburn 1864: $curroption = $settings->{'default'};
1.163 raeburn 1865: }
1866: if (!$curroption) {
1867: $curroption = 'norequest';
1868: }
1869: foreach my $option (@options) {
1870: my $val = $option;
1871: if ($option eq 'norequest') {
1872: $val = 0;
1873: }
1874: my $checked = '';
1875: if ($option eq $curroption) {
1876: $checked = ' checked="checked"';
1877: }
1878: $datatable .= '<span class="LC_nobreak"><label>'.
1879: '<input type="radio" name="authorreq_default"'.
1880: ' value="'.$val.'"'.$checked.' />'.
1881: $titles{$option}.'</label></span> ';
1882: }
1.101 raeburn 1883: } else {
1884: my $checked = 'checked="checked" ';
1885: if (ref($settings) eq 'HASH') {
1886: if (ref($settings->{$item}) eq 'HASH') {
1887: if ($settings->{$item}->{'default'} == 0) {
1888: $checked = '';
1889: } elsif ($settings->{$item}->{'default'} == 1) {
1890: $checked = 'checked="checked" ';
1891: }
1.78 raeburn 1892: }
1.72 raeburn 1893: }
1.101 raeburn 1894: $datatable .= '<span class="LC_nobreak"><label>'.
1895: '<input type="checkbox" name="'.$context.'_'.$item.
1896: '" value="default" '.$checked.'/>'.$titles{$item}.
1897: '</label></span> ';
1898: }
1899: }
1900: if ($context eq 'requestcourses') {
1901: $datatable .= '</tr><tr>';
1902: foreach my $item (@usertools) {
1.106 raeburn 1903: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1904: }
1.101 raeburn 1905: $datatable .= '</tr></table>';
1.72 raeburn 1906: }
1.86 raeburn 1907: $datatable .= '</td>';
1.163 raeburn 1908: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1909: $datatable .= '<td class="LC_right_item">'.
1910: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1911: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1912: $defaultquota.'" size="5" /></span>'.(' ' x2).
1913: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1914: '<input type="text" name="authorquota" value="'.
1915: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1916: }
1917: $datatable .= '</tr>';
1.72 raeburn 1918: $typecount ++;
1919: $css_class = $typecount%2?' class="LC_odd_row"':'';
1920: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1921: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1922: if ($context eq 'requestcourses') {
1.109 raeburn 1923: $datatable .= &mt('(overrides affiliation, if set)').
1924: '</td>'.
1925: '<td class="LC_left_item">'.
1926: '<table><tr>';
1.101 raeburn 1927: } else {
1.109 raeburn 1928: $datatable .= &mt('(overrides affiliation, if checked)').
1929: '</td>'.
1930: '<td class="LC_left_item" colspan="2">'.
1931: '<br />';
1.101 raeburn 1932: }
1933: my %advcell;
1.72 raeburn 1934: foreach my $item (@usertools) {
1.101 raeburn 1935: if ($context eq 'requestcourses') {
1936: my ($curroption,$currlimit);
1937: if (ref($settings) eq 'HASH') {
1938: if (ref($settings->{$item}) eq 'HASH') {
1939: $curroption = $settings->{$item}->{'_LC_adv'};
1940: if ($curroption =~ /^autolimit=(\d*)$/) {
1941: $currlimit = $1;
1942: }
1943: }
1944: }
1945: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1946: my $checked = '';
1947: if ($curroption eq '') {
1948: $checked = ' checked="checked"';
1949: }
1950: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1951: '<input type="radio" name="crsreq_'.$item.
1952: '__LC_adv" value=""'.$checked.' />'.
1953: &mt('No override set').'</label></span> ';
1.101 raeburn 1954: foreach my $option (@options) {
1955: my $val = $option;
1956: if ($option eq 'norequest') {
1957: $val = 0;
1958: }
1959: if ($option eq 'validate') {
1960: my $canvalidate = 0;
1961: if (ref($validations{$item}) eq 'HASH') {
1962: if ($validations{$item}{'_LC_adv'}) {
1963: $canvalidate = 1;
1964: }
1965: }
1966: next if (!$canvalidate);
1967: }
1968: my $checked = '';
1.104 raeburn 1969: if ($val eq $curroption) {
1.101 raeburn 1970: $checked = ' checked="checked"';
1971: } elsif ($option eq 'autolimit') {
1972: if ($curroption =~ /^autolimit/) {
1973: $checked = ' checked="checked"';
1974: }
1975: }
1976: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1977: '<input type="radio" name="crsreq_'.$item.
1978: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1979: $titles{$option}.'</label>';
1980: if ($option eq 'autolimit') {
1.127 raeburn 1981: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1982: $item.'_limit__LC_adv" size="1" '.
1983: 'value="'.$currlimit.'" />';
1984: }
1.127 raeburn 1985: $advcell{$item} .= '</span> ';
1.104 raeburn 1986: if ($option eq 'autolimit') {
1.127 raeburn 1987: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1988: }
1.101 raeburn 1989: }
1.163 raeburn 1990: } elsif ($context eq 'requestauthor') {
1991: my $curroption;
1992: if (ref($settings) eq 'HASH') {
1993: $curroption = $settings->{'_LC_adv'};
1994: }
1995: my $checked = '';
1996: if ($curroption eq '') {
1997: $checked = ' checked="checked"';
1998: }
1999: $datatable .= '<span class="LC_nobreak"><label>'.
2000: '<input type="radio" name="authorreq__LC_adv"'.
2001: ' value=""'.$checked.' />'.
2002: &mt('No override set').'</label></span> ';
2003: foreach my $option (@options) {
2004: my $val = $option;
2005: if ($option eq 'norequest') {
2006: $val = 0;
2007: }
2008: my $checked = '';
2009: if ($val eq $curroption) {
2010: $checked = ' checked="checked"';
2011: }
2012: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2013: '<input type="radio" name="authorreq__LC_adv"'.
2014: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2015: $titles{$option}.'</label></span> ';
2016: }
1.101 raeburn 2017: } else {
2018: my $checked = 'checked="checked" ';
2019: if (ref($settings) eq 'HASH') {
2020: if (ref($settings->{$item}) eq 'HASH') {
2021: if ($settings->{$item}->{'_LC_adv'} == 0) {
2022: $checked = '';
2023: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2024: $checked = 'checked="checked" ';
2025: }
1.79 raeburn 2026: }
1.72 raeburn 2027: }
1.101 raeburn 2028: $datatable .= '<span class="LC_nobreak"><label>'.
2029: '<input type="checkbox" name="'.$context.'_'.$item.
2030: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2031: '</label></span> ';
2032: }
2033: }
2034: if ($context eq 'requestcourses') {
2035: $datatable .= '</tr><tr>';
2036: foreach my $item (@usertools) {
1.106 raeburn 2037: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2038: }
1.101 raeburn 2039: $datatable .= '</tr></table>';
1.72 raeburn 2040: }
1.98 raeburn 2041: $datatable .= '</td></tr>';
1.30 raeburn 2042: $$rowtotal += $typecount;
1.3 raeburn 2043: return $datatable;
2044: }
2045:
1.163 raeburn 2046: sub print_requestmail {
2047: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2048: my ($now,$datatable,%currapp);
1.102 raeburn 2049: $now = time;
2050: if (ref($settings) eq 'HASH') {
2051: if (ref($settings->{'notify'}) eq 'HASH') {
2052: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2053: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2054: }
2055: }
2056: }
1.191 raeburn 2057: my $numinrow = 2;
1.224 raeburn 2058: my $css_class;
2059: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2060: my $text;
2061: if ($action eq 'requestcourses') {
2062: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2063: } elsif ($action eq 'requestauthor') {
2064: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2065: } else {
1.224 raeburn 2066: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2067: }
1.224 raeburn 2068: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2069: ' <td>'.$text.'</td>'.
1.102 raeburn 2070: ' <td class="LC_left_item">';
1.191 raeburn 2071: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2072: $action.'notifyapproval',%currapp);
1.191 raeburn 2073: if ($numdc > 0) {
2074: $datatable .= $table;
1.102 raeburn 2075: } else {
2076: $datatable .= &mt('There are no active Domain Coordinators');
2077: }
2078: $datatable .='</td></tr>';
2079: return $datatable;
2080: }
2081:
1.216 raeburn 2082: sub print_studentcode {
2083: my ($settings,$rowtotal) = @_;
2084: my $rownum = 0;
1.218 raeburn 2085: my ($output,%current);
2086: my @crstypes = ('official','unofficial','community','textbook');
1.248 raeburn 2087: if (ref($settings) eq 'HASH') {
2088: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2089: foreach my $type (@crstypes) {
2090: $current{$type} = $settings->{'uniquecode'}{$type};
2091: }
1.218 raeburn 2092: }
2093: }
2094: $output .= '<tr>'.
2095: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2096: '<td class="LC_left_item">';
2097: foreach my $type (@crstypes) {
2098: my $check = ' ';
2099: if ($current{$type}) {
2100: $check = ' checked="checked" ';
2101: }
2102: $output .= '<span class="LC_nobreak"><label>'.
2103: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2104: &mt($type).'</label></span>'.(' 'x2).' ';
2105: }
2106: $output .= '</td></tr>';
2107: $$rowtotal ++;
2108: return $output;
1.216 raeburn 2109: }
2110:
2111: sub print_textbookcourses {
1.242 raeburn 2112: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2113: my $rownum = 0;
2114: my $css_class;
2115: my $itemcount = 1;
2116: my $maxnum = 0;
2117: my $bookshash;
2118: if (ref($settings) eq 'HASH') {
1.242 raeburn 2119: $bookshash = $settings->{$type};
1.216 raeburn 2120: }
2121: my %ordered;
2122: if (ref($bookshash) eq 'HASH') {
2123: foreach my $item (keys(%{$bookshash})) {
2124: if (ref($bookshash->{$item}) eq 'HASH') {
2125: my $num = $bookshash->{$item}{'order'};
2126: $ordered{$num} = $item;
2127: }
2128: }
2129: }
2130: my $confname = $dom.'-domainconfig';
2131: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2132: my $maxnum = scalar(keys(%ordered));
2133: my $datatable;
1.216 raeburn 2134: if (keys(%ordered)) {
2135: my @items = sort { $a <=> $b } keys(%ordered);
2136: for (my $i=0; $i<@items; $i++) {
2137: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2138: my $key = $ordered{$items[$i]};
2139: my %coursehash=&Apache::lonnet::coursedescription($key);
2140: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2141: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2142: if (ref($bookshash->{$key}) eq 'HASH') {
2143: $subject = $bookshash->{$key}->{'subject'};
2144: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2145: if ($type eq 'textbooks') {
1.243 raeburn 2146: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2147: $author = $bookshash->{$key}->{'author'};
2148: $image = $bookshash->{$key}->{'image'};
2149: if ($image ne '') {
2150: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2151: my $imagethumb = "$path/tn-".$imagefile;
2152: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2153: }
1.216 raeburn 2154: }
2155: }
1.242 raeburn 2156: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2157: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2158: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2159: for (my $k=0; $k<=$maxnum; $k++) {
2160: my $vpos = $k+1;
2161: my $selstr;
2162: if ($k == $i) {
2163: $selstr = ' selected="selected" ';
2164: }
2165: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2166: }
2167: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2168: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2169: &mt('Delete?').'</label></span></td>'.
2170: '<td colspan="2">'.
1.242 raeburn 2171: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2172: (' 'x2).
1.242 raeburn 2173: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2174: if ($type eq 'textbooks') {
2175: $datatable .= (' 'x2).
1.243 raeburn 2176: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2177: (' 'x2).
1.242 raeburn 2178: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2179: (' 'x2).
2180: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2181: if ($image) {
2182: $datatable .= '<span class="LC_nobreak">'.
2183: $imgsrc.
2184: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2185: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2186: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2187: }
2188: if ($switchserver) {
2189: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2190: } else {
2191: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2192: }
1.216 raeburn 2193: }
1.242 raeburn 2194: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2195: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2196: $coursetitle.'</span></td></tr>'."\n";
2197: $itemcount ++;
2198: }
2199: }
2200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2201: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2202: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2203: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2204: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2205: for (my $k=0; $k<$maxnum+1; $k++) {
2206: my $vpos = $k+1;
2207: my $selstr;
2208: if ($k == $maxnum) {
2209: $selstr = ' selected="selected" ';
2210: }
2211: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2212: }
2213: $datatable .= '</select> '."\n".
1.242 raeburn 2214: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2215: '<td colspan="2">'.
1.242 raeburn 2216: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2217: (' 'x2).
1.242 raeburn 2218: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2219: (' 'x2);
2220: if ($type eq 'textbooks') {
1.243 raeburn 2221: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2222: (' 'x2).
2223: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2224: (' 'x2).
2225: '<span class="LC_nobreak">'.&mt('Image:').' ';
2226: if ($switchserver) {
2227: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2228: } else {
2229: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2230: }
1.216 raeburn 2231: }
2232: $datatable .= '</span>'."\n".
2233: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2234: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2235: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2236: &Apache::loncommon::selectcourse_link
1.242 raeburn 2237: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2238: '</span></td>'."\n".
2239: '</tr>'."\n";
2240: $itemcount ++;
2241: return $datatable;
2242: }
2243:
1.217 raeburn 2244: sub textbookcourses_javascript {
1.242 raeburn 2245: my ($settings) = @_;
2246: return unless(ref($settings) eq 'HASH');
2247: my (%ordered,%total,%jstext);
2248: foreach my $type ('textbooks','templates') {
2249: $total{$type} = 0;
2250: if (ref($settings->{$type}) eq 'HASH') {
2251: foreach my $item (keys(%{$settings->{$type}})) {
2252: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2253: my $num = $settings->{$type}->{$item}{'order'};
2254: $ordered{$type}{$num} = $item;
2255: }
2256: }
2257: $total{$type} = scalar(keys(%{$settings->{$type}}));
2258: }
2259: my @jsarray = ();
2260: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2261: push(@jsarray,$ordered{$type}{$item});
2262: }
2263: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2264: }
2265: return <<"ENDSCRIPT";
2266: <script type="text/javascript">
2267: // <![CDATA[
1.242 raeburn 2268: function reorderBooks(form,item,caller) {
1.217 raeburn 2269: var changedVal;
1.242 raeburn 2270: $jstext{'textbooks'};
2271: $jstext{'templates'};
2272: var newpos;
2273: var maxh;
2274: if (caller == 'textbooks') {
2275: newpos = 'textbooks_addbook_pos';
2276: maxh = 1 + $total{'textbooks'};
2277: } else {
2278: newpos = 'templates_addbook_pos';
2279: maxh = 1 + $total{'templates'};
2280: }
1.217 raeburn 2281: var current = new Array;
2282: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2283: if (item == newpos) {
2284: changedVal = newitemVal;
2285: } else {
2286: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2287: current[newitemVal] = newpos;
2288: }
1.242 raeburn 2289: if (caller == 'textbooks') {
2290: for (var i=0; i<textbooks.length; i++) {
2291: var elementName = 'textbooks_'+textbooks[i];
2292: if (elementName != item) {
2293: if (form.elements[elementName]) {
2294: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2295: current[currVal] = elementName;
2296: }
2297: }
2298: }
2299: }
2300: if (caller == 'templates') {
2301: for (var i=0; i<templates.length; i++) {
2302: var elementName = 'templates_'+templates[i];
2303: if (elementName != item) {
2304: if (form.elements[elementName]) {
2305: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2306: current[currVal] = elementName;
2307: }
1.217 raeburn 2308: }
2309: }
2310: }
2311: var oldVal;
2312: for (var j=0; j<maxh; j++) {
2313: if (current[j] == undefined) {
2314: oldVal = j;
2315: }
2316: }
2317: if (oldVal < changedVal) {
2318: for (var k=oldVal+1; k<=changedVal ; k++) {
2319: var elementName = current[k];
2320: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2321: }
2322: } else {
2323: for (var k=changedVal; k<oldVal; k++) {
2324: var elementName = current[k];
2325: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2326: }
2327: }
2328: return;
2329: }
2330:
2331: // ]]>
2332: </script>
2333:
2334: ENDSCRIPT
2335: }
2336:
1.3 raeburn 2337: sub print_autoenroll {
1.30 raeburn 2338: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2339: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2340: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2341: if (ref($settings) eq 'HASH') {
2342: if (exists($settings->{'run'})) {
2343: if ($settings->{'run'} eq '0') {
2344: $runoff = ' checked="checked" ';
2345: $runon = ' ';
2346: } else {
2347: $runon = ' checked="checked" ';
2348: $runoff = ' ';
2349: }
2350: } else {
2351: if ($autorun) {
2352: $runon = ' checked="checked" ';
2353: $runoff = ' ';
2354: } else {
2355: $runoff = ' checked="checked" ';
2356: $runon = ' ';
2357: }
2358: }
1.129 raeburn 2359: if (exists($settings->{'co-owners'})) {
2360: if ($settings->{'co-owners'} eq '0') {
2361: $coownersoff = ' checked="checked" ';
2362: $coownerson = ' ';
2363: } else {
2364: $coownerson = ' checked="checked" ';
2365: $coownersoff = ' ';
2366: }
2367: } else {
2368: $coownersoff = ' checked="checked" ';
2369: $coownerson = ' ';
2370: }
1.3 raeburn 2371: if (exists($settings->{'sender_domain'})) {
2372: $defdom = $settings->{'sender_domain'};
2373: }
1.14 raeburn 2374: } else {
2375: if ($autorun) {
2376: $runon = ' checked="checked" ';
2377: $runoff = ' ';
2378: } else {
2379: $runoff = ' checked="checked" ';
2380: $runon = ' ';
2381: }
1.3 raeburn 2382: }
2383: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2384: my $notif_sender;
2385: if (ref($settings) eq 'HASH') {
2386: $notif_sender = $settings->{'sender_uname'};
2387: }
1.3 raeburn 2388: my $datatable='<tr class="LC_odd_row">'.
2389: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2390: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2391: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2392: $runon.' value="1" />'.&mt('Yes').'</label> '.
2393: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2394: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2395: '</tr><tr>'.
2396: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2397: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2398: &mt('username').': '.
2399: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2400: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2401: ': '.$domform.'</span></td></tr>'.
2402: '<tr class="LC_odd_row">'.
2403: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2404: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2405: '<input type="radio" name="autoassign_coowners"'.
2406: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2407: '<label><input type="radio" name="autoassign_coowners"'.
2408: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2409: '</tr>';
2410: $$rowtotal += 3;
1.3 raeburn 2411: return $datatable;
2412: }
2413:
2414: sub print_autoupdate {
1.30 raeburn 2415: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2416: my $datatable;
2417: if ($position eq 'top') {
2418: my $updateon = ' ';
2419: my $updateoff = ' checked="checked" ';
2420: my $classlistson = ' ';
2421: my $classlistsoff = ' checked="checked" ';
2422: if (ref($settings) eq 'HASH') {
2423: if ($settings->{'run'} eq '1') {
2424: $updateon = $updateoff;
2425: $updateoff = ' ';
2426: }
2427: if ($settings->{'classlists'} eq '1') {
2428: $classlistson = $classlistsoff;
2429: $classlistsoff = ' ';
2430: }
2431: }
2432: my %title = (
2433: run => 'Auto-update active?',
2434: classlists => 'Update information in classlists?',
2435: );
2436: $datatable = '<tr class="LC_odd_row">'.
2437: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2438: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2439: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2440: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2441: '<label><input type="radio" name="autoupdate_run"'.
2442: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2443: '</tr><tr>'.
2444: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2445: '<td class="LC_right_item"><span class="LC_nobreak">'.
2446: '<label><input type="radio" name="classlists"'.
2447: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2448: '<label><input type="radio" name="classlists"'.
2449: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2450: '</tr>';
1.30 raeburn 2451: $$rowtotal += 2;
1.131 raeburn 2452: } elsif ($position eq 'middle') {
2453: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2454: my $numinrow = 3;
2455: my $locknamesettings;
2456: $datatable .= &insttypes_row($settings,$types,$usertypes,
2457: $dom,$numinrow,$othertitle,
2458: 'lockablenames');
2459: $$rowtotal ++;
1.3 raeburn 2460: } else {
1.44 raeburn 2461: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2462: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2463: 'permanentemail','id');
1.33 raeburn 2464: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2465: my $numrows = 0;
1.26 raeburn 2466: if (ref($types) eq 'ARRAY') {
2467: if (@{$types} > 0) {
2468: $datatable =
2469: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2470: \@fields,$types,\$numrows);
1.30 raeburn 2471: $$rowtotal += @{$types};
1.26 raeburn 2472: }
1.3 raeburn 2473: }
2474: $datatable .=
2475: &usertype_update_row($settings,{'default' => $othertitle},
2476: \%fieldtitles,\@fields,['default'],
2477: \$numrows);
1.30 raeburn 2478: $$rowtotal ++;
1.3 raeburn 2479: }
2480: return $datatable;
2481: }
2482:
1.125 raeburn 2483: sub print_autocreate {
2484: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2485: my (%createon,%createoff,%currhash);
1.125 raeburn 2486: my @types = ('xml','req');
2487: if (ref($settings) eq 'HASH') {
2488: foreach my $item (@types) {
2489: $createoff{$item} = ' checked="checked" ';
2490: $createon{$item} = ' ';
2491: if (exists($settings->{$item})) {
2492: if ($settings->{$item}) {
2493: $createon{$item} = ' checked="checked" ';
2494: $createoff{$item} = ' ';
2495: }
2496: }
2497: }
1.210 raeburn 2498: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2499: $currhash{$settings->{'xmldc'}} = 1;
2500: }
1.125 raeburn 2501: } else {
2502: foreach my $item (@types) {
2503: $createoff{$item} = ' checked="checked" ';
2504: $createon{$item} = ' ';
2505: }
2506: }
2507: $$rowtotal += 2;
1.191 raeburn 2508: my $numinrow = 2;
1.125 raeburn 2509: my $datatable='<tr class="LC_odd_row">'.
2510: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2511: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2512: '<input type="radio" name="autocreate_xml"'.
2513: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2514: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2515: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2516: '</td></tr><tr>'.
2517: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2518: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2519: '<input type="radio" name="autocreate_req"'.
2520: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2521: '<label><input type="radio" name="autocreate_req"'.
2522: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2523: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2524: 'autocreate_xmldc',%currhash);
1.247 raeburn 2525: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2526: if ($numdc > 1) {
1.247 raeburn 2527: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2528: '</td><td class="LC_left_item">';
1.125 raeburn 2529: } else {
1.247 raeburn 2530: $datatable .= &mt('Course creation processed as:').
2531: '</td><td class="LC_right_item">';
1.125 raeburn 2532: }
1.247 raeburn 2533: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2534: $$rowtotal += $rows;
1.125 raeburn 2535: return $datatable;
2536: }
2537:
1.23 raeburn 2538: sub print_directorysrch {
1.30 raeburn 2539: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2540: my $srchon = ' ';
2541: my $srchoff = ' checked="checked" ';
1.25 raeburn 2542: my ($exacton,$containson,$beginson);
1.24 raeburn 2543: my $localon = ' ';
2544: my $localoff = ' checked="checked" ';
1.23 raeburn 2545: if (ref($settings) eq 'HASH') {
2546: if ($settings->{'available'} eq '1') {
2547: $srchon = $srchoff;
2548: $srchoff = ' ';
2549: }
1.24 raeburn 2550: if ($settings->{'localonly'} eq '1') {
2551: $localon = $localoff;
2552: $localoff = ' ';
2553: }
1.25 raeburn 2554: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2555: foreach my $type (@{$settings->{'searchtypes'}}) {
2556: if ($type eq 'exact') {
2557: $exacton = ' checked="checked" ';
2558: } elsif ($type eq 'contains') {
2559: $containson = ' checked="checked" ';
2560: } elsif ($type eq 'begins') {
2561: $beginson = ' checked="checked" ';
2562: }
2563: }
2564: } else {
2565: if ($settings->{'searchtypes'} eq 'exact') {
2566: $exacton = ' checked="checked" ';
2567: } elsif ($settings->{'searchtypes'} eq 'contains') {
2568: $containson = ' checked="checked" ';
2569: } elsif ($settings->{'searchtypes'} eq 'specify') {
2570: $exacton = ' checked="checked" ';
2571: $containson = ' checked="checked" ';
2572: }
1.23 raeburn 2573: }
2574: }
2575: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2576: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2577:
2578: my $numinrow = 4;
1.26 raeburn 2579: my $cansrchrow = 0;
1.23 raeburn 2580: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2581: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2582: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2583: '<input type="radio" name="dirsrch_available"'.
2584: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2585: '<label><input type="radio" name="dirsrch_available"'.
2586: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2587: '</tr><tr>'.
1.30 raeburn 2588: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2589: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2590: '<input type="radio" name="dirsrch_localonly"'.
2591: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2592: '<label><input type="radio" name="dirsrch_localonly"'.
2593: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2594: '</tr>';
1.30 raeburn 2595: $$rowtotal += 2;
1.26 raeburn 2596: if (ref($usertypes) eq 'HASH') {
2597: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2598: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2599: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2600: $cansrchrow = 1;
2601: }
2602: }
2603: if ($cansrchrow) {
1.30 raeburn 2604: $$rowtotal ++;
1.26 raeburn 2605: $datatable .= '<tr>';
2606: } else {
2607: $datatable .= '<tr class="LC_odd_row">';
2608: }
1.30 raeburn 2609: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2610: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2611: foreach my $title (@{$titleorder}) {
2612: if (defined($searchtitles->{$title})) {
2613: my $check = ' ';
1.93 raeburn 2614: if (ref($settings) eq 'HASH') {
1.39 raeburn 2615: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2616: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2617: $check = ' checked="checked" ';
2618: }
1.25 raeburn 2619: }
2620: }
2621: $datatable .= '<td class="LC_left_item">'.
2622: '<span class="LC_nobreak"><label>'.
2623: '<input type="checkbox" name="searchby" '.
2624: 'value="'.$title.'"'.$check.'/>'.
2625: $searchtitles->{$title}.'</label></span></td>';
2626: }
2627: }
1.26 raeburn 2628: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2629: $$rowtotal ++;
1.26 raeburn 2630: if ($cansrchrow) {
2631: $datatable .= '<tr class="LC_odd_row">';
2632: } else {
2633: $datatable .= '<tr>';
2634: }
1.30 raeburn 2635: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2636: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2637: '<span class="LC_nobreak"><label>'.
2638: '<input type="checkbox" name="searchtypes" '.
2639: $exacton.' value="exact" />'.&mt('Exact match').
2640: '</label> '.
2641: '<label><input type="checkbox" name="searchtypes" '.
2642: $beginson.' value="begins" />'.&mt('Begins with').
2643: '</label> '.
2644: '<label><input type="checkbox" name="searchtypes" '.
2645: $containson.' value="contains" />'.&mt('Contains').
2646: '</label></span></td></tr>';
1.30 raeburn 2647: $$rowtotal ++;
1.25 raeburn 2648: return $datatable;
2649: }
2650:
1.28 raeburn 2651: sub print_contacts {
1.30 raeburn 2652: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2653: my $datatable;
2654: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2655: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2656: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2657: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2658: foreach my $type (@mailings) {
2659: $otheremails{$type} = '';
2660: }
1.134 raeburn 2661: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2662: if (ref($settings) eq 'HASH') {
2663: foreach my $item (@contacts) {
2664: if (exists($settings->{$item})) {
2665: $to{$item} = $settings->{$item};
2666: }
2667: }
2668: foreach my $type (@mailings) {
2669: if (exists($settings->{$type})) {
2670: if (ref($settings->{$type}) eq 'HASH') {
2671: foreach my $item (@contacts) {
2672: if ($settings->{$type}{$item}) {
2673: $checked{$type}{$item} = ' checked="checked" ';
2674: }
2675: }
2676: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2677: if ($type eq 'helpdeskmail') {
2678: $bccemails{$type} = $settings->{$type}{'bcc'};
2679: }
1.28 raeburn 2680: }
1.89 raeburn 2681: } elsif ($type eq 'lonstatusmail') {
2682: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2683: }
2684: }
2685: } else {
2686: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2687: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2688: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2689: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2690: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2691: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2692: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2693: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2694: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2695: }
2696: my ($titles,$short_titles) = &contact_titles();
2697: my $rownum = 0;
2698: my $css_class;
2699: foreach my $item (@contacts) {
1.69 raeburn 2700: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2701: $datatable .= '<tr'.$css_class.'>'.
2702: '<td><span class="LC_nobreak">'.$titles->{$item}.
2703: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2704: '<input type="text" name="'.$item.'" value="'.
2705: $to{$item}.'" /></td></tr>';
1.203 raeburn 2706: $rownum ++;
1.28 raeburn 2707: }
2708: foreach my $type (@mailings) {
1.69 raeburn 2709: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2710: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2711: '<td><span class="LC_nobreak">'.
2712: $titles->{$type}.': </span></td>'.
1.28 raeburn 2713: '<td class="LC_left_item">'.
2714: '<span class="LC_nobreak">';
2715: foreach my $item (@contacts) {
2716: $datatable .= '<label>'.
2717: '<input type="checkbox" name="'.$type.'"'.
2718: $checked{$type}{$item}.
2719: ' value="'.$item.'" />'.$short_titles->{$item}.
2720: '</label> ';
2721: }
2722: $datatable .= '</span><br />'.&mt('Others').': '.
2723: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2724: 'value="'.$otheremails{$type}.'" />';
2725: if ($type eq 'helpdeskmail') {
1.136 raeburn 2726: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2727: '<input type="text" name="'.$type.'_bcc" '.
2728: 'value="'.$bccemails{$type}.'" />';
2729: }
2730: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2731: $rownum ++;
1.28 raeburn 2732: }
1.203 raeburn 2733: my %choices;
2734: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2735: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2736: &mt('LON-CAPA core group - MSU'),600,500));
2737: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2738: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2739: &mt('LON-CAPA core group - MSU'),600,500));
2740: my @toggles = ('reporterrors','reportupdates');
2741: my %defaultchecked = ('reporterrors' => 'on',
2742: 'reportupdates' => 'on');
2743: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2744: \%choices,$rownum);
2745: $datatable .= $reports;
1.30 raeburn 2746: $$rowtotal += $rownum;
1.28 raeburn 2747: return $datatable;
2748: }
2749:
1.118 jms 2750: sub print_helpsettings {
1.168 raeburn 2751: my ($dom,$confname,$settings,$rowtotal) = @_;
2752: my ($datatable,$itemcount);
1.166 raeburn 2753: $itemcount = 1;
1.168 raeburn 2754: my (%choices,%defaultchecked,@toggles);
2755: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2756: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2757: &mt('LON-CAPA bug tracker'),600,500));
2758: %defaultchecked = ('submitbugs' => 'on');
2759: @toggles = ('submitbugs',);
1.166 raeburn 2760:
1.168 raeburn 2761: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2762: \%choices,$itemcount);
1.166 raeburn 2763: return $datatable;
1.121 raeburn 2764: }
2765:
2766: sub radiobutton_prefs {
1.192 raeburn 2767: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2768: $additional) = @_;
1.121 raeburn 2769: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2770: (ref($choices) eq 'HASH'));
2771:
1.170 raeburn 2772: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2773:
2774: foreach my $item (@{$toggles}) {
2775: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2776: $checkedon{$item} = ' checked="checked" ';
2777: $checkedoff{$item} = ' ';
1.121 raeburn 2778: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2779: $checkedoff{$item} = ' checked="checked" ';
2780: $checkedon{$item} = ' ';
2781: }
2782: }
2783: if (ref($settings) eq 'HASH') {
1.121 raeburn 2784: foreach my $item (@{$toggles}) {
1.118 jms 2785: if ($settings->{$item} eq '1') {
2786: $checkedon{$item} = ' checked="checked" ';
2787: $checkedoff{$item} = ' ';
2788: } elsif ($settings->{$item} eq '0') {
2789: $checkedoff{$item} = ' checked="checked" ';
2790: $checkedon{$item} = ' ';
2791: }
2792: }
1.121 raeburn 2793: }
1.192 raeburn 2794: if ($onclick) {
2795: $onclick = ' onclick="'.$onclick.'"';
2796: }
1.121 raeburn 2797: foreach my $item (@{$toggles}) {
1.118 jms 2798: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2799: $datatable .=
1.192 raeburn 2800: '<tr'.$css_class.'><td valign="top">'.
2801: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2802: '</span></td>'.
2803: '<td class="LC_right_item"><span class="LC_nobreak">'.
2804: '<label><input type="radio" name="'.
1.192 raeburn 2805: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2806: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2807: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2808: '</span>'.$additional.
2809: '</td>'.
1.118 jms 2810: '</tr>';
2811: $itemcount ++;
1.121 raeburn 2812: }
2813: return ($datatable,$itemcount);
2814: }
2815:
2816: sub print_coursedefaults {
1.139 raeburn 2817: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2818: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2819: my $itemcount = 1;
1.192 raeburn 2820: my %choices = &Apache::lonlocal::texthash (
2821: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2822: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2823: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2824: coursecredits => 'Credits can be specified for courses',
2825: );
1.198 raeburn 2826: my %staticdefaults = (
2827: anonsurvey_threshold => 10,
2828: uploadquota => 500,
2829: );
1.139 raeburn 2830: if ($position eq 'top') {
2831: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2832: @toggles = ('canuse_pdfforms');
1.139 raeburn 2833: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2834: \%choices,$itemcount);
1.139 raeburn 2835: } else {
2836: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2837: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2838: %curruploadquota);
1.192 raeburn 2839: my $currusecredits = 0;
1.216 raeburn 2840: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2841: if (ref($settings) eq 'HASH') {
2842: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2843: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2844: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2845: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2846: }
2847: }
1.192 raeburn 2848: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2849: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2850: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2851: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2852: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2853: ($def_textbook_credits ne '')) {
1.192 raeburn 2854: $currusecredits = 1;
2855: }
2856: }
1.139 raeburn 2857: }
2858: if (!$currdefresponder) {
1.198 raeburn 2859: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2860: } elsif ($currdefresponder < 1) {
2861: $currdefresponder = 1;
2862: }
1.198 raeburn 2863: foreach my $type (@types) {
2864: if ($curruploadquota{$type} eq '') {
2865: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2866: }
2867: }
1.139 raeburn 2868: $datatable .=
1.192 raeburn 2869: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2870: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2871: '</span></td>'.
2872: '<td class="LC_right_item"><span class="LC_nobreak">'.
2873: '<input type="text" name="anonsurvey_threshold"'.
2874: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2875: '</td></tr>'."\n";
2876: $itemcount ++;
2877: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2878: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2879: $choices{'uploadquota'}.
2880: '</span></td>'.
2881: '<td align="right" class="LC_right_item">'.
2882: '<table><tr>';
1.198 raeburn 2883: foreach my $type (@types) {
2884: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2885: '<input type="text" name="uploadquota_'.$type.'"'.
2886: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2887: }
2888: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2889: $itemcount ++;
1.236 raeburn 2890: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 2891: my $display = 'none';
1.192 raeburn 2892: if ($currusecredits) {
2893: $display = 'block';
2894: }
2895: my $additional = '<div id="credits" style="display: '.$display.'">'.
2896: '<span class="LC_nobreak">'.
2897: &mt('Default credits for official courses [_1]',
2898: '<input type="text" name="official_credits" value="'.
2899: $def_official_credits.'" size="3" />').
2900: '</span><br />'.
2901: '<span class="LC_nobreak">'.
2902: &mt('Default credits for unofficial courses [_1]',
2903: '<input type="text" name="unofficial_credits" value="'.
2904: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2905: '</span><br />'.
2906: '<span class="LC_nobreak">'.
2907: &mt('Default credits for textbook courses [_1]',
2908: '<input type="text" name="textbook_credits" value="'.
2909: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2910: '</span></div>'."\n";
2911: %defaultchecked = ('coursecredits' => 'off');
2912: @toggles = ('coursecredits');
2913: my $current = {
2914: 'coursecredits' => $currusecredits,
2915: };
2916: (my $table,$itemcount) =
2917: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2918: \%choices,$itemcount,$onclick,$additional);
2919: $datatable .= $table;
1.230 raeburn 2920: $itemcount ++;
1.139 raeburn 2921: }
1.192 raeburn 2922: $$rowtotal += $itemcount;
1.121 raeburn 2923: return $datatable;
1.118 jms 2924: }
2925:
1.231 raeburn 2926: sub print_selfenrollment {
2927: my ($position,$dom,$settings,$rowtotal) = @_;
2928: my ($css_class,$datatable);
2929: my $itemcount = 1;
2930: my @types = ('official','unofficial','community','textbook');
2931: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 2932: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2933: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 2934: my @rows;
2935: my $key;
2936: if ($position eq 'top') {
2937: $key = 'admin';
2938: if (ref($rowsref) eq 'ARRAY') {
2939: @rows = @{$rowsref};
2940: }
2941: } elsif ($position eq 'middle') {
2942: $key = 'default';
2943: @rows = ('types','registered','approval','limit');
2944: }
2945: foreach my $row (@rows) {
2946: if (defined($titlesref->{$row})) {
2947: $itemcount ++;
2948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2949: $datatable .= '<tr'.$css_class.'>'.
2950: '<td>'.$titlesref->{$row}.'</td>'.
2951: '<td class="LC_left_item">'.
2952: '<table><tr>';
2953: my (%current,%currentcap);
2954: if (ref($settings) eq 'HASH') {
2955: if (ref($settings->{$key}) eq 'HASH') {
2956: foreach my $type (@types) {
2957: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2958: $current{$type} = $settings->{$key}->{$type}->{$row};
2959: }
2960: if (($row eq 'limit') && ($key eq 'default')) {
2961: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2962: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2963: }
2964: }
2965: }
2966: }
2967: }
2968: my %roles = (
2969: '0' => &Apache::lonnet::plaintext('dc'),
2970: );
2971:
2972: foreach my $type (@types) {
2973: unless (($row eq 'registered') && ($key eq 'default')) {
2974: $datatable .= '<th>'.&mt($type).'</th>';
2975: }
2976: }
2977: unless (($row eq 'registered') && ($key eq 'default')) {
2978: $datatable .= '</tr><tr>';
2979: }
2980: foreach my $type (@types) {
2981: if ($type eq 'community') {
2982: $roles{'1'} = &mt('Community personnel');
2983: } else {
2984: $roles{'1'} = &mt('Course personnel');
2985: }
2986: $datatable .= '<td style="vertical-align: top">';
2987: if ($position eq 'top') {
2988: my %checked;
2989: if ($current{$type} eq '0') {
2990: $checked{'0'} = ' checked="checked"';
2991: } else {
2992: $checked{'1'} = ' checked="checked"';
2993: }
2994: foreach my $role ('1','0') {
2995: $datatable .= '<span class="LC_nobreak"><label>'.
2996: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2997: 'value="'.$role.'"'.$checked{$role}.' />'.
2998: $roles{$role}.'</label></span> ';
2999: }
3000: } else {
3001: if ($row eq 'types') {
3002: my %checked;
3003: if ($current{$type} =~ /^(all|dom)$/) {
3004: $checked{$1} = ' checked="checked"';
3005: } else {
3006: $checked{''} = ' checked="checked"';
3007: }
3008: foreach my $val ('','dom','all') {
3009: $datatable .= '<span class="LC_nobreak"><label>'.
3010: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3011: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3012: }
3013: } elsif ($row eq 'registered') {
3014: my %checked;
3015: if ($current{$type} eq '1') {
3016: $checked{'1'} = ' checked="checked"';
3017: } else {
3018: $checked{'0'} = ' checked="checked"';
3019: }
3020: foreach my $val ('0','1') {
3021: $datatable .= '<span class="LC_nobreak"><label>'.
3022: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3023: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3024: }
3025: } elsif ($row eq 'approval') {
3026: my %checked;
3027: if ($current{$type} =~ /^([12])$/) {
3028: $checked{$1} = ' checked="checked"';
3029: } else {
3030: $checked{'0'} = ' checked="checked"';
3031: }
3032: for my $val (0..2) {
3033: $datatable .= '<span class="LC_nobreak"><label>'.
3034: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3035: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3036: }
3037: } elsif ($row eq 'limit') {
3038: my %checked;
3039: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3040: $checked{$1} = ' checked="checked"';
3041: } else {
3042: $checked{'none'} = ' checked="checked"';
3043: }
3044: my $cap;
3045: if ($currentcap{$type} =~ /^\d+$/) {
3046: $cap = $currentcap{$type};
3047: }
3048: foreach my $val ('none','allstudents','selfenrolled') {
3049: $datatable .= '<span class="LC_nobreak"><label>'.
3050: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3051: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3052: }
3053: $datatable .= '<br />'.
3054: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3055: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3056: '</span>';
3057: }
3058: }
3059: $datatable .= '</td>';
3060: }
3061: $datatable .= '</tr>';
3062: }
3063: $datatable .= '</table></td></tr>';
3064: }
3065: } elsif ($position eq 'bottom') {
1.235 raeburn 3066: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3067: }
3068: $$rowtotal += $itemcount;
3069: return $datatable;
3070: }
3071:
3072: sub print_validation_rows {
3073: my ($caller,$dom,$settings,$rowtotal) = @_;
3074: my ($itemsref,$namesref,$fieldsref);
3075: if ($caller eq 'selfenroll') {
3076: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3077: } elsif ($caller eq 'requestcourses') {
3078: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3079: }
3080: my %currvalidation;
3081: if (ref($settings) eq 'HASH') {
3082: if (ref($settings->{'validation'}) eq 'HASH') {
3083: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3084: }
1.235 raeburn 3085: }
3086: my $datatable;
3087: my $itemcount = 0;
3088: foreach my $item (@{$itemsref}) {
3089: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3090: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3091: $namesref->{$item}.
3092: '</span></td>'.
3093: '<td class="LC_left_item">';
3094: if (($item eq 'url') || ($item eq 'button')) {
3095: $datatable .= '<span class="LC_nobreak">'.
3096: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3097: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3098: } elsif ($item eq 'fields') {
3099: my @currfields;
3100: if (ref($currvalidation{$item}) eq 'ARRAY') {
3101: @currfields = @{$currvalidation{$item}};
3102: }
3103: foreach my $field (@{$fieldsref}) {
3104: my $check = '';
3105: if (grep(/^\Q$field\E$/,@currfields)) {
3106: $check = ' checked="checked"';
3107: }
3108: $datatable .= '<span class="LC_nobreak"><label>'.
3109: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3110: ' value="'.$field.'"'.$check.' />'.$field.
3111: '</label></span> ';
3112: }
3113: } elsif ($item eq 'markup') {
3114: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3115: $currvalidation{$item}.
1.231 raeburn 3116: '</textarea>';
1.235 raeburn 3117: }
3118: $datatable .= '</td></tr>'."\n";
3119: if (ref($rowtotal)) {
1.231 raeburn 3120: $itemcount ++;
3121: }
3122: }
1.235 raeburn 3123: if ($caller eq 'requestcourses') {
3124: my %currhash;
1.248 raeburn 3125: if (ref($settings) eq 'HASH') {
3126: if (ref($settings->{'validation'}) eq 'HASH') {
3127: if ($settings->{'validation'}{'dc'} ne '') {
3128: $currhash{$settings->{'validation'}{'dc'}} = 1;
3129: }
1.235 raeburn 3130: }
3131: }
3132: my $numinrow = 2;
3133: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3134: 'validationdc',%currhash);
1.247 raeburn 3135: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3136: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3137: if ($numdc > 1) {
1.247 raeburn 3138: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3139: } else {
1.247 raeburn 3140: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3141: }
1.247 raeburn 3142: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3143: $itemcount ++;
3144: }
3145: if (ref($rowtotal)) {
3146: $$rowtotal += $itemcount;
3147: }
1.231 raeburn 3148: return $datatable;
3149: }
3150:
1.137 raeburn 3151: sub print_usersessions {
3152: my ($position,$dom,$settings,$rowtotal) = @_;
3153: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3154: my (%by_ip,%by_location,@intdoms);
3155: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3156:
3157: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3158: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3159: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3160: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3161: my $itemcount = 1;
3162: if ($position eq 'top') {
1.152 raeburn 3163: if (keys(%serverhomes) > 1) {
1.145 raeburn 3164: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3165: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3166: } else {
1.140 raeburn 3167: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3168: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3169: }
1.137 raeburn 3170: } else {
1.145 raeburn 3171: if (keys(%by_location) == 0) {
3172: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3173: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3174: } else {
3175: my %lt = &usersession_titles();
3176: my $numinrow = 5;
3177: my $prefix;
3178: my @types;
3179: if ($position eq 'bottom') {
3180: $prefix = 'remote';
3181: @types = ('version','excludedomain','includedomain');
3182: } else {
3183: $prefix = 'hosted';
3184: @types = ('excludedomain','includedomain');
3185: }
3186: my (%current,%checkedon,%checkedoff);
3187: my @lcversions = &Apache::lonnet::all_loncaparevs();
3188: my @locations = sort(keys(%by_location));
3189: foreach my $type (@types) {
3190: $checkedon{$type} = '';
3191: $checkedoff{$type} = ' checked="checked"';
3192: }
3193: if (ref($settings) eq 'HASH') {
3194: if (ref($settings->{$prefix}) eq 'HASH') {
3195: foreach my $key (keys(%{$settings->{$prefix}})) {
3196: $current{$key} = $settings->{$prefix}{$key};
3197: if ($key eq 'version') {
3198: if ($current{$key} ne '') {
3199: $checkedon{$key} = ' checked="checked"';
3200: $checkedoff{$key} = '';
3201: }
3202: } elsif (ref($current{$key}) eq 'ARRAY') {
3203: $checkedon{$key} = ' checked="checked"';
3204: $checkedoff{$key} = '';
3205: }
1.137 raeburn 3206: }
3207: }
3208: }
1.145 raeburn 3209: foreach my $type (@types) {
3210: next if ($type ne 'version' && !@locations);
3211: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3212: $datatable .= '<tr'.$css_class.'>
3213: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3214: <span class="LC_nobreak">
3215: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3216: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3217: if ($type eq 'version') {
3218: my $selector = '<select name="'.$prefix.'_version">';
3219: foreach my $version (@lcversions) {
3220: my $selected = '';
3221: if ($current{'version'} eq $version) {
3222: $selected = ' selected="selected"';
3223: }
3224: $selector .= ' <option value="'.$version.'"'.
3225: $selected.'>'.$version.'</option>';
3226: }
3227: $selector .= '</select> ';
3228: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3229: } else {
3230: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3231: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3232: ' />'.(' 'x2).
3233: '<input type="button" value="'.&mt('uncheck all').'" '.
3234: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3235: "\n".
3236: '</div><div><table>';
3237: my $rem;
3238: for (my $i=0; $i<@locations; $i++) {
3239: my ($showloc,$value,$checkedtype);
3240: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3241: my $ip = $by_location{$locations[$i]}->[0];
3242: if (ref($by_ip{$ip}) eq 'ARRAY') {
3243: $value = join(':',@{$by_ip{$ip}});
3244: $showloc = join(', ',@{$by_ip{$ip}});
3245: if (ref($current{$type}) eq 'ARRAY') {
3246: foreach my $loc (@{$by_ip{$ip}}) {
3247: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3248: $checkedtype = ' checked="checked"';
3249: last;
3250: }
3251: }
1.138 raeburn 3252: }
3253: }
3254: }
1.145 raeburn 3255: $rem = $i%($numinrow);
3256: if ($rem == 0) {
3257: if ($i > 0) {
3258: $datatable .= '</tr>';
3259: }
3260: $datatable .= '<tr>';
3261: }
3262: $datatable .= '<td class="LC_left_item">'.
3263: '<span class="LC_nobreak"><label>'.
3264: '<input type="checkbox" name="'.$prefix.'_'.$type.
3265: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3266: '</label></span></td>';
1.137 raeburn 3267: }
1.145 raeburn 3268: $rem = @locations%($numinrow);
3269: my $colsleft = $numinrow - $rem;
3270: if ($colsleft > 1 ) {
3271: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3272: ' </td>';
3273: } elsif ($colsleft == 1) {
3274: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3275: }
1.145 raeburn 3276: $datatable .= '</tr></table>';
1.137 raeburn 3277: }
1.145 raeburn 3278: $datatable .= '</td></tr>';
3279: $itemcount ++;
1.137 raeburn 3280: }
3281: }
3282: }
3283: $$rowtotal += $itemcount;
3284: return $datatable;
3285: }
3286:
1.138 raeburn 3287: sub build_location_hashes {
3288: my ($intdoms,$by_ip,$by_location) = @_;
3289: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3290: (ref($by_location) eq 'HASH'));
3291: my %iphost = &Apache::lonnet::get_iphost();
3292: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3293: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3294: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3295: foreach my $id (@{$iphost{$primary_ip}}) {
3296: my $intdom = &Apache::lonnet::internet_dom($id);
3297: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3298: push(@{$intdoms},$intdom);
3299: }
3300: }
3301: }
3302: foreach my $ip (keys(%iphost)) {
3303: if (ref($iphost{$ip}) eq 'ARRAY') {
3304: foreach my $id (@{$iphost{$ip}}) {
3305: my $location = &Apache::lonnet::internet_dom($id);
3306: if ($location) {
3307: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3308: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3309: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3310: push(@{$by_ip->{$ip}},$location);
3311: }
3312: } else {
3313: $by_ip->{$ip} = [$location];
3314: }
3315: }
3316: }
3317: }
3318: }
3319: foreach my $ip (sort(keys(%{$by_ip}))) {
3320: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3321: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3322: my $first = $by_ip->{$ip}->[0];
3323: if (ref($by_location->{$first}) eq 'ARRAY') {
3324: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3325: push(@{$by_location->{$first}},$ip);
3326: }
3327: } else {
3328: $by_location->{$first} = [$ip];
3329: }
3330: }
3331: }
3332: return;
3333: }
3334:
1.145 raeburn 3335: sub current_offloads_to {
3336: my ($dom,$settings,$servers) = @_;
3337: my (%spareid,%otherdomconfigs);
1.152 raeburn 3338: if (ref($servers) eq 'HASH') {
1.145 raeburn 3339: foreach my $lonhost (sort(keys(%{$servers}))) {
3340: my $gotspares;
1.152 raeburn 3341: if (ref($settings) eq 'HASH') {
3342: if (ref($settings->{'spares'}) eq 'HASH') {
3343: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3344: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3345: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3346: $gotspares = 1;
3347: }
1.145 raeburn 3348: }
3349: }
3350: unless ($gotspares) {
3351: my $gotspares;
3352: my $serverhomeID =
3353: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3354: my $serverhomedom =
3355: &Apache::lonnet::host_domain($serverhomeID);
3356: if ($serverhomedom ne $dom) {
3357: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3358: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3359: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3360: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3361: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3362: $gotspares = 1;
3363: }
3364: }
3365: } else {
3366: $otherdomconfigs{$serverhomedom} =
3367: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3368: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3369: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3370: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3371: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3372: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3373: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3374: $gotspares = 1;
3375: }
3376: }
3377: }
3378: }
3379: }
3380: }
3381: }
3382: unless ($gotspares) {
3383: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3384: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3385: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3386: } else {
3387: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3388: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3389: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3390: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3391: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3392: } else {
1.150 raeburn 3393: my %what = (
3394: spareid => 1,
3395: );
3396: my ($result,$returnhash) =
3397: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3398: if ($result eq 'ok') {
3399: if (ref($returnhash) eq 'HASH') {
3400: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3401: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3402: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3403: }
3404: }
1.145 raeburn 3405: }
3406: }
3407: }
3408: }
3409: }
3410: }
3411: return %spareid;
3412: }
3413:
3414: sub spares_row {
1.152 raeburn 3415: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3416: my $css_class;
3417: my $numinrow = 4;
3418: my $itemcount = 1;
3419: my $datatable;
1.152 raeburn 3420: my %typetitles = &sparestype_titles();
3421: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3422: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3423: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3424: my ($othercontrol,$serverdom);
3425: if ($serverhome ne $server) {
3426: $serverdom = &Apache::lonnet::host_domain($serverhome);
3427: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3428: } else {
3429: $serverdom = &Apache::lonnet::host_domain($server);
3430: if ($serverdom ne $dom) {
3431: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3432: }
3433: }
3434: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3435: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3436: $datatable .= '<tr'.$css_class.'>
3437: <td rowspan="2">
1.183 bisitz 3438: <span class="LC_nobreak">'.
3439: &mt('[_1] when busy, offloads to:'
3440: ,'<b>'.$server.'</b>').
3441: "\n";
1.145 raeburn 3442: my (%current,%canselect);
1.152 raeburn 3443: my @choices =
3444: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3445: foreach my $type ('primary','default') {
3446: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3447: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3448: my @spares = @{$spareid->{$server}{$type}};
3449: if (@spares > 0) {
1.152 raeburn 3450: if ($othercontrol) {
3451: $current{$type} = join(', ',@spares);
3452: } else {
3453: $current{$type} .= '<table>';
3454: my $numspares = scalar(@spares);
3455: for (my $i=0; $i<@spares; $i++) {
3456: my $rem = $i%($numinrow);
3457: if ($rem == 0) {
3458: if ($i > 0) {
3459: $current{$type} .= '</tr>';
3460: }
3461: $current{$type} .= '<tr>';
1.145 raeburn 3462: }
1.152 raeburn 3463: $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'".');" /> '.
3464: $spareid->{$server}{$type}[$i].
3465: '</label></td>'."\n";
3466: }
3467: my $rem = @spares%($numinrow);
3468: my $colsleft = $numinrow - $rem;
3469: if ($colsleft > 1 ) {
3470: $current{$type} .= '<td colspan="'.$colsleft.
3471: '" class="LC_left_item">'.
3472: ' </td>';
3473: } elsif ($colsleft == 1) {
3474: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3475: }
1.152 raeburn 3476: $current{$type} .= '</tr></table>';
1.150 raeburn 3477: }
1.145 raeburn 3478: }
3479: }
3480: if ($current{$type} eq '') {
3481: $current{$type} = &mt('None specified');
3482: }
1.152 raeburn 3483: if ($othercontrol) {
3484: if ($type eq 'primary') {
3485: $canselect{$type} = $othercontrol;
3486: }
3487: } else {
3488: $canselect{$type} =
3489: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3490: '<select name="newspare_'.$type.'_'.$server.'" '.
3491: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3492: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3493: if (@choices > 0) {
3494: foreach my $lonhost (@choices) {
3495: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3496: }
3497: }
3498: $canselect{$type} .= '</select>'."\n";
3499: }
3500: } else {
3501: $current{$type} = &mt('Could not be determined');
3502: if ($type eq 'primary') {
3503: $canselect{$type} = $othercontrol;
3504: }
1.145 raeburn 3505: }
1.152 raeburn 3506: if ($type eq 'default') {
3507: $datatable .= '<tr'.$css_class.'>';
3508: }
3509: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3510: '<td>'.$current{$type}.'</td>'."\n".
3511: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3512: }
3513: $itemcount ++;
3514: }
3515: }
3516: $$rowtotal += $itemcount;
3517: return $datatable;
3518: }
3519:
1.152 raeburn 3520: sub possible_newspares {
3521: my ($server,$currspares,$serverhomes,$altids) = @_;
3522: my $serverhostname = &Apache::lonnet::hostname($server);
3523: my %excluded;
3524: if ($serverhostname ne '') {
3525: %excluded = (
3526: $serverhostname => 1,
3527: );
3528: }
3529: if (ref($currspares) eq 'HASH') {
3530: foreach my $type (keys(%{$currspares})) {
3531: if (ref($currspares->{$type}) eq 'ARRAY') {
3532: if (@{$currspares->{$type}} > 0) {
3533: foreach my $curr (@{$currspares->{$type}}) {
3534: my $hostname = &Apache::lonnet::hostname($curr);
3535: $excluded{$hostname} = 1;
3536: }
3537: }
3538: }
3539: }
3540: }
3541: my @choices;
3542: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3543: if (keys(%{$serverhomes}) > 1) {
3544: foreach my $name (sort(keys(%{$serverhomes}))) {
3545: unless ($excluded{$name}) {
3546: if (exists($altids->{$serverhomes->{$name}})) {
3547: push(@choices,$altids->{$serverhomes->{$name}});
3548: } else {
3549: push(@choices,$serverhomes->{$name});
1.145 raeburn 3550: }
3551: }
3552: }
3553: }
3554: }
1.152 raeburn 3555: return sort(@choices);
1.145 raeburn 3556: }
3557:
1.150 raeburn 3558: sub print_loadbalancing {
3559: my ($dom,$settings,$rowtotal) = @_;
3560: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3561: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3562: my $numinrow = 1;
3563: my $datatable;
3564: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3565: my (%currbalancer,%currtargets,%currrules,%existing);
3566: if (ref($settings) eq 'HASH') {
3567: %existing = %{$settings};
3568: }
3569: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3570: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3571: \%currtargets,\%currrules);
1.150 raeburn 3572: } else {
3573: return;
3574: }
3575: my ($othertitle,$usertypes,$types) =
3576: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3577: my $rownum = 8;
1.150 raeburn 3578: if (ref($types) eq 'ARRAY') {
3579: $rownum += scalar(@{$types});
3580: }
1.171 raeburn 3581: my @css_class = ('LC_odd_row','LC_even_row');
3582: my $balnum = 0;
3583: my $islast;
3584: my (@toshow,$disabledtext);
3585: if (keys(%currbalancer) > 0) {
3586: @toshow = sort(keys(%currbalancer));
3587: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3588: push(@toshow,'');
3589: }
3590: } else {
3591: @toshow = ('');
3592: $disabledtext = &mt('No existing load balancer');
3593: }
3594: foreach my $lonhost (@toshow) {
3595: if ($balnum == scalar(@toshow)-1) {
3596: $islast = 1;
3597: } else {
3598: $islast = 0;
3599: }
3600: my $cssidx = $balnum%2;
3601: my $targets_div_style = 'display: none';
3602: my $disabled_div_style = 'display: block';
3603: my $homedom_div_style = 'display: none';
3604: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3605: '<td rowspan="'.$rownum.'" valign="top">'.
3606: '<p>';
3607: if ($lonhost eq '') {
1.210 raeburn 3608: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3609: if (keys(%currbalancer) > 0) {
3610: $datatable .= &mt('Add balancer:');
3611: } else {
3612: $datatable .= &mt('Enable balancer:');
3613: }
3614: $datatable .= ' '.
3615: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3616: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3617: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3618: '<option value="" selected="selected">'.&mt('None').
3619: '</option>'."\n";
3620: foreach my $server (sort(keys(%servers))) {
3621: next if ($currbalancer{$server});
3622: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3623: }
1.210 raeburn 3624: $datatable .=
1.171 raeburn 3625: '</select>'."\n".
3626: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3627: } else {
3628: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3629: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3630: &mt('Stop balancing').'</label>'.
3631: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3632: $targets_div_style = 'display: block';
3633: $disabled_div_style = 'display: none';
3634: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3635: $homedom_div_style = 'display: block';
3636: }
3637: }
3638: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3639: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3640: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3641: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3642: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3643: my @sparestypes = ('primary','default');
3644: my %typetitles = &sparestype_titles();
3645: foreach my $sparetype (@sparestypes) {
3646: my $targettable;
3647: for (my $i=0; $i<$numspares; $i++) {
3648: my $checked;
3649: if (ref($currtargets{$lonhost}) eq 'HASH') {
3650: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3651: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3652: $checked = ' checked="checked"';
3653: }
3654: }
3655: }
3656: my ($chkboxval,$disabled);
3657: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3658: $chkboxval = $spares[$i];
3659: }
3660: if (exists($currbalancer{$spares[$i]})) {
3661: $disabled = ' disabled="disabled"';
3662: }
1.210 raeburn 3663: $targettable .=
1.171 raeburn 3664: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3665: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3666: '</span></label></td>';
3667: my $rem = $i%($numinrow);
3668: if ($rem == 0) {
3669: if (($i > 0) && ($i < $numspares-1)) {
3670: $targettable .= '</tr>';
3671: }
3672: if ($i < $numspares-1) {
3673: $targettable .= '<tr>';
1.150 raeburn 3674: }
3675: }
3676: }
1.171 raeburn 3677: if ($targettable ne '') {
3678: my $rem = $numspares%($numinrow);
3679: my $colsleft = $numinrow - $rem;
3680: if ($colsleft > 1 ) {
3681: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3682: ' </td>';
3683: } elsif ($colsleft == 1) {
3684: $targettable .= '<td class="LC_left_item"> </td>';
3685: }
3686: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3687: '<table><tr>'.$targettable.'</tr></table><br />';
3688: }
3689: }
3690: $datatable .= '</div></td></tr>'.
3691: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3692: $othertitle,$usertypes,$types,\%servers,
3693: \%currbalancer,$lonhost,
3694: $targets_div_style,$homedom_div_style,
3695: $css_class[$cssidx],$balnum,$islast);
3696: $$rowtotal += $rownum;
3697: $balnum ++;
3698: }
3699: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3700: return $datatable;
3701: }
3702:
3703: sub get_loadbalancers_config {
3704: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3705: return unless ((ref($servers) eq 'HASH') &&
3706: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3707: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3708: if (keys(%{$existing}) > 0) {
3709: my $oldlonhost;
3710: foreach my $key (sort(keys(%{$existing}))) {
3711: if ($key eq 'lonhost') {
3712: $oldlonhost = $existing->{'lonhost'};
3713: $currbalancer->{$oldlonhost} = 1;
3714: } elsif ($key eq 'targets') {
3715: if ($oldlonhost) {
3716: $currtargets->{$oldlonhost} = $existing->{'targets'};
3717: }
3718: } elsif ($key eq 'rules') {
3719: if ($oldlonhost) {
3720: $currrules->{$oldlonhost} = $existing->{'rules'};
3721: }
3722: } elsif (ref($existing->{$key}) eq 'HASH') {
3723: $currbalancer->{$key} = 1;
3724: $currtargets->{$key} = $existing->{$key}{'targets'};
3725: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3726: }
3727: }
1.171 raeburn 3728: } else {
3729: my ($balancerref,$targetsref) =
3730: &Apache::lonnet::get_lonbalancer_config($servers);
3731: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3732: foreach my $server (sort(keys(%{$balancerref}))) {
3733: $currbalancer->{$server} = 1;
3734: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3735: }
3736: }
3737: }
1.171 raeburn 3738: return;
1.150 raeburn 3739: }
3740:
3741: sub loadbalancing_rules {
3742: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3743: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3744: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3745: my $output;
1.171 raeburn 3746: my $num = 0;
1.210 raeburn 3747: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3748: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3749: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3750: foreach my $type (@{$alltypes}) {
1.171 raeburn 3751: $num ++;
1.150 raeburn 3752: my $current;
3753: if (ref($currrules) eq 'HASH') {
3754: $current = $currrules->{$type};
3755: }
1.209 raeburn 3756: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3757: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3758: $current = '';
3759: }
3760: }
3761: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3762: $servers,$currbalancer,$lonhost,$dom,
3763: $targets_div_style,$homedom_div_style,
3764: $css_class,$balnum,$num,$islast);
1.150 raeburn 3765: }
3766: }
3767: return $output;
3768: }
3769:
3770: sub loadbalancing_titles {
3771: my ($dom,$intdom,$usertypes,$types) = @_;
3772: my %othertypes = (
3773: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3774: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3775: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3776: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3777: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3778: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3779: );
1.209 raeburn 3780: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3781: if (ref($types) eq 'ARRAY') {
3782: unshift(@alltypes,@{$types},'default');
3783: }
3784: my %titles;
3785: foreach my $type (@alltypes) {
3786: if ($type =~ /^_LC_/) {
3787: $titles{$type} = $othertypes{$type};
3788: } elsif ($type eq 'default') {
3789: $titles{$type} = &mt('All users from [_1]',$dom);
3790: if (ref($types) eq 'ARRAY') {
3791: if (@{$types} > 0) {
3792: $titles{$type} = &mt('Other users from [_1]',$dom);
3793: }
3794: }
3795: } elsif (ref($usertypes) eq 'HASH') {
3796: $titles{$type} = $usertypes->{$type};
3797: }
3798: }
3799: return (\@alltypes,\%othertypes,\%titles);
3800: }
3801:
3802: sub loadbalance_rule_row {
1.171 raeburn 3803: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3804: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3805: my @rulenames;
1.150 raeburn 3806: my %ruletitles = &offloadtype_text();
1.209 raeburn 3807: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3808: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3809: } else {
1.209 raeburn 3810: @rulenames = ('default','homeserver');
3811: if ($type eq '_LC_external') {
3812: push(@rulenames,'externalbalancer');
3813: } else {
3814: push(@rulenames,'specific');
3815: }
3816: push(@rulenames,'none');
1.150 raeburn 3817: }
3818: my $style = $targets_div_style;
1.209 raeburn 3819: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3820: $style = $homedom_div_style;
3821: }
1.171 raeburn 3822: my $space;
3823: if ($islast && $num == 1) {
3824: $space = '<div display="inline-block"> </div>';
3825: }
1.210 raeburn 3826: my $output =
1.171 raeburn 3827: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3828: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3829: '<td valaign="top">'.$space.
3830: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3831: for (my $i=0; $i<@rulenames; $i++) {
3832: my $rule = $rulenames[$i];
3833: my ($checked,$extra);
3834: if ($rulenames[$i] eq 'default') {
3835: $rule = '';
3836: }
3837: if ($rulenames[$i] eq 'specific') {
3838: if (ref($servers) eq 'HASH') {
3839: my $default;
3840: if (($current ne '') && (exists($servers->{$current}))) {
3841: $checked = ' checked="checked"';
3842: }
3843: unless ($checked) {
3844: $default = ' selected="selected"';
3845: }
1.210 raeburn 3846: $extra =
1.171 raeburn 3847: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3848: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3849: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3850: '<option value=""'.$default.'></option>'."\n";
3851: foreach my $server (sort(keys(%{$servers}))) {
3852: if (ref($currbalancer) eq 'HASH') {
3853: next if (exists($currbalancer->{$server}));
3854: }
1.150 raeburn 3855: my $selected;
1.171 raeburn 3856: if ($server eq $current) {
1.150 raeburn 3857: $selected = ' selected="selected"';
3858: }
1.171 raeburn 3859: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3860: }
3861: $extra .= '</select>';
3862: }
3863: } elsif ($rule eq $current) {
3864: $checked = ' checked="checked"';
3865: }
3866: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3867: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3868: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3869: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3870: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3871: '</label>'.$extra.'</span><br />'."\n";
3872: }
3873: $output .= '</div></td></tr>'."\n";
3874: return $output;
3875: }
3876:
3877: sub offloadtype_text {
3878: my %ruletitles = &Apache::lonlocal::texthash (
3879: 'default' => 'Offloads to default destinations',
3880: 'homeserver' => "Offloads to user's home server",
3881: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3882: 'specific' => 'Offloads to specific server',
1.161 raeburn 3883: 'none' => 'No offload',
1.209 raeburn 3884: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3885: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3886: );
3887: return %ruletitles;
3888: }
3889:
3890: sub sparestype_titles {
3891: my %typestitles = &Apache::lonlocal::texthash (
3892: 'primary' => 'primary',
3893: 'default' => 'default',
3894: );
3895: return %typestitles;
3896: }
3897:
1.28 raeburn 3898: sub contact_titles {
3899: my %titles = &Apache::lonlocal::texthash (
3900: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3901: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3902: 'errormail' => 'Error reports to be e-mailed to',
3903: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3904: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3905: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3906: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3907: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3908: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3909: );
3910: my %short_titles = &Apache::lonlocal::texthash (
3911: adminemail => 'Admin E-mail address',
3912: supportemail => 'Support E-mail',
3913: );
3914: return (\%titles,\%short_titles);
3915: }
3916:
1.72 raeburn 3917: sub tool_titles {
3918: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3919: aboutme => 'Personal web page',
1.86 raeburn 3920: blog => 'Blog',
1.162 raeburn 3921: webdav => 'WebDAV',
1.86 raeburn 3922: portfolio => 'Portfolio',
1.88 bisitz 3923: official => 'Official courses (with institutional codes)',
3924: unofficial => 'Unofficial courses',
1.98 raeburn 3925: community => 'Communities',
1.216 raeburn 3926: textbook => 'Textbook courses',
1.86 raeburn 3927: );
1.72 raeburn 3928: return %titles;
3929: }
3930:
1.101 raeburn 3931: sub courserequest_titles {
3932: my %titles = &Apache::lonlocal::texthash (
3933: official => 'Official',
3934: unofficial => 'Unofficial',
3935: community => 'Communities',
1.216 raeburn 3936: textbook => 'Textbook',
1.101 raeburn 3937: norequest => 'Not allowed',
1.104 raeburn 3938: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3939: validate => 'With validation',
3940: autolimit => 'Numerical limit',
1.103 raeburn 3941: unlimited => '(blank for unlimited)',
1.101 raeburn 3942: );
3943: return %titles;
3944: }
3945:
1.163 raeburn 3946: sub authorrequest_titles {
3947: my %titles = &Apache::lonlocal::texthash (
3948: norequest => 'Not allowed',
3949: approval => 'Approval by Dom. Coord.',
3950: automatic => 'Automatic approval',
3951: );
3952: return %titles;
1.210 raeburn 3953: }
1.163 raeburn 3954:
1.101 raeburn 3955: sub courserequest_conditions {
3956: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3957: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3958: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3959: );
3960: return %conditions;
3961: }
3962:
3963:
1.27 raeburn 3964: sub print_usercreation {
1.30 raeburn 3965: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3966: my $numinrow = 4;
1.28 raeburn 3967: my $datatable;
3968: if ($position eq 'top') {
1.30 raeburn 3969: $$rowtotal ++;
1.34 raeburn 3970: my $rowcount = 0;
1.32 raeburn 3971: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3972: if (ref($rules) eq 'HASH') {
3973: if (keys(%{$rules}) > 0) {
1.32 raeburn 3974: $datatable .= &user_formats_row('username',$settings,$rules,
3975: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3976: $$rowtotal ++;
1.32 raeburn 3977: $rowcount ++;
3978: }
3979: }
3980: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3981: if (ref($idrules) eq 'HASH') {
3982: if (keys(%{$idrules}) > 0) {
3983: $datatable .= &user_formats_row('id',$settings,$idrules,
3984: $idruleorder,$numinrow,$rowcount);
3985: $$rowtotal ++;
3986: $rowcount ++;
1.28 raeburn 3987: }
3988: }
1.39 raeburn 3989: if ($rowcount == 0) {
3990: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3991: $$rowtotal ++;
3992: $rowcount ++;
3993: }
1.34 raeburn 3994: } elsif ($position eq 'middle') {
1.224 raeburn 3995: my @creators = ('author','course','requestcrs');
1.37 raeburn 3996: my ($rules,$ruleorder) =
3997: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3998: my %lt = &usercreation_types();
3999: my %checked;
4000: if (ref($settings) eq 'HASH') {
4001: if (ref($settings->{'cancreate'}) eq 'HASH') {
4002: foreach my $item (@creators) {
4003: $checked{$item} = $settings->{'cancreate'}{$item};
4004: }
4005: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4006: foreach my $item (@creators) {
4007: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4008: $checked{$item} = 'none';
4009: }
4010: }
4011: }
4012: }
4013: my $rownum = 0;
4014: foreach my $item (@creators) {
4015: $rownum ++;
1.224 raeburn 4016: if ($checked{$item} eq '') {
4017: $checked{$item} = 'any';
1.34 raeburn 4018: }
4019: my $css_class;
4020: if ($rownum%2) {
4021: $css_class = '';
4022: } else {
4023: $css_class = ' class="LC_odd_row" ';
4024: }
4025: $datatable .= '<tr'.$css_class.'>'.
4026: '<td><span class="LC_nobreak">'.$lt{$item}.
4027: '</span></td><td align="right">';
1.224 raeburn 4028: my @options = ('any');
4029: if (ref($rules) eq 'HASH') {
4030: if (keys(%{$rules}) > 0) {
4031: push(@options,('official','unofficial'));
1.37 raeburn 4032: }
4033: }
1.224 raeburn 4034: push(@options,'none');
1.37 raeburn 4035: foreach my $option (@options) {
1.50 raeburn 4036: my $type = 'radio';
1.34 raeburn 4037: my $check = ' ';
1.224 raeburn 4038: if ($checked{$item} eq $option) {
4039: $check = ' checked="checked" ';
1.34 raeburn 4040: }
4041: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4042: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4043: $item.'" value="'.$option.'"'.$check.'/> '.
4044: $lt{$option}.'</label> </span>';
4045: }
4046: $datatable .= '</td></tr>';
4047: }
1.28 raeburn 4048: } else {
4049: my @contexts = ('author','course','domain');
4050: my @authtypes = ('int','krb4','krb5','loc');
4051: my %checked;
4052: if (ref($settings) eq 'HASH') {
4053: if (ref($settings->{'authtypes'}) eq 'HASH') {
4054: foreach my $item (@contexts) {
4055: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4056: foreach my $auth (@authtypes) {
4057: if ($settings->{'authtypes'}{$item}{$auth}) {
4058: $checked{$item}{$auth} = ' checked="checked" ';
4059: }
4060: }
4061: }
4062: }
1.27 raeburn 4063: }
1.35 raeburn 4064: } else {
4065: foreach my $item (@contexts) {
1.36 raeburn 4066: foreach my $auth (@authtypes) {
1.35 raeburn 4067: $checked{$item}{$auth} = ' checked="checked" ';
4068: }
4069: }
1.27 raeburn 4070: }
1.28 raeburn 4071: my %title = &context_names();
4072: my %authname = &authtype_names();
4073: my $rownum = 0;
4074: my $css_class;
4075: foreach my $item (@contexts) {
4076: if ($rownum%2) {
4077: $css_class = '';
4078: } else {
4079: $css_class = ' class="LC_odd_row" ';
4080: }
1.30 raeburn 4081: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4082: '<td>'.$title{$item}.
4083: '</td><td class="LC_left_item">'.
4084: '<span class="LC_nobreak">';
4085: foreach my $auth (@authtypes) {
4086: $datatable .= '<label>'.
4087: '<input type="checkbox" name="'.$item.'_auth" '.
4088: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4089: $authname{$auth}.'</label> ';
4090: }
4091: $datatable .= '</span></td></tr>';
4092: $rownum ++;
1.27 raeburn 4093: }
1.30 raeburn 4094: $$rowtotal += $rownum;
1.27 raeburn 4095: }
4096: return $datatable;
4097: }
4098:
1.224 raeburn 4099: sub print_selfcreation {
4100: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4101: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4102: if (ref($settings) eq 'HASH') {
4103: if (ref($settings->{'cancreate'}) eq 'HASH') {
4104: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4105: if (ref($createsettings) eq 'HASH') {
4106: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4107: @selfcreate = @{$createsettings->{'selfcreate'}};
4108: } elsif ($createsettings->{'selfcreate'} ne '') {
4109: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4110: @selfcreate = ('email','login','sso');
4111: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4112: @selfcreate = ($createsettings->{'selfcreate'});
4113: }
4114: }
4115: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4116: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4117: }
4118: }
4119: }
4120: }
4121: my %radiohash;
4122: my $numinrow = 4;
4123: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4124: if ($position eq 'top') {
4125: my %choices = &Apache::lonlocal::texthash (
4126: cancreate_login => 'Institutional Login',
4127: cancreate_sso => 'Institutional Single Sign On',
4128: );
4129: my @toggles = sort(keys(%choices));
4130: my %defaultchecked = (
4131: 'cancreate_login' => 'off',
4132: 'cancreate_sso' => 'off',
4133: );
1.228 raeburn 4134: my ($onclick,$itemcount);
1.224 raeburn 4135: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4136: \%choices,$itemcount,$onclick);
1.228 raeburn 4137: $$rowtotal += $itemcount;
4138:
1.224 raeburn 4139: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4140:
4141: if (ref($usertypes) eq 'HASH') {
4142: if (keys(%{$usertypes}) > 0) {
4143: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4144: $dom,$numinrow,$othertitle,
1.228 raeburn 4145: 'statustocreate',$$rowtotal);
1.224 raeburn 4146: $$rowtotal ++;
4147: }
4148: }
1.240 raeburn 4149: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4150: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4151: $fieldtitles{'inststatus'} = &mt('Institutional status');
4152: my $rem;
4153: my $numperrow = 2;
4154: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4155: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4156: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4157: '<td class="LC_left_item">'."\n".
4158: '<table><tr><td>'."\n";
4159: for (my $i=0; $i<@fields; $i++) {
4160: $rem = $i%($numperrow);
4161: if ($rem == 0) {
4162: if ($i > 0) {
4163: $datatable .= '</tr>';
4164: }
4165: $datatable .= '<tr>';
4166: }
4167: my $currval;
1.248 raeburn 4168: if (ref($createsettings) eq 'HASH') {
4169: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4170: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4171: }
1.240 raeburn 4172: }
4173: $datatable .= '<td class="LC_left_item">'.
4174: '<span class="LC_nobreak">'.
4175: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4176: 'value="'.$currval.'" size="10" /> '.
4177: $fieldtitles{$fields[$i]}.'</span></td>';
4178: }
4179: my $colsleft = $numperrow - $rem;
4180: if ($colsleft > 1 ) {
4181: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4182: ' </td>';
4183: } elsif ($colsleft == 1) {
4184: $datatable .= '<td class="LC_left_item"> </td>';
4185: }
4186: $datatable .= '</tr></table></td></tr>';
4187: $$rowtotal ++;
1.224 raeburn 4188: } elsif ($position eq 'middle') {
4189: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4190: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4191: $usertypes->{'default'} = $othertitle;
4192: if (ref($types) eq 'ARRAY') {
4193: push(@{$types},'default');
4194: $usertypes->{'default'} = $othertitle;
4195: foreach my $status (@{$types}) {
4196: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4197: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4198: $$rowtotal ++;
1.224 raeburn 4199: }
4200: }
4201: } else {
1.236 raeburn 4202: my %choices = &Apache::lonlocal::texthash (
4203: cancreate_email => 'E-mail address as username',
4204: );
4205: my @toggles = sort(keys(%choices));
4206: my %defaultchecked = (
4207: 'cancreate_email' => 'off',
4208: );
4209: my $itemcount = 0;
4210: my $display = 'none';
4211: if (grep(/^\Qemail\E$/,@selfcreate)) {
4212: $display = 'block';
4213: }
4214: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4215: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4216: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4217: my $usertypes = {};
4218: my $order = [];
4219: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4220: $usertypes = $domdefaults{'inststatustypes'};
4221: $order = $domdefaults{'inststatusguest'};
4222: }
4223: if (ref($order) eq 'ARRAY') {
4224: push(@{$order},'default');
4225: if (@{$order} > 1) {
4226: $usertypes->{'default'} = &mt('Other users');
4227: $additional .= '<table><tr>';
4228: foreach my $status (@{$order}) {
4229: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4230: }
4231: $additional .= '</tr><tr>';
4232: foreach my $status (@{$order}) {
4233: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4234: }
1.236 raeburn 4235: $additional .= '</tr></table>';
1.224 raeburn 4236: } else {
1.236 raeburn 4237: $usertypes->{'default'} = &mt('All users');
4238: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4239: }
4240: }
1.236 raeburn 4241: $additional .= '</div>'."\n";
4242:
4243: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4244: \%choices,$$rowtotal,$onclick,$additional);
4245: $$rowtotal ++;
1.236 raeburn 4246: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4247: $$rowtotal ++;
1.224 raeburn 4248: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4249: $numinrow = 1;
1.236 raeburn 4250: if (ref($order) eq 'ARRAY') {
4251: foreach my $status (@{$order}) {
1.228 raeburn 4252: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4253: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4254: $$rowtotal ++;
4255: }
4256: }
1.224 raeburn 4257: my ($emailrules,$emailruleorder) =
4258: &Apache::lonnet::inst_userrules($dom,'email');
4259: if (ref($emailrules) eq 'HASH') {
4260: if (keys(%{$emailrules}) > 0) {
4261: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4262: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4263: $$rowtotal ++;
4264: }
4265: }
1.228 raeburn 4266: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4267: }
4268: return $datatable;
4269: }
4270:
1.236 raeburn 4271: sub email_as_username {
4272: my ($rowtotal,$processing,$type) = @_;
4273: my %choices =
4274: &Apache::lonlocal::texthash (
4275: automatic => 'Automatic approval',
4276: approval => 'Queued for approval',
4277: );
4278: my $output;
4279: foreach my $option ('automatic','approval') {
4280: my $checked;
4281: if (ref($processing) eq 'HASH') {
4282: if ($type eq '') {
4283: if (!exists($processing->{'default'})) {
4284: if ($option eq 'automatic') {
4285: $checked = ' checked="checked"';
4286: }
4287: } else {
4288: if ($processing->{'default'} eq $option) {
4289: $checked = ' checked="checked"';
4290: }
4291: }
4292: } else {
4293: if (!exists($processing->{$type})) {
4294: if ($option eq 'automatic') {
4295: $checked = ' checked="checked"';
4296: }
4297: } else {
4298: if ($processing->{$type} eq $option) {
4299: $checked = ' checked="checked"';
4300: }
4301: }
4302: }
4303: } elsif ($option eq 'automatic') {
4304: $checked = ' checked="checked"';
4305: }
4306: my $name = 'cancreate_emailprocess';
4307: if (($type ne '') && ($type ne 'default')) {
4308: $name .= '_'.$type;
4309: }
4310: $output .= '<span class="LC_nobreak"><label>'.
4311: '<input type="radio" name="'.$name.'"'.
4312: $checked.' value="'.$option.'" />'.
4313: $choices{$option}.'</label></span>';
4314: if ($type eq '') {
4315: $output .= ' ';
4316: } else {
4317: $output .= '<br />';
4318: }
4319: }
4320: $$rowtotal ++;
4321: return $output;
4322: }
4323:
1.165 raeburn 4324: sub captcha_choice {
1.169 raeburn 4325: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4326: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4327: my %lt = &captcha_phrases();
4328: $keyentry = 'hidden';
4329: if ($context eq 'cancreate') {
1.224 raeburn 4330: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4331: } elsif ($context eq 'login') {
4332: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4333: }
4334: if (ref($settings) eq 'HASH') {
4335: if ($settings->{'captcha'}) {
4336: $checked{$settings->{'captcha'}} = ' checked="checked"';
4337: } else {
4338: $checked{'original'} = ' checked="checked"';
4339: }
4340: if ($settings->{'captcha'} eq 'recaptcha') {
4341: $pubtext = $lt{'pub'};
4342: $privtext = $lt{'priv'};
4343: $keyentry = 'text';
4344: }
4345: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4346: $currpub = $settings->{'recaptchakeys'}{'public'};
4347: $currpriv = $settings->{'recaptchakeys'}{'private'};
4348: }
4349: } else {
4350: $checked{'original'} = ' checked="checked"';
4351: }
1.169 raeburn 4352: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4353: my $output = '<tr'.$css_class.'>'.
4354: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4355: '<table><tr><td>'."\n";
4356: foreach my $option ('original','recaptcha','notused') {
4357: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4358: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4359: $lt{$option}.'</label></span>';
4360: unless ($option eq 'notused') {
4361: $output .= (' 'x2)."\n";
4362: }
4363: }
4364: #
4365: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4366: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4367: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4368: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4369: #
1.165 raeburn 4370: $output .= '</td></tr>'."\n".
4371: '<tr><td>'."\n".
4372: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4373: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4374: $currpub.'" size="40" /></span><br />'."\n".
4375: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4376: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4377: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4378: '</td></tr>';
4379: return $output;
4380: }
4381:
1.32 raeburn 4382: sub user_formats_row {
4383: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4384: my $output;
4385: my %text = (
4386: 'username' => 'new usernames',
4387: 'id' => 'IDs',
1.45 raeburn 4388: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4389: );
4390: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4391: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4392: '<td><span class="LC_nobreak">';
4393: if ($type eq 'email') {
4394: $output .= &mt("Formats disallowed for $text{$type}: ");
4395: } else {
4396: $output .= &mt("Format rules to check for $text{$type}: ");
4397: }
4398: $output .= '</span></td>'.
4399: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4400: my $rem;
4401: if (ref($ruleorder) eq 'ARRAY') {
4402: for (my $i=0; $i<@{$ruleorder}; $i++) {
4403: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4404: my $rem = $i%($numinrow);
4405: if ($rem == 0) {
4406: if ($i > 0) {
4407: $output .= '</tr>';
4408: }
4409: $output .= '<tr>';
4410: }
4411: my $check = ' ';
1.39 raeburn 4412: if (ref($settings) eq 'HASH') {
4413: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4414: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4415: $check = ' checked="checked" ';
4416: }
1.27 raeburn 4417: }
4418: }
4419: $output .= '<td class="LC_left_item">'.
4420: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4421: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4422: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4423: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4424: }
4425: }
4426: $rem = @{$ruleorder}%($numinrow);
4427: }
4428: my $colsleft = $numinrow - $rem;
4429: if ($colsleft > 1 ) {
4430: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4431: ' </td>';
4432: } elsif ($colsleft == 1) {
4433: $output .= '<td class="LC_left_item"> </td>';
4434: }
4435: $output .= '</tr></table></td></tr>';
4436: return $output;
4437: }
4438:
1.34 raeburn 4439: sub usercreation_types {
4440: my %lt = &Apache::lonlocal::texthash (
4441: author => 'When adding a co-author',
4442: course => 'When adding a user to a course',
1.100 raeburn 4443: requestcrs => 'When requesting a course',
1.34 raeburn 4444: any => 'Any',
4445: official => 'Institutional only ',
4446: unofficial => 'Non-institutional only',
4447: none => 'None',
4448: );
4449: return %lt;
1.48 raeburn 4450: }
1.34 raeburn 4451:
1.224 raeburn 4452: sub selfcreation_types {
4453: my %lt = &Apache::lonlocal::texthash (
4454: selfcreate => 'User creates own account',
4455: any => 'Any',
4456: official => 'Institutional only ',
4457: unofficial => 'Non-institutional only',
4458: email => 'E-mail address',
4459: login => 'Institutional Login',
4460: sso => 'SSO',
4461: );
4462: }
4463:
1.28 raeburn 4464: sub authtype_names {
4465: my %lt = &Apache::lonlocal::texthash(
4466: int => 'Internal',
4467: krb4 => 'Kerberos 4',
4468: krb5 => 'Kerberos 5',
4469: loc => 'Local',
4470: );
4471: return %lt;
4472: }
4473:
4474: sub context_names {
4475: my %context_title = &Apache::lonlocal::texthash(
4476: author => 'Creating users when an Author',
4477: course => 'Creating users when in a course',
4478: domain => 'Creating users when a Domain Coordinator',
4479: );
4480: return %context_title;
4481: }
4482:
1.33 raeburn 4483: sub print_usermodification {
4484: my ($position,$dom,$settings,$rowtotal) = @_;
4485: my $numinrow = 4;
4486: my ($context,$datatable,$rowcount);
4487: if ($position eq 'top') {
4488: $rowcount = 0;
4489: $context = 'author';
4490: foreach my $role ('ca','aa') {
4491: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4492: $numinrow,$rowcount);
4493: $$rowtotal ++;
4494: $rowcount ++;
4495: }
1.230 raeburn 4496: } elsif ($position eq 'bottom') {
1.33 raeburn 4497: $context = 'course';
4498: $rowcount = 0;
4499: foreach my $role ('st','ep','ta','in','cr') {
4500: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4501: $numinrow,$rowcount);
4502: $$rowtotal ++;
4503: $rowcount ++;
4504: }
4505: }
4506: return $datatable;
4507: }
4508:
1.43 raeburn 4509: sub print_defaults {
1.236 raeburn 4510: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4511: my $rownum = 0;
4512: my ($datatable,$css_class);
1.236 raeburn 4513: if ($position eq 'top') {
4514: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4515: 'datelocale_def','portal_def');
4516: my %defaults;
4517: if (ref($settings) eq 'HASH') {
4518: %defaults = %{$settings};
1.43 raeburn 4519: } else {
1.236 raeburn 4520: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4521: foreach my $item (@items) {
4522: $defaults{$item} = $domdefaults{$item};
4523: }
1.43 raeburn 4524: }
1.236 raeburn 4525: my $titles = &defaults_titles($dom);
4526: foreach my $item (@items) {
4527: if ($rownum%2) {
4528: $css_class = '';
4529: } else {
4530: $css_class = ' class="LC_odd_row" ';
4531: }
4532: $datatable .= '<tr'.$css_class.'>'.
4533: '<td><span class="LC_nobreak">'.$titles->{$item}.
4534: '</span></td><td class="LC_right_item" colspan="3">';
4535: if ($item eq 'auth_def') {
4536: my @authtypes = ('internal','krb4','krb5','localauth');
4537: my %shortauth = (
4538: internal => 'int',
4539: krb4 => 'krb4',
4540: krb5 => 'krb5',
4541: localauth => 'loc'
4542: );
4543: my %authnames = &authtype_names();
4544: foreach my $auth (@authtypes) {
4545: my $checked = ' ';
4546: if ($defaults{$item} eq $auth) {
4547: $checked = ' checked="checked" ';
4548: }
4549: $datatable .= '<label><input type="radio" name="'.$item.
4550: '" value="'.$auth.'"'.$checked.'/>'.
4551: $authnames{$shortauth{$auth}}.'</label> ';
4552: }
4553: } elsif ($item eq 'timezone_def') {
4554: my $includeempty = 1;
4555: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4556: } elsif ($item eq 'datelocale_def') {
4557: my $includeempty = 1;
4558: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4559: } elsif ($item eq 'lang_def') {
4560: my %langchoices = &get_languages_hash();
4561: $langchoices{''} = 'No language preference';
4562: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4563: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4564: \%langchoices);
4565: } else {
4566: my $size;
4567: if ($item eq 'portal_def') {
4568: $size = ' size="25"';
4569: }
4570: $datatable .= '<input type="text" name="'.$item.'" value="'.
4571: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4572: }
1.236 raeburn 4573: $datatable .= '</td></tr>';
4574: $rownum ++;
4575: }
4576: } else {
4577: my (%defaults);
4578: if (ref($settings) eq 'HASH') {
4579: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4580: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4581: my $maxnum = @{$settings->{'inststatusorder'}};
4582: for (my $i=0; $i<$maxnum; $i++) {
4583: $css_class = $rownum%2?' class="LC_odd_row"':'';
4584: my $item = $settings->{'inststatusorder'}->[$i];
4585: my $title = $settings->{'inststatustypes'}->{$item};
4586: my $guestok;
4587: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4588: $guestok = 1;
4589: }
4590: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4591: $datatable .= '<tr'.$css_class.'>'.
4592: '<td><span class="LC_nobreak">'.
4593: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4594: for (my $k=0; $k<=$maxnum; $k++) {
4595: my $vpos = $k+1;
4596: my $selstr;
4597: if ($k == $i) {
4598: $selstr = ' selected="selected" ';
4599: }
4600: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4601: }
4602: my ($checkedon,$checkedoff);
4603: $checkedoff = ' checked="checked"';
4604: if ($guestok) {
4605: $checkedon = $checkedoff;
4606: $checkedoff = '';
4607: }
4608: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4609: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4610: &mt('delete').'</span></td>'.
4611: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4612: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4613: '</span></td>'.
4614: '<td class="LC_right_item"><span class="LC_nobreak">'.
4615: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4616: &mt('Yes').'</label>'.(' 'x2).
4617: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4618: &mt('No').'</label></span></td></tr>';
4619: }
4620: $css_class = $rownum%2?' class="LC_odd_row"':'';
4621: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4622: $datatable .= '<tr '.$css_class.'>'.
4623: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4624: for (my $k=0; $k<=$maxnum; $k++) {
4625: my $vpos = $k+1;
4626: my $selstr;
4627: if ($k == $maxnum) {
4628: $selstr = ' selected="selected" ';
4629: }
4630: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4631: }
4632: $datatable .= '</select> '.&mt('Internal ID:').
4633: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4634: ' '.&mt('(new)').
4635: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4636: &mt('Name displayed:').
4637: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4638: '<td class="LC_right_item"><span class="LC_nobreak">'.
4639: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4640: &mt('Yes').'</label>'.(' 'x2).
4641: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4642: &mt('No').'</label></span></td></tr>';
4643: '</tr>'."\n";
4644: $rownum ++;
1.141 raeburn 4645: }
1.43 raeburn 4646: }
4647: }
4648: $$rowtotal += $rownum;
4649: return $datatable;
4650: }
4651:
1.168 raeburn 4652: sub get_languages_hash {
4653: my %langchoices;
4654: foreach my $id (&Apache::loncommon::languageids()) {
4655: my $code = &Apache::loncommon::supportedlanguagecode($id);
4656: if ($code ne '') {
4657: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4658: }
4659: }
4660: return %langchoices;
4661: }
4662:
1.43 raeburn 4663: sub defaults_titles {
1.141 raeburn 4664: my ($dom) = @_;
1.43 raeburn 4665: my %titles = &Apache::lonlocal::texthash (
4666: 'auth_def' => 'Default authentication type',
4667: 'auth_arg_def' => 'Default authentication argument',
4668: 'lang_def' => 'Default language',
1.54 raeburn 4669: 'timezone_def' => 'Default timezone',
1.68 raeburn 4670: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4671: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4672: );
1.141 raeburn 4673: if ($dom) {
4674: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4675: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4676: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4677: $protocol = 'http' if ($protocol ne 'https');
4678: if ($uint_dom) {
4679: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4680: $uint_dom);
4681: }
4682: }
1.43 raeburn 4683: return (\%titles);
4684: }
4685:
1.46 raeburn 4686: sub print_scantronformat {
4687: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4688: my $itemcount = 1;
1.60 raeburn 4689: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4690: %confhash);
1.46 raeburn 4691: my $switchserver = &check_switchserver($dom,$confname);
4692: my %lt = &Apache::lonlocal::texthash (
1.95 www 4693: default => 'Default bubblesheet format file error',
4694: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4695: );
4696: my %scantronfiles = (
4697: default => 'default.tab',
4698: custom => 'custom.tab',
4699: );
4700: foreach my $key (keys(%scantronfiles)) {
4701: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4702: .$scantronfiles{$key};
4703: }
4704: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4705: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4706: if (!$switchserver) {
4707: my $servadm = $r->dir_config('lonAdmEMail');
4708: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4709: if ($configuserok eq 'ok') {
4710: if ($author_ok eq 'ok') {
4711: my %legacyfile = (
4712: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4713: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4714: );
4715: my %md5chk;
4716: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4717: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4718: chomp($md5chk{$type});
1.46 raeburn 4719: }
4720: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4721: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4722: ($scantronurls{$type},my $error) =
1.46 raeburn 4723: &legacy_scantronformat($r,$dom,$confname,
4724: $type,$legacyfile{$type},
4725: $scantronurls{$type},
4726: $scantronfiles{$type});
1.60 raeburn 4727: if ($error ne '') {
4728: $error{$type} = $error;
4729: }
4730: }
4731: if (keys(%error) == 0) {
4732: $is_custom = 1;
4733: $confhash{'scantron'}{'scantronformat'} =
4734: $scantronurls{'custom'};
4735: my $putresult =
4736: &Apache::lonnet::put_dom('configuration',
4737: \%confhash,$dom);
4738: if ($putresult ne 'ok') {
4739: $error{'custom'} =
4740: '<span class="LC_error">'.
4741: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4742: }
1.46 raeburn 4743: }
4744: } else {
1.60 raeburn 4745: ($scantronurls{'default'},my $error) =
1.46 raeburn 4746: &legacy_scantronformat($r,$dom,$confname,
4747: 'default',$legacyfile{'default'},
4748: $scantronurls{'default'},
4749: $scantronfiles{'default'});
1.60 raeburn 4750: if ($error eq '') {
4751: $confhash{'scantron'}{'scantronformat'} = '';
4752: my $putresult =
4753: &Apache::lonnet::put_dom('configuration',
4754: \%confhash,$dom);
4755: if ($putresult ne 'ok') {
4756: $error{'default'} =
4757: '<span class="LC_error">'.
4758: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4759: }
4760: } else {
4761: $error{'default'} = $error;
4762: }
1.46 raeburn 4763: }
4764: }
4765: }
4766: } else {
1.95 www 4767: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4768: }
4769: }
4770: if (ref($settings) eq 'HASH') {
4771: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4772: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4773: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4774: $scantronurl = '';
4775: } else {
4776: $scantronurl = $settings->{'scantronformat'};
4777: }
4778: $is_custom = 1;
4779: } else {
4780: $scantronurl = $scantronurls{'default'};
4781: }
4782: } else {
1.60 raeburn 4783: if ($is_custom) {
4784: $scantronurl = $scantronurls{'custom'};
4785: } else {
4786: $scantronurl = $scantronurls{'default'};
4787: }
1.46 raeburn 4788: }
4789: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4790: $datatable .= '<tr'.$css_class.'>';
4791: if (!$is_custom) {
1.65 raeburn 4792: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4793: '<span class="LC_nobreak">';
1.46 raeburn 4794: if ($scantronurl) {
1.199 raeburn 4795: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4796: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4797: } else {
4798: $datatable = &mt('File unavailable for display');
4799: }
1.65 raeburn 4800: $datatable .= '</span></td>';
1.60 raeburn 4801: if (keys(%error) == 0) {
4802: $datatable .= '<td valign="bottom">';
4803: if (!$switchserver) {
4804: $datatable .= &mt('Upload:').'<br />';
4805: }
4806: } else {
4807: my $errorstr;
4808: foreach my $key (sort(keys(%error))) {
4809: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4810: }
4811: $datatable .= '<td>'.$errorstr;
4812: }
1.46 raeburn 4813: } else {
4814: if (keys(%error) > 0) {
4815: my $errorstr;
4816: foreach my $key (sort(keys(%error))) {
4817: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4818: }
1.60 raeburn 4819: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4820: } elsif ($scantronurl) {
1.199 raeburn 4821: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4822: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4823: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4824: $link.
4825: '<label><input type="checkbox" name="scantronformat_del"'.
4826: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4827: '<td><span class="LC_nobreak"> '.
4828: &mt('Replace:').'</span><br />';
1.46 raeburn 4829: }
4830: }
4831: if (keys(%error) == 0) {
4832: if ($switchserver) {
4833: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4834: } else {
1.65 raeburn 4835: $datatable .='<span class="LC_nobreak"> '.
4836: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4837: }
4838: }
4839: $datatable .= '</td></tr>';
4840: $$rowtotal ++;
4841: return $datatable;
4842: }
4843:
4844: sub legacy_scantronformat {
4845: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4846: my ($url,$error);
4847: my @statinfo = &Apache::lonnet::stat_file($newurl);
4848: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4849: (my $result,$url) =
4850: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4851: '','',$newfile);
4852: if ($result ne 'ok') {
1.130 raeburn 4853: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4854: }
4855: }
4856: return ($url,$error);
4857: }
1.43 raeburn 4858:
1.49 raeburn 4859: sub print_coursecategories {
1.57 raeburn 4860: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4861: my $datatable;
4862: if ($position eq 'top') {
1.238 raeburn 4863: my (%checked);
4864: my @catitems = ('unauth','auth');
4865: my @cattypes = ('std','domonly','codesrch','none');
4866: $checked{'unauth'} = 'std';
4867: $checked{'auth'} = 'std';
4868: if (ref($settings) eq 'HASH') {
4869: foreach my $type (@cattypes) {
4870: if ($type eq $settings->{'unauth'}) {
4871: $checked{'unauth'} = $type;
4872: }
4873: if ($type eq $settings->{'auth'}) {
4874: $checked{'auth'} = $type;
4875: }
4876: }
4877: }
4878: my %lt = &Apache::lonlocal::texthash (
4879: unauth => 'Catalog type for unauthenticated users',
4880: auth => 'Catalog type for authenticated users',
4881: none => 'No catalog',
4882: std => 'Standard catalog',
4883: domonly => 'Domain-only catalog',
4884: codesrch => "Code search form",
4885: );
4886: my $itemcount = 0;
4887: foreach my $item (@catitems) {
4888: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4889: $datatable .= '<tr '.$css_class.'>'.
4890: '<td>'.$lt{$item}.'</td>'.
4891: '<td class="LC_right_item"><span class="LC_nobreak">';
4892: foreach my $type (@cattypes) {
4893: my $ischecked;
4894: if ($checked{$item} eq $type) {
4895: $ischecked=' checked="checked"';
4896: }
4897: $datatable .= '<label>'.
4898: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4899: ' />'.$lt{$type}.'</label> ';
4900: }
4901: $datatable .= '</td></tr>';
4902: $itemcount ++;
4903: }
4904: $$rowtotal += $itemcount;
4905: } elsif ($position eq 'middle') {
1.57 raeburn 4906: my $toggle_cats_crs = ' ';
4907: my $toggle_cats_dom = ' checked="checked" ';
4908: my $can_cat_crs = ' ';
4909: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4910: my $toggle_catscomm_comm = ' ';
4911: my $toggle_catscomm_dom = ' checked="checked" ';
4912: my $can_catcomm_comm = ' ';
4913: my $can_catcomm_dom = ' checked="checked" ';
4914:
1.57 raeburn 4915: if (ref($settings) eq 'HASH') {
4916: if ($settings->{'togglecats'} eq 'crs') {
4917: $toggle_cats_crs = $toggle_cats_dom;
4918: $toggle_cats_dom = ' ';
4919: }
4920: if ($settings->{'categorize'} eq 'crs') {
4921: $can_cat_crs = $can_cat_dom;
4922: $can_cat_dom = ' ';
4923: }
1.120 raeburn 4924: if ($settings->{'togglecatscomm'} eq 'comm') {
4925: $toggle_catscomm_comm = $toggle_catscomm_dom;
4926: $toggle_catscomm_dom = ' ';
4927: }
4928: if ($settings->{'categorizecomm'} eq 'comm') {
4929: $can_catcomm_comm = $can_catcomm_dom;
4930: $can_catcomm_dom = ' ';
4931: }
1.57 raeburn 4932: }
4933: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4934: togglecats => 'Show/Hide a course in catalog',
4935: togglecatscomm => 'Show/Hide a community in catalog',
4936: categorize => 'Assign a category to a course',
4937: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4938: );
4939: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4940: dom => 'Set in Domain',
4941: crs => 'Set in Course',
4942: comm => 'Set in Community',
1.57 raeburn 4943: );
4944: $datatable = '<tr class="LC_odd_row">'.
4945: '<td>'.$title{'togglecats'}.'</td>'.
4946: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4947: '<input type="radio" name="togglecats"'.
4948: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4949: '<label><input type="radio" name="togglecats"'.
4950: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4951: '</tr><tr>'.
4952: '<td>'.$title{'categorize'}.'</td>'.
4953: '<td class="LC_right_item"><span class="LC_nobreak">'.
4954: '<label><input type="radio" name="categorize"'.
4955: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4956: '<label><input type="radio" name="categorize"'.
4957: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4958: '</tr><tr class="LC_odd_row">'.
4959: '<td>'.$title{'togglecatscomm'}.'</td>'.
4960: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4961: '<input type="radio" name="togglecatscomm"'.
4962: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4963: '<label><input type="radio" name="togglecatscomm"'.
4964: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4965: '</tr><tr>'.
4966: '<td>'.$title{'categorizecomm'}.'</td>'.
4967: '<td class="LC_right_item"><span class="LC_nobreak">'.
4968: '<label><input type="radio" name="categorizecomm"'.
4969: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4970: '<label><input type="radio" name="categorizecomm"'.
4971: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4972: '</tr>';
1.120 raeburn 4973: $$rowtotal += 4;
1.57 raeburn 4974: } else {
4975: my $css_class;
4976: my $itemcount = 1;
4977: my $cathash;
4978: if (ref($settings) eq 'HASH') {
4979: $cathash = $settings->{'cats'};
4980: }
4981: if (ref($cathash) eq 'HASH') {
4982: my (@cats,@trails,%allitems,%idx,@jsarray);
4983: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4984: \%allitems,\%idx,\@jsarray);
4985: my $maxdepth = scalar(@cats);
4986: my $colattrib = '';
4987: if ($maxdepth > 2) {
4988: $colattrib = ' colspan="2" ';
4989: }
4990: my @path;
4991: if (@cats > 0) {
4992: if (ref($cats[0]) eq 'ARRAY') {
4993: my $numtop = @{$cats[0]};
4994: my $maxnum = $numtop;
1.120 raeburn 4995: my %default_names = (
4996: instcode => &mt('Official courses'),
4997: communities => &mt('Communities'),
4998: );
4999:
5000: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5001: ($cathash->{'instcode::0'} eq '') ||
5002: (!grep(/^communities$/,@{$cats[0]})) ||
5003: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5004: $maxnum ++;
5005: }
5006: my $lastidx;
5007: for (my $i=0; $i<$numtop; $i++) {
5008: my $parent = $cats[0][$i];
5009: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5010: my $item = &escape($parent).'::0';
5011: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5012: $lastidx = $idx{$item};
5013: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5014: .'<select name="'.$item.'"'.$chgstr.'>';
5015: for (my $k=0; $k<=$maxnum; $k++) {
5016: my $vpos = $k+1;
5017: my $selstr;
5018: if ($k == $i) {
5019: $selstr = ' selected="selected" ';
5020: }
5021: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5022: }
1.214 raeburn 5023: $datatable .= '</select></span></td><td>';
1.120 raeburn 5024: if ($parent eq 'instcode' || $parent eq 'communities') {
5025: $datatable .= '<span class="LC_nobreak">'
5026: .$default_names{$parent}.'</span>';
5027: if ($parent eq 'instcode') {
5028: $datatable .= '<br /><span class="LC_nobreak">('
5029: .&mt('with institutional codes')
5030: .')</span></td><td'.$colattrib.'>';
5031: } else {
5032: $datatable .= '<table><tr><td>';
5033: }
5034: $datatable .= '<span class="LC_nobreak">'
5035: .'<label><input type="radio" name="'
5036: .$parent.'" value="1" checked="checked" />'
5037: .&mt('Display').'</label>';
5038: if ($parent eq 'instcode') {
5039: $datatable .= ' ';
5040: } else {
5041: $datatable .= '</span></td></tr><tr><td>'
5042: .'<span class="LC_nobreak">';
5043: }
5044: $datatable .= '<label><input type="radio" name="'
5045: .$parent.'" value="0" />'
5046: .&mt('Do not display').'</label></span>';
5047: if ($parent eq 'communities') {
5048: $datatable .= '</td></tr></table>';
5049: }
5050: $datatable .= '</td>';
1.57 raeburn 5051: } else {
5052: $datatable .= $parent
1.214 raeburn 5053: .' <span class="LC_nobreak"><label>'
5054: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5055: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5056: }
5057: my $depth = 1;
5058: push(@path,$parent);
5059: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5060: pop(@path);
5061: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5062: $itemcount ++;
5063: }
1.48 raeburn 5064: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5065: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5066: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5067: for (my $k=0; $k<=$maxnum; $k++) {
5068: my $vpos = $k+1;
5069: my $selstr;
1.57 raeburn 5070: if ($k == $numtop) {
1.48 raeburn 5071: $selstr = ' selected="selected" ';
5072: }
5073: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5074: }
1.59 bisitz 5075: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5076: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5077: .'</tr>'."\n";
1.48 raeburn 5078: $itemcount ++;
1.120 raeburn 5079: foreach my $default ('instcode','communities') {
5080: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5081: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5082: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5083: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5084: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5085: for (my $k=0; $k<=$maxnum; $k++) {
5086: my $vpos = $k+1;
5087: my $selstr;
5088: if ($k == $maxnum) {
5089: $selstr = ' selected="selected" ';
5090: }
5091: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5092: }
1.120 raeburn 5093: $datatable .= '</select></span></td>'.
5094: '<td><span class="LC_nobreak">'.
5095: $default_names{$default}.'</span>';
5096: if ($default eq 'instcode') {
5097: $datatable .= '<br /><span class="LC_nobreak">('
5098: .&mt('with institutional codes').')</span>';
5099: }
5100: $datatable .= '</td>'
5101: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5102: .&mt('Display').'</label> '
5103: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5104: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5105: }
5106: }
5107: }
1.57 raeburn 5108: } else {
5109: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5110: }
5111: } else {
1.238 raeburn 5112: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5113: .&initialize_categories($itemcount);
1.48 raeburn 5114: }
1.57 raeburn 5115: $$rowtotal += $itemcount;
1.48 raeburn 5116: }
5117: return $datatable;
5118: }
5119:
1.69 raeburn 5120: sub print_serverstatuses {
5121: my ($dom,$settings,$rowtotal) = @_;
5122: my $datatable;
5123: my @pages = &serverstatus_pages();
5124: my (%namedaccess,%machineaccess);
5125: foreach my $type (@pages) {
5126: $namedaccess{$type} = '';
5127: $machineaccess{$type}= '';
5128: }
5129: if (ref($settings) eq 'HASH') {
5130: foreach my $type (@pages) {
5131: if (exists($settings->{$type})) {
5132: if (ref($settings->{$type}) eq 'HASH') {
5133: foreach my $key (keys(%{$settings->{$type}})) {
5134: if ($key eq 'namedusers') {
5135: $namedaccess{$type} = $settings->{$type}->{$key};
5136: } elsif ($key eq 'machines') {
5137: $machineaccess{$type} = $settings->{$type}->{$key};
5138: }
5139: }
5140: }
5141: }
5142: }
5143: }
1.81 raeburn 5144: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5145: my $rownum = 0;
5146: my $css_class;
5147: foreach my $type (@pages) {
5148: $rownum ++;
5149: $css_class = $rownum%2?' class="LC_odd_row"':'';
5150: $datatable .= '<tr'.$css_class.'>'.
5151: '<td><span class="LC_nobreak">'.
5152: $titles->{$type}.'</span></td>'.
5153: '<td class="LC_left_item">'.
5154: '<input type="text" name="'.$type.'_namedusers" '.
5155: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5156: '<td class="LC_right_item">'.
5157: '<span class="LC_nobreak">'.
5158: '<input type="text" name="'.$type.'_machines" '.
5159: 'value="'.$machineaccess{$type}.'" size="10" />'.
5160: '</td></tr>'."\n";
5161: }
5162: $$rowtotal += $rownum;
5163: return $datatable;
5164: }
5165:
5166: sub serverstatus_pages {
5167: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5168: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5169: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5170: 'uniquecodes','diskusage');
1.69 raeburn 5171: }
5172:
1.236 raeburn 5173: sub defaults_javascript {
5174: my ($settings) = @_;
1.248 raeburn 5175: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5176: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5177: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5178: if ($maxnum eq '') {
5179: $maxnum = 0;
5180: }
5181: $maxnum ++;
1.249 raeburn 5182: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5183: return <<"ENDSCRIPT";
5184: <script type="text/javascript">
5185: // <![CDATA[
5186: function reorderTypes(form,caller) {
5187: var changedVal;
5188: $jstext
5189: var newpos = 'addinststatus_pos';
5190: var current = new Array;
5191: var maxh = $maxnum;
5192: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5193: var oldVal;
5194: if (caller == newpos) {
5195: changedVal = newitemVal;
5196: } else {
5197: var curritem = 'inststatus_pos_'+caller;
5198: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5199: current[newitemVal] = newpos;
5200: }
5201: for (var i=0; i<inststatuses.length; i++) {
5202: if (inststatuses[i] != caller) {
5203: var elementName = 'inststatus_pos_'+inststatuses[i];
5204: if (form.elements[elementName]) {
5205: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5206: current[currVal] = elementName;
5207: }
5208: }
5209: }
5210: for (var j=0; j<maxh; j++) {
5211: if (current[j] == undefined) {
5212: oldVal = j;
5213: }
5214: }
5215: if (oldVal < changedVal) {
5216: for (var k=oldVal+1; k<=changedVal ; k++) {
5217: var elementName = current[k];
5218: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5219: }
5220: } else {
5221: for (var k=changedVal; k<oldVal; k++) {
5222: var elementName = current[k];
5223: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5224: }
5225: }
5226: return;
5227: }
5228:
5229: // ]]>
5230: </script>
5231:
5232: ENDSCRIPT
5233: }
5234: }
5235:
1.49 raeburn 5236: sub coursecategories_javascript {
5237: my ($settings) = @_;
1.57 raeburn 5238: my ($output,$jstext,$cathash);
1.49 raeburn 5239: if (ref($settings) eq 'HASH') {
1.57 raeburn 5240: $cathash = $settings->{'cats'};
5241: }
5242: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5243: my (@cats,@jsarray,%idx);
1.57 raeburn 5244: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5245: if (@jsarray > 0) {
5246: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5247: for (my $i=0; $i<@jsarray; $i++) {
5248: if (ref($jsarray[$i]) eq 'ARRAY') {
5249: my $catstr = join('","',@{$jsarray[$i]});
5250: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5251: }
5252: }
5253: }
5254: } else {
5255: $jstext = ' var categories = Array(1);'."\n".
5256: ' categories[0] = Array("instcode_pos");'."\n";
5257: }
1.237 bisitz 5258: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5259: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5260: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5261: $output = <<"ENDSCRIPT";
5262: <script type="text/javascript">
1.109 raeburn 5263: // <![CDATA[
1.49 raeburn 5264: function reorderCats(form,parent,item,idx) {
5265: var changedVal;
5266: $jstext
5267: var newpos = 'addcategory_pos';
5268: if (parent == '') {
5269: var has_instcode = 0;
5270: var maxtop = categories[idx].length;
5271: for (var j=0; j<maxtop; j++) {
5272: if (categories[idx][j] == 'instcode::0') {
5273: has_instcode == 1;
5274: }
5275: }
5276: if (has_instcode == 0) {
5277: categories[idx][maxtop] = 'instcode_pos';
5278: }
5279: } else {
5280: newpos += '_'+parent;
5281: }
5282: var maxh = 1 + categories[idx].length;
5283: var current = new Array;
5284: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5285: if (item == newpos) {
5286: changedVal = newitemVal;
5287: } else {
5288: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5289: current[newitemVal] = newpos;
5290: }
5291: for (var i=0; i<categories[idx].length; i++) {
5292: var elementName = categories[idx][i];
5293: if (elementName != item) {
5294: if (form.elements[elementName]) {
5295: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5296: current[currVal] = elementName;
5297: }
5298: }
5299: }
5300: var oldVal;
5301: for (var j=0; j<maxh; j++) {
5302: if (current[j] == undefined) {
5303: oldVal = j;
5304: }
5305: }
5306: if (oldVal < changedVal) {
5307: for (var k=oldVal+1; k<=changedVal ; k++) {
5308: var elementName = current[k];
5309: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5310: }
5311: } else {
5312: for (var k=changedVal; k<oldVal; k++) {
5313: var elementName = current[k];
5314: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5315: }
5316: }
5317: return;
5318: }
1.120 raeburn 5319:
5320: function categoryCheck(form) {
5321: if (form.elements['addcategory_name'].value == 'instcode') {
5322: alert('$instcode_reserved\\n$choose_again');
5323: return false;
5324: }
5325: if (form.elements['addcategory_name'].value == 'communities') {
5326: alert('$communities_reserved\\n$choose_again');
5327: return false;
5328: }
5329: return true;
5330: }
5331:
1.109 raeburn 5332: // ]]>
1.49 raeburn 5333: </script>
5334:
5335: ENDSCRIPT
5336: return $output;
5337: }
5338:
1.48 raeburn 5339: sub initialize_categories {
5340: my ($itemcount) = @_;
1.120 raeburn 5341: my ($datatable,$css_class,$chgstr);
5342: my %default_names = (
5343: instcode => 'Official courses (with institutional codes)',
5344: communities => 'Communities',
5345: );
5346: my $select0 = ' selected="selected"';
5347: my $select1 = '';
5348: foreach my $default ('instcode','communities') {
5349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5350: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5351: if ($default eq 'communities') {
5352: $select1 = $select0;
5353: $select0 = '';
5354: }
5355: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5356: .'<select name="'.$default.'_pos">'
5357: .'<option value="0"'.$select0.'>1</option>'
5358: .'<option value="1"'.$select1.'>2</option>'
5359: .'<option value="2">3</option></select> '
5360: .$default_names{$default}
5361: .'</span></td><td><span class="LC_nobreak">'
5362: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5363: .&mt('Display').'</label> <label>'
5364: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5365: .'</label></span></td></tr>';
1.120 raeburn 5366: $itemcount ++;
5367: }
1.48 raeburn 5368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5369: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5370: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5371: .'<select name="addcategory_pos"'.$chgstr.'>'
5372: .'<option value="0">1</option>'
5373: .'<option value="1">2</option>'
5374: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5375: .&mt('Add category').'</td><td>'.&mt('Name:')
5376: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5377: return $datatable;
5378: }
5379:
5380: sub build_category_rows {
1.49 raeburn 5381: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5382: my ($text,$name,$item,$chgstr);
1.48 raeburn 5383: if (ref($cats) eq 'ARRAY') {
5384: my $maxdepth = scalar(@{$cats});
5385: if (ref($cats->[$depth]) eq 'HASH') {
5386: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5387: my $numchildren = @{$cats->[$depth]{$parent}};
5388: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5389: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5390: my ($idxnum,$parent_name,$parent_item);
5391: my $higher = $depth - 1;
5392: if ($higher == 0) {
5393: $parent_name = &escape($parent).'::'.$higher;
5394: } else {
5395: if (ref($path) eq 'ARRAY') {
5396: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5397: }
5398: }
5399: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5400: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5401: if ($j < $numchildren) {
1.48 raeburn 5402: $name = $cats->[$depth]{$parent}[$j];
5403: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5404: $idxnum = $idx->{$item};
5405: } else {
5406: $name = $parent_name;
5407: $item = $parent_item;
1.48 raeburn 5408: }
1.49 raeburn 5409: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5410: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5411: for (my $i=0; $i<=$numchildren; $i++) {
5412: my $vpos = $i+1;
5413: my $selstr;
5414: if ($j == $i) {
5415: $selstr = ' selected="selected" ';
5416: }
5417: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5418: }
5419: $text .= '</select> ';
5420: if ($j < $numchildren) {
5421: my $deeper = $depth+1;
5422: $text .= $name.' '
5423: .'<label><input type="checkbox" name="deletecategory" value="'
5424: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5425: if(ref($path) eq 'ARRAY') {
5426: push(@{$path},$name);
1.49 raeburn 5427: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5428: pop(@{$path});
5429: }
5430: } else {
1.59 bisitz 5431: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5432: if ($j == $numchildren) {
5433: $text .= $name;
5434: } else {
5435: $text .= $item;
5436: }
5437: $text .= '" value="" />';
5438: }
5439: $text .= '</td></tr>';
5440: }
5441: $text .= '</table></td>';
5442: } else {
5443: my $higher = $depth-1;
5444: if ($higher == 0) {
5445: $name = &escape($parent).'::'.$higher;
5446: } else {
5447: if (ref($path) eq 'ARRAY') {
5448: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5449: }
5450: }
5451: my $colspan;
5452: if ($parent ne 'instcode') {
5453: $colspan = $maxdepth - $depth - 1;
5454: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5455: }
5456: }
5457: }
5458: }
5459: return $text;
5460: }
5461:
1.33 raeburn 5462: sub modifiable_userdata_row {
1.228 raeburn 5463: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5464: my ($role,$rolename,$statustype);
5465: $role = $item;
1.224 raeburn 5466: if ($context eq 'cancreate') {
1.228 raeburn 5467: if ($item =~ /^emailusername_(.+)$/) {
5468: $statustype = $1;
5469: $role = 'emailusername';
5470: if (ref($usertypes) eq 'HASH') {
5471: if ($usertypes->{$statustype}) {
5472: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5473: } else {
5474: $rolename = &mt('Data provided by user');
5475: }
5476: }
1.224 raeburn 5477: }
5478: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5479: if (ref($usertypes) eq 'HASH') {
5480: $rolename = $usertypes->{$role};
5481: } else {
5482: $rolename = $role;
5483: }
1.33 raeburn 5484: } else {
1.63 raeburn 5485: if ($role eq 'cr') {
5486: $rolename = &mt('Custom role');
5487: } else {
5488: $rolename = &Apache::lonnet::plaintext($role);
5489: }
1.33 raeburn 5490: }
1.224 raeburn 5491: my (@fields,%fieldtitles);
5492: if (ref($fieldsref) eq 'ARRAY') {
5493: @fields = @{$fieldsref};
5494: } else {
5495: @fields = ('lastname','firstname','middlename','generation',
5496: 'permanentemail','id');
5497: }
5498: if ((ref($titlesref) eq 'HASH')) {
5499: %fieldtitles = %{$titlesref};
5500: } else {
5501: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5502: }
1.33 raeburn 5503: my $output;
5504: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5505: $output = '<tr '.$css_class.'>'.
5506: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5507: '<td class="LC_left_item" colspan="2"><table>';
5508: my $rem;
5509: my %checks;
5510: if (ref($settings) eq 'HASH') {
5511: if (ref($settings->{$context}) eq 'HASH') {
5512: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5513: my $hashref = $settings->{$context}->{$role};
5514: if ($role eq 'emailusername') {
5515: if ($statustype) {
5516: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5517: $hashref = $settings->{$context}->{$role}->{$statustype};
5518: if (ref($hashref) eq 'HASH') {
5519: foreach my $field (@fields) {
5520: if ($hashref->{$field}) {
5521: $checks{$field} = $hashref->{$field};
5522: }
5523: }
5524: }
5525: }
5526: }
5527: } else {
5528: if (ref($hashref) eq 'HASH') {
5529: foreach my $field (@fields) {
5530: if ($hashref->{$field}) {
5531: $checks{$field} = ' checked="checked" ';
5532: }
5533: }
1.33 raeburn 5534: }
5535: }
5536: }
5537: }
5538: }
1.228 raeburn 5539:
1.33 raeburn 5540: for (my $i=0; $i<@fields; $i++) {
5541: my $rem = $i%($numinrow);
5542: if ($rem == 0) {
5543: if ($i > 0) {
5544: $output .= '</tr>';
5545: }
5546: $output .= '<tr>';
5547: }
5548: my $check = ' ';
1.228 raeburn 5549: unless ($role eq 'emailusername') {
5550: if (exists($checks{$fields[$i]})) {
5551: $check = $checks{$fields[$i]}
5552: } else {
5553: if ($role eq 'st') {
5554: if (ref($settings) ne 'HASH') {
5555: $check = ' checked="checked" ';
5556: }
1.33 raeburn 5557: }
5558: }
5559: }
5560: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5561: '<span class="LC_nobreak">';
5562: if ($role eq 'emailusername') {
5563: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5564: $checks{$fields[$i]} = 'omit';
5565: }
5566: foreach my $option ('required','optional','omit') {
5567: my $checked='';
5568: if ($checks{$fields[$i]} eq $option) {
5569: $checked='checked="checked" ';
5570: }
5571: $output .= '<label>'.
5572: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5573: &mt($option).'</label>'.(' ' x2);
5574: }
5575: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5576: } else {
5577: $output .= '<label>'.
5578: '<input type="checkbox" name="canmodify_'.$role.'" '.
5579: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5580: '</label>';
5581: }
5582: $output .= '</span></td>';
1.33 raeburn 5583: $rem = @fields%($numinrow);
5584: }
5585: my $colsleft = $numinrow - $rem;
5586: if ($colsleft > 1 ) {
5587: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5588: ' </td>';
5589: } elsif ($colsleft == 1) {
5590: $output .= '<td class="LC_left_item"> </td>';
5591: }
5592: $output .= '</tr></table></td></tr>';
5593: return $output;
5594: }
1.28 raeburn 5595:
1.93 raeburn 5596: sub insttypes_row {
1.224 raeburn 5597: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5598: my %lt = &Apache::lonlocal::texthash (
5599: cansearch => 'Users allowed to search',
5600: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5601: lockablenames => 'User preference to lock name',
1.93 raeburn 5602: );
5603: my $showdom;
5604: if ($context eq 'cansearch') {
5605: $showdom = ' ('.$dom.')';
5606: }
1.165 raeburn 5607: my $class = 'LC_left_item';
5608: if ($context eq 'statustocreate') {
5609: $class = 'LC_right_item';
5610: }
1.224 raeburn 5611: my $css_class = ' class="LC_odd_row"';
5612: if ($rownum ne '') {
5613: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5614: }
5615: my $output = '<tr'.$css_class.'>'.
5616: '<td>'.$lt{$context}.$showdom.
5617: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5618: my $rem;
5619: if (ref($types) eq 'ARRAY') {
5620: for (my $i=0; $i<@{$types}; $i++) {
5621: if (defined($usertypes->{$types->[$i]})) {
5622: my $rem = $i%($numinrow);
5623: if ($rem == 0) {
5624: if ($i > 0) {
5625: $output .= '</tr>';
5626: }
5627: $output .= '<tr>';
1.23 raeburn 5628: }
1.26 raeburn 5629: my $check = ' ';
1.99 raeburn 5630: if (ref($settings) eq 'HASH') {
5631: if (ref($settings->{$context}) eq 'ARRAY') {
5632: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5633: $check = ' checked="checked" ';
5634: }
5635: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5636: $check = ' checked="checked" ';
5637: }
1.23 raeburn 5638: }
1.26 raeburn 5639: $output .= '<td class="LC_left_item">'.
5640: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5641: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5642: 'value="'.$types->[$i].'"'.$check.'/>'.
5643: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5644: }
5645: }
1.26 raeburn 5646: $rem = @{$types}%($numinrow);
1.23 raeburn 5647: }
5648: my $colsleft = $numinrow - $rem;
1.131 raeburn 5649: if (($rem == 0) && (@{$types} > 0)) {
5650: $output .= '<tr>';
5651: }
1.23 raeburn 5652: if ($colsleft > 1) {
1.25 raeburn 5653: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5654: } else {
1.25 raeburn 5655: $output .= '<td class="LC_left_item">';
1.23 raeburn 5656: }
5657: my $defcheck = ' ';
1.99 raeburn 5658: if (ref($settings) eq 'HASH') {
5659: if (ref($settings->{$context}) eq 'ARRAY') {
5660: if (grep(/^default$/,@{$settings->{$context}})) {
5661: $defcheck = ' checked="checked" ';
5662: }
5663: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5664: $defcheck = ' checked="checked" ';
5665: }
1.23 raeburn 5666: }
1.25 raeburn 5667: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5668: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5669: 'value="default"'.$defcheck.'/>'.
5670: $othertitle.'</label></span></td>'.
5671: '</tr></table></td></tr>';
5672: return $output;
1.23 raeburn 5673: }
5674:
5675: sub sorted_searchtitles {
5676: my %searchtitles = &Apache::lonlocal::texthash(
5677: 'uname' => 'username',
5678: 'lastname' => 'last name',
5679: 'lastfirst' => 'last name, first name',
5680: );
5681: my @titleorder = ('uname','lastname','lastfirst');
5682: return (\%searchtitles,\@titleorder);
5683: }
5684:
1.25 raeburn 5685: sub sorted_searchtypes {
5686: my %srchtypes_desc = (
5687: exact => 'is exact match',
5688: contains => 'contains ..',
5689: begins => 'begins with ..',
5690: );
5691: my @srchtypeorder = ('exact','begins','contains');
5692: return (\%srchtypes_desc,\@srchtypeorder);
5693: }
5694:
1.3 raeburn 5695: sub usertype_update_row {
5696: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5697: my $datatable;
5698: my $numinrow = 4;
5699: foreach my $type (@{$types}) {
5700: if (defined($usertypes->{$type})) {
5701: $$rownums ++;
5702: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5703: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5704: '</td><td class="LC_left_item"><table>';
5705: for (my $i=0; $i<@{$fields}; $i++) {
5706: my $rem = $i%($numinrow);
5707: if ($rem == 0) {
5708: if ($i > 0) {
5709: $datatable .= '</tr>';
5710: }
5711: $datatable .= '<tr>';
5712: }
5713: my $check = ' ';
1.39 raeburn 5714: if (ref($settings) eq 'HASH') {
5715: if (ref($settings->{'fields'}) eq 'HASH') {
5716: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5717: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5718: $check = ' checked="checked" ';
5719: }
1.3 raeburn 5720: }
5721: }
5722: }
5723:
5724: if ($i == @{$fields}-1) {
5725: my $colsleft = $numinrow - $rem;
5726: if ($colsleft > 1) {
5727: $datatable .= '<td colspan="'.$colsleft.'">';
5728: } else {
5729: $datatable .= '<td>';
5730: }
5731: } else {
5732: $datatable .= '<td>';
5733: }
1.8 raeburn 5734: $datatable .= '<span class="LC_nobreak"><label>'.
5735: '<input type="checkbox" name="updateable_'.$type.
5736: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5737: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5738: }
5739: $datatable .= '</tr></table></td></tr>';
5740: }
5741: }
5742: return $datatable;
1.1 raeburn 5743: }
5744:
5745: sub modify_login {
1.205 raeburn 5746: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5747: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5748: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5749: %title = ( coursecatalog => 'Display course catalog',
5750: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5751: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5752: newuser => 'Link for visitors to create a user account',
5753: loginheader => 'Log-in box header');
5754: @offon = ('off','on');
1.112 raeburn 5755: if (ref($domconfig{login}) eq 'HASH') {
5756: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5757: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5758: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5759: }
5760: }
5761: }
1.9 raeburn 5762: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5763: \%domconfig,\%loginhash);
1.188 raeburn 5764: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5765: foreach my $item (@toggles) {
5766: $loginhash{login}{$item} = $env{'form.'.$item};
5767: }
1.41 raeburn 5768: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5769: if (ref($colchanges{'login'}) eq 'HASH') {
5770: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5771: \%loginhash);
5772: }
1.110 raeburn 5773:
1.149 raeburn 5774: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5775: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5776: if (keys(%servers) > 1) {
5777: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5778: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5779: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5780: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5781: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5782: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5783: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5784: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5785: $changes{'loginvia'}{$lonhost} = 1;
5786: } else {
5787: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5788: $changes{'loginvia'}{$lonhost} = 1;
5789: }
5790: } else {
5791: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5792: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5793: $changes{'loginvia'}{$lonhost} = 1;
5794: }
5795: }
5796: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5797: foreach my $item (@loginvia_attribs) {
5798: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5799: }
5800: } else {
5801: foreach my $item (@loginvia_attribs) {
5802: my $new = $env{'form.'.$lonhost.'_'.$item};
5803: if (($item eq 'serverpath') && ($new eq 'custom')) {
5804: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5805: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5806: $new = '/';
5807: }
5808: }
5809: if (($item eq 'custompath') &&
5810: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5811: $new = '';
5812: }
5813: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5814: $changes{'loginvia'}{$lonhost} = 1;
5815: }
5816: if ($item eq 'exempt') {
5817: $new =~ s/^\s+//;
5818: $new =~ s/\s+$//;
5819: my @poss_ips = split(/\s*[,:]\s*/,$new);
5820: my @okips;
5821: foreach my $ip (@poss_ips) {
5822: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5823: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5824: push(@okips,$ip);
5825: }
5826: }
5827: }
5828: if (@okips > 0) {
5829: $new = join(',',@okips);
5830: } else {
5831: $new = '';
5832: }
5833: }
5834: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5835: }
5836: }
1.112 raeburn 5837: } else {
1.128 raeburn 5838: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5839: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5840: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5841: foreach my $item (@loginvia_attribs) {
5842: my $new = $env{'form.'.$lonhost.'_'.$item};
5843: if (($item eq 'serverpath') && ($new eq 'custom')) {
5844: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5845: $new = '/';
5846: }
5847: }
5848: if (($item eq 'custompath') &&
5849: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5850: $new = '';
5851: }
5852: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5853: }
1.110 raeburn 5854: }
5855: }
5856: }
5857: }
1.119 raeburn 5858:
1.168 raeburn 5859: my $servadm = $r->dir_config('lonAdmEMail');
5860: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5861: if (ref($domconfig{'login'}) eq 'HASH') {
5862: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5863: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5864: if ($lang eq 'nolang') {
5865: push(@currlangs,$lang);
5866: } elsif (defined($langchoices{$lang})) {
5867: push(@currlangs,$lang);
5868: } else {
5869: next;
5870: }
5871: }
5872: }
5873: }
5874: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5875: if (@currlangs > 0) {
5876: foreach my $lang (@currlangs) {
5877: if (grep(/^\Q$lang\E$/,@delurls)) {
5878: $changes{'helpurl'}{$lang} = 1;
5879: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5880: $changes{'helpurl'}{$lang} = 1;
5881: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5882: push(@newlangs,$lang);
5883: } else {
5884: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5885: }
5886: }
5887: }
5888: unless (grep(/^nolang$/,@currlangs)) {
5889: if ($env{'form.loginhelpurl_nolang.filename'}) {
5890: $changes{'helpurl'}{'nolang'} = 1;
5891: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5892: push(@newlangs,'nolang');
5893: }
5894: }
5895: if ($env{'form.loginhelpurl_add_lang'}) {
5896: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5897: ($env{'form.loginhelpurl_add_file.filename'})) {
5898: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5899: $addedfile = $env{'form.loginhelpurl_add_lang'};
5900: }
5901: }
5902: if ((@newlangs > 0) || ($addedfile)) {
5903: my $error;
5904: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5905: if ($configuserok eq 'ok') {
5906: if ($switchserver) {
5907: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5908: } elsif ($author_ok eq 'ok') {
5909: my @allnew = @newlangs;
5910: if ($addedfile ne '') {
5911: push(@allnew,$addedfile);
5912: }
5913: foreach my $lang (@allnew) {
5914: my $formelem = 'loginhelpurl_'.$lang;
5915: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5916: $formelem = 'loginhelpurl_add_file';
5917: }
5918: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5919: "help/$lang",'','',$newfile{$lang});
5920: if ($result eq 'ok') {
5921: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5922: $changes{'helpurl'}{$lang} = 1;
5923: } else {
5924: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5925: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5926: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5927: (!grep(/^\Q$lang\E$/,@delurls))) {
5928:
5929: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5930: }
5931: }
5932: }
5933: } else {
5934: $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);
5935: }
5936: } else {
5937: $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);
5938: }
5939: if ($error) {
5940: &Apache::lonnet::logthis($error);
5941: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5942: }
5943: }
1.169 raeburn 5944: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5945:
5946: my $defaulthelpfile = '/adm/loginproblems.html';
5947: my $defaulttext = &mt('Default in use');
5948:
1.1 raeburn 5949: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5950: $dom);
5951: if ($putresult eq 'ok') {
1.188 raeburn 5952: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5953: my %defaultchecked = (
5954: 'coursecatalog' => 'on',
1.188 raeburn 5955: 'helpdesk' => 'on',
1.42 raeburn 5956: 'adminmail' => 'off',
1.43 raeburn 5957: 'newuser' => 'off',
1.42 raeburn 5958: );
1.55 raeburn 5959: if (ref($domconfig{'login'}) eq 'HASH') {
5960: foreach my $item (@toggles) {
5961: if ($defaultchecked{$item} eq 'on') {
5962: if (($domconfig{'login'}{$item} eq '0') &&
5963: ($env{'form.'.$item} eq '1')) {
5964: $changes{$item} = 1;
5965: } elsif (($domconfig{'login'}{$item} eq '' ||
5966: $domconfig{'login'}{$item} eq '1') &&
5967: ($env{'form.'.$item} eq '0')) {
5968: $changes{$item} = 1;
5969: }
5970: } elsif ($defaultchecked{$item} eq 'off') {
5971: if (($domconfig{'login'}{$item} eq '1') &&
5972: ($env{'form.'.$item} eq '0')) {
5973: $changes{$item} = 1;
5974: } elsif (($domconfig{'login'}{$item} eq '' ||
5975: $domconfig{'login'}{$item} eq '0') &&
5976: ($env{'form.'.$item} eq '1')) {
5977: $changes{$item} = 1;
5978: }
1.42 raeburn 5979: }
5980: }
1.41 raeburn 5981: }
1.6 raeburn 5982: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5983: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5984: if (ref($lastactref) eq 'HASH') {
5985: $lastactref->{'domainconfig'} = 1;
5986: }
1.1 raeburn 5987: $resulttext = &mt('Changes made:').'<ul>';
5988: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5989: if ($item eq 'loginvia') {
1.112 raeburn 5990: if (ref($changes{$item}) eq 'HASH') {
5991: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5992: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5993: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5994: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5995: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5996: $protocol = 'http' if ($protocol ne 'https');
5997: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5998:
5999: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6000: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6001: } else {
6002: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6003: }
6004: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6005: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6006: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6007: }
6008: $resulttext .= '</li>';
6009: } else {
6010: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6011: }
1.112 raeburn 6012: } else {
1.128 raeburn 6013: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6014: }
6015: }
1.128 raeburn 6016: $resulttext .= '</ul></li>';
1.112 raeburn 6017: }
1.168 raeburn 6018: } elsif ($item eq 'helpurl') {
6019: if (ref($changes{$item}) eq 'HASH') {
6020: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6021: if (grep(/^\Q$lang\E$/,@delurls)) {
6022: my ($chg,$link);
6023: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6024: if ($lang eq 'nolang') {
6025: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6026: } else {
6027: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6028: }
6029: $resulttext .= '<li>'.$chg.'</li>';
6030: } else {
6031: my $chg;
6032: if ($lang eq 'nolang') {
6033: $chg = &mt('custom log-in help file for no preferred language');
6034: } else {
6035: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6036: }
6037: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6038: $loginhash{'login'}{'helpurl'}{$lang}.
6039: '?inhibitmenu=yes',$chg,600,500).
6040: '</li>';
6041: }
6042: }
6043: }
1.169 raeburn 6044: } elsif ($item eq 'captcha') {
6045: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6046: my $chgtxt;
1.169 raeburn 6047: if ($loginhash{'login'}{$item} eq 'notused') {
6048: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6049: } else {
6050: my %captchas = &captcha_phrases();
6051: if ($captchas{$loginhash{'login'}{$item}}) {
6052: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6053: } else {
6054: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6055: }
6056: }
6057: $resulttext .= '<li>'.$chgtxt.'</li>';
6058: }
6059: } elsif ($item eq 'recaptchakeys') {
6060: if (ref($loginhash{'login'}) eq 'HASH') {
6061: my ($privkey,$pubkey);
6062: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6063: $pubkey = $loginhash{'login'}{$item}{'public'};
6064: $privkey = $loginhash{'login'}{$item}{'private'};
6065: }
6066: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6067: if (!$pubkey) {
6068: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6069: } else {
6070: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6071: }
6072: if (!$privkey) {
6073: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6074: } else {
1.251 raeburn 6075: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6076: }
6077: $chgtxt .= '</ul>';
6078: $resulttext .= '<li>'.$chgtxt.'</li>';
6079: }
1.41 raeburn 6080: } else {
6081: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6082: }
1.1 raeburn 6083: }
1.6 raeburn 6084: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6085: } else {
6086: $resulttext = &mt('No changes made to log-in page settings');
6087: }
6088: } else {
1.11 albertel 6089: $resulttext = '<span class="LC_error">'.
6090: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6091: }
1.6 raeburn 6092: if ($errors) {
1.9 raeburn 6093: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6094: $errors.'</ul>';
6095: }
6096: return $resulttext;
6097: }
6098:
6099: sub color_font_choices {
6100: my %choices =
6101: &Apache::lonlocal::texthash (
6102: img => "Header",
6103: bgs => "Background colors",
6104: links => "Link colors",
1.55 raeburn 6105: images => "Images",
1.6 raeburn 6106: font => "Font color",
1.201 raeburn 6107: fontmenu => "Font menu",
1.76 raeburn 6108: pgbg => "Page",
1.6 raeburn 6109: tabbg => "Header",
6110: sidebg => "Border",
6111: link => "Link",
6112: alink => "Active link",
6113: vlink => "Visited link",
6114: );
6115: return %choices;
6116: }
6117:
6118: sub modify_rolecolors {
1.205 raeburn 6119: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6120: my ($resulttext,%rolehash);
6121: $rolehash{'rolecolors'} = {};
1.55 raeburn 6122: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6123: if ($domconfig{'rolecolors'} eq '') {
6124: $domconfig{'rolecolors'} = {};
6125: }
6126: }
1.9 raeburn 6127: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6128: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6129: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6130: $dom);
6131: if ($putresult eq 'ok') {
6132: if (keys(%changes) > 0) {
1.41 raeburn 6133: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6134: if (ref($lastactref) eq 'HASH') {
6135: $lastactref->{'domainconfig'} = 1;
6136: }
1.6 raeburn 6137: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6138: $rolehash{'rolecolors'});
6139: } else {
6140: $resulttext = &mt('No changes made to default color schemes');
6141: }
6142: } else {
1.11 albertel 6143: $resulttext = '<span class="LC_error">'.
6144: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6145: }
6146: if ($errors) {
6147: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6148: $errors.'</ul>';
6149: }
6150: return $resulttext;
6151: }
6152:
6153: sub modify_colors {
1.9 raeburn 6154: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6155: my (%changes,%choices);
1.51 raeburn 6156: my @bgs;
1.6 raeburn 6157: my @links = ('link','alink','vlink');
1.41 raeburn 6158: my @logintext;
1.6 raeburn 6159: my @images;
6160: my $servadm = $r->dir_config('lonAdmEMail');
6161: my $errors;
1.200 raeburn 6162: my %defaults;
1.6 raeburn 6163: foreach my $role (@{$roles}) {
6164: if ($role eq 'login') {
1.12 raeburn 6165: %choices = &login_choices();
1.41 raeburn 6166: @logintext = ('textcol','bgcol');
1.12 raeburn 6167: } else {
6168: %choices = &color_font_choices();
6169: }
6170: if ($role eq 'login') {
1.41 raeburn 6171: @images = ('img','logo','domlogo','login');
1.51 raeburn 6172: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6173: } else {
6174: @images = ('img');
1.200 raeburn 6175: @bgs = ('pgbg','tabbg','sidebg');
6176: }
6177: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6178: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6179: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6180: }
6181: if ($role eq 'login') {
6182: foreach my $item (@logintext) {
1.234 raeburn 6183: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6184: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6185: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6186: }
6187: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6188: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6189: }
6190: }
6191: } else {
1.234 raeburn 6192: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6193: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6194: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6195: }
6196: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6197: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6198: }
1.6 raeburn 6199: }
1.200 raeburn 6200: foreach my $item (@bgs) {
1.234 raeburn 6201: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6202: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6203: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6204: }
6205: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6206: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6207: }
6208: }
6209: foreach my $item (@links) {
1.234 raeburn 6210: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6211: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6212: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6213: }
6214: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6215: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6216: }
1.6 raeburn 6217: }
1.46 raeburn 6218: my ($configuserok,$author_ok,$switchserver) =
6219: &config_check($dom,$confname,$servadm);
1.9 raeburn 6220: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6221: if (ref($domconfig->{$role}) ne 'HASH') {
6222: $domconfig->{$role} = {};
6223: }
1.8 raeburn 6224: foreach my $img (@images) {
1.70 raeburn 6225: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6226: if (defined($env{'form.login_showlogo_'.$img})) {
6227: $confhash->{$role}{'showlogo'}{$img} = 1;
6228: } else {
6229: $confhash->{$role}{'showlogo'}{$img} = 0;
6230: }
6231: }
1.18 albertel 6232: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6233: && !defined($domconfig->{$role}{$img})
6234: && !$env{'form.'.$role.'_del_'.$img}
6235: && $env{'form.'.$role.'_import_'.$img}) {
6236: # import the old configured image from the .tab setting
6237: # if they haven't provided a new one
6238: $domconfig->{$role}{$img} =
6239: $env{'form.'.$role.'_import_'.$img};
6240: }
1.6 raeburn 6241: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6242: my $error;
1.6 raeburn 6243: if ($configuserok eq 'ok') {
1.9 raeburn 6244: if ($switchserver) {
1.12 raeburn 6245: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6246: } else {
6247: if ($author_ok eq 'ok') {
6248: my ($result,$logourl) =
6249: &publishlogo($r,'upload',$role.'_'.$img,
6250: $dom,$confname,$img,$width,$height);
6251: if ($result eq 'ok') {
6252: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6253: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6254: } else {
1.12 raeburn 6255: $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 6256: }
6257: } else {
1.46 raeburn 6258: $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 6259: }
6260: }
6261: } else {
1.46 raeburn 6262: $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 6263: }
6264: if ($error) {
1.8 raeburn 6265: &Apache::lonnet::logthis($error);
1.11 albertel 6266: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6267: }
6268: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6269: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6270: my $error;
6271: if ($configuserok eq 'ok') {
6272: # is confname an author?
6273: if ($switchserver eq '') {
6274: if ($author_ok eq 'ok') {
6275: my ($result,$logourl) =
6276: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6277: $dom,$confname,$img,$width,$height);
6278: if ($result eq 'ok') {
6279: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6280: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6281: }
6282: }
6283: }
6284: }
1.6 raeburn 6285: }
6286: }
6287: }
6288: if (ref($domconfig) eq 'HASH') {
6289: if (ref($domconfig->{$role}) eq 'HASH') {
6290: foreach my $img (@images) {
6291: if ($domconfig->{$role}{$img} ne '') {
6292: if ($env{'form.'.$role.'_del_'.$img}) {
6293: $confhash->{$role}{$img} = '';
1.12 raeburn 6294: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6295: } else {
1.9 raeburn 6296: if ($confhash->{$role}{$img} eq '') {
6297: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6298: }
1.6 raeburn 6299: }
6300: } else {
6301: if ($env{'form.'.$role.'_del_'.$img}) {
6302: $confhash->{$role}{$img} = '';
1.12 raeburn 6303: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6304: }
6305: }
1.70 raeburn 6306: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6307: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6308: if ($confhash->{$role}{'showlogo'}{$img} ne
6309: $domconfig->{$role}{'showlogo'}{$img}) {
6310: $changes{$role}{'showlogo'}{$img} = 1;
6311: }
6312: } else {
6313: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6314: $changes{$role}{'showlogo'}{$img} = 1;
6315: }
6316: }
6317: }
6318: }
1.6 raeburn 6319: if ($domconfig->{$role}{'font'} ne '') {
6320: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6321: $changes{$role}{'font'} = 1;
6322: }
6323: } else {
6324: if ($confhash->{$role}{'font'}) {
6325: $changes{$role}{'font'} = 1;
6326: }
6327: }
1.107 raeburn 6328: if ($role ne 'login') {
6329: if ($domconfig->{$role}{'fontmenu'} ne '') {
6330: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6331: $changes{$role}{'fontmenu'} = 1;
6332: }
6333: } else {
6334: if ($confhash->{$role}{'fontmenu'}) {
6335: $changes{$role}{'fontmenu'} = 1;
6336: }
1.97 tempelho 6337: }
6338: }
1.6 raeburn 6339: foreach my $item (@bgs) {
6340: if ($domconfig->{$role}{$item} ne '') {
6341: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6342: $changes{$role}{'bgs'}{$item} = 1;
6343: }
6344: } else {
6345: if ($confhash->{$role}{$item}) {
6346: $changes{$role}{'bgs'}{$item} = 1;
6347: }
6348: }
6349: }
6350: foreach my $item (@links) {
6351: if ($domconfig->{$role}{$item} ne '') {
6352: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6353: $changes{$role}{'links'}{$item} = 1;
6354: }
6355: } else {
6356: if ($confhash->{$role}{$item}) {
6357: $changes{$role}{'links'}{$item} = 1;
6358: }
6359: }
6360: }
1.41 raeburn 6361: foreach my $item (@logintext) {
6362: if ($domconfig->{$role}{$item} ne '') {
6363: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6364: $changes{$role}{'logintext'}{$item} = 1;
6365: }
6366: } else {
6367: if ($confhash->{$role}{$item}) {
6368: $changes{$role}{'logintext'}{$item} = 1;
6369: }
6370: }
6371: }
1.6 raeburn 6372: } else {
6373: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6374: \@logintext,$confhash,\%changes);
1.6 raeburn 6375: }
6376: } else {
6377: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6378: \@logintext,$confhash,\%changes);
1.6 raeburn 6379: }
6380: }
6381: return ($errors,%changes);
6382: }
6383:
1.46 raeburn 6384: sub config_check {
6385: my ($dom,$confname,$servadm) = @_;
6386: my ($configuserok,$author_ok,$switchserver,%currroles);
6387: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6388: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6389: $confname,$servadm);
6390: if ($configuserok eq 'ok') {
6391: $switchserver = &check_switchserver($dom,$confname);
6392: if ($switchserver eq '') {
6393: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6394: }
6395: }
6396: return ($configuserok,$author_ok,$switchserver);
6397: }
6398:
1.6 raeburn 6399: sub default_change_checker {
1.41 raeburn 6400: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6401: foreach my $item (@{$links}) {
6402: if ($confhash->{$role}{$item}) {
6403: $changes->{$role}{'links'}{$item} = 1;
6404: }
6405: }
6406: foreach my $item (@{$bgs}) {
6407: if ($confhash->{$role}{$item}) {
6408: $changes->{$role}{'bgs'}{$item} = 1;
6409: }
6410: }
1.41 raeburn 6411: foreach my $item (@{$logintext}) {
6412: if ($confhash->{$role}{$item}) {
6413: $changes->{$role}{'logintext'}{$item} = 1;
6414: }
6415: }
1.6 raeburn 6416: foreach my $img (@{$images}) {
6417: if ($env{'form.'.$role.'_del_'.$img}) {
6418: $confhash->{$role}{$img} = '';
1.12 raeburn 6419: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6420: }
1.70 raeburn 6421: if ($role eq 'login') {
6422: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6423: $changes->{$role}{'showlogo'}{$img} = 1;
6424: }
6425: }
1.6 raeburn 6426: }
6427: if ($confhash->{$role}{'font'}) {
6428: $changes->{$role}{'font'} = 1;
6429: }
1.48 raeburn 6430: }
1.6 raeburn 6431:
6432: sub display_colorchgs {
6433: my ($dom,$changes,$roles,$confhash) = @_;
6434: my (%choices,$resulttext);
6435: if (!grep(/^login$/,@{$roles})) {
6436: $resulttext = &mt('Changes made:').'<br />';
6437: }
6438: foreach my $role (@{$roles}) {
6439: if ($role eq 'login') {
6440: %choices = &login_choices();
6441: } else {
6442: %choices = &color_font_choices();
6443: }
6444: if (ref($changes->{$role}) eq 'HASH') {
6445: if ($role ne 'login') {
6446: $resulttext .= '<h4>'.&mt($role).'</h4>';
6447: }
6448: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6449: if ($role ne 'login') {
6450: $resulttext .= '<ul>';
6451: }
6452: if (ref($changes->{$role}{$key}) eq 'HASH') {
6453: if ($role ne 'login') {
6454: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6455: }
6456: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6457: if (($role eq 'login') && ($key eq 'showlogo')) {
6458: if ($confhash->{$role}{$key}{$item}) {
6459: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6460: } else {
6461: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6462: }
6463: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6464: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6465: } else {
1.12 raeburn 6466: my $newitem = $confhash->{$role}{$item};
6467: if ($key eq 'images') {
6468: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6469: }
6470: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6471: }
6472: }
6473: if ($role ne 'login') {
6474: $resulttext .= '</ul></li>';
6475: }
6476: } else {
6477: if ($confhash->{$role}{$key} eq '') {
6478: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6479: } else {
6480: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6481: }
6482: }
6483: if ($role ne 'login') {
6484: $resulttext .= '</ul>';
6485: }
6486: }
6487: }
6488: }
1.3 raeburn 6489: return $resulttext;
1.1 raeburn 6490: }
6491:
1.9 raeburn 6492: sub thumb_dimensions {
6493: return ('200','50');
6494: }
6495:
1.16 raeburn 6496: sub check_dimensions {
6497: my ($inputfile) = @_;
6498: my ($fullwidth,$fullheight);
6499: if ($inputfile =~ m|^[/\w.\-]+$|) {
6500: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6501: my $imageinfo = <PIPE>;
6502: if (!close(PIPE)) {
6503: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6504: }
6505: chomp($imageinfo);
6506: my ($fullsize) =
1.21 raeburn 6507: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6508: if ($fullsize) {
6509: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6510: }
6511: }
6512: }
6513: return ($fullwidth,$fullheight);
6514: }
6515:
1.9 raeburn 6516: sub check_configuser {
6517: my ($uhome,$dom,$confname,$servadm) = @_;
6518: my ($configuserok,%currroles);
6519: if ($uhome eq 'no_host') {
6520: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6521: my $configpass = &LONCAPA::Enrollment::create_password();
6522: $configuserok =
6523: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6524: $configpass,'','','','','',undef,$servadm);
6525: } else {
6526: $configuserok = 'ok';
6527: %currroles =
6528: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6529: }
6530: return ($configuserok,%currroles);
6531: }
6532:
6533: sub check_authorstatus {
6534: my ($dom,$confname,%currroles) = @_;
6535: my $author_ok;
1.40 raeburn 6536: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6537: my $start = time;
6538: my $end = 0;
6539: $author_ok =
6540: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6541: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6542: } else {
6543: $author_ok = 'ok';
6544: }
6545: return $author_ok;
6546: }
6547:
6548: sub publishlogo {
1.46 raeburn 6549: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6550: my ($output,$fname,$logourl);
6551: if ($action eq 'upload') {
6552: $fname=$env{'form.'.$formname.'.filename'};
6553: chop($env{'form.'.$formname});
6554: } else {
6555: ($fname) = ($formname =~ /([^\/]+)$/);
6556: }
1.46 raeburn 6557: if ($savefileas ne '') {
6558: $fname = $savefileas;
6559: }
1.9 raeburn 6560: $fname=&Apache::lonnet::clean_filename($fname);
6561: # See if there is anything left
6562: unless ($fname) { return ('error: no uploaded file'); }
6563: $fname="$subdir/$fname";
1.210 raeburn 6564: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6565: my $filepath="$docroot/priv";
6566: my $relpath = "$dom/$confname";
1.9 raeburn 6567: my ($fnamepath,$file,$fetchthumb);
6568: $file=$fname;
6569: if ($fname=~m|/|) {
6570: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6571: }
1.164 raeburn 6572: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6573: my $count;
1.164 raeburn 6574: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6575: $filepath.="/$parts[$count]";
6576: if ((-e $filepath)!=1) {
6577: mkdir($filepath,02770);
6578: }
6579: }
6580: # Check for bad extension and disallow upload
6581: if ($file=~/\.(\w+)$/ &&
6582: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6583: $output =
1.207 bisitz 6584: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6585: } elsif ($file=~/\.(\w+)$/ &&
6586: !defined(&Apache::loncommon::fileembstyle($1))) {
6587: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6588: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6589: $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 6590: } elsif (-d "$filepath/$file") {
1.195 bisitz 6591: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6592: } else {
6593: my $source = $filepath.'/'.$file;
6594: my $logfile;
6595: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6596: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6597: }
6598: print $logfile
6599: "\n================= Publish ".localtime()." ================\n".
6600: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6601: # Save the file
6602: if (!open(FH,'>'.$source)) {
6603: &Apache::lonnet::logthis('Failed to create '.$source);
6604: return (&mt('Failed to create file'));
6605: }
6606: if ($action eq 'upload') {
6607: if (!print FH ($env{'form.'.$formname})) {
6608: &Apache::lonnet::logthis('Failed to write to '.$source);
6609: return (&mt('Failed to write file'));
6610: }
6611: } else {
6612: my $original = &Apache::lonnet::filelocation('',$formname);
6613: if(!copy($original,$source)) {
6614: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6615: return (&mt('Failed to write file'));
6616: }
6617: }
6618: close(FH);
6619: chmod(0660, $source); # Permissions to rw-rw---.
6620:
6621: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6622: my $copyfile=$targetdir.'/'.$file;
6623:
6624: my @parts=split(/\//,$targetdir);
6625: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6626: for (my $count=5;$count<=$#parts;$count++) {
6627: $path.="/$parts[$count]";
6628: if (!-e $path) {
6629: print $logfile "\nCreating directory ".$path;
6630: mkdir($path,02770);
6631: }
6632: }
6633: my $versionresult;
6634: if (-e $copyfile) {
6635: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6636: } else {
6637: $versionresult = 'ok';
6638: }
6639: if ($versionresult eq 'ok') {
6640: if (copy($source,$copyfile)) {
6641: print $logfile "\nCopied original source to ".$copyfile."\n";
6642: $output = 'ok';
6643: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6644: push(@{$modified_urls},[$copyfile,$source]);
6645: my $metaoutput =
6646: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6647: unless ($registered_cleanup) {
6648: my $handlers = $r->get_handlers('PerlCleanupHandler');
6649: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6650: $registered_cleanup=1;
6651: }
1.9 raeburn 6652: } else {
6653: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6654: $output = &mt('Failed to copy file to RES space').", $!";
6655: }
6656: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6657: my $inputfile = $filepath.'/'.$file;
6658: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6659: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6660: if ($fullwidth ne '' && $fullheight ne '') {
6661: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6662: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6663: system("convert -sample $thumbsize $inputfile $outfile");
6664: chmod(0660, $filepath.'/tn-'.$file);
6665: if (-e $outfile) {
6666: my $copyfile=$targetdir.'/tn-'.$file;
6667: if (copy($outfile,$copyfile)) {
6668: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6669: my $thumb_metaoutput =
6670: &write_metadata($dom,$confname,$formname,
6671: $targetdir,'tn-'.$file,$logfile);
6672: push(@{$modified_urls},[$copyfile,$outfile]);
6673: unless ($registered_cleanup) {
6674: my $handlers = $r->get_handlers('PerlCleanupHandler');
6675: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6676: $registered_cleanup=1;
6677: }
1.16 raeburn 6678: } else {
6679: print $logfile "\nUnable to write ".$copyfile.
6680: ':'.$!."\n";
6681: }
6682: }
1.9 raeburn 6683: }
6684: }
6685: }
6686: } else {
6687: $output = $versionresult;
6688: }
6689: }
6690: return ($output,$logourl);
6691: }
6692:
6693: sub logo_versioning {
6694: my ($targetdir,$file,$logfile) = @_;
6695: my $target = $targetdir.'/'.$file;
6696: my ($maxversion,$fn,$extn,$output);
6697: $maxversion = 0;
6698: if ($file =~ /^(.+)\.(\w+)$/) {
6699: $fn=$1;
6700: $extn=$2;
6701: }
6702: opendir(DIR,$targetdir);
6703: while (my $filename=readdir(DIR)) {
6704: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6705: $maxversion=($1>$maxversion)?$1:$maxversion;
6706: }
6707: }
6708: $maxversion++;
6709: print $logfile "\nCreating old version ".$maxversion."\n";
6710: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6711: if (copy($target,$copyfile)) {
6712: print $logfile "Copied old target to ".$copyfile."\n";
6713: $copyfile=$copyfile.'.meta';
6714: if (copy($target.'.meta',$copyfile)) {
6715: print $logfile "Copied old target metadata to ".$copyfile."\n";
6716: $output = 'ok';
6717: } else {
6718: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6719: $output = &mt('Failed to copy old meta').", $!, ";
6720: }
6721: } else {
6722: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6723: $output = &mt('Failed to copy old target').", $!, ";
6724: }
6725: return $output;
6726: }
6727:
6728: sub write_metadata {
6729: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6730: my (%metadatafields,%metadatakeys,$output);
6731: $metadatafields{'title'}=$formname;
6732: $metadatafields{'creationdate'}=time;
6733: $metadatafields{'lastrevisiondate'}=time;
6734: $metadatafields{'copyright'}='public';
6735: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6736: $env{'user.domain'};
6737: $metadatafields{'authorspace'}=$confname.':'.$dom;
6738: $metadatafields{'domain'}=$dom;
6739: {
6740: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6741: my $mfh;
1.155 raeburn 6742: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6743: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6744: unless ($_=~/\./) {
6745: my $unikey=$_;
6746: $unikey=~/^([A-Za-z]+)/;
6747: my $tag=$1;
6748: $tag=~tr/A-Z/a-z/;
6749: print $mfh "\n\<$tag";
6750: foreach (split(/\,/,$metadatakeys{$unikey})) {
6751: my $value=$metadatafields{$unikey.'.'.$_};
6752: $value=~s/\"/\'\'/g;
6753: print $mfh ' '.$_.'="'.$value.'"';
6754: }
6755: print $mfh '>'.
6756: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6757: .'</'.$tag.'>';
6758: }
6759: }
6760: $output = 'ok';
6761: print $logfile "\nWrote metadata";
6762: close($mfh);
6763: } else {
6764: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6765: $output = &mt('Could not write metadata');
6766: }
6767: }
1.155 raeburn 6768: return $output;
6769: }
6770:
6771: sub notifysubscribed {
6772: foreach my $targetsource (@{$modified_urls}){
6773: next unless (ref($targetsource) eq 'ARRAY');
6774: my ($target,$source)=@{$targetsource};
6775: if ($source ne '') {
6776: if (open(my $logfh,'>>'.$source.'.log')) {
6777: print $logfh "\nCleanup phase: Notifications\n";
6778: my @subscribed=&subscribed_hosts($target);
6779: foreach my $subhost (@subscribed) {
6780: print $logfh "\nNotifying host ".$subhost.':';
6781: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6782: print $logfh $reply;
6783: }
6784: my @subscribedmeta=&subscribed_hosts("$target.meta");
6785: foreach my $subhost (@subscribedmeta) {
6786: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6787: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6788: $subhost);
6789: print $logfh $reply;
6790: }
6791: print $logfh "\n============ Done ============\n";
1.160 raeburn 6792: close($logfh);
1.155 raeburn 6793: }
6794: }
6795: }
6796: return OK;
6797: }
6798:
6799: sub subscribed_hosts {
6800: my ($target) = @_;
6801: my @subscribed;
6802: if (open(my $fh,"<$target.subscription")) {
6803: while (my $subline=<$fh>) {
6804: if ($subline =~ /^($match_lonid):/) {
6805: my $host = $1;
6806: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6807: unless (grep(/^\Q$host\E$/,@subscribed)) {
6808: push(@subscribed,$host);
6809: }
6810: }
6811: }
6812: }
6813: }
6814: return @subscribed;
1.9 raeburn 6815: }
6816:
6817: sub check_switchserver {
6818: my ($dom,$confname) = @_;
6819: my ($allowed,$switchserver);
6820: my $home = &Apache::lonnet::homeserver($confname,$dom);
6821: if ($home eq 'no_host') {
6822: $home = &Apache::lonnet::domain($dom,'primary');
6823: }
6824: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6825: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6826: if (!$allowed) {
1.180 raeburn 6827: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6828: }
6829: return $switchserver;
6830: }
6831:
1.1 raeburn 6832: sub modify_quotas {
1.216 raeburn 6833: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6834: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6835: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 6836: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6837: $validationfieldsref);
1.86 raeburn 6838: if ($action eq 'quotas') {
6839: $context = 'tools';
1.163 raeburn 6840: } else {
1.86 raeburn 6841: $context = $action;
6842: }
6843: if ($context eq 'requestcourses') {
1.216 raeburn 6844: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6845: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6846: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6847: %titles = &courserequest_titles();
6848: $toolregexp = join('|',@usertools);
6849: %conditions = &courserequest_conditions();
1.216 raeburn 6850: $confname = $dom.'-domainconfig';
6851: my $servadm = $r->dir_config('lonAdmEMail');
6852: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 6853: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6854: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 6855: } elsif ($context eq 'requestauthor') {
6856: @usertools = ('author');
6857: %titles = &authorrequest_titles();
1.86 raeburn 6858: } else {
1.162 raeburn 6859: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6860: %titles = &tool_titles();
1.86 raeburn 6861: }
1.212 raeburn 6862: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6863: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6864: foreach my $key (keys(%env)) {
1.101 raeburn 6865: if ($context eq 'requestcourses') {
6866: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6867: my $item = $1;
6868: my $type = $2;
6869: if ($type =~ /^limit_(.+)/) {
6870: $limithash{$item}{$1} = $env{$key};
6871: } else {
6872: $confhash{$item}{$type} = $env{$key};
6873: }
6874: }
1.163 raeburn 6875: } elsif ($context eq 'requestauthor') {
6876: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6877: $confhash{$1} = $env{$key};
6878: }
1.101 raeburn 6879: } else {
1.86 raeburn 6880: if ($key =~ /^form\.quota_(.+)$/) {
6881: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6882: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6883: $confhash{'authorquota'}{$1} = $env{$key};
6884: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6885: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6886: }
1.72 raeburn 6887: }
6888: }
1.163 raeburn 6889: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6890: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6891: @approvalnotify = sort(@approvalnotify);
6892: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6893: my @crstypes = ('official','unofficial','community','textbook');
6894: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6895: foreach my $type (@hasuniquecode) {
6896: if (grep(/^\Q$type\E$/,@crstypes)) {
6897: $confhash{'uniquecode'}{$type} = 1;
6898: }
1.216 raeburn 6899: }
1.242 raeburn 6900: my (%newbook,%allpos);
1.216 raeburn 6901: if ($context eq 'requestcourses') {
1.242 raeburn 6902: foreach my $type ('textbooks','templates') {
6903: @{$allpos{$type}} = ();
6904: my $invalid;
6905: if ($type eq 'textbooks') {
6906: $invalid = &mt('Invalid LON-CAPA course for textbook');
6907: } else {
6908: $invalid = &mt('Invalid LON-CAPA course for template');
6909: }
6910: if ($env{'form.'.$type.'_addbook'}) {
6911: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6912: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6913: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6914: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6915: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6916: } else {
6917: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6918: my $position = $env{'form.'.$type.'_addbook_pos'};
6919: $position =~ s/\D+//g;
6920: if ($position ne '') {
6921: $allpos{$type}[$position] = $newbook{$type};
6922: }
1.216 raeburn 6923: }
1.242 raeburn 6924: } else {
6925: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 6926: }
6927: }
1.242 raeburn 6928: }
1.216 raeburn 6929: }
1.102 raeburn 6930: if (ref($domconfig{$action}) eq 'HASH') {
6931: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6932: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6933: $changes{'notify'}{'approval'} = 1;
6934: }
6935: } else {
1.144 raeburn 6936: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6937: $changes{'notify'}{'approval'} = 1;
6938: }
6939: }
1.218 raeburn 6940: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6941: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6942: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6943: unless ($confhash{'uniquecode'}{$crstype}) {
6944: $changes{'uniquecode'} = 1;
6945: }
6946: }
6947: unless ($changes{'uniquecode'}) {
6948: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6949: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6950: $changes{'uniquecode'} = 1;
6951: }
6952: }
6953: }
6954: } else {
6955: $changes{'uniquecode'} = 1;
6956: }
6957: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6958: $changes{'uniquecode'} = 1;
1.216 raeburn 6959: }
6960: if ($context eq 'requestcourses') {
1.242 raeburn 6961: foreach my $type ('textbooks','templates') {
6962: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6963: my %deletions;
6964: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6965: if (@todelete) {
6966: map { $deletions{$_} = 1; } @todelete;
6967: }
6968: my %imgdeletions;
6969: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6970: if (@todeleteimages) {
6971: map { $imgdeletions{$_} = 1; } @todeleteimages;
6972: }
6973: my $maxnum = $env{'form.'.$type.'_maxnum'};
6974: for (my $i=0; $i<=$maxnum; $i++) {
6975: my $itemid = $env{'form.'.$type.'_id_'.$i};
6976: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6977: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6978: if ($deletions{$key}) {
6979: if ($domconfig{$action}{$type}{$key}{'image'}) {
6980: #FIXME need to obsolete item in RES space
6981: }
6982: next;
6983: } else {
6984: my $newpos = $env{'form.'.$itemid};
6985: $newpos =~ s/\D+//g;
1.243 raeburn 6986: foreach my $item ('subject','title','publisher','author') {
6987: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6988: ($type eq 'templates'));
1.242 raeburn 6989: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6990: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6991: $changes{$type}{$key} = 1;
6992: }
6993: }
6994: $allpos{$type}[$newpos] = $key;
6995: }
6996: if ($imgdeletions{$key}) {
6997: $changes{$type}{$key} = 1;
1.216 raeburn 6998: #FIXME need to obsolete item in RES space
1.242 raeburn 6999: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7000: my ($cdom,$cnum) = split(/_/,$key);
7001: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7002: $cdom,$cnum,$type,$configuserok,
7003: $switchserver,$author_ok);
7004: if ($imgurl) {
7005: $confhash{$type}{$key}{'image'} = $imgurl;
7006: $changes{$type}{$key} = 1;
1.216 raeburn 7007: }
1.242 raeburn 7008: if ($error) {
7009: &Apache::lonnet::logthis($error);
7010: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7011: }
7012: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7013: $confhash{$type}{$key}{'image'} =
7014: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7015: }
7016: }
7017: }
7018: }
7019: }
7020: }
1.102 raeburn 7021: } else {
1.144 raeburn 7022: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7023: $changes{'notify'}{'approval'} = 1;
7024: }
1.218 raeburn 7025: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7026: $changes{'uniquecode'} = 1;
7027: }
7028: }
7029: if ($context eq 'requestcourses') {
1.242 raeburn 7030: foreach my $type ('textbooks','templates') {
7031: if ($newbook{$type}) {
7032: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7033: foreach my $item ('subject','title','publisher','author') {
7034: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7035: ($type eq 'template'));
1.242 raeburn 7036: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7037: if ($env{'form.'.$type.'_addbook_'.$item}) {
7038: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7039: }
7040: }
7041: if ($type eq 'textbooks') {
7042: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7043: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7044: my ($imageurl,$error) =
7045: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7046: $configuserok,$switchserver,$author_ok);
7047: if ($imageurl) {
7048: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7049: }
7050: if ($error) {
7051: &Apache::lonnet::logthis($error);
7052: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7053: }
7054: }
1.216 raeburn 7055: }
7056: }
1.242 raeburn 7057: if (@{$allpos{$type}} > 0) {
7058: my $idx = 0;
7059: foreach my $item (@{$allpos{$type}}) {
7060: if ($item ne '') {
7061: $confhash{$type}{$item}{'order'} = $idx;
7062: if (ref($domconfig{$action}) eq 'HASH') {
7063: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7064: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7065: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7066: $changes{$type}{$item} = 1;
7067: }
1.216 raeburn 7068: }
7069: }
7070: }
1.242 raeburn 7071: $idx ++;
1.216 raeburn 7072: }
7073: }
7074: }
7075: }
1.235 raeburn 7076: if (ref($validationitemsref) eq 'ARRAY') {
7077: foreach my $item (@{$validationitemsref}) {
7078: if ($item eq 'fields') {
7079: my @changed;
7080: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7081: if (@{$confhash{'validation'}{$item}} > 0) {
7082: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7083: }
7084: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7085: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7086: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7087: $domconfig{'requestcourses'}{'validation'}{$item});
7088: } else {
7089: @changed = @{$confhash{'validation'}{$item}};
7090: }
7091: } else {
7092: @changed = @{$confhash{'validation'}{$item}};
7093: }
7094: if (@changed) {
7095: if ($confhash{'validation'}{$item}) {
7096: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7097: } else {
7098: $changes{'validation'}{$item} = &mt('None');
7099: }
7100: }
7101: } else {
7102: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7103: if ($item eq 'markup') {
7104: if ($env{'form.requestcourses_validation_'.$item}) {
7105: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7106: }
7107: }
7108: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7109: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7110: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7111: }
7112: } else {
7113: if ($confhash{'validation'}{$item} ne '') {
7114: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7115: }
7116: }
7117: }
7118: }
7119: }
7120: if ($env{'form.validationdc'}) {
7121: my $newval = $env{'form.validationdc'};
7122: my %domcoords = &get_active_dcs($dom);
7123: if (exists($domcoords{$newval})) {
7124: $confhash{'validation'}{'dc'} = $newval;
7125: }
7126: }
7127: if (ref($confhash{'validation'}) eq 'HASH') {
7128: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7129: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7130: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7131: if ($confhash{'validation'}{'dc'} eq '') {
7132: $changes{'validation'}{'dc'} = &mt('None');
7133: } else {
7134: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7135: }
7136: }
7137: } elsif ($confhash{'validation'}{'dc'} ne '') {
7138: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7139: }
7140: } elsif ($confhash{'validation'}{'dc'} ne '') {
7141: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7142: }
7143: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7144: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7145: $changes{'validation'}{'dc'} = &mt('None');
7146: }
7147: }
1.102 raeburn 7148: }
7149: } else {
1.86 raeburn 7150: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7151: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7152: }
1.72 raeburn 7153: foreach my $item (@usertools) {
7154: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7155: my $unset;
1.101 raeburn 7156: if ($context eq 'requestcourses') {
1.104 raeburn 7157: $unset = '0';
7158: if ($type eq '_LC_adv') {
7159: $unset = '';
7160: }
1.101 raeburn 7161: if ($confhash{$item}{$type} eq 'autolimit') {
7162: $confhash{$item}{$type} .= '=';
7163: unless ($limithash{$item}{$type} =~ /\D/) {
7164: $confhash{$item}{$type} .= $limithash{$item}{$type};
7165: }
7166: }
1.163 raeburn 7167: } elsif ($context eq 'requestauthor') {
7168: $unset = '0';
7169: if ($type eq '_LC_adv') {
7170: $unset = '';
7171: }
1.72 raeburn 7172: } else {
1.101 raeburn 7173: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7174: $confhash{$item}{$type} = 1;
7175: } else {
7176: $confhash{$item}{$type} = 0;
7177: }
1.72 raeburn 7178: }
1.86 raeburn 7179: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7180: if ($action eq 'requestauthor') {
7181: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7182: $changes{$type} = 1;
7183: }
7184: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7185: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7186: $changes{$item}{$type} = 1;
7187: }
7188: } else {
7189: if ($context eq 'requestcourses') {
1.104 raeburn 7190: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7191: $changes{$item}{$type} = 1;
7192: }
7193: } else {
7194: if (!$confhash{$item}{$type}) {
7195: $changes{$item}{$type} = 1;
7196: }
7197: }
7198: }
7199: } else {
7200: if ($context eq 'requestcourses') {
1.104 raeburn 7201: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7202: $changes{$item}{$type} = 1;
7203: }
1.163 raeburn 7204: } elsif ($context eq 'requestauthor') {
7205: if ($confhash{$type} ne $unset) {
7206: $changes{$type} = 1;
7207: }
1.72 raeburn 7208: } else {
7209: if (!$confhash{$item}{$type}) {
7210: $changes{$item}{$type} = 1;
7211: }
7212: }
7213: }
1.1 raeburn 7214: }
7215: }
1.163 raeburn 7216: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7217: if (ref($domconfig{'quotas'}) eq 'HASH') {
7218: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7219: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7220: if (exists($confhash{'defaultquota'}{$key})) {
7221: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7222: $changes{'defaultquota'}{$key} = 1;
7223: }
7224: } else {
7225: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7226: }
7227: }
1.86 raeburn 7228: } else {
7229: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7230: if (exists($confhash{'defaultquota'}{$key})) {
7231: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7232: $changes{'defaultquota'}{$key} = 1;
7233: }
7234: } else {
7235: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7236: }
1.1 raeburn 7237: }
7238: }
1.197 raeburn 7239: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7240: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7241: if (exists($confhash{'authorquota'}{$key})) {
7242: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7243: $changes{'authorquota'}{$key} = 1;
7244: }
7245: } else {
7246: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7247: }
7248: }
7249: }
1.1 raeburn 7250: }
1.86 raeburn 7251: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7252: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7253: if (ref($domconfig{'quotas'}) eq 'HASH') {
7254: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7255: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7256: $changes{'defaultquota'}{$key} = 1;
7257: }
7258: } else {
7259: if (!exists($domconfig{'quotas'}{$key})) {
7260: $changes{'defaultquota'}{$key} = 1;
7261: }
1.72 raeburn 7262: }
7263: } else {
1.86 raeburn 7264: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7265: }
1.1 raeburn 7266: }
7267: }
1.197 raeburn 7268: if (ref($confhash{'authorquota'}) eq 'HASH') {
7269: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7270: if (ref($domconfig{'quotas'}) eq 'HASH') {
7271: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7272: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7273: $changes{'authorquota'}{$key} = 1;
7274: }
7275: } else {
7276: $changes{'authorquota'}{$key} = 1;
7277: }
7278: } else {
7279: $changes{'authorquota'}{$key} = 1;
7280: }
7281: }
7282: }
1.1 raeburn 7283: }
1.72 raeburn 7284:
1.163 raeburn 7285: if ($context eq 'requestauthor') {
7286: $domdefaults{'requestauthor'} = \%confhash;
7287: } else {
7288: foreach my $key (keys(%confhash)) {
1.242 raeburn 7289: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 7290: $domdefaults{$key} = $confhash{$key};
7291: }
1.163 raeburn 7292: }
1.72 raeburn 7293: }
1.163 raeburn 7294:
1.1 raeburn 7295: my %quotahash = (
1.86 raeburn 7296: $action => { %confhash }
1.1 raeburn 7297: );
7298: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7299: $dom);
7300: if ($putresult eq 'ok') {
7301: if (keys(%changes) > 0) {
1.72 raeburn 7302: my $cachetime = 24*60*60;
7303: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7304: if (ref($lastactref) eq 'HASH') {
7305: $lastactref->{'domdefaults'} = 1;
7306: }
1.1 raeburn 7307: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7308: unless (($context eq 'requestcourses') ||
1.163 raeburn 7309: ($context eq 'requestauthor')) {
1.86 raeburn 7310: if (ref($changes{'defaultquota'}) eq 'HASH') {
7311: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7312: foreach my $type (@{$types},'default') {
7313: if (defined($changes{'defaultquota'}{$type})) {
7314: my $typetitle = $usertypes->{$type};
7315: if ($type eq 'default') {
7316: $typetitle = $othertitle;
7317: }
1.213 raeburn 7318: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7319: }
7320: }
1.86 raeburn 7321: $resulttext .= '</ul></li>';
1.72 raeburn 7322: }
1.197 raeburn 7323: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7324: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7325: foreach my $type (@{$types},'default') {
7326: if (defined($changes{'authorquota'}{$type})) {
7327: my $typetitle = $usertypes->{$type};
7328: if ($type eq 'default') {
7329: $typetitle = $othertitle;
7330: }
1.213 raeburn 7331: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7332: }
7333: }
7334: $resulttext .= '</ul></li>';
7335: }
1.72 raeburn 7336: }
1.80 raeburn 7337: my %newenv;
1.72 raeburn 7338: foreach my $item (@usertools) {
1.163 raeburn 7339: my (%haschgs,%inconf);
7340: if ($context eq 'requestauthor') {
7341: %haschgs = %changes;
1.210 raeburn 7342: %inconf = %confhash;
1.163 raeburn 7343: } else {
7344: if (ref($changes{$item}) eq 'HASH') {
7345: %haschgs = %{$changes{$item}};
7346: }
7347: if (ref($confhash{$item}) eq 'HASH') {
7348: %inconf = %{$confhash{$item}};
7349: }
7350: }
7351: if (keys(%haschgs) > 0) {
1.80 raeburn 7352: my $newacc =
7353: &Apache::lonnet::usertools_access($env{'user.name'},
7354: $env{'user.domain'},
1.86 raeburn 7355: $item,'reload',$context);
1.210 raeburn 7356: if (($context eq 'requestcourses') ||
1.163 raeburn 7357: ($context eq 'requestauthor')) {
1.108 raeburn 7358: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7359: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7360: }
7361: } else {
7362: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7363: $newenv{'environment.availabletools.'.$item} = $newacc;
7364: }
1.80 raeburn 7365: }
1.163 raeburn 7366: unless ($context eq 'requestauthor') {
7367: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7368: }
1.72 raeburn 7369: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7370: if ($haschgs{$type}) {
1.72 raeburn 7371: my $typetitle = $usertypes->{$type};
7372: if ($type eq 'default') {
7373: $typetitle = $othertitle;
7374: } elsif ($type eq '_LC_adv') {
7375: $typetitle = 'LON-CAPA Advanced Users';
7376: }
1.163 raeburn 7377: if ($inconf{$type}) {
1.101 raeburn 7378: if ($context eq 'requestcourses') {
7379: my $cond;
1.163 raeburn 7380: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7381: if ($1 eq '') {
7382: $cond = &mt('(Automatic processing of any request).');
7383: } else {
7384: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7385: }
7386: } else {
1.163 raeburn 7387: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7388: }
7389: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7390: } elsif ($context eq 'requestauthor') {
7391: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7392: $titles{$inconf{$type}},$typetitle);
7393:
1.101 raeburn 7394: } else {
7395: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7396: }
1.72 raeburn 7397: } else {
1.104 raeburn 7398: if ($type eq '_LC_adv') {
1.163 raeburn 7399: if ($inconf{$type} eq '0') {
1.104 raeburn 7400: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7401: } else {
7402: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7403: }
7404: } else {
7405: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7406: }
1.72 raeburn 7407: }
7408: }
1.26 raeburn 7409: }
1.163 raeburn 7410: unless ($context eq 'requestauthor') {
7411: $resulttext .= '</ul></li>';
7412: }
1.26 raeburn 7413: }
1.1 raeburn 7414: }
1.163 raeburn 7415: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7416: if (ref($changes{'notify'}) eq 'HASH') {
7417: if ($changes{'notify'}{'approval'}) {
7418: if (ref($confhash{'notify'}) eq 'HASH') {
7419: if ($confhash{'notify'}{'approval'}) {
7420: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7421: } else {
1.163 raeburn 7422: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7423: }
7424: }
7425: }
7426: }
7427: }
1.216 raeburn 7428: if ($action eq 'requestcourses') {
7429: my @offon = ('off','on');
7430: if ($changes{'uniquecode'}) {
1.218 raeburn 7431: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7432: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7433: $resulttext .= '<li>'.
7434: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7435: '</li>';
7436: } else {
7437: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7438: '</li>';
7439: }
1.216 raeburn 7440: }
1.242 raeburn 7441: foreach my $type ('textbooks','templates') {
7442: if (ref($changes{$type}) eq 'HASH') {
7443: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7444: foreach my $key (sort(keys(%{$changes{$type}}))) {
7445: my %coursehash = &Apache::lonnet::coursedescription($key);
7446: my $coursetitle = $coursehash{'description'};
7447: my $position = $confhash{$type}{$key}{'order'} + 1;
7448: $resulttext .= '<li>';
1.243 raeburn 7449: foreach my $item ('subject','title','publisher','author') {
7450: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7451: ($type eq 'templates'));
1.242 raeburn 7452: my $name = $item.':';
7453: $name =~ s/^(\w)/\U$1/;
7454: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7455: }
7456: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7457: if ($type eq 'textbooks') {
7458: if ($confhash{$type}{$key}{'image'}) {
7459: $resulttext .= ' '.&mt('Image: [_1]',
7460: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7461: ' alt="Textbook cover" />').'<br />';
7462: }
7463: }
7464: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 7465: }
1.242 raeburn 7466: $resulttext .= '</ul></li>';
1.216 raeburn 7467: }
7468: }
1.235 raeburn 7469: if (ref($changes{'validation'}) eq 'HASH') {
7470: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7471: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7472: foreach my $item (@{$validationitemsref}) {
7473: if (exists($changes{'validation'}{$item})) {
7474: if ($item eq 'markup') {
7475: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7476: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7477: } else {
7478: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7479: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7480: }
7481: }
7482: }
7483: if (exists($changes{'validation'}{'dc'})) {
7484: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7485: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7486: }
7487: }
7488: }
1.216 raeburn 7489: }
1.1 raeburn 7490: $resulttext .= '</ul>';
1.80 raeburn 7491: if (keys(%newenv)) {
7492: &Apache::lonnet::appenv(\%newenv);
7493: }
1.1 raeburn 7494: } else {
1.86 raeburn 7495: if ($context eq 'requestcourses') {
7496: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7497: } elsif ($context eq 'requestauthor') {
7498: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7499: } else {
1.90 weissno 7500: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7501: }
1.1 raeburn 7502: }
7503: } else {
1.11 albertel 7504: $resulttext = '<span class="LC_error">'.
7505: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7506: }
1.216 raeburn 7507: if ($errors) {
7508: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7509: '<ul>'.$errors.'</ul></p>';
7510: }
1.3 raeburn 7511: return $resulttext;
1.1 raeburn 7512: }
7513:
1.216 raeburn 7514: sub process_textbook_image {
1.242 raeburn 7515: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 7516: my $filename = $env{'form.'.$caller.'.filename'};
7517: my ($error,$url);
7518: my ($width,$height) = (50,50);
7519: if ($configuserok eq 'ok') {
7520: if ($switchserver) {
7521: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7522: $switchserver);
7523: } elsif ($author_ok eq 'ok') {
7524: my ($result,$imageurl) =
7525: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 7526: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 7527: if ($result eq 'ok') {
7528: $url = $imageurl;
7529: } else {
7530: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7531: }
7532: } else {
7533: $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);
7534: }
7535: } else {
7536: $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);
7537: }
7538: return ($url,$error);
7539: }
7540:
1.3 raeburn 7541: sub modify_autoenroll {
1.205 raeburn 7542: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7543: my ($resulttext,%changes);
7544: my %currautoenroll;
7545: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7546: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7547: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7548: }
7549: }
7550: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7551: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7552: sender => 'Sender for notification messages',
7553: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7554: my @offon = ('off','on');
1.17 raeburn 7555: my $sender_uname = $env{'form.sender_uname'};
7556: my $sender_domain = $env{'form.sender_domain'};
7557: if ($sender_domain eq '') {
7558: $sender_uname = '';
7559: } elsif ($sender_uname eq '') {
7560: $sender_domain = '';
7561: }
1.129 raeburn 7562: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7563: my %autoenrollhash = (
1.129 raeburn 7564: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7565: 'sender_uname' => $sender_uname,
7566: 'sender_domain' => $sender_domain,
7567: 'co-owners' => $coowners,
1.1 raeburn 7568: }
7569: );
1.4 raeburn 7570: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7571: $dom);
1.1 raeburn 7572: if ($putresult eq 'ok') {
7573: if (exists($currautoenroll{'run'})) {
7574: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7575: $changes{'run'} = 1;
7576: }
7577: } elsif ($autorun) {
7578: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7579: $changes{'run'} = 1;
1.1 raeburn 7580: }
7581: }
1.17 raeburn 7582: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7583: $changes{'sender'} = 1;
7584: }
1.17 raeburn 7585: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7586: $changes{'sender'} = 1;
7587: }
1.129 raeburn 7588: if ($currautoenroll{'co-owners'} ne '') {
7589: if ($currautoenroll{'co-owners'} ne $coowners) {
7590: $changes{'coowners'} = 1;
7591: }
7592: } elsif ($coowners) {
7593: $changes{'coowners'} = 1;
7594: }
1.1 raeburn 7595: if (keys(%changes) > 0) {
7596: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7597: if ($changes{'run'}) {
1.1 raeburn 7598: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7599: }
7600: if ($changes{'sender'}) {
1.17 raeburn 7601: if ($sender_uname eq '' || $sender_domain eq '') {
7602: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7603: } else {
7604: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7605: }
1.1 raeburn 7606: }
1.129 raeburn 7607: if ($changes{'coowners'}) {
7608: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7609: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7610: if (ref($lastactref) eq 'HASH') {
7611: $lastactref->{'domainconfig'} = 1;
7612: }
1.129 raeburn 7613: }
1.1 raeburn 7614: $resulttext .= '</ul>';
7615: } else {
7616: $resulttext = &mt('No changes made to auto-enrollment settings');
7617: }
7618: } else {
1.11 albertel 7619: $resulttext = '<span class="LC_error">'.
7620: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7621: }
1.3 raeburn 7622: return $resulttext;
1.1 raeburn 7623: }
7624:
7625: sub modify_autoupdate {
1.3 raeburn 7626: my ($dom,%domconfig) = @_;
1.1 raeburn 7627: my ($resulttext,%currautoupdate,%fields,%changes);
7628: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7629: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7630: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7631: }
7632: }
7633: my @offon = ('off','on');
7634: my %title = &Apache::lonlocal::texthash (
7635: run => 'Auto-update:',
7636: classlists => 'Updates to user information in classlists?'
7637: );
1.44 raeburn 7638: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7639: my %fieldtitles = &Apache::lonlocal::texthash (
7640: id => 'Student/Employee ID',
1.20 raeburn 7641: permanentemail => 'E-mail address',
1.1 raeburn 7642: lastname => 'Last Name',
7643: firstname => 'First Name',
7644: middlename => 'Middle Name',
1.132 raeburn 7645: generation => 'Generation',
1.1 raeburn 7646: );
1.142 raeburn 7647: $othertitle = &mt('All users');
1.1 raeburn 7648: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7649: $othertitle = &mt('Other users');
1.1 raeburn 7650: }
7651: foreach my $key (keys(%env)) {
7652: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7653: my ($usertype,$item) = ($1,$2);
7654: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7655: if ($usertype eq 'default') {
7656: push(@{$fields{$1}},$2);
7657: } elsif (ref($types) eq 'ARRAY') {
7658: if (grep(/^\Q$usertype\E$/,@{$types})) {
7659: push(@{$fields{$1}},$2);
7660: }
7661: }
7662: }
1.1 raeburn 7663: }
7664: }
1.131 raeburn 7665: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7666: @lockablenames = sort(@lockablenames);
7667: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7668: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7669: if (@changed) {
7670: $changes{'lockablenames'} = 1;
7671: }
7672: } else {
7673: if (@lockablenames) {
7674: $changes{'lockablenames'} = 1;
7675: }
7676: }
1.1 raeburn 7677: my %updatehash = (
7678: autoupdate => { run => $env{'form.autoupdate_run'},
7679: classlists => $env{'form.classlists'},
7680: fields => {%fields},
1.131 raeburn 7681: lockablenames => \@lockablenames,
1.1 raeburn 7682: }
7683: );
7684: foreach my $key (keys(%currautoupdate)) {
7685: if (($key eq 'run') || ($key eq 'classlists')) {
7686: if (exists($updatehash{autoupdate}{$key})) {
7687: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7688: $changes{$key} = 1;
7689: }
7690: }
7691: } elsif ($key eq 'fields') {
7692: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7693: foreach my $item (@{$types},'default') {
1.1 raeburn 7694: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7695: my $change = 0;
7696: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7697: if (!exists($fields{$item})) {
7698: $change = 1;
1.132 raeburn 7699: last;
1.1 raeburn 7700: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7701: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7702: $change = 1;
1.132 raeburn 7703: last;
1.1 raeburn 7704: }
7705: }
7706: }
7707: if ($change) {
7708: push(@{$changes{$key}},$item);
7709: }
1.26 raeburn 7710: }
1.1 raeburn 7711: }
7712: }
1.131 raeburn 7713: } elsif ($key eq 'lockablenames') {
7714: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7715: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7716: if (@changed) {
7717: $changes{'lockablenames'} = 1;
7718: }
7719: } else {
7720: if (@lockablenames) {
7721: $changes{'lockablenames'} = 1;
7722: }
7723: }
7724: }
7725: }
7726: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7727: if (@lockablenames) {
7728: $changes{'lockablenames'} = 1;
1.1 raeburn 7729: }
7730: }
1.26 raeburn 7731: foreach my $item (@{$types},'default') {
7732: if (defined($fields{$item})) {
7733: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7734: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7735: my $change = 0;
7736: if (ref($fields{$item}) eq 'ARRAY') {
7737: foreach my $type (@{$fields{$item}}) {
7738: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7739: $change = 1;
7740: last;
7741: }
7742: }
7743: }
7744: if ($change) {
7745: push(@{$changes{'fields'}},$item);
7746: }
7747: } else {
1.26 raeburn 7748: push(@{$changes{'fields'}},$item);
7749: }
7750: } else {
7751: push(@{$changes{'fields'}},$item);
1.1 raeburn 7752: }
7753: }
7754: }
7755: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7756: $dom);
7757: if ($putresult eq 'ok') {
7758: if (keys(%changes) > 0) {
7759: $resulttext = &mt('Changes made:').'<ul>';
7760: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7761: if ($key eq 'lockablenames') {
7762: $resulttext .= '<li>';
7763: if (@lockablenames) {
7764: $usertypes->{'default'} = $othertitle;
7765: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7766: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7767: } else {
7768: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7769: }
7770: $resulttext .= '</li>';
7771: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7772: foreach my $item (@{$changes{$key}}) {
7773: my @newvalues;
7774: foreach my $type (@{$fields{$item}}) {
7775: push(@newvalues,$fieldtitles{$type});
7776: }
1.3 raeburn 7777: my $newvaluestr;
7778: if (@newvalues > 0) {
7779: $newvaluestr = join(', ',@newvalues);
7780: } else {
7781: $newvaluestr = &mt('none');
1.6 raeburn 7782: }
1.1 raeburn 7783: if ($item eq 'default') {
1.26 raeburn 7784: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7785: } else {
1.26 raeburn 7786: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7787: }
7788: }
7789: } else {
7790: my $newvalue;
7791: if ($key eq 'run') {
7792: $newvalue = $offon[$env{'form.autoupdate_run'}];
7793: } else {
7794: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7795: }
1.1 raeburn 7796: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7797: }
7798: }
7799: $resulttext .= '</ul>';
7800: } else {
1.3 raeburn 7801: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7802: }
7803: } else {
1.11 albertel 7804: $resulttext = '<span class="LC_error">'.
7805: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7806: }
1.3 raeburn 7807: return $resulttext;
1.1 raeburn 7808: }
7809:
1.125 raeburn 7810: sub modify_autocreate {
7811: my ($dom,%domconfig) = @_;
7812: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7813: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7814: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7815: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7816: }
7817: }
7818: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7819: req => 'Auto-creation of validated requests for official courses',
7820: xmldc => 'Identity of course creator of courses from XML files',
7821: );
7822: my @types = ('xml','req');
7823: foreach my $item (@types) {
7824: $newvals{$item} = $env{'form.autocreate_'.$item};
7825: $newvals{$item} =~ s/\D//g;
7826: $newvals{$item} = 0 if ($newvals{$item} eq '');
7827: }
7828: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7829: my %domcoords = &get_active_dcs($dom);
7830: unless (exists($domcoords{$newvals{'xmldc'}})) {
7831: $newvals{'xmldc'} = '';
7832: }
7833: %autocreatehash = (
7834: autocreate => { xml => $newvals{'xml'},
7835: req => $newvals{'req'},
7836: }
7837: );
7838: if ($newvals{'xmldc'} ne '') {
7839: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7840: }
7841: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7842: $dom);
7843: if ($putresult eq 'ok') {
7844: my @items = @types;
7845: if ($newvals{'xml'}) {
7846: push(@items,'xmldc');
7847: }
7848: foreach my $item (@items) {
7849: if (exists($currautocreate{$item})) {
7850: if ($currautocreate{$item} ne $newvals{$item}) {
7851: $changes{$item} = 1;
7852: }
7853: } elsif ($newvals{$item}) {
7854: $changes{$item} = 1;
7855: }
7856: }
7857: if (keys(%changes) > 0) {
7858: my @offon = ('off','on');
7859: $resulttext = &mt('Changes made:').'<ul>';
7860: foreach my $item (@types) {
7861: if ($changes{$item}) {
7862: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7863: $resulttext .= '<li>'.
7864: &mt("$title{$item} set to [_1]$newtxt [_2]",
7865: '<b>','</b>').
7866: '</li>';
1.125 raeburn 7867: }
7868: }
7869: if ($changes{'xmldc'}) {
7870: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7871: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7872: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7873: }
7874: $resulttext .= '</ul>';
7875: } else {
7876: $resulttext = &mt('No changes made to auto-creation settings');
7877: }
7878: } else {
7879: $resulttext = '<span class="LC_error">'.
7880: &mt('An error occurred: [_1]',$putresult).'</span>';
7881: }
7882: return $resulttext;
7883: }
7884:
1.23 raeburn 7885: sub modify_directorysrch {
7886: my ($dom,%domconfig) = @_;
7887: my ($resulttext,%changes);
7888: my %currdirsrch;
7889: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7890: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7891: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7892: }
7893: }
7894: my %title = ( available => 'Directory search available',
1.24 raeburn 7895: localonly => 'Other domains can search',
1.23 raeburn 7896: searchby => 'Search types',
7897: searchtypes => 'Search latitude');
7898: my @offon = ('off','on');
1.24 raeburn 7899: my @otherdoms = ('Yes','No');
1.23 raeburn 7900:
1.25 raeburn 7901: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7902: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7903: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7904:
1.44 raeburn 7905: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7906: if (keys(%{$usertypes}) == 0) {
7907: @cansearch = ('default');
7908: } else {
7909: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7910: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7911: if (!grep(/^\Q$type\E$/,@cansearch)) {
7912: push(@{$changes{'cansearch'}},$type);
7913: }
1.23 raeburn 7914: }
1.26 raeburn 7915: foreach my $type (@cansearch) {
7916: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7917: push(@{$changes{'cansearch'}},$type);
7918: }
1.23 raeburn 7919: }
1.26 raeburn 7920: } else {
7921: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7922: }
7923: }
7924:
7925: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7926: foreach my $by (@{$currdirsrch{'searchby'}}) {
7927: if (!grep(/^\Q$by\E$/,@searchby)) {
7928: push(@{$changes{'searchby'}},$by);
7929: }
7930: }
7931: foreach my $by (@searchby) {
7932: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7933: push(@{$changes{'searchby'}},$by);
7934: }
7935: }
7936: } else {
7937: push(@{$changes{'searchby'}},@searchby);
7938: }
1.25 raeburn 7939:
7940: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7941: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7942: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7943: push(@{$changes{'searchtypes'}},$type);
7944: }
7945: }
7946: foreach my $type (@searchtypes) {
7947: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7948: push(@{$changes{'searchtypes'}},$type);
7949: }
7950: }
7951: } else {
7952: if (exists($currdirsrch{'searchtypes'})) {
7953: foreach my $type (@searchtypes) {
7954: if ($type ne $currdirsrch{'searchtypes'}) {
7955: push(@{$changes{'searchtypes'}},$type);
7956: }
7957: }
7958: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7959: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7960: }
7961: } else {
7962: push(@{$changes{'searchtypes'}},@searchtypes);
7963: }
7964: }
7965:
1.23 raeburn 7966: my %dirsrch_hash = (
7967: directorysrch => { available => $env{'form.dirsrch_available'},
7968: cansearch => \@cansearch,
1.24 raeburn 7969: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7970: searchby => \@searchby,
1.25 raeburn 7971: searchtypes => \@searchtypes,
1.23 raeburn 7972: }
7973: );
7974: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7975: $dom);
7976: if ($putresult eq 'ok') {
7977: if (exists($currdirsrch{'available'})) {
7978: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7979: $changes{'available'} = 1;
7980: }
7981: } else {
7982: if ($env{'form.dirsrch_available'} eq '1') {
7983: $changes{'available'} = 1;
7984: }
7985: }
1.24 raeburn 7986: if (exists($currdirsrch{'localonly'})) {
7987: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7988: $changes{'localonly'} = 1;
7989: }
7990: } else {
7991: if ($env{'form.dirsrch_localonly'} eq '1') {
7992: $changes{'localonly'} = 1;
7993: }
7994: }
1.23 raeburn 7995: if (keys(%changes) > 0) {
7996: $resulttext = &mt('Changes made:').'<ul>';
7997: if ($changes{'available'}) {
7998: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7999: }
1.24 raeburn 8000: if ($changes{'localonly'}) {
8001: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8002: }
8003:
1.23 raeburn 8004: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8005: my $chgtext;
1.26 raeburn 8006: if (ref($usertypes) eq 'HASH') {
8007: if (keys(%{$usertypes}) > 0) {
8008: foreach my $type (@{$types}) {
8009: if (grep(/^\Q$type\E$/,@cansearch)) {
8010: $chgtext .= $usertypes->{$type}.'; ';
8011: }
8012: }
8013: if (grep(/^default$/,@cansearch)) {
8014: $chgtext .= $othertitle;
8015: } else {
8016: $chgtext =~ s/\; $//;
8017: }
1.210 raeburn 8018: $resulttext .=
1.178 raeburn 8019: '<li>'.
8020: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8021: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8022: '</li>';
1.23 raeburn 8023: }
8024: }
8025: }
8026: if (ref($changes{'searchby'}) eq 'ARRAY') {
8027: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8028: my $chgtext;
8029: foreach my $type (@{$titleorder}) {
8030: if (grep(/^\Q$type\E$/,@searchby)) {
8031: if (defined($searchtitles->{$type})) {
8032: $chgtext .= $searchtitles->{$type}.'; ';
8033: }
8034: }
8035: }
8036: $chgtext =~ s/\; $//;
8037: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8038: }
1.25 raeburn 8039: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8040: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8041: my $chgtext;
8042: foreach my $type (@{$srchtypeorder}) {
8043: if (grep(/^\Q$type\E$/,@searchtypes)) {
8044: if (defined($srchtypes_desc->{$type})) {
8045: $chgtext .= $srchtypes_desc->{$type}.'; ';
8046: }
8047: }
8048: }
8049: $chgtext =~ s/\; $//;
1.178 raeburn 8050: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8051: }
8052: $resulttext .= '</ul>';
8053: } else {
8054: $resulttext = &mt('No changes made to institution directory search settings');
8055: }
8056: } else {
8057: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8058: &mt('An error occurred: [_1]',$putresult).'</span>';
8059: }
8060: return $resulttext;
8061: }
8062:
1.28 raeburn 8063: sub modify_contacts {
1.205 raeburn 8064: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8065: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8066: if (ref($domconfig{'contacts'}) eq 'HASH') {
8067: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8068: $currsetting{$key} = $domconfig{'contacts'}{$key};
8069: }
8070: }
1.134 raeburn 8071: my (%others,%to,%bcc);
1.28 raeburn 8072: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8073: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 8074: 'requestsmail','updatesmail','idconflictsmail');
8075: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8076: foreach my $type (@mailings) {
8077: @{$newsetting{$type}} =
8078: &Apache::loncommon::get_env_multiple('form.'.$type);
8079: foreach my $item (@contacts) {
8080: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8081: $contacts_hash{contacts}{$type}{$item} = 1;
8082: } else {
8083: $contacts_hash{contacts}{$type}{$item} = 0;
8084: }
8085: }
8086: $others{$type} = $env{'form.'.$type.'_others'};
8087: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8088: if ($type eq 'helpdeskmail') {
8089: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8090: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8091: }
1.28 raeburn 8092: }
8093: foreach my $item (@contacts) {
8094: $to{$item} = $env{'form.'.$item};
8095: $contacts_hash{'contacts'}{$item} = $to{$item};
8096: }
1.203 raeburn 8097: foreach my $item (@toggles) {
8098: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8099: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8100: }
8101: }
1.28 raeburn 8102: if (keys(%currsetting) > 0) {
8103: foreach my $item (@contacts) {
8104: if ($to{$item} ne $currsetting{$item}) {
8105: $changes{$item} = 1;
8106: }
8107: }
8108: foreach my $type (@mailings) {
8109: foreach my $item (@contacts) {
8110: if (ref($currsetting{$type}) eq 'HASH') {
8111: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8112: push(@{$changes{$type}},$item);
8113: }
8114: } else {
8115: push(@{$changes{$type}},@{$newsetting{$type}});
8116: }
8117: }
8118: if ($others{$type} ne $currsetting{$type}{'others'}) {
8119: push(@{$changes{$type}},'others');
8120: }
1.134 raeburn 8121: if ($type eq 'helpdeskmail') {
8122: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8123: push(@{$changes{$type}},'bcc');
8124: }
8125: }
1.28 raeburn 8126: }
8127: } else {
8128: my %default;
8129: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8130: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8131: $default{'errormail'} = 'adminemail';
8132: $default{'packagesmail'} = 'adminemail';
8133: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8134: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8135: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8136: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8137: foreach my $item (@contacts) {
8138: if ($to{$item} ne $default{$item}) {
8139: $changes{$item} = 1;
1.203 raeburn 8140: }
1.28 raeburn 8141: }
8142: foreach my $type (@mailings) {
8143: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8144:
8145: push(@{$changes{$type}},@{$newsetting{$type}});
8146: }
8147: if ($others{$type} ne '') {
8148: push(@{$changes{$type}},'others');
1.134 raeburn 8149: }
8150: if ($type eq 'helpdeskmail') {
8151: if ($bcc{$type} ne '') {
8152: push(@{$changes{$type}},'bcc');
8153: }
8154: }
1.28 raeburn 8155: }
8156: }
1.203 raeburn 8157: foreach my $item (@toggles) {
8158: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8159: $changes{$item} = 1;
8160: } elsif ((!$env{'form.'.$item}) &&
8161: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8162: $changes{$item} = 1;
8163: }
8164: }
1.28 raeburn 8165: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8166: $dom);
8167: if ($putresult eq 'ok') {
8168: if (keys(%changes) > 0) {
1.205 raeburn 8169: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8170: if (ref($lastactref) eq 'HASH') {
8171: $lastactref->{'domainconfig'} = 1;
8172: }
1.28 raeburn 8173: my ($titles,$short_titles) = &contact_titles();
8174: $resulttext = &mt('Changes made:').'<ul>';
8175: foreach my $item (@contacts) {
8176: if ($changes{$item}) {
8177: $resulttext .= '<li>'.$titles->{$item}.
8178: &mt(' set to: ').
8179: '<span class="LC_cusr_emph">'.
8180: $to{$item}.'</span></li>';
8181: }
8182: }
8183: foreach my $type (@mailings) {
8184: if (ref($changes{$type}) eq 'ARRAY') {
8185: $resulttext .= '<li>'.$titles->{$type}.': ';
8186: my @text;
8187: foreach my $item (@{$newsetting{$type}}) {
8188: push(@text,$short_titles->{$item});
8189: }
8190: if ($others{$type} ne '') {
8191: push(@text,$others{$type});
8192: }
8193: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8194: join(', ',@text).'</span>';
8195: if ($type eq 'helpdeskmail') {
8196: if ($bcc{$type} ne '') {
8197: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8198: }
8199: }
8200: $resulttext .= '</li>';
1.28 raeburn 8201: }
8202: }
1.203 raeburn 8203: my @offon = ('off','on');
8204: if ($changes{'reporterrors'}) {
8205: $resulttext .= '<li>'.
8206: &mt('E-mail error reports to [_1] set to "'.
8207: $offon[$env{'form.reporterrors'}].'".',
8208: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8209: &mt('LON-CAPA core group - MSU'),600,500)).
8210: '</li>';
8211: }
8212: if ($changes{'reportupdates'}) {
8213: $resulttext .= '<li>'.
8214: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8215: $offon[$env{'form.reportupdates'}].'".',
8216: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8217: &mt('LON-CAPA core group - MSU'),600,500)).
8218: '</li>';
8219: }
1.28 raeburn 8220: $resulttext .= '</ul>';
8221: } else {
1.34 raeburn 8222: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8223: }
8224: } else {
8225: $resulttext = '<span class="LC_error">'.
8226: &mt('An error occurred: [_1].',$putresult).'</span>';
8227: }
8228: return $resulttext;
8229: }
8230:
8231: sub modify_usercreation {
1.27 raeburn 8232: my ($dom,%domconfig) = @_;
1.224 raeburn 8233: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8234: my $warningmsg;
1.27 raeburn 8235: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8236: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8237: if ($key eq 'cancreate') {
8238: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8239: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8240: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8241: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8242: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8243: } else {
8244: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8245: }
8246: }
8247: }
8248: } elsif ($key eq 'email_rule') {
8249: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8250: } else {
8251: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8252: }
1.27 raeburn 8253: }
8254: }
8255: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8256: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8257: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8258: foreach my $item(@contexts) {
1.224 raeburn 8259: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8260: }
1.34 raeburn 8261: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8262: foreach my $item (@contexts) {
1.224 raeburn 8263: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8264: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8265: }
1.27 raeburn 8266: }
1.34 raeburn 8267: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8268: foreach my $item (@contexts) {
1.43 raeburn 8269: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8270: if ($cancreate{$item} ne 'any') {
8271: push(@{$changes{'cancreate'}},$item);
8272: }
8273: } else {
8274: if ($cancreate{$item} ne 'none') {
8275: push(@{$changes{'cancreate'}},$item);
8276: }
1.27 raeburn 8277: }
8278: }
8279: } else {
1.43 raeburn 8280: foreach my $item (@contexts) {
1.34 raeburn 8281: push(@{$changes{'cancreate'}},$item);
8282: }
1.27 raeburn 8283: }
1.34 raeburn 8284:
1.27 raeburn 8285: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8286: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8287: if (!grep(/^\Q$type\E$/,@username_rule)) {
8288: push(@{$changes{'username_rule'}},$type);
8289: }
8290: }
8291: foreach my $type (@username_rule) {
8292: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8293: push(@{$changes{'username_rule'}},$type);
8294: }
8295: }
8296: } else {
8297: push(@{$changes{'username_rule'}},@username_rule);
8298: }
8299:
1.32 raeburn 8300: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8301: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8302: if (!grep(/^\Q$type\E$/,@id_rule)) {
8303: push(@{$changes{'id_rule'}},$type);
8304: }
8305: }
8306: foreach my $type (@id_rule) {
8307: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8308: push(@{$changes{'id_rule'}},$type);
8309: }
8310: }
8311: } else {
8312: push(@{$changes{'id_rule'}},@id_rule);
8313: }
8314:
1.43 raeburn 8315: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8316: my @authtypes = ('int','krb4','krb5','loc');
8317: my %authhash;
1.43 raeburn 8318: foreach my $item (@authen_contexts) {
1.28 raeburn 8319: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8320: foreach my $auth (@authtypes) {
8321: if (grep(/^\Q$auth\E$/,@authallowed)) {
8322: $authhash{$item}{$auth} = 1;
8323: } else {
8324: $authhash{$item}{$auth} = 0;
8325: }
8326: }
8327: }
8328: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8329: foreach my $item (@authen_contexts) {
1.28 raeburn 8330: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8331: foreach my $auth (@authtypes) {
8332: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8333: push(@{$changes{'authtypes'}},$item);
8334: last;
8335: }
8336: }
8337: }
8338: }
8339: } else {
1.43 raeburn 8340: foreach my $item (@authen_contexts) {
1.28 raeburn 8341: push(@{$changes{'authtypes'}},$item);
8342: }
8343: }
8344:
1.224 raeburn 8345: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8346: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8347: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8348: $save_usercreate{'id_rule'} = \@id_rule;
8349: $save_usercreate{'username_rule'} = \@username_rule,
8350: $save_usercreate{'authtypes'} = \%authhash;
8351:
1.27 raeburn 8352: my %usercreation_hash = (
1.224 raeburn 8353: usercreation => \%save_usercreate,
8354: );
1.27 raeburn 8355:
8356: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8357: $dom);
1.50 raeburn 8358:
1.224 raeburn 8359: if ($putresult eq 'ok') {
8360: if (keys(%changes) > 0) {
8361: $resulttext = &mt('Changes made:').'<ul>';
8362: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8363: my %lt = &usercreation_types();
8364: foreach my $type (@{$changes{'cancreate'}}) {
8365: my $chgtext = $lt{$type}.', ';
8366: if ($cancreate{$type} eq 'none') {
8367: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8368: } elsif ($cancreate{$type} eq 'any') {
8369: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8370: } elsif ($cancreate{$type} eq 'official') {
8371: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8372: } elsif ($cancreate{$type} eq 'unofficial') {
8373: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8374: }
8375: $resulttext .= '<li>'.$chgtext.'</li>';
8376: }
8377: }
8378: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8379: my ($rules,$ruleorder) =
8380: &Apache::lonnet::inst_userrules($dom,'username');
8381: my $chgtext = '<ul>';
8382: foreach my $type (@username_rule) {
8383: if (ref($rules->{$type}) eq 'HASH') {
8384: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8385: }
8386: }
8387: $chgtext .= '</ul>';
8388: if (@username_rule > 0) {
8389: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8390: } else {
8391: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8392: }
8393: }
8394: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8395: my ($idrules,$idruleorder) =
8396: &Apache::lonnet::inst_userrules($dom,'id');
8397: my $chgtext = '<ul>';
8398: foreach my $type (@id_rule) {
8399: if (ref($idrules->{$type}) eq 'HASH') {
8400: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8401: }
8402: }
8403: $chgtext .= '</ul>';
8404: if (@id_rule > 0) {
8405: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8406: } else {
8407: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8408: }
8409: }
8410: my %authname = &authtype_names();
8411: my %context_title = &context_names();
8412: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8413: my $chgtext = '<ul>';
8414: foreach my $type (@{$changes{'authtypes'}}) {
8415: my @allowed;
8416: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8417: foreach my $auth (@authtypes) {
8418: if ($authhash{$type}{$auth}) {
8419: push(@allowed,$authname{$auth});
8420: }
8421: }
8422: if (@allowed > 0) {
8423: $chgtext .= join(', ',@allowed).'</li>';
8424: } else {
8425: $chgtext .= &mt('none').'</li>';
8426: }
8427: }
8428: $chgtext .= '</ul>';
8429: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8430: $resulttext .= '</li>';
8431: }
8432: $resulttext .= '</ul>';
8433: } else {
8434: $resulttext = &mt('No changes made to user creation settings');
8435: }
8436: } else {
8437: $resulttext = '<span class="LC_error">'.
8438: &mt('An error occurred: [_1]',$putresult).'</span>';
8439: }
8440: if ($warningmsg ne '') {
8441: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8442: }
8443: return $resulttext;
8444: }
8445:
8446: sub modify_selfcreation {
8447: my ($dom,%domconfig) = @_;
8448: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8449: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8450: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8451: if (ref($types) eq 'ARRAY') {
8452: $usertypes->{'default'} = $othertitle;
8453: push(@{$types},'default');
8454: }
1.224 raeburn 8455: #
8456: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8457: #
8458: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8459: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8460: if ($key eq 'cancreate') {
8461: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8462: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8463: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8464: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8465: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 8466: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 8467: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8468: } else {
8469: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8470: }
8471: }
8472: }
8473: } elsif ($key eq 'email_rule') {
8474: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8475: } else {
8476: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8477: }
8478: }
8479: }
8480: #
8481: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8482: #
8483: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8484: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8485: if ($key eq 'selfcreate') {
8486: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8487: } else {
8488: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8489: }
8490: }
8491: }
8492:
8493: my @contexts = ('selfcreate');
8494: @{$cancreate{'selfcreate'}} = ();
8495: %{$cancreate{'emailusername'}} = ();
8496: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8497: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 8498: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8499: my %selfcreatetypes = (
8500: sso => 'users authenticated by institutional single sign on',
8501: login => 'users authenticated by institutional log-in',
1.236 raeburn 8502: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8503: );
1.224 raeburn 8504: #
8505: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8506: # is permitted.
8507: #
1.236 raeburn 8508:
8509: my @statuses;
8510: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8511: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8512: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8513: }
8514: }
8515: push(@statuses,'default');
8516:
1.228 raeburn 8517: foreach my $item ('login','sso','email') {
1.224 raeburn 8518: if ($item eq 'email') {
1.236 raeburn 8519: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8520: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8521: push(@contexts,'selfcreateprocessing');
8522: foreach my $type (@statuses) {
8523: if ($type eq 'default') {
8524: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8525: } else {
8526: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8527: }
8528: }
1.224 raeburn 8529: }
8530: } else {
8531: if ($env{'form.cancreate_'.$item}) {
8532: push(@{$cancreate{'selfcreate'}},$item);
8533: }
8534: }
8535: }
8536: my (@email_rule,%userinfo,%savecaptcha);
8537: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8538: #
1.228 raeburn 8539: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8540: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8541: #
1.236 raeburn 8542:
1.244 raeburn 8543: if ($env{'form.cancreate_email'}) {
1.228 raeburn 8544: push(@contexts,'emailusername');
8545: if (ref($types) eq 'ARRAY') {
8546: foreach my $type (@{$types}) {
8547: if (ref($infofields) eq 'ARRAY') {
8548: foreach my $field (@{$infofields}) {
8549: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8550: $cancreate{'emailusername'}{$type}{$field} = $1;
8551: }
8552: }
1.224 raeburn 8553: }
8554: }
8555: }
8556: #
8557: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8558: # queued requests for self-creation of account using e-mail address as username
8559: #
8560:
8561: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8562: @approvalnotify = sort(@approvalnotify);
8563: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8564: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8565: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8566: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8567: push(@{$changes{'cancreate'}},'notify');
8568: }
8569: } else {
8570: if ($cancreate{'notify'}{'approval'}) {
8571: push(@{$changes{'cancreate'}},'notify');
8572: }
8573: }
8574: } elsif ($cancreate{'notify'}{'approval'}) {
8575: push(@{$changes{'cancreate'}},'notify');
8576: }
8577:
8578: #
8579: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8580: #
8581: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8582: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8583: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8584: if (@{$curr_usercreation{'email_rule'}} > 0) {
8585: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8586: if (!grep(/^\Q$type\E$/,@email_rule)) {
8587: push(@{$changes{'email_rule'}},$type);
8588: }
8589: }
8590: }
8591: if (@email_rule > 0) {
8592: foreach my $type (@email_rule) {
8593: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8594: push(@{$changes{'email_rule'}},$type);
8595: }
8596: }
8597: }
8598: } elsif (@email_rule > 0) {
8599: push(@{$changes{'email_rule'}},@email_rule);
8600: }
8601: }
8602: #
1.236 raeburn 8603: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8604: # institutional log-in.
8605: #
8606: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8607: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8608: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8609: ($domdefaults{'auth_def'} eq 'localauth'))) {
8610: $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.').' '.
8611: &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.');
8612: }
8613: }
8614: my @fields = ('lastname','firstname','middlename','generation',
8615: 'permanentemail','id');
1.240 raeburn 8616: my @shibfields = (@fields,'inststatus');
1.224 raeburn 8617: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8618: #
8619: # Where usernames may created for institutional log-in and/or institutional single sign on:
8620: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8621: # may self-create accounts
8622: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8623: # which the user may supply, if institutional data is unavailable.
8624: #
8625: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8626: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8627: if (@{$types} > 1) {
1.224 raeburn 8628: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8629: push(@contexts,'statustocreate');
8630: } else {
8631: undef($cancreate{'statustocreate'});
8632: }
8633: foreach my $type (@{$types}) {
8634: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8635: foreach my $field (@fields) {
8636: if (grep(/^\Q$field\E$/,@modifiable)) {
8637: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8638: } else {
8639: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8640: }
8641: }
8642: }
8643: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8644: foreach my $type (@{$types}) {
8645: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8646: foreach my $field (@fields) {
8647: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8648: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8649: push(@{$changes{'selfcreate'}},$type);
8650: last;
8651: }
8652: }
8653: }
8654: }
8655: } else {
8656: foreach my $type (@{$types}) {
8657: push(@{$changes{'selfcreate'}},$type);
8658: }
8659: }
8660: }
1.240 raeburn 8661: foreach my $field (@shibfields) {
8662: if ($env{'form.shibenv_'.$field} ne '') {
8663: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8664: }
8665: }
8666: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8667: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8668: foreach my $field (@shibfields) {
8669: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8670: push(@{$changes{'cancreate'}},'shibenv');
8671: }
8672: }
8673: } else {
8674: foreach my $field (@shibfields) {
8675: if ($env{'form.shibenv_'.$field}) {
8676: push(@{$changes{'cancreate'}},'shibenv');
8677: last;
8678: }
8679: }
8680: }
8681: }
1.224 raeburn 8682: }
8683: foreach my $item (@contexts) {
8684: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8685: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8686: if (ref($cancreate{$item}) eq 'ARRAY') {
8687: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8688: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8689: push(@{$changes{'cancreate'}},$item);
8690: }
8691: }
8692: }
8693: }
8694: if (ref($cancreate{$item}) eq 'ARRAY') {
8695: foreach my $type (@{$cancreate{$item}}) {
8696: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8697: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8698: push(@{$changes{'cancreate'}},$item);
8699: }
8700: }
8701: }
8702: }
8703: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8704: if (ref($cancreate{$item}) eq 'HASH') {
8705: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8706: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8707: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8708: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8709: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8710: push(@{$changes{'cancreate'}},$item);
8711: }
8712: }
8713: }
1.236 raeburn 8714: } elsif ($item eq 'selfcreateprocessing') {
8715: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8716: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8717: push(@{$changes{'cancreate'}},$item);
8718: }
8719: }
1.228 raeburn 8720: } else {
8721: if (!$cancreate{$item}{$curr}) {
8722: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8723: push(@{$changes{'cancreate'}},$item);
8724: }
1.224 raeburn 8725: }
8726: }
8727: }
8728: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8729: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8730: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8731: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8732: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8733: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8734: push(@{$changes{'cancreate'}},$item);
8735: }
8736: }
8737: } else {
8738: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8739: push(@{$changes{'cancreate'}},$item);
8740: }
8741: }
8742: }
1.236 raeburn 8743: } elsif ($item eq 'selfcreateprocessing') {
8744: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8745: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8746: push(@{$changes{'cancreate'}},$item);
8747: }
8748: }
1.228 raeburn 8749: } else {
8750: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8751: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8752: push(@{$changes{'cancreate'}},$item);
8753: }
1.224 raeburn 8754: }
8755: }
8756: }
8757: }
8758: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8759: if (ref($cancreate{$item}) eq 'ARRAY') {
8760: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8761: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8762: push(@{$changes{'cancreate'}},$item);
8763: }
8764: }
8765: } elsif (ref($cancreate{$item}) eq 'HASH') {
8766: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8767: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8768: push(@{$changes{'cancreate'}},$item);
8769: }
8770: }
8771: }
8772: } elsif ($item eq 'emailusername') {
1.228 raeburn 8773: if (ref($cancreate{$item}) eq 'HASH') {
8774: foreach my $type (keys(%{$cancreate{$item}})) {
8775: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8776: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8777: if ($cancreate{$item}{$type}{$field}) {
8778: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8779: push(@{$changes{'cancreate'}},$item);
8780: }
8781: last;
8782: }
8783: }
8784: }
8785: }
1.224 raeburn 8786: }
8787: }
8788: }
8789: #
8790: # Populate %save_usercreate hash with updates to self-creation configuration.
8791: #
8792: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8793: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8794: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8795: if (ref($cancreate{'notify'}) eq 'HASH') {
8796: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8797: }
1.236 raeburn 8798: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8799: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8800: }
1.224 raeburn 8801: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8802: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8803: }
1.240 raeburn 8804: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8805: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8806: }
1.224 raeburn 8807: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8808: $save_usercreate{'emailrule'} = \@email_rule;
8809:
8810: my %userconfig_hash = (
8811: usercreation => \%save_usercreate,
8812: usermodification => \%save_usermodify,
8813: );
8814: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8815: $dom);
8816: #
8817: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8818: #
1.27 raeburn 8819: if ($putresult eq 'ok') {
8820: if (keys(%changes) > 0) {
8821: $resulttext = &mt('Changes made:').'<ul>';
8822: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8823: my %lt = &selfcreation_types();
1.34 raeburn 8824: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8825: my $chgtext;
1.45 raeburn 8826: if ($type eq 'selfcreate') {
1.50 raeburn 8827: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8828: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8829: } else {
1.224 raeburn 8830: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8831: '<ul>';
1.50 raeburn 8832: foreach my $case (@{$cancreate{$type}}) {
8833: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8834: }
8835: $chgtext .= '</ul>';
1.100 raeburn 8836: if (ref($cancreate{$type}) eq 'ARRAY') {
8837: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8838: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8839: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8840: $chgtext .= '<br />'.
8841: '<span class="LC_warning">'.
8842: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8843: '</span>';
1.100 raeburn 8844: }
8845: }
8846: }
8847: }
1.43 raeburn 8848: }
1.240 raeburn 8849: } elsif ($type eq 'shibenv') {
8850: if (keys(%{$cancreate{$type}}) == 0) {
8851: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8852: } else {
8853: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8854: '<ul>';
8855: foreach my $field (@shibfields) {
8856: next if ($cancreate{$type}{$field} eq '');
8857: if ($field eq 'inststatus') {
8858: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8859: } else {
8860: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8861: }
8862: }
8863: $chgtext .= '</ul>';
8864: }
1.93 raeburn 8865: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8866: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8867: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8868: if (@{$cancreate{'selfcreate'}} > 0) {
8869: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8870: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8871: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8872: $chgtext .= '<br />'.
8873: '<span class="LC_warning">'.
8874: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8875: '</span>';
8876: }
1.96 raeburn 8877: } elsif (ref($usertypes) eq 'HASH') {
8878: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8879: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8880: } else {
8881: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8882: }
8883: $chgtext .= '<ul>';
8884: foreach my $case (@{$cancreate{$type}}) {
8885: if ($case eq 'default') {
8886: $chgtext .= '<li>'.$othertitle.'</li>';
8887: } else {
8888: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8889: }
8890: }
1.100 raeburn 8891: $chgtext .= '</ul>';
8892: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8893: $chgtext .= '<br /><span class="LC_warning">'.
8894: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8895: '</span>';
1.100 raeburn 8896: }
8897: }
8898: } else {
8899: if (@{$cancreate{$type}} == 0) {
8900: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8901: } else {
8902: $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 8903: }
8904: }
8905: }
1.236 raeburn 8906: } elsif ($type eq 'selfcreateprocessing') {
8907: my %choices = &Apache::lonlocal::texthash (
8908: automatic => 'Automatic approval',
8909: approval => 'Queued for approval',
8910: );
8911: if (@statuses > 1) {
8912: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8913: '<ul>';
8914: foreach my $type (@statuses) {
8915: if ($type eq 'default') {
8916: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8917: } else {
8918: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8919: }
8920: }
8921: $chgtext .= '</ul>';
8922: } else {
8923: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8924: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8925: }
1.165 raeburn 8926: } elsif ($type eq 'captcha') {
1.224 raeburn 8927: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8928: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8929: } else {
8930: my %captchas = &captcha_phrases();
1.224 raeburn 8931: if ($captchas{$savecaptcha{$type}}) {
8932: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8933: } else {
1.210 raeburn 8934: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8935: }
8936: }
8937: } elsif ($type eq 'recaptchakeys') {
8938: my ($privkey,$pubkey);
1.224 raeburn 8939: if (ref($savecaptcha{$type}) eq 'HASH') {
8940: $pubkey = $savecaptcha{$type}{'public'};
8941: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8942: }
8943: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8944: if (!$pubkey) {
8945: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8946: } else {
8947: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8948: }
8949: if (!$privkey) {
8950: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8951: } else {
8952: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8953: }
8954: $chgtext .= '</ul>';
1.224 raeburn 8955: } elsif ($type eq 'emailusername') {
8956: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8957: if (ref($types) eq 'ARRAY') {
8958: foreach my $type (@{$types}) {
8959: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8960: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 8961: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 8962: '<ul>';
8963: foreach my $field (@{$infofields}) {
8964: if ($cancreate{'emailusername'}{$type}{$field}) {
8965: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8966: }
8967: }
1.245 raeburn 8968: $chgtext .= '</ul>';
8969: } else {
8970: $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.228 raeburn 8971: }
8972: } else {
1.245 raeburn 8973: $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 8974: }
8975: }
8976: }
8977: }
8978: } elsif ($type eq 'notify') {
8979: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8980: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8981: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8982: if ($cancreate{'notify'}{'approval'}) {
8983: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8984: }
8985: }
1.43 raeburn 8986: }
1.34 raeburn 8987: }
1.224 raeburn 8988: if ($chgtext) {
8989: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8990: }
8991: }
8992: }
1.43 raeburn 8993: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8994: my ($emailrules,$emailruleorder) =
8995: &Apache::lonnet::inst_userrules($dom,'email');
8996: my $chgtext = '<ul>';
8997: foreach my $type (@email_rule) {
8998: if (ref($emailrules->{$type}) eq 'HASH') {
8999: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9000: }
9001: }
9002: $chgtext .= '</ul>';
9003: if (@email_rule > 0) {
1.224 raeburn 9004: $resulttext .= '<li>'.
9005: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9006: $chgtext.
9007: '</li>';
1.43 raeburn 9008: } else {
1.224 raeburn 9009: $resulttext .= '<li>'.
9010: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9011: '</li>';
1.43 raeburn 9012: }
9013: }
1.224 raeburn 9014: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9015: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9016: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9017: foreach my $type (@{$changes{'selfcreate'}}) {
9018: my $typename = $type;
9019: if (ref($usertypes) eq 'HASH') {
9020: if ($usertypes->{$type} ne '') {
9021: $typename = $usertypes->{$type};
9022: }
9023: }
9024: my @modifiable;
9025: $resulttext .= '<li>'.
9026: &mt('Self-creation of account by users with status: [_1]',
9027: '<span class="LC_cusr_emph">'.$typename.'</span>').
9028: ' - '.&mt('modifiable fields (if institutional data blank): ');
9029: foreach my $field (@fields) {
9030: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9031: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 9032: }
9033: }
1.224 raeburn 9034: if (@modifiable > 0) {
9035: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9036: } else {
1.224 raeburn 9037: $resulttext .= &mt('none');
1.43 raeburn 9038: }
1.224 raeburn 9039: $resulttext .= '</li>';
1.28 raeburn 9040: }
1.224 raeburn 9041: $resulttext .= '</ul></li>';
1.28 raeburn 9042: }
1.27 raeburn 9043: $resulttext .= '</ul>';
9044: } else {
1.224 raeburn 9045: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9046: }
9047: } else {
9048: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9049: &mt('An error occurred: [_1]',$putresult).'</span>';
9050: }
1.43 raeburn 9051: if ($warningmsg ne '') {
9052: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9053: }
1.23 raeburn 9054: return $resulttext;
9055: }
9056:
1.165 raeburn 9057: sub process_captcha {
9058: my ($container,$changes,$newsettings,$current) = @_;
9059: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9060: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9061: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9062: $newsettings->{'captcha'} = 'original';
9063: }
9064: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 9065: if ($container eq 'cancreate') {
1.169 raeburn 9066: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9067: push(@{$changes->{'cancreate'}},'captcha');
9068: } elsif (!defined($changes->{'cancreate'})) {
9069: $changes->{'cancreate'} = ['captcha'];
9070: }
9071: } else {
9072: $changes->{'captcha'} = 1;
1.165 raeburn 9073: }
9074: }
9075: my ($newpub,$newpriv,$currpub,$currpriv);
9076: if ($newsettings->{'captcha'} eq 'recaptcha') {
9077: $newpub = $env{'form.'.$container.'_recaptchapub'};
9078: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 9079: $newpub =~ s/[^\w\-]//g;
9080: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 9081: $newsettings->{'recaptchakeys'} = {
9082: public => $newpub,
9083: private => $newpriv,
9084: };
1.165 raeburn 9085: }
9086: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9087: $currpub = $current->{'recaptchakeys'}{'public'};
9088: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 9089: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9090: $newsettings->{'recaptchakeys'} = {
9091: public => '',
9092: private => '',
9093: }
9094: }
1.165 raeburn 9095: }
9096: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 9097: if ($container eq 'cancreate') {
9098: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9099: push(@{$changes->{'cancreate'}},'recaptchakeys');
9100: } elsif (!defined($changes->{'cancreate'})) {
9101: $changes->{'cancreate'} = ['recaptchakeys'];
9102: }
9103: } else {
1.210 raeburn 9104: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 9105: }
9106: }
9107: return;
9108: }
9109:
1.33 raeburn 9110: sub modify_usermodification {
9111: my ($dom,%domconfig) = @_;
1.224 raeburn 9112: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9113: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9114: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 9115: if ($key eq 'selfcreate') {
9116: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9117: } else {
9118: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9119: }
1.33 raeburn 9120: }
9121: }
1.224 raeburn 9122: my @contexts = ('author','course');
1.33 raeburn 9123: my %context_title = (
9124: author => 'In author context',
9125: course => 'In course context',
9126: );
9127: my @fields = ('lastname','firstname','middlename','generation',
9128: 'permanentemail','id');
9129: my %roles = (
9130: author => ['ca','aa'],
9131: course => ['st','ep','ta','in','cr'],
9132: );
9133: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9134: foreach my $context (@contexts) {
9135: foreach my $role (@{$roles{$context}}) {
9136: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9137: foreach my $item (@fields) {
9138: if (grep(/^\Q$item\E$/,@modifiable)) {
9139: $modifyhash{$context}{$role}{$item} = 1;
9140: } else {
9141: $modifyhash{$context}{$role}{$item} = 0;
9142: }
9143: }
9144: }
9145: if (ref($curr_usermodification{$context}) eq 'HASH') {
9146: foreach my $role (@{$roles{$context}}) {
9147: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9148: foreach my $field (@fields) {
9149: if ($modifyhash{$context}{$role}{$field} ne
9150: $curr_usermodification{$context}{$role}{$field}) {
9151: push(@{$changes{$context}},$role);
9152: last;
9153: }
9154: }
9155: }
9156: }
9157: } else {
9158: foreach my $context (@contexts) {
9159: foreach my $role (@{$roles{$context}}) {
9160: push(@{$changes{$context}},$role);
9161: }
9162: }
9163: }
9164: }
9165: my %usermodification_hash = (
9166: usermodification => \%modifyhash,
9167: );
9168: my $putresult = &Apache::lonnet::put_dom('configuration',
9169: \%usermodification_hash,$dom);
9170: if ($putresult eq 'ok') {
9171: if (keys(%changes) > 0) {
9172: $resulttext = &mt('Changes made: ').'<ul>';
9173: foreach my $context (@contexts) {
9174: if (ref($changes{$context}) eq 'ARRAY') {
9175: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9176: if (ref($changes{$context}) eq 'ARRAY') {
9177: foreach my $role (@{$changes{$context}}) {
9178: my $rolename;
1.224 raeburn 9179: if ($role eq 'cr') {
9180: $rolename = &mt('Custom');
1.33 raeburn 9181: } else {
1.224 raeburn 9182: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9183: }
9184: my @modifiable;
1.224 raeburn 9185: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9186: foreach my $field (@fields) {
9187: if ($modifyhash{$context}{$role}{$field}) {
9188: push(@modifiable,$fieldtitles{$field});
9189: }
9190: }
9191: if (@modifiable > 0) {
9192: $resulttext .= join(', ',@modifiable);
9193: } else {
9194: $resulttext .= &mt('none');
9195: }
9196: $resulttext .= '</li>';
9197: }
9198: $resulttext .= '</ul></li>';
9199: }
9200: }
9201: }
9202: $resulttext .= '</ul>';
9203: } else {
9204: $resulttext = &mt('No changes made to user modification settings');
9205: }
9206: } else {
9207: $resulttext = '<span class="LC_error">'.
9208: &mt('An error occurred: [_1]',$putresult).'</span>';
9209: }
9210: return $resulttext;
9211: }
9212:
1.43 raeburn 9213: sub modify_defaults {
1.212 raeburn 9214: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9215: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9216: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9217: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9218: my @authtypes = ('internal','krb4','krb5','localauth');
9219: foreach my $item (@items) {
9220: $newvalues{$item} = $env{'form.'.$item};
9221: if ($item eq 'auth_def') {
9222: if ($newvalues{$item} ne '') {
9223: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9224: push(@errors,$item);
9225: }
9226: }
9227: } elsif ($item eq 'lang_def') {
9228: if ($newvalues{$item} ne '') {
9229: if ($newvalues{$item} =~ /^(\w+)/) {
9230: my $langcode = $1;
1.103 raeburn 9231: if ($langcode ne 'x_chef') {
9232: if (code2language($langcode) eq '') {
9233: push(@errors,$item);
9234: }
1.43 raeburn 9235: }
9236: } else {
9237: push(@errors,$item);
9238: }
9239: }
1.54 raeburn 9240: } elsif ($item eq 'timezone_def') {
9241: if ($newvalues{$item} ne '') {
1.62 raeburn 9242: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9243: push(@errors,$item);
9244: }
9245: }
1.68 raeburn 9246: } elsif ($item eq 'datelocale_def') {
9247: if ($newvalues{$item} ne '') {
9248: my @datelocale_ids = DateTime::Locale->ids();
9249: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9250: push(@errors,$item);
9251: }
9252: }
1.141 raeburn 9253: } elsif ($item eq 'portal_def') {
9254: if ($newvalues{$item} ne '') {
9255: 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])\/?$/) {
9256: push(@errors,$item);
9257: }
9258: }
1.43 raeburn 9259: }
9260: if (grep(/^\Q$item\E$/,@errors)) {
9261: $newvalues{$item} = $domdefaults{$item};
9262: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9263: $changes{$item} = 1;
9264: }
1.72 raeburn 9265: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9266: }
9267: my %defaults_hash = (
1.72 raeburn 9268: defaults => \%newvalues,
9269: );
1.43 raeburn 9270: my $title = &defaults_titles();
1.236 raeburn 9271:
9272: my $currinststatus;
9273: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9274: $currinststatus = $domconfig{'inststatus'};
9275: } else {
9276: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9277: $currinststatus = {
9278: inststatustypes => $usertypes,
9279: inststatusorder => $types,
9280: inststatusguest => [],
9281: };
9282: }
9283: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9284: my @allpos;
9285: my %guests;
9286: my %alltypes;
9287: my ($currtitles,$currguests,$currorder);
9288: if (ref($currinststatus) eq 'HASH') {
9289: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9290: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9291: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9292: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9293: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9294: }
9295: }
9296: unless (grep(/^\Q$type\E$/,@todelete)) {
9297: my $position = $env{'form.inststatus_pos_'.$type};
9298: $position =~ s/\D+//g;
9299: $allpos[$position] = $type;
9300: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9301: $alltypes{$type} =~ s/`//g;
9302: if ($env{'form.inststatus_guest_'.$type}) {
9303: $guests{$type} = 1;
9304: }
9305: }
9306: }
9307: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9308: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9309: }
9310: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9311: $currtitles =~ s/,$//;
9312: }
9313: }
9314: if ($env{'form.addinststatus'}) {
9315: my $newtype = $env{'form.addinststatus'};
9316: $newtype =~ s/\W//g;
9317: unless (exists($alltypes{$newtype})) {
9318: if ($env{'form.addinststatus_guest'}) {
9319: $guests{$newtype} = 1;
9320: }
9321: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9322: $alltypes{$newtype} =~ s/`//g;
9323: my $position = $env{'form.addinststatus_pos'};
9324: $position =~ s/\D+//g;
9325: if ($position ne '') {
9326: $allpos[$position] = $newtype;
9327: }
9328: }
9329: }
9330: my (@orderedstatus,@orderedguests);
9331: foreach my $type (@allpos) {
9332: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9333: push(@orderedstatus,$type);
9334: if ($guests{$type}) {
9335: push(@orderedguests,$type);
9336: }
9337: }
9338: }
9339: foreach my $type (keys(%alltypes)) {
9340: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9341: delete($alltypes{$type});
9342: }
9343: }
9344: $defaults_hash{'inststatus'} = {
9345: inststatustypes => \%alltypes,
9346: inststatusorder => \@orderedstatus,
9347: inststatusguest => \@orderedguests,
9348: };
9349: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9350: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9351: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9352: }
9353: }
9354: if ($currorder ne join(',',@orderedstatus)) {
9355: $changes{'inststatus'}{'inststatusorder'} = 1;
9356: }
9357: if ($currguests ne join(',',@orderedguests)) {
9358: $changes{'inststatus'}{'inststatusguest'} = 1;
9359: }
9360: my $newtitles;
9361: foreach my $item (@orderedstatus) {
9362: $newtitles .= $alltypes{$item}.',';
9363: }
9364: $newtitles =~ s/,$//;
9365: if ($currtitles ne $newtitles) {
9366: $changes{'inststatus'}{'inststatustypes'} = 1;
9367: }
1.43 raeburn 9368: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9369: $dom);
9370: if ($putresult eq 'ok') {
9371: if (keys(%changes) > 0) {
9372: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9373: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9374: 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";
9375: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9376: if ($item eq 'inststatus') {
9377: if (ref($changes{'inststatus'}) eq 'HASH') {
9378: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9379: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9380: foreach my $type (@orderedstatus) {
9381: $resulttext .= $alltypes{$type}.', ';
9382: }
9383: $resulttext =~ s/, $//;
9384: $resulttext .= '</li>';
9385: }
9386: if ($changes{'inststatus'}{'inststatusguest'}) {
9387: $resulttext .= '<li>';
9388: if (@orderedguests) {
9389: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9390: foreach my $type (@orderedguests) {
9391: $resulttext .= $alltypes{$type}.', ';
9392: }
9393: $resulttext =~ s/, $//;
9394: } else {
9395: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9396: }
9397: $resulttext .= '</li>';
9398: }
9399: }
9400: } else {
9401: my $value = $env{'form.'.$item};
9402: if ($value eq '') {
9403: $value = &mt('none');
9404: } elsif ($item eq 'auth_def') {
9405: my %authnames = &authtype_names();
9406: my %shortauth = (
9407: internal => 'int',
9408: krb4 => 'krb4',
9409: krb5 => 'krb5',
9410: localauth => 'loc',
9411: );
9412: $value = $authnames{$shortauth{$value}};
9413: }
9414: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9415: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9416: }
9417: }
9418: $resulttext .= '</ul>';
9419: $mailmsgtext .= "\n";
9420: my $cachetime = 24*60*60;
1.72 raeburn 9421: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9422: if (ref($lastactref) eq 'HASH') {
9423: $lastactref->{'domdefaults'} = 1;
9424: }
1.68 raeburn 9425: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9426: my $notify = 1;
9427: if (ref($domconfig{'contacts'}) eq 'HASH') {
9428: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9429: $notify = 0;
9430: }
9431: }
9432: if ($notify) {
9433: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9434: "LON-CAPA Domain Settings Change - $dom",
9435: $mailmsgtext);
9436: }
1.54 raeburn 9437: }
1.43 raeburn 9438: } else {
1.54 raeburn 9439: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9440: }
9441: } else {
9442: $resulttext = '<span class="LC_error">'.
9443: &mt('An error occurred: [_1]',$putresult).'</span>';
9444: }
9445: if (@errors > 0) {
9446: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9447: foreach my $item (@errors) {
9448: $resulttext .= ' "'.$title->{$item}.'",';
9449: }
9450: $resulttext =~ s/,$//;
9451: }
9452: return $resulttext;
9453: }
9454:
1.46 raeburn 9455: sub modify_scantron {
1.205 raeburn 9456: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9457: my ($resulttext,%confhash,%changes,$errors);
9458: my $custom = 'custom.tab';
9459: my $default = 'default.tab';
9460: my $servadm = $r->dir_config('lonAdmEMail');
9461: my ($configuserok,$author_ok,$switchserver) =
9462: &config_check($dom,$confname,$servadm);
9463: if ($env{'form.scantronformat.filename'} ne '') {
9464: my $error;
9465: if ($configuserok eq 'ok') {
9466: if ($switchserver) {
1.130 raeburn 9467: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9468: } else {
9469: if ($author_ok eq 'ok') {
9470: my ($result,$scantronurl) =
9471: &publishlogo($r,'upload','scantronformat',$dom,
9472: $confname,'scantron','','',$custom);
9473: if ($result eq 'ok') {
9474: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9475: $changes{'scantronformat'} = 1;
1.46 raeburn 9476: } else {
9477: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9478: }
9479: } else {
9480: $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);
9481: }
9482: }
9483: } else {
9484: $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);
9485: }
9486: if ($error) {
9487: &Apache::lonnet::logthis($error);
9488: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9489: }
9490: }
1.48 raeburn 9491: if (ref($domconfig{'scantron'}) eq 'HASH') {
9492: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9493: if ($env{'form.scantronformat_del'}) {
9494: $confhash{'scantron'}{'scantronformat'} = '';
9495: $changes{'scantronformat'} = 1;
1.46 raeburn 9496: }
9497: }
9498: }
9499: if (keys(%confhash) > 0) {
9500: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9501: $dom);
9502: if ($putresult eq 'ok') {
9503: if (keys(%changes) > 0) {
1.48 raeburn 9504: if (ref($confhash{'scantron'}) eq 'HASH') {
9505: $resulttext = &mt('Changes made:').'<ul>';
9506: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9507: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9508: } else {
1.130 raeburn 9509: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9510: }
1.48 raeburn 9511: $resulttext .= '</ul>';
9512: } else {
1.130 raeburn 9513: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9514: }
9515: $resulttext .= '</ul>';
9516: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9517: if (ref($lastactref) eq 'HASH') {
9518: $lastactref->{'domainconfig'} = 1;
9519: }
1.46 raeburn 9520: } else {
1.130 raeburn 9521: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9522: }
9523: } else {
9524: $resulttext = '<span class="LC_error">'.
9525: &mt('An error occurred: [_1]',$putresult).'</span>';
9526: }
9527: } else {
1.130 raeburn 9528: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9529: }
9530: if ($errors) {
9531: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9532: $errors.'</ul>';
9533: }
9534: return $resulttext;
9535: }
9536:
1.48 raeburn 9537: sub modify_coursecategories {
1.239 raeburn 9538: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9539: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9540: $cathash);
1.48 raeburn 9541: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 9542: my @catitems = ('unauth','auth');
9543: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9544: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9545: $cathash = $domconfig{'coursecategories'}{'cats'};
9546: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9547: $changes{'togglecats'} = 1;
9548: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9549: }
9550: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9551: $changes{'categorize'} = 1;
9552: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9553: }
1.120 raeburn 9554: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9555: $changes{'togglecatscomm'} = 1;
9556: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9557: }
9558: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9559: $changes{'categorizecomm'} = 1;
9560: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9561: }
1.238 raeburn 9562: foreach my $item (@catitems) {
9563: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9564: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9565: $changes{$item} = 1;
9566: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9567: }
9568: }
9569: }
1.57 raeburn 9570: } else {
9571: $changes{'togglecats'} = 1;
9572: $changes{'categorize'} = 1;
1.124 raeburn 9573: $changes{'togglecatscomm'} = 1;
9574: $changes{'categorizecomm'} = 1;
1.87 raeburn 9575: $domconfig{'coursecategories'} = {
9576: togglecats => $env{'form.togglecats'},
9577: categorize => $env{'form.categorize'},
1.124 raeburn 9578: togglecatscomm => $env{'form.togglecatscomm'},
9579: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9580: };
1.238 raeburn 9581: foreach my $item (@catitems) {
9582: if ($env{'form.coursecat_'.$item} ne 'std') {
9583: $changes{$item} = 1;
9584: }
9585: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9586: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9587: }
9588: }
1.57 raeburn 9589: }
9590: if (ref($cathash) eq 'HASH') {
9591: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9592: push (@deletecategory,'instcode::0');
9593: }
1.120 raeburn 9594: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9595: push(@deletecategory,'communities::0');
9596: }
1.48 raeburn 9597: }
1.57 raeburn 9598: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9599: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9600: if (@deletecategory > 0) {
9601: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9602: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9603: foreach my $item (@deletecategory) {
1.57 raeburn 9604: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9605: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9606: $deletions{$item} = 1;
1.57 raeburn 9607: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9608: }
9609: }
9610: }
1.57 raeburn 9611: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9612: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9613: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9614: $reorderings{$item} = 1;
1.57 raeburn 9615: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9616: }
9617: if ($env{'form.addcategory_name_'.$item} ne '') {
9618: my $newcat = $env{'form.addcategory_name_'.$item};
9619: my $newdepth = $depth+1;
9620: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9621: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9622: $adds{$newitem} = 1;
9623: }
9624: if ($env{'form.subcat_'.$item} ne '') {
9625: my $newcat = $env{'form.subcat_'.$item};
9626: my $newdepth = $depth+1;
9627: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9628: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9629: $adds{$newitem} = 1;
9630: }
9631: }
9632: }
9633: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9634: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9635: my $newitem = 'instcode::0';
1.57 raeburn 9636: if ($cathash->{$newitem} eq '') {
9637: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9638: $adds{$newitem} = 1;
9639: }
9640: } else {
9641: my $newitem = 'instcode::0';
1.57 raeburn 9642: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9643: $adds{$newitem} = 1;
9644: }
9645: }
1.120 raeburn 9646: if ($env{'form.communities'} eq '1') {
9647: if (ref($cathash) eq 'HASH') {
9648: my $newitem = 'communities::0';
9649: if ($cathash->{$newitem} eq '') {
9650: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9651: $adds{$newitem} = 1;
9652: }
9653: } else {
9654: my $newitem = 'communities::0';
9655: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9656: $adds{$newitem} = 1;
9657: }
9658: }
1.48 raeburn 9659: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9660: if (($env{'form.addcategory_name'} ne 'instcode') &&
9661: ($env{'form.addcategory_name'} ne 'communities')) {
9662: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9663: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9664: $adds{$newitem} = 1;
9665: }
1.48 raeburn 9666: }
1.57 raeburn 9667: my $putresult;
1.48 raeburn 9668: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9669: if (keys(%deletions) > 0) {
9670: foreach my $key (keys(%deletions)) {
9671: if ($predelallitems{$key} ne '') {
9672: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9673: }
9674: }
9675: }
9676: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9677: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9678: if (ref($chkcats[0]) eq 'ARRAY') {
9679: my $depth = 0;
9680: my $chg = 0;
9681: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9682: my $name = $chkcats[0][$i];
9683: my $item;
9684: if ($name eq '') {
9685: $chg ++;
9686: } else {
9687: $item = &escape($name).'::0';
9688: if ($chg) {
1.57 raeburn 9689: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9690: }
9691: $depth ++;
1.57 raeburn 9692: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9693: $depth --;
9694: }
9695: }
9696: }
1.57 raeburn 9697: }
9698: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9699: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9700: if ($putresult eq 'ok') {
1.57 raeburn 9701: my %title = (
1.120 raeburn 9702: togglecats => 'Show/Hide a course in catalog',
9703: categorize => 'Assign a category to a course',
9704: togglecatscomm => 'Show/Hide a community in catalog',
9705: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9706: );
9707: my %level = (
1.120 raeburn 9708: dom => 'set in Domain ("Modify Course/Community")',
9709: crs => 'set in Course ("Course Configuration")',
9710: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 9711: none => 'No catalog',
9712: std => 'Standard catalog',
9713: domonly => 'Domain-only catalog',
9714: codesrch => 'Code search form',
1.57 raeburn 9715: );
1.48 raeburn 9716: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9717: if ($changes{'togglecats'}) {
9718: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9719: }
9720: if ($changes{'categorize'}) {
9721: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9722: }
1.120 raeburn 9723: if ($changes{'togglecatscomm'}) {
9724: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9725: }
9726: if ($changes{'categorizecomm'}) {
9727: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9728: }
1.238 raeburn 9729: if ($changes{'unauth'}) {
9730: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9731: }
9732: if ($changes{'auth'}) {
9733: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9734: }
1.57 raeburn 9735: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9736: my $cathash;
9737: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9738: $cathash = $domconfig{'coursecategories'}{'cats'};
9739: } else {
9740: $cathash = {};
9741: }
9742: my (@cats,@trails,%allitems);
9743: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9744: if (keys(%deletions) > 0) {
9745: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9746: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9747: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9748: }
9749: $resulttext .= '</ul></li>';
9750: }
9751: if (keys(%reorderings) > 0) {
9752: my %sort_by_trail;
9753: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9754: foreach my $key (keys(%reorderings)) {
9755: if ($allitems{$key} ne '') {
9756: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9757: }
1.48 raeburn 9758: }
1.57 raeburn 9759: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9760: $resulttext .= '<li>'.$trails[$trail].'</li>';
9761: }
9762: $resulttext .= '</ul></li>';
1.48 raeburn 9763: }
1.57 raeburn 9764: if (keys(%adds) > 0) {
9765: my %sort_by_trail;
9766: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9767: foreach my $key (keys(%adds)) {
9768: if ($allitems{$key} ne '') {
9769: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9770: }
9771: }
9772: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9773: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9774: }
1.57 raeburn 9775: $resulttext .= '</ul></li>';
1.48 raeburn 9776: }
9777: }
9778: $resulttext .= '</ul>';
1.239 raeburn 9779: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 9780: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9781: if ($changes{'auth'}) {
9782: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
9783: }
9784: if ($changes{'unauth'}) {
9785: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
9786: }
9787: my $cachetime = 24*60*60;
9788: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 9789: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 9790: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 9791: }
9792: }
1.48 raeburn 9793: } else {
9794: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9795: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9796: }
9797: } else {
1.120 raeburn 9798: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9799: }
9800: return $resulttext;
9801: }
9802:
1.69 raeburn 9803: sub modify_serverstatuses {
9804: my ($dom,%domconfig) = @_;
9805: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9806: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9807: %currserverstatus = %{$domconfig{'serverstatuses'}};
9808: }
9809: my @pages = &serverstatus_pages();
9810: foreach my $type (@pages) {
9811: $newserverstatus{$type}{'namedusers'} = '';
9812: $newserverstatus{$type}{'machines'} = '';
9813: if (defined($env{'form.'.$type.'_namedusers'})) {
9814: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9815: my @okusers;
9816: foreach my $user (@users) {
9817: my ($uname,$udom) = split(/:/,$user);
9818: if (($udom =~ /^$match_domain$/) &&
9819: (&Apache::lonnet::domain($udom)) &&
9820: ($uname =~ /^$match_username$/)) {
9821: if (!grep(/^\Q$user\E/,@okusers)) {
9822: push(@okusers,$user);
9823: }
9824: }
9825: }
9826: if (@okusers > 0) {
9827: @okusers = sort(@okusers);
9828: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9829: }
9830: }
9831: if (defined($env{'form.'.$type.'_machines'})) {
9832: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9833: my @okmachines;
9834: foreach my $ip (@machines) {
9835: my @parts = split(/\./,$ip);
9836: next if (@parts < 4);
9837: my $badip = 0;
9838: for (my $i=0; $i<4; $i++) {
9839: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9840: $badip = 1;
9841: last;
9842: }
9843: }
9844: if (!$badip) {
9845: push(@okmachines,$ip);
9846: }
9847: }
9848: @okmachines = sort(@okmachines);
9849: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9850: }
9851: }
9852: my %serverstatushash = (
9853: serverstatuses => \%newserverstatus,
9854: );
9855: foreach my $type (@pages) {
1.83 raeburn 9856: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9857: my (@current,@new);
1.83 raeburn 9858: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9859: if ($currserverstatus{$type}{$setting} ne '') {
9860: @current = split(/,/,$currserverstatus{$type}{$setting});
9861: }
9862: }
9863: if ($newserverstatus{$type}{$setting} ne '') {
9864: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9865: }
9866: if (@current > 0) {
9867: if (@new > 0) {
9868: foreach my $item (@current) {
9869: if (!grep(/^\Q$item\E$/,@new)) {
9870: $changes{$type}{$setting} = 1;
1.82 raeburn 9871: last;
9872: }
9873: }
1.84 raeburn 9874: foreach my $item (@new) {
9875: if (!grep(/^\Q$item\E$/,@current)) {
9876: $changes{$type}{$setting} = 1;
9877: last;
1.82 raeburn 9878: }
9879: }
9880: } else {
1.83 raeburn 9881: $changes{$type}{$setting} = 1;
1.69 raeburn 9882: }
1.83 raeburn 9883: } elsif (@new > 0) {
9884: $changes{$type}{$setting} = 1;
1.69 raeburn 9885: }
9886: }
9887: }
9888: if (keys(%changes) > 0) {
1.81 raeburn 9889: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9890: my $putresult = &Apache::lonnet::put_dom('configuration',
9891: \%serverstatushash,$dom);
9892: if ($putresult eq 'ok') {
9893: $resulttext .= &mt('Changes made:').'<ul>';
9894: foreach my $type (@pages) {
1.84 raeburn 9895: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9896: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9897: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9898: if ($newserverstatus{$type}{'namedusers'} eq '') {
9899: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9900: } else {
9901: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9902: }
1.84 raeburn 9903: }
9904: if ($changes{$type}{'machines'}) {
1.69 raeburn 9905: if ($newserverstatus{$type}{'machines'} eq '') {
9906: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9907: } else {
9908: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9909: }
9910:
9911: }
9912: $resulttext .= '</ul></li>';
9913: }
9914: }
9915: $resulttext .= '</ul>';
9916: } else {
9917: $resulttext = '<span class="LC_error">'.
9918: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9919:
9920: }
9921: } else {
9922: $resulttext = &mt('No changes made to access to server status pages');
9923: }
9924: return $resulttext;
9925: }
9926:
1.118 jms 9927: sub modify_helpsettings {
1.122 jms 9928: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9929: my ($resulttext,$errors,%changes,%helphash);
9930: my %defaultchecked = ('submitbugs' => 'on');
9931: my @offon = ('off','on');
1.118 jms 9932: my @toggles = ('submitbugs');
9933: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9934: foreach my $item (@toggles) {
1.166 raeburn 9935: if ($defaultchecked{$item} eq 'on') {
9936: if ($domconfig{'helpsettings'}{$item} eq '') {
9937: if ($env{'form.'.$item} eq '0') {
9938: $changes{$item} = 1;
9939: }
9940: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9941: $changes{$item} = 1;
9942: }
9943: } elsif ($defaultchecked{$item} eq 'off') {
9944: if ($domconfig{'helpsettings'}{$item} eq '') {
9945: if ($env{'form.'.$item} eq '1') {
9946: $changes{$item} = 1;
9947: }
9948: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9949: $changes{$item} = 1;
9950: }
9951: }
1.210 raeburn 9952: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9953: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9954: }
9955: }
1.118 jms 9956: }
1.123 jms 9957: my $putresult;
9958: if (keys(%changes) > 0) {
1.166 raeburn 9959: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9960: if ($putresult eq 'ok') {
1.166 raeburn 9961: $resulttext = &mt('Changes made:').'<ul>';
9962: foreach my $item (sort(keys(%changes))) {
9963: if ($item eq 'submitbugs') {
9964: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9965: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9966: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9967: }
9968: }
9969: $resulttext .= '</ul>';
9970: } else {
9971: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9972: $errors .= '<li><span class="LC_error">'.
9973: &mt('An error occurred storing the settings: [_1]',
9974: $putresult).'</span></li>';
1.166 raeburn 9975: }
1.118 jms 9976: }
9977: if ($errors) {
1.168 raeburn 9978: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9979: $errors.'</ul>';
9980: }
9981: return $resulttext;
9982: }
9983:
1.121 raeburn 9984: sub modify_coursedefaults {
1.212 raeburn 9985: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9986: my ($resulttext,$errors,%changes,%defaultshash);
9987: my %defaultchecked = ('canuse_pdfforms' => 'off');
9988: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9989: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9990: 'uploadquota_community','uploadquota_textbook');
9991: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9992: my %staticdefaults = (
9993: anonsurvey_threshold => 10,
9994: uploadquota => 500,
9995: );
1.121 raeburn 9996:
9997: $defaultshash{'coursedefaults'} = {};
9998:
9999: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10000: if ($domconfig{'coursedefaults'} eq '') {
10001: $domconfig{'coursedefaults'} = {};
10002: }
10003: }
10004:
10005: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10006: foreach my $item (@toggles) {
10007: if ($defaultchecked{$item} eq 'on') {
10008: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10009: ($env{'form.'.$item} eq '0')) {
10010: $changes{$item} = 1;
1.192 raeburn 10011: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10012: $changes{$item} = 1;
10013: }
10014: } elsif ($defaultchecked{$item} eq 'off') {
10015: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10016: ($env{'form.'.$item} eq '1')) {
10017: $changes{$item} = 1;
10018: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10019: $changes{$item} = 1;
10020: }
10021: }
10022: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10023: }
1.198 raeburn 10024: foreach my $item (@numbers) {
10025: my ($currdef,$newdef);
1.208 raeburn 10026: $newdef = $env{'form.'.$item};
1.198 raeburn 10027: if ($item eq 'anonsurvey_threshold') {
10028: $currdef = $domconfig{'coursedefaults'}{$item};
10029: $newdef =~ s/\D//g;
10030: if ($newdef eq '' || $newdef < 1) {
10031: $newdef = 1;
10032: }
10033: $defaultshash{'coursedefaults'}{$item} = $newdef;
10034: } else {
10035: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10036: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10037: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10038: }
10039: $newdef =~ s/[^\w.\-]//g;
10040: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10041: }
10042: if ($currdef ne $newdef) {
10043: my $staticdef;
10044: if ($item eq 'anonsurvey_threshold') {
10045: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10046: $changes{$item} = 1;
10047: }
10048: } else {
10049: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10050: $changes{'uploadquota'} = 1;
10051: }
10052: }
1.139 raeburn 10053: }
10054: }
1.231 raeburn 10055:
1.192 raeburn 10056: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 10057: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 10058: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 10059: $unofficialcreds =~ s/[^\d.]+//g;
10060: my $textbookcreds = $env{'form.textbook_credits'};
10061: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 10062: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10063: ($env{'form.coursecredits'} eq '1')) {
10064: $changes{'coursecredits'} = 1;
10065: } else {
10066: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 10067: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10068: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 10069: $changes{'coursecredits'} = 1;
10070: }
10071: }
10072: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10073: official => $officialcreds,
10074: unofficial => $unofficialcreds,
1.216 raeburn 10075: textbook => $textbookcreds,
1.192 raeburn 10076: }
1.121 raeburn 10077: }
10078: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10079: $dom);
10080: if ($putresult eq 'ok') {
10081: if (keys(%changes) > 0) {
1.213 raeburn 10082: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 10083: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 10084: ($changes{'uploadquota'})) {
1.192 raeburn 10085: if ($changes{'canuse_pdfforms'}) {
10086: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10087: }
10088: if ($changes{'coursecredits'}) {
10089: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10090: $domdefaults{'officialcredits'} =
10091: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10092: $domdefaults{'unofficialcredits'} =
10093: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 10094: $domdefaults{'textbookcredits'} =
10095: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 10096: }
10097: }
1.198 raeburn 10098: if ($changes{'uploadquota'}) {
10099: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10100: foreach my $type (@types) {
10101: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10102: }
10103: }
10104: }
1.121 raeburn 10105: my $cachetime = 24*60*60;
10106: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10107: if (ref($lastactref) eq 'HASH') {
10108: $lastactref->{'domdefaults'} = 1;
10109: }
1.121 raeburn 10110: }
10111: $resulttext = &mt('Changes made:').'<ul>';
10112: foreach my $item (sort(keys(%changes))) {
10113: if ($item eq 'canuse_pdfforms') {
10114: if ($env{'form.'.$item} eq '1') {
10115: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10116: } else {
10117: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10118: }
1.139 raeburn 10119: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 10120: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 10121: } elsif ($item eq 'uploadquota') {
10122: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10123: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10124: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10125: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 10126: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10127:
1.198 raeburn 10128: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10129: '</ul>'.
10130: '</li>';
10131: } else {
10132: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10133: }
1.192 raeburn 10134: } elsif ($item eq 'coursecredits') {
10135: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10136: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 10137: ($domdefaults{'unofficialcredits'} eq '') &&
10138: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 10139: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10140: } else {
10141: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10142: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10143: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 10144: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 10145: '</ul>'.
10146: '</li>';
10147: }
10148: } else {
10149: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10150: }
1.140 raeburn 10151: }
1.121 raeburn 10152: }
10153: $resulttext .= '</ul>';
10154: } else {
10155: $resulttext = &mt('No changes made to course defaults');
10156: }
10157: } else {
10158: $resulttext = '<span class="LC_error">'.
10159: &mt('An error occurred: [_1]',$putresult).'</span>';
10160: }
10161: return $resulttext;
10162: }
10163:
1.231 raeburn 10164: sub modify_selfenrollment {
10165: my ($dom,$lastactref,%domconfig) = @_;
10166: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10167: my @types = ('official','unofficial','community','textbook');
10168: my %titles = &tool_titles();
1.232 raeburn 10169: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10170: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 10171: $ordered{'default'} = ['types','registered','approval','limit'];
10172:
10173: my (%roles,%shown,%toplevel);
10174: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10175:
10176: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10177: if ($domconfig{'selfenrollment'} eq '') {
10178: $domconfig{'selfenrollment'} = {};
10179: }
10180: }
10181: %toplevel = (
10182: admin => 'Configuration Rights',
10183: default => 'Default settings',
10184: validation => 'Validation of self-enrollment requests',
10185: );
1.233 raeburn 10186: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10187:
10188: if (ref($ordered{'admin'}) eq 'ARRAY') {
10189: foreach my $item (@{$ordered{'admin'}}) {
10190: foreach my $type (@types) {
10191: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10192: $selfenrollhash{'admin'}{$type}{$item} = 1;
10193: } else {
10194: $selfenrollhash{'admin'}{$type}{$item} = 0;
10195: }
10196: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10197: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10198: if ($selfenrollhash{'admin'}{$type}{$item} ne
10199: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10200: push(@{$changes{'admin'}{$type}},$item);
10201: }
10202: } else {
10203: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10204: push(@{$changes{'admin'}{$type}},$item);
10205: }
10206: }
10207: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10208: push(@{$changes{'admin'}{$type}},$item);
10209: }
10210: }
10211: }
10212: }
10213:
10214: foreach my $item (@{$ordered{'default'}}) {
10215: foreach my $type (@types) {
10216: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10217: if ($item eq 'types') {
10218: unless (($value eq 'all') || ($value eq 'dom')) {
10219: $value = '';
10220: }
10221: } elsif ($item eq 'registered') {
10222: unless ($value eq '1') {
10223: $value = 0;
10224: }
10225: } elsif ($item eq 'approval') {
10226: unless ($value =~ /^[012]$/) {
10227: $value = 0;
10228: }
10229: } else {
10230: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10231: $value = 'none';
10232: }
10233: }
10234: $selfenrollhash{'default'}{$type}{$item} = $value;
10235: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10236: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10237: if ($selfenrollhash{'default'}{$type}{$item} ne
10238: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10239: push(@{$changes{'default'}{$type}},$item);
10240: }
10241: } else {
10242: push(@{$changes{'default'}{$type}},$item);
10243: }
10244: } else {
10245: push(@{$changes{'default'}{$type}},$item);
10246: }
10247: if ($item eq 'limit') {
10248: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10249: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10250: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10251: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10252: }
10253: } else {
10254: $selfenrollhash{'default'}{$type}{'cap'} = '';
10255: }
10256: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10257: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10258: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10259: push(@{$changes{'default'}{$type}},'cap');
10260: }
10261: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10262: push(@{$changes{'default'}{$type}},'cap');
10263: }
10264: }
10265: }
10266: }
10267:
10268: foreach my $item (@{$itemsref}) {
10269: if ($item eq 'fields') {
10270: my @changed;
10271: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10272: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10273: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10274: }
10275: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10276: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10277: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10278: $domconfig{'selfenrollment'}{'validation'}{$item});
10279: } else {
10280: @changed = @{$selfenrollhash{'validation'}{$item}};
10281: }
10282: } else {
10283: @changed = @{$selfenrollhash{'validation'}{$item}};
10284: }
10285: if (@changed) {
10286: if ($selfenrollhash{'validation'}{$item}) {
10287: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10288: } else {
10289: $changes{'validation'}{$item} = &mt('None');
10290: }
10291: }
10292: } else {
10293: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10294: if ($item eq 'markup') {
10295: if ($env{'form.selfenroll_validation_'.$item}) {
10296: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10297: }
10298: }
10299: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10300: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10301: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10302: }
10303: }
10304: }
10305: }
10306:
10307: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10308: $dom);
10309: if ($putresult eq 'ok') {
10310: if (keys(%changes) > 0) {
10311: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10312: $resulttext = &mt('Changes made:').'<ul>';
10313: foreach my $key ('admin','default','validation') {
10314: if (ref($changes{$key}) eq 'HASH') {
10315: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10316: if ($key eq 'validation') {
10317: foreach my $item (@{$itemsref}) {
10318: if (exists($changes{$key}{$item})) {
10319: if ($item eq 'markup') {
10320: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10321: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10322: } else {
10323: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10324: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10325: }
10326: }
10327: }
10328: } else {
10329: foreach my $type (@types) {
10330: if ($type eq 'community') {
10331: $roles{'1'} = &mt('Community personnel');
10332: } else {
10333: $roles{'1'} = &mt('Course personnel');
10334: }
10335: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10336: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10337: if ($key eq 'admin') {
10338: my @mgrdc = ();
10339: if (ref($ordered{$key}) eq 'ARRAY') {
10340: foreach my $item (@{$ordered{'admin'}}) {
10341: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10342: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10343: push(@mgrdc,$item);
10344: }
10345: }
10346: }
10347: if (@mgrdc) {
10348: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10349: } else {
10350: delete($domdefaults{$type.'selfenrolladmdc'});
10351: }
10352: }
10353: } else {
10354: if (ref($ordered{$key}) eq 'ARRAY') {
10355: foreach my $item (@{$ordered{$key}}) {
10356: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10357: $domdefaults{$type.'selfenroll'.$item} =
10358: $selfenrollhash{$key}{$type}{$item};
10359: }
10360: }
10361: }
10362: }
10363: }
1.231 raeburn 10364: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10365: foreach my $item (@{$ordered{$key}}) {
10366: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10367: $resulttext .= '<li>';
10368: if ($key eq 'admin') {
10369: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10370: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10371: } else {
10372: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10373: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10374: }
10375: $resulttext .= '</li>';
10376: }
10377: }
10378: $resulttext .= '</ul></li>';
10379: }
10380: }
10381: $resulttext .= '</ul></li>';
10382: }
10383: }
1.232 raeburn 10384: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10385: my $cachetime = 24*60*60;
10386: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10387: if (ref($lastactref) eq 'HASH') {
10388: $lastactref->{'domdefaults'} = 1;
10389: }
10390: }
1.231 raeburn 10391: }
10392: $resulttext .= '</ul>';
10393: } else {
10394: $resulttext = &mt('No changes made to self-enrollment settings');
10395: }
10396: } else {
10397: $resulttext = '<span class="LC_error">'.
10398: &mt('An error occurred: [_1]',$putresult).'</span>';
10399: }
10400: return $resulttext;
10401: }
10402:
1.137 raeburn 10403: sub modify_usersessions {
1.212 raeburn 10404: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10405: my @hostingtypes = ('version','excludedomain','includedomain');
10406: my @offloadtypes = ('primary','default');
10407: my %types = (
10408: remote => \@hostingtypes,
10409: hosted => \@hostingtypes,
10410: spares => \@offloadtypes,
10411: );
10412: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10413: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10414: my (%by_ip,%by_location,@intdoms);
10415: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10416: my @locations = sort(keys(%by_location));
1.137 raeburn 10417: my (%defaultshash,%changes);
10418: foreach my $prefix (@prefixes) {
10419: $defaultshash{'usersessions'}{$prefix} = {};
10420: }
1.212 raeburn 10421: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10422: my $resulttext;
1.138 raeburn 10423: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10424: foreach my $prefix (@prefixes) {
1.145 raeburn 10425: next if ($prefix eq 'spares');
10426: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10427: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10428: if ($type eq 'version') {
10429: my $value = $env{'form.'.$prefix.'_'.$type};
10430: my $okvalue;
10431: if ($value ne '') {
10432: if (grep(/^\Q$value\E$/,@lcversions)) {
10433: $okvalue = $value;
10434: }
10435: }
10436: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10437: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10438: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10439: if ($inuse == 0) {
10440: $changes{$prefix}{$type} = 1;
10441: } else {
10442: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10443: $changes{$prefix}{$type} = 1;
10444: }
10445: if ($okvalue ne '') {
10446: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10447: }
10448: }
10449: } else {
10450: if (($inuse == 1) && ($okvalue ne '')) {
10451: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10452: $changes{$prefix}{$type} = 1;
10453: }
10454: }
10455: } else {
10456: if (($inuse == 1) && ($okvalue ne '')) {
10457: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10458: $changes{$prefix}{$type} = 1;
10459: }
10460: }
10461: } else {
10462: if (($inuse == 1) && ($okvalue ne '')) {
10463: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10464: $changes{$prefix}{$type} = 1;
10465: }
10466: }
10467: } else {
10468: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10469: my @okvals;
10470: foreach my $val (@vals) {
1.138 raeburn 10471: if ($val =~ /:/) {
10472: my @items = split(/:/,$val);
10473: foreach my $item (@items) {
10474: if (ref($by_location{$item}) eq 'ARRAY') {
10475: push(@okvals,$item);
10476: }
10477: }
10478: } else {
10479: if (ref($by_location{$val}) eq 'ARRAY') {
10480: push(@okvals,$val);
10481: }
1.137 raeburn 10482: }
10483: }
10484: @okvals = sort(@okvals);
10485: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10486: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10487: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10488: if ($inuse == 0) {
10489: $changes{$prefix}{$type} = 1;
10490: } else {
10491: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10492: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10493: if (@changed > 0) {
10494: $changes{$prefix}{$type} = 1;
10495: }
10496: }
10497: } else {
10498: if ($inuse == 1) {
10499: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10500: $changes{$prefix}{$type} = 1;
10501: }
10502: }
10503: } else {
10504: if ($inuse == 1) {
10505: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10506: $changes{$prefix}{$type} = 1;
10507: }
10508: }
10509: } else {
10510: if ($inuse == 1) {
10511: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10512: $changes{$prefix}{$type} = 1;
10513: }
10514: }
10515: }
10516: }
10517: }
1.145 raeburn 10518:
10519: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10520: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10521: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10522: my $savespares;
10523:
10524: foreach my $lonhost (sort(keys(%servers))) {
10525: my $serverhomeID =
10526: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10527: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10528: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10529: my %spareschg;
10530: foreach my $type (@{$types{'spares'}}) {
10531: my @okspares;
10532: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10533: foreach my $server (@checked) {
1.152 raeburn 10534: if (&Apache::lonnet::hostname($server) ne '') {
10535: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10536: unless (grep(/^\Q$server\E$/,@okspares)) {
10537: push(@okspares,$server);
10538: }
1.145 raeburn 10539: }
10540: }
10541: }
10542: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10543: my $newspare;
1.152 raeburn 10544: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10545: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10546: $newspare = $new;
10547: }
10548: }
1.152 raeburn 10549: my @spares;
10550: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10551: @spares = sort(@okspares,$newspare);
10552: } else {
10553: @spares = sort(@okspares);
10554: }
10555: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10556: if (ref($spareid{$lonhost}) eq 'HASH') {
10557: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10558: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10559: if (@diffs > 0) {
10560: $spareschg{$type} = 1;
10561: }
10562: }
10563: }
10564: }
10565: if (keys(%spareschg) > 0) {
10566: $changes{'spares'}{$lonhost} = \%spareschg;
10567: }
10568: }
10569:
10570: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10571: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10572: if (ref($changes{'spares'}) eq 'HASH') {
10573: if (keys(%{$changes{'spares'}}) > 0) {
10574: $savespares = 1;
10575: }
10576: }
10577: } else {
10578: $savespares = 1;
10579: }
10580: }
10581:
1.147 raeburn 10582: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10583: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10584: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10585: $dom);
10586: if ($putresult eq 'ok') {
10587: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10588: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10589: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10590: }
10591: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10592: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10593: }
10594: }
10595: my $cachetime = 24*60*60;
10596: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10597: if (ref($lastactref) eq 'HASH') {
10598: $lastactref->{'domdefaults'} = 1;
10599: }
1.147 raeburn 10600: if (keys(%changes) > 0) {
10601: my %lt = &usersession_titles();
10602: $resulttext = &mt('Changes made:').'<ul>';
10603: foreach my $prefix (@prefixes) {
10604: if (ref($changes{$prefix}) eq 'HASH') {
10605: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10606: if ($prefix eq 'spares') {
10607: if (ref($changes{$prefix}) eq 'HASH') {
10608: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10609: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10610: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10611: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10612: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10613: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10614: foreach my $type (@{$types{$prefix}}) {
10615: if ($changes{$prefix}{$lonhost}{$type}) {
10616: my $offloadto = &mt('None');
10617: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10618: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10619: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10620: }
1.145 raeburn 10621: }
1.147 raeburn 10622: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10623: }
1.137 raeburn 10624: }
10625: }
1.147 raeburn 10626: $resulttext .= '</li>';
1.137 raeburn 10627: }
10628: }
1.147 raeburn 10629: } else {
10630: foreach my $type (@{$types{$prefix}}) {
10631: if (defined($changes{$prefix}{$type})) {
10632: my $newvalue;
10633: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10634: if (ref($defaultshash{'usersessions'}{$prefix})) {
10635: if ($type eq 'version') {
10636: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10637: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10638: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10639: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10640: }
1.145 raeburn 10641: }
10642: }
10643: }
1.147 raeburn 10644: if ($newvalue eq '') {
10645: if ($type eq 'version') {
10646: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10647: } else {
10648: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10649: }
1.145 raeburn 10650: } else {
1.147 raeburn 10651: if ($type eq 'version') {
10652: $newvalue .= ' '.&mt('(or later)');
10653: }
10654: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10655: }
1.137 raeburn 10656: }
10657: }
10658: }
1.147 raeburn 10659: $resulttext .= '</ul>';
1.137 raeburn 10660: }
10661: }
1.147 raeburn 10662: $resulttext .= '</ul>';
10663: } else {
10664: $resulttext = $nochgmsg;
1.137 raeburn 10665: }
10666: } else {
10667: $resulttext = '<span class="LC_error">'.
10668: &mt('An error occurred: [_1]',$putresult).'</span>';
10669: }
10670: } else {
1.147 raeburn 10671: $resulttext = $nochgmsg;
1.137 raeburn 10672: }
10673: return $resulttext;
10674: }
10675:
1.150 raeburn 10676: sub modify_loadbalancing {
10677: my ($dom,%domconfig) = @_;
10678: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10679: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10680: my ($othertitle,$usertypes,$types) =
10681: &Apache::loncommon::sorted_inst_types($dom);
10682: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10683: my @sparestypes = ('primary','default');
10684: my %typetitles = &sparestype_titles();
10685: my $resulttext;
1.171 raeburn 10686: my (%currbalancer,%currtargets,%currrules,%existing);
10687: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10688: %existing = %{$domconfig{'loadbalancing'}};
10689: }
10690: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10691: \%currtargets,\%currrules);
10692: my ($saveloadbalancing,%defaultshash,%changes);
10693: my ($alltypes,$othertypes,$titles) =
10694: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10695: my %ruletitles = &offloadtype_text();
10696: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10697: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10698: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10699: if ($balancer eq '') {
10700: next;
10701: }
1.210 raeburn 10702: if (!exists($servers{$balancer})) {
1.171 raeburn 10703: if (exists($currbalancer{$balancer})) {
10704: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10705: }
1.171 raeburn 10706: next;
10707: }
10708: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10709: push(@{$changes{'delete'}},$balancer);
10710: next;
10711: }
10712: if (!exists($currbalancer{$balancer})) {
10713: push(@{$changes{'add'}},$balancer);
10714: }
10715: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10716: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10717: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10718: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10719: $saveloadbalancing = 1;
10720: }
10721: foreach my $sparetype (@sparestypes) {
10722: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10723: my @offloadto;
10724: foreach my $target (@targets) {
10725: if (($servers{$target}) && ($target ne $balancer)) {
10726: if ($sparetype eq 'default') {
10727: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10728: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10729: }
10730: }
1.171 raeburn 10731: unless(grep(/^\Q$target\E$/,@offloadto)) {
10732: push(@offloadto,$target);
10733: }
1.150 raeburn 10734: }
1.171 raeburn 10735: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10736: }
10737: }
1.171 raeburn 10738: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10739: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10740: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10741: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10742: if (@targetdiffs > 0) {
1.171 raeburn 10743: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10744: }
1.171 raeburn 10745: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10746: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10747: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10748: }
10749: }
10750: }
10751: } else {
1.171 raeburn 10752: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10753: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10754: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10755: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10756: $changes{'curr'}{$balancer}{'targets'} = 1;
10757: }
1.150 raeburn 10758: }
10759: }
1.210 raeburn 10760: }
1.150 raeburn 10761: }
10762: my $ishomedom;
1.171 raeburn 10763: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10764: $ishomedom = 1;
1.150 raeburn 10765: }
10766: if (ref($alltypes) eq 'ARRAY') {
10767: foreach my $type (@{$alltypes}) {
10768: my $rule;
1.210 raeburn 10769: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10770: (!$ishomedom)) {
1.171 raeburn 10771: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10772: }
10773: if ($rule eq 'specific') {
10774: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10775: }
1.171 raeburn 10776: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10777: if (ref($currrules{$balancer}) eq 'HASH') {
10778: if ($rule ne $currrules{$balancer}{$type}) {
10779: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10780: }
10781: } elsif ($rule ne '') {
1.171 raeburn 10782: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10783: }
10784: }
10785: }
1.171 raeburn 10786: }
10787: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10788: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10789: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10790: $defaultshash{'loadbalancing'} = {};
10791: }
10792: my $putresult = &Apache::lonnet::put_dom('configuration',
10793: \%defaultshash,$dom);
10794: if ($putresult eq 'ok') {
10795: if (keys(%changes) > 0) {
1.252 ! raeburn 10796: my %toupdate;
1.171 raeburn 10797: if (ref($changes{'delete'}) eq 'ARRAY') {
10798: foreach my $balancer (sort(@{$changes{'delete'}})) {
10799: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 ! raeburn 10800: $toupdate{$balancer} = 1;
1.150 raeburn 10801: }
1.171 raeburn 10802: }
10803: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10804: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10805: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 ! raeburn 10806: $toupdate{$balancer} = 1;
1.171 raeburn 10807: }
10808: }
10809: if (ref($changes{'curr'}) eq 'HASH') {
10810: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10811: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10812: if ($changes{'curr'}{$balancer}{'targets'}) {
10813: my %offloadstr;
10814: foreach my $sparetype (@sparestypes) {
10815: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10816: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10817: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10818: }
10819: }
1.150 raeburn 10820: }
1.171 raeburn 10821: if (keys(%offloadstr) == 0) {
10822: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10823: } else {
1.171 raeburn 10824: my $showoffload;
10825: foreach my $sparetype (@sparestypes) {
10826: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10827: if (defined($offloadstr{$sparetype})) {
10828: $showoffload .= $offloadstr{$sparetype};
10829: } else {
10830: $showoffload .= &mt('None');
10831: }
10832: $showoffload .= (' 'x3);
10833: }
10834: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10835: }
10836: }
10837: }
1.171 raeburn 10838: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10839: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10840: foreach my $type (@{$alltypes}) {
10841: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10842: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10843: my $balancetext;
10844: if ($rule eq '') {
10845: $balancetext = $ruletitles{'default'};
1.209 raeburn 10846: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10847: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 10848: $balancetext = $ruletitles{$rule};
1.252 ! raeburn 10849: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
! 10850: foreach my $sparetype (@sparestypes) {
! 10851: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
! 10852: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
! 10853: }
! 10854: }
! 10855: }
1.171 raeburn 10856: } else {
10857: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10858: }
1.210 raeburn 10859: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10860: }
10861: }
10862: }
10863: }
1.252 ! raeburn 10864: if (keys(%toupdate)) {
! 10865: my %thismachine;
! 10866: my $updatedhere;
! 10867: my $cachetime = 60*60*24;
! 10868: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
! 10869: foreach my $lonhost (keys(%toupdate)) {
! 10870: if ($thismachine{$lonhost}) {
! 10871: unless ($updatedhere) {
! 10872: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
! 10873: $defaultshash{'loadbalancing'},
! 10874: $cachetime);
! 10875: $updatedhere = 1;
! 10876: }
! 10877: } else {
! 10878: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
! 10879: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
! 10880: }
! 10881: }
! 10882: }
1.150 raeburn 10883: }
1.171 raeburn 10884: }
10885: if ($resulttext ne '') {
10886: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10887: } else {
10888: $resulttext = $nochgmsg;
10889: }
10890: } else {
1.171 raeburn 10891: $resulttext = $nochgmsg;
1.150 raeburn 10892: }
10893: } else {
1.171 raeburn 10894: $resulttext = '<span class="LC_error">'.
10895: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10896: }
10897: } else {
1.171 raeburn 10898: $resulttext = $nochgmsg;
1.150 raeburn 10899: }
10900: return $resulttext;
10901: }
10902:
1.48 raeburn 10903: sub recurse_check {
10904: my ($chkcats,$categories,$depth,$name) = @_;
10905: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10906: my $chg = 0;
10907: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10908: my $category = $chkcats->[$depth]{$name}[$j];
10909: my $item;
10910: if ($category eq '') {
10911: $chg ++;
10912: } else {
10913: my $deeper = $depth + 1;
10914: $item = &escape($category).':'.&escape($name).':'.$depth;
10915: if ($chg) {
10916: $categories->{$item} -= $chg;
10917: }
10918: &recurse_check($chkcats,$categories,$deeper,$category);
10919: $deeper --;
10920: }
10921: }
10922: }
10923: return;
10924: }
10925:
10926: sub recurse_cat_deletes {
10927: my ($item,$coursecategories,$deletions) = @_;
10928: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10929: my $subdepth = $depth + 1;
10930: if (ref($coursecategories) eq 'HASH') {
10931: foreach my $subitem (keys(%{$coursecategories})) {
10932: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10933: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10934: delete($coursecategories->{$subitem});
10935: $deletions->{$subitem} = 1;
10936: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10937: }
1.48 raeburn 10938: }
10939: }
10940: return;
10941: }
10942:
1.125 raeburn 10943: sub get_active_dcs {
10944: my ($dom) = @_;
1.191 raeburn 10945: my $now = time;
10946: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10947: my %domcoords;
10948: my $numdcs = 0;
10949: foreach my $server (keys(%dompersonnel)) {
10950: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10951: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10952: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10953: }
10954: }
10955: return %domcoords;
10956: }
10957:
10958: sub active_dc_picker {
1.191 raeburn 10959: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 10960: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10961: my @domcoord = keys(%domcoords);
10962: if (keys(%currhash)) {
10963: foreach my $dc (keys(%currhash)) {
10964: unless (exists($domcoords{$dc})) {
10965: push(@domcoord,$dc);
10966: }
10967: }
10968: }
10969: @domcoord = sort(@domcoord);
1.210 raeburn 10970: my $numdcs = scalar(@domcoord);
1.191 raeburn 10971: my $rows = 0;
10972: my $table;
1.125 raeburn 10973: if ($numdcs > 1) {
1.191 raeburn 10974: $table = '<table>';
10975: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10976: my $rem = $i%($numinrow);
10977: if ($rem == 0) {
10978: if ($i > 0) {
1.191 raeburn 10979: $table .= '</tr>';
1.125 raeburn 10980: }
1.191 raeburn 10981: $table .= '<tr>';
10982: $rows ++;
1.125 raeburn 10983: }
1.191 raeburn 10984: my $check = '';
10985: if ($inputtype eq 'radio') {
10986: if (keys(%currhash) == 0) {
10987: if (!$i) {
10988: $check = ' checked="checked"';
10989: }
10990: } elsif (exists($currhash{$domcoord[$i]})) {
10991: $check = ' checked="checked"';
10992: }
10993: } else {
10994: if (exists($currhash{$domcoord[$i]})) {
10995: $check = ' checked="checked"';
1.125 raeburn 10996: }
10997: }
1.191 raeburn 10998: if ($i == @domcoord - 1) {
1.125 raeburn 10999: my $colsleft = $numinrow - $rem;
11000: if ($colsleft > 1) {
1.191 raeburn 11001: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11002: } else {
1.191 raeburn 11003: $table .= '<td class="LC_left_item">';
1.125 raeburn 11004: }
11005: } else {
1.191 raeburn 11006: $table .= '<td class="LC_left_item">';
11007: }
11008: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11009: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11010: $table .= '<span class="LC_nobreak"><label>'.
11011: '<input type="'.$inputtype.'" name="'.$name.'"'.
11012: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11013: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 11014: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 11015: }
1.219 raeburn 11016: $table .= '</label></span></td>';
1.191 raeburn 11017: }
11018: $table .= '</tr></table>';
11019: } elsif ($numdcs == 1) {
1.219 raeburn 11020: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11021: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 11022: if ($inputtype eq 'radio') {
1.247 raeburn 11023: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 11024: if ($user ne $dcname.':'.$dcdom) {
11025: $table .= ' ('.$dcname.':'.$dcdom.')';
11026: }
1.191 raeburn 11027: } else {
11028: my $check;
11029: if (exists($currhash{$domcoord[0]})) {
11030: $check = ' checked="checked"';
1.125 raeburn 11031: }
1.247 raeburn 11032: $table = '<span class="LC_nobreak"><label>'.
11033: '<input type="checkbox" name="'.$name.'" '.
11034: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 11035: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 11036: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 11037: }
1.220 raeburn 11038: $table .= '</label></span>';
1.191 raeburn 11039: $rows ++;
1.125 raeburn 11040: }
11041: }
1.191 raeburn 11042: return ($numdcs,$table,$rows);
1.125 raeburn 11043: }
11044:
1.137 raeburn 11045: sub usersession_titles {
11046: return &Apache::lonlocal::texthash(
11047: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11048: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11049: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11050: version => 'LON-CAPA version requirement',
1.138 raeburn 11051: excludedomain => 'Allow all, but exclude specific domains',
11052: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11053: primary => 'Primary (checked first)',
1.154 raeburn 11054: default => 'Default',
1.137 raeburn 11055: );
11056: }
11057:
1.152 raeburn 11058: sub id_for_thisdom {
11059: my (%servers) = @_;
11060: my %altids;
11061: foreach my $server (keys(%servers)) {
11062: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11063: if ($serverhome ne $server) {
11064: $altids{$serverhome} = $server;
11065: }
11066: }
11067: return %altids;
11068: }
11069:
1.150 raeburn 11070: sub count_servers {
11071: my ($currbalancer,%servers) = @_;
11072: my (@spares,$numspares);
11073: foreach my $lonhost (sort(keys(%servers))) {
11074: next if ($currbalancer eq $lonhost);
11075: push(@spares,$lonhost);
11076: }
11077: if ($currbalancer) {
11078: $numspares = scalar(@spares);
11079: } else {
11080: $numspares = scalar(@spares) - 1;
11081: }
11082: return ($numspares,@spares);
11083: }
11084:
11085: sub lonbalance_targets_js {
1.171 raeburn 11086: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11087: my $select = &mt('Select');
11088: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11089: if (ref($servers) eq 'HASH') {
11090: $alltargets = join("','",sort(keys(%{$servers})));
11091: my @homedoms;
11092: foreach my $server (sort(keys(%{$servers}))) {
11093: if (&Apache::lonnet::host_domain($server) eq $dom) {
11094: push(@homedoms,'1');
11095: } else {
11096: push(@homedoms,'0');
11097: }
11098: }
11099: $allishome = join("','",@homedoms);
11100: }
11101: if (ref($types) eq 'ARRAY') {
11102: if (@{$types} > 0) {
11103: @alltypes = @{$types};
11104: }
11105: }
11106: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11107: $allinsttypes = join("','",@alltypes);
1.171 raeburn 11108: my (%currbalancer,%currtargets,%currrules,%existing);
11109: if (ref($settings) eq 'HASH') {
11110: %existing = %{$settings};
11111: }
11112: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11113: \%currtargets,\%currrules);
1.210 raeburn 11114: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11115: return <<"END";
11116:
11117: <script type="text/javascript">
11118: // <![CDATA[
11119:
1.171 raeburn 11120: currBalancers = new Array('$balancers');
11121:
11122: function toggleTargets(balnum) {
11123: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11124: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11125: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11126: var prevbalancer = prevhostitem.value;
11127: var baltotal = document.getElementById('loadbalancing_total').value;
11128: prevhostitem.value = balancer;
11129: if (prevbalancer != '') {
11130: var prevIdx = currBalancers.indexOf(prevbalancer);
11131: if (prevIdx != -1) {
11132: currBalancers.splice(prevIdx,1);
11133: }
11134: }
1.150 raeburn 11135: if (balancer == '') {
1.171 raeburn 11136: hideSpares(balnum);
1.150 raeburn 11137: } else {
1.171 raeburn 11138: var currIdx = currBalancers.indexOf(balancer);
11139: if (currIdx == -1) {
11140: currBalancers.push(balancer);
11141: }
1.150 raeburn 11142: var homedoms = new Array('$allishome');
1.171 raeburn 11143: var ishomedom = homedoms[lonhostitem.selectedIndex];
11144: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11145: }
1.171 raeburn 11146: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11147: return;
11148: }
11149:
1.171 raeburn 11150: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11151: var alltargets = new Array('$alltargets');
11152: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11153: var offloadtypes = new Array('primary','default');
11154:
1.171 raeburn 11155: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11156: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11157:
1.151 raeburn 11158: for (var i=0; i<offloadtypes.length; i++) {
11159: var count = 0;
11160: for (var j=0; j<alltargets.length; j++) {
11161: if (alltargets[j] != balancer) {
1.171 raeburn 11162: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11163: item.value = alltargets[j];
11164: item.style.textAlign='left';
11165: item.style.textFace='normal';
11166: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11167: if (currBalancers.indexOf(alltargets[j]) == -1) {
11168: item.disabled = '';
11169: } else {
11170: item.disabled = 'disabled';
11171: item.checked = false;
11172: }
1.151 raeburn 11173: count ++;
11174: }
1.150 raeburn 11175: }
11176: }
1.151 raeburn 11177: for (var k=0; k<insttypes.length; k++) {
11178: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11179: if (ishomedom == 1) {
1.171 raeburn 11180: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11181: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11182: } else {
1.171 raeburn 11183: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11184: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11185: }
11186: } else {
1.171 raeburn 11187: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11188: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11189: }
1.151 raeburn 11190: if ((insttypes[k] != '_LC_external') &&
11191: ((insttypes[k] != '_LC_internetdom') ||
11192: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 11193: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11194: item.options.length = 0;
11195: item.options[0] = new Option("","",true,true);
1.210 raeburn 11196: var idx = 0;
1.151 raeburn 11197: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 11198: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11199: idx ++;
11200: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11201: }
11202: }
11203: }
11204: }
11205: return;
11206: }
11207:
1.171 raeburn 11208: function hideSpares(balnum) {
1.150 raeburn 11209: var alltargets = new Array('$alltargets');
11210: var insttypes = new Array('$allinsttypes');
11211: var offloadtypes = new Array('primary','default');
11212:
1.171 raeburn 11213: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11214: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11215:
11216: var total = alltargets.length - 1;
11217: for (var i=0; i<offloadtypes; i++) {
11218: for (var j=0; j<total; j++) {
1.171 raeburn 11219: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11220: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11221: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11222: }
1.150 raeburn 11223: }
11224: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11225: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11226: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11227: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11228: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11229: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11230: }
11231: }
11232: return;
11233: }
11234:
1.171 raeburn 11235: function checkOffloads(item,balnum,type) {
1.150 raeburn 11236: var alltargets = new Array('$alltargets');
11237: var offloadtypes = new Array('primary','default');
11238: if (item.checked) {
11239: var total = alltargets.length - 1;
11240: var other;
11241: if (type == offloadtypes[0]) {
1.151 raeburn 11242: other = offloadtypes[1];
1.150 raeburn 11243: } else {
1.151 raeburn 11244: other = offloadtypes[0];
1.150 raeburn 11245: }
11246: for (var i=0; i<total; i++) {
1.171 raeburn 11247: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11248: if (server == item.value) {
1.171 raeburn 11249: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11250: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11251: }
11252: }
11253: }
11254: }
11255: return;
11256: }
11257:
1.171 raeburn 11258: function singleServerToggle(balnum,type) {
11259: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11260: if (offloadtoSelIdx == 0) {
1.171 raeburn 11261: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11262: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11263:
11264: } else {
1.171 raeburn 11265: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11266: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11267: }
11268: return;
11269: }
11270:
1.171 raeburn 11271: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11272: if (type == '_LC_external') {
1.171 raeburn 11273: return;
1.150 raeburn 11274: }
1.171 raeburn 11275: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11276: for (var i=0; i<typesRules.length; i++) {
11277: if (formname.elements[typesRules[i]].checked) {
11278: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11279: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11280: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11281: } else {
1.171 raeburn 11282: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11283: }
11284: }
11285: }
11286: return;
11287: }
11288:
11289: function balancerDeleteChange(balnum) {
11290: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11291: var baltotal = document.getElementById('loadbalancing_total').value;
11292: var addtarget;
11293: var removetarget;
11294: var action = 'delete';
11295: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11296: var lonhost = hostitem.value;
11297: var currIdx = currBalancers.indexOf(lonhost);
11298: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11299: if (currIdx != -1) {
11300: currBalancers.splice(currIdx,1);
11301: }
11302: addtarget = lonhost;
11303: } else {
11304: if (currIdx == -1) {
11305: currBalancers.push(lonhost);
11306: }
11307: removetarget = lonhost;
11308: action = 'undelete';
11309: }
11310: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11311: }
11312: return;
11313: }
11314:
11315: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11316: if (baltotal > 1) {
11317: var offloadtypes = new Array('primary','default');
11318: var alltargets = new Array('$alltargets');
11319: var insttypes = new Array('$allinsttypes');
11320: for (var i=0; i<baltotal; i++) {
11321: if (i != balnum) {
11322: for (var j=0; j<offloadtypes.length; j++) {
11323: var total = alltargets.length - 1;
11324: for (var k=0; k<total; k++) {
11325: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11326: var server = serveritem.value;
11327: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11328: if (server == addtarget) {
11329: serveritem.disabled = '';
11330: }
11331: }
11332: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11333: if (server == removetarget) {
11334: serveritem.disabled = 'disabled';
11335: serveritem.checked = false;
11336: }
11337: }
11338: }
11339: }
11340: for (var j=0; j<insttypes.length; j++) {
11341: if (insttypes[j] != '_LC_external') {
11342: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11343: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11344: var currSel = singleserver.selectedIndex;
11345: var currVal = singleserver.options[currSel].value;
11346: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11347: var numoptions = singleserver.options.length;
11348: var needsnew = 1;
11349: for (var k=0; k<numoptions; k++) {
11350: if (singleserver.options[k] == addtarget) {
11351: needsnew = 0;
11352: break;
11353: }
11354: }
11355: if (needsnew == 1) {
11356: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11357: }
11358: }
11359: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11360: singleserver.options.length = 0;
11361: if ((currVal) && (currVal != removetarget)) {
11362: singleserver.options[0] = new Option("","",false,false);
11363: } else {
11364: singleserver.options[0] = new Option("","",true,true);
11365: }
11366: var idx = 0;
11367: for (var m=0; m<alltargets.length; m++) {
11368: if (currBalancers.indexOf(alltargets[m]) == -1) {
11369: idx ++;
11370: if (currVal == alltargets[m]) {
11371: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11372: } else {
11373: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11374: }
11375: }
11376: }
11377: }
11378: }
11379: }
11380: }
1.150 raeburn 11381: }
11382: }
11383: }
11384: return;
11385: }
11386:
1.152 raeburn 11387: // ]]>
11388: </script>
11389:
11390: END
11391: }
11392:
11393: sub new_spares_js {
11394: my @sparestypes = ('primary','default');
11395: my $types = join("','",@sparestypes);
11396: my $select = &mt('Select');
11397: return <<"END";
11398:
11399: <script type="text/javascript">
11400: // <![CDATA[
11401:
11402: function updateNewSpares(formname,lonhost) {
11403: var types = new Array('$types');
11404: var include = new Array();
11405: var exclude = new Array();
11406: for (var i=0; i<types.length; i++) {
11407: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11408: for (var j=0; j<spareboxes.length; j++) {
11409: if (formname.elements[spareboxes[j]].checked) {
11410: exclude.push(formname.elements[spareboxes[j]].value);
11411: } else {
11412: include.push(formname.elements[spareboxes[j]].value);
11413: }
11414: }
11415: }
11416: for (var i=0; i<types.length; i++) {
11417: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11418: var selIdx = newSpare.selectedIndex;
11419: var currnew = newSpare.options[selIdx].value;
11420: var okSpares = new Array();
11421: for (var j=0; j<newSpare.options.length; j++) {
11422: var possible = newSpare.options[j].value;
11423: if (possible != '') {
11424: if (exclude.indexOf(possible) == -1) {
11425: okSpares.push(possible);
11426: } else {
11427: if (currnew == possible) {
11428: selIdx = 0;
11429: }
11430: }
11431: }
11432: }
11433: for (var k=0; k<include.length; k++) {
11434: if (okSpares.indexOf(include[k]) == -1) {
11435: okSpares.push(include[k]);
11436: }
11437: }
11438: okSpares.sort();
11439: newSpare.options.length = 0;
11440: if (selIdx == 0) {
11441: newSpare.options[0] = new Option("$select","",true,true);
11442: } else {
11443: newSpare.options[0] = new Option("$select","",false,false);
11444: }
11445: for (var m=0; m<okSpares.length; m++) {
11446: var idx = m+1;
11447: var selThis = 0;
11448: if (selIdx != 0) {
11449: if (okSpares[m] == currnew) {
11450: selThis = 1;
11451: }
11452: }
11453: if (selThis == 1) {
11454: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11455: } else {
11456: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11457: }
11458: }
11459: }
11460: return;
11461: }
11462:
11463: function checkNewSpares(lonhost,type) {
11464: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11465: var chosen = newSpare.options[newSpare.selectedIndex].value;
11466: if (chosen != '') {
11467: var othertype;
11468: var othernewSpare;
11469: if (type == 'primary') {
11470: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11471: }
11472: if (type == 'default') {
11473: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11474: }
11475: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11476: othernewSpare.selectedIndex = 0;
11477: }
11478: }
11479: return;
11480: }
11481:
11482: // ]]>
11483: </script>
11484:
11485: END
11486:
11487: }
11488:
11489: sub common_domprefs_js {
11490: return <<"END";
11491:
11492: <script type="text/javascript">
11493: // <![CDATA[
11494:
1.150 raeburn 11495: function getIndicesByName(formname,item) {
1.152 raeburn 11496: var group = new Array();
1.150 raeburn 11497: for (var i=0;i<formname.elements.length;i++) {
11498: if (formname.elements[i].name == item) {
1.152 raeburn 11499: group.push(formname.elements[i].id);
1.150 raeburn 11500: }
11501: }
1.152 raeburn 11502: return group;
1.150 raeburn 11503: }
11504:
11505: // ]]>
11506: </script>
11507:
11508: END
1.152 raeburn 11509:
1.150 raeburn 11510: }
11511:
1.165 raeburn 11512: sub recaptcha_js {
11513: my %lt = &captcha_phrases();
11514: return <<"END";
11515:
11516: <script type="text/javascript">
11517: // <![CDATA[
11518:
11519: function updateCaptcha(caller,context) {
11520: var privitem;
11521: var pubitem;
11522: var privtext;
11523: var pubtext;
11524: if (document.getElementById(context+'_recaptchapub')) {
11525: pubitem = document.getElementById(context+'_recaptchapub');
11526: } else {
11527: return;
11528: }
11529: if (document.getElementById(context+'_recaptchapriv')) {
11530: privitem = document.getElementById(context+'_recaptchapriv');
11531: } else {
11532: return;
11533: }
11534: if (document.getElementById(context+'_recaptchapubtxt')) {
11535: pubtext = document.getElementById(context+'_recaptchapubtxt');
11536: } else {
11537: return;
11538: }
11539: if (document.getElementById(context+'_recaptchaprivtxt')) {
11540: privtext = document.getElementById(context+'_recaptchaprivtxt');
11541: } else {
11542: return;
11543: }
11544: if (caller.checked) {
11545: if (caller.value == 'recaptcha') {
11546: pubitem.type = 'text';
11547: privitem.type = 'text';
11548: pubitem.size = '40';
11549: privitem.size = '40';
11550: pubtext.innerHTML = "$lt{'pub'}";
11551: privtext.innerHTML = "$lt{'priv'}";
11552: } else {
11553: pubitem.type = 'hidden';
11554: privitem.type = 'hidden';
11555: pubtext.innerHTML = '';
11556: privtext.innerHTML = '';
11557: }
11558: }
11559: return;
11560: }
11561:
11562: // ]]>
11563: </script>
11564:
11565: END
11566:
11567: }
11568:
1.236 raeburn 11569: sub toggle_display_js {
1.192 raeburn 11570: return <<"END";
11571:
11572: <script type="text/javascript">
11573: // <![CDATA[
11574:
1.236 raeburn 11575: function toggleDisplay(domForm,caller) {
11576: if (document.getElementById(caller)) {
11577: var divitem = document.getElementById(caller);
11578: var optionsElement = domForm.coursecredits;
11579: if (caller == 'emailoptions') {
11580: optionsElement = domForm.cancreate_email;
11581: }
11582: if (optionsElement.length) {
1.192 raeburn 11583: var currval;
1.236 raeburn 11584: for (var i=0; i<optionsElement.length; i++) {
11585: if (optionsElement[i].checked) {
11586: currval = optionsElement[i].value;
1.192 raeburn 11587: }
11588: }
11589: if (currval == 1) {
1.236 raeburn 11590: divitem.style.display = 'block';
1.192 raeburn 11591: } else {
1.236 raeburn 11592: divitem.style.display = 'none';
1.192 raeburn 11593: }
11594: }
11595: }
11596: return;
11597: }
11598:
11599: // ]]>
11600: </script>
11601:
11602: END
11603:
11604: }
11605:
1.165 raeburn 11606: sub captcha_phrases {
11607: return &Apache::lonlocal::texthash (
11608: priv => 'Private key',
11609: pub => 'Public key',
11610: original => 'original (CAPTCHA)',
11611: recaptcha => 'successor (ReCAPTCHA)',
11612: notused => 'unused',
11613: );
11614: }
11615:
1.205 raeburn 11616: sub devalidate_remote_domconfs {
1.212 raeburn 11617: my ($dom,$cachekeys) = @_;
11618: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 11619: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11620: my %thismachine;
11621: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 11622: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 11623: if (keys(%servers) > 1) {
11624: foreach my $server (keys(%servers)) {
11625: next if ($thismachine{$server});
1.212 raeburn 11626: my @cached;
11627: foreach my $name (@posscached) {
11628: if ($cachekeys->{$name}) {
11629: push(@cached,&escape($name).':'.&escape($dom));
11630: }
11631: }
11632: if (@cached) {
11633: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11634: }
1.205 raeburn 11635: }
11636: }
11637: return;
11638: }
11639:
1.3 raeburn 11640: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>