Annotation of loncom/interface/domainprefs.pm, revision 1.238
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.238 ! raeburn 4: # $Id: domainprefs.pm,v 1.237 2014/04/25 17:56:43 bisitz 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 => ''},
372: {col1 => 'Validation (not official courses)',
373: col2 => 'Value'},],
1.230 raeburn 374: print => \&print_quotas,
375: modify => \&modify_quotas,
1.86 raeburn 376: },
1.163 raeburn 377: 'requestauthor' =>
1.223 bisitz 378: {text => 'Request Authoring Space',
1.163 raeburn 379: help => 'Domain_Configuration_Request_Author',
380: header => [{col1 => 'User affiliation',
381: col2 => 'Availability/Processing of requests',},
382: {col1 => 'Setting',
383: col2 => 'Value'}],
1.230 raeburn 384: print => \&print_quotas,
385: modify => \&modify_quotas,
1.163 raeburn 386: },
1.69 raeburn 387: 'coursecategories' =>
1.120 raeburn 388: { text => 'Cataloging of courses/communities',
1.67 raeburn 389: help => 'Domain_Configuration_Cataloging_Courses',
1.238 ! raeburn 390: header => [{col1 => 'Catalog type/availability',
! 391: col2 => '',},
! 392: {col1 => 'Category settings for standard catalog',
1.57 raeburn 393: col2 => '',},
394: {col1 => 'Categories',
395: col2 => '',
396: }],
1.230 raeburn 397: print => \&print_coursecategories,
398: modify => \&modify_coursecategories,
1.69 raeburn 399: },
400: 'serverstatuses' =>
1.77 raeburn 401: {text => 'Access to server status pages',
1.69 raeburn 402: help => 'Domain_Configuration_Server_Status',
403: header => [{col1 => 'Status Page',
404: col2 => 'Other named users',
405: col3 => 'Specific IPs',
406: }],
1.230 raeburn 407: print => \&print_serverstatuses,
408: modify => \&modify_serverstatuses,
1.69 raeburn 409: },
1.118 jms 410: 'helpsettings' =>
411: {text => 'Help page settings',
412: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 413: header => [{col1 => 'Help Settings (logged-in users)',
414: col2 => 'Value'}],
1.230 raeburn 415: print => \&print_helpsettings,
416: modify => \&modify_helpsettings,
1.118 jms 417: },
1.121 raeburn 418: 'coursedefaults' =>
419: {text => 'Course/Community defaults',
420: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 421: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
422: col2 => 'Value',},
423: {col1 => 'Defaults which can be overridden for each course by a DC',
424: col2 => 'Value',},],
1.230 raeburn 425: print => \&print_coursedefaults,
426: modify => \&modify_coursedefaults,
1.121 raeburn 427: },
1.231 raeburn 428: 'selfenrollment' =>
429: {text => 'Self-enrollment in Course/Community',
430: help => 'Domain_Configuration_Selfenrollment',
431: header => [{col1 => 'Configuration Rights',
432: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
433: {col1 => 'Defaults',
434: col2 => 'Value'},
435: {col1 => 'Self-enrollment validation (optional)',
436: col2 => 'Value'},],
437: print => \&print_selfenrollment,
438: modify => \&modify_selfenrollment,
439: },
1.120 raeburn 440: 'privacy' =>
441: {text => 'User Privacy',
442: help => 'Domain_Configuration_User_Privacy',
443: header => [{col1 => 'Setting',
444: col2 => 'Value',}],
1.230 raeburn 445: print => \&print_privacy,
446: modify => \&modify_privacy,
1.120 raeburn 447: },
1.141 raeburn 448: 'usersessions' =>
1.145 raeburn 449: {text => 'User session hosting/offloading',
1.137 raeburn 450: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 451: header => [{col1 => 'Domain server',
452: col2 => 'Servers to offload sessions to when busy'},
453: {col1 => 'Hosting of users from other domains',
1.137 raeburn 454: col2 => 'Rules'},
455: {col1 => "Hosting domain's own users elsewhere",
456: col2 => 'Rules'}],
1.230 raeburn 457: print => \&print_usersessions,
458: modify => \&modify_usersessions,
1.137 raeburn 459: },
1.150 raeburn 460: 'loadbalancing' =>
1.185 raeburn 461: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 462: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 463: header => [{col1 => 'Balancers',
1.150 raeburn 464: col2 => 'Default destinations',
1.183 bisitz 465: col3 => 'User affiliation',
1.150 raeburn 466: col4 => 'Overrides'},
467: ],
1.230 raeburn 468: print => \&print_loadbalancing,
469: modify => \&modify_loadbalancing,
1.150 raeburn 470: },
1.3 raeburn 471: );
1.110 raeburn 472: if (keys(%servers) > 1) {
473: $prefs{'login'} = { text => 'Log-in page options',
474: help => 'Domain_Configuration_Login_Page',
475: header => [{col1 => 'Log-in Service',
476: col2 => 'Server Setting',},
477: {col1 => 'Log-in Page Items',
1.168 raeburn 478: col2 => ''},
479: {col1 => 'Log-in Help',
480: col2 => 'Value'}],
1.230 raeburn 481: print => \&print_login,
482: modify => \&modify_login,
1.110 raeburn 483: };
484: }
1.174 foxr 485:
1.6 raeburn 486: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 487: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 488: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 489: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 490: text=>"Settings to display/modify"});
1.9 raeburn 491: my $confname = $dom.'-domainconfig';
1.174 foxr 492:
1.3 raeburn 493: if ($phase eq 'process') {
1.212 raeburn 494: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
495: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 496: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 497: $r->rflush();
1.212 raeburn 498: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 499: }
1.30 raeburn 500: } elsif ($phase eq 'display') {
1.192 raeburn 501: my $js = &recaptcha_js().
1.236 raeburn 502: &toggle_display_js();
1.171 raeburn 503: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 504: my ($othertitle,$usertypes,$types) =
505: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 506: $js .= &lonbalance_targets_js($dom,$types,\%servers,
507: $domconfig{'loadbalancing'}).
1.170 raeburn 508: &new_spares_js().
509: &common_domprefs_js().
510: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 511: }
1.216 raeburn 512: if (grep(/^requestcourses$/,@actions)) {
513: my $javascript_validations;
514: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
515: $js .= <<END;
516: <script type="text/javascript">
517: $javascript_validations
518: </script>
519: $coursebrowserjs
520: END
521: }
1.150 raeburn 522: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 523: } else {
1.180 raeburn 524: # check if domconfig user exists for the domain.
525: my $servadm = $r->dir_config('lonAdmEMail');
526: my ($configuserok,$author_ok,$switchserver) =
527: &config_check($dom,$confname,$servadm);
528: unless ($configuserok eq 'ok') {
1.181 raeburn 529: &Apache::lonconfigsettings::print_header($r,$phase,$context);
530: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 531: $confname).
1.181 raeburn 532: '<br />'
533: );
1.180 raeburn 534: if ($switchserver) {
1.181 raeburn 535: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
536: '<br />'.
537: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
538: '<br />'.
539: &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).
540: '<br />'.
541: &mt('To do that now, use the following link: [_1]',$switchserver)
542: );
543: } else {
544: $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.').
545: '<br />'.
546: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
547: );
1.180 raeburn 548: }
549: $r->print(&Apache::loncommon::end_page());
550: return OK;
551: }
1.21 raeburn 552: if (keys(%domconfig) == 0) {
553: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 554: my @ids=&Apache::lonnet::current_machine_ids();
555: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 556: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 557: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 558: my $custom_img_count = 0;
559: foreach my $img (@loginimages) {
560: if ($designhash{$dom.'.login.'.$img} ne '') {
561: $custom_img_count ++;
562: }
563: }
564: foreach my $role (@roles) {
565: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
566: $custom_img_count ++;
567: }
568: }
569: if ($custom_img_count > 0) {
1.94 raeburn 570: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 571: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 572: $r->print(
573: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
574: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
575: &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 />'.
576: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
577: if ($switch_server) {
1.30 raeburn 578: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 579: }
1.91 raeburn 580: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 581: return OK;
582: }
583: }
584: }
1.91 raeburn 585: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 586: }
587: return OK;
588: }
589:
590: sub process_changes {
1.205 raeburn 591: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 592: my %domconfig;
593: if (ref($values) eq 'HASH') {
594: %domconfig = %{$values};
595: }
1.3 raeburn 596: my $output;
597: if ($action eq 'login') {
1.205 raeburn 598: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 599: } elsif ($action eq 'rolecolors') {
1.9 raeburn 600: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 601: $lastactref,%domconfig);
1.3 raeburn 602: } elsif ($action eq 'quotas') {
1.216 raeburn 603: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 604: } elsif ($action eq 'autoenroll') {
1.205 raeburn 605: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 606: } elsif ($action eq 'autoupdate') {
607: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 608: } elsif ($action eq 'autocreate') {
609: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 610: } elsif ($action eq 'directorysrch') {
611: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 612: } elsif ($action eq 'usercreation') {
1.28 raeburn 613: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 614: } elsif ($action eq 'selfcreation') {
615: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 616: } elsif ($action eq 'usermodification') {
617: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 618: } elsif ($action eq 'contacts') {
1.205 raeburn 619: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 620: } elsif ($action eq 'defaults') {
1.212 raeburn 621: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 622: } elsif ($action eq 'scantron') {
1.205 raeburn 623: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 624: } elsif ($action eq 'coursecategories') {
625: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 626: } elsif ($action eq 'serverstatuses') {
627: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 628: } elsif ($action eq 'requestcourses') {
1.216 raeburn 629: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 630: } elsif ($action eq 'requestauthor') {
1.216 raeburn 631: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 632: } elsif ($action eq 'helpsettings') {
1.122 jms 633: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 634: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 635: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 636: } elsif ($action eq 'selfenrollment') {
637: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 638: } elsif ($action eq 'usersessions') {
1.212 raeburn 639: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 640: } elsif ($action eq 'loadbalancing') {
641: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 642: }
643: return $output;
644: }
645:
646: sub print_config_box {
1.9 raeburn 647: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 648: my $rowtotal = 0;
1.49 raeburn 649: my $output;
650: if ($action eq 'coursecategories') {
651: $output = &coursecategories_javascript($settings);
1.236 raeburn 652: } elsif ($action eq 'defaults') {
653: $output = &defaults_javascript($settings);
1.91 raeburn 654: }
1.236 raeburn 655: $output .=
1.30 raeburn 656: '<table class="LC_nested_outer">
1.3 raeburn 657: <tr>
1.66 raeburn 658: <th align="left" valign="middle"><span class="LC_nobreak">'.
659: &mt($item->{text}).' '.
660: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
661: '</tr>';
1.30 raeburn 662: $rowtotal ++;
1.110 raeburn 663: my $numheaders = 1;
664: if (ref($item->{'header'}) eq 'ARRAY') {
665: $numheaders = scalar(@{$item->{'header'}});
666: }
667: if ($numheaders > 1) {
1.64 raeburn 668: my $colspan = '';
1.145 raeburn 669: my $rightcolspan = '';
1.238 ! raeburn 670: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.168 raeburn 671: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 672: $colspan = ' colspan="2"';
673: }
1.145 raeburn 674: if ($action eq 'usersessions') {
675: $rightcolspan = ' colspan="3"';
676: }
1.30 raeburn 677: $output .= '
1.3 raeburn 678: <tr>
679: <td>
680: <table class="LC_nested">
681: <tr class="LC_info_row">
1.59 bisitz 682: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 683: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 684: </tr>';
1.69 raeburn 685: $rowtotal ++;
1.230 raeburn 686: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 687: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.230 raeburn 688: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
689: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 690: } elsif ($action eq 'coursecategories') {
1.230 raeburn 691: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 692: } elsif ($action eq 'login') {
1.168 raeburn 693: if ($numheaders == 3) {
694: $colspan = ' colspan="2"';
695: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
696: } else {
697: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
698: }
1.230 raeburn 699: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 700: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 701: } elsif ($action eq 'rolecolors') {
1.30 raeburn 702: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 703: }
1.30 raeburn 704: $output .= '
1.6 raeburn 705: </table>
706: </td>
707: </tr>
708: <tr>
709: <td>
710: <table class="LC_nested">
711: <tr class="LC_info_row">
1.230 raeburn 712: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 713: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 714: </tr>';
715: $rowtotal ++;
1.230 raeburn 716: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
717: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.238 ! raeburn 718: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
! 719: if ($action eq 'coursecategories') {
! 720: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
! 721: $colspan = ' colspan="2"';
! 722: } else {
! 723: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
! 724: }
! 725: $output .= '
1.63 raeburn 726: </table>
727: </td>
728: </tr>
729: <tr>
730: <td>
731: <table class="LC_nested">
732: <tr class="LC_info_row">
733: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 734: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 ! raeburn 735: </tr>'."\n";
! 736: if ($action eq 'coursecategories') {
! 737: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
! 738: } else {
! 739: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
! 740: }
1.63 raeburn 741: $rowtotal ++;
1.236 raeburn 742: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
743: ($action eq 'defaults')) {
1.230 raeburn 744: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 745: } elsif ($action eq 'login') {
1.168 raeburn 746: if ($numheaders == 3) {
747: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
748: </table>
749: </td>
750: </tr>
751: <tr>
752: <td>
753: <table class="LC_nested">
754: <tr class="LC_info_row">
755: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 756: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 757: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
758: $rowtotal ++;
759: } else {
760: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
761: }
1.102 raeburn 762: } elsif ($action eq 'requestcourses') {
1.216 raeburn 763: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
764: &print_studentcode($settings,\$rowtotal).'
765: </table>
766: </td>
767: </tr>
768: <tr>
769: <td>
770: <table class="LC_nested">
771: <tr class="LC_info_row">
772: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
773: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.235 raeburn 774: &print_textbookcourses($dom,$settings,\$rowtotal).'
775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
782: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
783: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
784: </tr>'.
785: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 786: } elsif ($action eq 'requestauthor') {
787: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 788: } elsif ($action eq 'rolecolors') {
1.30 raeburn 789: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 790: </table>
791: </td>
792: </tr>
793: <tr>
794: <td>
795: <table class="LC_nested">
796: <tr class="LC_info_row">
1.69 raeburn 797: <td class="LC_left_item"'.$colspan.' valign="top">'.
798: &mt($item->{'header'}->[2]->{'col1'}).'</td>
799: <td class="LC_right_item" valign="top">'.
800: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 801: </tr>'.
1.30 raeburn 802: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 803: </table>
804: </td>
805: </tr>
806: <tr>
807: <td>
808: <table class="LC_nested">
809: <tr class="LC_info_row">
1.59 bisitz 810: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
811: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 812: </tr>'.
1.30 raeburn 813: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
814: $rowtotal += 2;
1.6 raeburn 815: }
1.3 raeburn 816: } else {
1.30 raeburn 817: $output .= '
1.3 raeburn 818: <tr>
819: <td>
820: <table class="LC_nested">
1.30 raeburn 821: <tr class="LC_info_row">';
1.24 raeburn 822: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 823: $output .= '
1.59 bisitz 824: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 825: } elsif ($action eq 'serverstatuses') {
826: $output .= '
827: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
828: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
829:
1.6 raeburn 830: } else {
1.30 raeburn 831: $output .= '
1.69 raeburn 832: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
833: }
1.72 raeburn 834: if (defined($item->{'header'}->[0]->{'col3'})) {
835: $output .= '<td class="LC_left_item" valign="top">'.
836: &mt($item->{'header'}->[0]->{'col2'});
837: if ($action eq 'serverstatuses') {
838: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
839: }
1.69 raeburn 840: } else {
841: $output .= '<td class="LC_right_item" valign="top">'.
842: &mt($item->{'header'}->[0]->{'col2'});
843: }
844: $output .= '</td>';
845: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 846: if (defined($item->{'header'}->[0]->{'col4'})) {
847: $output .= '<td class="LC_left_item" valign="top">'.
848: &mt($item->{'header'}->[0]->{'col3'});
849: } else {
850: $output .= '<td class="LC_right_item" valign="top">'.
851: &mt($item->{'header'}->[0]->{'col3'});
852: }
1.69 raeburn 853: if ($action eq 'serverstatuses') {
854: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
855: }
856: $output .= '</td>';
1.6 raeburn 857: }
1.150 raeburn 858: if ($item->{'header'}->[0]->{'col4'}) {
859: $output .= '<td class="LC_right_item" valign="top">'.
860: &mt($item->{'header'}->[0]->{'col4'});
861: }
1.69 raeburn 862: $output .= '</tr>';
1.48 raeburn 863: $rowtotal ++;
1.168 raeburn 864: if ($action eq 'quotas') {
1.86 raeburn 865: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 866: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.236 raeburn 867: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.230 raeburn 868: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 869: } elsif ($action eq 'scantron') {
870: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 871: } elsif ($action eq 'helpsettings') {
1.168 raeburn 872: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 873: }
1.3 raeburn 874: }
1.30 raeburn 875: $output .= '
1.3 raeburn 876: </table>
877: </td>
878: </tr>
1.30 raeburn 879: </table><br />';
880: return ($output,$rowtotal);
1.1 raeburn 881: }
882:
1.3 raeburn 883: sub print_login {
1.168 raeburn 884: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 885: my ($css_class,$datatable);
1.6 raeburn 886: my %choices = &login_choices();
1.110 raeburn 887:
1.168 raeburn 888: if ($caller eq 'service') {
1.149 raeburn 889: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 890: my $choice = $choices{'disallowlogin'};
891: $css_class = ' class="LC_odd_row"';
1.128 raeburn 892: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 893: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 894: '<th>'.$choices{'server'}.'</th>'.
895: '<th>'.$choices{'serverpath'}.'</th>'.
896: '<th>'.$choices{'custompath'}.'</th>'.
897: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 898: my %disallowed;
899: if (ref($settings) eq 'HASH') {
900: if (ref($settings->{'loginvia'}) eq 'HASH') {
901: %disallowed = %{$settings->{'loginvia'}};
902: }
903: }
904: foreach my $lonhost (sort(keys(%servers))) {
905: my $direct = 'selected="selected"';
1.128 raeburn 906: if (ref($disallowed{$lonhost}) eq 'HASH') {
907: if ($disallowed{$lonhost}{'server'} ne '') {
908: $direct = '';
909: }
1.110 raeburn 910: }
1.115 raeburn 911: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 912: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 913: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
914: '</option>';
1.184 raeburn 915: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 916: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 917: my $selected = '';
1.128 raeburn 918: if (ref($disallowed{$lonhost}) eq 'HASH') {
919: if ($hostid eq $disallowed{$lonhost}{'server'}) {
920: $selected = 'selected="selected"';
921: }
1.110 raeburn 922: }
923: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
924: $servers{$hostid}.'</option>';
925: }
1.128 raeburn 926: $datatable .= '</select></td>'.
927: '<td><select name="'.$lonhost.'_serverpath">';
928: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
929: my $pathname = $path;
930: if ($path eq 'custom') {
931: $pathname = &mt('Custom Path').' ->';
932: }
933: my $selected = '';
934: if (ref($disallowed{$lonhost}) eq 'HASH') {
935: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
936: $selected = 'selected="selected"';
937: }
938: } elsif ($path eq '') {
939: $selected = 'selected="selected"';
940: }
941: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
942: }
943: $datatable .= '</select></td>';
944: my ($custom,$exempt);
945: if (ref($disallowed{$lonhost}) eq 'HASH') {
946: $custom = $disallowed{$lonhost}{'custompath'};
947: $exempt = $disallowed{$lonhost}{'exempt'};
948: }
949: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
950: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
951: '</tr>';
1.110 raeburn 952: }
953: $datatable .= '</table></td></tr>';
954: return $datatable;
1.168 raeburn 955: } elsif ($caller eq 'page') {
956: my %defaultchecked = (
957: 'coursecatalog' => 'on',
1.188 raeburn 958: 'helpdesk' => 'on',
1.168 raeburn 959: 'adminmail' => 'off',
960: 'newuser' => 'off',
961: );
1.188 raeburn 962: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 963: my (%checkedon,%checkedoff);
1.42 raeburn 964: foreach my $item (@toggles) {
1.168 raeburn 965: if ($defaultchecked{$item} eq 'on') {
966: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 967: $checkedoff{$item} = ' ';
1.168 raeburn 968: } elsif ($defaultchecked{$item} eq 'off') {
969: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 970: $checkedon{$item} = ' ';
971: }
1.1 raeburn 972: }
1.168 raeburn 973: my @images = ('img','logo','domlogo','login');
974: my @logintext = ('textcol','bgcol');
975: my @bgs = ('pgbg','mainbg','sidebg');
976: my @links = ('link','alink','vlink');
977: my %designhash = &Apache::loncommon::get_domainconf($dom);
978: my %defaultdesign = %Apache::loncommon::defaultdesign;
979: my (%is_custom,%designs);
980: my %defaults = (
981: font => $defaultdesign{'login.font'},
982: );
1.6 raeburn 983: foreach my $item (@images) {
1.168 raeburn 984: $defaults{$item} = $defaultdesign{'login.'.$item};
985: $defaults{'showlogo'}{$item} = 1;
986: }
987: foreach my $item (@bgs) {
988: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 989: }
1.41 raeburn 990: foreach my $item (@logintext) {
1.168 raeburn 991: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 992: }
1.168 raeburn 993: foreach my $item (@links) {
994: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 995: }
1.168 raeburn 996: if (ref($settings) eq 'HASH') {
997: foreach my $item (@toggles) {
998: if ($settings->{$item} eq '1') {
999: $checkedon{$item} = ' checked="checked" ';
1000: $checkedoff{$item} = ' ';
1001: } elsif ($settings->{$item} eq '0') {
1002: $checkedoff{$item} = ' checked="checked" ';
1003: $checkedon{$item} = ' ';
1004: }
1005: }
1006: foreach my $item (@images) {
1007: if (defined($settings->{$item})) {
1008: $designs{$item} = $settings->{$item};
1009: $is_custom{$item} = 1;
1010: }
1011: if (defined($settings->{'showlogo'}{$item})) {
1012: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1013: }
1014: }
1015: foreach my $item (@logintext) {
1016: if ($settings->{$item} ne '') {
1017: $designs{'logintext'}{$item} = $settings->{$item};
1018: $is_custom{$item} = 1;
1019: }
1020: }
1021: if ($settings->{'font'} ne '') {
1022: $designs{'font'} = $settings->{'font'};
1023: $is_custom{'font'} = 1;
1024: }
1025: foreach my $item (@bgs) {
1026: if ($settings->{$item} ne '') {
1027: $designs{'bgs'}{$item} = $settings->{$item};
1028: $is_custom{$item} = 1;
1029: }
1030: }
1031: foreach my $item (@links) {
1032: if ($settings->{$item} ne '') {
1033: $designs{'links'}{$item} = $settings->{$item};
1034: $is_custom{$item} = 1;
1035: }
1036: }
1037: } else {
1038: if ($designhash{$dom.'.login.font'} ne '') {
1039: $designs{'font'} = $designhash{$dom.'.login.font'};
1040: $is_custom{'font'} = 1;
1041: }
1042: foreach my $item (@images) {
1043: if ($designhash{$dom.'.login.'.$item} ne '') {
1044: $designs{$item} = $designhash{$dom.'.login.'.$item};
1045: $is_custom{$item} = 1;
1046: }
1047: }
1048: foreach my $item (@bgs) {
1049: if ($designhash{$dom.'.login.'.$item} ne '') {
1050: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1051: $is_custom{$item} = 1;
1052: }
1.6 raeburn 1053: }
1.168 raeburn 1054: foreach my $item (@links) {
1055: if ($designhash{$dom.'.login.'.$item} ne '') {
1056: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1057: $is_custom{$item} = 1;
1058: }
1.6 raeburn 1059: }
1060: }
1.168 raeburn 1061: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1062: logo => 'Institution Logo',
1063: domlogo => 'Domain Logo',
1064: login => 'Login box');
1065: my $itemcount = 1;
1066: foreach my $item (@toggles) {
1067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1068: $datatable .=
1069: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1070: '</td><td>'.
1071: '<span class="LC_nobreak"><label><input type="radio" name="'.
1072: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1073: '</label> <label><input type="radio" name="'.$item.'"'.
1074: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1075: '</tr>';
1076: $itemcount ++;
1.6 raeburn 1077: }
1.168 raeburn 1078: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1079: $datatable .= '</tr></table></td></tr>';
1080: } elsif ($caller eq 'help') {
1081: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1082: my $switchserver = &check_switchserver($dom,$confname);
1083: my $itemcount = 1;
1084: $defaulturl = '/adm/loginproblems.html';
1085: $defaulttype = 'default';
1086: %lt = &Apache::lonlocal::texthash (
1087: del => 'Delete?',
1088: rep => 'Replace:',
1089: upl => 'Upload:',
1090: default => 'Default',
1091: custom => 'Custom',
1092: );
1093: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1094: my @currlangs;
1095: if (ref($settings) eq 'HASH') {
1096: if (ref($settings->{'helpurl'}) eq 'HASH') {
1097: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1098: next if ($settings->{'helpurl'}{$key} eq '');
1099: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1100: $type{$key} = 'custom';
1101: unless ($key eq 'nolang') {
1102: push(@currlangs,$key);
1103: }
1104: }
1105: } elsif ($settings->{'helpurl'} ne '') {
1106: $type{'nolang'} = 'custom';
1107: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1108: }
1109: }
1.168 raeburn 1110: foreach my $lang ('nolang',sort(@currlangs)) {
1111: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1112: $datatable .= '<tr'.$css_class.'>';
1113: if ($url{$lang} eq '') {
1114: $url{$lang} = $defaulturl;
1115: }
1116: if ($type{$lang} eq '') {
1117: $type{$lang} = $defaulttype;
1118: }
1119: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1120: if ($lang eq 'nolang') {
1121: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1122: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1123: } else {
1124: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1125: $langchoices{$lang},
1126: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1127: }
1128: $datatable .= '</span></td>'."\n".
1129: '<td class="LC_left_item">';
1130: if ($type{$lang} eq 'custom') {
1131: $datatable .= '<span class="LC_nobreak"><label>'.
1132: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1133: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1134: } else {
1135: $datatable .= $lt{'upl'};
1136: }
1137: $datatable .='<br />';
1138: if ($switchserver) {
1139: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1140: } else {
1141: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1142: }
1.168 raeburn 1143: $datatable .= '</td></tr>';
1144: $itemcount ++;
1.6 raeburn 1145: }
1.168 raeburn 1146: my @addlangs;
1147: foreach my $lang (sort(keys(%langchoices))) {
1148: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1149: push(@addlangs,$lang);
1150: }
1151: if (@addlangs > 0) {
1152: my %toadd;
1153: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1154: $toadd{''} = &mt('Select');
1155: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1156: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1157: &mt('Add log-in help page for a specific language:').' '.
1158: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1159: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1160: if ($switchserver) {
1161: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1162: } else {
1163: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1164: }
1.168 raeburn 1165: $datatable .= '</td></tr>';
1.169 raeburn 1166: $itemcount ++;
1.6 raeburn 1167: }
1.169 raeburn 1168: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1169: }
1.6 raeburn 1170: return $datatable;
1171: }
1172:
1173: sub login_choices {
1174: my %choices =
1175: &Apache::lonlocal::texthash (
1.116 bisitz 1176: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1177: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1178: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1179: disallowlogin => "Login page requests redirected",
1180: hostid => "Server",
1.128 raeburn 1181: server => "Redirect to:",
1182: serverpath => "Path",
1183: custompath => "Custom",
1184: exempt => "Exempt IP(s)",
1.110 raeburn 1185: directlogin => "No redirect",
1186: newuser => "Link to create a user account",
1187: img => "Header",
1188: logo => "Main Logo",
1189: domlogo => "Domain Logo",
1190: login => "Log-in Header",
1191: textcol => "Text color",
1192: bgcol => "Box color",
1193: bgs => "Background colors",
1194: links => "Link colors",
1195: font => "Font color",
1196: pgbg => "Header",
1197: mainbg => "Page",
1198: sidebg => "Login box",
1199: link => "Link",
1200: alink => "Active link",
1201: vlink => "Visited link",
1.6 raeburn 1202: );
1203: return %choices;
1204: }
1205:
1206: sub print_rolecolors {
1.30 raeburn 1207: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1208: my %choices = &color_font_choices();
1209: my @bgs = ('pgbg','tabbg','sidebg');
1210: my @links = ('link','alink','vlink');
1211: my @images = ('img');
1212: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1213: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1214: my %defaultdesign = %Apache::loncommon::defaultdesign;
1215: my (%is_custom,%designs);
1.200 raeburn 1216: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1217: if (ref($settings) eq 'HASH') {
1218: if (ref($settings->{$role}) eq 'HASH') {
1219: if ($settings->{$role}->{'img'} ne '') {
1220: $designs{'img'} = $settings->{$role}->{'img'};
1221: $is_custom{'img'} = 1;
1222: }
1223: if ($settings->{$role}->{'font'} ne '') {
1224: $designs{'font'} = $settings->{$role}->{'font'};
1225: $is_custom{'font'} = 1;
1226: }
1.97 tempelho 1227: if ($settings->{$role}->{'fontmenu'} ne '') {
1228: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1229: $is_custom{'fontmenu'} = 1;
1230: }
1.6 raeburn 1231: foreach my $item (@bgs) {
1232: if ($settings->{$role}->{$item} ne '') {
1233: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1234: $is_custom{$item} = 1;
1235: }
1236: }
1237: foreach my $item (@links) {
1238: if ($settings->{$role}->{$item} ne '') {
1239: $designs{'links'}{$item} = $settings->{$role}->{$item};
1240: $is_custom{$item} = 1;
1241: }
1242: }
1243: }
1244: } else {
1245: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1246: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1247: $is_custom{'img'} = 1;
1248: }
1.97 tempelho 1249: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1250: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1251: $is_custom{'fontmenu'} = 1;
1252: }
1.6 raeburn 1253: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1254: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1255: $is_custom{'font'} = 1;
1256: }
1257: foreach my $item (@bgs) {
1258: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1259: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1260: $is_custom{$item} = 1;
1261:
1262: }
1263: }
1264: foreach my $item (@links) {
1265: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1266: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1267: $is_custom{$item} = 1;
1268: }
1269: }
1270: }
1271: my $itemcount = 1;
1.30 raeburn 1272: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1273: $datatable .= '</tr></table></td></tr>';
1274: return $datatable;
1275: }
1276:
1.200 raeburn 1277: sub role_defaults {
1278: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1279: my %defaults;
1280: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1281: return %defaults;
1282: }
1283: my %defaultdesign = %Apache::loncommon::defaultdesign;
1284: if ($role eq 'login') {
1285: %defaults = (
1286: font => $defaultdesign{$role.'.font'},
1287: );
1288: if (ref($logintext) eq 'ARRAY') {
1289: foreach my $item (@{$logintext}) {
1290: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1291: }
1292: }
1293: foreach my $item (@{$images}) {
1294: $defaults{'showlogo'}{$item} = 1;
1295: }
1296: } else {
1297: %defaults = (
1298: img => $defaultdesign{$role.'.img'},
1299: font => $defaultdesign{$role.'.font'},
1300: fontmenu => $defaultdesign{$role.'.fontmenu'},
1301: );
1302: }
1303: foreach my $item (@{$bgs}) {
1304: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1305: }
1306: foreach my $item (@{$links}) {
1307: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1308: }
1309: foreach my $item (@{$images}) {
1310: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1311: }
1312: return %defaults;
1313: }
1314:
1.6 raeburn 1315: sub display_color_options {
1.9 raeburn 1316: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1317: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1318: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1319: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1320: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1321: '<td>'.$choices->{'font'}.'</td>';
1322: if (!$is_custom->{'font'}) {
1.30 raeburn 1323: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1324: } else {
1325: $datatable .= '<td> </td>';
1326: }
1.174 foxr 1327: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1328:
1.8 raeburn 1329: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1330: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1331: ' value="'.$current_color.'" /> '.
1.174 foxr 1332: ' </td></tr>';
1.107 raeburn 1333: unless ($role eq 'login') {
1334: $datatable .= '<tr'.$css_class.'>'.
1335: '<td>'.$choices->{'fontmenu'}.'</td>';
1336: if (!$is_custom->{'fontmenu'}) {
1337: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1338: } else {
1339: $datatable .= '<td> </td>';
1340: }
1.202 raeburn 1341: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1342: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1343: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1344: '<input class="colorchooser" type="text" size="10" name="'
1345: .$role.'_fontmenu"'.
1346: ' value="'.$current_color.'" /> '.
1347: ' </td></tr>';
1.97 tempelho 1348: }
1.9 raeburn 1349: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1350: foreach my $img (@{$images}) {
1.18 albertel 1351: $itemcount ++;
1.6 raeburn 1352: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1353: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1354: '<td>'.$choices->{$img};
1.41 raeburn 1355: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1356: if ($role eq 'login') {
1357: if ($img eq 'login') {
1358: $login_hdr_pick =
1.135 bisitz 1359: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1360: $logincolors =
1361: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1362: $designs,$defaults);
1.70 raeburn 1363: } elsif ($img ne 'domlogo') {
1364: $datatable.= &logo_display_options($img,$defaults,$designs);
1365: }
1366: }
1367: $datatable .= '</td>';
1.6 raeburn 1368: if ($designs->{$img} ne '') {
1369: $imgfile = $designs->{$img};
1.18 albertel 1370: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1371: } else {
1372: $imgfile = $defaults->{$img};
1373: }
1374: if ($imgfile) {
1.9 raeburn 1375: my ($showfile,$fullsize);
1376: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1377: my $urldir = $1;
1378: my $filename = $2;
1379: my @info = &Apache::lonnet::stat_file($designs->{$img});
1380: if (@info) {
1381: my $thumbfile = 'tn-'.$filename;
1382: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1383: if (@thumb) {
1384: $showfile = $urldir.'/'.$thumbfile;
1385: } else {
1386: $showfile = $imgfile;
1387: }
1388: } else {
1389: $showfile = '';
1390: }
1391: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1392: $showfile = $imgfile;
1.6 raeburn 1393: my $imgdir = $1;
1394: my $filename = $2;
1.159 raeburn 1395: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1396: $showfile = "/$imgdir/tn-".$filename;
1397: } else {
1.159 raeburn 1398: my $input = $londocroot.$imgfile;
1399: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1400: if (!-e $output) {
1.9 raeburn 1401: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1402: my ($fullwidth,$fullheight) = &check_dimensions($input);
1403: if ($fullwidth ne '' && $fullheight ne '') {
1404: if ($fullwidth > $width && $fullheight > $height) {
1405: my $size = $width.'x'.$height;
1406: system("convert -sample $size $input $output");
1.159 raeburn 1407: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1408: }
1409: }
1.6 raeburn 1410: }
1411: }
1.16 raeburn 1412: }
1.6 raeburn 1413: if ($showfile) {
1.40 raeburn 1414: if ($showfile =~ m{^/(adm|res)/}) {
1415: if ($showfile =~ m{^/res/}) {
1416: my $local_showfile =
1417: &Apache::lonnet::filelocation('',$showfile);
1418: &Apache::lonnet::repcopy($local_showfile);
1419: }
1420: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1421: }
1422: if ($imgfile) {
1423: if ($imgfile =~ m{^/(adm|res)/}) {
1424: if ($imgfile =~ m{^/res/}) {
1425: my $local_imgfile =
1426: &Apache::lonnet::filelocation('',$imgfile);
1427: &Apache::lonnet::repcopy($local_imgfile);
1428: }
1429: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1430: } else {
1431: $fullsize = $imgfile;
1432: }
1433: }
1.41 raeburn 1434: $datatable .= '<td>';
1435: if ($img eq 'login') {
1.135 bisitz 1436: $datatable .= $login_hdr_pick;
1437: }
1.41 raeburn 1438: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1439: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1440: } else {
1.201 raeburn 1441: $datatable .= '<td> </td><td class="LC_left_item">'.
1442: &mt('Upload:').'<br />';
1.6 raeburn 1443: }
1444: } else {
1.201 raeburn 1445: $datatable .= '<td> </td><td class="LC_left_item">'.
1446: &mt('Upload:').'<br />';
1.6 raeburn 1447: }
1.9 raeburn 1448: if ($switchserver) {
1449: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1450: } else {
1.135 bisitz 1451: if ($img ne 'login') { # suppress file selection for Log-in header
1452: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1453: }
1.9 raeburn 1454: }
1455: $datatable .= '</td></tr>';
1.6 raeburn 1456: }
1457: $itemcount ++;
1458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1459: $datatable .= '<tr'.$css_class.'>'.
1460: '<td>'.$choices->{'bgs'}.'</td>';
1461: my $bgs_def;
1462: foreach my $item (@{$bgs}) {
1463: if (!$is_custom->{$item}) {
1.70 raeburn 1464: $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 1465: }
1466: }
1467: if ($bgs_def) {
1.8 raeburn 1468: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1469: } else {
1470: $datatable .= '<td> </td>';
1471: }
1472: $datatable .= '<td class="LC_right_item">'.
1473: '<table border="0"><tr>';
1.174 foxr 1474:
1.6 raeburn 1475: foreach my $item (@{$bgs}) {
1.201 raeburn 1476: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1477: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1478: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1479: $datatable .= ' ';
1.6 raeburn 1480: }
1.174 foxr 1481: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1482: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1483: }
1484: $datatable .= '</tr></table></td></tr>';
1485: $itemcount ++;
1486: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1487: $datatable .= '<tr'.$css_class.'>'.
1488: '<td>'.$choices->{'links'}.'</td>';
1489: my $links_def;
1490: foreach my $item (@{$links}) {
1491: if (!$is_custom->{$item}) {
1.30 raeburn 1492: $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 1493: }
1494: }
1495: if ($links_def) {
1.8 raeburn 1496: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1497: } else {
1498: $datatable .= '<td> </td>';
1499: }
1500: $datatable .= '<td class="LC_right_item">'.
1501: '<table border="0"><tr>';
1502: foreach my $item (@{$links}) {
1.234 raeburn 1503: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1504: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1505: if ($designs->{'links'}{$item}) {
1.174 foxr 1506: $datatable.=' ';
1.6 raeburn 1507: }
1.174 foxr 1508: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1509: '" /></td>';
1510: }
1.30 raeburn 1511: $$rowtotal += $itemcount;
1.3 raeburn 1512: return $datatable;
1513: }
1514:
1.70 raeburn 1515: sub logo_display_options {
1516: my ($img,$defaults,$designs) = @_;
1517: my $checkedon;
1518: if (ref($defaults) eq 'HASH') {
1519: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1520: if ($defaults->{'showlogo'}{$img}) {
1521: $checkedon = 'checked="checked" ';
1522: }
1523: }
1524: }
1525: if (ref($designs) eq 'HASH') {
1526: if (ref($designs->{'showlogo'}) eq 'HASH') {
1527: if (defined($designs->{'showlogo'}{$img})) {
1528: if ($designs->{'showlogo'}{$img} == 0) {
1529: $checkedon = '';
1530: } elsif ($designs->{'showlogo'}{$img} == 1) {
1531: $checkedon = 'checked="checked" ';
1532: }
1533: }
1534: }
1535: }
1536: return '<br /><label> <input type="checkbox" name="'.
1537: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1538: &mt('show').'</label>'."\n";
1539: }
1540:
1.41 raeburn 1541: sub login_header_options {
1.135 bisitz 1542: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1543: my $output = '';
1.41 raeburn 1544: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1545: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1546: if (!$is_custom->{'textcol'}) {
1547: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1548: ' ';
1549: }
1550: if (!$is_custom->{'bgcol'}) {
1551: $output .= $choices->{'bgcol'}.': '.
1552: '<span id="css_'.$role.'_font" style="background-color: '.
1553: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1554: }
1555: $output .= '<br />';
1556: }
1557: $output .='<br />';
1558: return $output;
1559: }
1560:
1561: sub login_text_colors {
1.201 raeburn 1562: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1563: my $color_menu = '<table border="0"><tr>';
1564: foreach my $item (@{$logintext}) {
1.201 raeburn 1565: $color_menu .= '<td align="center">'.$choices->{$item};
1566: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1567: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1568: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1569: }
1570: $color_menu .= '</tr></table><br />';
1571: return $color_menu;
1572: }
1573:
1574: sub image_changes {
1575: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1576: my $output;
1.135 bisitz 1577: if ($img eq 'login') {
1578: # suppress image for Log-in header
1579: } elsif (!$is_custom) {
1.70 raeburn 1580: if ($img ne 'domlogo') {
1.41 raeburn 1581: $output .= &mt('Default image:').'<br />';
1582: } else {
1583: $output .= &mt('Default in use:').'<br />';
1584: }
1585: }
1.135 bisitz 1586: if ($img eq 'login') { # suppress image for Log-in header
1587: $output .= '<td>'.$logincolors;
1.41 raeburn 1588: } else {
1.135 bisitz 1589: if ($img_import) {
1590: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1591: }
1592: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1593: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1594: if ($is_custom) {
1595: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1596: '<input type="checkbox" name="'.
1597: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1598: '</label> '.&mt('Replace:').'</span><br />';
1599: } else {
1.201 raeburn 1600: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1601: }
1.41 raeburn 1602: }
1603: return $output;
1604: }
1605:
1.3 raeburn 1606: sub print_quotas {
1.86 raeburn 1607: my ($dom,$settings,$rowtotal,$action) = @_;
1608: my $context;
1609: if ($action eq 'quotas') {
1610: $context = 'tools';
1611: } else {
1612: $context = $action;
1613: }
1.197 raeburn 1614: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1615: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1616: my $typecount = 0;
1.101 raeburn 1617: my ($css_class,%titles);
1.86 raeburn 1618: if ($context eq 'requestcourses') {
1.216 raeburn 1619: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1620: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1621: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1622: %titles = &courserequest_titles();
1.163 raeburn 1623: } elsif ($context eq 'requestauthor') {
1624: @usertools = ('author');
1625: @options = ('norequest','approval','automatic');
1.210 raeburn 1626: %titles = &authorrequest_titles();
1.86 raeburn 1627: } else {
1.162 raeburn 1628: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1629: %titles = &tool_titles();
1.86 raeburn 1630: }
1.26 raeburn 1631: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1632: foreach my $type (@{$types}) {
1.197 raeburn 1633: my ($currdefquota,$currauthorquota);
1.163 raeburn 1634: unless (($context eq 'requestcourses') ||
1635: ($context eq 'requestauthor')) {
1.86 raeburn 1636: if (ref($settings) eq 'HASH') {
1637: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1638: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1639: } else {
1640: $currdefquota = $settings->{$type};
1641: }
1.197 raeburn 1642: if (ref($settings->{authorquota}) eq 'HASH') {
1643: $currauthorquota = $settings->{authorquota}->{$type};
1644: }
1.78 raeburn 1645: }
1.72 raeburn 1646: }
1.3 raeburn 1647: if (defined($usertypes->{$type})) {
1648: $typecount ++;
1649: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1650: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1651: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1652: '<td class="LC_left_item">';
1.101 raeburn 1653: if ($context eq 'requestcourses') {
1654: $datatable .= '<table><tr>';
1655: }
1656: my %cell;
1.72 raeburn 1657: foreach my $item (@usertools) {
1.101 raeburn 1658: if ($context eq 'requestcourses') {
1659: my ($curroption,$currlimit);
1660: if (ref($settings) eq 'HASH') {
1661: if (ref($settings->{$item}) eq 'HASH') {
1662: $curroption = $settings->{$item}->{$type};
1663: if ($curroption =~ /^autolimit=(\d*)$/) {
1664: $currlimit = $1;
1665: }
1666: }
1667: }
1668: if (!$curroption) {
1669: $curroption = 'norequest';
1670: }
1671: $datatable .= '<th>'.$titles{$item}.'</th>';
1672: foreach my $option (@options) {
1673: my $val = $option;
1674: if ($option eq 'norequest') {
1675: $val = 0;
1676: }
1677: if ($option eq 'validate') {
1678: my $canvalidate = 0;
1679: if (ref($validations{$item}) eq 'HASH') {
1680: if ($validations{$item}{$type}) {
1681: $canvalidate = 1;
1682: }
1683: }
1684: next if (!$canvalidate);
1685: }
1686: my $checked = '';
1687: if ($option eq $curroption) {
1688: $checked = ' checked="checked"';
1689: } elsif ($option eq 'autolimit') {
1690: if ($curroption =~ /^autolimit/) {
1691: $checked = ' checked="checked"';
1692: }
1693: }
1694: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1695: '<input type="radio" name="crsreq_'.$item.
1696: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1697: $titles{$option}.'</label>';
1.101 raeburn 1698: if ($option eq 'autolimit') {
1.127 raeburn 1699: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1700: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1701: 'value="'.$currlimit.'" />';
1.101 raeburn 1702: }
1.127 raeburn 1703: $cell{$item} .= '</span> ';
1.103 raeburn 1704: if ($option eq 'autolimit') {
1.127 raeburn 1705: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1706: }
1.101 raeburn 1707: }
1.163 raeburn 1708: } elsif ($context eq 'requestauthor') {
1709: my $curroption;
1710: if (ref($settings) eq 'HASH') {
1711: $curroption = $settings->{$type};
1712: }
1713: if (!$curroption) {
1714: $curroption = 'norequest';
1715: }
1716: foreach my $option (@options) {
1717: my $val = $option;
1718: if ($option eq 'norequest') {
1719: $val = 0;
1720: }
1721: my $checked = '';
1722: if ($option eq $curroption) {
1723: $checked = ' checked="checked"';
1724: }
1725: $datatable .= '<span class="LC_nobreak"><label>'.
1726: '<input type="radio" name="authorreq_'.$type.
1727: '" value="'.$val.'"'.$checked.' />'.
1728: $titles{$option}.'</label></span> ';
1729: }
1.101 raeburn 1730: } else {
1731: my $checked = 'checked="checked" ';
1732: if (ref($settings) eq 'HASH') {
1733: if (ref($settings->{$item}) eq 'HASH') {
1734: if ($settings->{$item}->{$type} == 0) {
1735: $checked = '';
1736: } elsif ($settings->{$item}->{$type} == 1) {
1737: $checked = 'checked="checked" ';
1738: }
1.78 raeburn 1739: }
1.72 raeburn 1740: }
1.101 raeburn 1741: $datatable .= '<span class="LC_nobreak"><label>'.
1742: '<input type="checkbox" name="'.$context.'_'.$item.
1743: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1744: '</label></span> ';
1.72 raeburn 1745: }
1.101 raeburn 1746: }
1747: if ($context eq 'requestcourses') {
1748: $datatable .= '</tr><tr>';
1749: foreach my $item (@usertools) {
1.106 raeburn 1750: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1751: }
1752: $datatable .= '</tr></table>';
1.72 raeburn 1753: }
1.86 raeburn 1754: $datatable .= '</td>';
1.163 raeburn 1755: unless (($context eq 'requestcourses') ||
1756: ($context eq 'requestauthor')) {
1.86 raeburn 1757: $datatable .=
1.197 raeburn 1758: '<td class="LC_right_item">'.
1759: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1760: '<input type="text" name="quota_'.$type.
1.72 raeburn 1761: '" value="'.$currdefquota.
1.197 raeburn 1762: '" size="5" /></span>'.(' ' x 2).
1763: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1764: '<input type="text" name="authorquota_'.$type.
1765: '" value="'.$currauthorquota.
1766: '" size="5" /></span></td>';
1.86 raeburn 1767: }
1768: $datatable .= '</tr>';
1.3 raeburn 1769: }
1770: }
1771: }
1.163 raeburn 1772: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1773: $defaultquota = '20';
1.197 raeburn 1774: $authorquota = '500';
1.86 raeburn 1775: if (ref($settings) eq 'HASH') {
1776: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1777: $defaultquota = $settings->{'defaultquota'}->{'default'};
1778: } elsif (defined($settings->{'default'})) {
1779: $defaultquota = $settings->{'default'};
1780: }
1.197 raeburn 1781: if (ref($settings->{'authorquota'}) eq 'HASH') {
1782: $authorquota = $settings->{'authorquota'}->{'default'};
1783: }
1.3 raeburn 1784: }
1785: }
1786: $typecount ++;
1787: $css_class = $typecount%2?' class="LC_odd_row"':'';
1788: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1789: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1790: '<td class="LC_left_item">';
1.101 raeburn 1791: if ($context eq 'requestcourses') {
1792: $datatable .= '<table><tr>';
1793: }
1794: my %defcell;
1.72 raeburn 1795: foreach my $item (@usertools) {
1.101 raeburn 1796: if ($context eq 'requestcourses') {
1797: my ($curroption,$currlimit);
1798: if (ref($settings) eq 'HASH') {
1799: if (ref($settings->{$item}) eq 'HASH') {
1800: $curroption = $settings->{$item}->{'default'};
1801: if ($curroption =~ /^autolimit=(\d*)$/) {
1802: $currlimit = $1;
1803: }
1804: }
1805: }
1806: if (!$curroption) {
1807: $curroption = 'norequest';
1808: }
1809: $datatable .= '<th>'.$titles{$item}.'</th>';
1810: foreach my $option (@options) {
1811: my $val = $option;
1812: if ($option eq 'norequest') {
1813: $val = 0;
1814: }
1815: if ($option eq 'validate') {
1816: my $canvalidate = 0;
1817: if (ref($validations{$item}) eq 'HASH') {
1818: if ($validations{$item}{'default'}) {
1819: $canvalidate = 1;
1820: }
1821: }
1822: next if (!$canvalidate);
1823: }
1824: my $checked = '';
1825: if ($option eq $curroption) {
1826: $checked = ' checked="checked"';
1827: } elsif ($option eq 'autolimit') {
1828: if ($curroption =~ /^autolimit/) {
1829: $checked = ' checked="checked"';
1830: }
1831: }
1832: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1833: '<input type="radio" name="crsreq_'.$item.
1834: '_default" value="'.$val.'"'.$checked.' />'.
1835: $titles{$option}.'</label>';
1836: if ($option eq 'autolimit') {
1.127 raeburn 1837: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1838: $item.'_limit_default" size="1" '.
1839: 'value="'.$currlimit.'" />';
1840: }
1.127 raeburn 1841: $defcell{$item} .= '</span> ';
1.104 raeburn 1842: if ($option eq 'autolimit') {
1.127 raeburn 1843: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1844: }
1.101 raeburn 1845: }
1.163 raeburn 1846: } elsif ($context eq 'requestauthor') {
1847: my $curroption;
1848: if (ref($settings) eq 'HASH') {
1.172 raeburn 1849: $curroption = $settings->{'default'};
1.163 raeburn 1850: }
1851: if (!$curroption) {
1852: $curroption = 'norequest';
1853: }
1854: foreach my $option (@options) {
1855: my $val = $option;
1856: if ($option eq 'norequest') {
1857: $val = 0;
1858: }
1859: my $checked = '';
1860: if ($option eq $curroption) {
1861: $checked = ' checked="checked"';
1862: }
1863: $datatable .= '<span class="LC_nobreak"><label>'.
1864: '<input type="radio" name="authorreq_default"'.
1865: ' value="'.$val.'"'.$checked.' />'.
1866: $titles{$option}.'</label></span> ';
1867: }
1.101 raeburn 1868: } else {
1869: my $checked = 'checked="checked" ';
1870: if (ref($settings) eq 'HASH') {
1871: if (ref($settings->{$item}) eq 'HASH') {
1872: if ($settings->{$item}->{'default'} == 0) {
1873: $checked = '';
1874: } elsif ($settings->{$item}->{'default'} == 1) {
1875: $checked = 'checked="checked" ';
1876: }
1.78 raeburn 1877: }
1.72 raeburn 1878: }
1.101 raeburn 1879: $datatable .= '<span class="LC_nobreak"><label>'.
1880: '<input type="checkbox" name="'.$context.'_'.$item.
1881: '" value="default" '.$checked.'/>'.$titles{$item}.
1882: '</label></span> ';
1883: }
1884: }
1885: if ($context eq 'requestcourses') {
1886: $datatable .= '</tr><tr>';
1887: foreach my $item (@usertools) {
1.106 raeburn 1888: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1889: }
1.101 raeburn 1890: $datatable .= '</tr></table>';
1.72 raeburn 1891: }
1.86 raeburn 1892: $datatable .= '</td>';
1.163 raeburn 1893: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1894: $datatable .= '<td class="LC_right_item">'.
1895: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1896: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1897: $defaultquota.'" size="5" /></span>'.(' ' x2).
1898: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1899: '<input type="text" name="authorquota" value="'.
1900: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1901: }
1902: $datatable .= '</tr>';
1.72 raeburn 1903: $typecount ++;
1904: $css_class = $typecount%2?' class="LC_odd_row"':'';
1905: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1906: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1907: if ($context eq 'requestcourses') {
1.109 raeburn 1908: $datatable .= &mt('(overrides affiliation, if set)').
1909: '</td>'.
1910: '<td class="LC_left_item">'.
1911: '<table><tr>';
1.101 raeburn 1912: } else {
1.109 raeburn 1913: $datatable .= &mt('(overrides affiliation, if checked)').
1914: '</td>'.
1915: '<td class="LC_left_item" colspan="2">'.
1916: '<br />';
1.101 raeburn 1917: }
1918: my %advcell;
1.72 raeburn 1919: foreach my $item (@usertools) {
1.101 raeburn 1920: if ($context eq 'requestcourses') {
1921: my ($curroption,$currlimit);
1922: if (ref($settings) eq 'HASH') {
1923: if (ref($settings->{$item}) eq 'HASH') {
1924: $curroption = $settings->{$item}->{'_LC_adv'};
1925: if ($curroption =~ /^autolimit=(\d*)$/) {
1926: $currlimit = $1;
1927: }
1928: }
1929: }
1930: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1931: my $checked = '';
1932: if ($curroption eq '') {
1933: $checked = ' checked="checked"';
1934: }
1935: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1936: '<input type="radio" name="crsreq_'.$item.
1937: '__LC_adv" value=""'.$checked.' />'.
1938: &mt('No override set').'</label></span> ';
1.101 raeburn 1939: foreach my $option (@options) {
1940: my $val = $option;
1941: if ($option eq 'norequest') {
1942: $val = 0;
1943: }
1944: if ($option eq 'validate') {
1945: my $canvalidate = 0;
1946: if (ref($validations{$item}) eq 'HASH') {
1947: if ($validations{$item}{'_LC_adv'}) {
1948: $canvalidate = 1;
1949: }
1950: }
1951: next if (!$canvalidate);
1952: }
1953: my $checked = '';
1.104 raeburn 1954: if ($val eq $curroption) {
1.101 raeburn 1955: $checked = ' checked="checked"';
1956: } elsif ($option eq 'autolimit') {
1957: if ($curroption =~ /^autolimit/) {
1958: $checked = ' checked="checked"';
1959: }
1960: }
1961: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1962: '<input type="radio" name="crsreq_'.$item.
1963: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1964: $titles{$option}.'</label>';
1965: if ($option eq 'autolimit') {
1.127 raeburn 1966: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1967: $item.'_limit__LC_adv" size="1" '.
1968: 'value="'.$currlimit.'" />';
1969: }
1.127 raeburn 1970: $advcell{$item} .= '</span> ';
1.104 raeburn 1971: if ($option eq 'autolimit') {
1.127 raeburn 1972: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1973: }
1.101 raeburn 1974: }
1.163 raeburn 1975: } elsif ($context eq 'requestauthor') {
1976: my $curroption;
1977: if (ref($settings) eq 'HASH') {
1978: $curroption = $settings->{'_LC_adv'};
1979: }
1980: my $checked = '';
1981: if ($curroption eq '') {
1982: $checked = ' checked="checked"';
1983: }
1984: $datatable .= '<span class="LC_nobreak"><label>'.
1985: '<input type="radio" name="authorreq__LC_adv"'.
1986: ' value=""'.$checked.' />'.
1987: &mt('No override set').'</label></span> ';
1988: foreach my $option (@options) {
1989: my $val = $option;
1990: if ($option eq 'norequest') {
1991: $val = 0;
1992: }
1993: my $checked = '';
1994: if ($val eq $curroption) {
1995: $checked = ' checked="checked"';
1996: }
1997: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1998: '<input type="radio" name="authorreq__LC_adv"'.
1999: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2000: $titles{$option}.'</label></span> ';
2001: }
1.101 raeburn 2002: } else {
2003: my $checked = 'checked="checked" ';
2004: if (ref($settings) eq 'HASH') {
2005: if (ref($settings->{$item}) eq 'HASH') {
2006: if ($settings->{$item}->{'_LC_adv'} == 0) {
2007: $checked = '';
2008: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2009: $checked = 'checked="checked" ';
2010: }
1.79 raeburn 2011: }
1.72 raeburn 2012: }
1.101 raeburn 2013: $datatable .= '<span class="LC_nobreak"><label>'.
2014: '<input type="checkbox" name="'.$context.'_'.$item.
2015: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2016: '</label></span> ';
2017: }
2018: }
2019: if ($context eq 'requestcourses') {
2020: $datatable .= '</tr><tr>';
2021: foreach my $item (@usertools) {
1.106 raeburn 2022: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2023: }
1.101 raeburn 2024: $datatable .= '</tr></table>';
1.72 raeburn 2025: }
1.98 raeburn 2026: $datatable .= '</td></tr>';
1.30 raeburn 2027: $$rowtotal += $typecount;
1.3 raeburn 2028: return $datatable;
2029: }
2030:
1.163 raeburn 2031: sub print_requestmail {
2032: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2033: my ($now,$datatable,%currapp);
1.102 raeburn 2034: $now = time;
2035: if (ref($settings) eq 'HASH') {
2036: if (ref($settings->{'notify'}) eq 'HASH') {
2037: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2038: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2039: }
2040: }
2041: }
1.191 raeburn 2042: my $numinrow = 2;
1.224 raeburn 2043: my $css_class;
2044: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2045: my $text;
2046: if ($action eq 'requestcourses') {
2047: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2048: } elsif ($action eq 'requestauthor') {
2049: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2050: } else {
1.224 raeburn 2051: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2052: }
1.224 raeburn 2053: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2054: ' <td>'.$text.'</td>'.
1.102 raeburn 2055: ' <td class="LC_left_item">';
1.191 raeburn 2056: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2057: $action.'notifyapproval',%currapp);
1.191 raeburn 2058: if ($numdc > 0) {
2059: $datatable .= $table;
1.102 raeburn 2060: } else {
2061: $datatable .= &mt('There are no active Domain Coordinators');
2062: }
2063: $datatable .='</td></tr>';
2064: $$rowtotal += $rows;
2065: return $datatable;
2066: }
2067:
1.216 raeburn 2068: sub print_studentcode {
2069: my ($settings,$rowtotal) = @_;
2070: my $rownum = 0;
1.218 raeburn 2071: my ($output,%current);
2072: my @crstypes = ('official','unofficial','community','textbook');
2073: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2074: foreach my $type (@crstypes) {
2075: $current{$type} = $settings->{'uniquecode'}{$type};
2076: }
2077: }
2078: $output .= '<tr>'.
2079: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2080: '<td class="LC_left_item">';
2081: foreach my $type (@crstypes) {
2082: my $check = ' ';
2083: if ($current{$type}) {
2084: $check = ' checked="checked" ';
2085: }
2086: $output .= '<span class="LC_nobreak"><label>'.
2087: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2088: &mt($type).'</label></span>'.(' 'x2).' ';
2089: }
2090: $output .= '</td></tr>';
2091: $$rowtotal ++;
2092: return $output;
1.216 raeburn 2093: }
2094:
2095: sub print_textbookcourses {
2096: my ($dom,$settings,$rowtotal) = @_;
2097: my $rownum = 0;
2098: my $css_class;
2099: my $itemcount = 1;
2100: my $maxnum = 0;
2101: my $bookshash;
2102: if (ref($settings) eq 'HASH') {
2103: $bookshash = $settings->{'textbooks'};
2104: }
2105: my %ordered;
2106: if (ref($bookshash) eq 'HASH') {
2107: foreach my $item (keys(%{$bookshash})) {
2108: if (ref($bookshash->{$item}) eq 'HASH') {
2109: my $num = $bookshash->{$item}{'order'};
2110: $ordered{$num} = $item;
2111: }
2112: }
2113: }
2114: my $confname = $dom.'-domainconfig';
2115: my $switchserver = &check_switchserver($dom,$confname);
1.236 raeburn 2116: $maxnum = scalar(keys(%ordered));
1.217 raeburn 2117: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2118: if (keys(%ordered)) {
2119: my @items = sort { $a <=> $b } keys(%ordered);
2120: for (my $i=0; $i<@items; $i++) {
2121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2122: my $key = $ordered{$items[$i]};
2123: my %coursehash=&Apache::lonnet::coursedescription($key);
2124: my $coursetitle = $coursehash{'description'};
2125: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2126: if (ref($bookshash->{$key}) eq 'HASH') {
2127: $subject = $bookshash->{$key}->{'subject'};
2128: $title = $bookshash->{$key}->{'title'};
2129: $author = $bookshash->{$key}->{'author'};
2130: $image = $bookshash->{$key}->{'image'};
2131: if ($image ne '') {
2132: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2133: my $imagethumb = "$path/tn-".$imagefile;
2134: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2135: }
2136: }
1.217 raeburn 2137: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2138: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2139: .'<select name="'.$key.'"'.$chgstr.'>';
2140: for (my $k=0; $k<=$maxnum; $k++) {
2141: my $vpos = $k+1;
2142: my $selstr;
2143: if ($k == $i) {
2144: $selstr = ' selected="selected" ';
2145: }
2146: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2147: }
2148: $datatable .= '</select>'.(' 'x2).
2149: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2150: &mt('Delete?').'</label></span></td>'.
2151: '<td colspan="2">'.
2152: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2153: (' 'x2).
2154: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2155: (' 'x2).
2156: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2157: (' 'x2).
2158: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2159: if ($image) {
2160: $datatable .= '<span class="LC_nobreak">'.
2161: $imgsrc.
2162: '<label><input type="checkbox" name="book_image_del"'.
2163: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2164: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2165: }
2166: if ($switchserver) {
2167: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2168: } else {
2169: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2170: }
2171: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2172: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2173: $coursetitle.'</span></td></tr>'."\n";
2174: $itemcount ++;
2175: }
2176: }
2177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2178: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2179: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2180: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2181: '<select name="addbook_pos"'.$chgstr.'>';
2182: for (my $k=0; $k<$maxnum+1; $k++) {
2183: my $vpos = $k+1;
2184: my $selstr;
2185: if ($k == $maxnum) {
2186: $selstr = ' selected="selected" ';
2187: }
2188: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2189: }
2190: $datatable .= '</select> '."\n".
2191: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2192: '<td colspan="2">'.
2193: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2194: (' 'x2).
2195: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2196: (' 'x2).
2197: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2198: (' 'x2).
2199: '<span class="LC_nobreak">'.&mt('Image:').' ';
2200: if ($switchserver) {
2201: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2202: } else {
2203: $datatable .= '<input type="file" name="addbook_image" value="" />';
2204: }
2205: $datatable .= '</span>'."\n".
2206: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2207: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2208: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2209: &Apache::loncommon::selectcourse_link
2210: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2211: '</span></td>'."\n".
2212: '</tr>'."\n";
2213: $itemcount ++;
2214: return $datatable;
2215: }
2216:
1.217 raeburn 2217: sub textbookcourses_javascript {
2218: my ($textbooks) = @_;
2219: return unless(ref($textbooks) eq 'HASH');
2220: my $num = scalar(keys(%{$textbooks}));
2221: my @jsarray;
2222: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2223: push(@jsarray,$textbooks->{$item});
2224: }
2225: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2226: return <<"ENDSCRIPT";
2227: <script type="text/javascript">
2228: // <![CDATA[
2229: function reorderBooks(form,item) {
2230: var changedVal;
2231: $jstext
2232: var newpos = 'addbook_pos';
2233: var current = new Array;
2234: var maxh = 1 + $num;
2235: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2236: if (item == newpos) {
2237: changedVal = newitemVal;
2238: } else {
2239: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2240: current[newitemVal] = newpos;
2241: }
2242: for (var i=0; i<textbooks.length; i++) {
2243: var elementName = textbooks[i];
2244: if (elementName != item) {
2245: if (form.elements[elementName]) {
2246: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2247: current[currVal] = elementName;
2248: }
2249: }
2250: }
2251: var oldVal;
2252: for (var j=0; j<maxh; j++) {
2253: if (current[j] == undefined) {
2254: oldVal = j;
2255: }
2256: }
2257: if (oldVal < changedVal) {
2258: for (var k=oldVal+1; k<=changedVal ; k++) {
2259: var elementName = current[k];
2260: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2261: }
2262: } else {
2263: for (var k=changedVal; k<oldVal; k++) {
2264: var elementName = current[k];
2265: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2266: }
2267: }
2268: return;
2269: }
2270:
2271: // ]]>
2272: </script>
2273:
2274: ENDSCRIPT
2275: }
2276:
1.3 raeburn 2277: sub print_autoenroll {
1.30 raeburn 2278: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2279: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2280: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2281: if (ref($settings) eq 'HASH') {
2282: if (exists($settings->{'run'})) {
2283: if ($settings->{'run'} eq '0') {
2284: $runoff = ' checked="checked" ';
2285: $runon = ' ';
2286: } else {
2287: $runon = ' checked="checked" ';
2288: $runoff = ' ';
2289: }
2290: } else {
2291: if ($autorun) {
2292: $runon = ' checked="checked" ';
2293: $runoff = ' ';
2294: } else {
2295: $runoff = ' checked="checked" ';
2296: $runon = ' ';
2297: }
2298: }
1.129 raeburn 2299: if (exists($settings->{'co-owners'})) {
2300: if ($settings->{'co-owners'} eq '0') {
2301: $coownersoff = ' checked="checked" ';
2302: $coownerson = ' ';
2303: } else {
2304: $coownerson = ' checked="checked" ';
2305: $coownersoff = ' ';
2306: }
2307: } else {
2308: $coownersoff = ' checked="checked" ';
2309: $coownerson = ' ';
2310: }
1.3 raeburn 2311: if (exists($settings->{'sender_domain'})) {
2312: $defdom = $settings->{'sender_domain'};
2313: }
1.14 raeburn 2314: } else {
2315: if ($autorun) {
2316: $runon = ' checked="checked" ';
2317: $runoff = ' ';
2318: } else {
2319: $runoff = ' checked="checked" ';
2320: $runon = ' ';
2321: }
1.3 raeburn 2322: }
2323: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2324: my $notif_sender;
2325: if (ref($settings) eq 'HASH') {
2326: $notif_sender = $settings->{'sender_uname'};
2327: }
1.3 raeburn 2328: my $datatable='<tr class="LC_odd_row">'.
2329: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2330: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2331: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2332: $runon.' value="1" />'.&mt('Yes').'</label> '.
2333: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2334: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2335: '</tr><tr>'.
2336: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2337: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2338: &mt('username').': '.
2339: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2340: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2341: ': '.$domform.'</span></td></tr>'.
2342: '<tr class="LC_odd_row">'.
2343: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2344: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2345: '<input type="radio" name="autoassign_coowners"'.
2346: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2347: '<label><input type="radio" name="autoassign_coowners"'.
2348: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2349: '</tr>';
2350: $$rowtotal += 3;
1.3 raeburn 2351: return $datatable;
2352: }
2353:
2354: sub print_autoupdate {
1.30 raeburn 2355: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2356: my $datatable;
2357: if ($position eq 'top') {
2358: my $updateon = ' ';
2359: my $updateoff = ' checked="checked" ';
2360: my $classlistson = ' ';
2361: my $classlistsoff = ' checked="checked" ';
2362: if (ref($settings) eq 'HASH') {
2363: if ($settings->{'run'} eq '1') {
2364: $updateon = $updateoff;
2365: $updateoff = ' ';
2366: }
2367: if ($settings->{'classlists'} eq '1') {
2368: $classlistson = $classlistsoff;
2369: $classlistsoff = ' ';
2370: }
2371: }
2372: my %title = (
2373: run => 'Auto-update active?',
2374: classlists => 'Update information in classlists?',
2375: );
2376: $datatable = '<tr class="LC_odd_row">'.
2377: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2378: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2379: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2380: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2381: '<label><input type="radio" name="autoupdate_run"'.
2382: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2383: '</tr><tr>'.
2384: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2385: '<td class="LC_right_item"><span class="LC_nobreak">'.
2386: '<label><input type="radio" name="classlists"'.
2387: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2388: '<label><input type="radio" name="classlists"'.
2389: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2390: '</tr>';
1.30 raeburn 2391: $$rowtotal += 2;
1.131 raeburn 2392: } elsif ($position eq 'middle') {
2393: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2394: my $numinrow = 3;
2395: my $locknamesettings;
2396: $datatable .= &insttypes_row($settings,$types,$usertypes,
2397: $dom,$numinrow,$othertitle,
2398: 'lockablenames');
2399: $$rowtotal ++;
1.3 raeburn 2400: } else {
1.44 raeburn 2401: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2402: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2403: 'permanentemail','id');
1.33 raeburn 2404: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2405: my $numrows = 0;
1.26 raeburn 2406: if (ref($types) eq 'ARRAY') {
2407: if (@{$types} > 0) {
2408: $datatable =
2409: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2410: \@fields,$types,\$numrows);
1.30 raeburn 2411: $$rowtotal += @{$types};
1.26 raeburn 2412: }
1.3 raeburn 2413: }
2414: $datatable .=
2415: &usertype_update_row($settings,{'default' => $othertitle},
2416: \%fieldtitles,\@fields,['default'],
2417: \$numrows);
1.30 raeburn 2418: $$rowtotal ++;
1.3 raeburn 2419: }
2420: return $datatable;
2421: }
2422:
1.125 raeburn 2423: sub print_autocreate {
2424: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2425: my (%createon,%createoff,%currhash);
1.125 raeburn 2426: my @types = ('xml','req');
2427: if (ref($settings) eq 'HASH') {
2428: foreach my $item (@types) {
2429: $createoff{$item} = ' checked="checked" ';
2430: $createon{$item} = ' ';
2431: if (exists($settings->{$item})) {
2432: if ($settings->{$item}) {
2433: $createon{$item} = ' checked="checked" ';
2434: $createoff{$item} = ' ';
2435: }
2436: }
2437: }
1.210 raeburn 2438: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2439: $currhash{$settings->{'xmldc'}} = 1;
2440: }
1.125 raeburn 2441: } else {
2442: foreach my $item (@types) {
2443: $createoff{$item} = ' checked="checked" ';
2444: $createon{$item} = ' ';
2445: }
2446: }
2447: $$rowtotal += 2;
1.191 raeburn 2448: my $numinrow = 2;
1.125 raeburn 2449: my $datatable='<tr class="LC_odd_row">'.
2450: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2451: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2452: '<input type="radio" name="autocreate_xml"'.
2453: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2454: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2455: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2456: '</td></tr><tr>'.
2457: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2458: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2459: '<input type="radio" name="autocreate_req"'.
2460: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2461: '<label><input type="radio" name="autocreate_req"'.
2462: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2463: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2464: 'autocreate_xmldc',%currhash);
1.125 raeburn 2465: if ($numdc > 1) {
1.143 raeburn 2466: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2467: &mt('Course creation processed as: (choose Dom. Coord.)').
2468: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2469: } else {
1.143 raeburn 2470: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2471: }
1.191 raeburn 2472: $$rowtotal += $rows;
1.125 raeburn 2473: return $datatable;
2474: }
2475:
1.23 raeburn 2476: sub print_directorysrch {
1.30 raeburn 2477: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2478: my $srchon = ' ';
2479: my $srchoff = ' checked="checked" ';
1.25 raeburn 2480: my ($exacton,$containson,$beginson);
1.24 raeburn 2481: my $localon = ' ';
2482: my $localoff = ' checked="checked" ';
1.23 raeburn 2483: if (ref($settings) eq 'HASH') {
2484: if ($settings->{'available'} eq '1') {
2485: $srchon = $srchoff;
2486: $srchoff = ' ';
2487: }
1.24 raeburn 2488: if ($settings->{'localonly'} eq '1') {
2489: $localon = $localoff;
2490: $localoff = ' ';
2491: }
1.25 raeburn 2492: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2493: foreach my $type (@{$settings->{'searchtypes'}}) {
2494: if ($type eq 'exact') {
2495: $exacton = ' checked="checked" ';
2496: } elsif ($type eq 'contains') {
2497: $containson = ' checked="checked" ';
2498: } elsif ($type eq 'begins') {
2499: $beginson = ' checked="checked" ';
2500: }
2501: }
2502: } else {
2503: if ($settings->{'searchtypes'} eq 'exact') {
2504: $exacton = ' checked="checked" ';
2505: } elsif ($settings->{'searchtypes'} eq 'contains') {
2506: $containson = ' checked="checked" ';
2507: } elsif ($settings->{'searchtypes'} eq 'specify') {
2508: $exacton = ' checked="checked" ';
2509: $containson = ' checked="checked" ';
2510: }
1.23 raeburn 2511: }
2512: }
2513: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2514: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2515:
2516: my $numinrow = 4;
1.26 raeburn 2517: my $cansrchrow = 0;
1.23 raeburn 2518: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2519: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2520: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2521: '<input type="radio" name="dirsrch_available"'.
2522: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2523: '<label><input type="radio" name="dirsrch_available"'.
2524: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2525: '</tr><tr>'.
1.30 raeburn 2526: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2527: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2528: '<input type="radio" name="dirsrch_localonly"'.
2529: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2530: '<label><input type="radio" name="dirsrch_localonly"'.
2531: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2532: '</tr>';
1.30 raeburn 2533: $$rowtotal += 2;
1.26 raeburn 2534: if (ref($usertypes) eq 'HASH') {
2535: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2536: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2537: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2538: $cansrchrow = 1;
2539: }
2540: }
2541: if ($cansrchrow) {
1.30 raeburn 2542: $$rowtotal ++;
1.26 raeburn 2543: $datatable .= '<tr>';
2544: } else {
2545: $datatable .= '<tr class="LC_odd_row">';
2546: }
1.30 raeburn 2547: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2548: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2549: foreach my $title (@{$titleorder}) {
2550: if (defined($searchtitles->{$title})) {
2551: my $check = ' ';
1.93 raeburn 2552: if (ref($settings) eq 'HASH') {
1.39 raeburn 2553: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2554: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2555: $check = ' checked="checked" ';
2556: }
1.25 raeburn 2557: }
2558: }
2559: $datatable .= '<td class="LC_left_item">'.
2560: '<span class="LC_nobreak"><label>'.
2561: '<input type="checkbox" name="searchby" '.
2562: 'value="'.$title.'"'.$check.'/>'.
2563: $searchtitles->{$title}.'</label></span></td>';
2564: }
2565: }
1.26 raeburn 2566: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2567: $$rowtotal ++;
1.26 raeburn 2568: if ($cansrchrow) {
2569: $datatable .= '<tr class="LC_odd_row">';
2570: } else {
2571: $datatable .= '<tr>';
2572: }
1.30 raeburn 2573: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2574: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2575: '<span class="LC_nobreak"><label>'.
2576: '<input type="checkbox" name="searchtypes" '.
2577: $exacton.' value="exact" />'.&mt('Exact match').
2578: '</label> '.
2579: '<label><input type="checkbox" name="searchtypes" '.
2580: $beginson.' value="begins" />'.&mt('Begins with').
2581: '</label> '.
2582: '<label><input type="checkbox" name="searchtypes" '.
2583: $containson.' value="contains" />'.&mt('Contains').
2584: '</label></span></td></tr>';
1.30 raeburn 2585: $$rowtotal ++;
1.25 raeburn 2586: return $datatable;
2587: }
2588:
1.28 raeburn 2589: sub print_contacts {
1.30 raeburn 2590: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2591: my $datatable;
2592: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2593: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2594: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2595: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2596: foreach my $type (@mailings) {
2597: $otheremails{$type} = '';
2598: }
1.134 raeburn 2599: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2600: if (ref($settings) eq 'HASH') {
2601: foreach my $item (@contacts) {
2602: if (exists($settings->{$item})) {
2603: $to{$item} = $settings->{$item};
2604: }
2605: }
2606: foreach my $type (@mailings) {
2607: if (exists($settings->{$type})) {
2608: if (ref($settings->{$type}) eq 'HASH') {
2609: foreach my $item (@contacts) {
2610: if ($settings->{$type}{$item}) {
2611: $checked{$type}{$item} = ' checked="checked" ';
2612: }
2613: }
2614: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2615: if ($type eq 'helpdeskmail') {
2616: $bccemails{$type} = $settings->{$type}{'bcc'};
2617: }
1.28 raeburn 2618: }
1.89 raeburn 2619: } elsif ($type eq 'lonstatusmail') {
2620: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2621: }
2622: }
2623: } else {
2624: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2625: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2626: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2627: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2628: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2629: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2630: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2631: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2632: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2633: }
2634: my ($titles,$short_titles) = &contact_titles();
2635: my $rownum = 0;
2636: my $css_class;
2637: foreach my $item (@contacts) {
1.69 raeburn 2638: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2639: $datatable .= '<tr'.$css_class.'>'.
2640: '<td><span class="LC_nobreak">'.$titles->{$item}.
2641: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2642: '<input type="text" name="'.$item.'" value="'.
2643: $to{$item}.'" /></td></tr>';
1.203 raeburn 2644: $rownum ++;
1.28 raeburn 2645: }
2646: foreach my $type (@mailings) {
1.69 raeburn 2647: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2648: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2649: '<td><span class="LC_nobreak">'.
2650: $titles->{$type}.': </span></td>'.
1.28 raeburn 2651: '<td class="LC_left_item">'.
2652: '<span class="LC_nobreak">';
2653: foreach my $item (@contacts) {
2654: $datatable .= '<label>'.
2655: '<input type="checkbox" name="'.$type.'"'.
2656: $checked{$type}{$item}.
2657: ' value="'.$item.'" />'.$short_titles->{$item}.
2658: '</label> ';
2659: }
2660: $datatable .= '</span><br />'.&mt('Others').': '.
2661: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2662: 'value="'.$otheremails{$type}.'" />';
2663: if ($type eq 'helpdeskmail') {
1.136 raeburn 2664: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2665: '<input type="text" name="'.$type.'_bcc" '.
2666: 'value="'.$bccemails{$type}.'" />';
2667: }
2668: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2669: $rownum ++;
1.28 raeburn 2670: }
1.203 raeburn 2671: my %choices;
2672: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2673: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2674: &mt('LON-CAPA core group - MSU'),600,500));
2675: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2676: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2677: &mt('LON-CAPA core group - MSU'),600,500));
2678: my @toggles = ('reporterrors','reportupdates');
2679: my %defaultchecked = ('reporterrors' => 'on',
2680: 'reportupdates' => 'on');
2681: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2682: \%choices,$rownum);
2683: $datatable .= $reports;
1.30 raeburn 2684: $$rowtotal += $rownum;
1.28 raeburn 2685: return $datatable;
2686: }
2687:
1.118 jms 2688: sub print_helpsettings {
1.168 raeburn 2689: my ($dom,$confname,$settings,$rowtotal) = @_;
2690: my ($datatable,$itemcount);
1.166 raeburn 2691: $itemcount = 1;
1.168 raeburn 2692: my (%choices,%defaultchecked,@toggles);
2693: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2694: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2695: &mt('LON-CAPA bug tracker'),600,500));
2696: %defaultchecked = ('submitbugs' => 'on');
2697: @toggles = ('submitbugs',);
1.166 raeburn 2698:
1.168 raeburn 2699: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2700: \%choices,$itemcount);
1.166 raeburn 2701: return $datatable;
1.121 raeburn 2702: }
2703:
2704: sub radiobutton_prefs {
1.192 raeburn 2705: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2706: $additional) = @_;
1.121 raeburn 2707: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2708: (ref($choices) eq 'HASH'));
2709:
1.170 raeburn 2710: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2711:
2712: foreach my $item (@{$toggles}) {
2713: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2714: $checkedon{$item} = ' checked="checked" ';
2715: $checkedoff{$item} = ' ';
1.121 raeburn 2716: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2717: $checkedoff{$item} = ' checked="checked" ';
2718: $checkedon{$item} = ' ';
2719: }
2720: }
2721: if (ref($settings) eq 'HASH') {
1.121 raeburn 2722: foreach my $item (@{$toggles}) {
1.118 jms 2723: if ($settings->{$item} eq '1') {
2724: $checkedon{$item} = ' checked="checked" ';
2725: $checkedoff{$item} = ' ';
2726: } elsif ($settings->{$item} eq '0') {
2727: $checkedoff{$item} = ' checked="checked" ';
2728: $checkedon{$item} = ' ';
2729: }
2730: }
1.121 raeburn 2731: }
1.192 raeburn 2732: if ($onclick) {
2733: $onclick = ' onclick="'.$onclick.'"';
2734: }
1.121 raeburn 2735: foreach my $item (@{$toggles}) {
1.118 jms 2736: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2737: $datatable .=
1.192 raeburn 2738: '<tr'.$css_class.'><td valign="top">'.
2739: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2740: '</span></td>'.
2741: '<td class="LC_right_item"><span class="LC_nobreak">'.
2742: '<label><input type="radio" name="'.
1.192 raeburn 2743: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2744: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2745: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2746: '</span>'.$additional.
2747: '</td>'.
1.118 jms 2748: '</tr>';
2749: $itemcount ++;
1.121 raeburn 2750: }
2751: return ($datatable,$itemcount);
2752: }
2753:
2754: sub print_coursedefaults {
1.139 raeburn 2755: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2756: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2757: my $itemcount = 1;
1.192 raeburn 2758: my %choices = &Apache::lonlocal::texthash (
2759: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2760: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2761: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2762: coursecredits => 'Credits can be specified for courses',
2763: );
1.198 raeburn 2764: my %staticdefaults = (
2765: anonsurvey_threshold => 10,
2766: uploadquota => 500,
2767: );
1.139 raeburn 2768: if ($position eq 'top') {
2769: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2770: @toggles = ('canuse_pdfforms');
1.139 raeburn 2771: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2772: \%choices,$itemcount);
1.139 raeburn 2773: } else {
2774: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2775: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2776: %curruploadquota);
1.192 raeburn 2777: my $currusecredits = 0;
1.216 raeburn 2778: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2779: if (ref($settings) eq 'HASH') {
2780: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2781: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2782: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2783: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2784: }
2785: }
1.192 raeburn 2786: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2787: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2788: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2789: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2790: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2791: ($def_textbook_credits ne '')) {
1.192 raeburn 2792: $currusecredits = 1;
2793: }
2794: }
1.139 raeburn 2795: }
2796: if (!$currdefresponder) {
1.198 raeburn 2797: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2798: } elsif ($currdefresponder < 1) {
2799: $currdefresponder = 1;
2800: }
1.198 raeburn 2801: foreach my $type (@types) {
2802: if ($curruploadquota{$type} eq '') {
2803: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2804: }
2805: }
1.139 raeburn 2806: $datatable .=
1.192 raeburn 2807: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2808: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2809: '</span></td>'.
2810: '<td class="LC_right_item"><span class="LC_nobreak">'.
2811: '<input type="text" name="anonsurvey_threshold"'.
2812: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2813: '</td></tr>'."\n";
2814: $itemcount ++;
2815: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2816: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2817: $choices{'uploadquota'}.
2818: '</span></td>'.
2819: '<td align="right" class="LC_right_item">'.
2820: '<table><tr>';
1.198 raeburn 2821: foreach my $type (@types) {
2822: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2823: '<input type="text" name="uploadquota_'.$type.'"'.
2824: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2825: }
2826: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2827: $itemcount ++;
1.236 raeburn 2828: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 2829: my $display = 'none';
1.192 raeburn 2830: if ($currusecredits) {
2831: $display = 'block';
2832: }
2833: my $additional = '<div id="credits" style="display: '.$display.'">'.
2834: '<span class="LC_nobreak">'.
2835: &mt('Default credits for official courses [_1]',
2836: '<input type="text" name="official_credits" value="'.
2837: $def_official_credits.'" size="3" />').
2838: '</span><br />'.
2839: '<span class="LC_nobreak">'.
2840: &mt('Default credits for unofficial courses [_1]',
2841: '<input type="text" name="unofficial_credits" value="'.
2842: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2843: '</span><br />'.
2844: '<span class="LC_nobreak">'.
2845: &mt('Default credits for textbook courses [_1]',
2846: '<input type="text" name="textbook_credits" value="'.
2847: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2848: '</span></div>'."\n";
2849: %defaultchecked = ('coursecredits' => 'off');
2850: @toggles = ('coursecredits');
2851: my $current = {
2852: 'coursecredits' => $currusecredits,
2853: };
2854: (my $table,$itemcount) =
2855: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2856: \%choices,$itemcount,$onclick,$additional);
2857: $datatable .= $table;
1.230 raeburn 2858: $itemcount ++;
1.139 raeburn 2859: }
1.192 raeburn 2860: $$rowtotal += $itemcount;
1.121 raeburn 2861: return $datatable;
1.118 jms 2862: }
2863:
1.231 raeburn 2864: sub print_selfenrollment {
2865: my ($position,$dom,$settings,$rowtotal) = @_;
2866: my ($css_class,$datatable);
2867: my $itemcount = 1;
2868: my @types = ('official','unofficial','community','textbook');
2869: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 2870: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2871: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 2872: my @rows;
2873: my $key;
2874: if ($position eq 'top') {
2875: $key = 'admin';
2876: if (ref($rowsref) eq 'ARRAY') {
2877: @rows = @{$rowsref};
2878: }
2879: } elsif ($position eq 'middle') {
2880: $key = 'default';
2881: @rows = ('types','registered','approval','limit');
2882: }
2883: foreach my $row (@rows) {
2884: if (defined($titlesref->{$row})) {
2885: $itemcount ++;
2886: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2887: $datatable .= '<tr'.$css_class.'>'.
2888: '<td>'.$titlesref->{$row}.'</td>'.
2889: '<td class="LC_left_item">'.
2890: '<table><tr>';
2891: my (%current,%currentcap);
2892: if (ref($settings) eq 'HASH') {
2893: if (ref($settings->{$key}) eq 'HASH') {
2894: foreach my $type (@types) {
2895: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2896: $current{$type} = $settings->{$key}->{$type}->{$row};
2897: }
2898: if (($row eq 'limit') && ($key eq 'default')) {
2899: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2900: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2901: }
2902: }
2903: }
2904: }
2905: }
2906: my %roles = (
2907: '0' => &Apache::lonnet::plaintext('dc'),
2908: );
2909:
2910: foreach my $type (@types) {
2911: unless (($row eq 'registered') && ($key eq 'default')) {
2912: $datatable .= '<th>'.&mt($type).'</th>';
2913: }
2914: }
2915: unless (($row eq 'registered') && ($key eq 'default')) {
2916: $datatable .= '</tr><tr>';
2917: }
2918: foreach my $type (@types) {
2919: if ($type eq 'community') {
2920: $roles{'1'} = &mt('Community personnel');
2921: } else {
2922: $roles{'1'} = &mt('Course personnel');
2923: }
2924: $datatable .= '<td style="vertical-align: top">';
2925: if ($position eq 'top') {
2926: my %checked;
2927: if ($current{$type} eq '0') {
2928: $checked{'0'} = ' checked="checked"';
2929: } else {
2930: $checked{'1'} = ' checked="checked"';
2931: }
2932: foreach my $role ('1','0') {
2933: $datatable .= '<span class="LC_nobreak"><label>'.
2934: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2935: 'value="'.$role.'"'.$checked{$role}.' />'.
2936: $roles{$role}.'</label></span> ';
2937: }
2938: } else {
2939: if ($row eq 'types') {
2940: my %checked;
2941: if ($current{$type} =~ /^(all|dom)$/) {
2942: $checked{$1} = ' checked="checked"';
2943: } else {
2944: $checked{''} = ' checked="checked"';
2945: }
2946: foreach my $val ('','dom','all') {
2947: $datatable .= '<span class="LC_nobreak"><label>'.
2948: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2949: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2950: }
2951: } elsif ($row eq 'registered') {
2952: my %checked;
2953: if ($current{$type} eq '1') {
2954: $checked{'1'} = ' checked="checked"';
2955: } else {
2956: $checked{'0'} = ' checked="checked"';
2957: }
2958: foreach my $val ('0','1') {
2959: $datatable .= '<span class="LC_nobreak"><label>'.
2960: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2961: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2962: }
2963: } elsif ($row eq 'approval') {
2964: my %checked;
2965: if ($current{$type} =~ /^([12])$/) {
2966: $checked{$1} = ' checked="checked"';
2967: } else {
2968: $checked{'0'} = ' checked="checked"';
2969: }
2970: for my $val (0..2) {
2971: $datatable .= '<span class="LC_nobreak"><label>'.
2972: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2973: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2974: }
2975: } elsif ($row eq 'limit') {
2976: my %checked;
2977: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
2978: $checked{$1} = ' checked="checked"';
2979: } else {
2980: $checked{'none'} = ' checked="checked"';
2981: }
2982: my $cap;
2983: if ($currentcap{$type} =~ /^\d+$/) {
2984: $cap = $currentcap{$type};
2985: }
2986: foreach my $val ('none','allstudents','selfenrolled') {
2987: $datatable .= '<span class="LC_nobreak"><label>'.
2988: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2989: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2990: }
2991: $datatable .= '<br />'.
2992: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
2993: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
2994: '</span>';
2995: }
2996: }
2997: $datatable .= '</td>';
2998: }
2999: $datatable .= '</tr>';
3000: }
3001: $datatable .= '</table></td></tr>';
3002: }
3003: } elsif ($position eq 'bottom') {
1.235 raeburn 3004: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3005: }
3006: $$rowtotal += $itemcount;
3007: return $datatable;
3008: }
3009:
3010: sub print_validation_rows {
3011: my ($caller,$dom,$settings,$rowtotal) = @_;
3012: my ($itemsref,$namesref,$fieldsref);
3013: if ($caller eq 'selfenroll') {
3014: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3015: } elsif ($caller eq 'requestcourses') {
3016: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3017: }
3018: my %currvalidation;
3019: if (ref($settings) eq 'HASH') {
3020: if (ref($settings->{'validation'}) eq 'HASH') {
3021: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3022: }
1.235 raeburn 3023: }
3024: my $datatable;
3025: my $itemcount = 0;
3026: foreach my $item (@{$itemsref}) {
3027: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3028: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3029: $namesref->{$item}.
3030: '</span></td>'.
3031: '<td class="LC_left_item">';
3032: if (($item eq 'url') || ($item eq 'button')) {
3033: $datatable .= '<span class="LC_nobreak">'.
3034: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3035: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3036: } elsif ($item eq 'fields') {
3037: my @currfields;
3038: if (ref($currvalidation{$item}) eq 'ARRAY') {
3039: @currfields = @{$currvalidation{$item}};
3040: }
3041: foreach my $field (@{$fieldsref}) {
3042: my $check = '';
3043: if (grep(/^\Q$field\E$/,@currfields)) {
3044: $check = ' checked="checked"';
3045: }
3046: $datatable .= '<span class="LC_nobreak"><label>'.
3047: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3048: ' value="'.$field.'"'.$check.' />'.$field.
3049: '</label></span> ';
3050: }
3051: } elsif ($item eq 'markup') {
3052: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3053: $currvalidation{$item}.
1.231 raeburn 3054: '</textarea>';
1.235 raeburn 3055: }
3056: $datatable .= '</td></tr>'."\n";
3057: if (ref($rowtotal)) {
1.231 raeburn 3058: $itemcount ++;
3059: }
3060: }
1.235 raeburn 3061: if ($caller eq 'requestcourses') {
3062: my %currhash;
3063: if (ref($settings->{'validation'}) eq 'HASH') {
3064: if ($settings->{'validation'}{'dc'} ne '') {
3065: $currhash{$settings->{'validation'}{'dc'}} = 1;
3066: }
3067: }
3068: my $numinrow = 2;
3069: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3070: 'validationdc',%currhash);
3071: if ($numdc > 1) {
3072: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3073: &mt('Course creation processed as: (choose Dom. Coord.)').
3074: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3075: } else {
3076: $datatable .= $dctable.'</td></tr>';
3077: }
3078: $itemcount ++;
3079: }
3080: if (ref($rowtotal)) {
3081: $$rowtotal += $itemcount;
3082: }
1.231 raeburn 3083: return $datatable;
3084: }
3085:
1.137 raeburn 3086: sub print_usersessions {
3087: my ($position,$dom,$settings,$rowtotal) = @_;
3088: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3089: my (%by_ip,%by_location,@intdoms);
3090: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3091:
3092: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3093: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3094: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3095: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3096: my $itemcount = 1;
3097: if ($position eq 'top') {
1.152 raeburn 3098: if (keys(%serverhomes) > 1) {
1.145 raeburn 3099: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3100: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3101: } else {
1.140 raeburn 3102: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3103: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3104: }
1.137 raeburn 3105: } else {
1.145 raeburn 3106: if (keys(%by_location) == 0) {
3107: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3108: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3109: } else {
3110: my %lt = &usersession_titles();
3111: my $numinrow = 5;
3112: my $prefix;
3113: my @types;
3114: if ($position eq 'bottom') {
3115: $prefix = 'remote';
3116: @types = ('version','excludedomain','includedomain');
3117: } else {
3118: $prefix = 'hosted';
3119: @types = ('excludedomain','includedomain');
3120: }
3121: my (%current,%checkedon,%checkedoff);
3122: my @lcversions = &Apache::lonnet::all_loncaparevs();
3123: my @locations = sort(keys(%by_location));
3124: foreach my $type (@types) {
3125: $checkedon{$type} = '';
3126: $checkedoff{$type} = ' checked="checked"';
3127: }
3128: if (ref($settings) eq 'HASH') {
3129: if (ref($settings->{$prefix}) eq 'HASH') {
3130: foreach my $key (keys(%{$settings->{$prefix}})) {
3131: $current{$key} = $settings->{$prefix}{$key};
3132: if ($key eq 'version') {
3133: if ($current{$key} ne '') {
3134: $checkedon{$key} = ' checked="checked"';
3135: $checkedoff{$key} = '';
3136: }
3137: } elsif (ref($current{$key}) eq 'ARRAY') {
3138: $checkedon{$key} = ' checked="checked"';
3139: $checkedoff{$key} = '';
3140: }
1.137 raeburn 3141: }
3142: }
3143: }
1.145 raeburn 3144: foreach my $type (@types) {
3145: next if ($type ne 'version' && !@locations);
3146: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3147: $datatable .= '<tr'.$css_class.'>
3148: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3149: <span class="LC_nobreak">
3150: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3151: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3152: if ($type eq 'version') {
3153: my $selector = '<select name="'.$prefix.'_version">';
3154: foreach my $version (@lcversions) {
3155: my $selected = '';
3156: if ($current{'version'} eq $version) {
3157: $selected = ' selected="selected"';
3158: }
3159: $selector .= ' <option value="'.$version.'"'.
3160: $selected.'>'.$version.'</option>';
3161: }
3162: $selector .= '</select> ';
3163: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3164: } else {
3165: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3166: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3167: ' />'.(' 'x2).
3168: '<input type="button" value="'.&mt('uncheck all').'" '.
3169: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3170: "\n".
3171: '</div><div><table>';
3172: my $rem;
3173: for (my $i=0; $i<@locations; $i++) {
3174: my ($showloc,$value,$checkedtype);
3175: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3176: my $ip = $by_location{$locations[$i]}->[0];
3177: if (ref($by_ip{$ip}) eq 'ARRAY') {
3178: $value = join(':',@{$by_ip{$ip}});
3179: $showloc = join(', ',@{$by_ip{$ip}});
3180: if (ref($current{$type}) eq 'ARRAY') {
3181: foreach my $loc (@{$by_ip{$ip}}) {
3182: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3183: $checkedtype = ' checked="checked"';
3184: last;
3185: }
3186: }
1.138 raeburn 3187: }
3188: }
3189: }
1.145 raeburn 3190: $rem = $i%($numinrow);
3191: if ($rem == 0) {
3192: if ($i > 0) {
3193: $datatable .= '</tr>';
3194: }
3195: $datatable .= '<tr>';
3196: }
3197: $datatable .= '<td class="LC_left_item">'.
3198: '<span class="LC_nobreak"><label>'.
3199: '<input type="checkbox" name="'.$prefix.'_'.$type.
3200: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3201: '</label></span></td>';
1.137 raeburn 3202: }
1.145 raeburn 3203: $rem = @locations%($numinrow);
3204: my $colsleft = $numinrow - $rem;
3205: if ($colsleft > 1 ) {
3206: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3207: ' </td>';
3208: } elsif ($colsleft == 1) {
3209: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3210: }
1.145 raeburn 3211: $datatable .= '</tr></table>';
1.137 raeburn 3212: }
1.145 raeburn 3213: $datatable .= '</td></tr>';
3214: $itemcount ++;
1.137 raeburn 3215: }
3216: }
3217: }
3218: $$rowtotal += $itemcount;
3219: return $datatable;
3220: }
3221:
1.138 raeburn 3222: sub build_location_hashes {
3223: my ($intdoms,$by_ip,$by_location) = @_;
3224: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3225: (ref($by_location) eq 'HASH'));
3226: my %iphost = &Apache::lonnet::get_iphost();
3227: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3228: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3229: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3230: foreach my $id (@{$iphost{$primary_ip}}) {
3231: my $intdom = &Apache::lonnet::internet_dom($id);
3232: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3233: push(@{$intdoms},$intdom);
3234: }
3235: }
3236: }
3237: foreach my $ip (keys(%iphost)) {
3238: if (ref($iphost{$ip}) eq 'ARRAY') {
3239: foreach my $id (@{$iphost{$ip}}) {
3240: my $location = &Apache::lonnet::internet_dom($id);
3241: if ($location) {
3242: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3243: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3244: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3245: push(@{$by_ip->{$ip}},$location);
3246: }
3247: } else {
3248: $by_ip->{$ip} = [$location];
3249: }
3250: }
3251: }
3252: }
3253: }
3254: foreach my $ip (sort(keys(%{$by_ip}))) {
3255: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3256: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3257: my $first = $by_ip->{$ip}->[0];
3258: if (ref($by_location->{$first}) eq 'ARRAY') {
3259: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3260: push(@{$by_location->{$first}},$ip);
3261: }
3262: } else {
3263: $by_location->{$first} = [$ip];
3264: }
3265: }
3266: }
3267: return;
3268: }
3269:
1.145 raeburn 3270: sub current_offloads_to {
3271: my ($dom,$settings,$servers) = @_;
3272: my (%spareid,%otherdomconfigs);
1.152 raeburn 3273: if (ref($servers) eq 'HASH') {
1.145 raeburn 3274: foreach my $lonhost (sort(keys(%{$servers}))) {
3275: my $gotspares;
1.152 raeburn 3276: if (ref($settings) eq 'HASH') {
3277: if (ref($settings->{'spares'}) eq 'HASH') {
3278: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3279: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3280: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3281: $gotspares = 1;
3282: }
1.145 raeburn 3283: }
3284: }
3285: unless ($gotspares) {
3286: my $gotspares;
3287: my $serverhomeID =
3288: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3289: my $serverhomedom =
3290: &Apache::lonnet::host_domain($serverhomeID);
3291: if ($serverhomedom ne $dom) {
3292: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3293: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3294: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3295: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3296: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3297: $gotspares = 1;
3298: }
3299: }
3300: } else {
3301: $otherdomconfigs{$serverhomedom} =
3302: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3303: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3304: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3305: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3306: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3307: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3308: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3309: $gotspares = 1;
3310: }
3311: }
3312: }
3313: }
3314: }
3315: }
3316: }
3317: unless ($gotspares) {
3318: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3319: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3320: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3321: } else {
3322: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3323: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3324: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3325: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3326: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3327: } else {
1.150 raeburn 3328: my %what = (
3329: spareid => 1,
3330: );
3331: my ($result,$returnhash) =
3332: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3333: if ($result eq 'ok') {
3334: if (ref($returnhash) eq 'HASH') {
3335: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3336: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3337: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3338: }
3339: }
1.145 raeburn 3340: }
3341: }
3342: }
3343: }
3344: }
3345: }
3346: return %spareid;
3347: }
3348:
3349: sub spares_row {
1.152 raeburn 3350: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3351: my $css_class;
3352: my $numinrow = 4;
3353: my $itemcount = 1;
3354: my $datatable;
1.152 raeburn 3355: my %typetitles = &sparestype_titles();
3356: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3357: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3358: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3359: my ($othercontrol,$serverdom);
3360: if ($serverhome ne $server) {
3361: $serverdom = &Apache::lonnet::host_domain($serverhome);
3362: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3363: } else {
3364: $serverdom = &Apache::lonnet::host_domain($server);
3365: if ($serverdom ne $dom) {
3366: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3367: }
3368: }
3369: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3370: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3371: $datatable .= '<tr'.$css_class.'>
3372: <td rowspan="2">
1.183 bisitz 3373: <span class="LC_nobreak">'.
3374: &mt('[_1] when busy, offloads to:'
3375: ,'<b>'.$server.'</b>').
3376: "\n";
1.145 raeburn 3377: my (%current,%canselect);
1.152 raeburn 3378: my @choices =
3379: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3380: foreach my $type ('primary','default') {
3381: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3382: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3383: my @spares = @{$spareid->{$server}{$type}};
3384: if (@spares > 0) {
1.152 raeburn 3385: if ($othercontrol) {
3386: $current{$type} = join(', ',@spares);
3387: } else {
3388: $current{$type} .= '<table>';
3389: my $numspares = scalar(@spares);
3390: for (my $i=0; $i<@spares; $i++) {
3391: my $rem = $i%($numinrow);
3392: if ($rem == 0) {
3393: if ($i > 0) {
3394: $current{$type} .= '</tr>';
3395: }
3396: $current{$type} .= '<tr>';
1.145 raeburn 3397: }
1.152 raeburn 3398: $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'".');" /> '.
3399: $spareid->{$server}{$type}[$i].
3400: '</label></td>'."\n";
3401: }
3402: my $rem = @spares%($numinrow);
3403: my $colsleft = $numinrow - $rem;
3404: if ($colsleft > 1 ) {
3405: $current{$type} .= '<td colspan="'.$colsleft.
3406: '" class="LC_left_item">'.
3407: ' </td>';
3408: } elsif ($colsleft == 1) {
3409: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3410: }
1.152 raeburn 3411: $current{$type} .= '</tr></table>';
1.150 raeburn 3412: }
1.145 raeburn 3413: }
3414: }
3415: if ($current{$type} eq '') {
3416: $current{$type} = &mt('None specified');
3417: }
1.152 raeburn 3418: if ($othercontrol) {
3419: if ($type eq 'primary') {
3420: $canselect{$type} = $othercontrol;
3421: }
3422: } else {
3423: $canselect{$type} =
3424: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3425: '<select name="newspare_'.$type.'_'.$server.'" '.
3426: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3427: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3428: if (@choices > 0) {
3429: foreach my $lonhost (@choices) {
3430: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3431: }
3432: }
3433: $canselect{$type} .= '</select>'."\n";
3434: }
3435: } else {
3436: $current{$type} = &mt('Could not be determined');
3437: if ($type eq 'primary') {
3438: $canselect{$type} = $othercontrol;
3439: }
1.145 raeburn 3440: }
1.152 raeburn 3441: if ($type eq 'default') {
3442: $datatable .= '<tr'.$css_class.'>';
3443: }
3444: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3445: '<td>'.$current{$type}.'</td>'."\n".
3446: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3447: }
3448: $itemcount ++;
3449: }
3450: }
3451: $$rowtotal += $itemcount;
3452: return $datatable;
3453: }
3454:
1.152 raeburn 3455: sub possible_newspares {
3456: my ($server,$currspares,$serverhomes,$altids) = @_;
3457: my $serverhostname = &Apache::lonnet::hostname($server);
3458: my %excluded;
3459: if ($serverhostname ne '') {
3460: %excluded = (
3461: $serverhostname => 1,
3462: );
3463: }
3464: if (ref($currspares) eq 'HASH') {
3465: foreach my $type (keys(%{$currspares})) {
3466: if (ref($currspares->{$type}) eq 'ARRAY') {
3467: if (@{$currspares->{$type}} > 0) {
3468: foreach my $curr (@{$currspares->{$type}}) {
3469: my $hostname = &Apache::lonnet::hostname($curr);
3470: $excluded{$hostname} = 1;
3471: }
3472: }
3473: }
3474: }
3475: }
3476: my @choices;
3477: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3478: if (keys(%{$serverhomes}) > 1) {
3479: foreach my $name (sort(keys(%{$serverhomes}))) {
3480: unless ($excluded{$name}) {
3481: if (exists($altids->{$serverhomes->{$name}})) {
3482: push(@choices,$altids->{$serverhomes->{$name}});
3483: } else {
3484: push(@choices,$serverhomes->{$name});
1.145 raeburn 3485: }
3486: }
3487: }
3488: }
3489: }
1.152 raeburn 3490: return sort(@choices);
1.145 raeburn 3491: }
3492:
1.150 raeburn 3493: sub print_loadbalancing {
3494: my ($dom,$settings,$rowtotal) = @_;
3495: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3496: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3497: my $numinrow = 1;
3498: my $datatable;
3499: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3500: my (%currbalancer,%currtargets,%currrules,%existing);
3501: if (ref($settings) eq 'HASH') {
3502: %existing = %{$settings};
3503: }
3504: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3505: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3506: \%currtargets,\%currrules);
1.150 raeburn 3507: } else {
3508: return;
3509: }
3510: my ($othertitle,$usertypes,$types) =
3511: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3512: my $rownum = 8;
1.150 raeburn 3513: if (ref($types) eq 'ARRAY') {
3514: $rownum += scalar(@{$types});
3515: }
1.171 raeburn 3516: my @css_class = ('LC_odd_row','LC_even_row');
3517: my $balnum = 0;
3518: my $islast;
3519: my (@toshow,$disabledtext);
3520: if (keys(%currbalancer) > 0) {
3521: @toshow = sort(keys(%currbalancer));
3522: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3523: push(@toshow,'');
3524: }
3525: } else {
3526: @toshow = ('');
3527: $disabledtext = &mt('No existing load balancer');
3528: }
3529: foreach my $lonhost (@toshow) {
3530: if ($balnum == scalar(@toshow)-1) {
3531: $islast = 1;
3532: } else {
3533: $islast = 0;
3534: }
3535: my $cssidx = $balnum%2;
3536: my $targets_div_style = 'display: none';
3537: my $disabled_div_style = 'display: block';
3538: my $homedom_div_style = 'display: none';
3539: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3540: '<td rowspan="'.$rownum.'" valign="top">'.
3541: '<p>';
3542: if ($lonhost eq '') {
1.210 raeburn 3543: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3544: if (keys(%currbalancer) > 0) {
3545: $datatable .= &mt('Add balancer:');
3546: } else {
3547: $datatable .= &mt('Enable balancer:');
3548: }
3549: $datatable .= ' '.
3550: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3551: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3552: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3553: '<option value="" selected="selected">'.&mt('None').
3554: '</option>'."\n";
3555: foreach my $server (sort(keys(%servers))) {
3556: next if ($currbalancer{$server});
3557: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3558: }
1.210 raeburn 3559: $datatable .=
1.171 raeburn 3560: '</select>'."\n".
3561: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3562: } else {
3563: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3564: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3565: &mt('Stop balancing').'</label>'.
3566: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3567: $targets_div_style = 'display: block';
3568: $disabled_div_style = 'display: none';
3569: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3570: $homedom_div_style = 'display: block';
3571: }
3572: }
3573: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3574: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3575: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3576: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3577: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3578: my @sparestypes = ('primary','default');
3579: my %typetitles = &sparestype_titles();
3580: foreach my $sparetype (@sparestypes) {
3581: my $targettable;
3582: for (my $i=0; $i<$numspares; $i++) {
3583: my $checked;
3584: if (ref($currtargets{$lonhost}) eq 'HASH') {
3585: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3586: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3587: $checked = ' checked="checked"';
3588: }
3589: }
3590: }
3591: my ($chkboxval,$disabled);
3592: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3593: $chkboxval = $spares[$i];
3594: }
3595: if (exists($currbalancer{$spares[$i]})) {
3596: $disabled = ' disabled="disabled"';
3597: }
1.210 raeburn 3598: $targettable .=
1.171 raeburn 3599: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3600: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3601: '</span></label></td>';
3602: my $rem = $i%($numinrow);
3603: if ($rem == 0) {
3604: if (($i > 0) && ($i < $numspares-1)) {
3605: $targettable .= '</tr>';
3606: }
3607: if ($i < $numspares-1) {
3608: $targettable .= '<tr>';
1.150 raeburn 3609: }
3610: }
3611: }
1.171 raeburn 3612: if ($targettable ne '') {
3613: my $rem = $numspares%($numinrow);
3614: my $colsleft = $numinrow - $rem;
3615: if ($colsleft > 1 ) {
3616: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3617: ' </td>';
3618: } elsif ($colsleft == 1) {
3619: $targettable .= '<td class="LC_left_item"> </td>';
3620: }
3621: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3622: '<table><tr>'.$targettable.'</tr></table><br />';
3623: }
3624: }
3625: $datatable .= '</div></td></tr>'.
3626: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3627: $othertitle,$usertypes,$types,\%servers,
3628: \%currbalancer,$lonhost,
3629: $targets_div_style,$homedom_div_style,
3630: $css_class[$cssidx],$balnum,$islast);
3631: $$rowtotal += $rownum;
3632: $balnum ++;
3633: }
3634: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3635: return $datatable;
3636: }
3637:
3638: sub get_loadbalancers_config {
3639: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3640: return unless ((ref($servers) eq 'HASH') &&
3641: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3642: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3643: if (keys(%{$existing}) > 0) {
3644: my $oldlonhost;
3645: foreach my $key (sort(keys(%{$existing}))) {
3646: if ($key eq 'lonhost') {
3647: $oldlonhost = $existing->{'lonhost'};
3648: $currbalancer->{$oldlonhost} = 1;
3649: } elsif ($key eq 'targets') {
3650: if ($oldlonhost) {
3651: $currtargets->{$oldlonhost} = $existing->{'targets'};
3652: }
3653: } elsif ($key eq 'rules') {
3654: if ($oldlonhost) {
3655: $currrules->{$oldlonhost} = $existing->{'rules'};
3656: }
3657: } elsif (ref($existing->{$key}) eq 'HASH') {
3658: $currbalancer->{$key} = 1;
3659: $currtargets->{$key} = $existing->{$key}{'targets'};
3660: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3661: }
3662: }
1.171 raeburn 3663: } else {
3664: my ($balancerref,$targetsref) =
3665: &Apache::lonnet::get_lonbalancer_config($servers);
3666: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3667: foreach my $server (sort(keys(%{$balancerref}))) {
3668: $currbalancer->{$server} = 1;
3669: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3670: }
3671: }
3672: }
1.171 raeburn 3673: return;
1.150 raeburn 3674: }
3675:
3676: sub loadbalancing_rules {
3677: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3678: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3679: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3680: my $output;
1.171 raeburn 3681: my $num = 0;
1.210 raeburn 3682: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3683: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3684: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3685: foreach my $type (@{$alltypes}) {
1.171 raeburn 3686: $num ++;
1.150 raeburn 3687: my $current;
3688: if (ref($currrules) eq 'HASH') {
3689: $current = $currrules->{$type};
3690: }
1.209 raeburn 3691: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3692: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3693: $current = '';
3694: }
3695: }
3696: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3697: $servers,$currbalancer,$lonhost,$dom,
3698: $targets_div_style,$homedom_div_style,
3699: $css_class,$balnum,$num,$islast);
1.150 raeburn 3700: }
3701: }
3702: return $output;
3703: }
3704:
3705: sub loadbalancing_titles {
3706: my ($dom,$intdom,$usertypes,$types) = @_;
3707: my %othertypes = (
3708: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3709: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3710: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3711: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3712: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3713: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3714: );
1.209 raeburn 3715: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3716: if (ref($types) eq 'ARRAY') {
3717: unshift(@alltypes,@{$types},'default');
3718: }
3719: my %titles;
3720: foreach my $type (@alltypes) {
3721: if ($type =~ /^_LC_/) {
3722: $titles{$type} = $othertypes{$type};
3723: } elsif ($type eq 'default') {
3724: $titles{$type} = &mt('All users from [_1]',$dom);
3725: if (ref($types) eq 'ARRAY') {
3726: if (@{$types} > 0) {
3727: $titles{$type} = &mt('Other users from [_1]',$dom);
3728: }
3729: }
3730: } elsif (ref($usertypes) eq 'HASH') {
3731: $titles{$type} = $usertypes->{$type};
3732: }
3733: }
3734: return (\@alltypes,\%othertypes,\%titles);
3735: }
3736:
3737: sub loadbalance_rule_row {
1.171 raeburn 3738: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3739: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3740: my @rulenames;
1.150 raeburn 3741: my %ruletitles = &offloadtype_text();
1.209 raeburn 3742: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3743: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3744: } else {
1.209 raeburn 3745: @rulenames = ('default','homeserver');
3746: if ($type eq '_LC_external') {
3747: push(@rulenames,'externalbalancer');
3748: } else {
3749: push(@rulenames,'specific');
3750: }
3751: push(@rulenames,'none');
1.150 raeburn 3752: }
3753: my $style = $targets_div_style;
1.209 raeburn 3754: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3755: $style = $homedom_div_style;
3756: }
1.171 raeburn 3757: my $space;
3758: if ($islast && $num == 1) {
3759: $space = '<div display="inline-block"> </div>';
3760: }
1.210 raeburn 3761: my $output =
1.171 raeburn 3762: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3763: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3764: '<td valaign="top">'.$space.
3765: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3766: for (my $i=0; $i<@rulenames; $i++) {
3767: my $rule = $rulenames[$i];
3768: my ($checked,$extra);
3769: if ($rulenames[$i] eq 'default') {
3770: $rule = '';
3771: }
3772: if ($rulenames[$i] eq 'specific') {
3773: if (ref($servers) eq 'HASH') {
3774: my $default;
3775: if (($current ne '') && (exists($servers->{$current}))) {
3776: $checked = ' checked="checked"';
3777: }
3778: unless ($checked) {
3779: $default = ' selected="selected"';
3780: }
1.210 raeburn 3781: $extra =
1.171 raeburn 3782: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3783: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3784: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3785: '<option value=""'.$default.'></option>'."\n";
3786: foreach my $server (sort(keys(%{$servers}))) {
3787: if (ref($currbalancer) eq 'HASH') {
3788: next if (exists($currbalancer->{$server}));
3789: }
1.150 raeburn 3790: my $selected;
1.171 raeburn 3791: if ($server eq $current) {
1.150 raeburn 3792: $selected = ' selected="selected"';
3793: }
1.171 raeburn 3794: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3795: }
3796: $extra .= '</select>';
3797: }
3798: } elsif ($rule eq $current) {
3799: $checked = ' checked="checked"';
3800: }
3801: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3802: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3803: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3804: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3805: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3806: '</label>'.$extra.'</span><br />'."\n";
3807: }
3808: $output .= '</div></td></tr>'."\n";
3809: return $output;
3810: }
3811:
3812: sub offloadtype_text {
3813: my %ruletitles = &Apache::lonlocal::texthash (
3814: 'default' => 'Offloads to default destinations',
3815: 'homeserver' => "Offloads to user's home server",
3816: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3817: 'specific' => 'Offloads to specific server',
1.161 raeburn 3818: 'none' => 'No offload',
1.209 raeburn 3819: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3820: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3821: );
3822: return %ruletitles;
3823: }
3824:
3825: sub sparestype_titles {
3826: my %typestitles = &Apache::lonlocal::texthash (
3827: 'primary' => 'primary',
3828: 'default' => 'default',
3829: );
3830: return %typestitles;
3831: }
3832:
1.28 raeburn 3833: sub contact_titles {
3834: my %titles = &Apache::lonlocal::texthash (
3835: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3836: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3837: 'errormail' => 'Error reports to be e-mailed to',
3838: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3839: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3840: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3841: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3842: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3843: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3844: );
3845: my %short_titles = &Apache::lonlocal::texthash (
3846: adminemail => 'Admin E-mail address',
3847: supportemail => 'Support E-mail',
3848: );
3849: return (\%titles,\%short_titles);
3850: }
3851:
1.72 raeburn 3852: sub tool_titles {
3853: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3854: aboutme => 'Personal web page',
1.86 raeburn 3855: blog => 'Blog',
1.162 raeburn 3856: webdav => 'WebDAV',
1.86 raeburn 3857: portfolio => 'Portfolio',
1.88 bisitz 3858: official => 'Official courses (with institutional codes)',
3859: unofficial => 'Unofficial courses',
1.98 raeburn 3860: community => 'Communities',
1.216 raeburn 3861: textbook => 'Textbook courses',
1.86 raeburn 3862: );
1.72 raeburn 3863: return %titles;
3864: }
3865:
1.101 raeburn 3866: sub courserequest_titles {
3867: my %titles = &Apache::lonlocal::texthash (
3868: official => 'Official',
3869: unofficial => 'Unofficial',
3870: community => 'Communities',
1.216 raeburn 3871: textbook => 'Textbook',
1.101 raeburn 3872: norequest => 'Not allowed',
1.104 raeburn 3873: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3874: validate => 'With validation',
3875: autolimit => 'Numerical limit',
1.103 raeburn 3876: unlimited => '(blank for unlimited)',
1.101 raeburn 3877: );
3878: return %titles;
3879: }
3880:
1.163 raeburn 3881: sub authorrequest_titles {
3882: my %titles = &Apache::lonlocal::texthash (
3883: norequest => 'Not allowed',
3884: approval => 'Approval by Dom. Coord.',
3885: automatic => 'Automatic approval',
3886: );
3887: return %titles;
1.210 raeburn 3888: }
1.163 raeburn 3889:
1.101 raeburn 3890: sub courserequest_conditions {
3891: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3892: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3893: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3894: );
3895: return %conditions;
3896: }
3897:
3898:
1.27 raeburn 3899: sub print_usercreation {
1.30 raeburn 3900: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3901: my $numinrow = 4;
1.28 raeburn 3902: my $datatable;
3903: if ($position eq 'top') {
1.30 raeburn 3904: $$rowtotal ++;
1.34 raeburn 3905: my $rowcount = 0;
1.32 raeburn 3906: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3907: if (ref($rules) eq 'HASH') {
3908: if (keys(%{$rules}) > 0) {
1.32 raeburn 3909: $datatable .= &user_formats_row('username',$settings,$rules,
3910: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3911: $$rowtotal ++;
1.32 raeburn 3912: $rowcount ++;
3913: }
3914: }
3915: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3916: if (ref($idrules) eq 'HASH') {
3917: if (keys(%{$idrules}) > 0) {
3918: $datatable .= &user_formats_row('id',$settings,$idrules,
3919: $idruleorder,$numinrow,$rowcount);
3920: $$rowtotal ++;
3921: $rowcount ++;
1.28 raeburn 3922: }
3923: }
1.39 raeburn 3924: if ($rowcount == 0) {
3925: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3926: $$rowtotal ++;
3927: $rowcount ++;
3928: }
1.34 raeburn 3929: } elsif ($position eq 'middle') {
1.224 raeburn 3930: my @creators = ('author','course','requestcrs');
1.37 raeburn 3931: my ($rules,$ruleorder) =
3932: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3933: my %lt = &usercreation_types();
3934: my %checked;
3935: if (ref($settings) eq 'HASH') {
3936: if (ref($settings->{'cancreate'}) eq 'HASH') {
3937: foreach my $item (@creators) {
3938: $checked{$item} = $settings->{'cancreate'}{$item};
3939: }
3940: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3941: foreach my $item (@creators) {
3942: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3943: $checked{$item} = 'none';
3944: }
3945: }
3946: }
3947: }
3948: my $rownum = 0;
3949: foreach my $item (@creators) {
3950: $rownum ++;
1.224 raeburn 3951: if ($checked{$item} eq '') {
3952: $checked{$item} = 'any';
1.34 raeburn 3953: }
3954: my $css_class;
3955: if ($rownum%2) {
3956: $css_class = '';
3957: } else {
3958: $css_class = ' class="LC_odd_row" ';
3959: }
3960: $datatable .= '<tr'.$css_class.'>'.
3961: '<td><span class="LC_nobreak">'.$lt{$item}.
3962: '</span></td><td align="right">';
1.224 raeburn 3963: my @options = ('any');
3964: if (ref($rules) eq 'HASH') {
3965: if (keys(%{$rules}) > 0) {
3966: push(@options,('official','unofficial'));
1.37 raeburn 3967: }
3968: }
1.224 raeburn 3969: push(@options,'none');
1.37 raeburn 3970: foreach my $option (@options) {
1.50 raeburn 3971: my $type = 'radio';
1.34 raeburn 3972: my $check = ' ';
1.224 raeburn 3973: if ($checked{$item} eq $option) {
3974: $check = ' checked="checked" ';
1.34 raeburn 3975: }
3976: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3977: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3978: $item.'" value="'.$option.'"'.$check.'/> '.
3979: $lt{$option}.'</label> </span>';
3980: }
3981: $datatable .= '</td></tr>';
3982: }
1.28 raeburn 3983: } else {
3984: my @contexts = ('author','course','domain');
3985: my @authtypes = ('int','krb4','krb5','loc');
3986: my %checked;
3987: if (ref($settings) eq 'HASH') {
3988: if (ref($settings->{'authtypes'}) eq 'HASH') {
3989: foreach my $item (@contexts) {
3990: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3991: foreach my $auth (@authtypes) {
3992: if ($settings->{'authtypes'}{$item}{$auth}) {
3993: $checked{$item}{$auth} = ' checked="checked" ';
3994: }
3995: }
3996: }
3997: }
1.27 raeburn 3998: }
1.35 raeburn 3999: } else {
4000: foreach my $item (@contexts) {
1.36 raeburn 4001: foreach my $auth (@authtypes) {
1.35 raeburn 4002: $checked{$item}{$auth} = ' checked="checked" ';
4003: }
4004: }
1.27 raeburn 4005: }
1.28 raeburn 4006: my %title = &context_names();
4007: my %authname = &authtype_names();
4008: my $rownum = 0;
4009: my $css_class;
4010: foreach my $item (@contexts) {
4011: if ($rownum%2) {
4012: $css_class = '';
4013: } else {
4014: $css_class = ' class="LC_odd_row" ';
4015: }
1.30 raeburn 4016: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4017: '<td>'.$title{$item}.
4018: '</td><td class="LC_left_item">'.
4019: '<span class="LC_nobreak">';
4020: foreach my $auth (@authtypes) {
4021: $datatable .= '<label>'.
4022: '<input type="checkbox" name="'.$item.'_auth" '.
4023: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4024: $authname{$auth}.'</label> ';
4025: }
4026: $datatable .= '</span></td></tr>';
4027: $rownum ++;
1.27 raeburn 4028: }
1.30 raeburn 4029: $$rowtotal += $rownum;
1.27 raeburn 4030: }
4031: return $datatable;
4032: }
4033:
1.224 raeburn 4034: sub print_selfcreation {
4035: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4036: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4037: if (ref($settings) eq 'HASH') {
4038: if (ref($settings->{'cancreate'}) eq 'HASH') {
4039: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4040: if (ref($createsettings) eq 'HASH') {
4041: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4042: @selfcreate = @{$createsettings->{'selfcreate'}};
4043: } elsif ($createsettings->{'selfcreate'} ne '') {
4044: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4045: @selfcreate = ('email','login','sso');
4046: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4047: @selfcreate = ($createsettings->{'selfcreate'});
4048: }
4049: }
4050: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4051: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4052: }
4053: }
4054: }
4055: }
4056: my %radiohash;
4057: my $numinrow = 4;
4058: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4059: if ($position eq 'top') {
4060: my %choices = &Apache::lonlocal::texthash (
4061: cancreate_login => 'Institutional Login',
4062: cancreate_sso => 'Institutional Single Sign On',
4063: );
4064: my @toggles = sort(keys(%choices));
4065: my %defaultchecked = (
4066: 'cancreate_login' => 'off',
4067: 'cancreate_sso' => 'off',
4068: );
1.228 raeburn 4069: my ($onclick,$itemcount);
1.224 raeburn 4070: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4071: \%choices,$itemcount,$onclick);
1.228 raeburn 4072: $$rowtotal += $itemcount;
4073:
1.224 raeburn 4074: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4075:
4076: if (ref($usertypes) eq 'HASH') {
4077: if (keys(%{$usertypes}) > 0) {
4078: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4079: $dom,$numinrow,$othertitle,
1.228 raeburn 4080: 'statustocreate',$$rowtotal);
1.224 raeburn 4081: $$rowtotal ++;
4082: }
4083: }
4084: } elsif ($position eq 'middle') {
4085: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4086: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4087: $usertypes->{'default'} = $othertitle;
4088: if (ref($types) eq 'ARRAY') {
4089: push(@{$types},'default');
4090: $usertypes->{'default'} = $othertitle;
4091: foreach my $status (@{$types}) {
4092: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4093: $numinrow,$$rowtotal,$usertypes);
1.236 raeburn 4094: $$rowtotal ++;
1.224 raeburn 4095: }
4096: }
4097: } else {
1.236 raeburn 4098: my %choices = &Apache::lonlocal::texthash (
4099: cancreate_email => 'E-mail address as username',
4100: );
4101: my @toggles = sort(keys(%choices));
4102: my %defaultchecked = (
4103: 'cancreate_email' => 'off',
4104: );
4105: my $itemcount = 0;
4106: my $display = 'none';
4107: if (grep(/^\Qemail\E$/,@selfcreate)) {
4108: $display = 'block';
4109: }
4110: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4111: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4112: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4113: my $usertypes = {};
4114: my $order = [];
4115: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4116: $usertypes = $domdefaults{'inststatustypes'};
4117: $order = $domdefaults{'inststatusguest'};
4118: }
4119: if (ref($order) eq 'ARRAY') {
4120: push(@{$order},'default');
4121: if (@{$order} > 1) {
4122: $usertypes->{'default'} = &mt('Other users');
4123: $additional .= '<table><tr>';
4124: foreach my $status (@{$order}) {
4125: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4126: }
4127: $additional .= '</tr><tr>';
4128: foreach my $status (@{$order}) {
4129: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4130: }
1.236 raeburn 4131: $additional .= '</tr></table>';
1.224 raeburn 4132: } else {
1.236 raeburn 4133: $usertypes->{'default'} = &mt('All users');
4134: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4135: }
4136: }
1.236 raeburn 4137: $additional .= '</div>'."\n";
4138:
4139: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4140: \%choices,$itemcount,$onclick,$additional);
4141: $$rowtotal += $itemcount;
4142: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4143: $$rowtotal ++;
1.224 raeburn 4144: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4145: $numinrow = 1;
1.236 raeburn 4146: if (ref($order) eq 'ARRAY') {
4147: foreach my $status (@{$order}) {
1.228 raeburn 4148: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4149: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4150: $$rowtotal ++;
4151: }
4152: }
1.224 raeburn 4153: my ($emailrules,$emailruleorder) =
4154: &Apache::lonnet::inst_userrules($dom,'email');
4155: if (ref($emailrules) eq 'HASH') {
4156: if (keys(%{$emailrules}) > 0) {
4157: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4158: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4159: $$rowtotal ++;
4160: }
4161: }
1.228 raeburn 4162: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4163: }
4164: return $datatable;
4165: }
4166:
1.236 raeburn 4167: sub email_as_username {
4168: my ($rowtotal,$processing,$type) = @_;
4169: my %choices =
4170: &Apache::lonlocal::texthash (
4171: automatic => 'Automatic approval',
4172: approval => 'Queued for approval',
4173: );
4174: my $output;
4175: foreach my $option ('automatic','approval') {
4176: my $checked;
4177: if (ref($processing) eq 'HASH') {
4178: if ($type eq '') {
4179: if (!exists($processing->{'default'})) {
4180: if ($option eq 'automatic') {
4181: $checked = ' checked="checked"';
4182: }
4183: } else {
4184: if ($processing->{'default'} eq $option) {
4185: $checked = ' checked="checked"';
4186: }
4187: }
4188: } else {
4189: if (!exists($processing->{$type})) {
4190: if ($option eq 'automatic') {
4191: $checked = ' checked="checked"';
4192: }
4193: } else {
4194: if ($processing->{$type} eq $option) {
4195: $checked = ' checked="checked"';
4196: }
4197: }
4198: }
4199: } elsif ($option eq 'automatic') {
4200: $checked = ' checked="checked"';
4201: }
4202: my $name = 'cancreate_emailprocess';
4203: if (($type ne '') && ($type ne 'default')) {
4204: $name .= '_'.$type;
4205: }
4206: $output .= '<span class="LC_nobreak"><label>'.
4207: '<input type="radio" name="'.$name.'"'.
4208: $checked.' value="'.$option.'" />'.
4209: $choices{$option}.'</label></span>';
4210: if ($type eq '') {
4211: $output .= ' ';
4212: } else {
4213: $output .= '<br />';
4214: }
4215: }
4216: $$rowtotal ++;
4217: return $output;
4218: }
4219:
1.165 raeburn 4220: sub captcha_choice {
1.169 raeburn 4221: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4222: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4223: my %lt = &captcha_phrases();
4224: $keyentry = 'hidden';
4225: if ($context eq 'cancreate') {
1.224 raeburn 4226: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4227: } elsif ($context eq 'login') {
4228: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4229: }
4230: if (ref($settings) eq 'HASH') {
4231: if ($settings->{'captcha'}) {
4232: $checked{$settings->{'captcha'}} = ' checked="checked"';
4233: } else {
4234: $checked{'original'} = ' checked="checked"';
4235: }
4236: if ($settings->{'captcha'} eq 'recaptcha') {
4237: $pubtext = $lt{'pub'};
4238: $privtext = $lt{'priv'};
4239: $keyentry = 'text';
4240: }
4241: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4242: $currpub = $settings->{'recaptchakeys'}{'public'};
4243: $currpriv = $settings->{'recaptchakeys'}{'private'};
4244: }
4245: } else {
4246: $checked{'original'} = ' checked="checked"';
4247: }
1.169 raeburn 4248: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4249: my $output = '<tr'.$css_class.'>'.
4250: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4251: '<table><tr><td>'."\n";
4252: foreach my $option ('original','recaptcha','notused') {
4253: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4254: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4255: $lt{$option}.'</label></span>';
4256: unless ($option eq 'notused') {
4257: $output .= (' 'x2)."\n";
4258: }
4259: }
4260: #
4261: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4262: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4263: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4264: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4265: #
1.165 raeburn 4266: $output .= '</td></tr>'."\n".
4267: '<tr><td>'."\n".
4268: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4269: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4270: $currpub.'" size="40" /></span><br />'."\n".
4271: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4272: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4273: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4274: '</td></tr>';
4275: return $output;
4276: }
4277:
1.32 raeburn 4278: sub user_formats_row {
4279: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4280: my $output;
4281: my %text = (
4282: 'username' => 'new usernames',
4283: 'id' => 'IDs',
1.45 raeburn 4284: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4285: );
4286: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4287: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4288: '<td><span class="LC_nobreak">';
4289: if ($type eq 'email') {
4290: $output .= &mt("Formats disallowed for $text{$type}: ");
4291: } else {
4292: $output .= &mt("Format rules to check for $text{$type}: ");
4293: }
4294: $output .= '</span></td>'.
4295: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4296: my $rem;
4297: if (ref($ruleorder) eq 'ARRAY') {
4298: for (my $i=0; $i<@{$ruleorder}; $i++) {
4299: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4300: my $rem = $i%($numinrow);
4301: if ($rem == 0) {
4302: if ($i > 0) {
4303: $output .= '</tr>';
4304: }
4305: $output .= '<tr>';
4306: }
4307: my $check = ' ';
1.39 raeburn 4308: if (ref($settings) eq 'HASH') {
4309: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4310: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4311: $check = ' checked="checked" ';
4312: }
1.27 raeburn 4313: }
4314: }
4315: $output .= '<td class="LC_left_item">'.
4316: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4317: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4318: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4319: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4320: }
4321: }
4322: $rem = @{$ruleorder}%($numinrow);
4323: }
4324: my $colsleft = $numinrow - $rem;
4325: if ($colsleft > 1 ) {
4326: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4327: ' </td>';
4328: } elsif ($colsleft == 1) {
4329: $output .= '<td class="LC_left_item"> </td>';
4330: }
4331: $output .= '</tr></table></td></tr>';
4332: return $output;
4333: }
4334:
1.34 raeburn 4335: sub usercreation_types {
4336: my %lt = &Apache::lonlocal::texthash (
4337: author => 'When adding a co-author',
4338: course => 'When adding a user to a course',
1.100 raeburn 4339: requestcrs => 'When requesting a course',
1.34 raeburn 4340: any => 'Any',
4341: official => 'Institutional only ',
4342: unofficial => 'Non-institutional only',
4343: none => 'None',
4344: );
4345: return %lt;
1.48 raeburn 4346: }
1.34 raeburn 4347:
1.224 raeburn 4348: sub selfcreation_types {
4349: my %lt = &Apache::lonlocal::texthash (
4350: selfcreate => 'User creates own account',
4351: any => 'Any',
4352: official => 'Institutional only ',
4353: unofficial => 'Non-institutional only',
4354: email => 'E-mail address',
4355: login => 'Institutional Login',
4356: sso => 'SSO',
4357: );
4358: }
4359:
1.28 raeburn 4360: sub authtype_names {
4361: my %lt = &Apache::lonlocal::texthash(
4362: int => 'Internal',
4363: krb4 => 'Kerberos 4',
4364: krb5 => 'Kerberos 5',
4365: loc => 'Local',
4366: );
4367: return %lt;
4368: }
4369:
4370: sub context_names {
4371: my %context_title = &Apache::lonlocal::texthash(
4372: author => 'Creating users when an Author',
4373: course => 'Creating users when in a course',
4374: domain => 'Creating users when a Domain Coordinator',
4375: );
4376: return %context_title;
4377: }
4378:
1.33 raeburn 4379: sub print_usermodification {
4380: my ($position,$dom,$settings,$rowtotal) = @_;
4381: my $numinrow = 4;
4382: my ($context,$datatable,$rowcount);
4383: if ($position eq 'top') {
4384: $rowcount = 0;
4385: $context = 'author';
4386: foreach my $role ('ca','aa') {
4387: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4388: $numinrow,$rowcount);
4389: $$rowtotal ++;
4390: $rowcount ++;
4391: }
1.230 raeburn 4392: } elsif ($position eq 'bottom') {
1.33 raeburn 4393: $context = 'course';
4394: $rowcount = 0;
4395: foreach my $role ('st','ep','ta','in','cr') {
4396: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4397: $numinrow,$rowcount);
4398: $$rowtotal ++;
4399: $rowcount ++;
4400: }
4401: }
4402: return $datatable;
4403: }
4404:
1.43 raeburn 4405: sub print_defaults {
1.236 raeburn 4406: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4407: my $rownum = 0;
4408: my ($datatable,$css_class);
1.236 raeburn 4409: if ($position eq 'top') {
4410: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4411: 'datelocale_def','portal_def');
4412: my %defaults;
4413: if (ref($settings) eq 'HASH') {
4414: %defaults = %{$settings};
1.43 raeburn 4415: } else {
1.236 raeburn 4416: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4417: foreach my $item (@items) {
4418: $defaults{$item} = $domdefaults{$item};
4419: }
1.43 raeburn 4420: }
1.236 raeburn 4421: my $titles = &defaults_titles($dom);
4422: foreach my $item (@items) {
4423: if ($rownum%2) {
4424: $css_class = '';
4425: } else {
4426: $css_class = ' class="LC_odd_row" ';
4427: }
4428: $datatable .= '<tr'.$css_class.'>'.
4429: '<td><span class="LC_nobreak">'.$titles->{$item}.
4430: '</span></td><td class="LC_right_item" colspan="3">';
4431: if ($item eq 'auth_def') {
4432: my @authtypes = ('internal','krb4','krb5','localauth');
4433: my %shortauth = (
4434: internal => 'int',
4435: krb4 => 'krb4',
4436: krb5 => 'krb5',
4437: localauth => 'loc'
4438: );
4439: my %authnames = &authtype_names();
4440: foreach my $auth (@authtypes) {
4441: my $checked = ' ';
4442: if ($defaults{$item} eq $auth) {
4443: $checked = ' checked="checked" ';
4444: }
4445: $datatable .= '<label><input type="radio" name="'.$item.
4446: '" value="'.$auth.'"'.$checked.'/>'.
4447: $authnames{$shortauth{$auth}}.'</label> ';
4448: }
4449: } elsif ($item eq 'timezone_def') {
4450: my $includeempty = 1;
4451: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4452: } elsif ($item eq 'datelocale_def') {
4453: my $includeempty = 1;
4454: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4455: } elsif ($item eq 'lang_def') {
4456: my %langchoices = &get_languages_hash();
4457: $langchoices{''} = 'No language preference';
4458: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4459: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4460: \%langchoices);
4461: } else {
4462: my $size;
4463: if ($item eq 'portal_def') {
4464: $size = ' size="25"';
4465: }
4466: $datatable .= '<input type="text" name="'.$item.'" value="'.
4467: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4468: }
1.236 raeburn 4469: $datatable .= '</td></tr>';
4470: $rownum ++;
4471: }
4472: } else {
4473: my (%defaults);
4474: if (ref($settings) eq 'HASH') {
4475: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4476: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4477: my $maxnum = @{$settings->{'inststatusorder'}};
4478: for (my $i=0; $i<$maxnum; $i++) {
4479: $css_class = $rownum%2?' class="LC_odd_row"':'';
4480: my $item = $settings->{'inststatusorder'}->[$i];
4481: my $title = $settings->{'inststatustypes'}->{$item};
4482: my $guestok;
4483: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4484: $guestok = 1;
4485: }
4486: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4487: $datatable .= '<tr'.$css_class.'>'.
4488: '<td><span class="LC_nobreak">'.
4489: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4490: for (my $k=0; $k<=$maxnum; $k++) {
4491: my $vpos = $k+1;
4492: my $selstr;
4493: if ($k == $i) {
4494: $selstr = ' selected="selected" ';
4495: }
4496: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4497: }
4498: my ($checkedon,$checkedoff);
4499: $checkedoff = ' checked="checked"';
4500: if ($guestok) {
4501: $checkedon = $checkedoff;
4502: $checkedoff = '';
4503: }
4504: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4505: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4506: &mt('delete').'</span></td>'.
4507: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4508: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4509: '</span></td>'.
4510: '<td class="LC_right_item"><span class="LC_nobreak">'.
4511: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4512: &mt('Yes').'</label>'.(' 'x2).
4513: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4514: &mt('No').'</label></span></td></tr>';
4515: }
4516: $css_class = $rownum%2?' class="LC_odd_row"':'';
4517: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4518: $datatable .= '<tr '.$css_class.'>'.
4519: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4520: for (my $k=0; $k<=$maxnum; $k++) {
4521: my $vpos = $k+1;
4522: my $selstr;
4523: if ($k == $maxnum) {
4524: $selstr = ' selected="selected" ';
4525: }
4526: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4527: }
4528: $datatable .= '</select> '.&mt('Internal ID:').
4529: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4530: ' '.&mt('(new)').
4531: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4532: &mt('Name displayed:').
4533: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4534: '<td class="LC_right_item"><span class="LC_nobreak">'.
4535: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4536: &mt('Yes').'</label>'.(' 'x2).
4537: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4538: &mt('No').'</label></span></td></tr>';
4539: '</tr>'."\n";
4540: $rownum ++;
1.141 raeburn 4541: }
1.43 raeburn 4542: }
4543: }
4544: $$rowtotal += $rownum;
4545: return $datatable;
4546: }
4547:
1.168 raeburn 4548: sub get_languages_hash {
4549: my %langchoices;
4550: foreach my $id (&Apache::loncommon::languageids()) {
4551: my $code = &Apache::loncommon::supportedlanguagecode($id);
4552: if ($code ne '') {
4553: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4554: }
4555: }
4556: return %langchoices;
4557: }
4558:
1.43 raeburn 4559: sub defaults_titles {
1.141 raeburn 4560: my ($dom) = @_;
1.43 raeburn 4561: my %titles = &Apache::lonlocal::texthash (
4562: 'auth_def' => 'Default authentication type',
4563: 'auth_arg_def' => 'Default authentication argument',
4564: 'lang_def' => 'Default language',
1.54 raeburn 4565: 'timezone_def' => 'Default timezone',
1.68 raeburn 4566: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4567: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4568: );
1.141 raeburn 4569: if ($dom) {
4570: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4571: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4572: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4573: $protocol = 'http' if ($protocol ne 'https');
4574: if ($uint_dom) {
4575: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4576: $uint_dom);
4577: }
4578: }
1.43 raeburn 4579: return (\%titles);
4580: }
4581:
1.46 raeburn 4582: sub print_scantronformat {
4583: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4584: my $itemcount = 1;
1.60 raeburn 4585: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4586: %confhash);
1.46 raeburn 4587: my $switchserver = &check_switchserver($dom,$confname);
4588: my %lt = &Apache::lonlocal::texthash (
1.95 www 4589: default => 'Default bubblesheet format file error',
4590: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4591: );
4592: my %scantronfiles = (
4593: default => 'default.tab',
4594: custom => 'custom.tab',
4595: );
4596: foreach my $key (keys(%scantronfiles)) {
4597: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4598: .$scantronfiles{$key};
4599: }
4600: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4601: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4602: if (!$switchserver) {
4603: my $servadm = $r->dir_config('lonAdmEMail');
4604: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4605: if ($configuserok eq 'ok') {
4606: if ($author_ok eq 'ok') {
4607: my %legacyfile = (
4608: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4609: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4610: );
4611: my %md5chk;
4612: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4613: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4614: chomp($md5chk{$type});
1.46 raeburn 4615: }
4616: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4617: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4618: ($scantronurls{$type},my $error) =
1.46 raeburn 4619: &legacy_scantronformat($r,$dom,$confname,
4620: $type,$legacyfile{$type},
4621: $scantronurls{$type},
4622: $scantronfiles{$type});
1.60 raeburn 4623: if ($error ne '') {
4624: $error{$type} = $error;
4625: }
4626: }
4627: if (keys(%error) == 0) {
4628: $is_custom = 1;
4629: $confhash{'scantron'}{'scantronformat'} =
4630: $scantronurls{'custom'};
4631: my $putresult =
4632: &Apache::lonnet::put_dom('configuration',
4633: \%confhash,$dom);
4634: if ($putresult ne 'ok') {
4635: $error{'custom'} =
4636: '<span class="LC_error">'.
4637: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4638: }
1.46 raeburn 4639: }
4640: } else {
1.60 raeburn 4641: ($scantronurls{'default'},my $error) =
1.46 raeburn 4642: &legacy_scantronformat($r,$dom,$confname,
4643: 'default',$legacyfile{'default'},
4644: $scantronurls{'default'},
4645: $scantronfiles{'default'});
1.60 raeburn 4646: if ($error eq '') {
4647: $confhash{'scantron'}{'scantronformat'} = '';
4648: my $putresult =
4649: &Apache::lonnet::put_dom('configuration',
4650: \%confhash,$dom);
4651: if ($putresult ne 'ok') {
4652: $error{'default'} =
4653: '<span class="LC_error">'.
4654: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4655: }
4656: } else {
4657: $error{'default'} = $error;
4658: }
1.46 raeburn 4659: }
4660: }
4661: }
4662: } else {
1.95 www 4663: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4664: }
4665: }
4666: if (ref($settings) eq 'HASH') {
4667: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4668: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4669: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4670: $scantronurl = '';
4671: } else {
4672: $scantronurl = $settings->{'scantronformat'};
4673: }
4674: $is_custom = 1;
4675: } else {
4676: $scantronurl = $scantronurls{'default'};
4677: }
4678: } else {
1.60 raeburn 4679: if ($is_custom) {
4680: $scantronurl = $scantronurls{'custom'};
4681: } else {
4682: $scantronurl = $scantronurls{'default'};
4683: }
1.46 raeburn 4684: }
4685: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4686: $datatable .= '<tr'.$css_class.'>';
4687: if (!$is_custom) {
1.65 raeburn 4688: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4689: '<span class="LC_nobreak">';
1.46 raeburn 4690: if ($scantronurl) {
1.199 raeburn 4691: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4692: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4693: } else {
4694: $datatable = &mt('File unavailable for display');
4695: }
1.65 raeburn 4696: $datatable .= '</span></td>';
1.60 raeburn 4697: if (keys(%error) == 0) {
4698: $datatable .= '<td valign="bottom">';
4699: if (!$switchserver) {
4700: $datatable .= &mt('Upload:').'<br />';
4701: }
4702: } else {
4703: my $errorstr;
4704: foreach my $key (sort(keys(%error))) {
4705: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4706: }
4707: $datatable .= '<td>'.$errorstr;
4708: }
1.46 raeburn 4709: } else {
4710: if (keys(%error) > 0) {
4711: my $errorstr;
4712: foreach my $key (sort(keys(%error))) {
4713: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4714: }
1.60 raeburn 4715: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4716: } elsif ($scantronurl) {
1.199 raeburn 4717: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4718: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4719: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4720: $link.
4721: '<label><input type="checkbox" name="scantronformat_del"'.
4722: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4723: '<td><span class="LC_nobreak"> '.
4724: &mt('Replace:').'</span><br />';
1.46 raeburn 4725: }
4726: }
4727: if (keys(%error) == 0) {
4728: if ($switchserver) {
4729: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4730: } else {
1.65 raeburn 4731: $datatable .='<span class="LC_nobreak"> '.
4732: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4733: }
4734: }
4735: $datatable .= '</td></tr>';
4736: $$rowtotal ++;
4737: return $datatable;
4738: }
4739:
4740: sub legacy_scantronformat {
4741: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4742: my ($url,$error);
4743: my @statinfo = &Apache::lonnet::stat_file($newurl);
4744: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4745: (my $result,$url) =
4746: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4747: '','',$newfile);
4748: if ($result ne 'ok') {
1.130 raeburn 4749: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4750: }
4751: }
4752: return ($url,$error);
4753: }
1.43 raeburn 4754:
1.49 raeburn 4755: sub print_coursecategories {
1.57 raeburn 4756: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4757: my $datatable;
4758: if ($position eq 'top') {
1.238 ! raeburn 4759: my (%checked);
! 4760: my @catitems = ('unauth','auth');
! 4761: my @cattypes = ('std','domonly','codesrch','none');
! 4762: $checked{'unauth'} = 'std';
! 4763: $checked{'auth'} = 'std';
! 4764: if (ref($settings) eq 'HASH') {
! 4765: foreach my $type (@cattypes) {
! 4766: if ($type eq $settings->{'unauth'}) {
! 4767: $checked{'unauth'} = $type;
! 4768: }
! 4769: if ($type eq $settings->{'auth'}) {
! 4770: $checked{'auth'} = $type;
! 4771: }
! 4772: }
! 4773: }
! 4774: my %lt = &Apache::lonlocal::texthash (
! 4775: unauth => 'Catalog type for unauthenticated users',
! 4776: auth => 'Catalog type for authenticated users',
! 4777: none => 'No catalog',
! 4778: std => 'Standard catalog',
! 4779: domonly => 'Domain-only catalog',
! 4780: codesrch => "Code search form",
! 4781: );
! 4782: my $itemcount = 0;
! 4783: foreach my $item (@catitems) {
! 4784: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
! 4785: $datatable .= '<tr '.$css_class.'>'.
! 4786: '<td>'.$lt{$item}.'</td>'.
! 4787: '<td class="LC_right_item"><span class="LC_nobreak">';
! 4788: foreach my $type (@cattypes) {
! 4789: my $ischecked;
! 4790: if ($checked{$item} eq $type) {
! 4791: $ischecked=' checked="checked"';
! 4792: }
! 4793: $datatable .= '<label>'.
! 4794: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
! 4795: ' />'.$lt{$type}.'</label> ';
! 4796: }
! 4797: $datatable .= '</td></tr>';
! 4798: $itemcount ++;
! 4799: }
! 4800: $$rowtotal += $itemcount;
! 4801: } elsif ($position eq 'middle') {
1.57 raeburn 4802: my $toggle_cats_crs = ' ';
4803: my $toggle_cats_dom = ' checked="checked" ';
4804: my $can_cat_crs = ' ';
4805: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4806: my $toggle_catscomm_comm = ' ';
4807: my $toggle_catscomm_dom = ' checked="checked" ';
4808: my $can_catcomm_comm = ' ';
4809: my $can_catcomm_dom = ' checked="checked" ';
4810:
1.57 raeburn 4811: if (ref($settings) eq 'HASH') {
4812: if ($settings->{'togglecats'} eq 'crs') {
4813: $toggle_cats_crs = $toggle_cats_dom;
4814: $toggle_cats_dom = ' ';
4815: }
4816: if ($settings->{'categorize'} eq 'crs') {
4817: $can_cat_crs = $can_cat_dom;
4818: $can_cat_dom = ' ';
4819: }
1.120 raeburn 4820: if ($settings->{'togglecatscomm'} eq 'comm') {
4821: $toggle_catscomm_comm = $toggle_catscomm_dom;
4822: $toggle_catscomm_dom = ' ';
4823: }
4824: if ($settings->{'categorizecomm'} eq 'comm') {
4825: $can_catcomm_comm = $can_catcomm_dom;
4826: $can_catcomm_dom = ' ';
4827: }
1.57 raeburn 4828: }
4829: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4830: togglecats => 'Show/Hide a course in catalog',
4831: togglecatscomm => 'Show/Hide a community in catalog',
4832: categorize => 'Assign a category to a course',
4833: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4834: );
4835: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4836: dom => 'Set in Domain',
4837: crs => 'Set in Course',
4838: comm => 'Set in Community',
1.57 raeburn 4839: );
4840: $datatable = '<tr class="LC_odd_row">'.
4841: '<td>'.$title{'togglecats'}.'</td>'.
4842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4843: '<input type="radio" name="togglecats"'.
4844: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4845: '<label><input type="radio" name="togglecats"'.
4846: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4847: '</tr><tr>'.
4848: '<td>'.$title{'categorize'}.'</td>'.
4849: '<td class="LC_right_item"><span class="LC_nobreak">'.
4850: '<label><input type="radio" name="categorize"'.
4851: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4852: '<label><input type="radio" name="categorize"'.
4853: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4854: '</tr><tr class="LC_odd_row">'.
4855: '<td>'.$title{'togglecatscomm'}.'</td>'.
4856: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4857: '<input type="radio" name="togglecatscomm"'.
4858: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4859: '<label><input type="radio" name="togglecatscomm"'.
4860: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4861: '</tr><tr>'.
4862: '<td>'.$title{'categorizecomm'}.'</td>'.
4863: '<td class="LC_right_item"><span class="LC_nobreak">'.
4864: '<label><input type="radio" name="categorizecomm"'.
4865: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4866: '<label><input type="radio" name="categorizecomm"'.
4867: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4868: '</tr>';
1.120 raeburn 4869: $$rowtotal += 4;
1.57 raeburn 4870: } else {
4871: my $css_class;
4872: my $itemcount = 1;
4873: my $cathash;
4874: if (ref($settings) eq 'HASH') {
4875: $cathash = $settings->{'cats'};
4876: }
4877: if (ref($cathash) eq 'HASH') {
4878: my (@cats,@trails,%allitems,%idx,@jsarray);
4879: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4880: \%allitems,\%idx,\@jsarray);
4881: my $maxdepth = scalar(@cats);
4882: my $colattrib = '';
4883: if ($maxdepth > 2) {
4884: $colattrib = ' colspan="2" ';
4885: }
4886: my @path;
4887: if (@cats > 0) {
4888: if (ref($cats[0]) eq 'ARRAY') {
4889: my $numtop = @{$cats[0]};
4890: my $maxnum = $numtop;
1.120 raeburn 4891: my %default_names = (
4892: instcode => &mt('Official courses'),
4893: communities => &mt('Communities'),
4894: );
4895:
4896: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4897: ($cathash->{'instcode::0'} eq '') ||
4898: (!grep(/^communities$/,@{$cats[0]})) ||
4899: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4900: $maxnum ++;
4901: }
4902: my $lastidx;
4903: for (my $i=0; $i<$numtop; $i++) {
4904: my $parent = $cats[0][$i];
4905: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4906: my $item = &escape($parent).'::0';
4907: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4908: $lastidx = $idx{$item};
4909: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4910: .'<select name="'.$item.'"'.$chgstr.'>';
4911: for (my $k=0; $k<=$maxnum; $k++) {
4912: my $vpos = $k+1;
4913: my $selstr;
4914: if ($k == $i) {
4915: $selstr = ' selected="selected" ';
4916: }
4917: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4918: }
1.214 raeburn 4919: $datatable .= '</select></span></td><td>';
1.120 raeburn 4920: if ($parent eq 'instcode' || $parent eq 'communities') {
4921: $datatable .= '<span class="LC_nobreak">'
4922: .$default_names{$parent}.'</span>';
4923: if ($parent eq 'instcode') {
4924: $datatable .= '<br /><span class="LC_nobreak">('
4925: .&mt('with institutional codes')
4926: .')</span></td><td'.$colattrib.'>';
4927: } else {
4928: $datatable .= '<table><tr><td>';
4929: }
4930: $datatable .= '<span class="LC_nobreak">'
4931: .'<label><input type="radio" name="'
4932: .$parent.'" value="1" checked="checked" />'
4933: .&mt('Display').'</label>';
4934: if ($parent eq 'instcode') {
4935: $datatable .= ' ';
4936: } else {
4937: $datatable .= '</span></td></tr><tr><td>'
4938: .'<span class="LC_nobreak">';
4939: }
4940: $datatable .= '<label><input type="radio" name="'
4941: .$parent.'" value="0" />'
4942: .&mt('Do not display').'</label></span>';
4943: if ($parent eq 'communities') {
4944: $datatable .= '</td></tr></table>';
4945: }
4946: $datatable .= '</td>';
1.57 raeburn 4947: } else {
4948: $datatable .= $parent
1.214 raeburn 4949: .' <span class="LC_nobreak"><label>'
4950: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4951: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4952: }
4953: my $depth = 1;
4954: push(@path,$parent);
4955: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4956: pop(@path);
4957: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4958: $itemcount ++;
4959: }
1.48 raeburn 4960: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4961: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4962: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4963: for (my $k=0; $k<=$maxnum; $k++) {
4964: my $vpos = $k+1;
4965: my $selstr;
1.57 raeburn 4966: if ($k == $numtop) {
1.48 raeburn 4967: $selstr = ' selected="selected" ';
4968: }
4969: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4970: }
1.59 bisitz 4971: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4972: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4973: .'</tr>'."\n";
1.48 raeburn 4974: $itemcount ++;
1.120 raeburn 4975: foreach my $default ('instcode','communities') {
4976: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4977: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4978: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4979: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4980: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4981: for (my $k=0; $k<=$maxnum; $k++) {
4982: my $vpos = $k+1;
4983: my $selstr;
4984: if ($k == $maxnum) {
4985: $selstr = ' selected="selected" ';
4986: }
4987: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4988: }
1.120 raeburn 4989: $datatable .= '</select></span></td>'.
4990: '<td><span class="LC_nobreak">'.
4991: $default_names{$default}.'</span>';
4992: if ($default eq 'instcode') {
4993: $datatable .= '<br /><span class="LC_nobreak">('
4994: .&mt('with institutional codes').')</span>';
4995: }
4996: $datatable .= '</td>'
4997: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4998: .&mt('Display').'</label> '
4999: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5000: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5001: }
5002: }
5003: }
1.57 raeburn 5004: } else {
5005: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5006: }
5007: } else {
1.238 ! raeburn 5008: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5009: .&initialize_categories($itemcount);
1.48 raeburn 5010: }
1.57 raeburn 5011: $$rowtotal += $itemcount;
1.48 raeburn 5012: }
5013: return $datatable;
5014: }
5015:
1.69 raeburn 5016: sub print_serverstatuses {
5017: my ($dom,$settings,$rowtotal) = @_;
5018: my $datatable;
5019: my @pages = &serverstatus_pages();
5020: my (%namedaccess,%machineaccess);
5021: foreach my $type (@pages) {
5022: $namedaccess{$type} = '';
5023: $machineaccess{$type}= '';
5024: }
5025: if (ref($settings) eq 'HASH') {
5026: foreach my $type (@pages) {
5027: if (exists($settings->{$type})) {
5028: if (ref($settings->{$type}) eq 'HASH') {
5029: foreach my $key (keys(%{$settings->{$type}})) {
5030: if ($key eq 'namedusers') {
5031: $namedaccess{$type} = $settings->{$type}->{$key};
5032: } elsif ($key eq 'machines') {
5033: $machineaccess{$type} = $settings->{$type}->{$key};
5034: }
5035: }
5036: }
5037: }
5038: }
5039: }
1.81 raeburn 5040: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5041: my $rownum = 0;
5042: my $css_class;
5043: foreach my $type (@pages) {
5044: $rownum ++;
5045: $css_class = $rownum%2?' class="LC_odd_row"':'';
5046: $datatable .= '<tr'.$css_class.'>'.
5047: '<td><span class="LC_nobreak">'.
5048: $titles->{$type}.'</span></td>'.
5049: '<td class="LC_left_item">'.
5050: '<input type="text" name="'.$type.'_namedusers" '.
5051: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5052: '<td class="LC_right_item">'.
5053: '<span class="LC_nobreak">'.
5054: '<input type="text" name="'.$type.'_machines" '.
5055: 'value="'.$machineaccess{$type}.'" size="10" />'.
5056: '</td></tr>'."\n";
5057: }
5058: $$rowtotal += $rownum;
5059: return $datatable;
5060: }
5061:
5062: sub serverstatus_pages {
5063: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5064: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5065: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5066: 'uniquecodes','diskusage');
1.69 raeburn 5067: }
5068:
1.236 raeburn 5069: sub defaults_javascript {
5070: my ($settings) = @_;
5071: my ($output,$jstext);
5072: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5073: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5074: if ($maxnum eq '') {
5075: $maxnum = 0;
5076: }
5077: $maxnum ++;
5078: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5079: return <<"ENDSCRIPT";
5080: <script type="text/javascript">
5081: // <![CDATA[
5082: function reorderTypes(form,caller) {
5083: var changedVal;
5084: $jstext
5085: var newpos = 'addinststatus_pos';
5086: var current = new Array;
5087: var maxh = $maxnum;
5088: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5089: var oldVal;
5090: if (caller == newpos) {
5091: changedVal = newitemVal;
5092: } else {
5093: var curritem = 'inststatus_pos_'+caller;
5094: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5095: current[newitemVal] = newpos;
5096: }
5097: for (var i=0; i<inststatuses.length; i++) {
5098: if (inststatuses[i] != caller) {
5099: var elementName = 'inststatus_pos_'+inststatuses[i];
5100: if (form.elements[elementName]) {
5101: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5102: current[currVal] = elementName;
5103: }
5104: }
5105: }
5106: for (var j=0; j<maxh; j++) {
5107: if (current[j] == undefined) {
5108: oldVal = j;
5109: }
5110: }
5111: if (oldVal < changedVal) {
5112: for (var k=oldVal+1; k<=changedVal ; k++) {
5113: var elementName = current[k];
5114: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5115: }
5116: } else {
5117: for (var k=changedVal; k<oldVal; k++) {
5118: var elementName = current[k];
5119: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5120: }
5121: }
5122: return;
5123: }
5124:
5125: // ]]>
5126: </script>
5127:
5128: ENDSCRIPT
5129: }
5130: }
5131:
1.49 raeburn 5132: sub coursecategories_javascript {
5133: my ($settings) = @_;
1.57 raeburn 5134: my ($output,$jstext,$cathash);
1.49 raeburn 5135: if (ref($settings) eq 'HASH') {
1.57 raeburn 5136: $cathash = $settings->{'cats'};
5137: }
5138: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5139: my (@cats,@jsarray,%idx);
1.57 raeburn 5140: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5141: if (@jsarray > 0) {
5142: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5143: for (my $i=0; $i<@jsarray; $i++) {
5144: if (ref($jsarray[$i]) eq 'ARRAY') {
5145: my $catstr = join('","',@{$jsarray[$i]});
5146: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5147: }
5148: }
5149: }
5150: } else {
5151: $jstext = ' var categories = Array(1);'."\n".
5152: ' categories[0] = Array("instcode_pos");'."\n";
5153: }
1.237 bisitz 5154: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5155: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5156: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5157: $output = <<"ENDSCRIPT";
5158: <script type="text/javascript">
1.109 raeburn 5159: // <![CDATA[
1.49 raeburn 5160: function reorderCats(form,parent,item,idx) {
5161: var changedVal;
5162: $jstext
5163: var newpos = 'addcategory_pos';
5164: if (parent == '') {
5165: var has_instcode = 0;
5166: var maxtop = categories[idx].length;
5167: for (var j=0; j<maxtop; j++) {
5168: if (categories[idx][j] == 'instcode::0') {
5169: has_instcode == 1;
5170: }
5171: }
5172: if (has_instcode == 0) {
5173: categories[idx][maxtop] = 'instcode_pos';
5174: }
5175: } else {
5176: newpos += '_'+parent;
5177: }
5178: var maxh = 1 + categories[idx].length;
5179: var current = new Array;
5180: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5181: if (item == newpos) {
5182: changedVal = newitemVal;
5183: } else {
5184: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5185: current[newitemVal] = newpos;
5186: }
5187: for (var i=0; i<categories[idx].length; i++) {
5188: var elementName = categories[idx][i];
5189: if (elementName != item) {
5190: if (form.elements[elementName]) {
5191: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5192: current[currVal] = elementName;
5193: }
5194: }
5195: }
5196: var oldVal;
5197: for (var j=0; j<maxh; j++) {
5198: if (current[j] == undefined) {
5199: oldVal = j;
5200: }
5201: }
5202: if (oldVal < changedVal) {
5203: for (var k=oldVal+1; k<=changedVal ; k++) {
5204: var elementName = current[k];
5205: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5206: }
5207: } else {
5208: for (var k=changedVal; k<oldVal; k++) {
5209: var elementName = current[k];
5210: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5211: }
5212: }
5213: return;
5214: }
1.120 raeburn 5215:
5216: function categoryCheck(form) {
5217: if (form.elements['addcategory_name'].value == 'instcode') {
5218: alert('$instcode_reserved\\n$choose_again');
5219: return false;
5220: }
5221: if (form.elements['addcategory_name'].value == 'communities') {
5222: alert('$communities_reserved\\n$choose_again');
5223: return false;
5224: }
5225: return true;
5226: }
5227:
1.109 raeburn 5228: // ]]>
1.49 raeburn 5229: </script>
5230:
5231: ENDSCRIPT
5232: return $output;
5233: }
5234:
1.48 raeburn 5235: sub initialize_categories {
5236: my ($itemcount) = @_;
1.120 raeburn 5237: my ($datatable,$css_class,$chgstr);
5238: my %default_names = (
5239: instcode => 'Official courses (with institutional codes)',
5240: communities => 'Communities',
5241: );
5242: my $select0 = ' selected="selected"';
5243: my $select1 = '';
5244: foreach my $default ('instcode','communities') {
5245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5246: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5247: if ($default eq 'communities') {
5248: $select1 = $select0;
5249: $select0 = '';
5250: }
5251: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5252: .'<select name="'.$default.'_pos">'
5253: .'<option value="0"'.$select0.'>1</option>'
5254: .'<option value="1"'.$select1.'>2</option>'
5255: .'<option value="2">3</option></select> '
5256: .$default_names{$default}
5257: .'</span></td><td><span class="LC_nobreak">'
5258: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5259: .&mt('Display').'</label> <label>'
5260: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5261: .'</label></span></td></tr>';
1.120 raeburn 5262: $itemcount ++;
5263: }
1.48 raeburn 5264: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5265: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5266: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5267: .'<select name="addcategory_pos"'.$chgstr.'>'
5268: .'<option value="0">1</option>'
5269: .'<option value="1">2</option>'
5270: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5271: .&mt('Add category').'</td><td>'.&mt('Name:')
5272: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5273: return $datatable;
5274: }
5275:
5276: sub build_category_rows {
1.49 raeburn 5277: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5278: my ($text,$name,$item,$chgstr);
1.48 raeburn 5279: if (ref($cats) eq 'ARRAY') {
5280: my $maxdepth = scalar(@{$cats});
5281: if (ref($cats->[$depth]) eq 'HASH') {
5282: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5283: my $numchildren = @{$cats->[$depth]{$parent}};
5284: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5285: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5286: my ($idxnum,$parent_name,$parent_item);
5287: my $higher = $depth - 1;
5288: if ($higher == 0) {
5289: $parent_name = &escape($parent).'::'.$higher;
5290: } else {
5291: if (ref($path) eq 'ARRAY') {
5292: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5293: }
5294: }
5295: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5296: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5297: if ($j < $numchildren) {
1.48 raeburn 5298: $name = $cats->[$depth]{$parent}[$j];
5299: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5300: $idxnum = $idx->{$item};
5301: } else {
5302: $name = $parent_name;
5303: $item = $parent_item;
1.48 raeburn 5304: }
1.49 raeburn 5305: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5306: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5307: for (my $i=0; $i<=$numchildren; $i++) {
5308: my $vpos = $i+1;
5309: my $selstr;
5310: if ($j == $i) {
5311: $selstr = ' selected="selected" ';
5312: }
5313: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5314: }
5315: $text .= '</select> ';
5316: if ($j < $numchildren) {
5317: my $deeper = $depth+1;
5318: $text .= $name.' '
5319: .'<label><input type="checkbox" name="deletecategory" value="'
5320: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5321: if(ref($path) eq 'ARRAY') {
5322: push(@{$path},$name);
1.49 raeburn 5323: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5324: pop(@{$path});
5325: }
5326: } else {
1.59 bisitz 5327: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5328: if ($j == $numchildren) {
5329: $text .= $name;
5330: } else {
5331: $text .= $item;
5332: }
5333: $text .= '" value="" />';
5334: }
5335: $text .= '</td></tr>';
5336: }
5337: $text .= '</table></td>';
5338: } else {
5339: my $higher = $depth-1;
5340: if ($higher == 0) {
5341: $name = &escape($parent).'::'.$higher;
5342: } else {
5343: if (ref($path) eq 'ARRAY') {
5344: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5345: }
5346: }
5347: my $colspan;
5348: if ($parent ne 'instcode') {
5349: $colspan = $maxdepth - $depth - 1;
5350: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5351: }
5352: }
5353: }
5354: }
5355: return $text;
5356: }
5357:
1.33 raeburn 5358: sub modifiable_userdata_row {
1.228 raeburn 5359: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5360: my ($role,$rolename,$statustype);
5361: $role = $item;
1.224 raeburn 5362: if ($context eq 'cancreate') {
1.228 raeburn 5363: if ($item =~ /^emailusername_(.+)$/) {
5364: $statustype = $1;
5365: $role = 'emailusername';
5366: if (ref($usertypes) eq 'HASH') {
5367: if ($usertypes->{$statustype}) {
5368: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5369: } else {
5370: $rolename = &mt('Data provided by user');
5371: }
5372: }
1.224 raeburn 5373: }
5374: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5375: if (ref($usertypes) eq 'HASH') {
5376: $rolename = $usertypes->{$role};
5377: } else {
5378: $rolename = $role;
5379: }
1.33 raeburn 5380: } else {
1.63 raeburn 5381: if ($role eq 'cr') {
5382: $rolename = &mt('Custom role');
5383: } else {
5384: $rolename = &Apache::lonnet::plaintext($role);
5385: }
1.33 raeburn 5386: }
1.224 raeburn 5387: my (@fields,%fieldtitles);
5388: if (ref($fieldsref) eq 'ARRAY') {
5389: @fields = @{$fieldsref};
5390: } else {
5391: @fields = ('lastname','firstname','middlename','generation',
5392: 'permanentemail','id');
5393: }
5394: if ((ref($titlesref) eq 'HASH')) {
5395: %fieldtitles = %{$titlesref};
5396: } else {
5397: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5398: }
1.33 raeburn 5399: my $output;
5400: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5401: $output = '<tr '.$css_class.'>'.
5402: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5403: '<td class="LC_left_item" colspan="2"><table>';
5404: my $rem;
5405: my %checks;
5406: if (ref($settings) eq 'HASH') {
5407: if (ref($settings->{$context}) eq 'HASH') {
5408: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5409: my $hashref = $settings->{$context}->{$role};
5410: if ($role eq 'emailusername') {
5411: if ($statustype) {
5412: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5413: $hashref = $settings->{$context}->{$role}->{$statustype};
5414: if (ref($hashref) eq 'HASH') {
5415: foreach my $field (@fields) {
5416: if ($hashref->{$field}) {
5417: $checks{$field} = $hashref->{$field};
5418: }
5419: }
5420: }
5421: }
5422: }
5423: } else {
5424: if (ref($hashref) eq 'HASH') {
5425: foreach my $field (@fields) {
5426: if ($hashref->{$field}) {
5427: $checks{$field} = ' checked="checked" ';
5428: }
5429: }
1.33 raeburn 5430: }
5431: }
5432: }
5433: }
5434: }
1.228 raeburn 5435:
1.33 raeburn 5436: for (my $i=0; $i<@fields; $i++) {
5437: my $rem = $i%($numinrow);
5438: if ($rem == 0) {
5439: if ($i > 0) {
5440: $output .= '</tr>';
5441: }
5442: $output .= '<tr>';
5443: }
5444: my $check = ' ';
1.228 raeburn 5445: unless ($role eq 'emailusername') {
5446: if (exists($checks{$fields[$i]})) {
5447: $check = $checks{$fields[$i]}
5448: } else {
5449: if ($role eq 'st') {
5450: if (ref($settings) ne 'HASH') {
5451: $check = ' checked="checked" ';
5452: }
1.33 raeburn 5453: }
5454: }
5455: }
5456: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5457: '<span class="LC_nobreak">';
5458: if ($role eq 'emailusername') {
5459: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5460: $checks{$fields[$i]} = 'omit';
5461: }
5462: foreach my $option ('required','optional','omit') {
5463: my $checked='';
5464: if ($checks{$fields[$i]} eq $option) {
5465: $checked='checked="checked" ';
5466: }
5467: $output .= '<label>'.
5468: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5469: &mt($option).'</label>'.(' ' x2);
5470: }
5471: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5472: } else {
5473: $output .= '<label>'.
5474: '<input type="checkbox" name="canmodify_'.$role.'" '.
5475: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5476: '</label>';
5477: }
5478: $output .= '</span></td>';
1.33 raeburn 5479: $rem = @fields%($numinrow);
5480: }
5481: my $colsleft = $numinrow - $rem;
5482: if ($colsleft > 1 ) {
5483: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5484: ' </td>';
5485: } elsif ($colsleft == 1) {
5486: $output .= '<td class="LC_left_item"> </td>';
5487: }
5488: $output .= '</tr></table></td></tr>';
5489: return $output;
5490: }
1.28 raeburn 5491:
1.93 raeburn 5492: sub insttypes_row {
1.224 raeburn 5493: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5494: my %lt = &Apache::lonlocal::texthash (
5495: cansearch => 'Users allowed to search',
5496: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5497: lockablenames => 'User preference to lock name',
1.93 raeburn 5498: );
5499: my $showdom;
5500: if ($context eq 'cansearch') {
5501: $showdom = ' ('.$dom.')';
5502: }
1.165 raeburn 5503: my $class = 'LC_left_item';
5504: if ($context eq 'statustocreate') {
5505: $class = 'LC_right_item';
5506: }
1.224 raeburn 5507: my $css_class = ' class="LC_odd_row"';
5508: if ($rownum ne '') {
5509: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5510: }
5511: my $output = '<tr'.$css_class.'>'.
5512: '<td>'.$lt{$context}.$showdom.
5513: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5514: my $rem;
5515: if (ref($types) eq 'ARRAY') {
5516: for (my $i=0; $i<@{$types}; $i++) {
5517: if (defined($usertypes->{$types->[$i]})) {
5518: my $rem = $i%($numinrow);
5519: if ($rem == 0) {
5520: if ($i > 0) {
5521: $output .= '</tr>';
5522: }
5523: $output .= '<tr>';
1.23 raeburn 5524: }
1.26 raeburn 5525: my $check = ' ';
1.99 raeburn 5526: if (ref($settings) eq 'HASH') {
5527: if (ref($settings->{$context}) eq 'ARRAY') {
5528: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5529: $check = ' checked="checked" ';
5530: }
5531: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5532: $check = ' checked="checked" ';
5533: }
1.23 raeburn 5534: }
1.26 raeburn 5535: $output .= '<td class="LC_left_item">'.
5536: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5537: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5538: 'value="'.$types->[$i].'"'.$check.'/>'.
5539: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5540: }
5541: }
1.26 raeburn 5542: $rem = @{$types}%($numinrow);
1.23 raeburn 5543: }
5544: my $colsleft = $numinrow - $rem;
1.131 raeburn 5545: if (($rem == 0) && (@{$types} > 0)) {
5546: $output .= '<tr>';
5547: }
1.23 raeburn 5548: if ($colsleft > 1) {
1.25 raeburn 5549: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5550: } else {
1.25 raeburn 5551: $output .= '<td class="LC_left_item">';
1.23 raeburn 5552: }
5553: my $defcheck = ' ';
1.99 raeburn 5554: if (ref($settings) eq 'HASH') {
5555: if (ref($settings->{$context}) eq 'ARRAY') {
5556: if (grep(/^default$/,@{$settings->{$context}})) {
5557: $defcheck = ' checked="checked" ';
5558: }
5559: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5560: $defcheck = ' checked="checked" ';
5561: }
1.23 raeburn 5562: }
1.25 raeburn 5563: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5564: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5565: 'value="default"'.$defcheck.'/>'.
5566: $othertitle.'</label></span></td>'.
5567: '</tr></table></td></tr>';
5568: return $output;
1.23 raeburn 5569: }
5570:
5571: sub sorted_searchtitles {
5572: my %searchtitles = &Apache::lonlocal::texthash(
5573: 'uname' => 'username',
5574: 'lastname' => 'last name',
5575: 'lastfirst' => 'last name, first name',
5576: );
5577: my @titleorder = ('uname','lastname','lastfirst');
5578: return (\%searchtitles,\@titleorder);
5579: }
5580:
1.25 raeburn 5581: sub sorted_searchtypes {
5582: my %srchtypes_desc = (
5583: exact => 'is exact match',
5584: contains => 'contains ..',
5585: begins => 'begins with ..',
5586: );
5587: my @srchtypeorder = ('exact','begins','contains');
5588: return (\%srchtypes_desc,\@srchtypeorder);
5589: }
5590:
1.3 raeburn 5591: sub usertype_update_row {
5592: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5593: my $datatable;
5594: my $numinrow = 4;
5595: foreach my $type (@{$types}) {
5596: if (defined($usertypes->{$type})) {
5597: $$rownums ++;
5598: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5599: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5600: '</td><td class="LC_left_item"><table>';
5601: for (my $i=0; $i<@{$fields}; $i++) {
5602: my $rem = $i%($numinrow);
5603: if ($rem == 0) {
5604: if ($i > 0) {
5605: $datatable .= '</tr>';
5606: }
5607: $datatable .= '<tr>';
5608: }
5609: my $check = ' ';
1.39 raeburn 5610: if (ref($settings) eq 'HASH') {
5611: if (ref($settings->{'fields'}) eq 'HASH') {
5612: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5613: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5614: $check = ' checked="checked" ';
5615: }
1.3 raeburn 5616: }
5617: }
5618: }
5619:
5620: if ($i == @{$fields}-1) {
5621: my $colsleft = $numinrow - $rem;
5622: if ($colsleft > 1) {
5623: $datatable .= '<td colspan="'.$colsleft.'">';
5624: } else {
5625: $datatable .= '<td>';
5626: }
5627: } else {
5628: $datatable .= '<td>';
5629: }
1.8 raeburn 5630: $datatable .= '<span class="LC_nobreak"><label>'.
5631: '<input type="checkbox" name="updateable_'.$type.
5632: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5633: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5634: }
5635: $datatable .= '</tr></table></td></tr>';
5636: }
5637: }
5638: return $datatable;
1.1 raeburn 5639: }
5640:
5641: sub modify_login {
1.205 raeburn 5642: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5643: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5644: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5645: %title = ( coursecatalog => 'Display course catalog',
5646: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5647: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5648: newuser => 'Link for visitors to create a user account',
5649: loginheader => 'Log-in box header');
5650: @offon = ('off','on');
1.112 raeburn 5651: if (ref($domconfig{login}) eq 'HASH') {
5652: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5653: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5654: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5655: }
5656: }
5657: }
1.9 raeburn 5658: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5659: \%domconfig,\%loginhash);
1.188 raeburn 5660: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5661: foreach my $item (@toggles) {
5662: $loginhash{login}{$item} = $env{'form.'.$item};
5663: }
1.41 raeburn 5664: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5665: if (ref($colchanges{'login'}) eq 'HASH') {
5666: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5667: \%loginhash);
5668: }
1.110 raeburn 5669:
1.149 raeburn 5670: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5671: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5672: if (keys(%servers) > 1) {
5673: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5674: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5675: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5676: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5677: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5678: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5679: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5680: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5681: $changes{'loginvia'}{$lonhost} = 1;
5682: } else {
5683: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5684: $changes{'loginvia'}{$lonhost} = 1;
5685: }
5686: } else {
5687: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5688: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5689: $changes{'loginvia'}{$lonhost} = 1;
5690: }
5691: }
5692: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5693: foreach my $item (@loginvia_attribs) {
5694: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5695: }
5696: } else {
5697: foreach my $item (@loginvia_attribs) {
5698: my $new = $env{'form.'.$lonhost.'_'.$item};
5699: if (($item eq 'serverpath') && ($new eq 'custom')) {
5700: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5701: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5702: $new = '/';
5703: }
5704: }
5705: if (($item eq 'custompath') &&
5706: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5707: $new = '';
5708: }
5709: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5710: $changes{'loginvia'}{$lonhost} = 1;
5711: }
5712: if ($item eq 'exempt') {
5713: $new =~ s/^\s+//;
5714: $new =~ s/\s+$//;
5715: my @poss_ips = split(/\s*[,:]\s*/,$new);
5716: my @okips;
5717: foreach my $ip (@poss_ips) {
5718: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5719: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5720: push(@okips,$ip);
5721: }
5722: }
5723: }
5724: if (@okips > 0) {
5725: $new = join(',',@okips);
5726: } else {
5727: $new = '';
5728: }
5729: }
5730: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5731: }
5732: }
1.112 raeburn 5733: } else {
1.128 raeburn 5734: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5735: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5736: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5737: foreach my $item (@loginvia_attribs) {
5738: my $new = $env{'form.'.$lonhost.'_'.$item};
5739: if (($item eq 'serverpath') && ($new eq 'custom')) {
5740: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5741: $new = '/';
5742: }
5743: }
5744: if (($item eq 'custompath') &&
5745: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5746: $new = '';
5747: }
5748: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5749: }
1.110 raeburn 5750: }
5751: }
5752: }
5753: }
1.119 raeburn 5754:
1.168 raeburn 5755: my $servadm = $r->dir_config('lonAdmEMail');
5756: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5757: if (ref($domconfig{'login'}) eq 'HASH') {
5758: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5759: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5760: if ($lang eq 'nolang') {
5761: push(@currlangs,$lang);
5762: } elsif (defined($langchoices{$lang})) {
5763: push(@currlangs,$lang);
5764: } else {
5765: next;
5766: }
5767: }
5768: }
5769: }
5770: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5771: if (@currlangs > 0) {
5772: foreach my $lang (@currlangs) {
5773: if (grep(/^\Q$lang\E$/,@delurls)) {
5774: $changes{'helpurl'}{$lang} = 1;
5775: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5776: $changes{'helpurl'}{$lang} = 1;
5777: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5778: push(@newlangs,$lang);
5779: } else {
5780: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5781: }
5782: }
5783: }
5784: unless (grep(/^nolang$/,@currlangs)) {
5785: if ($env{'form.loginhelpurl_nolang.filename'}) {
5786: $changes{'helpurl'}{'nolang'} = 1;
5787: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5788: push(@newlangs,'nolang');
5789: }
5790: }
5791: if ($env{'form.loginhelpurl_add_lang'}) {
5792: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5793: ($env{'form.loginhelpurl_add_file.filename'})) {
5794: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5795: $addedfile = $env{'form.loginhelpurl_add_lang'};
5796: }
5797: }
5798: if ((@newlangs > 0) || ($addedfile)) {
5799: my $error;
5800: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5801: if ($configuserok eq 'ok') {
5802: if ($switchserver) {
5803: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5804: } elsif ($author_ok eq 'ok') {
5805: my @allnew = @newlangs;
5806: if ($addedfile ne '') {
5807: push(@allnew,$addedfile);
5808: }
5809: foreach my $lang (@allnew) {
5810: my $formelem = 'loginhelpurl_'.$lang;
5811: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5812: $formelem = 'loginhelpurl_add_file';
5813: }
5814: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5815: "help/$lang",'','',$newfile{$lang});
5816: if ($result eq 'ok') {
5817: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5818: $changes{'helpurl'}{$lang} = 1;
5819: } else {
5820: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5821: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5822: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5823: (!grep(/^\Q$lang\E$/,@delurls))) {
5824:
5825: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5826: }
5827: }
5828: }
5829: } else {
5830: $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);
5831: }
5832: } else {
5833: $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);
5834: }
5835: if ($error) {
5836: &Apache::lonnet::logthis($error);
5837: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5838: }
5839: }
1.169 raeburn 5840: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5841:
5842: my $defaulthelpfile = '/adm/loginproblems.html';
5843: my $defaulttext = &mt('Default in use');
5844:
1.1 raeburn 5845: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5846: $dom);
5847: if ($putresult eq 'ok') {
1.188 raeburn 5848: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5849: my %defaultchecked = (
5850: 'coursecatalog' => 'on',
1.188 raeburn 5851: 'helpdesk' => 'on',
1.42 raeburn 5852: 'adminmail' => 'off',
1.43 raeburn 5853: 'newuser' => 'off',
1.42 raeburn 5854: );
1.55 raeburn 5855: if (ref($domconfig{'login'}) eq 'HASH') {
5856: foreach my $item (@toggles) {
5857: if ($defaultchecked{$item} eq 'on') {
5858: if (($domconfig{'login'}{$item} eq '0') &&
5859: ($env{'form.'.$item} eq '1')) {
5860: $changes{$item} = 1;
5861: } elsif (($domconfig{'login'}{$item} eq '' ||
5862: $domconfig{'login'}{$item} eq '1') &&
5863: ($env{'form.'.$item} eq '0')) {
5864: $changes{$item} = 1;
5865: }
5866: } elsif ($defaultchecked{$item} eq 'off') {
5867: if (($domconfig{'login'}{$item} eq '1') &&
5868: ($env{'form.'.$item} eq '0')) {
5869: $changes{$item} = 1;
5870: } elsif (($domconfig{'login'}{$item} eq '' ||
5871: $domconfig{'login'}{$item} eq '0') &&
5872: ($env{'form.'.$item} eq '1')) {
5873: $changes{$item} = 1;
5874: }
1.42 raeburn 5875: }
5876: }
1.41 raeburn 5877: }
1.6 raeburn 5878: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5879: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5880: if (ref($lastactref) eq 'HASH') {
5881: $lastactref->{'domainconfig'} = 1;
5882: }
1.1 raeburn 5883: $resulttext = &mt('Changes made:').'<ul>';
5884: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5885: if ($item eq 'loginvia') {
1.112 raeburn 5886: if (ref($changes{$item}) eq 'HASH') {
5887: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5888: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5889: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5890: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5891: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5892: $protocol = 'http' if ($protocol ne 'https');
5893: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5894:
5895: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5896: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5897: } else {
5898: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5899: }
5900: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5901: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5902: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5903: }
5904: $resulttext .= '</li>';
5905: } else {
5906: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5907: }
1.112 raeburn 5908: } else {
1.128 raeburn 5909: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5910: }
5911: }
1.128 raeburn 5912: $resulttext .= '</ul></li>';
1.112 raeburn 5913: }
1.168 raeburn 5914: } elsif ($item eq 'helpurl') {
5915: if (ref($changes{$item}) eq 'HASH') {
5916: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5917: if (grep(/^\Q$lang\E$/,@delurls)) {
5918: my ($chg,$link);
5919: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5920: if ($lang eq 'nolang') {
5921: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5922: } else {
5923: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5924: }
5925: $resulttext .= '<li>'.$chg.'</li>';
5926: } else {
5927: my $chg;
5928: if ($lang eq 'nolang') {
5929: $chg = &mt('custom log-in help file for no preferred language');
5930: } else {
5931: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5932: }
5933: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5934: $loginhash{'login'}{'helpurl'}{$lang}.
5935: '?inhibitmenu=yes',$chg,600,500).
5936: '</li>';
5937: }
5938: }
5939: }
1.169 raeburn 5940: } elsif ($item eq 'captcha') {
5941: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5942: my $chgtxt;
1.169 raeburn 5943: if ($loginhash{'login'}{$item} eq 'notused') {
5944: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5945: } else {
5946: my %captchas = &captcha_phrases();
5947: if ($captchas{$loginhash{'login'}{$item}}) {
5948: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5949: } else {
5950: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5951: }
5952: }
5953: $resulttext .= '<li>'.$chgtxt.'</li>';
5954: }
5955: } elsif ($item eq 'recaptchakeys') {
5956: if (ref($loginhash{'login'}) eq 'HASH') {
5957: my ($privkey,$pubkey);
5958: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5959: $pubkey = $loginhash{'login'}{$item}{'public'};
5960: $privkey = $loginhash{'login'}{$item}{'private'};
5961: }
5962: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5963: if (!$pubkey) {
5964: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5965: } else {
5966: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5967: }
5968: if (!$privkey) {
5969: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5970: } else {
5971: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5972: }
5973: $chgtxt .= '</ul>';
5974: $resulttext .= '<li>'.$chgtxt.'</li>';
5975: }
1.41 raeburn 5976: } else {
5977: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5978: }
1.1 raeburn 5979: }
1.6 raeburn 5980: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5981: } else {
5982: $resulttext = &mt('No changes made to log-in page settings');
5983: }
5984: } else {
1.11 albertel 5985: $resulttext = '<span class="LC_error">'.
5986: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5987: }
1.6 raeburn 5988: if ($errors) {
1.9 raeburn 5989: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5990: $errors.'</ul>';
5991: }
5992: return $resulttext;
5993: }
5994:
5995: sub color_font_choices {
5996: my %choices =
5997: &Apache::lonlocal::texthash (
5998: img => "Header",
5999: bgs => "Background colors",
6000: links => "Link colors",
1.55 raeburn 6001: images => "Images",
1.6 raeburn 6002: font => "Font color",
1.201 raeburn 6003: fontmenu => "Font menu",
1.76 raeburn 6004: pgbg => "Page",
1.6 raeburn 6005: tabbg => "Header",
6006: sidebg => "Border",
6007: link => "Link",
6008: alink => "Active link",
6009: vlink => "Visited link",
6010: );
6011: return %choices;
6012: }
6013:
6014: sub modify_rolecolors {
1.205 raeburn 6015: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6016: my ($resulttext,%rolehash);
6017: $rolehash{'rolecolors'} = {};
1.55 raeburn 6018: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6019: if ($domconfig{'rolecolors'} eq '') {
6020: $domconfig{'rolecolors'} = {};
6021: }
6022: }
1.9 raeburn 6023: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6024: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6025: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6026: $dom);
6027: if ($putresult eq 'ok') {
6028: if (keys(%changes) > 0) {
1.41 raeburn 6029: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6030: if (ref($lastactref) eq 'HASH') {
6031: $lastactref->{'domainconfig'} = 1;
6032: }
1.6 raeburn 6033: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6034: $rolehash{'rolecolors'});
6035: } else {
6036: $resulttext = &mt('No changes made to default color schemes');
6037: }
6038: } else {
1.11 albertel 6039: $resulttext = '<span class="LC_error">'.
6040: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6041: }
6042: if ($errors) {
6043: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6044: $errors.'</ul>';
6045: }
6046: return $resulttext;
6047: }
6048:
6049: sub modify_colors {
1.9 raeburn 6050: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6051: my (%changes,%choices);
1.51 raeburn 6052: my @bgs;
1.6 raeburn 6053: my @links = ('link','alink','vlink');
1.41 raeburn 6054: my @logintext;
1.6 raeburn 6055: my @images;
6056: my $servadm = $r->dir_config('lonAdmEMail');
6057: my $errors;
1.200 raeburn 6058: my %defaults;
1.6 raeburn 6059: foreach my $role (@{$roles}) {
6060: if ($role eq 'login') {
1.12 raeburn 6061: %choices = &login_choices();
1.41 raeburn 6062: @logintext = ('textcol','bgcol');
1.12 raeburn 6063: } else {
6064: %choices = &color_font_choices();
6065: }
6066: if ($role eq 'login') {
1.41 raeburn 6067: @images = ('img','logo','domlogo','login');
1.51 raeburn 6068: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6069: } else {
6070: @images = ('img');
1.200 raeburn 6071: @bgs = ('pgbg','tabbg','sidebg');
6072: }
6073: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6074: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6075: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6076: }
6077: if ($role eq 'login') {
6078: foreach my $item (@logintext) {
1.234 raeburn 6079: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6080: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6081: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6082: }
6083: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6084: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6085: }
6086: }
6087: } else {
1.234 raeburn 6088: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6089: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6090: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6091: }
6092: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6093: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6094: }
1.6 raeburn 6095: }
1.200 raeburn 6096: foreach my $item (@bgs) {
1.234 raeburn 6097: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6098: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6099: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6100: }
6101: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6102: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6103: }
6104: }
6105: foreach my $item (@links) {
1.234 raeburn 6106: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6107: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6108: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6109: }
6110: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6111: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6112: }
1.6 raeburn 6113: }
1.46 raeburn 6114: my ($configuserok,$author_ok,$switchserver) =
6115: &config_check($dom,$confname,$servadm);
1.9 raeburn 6116: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6117: if (ref($domconfig->{$role}) ne 'HASH') {
6118: $domconfig->{$role} = {};
6119: }
1.8 raeburn 6120: foreach my $img (@images) {
1.70 raeburn 6121: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6122: if (defined($env{'form.login_showlogo_'.$img})) {
6123: $confhash->{$role}{'showlogo'}{$img} = 1;
6124: } else {
6125: $confhash->{$role}{'showlogo'}{$img} = 0;
6126: }
6127: }
1.18 albertel 6128: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6129: && !defined($domconfig->{$role}{$img})
6130: && !$env{'form.'.$role.'_del_'.$img}
6131: && $env{'form.'.$role.'_import_'.$img}) {
6132: # import the old configured image from the .tab setting
6133: # if they haven't provided a new one
6134: $domconfig->{$role}{$img} =
6135: $env{'form.'.$role.'_import_'.$img};
6136: }
1.6 raeburn 6137: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6138: my $error;
1.6 raeburn 6139: if ($configuserok eq 'ok') {
1.9 raeburn 6140: if ($switchserver) {
1.12 raeburn 6141: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6142: } else {
6143: if ($author_ok eq 'ok') {
6144: my ($result,$logourl) =
6145: &publishlogo($r,'upload',$role.'_'.$img,
6146: $dom,$confname,$img,$width,$height);
6147: if ($result eq 'ok') {
6148: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6149: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6150: } else {
1.12 raeburn 6151: $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 6152: }
6153: } else {
1.46 raeburn 6154: $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 6155: }
6156: }
6157: } else {
1.46 raeburn 6158: $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 6159: }
6160: if ($error) {
1.8 raeburn 6161: &Apache::lonnet::logthis($error);
1.11 albertel 6162: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6163: }
6164: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6165: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6166: my $error;
6167: if ($configuserok eq 'ok') {
6168: # is confname an author?
6169: if ($switchserver eq '') {
6170: if ($author_ok eq 'ok') {
6171: my ($result,$logourl) =
6172: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6173: $dom,$confname,$img,$width,$height);
6174: if ($result eq 'ok') {
6175: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6176: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6177: }
6178: }
6179: }
6180: }
1.6 raeburn 6181: }
6182: }
6183: }
6184: if (ref($domconfig) eq 'HASH') {
6185: if (ref($domconfig->{$role}) eq 'HASH') {
6186: foreach my $img (@images) {
6187: if ($domconfig->{$role}{$img} ne '') {
6188: if ($env{'form.'.$role.'_del_'.$img}) {
6189: $confhash->{$role}{$img} = '';
1.12 raeburn 6190: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6191: } else {
1.9 raeburn 6192: if ($confhash->{$role}{$img} eq '') {
6193: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6194: }
1.6 raeburn 6195: }
6196: } else {
6197: if ($env{'form.'.$role.'_del_'.$img}) {
6198: $confhash->{$role}{$img} = '';
1.12 raeburn 6199: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6200: }
6201: }
1.70 raeburn 6202: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6203: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6204: if ($confhash->{$role}{'showlogo'}{$img} ne
6205: $domconfig->{$role}{'showlogo'}{$img}) {
6206: $changes{$role}{'showlogo'}{$img} = 1;
6207: }
6208: } else {
6209: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6210: $changes{$role}{'showlogo'}{$img} = 1;
6211: }
6212: }
6213: }
6214: }
1.6 raeburn 6215: if ($domconfig->{$role}{'font'} ne '') {
6216: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6217: $changes{$role}{'font'} = 1;
6218: }
6219: } else {
6220: if ($confhash->{$role}{'font'}) {
6221: $changes{$role}{'font'} = 1;
6222: }
6223: }
1.107 raeburn 6224: if ($role ne 'login') {
6225: if ($domconfig->{$role}{'fontmenu'} ne '') {
6226: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6227: $changes{$role}{'fontmenu'} = 1;
6228: }
6229: } else {
6230: if ($confhash->{$role}{'fontmenu'}) {
6231: $changes{$role}{'fontmenu'} = 1;
6232: }
1.97 tempelho 6233: }
6234: }
1.6 raeburn 6235: foreach my $item (@bgs) {
6236: if ($domconfig->{$role}{$item} ne '') {
6237: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6238: $changes{$role}{'bgs'}{$item} = 1;
6239: }
6240: } else {
6241: if ($confhash->{$role}{$item}) {
6242: $changes{$role}{'bgs'}{$item} = 1;
6243: }
6244: }
6245: }
6246: foreach my $item (@links) {
6247: if ($domconfig->{$role}{$item} ne '') {
6248: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6249: $changes{$role}{'links'}{$item} = 1;
6250: }
6251: } else {
6252: if ($confhash->{$role}{$item}) {
6253: $changes{$role}{'links'}{$item} = 1;
6254: }
6255: }
6256: }
1.41 raeburn 6257: foreach my $item (@logintext) {
6258: if ($domconfig->{$role}{$item} ne '') {
6259: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6260: $changes{$role}{'logintext'}{$item} = 1;
6261: }
6262: } else {
6263: if ($confhash->{$role}{$item}) {
6264: $changes{$role}{'logintext'}{$item} = 1;
6265: }
6266: }
6267: }
1.6 raeburn 6268: } else {
6269: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6270: \@logintext,$confhash,\%changes);
1.6 raeburn 6271: }
6272: } else {
6273: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6274: \@logintext,$confhash,\%changes);
1.6 raeburn 6275: }
6276: }
6277: return ($errors,%changes);
6278: }
6279:
1.46 raeburn 6280: sub config_check {
6281: my ($dom,$confname,$servadm) = @_;
6282: my ($configuserok,$author_ok,$switchserver,%currroles);
6283: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6284: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6285: $confname,$servadm);
6286: if ($configuserok eq 'ok') {
6287: $switchserver = &check_switchserver($dom,$confname);
6288: if ($switchserver eq '') {
6289: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6290: }
6291: }
6292: return ($configuserok,$author_ok,$switchserver);
6293: }
6294:
1.6 raeburn 6295: sub default_change_checker {
1.41 raeburn 6296: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6297: foreach my $item (@{$links}) {
6298: if ($confhash->{$role}{$item}) {
6299: $changes->{$role}{'links'}{$item} = 1;
6300: }
6301: }
6302: foreach my $item (@{$bgs}) {
6303: if ($confhash->{$role}{$item}) {
6304: $changes->{$role}{'bgs'}{$item} = 1;
6305: }
6306: }
1.41 raeburn 6307: foreach my $item (@{$logintext}) {
6308: if ($confhash->{$role}{$item}) {
6309: $changes->{$role}{'logintext'}{$item} = 1;
6310: }
6311: }
1.6 raeburn 6312: foreach my $img (@{$images}) {
6313: if ($env{'form.'.$role.'_del_'.$img}) {
6314: $confhash->{$role}{$img} = '';
1.12 raeburn 6315: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6316: }
1.70 raeburn 6317: if ($role eq 'login') {
6318: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6319: $changes->{$role}{'showlogo'}{$img} = 1;
6320: }
6321: }
1.6 raeburn 6322: }
6323: if ($confhash->{$role}{'font'}) {
6324: $changes->{$role}{'font'} = 1;
6325: }
1.48 raeburn 6326: }
1.6 raeburn 6327:
6328: sub display_colorchgs {
6329: my ($dom,$changes,$roles,$confhash) = @_;
6330: my (%choices,$resulttext);
6331: if (!grep(/^login$/,@{$roles})) {
6332: $resulttext = &mt('Changes made:').'<br />';
6333: }
6334: foreach my $role (@{$roles}) {
6335: if ($role eq 'login') {
6336: %choices = &login_choices();
6337: } else {
6338: %choices = &color_font_choices();
6339: }
6340: if (ref($changes->{$role}) eq 'HASH') {
6341: if ($role ne 'login') {
6342: $resulttext .= '<h4>'.&mt($role).'</h4>';
6343: }
6344: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6345: if ($role ne 'login') {
6346: $resulttext .= '<ul>';
6347: }
6348: if (ref($changes->{$role}{$key}) eq 'HASH') {
6349: if ($role ne 'login') {
6350: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6351: }
6352: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6353: if (($role eq 'login') && ($key eq 'showlogo')) {
6354: if ($confhash->{$role}{$key}{$item}) {
6355: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6356: } else {
6357: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6358: }
6359: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6360: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6361: } else {
1.12 raeburn 6362: my $newitem = $confhash->{$role}{$item};
6363: if ($key eq 'images') {
6364: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6365: }
6366: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6367: }
6368: }
6369: if ($role ne 'login') {
6370: $resulttext .= '</ul></li>';
6371: }
6372: } else {
6373: if ($confhash->{$role}{$key} eq '') {
6374: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6375: } else {
6376: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6377: }
6378: }
6379: if ($role ne 'login') {
6380: $resulttext .= '</ul>';
6381: }
6382: }
6383: }
6384: }
1.3 raeburn 6385: return $resulttext;
1.1 raeburn 6386: }
6387:
1.9 raeburn 6388: sub thumb_dimensions {
6389: return ('200','50');
6390: }
6391:
1.16 raeburn 6392: sub check_dimensions {
6393: my ($inputfile) = @_;
6394: my ($fullwidth,$fullheight);
6395: if ($inputfile =~ m|^[/\w.\-]+$|) {
6396: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6397: my $imageinfo = <PIPE>;
6398: if (!close(PIPE)) {
6399: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6400: }
6401: chomp($imageinfo);
6402: my ($fullsize) =
1.21 raeburn 6403: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6404: if ($fullsize) {
6405: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6406: }
6407: }
6408: }
6409: return ($fullwidth,$fullheight);
6410: }
6411:
1.9 raeburn 6412: sub check_configuser {
6413: my ($uhome,$dom,$confname,$servadm) = @_;
6414: my ($configuserok,%currroles);
6415: if ($uhome eq 'no_host') {
6416: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6417: my $configpass = &LONCAPA::Enrollment::create_password();
6418: $configuserok =
6419: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6420: $configpass,'','','','','',undef,$servadm);
6421: } else {
6422: $configuserok = 'ok';
6423: %currroles =
6424: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6425: }
6426: return ($configuserok,%currroles);
6427: }
6428:
6429: sub check_authorstatus {
6430: my ($dom,$confname,%currroles) = @_;
6431: my $author_ok;
1.40 raeburn 6432: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6433: my $start = time;
6434: my $end = 0;
6435: $author_ok =
6436: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6437: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6438: } else {
6439: $author_ok = 'ok';
6440: }
6441: return $author_ok;
6442: }
6443:
6444: sub publishlogo {
1.46 raeburn 6445: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6446: my ($output,$fname,$logourl);
6447: if ($action eq 'upload') {
6448: $fname=$env{'form.'.$formname.'.filename'};
6449: chop($env{'form.'.$formname});
6450: } else {
6451: ($fname) = ($formname =~ /([^\/]+)$/);
6452: }
1.46 raeburn 6453: if ($savefileas ne '') {
6454: $fname = $savefileas;
6455: }
1.9 raeburn 6456: $fname=&Apache::lonnet::clean_filename($fname);
6457: # See if there is anything left
6458: unless ($fname) { return ('error: no uploaded file'); }
6459: $fname="$subdir/$fname";
1.210 raeburn 6460: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6461: my $filepath="$docroot/priv";
6462: my $relpath = "$dom/$confname";
1.9 raeburn 6463: my ($fnamepath,$file,$fetchthumb);
6464: $file=$fname;
6465: if ($fname=~m|/|) {
6466: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6467: }
1.164 raeburn 6468: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6469: my $count;
1.164 raeburn 6470: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6471: $filepath.="/$parts[$count]";
6472: if ((-e $filepath)!=1) {
6473: mkdir($filepath,02770);
6474: }
6475: }
6476: # Check for bad extension and disallow upload
6477: if ($file=~/\.(\w+)$/ &&
6478: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6479: $output =
1.207 bisitz 6480: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6481: } elsif ($file=~/\.(\w+)$/ &&
6482: !defined(&Apache::loncommon::fileembstyle($1))) {
6483: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6484: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6485: $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 6486: } elsif (-d "$filepath/$file") {
1.195 bisitz 6487: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6488: } else {
6489: my $source = $filepath.'/'.$file;
6490: my $logfile;
6491: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6492: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6493: }
6494: print $logfile
6495: "\n================= Publish ".localtime()." ================\n".
6496: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6497: # Save the file
6498: if (!open(FH,'>'.$source)) {
6499: &Apache::lonnet::logthis('Failed to create '.$source);
6500: return (&mt('Failed to create file'));
6501: }
6502: if ($action eq 'upload') {
6503: if (!print FH ($env{'form.'.$formname})) {
6504: &Apache::lonnet::logthis('Failed to write to '.$source);
6505: return (&mt('Failed to write file'));
6506: }
6507: } else {
6508: my $original = &Apache::lonnet::filelocation('',$formname);
6509: if(!copy($original,$source)) {
6510: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6511: return (&mt('Failed to write file'));
6512: }
6513: }
6514: close(FH);
6515: chmod(0660, $source); # Permissions to rw-rw---.
6516:
6517: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6518: my $copyfile=$targetdir.'/'.$file;
6519:
6520: my @parts=split(/\//,$targetdir);
6521: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6522: for (my $count=5;$count<=$#parts;$count++) {
6523: $path.="/$parts[$count]";
6524: if (!-e $path) {
6525: print $logfile "\nCreating directory ".$path;
6526: mkdir($path,02770);
6527: }
6528: }
6529: my $versionresult;
6530: if (-e $copyfile) {
6531: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6532: } else {
6533: $versionresult = 'ok';
6534: }
6535: if ($versionresult eq 'ok') {
6536: if (copy($source,$copyfile)) {
6537: print $logfile "\nCopied original source to ".$copyfile."\n";
6538: $output = 'ok';
6539: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6540: push(@{$modified_urls},[$copyfile,$source]);
6541: my $metaoutput =
6542: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6543: unless ($registered_cleanup) {
6544: my $handlers = $r->get_handlers('PerlCleanupHandler');
6545: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6546: $registered_cleanup=1;
6547: }
1.9 raeburn 6548: } else {
6549: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6550: $output = &mt('Failed to copy file to RES space').", $!";
6551: }
6552: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6553: my $inputfile = $filepath.'/'.$file;
6554: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6555: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6556: if ($fullwidth ne '' && $fullheight ne '') {
6557: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6558: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6559: system("convert -sample $thumbsize $inputfile $outfile");
6560: chmod(0660, $filepath.'/tn-'.$file);
6561: if (-e $outfile) {
6562: my $copyfile=$targetdir.'/tn-'.$file;
6563: if (copy($outfile,$copyfile)) {
6564: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6565: my $thumb_metaoutput =
6566: &write_metadata($dom,$confname,$formname,
6567: $targetdir,'tn-'.$file,$logfile);
6568: push(@{$modified_urls},[$copyfile,$outfile]);
6569: unless ($registered_cleanup) {
6570: my $handlers = $r->get_handlers('PerlCleanupHandler');
6571: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6572: $registered_cleanup=1;
6573: }
1.16 raeburn 6574: } else {
6575: print $logfile "\nUnable to write ".$copyfile.
6576: ':'.$!."\n";
6577: }
6578: }
1.9 raeburn 6579: }
6580: }
6581: }
6582: } else {
6583: $output = $versionresult;
6584: }
6585: }
6586: return ($output,$logourl);
6587: }
6588:
6589: sub logo_versioning {
6590: my ($targetdir,$file,$logfile) = @_;
6591: my $target = $targetdir.'/'.$file;
6592: my ($maxversion,$fn,$extn,$output);
6593: $maxversion = 0;
6594: if ($file =~ /^(.+)\.(\w+)$/) {
6595: $fn=$1;
6596: $extn=$2;
6597: }
6598: opendir(DIR,$targetdir);
6599: while (my $filename=readdir(DIR)) {
6600: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6601: $maxversion=($1>$maxversion)?$1:$maxversion;
6602: }
6603: }
6604: $maxversion++;
6605: print $logfile "\nCreating old version ".$maxversion."\n";
6606: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6607: if (copy($target,$copyfile)) {
6608: print $logfile "Copied old target to ".$copyfile."\n";
6609: $copyfile=$copyfile.'.meta';
6610: if (copy($target.'.meta',$copyfile)) {
6611: print $logfile "Copied old target metadata to ".$copyfile."\n";
6612: $output = 'ok';
6613: } else {
6614: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6615: $output = &mt('Failed to copy old meta').", $!, ";
6616: }
6617: } else {
6618: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6619: $output = &mt('Failed to copy old target').", $!, ";
6620: }
6621: return $output;
6622: }
6623:
6624: sub write_metadata {
6625: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6626: my (%metadatafields,%metadatakeys,$output);
6627: $metadatafields{'title'}=$formname;
6628: $metadatafields{'creationdate'}=time;
6629: $metadatafields{'lastrevisiondate'}=time;
6630: $metadatafields{'copyright'}='public';
6631: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6632: $env{'user.domain'};
6633: $metadatafields{'authorspace'}=$confname.':'.$dom;
6634: $metadatafields{'domain'}=$dom;
6635: {
6636: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6637: my $mfh;
1.155 raeburn 6638: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6639: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6640: unless ($_=~/\./) {
6641: my $unikey=$_;
6642: $unikey=~/^([A-Za-z]+)/;
6643: my $tag=$1;
6644: $tag=~tr/A-Z/a-z/;
6645: print $mfh "\n\<$tag";
6646: foreach (split(/\,/,$metadatakeys{$unikey})) {
6647: my $value=$metadatafields{$unikey.'.'.$_};
6648: $value=~s/\"/\'\'/g;
6649: print $mfh ' '.$_.'="'.$value.'"';
6650: }
6651: print $mfh '>'.
6652: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6653: .'</'.$tag.'>';
6654: }
6655: }
6656: $output = 'ok';
6657: print $logfile "\nWrote metadata";
6658: close($mfh);
6659: } else {
6660: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6661: $output = &mt('Could not write metadata');
6662: }
6663: }
1.155 raeburn 6664: return $output;
6665: }
6666:
6667: sub notifysubscribed {
6668: foreach my $targetsource (@{$modified_urls}){
6669: next unless (ref($targetsource) eq 'ARRAY');
6670: my ($target,$source)=@{$targetsource};
6671: if ($source ne '') {
6672: if (open(my $logfh,'>>'.$source.'.log')) {
6673: print $logfh "\nCleanup phase: Notifications\n";
6674: my @subscribed=&subscribed_hosts($target);
6675: foreach my $subhost (@subscribed) {
6676: print $logfh "\nNotifying host ".$subhost.':';
6677: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6678: print $logfh $reply;
6679: }
6680: my @subscribedmeta=&subscribed_hosts("$target.meta");
6681: foreach my $subhost (@subscribedmeta) {
6682: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6683: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6684: $subhost);
6685: print $logfh $reply;
6686: }
6687: print $logfh "\n============ Done ============\n";
1.160 raeburn 6688: close($logfh);
1.155 raeburn 6689: }
6690: }
6691: }
6692: return OK;
6693: }
6694:
6695: sub subscribed_hosts {
6696: my ($target) = @_;
6697: my @subscribed;
6698: if (open(my $fh,"<$target.subscription")) {
6699: while (my $subline=<$fh>) {
6700: if ($subline =~ /^($match_lonid):/) {
6701: my $host = $1;
6702: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6703: unless (grep(/^\Q$host\E$/,@subscribed)) {
6704: push(@subscribed,$host);
6705: }
6706: }
6707: }
6708: }
6709: }
6710: return @subscribed;
1.9 raeburn 6711: }
6712:
6713: sub check_switchserver {
6714: my ($dom,$confname) = @_;
6715: my ($allowed,$switchserver);
6716: my $home = &Apache::lonnet::homeserver($confname,$dom);
6717: if ($home eq 'no_host') {
6718: $home = &Apache::lonnet::domain($dom,'primary');
6719: }
6720: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6721: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6722: if (!$allowed) {
1.180 raeburn 6723: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6724: }
6725: return $switchserver;
6726: }
6727:
1.1 raeburn 6728: sub modify_quotas {
1.216 raeburn 6729: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6730: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6731: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 6732: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6733: $validationfieldsref);
1.86 raeburn 6734: if ($action eq 'quotas') {
6735: $context = 'tools';
1.163 raeburn 6736: } else {
1.86 raeburn 6737: $context = $action;
6738: }
6739: if ($context eq 'requestcourses') {
1.216 raeburn 6740: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6741: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6742: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6743: %titles = &courserequest_titles();
6744: $toolregexp = join('|',@usertools);
6745: %conditions = &courserequest_conditions();
1.216 raeburn 6746: $confname = $dom.'-domainconfig';
6747: my $servadm = $r->dir_config('lonAdmEMail');
6748: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 6749: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6750: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 6751: } elsif ($context eq 'requestauthor') {
6752: @usertools = ('author');
6753: %titles = &authorrequest_titles();
1.86 raeburn 6754: } else {
1.162 raeburn 6755: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6756: %titles = &tool_titles();
1.86 raeburn 6757: }
1.212 raeburn 6758: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6759: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6760: foreach my $key (keys(%env)) {
1.101 raeburn 6761: if ($context eq 'requestcourses') {
6762: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6763: my $item = $1;
6764: my $type = $2;
6765: if ($type =~ /^limit_(.+)/) {
6766: $limithash{$item}{$1} = $env{$key};
6767: } else {
6768: $confhash{$item}{$type} = $env{$key};
6769: }
6770: }
1.163 raeburn 6771: } elsif ($context eq 'requestauthor') {
6772: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6773: $confhash{$1} = $env{$key};
6774: }
1.101 raeburn 6775: } else {
1.86 raeburn 6776: if ($key =~ /^form\.quota_(.+)$/) {
6777: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6778: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6779: $confhash{'authorquota'}{$1} = $env{$key};
6780: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6781: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6782: }
1.72 raeburn 6783: }
6784: }
1.163 raeburn 6785: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6786: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6787: @approvalnotify = sort(@approvalnotify);
6788: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6789: my @crstypes = ('official','unofficial','community','textbook');
6790: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6791: foreach my $type (@hasuniquecode) {
6792: if (grep(/^\Q$type\E$/,@crstypes)) {
6793: $confhash{'uniquecode'}{$type} = 1;
6794: }
1.216 raeburn 6795: }
6796: my ($newbook,@allpos);
6797: if ($context eq 'requestcourses') {
6798: if ($env{'form.addbook'}) {
6799: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6800: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6801: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6802: $env{'form.addbook_cdom'}) eq 'no_host') {
6803: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6804: '</span></li>';
6805: } else {
6806: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6807: my $position = $env{'form.addbook_pos'};
6808: $position =~ s/\D+//g;
6809: if ($position ne '') {
6810: $allpos[$position] = $newbook;
6811: }
6812: }
6813: } else {
6814: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6815: '</span></li>';
6816: }
6817: }
1.235 raeburn 6818:
1.216 raeburn 6819: }
1.102 raeburn 6820: if (ref($domconfig{$action}) eq 'HASH') {
6821: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6822: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6823: $changes{'notify'}{'approval'} = 1;
6824: }
6825: } else {
1.144 raeburn 6826: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6827: $changes{'notify'}{'approval'} = 1;
6828: }
6829: }
1.218 raeburn 6830: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6831: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6832: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6833: unless ($confhash{'uniquecode'}{$crstype}) {
6834: $changes{'uniquecode'} = 1;
6835: }
6836: }
6837: unless ($changes{'uniquecode'}) {
6838: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6839: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6840: $changes{'uniquecode'} = 1;
6841: }
6842: }
6843: }
6844: } else {
6845: $changes{'uniquecode'} = 1;
6846: }
6847: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6848: $changes{'uniquecode'} = 1;
1.216 raeburn 6849: }
6850: if ($context eq 'requestcourses') {
6851: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6852: my %deletions;
6853: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6854: if (@todelete) {
6855: map { $deletions{$_} = 1; } @todelete;
6856: }
6857: my %imgdeletions;
6858: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6859: if (@todeleteimages) {
6860: map { $imgdeletions{$_} = 1; } @todeleteimages;
6861: }
6862: my $maxnum = $env{'form.book_maxnum'};
6863: for (my $i=0; $i<=$maxnum; $i++) {
6864: my $key = $env{'form.book_id_'.$i};
6865: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6866: if ($deletions{$key}) {
6867: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6868: #FIXME need to obsolete item in RES space
6869: }
6870: next;
6871: } else {
6872: my $newpos = $env{'form.'.$key};
6873: $newpos =~ s/\D+//g;
6874: foreach my $item ('subject','title','author') {
6875: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6876: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6877: $changes{'textbooks'}{$key} = 1;
6878: }
6879: }
6880: $allpos[$newpos] = $key;
6881: }
6882: if ($imgdeletions{$key}) {
6883: $changes{'textbooks'}{$key} = 1;
6884: #FIXME need to obsolete item in RES space
6885: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6886: my ($cdom,$cnum) = split(/_/,$key);
6887: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6888: $cdom,$cnum,$configuserok,
6889: $switchserver,$author_ok);
6890: if ($imgurl) {
6891: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6892: $changes{'textbooks'}{$key} = 1;
6893: }
6894: if ($error) {
6895: &Apache::lonnet::logthis($error);
6896: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6897: }
6898: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6899: $confhash{'textbooks'}{$key}{'image'} =
6900: $domconfig{$action}{'textbooks'}{$key}{'image'};
6901: }
6902: }
6903: }
6904: }
6905: }
1.102 raeburn 6906: } else {
1.144 raeburn 6907: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6908: $changes{'notify'}{'approval'} = 1;
6909: }
1.218 raeburn 6910: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6911: $changes{'uniquecode'} = 1;
6912: }
6913: }
6914: if ($context eq 'requestcourses') {
6915: if ($newbook) {
6916: $changes{'textbooks'}{$newbook} = 1;
6917: foreach my $item ('subject','title','author') {
6918: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6919: if ($env{'form.addbook_'.$item}) {
6920: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6921: }
6922: }
6923: if ($env{'form.addbook_image.filename'} ne '') {
6924: my ($cdom,$cnum) = split(/_/,$newbook);
1.235 raeburn 6925: my ($imageurl,$error) =
1.216 raeburn 6926: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6927: $switchserver,$author_ok);
6928: if ($imageurl) {
6929: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6930: }
6931: if ($error) {
6932: &Apache::lonnet::logthis($error);
6933: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6934: }
6935: }
6936: }
6937: if (@allpos > 0) {
6938: my $idx = 0;
6939: foreach my $item (@allpos) {
6940: if ($item ne '') {
6941: $confhash{'textbooks'}{$item}{'order'} = $idx;
6942: if (ref($domconfig{$action}) eq 'HASH') {
6943: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6944: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6945: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6946: $changes{'textbooks'}{$item} = 1;
6947: }
6948: }
6949: }
6950: }
6951: $idx ++;
6952: }
6953: }
6954: }
1.235 raeburn 6955: if (ref($validationitemsref) eq 'ARRAY') {
6956: foreach my $item (@{$validationitemsref}) {
6957: if ($item eq 'fields') {
6958: my @changed;
6959: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
6960: if (@{$confhash{'validation'}{$item}} > 0) {
6961: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
6962: }
6963: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6964: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
6965: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
6966: $domconfig{'requestcourses'}{'validation'}{$item});
6967: } else {
6968: @changed = @{$confhash{'validation'}{$item}};
6969: }
6970: } else {
6971: @changed = @{$confhash{'validation'}{$item}};
6972: }
6973: if (@changed) {
6974: if ($confhash{'validation'}{$item}) {
6975: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
6976: } else {
6977: $changes{'validation'}{$item} = &mt('None');
6978: }
6979: }
6980: } else {
6981: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
6982: if ($item eq 'markup') {
6983: if ($env{'form.requestcourses_validation_'.$item}) {
6984: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
6985: }
6986: }
6987: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6988: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
6989: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6990: }
6991: } else {
6992: if ($confhash{'validation'}{$item} ne '') {
6993: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6994: }
6995: }
6996: }
6997: }
6998: }
6999: if ($env{'form.validationdc'}) {
7000: my $newval = $env{'form.validationdc'};
7001: my %domcoords = &get_active_dcs($dom);
7002: if (exists($domcoords{$newval})) {
7003: $confhash{'validation'}{'dc'} = $newval;
7004: }
7005: }
7006: if (ref($confhash{'validation'}) eq 'HASH') {
7007: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7008: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7009: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7010: if ($confhash{'validation'}{'dc'} eq '') {
7011: $changes{'validation'}{'dc'} = &mt('None');
7012: } else {
7013: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7014: }
7015: }
7016: } elsif ($confhash{'validation'}{'dc'} ne '') {
7017: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7018: }
7019: } elsif ($confhash{'validation'}{'dc'} ne '') {
7020: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7021: }
7022: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7023: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7024: $changes{'validation'}{'dc'} = &mt('None');
7025: }
7026: }
1.102 raeburn 7027: }
7028: } else {
1.86 raeburn 7029: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7030: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7031: }
1.72 raeburn 7032: foreach my $item (@usertools) {
7033: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7034: my $unset;
1.101 raeburn 7035: if ($context eq 'requestcourses') {
1.104 raeburn 7036: $unset = '0';
7037: if ($type eq '_LC_adv') {
7038: $unset = '';
7039: }
1.101 raeburn 7040: if ($confhash{$item}{$type} eq 'autolimit') {
7041: $confhash{$item}{$type} .= '=';
7042: unless ($limithash{$item}{$type} =~ /\D/) {
7043: $confhash{$item}{$type} .= $limithash{$item}{$type};
7044: }
7045: }
1.163 raeburn 7046: } elsif ($context eq 'requestauthor') {
7047: $unset = '0';
7048: if ($type eq '_LC_adv') {
7049: $unset = '';
7050: }
1.72 raeburn 7051: } else {
1.101 raeburn 7052: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7053: $confhash{$item}{$type} = 1;
7054: } else {
7055: $confhash{$item}{$type} = 0;
7056: }
1.72 raeburn 7057: }
1.86 raeburn 7058: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7059: if ($action eq 'requestauthor') {
7060: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7061: $changes{$type} = 1;
7062: }
7063: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7064: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7065: $changes{$item}{$type} = 1;
7066: }
7067: } else {
7068: if ($context eq 'requestcourses') {
1.104 raeburn 7069: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7070: $changes{$item}{$type} = 1;
7071: }
7072: } else {
7073: if (!$confhash{$item}{$type}) {
7074: $changes{$item}{$type} = 1;
7075: }
7076: }
7077: }
7078: } else {
7079: if ($context eq 'requestcourses') {
1.104 raeburn 7080: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7081: $changes{$item}{$type} = 1;
7082: }
1.163 raeburn 7083: } elsif ($context eq 'requestauthor') {
7084: if ($confhash{$type} ne $unset) {
7085: $changes{$type} = 1;
7086: }
1.72 raeburn 7087: } else {
7088: if (!$confhash{$item}{$type}) {
7089: $changes{$item}{$type} = 1;
7090: }
7091: }
7092: }
1.1 raeburn 7093: }
7094: }
1.163 raeburn 7095: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7096: if (ref($domconfig{'quotas'}) eq 'HASH') {
7097: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7098: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7099: if (exists($confhash{'defaultquota'}{$key})) {
7100: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7101: $changes{'defaultquota'}{$key} = 1;
7102: }
7103: } else {
7104: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7105: }
7106: }
1.86 raeburn 7107: } else {
7108: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7109: if (exists($confhash{'defaultquota'}{$key})) {
7110: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7111: $changes{'defaultquota'}{$key} = 1;
7112: }
7113: } else {
7114: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7115: }
1.1 raeburn 7116: }
7117: }
1.197 raeburn 7118: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7119: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7120: if (exists($confhash{'authorquota'}{$key})) {
7121: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7122: $changes{'authorquota'}{$key} = 1;
7123: }
7124: } else {
7125: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7126: }
7127: }
7128: }
1.1 raeburn 7129: }
1.86 raeburn 7130: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7131: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7132: if (ref($domconfig{'quotas'}) eq 'HASH') {
7133: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7134: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7135: $changes{'defaultquota'}{$key} = 1;
7136: }
7137: } else {
7138: if (!exists($domconfig{'quotas'}{$key})) {
7139: $changes{'defaultquota'}{$key} = 1;
7140: }
1.72 raeburn 7141: }
7142: } else {
1.86 raeburn 7143: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7144: }
1.1 raeburn 7145: }
7146: }
1.197 raeburn 7147: if (ref($confhash{'authorquota'}) eq 'HASH') {
7148: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7149: if (ref($domconfig{'quotas'}) eq 'HASH') {
7150: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7151: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7152: $changes{'authorquota'}{$key} = 1;
7153: }
7154: } else {
7155: $changes{'authorquota'}{$key} = 1;
7156: }
7157: } else {
7158: $changes{'authorquota'}{$key} = 1;
7159: }
7160: }
7161: }
1.1 raeburn 7162: }
1.72 raeburn 7163:
1.163 raeburn 7164: if ($context eq 'requestauthor') {
7165: $domdefaults{'requestauthor'} = \%confhash;
7166: } else {
7167: foreach my $key (keys(%confhash)) {
1.216 raeburn 7168: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
7169: $domdefaults{$key} = $confhash{$key};
7170: }
1.163 raeburn 7171: }
1.72 raeburn 7172: }
1.163 raeburn 7173:
1.1 raeburn 7174: my %quotahash = (
1.86 raeburn 7175: $action => { %confhash }
1.1 raeburn 7176: );
7177: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7178: $dom);
7179: if ($putresult eq 'ok') {
7180: if (keys(%changes) > 0) {
1.72 raeburn 7181: my $cachetime = 24*60*60;
7182: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7183: if (ref($lastactref) eq 'HASH') {
7184: $lastactref->{'domdefaults'} = 1;
7185: }
1.1 raeburn 7186: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7187: unless (($context eq 'requestcourses') ||
1.163 raeburn 7188: ($context eq 'requestauthor')) {
1.86 raeburn 7189: if (ref($changes{'defaultquota'}) eq 'HASH') {
7190: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7191: foreach my $type (@{$types},'default') {
7192: if (defined($changes{'defaultquota'}{$type})) {
7193: my $typetitle = $usertypes->{$type};
7194: if ($type eq 'default') {
7195: $typetitle = $othertitle;
7196: }
1.213 raeburn 7197: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7198: }
7199: }
1.86 raeburn 7200: $resulttext .= '</ul></li>';
1.72 raeburn 7201: }
1.197 raeburn 7202: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7203: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7204: foreach my $type (@{$types},'default') {
7205: if (defined($changes{'authorquota'}{$type})) {
7206: my $typetitle = $usertypes->{$type};
7207: if ($type eq 'default') {
7208: $typetitle = $othertitle;
7209: }
1.213 raeburn 7210: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7211: }
7212: }
7213: $resulttext .= '</ul></li>';
7214: }
1.72 raeburn 7215: }
1.80 raeburn 7216: my %newenv;
1.72 raeburn 7217: foreach my $item (@usertools) {
1.163 raeburn 7218: my (%haschgs,%inconf);
7219: if ($context eq 'requestauthor') {
7220: %haschgs = %changes;
1.210 raeburn 7221: %inconf = %confhash;
1.163 raeburn 7222: } else {
7223: if (ref($changes{$item}) eq 'HASH') {
7224: %haschgs = %{$changes{$item}};
7225: }
7226: if (ref($confhash{$item}) eq 'HASH') {
7227: %inconf = %{$confhash{$item}};
7228: }
7229: }
7230: if (keys(%haschgs) > 0) {
1.80 raeburn 7231: my $newacc =
7232: &Apache::lonnet::usertools_access($env{'user.name'},
7233: $env{'user.domain'},
1.86 raeburn 7234: $item,'reload',$context);
1.210 raeburn 7235: if (($context eq 'requestcourses') ||
1.163 raeburn 7236: ($context eq 'requestauthor')) {
1.108 raeburn 7237: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7238: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7239: }
7240: } else {
7241: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7242: $newenv{'environment.availabletools.'.$item} = $newacc;
7243: }
1.80 raeburn 7244: }
1.163 raeburn 7245: unless ($context eq 'requestauthor') {
7246: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7247: }
1.72 raeburn 7248: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7249: if ($haschgs{$type}) {
1.72 raeburn 7250: my $typetitle = $usertypes->{$type};
7251: if ($type eq 'default') {
7252: $typetitle = $othertitle;
7253: } elsif ($type eq '_LC_adv') {
7254: $typetitle = 'LON-CAPA Advanced Users';
7255: }
1.163 raeburn 7256: if ($inconf{$type}) {
1.101 raeburn 7257: if ($context eq 'requestcourses') {
7258: my $cond;
1.163 raeburn 7259: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7260: if ($1 eq '') {
7261: $cond = &mt('(Automatic processing of any request).');
7262: } else {
7263: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7264: }
7265: } else {
1.163 raeburn 7266: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7267: }
7268: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7269: } elsif ($context eq 'requestauthor') {
7270: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7271: $titles{$inconf{$type}},$typetitle);
7272:
1.101 raeburn 7273: } else {
7274: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7275: }
1.72 raeburn 7276: } else {
1.104 raeburn 7277: if ($type eq '_LC_adv') {
1.163 raeburn 7278: if ($inconf{$type} eq '0') {
1.104 raeburn 7279: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7280: } else {
7281: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7282: }
7283: } else {
7284: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7285: }
1.72 raeburn 7286: }
7287: }
1.26 raeburn 7288: }
1.163 raeburn 7289: unless ($context eq 'requestauthor') {
7290: $resulttext .= '</ul></li>';
7291: }
1.26 raeburn 7292: }
1.1 raeburn 7293: }
1.163 raeburn 7294: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7295: if (ref($changes{'notify'}) eq 'HASH') {
7296: if ($changes{'notify'}{'approval'}) {
7297: if (ref($confhash{'notify'}) eq 'HASH') {
7298: if ($confhash{'notify'}{'approval'}) {
7299: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7300: } else {
1.163 raeburn 7301: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7302: }
7303: }
7304: }
7305: }
7306: }
1.216 raeburn 7307: if ($action eq 'requestcourses') {
7308: my @offon = ('off','on');
7309: if ($changes{'uniquecode'}) {
1.218 raeburn 7310: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7311: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7312: $resulttext .= '<li>'.
7313: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7314: '</li>';
7315: } else {
7316: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7317: '</li>';
7318: }
1.216 raeburn 7319: }
7320: if (ref($changes{'textbooks'}) eq 'HASH') {
7321: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
7322: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
7323: my %coursehash = &Apache::lonnet::coursedescription($key);
7324: my $coursetitle = $coursehash{'description'};
7325: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
7326: $resulttext .= '<li>';
7327: foreach my $item ('subject','title','author') {
7328: my $name = $item.':';
7329: $name =~ s/^(\w)/\U$1/;
7330: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
7331: }
7332: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7333: if ($confhash{'textbooks'}{$key}{'image'}) {
7334: $resulttext .= ' '.&mt('Image: [_1]',
7335: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
7336: ' alt="Textbook cover" />').'<br />';
7337: }
7338: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7339: }
7340: $resulttext .= '</ul></li>';
7341: }
1.235 raeburn 7342: if (ref($changes{'validation'}) eq 'HASH') {
7343: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7344: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7345: foreach my $item (@{$validationitemsref}) {
7346: if (exists($changes{'validation'}{$item})) {
7347: if ($item eq 'markup') {
7348: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7349: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7350: } else {
7351: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7352: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7353: }
7354: }
7355: }
7356: if (exists($changes{'validation'}{'dc'})) {
7357: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7358: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7359: }
7360: }
7361: }
1.216 raeburn 7362: }
1.1 raeburn 7363: $resulttext .= '</ul>';
1.80 raeburn 7364: if (keys(%newenv)) {
7365: &Apache::lonnet::appenv(\%newenv);
7366: }
1.1 raeburn 7367: } else {
1.86 raeburn 7368: if ($context eq 'requestcourses') {
7369: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7370: } elsif ($context eq 'requestauthor') {
7371: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7372: } else {
1.90 weissno 7373: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7374: }
1.1 raeburn 7375: }
7376: } else {
1.11 albertel 7377: $resulttext = '<span class="LC_error">'.
7378: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7379: }
1.216 raeburn 7380: if ($errors) {
7381: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7382: '<ul>'.$errors.'</ul></p>';
7383: }
1.3 raeburn 7384: return $resulttext;
1.1 raeburn 7385: }
7386:
1.216 raeburn 7387: sub process_textbook_image {
7388: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
7389: my $filename = $env{'form.'.$caller.'.filename'};
7390: my ($error,$url);
7391: my ($width,$height) = (50,50);
7392: if ($configuserok eq 'ok') {
7393: if ($switchserver) {
7394: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7395: $switchserver);
7396: } elsif ($author_ok eq 'ok') {
7397: my ($result,$imageurl) =
7398: &publishlogo($r,'upload',$caller,$dom,$confname,
7399: "textbooks/$dom/$cnum/cover",$width,$height);
7400: if ($result eq 'ok') {
7401: $url = $imageurl;
7402: } else {
7403: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7404: }
7405: } else {
7406: $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);
7407: }
7408: } else {
7409: $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);
7410: }
7411: return ($url,$error);
7412: }
7413:
1.3 raeburn 7414: sub modify_autoenroll {
1.205 raeburn 7415: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7416: my ($resulttext,%changes);
7417: my %currautoenroll;
7418: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7419: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7420: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7421: }
7422: }
7423: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7424: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7425: sender => 'Sender for notification messages',
7426: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7427: my @offon = ('off','on');
1.17 raeburn 7428: my $sender_uname = $env{'form.sender_uname'};
7429: my $sender_domain = $env{'form.sender_domain'};
7430: if ($sender_domain eq '') {
7431: $sender_uname = '';
7432: } elsif ($sender_uname eq '') {
7433: $sender_domain = '';
7434: }
1.129 raeburn 7435: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7436: my %autoenrollhash = (
1.129 raeburn 7437: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7438: 'sender_uname' => $sender_uname,
7439: 'sender_domain' => $sender_domain,
7440: 'co-owners' => $coowners,
1.1 raeburn 7441: }
7442: );
1.4 raeburn 7443: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7444: $dom);
1.1 raeburn 7445: if ($putresult eq 'ok') {
7446: if (exists($currautoenroll{'run'})) {
7447: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7448: $changes{'run'} = 1;
7449: }
7450: } elsif ($autorun) {
7451: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7452: $changes{'run'} = 1;
1.1 raeburn 7453: }
7454: }
1.17 raeburn 7455: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7456: $changes{'sender'} = 1;
7457: }
1.17 raeburn 7458: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7459: $changes{'sender'} = 1;
7460: }
1.129 raeburn 7461: if ($currautoenroll{'co-owners'} ne '') {
7462: if ($currautoenroll{'co-owners'} ne $coowners) {
7463: $changes{'coowners'} = 1;
7464: }
7465: } elsif ($coowners) {
7466: $changes{'coowners'} = 1;
7467: }
1.1 raeburn 7468: if (keys(%changes) > 0) {
7469: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7470: if ($changes{'run'}) {
1.1 raeburn 7471: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7472: }
7473: if ($changes{'sender'}) {
1.17 raeburn 7474: if ($sender_uname eq '' || $sender_domain eq '') {
7475: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7476: } else {
7477: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7478: }
1.1 raeburn 7479: }
1.129 raeburn 7480: if ($changes{'coowners'}) {
7481: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7482: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7483: if (ref($lastactref) eq 'HASH') {
7484: $lastactref->{'domainconfig'} = 1;
7485: }
1.129 raeburn 7486: }
1.1 raeburn 7487: $resulttext .= '</ul>';
7488: } else {
7489: $resulttext = &mt('No changes made to auto-enrollment settings');
7490: }
7491: } else {
1.11 albertel 7492: $resulttext = '<span class="LC_error">'.
7493: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7494: }
1.3 raeburn 7495: return $resulttext;
1.1 raeburn 7496: }
7497:
7498: sub modify_autoupdate {
1.3 raeburn 7499: my ($dom,%domconfig) = @_;
1.1 raeburn 7500: my ($resulttext,%currautoupdate,%fields,%changes);
7501: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7502: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7503: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7504: }
7505: }
7506: my @offon = ('off','on');
7507: my %title = &Apache::lonlocal::texthash (
7508: run => 'Auto-update:',
7509: classlists => 'Updates to user information in classlists?'
7510: );
1.44 raeburn 7511: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7512: my %fieldtitles = &Apache::lonlocal::texthash (
7513: id => 'Student/Employee ID',
1.20 raeburn 7514: permanentemail => 'E-mail address',
1.1 raeburn 7515: lastname => 'Last Name',
7516: firstname => 'First Name',
7517: middlename => 'Middle Name',
1.132 raeburn 7518: generation => 'Generation',
1.1 raeburn 7519: );
1.142 raeburn 7520: $othertitle = &mt('All users');
1.1 raeburn 7521: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7522: $othertitle = &mt('Other users');
1.1 raeburn 7523: }
7524: foreach my $key (keys(%env)) {
7525: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7526: my ($usertype,$item) = ($1,$2);
7527: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7528: if ($usertype eq 'default') {
7529: push(@{$fields{$1}},$2);
7530: } elsif (ref($types) eq 'ARRAY') {
7531: if (grep(/^\Q$usertype\E$/,@{$types})) {
7532: push(@{$fields{$1}},$2);
7533: }
7534: }
7535: }
1.1 raeburn 7536: }
7537: }
1.131 raeburn 7538: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7539: @lockablenames = sort(@lockablenames);
7540: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7541: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7542: if (@changed) {
7543: $changes{'lockablenames'} = 1;
7544: }
7545: } else {
7546: if (@lockablenames) {
7547: $changes{'lockablenames'} = 1;
7548: }
7549: }
1.1 raeburn 7550: my %updatehash = (
7551: autoupdate => { run => $env{'form.autoupdate_run'},
7552: classlists => $env{'form.classlists'},
7553: fields => {%fields},
1.131 raeburn 7554: lockablenames => \@lockablenames,
1.1 raeburn 7555: }
7556: );
7557: foreach my $key (keys(%currautoupdate)) {
7558: if (($key eq 'run') || ($key eq 'classlists')) {
7559: if (exists($updatehash{autoupdate}{$key})) {
7560: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7561: $changes{$key} = 1;
7562: }
7563: }
7564: } elsif ($key eq 'fields') {
7565: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7566: foreach my $item (@{$types},'default') {
1.1 raeburn 7567: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7568: my $change = 0;
7569: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7570: if (!exists($fields{$item})) {
7571: $change = 1;
1.132 raeburn 7572: last;
1.1 raeburn 7573: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7574: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7575: $change = 1;
1.132 raeburn 7576: last;
1.1 raeburn 7577: }
7578: }
7579: }
7580: if ($change) {
7581: push(@{$changes{$key}},$item);
7582: }
1.26 raeburn 7583: }
1.1 raeburn 7584: }
7585: }
1.131 raeburn 7586: } elsif ($key eq 'lockablenames') {
7587: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7588: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7589: if (@changed) {
7590: $changes{'lockablenames'} = 1;
7591: }
7592: } else {
7593: if (@lockablenames) {
7594: $changes{'lockablenames'} = 1;
7595: }
7596: }
7597: }
7598: }
7599: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7600: if (@lockablenames) {
7601: $changes{'lockablenames'} = 1;
1.1 raeburn 7602: }
7603: }
1.26 raeburn 7604: foreach my $item (@{$types},'default') {
7605: if (defined($fields{$item})) {
7606: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7607: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7608: my $change = 0;
7609: if (ref($fields{$item}) eq 'ARRAY') {
7610: foreach my $type (@{$fields{$item}}) {
7611: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7612: $change = 1;
7613: last;
7614: }
7615: }
7616: }
7617: if ($change) {
7618: push(@{$changes{'fields'}},$item);
7619: }
7620: } else {
1.26 raeburn 7621: push(@{$changes{'fields'}},$item);
7622: }
7623: } else {
7624: push(@{$changes{'fields'}},$item);
1.1 raeburn 7625: }
7626: }
7627: }
7628: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7629: $dom);
7630: if ($putresult eq 'ok') {
7631: if (keys(%changes) > 0) {
7632: $resulttext = &mt('Changes made:').'<ul>';
7633: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7634: if ($key eq 'lockablenames') {
7635: $resulttext .= '<li>';
7636: if (@lockablenames) {
7637: $usertypes->{'default'} = $othertitle;
7638: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7639: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7640: } else {
7641: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7642: }
7643: $resulttext .= '</li>';
7644: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7645: foreach my $item (@{$changes{$key}}) {
7646: my @newvalues;
7647: foreach my $type (@{$fields{$item}}) {
7648: push(@newvalues,$fieldtitles{$type});
7649: }
1.3 raeburn 7650: my $newvaluestr;
7651: if (@newvalues > 0) {
7652: $newvaluestr = join(', ',@newvalues);
7653: } else {
7654: $newvaluestr = &mt('none');
1.6 raeburn 7655: }
1.1 raeburn 7656: if ($item eq 'default') {
1.26 raeburn 7657: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7658: } else {
1.26 raeburn 7659: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7660: }
7661: }
7662: } else {
7663: my $newvalue;
7664: if ($key eq 'run') {
7665: $newvalue = $offon[$env{'form.autoupdate_run'}];
7666: } else {
7667: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7668: }
1.1 raeburn 7669: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7670: }
7671: }
7672: $resulttext .= '</ul>';
7673: } else {
1.3 raeburn 7674: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7675: }
7676: } else {
1.11 albertel 7677: $resulttext = '<span class="LC_error">'.
7678: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7679: }
1.3 raeburn 7680: return $resulttext;
1.1 raeburn 7681: }
7682:
1.125 raeburn 7683: sub modify_autocreate {
7684: my ($dom,%domconfig) = @_;
7685: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7686: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7687: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7688: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7689: }
7690: }
7691: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7692: req => 'Auto-creation of validated requests for official courses',
7693: xmldc => 'Identity of course creator of courses from XML files',
7694: );
7695: my @types = ('xml','req');
7696: foreach my $item (@types) {
7697: $newvals{$item} = $env{'form.autocreate_'.$item};
7698: $newvals{$item} =~ s/\D//g;
7699: $newvals{$item} = 0 if ($newvals{$item} eq '');
7700: }
7701: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7702: my %domcoords = &get_active_dcs($dom);
7703: unless (exists($domcoords{$newvals{'xmldc'}})) {
7704: $newvals{'xmldc'} = '';
7705: }
7706: %autocreatehash = (
7707: autocreate => { xml => $newvals{'xml'},
7708: req => $newvals{'req'},
7709: }
7710: );
7711: if ($newvals{'xmldc'} ne '') {
7712: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7713: }
7714: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7715: $dom);
7716: if ($putresult eq 'ok') {
7717: my @items = @types;
7718: if ($newvals{'xml'}) {
7719: push(@items,'xmldc');
7720: }
7721: foreach my $item (@items) {
7722: if (exists($currautocreate{$item})) {
7723: if ($currautocreate{$item} ne $newvals{$item}) {
7724: $changes{$item} = 1;
7725: }
7726: } elsif ($newvals{$item}) {
7727: $changes{$item} = 1;
7728: }
7729: }
7730: if (keys(%changes) > 0) {
7731: my @offon = ('off','on');
7732: $resulttext = &mt('Changes made:').'<ul>';
7733: foreach my $item (@types) {
7734: if ($changes{$item}) {
7735: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7736: $resulttext .= '<li>'.
7737: &mt("$title{$item} set to [_1]$newtxt [_2]",
7738: '<b>','</b>').
7739: '</li>';
1.125 raeburn 7740: }
7741: }
7742: if ($changes{'xmldc'}) {
7743: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7744: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7745: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7746: }
7747: $resulttext .= '</ul>';
7748: } else {
7749: $resulttext = &mt('No changes made to auto-creation settings');
7750: }
7751: } else {
7752: $resulttext = '<span class="LC_error">'.
7753: &mt('An error occurred: [_1]',$putresult).'</span>';
7754: }
7755: return $resulttext;
7756: }
7757:
1.23 raeburn 7758: sub modify_directorysrch {
7759: my ($dom,%domconfig) = @_;
7760: my ($resulttext,%changes);
7761: my %currdirsrch;
7762: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7763: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7764: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7765: }
7766: }
7767: my %title = ( available => 'Directory search available',
1.24 raeburn 7768: localonly => 'Other domains can search',
1.23 raeburn 7769: searchby => 'Search types',
7770: searchtypes => 'Search latitude');
7771: my @offon = ('off','on');
1.24 raeburn 7772: my @otherdoms = ('Yes','No');
1.23 raeburn 7773:
1.25 raeburn 7774: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7775: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7776: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7777:
1.44 raeburn 7778: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7779: if (keys(%{$usertypes}) == 0) {
7780: @cansearch = ('default');
7781: } else {
7782: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7783: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7784: if (!grep(/^\Q$type\E$/,@cansearch)) {
7785: push(@{$changes{'cansearch'}},$type);
7786: }
1.23 raeburn 7787: }
1.26 raeburn 7788: foreach my $type (@cansearch) {
7789: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7790: push(@{$changes{'cansearch'}},$type);
7791: }
1.23 raeburn 7792: }
1.26 raeburn 7793: } else {
7794: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7795: }
7796: }
7797:
7798: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7799: foreach my $by (@{$currdirsrch{'searchby'}}) {
7800: if (!grep(/^\Q$by\E$/,@searchby)) {
7801: push(@{$changes{'searchby'}},$by);
7802: }
7803: }
7804: foreach my $by (@searchby) {
7805: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7806: push(@{$changes{'searchby'}},$by);
7807: }
7808: }
7809: } else {
7810: push(@{$changes{'searchby'}},@searchby);
7811: }
1.25 raeburn 7812:
7813: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7814: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7815: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7816: push(@{$changes{'searchtypes'}},$type);
7817: }
7818: }
7819: foreach my $type (@searchtypes) {
7820: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7821: push(@{$changes{'searchtypes'}},$type);
7822: }
7823: }
7824: } else {
7825: if (exists($currdirsrch{'searchtypes'})) {
7826: foreach my $type (@searchtypes) {
7827: if ($type ne $currdirsrch{'searchtypes'}) {
7828: push(@{$changes{'searchtypes'}},$type);
7829: }
7830: }
7831: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7832: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7833: }
7834: } else {
7835: push(@{$changes{'searchtypes'}},@searchtypes);
7836: }
7837: }
7838:
1.23 raeburn 7839: my %dirsrch_hash = (
7840: directorysrch => { available => $env{'form.dirsrch_available'},
7841: cansearch => \@cansearch,
1.24 raeburn 7842: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7843: searchby => \@searchby,
1.25 raeburn 7844: searchtypes => \@searchtypes,
1.23 raeburn 7845: }
7846: );
7847: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7848: $dom);
7849: if ($putresult eq 'ok') {
7850: if (exists($currdirsrch{'available'})) {
7851: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7852: $changes{'available'} = 1;
7853: }
7854: } else {
7855: if ($env{'form.dirsrch_available'} eq '1') {
7856: $changes{'available'} = 1;
7857: }
7858: }
1.24 raeburn 7859: if (exists($currdirsrch{'localonly'})) {
7860: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7861: $changes{'localonly'} = 1;
7862: }
7863: } else {
7864: if ($env{'form.dirsrch_localonly'} eq '1') {
7865: $changes{'localonly'} = 1;
7866: }
7867: }
1.23 raeburn 7868: if (keys(%changes) > 0) {
7869: $resulttext = &mt('Changes made:').'<ul>';
7870: if ($changes{'available'}) {
7871: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7872: }
1.24 raeburn 7873: if ($changes{'localonly'}) {
7874: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7875: }
7876:
1.23 raeburn 7877: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7878: my $chgtext;
1.26 raeburn 7879: if (ref($usertypes) eq 'HASH') {
7880: if (keys(%{$usertypes}) > 0) {
7881: foreach my $type (@{$types}) {
7882: if (grep(/^\Q$type\E$/,@cansearch)) {
7883: $chgtext .= $usertypes->{$type}.'; ';
7884: }
7885: }
7886: if (grep(/^default$/,@cansearch)) {
7887: $chgtext .= $othertitle;
7888: } else {
7889: $chgtext =~ s/\; $//;
7890: }
1.210 raeburn 7891: $resulttext .=
1.178 raeburn 7892: '<li>'.
7893: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7894: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7895: '</li>';
1.23 raeburn 7896: }
7897: }
7898: }
7899: if (ref($changes{'searchby'}) eq 'ARRAY') {
7900: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7901: my $chgtext;
7902: foreach my $type (@{$titleorder}) {
7903: if (grep(/^\Q$type\E$/,@searchby)) {
7904: if (defined($searchtitles->{$type})) {
7905: $chgtext .= $searchtitles->{$type}.'; ';
7906: }
7907: }
7908: }
7909: $chgtext =~ s/\; $//;
7910: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7911: }
1.25 raeburn 7912: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7913: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7914: my $chgtext;
7915: foreach my $type (@{$srchtypeorder}) {
7916: if (grep(/^\Q$type\E$/,@searchtypes)) {
7917: if (defined($srchtypes_desc->{$type})) {
7918: $chgtext .= $srchtypes_desc->{$type}.'; ';
7919: }
7920: }
7921: }
7922: $chgtext =~ s/\; $//;
1.178 raeburn 7923: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7924: }
7925: $resulttext .= '</ul>';
7926: } else {
7927: $resulttext = &mt('No changes made to institution directory search settings');
7928: }
7929: } else {
7930: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7931: &mt('An error occurred: [_1]',$putresult).'</span>';
7932: }
7933: return $resulttext;
7934: }
7935:
1.28 raeburn 7936: sub modify_contacts {
1.205 raeburn 7937: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7938: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7939: if (ref($domconfig{'contacts'}) eq 'HASH') {
7940: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7941: $currsetting{$key} = $domconfig{'contacts'}{$key};
7942: }
7943: }
1.134 raeburn 7944: my (%others,%to,%bcc);
1.28 raeburn 7945: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7946: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7947: 'requestsmail','updatesmail','idconflictsmail');
7948: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7949: foreach my $type (@mailings) {
7950: @{$newsetting{$type}} =
7951: &Apache::loncommon::get_env_multiple('form.'.$type);
7952: foreach my $item (@contacts) {
7953: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7954: $contacts_hash{contacts}{$type}{$item} = 1;
7955: } else {
7956: $contacts_hash{contacts}{$type}{$item} = 0;
7957: }
7958: }
7959: $others{$type} = $env{'form.'.$type.'_others'};
7960: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7961: if ($type eq 'helpdeskmail') {
7962: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7963: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7964: }
1.28 raeburn 7965: }
7966: foreach my $item (@contacts) {
7967: $to{$item} = $env{'form.'.$item};
7968: $contacts_hash{'contacts'}{$item} = $to{$item};
7969: }
1.203 raeburn 7970: foreach my $item (@toggles) {
7971: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7972: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7973: }
7974: }
1.28 raeburn 7975: if (keys(%currsetting) > 0) {
7976: foreach my $item (@contacts) {
7977: if ($to{$item} ne $currsetting{$item}) {
7978: $changes{$item} = 1;
7979: }
7980: }
7981: foreach my $type (@mailings) {
7982: foreach my $item (@contacts) {
7983: if (ref($currsetting{$type}) eq 'HASH') {
7984: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7985: push(@{$changes{$type}},$item);
7986: }
7987: } else {
7988: push(@{$changes{$type}},@{$newsetting{$type}});
7989: }
7990: }
7991: if ($others{$type} ne $currsetting{$type}{'others'}) {
7992: push(@{$changes{$type}},'others');
7993: }
1.134 raeburn 7994: if ($type eq 'helpdeskmail') {
7995: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7996: push(@{$changes{$type}},'bcc');
7997: }
7998: }
1.28 raeburn 7999: }
8000: } else {
8001: my %default;
8002: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8003: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8004: $default{'errormail'} = 'adminemail';
8005: $default{'packagesmail'} = 'adminemail';
8006: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8007: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8008: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8009: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8010: foreach my $item (@contacts) {
8011: if ($to{$item} ne $default{$item}) {
8012: $changes{$item} = 1;
1.203 raeburn 8013: }
1.28 raeburn 8014: }
8015: foreach my $type (@mailings) {
8016: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8017:
8018: push(@{$changes{$type}},@{$newsetting{$type}});
8019: }
8020: if ($others{$type} ne '') {
8021: push(@{$changes{$type}},'others');
1.134 raeburn 8022: }
8023: if ($type eq 'helpdeskmail') {
8024: if ($bcc{$type} ne '') {
8025: push(@{$changes{$type}},'bcc');
8026: }
8027: }
1.28 raeburn 8028: }
8029: }
1.203 raeburn 8030: foreach my $item (@toggles) {
8031: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8032: $changes{$item} = 1;
8033: } elsif ((!$env{'form.'.$item}) &&
8034: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8035: $changes{$item} = 1;
8036: }
8037: }
1.28 raeburn 8038: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8039: $dom);
8040: if ($putresult eq 'ok') {
8041: if (keys(%changes) > 0) {
1.205 raeburn 8042: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8043: if (ref($lastactref) eq 'HASH') {
8044: $lastactref->{'domainconfig'} = 1;
8045: }
1.28 raeburn 8046: my ($titles,$short_titles) = &contact_titles();
8047: $resulttext = &mt('Changes made:').'<ul>';
8048: foreach my $item (@contacts) {
8049: if ($changes{$item}) {
8050: $resulttext .= '<li>'.$titles->{$item}.
8051: &mt(' set to: ').
8052: '<span class="LC_cusr_emph">'.
8053: $to{$item}.'</span></li>';
8054: }
8055: }
8056: foreach my $type (@mailings) {
8057: if (ref($changes{$type}) eq 'ARRAY') {
8058: $resulttext .= '<li>'.$titles->{$type}.': ';
8059: my @text;
8060: foreach my $item (@{$newsetting{$type}}) {
8061: push(@text,$short_titles->{$item});
8062: }
8063: if ($others{$type} ne '') {
8064: push(@text,$others{$type});
8065: }
8066: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8067: join(', ',@text).'</span>';
8068: if ($type eq 'helpdeskmail') {
8069: if ($bcc{$type} ne '') {
8070: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8071: }
8072: }
8073: $resulttext .= '</li>';
1.28 raeburn 8074: }
8075: }
1.203 raeburn 8076: my @offon = ('off','on');
8077: if ($changes{'reporterrors'}) {
8078: $resulttext .= '<li>'.
8079: &mt('E-mail error reports to [_1] set to "'.
8080: $offon[$env{'form.reporterrors'}].'".',
8081: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8082: &mt('LON-CAPA core group - MSU'),600,500)).
8083: '</li>';
8084: }
8085: if ($changes{'reportupdates'}) {
8086: $resulttext .= '<li>'.
8087: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8088: $offon[$env{'form.reportupdates'}].'".',
8089: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8090: &mt('LON-CAPA core group - MSU'),600,500)).
8091: '</li>';
8092: }
1.28 raeburn 8093: $resulttext .= '</ul>';
8094: } else {
1.34 raeburn 8095: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8096: }
8097: } else {
8098: $resulttext = '<span class="LC_error">'.
8099: &mt('An error occurred: [_1].',$putresult).'</span>';
8100: }
8101: return $resulttext;
8102: }
8103:
8104: sub modify_usercreation {
1.27 raeburn 8105: my ($dom,%domconfig) = @_;
1.224 raeburn 8106: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8107: my $warningmsg;
1.27 raeburn 8108: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8109: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8110: if ($key eq 'cancreate') {
8111: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8112: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8113: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8114: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8115: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8116: } else {
8117: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8118: }
8119: }
8120: }
8121: } elsif ($key eq 'email_rule') {
8122: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8123: } else {
8124: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8125: }
1.27 raeburn 8126: }
8127: }
8128: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8129: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8130: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8131: foreach my $item(@contexts) {
1.224 raeburn 8132: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8133: }
1.34 raeburn 8134: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8135: foreach my $item (@contexts) {
1.224 raeburn 8136: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8137: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8138: }
1.27 raeburn 8139: }
1.34 raeburn 8140: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8141: foreach my $item (@contexts) {
1.43 raeburn 8142: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8143: if ($cancreate{$item} ne 'any') {
8144: push(@{$changes{'cancreate'}},$item);
8145: }
8146: } else {
8147: if ($cancreate{$item} ne 'none') {
8148: push(@{$changes{'cancreate'}},$item);
8149: }
1.27 raeburn 8150: }
8151: }
8152: } else {
1.43 raeburn 8153: foreach my $item (@contexts) {
1.34 raeburn 8154: push(@{$changes{'cancreate'}},$item);
8155: }
1.27 raeburn 8156: }
1.34 raeburn 8157:
1.27 raeburn 8158: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8159: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8160: if (!grep(/^\Q$type\E$/,@username_rule)) {
8161: push(@{$changes{'username_rule'}},$type);
8162: }
8163: }
8164: foreach my $type (@username_rule) {
8165: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8166: push(@{$changes{'username_rule'}},$type);
8167: }
8168: }
8169: } else {
8170: push(@{$changes{'username_rule'}},@username_rule);
8171: }
8172:
1.32 raeburn 8173: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8174: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8175: if (!grep(/^\Q$type\E$/,@id_rule)) {
8176: push(@{$changes{'id_rule'}},$type);
8177: }
8178: }
8179: foreach my $type (@id_rule) {
8180: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8181: push(@{$changes{'id_rule'}},$type);
8182: }
8183: }
8184: } else {
8185: push(@{$changes{'id_rule'}},@id_rule);
8186: }
8187:
1.43 raeburn 8188: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8189: my @authtypes = ('int','krb4','krb5','loc');
8190: my %authhash;
1.43 raeburn 8191: foreach my $item (@authen_contexts) {
1.28 raeburn 8192: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8193: foreach my $auth (@authtypes) {
8194: if (grep(/^\Q$auth\E$/,@authallowed)) {
8195: $authhash{$item}{$auth} = 1;
8196: } else {
8197: $authhash{$item}{$auth} = 0;
8198: }
8199: }
8200: }
8201: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8202: foreach my $item (@authen_contexts) {
1.28 raeburn 8203: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8204: foreach my $auth (@authtypes) {
8205: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8206: push(@{$changes{'authtypes'}},$item);
8207: last;
8208: }
8209: }
8210: }
8211: }
8212: } else {
1.43 raeburn 8213: foreach my $item (@authen_contexts) {
1.28 raeburn 8214: push(@{$changes{'authtypes'}},$item);
8215: }
8216: }
8217:
1.224 raeburn 8218: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8219: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8220: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8221: $save_usercreate{'id_rule'} = \@id_rule;
8222: $save_usercreate{'username_rule'} = \@username_rule,
8223: $save_usercreate{'authtypes'} = \%authhash;
8224:
1.27 raeburn 8225: my %usercreation_hash = (
1.224 raeburn 8226: usercreation => \%save_usercreate,
8227: );
1.27 raeburn 8228:
8229: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8230: $dom);
1.50 raeburn 8231:
1.224 raeburn 8232: if ($putresult eq 'ok') {
8233: if (keys(%changes) > 0) {
8234: $resulttext = &mt('Changes made:').'<ul>';
8235: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8236: my %lt = &usercreation_types();
8237: foreach my $type (@{$changes{'cancreate'}}) {
8238: my $chgtext = $lt{$type}.', ';
8239: if ($cancreate{$type} eq 'none') {
8240: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8241: } elsif ($cancreate{$type} eq 'any') {
8242: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8243: } elsif ($cancreate{$type} eq 'official') {
8244: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8245: } elsif ($cancreate{$type} eq 'unofficial') {
8246: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8247: }
8248: $resulttext .= '<li>'.$chgtext.'</li>';
8249: }
8250: }
8251: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8252: my ($rules,$ruleorder) =
8253: &Apache::lonnet::inst_userrules($dom,'username');
8254: my $chgtext = '<ul>';
8255: foreach my $type (@username_rule) {
8256: if (ref($rules->{$type}) eq 'HASH') {
8257: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8258: }
8259: }
8260: $chgtext .= '</ul>';
8261: if (@username_rule > 0) {
8262: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8263: } else {
8264: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8265: }
8266: }
8267: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8268: my ($idrules,$idruleorder) =
8269: &Apache::lonnet::inst_userrules($dom,'id');
8270: my $chgtext = '<ul>';
8271: foreach my $type (@id_rule) {
8272: if (ref($idrules->{$type}) eq 'HASH') {
8273: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8274: }
8275: }
8276: $chgtext .= '</ul>';
8277: if (@id_rule > 0) {
8278: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8279: } else {
8280: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8281: }
8282: }
8283: my %authname = &authtype_names();
8284: my %context_title = &context_names();
8285: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8286: my $chgtext = '<ul>';
8287: foreach my $type (@{$changes{'authtypes'}}) {
8288: my @allowed;
8289: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8290: foreach my $auth (@authtypes) {
8291: if ($authhash{$type}{$auth}) {
8292: push(@allowed,$authname{$auth});
8293: }
8294: }
8295: if (@allowed > 0) {
8296: $chgtext .= join(', ',@allowed).'</li>';
8297: } else {
8298: $chgtext .= &mt('none').'</li>';
8299: }
8300: }
8301: $chgtext .= '</ul>';
8302: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8303: $resulttext .= '</li>';
8304: }
8305: $resulttext .= '</ul>';
8306: } else {
8307: $resulttext = &mt('No changes made to user creation settings');
8308: }
8309: } else {
8310: $resulttext = '<span class="LC_error">'.
8311: &mt('An error occurred: [_1]',$putresult).'</span>';
8312: }
8313: if ($warningmsg ne '') {
8314: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8315: }
8316: return $resulttext;
8317: }
8318:
8319: sub modify_selfcreation {
8320: my ($dom,%domconfig) = @_;
8321: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8322: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8323: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8324: if (ref($types) eq 'ARRAY') {
8325: $usertypes->{'default'} = $othertitle;
8326: push(@{$types},'default');
8327: }
1.224 raeburn 8328: #
8329: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8330: #
8331: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8332: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8333: if ($key eq 'cancreate') {
8334: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8335: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8336: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8337: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8338: ($item eq 'emailusername') || ($item eq 'notify') ||
8339: ($item eq 'selfcreateprocessing')) {
1.224 raeburn 8340: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8341: } else {
8342: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8343: }
8344: }
8345: }
8346: } elsif ($key eq 'email_rule') {
8347: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8348: } else {
8349: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8350: }
8351: }
8352: }
8353: #
8354: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8355: #
8356: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8357: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8358: if ($key eq 'selfcreate') {
8359: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8360: } else {
8361: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8362: }
8363: }
8364: }
8365:
8366: my @contexts = ('selfcreate');
8367: @{$cancreate{'selfcreate'}} = ();
8368: %{$cancreate{'emailusername'}} = ();
8369: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8370: %{$cancreate{'selfcreateprocessing'}} = ();
1.50 raeburn 8371: my %selfcreatetypes = (
8372: sso => 'users authenticated by institutional single sign on',
8373: login => 'users authenticated by institutional log-in',
1.236 raeburn 8374: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8375: );
1.224 raeburn 8376: #
8377: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8378: # is permitted.
8379: #
1.236 raeburn 8380:
8381: my @statuses;
8382: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8383: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8384: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8385: }
8386: }
8387: push(@statuses,'default');
8388:
1.228 raeburn 8389: foreach my $item ('login','sso','email') {
1.224 raeburn 8390: if ($item eq 'email') {
1.236 raeburn 8391: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8392: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8393: push(@contexts,'selfcreateprocessing');
8394: foreach my $type (@statuses) {
8395: if ($type eq 'default') {
8396: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8397: } else {
8398: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8399: }
8400: }
1.224 raeburn 8401: }
8402: } else {
8403: if ($env{'form.cancreate_'.$item}) {
8404: push(@{$cancreate{'selfcreate'}},$item);
8405: }
8406: }
8407: }
8408: my (@email_rule,%userinfo,%savecaptcha);
8409: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8410: #
1.228 raeburn 8411: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8412: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8413: #
1.236 raeburn 8414:
8415: if ($env{'form.cancreate_email'} eq 'email') {
1.228 raeburn 8416: push(@contexts,'emailusername');
8417: if (ref($types) eq 'ARRAY') {
8418: foreach my $type (@{$types}) {
8419: if (ref($infofields) eq 'ARRAY') {
8420: foreach my $field (@{$infofields}) {
8421: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8422: $cancreate{'emailusername'}{$type}{$field} = $1;
8423: }
8424: }
1.224 raeburn 8425: }
8426: }
8427: }
8428: #
8429: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8430: # queued requests for self-creation of account using e-mail address as username
8431: #
8432:
8433: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8434: @approvalnotify = sort(@approvalnotify);
8435: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8436: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8437: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8438: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8439: push(@{$changes{'cancreate'}},'notify');
8440: }
8441: } else {
8442: if ($cancreate{'notify'}{'approval'}) {
8443: push(@{$changes{'cancreate'}},'notify');
8444: }
8445: }
8446: } elsif ($cancreate{'notify'}{'approval'}) {
8447: push(@{$changes{'cancreate'}},'notify');
8448: }
8449:
8450: #
8451: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8452: #
8453: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8454: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8455: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8456: if (@{$curr_usercreation{'email_rule'}} > 0) {
8457: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8458: if (!grep(/^\Q$type\E$/,@email_rule)) {
8459: push(@{$changes{'email_rule'}},$type);
8460: }
8461: }
8462: }
8463: if (@email_rule > 0) {
8464: foreach my $type (@email_rule) {
8465: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8466: push(@{$changes{'email_rule'}},$type);
8467: }
8468: }
8469: }
8470: } elsif (@email_rule > 0) {
8471: push(@{$changes{'email_rule'}},@email_rule);
8472: }
8473: }
8474: #
1.236 raeburn 8475: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8476: # institutional log-in.
8477: #
8478: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8479: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8480: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8481: ($domdefaults{'auth_def'} eq 'localauth'))) {
8482: $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.').' '.
8483: &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.');
8484: }
8485: }
8486: my @fields = ('lastname','firstname','middlename','generation',
8487: 'permanentemail','id');
8488: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8489: #
8490: # Where usernames may created for institutional log-in and/or institutional single sign on:
8491: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8492: # may self-create accounts
8493: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8494: # which the user may supply, if institutional data is unavailable.
8495: #
8496: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8497: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8498: if (@{$types} > 1) {
1.224 raeburn 8499: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8500: push(@contexts,'statustocreate');
8501: } else {
8502: undef($cancreate{'statustocreate'});
8503: }
8504: foreach my $type (@{$types}) {
8505: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8506: foreach my $field (@fields) {
8507: if (grep(/^\Q$field\E$/,@modifiable)) {
8508: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8509: } else {
8510: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8511: }
8512: }
8513: }
8514: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8515: foreach my $type (@{$types}) {
8516: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8517: foreach my $field (@fields) {
8518: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8519: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8520: push(@{$changes{'selfcreate'}},$type);
8521: last;
8522: }
8523: }
8524: }
8525: }
8526: } else {
8527: foreach my $type (@{$types}) {
8528: push(@{$changes{'selfcreate'}},$type);
8529: }
8530: }
8531: }
8532: }
8533: foreach my $item (@contexts) {
8534: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8535: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8536: if (ref($cancreate{$item}) eq 'ARRAY') {
8537: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8538: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8539: push(@{$changes{'cancreate'}},$item);
8540: }
8541: }
8542: }
8543: }
8544: if (ref($cancreate{$item}) eq 'ARRAY') {
8545: foreach my $type (@{$cancreate{$item}}) {
8546: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8547: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8548: push(@{$changes{'cancreate'}},$item);
8549: }
8550: }
8551: }
8552: }
8553: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8554: if (ref($cancreate{$item}) eq 'HASH') {
8555: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8556: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8557: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8558: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8559: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8560: push(@{$changes{'cancreate'}},$item);
8561: }
8562: }
8563: }
1.236 raeburn 8564: } elsif ($item eq 'selfcreateprocessing') {
8565: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8566: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8567: push(@{$changes{'cancreate'}},$item);
8568: }
8569: }
1.228 raeburn 8570: } else {
8571: if (!$cancreate{$item}{$curr}) {
8572: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8573: push(@{$changes{'cancreate'}},$item);
8574: }
1.224 raeburn 8575: }
8576: }
8577: }
8578: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8579: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8580: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8581: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8582: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8583: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8584: push(@{$changes{'cancreate'}},$item);
8585: }
8586: }
8587: } else {
8588: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8589: push(@{$changes{'cancreate'}},$item);
8590: }
8591: }
8592: }
1.236 raeburn 8593: } elsif ($item eq 'selfcreateprocessing') {
8594: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8595: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8596: push(@{$changes{'cancreate'}},$item);
8597: }
8598: }
1.228 raeburn 8599: } else {
8600: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8601: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8602: push(@{$changes{'cancreate'}},$item);
8603: }
1.224 raeburn 8604: }
8605: }
8606: }
8607: }
8608: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8609: if (ref($cancreate{$item}) eq 'ARRAY') {
8610: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8611: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8612: push(@{$changes{'cancreate'}},$item);
8613: }
8614: }
8615: } elsif (ref($cancreate{$item}) eq 'HASH') {
8616: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8617: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8618: push(@{$changes{'cancreate'}},$item);
8619: }
8620: }
8621: }
8622: } elsif ($item eq 'emailusername') {
1.228 raeburn 8623: if (ref($cancreate{$item}) eq 'HASH') {
8624: foreach my $type (keys(%{$cancreate{$item}})) {
8625: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8626: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8627: if ($cancreate{$item}{$type}{$field}) {
8628: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8629: push(@{$changes{'cancreate'}},$item);
8630: }
8631: last;
8632: }
8633: }
8634: }
8635: }
1.224 raeburn 8636: }
8637: }
8638: }
8639: #
8640: # Populate %save_usercreate hash with updates to self-creation configuration.
8641: #
8642: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8643: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8644: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8645: if (ref($cancreate{'notify'}) eq 'HASH') {
8646: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8647: }
1.236 raeburn 8648: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8649: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8650: }
1.224 raeburn 8651: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8652: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8653: }
8654: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8655: $save_usercreate{'emailrule'} = \@email_rule;
8656:
8657: my %userconfig_hash = (
8658: usercreation => \%save_usercreate,
8659: usermodification => \%save_usermodify,
8660: );
8661: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8662: $dom);
8663: #
8664: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8665: #
1.27 raeburn 8666: if ($putresult eq 'ok') {
8667: if (keys(%changes) > 0) {
8668: $resulttext = &mt('Changes made:').'<ul>';
8669: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8670: my %lt = &selfcreation_types();
1.34 raeburn 8671: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8672: my $chgtext;
1.45 raeburn 8673: if ($type eq 'selfcreate') {
1.50 raeburn 8674: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8675: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8676: } else {
1.224 raeburn 8677: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8678: '<ul>';
1.50 raeburn 8679: foreach my $case (@{$cancreate{$type}}) {
8680: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8681: }
8682: $chgtext .= '</ul>';
1.100 raeburn 8683: if (ref($cancreate{$type}) eq 'ARRAY') {
8684: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8685: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8686: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8687: $chgtext .= '<br />'.
8688: '<span class="LC_warning">'.
8689: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8690: '</span>';
1.100 raeburn 8691: }
8692: }
8693: }
8694: }
1.43 raeburn 8695: }
1.93 raeburn 8696: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8697: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8698: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8699: if (@{$cancreate{'selfcreate'}} > 0) {
8700: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8701: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8702: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8703: $chgtext .= '<br />'.
8704: '<span class="LC_warning">'.
8705: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8706: '</span>';
8707: }
1.96 raeburn 8708: } elsif (ref($usertypes) eq 'HASH') {
8709: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8710: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8711: } else {
8712: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8713: }
8714: $chgtext .= '<ul>';
8715: foreach my $case (@{$cancreate{$type}}) {
8716: if ($case eq 'default') {
8717: $chgtext .= '<li>'.$othertitle.'</li>';
8718: } else {
8719: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8720: }
8721: }
1.100 raeburn 8722: $chgtext .= '</ul>';
8723: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8724: $chgtext .= '<br /><span class="LC_warning">'.
8725: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8726: '</span>';
1.100 raeburn 8727: }
8728: }
8729: } else {
8730: if (@{$cancreate{$type}} == 0) {
8731: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8732: } else {
8733: $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 8734: }
8735: }
8736: }
1.236 raeburn 8737: } elsif ($type eq 'selfcreateprocessing') {
8738: my %choices = &Apache::lonlocal::texthash (
8739: automatic => 'Automatic approval',
8740: approval => 'Queued for approval',
8741: );
8742: if (@statuses > 1) {
8743: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8744: '<ul>';
8745: foreach my $type (@statuses) {
8746: if ($type eq 'default') {
8747: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8748: } else {
8749: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8750: }
8751: }
8752: $chgtext .= '</ul>';
8753: } else {
8754: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8755: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8756: }
1.165 raeburn 8757: } elsif ($type eq 'captcha') {
1.224 raeburn 8758: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8759: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8760: } else {
8761: my %captchas = &captcha_phrases();
1.224 raeburn 8762: if ($captchas{$savecaptcha{$type}}) {
8763: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8764: } else {
1.210 raeburn 8765: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8766: }
8767: }
8768: } elsif ($type eq 'recaptchakeys') {
8769: my ($privkey,$pubkey);
1.224 raeburn 8770: if (ref($savecaptcha{$type}) eq 'HASH') {
8771: $pubkey = $savecaptcha{$type}{'public'};
8772: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8773: }
8774: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8775: if (!$pubkey) {
8776: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8777: } else {
8778: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8779: }
8780: if (!$privkey) {
8781: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8782: } else {
8783: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8784: }
8785: $chgtext .= '</ul>';
1.224 raeburn 8786: } elsif ($type eq 'emailusername') {
8787: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8788: if (ref($types) eq 'ARRAY') {
8789: foreach my $type (@{$types}) {
8790: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8791: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8792: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8793: '<ul>';
8794: foreach my $field (@{$infofields}) {
8795: if ($cancreate{'emailusername'}{$type}{$field}) {
8796: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8797: }
8798: }
8799: }
8800: $chgtext .= '</ul>';
8801: } else {
8802: $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 8803: }
8804: }
8805: }
8806: }
8807: } elsif ($type eq 'notify') {
8808: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8809: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8810: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8811: if ($cancreate{'notify'}{'approval'}) {
8812: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8813: }
8814: }
1.43 raeburn 8815: }
1.34 raeburn 8816: }
1.224 raeburn 8817: if ($chgtext) {
8818: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8819: }
8820: }
8821: }
1.43 raeburn 8822: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8823: my ($emailrules,$emailruleorder) =
8824: &Apache::lonnet::inst_userrules($dom,'email');
8825: my $chgtext = '<ul>';
8826: foreach my $type (@email_rule) {
8827: if (ref($emailrules->{$type}) eq 'HASH') {
8828: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8829: }
8830: }
8831: $chgtext .= '</ul>';
8832: if (@email_rule > 0) {
1.224 raeburn 8833: $resulttext .= '<li>'.
8834: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8835: $chgtext.
8836: '</li>';
1.43 raeburn 8837: } else {
1.224 raeburn 8838: $resulttext .= '<li>'.
8839: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8840: '</li>';
1.43 raeburn 8841: }
8842: }
1.224 raeburn 8843: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8844: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8845: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8846: foreach my $type (@{$changes{'selfcreate'}}) {
8847: my $typename = $type;
8848: if (ref($usertypes) eq 'HASH') {
8849: if ($usertypes->{$type} ne '') {
8850: $typename = $usertypes->{$type};
8851: }
8852: }
8853: my @modifiable;
8854: $resulttext .= '<li>'.
8855: &mt('Self-creation of account by users with status: [_1]',
8856: '<span class="LC_cusr_emph">'.$typename.'</span>').
8857: ' - '.&mt('modifiable fields (if institutional data blank): ');
8858: foreach my $field (@fields) {
8859: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8860: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8861: }
8862: }
1.224 raeburn 8863: if (@modifiable > 0) {
8864: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8865: } else {
1.224 raeburn 8866: $resulttext .= &mt('none');
1.43 raeburn 8867: }
1.224 raeburn 8868: $resulttext .= '</li>';
1.28 raeburn 8869: }
1.224 raeburn 8870: $resulttext .= '</ul></li>';
1.28 raeburn 8871: }
1.27 raeburn 8872: $resulttext .= '</ul>';
8873: } else {
1.224 raeburn 8874: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8875: }
8876: } else {
8877: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8878: &mt('An error occurred: [_1]',$putresult).'</span>';
8879: }
1.43 raeburn 8880: if ($warningmsg ne '') {
8881: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8882: }
1.23 raeburn 8883: return $resulttext;
8884: }
8885:
1.165 raeburn 8886: sub process_captcha {
8887: my ($container,$changes,$newsettings,$current) = @_;
8888: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8889: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8890: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8891: $newsettings->{'captcha'} = 'original';
8892: }
8893: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8894: if ($container eq 'cancreate') {
1.169 raeburn 8895: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8896: push(@{$changes->{'cancreate'}},'captcha');
8897: } elsif (!defined($changes->{'cancreate'})) {
8898: $changes->{'cancreate'} = ['captcha'];
8899: }
8900: } else {
8901: $changes->{'captcha'} = 1;
1.165 raeburn 8902: }
8903: }
8904: my ($newpub,$newpriv,$currpub,$currpriv);
8905: if ($newsettings->{'captcha'} eq 'recaptcha') {
8906: $newpub = $env{'form.'.$container.'_recaptchapub'};
8907: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8908: $newpub =~ s/\W//g;
8909: $newpriv =~ s/\W//g;
8910: $newsettings->{'recaptchakeys'} = {
8911: public => $newpub,
8912: private => $newpriv,
8913: };
1.165 raeburn 8914: }
8915: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8916: $currpub = $current->{'recaptchakeys'}{'public'};
8917: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8918: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8919: $newsettings->{'recaptchakeys'} = {
8920: public => '',
8921: private => '',
8922: }
8923: }
1.165 raeburn 8924: }
8925: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8926: if ($container eq 'cancreate') {
8927: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8928: push(@{$changes->{'cancreate'}},'recaptchakeys');
8929: } elsif (!defined($changes->{'cancreate'})) {
8930: $changes->{'cancreate'} = ['recaptchakeys'];
8931: }
8932: } else {
1.210 raeburn 8933: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8934: }
8935: }
8936: return;
8937: }
8938:
1.33 raeburn 8939: sub modify_usermodification {
8940: my ($dom,%domconfig) = @_;
1.224 raeburn 8941: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8942: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8943: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 8944: if ($key eq 'selfcreate') {
8945: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8946: } else {
8947: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8948: }
1.33 raeburn 8949: }
8950: }
1.224 raeburn 8951: my @contexts = ('author','course');
1.33 raeburn 8952: my %context_title = (
8953: author => 'In author context',
8954: course => 'In course context',
8955: );
8956: my @fields = ('lastname','firstname','middlename','generation',
8957: 'permanentemail','id');
8958: my %roles = (
8959: author => ['ca','aa'],
8960: course => ['st','ep','ta','in','cr'],
8961: );
8962: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8963: foreach my $context (@contexts) {
8964: foreach my $role (@{$roles{$context}}) {
8965: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8966: foreach my $item (@fields) {
8967: if (grep(/^\Q$item\E$/,@modifiable)) {
8968: $modifyhash{$context}{$role}{$item} = 1;
8969: } else {
8970: $modifyhash{$context}{$role}{$item} = 0;
8971: }
8972: }
8973: }
8974: if (ref($curr_usermodification{$context}) eq 'HASH') {
8975: foreach my $role (@{$roles{$context}}) {
8976: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8977: foreach my $field (@fields) {
8978: if ($modifyhash{$context}{$role}{$field} ne
8979: $curr_usermodification{$context}{$role}{$field}) {
8980: push(@{$changes{$context}},$role);
8981: last;
8982: }
8983: }
8984: }
8985: }
8986: } else {
8987: foreach my $context (@contexts) {
8988: foreach my $role (@{$roles{$context}}) {
8989: push(@{$changes{$context}},$role);
8990: }
8991: }
8992: }
8993: }
8994: my %usermodification_hash = (
8995: usermodification => \%modifyhash,
8996: );
8997: my $putresult = &Apache::lonnet::put_dom('configuration',
8998: \%usermodification_hash,$dom);
8999: if ($putresult eq 'ok') {
9000: if (keys(%changes) > 0) {
9001: $resulttext = &mt('Changes made: ').'<ul>';
9002: foreach my $context (@contexts) {
9003: if (ref($changes{$context}) eq 'ARRAY') {
9004: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9005: if (ref($changes{$context}) eq 'ARRAY') {
9006: foreach my $role (@{$changes{$context}}) {
9007: my $rolename;
1.224 raeburn 9008: if ($role eq 'cr') {
9009: $rolename = &mt('Custom');
1.33 raeburn 9010: } else {
1.224 raeburn 9011: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9012: }
9013: my @modifiable;
1.224 raeburn 9014: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9015: foreach my $field (@fields) {
9016: if ($modifyhash{$context}{$role}{$field}) {
9017: push(@modifiable,$fieldtitles{$field});
9018: }
9019: }
9020: if (@modifiable > 0) {
9021: $resulttext .= join(', ',@modifiable);
9022: } else {
9023: $resulttext .= &mt('none');
9024: }
9025: $resulttext .= '</li>';
9026: }
9027: $resulttext .= '</ul></li>';
9028: }
9029: }
9030: }
9031: $resulttext .= '</ul>';
9032: } else {
9033: $resulttext = &mt('No changes made to user modification settings');
9034: }
9035: } else {
9036: $resulttext = '<span class="LC_error">'.
9037: &mt('An error occurred: [_1]',$putresult).'</span>';
9038: }
9039: return $resulttext;
9040: }
9041:
1.43 raeburn 9042: sub modify_defaults {
1.212 raeburn 9043: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9044: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9045: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9046: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9047: my @authtypes = ('internal','krb4','krb5','localauth');
9048: foreach my $item (@items) {
9049: $newvalues{$item} = $env{'form.'.$item};
9050: if ($item eq 'auth_def') {
9051: if ($newvalues{$item} ne '') {
9052: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9053: push(@errors,$item);
9054: }
9055: }
9056: } elsif ($item eq 'lang_def') {
9057: if ($newvalues{$item} ne '') {
9058: if ($newvalues{$item} =~ /^(\w+)/) {
9059: my $langcode = $1;
1.103 raeburn 9060: if ($langcode ne 'x_chef') {
9061: if (code2language($langcode) eq '') {
9062: push(@errors,$item);
9063: }
1.43 raeburn 9064: }
9065: } else {
9066: push(@errors,$item);
9067: }
9068: }
1.54 raeburn 9069: } elsif ($item eq 'timezone_def') {
9070: if ($newvalues{$item} ne '') {
1.62 raeburn 9071: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9072: push(@errors,$item);
9073: }
9074: }
1.68 raeburn 9075: } elsif ($item eq 'datelocale_def') {
9076: if ($newvalues{$item} ne '') {
9077: my @datelocale_ids = DateTime::Locale->ids();
9078: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9079: push(@errors,$item);
9080: }
9081: }
1.141 raeburn 9082: } elsif ($item eq 'portal_def') {
9083: if ($newvalues{$item} ne '') {
9084: 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])\/?$/) {
9085: push(@errors,$item);
9086: }
9087: }
1.43 raeburn 9088: }
9089: if (grep(/^\Q$item\E$/,@errors)) {
9090: $newvalues{$item} = $domdefaults{$item};
9091: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9092: $changes{$item} = 1;
9093: }
1.72 raeburn 9094: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9095: }
9096: my %defaults_hash = (
1.72 raeburn 9097: defaults => \%newvalues,
9098: );
1.43 raeburn 9099: my $title = &defaults_titles();
1.236 raeburn 9100:
9101: my $currinststatus;
9102: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9103: $currinststatus = $domconfig{'inststatus'};
9104: } else {
9105: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9106: $currinststatus = {
9107: inststatustypes => $usertypes,
9108: inststatusorder => $types,
9109: inststatusguest => [],
9110: };
9111: }
9112: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9113: my @allpos;
9114: my %guests;
9115: my %alltypes;
9116: my ($currtitles,$currguests,$currorder);
9117: if (ref($currinststatus) eq 'HASH') {
9118: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9119: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9120: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9121: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9122: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9123: }
9124: }
9125: unless (grep(/^\Q$type\E$/,@todelete)) {
9126: my $position = $env{'form.inststatus_pos_'.$type};
9127: $position =~ s/\D+//g;
9128: $allpos[$position] = $type;
9129: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9130: $alltypes{$type} =~ s/`//g;
9131: if ($env{'form.inststatus_guest_'.$type}) {
9132: $guests{$type} = 1;
9133: }
9134: }
9135: }
9136: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9137: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9138: }
9139: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9140: $currtitles =~ s/,$//;
9141: }
9142: }
9143: if ($env{'form.addinststatus'}) {
9144: my $newtype = $env{'form.addinststatus'};
9145: $newtype =~ s/\W//g;
9146: unless (exists($alltypes{$newtype})) {
9147: if ($env{'form.addinststatus_guest'}) {
9148: $guests{$newtype} = 1;
9149: }
9150: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9151: $alltypes{$newtype} =~ s/`//g;
9152: my $position = $env{'form.addinststatus_pos'};
9153: $position =~ s/\D+//g;
9154: if ($position ne '') {
9155: $allpos[$position] = $newtype;
9156: }
9157: }
9158: }
9159: my (@orderedstatus,@orderedguests);
9160: foreach my $type (@allpos) {
9161: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9162: push(@orderedstatus,$type);
9163: if ($guests{$type}) {
9164: push(@orderedguests,$type);
9165: }
9166: }
9167: }
9168: foreach my $type (keys(%alltypes)) {
9169: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9170: delete($alltypes{$type});
9171: }
9172: }
9173: $defaults_hash{'inststatus'} = {
9174: inststatustypes => \%alltypes,
9175: inststatusorder => \@orderedstatus,
9176: inststatusguest => \@orderedguests,
9177: };
9178: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9179: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9180: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9181: }
9182: }
9183: if ($currorder ne join(',',@orderedstatus)) {
9184: $changes{'inststatus'}{'inststatusorder'} = 1;
9185: }
9186: if ($currguests ne join(',',@orderedguests)) {
9187: $changes{'inststatus'}{'inststatusguest'} = 1;
9188: }
9189: my $newtitles;
9190: foreach my $item (@orderedstatus) {
9191: $newtitles .= $alltypes{$item}.',';
9192: }
9193: $newtitles =~ s/,$//;
9194: if ($currtitles ne $newtitles) {
9195: $changes{'inststatus'}{'inststatustypes'} = 1;
9196: }
1.43 raeburn 9197: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9198: $dom);
9199: if ($putresult eq 'ok') {
9200: if (keys(%changes) > 0) {
9201: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9202: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9203: 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";
9204: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9205: if ($item eq 'inststatus') {
9206: if (ref($changes{'inststatus'}) eq 'HASH') {
9207: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9208: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9209: foreach my $type (@orderedstatus) {
9210: $resulttext .= $alltypes{$type}.', ';
9211: }
9212: $resulttext =~ s/, $//;
9213: $resulttext .= '</li>';
9214: }
9215: if ($changes{'inststatus'}{'inststatusguest'}) {
9216: $resulttext .= '<li>';
9217: if (@orderedguests) {
9218: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9219: foreach my $type (@orderedguests) {
9220: $resulttext .= $alltypes{$type}.', ';
9221: }
9222: $resulttext =~ s/, $//;
9223: } else {
9224: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9225: }
9226: $resulttext .= '</li>';
9227: }
9228: }
9229: } else {
9230: my $value = $env{'form.'.$item};
9231: if ($value eq '') {
9232: $value = &mt('none');
9233: } elsif ($item eq 'auth_def') {
9234: my %authnames = &authtype_names();
9235: my %shortauth = (
9236: internal => 'int',
9237: krb4 => 'krb4',
9238: krb5 => 'krb5',
9239: localauth => 'loc',
9240: );
9241: $value = $authnames{$shortauth{$value}};
9242: }
9243: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9244: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9245: }
9246: }
9247: $resulttext .= '</ul>';
9248: $mailmsgtext .= "\n";
9249: my $cachetime = 24*60*60;
1.72 raeburn 9250: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9251: if (ref($lastactref) eq 'HASH') {
9252: $lastactref->{'domdefaults'} = 1;
9253: }
1.68 raeburn 9254: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9255: my $notify = 1;
9256: if (ref($domconfig{'contacts'}) eq 'HASH') {
9257: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9258: $notify = 0;
9259: }
9260: }
9261: if ($notify) {
9262: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9263: "LON-CAPA Domain Settings Change - $dom",
9264: $mailmsgtext);
9265: }
1.54 raeburn 9266: }
1.43 raeburn 9267: } else {
1.54 raeburn 9268: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9269: }
9270: } else {
9271: $resulttext = '<span class="LC_error">'.
9272: &mt('An error occurred: [_1]',$putresult).'</span>';
9273: }
9274: if (@errors > 0) {
9275: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9276: foreach my $item (@errors) {
9277: $resulttext .= ' "'.$title->{$item}.'",';
9278: }
9279: $resulttext =~ s/,$//;
9280: }
9281: return $resulttext;
9282: }
9283:
1.46 raeburn 9284: sub modify_scantron {
1.205 raeburn 9285: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9286: my ($resulttext,%confhash,%changes,$errors);
9287: my $custom = 'custom.tab';
9288: my $default = 'default.tab';
9289: my $servadm = $r->dir_config('lonAdmEMail');
9290: my ($configuserok,$author_ok,$switchserver) =
9291: &config_check($dom,$confname,$servadm);
9292: if ($env{'form.scantronformat.filename'} ne '') {
9293: my $error;
9294: if ($configuserok eq 'ok') {
9295: if ($switchserver) {
1.130 raeburn 9296: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9297: } else {
9298: if ($author_ok eq 'ok') {
9299: my ($result,$scantronurl) =
9300: &publishlogo($r,'upload','scantronformat',$dom,
9301: $confname,'scantron','','',$custom);
9302: if ($result eq 'ok') {
9303: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9304: $changes{'scantronformat'} = 1;
1.46 raeburn 9305: } else {
9306: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9307: }
9308: } else {
9309: $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);
9310: }
9311: }
9312: } else {
9313: $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);
9314: }
9315: if ($error) {
9316: &Apache::lonnet::logthis($error);
9317: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9318: }
9319: }
1.48 raeburn 9320: if (ref($domconfig{'scantron'}) eq 'HASH') {
9321: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9322: if ($env{'form.scantronformat_del'}) {
9323: $confhash{'scantron'}{'scantronformat'} = '';
9324: $changes{'scantronformat'} = 1;
1.46 raeburn 9325: }
9326: }
9327: }
9328: if (keys(%confhash) > 0) {
9329: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9330: $dom);
9331: if ($putresult eq 'ok') {
9332: if (keys(%changes) > 0) {
1.48 raeburn 9333: if (ref($confhash{'scantron'}) eq 'HASH') {
9334: $resulttext = &mt('Changes made:').'<ul>';
9335: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9336: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9337: } else {
1.130 raeburn 9338: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9339: }
1.48 raeburn 9340: $resulttext .= '</ul>';
9341: } else {
1.130 raeburn 9342: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9343: }
9344: $resulttext .= '</ul>';
9345: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9346: if (ref($lastactref) eq 'HASH') {
9347: $lastactref->{'domainconfig'} = 1;
9348: }
1.46 raeburn 9349: } else {
1.130 raeburn 9350: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9351: }
9352: } else {
9353: $resulttext = '<span class="LC_error">'.
9354: &mt('An error occurred: [_1]',$putresult).'</span>';
9355: }
9356: } else {
1.130 raeburn 9357: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9358: }
9359: if ($errors) {
9360: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9361: $errors.'</ul>';
9362: }
9363: return $resulttext;
9364: }
9365:
1.48 raeburn 9366: sub modify_coursecategories {
9367: my ($dom,%domconfig) = @_;
1.57 raeburn 9368: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9369: $cathash);
1.48 raeburn 9370: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 ! raeburn 9371: my @catitems = ('unauth','auth');
! 9372: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9373: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9374: $cathash = $domconfig{'coursecategories'}{'cats'};
9375: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9376: $changes{'togglecats'} = 1;
9377: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9378: }
9379: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9380: $changes{'categorize'} = 1;
9381: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9382: }
1.120 raeburn 9383: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9384: $changes{'togglecatscomm'} = 1;
9385: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9386: }
9387: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9388: $changes{'categorizecomm'} = 1;
9389: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9390: }
1.238 ! raeburn 9391: foreach my $item (@catitems) {
! 9392: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
! 9393: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
! 9394: $changes{$item} = 1;
! 9395: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
! 9396: }
! 9397: }
! 9398: }
1.57 raeburn 9399: } else {
9400: $changes{'togglecats'} = 1;
9401: $changes{'categorize'} = 1;
1.124 raeburn 9402: $changes{'togglecatscomm'} = 1;
9403: $changes{'categorizecomm'} = 1;
1.87 raeburn 9404: $domconfig{'coursecategories'} = {
9405: togglecats => $env{'form.togglecats'},
9406: categorize => $env{'form.categorize'},
1.124 raeburn 9407: togglecatscomm => $env{'form.togglecatscomm'},
9408: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9409: };
1.238 ! raeburn 9410: foreach my $item (@catitems) {
! 9411: if ($env{'form.coursecat_'.$item} ne 'std') {
! 9412: $changes{$item} = 1;
! 9413: }
! 9414: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
! 9415: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
! 9416: }
! 9417: }
1.57 raeburn 9418: }
9419: if (ref($cathash) eq 'HASH') {
9420: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9421: push (@deletecategory,'instcode::0');
9422: }
1.120 raeburn 9423: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9424: push(@deletecategory,'communities::0');
9425: }
1.48 raeburn 9426: }
1.57 raeburn 9427: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9428: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9429: if (@deletecategory > 0) {
9430: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9431: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9432: foreach my $item (@deletecategory) {
1.57 raeburn 9433: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9434: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9435: $deletions{$item} = 1;
1.57 raeburn 9436: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9437: }
9438: }
9439: }
1.57 raeburn 9440: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9441: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9442: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9443: $reorderings{$item} = 1;
1.57 raeburn 9444: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9445: }
9446: if ($env{'form.addcategory_name_'.$item} ne '') {
9447: my $newcat = $env{'form.addcategory_name_'.$item};
9448: my $newdepth = $depth+1;
9449: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9450: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9451: $adds{$newitem} = 1;
9452: }
9453: if ($env{'form.subcat_'.$item} ne '') {
9454: my $newcat = $env{'form.subcat_'.$item};
9455: my $newdepth = $depth+1;
9456: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9457: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9458: $adds{$newitem} = 1;
9459: }
9460: }
9461: }
9462: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9463: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9464: my $newitem = 'instcode::0';
1.57 raeburn 9465: if ($cathash->{$newitem} eq '') {
9466: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9467: $adds{$newitem} = 1;
9468: }
9469: } else {
9470: my $newitem = 'instcode::0';
1.57 raeburn 9471: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9472: $adds{$newitem} = 1;
9473: }
9474: }
1.120 raeburn 9475: if ($env{'form.communities'} eq '1') {
9476: if (ref($cathash) eq 'HASH') {
9477: my $newitem = 'communities::0';
9478: if ($cathash->{$newitem} eq '') {
9479: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9480: $adds{$newitem} = 1;
9481: }
9482: } else {
9483: my $newitem = 'communities::0';
9484: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9485: $adds{$newitem} = 1;
9486: }
9487: }
1.48 raeburn 9488: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9489: if (($env{'form.addcategory_name'} ne 'instcode') &&
9490: ($env{'form.addcategory_name'} ne 'communities')) {
9491: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9492: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9493: $adds{$newitem} = 1;
9494: }
1.48 raeburn 9495: }
1.57 raeburn 9496: my $putresult;
1.48 raeburn 9497: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9498: if (keys(%deletions) > 0) {
9499: foreach my $key (keys(%deletions)) {
9500: if ($predelallitems{$key} ne '') {
9501: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9502: }
9503: }
9504: }
9505: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9506: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9507: if (ref($chkcats[0]) eq 'ARRAY') {
9508: my $depth = 0;
9509: my $chg = 0;
9510: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9511: my $name = $chkcats[0][$i];
9512: my $item;
9513: if ($name eq '') {
9514: $chg ++;
9515: } else {
9516: $item = &escape($name).'::0';
9517: if ($chg) {
1.57 raeburn 9518: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9519: }
9520: $depth ++;
1.57 raeburn 9521: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9522: $depth --;
9523: }
9524: }
9525: }
1.57 raeburn 9526: }
9527: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9528: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9529: if ($putresult eq 'ok') {
1.57 raeburn 9530: my %title = (
1.120 raeburn 9531: togglecats => 'Show/Hide a course in catalog',
9532: categorize => 'Assign a category to a course',
9533: togglecatscomm => 'Show/Hide a community in catalog',
9534: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9535: );
9536: my %level = (
1.120 raeburn 9537: dom => 'set in Domain ("Modify Course/Community")',
9538: crs => 'set in Course ("Course Configuration")',
9539: comm => 'set in Community ("Community Configuration")',
1.238 ! raeburn 9540: none => 'No catalog',
! 9541: std => 'Standard catalog',
! 9542: domonly => 'Domain-only catalog',
! 9543: codesrch => 'Code search form',
1.57 raeburn 9544: );
1.48 raeburn 9545: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9546: if ($changes{'togglecats'}) {
9547: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9548: }
9549: if ($changes{'categorize'}) {
9550: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9551: }
1.120 raeburn 9552: if ($changes{'togglecatscomm'}) {
9553: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9554: }
9555: if ($changes{'categorizecomm'}) {
9556: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9557: }
1.238 ! raeburn 9558: if ($changes{'unauth'}) {
! 9559: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
! 9560: }
! 9561: if ($changes{'auth'}) {
! 9562: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
! 9563: }
1.57 raeburn 9564: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9565: my $cathash;
9566: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9567: $cathash = $domconfig{'coursecategories'}{'cats'};
9568: } else {
9569: $cathash = {};
9570: }
9571: my (@cats,@trails,%allitems);
9572: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9573: if (keys(%deletions) > 0) {
9574: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9575: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9576: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9577: }
9578: $resulttext .= '</ul></li>';
9579: }
9580: if (keys(%reorderings) > 0) {
9581: my %sort_by_trail;
9582: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9583: foreach my $key (keys(%reorderings)) {
9584: if ($allitems{$key} ne '') {
9585: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9586: }
1.48 raeburn 9587: }
1.57 raeburn 9588: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9589: $resulttext .= '<li>'.$trails[$trail].'</li>';
9590: }
9591: $resulttext .= '</ul></li>';
1.48 raeburn 9592: }
1.57 raeburn 9593: if (keys(%adds) > 0) {
9594: my %sort_by_trail;
9595: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9596: foreach my $key (keys(%adds)) {
9597: if ($allitems{$key} ne '') {
9598: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9599: }
9600: }
9601: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9602: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9603: }
1.57 raeburn 9604: $resulttext .= '</ul></li>';
1.48 raeburn 9605: }
9606: }
9607: $resulttext .= '</ul>';
9608: } else {
9609: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9610: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9611: }
9612: } else {
1.120 raeburn 9613: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9614: }
9615: return $resulttext;
9616: }
9617:
1.69 raeburn 9618: sub modify_serverstatuses {
9619: my ($dom,%domconfig) = @_;
9620: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9621: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9622: %currserverstatus = %{$domconfig{'serverstatuses'}};
9623: }
9624: my @pages = &serverstatus_pages();
9625: foreach my $type (@pages) {
9626: $newserverstatus{$type}{'namedusers'} = '';
9627: $newserverstatus{$type}{'machines'} = '';
9628: if (defined($env{'form.'.$type.'_namedusers'})) {
9629: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9630: my @okusers;
9631: foreach my $user (@users) {
9632: my ($uname,$udom) = split(/:/,$user);
9633: if (($udom =~ /^$match_domain$/) &&
9634: (&Apache::lonnet::domain($udom)) &&
9635: ($uname =~ /^$match_username$/)) {
9636: if (!grep(/^\Q$user\E/,@okusers)) {
9637: push(@okusers,$user);
9638: }
9639: }
9640: }
9641: if (@okusers > 0) {
9642: @okusers = sort(@okusers);
9643: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9644: }
9645: }
9646: if (defined($env{'form.'.$type.'_machines'})) {
9647: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9648: my @okmachines;
9649: foreach my $ip (@machines) {
9650: my @parts = split(/\./,$ip);
9651: next if (@parts < 4);
9652: my $badip = 0;
9653: for (my $i=0; $i<4; $i++) {
9654: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9655: $badip = 1;
9656: last;
9657: }
9658: }
9659: if (!$badip) {
9660: push(@okmachines,$ip);
9661: }
9662: }
9663: @okmachines = sort(@okmachines);
9664: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9665: }
9666: }
9667: my %serverstatushash = (
9668: serverstatuses => \%newserverstatus,
9669: );
9670: foreach my $type (@pages) {
1.83 raeburn 9671: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9672: my (@current,@new);
1.83 raeburn 9673: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9674: if ($currserverstatus{$type}{$setting} ne '') {
9675: @current = split(/,/,$currserverstatus{$type}{$setting});
9676: }
9677: }
9678: if ($newserverstatus{$type}{$setting} ne '') {
9679: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9680: }
9681: if (@current > 0) {
9682: if (@new > 0) {
9683: foreach my $item (@current) {
9684: if (!grep(/^\Q$item\E$/,@new)) {
9685: $changes{$type}{$setting} = 1;
1.82 raeburn 9686: last;
9687: }
9688: }
1.84 raeburn 9689: foreach my $item (@new) {
9690: if (!grep(/^\Q$item\E$/,@current)) {
9691: $changes{$type}{$setting} = 1;
9692: last;
1.82 raeburn 9693: }
9694: }
9695: } else {
1.83 raeburn 9696: $changes{$type}{$setting} = 1;
1.69 raeburn 9697: }
1.83 raeburn 9698: } elsif (@new > 0) {
9699: $changes{$type}{$setting} = 1;
1.69 raeburn 9700: }
9701: }
9702: }
9703: if (keys(%changes) > 0) {
1.81 raeburn 9704: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9705: my $putresult = &Apache::lonnet::put_dom('configuration',
9706: \%serverstatushash,$dom);
9707: if ($putresult eq 'ok') {
9708: $resulttext .= &mt('Changes made:').'<ul>';
9709: foreach my $type (@pages) {
1.84 raeburn 9710: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9711: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9712: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9713: if ($newserverstatus{$type}{'namedusers'} eq '') {
9714: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9715: } else {
9716: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9717: }
1.84 raeburn 9718: }
9719: if ($changes{$type}{'machines'}) {
1.69 raeburn 9720: if ($newserverstatus{$type}{'machines'} eq '') {
9721: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9722: } else {
9723: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9724: }
9725:
9726: }
9727: $resulttext .= '</ul></li>';
9728: }
9729: }
9730: $resulttext .= '</ul>';
9731: } else {
9732: $resulttext = '<span class="LC_error">'.
9733: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9734:
9735: }
9736: } else {
9737: $resulttext = &mt('No changes made to access to server status pages');
9738: }
9739: return $resulttext;
9740: }
9741:
1.118 jms 9742: sub modify_helpsettings {
1.122 jms 9743: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9744: my ($resulttext,$errors,%changes,%helphash);
9745: my %defaultchecked = ('submitbugs' => 'on');
9746: my @offon = ('off','on');
1.118 jms 9747: my @toggles = ('submitbugs');
9748: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9749: foreach my $item (@toggles) {
1.166 raeburn 9750: if ($defaultchecked{$item} eq 'on') {
9751: if ($domconfig{'helpsettings'}{$item} eq '') {
9752: if ($env{'form.'.$item} eq '0') {
9753: $changes{$item} = 1;
9754: }
9755: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9756: $changes{$item} = 1;
9757: }
9758: } elsif ($defaultchecked{$item} eq 'off') {
9759: if ($domconfig{'helpsettings'}{$item} eq '') {
9760: if ($env{'form.'.$item} eq '1') {
9761: $changes{$item} = 1;
9762: }
9763: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9764: $changes{$item} = 1;
9765: }
9766: }
1.210 raeburn 9767: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9768: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9769: }
9770: }
1.118 jms 9771: }
1.123 jms 9772: my $putresult;
9773: if (keys(%changes) > 0) {
1.166 raeburn 9774: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9775: if ($putresult eq 'ok') {
1.166 raeburn 9776: $resulttext = &mt('Changes made:').'<ul>';
9777: foreach my $item (sort(keys(%changes))) {
9778: if ($item eq 'submitbugs') {
9779: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9780: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9781: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9782: }
9783: }
9784: $resulttext .= '</ul>';
9785: } else {
9786: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9787: $errors .= '<li><span class="LC_error">'.
9788: &mt('An error occurred storing the settings: [_1]',
9789: $putresult).'</span></li>';
1.166 raeburn 9790: }
1.118 jms 9791: }
9792: if ($errors) {
1.168 raeburn 9793: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9794: $errors.'</ul>';
9795: }
9796: return $resulttext;
9797: }
9798:
1.121 raeburn 9799: sub modify_coursedefaults {
1.212 raeburn 9800: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9801: my ($resulttext,$errors,%changes,%defaultshash);
9802: my %defaultchecked = ('canuse_pdfforms' => 'off');
9803: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9804: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9805: 'uploadquota_community','uploadquota_textbook');
9806: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9807: my %staticdefaults = (
9808: anonsurvey_threshold => 10,
9809: uploadquota => 500,
9810: );
1.121 raeburn 9811:
9812: $defaultshash{'coursedefaults'} = {};
9813:
9814: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9815: if ($domconfig{'coursedefaults'} eq '') {
9816: $domconfig{'coursedefaults'} = {};
9817: }
9818: }
9819:
9820: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9821: foreach my $item (@toggles) {
9822: if ($defaultchecked{$item} eq 'on') {
9823: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9824: ($env{'form.'.$item} eq '0')) {
9825: $changes{$item} = 1;
1.192 raeburn 9826: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9827: $changes{$item} = 1;
9828: }
9829: } elsif ($defaultchecked{$item} eq 'off') {
9830: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9831: ($env{'form.'.$item} eq '1')) {
9832: $changes{$item} = 1;
9833: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9834: $changes{$item} = 1;
9835: }
9836: }
9837: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9838: }
1.198 raeburn 9839: foreach my $item (@numbers) {
9840: my ($currdef,$newdef);
1.208 raeburn 9841: $newdef = $env{'form.'.$item};
1.198 raeburn 9842: if ($item eq 'anonsurvey_threshold') {
9843: $currdef = $domconfig{'coursedefaults'}{$item};
9844: $newdef =~ s/\D//g;
9845: if ($newdef eq '' || $newdef < 1) {
9846: $newdef = 1;
9847: }
9848: $defaultshash{'coursedefaults'}{$item} = $newdef;
9849: } else {
9850: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9851: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9852: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9853: }
9854: $newdef =~ s/[^\w.\-]//g;
9855: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9856: }
9857: if ($currdef ne $newdef) {
9858: my $staticdef;
9859: if ($item eq 'anonsurvey_threshold') {
9860: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9861: $changes{$item} = 1;
9862: }
9863: } else {
9864: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9865: $changes{'uploadquota'} = 1;
9866: }
9867: }
1.139 raeburn 9868: }
9869: }
1.231 raeburn 9870:
1.192 raeburn 9871: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 9872: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 9873: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 9874: $unofficialcreds =~ s/[^\d.]+//g;
9875: my $textbookcreds = $env{'form.textbook_credits'};
9876: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 9877: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9878: ($env{'form.coursecredits'} eq '1')) {
9879: $changes{'coursecredits'} = 1;
9880: } else {
9881: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 9882: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9883: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 9884: $changes{'coursecredits'} = 1;
9885: }
9886: }
9887: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9888: official => $officialcreds,
9889: unofficial => $unofficialcreds,
1.216 raeburn 9890: textbook => $textbookcreds,
1.192 raeburn 9891: }
1.121 raeburn 9892: }
9893: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9894: $dom);
9895: if ($putresult eq 'ok') {
9896: if (keys(%changes) > 0) {
1.213 raeburn 9897: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 9898: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 9899: ($changes{'uploadquota'})) {
1.192 raeburn 9900: if ($changes{'canuse_pdfforms'}) {
9901: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9902: }
9903: if ($changes{'coursecredits'}) {
9904: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9905: $domdefaults{'officialcredits'} =
9906: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9907: $domdefaults{'unofficialcredits'} =
9908: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 9909: $domdefaults{'textbookcredits'} =
9910: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9911: }
9912: }
1.198 raeburn 9913: if ($changes{'uploadquota'}) {
9914: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9915: foreach my $type (@types) {
9916: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9917: }
9918: }
9919: }
1.121 raeburn 9920: my $cachetime = 24*60*60;
9921: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9922: if (ref($lastactref) eq 'HASH') {
9923: $lastactref->{'domdefaults'} = 1;
9924: }
1.121 raeburn 9925: }
9926: $resulttext = &mt('Changes made:').'<ul>';
9927: foreach my $item (sort(keys(%changes))) {
9928: if ($item eq 'canuse_pdfforms') {
9929: if ($env{'form.'.$item} eq '1') {
9930: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9931: } else {
9932: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9933: }
1.139 raeburn 9934: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9935: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9936: } elsif ($item eq 'uploadquota') {
9937: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9938: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9939: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9940: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9941: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9942:
1.198 raeburn 9943: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9944: '</ul>'.
9945: '</li>';
9946: } else {
9947: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9948: }
1.192 raeburn 9949: } elsif ($item eq 'coursecredits') {
9950: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9951: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9952: ($domdefaults{'unofficialcredits'} eq '') &&
9953: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9954: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9955: } else {
9956: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9957: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9958: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9959: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9960: '</ul>'.
9961: '</li>';
9962: }
9963: } else {
9964: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9965: }
1.140 raeburn 9966: }
1.121 raeburn 9967: }
9968: $resulttext .= '</ul>';
9969: } else {
9970: $resulttext = &mt('No changes made to course defaults');
9971: }
9972: } else {
9973: $resulttext = '<span class="LC_error">'.
9974: &mt('An error occurred: [_1]',$putresult).'</span>';
9975: }
9976: return $resulttext;
9977: }
9978:
1.231 raeburn 9979: sub modify_selfenrollment {
9980: my ($dom,$lastactref,%domconfig) = @_;
9981: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
9982: my @types = ('official','unofficial','community','textbook');
9983: my %titles = &tool_titles();
1.232 raeburn 9984: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
9985: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 9986: $ordered{'default'} = ['types','registered','approval','limit'];
9987:
9988: my (%roles,%shown,%toplevel);
9989: $roles{'0'} = &Apache::lonnet::plaintext('dc');
9990:
9991: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
9992: if ($domconfig{'selfenrollment'} eq '') {
9993: $domconfig{'selfenrollment'} = {};
9994: }
9995: }
9996: %toplevel = (
9997: admin => 'Configuration Rights',
9998: default => 'Default settings',
9999: validation => 'Validation of self-enrollment requests',
10000: );
1.233 raeburn 10001: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10002:
10003: if (ref($ordered{'admin'}) eq 'ARRAY') {
10004: foreach my $item (@{$ordered{'admin'}}) {
10005: foreach my $type (@types) {
10006: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10007: $selfenrollhash{'admin'}{$type}{$item} = 1;
10008: } else {
10009: $selfenrollhash{'admin'}{$type}{$item} = 0;
10010: }
10011: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10012: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10013: if ($selfenrollhash{'admin'}{$type}{$item} ne
10014: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10015: push(@{$changes{'admin'}{$type}},$item);
10016: }
10017: } else {
10018: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10019: push(@{$changes{'admin'}{$type}},$item);
10020: }
10021: }
10022: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10023: push(@{$changes{'admin'}{$type}},$item);
10024: }
10025: }
10026: }
10027: }
10028:
10029: foreach my $item (@{$ordered{'default'}}) {
10030: foreach my $type (@types) {
10031: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10032: if ($item eq 'types') {
10033: unless (($value eq 'all') || ($value eq 'dom')) {
10034: $value = '';
10035: }
10036: } elsif ($item eq 'registered') {
10037: unless ($value eq '1') {
10038: $value = 0;
10039: }
10040: } elsif ($item eq 'approval') {
10041: unless ($value =~ /^[012]$/) {
10042: $value = 0;
10043: }
10044: } else {
10045: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10046: $value = 'none';
10047: }
10048: }
10049: $selfenrollhash{'default'}{$type}{$item} = $value;
10050: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10051: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10052: if ($selfenrollhash{'default'}{$type}{$item} ne
10053: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10054: push(@{$changes{'default'}{$type}},$item);
10055: }
10056: } else {
10057: push(@{$changes{'default'}{$type}},$item);
10058: }
10059: } else {
10060: push(@{$changes{'default'}{$type}},$item);
10061: }
10062: if ($item eq 'limit') {
10063: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10064: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10065: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10066: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10067: }
10068: } else {
10069: $selfenrollhash{'default'}{$type}{'cap'} = '';
10070: }
10071: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10072: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10073: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10074: push(@{$changes{'default'}{$type}},'cap');
10075: }
10076: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10077: push(@{$changes{'default'}{$type}},'cap');
10078: }
10079: }
10080: }
10081: }
10082:
10083: foreach my $item (@{$itemsref}) {
10084: if ($item eq 'fields') {
10085: my @changed;
10086: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10087: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10088: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10089: }
10090: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10091: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10092: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10093: $domconfig{'selfenrollment'}{'validation'}{$item});
10094: } else {
10095: @changed = @{$selfenrollhash{'validation'}{$item}};
10096: }
10097: } else {
10098: @changed = @{$selfenrollhash{'validation'}{$item}};
10099: }
10100: if (@changed) {
10101: if ($selfenrollhash{'validation'}{$item}) {
10102: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10103: } else {
10104: $changes{'validation'}{$item} = &mt('None');
10105: }
10106: }
10107: } else {
10108: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10109: if ($item eq 'markup') {
10110: if ($env{'form.selfenroll_validation_'.$item}) {
10111: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10112: }
10113: }
10114: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10115: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10116: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10117: }
10118: }
10119: }
10120: }
10121:
10122: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10123: $dom);
10124: if ($putresult eq 'ok') {
10125: if (keys(%changes) > 0) {
10126: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10127: $resulttext = &mt('Changes made:').'<ul>';
10128: foreach my $key ('admin','default','validation') {
10129: if (ref($changes{$key}) eq 'HASH') {
10130: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10131: if ($key eq 'validation') {
10132: foreach my $item (@{$itemsref}) {
10133: if (exists($changes{$key}{$item})) {
10134: if ($item eq 'markup') {
10135: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10136: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10137: } else {
10138: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10139: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10140: }
10141: }
10142: }
10143: } else {
10144: foreach my $type (@types) {
10145: if ($type eq 'community') {
10146: $roles{'1'} = &mt('Community personnel');
10147: } else {
10148: $roles{'1'} = &mt('Course personnel');
10149: }
10150: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10151: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10152: if ($key eq 'admin') {
10153: my @mgrdc = ();
10154: if (ref($ordered{$key}) eq 'ARRAY') {
10155: foreach my $item (@{$ordered{'admin'}}) {
10156: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10157: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10158: push(@mgrdc,$item);
10159: }
10160: }
10161: }
10162: if (@mgrdc) {
10163: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10164: } else {
10165: delete($domdefaults{$type.'selfenrolladmdc'});
10166: }
10167: }
10168: } else {
10169: if (ref($ordered{$key}) eq 'ARRAY') {
10170: foreach my $item (@{$ordered{$key}}) {
10171: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10172: $domdefaults{$type.'selfenroll'.$item} =
10173: $selfenrollhash{$key}{$type}{$item};
10174: }
10175: }
10176: }
10177: }
10178: }
1.231 raeburn 10179: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10180: foreach my $item (@{$ordered{$key}}) {
10181: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10182: $resulttext .= '<li>';
10183: if ($key eq 'admin') {
10184: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10185: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10186: } else {
10187: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10188: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10189: }
10190: $resulttext .= '</li>';
10191: }
10192: }
10193: $resulttext .= '</ul></li>';
10194: }
10195: }
10196: $resulttext .= '</ul></li>';
10197: }
10198: }
1.232 raeburn 10199: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10200: my $cachetime = 24*60*60;
10201: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10202: if (ref($lastactref) eq 'HASH') {
10203: $lastactref->{'domdefaults'} = 1;
10204: }
10205: }
1.231 raeburn 10206: }
10207: $resulttext .= '</ul>';
10208: } else {
10209: $resulttext = &mt('No changes made to self-enrollment settings');
10210: }
10211: } else {
10212: $resulttext = '<span class="LC_error">'.
10213: &mt('An error occurred: [_1]',$putresult).'</span>';
10214: }
10215: return $resulttext;
10216: }
10217:
1.137 raeburn 10218: sub modify_usersessions {
1.212 raeburn 10219: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10220: my @hostingtypes = ('version','excludedomain','includedomain');
10221: my @offloadtypes = ('primary','default');
10222: my %types = (
10223: remote => \@hostingtypes,
10224: hosted => \@hostingtypes,
10225: spares => \@offloadtypes,
10226: );
10227: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10228: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10229: my (%by_ip,%by_location,@intdoms);
10230: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10231: my @locations = sort(keys(%by_location));
1.137 raeburn 10232: my (%defaultshash,%changes);
10233: foreach my $prefix (@prefixes) {
10234: $defaultshash{'usersessions'}{$prefix} = {};
10235: }
1.212 raeburn 10236: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10237: my $resulttext;
1.138 raeburn 10238: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10239: foreach my $prefix (@prefixes) {
1.145 raeburn 10240: next if ($prefix eq 'spares');
10241: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10242: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10243: if ($type eq 'version') {
10244: my $value = $env{'form.'.$prefix.'_'.$type};
10245: my $okvalue;
10246: if ($value ne '') {
10247: if (grep(/^\Q$value\E$/,@lcversions)) {
10248: $okvalue = $value;
10249: }
10250: }
10251: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10252: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10253: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10254: if ($inuse == 0) {
10255: $changes{$prefix}{$type} = 1;
10256: } else {
10257: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10258: $changes{$prefix}{$type} = 1;
10259: }
10260: if ($okvalue ne '') {
10261: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10262: }
10263: }
10264: } else {
10265: if (($inuse == 1) && ($okvalue ne '')) {
10266: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10267: $changes{$prefix}{$type} = 1;
10268: }
10269: }
10270: } else {
10271: if (($inuse == 1) && ($okvalue ne '')) {
10272: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10273: $changes{$prefix}{$type} = 1;
10274: }
10275: }
10276: } else {
10277: if (($inuse == 1) && ($okvalue ne '')) {
10278: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10279: $changes{$prefix}{$type} = 1;
10280: }
10281: }
10282: } else {
10283: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10284: my @okvals;
10285: foreach my $val (@vals) {
1.138 raeburn 10286: if ($val =~ /:/) {
10287: my @items = split(/:/,$val);
10288: foreach my $item (@items) {
10289: if (ref($by_location{$item}) eq 'ARRAY') {
10290: push(@okvals,$item);
10291: }
10292: }
10293: } else {
10294: if (ref($by_location{$val}) eq 'ARRAY') {
10295: push(@okvals,$val);
10296: }
1.137 raeburn 10297: }
10298: }
10299: @okvals = sort(@okvals);
10300: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10301: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10302: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10303: if ($inuse == 0) {
10304: $changes{$prefix}{$type} = 1;
10305: } else {
10306: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10307: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10308: if (@changed > 0) {
10309: $changes{$prefix}{$type} = 1;
10310: }
10311: }
10312: } else {
10313: if ($inuse == 1) {
10314: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10315: $changes{$prefix}{$type} = 1;
10316: }
10317: }
10318: } else {
10319: if ($inuse == 1) {
10320: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10321: $changes{$prefix}{$type} = 1;
10322: }
10323: }
10324: } else {
10325: if ($inuse == 1) {
10326: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10327: $changes{$prefix}{$type} = 1;
10328: }
10329: }
10330: }
10331: }
10332: }
1.145 raeburn 10333:
10334: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10335: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10336: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10337: my $savespares;
10338:
10339: foreach my $lonhost (sort(keys(%servers))) {
10340: my $serverhomeID =
10341: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10342: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10343: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10344: my %spareschg;
10345: foreach my $type (@{$types{'spares'}}) {
10346: my @okspares;
10347: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10348: foreach my $server (@checked) {
1.152 raeburn 10349: if (&Apache::lonnet::hostname($server) ne '') {
10350: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10351: unless (grep(/^\Q$server\E$/,@okspares)) {
10352: push(@okspares,$server);
10353: }
1.145 raeburn 10354: }
10355: }
10356: }
10357: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10358: my $newspare;
1.152 raeburn 10359: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10360: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10361: $newspare = $new;
10362: }
10363: }
1.152 raeburn 10364: my @spares;
10365: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10366: @spares = sort(@okspares,$newspare);
10367: } else {
10368: @spares = sort(@okspares);
10369: }
10370: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10371: if (ref($spareid{$lonhost}) eq 'HASH') {
10372: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10373: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10374: if (@diffs > 0) {
10375: $spareschg{$type} = 1;
10376: }
10377: }
10378: }
10379: }
10380: if (keys(%spareschg) > 0) {
10381: $changes{'spares'}{$lonhost} = \%spareschg;
10382: }
10383: }
10384:
10385: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10386: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10387: if (ref($changes{'spares'}) eq 'HASH') {
10388: if (keys(%{$changes{'spares'}}) > 0) {
10389: $savespares = 1;
10390: }
10391: }
10392: } else {
10393: $savespares = 1;
10394: }
10395: }
10396:
1.147 raeburn 10397: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10398: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10399: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10400: $dom);
10401: if ($putresult eq 'ok') {
10402: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10403: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10404: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10405: }
10406: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10407: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10408: }
10409: }
10410: my $cachetime = 24*60*60;
10411: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10412: if (ref($lastactref) eq 'HASH') {
10413: $lastactref->{'domdefaults'} = 1;
10414: }
1.147 raeburn 10415: if (keys(%changes) > 0) {
10416: my %lt = &usersession_titles();
10417: $resulttext = &mt('Changes made:').'<ul>';
10418: foreach my $prefix (@prefixes) {
10419: if (ref($changes{$prefix}) eq 'HASH') {
10420: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10421: if ($prefix eq 'spares') {
10422: if (ref($changes{$prefix}) eq 'HASH') {
10423: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10424: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10425: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10426: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10427: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10428: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10429: foreach my $type (@{$types{$prefix}}) {
10430: if ($changes{$prefix}{$lonhost}{$type}) {
10431: my $offloadto = &mt('None');
10432: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10433: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10434: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10435: }
1.145 raeburn 10436: }
1.147 raeburn 10437: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10438: }
1.137 raeburn 10439: }
10440: }
1.147 raeburn 10441: $resulttext .= '</li>';
1.137 raeburn 10442: }
10443: }
1.147 raeburn 10444: } else {
10445: foreach my $type (@{$types{$prefix}}) {
10446: if (defined($changes{$prefix}{$type})) {
10447: my $newvalue;
10448: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10449: if (ref($defaultshash{'usersessions'}{$prefix})) {
10450: if ($type eq 'version') {
10451: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10452: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10453: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10454: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10455: }
1.145 raeburn 10456: }
10457: }
10458: }
1.147 raeburn 10459: if ($newvalue eq '') {
10460: if ($type eq 'version') {
10461: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10462: } else {
10463: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10464: }
1.145 raeburn 10465: } else {
1.147 raeburn 10466: if ($type eq 'version') {
10467: $newvalue .= ' '.&mt('(or later)');
10468: }
10469: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10470: }
1.137 raeburn 10471: }
10472: }
10473: }
1.147 raeburn 10474: $resulttext .= '</ul>';
1.137 raeburn 10475: }
10476: }
1.147 raeburn 10477: $resulttext .= '</ul>';
10478: } else {
10479: $resulttext = $nochgmsg;
1.137 raeburn 10480: }
10481: } else {
10482: $resulttext = '<span class="LC_error">'.
10483: &mt('An error occurred: [_1]',$putresult).'</span>';
10484: }
10485: } else {
1.147 raeburn 10486: $resulttext = $nochgmsg;
1.137 raeburn 10487: }
10488: return $resulttext;
10489: }
10490:
1.150 raeburn 10491: sub modify_loadbalancing {
10492: my ($dom,%domconfig) = @_;
10493: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10494: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10495: my ($othertitle,$usertypes,$types) =
10496: &Apache::loncommon::sorted_inst_types($dom);
10497: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10498: my @sparestypes = ('primary','default');
10499: my %typetitles = &sparestype_titles();
10500: my $resulttext;
1.171 raeburn 10501: my (%currbalancer,%currtargets,%currrules,%existing);
10502: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10503: %existing = %{$domconfig{'loadbalancing'}};
10504: }
10505: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10506: \%currtargets,\%currrules);
10507: my ($saveloadbalancing,%defaultshash,%changes);
10508: my ($alltypes,$othertypes,$titles) =
10509: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10510: my %ruletitles = &offloadtype_text();
10511: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10512: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10513: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10514: if ($balancer eq '') {
10515: next;
10516: }
1.210 raeburn 10517: if (!exists($servers{$balancer})) {
1.171 raeburn 10518: if (exists($currbalancer{$balancer})) {
10519: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10520: }
1.171 raeburn 10521: next;
10522: }
10523: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10524: push(@{$changes{'delete'}},$balancer);
10525: next;
10526: }
10527: if (!exists($currbalancer{$balancer})) {
10528: push(@{$changes{'add'}},$balancer);
10529: }
10530: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10531: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10532: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10533: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10534: $saveloadbalancing = 1;
10535: }
10536: foreach my $sparetype (@sparestypes) {
10537: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10538: my @offloadto;
10539: foreach my $target (@targets) {
10540: if (($servers{$target}) && ($target ne $balancer)) {
10541: if ($sparetype eq 'default') {
10542: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10543: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10544: }
10545: }
1.171 raeburn 10546: unless(grep(/^\Q$target\E$/,@offloadto)) {
10547: push(@offloadto,$target);
10548: }
1.150 raeburn 10549: }
1.171 raeburn 10550: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10551: }
10552: }
1.171 raeburn 10553: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10554: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10555: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10556: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10557: if (@targetdiffs > 0) {
1.171 raeburn 10558: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10559: }
1.171 raeburn 10560: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10561: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10562: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10563: }
10564: }
10565: }
10566: } else {
1.171 raeburn 10567: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10568: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10569: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10570: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10571: $changes{'curr'}{$balancer}{'targets'} = 1;
10572: }
1.150 raeburn 10573: }
10574: }
1.210 raeburn 10575: }
1.150 raeburn 10576: }
10577: my $ishomedom;
1.171 raeburn 10578: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10579: $ishomedom = 1;
1.150 raeburn 10580: }
10581: if (ref($alltypes) eq 'ARRAY') {
10582: foreach my $type (@{$alltypes}) {
10583: my $rule;
1.210 raeburn 10584: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10585: (!$ishomedom)) {
1.171 raeburn 10586: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10587: }
10588: if ($rule eq 'specific') {
10589: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10590: }
1.171 raeburn 10591: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10592: if (ref($currrules{$balancer}) eq 'HASH') {
10593: if ($rule ne $currrules{$balancer}{$type}) {
10594: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10595: }
10596: } elsif ($rule ne '') {
1.171 raeburn 10597: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10598: }
10599: }
10600: }
1.171 raeburn 10601: }
10602: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10603: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10604: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10605: $defaultshash{'loadbalancing'} = {};
10606: }
10607: my $putresult = &Apache::lonnet::put_dom('configuration',
10608: \%defaultshash,$dom);
10609: if ($putresult eq 'ok') {
10610: if (keys(%changes) > 0) {
10611: if (ref($changes{'delete'}) eq 'ARRAY') {
10612: foreach my $balancer (sort(@{$changes{'delete'}})) {
10613: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 10614: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10615: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10616: }
1.171 raeburn 10617: }
10618: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10619: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10620: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10621: }
10622: }
10623: if (ref($changes{'curr'}) eq 'HASH') {
10624: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10625: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10626: if ($changes{'curr'}{$balancer}{'targets'}) {
10627: my %offloadstr;
10628: foreach my $sparetype (@sparestypes) {
10629: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10630: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10631: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10632: }
10633: }
1.150 raeburn 10634: }
1.171 raeburn 10635: if (keys(%offloadstr) == 0) {
10636: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10637: } else {
1.171 raeburn 10638: my $showoffload;
10639: foreach my $sparetype (@sparestypes) {
10640: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10641: if (defined($offloadstr{$sparetype})) {
10642: $showoffload .= $offloadstr{$sparetype};
10643: } else {
10644: $showoffload .= &mt('None');
10645: }
10646: $showoffload .= (' 'x3);
10647: }
10648: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10649: }
10650: }
10651: }
1.171 raeburn 10652: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10653: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10654: foreach my $type (@{$alltypes}) {
10655: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10656: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10657: my $balancetext;
10658: if ($rule eq '') {
10659: $balancetext = $ruletitles{'default'};
1.209 raeburn 10660: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10661: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 10662: $balancetext = $ruletitles{$rule};
10663: } else {
10664: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10665: }
1.210 raeburn 10666: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10667: }
10668: }
10669: }
10670: }
1.215 raeburn 10671: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 10672: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10673: }
1.171 raeburn 10674: }
10675: if ($resulttext ne '') {
10676: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10677: } else {
10678: $resulttext = $nochgmsg;
10679: }
10680: } else {
1.171 raeburn 10681: $resulttext = $nochgmsg;
1.150 raeburn 10682: }
10683: } else {
1.171 raeburn 10684: $resulttext = '<span class="LC_error">'.
10685: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10686: }
10687: } else {
1.171 raeburn 10688: $resulttext = $nochgmsg;
1.150 raeburn 10689: }
10690: return $resulttext;
10691: }
10692:
1.48 raeburn 10693: sub recurse_check {
10694: my ($chkcats,$categories,$depth,$name) = @_;
10695: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10696: my $chg = 0;
10697: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10698: my $category = $chkcats->[$depth]{$name}[$j];
10699: my $item;
10700: if ($category eq '') {
10701: $chg ++;
10702: } else {
10703: my $deeper = $depth + 1;
10704: $item = &escape($category).':'.&escape($name).':'.$depth;
10705: if ($chg) {
10706: $categories->{$item} -= $chg;
10707: }
10708: &recurse_check($chkcats,$categories,$deeper,$category);
10709: $deeper --;
10710: }
10711: }
10712: }
10713: return;
10714: }
10715:
10716: sub recurse_cat_deletes {
10717: my ($item,$coursecategories,$deletions) = @_;
10718: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10719: my $subdepth = $depth + 1;
10720: if (ref($coursecategories) eq 'HASH') {
10721: foreach my $subitem (keys(%{$coursecategories})) {
10722: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10723: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10724: delete($coursecategories->{$subitem});
10725: $deletions->{$subitem} = 1;
10726: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10727: }
1.48 raeburn 10728: }
10729: }
10730: return;
10731: }
10732:
1.125 raeburn 10733: sub get_active_dcs {
10734: my ($dom) = @_;
1.191 raeburn 10735: my $now = time;
10736: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10737: my %domcoords;
10738: my $numdcs = 0;
10739: foreach my $server (keys(%dompersonnel)) {
10740: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10741: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10742: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10743: }
10744: }
10745: return %domcoords;
10746: }
10747:
10748: sub active_dc_picker {
1.191 raeburn 10749: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 10750: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10751: my @domcoord = keys(%domcoords);
10752: if (keys(%currhash)) {
10753: foreach my $dc (keys(%currhash)) {
10754: unless (exists($domcoords{$dc})) {
10755: push(@domcoord,$dc);
10756: }
10757: }
10758: }
10759: @domcoord = sort(@domcoord);
1.210 raeburn 10760: my $numdcs = scalar(@domcoord);
1.191 raeburn 10761: my $rows = 0;
10762: my $table;
1.125 raeburn 10763: if ($numdcs > 1) {
1.191 raeburn 10764: $table = '<table>';
10765: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10766: my $rem = $i%($numinrow);
10767: if ($rem == 0) {
10768: if ($i > 0) {
1.191 raeburn 10769: $table .= '</tr>';
1.125 raeburn 10770: }
1.191 raeburn 10771: $table .= '<tr>';
10772: $rows ++;
1.125 raeburn 10773: }
1.191 raeburn 10774: my $check = '';
10775: if ($inputtype eq 'radio') {
10776: if (keys(%currhash) == 0) {
10777: if (!$i) {
10778: $check = ' checked="checked"';
10779: }
10780: } elsif (exists($currhash{$domcoord[$i]})) {
10781: $check = ' checked="checked"';
10782: }
10783: } else {
10784: if (exists($currhash{$domcoord[$i]})) {
10785: $check = ' checked="checked"';
1.125 raeburn 10786: }
10787: }
1.191 raeburn 10788: if ($i == @domcoord - 1) {
1.125 raeburn 10789: my $colsleft = $numinrow - $rem;
10790: if ($colsleft > 1) {
1.191 raeburn 10791: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10792: } else {
1.191 raeburn 10793: $table .= '<td class="LC_left_item">';
1.125 raeburn 10794: }
10795: } else {
1.191 raeburn 10796: $table .= '<td class="LC_left_item">';
10797: }
10798: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10799: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10800: $table .= '<span class="LC_nobreak"><label>'.
10801: '<input type="'.$inputtype.'" name="'.$name.'"'.
10802: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10803: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 10804: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 10805: }
1.219 raeburn 10806: $table .= '</label></span></td>';
1.191 raeburn 10807: }
10808: $table .= '</tr></table>';
10809: } elsif ($numdcs == 1) {
1.219 raeburn 10810: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10811: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 10812: if ($inputtype eq 'radio') {
1.219 raeburn 10813: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10814: if ($user ne $dcname.':'.$dcdom) {
10815: $table .= ' ('.$dcname.':'.$dcdom.')';
10816: }
1.191 raeburn 10817: } else {
10818: my $check;
10819: if (exists($currhash{$domcoord[0]})) {
10820: $check = ' checked="checked"';
1.125 raeburn 10821: }
1.219 raeburn 10822: $table .= '<span class="LC_nobreak"><label>'.
10823: '<input type="checkbox" name="'.$name.'" '.
10824: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10825: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 10826: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 10827: }
1.220 raeburn 10828: $table .= '</label></span>';
1.191 raeburn 10829: $rows ++;
1.125 raeburn 10830: }
10831: }
1.191 raeburn 10832: return ($numdcs,$table,$rows);
1.125 raeburn 10833: }
10834:
1.137 raeburn 10835: sub usersession_titles {
10836: return &Apache::lonlocal::texthash(
10837: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10838: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10839: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10840: version => 'LON-CAPA version requirement',
1.138 raeburn 10841: excludedomain => 'Allow all, but exclude specific domains',
10842: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10843: primary => 'Primary (checked first)',
1.154 raeburn 10844: default => 'Default',
1.137 raeburn 10845: );
10846: }
10847:
1.152 raeburn 10848: sub id_for_thisdom {
10849: my (%servers) = @_;
10850: my %altids;
10851: foreach my $server (keys(%servers)) {
10852: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10853: if ($serverhome ne $server) {
10854: $altids{$serverhome} = $server;
10855: }
10856: }
10857: return %altids;
10858: }
10859:
1.150 raeburn 10860: sub count_servers {
10861: my ($currbalancer,%servers) = @_;
10862: my (@spares,$numspares);
10863: foreach my $lonhost (sort(keys(%servers))) {
10864: next if ($currbalancer eq $lonhost);
10865: push(@spares,$lonhost);
10866: }
10867: if ($currbalancer) {
10868: $numspares = scalar(@spares);
10869: } else {
10870: $numspares = scalar(@spares) - 1;
10871: }
10872: return ($numspares,@spares);
10873: }
10874:
10875: sub lonbalance_targets_js {
1.171 raeburn 10876: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 10877: my $select = &mt('Select');
10878: my ($alltargets,$allishome,$allinsttypes,@alltypes);
10879: if (ref($servers) eq 'HASH') {
10880: $alltargets = join("','",sort(keys(%{$servers})));
10881: my @homedoms;
10882: foreach my $server (sort(keys(%{$servers}))) {
10883: if (&Apache::lonnet::host_domain($server) eq $dom) {
10884: push(@homedoms,'1');
10885: } else {
10886: push(@homedoms,'0');
10887: }
10888: }
10889: $allishome = join("','",@homedoms);
10890: }
10891: if (ref($types) eq 'ARRAY') {
10892: if (@{$types} > 0) {
10893: @alltypes = @{$types};
10894: }
10895: }
10896: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
10897: $allinsttypes = join("','",@alltypes);
1.171 raeburn 10898: my (%currbalancer,%currtargets,%currrules,%existing);
10899: if (ref($settings) eq 'HASH') {
10900: %existing = %{$settings};
10901: }
10902: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
10903: \%currtargets,\%currrules);
1.210 raeburn 10904: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 10905: return <<"END";
10906:
10907: <script type="text/javascript">
10908: // <![CDATA[
10909:
1.171 raeburn 10910: currBalancers = new Array('$balancers');
10911:
10912: function toggleTargets(balnum) {
10913: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10914: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
10915: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
10916: var prevbalancer = prevhostitem.value;
10917: var baltotal = document.getElementById('loadbalancing_total').value;
10918: prevhostitem.value = balancer;
10919: if (prevbalancer != '') {
10920: var prevIdx = currBalancers.indexOf(prevbalancer);
10921: if (prevIdx != -1) {
10922: currBalancers.splice(prevIdx,1);
10923: }
10924: }
1.150 raeburn 10925: if (balancer == '') {
1.171 raeburn 10926: hideSpares(balnum);
1.150 raeburn 10927: } else {
1.171 raeburn 10928: var currIdx = currBalancers.indexOf(balancer);
10929: if (currIdx == -1) {
10930: currBalancers.push(balancer);
10931: }
1.150 raeburn 10932: var homedoms = new Array('$allishome');
1.171 raeburn 10933: var ishomedom = homedoms[lonhostitem.selectedIndex];
10934: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 10935: }
1.171 raeburn 10936: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 10937: return;
10938: }
10939:
1.171 raeburn 10940: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 10941: var alltargets = new Array('$alltargets');
10942: var insttypes = new Array('$allinsttypes');
1.151 raeburn 10943: var offloadtypes = new Array('primary','default');
10944:
1.171 raeburn 10945: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
10946: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 10947:
1.151 raeburn 10948: for (var i=0; i<offloadtypes.length; i++) {
10949: var count = 0;
10950: for (var j=0; j<alltargets.length; j++) {
10951: if (alltargets[j] != balancer) {
1.171 raeburn 10952: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
10953: item.value = alltargets[j];
10954: item.style.textAlign='left';
10955: item.style.textFace='normal';
10956: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
10957: if (currBalancers.indexOf(alltargets[j]) == -1) {
10958: item.disabled = '';
10959: } else {
10960: item.disabled = 'disabled';
10961: item.checked = false;
10962: }
1.151 raeburn 10963: count ++;
10964: }
1.150 raeburn 10965: }
10966: }
1.151 raeburn 10967: for (var k=0; k<insttypes.length; k++) {
10968: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 10969: if (ishomedom == 1) {
1.171 raeburn 10970: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10971: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10972: } else {
1.171 raeburn 10973: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10974: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 10975: }
10976: } else {
1.171 raeburn 10977: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10978: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10979: }
1.151 raeburn 10980: if ((insttypes[k] != '_LC_external') &&
10981: ((insttypes[k] != '_LC_internetdom') ||
10982: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 10983: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
10984: item.options.length = 0;
10985: item.options[0] = new Option("","",true,true);
1.210 raeburn 10986: var idx = 0;
1.151 raeburn 10987: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 10988: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
10989: idx ++;
10990: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 10991: }
10992: }
10993: }
10994: }
10995: return;
10996: }
10997:
1.171 raeburn 10998: function hideSpares(balnum) {
1.150 raeburn 10999: var alltargets = new Array('$alltargets');
11000: var insttypes = new Array('$allinsttypes');
11001: var offloadtypes = new Array('primary','default');
11002:
1.171 raeburn 11003: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11004: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11005:
11006: var total = alltargets.length - 1;
11007: for (var i=0; i<offloadtypes; i++) {
11008: for (var j=0; j<total; j++) {
1.171 raeburn 11009: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11010: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11011: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11012: }
1.150 raeburn 11013: }
11014: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11015: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11016: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11017: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11018: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11019: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11020: }
11021: }
11022: return;
11023: }
11024:
1.171 raeburn 11025: function checkOffloads(item,balnum,type) {
1.150 raeburn 11026: var alltargets = new Array('$alltargets');
11027: var offloadtypes = new Array('primary','default');
11028: if (item.checked) {
11029: var total = alltargets.length - 1;
11030: var other;
11031: if (type == offloadtypes[0]) {
1.151 raeburn 11032: other = offloadtypes[1];
1.150 raeburn 11033: } else {
1.151 raeburn 11034: other = offloadtypes[0];
1.150 raeburn 11035: }
11036: for (var i=0; i<total; i++) {
1.171 raeburn 11037: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11038: if (server == item.value) {
1.171 raeburn 11039: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11040: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11041: }
11042: }
11043: }
11044: }
11045: return;
11046: }
11047:
1.171 raeburn 11048: function singleServerToggle(balnum,type) {
11049: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11050: if (offloadtoSelIdx == 0) {
1.171 raeburn 11051: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11052: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11053:
11054: } else {
1.171 raeburn 11055: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11056: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11057: }
11058: return;
11059: }
11060:
1.171 raeburn 11061: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11062: if (type == '_LC_external') {
1.171 raeburn 11063: return;
1.150 raeburn 11064: }
1.171 raeburn 11065: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11066: for (var i=0; i<typesRules.length; i++) {
11067: if (formname.elements[typesRules[i]].checked) {
11068: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11069: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11070: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11071: } else {
1.171 raeburn 11072: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11073: }
11074: }
11075: }
11076: return;
11077: }
11078:
11079: function balancerDeleteChange(balnum) {
11080: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11081: var baltotal = document.getElementById('loadbalancing_total').value;
11082: var addtarget;
11083: var removetarget;
11084: var action = 'delete';
11085: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11086: var lonhost = hostitem.value;
11087: var currIdx = currBalancers.indexOf(lonhost);
11088: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11089: if (currIdx != -1) {
11090: currBalancers.splice(currIdx,1);
11091: }
11092: addtarget = lonhost;
11093: } else {
11094: if (currIdx == -1) {
11095: currBalancers.push(lonhost);
11096: }
11097: removetarget = lonhost;
11098: action = 'undelete';
11099: }
11100: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11101: }
11102: return;
11103: }
11104:
11105: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11106: if (baltotal > 1) {
11107: var offloadtypes = new Array('primary','default');
11108: var alltargets = new Array('$alltargets');
11109: var insttypes = new Array('$allinsttypes');
11110: for (var i=0; i<baltotal; i++) {
11111: if (i != balnum) {
11112: for (var j=0; j<offloadtypes.length; j++) {
11113: var total = alltargets.length - 1;
11114: for (var k=0; k<total; k++) {
11115: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11116: var server = serveritem.value;
11117: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11118: if (server == addtarget) {
11119: serveritem.disabled = '';
11120: }
11121: }
11122: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11123: if (server == removetarget) {
11124: serveritem.disabled = 'disabled';
11125: serveritem.checked = false;
11126: }
11127: }
11128: }
11129: }
11130: for (var j=0; j<insttypes.length; j++) {
11131: if (insttypes[j] != '_LC_external') {
11132: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11133: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11134: var currSel = singleserver.selectedIndex;
11135: var currVal = singleserver.options[currSel].value;
11136: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11137: var numoptions = singleserver.options.length;
11138: var needsnew = 1;
11139: for (var k=0; k<numoptions; k++) {
11140: if (singleserver.options[k] == addtarget) {
11141: needsnew = 0;
11142: break;
11143: }
11144: }
11145: if (needsnew == 1) {
11146: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11147: }
11148: }
11149: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11150: singleserver.options.length = 0;
11151: if ((currVal) && (currVal != removetarget)) {
11152: singleserver.options[0] = new Option("","",false,false);
11153: } else {
11154: singleserver.options[0] = new Option("","",true,true);
11155: }
11156: var idx = 0;
11157: for (var m=0; m<alltargets.length; m++) {
11158: if (currBalancers.indexOf(alltargets[m]) == -1) {
11159: idx ++;
11160: if (currVal == alltargets[m]) {
11161: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11162: } else {
11163: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11164: }
11165: }
11166: }
11167: }
11168: }
11169: }
11170: }
1.150 raeburn 11171: }
11172: }
11173: }
11174: return;
11175: }
11176:
1.152 raeburn 11177: // ]]>
11178: </script>
11179:
11180: END
11181: }
11182:
11183: sub new_spares_js {
11184: my @sparestypes = ('primary','default');
11185: my $types = join("','",@sparestypes);
11186: my $select = &mt('Select');
11187: return <<"END";
11188:
11189: <script type="text/javascript">
11190: // <![CDATA[
11191:
11192: function updateNewSpares(formname,lonhost) {
11193: var types = new Array('$types');
11194: var include = new Array();
11195: var exclude = new Array();
11196: for (var i=0; i<types.length; i++) {
11197: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11198: for (var j=0; j<spareboxes.length; j++) {
11199: if (formname.elements[spareboxes[j]].checked) {
11200: exclude.push(formname.elements[spareboxes[j]].value);
11201: } else {
11202: include.push(formname.elements[spareboxes[j]].value);
11203: }
11204: }
11205: }
11206: for (var i=0; i<types.length; i++) {
11207: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11208: var selIdx = newSpare.selectedIndex;
11209: var currnew = newSpare.options[selIdx].value;
11210: var okSpares = new Array();
11211: for (var j=0; j<newSpare.options.length; j++) {
11212: var possible = newSpare.options[j].value;
11213: if (possible != '') {
11214: if (exclude.indexOf(possible) == -1) {
11215: okSpares.push(possible);
11216: } else {
11217: if (currnew == possible) {
11218: selIdx = 0;
11219: }
11220: }
11221: }
11222: }
11223: for (var k=0; k<include.length; k++) {
11224: if (okSpares.indexOf(include[k]) == -1) {
11225: okSpares.push(include[k]);
11226: }
11227: }
11228: okSpares.sort();
11229: newSpare.options.length = 0;
11230: if (selIdx == 0) {
11231: newSpare.options[0] = new Option("$select","",true,true);
11232: } else {
11233: newSpare.options[0] = new Option("$select","",false,false);
11234: }
11235: for (var m=0; m<okSpares.length; m++) {
11236: var idx = m+1;
11237: var selThis = 0;
11238: if (selIdx != 0) {
11239: if (okSpares[m] == currnew) {
11240: selThis = 1;
11241: }
11242: }
11243: if (selThis == 1) {
11244: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11245: } else {
11246: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11247: }
11248: }
11249: }
11250: return;
11251: }
11252:
11253: function checkNewSpares(lonhost,type) {
11254: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11255: var chosen = newSpare.options[newSpare.selectedIndex].value;
11256: if (chosen != '') {
11257: var othertype;
11258: var othernewSpare;
11259: if (type == 'primary') {
11260: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11261: }
11262: if (type == 'default') {
11263: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11264: }
11265: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11266: othernewSpare.selectedIndex = 0;
11267: }
11268: }
11269: return;
11270: }
11271:
11272: // ]]>
11273: </script>
11274:
11275: END
11276:
11277: }
11278:
11279: sub common_domprefs_js {
11280: return <<"END";
11281:
11282: <script type="text/javascript">
11283: // <![CDATA[
11284:
1.150 raeburn 11285: function getIndicesByName(formname,item) {
1.152 raeburn 11286: var group = new Array();
1.150 raeburn 11287: for (var i=0;i<formname.elements.length;i++) {
11288: if (formname.elements[i].name == item) {
1.152 raeburn 11289: group.push(formname.elements[i].id);
1.150 raeburn 11290: }
11291: }
1.152 raeburn 11292: return group;
1.150 raeburn 11293: }
11294:
11295: // ]]>
11296: </script>
11297:
11298: END
1.152 raeburn 11299:
1.150 raeburn 11300: }
11301:
1.165 raeburn 11302: sub recaptcha_js {
11303: my %lt = &captcha_phrases();
11304: return <<"END";
11305:
11306: <script type="text/javascript">
11307: // <![CDATA[
11308:
11309: function updateCaptcha(caller,context) {
11310: var privitem;
11311: var pubitem;
11312: var privtext;
11313: var pubtext;
11314: if (document.getElementById(context+'_recaptchapub')) {
11315: pubitem = document.getElementById(context+'_recaptchapub');
11316: } else {
11317: return;
11318: }
11319: if (document.getElementById(context+'_recaptchapriv')) {
11320: privitem = document.getElementById(context+'_recaptchapriv');
11321: } else {
11322: return;
11323: }
11324: if (document.getElementById(context+'_recaptchapubtxt')) {
11325: pubtext = document.getElementById(context+'_recaptchapubtxt');
11326: } else {
11327: return;
11328: }
11329: if (document.getElementById(context+'_recaptchaprivtxt')) {
11330: privtext = document.getElementById(context+'_recaptchaprivtxt');
11331: } else {
11332: return;
11333: }
11334: if (caller.checked) {
11335: if (caller.value == 'recaptcha') {
11336: pubitem.type = 'text';
11337: privitem.type = 'text';
11338: pubitem.size = '40';
11339: privitem.size = '40';
11340: pubtext.innerHTML = "$lt{'pub'}";
11341: privtext.innerHTML = "$lt{'priv'}";
11342: } else {
11343: pubitem.type = 'hidden';
11344: privitem.type = 'hidden';
11345: pubtext.innerHTML = '';
11346: privtext.innerHTML = '';
11347: }
11348: }
11349: return;
11350: }
11351:
11352: // ]]>
11353: </script>
11354:
11355: END
11356:
11357: }
11358:
1.236 raeburn 11359: sub toggle_display_js {
1.192 raeburn 11360: return <<"END";
11361:
11362: <script type="text/javascript">
11363: // <![CDATA[
11364:
1.236 raeburn 11365: function toggleDisplay(domForm,caller) {
11366: if (document.getElementById(caller)) {
11367: var divitem = document.getElementById(caller);
11368: var optionsElement = domForm.coursecredits;
11369: if (caller == 'emailoptions') {
11370: optionsElement = domForm.cancreate_email;
11371: }
11372: if (optionsElement.length) {
1.192 raeburn 11373: var currval;
1.236 raeburn 11374: for (var i=0; i<optionsElement.length; i++) {
11375: if (optionsElement[i].checked) {
11376: currval = optionsElement[i].value;
1.192 raeburn 11377: }
11378: }
11379: if (currval == 1) {
1.236 raeburn 11380: divitem.style.display = 'block';
1.192 raeburn 11381: } else {
1.236 raeburn 11382: divitem.style.display = 'none';
1.192 raeburn 11383: }
11384: }
11385: }
11386: return;
11387: }
11388:
11389: // ]]>
11390: </script>
11391:
11392: END
11393:
11394: }
11395:
1.165 raeburn 11396: sub captcha_phrases {
11397: return &Apache::lonlocal::texthash (
11398: priv => 'Private key',
11399: pub => 'Public key',
11400: original => 'original (CAPTCHA)',
11401: recaptcha => 'successor (ReCAPTCHA)',
11402: notused => 'unused',
11403: );
11404: }
11405:
1.205 raeburn 11406: sub devalidate_remote_domconfs {
1.212 raeburn 11407: my ($dom,$cachekeys) = @_;
11408: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 11409: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11410: my %thismachine;
11411: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 11412: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 11413: if (keys(%servers) > 1) {
11414: foreach my $server (keys(%servers)) {
11415: next if ($thismachine{$server});
1.212 raeburn 11416: my @cached;
11417: foreach my $name (@posscached) {
11418: if ($cachekeys->{$name}) {
11419: push(@cached,&escape($name).':'.&escape($dom));
11420: }
11421: }
11422: if (@cached) {
11423: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11424: }
1.205 raeburn 11425: }
11426: }
11427: return;
11428: }
11429:
1.3 raeburn 11430: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>