Annotation of loncom/interface/domainprefs.pm, revision 1.253
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.253 ! raeburn 4: # $Id: domainprefs.pm,v 1.252 2014/10/04 02:41:44 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')) {
3809: @rulenames = ('balancer','offloadedto');
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.150 raeburn 3871: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3872: '</label>'.$extra.'</span><br />'."\n";
3873: }
3874: $output .= '</div></td></tr>'."\n";
3875: return $output;
3876: }
3877:
3878: sub offloadtype_text {
3879: my %ruletitles = &Apache::lonlocal::texthash (
3880: 'default' => 'Offloads to default destinations',
3881: 'homeserver' => "Offloads to user's home server",
3882: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3883: 'specific' => 'Offloads to specific server',
1.161 raeburn 3884: 'none' => 'No offload',
1.209 raeburn 3885: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3886: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3887: );
3888: return %ruletitles;
3889: }
3890:
3891: sub sparestype_titles {
3892: my %typestitles = &Apache::lonlocal::texthash (
3893: 'primary' => 'primary',
3894: 'default' => 'default',
3895: );
3896: return %typestitles;
3897: }
3898:
1.28 raeburn 3899: sub contact_titles {
3900: my %titles = &Apache::lonlocal::texthash (
3901: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3902: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3903: 'errormail' => 'Error reports to be e-mailed to',
3904: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3905: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3906: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3907: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3908: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3909: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3910: );
3911: my %short_titles = &Apache::lonlocal::texthash (
3912: adminemail => 'Admin E-mail address',
3913: supportemail => 'Support E-mail',
3914: );
3915: return (\%titles,\%short_titles);
3916: }
3917:
1.72 raeburn 3918: sub tool_titles {
3919: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3920: aboutme => 'Personal web page',
1.86 raeburn 3921: blog => 'Blog',
1.162 raeburn 3922: webdav => 'WebDAV',
1.86 raeburn 3923: portfolio => 'Portfolio',
1.88 bisitz 3924: official => 'Official courses (with institutional codes)',
3925: unofficial => 'Unofficial courses',
1.98 raeburn 3926: community => 'Communities',
1.216 raeburn 3927: textbook => 'Textbook courses',
1.86 raeburn 3928: );
1.72 raeburn 3929: return %titles;
3930: }
3931:
1.101 raeburn 3932: sub courserequest_titles {
3933: my %titles = &Apache::lonlocal::texthash (
3934: official => 'Official',
3935: unofficial => 'Unofficial',
3936: community => 'Communities',
1.216 raeburn 3937: textbook => 'Textbook',
1.101 raeburn 3938: norequest => 'Not allowed',
1.104 raeburn 3939: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3940: validate => 'With validation',
3941: autolimit => 'Numerical limit',
1.103 raeburn 3942: unlimited => '(blank for unlimited)',
1.101 raeburn 3943: );
3944: return %titles;
3945: }
3946:
1.163 raeburn 3947: sub authorrequest_titles {
3948: my %titles = &Apache::lonlocal::texthash (
3949: norequest => 'Not allowed',
3950: approval => 'Approval by Dom. Coord.',
3951: automatic => 'Automatic approval',
3952: );
3953: return %titles;
1.210 raeburn 3954: }
1.163 raeburn 3955:
1.101 raeburn 3956: sub courserequest_conditions {
3957: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3958: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3959: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3960: );
3961: return %conditions;
3962: }
3963:
3964:
1.27 raeburn 3965: sub print_usercreation {
1.30 raeburn 3966: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3967: my $numinrow = 4;
1.28 raeburn 3968: my $datatable;
3969: if ($position eq 'top') {
1.30 raeburn 3970: $$rowtotal ++;
1.34 raeburn 3971: my $rowcount = 0;
1.32 raeburn 3972: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3973: if (ref($rules) eq 'HASH') {
3974: if (keys(%{$rules}) > 0) {
1.32 raeburn 3975: $datatable .= &user_formats_row('username',$settings,$rules,
3976: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3977: $$rowtotal ++;
1.32 raeburn 3978: $rowcount ++;
3979: }
3980: }
3981: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3982: if (ref($idrules) eq 'HASH') {
3983: if (keys(%{$idrules}) > 0) {
3984: $datatable .= &user_formats_row('id',$settings,$idrules,
3985: $idruleorder,$numinrow,$rowcount);
3986: $$rowtotal ++;
3987: $rowcount ++;
1.28 raeburn 3988: }
3989: }
1.39 raeburn 3990: if ($rowcount == 0) {
3991: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3992: $$rowtotal ++;
3993: $rowcount ++;
3994: }
1.34 raeburn 3995: } elsif ($position eq 'middle') {
1.224 raeburn 3996: my @creators = ('author','course','requestcrs');
1.37 raeburn 3997: my ($rules,$ruleorder) =
3998: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3999: my %lt = &usercreation_types();
4000: my %checked;
4001: if (ref($settings) eq 'HASH') {
4002: if (ref($settings->{'cancreate'}) eq 'HASH') {
4003: foreach my $item (@creators) {
4004: $checked{$item} = $settings->{'cancreate'}{$item};
4005: }
4006: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4007: foreach my $item (@creators) {
4008: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4009: $checked{$item} = 'none';
4010: }
4011: }
4012: }
4013: }
4014: my $rownum = 0;
4015: foreach my $item (@creators) {
4016: $rownum ++;
1.224 raeburn 4017: if ($checked{$item} eq '') {
4018: $checked{$item} = 'any';
1.34 raeburn 4019: }
4020: my $css_class;
4021: if ($rownum%2) {
4022: $css_class = '';
4023: } else {
4024: $css_class = ' class="LC_odd_row" ';
4025: }
4026: $datatable .= '<tr'.$css_class.'>'.
4027: '<td><span class="LC_nobreak">'.$lt{$item}.
4028: '</span></td><td align="right">';
1.224 raeburn 4029: my @options = ('any');
4030: if (ref($rules) eq 'HASH') {
4031: if (keys(%{$rules}) > 0) {
4032: push(@options,('official','unofficial'));
1.37 raeburn 4033: }
4034: }
1.224 raeburn 4035: push(@options,'none');
1.37 raeburn 4036: foreach my $option (@options) {
1.50 raeburn 4037: my $type = 'radio';
1.34 raeburn 4038: my $check = ' ';
1.224 raeburn 4039: if ($checked{$item} eq $option) {
4040: $check = ' checked="checked" ';
1.34 raeburn 4041: }
4042: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4043: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4044: $item.'" value="'.$option.'"'.$check.'/> '.
4045: $lt{$option}.'</label> </span>';
4046: }
4047: $datatable .= '</td></tr>';
4048: }
1.28 raeburn 4049: } else {
4050: my @contexts = ('author','course','domain');
4051: my @authtypes = ('int','krb4','krb5','loc');
4052: my %checked;
4053: if (ref($settings) eq 'HASH') {
4054: if (ref($settings->{'authtypes'}) eq 'HASH') {
4055: foreach my $item (@contexts) {
4056: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4057: foreach my $auth (@authtypes) {
4058: if ($settings->{'authtypes'}{$item}{$auth}) {
4059: $checked{$item}{$auth} = ' checked="checked" ';
4060: }
4061: }
4062: }
4063: }
1.27 raeburn 4064: }
1.35 raeburn 4065: } else {
4066: foreach my $item (@contexts) {
1.36 raeburn 4067: foreach my $auth (@authtypes) {
1.35 raeburn 4068: $checked{$item}{$auth} = ' checked="checked" ';
4069: }
4070: }
1.27 raeburn 4071: }
1.28 raeburn 4072: my %title = &context_names();
4073: my %authname = &authtype_names();
4074: my $rownum = 0;
4075: my $css_class;
4076: foreach my $item (@contexts) {
4077: if ($rownum%2) {
4078: $css_class = '';
4079: } else {
4080: $css_class = ' class="LC_odd_row" ';
4081: }
1.30 raeburn 4082: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4083: '<td>'.$title{$item}.
4084: '</td><td class="LC_left_item">'.
4085: '<span class="LC_nobreak">';
4086: foreach my $auth (@authtypes) {
4087: $datatable .= '<label>'.
4088: '<input type="checkbox" name="'.$item.'_auth" '.
4089: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4090: $authname{$auth}.'</label> ';
4091: }
4092: $datatable .= '</span></td></tr>';
4093: $rownum ++;
1.27 raeburn 4094: }
1.30 raeburn 4095: $$rowtotal += $rownum;
1.27 raeburn 4096: }
4097: return $datatable;
4098: }
4099:
1.224 raeburn 4100: sub print_selfcreation {
4101: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4102: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4103: if (ref($settings) eq 'HASH') {
4104: if (ref($settings->{'cancreate'}) eq 'HASH') {
4105: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4106: if (ref($createsettings) eq 'HASH') {
4107: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4108: @selfcreate = @{$createsettings->{'selfcreate'}};
4109: } elsif ($createsettings->{'selfcreate'} ne '') {
4110: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4111: @selfcreate = ('email','login','sso');
4112: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4113: @selfcreate = ($createsettings->{'selfcreate'});
4114: }
4115: }
4116: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4117: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4118: }
4119: }
4120: }
4121: }
4122: my %radiohash;
4123: my $numinrow = 4;
4124: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4125: if ($position eq 'top') {
4126: my %choices = &Apache::lonlocal::texthash (
4127: cancreate_login => 'Institutional Login',
4128: cancreate_sso => 'Institutional Single Sign On',
4129: );
4130: my @toggles = sort(keys(%choices));
4131: my %defaultchecked = (
4132: 'cancreate_login' => 'off',
4133: 'cancreate_sso' => 'off',
4134: );
1.228 raeburn 4135: my ($onclick,$itemcount);
1.224 raeburn 4136: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4137: \%choices,$itemcount,$onclick);
1.228 raeburn 4138: $$rowtotal += $itemcount;
4139:
1.224 raeburn 4140: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4141:
4142: if (ref($usertypes) eq 'HASH') {
4143: if (keys(%{$usertypes}) > 0) {
4144: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4145: $dom,$numinrow,$othertitle,
1.228 raeburn 4146: 'statustocreate',$$rowtotal);
1.224 raeburn 4147: $$rowtotal ++;
4148: }
4149: }
1.240 raeburn 4150: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4151: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4152: $fieldtitles{'inststatus'} = &mt('Institutional status');
4153: my $rem;
4154: my $numperrow = 2;
4155: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4156: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4157: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4158: '<td class="LC_left_item">'."\n".
4159: '<table><tr><td>'."\n";
4160: for (my $i=0; $i<@fields; $i++) {
4161: $rem = $i%($numperrow);
4162: if ($rem == 0) {
4163: if ($i > 0) {
4164: $datatable .= '</tr>';
4165: }
4166: $datatable .= '<tr>';
4167: }
4168: my $currval;
1.248 raeburn 4169: if (ref($createsettings) eq 'HASH') {
4170: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4171: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4172: }
1.240 raeburn 4173: }
4174: $datatable .= '<td class="LC_left_item">'.
4175: '<span class="LC_nobreak">'.
4176: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4177: 'value="'.$currval.'" size="10" /> '.
4178: $fieldtitles{$fields[$i]}.'</span></td>';
4179: }
4180: my $colsleft = $numperrow - $rem;
4181: if ($colsleft > 1 ) {
4182: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4183: ' </td>';
4184: } elsif ($colsleft == 1) {
4185: $datatable .= '<td class="LC_left_item"> </td>';
4186: }
4187: $datatable .= '</tr></table></td></tr>';
4188: $$rowtotal ++;
1.224 raeburn 4189: } elsif ($position eq 'middle') {
4190: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4191: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4192: $usertypes->{'default'} = $othertitle;
4193: if (ref($types) eq 'ARRAY') {
4194: push(@{$types},'default');
4195: $usertypes->{'default'} = $othertitle;
4196: foreach my $status (@{$types}) {
4197: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4198: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4199: $$rowtotal ++;
1.224 raeburn 4200: }
4201: }
4202: } else {
1.236 raeburn 4203: my %choices = &Apache::lonlocal::texthash (
4204: cancreate_email => 'E-mail address as username',
4205: );
4206: my @toggles = sort(keys(%choices));
4207: my %defaultchecked = (
4208: 'cancreate_email' => 'off',
4209: );
4210: my $itemcount = 0;
4211: my $display = 'none';
4212: if (grep(/^\Qemail\E$/,@selfcreate)) {
4213: $display = 'block';
4214: }
4215: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4216: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4217: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4218: my $usertypes = {};
4219: my $order = [];
4220: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4221: $usertypes = $domdefaults{'inststatustypes'};
4222: $order = $domdefaults{'inststatusguest'};
4223: }
4224: if (ref($order) eq 'ARRAY') {
4225: push(@{$order},'default');
4226: if (@{$order} > 1) {
4227: $usertypes->{'default'} = &mt('Other users');
4228: $additional .= '<table><tr>';
4229: foreach my $status (@{$order}) {
4230: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4231: }
4232: $additional .= '</tr><tr>';
4233: foreach my $status (@{$order}) {
4234: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4235: }
1.236 raeburn 4236: $additional .= '</tr></table>';
1.224 raeburn 4237: } else {
1.236 raeburn 4238: $usertypes->{'default'} = &mt('All users');
4239: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4240: }
4241: }
1.236 raeburn 4242: $additional .= '</div>'."\n";
4243:
4244: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4245: \%choices,$$rowtotal,$onclick,$additional);
4246: $$rowtotal ++;
1.236 raeburn 4247: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4248: $$rowtotal ++;
1.224 raeburn 4249: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4250: $numinrow = 1;
1.236 raeburn 4251: if (ref($order) eq 'ARRAY') {
4252: foreach my $status (@{$order}) {
1.228 raeburn 4253: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4254: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4255: $$rowtotal ++;
4256: }
4257: }
1.224 raeburn 4258: my ($emailrules,$emailruleorder) =
4259: &Apache::lonnet::inst_userrules($dom,'email');
4260: if (ref($emailrules) eq 'HASH') {
4261: if (keys(%{$emailrules}) > 0) {
4262: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4263: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4264: $$rowtotal ++;
4265: }
4266: }
1.228 raeburn 4267: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4268: }
4269: return $datatable;
4270: }
4271:
1.236 raeburn 4272: sub email_as_username {
4273: my ($rowtotal,$processing,$type) = @_;
4274: my %choices =
4275: &Apache::lonlocal::texthash (
4276: automatic => 'Automatic approval',
4277: approval => 'Queued for approval',
4278: );
4279: my $output;
4280: foreach my $option ('automatic','approval') {
4281: my $checked;
4282: if (ref($processing) eq 'HASH') {
4283: if ($type eq '') {
4284: if (!exists($processing->{'default'})) {
4285: if ($option eq 'automatic') {
4286: $checked = ' checked="checked"';
4287: }
4288: } else {
4289: if ($processing->{'default'} eq $option) {
4290: $checked = ' checked="checked"';
4291: }
4292: }
4293: } else {
4294: if (!exists($processing->{$type})) {
4295: if ($option eq 'automatic') {
4296: $checked = ' checked="checked"';
4297: }
4298: } else {
4299: if ($processing->{$type} eq $option) {
4300: $checked = ' checked="checked"';
4301: }
4302: }
4303: }
4304: } elsif ($option eq 'automatic') {
4305: $checked = ' checked="checked"';
4306: }
4307: my $name = 'cancreate_emailprocess';
4308: if (($type ne '') && ($type ne 'default')) {
4309: $name .= '_'.$type;
4310: }
4311: $output .= '<span class="LC_nobreak"><label>'.
4312: '<input type="radio" name="'.$name.'"'.
4313: $checked.' value="'.$option.'" />'.
4314: $choices{$option}.'</label></span>';
4315: if ($type eq '') {
4316: $output .= ' ';
4317: } else {
4318: $output .= '<br />';
4319: }
4320: }
4321: $$rowtotal ++;
4322: return $output;
4323: }
4324:
1.165 raeburn 4325: sub captcha_choice {
1.169 raeburn 4326: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4327: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4328: my %lt = &captcha_phrases();
4329: $keyentry = 'hidden';
4330: if ($context eq 'cancreate') {
1.224 raeburn 4331: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4332: } elsif ($context eq 'login') {
4333: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4334: }
4335: if (ref($settings) eq 'HASH') {
4336: if ($settings->{'captcha'}) {
4337: $checked{$settings->{'captcha'}} = ' checked="checked"';
4338: } else {
4339: $checked{'original'} = ' checked="checked"';
4340: }
4341: if ($settings->{'captcha'} eq 'recaptcha') {
4342: $pubtext = $lt{'pub'};
4343: $privtext = $lt{'priv'};
4344: $keyentry = 'text';
4345: }
4346: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4347: $currpub = $settings->{'recaptchakeys'}{'public'};
4348: $currpriv = $settings->{'recaptchakeys'}{'private'};
4349: }
4350: } else {
4351: $checked{'original'} = ' checked="checked"';
4352: }
1.169 raeburn 4353: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4354: my $output = '<tr'.$css_class.'>'.
4355: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4356: '<table><tr><td>'."\n";
4357: foreach my $option ('original','recaptcha','notused') {
4358: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4359: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4360: $lt{$option}.'</label></span>';
4361: unless ($option eq 'notused') {
4362: $output .= (' 'x2)."\n";
4363: }
4364: }
4365: #
4366: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4367: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4368: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4369: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4370: #
1.165 raeburn 4371: $output .= '</td></tr>'."\n".
4372: '<tr><td>'."\n".
4373: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4374: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4375: $currpub.'" size="40" /></span><br />'."\n".
4376: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4377: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4378: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4379: '</td></tr>';
4380: return $output;
4381: }
4382:
1.32 raeburn 4383: sub user_formats_row {
4384: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4385: my $output;
4386: my %text = (
4387: 'username' => 'new usernames',
4388: 'id' => 'IDs',
1.45 raeburn 4389: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4390: );
4391: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4392: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4393: '<td><span class="LC_nobreak">';
4394: if ($type eq 'email') {
4395: $output .= &mt("Formats disallowed for $text{$type}: ");
4396: } else {
4397: $output .= &mt("Format rules to check for $text{$type}: ");
4398: }
4399: $output .= '</span></td>'.
4400: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4401: my $rem;
4402: if (ref($ruleorder) eq 'ARRAY') {
4403: for (my $i=0; $i<@{$ruleorder}; $i++) {
4404: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4405: my $rem = $i%($numinrow);
4406: if ($rem == 0) {
4407: if ($i > 0) {
4408: $output .= '</tr>';
4409: }
4410: $output .= '<tr>';
4411: }
4412: my $check = ' ';
1.39 raeburn 4413: if (ref($settings) eq 'HASH') {
4414: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4415: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4416: $check = ' checked="checked" ';
4417: }
1.27 raeburn 4418: }
4419: }
4420: $output .= '<td class="LC_left_item">'.
4421: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4422: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4423: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4424: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4425: }
4426: }
4427: $rem = @{$ruleorder}%($numinrow);
4428: }
4429: my $colsleft = $numinrow - $rem;
4430: if ($colsleft > 1 ) {
4431: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4432: ' </td>';
4433: } elsif ($colsleft == 1) {
4434: $output .= '<td class="LC_left_item"> </td>';
4435: }
4436: $output .= '</tr></table></td></tr>';
4437: return $output;
4438: }
4439:
1.34 raeburn 4440: sub usercreation_types {
4441: my %lt = &Apache::lonlocal::texthash (
4442: author => 'When adding a co-author',
4443: course => 'When adding a user to a course',
1.100 raeburn 4444: requestcrs => 'When requesting a course',
1.34 raeburn 4445: any => 'Any',
4446: official => 'Institutional only ',
4447: unofficial => 'Non-institutional only',
4448: none => 'None',
4449: );
4450: return %lt;
1.48 raeburn 4451: }
1.34 raeburn 4452:
1.224 raeburn 4453: sub selfcreation_types {
4454: my %lt = &Apache::lonlocal::texthash (
4455: selfcreate => 'User creates own account',
4456: any => 'Any',
4457: official => 'Institutional only ',
4458: unofficial => 'Non-institutional only',
4459: email => 'E-mail address',
4460: login => 'Institutional Login',
4461: sso => 'SSO',
4462: );
4463: }
4464:
1.28 raeburn 4465: sub authtype_names {
4466: my %lt = &Apache::lonlocal::texthash(
4467: int => 'Internal',
4468: krb4 => 'Kerberos 4',
4469: krb5 => 'Kerberos 5',
4470: loc => 'Local',
4471: );
4472: return %lt;
4473: }
4474:
4475: sub context_names {
4476: my %context_title = &Apache::lonlocal::texthash(
4477: author => 'Creating users when an Author',
4478: course => 'Creating users when in a course',
4479: domain => 'Creating users when a Domain Coordinator',
4480: );
4481: return %context_title;
4482: }
4483:
1.33 raeburn 4484: sub print_usermodification {
4485: my ($position,$dom,$settings,$rowtotal) = @_;
4486: my $numinrow = 4;
4487: my ($context,$datatable,$rowcount);
4488: if ($position eq 'top') {
4489: $rowcount = 0;
4490: $context = 'author';
4491: foreach my $role ('ca','aa') {
4492: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4493: $numinrow,$rowcount);
4494: $$rowtotal ++;
4495: $rowcount ++;
4496: }
1.230 raeburn 4497: } elsif ($position eq 'bottom') {
1.33 raeburn 4498: $context = 'course';
4499: $rowcount = 0;
4500: foreach my $role ('st','ep','ta','in','cr') {
4501: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4502: $numinrow,$rowcount);
4503: $$rowtotal ++;
4504: $rowcount ++;
4505: }
4506: }
4507: return $datatable;
4508: }
4509:
1.43 raeburn 4510: sub print_defaults {
1.236 raeburn 4511: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4512: my $rownum = 0;
4513: my ($datatable,$css_class);
1.236 raeburn 4514: if ($position eq 'top') {
4515: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4516: 'datelocale_def','portal_def');
4517: my %defaults;
4518: if (ref($settings) eq 'HASH') {
4519: %defaults = %{$settings};
1.43 raeburn 4520: } else {
1.236 raeburn 4521: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4522: foreach my $item (@items) {
4523: $defaults{$item} = $domdefaults{$item};
4524: }
1.43 raeburn 4525: }
1.236 raeburn 4526: my $titles = &defaults_titles($dom);
4527: foreach my $item (@items) {
4528: if ($rownum%2) {
4529: $css_class = '';
4530: } else {
4531: $css_class = ' class="LC_odd_row" ';
4532: }
4533: $datatable .= '<tr'.$css_class.'>'.
4534: '<td><span class="LC_nobreak">'.$titles->{$item}.
4535: '</span></td><td class="LC_right_item" colspan="3">';
4536: if ($item eq 'auth_def') {
4537: my @authtypes = ('internal','krb4','krb5','localauth');
4538: my %shortauth = (
4539: internal => 'int',
4540: krb4 => 'krb4',
4541: krb5 => 'krb5',
4542: localauth => 'loc'
4543: );
4544: my %authnames = &authtype_names();
4545: foreach my $auth (@authtypes) {
4546: my $checked = ' ';
4547: if ($defaults{$item} eq $auth) {
4548: $checked = ' checked="checked" ';
4549: }
4550: $datatable .= '<label><input type="radio" name="'.$item.
4551: '" value="'.$auth.'"'.$checked.'/>'.
4552: $authnames{$shortauth{$auth}}.'</label> ';
4553: }
4554: } elsif ($item eq 'timezone_def') {
4555: my $includeempty = 1;
4556: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4557: } elsif ($item eq 'datelocale_def') {
4558: my $includeempty = 1;
4559: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4560: } elsif ($item eq 'lang_def') {
4561: my %langchoices = &get_languages_hash();
4562: $langchoices{''} = 'No language preference';
4563: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4564: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4565: \%langchoices);
4566: } else {
4567: my $size;
4568: if ($item eq 'portal_def') {
4569: $size = ' size="25"';
4570: }
4571: $datatable .= '<input type="text" name="'.$item.'" value="'.
4572: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4573: }
1.236 raeburn 4574: $datatable .= '</td></tr>';
4575: $rownum ++;
4576: }
4577: } else {
4578: my (%defaults);
4579: if (ref($settings) eq 'HASH') {
4580: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4581: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4582: my $maxnum = @{$settings->{'inststatusorder'}};
4583: for (my $i=0; $i<$maxnum; $i++) {
4584: $css_class = $rownum%2?' class="LC_odd_row"':'';
4585: my $item = $settings->{'inststatusorder'}->[$i];
4586: my $title = $settings->{'inststatustypes'}->{$item};
4587: my $guestok;
4588: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4589: $guestok = 1;
4590: }
4591: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4592: $datatable .= '<tr'.$css_class.'>'.
4593: '<td><span class="LC_nobreak">'.
4594: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4595: for (my $k=0; $k<=$maxnum; $k++) {
4596: my $vpos = $k+1;
4597: my $selstr;
4598: if ($k == $i) {
4599: $selstr = ' selected="selected" ';
4600: }
4601: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4602: }
4603: my ($checkedon,$checkedoff);
4604: $checkedoff = ' checked="checked"';
4605: if ($guestok) {
4606: $checkedon = $checkedoff;
4607: $checkedoff = '';
4608: }
4609: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4610: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4611: &mt('delete').'</span></td>'.
4612: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4613: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4614: '</span></td>'.
4615: '<td class="LC_right_item"><span class="LC_nobreak">'.
4616: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4617: &mt('Yes').'</label>'.(' 'x2).
4618: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4619: &mt('No').'</label></span></td></tr>';
4620: }
4621: $css_class = $rownum%2?' class="LC_odd_row"':'';
4622: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4623: $datatable .= '<tr '.$css_class.'>'.
4624: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4625: for (my $k=0; $k<=$maxnum; $k++) {
4626: my $vpos = $k+1;
4627: my $selstr;
4628: if ($k == $maxnum) {
4629: $selstr = ' selected="selected" ';
4630: }
4631: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4632: }
4633: $datatable .= '</select> '.&mt('Internal ID:').
4634: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4635: ' '.&mt('(new)').
4636: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4637: &mt('Name displayed:').
4638: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4639: '<td class="LC_right_item"><span class="LC_nobreak">'.
4640: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4641: &mt('Yes').'</label>'.(' 'x2).
4642: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4643: &mt('No').'</label></span></td></tr>';
4644: '</tr>'."\n";
4645: $rownum ++;
1.141 raeburn 4646: }
1.43 raeburn 4647: }
4648: }
4649: $$rowtotal += $rownum;
4650: return $datatable;
4651: }
4652:
1.168 raeburn 4653: sub get_languages_hash {
4654: my %langchoices;
4655: foreach my $id (&Apache::loncommon::languageids()) {
4656: my $code = &Apache::loncommon::supportedlanguagecode($id);
4657: if ($code ne '') {
4658: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4659: }
4660: }
4661: return %langchoices;
4662: }
4663:
1.43 raeburn 4664: sub defaults_titles {
1.141 raeburn 4665: my ($dom) = @_;
1.43 raeburn 4666: my %titles = &Apache::lonlocal::texthash (
4667: 'auth_def' => 'Default authentication type',
4668: 'auth_arg_def' => 'Default authentication argument',
4669: 'lang_def' => 'Default language',
1.54 raeburn 4670: 'timezone_def' => 'Default timezone',
1.68 raeburn 4671: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4672: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4673: );
1.141 raeburn 4674: if ($dom) {
4675: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4676: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4677: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4678: $protocol = 'http' if ($protocol ne 'https');
4679: if ($uint_dom) {
4680: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4681: $uint_dom);
4682: }
4683: }
1.43 raeburn 4684: return (\%titles);
4685: }
4686:
1.46 raeburn 4687: sub print_scantronformat {
4688: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4689: my $itemcount = 1;
1.60 raeburn 4690: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4691: %confhash);
1.46 raeburn 4692: my $switchserver = &check_switchserver($dom,$confname);
4693: my %lt = &Apache::lonlocal::texthash (
1.95 www 4694: default => 'Default bubblesheet format file error',
4695: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4696: );
4697: my %scantronfiles = (
4698: default => 'default.tab',
4699: custom => 'custom.tab',
4700: );
4701: foreach my $key (keys(%scantronfiles)) {
4702: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4703: .$scantronfiles{$key};
4704: }
4705: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4706: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4707: if (!$switchserver) {
4708: my $servadm = $r->dir_config('lonAdmEMail');
4709: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4710: if ($configuserok eq 'ok') {
4711: if ($author_ok eq 'ok') {
4712: my %legacyfile = (
4713: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4714: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4715: );
4716: my %md5chk;
4717: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4718: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4719: chomp($md5chk{$type});
1.46 raeburn 4720: }
4721: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4722: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4723: ($scantronurls{$type},my $error) =
1.46 raeburn 4724: &legacy_scantronformat($r,$dom,$confname,
4725: $type,$legacyfile{$type},
4726: $scantronurls{$type},
4727: $scantronfiles{$type});
1.60 raeburn 4728: if ($error ne '') {
4729: $error{$type} = $error;
4730: }
4731: }
4732: if (keys(%error) == 0) {
4733: $is_custom = 1;
4734: $confhash{'scantron'}{'scantronformat'} =
4735: $scantronurls{'custom'};
4736: my $putresult =
4737: &Apache::lonnet::put_dom('configuration',
4738: \%confhash,$dom);
4739: if ($putresult ne 'ok') {
4740: $error{'custom'} =
4741: '<span class="LC_error">'.
4742: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4743: }
1.46 raeburn 4744: }
4745: } else {
1.60 raeburn 4746: ($scantronurls{'default'},my $error) =
1.46 raeburn 4747: &legacy_scantronformat($r,$dom,$confname,
4748: 'default',$legacyfile{'default'},
4749: $scantronurls{'default'},
4750: $scantronfiles{'default'});
1.60 raeburn 4751: if ($error eq '') {
4752: $confhash{'scantron'}{'scantronformat'} = '';
4753: my $putresult =
4754: &Apache::lonnet::put_dom('configuration',
4755: \%confhash,$dom);
4756: if ($putresult ne 'ok') {
4757: $error{'default'} =
4758: '<span class="LC_error">'.
4759: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4760: }
4761: } else {
4762: $error{'default'} = $error;
4763: }
1.46 raeburn 4764: }
4765: }
4766: }
4767: } else {
1.95 www 4768: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4769: }
4770: }
4771: if (ref($settings) eq 'HASH') {
4772: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4773: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4774: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4775: $scantronurl = '';
4776: } else {
4777: $scantronurl = $settings->{'scantronformat'};
4778: }
4779: $is_custom = 1;
4780: } else {
4781: $scantronurl = $scantronurls{'default'};
4782: }
4783: } else {
1.60 raeburn 4784: if ($is_custom) {
4785: $scantronurl = $scantronurls{'custom'};
4786: } else {
4787: $scantronurl = $scantronurls{'default'};
4788: }
1.46 raeburn 4789: }
4790: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4791: $datatable .= '<tr'.$css_class.'>';
4792: if (!$is_custom) {
1.65 raeburn 4793: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4794: '<span class="LC_nobreak">';
1.46 raeburn 4795: if ($scantronurl) {
1.199 raeburn 4796: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4797: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4798: } else {
4799: $datatable = &mt('File unavailable for display');
4800: }
1.65 raeburn 4801: $datatable .= '</span></td>';
1.60 raeburn 4802: if (keys(%error) == 0) {
4803: $datatable .= '<td valign="bottom">';
4804: if (!$switchserver) {
4805: $datatable .= &mt('Upload:').'<br />';
4806: }
4807: } else {
4808: my $errorstr;
4809: foreach my $key (sort(keys(%error))) {
4810: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4811: }
4812: $datatable .= '<td>'.$errorstr;
4813: }
1.46 raeburn 4814: } else {
4815: if (keys(%error) > 0) {
4816: my $errorstr;
4817: foreach my $key (sort(keys(%error))) {
4818: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4819: }
1.60 raeburn 4820: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4821: } elsif ($scantronurl) {
1.199 raeburn 4822: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4823: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4824: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4825: $link.
4826: '<label><input type="checkbox" name="scantronformat_del"'.
4827: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4828: '<td><span class="LC_nobreak"> '.
4829: &mt('Replace:').'</span><br />';
1.46 raeburn 4830: }
4831: }
4832: if (keys(%error) == 0) {
4833: if ($switchserver) {
4834: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4835: } else {
1.65 raeburn 4836: $datatable .='<span class="LC_nobreak"> '.
4837: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4838: }
4839: }
4840: $datatable .= '</td></tr>';
4841: $$rowtotal ++;
4842: return $datatable;
4843: }
4844:
4845: sub legacy_scantronformat {
4846: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4847: my ($url,$error);
4848: my @statinfo = &Apache::lonnet::stat_file($newurl);
4849: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4850: (my $result,$url) =
4851: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4852: '','',$newfile);
4853: if ($result ne 'ok') {
1.130 raeburn 4854: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4855: }
4856: }
4857: return ($url,$error);
4858: }
1.43 raeburn 4859:
1.49 raeburn 4860: sub print_coursecategories {
1.57 raeburn 4861: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4862: my $datatable;
4863: if ($position eq 'top') {
1.238 raeburn 4864: my (%checked);
4865: my @catitems = ('unauth','auth');
4866: my @cattypes = ('std','domonly','codesrch','none');
4867: $checked{'unauth'} = 'std';
4868: $checked{'auth'} = 'std';
4869: if (ref($settings) eq 'HASH') {
4870: foreach my $type (@cattypes) {
4871: if ($type eq $settings->{'unauth'}) {
4872: $checked{'unauth'} = $type;
4873: }
4874: if ($type eq $settings->{'auth'}) {
4875: $checked{'auth'} = $type;
4876: }
4877: }
4878: }
4879: my %lt = &Apache::lonlocal::texthash (
4880: unauth => 'Catalog type for unauthenticated users',
4881: auth => 'Catalog type for authenticated users',
4882: none => 'No catalog',
4883: std => 'Standard catalog',
4884: domonly => 'Domain-only catalog',
4885: codesrch => "Code search form",
4886: );
4887: my $itemcount = 0;
4888: foreach my $item (@catitems) {
4889: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4890: $datatable .= '<tr '.$css_class.'>'.
4891: '<td>'.$lt{$item}.'</td>'.
4892: '<td class="LC_right_item"><span class="LC_nobreak">';
4893: foreach my $type (@cattypes) {
4894: my $ischecked;
4895: if ($checked{$item} eq $type) {
4896: $ischecked=' checked="checked"';
4897: }
4898: $datatable .= '<label>'.
4899: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4900: ' />'.$lt{$type}.'</label> ';
4901: }
4902: $datatable .= '</td></tr>';
4903: $itemcount ++;
4904: }
4905: $$rowtotal += $itemcount;
4906: } elsif ($position eq 'middle') {
1.57 raeburn 4907: my $toggle_cats_crs = ' ';
4908: my $toggle_cats_dom = ' checked="checked" ';
4909: my $can_cat_crs = ' ';
4910: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4911: my $toggle_catscomm_comm = ' ';
4912: my $toggle_catscomm_dom = ' checked="checked" ';
4913: my $can_catcomm_comm = ' ';
4914: my $can_catcomm_dom = ' checked="checked" ';
4915:
1.57 raeburn 4916: if (ref($settings) eq 'HASH') {
4917: if ($settings->{'togglecats'} eq 'crs') {
4918: $toggle_cats_crs = $toggle_cats_dom;
4919: $toggle_cats_dom = ' ';
4920: }
4921: if ($settings->{'categorize'} eq 'crs') {
4922: $can_cat_crs = $can_cat_dom;
4923: $can_cat_dom = ' ';
4924: }
1.120 raeburn 4925: if ($settings->{'togglecatscomm'} eq 'comm') {
4926: $toggle_catscomm_comm = $toggle_catscomm_dom;
4927: $toggle_catscomm_dom = ' ';
4928: }
4929: if ($settings->{'categorizecomm'} eq 'comm') {
4930: $can_catcomm_comm = $can_catcomm_dom;
4931: $can_catcomm_dom = ' ';
4932: }
1.57 raeburn 4933: }
4934: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4935: togglecats => 'Show/Hide a course in catalog',
4936: togglecatscomm => 'Show/Hide a community in catalog',
4937: categorize => 'Assign a category to a course',
4938: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4939: );
4940: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4941: dom => 'Set in Domain',
4942: crs => 'Set in Course',
4943: comm => 'Set in Community',
1.57 raeburn 4944: );
4945: $datatable = '<tr class="LC_odd_row">'.
4946: '<td>'.$title{'togglecats'}.'</td>'.
4947: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4948: '<input type="radio" name="togglecats"'.
4949: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4950: '<label><input type="radio" name="togglecats"'.
4951: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4952: '</tr><tr>'.
4953: '<td>'.$title{'categorize'}.'</td>'.
4954: '<td class="LC_right_item"><span class="LC_nobreak">'.
4955: '<label><input type="radio" name="categorize"'.
4956: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4957: '<label><input type="radio" name="categorize"'.
4958: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4959: '</tr><tr class="LC_odd_row">'.
4960: '<td>'.$title{'togglecatscomm'}.'</td>'.
4961: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4962: '<input type="radio" name="togglecatscomm"'.
4963: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4964: '<label><input type="radio" name="togglecatscomm"'.
4965: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4966: '</tr><tr>'.
4967: '<td>'.$title{'categorizecomm'}.'</td>'.
4968: '<td class="LC_right_item"><span class="LC_nobreak">'.
4969: '<label><input type="radio" name="categorizecomm"'.
4970: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4971: '<label><input type="radio" name="categorizecomm"'.
4972: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4973: '</tr>';
1.120 raeburn 4974: $$rowtotal += 4;
1.57 raeburn 4975: } else {
4976: my $css_class;
4977: my $itemcount = 1;
4978: my $cathash;
4979: if (ref($settings) eq 'HASH') {
4980: $cathash = $settings->{'cats'};
4981: }
4982: if (ref($cathash) eq 'HASH') {
4983: my (@cats,@trails,%allitems,%idx,@jsarray);
4984: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4985: \%allitems,\%idx,\@jsarray);
4986: my $maxdepth = scalar(@cats);
4987: my $colattrib = '';
4988: if ($maxdepth > 2) {
4989: $colattrib = ' colspan="2" ';
4990: }
4991: my @path;
4992: if (@cats > 0) {
4993: if (ref($cats[0]) eq 'ARRAY') {
4994: my $numtop = @{$cats[0]};
4995: my $maxnum = $numtop;
1.120 raeburn 4996: my %default_names = (
4997: instcode => &mt('Official courses'),
4998: communities => &mt('Communities'),
4999: );
5000:
5001: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5002: ($cathash->{'instcode::0'} eq '') ||
5003: (!grep(/^communities$/,@{$cats[0]})) ||
5004: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5005: $maxnum ++;
5006: }
5007: my $lastidx;
5008: for (my $i=0; $i<$numtop; $i++) {
5009: my $parent = $cats[0][$i];
5010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5011: my $item = &escape($parent).'::0';
5012: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5013: $lastidx = $idx{$item};
5014: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5015: .'<select name="'.$item.'"'.$chgstr.'>';
5016: for (my $k=0; $k<=$maxnum; $k++) {
5017: my $vpos = $k+1;
5018: my $selstr;
5019: if ($k == $i) {
5020: $selstr = ' selected="selected" ';
5021: }
5022: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5023: }
1.214 raeburn 5024: $datatable .= '</select></span></td><td>';
1.120 raeburn 5025: if ($parent eq 'instcode' || $parent eq 'communities') {
5026: $datatable .= '<span class="LC_nobreak">'
5027: .$default_names{$parent}.'</span>';
5028: if ($parent eq 'instcode') {
5029: $datatable .= '<br /><span class="LC_nobreak">('
5030: .&mt('with institutional codes')
5031: .')</span></td><td'.$colattrib.'>';
5032: } else {
5033: $datatable .= '<table><tr><td>';
5034: }
5035: $datatable .= '<span class="LC_nobreak">'
5036: .'<label><input type="radio" name="'
5037: .$parent.'" value="1" checked="checked" />'
5038: .&mt('Display').'</label>';
5039: if ($parent eq 'instcode') {
5040: $datatable .= ' ';
5041: } else {
5042: $datatable .= '</span></td></tr><tr><td>'
5043: .'<span class="LC_nobreak">';
5044: }
5045: $datatable .= '<label><input type="radio" name="'
5046: .$parent.'" value="0" />'
5047: .&mt('Do not display').'</label></span>';
5048: if ($parent eq 'communities') {
5049: $datatable .= '</td></tr></table>';
5050: }
5051: $datatable .= '</td>';
1.57 raeburn 5052: } else {
5053: $datatable .= $parent
1.214 raeburn 5054: .' <span class="LC_nobreak"><label>'
5055: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5056: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5057: }
5058: my $depth = 1;
5059: push(@path,$parent);
5060: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5061: pop(@path);
5062: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5063: $itemcount ++;
5064: }
1.48 raeburn 5065: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5066: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5067: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5068: for (my $k=0; $k<=$maxnum; $k++) {
5069: my $vpos = $k+1;
5070: my $selstr;
1.57 raeburn 5071: if ($k == $numtop) {
1.48 raeburn 5072: $selstr = ' selected="selected" ';
5073: }
5074: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5075: }
1.59 bisitz 5076: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5077: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5078: .'</tr>'."\n";
1.48 raeburn 5079: $itemcount ++;
1.120 raeburn 5080: foreach my $default ('instcode','communities') {
5081: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5082: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5083: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5084: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5085: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5086: for (my $k=0; $k<=$maxnum; $k++) {
5087: my $vpos = $k+1;
5088: my $selstr;
5089: if ($k == $maxnum) {
5090: $selstr = ' selected="selected" ';
5091: }
5092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5093: }
1.120 raeburn 5094: $datatable .= '</select></span></td>'.
5095: '<td><span class="LC_nobreak">'.
5096: $default_names{$default}.'</span>';
5097: if ($default eq 'instcode') {
5098: $datatable .= '<br /><span class="LC_nobreak">('
5099: .&mt('with institutional codes').')</span>';
5100: }
5101: $datatable .= '</td>'
5102: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5103: .&mt('Display').'</label> '
5104: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5105: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5106: }
5107: }
5108: }
1.57 raeburn 5109: } else {
5110: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5111: }
5112: } else {
1.238 raeburn 5113: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5114: .&initialize_categories($itemcount);
1.48 raeburn 5115: }
1.57 raeburn 5116: $$rowtotal += $itemcount;
1.48 raeburn 5117: }
5118: return $datatable;
5119: }
5120:
1.69 raeburn 5121: sub print_serverstatuses {
5122: my ($dom,$settings,$rowtotal) = @_;
5123: my $datatable;
5124: my @pages = &serverstatus_pages();
5125: my (%namedaccess,%machineaccess);
5126: foreach my $type (@pages) {
5127: $namedaccess{$type} = '';
5128: $machineaccess{$type}= '';
5129: }
5130: if (ref($settings) eq 'HASH') {
5131: foreach my $type (@pages) {
5132: if (exists($settings->{$type})) {
5133: if (ref($settings->{$type}) eq 'HASH') {
5134: foreach my $key (keys(%{$settings->{$type}})) {
5135: if ($key eq 'namedusers') {
5136: $namedaccess{$type} = $settings->{$type}->{$key};
5137: } elsif ($key eq 'machines') {
5138: $machineaccess{$type} = $settings->{$type}->{$key};
5139: }
5140: }
5141: }
5142: }
5143: }
5144: }
1.81 raeburn 5145: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5146: my $rownum = 0;
5147: my $css_class;
5148: foreach my $type (@pages) {
5149: $rownum ++;
5150: $css_class = $rownum%2?' class="LC_odd_row"':'';
5151: $datatable .= '<tr'.$css_class.'>'.
5152: '<td><span class="LC_nobreak">'.
5153: $titles->{$type}.'</span></td>'.
5154: '<td class="LC_left_item">'.
5155: '<input type="text" name="'.$type.'_namedusers" '.
5156: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5157: '<td class="LC_right_item">'.
5158: '<span class="LC_nobreak">'.
5159: '<input type="text" name="'.$type.'_machines" '.
5160: 'value="'.$machineaccess{$type}.'" size="10" />'.
5161: '</td></tr>'."\n";
5162: }
5163: $$rowtotal += $rownum;
5164: return $datatable;
5165: }
5166:
5167: sub serverstatus_pages {
5168: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5169: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5170: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5171: 'uniquecodes','diskusage');
1.69 raeburn 5172: }
5173:
1.236 raeburn 5174: sub defaults_javascript {
5175: my ($settings) = @_;
1.248 raeburn 5176: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5177: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5178: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5179: if ($maxnum eq '') {
5180: $maxnum = 0;
5181: }
5182: $maxnum ++;
1.249 raeburn 5183: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5184: return <<"ENDSCRIPT";
5185: <script type="text/javascript">
5186: // <![CDATA[
5187: function reorderTypes(form,caller) {
5188: var changedVal;
5189: $jstext
5190: var newpos = 'addinststatus_pos';
5191: var current = new Array;
5192: var maxh = $maxnum;
5193: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5194: var oldVal;
5195: if (caller == newpos) {
5196: changedVal = newitemVal;
5197: } else {
5198: var curritem = 'inststatus_pos_'+caller;
5199: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5200: current[newitemVal] = newpos;
5201: }
5202: for (var i=0; i<inststatuses.length; i++) {
5203: if (inststatuses[i] != caller) {
5204: var elementName = 'inststatus_pos_'+inststatuses[i];
5205: if (form.elements[elementName]) {
5206: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5207: current[currVal] = elementName;
5208: }
5209: }
5210: }
5211: for (var j=0; j<maxh; j++) {
5212: if (current[j] == undefined) {
5213: oldVal = j;
5214: }
5215: }
5216: if (oldVal < changedVal) {
5217: for (var k=oldVal+1; k<=changedVal ; k++) {
5218: var elementName = current[k];
5219: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5220: }
5221: } else {
5222: for (var k=changedVal; k<oldVal; k++) {
5223: var elementName = current[k];
5224: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5225: }
5226: }
5227: return;
5228: }
5229:
5230: // ]]>
5231: </script>
5232:
5233: ENDSCRIPT
5234: }
5235: }
5236:
1.49 raeburn 5237: sub coursecategories_javascript {
5238: my ($settings) = @_;
1.57 raeburn 5239: my ($output,$jstext,$cathash);
1.49 raeburn 5240: if (ref($settings) eq 'HASH') {
1.57 raeburn 5241: $cathash = $settings->{'cats'};
5242: }
5243: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5244: my (@cats,@jsarray,%idx);
1.57 raeburn 5245: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5246: if (@jsarray > 0) {
5247: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5248: for (my $i=0; $i<@jsarray; $i++) {
5249: if (ref($jsarray[$i]) eq 'ARRAY') {
5250: my $catstr = join('","',@{$jsarray[$i]});
5251: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5252: }
5253: }
5254: }
5255: } else {
5256: $jstext = ' var categories = Array(1);'."\n".
5257: ' categories[0] = Array("instcode_pos");'."\n";
5258: }
1.237 bisitz 5259: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5260: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5261: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5262: $output = <<"ENDSCRIPT";
5263: <script type="text/javascript">
1.109 raeburn 5264: // <![CDATA[
1.49 raeburn 5265: function reorderCats(form,parent,item,idx) {
5266: var changedVal;
5267: $jstext
5268: var newpos = 'addcategory_pos';
5269: if (parent == '') {
5270: var has_instcode = 0;
5271: var maxtop = categories[idx].length;
5272: for (var j=0; j<maxtop; j++) {
5273: if (categories[idx][j] == 'instcode::0') {
5274: has_instcode == 1;
5275: }
5276: }
5277: if (has_instcode == 0) {
5278: categories[idx][maxtop] = 'instcode_pos';
5279: }
5280: } else {
5281: newpos += '_'+parent;
5282: }
5283: var maxh = 1 + categories[idx].length;
5284: var current = new Array;
5285: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5286: if (item == newpos) {
5287: changedVal = newitemVal;
5288: } else {
5289: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5290: current[newitemVal] = newpos;
5291: }
5292: for (var i=0; i<categories[idx].length; i++) {
5293: var elementName = categories[idx][i];
5294: if (elementName != item) {
5295: if (form.elements[elementName]) {
5296: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5297: current[currVal] = elementName;
5298: }
5299: }
5300: }
5301: var oldVal;
5302: for (var j=0; j<maxh; j++) {
5303: if (current[j] == undefined) {
5304: oldVal = j;
5305: }
5306: }
5307: if (oldVal < changedVal) {
5308: for (var k=oldVal+1; k<=changedVal ; k++) {
5309: var elementName = current[k];
5310: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5311: }
5312: } else {
5313: for (var k=changedVal; k<oldVal; k++) {
5314: var elementName = current[k];
5315: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5316: }
5317: }
5318: return;
5319: }
1.120 raeburn 5320:
5321: function categoryCheck(form) {
5322: if (form.elements['addcategory_name'].value == 'instcode') {
5323: alert('$instcode_reserved\\n$choose_again');
5324: return false;
5325: }
5326: if (form.elements['addcategory_name'].value == 'communities') {
5327: alert('$communities_reserved\\n$choose_again');
5328: return false;
5329: }
5330: return true;
5331: }
5332:
1.109 raeburn 5333: // ]]>
1.49 raeburn 5334: </script>
5335:
5336: ENDSCRIPT
5337: return $output;
5338: }
5339:
1.48 raeburn 5340: sub initialize_categories {
5341: my ($itemcount) = @_;
1.120 raeburn 5342: my ($datatable,$css_class,$chgstr);
5343: my %default_names = (
5344: instcode => 'Official courses (with institutional codes)',
5345: communities => 'Communities',
5346: );
5347: my $select0 = ' selected="selected"';
5348: my $select1 = '';
5349: foreach my $default ('instcode','communities') {
5350: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5351: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5352: if ($default eq 'communities') {
5353: $select1 = $select0;
5354: $select0 = '';
5355: }
5356: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5357: .'<select name="'.$default.'_pos">'
5358: .'<option value="0"'.$select0.'>1</option>'
5359: .'<option value="1"'.$select1.'>2</option>'
5360: .'<option value="2">3</option></select> '
5361: .$default_names{$default}
5362: .'</span></td><td><span class="LC_nobreak">'
5363: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5364: .&mt('Display').'</label> <label>'
5365: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5366: .'</label></span></td></tr>';
1.120 raeburn 5367: $itemcount ++;
5368: }
1.48 raeburn 5369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5370: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5371: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5372: .'<select name="addcategory_pos"'.$chgstr.'>'
5373: .'<option value="0">1</option>'
5374: .'<option value="1">2</option>'
5375: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5376: .&mt('Add category').'</td><td>'.&mt('Name:')
5377: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5378: return $datatable;
5379: }
5380:
5381: sub build_category_rows {
1.49 raeburn 5382: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5383: my ($text,$name,$item,$chgstr);
1.48 raeburn 5384: if (ref($cats) eq 'ARRAY') {
5385: my $maxdepth = scalar(@{$cats});
5386: if (ref($cats->[$depth]) eq 'HASH') {
5387: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5388: my $numchildren = @{$cats->[$depth]{$parent}};
5389: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5390: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5391: my ($idxnum,$parent_name,$parent_item);
5392: my $higher = $depth - 1;
5393: if ($higher == 0) {
5394: $parent_name = &escape($parent).'::'.$higher;
5395: } else {
5396: if (ref($path) eq 'ARRAY') {
5397: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5398: }
5399: }
5400: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5401: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5402: if ($j < $numchildren) {
1.48 raeburn 5403: $name = $cats->[$depth]{$parent}[$j];
5404: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5405: $idxnum = $idx->{$item};
5406: } else {
5407: $name = $parent_name;
5408: $item = $parent_item;
1.48 raeburn 5409: }
1.49 raeburn 5410: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5411: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5412: for (my $i=0; $i<=$numchildren; $i++) {
5413: my $vpos = $i+1;
5414: my $selstr;
5415: if ($j == $i) {
5416: $selstr = ' selected="selected" ';
5417: }
5418: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5419: }
5420: $text .= '</select> ';
5421: if ($j < $numchildren) {
5422: my $deeper = $depth+1;
5423: $text .= $name.' '
5424: .'<label><input type="checkbox" name="deletecategory" value="'
5425: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5426: if(ref($path) eq 'ARRAY') {
5427: push(@{$path},$name);
1.49 raeburn 5428: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5429: pop(@{$path});
5430: }
5431: } else {
1.59 bisitz 5432: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5433: if ($j == $numchildren) {
5434: $text .= $name;
5435: } else {
5436: $text .= $item;
5437: }
5438: $text .= '" value="" />';
5439: }
5440: $text .= '</td></tr>';
5441: }
5442: $text .= '</table></td>';
5443: } else {
5444: my $higher = $depth-1;
5445: if ($higher == 0) {
5446: $name = &escape($parent).'::'.$higher;
5447: } else {
5448: if (ref($path) eq 'ARRAY') {
5449: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5450: }
5451: }
5452: my $colspan;
5453: if ($parent ne 'instcode') {
5454: $colspan = $maxdepth - $depth - 1;
5455: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5456: }
5457: }
5458: }
5459: }
5460: return $text;
5461: }
5462:
1.33 raeburn 5463: sub modifiable_userdata_row {
1.228 raeburn 5464: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5465: my ($role,$rolename,$statustype);
5466: $role = $item;
1.224 raeburn 5467: if ($context eq 'cancreate') {
1.228 raeburn 5468: if ($item =~ /^emailusername_(.+)$/) {
5469: $statustype = $1;
5470: $role = 'emailusername';
5471: if (ref($usertypes) eq 'HASH') {
5472: if ($usertypes->{$statustype}) {
5473: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5474: } else {
5475: $rolename = &mt('Data provided by user');
5476: }
5477: }
1.224 raeburn 5478: }
5479: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5480: if (ref($usertypes) eq 'HASH') {
5481: $rolename = $usertypes->{$role};
5482: } else {
5483: $rolename = $role;
5484: }
1.33 raeburn 5485: } else {
1.63 raeburn 5486: if ($role eq 'cr') {
5487: $rolename = &mt('Custom role');
5488: } else {
5489: $rolename = &Apache::lonnet::plaintext($role);
5490: }
1.33 raeburn 5491: }
1.224 raeburn 5492: my (@fields,%fieldtitles);
5493: if (ref($fieldsref) eq 'ARRAY') {
5494: @fields = @{$fieldsref};
5495: } else {
5496: @fields = ('lastname','firstname','middlename','generation',
5497: 'permanentemail','id');
5498: }
5499: if ((ref($titlesref) eq 'HASH')) {
5500: %fieldtitles = %{$titlesref};
5501: } else {
5502: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5503: }
1.33 raeburn 5504: my $output;
5505: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5506: $output = '<tr '.$css_class.'>'.
5507: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5508: '<td class="LC_left_item" colspan="2"><table>';
5509: my $rem;
5510: my %checks;
5511: if (ref($settings) eq 'HASH') {
5512: if (ref($settings->{$context}) eq 'HASH') {
5513: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5514: my $hashref = $settings->{$context}->{$role};
5515: if ($role eq 'emailusername') {
5516: if ($statustype) {
5517: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5518: $hashref = $settings->{$context}->{$role}->{$statustype};
5519: if (ref($hashref) eq 'HASH') {
5520: foreach my $field (@fields) {
5521: if ($hashref->{$field}) {
5522: $checks{$field} = $hashref->{$field};
5523: }
5524: }
5525: }
5526: }
5527: }
5528: } else {
5529: if (ref($hashref) eq 'HASH') {
5530: foreach my $field (@fields) {
5531: if ($hashref->{$field}) {
5532: $checks{$field} = ' checked="checked" ';
5533: }
5534: }
1.33 raeburn 5535: }
5536: }
5537: }
5538: }
5539: }
1.228 raeburn 5540:
1.33 raeburn 5541: for (my $i=0; $i<@fields; $i++) {
5542: my $rem = $i%($numinrow);
5543: if ($rem == 0) {
5544: if ($i > 0) {
5545: $output .= '</tr>';
5546: }
5547: $output .= '<tr>';
5548: }
5549: my $check = ' ';
1.228 raeburn 5550: unless ($role eq 'emailusername') {
5551: if (exists($checks{$fields[$i]})) {
5552: $check = $checks{$fields[$i]}
5553: } else {
5554: if ($role eq 'st') {
5555: if (ref($settings) ne 'HASH') {
5556: $check = ' checked="checked" ';
5557: }
1.33 raeburn 5558: }
5559: }
5560: }
5561: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5562: '<span class="LC_nobreak">';
5563: if ($role eq 'emailusername') {
5564: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5565: $checks{$fields[$i]} = 'omit';
5566: }
5567: foreach my $option ('required','optional','omit') {
5568: my $checked='';
5569: if ($checks{$fields[$i]} eq $option) {
5570: $checked='checked="checked" ';
5571: }
5572: $output .= '<label>'.
5573: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5574: &mt($option).'</label>'.(' ' x2);
5575: }
5576: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5577: } else {
5578: $output .= '<label>'.
5579: '<input type="checkbox" name="canmodify_'.$role.'" '.
5580: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5581: '</label>';
5582: }
5583: $output .= '</span></td>';
1.33 raeburn 5584: $rem = @fields%($numinrow);
5585: }
5586: my $colsleft = $numinrow - $rem;
5587: if ($colsleft > 1 ) {
5588: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5589: ' </td>';
5590: } elsif ($colsleft == 1) {
5591: $output .= '<td class="LC_left_item"> </td>';
5592: }
5593: $output .= '</tr></table></td></tr>';
5594: return $output;
5595: }
1.28 raeburn 5596:
1.93 raeburn 5597: sub insttypes_row {
1.224 raeburn 5598: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5599: my %lt = &Apache::lonlocal::texthash (
5600: cansearch => 'Users allowed to search',
5601: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5602: lockablenames => 'User preference to lock name',
1.93 raeburn 5603: );
5604: my $showdom;
5605: if ($context eq 'cansearch') {
5606: $showdom = ' ('.$dom.')';
5607: }
1.165 raeburn 5608: my $class = 'LC_left_item';
5609: if ($context eq 'statustocreate') {
5610: $class = 'LC_right_item';
5611: }
1.224 raeburn 5612: my $css_class = ' class="LC_odd_row"';
5613: if ($rownum ne '') {
5614: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5615: }
5616: my $output = '<tr'.$css_class.'>'.
5617: '<td>'.$lt{$context}.$showdom.
5618: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5619: my $rem;
5620: if (ref($types) eq 'ARRAY') {
5621: for (my $i=0; $i<@{$types}; $i++) {
5622: if (defined($usertypes->{$types->[$i]})) {
5623: my $rem = $i%($numinrow);
5624: if ($rem == 0) {
5625: if ($i > 0) {
5626: $output .= '</tr>';
5627: }
5628: $output .= '<tr>';
1.23 raeburn 5629: }
1.26 raeburn 5630: my $check = ' ';
1.99 raeburn 5631: if (ref($settings) eq 'HASH') {
5632: if (ref($settings->{$context}) eq 'ARRAY') {
5633: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5634: $check = ' checked="checked" ';
5635: }
5636: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5637: $check = ' checked="checked" ';
5638: }
1.23 raeburn 5639: }
1.26 raeburn 5640: $output .= '<td class="LC_left_item">'.
5641: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5642: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5643: 'value="'.$types->[$i].'"'.$check.'/>'.
5644: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5645: }
5646: }
1.26 raeburn 5647: $rem = @{$types}%($numinrow);
1.23 raeburn 5648: }
5649: my $colsleft = $numinrow - $rem;
1.131 raeburn 5650: if (($rem == 0) && (@{$types} > 0)) {
5651: $output .= '<tr>';
5652: }
1.23 raeburn 5653: if ($colsleft > 1) {
1.25 raeburn 5654: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5655: } else {
1.25 raeburn 5656: $output .= '<td class="LC_left_item">';
1.23 raeburn 5657: }
5658: my $defcheck = ' ';
1.99 raeburn 5659: if (ref($settings) eq 'HASH') {
5660: if (ref($settings->{$context}) eq 'ARRAY') {
5661: if (grep(/^default$/,@{$settings->{$context}})) {
5662: $defcheck = ' checked="checked" ';
5663: }
5664: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5665: $defcheck = ' checked="checked" ';
5666: }
1.23 raeburn 5667: }
1.25 raeburn 5668: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5669: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5670: 'value="default"'.$defcheck.'/>'.
5671: $othertitle.'</label></span></td>'.
5672: '</tr></table></td></tr>';
5673: return $output;
1.23 raeburn 5674: }
5675:
5676: sub sorted_searchtitles {
5677: my %searchtitles = &Apache::lonlocal::texthash(
5678: 'uname' => 'username',
5679: 'lastname' => 'last name',
5680: 'lastfirst' => 'last name, first name',
5681: );
5682: my @titleorder = ('uname','lastname','lastfirst');
5683: return (\%searchtitles,\@titleorder);
5684: }
5685:
1.25 raeburn 5686: sub sorted_searchtypes {
5687: my %srchtypes_desc = (
5688: exact => 'is exact match',
5689: contains => 'contains ..',
5690: begins => 'begins with ..',
5691: );
5692: my @srchtypeorder = ('exact','begins','contains');
5693: return (\%srchtypes_desc,\@srchtypeorder);
5694: }
5695:
1.3 raeburn 5696: sub usertype_update_row {
5697: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5698: my $datatable;
5699: my $numinrow = 4;
5700: foreach my $type (@{$types}) {
5701: if (defined($usertypes->{$type})) {
5702: $$rownums ++;
5703: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5704: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5705: '</td><td class="LC_left_item"><table>';
5706: for (my $i=0; $i<@{$fields}; $i++) {
5707: my $rem = $i%($numinrow);
5708: if ($rem == 0) {
5709: if ($i > 0) {
5710: $datatable .= '</tr>';
5711: }
5712: $datatable .= '<tr>';
5713: }
5714: my $check = ' ';
1.39 raeburn 5715: if (ref($settings) eq 'HASH') {
5716: if (ref($settings->{'fields'}) eq 'HASH') {
5717: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5718: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5719: $check = ' checked="checked" ';
5720: }
1.3 raeburn 5721: }
5722: }
5723: }
5724:
5725: if ($i == @{$fields}-1) {
5726: my $colsleft = $numinrow - $rem;
5727: if ($colsleft > 1) {
5728: $datatable .= '<td colspan="'.$colsleft.'">';
5729: } else {
5730: $datatable .= '<td>';
5731: }
5732: } else {
5733: $datatable .= '<td>';
5734: }
1.8 raeburn 5735: $datatable .= '<span class="LC_nobreak"><label>'.
5736: '<input type="checkbox" name="updateable_'.$type.
5737: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5738: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5739: }
5740: $datatable .= '</tr></table></td></tr>';
5741: }
5742: }
5743: return $datatable;
1.1 raeburn 5744: }
5745:
5746: sub modify_login {
1.205 raeburn 5747: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5748: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5749: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5750: %title = ( coursecatalog => 'Display course catalog',
5751: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5752: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5753: newuser => 'Link for visitors to create a user account',
5754: loginheader => 'Log-in box header');
5755: @offon = ('off','on');
1.112 raeburn 5756: if (ref($domconfig{login}) eq 'HASH') {
5757: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5758: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5759: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5760: }
5761: }
5762: }
1.9 raeburn 5763: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5764: \%domconfig,\%loginhash);
1.188 raeburn 5765: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5766: foreach my $item (@toggles) {
5767: $loginhash{login}{$item} = $env{'form.'.$item};
5768: }
1.41 raeburn 5769: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5770: if (ref($colchanges{'login'}) eq 'HASH') {
5771: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5772: \%loginhash);
5773: }
1.110 raeburn 5774:
1.149 raeburn 5775: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5776: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5777: if (keys(%servers) > 1) {
5778: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5779: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5780: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5781: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5782: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5783: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5784: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5785: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5786: $changes{'loginvia'}{$lonhost} = 1;
5787: } else {
5788: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5789: $changes{'loginvia'}{$lonhost} = 1;
5790: }
5791: } else {
5792: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5793: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5794: $changes{'loginvia'}{$lonhost} = 1;
5795: }
5796: }
5797: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5798: foreach my $item (@loginvia_attribs) {
5799: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5800: }
5801: } else {
5802: foreach my $item (@loginvia_attribs) {
5803: my $new = $env{'form.'.$lonhost.'_'.$item};
5804: if (($item eq 'serverpath') && ($new eq 'custom')) {
5805: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5806: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5807: $new = '/';
5808: }
5809: }
5810: if (($item eq 'custompath') &&
5811: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5812: $new = '';
5813: }
5814: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5815: $changes{'loginvia'}{$lonhost} = 1;
5816: }
5817: if ($item eq 'exempt') {
5818: $new =~ s/^\s+//;
5819: $new =~ s/\s+$//;
5820: my @poss_ips = split(/\s*[,:]\s*/,$new);
5821: my @okips;
5822: foreach my $ip (@poss_ips) {
5823: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5824: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5825: push(@okips,$ip);
5826: }
5827: }
5828: }
5829: if (@okips > 0) {
5830: $new = join(',',@okips);
5831: } else {
5832: $new = '';
5833: }
5834: }
5835: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5836: }
5837: }
1.112 raeburn 5838: } else {
1.128 raeburn 5839: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5840: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5841: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5842: foreach my $item (@loginvia_attribs) {
5843: my $new = $env{'form.'.$lonhost.'_'.$item};
5844: if (($item eq 'serverpath') && ($new eq 'custom')) {
5845: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5846: $new = '/';
5847: }
5848: }
5849: if (($item eq 'custompath') &&
5850: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5851: $new = '';
5852: }
5853: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5854: }
1.110 raeburn 5855: }
5856: }
5857: }
5858: }
1.119 raeburn 5859:
1.168 raeburn 5860: my $servadm = $r->dir_config('lonAdmEMail');
5861: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5862: if (ref($domconfig{'login'}) eq 'HASH') {
5863: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5864: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5865: if ($lang eq 'nolang') {
5866: push(@currlangs,$lang);
5867: } elsif (defined($langchoices{$lang})) {
5868: push(@currlangs,$lang);
5869: } else {
5870: next;
5871: }
5872: }
5873: }
5874: }
5875: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5876: if (@currlangs > 0) {
5877: foreach my $lang (@currlangs) {
5878: if (grep(/^\Q$lang\E$/,@delurls)) {
5879: $changes{'helpurl'}{$lang} = 1;
5880: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5881: $changes{'helpurl'}{$lang} = 1;
5882: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5883: push(@newlangs,$lang);
5884: } else {
5885: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5886: }
5887: }
5888: }
5889: unless (grep(/^nolang$/,@currlangs)) {
5890: if ($env{'form.loginhelpurl_nolang.filename'}) {
5891: $changes{'helpurl'}{'nolang'} = 1;
5892: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5893: push(@newlangs,'nolang');
5894: }
5895: }
5896: if ($env{'form.loginhelpurl_add_lang'}) {
5897: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5898: ($env{'form.loginhelpurl_add_file.filename'})) {
5899: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5900: $addedfile = $env{'form.loginhelpurl_add_lang'};
5901: }
5902: }
5903: if ((@newlangs > 0) || ($addedfile)) {
5904: my $error;
5905: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5906: if ($configuserok eq 'ok') {
5907: if ($switchserver) {
5908: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5909: } elsif ($author_ok eq 'ok') {
5910: my @allnew = @newlangs;
5911: if ($addedfile ne '') {
5912: push(@allnew,$addedfile);
5913: }
5914: foreach my $lang (@allnew) {
5915: my $formelem = 'loginhelpurl_'.$lang;
5916: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5917: $formelem = 'loginhelpurl_add_file';
5918: }
5919: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5920: "help/$lang",'','',$newfile{$lang});
5921: if ($result eq 'ok') {
5922: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5923: $changes{'helpurl'}{$lang} = 1;
5924: } else {
5925: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5926: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5927: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5928: (!grep(/^\Q$lang\E$/,@delurls))) {
5929:
5930: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5931: }
5932: }
5933: }
5934: } else {
5935: $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);
5936: }
5937: } else {
5938: $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);
5939: }
5940: if ($error) {
5941: &Apache::lonnet::logthis($error);
5942: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5943: }
5944: }
1.169 raeburn 5945: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5946:
5947: my $defaulthelpfile = '/adm/loginproblems.html';
5948: my $defaulttext = &mt('Default in use');
5949:
1.1 raeburn 5950: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5951: $dom);
5952: if ($putresult eq 'ok') {
1.188 raeburn 5953: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5954: my %defaultchecked = (
5955: 'coursecatalog' => 'on',
1.188 raeburn 5956: 'helpdesk' => 'on',
1.42 raeburn 5957: 'adminmail' => 'off',
1.43 raeburn 5958: 'newuser' => 'off',
1.42 raeburn 5959: );
1.55 raeburn 5960: if (ref($domconfig{'login'}) eq 'HASH') {
5961: foreach my $item (@toggles) {
5962: if ($defaultchecked{$item} eq 'on') {
5963: if (($domconfig{'login'}{$item} eq '0') &&
5964: ($env{'form.'.$item} eq '1')) {
5965: $changes{$item} = 1;
5966: } elsif (($domconfig{'login'}{$item} eq '' ||
5967: $domconfig{'login'}{$item} eq '1') &&
5968: ($env{'form.'.$item} eq '0')) {
5969: $changes{$item} = 1;
5970: }
5971: } elsif ($defaultchecked{$item} eq 'off') {
5972: if (($domconfig{'login'}{$item} eq '1') &&
5973: ($env{'form.'.$item} eq '0')) {
5974: $changes{$item} = 1;
5975: } elsif (($domconfig{'login'}{$item} eq '' ||
5976: $domconfig{'login'}{$item} eq '0') &&
5977: ($env{'form.'.$item} eq '1')) {
5978: $changes{$item} = 1;
5979: }
1.42 raeburn 5980: }
5981: }
1.41 raeburn 5982: }
1.6 raeburn 5983: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5984: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5985: if (ref($lastactref) eq 'HASH') {
5986: $lastactref->{'domainconfig'} = 1;
5987: }
1.1 raeburn 5988: $resulttext = &mt('Changes made:').'<ul>';
5989: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5990: if ($item eq 'loginvia') {
1.112 raeburn 5991: if (ref($changes{$item}) eq 'HASH') {
5992: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5993: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5994: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5995: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5996: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5997: $protocol = 'http' if ($protocol ne 'https');
5998: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5999:
6000: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6001: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6002: } else {
6003: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6004: }
6005: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6006: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6007: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6008: }
6009: $resulttext .= '</li>';
6010: } else {
6011: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6012: }
1.112 raeburn 6013: } else {
1.128 raeburn 6014: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6015: }
6016: }
1.128 raeburn 6017: $resulttext .= '</ul></li>';
1.112 raeburn 6018: }
1.168 raeburn 6019: } elsif ($item eq 'helpurl') {
6020: if (ref($changes{$item}) eq 'HASH') {
6021: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6022: if (grep(/^\Q$lang\E$/,@delurls)) {
6023: my ($chg,$link);
6024: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6025: if ($lang eq 'nolang') {
6026: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6027: } else {
6028: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6029: }
6030: $resulttext .= '<li>'.$chg.'</li>';
6031: } else {
6032: my $chg;
6033: if ($lang eq 'nolang') {
6034: $chg = &mt('custom log-in help file for no preferred language');
6035: } else {
6036: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6037: }
6038: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6039: $loginhash{'login'}{'helpurl'}{$lang}.
6040: '?inhibitmenu=yes',$chg,600,500).
6041: '</li>';
6042: }
6043: }
6044: }
1.169 raeburn 6045: } elsif ($item eq 'captcha') {
6046: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6047: my $chgtxt;
1.169 raeburn 6048: if ($loginhash{'login'}{$item} eq 'notused') {
6049: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6050: } else {
6051: my %captchas = &captcha_phrases();
6052: if ($captchas{$loginhash{'login'}{$item}}) {
6053: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6054: } else {
6055: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6056: }
6057: }
6058: $resulttext .= '<li>'.$chgtxt.'</li>';
6059: }
6060: } elsif ($item eq 'recaptchakeys') {
6061: if (ref($loginhash{'login'}) eq 'HASH') {
6062: my ($privkey,$pubkey);
6063: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6064: $pubkey = $loginhash{'login'}{$item}{'public'};
6065: $privkey = $loginhash{'login'}{$item}{'private'};
6066: }
6067: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6068: if (!$pubkey) {
6069: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6070: } else {
6071: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6072: }
6073: if (!$privkey) {
6074: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6075: } else {
1.251 raeburn 6076: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6077: }
6078: $chgtxt .= '</ul>';
6079: $resulttext .= '<li>'.$chgtxt.'</li>';
6080: }
1.41 raeburn 6081: } else {
6082: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6083: }
1.1 raeburn 6084: }
1.6 raeburn 6085: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6086: } else {
6087: $resulttext = &mt('No changes made to log-in page settings');
6088: }
6089: } else {
1.11 albertel 6090: $resulttext = '<span class="LC_error">'.
6091: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6092: }
1.6 raeburn 6093: if ($errors) {
1.9 raeburn 6094: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6095: $errors.'</ul>';
6096: }
6097: return $resulttext;
6098: }
6099:
6100: sub color_font_choices {
6101: my %choices =
6102: &Apache::lonlocal::texthash (
6103: img => "Header",
6104: bgs => "Background colors",
6105: links => "Link colors",
1.55 raeburn 6106: images => "Images",
1.6 raeburn 6107: font => "Font color",
1.201 raeburn 6108: fontmenu => "Font menu",
1.76 raeburn 6109: pgbg => "Page",
1.6 raeburn 6110: tabbg => "Header",
6111: sidebg => "Border",
6112: link => "Link",
6113: alink => "Active link",
6114: vlink => "Visited link",
6115: );
6116: return %choices;
6117: }
6118:
6119: sub modify_rolecolors {
1.205 raeburn 6120: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6121: my ($resulttext,%rolehash);
6122: $rolehash{'rolecolors'} = {};
1.55 raeburn 6123: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6124: if ($domconfig{'rolecolors'} eq '') {
6125: $domconfig{'rolecolors'} = {};
6126: }
6127: }
1.9 raeburn 6128: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6129: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6130: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6131: $dom);
6132: if ($putresult eq 'ok') {
6133: if (keys(%changes) > 0) {
1.41 raeburn 6134: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6135: if (ref($lastactref) eq 'HASH') {
6136: $lastactref->{'domainconfig'} = 1;
6137: }
1.6 raeburn 6138: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6139: $rolehash{'rolecolors'});
6140: } else {
6141: $resulttext = &mt('No changes made to default color schemes');
6142: }
6143: } else {
1.11 albertel 6144: $resulttext = '<span class="LC_error">'.
6145: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6146: }
6147: if ($errors) {
6148: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6149: $errors.'</ul>';
6150: }
6151: return $resulttext;
6152: }
6153:
6154: sub modify_colors {
1.9 raeburn 6155: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6156: my (%changes,%choices);
1.51 raeburn 6157: my @bgs;
1.6 raeburn 6158: my @links = ('link','alink','vlink');
1.41 raeburn 6159: my @logintext;
1.6 raeburn 6160: my @images;
6161: my $servadm = $r->dir_config('lonAdmEMail');
6162: my $errors;
1.200 raeburn 6163: my %defaults;
1.6 raeburn 6164: foreach my $role (@{$roles}) {
6165: if ($role eq 'login') {
1.12 raeburn 6166: %choices = &login_choices();
1.41 raeburn 6167: @logintext = ('textcol','bgcol');
1.12 raeburn 6168: } else {
6169: %choices = &color_font_choices();
6170: }
6171: if ($role eq 'login') {
1.41 raeburn 6172: @images = ('img','logo','domlogo','login');
1.51 raeburn 6173: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6174: } else {
6175: @images = ('img');
1.200 raeburn 6176: @bgs = ('pgbg','tabbg','sidebg');
6177: }
6178: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6179: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6180: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6181: }
6182: if ($role eq 'login') {
6183: foreach my $item (@logintext) {
1.234 raeburn 6184: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6185: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6186: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6187: }
6188: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6189: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6190: }
6191: }
6192: } else {
1.234 raeburn 6193: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6194: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6195: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6196: }
6197: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6198: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6199: }
1.6 raeburn 6200: }
1.200 raeburn 6201: foreach my $item (@bgs) {
1.234 raeburn 6202: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6203: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6204: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6205: }
6206: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6207: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6208: }
6209: }
6210: foreach my $item (@links) {
1.234 raeburn 6211: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6212: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6213: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6214: }
6215: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6216: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6217: }
1.6 raeburn 6218: }
1.46 raeburn 6219: my ($configuserok,$author_ok,$switchserver) =
6220: &config_check($dom,$confname,$servadm);
1.9 raeburn 6221: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6222: if (ref($domconfig->{$role}) ne 'HASH') {
6223: $domconfig->{$role} = {};
6224: }
1.8 raeburn 6225: foreach my $img (@images) {
1.70 raeburn 6226: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6227: if (defined($env{'form.login_showlogo_'.$img})) {
6228: $confhash->{$role}{'showlogo'}{$img} = 1;
6229: } else {
6230: $confhash->{$role}{'showlogo'}{$img} = 0;
6231: }
6232: }
1.18 albertel 6233: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6234: && !defined($domconfig->{$role}{$img})
6235: && !$env{'form.'.$role.'_del_'.$img}
6236: && $env{'form.'.$role.'_import_'.$img}) {
6237: # import the old configured image from the .tab setting
6238: # if they haven't provided a new one
6239: $domconfig->{$role}{$img} =
6240: $env{'form.'.$role.'_import_'.$img};
6241: }
1.6 raeburn 6242: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6243: my $error;
1.6 raeburn 6244: if ($configuserok eq 'ok') {
1.9 raeburn 6245: if ($switchserver) {
1.12 raeburn 6246: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6247: } else {
6248: if ($author_ok eq 'ok') {
6249: my ($result,$logourl) =
6250: &publishlogo($r,'upload',$role.'_'.$img,
6251: $dom,$confname,$img,$width,$height);
6252: if ($result eq 'ok') {
6253: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6254: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6255: } else {
1.12 raeburn 6256: $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 6257: }
6258: } else {
1.46 raeburn 6259: $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 6260: }
6261: }
6262: } else {
1.46 raeburn 6263: $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 6264: }
6265: if ($error) {
1.8 raeburn 6266: &Apache::lonnet::logthis($error);
1.11 albertel 6267: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6268: }
6269: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6270: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6271: my $error;
6272: if ($configuserok eq 'ok') {
6273: # is confname an author?
6274: if ($switchserver eq '') {
6275: if ($author_ok eq 'ok') {
6276: my ($result,$logourl) =
6277: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6278: $dom,$confname,$img,$width,$height);
6279: if ($result eq 'ok') {
6280: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6281: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6282: }
6283: }
6284: }
6285: }
1.6 raeburn 6286: }
6287: }
6288: }
6289: if (ref($domconfig) eq 'HASH') {
6290: if (ref($domconfig->{$role}) eq 'HASH') {
6291: foreach my $img (@images) {
6292: if ($domconfig->{$role}{$img} ne '') {
6293: if ($env{'form.'.$role.'_del_'.$img}) {
6294: $confhash->{$role}{$img} = '';
1.12 raeburn 6295: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6296: } else {
1.9 raeburn 6297: if ($confhash->{$role}{$img} eq '') {
6298: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6299: }
1.6 raeburn 6300: }
6301: } else {
6302: if ($env{'form.'.$role.'_del_'.$img}) {
6303: $confhash->{$role}{$img} = '';
1.12 raeburn 6304: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6305: }
6306: }
1.70 raeburn 6307: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6308: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6309: if ($confhash->{$role}{'showlogo'}{$img} ne
6310: $domconfig->{$role}{'showlogo'}{$img}) {
6311: $changes{$role}{'showlogo'}{$img} = 1;
6312: }
6313: } else {
6314: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6315: $changes{$role}{'showlogo'}{$img} = 1;
6316: }
6317: }
6318: }
6319: }
1.6 raeburn 6320: if ($domconfig->{$role}{'font'} ne '') {
6321: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6322: $changes{$role}{'font'} = 1;
6323: }
6324: } else {
6325: if ($confhash->{$role}{'font'}) {
6326: $changes{$role}{'font'} = 1;
6327: }
6328: }
1.107 raeburn 6329: if ($role ne 'login') {
6330: if ($domconfig->{$role}{'fontmenu'} ne '') {
6331: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6332: $changes{$role}{'fontmenu'} = 1;
6333: }
6334: } else {
6335: if ($confhash->{$role}{'fontmenu'}) {
6336: $changes{$role}{'fontmenu'} = 1;
6337: }
1.97 tempelho 6338: }
6339: }
1.6 raeburn 6340: foreach my $item (@bgs) {
6341: if ($domconfig->{$role}{$item} ne '') {
6342: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6343: $changes{$role}{'bgs'}{$item} = 1;
6344: }
6345: } else {
6346: if ($confhash->{$role}{$item}) {
6347: $changes{$role}{'bgs'}{$item} = 1;
6348: }
6349: }
6350: }
6351: foreach my $item (@links) {
6352: if ($domconfig->{$role}{$item} ne '') {
6353: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6354: $changes{$role}{'links'}{$item} = 1;
6355: }
6356: } else {
6357: if ($confhash->{$role}{$item}) {
6358: $changes{$role}{'links'}{$item} = 1;
6359: }
6360: }
6361: }
1.41 raeburn 6362: foreach my $item (@logintext) {
6363: if ($domconfig->{$role}{$item} ne '') {
6364: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6365: $changes{$role}{'logintext'}{$item} = 1;
6366: }
6367: } else {
6368: if ($confhash->{$role}{$item}) {
6369: $changes{$role}{'logintext'}{$item} = 1;
6370: }
6371: }
6372: }
1.6 raeburn 6373: } else {
6374: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6375: \@logintext,$confhash,\%changes);
1.6 raeburn 6376: }
6377: } else {
6378: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6379: \@logintext,$confhash,\%changes);
1.6 raeburn 6380: }
6381: }
6382: return ($errors,%changes);
6383: }
6384:
1.46 raeburn 6385: sub config_check {
6386: my ($dom,$confname,$servadm) = @_;
6387: my ($configuserok,$author_ok,$switchserver,%currroles);
6388: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6389: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6390: $confname,$servadm);
6391: if ($configuserok eq 'ok') {
6392: $switchserver = &check_switchserver($dom,$confname);
6393: if ($switchserver eq '') {
6394: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6395: }
6396: }
6397: return ($configuserok,$author_ok,$switchserver);
6398: }
6399:
1.6 raeburn 6400: sub default_change_checker {
1.41 raeburn 6401: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6402: foreach my $item (@{$links}) {
6403: if ($confhash->{$role}{$item}) {
6404: $changes->{$role}{'links'}{$item} = 1;
6405: }
6406: }
6407: foreach my $item (@{$bgs}) {
6408: if ($confhash->{$role}{$item}) {
6409: $changes->{$role}{'bgs'}{$item} = 1;
6410: }
6411: }
1.41 raeburn 6412: foreach my $item (@{$logintext}) {
6413: if ($confhash->{$role}{$item}) {
6414: $changes->{$role}{'logintext'}{$item} = 1;
6415: }
6416: }
1.6 raeburn 6417: foreach my $img (@{$images}) {
6418: if ($env{'form.'.$role.'_del_'.$img}) {
6419: $confhash->{$role}{$img} = '';
1.12 raeburn 6420: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6421: }
1.70 raeburn 6422: if ($role eq 'login') {
6423: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6424: $changes->{$role}{'showlogo'}{$img} = 1;
6425: }
6426: }
1.6 raeburn 6427: }
6428: if ($confhash->{$role}{'font'}) {
6429: $changes->{$role}{'font'} = 1;
6430: }
1.48 raeburn 6431: }
1.6 raeburn 6432:
6433: sub display_colorchgs {
6434: my ($dom,$changes,$roles,$confhash) = @_;
6435: my (%choices,$resulttext);
6436: if (!grep(/^login$/,@{$roles})) {
6437: $resulttext = &mt('Changes made:').'<br />';
6438: }
6439: foreach my $role (@{$roles}) {
6440: if ($role eq 'login') {
6441: %choices = &login_choices();
6442: } else {
6443: %choices = &color_font_choices();
6444: }
6445: if (ref($changes->{$role}) eq 'HASH') {
6446: if ($role ne 'login') {
6447: $resulttext .= '<h4>'.&mt($role).'</h4>';
6448: }
6449: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6450: if ($role ne 'login') {
6451: $resulttext .= '<ul>';
6452: }
6453: if (ref($changes->{$role}{$key}) eq 'HASH') {
6454: if ($role ne 'login') {
6455: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6456: }
6457: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6458: if (($role eq 'login') && ($key eq 'showlogo')) {
6459: if ($confhash->{$role}{$key}{$item}) {
6460: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6461: } else {
6462: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6463: }
6464: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6465: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6466: } else {
1.12 raeburn 6467: my $newitem = $confhash->{$role}{$item};
6468: if ($key eq 'images') {
6469: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6470: }
6471: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6472: }
6473: }
6474: if ($role ne 'login') {
6475: $resulttext .= '</ul></li>';
6476: }
6477: } else {
6478: if ($confhash->{$role}{$key} eq '') {
6479: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6480: } else {
6481: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6482: }
6483: }
6484: if ($role ne 'login') {
6485: $resulttext .= '</ul>';
6486: }
6487: }
6488: }
6489: }
1.3 raeburn 6490: return $resulttext;
1.1 raeburn 6491: }
6492:
1.9 raeburn 6493: sub thumb_dimensions {
6494: return ('200','50');
6495: }
6496:
1.16 raeburn 6497: sub check_dimensions {
6498: my ($inputfile) = @_;
6499: my ($fullwidth,$fullheight);
6500: if ($inputfile =~ m|^[/\w.\-]+$|) {
6501: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6502: my $imageinfo = <PIPE>;
6503: if (!close(PIPE)) {
6504: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6505: }
6506: chomp($imageinfo);
6507: my ($fullsize) =
1.21 raeburn 6508: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6509: if ($fullsize) {
6510: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6511: }
6512: }
6513: }
6514: return ($fullwidth,$fullheight);
6515: }
6516:
1.9 raeburn 6517: sub check_configuser {
6518: my ($uhome,$dom,$confname,$servadm) = @_;
6519: my ($configuserok,%currroles);
6520: if ($uhome eq 'no_host') {
6521: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6522: my $configpass = &LONCAPA::Enrollment::create_password();
6523: $configuserok =
6524: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6525: $configpass,'','','','','',undef,$servadm);
6526: } else {
6527: $configuserok = 'ok';
6528: %currroles =
6529: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6530: }
6531: return ($configuserok,%currroles);
6532: }
6533:
6534: sub check_authorstatus {
6535: my ($dom,$confname,%currroles) = @_;
6536: my $author_ok;
1.40 raeburn 6537: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6538: my $start = time;
6539: my $end = 0;
6540: $author_ok =
6541: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6542: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6543: } else {
6544: $author_ok = 'ok';
6545: }
6546: return $author_ok;
6547: }
6548:
6549: sub publishlogo {
1.46 raeburn 6550: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6551: my ($output,$fname,$logourl);
6552: if ($action eq 'upload') {
6553: $fname=$env{'form.'.$formname.'.filename'};
6554: chop($env{'form.'.$formname});
6555: } else {
6556: ($fname) = ($formname =~ /([^\/]+)$/);
6557: }
1.46 raeburn 6558: if ($savefileas ne '') {
6559: $fname = $savefileas;
6560: }
1.9 raeburn 6561: $fname=&Apache::lonnet::clean_filename($fname);
6562: # See if there is anything left
6563: unless ($fname) { return ('error: no uploaded file'); }
6564: $fname="$subdir/$fname";
1.210 raeburn 6565: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6566: my $filepath="$docroot/priv";
6567: my $relpath = "$dom/$confname";
1.9 raeburn 6568: my ($fnamepath,$file,$fetchthumb);
6569: $file=$fname;
6570: if ($fname=~m|/|) {
6571: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6572: }
1.164 raeburn 6573: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6574: my $count;
1.164 raeburn 6575: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6576: $filepath.="/$parts[$count]";
6577: if ((-e $filepath)!=1) {
6578: mkdir($filepath,02770);
6579: }
6580: }
6581: # Check for bad extension and disallow upload
6582: if ($file=~/\.(\w+)$/ &&
6583: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6584: $output =
1.207 bisitz 6585: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6586: } elsif ($file=~/\.(\w+)$/ &&
6587: !defined(&Apache::loncommon::fileembstyle($1))) {
6588: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6589: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6590: $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 6591: } elsif (-d "$filepath/$file") {
1.195 bisitz 6592: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6593: } else {
6594: my $source = $filepath.'/'.$file;
6595: my $logfile;
6596: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6597: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6598: }
6599: print $logfile
6600: "\n================= Publish ".localtime()." ================\n".
6601: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6602: # Save the file
6603: if (!open(FH,'>'.$source)) {
6604: &Apache::lonnet::logthis('Failed to create '.$source);
6605: return (&mt('Failed to create file'));
6606: }
6607: if ($action eq 'upload') {
6608: if (!print FH ($env{'form.'.$formname})) {
6609: &Apache::lonnet::logthis('Failed to write to '.$source);
6610: return (&mt('Failed to write file'));
6611: }
6612: } else {
6613: my $original = &Apache::lonnet::filelocation('',$formname);
6614: if(!copy($original,$source)) {
6615: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6616: return (&mt('Failed to write file'));
6617: }
6618: }
6619: close(FH);
6620: chmod(0660, $source); # Permissions to rw-rw---.
6621:
6622: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6623: my $copyfile=$targetdir.'/'.$file;
6624:
6625: my @parts=split(/\//,$targetdir);
6626: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6627: for (my $count=5;$count<=$#parts;$count++) {
6628: $path.="/$parts[$count]";
6629: if (!-e $path) {
6630: print $logfile "\nCreating directory ".$path;
6631: mkdir($path,02770);
6632: }
6633: }
6634: my $versionresult;
6635: if (-e $copyfile) {
6636: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6637: } else {
6638: $versionresult = 'ok';
6639: }
6640: if ($versionresult eq 'ok') {
6641: if (copy($source,$copyfile)) {
6642: print $logfile "\nCopied original source to ".$copyfile."\n";
6643: $output = 'ok';
6644: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6645: push(@{$modified_urls},[$copyfile,$source]);
6646: my $metaoutput =
6647: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6648: unless ($registered_cleanup) {
6649: my $handlers = $r->get_handlers('PerlCleanupHandler');
6650: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6651: $registered_cleanup=1;
6652: }
1.9 raeburn 6653: } else {
6654: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6655: $output = &mt('Failed to copy file to RES space').", $!";
6656: }
6657: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6658: my $inputfile = $filepath.'/'.$file;
6659: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6660: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6661: if ($fullwidth ne '' && $fullheight ne '') {
6662: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6663: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6664: system("convert -sample $thumbsize $inputfile $outfile");
6665: chmod(0660, $filepath.'/tn-'.$file);
6666: if (-e $outfile) {
6667: my $copyfile=$targetdir.'/tn-'.$file;
6668: if (copy($outfile,$copyfile)) {
6669: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6670: my $thumb_metaoutput =
6671: &write_metadata($dom,$confname,$formname,
6672: $targetdir,'tn-'.$file,$logfile);
6673: push(@{$modified_urls},[$copyfile,$outfile]);
6674: unless ($registered_cleanup) {
6675: my $handlers = $r->get_handlers('PerlCleanupHandler');
6676: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6677: $registered_cleanup=1;
6678: }
1.16 raeburn 6679: } else {
6680: print $logfile "\nUnable to write ".$copyfile.
6681: ':'.$!."\n";
6682: }
6683: }
1.9 raeburn 6684: }
6685: }
6686: }
6687: } else {
6688: $output = $versionresult;
6689: }
6690: }
6691: return ($output,$logourl);
6692: }
6693:
6694: sub logo_versioning {
6695: my ($targetdir,$file,$logfile) = @_;
6696: my $target = $targetdir.'/'.$file;
6697: my ($maxversion,$fn,$extn,$output);
6698: $maxversion = 0;
6699: if ($file =~ /^(.+)\.(\w+)$/) {
6700: $fn=$1;
6701: $extn=$2;
6702: }
6703: opendir(DIR,$targetdir);
6704: while (my $filename=readdir(DIR)) {
6705: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6706: $maxversion=($1>$maxversion)?$1:$maxversion;
6707: }
6708: }
6709: $maxversion++;
6710: print $logfile "\nCreating old version ".$maxversion."\n";
6711: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6712: if (copy($target,$copyfile)) {
6713: print $logfile "Copied old target to ".$copyfile."\n";
6714: $copyfile=$copyfile.'.meta';
6715: if (copy($target.'.meta',$copyfile)) {
6716: print $logfile "Copied old target metadata to ".$copyfile."\n";
6717: $output = 'ok';
6718: } else {
6719: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6720: $output = &mt('Failed to copy old meta').", $!, ";
6721: }
6722: } else {
6723: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6724: $output = &mt('Failed to copy old target').", $!, ";
6725: }
6726: return $output;
6727: }
6728:
6729: sub write_metadata {
6730: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6731: my (%metadatafields,%metadatakeys,$output);
6732: $metadatafields{'title'}=$formname;
6733: $metadatafields{'creationdate'}=time;
6734: $metadatafields{'lastrevisiondate'}=time;
6735: $metadatafields{'copyright'}='public';
6736: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6737: $env{'user.domain'};
6738: $metadatafields{'authorspace'}=$confname.':'.$dom;
6739: $metadatafields{'domain'}=$dom;
6740: {
6741: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6742: my $mfh;
1.155 raeburn 6743: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6744: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6745: unless ($_=~/\./) {
6746: my $unikey=$_;
6747: $unikey=~/^([A-Za-z]+)/;
6748: my $tag=$1;
6749: $tag=~tr/A-Z/a-z/;
6750: print $mfh "\n\<$tag";
6751: foreach (split(/\,/,$metadatakeys{$unikey})) {
6752: my $value=$metadatafields{$unikey.'.'.$_};
6753: $value=~s/\"/\'\'/g;
6754: print $mfh ' '.$_.'="'.$value.'"';
6755: }
6756: print $mfh '>'.
6757: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6758: .'</'.$tag.'>';
6759: }
6760: }
6761: $output = 'ok';
6762: print $logfile "\nWrote metadata";
6763: close($mfh);
6764: } else {
6765: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6766: $output = &mt('Could not write metadata');
6767: }
6768: }
1.155 raeburn 6769: return $output;
6770: }
6771:
6772: sub notifysubscribed {
6773: foreach my $targetsource (@{$modified_urls}){
6774: next unless (ref($targetsource) eq 'ARRAY');
6775: my ($target,$source)=@{$targetsource};
6776: if ($source ne '') {
6777: if (open(my $logfh,'>>'.$source.'.log')) {
6778: print $logfh "\nCleanup phase: Notifications\n";
6779: my @subscribed=&subscribed_hosts($target);
6780: foreach my $subhost (@subscribed) {
6781: print $logfh "\nNotifying host ".$subhost.':';
6782: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6783: print $logfh $reply;
6784: }
6785: my @subscribedmeta=&subscribed_hosts("$target.meta");
6786: foreach my $subhost (@subscribedmeta) {
6787: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6788: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6789: $subhost);
6790: print $logfh $reply;
6791: }
6792: print $logfh "\n============ Done ============\n";
1.160 raeburn 6793: close($logfh);
1.155 raeburn 6794: }
6795: }
6796: }
6797: return OK;
6798: }
6799:
6800: sub subscribed_hosts {
6801: my ($target) = @_;
6802: my @subscribed;
6803: if (open(my $fh,"<$target.subscription")) {
6804: while (my $subline=<$fh>) {
6805: if ($subline =~ /^($match_lonid):/) {
6806: my $host = $1;
6807: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6808: unless (grep(/^\Q$host\E$/,@subscribed)) {
6809: push(@subscribed,$host);
6810: }
6811: }
6812: }
6813: }
6814: }
6815: return @subscribed;
1.9 raeburn 6816: }
6817:
6818: sub check_switchserver {
6819: my ($dom,$confname) = @_;
6820: my ($allowed,$switchserver);
6821: my $home = &Apache::lonnet::homeserver($confname,$dom);
6822: if ($home eq 'no_host') {
6823: $home = &Apache::lonnet::domain($dom,'primary');
6824: }
6825: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6826: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6827: if (!$allowed) {
1.180 raeburn 6828: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6829: }
6830: return $switchserver;
6831: }
6832:
1.1 raeburn 6833: sub modify_quotas {
1.216 raeburn 6834: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6835: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6836: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 6837: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6838: $validationfieldsref);
1.86 raeburn 6839: if ($action eq 'quotas') {
6840: $context = 'tools';
1.163 raeburn 6841: } else {
1.86 raeburn 6842: $context = $action;
6843: }
6844: if ($context eq 'requestcourses') {
1.216 raeburn 6845: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6846: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6847: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6848: %titles = &courserequest_titles();
6849: $toolregexp = join('|',@usertools);
6850: %conditions = &courserequest_conditions();
1.216 raeburn 6851: $confname = $dom.'-domainconfig';
6852: my $servadm = $r->dir_config('lonAdmEMail');
6853: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 6854: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6855: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 6856: } elsif ($context eq 'requestauthor') {
6857: @usertools = ('author');
6858: %titles = &authorrequest_titles();
1.86 raeburn 6859: } else {
1.162 raeburn 6860: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6861: %titles = &tool_titles();
1.86 raeburn 6862: }
1.212 raeburn 6863: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6864: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6865: foreach my $key (keys(%env)) {
1.101 raeburn 6866: if ($context eq 'requestcourses') {
6867: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6868: my $item = $1;
6869: my $type = $2;
6870: if ($type =~ /^limit_(.+)/) {
6871: $limithash{$item}{$1} = $env{$key};
6872: } else {
6873: $confhash{$item}{$type} = $env{$key};
6874: }
6875: }
1.163 raeburn 6876: } elsif ($context eq 'requestauthor') {
6877: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6878: $confhash{$1} = $env{$key};
6879: }
1.101 raeburn 6880: } else {
1.86 raeburn 6881: if ($key =~ /^form\.quota_(.+)$/) {
6882: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6883: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6884: $confhash{'authorquota'}{$1} = $env{$key};
6885: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6886: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6887: }
1.72 raeburn 6888: }
6889: }
1.163 raeburn 6890: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6891: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6892: @approvalnotify = sort(@approvalnotify);
6893: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6894: my @crstypes = ('official','unofficial','community','textbook');
6895: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6896: foreach my $type (@hasuniquecode) {
6897: if (grep(/^\Q$type\E$/,@crstypes)) {
6898: $confhash{'uniquecode'}{$type} = 1;
6899: }
1.216 raeburn 6900: }
1.242 raeburn 6901: my (%newbook,%allpos);
1.216 raeburn 6902: if ($context eq 'requestcourses') {
1.242 raeburn 6903: foreach my $type ('textbooks','templates') {
6904: @{$allpos{$type}} = ();
6905: my $invalid;
6906: if ($type eq 'textbooks') {
6907: $invalid = &mt('Invalid LON-CAPA course for textbook');
6908: } else {
6909: $invalid = &mt('Invalid LON-CAPA course for template');
6910: }
6911: if ($env{'form.'.$type.'_addbook'}) {
6912: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6913: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6914: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6915: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6916: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6917: } else {
6918: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6919: my $position = $env{'form.'.$type.'_addbook_pos'};
6920: $position =~ s/\D+//g;
6921: if ($position ne '') {
6922: $allpos{$type}[$position] = $newbook{$type};
6923: }
1.216 raeburn 6924: }
1.242 raeburn 6925: } else {
6926: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 6927: }
6928: }
1.242 raeburn 6929: }
1.216 raeburn 6930: }
1.102 raeburn 6931: if (ref($domconfig{$action}) eq 'HASH') {
6932: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6933: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6934: $changes{'notify'}{'approval'} = 1;
6935: }
6936: } else {
1.144 raeburn 6937: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6938: $changes{'notify'}{'approval'} = 1;
6939: }
6940: }
1.218 raeburn 6941: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6942: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6943: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6944: unless ($confhash{'uniquecode'}{$crstype}) {
6945: $changes{'uniquecode'} = 1;
6946: }
6947: }
6948: unless ($changes{'uniquecode'}) {
6949: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6950: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6951: $changes{'uniquecode'} = 1;
6952: }
6953: }
6954: }
6955: } else {
6956: $changes{'uniquecode'} = 1;
6957: }
6958: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6959: $changes{'uniquecode'} = 1;
1.216 raeburn 6960: }
6961: if ($context eq 'requestcourses') {
1.242 raeburn 6962: foreach my $type ('textbooks','templates') {
6963: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6964: my %deletions;
6965: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6966: if (@todelete) {
6967: map { $deletions{$_} = 1; } @todelete;
6968: }
6969: my %imgdeletions;
6970: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6971: if (@todeleteimages) {
6972: map { $imgdeletions{$_} = 1; } @todeleteimages;
6973: }
6974: my $maxnum = $env{'form.'.$type.'_maxnum'};
6975: for (my $i=0; $i<=$maxnum; $i++) {
6976: my $itemid = $env{'form.'.$type.'_id_'.$i};
6977: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6978: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6979: if ($deletions{$key}) {
6980: if ($domconfig{$action}{$type}{$key}{'image'}) {
6981: #FIXME need to obsolete item in RES space
6982: }
6983: next;
6984: } else {
6985: my $newpos = $env{'form.'.$itemid};
6986: $newpos =~ s/\D+//g;
1.243 raeburn 6987: foreach my $item ('subject','title','publisher','author') {
6988: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6989: ($type eq 'templates'));
1.242 raeburn 6990: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6991: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6992: $changes{$type}{$key} = 1;
6993: }
6994: }
6995: $allpos{$type}[$newpos] = $key;
6996: }
6997: if ($imgdeletions{$key}) {
6998: $changes{$type}{$key} = 1;
1.216 raeburn 6999: #FIXME need to obsolete item in RES space
1.242 raeburn 7000: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7001: my ($cdom,$cnum) = split(/_/,$key);
7002: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7003: $cdom,$cnum,$type,$configuserok,
7004: $switchserver,$author_ok);
7005: if ($imgurl) {
7006: $confhash{$type}{$key}{'image'} = $imgurl;
7007: $changes{$type}{$key} = 1;
1.216 raeburn 7008: }
1.242 raeburn 7009: if ($error) {
7010: &Apache::lonnet::logthis($error);
7011: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7012: }
7013: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7014: $confhash{$type}{$key}{'image'} =
7015: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7016: }
7017: }
7018: }
7019: }
7020: }
7021: }
1.102 raeburn 7022: } else {
1.144 raeburn 7023: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7024: $changes{'notify'}{'approval'} = 1;
7025: }
1.218 raeburn 7026: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7027: $changes{'uniquecode'} = 1;
7028: }
7029: }
7030: if ($context eq 'requestcourses') {
1.242 raeburn 7031: foreach my $type ('textbooks','templates') {
7032: if ($newbook{$type}) {
7033: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7034: foreach my $item ('subject','title','publisher','author') {
7035: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7036: ($type eq 'template'));
1.242 raeburn 7037: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7038: if ($env{'form.'.$type.'_addbook_'.$item}) {
7039: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7040: }
7041: }
7042: if ($type eq 'textbooks') {
7043: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7044: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7045: my ($imageurl,$error) =
7046: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7047: $configuserok,$switchserver,$author_ok);
7048: if ($imageurl) {
7049: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7050: }
7051: if ($error) {
7052: &Apache::lonnet::logthis($error);
7053: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7054: }
7055: }
1.216 raeburn 7056: }
7057: }
1.242 raeburn 7058: if (@{$allpos{$type}} > 0) {
7059: my $idx = 0;
7060: foreach my $item (@{$allpos{$type}}) {
7061: if ($item ne '') {
7062: $confhash{$type}{$item}{'order'} = $idx;
7063: if (ref($domconfig{$action}) eq 'HASH') {
7064: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7065: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7066: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7067: $changes{$type}{$item} = 1;
7068: }
1.216 raeburn 7069: }
7070: }
7071: }
1.242 raeburn 7072: $idx ++;
1.216 raeburn 7073: }
7074: }
7075: }
7076: }
1.235 raeburn 7077: if (ref($validationitemsref) eq 'ARRAY') {
7078: foreach my $item (@{$validationitemsref}) {
7079: if ($item eq 'fields') {
7080: my @changed;
7081: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7082: if (@{$confhash{'validation'}{$item}} > 0) {
7083: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7084: }
7085: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7086: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7087: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7088: $domconfig{'requestcourses'}{'validation'}{$item});
7089: } else {
7090: @changed = @{$confhash{'validation'}{$item}};
7091: }
7092: } else {
7093: @changed = @{$confhash{'validation'}{$item}};
7094: }
7095: if (@changed) {
7096: if ($confhash{'validation'}{$item}) {
7097: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7098: } else {
7099: $changes{'validation'}{$item} = &mt('None');
7100: }
7101: }
7102: } else {
7103: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7104: if ($item eq 'markup') {
7105: if ($env{'form.requestcourses_validation_'.$item}) {
7106: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7107: }
7108: }
7109: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7110: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7111: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7112: }
7113: } else {
7114: if ($confhash{'validation'}{$item} ne '') {
7115: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7116: }
7117: }
7118: }
7119: }
7120: }
7121: if ($env{'form.validationdc'}) {
7122: my $newval = $env{'form.validationdc'};
7123: my %domcoords = &get_active_dcs($dom);
7124: if (exists($domcoords{$newval})) {
7125: $confhash{'validation'}{'dc'} = $newval;
7126: }
7127: }
7128: if (ref($confhash{'validation'}) eq 'HASH') {
7129: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7130: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7131: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7132: if ($confhash{'validation'}{'dc'} eq '') {
7133: $changes{'validation'}{'dc'} = &mt('None');
7134: } else {
7135: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7136: }
7137: }
7138: } elsif ($confhash{'validation'}{'dc'} ne '') {
7139: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7140: }
7141: } elsif ($confhash{'validation'}{'dc'} ne '') {
7142: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7143: }
7144: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7145: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7146: $changes{'validation'}{'dc'} = &mt('None');
7147: }
7148: }
1.102 raeburn 7149: }
7150: } else {
1.86 raeburn 7151: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7152: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7153: }
1.72 raeburn 7154: foreach my $item (@usertools) {
7155: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7156: my $unset;
1.101 raeburn 7157: if ($context eq 'requestcourses') {
1.104 raeburn 7158: $unset = '0';
7159: if ($type eq '_LC_adv') {
7160: $unset = '';
7161: }
1.101 raeburn 7162: if ($confhash{$item}{$type} eq 'autolimit') {
7163: $confhash{$item}{$type} .= '=';
7164: unless ($limithash{$item}{$type} =~ /\D/) {
7165: $confhash{$item}{$type} .= $limithash{$item}{$type};
7166: }
7167: }
1.163 raeburn 7168: } elsif ($context eq 'requestauthor') {
7169: $unset = '0';
7170: if ($type eq '_LC_adv') {
7171: $unset = '';
7172: }
1.72 raeburn 7173: } else {
1.101 raeburn 7174: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7175: $confhash{$item}{$type} = 1;
7176: } else {
7177: $confhash{$item}{$type} = 0;
7178: }
1.72 raeburn 7179: }
1.86 raeburn 7180: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7181: if ($action eq 'requestauthor') {
7182: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7183: $changes{$type} = 1;
7184: }
7185: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7186: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7187: $changes{$item}{$type} = 1;
7188: }
7189: } else {
7190: if ($context eq 'requestcourses') {
1.104 raeburn 7191: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7192: $changes{$item}{$type} = 1;
7193: }
7194: } else {
7195: if (!$confhash{$item}{$type}) {
7196: $changes{$item}{$type} = 1;
7197: }
7198: }
7199: }
7200: } else {
7201: if ($context eq 'requestcourses') {
1.104 raeburn 7202: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7203: $changes{$item}{$type} = 1;
7204: }
1.163 raeburn 7205: } elsif ($context eq 'requestauthor') {
7206: if ($confhash{$type} ne $unset) {
7207: $changes{$type} = 1;
7208: }
1.72 raeburn 7209: } else {
7210: if (!$confhash{$item}{$type}) {
7211: $changes{$item}{$type} = 1;
7212: }
7213: }
7214: }
1.1 raeburn 7215: }
7216: }
1.163 raeburn 7217: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7218: if (ref($domconfig{'quotas'}) eq 'HASH') {
7219: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7220: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7221: if (exists($confhash{'defaultquota'}{$key})) {
7222: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7223: $changes{'defaultquota'}{$key} = 1;
7224: }
7225: } else {
7226: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7227: }
7228: }
1.86 raeburn 7229: } else {
7230: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7231: if (exists($confhash{'defaultquota'}{$key})) {
7232: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7233: $changes{'defaultquota'}{$key} = 1;
7234: }
7235: } else {
7236: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7237: }
1.1 raeburn 7238: }
7239: }
1.197 raeburn 7240: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7241: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7242: if (exists($confhash{'authorquota'}{$key})) {
7243: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7244: $changes{'authorquota'}{$key} = 1;
7245: }
7246: } else {
7247: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7248: }
7249: }
7250: }
1.1 raeburn 7251: }
1.86 raeburn 7252: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7253: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7254: if (ref($domconfig{'quotas'}) eq 'HASH') {
7255: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7256: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7257: $changes{'defaultquota'}{$key} = 1;
7258: }
7259: } else {
7260: if (!exists($domconfig{'quotas'}{$key})) {
7261: $changes{'defaultquota'}{$key} = 1;
7262: }
1.72 raeburn 7263: }
7264: } else {
1.86 raeburn 7265: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7266: }
1.1 raeburn 7267: }
7268: }
1.197 raeburn 7269: if (ref($confhash{'authorquota'}) eq 'HASH') {
7270: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7271: if (ref($domconfig{'quotas'}) eq 'HASH') {
7272: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7273: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7274: $changes{'authorquota'}{$key} = 1;
7275: }
7276: } else {
7277: $changes{'authorquota'}{$key} = 1;
7278: }
7279: } else {
7280: $changes{'authorquota'}{$key} = 1;
7281: }
7282: }
7283: }
1.1 raeburn 7284: }
1.72 raeburn 7285:
1.163 raeburn 7286: if ($context eq 'requestauthor') {
7287: $domdefaults{'requestauthor'} = \%confhash;
7288: } else {
7289: foreach my $key (keys(%confhash)) {
1.242 raeburn 7290: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 7291: $domdefaults{$key} = $confhash{$key};
7292: }
1.163 raeburn 7293: }
1.72 raeburn 7294: }
1.163 raeburn 7295:
1.1 raeburn 7296: my %quotahash = (
1.86 raeburn 7297: $action => { %confhash }
1.1 raeburn 7298: );
7299: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7300: $dom);
7301: if ($putresult eq 'ok') {
7302: if (keys(%changes) > 0) {
1.72 raeburn 7303: my $cachetime = 24*60*60;
7304: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7305: if (ref($lastactref) eq 'HASH') {
7306: $lastactref->{'domdefaults'} = 1;
7307: }
1.1 raeburn 7308: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7309: unless (($context eq 'requestcourses') ||
1.163 raeburn 7310: ($context eq 'requestauthor')) {
1.86 raeburn 7311: if (ref($changes{'defaultquota'}) eq 'HASH') {
7312: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7313: foreach my $type (@{$types},'default') {
7314: if (defined($changes{'defaultquota'}{$type})) {
7315: my $typetitle = $usertypes->{$type};
7316: if ($type eq 'default') {
7317: $typetitle = $othertitle;
7318: }
1.213 raeburn 7319: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7320: }
7321: }
1.86 raeburn 7322: $resulttext .= '</ul></li>';
1.72 raeburn 7323: }
1.197 raeburn 7324: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7325: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7326: foreach my $type (@{$types},'default') {
7327: if (defined($changes{'authorquota'}{$type})) {
7328: my $typetitle = $usertypes->{$type};
7329: if ($type eq 'default') {
7330: $typetitle = $othertitle;
7331: }
1.213 raeburn 7332: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7333: }
7334: }
7335: $resulttext .= '</ul></li>';
7336: }
1.72 raeburn 7337: }
1.80 raeburn 7338: my %newenv;
1.72 raeburn 7339: foreach my $item (@usertools) {
1.163 raeburn 7340: my (%haschgs,%inconf);
7341: if ($context eq 'requestauthor') {
7342: %haschgs = %changes;
1.210 raeburn 7343: %inconf = %confhash;
1.163 raeburn 7344: } else {
7345: if (ref($changes{$item}) eq 'HASH') {
7346: %haschgs = %{$changes{$item}};
7347: }
7348: if (ref($confhash{$item}) eq 'HASH') {
7349: %inconf = %{$confhash{$item}};
7350: }
7351: }
7352: if (keys(%haschgs) > 0) {
1.80 raeburn 7353: my $newacc =
7354: &Apache::lonnet::usertools_access($env{'user.name'},
7355: $env{'user.domain'},
1.86 raeburn 7356: $item,'reload',$context);
1.210 raeburn 7357: if (($context eq 'requestcourses') ||
1.163 raeburn 7358: ($context eq 'requestauthor')) {
1.108 raeburn 7359: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7360: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7361: }
7362: } else {
7363: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7364: $newenv{'environment.availabletools.'.$item} = $newacc;
7365: }
1.80 raeburn 7366: }
1.163 raeburn 7367: unless ($context eq 'requestauthor') {
7368: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7369: }
1.72 raeburn 7370: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7371: if ($haschgs{$type}) {
1.72 raeburn 7372: my $typetitle = $usertypes->{$type};
7373: if ($type eq 'default') {
7374: $typetitle = $othertitle;
7375: } elsif ($type eq '_LC_adv') {
7376: $typetitle = 'LON-CAPA Advanced Users';
7377: }
1.163 raeburn 7378: if ($inconf{$type}) {
1.101 raeburn 7379: if ($context eq 'requestcourses') {
7380: my $cond;
1.163 raeburn 7381: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7382: if ($1 eq '') {
7383: $cond = &mt('(Automatic processing of any request).');
7384: } else {
7385: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7386: }
7387: } else {
1.163 raeburn 7388: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7389: }
7390: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7391: } elsif ($context eq 'requestauthor') {
7392: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7393: $titles{$inconf{$type}},$typetitle);
7394:
1.101 raeburn 7395: } else {
7396: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7397: }
1.72 raeburn 7398: } else {
1.104 raeburn 7399: if ($type eq '_LC_adv') {
1.163 raeburn 7400: if ($inconf{$type} eq '0') {
1.104 raeburn 7401: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7402: } else {
7403: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7404: }
7405: } else {
7406: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7407: }
1.72 raeburn 7408: }
7409: }
1.26 raeburn 7410: }
1.163 raeburn 7411: unless ($context eq 'requestauthor') {
7412: $resulttext .= '</ul></li>';
7413: }
1.26 raeburn 7414: }
1.1 raeburn 7415: }
1.163 raeburn 7416: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7417: if (ref($changes{'notify'}) eq 'HASH') {
7418: if ($changes{'notify'}{'approval'}) {
7419: if (ref($confhash{'notify'}) eq 'HASH') {
7420: if ($confhash{'notify'}{'approval'}) {
7421: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7422: } else {
1.163 raeburn 7423: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7424: }
7425: }
7426: }
7427: }
7428: }
1.216 raeburn 7429: if ($action eq 'requestcourses') {
7430: my @offon = ('off','on');
7431: if ($changes{'uniquecode'}) {
1.218 raeburn 7432: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7433: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7434: $resulttext .= '<li>'.
7435: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7436: '</li>';
7437: } else {
7438: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7439: '</li>';
7440: }
1.216 raeburn 7441: }
1.242 raeburn 7442: foreach my $type ('textbooks','templates') {
7443: if (ref($changes{$type}) eq 'HASH') {
7444: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7445: foreach my $key (sort(keys(%{$changes{$type}}))) {
7446: my %coursehash = &Apache::lonnet::coursedescription($key);
7447: my $coursetitle = $coursehash{'description'};
7448: my $position = $confhash{$type}{$key}{'order'} + 1;
7449: $resulttext .= '<li>';
1.243 raeburn 7450: foreach my $item ('subject','title','publisher','author') {
7451: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7452: ($type eq 'templates'));
1.242 raeburn 7453: my $name = $item.':';
7454: $name =~ s/^(\w)/\U$1/;
7455: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7456: }
7457: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7458: if ($type eq 'textbooks') {
7459: if ($confhash{$type}{$key}{'image'}) {
7460: $resulttext .= ' '.&mt('Image: [_1]',
7461: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7462: ' alt="Textbook cover" />').'<br />';
7463: }
7464: }
7465: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 7466: }
1.242 raeburn 7467: $resulttext .= '</ul></li>';
1.216 raeburn 7468: }
7469: }
1.235 raeburn 7470: if (ref($changes{'validation'}) eq 'HASH') {
7471: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7472: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7473: foreach my $item (@{$validationitemsref}) {
7474: if (exists($changes{'validation'}{$item})) {
7475: if ($item eq 'markup') {
7476: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7477: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7478: } else {
7479: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7480: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7481: }
7482: }
7483: }
7484: if (exists($changes{'validation'}{'dc'})) {
7485: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7486: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7487: }
7488: }
7489: }
1.216 raeburn 7490: }
1.1 raeburn 7491: $resulttext .= '</ul>';
1.80 raeburn 7492: if (keys(%newenv)) {
7493: &Apache::lonnet::appenv(\%newenv);
7494: }
1.1 raeburn 7495: } else {
1.86 raeburn 7496: if ($context eq 'requestcourses') {
7497: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7498: } elsif ($context eq 'requestauthor') {
7499: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7500: } else {
1.90 weissno 7501: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7502: }
1.1 raeburn 7503: }
7504: } else {
1.11 albertel 7505: $resulttext = '<span class="LC_error">'.
7506: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7507: }
1.216 raeburn 7508: if ($errors) {
7509: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7510: '<ul>'.$errors.'</ul></p>';
7511: }
1.3 raeburn 7512: return $resulttext;
1.1 raeburn 7513: }
7514:
1.216 raeburn 7515: sub process_textbook_image {
1.242 raeburn 7516: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 7517: my $filename = $env{'form.'.$caller.'.filename'};
7518: my ($error,$url);
7519: my ($width,$height) = (50,50);
7520: if ($configuserok eq 'ok') {
7521: if ($switchserver) {
7522: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7523: $switchserver);
7524: } elsif ($author_ok eq 'ok') {
7525: my ($result,$imageurl) =
7526: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 7527: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 7528: if ($result eq 'ok') {
7529: $url = $imageurl;
7530: } else {
7531: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7532: }
7533: } else {
7534: $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);
7535: }
7536: } else {
7537: $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);
7538: }
7539: return ($url,$error);
7540: }
7541:
1.3 raeburn 7542: sub modify_autoenroll {
1.205 raeburn 7543: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7544: my ($resulttext,%changes);
7545: my %currautoenroll;
7546: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7547: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7548: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7549: }
7550: }
7551: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7552: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7553: sender => 'Sender for notification messages',
7554: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7555: my @offon = ('off','on');
1.17 raeburn 7556: my $sender_uname = $env{'form.sender_uname'};
7557: my $sender_domain = $env{'form.sender_domain'};
7558: if ($sender_domain eq '') {
7559: $sender_uname = '';
7560: } elsif ($sender_uname eq '') {
7561: $sender_domain = '';
7562: }
1.129 raeburn 7563: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7564: my %autoenrollhash = (
1.129 raeburn 7565: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7566: 'sender_uname' => $sender_uname,
7567: 'sender_domain' => $sender_domain,
7568: 'co-owners' => $coowners,
1.1 raeburn 7569: }
7570: );
1.4 raeburn 7571: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7572: $dom);
1.1 raeburn 7573: if ($putresult eq 'ok') {
7574: if (exists($currautoenroll{'run'})) {
7575: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7576: $changes{'run'} = 1;
7577: }
7578: } elsif ($autorun) {
7579: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7580: $changes{'run'} = 1;
1.1 raeburn 7581: }
7582: }
1.17 raeburn 7583: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7584: $changes{'sender'} = 1;
7585: }
1.17 raeburn 7586: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7587: $changes{'sender'} = 1;
7588: }
1.129 raeburn 7589: if ($currautoenroll{'co-owners'} ne '') {
7590: if ($currautoenroll{'co-owners'} ne $coowners) {
7591: $changes{'coowners'} = 1;
7592: }
7593: } elsif ($coowners) {
7594: $changes{'coowners'} = 1;
7595: }
1.1 raeburn 7596: if (keys(%changes) > 0) {
7597: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7598: if ($changes{'run'}) {
1.1 raeburn 7599: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7600: }
7601: if ($changes{'sender'}) {
1.17 raeburn 7602: if ($sender_uname eq '' || $sender_domain eq '') {
7603: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7604: } else {
7605: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7606: }
1.1 raeburn 7607: }
1.129 raeburn 7608: if ($changes{'coowners'}) {
7609: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7610: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7611: if (ref($lastactref) eq 'HASH') {
7612: $lastactref->{'domainconfig'} = 1;
7613: }
1.129 raeburn 7614: }
1.1 raeburn 7615: $resulttext .= '</ul>';
7616: } else {
7617: $resulttext = &mt('No changes made to auto-enrollment settings');
7618: }
7619: } else {
1.11 albertel 7620: $resulttext = '<span class="LC_error">'.
7621: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7622: }
1.3 raeburn 7623: return $resulttext;
1.1 raeburn 7624: }
7625:
7626: sub modify_autoupdate {
1.3 raeburn 7627: my ($dom,%domconfig) = @_;
1.1 raeburn 7628: my ($resulttext,%currautoupdate,%fields,%changes);
7629: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7630: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7631: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7632: }
7633: }
7634: my @offon = ('off','on');
7635: my %title = &Apache::lonlocal::texthash (
7636: run => 'Auto-update:',
7637: classlists => 'Updates to user information in classlists?'
7638: );
1.44 raeburn 7639: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7640: my %fieldtitles = &Apache::lonlocal::texthash (
7641: id => 'Student/Employee ID',
1.20 raeburn 7642: permanentemail => 'E-mail address',
1.1 raeburn 7643: lastname => 'Last Name',
7644: firstname => 'First Name',
7645: middlename => 'Middle Name',
1.132 raeburn 7646: generation => 'Generation',
1.1 raeburn 7647: );
1.142 raeburn 7648: $othertitle = &mt('All users');
1.1 raeburn 7649: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7650: $othertitle = &mt('Other users');
1.1 raeburn 7651: }
7652: foreach my $key (keys(%env)) {
7653: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7654: my ($usertype,$item) = ($1,$2);
7655: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7656: if ($usertype eq 'default') {
7657: push(@{$fields{$1}},$2);
7658: } elsif (ref($types) eq 'ARRAY') {
7659: if (grep(/^\Q$usertype\E$/,@{$types})) {
7660: push(@{$fields{$1}},$2);
7661: }
7662: }
7663: }
1.1 raeburn 7664: }
7665: }
1.131 raeburn 7666: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7667: @lockablenames = sort(@lockablenames);
7668: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7669: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7670: if (@changed) {
7671: $changes{'lockablenames'} = 1;
7672: }
7673: } else {
7674: if (@lockablenames) {
7675: $changes{'lockablenames'} = 1;
7676: }
7677: }
1.1 raeburn 7678: my %updatehash = (
7679: autoupdate => { run => $env{'form.autoupdate_run'},
7680: classlists => $env{'form.classlists'},
7681: fields => {%fields},
1.131 raeburn 7682: lockablenames => \@lockablenames,
1.1 raeburn 7683: }
7684: );
7685: foreach my $key (keys(%currautoupdate)) {
7686: if (($key eq 'run') || ($key eq 'classlists')) {
7687: if (exists($updatehash{autoupdate}{$key})) {
7688: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7689: $changes{$key} = 1;
7690: }
7691: }
7692: } elsif ($key eq 'fields') {
7693: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7694: foreach my $item (@{$types},'default') {
1.1 raeburn 7695: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7696: my $change = 0;
7697: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7698: if (!exists($fields{$item})) {
7699: $change = 1;
1.132 raeburn 7700: last;
1.1 raeburn 7701: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7702: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7703: $change = 1;
1.132 raeburn 7704: last;
1.1 raeburn 7705: }
7706: }
7707: }
7708: if ($change) {
7709: push(@{$changes{$key}},$item);
7710: }
1.26 raeburn 7711: }
1.1 raeburn 7712: }
7713: }
1.131 raeburn 7714: } elsif ($key eq 'lockablenames') {
7715: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7716: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7717: if (@changed) {
7718: $changes{'lockablenames'} = 1;
7719: }
7720: } else {
7721: if (@lockablenames) {
7722: $changes{'lockablenames'} = 1;
7723: }
7724: }
7725: }
7726: }
7727: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7728: if (@lockablenames) {
7729: $changes{'lockablenames'} = 1;
1.1 raeburn 7730: }
7731: }
1.26 raeburn 7732: foreach my $item (@{$types},'default') {
7733: if (defined($fields{$item})) {
7734: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7735: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7736: my $change = 0;
7737: if (ref($fields{$item}) eq 'ARRAY') {
7738: foreach my $type (@{$fields{$item}}) {
7739: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7740: $change = 1;
7741: last;
7742: }
7743: }
7744: }
7745: if ($change) {
7746: push(@{$changes{'fields'}},$item);
7747: }
7748: } else {
1.26 raeburn 7749: push(@{$changes{'fields'}},$item);
7750: }
7751: } else {
7752: push(@{$changes{'fields'}},$item);
1.1 raeburn 7753: }
7754: }
7755: }
7756: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7757: $dom);
7758: if ($putresult eq 'ok') {
7759: if (keys(%changes) > 0) {
7760: $resulttext = &mt('Changes made:').'<ul>';
7761: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7762: if ($key eq 'lockablenames') {
7763: $resulttext .= '<li>';
7764: if (@lockablenames) {
7765: $usertypes->{'default'} = $othertitle;
7766: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7767: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7768: } else {
7769: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7770: }
7771: $resulttext .= '</li>';
7772: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7773: foreach my $item (@{$changes{$key}}) {
7774: my @newvalues;
7775: foreach my $type (@{$fields{$item}}) {
7776: push(@newvalues,$fieldtitles{$type});
7777: }
1.3 raeburn 7778: my $newvaluestr;
7779: if (@newvalues > 0) {
7780: $newvaluestr = join(', ',@newvalues);
7781: } else {
7782: $newvaluestr = &mt('none');
1.6 raeburn 7783: }
1.1 raeburn 7784: if ($item eq 'default') {
1.26 raeburn 7785: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7786: } else {
1.26 raeburn 7787: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7788: }
7789: }
7790: } else {
7791: my $newvalue;
7792: if ($key eq 'run') {
7793: $newvalue = $offon[$env{'form.autoupdate_run'}];
7794: } else {
7795: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7796: }
1.1 raeburn 7797: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7798: }
7799: }
7800: $resulttext .= '</ul>';
7801: } else {
1.3 raeburn 7802: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7803: }
7804: } else {
1.11 albertel 7805: $resulttext = '<span class="LC_error">'.
7806: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7807: }
1.3 raeburn 7808: return $resulttext;
1.1 raeburn 7809: }
7810:
1.125 raeburn 7811: sub modify_autocreate {
7812: my ($dom,%domconfig) = @_;
7813: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7814: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7815: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7816: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7817: }
7818: }
7819: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7820: req => 'Auto-creation of validated requests for official courses',
7821: xmldc => 'Identity of course creator of courses from XML files',
7822: );
7823: my @types = ('xml','req');
7824: foreach my $item (@types) {
7825: $newvals{$item} = $env{'form.autocreate_'.$item};
7826: $newvals{$item} =~ s/\D//g;
7827: $newvals{$item} = 0 if ($newvals{$item} eq '');
7828: }
7829: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7830: my %domcoords = &get_active_dcs($dom);
7831: unless (exists($domcoords{$newvals{'xmldc'}})) {
7832: $newvals{'xmldc'} = '';
7833: }
7834: %autocreatehash = (
7835: autocreate => { xml => $newvals{'xml'},
7836: req => $newvals{'req'},
7837: }
7838: );
7839: if ($newvals{'xmldc'} ne '') {
7840: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7841: }
7842: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7843: $dom);
7844: if ($putresult eq 'ok') {
7845: my @items = @types;
7846: if ($newvals{'xml'}) {
7847: push(@items,'xmldc');
7848: }
7849: foreach my $item (@items) {
7850: if (exists($currautocreate{$item})) {
7851: if ($currautocreate{$item} ne $newvals{$item}) {
7852: $changes{$item} = 1;
7853: }
7854: } elsif ($newvals{$item}) {
7855: $changes{$item} = 1;
7856: }
7857: }
7858: if (keys(%changes) > 0) {
7859: my @offon = ('off','on');
7860: $resulttext = &mt('Changes made:').'<ul>';
7861: foreach my $item (@types) {
7862: if ($changes{$item}) {
7863: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7864: $resulttext .= '<li>'.
7865: &mt("$title{$item} set to [_1]$newtxt [_2]",
7866: '<b>','</b>').
7867: '</li>';
1.125 raeburn 7868: }
7869: }
7870: if ($changes{'xmldc'}) {
7871: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7872: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7873: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7874: }
7875: $resulttext .= '</ul>';
7876: } else {
7877: $resulttext = &mt('No changes made to auto-creation settings');
7878: }
7879: } else {
7880: $resulttext = '<span class="LC_error">'.
7881: &mt('An error occurred: [_1]',$putresult).'</span>';
7882: }
7883: return $resulttext;
7884: }
7885:
1.23 raeburn 7886: sub modify_directorysrch {
7887: my ($dom,%domconfig) = @_;
7888: my ($resulttext,%changes);
7889: my %currdirsrch;
7890: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7891: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7892: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7893: }
7894: }
7895: my %title = ( available => 'Directory search available',
1.24 raeburn 7896: localonly => 'Other domains can search',
1.23 raeburn 7897: searchby => 'Search types',
7898: searchtypes => 'Search latitude');
7899: my @offon = ('off','on');
1.24 raeburn 7900: my @otherdoms = ('Yes','No');
1.23 raeburn 7901:
1.25 raeburn 7902: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7903: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7904: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7905:
1.44 raeburn 7906: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7907: if (keys(%{$usertypes}) == 0) {
7908: @cansearch = ('default');
7909: } else {
7910: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7911: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7912: if (!grep(/^\Q$type\E$/,@cansearch)) {
7913: push(@{$changes{'cansearch'}},$type);
7914: }
1.23 raeburn 7915: }
1.26 raeburn 7916: foreach my $type (@cansearch) {
7917: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7918: push(@{$changes{'cansearch'}},$type);
7919: }
1.23 raeburn 7920: }
1.26 raeburn 7921: } else {
7922: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7923: }
7924: }
7925:
7926: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7927: foreach my $by (@{$currdirsrch{'searchby'}}) {
7928: if (!grep(/^\Q$by\E$/,@searchby)) {
7929: push(@{$changes{'searchby'}},$by);
7930: }
7931: }
7932: foreach my $by (@searchby) {
7933: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7934: push(@{$changes{'searchby'}},$by);
7935: }
7936: }
7937: } else {
7938: push(@{$changes{'searchby'}},@searchby);
7939: }
1.25 raeburn 7940:
7941: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7942: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7943: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7944: push(@{$changes{'searchtypes'}},$type);
7945: }
7946: }
7947: foreach my $type (@searchtypes) {
7948: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7949: push(@{$changes{'searchtypes'}},$type);
7950: }
7951: }
7952: } else {
7953: if (exists($currdirsrch{'searchtypes'})) {
7954: foreach my $type (@searchtypes) {
7955: if ($type ne $currdirsrch{'searchtypes'}) {
7956: push(@{$changes{'searchtypes'}},$type);
7957: }
7958: }
7959: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7960: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7961: }
7962: } else {
7963: push(@{$changes{'searchtypes'}},@searchtypes);
7964: }
7965: }
7966:
1.23 raeburn 7967: my %dirsrch_hash = (
7968: directorysrch => { available => $env{'form.dirsrch_available'},
7969: cansearch => \@cansearch,
1.24 raeburn 7970: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7971: searchby => \@searchby,
1.25 raeburn 7972: searchtypes => \@searchtypes,
1.23 raeburn 7973: }
7974: );
7975: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7976: $dom);
7977: if ($putresult eq 'ok') {
7978: if (exists($currdirsrch{'available'})) {
7979: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7980: $changes{'available'} = 1;
7981: }
7982: } else {
7983: if ($env{'form.dirsrch_available'} eq '1') {
7984: $changes{'available'} = 1;
7985: }
7986: }
1.24 raeburn 7987: if (exists($currdirsrch{'localonly'})) {
7988: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7989: $changes{'localonly'} = 1;
7990: }
7991: } else {
7992: if ($env{'form.dirsrch_localonly'} eq '1') {
7993: $changes{'localonly'} = 1;
7994: }
7995: }
1.23 raeburn 7996: if (keys(%changes) > 0) {
7997: $resulttext = &mt('Changes made:').'<ul>';
7998: if ($changes{'available'}) {
7999: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8000: }
1.24 raeburn 8001: if ($changes{'localonly'}) {
8002: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8003: }
8004:
1.23 raeburn 8005: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8006: my $chgtext;
1.26 raeburn 8007: if (ref($usertypes) eq 'HASH') {
8008: if (keys(%{$usertypes}) > 0) {
8009: foreach my $type (@{$types}) {
8010: if (grep(/^\Q$type\E$/,@cansearch)) {
8011: $chgtext .= $usertypes->{$type}.'; ';
8012: }
8013: }
8014: if (grep(/^default$/,@cansearch)) {
8015: $chgtext .= $othertitle;
8016: } else {
8017: $chgtext =~ s/\; $//;
8018: }
1.210 raeburn 8019: $resulttext .=
1.178 raeburn 8020: '<li>'.
8021: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8022: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8023: '</li>';
1.23 raeburn 8024: }
8025: }
8026: }
8027: if (ref($changes{'searchby'}) eq 'ARRAY') {
8028: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8029: my $chgtext;
8030: foreach my $type (@{$titleorder}) {
8031: if (grep(/^\Q$type\E$/,@searchby)) {
8032: if (defined($searchtitles->{$type})) {
8033: $chgtext .= $searchtitles->{$type}.'; ';
8034: }
8035: }
8036: }
8037: $chgtext =~ s/\; $//;
8038: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8039: }
1.25 raeburn 8040: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8041: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8042: my $chgtext;
8043: foreach my $type (@{$srchtypeorder}) {
8044: if (grep(/^\Q$type\E$/,@searchtypes)) {
8045: if (defined($srchtypes_desc->{$type})) {
8046: $chgtext .= $srchtypes_desc->{$type}.'; ';
8047: }
8048: }
8049: }
8050: $chgtext =~ s/\; $//;
1.178 raeburn 8051: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8052: }
8053: $resulttext .= '</ul>';
8054: } else {
8055: $resulttext = &mt('No changes made to institution directory search settings');
8056: }
8057: } else {
8058: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8059: &mt('An error occurred: [_1]',$putresult).'</span>';
8060: }
8061: return $resulttext;
8062: }
8063:
1.28 raeburn 8064: sub modify_contacts {
1.205 raeburn 8065: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8066: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8067: if (ref($domconfig{'contacts'}) eq 'HASH') {
8068: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8069: $currsetting{$key} = $domconfig{'contacts'}{$key};
8070: }
8071: }
1.134 raeburn 8072: my (%others,%to,%bcc);
1.28 raeburn 8073: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8074: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 8075: 'requestsmail','updatesmail','idconflictsmail');
8076: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8077: foreach my $type (@mailings) {
8078: @{$newsetting{$type}} =
8079: &Apache::loncommon::get_env_multiple('form.'.$type);
8080: foreach my $item (@contacts) {
8081: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8082: $contacts_hash{contacts}{$type}{$item} = 1;
8083: } else {
8084: $contacts_hash{contacts}{$type}{$item} = 0;
8085: }
8086: }
8087: $others{$type} = $env{'form.'.$type.'_others'};
8088: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8089: if ($type eq 'helpdeskmail') {
8090: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8091: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8092: }
1.28 raeburn 8093: }
8094: foreach my $item (@contacts) {
8095: $to{$item} = $env{'form.'.$item};
8096: $contacts_hash{'contacts'}{$item} = $to{$item};
8097: }
1.203 raeburn 8098: foreach my $item (@toggles) {
8099: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8100: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8101: }
8102: }
1.28 raeburn 8103: if (keys(%currsetting) > 0) {
8104: foreach my $item (@contacts) {
8105: if ($to{$item} ne $currsetting{$item}) {
8106: $changes{$item} = 1;
8107: }
8108: }
8109: foreach my $type (@mailings) {
8110: foreach my $item (@contacts) {
8111: if (ref($currsetting{$type}) eq 'HASH') {
8112: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8113: push(@{$changes{$type}},$item);
8114: }
8115: } else {
8116: push(@{$changes{$type}},@{$newsetting{$type}});
8117: }
8118: }
8119: if ($others{$type} ne $currsetting{$type}{'others'}) {
8120: push(@{$changes{$type}},'others');
8121: }
1.134 raeburn 8122: if ($type eq 'helpdeskmail') {
8123: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8124: push(@{$changes{$type}},'bcc');
8125: }
8126: }
1.28 raeburn 8127: }
8128: } else {
8129: my %default;
8130: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8131: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8132: $default{'errormail'} = 'adminemail';
8133: $default{'packagesmail'} = 'adminemail';
8134: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8135: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8136: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8137: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8138: foreach my $item (@contacts) {
8139: if ($to{$item} ne $default{$item}) {
8140: $changes{$item} = 1;
1.203 raeburn 8141: }
1.28 raeburn 8142: }
8143: foreach my $type (@mailings) {
8144: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8145:
8146: push(@{$changes{$type}},@{$newsetting{$type}});
8147: }
8148: if ($others{$type} ne '') {
8149: push(@{$changes{$type}},'others');
1.134 raeburn 8150: }
8151: if ($type eq 'helpdeskmail') {
8152: if ($bcc{$type} ne '') {
8153: push(@{$changes{$type}},'bcc');
8154: }
8155: }
1.28 raeburn 8156: }
8157: }
1.203 raeburn 8158: foreach my $item (@toggles) {
8159: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8160: $changes{$item} = 1;
8161: } elsif ((!$env{'form.'.$item}) &&
8162: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8163: $changes{$item} = 1;
8164: }
8165: }
1.28 raeburn 8166: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8167: $dom);
8168: if ($putresult eq 'ok') {
8169: if (keys(%changes) > 0) {
1.205 raeburn 8170: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8171: if (ref($lastactref) eq 'HASH') {
8172: $lastactref->{'domainconfig'} = 1;
8173: }
1.28 raeburn 8174: my ($titles,$short_titles) = &contact_titles();
8175: $resulttext = &mt('Changes made:').'<ul>';
8176: foreach my $item (@contacts) {
8177: if ($changes{$item}) {
8178: $resulttext .= '<li>'.$titles->{$item}.
8179: &mt(' set to: ').
8180: '<span class="LC_cusr_emph">'.
8181: $to{$item}.'</span></li>';
8182: }
8183: }
8184: foreach my $type (@mailings) {
8185: if (ref($changes{$type}) eq 'ARRAY') {
8186: $resulttext .= '<li>'.$titles->{$type}.': ';
8187: my @text;
8188: foreach my $item (@{$newsetting{$type}}) {
8189: push(@text,$short_titles->{$item});
8190: }
8191: if ($others{$type} ne '') {
8192: push(@text,$others{$type});
8193: }
8194: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8195: join(', ',@text).'</span>';
8196: if ($type eq 'helpdeskmail') {
8197: if ($bcc{$type} ne '') {
8198: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8199: }
8200: }
8201: $resulttext .= '</li>';
1.28 raeburn 8202: }
8203: }
1.203 raeburn 8204: my @offon = ('off','on');
8205: if ($changes{'reporterrors'}) {
8206: $resulttext .= '<li>'.
8207: &mt('E-mail error reports to [_1] set to "'.
8208: $offon[$env{'form.reporterrors'}].'".',
8209: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8210: &mt('LON-CAPA core group - MSU'),600,500)).
8211: '</li>';
8212: }
8213: if ($changes{'reportupdates'}) {
8214: $resulttext .= '<li>'.
8215: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8216: $offon[$env{'form.reportupdates'}].'".',
8217: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8218: &mt('LON-CAPA core group - MSU'),600,500)).
8219: '</li>';
8220: }
1.28 raeburn 8221: $resulttext .= '</ul>';
8222: } else {
1.34 raeburn 8223: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8224: }
8225: } else {
8226: $resulttext = '<span class="LC_error">'.
8227: &mt('An error occurred: [_1].',$putresult).'</span>';
8228: }
8229: return $resulttext;
8230: }
8231:
8232: sub modify_usercreation {
1.27 raeburn 8233: my ($dom,%domconfig) = @_;
1.224 raeburn 8234: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8235: my $warningmsg;
1.27 raeburn 8236: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8237: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8238: if ($key eq 'cancreate') {
8239: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8240: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8241: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8242: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8243: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8244: } else {
8245: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8246: }
8247: }
8248: }
8249: } elsif ($key eq 'email_rule') {
8250: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8251: } else {
8252: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8253: }
1.27 raeburn 8254: }
8255: }
8256: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8257: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8258: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8259: foreach my $item(@contexts) {
1.224 raeburn 8260: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8261: }
1.34 raeburn 8262: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8263: foreach my $item (@contexts) {
1.224 raeburn 8264: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8265: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8266: }
1.27 raeburn 8267: }
1.34 raeburn 8268: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8269: foreach my $item (@contexts) {
1.43 raeburn 8270: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8271: if ($cancreate{$item} ne 'any') {
8272: push(@{$changes{'cancreate'}},$item);
8273: }
8274: } else {
8275: if ($cancreate{$item} ne 'none') {
8276: push(@{$changes{'cancreate'}},$item);
8277: }
1.27 raeburn 8278: }
8279: }
8280: } else {
1.43 raeburn 8281: foreach my $item (@contexts) {
1.34 raeburn 8282: push(@{$changes{'cancreate'}},$item);
8283: }
1.27 raeburn 8284: }
1.34 raeburn 8285:
1.27 raeburn 8286: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8287: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8288: if (!grep(/^\Q$type\E$/,@username_rule)) {
8289: push(@{$changes{'username_rule'}},$type);
8290: }
8291: }
8292: foreach my $type (@username_rule) {
8293: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8294: push(@{$changes{'username_rule'}},$type);
8295: }
8296: }
8297: } else {
8298: push(@{$changes{'username_rule'}},@username_rule);
8299: }
8300:
1.32 raeburn 8301: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8302: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8303: if (!grep(/^\Q$type\E$/,@id_rule)) {
8304: push(@{$changes{'id_rule'}},$type);
8305: }
8306: }
8307: foreach my $type (@id_rule) {
8308: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8309: push(@{$changes{'id_rule'}},$type);
8310: }
8311: }
8312: } else {
8313: push(@{$changes{'id_rule'}},@id_rule);
8314: }
8315:
1.43 raeburn 8316: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8317: my @authtypes = ('int','krb4','krb5','loc');
8318: my %authhash;
1.43 raeburn 8319: foreach my $item (@authen_contexts) {
1.28 raeburn 8320: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8321: foreach my $auth (@authtypes) {
8322: if (grep(/^\Q$auth\E$/,@authallowed)) {
8323: $authhash{$item}{$auth} = 1;
8324: } else {
8325: $authhash{$item}{$auth} = 0;
8326: }
8327: }
8328: }
8329: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8330: foreach my $item (@authen_contexts) {
1.28 raeburn 8331: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8332: foreach my $auth (@authtypes) {
8333: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8334: push(@{$changes{'authtypes'}},$item);
8335: last;
8336: }
8337: }
8338: }
8339: }
8340: } else {
1.43 raeburn 8341: foreach my $item (@authen_contexts) {
1.28 raeburn 8342: push(@{$changes{'authtypes'}},$item);
8343: }
8344: }
8345:
1.224 raeburn 8346: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8347: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8348: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8349: $save_usercreate{'id_rule'} = \@id_rule;
8350: $save_usercreate{'username_rule'} = \@username_rule,
8351: $save_usercreate{'authtypes'} = \%authhash;
8352:
1.27 raeburn 8353: my %usercreation_hash = (
1.224 raeburn 8354: usercreation => \%save_usercreate,
8355: );
1.27 raeburn 8356:
8357: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8358: $dom);
1.50 raeburn 8359:
1.224 raeburn 8360: if ($putresult eq 'ok') {
8361: if (keys(%changes) > 0) {
8362: $resulttext = &mt('Changes made:').'<ul>';
8363: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8364: my %lt = &usercreation_types();
8365: foreach my $type (@{$changes{'cancreate'}}) {
8366: my $chgtext = $lt{$type}.', ';
8367: if ($cancreate{$type} eq 'none') {
8368: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8369: } elsif ($cancreate{$type} eq 'any') {
8370: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8371: } elsif ($cancreate{$type} eq 'official') {
8372: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8373: } elsif ($cancreate{$type} eq 'unofficial') {
8374: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8375: }
8376: $resulttext .= '<li>'.$chgtext.'</li>';
8377: }
8378: }
8379: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8380: my ($rules,$ruleorder) =
8381: &Apache::lonnet::inst_userrules($dom,'username');
8382: my $chgtext = '<ul>';
8383: foreach my $type (@username_rule) {
8384: if (ref($rules->{$type}) eq 'HASH') {
8385: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8386: }
8387: }
8388: $chgtext .= '</ul>';
8389: if (@username_rule > 0) {
8390: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8391: } else {
8392: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8393: }
8394: }
8395: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8396: my ($idrules,$idruleorder) =
8397: &Apache::lonnet::inst_userrules($dom,'id');
8398: my $chgtext = '<ul>';
8399: foreach my $type (@id_rule) {
8400: if (ref($idrules->{$type}) eq 'HASH') {
8401: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8402: }
8403: }
8404: $chgtext .= '</ul>';
8405: if (@id_rule > 0) {
8406: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8407: } else {
8408: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8409: }
8410: }
8411: my %authname = &authtype_names();
8412: my %context_title = &context_names();
8413: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8414: my $chgtext = '<ul>';
8415: foreach my $type (@{$changes{'authtypes'}}) {
8416: my @allowed;
8417: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8418: foreach my $auth (@authtypes) {
8419: if ($authhash{$type}{$auth}) {
8420: push(@allowed,$authname{$auth});
8421: }
8422: }
8423: if (@allowed > 0) {
8424: $chgtext .= join(', ',@allowed).'</li>';
8425: } else {
8426: $chgtext .= &mt('none').'</li>';
8427: }
8428: }
8429: $chgtext .= '</ul>';
8430: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8431: $resulttext .= '</li>';
8432: }
8433: $resulttext .= '</ul>';
8434: } else {
8435: $resulttext = &mt('No changes made to user creation settings');
8436: }
8437: } else {
8438: $resulttext = '<span class="LC_error">'.
8439: &mt('An error occurred: [_1]',$putresult).'</span>';
8440: }
8441: if ($warningmsg ne '') {
8442: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8443: }
8444: return $resulttext;
8445: }
8446:
8447: sub modify_selfcreation {
8448: my ($dom,%domconfig) = @_;
8449: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8450: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8451: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8452: if (ref($types) eq 'ARRAY') {
8453: $usertypes->{'default'} = $othertitle;
8454: push(@{$types},'default');
8455: }
1.224 raeburn 8456: #
8457: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8458: #
8459: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8460: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8461: if ($key eq 'cancreate') {
8462: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8463: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8464: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8465: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8466: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 8467: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 8468: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8469: } else {
8470: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8471: }
8472: }
8473: }
8474: } elsif ($key eq 'email_rule') {
8475: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8476: } else {
8477: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8478: }
8479: }
8480: }
8481: #
8482: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8483: #
8484: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8485: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8486: if ($key eq 'selfcreate') {
8487: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8488: } else {
8489: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8490: }
8491: }
8492: }
8493:
8494: my @contexts = ('selfcreate');
8495: @{$cancreate{'selfcreate'}} = ();
8496: %{$cancreate{'emailusername'}} = ();
8497: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8498: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 8499: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8500: my %selfcreatetypes = (
8501: sso => 'users authenticated by institutional single sign on',
8502: login => 'users authenticated by institutional log-in',
1.236 raeburn 8503: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8504: );
1.224 raeburn 8505: #
8506: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8507: # is permitted.
8508: #
1.236 raeburn 8509:
8510: my @statuses;
8511: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8512: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8513: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8514: }
8515: }
8516: push(@statuses,'default');
8517:
1.228 raeburn 8518: foreach my $item ('login','sso','email') {
1.224 raeburn 8519: if ($item eq 'email') {
1.236 raeburn 8520: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8521: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8522: push(@contexts,'selfcreateprocessing');
8523: foreach my $type (@statuses) {
8524: if ($type eq 'default') {
8525: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8526: } else {
8527: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8528: }
8529: }
1.224 raeburn 8530: }
8531: } else {
8532: if ($env{'form.cancreate_'.$item}) {
8533: push(@{$cancreate{'selfcreate'}},$item);
8534: }
8535: }
8536: }
8537: my (@email_rule,%userinfo,%savecaptcha);
8538: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8539: #
1.228 raeburn 8540: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8541: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8542: #
1.236 raeburn 8543:
1.244 raeburn 8544: if ($env{'form.cancreate_email'}) {
1.228 raeburn 8545: push(@contexts,'emailusername');
8546: if (ref($types) eq 'ARRAY') {
8547: foreach my $type (@{$types}) {
8548: if (ref($infofields) eq 'ARRAY') {
8549: foreach my $field (@{$infofields}) {
8550: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8551: $cancreate{'emailusername'}{$type}{$field} = $1;
8552: }
8553: }
1.224 raeburn 8554: }
8555: }
8556: }
8557: #
8558: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8559: # queued requests for self-creation of account using e-mail address as username
8560: #
8561:
8562: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8563: @approvalnotify = sort(@approvalnotify);
8564: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8565: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8566: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8567: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8568: push(@{$changes{'cancreate'}},'notify');
8569: }
8570: } else {
8571: if ($cancreate{'notify'}{'approval'}) {
8572: push(@{$changes{'cancreate'}},'notify');
8573: }
8574: }
8575: } elsif ($cancreate{'notify'}{'approval'}) {
8576: push(@{$changes{'cancreate'}},'notify');
8577: }
8578:
8579: #
8580: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8581: #
8582: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8583: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8584: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8585: if (@{$curr_usercreation{'email_rule'}} > 0) {
8586: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8587: if (!grep(/^\Q$type\E$/,@email_rule)) {
8588: push(@{$changes{'email_rule'}},$type);
8589: }
8590: }
8591: }
8592: if (@email_rule > 0) {
8593: foreach my $type (@email_rule) {
8594: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8595: push(@{$changes{'email_rule'}},$type);
8596: }
8597: }
8598: }
8599: } elsif (@email_rule > 0) {
8600: push(@{$changes{'email_rule'}},@email_rule);
8601: }
8602: }
8603: #
1.236 raeburn 8604: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8605: # institutional log-in.
8606: #
8607: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8608: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8609: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8610: ($domdefaults{'auth_def'} eq 'localauth'))) {
8611: $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.').' '.
8612: &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.');
8613: }
8614: }
8615: my @fields = ('lastname','firstname','middlename','generation',
8616: 'permanentemail','id');
1.240 raeburn 8617: my @shibfields = (@fields,'inststatus');
1.224 raeburn 8618: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8619: #
8620: # Where usernames may created for institutional log-in and/or institutional single sign on:
8621: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8622: # may self-create accounts
8623: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8624: # which the user may supply, if institutional data is unavailable.
8625: #
8626: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8627: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8628: if (@{$types} > 1) {
1.224 raeburn 8629: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8630: push(@contexts,'statustocreate');
8631: } else {
8632: undef($cancreate{'statustocreate'});
8633: }
8634: foreach my $type (@{$types}) {
8635: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8636: foreach my $field (@fields) {
8637: if (grep(/^\Q$field\E$/,@modifiable)) {
8638: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8639: } else {
8640: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8641: }
8642: }
8643: }
8644: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8645: foreach my $type (@{$types}) {
8646: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8647: foreach my $field (@fields) {
8648: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8649: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8650: push(@{$changes{'selfcreate'}},$type);
8651: last;
8652: }
8653: }
8654: }
8655: }
8656: } else {
8657: foreach my $type (@{$types}) {
8658: push(@{$changes{'selfcreate'}},$type);
8659: }
8660: }
8661: }
1.240 raeburn 8662: foreach my $field (@shibfields) {
8663: if ($env{'form.shibenv_'.$field} ne '') {
8664: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8665: }
8666: }
8667: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8668: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8669: foreach my $field (@shibfields) {
8670: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8671: push(@{$changes{'cancreate'}},'shibenv');
8672: }
8673: }
8674: } else {
8675: foreach my $field (@shibfields) {
8676: if ($env{'form.shibenv_'.$field}) {
8677: push(@{$changes{'cancreate'}},'shibenv');
8678: last;
8679: }
8680: }
8681: }
8682: }
1.224 raeburn 8683: }
8684: foreach my $item (@contexts) {
8685: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8686: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8687: if (ref($cancreate{$item}) eq 'ARRAY') {
8688: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8689: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8690: push(@{$changes{'cancreate'}},$item);
8691: }
8692: }
8693: }
8694: }
8695: if (ref($cancreate{$item}) eq 'ARRAY') {
8696: foreach my $type (@{$cancreate{$item}}) {
8697: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8698: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8699: push(@{$changes{'cancreate'}},$item);
8700: }
8701: }
8702: }
8703: }
8704: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8705: if (ref($cancreate{$item}) eq 'HASH') {
8706: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8707: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8708: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8709: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8710: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8711: push(@{$changes{'cancreate'}},$item);
8712: }
8713: }
8714: }
1.236 raeburn 8715: } elsif ($item eq 'selfcreateprocessing') {
8716: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8717: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8718: push(@{$changes{'cancreate'}},$item);
8719: }
8720: }
1.228 raeburn 8721: } else {
8722: if (!$cancreate{$item}{$curr}) {
8723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8724: push(@{$changes{'cancreate'}},$item);
8725: }
1.224 raeburn 8726: }
8727: }
8728: }
8729: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8730: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8731: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8732: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8733: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8734: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8735: push(@{$changes{'cancreate'}},$item);
8736: }
8737: }
8738: } else {
8739: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8740: push(@{$changes{'cancreate'}},$item);
8741: }
8742: }
8743: }
1.236 raeburn 8744: } elsif ($item eq 'selfcreateprocessing') {
8745: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8746: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8747: push(@{$changes{'cancreate'}},$item);
8748: }
8749: }
1.228 raeburn 8750: } else {
8751: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8752: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8753: push(@{$changes{'cancreate'}},$item);
8754: }
1.224 raeburn 8755: }
8756: }
8757: }
8758: }
8759: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8760: if (ref($cancreate{$item}) eq 'ARRAY') {
8761: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8762: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8763: push(@{$changes{'cancreate'}},$item);
8764: }
8765: }
8766: } elsif (ref($cancreate{$item}) eq 'HASH') {
8767: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8768: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8769: push(@{$changes{'cancreate'}},$item);
8770: }
8771: }
8772: }
8773: } elsif ($item eq 'emailusername') {
1.228 raeburn 8774: if (ref($cancreate{$item}) eq 'HASH') {
8775: foreach my $type (keys(%{$cancreate{$item}})) {
8776: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8777: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8778: if ($cancreate{$item}{$type}{$field}) {
8779: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8780: push(@{$changes{'cancreate'}},$item);
8781: }
8782: last;
8783: }
8784: }
8785: }
8786: }
1.224 raeburn 8787: }
8788: }
8789: }
8790: #
8791: # Populate %save_usercreate hash with updates to self-creation configuration.
8792: #
8793: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8794: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8795: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8796: if (ref($cancreate{'notify'}) eq 'HASH') {
8797: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8798: }
1.236 raeburn 8799: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8800: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8801: }
1.224 raeburn 8802: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8803: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8804: }
1.240 raeburn 8805: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8806: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8807: }
1.224 raeburn 8808: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8809: $save_usercreate{'emailrule'} = \@email_rule;
8810:
8811: my %userconfig_hash = (
8812: usercreation => \%save_usercreate,
8813: usermodification => \%save_usermodify,
8814: );
8815: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8816: $dom);
8817: #
8818: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8819: #
1.27 raeburn 8820: if ($putresult eq 'ok') {
8821: if (keys(%changes) > 0) {
8822: $resulttext = &mt('Changes made:').'<ul>';
8823: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8824: my %lt = &selfcreation_types();
1.34 raeburn 8825: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8826: my $chgtext;
1.45 raeburn 8827: if ($type eq 'selfcreate') {
1.50 raeburn 8828: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8829: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8830: } else {
1.224 raeburn 8831: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8832: '<ul>';
1.50 raeburn 8833: foreach my $case (@{$cancreate{$type}}) {
8834: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8835: }
8836: $chgtext .= '</ul>';
1.100 raeburn 8837: if (ref($cancreate{$type}) eq 'ARRAY') {
8838: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8839: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8840: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8841: $chgtext .= '<br />'.
8842: '<span class="LC_warning">'.
8843: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8844: '</span>';
1.100 raeburn 8845: }
8846: }
8847: }
8848: }
1.43 raeburn 8849: }
1.240 raeburn 8850: } elsif ($type eq 'shibenv') {
8851: if (keys(%{$cancreate{$type}}) == 0) {
8852: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8853: } else {
8854: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8855: '<ul>';
8856: foreach my $field (@shibfields) {
8857: next if ($cancreate{$type}{$field} eq '');
8858: if ($field eq 'inststatus') {
8859: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8860: } else {
8861: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8862: }
8863: }
8864: $chgtext .= '</ul>';
8865: }
1.93 raeburn 8866: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8867: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8868: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8869: if (@{$cancreate{'selfcreate'}} > 0) {
8870: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8871: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8872: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8873: $chgtext .= '<br />'.
8874: '<span class="LC_warning">'.
8875: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8876: '</span>';
8877: }
1.96 raeburn 8878: } elsif (ref($usertypes) eq 'HASH') {
8879: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8880: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8881: } else {
8882: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8883: }
8884: $chgtext .= '<ul>';
8885: foreach my $case (@{$cancreate{$type}}) {
8886: if ($case eq 'default') {
8887: $chgtext .= '<li>'.$othertitle.'</li>';
8888: } else {
8889: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8890: }
8891: }
1.100 raeburn 8892: $chgtext .= '</ul>';
8893: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8894: $chgtext .= '<br /><span class="LC_warning">'.
8895: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8896: '</span>';
1.100 raeburn 8897: }
8898: }
8899: } else {
8900: if (@{$cancreate{$type}} == 0) {
8901: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8902: } else {
8903: $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 8904: }
8905: }
8906: }
1.236 raeburn 8907: } elsif ($type eq 'selfcreateprocessing') {
8908: my %choices = &Apache::lonlocal::texthash (
8909: automatic => 'Automatic approval',
8910: approval => 'Queued for approval',
8911: );
8912: if (@statuses > 1) {
8913: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8914: '<ul>';
8915: foreach my $type (@statuses) {
8916: if ($type eq 'default') {
8917: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8918: } else {
8919: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8920: }
8921: }
8922: $chgtext .= '</ul>';
8923: } else {
8924: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8925: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8926: }
1.165 raeburn 8927: } elsif ($type eq 'captcha') {
1.224 raeburn 8928: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8929: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8930: } else {
8931: my %captchas = &captcha_phrases();
1.224 raeburn 8932: if ($captchas{$savecaptcha{$type}}) {
8933: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8934: } else {
1.210 raeburn 8935: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8936: }
8937: }
8938: } elsif ($type eq 'recaptchakeys') {
8939: my ($privkey,$pubkey);
1.224 raeburn 8940: if (ref($savecaptcha{$type}) eq 'HASH') {
8941: $pubkey = $savecaptcha{$type}{'public'};
8942: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8943: }
8944: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8945: if (!$pubkey) {
8946: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8947: } else {
8948: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8949: }
8950: if (!$privkey) {
8951: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8952: } else {
8953: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8954: }
8955: $chgtext .= '</ul>';
1.224 raeburn 8956: } elsif ($type eq 'emailusername') {
8957: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8958: if (ref($types) eq 'ARRAY') {
8959: foreach my $type (@{$types}) {
8960: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8961: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 8962: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 8963: '<ul>';
8964: foreach my $field (@{$infofields}) {
8965: if ($cancreate{'emailusername'}{$type}{$field}) {
8966: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8967: }
8968: }
1.245 raeburn 8969: $chgtext .= '</ul>';
8970: } else {
8971: $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 8972: }
8973: } else {
1.245 raeburn 8974: $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 8975: }
8976: }
8977: }
8978: }
8979: } elsif ($type eq 'notify') {
8980: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8981: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8982: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8983: if ($cancreate{'notify'}{'approval'}) {
8984: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8985: }
8986: }
1.43 raeburn 8987: }
1.34 raeburn 8988: }
1.224 raeburn 8989: if ($chgtext) {
8990: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8991: }
8992: }
8993: }
1.43 raeburn 8994: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8995: my ($emailrules,$emailruleorder) =
8996: &Apache::lonnet::inst_userrules($dom,'email');
8997: my $chgtext = '<ul>';
8998: foreach my $type (@email_rule) {
8999: if (ref($emailrules->{$type}) eq 'HASH') {
9000: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9001: }
9002: }
9003: $chgtext .= '</ul>';
9004: if (@email_rule > 0) {
1.224 raeburn 9005: $resulttext .= '<li>'.
9006: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9007: $chgtext.
9008: '</li>';
1.43 raeburn 9009: } else {
1.224 raeburn 9010: $resulttext .= '<li>'.
9011: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9012: '</li>';
1.43 raeburn 9013: }
9014: }
1.224 raeburn 9015: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9016: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9017: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9018: foreach my $type (@{$changes{'selfcreate'}}) {
9019: my $typename = $type;
9020: if (ref($usertypes) eq 'HASH') {
9021: if ($usertypes->{$type} ne '') {
9022: $typename = $usertypes->{$type};
9023: }
9024: }
9025: my @modifiable;
9026: $resulttext .= '<li>'.
9027: &mt('Self-creation of account by users with status: [_1]',
9028: '<span class="LC_cusr_emph">'.$typename.'</span>').
9029: ' - '.&mt('modifiable fields (if institutional data blank): ');
9030: foreach my $field (@fields) {
9031: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9032: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 9033: }
9034: }
1.224 raeburn 9035: if (@modifiable > 0) {
9036: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9037: } else {
1.224 raeburn 9038: $resulttext .= &mt('none');
1.43 raeburn 9039: }
1.224 raeburn 9040: $resulttext .= '</li>';
1.28 raeburn 9041: }
1.224 raeburn 9042: $resulttext .= '</ul></li>';
1.28 raeburn 9043: }
1.27 raeburn 9044: $resulttext .= '</ul>';
9045: } else {
1.224 raeburn 9046: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9047: }
9048: } else {
9049: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9050: &mt('An error occurred: [_1]',$putresult).'</span>';
9051: }
1.43 raeburn 9052: if ($warningmsg ne '') {
9053: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9054: }
1.23 raeburn 9055: return $resulttext;
9056: }
9057:
1.165 raeburn 9058: sub process_captcha {
9059: my ($container,$changes,$newsettings,$current) = @_;
9060: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9061: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9062: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9063: $newsettings->{'captcha'} = 'original';
9064: }
9065: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 9066: if ($container eq 'cancreate') {
1.169 raeburn 9067: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9068: push(@{$changes->{'cancreate'}},'captcha');
9069: } elsif (!defined($changes->{'cancreate'})) {
9070: $changes->{'cancreate'} = ['captcha'];
9071: }
9072: } else {
9073: $changes->{'captcha'} = 1;
1.165 raeburn 9074: }
9075: }
9076: my ($newpub,$newpriv,$currpub,$currpriv);
9077: if ($newsettings->{'captcha'} eq 'recaptcha') {
9078: $newpub = $env{'form.'.$container.'_recaptchapub'};
9079: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 9080: $newpub =~ s/[^\w\-]//g;
9081: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 9082: $newsettings->{'recaptchakeys'} = {
9083: public => $newpub,
9084: private => $newpriv,
9085: };
1.165 raeburn 9086: }
9087: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9088: $currpub = $current->{'recaptchakeys'}{'public'};
9089: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 9090: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9091: $newsettings->{'recaptchakeys'} = {
9092: public => '',
9093: private => '',
9094: }
9095: }
1.165 raeburn 9096: }
9097: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 9098: if ($container eq 'cancreate') {
9099: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9100: push(@{$changes->{'cancreate'}},'recaptchakeys');
9101: } elsif (!defined($changes->{'cancreate'})) {
9102: $changes->{'cancreate'} = ['recaptchakeys'];
9103: }
9104: } else {
1.210 raeburn 9105: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 9106: }
9107: }
9108: return;
9109: }
9110:
1.33 raeburn 9111: sub modify_usermodification {
9112: my ($dom,%domconfig) = @_;
1.224 raeburn 9113: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9114: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9115: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 9116: if ($key eq 'selfcreate') {
9117: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9118: } else {
9119: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9120: }
1.33 raeburn 9121: }
9122: }
1.224 raeburn 9123: my @contexts = ('author','course');
1.33 raeburn 9124: my %context_title = (
9125: author => 'In author context',
9126: course => 'In course context',
9127: );
9128: my @fields = ('lastname','firstname','middlename','generation',
9129: 'permanentemail','id');
9130: my %roles = (
9131: author => ['ca','aa'],
9132: course => ['st','ep','ta','in','cr'],
9133: );
9134: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9135: foreach my $context (@contexts) {
9136: foreach my $role (@{$roles{$context}}) {
9137: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9138: foreach my $item (@fields) {
9139: if (grep(/^\Q$item\E$/,@modifiable)) {
9140: $modifyhash{$context}{$role}{$item} = 1;
9141: } else {
9142: $modifyhash{$context}{$role}{$item} = 0;
9143: }
9144: }
9145: }
9146: if (ref($curr_usermodification{$context}) eq 'HASH') {
9147: foreach my $role (@{$roles{$context}}) {
9148: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9149: foreach my $field (@fields) {
9150: if ($modifyhash{$context}{$role}{$field} ne
9151: $curr_usermodification{$context}{$role}{$field}) {
9152: push(@{$changes{$context}},$role);
9153: last;
9154: }
9155: }
9156: }
9157: }
9158: } else {
9159: foreach my $context (@contexts) {
9160: foreach my $role (@{$roles{$context}}) {
9161: push(@{$changes{$context}},$role);
9162: }
9163: }
9164: }
9165: }
9166: my %usermodification_hash = (
9167: usermodification => \%modifyhash,
9168: );
9169: my $putresult = &Apache::lonnet::put_dom('configuration',
9170: \%usermodification_hash,$dom);
9171: if ($putresult eq 'ok') {
9172: if (keys(%changes) > 0) {
9173: $resulttext = &mt('Changes made: ').'<ul>';
9174: foreach my $context (@contexts) {
9175: if (ref($changes{$context}) eq 'ARRAY') {
9176: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9177: if (ref($changes{$context}) eq 'ARRAY') {
9178: foreach my $role (@{$changes{$context}}) {
9179: my $rolename;
1.224 raeburn 9180: if ($role eq 'cr') {
9181: $rolename = &mt('Custom');
1.33 raeburn 9182: } else {
1.224 raeburn 9183: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9184: }
9185: my @modifiable;
1.224 raeburn 9186: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9187: foreach my $field (@fields) {
9188: if ($modifyhash{$context}{$role}{$field}) {
9189: push(@modifiable,$fieldtitles{$field});
9190: }
9191: }
9192: if (@modifiable > 0) {
9193: $resulttext .= join(', ',@modifiable);
9194: } else {
9195: $resulttext .= &mt('none');
9196: }
9197: $resulttext .= '</li>';
9198: }
9199: $resulttext .= '</ul></li>';
9200: }
9201: }
9202: }
9203: $resulttext .= '</ul>';
9204: } else {
9205: $resulttext = &mt('No changes made to user modification settings');
9206: }
9207: } else {
9208: $resulttext = '<span class="LC_error">'.
9209: &mt('An error occurred: [_1]',$putresult).'</span>';
9210: }
9211: return $resulttext;
9212: }
9213:
1.43 raeburn 9214: sub modify_defaults {
1.212 raeburn 9215: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9216: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9217: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9218: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9219: my @authtypes = ('internal','krb4','krb5','localauth');
9220: foreach my $item (@items) {
9221: $newvalues{$item} = $env{'form.'.$item};
9222: if ($item eq 'auth_def') {
9223: if ($newvalues{$item} ne '') {
9224: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9225: push(@errors,$item);
9226: }
9227: }
9228: } elsif ($item eq 'lang_def') {
9229: if ($newvalues{$item} ne '') {
9230: if ($newvalues{$item} =~ /^(\w+)/) {
9231: my $langcode = $1;
1.103 raeburn 9232: if ($langcode ne 'x_chef') {
9233: if (code2language($langcode) eq '') {
9234: push(@errors,$item);
9235: }
1.43 raeburn 9236: }
9237: } else {
9238: push(@errors,$item);
9239: }
9240: }
1.54 raeburn 9241: } elsif ($item eq 'timezone_def') {
9242: if ($newvalues{$item} ne '') {
1.62 raeburn 9243: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9244: push(@errors,$item);
9245: }
9246: }
1.68 raeburn 9247: } elsif ($item eq 'datelocale_def') {
9248: if ($newvalues{$item} ne '') {
9249: my @datelocale_ids = DateTime::Locale->ids();
9250: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9251: push(@errors,$item);
9252: }
9253: }
1.141 raeburn 9254: } elsif ($item eq 'portal_def') {
9255: if ($newvalues{$item} ne '') {
9256: 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])\/?$/) {
9257: push(@errors,$item);
9258: }
9259: }
1.43 raeburn 9260: }
9261: if (grep(/^\Q$item\E$/,@errors)) {
9262: $newvalues{$item} = $domdefaults{$item};
9263: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9264: $changes{$item} = 1;
9265: }
1.72 raeburn 9266: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9267: }
9268: my %defaults_hash = (
1.72 raeburn 9269: defaults => \%newvalues,
9270: );
1.43 raeburn 9271: my $title = &defaults_titles();
1.236 raeburn 9272:
9273: my $currinststatus;
9274: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9275: $currinststatus = $domconfig{'inststatus'};
9276: } else {
9277: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9278: $currinststatus = {
9279: inststatustypes => $usertypes,
9280: inststatusorder => $types,
9281: inststatusguest => [],
9282: };
9283: }
9284: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9285: my @allpos;
9286: my %guests;
9287: my %alltypes;
9288: my ($currtitles,$currguests,$currorder);
9289: if (ref($currinststatus) eq 'HASH') {
9290: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9291: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9292: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9293: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9294: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9295: }
9296: }
9297: unless (grep(/^\Q$type\E$/,@todelete)) {
9298: my $position = $env{'form.inststatus_pos_'.$type};
9299: $position =~ s/\D+//g;
9300: $allpos[$position] = $type;
9301: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9302: $alltypes{$type} =~ s/`//g;
9303: if ($env{'form.inststatus_guest_'.$type}) {
9304: $guests{$type} = 1;
9305: }
9306: }
9307: }
9308: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9309: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9310: }
9311: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9312: $currtitles =~ s/,$//;
9313: }
9314: }
9315: if ($env{'form.addinststatus'}) {
9316: my $newtype = $env{'form.addinststatus'};
9317: $newtype =~ s/\W//g;
9318: unless (exists($alltypes{$newtype})) {
9319: if ($env{'form.addinststatus_guest'}) {
9320: $guests{$newtype} = 1;
9321: }
9322: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9323: $alltypes{$newtype} =~ s/`//g;
9324: my $position = $env{'form.addinststatus_pos'};
9325: $position =~ s/\D+//g;
9326: if ($position ne '') {
9327: $allpos[$position] = $newtype;
9328: }
9329: }
9330: }
9331: my (@orderedstatus,@orderedguests);
9332: foreach my $type (@allpos) {
9333: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9334: push(@orderedstatus,$type);
9335: if ($guests{$type}) {
9336: push(@orderedguests,$type);
9337: }
9338: }
9339: }
9340: foreach my $type (keys(%alltypes)) {
9341: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9342: delete($alltypes{$type});
9343: }
9344: }
9345: $defaults_hash{'inststatus'} = {
9346: inststatustypes => \%alltypes,
9347: inststatusorder => \@orderedstatus,
9348: inststatusguest => \@orderedguests,
9349: };
9350: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9351: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9352: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9353: }
9354: }
9355: if ($currorder ne join(',',@orderedstatus)) {
9356: $changes{'inststatus'}{'inststatusorder'} = 1;
9357: }
9358: if ($currguests ne join(',',@orderedguests)) {
9359: $changes{'inststatus'}{'inststatusguest'} = 1;
9360: }
9361: my $newtitles;
9362: foreach my $item (@orderedstatus) {
9363: $newtitles .= $alltypes{$item}.',';
9364: }
9365: $newtitles =~ s/,$//;
9366: if ($currtitles ne $newtitles) {
9367: $changes{'inststatus'}{'inststatustypes'} = 1;
9368: }
1.43 raeburn 9369: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9370: $dom);
9371: if ($putresult eq 'ok') {
9372: if (keys(%changes) > 0) {
9373: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9374: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9375: 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";
9376: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9377: if ($item eq 'inststatus') {
9378: if (ref($changes{'inststatus'}) eq 'HASH') {
9379: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9380: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9381: foreach my $type (@orderedstatus) {
9382: $resulttext .= $alltypes{$type}.', ';
9383: }
9384: $resulttext =~ s/, $//;
9385: $resulttext .= '</li>';
9386: }
9387: if ($changes{'inststatus'}{'inststatusguest'}) {
9388: $resulttext .= '<li>';
9389: if (@orderedguests) {
9390: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9391: foreach my $type (@orderedguests) {
9392: $resulttext .= $alltypes{$type}.', ';
9393: }
9394: $resulttext =~ s/, $//;
9395: } else {
9396: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9397: }
9398: $resulttext .= '</li>';
9399: }
9400: }
9401: } else {
9402: my $value = $env{'form.'.$item};
9403: if ($value eq '') {
9404: $value = &mt('none');
9405: } elsif ($item eq 'auth_def') {
9406: my %authnames = &authtype_names();
9407: my %shortauth = (
9408: internal => 'int',
9409: krb4 => 'krb4',
9410: krb5 => 'krb5',
9411: localauth => 'loc',
9412: );
9413: $value = $authnames{$shortauth{$value}};
9414: }
9415: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9416: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9417: }
9418: }
9419: $resulttext .= '</ul>';
9420: $mailmsgtext .= "\n";
9421: my $cachetime = 24*60*60;
1.72 raeburn 9422: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9423: if (ref($lastactref) eq 'HASH') {
9424: $lastactref->{'domdefaults'} = 1;
9425: }
1.68 raeburn 9426: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9427: my $notify = 1;
9428: if (ref($domconfig{'contacts'}) eq 'HASH') {
9429: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9430: $notify = 0;
9431: }
9432: }
9433: if ($notify) {
9434: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9435: "LON-CAPA Domain Settings Change - $dom",
9436: $mailmsgtext);
9437: }
1.54 raeburn 9438: }
1.43 raeburn 9439: } else {
1.54 raeburn 9440: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9441: }
9442: } else {
9443: $resulttext = '<span class="LC_error">'.
9444: &mt('An error occurred: [_1]',$putresult).'</span>';
9445: }
9446: if (@errors > 0) {
9447: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9448: foreach my $item (@errors) {
9449: $resulttext .= ' "'.$title->{$item}.'",';
9450: }
9451: $resulttext =~ s/,$//;
9452: }
9453: return $resulttext;
9454: }
9455:
1.46 raeburn 9456: sub modify_scantron {
1.205 raeburn 9457: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9458: my ($resulttext,%confhash,%changes,$errors);
9459: my $custom = 'custom.tab';
9460: my $default = 'default.tab';
9461: my $servadm = $r->dir_config('lonAdmEMail');
9462: my ($configuserok,$author_ok,$switchserver) =
9463: &config_check($dom,$confname,$servadm);
9464: if ($env{'form.scantronformat.filename'} ne '') {
9465: my $error;
9466: if ($configuserok eq 'ok') {
9467: if ($switchserver) {
1.130 raeburn 9468: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9469: } else {
9470: if ($author_ok eq 'ok') {
9471: my ($result,$scantronurl) =
9472: &publishlogo($r,'upload','scantronformat',$dom,
9473: $confname,'scantron','','',$custom);
9474: if ($result eq 'ok') {
9475: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9476: $changes{'scantronformat'} = 1;
1.46 raeburn 9477: } else {
9478: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9479: }
9480: } else {
9481: $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);
9482: }
9483: }
9484: } else {
9485: $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);
9486: }
9487: if ($error) {
9488: &Apache::lonnet::logthis($error);
9489: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9490: }
9491: }
1.48 raeburn 9492: if (ref($domconfig{'scantron'}) eq 'HASH') {
9493: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9494: if ($env{'form.scantronformat_del'}) {
9495: $confhash{'scantron'}{'scantronformat'} = '';
9496: $changes{'scantronformat'} = 1;
1.46 raeburn 9497: }
9498: }
9499: }
9500: if (keys(%confhash) > 0) {
9501: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9502: $dom);
9503: if ($putresult eq 'ok') {
9504: if (keys(%changes) > 0) {
1.48 raeburn 9505: if (ref($confhash{'scantron'}) eq 'HASH') {
9506: $resulttext = &mt('Changes made:').'<ul>';
9507: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9508: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9509: } else {
1.130 raeburn 9510: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9511: }
1.48 raeburn 9512: $resulttext .= '</ul>';
9513: } else {
1.130 raeburn 9514: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9515: }
9516: $resulttext .= '</ul>';
9517: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9518: if (ref($lastactref) eq 'HASH') {
9519: $lastactref->{'domainconfig'} = 1;
9520: }
1.46 raeburn 9521: } else {
1.130 raeburn 9522: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9523: }
9524: } else {
9525: $resulttext = '<span class="LC_error">'.
9526: &mt('An error occurred: [_1]',$putresult).'</span>';
9527: }
9528: } else {
1.130 raeburn 9529: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9530: }
9531: if ($errors) {
9532: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9533: $errors.'</ul>';
9534: }
9535: return $resulttext;
9536: }
9537:
1.48 raeburn 9538: sub modify_coursecategories {
1.239 raeburn 9539: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9540: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9541: $cathash);
1.48 raeburn 9542: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 9543: my @catitems = ('unauth','auth');
9544: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9545: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9546: $cathash = $domconfig{'coursecategories'}{'cats'};
9547: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9548: $changes{'togglecats'} = 1;
9549: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9550: }
9551: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9552: $changes{'categorize'} = 1;
9553: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9554: }
1.120 raeburn 9555: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9556: $changes{'togglecatscomm'} = 1;
9557: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9558: }
9559: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9560: $changes{'categorizecomm'} = 1;
9561: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9562: }
1.238 raeburn 9563: foreach my $item (@catitems) {
9564: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9565: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9566: $changes{$item} = 1;
9567: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9568: }
9569: }
9570: }
1.57 raeburn 9571: } else {
9572: $changes{'togglecats'} = 1;
9573: $changes{'categorize'} = 1;
1.124 raeburn 9574: $changes{'togglecatscomm'} = 1;
9575: $changes{'categorizecomm'} = 1;
1.87 raeburn 9576: $domconfig{'coursecategories'} = {
9577: togglecats => $env{'form.togglecats'},
9578: categorize => $env{'form.categorize'},
1.124 raeburn 9579: togglecatscomm => $env{'form.togglecatscomm'},
9580: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9581: };
1.238 raeburn 9582: foreach my $item (@catitems) {
9583: if ($env{'form.coursecat_'.$item} ne 'std') {
9584: $changes{$item} = 1;
9585: }
9586: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9587: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9588: }
9589: }
1.57 raeburn 9590: }
9591: if (ref($cathash) eq 'HASH') {
9592: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9593: push (@deletecategory,'instcode::0');
9594: }
1.120 raeburn 9595: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9596: push(@deletecategory,'communities::0');
9597: }
1.48 raeburn 9598: }
1.57 raeburn 9599: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9600: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9601: if (@deletecategory > 0) {
9602: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9603: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9604: foreach my $item (@deletecategory) {
1.57 raeburn 9605: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9606: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9607: $deletions{$item} = 1;
1.57 raeburn 9608: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9609: }
9610: }
9611: }
1.57 raeburn 9612: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9613: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9614: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9615: $reorderings{$item} = 1;
1.57 raeburn 9616: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9617: }
9618: if ($env{'form.addcategory_name_'.$item} ne '') {
9619: my $newcat = $env{'form.addcategory_name_'.$item};
9620: my $newdepth = $depth+1;
9621: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9622: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9623: $adds{$newitem} = 1;
9624: }
9625: if ($env{'form.subcat_'.$item} ne '') {
9626: my $newcat = $env{'form.subcat_'.$item};
9627: my $newdepth = $depth+1;
9628: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9629: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9630: $adds{$newitem} = 1;
9631: }
9632: }
9633: }
9634: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9635: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9636: my $newitem = 'instcode::0';
1.57 raeburn 9637: if ($cathash->{$newitem} eq '') {
9638: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9639: $adds{$newitem} = 1;
9640: }
9641: } else {
9642: my $newitem = 'instcode::0';
1.57 raeburn 9643: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9644: $adds{$newitem} = 1;
9645: }
9646: }
1.120 raeburn 9647: if ($env{'form.communities'} eq '1') {
9648: if (ref($cathash) eq 'HASH') {
9649: my $newitem = 'communities::0';
9650: if ($cathash->{$newitem} eq '') {
9651: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9652: $adds{$newitem} = 1;
9653: }
9654: } else {
9655: my $newitem = 'communities::0';
9656: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9657: $adds{$newitem} = 1;
9658: }
9659: }
1.48 raeburn 9660: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9661: if (($env{'form.addcategory_name'} ne 'instcode') &&
9662: ($env{'form.addcategory_name'} ne 'communities')) {
9663: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9664: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9665: $adds{$newitem} = 1;
9666: }
1.48 raeburn 9667: }
1.57 raeburn 9668: my $putresult;
1.48 raeburn 9669: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9670: if (keys(%deletions) > 0) {
9671: foreach my $key (keys(%deletions)) {
9672: if ($predelallitems{$key} ne '') {
9673: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9674: }
9675: }
9676: }
9677: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9678: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9679: if (ref($chkcats[0]) eq 'ARRAY') {
9680: my $depth = 0;
9681: my $chg = 0;
9682: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9683: my $name = $chkcats[0][$i];
9684: my $item;
9685: if ($name eq '') {
9686: $chg ++;
9687: } else {
9688: $item = &escape($name).'::0';
9689: if ($chg) {
1.57 raeburn 9690: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9691: }
9692: $depth ++;
1.57 raeburn 9693: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9694: $depth --;
9695: }
9696: }
9697: }
1.57 raeburn 9698: }
9699: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9700: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9701: if ($putresult eq 'ok') {
1.57 raeburn 9702: my %title = (
1.120 raeburn 9703: togglecats => 'Show/Hide a course in catalog',
9704: categorize => 'Assign a category to a course',
9705: togglecatscomm => 'Show/Hide a community in catalog',
9706: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9707: );
9708: my %level = (
1.120 raeburn 9709: dom => 'set in Domain ("Modify Course/Community")',
9710: crs => 'set in Course ("Course Configuration")',
9711: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 9712: none => 'No catalog',
9713: std => 'Standard catalog',
9714: domonly => 'Domain-only catalog',
9715: codesrch => 'Code search form',
1.57 raeburn 9716: );
1.48 raeburn 9717: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9718: if ($changes{'togglecats'}) {
9719: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9720: }
9721: if ($changes{'categorize'}) {
9722: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9723: }
1.120 raeburn 9724: if ($changes{'togglecatscomm'}) {
9725: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9726: }
9727: if ($changes{'categorizecomm'}) {
9728: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9729: }
1.238 raeburn 9730: if ($changes{'unauth'}) {
9731: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9732: }
9733: if ($changes{'auth'}) {
9734: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9735: }
1.57 raeburn 9736: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9737: my $cathash;
9738: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9739: $cathash = $domconfig{'coursecategories'}{'cats'};
9740: } else {
9741: $cathash = {};
9742: }
9743: my (@cats,@trails,%allitems);
9744: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9745: if (keys(%deletions) > 0) {
9746: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9747: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9748: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9749: }
9750: $resulttext .= '</ul></li>';
9751: }
9752: if (keys(%reorderings) > 0) {
9753: my %sort_by_trail;
9754: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9755: foreach my $key (keys(%reorderings)) {
9756: if ($allitems{$key} ne '') {
9757: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9758: }
1.48 raeburn 9759: }
1.57 raeburn 9760: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9761: $resulttext .= '<li>'.$trails[$trail].'</li>';
9762: }
9763: $resulttext .= '</ul></li>';
1.48 raeburn 9764: }
1.57 raeburn 9765: if (keys(%adds) > 0) {
9766: my %sort_by_trail;
9767: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9768: foreach my $key (keys(%adds)) {
9769: if ($allitems{$key} ne '') {
9770: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9771: }
9772: }
9773: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9774: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9775: }
1.57 raeburn 9776: $resulttext .= '</ul></li>';
1.48 raeburn 9777: }
9778: }
9779: $resulttext .= '</ul>';
1.239 raeburn 9780: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 9781: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9782: if ($changes{'auth'}) {
9783: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
9784: }
9785: if ($changes{'unauth'}) {
9786: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
9787: }
9788: my $cachetime = 24*60*60;
9789: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 9790: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 9791: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 9792: }
9793: }
1.48 raeburn 9794: } else {
9795: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9796: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9797: }
9798: } else {
1.120 raeburn 9799: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9800: }
9801: return $resulttext;
9802: }
9803:
1.69 raeburn 9804: sub modify_serverstatuses {
9805: my ($dom,%domconfig) = @_;
9806: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9807: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9808: %currserverstatus = %{$domconfig{'serverstatuses'}};
9809: }
9810: my @pages = &serverstatus_pages();
9811: foreach my $type (@pages) {
9812: $newserverstatus{$type}{'namedusers'} = '';
9813: $newserverstatus{$type}{'machines'} = '';
9814: if (defined($env{'form.'.$type.'_namedusers'})) {
9815: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9816: my @okusers;
9817: foreach my $user (@users) {
9818: my ($uname,$udom) = split(/:/,$user);
9819: if (($udom =~ /^$match_domain$/) &&
9820: (&Apache::lonnet::domain($udom)) &&
9821: ($uname =~ /^$match_username$/)) {
9822: if (!grep(/^\Q$user\E/,@okusers)) {
9823: push(@okusers,$user);
9824: }
9825: }
9826: }
9827: if (@okusers > 0) {
9828: @okusers = sort(@okusers);
9829: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9830: }
9831: }
9832: if (defined($env{'form.'.$type.'_machines'})) {
9833: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9834: my @okmachines;
9835: foreach my $ip (@machines) {
9836: my @parts = split(/\./,$ip);
9837: next if (@parts < 4);
9838: my $badip = 0;
9839: for (my $i=0; $i<4; $i++) {
9840: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9841: $badip = 1;
9842: last;
9843: }
9844: }
9845: if (!$badip) {
9846: push(@okmachines,$ip);
9847: }
9848: }
9849: @okmachines = sort(@okmachines);
9850: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9851: }
9852: }
9853: my %serverstatushash = (
9854: serverstatuses => \%newserverstatus,
9855: );
9856: foreach my $type (@pages) {
1.83 raeburn 9857: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9858: my (@current,@new);
1.83 raeburn 9859: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9860: if ($currserverstatus{$type}{$setting} ne '') {
9861: @current = split(/,/,$currserverstatus{$type}{$setting});
9862: }
9863: }
9864: if ($newserverstatus{$type}{$setting} ne '') {
9865: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9866: }
9867: if (@current > 0) {
9868: if (@new > 0) {
9869: foreach my $item (@current) {
9870: if (!grep(/^\Q$item\E$/,@new)) {
9871: $changes{$type}{$setting} = 1;
1.82 raeburn 9872: last;
9873: }
9874: }
1.84 raeburn 9875: foreach my $item (@new) {
9876: if (!grep(/^\Q$item\E$/,@current)) {
9877: $changes{$type}{$setting} = 1;
9878: last;
1.82 raeburn 9879: }
9880: }
9881: } else {
1.83 raeburn 9882: $changes{$type}{$setting} = 1;
1.69 raeburn 9883: }
1.83 raeburn 9884: } elsif (@new > 0) {
9885: $changes{$type}{$setting} = 1;
1.69 raeburn 9886: }
9887: }
9888: }
9889: if (keys(%changes) > 0) {
1.81 raeburn 9890: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9891: my $putresult = &Apache::lonnet::put_dom('configuration',
9892: \%serverstatushash,$dom);
9893: if ($putresult eq 'ok') {
9894: $resulttext .= &mt('Changes made:').'<ul>';
9895: foreach my $type (@pages) {
1.84 raeburn 9896: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9897: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9898: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9899: if ($newserverstatus{$type}{'namedusers'} eq '') {
9900: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9901: } else {
9902: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9903: }
1.84 raeburn 9904: }
9905: if ($changes{$type}{'machines'}) {
1.69 raeburn 9906: if ($newserverstatus{$type}{'machines'} eq '') {
9907: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9908: } else {
9909: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9910: }
9911:
9912: }
9913: $resulttext .= '</ul></li>';
9914: }
9915: }
9916: $resulttext .= '</ul>';
9917: } else {
9918: $resulttext = '<span class="LC_error">'.
9919: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9920:
9921: }
9922: } else {
9923: $resulttext = &mt('No changes made to access to server status pages');
9924: }
9925: return $resulttext;
9926: }
9927:
1.118 jms 9928: sub modify_helpsettings {
1.122 jms 9929: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9930: my ($resulttext,$errors,%changes,%helphash);
9931: my %defaultchecked = ('submitbugs' => 'on');
9932: my @offon = ('off','on');
1.118 jms 9933: my @toggles = ('submitbugs');
9934: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9935: foreach my $item (@toggles) {
1.166 raeburn 9936: if ($defaultchecked{$item} eq 'on') {
9937: if ($domconfig{'helpsettings'}{$item} eq '') {
9938: if ($env{'form.'.$item} eq '0') {
9939: $changes{$item} = 1;
9940: }
9941: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9942: $changes{$item} = 1;
9943: }
9944: } elsif ($defaultchecked{$item} eq 'off') {
9945: if ($domconfig{'helpsettings'}{$item} eq '') {
9946: if ($env{'form.'.$item} eq '1') {
9947: $changes{$item} = 1;
9948: }
9949: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9950: $changes{$item} = 1;
9951: }
9952: }
1.210 raeburn 9953: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9954: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9955: }
9956: }
1.118 jms 9957: }
1.123 jms 9958: my $putresult;
9959: if (keys(%changes) > 0) {
1.166 raeburn 9960: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9961: if ($putresult eq 'ok') {
1.166 raeburn 9962: $resulttext = &mt('Changes made:').'<ul>';
9963: foreach my $item (sort(keys(%changes))) {
9964: if ($item eq 'submitbugs') {
9965: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9966: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9967: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9968: }
9969: }
9970: $resulttext .= '</ul>';
9971: } else {
9972: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9973: $errors .= '<li><span class="LC_error">'.
9974: &mt('An error occurred storing the settings: [_1]',
9975: $putresult).'</span></li>';
1.166 raeburn 9976: }
1.118 jms 9977: }
9978: if ($errors) {
1.168 raeburn 9979: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9980: $errors.'</ul>';
9981: }
9982: return $resulttext;
9983: }
9984:
1.121 raeburn 9985: sub modify_coursedefaults {
1.212 raeburn 9986: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9987: my ($resulttext,$errors,%changes,%defaultshash);
9988: my %defaultchecked = ('canuse_pdfforms' => 'off');
9989: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9990: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9991: 'uploadquota_community','uploadquota_textbook');
9992: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9993: my %staticdefaults = (
9994: anonsurvey_threshold => 10,
9995: uploadquota => 500,
9996: );
1.121 raeburn 9997:
9998: $defaultshash{'coursedefaults'} = {};
9999:
10000: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10001: if ($domconfig{'coursedefaults'} eq '') {
10002: $domconfig{'coursedefaults'} = {};
10003: }
10004: }
10005:
10006: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10007: foreach my $item (@toggles) {
10008: if ($defaultchecked{$item} eq 'on') {
10009: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10010: ($env{'form.'.$item} eq '0')) {
10011: $changes{$item} = 1;
1.192 raeburn 10012: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10013: $changes{$item} = 1;
10014: }
10015: } elsif ($defaultchecked{$item} eq 'off') {
10016: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10017: ($env{'form.'.$item} eq '1')) {
10018: $changes{$item} = 1;
10019: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10020: $changes{$item} = 1;
10021: }
10022: }
10023: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10024: }
1.198 raeburn 10025: foreach my $item (@numbers) {
10026: my ($currdef,$newdef);
1.208 raeburn 10027: $newdef = $env{'form.'.$item};
1.198 raeburn 10028: if ($item eq 'anonsurvey_threshold') {
10029: $currdef = $domconfig{'coursedefaults'}{$item};
10030: $newdef =~ s/\D//g;
10031: if ($newdef eq '' || $newdef < 1) {
10032: $newdef = 1;
10033: }
10034: $defaultshash{'coursedefaults'}{$item} = $newdef;
10035: } else {
10036: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10037: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10038: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10039: }
10040: $newdef =~ s/[^\w.\-]//g;
10041: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10042: }
10043: if ($currdef ne $newdef) {
10044: my $staticdef;
10045: if ($item eq 'anonsurvey_threshold') {
10046: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10047: $changes{$item} = 1;
10048: }
10049: } else {
10050: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10051: $changes{'uploadquota'} = 1;
10052: }
10053: }
1.139 raeburn 10054: }
10055: }
1.231 raeburn 10056:
1.192 raeburn 10057: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 10058: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 10059: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 10060: $unofficialcreds =~ s/[^\d.]+//g;
10061: my $textbookcreds = $env{'form.textbook_credits'};
10062: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 10063: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10064: ($env{'form.coursecredits'} eq '1')) {
10065: $changes{'coursecredits'} = 1;
10066: } else {
10067: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 10068: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10069: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 10070: $changes{'coursecredits'} = 1;
10071: }
10072: }
10073: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10074: official => $officialcreds,
10075: unofficial => $unofficialcreds,
1.216 raeburn 10076: textbook => $textbookcreds,
1.192 raeburn 10077: }
1.121 raeburn 10078: }
10079: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10080: $dom);
10081: if ($putresult eq 'ok') {
10082: if (keys(%changes) > 0) {
1.213 raeburn 10083: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 10084: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 10085: ($changes{'uploadquota'})) {
1.192 raeburn 10086: if ($changes{'canuse_pdfforms'}) {
10087: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10088: }
10089: if ($changes{'coursecredits'}) {
10090: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10091: $domdefaults{'officialcredits'} =
10092: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10093: $domdefaults{'unofficialcredits'} =
10094: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 10095: $domdefaults{'textbookcredits'} =
10096: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 10097: }
10098: }
1.198 raeburn 10099: if ($changes{'uploadquota'}) {
10100: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10101: foreach my $type (@types) {
10102: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10103: }
10104: }
10105: }
1.121 raeburn 10106: my $cachetime = 24*60*60;
10107: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10108: if (ref($lastactref) eq 'HASH') {
10109: $lastactref->{'domdefaults'} = 1;
10110: }
1.121 raeburn 10111: }
10112: $resulttext = &mt('Changes made:').'<ul>';
10113: foreach my $item (sort(keys(%changes))) {
10114: if ($item eq 'canuse_pdfforms') {
10115: if ($env{'form.'.$item} eq '1') {
10116: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10117: } else {
10118: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10119: }
1.139 raeburn 10120: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 10121: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 10122: } elsif ($item eq 'uploadquota') {
10123: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10124: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10125: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10126: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 10127: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10128:
1.198 raeburn 10129: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10130: '</ul>'.
10131: '</li>';
10132: } else {
10133: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10134: }
1.192 raeburn 10135: } elsif ($item eq 'coursecredits') {
10136: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10137: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 10138: ($domdefaults{'unofficialcredits'} eq '') &&
10139: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 10140: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10141: } else {
10142: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10143: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10144: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 10145: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 10146: '</ul>'.
10147: '</li>';
10148: }
10149: } else {
10150: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10151: }
1.140 raeburn 10152: }
1.121 raeburn 10153: }
10154: $resulttext .= '</ul>';
10155: } else {
10156: $resulttext = &mt('No changes made to course defaults');
10157: }
10158: } else {
10159: $resulttext = '<span class="LC_error">'.
10160: &mt('An error occurred: [_1]',$putresult).'</span>';
10161: }
10162: return $resulttext;
10163: }
10164:
1.231 raeburn 10165: sub modify_selfenrollment {
10166: my ($dom,$lastactref,%domconfig) = @_;
10167: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10168: my @types = ('official','unofficial','community','textbook');
10169: my %titles = &tool_titles();
1.232 raeburn 10170: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10171: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 10172: $ordered{'default'} = ['types','registered','approval','limit'];
10173:
10174: my (%roles,%shown,%toplevel);
10175: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10176:
10177: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10178: if ($domconfig{'selfenrollment'} eq '') {
10179: $domconfig{'selfenrollment'} = {};
10180: }
10181: }
10182: %toplevel = (
10183: admin => 'Configuration Rights',
10184: default => 'Default settings',
10185: validation => 'Validation of self-enrollment requests',
10186: );
1.233 raeburn 10187: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10188:
10189: if (ref($ordered{'admin'}) eq 'ARRAY') {
10190: foreach my $item (@{$ordered{'admin'}}) {
10191: foreach my $type (@types) {
10192: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10193: $selfenrollhash{'admin'}{$type}{$item} = 1;
10194: } else {
10195: $selfenrollhash{'admin'}{$type}{$item} = 0;
10196: }
10197: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10198: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10199: if ($selfenrollhash{'admin'}{$type}{$item} ne
10200: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10201: push(@{$changes{'admin'}{$type}},$item);
10202: }
10203: } else {
10204: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10205: push(@{$changes{'admin'}{$type}},$item);
10206: }
10207: }
10208: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10209: push(@{$changes{'admin'}{$type}},$item);
10210: }
10211: }
10212: }
10213: }
10214:
10215: foreach my $item (@{$ordered{'default'}}) {
10216: foreach my $type (@types) {
10217: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10218: if ($item eq 'types') {
10219: unless (($value eq 'all') || ($value eq 'dom')) {
10220: $value = '';
10221: }
10222: } elsif ($item eq 'registered') {
10223: unless ($value eq '1') {
10224: $value = 0;
10225: }
10226: } elsif ($item eq 'approval') {
10227: unless ($value =~ /^[012]$/) {
10228: $value = 0;
10229: }
10230: } else {
10231: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10232: $value = 'none';
10233: }
10234: }
10235: $selfenrollhash{'default'}{$type}{$item} = $value;
10236: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10237: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10238: if ($selfenrollhash{'default'}{$type}{$item} ne
10239: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10240: push(@{$changes{'default'}{$type}},$item);
10241: }
10242: } else {
10243: push(@{$changes{'default'}{$type}},$item);
10244: }
10245: } else {
10246: push(@{$changes{'default'}{$type}},$item);
10247: }
10248: if ($item eq 'limit') {
10249: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10250: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10251: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10252: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10253: }
10254: } else {
10255: $selfenrollhash{'default'}{$type}{'cap'} = '';
10256: }
10257: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10258: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10259: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10260: push(@{$changes{'default'}{$type}},'cap');
10261: }
10262: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10263: push(@{$changes{'default'}{$type}},'cap');
10264: }
10265: }
10266: }
10267: }
10268:
10269: foreach my $item (@{$itemsref}) {
10270: if ($item eq 'fields') {
10271: my @changed;
10272: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10273: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10274: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10275: }
10276: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10277: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10278: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10279: $domconfig{'selfenrollment'}{'validation'}{$item});
10280: } else {
10281: @changed = @{$selfenrollhash{'validation'}{$item}};
10282: }
10283: } else {
10284: @changed = @{$selfenrollhash{'validation'}{$item}};
10285: }
10286: if (@changed) {
10287: if ($selfenrollhash{'validation'}{$item}) {
10288: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10289: } else {
10290: $changes{'validation'}{$item} = &mt('None');
10291: }
10292: }
10293: } else {
10294: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10295: if ($item eq 'markup') {
10296: if ($env{'form.selfenroll_validation_'.$item}) {
10297: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10298: }
10299: }
10300: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10301: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10302: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10303: }
10304: }
10305: }
10306: }
10307:
10308: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10309: $dom);
10310: if ($putresult eq 'ok') {
10311: if (keys(%changes) > 0) {
10312: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10313: $resulttext = &mt('Changes made:').'<ul>';
10314: foreach my $key ('admin','default','validation') {
10315: if (ref($changes{$key}) eq 'HASH') {
10316: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10317: if ($key eq 'validation') {
10318: foreach my $item (@{$itemsref}) {
10319: if (exists($changes{$key}{$item})) {
10320: if ($item eq 'markup') {
10321: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10322: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10323: } else {
10324: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10325: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10326: }
10327: }
10328: }
10329: } else {
10330: foreach my $type (@types) {
10331: if ($type eq 'community') {
10332: $roles{'1'} = &mt('Community personnel');
10333: } else {
10334: $roles{'1'} = &mt('Course personnel');
10335: }
10336: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10337: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10338: if ($key eq 'admin') {
10339: my @mgrdc = ();
10340: if (ref($ordered{$key}) eq 'ARRAY') {
10341: foreach my $item (@{$ordered{'admin'}}) {
10342: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10343: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10344: push(@mgrdc,$item);
10345: }
10346: }
10347: }
10348: if (@mgrdc) {
10349: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10350: } else {
10351: delete($domdefaults{$type.'selfenrolladmdc'});
10352: }
10353: }
10354: } else {
10355: if (ref($ordered{$key}) eq 'ARRAY') {
10356: foreach my $item (@{$ordered{$key}}) {
10357: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10358: $domdefaults{$type.'selfenroll'.$item} =
10359: $selfenrollhash{$key}{$type}{$item};
10360: }
10361: }
10362: }
10363: }
10364: }
1.231 raeburn 10365: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10366: foreach my $item (@{$ordered{$key}}) {
10367: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10368: $resulttext .= '<li>';
10369: if ($key eq 'admin') {
10370: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10371: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10372: } else {
10373: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10374: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10375: }
10376: $resulttext .= '</li>';
10377: }
10378: }
10379: $resulttext .= '</ul></li>';
10380: }
10381: }
10382: $resulttext .= '</ul></li>';
10383: }
10384: }
1.232 raeburn 10385: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10386: my $cachetime = 24*60*60;
10387: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10388: if (ref($lastactref) eq 'HASH') {
10389: $lastactref->{'domdefaults'} = 1;
10390: }
10391: }
1.231 raeburn 10392: }
10393: $resulttext .= '</ul>';
10394: } else {
10395: $resulttext = &mt('No changes made to self-enrollment settings');
10396: }
10397: } else {
10398: $resulttext = '<span class="LC_error">'.
10399: &mt('An error occurred: [_1]',$putresult).'</span>';
10400: }
10401: return $resulttext;
10402: }
10403:
1.137 raeburn 10404: sub modify_usersessions {
1.212 raeburn 10405: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10406: my @hostingtypes = ('version','excludedomain','includedomain');
10407: my @offloadtypes = ('primary','default');
10408: my %types = (
10409: remote => \@hostingtypes,
10410: hosted => \@hostingtypes,
10411: spares => \@offloadtypes,
10412: );
10413: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10414: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10415: my (%by_ip,%by_location,@intdoms);
10416: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10417: my @locations = sort(keys(%by_location));
1.137 raeburn 10418: my (%defaultshash,%changes);
10419: foreach my $prefix (@prefixes) {
10420: $defaultshash{'usersessions'}{$prefix} = {};
10421: }
1.212 raeburn 10422: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10423: my $resulttext;
1.138 raeburn 10424: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10425: foreach my $prefix (@prefixes) {
1.145 raeburn 10426: next if ($prefix eq 'spares');
10427: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10428: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10429: if ($type eq 'version') {
10430: my $value = $env{'form.'.$prefix.'_'.$type};
10431: my $okvalue;
10432: if ($value ne '') {
10433: if (grep(/^\Q$value\E$/,@lcversions)) {
10434: $okvalue = $value;
10435: }
10436: }
10437: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10438: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10439: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10440: if ($inuse == 0) {
10441: $changes{$prefix}{$type} = 1;
10442: } else {
10443: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10444: $changes{$prefix}{$type} = 1;
10445: }
10446: if ($okvalue ne '') {
10447: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10448: }
10449: }
10450: } else {
10451: if (($inuse == 1) && ($okvalue ne '')) {
10452: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10453: $changes{$prefix}{$type} = 1;
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: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10470: my @okvals;
10471: foreach my $val (@vals) {
1.138 raeburn 10472: if ($val =~ /:/) {
10473: my @items = split(/:/,$val);
10474: foreach my $item (@items) {
10475: if (ref($by_location{$item}) eq 'ARRAY') {
10476: push(@okvals,$item);
10477: }
10478: }
10479: } else {
10480: if (ref($by_location{$val}) eq 'ARRAY') {
10481: push(@okvals,$val);
10482: }
1.137 raeburn 10483: }
10484: }
10485: @okvals = sort(@okvals);
10486: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10487: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10488: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10489: if ($inuse == 0) {
10490: $changes{$prefix}{$type} = 1;
10491: } else {
10492: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10493: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10494: if (@changed > 0) {
10495: $changes{$prefix}{$type} = 1;
10496: }
10497: }
10498: } else {
10499: if ($inuse == 1) {
10500: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
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: }
10517: }
10518: }
1.145 raeburn 10519:
10520: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10521: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10522: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10523: my $savespares;
10524:
10525: foreach my $lonhost (sort(keys(%servers))) {
10526: my $serverhomeID =
10527: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10528: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10529: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10530: my %spareschg;
10531: foreach my $type (@{$types{'spares'}}) {
10532: my @okspares;
10533: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10534: foreach my $server (@checked) {
1.152 raeburn 10535: if (&Apache::lonnet::hostname($server) ne '') {
10536: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10537: unless (grep(/^\Q$server\E$/,@okspares)) {
10538: push(@okspares,$server);
10539: }
1.145 raeburn 10540: }
10541: }
10542: }
10543: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10544: my $newspare;
1.152 raeburn 10545: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10546: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10547: $newspare = $new;
10548: }
10549: }
1.152 raeburn 10550: my @spares;
10551: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10552: @spares = sort(@okspares,$newspare);
10553: } else {
10554: @spares = sort(@okspares);
10555: }
10556: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10557: if (ref($spareid{$lonhost}) eq 'HASH') {
10558: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10559: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10560: if (@diffs > 0) {
10561: $spareschg{$type} = 1;
10562: }
10563: }
10564: }
10565: }
10566: if (keys(%spareschg) > 0) {
10567: $changes{'spares'}{$lonhost} = \%spareschg;
10568: }
10569: }
10570:
10571: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10572: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10573: if (ref($changes{'spares'}) eq 'HASH') {
10574: if (keys(%{$changes{'spares'}}) > 0) {
10575: $savespares = 1;
10576: }
10577: }
10578: } else {
10579: $savespares = 1;
10580: }
10581: }
10582:
1.147 raeburn 10583: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10584: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10585: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10586: $dom);
10587: if ($putresult eq 'ok') {
10588: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10589: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10590: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10591: }
10592: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10593: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10594: }
10595: }
10596: my $cachetime = 24*60*60;
10597: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10598: if (ref($lastactref) eq 'HASH') {
10599: $lastactref->{'domdefaults'} = 1;
10600: }
1.147 raeburn 10601: if (keys(%changes) > 0) {
10602: my %lt = &usersession_titles();
10603: $resulttext = &mt('Changes made:').'<ul>';
10604: foreach my $prefix (@prefixes) {
10605: if (ref($changes{$prefix}) eq 'HASH') {
10606: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10607: if ($prefix eq 'spares') {
10608: if (ref($changes{$prefix}) eq 'HASH') {
10609: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10610: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10611: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10612: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10613: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10614: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10615: foreach my $type (@{$types{$prefix}}) {
10616: if ($changes{$prefix}{$lonhost}{$type}) {
10617: my $offloadto = &mt('None');
10618: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10619: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10620: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10621: }
1.145 raeburn 10622: }
1.147 raeburn 10623: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10624: }
1.137 raeburn 10625: }
10626: }
1.147 raeburn 10627: $resulttext .= '</li>';
1.137 raeburn 10628: }
10629: }
1.147 raeburn 10630: } else {
10631: foreach my $type (@{$types{$prefix}}) {
10632: if (defined($changes{$prefix}{$type})) {
10633: my $newvalue;
10634: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10635: if (ref($defaultshash{'usersessions'}{$prefix})) {
10636: if ($type eq 'version') {
10637: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10638: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10639: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10640: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10641: }
1.145 raeburn 10642: }
10643: }
10644: }
1.147 raeburn 10645: if ($newvalue eq '') {
10646: if ($type eq 'version') {
10647: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10648: } else {
10649: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10650: }
1.145 raeburn 10651: } else {
1.147 raeburn 10652: if ($type eq 'version') {
10653: $newvalue .= ' '.&mt('(or later)');
10654: }
10655: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10656: }
1.137 raeburn 10657: }
10658: }
10659: }
1.147 raeburn 10660: $resulttext .= '</ul>';
1.137 raeburn 10661: }
10662: }
1.147 raeburn 10663: $resulttext .= '</ul>';
10664: } else {
10665: $resulttext = $nochgmsg;
1.137 raeburn 10666: }
10667: } else {
10668: $resulttext = '<span class="LC_error">'.
10669: &mt('An error occurred: [_1]',$putresult).'</span>';
10670: }
10671: } else {
1.147 raeburn 10672: $resulttext = $nochgmsg;
1.137 raeburn 10673: }
10674: return $resulttext;
10675: }
10676:
1.150 raeburn 10677: sub modify_loadbalancing {
10678: my ($dom,%domconfig) = @_;
10679: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10680: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10681: my ($othertitle,$usertypes,$types) =
10682: &Apache::loncommon::sorted_inst_types($dom);
10683: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 ! raeburn 10684: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 10685: my @sparestypes = ('primary','default');
10686: my %typetitles = &sparestype_titles();
10687: my $resulttext;
1.171 raeburn 10688: my (%currbalancer,%currtargets,%currrules,%existing);
10689: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10690: %existing = %{$domconfig{'loadbalancing'}};
10691: }
10692: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10693: \%currtargets,\%currrules);
10694: my ($saveloadbalancing,%defaultshash,%changes);
10695: my ($alltypes,$othertypes,$titles) =
10696: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10697: my %ruletitles = &offloadtype_text();
10698: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10699: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10700: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10701: if ($balancer eq '') {
10702: next;
10703: }
1.210 raeburn 10704: if (!exists($servers{$balancer})) {
1.171 raeburn 10705: if (exists($currbalancer{$balancer})) {
10706: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10707: }
1.171 raeburn 10708: next;
10709: }
10710: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10711: push(@{$changes{'delete'}},$balancer);
10712: next;
10713: }
10714: if (!exists($currbalancer{$balancer})) {
10715: push(@{$changes{'add'}},$balancer);
10716: }
10717: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10718: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10719: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10720: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10721: $saveloadbalancing = 1;
10722: }
10723: foreach my $sparetype (@sparestypes) {
10724: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10725: my @offloadto;
10726: foreach my $target (@targets) {
10727: if (($servers{$target}) && ($target ne $balancer)) {
10728: if ($sparetype eq 'default') {
10729: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10730: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10731: }
10732: }
1.171 raeburn 10733: unless(grep(/^\Q$target\E$/,@offloadto)) {
10734: push(@offloadto,$target);
10735: }
1.150 raeburn 10736: }
1.171 raeburn 10737: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10738: }
10739: }
1.171 raeburn 10740: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10741: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10742: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10743: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10744: if (@targetdiffs > 0) {
1.171 raeburn 10745: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10746: }
1.171 raeburn 10747: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10748: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10749: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10750: }
10751: }
10752: }
10753: } else {
1.171 raeburn 10754: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10755: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10756: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10757: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10758: $changes{'curr'}{$balancer}{'targets'} = 1;
10759: }
1.150 raeburn 10760: }
10761: }
1.210 raeburn 10762: }
1.150 raeburn 10763: }
10764: my $ishomedom;
1.171 raeburn 10765: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10766: $ishomedom = 1;
1.150 raeburn 10767: }
10768: if (ref($alltypes) eq 'ARRAY') {
10769: foreach my $type (@{$alltypes}) {
10770: my $rule;
1.210 raeburn 10771: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10772: (!$ishomedom)) {
1.171 raeburn 10773: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10774: }
10775: if ($rule eq 'specific') {
10776: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10777: }
1.171 raeburn 10778: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10779: if (ref($currrules{$balancer}) eq 'HASH') {
10780: if ($rule ne $currrules{$balancer}{$type}) {
10781: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10782: }
10783: } elsif ($rule ne '') {
1.171 raeburn 10784: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10785: }
10786: }
10787: }
1.171 raeburn 10788: }
10789: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10790: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10791: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10792: $defaultshash{'loadbalancing'} = {};
10793: }
10794: my $putresult = &Apache::lonnet::put_dom('configuration',
10795: \%defaultshash,$dom);
10796: if ($putresult eq 'ok') {
10797: if (keys(%changes) > 0) {
1.252 raeburn 10798: my %toupdate;
1.171 raeburn 10799: if (ref($changes{'delete'}) eq 'ARRAY') {
10800: foreach my $balancer (sort(@{$changes{'delete'}})) {
10801: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 10802: $toupdate{$balancer} = 1;
1.150 raeburn 10803: }
1.171 raeburn 10804: }
10805: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10806: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10807: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 10808: $toupdate{$balancer} = 1;
1.171 raeburn 10809: }
10810: }
10811: if (ref($changes{'curr'}) eq 'HASH') {
10812: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 ! raeburn 10813: $toupdate{$balancer} = 1;
1.171 raeburn 10814: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10815: if ($changes{'curr'}{$balancer}{'targets'}) {
10816: my %offloadstr;
10817: foreach my $sparetype (@sparestypes) {
10818: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10819: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10820: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10821: }
10822: }
1.150 raeburn 10823: }
1.171 raeburn 10824: if (keys(%offloadstr) == 0) {
10825: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10826: } else {
1.171 raeburn 10827: my $showoffload;
10828: foreach my $sparetype (@sparestypes) {
10829: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10830: if (defined($offloadstr{$sparetype})) {
10831: $showoffload .= $offloadstr{$sparetype};
10832: } else {
10833: $showoffload .= &mt('None');
10834: }
10835: $showoffload .= (' 'x3);
10836: }
10837: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10838: }
10839: }
10840: }
1.171 raeburn 10841: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10842: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10843: foreach my $type (@{$alltypes}) {
10844: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10845: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10846: my $balancetext;
10847: if ($rule eq '') {
10848: $balancetext = $ruletitles{'default'};
1.209 raeburn 10849: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10850: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 10851: $balancetext = $ruletitles{$rule};
1.252 raeburn 10852: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
10853: foreach my $sparetype (@sparestypes) {
10854: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10855: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10856: }
10857: }
1.253 ! raeburn 10858: foreach my $item (@{$alltypes}) {
! 10859: next if ($item =~ /^_LC_ipchange/);
! 10860: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
! 10861: if ($hasrule eq 'homeserver') {
! 10862: map { $toupdate{$_} = 1; } (keys(%libraryservers));
! 10863: } else {
! 10864: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
! 10865: if ($servers{$hasrule}) {
! 10866: $toupdate{$hasrule} = 1;
! 10867: }
! 10868: }
! 10869: }
! 10870: }
1.252 raeburn 10871: }
1.171 raeburn 10872: } else {
10873: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10874: }
1.210 raeburn 10875: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10876: }
10877: }
10878: }
10879: }
1.252 raeburn 10880: if (keys(%toupdate)) {
10881: my %thismachine;
10882: my $updatedhere;
10883: my $cachetime = 60*60*24;
10884: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
10885: foreach my $lonhost (keys(%toupdate)) {
10886: if ($thismachine{$lonhost}) {
10887: unless ($updatedhere) {
10888: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
10889: $defaultshash{'loadbalancing'},
10890: $cachetime);
10891: $updatedhere = 1;
10892: }
10893: } else {
10894: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10895: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
10896: }
10897: }
10898: }
1.150 raeburn 10899: }
1.171 raeburn 10900: }
10901: if ($resulttext ne '') {
10902: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10903: } else {
10904: $resulttext = $nochgmsg;
10905: }
10906: } else {
1.171 raeburn 10907: $resulttext = $nochgmsg;
1.150 raeburn 10908: }
10909: } else {
1.171 raeburn 10910: $resulttext = '<span class="LC_error">'.
10911: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10912: }
10913: } else {
1.171 raeburn 10914: $resulttext = $nochgmsg;
1.150 raeburn 10915: }
10916: return $resulttext;
10917: }
10918:
1.48 raeburn 10919: sub recurse_check {
10920: my ($chkcats,$categories,$depth,$name) = @_;
10921: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10922: my $chg = 0;
10923: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10924: my $category = $chkcats->[$depth]{$name}[$j];
10925: my $item;
10926: if ($category eq '') {
10927: $chg ++;
10928: } else {
10929: my $deeper = $depth + 1;
10930: $item = &escape($category).':'.&escape($name).':'.$depth;
10931: if ($chg) {
10932: $categories->{$item} -= $chg;
10933: }
10934: &recurse_check($chkcats,$categories,$deeper,$category);
10935: $deeper --;
10936: }
10937: }
10938: }
10939: return;
10940: }
10941:
10942: sub recurse_cat_deletes {
10943: my ($item,$coursecategories,$deletions) = @_;
10944: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10945: my $subdepth = $depth + 1;
10946: if (ref($coursecategories) eq 'HASH') {
10947: foreach my $subitem (keys(%{$coursecategories})) {
10948: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10949: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10950: delete($coursecategories->{$subitem});
10951: $deletions->{$subitem} = 1;
10952: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10953: }
1.48 raeburn 10954: }
10955: }
10956: return;
10957: }
10958:
1.125 raeburn 10959: sub get_active_dcs {
10960: my ($dom) = @_;
1.191 raeburn 10961: my $now = time;
10962: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10963: my %domcoords;
10964: my $numdcs = 0;
10965: foreach my $server (keys(%dompersonnel)) {
10966: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10967: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10968: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10969: }
10970: }
10971: return %domcoords;
10972: }
10973:
10974: sub active_dc_picker {
1.191 raeburn 10975: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 10976: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10977: my @domcoord = keys(%domcoords);
10978: if (keys(%currhash)) {
10979: foreach my $dc (keys(%currhash)) {
10980: unless (exists($domcoords{$dc})) {
10981: push(@domcoord,$dc);
10982: }
10983: }
10984: }
10985: @domcoord = sort(@domcoord);
1.210 raeburn 10986: my $numdcs = scalar(@domcoord);
1.191 raeburn 10987: my $rows = 0;
10988: my $table;
1.125 raeburn 10989: if ($numdcs > 1) {
1.191 raeburn 10990: $table = '<table>';
10991: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10992: my $rem = $i%($numinrow);
10993: if ($rem == 0) {
10994: if ($i > 0) {
1.191 raeburn 10995: $table .= '</tr>';
1.125 raeburn 10996: }
1.191 raeburn 10997: $table .= '<tr>';
10998: $rows ++;
1.125 raeburn 10999: }
1.191 raeburn 11000: my $check = '';
11001: if ($inputtype eq 'radio') {
11002: if (keys(%currhash) == 0) {
11003: if (!$i) {
11004: $check = ' checked="checked"';
11005: }
11006: } elsif (exists($currhash{$domcoord[$i]})) {
11007: $check = ' checked="checked"';
11008: }
11009: } else {
11010: if (exists($currhash{$domcoord[$i]})) {
11011: $check = ' checked="checked"';
1.125 raeburn 11012: }
11013: }
1.191 raeburn 11014: if ($i == @domcoord - 1) {
1.125 raeburn 11015: my $colsleft = $numinrow - $rem;
11016: if ($colsleft > 1) {
1.191 raeburn 11017: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11018: } else {
1.191 raeburn 11019: $table .= '<td class="LC_left_item">';
1.125 raeburn 11020: }
11021: } else {
1.191 raeburn 11022: $table .= '<td class="LC_left_item">';
11023: }
11024: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11025: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11026: $table .= '<span class="LC_nobreak"><label>'.
11027: '<input type="'.$inputtype.'" name="'.$name.'"'.
11028: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11029: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 11030: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 11031: }
1.219 raeburn 11032: $table .= '</label></span></td>';
1.191 raeburn 11033: }
11034: $table .= '</tr></table>';
11035: } elsif ($numdcs == 1) {
1.219 raeburn 11036: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11037: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 11038: if ($inputtype eq 'radio') {
1.247 raeburn 11039: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 11040: if ($user ne $dcname.':'.$dcdom) {
11041: $table .= ' ('.$dcname.':'.$dcdom.')';
11042: }
1.191 raeburn 11043: } else {
11044: my $check;
11045: if (exists($currhash{$domcoord[0]})) {
11046: $check = ' checked="checked"';
1.125 raeburn 11047: }
1.247 raeburn 11048: $table = '<span class="LC_nobreak"><label>'.
11049: '<input type="checkbox" name="'.$name.'" '.
11050: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 11051: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 11052: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 11053: }
1.220 raeburn 11054: $table .= '</label></span>';
1.191 raeburn 11055: $rows ++;
1.125 raeburn 11056: }
11057: }
1.191 raeburn 11058: return ($numdcs,$table,$rows);
1.125 raeburn 11059: }
11060:
1.137 raeburn 11061: sub usersession_titles {
11062: return &Apache::lonlocal::texthash(
11063: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11064: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11065: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11066: version => 'LON-CAPA version requirement',
1.138 raeburn 11067: excludedomain => 'Allow all, but exclude specific domains',
11068: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11069: primary => 'Primary (checked first)',
1.154 raeburn 11070: default => 'Default',
1.137 raeburn 11071: );
11072: }
11073:
1.152 raeburn 11074: sub id_for_thisdom {
11075: my (%servers) = @_;
11076: my %altids;
11077: foreach my $server (keys(%servers)) {
11078: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11079: if ($serverhome ne $server) {
11080: $altids{$serverhome} = $server;
11081: }
11082: }
11083: return %altids;
11084: }
11085:
1.150 raeburn 11086: sub count_servers {
11087: my ($currbalancer,%servers) = @_;
11088: my (@spares,$numspares);
11089: foreach my $lonhost (sort(keys(%servers))) {
11090: next if ($currbalancer eq $lonhost);
11091: push(@spares,$lonhost);
11092: }
11093: if ($currbalancer) {
11094: $numspares = scalar(@spares);
11095: } else {
11096: $numspares = scalar(@spares) - 1;
11097: }
11098: return ($numspares,@spares);
11099: }
11100:
11101: sub lonbalance_targets_js {
1.171 raeburn 11102: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11103: my $select = &mt('Select');
11104: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11105: if (ref($servers) eq 'HASH') {
11106: $alltargets = join("','",sort(keys(%{$servers})));
11107: my @homedoms;
11108: foreach my $server (sort(keys(%{$servers}))) {
11109: if (&Apache::lonnet::host_domain($server) eq $dom) {
11110: push(@homedoms,'1');
11111: } else {
11112: push(@homedoms,'0');
11113: }
11114: }
11115: $allishome = join("','",@homedoms);
11116: }
11117: if (ref($types) eq 'ARRAY') {
11118: if (@{$types} > 0) {
11119: @alltypes = @{$types};
11120: }
11121: }
11122: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11123: $allinsttypes = join("','",@alltypes);
1.171 raeburn 11124: my (%currbalancer,%currtargets,%currrules,%existing);
11125: if (ref($settings) eq 'HASH') {
11126: %existing = %{$settings};
11127: }
11128: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11129: \%currtargets,\%currrules);
1.210 raeburn 11130: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11131: return <<"END";
11132:
11133: <script type="text/javascript">
11134: // <![CDATA[
11135:
1.171 raeburn 11136: currBalancers = new Array('$balancers');
11137:
11138: function toggleTargets(balnum) {
11139: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11140: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11141: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11142: var prevbalancer = prevhostitem.value;
11143: var baltotal = document.getElementById('loadbalancing_total').value;
11144: prevhostitem.value = balancer;
11145: if (prevbalancer != '') {
11146: var prevIdx = currBalancers.indexOf(prevbalancer);
11147: if (prevIdx != -1) {
11148: currBalancers.splice(prevIdx,1);
11149: }
11150: }
1.150 raeburn 11151: if (balancer == '') {
1.171 raeburn 11152: hideSpares(balnum);
1.150 raeburn 11153: } else {
1.171 raeburn 11154: var currIdx = currBalancers.indexOf(balancer);
11155: if (currIdx == -1) {
11156: currBalancers.push(balancer);
11157: }
1.150 raeburn 11158: var homedoms = new Array('$allishome');
1.171 raeburn 11159: var ishomedom = homedoms[lonhostitem.selectedIndex];
11160: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11161: }
1.171 raeburn 11162: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11163: return;
11164: }
11165:
1.171 raeburn 11166: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11167: var alltargets = new Array('$alltargets');
11168: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11169: var offloadtypes = new Array('primary','default');
11170:
1.171 raeburn 11171: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11172: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11173:
1.151 raeburn 11174: for (var i=0; i<offloadtypes.length; i++) {
11175: var count = 0;
11176: for (var j=0; j<alltargets.length; j++) {
11177: if (alltargets[j] != balancer) {
1.171 raeburn 11178: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11179: item.value = alltargets[j];
11180: item.style.textAlign='left';
11181: item.style.textFace='normal';
11182: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11183: if (currBalancers.indexOf(alltargets[j]) == -1) {
11184: item.disabled = '';
11185: } else {
11186: item.disabled = 'disabled';
11187: item.checked = false;
11188: }
1.151 raeburn 11189: count ++;
11190: }
1.150 raeburn 11191: }
11192: }
1.151 raeburn 11193: for (var k=0; k<insttypes.length; k++) {
11194: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11195: if (ishomedom == 1) {
1.171 raeburn 11196: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11197: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11198: } else {
1.171 raeburn 11199: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11200: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11201: }
11202: } else {
1.171 raeburn 11203: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11204: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11205: }
1.151 raeburn 11206: if ((insttypes[k] != '_LC_external') &&
11207: ((insttypes[k] != '_LC_internetdom') ||
11208: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 11209: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11210: item.options.length = 0;
11211: item.options[0] = new Option("","",true,true);
1.210 raeburn 11212: var idx = 0;
1.151 raeburn 11213: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 11214: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11215: idx ++;
11216: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11217: }
11218: }
11219: }
11220: }
11221: return;
11222: }
11223:
1.171 raeburn 11224: function hideSpares(balnum) {
1.150 raeburn 11225: var alltargets = new Array('$alltargets');
11226: var insttypes = new Array('$allinsttypes');
11227: var offloadtypes = new Array('primary','default');
11228:
1.171 raeburn 11229: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11230: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11231:
11232: var total = alltargets.length - 1;
11233: for (var i=0; i<offloadtypes; i++) {
11234: for (var j=0; j<total; j++) {
1.171 raeburn 11235: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11236: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11237: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11238: }
1.150 raeburn 11239: }
11240: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11241: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11242: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11243: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11244: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11245: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11246: }
11247: }
11248: return;
11249: }
11250:
1.171 raeburn 11251: function checkOffloads(item,balnum,type) {
1.150 raeburn 11252: var alltargets = new Array('$alltargets');
11253: var offloadtypes = new Array('primary','default');
11254: if (item.checked) {
11255: var total = alltargets.length - 1;
11256: var other;
11257: if (type == offloadtypes[0]) {
1.151 raeburn 11258: other = offloadtypes[1];
1.150 raeburn 11259: } else {
1.151 raeburn 11260: other = offloadtypes[0];
1.150 raeburn 11261: }
11262: for (var i=0; i<total; i++) {
1.171 raeburn 11263: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11264: if (server == item.value) {
1.171 raeburn 11265: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11266: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11267: }
11268: }
11269: }
11270: }
11271: return;
11272: }
11273:
1.171 raeburn 11274: function singleServerToggle(balnum,type) {
11275: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11276: if (offloadtoSelIdx == 0) {
1.171 raeburn 11277: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11278: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11279:
11280: } else {
1.171 raeburn 11281: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11282: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11283: }
11284: return;
11285: }
11286:
1.171 raeburn 11287: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11288: if (type == '_LC_external') {
1.171 raeburn 11289: return;
1.150 raeburn 11290: }
1.171 raeburn 11291: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11292: for (var i=0; i<typesRules.length; i++) {
11293: if (formname.elements[typesRules[i]].checked) {
11294: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11295: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11296: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11297: } else {
1.171 raeburn 11298: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11299: }
11300: }
11301: }
11302: return;
11303: }
11304:
11305: function balancerDeleteChange(balnum) {
11306: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11307: var baltotal = document.getElementById('loadbalancing_total').value;
11308: var addtarget;
11309: var removetarget;
11310: var action = 'delete';
11311: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11312: var lonhost = hostitem.value;
11313: var currIdx = currBalancers.indexOf(lonhost);
11314: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11315: if (currIdx != -1) {
11316: currBalancers.splice(currIdx,1);
11317: }
11318: addtarget = lonhost;
11319: } else {
11320: if (currIdx == -1) {
11321: currBalancers.push(lonhost);
11322: }
11323: removetarget = lonhost;
11324: action = 'undelete';
11325: }
11326: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11327: }
11328: return;
11329: }
11330:
11331: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11332: if (baltotal > 1) {
11333: var offloadtypes = new Array('primary','default');
11334: var alltargets = new Array('$alltargets');
11335: var insttypes = new Array('$allinsttypes');
11336: for (var i=0; i<baltotal; i++) {
11337: if (i != balnum) {
11338: for (var j=0; j<offloadtypes.length; j++) {
11339: var total = alltargets.length - 1;
11340: for (var k=0; k<total; k++) {
11341: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11342: var server = serveritem.value;
11343: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11344: if (server == addtarget) {
11345: serveritem.disabled = '';
11346: }
11347: }
11348: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11349: if (server == removetarget) {
11350: serveritem.disabled = 'disabled';
11351: serveritem.checked = false;
11352: }
11353: }
11354: }
11355: }
11356: for (var j=0; j<insttypes.length; j++) {
11357: if (insttypes[j] != '_LC_external') {
11358: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11359: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11360: var currSel = singleserver.selectedIndex;
11361: var currVal = singleserver.options[currSel].value;
11362: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11363: var numoptions = singleserver.options.length;
11364: var needsnew = 1;
11365: for (var k=0; k<numoptions; k++) {
11366: if (singleserver.options[k] == addtarget) {
11367: needsnew = 0;
11368: break;
11369: }
11370: }
11371: if (needsnew == 1) {
11372: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11373: }
11374: }
11375: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11376: singleserver.options.length = 0;
11377: if ((currVal) && (currVal != removetarget)) {
11378: singleserver.options[0] = new Option("","",false,false);
11379: } else {
11380: singleserver.options[0] = new Option("","",true,true);
11381: }
11382: var idx = 0;
11383: for (var m=0; m<alltargets.length; m++) {
11384: if (currBalancers.indexOf(alltargets[m]) == -1) {
11385: idx ++;
11386: if (currVal == alltargets[m]) {
11387: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11388: } else {
11389: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11390: }
11391: }
11392: }
11393: }
11394: }
11395: }
11396: }
1.150 raeburn 11397: }
11398: }
11399: }
11400: return;
11401: }
11402:
1.152 raeburn 11403: // ]]>
11404: </script>
11405:
11406: END
11407: }
11408:
11409: sub new_spares_js {
11410: my @sparestypes = ('primary','default');
11411: my $types = join("','",@sparestypes);
11412: my $select = &mt('Select');
11413: return <<"END";
11414:
11415: <script type="text/javascript">
11416: // <![CDATA[
11417:
11418: function updateNewSpares(formname,lonhost) {
11419: var types = new Array('$types');
11420: var include = new Array();
11421: var exclude = new Array();
11422: for (var i=0; i<types.length; i++) {
11423: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11424: for (var j=0; j<spareboxes.length; j++) {
11425: if (formname.elements[spareboxes[j]].checked) {
11426: exclude.push(formname.elements[spareboxes[j]].value);
11427: } else {
11428: include.push(formname.elements[spareboxes[j]].value);
11429: }
11430: }
11431: }
11432: for (var i=0; i<types.length; i++) {
11433: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11434: var selIdx = newSpare.selectedIndex;
11435: var currnew = newSpare.options[selIdx].value;
11436: var okSpares = new Array();
11437: for (var j=0; j<newSpare.options.length; j++) {
11438: var possible = newSpare.options[j].value;
11439: if (possible != '') {
11440: if (exclude.indexOf(possible) == -1) {
11441: okSpares.push(possible);
11442: } else {
11443: if (currnew == possible) {
11444: selIdx = 0;
11445: }
11446: }
11447: }
11448: }
11449: for (var k=0; k<include.length; k++) {
11450: if (okSpares.indexOf(include[k]) == -1) {
11451: okSpares.push(include[k]);
11452: }
11453: }
11454: okSpares.sort();
11455: newSpare.options.length = 0;
11456: if (selIdx == 0) {
11457: newSpare.options[0] = new Option("$select","",true,true);
11458: } else {
11459: newSpare.options[0] = new Option("$select","",false,false);
11460: }
11461: for (var m=0; m<okSpares.length; m++) {
11462: var idx = m+1;
11463: var selThis = 0;
11464: if (selIdx != 0) {
11465: if (okSpares[m] == currnew) {
11466: selThis = 1;
11467: }
11468: }
11469: if (selThis == 1) {
11470: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11471: } else {
11472: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11473: }
11474: }
11475: }
11476: return;
11477: }
11478:
11479: function checkNewSpares(lonhost,type) {
11480: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11481: var chosen = newSpare.options[newSpare.selectedIndex].value;
11482: if (chosen != '') {
11483: var othertype;
11484: var othernewSpare;
11485: if (type == 'primary') {
11486: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11487: }
11488: if (type == 'default') {
11489: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11490: }
11491: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11492: othernewSpare.selectedIndex = 0;
11493: }
11494: }
11495: return;
11496: }
11497:
11498: // ]]>
11499: </script>
11500:
11501: END
11502:
11503: }
11504:
11505: sub common_domprefs_js {
11506: return <<"END";
11507:
11508: <script type="text/javascript">
11509: // <![CDATA[
11510:
1.150 raeburn 11511: function getIndicesByName(formname,item) {
1.152 raeburn 11512: var group = new Array();
1.150 raeburn 11513: for (var i=0;i<formname.elements.length;i++) {
11514: if (formname.elements[i].name == item) {
1.152 raeburn 11515: group.push(formname.elements[i].id);
1.150 raeburn 11516: }
11517: }
1.152 raeburn 11518: return group;
1.150 raeburn 11519: }
11520:
11521: // ]]>
11522: </script>
11523:
11524: END
1.152 raeburn 11525:
1.150 raeburn 11526: }
11527:
1.165 raeburn 11528: sub recaptcha_js {
11529: my %lt = &captcha_phrases();
11530: return <<"END";
11531:
11532: <script type="text/javascript">
11533: // <![CDATA[
11534:
11535: function updateCaptcha(caller,context) {
11536: var privitem;
11537: var pubitem;
11538: var privtext;
11539: var pubtext;
11540: if (document.getElementById(context+'_recaptchapub')) {
11541: pubitem = document.getElementById(context+'_recaptchapub');
11542: } else {
11543: return;
11544: }
11545: if (document.getElementById(context+'_recaptchapriv')) {
11546: privitem = document.getElementById(context+'_recaptchapriv');
11547: } else {
11548: return;
11549: }
11550: if (document.getElementById(context+'_recaptchapubtxt')) {
11551: pubtext = document.getElementById(context+'_recaptchapubtxt');
11552: } else {
11553: return;
11554: }
11555: if (document.getElementById(context+'_recaptchaprivtxt')) {
11556: privtext = document.getElementById(context+'_recaptchaprivtxt');
11557: } else {
11558: return;
11559: }
11560: if (caller.checked) {
11561: if (caller.value == 'recaptcha') {
11562: pubitem.type = 'text';
11563: privitem.type = 'text';
11564: pubitem.size = '40';
11565: privitem.size = '40';
11566: pubtext.innerHTML = "$lt{'pub'}";
11567: privtext.innerHTML = "$lt{'priv'}";
11568: } else {
11569: pubitem.type = 'hidden';
11570: privitem.type = 'hidden';
11571: pubtext.innerHTML = '';
11572: privtext.innerHTML = '';
11573: }
11574: }
11575: return;
11576: }
11577:
11578: // ]]>
11579: </script>
11580:
11581: END
11582:
11583: }
11584:
1.236 raeburn 11585: sub toggle_display_js {
1.192 raeburn 11586: return <<"END";
11587:
11588: <script type="text/javascript">
11589: // <![CDATA[
11590:
1.236 raeburn 11591: function toggleDisplay(domForm,caller) {
11592: if (document.getElementById(caller)) {
11593: var divitem = document.getElementById(caller);
11594: var optionsElement = domForm.coursecredits;
11595: if (caller == 'emailoptions') {
11596: optionsElement = domForm.cancreate_email;
11597: }
11598: if (optionsElement.length) {
1.192 raeburn 11599: var currval;
1.236 raeburn 11600: for (var i=0; i<optionsElement.length; i++) {
11601: if (optionsElement[i].checked) {
11602: currval = optionsElement[i].value;
1.192 raeburn 11603: }
11604: }
11605: if (currval == 1) {
1.236 raeburn 11606: divitem.style.display = 'block';
1.192 raeburn 11607: } else {
1.236 raeburn 11608: divitem.style.display = 'none';
1.192 raeburn 11609: }
11610: }
11611: }
11612: return;
11613: }
11614:
11615: // ]]>
11616: </script>
11617:
11618: END
11619:
11620: }
11621:
1.165 raeburn 11622: sub captcha_phrases {
11623: return &Apache::lonlocal::texthash (
11624: priv => 'Private key',
11625: pub => 'Public key',
11626: original => 'original (CAPTCHA)',
11627: recaptcha => 'successor (ReCAPTCHA)',
11628: notused => 'unused',
11629: );
11630: }
11631:
1.205 raeburn 11632: sub devalidate_remote_domconfs {
1.212 raeburn 11633: my ($dom,$cachekeys) = @_;
11634: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 11635: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11636: my %thismachine;
11637: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 11638: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 11639: if (keys(%servers) > 1) {
11640: foreach my $server (keys(%servers)) {
11641: next if ($thismachine{$server});
1.212 raeburn 11642: my @cached;
11643: foreach my $name (@posscached) {
11644: if ($cachekeys->{$name}) {
11645: push(@cached,&escape($name).':'.&escape($dom));
11646: }
11647: }
11648: if (@cached) {
11649: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11650: }
1.205 raeburn 11651: }
11652: }
11653: return;
11654: }
11655:
1.3 raeburn 11656: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>