Annotation of loncom/interface/domainprefs.pm, revision 1.243
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.243 ! raeburn 4: # $Id: domainprefs.pm,v 1.242 2014/05/09 15:02:31 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.216 raeburn 765: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
766: &print_studentcode($settings,\$rowtotal).'
767: </table>
768: </td>
769: </tr>
770: <tr>
771: <td>
772: <table class="LC_nested">
773: <tr class="LC_info_row">
774: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
775: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 776: &textbookcourses_javascript($settings).
777: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
778: </table>
779: </td>
780: </tr>
781: <tr>
782: <td>
783: <table class="LC_nested">
784: <tr class="LC_info_row">
785: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
786: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
787: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 788: </table>
789: </td>
790: </tr>
791: <tr>
792: <td>
793: <table class="LC_nested">
794: <tr class="LC_info_row">
1.242 raeburn 795: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
796: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 797: </tr>'.
798: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 799: } elsif ($action eq 'requestauthor') {
800: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 801: } elsif ($action eq 'rolecolors') {
1.30 raeburn 802: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 803: </table>
804: </td>
805: </tr>
806: <tr>
807: <td>
808: <table class="LC_nested">
809: <tr class="LC_info_row">
1.69 raeburn 810: <td class="LC_left_item"'.$colspan.' valign="top">'.
811: &mt($item->{'header'}->[2]->{'col1'}).'</td>
812: <td class="LC_right_item" valign="top">'.
813: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 814: </tr>'.
1.30 raeburn 815: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 816: </table>
817: </td>
818: </tr>
819: <tr>
820: <td>
821: <table class="LC_nested">
822: <tr class="LC_info_row">
1.59 bisitz 823: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
824: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 825: </tr>'.
1.30 raeburn 826: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
827: $rowtotal += 2;
1.6 raeburn 828: }
1.3 raeburn 829: } else {
1.30 raeburn 830: $output .= '
1.3 raeburn 831: <tr>
832: <td>
833: <table class="LC_nested">
1.30 raeburn 834: <tr class="LC_info_row">';
1.24 raeburn 835: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 836: $output .= '
1.59 bisitz 837: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 838: } elsif ($action eq 'serverstatuses') {
839: $output .= '
840: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
841: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
842:
1.6 raeburn 843: } else {
1.30 raeburn 844: $output .= '
1.69 raeburn 845: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
846: }
1.72 raeburn 847: if (defined($item->{'header'}->[0]->{'col3'})) {
848: $output .= '<td class="LC_left_item" valign="top">'.
849: &mt($item->{'header'}->[0]->{'col2'});
850: if ($action eq 'serverstatuses') {
851: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
852: }
1.69 raeburn 853: } else {
854: $output .= '<td class="LC_right_item" valign="top">'.
855: &mt($item->{'header'}->[0]->{'col2'});
856: }
857: $output .= '</td>';
858: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 859: if (defined($item->{'header'}->[0]->{'col4'})) {
860: $output .= '<td class="LC_left_item" valign="top">'.
861: &mt($item->{'header'}->[0]->{'col3'});
862: } else {
863: $output .= '<td class="LC_right_item" valign="top">'.
864: &mt($item->{'header'}->[0]->{'col3'});
865: }
1.69 raeburn 866: if ($action eq 'serverstatuses') {
867: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
868: }
869: $output .= '</td>';
1.6 raeburn 870: }
1.150 raeburn 871: if ($item->{'header'}->[0]->{'col4'}) {
872: $output .= '<td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col4'});
874: }
1.69 raeburn 875: $output .= '</tr>';
1.48 raeburn 876: $rowtotal ++;
1.168 raeburn 877: if ($action eq 'quotas') {
1.86 raeburn 878: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 879: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.236 raeburn 880: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.230 raeburn 881: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 882: } elsif ($action eq 'scantron') {
883: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 884: } elsif ($action eq 'helpsettings') {
1.168 raeburn 885: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 886: }
1.3 raeburn 887: }
1.30 raeburn 888: $output .= '
1.3 raeburn 889: </table>
890: </td>
891: </tr>
1.30 raeburn 892: </table><br />';
893: return ($output,$rowtotal);
1.1 raeburn 894: }
895:
1.3 raeburn 896: sub print_login {
1.168 raeburn 897: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 898: my ($css_class,$datatable);
1.6 raeburn 899: my %choices = &login_choices();
1.110 raeburn 900:
1.168 raeburn 901: if ($caller eq 'service') {
1.149 raeburn 902: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 903: my $choice = $choices{'disallowlogin'};
904: $css_class = ' class="LC_odd_row"';
1.128 raeburn 905: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 906: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 907: '<th>'.$choices{'server'}.'</th>'.
908: '<th>'.$choices{'serverpath'}.'</th>'.
909: '<th>'.$choices{'custompath'}.'</th>'.
910: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 911: my %disallowed;
912: if (ref($settings) eq 'HASH') {
913: if (ref($settings->{'loginvia'}) eq 'HASH') {
914: %disallowed = %{$settings->{'loginvia'}};
915: }
916: }
917: foreach my $lonhost (sort(keys(%servers))) {
918: my $direct = 'selected="selected"';
1.128 raeburn 919: if (ref($disallowed{$lonhost}) eq 'HASH') {
920: if ($disallowed{$lonhost}{'server'} ne '') {
921: $direct = '';
922: }
1.110 raeburn 923: }
1.115 raeburn 924: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 925: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 926: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
927: '</option>';
1.184 raeburn 928: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 929: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 930: my $selected = '';
1.128 raeburn 931: if (ref($disallowed{$lonhost}) eq 'HASH') {
932: if ($hostid eq $disallowed{$lonhost}{'server'}) {
933: $selected = 'selected="selected"';
934: }
1.110 raeburn 935: }
936: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
937: $servers{$hostid}.'</option>';
938: }
1.128 raeburn 939: $datatable .= '</select></td>'.
940: '<td><select name="'.$lonhost.'_serverpath">';
941: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
942: my $pathname = $path;
943: if ($path eq 'custom') {
944: $pathname = &mt('Custom Path').' ->';
945: }
946: my $selected = '';
947: if (ref($disallowed{$lonhost}) eq 'HASH') {
948: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
949: $selected = 'selected="selected"';
950: }
951: } elsif ($path eq '') {
952: $selected = 'selected="selected"';
953: }
954: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
955: }
956: $datatable .= '</select></td>';
957: my ($custom,$exempt);
958: if (ref($disallowed{$lonhost}) eq 'HASH') {
959: $custom = $disallowed{$lonhost}{'custompath'};
960: $exempt = $disallowed{$lonhost}{'exempt'};
961: }
962: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
963: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
964: '</tr>';
1.110 raeburn 965: }
966: $datatable .= '</table></td></tr>';
967: return $datatable;
1.168 raeburn 968: } elsif ($caller eq 'page') {
969: my %defaultchecked = (
970: 'coursecatalog' => 'on',
1.188 raeburn 971: 'helpdesk' => 'on',
1.168 raeburn 972: 'adminmail' => 'off',
973: 'newuser' => 'off',
974: );
1.188 raeburn 975: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 976: my (%checkedon,%checkedoff);
1.42 raeburn 977: foreach my $item (@toggles) {
1.168 raeburn 978: if ($defaultchecked{$item} eq 'on') {
979: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 980: $checkedoff{$item} = ' ';
1.168 raeburn 981: } elsif ($defaultchecked{$item} eq 'off') {
982: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 983: $checkedon{$item} = ' ';
984: }
1.1 raeburn 985: }
1.168 raeburn 986: my @images = ('img','logo','domlogo','login');
987: my @logintext = ('textcol','bgcol');
988: my @bgs = ('pgbg','mainbg','sidebg');
989: my @links = ('link','alink','vlink');
990: my %designhash = &Apache::loncommon::get_domainconf($dom);
991: my %defaultdesign = %Apache::loncommon::defaultdesign;
992: my (%is_custom,%designs);
993: my %defaults = (
994: font => $defaultdesign{'login.font'},
995: );
1.6 raeburn 996: foreach my $item (@images) {
1.168 raeburn 997: $defaults{$item} = $defaultdesign{'login.'.$item};
998: $defaults{'showlogo'}{$item} = 1;
999: }
1000: foreach my $item (@bgs) {
1001: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1002: }
1.41 raeburn 1003: foreach my $item (@logintext) {
1.168 raeburn 1004: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1005: }
1.168 raeburn 1006: foreach my $item (@links) {
1007: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1008: }
1.168 raeburn 1009: if (ref($settings) eq 'HASH') {
1010: foreach my $item (@toggles) {
1011: if ($settings->{$item} eq '1') {
1012: $checkedon{$item} = ' checked="checked" ';
1013: $checkedoff{$item} = ' ';
1014: } elsif ($settings->{$item} eq '0') {
1015: $checkedoff{$item} = ' checked="checked" ';
1016: $checkedon{$item} = ' ';
1017: }
1018: }
1019: foreach my $item (@images) {
1020: if (defined($settings->{$item})) {
1021: $designs{$item} = $settings->{$item};
1022: $is_custom{$item} = 1;
1023: }
1024: if (defined($settings->{'showlogo'}{$item})) {
1025: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1026: }
1027: }
1028: foreach my $item (@logintext) {
1029: if ($settings->{$item} ne '') {
1030: $designs{'logintext'}{$item} = $settings->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: }
1034: if ($settings->{'font'} ne '') {
1035: $designs{'font'} = $settings->{'font'};
1036: $is_custom{'font'} = 1;
1037: }
1038: foreach my $item (@bgs) {
1039: if ($settings->{$item} ne '') {
1040: $designs{'bgs'}{$item} = $settings->{$item};
1041: $is_custom{$item} = 1;
1042: }
1043: }
1044: foreach my $item (@links) {
1045: if ($settings->{$item} ne '') {
1046: $designs{'links'}{$item} = $settings->{$item};
1047: $is_custom{$item} = 1;
1048: }
1049: }
1050: } else {
1051: if ($designhash{$dom.'.login.font'} ne '') {
1052: $designs{'font'} = $designhash{$dom.'.login.font'};
1053: $is_custom{'font'} = 1;
1054: }
1055: foreach my $item (@images) {
1056: if ($designhash{$dom.'.login.'.$item} ne '') {
1057: $designs{$item} = $designhash{$dom.'.login.'.$item};
1058: $is_custom{$item} = 1;
1059: }
1060: }
1061: foreach my $item (@bgs) {
1062: if ($designhash{$dom.'.login.'.$item} ne '') {
1063: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1064: $is_custom{$item} = 1;
1065: }
1.6 raeburn 1066: }
1.168 raeburn 1067: foreach my $item (@links) {
1068: if ($designhash{$dom.'.login.'.$item} ne '') {
1069: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1070: $is_custom{$item} = 1;
1071: }
1.6 raeburn 1072: }
1073: }
1.168 raeburn 1074: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1075: logo => 'Institution Logo',
1076: domlogo => 'Domain Logo',
1077: login => 'Login box');
1078: my $itemcount = 1;
1079: foreach my $item (@toggles) {
1080: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1081: $datatable .=
1082: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1083: '</td><td>'.
1084: '<span class="LC_nobreak"><label><input type="radio" name="'.
1085: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1086: '</label> <label><input type="radio" name="'.$item.'"'.
1087: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1088: '</tr>';
1089: $itemcount ++;
1.6 raeburn 1090: }
1.168 raeburn 1091: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1092: $datatable .= '</tr></table></td></tr>';
1093: } elsif ($caller eq 'help') {
1094: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1095: my $switchserver = &check_switchserver($dom,$confname);
1096: my $itemcount = 1;
1097: $defaulturl = '/adm/loginproblems.html';
1098: $defaulttype = 'default';
1099: %lt = &Apache::lonlocal::texthash (
1100: del => 'Delete?',
1101: rep => 'Replace:',
1102: upl => 'Upload:',
1103: default => 'Default',
1104: custom => 'Custom',
1105: );
1106: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1107: my @currlangs;
1108: if (ref($settings) eq 'HASH') {
1109: if (ref($settings->{'helpurl'}) eq 'HASH') {
1110: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1111: next if ($settings->{'helpurl'}{$key} eq '');
1112: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1113: $type{$key} = 'custom';
1114: unless ($key eq 'nolang') {
1115: push(@currlangs,$key);
1116: }
1117: }
1118: } elsif ($settings->{'helpurl'} ne '') {
1119: $type{'nolang'} = 'custom';
1120: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1121: }
1122: }
1.168 raeburn 1123: foreach my $lang ('nolang',sort(@currlangs)) {
1124: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1125: $datatable .= '<tr'.$css_class.'>';
1126: if ($url{$lang} eq '') {
1127: $url{$lang} = $defaulturl;
1128: }
1129: if ($type{$lang} eq '') {
1130: $type{$lang} = $defaulttype;
1131: }
1132: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1133: if ($lang eq 'nolang') {
1134: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1135: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1136: } else {
1137: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1138: $langchoices{$lang},
1139: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1140: }
1141: $datatable .= '</span></td>'."\n".
1142: '<td class="LC_left_item">';
1143: if ($type{$lang} eq 'custom') {
1144: $datatable .= '<span class="LC_nobreak"><label>'.
1145: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1146: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1147: } else {
1148: $datatable .= $lt{'upl'};
1149: }
1150: $datatable .='<br />';
1151: if ($switchserver) {
1152: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1153: } else {
1154: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1155: }
1.168 raeburn 1156: $datatable .= '</td></tr>';
1157: $itemcount ++;
1.6 raeburn 1158: }
1.168 raeburn 1159: my @addlangs;
1160: foreach my $lang (sort(keys(%langchoices))) {
1161: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1162: push(@addlangs,$lang);
1163: }
1164: if (@addlangs > 0) {
1165: my %toadd;
1166: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1167: $toadd{''} = &mt('Select');
1168: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1169: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1170: &mt('Add log-in help page for a specific language:').' '.
1171: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1172: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1173: if ($switchserver) {
1174: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1175: } else {
1176: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1177: }
1.168 raeburn 1178: $datatable .= '</td></tr>';
1.169 raeburn 1179: $itemcount ++;
1.6 raeburn 1180: }
1.169 raeburn 1181: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1182: }
1.6 raeburn 1183: return $datatable;
1184: }
1185:
1186: sub login_choices {
1187: my %choices =
1188: &Apache::lonlocal::texthash (
1.116 bisitz 1189: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1190: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1191: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1192: disallowlogin => "Login page requests redirected",
1193: hostid => "Server",
1.128 raeburn 1194: server => "Redirect to:",
1195: serverpath => "Path",
1196: custompath => "Custom",
1197: exempt => "Exempt IP(s)",
1.110 raeburn 1198: directlogin => "No redirect",
1199: newuser => "Link to create a user account",
1200: img => "Header",
1201: logo => "Main Logo",
1202: domlogo => "Domain Logo",
1203: login => "Log-in Header",
1204: textcol => "Text color",
1205: bgcol => "Box color",
1206: bgs => "Background colors",
1207: links => "Link colors",
1208: font => "Font color",
1209: pgbg => "Header",
1210: mainbg => "Page",
1211: sidebg => "Login box",
1212: link => "Link",
1213: alink => "Active link",
1214: vlink => "Visited link",
1.6 raeburn 1215: );
1216: return %choices;
1217: }
1218:
1219: sub print_rolecolors {
1.30 raeburn 1220: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1221: my %choices = &color_font_choices();
1222: my @bgs = ('pgbg','tabbg','sidebg');
1223: my @links = ('link','alink','vlink');
1224: my @images = ('img');
1225: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1226: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1227: my %defaultdesign = %Apache::loncommon::defaultdesign;
1228: my (%is_custom,%designs);
1.200 raeburn 1229: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1230: if (ref($settings) eq 'HASH') {
1231: if (ref($settings->{$role}) eq 'HASH') {
1232: if ($settings->{$role}->{'img'} ne '') {
1233: $designs{'img'} = $settings->{$role}->{'img'};
1234: $is_custom{'img'} = 1;
1235: }
1236: if ($settings->{$role}->{'font'} ne '') {
1237: $designs{'font'} = $settings->{$role}->{'font'};
1238: $is_custom{'font'} = 1;
1239: }
1.97 tempelho 1240: if ($settings->{$role}->{'fontmenu'} ne '') {
1241: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1242: $is_custom{'fontmenu'} = 1;
1243: }
1.6 raeburn 1244: foreach my $item (@bgs) {
1245: if ($settings->{$role}->{$item} ne '') {
1246: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1247: $is_custom{$item} = 1;
1248: }
1249: }
1250: foreach my $item (@links) {
1251: if ($settings->{$role}->{$item} ne '') {
1252: $designs{'links'}{$item} = $settings->{$role}->{$item};
1253: $is_custom{$item} = 1;
1254: }
1255: }
1256: }
1257: } else {
1258: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1259: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1260: $is_custom{'img'} = 1;
1261: }
1.97 tempelho 1262: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1263: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1264: $is_custom{'fontmenu'} = 1;
1265: }
1.6 raeburn 1266: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1267: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1268: $is_custom{'font'} = 1;
1269: }
1270: foreach my $item (@bgs) {
1271: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1272: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1273: $is_custom{$item} = 1;
1274:
1275: }
1276: }
1277: foreach my $item (@links) {
1278: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1279: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1280: $is_custom{$item} = 1;
1281: }
1282: }
1283: }
1284: my $itemcount = 1;
1.30 raeburn 1285: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1286: $datatable .= '</tr></table></td></tr>';
1287: return $datatable;
1288: }
1289:
1.200 raeburn 1290: sub role_defaults {
1291: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1292: my %defaults;
1293: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1294: return %defaults;
1295: }
1296: my %defaultdesign = %Apache::loncommon::defaultdesign;
1297: if ($role eq 'login') {
1298: %defaults = (
1299: font => $defaultdesign{$role.'.font'},
1300: );
1301: if (ref($logintext) eq 'ARRAY') {
1302: foreach my $item (@{$logintext}) {
1303: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1304: }
1305: }
1306: foreach my $item (@{$images}) {
1307: $defaults{'showlogo'}{$item} = 1;
1308: }
1309: } else {
1310: %defaults = (
1311: img => $defaultdesign{$role.'.img'},
1312: font => $defaultdesign{$role.'.font'},
1313: fontmenu => $defaultdesign{$role.'.fontmenu'},
1314: );
1315: }
1316: foreach my $item (@{$bgs}) {
1317: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1318: }
1319: foreach my $item (@{$links}) {
1320: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1321: }
1322: foreach my $item (@{$images}) {
1323: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1324: }
1325: return %defaults;
1326: }
1327:
1.6 raeburn 1328: sub display_color_options {
1.9 raeburn 1329: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1330: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1331: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1332: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1333: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1334: '<td>'.$choices->{'font'}.'</td>';
1335: if (!$is_custom->{'font'}) {
1.30 raeburn 1336: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1337: } else {
1338: $datatable .= '<td> </td>';
1339: }
1.174 foxr 1340: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1341:
1.8 raeburn 1342: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1343: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1344: ' value="'.$current_color.'" /> '.
1.174 foxr 1345: ' </td></tr>';
1.107 raeburn 1346: unless ($role eq 'login') {
1347: $datatable .= '<tr'.$css_class.'>'.
1348: '<td>'.$choices->{'fontmenu'}.'</td>';
1349: if (!$is_custom->{'fontmenu'}) {
1350: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1351: } else {
1352: $datatable .= '<td> </td>';
1353: }
1.202 raeburn 1354: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1355: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1356: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1357: '<input class="colorchooser" type="text" size="10" name="'
1358: .$role.'_fontmenu"'.
1359: ' value="'.$current_color.'" /> '.
1360: ' </td></tr>';
1.97 tempelho 1361: }
1.9 raeburn 1362: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1363: foreach my $img (@{$images}) {
1.18 albertel 1364: $itemcount ++;
1.6 raeburn 1365: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1366: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1367: '<td>'.$choices->{$img};
1.41 raeburn 1368: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1369: if ($role eq 'login') {
1370: if ($img eq 'login') {
1371: $login_hdr_pick =
1.135 bisitz 1372: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1373: $logincolors =
1374: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1375: $designs,$defaults);
1.70 raeburn 1376: } elsif ($img ne 'domlogo') {
1377: $datatable.= &logo_display_options($img,$defaults,$designs);
1378: }
1379: }
1380: $datatable .= '</td>';
1.6 raeburn 1381: if ($designs->{$img} ne '') {
1382: $imgfile = $designs->{$img};
1.18 albertel 1383: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1384: } else {
1385: $imgfile = $defaults->{$img};
1386: }
1387: if ($imgfile) {
1.9 raeburn 1388: my ($showfile,$fullsize);
1389: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1390: my $urldir = $1;
1391: my $filename = $2;
1392: my @info = &Apache::lonnet::stat_file($designs->{$img});
1393: if (@info) {
1394: my $thumbfile = 'tn-'.$filename;
1395: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1396: if (@thumb) {
1397: $showfile = $urldir.'/'.$thumbfile;
1398: } else {
1399: $showfile = $imgfile;
1400: }
1401: } else {
1402: $showfile = '';
1403: }
1404: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1405: $showfile = $imgfile;
1.6 raeburn 1406: my $imgdir = $1;
1407: my $filename = $2;
1.159 raeburn 1408: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1409: $showfile = "/$imgdir/tn-".$filename;
1410: } else {
1.159 raeburn 1411: my $input = $londocroot.$imgfile;
1412: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1413: if (!-e $output) {
1.9 raeburn 1414: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1415: my ($fullwidth,$fullheight) = &check_dimensions($input);
1416: if ($fullwidth ne '' && $fullheight ne '') {
1417: if ($fullwidth > $width && $fullheight > $height) {
1418: my $size = $width.'x'.$height;
1419: system("convert -sample $size $input $output");
1.159 raeburn 1420: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1421: }
1422: }
1.6 raeburn 1423: }
1424: }
1.16 raeburn 1425: }
1.6 raeburn 1426: if ($showfile) {
1.40 raeburn 1427: if ($showfile =~ m{^/(adm|res)/}) {
1428: if ($showfile =~ m{^/res/}) {
1429: my $local_showfile =
1430: &Apache::lonnet::filelocation('',$showfile);
1431: &Apache::lonnet::repcopy($local_showfile);
1432: }
1433: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1434: }
1435: if ($imgfile) {
1436: if ($imgfile =~ m{^/(adm|res)/}) {
1437: if ($imgfile =~ m{^/res/}) {
1438: my $local_imgfile =
1439: &Apache::lonnet::filelocation('',$imgfile);
1440: &Apache::lonnet::repcopy($local_imgfile);
1441: }
1442: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1443: } else {
1444: $fullsize = $imgfile;
1445: }
1446: }
1.41 raeburn 1447: $datatable .= '<td>';
1448: if ($img eq 'login') {
1.135 bisitz 1449: $datatable .= $login_hdr_pick;
1450: }
1.41 raeburn 1451: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1452: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1453: } else {
1.201 raeburn 1454: $datatable .= '<td> </td><td class="LC_left_item">'.
1455: &mt('Upload:').'<br />';
1.6 raeburn 1456: }
1457: } else {
1.201 raeburn 1458: $datatable .= '<td> </td><td class="LC_left_item">'.
1459: &mt('Upload:').'<br />';
1.6 raeburn 1460: }
1.9 raeburn 1461: if ($switchserver) {
1462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1463: } else {
1.135 bisitz 1464: if ($img ne 'login') { # suppress file selection for Log-in header
1465: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1466: }
1.9 raeburn 1467: }
1468: $datatable .= '</td></tr>';
1.6 raeburn 1469: }
1470: $itemcount ++;
1471: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1472: $datatable .= '<tr'.$css_class.'>'.
1473: '<td>'.$choices->{'bgs'}.'</td>';
1474: my $bgs_def;
1475: foreach my $item (@{$bgs}) {
1476: if (!$is_custom->{$item}) {
1.70 raeburn 1477: $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 1478: }
1479: }
1480: if ($bgs_def) {
1.8 raeburn 1481: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1482: } else {
1483: $datatable .= '<td> </td>';
1484: }
1485: $datatable .= '<td class="LC_right_item">'.
1486: '<table border="0"><tr>';
1.174 foxr 1487:
1.6 raeburn 1488: foreach my $item (@{$bgs}) {
1.201 raeburn 1489: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1490: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1491: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1492: $datatable .= ' ';
1.6 raeburn 1493: }
1.174 foxr 1494: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1495: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1496: }
1497: $datatable .= '</tr></table></td></tr>';
1498: $itemcount ++;
1499: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1500: $datatable .= '<tr'.$css_class.'>'.
1501: '<td>'.$choices->{'links'}.'</td>';
1502: my $links_def;
1503: foreach my $item (@{$links}) {
1504: if (!$is_custom->{$item}) {
1.30 raeburn 1505: $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 1506: }
1507: }
1508: if ($links_def) {
1.8 raeburn 1509: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1510: } else {
1511: $datatable .= '<td> </td>';
1512: }
1513: $datatable .= '<td class="LC_right_item">'.
1514: '<table border="0"><tr>';
1515: foreach my $item (@{$links}) {
1.234 raeburn 1516: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1517: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1518: if ($designs->{'links'}{$item}) {
1.174 foxr 1519: $datatable.=' ';
1.6 raeburn 1520: }
1.174 foxr 1521: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1522: '" /></td>';
1523: }
1.30 raeburn 1524: $$rowtotal += $itemcount;
1.3 raeburn 1525: return $datatable;
1526: }
1527:
1.70 raeburn 1528: sub logo_display_options {
1529: my ($img,$defaults,$designs) = @_;
1530: my $checkedon;
1531: if (ref($defaults) eq 'HASH') {
1532: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1533: if ($defaults->{'showlogo'}{$img}) {
1534: $checkedon = 'checked="checked" ';
1535: }
1536: }
1537: }
1538: if (ref($designs) eq 'HASH') {
1539: if (ref($designs->{'showlogo'}) eq 'HASH') {
1540: if (defined($designs->{'showlogo'}{$img})) {
1541: if ($designs->{'showlogo'}{$img} == 0) {
1542: $checkedon = '';
1543: } elsif ($designs->{'showlogo'}{$img} == 1) {
1544: $checkedon = 'checked="checked" ';
1545: }
1546: }
1547: }
1548: }
1549: return '<br /><label> <input type="checkbox" name="'.
1550: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1551: &mt('show').'</label>'."\n";
1552: }
1553:
1.41 raeburn 1554: sub login_header_options {
1.135 bisitz 1555: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1556: my $output = '';
1.41 raeburn 1557: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1558: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1559: if (!$is_custom->{'textcol'}) {
1560: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1561: ' ';
1562: }
1563: if (!$is_custom->{'bgcol'}) {
1564: $output .= $choices->{'bgcol'}.': '.
1565: '<span id="css_'.$role.'_font" style="background-color: '.
1566: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1567: }
1568: $output .= '<br />';
1569: }
1570: $output .='<br />';
1571: return $output;
1572: }
1573:
1574: sub login_text_colors {
1.201 raeburn 1575: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1576: my $color_menu = '<table border="0"><tr>';
1577: foreach my $item (@{$logintext}) {
1.201 raeburn 1578: $color_menu .= '<td align="center">'.$choices->{$item};
1579: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1580: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1581: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1582: }
1583: $color_menu .= '</tr></table><br />';
1584: return $color_menu;
1585: }
1586:
1587: sub image_changes {
1588: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1589: my $output;
1.135 bisitz 1590: if ($img eq 'login') {
1591: # suppress image for Log-in header
1592: } elsif (!$is_custom) {
1.70 raeburn 1593: if ($img ne 'domlogo') {
1.41 raeburn 1594: $output .= &mt('Default image:').'<br />';
1595: } else {
1596: $output .= &mt('Default in use:').'<br />';
1597: }
1598: }
1.135 bisitz 1599: if ($img eq 'login') { # suppress image for Log-in header
1600: $output .= '<td>'.$logincolors;
1.41 raeburn 1601: } else {
1.135 bisitz 1602: if ($img_import) {
1603: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1604: }
1605: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1606: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1607: if ($is_custom) {
1608: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1609: '<input type="checkbox" name="'.
1610: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1611: '</label> '.&mt('Replace:').'</span><br />';
1612: } else {
1.201 raeburn 1613: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1614: }
1.41 raeburn 1615: }
1616: return $output;
1617: }
1618:
1.3 raeburn 1619: sub print_quotas {
1.86 raeburn 1620: my ($dom,$settings,$rowtotal,$action) = @_;
1621: my $context;
1622: if ($action eq 'quotas') {
1623: $context = 'tools';
1624: } else {
1625: $context = $action;
1626: }
1.197 raeburn 1627: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1629: my $typecount = 0;
1.101 raeburn 1630: my ($css_class,%titles);
1.86 raeburn 1631: if ($context eq 'requestcourses') {
1.216 raeburn 1632: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1633: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1634: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1635: %titles = &courserequest_titles();
1.163 raeburn 1636: } elsif ($context eq 'requestauthor') {
1637: @usertools = ('author');
1638: @options = ('norequest','approval','automatic');
1.210 raeburn 1639: %titles = &authorrequest_titles();
1.86 raeburn 1640: } else {
1.162 raeburn 1641: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1642: %titles = &tool_titles();
1.86 raeburn 1643: }
1.26 raeburn 1644: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1645: foreach my $type (@{$types}) {
1.197 raeburn 1646: my ($currdefquota,$currauthorquota);
1.163 raeburn 1647: unless (($context eq 'requestcourses') ||
1648: ($context eq 'requestauthor')) {
1.86 raeburn 1649: if (ref($settings) eq 'HASH') {
1650: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1651: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1652: } else {
1653: $currdefquota = $settings->{$type};
1654: }
1.197 raeburn 1655: if (ref($settings->{authorquota}) eq 'HASH') {
1656: $currauthorquota = $settings->{authorquota}->{$type};
1657: }
1.78 raeburn 1658: }
1.72 raeburn 1659: }
1.3 raeburn 1660: if (defined($usertypes->{$type})) {
1661: $typecount ++;
1662: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1663: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1664: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1665: '<td class="LC_left_item">';
1.101 raeburn 1666: if ($context eq 'requestcourses') {
1667: $datatable .= '<table><tr>';
1668: }
1669: my %cell;
1.72 raeburn 1670: foreach my $item (@usertools) {
1.101 raeburn 1671: if ($context eq 'requestcourses') {
1672: my ($curroption,$currlimit);
1673: if (ref($settings) eq 'HASH') {
1674: if (ref($settings->{$item}) eq 'HASH') {
1675: $curroption = $settings->{$item}->{$type};
1676: if ($curroption =~ /^autolimit=(\d*)$/) {
1677: $currlimit = $1;
1678: }
1679: }
1680: }
1681: if (!$curroption) {
1682: $curroption = 'norequest';
1683: }
1684: $datatable .= '<th>'.$titles{$item}.'</th>';
1685: foreach my $option (@options) {
1686: my $val = $option;
1687: if ($option eq 'norequest') {
1688: $val = 0;
1689: }
1690: if ($option eq 'validate') {
1691: my $canvalidate = 0;
1692: if (ref($validations{$item}) eq 'HASH') {
1693: if ($validations{$item}{$type}) {
1694: $canvalidate = 1;
1695: }
1696: }
1697: next if (!$canvalidate);
1698: }
1699: my $checked = '';
1700: if ($option eq $curroption) {
1701: $checked = ' checked="checked"';
1702: } elsif ($option eq 'autolimit') {
1703: if ($curroption =~ /^autolimit/) {
1704: $checked = ' checked="checked"';
1705: }
1706: }
1707: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1708: '<input type="radio" name="crsreq_'.$item.
1709: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1710: $titles{$option}.'</label>';
1.101 raeburn 1711: if ($option eq 'autolimit') {
1.127 raeburn 1712: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1713: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1714: 'value="'.$currlimit.'" />';
1.101 raeburn 1715: }
1.127 raeburn 1716: $cell{$item} .= '</span> ';
1.103 raeburn 1717: if ($option eq 'autolimit') {
1.127 raeburn 1718: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1719: }
1.101 raeburn 1720: }
1.163 raeburn 1721: } elsif ($context eq 'requestauthor') {
1722: my $curroption;
1723: if (ref($settings) eq 'HASH') {
1724: $curroption = $settings->{$type};
1725: }
1726: if (!$curroption) {
1727: $curroption = 'norequest';
1728: }
1729: foreach my $option (@options) {
1730: my $val = $option;
1731: if ($option eq 'norequest') {
1732: $val = 0;
1733: }
1734: my $checked = '';
1735: if ($option eq $curroption) {
1736: $checked = ' checked="checked"';
1737: }
1738: $datatable .= '<span class="LC_nobreak"><label>'.
1739: '<input type="radio" name="authorreq_'.$type.
1740: '" value="'.$val.'"'.$checked.' />'.
1741: $titles{$option}.'</label></span> ';
1742: }
1.101 raeburn 1743: } else {
1744: my $checked = 'checked="checked" ';
1745: if (ref($settings) eq 'HASH') {
1746: if (ref($settings->{$item}) eq 'HASH') {
1747: if ($settings->{$item}->{$type} == 0) {
1748: $checked = '';
1749: } elsif ($settings->{$item}->{$type} == 1) {
1750: $checked = 'checked="checked" ';
1751: }
1.78 raeburn 1752: }
1.72 raeburn 1753: }
1.101 raeburn 1754: $datatable .= '<span class="LC_nobreak"><label>'.
1755: '<input type="checkbox" name="'.$context.'_'.$item.
1756: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1757: '</label></span> ';
1.72 raeburn 1758: }
1.101 raeburn 1759: }
1760: if ($context eq 'requestcourses') {
1761: $datatable .= '</tr><tr>';
1762: foreach my $item (@usertools) {
1.106 raeburn 1763: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1764: }
1765: $datatable .= '</tr></table>';
1.72 raeburn 1766: }
1.86 raeburn 1767: $datatable .= '</td>';
1.163 raeburn 1768: unless (($context eq 'requestcourses') ||
1769: ($context eq 'requestauthor')) {
1.86 raeburn 1770: $datatable .=
1.197 raeburn 1771: '<td class="LC_right_item">'.
1772: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1773: '<input type="text" name="quota_'.$type.
1.72 raeburn 1774: '" value="'.$currdefquota.
1.197 raeburn 1775: '" size="5" /></span>'.(' ' x 2).
1776: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1777: '<input type="text" name="authorquota_'.$type.
1778: '" value="'.$currauthorquota.
1779: '" size="5" /></span></td>';
1.86 raeburn 1780: }
1781: $datatable .= '</tr>';
1.3 raeburn 1782: }
1783: }
1784: }
1.163 raeburn 1785: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1786: $defaultquota = '20';
1.197 raeburn 1787: $authorquota = '500';
1.86 raeburn 1788: if (ref($settings) eq 'HASH') {
1789: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1790: $defaultquota = $settings->{'defaultquota'}->{'default'};
1791: } elsif (defined($settings->{'default'})) {
1792: $defaultquota = $settings->{'default'};
1793: }
1.197 raeburn 1794: if (ref($settings->{'authorquota'}) eq 'HASH') {
1795: $authorquota = $settings->{'authorquota'}->{'default'};
1796: }
1.3 raeburn 1797: }
1798: }
1799: $typecount ++;
1800: $css_class = $typecount%2?' class="LC_odd_row"':'';
1801: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1802: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1803: '<td class="LC_left_item">';
1.101 raeburn 1804: if ($context eq 'requestcourses') {
1805: $datatable .= '<table><tr>';
1806: }
1807: my %defcell;
1.72 raeburn 1808: foreach my $item (@usertools) {
1.101 raeburn 1809: if ($context eq 'requestcourses') {
1810: my ($curroption,$currlimit);
1811: if (ref($settings) eq 'HASH') {
1812: if (ref($settings->{$item}) eq 'HASH') {
1813: $curroption = $settings->{$item}->{'default'};
1814: if ($curroption =~ /^autolimit=(\d*)$/) {
1815: $currlimit = $1;
1816: }
1817: }
1818: }
1819: if (!$curroption) {
1820: $curroption = 'norequest';
1821: }
1822: $datatable .= '<th>'.$titles{$item}.'</th>';
1823: foreach my $option (@options) {
1824: my $val = $option;
1825: if ($option eq 'norequest') {
1826: $val = 0;
1827: }
1828: if ($option eq 'validate') {
1829: my $canvalidate = 0;
1830: if (ref($validations{$item}) eq 'HASH') {
1831: if ($validations{$item}{'default'}) {
1832: $canvalidate = 1;
1833: }
1834: }
1835: next if (!$canvalidate);
1836: }
1837: my $checked = '';
1838: if ($option eq $curroption) {
1839: $checked = ' checked="checked"';
1840: } elsif ($option eq 'autolimit') {
1841: if ($curroption =~ /^autolimit/) {
1842: $checked = ' checked="checked"';
1843: }
1844: }
1845: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1846: '<input type="radio" name="crsreq_'.$item.
1847: '_default" value="'.$val.'"'.$checked.' />'.
1848: $titles{$option}.'</label>';
1849: if ($option eq 'autolimit') {
1.127 raeburn 1850: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1851: $item.'_limit_default" size="1" '.
1852: 'value="'.$currlimit.'" />';
1853: }
1.127 raeburn 1854: $defcell{$item} .= '</span> ';
1.104 raeburn 1855: if ($option eq 'autolimit') {
1.127 raeburn 1856: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1857: }
1.101 raeburn 1858: }
1.163 raeburn 1859: } elsif ($context eq 'requestauthor') {
1860: my $curroption;
1861: if (ref($settings) eq 'HASH') {
1.172 raeburn 1862: $curroption = $settings->{'default'};
1.163 raeburn 1863: }
1864: if (!$curroption) {
1865: $curroption = 'norequest';
1866: }
1867: foreach my $option (@options) {
1868: my $val = $option;
1869: if ($option eq 'norequest') {
1870: $val = 0;
1871: }
1872: my $checked = '';
1873: if ($option eq $curroption) {
1874: $checked = ' checked="checked"';
1875: }
1876: $datatable .= '<span class="LC_nobreak"><label>'.
1877: '<input type="radio" name="authorreq_default"'.
1878: ' value="'.$val.'"'.$checked.' />'.
1879: $titles{$option}.'</label></span> ';
1880: }
1.101 raeburn 1881: } else {
1882: my $checked = 'checked="checked" ';
1883: if (ref($settings) eq 'HASH') {
1884: if (ref($settings->{$item}) eq 'HASH') {
1885: if ($settings->{$item}->{'default'} == 0) {
1886: $checked = '';
1887: } elsif ($settings->{$item}->{'default'} == 1) {
1888: $checked = 'checked="checked" ';
1889: }
1.78 raeburn 1890: }
1.72 raeburn 1891: }
1.101 raeburn 1892: $datatable .= '<span class="LC_nobreak"><label>'.
1893: '<input type="checkbox" name="'.$context.'_'.$item.
1894: '" value="default" '.$checked.'/>'.$titles{$item}.
1895: '</label></span> ';
1896: }
1897: }
1898: if ($context eq 'requestcourses') {
1899: $datatable .= '</tr><tr>';
1900: foreach my $item (@usertools) {
1.106 raeburn 1901: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1902: }
1.101 raeburn 1903: $datatable .= '</tr></table>';
1.72 raeburn 1904: }
1.86 raeburn 1905: $datatable .= '</td>';
1.163 raeburn 1906: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1907: $datatable .= '<td class="LC_right_item">'.
1908: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1909: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1910: $defaultquota.'" size="5" /></span>'.(' ' x2).
1911: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1912: '<input type="text" name="authorquota" value="'.
1913: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1914: }
1915: $datatable .= '</tr>';
1.72 raeburn 1916: $typecount ++;
1917: $css_class = $typecount%2?' class="LC_odd_row"':'';
1918: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1919: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1920: if ($context eq 'requestcourses') {
1.109 raeburn 1921: $datatable .= &mt('(overrides affiliation, if set)').
1922: '</td>'.
1923: '<td class="LC_left_item">'.
1924: '<table><tr>';
1.101 raeburn 1925: } else {
1.109 raeburn 1926: $datatable .= &mt('(overrides affiliation, if checked)').
1927: '</td>'.
1928: '<td class="LC_left_item" colspan="2">'.
1929: '<br />';
1.101 raeburn 1930: }
1931: my %advcell;
1.72 raeburn 1932: foreach my $item (@usertools) {
1.101 raeburn 1933: if ($context eq 'requestcourses') {
1934: my ($curroption,$currlimit);
1935: if (ref($settings) eq 'HASH') {
1936: if (ref($settings->{$item}) eq 'HASH') {
1937: $curroption = $settings->{$item}->{'_LC_adv'};
1938: if ($curroption =~ /^autolimit=(\d*)$/) {
1939: $currlimit = $1;
1940: }
1941: }
1942: }
1943: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1944: my $checked = '';
1945: if ($curroption eq '') {
1946: $checked = ' checked="checked"';
1947: }
1948: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1949: '<input type="radio" name="crsreq_'.$item.
1950: '__LC_adv" value=""'.$checked.' />'.
1951: &mt('No override set').'</label></span> ';
1.101 raeburn 1952: foreach my $option (@options) {
1953: my $val = $option;
1954: if ($option eq 'norequest') {
1955: $val = 0;
1956: }
1957: if ($option eq 'validate') {
1958: my $canvalidate = 0;
1959: if (ref($validations{$item}) eq 'HASH') {
1960: if ($validations{$item}{'_LC_adv'}) {
1961: $canvalidate = 1;
1962: }
1963: }
1964: next if (!$canvalidate);
1965: }
1966: my $checked = '';
1.104 raeburn 1967: if ($val eq $curroption) {
1.101 raeburn 1968: $checked = ' checked="checked"';
1969: } elsif ($option eq 'autolimit') {
1970: if ($curroption =~ /^autolimit/) {
1971: $checked = ' checked="checked"';
1972: }
1973: }
1974: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1975: '<input type="radio" name="crsreq_'.$item.
1976: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1977: $titles{$option}.'</label>';
1978: if ($option eq 'autolimit') {
1.127 raeburn 1979: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1980: $item.'_limit__LC_adv" size="1" '.
1981: 'value="'.$currlimit.'" />';
1982: }
1.127 raeburn 1983: $advcell{$item} .= '</span> ';
1.104 raeburn 1984: if ($option eq 'autolimit') {
1.127 raeburn 1985: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1986: }
1.101 raeburn 1987: }
1.163 raeburn 1988: } elsif ($context eq 'requestauthor') {
1989: my $curroption;
1990: if (ref($settings) eq 'HASH') {
1991: $curroption = $settings->{'_LC_adv'};
1992: }
1993: my $checked = '';
1994: if ($curroption eq '') {
1995: $checked = ' checked="checked"';
1996: }
1997: $datatable .= '<span class="LC_nobreak"><label>'.
1998: '<input type="radio" name="authorreq__LC_adv"'.
1999: ' value=""'.$checked.' />'.
2000: &mt('No override set').'</label></span> ';
2001: foreach my $option (@options) {
2002: my $val = $option;
2003: if ($option eq 'norequest') {
2004: $val = 0;
2005: }
2006: my $checked = '';
2007: if ($val eq $curroption) {
2008: $checked = ' checked="checked"';
2009: }
2010: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2011: '<input type="radio" name="authorreq__LC_adv"'.
2012: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2013: $titles{$option}.'</label></span> ';
2014: }
1.101 raeburn 2015: } else {
2016: my $checked = 'checked="checked" ';
2017: if (ref($settings) eq 'HASH') {
2018: if (ref($settings->{$item}) eq 'HASH') {
2019: if ($settings->{$item}->{'_LC_adv'} == 0) {
2020: $checked = '';
2021: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2022: $checked = 'checked="checked" ';
2023: }
1.79 raeburn 2024: }
1.72 raeburn 2025: }
1.101 raeburn 2026: $datatable .= '<span class="LC_nobreak"><label>'.
2027: '<input type="checkbox" name="'.$context.'_'.$item.
2028: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2029: '</label></span> ';
2030: }
2031: }
2032: if ($context eq 'requestcourses') {
2033: $datatable .= '</tr><tr>';
2034: foreach my $item (@usertools) {
1.106 raeburn 2035: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2036: }
1.101 raeburn 2037: $datatable .= '</tr></table>';
1.72 raeburn 2038: }
1.98 raeburn 2039: $datatable .= '</td></tr>';
1.30 raeburn 2040: $$rowtotal += $typecount;
1.3 raeburn 2041: return $datatable;
2042: }
2043:
1.163 raeburn 2044: sub print_requestmail {
2045: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2046: my ($now,$datatable,%currapp);
1.102 raeburn 2047: $now = time;
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{'notify'}) eq 'HASH') {
2050: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2051: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2052: }
2053: }
2054: }
1.191 raeburn 2055: my $numinrow = 2;
1.224 raeburn 2056: my $css_class;
2057: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2058: my $text;
2059: if ($action eq 'requestcourses') {
2060: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2061: } elsif ($action eq 'requestauthor') {
2062: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2063: } else {
1.224 raeburn 2064: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2065: }
1.224 raeburn 2066: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2067: ' <td>'.$text.'</td>'.
1.102 raeburn 2068: ' <td class="LC_left_item">';
1.191 raeburn 2069: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2070: $action.'notifyapproval',%currapp);
1.191 raeburn 2071: if ($numdc > 0) {
2072: $datatable .= $table;
1.102 raeburn 2073: } else {
2074: $datatable .= &mt('There are no active Domain Coordinators');
2075: }
2076: $datatable .='</td></tr>';
2077: $$rowtotal += $rows;
2078: return $datatable;
2079: }
2080:
1.216 raeburn 2081: sub print_studentcode {
2082: my ($settings,$rowtotal) = @_;
2083: my $rownum = 0;
1.218 raeburn 2084: my ($output,%current);
2085: my @crstypes = ('official','unofficial','community','textbook');
2086: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2087: foreach my $type (@crstypes) {
2088: $current{$type} = $settings->{'uniquecode'}{$type};
2089: }
2090: }
2091: $output .= '<tr>'.
2092: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2093: '<td class="LC_left_item">';
2094: foreach my $type (@crstypes) {
2095: my $check = ' ';
2096: if ($current{$type}) {
2097: $check = ' checked="checked" ';
2098: }
2099: $output .= '<span class="LC_nobreak"><label>'.
2100: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2101: &mt($type).'</label></span>'.(' 'x2).' ';
2102: }
2103: $output .= '</td></tr>';
2104: $$rowtotal ++;
2105: return $output;
1.216 raeburn 2106: }
2107:
2108: sub print_textbookcourses {
1.242 raeburn 2109: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2110: my $rownum = 0;
2111: my $css_class;
2112: my $itemcount = 1;
2113: my $maxnum = 0;
2114: my $bookshash;
2115: if (ref($settings) eq 'HASH') {
1.242 raeburn 2116: $bookshash = $settings->{$type};
1.216 raeburn 2117: }
2118: my %ordered;
2119: if (ref($bookshash) eq 'HASH') {
2120: foreach my $item (keys(%{$bookshash})) {
2121: if (ref($bookshash->{$item}) eq 'HASH') {
2122: my $num = $bookshash->{$item}{'order'};
2123: $ordered{$num} = $item;
2124: }
2125: }
2126: }
2127: my $confname = $dom.'-domainconfig';
2128: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2129: my $maxnum = scalar(keys(%ordered));
2130: my $datatable;
1.216 raeburn 2131: if (keys(%ordered)) {
2132: my @items = sort { $a <=> $b } keys(%ordered);
2133: for (my $i=0; $i<@items; $i++) {
2134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2135: my $key = $ordered{$items[$i]};
2136: my %coursehash=&Apache::lonnet::coursedescription($key);
2137: my $coursetitle = $coursehash{'description'};
1.243 ! raeburn 2138: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2139: if (ref($bookshash->{$key}) eq 'HASH') {
2140: $subject = $bookshash->{$key}->{'subject'};
2141: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2142: if ($type eq 'textbooks') {
1.243 ! raeburn 2143: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2144: $author = $bookshash->{$key}->{'author'};
2145: $image = $bookshash->{$key}->{'image'};
2146: if ($image ne '') {
2147: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2148: my $imagethumb = "$path/tn-".$imagefile;
2149: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2150: }
1.216 raeburn 2151: }
2152: }
1.242 raeburn 2153: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2154: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2155: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2156: for (my $k=0; $k<=$maxnum; $k++) {
2157: my $vpos = $k+1;
2158: my $selstr;
2159: if ($k == $i) {
2160: $selstr = ' selected="selected" ';
2161: }
2162: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2163: }
2164: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2165: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2166: &mt('Delete?').'</label></span></td>'.
2167: '<td colspan="2">'.
1.242 raeburn 2168: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2169: (' 'x2).
1.242 raeburn 2170: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2171: if ($type eq 'textbooks') {
2172: $datatable .= (' 'x2).
1.243 ! raeburn 2173: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
! 2174: (' 'x2).
1.242 raeburn 2175: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2176: (' 'x2).
2177: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2178: if ($image) {
2179: $datatable .= '<span class="LC_nobreak">'.
2180: $imgsrc.
2181: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2182: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2183: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2184: }
2185: if ($switchserver) {
2186: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2187: } else {
2188: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2189: }
1.216 raeburn 2190: }
1.242 raeburn 2191: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2192: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2193: $coursetitle.'</span></td></tr>'."\n";
2194: $itemcount ++;
2195: }
2196: }
2197: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2198: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2199: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2200: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2201: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2202: for (my $k=0; $k<$maxnum+1; $k++) {
2203: my $vpos = $k+1;
2204: my $selstr;
2205: if ($k == $maxnum) {
2206: $selstr = ' selected="selected" ';
2207: }
2208: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2209: }
2210: $datatable .= '</select> '."\n".
1.242 raeburn 2211: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2212: '<td colspan="2">'.
1.242 raeburn 2213: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2214: (' 'x2).
1.242 raeburn 2215: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2216: (' 'x2);
2217: if ($type eq 'textbooks') {
1.243 ! raeburn 2218: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
! 2219: (' 'x2).
! 2220: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2221: (' 'x2).
2222: '<span class="LC_nobreak">'.&mt('Image:').' ';
2223: if ($switchserver) {
2224: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2225: } else {
2226: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2227: }
1.216 raeburn 2228: }
2229: $datatable .= '</span>'."\n".
2230: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2231: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2232: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2233: &Apache::loncommon::selectcourse_link
1.242 raeburn 2234: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2235: '</span></td>'."\n".
2236: '</tr>'."\n";
2237: $itemcount ++;
2238: return $datatable;
2239: }
2240:
1.217 raeburn 2241: sub textbookcourses_javascript {
1.242 raeburn 2242: my ($settings) = @_;
2243: return unless(ref($settings) eq 'HASH');
2244: my (%ordered,%total,%jstext);
2245: foreach my $type ('textbooks','templates') {
2246: $total{$type} = 0;
2247: if (ref($settings->{$type}) eq 'HASH') {
2248: foreach my $item (keys(%{$settings->{$type}})) {
2249: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2250: my $num = $settings->{$type}->{$item}{'order'};
2251: $ordered{$type}{$num} = $item;
2252: }
2253: }
2254: $total{$type} = scalar(keys(%{$settings->{$type}}));
2255: }
2256: my @jsarray = ();
2257: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2258: push(@jsarray,$ordered{$type}{$item});
2259: }
2260: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2261: }
2262: return <<"ENDSCRIPT";
2263: <script type="text/javascript">
2264: // <![CDATA[
1.242 raeburn 2265: function reorderBooks(form,item,caller) {
1.217 raeburn 2266: var changedVal;
1.242 raeburn 2267: $jstext{'textbooks'};
2268: $jstext{'templates'};
2269: var newpos;
2270: var maxh;
2271: if (caller == 'textbooks') {
2272: newpos = 'textbooks_addbook_pos';
2273: maxh = 1 + $total{'textbooks'};
2274: } else {
2275: newpos = 'templates_addbook_pos';
2276: maxh = 1 + $total{'templates'};
2277: }
1.217 raeburn 2278: var current = new Array;
2279: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2280: if (item == newpos) {
2281: changedVal = newitemVal;
2282: } else {
2283: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2284: current[newitemVal] = newpos;
2285: }
1.242 raeburn 2286: if (caller == 'textbooks') {
2287: for (var i=0; i<textbooks.length; i++) {
2288: var elementName = 'textbooks_'+textbooks[i];
2289: if (elementName != item) {
2290: if (form.elements[elementName]) {
2291: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2292: current[currVal] = elementName;
2293: }
2294: }
2295: }
2296: }
2297: if (caller == 'templates') {
2298: for (var i=0; i<templates.length; i++) {
2299: var elementName = 'templates_'+templates[i];
2300: if (elementName != item) {
2301: if (form.elements[elementName]) {
2302: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2303: current[currVal] = elementName;
2304: }
1.217 raeburn 2305: }
2306: }
2307: }
2308: var oldVal;
2309: for (var j=0; j<maxh; j++) {
2310: if (current[j] == undefined) {
2311: oldVal = j;
2312: }
2313: }
2314: if (oldVal < changedVal) {
2315: for (var k=oldVal+1; k<=changedVal ; k++) {
2316: var elementName = current[k];
2317: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2318: }
2319: } else {
2320: for (var k=changedVal; k<oldVal; k++) {
2321: var elementName = current[k];
2322: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2323: }
2324: }
2325: return;
2326: }
2327:
2328: // ]]>
2329: </script>
2330:
2331: ENDSCRIPT
2332: }
2333:
1.3 raeburn 2334: sub print_autoenroll {
1.30 raeburn 2335: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2336: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2337: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2338: if (ref($settings) eq 'HASH') {
2339: if (exists($settings->{'run'})) {
2340: if ($settings->{'run'} eq '0') {
2341: $runoff = ' checked="checked" ';
2342: $runon = ' ';
2343: } else {
2344: $runon = ' checked="checked" ';
2345: $runoff = ' ';
2346: }
2347: } else {
2348: if ($autorun) {
2349: $runon = ' checked="checked" ';
2350: $runoff = ' ';
2351: } else {
2352: $runoff = ' checked="checked" ';
2353: $runon = ' ';
2354: }
2355: }
1.129 raeburn 2356: if (exists($settings->{'co-owners'})) {
2357: if ($settings->{'co-owners'} eq '0') {
2358: $coownersoff = ' checked="checked" ';
2359: $coownerson = ' ';
2360: } else {
2361: $coownerson = ' checked="checked" ';
2362: $coownersoff = ' ';
2363: }
2364: } else {
2365: $coownersoff = ' checked="checked" ';
2366: $coownerson = ' ';
2367: }
1.3 raeburn 2368: if (exists($settings->{'sender_domain'})) {
2369: $defdom = $settings->{'sender_domain'};
2370: }
1.14 raeburn 2371: } else {
2372: if ($autorun) {
2373: $runon = ' checked="checked" ';
2374: $runoff = ' ';
2375: } else {
2376: $runoff = ' checked="checked" ';
2377: $runon = ' ';
2378: }
1.3 raeburn 2379: }
2380: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2381: my $notif_sender;
2382: if (ref($settings) eq 'HASH') {
2383: $notif_sender = $settings->{'sender_uname'};
2384: }
1.3 raeburn 2385: my $datatable='<tr class="LC_odd_row">'.
2386: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2387: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2388: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2389: $runon.' value="1" />'.&mt('Yes').'</label> '.
2390: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2391: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2392: '</tr><tr>'.
2393: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2394: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2395: &mt('username').': '.
2396: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2397: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2398: ': '.$domform.'</span></td></tr>'.
2399: '<tr class="LC_odd_row">'.
2400: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2401: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2402: '<input type="radio" name="autoassign_coowners"'.
2403: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2404: '<label><input type="radio" name="autoassign_coowners"'.
2405: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2406: '</tr>';
2407: $$rowtotal += 3;
1.3 raeburn 2408: return $datatable;
2409: }
2410:
2411: sub print_autoupdate {
1.30 raeburn 2412: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2413: my $datatable;
2414: if ($position eq 'top') {
2415: my $updateon = ' ';
2416: my $updateoff = ' checked="checked" ';
2417: my $classlistson = ' ';
2418: my $classlistsoff = ' checked="checked" ';
2419: if (ref($settings) eq 'HASH') {
2420: if ($settings->{'run'} eq '1') {
2421: $updateon = $updateoff;
2422: $updateoff = ' ';
2423: }
2424: if ($settings->{'classlists'} eq '1') {
2425: $classlistson = $classlistsoff;
2426: $classlistsoff = ' ';
2427: }
2428: }
2429: my %title = (
2430: run => 'Auto-update active?',
2431: classlists => 'Update information in classlists?',
2432: );
2433: $datatable = '<tr class="LC_odd_row">'.
2434: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2435: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2436: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2437: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2438: '<label><input type="radio" name="autoupdate_run"'.
2439: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2440: '</tr><tr>'.
2441: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2442: '<td class="LC_right_item"><span class="LC_nobreak">'.
2443: '<label><input type="radio" name="classlists"'.
2444: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2445: '<label><input type="radio" name="classlists"'.
2446: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2447: '</tr>';
1.30 raeburn 2448: $$rowtotal += 2;
1.131 raeburn 2449: } elsif ($position eq 'middle') {
2450: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2451: my $numinrow = 3;
2452: my $locknamesettings;
2453: $datatable .= &insttypes_row($settings,$types,$usertypes,
2454: $dom,$numinrow,$othertitle,
2455: 'lockablenames');
2456: $$rowtotal ++;
1.3 raeburn 2457: } else {
1.44 raeburn 2458: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2459: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2460: 'permanentemail','id');
1.33 raeburn 2461: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2462: my $numrows = 0;
1.26 raeburn 2463: if (ref($types) eq 'ARRAY') {
2464: if (@{$types} > 0) {
2465: $datatable =
2466: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2467: \@fields,$types,\$numrows);
1.30 raeburn 2468: $$rowtotal += @{$types};
1.26 raeburn 2469: }
1.3 raeburn 2470: }
2471: $datatable .=
2472: &usertype_update_row($settings,{'default' => $othertitle},
2473: \%fieldtitles,\@fields,['default'],
2474: \$numrows);
1.30 raeburn 2475: $$rowtotal ++;
1.3 raeburn 2476: }
2477: return $datatable;
2478: }
2479:
1.125 raeburn 2480: sub print_autocreate {
2481: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2482: my (%createon,%createoff,%currhash);
1.125 raeburn 2483: my @types = ('xml','req');
2484: if (ref($settings) eq 'HASH') {
2485: foreach my $item (@types) {
2486: $createoff{$item} = ' checked="checked" ';
2487: $createon{$item} = ' ';
2488: if (exists($settings->{$item})) {
2489: if ($settings->{$item}) {
2490: $createon{$item} = ' checked="checked" ';
2491: $createoff{$item} = ' ';
2492: }
2493: }
2494: }
1.210 raeburn 2495: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2496: $currhash{$settings->{'xmldc'}} = 1;
2497: }
1.125 raeburn 2498: } else {
2499: foreach my $item (@types) {
2500: $createoff{$item} = ' checked="checked" ';
2501: $createon{$item} = ' ';
2502: }
2503: }
2504: $$rowtotal += 2;
1.191 raeburn 2505: my $numinrow = 2;
1.125 raeburn 2506: my $datatable='<tr class="LC_odd_row">'.
2507: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2508: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2509: '<input type="radio" name="autocreate_xml"'.
2510: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2511: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2512: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2513: '</td></tr><tr>'.
2514: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2515: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2516: '<input type="radio" name="autocreate_req"'.
2517: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2518: '<label><input type="radio" name="autocreate_req"'.
2519: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2520: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2521: 'autocreate_xmldc',%currhash);
1.125 raeburn 2522: if ($numdc > 1) {
1.143 raeburn 2523: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2524: &mt('Course creation processed as: (choose Dom. Coord.)').
2525: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2526: } else {
1.143 raeburn 2527: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2528: }
1.191 raeburn 2529: $$rowtotal += $rows;
1.125 raeburn 2530: return $datatable;
2531: }
2532:
1.23 raeburn 2533: sub print_directorysrch {
1.30 raeburn 2534: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2535: my $srchon = ' ';
2536: my $srchoff = ' checked="checked" ';
1.25 raeburn 2537: my ($exacton,$containson,$beginson);
1.24 raeburn 2538: my $localon = ' ';
2539: my $localoff = ' checked="checked" ';
1.23 raeburn 2540: if (ref($settings) eq 'HASH') {
2541: if ($settings->{'available'} eq '1') {
2542: $srchon = $srchoff;
2543: $srchoff = ' ';
2544: }
1.24 raeburn 2545: if ($settings->{'localonly'} eq '1') {
2546: $localon = $localoff;
2547: $localoff = ' ';
2548: }
1.25 raeburn 2549: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2550: foreach my $type (@{$settings->{'searchtypes'}}) {
2551: if ($type eq 'exact') {
2552: $exacton = ' checked="checked" ';
2553: } elsif ($type eq 'contains') {
2554: $containson = ' checked="checked" ';
2555: } elsif ($type eq 'begins') {
2556: $beginson = ' checked="checked" ';
2557: }
2558: }
2559: } else {
2560: if ($settings->{'searchtypes'} eq 'exact') {
2561: $exacton = ' checked="checked" ';
2562: } elsif ($settings->{'searchtypes'} eq 'contains') {
2563: $containson = ' checked="checked" ';
2564: } elsif ($settings->{'searchtypes'} eq 'specify') {
2565: $exacton = ' checked="checked" ';
2566: $containson = ' checked="checked" ';
2567: }
1.23 raeburn 2568: }
2569: }
2570: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2571: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2572:
2573: my $numinrow = 4;
1.26 raeburn 2574: my $cansrchrow = 0;
1.23 raeburn 2575: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2576: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2577: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2578: '<input type="radio" name="dirsrch_available"'.
2579: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2580: '<label><input type="radio" name="dirsrch_available"'.
2581: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2582: '</tr><tr>'.
1.30 raeburn 2583: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2584: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2585: '<input type="radio" name="dirsrch_localonly"'.
2586: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2587: '<label><input type="radio" name="dirsrch_localonly"'.
2588: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2589: '</tr>';
1.30 raeburn 2590: $$rowtotal += 2;
1.26 raeburn 2591: if (ref($usertypes) eq 'HASH') {
2592: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2593: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2594: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2595: $cansrchrow = 1;
2596: }
2597: }
2598: if ($cansrchrow) {
1.30 raeburn 2599: $$rowtotal ++;
1.26 raeburn 2600: $datatable .= '<tr>';
2601: } else {
2602: $datatable .= '<tr class="LC_odd_row">';
2603: }
1.30 raeburn 2604: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2605: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2606: foreach my $title (@{$titleorder}) {
2607: if (defined($searchtitles->{$title})) {
2608: my $check = ' ';
1.93 raeburn 2609: if (ref($settings) eq 'HASH') {
1.39 raeburn 2610: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2611: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2612: $check = ' checked="checked" ';
2613: }
1.25 raeburn 2614: }
2615: }
2616: $datatable .= '<td class="LC_left_item">'.
2617: '<span class="LC_nobreak"><label>'.
2618: '<input type="checkbox" name="searchby" '.
2619: 'value="'.$title.'"'.$check.'/>'.
2620: $searchtitles->{$title}.'</label></span></td>';
2621: }
2622: }
1.26 raeburn 2623: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2624: $$rowtotal ++;
1.26 raeburn 2625: if ($cansrchrow) {
2626: $datatable .= '<tr class="LC_odd_row">';
2627: } else {
2628: $datatable .= '<tr>';
2629: }
1.30 raeburn 2630: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2631: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2632: '<span class="LC_nobreak"><label>'.
2633: '<input type="checkbox" name="searchtypes" '.
2634: $exacton.' value="exact" />'.&mt('Exact match').
2635: '</label> '.
2636: '<label><input type="checkbox" name="searchtypes" '.
2637: $beginson.' value="begins" />'.&mt('Begins with').
2638: '</label> '.
2639: '<label><input type="checkbox" name="searchtypes" '.
2640: $containson.' value="contains" />'.&mt('Contains').
2641: '</label></span></td></tr>';
1.30 raeburn 2642: $$rowtotal ++;
1.25 raeburn 2643: return $datatable;
2644: }
2645:
1.28 raeburn 2646: sub print_contacts {
1.30 raeburn 2647: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2648: my $datatable;
2649: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2650: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2651: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2652: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2653: foreach my $type (@mailings) {
2654: $otheremails{$type} = '';
2655: }
1.134 raeburn 2656: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2657: if (ref($settings) eq 'HASH') {
2658: foreach my $item (@contacts) {
2659: if (exists($settings->{$item})) {
2660: $to{$item} = $settings->{$item};
2661: }
2662: }
2663: foreach my $type (@mailings) {
2664: if (exists($settings->{$type})) {
2665: if (ref($settings->{$type}) eq 'HASH') {
2666: foreach my $item (@contacts) {
2667: if ($settings->{$type}{$item}) {
2668: $checked{$type}{$item} = ' checked="checked" ';
2669: }
2670: }
2671: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2672: if ($type eq 'helpdeskmail') {
2673: $bccemails{$type} = $settings->{$type}{'bcc'};
2674: }
1.28 raeburn 2675: }
1.89 raeburn 2676: } elsif ($type eq 'lonstatusmail') {
2677: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2678: }
2679: }
2680: } else {
2681: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2682: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2683: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2684: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2685: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2686: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2687: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2688: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2689: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2690: }
2691: my ($titles,$short_titles) = &contact_titles();
2692: my $rownum = 0;
2693: my $css_class;
2694: foreach my $item (@contacts) {
1.69 raeburn 2695: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2696: $datatable .= '<tr'.$css_class.'>'.
2697: '<td><span class="LC_nobreak">'.$titles->{$item}.
2698: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2699: '<input type="text" name="'.$item.'" value="'.
2700: $to{$item}.'" /></td></tr>';
1.203 raeburn 2701: $rownum ++;
1.28 raeburn 2702: }
2703: foreach my $type (@mailings) {
1.69 raeburn 2704: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2705: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2706: '<td><span class="LC_nobreak">'.
2707: $titles->{$type}.': </span></td>'.
1.28 raeburn 2708: '<td class="LC_left_item">'.
2709: '<span class="LC_nobreak">';
2710: foreach my $item (@contacts) {
2711: $datatable .= '<label>'.
2712: '<input type="checkbox" name="'.$type.'"'.
2713: $checked{$type}{$item}.
2714: ' value="'.$item.'" />'.$short_titles->{$item}.
2715: '</label> ';
2716: }
2717: $datatable .= '</span><br />'.&mt('Others').': '.
2718: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2719: 'value="'.$otheremails{$type}.'" />';
2720: if ($type eq 'helpdeskmail') {
1.136 raeburn 2721: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2722: '<input type="text" name="'.$type.'_bcc" '.
2723: 'value="'.$bccemails{$type}.'" />';
2724: }
2725: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2726: $rownum ++;
1.28 raeburn 2727: }
1.203 raeburn 2728: my %choices;
2729: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2730: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2731: &mt('LON-CAPA core group - MSU'),600,500));
2732: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2733: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2734: &mt('LON-CAPA core group - MSU'),600,500));
2735: my @toggles = ('reporterrors','reportupdates');
2736: my %defaultchecked = ('reporterrors' => 'on',
2737: 'reportupdates' => 'on');
2738: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2739: \%choices,$rownum);
2740: $datatable .= $reports;
1.30 raeburn 2741: $$rowtotal += $rownum;
1.28 raeburn 2742: return $datatable;
2743: }
2744:
1.118 jms 2745: sub print_helpsettings {
1.168 raeburn 2746: my ($dom,$confname,$settings,$rowtotal) = @_;
2747: my ($datatable,$itemcount);
1.166 raeburn 2748: $itemcount = 1;
1.168 raeburn 2749: my (%choices,%defaultchecked,@toggles);
2750: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2751: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2752: &mt('LON-CAPA bug tracker'),600,500));
2753: %defaultchecked = ('submitbugs' => 'on');
2754: @toggles = ('submitbugs',);
1.166 raeburn 2755:
1.168 raeburn 2756: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2757: \%choices,$itemcount);
1.166 raeburn 2758: return $datatable;
1.121 raeburn 2759: }
2760:
2761: sub radiobutton_prefs {
1.192 raeburn 2762: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2763: $additional) = @_;
1.121 raeburn 2764: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2765: (ref($choices) eq 'HASH'));
2766:
1.170 raeburn 2767: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2768:
2769: foreach my $item (@{$toggles}) {
2770: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2771: $checkedon{$item} = ' checked="checked" ';
2772: $checkedoff{$item} = ' ';
1.121 raeburn 2773: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2774: $checkedoff{$item} = ' checked="checked" ';
2775: $checkedon{$item} = ' ';
2776: }
2777: }
2778: if (ref($settings) eq 'HASH') {
1.121 raeburn 2779: foreach my $item (@{$toggles}) {
1.118 jms 2780: if ($settings->{$item} eq '1') {
2781: $checkedon{$item} = ' checked="checked" ';
2782: $checkedoff{$item} = ' ';
2783: } elsif ($settings->{$item} eq '0') {
2784: $checkedoff{$item} = ' checked="checked" ';
2785: $checkedon{$item} = ' ';
2786: }
2787: }
1.121 raeburn 2788: }
1.192 raeburn 2789: if ($onclick) {
2790: $onclick = ' onclick="'.$onclick.'"';
2791: }
1.121 raeburn 2792: foreach my $item (@{$toggles}) {
1.118 jms 2793: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2794: $datatable .=
1.192 raeburn 2795: '<tr'.$css_class.'><td valign="top">'.
2796: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2797: '</span></td>'.
2798: '<td class="LC_right_item"><span class="LC_nobreak">'.
2799: '<label><input type="radio" name="'.
1.192 raeburn 2800: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2801: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2802: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2803: '</span>'.$additional.
2804: '</td>'.
1.118 jms 2805: '</tr>';
2806: $itemcount ++;
1.121 raeburn 2807: }
2808: return ($datatable,$itemcount);
2809: }
2810:
2811: sub print_coursedefaults {
1.139 raeburn 2812: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2813: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2814: my $itemcount = 1;
1.192 raeburn 2815: my %choices = &Apache::lonlocal::texthash (
2816: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2817: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2818: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2819: coursecredits => 'Credits can be specified for courses',
2820: );
1.198 raeburn 2821: my %staticdefaults = (
2822: anonsurvey_threshold => 10,
2823: uploadquota => 500,
2824: );
1.139 raeburn 2825: if ($position eq 'top') {
2826: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2827: @toggles = ('canuse_pdfforms');
1.139 raeburn 2828: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2829: \%choices,$itemcount);
1.139 raeburn 2830: } else {
2831: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2832: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2833: %curruploadquota);
1.192 raeburn 2834: my $currusecredits = 0;
1.216 raeburn 2835: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2836: if (ref($settings) eq 'HASH') {
2837: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2838: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2839: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2840: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2841: }
2842: }
1.192 raeburn 2843: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2844: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2845: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2846: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2847: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2848: ($def_textbook_credits ne '')) {
1.192 raeburn 2849: $currusecredits = 1;
2850: }
2851: }
1.139 raeburn 2852: }
2853: if (!$currdefresponder) {
1.198 raeburn 2854: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2855: } elsif ($currdefresponder < 1) {
2856: $currdefresponder = 1;
2857: }
1.198 raeburn 2858: foreach my $type (@types) {
2859: if ($curruploadquota{$type} eq '') {
2860: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2861: }
2862: }
1.139 raeburn 2863: $datatable .=
1.192 raeburn 2864: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2865: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2866: '</span></td>'.
2867: '<td class="LC_right_item"><span class="LC_nobreak">'.
2868: '<input type="text" name="anonsurvey_threshold"'.
2869: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2870: '</td></tr>'."\n";
2871: $itemcount ++;
2872: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2873: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2874: $choices{'uploadquota'}.
2875: '</span></td>'.
2876: '<td align="right" class="LC_right_item">'.
2877: '<table><tr>';
1.198 raeburn 2878: foreach my $type (@types) {
2879: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2880: '<input type="text" name="uploadquota_'.$type.'"'.
2881: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2882: }
2883: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2884: $itemcount ++;
1.236 raeburn 2885: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 2886: my $display = 'none';
1.192 raeburn 2887: if ($currusecredits) {
2888: $display = 'block';
2889: }
2890: my $additional = '<div id="credits" style="display: '.$display.'">'.
2891: '<span class="LC_nobreak">'.
2892: &mt('Default credits for official courses [_1]',
2893: '<input type="text" name="official_credits" value="'.
2894: $def_official_credits.'" size="3" />').
2895: '</span><br />'.
2896: '<span class="LC_nobreak">'.
2897: &mt('Default credits for unofficial courses [_1]',
2898: '<input type="text" name="unofficial_credits" value="'.
2899: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2900: '</span><br />'.
2901: '<span class="LC_nobreak">'.
2902: &mt('Default credits for textbook courses [_1]',
2903: '<input type="text" name="textbook_credits" value="'.
2904: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2905: '</span></div>'."\n";
2906: %defaultchecked = ('coursecredits' => 'off');
2907: @toggles = ('coursecredits');
2908: my $current = {
2909: 'coursecredits' => $currusecredits,
2910: };
2911: (my $table,$itemcount) =
2912: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2913: \%choices,$itemcount,$onclick,$additional);
2914: $datatable .= $table;
1.230 raeburn 2915: $itemcount ++;
1.139 raeburn 2916: }
1.192 raeburn 2917: $$rowtotal += $itemcount;
1.121 raeburn 2918: return $datatable;
1.118 jms 2919: }
2920:
1.231 raeburn 2921: sub print_selfenrollment {
2922: my ($position,$dom,$settings,$rowtotal) = @_;
2923: my ($css_class,$datatable);
2924: my $itemcount = 1;
2925: my @types = ('official','unofficial','community','textbook');
2926: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 2927: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2928: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 2929: my @rows;
2930: my $key;
2931: if ($position eq 'top') {
2932: $key = 'admin';
2933: if (ref($rowsref) eq 'ARRAY') {
2934: @rows = @{$rowsref};
2935: }
2936: } elsif ($position eq 'middle') {
2937: $key = 'default';
2938: @rows = ('types','registered','approval','limit');
2939: }
2940: foreach my $row (@rows) {
2941: if (defined($titlesref->{$row})) {
2942: $itemcount ++;
2943: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2944: $datatable .= '<tr'.$css_class.'>'.
2945: '<td>'.$titlesref->{$row}.'</td>'.
2946: '<td class="LC_left_item">'.
2947: '<table><tr>';
2948: my (%current,%currentcap);
2949: if (ref($settings) eq 'HASH') {
2950: if (ref($settings->{$key}) eq 'HASH') {
2951: foreach my $type (@types) {
2952: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2953: $current{$type} = $settings->{$key}->{$type}->{$row};
2954: }
2955: if (($row eq 'limit') && ($key eq 'default')) {
2956: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2957: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2958: }
2959: }
2960: }
2961: }
2962: }
2963: my %roles = (
2964: '0' => &Apache::lonnet::plaintext('dc'),
2965: );
2966:
2967: foreach my $type (@types) {
2968: unless (($row eq 'registered') && ($key eq 'default')) {
2969: $datatable .= '<th>'.&mt($type).'</th>';
2970: }
2971: }
2972: unless (($row eq 'registered') && ($key eq 'default')) {
2973: $datatable .= '</tr><tr>';
2974: }
2975: foreach my $type (@types) {
2976: if ($type eq 'community') {
2977: $roles{'1'} = &mt('Community personnel');
2978: } else {
2979: $roles{'1'} = &mt('Course personnel');
2980: }
2981: $datatable .= '<td style="vertical-align: top">';
2982: if ($position eq 'top') {
2983: my %checked;
2984: if ($current{$type} eq '0') {
2985: $checked{'0'} = ' checked="checked"';
2986: } else {
2987: $checked{'1'} = ' checked="checked"';
2988: }
2989: foreach my $role ('1','0') {
2990: $datatable .= '<span class="LC_nobreak"><label>'.
2991: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2992: 'value="'.$role.'"'.$checked{$role}.' />'.
2993: $roles{$role}.'</label></span> ';
2994: }
2995: } else {
2996: if ($row eq 'types') {
2997: my %checked;
2998: if ($current{$type} =~ /^(all|dom)$/) {
2999: $checked{$1} = ' checked="checked"';
3000: } else {
3001: $checked{''} = ' checked="checked"';
3002: }
3003: foreach my $val ('','dom','all') {
3004: $datatable .= '<span class="LC_nobreak"><label>'.
3005: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3006: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3007: }
3008: } elsif ($row eq 'registered') {
3009: my %checked;
3010: if ($current{$type} eq '1') {
3011: $checked{'1'} = ' checked="checked"';
3012: } else {
3013: $checked{'0'} = ' checked="checked"';
3014: }
3015: foreach my $val ('0','1') {
3016: $datatable .= '<span class="LC_nobreak"><label>'.
3017: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3018: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3019: }
3020: } elsif ($row eq 'approval') {
3021: my %checked;
3022: if ($current{$type} =~ /^([12])$/) {
3023: $checked{$1} = ' checked="checked"';
3024: } else {
3025: $checked{'0'} = ' checked="checked"';
3026: }
3027: for my $val (0..2) {
3028: $datatable .= '<span class="LC_nobreak"><label>'.
3029: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3030: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3031: }
3032: } elsif ($row eq 'limit') {
3033: my %checked;
3034: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3035: $checked{$1} = ' checked="checked"';
3036: } else {
3037: $checked{'none'} = ' checked="checked"';
3038: }
3039: my $cap;
3040: if ($currentcap{$type} =~ /^\d+$/) {
3041: $cap = $currentcap{$type};
3042: }
3043: foreach my $val ('none','allstudents','selfenrolled') {
3044: $datatable .= '<span class="LC_nobreak"><label>'.
3045: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3046: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3047: }
3048: $datatable .= '<br />'.
3049: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3050: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3051: '</span>';
3052: }
3053: }
3054: $datatable .= '</td>';
3055: }
3056: $datatable .= '</tr>';
3057: }
3058: $datatable .= '</table></td></tr>';
3059: }
3060: } elsif ($position eq 'bottom') {
1.235 raeburn 3061: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3062: }
3063: $$rowtotal += $itemcount;
3064: return $datatable;
3065: }
3066:
3067: sub print_validation_rows {
3068: my ($caller,$dom,$settings,$rowtotal) = @_;
3069: my ($itemsref,$namesref,$fieldsref);
3070: if ($caller eq 'selfenroll') {
3071: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3072: } elsif ($caller eq 'requestcourses') {
3073: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3074: }
3075: my %currvalidation;
3076: if (ref($settings) eq 'HASH') {
3077: if (ref($settings->{'validation'}) eq 'HASH') {
3078: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3079: }
1.235 raeburn 3080: }
3081: my $datatable;
3082: my $itemcount = 0;
3083: foreach my $item (@{$itemsref}) {
3084: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3085: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3086: $namesref->{$item}.
3087: '</span></td>'.
3088: '<td class="LC_left_item">';
3089: if (($item eq 'url') || ($item eq 'button')) {
3090: $datatable .= '<span class="LC_nobreak">'.
3091: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3092: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3093: } elsif ($item eq 'fields') {
3094: my @currfields;
3095: if (ref($currvalidation{$item}) eq 'ARRAY') {
3096: @currfields = @{$currvalidation{$item}};
3097: }
3098: foreach my $field (@{$fieldsref}) {
3099: my $check = '';
3100: if (grep(/^\Q$field\E$/,@currfields)) {
3101: $check = ' checked="checked"';
3102: }
3103: $datatable .= '<span class="LC_nobreak"><label>'.
3104: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3105: ' value="'.$field.'"'.$check.' />'.$field.
3106: '</label></span> ';
3107: }
3108: } elsif ($item eq 'markup') {
3109: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3110: $currvalidation{$item}.
1.231 raeburn 3111: '</textarea>';
1.235 raeburn 3112: }
3113: $datatable .= '</td></tr>'."\n";
3114: if (ref($rowtotal)) {
1.231 raeburn 3115: $itemcount ++;
3116: }
3117: }
1.235 raeburn 3118: if ($caller eq 'requestcourses') {
3119: my %currhash;
3120: if (ref($settings->{'validation'}) eq 'HASH') {
3121: if ($settings->{'validation'}{'dc'} ne '') {
3122: $currhash{$settings->{'validation'}{'dc'}} = 1;
3123: }
3124: }
3125: my $numinrow = 2;
3126: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3127: 'validationdc',%currhash);
3128: if ($numdc > 1) {
3129: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3130: &mt('Course creation processed as: (choose Dom. Coord.)').
3131: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3132: } else {
3133: $datatable .= $dctable.'</td></tr>';
3134: }
3135: $itemcount ++;
3136: }
3137: if (ref($rowtotal)) {
3138: $$rowtotal += $itemcount;
3139: }
1.231 raeburn 3140: return $datatable;
3141: }
3142:
1.137 raeburn 3143: sub print_usersessions {
3144: my ($position,$dom,$settings,$rowtotal) = @_;
3145: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3146: my (%by_ip,%by_location,@intdoms);
3147: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3148:
3149: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3150: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3151: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3152: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3153: my $itemcount = 1;
3154: if ($position eq 'top') {
1.152 raeburn 3155: if (keys(%serverhomes) > 1) {
1.145 raeburn 3156: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3157: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3158: } else {
1.140 raeburn 3159: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3160: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3161: }
1.137 raeburn 3162: } else {
1.145 raeburn 3163: if (keys(%by_location) == 0) {
3164: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3165: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3166: } else {
3167: my %lt = &usersession_titles();
3168: my $numinrow = 5;
3169: my $prefix;
3170: my @types;
3171: if ($position eq 'bottom') {
3172: $prefix = 'remote';
3173: @types = ('version','excludedomain','includedomain');
3174: } else {
3175: $prefix = 'hosted';
3176: @types = ('excludedomain','includedomain');
3177: }
3178: my (%current,%checkedon,%checkedoff);
3179: my @lcversions = &Apache::lonnet::all_loncaparevs();
3180: my @locations = sort(keys(%by_location));
3181: foreach my $type (@types) {
3182: $checkedon{$type} = '';
3183: $checkedoff{$type} = ' checked="checked"';
3184: }
3185: if (ref($settings) eq 'HASH') {
3186: if (ref($settings->{$prefix}) eq 'HASH') {
3187: foreach my $key (keys(%{$settings->{$prefix}})) {
3188: $current{$key} = $settings->{$prefix}{$key};
3189: if ($key eq 'version') {
3190: if ($current{$key} ne '') {
3191: $checkedon{$key} = ' checked="checked"';
3192: $checkedoff{$key} = '';
3193: }
3194: } elsif (ref($current{$key}) eq 'ARRAY') {
3195: $checkedon{$key} = ' checked="checked"';
3196: $checkedoff{$key} = '';
3197: }
1.137 raeburn 3198: }
3199: }
3200: }
1.145 raeburn 3201: foreach my $type (@types) {
3202: next if ($type ne 'version' && !@locations);
3203: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3204: $datatable .= '<tr'.$css_class.'>
3205: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3206: <span class="LC_nobreak">
3207: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3208: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3209: if ($type eq 'version') {
3210: my $selector = '<select name="'.$prefix.'_version">';
3211: foreach my $version (@lcversions) {
3212: my $selected = '';
3213: if ($current{'version'} eq $version) {
3214: $selected = ' selected="selected"';
3215: }
3216: $selector .= ' <option value="'.$version.'"'.
3217: $selected.'>'.$version.'</option>';
3218: }
3219: $selector .= '</select> ';
3220: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3221: } else {
3222: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3223: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3224: ' />'.(' 'x2).
3225: '<input type="button" value="'.&mt('uncheck all').'" '.
3226: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3227: "\n".
3228: '</div><div><table>';
3229: my $rem;
3230: for (my $i=0; $i<@locations; $i++) {
3231: my ($showloc,$value,$checkedtype);
3232: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3233: my $ip = $by_location{$locations[$i]}->[0];
3234: if (ref($by_ip{$ip}) eq 'ARRAY') {
3235: $value = join(':',@{$by_ip{$ip}});
3236: $showloc = join(', ',@{$by_ip{$ip}});
3237: if (ref($current{$type}) eq 'ARRAY') {
3238: foreach my $loc (@{$by_ip{$ip}}) {
3239: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3240: $checkedtype = ' checked="checked"';
3241: last;
3242: }
3243: }
1.138 raeburn 3244: }
3245: }
3246: }
1.145 raeburn 3247: $rem = $i%($numinrow);
3248: if ($rem == 0) {
3249: if ($i > 0) {
3250: $datatable .= '</tr>';
3251: }
3252: $datatable .= '<tr>';
3253: }
3254: $datatable .= '<td class="LC_left_item">'.
3255: '<span class="LC_nobreak"><label>'.
3256: '<input type="checkbox" name="'.$prefix.'_'.$type.
3257: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3258: '</label></span></td>';
1.137 raeburn 3259: }
1.145 raeburn 3260: $rem = @locations%($numinrow);
3261: my $colsleft = $numinrow - $rem;
3262: if ($colsleft > 1 ) {
3263: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3264: ' </td>';
3265: } elsif ($colsleft == 1) {
3266: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3267: }
1.145 raeburn 3268: $datatable .= '</tr></table>';
1.137 raeburn 3269: }
1.145 raeburn 3270: $datatable .= '</td></tr>';
3271: $itemcount ++;
1.137 raeburn 3272: }
3273: }
3274: }
3275: $$rowtotal += $itemcount;
3276: return $datatable;
3277: }
3278:
1.138 raeburn 3279: sub build_location_hashes {
3280: my ($intdoms,$by_ip,$by_location) = @_;
3281: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3282: (ref($by_location) eq 'HASH'));
3283: my %iphost = &Apache::lonnet::get_iphost();
3284: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3285: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3286: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3287: foreach my $id (@{$iphost{$primary_ip}}) {
3288: my $intdom = &Apache::lonnet::internet_dom($id);
3289: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3290: push(@{$intdoms},$intdom);
3291: }
3292: }
3293: }
3294: foreach my $ip (keys(%iphost)) {
3295: if (ref($iphost{$ip}) eq 'ARRAY') {
3296: foreach my $id (@{$iphost{$ip}}) {
3297: my $location = &Apache::lonnet::internet_dom($id);
3298: if ($location) {
3299: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3300: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3301: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3302: push(@{$by_ip->{$ip}},$location);
3303: }
3304: } else {
3305: $by_ip->{$ip} = [$location];
3306: }
3307: }
3308: }
3309: }
3310: }
3311: foreach my $ip (sort(keys(%{$by_ip}))) {
3312: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3313: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3314: my $first = $by_ip->{$ip}->[0];
3315: if (ref($by_location->{$first}) eq 'ARRAY') {
3316: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3317: push(@{$by_location->{$first}},$ip);
3318: }
3319: } else {
3320: $by_location->{$first} = [$ip];
3321: }
3322: }
3323: }
3324: return;
3325: }
3326:
1.145 raeburn 3327: sub current_offloads_to {
3328: my ($dom,$settings,$servers) = @_;
3329: my (%spareid,%otherdomconfigs);
1.152 raeburn 3330: if (ref($servers) eq 'HASH') {
1.145 raeburn 3331: foreach my $lonhost (sort(keys(%{$servers}))) {
3332: my $gotspares;
1.152 raeburn 3333: if (ref($settings) eq 'HASH') {
3334: if (ref($settings->{'spares'}) eq 'HASH') {
3335: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3336: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3337: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3338: $gotspares = 1;
3339: }
1.145 raeburn 3340: }
3341: }
3342: unless ($gotspares) {
3343: my $gotspares;
3344: my $serverhomeID =
3345: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3346: my $serverhomedom =
3347: &Apache::lonnet::host_domain($serverhomeID);
3348: if ($serverhomedom ne $dom) {
3349: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3350: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3351: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3352: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3353: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3354: $gotspares = 1;
3355: }
3356: }
3357: } else {
3358: $otherdomconfigs{$serverhomedom} =
3359: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3360: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3361: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3362: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3363: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3364: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3365: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3366: $gotspares = 1;
3367: }
3368: }
3369: }
3370: }
3371: }
3372: }
3373: }
3374: unless ($gotspares) {
3375: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3376: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3377: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3378: } else {
3379: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3380: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3381: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3382: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3383: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3384: } else {
1.150 raeburn 3385: my %what = (
3386: spareid => 1,
3387: );
3388: my ($result,$returnhash) =
3389: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3390: if ($result eq 'ok') {
3391: if (ref($returnhash) eq 'HASH') {
3392: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3393: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3394: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3395: }
3396: }
1.145 raeburn 3397: }
3398: }
3399: }
3400: }
3401: }
3402: }
3403: return %spareid;
3404: }
3405:
3406: sub spares_row {
1.152 raeburn 3407: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3408: my $css_class;
3409: my $numinrow = 4;
3410: my $itemcount = 1;
3411: my $datatable;
1.152 raeburn 3412: my %typetitles = &sparestype_titles();
3413: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3414: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3415: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3416: my ($othercontrol,$serverdom);
3417: if ($serverhome ne $server) {
3418: $serverdom = &Apache::lonnet::host_domain($serverhome);
3419: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3420: } else {
3421: $serverdom = &Apache::lonnet::host_domain($server);
3422: if ($serverdom ne $dom) {
3423: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3424: }
3425: }
3426: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3427: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3428: $datatable .= '<tr'.$css_class.'>
3429: <td rowspan="2">
1.183 bisitz 3430: <span class="LC_nobreak">'.
3431: &mt('[_1] when busy, offloads to:'
3432: ,'<b>'.$server.'</b>').
3433: "\n";
1.145 raeburn 3434: my (%current,%canselect);
1.152 raeburn 3435: my @choices =
3436: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3437: foreach my $type ('primary','default') {
3438: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3439: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3440: my @spares = @{$spareid->{$server}{$type}};
3441: if (@spares > 0) {
1.152 raeburn 3442: if ($othercontrol) {
3443: $current{$type} = join(', ',@spares);
3444: } else {
3445: $current{$type} .= '<table>';
3446: my $numspares = scalar(@spares);
3447: for (my $i=0; $i<@spares; $i++) {
3448: my $rem = $i%($numinrow);
3449: if ($rem == 0) {
3450: if ($i > 0) {
3451: $current{$type} .= '</tr>';
3452: }
3453: $current{$type} .= '<tr>';
1.145 raeburn 3454: }
1.152 raeburn 3455: $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'".');" /> '.
3456: $spareid->{$server}{$type}[$i].
3457: '</label></td>'."\n";
3458: }
3459: my $rem = @spares%($numinrow);
3460: my $colsleft = $numinrow - $rem;
3461: if ($colsleft > 1 ) {
3462: $current{$type} .= '<td colspan="'.$colsleft.
3463: '" class="LC_left_item">'.
3464: ' </td>';
3465: } elsif ($colsleft == 1) {
3466: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3467: }
1.152 raeburn 3468: $current{$type} .= '</tr></table>';
1.150 raeburn 3469: }
1.145 raeburn 3470: }
3471: }
3472: if ($current{$type} eq '') {
3473: $current{$type} = &mt('None specified');
3474: }
1.152 raeburn 3475: if ($othercontrol) {
3476: if ($type eq 'primary') {
3477: $canselect{$type} = $othercontrol;
3478: }
3479: } else {
3480: $canselect{$type} =
3481: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3482: '<select name="newspare_'.$type.'_'.$server.'" '.
3483: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3484: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3485: if (@choices > 0) {
3486: foreach my $lonhost (@choices) {
3487: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3488: }
3489: }
3490: $canselect{$type} .= '</select>'."\n";
3491: }
3492: } else {
3493: $current{$type} = &mt('Could not be determined');
3494: if ($type eq 'primary') {
3495: $canselect{$type} = $othercontrol;
3496: }
1.145 raeburn 3497: }
1.152 raeburn 3498: if ($type eq 'default') {
3499: $datatable .= '<tr'.$css_class.'>';
3500: }
3501: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3502: '<td>'.$current{$type}.'</td>'."\n".
3503: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3504: }
3505: $itemcount ++;
3506: }
3507: }
3508: $$rowtotal += $itemcount;
3509: return $datatable;
3510: }
3511:
1.152 raeburn 3512: sub possible_newspares {
3513: my ($server,$currspares,$serverhomes,$altids) = @_;
3514: my $serverhostname = &Apache::lonnet::hostname($server);
3515: my %excluded;
3516: if ($serverhostname ne '') {
3517: %excluded = (
3518: $serverhostname => 1,
3519: );
3520: }
3521: if (ref($currspares) eq 'HASH') {
3522: foreach my $type (keys(%{$currspares})) {
3523: if (ref($currspares->{$type}) eq 'ARRAY') {
3524: if (@{$currspares->{$type}} > 0) {
3525: foreach my $curr (@{$currspares->{$type}}) {
3526: my $hostname = &Apache::lonnet::hostname($curr);
3527: $excluded{$hostname} = 1;
3528: }
3529: }
3530: }
3531: }
3532: }
3533: my @choices;
3534: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3535: if (keys(%{$serverhomes}) > 1) {
3536: foreach my $name (sort(keys(%{$serverhomes}))) {
3537: unless ($excluded{$name}) {
3538: if (exists($altids->{$serverhomes->{$name}})) {
3539: push(@choices,$altids->{$serverhomes->{$name}});
3540: } else {
3541: push(@choices,$serverhomes->{$name});
1.145 raeburn 3542: }
3543: }
3544: }
3545: }
3546: }
1.152 raeburn 3547: return sort(@choices);
1.145 raeburn 3548: }
3549:
1.150 raeburn 3550: sub print_loadbalancing {
3551: my ($dom,$settings,$rowtotal) = @_;
3552: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3553: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3554: my $numinrow = 1;
3555: my $datatable;
3556: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3557: my (%currbalancer,%currtargets,%currrules,%existing);
3558: if (ref($settings) eq 'HASH') {
3559: %existing = %{$settings};
3560: }
3561: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3562: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3563: \%currtargets,\%currrules);
1.150 raeburn 3564: } else {
3565: return;
3566: }
3567: my ($othertitle,$usertypes,$types) =
3568: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3569: my $rownum = 8;
1.150 raeburn 3570: if (ref($types) eq 'ARRAY') {
3571: $rownum += scalar(@{$types});
3572: }
1.171 raeburn 3573: my @css_class = ('LC_odd_row','LC_even_row');
3574: my $balnum = 0;
3575: my $islast;
3576: my (@toshow,$disabledtext);
3577: if (keys(%currbalancer) > 0) {
3578: @toshow = sort(keys(%currbalancer));
3579: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3580: push(@toshow,'');
3581: }
3582: } else {
3583: @toshow = ('');
3584: $disabledtext = &mt('No existing load balancer');
3585: }
3586: foreach my $lonhost (@toshow) {
3587: if ($balnum == scalar(@toshow)-1) {
3588: $islast = 1;
3589: } else {
3590: $islast = 0;
3591: }
3592: my $cssidx = $balnum%2;
3593: my $targets_div_style = 'display: none';
3594: my $disabled_div_style = 'display: block';
3595: my $homedom_div_style = 'display: none';
3596: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3597: '<td rowspan="'.$rownum.'" valign="top">'.
3598: '<p>';
3599: if ($lonhost eq '') {
1.210 raeburn 3600: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3601: if (keys(%currbalancer) > 0) {
3602: $datatable .= &mt('Add balancer:');
3603: } else {
3604: $datatable .= &mt('Enable balancer:');
3605: }
3606: $datatable .= ' '.
3607: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3608: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3609: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3610: '<option value="" selected="selected">'.&mt('None').
3611: '</option>'."\n";
3612: foreach my $server (sort(keys(%servers))) {
3613: next if ($currbalancer{$server});
3614: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3615: }
1.210 raeburn 3616: $datatable .=
1.171 raeburn 3617: '</select>'."\n".
3618: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3619: } else {
3620: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3621: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3622: &mt('Stop balancing').'</label>'.
3623: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3624: $targets_div_style = 'display: block';
3625: $disabled_div_style = 'display: none';
3626: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3627: $homedom_div_style = 'display: block';
3628: }
3629: }
3630: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3631: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3632: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3633: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3634: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3635: my @sparestypes = ('primary','default');
3636: my %typetitles = &sparestype_titles();
3637: foreach my $sparetype (@sparestypes) {
3638: my $targettable;
3639: for (my $i=0; $i<$numspares; $i++) {
3640: my $checked;
3641: if (ref($currtargets{$lonhost}) eq 'HASH') {
3642: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3643: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3644: $checked = ' checked="checked"';
3645: }
3646: }
3647: }
3648: my ($chkboxval,$disabled);
3649: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3650: $chkboxval = $spares[$i];
3651: }
3652: if (exists($currbalancer{$spares[$i]})) {
3653: $disabled = ' disabled="disabled"';
3654: }
1.210 raeburn 3655: $targettable .=
1.171 raeburn 3656: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3657: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3658: '</span></label></td>';
3659: my $rem = $i%($numinrow);
3660: if ($rem == 0) {
3661: if (($i > 0) && ($i < $numspares-1)) {
3662: $targettable .= '</tr>';
3663: }
3664: if ($i < $numspares-1) {
3665: $targettable .= '<tr>';
1.150 raeburn 3666: }
3667: }
3668: }
1.171 raeburn 3669: if ($targettable ne '') {
3670: my $rem = $numspares%($numinrow);
3671: my $colsleft = $numinrow - $rem;
3672: if ($colsleft > 1 ) {
3673: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3674: ' </td>';
3675: } elsif ($colsleft == 1) {
3676: $targettable .= '<td class="LC_left_item"> </td>';
3677: }
3678: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3679: '<table><tr>'.$targettable.'</tr></table><br />';
3680: }
3681: }
3682: $datatable .= '</div></td></tr>'.
3683: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3684: $othertitle,$usertypes,$types,\%servers,
3685: \%currbalancer,$lonhost,
3686: $targets_div_style,$homedom_div_style,
3687: $css_class[$cssidx],$balnum,$islast);
3688: $$rowtotal += $rownum;
3689: $balnum ++;
3690: }
3691: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3692: return $datatable;
3693: }
3694:
3695: sub get_loadbalancers_config {
3696: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3697: return unless ((ref($servers) eq 'HASH') &&
3698: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3699: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3700: if (keys(%{$existing}) > 0) {
3701: my $oldlonhost;
3702: foreach my $key (sort(keys(%{$existing}))) {
3703: if ($key eq 'lonhost') {
3704: $oldlonhost = $existing->{'lonhost'};
3705: $currbalancer->{$oldlonhost} = 1;
3706: } elsif ($key eq 'targets') {
3707: if ($oldlonhost) {
3708: $currtargets->{$oldlonhost} = $existing->{'targets'};
3709: }
3710: } elsif ($key eq 'rules') {
3711: if ($oldlonhost) {
3712: $currrules->{$oldlonhost} = $existing->{'rules'};
3713: }
3714: } elsif (ref($existing->{$key}) eq 'HASH') {
3715: $currbalancer->{$key} = 1;
3716: $currtargets->{$key} = $existing->{$key}{'targets'};
3717: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3718: }
3719: }
1.171 raeburn 3720: } else {
3721: my ($balancerref,$targetsref) =
3722: &Apache::lonnet::get_lonbalancer_config($servers);
3723: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3724: foreach my $server (sort(keys(%{$balancerref}))) {
3725: $currbalancer->{$server} = 1;
3726: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3727: }
3728: }
3729: }
1.171 raeburn 3730: return;
1.150 raeburn 3731: }
3732:
3733: sub loadbalancing_rules {
3734: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3735: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3736: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3737: my $output;
1.171 raeburn 3738: my $num = 0;
1.210 raeburn 3739: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3740: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3741: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3742: foreach my $type (@{$alltypes}) {
1.171 raeburn 3743: $num ++;
1.150 raeburn 3744: my $current;
3745: if (ref($currrules) eq 'HASH') {
3746: $current = $currrules->{$type};
3747: }
1.209 raeburn 3748: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3749: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3750: $current = '';
3751: }
3752: }
3753: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3754: $servers,$currbalancer,$lonhost,$dom,
3755: $targets_div_style,$homedom_div_style,
3756: $css_class,$balnum,$num,$islast);
1.150 raeburn 3757: }
3758: }
3759: return $output;
3760: }
3761:
3762: sub loadbalancing_titles {
3763: my ($dom,$intdom,$usertypes,$types) = @_;
3764: my %othertypes = (
3765: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3766: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3767: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3768: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3769: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3770: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3771: );
1.209 raeburn 3772: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3773: if (ref($types) eq 'ARRAY') {
3774: unshift(@alltypes,@{$types},'default');
3775: }
3776: my %titles;
3777: foreach my $type (@alltypes) {
3778: if ($type =~ /^_LC_/) {
3779: $titles{$type} = $othertypes{$type};
3780: } elsif ($type eq 'default') {
3781: $titles{$type} = &mt('All users from [_1]',$dom);
3782: if (ref($types) eq 'ARRAY') {
3783: if (@{$types} > 0) {
3784: $titles{$type} = &mt('Other users from [_1]',$dom);
3785: }
3786: }
3787: } elsif (ref($usertypes) eq 'HASH') {
3788: $titles{$type} = $usertypes->{$type};
3789: }
3790: }
3791: return (\@alltypes,\%othertypes,\%titles);
3792: }
3793:
3794: sub loadbalance_rule_row {
1.171 raeburn 3795: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3796: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3797: my @rulenames;
1.150 raeburn 3798: my %ruletitles = &offloadtype_text();
1.209 raeburn 3799: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3800: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3801: } else {
1.209 raeburn 3802: @rulenames = ('default','homeserver');
3803: if ($type eq '_LC_external') {
3804: push(@rulenames,'externalbalancer');
3805: } else {
3806: push(@rulenames,'specific');
3807: }
3808: push(@rulenames,'none');
1.150 raeburn 3809: }
3810: my $style = $targets_div_style;
1.209 raeburn 3811: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3812: $style = $homedom_div_style;
3813: }
1.171 raeburn 3814: my $space;
3815: if ($islast && $num == 1) {
3816: $space = '<div display="inline-block"> </div>';
3817: }
1.210 raeburn 3818: my $output =
1.171 raeburn 3819: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3820: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3821: '<td valaign="top">'.$space.
3822: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3823: for (my $i=0; $i<@rulenames; $i++) {
3824: my $rule = $rulenames[$i];
3825: my ($checked,$extra);
3826: if ($rulenames[$i] eq 'default') {
3827: $rule = '';
3828: }
3829: if ($rulenames[$i] eq 'specific') {
3830: if (ref($servers) eq 'HASH') {
3831: my $default;
3832: if (($current ne '') && (exists($servers->{$current}))) {
3833: $checked = ' checked="checked"';
3834: }
3835: unless ($checked) {
3836: $default = ' selected="selected"';
3837: }
1.210 raeburn 3838: $extra =
1.171 raeburn 3839: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3840: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3841: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3842: '<option value=""'.$default.'></option>'."\n";
3843: foreach my $server (sort(keys(%{$servers}))) {
3844: if (ref($currbalancer) eq 'HASH') {
3845: next if (exists($currbalancer->{$server}));
3846: }
1.150 raeburn 3847: my $selected;
1.171 raeburn 3848: if ($server eq $current) {
1.150 raeburn 3849: $selected = ' selected="selected"';
3850: }
1.171 raeburn 3851: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3852: }
3853: $extra .= '</select>';
3854: }
3855: } elsif ($rule eq $current) {
3856: $checked = ' checked="checked"';
3857: }
3858: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3859: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3860: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3861: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3862: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3863: '</label>'.$extra.'</span><br />'."\n";
3864: }
3865: $output .= '</div></td></tr>'."\n";
3866: return $output;
3867: }
3868:
3869: sub offloadtype_text {
3870: my %ruletitles = &Apache::lonlocal::texthash (
3871: 'default' => 'Offloads to default destinations',
3872: 'homeserver' => "Offloads to user's home server",
3873: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3874: 'specific' => 'Offloads to specific server',
1.161 raeburn 3875: 'none' => 'No offload',
1.209 raeburn 3876: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3877: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3878: );
3879: return %ruletitles;
3880: }
3881:
3882: sub sparestype_titles {
3883: my %typestitles = &Apache::lonlocal::texthash (
3884: 'primary' => 'primary',
3885: 'default' => 'default',
3886: );
3887: return %typestitles;
3888: }
3889:
1.28 raeburn 3890: sub contact_titles {
3891: my %titles = &Apache::lonlocal::texthash (
3892: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3893: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3894: 'errormail' => 'Error reports to be e-mailed to',
3895: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3896: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3897: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3898: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3899: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3900: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3901: );
3902: my %short_titles = &Apache::lonlocal::texthash (
3903: adminemail => 'Admin E-mail address',
3904: supportemail => 'Support E-mail',
3905: );
3906: return (\%titles,\%short_titles);
3907: }
3908:
1.72 raeburn 3909: sub tool_titles {
3910: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3911: aboutme => 'Personal web page',
1.86 raeburn 3912: blog => 'Blog',
1.162 raeburn 3913: webdav => 'WebDAV',
1.86 raeburn 3914: portfolio => 'Portfolio',
1.88 bisitz 3915: official => 'Official courses (with institutional codes)',
3916: unofficial => 'Unofficial courses',
1.98 raeburn 3917: community => 'Communities',
1.216 raeburn 3918: textbook => 'Textbook courses',
1.86 raeburn 3919: );
1.72 raeburn 3920: return %titles;
3921: }
3922:
1.101 raeburn 3923: sub courserequest_titles {
3924: my %titles = &Apache::lonlocal::texthash (
3925: official => 'Official',
3926: unofficial => 'Unofficial',
3927: community => 'Communities',
1.216 raeburn 3928: textbook => 'Textbook',
1.101 raeburn 3929: norequest => 'Not allowed',
1.104 raeburn 3930: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3931: validate => 'With validation',
3932: autolimit => 'Numerical limit',
1.103 raeburn 3933: unlimited => '(blank for unlimited)',
1.101 raeburn 3934: );
3935: return %titles;
3936: }
3937:
1.163 raeburn 3938: sub authorrequest_titles {
3939: my %titles = &Apache::lonlocal::texthash (
3940: norequest => 'Not allowed',
3941: approval => 'Approval by Dom. Coord.',
3942: automatic => 'Automatic approval',
3943: );
3944: return %titles;
1.210 raeburn 3945: }
1.163 raeburn 3946:
1.101 raeburn 3947: sub courserequest_conditions {
3948: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3949: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3950: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3951: );
3952: return %conditions;
3953: }
3954:
3955:
1.27 raeburn 3956: sub print_usercreation {
1.30 raeburn 3957: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3958: my $numinrow = 4;
1.28 raeburn 3959: my $datatable;
3960: if ($position eq 'top') {
1.30 raeburn 3961: $$rowtotal ++;
1.34 raeburn 3962: my $rowcount = 0;
1.32 raeburn 3963: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3964: if (ref($rules) eq 'HASH') {
3965: if (keys(%{$rules}) > 0) {
1.32 raeburn 3966: $datatable .= &user_formats_row('username',$settings,$rules,
3967: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3968: $$rowtotal ++;
1.32 raeburn 3969: $rowcount ++;
3970: }
3971: }
3972: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3973: if (ref($idrules) eq 'HASH') {
3974: if (keys(%{$idrules}) > 0) {
3975: $datatable .= &user_formats_row('id',$settings,$idrules,
3976: $idruleorder,$numinrow,$rowcount);
3977: $$rowtotal ++;
3978: $rowcount ++;
1.28 raeburn 3979: }
3980: }
1.39 raeburn 3981: if ($rowcount == 0) {
3982: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3983: $$rowtotal ++;
3984: $rowcount ++;
3985: }
1.34 raeburn 3986: } elsif ($position eq 'middle') {
1.224 raeburn 3987: my @creators = ('author','course','requestcrs');
1.37 raeburn 3988: my ($rules,$ruleorder) =
3989: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3990: my %lt = &usercreation_types();
3991: my %checked;
3992: if (ref($settings) eq 'HASH') {
3993: if (ref($settings->{'cancreate'}) eq 'HASH') {
3994: foreach my $item (@creators) {
3995: $checked{$item} = $settings->{'cancreate'}{$item};
3996: }
3997: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3998: foreach my $item (@creators) {
3999: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4000: $checked{$item} = 'none';
4001: }
4002: }
4003: }
4004: }
4005: my $rownum = 0;
4006: foreach my $item (@creators) {
4007: $rownum ++;
1.224 raeburn 4008: if ($checked{$item} eq '') {
4009: $checked{$item} = 'any';
1.34 raeburn 4010: }
4011: my $css_class;
4012: if ($rownum%2) {
4013: $css_class = '';
4014: } else {
4015: $css_class = ' class="LC_odd_row" ';
4016: }
4017: $datatable .= '<tr'.$css_class.'>'.
4018: '<td><span class="LC_nobreak">'.$lt{$item}.
4019: '</span></td><td align="right">';
1.224 raeburn 4020: my @options = ('any');
4021: if (ref($rules) eq 'HASH') {
4022: if (keys(%{$rules}) > 0) {
4023: push(@options,('official','unofficial'));
1.37 raeburn 4024: }
4025: }
1.224 raeburn 4026: push(@options,'none');
1.37 raeburn 4027: foreach my $option (@options) {
1.50 raeburn 4028: my $type = 'radio';
1.34 raeburn 4029: my $check = ' ';
1.224 raeburn 4030: if ($checked{$item} eq $option) {
4031: $check = ' checked="checked" ';
1.34 raeburn 4032: }
4033: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4034: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4035: $item.'" value="'.$option.'"'.$check.'/> '.
4036: $lt{$option}.'</label> </span>';
4037: }
4038: $datatable .= '</td></tr>';
4039: }
1.28 raeburn 4040: } else {
4041: my @contexts = ('author','course','domain');
4042: my @authtypes = ('int','krb4','krb5','loc');
4043: my %checked;
4044: if (ref($settings) eq 'HASH') {
4045: if (ref($settings->{'authtypes'}) eq 'HASH') {
4046: foreach my $item (@contexts) {
4047: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4048: foreach my $auth (@authtypes) {
4049: if ($settings->{'authtypes'}{$item}{$auth}) {
4050: $checked{$item}{$auth} = ' checked="checked" ';
4051: }
4052: }
4053: }
4054: }
1.27 raeburn 4055: }
1.35 raeburn 4056: } else {
4057: foreach my $item (@contexts) {
1.36 raeburn 4058: foreach my $auth (@authtypes) {
1.35 raeburn 4059: $checked{$item}{$auth} = ' checked="checked" ';
4060: }
4061: }
1.27 raeburn 4062: }
1.28 raeburn 4063: my %title = &context_names();
4064: my %authname = &authtype_names();
4065: my $rownum = 0;
4066: my $css_class;
4067: foreach my $item (@contexts) {
4068: if ($rownum%2) {
4069: $css_class = '';
4070: } else {
4071: $css_class = ' class="LC_odd_row" ';
4072: }
1.30 raeburn 4073: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4074: '<td>'.$title{$item}.
4075: '</td><td class="LC_left_item">'.
4076: '<span class="LC_nobreak">';
4077: foreach my $auth (@authtypes) {
4078: $datatable .= '<label>'.
4079: '<input type="checkbox" name="'.$item.'_auth" '.
4080: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4081: $authname{$auth}.'</label> ';
4082: }
4083: $datatable .= '</span></td></tr>';
4084: $rownum ++;
1.27 raeburn 4085: }
1.30 raeburn 4086: $$rowtotal += $rownum;
1.27 raeburn 4087: }
4088: return $datatable;
4089: }
4090:
1.224 raeburn 4091: sub print_selfcreation {
4092: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4093: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4094: if (ref($settings) eq 'HASH') {
4095: if (ref($settings->{'cancreate'}) eq 'HASH') {
4096: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4097: if (ref($createsettings) eq 'HASH') {
4098: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4099: @selfcreate = @{$createsettings->{'selfcreate'}};
4100: } elsif ($createsettings->{'selfcreate'} ne '') {
4101: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4102: @selfcreate = ('email','login','sso');
4103: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4104: @selfcreate = ($createsettings->{'selfcreate'});
4105: }
4106: }
4107: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4108: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4109: }
4110: }
4111: }
4112: }
4113: my %radiohash;
4114: my $numinrow = 4;
4115: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4116: if ($position eq 'top') {
4117: my %choices = &Apache::lonlocal::texthash (
4118: cancreate_login => 'Institutional Login',
4119: cancreate_sso => 'Institutional Single Sign On',
4120: );
4121: my @toggles = sort(keys(%choices));
4122: my %defaultchecked = (
4123: 'cancreate_login' => 'off',
4124: 'cancreate_sso' => 'off',
4125: );
1.228 raeburn 4126: my ($onclick,$itemcount);
1.224 raeburn 4127: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4128: \%choices,$itemcount,$onclick);
1.228 raeburn 4129: $$rowtotal += $itemcount;
4130:
1.224 raeburn 4131: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4132:
4133: if (ref($usertypes) eq 'HASH') {
4134: if (keys(%{$usertypes}) > 0) {
4135: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4136: $dom,$numinrow,$othertitle,
1.228 raeburn 4137: 'statustocreate',$$rowtotal);
1.224 raeburn 4138: $$rowtotal ++;
4139: }
4140: }
1.240 raeburn 4141: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4142: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4143: $fieldtitles{'inststatus'} = &mt('Institutional status');
4144: my $rem;
4145: my $numperrow = 2;
4146: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4147: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4148: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4149: '<td class="LC_left_item">'."\n".
4150: '<table><tr><td>'."\n";
4151: for (my $i=0; $i<@fields; $i++) {
4152: $rem = $i%($numperrow);
4153: if ($rem == 0) {
4154: if ($i > 0) {
4155: $datatable .= '</tr>';
4156: }
4157: $datatable .= '<tr>';
4158: }
4159: my $currval;
4160: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4161: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4162: }
4163: $datatable .= '<td class="LC_left_item">'.
4164: '<span class="LC_nobreak">'.
4165: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4166: 'value="'.$currval.'" size="10" /> '.
4167: $fieldtitles{$fields[$i]}.'</span></td>';
4168: }
4169: my $colsleft = $numperrow - $rem;
4170: if ($colsleft > 1 ) {
4171: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4172: ' </td>';
4173: } elsif ($colsleft == 1) {
4174: $datatable .= '<td class="LC_left_item"> </td>';
4175: }
4176: $datatable .= '</tr></table></td></tr>';
4177: $$rowtotal ++;
1.224 raeburn 4178: } elsif ($position eq 'middle') {
4179: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4180: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4181: $usertypes->{'default'} = $othertitle;
4182: if (ref($types) eq 'ARRAY') {
4183: push(@{$types},'default');
4184: $usertypes->{'default'} = $othertitle;
4185: foreach my $status (@{$types}) {
4186: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4187: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4188: $$rowtotal ++;
1.224 raeburn 4189: }
4190: }
4191: } else {
1.236 raeburn 4192: my %choices = &Apache::lonlocal::texthash (
4193: cancreate_email => 'E-mail address as username',
4194: );
4195: my @toggles = sort(keys(%choices));
4196: my %defaultchecked = (
4197: 'cancreate_email' => 'off',
4198: );
4199: my $itemcount = 0;
4200: my $display = 'none';
4201: if (grep(/^\Qemail\E$/,@selfcreate)) {
4202: $display = 'block';
4203: }
4204: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4205: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4206: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4207: my $usertypes = {};
4208: my $order = [];
4209: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4210: $usertypes = $domdefaults{'inststatustypes'};
4211: $order = $domdefaults{'inststatusguest'};
4212: }
4213: if (ref($order) eq 'ARRAY') {
4214: push(@{$order},'default');
4215: if (@{$order} > 1) {
4216: $usertypes->{'default'} = &mt('Other users');
4217: $additional .= '<table><tr>';
4218: foreach my $status (@{$order}) {
4219: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4220: }
4221: $additional .= '</tr><tr>';
4222: foreach my $status (@{$order}) {
4223: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4224: }
1.236 raeburn 4225: $additional .= '</tr></table>';
1.224 raeburn 4226: } else {
1.236 raeburn 4227: $usertypes->{'default'} = &mt('All users');
4228: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4229: }
4230: }
1.236 raeburn 4231: $additional .= '</div>'."\n";
4232:
4233: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4234: \%choices,$$rowtotal,$onclick,$additional);
4235: $$rowtotal ++;
1.236 raeburn 4236: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4237: $$rowtotal ++;
1.224 raeburn 4238: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4239: $numinrow = 1;
1.236 raeburn 4240: if (ref($order) eq 'ARRAY') {
4241: foreach my $status (@{$order}) {
1.228 raeburn 4242: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4243: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4244: $$rowtotal ++;
4245: }
4246: }
1.224 raeburn 4247: my ($emailrules,$emailruleorder) =
4248: &Apache::lonnet::inst_userrules($dom,'email');
4249: if (ref($emailrules) eq 'HASH') {
4250: if (keys(%{$emailrules}) > 0) {
4251: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4252: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4253: $$rowtotal ++;
4254: }
4255: }
1.228 raeburn 4256: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4257: }
4258: return $datatable;
4259: }
4260:
1.236 raeburn 4261: sub email_as_username {
4262: my ($rowtotal,$processing,$type) = @_;
4263: my %choices =
4264: &Apache::lonlocal::texthash (
4265: automatic => 'Automatic approval',
4266: approval => 'Queued for approval',
4267: );
4268: my $output;
4269: foreach my $option ('automatic','approval') {
4270: my $checked;
4271: if (ref($processing) eq 'HASH') {
4272: if ($type eq '') {
4273: if (!exists($processing->{'default'})) {
4274: if ($option eq 'automatic') {
4275: $checked = ' checked="checked"';
4276: }
4277: } else {
4278: if ($processing->{'default'} eq $option) {
4279: $checked = ' checked="checked"';
4280: }
4281: }
4282: } else {
4283: if (!exists($processing->{$type})) {
4284: if ($option eq 'automatic') {
4285: $checked = ' checked="checked"';
4286: }
4287: } else {
4288: if ($processing->{$type} eq $option) {
4289: $checked = ' checked="checked"';
4290: }
4291: }
4292: }
4293: } elsif ($option eq 'automatic') {
4294: $checked = ' checked="checked"';
4295: }
4296: my $name = 'cancreate_emailprocess';
4297: if (($type ne '') && ($type ne 'default')) {
4298: $name .= '_'.$type;
4299: }
4300: $output .= '<span class="LC_nobreak"><label>'.
4301: '<input type="radio" name="'.$name.'"'.
4302: $checked.' value="'.$option.'" />'.
4303: $choices{$option}.'</label></span>';
4304: if ($type eq '') {
4305: $output .= ' ';
4306: } else {
4307: $output .= '<br />';
4308: }
4309: }
4310: $$rowtotal ++;
4311: return $output;
4312: }
4313:
1.165 raeburn 4314: sub captcha_choice {
1.169 raeburn 4315: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4316: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4317: my %lt = &captcha_phrases();
4318: $keyentry = 'hidden';
4319: if ($context eq 'cancreate') {
1.224 raeburn 4320: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4321: } elsif ($context eq 'login') {
4322: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4323: }
4324: if (ref($settings) eq 'HASH') {
4325: if ($settings->{'captcha'}) {
4326: $checked{$settings->{'captcha'}} = ' checked="checked"';
4327: } else {
4328: $checked{'original'} = ' checked="checked"';
4329: }
4330: if ($settings->{'captcha'} eq 'recaptcha') {
4331: $pubtext = $lt{'pub'};
4332: $privtext = $lt{'priv'};
4333: $keyentry = 'text';
4334: }
4335: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4336: $currpub = $settings->{'recaptchakeys'}{'public'};
4337: $currpriv = $settings->{'recaptchakeys'}{'private'};
4338: }
4339: } else {
4340: $checked{'original'} = ' checked="checked"';
4341: }
1.169 raeburn 4342: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4343: my $output = '<tr'.$css_class.'>'.
4344: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4345: '<table><tr><td>'."\n";
4346: foreach my $option ('original','recaptcha','notused') {
4347: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4348: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4349: $lt{$option}.'</label></span>';
4350: unless ($option eq 'notused') {
4351: $output .= (' 'x2)."\n";
4352: }
4353: }
4354: #
4355: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4356: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4357: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4358: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4359: #
1.165 raeburn 4360: $output .= '</td></tr>'."\n".
4361: '<tr><td>'."\n".
4362: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4363: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4364: $currpub.'" size="40" /></span><br />'."\n".
4365: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4366: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4367: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4368: '</td></tr>';
4369: return $output;
4370: }
4371:
1.32 raeburn 4372: sub user_formats_row {
4373: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4374: my $output;
4375: my %text = (
4376: 'username' => 'new usernames',
4377: 'id' => 'IDs',
1.45 raeburn 4378: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4379: );
4380: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4381: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4382: '<td><span class="LC_nobreak">';
4383: if ($type eq 'email') {
4384: $output .= &mt("Formats disallowed for $text{$type}: ");
4385: } else {
4386: $output .= &mt("Format rules to check for $text{$type}: ");
4387: }
4388: $output .= '</span></td>'.
4389: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4390: my $rem;
4391: if (ref($ruleorder) eq 'ARRAY') {
4392: for (my $i=0; $i<@{$ruleorder}; $i++) {
4393: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4394: my $rem = $i%($numinrow);
4395: if ($rem == 0) {
4396: if ($i > 0) {
4397: $output .= '</tr>';
4398: }
4399: $output .= '<tr>';
4400: }
4401: my $check = ' ';
1.39 raeburn 4402: if (ref($settings) eq 'HASH') {
4403: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4404: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4405: $check = ' checked="checked" ';
4406: }
1.27 raeburn 4407: }
4408: }
4409: $output .= '<td class="LC_left_item">'.
4410: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4411: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4412: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4413: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4414: }
4415: }
4416: $rem = @{$ruleorder}%($numinrow);
4417: }
4418: my $colsleft = $numinrow - $rem;
4419: if ($colsleft > 1 ) {
4420: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4421: ' </td>';
4422: } elsif ($colsleft == 1) {
4423: $output .= '<td class="LC_left_item"> </td>';
4424: }
4425: $output .= '</tr></table></td></tr>';
4426: return $output;
4427: }
4428:
1.34 raeburn 4429: sub usercreation_types {
4430: my %lt = &Apache::lonlocal::texthash (
4431: author => 'When adding a co-author',
4432: course => 'When adding a user to a course',
1.100 raeburn 4433: requestcrs => 'When requesting a course',
1.34 raeburn 4434: any => 'Any',
4435: official => 'Institutional only ',
4436: unofficial => 'Non-institutional only',
4437: none => 'None',
4438: );
4439: return %lt;
1.48 raeburn 4440: }
1.34 raeburn 4441:
1.224 raeburn 4442: sub selfcreation_types {
4443: my %lt = &Apache::lonlocal::texthash (
4444: selfcreate => 'User creates own account',
4445: any => 'Any',
4446: official => 'Institutional only ',
4447: unofficial => 'Non-institutional only',
4448: email => 'E-mail address',
4449: login => 'Institutional Login',
4450: sso => 'SSO',
4451: );
4452: }
4453:
1.28 raeburn 4454: sub authtype_names {
4455: my %lt = &Apache::lonlocal::texthash(
4456: int => 'Internal',
4457: krb4 => 'Kerberos 4',
4458: krb5 => 'Kerberos 5',
4459: loc => 'Local',
4460: );
4461: return %lt;
4462: }
4463:
4464: sub context_names {
4465: my %context_title = &Apache::lonlocal::texthash(
4466: author => 'Creating users when an Author',
4467: course => 'Creating users when in a course',
4468: domain => 'Creating users when a Domain Coordinator',
4469: );
4470: return %context_title;
4471: }
4472:
1.33 raeburn 4473: sub print_usermodification {
4474: my ($position,$dom,$settings,$rowtotal) = @_;
4475: my $numinrow = 4;
4476: my ($context,$datatable,$rowcount);
4477: if ($position eq 'top') {
4478: $rowcount = 0;
4479: $context = 'author';
4480: foreach my $role ('ca','aa') {
4481: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4482: $numinrow,$rowcount);
4483: $$rowtotal ++;
4484: $rowcount ++;
4485: }
1.230 raeburn 4486: } elsif ($position eq 'bottom') {
1.33 raeburn 4487: $context = 'course';
4488: $rowcount = 0;
4489: foreach my $role ('st','ep','ta','in','cr') {
4490: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4491: $numinrow,$rowcount);
4492: $$rowtotal ++;
4493: $rowcount ++;
4494: }
4495: }
4496: return $datatable;
4497: }
4498:
1.43 raeburn 4499: sub print_defaults {
1.236 raeburn 4500: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4501: my $rownum = 0;
4502: my ($datatable,$css_class);
1.236 raeburn 4503: if ($position eq 'top') {
4504: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4505: 'datelocale_def','portal_def');
4506: my %defaults;
4507: if (ref($settings) eq 'HASH') {
4508: %defaults = %{$settings};
1.43 raeburn 4509: } else {
1.236 raeburn 4510: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4511: foreach my $item (@items) {
4512: $defaults{$item} = $domdefaults{$item};
4513: }
1.43 raeburn 4514: }
1.236 raeburn 4515: my $titles = &defaults_titles($dom);
4516: foreach my $item (@items) {
4517: if ($rownum%2) {
4518: $css_class = '';
4519: } else {
4520: $css_class = ' class="LC_odd_row" ';
4521: }
4522: $datatable .= '<tr'.$css_class.'>'.
4523: '<td><span class="LC_nobreak">'.$titles->{$item}.
4524: '</span></td><td class="LC_right_item" colspan="3">';
4525: if ($item eq 'auth_def') {
4526: my @authtypes = ('internal','krb4','krb5','localauth');
4527: my %shortauth = (
4528: internal => 'int',
4529: krb4 => 'krb4',
4530: krb5 => 'krb5',
4531: localauth => 'loc'
4532: );
4533: my %authnames = &authtype_names();
4534: foreach my $auth (@authtypes) {
4535: my $checked = ' ';
4536: if ($defaults{$item} eq $auth) {
4537: $checked = ' checked="checked" ';
4538: }
4539: $datatable .= '<label><input type="radio" name="'.$item.
4540: '" value="'.$auth.'"'.$checked.'/>'.
4541: $authnames{$shortauth{$auth}}.'</label> ';
4542: }
4543: } elsif ($item eq 'timezone_def') {
4544: my $includeempty = 1;
4545: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4546: } elsif ($item eq 'datelocale_def') {
4547: my $includeempty = 1;
4548: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4549: } elsif ($item eq 'lang_def') {
4550: my %langchoices = &get_languages_hash();
4551: $langchoices{''} = 'No language preference';
4552: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4553: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4554: \%langchoices);
4555: } else {
4556: my $size;
4557: if ($item eq 'portal_def') {
4558: $size = ' size="25"';
4559: }
4560: $datatable .= '<input type="text" name="'.$item.'" value="'.
4561: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4562: }
1.236 raeburn 4563: $datatable .= '</td></tr>';
4564: $rownum ++;
4565: }
4566: } else {
4567: my (%defaults);
4568: if (ref($settings) eq 'HASH') {
4569: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4570: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4571: my $maxnum = @{$settings->{'inststatusorder'}};
4572: for (my $i=0; $i<$maxnum; $i++) {
4573: $css_class = $rownum%2?' class="LC_odd_row"':'';
4574: my $item = $settings->{'inststatusorder'}->[$i];
4575: my $title = $settings->{'inststatustypes'}->{$item};
4576: my $guestok;
4577: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4578: $guestok = 1;
4579: }
4580: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4581: $datatable .= '<tr'.$css_class.'>'.
4582: '<td><span class="LC_nobreak">'.
4583: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4584: for (my $k=0; $k<=$maxnum; $k++) {
4585: my $vpos = $k+1;
4586: my $selstr;
4587: if ($k == $i) {
4588: $selstr = ' selected="selected" ';
4589: }
4590: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4591: }
4592: my ($checkedon,$checkedoff);
4593: $checkedoff = ' checked="checked"';
4594: if ($guestok) {
4595: $checkedon = $checkedoff;
4596: $checkedoff = '';
4597: }
4598: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4599: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4600: &mt('delete').'</span></td>'.
4601: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4602: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4603: '</span></td>'.
4604: '<td class="LC_right_item"><span class="LC_nobreak">'.
4605: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4606: &mt('Yes').'</label>'.(' 'x2).
4607: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4608: &mt('No').'</label></span></td></tr>';
4609: }
4610: $css_class = $rownum%2?' class="LC_odd_row"':'';
4611: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4612: $datatable .= '<tr '.$css_class.'>'.
4613: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4614: for (my $k=0; $k<=$maxnum; $k++) {
4615: my $vpos = $k+1;
4616: my $selstr;
4617: if ($k == $maxnum) {
4618: $selstr = ' selected="selected" ';
4619: }
4620: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4621: }
4622: $datatable .= '</select> '.&mt('Internal ID:').
4623: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4624: ' '.&mt('(new)').
4625: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4626: &mt('Name displayed:').
4627: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4628: '<td class="LC_right_item"><span class="LC_nobreak">'.
4629: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4630: &mt('Yes').'</label>'.(' 'x2).
4631: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4632: &mt('No').'</label></span></td></tr>';
4633: '</tr>'."\n";
4634: $rownum ++;
1.141 raeburn 4635: }
1.43 raeburn 4636: }
4637: }
4638: $$rowtotal += $rownum;
4639: return $datatable;
4640: }
4641:
1.168 raeburn 4642: sub get_languages_hash {
4643: my %langchoices;
4644: foreach my $id (&Apache::loncommon::languageids()) {
4645: my $code = &Apache::loncommon::supportedlanguagecode($id);
4646: if ($code ne '') {
4647: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4648: }
4649: }
4650: return %langchoices;
4651: }
4652:
1.43 raeburn 4653: sub defaults_titles {
1.141 raeburn 4654: my ($dom) = @_;
1.43 raeburn 4655: my %titles = &Apache::lonlocal::texthash (
4656: 'auth_def' => 'Default authentication type',
4657: 'auth_arg_def' => 'Default authentication argument',
4658: 'lang_def' => 'Default language',
1.54 raeburn 4659: 'timezone_def' => 'Default timezone',
1.68 raeburn 4660: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4661: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4662: );
1.141 raeburn 4663: if ($dom) {
4664: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4665: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4666: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4667: $protocol = 'http' if ($protocol ne 'https');
4668: if ($uint_dom) {
4669: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4670: $uint_dom);
4671: }
4672: }
1.43 raeburn 4673: return (\%titles);
4674: }
4675:
1.46 raeburn 4676: sub print_scantronformat {
4677: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4678: my $itemcount = 1;
1.60 raeburn 4679: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4680: %confhash);
1.46 raeburn 4681: my $switchserver = &check_switchserver($dom,$confname);
4682: my %lt = &Apache::lonlocal::texthash (
1.95 www 4683: default => 'Default bubblesheet format file error',
4684: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4685: );
4686: my %scantronfiles = (
4687: default => 'default.tab',
4688: custom => 'custom.tab',
4689: );
4690: foreach my $key (keys(%scantronfiles)) {
4691: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4692: .$scantronfiles{$key};
4693: }
4694: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4695: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4696: if (!$switchserver) {
4697: my $servadm = $r->dir_config('lonAdmEMail');
4698: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4699: if ($configuserok eq 'ok') {
4700: if ($author_ok eq 'ok') {
4701: my %legacyfile = (
4702: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4703: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4704: );
4705: my %md5chk;
4706: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4707: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4708: chomp($md5chk{$type});
1.46 raeburn 4709: }
4710: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4711: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4712: ($scantronurls{$type},my $error) =
1.46 raeburn 4713: &legacy_scantronformat($r,$dom,$confname,
4714: $type,$legacyfile{$type},
4715: $scantronurls{$type},
4716: $scantronfiles{$type});
1.60 raeburn 4717: if ($error ne '') {
4718: $error{$type} = $error;
4719: }
4720: }
4721: if (keys(%error) == 0) {
4722: $is_custom = 1;
4723: $confhash{'scantron'}{'scantronformat'} =
4724: $scantronurls{'custom'};
4725: my $putresult =
4726: &Apache::lonnet::put_dom('configuration',
4727: \%confhash,$dom);
4728: if ($putresult ne 'ok') {
4729: $error{'custom'} =
4730: '<span class="LC_error">'.
4731: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4732: }
1.46 raeburn 4733: }
4734: } else {
1.60 raeburn 4735: ($scantronurls{'default'},my $error) =
1.46 raeburn 4736: &legacy_scantronformat($r,$dom,$confname,
4737: 'default',$legacyfile{'default'},
4738: $scantronurls{'default'},
4739: $scantronfiles{'default'});
1.60 raeburn 4740: if ($error eq '') {
4741: $confhash{'scantron'}{'scantronformat'} = '';
4742: my $putresult =
4743: &Apache::lonnet::put_dom('configuration',
4744: \%confhash,$dom);
4745: if ($putresult ne 'ok') {
4746: $error{'default'} =
4747: '<span class="LC_error">'.
4748: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4749: }
4750: } else {
4751: $error{'default'} = $error;
4752: }
1.46 raeburn 4753: }
4754: }
4755: }
4756: } else {
1.95 www 4757: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4758: }
4759: }
4760: if (ref($settings) eq 'HASH') {
4761: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4762: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4763: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4764: $scantronurl = '';
4765: } else {
4766: $scantronurl = $settings->{'scantronformat'};
4767: }
4768: $is_custom = 1;
4769: } else {
4770: $scantronurl = $scantronurls{'default'};
4771: }
4772: } else {
1.60 raeburn 4773: if ($is_custom) {
4774: $scantronurl = $scantronurls{'custom'};
4775: } else {
4776: $scantronurl = $scantronurls{'default'};
4777: }
1.46 raeburn 4778: }
4779: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4780: $datatable .= '<tr'.$css_class.'>';
4781: if (!$is_custom) {
1.65 raeburn 4782: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4783: '<span class="LC_nobreak">';
1.46 raeburn 4784: if ($scantronurl) {
1.199 raeburn 4785: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4786: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4787: } else {
4788: $datatable = &mt('File unavailable for display');
4789: }
1.65 raeburn 4790: $datatable .= '</span></td>';
1.60 raeburn 4791: if (keys(%error) == 0) {
4792: $datatable .= '<td valign="bottom">';
4793: if (!$switchserver) {
4794: $datatable .= &mt('Upload:').'<br />';
4795: }
4796: } else {
4797: my $errorstr;
4798: foreach my $key (sort(keys(%error))) {
4799: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4800: }
4801: $datatable .= '<td>'.$errorstr;
4802: }
1.46 raeburn 4803: } else {
4804: if (keys(%error) > 0) {
4805: my $errorstr;
4806: foreach my $key (sort(keys(%error))) {
4807: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4808: }
1.60 raeburn 4809: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4810: } elsif ($scantronurl) {
1.199 raeburn 4811: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4812: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4813: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4814: $link.
4815: '<label><input type="checkbox" name="scantronformat_del"'.
4816: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4817: '<td><span class="LC_nobreak"> '.
4818: &mt('Replace:').'</span><br />';
1.46 raeburn 4819: }
4820: }
4821: if (keys(%error) == 0) {
4822: if ($switchserver) {
4823: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4824: } else {
1.65 raeburn 4825: $datatable .='<span class="LC_nobreak"> '.
4826: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4827: }
4828: }
4829: $datatable .= '</td></tr>';
4830: $$rowtotal ++;
4831: return $datatable;
4832: }
4833:
4834: sub legacy_scantronformat {
4835: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4836: my ($url,$error);
4837: my @statinfo = &Apache::lonnet::stat_file($newurl);
4838: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4839: (my $result,$url) =
4840: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4841: '','',$newfile);
4842: if ($result ne 'ok') {
1.130 raeburn 4843: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4844: }
4845: }
4846: return ($url,$error);
4847: }
1.43 raeburn 4848:
1.49 raeburn 4849: sub print_coursecategories {
1.57 raeburn 4850: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4851: my $datatable;
4852: if ($position eq 'top') {
1.238 raeburn 4853: my (%checked);
4854: my @catitems = ('unauth','auth');
4855: my @cattypes = ('std','domonly','codesrch','none');
4856: $checked{'unauth'} = 'std';
4857: $checked{'auth'} = 'std';
4858: if (ref($settings) eq 'HASH') {
4859: foreach my $type (@cattypes) {
4860: if ($type eq $settings->{'unauth'}) {
4861: $checked{'unauth'} = $type;
4862: }
4863: if ($type eq $settings->{'auth'}) {
4864: $checked{'auth'} = $type;
4865: }
4866: }
4867: }
4868: my %lt = &Apache::lonlocal::texthash (
4869: unauth => 'Catalog type for unauthenticated users',
4870: auth => 'Catalog type for authenticated users',
4871: none => 'No catalog',
4872: std => 'Standard catalog',
4873: domonly => 'Domain-only catalog',
4874: codesrch => "Code search form",
4875: );
4876: my $itemcount = 0;
4877: foreach my $item (@catitems) {
4878: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4879: $datatable .= '<tr '.$css_class.'>'.
4880: '<td>'.$lt{$item}.'</td>'.
4881: '<td class="LC_right_item"><span class="LC_nobreak">';
4882: foreach my $type (@cattypes) {
4883: my $ischecked;
4884: if ($checked{$item} eq $type) {
4885: $ischecked=' checked="checked"';
4886: }
4887: $datatable .= '<label>'.
4888: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4889: ' />'.$lt{$type}.'</label> ';
4890: }
4891: $datatable .= '</td></tr>';
4892: $itemcount ++;
4893: }
4894: $$rowtotal += $itemcount;
4895: } elsif ($position eq 'middle') {
1.57 raeburn 4896: my $toggle_cats_crs = ' ';
4897: my $toggle_cats_dom = ' checked="checked" ';
4898: my $can_cat_crs = ' ';
4899: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4900: my $toggle_catscomm_comm = ' ';
4901: my $toggle_catscomm_dom = ' checked="checked" ';
4902: my $can_catcomm_comm = ' ';
4903: my $can_catcomm_dom = ' checked="checked" ';
4904:
1.57 raeburn 4905: if (ref($settings) eq 'HASH') {
4906: if ($settings->{'togglecats'} eq 'crs') {
4907: $toggle_cats_crs = $toggle_cats_dom;
4908: $toggle_cats_dom = ' ';
4909: }
4910: if ($settings->{'categorize'} eq 'crs') {
4911: $can_cat_crs = $can_cat_dom;
4912: $can_cat_dom = ' ';
4913: }
1.120 raeburn 4914: if ($settings->{'togglecatscomm'} eq 'comm') {
4915: $toggle_catscomm_comm = $toggle_catscomm_dom;
4916: $toggle_catscomm_dom = ' ';
4917: }
4918: if ($settings->{'categorizecomm'} eq 'comm') {
4919: $can_catcomm_comm = $can_catcomm_dom;
4920: $can_catcomm_dom = ' ';
4921: }
1.57 raeburn 4922: }
4923: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4924: togglecats => 'Show/Hide a course in catalog',
4925: togglecatscomm => 'Show/Hide a community in catalog',
4926: categorize => 'Assign a category to a course',
4927: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4928: );
4929: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4930: dom => 'Set in Domain',
4931: crs => 'Set in Course',
4932: comm => 'Set in Community',
1.57 raeburn 4933: );
4934: $datatable = '<tr class="LC_odd_row">'.
4935: '<td>'.$title{'togglecats'}.'</td>'.
4936: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4937: '<input type="radio" name="togglecats"'.
4938: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4939: '<label><input type="radio" name="togglecats"'.
4940: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4941: '</tr><tr>'.
4942: '<td>'.$title{'categorize'}.'</td>'.
4943: '<td class="LC_right_item"><span class="LC_nobreak">'.
4944: '<label><input type="radio" name="categorize"'.
4945: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4946: '<label><input type="radio" name="categorize"'.
4947: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4948: '</tr><tr class="LC_odd_row">'.
4949: '<td>'.$title{'togglecatscomm'}.'</td>'.
4950: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4951: '<input type="radio" name="togglecatscomm"'.
4952: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4953: '<label><input type="radio" name="togglecatscomm"'.
4954: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4955: '</tr><tr>'.
4956: '<td>'.$title{'categorizecomm'}.'</td>'.
4957: '<td class="LC_right_item"><span class="LC_nobreak">'.
4958: '<label><input type="radio" name="categorizecomm"'.
4959: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4960: '<label><input type="radio" name="categorizecomm"'.
4961: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4962: '</tr>';
1.120 raeburn 4963: $$rowtotal += 4;
1.57 raeburn 4964: } else {
4965: my $css_class;
4966: my $itemcount = 1;
4967: my $cathash;
4968: if (ref($settings) eq 'HASH') {
4969: $cathash = $settings->{'cats'};
4970: }
4971: if (ref($cathash) eq 'HASH') {
4972: my (@cats,@trails,%allitems,%idx,@jsarray);
4973: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4974: \%allitems,\%idx,\@jsarray);
4975: my $maxdepth = scalar(@cats);
4976: my $colattrib = '';
4977: if ($maxdepth > 2) {
4978: $colattrib = ' colspan="2" ';
4979: }
4980: my @path;
4981: if (@cats > 0) {
4982: if (ref($cats[0]) eq 'ARRAY') {
4983: my $numtop = @{$cats[0]};
4984: my $maxnum = $numtop;
1.120 raeburn 4985: my %default_names = (
4986: instcode => &mt('Official courses'),
4987: communities => &mt('Communities'),
4988: );
4989:
4990: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4991: ($cathash->{'instcode::0'} eq '') ||
4992: (!grep(/^communities$/,@{$cats[0]})) ||
4993: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4994: $maxnum ++;
4995: }
4996: my $lastidx;
4997: for (my $i=0; $i<$numtop; $i++) {
4998: my $parent = $cats[0][$i];
4999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5000: my $item = &escape($parent).'::0';
5001: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5002: $lastidx = $idx{$item};
5003: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5004: .'<select name="'.$item.'"'.$chgstr.'>';
5005: for (my $k=0; $k<=$maxnum; $k++) {
5006: my $vpos = $k+1;
5007: my $selstr;
5008: if ($k == $i) {
5009: $selstr = ' selected="selected" ';
5010: }
5011: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5012: }
1.214 raeburn 5013: $datatable .= '</select></span></td><td>';
1.120 raeburn 5014: if ($parent eq 'instcode' || $parent eq 'communities') {
5015: $datatable .= '<span class="LC_nobreak">'
5016: .$default_names{$parent}.'</span>';
5017: if ($parent eq 'instcode') {
5018: $datatable .= '<br /><span class="LC_nobreak">('
5019: .&mt('with institutional codes')
5020: .')</span></td><td'.$colattrib.'>';
5021: } else {
5022: $datatable .= '<table><tr><td>';
5023: }
5024: $datatable .= '<span class="LC_nobreak">'
5025: .'<label><input type="radio" name="'
5026: .$parent.'" value="1" checked="checked" />'
5027: .&mt('Display').'</label>';
5028: if ($parent eq 'instcode') {
5029: $datatable .= ' ';
5030: } else {
5031: $datatable .= '</span></td></tr><tr><td>'
5032: .'<span class="LC_nobreak">';
5033: }
5034: $datatable .= '<label><input type="radio" name="'
5035: .$parent.'" value="0" />'
5036: .&mt('Do not display').'</label></span>';
5037: if ($parent eq 'communities') {
5038: $datatable .= '</td></tr></table>';
5039: }
5040: $datatable .= '</td>';
1.57 raeburn 5041: } else {
5042: $datatable .= $parent
1.214 raeburn 5043: .' <span class="LC_nobreak"><label>'
5044: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5045: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5046: }
5047: my $depth = 1;
5048: push(@path,$parent);
5049: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5050: pop(@path);
5051: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5052: $itemcount ++;
5053: }
1.48 raeburn 5054: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5055: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5056: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5057: for (my $k=0; $k<=$maxnum; $k++) {
5058: my $vpos = $k+1;
5059: my $selstr;
1.57 raeburn 5060: if ($k == $numtop) {
1.48 raeburn 5061: $selstr = ' selected="selected" ';
5062: }
5063: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5064: }
1.59 bisitz 5065: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5066: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5067: .'</tr>'."\n";
1.48 raeburn 5068: $itemcount ++;
1.120 raeburn 5069: foreach my $default ('instcode','communities') {
5070: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5072: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5073: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5074: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5075: for (my $k=0; $k<=$maxnum; $k++) {
5076: my $vpos = $k+1;
5077: my $selstr;
5078: if ($k == $maxnum) {
5079: $selstr = ' selected="selected" ';
5080: }
5081: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5082: }
1.120 raeburn 5083: $datatable .= '</select></span></td>'.
5084: '<td><span class="LC_nobreak">'.
5085: $default_names{$default}.'</span>';
5086: if ($default eq 'instcode') {
5087: $datatable .= '<br /><span class="LC_nobreak">('
5088: .&mt('with institutional codes').')</span>';
5089: }
5090: $datatable .= '</td>'
5091: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5092: .&mt('Display').'</label> '
5093: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5094: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5095: }
5096: }
5097: }
1.57 raeburn 5098: } else {
5099: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5100: }
5101: } else {
1.238 raeburn 5102: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5103: .&initialize_categories($itemcount);
1.48 raeburn 5104: }
1.57 raeburn 5105: $$rowtotal += $itemcount;
1.48 raeburn 5106: }
5107: return $datatable;
5108: }
5109:
1.69 raeburn 5110: sub print_serverstatuses {
5111: my ($dom,$settings,$rowtotal) = @_;
5112: my $datatable;
5113: my @pages = &serverstatus_pages();
5114: my (%namedaccess,%machineaccess);
5115: foreach my $type (@pages) {
5116: $namedaccess{$type} = '';
5117: $machineaccess{$type}= '';
5118: }
5119: if (ref($settings) eq 'HASH') {
5120: foreach my $type (@pages) {
5121: if (exists($settings->{$type})) {
5122: if (ref($settings->{$type}) eq 'HASH') {
5123: foreach my $key (keys(%{$settings->{$type}})) {
5124: if ($key eq 'namedusers') {
5125: $namedaccess{$type} = $settings->{$type}->{$key};
5126: } elsif ($key eq 'machines') {
5127: $machineaccess{$type} = $settings->{$type}->{$key};
5128: }
5129: }
5130: }
5131: }
5132: }
5133: }
1.81 raeburn 5134: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5135: my $rownum = 0;
5136: my $css_class;
5137: foreach my $type (@pages) {
5138: $rownum ++;
5139: $css_class = $rownum%2?' class="LC_odd_row"':'';
5140: $datatable .= '<tr'.$css_class.'>'.
5141: '<td><span class="LC_nobreak">'.
5142: $titles->{$type}.'</span></td>'.
5143: '<td class="LC_left_item">'.
5144: '<input type="text" name="'.$type.'_namedusers" '.
5145: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5146: '<td class="LC_right_item">'.
5147: '<span class="LC_nobreak">'.
5148: '<input type="text" name="'.$type.'_machines" '.
5149: 'value="'.$machineaccess{$type}.'" size="10" />'.
5150: '</td></tr>'."\n";
5151: }
5152: $$rowtotal += $rownum;
5153: return $datatable;
5154: }
5155:
5156: sub serverstatus_pages {
5157: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5158: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5159: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5160: 'uniquecodes','diskusage');
1.69 raeburn 5161: }
5162:
1.236 raeburn 5163: sub defaults_javascript {
5164: my ($settings) = @_;
5165: my ($output,$jstext);
5166: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5167: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5168: if ($maxnum eq '') {
5169: $maxnum = 0;
5170: }
5171: $maxnum ++;
5172: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5173: return <<"ENDSCRIPT";
5174: <script type="text/javascript">
5175: // <![CDATA[
5176: function reorderTypes(form,caller) {
5177: var changedVal;
5178: $jstext
5179: var newpos = 'addinststatus_pos';
5180: var current = new Array;
5181: var maxh = $maxnum;
5182: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5183: var oldVal;
5184: if (caller == newpos) {
5185: changedVal = newitemVal;
5186: } else {
5187: var curritem = 'inststatus_pos_'+caller;
5188: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5189: current[newitemVal] = newpos;
5190: }
5191: for (var i=0; i<inststatuses.length; i++) {
5192: if (inststatuses[i] != caller) {
5193: var elementName = 'inststatus_pos_'+inststatuses[i];
5194: if (form.elements[elementName]) {
5195: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5196: current[currVal] = elementName;
5197: }
5198: }
5199: }
5200: for (var j=0; j<maxh; j++) {
5201: if (current[j] == undefined) {
5202: oldVal = j;
5203: }
5204: }
5205: if (oldVal < changedVal) {
5206: for (var k=oldVal+1; k<=changedVal ; k++) {
5207: var elementName = current[k];
5208: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5209: }
5210: } else {
5211: for (var k=changedVal; k<oldVal; k++) {
5212: var elementName = current[k];
5213: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5214: }
5215: }
5216: return;
5217: }
5218:
5219: // ]]>
5220: </script>
5221:
5222: ENDSCRIPT
5223: }
5224: }
5225:
1.49 raeburn 5226: sub coursecategories_javascript {
5227: my ($settings) = @_;
1.57 raeburn 5228: my ($output,$jstext,$cathash);
1.49 raeburn 5229: if (ref($settings) eq 'HASH') {
1.57 raeburn 5230: $cathash = $settings->{'cats'};
5231: }
5232: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5233: my (@cats,@jsarray,%idx);
1.57 raeburn 5234: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5235: if (@jsarray > 0) {
5236: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5237: for (my $i=0; $i<@jsarray; $i++) {
5238: if (ref($jsarray[$i]) eq 'ARRAY') {
5239: my $catstr = join('","',@{$jsarray[$i]});
5240: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5241: }
5242: }
5243: }
5244: } else {
5245: $jstext = ' var categories = Array(1);'."\n".
5246: ' categories[0] = Array("instcode_pos");'."\n";
5247: }
1.237 bisitz 5248: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5249: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5250: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5251: $output = <<"ENDSCRIPT";
5252: <script type="text/javascript">
1.109 raeburn 5253: // <![CDATA[
1.49 raeburn 5254: function reorderCats(form,parent,item,idx) {
5255: var changedVal;
5256: $jstext
5257: var newpos = 'addcategory_pos';
5258: if (parent == '') {
5259: var has_instcode = 0;
5260: var maxtop = categories[idx].length;
5261: for (var j=0; j<maxtop; j++) {
5262: if (categories[idx][j] == 'instcode::0') {
5263: has_instcode == 1;
5264: }
5265: }
5266: if (has_instcode == 0) {
5267: categories[idx][maxtop] = 'instcode_pos';
5268: }
5269: } else {
5270: newpos += '_'+parent;
5271: }
5272: var maxh = 1 + categories[idx].length;
5273: var current = new Array;
5274: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5275: if (item == newpos) {
5276: changedVal = newitemVal;
5277: } else {
5278: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5279: current[newitemVal] = newpos;
5280: }
5281: for (var i=0; i<categories[idx].length; i++) {
5282: var elementName = categories[idx][i];
5283: if (elementName != item) {
5284: if (form.elements[elementName]) {
5285: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5286: current[currVal] = elementName;
5287: }
5288: }
5289: }
5290: var oldVal;
5291: for (var j=0; j<maxh; j++) {
5292: if (current[j] == undefined) {
5293: oldVal = j;
5294: }
5295: }
5296: if (oldVal < changedVal) {
5297: for (var k=oldVal+1; k<=changedVal ; k++) {
5298: var elementName = current[k];
5299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5300: }
5301: } else {
5302: for (var k=changedVal; k<oldVal; k++) {
5303: var elementName = current[k];
5304: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5305: }
5306: }
5307: return;
5308: }
1.120 raeburn 5309:
5310: function categoryCheck(form) {
5311: if (form.elements['addcategory_name'].value == 'instcode') {
5312: alert('$instcode_reserved\\n$choose_again');
5313: return false;
5314: }
5315: if (form.elements['addcategory_name'].value == 'communities') {
5316: alert('$communities_reserved\\n$choose_again');
5317: return false;
5318: }
5319: return true;
5320: }
5321:
1.109 raeburn 5322: // ]]>
1.49 raeburn 5323: </script>
5324:
5325: ENDSCRIPT
5326: return $output;
5327: }
5328:
1.48 raeburn 5329: sub initialize_categories {
5330: my ($itemcount) = @_;
1.120 raeburn 5331: my ($datatable,$css_class,$chgstr);
5332: my %default_names = (
5333: instcode => 'Official courses (with institutional codes)',
5334: communities => 'Communities',
5335: );
5336: my $select0 = ' selected="selected"';
5337: my $select1 = '';
5338: foreach my $default ('instcode','communities') {
5339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5340: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5341: if ($default eq 'communities') {
5342: $select1 = $select0;
5343: $select0 = '';
5344: }
5345: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5346: .'<select name="'.$default.'_pos">'
5347: .'<option value="0"'.$select0.'>1</option>'
5348: .'<option value="1"'.$select1.'>2</option>'
5349: .'<option value="2">3</option></select> '
5350: .$default_names{$default}
5351: .'</span></td><td><span class="LC_nobreak">'
5352: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5353: .&mt('Display').'</label> <label>'
5354: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5355: .'</label></span></td></tr>';
1.120 raeburn 5356: $itemcount ++;
5357: }
1.48 raeburn 5358: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5359: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5360: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5361: .'<select name="addcategory_pos"'.$chgstr.'>'
5362: .'<option value="0">1</option>'
5363: .'<option value="1">2</option>'
5364: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5365: .&mt('Add category').'</td><td>'.&mt('Name:')
5366: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5367: return $datatable;
5368: }
5369:
5370: sub build_category_rows {
1.49 raeburn 5371: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5372: my ($text,$name,$item,$chgstr);
1.48 raeburn 5373: if (ref($cats) eq 'ARRAY') {
5374: my $maxdepth = scalar(@{$cats});
5375: if (ref($cats->[$depth]) eq 'HASH') {
5376: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5377: my $numchildren = @{$cats->[$depth]{$parent}};
5378: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5379: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5380: my ($idxnum,$parent_name,$parent_item);
5381: my $higher = $depth - 1;
5382: if ($higher == 0) {
5383: $parent_name = &escape($parent).'::'.$higher;
5384: } else {
5385: if (ref($path) eq 'ARRAY') {
5386: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5387: }
5388: }
5389: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5390: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5391: if ($j < $numchildren) {
1.48 raeburn 5392: $name = $cats->[$depth]{$parent}[$j];
5393: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5394: $idxnum = $idx->{$item};
5395: } else {
5396: $name = $parent_name;
5397: $item = $parent_item;
1.48 raeburn 5398: }
1.49 raeburn 5399: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5400: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5401: for (my $i=0; $i<=$numchildren; $i++) {
5402: my $vpos = $i+1;
5403: my $selstr;
5404: if ($j == $i) {
5405: $selstr = ' selected="selected" ';
5406: }
5407: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5408: }
5409: $text .= '</select> ';
5410: if ($j < $numchildren) {
5411: my $deeper = $depth+1;
5412: $text .= $name.' '
5413: .'<label><input type="checkbox" name="deletecategory" value="'
5414: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5415: if(ref($path) eq 'ARRAY') {
5416: push(@{$path},$name);
1.49 raeburn 5417: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5418: pop(@{$path});
5419: }
5420: } else {
1.59 bisitz 5421: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5422: if ($j == $numchildren) {
5423: $text .= $name;
5424: } else {
5425: $text .= $item;
5426: }
5427: $text .= '" value="" />';
5428: }
5429: $text .= '</td></tr>';
5430: }
5431: $text .= '</table></td>';
5432: } else {
5433: my $higher = $depth-1;
5434: if ($higher == 0) {
5435: $name = &escape($parent).'::'.$higher;
5436: } else {
5437: if (ref($path) eq 'ARRAY') {
5438: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5439: }
5440: }
5441: my $colspan;
5442: if ($parent ne 'instcode') {
5443: $colspan = $maxdepth - $depth - 1;
5444: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5445: }
5446: }
5447: }
5448: }
5449: return $text;
5450: }
5451:
1.33 raeburn 5452: sub modifiable_userdata_row {
1.228 raeburn 5453: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5454: my ($role,$rolename,$statustype);
5455: $role = $item;
1.224 raeburn 5456: if ($context eq 'cancreate') {
1.228 raeburn 5457: if ($item =~ /^emailusername_(.+)$/) {
5458: $statustype = $1;
5459: $role = 'emailusername';
5460: if (ref($usertypes) eq 'HASH') {
5461: if ($usertypes->{$statustype}) {
5462: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5463: } else {
5464: $rolename = &mt('Data provided by user');
5465: }
5466: }
1.224 raeburn 5467: }
5468: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5469: if (ref($usertypes) eq 'HASH') {
5470: $rolename = $usertypes->{$role};
5471: } else {
5472: $rolename = $role;
5473: }
1.33 raeburn 5474: } else {
1.63 raeburn 5475: if ($role eq 'cr') {
5476: $rolename = &mt('Custom role');
5477: } else {
5478: $rolename = &Apache::lonnet::plaintext($role);
5479: }
1.33 raeburn 5480: }
1.224 raeburn 5481: my (@fields,%fieldtitles);
5482: if (ref($fieldsref) eq 'ARRAY') {
5483: @fields = @{$fieldsref};
5484: } else {
5485: @fields = ('lastname','firstname','middlename','generation',
5486: 'permanentemail','id');
5487: }
5488: if ((ref($titlesref) eq 'HASH')) {
5489: %fieldtitles = %{$titlesref};
5490: } else {
5491: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5492: }
1.33 raeburn 5493: my $output;
5494: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5495: $output = '<tr '.$css_class.'>'.
5496: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5497: '<td class="LC_left_item" colspan="2"><table>';
5498: my $rem;
5499: my %checks;
5500: if (ref($settings) eq 'HASH') {
5501: if (ref($settings->{$context}) eq 'HASH') {
5502: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5503: my $hashref = $settings->{$context}->{$role};
5504: if ($role eq 'emailusername') {
5505: if ($statustype) {
5506: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5507: $hashref = $settings->{$context}->{$role}->{$statustype};
5508: if (ref($hashref) eq 'HASH') {
5509: foreach my $field (@fields) {
5510: if ($hashref->{$field}) {
5511: $checks{$field} = $hashref->{$field};
5512: }
5513: }
5514: }
5515: }
5516: }
5517: } else {
5518: if (ref($hashref) eq 'HASH') {
5519: foreach my $field (@fields) {
5520: if ($hashref->{$field}) {
5521: $checks{$field} = ' checked="checked" ';
5522: }
5523: }
1.33 raeburn 5524: }
5525: }
5526: }
5527: }
5528: }
1.228 raeburn 5529:
1.33 raeburn 5530: for (my $i=0; $i<@fields; $i++) {
5531: my $rem = $i%($numinrow);
5532: if ($rem == 0) {
5533: if ($i > 0) {
5534: $output .= '</tr>';
5535: }
5536: $output .= '<tr>';
5537: }
5538: my $check = ' ';
1.228 raeburn 5539: unless ($role eq 'emailusername') {
5540: if (exists($checks{$fields[$i]})) {
5541: $check = $checks{$fields[$i]}
5542: } else {
5543: if ($role eq 'st') {
5544: if (ref($settings) ne 'HASH') {
5545: $check = ' checked="checked" ';
5546: }
1.33 raeburn 5547: }
5548: }
5549: }
5550: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5551: '<span class="LC_nobreak">';
5552: if ($role eq 'emailusername') {
5553: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5554: $checks{$fields[$i]} = 'omit';
5555: }
5556: foreach my $option ('required','optional','omit') {
5557: my $checked='';
5558: if ($checks{$fields[$i]} eq $option) {
5559: $checked='checked="checked" ';
5560: }
5561: $output .= '<label>'.
5562: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5563: &mt($option).'</label>'.(' ' x2);
5564: }
5565: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5566: } else {
5567: $output .= '<label>'.
5568: '<input type="checkbox" name="canmodify_'.$role.'" '.
5569: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5570: '</label>';
5571: }
5572: $output .= '</span></td>';
1.33 raeburn 5573: $rem = @fields%($numinrow);
5574: }
5575: my $colsleft = $numinrow - $rem;
5576: if ($colsleft > 1 ) {
5577: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5578: ' </td>';
5579: } elsif ($colsleft == 1) {
5580: $output .= '<td class="LC_left_item"> </td>';
5581: }
5582: $output .= '</tr></table></td></tr>';
5583: return $output;
5584: }
1.28 raeburn 5585:
1.93 raeburn 5586: sub insttypes_row {
1.224 raeburn 5587: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5588: my %lt = &Apache::lonlocal::texthash (
5589: cansearch => 'Users allowed to search',
5590: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5591: lockablenames => 'User preference to lock name',
1.93 raeburn 5592: );
5593: my $showdom;
5594: if ($context eq 'cansearch') {
5595: $showdom = ' ('.$dom.')';
5596: }
1.165 raeburn 5597: my $class = 'LC_left_item';
5598: if ($context eq 'statustocreate') {
5599: $class = 'LC_right_item';
5600: }
1.224 raeburn 5601: my $css_class = ' class="LC_odd_row"';
5602: if ($rownum ne '') {
5603: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5604: }
5605: my $output = '<tr'.$css_class.'>'.
5606: '<td>'.$lt{$context}.$showdom.
5607: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5608: my $rem;
5609: if (ref($types) eq 'ARRAY') {
5610: for (my $i=0; $i<@{$types}; $i++) {
5611: if (defined($usertypes->{$types->[$i]})) {
5612: my $rem = $i%($numinrow);
5613: if ($rem == 0) {
5614: if ($i > 0) {
5615: $output .= '</tr>';
5616: }
5617: $output .= '<tr>';
1.23 raeburn 5618: }
1.26 raeburn 5619: my $check = ' ';
1.99 raeburn 5620: if (ref($settings) eq 'HASH') {
5621: if (ref($settings->{$context}) eq 'ARRAY') {
5622: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5623: $check = ' checked="checked" ';
5624: }
5625: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5626: $check = ' checked="checked" ';
5627: }
1.23 raeburn 5628: }
1.26 raeburn 5629: $output .= '<td class="LC_left_item">'.
5630: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5631: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5632: 'value="'.$types->[$i].'"'.$check.'/>'.
5633: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5634: }
5635: }
1.26 raeburn 5636: $rem = @{$types}%($numinrow);
1.23 raeburn 5637: }
5638: my $colsleft = $numinrow - $rem;
1.131 raeburn 5639: if (($rem == 0) && (@{$types} > 0)) {
5640: $output .= '<tr>';
5641: }
1.23 raeburn 5642: if ($colsleft > 1) {
1.25 raeburn 5643: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5644: } else {
1.25 raeburn 5645: $output .= '<td class="LC_left_item">';
1.23 raeburn 5646: }
5647: my $defcheck = ' ';
1.99 raeburn 5648: if (ref($settings) eq 'HASH') {
5649: if (ref($settings->{$context}) eq 'ARRAY') {
5650: if (grep(/^default$/,@{$settings->{$context}})) {
5651: $defcheck = ' checked="checked" ';
5652: }
5653: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5654: $defcheck = ' checked="checked" ';
5655: }
1.23 raeburn 5656: }
1.25 raeburn 5657: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5658: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5659: 'value="default"'.$defcheck.'/>'.
5660: $othertitle.'</label></span></td>'.
5661: '</tr></table></td></tr>';
5662: return $output;
1.23 raeburn 5663: }
5664:
5665: sub sorted_searchtitles {
5666: my %searchtitles = &Apache::lonlocal::texthash(
5667: 'uname' => 'username',
5668: 'lastname' => 'last name',
5669: 'lastfirst' => 'last name, first name',
5670: );
5671: my @titleorder = ('uname','lastname','lastfirst');
5672: return (\%searchtitles,\@titleorder);
5673: }
5674:
1.25 raeburn 5675: sub sorted_searchtypes {
5676: my %srchtypes_desc = (
5677: exact => 'is exact match',
5678: contains => 'contains ..',
5679: begins => 'begins with ..',
5680: );
5681: my @srchtypeorder = ('exact','begins','contains');
5682: return (\%srchtypes_desc,\@srchtypeorder);
5683: }
5684:
1.3 raeburn 5685: sub usertype_update_row {
5686: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5687: my $datatable;
5688: my $numinrow = 4;
5689: foreach my $type (@{$types}) {
5690: if (defined($usertypes->{$type})) {
5691: $$rownums ++;
5692: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5693: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5694: '</td><td class="LC_left_item"><table>';
5695: for (my $i=0; $i<@{$fields}; $i++) {
5696: my $rem = $i%($numinrow);
5697: if ($rem == 0) {
5698: if ($i > 0) {
5699: $datatable .= '</tr>';
5700: }
5701: $datatable .= '<tr>';
5702: }
5703: my $check = ' ';
1.39 raeburn 5704: if (ref($settings) eq 'HASH') {
5705: if (ref($settings->{'fields'}) eq 'HASH') {
5706: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5707: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5708: $check = ' checked="checked" ';
5709: }
1.3 raeburn 5710: }
5711: }
5712: }
5713:
5714: if ($i == @{$fields}-1) {
5715: my $colsleft = $numinrow - $rem;
5716: if ($colsleft > 1) {
5717: $datatable .= '<td colspan="'.$colsleft.'">';
5718: } else {
5719: $datatable .= '<td>';
5720: }
5721: } else {
5722: $datatable .= '<td>';
5723: }
1.8 raeburn 5724: $datatable .= '<span class="LC_nobreak"><label>'.
5725: '<input type="checkbox" name="updateable_'.$type.
5726: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5727: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5728: }
5729: $datatable .= '</tr></table></td></tr>';
5730: }
5731: }
5732: return $datatable;
1.1 raeburn 5733: }
5734:
5735: sub modify_login {
1.205 raeburn 5736: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5737: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5738: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5739: %title = ( coursecatalog => 'Display course catalog',
5740: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5741: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5742: newuser => 'Link for visitors to create a user account',
5743: loginheader => 'Log-in box header');
5744: @offon = ('off','on');
1.112 raeburn 5745: if (ref($domconfig{login}) eq 'HASH') {
5746: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5747: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5748: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5749: }
5750: }
5751: }
1.9 raeburn 5752: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5753: \%domconfig,\%loginhash);
1.188 raeburn 5754: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5755: foreach my $item (@toggles) {
5756: $loginhash{login}{$item} = $env{'form.'.$item};
5757: }
1.41 raeburn 5758: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5759: if (ref($colchanges{'login'}) eq 'HASH') {
5760: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5761: \%loginhash);
5762: }
1.110 raeburn 5763:
1.149 raeburn 5764: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5765: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5766: if (keys(%servers) > 1) {
5767: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5768: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5769: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5770: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5771: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5772: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5773: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5774: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5775: $changes{'loginvia'}{$lonhost} = 1;
5776: } else {
5777: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5778: $changes{'loginvia'}{$lonhost} = 1;
5779: }
5780: } else {
5781: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5782: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5783: $changes{'loginvia'}{$lonhost} = 1;
5784: }
5785: }
5786: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5787: foreach my $item (@loginvia_attribs) {
5788: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5789: }
5790: } else {
5791: foreach my $item (@loginvia_attribs) {
5792: my $new = $env{'form.'.$lonhost.'_'.$item};
5793: if (($item eq 'serverpath') && ($new eq 'custom')) {
5794: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5795: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5796: $new = '/';
5797: }
5798: }
5799: if (($item eq 'custompath') &&
5800: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5801: $new = '';
5802: }
5803: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5804: $changes{'loginvia'}{$lonhost} = 1;
5805: }
5806: if ($item eq 'exempt') {
5807: $new =~ s/^\s+//;
5808: $new =~ s/\s+$//;
5809: my @poss_ips = split(/\s*[,:]\s*/,$new);
5810: my @okips;
5811: foreach my $ip (@poss_ips) {
5812: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5813: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5814: push(@okips,$ip);
5815: }
5816: }
5817: }
5818: if (@okips > 0) {
5819: $new = join(',',@okips);
5820: } else {
5821: $new = '';
5822: }
5823: }
5824: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5825: }
5826: }
1.112 raeburn 5827: } else {
1.128 raeburn 5828: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5829: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5830: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5831: foreach my $item (@loginvia_attribs) {
5832: my $new = $env{'form.'.$lonhost.'_'.$item};
5833: if (($item eq 'serverpath') && ($new eq 'custom')) {
5834: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5835: $new = '/';
5836: }
5837: }
5838: if (($item eq 'custompath') &&
5839: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5840: $new = '';
5841: }
5842: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5843: }
1.110 raeburn 5844: }
5845: }
5846: }
5847: }
1.119 raeburn 5848:
1.168 raeburn 5849: my $servadm = $r->dir_config('lonAdmEMail');
5850: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5851: if (ref($domconfig{'login'}) eq 'HASH') {
5852: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5853: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5854: if ($lang eq 'nolang') {
5855: push(@currlangs,$lang);
5856: } elsif (defined($langchoices{$lang})) {
5857: push(@currlangs,$lang);
5858: } else {
5859: next;
5860: }
5861: }
5862: }
5863: }
5864: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5865: if (@currlangs > 0) {
5866: foreach my $lang (@currlangs) {
5867: if (grep(/^\Q$lang\E$/,@delurls)) {
5868: $changes{'helpurl'}{$lang} = 1;
5869: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5870: $changes{'helpurl'}{$lang} = 1;
5871: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5872: push(@newlangs,$lang);
5873: } else {
5874: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5875: }
5876: }
5877: }
5878: unless (grep(/^nolang$/,@currlangs)) {
5879: if ($env{'form.loginhelpurl_nolang.filename'}) {
5880: $changes{'helpurl'}{'nolang'} = 1;
5881: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5882: push(@newlangs,'nolang');
5883: }
5884: }
5885: if ($env{'form.loginhelpurl_add_lang'}) {
5886: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5887: ($env{'form.loginhelpurl_add_file.filename'})) {
5888: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5889: $addedfile = $env{'form.loginhelpurl_add_lang'};
5890: }
5891: }
5892: if ((@newlangs > 0) || ($addedfile)) {
5893: my $error;
5894: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5895: if ($configuserok eq 'ok') {
5896: if ($switchserver) {
5897: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5898: } elsif ($author_ok eq 'ok') {
5899: my @allnew = @newlangs;
5900: if ($addedfile ne '') {
5901: push(@allnew,$addedfile);
5902: }
5903: foreach my $lang (@allnew) {
5904: my $formelem = 'loginhelpurl_'.$lang;
5905: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5906: $formelem = 'loginhelpurl_add_file';
5907: }
5908: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5909: "help/$lang",'','',$newfile{$lang});
5910: if ($result eq 'ok') {
5911: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5912: $changes{'helpurl'}{$lang} = 1;
5913: } else {
5914: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5915: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5916: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5917: (!grep(/^\Q$lang\E$/,@delurls))) {
5918:
5919: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5920: }
5921: }
5922: }
5923: } else {
5924: $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);
5925: }
5926: } else {
5927: $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);
5928: }
5929: if ($error) {
5930: &Apache::lonnet::logthis($error);
5931: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5932: }
5933: }
1.169 raeburn 5934: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5935:
5936: my $defaulthelpfile = '/adm/loginproblems.html';
5937: my $defaulttext = &mt('Default in use');
5938:
1.1 raeburn 5939: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5940: $dom);
5941: if ($putresult eq 'ok') {
1.188 raeburn 5942: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5943: my %defaultchecked = (
5944: 'coursecatalog' => 'on',
1.188 raeburn 5945: 'helpdesk' => 'on',
1.42 raeburn 5946: 'adminmail' => 'off',
1.43 raeburn 5947: 'newuser' => 'off',
1.42 raeburn 5948: );
1.55 raeburn 5949: if (ref($domconfig{'login'}) eq 'HASH') {
5950: foreach my $item (@toggles) {
5951: if ($defaultchecked{$item} eq 'on') {
5952: if (($domconfig{'login'}{$item} eq '0') &&
5953: ($env{'form.'.$item} eq '1')) {
5954: $changes{$item} = 1;
5955: } elsif (($domconfig{'login'}{$item} eq '' ||
5956: $domconfig{'login'}{$item} eq '1') &&
5957: ($env{'form.'.$item} eq '0')) {
5958: $changes{$item} = 1;
5959: }
5960: } elsif ($defaultchecked{$item} eq 'off') {
5961: if (($domconfig{'login'}{$item} eq '1') &&
5962: ($env{'form.'.$item} eq '0')) {
5963: $changes{$item} = 1;
5964: } elsif (($domconfig{'login'}{$item} eq '' ||
5965: $domconfig{'login'}{$item} eq '0') &&
5966: ($env{'form.'.$item} eq '1')) {
5967: $changes{$item} = 1;
5968: }
1.42 raeburn 5969: }
5970: }
1.41 raeburn 5971: }
1.6 raeburn 5972: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5973: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5974: if (ref($lastactref) eq 'HASH') {
5975: $lastactref->{'domainconfig'} = 1;
5976: }
1.1 raeburn 5977: $resulttext = &mt('Changes made:').'<ul>';
5978: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5979: if ($item eq 'loginvia') {
1.112 raeburn 5980: if (ref($changes{$item}) eq 'HASH') {
5981: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5982: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5983: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5984: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5985: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5986: $protocol = 'http' if ($protocol ne 'https');
5987: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5988:
5989: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5990: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5991: } else {
5992: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5993: }
5994: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5995: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5996: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5997: }
5998: $resulttext .= '</li>';
5999: } else {
6000: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6001: }
1.112 raeburn 6002: } else {
1.128 raeburn 6003: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6004: }
6005: }
1.128 raeburn 6006: $resulttext .= '</ul></li>';
1.112 raeburn 6007: }
1.168 raeburn 6008: } elsif ($item eq 'helpurl') {
6009: if (ref($changes{$item}) eq 'HASH') {
6010: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6011: if (grep(/^\Q$lang\E$/,@delurls)) {
6012: my ($chg,$link);
6013: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6014: if ($lang eq 'nolang') {
6015: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6016: } else {
6017: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6018: }
6019: $resulttext .= '<li>'.$chg.'</li>';
6020: } else {
6021: my $chg;
6022: if ($lang eq 'nolang') {
6023: $chg = &mt('custom log-in help file for no preferred language');
6024: } else {
6025: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6026: }
6027: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6028: $loginhash{'login'}{'helpurl'}{$lang}.
6029: '?inhibitmenu=yes',$chg,600,500).
6030: '</li>';
6031: }
6032: }
6033: }
1.169 raeburn 6034: } elsif ($item eq 'captcha') {
6035: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6036: my $chgtxt;
1.169 raeburn 6037: if ($loginhash{'login'}{$item} eq 'notused') {
6038: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6039: } else {
6040: my %captchas = &captcha_phrases();
6041: if ($captchas{$loginhash{'login'}{$item}}) {
6042: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6043: } else {
6044: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6045: }
6046: }
6047: $resulttext .= '<li>'.$chgtxt.'</li>';
6048: }
6049: } elsif ($item eq 'recaptchakeys') {
6050: if (ref($loginhash{'login'}) eq 'HASH') {
6051: my ($privkey,$pubkey);
6052: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6053: $pubkey = $loginhash{'login'}{$item}{'public'};
6054: $privkey = $loginhash{'login'}{$item}{'private'};
6055: }
6056: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6057: if (!$pubkey) {
6058: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6059: } else {
6060: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6061: }
6062: if (!$privkey) {
6063: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6064: } else {
6065: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6066: }
6067: $chgtxt .= '</ul>';
6068: $resulttext .= '<li>'.$chgtxt.'</li>';
6069: }
1.41 raeburn 6070: } else {
6071: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6072: }
1.1 raeburn 6073: }
1.6 raeburn 6074: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6075: } else {
6076: $resulttext = &mt('No changes made to log-in page settings');
6077: }
6078: } else {
1.11 albertel 6079: $resulttext = '<span class="LC_error">'.
6080: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6081: }
1.6 raeburn 6082: if ($errors) {
1.9 raeburn 6083: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6084: $errors.'</ul>';
6085: }
6086: return $resulttext;
6087: }
6088:
6089: sub color_font_choices {
6090: my %choices =
6091: &Apache::lonlocal::texthash (
6092: img => "Header",
6093: bgs => "Background colors",
6094: links => "Link colors",
1.55 raeburn 6095: images => "Images",
1.6 raeburn 6096: font => "Font color",
1.201 raeburn 6097: fontmenu => "Font menu",
1.76 raeburn 6098: pgbg => "Page",
1.6 raeburn 6099: tabbg => "Header",
6100: sidebg => "Border",
6101: link => "Link",
6102: alink => "Active link",
6103: vlink => "Visited link",
6104: );
6105: return %choices;
6106: }
6107:
6108: sub modify_rolecolors {
1.205 raeburn 6109: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6110: my ($resulttext,%rolehash);
6111: $rolehash{'rolecolors'} = {};
1.55 raeburn 6112: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6113: if ($domconfig{'rolecolors'} eq '') {
6114: $domconfig{'rolecolors'} = {};
6115: }
6116: }
1.9 raeburn 6117: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6118: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6119: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6120: $dom);
6121: if ($putresult eq 'ok') {
6122: if (keys(%changes) > 0) {
1.41 raeburn 6123: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6124: if (ref($lastactref) eq 'HASH') {
6125: $lastactref->{'domainconfig'} = 1;
6126: }
1.6 raeburn 6127: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6128: $rolehash{'rolecolors'});
6129: } else {
6130: $resulttext = &mt('No changes made to default color schemes');
6131: }
6132: } else {
1.11 albertel 6133: $resulttext = '<span class="LC_error">'.
6134: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6135: }
6136: if ($errors) {
6137: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6138: $errors.'</ul>';
6139: }
6140: return $resulttext;
6141: }
6142:
6143: sub modify_colors {
1.9 raeburn 6144: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6145: my (%changes,%choices);
1.51 raeburn 6146: my @bgs;
1.6 raeburn 6147: my @links = ('link','alink','vlink');
1.41 raeburn 6148: my @logintext;
1.6 raeburn 6149: my @images;
6150: my $servadm = $r->dir_config('lonAdmEMail');
6151: my $errors;
1.200 raeburn 6152: my %defaults;
1.6 raeburn 6153: foreach my $role (@{$roles}) {
6154: if ($role eq 'login') {
1.12 raeburn 6155: %choices = &login_choices();
1.41 raeburn 6156: @logintext = ('textcol','bgcol');
1.12 raeburn 6157: } else {
6158: %choices = &color_font_choices();
6159: }
6160: if ($role eq 'login') {
1.41 raeburn 6161: @images = ('img','logo','domlogo','login');
1.51 raeburn 6162: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6163: } else {
6164: @images = ('img');
1.200 raeburn 6165: @bgs = ('pgbg','tabbg','sidebg');
6166: }
6167: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6168: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6169: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6170: }
6171: if ($role eq 'login') {
6172: foreach my $item (@logintext) {
1.234 raeburn 6173: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6174: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6175: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6176: }
6177: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6178: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6179: }
6180: }
6181: } else {
1.234 raeburn 6182: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6183: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6184: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6185: }
6186: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6187: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6188: }
1.6 raeburn 6189: }
1.200 raeburn 6190: foreach my $item (@bgs) {
1.234 raeburn 6191: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6192: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6193: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6194: }
6195: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6196: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6197: }
6198: }
6199: foreach my $item (@links) {
1.234 raeburn 6200: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6201: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6202: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6203: }
6204: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6205: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6206: }
1.6 raeburn 6207: }
1.46 raeburn 6208: my ($configuserok,$author_ok,$switchserver) =
6209: &config_check($dom,$confname,$servadm);
1.9 raeburn 6210: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6211: if (ref($domconfig->{$role}) ne 'HASH') {
6212: $domconfig->{$role} = {};
6213: }
1.8 raeburn 6214: foreach my $img (@images) {
1.70 raeburn 6215: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6216: if (defined($env{'form.login_showlogo_'.$img})) {
6217: $confhash->{$role}{'showlogo'}{$img} = 1;
6218: } else {
6219: $confhash->{$role}{'showlogo'}{$img} = 0;
6220: }
6221: }
1.18 albertel 6222: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6223: && !defined($domconfig->{$role}{$img})
6224: && !$env{'form.'.$role.'_del_'.$img}
6225: && $env{'form.'.$role.'_import_'.$img}) {
6226: # import the old configured image from the .tab setting
6227: # if they haven't provided a new one
6228: $domconfig->{$role}{$img} =
6229: $env{'form.'.$role.'_import_'.$img};
6230: }
1.6 raeburn 6231: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6232: my $error;
1.6 raeburn 6233: if ($configuserok eq 'ok') {
1.9 raeburn 6234: if ($switchserver) {
1.12 raeburn 6235: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6236: } else {
6237: if ($author_ok eq 'ok') {
6238: my ($result,$logourl) =
6239: &publishlogo($r,'upload',$role.'_'.$img,
6240: $dom,$confname,$img,$width,$height);
6241: if ($result eq 'ok') {
6242: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6243: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6244: } else {
1.12 raeburn 6245: $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 6246: }
6247: } else {
1.46 raeburn 6248: $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 6249: }
6250: }
6251: } else {
1.46 raeburn 6252: $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 6253: }
6254: if ($error) {
1.8 raeburn 6255: &Apache::lonnet::logthis($error);
1.11 albertel 6256: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6257: }
6258: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6259: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6260: my $error;
6261: if ($configuserok eq 'ok') {
6262: # is confname an author?
6263: if ($switchserver eq '') {
6264: if ($author_ok eq 'ok') {
6265: my ($result,$logourl) =
6266: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6267: $dom,$confname,$img,$width,$height);
6268: if ($result eq 'ok') {
6269: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6270: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6271: }
6272: }
6273: }
6274: }
1.6 raeburn 6275: }
6276: }
6277: }
6278: if (ref($domconfig) eq 'HASH') {
6279: if (ref($domconfig->{$role}) eq 'HASH') {
6280: foreach my $img (@images) {
6281: if ($domconfig->{$role}{$img} ne '') {
6282: if ($env{'form.'.$role.'_del_'.$img}) {
6283: $confhash->{$role}{$img} = '';
1.12 raeburn 6284: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6285: } else {
1.9 raeburn 6286: if ($confhash->{$role}{$img} eq '') {
6287: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6288: }
1.6 raeburn 6289: }
6290: } else {
6291: if ($env{'form.'.$role.'_del_'.$img}) {
6292: $confhash->{$role}{$img} = '';
1.12 raeburn 6293: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6294: }
6295: }
1.70 raeburn 6296: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6297: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6298: if ($confhash->{$role}{'showlogo'}{$img} ne
6299: $domconfig->{$role}{'showlogo'}{$img}) {
6300: $changes{$role}{'showlogo'}{$img} = 1;
6301: }
6302: } else {
6303: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6304: $changes{$role}{'showlogo'}{$img} = 1;
6305: }
6306: }
6307: }
6308: }
1.6 raeburn 6309: if ($domconfig->{$role}{'font'} ne '') {
6310: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6311: $changes{$role}{'font'} = 1;
6312: }
6313: } else {
6314: if ($confhash->{$role}{'font'}) {
6315: $changes{$role}{'font'} = 1;
6316: }
6317: }
1.107 raeburn 6318: if ($role ne 'login') {
6319: if ($domconfig->{$role}{'fontmenu'} ne '') {
6320: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6321: $changes{$role}{'fontmenu'} = 1;
6322: }
6323: } else {
6324: if ($confhash->{$role}{'fontmenu'}) {
6325: $changes{$role}{'fontmenu'} = 1;
6326: }
1.97 tempelho 6327: }
6328: }
1.6 raeburn 6329: foreach my $item (@bgs) {
6330: if ($domconfig->{$role}{$item} ne '') {
6331: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6332: $changes{$role}{'bgs'}{$item} = 1;
6333: }
6334: } else {
6335: if ($confhash->{$role}{$item}) {
6336: $changes{$role}{'bgs'}{$item} = 1;
6337: }
6338: }
6339: }
6340: foreach my $item (@links) {
6341: if ($domconfig->{$role}{$item} ne '') {
6342: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6343: $changes{$role}{'links'}{$item} = 1;
6344: }
6345: } else {
6346: if ($confhash->{$role}{$item}) {
6347: $changes{$role}{'links'}{$item} = 1;
6348: }
6349: }
6350: }
1.41 raeburn 6351: foreach my $item (@logintext) {
6352: if ($domconfig->{$role}{$item} ne '') {
6353: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6354: $changes{$role}{'logintext'}{$item} = 1;
6355: }
6356: } else {
6357: if ($confhash->{$role}{$item}) {
6358: $changes{$role}{'logintext'}{$item} = 1;
6359: }
6360: }
6361: }
1.6 raeburn 6362: } else {
6363: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6364: \@logintext,$confhash,\%changes);
1.6 raeburn 6365: }
6366: } else {
6367: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6368: \@logintext,$confhash,\%changes);
1.6 raeburn 6369: }
6370: }
6371: return ($errors,%changes);
6372: }
6373:
1.46 raeburn 6374: sub config_check {
6375: my ($dom,$confname,$servadm) = @_;
6376: my ($configuserok,$author_ok,$switchserver,%currroles);
6377: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6378: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6379: $confname,$servadm);
6380: if ($configuserok eq 'ok') {
6381: $switchserver = &check_switchserver($dom,$confname);
6382: if ($switchserver eq '') {
6383: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6384: }
6385: }
6386: return ($configuserok,$author_ok,$switchserver);
6387: }
6388:
1.6 raeburn 6389: sub default_change_checker {
1.41 raeburn 6390: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6391: foreach my $item (@{$links}) {
6392: if ($confhash->{$role}{$item}) {
6393: $changes->{$role}{'links'}{$item} = 1;
6394: }
6395: }
6396: foreach my $item (@{$bgs}) {
6397: if ($confhash->{$role}{$item}) {
6398: $changes->{$role}{'bgs'}{$item} = 1;
6399: }
6400: }
1.41 raeburn 6401: foreach my $item (@{$logintext}) {
6402: if ($confhash->{$role}{$item}) {
6403: $changes->{$role}{'logintext'}{$item} = 1;
6404: }
6405: }
1.6 raeburn 6406: foreach my $img (@{$images}) {
6407: if ($env{'form.'.$role.'_del_'.$img}) {
6408: $confhash->{$role}{$img} = '';
1.12 raeburn 6409: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6410: }
1.70 raeburn 6411: if ($role eq 'login') {
6412: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6413: $changes->{$role}{'showlogo'}{$img} = 1;
6414: }
6415: }
1.6 raeburn 6416: }
6417: if ($confhash->{$role}{'font'}) {
6418: $changes->{$role}{'font'} = 1;
6419: }
1.48 raeburn 6420: }
1.6 raeburn 6421:
6422: sub display_colorchgs {
6423: my ($dom,$changes,$roles,$confhash) = @_;
6424: my (%choices,$resulttext);
6425: if (!grep(/^login$/,@{$roles})) {
6426: $resulttext = &mt('Changes made:').'<br />';
6427: }
6428: foreach my $role (@{$roles}) {
6429: if ($role eq 'login') {
6430: %choices = &login_choices();
6431: } else {
6432: %choices = &color_font_choices();
6433: }
6434: if (ref($changes->{$role}) eq 'HASH') {
6435: if ($role ne 'login') {
6436: $resulttext .= '<h4>'.&mt($role).'</h4>';
6437: }
6438: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6439: if ($role ne 'login') {
6440: $resulttext .= '<ul>';
6441: }
6442: if (ref($changes->{$role}{$key}) eq 'HASH') {
6443: if ($role ne 'login') {
6444: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6445: }
6446: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6447: if (($role eq 'login') && ($key eq 'showlogo')) {
6448: if ($confhash->{$role}{$key}{$item}) {
6449: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6450: } else {
6451: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6452: }
6453: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6454: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6455: } else {
1.12 raeburn 6456: my $newitem = $confhash->{$role}{$item};
6457: if ($key eq 'images') {
6458: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6459: }
6460: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6461: }
6462: }
6463: if ($role ne 'login') {
6464: $resulttext .= '</ul></li>';
6465: }
6466: } else {
6467: if ($confhash->{$role}{$key} eq '') {
6468: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6469: } else {
6470: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6471: }
6472: }
6473: if ($role ne 'login') {
6474: $resulttext .= '</ul>';
6475: }
6476: }
6477: }
6478: }
1.3 raeburn 6479: return $resulttext;
1.1 raeburn 6480: }
6481:
1.9 raeburn 6482: sub thumb_dimensions {
6483: return ('200','50');
6484: }
6485:
1.16 raeburn 6486: sub check_dimensions {
6487: my ($inputfile) = @_;
6488: my ($fullwidth,$fullheight);
6489: if ($inputfile =~ m|^[/\w.\-]+$|) {
6490: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6491: my $imageinfo = <PIPE>;
6492: if (!close(PIPE)) {
6493: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6494: }
6495: chomp($imageinfo);
6496: my ($fullsize) =
1.21 raeburn 6497: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6498: if ($fullsize) {
6499: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6500: }
6501: }
6502: }
6503: return ($fullwidth,$fullheight);
6504: }
6505:
1.9 raeburn 6506: sub check_configuser {
6507: my ($uhome,$dom,$confname,$servadm) = @_;
6508: my ($configuserok,%currroles);
6509: if ($uhome eq 'no_host') {
6510: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6511: my $configpass = &LONCAPA::Enrollment::create_password();
6512: $configuserok =
6513: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6514: $configpass,'','','','','',undef,$servadm);
6515: } else {
6516: $configuserok = 'ok';
6517: %currroles =
6518: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6519: }
6520: return ($configuserok,%currroles);
6521: }
6522:
6523: sub check_authorstatus {
6524: my ($dom,$confname,%currroles) = @_;
6525: my $author_ok;
1.40 raeburn 6526: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6527: my $start = time;
6528: my $end = 0;
6529: $author_ok =
6530: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6531: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6532: } else {
6533: $author_ok = 'ok';
6534: }
6535: return $author_ok;
6536: }
6537:
6538: sub publishlogo {
1.46 raeburn 6539: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6540: my ($output,$fname,$logourl);
6541: if ($action eq 'upload') {
6542: $fname=$env{'form.'.$formname.'.filename'};
6543: chop($env{'form.'.$formname});
6544: } else {
6545: ($fname) = ($formname =~ /([^\/]+)$/);
6546: }
1.46 raeburn 6547: if ($savefileas ne '') {
6548: $fname = $savefileas;
6549: }
1.9 raeburn 6550: $fname=&Apache::lonnet::clean_filename($fname);
6551: # See if there is anything left
6552: unless ($fname) { return ('error: no uploaded file'); }
6553: $fname="$subdir/$fname";
1.210 raeburn 6554: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6555: my $filepath="$docroot/priv";
6556: my $relpath = "$dom/$confname";
1.9 raeburn 6557: my ($fnamepath,$file,$fetchthumb);
6558: $file=$fname;
6559: if ($fname=~m|/|) {
6560: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6561: }
1.164 raeburn 6562: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6563: my $count;
1.164 raeburn 6564: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6565: $filepath.="/$parts[$count]";
6566: if ((-e $filepath)!=1) {
6567: mkdir($filepath,02770);
6568: }
6569: }
6570: # Check for bad extension and disallow upload
6571: if ($file=~/\.(\w+)$/ &&
6572: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6573: $output =
1.207 bisitz 6574: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6575: } elsif ($file=~/\.(\w+)$/ &&
6576: !defined(&Apache::loncommon::fileembstyle($1))) {
6577: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6578: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6579: $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 6580: } elsif (-d "$filepath/$file") {
1.195 bisitz 6581: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6582: } else {
6583: my $source = $filepath.'/'.$file;
6584: my $logfile;
6585: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6586: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6587: }
6588: print $logfile
6589: "\n================= Publish ".localtime()." ================\n".
6590: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6591: # Save the file
6592: if (!open(FH,'>'.$source)) {
6593: &Apache::lonnet::logthis('Failed to create '.$source);
6594: return (&mt('Failed to create file'));
6595: }
6596: if ($action eq 'upload') {
6597: if (!print FH ($env{'form.'.$formname})) {
6598: &Apache::lonnet::logthis('Failed to write to '.$source);
6599: return (&mt('Failed to write file'));
6600: }
6601: } else {
6602: my $original = &Apache::lonnet::filelocation('',$formname);
6603: if(!copy($original,$source)) {
6604: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6605: return (&mt('Failed to write file'));
6606: }
6607: }
6608: close(FH);
6609: chmod(0660, $source); # Permissions to rw-rw---.
6610:
6611: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6612: my $copyfile=$targetdir.'/'.$file;
6613:
6614: my @parts=split(/\//,$targetdir);
6615: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6616: for (my $count=5;$count<=$#parts;$count++) {
6617: $path.="/$parts[$count]";
6618: if (!-e $path) {
6619: print $logfile "\nCreating directory ".$path;
6620: mkdir($path,02770);
6621: }
6622: }
6623: my $versionresult;
6624: if (-e $copyfile) {
6625: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6626: } else {
6627: $versionresult = 'ok';
6628: }
6629: if ($versionresult eq 'ok') {
6630: if (copy($source,$copyfile)) {
6631: print $logfile "\nCopied original source to ".$copyfile."\n";
6632: $output = 'ok';
6633: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6634: push(@{$modified_urls},[$copyfile,$source]);
6635: my $metaoutput =
6636: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6637: unless ($registered_cleanup) {
6638: my $handlers = $r->get_handlers('PerlCleanupHandler');
6639: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6640: $registered_cleanup=1;
6641: }
1.9 raeburn 6642: } else {
6643: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6644: $output = &mt('Failed to copy file to RES space').", $!";
6645: }
6646: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6647: my $inputfile = $filepath.'/'.$file;
6648: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6649: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6650: if ($fullwidth ne '' && $fullheight ne '') {
6651: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6652: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6653: system("convert -sample $thumbsize $inputfile $outfile");
6654: chmod(0660, $filepath.'/tn-'.$file);
6655: if (-e $outfile) {
6656: my $copyfile=$targetdir.'/tn-'.$file;
6657: if (copy($outfile,$copyfile)) {
6658: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6659: my $thumb_metaoutput =
6660: &write_metadata($dom,$confname,$formname,
6661: $targetdir,'tn-'.$file,$logfile);
6662: push(@{$modified_urls},[$copyfile,$outfile]);
6663: unless ($registered_cleanup) {
6664: my $handlers = $r->get_handlers('PerlCleanupHandler');
6665: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6666: $registered_cleanup=1;
6667: }
1.16 raeburn 6668: } else {
6669: print $logfile "\nUnable to write ".$copyfile.
6670: ':'.$!."\n";
6671: }
6672: }
1.9 raeburn 6673: }
6674: }
6675: }
6676: } else {
6677: $output = $versionresult;
6678: }
6679: }
6680: return ($output,$logourl);
6681: }
6682:
6683: sub logo_versioning {
6684: my ($targetdir,$file,$logfile) = @_;
6685: my $target = $targetdir.'/'.$file;
6686: my ($maxversion,$fn,$extn,$output);
6687: $maxversion = 0;
6688: if ($file =~ /^(.+)\.(\w+)$/) {
6689: $fn=$1;
6690: $extn=$2;
6691: }
6692: opendir(DIR,$targetdir);
6693: while (my $filename=readdir(DIR)) {
6694: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6695: $maxversion=($1>$maxversion)?$1:$maxversion;
6696: }
6697: }
6698: $maxversion++;
6699: print $logfile "\nCreating old version ".$maxversion."\n";
6700: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6701: if (copy($target,$copyfile)) {
6702: print $logfile "Copied old target to ".$copyfile."\n";
6703: $copyfile=$copyfile.'.meta';
6704: if (copy($target.'.meta',$copyfile)) {
6705: print $logfile "Copied old target metadata to ".$copyfile."\n";
6706: $output = 'ok';
6707: } else {
6708: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6709: $output = &mt('Failed to copy old meta').", $!, ";
6710: }
6711: } else {
6712: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6713: $output = &mt('Failed to copy old target').", $!, ";
6714: }
6715: return $output;
6716: }
6717:
6718: sub write_metadata {
6719: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6720: my (%metadatafields,%metadatakeys,$output);
6721: $metadatafields{'title'}=$formname;
6722: $metadatafields{'creationdate'}=time;
6723: $metadatafields{'lastrevisiondate'}=time;
6724: $metadatafields{'copyright'}='public';
6725: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6726: $env{'user.domain'};
6727: $metadatafields{'authorspace'}=$confname.':'.$dom;
6728: $metadatafields{'domain'}=$dom;
6729: {
6730: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6731: my $mfh;
1.155 raeburn 6732: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6733: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6734: unless ($_=~/\./) {
6735: my $unikey=$_;
6736: $unikey=~/^([A-Za-z]+)/;
6737: my $tag=$1;
6738: $tag=~tr/A-Z/a-z/;
6739: print $mfh "\n\<$tag";
6740: foreach (split(/\,/,$metadatakeys{$unikey})) {
6741: my $value=$metadatafields{$unikey.'.'.$_};
6742: $value=~s/\"/\'\'/g;
6743: print $mfh ' '.$_.'="'.$value.'"';
6744: }
6745: print $mfh '>'.
6746: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6747: .'</'.$tag.'>';
6748: }
6749: }
6750: $output = 'ok';
6751: print $logfile "\nWrote metadata";
6752: close($mfh);
6753: } else {
6754: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6755: $output = &mt('Could not write metadata');
6756: }
6757: }
1.155 raeburn 6758: return $output;
6759: }
6760:
6761: sub notifysubscribed {
6762: foreach my $targetsource (@{$modified_urls}){
6763: next unless (ref($targetsource) eq 'ARRAY');
6764: my ($target,$source)=@{$targetsource};
6765: if ($source ne '') {
6766: if (open(my $logfh,'>>'.$source.'.log')) {
6767: print $logfh "\nCleanup phase: Notifications\n";
6768: my @subscribed=&subscribed_hosts($target);
6769: foreach my $subhost (@subscribed) {
6770: print $logfh "\nNotifying host ".$subhost.':';
6771: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6772: print $logfh $reply;
6773: }
6774: my @subscribedmeta=&subscribed_hosts("$target.meta");
6775: foreach my $subhost (@subscribedmeta) {
6776: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6777: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6778: $subhost);
6779: print $logfh $reply;
6780: }
6781: print $logfh "\n============ Done ============\n";
1.160 raeburn 6782: close($logfh);
1.155 raeburn 6783: }
6784: }
6785: }
6786: return OK;
6787: }
6788:
6789: sub subscribed_hosts {
6790: my ($target) = @_;
6791: my @subscribed;
6792: if (open(my $fh,"<$target.subscription")) {
6793: while (my $subline=<$fh>) {
6794: if ($subline =~ /^($match_lonid):/) {
6795: my $host = $1;
6796: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6797: unless (grep(/^\Q$host\E$/,@subscribed)) {
6798: push(@subscribed,$host);
6799: }
6800: }
6801: }
6802: }
6803: }
6804: return @subscribed;
1.9 raeburn 6805: }
6806:
6807: sub check_switchserver {
6808: my ($dom,$confname) = @_;
6809: my ($allowed,$switchserver);
6810: my $home = &Apache::lonnet::homeserver($confname,$dom);
6811: if ($home eq 'no_host') {
6812: $home = &Apache::lonnet::domain($dom,'primary');
6813: }
6814: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6815: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6816: if (!$allowed) {
1.180 raeburn 6817: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6818: }
6819: return $switchserver;
6820: }
6821:
1.1 raeburn 6822: sub modify_quotas {
1.216 raeburn 6823: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6824: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6825: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 6826: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6827: $validationfieldsref);
1.86 raeburn 6828: if ($action eq 'quotas') {
6829: $context = 'tools';
1.163 raeburn 6830: } else {
1.86 raeburn 6831: $context = $action;
6832: }
6833: if ($context eq 'requestcourses') {
1.216 raeburn 6834: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6835: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6836: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6837: %titles = &courserequest_titles();
6838: $toolregexp = join('|',@usertools);
6839: %conditions = &courserequest_conditions();
1.216 raeburn 6840: $confname = $dom.'-domainconfig';
6841: my $servadm = $r->dir_config('lonAdmEMail');
6842: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 6843: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6844: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 6845: } elsif ($context eq 'requestauthor') {
6846: @usertools = ('author');
6847: %titles = &authorrequest_titles();
1.86 raeburn 6848: } else {
1.162 raeburn 6849: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6850: %titles = &tool_titles();
1.86 raeburn 6851: }
1.212 raeburn 6852: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6853: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6854: foreach my $key (keys(%env)) {
1.101 raeburn 6855: if ($context eq 'requestcourses') {
6856: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6857: my $item = $1;
6858: my $type = $2;
6859: if ($type =~ /^limit_(.+)/) {
6860: $limithash{$item}{$1} = $env{$key};
6861: } else {
6862: $confhash{$item}{$type} = $env{$key};
6863: }
6864: }
1.163 raeburn 6865: } elsif ($context eq 'requestauthor') {
6866: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6867: $confhash{$1} = $env{$key};
6868: }
1.101 raeburn 6869: } else {
1.86 raeburn 6870: if ($key =~ /^form\.quota_(.+)$/) {
6871: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6872: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6873: $confhash{'authorquota'}{$1} = $env{$key};
6874: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6875: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6876: }
1.72 raeburn 6877: }
6878: }
1.163 raeburn 6879: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6880: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6881: @approvalnotify = sort(@approvalnotify);
6882: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6883: my @crstypes = ('official','unofficial','community','textbook');
6884: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6885: foreach my $type (@hasuniquecode) {
6886: if (grep(/^\Q$type\E$/,@crstypes)) {
6887: $confhash{'uniquecode'}{$type} = 1;
6888: }
1.216 raeburn 6889: }
1.242 raeburn 6890: my (%newbook,%allpos);
1.216 raeburn 6891: if ($context eq 'requestcourses') {
1.242 raeburn 6892: foreach my $type ('textbooks','templates') {
6893: @{$allpos{$type}} = ();
6894: my $invalid;
6895: if ($type eq 'textbooks') {
6896: $invalid = &mt('Invalid LON-CAPA course for textbook');
6897: } else {
6898: $invalid = &mt('Invalid LON-CAPA course for template');
6899: }
6900: if ($env{'form.'.$type.'_addbook'}) {
6901: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6902: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6903: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6904: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6905: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6906: } else {
6907: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6908: my $position = $env{'form.'.$type.'_addbook_pos'};
6909: $position =~ s/\D+//g;
6910: if ($position ne '') {
6911: $allpos{$type}[$position] = $newbook{$type};
6912: }
1.216 raeburn 6913: }
1.242 raeburn 6914: } else {
6915: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 6916: }
6917: }
1.242 raeburn 6918: }
1.216 raeburn 6919: }
1.102 raeburn 6920: if (ref($domconfig{$action}) eq 'HASH') {
6921: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6922: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6923: $changes{'notify'}{'approval'} = 1;
6924: }
6925: } else {
1.144 raeburn 6926: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6927: $changes{'notify'}{'approval'} = 1;
6928: }
6929: }
1.218 raeburn 6930: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6931: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6932: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6933: unless ($confhash{'uniquecode'}{$crstype}) {
6934: $changes{'uniquecode'} = 1;
6935: }
6936: }
6937: unless ($changes{'uniquecode'}) {
6938: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6939: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6940: $changes{'uniquecode'} = 1;
6941: }
6942: }
6943: }
6944: } else {
6945: $changes{'uniquecode'} = 1;
6946: }
6947: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6948: $changes{'uniquecode'} = 1;
1.216 raeburn 6949: }
6950: if ($context eq 'requestcourses') {
1.242 raeburn 6951: foreach my $type ('textbooks','templates') {
6952: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6953: my %deletions;
6954: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6955: if (@todelete) {
6956: map { $deletions{$_} = 1; } @todelete;
6957: }
6958: my %imgdeletions;
6959: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6960: if (@todeleteimages) {
6961: map { $imgdeletions{$_} = 1; } @todeleteimages;
6962: }
6963: my $maxnum = $env{'form.'.$type.'_maxnum'};
6964: for (my $i=0; $i<=$maxnum; $i++) {
6965: my $itemid = $env{'form.'.$type.'_id_'.$i};
6966: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6967: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6968: if ($deletions{$key}) {
6969: if ($domconfig{$action}{$type}{$key}{'image'}) {
6970: #FIXME need to obsolete item in RES space
6971: }
6972: next;
6973: } else {
6974: my $newpos = $env{'form.'.$itemid};
6975: $newpos =~ s/\D+//g;
1.243 ! raeburn 6976: foreach my $item ('subject','title','publisher','author') {
! 6977: next if ((($item eq 'author') || ($item eq 'publisher')) &&
! 6978: ($type eq 'templates'));
1.242 raeburn 6979: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6980: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6981: $changes{$type}{$key} = 1;
6982: }
6983: }
6984: $allpos{$type}[$newpos] = $key;
6985: }
6986: if ($imgdeletions{$key}) {
6987: $changes{$type}{$key} = 1;
1.216 raeburn 6988: #FIXME need to obsolete item in RES space
1.242 raeburn 6989: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
6990: my ($cdom,$cnum) = split(/_/,$key);
6991: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
6992: $cdom,$cnum,$type,$configuserok,
6993: $switchserver,$author_ok);
6994: if ($imgurl) {
6995: $confhash{$type}{$key}{'image'} = $imgurl;
6996: $changes{$type}{$key} = 1;
1.216 raeburn 6997: }
1.242 raeburn 6998: if ($error) {
6999: &Apache::lonnet::logthis($error);
7000: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7001: }
7002: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7003: $confhash{$type}{$key}{'image'} =
7004: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7005: }
7006: }
7007: }
7008: }
7009: }
7010: }
1.102 raeburn 7011: } else {
1.144 raeburn 7012: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7013: $changes{'notify'}{'approval'} = 1;
7014: }
1.218 raeburn 7015: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7016: $changes{'uniquecode'} = 1;
7017: }
7018: }
7019: if ($context eq 'requestcourses') {
1.242 raeburn 7020: foreach my $type ('textbooks','templates') {
7021: if ($newbook{$type}) {
7022: $changes{$type}{$newbook{$type}} = 1;
1.243 ! raeburn 7023: foreach my $item ('subject','title','publisher','author') {
! 7024: next if ((($item eq 'author') || ($item eq 'publisher')) &&
! 7025: ($type eq 'template'));
1.242 raeburn 7026: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7027: if ($env{'form.'.$type.'_addbook_'.$item}) {
7028: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7029: }
7030: }
7031: if ($type eq 'textbooks') {
7032: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7033: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7034: my ($imageurl,$error) =
7035: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7036: $configuserok,$switchserver,$author_ok);
7037: if ($imageurl) {
7038: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7039: }
7040: if ($error) {
7041: &Apache::lonnet::logthis($error);
7042: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7043: }
7044: }
1.216 raeburn 7045: }
7046: }
1.242 raeburn 7047: if (@{$allpos{$type}} > 0) {
7048: my $idx = 0;
7049: foreach my $item (@{$allpos{$type}}) {
7050: if ($item ne '') {
7051: $confhash{$type}{$item}{'order'} = $idx;
7052: if (ref($domconfig{$action}) eq 'HASH') {
7053: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7054: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7055: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7056: $changes{$type}{$item} = 1;
7057: }
1.216 raeburn 7058: }
7059: }
7060: }
1.242 raeburn 7061: $idx ++;
1.216 raeburn 7062: }
7063: }
7064: }
7065: }
1.235 raeburn 7066: if (ref($validationitemsref) eq 'ARRAY') {
7067: foreach my $item (@{$validationitemsref}) {
7068: if ($item eq 'fields') {
7069: my @changed;
7070: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7071: if (@{$confhash{'validation'}{$item}} > 0) {
7072: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7073: }
7074: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7075: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7076: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7077: $domconfig{'requestcourses'}{'validation'}{$item});
7078: } else {
7079: @changed = @{$confhash{'validation'}{$item}};
7080: }
7081: } else {
7082: @changed = @{$confhash{'validation'}{$item}};
7083: }
7084: if (@changed) {
7085: if ($confhash{'validation'}{$item}) {
7086: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7087: } else {
7088: $changes{'validation'}{$item} = &mt('None');
7089: }
7090: }
7091: } else {
7092: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7093: if ($item eq 'markup') {
7094: if ($env{'form.requestcourses_validation_'.$item}) {
7095: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7096: }
7097: }
7098: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7099: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7100: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7101: }
7102: } else {
7103: if ($confhash{'validation'}{$item} ne '') {
7104: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7105: }
7106: }
7107: }
7108: }
7109: }
7110: if ($env{'form.validationdc'}) {
7111: my $newval = $env{'form.validationdc'};
7112: my %domcoords = &get_active_dcs($dom);
7113: if (exists($domcoords{$newval})) {
7114: $confhash{'validation'}{'dc'} = $newval;
7115: }
7116: }
7117: if (ref($confhash{'validation'}) eq 'HASH') {
7118: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7119: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7120: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7121: if ($confhash{'validation'}{'dc'} eq '') {
7122: $changes{'validation'}{'dc'} = &mt('None');
7123: } else {
7124: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7125: }
7126: }
7127: } elsif ($confhash{'validation'}{'dc'} ne '') {
7128: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7129: }
7130: } elsif ($confhash{'validation'}{'dc'} ne '') {
7131: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7132: }
7133: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7134: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7135: $changes{'validation'}{'dc'} = &mt('None');
7136: }
7137: }
1.102 raeburn 7138: }
7139: } else {
1.86 raeburn 7140: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7141: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7142: }
1.72 raeburn 7143: foreach my $item (@usertools) {
7144: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7145: my $unset;
1.101 raeburn 7146: if ($context eq 'requestcourses') {
1.104 raeburn 7147: $unset = '0';
7148: if ($type eq '_LC_adv') {
7149: $unset = '';
7150: }
1.101 raeburn 7151: if ($confhash{$item}{$type} eq 'autolimit') {
7152: $confhash{$item}{$type} .= '=';
7153: unless ($limithash{$item}{$type} =~ /\D/) {
7154: $confhash{$item}{$type} .= $limithash{$item}{$type};
7155: }
7156: }
1.163 raeburn 7157: } elsif ($context eq 'requestauthor') {
7158: $unset = '0';
7159: if ($type eq '_LC_adv') {
7160: $unset = '';
7161: }
1.72 raeburn 7162: } else {
1.101 raeburn 7163: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7164: $confhash{$item}{$type} = 1;
7165: } else {
7166: $confhash{$item}{$type} = 0;
7167: }
1.72 raeburn 7168: }
1.86 raeburn 7169: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7170: if ($action eq 'requestauthor') {
7171: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7172: $changes{$type} = 1;
7173: }
7174: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7175: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7176: $changes{$item}{$type} = 1;
7177: }
7178: } else {
7179: if ($context eq 'requestcourses') {
1.104 raeburn 7180: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7181: $changes{$item}{$type} = 1;
7182: }
7183: } else {
7184: if (!$confhash{$item}{$type}) {
7185: $changes{$item}{$type} = 1;
7186: }
7187: }
7188: }
7189: } else {
7190: if ($context eq 'requestcourses') {
1.104 raeburn 7191: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7192: $changes{$item}{$type} = 1;
7193: }
1.163 raeburn 7194: } elsif ($context eq 'requestauthor') {
7195: if ($confhash{$type} ne $unset) {
7196: $changes{$type} = 1;
7197: }
1.72 raeburn 7198: } else {
7199: if (!$confhash{$item}{$type}) {
7200: $changes{$item}{$type} = 1;
7201: }
7202: }
7203: }
1.1 raeburn 7204: }
7205: }
1.163 raeburn 7206: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7207: if (ref($domconfig{'quotas'}) eq 'HASH') {
7208: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7209: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7210: if (exists($confhash{'defaultquota'}{$key})) {
7211: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7212: $changes{'defaultquota'}{$key} = 1;
7213: }
7214: } else {
7215: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7216: }
7217: }
1.86 raeburn 7218: } else {
7219: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7220: if (exists($confhash{'defaultquota'}{$key})) {
7221: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7222: $changes{'defaultquota'}{$key} = 1;
7223: }
7224: } else {
7225: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7226: }
1.1 raeburn 7227: }
7228: }
1.197 raeburn 7229: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7230: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7231: if (exists($confhash{'authorquota'}{$key})) {
7232: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7233: $changes{'authorquota'}{$key} = 1;
7234: }
7235: } else {
7236: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7237: }
7238: }
7239: }
1.1 raeburn 7240: }
1.86 raeburn 7241: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7242: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7243: if (ref($domconfig{'quotas'}) eq 'HASH') {
7244: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7245: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7246: $changes{'defaultquota'}{$key} = 1;
7247: }
7248: } else {
7249: if (!exists($domconfig{'quotas'}{$key})) {
7250: $changes{'defaultquota'}{$key} = 1;
7251: }
1.72 raeburn 7252: }
7253: } else {
1.86 raeburn 7254: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7255: }
1.1 raeburn 7256: }
7257: }
1.197 raeburn 7258: if (ref($confhash{'authorquota'}) eq 'HASH') {
7259: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7260: if (ref($domconfig{'quotas'}) eq 'HASH') {
7261: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7262: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7263: $changes{'authorquota'}{$key} = 1;
7264: }
7265: } else {
7266: $changes{'authorquota'}{$key} = 1;
7267: }
7268: } else {
7269: $changes{'authorquota'}{$key} = 1;
7270: }
7271: }
7272: }
1.1 raeburn 7273: }
1.72 raeburn 7274:
1.163 raeburn 7275: if ($context eq 'requestauthor') {
7276: $domdefaults{'requestauthor'} = \%confhash;
7277: } else {
7278: foreach my $key (keys(%confhash)) {
1.242 raeburn 7279: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 7280: $domdefaults{$key} = $confhash{$key};
7281: }
1.163 raeburn 7282: }
1.72 raeburn 7283: }
1.163 raeburn 7284:
1.1 raeburn 7285: my %quotahash = (
1.86 raeburn 7286: $action => { %confhash }
1.1 raeburn 7287: );
7288: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7289: $dom);
7290: if ($putresult eq 'ok') {
7291: if (keys(%changes) > 0) {
1.72 raeburn 7292: my $cachetime = 24*60*60;
7293: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7294: if (ref($lastactref) eq 'HASH') {
7295: $lastactref->{'domdefaults'} = 1;
7296: }
1.1 raeburn 7297: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7298: unless (($context eq 'requestcourses') ||
1.163 raeburn 7299: ($context eq 'requestauthor')) {
1.86 raeburn 7300: if (ref($changes{'defaultquota'}) eq 'HASH') {
7301: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7302: foreach my $type (@{$types},'default') {
7303: if (defined($changes{'defaultquota'}{$type})) {
7304: my $typetitle = $usertypes->{$type};
7305: if ($type eq 'default') {
7306: $typetitle = $othertitle;
7307: }
1.213 raeburn 7308: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7309: }
7310: }
1.86 raeburn 7311: $resulttext .= '</ul></li>';
1.72 raeburn 7312: }
1.197 raeburn 7313: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7314: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7315: foreach my $type (@{$types},'default') {
7316: if (defined($changes{'authorquota'}{$type})) {
7317: my $typetitle = $usertypes->{$type};
7318: if ($type eq 'default') {
7319: $typetitle = $othertitle;
7320: }
1.213 raeburn 7321: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7322: }
7323: }
7324: $resulttext .= '</ul></li>';
7325: }
1.72 raeburn 7326: }
1.80 raeburn 7327: my %newenv;
1.72 raeburn 7328: foreach my $item (@usertools) {
1.163 raeburn 7329: my (%haschgs,%inconf);
7330: if ($context eq 'requestauthor') {
7331: %haschgs = %changes;
1.210 raeburn 7332: %inconf = %confhash;
1.163 raeburn 7333: } else {
7334: if (ref($changes{$item}) eq 'HASH') {
7335: %haschgs = %{$changes{$item}};
7336: }
7337: if (ref($confhash{$item}) eq 'HASH') {
7338: %inconf = %{$confhash{$item}};
7339: }
7340: }
7341: if (keys(%haschgs) > 0) {
1.80 raeburn 7342: my $newacc =
7343: &Apache::lonnet::usertools_access($env{'user.name'},
7344: $env{'user.domain'},
1.86 raeburn 7345: $item,'reload',$context);
1.210 raeburn 7346: if (($context eq 'requestcourses') ||
1.163 raeburn 7347: ($context eq 'requestauthor')) {
1.108 raeburn 7348: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7349: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7350: }
7351: } else {
7352: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7353: $newenv{'environment.availabletools.'.$item} = $newacc;
7354: }
1.80 raeburn 7355: }
1.163 raeburn 7356: unless ($context eq 'requestauthor') {
7357: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7358: }
1.72 raeburn 7359: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7360: if ($haschgs{$type}) {
1.72 raeburn 7361: my $typetitle = $usertypes->{$type};
7362: if ($type eq 'default') {
7363: $typetitle = $othertitle;
7364: } elsif ($type eq '_LC_adv') {
7365: $typetitle = 'LON-CAPA Advanced Users';
7366: }
1.163 raeburn 7367: if ($inconf{$type}) {
1.101 raeburn 7368: if ($context eq 'requestcourses') {
7369: my $cond;
1.163 raeburn 7370: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7371: if ($1 eq '') {
7372: $cond = &mt('(Automatic processing of any request).');
7373: } else {
7374: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7375: }
7376: } else {
1.163 raeburn 7377: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7378: }
7379: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7380: } elsif ($context eq 'requestauthor') {
7381: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7382: $titles{$inconf{$type}},$typetitle);
7383:
1.101 raeburn 7384: } else {
7385: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7386: }
1.72 raeburn 7387: } else {
1.104 raeburn 7388: if ($type eq '_LC_adv') {
1.163 raeburn 7389: if ($inconf{$type} eq '0') {
1.104 raeburn 7390: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7391: } else {
7392: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7393: }
7394: } else {
7395: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7396: }
1.72 raeburn 7397: }
7398: }
1.26 raeburn 7399: }
1.163 raeburn 7400: unless ($context eq 'requestauthor') {
7401: $resulttext .= '</ul></li>';
7402: }
1.26 raeburn 7403: }
1.1 raeburn 7404: }
1.163 raeburn 7405: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7406: if (ref($changes{'notify'}) eq 'HASH') {
7407: if ($changes{'notify'}{'approval'}) {
7408: if (ref($confhash{'notify'}) eq 'HASH') {
7409: if ($confhash{'notify'}{'approval'}) {
7410: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7411: } else {
1.163 raeburn 7412: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7413: }
7414: }
7415: }
7416: }
7417: }
1.216 raeburn 7418: if ($action eq 'requestcourses') {
7419: my @offon = ('off','on');
7420: if ($changes{'uniquecode'}) {
1.218 raeburn 7421: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7422: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7423: $resulttext .= '<li>'.
7424: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7425: '</li>';
7426: } else {
7427: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7428: '</li>';
7429: }
1.216 raeburn 7430: }
1.242 raeburn 7431: foreach my $type ('textbooks','templates') {
7432: if (ref($changes{$type}) eq 'HASH') {
7433: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7434: foreach my $key (sort(keys(%{$changes{$type}}))) {
7435: my %coursehash = &Apache::lonnet::coursedescription($key);
7436: my $coursetitle = $coursehash{'description'};
7437: my $position = $confhash{$type}{$key}{'order'} + 1;
7438: $resulttext .= '<li>';
1.243 ! raeburn 7439: foreach my $item ('subject','title','publisher','author') {
! 7440: next if ((($item eq 'author') || ($item eq 'publisher')) &&
! 7441: ($type eq 'templates'));
1.242 raeburn 7442: my $name = $item.':';
7443: $name =~ s/^(\w)/\U$1/;
7444: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7445: }
7446: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7447: if ($type eq 'textbooks') {
7448: if ($confhash{$type}{$key}{'image'}) {
7449: $resulttext .= ' '.&mt('Image: [_1]',
7450: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7451: ' alt="Textbook cover" />').'<br />';
7452: }
7453: }
7454: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 7455: }
1.242 raeburn 7456: $resulttext .= '</ul></li>';
1.216 raeburn 7457: }
7458: }
1.235 raeburn 7459: if (ref($changes{'validation'}) eq 'HASH') {
7460: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7461: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7462: foreach my $item (@{$validationitemsref}) {
7463: if (exists($changes{'validation'}{$item})) {
7464: if ($item eq 'markup') {
7465: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7466: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7467: } else {
7468: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7469: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7470: }
7471: }
7472: }
7473: if (exists($changes{'validation'}{'dc'})) {
7474: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7475: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7476: }
7477: }
7478: }
1.216 raeburn 7479: }
1.1 raeburn 7480: $resulttext .= '</ul>';
1.80 raeburn 7481: if (keys(%newenv)) {
7482: &Apache::lonnet::appenv(\%newenv);
7483: }
1.1 raeburn 7484: } else {
1.86 raeburn 7485: if ($context eq 'requestcourses') {
7486: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7487: } elsif ($context eq 'requestauthor') {
7488: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7489: } else {
1.90 weissno 7490: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7491: }
1.1 raeburn 7492: }
7493: } else {
1.11 albertel 7494: $resulttext = '<span class="LC_error">'.
7495: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7496: }
1.216 raeburn 7497: if ($errors) {
7498: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7499: '<ul>'.$errors.'</ul></p>';
7500: }
1.3 raeburn 7501: return $resulttext;
1.1 raeburn 7502: }
7503:
1.216 raeburn 7504: sub process_textbook_image {
1.242 raeburn 7505: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 7506: my $filename = $env{'form.'.$caller.'.filename'};
7507: my ($error,$url);
7508: my ($width,$height) = (50,50);
7509: if ($configuserok eq 'ok') {
7510: if ($switchserver) {
7511: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7512: $switchserver);
7513: } elsif ($author_ok eq 'ok') {
7514: my ($result,$imageurl) =
7515: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 7516: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 7517: if ($result eq 'ok') {
7518: $url = $imageurl;
7519: } else {
7520: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7521: }
7522: } else {
7523: $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);
7524: }
7525: } else {
7526: $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);
7527: }
7528: return ($url,$error);
7529: }
7530:
1.3 raeburn 7531: sub modify_autoenroll {
1.205 raeburn 7532: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7533: my ($resulttext,%changes);
7534: my %currautoenroll;
7535: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7536: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7537: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7538: }
7539: }
7540: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7541: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7542: sender => 'Sender for notification messages',
7543: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7544: my @offon = ('off','on');
1.17 raeburn 7545: my $sender_uname = $env{'form.sender_uname'};
7546: my $sender_domain = $env{'form.sender_domain'};
7547: if ($sender_domain eq '') {
7548: $sender_uname = '';
7549: } elsif ($sender_uname eq '') {
7550: $sender_domain = '';
7551: }
1.129 raeburn 7552: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7553: my %autoenrollhash = (
1.129 raeburn 7554: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7555: 'sender_uname' => $sender_uname,
7556: 'sender_domain' => $sender_domain,
7557: 'co-owners' => $coowners,
1.1 raeburn 7558: }
7559: );
1.4 raeburn 7560: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7561: $dom);
1.1 raeburn 7562: if ($putresult eq 'ok') {
7563: if (exists($currautoenroll{'run'})) {
7564: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7565: $changes{'run'} = 1;
7566: }
7567: } elsif ($autorun) {
7568: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7569: $changes{'run'} = 1;
1.1 raeburn 7570: }
7571: }
1.17 raeburn 7572: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7573: $changes{'sender'} = 1;
7574: }
1.17 raeburn 7575: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7576: $changes{'sender'} = 1;
7577: }
1.129 raeburn 7578: if ($currautoenroll{'co-owners'} ne '') {
7579: if ($currautoenroll{'co-owners'} ne $coowners) {
7580: $changes{'coowners'} = 1;
7581: }
7582: } elsif ($coowners) {
7583: $changes{'coowners'} = 1;
7584: }
1.1 raeburn 7585: if (keys(%changes) > 0) {
7586: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7587: if ($changes{'run'}) {
1.1 raeburn 7588: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7589: }
7590: if ($changes{'sender'}) {
1.17 raeburn 7591: if ($sender_uname eq '' || $sender_domain eq '') {
7592: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7593: } else {
7594: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7595: }
1.1 raeburn 7596: }
1.129 raeburn 7597: if ($changes{'coowners'}) {
7598: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7599: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7600: if (ref($lastactref) eq 'HASH') {
7601: $lastactref->{'domainconfig'} = 1;
7602: }
1.129 raeburn 7603: }
1.1 raeburn 7604: $resulttext .= '</ul>';
7605: } else {
7606: $resulttext = &mt('No changes made to auto-enrollment settings');
7607: }
7608: } else {
1.11 albertel 7609: $resulttext = '<span class="LC_error">'.
7610: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7611: }
1.3 raeburn 7612: return $resulttext;
1.1 raeburn 7613: }
7614:
7615: sub modify_autoupdate {
1.3 raeburn 7616: my ($dom,%domconfig) = @_;
1.1 raeburn 7617: my ($resulttext,%currautoupdate,%fields,%changes);
7618: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7619: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7620: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7621: }
7622: }
7623: my @offon = ('off','on');
7624: my %title = &Apache::lonlocal::texthash (
7625: run => 'Auto-update:',
7626: classlists => 'Updates to user information in classlists?'
7627: );
1.44 raeburn 7628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7629: my %fieldtitles = &Apache::lonlocal::texthash (
7630: id => 'Student/Employee ID',
1.20 raeburn 7631: permanentemail => 'E-mail address',
1.1 raeburn 7632: lastname => 'Last Name',
7633: firstname => 'First Name',
7634: middlename => 'Middle Name',
1.132 raeburn 7635: generation => 'Generation',
1.1 raeburn 7636: );
1.142 raeburn 7637: $othertitle = &mt('All users');
1.1 raeburn 7638: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7639: $othertitle = &mt('Other users');
1.1 raeburn 7640: }
7641: foreach my $key (keys(%env)) {
7642: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7643: my ($usertype,$item) = ($1,$2);
7644: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7645: if ($usertype eq 'default') {
7646: push(@{$fields{$1}},$2);
7647: } elsif (ref($types) eq 'ARRAY') {
7648: if (grep(/^\Q$usertype\E$/,@{$types})) {
7649: push(@{$fields{$1}},$2);
7650: }
7651: }
7652: }
1.1 raeburn 7653: }
7654: }
1.131 raeburn 7655: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7656: @lockablenames = sort(@lockablenames);
7657: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7658: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7659: if (@changed) {
7660: $changes{'lockablenames'} = 1;
7661: }
7662: } else {
7663: if (@lockablenames) {
7664: $changes{'lockablenames'} = 1;
7665: }
7666: }
1.1 raeburn 7667: my %updatehash = (
7668: autoupdate => { run => $env{'form.autoupdate_run'},
7669: classlists => $env{'form.classlists'},
7670: fields => {%fields},
1.131 raeburn 7671: lockablenames => \@lockablenames,
1.1 raeburn 7672: }
7673: );
7674: foreach my $key (keys(%currautoupdate)) {
7675: if (($key eq 'run') || ($key eq 'classlists')) {
7676: if (exists($updatehash{autoupdate}{$key})) {
7677: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7678: $changes{$key} = 1;
7679: }
7680: }
7681: } elsif ($key eq 'fields') {
7682: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7683: foreach my $item (@{$types},'default') {
1.1 raeburn 7684: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7685: my $change = 0;
7686: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7687: if (!exists($fields{$item})) {
7688: $change = 1;
1.132 raeburn 7689: last;
1.1 raeburn 7690: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7691: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7692: $change = 1;
1.132 raeburn 7693: last;
1.1 raeburn 7694: }
7695: }
7696: }
7697: if ($change) {
7698: push(@{$changes{$key}},$item);
7699: }
1.26 raeburn 7700: }
1.1 raeburn 7701: }
7702: }
1.131 raeburn 7703: } elsif ($key eq 'lockablenames') {
7704: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7705: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7706: if (@changed) {
7707: $changes{'lockablenames'} = 1;
7708: }
7709: } else {
7710: if (@lockablenames) {
7711: $changes{'lockablenames'} = 1;
7712: }
7713: }
7714: }
7715: }
7716: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7717: if (@lockablenames) {
7718: $changes{'lockablenames'} = 1;
1.1 raeburn 7719: }
7720: }
1.26 raeburn 7721: foreach my $item (@{$types},'default') {
7722: if (defined($fields{$item})) {
7723: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7724: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7725: my $change = 0;
7726: if (ref($fields{$item}) eq 'ARRAY') {
7727: foreach my $type (@{$fields{$item}}) {
7728: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7729: $change = 1;
7730: last;
7731: }
7732: }
7733: }
7734: if ($change) {
7735: push(@{$changes{'fields'}},$item);
7736: }
7737: } else {
1.26 raeburn 7738: push(@{$changes{'fields'}},$item);
7739: }
7740: } else {
7741: push(@{$changes{'fields'}},$item);
1.1 raeburn 7742: }
7743: }
7744: }
7745: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7746: $dom);
7747: if ($putresult eq 'ok') {
7748: if (keys(%changes) > 0) {
7749: $resulttext = &mt('Changes made:').'<ul>';
7750: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7751: if ($key eq 'lockablenames') {
7752: $resulttext .= '<li>';
7753: if (@lockablenames) {
7754: $usertypes->{'default'} = $othertitle;
7755: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7756: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7757: } else {
7758: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7759: }
7760: $resulttext .= '</li>';
7761: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7762: foreach my $item (@{$changes{$key}}) {
7763: my @newvalues;
7764: foreach my $type (@{$fields{$item}}) {
7765: push(@newvalues,$fieldtitles{$type});
7766: }
1.3 raeburn 7767: my $newvaluestr;
7768: if (@newvalues > 0) {
7769: $newvaluestr = join(', ',@newvalues);
7770: } else {
7771: $newvaluestr = &mt('none');
1.6 raeburn 7772: }
1.1 raeburn 7773: if ($item eq 'default') {
1.26 raeburn 7774: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7775: } else {
1.26 raeburn 7776: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7777: }
7778: }
7779: } else {
7780: my $newvalue;
7781: if ($key eq 'run') {
7782: $newvalue = $offon[$env{'form.autoupdate_run'}];
7783: } else {
7784: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7785: }
1.1 raeburn 7786: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7787: }
7788: }
7789: $resulttext .= '</ul>';
7790: } else {
1.3 raeburn 7791: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7792: }
7793: } else {
1.11 albertel 7794: $resulttext = '<span class="LC_error">'.
7795: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7796: }
1.3 raeburn 7797: return $resulttext;
1.1 raeburn 7798: }
7799:
1.125 raeburn 7800: sub modify_autocreate {
7801: my ($dom,%domconfig) = @_;
7802: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7803: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7804: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7805: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7806: }
7807: }
7808: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7809: req => 'Auto-creation of validated requests for official courses',
7810: xmldc => 'Identity of course creator of courses from XML files',
7811: );
7812: my @types = ('xml','req');
7813: foreach my $item (@types) {
7814: $newvals{$item} = $env{'form.autocreate_'.$item};
7815: $newvals{$item} =~ s/\D//g;
7816: $newvals{$item} = 0 if ($newvals{$item} eq '');
7817: }
7818: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7819: my %domcoords = &get_active_dcs($dom);
7820: unless (exists($domcoords{$newvals{'xmldc'}})) {
7821: $newvals{'xmldc'} = '';
7822: }
7823: %autocreatehash = (
7824: autocreate => { xml => $newvals{'xml'},
7825: req => $newvals{'req'},
7826: }
7827: );
7828: if ($newvals{'xmldc'} ne '') {
7829: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7830: }
7831: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7832: $dom);
7833: if ($putresult eq 'ok') {
7834: my @items = @types;
7835: if ($newvals{'xml'}) {
7836: push(@items,'xmldc');
7837: }
7838: foreach my $item (@items) {
7839: if (exists($currautocreate{$item})) {
7840: if ($currautocreate{$item} ne $newvals{$item}) {
7841: $changes{$item} = 1;
7842: }
7843: } elsif ($newvals{$item}) {
7844: $changes{$item} = 1;
7845: }
7846: }
7847: if (keys(%changes) > 0) {
7848: my @offon = ('off','on');
7849: $resulttext = &mt('Changes made:').'<ul>';
7850: foreach my $item (@types) {
7851: if ($changes{$item}) {
7852: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7853: $resulttext .= '<li>'.
7854: &mt("$title{$item} set to [_1]$newtxt [_2]",
7855: '<b>','</b>').
7856: '</li>';
1.125 raeburn 7857: }
7858: }
7859: if ($changes{'xmldc'}) {
7860: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7861: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7862: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7863: }
7864: $resulttext .= '</ul>';
7865: } else {
7866: $resulttext = &mt('No changes made to auto-creation settings');
7867: }
7868: } else {
7869: $resulttext = '<span class="LC_error">'.
7870: &mt('An error occurred: [_1]',$putresult).'</span>';
7871: }
7872: return $resulttext;
7873: }
7874:
1.23 raeburn 7875: sub modify_directorysrch {
7876: my ($dom,%domconfig) = @_;
7877: my ($resulttext,%changes);
7878: my %currdirsrch;
7879: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7880: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7881: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7882: }
7883: }
7884: my %title = ( available => 'Directory search available',
1.24 raeburn 7885: localonly => 'Other domains can search',
1.23 raeburn 7886: searchby => 'Search types',
7887: searchtypes => 'Search latitude');
7888: my @offon = ('off','on');
1.24 raeburn 7889: my @otherdoms = ('Yes','No');
1.23 raeburn 7890:
1.25 raeburn 7891: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7892: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7893: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7894:
1.44 raeburn 7895: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7896: if (keys(%{$usertypes}) == 0) {
7897: @cansearch = ('default');
7898: } else {
7899: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7900: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7901: if (!grep(/^\Q$type\E$/,@cansearch)) {
7902: push(@{$changes{'cansearch'}},$type);
7903: }
1.23 raeburn 7904: }
1.26 raeburn 7905: foreach my $type (@cansearch) {
7906: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7907: push(@{$changes{'cansearch'}},$type);
7908: }
1.23 raeburn 7909: }
1.26 raeburn 7910: } else {
7911: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7912: }
7913: }
7914:
7915: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7916: foreach my $by (@{$currdirsrch{'searchby'}}) {
7917: if (!grep(/^\Q$by\E$/,@searchby)) {
7918: push(@{$changes{'searchby'}},$by);
7919: }
7920: }
7921: foreach my $by (@searchby) {
7922: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7923: push(@{$changes{'searchby'}},$by);
7924: }
7925: }
7926: } else {
7927: push(@{$changes{'searchby'}},@searchby);
7928: }
1.25 raeburn 7929:
7930: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7931: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7932: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7933: push(@{$changes{'searchtypes'}},$type);
7934: }
7935: }
7936: foreach my $type (@searchtypes) {
7937: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7938: push(@{$changes{'searchtypes'}},$type);
7939: }
7940: }
7941: } else {
7942: if (exists($currdirsrch{'searchtypes'})) {
7943: foreach my $type (@searchtypes) {
7944: if ($type ne $currdirsrch{'searchtypes'}) {
7945: push(@{$changes{'searchtypes'}},$type);
7946: }
7947: }
7948: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7949: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7950: }
7951: } else {
7952: push(@{$changes{'searchtypes'}},@searchtypes);
7953: }
7954: }
7955:
1.23 raeburn 7956: my %dirsrch_hash = (
7957: directorysrch => { available => $env{'form.dirsrch_available'},
7958: cansearch => \@cansearch,
1.24 raeburn 7959: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7960: searchby => \@searchby,
1.25 raeburn 7961: searchtypes => \@searchtypes,
1.23 raeburn 7962: }
7963: );
7964: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7965: $dom);
7966: if ($putresult eq 'ok') {
7967: if (exists($currdirsrch{'available'})) {
7968: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7969: $changes{'available'} = 1;
7970: }
7971: } else {
7972: if ($env{'form.dirsrch_available'} eq '1') {
7973: $changes{'available'} = 1;
7974: }
7975: }
1.24 raeburn 7976: if (exists($currdirsrch{'localonly'})) {
7977: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7978: $changes{'localonly'} = 1;
7979: }
7980: } else {
7981: if ($env{'form.dirsrch_localonly'} eq '1') {
7982: $changes{'localonly'} = 1;
7983: }
7984: }
1.23 raeburn 7985: if (keys(%changes) > 0) {
7986: $resulttext = &mt('Changes made:').'<ul>';
7987: if ($changes{'available'}) {
7988: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7989: }
1.24 raeburn 7990: if ($changes{'localonly'}) {
7991: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7992: }
7993:
1.23 raeburn 7994: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7995: my $chgtext;
1.26 raeburn 7996: if (ref($usertypes) eq 'HASH') {
7997: if (keys(%{$usertypes}) > 0) {
7998: foreach my $type (@{$types}) {
7999: if (grep(/^\Q$type\E$/,@cansearch)) {
8000: $chgtext .= $usertypes->{$type}.'; ';
8001: }
8002: }
8003: if (grep(/^default$/,@cansearch)) {
8004: $chgtext .= $othertitle;
8005: } else {
8006: $chgtext =~ s/\; $//;
8007: }
1.210 raeburn 8008: $resulttext .=
1.178 raeburn 8009: '<li>'.
8010: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8011: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8012: '</li>';
1.23 raeburn 8013: }
8014: }
8015: }
8016: if (ref($changes{'searchby'}) eq 'ARRAY') {
8017: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8018: my $chgtext;
8019: foreach my $type (@{$titleorder}) {
8020: if (grep(/^\Q$type\E$/,@searchby)) {
8021: if (defined($searchtitles->{$type})) {
8022: $chgtext .= $searchtitles->{$type}.'; ';
8023: }
8024: }
8025: }
8026: $chgtext =~ s/\; $//;
8027: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8028: }
1.25 raeburn 8029: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8030: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8031: my $chgtext;
8032: foreach my $type (@{$srchtypeorder}) {
8033: if (grep(/^\Q$type\E$/,@searchtypes)) {
8034: if (defined($srchtypes_desc->{$type})) {
8035: $chgtext .= $srchtypes_desc->{$type}.'; ';
8036: }
8037: }
8038: }
8039: $chgtext =~ s/\; $//;
1.178 raeburn 8040: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8041: }
8042: $resulttext .= '</ul>';
8043: } else {
8044: $resulttext = &mt('No changes made to institution directory search settings');
8045: }
8046: } else {
8047: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8048: &mt('An error occurred: [_1]',$putresult).'</span>';
8049: }
8050: return $resulttext;
8051: }
8052:
1.28 raeburn 8053: sub modify_contacts {
1.205 raeburn 8054: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8055: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8056: if (ref($domconfig{'contacts'}) eq 'HASH') {
8057: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8058: $currsetting{$key} = $domconfig{'contacts'}{$key};
8059: }
8060: }
1.134 raeburn 8061: my (%others,%to,%bcc);
1.28 raeburn 8062: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8063: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 8064: 'requestsmail','updatesmail','idconflictsmail');
8065: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8066: foreach my $type (@mailings) {
8067: @{$newsetting{$type}} =
8068: &Apache::loncommon::get_env_multiple('form.'.$type);
8069: foreach my $item (@contacts) {
8070: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8071: $contacts_hash{contacts}{$type}{$item} = 1;
8072: } else {
8073: $contacts_hash{contacts}{$type}{$item} = 0;
8074: }
8075: }
8076: $others{$type} = $env{'form.'.$type.'_others'};
8077: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8078: if ($type eq 'helpdeskmail') {
8079: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8080: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8081: }
1.28 raeburn 8082: }
8083: foreach my $item (@contacts) {
8084: $to{$item} = $env{'form.'.$item};
8085: $contacts_hash{'contacts'}{$item} = $to{$item};
8086: }
1.203 raeburn 8087: foreach my $item (@toggles) {
8088: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8089: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8090: }
8091: }
1.28 raeburn 8092: if (keys(%currsetting) > 0) {
8093: foreach my $item (@contacts) {
8094: if ($to{$item} ne $currsetting{$item}) {
8095: $changes{$item} = 1;
8096: }
8097: }
8098: foreach my $type (@mailings) {
8099: foreach my $item (@contacts) {
8100: if (ref($currsetting{$type}) eq 'HASH') {
8101: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8102: push(@{$changes{$type}},$item);
8103: }
8104: } else {
8105: push(@{$changes{$type}},@{$newsetting{$type}});
8106: }
8107: }
8108: if ($others{$type} ne $currsetting{$type}{'others'}) {
8109: push(@{$changes{$type}},'others');
8110: }
1.134 raeburn 8111: if ($type eq 'helpdeskmail') {
8112: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8113: push(@{$changes{$type}},'bcc');
8114: }
8115: }
1.28 raeburn 8116: }
8117: } else {
8118: my %default;
8119: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8120: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8121: $default{'errormail'} = 'adminemail';
8122: $default{'packagesmail'} = 'adminemail';
8123: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8124: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8125: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8126: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8127: foreach my $item (@contacts) {
8128: if ($to{$item} ne $default{$item}) {
8129: $changes{$item} = 1;
1.203 raeburn 8130: }
1.28 raeburn 8131: }
8132: foreach my $type (@mailings) {
8133: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8134:
8135: push(@{$changes{$type}},@{$newsetting{$type}});
8136: }
8137: if ($others{$type} ne '') {
8138: push(@{$changes{$type}},'others');
1.134 raeburn 8139: }
8140: if ($type eq 'helpdeskmail') {
8141: if ($bcc{$type} ne '') {
8142: push(@{$changes{$type}},'bcc');
8143: }
8144: }
1.28 raeburn 8145: }
8146: }
1.203 raeburn 8147: foreach my $item (@toggles) {
8148: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8149: $changes{$item} = 1;
8150: } elsif ((!$env{'form.'.$item}) &&
8151: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8152: $changes{$item} = 1;
8153: }
8154: }
1.28 raeburn 8155: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8156: $dom);
8157: if ($putresult eq 'ok') {
8158: if (keys(%changes) > 0) {
1.205 raeburn 8159: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8160: if (ref($lastactref) eq 'HASH') {
8161: $lastactref->{'domainconfig'} = 1;
8162: }
1.28 raeburn 8163: my ($titles,$short_titles) = &contact_titles();
8164: $resulttext = &mt('Changes made:').'<ul>';
8165: foreach my $item (@contacts) {
8166: if ($changes{$item}) {
8167: $resulttext .= '<li>'.$titles->{$item}.
8168: &mt(' set to: ').
8169: '<span class="LC_cusr_emph">'.
8170: $to{$item}.'</span></li>';
8171: }
8172: }
8173: foreach my $type (@mailings) {
8174: if (ref($changes{$type}) eq 'ARRAY') {
8175: $resulttext .= '<li>'.$titles->{$type}.': ';
8176: my @text;
8177: foreach my $item (@{$newsetting{$type}}) {
8178: push(@text,$short_titles->{$item});
8179: }
8180: if ($others{$type} ne '') {
8181: push(@text,$others{$type});
8182: }
8183: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8184: join(', ',@text).'</span>';
8185: if ($type eq 'helpdeskmail') {
8186: if ($bcc{$type} ne '') {
8187: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8188: }
8189: }
8190: $resulttext .= '</li>';
1.28 raeburn 8191: }
8192: }
1.203 raeburn 8193: my @offon = ('off','on');
8194: if ($changes{'reporterrors'}) {
8195: $resulttext .= '<li>'.
8196: &mt('E-mail error reports to [_1] set to "'.
8197: $offon[$env{'form.reporterrors'}].'".',
8198: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8199: &mt('LON-CAPA core group - MSU'),600,500)).
8200: '</li>';
8201: }
8202: if ($changes{'reportupdates'}) {
8203: $resulttext .= '<li>'.
8204: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8205: $offon[$env{'form.reportupdates'}].'".',
8206: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8207: &mt('LON-CAPA core group - MSU'),600,500)).
8208: '</li>';
8209: }
1.28 raeburn 8210: $resulttext .= '</ul>';
8211: } else {
1.34 raeburn 8212: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8213: }
8214: } else {
8215: $resulttext = '<span class="LC_error">'.
8216: &mt('An error occurred: [_1].',$putresult).'</span>';
8217: }
8218: return $resulttext;
8219: }
8220:
8221: sub modify_usercreation {
1.27 raeburn 8222: my ($dom,%domconfig) = @_;
1.224 raeburn 8223: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8224: my $warningmsg;
1.27 raeburn 8225: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8226: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8227: if ($key eq 'cancreate') {
8228: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8229: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8230: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8231: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8232: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8233: } else {
8234: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8235: }
8236: }
8237: }
8238: } elsif ($key eq 'email_rule') {
8239: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8240: } else {
8241: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8242: }
1.27 raeburn 8243: }
8244: }
8245: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8246: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8247: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8248: foreach my $item(@contexts) {
1.224 raeburn 8249: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8250: }
1.34 raeburn 8251: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8252: foreach my $item (@contexts) {
1.224 raeburn 8253: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8254: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8255: }
1.27 raeburn 8256: }
1.34 raeburn 8257: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8258: foreach my $item (@contexts) {
1.43 raeburn 8259: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8260: if ($cancreate{$item} ne 'any') {
8261: push(@{$changes{'cancreate'}},$item);
8262: }
8263: } else {
8264: if ($cancreate{$item} ne 'none') {
8265: push(@{$changes{'cancreate'}},$item);
8266: }
1.27 raeburn 8267: }
8268: }
8269: } else {
1.43 raeburn 8270: foreach my $item (@contexts) {
1.34 raeburn 8271: push(@{$changes{'cancreate'}},$item);
8272: }
1.27 raeburn 8273: }
1.34 raeburn 8274:
1.27 raeburn 8275: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8276: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8277: if (!grep(/^\Q$type\E$/,@username_rule)) {
8278: push(@{$changes{'username_rule'}},$type);
8279: }
8280: }
8281: foreach my $type (@username_rule) {
8282: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8283: push(@{$changes{'username_rule'}},$type);
8284: }
8285: }
8286: } else {
8287: push(@{$changes{'username_rule'}},@username_rule);
8288: }
8289:
1.32 raeburn 8290: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8291: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8292: if (!grep(/^\Q$type\E$/,@id_rule)) {
8293: push(@{$changes{'id_rule'}},$type);
8294: }
8295: }
8296: foreach my $type (@id_rule) {
8297: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8298: push(@{$changes{'id_rule'}},$type);
8299: }
8300: }
8301: } else {
8302: push(@{$changes{'id_rule'}},@id_rule);
8303: }
8304:
1.43 raeburn 8305: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8306: my @authtypes = ('int','krb4','krb5','loc');
8307: my %authhash;
1.43 raeburn 8308: foreach my $item (@authen_contexts) {
1.28 raeburn 8309: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8310: foreach my $auth (@authtypes) {
8311: if (grep(/^\Q$auth\E$/,@authallowed)) {
8312: $authhash{$item}{$auth} = 1;
8313: } else {
8314: $authhash{$item}{$auth} = 0;
8315: }
8316: }
8317: }
8318: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8319: foreach my $item (@authen_contexts) {
1.28 raeburn 8320: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8321: foreach my $auth (@authtypes) {
8322: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8323: push(@{$changes{'authtypes'}},$item);
8324: last;
8325: }
8326: }
8327: }
8328: }
8329: } else {
1.43 raeburn 8330: foreach my $item (@authen_contexts) {
1.28 raeburn 8331: push(@{$changes{'authtypes'}},$item);
8332: }
8333: }
8334:
1.224 raeburn 8335: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8336: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8337: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8338: $save_usercreate{'id_rule'} = \@id_rule;
8339: $save_usercreate{'username_rule'} = \@username_rule,
8340: $save_usercreate{'authtypes'} = \%authhash;
8341:
1.27 raeburn 8342: my %usercreation_hash = (
1.224 raeburn 8343: usercreation => \%save_usercreate,
8344: );
1.27 raeburn 8345:
8346: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8347: $dom);
1.50 raeburn 8348:
1.224 raeburn 8349: if ($putresult eq 'ok') {
8350: if (keys(%changes) > 0) {
8351: $resulttext = &mt('Changes made:').'<ul>';
8352: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8353: my %lt = &usercreation_types();
8354: foreach my $type (@{$changes{'cancreate'}}) {
8355: my $chgtext = $lt{$type}.', ';
8356: if ($cancreate{$type} eq 'none') {
8357: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8358: } elsif ($cancreate{$type} eq 'any') {
8359: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8360: } elsif ($cancreate{$type} eq 'official') {
8361: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8362: } elsif ($cancreate{$type} eq 'unofficial') {
8363: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8364: }
8365: $resulttext .= '<li>'.$chgtext.'</li>';
8366: }
8367: }
8368: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8369: my ($rules,$ruleorder) =
8370: &Apache::lonnet::inst_userrules($dom,'username');
8371: my $chgtext = '<ul>';
8372: foreach my $type (@username_rule) {
8373: if (ref($rules->{$type}) eq 'HASH') {
8374: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8375: }
8376: }
8377: $chgtext .= '</ul>';
8378: if (@username_rule > 0) {
8379: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8380: } else {
8381: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8382: }
8383: }
8384: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8385: my ($idrules,$idruleorder) =
8386: &Apache::lonnet::inst_userrules($dom,'id');
8387: my $chgtext = '<ul>';
8388: foreach my $type (@id_rule) {
8389: if (ref($idrules->{$type}) eq 'HASH') {
8390: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8391: }
8392: }
8393: $chgtext .= '</ul>';
8394: if (@id_rule > 0) {
8395: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8396: } else {
8397: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8398: }
8399: }
8400: my %authname = &authtype_names();
8401: my %context_title = &context_names();
8402: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8403: my $chgtext = '<ul>';
8404: foreach my $type (@{$changes{'authtypes'}}) {
8405: my @allowed;
8406: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8407: foreach my $auth (@authtypes) {
8408: if ($authhash{$type}{$auth}) {
8409: push(@allowed,$authname{$auth});
8410: }
8411: }
8412: if (@allowed > 0) {
8413: $chgtext .= join(', ',@allowed).'</li>';
8414: } else {
8415: $chgtext .= &mt('none').'</li>';
8416: }
8417: }
8418: $chgtext .= '</ul>';
8419: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8420: $resulttext .= '</li>';
8421: }
8422: $resulttext .= '</ul>';
8423: } else {
8424: $resulttext = &mt('No changes made to user creation settings');
8425: }
8426: } else {
8427: $resulttext = '<span class="LC_error">'.
8428: &mt('An error occurred: [_1]',$putresult).'</span>';
8429: }
8430: if ($warningmsg ne '') {
8431: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8432: }
8433: return $resulttext;
8434: }
8435:
8436: sub modify_selfcreation {
8437: my ($dom,%domconfig) = @_;
8438: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8439: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8440: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8441: if (ref($types) eq 'ARRAY') {
8442: $usertypes->{'default'} = $othertitle;
8443: push(@{$types},'default');
8444: }
1.224 raeburn 8445: #
8446: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8447: #
8448: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8449: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8450: if ($key eq 'cancreate') {
8451: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8452: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8453: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8454: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8455: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 8456: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 8457: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8458: } else {
8459: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8460: }
8461: }
8462: }
8463: } elsif ($key eq 'email_rule') {
8464: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8465: } else {
8466: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8467: }
8468: }
8469: }
8470: #
8471: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8472: #
8473: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8474: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8475: if ($key eq 'selfcreate') {
8476: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8477: } else {
8478: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8479: }
8480: }
8481: }
8482:
8483: my @contexts = ('selfcreate');
8484: @{$cancreate{'selfcreate'}} = ();
8485: %{$cancreate{'emailusername'}} = ();
8486: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8487: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 8488: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8489: my %selfcreatetypes = (
8490: sso => 'users authenticated by institutional single sign on',
8491: login => 'users authenticated by institutional log-in',
1.236 raeburn 8492: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8493: );
1.224 raeburn 8494: #
8495: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8496: # is permitted.
8497: #
1.236 raeburn 8498:
8499: my @statuses;
8500: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8501: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8502: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8503: }
8504: }
8505: push(@statuses,'default');
8506:
1.228 raeburn 8507: foreach my $item ('login','sso','email') {
1.224 raeburn 8508: if ($item eq 'email') {
1.236 raeburn 8509: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8510: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8511: push(@contexts,'selfcreateprocessing');
8512: foreach my $type (@statuses) {
8513: if ($type eq 'default') {
8514: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8515: } else {
8516: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8517: }
8518: }
1.224 raeburn 8519: }
8520: } else {
8521: if ($env{'form.cancreate_'.$item}) {
8522: push(@{$cancreate{'selfcreate'}},$item);
8523: }
8524: }
8525: }
8526: my (@email_rule,%userinfo,%savecaptcha);
8527: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8528: #
1.228 raeburn 8529: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8530: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8531: #
1.236 raeburn 8532:
8533: if ($env{'form.cancreate_email'} eq 'email') {
1.228 raeburn 8534: push(@contexts,'emailusername');
8535: if (ref($types) eq 'ARRAY') {
8536: foreach my $type (@{$types}) {
8537: if (ref($infofields) eq 'ARRAY') {
8538: foreach my $field (@{$infofields}) {
8539: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8540: $cancreate{'emailusername'}{$type}{$field} = $1;
8541: }
8542: }
1.224 raeburn 8543: }
8544: }
8545: }
8546: #
8547: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8548: # queued requests for self-creation of account using e-mail address as username
8549: #
8550:
8551: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8552: @approvalnotify = sort(@approvalnotify);
8553: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8554: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8555: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8556: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8557: push(@{$changes{'cancreate'}},'notify');
8558: }
8559: } else {
8560: if ($cancreate{'notify'}{'approval'}) {
8561: push(@{$changes{'cancreate'}},'notify');
8562: }
8563: }
8564: } elsif ($cancreate{'notify'}{'approval'}) {
8565: push(@{$changes{'cancreate'}},'notify');
8566: }
8567:
8568: #
8569: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8570: #
8571: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8572: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8573: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8574: if (@{$curr_usercreation{'email_rule'}} > 0) {
8575: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8576: if (!grep(/^\Q$type\E$/,@email_rule)) {
8577: push(@{$changes{'email_rule'}},$type);
8578: }
8579: }
8580: }
8581: if (@email_rule > 0) {
8582: foreach my $type (@email_rule) {
8583: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8584: push(@{$changes{'email_rule'}},$type);
8585: }
8586: }
8587: }
8588: } elsif (@email_rule > 0) {
8589: push(@{$changes{'email_rule'}},@email_rule);
8590: }
8591: }
8592: #
1.236 raeburn 8593: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8594: # institutional log-in.
8595: #
8596: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8597: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8598: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8599: ($domdefaults{'auth_def'} eq 'localauth'))) {
8600: $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.').' '.
8601: &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.');
8602: }
8603: }
8604: my @fields = ('lastname','firstname','middlename','generation',
8605: 'permanentemail','id');
1.240 raeburn 8606: my @shibfields = (@fields,'inststatus');
1.224 raeburn 8607: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8608: #
8609: # Where usernames may created for institutional log-in and/or institutional single sign on:
8610: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8611: # may self-create accounts
8612: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8613: # which the user may supply, if institutional data is unavailable.
8614: #
8615: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8616: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8617: if (@{$types} > 1) {
1.224 raeburn 8618: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8619: push(@contexts,'statustocreate');
8620: } else {
8621: undef($cancreate{'statustocreate'});
8622: }
8623: foreach my $type (@{$types}) {
8624: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8625: foreach my $field (@fields) {
8626: if (grep(/^\Q$field\E$/,@modifiable)) {
8627: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8628: } else {
8629: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8630: }
8631: }
8632: }
8633: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8634: foreach my $type (@{$types}) {
8635: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8636: foreach my $field (@fields) {
8637: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8638: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8639: push(@{$changes{'selfcreate'}},$type);
8640: last;
8641: }
8642: }
8643: }
8644: }
8645: } else {
8646: foreach my $type (@{$types}) {
8647: push(@{$changes{'selfcreate'}},$type);
8648: }
8649: }
8650: }
1.240 raeburn 8651: foreach my $field (@shibfields) {
8652: if ($env{'form.shibenv_'.$field} ne '') {
8653: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8654: }
8655: }
8656: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8657: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8658: foreach my $field (@shibfields) {
8659: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8660: push(@{$changes{'cancreate'}},'shibenv');
8661: }
8662: }
8663: } else {
8664: foreach my $field (@shibfields) {
8665: if ($env{'form.shibenv_'.$field}) {
8666: push(@{$changes{'cancreate'}},'shibenv');
8667: last;
8668: }
8669: }
8670: }
8671: }
1.224 raeburn 8672: }
8673: foreach my $item (@contexts) {
8674: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8675: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8676: if (ref($cancreate{$item}) eq 'ARRAY') {
8677: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8678: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8679: push(@{$changes{'cancreate'}},$item);
8680: }
8681: }
8682: }
8683: }
8684: if (ref($cancreate{$item}) eq 'ARRAY') {
8685: foreach my $type (@{$cancreate{$item}}) {
8686: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8687: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8688: push(@{$changes{'cancreate'}},$item);
8689: }
8690: }
8691: }
8692: }
8693: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8694: if (ref($cancreate{$item}) eq 'HASH') {
8695: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8696: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8697: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8698: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8699: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8700: push(@{$changes{'cancreate'}},$item);
8701: }
8702: }
8703: }
1.236 raeburn 8704: } elsif ($item eq 'selfcreateprocessing') {
8705: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8706: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8707: push(@{$changes{'cancreate'}},$item);
8708: }
8709: }
1.228 raeburn 8710: } else {
8711: if (!$cancreate{$item}{$curr}) {
8712: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8713: push(@{$changes{'cancreate'}},$item);
8714: }
1.224 raeburn 8715: }
8716: }
8717: }
8718: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8719: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8720: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8721: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8722: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8724: push(@{$changes{'cancreate'}},$item);
8725: }
8726: }
8727: } else {
8728: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8729: push(@{$changes{'cancreate'}},$item);
8730: }
8731: }
8732: }
1.236 raeburn 8733: } elsif ($item eq 'selfcreateprocessing') {
8734: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8735: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8736: push(@{$changes{'cancreate'}},$item);
8737: }
8738: }
1.228 raeburn 8739: } else {
8740: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8741: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8742: push(@{$changes{'cancreate'}},$item);
8743: }
1.224 raeburn 8744: }
8745: }
8746: }
8747: }
8748: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8749: if (ref($cancreate{$item}) eq 'ARRAY') {
8750: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8751: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8752: push(@{$changes{'cancreate'}},$item);
8753: }
8754: }
8755: } elsif (ref($cancreate{$item}) eq 'HASH') {
8756: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8757: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8758: push(@{$changes{'cancreate'}},$item);
8759: }
8760: }
8761: }
8762: } elsif ($item eq 'emailusername') {
1.228 raeburn 8763: if (ref($cancreate{$item}) eq 'HASH') {
8764: foreach my $type (keys(%{$cancreate{$item}})) {
8765: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8766: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8767: if ($cancreate{$item}{$type}{$field}) {
8768: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8769: push(@{$changes{'cancreate'}},$item);
8770: }
8771: last;
8772: }
8773: }
8774: }
8775: }
1.224 raeburn 8776: }
8777: }
8778: }
8779: #
8780: # Populate %save_usercreate hash with updates to self-creation configuration.
8781: #
8782: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8783: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8784: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8785: if (ref($cancreate{'notify'}) eq 'HASH') {
8786: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8787: }
1.236 raeburn 8788: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8789: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8790: }
1.224 raeburn 8791: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8792: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8793: }
1.240 raeburn 8794: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8795: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8796: }
1.224 raeburn 8797: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8798: $save_usercreate{'emailrule'} = \@email_rule;
8799:
8800: my %userconfig_hash = (
8801: usercreation => \%save_usercreate,
8802: usermodification => \%save_usermodify,
8803: );
8804: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8805: $dom);
8806: #
8807: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8808: #
1.27 raeburn 8809: if ($putresult eq 'ok') {
8810: if (keys(%changes) > 0) {
8811: $resulttext = &mt('Changes made:').'<ul>';
8812: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8813: my %lt = &selfcreation_types();
1.34 raeburn 8814: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8815: my $chgtext;
1.45 raeburn 8816: if ($type eq 'selfcreate') {
1.50 raeburn 8817: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8818: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8819: } else {
1.224 raeburn 8820: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8821: '<ul>';
1.50 raeburn 8822: foreach my $case (@{$cancreate{$type}}) {
8823: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8824: }
8825: $chgtext .= '</ul>';
1.100 raeburn 8826: if (ref($cancreate{$type}) eq 'ARRAY') {
8827: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8828: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8829: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8830: $chgtext .= '<br />'.
8831: '<span class="LC_warning">'.
8832: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8833: '</span>';
1.100 raeburn 8834: }
8835: }
8836: }
8837: }
1.43 raeburn 8838: }
1.240 raeburn 8839: } elsif ($type eq 'shibenv') {
8840: if (keys(%{$cancreate{$type}}) == 0) {
8841: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8842: } else {
8843: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8844: '<ul>';
8845: foreach my $field (@shibfields) {
8846: next if ($cancreate{$type}{$field} eq '');
8847: if ($field eq 'inststatus') {
8848: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8849: } else {
8850: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8851: }
8852: }
8853: $chgtext .= '</ul>';
8854: }
1.93 raeburn 8855: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8856: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8857: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8858: if (@{$cancreate{'selfcreate'}} > 0) {
8859: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8860: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8861: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8862: $chgtext .= '<br />'.
8863: '<span class="LC_warning">'.
8864: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8865: '</span>';
8866: }
1.96 raeburn 8867: } elsif (ref($usertypes) eq 'HASH') {
8868: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8869: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8870: } else {
8871: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8872: }
8873: $chgtext .= '<ul>';
8874: foreach my $case (@{$cancreate{$type}}) {
8875: if ($case eq 'default') {
8876: $chgtext .= '<li>'.$othertitle.'</li>';
8877: } else {
8878: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8879: }
8880: }
1.100 raeburn 8881: $chgtext .= '</ul>';
8882: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8883: $chgtext .= '<br /><span class="LC_warning">'.
8884: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8885: '</span>';
1.100 raeburn 8886: }
8887: }
8888: } else {
8889: if (@{$cancreate{$type}} == 0) {
8890: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8891: } else {
8892: $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 8893: }
8894: }
8895: }
1.236 raeburn 8896: } elsif ($type eq 'selfcreateprocessing') {
8897: my %choices = &Apache::lonlocal::texthash (
8898: automatic => 'Automatic approval',
8899: approval => 'Queued for approval',
8900: );
8901: if (@statuses > 1) {
8902: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8903: '<ul>';
8904: foreach my $type (@statuses) {
8905: if ($type eq 'default') {
8906: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8907: } else {
8908: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8909: }
8910: }
8911: $chgtext .= '</ul>';
8912: } else {
8913: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8914: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8915: }
1.165 raeburn 8916: } elsif ($type eq 'captcha') {
1.224 raeburn 8917: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8918: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8919: } else {
8920: my %captchas = &captcha_phrases();
1.224 raeburn 8921: if ($captchas{$savecaptcha{$type}}) {
8922: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8923: } else {
1.210 raeburn 8924: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8925: }
8926: }
8927: } elsif ($type eq 'recaptchakeys') {
8928: my ($privkey,$pubkey);
1.224 raeburn 8929: if (ref($savecaptcha{$type}) eq 'HASH') {
8930: $pubkey = $savecaptcha{$type}{'public'};
8931: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8932: }
8933: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8934: if (!$pubkey) {
8935: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8936: } else {
8937: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8938: }
8939: if (!$privkey) {
8940: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8941: } else {
8942: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8943: }
8944: $chgtext .= '</ul>';
1.224 raeburn 8945: } elsif ($type eq 'emailusername') {
8946: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8947: if (ref($types) eq 'ARRAY') {
8948: foreach my $type (@{$types}) {
8949: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8950: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8951: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8952: '<ul>';
8953: foreach my $field (@{$infofields}) {
8954: if ($cancreate{'emailusername'}{$type}{$field}) {
8955: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8956: }
8957: }
8958: }
8959: $chgtext .= '</ul>';
8960: } else {
8961: $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 8962: }
8963: }
8964: }
8965: }
8966: } elsif ($type eq 'notify') {
8967: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8968: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8969: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8970: if ($cancreate{'notify'}{'approval'}) {
8971: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8972: }
8973: }
1.43 raeburn 8974: }
1.34 raeburn 8975: }
1.224 raeburn 8976: if ($chgtext) {
8977: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8978: }
8979: }
8980: }
1.43 raeburn 8981: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8982: my ($emailrules,$emailruleorder) =
8983: &Apache::lonnet::inst_userrules($dom,'email');
8984: my $chgtext = '<ul>';
8985: foreach my $type (@email_rule) {
8986: if (ref($emailrules->{$type}) eq 'HASH') {
8987: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8988: }
8989: }
8990: $chgtext .= '</ul>';
8991: if (@email_rule > 0) {
1.224 raeburn 8992: $resulttext .= '<li>'.
8993: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8994: $chgtext.
8995: '</li>';
1.43 raeburn 8996: } else {
1.224 raeburn 8997: $resulttext .= '<li>'.
8998: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8999: '</li>';
1.43 raeburn 9000: }
9001: }
1.224 raeburn 9002: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9003: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9004: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9005: foreach my $type (@{$changes{'selfcreate'}}) {
9006: my $typename = $type;
9007: if (ref($usertypes) eq 'HASH') {
9008: if ($usertypes->{$type} ne '') {
9009: $typename = $usertypes->{$type};
9010: }
9011: }
9012: my @modifiable;
9013: $resulttext .= '<li>'.
9014: &mt('Self-creation of account by users with status: [_1]',
9015: '<span class="LC_cusr_emph">'.$typename.'</span>').
9016: ' - '.&mt('modifiable fields (if institutional data blank): ');
9017: foreach my $field (@fields) {
9018: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9019: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 9020: }
9021: }
1.224 raeburn 9022: if (@modifiable > 0) {
9023: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9024: } else {
1.224 raeburn 9025: $resulttext .= &mt('none');
1.43 raeburn 9026: }
1.224 raeburn 9027: $resulttext .= '</li>';
1.28 raeburn 9028: }
1.224 raeburn 9029: $resulttext .= '</ul></li>';
1.28 raeburn 9030: }
1.27 raeburn 9031: $resulttext .= '</ul>';
9032: } else {
1.224 raeburn 9033: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9034: }
9035: } else {
9036: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9037: &mt('An error occurred: [_1]',$putresult).'</span>';
9038: }
1.43 raeburn 9039: if ($warningmsg ne '') {
9040: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9041: }
1.23 raeburn 9042: return $resulttext;
9043: }
9044:
1.165 raeburn 9045: sub process_captcha {
9046: my ($container,$changes,$newsettings,$current) = @_;
9047: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9048: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9049: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9050: $newsettings->{'captcha'} = 'original';
9051: }
9052: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 9053: if ($container eq 'cancreate') {
1.169 raeburn 9054: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9055: push(@{$changes->{'cancreate'}},'captcha');
9056: } elsif (!defined($changes->{'cancreate'})) {
9057: $changes->{'cancreate'} = ['captcha'];
9058: }
9059: } else {
9060: $changes->{'captcha'} = 1;
1.165 raeburn 9061: }
9062: }
9063: my ($newpub,$newpriv,$currpub,$currpriv);
9064: if ($newsettings->{'captcha'} eq 'recaptcha') {
9065: $newpub = $env{'form.'.$container.'_recaptchapub'};
9066: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 9067: $newpub =~ s/\W//g;
9068: $newpriv =~ s/\W//g;
9069: $newsettings->{'recaptchakeys'} = {
9070: public => $newpub,
9071: private => $newpriv,
9072: };
1.165 raeburn 9073: }
9074: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9075: $currpub = $current->{'recaptchakeys'}{'public'};
9076: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 9077: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9078: $newsettings->{'recaptchakeys'} = {
9079: public => '',
9080: private => '',
9081: }
9082: }
1.165 raeburn 9083: }
9084: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 9085: if ($container eq 'cancreate') {
9086: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9087: push(@{$changes->{'cancreate'}},'recaptchakeys');
9088: } elsif (!defined($changes->{'cancreate'})) {
9089: $changes->{'cancreate'} = ['recaptchakeys'];
9090: }
9091: } else {
1.210 raeburn 9092: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 9093: }
9094: }
9095: return;
9096: }
9097:
1.33 raeburn 9098: sub modify_usermodification {
9099: my ($dom,%domconfig) = @_;
1.224 raeburn 9100: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9101: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9102: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 9103: if ($key eq 'selfcreate') {
9104: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9105: } else {
9106: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9107: }
1.33 raeburn 9108: }
9109: }
1.224 raeburn 9110: my @contexts = ('author','course');
1.33 raeburn 9111: my %context_title = (
9112: author => 'In author context',
9113: course => 'In course context',
9114: );
9115: my @fields = ('lastname','firstname','middlename','generation',
9116: 'permanentemail','id');
9117: my %roles = (
9118: author => ['ca','aa'],
9119: course => ['st','ep','ta','in','cr'],
9120: );
9121: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9122: foreach my $context (@contexts) {
9123: foreach my $role (@{$roles{$context}}) {
9124: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9125: foreach my $item (@fields) {
9126: if (grep(/^\Q$item\E$/,@modifiable)) {
9127: $modifyhash{$context}{$role}{$item} = 1;
9128: } else {
9129: $modifyhash{$context}{$role}{$item} = 0;
9130: }
9131: }
9132: }
9133: if (ref($curr_usermodification{$context}) eq 'HASH') {
9134: foreach my $role (@{$roles{$context}}) {
9135: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9136: foreach my $field (@fields) {
9137: if ($modifyhash{$context}{$role}{$field} ne
9138: $curr_usermodification{$context}{$role}{$field}) {
9139: push(@{$changes{$context}},$role);
9140: last;
9141: }
9142: }
9143: }
9144: }
9145: } else {
9146: foreach my $context (@contexts) {
9147: foreach my $role (@{$roles{$context}}) {
9148: push(@{$changes{$context}},$role);
9149: }
9150: }
9151: }
9152: }
9153: my %usermodification_hash = (
9154: usermodification => \%modifyhash,
9155: );
9156: my $putresult = &Apache::lonnet::put_dom('configuration',
9157: \%usermodification_hash,$dom);
9158: if ($putresult eq 'ok') {
9159: if (keys(%changes) > 0) {
9160: $resulttext = &mt('Changes made: ').'<ul>';
9161: foreach my $context (@contexts) {
9162: if (ref($changes{$context}) eq 'ARRAY') {
9163: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9164: if (ref($changes{$context}) eq 'ARRAY') {
9165: foreach my $role (@{$changes{$context}}) {
9166: my $rolename;
1.224 raeburn 9167: if ($role eq 'cr') {
9168: $rolename = &mt('Custom');
1.33 raeburn 9169: } else {
1.224 raeburn 9170: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9171: }
9172: my @modifiable;
1.224 raeburn 9173: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9174: foreach my $field (@fields) {
9175: if ($modifyhash{$context}{$role}{$field}) {
9176: push(@modifiable,$fieldtitles{$field});
9177: }
9178: }
9179: if (@modifiable > 0) {
9180: $resulttext .= join(', ',@modifiable);
9181: } else {
9182: $resulttext .= &mt('none');
9183: }
9184: $resulttext .= '</li>';
9185: }
9186: $resulttext .= '</ul></li>';
9187: }
9188: }
9189: }
9190: $resulttext .= '</ul>';
9191: } else {
9192: $resulttext = &mt('No changes made to user modification settings');
9193: }
9194: } else {
9195: $resulttext = '<span class="LC_error">'.
9196: &mt('An error occurred: [_1]',$putresult).'</span>';
9197: }
9198: return $resulttext;
9199: }
9200:
1.43 raeburn 9201: sub modify_defaults {
1.212 raeburn 9202: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9203: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9204: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9205: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9206: my @authtypes = ('internal','krb4','krb5','localauth');
9207: foreach my $item (@items) {
9208: $newvalues{$item} = $env{'form.'.$item};
9209: if ($item eq 'auth_def') {
9210: if ($newvalues{$item} ne '') {
9211: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9212: push(@errors,$item);
9213: }
9214: }
9215: } elsif ($item eq 'lang_def') {
9216: if ($newvalues{$item} ne '') {
9217: if ($newvalues{$item} =~ /^(\w+)/) {
9218: my $langcode = $1;
1.103 raeburn 9219: if ($langcode ne 'x_chef') {
9220: if (code2language($langcode) eq '') {
9221: push(@errors,$item);
9222: }
1.43 raeburn 9223: }
9224: } else {
9225: push(@errors,$item);
9226: }
9227: }
1.54 raeburn 9228: } elsif ($item eq 'timezone_def') {
9229: if ($newvalues{$item} ne '') {
1.62 raeburn 9230: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9231: push(@errors,$item);
9232: }
9233: }
1.68 raeburn 9234: } elsif ($item eq 'datelocale_def') {
9235: if ($newvalues{$item} ne '') {
9236: my @datelocale_ids = DateTime::Locale->ids();
9237: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9238: push(@errors,$item);
9239: }
9240: }
1.141 raeburn 9241: } elsif ($item eq 'portal_def') {
9242: if ($newvalues{$item} ne '') {
9243: 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])\/?$/) {
9244: push(@errors,$item);
9245: }
9246: }
1.43 raeburn 9247: }
9248: if (grep(/^\Q$item\E$/,@errors)) {
9249: $newvalues{$item} = $domdefaults{$item};
9250: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9251: $changes{$item} = 1;
9252: }
1.72 raeburn 9253: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9254: }
9255: my %defaults_hash = (
1.72 raeburn 9256: defaults => \%newvalues,
9257: );
1.43 raeburn 9258: my $title = &defaults_titles();
1.236 raeburn 9259:
9260: my $currinststatus;
9261: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9262: $currinststatus = $domconfig{'inststatus'};
9263: } else {
9264: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9265: $currinststatus = {
9266: inststatustypes => $usertypes,
9267: inststatusorder => $types,
9268: inststatusguest => [],
9269: };
9270: }
9271: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9272: my @allpos;
9273: my %guests;
9274: my %alltypes;
9275: my ($currtitles,$currguests,$currorder);
9276: if (ref($currinststatus) eq 'HASH') {
9277: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9278: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9279: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9280: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9281: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9282: }
9283: }
9284: unless (grep(/^\Q$type\E$/,@todelete)) {
9285: my $position = $env{'form.inststatus_pos_'.$type};
9286: $position =~ s/\D+//g;
9287: $allpos[$position] = $type;
9288: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9289: $alltypes{$type} =~ s/`//g;
9290: if ($env{'form.inststatus_guest_'.$type}) {
9291: $guests{$type} = 1;
9292: }
9293: }
9294: }
9295: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9296: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9297: }
9298: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9299: $currtitles =~ s/,$//;
9300: }
9301: }
9302: if ($env{'form.addinststatus'}) {
9303: my $newtype = $env{'form.addinststatus'};
9304: $newtype =~ s/\W//g;
9305: unless (exists($alltypes{$newtype})) {
9306: if ($env{'form.addinststatus_guest'}) {
9307: $guests{$newtype} = 1;
9308: }
9309: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9310: $alltypes{$newtype} =~ s/`//g;
9311: my $position = $env{'form.addinststatus_pos'};
9312: $position =~ s/\D+//g;
9313: if ($position ne '') {
9314: $allpos[$position] = $newtype;
9315: }
9316: }
9317: }
9318: my (@orderedstatus,@orderedguests);
9319: foreach my $type (@allpos) {
9320: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9321: push(@orderedstatus,$type);
9322: if ($guests{$type}) {
9323: push(@orderedguests,$type);
9324: }
9325: }
9326: }
9327: foreach my $type (keys(%alltypes)) {
9328: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9329: delete($alltypes{$type});
9330: }
9331: }
9332: $defaults_hash{'inststatus'} = {
9333: inststatustypes => \%alltypes,
9334: inststatusorder => \@orderedstatus,
9335: inststatusguest => \@orderedguests,
9336: };
9337: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9338: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9339: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9340: }
9341: }
9342: if ($currorder ne join(',',@orderedstatus)) {
9343: $changes{'inststatus'}{'inststatusorder'} = 1;
9344: }
9345: if ($currguests ne join(',',@orderedguests)) {
9346: $changes{'inststatus'}{'inststatusguest'} = 1;
9347: }
9348: my $newtitles;
9349: foreach my $item (@orderedstatus) {
9350: $newtitles .= $alltypes{$item}.',';
9351: }
9352: $newtitles =~ s/,$//;
9353: if ($currtitles ne $newtitles) {
9354: $changes{'inststatus'}{'inststatustypes'} = 1;
9355: }
1.43 raeburn 9356: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9357: $dom);
9358: if ($putresult eq 'ok') {
9359: if (keys(%changes) > 0) {
9360: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9361: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9362: 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";
9363: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9364: if ($item eq 'inststatus') {
9365: if (ref($changes{'inststatus'}) eq 'HASH') {
9366: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9367: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9368: foreach my $type (@orderedstatus) {
9369: $resulttext .= $alltypes{$type}.', ';
9370: }
9371: $resulttext =~ s/, $//;
9372: $resulttext .= '</li>';
9373: }
9374: if ($changes{'inststatus'}{'inststatusguest'}) {
9375: $resulttext .= '<li>';
9376: if (@orderedguests) {
9377: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9378: foreach my $type (@orderedguests) {
9379: $resulttext .= $alltypes{$type}.', ';
9380: }
9381: $resulttext =~ s/, $//;
9382: } else {
9383: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9384: }
9385: $resulttext .= '</li>';
9386: }
9387: }
9388: } else {
9389: my $value = $env{'form.'.$item};
9390: if ($value eq '') {
9391: $value = &mt('none');
9392: } elsif ($item eq 'auth_def') {
9393: my %authnames = &authtype_names();
9394: my %shortauth = (
9395: internal => 'int',
9396: krb4 => 'krb4',
9397: krb5 => 'krb5',
9398: localauth => 'loc',
9399: );
9400: $value = $authnames{$shortauth{$value}};
9401: }
9402: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9403: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9404: }
9405: }
9406: $resulttext .= '</ul>';
9407: $mailmsgtext .= "\n";
9408: my $cachetime = 24*60*60;
1.72 raeburn 9409: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9410: if (ref($lastactref) eq 'HASH') {
9411: $lastactref->{'domdefaults'} = 1;
9412: }
1.68 raeburn 9413: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9414: my $notify = 1;
9415: if (ref($domconfig{'contacts'}) eq 'HASH') {
9416: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9417: $notify = 0;
9418: }
9419: }
9420: if ($notify) {
9421: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9422: "LON-CAPA Domain Settings Change - $dom",
9423: $mailmsgtext);
9424: }
1.54 raeburn 9425: }
1.43 raeburn 9426: } else {
1.54 raeburn 9427: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9428: }
9429: } else {
9430: $resulttext = '<span class="LC_error">'.
9431: &mt('An error occurred: [_1]',$putresult).'</span>';
9432: }
9433: if (@errors > 0) {
9434: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9435: foreach my $item (@errors) {
9436: $resulttext .= ' "'.$title->{$item}.'",';
9437: }
9438: $resulttext =~ s/,$//;
9439: }
9440: return $resulttext;
9441: }
9442:
1.46 raeburn 9443: sub modify_scantron {
1.205 raeburn 9444: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9445: my ($resulttext,%confhash,%changes,$errors);
9446: my $custom = 'custom.tab';
9447: my $default = 'default.tab';
9448: my $servadm = $r->dir_config('lonAdmEMail');
9449: my ($configuserok,$author_ok,$switchserver) =
9450: &config_check($dom,$confname,$servadm);
9451: if ($env{'form.scantronformat.filename'} ne '') {
9452: my $error;
9453: if ($configuserok eq 'ok') {
9454: if ($switchserver) {
1.130 raeburn 9455: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9456: } else {
9457: if ($author_ok eq 'ok') {
9458: my ($result,$scantronurl) =
9459: &publishlogo($r,'upload','scantronformat',$dom,
9460: $confname,'scantron','','',$custom);
9461: if ($result eq 'ok') {
9462: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9463: $changes{'scantronformat'} = 1;
1.46 raeburn 9464: } else {
9465: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9466: }
9467: } else {
9468: $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);
9469: }
9470: }
9471: } else {
9472: $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);
9473: }
9474: if ($error) {
9475: &Apache::lonnet::logthis($error);
9476: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9477: }
9478: }
1.48 raeburn 9479: if (ref($domconfig{'scantron'}) eq 'HASH') {
9480: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9481: if ($env{'form.scantronformat_del'}) {
9482: $confhash{'scantron'}{'scantronformat'} = '';
9483: $changes{'scantronformat'} = 1;
1.46 raeburn 9484: }
9485: }
9486: }
9487: if (keys(%confhash) > 0) {
9488: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9489: $dom);
9490: if ($putresult eq 'ok') {
9491: if (keys(%changes) > 0) {
1.48 raeburn 9492: if (ref($confhash{'scantron'}) eq 'HASH') {
9493: $resulttext = &mt('Changes made:').'<ul>';
9494: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9495: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9496: } else {
1.130 raeburn 9497: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9498: }
1.48 raeburn 9499: $resulttext .= '</ul>';
9500: } else {
1.130 raeburn 9501: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9502: }
9503: $resulttext .= '</ul>';
9504: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9505: if (ref($lastactref) eq 'HASH') {
9506: $lastactref->{'domainconfig'} = 1;
9507: }
1.46 raeburn 9508: } else {
1.130 raeburn 9509: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9510: }
9511: } else {
9512: $resulttext = '<span class="LC_error">'.
9513: &mt('An error occurred: [_1]',$putresult).'</span>';
9514: }
9515: } else {
1.130 raeburn 9516: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9517: }
9518: if ($errors) {
9519: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9520: $errors.'</ul>';
9521: }
9522: return $resulttext;
9523: }
9524:
1.48 raeburn 9525: sub modify_coursecategories {
1.239 raeburn 9526: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9527: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9528: $cathash);
1.48 raeburn 9529: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 9530: my @catitems = ('unauth','auth');
9531: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9532: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9533: $cathash = $domconfig{'coursecategories'}{'cats'};
9534: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9535: $changes{'togglecats'} = 1;
9536: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9537: }
9538: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9539: $changes{'categorize'} = 1;
9540: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9541: }
1.120 raeburn 9542: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9543: $changes{'togglecatscomm'} = 1;
9544: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9545: }
9546: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9547: $changes{'categorizecomm'} = 1;
9548: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9549: }
1.238 raeburn 9550: foreach my $item (@catitems) {
9551: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9552: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9553: $changes{$item} = 1;
9554: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9555: }
9556: }
9557: }
1.57 raeburn 9558: } else {
9559: $changes{'togglecats'} = 1;
9560: $changes{'categorize'} = 1;
1.124 raeburn 9561: $changes{'togglecatscomm'} = 1;
9562: $changes{'categorizecomm'} = 1;
1.87 raeburn 9563: $domconfig{'coursecategories'} = {
9564: togglecats => $env{'form.togglecats'},
9565: categorize => $env{'form.categorize'},
1.124 raeburn 9566: togglecatscomm => $env{'form.togglecatscomm'},
9567: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9568: };
1.238 raeburn 9569: foreach my $item (@catitems) {
9570: if ($env{'form.coursecat_'.$item} ne 'std') {
9571: $changes{$item} = 1;
9572: }
9573: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9574: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9575: }
9576: }
1.57 raeburn 9577: }
9578: if (ref($cathash) eq 'HASH') {
9579: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9580: push (@deletecategory,'instcode::0');
9581: }
1.120 raeburn 9582: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9583: push(@deletecategory,'communities::0');
9584: }
1.48 raeburn 9585: }
1.57 raeburn 9586: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9587: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9588: if (@deletecategory > 0) {
9589: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9590: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9591: foreach my $item (@deletecategory) {
1.57 raeburn 9592: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9593: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9594: $deletions{$item} = 1;
1.57 raeburn 9595: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9596: }
9597: }
9598: }
1.57 raeburn 9599: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9600: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9601: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9602: $reorderings{$item} = 1;
1.57 raeburn 9603: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9604: }
9605: if ($env{'form.addcategory_name_'.$item} ne '') {
9606: my $newcat = $env{'form.addcategory_name_'.$item};
9607: my $newdepth = $depth+1;
9608: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9609: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9610: $adds{$newitem} = 1;
9611: }
9612: if ($env{'form.subcat_'.$item} ne '') {
9613: my $newcat = $env{'form.subcat_'.$item};
9614: my $newdepth = $depth+1;
9615: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9616: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9617: $adds{$newitem} = 1;
9618: }
9619: }
9620: }
9621: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9622: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9623: my $newitem = 'instcode::0';
1.57 raeburn 9624: if ($cathash->{$newitem} eq '') {
9625: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9626: $adds{$newitem} = 1;
9627: }
9628: } else {
9629: my $newitem = 'instcode::0';
1.57 raeburn 9630: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9631: $adds{$newitem} = 1;
9632: }
9633: }
1.120 raeburn 9634: if ($env{'form.communities'} eq '1') {
9635: if (ref($cathash) eq 'HASH') {
9636: my $newitem = 'communities::0';
9637: if ($cathash->{$newitem} eq '') {
9638: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9639: $adds{$newitem} = 1;
9640: }
9641: } else {
9642: my $newitem = 'communities::0';
9643: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9644: $adds{$newitem} = 1;
9645: }
9646: }
1.48 raeburn 9647: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9648: if (($env{'form.addcategory_name'} ne 'instcode') &&
9649: ($env{'form.addcategory_name'} ne 'communities')) {
9650: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9651: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9652: $adds{$newitem} = 1;
9653: }
1.48 raeburn 9654: }
1.57 raeburn 9655: my $putresult;
1.48 raeburn 9656: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9657: if (keys(%deletions) > 0) {
9658: foreach my $key (keys(%deletions)) {
9659: if ($predelallitems{$key} ne '') {
9660: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9661: }
9662: }
9663: }
9664: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9665: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9666: if (ref($chkcats[0]) eq 'ARRAY') {
9667: my $depth = 0;
9668: my $chg = 0;
9669: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9670: my $name = $chkcats[0][$i];
9671: my $item;
9672: if ($name eq '') {
9673: $chg ++;
9674: } else {
9675: $item = &escape($name).'::0';
9676: if ($chg) {
1.57 raeburn 9677: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9678: }
9679: $depth ++;
1.57 raeburn 9680: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9681: $depth --;
9682: }
9683: }
9684: }
1.57 raeburn 9685: }
9686: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9687: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9688: if ($putresult eq 'ok') {
1.57 raeburn 9689: my %title = (
1.120 raeburn 9690: togglecats => 'Show/Hide a course in catalog',
9691: categorize => 'Assign a category to a course',
9692: togglecatscomm => 'Show/Hide a community in catalog',
9693: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9694: );
9695: my %level = (
1.120 raeburn 9696: dom => 'set in Domain ("Modify Course/Community")',
9697: crs => 'set in Course ("Course Configuration")',
9698: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 9699: none => 'No catalog',
9700: std => 'Standard catalog',
9701: domonly => 'Domain-only catalog',
9702: codesrch => 'Code search form',
1.57 raeburn 9703: );
1.48 raeburn 9704: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9705: if ($changes{'togglecats'}) {
9706: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9707: }
9708: if ($changes{'categorize'}) {
9709: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9710: }
1.120 raeburn 9711: if ($changes{'togglecatscomm'}) {
9712: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9713: }
9714: if ($changes{'categorizecomm'}) {
9715: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9716: }
1.238 raeburn 9717: if ($changes{'unauth'}) {
9718: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9719: }
9720: if ($changes{'auth'}) {
9721: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9722: }
1.57 raeburn 9723: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9724: my $cathash;
9725: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9726: $cathash = $domconfig{'coursecategories'}{'cats'};
9727: } else {
9728: $cathash = {};
9729: }
9730: my (@cats,@trails,%allitems);
9731: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9732: if (keys(%deletions) > 0) {
9733: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9734: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9735: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9736: }
9737: $resulttext .= '</ul></li>';
9738: }
9739: if (keys(%reorderings) > 0) {
9740: my %sort_by_trail;
9741: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9742: foreach my $key (keys(%reorderings)) {
9743: if ($allitems{$key} ne '') {
9744: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9745: }
1.48 raeburn 9746: }
1.57 raeburn 9747: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9748: $resulttext .= '<li>'.$trails[$trail].'</li>';
9749: }
9750: $resulttext .= '</ul></li>';
1.48 raeburn 9751: }
1.57 raeburn 9752: if (keys(%adds) > 0) {
9753: my %sort_by_trail;
9754: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9755: foreach my $key (keys(%adds)) {
9756: if ($allitems{$key} ne '') {
9757: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9758: }
9759: }
9760: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9761: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9762: }
1.57 raeburn 9763: $resulttext .= '</ul></li>';
1.48 raeburn 9764: }
9765: }
9766: $resulttext .= '</ul>';
1.239 raeburn 9767: if ($changes{'unauth'} || $changes{'auth'}) {
9768: &Apache::loncommon::devalidate_domconfig_cache($dom);
9769: if (ref($lastactref) eq 'HASH') {
9770: $lastactref->{'domainconfig'} = 1;
9771: }
9772: }
1.48 raeburn 9773: } else {
9774: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9775: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9776: }
9777: } else {
1.120 raeburn 9778: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9779: }
9780: return $resulttext;
9781: }
9782:
1.69 raeburn 9783: sub modify_serverstatuses {
9784: my ($dom,%domconfig) = @_;
9785: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9786: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9787: %currserverstatus = %{$domconfig{'serverstatuses'}};
9788: }
9789: my @pages = &serverstatus_pages();
9790: foreach my $type (@pages) {
9791: $newserverstatus{$type}{'namedusers'} = '';
9792: $newserverstatus{$type}{'machines'} = '';
9793: if (defined($env{'form.'.$type.'_namedusers'})) {
9794: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9795: my @okusers;
9796: foreach my $user (@users) {
9797: my ($uname,$udom) = split(/:/,$user);
9798: if (($udom =~ /^$match_domain$/) &&
9799: (&Apache::lonnet::domain($udom)) &&
9800: ($uname =~ /^$match_username$/)) {
9801: if (!grep(/^\Q$user\E/,@okusers)) {
9802: push(@okusers,$user);
9803: }
9804: }
9805: }
9806: if (@okusers > 0) {
9807: @okusers = sort(@okusers);
9808: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9809: }
9810: }
9811: if (defined($env{'form.'.$type.'_machines'})) {
9812: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9813: my @okmachines;
9814: foreach my $ip (@machines) {
9815: my @parts = split(/\./,$ip);
9816: next if (@parts < 4);
9817: my $badip = 0;
9818: for (my $i=0; $i<4; $i++) {
9819: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9820: $badip = 1;
9821: last;
9822: }
9823: }
9824: if (!$badip) {
9825: push(@okmachines,$ip);
9826: }
9827: }
9828: @okmachines = sort(@okmachines);
9829: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9830: }
9831: }
9832: my %serverstatushash = (
9833: serverstatuses => \%newserverstatus,
9834: );
9835: foreach my $type (@pages) {
1.83 raeburn 9836: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9837: my (@current,@new);
1.83 raeburn 9838: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9839: if ($currserverstatus{$type}{$setting} ne '') {
9840: @current = split(/,/,$currserverstatus{$type}{$setting});
9841: }
9842: }
9843: if ($newserverstatus{$type}{$setting} ne '') {
9844: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9845: }
9846: if (@current > 0) {
9847: if (@new > 0) {
9848: foreach my $item (@current) {
9849: if (!grep(/^\Q$item\E$/,@new)) {
9850: $changes{$type}{$setting} = 1;
1.82 raeburn 9851: last;
9852: }
9853: }
1.84 raeburn 9854: foreach my $item (@new) {
9855: if (!grep(/^\Q$item\E$/,@current)) {
9856: $changes{$type}{$setting} = 1;
9857: last;
1.82 raeburn 9858: }
9859: }
9860: } else {
1.83 raeburn 9861: $changes{$type}{$setting} = 1;
1.69 raeburn 9862: }
1.83 raeburn 9863: } elsif (@new > 0) {
9864: $changes{$type}{$setting} = 1;
1.69 raeburn 9865: }
9866: }
9867: }
9868: if (keys(%changes) > 0) {
1.81 raeburn 9869: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9870: my $putresult = &Apache::lonnet::put_dom('configuration',
9871: \%serverstatushash,$dom);
9872: if ($putresult eq 'ok') {
9873: $resulttext .= &mt('Changes made:').'<ul>';
9874: foreach my $type (@pages) {
1.84 raeburn 9875: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9876: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9877: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9878: if ($newserverstatus{$type}{'namedusers'} eq '') {
9879: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9880: } else {
9881: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9882: }
1.84 raeburn 9883: }
9884: if ($changes{$type}{'machines'}) {
1.69 raeburn 9885: if ($newserverstatus{$type}{'machines'} eq '') {
9886: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9887: } else {
9888: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9889: }
9890:
9891: }
9892: $resulttext .= '</ul></li>';
9893: }
9894: }
9895: $resulttext .= '</ul>';
9896: } else {
9897: $resulttext = '<span class="LC_error">'.
9898: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9899:
9900: }
9901: } else {
9902: $resulttext = &mt('No changes made to access to server status pages');
9903: }
9904: return $resulttext;
9905: }
9906:
1.118 jms 9907: sub modify_helpsettings {
1.122 jms 9908: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9909: my ($resulttext,$errors,%changes,%helphash);
9910: my %defaultchecked = ('submitbugs' => 'on');
9911: my @offon = ('off','on');
1.118 jms 9912: my @toggles = ('submitbugs');
9913: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9914: foreach my $item (@toggles) {
1.166 raeburn 9915: if ($defaultchecked{$item} eq 'on') {
9916: if ($domconfig{'helpsettings'}{$item} eq '') {
9917: if ($env{'form.'.$item} eq '0') {
9918: $changes{$item} = 1;
9919: }
9920: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9921: $changes{$item} = 1;
9922: }
9923: } elsif ($defaultchecked{$item} eq 'off') {
9924: if ($domconfig{'helpsettings'}{$item} eq '') {
9925: if ($env{'form.'.$item} eq '1') {
9926: $changes{$item} = 1;
9927: }
9928: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9929: $changes{$item} = 1;
9930: }
9931: }
1.210 raeburn 9932: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9933: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9934: }
9935: }
1.118 jms 9936: }
1.123 jms 9937: my $putresult;
9938: if (keys(%changes) > 0) {
1.166 raeburn 9939: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9940: if ($putresult eq 'ok') {
1.166 raeburn 9941: $resulttext = &mt('Changes made:').'<ul>';
9942: foreach my $item (sort(keys(%changes))) {
9943: if ($item eq 'submitbugs') {
9944: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9945: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9946: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9947: }
9948: }
9949: $resulttext .= '</ul>';
9950: } else {
9951: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9952: $errors .= '<li><span class="LC_error">'.
9953: &mt('An error occurred storing the settings: [_1]',
9954: $putresult).'</span></li>';
1.166 raeburn 9955: }
1.118 jms 9956: }
9957: if ($errors) {
1.168 raeburn 9958: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9959: $errors.'</ul>';
9960: }
9961: return $resulttext;
9962: }
9963:
1.121 raeburn 9964: sub modify_coursedefaults {
1.212 raeburn 9965: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9966: my ($resulttext,$errors,%changes,%defaultshash);
9967: my %defaultchecked = ('canuse_pdfforms' => 'off');
9968: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9969: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9970: 'uploadquota_community','uploadquota_textbook');
9971: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9972: my %staticdefaults = (
9973: anonsurvey_threshold => 10,
9974: uploadquota => 500,
9975: );
1.121 raeburn 9976:
9977: $defaultshash{'coursedefaults'} = {};
9978:
9979: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9980: if ($domconfig{'coursedefaults'} eq '') {
9981: $domconfig{'coursedefaults'} = {};
9982: }
9983: }
9984:
9985: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9986: foreach my $item (@toggles) {
9987: if ($defaultchecked{$item} eq 'on') {
9988: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9989: ($env{'form.'.$item} eq '0')) {
9990: $changes{$item} = 1;
1.192 raeburn 9991: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9992: $changes{$item} = 1;
9993: }
9994: } elsif ($defaultchecked{$item} eq 'off') {
9995: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9996: ($env{'form.'.$item} eq '1')) {
9997: $changes{$item} = 1;
9998: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9999: $changes{$item} = 1;
10000: }
10001: }
10002: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10003: }
1.198 raeburn 10004: foreach my $item (@numbers) {
10005: my ($currdef,$newdef);
1.208 raeburn 10006: $newdef = $env{'form.'.$item};
1.198 raeburn 10007: if ($item eq 'anonsurvey_threshold') {
10008: $currdef = $domconfig{'coursedefaults'}{$item};
10009: $newdef =~ s/\D//g;
10010: if ($newdef eq '' || $newdef < 1) {
10011: $newdef = 1;
10012: }
10013: $defaultshash{'coursedefaults'}{$item} = $newdef;
10014: } else {
10015: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10016: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10017: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10018: }
10019: $newdef =~ s/[^\w.\-]//g;
10020: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10021: }
10022: if ($currdef ne $newdef) {
10023: my $staticdef;
10024: if ($item eq 'anonsurvey_threshold') {
10025: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10026: $changes{$item} = 1;
10027: }
10028: } else {
10029: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10030: $changes{'uploadquota'} = 1;
10031: }
10032: }
1.139 raeburn 10033: }
10034: }
1.231 raeburn 10035:
1.192 raeburn 10036: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 10037: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 10038: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 10039: $unofficialcreds =~ s/[^\d.]+//g;
10040: my $textbookcreds = $env{'form.textbook_credits'};
10041: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 10042: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10043: ($env{'form.coursecredits'} eq '1')) {
10044: $changes{'coursecredits'} = 1;
10045: } else {
10046: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 10047: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10048: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 10049: $changes{'coursecredits'} = 1;
10050: }
10051: }
10052: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10053: official => $officialcreds,
10054: unofficial => $unofficialcreds,
1.216 raeburn 10055: textbook => $textbookcreds,
1.192 raeburn 10056: }
1.121 raeburn 10057: }
10058: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10059: $dom);
10060: if ($putresult eq 'ok') {
10061: if (keys(%changes) > 0) {
1.213 raeburn 10062: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 10063: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 10064: ($changes{'uploadquota'})) {
1.192 raeburn 10065: if ($changes{'canuse_pdfforms'}) {
10066: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10067: }
10068: if ($changes{'coursecredits'}) {
10069: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10070: $domdefaults{'officialcredits'} =
10071: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10072: $domdefaults{'unofficialcredits'} =
10073: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 10074: $domdefaults{'textbookcredits'} =
10075: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 10076: }
10077: }
1.198 raeburn 10078: if ($changes{'uploadquota'}) {
10079: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10080: foreach my $type (@types) {
10081: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10082: }
10083: }
10084: }
1.121 raeburn 10085: my $cachetime = 24*60*60;
10086: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10087: if (ref($lastactref) eq 'HASH') {
10088: $lastactref->{'domdefaults'} = 1;
10089: }
1.121 raeburn 10090: }
10091: $resulttext = &mt('Changes made:').'<ul>';
10092: foreach my $item (sort(keys(%changes))) {
10093: if ($item eq 'canuse_pdfforms') {
10094: if ($env{'form.'.$item} eq '1') {
10095: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10096: } else {
10097: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10098: }
1.139 raeburn 10099: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 10100: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 10101: } elsif ($item eq 'uploadquota') {
10102: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10103: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10104: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10105: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 10106: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10107:
1.198 raeburn 10108: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10109: '</ul>'.
10110: '</li>';
10111: } else {
10112: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10113: }
1.192 raeburn 10114: } elsif ($item eq 'coursecredits') {
10115: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10116: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 10117: ($domdefaults{'unofficialcredits'} eq '') &&
10118: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 10119: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10120: } else {
10121: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10122: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10123: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 10124: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 10125: '</ul>'.
10126: '</li>';
10127: }
10128: } else {
10129: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10130: }
1.140 raeburn 10131: }
1.121 raeburn 10132: }
10133: $resulttext .= '</ul>';
10134: } else {
10135: $resulttext = &mt('No changes made to course defaults');
10136: }
10137: } else {
10138: $resulttext = '<span class="LC_error">'.
10139: &mt('An error occurred: [_1]',$putresult).'</span>';
10140: }
10141: return $resulttext;
10142: }
10143:
1.231 raeburn 10144: sub modify_selfenrollment {
10145: my ($dom,$lastactref,%domconfig) = @_;
10146: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10147: my @types = ('official','unofficial','community','textbook');
10148: my %titles = &tool_titles();
1.232 raeburn 10149: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10150: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 10151: $ordered{'default'} = ['types','registered','approval','limit'];
10152:
10153: my (%roles,%shown,%toplevel);
10154: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10155:
10156: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10157: if ($domconfig{'selfenrollment'} eq '') {
10158: $domconfig{'selfenrollment'} = {};
10159: }
10160: }
10161: %toplevel = (
10162: admin => 'Configuration Rights',
10163: default => 'Default settings',
10164: validation => 'Validation of self-enrollment requests',
10165: );
1.233 raeburn 10166: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10167:
10168: if (ref($ordered{'admin'}) eq 'ARRAY') {
10169: foreach my $item (@{$ordered{'admin'}}) {
10170: foreach my $type (@types) {
10171: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10172: $selfenrollhash{'admin'}{$type}{$item} = 1;
10173: } else {
10174: $selfenrollhash{'admin'}{$type}{$item} = 0;
10175: }
10176: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10177: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10178: if ($selfenrollhash{'admin'}{$type}{$item} ne
10179: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10180: push(@{$changes{'admin'}{$type}},$item);
10181: }
10182: } else {
10183: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10184: push(@{$changes{'admin'}{$type}},$item);
10185: }
10186: }
10187: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10188: push(@{$changes{'admin'}{$type}},$item);
10189: }
10190: }
10191: }
10192: }
10193:
10194: foreach my $item (@{$ordered{'default'}}) {
10195: foreach my $type (@types) {
10196: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10197: if ($item eq 'types') {
10198: unless (($value eq 'all') || ($value eq 'dom')) {
10199: $value = '';
10200: }
10201: } elsif ($item eq 'registered') {
10202: unless ($value eq '1') {
10203: $value = 0;
10204: }
10205: } elsif ($item eq 'approval') {
10206: unless ($value =~ /^[012]$/) {
10207: $value = 0;
10208: }
10209: } else {
10210: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10211: $value = 'none';
10212: }
10213: }
10214: $selfenrollhash{'default'}{$type}{$item} = $value;
10215: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10216: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10217: if ($selfenrollhash{'default'}{$type}{$item} ne
10218: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10219: push(@{$changes{'default'}{$type}},$item);
10220: }
10221: } else {
10222: push(@{$changes{'default'}{$type}},$item);
10223: }
10224: } else {
10225: push(@{$changes{'default'}{$type}},$item);
10226: }
10227: if ($item eq 'limit') {
10228: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10229: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10230: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10231: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10232: }
10233: } else {
10234: $selfenrollhash{'default'}{$type}{'cap'} = '';
10235: }
10236: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10237: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10238: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10239: push(@{$changes{'default'}{$type}},'cap');
10240: }
10241: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10242: push(@{$changes{'default'}{$type}},'cap');
10243: }
10244: }
10245: }
10246: }
10247:
10248: foreach my $item (@{$itemsref}) {
10249: if ($item eq 'fields') {
10250: my @changed;
10251: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10252: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10253: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10254: }
10255: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10256: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10257: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10258: $domconfig{'selfenrollment'}{'validation'}{$item});
10259: } else {
10260: @changed = @{$selfenrollhash{'validation'}{$item}};
10261: }
10262: } else {
10263: @changed = @{$selfenrollhash{'validation'}{$item}};
10264: }
10265: if (@changed) {
10266: if ($selfenrollhash{'validation'}{$item}) {
10267: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10268: } else {
10269: $changes{'validation'}{$item} = &mt('None');
10270: }
10271: }
10272: } else {
10273: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10274: if ($item eq 'markup') {
10275: if ($env{'form.selfenroll_validation_'.$item}) {
10276: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10277: }
10278: }
10279: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10280: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10281: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10282: }
10283: }
10284: }
10285: }
10286:
10287: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10288: $dom);
10289: if ($putresult eq 'ok') {
10290: if (keys(%changes) > 0) {
10291: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10292: $resulttext = &mt('Changes made:').'<ul>';
10293: foreach my $key ('admin','default','validation') {
10294: if (ref($changes{$key}) eq 'HASH') {
10295: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10296: if ($key eq 'validation') {
10297: foreach my $item (@{$itemsref}) {
10298: if (exists($changes{$key}{$item})) {
10299: if ($item eq 'markup') {
10300: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10301: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10302: } else {
10303: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10304: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10305: }
10306: }
10307: }
10308: } else {
10309: foreach my $type (@types) {
10310: if ($type eq 'community') {
10311: $roles{'1'} = &mt('Community personnel');
10312: } else {
10313: $roles{'1'} = &mt('Course personnel');
10314: }
10315: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10316: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10317: if ($key eq 'admin') {
10318: my @mgrdc = ();
10319: if (ref($ordered{$key}) eq 'ARRAY') {
10320: foreach my $item (@{$ordered{'admin'}}) {
10321: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10322: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10323: push(@mgrdc,$item);
10324: }
10325: }
10326: }
10327: if (@mgrdc) {
10328: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10329: } else {
10330: delete($domdefaults{$type.'selfenrolladmdc'});
10331: }
10332: }
10333: } else {
10334: if (ref($ordered{$key}) eq 'ARRAY') {
10335: foreach my $item (@{$ordered{$key}}) {
10336: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10337: $domdefaults{$type.'selfenroll'.$item} =
10338: $selfenrollhash{$key}{$type}{$item};
10339: }
10340: }
10341: }
10342: }
10343: }
1.231 raeburn 10344: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10345: foreach my $item (@{$ordered{$key}}) {
10346: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10347: $resulttext .= '<li>';
10348: if ($key eq 'admin') {
10349: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10350: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10351: } else {
10352: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10353: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10354: }
10355: $resulttext .= '</li>';
10356: }
10357: }
10358: $resulttext .= '</ul></li>';
10359: }
10360: }
10361: $resulttext .= '</ul></li>';
10362: }
10363: }
1.232 raeburn 10364: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10365: my $cachetime = 24*60*60;
10366: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10367: if (ref($lastactref) eq 'HASH') {
10368: $lastactref->{'domdefaults'} = 1;
10369: }
10370: }
1.231 raeburn 10371: }
10372: $resulttext .= '</ul>';
10373: } else {
10374: $resulttext = &mt('No changes made to self-enrollment settings');
10375: }
10376: } else {
10377: $resulttext = '<span class="LC_error">'.
10378: &mt('An error occurred: [_1]',$putresult).'</span>';
10379: }
10380: return $resulttext;
10381: }
10382:
1.137 raeburn 10383: sub modify_usersessions {
1.212 raeburn 10384: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10385: my @hostingtypes = ('version','excludedomain','includedomain');
10386: my @offloadtypes = ('primary','default');
10387: my %types = (
10388: remote => \@hostingtypes,
10389: hosted => \@hostingtypes,
10390: spares => \@offloadtypes,
10391: );
10392: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10393: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10394: my (%by_ip,%by_location,@intdoms);
10395: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10396: my @locations = sort(keys(%by_location));
1.137 raeburn 10397: my (%defaultshash,%changes);
10398: foreach my $prefix (@prefixes) {
10399: $defaultshash{'usersessions'}{$prefix} = {};
10400: }
1.212 raeburn 10401: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10402: my $resulttext;
1.138 raeburn 10403: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10404: foreach my $prefix (@prefixes) {
1.145 raeburn 10405: next if ($prefix eq 'spares');
10406: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10407: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10408: if ($type eq 'version') {
10409: my $value = $env{'form.'.$prefix.'_'.$type};
10410: my $okvalue;
10411: if ($value ne '') {
10412: if (grep(/^\Q$value\E$/,@lcversions)) {
10413: $okvalue = $value;
10414: }
10415: }
10416: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10417: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10418: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10419: if ($inuse == 0) {
10420: $changes{$prefix}{$type} = 1;
10421: } else {
10422: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10423: $changes{$prefix}{$type} = 1;
10424: }
10425: if ($okvalue ne '') {
10426: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10427: }
10428: }
10429: } else {
10430: if (($inuse == 1) && ($okvalue ne '')) {
10431: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10432: $changes{$prefix}{$type} = 1;
10433: }
10434: }
10435: } else {
10436: if (($inuse == 1) && ($okvalue ne '')) {
10437: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10438: $changes{$prefix}{$type} = 1;
10439: }
10440: }
10441: } else {
10442: if (($inuse == 1) && ($okvalue ne '')) {
10443: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10444: $changes{$prefix}{$type} = 1;
10445: }
10446: }
10447: } else {
10448: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10449: my @okvals;
10450: foreach my $val (@vals) {
1.138 raeburn 10451: if ($val =~ /:/) {
10452: my @items = split(/:/,$val);
10453: foreach my $item (@items) {
10454: if (ref($by_location{$item}) eq 'ARRAY') {
10455: push(@okvals,$item);
10456: }
10457: }
10458: } else {
10459: if (ref($by_location{$val}) eq 'ARRAY') {
10460: push(@okvals,$val);
10461: }
1.137 raeburn 10462: }
10463: }
10464: @okvals = sort(@okvals);
10465: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10466: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10467: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10468: if ($inuse == 0) {
10469: $changes{$prefix}{$type} = 1;
10470: } else {
10471: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10472: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10473: if (@changed > 0) {
10474: $changes{$prefix}{$type} = 1;
10475: }
10476: }
10477: } else {
10478: if ($inuse == 1) {
10479: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10480: $changes{$prefix}{$type} = 1;
10481: }
10482: }
10483: } else {
10484: if ($inuse == 1) {
10485: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10486: $changes{$prefix}{$type} = 1;
10487: }
10488: }
10489: } else {
10490: if ($inuse == 1) {
10491: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10492: $changes{$prefix}{$type} = 1;
10493: }
10494: }
10495: }
10496: }
10497: }
1.145 raeburn 10498:
10499: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10500: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10501: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10502: my $savespares;
10503:
10504: foreach my $lonhost (sort(keys(%servers))) {
10505: my $serverhomeID =
10506: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10507: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10508: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10509: my %spareschg;
10510: foreach my $type (@{$types{'spares'}}) {
10511: my @okspares;
10512: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10513: foreach my $server (@checked) {
1.152 raeburn 10514: if (&Apache::lonnet::hostname($server) ne '') {
10515: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10516: unless (grep(/^\Q$server\E$/,@okspares)) {
10517: push(@okspares,$server);
10518: }
1.145 raeburn 10519: }
10520: }
10521: }
10522: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10523: my $newspare;
1.152 raeburn 10524: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10525: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10526: $newspare = $new;
10527: }
10528: }
1.152 raeburn 10529: my @spares;
10530: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10531: @spares = sort(@okspares,$newspare);
10532: } else {
10533: @spares = sort(@okspares);
10534: }
10535: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10536: if (ref($spareid{$lonhost}) eq 'HASH') {
10537: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10538: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10539: if (@diffs > 0) {
10540: $spareschg{$type} = 1;
10541: }
10542: }
10543: }
10544: }
10545: if (keys(%spareschg) > 0) {
10546: $changes{'spares'}{$lonhost} = \%spareschg;
10547: }
10548: }
10549:
10550: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10551: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10552: if (ref($changes{'spares'}) eq 'HASH') {
10553: if (keys(%{$changes{'spares'}}) > 0) {
10554: $savespares = 1;
10555: }
10556: }
10557: } else {
10558: $savespares = 1;
10559: }
10560: }
10561:
1.147 raeburn 10562: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10563: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10564: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10565: $dom);
10566: if ($putresult eq 'ok') {
10567: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10568: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10569: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10570: }
10571: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10572: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10573: }
10574: }
10575: my $cachetime = 24*60*60;
10576: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10577: if (ref($lastactref) eq 'HASH') {
10578: $lastactref->{'domdefaults'} = 1;
10579: }
1.147 raeburn 10580: if (keys(%changes) > 0) {
10581: my %lt = &usersession_titles();
10582: $resulttext = &mt('Changes made:').'<ul>';
10583: foreach my $prefix (@prefixes) {
10584: if (ref($changes{$prefix}) eq 'HASH') {
10585: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10586: if ($prefix eq 'spares') {
10587: if (ref($changes{$prefix}) eq 'HASH') {
10588: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10589: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10590: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10591: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10592: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10593: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10594: foreach my $type (@{$types{$prefix}}) {
10595: if ($changes{$prefix}{$lonhost}{$type}) {
10596: my $offloadto = &mt('None');
10597: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10598: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10599: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10600: }
1.145 raeburn 10601: }
1.147 raeburn 10602: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10603: }
1.137 raeburn 10604: }
10605: }
1.147 raeburn 10606: $resulttext .= '</li>';
1.137 raeburn 10607: }
10608: }
1.147 raeburn 10609: } else {
10610: foreach my $type (@{$types{$prefix}}) {
10611: if (defined($changes{$prefix}{$type})) {
10612: my $newvalue;
10613: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10614: if (ref($defaultshash{'usersessions'}{$prefix})) {
10615: if ($type eq 'version') {
10616: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10617: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10618: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10619: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10620: }
1.145 raeburn 10621: }
10622: }
10623: }
1.147 raeburn 10624: if ($newvalue eq '') {
10625: if ($type eq 'version') {
10626: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10627: } else {
10628: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10629: }
1.145 raeburn 10630: } else {
1.147 raeburn 10631: if ($type eq 'version') {
10632: $newvalue .= ' '.&mt('(or later)');
10633: }
10634: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10635: }
1.137 raeburn 10636: }
10637: }
10638: }
1.147 raeburn 10639: $resulttext .= '</ul>';
1.137 raeburn 10640: }
10641: }
1.147 raeburn 10642: $resulttext .= '</ul>';
10643: } else {
10644: $resulttext = $nochgmsg;
1.137 raeburn 10645: }
10646: } else {
10647: $resulttext = '<span class="LC_error">'.
10648: &mt('An error occurred: [_1]',$putresult).'</span>';
10649: }
10650: } else {
1.147 raeburn 10651: $resulttext = $nochgmsg;
1.137 raeburn 10652: }
10653: return $resulttext;
10654: }
10655:
1.150 raeburn 10656: sub modify_loadbalancing {
10657: my ($dom,%domconfig) = @_;
10658: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10659: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10660: my ($othertitle,$usertypes,$types) =
10661: &Apache::loncommon::sorted_inst_types($dom);
10662: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10663: my @sparestypes = ('primary','default');
10664: my %typetitles = &sparestype_titles();
10665: my $resulttext;
1.171 raeburn 10666: my (%currbalancer,%currtargets,%currrules,%existing);
10667: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10668: %existing = %{$domconfig{'loadbalancing'}};
10669: }
10670: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10671: \%currtargets,\%currrules);
10672: my ($saveloadbalancing,%defaultshash,%changes);
10673: my ($alltypes,$othertypes,$titles) =
10674: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10675: my %ruletitles = &offloadtype_text();
10676: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10677: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10678: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10679: if ($balancer eq '') {
10680: next;
10681: }
1.210 raeburn 10682: if (!exists($servers{$balancer})) {
1.171 raeburn 10683: if (exists($currbalancer{$balancer})) {
10684: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10685: }
1.171 raeburn 10686: next;
10687: }
10688: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10689: push(@{$changes{'delete'}},$balancer);
10690: next;
10691: }
10692: if (!exists($currbalancer{$balancer})) {
10693: push(@{$changes{'add'}},$balancer);
10694: }
10695: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10696: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10697: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10698: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10699: $saveloadbalancing = 1;
10700: }
10701: foreach my $sparetype (@sparestypes) {
10702: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10703: my @offloadto;
10704: foreach my $target (@targets) {
10705: if (($servers{$target}) && ($target ne $balancer)) {
10706: if ($sparetype eq 'default') {
10707: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10708: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10709: }
10710: }
1.171 raeburn 10711: unless(grep(/^\Q$target\E$/,@offloadto)) {
10712: push(@offloadto,$target);
10713: }
1.150 raeburn 10714: }
1.171 raeburn 10715: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10716: }
10717: }
1.171 raeburn 10718: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10719: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10720: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10721: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10722: if (@targetdiffs > 0) {
1.171 raeburn 10723: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10724: }
1.171 raeburn 10725: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10726: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10727: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10728: }
10729: }
10730: }
10731: } else {
1.171 raeburn 10732: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10733: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10734: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10735: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10736: $changes{'curr'}{$balancer}{'targets'} = 1;
10737: }
1.150 raeburn 10738: }
10739: }
1.210 raeburn 10740: }
1.150 raeburn 10741: }
10742: my $ishomedom;
1.171 raeburn 10743: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10744: $ishomedom = 1;
1.150 raeburn 10745: }
10746: if (ref($alltypes) eq 'ARRAY') {
10747: foreach my $type (@{$alltypes}) {
10748: my $rule;
1.210 raeburn 10749: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10750: (!$ishomedom)) {
1.171 raeburn 10751: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10752: }
10753: if ($rule eq 'specific') {
10754: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10755: }
1.171 raeburn 10756: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10757: if (ref($currrules{$balancer}) eq 'HASH') {
10758: if ($rule ne $currrules{$balancer}{$type}) {
10759: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10760: }
10761: } elsif ($rule ne '') {
1.171 raeburn 10762: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10763: }
10764: }
10765: }
1.171 raeburn 10766: }
10767: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10768: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10769: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10770: $defaultshash{'loadbalancing'} = {};
10771: }
10772: my $putresult = &Apache::lonnet::put_dom('configuration',
10773: \%defaultshash,$dom);
10774: if ($putresult eq 'ok') {
10775: if (keys(%changes) > 0) {
10776: if (ref($changes{'delete'}) eq 'ARRAY') {
10777: foreach my $balancer (sort(@{$changes{'delete'}})) {
10778: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 10779: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10780: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10781: }
1.171 raeburn 10782: }
10783: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10784: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10785: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10786: }
10787: }
10788: if (ref($changes{'curr'}) eq 'HASH') {
10789: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10790: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10791: if ($changes{'curr'}{$balancer}{'targets'}) {
10792: my %offloadstr;
10793: foreach my $sparetype (@sparestypes) {
10794: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10795: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10796: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10797: }
10798: }
1.150 raeburn 10799: }
1.171 raeburn 10800: if (keys(%offloadstr) == 0) {
10801: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10802: } else {
1.171 raeburn 10803: my $showoffload;
10804: foreach my $sparetype (@sparestypes) {
10805: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10806: if (defined($offloadstr{$sparetype})) {
10807: $showoffload .= $offloadstr{$sparetype};
10808: } else {
10809: $showoffload .= &mt('None');
10810: }
10811: $showoffload .= (' 'x3);
10812: }
10813: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10814: }
10815: }
10816: }
1.171 raeburn 10817: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10818: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10819: foreach my $type (@{$alltypes}) {
10820: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10821: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10822: my $balancetext;
10823: if ($rule eq '') {
10824: $balancetext = $ruletitles{'default'};
1.209 raeburn 10825: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10826: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 10827: $balancetext = $ruletitles{$rule};
10828: } else {
10829: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10830: }
1.210 raeburn 10831: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10832: }
10833: }
10834: }
10835: }
1.215 raeburn 10836: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 10837: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10838: }
1.171 raeburn 10839: }
10840: if ($resulttext ne '') {
10841: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10842: } else {
10843: $resulttext = $nochgmsg;
10844: }
10845: } else {
1.171 raeburn 10846: $resulttext = $nochgmsg;
1.150 raeburn 10847: }
10848: } else {
1.171 raeburn 10849: $resulttext = '<span class="LC_error">'.
10850: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10851: }
10852: } else {
1.171 raeburn 10853: $resulttext = $nochgmsg;
1.150 raeburn 10854: }
10855: return $resulttext;
10856: }
10857:
1.48 raeburn 10858: sub recurse_check {
10859: my ($chkcats,$categories,$depth,$name) = @_;
10860: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10861: my $chg = 0;
10862: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10863: my $category = $chkcats->[$depth]{$name}[$j];
10864: my $item;
10865: if ($category eq '') {
10866: $chg ++;
10867: } else {
10868: my $deeper = $depth + 1;
10869: $item = &escape($category).':'.&escape($name).':'.$depth;
10870: if ($chg) {
10871: $categories->{$item} -= $chg;
10872: }
10873: &recurse_check($chkcats,$categories,$deeper,$category);
10874: $deeper --;
10875: }
10876: }
10877: }
10878: return;
10879: }
10880:
10881: sub recurse_cat_deletes {
10882: my ($item,$coursecategories,$deletions) = @_;
10883: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10884: my $subdepth = $depth + 1;
10885: if (ref($coursecategories) eq 'HASH') {
10886: foreach my $subitem (keys(%{$coursecategories})) {
10887: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10888: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10889: delete($coursecategories->{$subitem});
10890: $deletions->{$subitem} = 1;
10891: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10892: }
1.48 raeburn 10893: }
10894: }
10895: return;
10896: }
10897:
1.125 raeburn 10898: sub get_active_dcs {
10899: my ($dom) = @_;
1.191 raeburn 10900: my $now = time;
10901: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10902: my %domcoords;
10903: my $numdcs = 0;
10904: foreach my $server (keys(%dompersonnel)) {
10905: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10906: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10907: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10908: }
10909: }
10910: return %domcoords;
10911: }
10912:
10913: sub active_dc_picker {
1.191 raeburn 10914: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 10915: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10916: my @domcoord = keys(%domcoords);
10917: if (keys(%currhash)) {
10918: foreach my $dc (keys(%currhash)) {
10919: unless (exists($domcoords{$dc})) {
10920: push(@domcoord,$dc);
10921: }
10922: }
10923: }
10924: @domcoord = sort(@domcoord);
1.210 raeburn 10925: my $numdcs = scalar(@domcoord);
1.191 raeburn 10926: my $rows = 0;
10927: my $table;
1.125 raeburn 10928: if ($numdcs > 1) {
1.191 raeburn 10929: $table = '<table>';
10930: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10931: my $rem = $i%($numinrow);
10932: if ($rem == 0) {
10933: if ($i > 0) {
1.191 raeburn 10934: $table .= '</tr>';
1.125 raeburn 10935: }
1.191 raeburn 10936: $table .= '<tr>';
10937: $rows ++;
1.125 raeburn 10938: }
1.191 raeburn 10939: my $check = '';
10940: if ($inputtype eq 'radio') {
10941: if (keys(%currhash) == 0) {
10942: if (!$i) {
10943: $check = ' checked="checked"';
10944: }
10945: } elsif (exists($currhash{$domcoord[$i]})) {
10946: $check = ' checked="checked"';
10947: }
10948: } else {
10949: if (exists($currhash{$domcoord[$i]})) {
10950: $check = ' checked="checked"';
1.125 raeburn 10951: }
10952: }
1.191 raeburn 10953: if ($i == @domcoord - 1) {
1.125 raeburn 10954: my $colsleft = $numinrow - $rem;
10955: if ($colsleft > 1) {
1.191 raeburn 10956: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10957: } else {
1.191 raeburn 10958: $table .= '<td class="LC_left_item">';
1.125 raeburn 10959: }
10960: } else {
1.191 raeburn 10961: $table .= '<td class="LC_left_item">';
10962: }
10963: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10964: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10965: $table .= '<span class="LC_nobreak"><label>'.
10966: '<input type="'.$inputtype.'" name="'.$name.'"'.
10967: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10968: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 10969: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 10970: }
1.219 raeburn 10971: $table .= '</label></span></td>';
1.191 raeburn 10972: }
10973: $table .= '</tr></table>';
10974: } elsif ($numdcs == 1) {
1.219 raeburn 10975: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10976: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 10977: if ($inputtype eq 'radio') {
1.219 raeburn 10978: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10979: if ($user ne $dcname.':'.$dcdom) {
10980: $table .= ' ('.$dcname.':'.$dcdom.')';
10981: }
1.191 raeburn 10982: } else {
10983: my $check;
10984: if (exists($currhash{$domcoord[0]})) {
10985: $check = ' checked="checked"';
1.125 raeburn 10986: }
1.219 raeburn 10987: $table .= '<span class="LC_nobreak"><label>'.
10988: '<input type="checkbox" name="'.$name.'" '.
10989: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10990: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 10991: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 10992: }
1.220 raeburn 10993: $table .= '</label></span>';
1.191 raeburn 10994: $rows ++;
1.125 raeburn 10995: }
10996: }
1.191 raeburn 10997: return ($numdcs,$table,$rows);
1.125 raeburn 10998: }
10999:
1.137 raeburn 11000: sub usersession_titles {
11001: return &Apache::lonlocal::texthash(
11002: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11003: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11004: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11005: version => 'LON-CAPA version requirement',
1.138 raeburn 11006: excludedomain => 'Allow all, but exclude specific domains',
11007: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11008: primary => 'Primary (checked first)',
1.154 raeburn 11009: default => 'Default',
1.137 raeburn 11010: );
11011: }
11012:
1.152 raeburn 11013: sub id_for_thisdom {
11014: my (%servers) = @_;
11015: my %altids;
11016: foreach my $server (keys(%servers)) {
11017: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11018: if ($serverhome ne $server) {
11019: $altids{$serverhome} = $server;
11020: }
11021: }
11022: return %altids;
11023: }
11024:
1.150 raeburn 11025: sub count_servers {
11026: my ($currbalancer,%servers) = @_;
11027: my (@spares,$numspares);
11028: foreach my $lonhost (sort(keys(%servers))) {
11029: next if ($currbalancer eq $lonhost);
11030: push(@spares,$lonhost);
11031: }
11032: if ($currbalancer) {
11033: $numspares = scalar(@spares);
11034: } else {
11035: $numspares = scalar(@spares) - 1;
11036: }
11037: return ($numspares,@spares);
11038: }
11039:
11040: sub lonbalance_targets_js {
1.171 raeburn 11041: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11042: my $select = &mt('Select');
11043: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11044: if (ref($servers) eq 'HASH') {
11045: $alltargets = join("','",sort(keys(%{$servers})));
11046: my @homedoms;
11047: foreach my $server (sort(keys(%{$servers}))) {
11048: if (&Apache::lonnet::host_domain($server) eq $dom) {
11049: push(@homedoms,'1');
11050: } else {
11051: push(@homedoms,'0');
11052: }
11053: }
11054: $allishome = join("','",@homedoms);
11055: }
11056: if (ref($types) eq 'ARRAY') {
11057: if (@{$types} > 0) {
11058: @alltypes = @{$types};
11059: }
11060: }
11061: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11062: $allinsttypes = join("','",@alltypes);
1.171 raeburn 11063: my (%currbalancer,%currtargets,%currrules,%existing);
11064: if (ref($settings) eq 'HASH') {
11065: %existing = %{$settings};
11066: }
11067: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11068: \%currtargets,\%currrules);
1.210 raeburn 11069: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11070: return <<"END";
11071:
11072: <script type="text/javascript">
11073: // <![CDATA[
11074:
1.171 raeburn 11075: currBalancers = new Array('$balancers');
11076:
11077: function toggleTargets(balnum) {
11078: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11079: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11080: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11081: var prevbalancer = prevhostitem.value;
11082: var baltotal = document.getElementById('loadbalancing_total').value;
11083: prevhostitem.value = balancer;
11084: if (prevbalancer != '') {
11085: var prevIdx = currBalancers.indexOf(prevbalancer);
11086: if (prevIdx != -1) {
11087: currBalancers.splice(prevIdx,1);
11088: }
11089: }
1.150 raeburn 11090: if (balancer == '') {
1.171 raeburn 11091: hideSpares(balnum);
1.150 raeburn 11092: } else {
1.171 raeburn 11093: var currIdx = currBalancers.indexOf(balancer);
11094: if (currIdx == -1) {
11095: currBalancers.push(balancer);
11096: }
1.150 raeburn 11097: var homedoms = new Array('$allishome');
1.171 raeburn 11098: var ishomedom = homedoms[lonhostitem.selectedIndex];
11099: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11100: }
1.171 raeburn 11101: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11102: return;
11103: }
11104:
1.171 raeburn 11105: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11106: var alltargets = new Array('$alltargets');
11107: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11108: var offloadtypes = new Array('primary','default');
11109:
1.171 raeburn 11110: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11111: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11112:
1.151 raeburn 11113: for (var i=0; i<offloadtypes.length; i++) {
11114: var count = 0;
11115: for (var j=0; j<alltargets.length; j++) {
11116: if (alltargets[j] != balancer) {
1.171 raeburn 11117: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11118: item.value = alltargets[j];
11119: item.style.textAlign='left';
11120: item.style.textFace='normal';
11121: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11122: if (currBalancers.indexOf(alltargets[j]) == -1) {
11123: item.disabled = '';
11124: } else {
11125: item.disabled = 'disabled';
11126: item.checked = false;
11127: }
1.151 raeburn 11128: count ++;
11129: }
1.150 raeburn 11130: }
11131: }
1.151 raeburn 11132: for (var k=0; k<insttypes.length; k++) {
11133: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11134: if (ishomedom == 1) {
1.171 raeburn 11135: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11136: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11137: } else {
1.171 raeburn 11138: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11139: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11140: }
11141: } else {
1.171 raeburn 11142: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11143: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11144: }
1.151 raeburn 11145: if ((insttypes[k] != '_LC_external') &&
11146: ((insttypes[k] != '_LC_internetdom') ||
11147: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 11148: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11149: item.options.length = 0;
11150: item.options[0] = new Option("","",true,true);
1.210 raeburn 11151: var idx = 0;
1.151 raeburn 11152: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 11153: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11154: idx ++;
11155: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11156: }
11157: }
11158: }
11159: }
11160: return;
11161: }
11162:
1.171 raeburn 11163: function hideSpares(balnum) {
1.150 raeburn 11164: var alltargets = new Array('$alltargets');
11165: var insttypes = new Array('$allinsttypes');
11166: var offloadtypes = new Array('primary','default');
11167:
1.171 raeburn 11168: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11169: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11170:
11171: var total = alltargets.length - 1;
11172: for (var i=0; i<offloadtypes; i++) {
11173: for (var j=0; j<total; j++) {
1.171 raeburn 11174: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11175: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11176: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11177: }
1.150 raeburn 11178: }
11179: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11180: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11181: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11182: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11183: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11184: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11185: }
11186: }
11187: return;
11188: }
11189:
1.171 raeburn 11190: function checkOffloads(item,balnum,type) {
1.150 raeburn 11191: var alltargets = new Array('$alltargets');
11192: var offloadtypes = new Array('primary','default');
11193: if (item.checked) {
11194: var total = alltargets.length - 1;
11195: var other;
11196: if (type == offloadtypes[0]) {
1.151 raeburn 11197: other = offloadtypes[1];
1.150 raeburn 11198: } else {
1.151 raeburn 11199: other = offloadtypes[0];
1.150 raeburn 11200: }
11201: for (var i=0; i<total; i++) {
1.171 raeburn 11202: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11203: if (server == item.value) {
1.171 raeburn 11204: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11205: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11206: }
11207: }
11208: }
11209: }
11210: return;
11211: }
11212:
1.171 raeburn 11213: function singleServerToggle(balnum,type) {
11214: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11215: if (offloadtoSelIdx == 0) {
1.171 raeburn 11216: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11217: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11218:
11219: } else {
1.171 raeburn 11220: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11221: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11222: }
11223: return;
11224: }
11225:
1.171 raeburn 11226: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11227: if (type == '_LC_external') {
1.171 raeburn 11228: return;
1.150 raeburn 11229: }
1.171 raeburn 11230: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11231: for (var i=0; i<typesRules.length; i++) {
11232: if (formname.elements[typesRules[i]].checked) {
11233: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11234: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11235: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11236: } else {
1.171 raeburn 11237: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11238: }
11239: }
11240: }
11241: return;
11242: }
11243:
11244: function balancerDeleteChange(balnum) {
11245: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11246: var baltotal = document.getElementById('loadbalancing_total').value;
11247: var addtarget;
11248: var removetarget;
11249: var action = 'delete';
11250: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11251: var lonhost = hostitem.value;
11252: var currIdx = currBalancers.indexOf(lonhost);
11253: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11254: if (currIdx != -1) {
11255: currBalancers.splice(currIdx,1);
11256: }
11257: addtarget = lonhost;
11258: } else {
11259: if (currIdx == -1) {
11260: currBalancers.push(lonhost);
11261: }
11262: removetarget = lonhost;
11263: action = 'undelete';
11264: }
11265: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11266: }
11267: return;
11268: }
11269:
11270: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11271: if (baltotal > 1) {
11272: var offloadtypes = new Array('primary','default');
11273: var alltargets = new Array('$alltargets');
11274: var insttypes = new Array('$allinsttypes');
11275: for (var i=0; i<baltotal; i++) {
11276: if (i != balnum) {
11277: for (var j=0; j<offloadtypes.length; j++) {
11278: var total = alltargets.length - 1;
11279: for (var k=0; k<total; k++) {
11280: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11281: var server = serveritem.value;
11282: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11283: if (server == addtarget) {
11284: serveritem.disabled = '';
11285: }
11286: }
11287: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11288: if (server == removetarget) {
11289: serveritem.disabled = 'disabled';
11290: serveritem.checked = false;
11291: }
11292: }
11293: }
11294: }
11295: for (var j=0; j<insttypes.length; j++) {
11296: if (insttypes[j] != '_LC_external') {
11297: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11298: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11299: var currSel = singleserver.selectedIndex;
11300: var currVal = singleserver.options[currSel].value;
11301: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11302: var numoptions = singleserver.options.length;
11303: var needsnew = 1;
11304: for (var k=0; k<numoptions; k++) {
11305: if (singleserver.options[k] == addtarget) {
11306: needsnew = 0;
11307: break;
11308: }
11309: }
11310: if (needsnew == 1) {
11311: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11312: }
11313: }
11314: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11315: singleserver.options.length = 0;
11316: if ((currVal) && (currVal != removetarget)) {
11317: singleserver.options[0] = new Option("","",false,false);
11318: } else {
11319: singleserver.options[0] = new Option("","",true,true);
11320: }
11321: var idx = 0;
11322: for (var m=0; m<alltargets.length; m++) {
11323: if (currBalancers.indexOf(alltargets[m]) == -1) {
11324: idx ++;
11325: if (currVal == alltargets[m]) {
11326: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11327: } else {
11328: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11329: }
11330: }
11331: }
11332: }
11333: }
11334: }
11335: }
1.150 raeburn 11336: }
11337: }
11338: }
11339: return;
11340: }
11341:
1.152 raeburn 11342: // ]]>
11343: </script>
11344:
11345: END
11346: }
11347:
11348: sub new_spares_js {
11349: my @sparestypes = ('primary','default');
11350: my $types = join("','",@sparestypes);
11351: my $select = &mt('Select');
11352: return <<"END";
11353:
11354: <script type="text/javascript">
11355: // <![CDATA[
11356:
11357: function updateNewSpares(formname,lonhost) {
11358: var types = new Array('$types');
11359: var include = new Array();
11360: var exclude = new Array();
11361: for (var i=0; i<types.length; i++) {
11362: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11363: for (var j=0; j<spareboxes.length; j++) {
11364: if (formname.elements[spareboxes[j]].checked) {
11365: exclude.push(formname.elements[spareboxes[j]].value);
11366: } else {
11367: include.push(formname.elements[spareboxes[j]].value);
11368: }
11369: }
11370: }
11371: for (var i=0; i<types.length; i++) {
11372: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11373: var selIdx = newSpare.selectedIndex;
11374: var currnew = newSpare.options[selIdx].value;
11375: var okSpares = new Array();
11376: for (var j=0; j<newSpare.options.length; j++) {
11377: var possible = newSpare.options[j].value;
11378: if (possible != '') {
11379: if (exclude.indexOf(possible) == -1) {
11380: okSpares.push(possible);
11381: } else {
11382: if (currnew == possible) {
11383: selIdx = 0;
11384: }
11385: }
11386: }
11387: }
11388: for (var k=0; k<include.length; k++) {
11389: if (okSpares.indexOf(include[k]) == -1) {
11390: okSpares.push(include[k]);
11391: }
11392: }
11393: okSpares.sort();
11394: newSpare.options.length = 0;
11395: if (selIdx == 0) {
11396: newSpare.options[0] = new Option("$select","",true,true);
11397: } else {
11398: newSpare.options[0] = new Option("$select","",false,false);
11399: }
11400: for (var m=0; m<okSpares.length; m++) {
11401: var idx = m+1;
11402: var selThis = 0;
11403: if (selIdx != 0) {
11404: if (okSpares[m] == currnew) {
11405: selThis = 1;
11406: }
11407: }
11408: if (selThis == 1) {
11409: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11410: } else {
11411: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11412: }
11413: }
11414: }
11415: return;
11416: }
11417:
11418: function checkNewSpares(lonhost,type) {
11419: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11420: var chosen = newSpare.options[newSpare.selectedIndex].value;
11421: if (chosen != '') {
11422: var othertype;
11423: var othernewSpare;
11424: if (type == 'primary') {
11425: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11426: }
11427: if (type == 'default') {
11428: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11429: }
11430: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11431: othernewSpare.selectedIndex = 0;
11432: }
11433: }
11434: return;
11435: }
11436:
11437: // ]]>
11438: </script>
11439:
11440: END
11441:
11442: }
11443:
11444: sub common_domprefs_js {
11445: return <<"END";
11446:
11447: <script type="text/javascript">
11448: // <![CDATA[
11449:
1.150 raeburn 11450: function getIndicesByName(formname,item) {
1.152 raeburn 11451: var group = new Array();
1.150 raeburn 11452: for (var i=0;i<formname.elements.length;i++) {
11453: if (formname.elements[i].name == item) {
1.152 raeburn 11454: group.push(formname.elements[i].id);
1.150 raeburn 11455: }
11456: }
1.152 raeburn 11457: return group;
1.150 raeburn 11458: }
11459:
11460: // ]]>
11461: </script>
11462:
11463: END
1.152 raeburn 11464:
1.150 raeburn 11465: }
11466:
1.165 raeburn 11467: sub recaptcha_js {
11468: my %lt = &captcha_phrases();
11469: return <<"END";
11470:
11471: <script type="text/javascript">
11472: // <![CDATA[
11473:
11474: function updateCaptcha(caller,context) {
11475: var privitem;
11476: var pubitem;
11477: var privtext;
11478: var pubtext;
11479: if (document.getElementById(context+'_recaptchapub')) {
11480: pubitem = document.getElementById(context+'_recaptchapub');
11481: } else {
11482: return;
11483: }
11484: if (document.getElementById(context+'_recaptchapriv')) {
11485: privitem = document.getElementById(context+'_recaptchapriv');
11486: } else {
11487: return;
11488: }
11489: if (document.getElementById(context+'_recaptchapubtxt')) {
11490: pubtext = document.getElementById(context+'_recaptchapubtxt');
11491: } else {
11492: return;
11493: }
11494: if (document.getElementById(context+'_recaptchaprivtxt')) {
11495: privtext = document.getElementById(context+'_recaptchaprivtxt');
11496: } else {
11497: return;
11498: }
11499: if (caller.checked) {
11500: if (caller.value == 'recaptcha') {
11501: pubitem.type = 'text';
11502: privitem.type = 'text';
11503: pubitem.size = '40';
11504: privitem.size = '40';
11505: pubtext.innerHTML = "$lt{'pub'}";
11506: privtext.innerHTML = "$lt{'priv'}";
11507: } else {
11508: pubitem.type = 'hidden';
11509: privitem.type = 'hidden';
11510: pubtext.innerHTML = '';
11511: privtext.innerHTML = '';
11512: }
11513: }
11514: return;
11515: }
11516:
11517: // ]]>
11518: </script>
11519:
11520: END
11521:
11522: }
11523:
1.236 raeburn 11524: sub toggle_display_js {
1.192 raeburn 11525: return <<"END";
11526:
11527: <script type="text/javascript">
11528: // <![CDATA[
11529:
1.236 raeburn 11530: function toggleDisplay(domForm,caller) {
11531: if (document.getElementById(caller)) {
11532: var divitem = document.getElementById(caller);
11533: var optionsElement = domForm.coursecredits;
11534: if (caller == 'emailoptions') {
11535: optionsElement = domForm.cancreate_email;
11536: }
11537: if (optionsElement.length) {
1.192 raeburn 11538: var currval;
1.236 raeburn 11539: for (var i=0; i<optionsElement.length; i++) {
11540: if (optionsElement[i].checked) {
11541: currval = optionsElement[i].value;
1.192 raeburn 11542: }
11543: }
11544: if (currval == 1) {
1.236 raeburn 11545: divitem.style.display = 'block';
1.192 raeburn 11546: } else {
1.236 raeburn 11547: divitem.style.display = 'none';
1.192 raeburn 11548: }
11549: }
11550: }
11551: return;
11552: }
11553:
11554: // ]]>
11555: </script>
11556:
11557: END
11558:
11559: }
11560:
1.165 raeburn 11561: sub captcha_phrases {
11562: return &Apache::lonlocal::texthash (
11563: priv => 'Private key',
11564: pub => 'Public key',
11565: original => 'original (CAPTCHA)',
11566: recaptcha => 'successor (ReCAPTCHA)',
11567: notused => 'unused',
11568: );
11569: }
11570:
1.205 raeburn 11571: sub devalidate_remote_domconfs {
1.212 raeburn 11572: my ($dom,$cachekeys) = @_;
11573: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 11574: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11575: my %thismachine;
11576: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 11577: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 11578: if (keys(%servers) > 1) {
11579: foreach my $server (keys(%servers)) {
11580: next if ($thismachine{$server});
1.212 raeburn 11581: my @cached;
11582: foreach my $name (@posscached) {
11583: if ($cachekeys->{$name}) {
11584: push(@cached,&escape($name).':'.&escape($dom));
11585: }
11586: }
11587: if (@cached) {
11588: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11589: }
1.205 raeburn 11590: }
11591: }
11592: return;
11593: }
11594:
1.3 raeburn 11595: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>