Annotation of loncom/interface/domainprefs.pm, revision 1.255
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.255 ! raeburn 4: # $Id: domainprefs.pm,v 1.254 2014/10/06 00:48:39 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
216: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 217: 'coursedefaults','usersessions','loadbalancing',
1.236 raeburn 218: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 222: 'requestcourses','requestauthor','coursecategories',
223: 'serverstatuses','helpsettings',
1.231 raeburn 224: 'coursedefaults','selfenrollment','usersessions');
1.171 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.230 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
253: col2 => 'Value'}],
1.230 raeburn 254: print => \&print_login,
255: modify => \&modify_login,
1.30 raeburn 256: },
1.43 raeburn 257: 'defaults' =>
1.236 raeburn 258: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 259: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 260: header => [{col1 => 'Setting',
1.236 raeburn 261: col2 => 'Value'},
262: {col1 => 'Institutional user types',
263: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 264: print => \&print_defaults,
265: modify => \&modify_defaults,
1.43 raeburn 266: },
1.30 raeburn 267: 'quotas' =>
1.197 raeburn 268: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 269: help => 'Domain_Configuration_Quotas',
1.77 raeburn 270: header => [{col1 => 'User affiliation',
1.72 raeburn 271: col2 => 'Available tools',
1.213 raeburn 272: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 273: print => \&print_quotas,
274: modify => \&modify_quotas,
1.30 raeburn 275: },
276: 'autoenroll' =>
277: { text => 'Auto-enrollment settings',
1.67 raeburn 278: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 279: header => [{col1 => 'Configuration setting',
280: col2 => 'Value(s)'}],
1.230 raeburn 281: print => \&print_autoenroll,
282: modify => \&modify_autoenroll,
1.30 raeburn 283: },
284: 'autoupdate' =>
285: { text => 'Auto-update settings',
1.67 raeburn 286: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 287: header => [{col1 => 'Setting',
288: col2 => 'Value',},
1.131 raeburn 289: {col1 => 'Setting',
290: col2 => 'Affiliation'},
1.43 raeburn 291: {col1 => 'User population',
1.227 bisitz 292: col2 => 'Updatable user data'}],
1.230 raeburn 293: print => \&print_autoupdate,
294: modify => \&modify_autoupdate,
1.30 raeburn 295: },
1.125 raeburn 296: 'autocreate' =>
297: { text => 'Auto-course creation settings',
298: help => 'Domain_Configuration_Auto_Creation',
299: header => [{col1 => 'Configuration Setting',
300: col2 => 'Value',}],
1.230 raeburn 301: print => \&print_autocreate,
302: modify => \&modify_autocreate,
1.125 raeburn 303: },
1.30 raeburn 304: 'directorysrch' =>
305: { text => 'Institutional directory searches',
1.67 raeburn 306: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 307: header => [{col1 => 'Setting',
308: col2 => 'Value',}],
1.230 raeburn 309: print => \&print_directorysrch,
310: modify => \&modify_directorysrch,
1.30 raeburn 311: },
312: 'contacts' =>
313: { text => 'Contact Information',
1.67 raeburn 314: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 315: header => [{col1 => 'Setting',
316: col2 => 'Value',}],
1.230 raeburn 317: print => \&print_contacts,
318: modify => \&modify_contacts,
1.30 raeburn 319: },
320: 'usercreation' =>
321: { text => 'User creation',
1.67 raeburn 322: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 323: header => [{col1 => 'Format rule type',
324: col2 => 'Format rules in force'},
1.34 raeburn 325: {col1 => 'User account creation',
326: col2 => 'Usernames which may be created',},
1.30 raeburn 327: {col1 => 'Context',
1.43 raeburn 328: col2 => 'Assignable authentication types'}],
1.230 raeburn 329: print => \&print_usercreation,
330: modify => \&modify_usercreation,
1.30 raeburn 331: },
1.224 raeburn 332: 'selfcreation' =>
333: { text => 'Users self-creating accounts',
334: help => 'Domain_Configuration_Self_Creation',
335: header => [{col1 => 'Self-creation with institutional username',
336: col2 => 'Enabled?'},
337: {col1 => 'Institutional user type (login/SSO self-creation)',
338: col2 => 'Information user can enter'},
339: {col1 => 'Self-creation with e-mail as username',
340: col2 => 'Settings'}],
1.230 raeburn 341: print => \&print_selfcreation,
342: modify => \&modify_selfcreation,
1.224 raeburn 343: },
1.69 raeburn 344: 'usermodification' =>
1.33 raeburn 345: { text => 'User modification',
1.67 raeburn 346: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 347: header => [{col1 => 'Target user has role',
1.227 bisitz 348: col2 => 'User information updatable in author context'},
1.33 raeburn 349: {col1 => 'Target user has role',
1.227 bisitz 350: col2 => 'User information updatable in course context'}],
1.230 raeburn 351: print => \&print_usermodification,
352: modify => \&modify_usermodification,
1.33 raeburn 353: },
1.69 raeburn 354: 'scantron' =>
1.95 www 355: { text => 'Bubblesheet format file',
1.67 raeburn 356: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 357: header => [ {col1 => 'Item',
358: col2 => '',
359: }],
1.230 raeburn 360: print => \&print_scantron,
361: modify => \&modify_scantron,
1.46 raeburn 362: },
1.86 raeburn 363: 'requestcourses' =>
364: {text => 'Request creation of courses',
365: help => 'Domain_Configuration_Request_Courses',
366: header => [{col1 => 'User affiliation',
1.102 raeburn 367: col2 => 'Availability/Processing of requests',},
368: {col1 => 'Setting',
1.216 raeburn 369: col2 => 'Value'},
370: {col1 => 'Available textbooks',
1.235 raeburn 371: col2 => ''},
1.242 raeburn 372: {col1 => 'Available templates',
373: col2 => ''},
1.235 raeburn 374: {col1 => 'Validation (not official courses)',
375: col2 => 'Value'},],
1.230 raeburn 376: print => \&print_quotas,
377: modify => \&modify_quotas,
1.86 raeburn 378: },
1.163 raeburn 379: 'requestauthor' =>
1.223 bisitz 380: {text => 'Request Authoring Space',
1.163 raeburn 381: help => 'Domain_Configuration_Request_Author',
382: header => [{col1 => 'User affiliation',
383: col2 => 'Availability/Processing of requests',},
384: {col1 => 'Setting',
385: col2 => 'Value'}],
1.230 raeburn 386: print => \&print_quotas,
387: modify => \&modify_quotas,
1.163 raeburn 388: },
1.69 raeburn 389: 'coursecategories' =>
1.120 raeburn 390: { text => 'Cataloging of courses/communities',
1.67 raeburn 391: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 392: header => [{col1 => 'Catalog type/availability',
393: col2 => '',},
394: {col1 => 'Category settings for standard catalog',
1.57 raeburn 395: col2 => '',},
396: {col1 => 'Categories',
397: col2 => '',
398: }],
1.230 raeburn 399: print => \&print_coursecategories,
400: modify => \&modify_coursecategories,
1.69 raeburn 401: },
402: 'serverstatuses' =>
1.77 raeburn 403: {text => 'Access to server status pages',
1.69 raeburn 404: help => 'Domain_Configuration_Server_Status',
405: header => [{col1 => 'Status Page',
406: col2 => 'Other named users',
407: col3 => 'Specific IPs',
408: }],
1.230 raeburn 409: print => \&print_serverstatuses,
410: modify => \&modify_serverstatuses,
1.69 raeburn 411: },
1.118 jms 412: 'helpsettings' =>
413: {text => 'Help page settings',
414: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 415: header => [{col1 => 'Help Settings (logged-in users)',
416: col2 => 'Value'}],
1.230 raeburn 417: print => \&print_helpsettings,
418: modify => \&modify_helpsettings,
1.118 jms 419: },
1.121 raeburn 420: 'coursedefaults' =>
421: {text => 'Course/Community defaults',
422: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 423: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
424: col2 => 'Value',},
425: {col1 => 'Defaults which can be overridden for each course by a DC',
426: col2 => 'Value',},],
1.230 raeburn 427: print => \&print_coursedefaults,
428: modify => \&modify_coursedefaults,
1.121 raeburn 429: },
1.231 raeburn 430: 'selfenrollment' =>
431: {text => 'Self-enrollment in Course/Community',
432: help => 'Domain_Configuration_Selfenrollment',
433: header => [{col1 => 'Configuration Rights',
434: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
435: {col1 => 'Defaults',
436: col2 => 'Value'},
437: {col1 => 'Self-enrollment validation (optional)',
438: col2 => 'Value'},],
439: print => \&print_selfenrollment,
440: modify => \&modify_selfenrollment,
441: },
1.120 raeburn 442: 'privacy' =>
443: {text => 'User Privacy',
444: help => 'Domain_Configuration_User_Privacy',
445: header => [{col1 => 'Setting',
446: col2 => 'Value',}],
1.230 raeburn 447: print => \&print_privacy,
448: modify => \&modify_privacy,
1.120 raeburn 449: },
1.141 raeburn 450: 'usersessions' =>
1.145 raeburn 451: {text => 'User session hosting/offloading',
1.137 raeburn 452: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 453: header => [{col1 => 'Domain server',
454: col2 => 'Servers to offload sessions to when busy'},
455: {col1 => 'Hosting of users from other domains',
1.137 raeburn 456: col2 => 'Rules'},
457: {col1 => "Hosting domain's own users elsewhere",
458: col2 => 'Rules'}],
1.230 raeburn 459: print => \&print_usersessions,
460: modify => \&modify_usersessions,
1.137 raeburn 461: },
1.150 raeburn 462: 'loadbalancing' =>
1.185 raeburn 463: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 464: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 465: header => [{col1 => 'Balancers',
1.150 raeburn 466: col2 => 'Default destinations',
1.183 bisitz 467: col3 => 'User affiliation',
1.150 raeburn 468: col4 => 'Overrides'},
469: ],
1.230 raeburn 470: print => \&print_loadbalancing,
471: modify => \&modify_loadbalancing,
1.150 raeburn 472: },
1.3 raeburn 473: );
1.110 raeburn 474: if (keys(%servers) > 1) {
475: $prefs{'login'} = { text => 'Log-in page options',
476: help => 'Domain_Configuration_Login_Page',
477: header => [{col1 => 'Log-in Service',
478: col2 => 'Server Setting',},
479: {col1 => 'Log-in Page Items',
1.168 raeburn 480: col2 => ''},
481: {col1 => 'Log-in Help',
482: col2 => 'Value'}],
1.230 raeburn 483: print => \&print_login,
484: modify => \&modify_login,
1.110 raeburn 485: };
486: }
1.174 foxr 487:
1.6 raeburn 488: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 489: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 490: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 491: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 492: text=>"Settings to display/modify"});
1.9 raeburn 493: my $confname = $dom.'-domainconfig';
1.174 foxr 494:
1.3 raeburn 495: if ($phase eq 'process') {
1.212 raeburn 496: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
497: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 498: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 499: $r->rflush();
1.212 raeburn 500: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 501: }
1.30 raeburn 502: } elsif ($phase eq 'display') {
1.192 raeburn 503: my $js = &recaptcha_js().
1.236 raeburn 504: &toggle_display_js();
1.171 raeburn 505: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 506: my ($othertitle,$usertypes,$types) =
507: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 508: $js .= &lonbalance_targets_js($dom,$types,\%servers,
509: $domconfig{'loadbalancing'}).
1.170 raeburn 510: &new_spares_js().
511: &common_domprefs_js().
512: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 513: }
1.216 raeburn 514: if (grep(/^requestcourses$/,@actions)) {
515: my $javascript_validations;
516: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
517: $js .= <<END;
518: <script type="text/javascript">
519: $javascript_validations
520: </script>
521: $coursebrowserjs
522: END
523: }
1.150 raeburn 524: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 525: } else {
1.180 raeburn 526: # check if domconfig user exists for the domain.
527: my $servadm = $r->dir_config('lonAdmEMail');
528: my ($configuserok,$author_ok,$switchserver) =
529: &config_check($dom,$confname,$servadm);
530: unless ($configuserok eq 'ok') {
1.181 raeburn 531: &Apache::lonconfigsettings::print_header($r,$phase,$context);
532: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 533: $confname).
1.181 raeburn 534: '<br />'
535: );
1.180 raeburn 536: if ($switchserver) {
1.181 raeburn 537: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
538: '<br />'.
539: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
540: '<br />'.
541: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
542: '<br />'.
543: &mt('To do that now, use the following link: [_1]',$switchserver)
544: );
545: } else {
546: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
547: '<br />'.
548: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
549: );
1.180 raeburn 550: }
551: $r->print(&Apache::loncommon::end_page());
552: return OK;
553: }
1.21 raeburn 554: if (keys(%domconfig) == 0) {
555: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 556: my @ids=&Apache::lonnet::current_machine_ids();
557: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 558: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 559: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 560: my $custom_img_count = 0;
561: foreach my $img (@loginimages) {
562: if ($designhash{$dom.'.login.'.$img} ne '') {
563: $custom_img_count ++;
564: }
565: }
566: foreach my $role (@roles) {
567: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
568: $custom_img_count ++;
569: }
570: }
571: if ($custom_img_count > 0) {
1.94 raeburn 572: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 573: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 574: $r->print(
575: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
576: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
577: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
578: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
579: if ($switch_server) {
1.30 raeburn 580: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 581: }
1.91 raeburn 582: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 583: return OK;
584: }
585: }
586: }
1.91 raeburn 587: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 588: }
589: return OK;
590: }
591:
592: sub process_changes {
1.205 raeburn 593: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 594: my %domconfig;
595: if (ref($values) eq 'HASH') {
596: %domconfig = %{$values};
597: }
1.3 raeburn 598: my $output;
599: if ($action eq 'login') {
1.205 raeburn 600: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 601: } elsif ($action eq 'rolecolors') {
1.9 raeburn 602: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 603: $lastactref,%domconfig);
1.3 raeburn 604: } elsif ($action eq 'quotas') {
1.216 raeburn 605: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 606: } elsif ($action eq 'autoenroll') {
1.205 raeburn 607: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 608: } elsif ($action eq 'autoupdate') {
609: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 610: } elsif ($action eq 'autocreate') {
611: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 612: } elsif ($action eq 'directorysrch') {
613: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 614: } elsif ($action eq 'usercreation') {
1.28 raeburn 615: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 616: } elsif ($action eq 'selfcreation') {
617: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 618: } elsif ($action eq 'usermodification') {
619: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 620: } elsif ($action eq 'contacts') {
1.205 raeburn 621: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 622: } elsif ($action eq 'defaults') {
1.212 raeburn 623: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 624: } elsif ($action eq 'scantron') {
1.205 raeburn 625: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 626: } elsif ($action eq 'coursecategories') {
1.239 raeburn 627: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 628: } elsif ($action eq 'serverstatuses') {
629: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 630: } elsif ($action eq 'requestcourses') {
1.216 raeburn 631: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 632: } elsif ($action eq 'requestauthor') {
1.216 raeburn 633: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 634: } elsif ($action eq 'helpsettings') {
1.122 jms 635: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 636: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 637: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 638: } elsif ($action eq 'selfenrollment') {
639: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 640: } elsif ($action eq 'usersessions') {
1.212 raeburn 641: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 642: } elsif ($action eq 'loadbalancing') {
643: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 644: }
645: return $output;
646: }
647:
648: sub print_config_box {
1.9 raeburn 649: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 650: my $rowtotal = 0;
1.49 raeburn 651: my $output;
652: if ($action eq 'coursecategories') {
653: $output = &coursecategories_javascript($settings);
1.236 raeburn 654: } elsif ($action eq 'defaults') {
655: $output = &defaults_javascript($settings);
1.91 raeburn 656: }
1.236 raeburn 657: $output .=
1.30 raeburn 658: '<table class="LC_nested_outer">
1.3 raeburn 659: <tr>
1.66 raeburn 660: <th align="left" valign="middle"><span class="LC_nobreak">'.
661: &mt($item->{text}).' '.
662: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
663: '</tr>';
1.30 raeburn 664: $rowtotal ++;
1.110 raeburn 665: my $numheaders = 1;
666: if (ref($item->{'header'}) eq 'ARRAY') {
667: $numheaders = scalar(@{$item->{'header'}});
668: }
669: if ($numheaders > 1) {
1.64 raeburn 670: my $colspan = '';
1.145 raeburn 671: my $rightcolspan = '';
1.238 raeburn 672: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.168 raeburn 673: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 674: $colspan = ' colspan="2"';
675: }
1.145 raeburn 676: if ($action eq 'usersessions') {
677: $rightcolspan = ' colspan="3"';
678: }
1.30 raeburn 679: $output .= '
1.3 raeburn 680: <tr>
681: <td>
682: <table class="LC_nested">
683: <tr class="LC_info_row">
1.59 bisitz 684: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 685: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 686: </tr>';
1.69 raeburn 687: $rowtotal ++;
1.230 raeburn 688: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 689: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.230 raeburn 690: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
691: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 692: } elsif ($action eq 'coursecategories') {
1.230 raeburn 693: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 694: } elsif ($action eq 'login') {
1.168 raeburn 695: if ($numheaders == 3) {
696: $colspan = ' colspan="2"';
697: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
698: } else {
699: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
700: }
1.230 raeburn 701: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 702: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 703: } elsif ($action eq 'rolecolors') {
1.30 raeburn 704: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 705: }
1.30 raeburn 706: $output .= '
1.6 raeburn 707: </table>
708: </td>
709: </tr>
710: <tr>
711: <td>
712: <table class="LC_nested">
713: <tr class="LC_info_row">
1.230 raeburn 714: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 715: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 716: </tr>';
717: $rowtotal ++;
1.230 raeburn 718: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
719: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.238 raeburn 720: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
721: if ($action eq 'coursecategories') {
722: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
723: $colspan = ' colspan="2"';
724: } else {
725: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
726: }
727: $output .= '
1.63 raeburn 728: </table>
729: </td>
730: </tr>
731: <tr>
732: <td>
733: <table class="LC_nested">
734: <tr class="LC_info_row">
735: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 736: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 737: </tr>'."\n";
738: if ($action eq 'coursecategories') {
739: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
740: } else {
741: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
742: }
1.63 raeburn 743: $rowtotal ++;
1.236 raeburn 744: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
745: ($action eq 'defaults')) {
1.230 raeburn 746: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 747: } elsif ($action eq 'login') {
1.168 raeburn 748: if ($numheaders == 3) {
749: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
757: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 758: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 759: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
760: $rowtotal ++;
761: } else {
762: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
763: }
1.102 raeburn 764: } elsif ($action eq 'requestcourses') {
1.247 raeburn 765: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
766: $rowtotal ++;
767: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 768: </table>
769: </td>
770: </tr>
771: <tr>
772: <td>
773: <table class="LC_nested">
774: <tr class="LC_info_row">
775: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
776: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 777: &textbookcourses_javascript($settings).
778: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
779: </table>
780: </td>
781: </tr>
782: <tr>
783: <td>
784: <table class="LC_nested">
785: <tr class="LC_info_row">
786: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
787: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
788: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 789: </table>
790: </td>
791: </tr>
792: <tr>
793: <td>
794: <table class="LC_nested">
795: <tr class="LC_info_row">
1.242 raeburn 796: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
797: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 798: </tr>'.
799: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 800: } elsif ($action eq 'requestauthor') {
801: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 802: $rowtotal ++;
1.122 jms 803: } elsif ($action eq 'rolecolors') {
1.30 raeburn 804: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 805: </table>
806: </td>
807: </tr>
808: <tr>
809: <td>
810: <table class="LC_nested">
811: <tr class="LC_info_row">
1.69 raeburn 812: <td class="LC_left_item"'.$colspan.' valign="top">'.
813: &mt($item->{'header'}->[2]->{'col1'}).'</td>
814: <td class="LC_right_item" valign="top">'.
815: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 816: </tr>'.
1.30 raeburn 817: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 818: </table>
819: </td>
820: </tr>
821: <tr>
822: <td>
823: <table class="LC_nested">
824: <tr class="LC_info_row">
1.59 bisitz 825: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
826: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 827: </tr>'.
1.30 raeburn 828: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
829: $rowtotal += 2;
1.6 raeburn 830: }
1.3 raeburn 831: } else {
1.30 raeburn 832: $output .= '
1.3 raeburn 833: <tr>
834: <td>
835: <table class="LC_nested">
1.30 raeburn 836: <tr class="LC_info_row">';
1.24 raeburn 837: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 838: $output .= '
1.59 bisitz 839: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 840: } elsif ($action eq 'serverstatuses') {
841: $output .= '
842: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
843: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
844:
1.6 raeburn 845: } else {
1.30 raeburn 846: $output .= '
1.69 raeburn 847: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
848: }
1.72 raeburn 849: if (defined($item->{'header'}->[0]->{'col3'})) {
850: $output .= '<td class="LC_left_item" valign="top">'.
851: &mt($item->{'header'}->[0]->{'col2'});
852: if ($action eq 'serverstatuses') {
853: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
854: }
1.69 raeburn 855: } else {
856: $output .= '<td class="LC_right_item" valign="top">'.
857: &mt($item->{'header'}->[0]->{'col2'});
858: }
859: $output .= '</td>';
860: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 861: if (defined($item->{'header'}->[0]->{'col4'})) {
862: $output .= '<td class="LC_left_item" valign="top">'.
863: &mt($item->{'header'}->[0]->{'col3'});
864: } else {
865: $output .= '<td class="LC_right_item" valign="top">'.
866: &mt($item->{'header'}->[0]->{'col3'});
867: }
1.69 raeburn 868: if ($action eq 'serverstatuses') {
869: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
870: }
871: $output .= '</td>';
1.6 raeburn 872: }
1.150 raeburn 873: if ($item->{'header'}->[0]->{'col4'}) {
874: $output .= '<td class="LC_right_item" valign="top">'.
875: &mt($item->{'header'}->[0]->{'col4'});
876: }
1.69 raeburn 877: $output .= '</tr>';
1.48 raeburn 878: $rowtotal ++;
1.168 raeburn 879: if ($action eq 'quotas') {
1.86 raeburn 880: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 881: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.236 raeburn 882: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.230 raeburn 883: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 884: } elsif ($action eq 'scantron') {
885: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 886: } elsif ($action eq 'helpsettings') {
1.168 raeburn 887: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 888: }
1.3 raeburn 889: }
1.30 raeburn 890: $output .= '
1.3 raeburn 891: </table>
892: </td>
893: </tr>
1.30 raeburn 894: </table><br />';
895: return ($output,$rowtotal);
1.1 raeburn 896: }
897:
1.3 raeburn 898: sub print_login {
1.168 raeburn 899: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 900: my ($css_class,$datatable);
1.6 raeburn 901: my %choices = &login_choices();
1.110 raeburn 902:
1.168 raeburn 903: if ($caller eq 'service') {
1.149 raeburn 904: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 905: my $choice = $choices{'disallowlogin'};
906: $css_class = ' class="LC_odd_row"';
1.128 raeburn 907: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 908: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 909: '<th>'.$choices{'server'}.'</th>'.
910: '<th>'.$choices{'serverpath'}.'</th>'.
911: '<th>'.$choices{'custompath'}.'</th>'.
912: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 913: my %disallowed;
914: if (ref($settings) eq 'HASH') {
915: if (ref($settings->{'loginvia'}) eq 'HASH') {
916: %disallowed = %{$settings->{'loginvia'}};
917: }
918: }
919: foreach my $lonhost (sort(keys(%servers))) {
920: my $direct = 'selected="selected"';
1.128 raeburn 921: if (ref($disallowed{$lonhost}) eq 'HASH') {
922: if ($disallowed{$lonhost}{'server'} ne '') {
923: $direct = '';
924: }
1.110 raeburn 925: }
1.115 raeburn 926: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 927: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 928: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
929: '</option>';
1.184 raeburn 930: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 931: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 932: my $selected = '';
1.128 raeburn 933: if (ref($disallowed{$lonhost}) eq 'HASH') {
934: if ($hostid eq $disallowed{$lonhost}{'server'}) {
935: $selected = 'selected="selected"';
936: }
1.110 raeburn 937: }
938: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
939: $servers{$hostid}.'</option>';
940: }
1.128 raeburn 941: $datatable .= '</select></td>'.
942: '<td><select name="'.$lonhost.'_serverpath">';
943: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
944: my $pathname = $path;
945: if ($path eq 'custom') {
946: $pathname = &mt('Custom Path').' ->';
947: }
948: my $selected = '';
949: if (ref($disallowed{$lonhost}) eq 'HASH') {
950: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
951: $selected = 'selected="selected"';
952: }
953: } elsif ($path eq '') {
954: $selected = 'selected="selected"';
955: }
956: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
957: }
958: $datatable .= '</select></td>';
959: my ($custom,$exempt);
960: if (ref($disallowed{$lonhost}) eq 'HASH') {
961: $custom = $disallowed{$lonhost}{'custompath'};
962: $exempt = $disallowed{$lonhost}{'exempt'};
963: }
964: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
965: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
966: '</tr>';
1.110 raeburn 967: }
968: $datatable .= '</table></td></tr>';
969: return $datatable;
1.168 raeburn 970: } elsif ($caller eq 'page') {
971: my %defaultchecked = (
972: 'coursecatalog' => 'on',
1.188 raeburn 973: 'helpdesk' => 'on',
1.168 raeburn 974: 'adminmail' => 'off',
975: 'newuser' => 'off',
976: );
1.188 raeburn 977: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 978: my (%checkedon,%checkedoff);
1.42 raeburn 979: foreach my $item (@toggles) {
1.168 raeburn 980: if ($defaultchecked{$item} eq 'on') {
981: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 982: $checkedoff{$item} = ' ';
1.168 raeburn 983: } elsif ($defaultchecked{$item} eq 'off') {
984: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 985: $checkedon{$item} = ' ';
986: }
1.1 raeburn 987: }
1.168 raeburn 988: my @images = ('img','logo','domlogo','login');
989: my @logintext = ('textcol','bgcol');
990: my @bgs = ('pgbg','mainbg','sidebg');
991: my @links = ('link','alink','vlink');
992: my %designhash = &Apache::loncommon::get_domainconf($dom);
993: my %defaultdesign = %Apache::loncommon::defaultdesign;
994: my (%is_custom,%designs);
995: my %defaults = (
996: font => $defaultdesign{'login.font'},
997: );
1.6 raeburn 998: foreach my $item (@images) {
1.168 raeburn 999: $defaults{$item} = $defaultdesign{'login.'.$item};
1000: $defaults{'showlogo'}{$item} = 1;
1001: }
1002: foreach my $item (@bgs) {
1003: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1004: }
1.41 raeburn 1005: foreach my $item (@logintext) {
1.168 raeburn 1006: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1007: }
1.168 raeburn 1008: foreach my $item (@links) {
1009: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1010: }
1.168 raeburn 1011: if (ref($settings) eq 'HASH') {
1012: foreach my $item (@toggles) {
1013: if ($settings->{$item} eq '1') {
1014: $checkedon{$item} = ' checked="checked" ';
1015: $checkedoff{$item} = ' ';
1016: } elsif ($settings->{$item} eq '0') {
1017: $checkedoff{$item} = ' checked="checked" ';
1018: $checkedon{$item} = ' ';
1019: }
1020: }
1021: foreach my $item (@images) {
1022: if (defined($settings->{$item})) {
1023: $designs{$item} = $settings->{$item};
1024: $is_custom{$item} = 1;
1025: }
1026: if (defined($settings->{'showlogo'}{$item})) {
1027: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1028: }
1029: }
1030: foreach my $item (@logintext) {
1031: if ($settings->{$item} ne '') {
1032: $designs{'logintext'}{$item} = $settings->{$item};
1033: $is_custom{$item} = 1;
1034: }
1035: }
1036: if ($settings->{'font'} ne '') {
1037: $designs{'font'} = $settings->{'font'};
1038: $is_custom{'font'} = 1;
1039: }
1040: foreach my $item (@bgs) {
1041: if ($settings->{$item} ne '') {
1042: $designs{'bgs'}{$item} = $settings->{$item};
1043: $is_custom{$item} = 1;
1044: }
1045: }
1046: foreach my $item (@links) {
1047: if ($settings->{$item} ne '') {
1048: $designs{'links'}{$item} = $settings->{$item};
1049: $is_custom{$item} = 1;
1050: }
1051: }
1052: } else {
1053: if ($designhash{$dom.'.login.font'} ne '') {
1054: $designs{'font'} = $designhash{$dom.'.login.font'};
1055: $is_custom{'font'} = 1;
1056: }
1057: foreach my $item (@images) {
1058: if ($designhash{$dom.'.login.'.$item} ne '') {
1059: $designs{$item} = $designhash{$dom.'.login.'.$item};
1060: $is_custom{$item} = 1;
1061: }
1062: }
1063: foreach my $item (@bgs) {
1064: if ($designhash{$dom.'.login.'.$item} ne '') {
1065: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1066: $is_custom{$item} = 1;
1067: }
1.6 raeburn 1068: }
1.168 raeburn 1069: foreach my $item (@links) {
1070: if ($designhash{$dom.'.login.'.$item} ne '') {
1071: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1072: $is_custom{$item} = 1;
1073: }
1.6 raeburn 1074: }
1075: }
1.168 raeburn 1076: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1077: logo => 'Institution Logo',
1078: domlogo => 'Domain Logo',
1079: login => 'Login box');
1080: my $itemcount = 1;
1081: foreach my $item (@toggles) {
1082: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1083: $datatable .=
1084: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1085: '</td><td>'.
1086: '<span class="LC_nobreak"><label><input type="radio" name="'.
1087: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1088: '</label> <label><input type="radio" name="'.$item.'"'.
1089: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1090: '</tr>';
1091: $itemcount ++;
1.6 raeburn 1092: }
1.168 raeburn 1093: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1094: $datatable .= '</tr></table></td></tr>';
1095: } elsif ($caller eq 'help') {
1096: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1097: my $switchserver = &check_switchserver($dom,$confname);
1098: my $itemcount = 1;
1099: $defaulturl = '/adm/loginproblems.html';
1100: $defaulttype = 'default';
1101: %lt = &Apache::lonlocal::texthash (
1102: del => 'Delete?',
1103: rep => 'Replace:',
1104: upl => 'Upload:',
1105: default => 'Default',
1106: custom => 'Custom',
1107: );
1108: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1109: my @currlangs;
1110: if (ref($settings) eq 'HASH') {
1111: if (ref($settings->{'helpurl'}) eq 'HASH') {
1112: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1113: next if ($settings->{'helpurl'}{$key} eq '');
1114: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1115: $type{$key} = 'custom';
1116: unless ($key eq 'nolang') {
1117: push(@currlangs,$key);
1118: }
1119: }
1120: } elsif ($settings->{'helpurl'} ne '') {
1121: $type{'nolang'} = 'custom';
1122: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1123: }
1124: }
1.168 raeburn 1125: foreach my $lang ('nolang',sort(@currlangs)) {
1126: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1127: $datatable .= '<tr'.$css_class.'>';
1128: if ($url{$lang} eq '') {
1129: $url{$lang} = $defaulturl;
1130: }
1131: if ($type{$lang} eq '') {
1132: $type{$lang} = $defaulttype;
1133: }
1134: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1135: if ($lang eq 'nolang') {
1136: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1137: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1138: } else {
1139: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1140: $langchoices{$lang},
1141: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1142: }
1143: $datatable .= '</span></td>'."\n".
1144: '<td class="LC_left_item">';
1145: if ($type{$lang} eq 'custom') {
1146: $datatable .= '<span class="LC_nobreak"><label>'.
1147: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1148: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1149: } else {
1150: $datatable .= $lt{'upl'};
1151: }
1152: $datatable .='<br />';
1153: if ($switchserver) {
1154: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1155: } else {
1156: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1157: }
1.168 raeburn 1158: $datatable .= '</td></tr>';
1159: $itemcount ++;
1.6 raeburn 1160: }
1.168 raeburn 1161: my @addlangs;
1162: foreach my $lang (sort(keys(%langchoices))) {
1163: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1164: push(@addlangs,$lang);
1165: }
1166: if (@addlangs > 0) {
1167: my %toadd;
1168: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1169: $toadd{''} = &mt('Select');
1170: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1171: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1172: &mt('Add log-in help page for a specific language:').' '.
1173: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1174: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1175: if ($switchserver) {
1176: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1177: } else {
1178: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1179: }
1.168 raeburn 1180: $datatable .= '</td></tr>';
1.169 raeburn 1181: $itemcount ++;
1.6 raeburn 1182: }
1.169 raeburn 1183: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1184: }
1.6 raeburn 1185: return $datatable;
1186: }
1187:
1188: sub login_choices {
1189: my %choices =
1190: &Apache::lonlocal::texthash (
1.116 bisitz 1191: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1192: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1193: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1194: disallowlogin => "Login page requests redirected",
1195: hostid => "Server",
1.128 raeburn 1196: server => "Redirect to:",
1197: serverpath => "Path",
1198: custompath => "Custom",
1199: exempt => "Exempt IP(s)",
1.110 raeburn 1200: directlogin => "No redirect",
1201: newuser => "Link to create a user account",
1202: img => "Header",
1203: logo => "Main Logo",
1204: domlogo => "Domain Logo",
1205: login => "Log-in Header",
1206: textcol => "Text color",
1207: bgcol => "Box color",
1208: bgs => "Background colors",
1209: links => "Link colors",
1210: font => "Font color",
1211: pgbg => "Header",
1212: mainbg => "Page",
1213: sidebg => "Login box",
1214: link => "Link",
1215: alink => "Active link",
1216: vlink => "Visited link",
1.6 raeburn 1217: );
1218: return %choices;
1219: }
1220:
1221: sub print_rolecolors {
1.30 raeburn 1222: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1223: my %choices = &color_font_choices();
1224: my @bgs = ('pgbg','tabbg','sidebg');
1225: my @links = ('link','alink','vlink');
1226: my @images = ('img');
1227: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1228: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1229: my %defaultdesign = %Apache::loncommon::defaultdesign;
1230: my (%is_custom,%designs);
1.200 raeburn 1231: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1232: if (ref($settings) eq 'HASH') {
1233: if (ref($settings->{$role}) eq 'HASH') {
1234: if ($settings->{$role}->{'img'} ne '') {
1235: $designs{'img'} = $settings->{$role}->{'img'};
1236: $is_custom{'img'} = 1;
1237: }
1238: if ($settings->{$role}->{'font'} ne '') {
1239: $designs{'font'} = $settings->{$role}->{'font'};
1240: $is_custom{'font'} = 1;
1241: }
1.97 tempelho 1242: if ($settings->{$role}->{'fontmenu'} ne '') {
1243: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1244: $is_custom{'fontmenu'} = 1;
1245: }
1.6 raeburn 1246: foreach my $item (@bgs) {
1247: if ($settings->{$role}->{$item} ne '') {
1248: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1249: $is_custom{$item} = 1;
1250: }
1251: }
1252: foreach my $item (@links) {
1253: if ($settings->{$role}->{$item} ne '') {
1254: $designs{'links'}{$item} = $settings->{$role}->{$item};
1255: $is_custom{$item} = 1;
1256: }
1257: }
1258: }
1259: } else {
1260: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1261: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1262: $is_custom{'img'} = 1;
1263: }
1.97 tempelho 1264: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1265: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1266: $is_custom{'fontmenu'} = 1;
1267: }
1.6 raeburn 1268: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1269: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1270: $is_custom{'font'} = 1;
1271: }
1272: foreach my $item (@bgs) {
1273: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1274: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1275: $is_custom{$item} = 1;
1276:
1277: }
1278: }
1279: foreach my $item (@links) {
1280: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1281: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1282: $is_custom{$item} = 1;
1283: }
1284: }
1285: }
1286: my $itemcount = 1;
1.30 raeburn 1287: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1288: $datatable .= '</tr></table></td></tr>';
1289: return $datatable;
1290: }
1291:
1.200 raeburn 1292: sub role_defaults {
1293: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1294: my %defaults;
1295: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1296: return %defaults;
1297: }
1298: my %defaultdesign = %Apache::loncommon::defaultdesign;
1299: if ($role eq 'login') {
1300: %defaults = (
1301: font => $defaultdesign{$role.'.font'},
1302: );
1303: if (ref($logintext) eq 'ARRAY') {
1304: foreach my $item (@{$logintext}) {
1305: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1306: }
1307: }
1308: foreach my $item (@{$images}) {
1309: $defaults{'showlogo'}{$item} = 1;
1310: }
1311: } else {
1312: %defaults = (
1313: img => $defaultdesign{$role.'.img'},
1314: font => $defaultdesign{$role.'.font'},
1315: fontmenu => $defaultdesign{$role.'.fontmenu'},
1316: );
1317: }
1318: foreach my $item (@{$bgs}) {
1319: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1320: }
1321: foreach my $item (@{$links}) {
1322: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1323: }
1324: foreach my $item (@{$images}) {
1325: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1326: }
1327: return %defaults;
1328: }
1329:
1.6 raeburn 1330: sub display_color_options {
1.9 raeburn 1331: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1332: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1333: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1334: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1335: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1336: '<td>'.$choices->{'font'}.'</td>';
1337: if (!$is_custom->{'font'}) {
1.30 raeburn 1338: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1339: } else {
1340: $datatable .= '<td> </td>';
1341: }
1.174 foxr 1342: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1343:
1.8 raeburn 1344: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1345: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1346: ' value="'.$current_color.'" /> '.
1.174 foxr 1347: ' </td></tr>';
1.107 raeburn 1348: unless ($role eq 'login') {
1349: $datatable .= '<tr'.$css_class.'>'.
1350: '<td>'.$choices->{'fontmenu'}.'</td>';
1351: if (!$is_custom->{'fontmenu'}) {
1352: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1353: } else {
1354: $datatable .= '<td> </td>';
1355: }
1.202 raeburn 1356: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1357: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1358: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1359: '<input class="colorchooser" type="text" size="10" name="'
1360: .$role.'_fontmenu"'.
1361: ' value="'.$current_color.'" /> '.
1362: ' </td></tr>';
1.97 tempelho 1363: }
1.9 raeburn 1364: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1365: foreach my $img (@{$images}) {
1.18 albertel 1366: $itemcount ++;
1.6 raeburn 1367: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1368: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1369: '<td>'.$choices->{$img};
1.41 raeburn 1370: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1371: if ($role eq 'login') {
1372: if ($img eq 'login') {
1373: $login_hdr_pick =
1.135 bisitz 1374: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1375: $logincolors =
1376: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1377: $designs,$defaults);
1.70 raeburn 1378: } elsif ($img ne 'domlogo') {
1379: $datatable.= &logo_display_options($img,$defaults,$designs);
1380: }
1381: }
1382: $datatable .= '</td>';
1.6 raeburn 1383: if ($designs->{$img} ne '') {
1384: $imgfile = $designs->{$img};
1.18 albertel 1385: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1386: } else {
1387: $imgfile = $defaults->{$img};
1388: }
1389: if ($imgfile) {
1.9 raeburn 1390: my ($showfile,$fullsize);
1391: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1392: my $urldir = $1;
1393: my $filename = $2;
1394: my @info = &Apache::lonnet::stat_file($designs->{$img});
1395: if (@info) {
1396: my $thumbfile = 'tn-'.$filename;
1397: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1398: if (@thumb) {
1399: $showfile = $urldir.'/'.$thumbfile;
1400: } else {
1401: $showfile = $imgfile;
1402: }
1403: } else {
1404: $showfile = '';
1405: }
1406: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1407: $showfile = $imgfile;
1.6 raeburn 1408: my $imgdir = $1;
1409: my $filename = $2;
1.159 raeburn 1410: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1411: $showfile = "/$imgdir/tn-".$filename;
1412: } else {
1.159 raeburn 1413: my $input = $londocroot.$imgfile;
1414: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1415: if (!-e $output) {
1.9 raeburn 1416: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1417: my ($fullwidth,$fullheight) = &check_dimensions($input);
1418: if ($fullwidth ne '' && $fullheight ne '') {
1419: if ($fullwidth > $width && $fullheight > $height) {
1420: my $size = $width.'x'.$height;
1421: system("convert -sample $size $input $output");
1.159 raeburn 1422: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1423: }
1424: }
1.6 raeburn 1425: }
1426: }
1.16 raeburn 1427: }
1.6 raeburn 1428: if ($showfile) {
1.40 raeburn 1429: if ($showfile =~ m{^/(adm|res)/}) {
1430: if ($showfile =~ m{^/res/}) {
1431: my $local_showfile =
1432: &Apache::lonnet::filelocation('',$showfile);
1433: &Apache::lonnet::repcopy($local_showfile);
1434: }
1435: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1436: }
1437: if ($imgfile) {
1438: if ($imgfile =~ m{^/(adm|res)/}) {
1439: if ($imgfile =~ m{^/res/}) {
1440: my $local_imgfile =
1441: &Apache::lonnet::filelocation('',$imgfile);
1442: &Apache::lonnet::repcopy($local_imgfile);
1443: }
1444: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1445: } else {
1446: $fullsize = $imgfile;
1447: }
1448: }
1.41 raeburn 1449: $datatable .= '<td>';
1450: if ($img eq 'login') {
1.135 bisitz 1451: $datatable .= $login_hdr_pick;
1452: }
1.41 raeburn 1453: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1454: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1455: } else {
1.201 raeburn 1456: $datatable .= '<td> </td><td class="LC_left_item">'.
1457: &mt('Upload:').'<br />';
1.6 raeburn 1458: }
1459: } else {
1.201 raeburn 1460: $datatable .= '<td> </td><td class="LC_left_item">'.
1461: &mt('Upload:').'<br />';
1.6 raeburn 1462: }
1.9 raeburn 1463: if ($switchserver) {
1464: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1465: } else {
1.135 bisitz 1466: if ($img ne 'login') { # suppress file selection for Log-in header
1467: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1468: }
1.9 raeburn 1469: }
1470: $datatable .= '</td></tr>';
1.6 raeburn 1471: }
1472: $itemcount ++;
1473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1474: $datatable .= '<tr'.$css_class.'>'.
1475: '<td>'.$choices->{'bgs'}.'</td>';
1476: my $bgs_def;
1477: foreach my $item (@{$bgs}) {
1478: if (!$is_custom->{$item}) {
1.70 raeburn 1479: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1480: }
1481: }
1482: if ($bgs_def) {
1.8 raeburn 1483: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1484: } else {
1485: $datatable .= '<td> </td>';
1486: }
1487: $datatable .= '<td class="LC_right_item">'.
1488: '<table border="0"><tr>';
1.174 foxr 1489:
1.6 raeburn 1490: foreach my $item (@{$bgs}) {
1.201 raeburn 1491: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1492: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1493: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1494: $datatable .= ' ';
1.6 raeburn 1495: }
1.174 foxr 1496: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1497: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1498: }
1499: $datatable .= '</tr></table></td></tr>';
1500: $itemcount ++;
1501: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1502: $datatable .= '<tr'.$css_class.'>'.
1503: '<td>'.$choices->{'links'}.'</td>';
1504: my $links_def;
1505: foreach my $item (@{$links}) {
1506: if (!$is_custom->{$item}) {
1.30 raeburn 1507: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1508: }
1509: }
1510: if ($links_def) {
1.8 raeburn 1511: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1512: } else {
1513: $datatable .= '<td> </td>';
1514: }
1515: $datatable .= '<td class="LC_right_item">'.
1516: '<table border="0"><tr>';
1517: foreach my $item (@{$links}) {
1.234 raeburn 1518: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1519: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1520: if ($designs->{'links'}{$item}) {
1.174 foxr 1521: $datatable.=' ';
1.6 raeburn 1522: }
1.174 foxr 1523: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1524: '" /></td>';
1525: }
1.30 raeburn 1526: $$rowtotal += $itemcount;
1.3 raeburn 1527: return $datatable;
1528: }
1529:
1.70 raeburn 1530: sub logo_display_options {
1531: my ($img,$defaults,$designs) = @_;
1532: my $checkedon;
1533: if (ref($defaults) eq 'HASH') {
1534: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1535: if ($defaults->{'showlogo'}{$img}) {
1536: $checkedon = 'checked="checked" ';
1537: }
1538: }
1539: }
1540: if (ref($designs) eq 'HASH') {
1541: if (ref($designs->{'showlogo'}) eq 'HASH') {
1542: if (defined($designs->{'showlogo'}{$img})) {
1543: if ($designs->{'showlogo'}{$img} == 0) {
1544: $checkedon = '';
1545: } elsif ($designs->{'showlogo'}{$img} == 1) {
1546: $checkedon = 'checked="checked" ';
1547: }
1548: }
1549: }
1550: }
1551: return '<br /><label> <input type="checkbox" name="'.
1552: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1553: &mt('show').'</label>'."\n";
1554: }
1555:
1.41 raeburn 1556: sub login_header_options {
1.135 bisitz 1557: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1558: my $output = '';
1.41 raeburn 1559: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1560: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1561: if (!$is_custom->{'textcol'}) {
1562: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1563: ' ';
1564: }
1565: if (!$is_custom->{'bgcol'}) {
1566: $output .= $choices->{'bgcol'}.': '.
1567: '<span id="css_'.$role.'_font" style="background-color: '.
1568: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1569: }
1570: $output .= '<br />';
1571: }
1572: $output .='<br />';
1573: return $output;
1574: }
1575:
1576: sub login_text_colors {
1.201 raeburn 1577: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1578: my $color_menu = '<table border="0"><tr>';
1579: foreach my $item (@{$logintext}) {
1.201 raeburn 1580: $color_menu .= '<td align="center">'.$choices->{$item};
1581: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1582: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1583: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1584: }
1585: $color_menu .= '</tr></table><br />';
1586: return $color_menu;
1587: }
1588:
1589: sub image_changes {
1590: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1591: my $output;
1.135 bisitz 1592: if ($img eq 'login') {
1593: # suppress image for Log-in header
1594: } elsif (!$is_custom) {
1.70 raeburn 1595: if ($img ne 'domlogo') {
1.41 raeburn 1596: $output .= &mt('Default image:').'<br />';
1597: } else {
1598: $output .= &mt('Default in use:').'<br />';
1599: }
1600: }
1.135 bisitz 1601: if ($img eq 'login') { # suppress image for Log-in header
1602: $output .= '<td>'.$logincolors;
1.41 raeburn 1603: } else {
1.135 bisitz 1604: if ($img_import) {
1605: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1606: }
1607: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1608: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1609: if ($is_custom) {
1610: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1611: '<input type="checkbox" name="'.
1612: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1613: '</label> '.&mt('Replace:').'</span><br />';
1614: } else {
1.201 raeburn 1615: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1616: }
1.41 raeburn 1617: }
1618: return $output;
1619: }
1620:
1.3 raeburn 1621: sub print_quotas {
1.86 raeburn 1622: my ($dom,$settings,$rowtotal,$action) = @_;
1623: my $context;
1624: if ($action eq 'quotas') {
1625: $context = 'tools';
1626: } else {
1627: $context = $action;
1628: }
1.197 raeburn 1629: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1630: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1631: my $typecount = 0;
1.101 raeburn 1632: my ($css_class,%titles);
1.86 raeburn 1633: if ($context eq 'requestcourses') {
1.216 raeburn 1634: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1635: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1636: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1637: %titles = &courserequest_titles();
1.163 raeburn 1638: } elsif ($context eq 'requestauthor') {
1639: @usertools = ('author');
1640: @options = ('norequest','approval','automatic');
1.210 raeburn 1641: %titles = &authorrequest_titles();
1.86 raeburn 1642: } else {
1.162 raeburn 1643: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1644: %titles = &tool_titles();
1.86 raeburn 1645: }
1.26 raeburn 1646: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1647: foreach my $type (@{$types}) {
1.197 raeburn 1648: my ($currdefquota,$currauthorquota);
1.163 raeburn 1649: unless (($context eq 'requestcourses') ||
1650: ($context eq 'requestauthor')) {
1.86 raeburn 1651: if (ref($settings) eq 'HASH') {
1652: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1653: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1654: } else {
1655: $currdefquota = $settings->{$type};
1656: }
1.197 raeburn 1657: if (ref($settings->{authorquota}) eq 'HASH') {
1658: $currauthorquota = $settings->{authorquota}->{$type};
1659: }
1.78 raeburn 1660: }
1.72 raeburn 1661: }
1.3 raeburn 1662: if (defined($usertypes->{$type})) {
1663: $typecount ++;
1664: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1665: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1666: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1667: '<td class="LC_left_item">';
1.101 raeburn 1668: if ($context eq 'requestcourses') {
1669: $datatable .= '<table><tr>';
1670: }
1671: my %cell;
1.72 raeburn 1672: foreach my $item (@usertools) {
1.101 raeburn 1673: if ($context eq 'requestcourses') {
1674: my ($curroption,$currlimit);
1675: if (ref($settings) eq 'HASH') {
1676: if (ref($settings->{$item}) eq 'HASH') {
1677: $curroption = $settings->{$item}->{$type};
1678: if ($curroption =~ /^autolimit=(\d*)$/) {
1679: $currlimit = $1;
1680: }
1681: }
1682: }
1683: if (!$curroption) {
1684: $curroption = 'norequest';
1685: }
1686: $datatable .= '<th>'.$titles{$item}.'</th>';
1687: foreach my $option (@options) {
1688: my $val = $option;
1689: if ($option eq 'norequest') {
1690: $val = 0;
1691: }
1692: if ($option eq 'validate') {
1693: my $canvalidate = 0;
1694: if (ref($validations{$item}) eq 'HASH') {
1695: if ($validations{$item}{$type}) {
1696: $canvalidate = 1;
1697: }
1698: }
1699: next if (!$canvalidate);
1700: }
1701: my $checked = '';
1702: if ($option eq $curroption) {
1703: $checked = ' checked="checked"';
1704: } elsif ($option eq 'autolimit') {
1705: if ($curroption =~ /^autolimit/) {
1706: $checked = ' checked="checked"';
1707: }
1708: }
1709: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1710: '<input type="radio" name="crsreq_'.$item.
1711: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1712: $titles{$option}.'</label>';
1.101 raeburn 1713: if ($option eq 'autolimit') {
1.127 raeburn 1714: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1715: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1716: 'value="'.$currlimit.'" />';
1.101 raeburn 1717: }
1.127 raeburn 1718: $cell{$item} .= '</span> ';
1.103 raeburn 1719: if ($option eq 'autolimit') {
1.127 raeburn 1720: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1721: }
1.101 raeburn 1722: }
1.163 raeburn 1723: } elsif ($context eq 'requestauthor') {
1724: my $curroption;
1725: if (ref($settings) eq 'HASH') {
1726: $curroption = $settings->{$type};
1727: }
1728: if (!$curroption) {
1729: $curroption = 'norequest';
1730: }
1731: foreach my $option (@options) {
1732: my $val = $option;
1733: if ($option eq 'norequest') {
1734: $val = 0;
1735: }
1736: my $checked = '';
1737: if ($option eq $curroption) {
1738: $checked = ' checked="checked"';
1739: }
1740: $datatable .= '<span class="LC_nobreak"><label>'.
1741: '<input type="radio" name="authorreq_'.$type.
1742: '" value="'.$val.'"'.$checked.' />'.
1743: $titles{$option}.'</label></span> ';
1744: }
1.101 raeburn 1745: } else {
1746: my $checked = 'checked="checked" ';
1747: if (ref($settings) eq 'HASH') {
1748: if (ref($settings->{$item}) eq 'HASH') {
1749: if ($settings->{$item}->{$type} == 0) {
1750: $checked = '';
1751: } elsif ($settings->{$item}->{$type} == 1) {
1752: $checked = 'checked="checked" ';
1753: }
1.78 raeburn 1754: }
1.72 raeburn 1755: }
1.101 raeburn 1756: $datatable .= '<span class="LC_nobreak"><label>'.
1757: '<input type="checkbox" name="'.$context.'_'.$item.
1758: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1759: '</label></span> ';
1.72 raeburn 1760: }
1.101 raeburn 1761: }
1762: if ($context eq 'requestcourses') {
1763: $datatable .= '</tr><tr>';
1764: foreach my $item (@usertools) {
1.106 raeburn 1765: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1766: }
1767: $datatable .= '</tr></table>';
1.72 raeburn 1768: }
1.86 raeburn 1769: $datatable .= '</td>';
1.163 raeburn 1770: unless (($context eq 'requestcourses') ||
1771: ($context eq 'requestauthor')) {
1.86 raeburn 1772: $datatable .=
1.197 raeburn 1773: '<td class="LC_right_item">'.
1774: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1775: '<input type="text" name="quota_'.$type.
1.72 raeburn 1776: '" value="'.$currdefquota.
1.197 raeburn 1777: '" size="5" /></span>'.(' ' x 2).
1778: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1779: '<input type="text" name="authorquota_'.$type.
1780: '" value="'.$currauthorquota.
1781: '" size="5" /></span></td>';
1.86 raeburn 1782: }
1783: $datatable .= '</tr>';
1.3 raeburn 1784: }
1785: }
1786: }
1.163 raeburn 1787: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1788: $defaultquota = '20';
1.197 raeburn 1789: $authorquota = '500';
1.86 raeburn 1790: if (ref($settings) eq 'HASH') {
1791: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1792: $defaultquota = $settings->{'defaultquota'}->{'default'};
1793: } elsif (defined($settings->{'default'})) {
1794: $defaultquota = $settings->{'default'};
1795: }
1.197 raeburn 1796: if (ref($settings->{'authorquota'}) eq 'HASH') {
1797: $authorquota = $settings->{'authorquota'}->{'default'};
1798: }
1.3 raeburn 1799: }
1800: }
1801: $typecount ++;
1802: $css_class = $typecount%2?' class="LC_odd_row"':'';
1803: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1804: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1805: '<td class="LC_left_item">';
1.101 raeburn 1806: if ($context eq 'requestcourses') {
1807: $datatable .= '<table><tr>';
1808: }
1809: my %defcell;
1.72 raeburn 1810: foreach my $item (@usertools) {
1.101 raeburn 1811: if ($context eq 'requestcourses') {
1812: my ($curroption,$currlimit);
1813: if (ref($settings) eq 'HASH') {
1814: if (ref($settings->{$item}) eq 'HASH') {
1815: $curroption = $settings->{$item}->{'default'};
1816: if ($curroption =~ /^autolimit=(\d*)$/) {
1817: $currlimit = $1;
1818: }
1819: }
1820: }
1821: if (!$curroption) {
1822: $curroption = 'norequest';
1823: }
1824: $datatable .= '<th>'.$titles{$item}.'</th>';
1825: foreach my $option (@options) {
1826: my $val = $option;
1827: if ($option eq 'norequest') {
1828: $val = 0;
1829: }
1830: if ($option eq 'validate') {
1831: my $canvalidate = 0;
1832: if (ref($validations{$item}) eq 'HASH') {
1833: if ($validations{$item}{'default'}) {
1834: $canvalidate = 1;
1835: }
1836: }
1837: next if (!$canvalidate);
1838: }
1839: my $checked = '';
1840: if ($option eq $curroption) {
1841: $checked = ' checked="checked"';
1842: } elsif ($option eq 'autolimit') {
1843: if ($curroption =~ /^autolimit/) {
1844: $checked = ' checked="checked"';
1845: }
1846: }
1847: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1848: '<input type="radio" name="crsreq_'.$item.
1849: '_default" value="'.$val.'"'.$checked.' />'.
1850: $titles{$option}.'</label>';
1851: if ($option eq 'autolimit') {
1.127 raeburn 1852: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1853: $item.'_limit_default" size="1" '.
1854: 'value="'.$currlimit.'" />';
1855: }
1.127 raeburn 1856: $defcell{$item} .= '</span> ';
1.104 raeburn 1857: if ($option eq 'autolimit') {
1.127 raeburn 1858: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1859: }
1.101 raeburn 1860: }
1.163 raeburn 1861: } elsif ($context eq 'requestauthor') {
1862: my $curroption;
1863: if (ref($settings) eq 'HASH') {
1.172 raeburn 1864: $curroption = $settings->{'default'};
1.163 raeburn 1865: }
1866: if (!$curroption) {
1867: $curroption = 'norequest';
1868: }
1869: foreach my $option (@options) {
1870: my $val = $option;
1871: if ($option eq 'norequest') {
1872: $val = 0;
1873: }
1874: my $checked = '';
1875: if ($option eq $curroption) {
1876: $checked = ' checked="checked"';
1877: }
1878: $datatable .= '<span class="LC_nobreak"><label>'.
1879: '<input type="radio" name="authorreq_default"'.
1880: ' value="'.$val.'"'.$checked.' />'.
1881: $titles{$option}.'</label></span> ';
1882: }
1.101 raeburn 1883: } else {
1884: my $checked = 'checked="checked" ';
1885: if (ref($settings) eq 'HASH') {
1886: if (ref($settings->{$item}) eq 'HASH') {
1887: if ($settings->{$item}->{'default'} == 0) {
1888: $checked = '';
1889: } elsif ($settings->{$item}->{'default'} == 1) {
1890: $checked = 'checked="checked" ';
1891: }
1.78 raeburn 1892: }
1.72 raeburn 1893: }
1.101 raeburn 1894: $datatable .= '<span class="LC_nobreak"><label>'.
1895: '<input type="checkbox" name="'.$context.'_'.$item.
1896: '" value="default" '.$checked.'/>'.$titles{$item}.
1897: '</label></span> ';
1898: }
1899: }
1900: if ($context eq 'requestcourses') {
1901: $datatable .= '</tr><tr>';
1902: foreach my $item (@usertools) {
1.106 raeburn 1903: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1904: }
1.101 raeburn 1905: $datatable .= '</tr></table>';
1.72 raeburn 1906: }
1.86 raeburn 1907: $datatable .= '</td>';
1.163 raeburn 1908: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1909: $datatable .= '<td class="LC_right_item">'.
1910: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1911: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1912: $defaultquota.'" size="5" /></span>'.(' ' x2).
1913: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1914: '<input type="text" name="authorquota" value="'.
1915: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1916: }
1917: $datatable .= '</tr>';
1.72 raeburn 1918: $typecount ++;
1919: $css_class = $typecount%2?' class="LC_odd_row"':'';
1920: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1921: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1922: if ($context eq 'requestcourses') {
1.109 raeburn 1923: $datatable .= &mt('(overrides affiliation, if set)').
1924: '</td>'.
1925: '<td class="LC_left_item">'.
1926: '<table><tr>';
1.101 raeburn 1927: } else {
1.109 raeburn 1928: $datatable .= &mt('(overrides affiliation, if checked)').
1929: '</td>'.
1930: '<td class="LC_left_item" colspan="2">'.
1931: '<br />';
1.101 raeburn 1932: }
1933: my %advcell;
1.72 raeburn 1934: foreach my $item (@usertools) {
1.101 raeburn 1935: if ($context eq 'requestcourses') {
1936: my ($curroption,$currlimit);
1937: if (ref($settings) eq 'HASH') {
1938: if (ref($settings->{$item}) eq 'HASH') {
1939: $curroption = $settings->{$item}->{'_LC_adv'};
1940: if ($curroption =~ /^autolimit=(\d*)$/) {
1941: $currlimit = $1;
1942: }
1943: }
1944: }
1945: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1946: my $checked = '';
1947: if ($curroption eq '') {
1948: $checked = ' checked="checked"';
1949: }
1950: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1951: '<input type="radio" name="crsreq_'.$item.
1952: '__LC_adv" value=""'.$checked.' />'.
1953: &mt('No override set').'</label></span> ';
1.101 raeburn 1954: foreach my $option (@options) {
1955: my $val = $option;
1956: if ($option eq 'norequest') {
1957: $val = 0;
1958: }
1959: if ($option eq 'validate') {
1960: my $canvalidate = 0;
1961: if (ref($validations{$item}) eq 'HASH') {
1962: if ($validations{$item}{'_LC_adv'}) {
1963: $canvalidate = 1;
1964: }
1965: }
1966: next if (!$canvalidate);
1967: }
1968: my $checked = '';
1.104 raeburn 1969: if ($val eq $curroption) {
1.101 raeburn 1970: $checked = ' checked="checked"';
1971: } elsif ($option eq 'autolimit') {
1972: if ($curroption =~ /^autolimit/) {
1973: $checked = ' checked="checked"';
1974: }
1975: }
1976: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1977: '<input type="radio" name="crsreq_'.$item.
1978: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1979: $titles{$option}.'</label>';
1980: if ($option eq 'autolimit') {
1.127 raeburn 1981: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1982: $item.'_limit__LC_adv" size="1" '.
1983: 'value="'.$currlimit.'" />';
1984: }
1.127 raeburn 1985: $advcell{$item} .= '</span> ';
1.104 raeburn 1986: if ($option eq 'autolimit') {
1.127 raeburn 1987: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1988: }
1.101 raeburn 1989: }
1.163 raeburn 1990: } elsif ($context eq 'requestauthor') {
1991: my $curroption;
1992: if (ref($settings) eq 'HASH') {
1993: $curroption = $settings->{'_LC_adv'};
1994: }
1995: my $checked = '';
1996: if ($curroption eq '') {
1997: $checked = ' checked="checked"';
1998: }
1999: $datatable .= '<span class="LC_nobreak"><label>'.
2000: '<input type="radio" name="authorreq__LC_adv"'.
2001: ' value=""'.$checked.' />'.
2002: &mt('No override set').'</label></span> ';
2003: foreach my $option (@options) {
2004: my $val = $option;
2005: if ($option eq 'norequest') {
2006: $val = 0;
2007: }
2008: my $checked = '';
2009: if ($val eq $curroption) {
2010: $checked = ' checked="checked"';
2011: }
2012: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2013: '<input type="radio" name="authorreq__LC_adv"'.
2014: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2015: $titles{$option}.'</label></span> ';
2016: }
1.101 raeburn 2017: } else {
2018: my $checked = 'checked="checked" ';
2019: if (ref($settings) eq 'HASH') {
2020: if (ref($settings->{$item}) eq 'HASH') {
2021: if ($settings->{$item}->{'_LC_adv'} == 0) {
2022: $checked = '';
2023: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2024: $checked = 'checked="checked" ';
2025: }
1.79 raeburn 2026: }
1.72 raeburn 2027: }
1.101 raeburn 2028: $datatable .= '<span class="LC_nobreak"><label>'.
2029: '<input type="checkbox" name="'.$context.'_'.$item.
2030: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2031: '</label></span> ';
2032: }
2033: }
2034: if ($context eq 'requestcourses') {
2035: $datatable .= '</tr><tr>';
2036: foreach my $item (@usertools) {
1.106 raeburn 2037: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2038: }
1.101 raeburn 2039: $datatable .= '</tr></table>';
1.72 raeburn 2040: }
1.98 raeburn 2041: $datatable .= '</td></tr>';
1.30 raeburn 2042: $$rowtotal += $typecount;
1.3 raeburn 2043: return $datatable;
2044: }
2045:
1.163 raeburn 2046: sub print_requestmail {
2047: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2048: my ($now,$datatable,%currapp);
1.102 raeburn 2049: $now = time;
2050: if (ref($settings) eq 'HASH') {
2051: if (ref($settings->{'notify'}) eq 'HASH') {
2052: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2053: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2054: }
2055: }
2056: }
1.191 raeburn 2057: my $numinrow = 2;
1.224 raeburn 2058: my $css_class;
2059: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2060: my $text;
2061: if ($action eq 'requestcourses') {
2062: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2063: } elsif ($action eq 'requestauthor') {
2064: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2065: } else {
1.224 raeburn 2066: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2067: }
1.224 raeburn 2068: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2069: ' <td>'.$text.'</td>'.
1.102 raeburn 2070: ' <td class="LC_left_item">';
1.191 raeburn 2071: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2072: $action.'notifyapproval',%currapp);
1.191 raeburn 2073: if ($numdc > 0) {
2074: $datatable .= $table;
1.102 raeburn 2075: } else {
2076: $datatable .= &mt('There are no active Domain Coordinators');
2077: }
2078: $datatable .='</td></tr>';
2079: return $datatable;
2080: }
2081:
1.216 raeburn 2082: sub print_studentcode {
2083: my ($settings,$rowtotal) = @_;
2084: my $rownum = 0;
1.218 raeburn 2085: my ($output,%current);
2086: my @crstypes = ('official','unofficial','community','textbook');
1.248 raeburn 2087: if (ref($settings) eq 'HASH') {
2088: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2089: foreach my $type (@crstypes) {
2090: $current{$type} = $settings->{'uniquecode'}{$type};
2091: }
1.218 raeburn 2092: }
2093: }
2094: $output .= '<tr>'.
2095: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2096: '<td class="LC_left_item">';
2097: foreach my $type (@crstypes) {
2098: my $check = ' ';
2099: if ($current{$type}) {
2100: $check = ' checked="checked" ';
2101: }
2102: $output .= '<span class="LC_nobreak"><label>'.
2103: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2104: &mt($type).'</label></span>'.(' 'x2).' ';
2105: }
2106: $output .= '</td></tr>';
2107: $$rowtotal ++;
2108: return $output;
1.216 raeburn 2109: }
2110:
2111: sub print_textbookcourses {
1.242 raeburn 2112: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2113: my $rownum = 0;
2114: my $css_class;
2115: my $itemcount = 1;
2116: my $maxnum = 0;
2117: my $bookshash;
2118: if (ref($settings) eq 'HASH') {
1.242 raeburn 2119: $bookshash = $settings->{$type};
1.216 raeburn 2120: }
2121: my %ordered;
2122: if (ref($bookshash) eq 'HASH') {
2123: foreach my $item (keys(%{$bookshash})) {
2124: if (ref($bookshash->{$item}) eq 'HASH') {
2125: my $num = $bookshash->{$item}{'order'};
2126: $ordered{$num} = $item;
2127: }
2128: }
2129: }
2130: my $confname = $dom.'-domainconfig';
2131: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2132: my $maxnum = scalar(keys(%ordered));
2133: my $datatable;
1.216 raeburn 2134: if (keys(%ordered)) {
2135: my @items = sort { $a <=> $b } keys(%ordered);
2136: for (my $i=0; $i<@items; $i++) {
2137: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2138: my $key = $ordered{$items[$i]};
2139: my %coursehash=&Apache::lonnet::coursedescription($key);
2140: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2141: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2142: if (ref($bookshash->{$key}) eq 'HASH') {
2143: $subject = $bookshash->{$key}->{'subject'};
2144: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2145: if ($type eq 'textbooks') {
1.243 raeburn 2146: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2147: $author = $bookshash->{$key}->{'author'};
2148: $image = $bookshash->{$key}->{'image'};
2149: if ($image ne '') {
2150: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2151: my $imagethumb = "$path/tn-".$imagefile;
2152: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2153: }
1.216 raeburn 2154: }
2155: }
1.242 raeburn 2156: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2157: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2158: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2159: for (my $k=0; $k<=$maxnum; $k++) {
2160: my $vpos = $k+1;
2161: my $selstr;
2162: if ($k == $i) {
2163: $selstr = ' selected="selected" ';
2164: }
2165: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2166: }
2167: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2168: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2169: &mt('Delete?').'</label></span></td>'.
2170: '<td colspan="2">'.
1.242 raeburn 2171: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2172: (' 'x2).
1.242 raeburn 2173: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2174: if ($type eq 'textbooks') {
2175: $datatable .= (' 'x2).
1.243 raeburn 2176: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2177: (' 'x2).
1.242 raeburn 2178: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2179: (' 'x2).
2180: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2181: if ($image) {
2182: $datatable .= '<span class="LC_nobreak">'.
2183: $imgsrc.
2184: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2185: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2186: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2187: }
2188: if ($switchserver) {
2189: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2190: } else {
2191: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2192: }
1.216 raeburn 2193: }
1.242 raeburn 2194: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2195: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2196: $coursetitle.'</span></td></tr>'."\n";
2197: $itemcount ++;
2198: }
2199: }
2200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2201: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2202: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2203: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2204: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2205: for (my $k=0; $k<$maxnum+1; $k++) {
2206: my $vpos = $k+1;
2207: my $selstr;
2208: if ($k == $maxnum) {
2209: $selstr = ' selected="selected" ';
2210: }
2211: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2212: }
2213: $datatable .= '</select> '."\n".
1.242 raeburn 2214: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2215: '<td colspan="2">'.
1.242 raeburn 2216: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2217: (' 'x2).
1.242 raeburn 2218: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2219: (' 'x2);
2220: if ($type eq 'textbooks') {
1.243 raeburn 2221: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2222: (' 'x2).
2223: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2224: (' 'x2).
2225: '<span class="LC_nobreak">'.&mt('Image:').' ';
2226: if ($switchserver) {
2227: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2228: } else {
2229: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2230: }
1.216 raeburn 2231: }
2232: $datatable .= '</span>'."\n".
2233: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2234: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2235: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2236: &Apache::loncommon::selectcourse_link
1.242 raeburn 2237: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2238: '</span></td>'."\n".
2239: '</tr>'."\n";
2240: $itemcount ++;
2241: return $datatable;
2242: }
2243:
1.217 raeburn 2244: sub textbookcourses_javascript {
1.242 raeburn 2245: my ($settings) = @_;
2246: return unless(ref($settings) eq 'HASH');
2247: my (%ordered,%total,%jstext);
2248: foreach my $type ('textbooks','templates') {
2249: $total{$type} = 0;
2250: if (ref($settings->{$type}) eq 'HASH') {
2251: foreach my $item (keys(%{$settings->{$type}})) {
2252: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2253: my $num = $settings->{$type}->{$item}{'order'};
2254: $ordered{$type}{$num} = $item;
2255: }
2256: }
2257: $total{$type} = scalar(keys(%{$settings->{$type}}));
2258: }
2259: my @jsarray = ();
2260: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2261: push(@jsarray,$ordered{$type}{$item});
2262: }
2263: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2264: }
2265: return <<"ENDSCRIPT";
2266: <script type="text/javascript">
2267: // <![CDATA[
1.242 raeburn 2268: function reorderBooks(form,item,caller) {
1.217 raeburn 2269: var changedVal;
1.242 raeburn 2270: $jstext{'textbooks'};
2271: $jstext{'templates'};
2272: var newpos;
2273: var maxh;
2274: if (caller == 'textbooks') {
2275: newpos = 'textbooks_addbook_pos';
2276: maxh = 1 + $total{'textbooks'};
2277: } else {
2278: newpos = 'templates_addbook_pos';
2279: maxh = 1 + $total{'templates'};
2280: }
1.217 raeburn 2281: var current = new Array;
2282: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2283: if (item == newpos) {
2284: changedVal = newitemVal;
2285: } else {
2286: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2287: current[newitemVal] = newpos;
2288: }
1.242 raeburn 2289: if (caller == 'textbooks') {
2290: for (var i=0; i<textbooks.length; i++) {
2291: var elementName = 'textbooks_'+textbooks[i];
2292: if (elementName != item) {
2293: if (form.elements[elementName]) {
2294: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2295: current[currVal] = elementName;
2296: }
2297: }
2298: }
2299: }
2300: if (caller == 'templates') {
2301: for (var i=0; i<templates.length; i++) {
2302: var elementName = 'templates_'+templates[i];
2303: if (elementName != item) {
2304: if (form.elements[elementName]) {
2305: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2306: current[currVal] = elementName;
2307: }
1.217 raeburn 2308: }
2309: }
2310: }
2311: var oldVal;
2312: for (var j=0; j<maxh; j++) {
2313: if (current[j] == undefined) {
2314: oldVal = j;
2315: }
2316: }
2317: if (oldVal < changedVal) {
2318: for (var k=oldVal+1; k<=changedVal ; k++) {
2319: var elementName = current[k];
2320: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2321: }
2322: } else {
2323: for (var k=changedVal; k<oldVal; k++) {
2324: var elementName = current[k];
2325: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2326: }
2327: }
2328: return;
2329: }
2330:
2331: // ]]>
2332: </script>
2333:
2334: ENDSCRIPT
2335: }
2336:
1.3 raeburn 2337: sub print_autoenroll {
1.30 raeburn 2338: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2339: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2340: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2341: if (ref($settings) eq 'HASH') {
2342: if (exists($settings->{'run'})) {
2343: if ($settings->{'run'} eq '0') {
2344: $runoff = ' checked="checked" ';
2345: $runon = ' ';
2346: } else {
2347: $runon = ' checked="checked" ';
2348: $runoff = ' ';
2349: }
2350: } else {
2351: if ($autorun) {
2352: $runon = ' checked="checked" ';
2353: $runoff = ' ';
2354: } else {
2355: $runoff = ' checked="checked" ';
2356: $runon = ' ';
2357: }
2358: }
1.129 raeburn 2359: if (exists($settings->{'co-owners'})) {
2360: if ($settings->{'co-owners'} eq '0') {
2361: $coownersoff = ' checked="checked" ';
2362: $coownerson = ' ';
2363: } else {
2364: $coownerson = ' checked="checked" ';
2365: $coownersoff = ' ';
2366: }
2367: } else {
2368: $coownersoff = ' checked="checked" ';
2369: $coownerson = ' ';
2370: }
1.3 raeburn 2371: if (exists($settings->{'sender_domain'})) {
2372: $defdom = $settings->{'sender_domain'};
2373: }
1.14 raeburn 2374: } else {
2375: if ($autorun) {
2376: $runon = ' checked="checked" ';
2377: $runoff = ' ';
2378: } else {
2379: $runoff = ' checked="checked" ';
2380: $runon = ' ';
2381: }
1.3 raeburn 2382: }
2383: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2384: my $notif_sender;
2385: if (ref($settings) eq 'HASH') {
2386: $notif_sender = $settings->{'sender_uname'};
2387: }
1.3 raeburn 2388: my $datatable='<tr class="LC_odd_row">'.
2389: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2390: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2391: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2392: $runon.' value="1" />'.&mt('Yes').'</label> '.
2393: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2394: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2395: '</tr><tr>'.
2396: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2397: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2398: &mt('username').': '.
2399: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2400: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2401: ': '.$domform.'</span></td></tr>'.
2402: '<tr class="LC_odd_row">'.
2403: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2404: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2405: '<input type="radio" name="autoassign_coowners"'.
2406: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2407: '<label><input type="radio" name="autoassign_coowners"'.
2408: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2409: '</tr>';
2410: $$rowtotal += 3;
1.3 raeburn 2411: return $datatable;
2412: }
2413:
2414: sub print_autoupdate {
1.30 raeburn 2415: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2416: my $datatable;
2417: if ($position eq 'top') {
2418: my $updateon = ' ';
2419: my $updateoff = ' checked="checked" ';
2420: my $classlistson = ' ';
2421: my $classlistsoff = ' checked="checked" ';
2422: if (ref($settings) eq 'HASH') {
2423: if ($settings->{'run'} eq '1') {
2424: $updateon = $updateoff;
2425: $updateoff = ' ';
2426: }
2427: if ($settings->{'classlists'} eq '1') {
2428: $classlistson = $classlistsoff;
2429: $classlistsoff = ' ';
2430: }
2431: }
2432: my %title = (
2433: run => 'Auto-update active?',
2434: classlists => 'Update information in classlists?',
2435: );
2436: $datatable = '<tr class="LC_odd_row">'.
2437: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2438: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2439: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2440: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2441: '<label><input type="radio" name="autoupdate_run"'.
2442: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2443: '</tr><tr>'.
2444: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2445: '<td class="LC_right_item"><span class="LC_nobreak">'.
2446: '<label><input type="radio" name="classlists"'.
2447: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2448: '<label><input type="radio" name="classlists"'.
2449: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2450: '</tr>';
1.30 raeburn 2451: $$rowtotal += 2;
1.131 raeburn 2452: } elsif ($position eq 'middle') {
2453: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2454: my $numinrow = 3;
2455: my $locknamesettings;
2456: $datatable .= &insttypes_row($settings,$types,$usertypes,
2457: $dom,$numinrow,$othertitle,
2458: 'lockablenames');
2459: $$rowtotal ++;
1.3 raeburn 2460: } else {
1.44 raeburn 2461: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2462: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2463: 'permanentemail','id');
1.33 raeburn 2464: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2465: my $numrows = 0;
1.26 raeburn 2466: if (ref($types) eq 'ARRAY') {
2467: if (@{$types} > 0) {
2468: $datatable =
2469: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2470: \@fields,$types,\$numrows);
1.30 raeburn 2471: $$rowtotal += @{$types};
1.26 raeburn 2472: }
1.3 raeburn 2473: }
2474: $datatable .=
2475: &usertype_update_row($settings,{'default' => $othertitle},
2476: \%fieldtitles,\@fields,['default'],
2477: \$numrows);
1.30 raeburn 2478: $$rowtotal ++;
1.3 raeburn 2479: }
2480: return $datatable;
2481: }
2482:
1.125 raeburn 2483: sub print_autocreate {
2484: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2485: my (%createon,%createoff,%currhash);
1.125 raeburn 2486: my @types = ('xml','req');
2487: if (ref($settings) eq 'HASH') {
2488: foreach my $item (@types) {
2489: $createoff{$item} = ' checked="checked" ';
2490: $createon{$item} = ' ';
2491: if (exists($settings->{$item})) {
2492: if ($settings->{$item}) {
2493: $createon{$item} = ' checked="checked" ';
2494: $createoff{$item} = ' ';
2495: }
2496: }
2497: }
1.210 raeburn 2498: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2499: $currhash{$settings->{'xmldc'}} = 1;
2500: }
1.125 raeburn 2501: } else {
2502: foreach my $item (@types) {
2503: $createoff{$item} = ' checked="checked" ';
2504: $createon{$item} = ' ';
2505: }
2506: }
2507: $$rowtotal += 2;
1.191 raeburn 2508: my $numinrow = 2;
1.125 raeburn 2509: my $datatable='<tr class="LC_odd_row">'.
2510: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2511: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2512: '<input type="radio" name="autocreate_xml"'.
2513: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2514: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2515: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2516: '</td></tr><tr>'.
2517: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2518: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2519: '<input type="radio" name="autocreate_req"'.
2520: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2521: '<label><input type="radio" name="autocreate_req"'.
2522: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2523: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2524: 'autocreate_xmldc',%currhash);
1.247 raeburn 2525: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2526: if ($numdc > 1) {
1.247 raeburn 2527: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2528: '</td><td class="LC_left_item">';
1.125 raeburn 2529: } else {
1.247 raeburn 2530: $datatable .= &mt('Course creation processed as:').
2531: '</td><td class="LC_right_item">';
1.125 raeburn 2532: }
1.247 raeburn 2533: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2534: $$rowtotal += $rows;
1.125 raeburn 2535: return $datatable;
2536: }
2537:
1.23 raeburn 2538: sub print_directorysrch {
1.30 raeburn 2539: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2540: my $srchon = ' ';
2541: my $srchoff = ' checked="checked" ';
1.25 raeburn 2542: my ($exacton,$containson,$beginson);
1.24 raeburn 2543: my $localon = ' ';
2544: my $localoff = ' checked="checked" ';
1.23 raeburn 2545: if (ref($settings) eq 'HASH') {
2546: if ($settings->{'available'} eq '1') {
2547: $srchon = $srchoff;
2548: $srchoff = ' ';
2549: }
1.24 raeburn 2550: if ($settings->{'localonly'} eq '1') {
2551: $localon = $localoff;
2552: $localoff = ' ';
2553: }
1.25 raeburn 2554: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2555: foreach my $type (@{$settings->{'searchtypes'}}) {
2556: if ($type eq 'exact') {
2557: $exacton = ' checked="checked" ';
2558: } elsif ($type eq 'contains') {
2559: $containson = ' checked="checked" ';
2560: } elsif ($type eq 'begins') {
2561: $beginson = ' checked="checked" ';
2562: }
2563: }
2564: } else {
2565: if ($settings->{'searchtypes'} eq 'exact') {
2566: $exacton = ' checked="checked" ';
2567: } elsif ($settings->{'searchtypes'} eq 'contains') {
2568: $containson = ' checked="checked" ';
2569: } elsif ($settings->{'searchtypes'} eq 'specify') {
2570: $exacton = ' checked="checked" ';
2571: $containson = ' checked="checked" ';
2572: }
1.23 raeburn 2573: }
2574: }
2575: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2576: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2577:
2578: my $numinrow = 4;
1.26 raeburn 2579: my $cansrchrow = 0;
1.23 raeburn 2580: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2581: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2582: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2583: '<input type="radio" name="dirsrch_available"'.
2584: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2585: '<label><input type="radio" name="dirsrch_available"'.
2586: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2587: '</tr><tr>'.
1.30 raeburn 2588: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2589: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2590: '<input type="radio" name="dirsrch_localonly"'.
2591: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2592: '<label><input type="radio" name="dirsrch_localonly"'.
2593: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2594: '</tr>';
1.30 raeburn 2595: $$rowtotal += 2;
1.26 raeburn 2596: if (ref($usertypes) eq 'HASH') {
2597: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2598: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2599: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2600: $cansrchrow = 1;
2601: }
2602: }
2603: if ($cansrchrow) {
1.30 raeburn 2604: $$rowtotal ++;
1.26 raeburn 2605: $datatable .= '<tr>';
2606: } else {
2607: $datatable .= '<tr class="LC_odd_row">';
2608: }
1.30 raeburn 2609: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2610: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2611: foreach my $title (@{$titleorder}) {
2612: if (defined($searchtitles->{$title})) {
2613: my $check = ' ';
1.93 raeburn 2614: if (ref($settings) eq 'HASH') {
1.39 raeburn 2615: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2616: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2617: $check = ' checked="checked" ';
2618: }
1.25 raeburn 2619: }
2620: }
2621: $datatable .= '<td class="LC_left_item">'.
2622: '<span class="LC_nobreak"><label>'.
2623: '<input type="checkbox" name="searchby" '.
2624: 'value="'.$title.'"'.$check.'/>'.
2625: $searchtitles->{$title}.'</label></span></td>';
2626: }
2627: }
1.26 raeburn 2628: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2629: $$rowtotal ++;
1.26 raeburn 2630: if ($cansrchrow) {
2631: $datatable .= '<tr class="LC_odd_row">';
2632: } else {
2633: $datatable .= '<tr>';
2634: }
1.30 raeburn 2635: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2636: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2637: '<span class="LC_nobreak"><label>'.
2638: '<input type="checkbox" name="searchtypes" '.
2639: $exacton.' value="exact" />'.&mt('Exact match').
2640: '</label> '.
2641: '<label><input type="checkbox" name="searchtypes" '.
2642: $beginson.' value="begins" />'.&mt('Begins with').
2643: '</label> '.
2644: '<label><input type="checkbox" name="searchtypes" '.
2645: $containson.' value="contains" />'.&mt('Contains').
2646: '</label></span></td></tr>';
1.30 raeburn 2647: $$rowtotal ++;
1.25 raeburn 2648: return $datatable;
2649: }
2650:
1.28 raeburn 2651: sub print_contacts {
1.30 raeburn 2652: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2653: my $datatable;
2654: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2655: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2656: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2657: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2658: foreach my $type (@mailings) {
2659: $otheremails{$type} = '';
2660: }
1.134 raeburn 2661: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2662: if (ref($settings) eq 'HASH') {
2663: foreach my $item (@contacts) {
2664: if (exists($settings->{$item})) {
2665: $to{$item} = $settings->{$item};
2666: }
2667: }
2668: foreach my $type (@mailings) {
2669: if (exists($settings->{$type})) {
2670: if (ref($settings->{$type}) eq 'HASH') {
2671: foreach my $item (@contacts) {
2672: if ($settings->{$type}{$item}) {
2673: $checked{$type}{$item} = ' checked="checked" ';
2674: }
2675: }
2676: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2677: if ($type eq 'helpdeskmail') {
2678: $bccemails{$type} = $settings->{$type}{'bcc'};
2679: }
1.28 raeburn 2680: }
1.89 raeburn 2681: } elsif ($type eq 'lonstatusmail') {
2682: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2683: }
2684: }
2685: } else {
2686: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2687: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2688: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2689: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2690: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2691: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2692: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2693: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2694: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2695: }
2696: my ($titles,$short_titles) = &contact_titles();
2697: my $rownum = 0;
2698: my $css_class;
2699: foreach my $item (@contacts) {
1.69 raeburn 2700: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2701: $datatable .= '<tr'.$css_class.'>'.
2702: '<td><span class="LC_nobreak">'.$titles->{$item}.
2703: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2704: '<input type="text" name="'.$item.'" value="'.
2705: $to{$item}.'" /></td></tr>';
1.203 raeburn 2706: $rownum ++;
1.28 raeburn 2707: }
2708: foreach my $type (@mailings) {
1.69 raeburn 2709: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2710: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2711: '<td><span class="LC_nobreak">'.
2712: $titles->{$type}.': </span></td>'.
1.28 raeburn 2713: '<td class="LC_left_item">'.
2714: '<span class="LC_nobreak">';
2715: foreach my $item (@contacts) {
2716: $datatable .= '<label>'.
2717: '<input type="checkbox" name="'.$type.'"'.
2718: $checked{$type}{$item}.
2719: ' value="'.$item.'" />'.$short_titles->{$item}.
2720: '</label> ';
2721: }
2722: $datatable .= '</span><br />'.&mt('Others').': '.
2723: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2724: 'value="'.$otheremails{$type}.'" />';
2725: if ($type eq 'helpdeskmail') {
1.136 raeburn 2726: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2727: '<input type="text" name="'.$type.'_bcc" '.
2728: 'value="'.$bccemails{$type}.'" />';
2729: }
2730: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2731: $rownum ++;
1.28 raeburn 2732: }
1.203 raeburn 2733: my %choices;
2734: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2735: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2736: &mt('LON-CAPA core group - MSU'),600,500));
2737: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2738: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2739: &mt('LON-CAPA core group - MSU'),600,500));
2740: my @toggles = ('reporterrors','reportupdates');
2741: my %defaultchecked = ('reporterrors' => 'on',
2742: 'reportupdates' => 'on');
2743: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2744: \%choices,$rownum);
2745: $datatable .= $reports;
1.30 raeburn 2746: $$rowtotal += $rownum;
1.28 raeburn 2747: return $datatable;
2748: }
2749:
1.118 jms 2750: sub print_helpsettings {
1.168 raeburn 2751: my ($dom,$confname,$settings,$rowtotal) = @_;
2752: my ($datatable,$itemcount);
1.166 raeburn 2753: $itemcount = 1;
1.168 raeburn 2754: my (%choices,%defaultchecked,@toggles);
2755: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2756: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2757: &mt('LON-CAPA bug tracker'),600,500));
2758: %defaultchecked = ('submitbugs' => 'on');
2759: @toggles = ('submitbugs',);
1.166 raeburn 2760:
1.168 raeburn 2761: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2762: \%choices,$itemcount);
1.166 raeburn 2763: return $datatable;
1.121 raeburn 2764: }
2765:
2766: sub radiobutton_prefs {
1.192 raeburn 2767: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2768: $additional) = @_;
1.121 raeburn 2769: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2770: (ref($choices) eq 'HASH'));
2771:
1.170 raeburn 2772: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2773:
2774: foreach my $item (@{$toggles}) {
2775: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2776: $checkedon{$item} = ' checked="checked" ';
2777: $checkedoff{$item} = ' ';
1.121 raeburn 2778: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2779: $checkedoff{$item} = ' checked="checked" ';
2780: $checkedon{$item} = ' ';
2781: }
2782: }
2783: if (ref($settings) eq 'HASH') {
1.121 raeburn 2784: foreach my $item (@{$toggles}) {
1.118 jms 2785: if ($settings->{$item} eq '1') {
2786: $checkedon{$item} = ' checked="checked" ';
2787: $checkedoff{$item} = ' ';
2788: } elsif ($settings->{$item} eq '0') {
2789: $checkedoff{$item} = ' checked="checked" ';
2790: $checkedon{$item} = ' ';
2791: }
2792: }
1.121 raeburn 2793: }
1.192 raeburn 2794: if ($onclick) {
2795: $onclick = ' onclick="'.$onclick.'"';
2796: }
1.121 raeburn 2797: foreach my $item (@{$toggles}) {
1.118 jms 2798: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2799: $datatable .=
1.192 raeburn 2800: '<tr'.$css_class.'><td valign="top">'.
2801: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2802: '</span></td>'.
2803: '<td class="LC_right_item"><span class="LC_nobreak">'.
2804: '<label><input type="radio" name="'.
1.192 raeburn 2805: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2806: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2807: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2808: '</span>'.$additional.
2809: '</td>'.
1.118 jms 2810: '</tr>';
2811: $itemcount ++;
1.121 raeburn 2812: }
2813: return ($datatable,$itemcount);
2814: }
2815:
2816: sub print_coursedefaults {
1.139 raeburn 2817: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2818: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2819: my $itemcount = 1;
1.192 raeburn 2820: my %choices = &Apache::lonlocal::texthash (
2821: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2822: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2823: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2824: coursecredits => 'Credits can be specified for courses',
2825: );
1.198 raeburn 2826: my %staticdefaults = (
2827: anonsurvey_threshold => 10,
2828: uploadquota => 500,
2829: );
1.139 raeburn 2830: if ($position eq 'top') {
2831: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2832: @toggles = ('canuse_pdfforms');
1.139 raeburn 2833: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2834: \%choices,$itemcount);
1.139 raeburn 2835: } else {
2836: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2837: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2838: %curruploadquota);
1.192 raeburn 2839: my $currusecredits = 0;
1.216 raeburn 2840: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2841: if (ref($settings) eq 'HASH') {
2842: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2843: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2844: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2845: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2846: }
2847: }
1.192 raeburn 2848: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2849: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2850: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2851: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2852: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2853: ($def_textbook_credits ne '')) {
1.192 raeburn 2854: $currusecredits = 1;
2855: }
2856: }
1.139 raeburn 2857: }
2858: if (!$currdefresponder) {
1.198 raeburn 2859: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2860: } elsif ($currdefresponder < 1) {
2861: $currdefresponder = 1;
2862: }
1.198 raeburn 2863: foreach my $type (@types) {
2864: if ($curruploadquota{$type} eq '') {
2865: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2866: }
2867: }
1.139 raeburn 2868: $datatable .=
1.192 raeburn 2869: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2870: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2871: '</span></td>'.
2872: '<td class="LC_right_item"><span class="LC_nobreak">'.
2873: '<input type="text" name="anonsurvey_threshold"'.
2874: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2875: '</td></tr>'."\n";
2876: $itemcount ++;
2877: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2878: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2879: $choices{'uploadquota'}.
2880: '</span></td>'.
2881: '<td align="right" class="LC_right_item">'.
2882: '<table><tr>';
1.198 raeburn 2883: foreach my $type (@types) {
2884: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2885: '<input type="text" name="uploadquota_'.$type.'"'.
2886: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2887: }
2888: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2889: $itemcount ++;
1.236 raeburn 2890: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 2891: my $display = 'none';
1.192 raeburn 2892: if ($currusecredits) {
2893: $display = 'block';
2894: }
2895: my $additional = '<div id="credits" style="display: '.$display.'">'.
2896: '<span class="LC_nobreak">'.
2897: &mt('Default credits for official courses [_1]',
2898: '<input type="text" name="official_credits" value="'.
2899: $def_official_credits.'" size="3" />').
2900: '</span><br />'.
2901: '<span class="LC_nobreak">'.
2902: &mt('Default credits for unofficial courses [_1]',
2903: '<input type="text" name="unofficial_credits" value="'.
2904: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2905: '</span><br />'.
2906: '<span class="LC_nobreak">'.
2907: &mt('Default credits for textbook courses [_1]',
2908: '<input type="text" name="textbook_credits" value="'.
2909: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2910: '</span></div>'."\n";
2911: %defaultchecked = ('coursecredits' => 'off');
2912: @toggles = ('coursecredits');
2913: my $current = {
2914: 'coursecredits' => $currusecredits,
2915: };
2916: (my $table,$itemcount) =
2917: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2918: \%choices,$itemcount,$onclick,$additional);
2919: $datatable .= $table;
1.230 raeburn 2920: $itemcount ++;
1.139 raeburn 2921: }
1.192 raeburn 2922: $$rowtotal += $itemcount;
1.121 raeburn 2923: return $datatable;
1.118 jms 2924: }
2925:
1.231 raeburn 2926: sub print_selfenrollment {
2927: my ($position,$dom,$settings,$rowtotal) = @_;
2928: my ($css_class,$datatable);
2929: my $itemcount = 1;
2930: my @types = ('official','unofficial','community','textbook');
2931: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 2932: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2933: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 2934: my @rows;
2935: my $key;
2936: if ($position eq 'top') {
2937: $key = 'admin';
2938: if (ref($rowsref) eq 'ARRAY') {
2939: @rows = @{$rowsref};
2940: }
2941: } elsif ($position eq 'middle') {
2942: $key = 'default';
2943: @rows = ('types','registered','approval','limit');
2944: }
2945: foreach my $row (@rows) {
2946: if (defined($titlesref->{$row})) {
2947: $itemcount ++;
2948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2949: $datatable .= '<tr'.$css_class.'>'.
2950: '<td>'.$titlesref->{$row}.'</td>'.
2951: '<td class="LC_left_item">'.
2952: '<table><tr>';
2953: my (%current,%currentcap);
2954: if (ref($settings) eq 'HASH') {
2955: if (ref($settings->{$key}) eq 'HASH') {
2956: foreach my $type (@types) {
2957: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2958: $current{$type} = $settings->{$key}->{$type}->{$row};
2959: }
2960: if (($row eq 'limit') && ($key eq 'default')) {
2961: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2962: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2963: }
2964: }
2965: }
2966: }
2967: }
2968: my %roles = (
2969: '0' => &Apache::lonnet::plaintext('dc'),
2970: );
2971:
2972: foreach my $type (@types) {
2973: unless (($row eq 'registered') && ($key eq 'default')) {
2974: $datatable .= '<th>'.&mt($type).'</th>';
2975: }
2976: }
2977: unless (($row eq 'registered') && ($key eq 'default')) {
2978: $datatable .= '</tr><tr>';
2979: }
2980: foreach my $type (@types) {
2981: if ($type eq 'community') {
2982: $roles{'1'} = &mt('Community personnel');
2983: } else {
2984: $roles{'1'} = &mt('Course personnel');
2985: }
2986: $datatable .= '<td style="vertical-align: top">';
2987: if ($position eq 'top') {
2988: my %checked;
2989: if ($current{$type} eq '0') {
2990: $checked{'0'} = ' checked="checked"';
2991: } else {
2992: $checked{'1'} = ' checked="checked"';
2993: }
2994: foreach my $role ('1','0') {
2995: $datatable .= '<span class="LC_nobreak"><label>'.
2996: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2997: 'value="'.$role.'"'.$checked{$role}.' />'.
2998: $roles{$role}.'</label></span> ';
2999: }
3000: } else {
3001: if ($row eq 'types') {
3002: my %checked;
3003: if ($current{$type} =~ /^(all|dom)$/) {
3004: $checked{$1} = ' checked="checked"';
3005: } else {
3006: $checked{''} = ' checked="checked"';
3007: }
3008: foreach my $val ('','dom','all') {
3009: $datatable .= '<span class="LC_nobreak"><label>'.
3010: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3011: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3012: }
3013: } elsif ($row eq 'registered') {
3014: my %checked;
3015: if ($current{$type} eq '1') {
3016: $checked{'1'} = ' checked="checked"';
3017: } else {
3018: $checked{'0'} = ' checked="checked"';
3019: }
3020: foreach my $val ('0','1') {
3021: $datatable .= '<span class="LC_nobreak"><label>'.
3022: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3023: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3024: }
3025: } elsif ($row eq 'approval') {
3026: my %checked;
3027: if ($current{$type} =~ /^([12])$/) {
3028: $checked{$1} = ' checked="checked"';
3029: } else {
3030: $checked{'0'} = ' checked="checked"';
3031: }
3032: for my $val (0..2) {
3033: $datatable .= '<span class="LC_nobreak"><label>'.
3034: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3035: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3036: }
3037: } elsif ($row eq 'limit') {
3038: my %checked;
3039: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3040: $checked{$1} = ' checked="checked"';
3041: } else {
3042: $checked{'none'} = ' checked="checked"';
3043: }
3044: my $cap;
3045: if ($currentcap{$type} =~ /^\d+$/) {
3046: $cap = $currentcap{$type};
3047: }
3048: foreach my $val ('none','allstudents','selfenrolled') {
3049: $datatable .= '<span class="LC_nobreak"><label>'.
3050: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3051: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3052: }
3053: $datatable .= '<br />'.
3054: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3055: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3056: '</span>';
3057: }
3058: }
3059: $datatable .= '</td>';
3060: }
3061: $datatable .= '</tr>';
3062: }
3063: $datatable .= '</table></td></tr>';
3064: }
3065: } elsif ($position eq 'bottom') {
1.235 raeburn 3066: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3067: }
3068: $$rowtotal += $itemcount;
3069: return $datatable;
3070: }
3071:
3072: sub print_validation_rows {
3073: my ($caller,$dom,$settings,$rowtotal) = @_;
3074: my ($itemsref,$namesref,$fieldsref);
3075: if ($caller eq 'selfenroll') {
3076: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3077: } elsif ($caller eq 'requestcourses') {
3078: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3079: }
3080: my %currvalidation;
3081: if (ref($settings) eq 'HASH') {
3082: if (ref($settings->{'validation'}) eq 'HASH') {
3083: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3084: }
1.235 raeburn 3085: }
3086: my $datatable;
3087: my $itemcount = 0;
3088: foreach my $item (@{$itemsref}) {
3089: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3090: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3091: $namesref->{$item}.
3092: '</span></td>'.
3093: '<td class="LC_left_item">';
3094: if (($item eq 'url') || ($item eq 'button')) {
3095: $datatable .= '<span class="LC_nobreak">'.
3096: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3097: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3098: } elsif ($item eq 'fields') {
3099: my @currfields;
3100: if (ref($currvalidation{$item}) eq 'ARRAY') {
3101: @currfields = @{$currvalidation{$item}};
3102: }
3103: foreach my $field (@{$fieldsref}) {
3104: my $check = '';
3105: if (grep(/^\Q$field\E$/,@currfields)) {
3106: $check = ' checked="checked"';
3107: }
3108: $datatable .= '<span class="LC_nobreak"><label>'.
3109: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3110: ' value="'.$field.'"'.$check.' />'.$field.
3111: '</label></span> ';
3112: }
3113: } elsif ($item eq 'markup') {
3114: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3115: $currvalidation{$item}.
1.231 raeburn 3116: '</textarea>';
1.235 raeburn 3117: }
3118: $datatable .= '</td></tr>'."\n";
3119: if (ref($rowtotal)) {
1.231 raeburn 3120: $itemcount ++;
3121: }
3122: }
1.235 raeburn 3123: if ($caller eq 'requestcourses') {
3124: my %currhash;
1.248 raeburn 3125: if (ref($settings) eq 'HASH') {
3126: if (ref($settings->{'validation'}) eq 'HASH') {
3127: if ($settings->{'validation'}{'dc'} ne '') {
3128: $currhash{$settings->{'validation'}{'dc'}} = 1;
3129: }
1.235 raeburn 3130: }
3131: }
3132: my $numinrow = 2;
3133: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3134: 'validationdc',%currhash);
1.247 raeburn 3135: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3136: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3137: if ($numdc > 1) {
1.247 raeburn 3138: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3139: } else {
1.247 raeburn 3140: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3141: }
1.247 raeburn 3142: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3143: $itemcount ++;
3144: }
3145: if (ref($rowtotal)) {
3146: $$rowtotal += $itemcount;
3147: }
1.231 raeburn 3148: return $datatable;
3149: }
3150:
1.137 raeburn 3151: sub print_usersessions {
3152: my ($position,$dom,$settings,$rowtotal) = @_;
3153: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3154: my (%by_ip,%by_location,@intdoms);
3155: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3156:
3157: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3158: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3159: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3160: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3161: my $itemcount = 1;
3162: if ($position eq 'top') {
1.152 raeburn 3163: if (keys(%serverhomes) > 1) {
1.145 raeburn 3164: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3165: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3166: } else {
1.140 raeburn 3167: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3168: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3169: }
1.137 raeburn 3170: } else {
1.145 raeburn 3171: if (keys(%by_location) == 0) {
3172: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3173: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3174: } else {
3175: my %lt = &usersession_titles();
3176: my $numinrow = 5;
3177: my $prefix;
3178: my @types;
3179: if ($position eq 'bottom') {
3180: $prefix = 'remote';
3181: @types = ('version','excludedomain','includedomain');
3182: } else {
3183: $prefix = 'hosted';
3184: @types = ('excludedomain','includedomain');
3185: }
3186: my (%current,%checkedon,%checkedoff);
3187: my @lcversions = &Apache::lonnet::all_loncaparevs();
3188: my @locations = sort(keys(%by_location));
3189: foreach my $type (@types) {
3190: $checkedon{$type} = '';
3191: $checkedoff{$type} = ' checked="checked"';
3192: }
3193: if (ref($settings) eq 'HASH') {
3194: if (ref($settings->{$prefix}) eq 'HASH') {
3195: foreach my $key (keys(%{$settings->{$prefix}})) {
3196: $current{$key} = $settings->{$prefix}{$key};
3197: if ($key eq 'version') {
3198: if ($current{$key} ne '') {
3199: $checkedon{$key} = ' checked="checked"';
3200: $checkedoff{$key} = '';
3201: }
3202: } elsif (ref($current{$key}) eq 'ARRAY') {
3203: $checkedon{$key} = ' checked="checked"';
3204: $checkedoff{$key} = '';
3205: }
1.137 raeburn 3206: }
3207: }
3208: }
1.145 raeburn 3209: foreach my $type (@types) {
3210: next if ($type ne 'version' && !@locations);
3211: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3212: $datatable .= '<tr'.$css_class.'>
3213: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3214: <span class="LC_nobreak">
3215: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3216: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3217: if ($type eq 'version') {
3218: my $selector = '<select name="'.$prefix.'_version">';
3219: foreach my $version (@lcversions) {
3220: my $selected = '';
3221: if ($current{'version'} eq $version) {
3222: $selected = ' selected="selected"';
3223: }
3224: $selector .= ' <option value="'.$version.'"'.
3225: $selected.'>'.$version.'</option>';
3226: }
3227: $selector .= '</select> ';
3228: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3229: } else {
3230: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3231: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3232: ' />'.(' 'x2).
3233: '<input type="button" value="'.&mt('uncheck all').'" '.
3234: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3235: "\n".
3236: '</div><div><table>';
3237: my $rem;
3238: for (my $i=0; $i<@locations; $i++) {
3239: my ($showloc,$value,$checkedtype);
3240: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3241: my $ip = $by_location{$locations[$i]}->[0];
3242: if (ref($by_ip{$ip}) eq 'ARRAY') {
3243: $value = join(':',@{$by_ip{$ip}});
3244: $showloc = join(', ',@{$by_ip{$ip}});
3245: if (ref($current{$type}) eq 'ARRAY') {
3246: foreach my $loc (@{$by_ip{$ip}}) {
3247: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3248: $checkedtype = ' checked="checked"';
3249: last;
3250: }
3251: }
1.138 raeburn 3252: }
3253: }
3254: }
1.145 raeburn 3255: $rem = $i%($numinrow);
3256: if ($rem == 0) {
3257: if ($i > 0) {
3258: $datatable .= '</tr>';
3259: }
3260: $datatable .= '<tr>';
3261: }
3262: $datatable .= '<td class="LC_left_item">'.
3263: '<span class="LC_nobreak"><label>'.
3264: '<input type="checkbox" name="'.$prefix.'_'.$type.
3265: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3266: '</label></span></td>';
1.137 raeburn 3267: }
1.145 raeburn 3268: $rem = @locations%($numinrow);
3269: my $colsleft = $numinrow - $rem;
3270: if ($colsleft > 1 ) {
3271: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3272: ' </td>';
3273: } elsif ($colsleft == 1) {
3274: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3275: }
1.145 raeburn 3276: $datatable .= '</tr></table>';
1.137 raeburn 3277: }
1.145 raeburn 3278: $datatable .= '</td></tr>';
3279: $itemcount ++;
1.137 raeburn 3280: }
3281: }
3282: }
3283: $$rowtotal += $itemcount;
3284: return $datatable;
3285: }
3286:
1.138 raeburn 3287: sub build_location_hashes {
3288: my ($intdoms,$by_ip,$by_location) = @_;
3289: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3290: (ref($by_location) eq 'HASH'));
3291: my %iphost = &Apache::lonnet::get_iphost();
3292: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3293: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3294: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3295: foreach my $id (@{$iphost{$primary_ip}}) {
3296: my $intdom = &Apache::lonnet::internet_dom($id);
3297: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3298: push(@{$intdoms},$intdom);
3299: }
3300: }
3301: }
3302: foreach my $ip (keys(%iphost)) {
3303: if (ref($iphost{$ip}) eq 'ARRAY') {
3304: foreach my $id (@{$iphost{$ip}}) {
3305: my $location = &Apache::lonnet::internet_dom($id);
3306: if ($location) {
3307: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3308: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3309: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3310: push(@{$by_ip->{$ip}},$location);
3311: }
3312: } else {
3313: $by_ip->{$ip} = [$location];
3314: }
3315: }
3316: }
3317: }
3318: }
3319: foreach my $ip (sort(keys(%{$by_ip}))) {
3320: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3321: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3322: my $first = $by_ip->{$ip}->[0];
3323: if (ref($by_location->{$first}) eq 'ARRAY') {
3324: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3325: push(@{$by_location->{$first}},$ip);
3326: }
3327: } else {
3328: $by_location->{$first} = [$ip];
3329: }
3330: }
3331: }
3332: return;
3333: }
3334:
1.145 raeburn 3335: sub current_offloads_to {
3336: my ($dom,$settings,$servers) = @_;
3337: my (%spareid,%otherdomconfigs);
1.152 raeburn 3338: if (ref($servers) eq 'HASH') {
1.145 raeburn 3339: foreach my $lonhost (sort(keys(%{$servers}))) {
3340: my $gotspares;
1.152 raeburn 3341: if (ref($settings) eq 'HASH') {
3342: if (ref($settings->{'spares'}) eq 'HASH') {
3343: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3344: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3345: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3346: $gotspares = 1;
3347: }
1.145 raeburn 3348: }
3349: }
3350: unless ($gotspares) {
3351: my $gotspares;
3352: my $serverhomeID =
3353: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3354: my $serverhomedom =
3355: &Apache::lonnet::host_domain($serverhomeID);
3356: if ($serverhomedom ne $dom) {
3357: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3358: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3359: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3360: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3361: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3362: $gotspares = 1;
3363: }
3364: }
3365: } else {
3366: $otherdomconfigs{$serverhomedom} =
3367: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3368: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3369: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3370: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3371: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3372: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3373: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3374: $gotspares = 1;
3375: }
3376: }
3377: }
3378: }
3379: }
3380: }
3381: }
3382: unless ($gotspares) {
3383: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3384: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3385: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3386: } else {
3387: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3388: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3389: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3390: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3391: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3392: } else {
1.150 raeburn 3393: my %what = (
3394: spareid => 1,
3395: );
3396: my ($result,$returnhash) =
3397: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3398: if ($result eq 'ok') {
3399: if (ref($returnhash) eq 'HASH') {
3400: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3401: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3402: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3403: }
3404: }
1.145 raeburn 3405: }
3406: }
3407: }
3408: }
3409: }
3410: }
3411: return %spareid;
3412: }
3413:
3414: sub spares_row {
1.152 raeburn 3415: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3416: my $css_class;
3417: my $numinrow = 4;
3418: my $itemcount = 1;
3419: my $datatable;
1.152 raeburn 3420: my %typetitles = &sparestype_titles();
3421: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3422: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3423: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3424: my ($othercontrol,$serverdom);
3425: if ($serverhome ne $server) {
3426: $serverdom = &Apache::lonnet::host_domain($serverhome);
3427: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3428: } else {
3429: $serverdom = &Apache::lonnet::host_domain($server);
3430: if ($serverdom ne $dom) {
3431: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3432: }
3433: }
3434: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3435: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3436: $datatable .= '<tr'.$css_class.'>
3437: <td rowspan="2">
1.183 bisitz 3438: <span class="LC_nobreak">'.
3439: &mt('[_1] when busy, offloads to:'
3440: ,'<b>'.$server.'</b>').
3441: "\n";
1.145 raeburn 3442: my (%current,%canselect);
1.152 raeburn 3443: my @choices =
3444: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3445: foreach my $type ('primary','default') {
3446: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3447: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3448: my @spares = @{$spareid->{$server}{$type}};
3449: if (@spares > 0) {
1.152 raeburn 3450: if ($othercontrol) {
3451: $current{$type} = join(', ',@spares);
3452: } else {
3453: $current{$type} .= '<table>';
3454: my $numspares = scalar(@spares);
3455: for (my $i=0; $i<@spares; $i++) {
3456: my $rem = $i%($numinrow);
3457: if ($rem == 0) {
3458: if ($i > 0) {
3459: $current{$type} .= '</tr>';
3460: }
3461: $current{$type} .= '<tr>';
1.145 raeburn 3462: }
1.152 raeburn 3463: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
3464: $spareid->{$server}{$type}[$i].
3465: '</label></td>'."\n";
3466: }
3467: my $rem = @spares%($numinrow);
3468: my $colsleft = $numinrow - $rem;
3469: if ($colsleft > 1 ) {
3470: $current{$type} .= '<td colspan="'.$colsleft.
3471: '" class="LC_left_item">'.
3472: ' </td>';
3473: } elsif ($colsleft == 1) {
3474: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3475: }
1.152 raeburn 3476: $current{$type} .= '</tr></table>';
1.150 raeburn 3477: }
1.145 raeburn 3478: }
3479: }
3480: if ($current{$type} eq '') {
3481: $current{$type} = &mt('None specified');
3482: }
1.152 raeburn 3483: if ($othercontrol) {
3484: if ($type eq 'primary') {
3485: $canselect{$type} = $othercontrol;
3486: }
3487: } else {
3488: $canselect{$type} =
3489: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3490: '<select name="newspare_'.$type.'_'.$server.'" '.
3491: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3492: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3493: if (@choices > 0) {
3494: foreach my $lonhost (@choices) {
3495: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3496: }
3497: }
3498: $canselect{$type} .= '</select>'."\n";
3499: }
3500: } else {
3501: $current{$type} = &mt('Could not be determined');
3502: if ($type eq 'primary') {
3503: $canselect{$type} = $othercontrol;
3504: }
1.145 raeburn 3505: }
1.152 raeburn 3506: if ($type eq 'default') {
3507: $datatable .= '<tr'.$css_class.'>';
3508: }
3509: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3510: '<td>'.$current{$type}.'</td>'."\n".
3511: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3512: }
3513: $itemcount ++;
3514: }
3515: }
3516: $$rowtotal += $itemcount;
3517: return $datatable;
3518: }
3519:
1.152 raeburn 3520: sub possible_newspares {
3521: my ($server,$currspares,$serverhomes,$altids) = @_;
3522: my $serverhostname = &Apache::lonnet::hostname($server);
3523: my %excluded;
3524: if ($serverhostname ne '') {
3525: %excluded = (
3526: $serverhostname => 1,
3527: );
3528: }
3529: if (ref($currspares) eq 'HASH') {
3530: foreach my $type (keys(%{$currspares})) {
3531: if (ref($currspares->{$type}) eq 'ARRAY') {
3532: if (@{$currspares->{$type}} > 0) {
3533: foreach my $curr (@{$currspares->{$type}}) {
3534: my $hostname = &Apache::lonnet::hostname($curr);
3535: $excluded{$hostname} = 1;
3536: }
3537: }
3538: }
3539: }
3540: }
3541: my @choices;
3542: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3543: if (keys(%{$serverhomes}) > 1) {
3544: foreach my $name (sort(keys(%{$serverhomes}))) {
3545: unless ($excluded{$name}) {
3546: if (exists($altids->{$serverhomes->{$name}})) {
3547: push(@choices,$altids->{$serverhomes->{$name}});
3548: } else {
3549: push(@choices,$serverhomes->{$name});
1.145 raeburn 3550: }
3551: }
3552: }
3553: }
3554: }
1.152 raeburn 3555: return sort(@choices);
1.145 raeburn 3556: }
3557:
1.150 raeburn 3558: sub print_loadbalancing {
3559: my ($dom,$settings,$rowtotal) = @_;
3560: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3561: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3562: my $numinrow = 1;
3563: my $datatable;
3564: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3565: my (%currbalancer,%currtargets,%currrules,%existing);
3566: if (ref($settings) eq 'HASH') {
3567: %existing = %{$settings};
3568: }
3569: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3570: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3571: \%currtargets,\%currrules);
1.150 raeburn 3572: } else {
3573: return;
3574: }
3575: my ($othertitle,$usertypes,$types) =
3576: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3577: my $rownum = 8;
1.150 raeburn 3578: if (ref($types) eq 'ARRAY') {
3579: $rownum += scalar(@{$types});
3580: }
1.171 raeburn 3581: my @css_class = ('LC_odd_row','LC_even_row');
3582: my $balnum = 0;
3583: my $islast;
3584: my (@toshow,$disabledtext);
3585: if (keys(%currbalancer) > 0) {
3586: @toshow = sort(keys(%currbalancer));
3587: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3588: push(@toshow,'');
3589: }
3590: } else {
3591: @toshow = ('');
3592: $disabledtext = &mt('No existing load balancer');
3593: }
3594: foreach my $lonhost (@toshow) {
3595: if ($balnum == scalar(@toshow)-1) {
3596: $islast = 1;
3597: } else {
3598: $islast = 0;
3599: }
3600: my $cssidx = $balnum%2;
3601: my $targets_div_style = 'display: none';
3602: my $disabled_div_style = 'display: block';
3603: my $homedom_div_style = 'display: none';
3604: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3605: '<td rowspan="'.$rownum.'" valign="top">'.
3606: '<p>';
3607: if ($lonhost eq '') {
1.210 raeburn 3608: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3609: if (keys(%currbalancer) > 0) {
3610: $datatable .= &mt('Add balancer:');
3611: } else {
3612: $datatable .= &mt('Enable balancer:');
3613: }
3614: $datatable .= ' '.
3615: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3616: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3617: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3618: '<option value="" selected="selected">'.&mt('None').
3619: '</option>'."\n";
3620: foreach my $server (sort(keys(%servers))) {
3621: next if ($currbalancer{$server});
3622: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3623: }
1.210 raeburn 3624: $datatable .=
1.171 raeburn 3625: '</select>'."\n".
3626: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3627: } else {
3628: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3629: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3630: &mt('Stop balancing').'</label>'.
3631: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3632: $targets_div_style = 'display: block';
3633: $disabled_div_style = 'display: none';
3634: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3635: $homedom_div_style = 'display: block';
3636: }
3637: }
3638: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3639: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3640: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3641: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3642: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3643: my @sparestypes = ('primary','default');
3644: my %typetitles = &sparestype_titles();
3645: foreach my $sparetype (@sparestypes) {
3646: my $targettable;
3647: for (my $i=0; $i<$numspares; $i++) {
3648: my $checked;
3649: if (ref($currtargets{$lonhost}) eq 'HASH') {
3650: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3651: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3652: $checked = ' checked="checked"';
3653: }
3654: }
3655: }
3656: my ($chkboxval,$disabled);
3657: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3658: $chkboxval = $spares[$i];
3659: }
3660: if (exists($currbalancer{$spares[$i]})) {
3661: $disabled = ' disabled="disabled"';
3662: }
1.210 raeburn 3663: $targettable .=
1.253 raeburn 3664: '<td><span class="LC_nobreak"><label>'.
3665: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 3666: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 3667: '</span></label></span></td>';
1.171 raeburn 3668: my $rem = $i%($numinrow);
3669: if ($rem == 0) {
3670: if (($i > 0) && ($i < $numspares-1)) {
3671: $targettable .= '</tr>';
3672: }
3673: if ($i < $numspares-1) {
3674: $targettable .= '<tr>';
1.150 raeburn 3675: }
3676: }
3677: }
1.171 raeburn 3678: if ($targettable ne '') {
3679: my $rem = $numspares%($numinrow);
3680: my $colsleft = $numinrow - $rem;
3681: if ($colsleft > 1 ) {
3682: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3683: ' </td>';
3684: } elsif ($colsleft == 1) {
3685: $targettable .= '<td class="LC_left_item"> </td>';
3686: }
3687: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3688: '<table><tr>'.$targettable.'</tr></table><br />';
3689: }
3690: }
3691: $datatable .= '</div></td></tr>'.
3692: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3693: $othertitle,$usertypes,$types,\%servers,
3694: \%currbalancer,$lonhost,
3695: $targets_div_style,$homedom_div_style,
3696: $css_class[$cssidx],$balnum,$islast);
3697: $$rowtotal += $rownum;
3698: $balnum ++;
3699: }
3700: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3701: return $datatable;
3702: }
3703:
3704: sub get_loadbalancers_config {
3705: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3706: return unless ((ref($servers) eq 'HASH') &&
3707: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3708: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3709: if (keys(%{$existing}) > 0) {
3710: my $oldlonhost;
3711: foreach my $key (sort(keys(%{$existing}))) {
3712: if ($key eq 'lonhost') {
3713: $oldlonhost = $existing->{'lonhost'};
3714: $currbalancer->{$oldlonhost} = 1;
3715: } elsif ($key eq 'targets') {
3716: if ($oldlonhost) {
3717: $currtargets->{$oldlonhost} = $existing->{'targets'};
3718: }
3719: } elsif ($key eq 'rules') {
3720: if ($oldlonhost) {
3721: $currrules->{$oldlonhost} = $existing->{'rules'};
3722: }
3723: } elsif (ref($existing->{$key}) eq 'HASH') {
3724: $currbalancer->{$key} = 1;
3725: $currtargets->{$key} = $existing->{$key}{'targets'};
3726: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3727: }
3728: }
1.171 raeburn 3729: } else {
3730: my ($balancerref,$targetsref) =
3731: &Apache::lonnet::get_lonbalancer_config($servers);
3732: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3733: foreach my $server (sort(keys(%{$balancerref}))) {
3734: $currbalancer->{$server} = 1;
3735: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3736: }
3737: }
3738: }
1.171 raeburn 3739: return;
1.150 raeburn 3740: }
3741:
3742: sub loadbalancing_rules {
3743: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3744: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3745: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3746: my $output;
1.171 raeburn 3747: my $num = 0;
1.210 raeburn 3748: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3749: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3750: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3751: foreach my $type (@{$alltypes}) {
1.171 raeburn 3752: $num ++;
1.150 raeburn 3753: my $current;
3754: if (ref($currrules) eq 'HASH') {
3755: $current = $currrules->{$type};
3756: }
1.253 raeburn 3757: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3758: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3759: $current = '';
3760: }
3761: }
3762: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3763: $servers,$currbalancer,$lonhost,$dom,
3764: $targets_div_style,$homedom_div_style,
3765: $css_class,$balnum,$num,$islast);
1.150 raeburn 3766: }
3767: }
3768: return $output;
3769: }
3770:
3771: sub loadbalancing_titles {
3772: my ($dom,$intdom,$usertypes,$types) = @_;
3773: my %othertypes = (
3774: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3775: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3776: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3777: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3778: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3779: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3780: );
1.209 raeburn 3781: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3782: if (ref($types) eq 'ARRAY') {
3783: unshift(@alltypes,@{$types},'default');
3784: }
3785: my %titles;
3786: foreach my $type (@alltypes) {
3787: if ($type =~ /^_LC_/) {
3788: $titles{$type} = $othertypes{$type};
3789: } elsif ($type eq 'default') {
3790: $titles{$type} = &mt('All users from [_1]',$dom);
3791: if (ref($types) eq 'ARRAY') {
3792: if (@{$types} > 0) {
3793: $titles{$type} = &mt('Other users from [_1]',$dom);
3794: }
3795: }
3796: } elsif (ref($usertypes) eq 'HASH') {
3797: $titles{$type} = $usertypes->{$type};
3798: }
3799: }
3800: return (\@alltypes,\%othertypes,\%titles);
3801: }
3802:
3803: sub loadbalance_rule_row {
1.171 raeburn 3804: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3805: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3806: my @rulenames;
1.150 raeburn 3807: my %ruletitles = &offloadtype_text();
1.209 raeburn 3808: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 3809: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 3810: } else {
1.209 raeburn 3811: @rulenames = ('default','homeserver');
3812: if ($type eq '_LC_external') {
3813: push(@rulenames,'externalbalancer');
3814: } else {
3815: push(@rulenames,'specific');
3816: }
3817: push(@rulenames,'none');
1.150 raeburn 3818: }
3819: my $style = $targets_div_style;
1.253 raeburn 3820: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 3821: $style = $homedom_div_style;
3822: }
1.171 raeburn 3823: my $space;
3824: if ($islast && $num == 1) {
3825: $space = '<div display="inline-block"> </div>';
3826: }
1.210 raeburn 3827: my $output =
1.171 raeburn 3828: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3829: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3830: '<td valaign="top">'.$space.
3831: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3832: for (my $i=0; $i<@rulenames; $i++) {
3833: my $rule = $rulenames[$i];
3834: my ($checked,$extra);
3835: if ($rulenames[$i] eq 'default') {
3836: $rule = '';
3837: }
3838: if ($rulenames[$i] eq 'specific') {
3839: if (ref($servers) eq 'HASH') {
3840: my $default;
3841: if (($current ne '') && (exists($servers->{$current}))) {
3842: $checked = ' checked="checked"';
3843: }
3844: unless ($checked) {
3845: $default = ' selected="selected"';
3846: }
1.210 raeburn 3847: $extra =
1.171 raeburn 3848: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3849: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3850: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3851: '<option value=""'.$default.'></option>'."\n";
3852: foreach my $server (sort(keys(%{$servers}))) {
3853: if (ref($currbalancer) eq 'HASH') {
3854: next if (exists($currbalancer->{$server}));
3855: }
1.150 raeburn 3856: my $selected;
1.171 raeburn 3857: if ($server eq $current) {
1.150 raeburn 3858: $selected = ' selected="selected"';
3859: }
1.171 raeburn 3860: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3861: }
3862: $extra .= '</select>';
3863: }
3864: } elsif ($rule eq $current) {
3865: $checked = ' checked="checked"';
3866: }
3867: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3868: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3869: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3870: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 3871: ')"'.$checked.' /> ';
3872: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
3873: $output .= $ruletitles{'particular'};
3874: } else {
3875: $output .= $ruletitles{$rulenames[$i]};
3876: }
3877: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 3878: }
3879: $output .= '</div></td></tr>'."\n";
3880: return $output;
3881: }
3882:
3883: sub offloadtype_text {
3884: my %ruletitles = &Apache::lonlocal::texthash (
3885: 'default' => 'Offloads to default destinations',
3886: 'homeserver' => "Offloads to user's home server",
3887: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3888: 'specific' => 'Offloads to specific server',
1.161 raeburn 3889: 'none' => 'No offload',
1.209 raeburn 3890: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3891: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 3892: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 3893: );
3894: return %ruletitles;
3895: }
3896:
3897: sub sparestype_titles {
3898: my %typestitles = &Apache::lonlocal::texthash (
3899: 'primary' => 'primary',
3900: 'default' => 'default',
3901: );
3902: return %typestitles;
3903: }
3904:
1.28 raeburn 3905: sub contact_titles {
3906: my %titles = &Apache::lonlocal::texthash (
3907: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3908: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3909: 'errormail' => 'Error reports to be e-mailed to',
3910: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3911: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3912: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3913: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3914: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3915: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3916: );
3917: my %short_titles = &Apache::lonlocal::texthash (
3918: adminemail => 'Admin E-mail address',
3919: supportemail => 'Support E-mail',
3920: );
3921: return (\%titles,\%short_titles);
3922: }
3923:
1.72 raeburn 3924: sub tool_titles {
3925: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3926: aboutme => 'Personal web page',
1.86 raeburn 3927: blog => 'Blog',
1.162 raeburn 3928: webdav => 'WebDAV',
1.86 raeburn 3929: portfolio => 'Portfolio',
1.88 bisitz 3930: official => 'Official courses (with institutional codes)',
3931: unofficial => 'Unofficial courses',
1.98 raeburn 3932: community => 'Communities',
1.216 raeburn 3933: textbook => 'Textbook courses',
1.86 raeburn 3934: );
1.72 raeburn 3935: return %titles;
3936: }
3937:
1.101 raeburn 3938: sub courserequest_titles {
3939: my %titles = &Apache::lonlocal::texthash (
3940: official => 'Official',
3941: unofficial => 'Unofficial',
3942: community => 'Communities',
1.216 raeburn 3943: textbook => 'Textbook',
1.101 raeburn 3944: norequest => 'Not allowed',
1.104 raeburn 3945: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3946: validate => 'With validation',
3947: autolimit => 'Numerical limit',
1.103 raeburn 3948: unlimited => '(blank for unlimited)',
1.101 raeburn 3949: );
3950: return %titles;
3951: }
3952:
1.163 raeburn 3953: sub authorrequest_titles {
3954: my %titles = &Apache::lonlocal::texthash (
3955: norequest => 'Not allowed',
3956: approval => 'Approval by Dom. Coord.',
3957: automatic => 'Automatic approval',
3958: );
3959: return %titles;
1.210 raeburn 3960: }
1.163 raeburn 3961:
1.101 raeburn 3962: sub courserequest_conditions {
3963: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3964: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3965: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3966: );
3967: return %conditions;
3968: }
3969:
3970:
1.27 raeburn 3971: sub print_usercreation {
1.30 raeburn 3972: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3973: my $numinrow = 4;
1.28 raeburn 3974: my $datatable;
3975: if ($position eq 'top') {
1.30 raeburn 3976: $$rowtotal ++;
1.34 raeburn 3977: my $rowcount = 0;
1.32 raeburn 3978: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3979: if (ref($rules) eq 'HASH') {
3980: if (keys(%{$rules}) > 0) {
1.32 raeburn 3981: $datatable .= &user_formats_row('username',$settings,$rules,
3982: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3983: $$rowtotal ++;
1.32 raeburn 3984: $rowcount ++;
3985: }
3986: }
3987: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3988: if (ref($idrules) eq 'HASH') {
3989: if (keys(%{$idrules}) > 0) {
3990: $datatable .= &user_formats_row('id',$settings,$idrules,
3991: $idruleorder,$numinrow,$rowcount);
3992: $$rowtotal ++;
3993: $rowcount ++;
1.28 raeburn 3994: }
3995: }
1.39 raeburn 3996: if ($rowcount == 0) {
3997: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3998: $$rowtotal ++;
3999: $rowcount ++;
4000: }
1.34 raeburn 4001: } elsif ($position eq 'middle') {
1.224 raeburn 4002: my @creators = ('author','course','requestcrs');
1.37 raeburn 4003: my ($rules,$ruleorder) =
4004: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4005: my %lt = &usercreation_types();
4006: my %checked;
4007: if (ref($settings) eq 'HASH') {
4008: if (ref($settings->{'cancreate'}) eq 'HASH') {
4009: foreach my $item (@creators) {
4010: $checked{$item} = $settings->{'cancreate'}{$item};
4011: }
4012: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4013: foreach my $item (@creators) {
4014: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4015: $checked{$item} = 'none';
4016: }
4017: }
4018: }
4019: }
4020: my $rownum = 0;
4021: foreach my $item (@creators) {
4022: $rownum ++;
1.224 raeburn 4023: if ($checked{$item} eq '') {
4024: $checked{$item} = 'any';
1.34 raeburn 4025: }
4026: my $css_class;
4027: if ($rownum%2) {
4028: $css_class = '';
4029: } else {
4030: $css_class = ' class="LC_odd_row" ';
4031: }
4032: $datatable .= '<tr'.$css_class.'>'.
4033: '<td><span class="LC_nobreak">'.$lt{$item}.
4034: '</span></td><td align="right">';
1.224 raeburn 4035: my @options = ('any');
4036: if (ref($rules) eq 'HASH') {
4037: if (keys(%{$rules}) > 0) {
4038: push(@options,('official','unofficial'));
1.37 raeburn 4039: }
4040: }
1.224 raeburn 4041: push(@options,'none');
1.37 raeburn 4042: foreach my $option (@options) {
1.50 raeburn 4043: my $type = 'radio';
1.34 raeburn 4044: my $check = ' ';
1.224 raeburn 4045: if ($checked{$item} eq $option) {
4046: $check = ' checked="checked" ';
1.34 raeburn 4047: }
4048: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4049: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4050: $item.'" value="'.$option.'"'.$check.'/> '.
4051: $lt{$option}.'</label> </span>';
4052: }
4053: $datatable .= '</td></tr>';
4054: }
1.28 raeburn 4055: } else {
4056: my @contexts = ('author','course','domain');
4057: my @authtypes = ('int','krb4','krb5','loc');
4058: my %checked;
4059: if (ref($settings) eq 'HASH') {
4060: if (ref($settings->{'authtypes'}) eq 'HASH') {
4061: foreach my $item (@contexts) {
4062: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4063: foreach my $auth (@authtypes) {
4064: if ($settings->{'authtypes'}{$item}{$auth}) {
4065: $checked{$item}{$auth} = ' checked="checked" ';
4066: }
4067: }
4068: }
4069: }
1.27 raeburn 4070: }
1.35 raeburn 4071: } else {
4072: foreach my $item (@contexts) {
1.36 raeburn 4073: foreach my $auth (@authtypes) {
1.35 raeburn 4074: $checked{$item}{$auth} = ' checked="checked" ';
4075: }
4076: }
1.27 raeburn 4077: }
1.28 raeburn 4078: my %title = &context_names();
4079: my %authname = &authtype_names();
4080: my $rownum = 0;
4081: my $css_class;
4082: foreach my $item (@contexts) {
4083: if ($rownum%2) {
4084: $css_class = '';
4085: } else {
4086: $css_class = ' class="LC_odd_row" ';
4087: }
1.30 raeburn 4088: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4089: '<td>'.$title{$item}.
4090: '</td><td class="LC_left_item">'.
4091: '<span class="LC_nobreak">';
4092: foreach my $auth (@authtypes) {
4093: $datatable .= '<label>'.
4094: '<input type="checkbox" name="'.$item.'_auth" '.
4095: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4096: $authname{$auth}.'</label> ';
4097: }
4098: $datatable .= '</span></td></tr>';
4099: $rownum ++;
1.27 raeburn 4100: }
1.30 raeburn 4101: $$rowtotal += $rownum;
1.27 raeburn 4102: }
4103: return $datatable;
4104: }
4105:
1.224 raeburn 4106: sub print_selfcreation {
4107: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4108: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4109: if (ref($settings) eq 'HASH') {
4110: if (ref($settings->{'cancreate'}) eq 'HASH') {
4111: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4112: if (ref($createsettings) eq 'HASH') {
4113: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4114: @selfcreate = @{$createsettings->{'selfcreate'}};
4115: } elsif ($createsettings->{'selfcreate'} ne '') {
4116: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4117: @selfcreate = ('email','login','sso');
4118: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4119: @selfcreate = ($createsettings->{'selfcreate'});
4120: }
4121: }
4122: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4123: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4124: }
4125: }
4126: }
4127: }
4128: my %radiohash;
4129: my $numinrow = 4;
4130: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4131: if ($position eq 'top') {
4132: my %choices = &Apache::lonlocal::texthash (
4133: cancreate_login => 'Institutional Login',
4134: cancreate_sso => 'Institutional Single Sign On',
4135: );
4136: my @toggles = sort(keys(%choices));
4137: my %defaultchecked = (
4138: 'cancreate_login' => 'off',
4139: 'cancreate_sso' => 'off',
4140: );
1.228 raeburn 4141: my ($onclick,$itemcount);
1.224 raeburn 4142: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4143: \%choices,$itemcount,$onclick);
1.228 raeburn 4144: $$rowtotal += $itemcount;
4145:
1.224 raeburn 4146: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4147:
4148: if (ref($usertypes) eq 'HASH') {
4149: if (keys(%{$usertypes}) > 0) {
4150: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4151: $dom,$numinrow,$othertitle,
1.228 raeburn 4152: 'statustocreate',$$rowtotal);
1.224 raeburn 4153: $$rowtotal ++;
4154: }
4155: }
1.240 raeburn 4156: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4157: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4158: $fieldtitles{'inststatus'} = &mt('Institutional status');
4159: my $rem;
4160: my $numperrow = 2;
4161: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4162: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4163: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4164: '<td class="LC_left_item">'."\n".
4165: '<table><tr><td>'."\n";
4166: for (my $i=0; $i<@fields; $i++) {
4167: $rem = $i%($numperrow);
4168: if ($rem == 0) {
4169: if ($i > 0) {
4170: $datatable .= '</tr>';
4171: }
4172: $datatable .= '<tr>';
4173: }
4174: my $currval;
1.248 raeburn 4175: if (ref($createsettings) eq 'HASH') {
4176: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4177: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4178: }
1.240 raeburn 4179: }
4180: $datatable .= '<td class="LC_left_item">'.
4181: '<span class="LC_nobreak">'.
4182: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4183: 'value="'.$currval.'" size="10" /> '.
4184: $fieldtitles{$fields[$i]}.'</span></td>';
4185: }
4186: my $colsleft = $numperrow - $rem;
4187: if ($colsleft > 1 ) {
4188: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4189: ' </td>';
4190: } elsif ($colsleft == 1) {
4191: $datatable .= '<td class="LC_left_item"> </td>';
4192: }
4193: $datatable .= '</tr></table></td></tr>';
4194: $$rowtotal ++;
1.224 raeburn 4195: } elsif ($position eq 'middle') {
4196: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4197: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4198: $usertypes->{'default'} = $othertitle;
4199: if (ref($types) eq 'ARRAY') {
4200: push(@{$types},'default');
4201: $usertypes->{'default'} = $othertitle;
4202: foreach my $status (@{$types}) {
4203: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4204: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4205: $$rowtotal ++;
1.224 raeburn 4206: }
4207: }
4208: } else {
1.236 raeburn 4209: my %choices = &Apache::lonlocal::texthash (
4210: cancreate_email => 'E-mail address as username',
4211: );
4212: my @toggles = sort(keys(%choices));
4213: my %defaultchecked = (
4214: 'cancreate_email' => 'off',
4215: );
4216: my $itemcount = 0;
4217: my $display = 'none';
4218: if (grep(/^\Qemail\E$/,@selfcreate)) {
4219: $display = 'block';
4220: }
4221: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4222: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4223: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4224: my $usertypes = {};
4225: my $order = [];
4226: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4227: $usertypes = $domdefaults{'inststatustypes'};
4228: $order = $domdefaults{'inststatusguest'};
4229: }
4230: if (ref($order) eq 'ARRAY') {
4231: push(@{$order},'default');
4232: if (@{$order} > 1) {
4233: $usertypes->{'default'} = &mt('Other users');
4234: $additional .= '<table><tr>';
4235: foreach my $status (@{$order}) {
4236: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4237: }
4238: $additional .= '</tr><tr>';
4239: foreach my $status (@{$order}) {
4240: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4241: }
1.236 raeburn 4242: $additional .= '</tr></table>';
1.224 raeburn 4243: } else {
1.236 raeburn 4244: $usertypes->{'default'} = &mt('All users');
4245: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4246: }
4247: }
1.236 raeburn 4248: $additional .= '</div>'."\n";
4249:
4250: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4251: \%choices,$$rowtotal,$onclick,$additional);
4252: $$rowtotal ++;
1.236 raeburn 4253: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4254: $$rowtotal ++;
1.224 raeburn 4255: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4256: $numinrow = 1;
1.236 raeburn 4257: if (ref($order) eq 'ARRAY') {
4258: foreach my $status (@{$order}) {
1.228 raeburn 4259: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4260: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4261: $$rowtotal ++;
4262: }
4263: }
1.224 raeburn 4264: my ($emailrules,$emailruleorder) =
4265: &Apache::lonnet::inst_userrules($dom,'email');
4266: if (ref($emailrules) eq 'HASH') {
4267: if (keys(%{$emailrules}) > 0) {
4268: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4269: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4270: $$rowtotal ++;
4271: }
4272: }
1.228 raeburn 4273: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4274: }
4275: return $datatable;
4276: }
4277:
1.236 raeburn 4278: sub email_as_username {
4279: my ($rowtotal,$processing,$type) = @_;
4280: my %choices =
4281: &Apache::lonlocal::texthash (
4282: automatic => 'Automatic approval',
4283: approval => 'Queued for approval',
4284: );
4285: my $output;
4286: foreach my $option ('automatic','approval') {
4287: my $checked;
4288: if (ref($processing) eq 'HASH') {
4289: if ($type eq '') {
4290: if (!exists($processing->{'default'})) {
4291: if ($option eq 'automatic') {
4292: $checked = ' checked="checked"';
4293: }
4294: } else {
4295: if ($processing->{'default'} eq $option) {
4296: $checked = ' checked="checked"';
4297: }
4298: }
4299: } else {
4300: if (!exists($processing->{$type})) {
4301: if ($option eq 'automatic') {
4302: $checked = ' checked="checked"';
4303: }
4304: } else {
4305: if ($processing->{$type} eq $option) {
4306: $checked = ' checked="checked"';
4307: }
4308: }
4309: }
4310: } elsif ($option eq 'automatic') {
4311: $checked = ' checked="checked"';
4312: }
4313: my $name = 'cancreate_emailprocess';
4314: if (($type ne '') && ($type ne 'default')) {
4315: $name .= '_'.$type;
4316: }
4317: $output .= '<span class="LC_nobreak"><label>'.
4318: '<input type="radio" name="'.$name.'"'.
4319: $checked.' value="'.$option.'" />'.
4320: $choices{$option}.'</label></span>';
4321: if ($type eq '') {
4322: $output .= ' ';
4323: } else {
4324: $output .= '<br />';
4325: }
4326: }
4327: $$rowtotal ++;
4328: return $output;
4329: }
4330:
1.165 raeburn 4331: sub captcha_choice {
1.169 raeburn 4332: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4333: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4334: my %lt = &captcha_phrases();
4335: $keyentry = 'hidden';
4336: if ($context eq 'cancreate') {
1.224 raeburn 4337: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4338: } elsif ($context eq 'login') {
4339: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4340: }
4341: if (ref($settings) eq 'HASH') {
4342: if ($settings->{'captcha'}) {
4343: $checked{$settings->{'captcha'}} = ' checked="checked"';
4344: } else {
4345: $checked{'original'} = ' checked="checked"';
4346: }
4347: if ($settings->{'captcha'} eq 'recaptcha') {
4348: $pubtext = $lt{'pub'};
4349: $privtext = $lt{'priv'};
4350: $keyentry = 'text';
4351: }
4352: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4353: $currpub = $settings->{'recaptchakeys'}{'public'};
4354: $currpriv = $settings->{'recaptchakeys'}{'private'};
4355: }
4356: } else {
4357: $checked{'original'} = ' checked="checked"';
4358: }
1.169 raeburn 4359: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4360: my $output = '<tr'.$css_class.'>'.
4361: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4362: '<table><tr><td>'."\n";
4363: foreach my $option ('original','recaptcha','notused') {
4364: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4365: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4366: $lt{$option}.'</label></span>';
4367: unless ($option eq 'notused') {
4368: $output .= (' 'x2)."\n";
4369: }
4370: }
4371: #
4372: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4373: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4374: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4375: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4376: #
1.165 raeburn 4377: $output .= '</td></tr>'."\n".
4378: '<tr><td>'."\n".
4379: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4380: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4381: $currpub.'" size="40" /></span><br />'."\n".
4382: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4383: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4384: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4385: '</td></tr>';
4386: return $output;
4387: }
4388:
1.32 raeburn 4389: sub user_formats_row {
4390: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4391: my $output;
4392: my %text = (
4393: 'username' => 'new usernames',
4394: 'id' => 'IDs',
1.45 raeburn 4395: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4396: );
4397: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4398: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4399: '<td><span class="LC_nobreak">';
4400: if ($type eq 'email') {
4401: $output .= &mt("Formats disallowed for $text{$type}: ");
4402: } else {
4403: $output .= &mt("Format rules to check for $text{$type}: ");
4404: }
4405: $output .= '</span></td>'.
4406: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4407: my $rem;
4408: if (ref($ruleorder) eq 'ARRAY') {
4409: for (my $i=0; $i<@{$ruleorder}; $i++) {
4410: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4411: my $rem = $i%($numinrow);
4412: if ($rem == 0) {
4413: if ($i > 0) {
4414: $output .= '</tr>';
4415: }
4416: $output .= '<tr>';
4417: }
4418: my $check = ' ';
1.39 raeburn 4419: if (ref($settings) eq 'HASH') {
4420: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4421: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4422: $check = ' checked="checked" ';
4423: }
1.27 raeburn 4424: }
4425: }
4426: $output .= '<td class="LC_left_item">'.
4427: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4428: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4429: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4430: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4431: }
4432: }
4433: $rem = @{$ruleorder}%($numinrow);
4434: }
4435: my $colsleft = $numinrow - $rem;
4436: if ($colsleft > 1 ) {
4437: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4438: ' </td>';
4439: } elsif ($colsleft == 1) {
4440: $output .= '<td class="LC_left_item"> </td>';
4441: }
4442: $output .= '</tr></table></td></tr>';
4443: return $output;
4444: }
4445:
1.34 raeburn 4446: sub usercreation_types {
4447: my %lt = &Apache::lonlocal::texthash (
4448: author => 'When adding a co-author',
4449: course => 'When adding a user to a course',
1.100 raeburn 4450: requestcrs => 'When requesting a course',
1.34 raeburn 4451: any => 'Any',
4452: official => 'Institutional only ',
4453: unofficial => 'Non-institutional only',
4454: none => 'None',
4455: );
4456: return %lt;
1.48 raeburn 4457: }
1.34 raeburn 4458:
1.224 raeburn 4459: sub selfcreation_types {
4460: my %lt = &Apache::lonlocal::texthash (
4461: selfcreate => 'User creates own account',
4462: any => 'Any',
4463: official => 'Institutional only ',
4464: unofficial => 'Non-institutional only',
4465: email => 'E-mail address',
4466: login => 'Institutional Login',
4467: sso => 'SSO',
4468: );
4469: }
4470:
1.28 raeburn 4471: sub authtype_names {
4472: my %lt = &Apache::lonlocal::texthash(
4473: int => 'Internal',
4474: krb4 => 'Kerberos 4',
4475: krb5 => 'Kerberos 5',
4476: loc => 'Local',
4477: );
4478: return %lt;
4479: }
4480:
4481: sub context_names {
4482: my %context_title = &Apache::lonlocal::texthash(
4483: author => 'Creating users when an Author',
4484: course => 'Creating users when in a course',
4485: domain => 'Creating users when a Domain Coordinator',
4486: );
4487: return %context_title;
4488: }
4489:
1.33 raeburn 4490: sub print_usermodification {
4491: my ($position,$dom,$settings,$rowtotal) = @_;
4492: my $numinrow = 4;
4493: my ($context,$datatable,$rowcount);
4494: if ($position eq 'top') {
4495: $rowcount = 0;
4496: $context = 'author';
4497: foreach my $role ('ca','aa') {
4498: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4499: $numinrow,$rowcount);
4500: $$rowtotal ++;
4501: $rowcount ++;
4502: }
1.230 raeburn 4503: } elsif ($position eq 'bottom') {
1.33 raeburn 4504: $context = 'course';
4505: $rowcount = 0;
4506: foreach my $role ('st','ep','ta','in','cr') {
4507: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4508: $numinrow,$rowcount);
4509: $$rowtotal ++;
4510: $rowcount ++;
4511: }
4512: }
4513: return $datatable;
4514: }
4515:
1.43 raeburn 4516: sub print_defaults {
1.236 raeburn 4517: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4518: my $rownum = 0;
4519: my ($datatable,$css_class);
1.236 raeburn 4520: if ($position eq 'top') {
4521: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4522: 'datelocale_def','portal_def');
4523: my %defaults;
4524: if (ref($settings) eq 'HASH') {
4525: %defaults = %{$settings};
1.43 raeburn 4526: } else {
1.236 raeburn 4527: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4528: foreach my $item (@items) {
4529: $defaults{$item} = $domdefaults{$item};
4530: }
1.43 raeburn 4531: }
1.236 raeburn 4532: my $titles = &defaults_titles($dom);
4533: foreach my $item (@items) {
4534: if ($rownum%2) {
4535: $css_class = '';
4536: } else {
4537: $css_class = ' class="LC_odd_row" ';
4538: }
4539: $datatable .= '<tr'.$css_class.'>'.
4540: '<td><span class="LC_nobreak">'.$titles->{$item}.
4541: '</span></td><td class="LC_right_item" colspan="3">';
4542: if ($item eq 'auth_def') {
4543: my @authtypes = ('internal','krb4','krb5','localauth');
4544: my %shortauth = (
4545: internal => 'int',
4546: krb4 => 'krb4',
4547: krb5 => 'krb5',
4548: localauth => 'loc'
4549: );
4550: my %authnames = &authtype_names();
4551: foreach my $auth (@authtypes) {
4552: my $checked = ' ';
4553: if ($defaults{$item} eq $auth) {
4554: $checked = ' checked="checked" ';
4555: }
4556: $datatable .= '<label><input type="radio" name="'.$item.
4557: '" value="'.$auth.'"'.$checked.'/>'.
4558: $authnames{$shortauth{$auth}}.'</label> ';
4559: }
4560: } elsif ($item eq 'timezone_def') {
4561: my $includeempty = 1;
4562: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4563: } elsif ($item eq 'datelocale_def') {
4564: my $includeempty = 1;
4565: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4566: } elsif ($item eq 'lang_def') {
4567: my %langchoices = &get_languages_hash();
4568: $langchoices{''} = 'No language preference';
4569: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4570: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4571: \%langchoices);
4572: } else {
4573: my $size;
4574: if ($item eq 'portal_def') {
4575: $size = ' size="25"';
4576: }
4577: $datatable .= '<input type="text" name="'.$item.'" value="'.
4578: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4579: }
1.236 raeburn 4580: $datatable .= '</td></tr>';
4581: $rownum ++;
4582: }
4583: } else {
4584: my (%defaults);
4585: if (ref($settings) eq 'HASH') {
4586: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4587: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4588: my $maxnum = @{$settings->{'inststatusorder'}};
4589: for (my $i=0; $i<$maxnum; $i++) {
4590: $css_class = $rownum%2?' class="LC_odd_row"':'';
4591: my $item = $settings->{'inststatusorder'}->[$i];
4592: my $title = $settings->{'inststatustypes'}->{$item};
4593: my $guestok;
4594: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4595: $guestok = 1;
4596: }
4597: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4598: $datatable .= '<tr'.$css_class.'>'.
4599: '<td><span class="LC_nobreak">'.
4600: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4601: for (my $k=0; $k<=$maxnum; $k++) {
4602: my $vpos = $k+1;
4603: my $selstr;
4604: if ($k == $i) {
4605: $selstr = ' selected="selected" ';
4606: }
4607: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4608: }
4609: my ($checkedon,$checkedoff);
4610: $checkedoff = ' checked="checked"';
4611: if ($guestok) {
4612: $checkedon = $checkedoff;
4613: $checkedoff = '';
4614: }
4615: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4616: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4617: &mt('delete').'</span></td>'.
4618: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4619: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4620: '</span></td>'.
4621: '<td class="LC_right_item"><span class="LC_nobreak">'.
4622: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4623: &mt('Yes').'</label>'.(' 'x2).
4624: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4625: &mt('No').'</label></span></td></tr>';
4626: }
4627: $css_class = $rownum%2?' class="LC_odd_row"':'';
4628: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4629: $datatable .= '<tr '.$css_class.'>'.
4630: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4631: for (my $k=0; $k<=$maxnum; $k++) {
4632: my $vpos = $k+1;
4633: my $selstr;
4634: if ($k == $maxnum) {
4635: $selstr = ' selected="selected" ';
4636: }
4637: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4638: }
4639: $datatable .= '</select> '.&mt('Internal ID:').
4640: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4641: ' '.&mt('(new)').
4642: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4643: &mt('Name displayed:').
4644: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4645: '<td class="LC_right_item"><span class="LC_nobreak">'.
4646: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4647: &mt('Yes').'</label>'.(' 'x2).
4648: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4649: &mt('No').'</label></span></td></tr>';
4650: '</tr>'."\n";
4651: $rownum ++;
1.141 raeburn 4652: }
1.43 raeburn 4653: }
4654: }
4655: $$rowtotal += $rownum;
4656: return $datatable;
4657: }
4658:
1.168 raeburn 4659: sub get_languages_hash {
4660: my %langchoices;
4661: foreach my $id (&Apache::loncommon::languageids()) {
4662: my $code = &Apache::loncommon::supportedlanguagecode($id);
4663: if ($code ne '') {
4664: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4665: }
4666: }
4667: return %langchoices;
4668: }
4669:
1.43 raeburn 4670: sub defaults_titles {
1.141 raeburn 4671: my ($dom) = @_;
1.43 raeburn 4672: my %titles = &Apache::lonlocal::texthash (
4673: 'auth_def' => 'Default authentication type',
4674: 'auth_arg_def' => 'Default authentication argument',
4675: 'lang_def' => 'Default language',
1.54 raeburn 4676: 'timezone_def' => 'Default timezone',
1.68 raeburn 4677: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4678: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4679: );
1.141 raeburn 4680: if ($dom) {
4681: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4682: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4683: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4684: $protocol = 'http' if ($protocol ne 'https');
4685: if ($uint_dom) {
4686: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4687: $uint_dom);
4688: }
4689: }
1.43 raeburn 4690: return (\%titles);
4691: }
4692:
1.46 raeburn 4693: sub print_scantronformat {
4694: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4695: my $itemcount = 1;
1.60 raeburn 4696: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4697: %confhash);
1.46 raeburn 4698: my $switchserver = &check_switchserver($dom,$confname);
4699: my %lt = &Apache::lonlocal::texthash (
1.95 www 4700: default => 'Default bubblesheet format file error',
4701: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4702: );
4703: my %scantronfiles = (
4704: default => 'default.tab',
4705: custom => 'custom.tab',
4706: );
4707: foreach my $key (keys(%scantronfiles)) {
4708: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4709: .$scantronfiles{$key};
4710: }
4711: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4712: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4713: if (!$switchserver) {
4714: my $servadm = $r->dir_config('lonAdmEMail');
4715: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4716: if ($configuserok eq 'ok') {
4717: if ($author_ok eq 'ok') {
4718: my %legacyfile = (
4719: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4720: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4721: );
4722: my %md5chk;
4723: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4724: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4725: chomp($md5chk{$type});
1.46 raeburn 4726: }
4727: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4728: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4729: ($scantronurls{$type},my $error) =
1.46 raeburn 4730: &legacy_scantronformat($r,$dom,$confname,
4731: $type,$legacyfile{$type},
4732: $scantronurls{$type},
4733: $scantronfiles{$type});
1.60 raeburn 4734: if ($error ne '') {
4735: $error{$type} = $error;
4736: }
4737: }
4738: if (keys(%error) == 0) {
4739: $is_custom = 1;
4740: $confhash{'scantron'}{'scantronformat'} =
4741: $scantronurls{'custom'};
4742: my $putresult =
4743: &Apache::lonnet::put_dom('configuration',
4744: \%confhash,$dom);
4745: if ($putresult ne 'ok') {
4746: $error{'custom'} =
4747: '<span class="LC_error">'.
4748: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4749: }
1.46 raeburn 4750: }
4751: } else {
1.60 raeburn 4752: ($scantronurls{'default'},my $error) =
1.46 raeburn 4753: &legacy_scantronformat($r,$dom,$confname,
4754: 'default',$legacyfile{'default'},
4755: $scantronurls{'default'},
4756: $scantronfiles{'default'});
1.60 raeburn 4757: if ($error eq '') {
4758: $confhash{'scantron'}{'scantronformat'} = '';
4759: my $putresult =
4760: &Apache::lonnet::put_dom('configuration',
4761: \%confhash,$dom);
4762: if ($putresult ne 'ok') {
4763: $error{'default'} =
4764: '<span class="LC_error">'.
4765: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4766: }
4767: } else {
4768: $error{'default'} = $error;
4769: }
1.46 raeburn 4770: }
4771: }
4772: }
4773: } else {
1.95 www 4774: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4775: }
4776: }
4777: if (ref($settings) eq 'HASH') {
4778: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4779: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4780: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4781: $scantronurl = '';
4782: } else {
4783: $scantronurl = $settings->{'scantronformat'};
4784: }
4785: $is_custom = 1;
4786: } else {
4787: $scantronurl = $scantronurls{'default'};
4788: }
4789: } else {
1.60 raeburn 4790: if ($is_custom) {
4791: $scantronurl = $scantronurls{'custom'};
4792: } else {
4793: $scantronurl = $scantronurls{'default'};
4794: }
1.46 raeburn 4795: }
4796: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4797: $datatable .= '<tr'.$css_class.'>';
4798: if (!$is_custom) {
1.65 raeburn 4799: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4800: '<span class="LC_nobreak">';
1.46 raeburn 4801: if ($scantronurl) {
1.199 raeburn 4802: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4803: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4804: } else {
4805: $datatable = &mt('File unavailable for display');
4806: }
1.65 raeburn 4807: $datatable .= '</span></td>';
1.60 raeburn 4808: if (keys(%error) == 0) {
4809: $datatable .= '<td valign="bottom">';
4810: if (!$switchserver) {
4811: $datatable .= &mt('Upload:').'<br />';
4812: }
4813: } else {
4814: my $errorstr;
4815: foreach my $key (sort(keys(%error))) {
4816: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4817: }
4818: $datatable .= '<td>'.$errorstr;
4819: }
1.46 raeburn 4820: } else {
4821: if (keys(%error) > 0) {
4822: my $errorstr;
4823: foreach my $key (sort(keys(%error))) {
4824: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4825: }
1.60 raeburn 4826: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4827: } elsif ($scantronurl) {
1.199 raeburn 4828: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4829: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4830: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4831: $link.
4832: '<label><input type="checkbox" name="scantronformat_del"'.
4833: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4834: '<td><span class="LC_nobreak"> '.
4835: &mt('Replace:').'</span><br />';
1.46 raeburn 4836: }
4837: }
4838: if (keys(%error) == 0) {
4839: if ($switchserver) {
4840: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4841: } else {
1.65 raeburn 4842: $datatable .='<span class="LC_nobreak"> '.
4843: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4844: }
4845: }
4846: $datatable .= '</td></tr>';
4847: $$rowtotal ++;
4848: return $datatable;
4849: }
4850:
4851: sub legacy_scantronformat {
4852: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4853: my ($url,$error);
4854: my @statinfo = &Apache::lonnet::stat_file($newurl);
4855: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4856: (my $result,$url) =
4857: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4858: '','',$newfile);
4859: if ($result ne 'ok') {
1.130 raeburn 4860: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4861: }
4862: }
4863: return ($url,$error);
4864: }
1.43 raeburn 4865:
1.49 raeburn 4866: sub print_coursecategories {
1.57 raeburn 4867: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4868: my $datatable;
4869: if ($position eq 'top') {
1.238 raeburn 4870: my (%checked);
4871: my @catitems = ('unauth','auth');
4872: my @cattypes = ('std','domonly','codesrch','none');
4873: $checked{'unauth'} = 'std';
4874: $checked{'auth'} = 'std';
4875: if (ref($settings) eq 'HASH') {
4876: foreach my $type (@cattypes) {
4877: if ($type eq $settings->{'unauth'}) {
4878: $checked{'unauth'} = $type;
4879: }
4880: if ($type eq $settings->{'auth'}) {
4881: $checked{'auth'} = $type;
4882: }
4883: }
4884: }
4885: my %lt = &Apache::lonlocal::texthash (
4886: unauth => 'Catalog type for unauthenticated users',
4887: auth => 'Catalog type for authenticated users',
4888: none => 'No catalog',
4889: std => 'Standard catalog',
4890: domonly => 'Domain-only catalog',
4891: codesrch => "Code search form",
4892: );
4893: my $itemcount = 0;
4894: foreach my $item (@catitems) {
4895: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4896: $datatable .= '<tr '.$css_class.'>'.
4897: '<td>'.$lt{$item}.'</td>'.
4898: '<td class="LC_right_item"><span class="LC_nobreak">';
4899: foreach my $type (@cattypes) {
4900: my $ischecked;
4901: if ($checked{$item} eq $type) {
4902: $ischecked=' checked="checked"';
4903: }
4904: $datatable .= '<label>'.
4905: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4906: ' />'.$lt{$type}.'</label> ';
4907: }
4908: $datatable .= '</td></tr>';
4909: $itemcount ++;
4910: }
4911: $$rowtotal += $itemcount;
4912: } elsif ($position eq 'middle') {
1.57 raeburn 4913: my $toggle_cats_crs = ' ';
4914: my $toggle_cats_dom = ' checked="checked" ';
4915: my $can_cat_crs = ' ';
4916: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4917: my $toggle_catscomm_comm = ' ';
4918: my $toggle_catscomm_dom = ' checked="checked" ';
4919: my $can_catcomm_comm = ' ';
4920: my $can_catcomm_dom = ' checked="checked" ';
4921:
1.57 raeburn 4922: if (ref($settings) eq 'HASH') {
4923: if ($settings->{'togglecats'} eq 'crs') {
4924: $toggle_cats_crs = $toggle_cats_dom;
4925: $toggle_cats_dom = ' ';
4926: }
4927: if ($settings->{'categorize'} eq 'crs') {
4928: $can_cat_crs = $can_cat_dom;
4929: $can_cat_dom = ' ';
4930: }
1.120 raeburn 4931: if ($settings->{'togglecatscomm'} eq 'comm') {
4932: $toggle_catscomm_comm = $toggle_catscomm_dom;
4933: $toggle_catscomm_dom = ' ';
4934: }
4935: if ($settings->{'categorizecomm'} eq 'comm') {
4936: $can_catcomm_comm = $can_catcomm_dom;
4937: $can_catcomm_dom = ' ';
4938: }
1.57 raeburn 4939: }
4940: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4941: togglecats => 'Show/Hide a course in catalog',
4942: togglecatscomm => 'Show/Hide a community in catalog',
4943: categorize => 'Assign a category to a course',
4944: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4945: );
4946: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4947: dom => 'Set in Domain',
4948: crs => 'Set in Course',
4949: comm => 'Set in Community',
1.57 raeburn 4950: );
4951: $datatable = '<tr class="LC_odd_row">'.
4952: '<td>'.$title{'togglecats'}.'</td>'.
4953: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4954: '<input type="radio" name="togglecats"'.
4955: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4956: '<label><input type="radio" name="togglecats"'.
4957: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4958: '</tr><tr>'.
4959: '<td>'.$title{'categorize'}.'</td>'.
4960: '<td class="LC_right_item"><span class="LC_nobreak">'.
4961: '<label><input type="radio" name="categorize"'.
4962: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4963: '<label><input type="radio" name="categorize"'.
4964: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4965: '</tr><tr class="LC_odd_row">'.
4966: '<td>'.$title{'togglecatscomm'}.'</td>'.
4967: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4968: '<input type="radio" name="togglecatscomm"'.
4969: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4970: '<label><input type="radio" name="togglecatscomm"'.
4971: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4972: '</tr><tr>'.
4973: '<td>'.$title{'categorizecomm'}.'</td>'.
4974: '<td class="LC_right_item"><span class="LC_nobreak">'.
4975: '<label><input type="radio" name="categorizecomm"'.
4976: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4977: '<label><input type="radio" name="categorizecomm"'.
4978: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4979: '</tr>';
1.120 raeburn 4980: $$rowtotal += 4;
1.57 raeburn 4981: } else {
4982: my $css_class;
4983: my $itemcount = 1;
4984: my $cathash;
4985: if (ref($settings) eq 'HASH') {
4986: $cathash = $settings->{'cats'};
4987: }
4988: if (ref($cathash) eq 'HASH') {
4989: my (@cats,@trails,%allitems,%idx,@jsarray);
4990: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4991: \%allitems,\%idx,\@jsarray);
4992: my $maxdepth = scalar(@cats);
4993: my $colattrib = '';
4994: if ($maxdepth > 2) {
4995: $colattrib = ' colspan="2" ';
4996: }
4997: my @path;
4998: if (@cats > 0) {
4999: if (ref($cats[0]) eq 'ARRAY') {
5000: my $numtop = @{$cats[0]};
5001: my $maxnum = $numtop;
1.120 raeburn 5002: my %default_names = (
5003: instcode => &mt('Official courses'),
5004: communities => &mt('Communities'),
5005: );
5006:
5007: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5008: ($cathash->{'instcode::0'} eq '') ||
5009: (!grep(/^communities$/,@{$cats[0]})) ||
5010: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5011: $maxnum ++;
5012: }
5013: my $lastidx;
5014: for (my $i=0; $i<$numtop; $i++) {
5015: my $parent = $cats[0][$i];
5016: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5017: my $item = &escape($parent).'::0';
5018: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5019: $lastidx = $idx{$item};
5020: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5021: .'<select name="'.$item.'"'.$chgstr.'>';
5022: for (my $k=0; $k<=$maxnum; $k++) {
5023: my $vpos = $k+1;
5024: my $selstr;
5025: if ($k == $i) {
5026: $selstr = ' selected="selected" ';
5027: }
5028: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5029: }
1.214 raeburn 5030: $datatable .= '</select></span></td><td>';
1.120 raeburn 5031: if ($parent eq 'instcode' || $parent eq 'communities') {
5032: $datatable .= '<span class="LC_nobreak">'
5033: .$default_names{$parent}.'</span>';
5034: if ($parent eq 'instcode') {
5035: $datatable .= '<br /><span class="LC_nobreak">('
5036: .&mt('with institutional codes')
5037: .')</span></td><td'.$colattrib.'>';
5038: } else {
5039: $datatable .= '<table><tr><td>';
5040: }
5041: $datatable .= '<span class="LC_nobreak">'
5042: .'<label><input type="radio" name="'
5043: .$parent.'" value="1" checked="checked" />'
5044: .&mt('Display').'</label>';
5045: if ($parent eq 'instcode') {
5046: $datatable .= ' ';
5047: } else {
5048: $datatable .= '</span></td></tr><tr><td>'
5049: .'<span class="LC_nobreak">';
5050: }
5051: $datatable .= '<label><input type="radio" name="'
5052: .$parent.'" value="0" />'
5053: .&mt('Do not display').'</label></span>';
5054: if ($parent eq 'communities') {
5055: $datatable .= '</td></tr></table>';
5056: }
5057: $datatable .= '</td>';
1.57 raeburn 5058: } else {
5059: $datatable .= $parent
1.214 raeburn 5060: .' <span class="LC_nobreak"><label>'
5061: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5062: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5063: }
5064: my $depth = 1;
5065: push(@path,$parent);
5066: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5067: pop(@path);
5068: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5069: $itemcount ++;
5070: }
1.48 raeburn 5071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5072: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5073: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5074: for (my $k=0; $k<=$maxnum; $k++) {
5075: my $vpos = $k+1;
5076: my $selstr;
1.57 raeburn 5077: if ($k == $numtop) {
1.48 raeburn 5078: $selstr = ' selected="selected" ';
5079: }
5080: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5081: }
1.59 bisitz 5082: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5083: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5084: .'</tr>'."\n";
1.48 raeburn 5085: $itemcount ++;
1.120 raeburn 5086: foreach my $default ('instcode','communities') {
5087: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5088: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5089: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5090: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5091: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5092: for (my $k=0; $k<=$maxnum; $k++) {
5093: my $vpos = $k+1;
5094: my $selstr;
5095: if ($k == $maxnum) {
5096: $selstr = ' selected="selected" ';
5097: }
5098: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5099: }
1.120 raeburn 5100: $datatable .= '</select></span></td>'.
5101: '<td><span class="LC_nobreak">'.
5102: $default_names{$default}.'</span>';
5103: if ($default eq 'instcode') {
5104: $datatable .= '<br /><span class="LC_nobreak">('
5105: .&mt('with institutional codes').')</span>';
5106: }
5107: $datatable .= '</td>'
5108: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5109: .&mt('Display').'</label> '
5110: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5111: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5112: }
5113: }
5114: }
1.57 raeburn 5115: } else {
5116: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5117: }
5118: } else {
1.238 raeburn 5119: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5120: .&initialize_categories($itemcount);
1.48 raeburn 5121: }
1.57 raeburn 5122: $$rowtotal += $itemcount;
1.48 raeburn 5123: }
5124: return $datatable;
5125: }
5126:
1.69 raeburn 5127: sub print_serverstatuses {
5128: my ($dom,$settings,$rowtotal) = @_;
5129: my $datatable;
5130: my @pages = &serverstatus_pages();
5131: my (%namedaccess,%machineaccess);
5132: foreach my $type (@pages) {
5133: $namedaccess{$type} = '';
5134: $machineaccess{$type}= '';
5135: }
5136: if (ref($settings) eq 'HASH') {
5137: foreach my $type (@pages) {
5138: if (exists($settings->{$type})) {
5139: if (ref($settings->{$type}) eq 'HASH') {
5140: foreach my $key (keys(%{$settings->{$type}})) {
5141: if ($key eq 'namedusers') {
5142: $namedaccess{$type} = $settings->{$type}->{$key};
5143: } elsif ($key eq 'machines') {
5144: $machineaccess{$type} = $settings->{$type}->{$key};
5145: }
5146: }
5147: }
5148: }
5149: }
5150: }
1.81 raeburn 5151: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5152: my $rownum = 0;
5153: my $css_class;
5154: foreach my $type (@pages) {
5155: $rownum ++;
5156: $css_class = $rownum%2?' class="LC_odd_row"':'';
5157: $datatable .= '<tr'.$css_class.'>'.
5158: '<td><span class="LC_nobreak">'.
5159: $titles->{$type}.'</span></td>'.
5160: '<td class="LC_left_item">'.
5161: '<input type="text" name="'.$type.'_namedusers" '.
5162: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5163: '<td class="LC_right_item">'.
5164: '<span class="LC_nobreak">'.
5165: '<input type="text" name="'.$type.'_machines" '.
5166: 'value="'.$machineaccess{$type}.'" size="10" />'.
5167: '</td></tr>'."\n";
5168: }
5169: $$rowtotal += $rownum;
5170: return $datatable;
5171: }
5172:
5173: sub serverstatus_pages {
5174: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5175: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5176: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5177: 'uniquecodes','diskusage');
1.69 raeburn 5178: }
5179:
1.236 raeburn 5180: sub defaults_javascript {
5181: my ($settings) = @_;
1.248 raeburn 5182: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5183: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5184: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5185: if ($maxnum eq '') {
5186: $maxnum = 0;
5187: }
5188: $maxnum ++;
1.249 raeburn 5189: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5190: return <<"ENDSCRIPT";
5191: <script type="text/javascript">
5192: // <![CDATA[
5193: function reorderTypes(form,caller) {
5194: var changedVal;
5195: $jstext
5196: var newpos = 'addinststatus_pos';
5197: var current = new Array;
5198: var maxh = $maxnum;
5199: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5200: var oldVal;
5201: if (caller == newpos) {
5202: changedVal = newitemVal;
5203: } else {
5204: var curritem = 'inststatus_pos_'+caller;
5205: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5206: current[newitemVal] = newpos;
5207: }
5208: for (var i=0; i<inststatuses.length; i++) {
5209: if (inststatuses[i] != caller) {
5210: var elementName = 'inststatus_pos_'+inststatuses[i];
5211: if (form.elements[elementName]) {
5212: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5213: current[currVal] = elementName;
5214: }
5215: }
5216: }
5217: for (var j=0; j<maxh; j++) {
5218: if (current[j] == undefined) {
5219: oldVal = j;
5220: }
5221: }
5222: if (oldVal < changedVal) {
5223: for (var k=oldVal+1; k<=changedVal ; k++) {
5224: var elementName = current[k];
5225: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5226: }
5227: } else {
5228: for (var k=changedVal; k<oldVal; k++) {
5229: var elementName = current[k];
5230: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5231: }
5232: }
5233: return;
5234: }
5235:
5236: // ]]>
5237: </script>
5238:
5239: ENDSCRIPT
5240: }
5241: }
5242:
1.49 raeburn 5243: sub coursecategories_javascript {
5244: my ($settings) = @_;
1.57 raeburn 5245: my ($output,$jstext,$cathash);
1.49 raeburn 5246: if (ref($settings) eq 'HASH') {
1.57 raeburn 5247: $cathash = $settings->{'cats'};
5248: }
5249: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5250: my (@cats,@jsarray,%idx);
1.57 raeburn 5251: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5252: if (@jsarray > 0) {
5253: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5254: for (my $i=0; $i<@jsarray; $i++) {
5255: if (ref($jsarray[$i]) eq 'ARRAY') {
5256: my $catstr = join('","',@{$jsarray[$i]});
5257: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5258: }
5259: }
5260: }
5261: } else {
5262: $jstext = ' var categories = Array(1);'."\n".
5263: ' categories[0] = Array("instcode_pos");'."\n";
5264: }
1.237 bisitz 5265: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5266: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5267: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5268: $output = <<"ENDSCRIPT";
5269: <script type="text/javascript">
1.109 raeburn 5270: // <![CDATA[
1.49 raeburn 5271: function reorderCats(form,parent,item,idx) {
5272: var changedVal;
5273: $jstext
5274: var newpos = 'addcategory_pos';
5275: if (parent == '') {
5276: var has_instcode = 0;
5277: var maxtop = categories[idx].length;
5278: for (var j=0; j<maxtop; j++) {
5279: if (categories[idx][j] == 'instcode::0') {
5280: has_instcode == 1;
5281: }
5282: }
5283: if (has_instcode == 0) {
5284: categories[idx][maxtop] = 'instcode_pos';
5285: }
5286: } else {
5287: newpos += '_'+parent;
5288: }
5289: var maxh = 1 + categories[idx].length;
5290: var current = new Array;
5291: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5292: if (item == newpos) {
5293: changedVal = newitemVal;
5294: } else {
5295: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5296: current[newitemVal] = newpos;
5297: }
5298: for (var i=0; i<categories[idx].length; i++) {
5299: var elementName = categories[idx][i];
5300: if (elementName != item) {
5301: if (form.elements[elementName]) {
5302: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5303: current[currVal] = elementName;
5304: }
5305: }
5306: }
5307: var oldVal;
5308: for (var j=0; j<maxh; j++) {
5309: if (current[j] == undefined) {
5310: oldVal = j;
5311: }
5312: }
5313: if (oldVal < changedVal) {
5314: for (var k=oldVal+1; k<=changedVal ; k++) {
5315: var elementName = current[k];
5316: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5317: }
5318: } else {
5319: for (var k=changedVal; k<oldVal; k++) {
5320: var elementName = current[k];
5321: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5322: }
5323: }
5324: return;
5325: }
1.120 raeburn 5326:
5327: function categoryCheck(form) {
5328: if (form.elements['addcategory_name'].value == 'instcode') {
5329: alert('$instcode_reserved\\n$choose_again');
5330: return false;
5331: }
5332: if (form.elements['addcategory_name'].value == 'communities') {
5333: alert('$communities_reserved\\n$choose_again');
5334: return false;
5335: }
5336: return true;
5337: }
5338:
1.109 raeburn 5339: // ]]>
1.49 raeburn 5340: </script>
5341:
5342: ENDSCRIPT
5343: return $output;
5344: }
5345:
1.48 raeburn 5346: sub initialize_categories {
5347: my ($itemcount) = @_;
1.120 raeburn 5348: my ($datatable,$css_class,$chgstr);
5349: my %default_names = (
5350: instcode => 'Official courses (with institutional codes)',
5351: communities => 'Communities',
5352: );
5353: my $select0 = ' selected="selected"';
5354: my $select1 = '';
5355: foreach my $default ('instcode','communities') {
5356: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5357: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5358: if ($default eq 'communities') {
5359: $select1 = $select0;
5360: $select0 = '';
5361: }
5362: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5363: .'<select name="'.$default.'_pos">'
5364: .'<option value="0"'.$select0.'>1</option>'
5365: .'<option value="1"'.$select1.'>2</option>'
5366: .'<option value="2">3</option></select> '
5367: .$default_names{$default}
5368: .'</span></td><td><span class="LC_nobreak">'
5369: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5370: .&mt('Display').'</label> <label>'
5371: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5372: .'</label></span></td></tr>';
1.120 raeburn 5373: $itemcount ++;
5374: }
1.48 raeburn 5375: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5376: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5377: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5378: .'<select name="addcategory_pos"'.$chgstr.'>'
5379: .'<option value="0">1</option>'
5380: .'<option value="1">2</option>'
5381: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5382: .&mt('Add category').'</td><td>'.&mt('Name:')
5383: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5384: return $datatable;
5385: }
5386:
5387: sub build_category_rows {
1.49 raeburn 5388: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5389: my ($text,$name,$item,$chgstr);
1.48 raeburn 5390: if (ref($cats) eq 'ARRAY') {
5391: my $maxdepth = scalar(@{$cats});
5392: if (ref($cats->[$depth]) eq 'HASH') {
5393: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5394: my $numchildren = @{$cats->[$depth]{$parent}};
5395: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5396: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5397: my ($idxnum,$parent_name,$parent_item);
5398: my $higher = $depth - 1;
5399: if ($higher == 0) {
5400: $parent_name = &escape($parent).'::'.$higher;
5401: } else {
5402: if (ref($path) eq 'ARRAY') {
5403: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5404: }
5405: }
5406: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5407: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5408: if ($j < $numchildren) {
1.48 raeburn 5409: $name = $cats->[$depth]{$parent}[$j];
5410: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5411: $idxnum = $idx->{$item};
5412: } else {
5413: $name = $parent_name;
5414: $item = $parent_item;
1.48 raeburn 5415: }
1.49 raeburn 5416: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5417: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5418: for (my $i=0; $i<=$numchildren; $i++) {
5419: my $vpos = $i+1;
5420: my $selstr;
5421: if ($j == $i) {
5422: $selstr = ' selected="selected" ';
5423: }
5424: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5425: }
5426: $text .= '</select> ';
5427: if ($j < $numchildren) {
5428: my $deeper = $depth+1;
5429: $text .= $name.' '
5430: .'<label><input type="checkbox" name="deletecategory" value="'
5431: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5432: if(ref($path) eq 'ARRAY') {
5433: push(@{$path},$name);
1.49 raeburn 5434: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5435: pop(@{$path});
5436: }
5437: } else {
1.59 bisitz 5438: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5439: if ($j == $numchildren) {
5440: $text .= $name;
5441: } else {
5442: $text .= $item;
5443: }
5444: $text .= '" value="" />';
5445: }
5446: $text .= '</td></tr>';
5447: }
5448: $text .= '</table></td>';
5449: } else {
5450: my $higher = $depth-1;
5451: if ($higher == 0) {
5452: $name = &escape($parent).'::'.$higher;
5453: } else {
5454: if (ref($path) eq 'ARRAY') {
5455: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5456: }
5457: }
5458: my $colspan;
5459: if ($parent ne 'instcode') {
5460: $colspan = $maxdepth - $depth - 1;
5461: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5462: }
5463: }
5464: }
5465: }
5466: return $text;
5467: }
5468:
1.33 raeburn 5469: sub modifiable_userdata_row {
1.228 raeburn 5470: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5471: my ($role,$rolename,$statustype);
5472: $role = $item;
1.224 raeburn 5473: if ($context eq 'cancreate') {
1.228 raeburn 5474: if ($item =~ /^emailusername_(.+)$/) {
5475: $statustype = $1;
5476: $role = 'emailusername';
5477: if (ref($usertypes) eq 'HASH') {
5478: if ($usertypes->{$statustype}) {
5479: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5480: } else {
5481: $rolename = &mt('Data provided by user');
5482: }
5483: }
1.224 raeburn 5484: }
5485: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5486: if (ref($usertypes) eq 'HASH') {
5487: $rolename = $usertypes->{$role};
5488: } else {
5489: $rolename = $role;
5490: }
1.33 raeburn 5491: } else {
1.63 raeburn 5492: if ($role eq 'cr') {
5493: $rolename = &mt('Custom role');
5494: } else {
5495: $rolename = &Apache::lonnet::plaintext($role);
5496: }
1.33 raeburn 5497: }
1.224 raeburn 5498: my (@fields,%fieldtitles);
5499: if (ref($fieldsref) eq 'ARRAY') {
5500: @fields = @{$fieldsref};
5501: } else {
5502: @fields = ('lastname','firstname','middlename','generation',
5503: 'permanentemail','id');
5504: }
5505: if ((ref($titlesref) eq 'HASH')) {
5506: %fieldtitles = %{$titlesref};
5507: } else {
5508: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5509: }
1.33 raeburn 5510: my $output;
5511: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5512: $output = '<tr '.$css_class.'>'.
5513: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5514: '<td class="LC_left_item" colspan="2"><table>';
5515: my $rem;
5516: my %checks;
5517: if (ref($settings) eq 'HASH') {
5518: if (ref($settings->{$context}) eq 'HASH') {
5519: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5520: my $hashref = $settings->{$context}->{$role};
5521: if ($role eq 'emailusername') {
5522: if ($statustype) {
5523: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5524: $hashref = $settings->{$context}->{$role}->{$statustype};
5525: if (ref($hashref) eq 'HASH') {
5526: foreach my $field (@fields) {
5527: if ($hashref->{$field}) {
5528: $checks{$field} = $hashref->{$field};
5529: }
5530: }
5531: }
5532: }
5533: }
5534: } else {
5535: if (ref($hashref) eq 'HASH') {
5536: foreach my $field (@fields) {
5537: if ($hashref->{$field}) {
5538: $checks{$field} = ' checked="checked" ';
5539: }
5540: }
1.33 raeburn 5541: }
5542: }
5543: }
5544: }
5545: }
1.228 raeburn 5546:
1.33 raeburn 5547: for (my $i=0; $i<@fields; $i++) {
5548: my $rem = $i%($numinrow);
5549: if ($rem == 0) {
5550: if ($i > 0) {
5551: $output .= '</tr>';
5552: }
5553: $output .= '<tr>';
5554: }
5555: my $check = ' ';
1.228 raeburn 5556: unless ($role eq 'emailusername') {
5557: if (exists($checks{$fields[$i]})) {
5558: $check = $checks{$fields[$i]}
5559: } else {
5560: if ($role eq 'st') {
5561: if (ref($settings) ne 'HASH') {
5562: $check = ' checked="checked" ';
5563: }
1.33 raeburn 5564: }
5565: }
5566: }
5567: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5568: '<span class="LC_nobreak">';
5569: if ($role eq 'emailusername') {
5570: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5571: $checks{$fields[$i]} = 'omit';
5572: }
5573: foreach my $option ('required','optional','omit') {
5574: my $checked='';
5575: if ($checks{$fields[$i]} eq $option) {
5576: $checked='checked="checked" ';
5577: }
5578: $output .= '<label>'.
5579: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5580: &mt($option).'</label>'.(' ' x2);
5581: }
5582: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5583: } else {
5584: $output .= '<label>'.
5585: '<input type="checkbox" name="canmodify_'.$role.'" '.
5586: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5587: '</label>';
5588: }
5589: $output .= '</span></td>';
1.33 raeburn 5590: $rem = @fields%($numinrow);
5591: }
5592: my $colsleft = $numinrow - $rem;
5593: if ($colsleft > 1 ) {
5594: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5595: ' </td>';
5596: } elsif ($colsleft == 1) {
5597: $output .= '<td class="LC_left_item"> </td>';
5598: }
5599: $output .= '</tr></table></td></tr>';
5600: return $output;
5601: }
1.28 raeburn 5602:
1.93 raeburn 5603: sub insttypes_row {
1.224 raeburn 5604: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5605: my %lt = &Apache::lonlocal::texthash (
5606: cansearch => 'Users allowed to search',
5607: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5608: lockablenames => 'User preference to lock name',
1.93 raeburn 5609: );
5610: my $showdom;
5611: if ($context eq 'cansearch') {
5612: $showdom = ' ('.$dom.')';
5613: }
1.165 raeburn 5614: my $class = 'LC_left_item';
5615: if ($context eq 'statustocreate') {
5616: $class = 'LC_right_item';
5617: }
1.224 raeburn 5618: my $css_class = ' class="LC_odd_row"';
5619: if ($rownum ne '') {
5620: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5621: }
5622: my $output = '<tr'.$css_class.'>'.
5623: '<td>'.$lt{$context}.$showdom.
5624: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5625: my $rem;
5626: if (ref($types) eq 'ARRAY') {
5627: for (my $i=0; $i<@{$types}; $i++) {
5628: if (defined($usertypes->{$types->[$i]})) {
5629: my $rem = $i%($numinrow);
5630: if ($rem == 0) {
5631: if ($i > 0) {
5632: $output .= '</tr>';
5633: }
5634: $output .= '<tr>';
1.23 raeburn 5635: }
1.26 raeburn 5636: my $check = ' ';
1.99 raeburn 5637: if (ref($settings) eq 'HASH') {
5638: if (ref($settings->{$context}) eq 'ARRAY') {
5639: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5640: $check = ' checked="checked" ';
5641: }
5642: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5643: $check = ' checked="checked" ';
5644: }
1.23 raeburn 5645: }
1.26 raeburn 5646: $output .= '<td class="LC_left_item">'.
5647: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5648: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5649: 'value="'.$types->[$i].'"'.$check.'/>'.
5650: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5651: }
5652: }
1.26 raeburn 5653: $rem = @{$types}%($numinrow);
1.23 raeburn 5654: }
5655: my $colsleft = $numinrow - $rem;
1.131 raeburn 5656: if (($rem == 0) && (@{$types} > 0)) {
5657: $output .= '<tr>';
5658: }
1.23 raeburn 5659: if ($colsleft > 1) {
1.25 raeburn 5660: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5661: } else {
1.25 raeburn 5662: $output .= '<td class="LC_left_item">';
1.23 raeburn 5663: }
5664: my $defcheck = ' ';
1.99 raeburn 5665: if (ref($settings) eq 'HASH') {
5666: if (ref($settings->{$context}) eq 'ARRAY') {
5667: if (grep(/^default$/,@{$settings->{$context}})) {
5668: $defcheck = ' checked="checked" ';
5669: }
5670: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5671: $defcheck = ' checked="checked" ';
5672: }
1.23 raeburn 5673: }
1.25 raeburn 5674: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5675: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5676: 'value="default"'.$defcheck.'/>'.
5677: $othertitle.'</label></span></td>'.
5678: '</tr></table></td></tr>';
5679: return $output;
1.23 raeburn 5680: }
5681:
5682: sub sorted_searchtitles {
5683: my %searchtitles = &Apache::lonlocal::texthash(
5684: 'uname' => 'username',
5685: 'lastname' => 'last name',
5686: 'lastfirst' => 'last name, first name',
5687: );
5688: my @titleorder = ('uname','lastname','lastfirst');
5689: return (\%searchtitles,\@titleorder);
5690: }
5691:
1.25 raeburn 5692: sub sorted_searchtypes {
5693: my %srchtypes_desc = (
5694: exact => 'is exact match',
5695: contains => 'contains ..',
5696: begins => 'begins with ..',
5697: );
5698: my @srchtypeorder = ('exact','begins','contains');
5699: return (\%srchtypes_desc,\@srchtypeorder);
5700: }
5701:
1.3 raeburn 5702: sub usertype_update_row {
5703: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5704: my $datatable;
5705: my $numinrow = 4;
5706: foreach my $type (@{$types}) {
5707: if (defined($usertypes->{$type})) {
5708: $$rownums ++;
5709: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5710: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5711: '</td><td class="LC_left_item"><table>';
5712: for (my $i=0; $i<@{$fields}; $i++) {
5713: my $rem = $i%($numinrow);
5714: if ($rem == 0) {
5715: if ($i > 0) {
5716: $datatable .= '</tr>';
5717: }
5718: $datatable .= '<tr>';
5719: }
5720: my $check = ' ';
1.39 raeburn 5721: if (ref($settings) eq 'HASH') {
5722: if (ref($settings->{'fields'}) eq 'HASH') {
5723: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5724: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5725: $check = ' checked="checked" ';
5726: }
1.3 raeburn 5727: }
5728: }
5729: }
5730:
5731: if ($i == @{$fields}-1) {
5732: my $colsleft = $numinrow - $rem;
5733: if ($colsleft > 1) {
5734: $datatable .= '<td colspan="'.$colsleft.'">';
5735: } else {
5736: $datatable .= '<td>';
5737: }
5738: } else {
5739: $datatable .= '<td>';
5740: }
1.8 raeburn 5741: $datatable .= '<span class="LC_nobreak"><label>'.
5742: '<input type="checkbox" name="updateable_'.$type.
5743: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5744: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5745: }
5746: $datatable .= '</tr></table></td></tr>';
5747: }
5748: }
5749: return $datatable;
1.1 raeburn 5750: }
5751:
5752: sub modify_login {
1.205 raeburn 5753: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5754: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5755: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5756: %title = ( coursecatalog => 'Display course catalog',
5757: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5758: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5759: newuser => 'Link for visitors to create a user account',
5760: loginheader => 'Log-in box header');
5761: @offon = ('off','on');
1.112 raeburn 5762: if (ref($domconfig{login}) eq 'HASH') {
5763: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5764: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5765: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5766: }
5767: }
5768: }
1.9 raeburn 5769: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5770: \%domconfig,\%loginhash);
1.188 raeburn 5771: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5772: foreach my $item (@toggles) {
5773: $loginhash{login}{$item} = $env{'form.'.$item};
5774: }
1.41 raeburn 5775: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5776: if (ref($colchanges{'login'}) eq 'HASH') {
5777: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5778: \%loginhash);
5779: }
1.110 raeburn 5780:
1.149 raeburn 5781: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5782: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5783: if (keys(%servers) > 1) {
5784: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5785: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5786: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5787: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5788: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5789: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5790: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5791: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5792: $changes{'loginvia'}{$lonhost} = 1;
5793: } else {
5794: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5795: $changes{'loginvia'}{$lonhost} = 1;
5796: }
5797: } else {
5798: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5799: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5800: $changes{'loginvia'}{$lonhost} = 1;
5801: }
5802: }
5803: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5804: foreach my $item (@loginvia_attribs) {
5805: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5806: }
5807: } else {
5808: foreach my $item (@loginvia_attribs) {
5809: my $new = $env{'form.'.$lonhost.'_'.$item};
5810: if (($item eq 'serverpath') && ($new eq 'custom')) {
5811: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5812: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5813: $new = '/';
5814: }
5815: }
5816: if (($item eq 'custompath') &&
5817: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5818: $new = '';
5819: }
5820: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5821: $changes{'loginvia'}{$lonhost} = 1;
5822: }
5823: if ($item eq 'exempt') {
5824: $new =~ s/^\s+//;
5825: $new =~ s/\s+$//;
5826: my @poss_ips = split(/\s*[,:]\s*/,$new);
5827: my @okips;
5828: foreach my $ip (@poss_ips) {
5829: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5830: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5831: push(@okips,$ip);
5832: }
5833: }
5834: }
5835: if (@okips > 0) {
5836: $new = join(',',@okips);
5837: } else {
5838: $new = '';
5839: }
5840: }
5841: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5842: }
5843: }
1.112 raeburn 5844: } else {
1.128 raeburn 5845: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5846: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5847: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5848: foreach my $item (@loginvia_attribs) {
5849: my $new = $env{'form.'.$lonhost.'_'.$item};
5850: if (($item eq 'serverpath') && ($new eq 'custom')) {
5851: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5852: $new = '/';
5853: }
5854: }
5855: if (($item eq 'custompath') &&
5856: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5857: $new = '';
5858: }
5859: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5860: }
1.110 raeburn 5861: }
5862: }
5863: }
5864: }
1.119 raeburn 5865:
1.168 raeburn 5866: my $servadm = $r->dir_config('lonAdmEMail');
5867: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5868: if (ref($domconfig{'login'}) eq 'HASH') {
5869: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5870: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5871: if ($lang eq 'nolang') {
5872: push(@currlangs,$lang);
5873: } elsif (defined($langchoices{$lang})) {
5874: push(@currlangs,$lang);
5875: } else {
5876: next;
5877: }
5878: }
5879: }
5880: }
5881: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5882: if (@currlangs > 0) {
5883: foreach my $lang (@currlangs) {
5884: if (grep(/^\Q$lang\E$/,@delurls)) {
5885: $changes{'helpurl'}{$lang} = 1;
5886: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5887: $changes{'helpurl'}{$lang} = 1;
5888: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5889: push(@newlangs,$lang);
5890: } else {
5891: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5892: }
5893: }
5894: }
5895: unless (grep(/^nolang$/,@currlangs)) {
5896: if ($env{'form.loginhelpurl_nolang.filename'}) {
5897: $changes{'helpurl'}{'nolang'} = 1;
5898: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5899: push(@newlangs,'nolang');
5900: }
5901: }
5902: if ($env{'form.loginhelpurl_add_lang'}) {
5903: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5904: ($env{'form.loginhelpurl_add_file.filename'})) {
5905: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5906: $addedfile = $env{'form.loginhelpurl_add_lang'};
5907: }
5908: }
5909: if ((@newlangs > 0) || ($addedfile)) {
5910: my $error;
5911: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5912: if ($configuserok eq 'ok') {
5913: if ($switchserver) {
5914: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5915: } elsif ($author_ok eq 'ok') {
5916: my @allnew = @newlangs;
5917: if ($addedfile ne '') {
5918: push(@allnew,$addedfile);
5919: }
5920: foreach my $lang (@allnew) {
5921: my $formelem = 'loginhelpurl_'.$lang;
5922: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5923: $formelem = 'loginhelpurl_add_file';
5924: }
5925: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5926: "help/$lang",'','',$newfile{$lang});
5927: if ($result eq 'ok') {
5928: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5929: $changes{'helpurl'}{$lang} = 1;
5930: } else {
5931: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5932: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5933: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5934: (!grep(/^\Q$lang\E$/,@delurls))) {
5935:
5936: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5937: }
5938: }
5939: }
5940: } else {
5941: $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);
5942: }
5943: } else {
5944: $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);
5945: }
5946: if ($error) {
5947: &Apache::lonnet::logthis($error);
5948: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5949: }
5950: }
1.169 raeburn 5951: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5952:
5953: my $defaulthelpfile = '/adm/loginproblems.html';
5954: my $defaulttext = &mt('Default in use');
5955:
1.1 raeburn 5956: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5957: $dom);
5958: if ($putresult eq 'ok') {
1.188 raeburn 5959: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5960: my %defaultchecked = (
5961: 'coursecatalog' => 'on',
1.188 raeburn 5962: 'helpdesk' => 'on',
1.42 raeburn 5963: 'adminmail' => 'off',
1.43 raeburn 5964: 'newuser' => 'off',
1.42 raeburn 5965: );
1.55 raeburn 5966: if (ref($domconfig{'login'}) eq 'HASH') {
5967: foreach my $item (@toggles) {
5968: if ($defaultchecked{$item} eq 'on') {
5969: if (($domconfig{'login'}{$item} eq '0') &&
5970: ($env{'form.'.$item} eq '1')) {
5971: $changes{$item} = 1;
5972: } elsif (($domconfig{'login'}{$item} eq '' ||
5973: $domconfig{'login'}{$item} eq '1') &&
5974: ($env{'form.'.$item} eq '0')) {
5975: $changes{$item} = 1;
5976: }
5977: } elsif ($defaultchecked{$item} eq 'off') {
5978: if (($domconfig{'login'}{$item} eq '1') &&
5979: ($env{'form.'.$item} eq '0')) {
5980: $changes{$item} = 1;
5981: } elsif (($domconfig{'login'}{$item} eq '' ||
5982: $domconfig{'login'}{$item} eq '0') &&
5983: ($env{'form.'.$item} eq '1')) {
5984: $changes{$item} = 1;
5985: }
1.42 raeburn 5986: }
5987: }
1.41 raeburn 5988: }
1.6 raeburn 5989: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5990: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5991: if (ref($lastactref) eq 'HASH') {
5992: $lastactref->{'domainconfig'} = 1;
5993: }
1.1 raeburn 5994: $resulttext = &mt('Changes made:').'<ul>';
5995: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5996: if ($item eq 'loginvia') {
1.112 raeburn 5997: if (ref($changes{$item}) eq 'HASH') {
5998: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5999: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6000: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6001: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6002: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6003: $protocol = 'http' if ($protocol ne 'https');
6004: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6005:
6006: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6007: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6008: } else {
6009: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6010: }
6011: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6012: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6013: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6014: }
6015: $resulttext .= '</li>';
6016: } else {
6017: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6018: }
1.112 raeburn 6019: } else {
1.128 raeburn 6020: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6021: }
6022: }
1.128 raeburn 6023: $resulttext .= '</ul></li>';
1.112 raeburn 6024: }
1.168 raeburn 6025: } elsif ($item eq 'helpurl') {
6026: if (ref($changes{$item}) eq 'HASH') {
6027: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6028: if (grep(/^\Q$lang\E$/,@delurls)) {
6029: my ($chg,$link);
6030: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6031: if ($lang eq 'nolang') {
6032: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6033: } else {
6034: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6035: }
6036: $resulttext .= '<li>'.$chg.'</li>';
6037: } else {
6038: my $chg;
6039: if ($lang eq 'nolang') {
6040: $chg = &mt('custom log-in help file for no preferred language');
6041: } else {
6042: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6043: }
6044: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6045: $loginhash{'login'}{'helpurl'}{$lang}.
6046: '?inhibitmenu=yes',$chg,600,500).
6047: '</li>';
6048: }
6049: }
6050: }
1.169 raeburn 6051: } elsif ($item eq 'captcha') {
6052: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6053: my $chgtxt;
1.169 raeburn 6054: if ($loginhash{'login'}{$item} eq 'notused') {
6055: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6056: } else {
6057: my %captchas = &captcha_phrases();
6058: if ($captchas{$loginhash{'login'}{$item}}) {
6059: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6060: } else {
6061: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6062: }
6063: }
6064: $resulttext .= '<li>'.$chgtxt.'</li>';
6065: }
6066: } elsif ($item eq 'recaptchakeys') {
6067: if (ref($loginhash{'login'}) eq 'HASH') {
6068: my ($privkey,$pubkey);
6069: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6070: $pubkey = $loginhash{'login'}{$item}{'public'};
6071: $privkey = $loginhash{'login'}{$item}{'private'};
6072: }
6073: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6074: if (!$pubkey) {
6075: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6076: } else {
6077: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6078: }
6079: if (!$privkey) {
6080: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6081: } else {
1.251 raeburn 6082: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6083: }
6084: $chgtxt .= '</ul>';
6085: $resulttext .= '<li>'.$chgtxt.'</li>';
6086: }
1.41 raeburn 6087: } else {
6088: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6089: }
1.1 raeburn 6090: }
1.6 raeburn 6091: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6092: } else {
6093: $resulttext = &mt('No changes made to log-in page settings');
6094: }
6095: } else {
1.11 albertel 6096: $resulttext = '<span class="LC_error">'.
6097: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6098: }
1.6 raeburn 6099: if ($errors) {
1.9 raeburn 6100: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6101: $errors.'</ul>';
6102: }
6103: return $resulttext;
6104: }
6105:
6106: sub color_font_choices {
6107: my %choices =
6108: &Apache::lonlocal::texthash (
6109: img => "Header",
6110: bgs => "Background colors",
6111: links => "Link colors",
1.55 raeburn 6112: images => "Images",
1.6 raeburn 6113: font => "Font color",
1.201 raeburn 6114: fontmenu => "Font menu",
1.76 raeburn 6115: pgbg => "Page",
1.6 raeburn 6116: tabbg => "Header",
6117: sidebg => "Border",
6118: link => "Link",
6119: alink => "Active link",
6120: vlink => "Visited link",
6121: );
6122: return %choices;
6123: }
6124:
6125: sub modify_rolecolors {
1.205 raeburn 6126: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6127: my ($resulttext,%rolehash);
6128: $rolehash{'rolecolors'} = {};
1.55 raeburn 6129: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6130: if ($domconfig{'rolecolors'} eq '') {
6131: $domconfig{'rolecolors'} = {};
6132: }
6133: }
1.9 raeburn 6134: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6135: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6136: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6137: $dom);
6138: if ($putresult eq 'ok') {
6139: if (keys(%changes) > 0) {
1.41 raeburn 6140: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6141: if (ref($lastactref) eq 'HASH') {
6142: $lastactref->{'domainconfig'} = 1;
6143: }
1.6 raeburn 6144: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6145: $rolehash{'rolecolors'});
6146: } else {
6147: $resulttext = &mt('No changes made to default color schemes');
6148: }
6149: } else {
1.11 albertel 6150: $resulttext = '<span class="LC_error">'.
6151: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6152: }
6153: if ($errors) {
6154: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6155: $errors.'</ul>';
6156: }
6157: return $resulttext;
6158: }
6159:
6160: sub modify_colors {
1.9 raeburn 6161: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6162: my (%changes,%choices);
1.51 raeburn 6163: my @bgs;
1.6 raeburn 6164: my @links = ('link','alink','vlink');
1.41 raeburn 6165: my @logintext;
1.6 raeburn 6166: my @images;
6167: my $servadm = $r->dir_config('lonAdmEMail');
6168: my $errors;
1.200 raeburn 6169: my %defaults;
1.6 raeburn 6170: foreach my $role (@{$roles}) {
6171: if ($role eq 'login') {
1.12 raeburn 6172: %choices = &login_choices();
1.41 raeburn 6173: @logintext = ('textcol','bgcol');
1.12 raeburn 6174: } else {
6175: %choices = &color_font_choices();
6176: }
6177: if ($role eq 'login') {
1.41 raeburn 6178: @images = ('img','logo','domlogo','login');
1.51 raeburn 6179: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6180: } else {
6181: @images = ('img');
1.200 raeburn 6182: @bgs = ('pgbg','tabbg','sidebg');
6183: }
6184: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6185: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6186: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6187: }
6188: if ($role eq 'login') {
6189: foreach my $item (@logintext) {
1.234 raeburn 6190: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6191: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6192: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6193: }
6194: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6195: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6196: }
6197: }
6198: } else {
1.234 raeburn 6199: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6200: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6201: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6202: }
6203: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6204: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6205: }
1.6 raeburn 6206: }
1.200 raeburn 6207: foreach my $item (@bgs) {
1.234 raeburn 6208: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6209: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6210: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6211: }
6212: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6213: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6214: }
6215: }
6216: foreach my $item (@links) {
1.234 raeburn 6217: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6218: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6219: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6220: }
6221: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6222: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6223: }
1.6 raeburn 6224: }
1.46 raeburn 6225: my ($configuserok,$author_ok,$switchserver) =
6226: &config_check($dom,$confname,$servadm);
1.9 raeburn 6227: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6228: if (ref($domconfig->{$role}) ne 'HASH') {
6229: $domconfig->{$role} = {};
6230: }
1.8 raeburn 6231: foreach my $img (@images) {
1.70 raeburn 6232: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6233: if (defined($env{'form.login_showlogo_'.$img})) {
6234: $confhash->{$role}{'showlogo'}{$img} = 1;
6235: } else {
6236: $confhash->{$role}{'showlogo'}{$img} = 0;
6237: }
6238: }
1.18 albertel 6239: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6240: && !defined($domconfig->{$role}{$img})
6241: && !$env{'form.'.$role.'_del_'.$img}
6242: && $env{'form.'.$role.'_import_'.$img}) {
6243: # import the old configured image from the .tab setting
6244: # if they haven't provided a new one
6245: $domconfig->{$role}{$img} =
6246: $env{'form.'.$role.'_import_'.$img};
6247: }
1.6 raeburn 6248: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6249: my $error;
1.6 raeburn 6250: if ($configuserok eq 'ok') {
1.9 raeburn 6251: if ($switchserver) {
1.12 raeburn 6252: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6253: } else {
6254: if ($author_ok eq 'ok') {
6255: my ($result,$logourl) =
6256: &publishlogo($r,'upload',$role.'_'.$img,
6257: $dom,$confname,$img,$width,$height);
6258: if ($result eq 'ok') {
6259: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6260: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6261: } else {
1.12 raeburn 6262: $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 6263: }
6264: } else {
1.46 raeburn 6265: $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 6266: }
6267: }
6268: } else {
1.46 raeburn 6269: $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 6270: }
6271: if ($error) {
1.8 raeburn 6272: &Apache::lonnet::logthis($error);
1.11 albertel 6273: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6274: }
6275: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6276: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6277: my $error;
6278: if ($configuserok eq 'ok') {
6279: # is confname an author?
6280: if ($switchserver eq '') {
6281: if ($author_ok eq 'ok') {
6282: my ($result,$logourl) =
6283: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6284: $dom,$confname,$img,$width,$height);
6285: if ($result eq 'ok') {
6286: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6287: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6288: }
6289: }
6290: }
6291: }
1.6 raeburn 6292: }
6293: }
6294: }
6295: if (ref($domconfig) eq 'HASH') {
6296: if (ref($domconfig->{$role}) eq 'HASH') {
6297: foreach my $img (@images) {
6298: if ($domconfig->{$role}{$img} ne '') {
6299: if ($env{'form.'.$role.'_del_'.$img}) {
6300: $confhash->{$role}{$img} = '';
1.12 raeburn 6301: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6302: } else {
1.9 raeburn 6303: if ($confhash->{$role}{$img} eq '') {
6304: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6305: }
1.6 raeburn 6306: }
6307: } else {
6308: if ($env{'form.'.$role.'_del_'.$img}) {
6309: $confhash->{$role}{$img} = '';
1.12 raeburn 6310: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6311: }
6312: }
1.70 raeburn 6313: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6314: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6315: if ($confhash->{$role}{'showlogo'}{$img} ne
6316: $domconfig->{$role}{'showlogo'}{$img}) {
6317: $changes{$role}{'showlogo'}{$img} = 1;
6318: }
6319: } else {
6320: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6321: $changes{$role}{'showlogo'}{$img} = 1;
6322: }
6323: }
6324: }
6325: }
1.6 raeburn 6326: if ($domconfig->{$role}{'font'} ne '') {
6327: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6328: $changes{$role}{'font'} = 1;
6329: }
6330: } else {
6331: if ($confhash->{$role}{'font'}) {
6332: $changes{$role}{'font'} = 1;
6333: }
6334: }
1.107 raeburn 6335: if ($role ne 'login') {
6336: if ($domconfig->{$role}{'fontmenu'} ne '') {
6337: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6338: $changes{$role}{'fontmenu'} = 1;
6339: }
6340: } else {
6341: if ($confhash->{$role}{'fontmenu'}) {
6342: $changes{$role}{'fontmenu'} = 1;
6343: }
1.97 tempelho 6344: }
6345: }
1.6 raeburn 6346: foreach my $item (@bgs) {
6347: if ($domconfig->{$role}{$item} ne '') {
6348: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6349: $changes{$role}{'bgs'}{$item} = 1;
6350: }
6351: } else {
6352: if ($confhash->{$role}{$item}) {
6353: $changes{$role}{'bgs'}{$item} = 1;
6354: }
6355: }
6356: }
6357: foreach my $item (@links) {
6358: if ($domconfig->{$role}{$item} ne '') {
6359: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6360: $changes{$role}{'links'}{$item} = 1;
6361: }
6362: } else {
6363: if ($confhash->{$role}{$item}) {
6364: $changes{$role}{'links'}{$item} = 1;
6365: }
6366: }
6367: }
1.41 raeburn 6368: foreach my $item (@logintext) {
6369: if ($domconfig->{$role}{$item} ne '') {
6370: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6371: $changes{$role}{'logintext'}{$item} = 1;
6372: }
6373: } else {
6374: if ($confhash->{$role}{$item}) {
6375: $changes{$role}{'logintext'}{$item} = 1;
6376: }
6377: }
6378: }
1.6 raeburn 6379: } else {
6380: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6381: \@logintext,$confhash,\%changes);
1.6 raeburn 6382: }
6383: } else {
6384: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6385: \@logintext,$confhash,\%changes);
1.6 raeburn 6386: }
6387: }
6388: return ($errors,%changes);
6389: }
6390:
1.46 raeburn 6391: sub config_check {
6392: my ($dom,$confname,$servadm) = @_;
6393: my ($configuserok,$author_ok,$switchserver,%currroles);
6394: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6395: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6396: $confname,$servadm);
6397: if ($configuserok eq 'ok') {
6398: $switchserver = &check_switchserver($dom,$confname);
6399: if ($switchserver eq '') {
6400: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6401: }
6402: }
6403: return ($configuserok,$author_ok,$switchserver);
6404: }
6405:
1.6 raeburn 6406: sub default_change_checker {
1.41 raeburn 6407: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6408: foreach my $item (@{$links}) {
6409: if ($confhash->{$role}{$item}) {
6410: $changes->{$role}{'links'}{$item} = 1;
6411: }
6412: }
6413: foreach my $item (@{$bgs}) {
6414: if ($confhash->{$role}{$item}) {
6415: $changes->{$role}{'bgs'}{$item} = 1;
6416: }
6417: }
1.41 raeburn 6418: foreach my $item (@{$logintext}) {
6419: if ($confhash->{$role}{$item}) {
6420: $changes->{$role}{'logintext'}{$item} = 1;
6421: }
6422: }
1.6 raeburn 6423: foreach my $img (@{$images}) {
6424: if ($env{'form.'.$role.'_del_'.$img}) {
6425: $confhash->{$role}{$img} = '';
1.12 raeburn 6426: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6427: }
1.70 raeburn 6428: if ($role eq 'login') {
6429: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6430: $changes->{$role}{'showlogo'}{$img} = 1;
6431: }
6432: }
1.6 raeburn 6433: }
6434: if ($confhash->{$role}{'font'}) {
6435: $changes->{$role}{'font'} = 1;
6436: }
1.48 raeburn 6437: }
1.6 raeburn 6438:
6439: sub display_colorchgs {
6440: my ($dom,$changes,$roles,$confhash) = @_;
6441: my (%choices,$resulttext);
6442: if (!grep(/^login$/,@{$roles})) {
6443: $resulttext = &mt('Changes made:').'<br />';
6444: }
6445: foreach my $role (@{$roles}) {
6446: if ($role eq 'login') {
6447: %choices = &login_choices();
6448: } else {
6449: %choices = &color_font_choices();
6450: }
6451: if (ref($changes->{$role}) eq 'HASH') {
6452: if ($role ne 'login') {
6453: $resulttext .= '<h4>'.&mt($role).'</h4>';
6454: }
6455: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6456: if ($role ne 'login') {
6457: $resulttext .= '<ul>';
6458: }
6459: if (ref($changes->{$role}{$key}) eq 'HASH') {
6460: if ($role ne 'login') {
6461: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6462: }
6463: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6464: if (($role eq 'login') && ($key eq 'showlogo')) {
6465: if ($confhash->{$role}{$key}{$item}) {
6466: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6467: } else {
6468: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6469: }
6470: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6471: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6472: } else {
1.12 raeburn 6473: my $newitem = $confhash->{$role}{$item};
6474: if ($key eq 'images') {
6475: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6476: }
6477: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6478: }
6479: }
6480: if ($role ne 'login') {
6481: $resulttext .= '</ul></li>';
6482: }
6483: } else {
6484: if ($confhash->{$role}{$key} eq '') {
6485: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6486: } else {
6487: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6488: }
6489: }
6490: if ($role ne 'login') {
6491: $resulttext .= '</ul>';
6492: }
6493: }
6494: }
6495: }
1.3 raeburn 6496: return $resulttext;
1.1 raeburn 6497: }
6498:
1.9 raeburn 6499: sub thumb_dimensions {
6500: return ('200','50');
6501: }
6502:
1.16 raeburn 6503: sub check_dimensions {
6504: my ($inputfile) = @_;
6505: my ($fullwidth,$fullheight);
6506: if ($inputfile =~ m|^[/\w.\-]+$|) {
6507: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6508: my $imageinfo = <PIPE>;
6509: if (!close(PIPE)) {
6510: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6511: }
6512: chomp($imageinfo);
6513: my ($fullsize) =
1.21 raeburn 6514: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6515: if ($fullsize) {
6516: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6517: }
6518: }
6519: }
6520: return ($fullwidth,$fullheight);
6521: }
6522:
1.9 raeburn 6523: sub check_configuser {
6524: my ($uhome,$dom,$confname,$servadm) = @_;
6525: my ($configuserok,%currroles);
6526: if ($uhome eq 'no_host') {
6527: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6528: my $configpass = &LONCAPA::Enrollment::create_password();
6529: $configuserok =
6530: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6531: $configpass,'','','','','',undef,$servadm);
6532: } else {
6533: $configuserok = 'ok';
6534: %currroles =
6535: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6536: }
6537: return ($configuserok,%currroles);
6538: }
6539:
6540: sub check_authorstatus {
6541: my ($dom,$confname,%currroles) = @_;
6542: my $author_ok;
1.40 raeburn 6543: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6544: my $start = time;
6545: my $end = 0;
6546: $author_ok =
6547: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6548: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6549: } else {
6550: $author_ok = 'ok';
6551: }
6552: return $author_ok;
6553: }
6554:
6555: sub publishlogo {
1.46 raeburn 6556: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6557: my ($output,$fname,$logourl);
6558: if ($action eq 'upload') {
6559: $fname=$env{'form.'.$formname.'.filename'};
6560: chop($env{'form.'.$formname});
6561: } else {
6562: ($fname) = ($formname =~ /([^\/]+)$/);
6563: }
1.46 raeburn 6564: if ($savefileas ne '') {
6565: $fname = $savefileas;
6566: }
1.9 raeburn 6567: $fname=&Apache::lonnet::clean_filename($fname);
6568: # See if there is anything left
6569: unless ($fname) { return ('error: no uploaded file'); }
6570: $fname="$subdir/$fname";
1.210 raeburn 6571: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6572: my $filepath="$docroot/priv";
6573: my $relpath = "$dom/$confname";
1.9 raeburn 6574: my ($fnamepath,$file,$fetchthumb);
6575: $file=$fname;
6576: if ($fname=~m|/|) {
6577: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6578: }
1.164 raeburn 6579: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6580: my $count;
1.164 raeburn 6581: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6582: $filepath.="/$parts[$count]";
6583: if ((-e $filepath)!=1) {
6584: mkdir($filepath,02770);
6585: }
6586: }
6587: # Check for bad extension and disallow upload
6588: if ($file=~/\.(\w+)$/ &&
6589: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6590: $output =
1.207 bisitz 6591: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6592: } elsif ($file=~/\.(\w+)$/ &&
6593: !defined(&Apache::loncommon::fileembstyle($1))) {
6594: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6595: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6596: $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 6597: } elsif (-d "$filepath/$file") {
1.195 bisitz 6598: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6599: } else {
6600: my $source = $filepath.'/'.$file;
6601: my $logfile;
6602: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6603: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6604: }
6605: print $logfile
6606: "\n================= Publish ".localtime()." ================\n".
6607: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6608: # Save the file
6609: if (!open(FH,'>'.$source)) {
6610: &Apache::lonnet::logthis('Failed to create '.$source);
6611: return (&mt('Failed to create file'));
6612: }
6613: if ($action eq 'upload') {
6614: if (!print FH ($env{'form.'.$formname})) {
6615: &Apache::lonnet::logthis('Failed to write to '.$source);
6616: return (&mt('Failed to write file'));
6617: }
6618: } else {
6619: my $original = &Apache::lonnet::filelocation('',$formname);
6620: if(!copy($original,$source)) {
6621: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6622: return (&mt('Failed to write file'));
6623: }
6624: }
6625: close(FH);
6626: chmod(0660, $source); # Permissions to rw-rw---.
6627:
6628: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6629: my $copyfile=$targetdir.'/'.$file;
6630:
6631: my @parts=split(/\//,$targetdir);
6632: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6633: for (my $count=5;$count<=$#parts;$count++) {
6634: $path.="/$parts[$count]";
6635: if (!-e $path) {
6636: print $logfile "\nCreating directory ".$path;
6637: mkdir($path,02770);
6638: }
6639: }
6640: my $versionresult;
6641: if (-e $copyfile) {
6642: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6643: } else {
6644: $versionresult = 'ok';
6645: }
6646: if ($versionresult eq 'ok') {
6647: if (copy($source,$copyfile)) {
6648: print $logfile "\nCopied original source to ".$copyfile."\n";
6649: $output = 'ok';
6650: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6651: push(@{$modified_urls},[$copyfile,$source]);
6652: my $metaoutput =
6653: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6654: unless ($registered_cleanup) {
6655: my $handlers = $r->get_handlers('PerlCleanupHandler');
6656: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6657: $registered_cleanup=1;
6658: }
1.9 raeburn 6659: } else {
6660: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6661: $output = &mt('Failed to copy file to RES space').", $!";
6662: }
6663: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6664: my $inputfile = $filepath.'/'.$file;
6665: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6666: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6667: if ($fullwidth ne '' && $fullheight ne '') {
6668: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6669: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6670: system("convert -sample $thumbsize $inputfile $outfile");
6671: chmod(0660, $filepath.'/tn-'.$file);
6672: if (-e $outfile) {
6673: my $copyfile=$targetdir.'/tn-'.$file;
6674: if (copy($outfile,$copyfile)) {
6675: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6676: my $thumb_metaoutput =
6677: &write_metadata($dom,$confname,$formname,
6678: $targetdir,'tn-'.$file,$logfile);
6679: push(@{$modified_urls},[$copyfile,$outfile]);
6680: unless ($registered_cleanup) {
6681: my $handlers = $r->get_handlers('PerlCleanupHandler');
6682: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6683: $registered_cleanup=1;
6684: }
1.16 raeburn 6685: } else {
6686: print $logfile "\nUnable to write ".$copyfile.
6687: ':'.$!."\n";
6688: }
6689: }
1.9 raeburn 6690: }
6691: }
6692: }
6693: } else {
6694: $output = $versionresult;
6695: }
6696: }
6697: return ($output,$logourl);
6698: }
6699:
6700: sub logo_versioning {
6701: my ($targetdir,$file,$logfile) = @_;
6702: my $target = $targetdir.'/'.$file;
6703: my ($maxversion,$fn,$extn,$output);
6704: $maxversion = 0;
6705: if ($file =~ /^(.+)\.(\w+)$/) {
6706: $fn=$1;
6707: $extn=$2;
6708: }
6709: opendir(DIR,$targetdir);
6710: while (my $filename=readdir(DIR)) {
6711: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6712: $maxversion=($1>$maxversion)?$1:$maxversion;
6713: }
6714: }
6715: $maxversion++;
6716: print $logfile "\nCreating old version ".$maxversion."\n";
6717: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6718: if (copy($target,$copyfile)) {
6719: print $logfile "Copied old target to ".$copyfile."\n";
6720: $copyfile=$copyfile.'.meta';
6721: if (copy($target.'.meta',$copyfile)) {
6722: print $logfile "Copied old target metadata to ".$copyfile."\n";
6723: $output = 'ok';
6724: } else {
6725: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6726: $output = &mt('Failed to copy old meta').", $!, ";
6727: }
6728: } else {
6729: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6730: $output = &mt('Failed to copy old target').", $!, ";
6731: }
6732: return $output;
6733: }
6734:
6735: sub write_metadata {
6736: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6737: my (%metadatafields,%metadatakeys,$output);
6738: $metadatafields{'title'}=$formname;
6739: $metadatafields{'creationdate'}=time;
6740: $metadatafields{'lastrevisiondate'}=time;
6741: $metadatafields{'copyright'}='public';
6742: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6743: $env{'user.domain'};
6744: $metadatafields{'authorspace'}=$confname.':'.$dom;
6745: $metadatafields{'domain'}=$dom;
6746: {
6747: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6748: my $mfh;
1.155 raeburn 6749: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6750: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6751: unless ($_=~/\./) {
6752: my $unikey=$_;
6753: $unikey=~/^([A-Za-z]+)/;
6754: my $tag=$1;
6755: $tag=~tr/A-Z/a-z/;
6756: print $mfh "\n\<$tag";
6757: foreach (split(/\,/,$metadatakeys{$unikey})) {
6758: my $value=$metadatafields{$unikey.'.'.$_};
6759: $value=~s/\"/\'\'/g;
6760: print $mfh ' '.$_.'="'.$value.'"';
6761: }
6762: print $mfh '>'.
6763: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6764: .'</'.$tag.'>';
6765: }
6766: }
6767: $output = 'ok';
6768: print $logfile "\nWrote metadata";
6769: close($mfh);
6770: } else {
6771: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6772: $output = &mt('Could not write metadata');
6773: }
6774: }
1.155 raeburn 6775: return $output;
6776: }
6777:
6778: sub notifysubscribed {
6779: foreach my $targetsource (@{$modified_urls}){
6780: next unless (ref($targetsource) eq 'ARRAY');
6781: my ($target,$source)=@{$targetsource};
6782: if ($source ne '') {
6783: if (open(my $logfh,'>>'.$source.'.log')) {
6784: print $logfh "\nCleanup phase: Notifications\n";
6785: my @subscribed=&subscribed_hosts($target);
6786: foreach my $subhost (@subscribed) {
6787: print $logfh "\nNotifying host ".$subhost.':';
6788: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6789: print $logfh $reply;
6790: }
6791: my @subscribedmeta=&subscribed_hosts("$target.meta");
6792: foreach my $subhost (@subscribedmeta) {
6793: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6794: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6795: $subhost);
6796: print $logfh $reply;
6797: }
6798: print $logfh "\n============ Done ============\n";
1.160 raeburn 6799: close($logfh);
1.155 raeburn 6800: }
6801: }
6802: }
6803: return OK;
6804: }
6805:
6806: sub subscribed_hosts {
6807: my ($target) = @_;
6808: my @subscribed;
6809: if (open(my $fh,"<$target.subscription")) {
6810: while (my $subline=<$fh>) {
6811: if ($subline =~ /^($match_lonid):/) {
6812: my $host = $1;
6813: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6814: unless (grep(/^\Q$host\E$/,@subscribed)) {
6815: push(@subscribed,$host);
6816: }
6817: }
6818: }
6819: }
6820: }
6821: return @subscribed;
1.9 raeburn 6822: }
6823:
6824: sub check_switchserver {
6825: my ($dom,$confname) = @_;
6826: my ($allowed,$switchserver);
6827: my $home = &Apache::lonnet::homeserver($confname,$dom);
6828: if ($home eq 'no_host') {
6829: $home = &Apache::lonnet::domain($dom,'primary');
6830: }
6831: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6832: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6833: if (!$allowed) {
1.180 raeburn 6834: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6835: }
6836: return $switchserver;
6837: }
6838:
1.1 raeburn 6839: sub modify_quotas {
1.216 raeburn 6840: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6841: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6842: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 6843: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6844: $validationfieldsref);
1.86 raeburn 6845: if ($action eq 'quotas') {
6846: $context = 'tools';
1.163 raeburn 6847: } else {
1.86 raeburn 6848: $context = $action;
6849: }
6850: if ($context eq 'requestcourses') {
1.216 raeburn 6851: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6852: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6853: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6854: %titles = &courserequest_titles();
6855: $toolregexp = join('|',@usertools);
6856: %conditions = &courserequest_conditions();
1.216 raeburn 6857: $confname = $dom.'-domainconfig';
6858: my $servadm = $r->dir_config('lonAdmEMail');
6859: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 6860: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6861: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 6862: } elsif ($context eq 'requestauthor') {
6863: @usertools = ('author');
6864: %titles = &authorrequest_titles();
1.86 raeburn 6865: } else {
1.162 raeburn 6866: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6867: %titles = &tool_titles();
1.86 raeburn 6868: }
1.212 raeburn 6869: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6870: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6871: foreach my $key (keys(%env)) {
1.101 raeburn 6872: if ($context eq 'requestcourses') {
6873: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6874: my $item = $1;
6875: my $type = $2;
6876: if ($type =~ /^limit_(.+)/) {
6877: $limithash{$item}{$1} = $env{$key};
6878: } else {
6879: $confhash{$item}{$type} = $env{$key};
6880: }
6881: }
1.163 raeburn 6882: } elsif ($context eq 'requestauthor') {
6883: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6884: $confhash{$1} = $env{$key};
6885: }
1.101 raeburn 6886: } else {
1.86 raeburn 6887: if ($key =~ /^form\.quota_(.+)$/) {
6888: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6889: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6890: $confhash{'authorquota'}{$1} = $env{$key};
6891: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6892: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6893: }
1.72 raeburn 6894: }
6895: }
1.163 raeburn 6896: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6897: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6898: @approvalnotify = sort(@approvalnotify);
6899: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6900: my @crstypes = ('official','unofficial','community','textbook');
6901: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6902: foreach my $type (@hasuniquecode) {
6903: if (grep(/^\Q$type\E$/,@crstypes)) {
6904: $confhash{'uniquecode'}{$type} = 1;
6905: }
1.216 raeburn 6906: }
1.242 raeburn 6907: my (%newbook,%allpos);
1.216 raeburn 6908: if ($context eq 'requestcourses') {
1.242 raeburn 6909: foreach my $type ('textbooks','templates') {
6910: @{$allpos{$type}} = ();
6911: my $invalid;
6912: if ($type eq 'textbooks') {
6913: $invalid = &mt('Invalid LON-CAPA course for textbook');
6914: } else {
6915: $invalid = &mt('Invalid LON-CAPA course for template');
6916: }
6917: if ($env{'form.'.$type.'_addbook'}) {
6918: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6919: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6920: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6921: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6922: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6923: } else {
6924: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6925: my $position = $env{'form.'.$type.'_addbook_pos'};
6926: $position =~ s/\D+//g;
6927: if ($position ne '') {
6928: $allpos{$type}[$position] = $newbook{$type};
6929: }
1.216 raeburn 6930: }
1.242 raeburn 6931: } else {
6932: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 6933: }
6934: }
1.242 raeburn 6935: }
1.216 raeburn 6936: }
1.102 raeburn 6937: if (ref($domconfig{$action}) eq 'HASH') {
6938: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6939: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6940: $changes{'notify'}{'approval'} = 1;
6941: }
6942: } else {
1.144 raeburn 6943: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6944: $changes{'notify'}{'approval'} = 1;
6945: }
6946: }
1.218 raeburn 6947: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6948: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6949: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6950: unless ($confhash{'uniquecode'}{$crstype}) {
6951: $changes{'uniquecode'} = 1;
6952: }
6953: }
6954: unless ($changes{'uniquecode'}) {
6955: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6956: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6957: $changes{'uniquecode'} = 1;
6958: }
6959: }
6960: }
6961: } else {
6962: $changes{'uniquecode'} = 1;
6963: }
6964: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6965: $changes{'uniquecode'} = 1;
1.216 raeburn 6966: }
6967: if ($context eq 'requestcourses') {
1.242 raeburn 6968: foreach my $type ('textbooks','templates') {
6969: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6970: my %deletions;
6971: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6972: if (@todelete) {
6973: map { $deletions{$_} = 1; } @todelete;
6974: }
6975: my %imgdeletions;
6976: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6977: if (@todeleteimages) {
6978: map { $imgdeletions{$_} = 1; } @todeleteimages;
6979: }
6980: my $maxnum = $env{'form.'.$type.'_maxnum'};
6981: for (my $i=0; $i<=$maxnum; $i++) {
6982: my $itemid = $env{'form.'.$type.'_id_'.$i};
6983: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6984: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6985: if ($deletions{$key}) {
6986: if ($domconfig{$action}{$type}{$key}{'image'}) {
6987: #FIXME need to obsolete item in RES space
6988: }
6989: next;
6990: } else {
6991: my $newpos = $env{'form.'.$itemid};
6992: $newpos =~ s/\D+//g;
1.243 raeburn 6993: foreach my $item ('subject','title','publisher','author') {
6994: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6995: ($type eq 'templates'));
1.242 raeburn 6996: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6997: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6998: $changes{$type}{$key} = 1;
6999: }
7000: }
7001: $allpos{$type}[$newpos] = $key;
7002: }
7003: if ($imgdeletions{$key}) {
7004: $changes{$type}{$key} = 1;
1.216 raeburn 7005: #FIXME need to obsolete item in RES space
1.242 raeburn 7006: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7007: my ($cdom,$cnum) = split(/_/,$key);
7008: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7009: $cdom,$cnum,$type,$configuserok,
7010: $switchserver,$author_ok);
7011: if ($imgurl) {
7012: $confhash{$type}{$key}{'image'} = $imgurl;
7013: $changes{$type}{$key} = 1;
1.216 raeburn 7014: }
1.242 raeburn 7015: if ($error) {
7016: &Apache::lonnet::logthis($error);
7017: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7018: }
7019: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7020: $confhash{$type}{$key}{'image'} =
7021: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7022: }
7023: }
7024: }
7025: }
7026: }
7027: }
1.102 raeburn 7028: } else {
1.144 raeburn 7029: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7030: $changes{'notify'}{'approval'} = 1;
7031: }
1.218 raeburn 7032: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7033: $changes{'uniquecode'} = 1;
7034: }
7035: }
7036: if ($context eq 'requestcourses') {
1.242 raeburn 7037: foreach my $type ('textbooks','templates') {
7038: if ($newbook{$type}) {
7039: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7040: foreach my $item ('subject','title','publisher','author') {
7041: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7042: ($type eq 'template'));
1.242 raeburn 7043: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7044: if ($env{'form.'.$type.'_addbook_'.$item}) {
7045: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7046: }
7047: }
7048: if ($type eq 'textbooks') {
7049: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7050: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7051: my ($imageurl,$error) =
7052: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7053: $configuserok,$switchserver,$author_ok);
7054: if ($imageurl) {
7055: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7056: }
7057: if ($error) {
7058: &Apache::lonnet::logthis($error);
7059: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7060: }
7061: }
1.216 raeburn 7062: }
7063: }
1.242 raeburn 7064: if (@{$allpos{$type}} > 0) {
7065: my $idx = 0;
7066: foreach my $item (@{$allpos{$type}}) {
7067: if ($item ne '') {
7068: $confhash{$type}{$item}{'order'} = $idx;
7069: if (ref($domconfig{$action}) eq 'HASH') {
7070: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7071: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7072: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7073: $changes{$type}{$item} = 1;
7074: }
1.216 raeburn 7075: }
7076: }
7077: }
1.242 raeburn 7078: $idx ++;
1.216 raeburn 7079: }
7080: }
7081: }
7082: }
1.235 raeburn 7083: if (ref($validationitemsref) eq 'ARRAY') {
7084: foreach my $item (@{$validationitemsref}) {
7085: if ($item eq 'fields') {
7086: my @changed;
7087: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7088: if (@{$confhash{'validation'}{$item}} > 0) {
7089: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7090: }
7091: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7092: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7093: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7094: $domconfig{'requestcourses'}{'validation'}{$item});
7095: } else {
7096: @changed = @{$confhash{'validation'}{$item}};
7097: }
7098: } else {
7099: @changed = @{$confhash{'validation'}{$item}};
7100: }
7101: if (@changed) {
7102: if ($confhash{'validation'}{$item}) {
7103: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7104: } else {
7105: $changes{'validation'}{$item} = &mt('None');
7106: }
7107: }
7108: } else {
7109: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7110: if ($item eq 'markup') {
7111: if ($env{'form.requestcourses_validation_'.$item}) {
7112: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7113: }
7114: }
7115: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7116: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7117: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7118: }
7119: } else {
7120: if ($confhash{'validation'}{$item} ne '') {
7121: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7122: }
7123: }
7124: }
7125: }
7126: }
7127: if ($env{'form.validationdc'}) {
7128: my $newval = $env{'form.validationdc'};
7129: my %domcoords = &get_active_dcs($dom);
7130: if (exists($domcoords{$newval})) {
7131: $confhash{'validation'}{'dc'} = $newval;
7132: }
7133: }
7134: if (ref($confhash{'validation'}) eq 'HASH') {
7135: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7136: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7137: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7138: if ($confhash{'validation'}{'dc'} eq '') {
7139: $changes{'validation'}{'dc'} = &mt('None');
7140: } else {
7141: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7142: }
7143: }
7144: } elsif ($confhash{'validation'}{'dc'} ne '') {
7145: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7146: }
7147: } elsif ($confhash{'validation'}{'dc'} ne '') {
7148: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7149: }
7150: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7151: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7152: $changes{'validation'}{'dc'} = &mt('None');
7153: }
7154: }
1.102 raeburn 7155: }
7156: } else {
1.86 raeburn 7157: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7158: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7159: }
1.72 raeburn 7160: foreach my $item (@usertools) {
7161: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7162: my $unset;
1.101 raeburn 7163: if ($context eq 'requestcourses') {
1.104 raeburn 7164: $unset = '0';
7165: if ($type eq '_LC_adv') {
7166: $unset = '';
7167: }
1.101 raeburn 7168: if ($confhash{$item}{$type} eq 'autolimit') {
7169: $confhash{$item}{$type} .= '=';
7170: unless ($limithash{$item}{$type} =~ /\D/) {
7171: $confhash{$item}{$type} .= $limithash{$item}{$type};
7172: }
7173: }
1.163 raeburn 7174: } elsif ($context eq 'requestauthor') {
7175: $unset = '0';
7176: if ($type eq '_LC_adv') {
7177: $unset = '';
7178: }
1.72 raeburn 7179: } else {
1.101 raeburn 7180: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7181: $confhash{$item}{$type} = 1;
7182: } else {
7183: $confhash{$item}{$type} = 0;
7184: }
1.72 raeburn 7185: }
1.86 raeburn 7186: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7187: if ($action eq 'requestauthor') {
7188: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7189: $changes{$type} = 1;
7190: }
7191: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7192: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7193: $changes{$item}{$type} = 1;
7194: }
7195: } else {
7196: if ($context eq 'requestcourses') {
1.104 raeburn 7197: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7198: $changes{$item}{$type} = 1;
7199: }
7200: } else {
7201: if (!$confhash{$item}{$type}) {
7202: $changes{$item}{$type} = 1;
7203: }
7204: }
7205: }
7206: } else {
7207: if ($context eq 'requestcourses') {
1.104 raeburn 7208: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7209: $changes{$item}{$type} = 1;
7210: }
1.163 raeburn 7211: } elsif ($context eq 'requestauthor') {
7212: if ($confhash{$type} ne $unset) {
7213: $changes{$type} = 1;
7214: }
1.72 raeburn 7215: } else {
7216: if (!$confhash{$item}{$type}) {
7217: $changes{$item}{$type} = 1;
7218: }
7219: }
7220: }
1.1 raeburn 7221: }
7222: }
1.163 raeburn 7223: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7224: if (ref($domconfig{'quotas'}) eq 'HASH') {
7225: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7226: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7227: if (exists($confhash{'defaultquota'}{$key})) {
7228: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7229: $changes{'defaultquota'}{$key} = 1;
7230: }
7231: } else {
7232: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7233: }
7234: }
1.86 raeburn 7235: } else {
7236: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7237: if (exists($confhash{'defaultquota'}{$key})) {
7238: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7239: $changes{'defaultquota'}{$key} = 1;
7240: }
7241: } else {
7242: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7243: }
1.1 raeburn 7244: }
7245: }
1.197 raeburn 7246: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7247: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7248: if (exists($confhash{'authorquota'}{$key})) {
7249: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7250: $changes{'authorquota'}{$key} = 1;
7251: }
7252: } else {
7253: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7254: }
7255: }
7256: }
1.1 raeburn 7257: }
1.86 raeburn 7258: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7259: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7260: if (ref($domconfig{'quotas'}) eq 'HASH') {
7261: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7262: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7263: $changes{'defaultquota'}{$key} = 1;
7264: }
7265: } else {
7266: if (!exists($domconfig{'quotas'}{$key})) {
7267: $changes{'defaultquota'}{$key} = 1;
7268: }
1.72 raeburn 7269: }
7270: } else {
1.86 raeburn 7271: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7272: }
1.1 raeburn 7273: }
7274: }
1.197 raeburn 7275: if (ref($confhash{'authorquota'}) eq 'HASH') {
7276: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7277: if (ref($domconfig{'quotas'}) eq 'HASH') {
7278: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7279: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7280: $changes{'authorquota'}{$key} = 1;
7281: }
7282: } else {
7283: $changes{'authorquota'}{$key} = 1;
7284: }
7285: } else {
7286: $changes{'authorquota'}{$key} = 1;
7287: }
7288: }
7289: }
1.1 raeburn 7290: }
1.72 raeburn 7291:
1.163 raeburn 7292: if ($context eq 'requestauthor') {
7293: $domdefaults{'requestauthor'} = \%confhash;
7294: } else {
7295: foreach my $key (keys(%confhash)) {
1.242 raeburn 7296: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 7297: $domdefaults{$key} = $confhash{$key};
7298: }
1.163 raeburn 7299: }
1.72 raeburn 7300: }
1.163 raeburn 7301:
1.1 raeburn 7302: my %quotahash = (
1.86 raeburn 7303: $action => { %confhash }
1.1 raeburn 7304: );
7305: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7306: $dom);
7307: if ($putresult eq 'ok') {
7308: if (keys(%changes) > 0) {
1.72 raeburn 7309: my $cachetime = 24*60*60;
7310: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7311: if (ref($lastactref) eq 'HASH') {
7312: $lastactref->{'domdefaults'} = 1;
7313: }
1.1 raeburn 7314: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7315: unless (($context eq 'requestcourses') ||
1.163 raeburn 7316: ($context eq 'requestauthor')) {
1.86 raeburn 7317: if (ref($changes{'defaultquota'}) eq 'HASH') {
7318: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7319: foreach my $type (@{$types},'default') {
7320: if (defined($changes{'defaultquota'}{$type})) {
7321: my $typetitle = $usertypes->{$type};
7322: if ($type eq 'default') {
7323: $typetitle = $othertitle;
7324: }
1.213 raeburn 7325: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7326: }
7327: }
1.86 raeburn 7328: $resulttext .= '</ul></li>';
1.72 raeburn 7329: }
1.197 raeburn 7330: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7331: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7332: foreach my $type (@{$types},'default') {
7333: if (defined($changes{'authorquota'}{$type})) {
7334: my $typetitle = $usertypes->{$type};
7335: if ($type eq 'default') {
7336: $typetitle = $othertitle;
7337: }
1.213 raeburn 7338: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7339: }
7340: }
7341: $resulttext .= '</ul></li>';
7342: }
1.72 raeburn 7343: }
1.80 raeburn 7344: my %newenv;
1.72 raeburn 7345: foreach my $item (@usertools) {
1.163 raeburn 7346: my (%haschgs,%inconf);
7347: if ($context eq 'requestauthor') {
7348: %haschgs = %changes;
1.210 raeburn 7349: %inconf = %confhash;
1.163 raeburn 7350: } else {
7351: if (ref($changes{$item}) eq 'HASH') {
7352: %haschgs = %{$changes{$item}};
7353: }
7354: if (ref($confhash{$item}) eq 'HASH') {
7355: %inconf = %{$confhash{$item}};
7356: }
7357: }
7358: if (keys(%haschgs) > 0) {
1.80 raeburn 7359: my $newacc =
7360: &Apache::lonnet::usertools_access($env{'user.name'},
7361: $env{'user.domain'},
1.86 raeburn 7362: $item,'reload',$context);
1.210 raeburn 7363: if (($context eq 'requestcourses') ||
1.163 raeburn 7364: ($context eq 'requestauthor')) {
1.108 raeburn 7365: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7366: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7367: }
7368: } else {
7369: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7370: $newenv{'environment.availabletools.'.$item} = $newacc;
7371: }
1.80 raeburn 7372: }
1.163 raeburn 7373: unless ($context eq 'requestauthor') {
7374: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7375: }
1.72 raeburn 7376: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7377: if ($haschgs{$type}) {
1.72 raeburn 7378: my $typetitle = $usertypes->{$type};
7379: if ($type eq 'default') {
7380: $typetitle = $othertitle;
7381: } elsif ($type eq '_LC_adv') {
7382: $typetitle = 'LON-CAPA Advanced Users';
7383: }
1.163 raeburn 7384: if ($inconf{$type}) {
1.101 raeburn 7385: if ($context eq 'requestcourses') {
7386: my $cond;
1.163 raeburn 7387: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7388: if ($1 eq '') {
7389: $cond = &mt('(Automatic processing of any request).');
7390: } else {
7391: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7392: }
7393: } else {
1.163 raeburn 7394: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7395: }
7396: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7397: } elsif ($context eq 'requestauthor') {
7398: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7399: $titles{$inconf{$type}},$typetitle);
7400:
1.101 raeburn 7401: } else {
7402: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7403: }
1.72 raeburn 7404: } else {
1.104 raeburn 7405: if ($type eq '_LC_adv') {
1.163 raeburn 7406: if ($inconf{$type} eq '0') {
1.104 raeburn 7407: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7408: } else {
7409: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7410: }
7411: } else {
7412: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7413: }
1.72 raeburn 7414: }
7415: }
1.26 raeburn 7416: }
1.163 raeburn 7417: unless ($context eq 'requestauthor') {
7418: $resulttext .= '</ul></li>';
7419: }
1.26 raeburn 7420: }
1.1 raeburn 7421: }
1.163 raeburn 7422: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7423: if (ref($changes{'notify'}) eq 'HASH') {
7424: if ($changes{'notify'}{'approval'}) {
7425: if (ref($confhash{'notify'}) eq 'HASH') {
7426: if ($confhash{'notify'}{'approval'}) {
7427: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7428: } else {
1.163 raeburn 7429: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7430: }
7431: }
7432: }
7433: }
7434: }
1.216 raeburn 7435: if ($action eq 'requestcourses') {
7436: my @offon = ('off','on');
7437: if ($changes{'uniquecode'}) {
1.218 raeburn 7438: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7439: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7440: $resulttext .= '<li>'.
7441: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7442: '</li>';
7443: } else {
7444: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7445: '</li>';
7446: }
1.216 raeburn 7447: }
1.242 raeburn 7448: foreach my $type ('textbooks','templates') {
7449: if (ref($changes{$type}) eq 'HASH') {
7450: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7451: foreach my $key (sort(keys(%{$changes{$type}}))) {
7452: my %coursehash = &Apache::lonnet::coursedescription($key);
7453: my $coursetitle = $coursehash{'description'};
7454: my $position = $confhash{$type}{$key}{'order'} + 1;
7455: $resulttext .= '<li>';
1.243 raeburn 7456: foreach my $item ('subject','title','publisher','author') {
7457: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7458: ($type eq 'templates'));
1.242 raeburn 7459: my $name = $item.':';
7460: $name =~ s/^(\w)/\U$1/;
7461: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7462: }
7463: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7464: if ($type eq 'textbooks') {
7465: if ($confhash{$type}{$key}{'image'}) {
7466: $resulttext .= ' '.&mt('Image: [_1]',
7467: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7468: ' alt="Textbook cover" />').'<br />';
7469: }
7470: }
7471: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 7472: }
1.242 raeburn 7473: $resulttext .= '</ul></li>';
1.216 raeburn 7474: }
7475: }
1.235 raeburn 7476: if (ref($changes{'validation'}) eq 'HASH') {
7477: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7478: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7479: foreach my $item (@{$validationitemsref}) {
7480: if (exists($changes{'validation'}{$item})) {
7481: if ($item eq 'markup') {
7482: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7483: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7484: } else {
7485: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7486: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7487: }
7488: }
7489: }
7490: if (exists($changes{'validation'}{'dc'})) {
7491: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7492: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7493: }
7494: }
7495: }
1.216 raeburn 7496: }
1.1 raeburn 7497: $resulttext .= '</ul>';
1.80 raeburn 7498: if (keys(%newenv)) {
7499: &Apache::lonnet::appenv(\%newenv);
7500: }
1.1 raeburn 7501: } else {
1.86 raeburn 7502: if ($context eq 'requestcourses') {
7503: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7504: } elsif ($context eq 'requestauthor') {
7505: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7506: } else {
1.90 weissno 7507: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7508: }
1.1 raeburn 7509: }
7510: } else {
1.11 albertel 7511: $resulttext = '<span class="LC_error">'.
7512: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7513: }
1.216 raeburn 7514: if ($errors) {
7515: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7516: '<ul>'.$errors.'</ul></p>';
7517: }
1.3 raeburn 7518: return $resulttext;
1.1 raeburn 7519: }
7520:
1.216 raeburn 7521: sub process_textbook_image {
1.242 raeburn 7522: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 7523: my $filename = $env{'form.'.$caller.'.filename'};
7524: my ($error,$url);
7525: my ($width,$height) = (50,50);
7526: if ($configuserok eq 'ok') {
7527: if ($switchserver) {
7528: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7529: $switchserver);
7530: } elsif ($author_ok eq 'ok') {
7531: my ($result,$imageurl) =
7532: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 7533: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 7534: if ($result eq 'ok') {
7535: $url = $imageurl;
7536: } else {
7537: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7538: }
7539: } else {
7540: $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);
7541: }
7542: } else {
7543: $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);
7544: }
7545: return ($url,$error);
7546: }
7547:
1.3 raeburn 7548: sub modify_autoenroll {
1.205 raeburn 7549: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7550: my ($resulttext,%changes);
7551: my %currautoenroll;
7552: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7553: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7554: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7555: }
7556: }
7557: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7558: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7559: sender => 'Sender for notification messages',
7560: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7561: my @offon = ('off','on');
1.17 raeburn 7562: my $sender_uname = $env{'form.sender_uname'};
7563: my $sender_domain = $env{'form.sender_domain'};
7564: if ($sender_domain eq '') {
7565: $sender_uname = '';
7566: } elsif ($sender_uname eq '') {
7567: $sender_domain = '';
7568: }
1.129 raeburn 7569: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7570: my %autoenrollhash = (
1.129 raeburn 7571: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7572: 'sender_uname' => $sender_uname,
7573: 'sender_domain' => $sender_domain,
7574: 'co-owners' => $coowners,
1.1 raeburn 7575: }
7576: );
1.4 raeburn 7577: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7578: $dom);
1.1 raeburn 7579: if ($putresult eq 'ok') {
7580: if (exists($currautoenroll{'run'})) {
7581: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7582: $changes{'run'} = 1;
7583: }
7584: } elsif ($autorun) {
7585: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7586: $changes{'run'} = 1;
1.1 raeburn 7587: }
7588: }
1.17 raeburn 7589: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7590: $changes{'sender'} = 1;
7591: }
1.17 raeburn 7592: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7593: $changes{'sender'} = 1;
7594: }
1.129 raeburn 7595: if ($currautoenroll{'co-owners'} ne '') {
7596: if ($currautoenroll{'co-owners'} ne $coowners) {
7597: $changes{'coowners'} = 1;
7598: }
7599: } elsif ($coowners) {
7600: $changes{'coowners'} = 1;
7601: }
1.1 raeburn 7602: if (keys(%changes) > 0) {
7603: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7604: if ($changes{'run'}) {
1.1 raeburn 7605: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7606: }
7607: if ($changes{'sender'}) {
1.17 raeburn 7608: if ($sender_uname eq '' || $sender_domain eq '') {
7609: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7610: } else {
7611: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7612: }
1.1 raeburn 7613: }
1.129 raeburn 7614: if ($changes{'coowners'}) {
7615: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7616: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7617: if (ref($lastactref) eq 'HASH') {
7618: $lastactref->{'domainconfig'} = 1;
7619: }
1.129 raeburn 7620: }
1.1 raeburn 7621: $resulttext .= '</ul>';
7622: } else {
7623: $resulttext = &mt('No changes made to auto-enrollment settings');
7624: }
7625: } else {
1.11 albertel 7626: $resulttext = '<span class="LC_error">'.
7627: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7628: }
1.3 raeburn 7629: return $resulttext;
1.1 raeburn 7630: }
7631:
7632: sub modify_autoupdate {
1.3 raeburn 7633: my ($dom,%domconfig) = @_;
1.1 raeburn 7634: my ($resulttext,%currautoupdate,%fields,%changes);
7635: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7636: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7637: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7638: }
7639: }
7640: my @offon = ('off','on');
7641: my %title = &Apache::lonlocal::texthash (
7642: run => 'Auto-update:',
7643: classlists => 'Updates to user information in classlists?'
7644: );
1.44 raeburn 7645: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7646: my %fieldtitles = &Apache::lonlocal::texthash (
7647: id => 'Student/Employee ID',
1.20 raeburn 7648: permanentemail => 'E-mail address',
1.1 raeburn 7649: lastname => 'Last Name',
7650: firstname => 'First Name',
7651: middlename => 'Middle Name',
1.132 raeburn 7652: generation => 'Generation',
1.1 raeburn 7653: );
1.142 raeburn 7654: $othertitle = &mt('All users');
1.1 raeburn 7655: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7656: $othertitle = &mt('Other users');
1.1 raeburn 7657: }
7658: foreach my $key (keys(%env)) {
7659: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7660: my ($usertype,$item) = ($1,$2);
7661: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7662: if ($usertype eq 'default') {
7663: push(@{$fields{$1}},$2);
7664: } elsif (ref($types) eq 'ARRAY') {
7665: if (grep(/^\Q$usertype\E$/,@{$types})) {
7666: push(@{$fields{$1}},$2);
7667: }
7668: }
7669: }
1.1 raeburn 7670: }
7671: }
1.131 raeburn 7672: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7673: @lockablenames = sort(@lockablenames);
7674: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7675: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7676: if (@changed) {
7677: $changes{'lockablenames'} = 1;
7678: }
7679: } else {
7680: if (@lockablenames) {
7681: $changes{'lockablenames'} = 1;
7682: }
7683: }
1.1 raeburn 7684: my %updatehash = (
7685: autoupdate => { run => $env{'form.autoupdate_run'},
7686: classlists => $env{'form.classlists'},
7687: fields => {%fields},
1.131 raeburn 7688: lockablenames => \@lockablenames,
1.1 raeburn 7689: }
7690: );
7691: foreach my $key (keys(%currautoupdate)) {
7692: if (($key eq 'run') || ($key eq 'classlists')) {
7693: if (exists($updatehash{autoupdate}{$key})) {
7694: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7695: $changes{$key} = 1;
7696: }
7697: }
7698: } elsif ($key eq 'fields') {
7699: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7700: foreach my $item (@{$types},'default') {
1.1 raeburn 7701: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7702: my $change = 0;
7703: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7704: if (!exists($fields{$item})) {
7705: $change = 1;
1.132 raeburn 7706: last;
1.1 raeburn 7707: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7708: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7709: $change = 1;
1.132 raeburn 7710: last;
1.1 raeburn 7711: }
7712: }
7713: }
7714: if ($change) {
7715: push(@{$changes{$key}},$item);
7716: }
1.26 raeburn 7717: }
1.1 raeburn 7718: }
7719: }
1.131 raeburn 7720: } elsif ($key eq 'lockablenames') {
7721: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7722: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7723: if (@changed) {
7724: $changes{'lockablenames'} = 1;
7725: }
7726: } else {
7727: if (@lockablenames) {
7728: $changes{'lockablenames'} = 1;
7729: }
7730: }
7731: }
7732: }
7733: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7734: if (@lockablenames) {
7735: $changes{'lockablenames'} = 1;
1.1 raeburn 7736: }
7737: }
1.26 raeburn 7738: foreach my $item (@{$types},'default') {
7739: if (defined($fields{$item})) {
7740: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7741: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7742: my $change = 0;
7743: if (ref($fields{$item}) eq 'ARRAY') {
7744: foreach my $type (@{$fields{$item}}) {
7745: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7746: $change = 1;
7747: last;
7748: }
7749: }
7750: }
7751: if ($change) {
7752: push(@{$changes{'fields'}},$item);
7753: }
7754: } else {
1.26 raeburn 7755: push(@{$changes{'fields'}},$item);
7756: }
7757: } else {
7758: push(@{$changes{'fields'}},$item);
1.1 raeburn 7759: }
7760: }
7761: }
7762: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7763: $dom);
7764: if ($putresult eq 'ok') {
7765: if (keys(%changes) > 0) {
7766: $resulttext = &mt('Changes made:').'<ul>';
7767: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7768: if ($key eq 'lockablenames') {
7769: $resulttext .= '<li>';
7770: if (@lockablenames) {
7771: $usertypes->{'default'} = $othertitle;
7772: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7773: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7774: } else {
7775: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7776: }
7777: $resulttext .= '</li>';
7778: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7779: foreach my $item (@{$changes{$key}}) {
7780: my @newvalues;
7781: foreach my $type (@{$fields{$item}}) {
7782: push(@newvalues,$fieldtitles{$type});
7783: }
1.3 raeburn 7784: my $newvaluestr;
7785: if (@newvalues > 0) {
7786: $newvaluestr = join(', ',@newvalues);
7787: } else {
7788: $newvaluestr = &mt('none');
1.6 raeburn 7789: }
1.1 raeburn 7790: if ($item eq 'default') {
1.26 raeburn 7791: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7792: } else {
1.26 raeburn 7793: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7794: }
7795: }
7796: } else {
7797: my $newvalue;
7798: if ($key eq 'run') {
7799: $newvalue = $offon[$env{'form.autoupdate_run'}];
7800: } else {
7801: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7802: }
1.1 raeburn 7803: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7804: }
7805: }
7806: $resulttext .= '</ul>';
7807: } else {
1.3 raeburn 7808: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7809: }
7810: } else {
1.11 albertel 7811: $resulttext = '<span class="LC_error">'.
7812: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7813: }
1.3 raeburn 7814: return $resulttext;
1.1 raeburn 7815: }
7816:
1.125 raeburn 7817: sub modify_autocreate {
7818: my ($dom,%domconfig) = @_;
7819: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7820: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7821: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7822: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7823: }
7824: }
7825: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7826: req => 'Auto-creation of validated requests for official courses',
7827: xmldc => 'Identity of course creator of courses from XML files',
7828: );
7829: my @types = ('xml','req');
7830: foreach my $item (@types) {
7831: $newvals{$item} = $env{'form.autocreate_'.$item};
7832: $newvals{$item} =~ s/\D//g;
7833: $newvals{$item} = 0 if ($newvals{$item} eq '');
7834: }
7835: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7836: my %domcoords = &get_active_dcs($dom);
7837: unless (exists($domcoords{$newvals{'xmldc'}})) {
7838: $newvals{'xmldc'} = '';
7839: }
7840: %autocreatehash = (
7841: autocreate => { xml => $newvals{'xml'},
7842: req => $newvals{'req'},
7843: }
7844: );
7845: if ($newvals{'xmldc'} ne '') {
7846: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7847: }
7848: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7849: $dom);
7850: if ($putresult eq 'ok') {
7851: my @items = @types;
7852: if ($newvals{'xml'}) {
7853: push(@items,'xmldc');
7854: }
7855: foreach my $item (@items) {
7856: if (exists($currautocreate{$item})) {
7857: if ($currautocreate{$item} ne $newvals{$item}) {
7858: $changes{$item} = 1;
7859: }
7860: } elsif ($newvals{$item}) {
7861: $changes{$item} = 1;
7862: }
7863: }
7864: if (keys(%changes) > 0) {
7865: my @offon = ('off','on');
7866: $resulttext = &mt('Changes made:').'<ul>';
7867: foreach my $item (@types) {
7868: if ($changes{$item}) {
7869: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7870: $resulttext .= '<li>'.
7871: &mt("$title{$item} set to [_1]$newtxt [_2]",
7872: '<b>','</b>').
7873: '</li>';
1.125 raeburn 7874: }
7875: }
7876: if ($changes{'xmldc'}) {
7877: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7878: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7879: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7880: }
7881: $resulttext .= '</ul>';
7882: } else {
7883: $resulttext = &mt('No changes made to auto-creation settings');
7884: }
7885: } else {
7886: $resulttext = '<span class="LC_error">'.
7887: &mt('An error occurred: [_1]',$putresult).'</span>';
7888: }
7889: return $resulttext;
7890: }
7891:
1.23 raeburn 7892: sub modify_directorysrch {
7893: my ($dom,%domconfig) = @_;
7894: my ($resulttext,%changes);
7895: my %currdirsrch;
7896: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7897: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7898: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7899: }
7900: }
7901: my %title = ( available => 'Directory search available',
1.24 raeburn 7902: localonly => 'Other domains can search',
1.23 raeburn 7903: searchby => 'Search types',
7904: searchtypes => 'Search latitude');
7905: my @offon = ('off','on');
1.24 raeburn 7906: my @otherdoms = ('Yes','No');
1.23 raeburn 7907:
1.25 raeburn 7908: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7909: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7910: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7911:
1.44 raeburn 7912: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7913: if (keys(%{$usertypes}) == 0) {
7914: @cansearch = ('default');
7915: } else {
7916: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7917: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7918: if (!grep(/^\Q$type\E$/,@cansearch)) {
7919: push(@{$changes{'cansearch'}},$type);
7920: }
1.23 raeburn 7921: }
1.26 raeburn 7922: foreach my $type (@cansearch) {
7923: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7924: push(@{$changes{'cansearch'}},$type);
7925: }
1.23 raeburn 7926: }
1.26 raeburn 7927: } else {
7928: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7929: }
7930: }
7931:
7932: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7933: foreach my $by (@{$currdirsrch{'searchby'}}) {
7934: if (!grep(/^\Q$by\E$/,@searchby)) {
7935: push(@{$changes{'searchby'}},$by);
7936: }
7937: }
7938: foreach my $by (@searchby) {
7939: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7940: push(@{$changes{'searchby'}},$by);
7941: }
7942: }
7943: } else {
7944: push(@{$changes{'searchby'}},@searchby);
7945: }
1.25 raeburn 7946:
7947: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7948: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7949: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7950: push(@{$changes{'searchtypes'}},$type);
7951: }
7952: }
7953: foreach my $type (@searchtypes) {
7954: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7955: push(@{$changes{'searchtypes'}},$type);
7956: }
7957: }
7958: } else {
7959: if (exists($currdirsrch{'searchtypes'})) {
7960: foreach my $type (@searchtypes) {
7961: if ($type ne $currdirsrch{'searchtypes'}) {
7962: push(@{$changes{'searchtypes'}},$type);
7963: }
7964: }
7965: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7966: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7967: }
7968: } else {
7969: push(@{$changes{'searchtypes'}},@searchtypes);
7970: }
7971: }
7972:
1.23 raeburn 7973: my %dirsrch_hash = (
7974: directorysrch => { available => $env{'form.dirsrch_available'},
7975: cansearch => \@cansearch,
1.24 raeburn 7976: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7977: searchby => \@searchby,
1.25 raeburn 7978: searchtypes => \@searchtypes,
1.23 raeburn 7979: }
7980: );
7981: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7982: $dom);
7983: if ($putresult eq 'ok') {
7984: if (exists($currdirsrch{'available'})) {
7985: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7986: $changes{'available'} = 1;
7987: }
7988: } else {
7989: if ($env{'form.dirsrch_available'} eq '1') {
7990: $changes{'available'} = 1;
7991: }
7992: }
1.24 raeburn 7993: if (exists($currdirsrch{'localonly'})) {
7994: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7995: $changes{'localonly'} = 1;
7996: }
7997: } else {
7998: if ($env{'form.dirsrch_localonly'} eq '1') {
7999: $changes{'localonly'} = 1;
8000: }
8001: }
1.23 raeburn 8002: if (keys(%changes) > 0) {
8003: $resulttext = &mt('Changes made:').'<ul>';
8004: if ($changes{'available'}) {
8005: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8006: }
1.24 raeburn 8007: if ($changes{'localonly'}) {
8008: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8009: }
8010:
1.23 raeburn 8011: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8012: my $chgtext;
1.26 raeburn 8013: if (ref($usertypes) eq 'HASH') {
8014: if (keys(%{$usertypes}) > 0) {
8015: foreach my $type (@{$types}) {
8016: if (grep(/^\Q$type\E$/,@cansearch)) {
8017: $chgtext .= $usertypes->{$type}.'; ';
8018: }
8019: }
8020: if (grep(/^default$/,@cansearch)) {
8021: $chgtext .= $othertitle;
8022: } else {
8023: $chgtext =~ s/\; $//;
8024: }
1.210 raeburn 8025: $resulttext .=
1.178 raeburn 8026: '<li>'.
8027: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8028: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8029: '</li>';
1.23 raeburn 8030: }
8031: }
8032: }
8033: if (ref($changes{'searchby'}) eq 'ARRAY') {
8034: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8035: my $chgtext;
8036: foreach my $type (@{$titleorder}) {
8037: if (grep(/^\Q$type\E$/,@searchby)) {
8038: if (defined($searchtitles->{$type})) {
8039: $chgtext .= $searchtitles->{$type}.'; ';
8040: }
8041: }
8042: }
8043: $chgtext =~ s/\; $//;
8044: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8045: }
1.25 raeburn 8046: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8047: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8048: my $chgtext;
8049: foreach my $type (@{$srchtypeorder}) {
8050: if (grep(/^\Q$type\E$/,@searchtypes)) {
8051: if (defined($srchtypes_desc->{$type})) {
8052: $chgtext .= $srchtypes_desc->{$type}.'; ';
8053: }
8054: }
8055: }
8056: $chgtext =~ s/\; $//;
1.178 raeburn 8057: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8058: }
8059: $resulttext .= '</ul>';
8060: } else {
8061: $resulttext = &mt('No changes made to institution directory search settings');
8062: }
8063: } else {
8064: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8065: &mt('An error occurred: [_1]',$putresult).'</span>';
8066: }
8067: return $resulttext;
8068: }
8069:
1.28 raeburn 8070: sub modify_contacts {
1.205 raeburn 8071: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8072: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8073: if (ref($domconfig{'contacts'}) eq 'HASH') {
8074: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8075: $currsetting{$key} = $domconfig{'contacts'}{$key};
8076: }
8077: }
1.134 raeburn 8078: my (%others,%to,%bcc);
1.28 raeburn 8079: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8080: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 8081: 'requestsmail','updatesmail','idconflictsmail');
8082: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8083: foreach my $type (@mailings) {
8084: @{$newsetting{$type}} =
8085: &Apache::loncommon::get_env_multiple('form.'.$type);
8086: foreach my $item (@contacts) {
8087: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8088: $contacts_hash{contacts}{$type}{$item} = 1;
8089: } else {
8090: $contacts_hash{contacts}{$type}{$item} = 0;
8091: }
8092: }
8093: $others{$type} = $env{'form.'.$type.'_others'};
8094: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8095: if ($type eq 'helpdeskmail') {
8096: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8097: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8098: }
1.28 raeburn 8099: }
8100: foreach my $item (@contacts) {
8101: $to{$item} = $env{'form.'.$item};
8102: $contacts_hash{'contacts'}{$item} = $to{$item};
8103: }
1.203 raeburn 8104: foreach my $item (@toggles) {
8105: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8106: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8107: }
8108: }
1.28 raeburn 8109: if (keys(%currsetting) > 0) {
8110: foreach my $item (@contacts) {
8111: if ($to{$item} ne $currsetting{$item}) {
8112: $changes{$item} = 1;
8113: }
8114: }
8115: foreach my $type (@mailings) {
8116: foreach my $item (@contacts) {
8117: if (ref($currsetting{$type}) eq 'HASH') {
8118: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8119: push(@{$changes{$type}},$item);
8120: }
8121: } else {
8122: push(@{$changes{$type}},@{$newsetting{$type}});
8123: }
8124: }
8125: if ($others{$type} ne $currsetting{$type}{'others'}) {
8126: push(@{$changes{$type}},'others');
8127: }
1.134 raeburn 8128: if ($type eq 'helpdeskmail') {
8129: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8130: push(@{$changes{$type}},'bcc');
8131: }
8132: }
1.28 raeburn 8133: }
8134: } else {
8135: my %default;
8136: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8137: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8138: $default{'errormail'} = 'adminemail';
8139: $default{'packagesmail'} = 'adminemail';
8140: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8141: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8142: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8143: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8144: foreach my $item (@contacts) {
8145: if ($to{$item} ne $default{$item}) {
8146: $changes{$item} = 1;
1.203 raeburn 8147: }
1.28 raeburn 8148: }
8149: foreach my $type (@mailings) {
8150: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8151:
8152: push(@{$changes{$type}},@{$newsetting{$type}});
8153: }
8154: if ($others{$type} ne '') {
8155: push(@{$changes{$type}},'others');
1.134 raeburn 8156: }
8157: if ($type eq 'helpdeskmail') {
8158: if ($bcc{$type} ne '') {
8159: push(@{$changes{$type}},'bcc');
8160: }
8161: }
1.28 raeburn 8162: }
8163: }
1.203 raeburn 8164: foreach my $item (@toggles) {
8165: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8166: $changes{$item} = 1;
8167: } elsif ((!$env{'form.'.$item}) &&
8168: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8169: $changes{$item} = 1;
8170: }
8171: }
1.28 raeburn 8172: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8173: $dom);
8174: if ($putresult eq 'ok') {
8175: if (keys(%changes) > 0) {
1.205 raeburn 8176: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8177: if (ref($lastactref) eq 'HASH') {
8178: $lastactref->{'domainconfig'} = 1;
8179: }
1.28 raeburn 8180: my ($titles,$short_titles) = &contact_titles();
8181: $resulttext = &mt('Changes made:').'<ul>';
8182: foreach my $item (@contacts) {
8183: if ($changes{$item}) {
8184: $resulttext .= '<li>'.$titles->{$item}.
8185: &mt(' set to: ').
8186: '<span class="LC_cusr_emph">'.
8187: $to{$item}.'</span></li>';
8188: }
8189: }
8190: foreach my $type (@mailings) {
8191: if (ref($changes{$type}) eq 'ARRAY') {
8192: $resulttext .= '<li>'.$titles->{$type}.': ';
8193: my @text;
8194: foreach my $item (@{$newsetting{$type}}) {
8195: push(@text,$short_titles->{$item});
8196: }
8197: if ($others{$type} ne '') {
8198: push(@text,$others{$type});
8199: }
8200: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8201: join(', ',@text).'</span>';
8202: if ($type eq 'helpdeskmail') {
8203: if ($bcc{$type} ne '') {
8204: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8205: }
8206: }
8207: $resulttext .= '</li>';
1.28 raeburn 8208: }
8209: }
1.203 raeburn 8210: my @offon = ('off','on');
8211: if ($changes{'reporterrors'}) {
8212: $resulttext .= '<li>'.
8213: &mt('E-mail error reports to [_1] set to "'.
8214: $offon[$env{'form.reporterrors'}].'".',
8215: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8216: &mt('LON-CAPA core group - MSU'),600,500)).
8217: '</li>';
8218: }
8219: if ($changes{'reportupdates'}) {
8220: $resulttext .= '<li>'.
8221: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8222: $offon[$env{'form.reportupdates'}].'".',
8223: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8224: &mt('LON-CAPA core group - MSU'),600,500)).
8225: '</li>';
8226: }
1.28 raeburn 8227: $resulttext .= '</ul>';
8228: } else {
1.34 raeburn 8229: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8230: }
8231: } else {
8232: $resulttext = '<span class="LC_error">'.
8233: &mt('An error occurred: [_1].',$putresult).'</span>';
8234: }
8235: return $resulttext;
8236: }
8237:
8238: sub modify_usercreation {
1.27 raeburn 8239: my ($dom,%domconfig) = @_;
1.224 raeburn 8240: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8241: my $warningmsg;
1.27 raeburn 8242: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8243: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8244: if ($key eq 'cancreate') {
8245: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8246: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8247: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8248: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8249: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8250: } else {
8251: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8252: }
8253: }
8254: }
8255: } elsif ($key eq 'email_rule') {
8256: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8257: } else {
8258: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8259: }
1.27 raeburn 8260: }
8261: }
8262: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8263: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8264: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8265: foreach my $item(@contexts) {
1.224 raeburn 8266: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8267: }
1.34 raeburn 8268: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8269: foreach my $item (@contexts) {
1.224 raeburn 8270: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8271: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8272: }
1.27 raeburn 8273: }
1.34 raeburn 8274: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8275: foreach my $item (@contexts) {
1.43 raeburn 8276: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8277: if ($cancreate{$item} ne 'any') {
8278: push(@{$changes{'cancreate'}},$item);
8279: }
8280: } else {
8281: if ($cancreate{$item} ne 'none') {
8282: push(@{$changes{'cancreate'}},$item);
8283: }
1.27 raeburn 8284: }
8285: }
8286: } else {
1.43 raeburn 8287: foreach my $item (@contexts) {
1.34 raeburn 8288: push(@{$changes{'cancreate'}},$item);
8289: }
1.27 raeburn 8290: }
1.34 raeburn 8291:
1.27 raeburn 8292: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8293: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8294: if (!grep(/^\Q$type\E$/,@username_rule)) {
8295: push(@{$changes{'username_rule'}},$type);
8296: }
8297: }
8298: foreach my $type (@username_rule) {
8299: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8300: push(@{$changes{'username_rule'}},$type);
8301: }
8302: }
8303: } else {
8304: push(@{$changes{'username_rule'}},@username_rule);
8305: }
8306:
1.32 raeburn 8307: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8308: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8309: if (!grep(/^\Q$type\E$/,@id_rule)) {
8310: push(@{$changes{'id_rule'}},$type);
8311: }
8312: }
8313: foreach my $type (@id_rule) {
8314: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8315: push(@{$changes{'id_rule'}},$type);
8316: }
8317: }
8318: } else {
8319: push(@{$changes{'id_rule'}},@id_rule);
8320: }
8321:
1.43 raeburn 8322: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8323: my @authtypes = ('int','krb4','krb5','loc');
8324: my %authhash;
1.43 raeburn 8325: foreach my $item (@authen_contexts) {
1.28 raeburn 8326: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8327: foreach my $auth (@authtypes) {
8328: if (grep(/^\Q$auth\E$/,@authallowed)) {
8329: $authhash{$item}{$auth} = 1;
8330: } else {
8331: $authhash{$item}{$auth} = 0;
8332: }
8333: }
8334: }
8335: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8336: foreach my $item (@authen_contexts) {
1.28 raeburn 8337: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8338: foreach my $auth (@authtypes) {
8339: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8340: push(@{$changes{'authtypes'}},$item);
8341: last;
8342: }
8343: }
8344: }
8345: }
8346: } else {
1.43 raeburn 8347: foreach my $item (@authen_contexts) {
1.28 raeburn 8348: push(@{$changes{'authtypes'}},$item);
8349: }
8350: }
8351:
1.224 raeburn 8352: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8353: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8354: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8355: $save_usercreate{'id_rule'} = \@id_rule;
8356: $save_usercreate{'username_rule'} = \@username_rule,
8357: $save_usercreate{'authtypes'} = \%authhash;
8358:
1.27 raeburn 8359: my %usercreation_hash = (
1.224 raeburn 8360: usercreation => \%save_usercreate,
8361: );
1.27 raeburn 8362:
8363: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8364: $dom);
1.50 raeburn 8365:
1.224 raeburn 8366: if ($putresult eq 'ok') {
8367: if (keys(%changes) > 0) {
8368: $resulttext = &mt('Changes made:').'<ul>';
8369: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8370: my %lt = &usercreation_types();
8371: foreach my $type (@{$changes{'cancreate'}}) {
8372: my $chgtext = $lt{$type}.', ';
8373: if ($cancreate{$type} eq 'none') {
8374: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8375: } elsif ($cancreate{$type} eq 'any') {
8376: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8377: } elsif ($cancreate{$type} eq 'official') {
8378: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8379: } elsif ($cancreate{$type} eq 'unofficial') {
8380: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8381: }
8382: $resulttext .= '<li>'.$chgtext.'</li>';
8383: }
8384: }
8385: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8386: my ($rules,$ruleorder) =
8387: &Apache::lonnet::inst_userrules($dom,'username');
8388: my $chgtext = '<ul>';
8389: foreach my $type (@username_rule) {
8390: if (ref($rules->{$type}) eq 'HASH') {
8391: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8392: }
8393: }
8394: $chgtext .= '</ul>';
8395: if (@username_rule > 0) {
8396: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8397: } else {
8398: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8399: }
8400: }
8401: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8402: my ($idrules,$idruleorder) =
8403: &Apache::lonnet::inst_userrules($dom,'id');
8404: my $chgtext = '<ul>';
8405: foreach my $type (@id_rule) {
8406: if (ref($idrules->{$type}) eq 'HASH') {
8407: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8408: }
8409: }
8410: $chgtext .= '</ul>';
8411: if (@id_rule > 0) {
8412: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8413: } else {
8414: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8415: }
8416: }
8417: my %authname = &authtype_names();
8418: my %context_title = &context_names();
8419: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8420: my $chgtext = '<ul>';
8421: foreach my $type (@{$changes{'authtypes'}}) {
8422: my @allowed;
8423: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8424: foreach my $auth (@authtypes) {
8425: if ($authhash{$type}{$auth}) {
8426: push(@allowed,$authname{$auth});
8427: }
8428: }
8429: if (@allowed > 0) {
8430: $chgtext .= join(', ',@allowed).'</li>';
8431: } else {
8432: $chgtext .= &mt('none').'</li>';
8433: }
8434: }
8435: $chgtext .= '</ul>';
8436: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8437: $resulttext .= '</li>';
8438: }
8439: $resulttext .= '</ul>';
8440: } else {
8441: $resulttext = &mt('No changes made to user creation settings');
8442: }
8443: } else {
8444: $resulttext = '<span class="LC_error">'.
8445: &mt('An error occurred: [_1]',$putresult).'</span>';
8446: }
8447: if ($warningmsg ne '') {
8448: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8449: }
8450: return $resulttext;
8451: }
8452:
8453: sub modify_selfcreation {
8454: my ($dom,%domconfig) = @_;
8455: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8456: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8457: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8458: if (ref($types) eq 'ARRAY') {
8459: $usertypes->{'default'} = $othertitle;
8460: push(@{$types},'default');
8461: }
1.224 raeburn 8462: #
8463: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8464: #
8465: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8466: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8467: if ($key eq 'cancreate') {
8468: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8469: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8470: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8471: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8472: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 8473: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 8474: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8475: } else {
8476: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8477: }
8478: }
8479: }
8480: } elsif ($key eq 'email_rule') {
8481: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8482: } else {
8483: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8484: }
8485: }
8486: }
8487: #
8488: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8489: #
8490: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8491: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8492: if ($key eq 'selfcreate') {
8493: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8494: } else {
8495: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8496: }
8497: }
8498: }
8499:
8500: my @contexts = ('selfcreate');
8501: @{$cancreate{'selfcreate'}} = ();
8502: %{$cancreate{'emailusername'}} = ();
8503: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8504: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 8505: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8506: my %selfcreatetypes = (
8507: sso => 'users authenticated by institutional single sign on',
8508: login => 'users authenticated by institutional log-in',
1.236 raeburn 8509: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8510: );
1.224 raeburn 8511: #
8512: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8513: # is permitted.
8514: #
1.236 raeburn 8515:
8516: my @statuses;
8517: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8518: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8519: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8520: }
8521: }
8522: push(@statuses,'default');
8523:
1.228 raeburn 8524: foreach my $item ('login','sso','email') {
1.224 raeburn 8525: if ($item eq 'email') {
1.236 raeburn 8526: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8527: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8528: push(@contexts,'selfcreateprocessing');
8529: foreach my $type (@statuses) {
8530: if ($type eq 'default') {
8531: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8532: } else {
8533: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8534: }
8535: }
1.224 raeburn 8536: }
8537: } else {
8538: if ($env{'form.cancreate_'.$item}) {
8539: push(@{$cancreate{'selfcreate'}},$item);
8540: }
8541: }
8542: }
8543: my (@email_rule,%userinfo,%savecaptcha);
8544: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8545: #
1.228 raeburn 8546: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8547: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8548: #
1.236 raeburn 8549:
1.244 raeburn 8550: if ($env{'form.cancreate_email'}) {
1.228 raeburn 8551: push(@contexts,'emailusername');
8552: if (ref($types) eq 'ARRAY') {
8553: foreach my $type (@{$types}) {
8554: if (ref($infofields) eq 'ARRAY') {
8555: foreach my $field (@{$infofields}) {
8556: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8557: $cancreate{'emailusername'}{$type}{$field} = $1;
8558: }
8559: }
1.224 raeburn 8560: }
8561: }
8562: }
8563: #
8564: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8565: # queued requests for self-creation of account using e-mail address as username
8566: #
8567:
8568: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8569: @approvalnotify = sort(@approvalnotify);
8570: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8571: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8572: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8573: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8574: push(@{$changes{'cancreate'}},'notify');
8575: }
8576: } else {
8577: if ($cancreate{'notify'}{'approval'}) {
8578: push(@{$changes{'cancreate'}},'notify');
8579: }
8580: }
8581: } elsif ($cancreate{'notify'}{'approval'}) {
8582: push(@{$changes{'cancreate'}},'notify');
8583: }
8584:
8585: #
8586: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8587: #
8588: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8589: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8590: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8591: if (@{$curr_usercreation{'email_rule'}} > 0) {
8592: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8593: if (!grep(/^\Q$type\E$/,@email_rule)) {
8594: push(@{$changes{'email_rule'}},$type);
8595: }
8596: }
8597: }
8598: if (@email_rule > 0) {
8599: foreach my $type (@email_rule) {
8600: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8601: push(@{$changes{'email_rule'}},$type);
8602: }
8603: }
8604: }
8605: } elsif (@email_rule > 0) {
8606: push(@{$changes{'email_rule'}},@email_rule);
8607: }
8608: }
8609: #
1.236 raeburn 8610: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8611: # institutional log-in.
8612: #
8613: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8614: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8615: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8616: ($domdefaults{'auth_def'} eq 'localauth'))) {
8617: $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.').' '.
8618: &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.');
8619: }
8620: }
8621: my @fields = ('lastname','firstname','middlename','generation',
8622: 'permanentemail','id');
1.240 raeburn 8623: my @shibfields = (@fields,'inststatus');
1.224 raeburn 8624: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8625: #
8626: # Where usernames may created for institutional log-in and/or institutional single sign on:
8627: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8628: # may self-create accounts
8629: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8630: # which the user may supply, if institutional data is unavailable.
8631: #
8632: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8633: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8634: if (@{$types} > 1) {
1.224 raeburn 8635: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8636: push(@contexts,'statustocreate');
8637: } else {
8638: undef($cancreate{'statustocreate'});
8639: }
8640: foreach my $type (@{$types}) {
8641: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8642: foreach my $field (@fields) {
8643: if (grep(/^\Q$field\E$/,@modifiable)) {
8644: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8645: } else {
8646: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8647: }
8648: }
8649: }
8650: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8651: foreach my $type (@{$types}) {
8652: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8653: foreach my $field (@fields) {
8654: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8655: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8656: push(@{$changes{'selfcreate'}},$type);
8657: last;
8658: }
8659: }
8660: }
8661: }
8662: } else {
8663: foreach my $type (@{$types}) {
8664: push(@{$changes{'selfcreate'}},$type);
8665: }
8666: }
8667: }
1.240 raeburn 8668: foreach my $field (@shibfields) {
8669: if ($env{'form.shibenv_'.$field} ne '') {
8670: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8671: }
8672: }
8673: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8674: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8675: foreach my $field (@shibfields) {
8676: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8677: push(@{$changes{'cancreate'}},'shibenv');
8678: }
8679: }
8680: } else {
8681: foreach my $field (@shibfields) {
8682: if ($env{'form.shibenv_'.$field}) {
8683: push(@{$changes{'cancreate'}},'shibenv');
8684: last;
8685: }
8686: }
8687: }
8688: }
1.224 raeburn 8689: }
8690: foreach my $item (@contexts) {
8691: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8692: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8693: if (ref($cancreate{$item}) eq 'ARRAY') {
8694: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8695: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8696: push(@{$changes{'cancreate'}},$item);
8697: }
8698: }
8699: }
8700: }
8701: if (ref($cancreate{$item}) eq 'ARRAY') {
8702: foreach my $type (@{$cancreate{$item}}) {
8703: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8704: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8705: push(@{$changes{'cancreate'}},$item);
8706: }
8707: }
8708: }
8709: }
8710: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8711: if (ref($cancreate{$item}) eq 'HASH') {
8712: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8713: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8714: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8715: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8716: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8717: push(@{$changes{'cancreate'}},$item);
8718: }
8719: }
8720: }
1.236 raeburn 8721: } elsif ($item eq 'selfcreateprocessing') {
8722: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8724: push(@{$changes{'cancreate'}},$item);
8725: }
8726: }
1.228 raeburn 8727: } else {
8728: if (!$cancreate{$item}{$curr}) {
8729: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8730: push(@{$changes{'cancreate'}},$item);
8731: }
1.224 raeburn 8732: }
8733: }
8734: }
8735: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8736: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8737: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8738: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8739: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8740: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8741: push(@{$changes{'cancreate'}},$item);
8742: }
8743: }
8744: } else {
8745: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8746: push(@{$changes{'cancreate'}},$item);
8747: }
8748: }
8749: }
1.236 raeburn 8750: } elsif ($item eq 'selfcreateprocessing') {
8751: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8752: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8753: push(@{$changes{'cancreate'}},$item);
8754: }
8755: }
1.228 raeburn 8756: } else {
8757: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8758: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8759: push(@{$changes{'cancreate'}},$item);
8760: }
1.224 raeburn 8761: }
8762: }
8763: }
8764: }
8765: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8766: if (ref($cancreate{$item}) eq 'ARRAY') {
8767: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8768: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8769: push(@{$changes{'cancreate'}},$item);
8770: }
8771: }
8772: } elsif (ref($cancreate{$item}) eq 'HASH') {
8773: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8774: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8775: push(@{$changes{'cancreate'}},$item);
8776: }
8777: }
8778: }
8779: } elsif ($item eq 'emailusername') {
1.228 raeburn 8780: if (ref($cancreate{$item}) eq 'HASH') {
8781: foreach my $type (keys(%{$cancreate{$item}})) {
8782: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8783: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8784: if ($cancreate{$item}{$type}{$field}) {
8785: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8786: push(@{$changes{'cancreate'}},$item);
8787: }
8788: last;
8789: }
8790: }
8791: }
8792: }
1.224 raeburn 8793: }
8794: }
8795: }
8796: #
8797: # Populate %save_usercreate hash with updates to self-creation configuration.
8798: #
8799: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8800: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8801: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8802: if (ref($cancreate{'notify'}) eq 'HASH') {
8803: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8804: }
1.236 raeburn 8805: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8806: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8807: }
1.224 raeburn 8808: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8809: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8810: }
1.240 raeburn 8811: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8812: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8813: }
1.224 raeburn 8814: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8815: $save_usercreate{'emailrule'} = \@email_rule;
8816:
8817: my %userconfig_hash = (
8818: usercreation => \%save_usercreate,
8819: usermodification => \%save_usermodify,
8820: );
8821: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8822: $dom);
8823: #
8824: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8825: #
1.27 raeburn 8826: if ($putresult eq 'ok') {
8827: if (keys(%changes) > 0) {
8828: $resulttext = &mt('Changes made:').'<ul>';
8829: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8830: my %lt = &selfcreation_types();
1.34 raeburn 8831: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8832: my $chgtext;
1.45 raeburn 8833: if ($type eq 'selfcreate') {
1.50 raeburn 8834: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8835: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8836: } else {
1.224 raeburn 8837: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8838: '<ul>';
1.50 raeburn 8839: foreach my $case (@{$cancreate{$type}}) {
8840: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8841: }
8842: $chgtext .= '</ul>';
1.100 raeburn 8843: if (ref($cancreate{$type}) eq 'ARRAY') {
8844: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8845: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8846: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8847: $chgtext .= '<br />'.
8848: '<span class="LC_warning">'.
8849: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8850: '</span>';
1.100 raeburn 8851: }
8852: }
8853: }
8854: }
1.43 raeburn 8855: }
1.240 raeburn 8856: } elsif ($type eq 'shibenv') {
8857: if (keys(%{$cancreate{$type}}) == 0) {
8858: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8859: } else {
8860: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8861: '<ul>';
8862: foreach my $field (@shibfields) {
8863: next if ($cancreate{$type}{$field} eq '');
8864: if ($field eq 'inststatus') {
8865: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8866: } else {
8867: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8868: }
8869: }
8870: $chgtext .= '</ul>';
8871: }
1.93 raeburn 8872: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8873: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8874: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8875: if (@{$cancreate{'selfcreate'}} > 0) {
8876: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8877: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8878: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8879: $chgtext .= '<br />'.
8880: '<span class="LC_warning">'.
8881: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8882: '</span>';
8883: }
1.96 raeburn 8884: } elsif (ref($usertypes) eq 'HASH') {
8885: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8886: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8887: } else {
8888: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8889: }
8890: $chgtext .= '<ul>';
8891: foreach my $case (@{$cancreate{$type}}) {
8892: if ($case eq 'default') {
8893: $chgtext .= '<li>'.$othertitle.'</li>';
8894: } else {
8895: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8896: }
8897: }
1.100 raeburn 8898: $chgtext .= '</ul>';
8899: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8900: $chgtext .= '<br /><span class="LC_warning">'.
8901: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8902: '</span>';
1.100 raeburn 8903: }
8904: }
8905: } else {
8906: if (@{$cancreate{$type}} == 0) {
8907: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8908: } else {
8909: $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 8910: }
8911: }
8912: }
1.236 raeburn 8913: } elsif ($type eq 'selfcreateprocessing') {
8914: my %choices = &Apache::lonlocal::texthash (
8915: automatic => 'Automatic approval',
8916: approval => 'Queued for approval',
8917: );
8918: if (@statuses > 1) {
8919: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8920: '<ul>';
8921: foreach my $type (@statuses) {
8922: if ($type eq 'default') {
8923: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8924: } else {
8925: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8926: }
8927: }
8928: $chgtext .= '</ul>';
8929: } else {
8930: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8931: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8932: }
1.165 raeburn 8933: } elsif ($type eq 'captcha') {
1.224 raeburn 8934: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8935: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8936: } else {
8937: my %captchas = &captcha_phrases();
1.224 raeburn 8938: if ($captchas{$savecaptcha{$type}}) {
8939: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8940: } else {
1.210 raeburn 8941: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8942: }
8943: }
8944: } elsif ($type eq 'recaptchakeys') {
8945: my ($privkey,$pubkey);
1.224 raeburn 8946: if (ref($savecaptcha{$type}) eq 'HASH') {
8947: $pubkey = $savecaptcha{$type}{'public'};
8948: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8949: }
8950: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8951: if (!$pubkey) {
8952: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8953: } else {
8954: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8955: }
8956: if (!$privkey) {
8957: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8958: } else {
8959: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8960: }
8961: $chgtext .= '</ul>';
1.224 raeburn 8962: } elsif ($type eq 'emailusername') {
8963: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8964: if (ref($types) eq 'ARRAY') {
8965: foreach my $type (@{$types}) {
8966: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8967: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 8968: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 8969: '<ul>';
8970: foreach my $field (@{$infofields}) {
8971: if ($cancreate{'emailusername'}{$type}{$field}) {
8972: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8973: }
8974: }
1.245 raeburn 8975: $chgtext .= '</ul>';
8976: } else {
8977: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.228 raeburn 8978: }
8979: } else {
1.245 raeburn 8980: $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 8981: }
8982: }
8983: }
8984: }
8985: } elsif ($type eq 'notify') {
8986: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8987: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8988: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8989: if ($cancreate{'notify'}{'approval'}) {
8990: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8991: }
8992: }
1.43 raeburn 8993: }
1.34 raeburn 8994: }
1.224 raeburn 8995: if ($chgtext) {
8996: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8997: }
8998: }
8999: }
1.43 raeburn 9000: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9001: my ($emailrules,$emailruleorder) =
9002: &Apache::lonnet::inst_userrules($dom,'email');
9003: my $chgtext = '<ul>';
9004: foreach my $type (@email_rule) {
9005: if (ref($emailrules->{$type}) eq 'HASH') {
9006: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9007: }
9008: }
9009: $chgtext .= '</ul>';
9010: if (@email_rule > 0) {
1.224 raeburn 9011: $resulttext .= '<li>'.
9012: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9013: $chgtext.
9014: '</li>';
1.43 raeburn 9015: } else {
1.224 raeburn 9016: $resulttext .= '<li>'.
9017: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9018: '</li>';
1.43 raeburn 9019: }
9020: }
1.224 raeburn 9021: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9022: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9023: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9024: foreach my $type (@{$changes{'selfcreate'}}) {
9025: my $typename = $type;
9026: if (ref($usertypes) eq 'HASH') {
9027: if ($usertypes->{$type} ne '') {
9028: $typename = $usertypes->{$type};
9029: }
9030: }
9031: my @modifiable;
9032: $resulttext .= '<li>'.
9033: &mt('Self-creation of account by users with status: [_1]',
9034: '<span class="LC_cusr_emph">'.$typename.'</span>').
9035: ' - '.&mt('modifiable fields (if institutional data blank): ');
9036: foreach my $field (@fields) {
9037: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9038: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 9039: }
9040: }
1.224 raeburn 9041: if (@modifiable > 0) {
9042: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9043: } else {
1.224 raeburn 9044: $resulttext .= &mt('none');
1.43 raeburn 9045: }
1.224 raeburn 9046: $resulttext .= '</li>';
1.28 raeburn 9047: }
1.224 raeburn 9048: $resulttext .= '</ul></li>';
1.28 raeburn 9049: }
1.27 raeburn 9050: $resulttext .= '</ul>';
9051: } else {
1.224 raeburn 9052: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9053: }
9054: } else {
9055: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9056: &mt('An error occurred: [_1]',$putresult).'</span>';
9057: }
1.43 raeburn 9058: if ($warningmsg ne '') {
9059: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9060: }
1.23 raeburn 9061: return $resulttext;
9062: }
9063:
1.165 raeburn 9064: sub process_captcha {
9065: my ($container,$changes,$newsettings,$current) = @_;
9066: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9067: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9068: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9069: $newsettings->{'captcha'} = 'original';
9070: }
9071: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 9072: if ($container eq 'cancreate') {
1.169 raeburn 9073: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9074: push(@{$changes->{'cancreate'}},'captcha');
9075: } elsif (!defined($changes->{'cancreate'})) {
9076: $changes->{'cancreate'} = ['captcha'];
9077: }
9078: } else {
9079: $changes->{'captcha'} = 1;
1.165 raeburn 9080: }
9081: }
9082: my ($newpub,$newpriv,$currpub,$currpriv);
9083: if ($newsettings->{'captcha'} eq 'recaptcha') {
9084: $newpub = $env{'form.'.$container.'_recaptchapub'};
9085: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 9086: $newpub =~ s/[^\w\-]//g;
9087: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 9088: $newsettings->{'recaptchakeys'} = {
9089: public => $newpub,
9090: private => $newpriv,
9091: };
1.165 raeburn 9092: }
9093: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9094: $currpub = $current->{'recaptchakeys'}{'public'};
9095: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 9096: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9097: $newsettings->{'recaptchakeys'} = {
9098: public => '',
9099: private => '',
9100: }
9101: }
1.165 raeburn 9102: }
9103: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 9104: if ($container eq 'cancreate') {
9105: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9106: push(@{$changes->{'cancreate'}},'recaptchakeys');
9107: } elsif (!defined($changes->{'cancreate'})) {
9108: $changes->{'cancreate'} = ['recaptchakeys'];
9109: }
9110: } else {
1.210 raeburn 9111: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 9112: }
9113: }
9114: return;
9115: }
9116:
1.33 raeburn 9117: sub modify_usermodification {
9118: my ($dom,%domconfig) = @_;
1.224 raeburn 9119: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9120: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9121: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 9122: if ($key eq 'selfcreate') {
9123: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9124: } else {
9125: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9126: }
1.33 raeburn 9127: }
9128: }
1.224 raeburn 9129: my @contexts = ('author','course');
1.33 raeburn 9130: my %context_title = (
9131: author => 'In author context',
9132: course => 'In course context',
9133: );
9134: my @fields = ('lastname','firstname','middlename','generation',
9135: 'permanentemail','id');
9136: my %roles = (
9137: author => ['ca','aa'],
9138: course => ['st','ep','ta','in','cr'],
9139: );
9140: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9141: foreach my $context (@contexts) {
9142: foreach my $role (@{$roles{$context}}) {
9143: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9144: foreach my $item (@fields) {
9145: if (grep(/^\Q$item\E$/,@modifiable)) {
9146: $modifyhash{$context}{$role}{$item} = 1;
9147: } else {
9148: $modifyhash{$context}{$role}{$item} = 0;
9149: }
9150: }
9151: }
9152: if (ref($curr_usermodification{$context}) eq 'HASH') {
9153: foreach my $role (@{$roles{$context}}) {
9154: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9155: foreach my $field (@fields) {
9156: if ($modifyhash{$context}{$role}{$field} ne
9157: $curr_usermodification{$context}{$role}{$field}) {
9158: push(@{$changes{$context}},$role);
9159: last;
9160: }
9161: }
9162: }
9163: }
9164: } else {
9165: foreach my $context (@contexts) {
9166: foreach my $role (@{$roles{$context}}) {
9167: push(@{$changes{$context}},$role);
9168: }
9169: }
9170: }
9171: }
9172: my %usermodification_hash = (
9173: usermodification => \%modifyhash,
9174: );
9175: my $putresult = &Apache::lonnet::put_dom('configuration',
9176: \%usermodification_hash,$dom);
9177: if ($putresult eq 'ok') {
9178: if (keys(%changes) > 0) {
9179: $resulttext = &mt('Changes made: ').'<ul>';
9180: foreach my $context (@contexts) {
9181: if (ref($changes{$context}) eq 'ARRAY') {
9182: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9183: if (ref($changes{$context}) eq 'ARRAY') {
9184: foreach my $role (@{$changes{$context}}) {
9185: my $rolename;
1.224 raeburn 9186: if ($role eq 'cr') {
9187: $rolename = &mt('Custom');
1.33 raeburn 9188: } else {
1.224 raeburn 9189: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9190: }
9191: my @modifiable;
1.224 raeburn 9192: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9193: foreach my $field (@fields) {
9194: if ($modifyhash{$context}{$role}{$field}) {
9195: push(@modifiable,$fieldtitles{$field});
9196: }
9197: }
9198: if (@modifiable > 0) {
9199: $resulttext .= join(', ',@modifiable);
9200: } else {
9201: $resulttext .= &mt('none');
9202: }
9203: $resulttext .= '</li>';
9204: }
9205: $resulttext .= '</ul></li>';
9206: }
9207: }
9208: }
9209: $resulttext .= '</ul>';
9210: } else {
9211: $resulttext = &mt('No changes made to user modification settings');
9212: }
9213: } else {
9214: $resulttext = '<span class="LC_error">'.
9215: &mt('An error occurred: [_1]',$putresult).'</span>';
9216: }
9217: return $resulttext;
9218: }
9219:
1.43 raeburn 9220: sub modify_defaults {
1.212 raeburn 9221: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9222: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9223: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9224: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9225: my @authtypes = ('internal','krb4','krb5','localauth');
9226: foreach my $item (@items) {
9227: $newvalues{$item} = $env{'form.'.$item};
9228: if ($item eq 'auth_def') {
9229: if ($newvalues{$item} ne '') {
9230: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9231: push(@errors,$item);
9232: }
9233: }
9234: } elsif ($item eq 'lang_def') {
9235: if ($newvalues{$item} ne '') {
9236: if ($newvalues{$item} =~ /^(\w+)/) {
9237: my $langcode = $1;
1.103 raeburn 9238: if ($langcode ne 'x_chef') {
9239: if (code2language($langcode) eq '') {
9240: push(@errors,$item);
9241: }
1.43 raeburn 9242: }
9243: } else {
9244: push(@errors,$item);
9245: }
9246: }
1.54 raeburn 9247: } elsif ($item eq 'timezone_def') {
9248: if ($newvalues{$item} ne '') {
1.62 raeburn 9249: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9250: push(@errors,$item);
9251: }
9252: }
1.68 raeburn 9253: } elsif ($item eq 'datelocale_def') {
9254: if ($newvalues{$item} ne '') {
9255: my @datelocale_ids = DateTime::Locale->ids();
9256: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9257: push(@errors,$item);
9258: }
9259: }
1.141 raeburn 9260: } elsif ($item eq 'portal_def') {
9261: if ($newvalues{$item} ne '') {
9262: 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])\/?$/) {
9263: push(@errors,$item);
9264: }
9265: }
1.43 raeburn 9266: }
9267: if (grep(/^\Q$item\E$/,@errors)) {
9268: $newvalues{$item} = $domdefaults{$item};
9269: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9270: $changes{$item} = 1;
9271: }
1.72 raeburn 9272: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9273: }
9274: my %defaults_hash = (
1.72 raeburn 9275: defaults => \%newvalues,
9276: );
1.43 raeburn 9277: my $title = &defaults_titles();
1.236 raeburn 9278:
9279: my $currinststatus;
9280: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9281: $currinststatus = $domconfig{'inststatus'};
9282: } else {
9283: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9284: $currinststatus = {
9285: inststatustypes => $usertypes,
9286: inststatusorder => $types,
9287: inststatusguest => [],
9288: };
9289: }
9290: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9291: my @allpos;
9292: my %guests;
9293: my %alltypes;
9294: my ($currtitles,$currguests,$currorder);
9295: if (ref($currinststatus) eq 'HASH') {
9296: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9297: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9298: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9299: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9300: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9301: }
9302: }
9303: unless (grep(/^\Q$type\E$/,@todelete)) {
9304: my $position = $env{'form.inststatus_pos_'.$type};
9305: $position =~ s/\D+//g;
9306: $allpos[$position] = $type;
9307: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9308: $alltypes{$type} =~ s/`//g;
9309: if ($env{'form.inststatus_guest_'.$type}) {
9310: $guests{$type} = 1;
9311: }
9312: }
9313: }
9314: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9315: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9316: }
9317: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9318: $currtitles =~ s/,$//;
9319: }
9320: }
9321: if ($env{'form.addinststatus'}) {
9322: my $newtype = $env{'form.addinststatus'};
9323: $newtype =~ s/\W//g;
9324: unless (exists($alltypes{$newtype})) {
9325: if ($env{'form.addinststatus_guest'}) {
9326: $guests{$newtype} = 1;
9327: }
9328: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9329: $alltypes{$newtype} =~ s/`//g;
9330: my $position = $env{'form.addinststatus_pos'};
9331: $position =~ s/\D+//g;
9332: if ($position ne '') {
9333: $allpos[$position] = $newtype;
9334: }
9335: }
9336: }
9337: my (@orderedstatus,@orderedguests);
9338: foreach my $type (@allpos) {
9339: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9340: push(@orderedstatus,$type);
9341: if ($guests{$type}) {
9342: push(@orderedguests,$type);
9343: }
9344: }
9345: }
9346: foreach my $type (keys(%alltypes)) {
9347: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9348: delete($alltypes{$type});
9349: }
9350: }
9351: $defaults_hash{'inststatus'} = {
9352: inststatustypes => \%alltypes,
9353: inststatusorder => \@orderedstatus,
9354: inststatusguest => \@orderedguests,
9355: };
9356: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9357: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9358: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9359: }
9360: }
9361: if ($currorder ne join(',',@orderedstatus)) {
9362: $changes{'inststatus'}{'inststatusorder'} = 1;
9363: }
9364: if ($currguests ne join(',',@orderedguests)) {
9365: $changes{'inststatus'}{'inststatusguest'} = 1;
9366: }
9367: my $newtitles;
9368: foreach my $item (@orderedstatus) {
9369: $newtitles .= $alltypes{$item}.',';
9370: }
9371: $newtitles =~ s/,$//;
9372: if ($currtitles ne $newtitles) {
9373: $changes{'inststatus'}{'inststatustypes'} = 1;
9374: }
1.43 raeburn 9375: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9376: $dom);
9377: if ($putresult eq 'ok') {
9378: if (keys(%changes) > 0) {
9379: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9380: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9381: 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";
9382: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9383: if ($item eq 'inststatus') {
9384: if (ref($changes{'inststatus'}) eq 'HASH') {
9385: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9386: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9387: foreach my $type (@orderedstatus) {
9388: $resulttext .= $alltypes{$type}.', ';
9389: }
9390: $resulttext =~ s/, $//;
9391: $resulttext .= '</li>';
9392: }
9393: if ($changes{'inststatus'}{'inststatusguest'}) {
9394: $resulttext .= '<li>';
9395: if (@orderedguests) {
9396: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9397: foreach my $type (@orderedguests) {
9398: $resulttext .= $alltypes{$type}.', ';
9399: }
9400: $resulttext =~ s/, $//;
9401: } else {
9402: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9403: }
9404: $resulttext .= '</li>';
9405: }
9406: }
9407: } else {
9408: my $value = $env{'form.'.$item};
9409: if ($value eq '') {
9410: $value = &mt('none');
9411: } elsif ($item eq 'auth_def') {
9412: my %authnames = &authtype_names();
9413: my %shortauth = (
9414: internal => 'int',
9415: krb4 => 'krb4',
9416: krb5 => 'krb5',
9417: localauth => 'loc',
9418: );
9419: $value = $authnames{$shortauth{$value}};
9420: }
9421: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9422: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9423: }
9424: }
9425: $resulttext .= '</ul>';
9426: $mailmsgtext .= "\n";
9427: my $cachetime = 24*60*60;
1.72 raeburn 9428: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9429: if (ref($lastactref) eq 'HASH') {
9430: $lastactref->{'domdefaults'} = 1;
9431: }
1.68 raeburn 9432: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9433: my $notify = 1;
9434: if (ref($domconfig{'contacts'}) eq 'HASH') {
9435: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9436: $notify = 0;
9437: }
9438: }
9439: if ($notify) {
9440: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9441: "LON-CAPA Domain Settings Change - $dom",
9442: $mailmsgtext);
9443: }
1.54 raeburn 9444: }
1.43 raeburn 9445: } else {
1.54 raeburn 9446: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9447: }
9448: } else {
9449: $resulttext = '<span class="LC_error">'.
9450: &mt('An error occurred: [_1]',$putresult).'</span>';
9451: }
9452: if (@errors > 0) {
9453: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9454: foreach my $item (@errors) {
9455: $resulttext .= ' "'.$title->{$item}.'",';
9456: }
9457: $resulttext =~ s/,$//;
9458: }
9459: return $resulttext;
9460: }
9461:
1.46 raeburn 9462: sub modify_scantron {
1.205 raeburn 9463: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9464: my ($resulttext,%confhash,%changes,$errors);
9465: my $custom = 'custom.tab';
9466: my $default = 'default.tab';
9467: my $servadm = $r->dir_config('lonAdmEMail');
9468: my ($configuserok,$author_ok,$switchserver) =
9469: &config_check($dom,$confname,$servadm);
9470: if ($env{'form.scantronformat.filename'} ne '') {
9471: my $error;
9472: if ($configuserok eq 'ok') {
9473: if ($switchserver) {
1.130 raeburn 9474: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9475: } else {
9476: if ($author_ok eq 'ok') {
9477: my ($result,$scantronurl) =
9478: &publishlogo($r,'upload','scantronformat',$dom,
9479: $confname,'scantron','','',$custom);
9480: if ($result eq 'ok') {
9481: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9482: $changes{'scantronformat'} = 1;
1.46 raeburn 9483: } else {
9484: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9485: }
9486: } else {
9487: $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);
9488: }
9489: }
9490: } else {
9491: $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);
9492: }
9493: if ($error) {
9494: &Apache::lonnet::logthis($error);
9495: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9496: }
9497: }
1.48 raeburn 9498: if (ref($domconfig{'scantron'}) eq 'HASH') {
9499: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9500: if ($env{'form.scantronformat_del'}) {
9501: $confhash{'scantron'}{'scantronformat'} = '';
9502: $changes{'scantronformat'} = 1;
1.46 raeburn 9503: }
9504: }
9505: }
9506: if (keys(%confhash) > 0) {
9507: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9508: $dom);
9509: if ($putresult eq 'ok') {
9510: if (keys(%changes) > 0) {
1.48 raeburn 9511: if (ref($confhash{'scantron'}) eq 'HASH') {
9512: $resulttext = &mt('Changes made:').'<ul>';
9513: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9514: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9515: } else {
1.130 raeburn 9516: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9517: }
1.48 raeburn 9518: $resulttext .= '</ul>';
9519: } else {
1.130 raeburn 9520: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9521: }
9522: $resulttext .= '</ul>';
9523: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9524: if (ref($lastactref) eq 'HASH') {
9525: $lastactref->{'domainconfig'} = 1;
9526: }
1.46 raeburn 9527: } else {
1.130 raeburn 9528: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9529: }
9530: } else {
9531: $resulttext = '<span class="LC_error">'.
9532: &mt('An error occurred: [_1]',$putresult).'</span>';
9533: }
9534: } else {
1.130 raeburn 9535: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9536: }
9537: if ($errors) {
9538: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9539: $errors.'</ul>';
9540: }
9541: return $resulttext;
9542: }
9543:
1.48 raeburn 9544: sub modify_coursecategories {
1.239 raeburn 9545: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9546: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9547: $cathash);
1.48 raeburn 9548: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 9549: my @catitems = ('unauth','auth');
9550: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9551: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9552: $cathash = $domconfig{'coursecategories'}{'cats'};
9553: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9554: $changes{'togglecats'} = 1;
9555: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9556: }
9557: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9558: $changes{'categorize'} = 1;
9559: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9560: }
1.120 raeburn 9561: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9562: $changes{'togglecatscomm'} = 1;
9563: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9564: }
9565: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9566: $changes{'categorizecomm'} = 1;
9567: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9568: }
1.238 raeburn 9569: foreach my $item (@catitems) {
9570: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9571: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9572: $changes{$item} = 1;
9573: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9574: }
9575: }
9576: }
1.57 raeburn 9577: } else {
9578: $changes{'togglecats'} = 1;
9579: $changes{'categorize'} = 1;
1.124 raeburn 9580: $changes{'togglecatscomm'} = 1;
9581: $changes{'categorizecomm'} = 1;
1.87 raeburn 9582: $domconfig{'coursecategories'} = {
9583: togglecats => $env{'form.togglecats'},
9584: categorize => $env{'form.categorize'},
1.124 raeburn 9585: togglecatscomm => $env{'form.togglecatscomm'},
9586: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9587: };
1.238 raeburn 9588: foreach my $item (@catitems) {
9589: if ($env{'form.coursecat_'.$item} ne 'std') {
9590: $changes{$item} = 1;
9591: }
9592: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9593: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9594: }
9595: }
1.57 raeburn 9596: }
9597: if (ref($cathash) eq 'HASH') {
9598: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9599: push (@deletecategory,'instcode::0');
9600: }
1.120 raeburn 9601: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9602: push(@deletecategory,'communities::0');
9603: }
1.48 raeburn 9604: }
1.57 raeburn 9605: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9606: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9607: if (@deletecategory > 0) {
9608: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9609: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9610: foreach my $item (@deletecategory) {
1.57 raeburn 9611: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9612: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9613: $deletions{$item} = 1;
1.57 raeburn 9614: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9615: }
9616: }
9617: }
1.57 raeburn 9618: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9619: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9620: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9621: $reorderings{$item} = 1;
1.57 raeburn 9622: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9623: }
9624: if ($env{'form.addcategory_name_'.$item} ne '') {
9625: my $newcat = $env{'form.addcategory_name_'.$item};
9626: my $newdepth = $depth+1;
9627: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9628: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9629: $adds{$newitem} = 1;
9630: }
9631: if ($env{'form.subcat_'.$item} ne '') {
9632: my $newcat = $env{'form.subcat_'.$item};
9633: my $newdepth = $depth+1;
9634: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9635: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9636: $adds{$newitem} = 1;
9637: }
9638: }
9639: }
9640: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9641: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9642: my $newitem = 'instcode::0';
1.57 raeburn 9643: if ($cathash->{$newitem} eq '') {
9644: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9645: $adds{$newitem} = 1;
9646: }
9647: } else {
9648: my $newitem = 'instcode::0';
1.57 raeburn 9649: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9650: $adds{$newitem} = 1;
9651: }
9652: }
1.120 raeburn 9653: if ($env{'form.communities'} eq '1') {
9654: if (ref($cathash) eq 'HASH') {
9655: my $newitem = 'communities::0';
9656: if ($cathash->{$newitem} eq '') {
9657: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9658: $adds{$newitem} = 1;
9659: }
9660: } else {
9661: my $newitem = 'communities::0';
9662: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9663: $adds{$newitem} = 1;
9664: }
9665: }
1.48 raeburn 9666: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9667: if (($env{'form.addcategory_name'} ne 'instcode') &&
9668: ($env{'form.addcategory_name'} ne 'communities')) {
9669: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9670: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9671: $adds{$newitem} = 1;
9672: }
1.48 raeburn 9673: }
1.57 raeburn 9674: my $putresult;
1.48 raeburn 9675: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9676: if (keys(%deletions) > 0) {
9677: foreach my $key (keys(%deletions)) {
9678: if ($predelallitems{$key} ne '') {
9679: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9680: }
9681: }
9682: }
9683: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9684: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9685: if (ref($chkcats[0]) eq 'ARRAY') {
9686: my $depth = 0;
9687: my $chg = 0;
9688: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9689: my $name = $chkcats[0][$i];
9690: my $item;
9691: if ($name eq '') {
9692: $chg ++;
9693: } else {
9694: $item = &escape($name).'::0';
9695: if ($chg) {
1.57 raeburn 9696: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9697: }
9698: $depth ++;
1.57 raeburn 9699: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9700: $depth --;
9701: }
9702: }
9703: }
1.57 raeburn 9704: }
9705: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9706: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9707: if ($putresult eq 'ok') {
1.57 raeburn 9708: my %title = (
1.120 raeburn 9709: togglecats => 'Show/Hide a course in catalog',
9710: categorize => 'Assign a category to a course',
9711: togglecatscomm => 'Show/Hide a community in catalog',
9712: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9713: );
9714: my %level = (
1.120 raeburn 9715: dom => 'set in Domain ("Modify Course/Community")',
9716: crs => 'set in Course ("Course Configuration")',
9717: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 9718: none => 'No catalog',
9719: std => 'Standard catalog',
9720: domonly => 'Domain-only catalog',
9721: codesrch => 'Code search form',
1.57 raeburn 9722: );
1.48 raeburn 9723: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9724: if ($changes{'togglecats'}) {
9725: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9726: }
9727: if ($changes{'categorize'}) {
9728: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9729: }
1.120 raeburn 9730: if ($changes{'togglecatscomm'}) {
9731: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9732: }
9733: if ($changes{'categorizecomm'}) {
9734: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9735: }
1.238 raeburn 9736: if ($changes{'unauth'}) {
9737: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9738: }
9739: if ($changes{'auth'}) {
9740: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9741: }
1.57 raeburn 9742: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9743: my $cathash;
9744: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9745: $cathash = $domconfig{'coursecategories'}{'cats'};
9746: } else {
9747: $cathash = {};
9748: }
9749: my (@cats,@trails,%allitems);
9750: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9751: if (keys(%deletions) > 0) {
9752: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9753: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9754: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9755: }
9756: $resulttext .= '</ul></li>';
9757: }
9758: if (keys(%reorderings) > 0) {
9759: my %sort_by_trail;
9760: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9761: foreach my $key (keys(%reorderings)) {
9762: if ($allitems{$key} ne '') {
9763: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9764: }
1.48 raeburn 9765: }
1.57 raeburn 9766: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9767: $resulttext .= '<li>'.$trails[$trail].'</li>';
9768: }
9769: $resulttext .= '</ul></li>';
1.48 raeburn 9770: }
1.57 raeburn 9771: if (keys(%adds) > 0) {
9772: my %sort_by_trail;
9773: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9774: foreach my $key (keys(%adds)) {
9775: if ($allitems{$key} ne '') {
9776: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9777: }
9778: }
9779: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9780: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9781: }
1.57 raeburn 9782: $resulttext .= '</ul></li>';
1.48 raeburn 9783: }
9784: }
9785: $resulttext .= '</ul>';
1.239 raeburn 9786: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 9787: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9788: if ($changes{'auth'}) {
9789: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
9790: }
9791: if ($changes{'unauth'}) {
9792: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
9793: }
9794: my $cachetime = 24*60*60;
9795: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 9796: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 9797: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 9798: }
9799: }
1.48 raeburn 9800: } else {
9801: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9802: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9803: }
9804: } else {
1.120 raeburn 9805: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9806: }
9807: return $resulttext;
9808: }
9809:
1.69 raeburn 9810: sub modify_serverstatuses {
9811: my ($dom,%domconfig) = @_;
9812: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9813: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9814: %currserverstatus = %{$domconfig{'serverstatuses'}};
9815: }
9816: my @pages = &serverstatus_pages();
9817: foreach my $type (@pages) {
9818: $newserverstatus{$type}{'namedusers'} = '';
9819: $newserverstatus{$type}{'machines'} = '';
9820: if (defined($env{'form.'.$type.'_namedusers'})) {
9821: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9822: my @okusers;
9823: foreach my $user (@users) {
9824: my ($uname,$udom) = split(/:/,$user);
9825: if (($udom =~ /^$match_domain$/) &&
9826: (&Apache::lonnet::domain($udom)) &&
9827: ($uname =~ /^$match_username$/)) {
9828: if (!grep(/^\Q$user\E/,@okusers)) {
9829: push(@okusers,$user);
9830: }
9831: }
9832: }
9833: if (@okusers > 0) {
9834: @okusers = sort(@okusers);
9835: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9836: }
9837: }
9838: if (defined($env{'form.'.$type.'_machines'})) {
9839: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9840: my @okmachines;
9841: foreach my $ip (@machines) {
9842: my @parts = split(/\./,$ip);
9843: next if (@parts < 4);
9844: my $badip = 0;
9845: for (my $i=0; $i<4; $i++) {
9846: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9847: $badip = 1;
9848: last;
9849: }
9850: }
9851: if (!$badip) {
9852: push(@okmachines,$ip);
9853: }
9854: }
9855: @okmachines = sort(@okmachines);
9856: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9857: }
9858: }
9859: my %serverstatushash = (
9860: serverstatuses => \%newserverstatus,
9861: );
9862: foreach my $type (@pages) {
1.83 raeburn 9863: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9864: my (@current,@new);
1.83 raeburn 9865: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9866: if ($currserverstatus{$type}{$setting} ne '') {
9867: @current = split(/,/,$currserverstatus{$type}{$setting});
9868: }
9869: }
9870: if ($newserverstatus{$type}{$setting} ne '') {
9871: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9872: }
9873: if (@current > 0) {
9874: if (@new > 0) {
9875: foreach my $item (@current) {
9876: if (!grep(/^\Q$item\E$/,@new)) {
9877: $changes{$type}{$setting} = 1;
1.82 raeburn 9878: last;
9879: }
9880: }
1.84 raeburn 9881: foreach my $item (@new) {
9882: if (!grep(/^\Q$item\E$/,@current)) {
9883: $changes{$type}{$setting} = 1;
9884: last;
1.82 raeburn 9885: }
9886: }
9887: } else {
1.83 raeburn 9888: $changes{$type}{$setting} = 1;
1.69 raeburn 9889: }
1.83 raeburn 9890: } elsif (@new > 0) {
9891: $changes{$type}{$setting} = 1;
1.69 raeburn 9892: }
9893: }
9894: }
9895: if (keys(%changes) > 0) {
1.81 raeburn 9896: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9897: my $putresult = &Apache::lonnet::put_dom('configuration',
9898: \%serverstatushash,$dom);
9899: if ($putresult eq 'ok') {
9900: $resulttext .= &mt('Changes made:').'<ul>';
9901: foreach my $type (@pages) {
1.84 raeburn 9902: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9903: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9904: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9905: if ($newserverstatus{$type}{'namedusers'} eq '') {
9906: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9907: } else {
9908: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9909: }
1.84 raeburn 9910: }
9911: if ($changes{$type}{'machines'}) {
1.69 raeburn 9912: if ($newserverstatus{$type}{'machines'} eq '') {
9913: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9914: } else {
9915: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9916: }
9917:
9918: }
9919: $resulttext .= '</ul></li>';
9920: }
9921: }
9922: $resulttext .= '</ul>';
9923: } else {
9924: $resulttext = '<span class="LC_error">'.
9925: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9926:
9927: }
9928: } else {
9929: $resulttext = &mt('No changes made to access to server status pages');
9930: }
9931: return $resulttext;
9932: }
9933:
1.118 jms 9934: sub modify_helpsettings {
1.122 jms 9935: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9936: my ($resulttext,$errors,%changes,%helphash);
9937: my %defaultchecked = ('submitbugs' => 'on');
9938: my @offon = ('off','on');
1.118 jms 9939: my @toggles = ('submitbugs');
9940: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9941: foreach my $item (@toggles) {
1.166 raeburn 9942: if ($defaultchecked{$item} eq 'on') {
9943: if ($domconfig{'helpsettings'}{$item} eq '') {
9944: if ($env{'form.'.$item} eq '0') {
9945: $changes{$item} = 1;
9946: }
9947: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9948: $changes{$item} = 1;
9949: }
9950: } elsif ($defaultchecked{$item} eq 'off') {
9951: if ($domconfig{'helpsettings'}{$item} eq '') {
9952: if ($env{'form.'.$item} eq '1') {
9953: $changes{$item} = 1;
9954: }
9955: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9956: $changes{$item} = 1;
9957: }
9958: }
1.210 raeburn 9959: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9960: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9961: }
9962: }
1.118 jms 9963: }
1.123 jms 9964: my $putresult;
9965: if (keys(%changes) > 0) {
1.166 raeburn 9966: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9967: if ($putresult eq 'ok') {
1.166 raeburn 9968: $resulttext = &mt('Changes made:').'<ul>';
9969: foreach my $item (sort(keys(%changes))) {
9970: if ($item eq 'submitbugs') {
9971: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9972: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9973: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9974: }
9975: }
9976: $resulttext .= '</ul>';
9977: } else {
9978: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9979: $errors .= '<li><span class="LC_error">'.
9980: &mt('An error occurred storing the settings: [_1]',
9981: $putresult).'</span></li>';
1.166 raeburn 9982: }
1.118 jms 9983: }
9984: if ($errors) {
1.168 raeburn 9985: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9986: $errors.'</ul>';
9987: }
9988: return $resulttext;
9989: }
9990:
1.121 raeburn 9991: sub modify_coursedefaults {
1.212 raeburn 9992: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9993: my ($resulttext,$errors,%changes,%defaultshash);
9994: my %defaultchecked = ('canuse_pdfforms' => 'off');
9995: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9996: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9997: 'uploadquota_community','uploadquota_textbook');
9998: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9999: my %staticdefaults = (
10000: anonsurvey_threshold => 10,
10001: uploadquota => 500,
10002: );
1.121 raeburn 10003:
10004: $defaultshash{'coursedefaults'} = {};
10005:
10006: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10007: if ($domconfig{'coursedefaults'} eq '') {
10008: $domconfig{'coursedefaults'} = {};
10009: }
10010: }
10011:
10012: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10013: foreach my $item (@toggles) {
10014: if ($defaultchecked{$item} eq 'on') {
10015: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10016: ($env{'form.'.$item} eq '0')) {
10017: $changes{$item} = 1;
1.192 raeburn 10018: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10019: $changes{$item} = 1;
10020: }
10021: } elsif ($defaultchecked{$item} eq 'off') {
10022: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10023: ($env{'form.'.$item} eq '1')) {
10024: $changes{$item} = 1;
10025: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10026: $changes{$item} = 1;
10027: }
10028: }
10029: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10030: }
1.198 raeburn 10031: foreach my $item (@numbers) {
10032: my ($currdef,$newdef);
1.208 raeburn 10033: $newdef = $env{'form.'.$item};
1.198 raeburn 10034: if ($item eq 'anonsurvey_threshold') {
10035: $currdef = $domconfig{'coursedefaults'}{$item};
10036: $newdef =~ s/\D//g;
10037: if ($newdef eq '' || $newdef < 1) {
10038: $newdef = 1;
10039: }
10040: $defaultshash{'coursedefaults'}{$item} = $newdef;
10041: } else {
10042: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10043: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10044: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10045: }
10046: $newdef =~ s/[^\w.\-]//g;
10047: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10048: }
10049: if ($currdef ne $newdef) {
10050: my $staticdef;
10051: if ($item eq 'anonsurvey_threshold') {
10052: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10053: $changes{$item} = 1;
10054: }
10055: } else {
10056: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10057: $changes{'uploadquota'} = 1;
10058: }
10059: }
1.139 raeburn 10060: }
10061: }
1.231 raeburn 10062:
1.192 raeburn 10063: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 10064: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 10065: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 10066: $unofficialcreds =~ s/[^\d.]+//g;
10067: my $textbookcreds = $env{'form.textbook_credits'};
10068: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 10069: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10070: ($env{'form.coursecredits'} eq '1')) {
10071: $changes{'coursecredits'} = 1;
10072: } else {
10073: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 10074: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10075: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 10076: $changes{'coursecredits'} = 1;
10077: }
10078: }
10079: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10080: official => $officialcreds,
10081: unofficial => $unofficialcreds,
1.216 raeburn 10082: textbook => $textbookcreds,
1.192 raeburn 10083: }
1.121 raeburn 10084: }
10085: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10086: $dom);
10087: if ($putresult eq 'ok') {
10088: if (keys(%changes) > 0) {
1.213 raeburn 10089: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 10090: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 10091: ($changes{'uploadquota'})) {
1.192 raeburn 10092: if ($changes{'canuse_pdfforms'}) {
10093: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10094: }
10095: if ($changes{'coursecredits'}) {
10096: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10097: $domdefaults{'officialcredits'} =
10098: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10099: $domdefaults{'unofficialcredits'} =
10100: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 10101: $domdefaults{'textbookcredits'} =
10102: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 10103: }
10104: }
1.198 raeburn 10105: if ($changes{'uploadquota'}) {
10106: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10107: foreach my $type (@types) {
10108: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10109: }
10110: }
10111: }
1.121 raeburn 10112: my $cachetime = 24*60*60;
10113: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10114: if (ref($lastactref) eq 'HASH') {
10115: $lastactref->{'domdefaults'} = 1;
10116: }
1.121 raeburn 10117: }
10118: $resulttext = &mt('Changes made:').'<ul>';
10119: foreach my $item (sort(keys(%changes))) {
10120: if ($item eq 'canuse_pdfforms') {
10121: if ($env{'form.'.$item} eq '1') {
10122: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10123: } else {
10124: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10125: }
1.139 raeburn 10126: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 10127: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 10128: } elsif ($item eq 'uploadquota') {
10129: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10130: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10131: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10132: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 10133: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10134:
1.198 raeburn 10135: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10136: '</ul>'.
10137: '</li>';
10138: } else {
10139: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10140: }
1.192 raeburn 10141: } elsif ($item eq 'coursecredits') {
10142: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10143: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 10144: ($domdefaults{'unofficialcredits'} eq '') &&
10145: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 10146: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10147: } else {
10148: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10149: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10150: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 10151: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 10152: '</ul>'.
10153: '</li>';
10154: }
10155: } else {
10156: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10157: }
1.140 raeburn 10158: }
1.121 raeburn 10159: }
10160: $resulttext .= '</ul>';
10161: } else {
10162: $resulttext = &mt('No changes made to course defaults');
10163: }
10164: } else {
10165: $resulttext = '<span class="LC_error">'.
10166: &mt('An error occurred: [_1]',$putresult).'</span>';
10167: }
10168: return $resulttext;
10169: }
10170:
1.231 raeburn 10171: sub modify_selfenrollment {
10172: my ($dom,$lastactref,%domconfig) = @_;
10173: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10174: my @types = ('official','unofficial','community','textbook');
10175: my %titles = &tool_titles();
1.232 raeburn 10176: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10177: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 10178: $ordered{'default'} = ['types','registered','approval','limit'];
10179:
10180: my (%roles,%shown,%toplevel);
10181: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10182:
10183: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10184: if ($domconfig{'selfenrollment'} eq '') {
10185: $domconfig{'selfenrollment'} = {};
10186: }
10187: }
10188: %toplevel = (
10189: admin => 'Configuration Rights',
10190: default => 'Default settings',
10191: validation => 'Validation of self-enrollment requests',
10192: );
1.233 raeburn 10193: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10194:
10195: if (ref($ordered{'admin'}) eq 'ARRAY') {
10196: foreach my $item (@{$ordered{'admin'}}) {
10197: foreach my $type (@types) {
10198: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10199: $selfenrollhash{'admin'}{$type}{$item} = 1;
10200: } else {
10201: $selfenrollhash{'admin'}{$type}{$item} = 0;
10202: }
10203: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10204: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10205: if ($selfenrollhash{'admin'}{$type}{$item} ne
10206: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10207: push(@{$changes{'admin'}{$type}},$item);
10208: }
10209: } else {
10210: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10211: push(@{$changes{'admin'}{$type}},$item);
10212: }
10213: }
10214: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10215: push(@{$changes{'admin'}{$type}},$item);
10216: }
10217: }
10218: }
10219: }
10220:
10221: foreach my $item (@{$ordered{'default'}}) {
10222: foreach my $type (@types) {
10223: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10224: if ($item eq 'types') {
10225: unless (($value eq 'all') || ($value eq 'dom')) {
10226: $value = '';
10227: }
10228: } elsif ($item eq 'registered') {
10229: unless ($value eq '1') {
10230: $value = 0;
10231: }
10232: } elsif ($item eq 'approval') {
10233: unless ($value =~ /^[012]$/) {
10234: $value = 0;
10235: }
10236: } else {
10237: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10238: $value = 'none';
10239: }
10240: }
10241: $selfenrollhash{'default'}{$type}{$item} = $value;
10242: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10243: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10244: if ($selfenrollhash{'default'}{$type}{$item} ne
10245: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10246: push(@{$changes{'default'}{$type}},$item);
10247: }
10248: } else {
10249: push(@{$changes{'default'}{$type}},$item);
10250: }
10251: } else {
10252: push(@{$changes{'default'}{$type}},$item);
10253: }
10254: if ($item eq 'limit') {
10255: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10256: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10257: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10258: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10259: }
10260: } else {
10261: $selfenrollhash{'default'}{$type}{'cap'} = '';
10262: }
10263: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10264: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10265: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10266: push(@{$changes{'default'}{$type}},'cap');
10267: }
10268: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10269: push(@{$changes{'default'}{$type}},'cap');
10270: }
10271: }
10272: }
10273: }
10274:
10275: foreach my $item (@{$itemsref}) {
10276: if ($item eq 'fields') {
10277: my @changed;
10278: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10279: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10280: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10281: }
10282: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10283: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10284: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10285: $domconfig{'selfenrollment'}{'validation'}{$item});
10286: } else {
10287: @changed = @{$selfenrollhash{'validation'}{$item}};
10288: }
10289: } else {
10290: @changed = @{$selfenrollhash{'validation'}{$item}};
10291: }
10292: if (@changed) {
10293: if ($selfenrollhash{'validation'}{$item}) {
10294: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10295: } else {
10296: $changes{'validation'}{$item} = &mt('None');
10297: }
10298: }
10299: } else {
10300: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10301: if ($item eq 'markup') {
10302: if ($env{'form.selfenroll_validation_'.$item}) {
10303: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10304: }
10305: }
10306: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10307: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10308: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10309: }
10310: }
10311: }
10312: }
10313:
10314: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10315: $dom);
10316: if ($putresult eq 'ok') {
10317: if (keys(%changes) > 0) {
10318: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10319: $resulttext = &mt('Changes made:').'<ul>';
10320: foreach my $key ('admin','default','validation') {
10321: if (ref($changes{$key}) eq 'HASH') {
10322: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10323: if ($key eq 'validation') {
10324: foreach my $item (@{$itemsref}) {
10325: if (exists($changes{$key}{$item})) {
10326: if ($item eq 'markup') {
10327: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10328: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10329: } else {
10330: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10331: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10332: }
10333: }
10334: }
10335: } else {
10336: foreach my $type (@types) {
10337: if ($type eq 'community') {
10338: $roles{'1'} = &mt('Community personnel');
10339: } else {
10340: $roles{'1'} = &mt('Course personnel');
10341: }
10342: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10343: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10344: if ($key eq 'admin') {
10345: my @mgrdc = ();
10346: if (ref($ordered{$key}) eq 'ARRAY') {
10347: foreach my $item (@{$ordered{'admin'}}) {
10348: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10349: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10350: push(@mgrdc,$item);
10351: }
10352: }
10353: }
10354: if (@mgrdc) {
10355: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10356: } else {
10357: delete($domdefaults{$type.'selfenrolladmdc'});
10358: }
10359: }
10360: } else {
10361: if (ref($ordered{$key}) eq 'ARRAY') {
10362: foreach my $item (@{$ordered{$key}}) {
10363: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10364: $domdefaults{$type.'selfenroll'.$item} =
10365: $selfenrollhash{$key}{$type}{$item};
10366: }
10367: }
10368: }
10369: }
10370: }
1.231 raeburn 10371: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10372: foreach my $item (@{$ordered{$key}}) {
10373: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10374: $resulttext .= '<li>';
10375: if ($key eq 'admin') {
10376: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10377: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10378: } else {
10379: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10380: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10381: }
10382: $resulttext .= '</li>';
10383: }
10384: }
10385: $resulttext .= '</ul></li>';
10386: }
10387: }
10388: $resulttext .= '</ul></li>';
10389: }
10390: }
1.232 raeburn 10391: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10392: my $cachetime = 24*60*60;
10393: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10394: if (ref($lastactref) eq 'HASH') {
10395: $lastactref->{'domdefaults'} = 1;
10396: }
10397: }
1.231 raeburn 10398: }
10399: $resulttext .= '</ul>';
10400: } else {
10401: $resulttext = &mt('No changes made to self-enrollment settings');
10402: }
10403: } else {
10404: $resulttext = '<span class="LC_error">'.
10405: &mt('An error occurred: [_1]',$putresult).'</span>';
10406: }
10407: return $resulttext;
10408: }
10409:
1.137 raeburn 10410: sub modify_usersessions {
1.212 raeburn 10411: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10412: my @hostingtypes = ('version','excludedomain','includedomain');
10413: my @offloadtypes = ('primary','default');
10414: my %types = (
10415: remote => \@hostingtypes,
10416: hosted => \@hostingtypes,
10417: spares => \@offloadtypes,
10418: );
10419: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10420: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10421: my (%by_ip,%by_location,@intdoms);
10422: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10423: my @locations = sort(keys(%by_location));
1.137 raeburn 10424: my (%defaultshash,%changes);
10425: foreach my $prefix (@prefixes) {
10426: $defaultshash{'usersessions'}{$prefix} = {};
10427: }
1.212 raeburn 10428: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10429: my $resulttext;
1.138 raeburn 10430: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10431: foreach my $prefix (@prefixes) {
1.145 raeburn 10432: next if ($prefix eq 'spares');
10433: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10434: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10435: if ($type eq 'version') {
10436: my $value = $env{'form.'.$prefix.'_'.$type};
10437: my $okvalue;
10438: if ($value ne '') {
10439: if (grep(/^\Q$value\E$/,@lcversions)) {
10440: $okvalue = $value;
10441: }
10442: }
10443: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10444: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10445: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10446: if ($inuse == 0) {
10447: $changes{$prefix}{$type} = 1;
10448: } else {
10449: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10450: $changes{$prefix}{$type} = 1;
10451: }
10452: if ($okvalue ne '') {
10453: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10454: }
10455: }
10456: } else {
10457: if (($inuse == 1) && ($okvalue ne '')) {
10458: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10459: $changes{$prefix}{$type} = 1;
10460: }
10461: }
10462: } else {
10463: if (($inuse == 1) && ($okvalue ne '')) {
10464: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10465: $changes{$prefix}{$type} = 1;
10466: }
10467: }
10468: } else {
10469: if (($inuse == 1) && ($okvalue ne '')) {
10470: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10471: $changes{$prefix}{$type} = 1;
10472: }
10473: }
10474: } else {
10475: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10476: my @okvals;
10477: foreach my $val (@vals) {
1.138 raeburn 10478: if ($val =~ /:/) {
10479: my @items = split(/:/,$val);
10480: foreach my $item (@items) {
10481: if (ref($by_location{$item}) eq 'ARRAY') {
10482: push(@okvals,$item);
10483: }
10484: }
10485: } else {
10486: if (ref($by_location{$val}) eq 'ARRAY') {
10487: push(@okvals,$val);
10488: }
1.137 raeburn 10489: }
10490: }
10491: @okvals = sort(@okvals);
10492: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10493: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10494: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10495: if ($inuse == 0) {
10496: $changes{$prefix}{$type} = 1;
10497: } else {
10498: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10499: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10500: if (@changed > 0) {
10501: $changes{$prefix}{$type} = 1;
10502: }
10503: }
10504: } else {
10505: if ($inuse == 1) {
10506: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10507: $changes{$prefix}{$type} = 1;
10508: }
10509: }
10510: } else {
10511: if ($inuse == 1) {
10512: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10513: $changes{$prefix}{$type} = 1;
10514: }
10515: }
10516: } else {
10517: if ($inuse == 1) {
10518: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10519: $changes{$prefix}{$type} = 1;
10520: }
10521: }
10522: }
10523: }
10524: }
1.145 raeburn 10525:
10526: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10527: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10528: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10529: my $savespares;
10530:
10531: foreach my $lonhost (sort(keys(%servers))) {
10532: my $serverhomeID =
10533: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10534: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10535: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10536: my %spareschg;
10537: foreach my $type (@{$types{'spares'}}) {
10538: my @okspares;
10539: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10540: foreach my $server (@checked) {
1.152 raeburn 10541: if (&Apache::lonnet::hostname($server) ne '') {
10542: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10543: unless (grep(/^\Q$server\E$/,@okspares)) {
10544: push(@okspares,$server);
10545: }
1.145 raeburn 10546: }
10547: }
10548: }
10549: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10550: my $newspare;
1.152 raeburn 10551: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10552: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10553: $newspare = $new;
10554: }
10555: }
1.152 raeburn 10556: my @spares;
10557: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10558: @spares = sort(@okspares,$newspare);
10559: } else {
10560: @spares = sort(@okspares);
10561: }
10562: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10563: if (ref($spareid{$lonhost}) eq 'HASH') {
10564: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10565: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10566: if (@diffs > 0) {
10567: $spareschg{$type} = 1;
10568: }
10569: }
10570: }
10571: }
10572: if (keys(%spareschg) > 0) {
10573: $changes{'spares'}{$lonhost} = \%spareschg;
10574: }
10575: }
10576:
10577: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10578: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10579: if (ref($changes{'spares'}) eq 'HASH') {
10580: if (keys(%{$changes{'spares'}}) > 0) {
10581: $savespares = 1;
10582: }
10583: }
10584: } else {
10585: $savespares = 1;
10586: }
10587: }
10588:
1.147 raeburn 10589: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10590: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10591: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10592: $dom);
10593: if ($putresult eq 'ok') {
10594: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10595: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10596: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10597: }
10598: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10599: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10600: }
10601: }
10602: my $cachetime = 24*60*60;
10603: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10604: if (ref($lastactref) eq 'HASH') {
10605: $lastactref->{'domdefaults'} = 1;
10606: }
1.147 raeburn 10607: if (keys(%changes) > 0) {
10608: my %lt = &usersession_titles();
10609: $resulttext = &mt('Changes made:').'<ul>';
10610: foreach my $prefix (@prefixes) {
10611: if (ref($changes{$prefix}) eq 'HASH') {
10612: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10613: if ($prefix eq 'spares') {
10614: if (ref($changes{$prefix}) eq 'HASH') {
10615: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10616: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10617: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10618: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10619: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10620: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10621: foreach my $type (@{$types{$prefix}}) {
10622: if ($changes{$prefix}{$lonhost}{$type}) {
10623: my $offloadto = &mt('None');
10624: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10625: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10626: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10627: }
1.145 raeburn 10628: }
1.147 raeburn 10629: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10630: }
1.137 raeburn 10631: }
10632: }
1.147 raeburn 10633: $resulttext .= '</li>';
1.137 raeburn 10634: }
10635: }
1.147 raeburn 10636: } else {
10637: foreach my $type (@{$types{$prefix}}) {
10638: if (defined($changes{$prefix}{$type})) {
10639: my $newvalue;
10640: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10641: if (ref($defaultshash{'usersessions'}{$prefix})) {
10642: if ($type eq 'version') {
10643: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10644: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10645: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10646: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10647: }
1.145 raeburn 10648: }
10649: }
10650: }
1.147 raeburn 10651: if ($newvalue eq '') {
10652: if ($type eq 'version') {
10653: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10654: } else {
10655: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10656: }
1.145 raeburn 10657: } else {
1.147 raeburn 10658: if ($type eq 'version') {
10659: $newvalue .= ' '.&mt('(or later)');
10660: }
10661: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10662: }
1.137 raeburn 10663: }
10664: }
10665: }
1.147 raeburn 10666: $resulttext .= '</ul>';
1.137 raeburn 10667: }
10668: }
1.147 raeburn 10669: $resulttext .= '</ul>';
10670: } else {
10671: $resulttext = $nochgmsg;
1.137 raeburn 10672: }
10673: } else {
10674: $resulttext = '<span class="LC_error">'.
10675: &mt('An error occurred: [_1]',$putresult).'</span>';
10676: }
10677: } else {
1.147 raeburn 10678: $resulttext = $nochgmsg;
1.137 raeburn 10679: }
10680: return $resulttext;
10681: }
10682:
1.150 raeburn 10683: sub modify_loadbalancing {
10684: my ($dom,%domconfig) = @_;
10685: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10686: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10687: my ($othertitle,$usertypes,$types) =
10688: &Apache::loncommon::sorted_inst_types($dom);
10689: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 10690: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 10691: my @sparestypes = ('primary','default');
10692: my %typetitles = &sparestype_titles();
10693: my $resulttext;
1.171 raeburn 10694: my (%currbalancer,%currtargets,%currrules,%existing);
10695: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10696: %existing = %{$domconfig{'loadbalancing'}};
10697: }
10698: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10699: \%currtargets,\%currrules);
10700: my ($saveloadbalancing,%defaultshash,%changes);
10701: my ($alltypes,$othertypes,$titles) =
10702: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10703: my %ruletitles = &offloadtype_text();
10704: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10705: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10706: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10707: if ($balancer eq '') {
10708: next;
10709: }
1.210 raeburn 10710: if (!exists($servers{$balancer})) {
1.171 raeburn 10711: if (exists($currbalancer{$balancer})) {
10712: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10713: }
1.171 raeburn 10714: next;
10715: }
10716: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10717: push(@{$changes{'delete'}},$balancer);
10718: next;
10719: }
10720: if (!exists($currbalancer{$balancer})) {
10721: push(@{$changes{'add'}},$balancer);
10722: }
10723: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10724: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10725: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10726: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10727: $saveloadbalancing = 1;
10728: }
10729: foreach my $sparetype (@sparestypes) {
10730: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10731: my @offloadto;
10732: foreach my $target (@targets) {
10733: if (($servers{$target}) && ($target ne $balancer)) {
10734: if ($sparetype eq 'default') {
10735: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10736: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10737: }
10738: }
1.171 raeburn 10739: unless(grep(/^\Q$target\E$/,@offloadto)) {
10740: push(@offloadto,$target);
10741: }
1.150 raeburn 10742: }
1.171 raeburn 10743: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10744: }
10745: }
1.171 raeburn 10746: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10747: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10748: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10749: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10750: if (@targetdiffs > 0) {
1.171 raeburn 10751: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10752: }
1.171 raeburn 10753: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10754: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10755: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10756: }
10757: }
10758: }
10759: } else {
1.171 raeburn 10760: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10761: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10762: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10763: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10764: $changes{'curr'}{$balancer}{'targets'} = 1;
10765: }
1.150 raeburn 10766: }
10767: }
1.210 raeburn 10768: }
1.150 raeburn 10769: }
10770: my $ishomedom;
1.171 raeburn 10771: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10772: $ishomedom = 1;
1.150 raeburn 10773: }
10774: if (ref($alltypes) eq 'ARRAY') {
10775: foreach my $type (@{$alltypes}) {
10776: my $rule;
1.210 raeburn 10777: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10778: (!$ishomedom)) {
1.171 raeburn 10779: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10780: }
10781: if ($rule eq 'specific') {
1.255 ! raeburn 10782: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
! 10783: if (exists($servers{$specifiedhost})) {
! 10784: $rule = $specifiedhost;
! 10785: }
1.150 raeburn 10786: }
1.171 raeburn 10787: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10788: if (ref($currrules{$balancer}) eq 'HASH') {
10789: if ($rule ne $currrules{$balancer}{$type}) {
10790: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10791: }
10792: } elsif ($rule ne '') {
1.171 raeburn 10793: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10794: }
10795: }
10796: }
1.171 raeburn 10797: }
10798: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10799: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10800: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10801: $defaultshash{'loadbalancing'} = {};
10802: }
10803: my $putresult = &Apache::lonnet::put_dom('configuration',
10804: \%defaultshash,$dom);
10805: if ($putresult eq 'ok') {
10806: if (keys(%changes) > 0) {
1.252 raeburn 10807: my %toupdate;
1.171 raeburn 10808: if (ref($changes{'delete'}) eq 'ARRAY') {
10809: foreach my $balancer (sort(@{$changes{'delete'}})) {
10810: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 10811: $toupdate{$balancer} = 1;
1.150 raeburn 10812: }
1.171 raeburn 10813: }
10814: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10815: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10816: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 10817: $toupdate{$balancer} = 1;
1.171 raeburn 10818: }
10819: }
10820: if (ref($changes{'curr'}) eq 'HASH') {
10821: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 10822: $toupdate{$balancer} = 1;
1.171 raeburn 10823: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10824: if ($changes{'curr'}{$balancer}{'targets'}) {
10825: my %offloadstr;
10826: foreach my $sparetype (@sparestypes) {
10827: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10828: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10829: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10830: }
10831: }
1.150 raeburn 10832: }
1.171 raeburn 10833: if (keys(%offloadstr) == 0) {
10834: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10835: } else {
1.171 raeburn 10836: my $showoffload;
10837: foreach my $sparetype (@sparestypes) {
10838: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10839: if (defined($offloadstr{$sparetype})) {
10840: $showoffload .= $offloadstr{$sparetype};
10841: } else {
10842: $showoffload .= &mt('None');
10843: }
10844: $showoffload .= (' 'x3);
10845: }
10846: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10847: }
10848: }
10849: }
1.171 raeburn 10850: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10851: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10852: foreach my $type (@{$alltypes}) {
10853: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10854: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10855: my $balancetext;
10856: if ($rule eq '') {
10857: $balancetext = $ruletitles{'default'};
1.209 raeburn 10858: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 10859: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
10860: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 10861: foreach my $sparetype (@sparestypes) {
10862: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10863: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10864: }
10865: }
1.253 raeburn 10866: foreach my $item (@{$alltypes}) {
10867: next if ($item =~ /^_LC_ipchange/);
10868: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
10869: if ($hasrule eq 'homeserver') {
10870: map { $toupdate{$_} = 1; } (keys(%libraryservers));
10871: } else {
10872: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
10873: if ($servers{$hasrule}) {
10874: $toupdate{$hasrule} = 1;
10875: }
10876: }
10877: }
10878: }
1.254 raeburn 10879: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
10880: $balancetext = $ruletitles{$rule};
10881: } else {
10882: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10883: $balancetext = $ruletitles{'particular'}.' '.$receiver;
10884: if ($receiver) {
10885: $toupdate{$receiver};
10886: }
10887: }
10888: } else {
10889: $balancetext = $ruletitles{$rule};
1.252 raeburn 10890: }
1.171 raeburn 10891: } else {
10892: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10893: }
1.210 raeburn 10894: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10895: }
10896: }
10897: }
10898: }
1.252 raeburn 10899: if (keys(%toupdate)) {
10900: my %thismachine;
10901: my $updatedhere;
10902: my $cachetime = 60*60*24;
10903: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
10904: foreach my $lonhost (keys(%toupdate)) {
10905: if ($thismachine{$lonhost}) {
10906: unless ($updatedhere) {
10907: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
10908: $defaultshash{'loadbalancing'},
10909: $cachetime);
10910: $updatedhere = 1;
10911: }
10912: } else {
10913: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10914: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
10915: }
10916: }
10917: }
1.150 raeburn 10918: }
1.171 raeburn 10919: }
10920: if ($resulttext ne '') {
10921: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10922: } else {
10923: $resulttext = $nochgmsg;
10924: }
10925: } else {
1.171 raeburn 10926: $resulttext = $nochgmsg;
1.150 raeburn 10927: }
10928: } else {
1.171 raeburn 10929: $resulttext = '<span class="LC_error">'.
10930: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10931: }
10932: } else {
1.171 raeburn 10933: $resulttext = $nochgmsg;
1.150 raeburn 10934: }
10935: return $resulttext;
10936: }
10937:
1.48 raeburn 10938: sub recurse_check {
10939: my ($chkcats,$categories,$depth,$name) = @_;
10940: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10941: my $chg = 0;
10942: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10943: my $category = $chkcats->[$depth]{$name}[$j];
10944: my $item;
10945: if ($category eq '') {
10946: $chg ++;
10947: } else {
10948: my $deeper = $depth + 1;
10949: $item = &escape($category).':'.&escape($name).':'.$depth;
10950: if ($chg) {
10951: $categories->{$item} -= $chg;
10952: }
10953: &recurse_check($chkcats,$categories,$deeper,$category);
10954: $deeper --;
10955: }
10956: }
10957: }
10958: return;
10959: }
10960:
10961: sub recurse_cat_deletes {
10962: my ($item,$coursecategories,$deletions) = @_;
10963: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10964: my $subdepth = $depth + 1;
10965: if (ref($coursecategories) eq 'HASH') {
10966: foreach my $subitem (keys(%{$coursecategories})) {
10967: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10968: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10969: delete($coursecategories->{$subitem});
10970: $deletions->{$subitem} = 1;
10971: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10972: }
1.48 raeburn 10973: }
10974: }
10975: return;
10976: }
10977:
1.125 raeburn 10978: sub get_active_dcs {
10979: my ($dom) = @_;
1.191 raeburn 10980: my $now = time;
10981: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10982: my %domcoords;
10983: my $numdcs = 0;
10984: foreach my $server (keys(%dompersonnel)) {
10985: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10986: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10987: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10988: }
10989: }
10990: return %domcoords;
10991: }
10992:
10993: sub active_dc_picker {
1.191 raeburn 10994: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 10995: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10996: my @domcoord = keys(%domcoords);
10997: if (keys(%currhash)) {
10998: foreach my $dc (keys(%currhash)) {
10999: unless (exists($domcoords{$dc})) {
11000: push(@domcoord,$dc);
11001: }
11002: }
11003: }
11004: @domcoord = sort(@domcoord);
1.210 raeburn 11005: my $numdcs = scalar(@domcoord);
1.191 raeburn 11006: my $rows = 0;
11007: my $table;
1.125 raeburn 11008: if ($numdcs > 1) {
1.191 raeburn 11009: $table = '<table>';
11010: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11011: my $rem = $i%($numinrow);
11012: if ($rem == 0) {
11013: if ($i > 0) {
1.191 raeburn 11014: $table .= '</tr>';
1.125 raeburn 11015: }
1.191 raeburn 11016: $table .= '<tr>';
11017: $rows ++;
1.125 raeburn 11018: }
1.191 raeburn 11019: my $check = '';
11020: if ($inputtype eq 'radio') {
11021: if (keys(%currhash) == 0) {
11022: if (!$i) {
11023: $check = ' checked="checked"';
11024: }
11025: } elsif (exists($currhash{$domcoord[$i]})) {
11026: $check = ' checked="checked"';
11027: }
11028: } else {
11029: if (exists($currhash{$domcoord[$i]})) {
11030: $check = ' checked="checked"';
1.125 raeburn 11031: }
11032: }
1.191 raeburn 11033: if ($i == @domcoord - 1) {
1.125 raeburn 11034: my $colsleft = $numinrow - $rem;
11035: if ($colsleft > 1) {
1.191 raeburn 11036: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11037: } else {
1.191 raeburn 11038: $table .= '<td class="LC_left_item">';
1.125 raeburn 11039: }
11040: } else {
1.191 raeburn 11041: $table .= '<td class="LC_left_item">';
11042: }
11043: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11044: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11045: $table .= '<span class="LC_nobreak"><label>'.
11046: '<input type="'.$inputtype.'" name="'.$name.'"'.
11047: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11048: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 11049: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 11050: }
1.219 raeburn 11051: $table .= '</label></span></td>';
1.191 raeburn 11052: }
11053: $table .= '</tr></table>';
11054: } elsif ($numdcs == 1) {
1.219 raeburn 11055: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11056: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 11057: if ($inputtype eq 'radio') {
1.247 raeburn 11058: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 11059: if ($user ne $dcname.':'.$dcdom) {
11060: $table .= ' ('.$dcname.':'.$dcdom.')';
11061: }
1.191 raeburn 11062: } else {
11063: my $check;
11064: if (exists($currhash{$domcoord[0]})) {
11065: $check = ' checked="checked"';
1.125 raeburn 11066: }
1.247 raeburn 11067: $table = '<span class="LC_nobreak"><label>'.
11068: '<input type="checkbox" name="'.$name.'" '.
11069: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 11070: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 11071: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 11072: }
1.220 raeburn 11073: $table .= '</label></span>';
1.191 raeburn 11074: $rows ++;
1.125 raeburn 11075: }
11076: }
1.191 raeburn 11077: return ($numdcs,$table,$rows);
1.125 raeburn 11078: }
11079:
1.137 raeburn 11080: sub usersession_titles {
11081: return &Apache::lonlocal::texthash(
11082: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11083: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11084: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11085: version => 'LON-CAPA version requirement',
1.138 raeburn 11086: excludedomain => 'Allow all, but exclude specific domains',
11087: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11088: primary => 'Primary (checked first)',
1.154 raeburn 11089: default => 'Default',
1.137 raeburn 11090: );
11091: }
11092:
1.152 raeburn 11093: sub id_for_thisdom {
11094: my (%servers) = @_;
11095: my %altids;
11096: foreach my $server (keys(%servers)) {
11097: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11098: if ($serverhome ne $server) {
11099: $altids{$serverhome} = $server;
11100: }
11101: }
11102: return %altids;
11103: }
11104:
1.150 raeburn 11105: sub count_servers {
11106: my ($currbalancer,%servers) = @_;
11107: my (@spares,$numspares);
11108: foreach my $lonhost (sort(keys(%servers))) {
11109: next if ($currbalancer eq $lonhost);
11110: push(@spares,$lonhost);
11111: }
11112: if ($currbalancer) {
11113: $numspares = scalar(@spares);
11114: } else {
11115: $numspares = scalar(@spares) - 1;
11116: }
11117: return ($numspares,@spares);
11118: }
11119:
11120: sub lonbalance_targets_js {
1.171 raeburn 11121: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11122: my $select = &mt('Select');
11123: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11124: if (ref($servers) eq 'HASH') {
11125: $alltargets = join("','",sort(keys(%{$servers})));
11126: my @homedoms;
11127: foreach my $server (sort(keys(%{$servers}))) {
11128: if (&Apache::lonnet::host_domain($server) eq $dom) {
11129: push(@homedoms,'1');
11130: } else {
11131: push(@homedoms,'0');
11132: }
11133: }
11134: $allishome = join("','",@homedoms);
11135: }
11136: if (ref($types) eq 'ARRAY') {
11137: if (@{$types} > 0) {
11138: @alltypes = @{$types};
11139: }
11140: }
11141: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11142: $allinsttypes = join("','",@alltypes);
1.171 raeburn 11143: my (%currbalancer,%currtargets,%currrules,%existing);
11144: if (ref($settings) eq 'HASH') {
11145: %existing = %{$settings};
11146: }
11147: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11148: \%currtargets,\%currrules);
1.210 raeburn 11149: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11150: return <<"END";
11151:
11152: <script type="text/javascript">
11153: // <![CDATA[
11154:
1.171 raeburn 11155: currBalancers = new Array('$balancers');
11156:
11157: function toggleTargets(balnum) {
11158: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11159: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11160: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11161: var prevbalancer = prevhostitem.value;
11162: var baltotal = document.getElementById('loadbalancing_total').value;
11163: prevhostitem.value = balancer;
11164: if (prevbalancer != '') {
11165: var prevIdx = currBalancers.indexOf(prevbalancer);
11166: if (prevIdx != -1) {
11167: currBalancers.splice(prevIdx,1);
11168: }
11169: }
1.150 raeburn 11170: if (balancer == '') {
1.171 raeburn 11171: hideSpares(balnum);
1.150 raeburn 11172: } else {
1.171 raeburn 11173: var currIdx = currBalancers.indexOf(balancer);
11174: if (currIdx == -1) {
11175: currBalancers.push(balancer);
11176: }
1.150 raeburn 11177: var homedoms = new Array('$allishome');
1.171 raeburn 11178: var ishomedom = homedoms[lonhostitem.selectedIndex];
11179: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11180: }
1.171 raeburn 11181: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11182: return;
11183: }
11184:
1.171 raeburn 11185: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11186: var alltargets = new Array('$alltargets');
11187: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11188: var offloadtypes = new Array('primary','default');
11189:
1.171 raeburn 11190: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11191: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11192:
1.151 raeburn 11193: for (var i=0; i<offloadtypes.length; i++) {
11194: var count = 0;
11195: for (var j=0; j<alltargets.length; j++) {
11196: if (alltargets[j] != balancer) {
1.171 raeburn 11197: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11198: item.value = alltargets[j];
11199: item.style.textAlign='left';
11200: item.style.textFace='normal';
11201: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11202: if (currBalancers.indexOf(alltargets[j]) == -1) {
11203: item.disabled = '';
11204: } else {
11205: item.disabled = 'disabled';
11206: item.checked = false;
11207: }
1.151 raeburn 11208: count ++;
11209: }
1.150 raeburn 11210: }
11211: }
1.151 raeburn 11212: for (var k=0; k<insttypes.length; k++) {
11213: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11214: if (ishomedom == 1) {
1.171 raeburn 11215: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11216: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11217: } else {
1.171 raeburn 11218: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11219: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11220: }
11221: } else {
1.171 raeburn 11222: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11223: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11224: }
1.151 raeburn 11225: if ((insttypes[k] != '_LC_external') &&
11226: ((insttypes[k] != '_LC_internetdom') ||
11227: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 11228: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11229: item.options.length = 0;
11230: item.options[0] = new Option("","",true,true);
1.210 raeburn 11231: var idx = 0;
1.151 raeburn 11232: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 11233: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11234: idx ++;
11235: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11236: }
11237: }
11238: }
11239: }
11240: return;
11241: }
11242:
1.171 raeburn 11243: function hideSpares(balnum) {
1.150 raeburn 11244: var alltargets = new Array('$alltargets');
11245: var insttypes = new Array('$allinsttypes');
11246: var offloadtypes = new Array('primary','default');
11247:
1.171 raeburn 11248: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11249: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11250:
11251: var total = alltargets.length - 1;
11252: for (var i=0; i<offloadtypes; i++) {
11253: for (var j=0; j<total; j++) {
1.171 raeburn 11254: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11255: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11256: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11257: }
1.150 raeburn 11258: }
11259: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11260: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11261: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11262: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11263: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11264: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11265: }
11266: }
11267: return;
11268: }
11269:
1.171 raeburn 11270: function checkOffloads(item,balnum,type) {
1.150 raeburn 11271: var alltargets = new Array('$alltargets');
11272: var offloadtypes = new Array('primary','default');
11273: if (item.checked) {
11274: var total = alltargets.length - 1;
11275: var other;
11276: if (type == offloadtypes[0]) {
1.151 raeburn 11277: other = offloadtypes[1];
1.150 raeburn 11278: } else {
1.151 raeburn 11279: other = offloadtypes[0];
1.150 raeburn 11280: }
11281: for (var i=0; i<total; i++) {
1.171 raeburn 11282: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11283: if (server == item.value) {
1.171 raeburn 11284: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11285: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11286: }
11287: }
11288: }
11289: }
11290: return;
11291: }
11292:
1.171 raeburn 11293: function singleServerToggle(balnum,type) {
11294: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11295: if (offloadtoSelIdx == 0) {
1.171 raeburn 11296: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11297: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11298:
11299: } else {
1.171 raeburn 11300: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11301: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11302: }
11303: return;
11304: }
11305:
1.171 raeburn 11306: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11307: if (type == '_LC_external') {
1.171 raeburn 11308: return;
1.150 raeburn 11309: }
1.171 raeburn 11310: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11311: for (var i=0; i<typesRules.length; i++) {
11312: if (formname.elements[typesRules[i]].checked) {
11313: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11314: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11315: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11316: } else {
1.171 raeburn 11317: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11318: }
11319: }
11320: }
11321: return;
11322: }
11323:
11324: function balancerDeleteChange(balnum) {
11325: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11326: var baltotal = document.getElementById('loadbalancing_total').value;
11327: var addtarget;
11328: var removetarget;
11329: var action = 'delete';
11330: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11331: var lonhost = hostitem.value;
11332: var currIdx = currBalancers.indexOf(lonhost);
11333: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11334: if (currIdx != -1) {
11335: currBalancers.splice(currIdx,1);
11336: }
11337: addtarget = lonhost;
11338: } else {
11339: if (currIdx == -1) {
11340: currBalancers.push(lonhost);
11341: }
11342: removetarget = lonhost;
11343: action = 'undelete';
11344: }
11345: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11346: }
11347: return;
11348: }
11349:
11350: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11351: if (baltotal > 1) {
11352: var offloadtypes = new Array('primary','default');
11353: var alltargets = new Array('$alltargets');
11354: var insttypes = new Array('$allinsttypes');
11355: for (var i=0; i<baltotal; i++) {
11356: if (i != balnum) {
11357: for (var j=0; j<offloadtypes.length; j++) {
11358: var total = alltargets.length - 1;
11359: for (var k=0; k<total; k++) {
11360: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11361: var server = serveritem.value;
11362: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11363: if (server == addtarget) {
11364: serveritem.disabled = '';
11365: }
11366: }
11367: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11368: if (server == removetarget) {
11369: serveritem.disabled = 'disabled';
11370: serveritem.checked = false;
11371: }
11372: }
11373: }
11374: }
11375: for (var j=0; j<insttypes.length; j++) {
11376: if (insttypes[j] != '_LC_external') {
11377: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11378: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11379: var currSel = singleserver.selectedIndex;
11380: var currVal = singleserver.options[currSel].value;
11381: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11382: var numoptions = singleserver.options.length;
11383: var needsnew = 1;
11384: for (var k=0; k<numoptions; k++) {
11385: if (singleserver.options[k] == addtarget) {
11386: needsnew = 0;
11387: break;
11388: }
11389: }
11390: if (needsnew == 1) {
11391: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11392: }
11393: }
11394: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11395: singleserver.options.length = 0;
11396: if ((currVal) && (currVal != removetarget)) {
11397: singleserver.options[0] = new Option("","",false,false);
11398: } else {
11399: singleserver.options[0] = new Option("","",true,true);
11400: }
11401: var idx = 0;
11402: for (var m=0; m<alltargets.length; m++) {
11403: if (currBalancers.indexOf(alltargets[m]) == -1) {
11404: idx ++;
11405: if (currVal == alltargets[m]) {
11406: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11407: } else {
11408: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11409: }
11410: }
11411: }
11412: }
11413: }
11414: }
11415: }
1.150 raeburn 11416: }
11417: }
11418: }
11419: return;
11420: }
11421:
1.152 raeburn 11422: // ]]>
11423: </script>
11424:
11425: END
11426: }
11427:
11428: sub new_spares_js {
11429: my @sparestypes = ('primary','default');
11430: my $types = join("','",@sparestypes);
11431: my $select = &mt('Select');
11432: return <<"END";
11433:
11434: <script type="text/javascript">
11435: // <![CDATA[
11436:
11437: function updateNewSpares(formname,lonhost) {
11438: var types = new Array('$types');
11439: var include = new Array();
11440: var exclude = new Array();
11441: for (var i=0; i<types.length; i++) {
11442: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11443: for (var j=0; j<spareboxes.length; j++) {
11444: if (formname.elements[spareboxes[j]].checked) {
11445: exclude.push(formname.elements[spareboxes[j]].value);
11446: } else {
11447: include.push(formname.elements[spareboxes[j]].value);
11448: }
11449: }
11450: }
11451: for (var i=0; i<types.length; i++) {
11452: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11453: var selIdx = newSpare.selectedIndex;
11454: var currnew = newSpare.options[selIdx].value;
11455: var okSpares = new Array();
11456: for (var j=0; j<newSpare.options.length; j++) {
11457: var possible = newSpare.options[j].value;
11458: if (possible != '') {
11459: if (exclude.indexOf(possible) == -1) {
11460: okSpares.push(possible);
11461: } else {
11462: if (currnew == possible) {
11463: selIdx = 0;
11464: }
11465: }
11466: }
11467: }
11468: for (var k=0; k<include.length; k++) {
11469: if (okSpares.indexOf(include[k]) == -1) {
11470: okSpares.push(include[k]);
11471: }
11472: }
11473: okSpares.sort();
11474: newSpare.options.length = 0;
11475: if (selIdx == 0) {
11476: newSpare.options[0] = new Option("$select","",true,true);
11477: } else {
11478: newSpare.options[0] = new Option("$select","",false,false);
11479: }
11480: for (var m=0; m<okSpares.length; m++) {
11481: var idx = m+1;
11482: var selThis = 0;
11483: if (selIdx != 0) {
11484: if (okSpares[m] == currnew) {
11485: selThis = 1;
11486: }
11487: }
11488: if (selThis == 1) {
11489: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11490: } else {
11491: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11492: }
11493: }
11494: }
11495: return;
11496: }
11497:
11498: function checkNewSpares(lonhost,type) {
11499: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11500: var chosen = newSpare.options[newSpare.selectedIndex].value;
11501: if (chosen != '') {
11502: var othertype;
11503: var othernewSpare;
11504: if (type == 'primary') {
11505: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11506: }
11507: if (type == 'default') {
11508: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11509: }
11510: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11511: othernewSpare.selectedIndex = 0;
11512: }
11513: }
11514: return;
11515: }
11516:
11517: // ]]>
11518: </script>
11519:
11520: END
11521:
11522: }
11523:
11524: sub common_domprefs_js {
11525: return <<"END";
11526:
11527: <script type="text/javascript">
11528: // <![CDATA[
11529:
1.150 raeburn 11530: function getIndicesByName(formname,item) {
1.152 raeburn 11531: var group = new Array();
1.150 raeburn 11532: for (var i=0;i<formname.elements.length;i++) {
11533: if (formname.elements[i].name == item) {
1.152 raeburn 11534: group.push(formname.elements[i].id);
1.150 raeburn 11535: }
11536: }
1.152 raeburn 11537: return group;
1.150 raeburn 11538: }
11539:
11540: // ]]>
11541: </script>
11542:
11543: END
1.152 raeburn 11544:
1.150 raeburn 11545: }
11546:
1.165 raeburn 11547: sub recaptcha_js {
11548: my %lt = &captcha_phrases();
11549: return <<"END";
11550:
11551: <script type="text/javascript">
11552: // <![CDATA[
11553:
11554: function updateCaptcha(caller,context) {
11555: var privitem;
11556: var pubitem;
11557: var privtext;
11558: var pubtext;
11559: if (document.getElementById(context+'_recaptchapub')) {
11560: pubitem = document.getElementById(context+'_recaptchapub');
11561: } else {
11562: return;
11563: }
11564: if (document.getElementById(context+'_recaptchapriv')) {
11565: privitem = document.getElementById(context+'_recaptchapriv');
11566: } else {
11567: return;
11568: }
11569: if (document.getElementById(context+'_recaptchapubtxt')) {
11570: pubtext = document.getElementById(context+'_recaptchapubtxt');
11571: } else {
11572: return;
11573: }
11574: if (document.getElementById(context+'_recaptchaprivtxt')) {
11575: privtext = document.getElementById(context+'_recaptchaprivtxt');
11576: } else {
11577: return;
11578: }
11579: if (caller.checked) {
11580: if (caller.value == 'recaptcha') {
11581: pubitem.type = 'text';
11582: privitem.type = 'text';
11583: pubitem.size = '40';
11584: privitem.size = '40';
11585: pubtext.innerHTML = "$lt{'pub'}";
11586: privtext.innerHTML = "$lt{'priv'}";
11587: } else {
11588: pubitem.type = 'hidden';
11589: privitem.type = 'hidden';
11590: pubtext.innerHTML = '';
11591: privtext.innerHTML = '';
11592: }
11593: }
11594: return;
11595: }
11596:
11597: // ]]>
11598: </script>
11599:
11600: END
11601:
11602: }
11603:
1.236 raeburn 11604: sub toggle_display_js {
1.192 raeburn 11605: return <<"END";
11606:
11607: <script type="text/javascript">
11608: // <![CDATA[
11609:
1.236 raeburn 11610: function toggleDisplay(domForm,caller) {
11611: if (document.getElementById(caller)) {
11612: var divitem = document.getElementById(caller);
11613: var optionsElement = domForm.coursecredits;
11614: if (caller == 'emailoptions') {
11615: optionsElement = domForm.cancreate_email;
11616: }
11617: if (optionsElement.length) {
1.192 raeburn 11618: var currval;
1.236 raeburn 11619: for (var i=0; i<optionsElement.length; i++) {
11620: if (optionsElement[i].checked) {
11621: currval = optionsElement[i].value;
1.192 raeburn 11622: }
11623: }
11624: if (currval == 1) {
1.236 raeburn 11625: divitem.style.display = 'block';
1.192 raeburn 11626: } else {
1.236 raeburn 11627: divitem.style.display = 'none';
1.192 raeburn 11628: }
11629: }
11630: }
11631: return;
11632: }
11633:
11634: // ]]>
11635: </script>
11636:
11637: END
11638:
11639: }
11640:
1.165 raeburn 11641: sub captcha_phrases {
11642: return &Apache::lonlocal::texthash (
11643: priv => 'Private key',
11644: pub => 'Public key',
11645: original => 'original (CAPTCHA)',
11646: recaptcha => 'successor (ReCAPTCHA)',
11647: notused => 'unused',
11648: );
11649: }
11650:
1.205 raeburn 11651: sub devalidate_remote_domconfs {
1.212 raeburn 11652: my ($dom,$cachekeys) = @_;
11653: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 11654: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11655: my %thismachine;
11656: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 11657: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 11658: if (keys(%servers) > 1) {
11659: foreach my $server (keys(%servers)) {
11660: next if ($thismachine{$server});
1.212 raeburn 11661: my @cached;
11662: foreach my $name (@posscached) {
11663: if ($cachekeys->{$name}) {
11664: push(@cached,&escape($name).':'.&escape($dom));
11665: }
11666: }
11667: if (@cached) {
11668: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11669: }
1.205 raeburn 11670: }
11671: }
11672: return;
11673: }
11674:
1.3 raeburn 11675: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>