Annotation of loncom/interface/domainprefs.pm, revision 1.235
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.235 ! raeburn 4: # $Id: domainprefs.pm,v 1.234 2014/04/13 00:42:06 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.216 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 ! raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
216: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 217: 'coursedefaults','usersessions','loadbalancing',
1.231 raeburn 218: 'requestauthor','selfenrollment'],$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.141 raeburn 258: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 259: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 260: header => [{col1 => 'Setting',
261: col2 => 'Value'}],
1.230 raeburn 262: print => \&print_defaults,
263: modify => \&modify_defaults,
1.43 raeburn 264: },
1.30 raeburn 265: 'quotas' =>
1.197 raeburn 266: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 267: help => 'Domain_Configuration_Quotas',
1.77 raeburn 268: header => [{col1 => 'User affiliation',
1.72 raeburn 269: col2 => 'Available tools',
1.213 raeburn 270: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 271: print => \&print_quotas,
272: modify => \&modify_quotas,
1.30 raeburn 273: },
274: 'autoenroll' =>
275: { text => 'Auto-enrollment settings',
1.67 raeburn 276: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 277: header => [{col1 => 'Configuration setting',
278: col2 => 'Value(s)'}],
1.230 raeburn 279: print => \&print_autoenroll,
280: modify => \&modify_autoenroll,
1.30 raeburn 281: },
282: 'autoupdate' =>
283: { text => 'Auto-update settings',
1.67 raeburn 284: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 285: header => [{col1 => 'Setting',
286: col2 => 'Value',},
1.131 raeburn 287: {col1 => 'Setting',
288: col2 => 'Affiliation'},
1.43 raeburn 289: {col1 => 'User population',
1.227 bisitz 290: col2 => 'Updatable user data'}],
1.230 raeburn 291: print => \&print_autoupdate,
292: modify => \&modify_autoupdate,
1.30 raeburn 293: },
1.125 raeburn 294: 'autocreate' =>
295: { text => 'Auto-course creation settings',
296: help => 'Domain_Configuration_Auto_Creation',
297: header => [{col1 => 'Configuration Setting',
298: col2 => 'Value',}],
1.230 raeburn 299: print => \&print_autocreate,
300: modify => \&modify_autocreate,
1.125 raeburn 301: },
1.30 raeburn 302: 'directorysrch' =>
303: { text => 'Institutional directory searches',
1.67 raeburn 304: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 305: header => [{col1 => 'Setting',
306: col2 => 'Value',}],
1.230 raeburn 307: print => \&print_directorysrch,
308: modify => \&modify_directorysrch,
1.30 raeburn 309: },
310: 'contacts' =>
311: { text => 'Contact Information',
1.67 raeburn 312: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 313: header => [{col1 => 'Setting',
314: col2 => 'Value',}],
1.230 raeburn 315: print => \&print_contacts,
316: modify => \&modify_contacts,
1.30 raeburn 317: },
318: 'usercreation' =>
319: { text => 'User creation',
1.67 raeburn 320: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 321: header => [{col1 => 'Format rule type',
322: col2 => 'Format rules in force'},
1.34 raeburn 323: {col1 => 'User account creation',
324: col2 => 'Usernames which may be created',},
1.30 raeburn 325: {col1 => 'Context',
1.43 raeburn 326: col2 => 'Assignable authentication types'}],
1.230 raeburn 327: print => \&print_usercreation,
328: modify => \&modify_usercreation,
1.30 raeburn 329: },
1.224 raeburn 330: 'selfcreation' =>
331: { text => 'Users self-creating accounts',
332: help => 'Domain_Configuration_Self_Creation',
333: header => [{col1 => 'Self-creation with institutional username',
334: col2 => 'Enabled?'},
335: {col1 => 'Institutional user type (login/SSO self-creation)',
336: col2 => 'Information user can enter'},
337: {col1 => 'Self-creation with e-mail as username',
338: col2 => 'Settings'}],
1.230 raeburn 339: print => \&print_selfcreation,
340: modify => \&modify_selfcreation,
1.224 raeburn 341: },
1.69 raeburn 342: 'usermodification' =>
1.33 raeburn 343: { text => 'User modification',
1.67 raeburn 344: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 345: header => [{col1 => 'Target user has role',
1.227 bisitz 346: col2 => 'User information updatable in author context'},
1.33 raeburn 347: {col1 => 'Target user has role',
1.227 bisitz 348: col2 => 'User information updatable in course context'}],
1.230 raeburn 349: print => \&print_usermodification,
350: modify => \&modify_usermodification,
1.33 raeburn 351: },
1.69 raeburn 352: 'scantron' =>
1.95 www 353: { text => 'Bubblesheet format file',
1.67 raeburn 354: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 355: header => [ {col1 => 'Item',
356: col2 => '',
357: }],
1.230 raeburn 358: print => \&print_scantron,
359: modify => \&modify_scantron,
1.46 raeburn 360: },
1.86 raeburn 361: 'requestcourses' =>
362: {text => 'Request creation of courses',
363: help => 'Domain_Configuration_Request_Courses',
364: header => [{col1 => 'User affiliation',
1.102 raeburn 365: col2 => 'Availability/Processing of requests',},
366: {col1 => 'Setting',
1.216 raeburn 367: col2 => 'Value'},
368: {col1 => 'Available textbooks',
1.235 ! raeburn 369: col2 => ''},
! 370: {col1 => 'Validation (not official courses)',
! 371: col2 => 'Value'},],
1.230 raeburn 372: print => \&print_quotas,
373: modify => \&modify_quotas,
1.86 raeburn 374: },
1.163 raeburn 375: 'requestauthor' =>
1.223 bisitz 376: {text => 'Request Authoring Space',
1.163 raeburn 377: help => 'Domain_Configuration_Request_Author',
378: header => [{col1 => 'User affiliation',
379: col2 => 'Availability/Processing of requests',},
380: {col1 => 'Setting',
381: col2 => 'Value'}],
1.230 raeburn 382: print => \&print_quotas,
383: modify => \&modify_quotas,
1.163 raeburn 384: },
1.69 raeburn 385: 'coursecategories' =>
1.120 raeburn 386: { text => 'Cataloging of courses/communities',
1.67 raeburn 387: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 388: header => [{col1 => 'Category settings',
1.57 raeburn 389: col2 => '',},
390: {col1 => 'Categories',
391: col2 => '',
392: }],
1.230 raeburn 393: print => \&print_coursecategories,
394: modify => \&modify_coursecategories,
1.69 raeburn 395: },
396: 'serverstatuses' =>
1.77 raeburn 397: {text => 'Access to server status pages',
1.69 raeburn 398: help => 'Domain_Configuration_Server_Status',
399: header => [{col1 => 'Status Page',
400: col2 => 'Other named users',
401: col3 => 'Specific IPs',
402: }],
1.230 raeburn 403: print => \&print_serverstatuses,
404: modify => \&modify_serverstatuses,
1.69 raeburn 405: },
1.118 jms 406: 'helpsettings' =>
407: {text => 'Help page settings',
408: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 409: header => [{col1 => 'Help Settings (logged-in users)',
410: col2 => 'Value'}],
1.230 raeburn 411: print => \&print_helpsettings,
412: modify => \&modify_helpsettings,
1.118 jms 413: },
1.121 raeburn 414: 'coursedefaults' =>
415: {text => 'Course/Community defaults',
416: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 417: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
418: col2 => 'Value',},
419: {col1 => 'Defaults which can be overridden for each course by a DC',
420: col2 => 'Value',},],
1.230 raeburn 421: print => \&print_coursedefaults,
422: modify => \&modify_coursedefaults,
1.121 raeburn 423: },
1.231 raeburn 424: 'selfenrollment' =>
425: {text => 'Self-enrollment in Course/Community',
426: help => 'Domain_Configuration_Selfenrollment',
427: header => [{col1 => 'Configuration Rights',
428: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
429: {col1 => 'Defaults',
430: col2 => 'Value'},
431: {col1 => 'Self-enrollment validation (optional)',
432: col2 => 'Value'},],
433: print => \&print_selfenrollment,
434: modify => \&modify_selfenrollment,
435: },
1.120 raeburn 436: 'privacy' =>
437: {text => 'User Privacy',
438: help => 'Domain_Configuration_User_Privacy',
439: header => [{col1 => 'Setting',
440: col2 => 'Value',}],
1.230 raeburn 441: print => \&print_privacy,
442: modify => \&modify_privacy,
1.120 raeburn 443: },
1.141 raeburn 444: 'usersessions' =>
1.145 raeburn 445: {text => 'User session hosting/offloading',
1.137 raeburn 446: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 447: header => [{col1 => 'Domain server',
448: col2 => 'Servers to offload sessions to when busy'},
449: {col1 => 'Hosting of users from other domains',
1.137 raeburn 450: col2 => 'Rules'},
451: {col1 => "Hosting domain's own users elsewhere",
452: col2 => 'Rules'}],
1.230 raeburn 453: print => \&print_usersessions,
454: modify => \&modify_usersessions,
1.137 raeburn 455: },
1.150 raeburn 456: 'loadbalancing' =>
1.185 raeburn 457: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 458: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 459: header => [{col1 => 'Balancers',
1.150 raeburn 460: col2 => 'Default destinations',
1.183 bisitz 461: col3 => 'User affiliation',
1.150 raeburn 462: col4 => 'Overrides'},
463: ],
1.230 raeburn 464: print => \&print_loadbalancing,
465: modify => \&modify_loadbalancing,
1.150 raeburn 466: },
1.3 raeburn 467: );
1.110 raeburn 468: if (keys(%servers) > 1) {
469: $prefs{'login'} = { text => 'Log-in page options',
470: help => 'Domain_Configuration_Login_Page',
471: header => [{col1 => 'Log-in Service',
472: col2 => 'Server Setting',},
473: {col1 => 'Log-in Page Items',
1.168 raeburn 474: col2 => ''},
475: {col1 => 'Log-in Help',
476: col2 => 'Value'}],
1.230 raeburn 477: print => \&print_login,
478: modify => \&modify_login,
1.110 raeburn 479: };
480: }
1.174 foxr 481:
1.6 raeburn 482: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 483: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 484: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 485: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 486: text=>"Settings to display/modify"});
1.9 raeburn 487: my $confname = $dom.'-domainconfig';
1.174 foxr 488:
1.3 raeburn 489: if ($phase eq 'process') {
1.212 raeburn 490: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
491: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 492: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 493: $r->rflush();
1.212 raeburn 494: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 495: }
1.30 raeburn 496: } elsif ($phase eq 'display') {
1.192 raeburn 497: my $js = &recaptcha_js().
498: &credits_js();
1.171 raeburn 499: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 500: my ($othertitle,$usertypes,$types) =
501: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 502: $js .= &lonbalance_targets_js($dom,$types,\%servers,
503: $domconfig{'loadbalancing'}).
1.170 raeburn 504: &new_spares_js().
505: &common_domprefs_js().
506: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 507: }
1.216 raeburn 508: if (grep(/^requestcourses$/,@actions)) {
509: my $javascript_validations;
510: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
511: $js .= <<END;
512: <script type="text/javascript">
513: $javascript_validations
514: </script>
515: $coursebrowserjs
516: END
517: }
1.150 raeburn 518: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 519: } else {
1.180 raeburn 520: # check if domconfig user exists for the domain.
521: my $servadm = $r->dir_config('lonAdmEMail');
522: my ($configuserok,$author_ok,$switchserver) =
523: &config_check($dom,$confname,$servadm);
524: unless ($configuserok eq 'ok') {
1.181 raeburn 525: &Apache::lonconfigsettings::print_header($r,$phase,$context);
526: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 527: $confname).
1.181 raeburn 528: '<br />'
529: );
1.180 raeburn 530: if ($switchserver) {
1.181 raeburn 531: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
532: '<br />'.
533: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
534: '<br />'.
535: &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).
536: '<br />'.
537: &mt('To do that now, use the following link: [_1]',$switchserver)
538: );
539: } else {
540: $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.').
541: '<br />'.
542: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
543: );
1.180 raeburn 544: }
545: $r->print(&Apache::loncommon::end_page());
546: return OK;
547: }
1.21 raeburn 548: if (keys(%domconfig) == 0) {
549: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 550: my @ids=&Apache::lonnet::current_machine_ids();
551: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 552: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 553: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 554: my $custom_img_count = 0;
555: foreach my $img (@loginimages) {
556: if ($designhash{$dom.'.login.'.$img} ne '') {
557: $custom_img_count ++;
558: }
559: }
560: foreach my $role (@roles) {
561: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
562: $custom_img_count ++;
563: }
564: }
565: if ($custom_img_count > 0) {
1.94 raeburn 566: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 567: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 568: $r->print(
569: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
570: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
571: &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 />'.
572: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
573: if ($switch_server) {
1.30 raeburn 574: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 575: }
1.91 raeburn 576: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 577: return OK;
578: }
579: }
580: }
1.91 raeburn 581: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 582: }
583: return OK;
584: }
585:
586: sub process_changes {
1.205 raeburn 587: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 588: my %domconfig;
589: if (ref($values) eq 'HASH') {
590: %domconfig = %{$values};
591: }
1.3 raeburn 592: my $output;
593: if ($action eq 'login') {
1.205 raeburn 594: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 595: } elsif ($action eq 'rolecolors') {
1.9 raeburn 596: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 597: $lastactref,%domconfig);
1.3 raeburn 598: } elsif ($action eq 'quotas') {
1.216 raeburn 599: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 600: } elsif ($action eq 'autoenroll') {
1.205 raeburn 601: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 602: } elsif ($action eq 'autoupdate') {
603: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 604: } elsif ($action eq 'autocreate') {
605: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 606: } elsif ($action eq 'directorysrch') {
607: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 608: } elsif ($action eq 'usercreation') {
1.28 raeburn 609: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 610: } elsif ($action eq 'selfcreation') {
611: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 612: } elsif ($action eq 'usermodification') {
613: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 614: } elsif ($action eq 'contacts') {
1.205 raeburn 615: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 616: } elsif ($action eq 'defaults') {
1.212 raeburn 617: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 618: } elsif ($action eq 'scantron') {
1.205 raeburn 619: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 620: } elsif ($action eq 'coursecategories') {
621: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 622: } elsif ($action eq 'serverstatuses') {
623: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 624: } elsif ($action eq 'requestcourses') {
1.216 raeburn 625: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 626: } elsif ($action eq 'requestauthor') {
1.216 raeburn 627: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 628: } elsif ($action eq 'helpsettings') {
1.122 jms 629: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 630: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 631: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 632: } elsif ($action eq 'selfenrollment') {
633: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 634: } elsif ($action eq 'usersessions') {
1.212 raeburn 635: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 636: } elsif ($action eq 'loadbalancing') {
637: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 638: }
639: return $output;
640: }
641:
642: sub print_config_box {
1.9 raeburn 643: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 644: my $rowtotal = 0;
1.49 raeburn 645: my $output;
646: if ($action eq 'coursecategories') {
647: $output = &coursecategories_javascript($settings);
1.91 raeburn 648: }
1.49 raeburn 649: $output .=
1.30 raeburn 650: '<table class="LC_nested_outer">
1.3 raeburn 651: <tr>
1.66 raeburn 652: <th align="left" valign="middle"><span class="LC_nobreak">'.
653: &mt($item->{text}).' '.
654: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
655: '</tr>';
1.30 raeburn 656: $rowtotal ++;
1.110 raeburn 657: my $numheaders = 1;
658: if (ref($item->{'header'}) eq 'ARRAY') {
659: $numheaders = scalar(@{$item->{'header'}});
660: }
661: if ($numheaders > 1) {
1.64 raeburn 662: my $colspan = '';
1.145 raeburn 663: my $rightcolspan = '';
1.210 raeburn 664: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 665: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 666: $colspan = ' colspan="2"';
667: }
1.145 raeburn 668: if ($action eq 'usersessions') {
669: $rightcolspan = ' colspan="3"';
670: }
1.30 raeburn 671: $output .= '
1.3 raeburn 672: <tr>
673: <td>
674: <table class="LC_nested">
675: <tr class="LC_info_row">
1.59 bisitz 676: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 677: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 678: </tr>';
1.69 raeburn 679: $rowtotal ++;
1.230 raeburn 680: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
681: ($action eq 'usermodification') || ($action eq 'coursedefaults') ||
682: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
683: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 684: } elsif ($action eq 'coursecategories') {
1.230 raeburn 685: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 686: } elsif ($action eq 'login') {
1.168 raeburn 687: if ($numheaders == 3) {
688: $colspan = ' colspan="2"';
689: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
690: } else {
691: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
692: }
1.230 raeburn 693: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 694: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 695: } elsif ($action eq 'rolecolors') {
1.30 raeburn 696: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 697: }
1.30 raeburn 698: $output .= '
1.6 raeburn 699: </table>
700: </td>
701: </tr>
702: <tr>
703: <td>
704: <table class="LC_nested">
705: <tr class="LC_info_row">
1.230 raeburn 706: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 707: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 708: </tr>';
709: $rowtotal ++;
1.230 raeburn 710: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
711: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
712: ($action eq 'usersessions')) {
713: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 714: </table>
715: </td>
716: </tr>
717: <tr>
718: <td>
719: <table class="LC_nested">
720: <tr class="LC_info_row">
721: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 722: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.230 raeburn 723: </tr>'."\n".
724: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 725: $rowtotal ++;
1.230 raeburn 726: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults')) {
727: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.57 raeburn 728: } elsif ($action eq 'coursecategories') {
729: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 730: } elsif ($action eq 'login') {
1.168 raeburn 731: if ($numheaders == 3) {
732: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
733: </table>
734: </td>
735: </tr>
736: <tr>
737: <td>
738: <table class="LC_nested">
739: <tr class="LC_info_row">
740: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 741: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 742: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
743: $rowtotal ++;
744: } else {
745: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
746: }
1.102 raeburn 747: } elsif ($action eq 'requestcourses') {
1.216 raeburn 748: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
749: &print_studentcode($settings,\$rowtotal).'
750: </table>
751: </td>
752: </tr>
753: <tr>
754: <td>
755: <table class="LC_nested">
756: <tr class="LC_info_row">
757: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
758: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.235 ! raeburn 759: &print_textbookcourses($dom,$settings,\$rowtotal).'
! 760: </table>
! 761: </td>
! 762: </tr>
! 763: <tr>
! 764: <td>
! 765: <table class="LC_nested">
! 766: <tr class="LC_info_row">
! 767: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
! 768: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
! 769: </tr>'.
! 770: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 771: } elsif ($action eq 'requestauthor') {
772: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 773: } elsif ($action eq 'rolecolors') {
1.30 raeburn 774: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
1.69 raeburn 782: <td class="LC_left_item"'.$colspan.' valign="top">'.
783: &mt($item->{'header'}->[2]->{'col1'}).'</td>
784: <td class="LC_right_item" valign="top">'.
785: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 786: </tr>'.
1.30 raeburn 787: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 788: </table>
789: </td>
790: </tr>
791: <tr>
792: <td>
793: <table class="LC_nested">
794: <tr class="LC_info_row">
1.59 bisitz 795: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
796: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 797: </tr>'.
1.30 raeburn 798: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
799: $rowtotal += 2;
1.6 raeburn 800: }
1.3 raeburn 801: } else {
1.30 raeburn 802: $output .= '
1.3 raeburn 803: <tr>
804: <td>
805: <table class="LC_nested">
1.30 raeburn 806: <tr class="LC_info_row">';
1.24 raeburn 807: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 808: $output .= '
1.59 bisitz 809: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 810: } elsif ($action eq 'serverstatuses') {
811: $output .= '
812: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
813: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
814:
1.6 raeburn 815: } else {
1.30 raeburn 816: $output .= '
1.69 raeburn 817: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
818: }
1.72 raeburn 819: if (defined($item->{'header'}->[0]->{'col3'})) {
820: $output .= '<td class="LC_left_item" valign="top">'.
821: &mt($item->{'header'}->[0]->{'col2'});
822: if ($action eq 'serverstatuses') {
823: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
824: }
1.69 raeburn 825: } else {
826: $output .= '<td class="LC_right_item" valign="top">'.
827: &mt($item->{'header'}->[0]->{'col2'});
828: }
829: $output .= '</td>';
830: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 831: if (defined($item->{'header'}->[0]->{'col4'})) {
832: $output .= '<td class="LC_left_item" valign="top">'.
833: &mt($item->{'header'}->[0]->{'col3'});
834: } else {
835: $output .= '<td class="LC_right_item" valign="top">'.
836: &mt($item->{'header'}->[0]->{'col3'});
837: }
1.69 raeburn 838: if ($action eq 'serverstatuses') {
839: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
840: }
841: $output .= '</td>';
1.6 raeburn 842: }
1.150 raeburn 843: if ($item->{'header'}->[0]->{'col4'}) {
844: $output .= '<td class="LC_right_item" valign="top">'.
845: &mt($item->{'header'}->[0]->{'col4'});
846: }
1.69 raeburn 847: $output .= '</tr>';
1.48 raeburn 848: $rowtotal ++;
1.168 raeburn 849: if ($action eq 'quotas') {
1.86 raeburn 850: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 851: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
852: ($action eq 'contacts') || ($action eq 'defaults') || ($action eq 'serverstatuses') ||
853: ($action eq 'loadbalancing')) {
854: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 855: } elsif ($action eq 'scantron') {
856: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 857: } elsif ($action eq 'helpsettings') {
1.168 raeburn 858: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 859: }
1.3 raeburn 860: }
1.30 raeburn 861: $output .= '
1.3 raeburn 862: </table>
863: </td>
864: </tr>
1.30 raeburn 865: </table><br />';
866: return ($output,$rowtotal);
1.1 raeburn 867: }
868:
1.3 raeburn 869: sub print_login {
1.168 raeburn 870: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 871: my ($css_class,$datatable);
1.6 raeburn 872: my %choices = &login_choices();
1.110 raeburn 873:
1.168 raeburn 874: if ($caller eq 'service') {
1.149 raeburn 875: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 876: my $choice = $choices{'disallowlogin'};
877: $css_class = ' class="LC_odd_row"';
1.128 raeburn 878: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 879: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 880: '<th>'.$choices{'server'}.'</th>'.
881: '<th>'.$choices{'serverpath'}.'</th>'.
882: '<th>'.$choices{'custompath'}.'</th>'.
883: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 884: my %disallowed;
885: if (ref($settings) eq 'HASH') {
886: if (ref($settings->{'loginvia'}) eq 'HASH') {
887: %disallowed = %{$settings->{'loginvia'}};
888: }
889: }
890: foreach my $lonhost (sort(keys(%servers))) {
891: my $direct = 'selected="selected"';
1.128 raeburn 892: if (ref($disallowed{$lonhost}) eq 'HASH') {
893: if ($disallowed{$lonhost}{'server'} ne '') {
894: $direct = '';
895: }
1.110 raeburn 896: }
1.115 raeburn 897: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 898: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 899: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
900: '</option>';
1.184 raeburn 901: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 902: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 903: my $selected = '';
1.128 raeburn 904: if (ref($disallowed{$lonhost}) eq 'HASH') {
905: if ($hostid eq $disallowed{$lonhost}{'server'}) {
906: $selected = 'selected="selected"';
907: }
1.110 raeburn 908: }
909: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
910: $servers{$hostid}.'</option>';
911: }
1.128 raeburn 912: $datatable .= '</select></td>'.
913: '<td><select name="'.$lonhost.'_serverpath">';
914: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
915: my $pathname = $path;
916: if ($path eq 'custom') {
917: $pathname = &mt('Custom Path').' ->';
918: }
919: my $selected = '';
920: if (ref($disallowed{$lonhost}) eq 'HASH') {
921: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
922: $selected = 'selected="selected"';
923: }
924: } elsif ($path eq '') {
925: $selected = 'selected="selected"';
926: }
927: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
928: }
929: $datatable .= '</select></td>';
930: my ($custom,$exempt);
931: if (ref($disallowed{$lonhost}) eq 'HASH') {
932: $custom = $disallowed{$lonhost}{'custompath'};
933: $exempt = $disallowed{$lonhost}{'exempt'};
934: }
935: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
936: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
937: '</tr>';
1.110 raeburn 938: }
939: $datatable .= '</table></td></tr>';
940: return $datatable;
1.168 raeburn 941: } elsif ($caller eq 'page') {
942: my %defaultchecked = (
943: 'coursecatalog' => 'on',
1.188 raeburn 944: 'helpdesk' => 'on',
1.168 raeburn 945: 'adminmail' => 'off',
946: 'newuser' => 'off',
947: );
1.188 raeburn 948: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 949: my (%checkedon,%checkedoff);
1.42 raeburn 950: foreach my $item (@toggles) {
1.168 raeburn 951: if ($defaultchecked{$item} eq 'on') {
952: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 953: $checkedoff{$item} = ' ';
1.168 raeburn 954: } elsif ($defaultchecked{$item} eq 'off') {
955: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 956: $checkedon{$item} = ' ';
957: }
1.1 raeburn 958: }
1.168 raeburn 959: my @images = ('img','logo','domlogo','login');
960: my @logintext = ('textcol','bgcol');
961: my @bgs = ('pgbg','mainbg','sidebg');
962: my @links = ('link','alink','vlink');
963: my %designhash = &Apache::loncommon::get_domainconf($dom);
964: my %defaultdesign = %Apache::loncommon::defaultdesign;
965: my (%is_custom,%designs);
966: my %defaults = (
967: font => $defaultdesign{'login.font'},
968: );
1.6 raeburn 969: foreach my $item (@images) {
1.168 raeburn 970: $defaults{$item} = $defaultdesign{'login.'.$item};
971: $defaults{'showlogo'}{$item} = 1;
972: }
973: foreach my $item (@bgs) {
974: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 975: }
1.41 raeburn 976: foreach my $item (@logintext) {
1.168 raeburn 977: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 978: }
1.168 raeburn 979: foreach my $item (@links) {
980: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 981: }
1.168 raeburn 982: if (ref($settings) eq 'HASH') {
983: foreach my $item (@toggles) {
984: if ($settings->{$item} eq '1') {
985: $checkedon{$item} = ' checked="checked" ';
986: $checkedoff{$item} = ' ';
987: } elsif ($settings->{$item} eq '0') {
988: $checkedoff{$item} = ' checked="checked" ';
989: $checkedon{$item} = ' ';
990: }
991: }
992: foreach my $item (@images) {
993: if (defined($settings->{$item})) {
994: $designs{$item} = $settings->{$item};
995: $is_custom{$item} = 1;
996: }
997: if (defined($settings->{'showlogo'}{$item})) {
998: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
999: }
1000: }
1001: foreach my $item (@logintext) {
1002: if ($settings->{$item} ne '') {
1003: $designs{'logintext'}{$item} = $settings->{$item};
1004: $is_custom{$item} = 1;
1005: }
1006: }
1007: if ($settings->{'font'} ne '') {
1008: $designs{'font'} = $settings->{'font'};
1009: $is_custom{'font'} = 1;
1010: }
1011: foreach my $item (@bgs) {
1012: if ($settings->{$item} ne '') {
1013: $designs{'bgs'}{$item} = $settings->{$item};
1014: $is_custom{$item} = 1;
1015: }
1016: }
1017: foreach my $item (@links) {
1018: if ($settings->{$item} ne '') {
1019: $designs{'links'}{$item} = $settings->{$item};
1020: $is_custom{$item} = 1;
1021: }
1022: }
1023: } else {
1024: if ($designhash{$dom.'.login.font'} ne '') {
1025: $designs{'font'} = $designhash{$dom.'.login.font'};
1026: $is_custom{'font'} = 1;
1027: }
1028: foreach my $item (@images) {
1029: if ($designhash{$dom.'.login.'.$item} ne '') {
1030: $designs{$item} = $designhash{$dom.'.login.'.$item};
1031: $is_custom{$item} = 1;
1032: }
1033: }
1034: foreach my $item (@bgs) {
1035: if ($designhash{$dom.'.login.'.$item} ne '') {
1036: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1037: $is_custom{$item} = 1;
1038: }
1.6 raeburn 1039: }
1.168 raeburn 1040: foreach my $item (@links) {
1041: if ($designhash{$dom.'.login.'.$item} ne '') {
1042: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1043: $is_custom{$item} = 1;
1044: }
1.6 raeburn 1045: }
1046: }
1.168 raeburn 1047: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1048: logo => 'Institution Logo',
1049: domlogo => 'Domain Logo',
1050: login => 'Login box');
1051: my $itemcount = 1;
1052: foreach my $item (@toggles) {
1053: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1054: $datatable .=
1055: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1056: '</td><td>'.
1057: '<span class="LC_nobreak"><label><input type="radio" name="'.
1058: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1059: '</label> <label><input type="radio" name="'.$item.'"'.
1060: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1061: '</tr>';
1062: $itemcount ++;
1.6 raeburn 1063: }
1.168 raeburn 1064: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1065: $datatable .= '</tr></table></td></tr>';
1066: } elsif ($caller eq 'help') {
1067: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1068: my $switchserver = &check_switchserver($dom,$confname);
1069: my $itemcount = 1;
1070: $defaulturl = '/adm/loginproblems.html';
1071: $defaulttype = 'default';
1072: %lt = &Apache::lonlocal::texthash (
1073: del => 'Delete?',
1074: rep => 'Replace:',
1075: upl => 'Upload:',
1076: default => 'Default',
1077: custom => 'Custom',
1078: );
1079: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1080: my @currlangs;
1081: if (ref($settings) eq 'HASH') {
1082: if (ref($settings->{'helpurl'}) eq 'HASH') {
1083: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1084: next if ($settings->{'helpurl'}{$key} eq '');
1085: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1086: $type{$key} = 'custom';
1087: unless ($key eq 'nolang') {
1088: push(@currlangs,$key);
1089: }
1090: }
1091: } elsif ($settings->{'helpurl'} ne '') {
1092: $type{'nolang'} = 'custom';
1093: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1094: }
1095: }
1.168 raeburn 1096: foreach my $lang ('nolang',sort(@currlangs)) {
1097: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1098: $datatable .= '<tr'.$css_class.'>';
1099: if ($url{$lang} eq '') {
1100: $url{$lang} = $defaulturl;
1101: }
1102: if ($type{$lang} eq '') {
1103: $type{$lang} = $defaulttype;
1104: }
1105: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1106: if ($lang eq 'nolang') {
1107: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1108: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1109: } else {
1110: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1111: $langchoices{$lang},
1112: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1113: }
1114: $datatable .= '</span></td>'."\n".
1115: '<td class="LC_left_item">';
1116: if ($type{$lang} eq 'custom') {
1117: $datatable .= '<span class="LC_nobreak"><label>'.
1118: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1119: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1120: } else {
1121: $datatable .= $lt{'upl'};
1122: }
1123: $datatable .='<br />';
1124: if ($switchserver) {
1125: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1126: } else {
1127: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1128: }
1.168 raeburn 1129: $datatable .= '</td></tr>';
1130: $itemcount ++;
1.6 raeburn 1131: }
1.168 raeburn 1132: my @addlangs;
1133: foreach my $lang (sort(keys(%langchoices))) {
1134: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1135: push(@addlangs,$lang);
1136: }
1137: if (@addlangs > 0) {
1138: my %toadd;
1139: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1140: $toadd{''} = &mt('Select');
1141: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1142: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1143: &mt('Add log-in help page for a specific language:').' '.
1144: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1145: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1146: if ($switchserver) {
1147: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1148: } else {
1149: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1150: }
1.168 raeburn 1151: $datatable .= '</td></tr>';
1.169 raeburn 1152: $itemcount ++;
1.6 raeburn 1153: }
1.169 raeburn 1154: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1155: }
1.6 raeburn 1156: return $datatable;
1157: }
1158:
1159: sub login_choices {
1160: my %choices =
1161: &Apache::lonlocal::texthash (
1.116 bisitz 1162: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1163: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1164: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1165: disallowlogin => "Login page requests redirected",
1166: hostid => "Server",
1.128 raeburn 1167: server => "Redirect to:",
1168: serverpath => "Path",
1169: custompath => "Custom",
1170: exempt => "Exempt IP(s)",
1.110 raeburn 1171: directlogin => "No redirect",
1172: newuser => "Link to create a user account",
1173: img => "Header",
1174: logo => "Main Logo",
1175: domlogo => "Domain Logo",
1176: login => "Log-in Header",
1177: textcol => "Text color",
1178: bgcol => "Box color",
1179: bgs => "Background colors",
1180: links => "Link colors",
1181: font => "Font color",
1182: pgbg => "Header",
1183: mainbg => "Page",
1184: sidebg => "Login box",
1185: link => "Link",
1186: alink => "Active link",
1187: vlink => "Visited link",
1.6 raeburn 1188: );
1189: return %choices;
1190: }
1191:
1192: sub print_rolecolors {
1.30 raeburn 1193: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1194: my %choices = &color_font_choices();
1195: my @bgs = ('pgbg','tabbg','sidebg');
1196: my @links = ('link','alink','vlink');
1197: my @images = ('img');
1198: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1199: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1200: my %defaultdesign = %Apache::loncommon::defaultdesign;
1201: my (%is_custom,%designs);
1.200 raeburn 1202: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1203: if (ref($settings) eq 'HASH') {
1204: if (ref($settings->{$role}) eq 'HASH') {
1205: if ($settings->{$role}->{'img'} ne '') {
1206: $designs{'img'} = $settings->{$role}->{'img'};
1207: $is_custom{'img'} = 1;
1208: }
1209: if ($settings->{$role}->{'font'} ne '') {
1210: $designs{'font'} = $settings->{$role}->{'font'};
1211: $is_custom{'font'} = 1;
1212: }
1.97 tempelho 1213: if ($settings->{$role}->{'fontmenu'} ne '') {
1214: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1215: $is_custom{'fontmenu'} = 1;
1216: }
1.6 raeburn 1217: foreach my $item (@bgs) {
1218: if ($settings->{$role}->{$item} ne '') {
1219: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1220: $is_custom{$item} = 1;
1221: }
1222: }
1223: foreach my $item (@links) {
1224: if ($settings->{$role}->{$item} ne '') {
1225: $designs{'links'}{$item} = $settings->{$role}->{$item};
1226: $is_custom{$item} = 1;
1227: }
1228: }
1229: }
1230: } else {
1231: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1232: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1233: $is_custom{'img'} = 1;
1234: }
1.97 tempelho 1235: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1236: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1237: $is_custom{'fontmenu'} = 1;
1238: }
1.6 raeburn 1239: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1240: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1241: $is_custom{'font'} = 1;
1242: }
1243: foreach my $item (@bgs) {
1244: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1245: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1246: $is_custom{$item} = 1;
1247:
1248: }
1249: }
1250: foreach my $item (@links) {
1251: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1252: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1253: $is_custom{$item} = 1;
1254: }
1255: }
1256: }
1257: my $itemcount = 1;
1.30 raeburn 1258: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1259: $datatable .= '</tr></table></td></tr>';
1260: return $datatable;
1261: }
1262:
1.200 raeburn 1263: sub role_defaults {
1264: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1265: my %defaults;
1266: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1267: return %defaults;
1268: }
1269: my %defaultdesign = %Apache::loncommon::defaultdesign;
1270: if ($role eq 'login') {
1271: %defaults = (
1272: font => $defaultdesign{$role.'.font'},
1273: );
1274: if (ref($logintext) eq 'ARRAY') {
1275: foreach my $item (@{$logintext}) {
1276: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1277: }
1278: }
1279: foreach my $item (@{$images}) {
1280: $defaults{'showlogo'}{$item} = 1;
1281: }
1282: } else {
1283: %defaults = (
1284: img => $defaultdesign{$role.'.img'},
1285: font => $defaultdesign{$role.'.font'},
1286: fontmenu => $defaultdesign{$role.'.fontmenu'},
1287: );
1288: }
1289: foreach my $item (@{$bgs}) {
1290: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1291: }
1292: foreach my $item (@{$links}) {
1293: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1294: }
1295: foreach my $item (@{$images}) {
1296: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1297: }
1298: return %defaults;
1299: }
1300:
1.6 raeburn 1301: sub display_color_options {
1.9 raeburn 1302: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1303: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1304: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1305: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1306: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1307: '<td>'.$choices->{'font'}.'</td>';
1308: if (!$is_custom->{'font'}) {
1.30 raeburn 1309: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1310: } else {
1311: $datatable .= '<td> </td>';
1312: }
1.174 foxr 1313: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1314:
1.8 raeburn 1315: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1316: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1317: ' value="'.$current_color.'" /> '.
1.174 foxr 1318: ' </td></tr>';
1.107 raeburn 1319: unless ($role eq 'login') {
1320: $datatable .= '<tr'.$css_class.'>'.
1321: '<td>'.$choices->{'fontmenu'}.'</td>';
1322: if (!$is_custom->{'fontmenu'}) {
1323: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1324: } else {
1325: $datatable .= '<td> </td>';
1326: }
1.202 raeburn 1327: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1328: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1329: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1330: '<input class="colorchooser" type="text" size="10" name="'
1331: .$role.'_fontmenu"'.
1332: ' value="'.$current_color.'" /> '.
1333: ' </td></tr>';
1.97 tempelho 1334: }
1.9 raeburn 1335: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1336: foreach my $img (@{$images}) {
1.18 albertel 1337: $itemcount ++;
1.6 raeburn 1338: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1339: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1340: '<td>'.$choices->{$img};
1.41 raeburn 1341: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1342: if ($role eq 'login') {
1343: if ($img eq 'login') {
1344: $login_hdr_pick =
1.135 bisitz 1345: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1346: $logincolors =
1347: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1348: $designs,$defaults);
1.70 raeburn 1349: } elsif ($img ne 'domlogo') {
1350: $datatable.= &logo_display_options($img,$defaults,$designs);
1351: }
1352: }
1353: $datatable .= '</td>';
1.6 raeburn 1354: if ($designs->{$img} ne '') {
1355: $imgfile = $designs->{$img};
1.18 albertel 1356: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1357: } else {
1358: $imgfile = $defaults->{$img};
1359: }
1360: if ($imgfile) {
1.9 raeburn 1361: my ($showfile,$fullsize);
1362: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1363: my $urldir = $1;
1364: my $filename = $2;
1365: my @info = &Apache::lonnet::stat_file($designs->{$img});
1366: if (@info) {
1367: my $thumbfile = 'tn-'.$filename;
1368: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1369: if (@thumb) {
1370: $showfile = $urldir.'/'.$thumbfile;
1371: } else {
1372: $showfile = $imgfile;
1373: }
1374: } else {
1375: $showfile = '';
1376: }
1377: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1378: $showfile = $imgfile;
1.6 raeburn 1379: my $imgdir = $1;
1380: my $filename = $2;
1.159 raeburn 1381: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1382: $showfile = "/$imgdir/tn-".$filename;
1383: } else {
1.159 raeburn 1384: my $input = $londocroot.$imgfile;
1385: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1386: if (!-e $output) {
1.9 raeburn 1387: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1388: my ($fullwidth,$fullheight) = &check_dimensions($input);
1389: if ($fullwidth ne '' && $fullheight ne '') {
1390: if ($fullwidth > $width && $fullheight > $height) {
1391: my $size = $width.'x'.$height;
1392: system("convert -sample $size $input $output");
1.159 raeburn 1393: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1394: }
1395: }
1.6 raeburn 1396: }
1397: }
1.16 raeburn 1398: }
1.6 raeburn 1399: if ($showfile) {
1.40 raeburn 1400: if ($showfile =~ m{^/(adm|res)/}) {
1401: if ($showfile =~ m{^/res/}) {
1402: my $local_showfile =
1403: &Apache::lonnet::filelocation('',$showfile);
1404: &Apache::lonnet::repcopy($local_showfile);
1405: }
1406: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1407: }
1408: if ($imgfile) {
1409: if ($imgfile =~ m{^/(adm|res)/}) {
1410: if ($imgfile =~ m{^/res/}) {
1411: my $local_imgfile =
1412: &Apache::lonnet::filelocation('',$imgfile);
1413: &Apache::lonnet::repcopy($local_imgfile);
1414: }
1415: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1416: } else {
1417: $fullsize = $imgfile;
1418: }
1419: }
1.41 raeburn 1420: $datatable .= '<td>';
1421: if ($img eq 'login') {
1.135 bisitz 1422: $datatable .= $login_hdr_pick;
1423: }
1.41 raeburn 1424: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1425: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1426: } else {
1.201 raeburn 1427: $datatable .= '<td> </td><td class="LC_left_item">'.
1428: &mt('Upload:').'<br />';
1.6 raeburn 1429: }
1430: } else {
1.201 raeburn 1431: $datatable .= '<td> </td><td class="LC_left_item">'.
1432: &mt('Upload:').'<br />';
1.6 raeburn 1433: }
1.9 raeburn 1434: if ($switchserver) {
1435: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1436: } else {
1.135 bisitz 1437: if ($img ne 'login') { # suppress file selection for Log-in header
1438: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1439: }
1.9 raeburn 1440: }
1441: $datatable .= '</td></tr>';
1.6 raeburn 1442: }
1443: $itemcount ++;
1444: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1445: $datatable .= '<tr'.$css_class.'>'.
1446: '<td>'.$choices->{'bgs'}.'</td>';
1447: my $bgs_def;
1448: foreach my $item (@{$bgs}) {
1449: if (!$is_custom->{$item}) {
1.70 raeburn 1450: $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 1451: }
1452: }
1453: if ($bgs_def) {
1.8 raeburn 1454: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1455: } else {
1456: $datatable .= '<td> </td>';
1457: }
1458: $datatable .= '<td class="LC_right_item">'.
1459: '<table border="0"><tr>';
1.174 foxr 1460:
1.6 raeburn 1461: foreach my $item (@{$bgs}) {
1.201 raeburn 1462: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1463: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1464: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1465: $datatable .= ' ';
1.6 raeburn 1466: }
1.174 foxr 1467: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1468: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1469: }
1470: $datatable .= '</tr></table></td></tr>';
1471: $itemcount ++;
1472: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1473: $datatable .= '<tr'.$css_class.'>'.
1474: '<td>'.$choices->{'links'}.'</td>';
1475: my $links_def;
1476: foreach my $item (@{$links}) {
1477: if (!$is_custom->{$item}) {
1.30 raeburn 1478: $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 1479: }
1480: }
1481: if ($links_def) {
1.8 raeburn 1482: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1483: } else {
1484: $datatable .= '<td> </td>';
1485: }
1486: $datatable .= '<td class="LC_right_item">'.
1487: '<table border="0"><tr>';
1488: foreach my $item (@{$links}) {
1.234 raeburn 1489: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1490: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1491: if ($designs->{'links'}{$item}) {
1.174 foxr 1492: $datatable.=' ';
1.6 raeburn 1493: }
1.174 foxr 1494: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1495: '" /></td>';
1496: }
1.30 raeburn 1497: $$rowtotal += $itemcount;
1.3 raeburn 1498: return $datatable;
1499: }
1500:
1.70 raeburn 1501: sub logo_display_options {
1502: my ($img,$defaults,$designs) = @_;
1503: my $checkedon;
1504: if (ref($defaults) eq 'HASH') {
1505: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1506: if ($defaults->{'showlogo'}{$img}) {
1507: $checkedon = 'checked="checked" ';
1508: }
1509: }
1510: }
1511: if (ref($designs) eq 'HASH') {
1512: if (ref($designs->{'showlogo'}) eq 'HASH') {
1513: if (defined($designs->{'showlogo'}{$img})) {
1514: if ($designs->{'showlogo'}{$img} == 0) {
1515: $checkedon = '';
1516: } elsif ($designs->{'showlogo'}{$img} == 1) {
1517: $checkedon = 'checked="checked" ';
1518: }
1519: }
1520: }
1521: }
1522: return '<br /><label> <input type="checkbox" name="'.
1523: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1524: &mt('show').'</label>'."\n";
1525: }
1526:
1.41 raeburn 1527: sub login_header_options {
1.135 bisitz 1528: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1529: my $output = '';
1.41 raeburn 1530: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1531: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1532: if (!$is_custom->{'textcol'}) {
1533: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1534: ' ';
1535: }
1536: if (!$is_custom->{'bgcol'}) {
1537: $output .= $choices->{'bgcol'}.': '.
1538: '<span id="css_'.$role.'_font" style="background-color: '.
1539: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1540: }
1541: $output .= '<br />';
1542: }
1543: $output .='<br />';
1544: return $output;
1545: }
1546:
1547: sub login_text_colors {
1.201 raeburn 1548: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1549: my $color_menu = '<table border="0"><tr>';
1550: foreach my $item (@{$logintext}) {
1.201 raeburn 1551: $color_menu .= '<td align="center">'.$choices->{$item};
1552: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1553: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1554: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1555: }
1556: $color_menu .= '</tr></table><br />';
1557: return $color_menu;
1558: }
1559:
1560: sub image_changes {
1561: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1562: my $output;
1.135 bisitz 1563: if ($img eq 'login') {
1564: # suppress image for Log-in header
1565: } elsif (!$is_custom) {
1.70 raeburn 1566: if ($img ne 'domlogo') {
1.41 raeburn 1567: $output .= &mt('Default image:').'<br />';
1568: } else {
1569: $output .= &mt('Default in use:').'<br />';
1570: }
1571: }
1.135 bisitz 1572: if ($img eq 'login') { # suppress image for Log-in header
1573: $output .= '<td>'.$logincolors;
1.41 raeburn 1574: } else {
1.135 bisitz 1575: if ($img_import) {
1576: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1577: }
1578: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1579: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1580: if ($is_custom) {
1581: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1582: '<input type="checkbox" name="'.
1583: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1584: '</label> '.&mt('Replace:').'</span><br />';
1585: } else {
1.201 raeburn 1586: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1587: }
1.41 raeburn 1588: }
1589: return $output;
1590: }
1591:
1.3 raeburn 1592: sub print_quotas {
1.86 raeburn 1593: my ($dom,$settings,$rowtotal,$action) = @_;
1594: my $context;
1595: if ($action eq 'quotas') {
1596: $context = 'tools';
1597: } else {
1598: $context = $action;
1599: }
1.197 raeburn 1600: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1601: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1602: my $typecount = 0;
1.101 raeburn 1603: my ($css_class,%titles);
1.86 raeburn 1604: if ($context eq 'requestcourses') {
1.216 raeburn 1605: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1606: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1607: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1608: %titles = &courserequest_titles();
1.163 raeburn 1609: } elsif ($context eq 'requestauthor') {
1610: @usertools = ('author');
1611: @options = ('norequest','approval','automatic');
1.210 raeburn 1612: %titles = &authorrequest_titles();
1.86 raeburn 1613: } else {
1.162 raeburn 1614: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1615: %titles = &tool_titles();
1.86 raeburn 1616: }
1.26 raeburn 1617: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1618: foreach my $type (@{$types}) {
1.197 raeburn 1619: my ($currdefquota,$currauthorquota);
1.163 raeburn 1620: unless (($context eq 'requestcourses') ||
1621: ($context eq 'requestauthor')) {
1.86 raeburn 1622: if (ref($settings) eq 'HASH') {
1623: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1624: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1625: } else {
1626: $currdefquota = $settings->{$type};
1627: }
1.197 raeburn 1628: if (ref($settings->{authorquota}) eq 'HASH') {
1629: $currauthorquota = $settings->{authorquota}->{$type};
1630: }
1.78 raeburn 1631: }
1.72 raeburn 1632: }
1.3 raeburn 1633: if (defined($usertypes->{$type})) {
1634: $typecount ++;
1635: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1636: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1637: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1638: '<td class="LC_left_item">';
1.101 raeburn 1639: if ($context eq 'requestcourses') {
1640: $datatable .= '<table><tr>';
1641: }
1642: my %cell;
1.72 raeburn 1643: foreach my $item (@usertools) {
1.101 raeburn 1644: if ($context eq 'requestcourses') {
1645: my ($curroption,$currlimit);
1646: if (ref($settings) eq 'HASH') {
1647: if (ref($settings->{$item}) eq 'HASH') {
1648: $curroption = $settings->{$item}->{$type};
1649: if ($curroption =~ /^autolimit=(\d*)$/) {
1650: $currlimit = $1;
1651: }
1652: }
1653: }
1654: if (!$curroption) {
1655: $curroption = 'norequest';
1656: }
1657: $datatable .= '<th>'.$titles{$item}.'</th>';
1658: foreach my $option (@options) {
1659: my $val = $option;
1660: if ($option eq 'norequest') {
1661: $val = 0;
1662: }
1663: if ($option eq 'validate') {
1664: my $canvalidate = 0;
1665: if (ref($validations{$item}) eq 'HASH') {
1666: if ($validations{$item}{$type}) {
1667: $canvalidate = 1;
1668: }
1669: }
1670: next if (!$canvalidate);
1671: }
1672: my $checked = '';
1673: if ($option eq $curroption) {
1674: $checked = ' checked="checked"';
1675: } elsif ($option eq 'autolimit') {
1676: if ($curroption =~ /^autolimit/) {
1677: $checked = ' checked="checked"';
1678: }
1679: }
1680: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1681: '<input type="radio" name="crsreq_'.$item.
1682: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1683: $titles{$option}.'</label>';
1.101 raeburn 1684: if ($option eq 'autolimit') {
1.127 raeburn 1685: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1686: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1687: 'value="'.$currlimit.'" />';
1.101 raeburn 1688: }
1.127 raeburn 1689: $cell{$item} .= '</span> ';
1.103 raeburn 1690: if ($option eq 'autolimit') {
1.127 raeburn 1691: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1692: }
1.101 raeburn 1693: }
1.163 raeburn 1694: } elsif ($context eq 'requestauthor') {
1695: my $curroption;
1696: if (ref($settings) eq 'HASH') {
1697: $curroption = $settings->{$type};
1698: }
1699: if (!$curroption) {
1700: $curroption = 'norequest';
1701: }
1702: foreach my $option (@options) {
1703: my $val = $option;
1704: if ($option eq 'norequest') {
1705: $val = 0;
1706: }
1707: my $checked = '';
1708: if ($option eq $curroption) {
1709: $checked = ' checked="checked"';
1710: }
1711: $datatable .= '<span class="LC_nobreak"><label>'.
1712: '<input type="radio" name="authorreq_'.$type.
1713: '" value="'.$val.'"'.$checked.' />'.
1714: $titles{$option}.'</label></span> ';
1715: }
1.101 raeburn 1716: } else {
1717: my $checked = 'checked="checked" ';
1718: if (ref($settings) eq 'HASH') {
1719: if (ref($settings->{$item}) eq 'HASH') {
1720: if ($settings->{$item}->{$type} == 0) {
1721: $checked = '';
1722: } elsif ($settings->{$item}->{$type} == 1) {
1723: $checked = 'checked="checked" ';
1724: }
1.78 raeburn 1725: }
1.72 raeburn 1726: }
1.101 raeburn 1727: $datatable .= '<span class="LC_nobreak"><label>'.
1728: '<input type="checkbox" name="'.$context.'_'.$item.
1729: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1730: '</label></span> ';
1.72 raeburn 1731: }
1.101 raeburn 1732: }
1733: if ($context eq 'requestcourses') {
1734: $datatable .= '</tr><tr>';
1735: foreach my $item (@usertools) {
1.106 raeburn 1736: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1737: }
1738: $datatable .= '</tr></table>';
1.72 raeburn 1739: }
1.86 raeburn 1740: $datatable .= '</td>';
1.163 raeburn 1741: unless (($context eq 'requestcourses') ||
1742: ($context eq 'requestauthor')) {
1.86 raeburn 1743: $datatable .=
1.197 raeburn 1744: '<td class="LC_right_item">'.
1745: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1746: '<input type="text" name="quota_'.$type.
1.72 raeburn 1747: '" value="'.$currdefquota.
1.197 raeburn 1748: '" size="5" /></span>'.(' ' x 2).
1749: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1750: '<input type="text" name="authorquota_'.$type.
1751: '" value="'.$currauthorquota.
1752: '" size="5" /></span></td>';
1.86 raeburn 1753: }
1754: $datatable .= '</tr>';
1.3 raeburn 1755: }
1756: }
1757: }
1.163 raeburn 1758: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1759: $defaultquota = '20';
1.197 raeburn 1760: $authorquota = '500';
1.86 raeburn 1761: if (ref($settings) eq 'HASH') {
1762: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1763: $defaultquota = $settings->{'defaultquota'}->{'default'};
1764: } elsif (defined($settings->{'default'})) {
1765: $defaultquota = $settings->{'default'};
1766: }
1.197 raeburn 1767: if (ref($settings->{'authorquota'}) eq 'HASH') {
1768: $authorquota = $settings->{'authorquota'}->{'default'};
1769: }
1.3 raeburn 1770: }
1771: }
1772: $typecount ++;
1773: $css_class = $typecount%2?' class="LC_odd_row"':'';
1774: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1775: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1776: '<td class="LC_left_item">';
1.101 raeburn 1777: if ($context eq 'requestcourses') {
1778: $datatable .= '<table><tr>';
1779: }
1780: my %defcell;
1.72 raeburn 1781: foreach my $item (@usertools) {
1.101 raeburn 1782: if ($context eq 'requestcourses') {
1783: my ($curroption,$currlimit);
1784: if (ref($settings) eq 'HASH') {
1785: if (ref($settings->{$item}) eq 'HASH') {
1786: $curroption = $settings->{$item}->{'default'};
1787: if ($curroption =~ /^autolimit=(\d*)$/) {
1788: $currlimit = $1;
1789: }
1790: }
1791: }
1792: if (!$curroption) {
1793: $curroption = 'norequest';
1794: }
1795: $datatable .= '<th>'.$titles{$item}.'</th>';
1796: foreach my $option (@options) {
1797: my $val = $option;
1798: if ($option eq 'norequest') {
1799: $val = 0;
1800: }
1801: if ($option eq 'validate') {
1802: my $canvalidate = 0;
1803: if (ref($validations{$item}) eq 'HASH') {
1804: if ($validations{$item}{'default'}) {
1805: $canvalidate = 1;
1806: }
1807: }
1808: next if (!$canvalidate);
1809: }
1810: my $checked = '';
1811: if ($option eq $curroption) {
1812: $checked = ' checked="checked"';
1813: } elsif ($option eq 'autolimit') {
1814: if ($curroption =~ /^autolimit/) {
1815: $checked = ' checked="checked"';
1816: }
1817: }
1818: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1819: '<input type="radio" name="crsreq_'.$item.
1820: '_default" value="'.$val.'"'.$checked.' />'.
1821: $titles{$option}.'</label>';
1822: if ($option eq 'autolimit') {
1.127 raeburn 1823: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1824: $item.'_limit_default" size="1" '.
1825: 'value="'.$currlimit.'" />';
1826: }
1.127 raeburn 1827: $defcell{$item} .= '</span> ';
1.104 raeburn 1828: if ($option eq 'autolimit') {
1.127 raeburn 1829: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1830: }
1.101 raeburn 1831: }
1.163 raeburn 1832: } elsif ($context eq 'requestauthor') {
1833: my $curroption;
1834: if (ref($settings) eq 'HASH') {
1.172 raeburn 1835: $curroption = $settings->{'default'};
1.163 raeburn 1836: }
1837: if (!$curroption) {
1838: $curroption = 'norequest';
1839: }
1840: foreach my $option (@options) {
1841: my $val = $option;
1842: if ($option eq 'norequest') {
1843: $val = 0;
1844: }
1845: my $checked = '';
1846: if ($option eq $curroption) {
1847: $checked = ' checked="checked"';
1848: }
1849: $datatable .= '<span class="LC_nobreak"><label>'.
1850: '<input type="radio" name="authorreq_default"'.
1851: ' value="'.$val.'"'.$checked.' />'.
1852: $titles{$option}.'</label></span> ';
1853: }
1.101 raeburn 1854: } else {
1855: my $checked = 'checked="checked" ';
1856: if (ref($settings) eq 'HASH') {
1857: if (ref($settings->{$item}) eq 'HASH') {
1858: if ($settings->{$item}->{'default'} == 0) {
1859: $checked = '';
1860: } elsif ($settings->{$item}->{'default'} == 1) {
1861: $checked = 'checked="checked" ';
1862: }
1.78 raeburn 1863: }
1.72 raeburn 1864: }
1.101 raeburn 1865: $datatable .= '<span class="LC_nobreak"><label>'.
1866: '<input type="checkbox" name="'.$context.'_'.$item.
1867: '" value="default" '.$checked.'/>'.$titles{$item}.
1868: '</label></span> ';
1869: }
1870: }
1871: if ($context eq 'requestcourses') {
1872: $datatable .= '</tr><tr>';
1873: foreach my $item (@usertools) {
1.106 raeburn 1874: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1875: }
1.101 raeburn 1876: $datatable .= '</tr></table>';
1.72 raeburn 1877: }
1.86 raeburn 1878: $datatable .= '</td>';
1.163 raeburn 1879: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1880: $datatable .= '<td class="LC_right_item">'.
1881: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1882: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1883: $defaultquota.'" size="5" /></span>'.(' ' x2).
1884: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1885: '<input type="text" name="authorquota" value="'.
1886: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1887: }
1888: $datatable .= '</tr>';
1.72 raeburn 1889: $typecount ++;
1890: $css_class = $typecount%2?' class="LC_odd_row"':'';
1891: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1892: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1893: if ($context eq 'requestcourses') {
1.109 raeburn 1894: $datatable .= &mt('(overrides affiliation, if set)').
1895: '</td>'.
1896: '<td class="LC_left_item">'.
1897: '<table><tr>';
1.101 raeburn 1898: } else {
1.109 raeburn 1899: $datatable .= &mt('(overrides affiliation, if checked)').
1900: '</td>'.
1901: '<td class="LC_left_item" colspan="2">'.
1902: '<br />';
1.101 raeburn 1903: }
1904: my %advcell;
1.72 raeburn 1905: foreach my $item (@usertools) {
1.101 raeburn 1906: if ($context eq 'requestcourses') {
1907: my ($curroption,$currlimit);
1908: if (ref($settings) eq 'HASH') {
1909: if (ref($settings->{$item}) eq 'HASH') {
1910: $curroption = $settings->{$item}->{'_LC_adv'};
1911: if ($curroption =~ /^autolimit=(\d*)$/) {
1912: $currlimit = $1;
1913: }
1914: }
1915: }
1916: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1917: my $checked = '';
1918: if ($curroption eq '') {
1919: $checked = ' checked="checked"';
1920: }
1921: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1922: '<input type="radio" name="crsreq_'.$item.
1923: '__LC_adv" value=""'.$checked.' />'.
1924: &mt('No override set').'</label></span> ';
1.101 raeburn 1925: foreach my $option (@options) {
1926: my $val = $option;
1927: if ($option eq 'norequest') {
1928: $val = 0;
1929: }
1930: if ($option eq 'validate') {
1931: my $canvalidate = 0;
1932: if (ref($validations{$item}) eq 'HASH') {
1933: if ($validations{$item}{'_LC_adv'}) {
1934: $canvalidate = 1;
1935: }
1936: }
1937: next if (!$canvalidate);
1938: }
1939: my $checked = '';
1.104 raeburn 1940: if ($val eq $curroption) {
1.101 raeburn 1941: $checked = ' checked="checked"';
1942: } elsif ($option eq 'autolimit') {
1943: if ($curroption =~ /^autolimit/) {
1944: $checked = ' checked="checked"';
1945: }
1946: }
1947: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1948: '<input type="radio" name="crsreq_'.$item.
1949: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1950: $titles{$option}.'</label>';
1951: if ($option eq 'autolimit') {
1.127 raeburn 1952: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1953: $item.'_limit__LC_adv" size="1" '.
1954: 'value="'.$currlimit.'" />';
1955: }
1.127 raeburn 1956: $advcell{$item} .= '</span> ';
1.104 raeburn 1957: if ($option eq 'autolimit') {
1.127 raeburn 1958: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1959: }
1.101 raeburn 1960: }
1.163 raeburn 1961: } elsif ($context eq 'requestauthor') {
1962: my $curroption;
1963: if (ref($settings) eq 'HASH') {
1964: $curroption = $settings->{'_LC_adv'};
1965: }
1966: my $checked = '';
1967: if ($curroption eq '') {
1968: $checked = ' checked="checked"';
1969: }
1970: $datatable .= '<span class="LC_nobreak"><label>'.
1971: '<input type="radio" name="authorreq__LC_adv"'.
1972: ' value=""'.$checked.' />'.
1973: &mt('No override set').'</label></span> ';
1974: foreach my $option (@options) {
1975: my $val = $option;
1976: if ($option eq 'norequest') {
1977: $val = 0;
1978: }
1979: my $checked = '';
1980: if ($val eq $curroption) {
1981: $checked = ' checked="checked"';
1982: }
1983: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1984: '<input type="radio" name="authorreq__LC_adv"'.
1985: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1986: $titles{$option}.'</label></span> ';
1987: }
1.101 raeburn 1988: } else {
1989: my $checked = 'checked="checked" ';
1990: if (ref($settings) eq 'HASH') {
1991: if (ref($settings->{$item}) eq 'HASH') {
1992: if ($settings->{$item}->{'_LC_adv'} == 0) {
1993: $checked = '';
1994: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1995: $checked = 'checked="checked" ';
1996: }
1.79 raeburn 1997: }
1.72 raeburn 1998: }
1.101 raeburn 1999: $datatable .= '<span class="LC_nobreak"><label>'.
2000: '<input type="checkbox" name="'.$context.'_'.$item.
2001: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2002: '</label></span> ';
2003: }
2004: }
2005: if ($context eq 'requestcourses') {
2006: $datatable .= '</tr><tr>';
2007: foreach my $item (@usertools) {
1.106 raeburn 2008: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2009: }
1.101 raeburn 2010: $datatable .= '</tr></table>';
1.72 raeburn 2011: }
1.98 raeburn 2012: $datatable .= '</td></tr>';
1.30 raeburn 2013: $$rowtotal += $typecount;
1.3 raeburn 2014: return $datatable;
2015: }
2016:
1.163 raeburn 2017: sub print_requestmail {
2018: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2019: my ($now,$datatable,%currapp);
1.102 raeburn 2020: $now = time;
2021: if (ref($settings) eq 'HASH') {
2022: if (ref($settings->{'notify'}) eq 'HASH') {
2023: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2024: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2025: }
2026: }
2027: }
1.191 raeburn 2028: my $numinrow = 2;
1.224 raeburn 2029: my $css_class;
2030: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2031: my $text;
2032: if ($action eq 'requestcourses') {
2033: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2034: } elsif ($action eq 'requestauthor') {
2035: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2036: } else {
1.224 raeburn 2037: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2038: }
1.224 raeburn 2039: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2040: ' <td>'.$text.'</td>'.
1.102 raeburn 2041: ' <td class="LC_left_item">';
1.191 raeburn 2042: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2043: $action.'notifyapproval',%currapp);
1.191 raeburn 2044: if ($numdc > 0) {
2045: $datatable .= $table;
1.102 raeburn 2046: } else {
2047: $datatable .= &mt('There are no active Domain Coordinators');
2048: }
2049: $datatable .='</td></tr>';
2050: $$rowtotal += $rows;
2051: return $datatable;
2052: }
2053:
1.216 raeburn 2054: sub print_studentcode {
2055: my ($settings,$rowtotal) = @_;
2056: my $rownum = 0;
1.218 raeburn 2057: my ($output,%current);
2058: my @crstypes = ('official','unofficial','community','textbook');
2059: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2060: foreach my $type (@crstypes) {
2061: $current{$type} = $settings->{'uniquecode'}{$type};
2062: }
2063: }
2064: $output .= '<tr>'.
2065: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2066: '<td class="LC_left_item">';
2067: foreach my $type (@crstypes) {
2068: my $check = ' ';
2069: if ($current{$type}) {
2070: $check = ' checked="checked" ';
2071: }
2072: $output .= '<span class="LC_nobreak"><label>'.
2073: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2074: &mt($type).'</label></span>'.(' 'x2).' ';
2075: }
2076: $output .= '</td></tr>';
2077: $$rowtotal ++;
2078: return $output;
1.216 raeburn 2079: }
2080:
2081: sub print_textbookcourses {
2082: my ($dom,$settings,$rowtotal) = @_;
2083: my $rownum = 0;
2084: my $css_class;
2085: my $itemcount = 1;
2086: my $maxnum = 0;
2087: my $bookshash;
2088: if (ref($settings) eq 'HASH') {
2089: $bookshash = $settings->{'textbooks'};
2090: }
2091: my %ordered;
2092: if (ref($bookshash) eq 'HASH') {
2093: foreach my $item (keys(%{$bookshash})) {
2094: if (ref($bookshash->{$item}) eq 'HASH') {
2095: my $num = $bookshash->{$item}{'order'};
2096: $ordered{$num} = $item;
2097: }
2098: }
2099: }
2100: my $confname = $dom.'-domainconfig';
2101: my $switchserver = &check_switchserver($dom,$confname);
2102: my $maxnum = scalar(keys(%ordered));
1.217 raeburn 2103: my $datatable = &textbookcourses_javascript(\%ordered);
1.216 raeburn 2104: if (keys(%ordered)) {
2105: my @items = sort { $a <=> $b } keys(%ordered);
2106: for (my $i=0; $i<@items; $i++) {
2107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2108: my $key = $ordered{$items[$i]};
2109: my %coursehash=&Apache::lonnet::coursedescription($key);
2110: my $coursetitle = $coursehash{'description'};
2111: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2112: if (ref($bookshash->{$key}) eq 'HASH') {
2113: $subject = $bookshash->{$key}->{'subject'};
2114: $title = $bookshash->{$key}->{'title'};
2115: $author = $bookshash->{$key}->{'author'};
2116: $image = $bookshash->{$key}->{'image'};
2117: if ($image ne '') {
2118: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2119: my $imagethumb = "$path/tn-".$imagefile;
2120: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2121: }
2122: }
1.217 raeburn 2123: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216 raeburn 2124: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2125: .'<select name="'.$key.'"'.$chgstr.'>';
2126: for (my $k=0; $k<=$maxnum; $k++) {
2127: my $vpos = $k+1;
2128: my $selstr;
2129: if ($k == $i) {
2130: $selstr = ' selected="selected" ';
2131: }
2132: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2133: }
2134: $datatable .= '</select>'.(' 'x2).
2135: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2136: &mt('Delete?').'</label></span></td>'.
2137: '<td colspan="2">'.
2138: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2139: (' 'x2).
2140: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2141: (' 'x2).
2142: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2143: (' 'x2).
2144: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2145: if ($image) {
2146: $datatable .= '<span class="LC_nobreak">'.
2147: $imgsrc.
2148: '<label><input type="checkbox" name="book_image_del"'.
2149: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2150: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2151: }
2152: if ($switchserver) {
2153: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2154: } else {
2155: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2156: }
2157: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2158: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2159: $coursetitle.'</span></td></tr>'."\n";
2160: $itemcount ++;
2161: }
2162: }
2163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217 raeburn 2164: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216 raeburn 2165: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2166: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2167: '<select name="addbook_pos"'.$chgstr.'>';
2168: for (my $k=0; $k<$maxnum+1; $k++) {
2169: my $vpos = $k+1;
2170: my $selstr;
2171: if ($k == $maxnum) {
2172: $selstr = ' selected="selected" ';
2173: }
2174: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2175: }
2176: $datatable .= '</select> '."\n".
2177: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2178: '<td colspan="2">'.
2179: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2180: (' 'x2).
2181: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2182: (' 'x2).
2183: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2184: (' 'x2).
2185: '<span class="LC_nobreak">'.&mt('Image:').' ';
2186: if ($switchserver) {
2187: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2188: } else {
2189: $datatable .= '<input type="file" name="addbook_image" value="" />';
2190: }
2191: $datatable .= '</span>'."\n".
2192: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2193: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2194: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2195: &Apache::loncommon::selectcourse_link
2196: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2197: '</span></td>'."\n".
2198: '</tr>'."\n";
2199: $itemcount ++;
2200: return $datatable;
2201: }
2202:
1.217 raeburn 2203: sub textbookcourses_javascript {
2204: my ($textbooks) = @_;
2205: return unless(ref($textbooks) eq 'HASH');
2206: my $num = scalar(keys(%{$textbooks}));
2207: my @jsarray;
2208: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2209: push(@jsarray,$textbooks->{$item});
2210: }
2211: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2212: return <<"ENDSCRIPT";
2213: <script type="text/javascript">
2214: // <![CDATA[
2215: function reorderBooks(form,item) {
2216: var changedVal;
2217: $jstext
2218: var newpos = 'addbook_pos';
2219: var current = new Array;
2220: var maxh = 1 + $num;
2221: var current = new Array;
2222: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2223: if (item == newpos) {
2224: changedVal = newitemVal;
2225: } else {
2226: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2227: current[newitemVal] = newpos;
2228: }
2229: for (var i=0; i<textbooks.length; i++) {
2230: var elementName = textbooks[i];
2231: if (elementName != item) {
2232: if (form.elements[elementName]) {
2233: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2234: current[currVal] = elementName;
2235: }
2236: }
2237: }
2238: var oldVal;
2239: for (var j=0; j<maxh; j++) {
2240: if (current[j] == undefined) {
2241: oldVal = j;
2242: }
2243: }
2244: if (oldVal < changedVal) {
2245: for (var k=oldVal+1; k<=changedVal ; k++) {
2246: var elementName = current[k];
2247: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2248: }
2249: } else {
2250: for (var k=changedVal; k<oldVal; k++) {
2251: var elementName = current[k];
2252: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2253: }
2254: }
2255: return;
2256: }
2257:
2258: // ]]>
2259: </script>
2260:
2261: ENDSCRIPT
2262: }
2263:
1.3 raeburn 2264: sub print_autoenroll {
1.30 raeburn 2265: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2266: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2267: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2268: if (ref($settings) eq 'HASH') {
2269: if (exists($settings->{'run'})) {
2270: if ($settings->{'run'} eq '0') {
2271: $runoff = ' checked="checked" ';
2272: $runon = ' ';
2273: } else {
2274: $runon = ' checked="checked" ';
2275: $runoff = ' ';
2276: }
2277: } else {
2278: if ($autorun) {
2279: $runon = ' checked="checked" ';
2280: $runoff = ' ';
2281: } else {
2282: $runoff = ' checked="checked" ';
2283: $runon = ' ';
2284: }
2285: }
1.129 raeburn 2286: if (exists($settings->{'co-owners'})) {
2287: if ($settings->{'co-owners'} eq '0') {
2288: $coownersoff = ' checked="checked" ';
2289: $coownerson = ' ';
2290: } else {
2291: $coownerson = ' checked="checked" ';
2292: $coownersoff = ' ';
2293: }
2294: } else {
2295: $coownersoff = ' checked="checked" ';
2296: $coownerson = ' ';
2297: }
1.3 raeburn 2298: if (exists($settings->{'sender_domain'})) {
2299: $defdom = $settings->{'sender_domain'};
2300: }
1.14 raeburn 2301: } else {
2302: if ($autorun) {
2303: $runon = ' checked="checked" ';
2304: $runoff = ' ';
2305: } else {
2306: $runoff = ' checked="checked" ';
2307: $runon = ' ';
2308: }
1.3 raeburn 2309: }
2310: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2311: my $notif_sender;
2312: if (ref($settings) eq 'HASH') {
2313: $notif_sender = $settings->{'sender_uname'};
2314: }
1.3 raeburn 2315: my $datatable='<tr class="LC_odd_row">'.
2316: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2317: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2318: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2319: $runon.' value="1" />'.&mt('Yes').'</label> '.
2320: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2321: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2322: '</tr><tr>'.
2323: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2324: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2325: &mt('username').': '.
2326: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2327: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2328: ': '.$domform.'</span></td></tr>'.
2329: '<tr class="LC_odd_row">'.
2330: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2331: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2332: '<input type="radio" name="autoassign_coowners"'.
2333: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2334: '<label><input type="radio" name="autoassign_coowners"'.
2335: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2336: '</tr>';
2337: $$rowtotal += 3;
1.3 raeburn 2338: return $datatable;
2339: }
2340:
2341: sub print_autoupdate {
1.30 raeburn 2342: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2343: my $datatable;
2344: if ($position eq 'top') {
2345: my $updateon = ' ';
2346: my $updateoff = ' checked="checked" ';
2347: my $classlistson = ' ';
2348: my $classlistsoff = ' checked="checked" ';
2349: if (ref($settings) eq 'HASH') {
2350: if ($settings->{'run'} eq '1') {
2351: $updateon = $updateoff;
2352: $updateoff = ' ';
2353: }
2354: if ($settings->{'classlists'} eq '1') {
2355: $classlistson = $classlistsoff;
2356: $classlistsoff = ' ';
2357: }
2358: }
2359: my %title = (
2360: run => 'Auto-update active?',
2361: classlists => 'Update information in classlists?',
2362: );
2363: $datatable = '<tr class="LC_odd_row">'.
2364: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2365: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2366: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2367: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2368: '<label><input type="radio" name="autoupdate_run"'.
2369: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2370: '</tr><tr>'.
2371: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2372: '<td class="LC_right_item"><span class="LC_nobreak">'.
2373: '<label><input type="radio" name="classlists"'.
2374: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2375: '<label><input type="radio" name="classlists"'.
2376: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2377: '</tr>';
1.30 raeburn 2378: $$rowtotal += 2;
1.131 raeburn 2379: } elsif ($position eq 'middle') {
2380: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2381: my $numinrow = 3;
2382: my $locknamesettings;
2383: $datatable .= &insttypes_row($settings,$types,$usertypes,
2384: $dom,$numinrow,$othertitle,
2385: 'lockablenames');
2386: $$rowtotal ++;
1.3 raeburn 2387: } else {
1.44 raeburn 2388: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2389: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2390: 'permanentemail','id');
1.33 raeburn 2391: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2392: my $numrows = 0;
1.26 raeburn 2393: if (ref($types) eq 'ARRAY') {
2394: if (@{$types} > 0) {
2395: $datatable =
2396: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2397: \@fields,$types,\$numrows);
1.30 raeburn 2398: $$rowtotal += @{$types};
1.26 raeburn 2399: }
1.3 raeburn 2400: }
2401: $datatable .=
2402: &usertype_update_row($settings,{'default' => $othertitle},
2403: \%fieldtitles,\@fields,['default'],
2404: \$numrows);
1.30 raeburn 2405: $$rowtotal ++;
1.3 raeburn 2406: }
2407: return $datatable;
2408: }
2409:
1.125 raeburn 2410: sub print_autocreate {
2411: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2412: my (%createon,%createoff,%currhash);
1.125 raeburn 2413: my @types = ('xml','req');
2414: if (ref($settings) eq 'HASH') {
2415: foreach my $item (@types) {
2416: $createoff{$item} = ' checked="checked" ';
2417: $createon{$item} = ' ';
2418: if (exists($settings->{$item})) {
2419: if ($settings->{$item}) {
2420: $createon{$item} = ' checked="checked" ';
2421: $createoff{$item} = ' ';
2422: }
2423: }
2424: }
1.210 raeburn 2425: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2426: $currhash{$settings->{'xmldc'}} = 1;
2427: }
1.125 raeburn 2428: } else {
2429: foreach my $item (@types) {
2430: $createoff{$item} = ' checked="checked" ';
2431: $createon{$item} = ' ';
2432: }
2433: }
2434: $$rowtotal += 2;
1.191 raeburn 2435: my $numinrow = 2;
1.125 raeburn 2436: my $datatable='<tr class="LC_odd_row">'.
2437: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2438: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2439: '<input type="radio" name="autocreate_xml"'.
2440: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2441: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2442: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2443: '</td></tr><tr>'.
2444: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2445: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2446: '<input type="radio" name="autocreate_req"'.
2447: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2448: '<label><input type="radio" name="autocreate_req"'.
2449: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2450: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2451: 'autocreate_xmldc',%currhash);
1.125 raeburn 2452: if ($numdc > 1) {
1.143 raeburn 2453: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2454: &mt('Course creation processed as: (choose Dom. Coord.)').
2455: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2456: } else {
1.143 raeburn 2457: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2458: }
1.191 raeburn 2459: $$rowtotal += $rows;
1.125 raeburn 2460: return $datatable;
2461: }
2462:
1.23 raeburn 2463: sub print_directorysrch {
1.30 raeburn 2464: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2465: my $srchon = ' ';
2466: my $srchoff = ' checked="checked" ';
1.25 raeburn 2467: my ($exacton,$containson,$beginson);
1.24 raeburn 2468: my $localon = ' ';
2469: my $localoff = ' checked="checked" ';
1.23 raeburn 2470: if (ref($settings) eq 'HASH') {
2471: if ($settings->{'available'} eq '1') {
2472: $srchon = $srchoff;
2473: $srchoff = ' ';
2474: }
1.24 raeburn 2475: if ($settings->{'localonly'} eq '1') {
2476: $localon = $localoff;
2477: $localoff = ' ';
2478: }
1.25 raeburn 2479: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2480: foreach my $type (@{$settings->{'searchtypes'}}) {
2481: if ($type eq 'exact') {
2482: $exacton = ' checked="checked" ';
2483: } elsif ($type eq 'contains') {
2484: $containson = ' checked="checked" ';
2485: } elsif ($type eq 'begins') {
2486: $beginson = ' checked="checked" ';
2487: }
2488: }
2489: } else {
2490: if ($settings->{'searchtypes'} eq 'exact') {
2491: $exacton = ' checked="checked" ';
2492: } elsif ($settings->{'searchtypes'} eq 'contains') {
2493: $containson = ' checked="checked" ';
2494: } elsif ($settings->{'searchtypes'} eq 'specify') {
2495: $exacton = ' checked="checked" ';
2496: $containson = ' checked="checked" ';
2497: }
1.23 raeburn 2498: }
2499: }
2500: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2501: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2502:
2503: my $numinrow = 4;
1.26 raeburn 2504: my $cansrchrow = 0;
1.23 raeburn 2505: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2506: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2507: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2508: '<input type="radio" name="dirsrch_available"'.
2509: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2510: '<label><input type="radio" name="dirsrch_available"'.
2511: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2512: '</tr><tr>'.
1.30 raeburn 2513: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2514: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2515: '<input type="radio" name="dirsrch_localonly"'.
2516: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2517: '<label><input type="radio" name="dirsrch_localonly"'.
2518: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2519: '</tr>';
1.30 raeburn 2520: $$rowtotal += 2;
1.26 raeburn 2521: if (ref($usertypes) eq 'HASH') {
2522: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2523: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2524: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2525: $cansrchrow = 1;
2526: }
2527: }
2528: if ($cansrchrow) {
1.30 raeburn 2529: $$rowtotal ++;
1.26 raeburn 2530: $datatable .= '<tr>';
2531: } else {
2532: $datatable .= '<tr class="LC_odd_row">';
2533: }
1.30 raeburn 2534: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2535: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2536: foreach my $title (@{$titleorder}) {
2537: if (defined($searchtitles->{$title})) {
2538: my $check = ' ';
1.93 raeburn 2539: if (ref($settings) eq 'HASH') {
1.39 raeburn 2540: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2541: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2542: $check = ' checked="checked" ';
2543: }
1.25 raeburn 2544: }
2545: }
2546: $datatable .= '<td class="LC_left_item">'.
2547: '<span class="LC_nobreak"><label>'.
2548: '<input type="checkbox" name="searchby" '.
2549: 'value="'.$title.'"'.$check.'/>'.
2550: $searchtitles->{$title}.'</label></span></td>';
2551: }
2552: }
1.26 raeburn 2553: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2554: $$rowtotal ++;
1.26 raeburn 2555: if ($cansrchrow) {
2556: $datatable .= '<tr class="LC_odd_row">';
2557: } else {
2558: $datatable .= '<tr>';
2559: }
1.30 raeburn 2560: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2561: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2562: '<span class="LC_nobreak"><label>'.
2563: '<input type="checkbox" name="searchtypes" '.
2564: $exacton.' value="exact" />'.&mt('Exact match').
2565: '</label> '.
2566: '<label><input type="checkbox" name="searchtypes" '.
2567: $beginson.' value="begins" />'.&mt('Begins with').
2568: '</label> '.
2569: '<label><input type="checkbox" name="searchtypes" '.
2570: $containson.' value="contains" />'.&mt('Contains').
2571: '</label></span></td></tr>';
1.30 raeburn 2572: $$rowtotal ++;
1.25 raeburn 2573: return $datatable;
2574: }
2575:
1.28 raeburn 2576: sub print_contacts {
1.30 raeburn 2577: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2578: my $datatable;
2579: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2580: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2581: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2582: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2583: foreach my $type (@mailings) {
2584: $otheremails{$type} = '';
2585: }
1.134 raeburn 2586: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2587: if (ref($settings) eq 'HASH') {
2588: foreach my $item (@contacts) {
2589: if (exists($settings->{$item})) {
2590: $to{$item} = $settings->{$item};
2591: }
2592: }
2593: foreach my $type (@mailings) {
2594: if (exists($settings->{$type})) {
2595: if (ref($settings->{$type}) eq 'HASH') {
2596: foreach my $item (@contacts) {
2597: if ($settings->{$type}{$item}) {
2598: $checked{$type}{$item} = ' checked="checked" ';
2599: }
2600: }
2601: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2602: if ($type eq 'helpdeskmail') {
2603: $bccemails{$type} = $settings->{$type}{'bcc'};
2604: }
1.28 raeburn 2605: }
1.89 raeburn 2606: } elsif ($type eq 'lonstatusmail') {
2607: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2608: }
2609: }
2610: } else {
2611: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2612: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2613: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2614: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2615: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2616: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2617: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2618: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2619: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2620: }
2621: my ($titles,$short_titles) = &contact_titles();
2622: my $rownum = 0;
2623: my $css_class;
2624: foreach my $item (@contacts) {
1.69 raeburn 2625: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2626: $datatable .= '<tr'.$css_class.'>'.
2627: '<td><span class="LC_nobreak">'.$titles->{$item}.
2628: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2629: '<input type="text" name="'.$item.'" value="'.
2630: $to{$item}.'" /></td></tr>';
1.203 raeburn 2631: $rownum ++;
1.28 raeburn 2632: }
2633: foreach my $type (@mailings) {
1.69 raeburn 2634: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2635: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2636: '<td><span class="LC_nobreak">'.
2637: $titles->{$type}.': </span></td>'.
1.28 raeburn 2638: '<td class="LC_left_item">'.
2639: '<span class="LC_nobreak">';
2640: foreach my $item (@contacts) {
2641: $datatable .= '<label>'.
2642: '<input type="checkbox" name="'.$type.'"'.
2643: $checked{$type}{$item}.
2644: ' value="'.$item.'" />'.$short_titles->{$item}.
2645: '</label> ';
2646: }
2647: $datatable .= '</span><br />'.&mt('Others').': '.
2648: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2649: 'value="'.$otheremails{$type}.'" />';
2650: if ($type eq 'helpdeskmail') {
1.136 raeburn 2651: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2652: '<input type="text" name="'.$type.'_bcc" '.
2653: 'value="'.$bccemails{$type}.'" />';
2654: }
2655: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2656: $rownum ++;
1.28 raeburn 2657: }
1.203 raeburn 2658: my %choices;
2659: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2660: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2661: &mt('LON-CAPA core group - MSU'),600,500));
2662: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2663: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2664: &mt('LON-CAPA core group - MSU'),600,500));
2665: my @toggles = ('reporterrors','reportupdates');
2666: my %defaultchecked = ('reporterrors' => 'on',
2667: 'reportupdates' => 'on');
2668: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2669: \%choices,$rownum);
2670: $datatable .= $reports;
1.30 raeburn 2671: $$rowtotal += $rownum;
1.28 raeburn 2672: return $datatable;
2673: }
2674:
1.118 jms 2675: sub print_helpsettings {
1.168 raeburn 2676: my ($dom,$confname,$settings,$rowtotal) = @_;
2677: my ($datatable,$itemcount);
1.166 raeburn 2678: $itemcount = 1;
1.168 raeburn 2679: my (%choices,%defaultchecked,@toggles);
2680: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2681: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2682: &mt('LON-CAPA bug tracker'),600,500));
2683: %defaultchecked = ('submitbugs' => 'on');
2684: @toggles = ('submitbugs',);
1.166 raeburn 2685:
1.168 raeburn 2686: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2687: \%choices,$itemcount);
1.166 raeburn 2688: return $datatable;
1.121 raeburn 2689: }
2690:
2691: sub radiobutton_prefs {
1.192 raeburn 2692: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2693: $additional) = @_;
1.121 raeburn 2694: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2695: (ref($choices) eq 'HASH'));
2696:
1.170 raeburn 2697: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2698:
2699: foreach my $item (@{$toggles}) {
2700: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2701: $checkedon{$item} = ' checked="checked" ';
2702: $checkedoff{$item} = ' ';
1.121 raeburn 2703: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2704: $checkedoff{$item} = ' checked="checked" ';
2705: $checkedon{$item} = ' ';
2706: }
2707: }
2708: if (ref($settings) eq 'HASH') {
1.121 raeburn 2709: foreach my $item (@{$toggles}) {
1.118 jms 2710: if ($settings->{$item} eq '1') {
2711: $checkedon{$item} = ' checked="checked" ';
2712: $checkedoff{$item} = ' ';
2713: } elsif ($settings->{$item} eq '0') {
2714: $checkedoff{$item} = ' checked="checked" ';
2715: $checkedon{$item} = ' ';
2716: }
2717: }
1.121 raeburn 2718: }
1.192 raeburn 2719: if ($onclick) {
2720: $onclick = ' onclick="'.$onclick.'"';
2721: }
1.121 raeburn 2722: foreach my $item (@{$toggles}) {
1.118 jms 2723: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2724: $datatable .=
1.192 raeburn 2725: '<tr'.$css_class.'><td valign="top">'.
2726: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2727: '</span></td>'.
2728: '<td class="LC_right_item"><span class="LC_nobreak">'.
2729: '<label><input type="radio" name="'.
1.192 raeburn 2730: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2731: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2732: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2733: '</span>'.$additional.
2734: '</td>'.
1.118 jms 2735: '</tr>';
2736: $itemcount ++;
1.121 raeburn 2737: }
2738: return ($datatable,$itemcount);
2739: }
2740:
2741: sub print_coursedefaults {
1.139 raeburn 2742: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2743: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2744: my $itemcount = 1;
1.192 raeburn 2745: my %choices = &Apache::lonlocal::texthash (
2746: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2747: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2748: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2749: coursecredits => 'Credits can be specified for courses',
2750: );
1.198 raeburn 2751: my %staticdefaults = (
2752: anonsurvey_threshold => 10,
2753: uploadquota => 500,
2754: );
1.139 raeburn 2755: if ($position eq 'top') {
2756: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2757: @toggles = ('canuse_pdfforms');
1.139 raeburn 2758: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2759: \%choices,$itemcount);
1.139 raeburn 2760: } else {
2761: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2762: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2763: %curruploadquota);
1.192 raeburn 2764: my $currusecredits = 0;
1.216 raeburn 2765: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2766: if (ref($settings) eq 'HASH') {
2767: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2768: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2769: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2770: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2771: }
2772: }
1.192 raeburn 2773: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2774: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2775: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2776: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2777: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2778: ($def_textbook_credits ne '')) {
1.192 raeburn 2779: $currusecredits = 1;
2780: }
2781: }
1.139 raeburn 2782: }
2783: if (!$currdefresponder) {
1.198 raeburn 2784: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2785: } elsif ($currdefresponder < 1) {
2786: $currdefresponder = 1;
2787: }
1.198 raeburn 2788: foreach my $type (@types) {
2789: if ($curruploadquota{$type} eq '') {
2790: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2791: }
2792: }
1.139 raeburn 2793: $datatable .=
1.192 raeburn 2794: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2795: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2796: '</span></td>'.
2797: '<td class="LC_right_item"><span class="LC_nobreak">'.
2798: '<input type="text" name="anonsurvey_threshold"'.
2799: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2800: '</td></tr>'."\n";
2801: $itemcount ++;
2802: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2803: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2804: $choices{'uploadquota'}.
2805: '</span></td>'.
2806: '<td align="right" class="LC_right_item">'.
2807: '<table><tr>';
1.198 raeburn 2808: foreach my $type (@types) {
2809: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2810: '<input type="text" name="uploadquota_'.$type.'"'.
2811: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2812: }
2813: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2814: $itemcount ++;
1.192 raeburn 2815: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2816: my $display = 'none';
1.192 raeburn 2817: if ($currusecredits) {
2818: $display = 'block';
2819: }
2820: my $additional = '<div id="credits" style="display: '.$display.'">'.
2821: '<span class="LC_nobreak">'.
2822: &mt('Default credits for official courses [_1]',
2823: '<input type="text" name="official_credits" value="'.
2824: $def_official_credits.'" size="3" />').
2825: '</span><br />'.
2826: '<span class="LC_nobreak">'.
2827: &mt('Default credits for unofficial courses [_1]',
2828: '<input type="text" name="unofficial_credits" value="'.
2829: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2830: '</span><br />'.
2831: '<span class="LC_nobreak">'.
2832: &mt('Default credits for textbook courses [_1]',
2833: '<input type="text" name="textbook_credits" value="'.
2834: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2835: '</span></div>'."\n";
2836: %defaultchecked = ('coursecredits' => 'off');
2837: @toggles = ('coursecredits');
2838: my $current = {
2839: 'coursecredits' => $currusecredits,
2840: };
2841: (my $table,$itemcount) =
2842: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2843: \%choices,$itemcount,$onclick,$additional);
2844: $datatable .= $table;
1.230 raeburn 2845: $itemcount ++;
1.139 raeburn 2846: }
1.192 raeburn 2847: $$rowtotal += $itemcount;
1.121 raeburn 2848: return $datatable;
1.118 jms 2849: }
2850:
1.231 raeburn 2851: sub print_selfenrollment {
2852: my ($position,$dom,$settings,$rowtotal) = @_;
2853: my ($css_class,$datatable);
2854: my $itemcount = 1;
2855: my @types = ('official','unofficial','community','textbook');
2856: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 2857: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2858: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 2859: my @rows;
2860: my $key;
2861: if ($position eq 'top') {
2862: $key = 'admin';
2863: if (ref($rowsref) eq 'ARRAY') {
2864: @rows = @{$rowsref};
2865: }
2866: } elsif ($position eq 'middle') {
2867: $key = 'default';
2868: @rows = ('types','registered','approval','limit');
2869: }
2870: foreach my $row (@rows) {
2871: if (defined($titlesref->{$row})) {
2872: $itemcount ++;
2873: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2874: $datatable .= '<tr'.$css_class.'>'.
2875: '<td>'.$titlesref->{$row}.'</td>'.
2876: '<td class="LC_left_item">'.
2877: '<table><tr>';
2878: my (%current,%currentcap);
2879: if (ref($settings) eq 'HASH') {
2880: if (ref($settings->{$key}) eq 'HASH') {
2881: foreach my $type (@types) {
2882: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2883: $current{$type} = $settings->{$key}->{$type}->{$row};
2884: }
2885: if (($row eq 'limit') && ($key eq 'default')) {
2886: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2887: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2888: }
2889: }
2890: }
2891: }
2892: }
2893: my %roles = (
2894: '0' => &Apache::lonnet::plaintext('dc'),
2895: );
2896:
2897: foreach my $type (@types) {
2898: unless (($row eq 'registered') && ($key eq 'default')) {
2899: $datatable .= '<th>'.&mt($type).'</th>';
2900: }
2901: }
2902: unless (($row eq 'registered') && ($key eq 'default')) {
2903: $datatable .= '</tr><tr>';
2904: }
2905: foreach my $type (@types) {
2906: if ($type eq 'community') {
2907: $roles{'1'} = &mt('Community personnel');
2908: } else {
2909: $roles{'1'} = &mt('Course personnel');
2910: }
2911: $datatable .= '<td style="vertical-align: top">';
2912: if ($position eq 'top') {
2913: my %checked;
2914: if ($current{$type} eq '0') {
2915: $checked{'0'} = ' checked="checked"';
2916: } else {
2917: $checked{'1'} = ' checked="checked"';
2918: }
2919: foreach my $role ('1','0') {
2920: $datatable .= '<span class="LC_nobreak"><label>'.
2921: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2922: 'value="'.$role.'"'.$checked{$role}.' />'.
2923: $roles{$role}.'</label></span> ';
2924: }
2925: } else {
2926: if ($row eq 'types') {
2927: my %checked;
2928: if ($current{$type} =~ /^(all|dom)$/) {
2929: $checked{$1} = ' checked="checked"';
2930: } else {
2931: $checked{''} = ' checked="checked"';
2932: }
2933: foreach my $val ('','dom','all') {
2934: $datatable .= '<span class="LC_nobreak"><label>'.
2935: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2936: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2937: }
2938: } elsif ($row eq 'registered') {
2939: my %checked;
2940: if ($current{$type} eq '1') {
2941: $checked{'1'} = ' checked="checked"';
2942: } else {
2943: $checked{'0'} = ' checked="checked"';
2944: }
2945: foreach my $val ('0','1') {
2946: $datatable .= '<span class="LC_nobreak"><label>'.
2947: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2948: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2949: }
2950: } elsif ($row eq 'approval') {
2951: my %checked;
2952: if ($current{$type} =~ /^([12])$/) {
2953: $checked{$1} = ' checked="checked"';
2954: } else {
2955: $checked{'0'} = ' checked="checked"';
2956: }
2957: for my $val (0..2) {
2958: $datatable .= '<span class="LC_nobreak"><label>'.
2959: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2960: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2961: }
2962: } elsif ($row eq 'limit') {
2963: my %checked;
2964: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
2965: $checked{$1} = ' checked="checked"';
2966: } else {
2967: $checked{'none'} = ' checked="checked"';
2968: }
2969: my $cap;
2970: if ($currentcap{$type} =~ /^\d+$/) {
2971: $cap = $currentcap{$type};
2972: }
2973: foreach my $val ('none','allstudents','selfenrolled') {
2974: $datatable .= '<span class="LC_nobreak"><label>'.
2975: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2976: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2977: }
2978: $datatable .= '<br />'.
2979: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
2980: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
2981: '</span>';
2982: }
2983: }
2984: $datatable .= '</td>';
2985: }
2986: $datatable .= '</tr>';
2987: }
2988: $datatable .= '</table></td></tr>';
2989: }
2990: } elsif ($position eq 'bottom') {
1.235 ! raeburn 2991: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
! 2992: }
! 2993: $$rowtotal += $itemcount;
! 2994: return $datatable;
! 2995: }
! 2996:
! 2997: sub print_validation_rows {
! 2998: my ($caller,$dom,$settings,$rowtotal) = @_;
! 2999: my ($itemsref,$namesref,$fieldsref);
! 3000: if ($caller eq 'selfenroll') {
! 3001: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
! 3002: } elsif ($caller eq 'requestcourses') {
! 3003: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
! 3004: }
! 3005: my %currvalidation;
! 3006: if (ref($settings) eq 'HASH') {
! 3007: if (ref($settings->{'validation'}) eq 'HASH') {
! 3008: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3009: }
1.235 ! raeburn 3010: }
! 3011: my $datatable;
! 3012: my $itemcount = 0;
! 3013: foreach my $item (@{$itemsref}) {
! 3014: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 3015: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
! 3016: $namesref->{$item}.
! 3017: '</span></td>'.
! 3018: '<td class="LC_left_item">';
! 3019: if (($item eq 'url') || ($item eq 'button')) {
! 3020: $datatable .= '<span class="LC_nobreak">'.
! 3021: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
! 3022: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
! 3023: } elsif ($item eq 'fields') {
! 3024: my @currfields;
! 3025: if (ref($currvalidation{$item}) eq 'ARRAY') {
! 3026: @currfields = @{$currvalidation{$item}};
! 3027: }
! 3028: foreach my $field (@{$fieldsref}) {
! 3029: my $check = '';
! 3030: if (grep(/^\Q$field\E$/,@currfields)) {
! 3031: $check = ' checked="checked"';
! 3032: }
! 3033: $datatable .= '<span class="LC_nobreak"><label>'.
! 3034: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
! 3035: ' value="'.$field.'"'.$check.' />'.$field.
! 3036: '</label></span> ';
! 3037: }
! 3038: } elsif ($item eq 'markup') {
! 3039: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
! 3040: $currvalidation{$item}.
1.231 raeburn 3041: '</textarea>';
1.235 ! raeburn 3042: }
! 3043: $datatable .= '</td></tr>'."\n";
! 3044: if (ref($rowtotal)) {
1.231 raeburn 3045: $itemcount ++;
3046: }
3047: }
1.235 ! raeburn 3048: if ($caller eq 'requestcourses') {
! 3049: my %currhash;
! 3050: if (ref($settings->{'validation'}) eq 'HASH') {
! 3051: if ($settings->{'validation'}{'dc'} ne '') {
! 3052: $currhash{$settings->{'validation'}{'dc'}} = 1;
! 3053: }
! 3054: }
! 3055: my $numinrow = 2;
! 3056: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
! 3057: 'validationdc',%currhash);
! 3058: if ($numdc > 1) {
! 3059: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
! 3060: &mt('Course creation processed as: (choose Dom. Coord.)').
! 3061: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
! 3062: } else {
! 3063: $datatable .= $dctable.'</td></tr>';
! 3064: }
! 3065: $itemcount ++;
! 3066: }
! 3067: if (ref($rowtotal)) {
! 3068: $$rowtotal += $itemcount;
! 3069: }
1.231 raeburn 3070: return $datatable;
3071: }
3072:
1.137 raeburn 3073: sub print_usersessions {
3074: my ($position,$dom,$settings,$rowtotal) = @_;
3075: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3076: my (%by_ip,%by_location,@intdoms);
3077: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3078:
3079: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3080: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3081: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3082: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3083: my $itemcount = 1;
3084: if ($position eq 'top') {
1.152 raeburn 3085: if (keys(%serverhomes) > 1) {
1.145 raeburn 3086: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3087: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3088: } else {
1.140 raeburn 3089: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3090: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3091: }
1.137 raeburn 3092: } else {
1.145 raeburn 3093: if (keys(%by_location) == 0) {
3094: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3095: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3096: } else {
3097: my %lt = &usersession_titles();
3098: my $numinrow = 5;
3099: my $prefix;
3100: my @types;
3101: if ($position eq 'bottom') {
3102: $prefix = 'remote';
3103: @types = ('version','excludedomain','includedomain');
3104: } else {
3105: $prefix = 'hosted';
3106: @types = ('excludedomain','includedomain');
3107: }
3108: my (%current,%checkedon,%checkedoff);
3109: my @lcversions = &Apache::lonnet::all_loncaparevs();
3110: my @locations = sort(keys(%by_location));
3111: foreach my $type (@types) {
3112: $checkedon{$type} = '';
3113: $checkedoff{$type} = ' checked="checked"';
3114: }
3115: if (ref($settings) eq 'HASH') {
3116: if (ref($settings->{$prefix}) eq 'HASH') {
3117: foreach my $key (keys(%{$settings->{$prefix}})) {
3118: $current{$key} = $settings->{$prefix}{$key};
3119: if ($key eq 'version') {
3120: if ($current{$key} ne '') {
3121: $checkedon{$key} = ' checked="checked"';
3122: $checkedoff{$key} = '';
3123: }
3124: } elsif (ref($current{$key}) eq 'ARRAY') {
3125: $checkedon{$key} = ' checked="checked"';
3126: $checkedoff{$key} = '';
3127: }
1.137 raeburn 3128: }
3129: }
3130: }
1.145 raeburn 3131: foreach my $type (@types) {
3132: next if ($type ne 'version' && !@locations);
3133: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3134: $datatable .= '<tr'.$css_class.'>
3135: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3136: <span class="LC_nobreak">
3137: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3138: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3139: if ($type eq 'version') {
3140: my $selector = '<select name="'.$prefix.'_version">';
3141: foreach my $version (@lcversions) {
3142: my $selected = '';
3143: if ($current{'version'} eq $version) {
3144: $selected = ' selected="selected"';
3145: }
3146: $selector .= ' <option value="'.$version.'"'.
3147: $selected.'>'.$version.'</option>';
3148: }
3149: $selector .= '</select> ';
3150: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3151: } else {
3152: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3153: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3154: ' />'.(' 'x2).
3155: '<input type="button" value="'.&mt('uncheck all').'" '.
3156: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3157: "\n".
3158: '</div><div><table>';
3159: my $rem;
3160: for (my $i=0; $i<@locations; $i++) {
3161: my ($showloc,$value,$checkedtype);
3162: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3163: my $ip = $by_location{$locations[$i]}->[0];
3164: if (ref($by_ip{$ip}) eq 'ARRAY') {
3165: $value = join(':',@{$by_ip{$ip}});
3166: $showloc = join(', ',@{$by_ip{$ip}});
3167: if (ref($current{$type}) eq 'ARRAY') {
3168: foreach my $loc (@{$by_ip{$ip}}) {
3169: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3170: $checkedtype = ' checked="checked"';
3171: last;
3172: }
3173: }
1.138 raeburn 3174: }
3175: }
3176: }
1.145 raeburn 3177: $rem = $i%($numinrow);
3178: if ($rem == 0) {
3179: if ($i > 0) {
3180: $datatable .= '</tr>';
3181: }
3182: $datatable .= '<tr>';
3183: }
3184: $datatable .= '<td class="LC_left_item">'.
3185: '<span class="LC_nobreak"><label>'.
3186: '<input type="checkbox" name="'.$prefix.'_'.$type.
3187: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3188: '</label></span></td>';
1.137 raeburn 3189: }
1.145 raeburn 3190: $rem = @locations%($numinrow);
3191: my $colsleft = $numinrow - $rem;
3192: if ($colsleft > 1 ) {
3193: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3194: ' </td>';
3195: } elsif ($colsleft == 1) {
3196: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3197: }
1.145 raeburn 3198: $datatable .= '</tr></table>';
1.137 raeburn 3199: }
1.145 raeburn 3200: $datatable .= '</td></tr>';
3201: $itemcount ++;
1.137 raeburn 3202: }
3203: }
3204: }
3205: $$rowtotal += $itemcount;
3206: return $datatable;
3207: }
3208:
1.138 raeburn 3209: sub build_location_hashes {
3210: my ($intdoms,$by_ip,$by_location) = @_;
3211: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3212: (ref($by_location) eq 'HASH'));
3213: my %iphost = &Apache::lonnet::get_iphost();
3214: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3215: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3216: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3217: foreach my $id (@{$iphost{$primary_ip}}) {
3218: my $intdom = &Apache::lonnet::internet_dom($id);
3219: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3220: push(@{$intdoms},$intdom);
3221: }
3222: }
3223: }
3224: foreach my $ip (keys(%iphost)) {
3225: if (ref($iphost{$ip}) eq 'ARRAY') {
3226: foreach my $id (@{$iphost{$ip}}) {
3227: my $location = &Apache::lonnet::internet_dom($id);
3228: if ($location) {
3229: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3230: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3231: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3232: push(@{$by_ip->{$ip}},$location);
3233: }
3234: } else {
3235: $by_ip->{$ip} = [$location];
3236: }
3237: }
3238: }
3239: }
3240: }
3241: foreach my $ip (sort(keys(%{$by_ip}))) {
3242: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3243: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3244: my $first = $by_ip->{$ip}->[0];
3245: if (ref($by_location->{$first}) eq 'ARRAY') {
3246: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3247: push(@{$by_location->{$first}},$ip);
3248: }
3249: } else {
3250: $by_location->{$first} = [$ip];
3251: }
3252: }
3253: }
3254: return;
3255: }
3256:
1.145 raeburn 3257: sub current_offloads_to {
3258: my ($dom,$settings,$servers) = @_;
3259: my (%spareid,%otherdomconfigs);
1.152 raeburn 3260: if (ref($servers) eq 'HASH') {
1.145 raeburn 3261: foreach my $lonhost (sort(keys(%{$servers}))) {
3262: my $gotspares;
1.152 raeburn 3263: if (ref($settings) eq 'HASH') {
3264: if (ref($settings->{'spares'}) eq 'HASH') {
3265: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3266: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3267: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3268: $gotspares = 1;
3269: }
1.145 raeburn 3270: }
3271: }
3272: unless ($gotspares) {
3273: my $gotspares;
3274: my $serverhomeID =
3275: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3276: my $serverhomedom =
3277: &Apache::lonnet::host_domain($serverhomeID);
3278: if ($serverhomedom ne $dom) {
3279: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3280: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3281: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3282: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3283: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3284: $gotspares = 1;
3285: }
3286: }
3287: } else {
3288: $otherdomconfigs{$serverhomedom} =
3289: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3290: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3291: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3292: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3293: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3294: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3295: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3296: $gotspares = 1;
3297: }
3298: }
3299: }
3300: }
3301: }
3302: }
3303: }
3304: unless ($gotspares) {
3305: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3306: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3307: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3308: } else {
3309: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3310: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3311: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3312: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3313: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3314: } else {
1.150 raeburn 3315: my %what = (
3316: spareid => 1,
3317: );
3318: my ($result,$returnhash) =
3319: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3320: if ($result eq 'ok') {
3321: if (ref($returnhash) eq 'HASH') {
3322: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3323: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3324: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3325: }
3326: }
1.145 raeburn 3327: }
3328: }
3329: }
3330: }
3331: }
3332: }
3333: return %spareid;
3334: }
3335:
3336: sub spares_row {
1.152 raeburn 3337: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3338: my $css_class;
3339: my $numinrow = 4;
3340: my $itemcount = 1;
3341: my $datatable;
1.152 raeburn 3342: my %typetitles = &sparestype_titles();
3343: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3344: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3345: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3346: my ($othercontrol,$serverdom);
3347: if ($serverhome ne $server) {
3348: $serverdom = &Apache::lonnet::host_domain($serverhome);
3349: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3350: } else {
3351: $serverdom = &Apache::lonnet::host_domain($server);
3352: if ($serverdom ne $dom) {
3353: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3354: }
3355: }
3356: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3357: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3358: $datatable .= '<tr'.$css_class.'>
3359: <td rowspan="2">
1.183 bisitz 3360: <span class="LC_nobreak">'.
3361: &mt('[_1] when busy, offloads to:'
3362: ,'<b>'.$server.'</b>').
3363: "\n";
1.145 raeburn 3364: my (%current,%canselect);
1.152 raeburn 3365: my @choices =
3366: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3367: foreach my $type ('primary','default') {
3368: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3369: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3370: my @spares = @{$spareid->{$server}{$type}};
3371: if (@spares > 0) {
1.152 raeburn 3372: if ($othercontrol) {
3373: $current{$type} = join(', ',@spares);
3374: } else {
3375: $current{$type} .= '<table>';
3376: my $numspares = scalar(@spares);
3377: for (my $i=0; $i<@spares; $i++) {
3378: my $rem = $i%($numinrow);
3379: if ($rem == 0) {
3380: if ($i > 0) {
3381: $current{$type} .= '</tr>';
3382: }
3383: $current{$type} .= '<tr>';
1.145 raeburn 3384: }
1.152 raeburn 3385: $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'".');" /> '.
3386: $spareid->{$server}{$type}[$i].
3387: '</label></td>'."\n";
3388: }
3389: my $rem = @spares%($numinrow);
3390: my $colsleft = $numinrow - $rem;
3391: if ($colsleft > 1 ) {
3392: $current{$type} .= '<td colspan="'.$colsleft.
3393: '" class="LC_left_item">'.
3394: ' </td>';
3395: } elsif ($colsleft == 1) {
3396: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3397: }
1.152 raeburn 3398: $current{$type} .= '</tr></table>';
1.150 raeburn 3399: }
1.145 raeburn 3400: }
3401: }
3402: if ($current{$type} eq '') {
3403: $current{$type} = &mt('None specified');
3404: }
1.152 raeburn 3405: if ($othercontrol) {
3406: if ($type eq 'primary') {
3407: $canselect{$type} = $othercontrol;
3408: }
3409: } else {
3410: $canselect{$type} =
3411: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3412: '<select name="newspare_'.$type.'_'.$server.'" '.
3413: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3414: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3415: if (@choices > 0) {
3416: foreach my $lonhost (@choices) {
3417: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3418: }
3419: }
3420: $canselect{$type} .= '</select>'."\n";
3421: }
3422: } else {
3423: $current{$type} = &mt('Could not be determined');
3424: if ($type eq 'primary') {
3425: $canselect{$type} = $othercontrol;
3426: }
1.145 raeburn 3427: }
1.152 raeburn 3428: if ($type eq 'default') {
3429: $datatable .= '<tr'.$css_class.'>';
3430: }
3431: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3432: '<td>'.$current{$type}.'</td>'."\n".
3433: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3434: }
3435: $itemcount ++;
3436: }
3437: }
3438: $$rowtotal += $itemcount;
3439: return $datatable;
3440: }
3441:
1.152 raeburn 3442: sub possible_newspares {
3443: my ($server,$currspares,$serverhomes,$altids) = @_;
3444: my $serverhostname = &Apache::lonnet::hostname($server);
3445: my %excluded;
3446: if ($serverhostname ne '') {
3447: %excluded = (
3448: $serverhostname => 1,
3449: );
3450: }
3451: if (ref($currspares) eq 'HASH') {
3452: foreach my $type (keys(%{$currspares})) {
3453: if (ref($currspares->{$type}) eq 'ARRAY') {
3454: if (@{$currspares->{$type}} > 0) {
3455: foreach my $curr (@{$currspares->{$type}}) {
3456: my $hostname = &Apache::lonnet::hostname($curr);
3457: $excluded{$hostname} = 1;
3458: }
3459: }
3460: }
3461: }
3462: }
3463: my @choices;
3464: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3465: if (keys(%{$serverhomes}) > 1) {
3466: foreach my $name (sort(keys(%{$serverhomes}))) {
3467: unless ($excluded{$name}) {
3468: if (exists($altids->{$serverhomes->{$name}})) {
3469: push(@choices,$altids->{$serverhomes->{$name}});
3470: } else {
3471: push(@choices,$serverhomes->{$name});
1.145 raeburn 3472: }
3473: }
3474: }
3475: }
3476: }
1.152 raeburn 3477: return sort(@choices);
1.145 raeburn 3478: }
3479:
1.150 raeburn 3480: sub print_loadbalancing {
3481: my ($dom,$settings,$rowtotal) = @_;
3482: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3483: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3484: my $numinrow = 1;
3485: my $datatable;
3486: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3487: my (%currbalancer,%currtargets,%currrules,%existing);
3488: if (ref($settings) eq 'HASH') {
3489: %existing = %{$settings};
3490: }
3491: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3492: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3493: \%currtargets,\%currrules);
1.150 raeburn 3494: } else {
3495: return;
3496: }
3497: my ($othertitle,$usertypes,$types) =
3498: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3499: my $rownum = 8;
1.150 raeburn 3500: if (ref($types) eq 'ARRAY') {
3501: $rownum += scalar(@{$types});
3502: }
1.171 raeburn 3503: my @css_class = ('LC_odd_row','LC_even_row');
3504: my $balnum = 0;
3505: my $islast;
3506: my (@toshow,$disabledtext);
3507: if (keys(%currbalancer) > 0) {
3508: @toshow = sort(keys(%currbalancer));
3509: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3510: push(@toshow,'');
3511: }
3512: } else {
3513: @toshow = ('');
3514: $disabledtext = &mt('No existing load balancer');
3515: }
3516: foreach my $lonhost (@toshow) {
3517: if ($balnum == scalar(@toshow)-1) {
3518: $islast = 1;
3519: } else {
3520: $islast = 0;
3521: }
3522: my $cssidx = $balnum%2;
3523: my $targets_div_style = 'display: none';
3524: my $disabled_div_style = 'display: block';
3525: my $homedom_div_style = 'display: none';
3526: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3527: '<td rowspan="'.$rownum.'" valign="top">'.
3528: '<p>';
3529: if ($lonhost eq '') {
1.210 raeburn 3530: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3531: if (keys(%currbalancer) > 0) {
3532: $datatable .= &mt('Add balancer:');
3533: } else {
3534: $datatable .= &mt('Enable balancer:');
3535: }
3536: $datatable .= ' '.
3537: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3538: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3539: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3540: '<option value="" selected="selected">'.&mt('None').
3541: '</option>'."\n";
3542: foreach my $server (sort(keys(%servers))) {
3543: next if ($currbalancer{$server});
3544: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3545: }
1.210 raeburn 3546: $datatable .=
1.171 raeburn 3547: '</select>'."\n".
3548: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3549: } else {
3550: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3551: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3552: &mt('Stop balancing').'</label>'.
3553: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3554: $targets_div_style = 'display: block';
3555: $disabled_div_style = 'display: none';
3556: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3557: $homedom_div_style = 'display: block';
3558: }
3559: }
3560: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3561: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3562: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3563: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3564: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3565: my @sparestypes = ('primary','default');
3566: my %typetitles = &sparestype_titles();
3567: foreach my $sparetype (@sparestypes) {
3568: my $targettable;
3569: for (my $i=0; $i<$numspares; $i++) {
3570: my $checked;
3571: if (ref($currtargets{$lonhost}) eq 'HASH') {
3572: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3573: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3574: $checked = ' checked="checked"';
3575: }
3576: }
3577: }
3578: my ($chkboxval,$disabled);
3579: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3580: $chkboxval = $spares[$i];
3581: }
3582: if (exists($currbalancer{$spares[$i]})) {
3583: $disabled = ' disabled="disabled"';
3584: }
1.210 raeburn 3585: $targettable .=
1.171 raeburn 3586: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3587: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3588: '</span></label></td>';
3589: my $rem = $i%($numinrow);
3590: if ($rem == 0) {
3591: if (($i > 0) && ($i < $numspares-1)) {
3592: $targettable .= '</tr>';
3593: }
3594: if ($i < $numspares-1) {
3595: $targettable .= '<tr>';
1.150 raeburn 3596: }
3597: }
3598: }
1.171 raeburn 3599: if ($targettable ne '') {
3600: my $rem = $numspares%($numinrow);
3601: my $colsleft = $numinrow - $rem;
3602: if ($colsleft > 1 ) {
3603: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3604: ' </td>';
3605: } elsif ($colsleft == 1) {
3606: $targettable .= '<td class="LC_left_item"> </td>';
3607: }
3608: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3609: '<table><tr>'.$targettable.'</tr></table><br />';
3610: }
3611: }
3612: $datatable .= '</div></td></tr>'.
3613: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3614: $othertitle,$usertypes,$types,\%servers,
3615: \%currbalancer,$lonhost,
3616: $targets_div_style,$homedom_div_style,
3617: $css_class[$cssidx],$balnum,$islast);
3618: $$rowtotal += $rownum;
3619: $balnum ++;
3620: }
3621: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3622: return $datatable;
3623: }
3624:
3625: sub get_loadbalancers_config {
3626: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3627: return unless ((ref($servers) eq 'HASH') &&
3628: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3629: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3630: if (keys(%{$existing}) > 0) {
3631: my $oldlonhost;
3632: foreach my $key (sort(keys(%{$existing}))) {
3633: if ($key eq 'lonhost') {
3634: $oldlonhost = $existing->{'lonhost'};
3635: $currbalancer->{$oldlonhost} = 1;
3636: } elsif ($key eq 'targets') {
3637: if ($oldlonhost) {
3638: $currtargets->{$oldlonhost} = $existing->{'targets'};
3639: }
3640: } elsif ($key eq 'rules') {
3641: if ($oldlonhost) {
3642: $currrules->{$oldlonhost} = $existing->{'rules'};
3643: }
3644: } elsif (ref($existing->{$key}) eq 'HASH') {
3645: $currbalancer->{$key} = 1;
3646: $currtargets->{$key} = $existing->{$key}{'targets'};
3647: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3648: }
3649: }
1.171 raeburn 3650: } else {
3651: my ($balancerref,$targetsref) =
3652: &Apache::lonnet::get_lonbalancer_config($servers);
3653: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3654: foreach my $server (sort(keys(%{$balancerref}))) {
3655: $currbalancer->{$server} = 1;
3656: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3657: }
3658: }
3659: }
1.171 raeburn 3660: return;
1.150 raeburn 3661: }
3662:
3663: sub loadbalancing_rules {
3664: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3665: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3666: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3667: my $output;
1.171 raeburn 3668: my $num = 0;
1.210 raeburn 3669: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3670: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3671: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3672: foreach my $type (@{$alltypes}) {
1.171 raeburn 3673: $num ++;
1.150 raeburn 3674: my $current;
3675: if (ref($currrules) eq 'HASH') {
3676: $current = $currrules->{$type};
3677: }
1.209 raeburn 3678: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3679: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3680: $current = '';
3681: }
3682: }
3683: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3684: $servers,$currbalancer,$lonhost,$dom,
3685: $targets_div_style,$homedom_div_style,
3686: $css_class,$balnum,$num,$islast);
1.150 raeburn 3687: }
3688: }
3689: return $output;
3690: }
3691:
3692: sub loadbalancing_titles {
3693: my ($dom,$intdom,$usertypes,$types) = @_;
3694: my %othertypes = (
3695: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3696: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3697: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3698: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3699: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3700: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3701: );
1.209 raeburn 3702: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3703: if (ref($types) eq 'ARRAY') {
3704: unshift(@alltypes,@{$types},'default');
3705: }
3706: my %titles;
3707: foreach my $type (@alltypes) {
3708: if ($type =~ /^_LC_/) {
3709: $titles{$type} = $othertypes{$type};
3710: } elsif ($type eq 'default') {
3711: $titles{$type} = &mt('All users from [_1]',$dom);
3712: if (ref($types) eq 'ARRAY') {
3713: if (@{$types} > 0) {
3714: $titles{$type} = &mt('Other users from [_1]',$dom);
3715: }
3716: }
3717: } elsif (ref($usertypes) eq 'HASH') {
3718: $titles{$type} = $usertypes->{$type};
3719: }
3720: }
3721: return (\@alltypes,\%othertypes,\%titles);
3722: }
3723:
3724: sub loadbalance_rule_row {
1.171 raeburn 3725: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3726: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3727: my @rulenames;
1.150 raeburn 3728: my %ruletitles = &offloadtype_text();
1.209 raeburn 3729: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3730: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3731: } else {
1.209 raeburn 3732: @rulenames = ('default','homeserver');
3733: if ($type eq '_LC_external') {
3734: push(@rulenames,'externalbalancer');
3735: } else {
3736: push(@rulenames,'specific');
3737: }
3738: push(@rulenames,'none');
1.150 raeburn 3739: }
3740: my $style = $targets_div_style;
1.209 raeburn 3741: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3742: $style = $homedom_div_style;
3743: }
1.171 raeburn 3744: my $space;
3745: if ($islast && $num == 1) {
3746: $space = '<div display="inline-block"> </div>';
3747: }
1.210 raeburn 3748: my $output =
1.171 raeburn 3749: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3750: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3751: '<td valaign="top">'.$space.
3752: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3753: for (my $i=0; $i<@rulenames; $i++) {
3754: my $rule = $rulenames[$i];
3755: my ($checked,$extra);
3756: if ($rulenames[$i] eq 'default') {
3757: $rule = '';
3758: }
3759: if ($rulenames[$i] eq 'specific') {
3760: if (ref($servers) eq 'HASH') {
3761: my $default;
3762: if (($current ne '') && (exists($servers->{$current}))) {
3763: $checked = ' checked="checked"';
3764: }
3765: unless ($checked) {
3766: $default = ' selected="selected"';
3767: }
1.210 raeburn 3768: $extra =
1.171 raeburn 3769: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3770: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3771: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3772: '<option value=""'.$default.'></option>'."\n";
3773: foreach my $server (sort(keys(%{$servers}))) {
3774: if (ref($currbalancer) eq 'HASH') {
3775: next if (exists($currbalancer->{$server}));
3776: }
1.150 raeburn 3777: my $selected;
1.171 raeburn 3778: if ($server eq $current) {
1.150 raeburn 3779: $selected = ' selected="selected"';
3780: }
1.171 raeburn 3781: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3782: }
3783: $extra .= '</select>';
3784: }
3785: } elsif ($rule eq $current) {
3786: $checked = ' checked="checked"';
3787: }
3788: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3789: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3790: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3791: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3792: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3793: '</label>'.$extra.'</span><br />'."\n";
3794: }
3795: $output .= '</div></td></tr>'."\n";
3796: return $output;
3797: }
3798:
3799: sub offloadtype_text {
3800: my %ruletitles = &Apache::lonlocal::texthash (
3801: 'default' => 'Offloads to default destinations',
3802: 'homeserver' => "Offloads to user's home server",
3803: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3804: 'specific' => 'Offloads to specific server',
1.161 raeburn 3805: 'none' => 'No offload',
1.209 raeburn 3806: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3807: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3808: );
3809: return %ruletitles;
3810: }
3811:
3812: sub sparestype_titles {
3813: my %typestitles = &Apache::lonlocal::texthash (
3814: 'primary' => 'primary',
3815: 'default' => 'default',
3816: );
3817: return %typestitles;
3818: }
3819:
1.28 raeburn 3820: sub contact_titles {
3821: my %titles = &Apache::lonlocal::texthash (
3822: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3823: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3824: 'errormail' => 'Error reports to be e-mailed to',
3825: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3826: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3827: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3828: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3829: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3830: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3831: );
3832: my %short_titles = &Apache::lonlocal::texthash (
3833: adminemail => 'Admin E-mail address',
3834: supportemail => 'Support E-mail',
3835: );
3836: return (\%titles,\%short_titles);
3837: }
3838:
1.72 raeburn 3839: sub tool_titles {
3840: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3841: aboutme => 'Personal web page',
1.86 raeburn 3842: blog => 'Blog',
1.162 raeburn 3843: webdav => 'WebDAV',
1.86 raeburn 3844: portfolio => 'Portfolio',
1.88 bisitz 3845: official => 'Official courses (with institutional codes)',
3846: unofficial => 'Unofficial courses',
1.98 raeburn 3847: community => 'Communities',
1.216 raeburn 3848: textbook => 'Textbook courses',
1.86 raeburn 3849: );
1.72 raeburn 3850: return %titles;
3851: }
3852:
1.101 raeburn 3853: sub courserequest_titles {
3854: my %titles = &Apache::lonlocal::texthash (
3855: official => 'Official',
3856: unofficial => 'Unofficial',
3857: community => 'Communities',
1.216 raeburn 3858: textbook => 'Textbook',
1.101 raeburn 3859: norequest => 'Not allowed',
1.104 raeburn 3860: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3861: validate => 'With validation',
3862: autolimit => 'Numerical limit',
1.103 raeburn 3863: unlimited => '(blank for unlimited)',
1.101 raeburn 3864: );
3865: return %titles;
3866: }
3867:
1.163 raeburn 3868: sub authorrequest_titles {
3869: my %titles = &Apache::lonlocal::texthash (
3870: norequest => 'Not allowed',
3871: approval => 'Approval by Dom. Coord.',
3872: automatic => 'Automatic approval',
3873: );
3874: return %titles;
1.210 raeburn 3875: }
1.163 raeburn 3876:
1.101 raeburn 3877: sub courserequest_conditions {
3878: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3879: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3880: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3881: );
3882: return %conditions;
3883: }
3884:
3885:
1.27 raeburn 3886: sub print_usercreation {
1.30 raeburn 3887: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3888: my $numinrow = 4;
1.28 raeburn 3889: my $datatable;
3890: if ($position eq 'top') {
1.30 raeburn 3891: $$rowtotal ++;
1.34 raeburn 3892: my $rowcount = 0;
1.32 raeburn 3893: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3894: if (ref($rules) eq 'HASH') {
3895: if (keys(%{$rules}) > 0) {
1.32 raeburn 3896: $datatable .= &user_formats_row('username',$settings,$rules,
3897: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3898: $$rowtotal ++;
1.32 raeburn 3899: $rowcount ++;
3900: }
3901: }
3902: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3903: if (ref($idrules) eq 'HASH') {
3904: if (keys(%{$idrules}) > 0) {
3905: $datatable .= &user_formats_row('id',$settings,$idrules,
3906: $idruleorder,$numinrow,$rowcount);
3907: $$rowtotal ++;
3908: $rowcount ++;
1.28 raeburn 3909: }
3910: }
1.39 raeburn 3911: if ($rowcount == 0) {
3912: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3913: $$rowtotal ++;
3914: $rowcount ++;
3915: }
1.34 raeburn 3916: } elsif ($position eq 'middle') {
1.224 raeburn 3917: my @creators = ('author','course','requestcrs');
1.37 raeburn 3918: my ($rules,$ruleorder) =
3919: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3920: my %lt = &usercreation_types();
3921: my %checked;
3922: if (ref($settings) eq 'HASH') {
3923: if (ref($settings->{'cancreate'}) eq 'HASH') {
3924: foreach my $item (@creators) {
3925: $checked{$item} = $settings->{'cancreate'}{$item};
3926: }
3927: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3928: foreach my $item (@creators) {
3929: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3930: $checked{$item} = 'none';
3931: }
3932: }
3933: }
3934: }
3935: my $rownum = 0;
3936: foreach my $item (@creators) {
3937: $rownum ++;
1.224 raeburn 3938: if ($checked{$item} eq '') {
3939: $checked{$item} = 'any';
1.34 raeburn 3940: }
3941: my $css_class;
3942: if ($rownum%2) {
3943: $css_class = '';
3944: } else {
3945: $css_class = ' class="LC_odd_row" ';
3946: }
3947: $datatable .= '<tr'.$css_class.'>'.
3948: '<td><span class="LC_nobreak">'.$lt{$item}.
3949: '</span></td><td align="right">';
1.224 raeburn 3950: my @options = ('any');
3951: if (ref($rules) eq 'HASH') {
3952: if (keys(%{$rules}) > 0) {
3953: push(@options,('official','unofficial'));
1.37 raeburn 3954: }
3955: }
1.224 raeburn 3956: push(@options,'none');
1.37 raeburn 3957: foreach my $option (@options) {
1.50 raeburn 3958: my $type = 'radio';
1.34 raeburn 3959: my $check = ' ';
1.224 raeburn 3960: if ($checked{$item} eq $option) {
3961: $check = ' checked="checked" ';
1.34 raeburn 3962: }
3963: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3964: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3965: $item.'" value="'.$option.'"'.$check.'/> '.
3966: $lt{$option}.'</label> </span>';
3967: }
3968: $datatable .= '</td></tr>';
3969: }
1.28 raeburn 3970: } else {
3971: my @contexts = ('author','course','domain');
3972: my @authtypes = ('int','krb4','krb5','loc');
3973: my %checked;
3974: if (ref($settings) eq 'HASH') {
3975: if (ref($settings->{'authtypes'}) eq 'HASH') {
3976: foreach my $item (@contexts) {
3977: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3978: foreach my $auth (@authtypes) {
3979: if ($settings->{'authtypes'}{$item}{$auth}) {
3980: $checked{$item}{$auth} = ' checked="checked" ';
3981: }
3982: }
3983: }
3984: }
1.27 raeburn 3985: }
1.35 raeburn 3986: } else {
3987: foreach my $item (@contexts) {
1.36 raeburn 3988: foreach my $auth (@authtypes) {
1.35 raeburn 3989: $checked{$item}{$auth} = ' checked="checked" ';
3990: }
3991: }
1.27 raeburn 3992: }
1.28 raeburn 3993: my %title = &context_names();
3994: my %authname = &authtype_names();
3995: my $rownum = 0;
3996: my $css_class;
3997: foreach my $item (@contexts) {
3998: if ($rownum%2) {
3999: $css_class = '';
4000: } else {
4001: $css_class = ' class="LC_odd_row" ';
4002: }
1.30 raeburn 4003: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4004: '<td>'.$title{$item}.
4005: '</td><td class="LC_left_item">'.
4006: '<span class="LC_nobreak">';
4007: foreach my $auth (@authtypes) {
4008: $datatable .= '<label>'.
4009: '<input type="checkbox" name="'.$item.'_auth" '.
4010: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4011: $authname{$auth}.'</label> ';
4012: }
4013: $datatable .= '</span></td></tr>';
4014: $rownum ++;
1.27 raeburn 4015: }
1.30 raeburn 4016: $$rowtotal += $rownum;
1.27 raeburn 4017: }
4018: return $datatable;
4019: }
4020:
1.224 raeburn 4021: sub print_selfcreation {
4022: my ($position,$dom,$settings,$rowtotal) = @_;
4023: my (@selfcreate,$createsettings,$datatable);
4024: if (ref($settings) eq 'HASH') {
4025: if (ref($settings->{'cancreate'}) eq 'HASH') {
4026: $createsettings = $settings->{'cancreate'};
4027: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
4028: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
4029: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
4030: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4031: @selfcreate = ('email','login','sso');
4032: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
4033: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
4034: }
4035: }
4036: }
4037: }
4038: my %radiohash;
4039: my $numinrow = 4;
4040: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4041: if ($position eq 'top') {
4042: my %choices = &Apache::lonlocal::texthash (
4043: cancreate_login => 'Institutional Login',
4044: cancreate_sso => 'Institutional Single Sign On',
4045: );
4046: my @toggles = sort(keys(%choices));
4047: my %defaultchecked = (
4048: 'cancreate_login' => 'off',
4049: 'cancreate_sso' => 'off',
4050: );
1.228 raeburn 4051: my ($onclick,$itemcount);
1.224 raeburn 4052: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4053: \%choices,$itemcount,$onclick);
1.228 raeburn 4054: $$rowtotal += $itemcount;
4055:
1.224 raeburn 4056: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4057:
4058: if (ref($usertypes) eq 'HASH') {
4059: if (keys(%{$usertypes}) > 0) {
4060: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4061: $dom,$numinrow,$othertitle,
1.228 raeburn 4062: 'statustocreate',$$rowtotal);
1.224 raeburn 4063: $$rowtotal ++;
4064: }
4065: }
4066: } elsif ($position eq 'middle') {
4067: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4068: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4069: $usertypes->{'default'} = $othertitle;
4070: if (ref($types) eq 'ARRAY') {
4071: push(@{$types},'default');
4072: $usertypes->{'default'} = $othertitle;
4073: foreach my $status (@{$types}) {
4074: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4075: $numinrow,$$rowtotal,$usertypes);
1.224 raeburn 4076: $$rowtotal ++;
4077: }
4078: }
4079: } else {
1.228 raeburn 4080: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
1.224 raeburn 4081: my %choices =
4082: &Apache::lonlocal::texthash(
4083: email => 'Approved automatically',
4084: emailapproval => 'Queued for approval by DC',
4085: off => 'Not enabled',
4086: );
4087: $datatable .= '<tr'.$css_class.'>'.
4088: '<td>'.&mt('E-mail address as username').
4089: '</td><td class="LC_left_item">'.
4090: '<span class="LC_nobreak">';
4091: foreach my $option ('email','emailapproval','off') {
4092: my $checked;
4093: if ($option eq 'email') {
4094: if ($radiohash{'cancreate_email'}) {
4095: $checked = 'checked="checked"';
4096: }
4097: } elsif ($option eq 'emailapproval') {
4098: if ($radiohash{'cancreate_emailapproval'}) {
4099: $checked = 'checked="checked"';
4100: }
4101: } else {
4102: if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
4103: $checked = 'checked="checked"';
4104: }
4105: }
4106: $datatable .= '<label>'.
4107: '<input type="radio" name="cancreate_email" '.
4108: $checked.' value="'.$option.'" />'.
4109: $choices{$option}.'</label> ';
4110: }
4111: $$rowtotal ++;
4112: $datatable .= '</span></td></tr>'.
4113: &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4114: $$rowtotal ++;
1.224 raeburn 4115: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4116: $numinrow = 1;
4117: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4118: $usertypes->{'default'} = $othertitle;
4119: if (ref($types) eq 'ARRAY') {
4120: push(@{$types},'default');
4121: $usertypes->{'default'} = $othertitle;
4122: foreach my $status (@{$types}) {
4123: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4124: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4125: $$rowtotal ++;
4126: }
4127: }
1.224 raeburn 4128: my ($emailrules,$emailruleorder) =
4129: &Apache::lonnet::inst_userrules($dom,'email');
4130: if (ref($emailrules) eq 'HASH') {
4131: if (keys(%{$emailrules}) > 0) {
4132: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4133: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4134: $$rowtotal ++;
4135: }
4136: }
1.228 raeburn 4137: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4138: }
4139: return $datatable;
4140: }
4141:
1.165 raeburn 4142: sub captcha_choice {
1.169 raeburn 4143: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4144: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4145: my %lt = &captcha_phrases();
4146: $keyentry = 'hidden';
4147: if ($context eq 'cancreate') {
1.224 raeburn 4148: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4149: } elsif ($context eq 'login') {
4150: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4151: }
4152: if (ref($settings) eq 'HASH') {
4153: if ($settings->{'captcha'}) {
4154: $checked{$settings->{'captcha'}} = ' checked="checked"';
4155: } else {
4156: $checked{'original'} = ' checked="checked"';
4157: }
4158: if ($settings->{'captcha'} eq 'recaptcha') {
4159: $pubtext = $lt{'pub'};
4160: $privtext = $lt{'priv'};
4161: $keyentry = 'text';
4162: }
4163: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4164: $currpub = $settings->{'recaptchakeys'}{'public'};
4165: $currpriv = $settings->{'recaptchakeys'}{'private'};
4166: }
4167: } else {
4168: $checked{'original'} = ' checked="checked"';
4169: }
1.169 raeburn 4170: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4171: my $output = '<tr'.$css_class.'>'.
4172: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4173: '<table><tr><td>'."\n";
4174: foreach my $option ('original','recaptcha','notused') {
4175: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4176: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4177: $lt{$option}.'</label></span>';
4178: unless ($option eq 'notused') {
4179: $output .= (' 'x2)."\n";
4180: }
4181: }
4182: #
4183: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4184: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4185: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4186: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4187: #
1.165 raeburn 4188: $output .= '</td></tr>'."\n".
4189: '<tr><td>'."\n".
4190: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4191: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4192: $currpub.'" size="40" /></span><br />'."\n".
4193: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4194: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4195: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4196: '</td></tr>';
4197: return $output;
4198: }
4199:
1.32 raeburn 4200: sub user_formats_row {
4201: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4202: my $output;
4203: my %text = (
4204: 'username' => 'new usernames',
4205: 'id' => 'IDs',
1.45 raeburn 4206: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4207: );
4208: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4209: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4210: '<td><span class="LC_nobreak">';
4211: if ($type eq 'email') {
4212: $output .= &mt("Formats disallowed for $text{$type}: ");
4213: } else {
4214: $output .= &mt("Format rules to check for $text{$type}: ");
4215: }
4216: $output .= '</span></td>'.
4217: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4218: my $rem;
4219: if (ref($ruleorder) eq 'ARRAY') {
4220: for (my $i=0; $i<@{$ruleorder}; $i++) {
4221: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4222: my $rem = $i%($numinrow);
4223: if ($rem == 0) {
4224: if ($i > 0) {
4225: $output .= '</tr>';
4226: }
4227: $output .= '<tr>';
4228: }
4229: my $check = ' ';
1.39 raeburn 4230: if (ref($settings) eq 'HASH') {
4231: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4232: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4233: $check = ' checked="checked" ';
4234: }
1.27 raeburn 4235: }
4236: }
4237: $output .= '<td class="LC_left_item">'.
4238: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4239: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4240: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4241: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4242: }
4243: }
4244: $rem = @{$ruleorder}%($numinrow);
4245: }
4246: my $colsleft = $numinrow - $rem;
4247: if ($colsleft > 1 ) {
4248: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4249: ' </td>';
4250: } elsif ($colsleft == 1) {
4251: $output .= '<td class="LC_left_item"> </td>';
4252: }
4253: $output .= '</tr></table></td></tr>';
4254: return $output;
4255: }
4256:
1.34 raeburn 4257: sub usercreation_types {
4258: my %lt = &Apache::lonlocal::texthash (
4259: author => 'When adding a co-author',
4260: course => 'When adding a user to a course',
1.100 raeburn 4261: requestcrs => 'When requesting a course',
1.34 raeburn 4262: any => 'Any',
4263: official => 'Institutional only ',
4264: unofficial => 'Non-institutional only',
4265: none => 'None',
4266: );
4267: return %lt;
1.48 raeburn 4268: }
1.34 raeburn 4269:
1.224 raeburn 4270: sub selfcreation_types {
4271: my %lt = &Apache::lonlocal::texthash (
4272: selfcreate => 'User creates own account',
4273: any => 'Any',
4274: official => 'Institutional only ',
4275: unofficial => 'Non-institutional only',
4276: email => 'E-mail address',
4277: login => 'Institutional Login',
4278: sso => 'SSO',
4279: );
4280: }
4281:
1.28 raeburn 4282: sub authtype_names {
4283: my %lt = &Apache::lonlocal::texthash(
4284: int => 'Internal',
4285: krb4 => 'Kerberos 4',
4286: krb5 => 'Kerberos 5',
4287: loc => 'Local',
4288: );
4289: return %lt;
4290: }
4291:
4292: sub context_names {
4293: my %context_title = &Apache::lonlocal::texthash(
4294: author => 'Creating users when an Author',
4295: course => 'Creating users when in a course',
4296: domain => 'Creating users when a Domain Coordinator',
4297: );
4298: return %context_title;
4299: }
4300:
1.33 raeburn 4301: sub print_usermodification {
4302: my ($position,$dom,$settings,$rowtotal) = @_;
4303: my $numinrow = 4;
4304: my ($context,$datatable,$rowcount);
4305: if ($position eq 'top') {
4306: $rowcount = 0;
4307: $context = 'author';
4308: foreach my $role ('ca','aa') {
4309: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4310: $numinrow,$rowcount);
4311: $$rowtotal ++;
4312: $rowcount ++;
4313: }
1.230 raeburn 4314: } elsif ($position eq 'bottom') {
1.33 raeburn 4315: $context = 'course';
4316: $rowcount = 0;
4317: foreach my $role ('st','ep','ta','in','cr') {
4318: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4319: $numinrow,$rowcount);
4320: $$rowtotal ++;
4321: $rowcount ++;
4322: }
4323: }
4324: return $datatable;
4325: }
4326:
1.43 raeburn 4327: sub print_defaults {
1.212 raeburn 4328: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 4329: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 4330: 'datelocale_def','portal_def');
1.212 raeburn 4331: my %defaults;
4332: if (ref($settings) eq 'HASH') {
1.213 raeburn 4333: %defaults = %{$settings};
1.212 raeburn 4334: } else {
4335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4336: foreach my $item (@items) {
4337: $defaults{$item} = $domdefaults{$item};
4338: }
4339: }
1.141 raeburn 4340: my $titles = &defaults_titles($dom);
1.43 raeburn 4341: my $rownum = 0;
4342: my ($datatable,$css_class);
4343: foreach my $item (@items) {
4344: if ($rownum%2) {
4345: $css_class = '';
4346: } else {
4347: $css_class = ' class="LC_odd_row" ';
4348: }
4349: $datatable .= '<tr'.$css_class.'>'.
4350: '<td><span class="LC_nobreak">'.$titles->{$item}.
4351: '</span></td><td class="LC_right_item">';
4352: if ($item eq 'auth_def') {
4353: my @authtypes = ('internal','krb4','krb5','localauth');
4354: my %shortauth = (
4355: internal => 'int',
4356: krb4 => 'krb4',
4357: krb5 => 'krb5',
4358: localauth => 'loc'
4359: );
4360: my %authnames = &authtype_names();
4361: foreach my $auth (@authtypes) {
4362: my $checked = ' ';
1.212 raeburn 4363: if ($defaults{$item} eq $auth) {
1.43 raeburn 4364: $checked = ' checked="checked" ';
4365: }
4366: $datatable .= '<label><input type="radio" name="'.$item.
4367: '" value="'.$auth.'"'.$checked.'/>'.
4368: $authnames{$shortauth{$auth}}.'</label> ';
4369: }
1.54 raeburn 4370: } elsif ($item eq 'timezone_def') {
4371: my $includeempty = 1;
1.212 raeburn 4372: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 4373: } elsif ($item eq 'datelocale_def') {
4374: my $includeempty = 1;
1.212 raeburn 4375: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 4376: } elsif ($item eq 'lang_def') {
1.168 raeburn 4377: my %langchoices = &get_languages_hash();
4378: $langchoices{''} = 'No language preference';
1.167 raeburn 4379: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 raeburn 4380: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 4381: \%langchoices);
1.43 raeburn 4382: } else {
1.141 raeburn 4383: my $size;
4384: if ($item eq 'portal_def') {
4385: $size = ' size="25"';
4386: }
1.43 raeburn 4387: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 raeburn 4388: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4389: }
4390: $datatable .= '</td></tr>';
4391: $rownum ++;
4392: }
4393: $$rowtotal += $rownum;
4394: return $datatable;
4395: }
4396:
1.168 raeburn 4397: sub get_languages_hash {
4398: my %langchoices;
4399: foreach my $id (&Apache::loncommon::languageids()) {
4400: my $code = &Apache::loncommon::supportedlanguagecode($id);
4401: if ($code ne '') {
4402: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4403: }
4404: }
4405: return %langchoices;
4406: }
4407:
1.43 raeburn 4408: sub defaults_titles {
1.141 raeburn 4409: my ($dom) = @_;
1.43 raeburn 4410: my %titles = &Apache::lonlocal::texthash (
4411: 'auth_def' => 'Default authentication type',
4412: 'auth_arg_def' => 'Default authentication argument',
4413: 'lang_def' => 'Default language',
1.54 raeburn 4414: 'timezone_def' => 'Default timezone',
1.68 raeburn 4415: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4416: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4417: );
1.141 raeburn 4418: if ($dom) {
4419: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4420: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4421: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4422: $protocol = 'http' if ($protocol ne 'https');
4423: if ($uint_dom) {
4424: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4425: $uint_dom);
4426: }
4427: }
1.43 raeburn 4428: return (\%titles);
4429: }
4430:
1.46 raeburn 4431: sub print_scantronformat {
4432: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4433: my $itemcount = 1;
1.60 raeburn 4434: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4435: %confhash);
1.46 raeburn 4436: my $switchserver = &check_switchserver($dom,$confname);
4437: my %lt = &Apache::lonlocal::texthash (
1.95 www 4438: default => 'Default bubblesheet format file error',
4439: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4440: );
4441: my %scantronfiles = (
4442: default => 'default.tab',
4443: custom => 'custom.tab',
4444: );
4445: foreach my $key (keys(%scantronfiles)) {
4446: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4447: .$scantronfiles{$key};
4448: }
4449: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4450: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4451: if (!$switchserver) {
4452: my $servadm = $r->dir_config('lonAdmEMail');
4453: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4454: if ($configuserok eq 'ok') {
4455: if ($author_ok eq 'ok') {
4456: my %legacyfile = (
4457: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4458: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4459: );
4460: my %md5chk;
4461: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4462: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4463: chomp($md5chk{$type});
1.46 raeburn 4464: }
4465: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4466: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4467: ($scantronurls{$type},my $error) =
1.46 raeburn 4468: &legacy_scantronformat($r,$dom,$confname,
4469: $type,$legacyfile{$type},
4470: $scantronurls{$type},
4471: $scantronfiles{$type});
1.60 raeburn 4472: if ($error ne '') {
4473: $error{$type} = $error;
4474: }
4475: }
4476: if (keys(%error) == 0) {
4477: $is_custom = 1;
4478: $confhash{'scantron'}{'scantronformat'} =
4479: $scantronurls{'custom'};
4480: my $putresult =
4481: &Apache::lonnet::put_dom('configuration',
4482: \%confhash,$dom);
4483: if ($putresult ne 'ok') {
4484: $error{'custom'} =
4485: '<span class="LC_error">'.
4486: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4487: }
1.46 raeburn 4488: }
4489: } else {
1.60 raeburn 4490: ($scantronurls{'default'},my $error) =
1.46 raeburn 4491: &legacy_scantronformat($r,$dom,$confname,
4492: 'default',$legacyfile{'default'},
4493: $scantronurls{'default'},
4494: $scantronfiles{'default'});
1.60 raeburn 4495: if ($error eq '') {
4496: $confhash{'scantron'}{'scantronformat'} = '';
4497: my $putresult =
4498: &Apache::lonnet::put_dom('configuration',
4499: \%confhash,$dom);
4500: if ($putresult ne 'ok') {
4501: $error{'default'} =
4502: '<span class="LC_error">'.
4503: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4504: }
4505: } else {
4506: $error{'default'} = $error;
4507: }
1.46 raeburn 4508: }
4509: }
4510: }
4511: } else {
1.95 www 4512: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4513: }
4514: }
4515: if (ref($settings) eq 'HASH') {
4516: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4517: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4518: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4519: $scantronurl = '';
4520: } else {
4521: $scantronurl = $settings->{'scantronformat'};
4522: }
4523: $is_custom = 1;
4524: } else {
4525: $scantronurl = $scantronurls{'default'};
4526: }
4527: } else {
1.60 raeburn 4528: if ($is_custom) {
4529: $scantronurl = $scantronurls{'custom'};
4530: } else {
4531: $scantronurl = $scantronurls{'default'};
4532: }
1.46 raeburn 4533: }
4534: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4535: $datatable .= '<tr'.$css_class.'>';
4536: if (!$is_custom) {
1.65 raeburn 4537: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4538: '<span class="LC_nobreak">';
1.46 raeburn 4539: if ($scantronurl) {
1.199 raeburn 4540: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4541: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4542: } else {
4543: $datatable = &mt('File unavailable for display');
4544: }
1.65 raeburn 4545: $datatable .= '</span></td>';
1.60 raeburn 4546: if (keys(%error) == 0) {
4547: $datatable .= '<td valign="bottom">';
4548: if (!$switchserver) {
4549: $datatable .= &mt('Upload:').'<br />';
4550: }
4551: } else {
4552: my $errorstr;
4553: foreach my $key (sort(keys(%error))) {
4554: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4555: }
4556: $datatable .= '<td>'.$errorstr;
4557: }
1.46 raeburn 4558: } else {
4559: if (keys(%error) > 0) {
4560: my $errorstr;
4561: foreach my $key (sort(keys(%error))) {
4562: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4563: }
1.60 raeburn 4564: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4565: } elsif ($scantronurl) {
1.199 raeburn 4566: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4567: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4568: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4569: $link.
4570: '<label><input type="checkbox" name="scantronformat_del"'.
4571: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4572: '<td><span class="LC_nobreak"> '.
4573: &mt('Replace:').'</span><br />';
1.46 raeburn 4574: }
4575: }
4576: if (keys(%error) == 0) {
4577: if ($switchserver) {
4578: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4579: } else {
1.65 raeburn 4580: $datatable .='<span class="LC_nobreak"> '.
4581: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4582: }
4583: }
4584: $datatable .= '</td></tr>';
4585: $$rowtotal ++;
4586: return $datatable;
4587: }
4588:
4589: sub legacy_scantronformat {
4590: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4591: my ($url,$error);
4592: my @statinfo = &Apache::lonnet::stat_file($newurl);
4593: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4594: (my $result,$url) =
4595: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4596: '','',$newfile);
4597: if ($result ne 'ok') {
1.130 raeburn 4598: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4599: }
4600: }
4601: return ($url,$error);
4602: }
1.43 raeburn 4603:
1.49 raeburn 4604: sub print_coursecategories {
1.57 raeburn 4605: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4606: my $datatable;
4607: if ($position eq 'top') {
4608: my $toggle_cats_crs = ' ';
4609: my $toggle_cats_dom = ' checked="checked" ';
4610: my $can_cat_crs = ' ';
4611: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4612: my $toggle_catscomm_comm = ' ';
4613: my $toggle_catscomm_dom = ' checked="checked" ';
4614: my $can_catcomm_comm = ' ';
4615: my $can_catcomm_dom = ' checked="checked" ';
4616:
1.57 raeburn 4617: if (ref($settings) eq 'HASH') {
4618: if ($settings->{'togglecats'} eq 'crs') {
4619: $toggle_cats_crs = $toggle_cats_dom;
4620: $toggle_cats_dom = ' ';
4621: }
4622: if ($settings->{'categorize'} eq 'crs') {
4623: $can_cat_crs = $can_cat_dom;
4624: $can_cat_dom = ' ';
4625: }
1.120 raeburn 4626: if ($settings->{'togglecatscomm'} eq 'comm') {
4627: $toggle_catscomm_comm = $toggle_catscomm_dom;
4628: $toggle_catscomm_dom = ' ';
4629: }
4630: if ($settings->{'categorizecomm'} eq 'comm') {
4631: $can_catcomm_comm = $can_catcomm_dom;
4632: $can_catcomm_dom = ' ';
4633: }
1.57 raeburn 4634: }
4635: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4636: togglecats => 'Show/Hide a course in catalog',
4637: togglecatscomm => 'Show/Hide a community in catalog',
4638: categorize => 'Assign a category to a course',
4639: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4640: );
4641: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4642: dom => 'Set in Domain',
4643: crs => 'Set in Course',
4644: comm => 'Set in Community',
1.57 raeburn 4645: );
4646: $datatable = '<tr class="LC_odd_row">'.
4647: '<td>'.$title{'togglecats'}.'</td>'.
4648: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4649: '<input type="radio" name="togglecats"'.
4650: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4651: '<label><input type="radio" name="togglecats"'.
4652: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4653: '</tr><tr>'.
4654: '<td>'.$title{'categorize'}.'</td>'.
4655: '<td class="LC_right_item"><span class="LC_nobreak">'.
4656: '<label><input type="radio" name="categorize"'.
4657: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4658: '<label><input type="radio" name="categorize"'.
4659: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4660: '</tr><tr class="LC_odd_row">'.
4661: '<td>'.$title{'togglecatscomm'}.'</td>'.
4662: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4663: '<input type="radio" name="togglecatscomm"'.
4664: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4665: '<label><input type="radio" name="togglecatscomm"'.
4666: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4667: '</tr><tr>'.
4668: '<td>'.$title{'categorizecomm'}.'</td>'.
4669: '<td class="LC_right_item"><span class="LC_nobreak">'.
4670: '<label><input type="radio" name="categorizecomm"'.
4671: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4672: '<label><input type="radio" name="categorizecomm"'.
4673: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4674: '</tr>';
1.120 raeburn 4675: $$rowtotal += 4;
1.57 raeburn 4676: } else {
4677: my $css_class;
4678: my $itemcount = 1;
4679: my $cathash;
4680: if (ref($settings) eq 'HASH') {
4681: $cathash = $settings->{'cats'};
4682: }
4683: if (ref($cathash) eq 'HASH') {
4684: my (@cats,@trails,%allitems,%idx,@jsarray);
4685: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4686: \%allitems,\%idx,\@jsarray);
4687: my $maxdepth = scalar(@cats);
4688: my $colattrib = '';
4689: if ($maxdepth > 2) {
4690: $colattrib = ' colspan="2" ';
4691: }
4692: my @path;
4693: if (@cats > 0) {
4694: if (ref($cats[0]) eq 'ARRAY') {
4695: my $numtop = @{$cats[0]};
4696: my $maxnum = $numtop;
1.120 raeburn 4697: my %default_names = (
4698: instcode => &mt('Official courses'),
4699: communities => &mt('Communities'),
4700: );
4701:
4702: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4703: ($cathash->{'instcode::0'} eq '') ||
4704: (!grep(/^communities$/,@{$cats[0]})) ||
4705: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4706: $maxnum ++;
4707: }
4708: my $lastidx;
4709: for (my $i=0; $i<$numtop; $i++) {
4710: my $parent = $cats[0][$i];
4711: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4712: my $item = &escape($parent).'::0';
4713: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4714: $lastidx = $idx{$item};
4715: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4716: .'<select name="'.$item.'"'.$chgstr.'>';
4717: for (my $k=0; $k<=$maxnum; $k++) {
4718: my $vpos = $k+1;
4719: my $selstr;
4720: if ($k == $i) {
4721: $selstr = ' selected="selected" ';
4722: }
4723: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4724: }
1.214 raeburn 4725: $datatable .= '</select></span></td><td>';
1.120 raeburn 4726: if ($parent eq 'instcode' || $parent eq 'communities') {
4727: $datatable .= '<span class="LC_nobreak">'
4728: .$default_names{$parent}.'</span>';
4729: if ($parent eq 'instcode') {
4730: $datatable .= '<br /><span class="LC_nobreak">('
4731: .&mt('with institutional codes')
4732: .')</span></td><td'.$colattrib.'>';
4733: } else {
4734: $datatable .= '<table><tr><td>';
4735: }
4736: $datatable .= '<span class="LC_nobreak">'
4737: .'<label><input type="radio" name="'
4738: .$parent.'" value="1" checked="checked" />'
4739: .&mt('Display').'</label>';
4740: if ($parent eq 'instcode') {
4741: $datatable .= ' ';
4742: } else {
4743: $datatable .= '</span></td></tr><tr><td>'
4744: .'<span class="LC_nobreak">';
4745: }
4746: $datatable .= '<label><input type="radio" name="'
4747: .$parent.'" value="0" />'
4748: .&mt('Do not display').'</label></span>';
4749: if ($parent eq 'communities') {
4750: $datatable .= '</td></tr></table>';
4751: }
4752: $datatable .= '</td>';
1.57 raeburn 4753: } else {
4754: $datatable .= $parent
1.214 raeburn 4755: .' <span class="LC_nobreak"><label>'
4756: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4757: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4758: }
4759: my $depth = 1;
4760: push(@path,$parent);
4761: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4762: pop(@path);
4763: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4764: $itemcount ++;
4765: }
1.48 raeburn 4766: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4767: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4768: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4769: for (my $k=0; $k<=$maxnum; $k++) {
4770: my $vpos = $k+1;
4771: my $selstr;
1.57 raeburn 4772: if ($k == $numtop) {
1.48 raeburn 4773: $selstr = ' selected="selected" ';
4774: }
4775: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4776: }
1.59 bisitz 4777: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4778: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4779: .'</tr>'."\n";
1.48 raeburn 4780: $itemcount ++;
1.120 raeburn 4781: foreach my $default ('instcode','communities') {
4782: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4783: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4784: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4785: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4786: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4787: for (my $k=0; $k<=$maxnum; $k++) {
4788: my $vpos = $k+1;
4789: my $selstr;
4790: if ($k == $maxnum) {
4791: $selstr = ' selected="selected" ';
4792: }
4793: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4794: }
1.120 raeburn 4795: $datatable .= '</select></span></td>'.
4796: '<td><span class="LC_nobreak">'.
4797: $default_names{$default}.'</span>';
4798: if ($default eq 'instcode') {
4799: $datatable .= '<br /><span class="LC_nobreak">('
4800: .&mt('with institutional codes').')</span>';
4801: }
4802: $datatable .= '</td>'
4803: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4804: .&mt('Display').'</label> '
4805: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4806: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4807: }
4808: }
4809: }
1.57 raeburn 4810: } else {
4811: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4812: }
4813: } else {
1.57 raeburn 4814: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4815: .&initialize_categories($itemcount);
1.48 raeburn 4816: }
1.57 raeburn 4817: $$rowtotal += $itemcount;
1.48 raeburn 4818: }
4819: return $datatable;
4820: }
4821:
1.69 raeburn 4822: sub print_serverstatuses {
4823: my ($dom,$settings,$rowtotal) = @_;
4824: my $datatable;
4825: my @pages = &serverstatus_pages();
4826: my (%namedaccess,%machineaccess);
4827: foreach my $type (@pages) {
4828: $namedaccess{$type} = '';
4829: $machineaccess{$type}= '';
4830: }
4831: if (ref($settings) eq 'HASH') {
4832: foreach my $type (@pages) {
4833: if (exists($settings->{$type})) {
4834: if (ref($settings->{$type}) eq 'HASH') {
4835: foreach my $key (keys(%{$settings->{$type}})) {
4836: if ($key eq 'namedusers') {
4837: $namedaccess{$type} = $settings->{$type}->{$key};
4838: } elsif ($key eq 'machines') {
4839: $machineaccess{$type} = $settings->{$type}->{$key};
4840: }
4841: }
4842: }
4843: }
4844: }
4845: }
1.81 raeburn 4846: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4847: my $rownum = 0;
4848: my $css_class;
4849: foreach my $type (@pages) {
4850: $rownum ++;
4851: $css_class = $rownum%2?' class="LC_odd_row"':'';
4852: $datatable .= '<tr'.$css_class.'>'.
4853: '<td><span class="LC_nobreak">'.
4854: $titles->{$type}.'</span></td>'.
4855: '<td class="LC_left_item">'.
4856: '<input type="text" name="'.$type.'_namedusers" '.
4857: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4858: '<td class="LC_right_item">'.
4859: '<span class="LC_nobreak">'.
4860: '<input type="text" name="'.$type.'_machines" '.
4861: 'value="'.$machineaccess{$type}.'" size="10" />'.
4862: '</td></tr>'."\n";
4863: }
4864: $$rowtotal += $rownum;
4865: return $datatable;
4866: }
4867:
4868: sub serverstatus_pages {
4869: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4870: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 4871: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 4872: 'uniquecodes','diskusage');
1.69 raeburn 4873: }
4874:
1.49 raeburn 4875: sub coursecategories_javascript {
4876: my ($settings) = @_;
1.57 raeburn 4877: my ($output,$jstext,$cathash);
1.49 raeburn 4878: if (ref($settings) eq 'HASH') {
1.57 raeburn 4879: $cathash = $settings->{'cats'};
4880: }
4881: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4882: my (@cats,@jsarray,%idx);
1.57 raeburn 4883: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4884: if (@jsarray > 0) {
4885: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4886: for (my $i=0; $i<@jsarray; $i++) {
4887: if (ref($jsarray[$i]) eq 'ARRAY') {
4888: my $catstr = join('","',@{$jsarray[$i]});
4889: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4890: }
4891: }
4892: }
4893: } else {
4894: $jstext = ' var categories = Array(1);'."\n".
4895: ' categories[0] = Array("instcode_pos");'."\n";
4896: }
1.120 raeburn 4897: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4898: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4899: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4900: $output = <<"ENDSCRIPT";
4901: <script type="text/javascript">
1.109 raeburn 4902: // <![CDATA[
1.49 raeburn 4903: function reorderCats(form,parent,item,idx) {
4904: var changedVal;
4905: $jstext
4906: var newpos = 'addcategory_pos';
4907: var current = new Array;
4908: if (parent == '') {
4909: var has_instcode = 0;
4910: var maxtop = categories[idx].length;
4911: for (var j=0; j<maxtop; j++) {
4912: if (categories[idx][j] == 'instcode::0') {
4913: has_instcode == 1;
4914: }
4915: }
4916: if (has_instcode == 0) {
4917: categories[idx][maxtop] = 'instcode_pos';
4918: }
4919: } else {
4920: newpos += '_'+parent;
4921: }
4922: var maxh = 1 + categories[idx].length;
4923: var current = new Array;
4924: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4925: if (item == newpos) {
4926: changedVal = newitemVal;
4927: } else {
4928: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4929: current[newitemVal] = newpos;
4930: }
4931: for (var i=0; i<categories[idx].length; i++) {
4932: var elementName = categories[idx][i];
4933: if (elementName != item) {
4934: if (form.elements[elementName]) {
4935: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4936: current[currVal] = elementName;
4937: }
4938: }
4939: }
4940: var oldVal;
4941: for (var j=0; j<maxh; j++) {
4942: if (current[j] == undefined) {
4943: oldVal = j;
4944: }
4945: }
4946: if (oldVal < changedVal) {
4947: for (var k=oldVal+1; k<=changedVal ; k++) {
4948: var elementName = current[k];
4949: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4950: }
4951: } else {
4952: for (var k=changedVal; k<oldVal; k++) {
4953: var elementName = current[k];
4954: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4955: }
4956: }
4957: return;
4958: }
1.120 raeburn 4959:
4960: function categoryCheck(form) {
4961: if (form.elements['addcategory_name'].value == 'instcode') {
4962: alert('$instcode_reserved\\n$choose_again');
4963: return false;
4964: }
4965: if (form.elements['addcategory_name'].value == 'communities') {
4966: alert('$communities_reserved\\n$choose_again');
4967: return false;
4968: }
4969: return true;
4970: }
4971:
1.109 raeburn 4972: // ]]>
1.49 raeburn 4973: </script>
4974:
4975: ENDSCRIPT
4976: return $output;
4977: }
4978:
1.48 raeburn 4979: sub initialize_categories {
4980: my ($itemcount) = @_;
1.120 raeburn 4981: my ($datatable,$css_class,$chgstr);
4982: my %default_names = (
4983: instcode => 'Official courses (with institutional codes)',
4984: communities => 'Communities',
4985: );
4986: my $select0 = ' selected="selected"';
4987: my $select1 = '';
4988: foreach my $default ('instcode','communities') {
4989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4990: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4991: if ($default eq 'communities') {
4992: $select1 = $select0;
4993: $select0 = '';
4994: }
4995: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4996: .'<select name="'.$default.'_pos">'
4997: .'<option value="0"'.$select0.'>1</option>'
4998: .'<option value="1"'.$select1.'>2</option>'
4999: .'<option value="2">3</option></select> '
5000: .$default_names{$default}
5001: .'</span></td><td><span class="LC_nobreak">'
5002: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5003: .&mt('Display').'</label> <label>'
5004: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5005: .'</label></span></td></tr>';
1.120 raeburn 5006: $itemcount ++;
5007: }
1.48 raeburn 5008: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5009: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5010: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5011: .'<select name="addcategory_pos"'.$chgstr.'>'
5012: .'<option value="0">1</option>'
5013: .'<option value="1">2</option>'
5014: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5015: .&mt('Add category').'</td><td>'.&mt('Name:')
5016: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5017: return $datatable;
5018: }
5019:
5020: sub build_category_rows {
1.49 raeburn 5021: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5022: my ($text,$name,$item,$chgstr);
1.48 raeburn 5023: if (ref($cats) eq 'ARRAY') {
5024: my $maxdepth = scalar(@{$cats});
5025: if (ref($cats->[$depth]) eq 'HASH') {
5026: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5027: my $numchildren = @{$cats->[$depth]{$parent}};
5028: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5029: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5030: my ($idxnum,$parent_name,$parent_item);
5031: my $higher = $depth - 1;
5032: if ($higher == 0) {
5033: $parent_name = &escape($parent).'::'.$higher;
5034: } else {
5035: if (ref($path) eq 'ARRAY') {
5036: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5037: }
5038: }
5039: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5040: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5041: if ($j < $numchildren) {
1.48 raeburn 5042: $name = $cats->[$depth]{$parent}[$j];
5043: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5044: $idxnum = $idx->{$item};
5045: } else {
5046: $name = $parent_name;
5047: $item = $parent_item;
1.48 raeburn 5048: }
1.49 raeburn 5049: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5050: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5051: for (my $i=0; $i<=$numchildren; $i++) {
5052: my $vpos = $i+1;
5053: my $selstr;
5054: if ($j == $i) {
5055: $selstr = ' selected="selected" ';
5056: }
5057: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5058: }
5059: $text .= '</select> ';
5060: if ($j < $numchildren) {
5061: my $deeper = $depth+1;
5062: $text .= $name.' '
5063: .'<label><input type="checkbox" name="deletecategory" value="'
5064: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5065: if(ref($path) eq 'ARRAY') {
5066: push(@{$path},$name);
1.49 raeburn 5067: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5068: pop(@{$path});
5069: }
5070: } else {
1.59 bisitz 5071: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5072: if ($j == $numchildren) {
5073: $text .= $name;
5074: } else {
5075: $text .= $item;
5076: }
5077: $text .= '" value="" />';
5078: }
5079: $text .= '</td></tr>';
5080: }
5081: $text .= '</table></td>';
5082: } else {
5083: my $higher = $depth-1;
5084: if ($higher == 0) {
5085: $name = &escape($parent).'::'.$higher;
5086: } else {
5087: if (ref($path) eq 'ARRAY') {
5088: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5089: }
5090: }
5091: my $colspan;
5092: if ($parent ne 'instcode') {
5093: $colspan = $maxdepth - $depth - 1;
5094: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5095: }
5096: }
5097: }
5098: }
5099: return $text;
5100: }
5101:
1.33 raeburn 5102: sub modifiable_userdata_row {
1.228 raeburn 5103: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5104: my ($role,$rolename,$statustype);
5105: $role = $item;
1.224 raeburn 5106: if ($context eq 'cancreate') {
1.228 raeburn 5107: if ($item =~ /^emailusername_(.+)$/) {
5108: $statustype = $1;
5109: $role = 'emailusername';
5110: if (ref($usertypes) eq 'HASH') {
5111: if ($usertypes->{$statustype}) {
5112: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5113: } else {
5114: $rolename = &mt('Data provided by user');
5115: }
5116: }
1.224 raeburn 5117: }
5118: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5119: if (ref($usertypes) eq 'HASH') {
5120: $rolename = $usertypes->{$role};
5121: } else {
5122: $rolename = $role;
5123: }
1.33 raeburn 5124: } else {
1.63 raeburn 5125: if ($role eq 'cr') {
5126: $rolename = &mt('Custom role');
5127: } else {
5128: $rolename = &Apache::lonnet::plaintext($role);
5129: }
1.33 raeburn 5130: }
1.224 raeburn 5131: my (@fields,%fieldtitles);
5132: if (ref($fieldsref) eq 'ARRAY') {
5133: @fields = @{$fieldsref};
5134: } else {
5135: @fields = ('lastname','firstname','middlename','generation',
5136: 'permanentemail','id');
5137: }
5138: if ((ref($titlesref) eq 'HASH')) {
5139: %fieldtitles = %{$titlesref};
5140: } else {
5141: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5142: }
1.33 raeburn 5143: my $output;
5144: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5145: $output = '<tr '.$css_class.'>'.
5146: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5147: '<td class="LC_left_item" colspan="2"><table>';
5148: my $rem;
5149: my %checks;
5150: if (ref($settings) eq 'HASH') {
5151: if (ref($settings->{$context}) eq 'HASH') {
5152: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5153: my $hashref = $settings->{$context}->{$role};
5154: if ($role eq 'emailusername') {
5155: if ($statustype) {
5156: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5157: $hashref = $settings->{$context}->{$role}->{$statustype};
5158: if (ref($hashref) eq 'HASH') {
5159: foreach my $field (@fields) {
5160: if ($hashref->{$field}) {
5161: $checks{$field} = $hashref->{$field};
5162: }
5163: }
5164: }
5165: }
5166: }
5167: } else {
5168: if (ref($hashref) eq 'HASH') {
5169: foreach my $field (@fields) {
5170: if ($hashref->{$field}) {
5171: $checks{$field} = ' checked="checked" ';
5172: }
5173: }
1.33 raeburn 5174: }
5175: }
5176: }
5177: }
5178: }
1.228 raeburn 5179:
1.33 raeburn 5180: for (my $i=0; $i<@fields; $i++) {
5181: my $rem = $i%($numinrow);
5182: if ($rem == 0) {
5183: if ($i > 0) {
5184: $output .= '</tr>';
5185: }
5186: $output .= '<tr>';
5187: }
5188: my $check = ' ';
1.228 raeburn 5189: unless ($role eq 'emailusername') {
5190: if (exists($checks{$fields[$i]})) {
5191: $check = $checks{$fields[$i]}
5192: } else {
5193: if ($role eq 'st') {
5194: if (ref($settings) ne 'HASH') {
5195: $check = ' checked="checked" ';
5196: }
1.33 raeburn 5197: }
5198: }
5199: }
5200: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5201: '<span class="LC_nobreak">';
5202: if ($role eq 'emailusername') {
5203: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5204: $checks{$fields[$i]} = 'omit';
5205: }
5206: foreach my $option ('required','optional','omit') {
5207: my $checked='';
5208: if ($checks{$fields[$i]} eq $option) {
5209: $checked='checked="checked" ';
5210: }
5211: $output .= '<label>'.
5212: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5213: &mt($option).'</label>'.(' ' x2);
5214: }
5215: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5216: } else {
5217: $output .= '<label>'.
5218: '<input type="checkbox" name="canmodify_'.$role.'" '.
5219: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5220: '</label>';
5221: }
5222: $output .= '</span></td>';
1.33 raeburn 5223: $rem = @fields%($numinrow);
5224: }
5225: my $colsleft = $numinrow - $rem;
5226: if ($colsleft > 1 ) {
5227: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5228: ' </td>';
5229: } elsif ($colsleft == 1) {
5230: $output .= '<td class="LC_left_item"> </td>';
5231: }
5232: $output .= '</tr></table></td></tr>';
5233: return $output;
5234: }
1.28 raeburn 5235:
1.93 raeburn 5236: sub insttypes_row {
1.224 raeburn 5237: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5238: my %lt = &Apache::lonlocal::texthash (
5239: cansearch => 'Users allowed to search',
5240: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5241: lockablenames => 'User preference to lock name',
1.93 raeburn 5242: );
5243: my $showdom;
5244: if ($context eq 'cansearch') {
5245: $showdom = ' ('.$dom.')';
5246: }
1.165 raeburn 5247: my $class = 'LC_left_item';
5248: if ($context eq 'statustocreate') {
5249: $class = 'LC_right_item';
5250: }
1.224 raeburn 5251: my $css_class = ' class="LC_odd_row"';
5252: if ($rownum ne '') {
5253: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5254: }
5255: my $output = '<tr'.$css_class.'>'.
5256: '<td>'.$lt{$context}.$showdom.
5257: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5258: my $rem;
5259: if (ref($types) eq 'ARRAY') {
5260: for (my $i=0; $i<@{$types}; $i++) {
5261: if (defined($usertypes->{$types->[$i]})) {
5262: my $rem = $i%($numinrow);
5263: if ($rem == 0) {
5264: if ($i > 0) {
5265: $output .= '</tr>';
5266: }
5267: $output .= '<tr>';
1.23 raeburn 5268: }
1.26 raeburn 5269: my $check = ' ';
1.99 raeburn 5270: if (ref($settings) eq 'HASH') {
5271: if (ref($settings->{$context}) eq 'ARRAY') {
5272: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5273: $check = ' checked="checked" ';
5274: }
5275: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5276: $check = ' checked="checked" ';
5277: }
1.23 raeburn 5278: }
1.26 raeburn 5279: $output .= '<td class="LC_left_item">'.
5280: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5281: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5282: 'value="'.$types->[$i].'"'.$check.'/>'.
5283: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5284: }
5285: }
1.26 raeburn 5286: $rem = @{$types}%($numinrow);
1.23 raeburn 5287: }
5288: my $colsleft = $numinrow - $rem;
1.131 raeburn 5289: if (($rem == 0) && (@{$types} > 0)) {
5290: $output .= '<tr>';
5291: }
1.23 raeburn 5292: if ($colsleft > 1) {
1.25 raeburn 5293: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5294: } else {
1.25 raeburn 5295: $output .= '<td class="LC_left_item">';
1.23 raeburn 5296: }
5297: my $defcheck = ' ';
1.99 raeburn 5298: if (ref($settings) eq 'HASH') {
5299: if (ref($settings->{$context}) eq 'ARRAY') {
5300: if (grep(/^default$/,@{$settings->{$context}})) {
5301: $defcheck = ' checked="checked" ';
5302: }
5303: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5304: $defcheck = ' checked="checked" ';
5305: }
1.23 raeburn 5306: }
1.25 raeburn 5307: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5308: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5309: 'value="default"'.$defcheck.'/>'.
5310: $othertitle.'</label></span></td>'.
5311: '</tr></table></td></tr>';
5312: return $output;
1.23 raeburn 5313: }
5314:
5315: sub sorted_searchtitles {
5316: my %searchtitles = &Apache::lonlocal::texthash(
5317: 'uname' => 'username',
5318: 'lastname' => 'last name',
5319: 'lastfirst' => 'last name, first name',
5320: );
5321: my @titleorder = ('uname','lastname','lastfirst');
5322: return (\%searchtitles,\@titleorder);
5323: }
5324:
1.25 raeburn 5325: sub sorted_searchtypes {
5326: my %srchtypes_desc = (
5327: exact => 'is exact match',
5328: contains => 'contains ..',
5329: begins => 'begins with ..',
5330: );
5331: my @srchtypeorder = ('exact','begins','contains');
5332: return (\%srchtypes_desc,\@srchtypeorder);
5333: }
5334:
1.3 raeburn 5335: sub usertype_update_row {
5336: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5337: my $datatable;
5338: my $numinrow = 4;
5339: foreach my $type (@{$types}) {
5340: if (defined($usertypes->{$type})) {
5341: $$rownums ++;
5342: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5343: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5344: '</td><td class="LC_left_item"><table>';
5345: for (my $i=0; $i<@{$fields}; $i++) {
5346: my $rem = $i%($numinrow);
5347: if ($rem == 0) {
5348: if ($i > 0) {
5349: $datatable .= '</tr>';
5350: }
5351: $datatable .= '<tr>';
5352: }
5353: my $check = ' ';
1.39 raeburn 5354: if (ref($settings) eq 'HASH') {
5355: if (ref($settings->{'fields'}) eq 'HASH') {
5356: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5357: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5358: $check = ' checked="checked" ';
5359: }
1.3 raeburn 5360: }
5361: }
5362: }
5363:
5364: if ($i == @{$fields}-1) {
5365: my $colsleft = $numinrow - $rem;
5366: if ($colsleft > 1) {
5367: $datatable .= '<td colspan="'.$colsleft.'">';
5368: } else {
5369: $datatable .= '<td>';
5370: }
5371: } else {
5372: $datatable .= '<td>';
5373: }
1.8 raeburn 5374: $datatable .= '<span class="LC_nobreak"><label>'.
5375: '<input type="checkbox" name="updateable_'.$type.
5376: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5377: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5378: }
5379: $datatable .= '</tr></table></td></tr>';
5380: }
5381: }
5382: return $datatable;
1.1 raeburn 5383: }
5384:
5385: sub modify_login {
1.205 raeburn 5386: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5387: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5388: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5389: %title = ( coursecatalog => 'Display course catalog',
5390: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5391: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5392: newuser => 'Link for visitors to create a user account',
5393: loginheader => 'Log-in box header');
5394: @offon = ('off','on');
1.112 raeburn 5395: if (ref($domconfig{login}) eq 'HASH') {
5396: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5397: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5398: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5399: }
5400: }
5401: }
1.9 raeburn 5402: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5403: \%domconfig,\%loginhash);
1.188 raeburn 5404: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5405: foreach my $item (@toggles) {
5406: $loginhash{login}{$item} = $env{'form.'.$item};
5407: }
1.41 raeburn 5408: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5409: if (ref($colchanges{'login'}) eq 'HASH') {
5410: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5411: \%loginhash);
5412: }
1.110 raeburn 5413:
1.149 raeburn 5414: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5415: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5416: if (keys(%servers) > 1) {
5417: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5418: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5419: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5420: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5421: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5422: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5423: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5424: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5425: $changes{'loginvia'}{$lonhost} = 1;
5426: } else {
5427: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5428: $changes{'loginvia'}{$lonhost} = 1;
5429: }
5430: } else {
5431: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5432: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5433: $changes{'loginvia'}{$lonhost} = 1;
5434: }
5435: }
5436: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5437: foreach my $item (@loginvia_attribs) {
5438: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5439: }
5440: } else {
5441: foreach my $item (@loginvia_attribs) {
5442: my $new = $env{'form.'.$lonhost.'_'.$item};
5443: if (($item eq 'serverpath') && ($new eq 'custom')) {
5444: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5445: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5446: $new = '/';
5447: }
5448: }
5449: if (($item eq 'custompath') &&
5450: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5451: $new = '';
5452: }
5453: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5454: $changes{'loginvia'}{$lonhost} = 1;
5455: }
5456: if ($item eq 'exempt') {
5457: $new =~ s/^\s+//;
5458: $new =~ s/\s+$//;
5459: my @poss_ips = split(/\s*[,:]\s*/,$new);
5460: my @okips;
5461: foreach my $ip (@poss_ips) {
5462: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5463: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5464: push(@okips,$ip);
5465: }
5466: }
5467: }
5468: if (@okips > 0) {
5469: $new = join(',',@okips);
5470: } else {
5471: $new = '';
5472: }
5473: }
5474: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5475: }
5476: }
1.112 raeburn 5477: } else {
1.128 raeburn 5478: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5479: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5480: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5481: foreach my $item (@loginvia_attribs) {
5482: my $new = $env{'form.'.$lonhost.'_'.$item};
5483: if (($item eq 'serverpath') && ($new eq 'custom')) {
5484: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5485: $new = '/';
5486: }
5487: }
5488: if (($item eq 'custompath') &&
5489: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5490: $new = '';
5491: }
5492: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5493: }
1.110 raeburn 5494: }
5495: }
5496: }
5497: }
1.119 raeburn 5498:
1.168 raeburn 5499: my $servadm = $r->dir_config('lonAdmEMail');
5500: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5501: if (ref($domconfig{'login'}) eq 'HASH') {
5502: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5503: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5504: if ($lang eq 'nolang') {
5505: push(@currlangs,$lang);
5506: } elsif (defined($langchoices{$lang})) {
5507: push(@currlangs,$lang);
5508: } else {
5509: next;
5510: }
5511: }
5512: }
5513: }
5514: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5515: if (@currlangs > 0) {
5516: foreach my $lang (@currlangs) {
5517: if (grep(/^\Q$lang\E$/,@delurls)) {
5518: $changes{'helpurl'}{$lang} = 1;
5519: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5520: $changes{'helpurl'}{$lang} = 1;
5521: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5522: push(@newlangs,$lang);
5523: } else {
5524: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5525: }
5526: }
5527: }
5528: unless (grep(/^nolang$/,@currlangs)) {
5529: if ($env{'form.loginhelpurl_nolang.filename'}) {
5530: $changes{'helpurl'}{'nolang'} = 1;
5531: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5532: push(@newlangs,'nolang');
5533: }
5534: }
5535: if ($env{'form.loginhelpurl_add_lang'}) {
5536: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5537: ($env{'form.loginhelpurl_add_file.filename'})) {
5538: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5539: $addedfile = $env{'form.loginhelpurl_add_lang'};
5540: }
5541: }
5542: if ((@newlangs > 0) || ($addedfile)) {
5543: my $error;
5544: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5545: if ($configuserok eq 'ok') {
5546: if ($switchserver) {
5547: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5548: } elsif ($author_ok eq 'ok') {
5549: my @allnew = @newlangs;
5550: if ($addedfile ne '') {
5551: push(@allnew,$addedfile);
5552: }
5553: foreach my $lang (@allnew) {
5554: my $formelem = 'loginhelpurl_'.$lang;
5555: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5556: $formelem = 'loginhelpurl_add_file';
5557: }
5558: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5559: "help/$lang",'','',$newfile{$lang});
5560: if ($result eq 'ok') {
5561: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5562: $changes{'helpurl'}{$lang} = 1;
5563: } else {
5564: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5565: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5566: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5567: (!grep(/^\Q$lang\E$/,@delurls))) {
5568:
5569: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5570: }
5571: }
5572: }
5573: } else {
5574: $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);
5575: }
5576: } else {
5577: $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);
5578: }
5579: if ($error) {
5580: &Apache::lonnet::logthis($error);
5581: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5582: }
5583: }
1.169 raeburn 5584: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 5585:
5586: my $defaulthelpfile = '/adm/loginproblems.html';
5587: my $defaulttext = &mt('Default in use');
5588:
1.1 raeburn 5589: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5590: $dom);
5591: if ($putresult eq 'ok') {
1.188 raeburn 5592: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5593: my %defaultchecked = (
5594: 'coursecatalog' => 'on',
1.188 raeburn 5595: 'helpdesk' => 'on',
1.42 raeburn 5596: 'adminmail' => 'off',
1.43 raeburn 5597: 'newuser' => 'off',
1.42 raeburn 5598: );
1.55 raeburn 5599: if (ref($domconfig{'login'}) eq 'HASH') {
5600: foreach my $item (@toggles) {
5601: if ($defaultchecked{$item} eq 'on') {
5602: if (($domconfig{'login'}{$item} eq '0') &&
5603: ($env{'form.'.$item} eq '1')) {
5604: $changes{$item} = 1;
5605: } elsif (($domconfig{'login'}{$item} eq '' ||
5606: $domconfig{'login'}{$item} eq '1') &&
5607: ($env{'form.'.$item} eq '0')) {
5608: $changes{$item} = 1;
5609: }
5610: } elsif ($defaultchecked{$item} eq 'off') {
5611: if (($domconfig{'login'}{$item} eq '1') &&
5612: ($env{'form.'.$item} eq '0')) {
5613: $changes{$item} = 1;
5614: } elsif (($domconfig{'login'}{$item} eq '' ||
5615: $domconfig{'login'}{$item} eq '0') &&
5616: ($env{'form.'.$item} eq '1')) {
5617: $changes{$item} = 1;
5618: }
1.42 raeburn 5619: }
5620: }
1.41 raeburn 5621: }
1.6 raeburn 5622: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5623: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5624: if (ref($lastactref) eq 'HASH') {
5625: $lastactref->{'domainconfig'} = 1;
5626: }
1.1 raeburn 5627: $resulttext = &mt('Changes made:').'<ul>';
5628: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5629: if ($item eq 'loginvia') {
1.112 raeburn 5630: if (ref($changes{$item}) eq 'HASH') {
5631: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5632: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5633: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5634: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5635: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5636: $protocol = 'http' if ($protocol ne 'https');
5637: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5638:
5639: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5640: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5641: } else {
5642: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5643: }
5644: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5645: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5646: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5647: }
5648: $resulttext .= '</li>';
5649: } else {
5650: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5651: }
1.112 raeburn 5652: } else {
1.128 raeburn 5653: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5654: }
5655: }
1.128 raeburn 5656: $resulttext .= '</ul></li>';
1.112 raeburn 5657: }
1.168 raeburn 5658: } elsif ($item eq 'helpurl') {
5659: if (ref($changes{$item}) eq 'HASH') {
5660: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5661: if (grep(/^\Q$lang\E$/,@delurls)) {
5662: my ($chg,$link);
5663: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5664: if ($lang eq 'nolang') {
5665: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5666: } else {
5667: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5668: }
5669: $resulttext .= '<li>'.$chg.'</li>';
5670: } else {
5671: my $chg;
5672: if ($lang eq 'nolang') {
5673: $chg = &mt('custom log-in help file for no preferred language');
5674: } else {
5675: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5676: }
5677: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5678: $loginhash{'login'}{'helpurl'}{$lang}.
5679: '?inhibitmenu=yes',$chg,600,500).
5680: '</li>';
5681: }
5682: }
5683: }
1.169 raeburn 5684: } elsif ($item eq 'captcha') {
5685: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5686: my $chgtxt;
1.169 raeburn 5687: if ($loginhash{'login'}{$item} eq 'notused') {
5688: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5689: } else {
5690: my %captchas = &captcha_phrases();
5691: if ($captchas{$loginhash{'login'}{$item}}) {
5692: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5693: } else {
5694: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5695: }
5696: }
5697: $resulttext .= '<li>'.$chgtxt.'</li>';
5698: }
5699: } elsif ($item eq 'recaptchakeys') {
5700: if (ref($loginhash{'login'}) eq 'HASH') {
5701: my ($privkey,$pubkey);
5702: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5703: $pubkey = $loginhash{'login'}{$item}{'public'};
5704: $privkey = $loginhash{'login'}{$item}{'private'};
5705: }
5706: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5707: if (!$pubkey) {
5708: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5709: } else {
5710: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5711: }
5712: if (!$privkey) {
5713: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5714: } else {
5715: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5716: }
5717: $chgtxt .= '</ul>';
5718: $resulttext .= '<li>'.$chgtxt.'</li>';
5719: }
1.41 raeburn 5720: } else {
5721: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5722: }
1.1 raeburn 5723: }
1.6 raeburn 5724: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5725: } else {
5726: $resulttext = &mt('No changes made to log-in page settings');
5727: }
5728: } else {
1.11 albertel 5729: $resulttext = '<span class="LC_error">'.
5730: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5731: }
1.6 raeburn 5732: if ($errors) {
1.9 raeburn 5733: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5734: $errors.'</ul>';
5735: }
5736: return $resulttext;
5737: }
5738:
5739: sub color_font_choices {
5740: my %choices =
5741: &Apache::lonlocal::texthash (
5742: img => "Header",
5743: bgs => "Background colors",
5744: links => "Link colors",
1.55 raeburn 5745: images => "Images",
1.6 raeburn 5746: font => "Font color",
1.201 raeburn 5747: fontmenu => "Font menu",
1.76 raeburn 5748: pgbg => "Page",
1.6 raeburn 5749: tabbg => "Header",
5750: sidebg => "Border",
5751: link => "Link",
5752: alink => "Active link",
5753: vlink => "Visited link",
5754: );
5755: return %choices;
5756: }
5757:
5758: sub modify_rolecolors {
1.205 raeburn 5759: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5760: my ($resulttext,%rolehash);
5761: $rolehash{'rolecolors'} = {};
1.55 raeburn 5762: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5763: if ($domconfig{'rolecolors'} eq '') {
5764: $domconfig{'rolecolors'} = {};
5765: }
5766: }
1.9 raeburn 5767: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5768: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5769: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5770: $dom);
5771: if ($putresult eq 'ok') {
5772: if (keys(%changes) > 0) {
1.41 raeburn 5773: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 5774: if (ref($lastactref) eq 'HASH') {
5775: $lastactref->{'domainconfig'} = 1;
5776: }
1.6 raeburn 5777: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5778: $rolehash{'rolecolors'});
5779: } else {
5780: $resulttext = &mt('No changes made to default color schemes');
5781: }
5782: } else {
1.11 albertel 5783: $resulttext = '<span class="LC_error">'.
5784: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5785: }
5786: if ($errors) {
5787: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5788: $errors.'</ul>';
5789: }
5790: return $resulttext;
5791: }
5792:
5793: sub modify_colors {
1.9 raeburn 5794: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5795: my (%changes,%choices);
1.51 raeburn 5796: my @bgs;
1.6 raeburn 5797: my @links = ('link','alink','vlink');
1.41 raeburn 5798: my @logintext;
1.6 raeburn 5799: my @images;
5800: my $servadm = $r->dir_config('lonAdmEMail');
5801: my $errors;
1.200 raeburn 5802: my %defaults;
1.6 raeburn 5803: foreach my $role (@{$roles}) {
5804: if ($role eq 'login') {
1.12 raeburn 5805: %choices = &login_choices();
1.41 raeburn 5806: @logintext = ('textcol','bgcol');
1.12 raeburn 5807: } else {
5808: %choices = &color_font_choices();
5809: }
5810: if ($role eq 'login') {
1.41 raeburn 5811: @images = ('img','logo','domlogo','login');
1.51 raeburn 5812: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5813: } else {
5814: @images = ('img');
1.200 raeburn 5815: @bgs = ('pgbg','tabbg','sidebg');
5816: }
5817: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5818: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5819: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5820: }
5821: if ($role eq 'login') {
5822: foreach my $item (@logintext) {
1.234 raeburn 5823: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
5824: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
5825: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
5826: }
5827: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 5828: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5829: }
5830: }
5831: } else {
1.234 raeburn 5832: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
5833: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
5834: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
5835: }
5836: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 5837: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5838: }
1.6 raeburn 5839: }
1.200 raeburn 5840: foreach my $item (@bgs) {
1.234 raeburn 5841: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
5842: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
5843: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
5844: }
5845: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 5846: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5847: }
5848: }
5849: foreach my $item (@links) {
1.234 raeburn 5850: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
5851: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
5852: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
5853: }
5854: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 5855: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5856: }
1.6 raeburn 5857: }
1.46 raeburn 5858: my ($configuserok,$author_ok,$switchserver) =
5859: &config_check($dom,$confname,$servadm);
1.9 raeburn 5860: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5861: if (ref($domconfig->{$role}) ne 'HASH') {
5862: $domconfig->{$role} = {};
5863: }
1.8 raeburn 5864: foreach my $img (@images) {
1.70 raeburn 5865: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5866: if (defined($env{'form.login_showlogo_'.$img})) {
5867: $confhash->{$role}{'showlogo'}{$img} = 1;
5868: } else {
5869: $confhash->{$role}{'showlogo'}{$img} = 0;
5870: }
5871: }
1.18 albertel 5872: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5873: && !defined($domconfig->{$role}{$img})
5874: && !$env{'form.'.$role.'_del_'.$img}
5875: && $env{'form.'.$role.'_import_'.$img}) {
5876: # import the old configured image from the .tab setting
5877: # if they haven't provided a new one
5878: $domconfig->{$role}{$img} =
5879: $env{'form.'.$role.'_import_'.$img};
5880: }
1.6 raeburn 5881: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5882: my $error;
1.6 raeburn 5883: if ($configuserok eq 'ok') {
1.9 raeburn 5884: if ($switchserver) {
1.12 raeburn 5885: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5886: } else {
5887: if ($author_ok eq 'ok') {
5888: my ($result,$logourl) =
5889: &publishlogo($r,'upload',$role.'_'.$img,
5890: $dom,$confname,$img,$width,$height);
5891: if ($result eq 'ok') {
5892: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5893: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5894: } else {
1.12 raeburn 5895: $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 5896: }
5897: } else {
1.46 raeburn 5898: $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 5899: }
5900: }
5901: } else {
1.46 raeburn 5902: $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 5903: }
5904: if ($error) {
1.8 raeburn 5905: &Apache::lonnet::logthis($error);
1.11 albertel 5906: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5907: }
5908: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5909: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5910: my $error;
5911: if ($configuserok eq 'ok') {
5912: # is confname an author?
5913: if ($switchserver eq '') {
5914: if ($author_ok eq 'ok') {
5915: my ($result,$logourl) =
5916: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5917: $dom,$confname,$img,$width,$height);
5918: if ($result eq 'ok') {
5919: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5920: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5921: }
5922: }
5923: }
5924: }
1.6 raeburn 5925: }
5926: }
5927: }
5928: if (ref($domconfig) eq 'HASH') {
5929: if (ref($domconfig->{$role}) eq 'HASH') {
5930: foreach my $img (@images) {
5931: if ($domconfig->{$role}{$img} ne '') {
5932: if ($env{'form.'.$role.'_del_'.$img}) {
5933: $confhash->{$role}{$img} = '';
1.12 raeburn 5934: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5935: } else {
1.9 raeburn 5936: if ($confhash->{$role}{$img} eq '') {
5937: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5938: }
1.6 raeburn 5939: }
5940: } else {
5941: if ($env{'form.'.$role.'_del_'.$img}) {
5942: $confhash->{$role}{$img} = '';
1.12 raeburn 5943: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5944: }
5945: }
1.70 raeburn 5946: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5947: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5948: if ($confhash->{$role}{'showlogo'}{$img} ne
5949: $domconfig->{$role}{'showlogo'}{$img}) {
5950: $changes{$role}{'showlogo'}{$img} = 1;
5951: }
5952: } else {
5953: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5954: $changes{$role}{'showlogo'}{$img} = 1;
5955: }
5956: }
5957: }
5958: }
1.6 raeburn 5959: if ($domconfig->{$role}{'font'} ne '') {
5960: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5961: $changes{$role}{'font'} = 1;
5962: }
5963: } else {
5964: if ($confhash->{$role}{'font'}) {
5965: $changes{$role}{'font'} = 1;
5966: }
5967: }
1.107 raeburn 5968: if ($role ne 'login') {
5969: if ($domconfig->{$role}{'fontmenu'} ne '') {
5970: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5971: $changes{$role}{'fontmenu'} = 1;
5972: }
5973: } else {
5974: if ($confhash->{$role}{'fontmenu'}) {
5975: $changes{$role}{'fontmenu'} = 1;
5976: }
1.97 tempelho 5977: }
5978: }
1.6 raeburn 5979: foreach my $item (@bgs) {
5980: if ($domconfig->{$role}{$item} ne '') {
5981: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5982: $changes{$role}{'bgs'}{$item} = 1;
5983: }
5984: } else {
5985: if ($confhash->{$role}{$item}) {
5986: $changes{$role}{'bgs'}{$item} = 1;
5987: }
5988: }
5989: }
5990: foreach my $item (@links) {
5991: if ($domconfig->{$role}{$item} ne '') {
5992: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5993: $changes{$role}{'links'}{$item} = 1;
5994: }
5995: } else {
5996: if ($confhash->{$role}{$item}) {
5997: $changes{$role}{'links'}{$item} = 1;
5998: }
5999: }
6000: }
1.41 raeburn 6001: foreach my $item (@logintext) {
6002: if ($domconfig->{$role}{$item} ne '') {
6003: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6004: $changes{$role}{'logintext'}{$item} = 1;
6005: }
6006: } else {
6007: if ($confhash->{$role}{$item}) {
6008: $changes{$role}{'logintext'}{$item} = 1;
6009: }
6010: }
6011: }
1.6 raeburn 6012: } else {
6013: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6014: \@logintext,$confhash,\%changes);
1.6 raeburn 6015: }
6016: } else {
6017: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6018: \@logintext,$confhash,\%changes);
1.6 raeburn 6019: }
6020: }
6021: return ($errors,%changes);
6022: }
6023:
1.46 raeburn 6024: sub config_check {
6025: my ($dom,$confname,$servadm) = @_;
6026: my ($configuserok,$author_ok,$switchserver,%currroles);
6027: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6028: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6029: $confname,$servadm);
6030: if ($configuserok eq 'ok') {
6031: $switchserver = &check_switchserver($dom,$confname);
6032: if ($switchserver eq '') {
6033: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6034: }
6035: }
6036: return ($configuserok,$author_ok,$switchserver);
6037: }
6038:
1.6 raeburn 6039: sub default_change_checker {
1.41 raeburn 6040: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6041: foreach my $item (@{$links}) {
6042: if ($confhash->{$role}{$item}) {
6043: $changes->{$role}{'links'}{$item} = 1;
6044: }
6045: }
6046: foreach my $item (@{$bgs}) {
6047: if ($confhash->{$role}{$item}) {
6048: $changes->{$role}{'bgs'}{$item} = 1;
6049: }
6050: }
1.41 raeburn 6051: foreach my $item (@{$logintext}) {
6052: if ($confhash->{$role}{$item}) {
6053: $changes->{$role}{'logintext'}{$item} = 1;
6054: }
6055: }
1.6 raeburn 6056: foreach my $img (@{$images}) {
6057: if ($env{'form.'.$role.'_del_'.$img}) {
6058: $confhash->{$role}{$img} = '';
1.12 raeburn 6059: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6060: }
1.70 raeburn 6061: if ($role eq 'login') {
6062: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6063: $changes->{$role}{'showlogo'}{$img} = 1;
6064: }
6065: }
1.6 raeburn 6066: }
6067: if ($confhash->{$role}{'font'}) {
6068: $changes->{$role}{'font'} = 1;
6069: }
1.48 raeburn 6070: }
1.6 raeburn 6071:
6072: sub display_colorchgs {
6073: my ($dom,$changes,$roles,$confhash) = @_;
6074: my (%choices,$resulttext);
6075: if (!grep(/^login$/,@{$roles})) {
6076: $resulttext = &mt('Changes made:').'<br />';
6077: }
6078: foreach my $role (@{$roles}) {
6079: if ($role eq 'login') {
6080: %choices = &login_choices();
6081: } else {
6082: %choices = &color_font_choices();
6083: }
6084: if (ref($changes->{$role}) eq 'HASH') {
6085: if ($role ne 'login') {
6086: $resulttext .= '<h4>'.&mt($role).'</h4>';
6087: }
6088: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6089: if ($role ne 'login') {
6090: $resulttext .= '<ul>';
6091: }
6092: if (ref($changes->{$role}{$key}) eq 'HASH') {
6093: if ($role ne 'login') {
6094: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6095: }
6096: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6097: if (($role eq 'login') && ($key eq 'showlogo')) {
6098: if ($confhash->{$role}{$key}{$item}) {
6099: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6100: } else {
6101: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6102: }
6103: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6104: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6105: } else {
1.12 raeburn 6106: my $newitem = $confhash->{$role}{$item};
6107: if ($key eq 'images') {
6108: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6109: }
6110: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6111: }
6112: }
6113: if ($role ne 'login') {
6114: $resulttext .= '</ul></li>';
6115: }
6116: } else {
6117: if ($confhash->{$role}{$key} eq '') {
6118: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6119: } else {
6120: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6121: }
6122: }
6123: if ($role ne 'login') {
6124: $resulttext .= '</ul>';
6125: }
6126: }
6127: }
6128: }
1.3 raeburn 6129: return $resulttext;
1.1 raeburn 6130: }
6131:
1.9 raeburn 6132: sub thumb_dimensions {
6133: return ('200','50');
6134: }
6135:
1.16 raeburn 6136: sub check_dimensions {
6137: my ($inputfile) = @_;
6138: my ($fullwidth,$fullheight);
6139: if ($inputfile =~ m|^[/\w.\-]+$|) {
6140: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6141: my $imageinfo = <PIPE>;
6142: if (!close(PIPE)) {
6143: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6144: }
6145: chomp($imageinfo);
6146: my ($fullsize) =
1.21 raeburn 6147: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6148: if ($fullsize) {
6149: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6150: }
6151: }
6152: }
6153: return ($fullwidth,$fullheight);
6154: }
6155:
1.9 raeburn 6156: sub check_configuser {
6157: my ($uhome,$dom,$confname,$servadm) = @_;
6158: my ($configuserok,%currroles);
6159: if ($uhome eq 'no_host') {
6160: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6161: my $configpass = &LONCAPA::Enrollment::create_password();
6162: $configuserok =
6163: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6164: $configpass,'','','','','',undef,$servadm);
6165: } else {
6166: $configuserok = 'ok';
6167: %currroles =
6168: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6169: }
6170: return ($configuserok,%currroles);
6171: }
6172:
6173: sub check_authorstatus {
6174: my ($dom,$confname,%currroles) = @_;
6175: my $author_ok;
1.40 raeburn 6176: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6177: my $start = time;
6178: my $end = 0;
6179: $author_ok =
6180: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6181: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6182: } else {
6183: $author_ok = 'ok';
6184: }
6185: return $author_ok;
6186: }
6187:
6188: sub publishlogo {
1.46 raeburn 6189: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6190: my ($output,$fname,$logourl);
6191: if ($action eq 'upload') {
6192: $fname=$env{'form.'.$formname.'.filename'};
6193: chop($env{'form.'.$formname});
6194: } else {
6195: ($fname) = ($formname =~ /([^\/]+)$/);
6196: }
1.46 raeburn 6197: if ($savefileas ne '') {
6198: $fname = $savefileas;
6199: }
1.9 raeburn 6200: $fname=&Apache::lonnet::clean_filename($fname);
6201: # See if there is anything left
6202: unless ($fname) { return ('error: no uploaded file'); }
6203: $fname="$subdir/$fname";
1.210 raeburn 6204: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6205: my $filepath="$docroot/priv";
6206: my $relpath = "$dom/$confname";
1.9 raeburn 6207: my ($fnamepath,$file,$fetchthumb);
6208: $file=$fname;
6209: if ($fname=~m|/|) {
6210: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6211: }
1.164 raeburn 6212: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6213: my $count;
1.164 raeburn 6214: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6215: $filepath.="/$parts[$count]";
6216: if ((-e $filepath)!=1) {
6217: mkdir($filepath,02770);
6218: }
6219: }
6220: # Check for bad extension and disallow upload
6221: if ($file=~/\.(\w+)$/ &&
6222: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6223: $output =
1.207 bisitz 6224: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6225: } elsif ($file=~/\.(\w+)$/ &&
6226: !defined(&Apache::loncommon::fileembstyle($1))) {
6227: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6228: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6229: $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 6230: } elsif (-d "$filepath/$file") {
1.195 bisitz 6231: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6232: } else {
6233: my $source = $filepath.'/'.$file;
6234: my $logfile;
6235: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6236: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6237: }
6238: print $logfile
6239: "\n================= Publish ".localtime()." ================\n".
6240: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6241: # Save the file
6242: if (!open(FH,'>'.$source)) {
6243: &Apache::lonnet::logthis('Failed to create '.$source);
6244: return (&mt('Failed to create file'));
6245: }
6246: if ($action eq 'upload') {
6247: if (!print FH ($env{'form.'.$formname})) {
6248: &Apache::lonnet::logthis('Failed to write to '.$source);
6249: return (&mt('Failed to write file'));
6250: }
6251: } else {
6252: my $original = &Apache::lonnet::filelocation('',$formname);
6253: if(!copy($original,$source)) {
6254: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6255: return (&mt('Failed to write file'));
6256: }
6257: }
6258: close(FH);
6259: chmod(0660, $source); # Permissions to rw-rw---.
6260:
6261: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6262: my $copyfile=$targetdir.'/'.$file;
6263:
6264: my @parts=split(/\//,$targetdir);
6265: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6266: for (my $count=5;$count<=$#parts;$count++) {
6267: $path.="/$parts[$count]";
6268: if (!-e $path) {
6269: print $logfile "\nCreating directory ".$path;
6270: mkdir($path,02770);
6271: }
6272: }
6273: my $versionresult;
6274: if (-e $copyfile) {
6275: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6276: } else {
6277: $versionresult = 'ok';
6278: }
6279: if ($versionresult eq 'ok') {
6280: if (copy($source,$copyfile)) {
6281: print $logfile "\nCopied original source to ".$copyfile."\n";
6282: $output = 'ok';
6283: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6284: push(@{$modified_urls},[$copyfile,$source]);
6285: my $metaoutput =
6286: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6287: unless ($registered_cleanup) {
6288: my $handlers = $r->get_handlers('PerlCleanupHandler');
6289: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6290: $registered_cleanup=1;
6291: }
1.9 raeburn 6292: } else {
6293: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6294: $output = &mt('Failed to copy file to RES space').", $!";
6295: }
6296: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6297: my $inputfile = $filepath.'/'.$file;
6298: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6299: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6300: if ($fullwidth ne '' && $fullheight ne '') {
6301: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6302: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6303: system("convert -sample $thumbsize $inputfile $outfile");
6304: chmod(0660, $filepath.'/tn-'.$file);
6305: if (-e $outfile) {
6306: my $copyfile=$targetdir.'/tn-'.$file;
6307: if (copy($outfile,$copyfile)) {
6308: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6309: my $thumb_metaoutput =
6310: &write_metadata($dom,$confname,$formname,
6311: $targetdir,'tn-'.$file,$logfile);
6312: push(@{$modified_urls},[$copyfile,$outfile]);
6313: unless ($registered_cleanup) {
6314: my $handlers = $r->get_handlers('PerlCleanupHandler');
6315: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6316: $registered_cleanup=1;
6317: }
1.16 raeburn 6318: } else {
6319: print $logfile "\nUnable to write ".$copyfile.
6320: ':'.$!."\n";
6321: }
6322: }
1.9 raeburn 6323: }
6324: }
6325: }
6326: } else {
6327: $output = $versionresult;
6328: }
6329: }
6330: return ($output,$logourl);
6331: }
6332:
6333: sub logo_versioning {
6334: my ($targetdir,$file,$logfile) = @_;
6335: my $target = $targetdir.'/'.$file;
6336: my ($maxversion,$fn,$extn,$output);
6337: $maxversion = 0;
6338: if ($file =~ /^(.+)\.(\w+)$/) {
6339: $fn=$1;
6340: $extn=$2;
6341: }
6342: opendir(DIR,$targetdir);
6343: while (my $filename=readdir(DIR)) {
6344: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6345: $maxversion=($1>$maxversion)?$1:$maxversion;
6346: }
6347: }
6348: $maxversion++;
6349: print $logfile "\nCreating old version ".$maxversion."\n";
6350: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6351: if (copy($target,$copyfile)) {
6352: print $logfile "Copied old target to ".$copyfile."\n";
6353: $copyfile=$copyfile.'.meta';
6354: if (copy($target.'.meta',$copyfile)) {
6355: print $logfile "Copied old target metadata to ".$copyfile."\n";
6356: $output = 'ok';
6357: } else {
6358: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6359: $output = &mt('Failed to copy old meta').", $!, ";
6360: }
6361: } else {
6362: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6363: $output = &mt('Failed to copy old target').", $!, ";
6364: }
6365: return $output;
6366: }
6367:
6368: sub write_metadata {
6369: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6370: my (%metadatafields,%metadatakeys,$output);
6371: $metadatafields{'title'}=$formname;
6372: $metadatafields{'creationdate'}=time;
6373: $metadatafields{'lastrevisiondate'}=time;
6374: $metadatafields{'copyright'}='public';
6375: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6376: $env{'user.domain'};
6377: $metadatafields{'authorspace'}=$confname.':'.$dom;
6378: $metadatafields{'domain'}=$dom;
6379: {
6380: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6381: my $mfh;
1.155 raeburn 6382: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6383: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6384: unless ($_=~/\./) {
6385: my $unikey=$_;
6386: $unikey=~/^([A-Za-z]+)/;
6387: my $tag=$1;
6388: $tag=~tr/A-Z/a-z/;
6389: print $mfh "\n\<$tag";
6390: foreach (split(/\,/,$metadatakeys{$unikey})) {
6391: my $value=$metadatafields{$unikey.'.'.$_};
6392: $value=~s/\"/\'\'/g;
6393: print $mfh ' '.$_.'="'.$value.'"';
6394: }
6395: print $mfh '>'.
6396: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6397: .'</'.$tag.'>';
6398: }
6399: }
6400: $output = 'ok';
6401: print $logfile "\nWrote metadata";
6402: close($mfh);
6403: } else {
6404: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6405: $output = &mt('Could not write metadata');
6406: }
6407: }
1.155 raeburn 6408: return $output;
6409: }
6410:
6411: sub notifysubscribed {
6412: foreach my $targetsource (@{$modified_urls}){
6413: next unless (ref($targetsource) eq 'ARRAY');
6414: my ($target,$source)=@{$targetsource};
6415: if ($source ne '') {
6416: if (open(my $logfh,'>>'.$source.'.log')) {
6417: print $logfh "\nCleanup phase: Notifications\n";
6418: my @subscribed=&subscribed_hosts($target);
6419: foreach my $subhost (@subscribed) {
6420: print $logfh "\nNotifying host ".$subhost.':';
6421: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6422: print $logfh $reply;
6423: }
6424: my @subscribedmeta=&subscribed_hosts("$target.meta");
6425: foreach my $subhost (@subscribedmeta) {
6426: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6427: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6428: $subhost);
6429: print $logfh $reply;
6430: }
6431: print $logfh "\n============ Done ============\n";
1.160 raeburn 6432: close($logfh);
1.155 raeburn 6433: }
6434: }
6435: }
6436: return OK;
6437: }
6438:
6439: sub subscribed_hosts {
6440: my ($target) = @_;
6441: my @subscribed;
6442: if (open(my $fh,"<$target.subscription")) {
6443: while (my $subline=<$fh>) {
6444: if ($subline =~ /^($match_lonid):/) {
6445: my $host = $1;
6446: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6447: unless (grep(/^\Q$host\E$/,@subscribed)) {
6448: push(@subscribed,$host);
6449: }
6450: }
6451: }
6452: }
6453: }
6454: return @subscribed;
1.9 raeburn 6455: }
6456:
6457: sub check_switchserver {
6458: my ($dom,$confname) = @_;
6459: my ($allowed,$switchserver);
6460: my $home = &Apache::lonnet::homeserver($confname,$dom);
6461: if ($home eq 'no_host') {
6462: $home = &Apache::lonnet::domain($dom,'primary');
6463: }
6464: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6465: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6466: if (!$allowed) {
1.180 raeburn 6467: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6468: }
6469: return $switchserver;
6470: }
6471:
1.1 raeburn 6472: sub modify_quotas {
1.216 raeburn 6473: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6474: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 6475: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 ! raeburn 6476: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
! 6477: $validationfieldsref);
1.86 raeburn 6478: if ($action eq 'quotas') {
6479: $context = 'tools';
1.163 raeburn 6480: } else {
1.86 raeburn 6481: $context = $action;
6482: }
6483: if ($context eq 'requestcourses') {
1.216 raeburn 6484: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6485: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6486: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6487: %titles = &courserequest_titles();
6488: $toolregexp = join('|',@usertools);
6489: %conditions = &courserequest_conditions();
1.216 raeburn 6490: $confname = $dom.'-domainconfig';
6491: my $servadm = $r->dir_config('lonAdmEMail');
6492: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 ! raeburn 6493: ($validationitemsref,$validationnamesref,$validationfieldsref) =
! 6494: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 6495: } elsif ($context eq 'requestauthor') {
6496: @usertools = ('author');
6497: %titles = &authorrequest_titles();
1.86 raeburn 6498: } else {
1.162 raeburn 6499: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6500: %titles = &tool_titles();
1.86 raeburn 6501: }
1.212 raeburn 6502: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6503: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6504: foreach my $key (keys(%env)) {
1.101 raeburn 6505: if ($context eq 'requestcourses') {
6506: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6507: my $item = $1;
6508: my $type = $2;
6509: if ($type =~ /^limit_(.+)/) {
6510: $limithash{$item}{$1} = $env{$key};
6511: } else {
6512: $confhash{$item}{$type} = $env{$key};
6513: }
6514: }
1.163 raeburn 6515: } elsif ($context eq 'requestauthor') {
6516: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6517: $confhash{$1} = $env{$key};
6518: }
1.101 raeburn 6519: } else {
1.86 raeburn 6520: if ($key =~ /^form\.quota_(.+)$/) {
6521: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 6522: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6523: $confhash{'authorquota'}{$1} = $env{$key};
6524: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6525: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6526: }
1.72 raeburn 6527: }
6528: }
1.163 raeburn 6529: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 6530: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6531: @approvalnotify = sort(@approvalnotify);
6532: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 6533: my @crstypes = ('official','unofficial','community','textbook');
6534: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6535: foreach my $type (@hasuniquecode) {
6536: if (grep(/^\Q$type\E$/,@crstypes)) {
6537: $confhash{'uniquecode'}{$type} = 1;
6538: }
1.216 raeburn 6539: }
6540: my ($newbook,@allpos);
6541: if ($context eq 'requestcourses') {
6542: if ($env{'form.addbook'}) {
6543: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6544: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6545: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6546: $env{'form.addbook_cdom'}) eq 'no_host') {
6547: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6548: '</span></li>';
6549: } else {
6550: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6551: my $position = $env{'form.addbook_pos'};
6552: $position =~ s/\D+//g;
6553: if ($position ne '') {
6554: $allpos[$position] = $newbook;
6555: }
6556: }
6557: } else {
6558: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6559: '</span></li>';
6560: }
6561: }
1.235 ! raeburn 6562:
1.216 raeburn 6563: }
1.102 raeburn 6564: if (ref($domconfig{$action}) eq 'HASH') {
6565: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6566: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6567: $changes{'notify'}{'approval'} = 1;
6568: }
6569: } else {
1.144 raeburn 6570: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6571: $changes{'notify'}{'approval'} = 1;
6572: }
6573: }
1.218 raeburn 6574: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6575: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6576: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6577: unless ($confhash{'uniquecode'}{$crstype}) {
6578: $changes{'uniquecode'} = 1;
6579: }
6580: }
6581: unless ($changes{'uniquecode'}) {
6582: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6583: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6584: $changes{'uniquecode'} = 1;
6585: }
6586: }
6587: }
6588: } else {
6589: $changes{'uniquecode'} = 1;
6590: }
6591: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6592: $changes{'uniquecode'} = 1;
1.216 raeburn 6593: }
6594: if ($context eq 'requestcourses') {
6595: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6596: my %deletions;
6597: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6598: if (@todelete) {
6599: map { $deletions{$_} = 1; } @todelete;
6600: }
6601: my %imgdeletions;
6602: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6603: if (@todeleteimages) {
6604: map { $imgdeletions{$_} = 1; } @todeleteimages;
6605: }
6606: my $maxnum = $env{'form.book_maxnum'};
6607: for (my $i=0; $i<=$maxnum; $i++) {
6608: my $key = $env{'form.book_id_'.$i};
6609: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6610: if ($deletions{$key}) {
6611: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6612: #FIXME need to obsolete item in RES space
6613: }
6614: next;
6615: } else {
6616: my $newpos = $env{'form.'.$key};
6617: $newpos =~ s/\D+//g;
6618: foreach my $item ('subject','title','author') {
6619: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6620: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6621: $changes{'textbooks'}{$key} = 1;
6622: }
6623: }
6624: $allpos[$newpos] = $key;
6625: }
6626: if ($imgdeletions{$key}) {
6627: $changes{'textbooks'}{$key} = 1;
6628: #FIXME need to obsolete item in RES space
6629: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6630: my ($cdom,$cnum) = split(/_/,$key);
6631: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6632: $cdom,$cnum,$configuserok,
6633: $switchserver,$author_ok);
6634: if ($imgurl) {
6635: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6636: $changes{'textbooks'}{$key} = 1;
6637: }
6638: if ($error) {
6639: &Apache::lonnet::logthis($error);
6640: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6641: }
6642: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6643: $confhash{'textbooks'}{$key}{'image'} =
6644: $domconfig{$action}{'textbooks'}{$key}{'image'};
6645: }
6646: }
6647: }
6648: }
6649: }
1.102 raeburn 6650: } else {
1.144 raeburn 6651: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6652: $changes{'notify'}{'approval'} = 1;
6653: }
1.218 raeburn 6654: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 6655: $changes{'uniquecode'} = 1;
6656: }
6657: }
6658: if ($context eq 'requestcourses') {
6659: if ($newbook) {
6660: $changes{'textbooks'}{$newbook} = 1;
6661: foreach my $item ('subject','title','author') {
6662: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6663: if ($env{'form.addbook_'.$item}) {
6664: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6665: }
6666: }
6667: if ($env{'form.addbook_image.filename'} ne '') {
6668: my ($cdom,$cnum) = split(/_/,$newbook);
1.235 ! raeburn 6669: my ($imageurl,$error) =
1.216 raeburn 6670: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6671: $switchserver,$author_ok);
6672: if ($imageurl) {
6673: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6674: }
6675: if ($error) {
6676: &Apache::lonnet::logthis($error);
6677: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6678: }
6679: }
6680: }
6681: if (@allpos > 0) {
6682: my $idx = 0;
6683: foreach my $item (@allpos) {
6684: if ($item ne '') {
6685: $confhash{'textbooks'}{$item}{'order'} = $idx;
6686: if (ref($domconfig{$action}) eq 'HASH') {
6687: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6688: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6689: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6690: $changes{'textbooks'}{$item} = 1;
6691: }
6692: }
6693: }
6694: }
6695: $idx ++;
6696: }
6697: }
6698: }
1.235 ! raeburn 6699: if (ref($validationitemsref) eq 'ARRAY') {
! 6700: foreach my $item (@{$validationitemsref}) {
! 6701: if ($item eq 'fields') {
! 6702: my @changed;
! 6703: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
! 6704: if (@{$confhash{'validation'}{$item}} > 0) {
! 6705: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
! 6706: }
! 6707: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
! 6708: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
! 6709: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
! 6710: $domconfig{'requestcourses'}{'validation'}{$item});
! 6711: } else {
! 6712: @changed = @{$confhash{'validation'}{$item}};
! 6713: }
! 6714: } else {
! 6715: @changed = @{$confhash{'validation'}{$item}};
! 6716: }
! 6717: if (@changed) {
! 6718: if ($confhash{'validation'}{$item}) {
! 6719: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
! 6720: } else {
! 6721: $changes{'validation'}{$item} = &mt('None');
! 6722: }
! 6723: }
! 6724: } else {
! 6725: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
! 6726: if ($item eq 'markup') {
! 6727: if ($env{'form.requestcourses_validation_'.$item}) {
! 6728: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
! 6729: }
! 6730: }
! 6731: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
! 6732: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
! 6733: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
! 6734: }
! 6735: } else {
! 6736: if ($confhash{'validation'}{$item} ne '') {
! 6737: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
! 6738: }
! 6739: }
! 6740: }
! 6741: }
! 6742: }
! 6743: if ($env{'form.validationdc'}) {
! 6744: my $newval = $env{'form.validationdc'};
! 6745: my %domcoords = &get_active_dcs($dom);
! 6746: if (exists($domcoords{$newval})) {
! 6747: $confhash{'validation'}{'dc'} = $newval;
! 6748: }
! 6749: }
! 6750: if (ref($confhash{'validation'}) eq 'HASH') {
! 6751: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
! 6752: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
! 6753: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
! 6754: if ($confhash{'validation'}{'dc'} eq '') {
! 6755: $changes{'validation'}{'dc'} = &mt('None');
! 6756: } else {
! 6757: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
! 6758: }
! 6759: }
! 6760: } elsif ($confhash{'validation'}{'dc'} ne '') {
! 6761: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
! 6762: }
! 6763: } elsif ($confhash{'validation'}{'dc'} ne '') {
! 6764: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
! 6765: }
! 6766: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
! 6767: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
! 6768: $changes{'validation'}{'dc'} = &mt('None');
! 6769: }
! 6770: }
1.102 raeburn 6771: }
6772: } else {
1.86 raeburn 6773: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 6774: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6775: }
1.72 raeburn 6776: foreach my $item (@usertools) {
6777: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6778: my $unset;
1.101 raeburn 6779: if ($context eq 'requestcourses') {
1.104 raeburn 6780: $unset = '0';
6781: if ($type eq '_LC_adv') {
6782: $unset = '';
6783: }
1.101 raeburn 6784: if ($confhash{$item}{$type} eq 'autolimit') {
6785: $confhash{$item}{$type} .= '=';
6786: unless ($limithash{$item}{$type} =~ /\D/) {
6787: $confhash{$item}{$type} .= $limithash{$item}{$type};
6788: }
6789: }
1.163 raeburn 6790: } elsif ($context eq 'requestauthor') {
6791: $unset = '0';
6792: if ($type eq '_LC_adv') {
6793: $unset = '';
6794: }
1.72 raeburn 6795: } else {
1.101 raeburn 6796: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6797: $confhash{$item}{$type} = 1;
6798: } else {
6799: $confhash{$item}{$type} = 0;
6800: }
1.72 raeburn 6801: }
1.86 raeburn 6802: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 6803: if ($action eq 'requestauthor') {
6804: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6805: $changes{$type} = 1;
6806: }
6807: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6808: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6809: $changes{$item}{$type} = 1;
6810: }
6811: } else {
6812: if ($context eq 'requestcourses') {
1.104 raeburn 6813: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6814: $changes{$item}{$type} = 1;
6815: }
6816: } else {
6817: if (!$confhash{$item}{$type}) {
6818: $changes{$item}{$type} = 1;
6819: }
6820: }
6821: }
6822: } else {
6823: if ($context eq 'requestcourses') {
1.104 raeburn 6824: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 6825: $changes{$item}{$type} = 1;
6826: }
1.163 raeburn 6827: } elsif ($context eq 'requestauthor') {
6828: if ($confhash{$type} ne $unset) {
6829: $changes{$type} = 1;
6830: }
1.72 raeburn 6831: } else {
6832: if (!$confhash{$item}{$type}) {
6833: $changes{$item}{$type} = 1;
6834: }
6835: }
6836: }
1.1 raeburn 6837: }
6838: }
1.163 raeburn 6839: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 6840: if (ref($domconfig{'quotas'}) eq 'HASH') {
6841: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6842: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
6843: if (exists($confhash{'defaultquota'}{$key})) {
6844: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
6845: $changes{'defaultquota'}{$key} = 1;
6846: }
6847: } else {
6848: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 6849: }
6850: }
1.86 raeburn 6851: } else {
6852: foreach my $key (keys(%{$domconfig{'quotas'}})) {
6853: if (exists($confhash{'defaultquota'}{$key})) {
6854: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
6855: $changes{'defaultquota'}{$key} = 1;
6856: }
6857: } else {
6858: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 6859: }
1.1 raeburn 6860: }
6861: }
1.197 raeburn 6862: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6863: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
6864: if (exists($confhash{'authorquota'}{$key})) {
6865: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
6866: $changes{'authorquota'}{$key} = 1;
6867: }
6868: } else {
6869: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
6870: }
6871: }
6872: }
1.1 raeburn 6873: }
1.86 raeburn 6874: if (ref($confhash{'defaultquota'}) eq 'HASH') {
6875: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
6876: if (ref($domconfig{'quotas'}) eq 'HASH') {
6877: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
6878: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6879: $changes{'defaultquota'}{$key} = 1;
6880: }
6881: } else {
6882: if (!exists($domconfig{'quotas'}{$key})) {
6883: $changes{'defaultquota'}{$key} = 1;
6884: }
1.72 raeburn 6885: }
6886: } else {
1.86 raeburn 6887: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6888: }
1.1 raeburn 6889: }
6890: }
1.197 raeburn 6891: if (ref($confhash{'authorquota'}) eq 'HASH') {
6892: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6893: if (ref($domconfig{'quotas'}) eq 'HASH') {
6894: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6895: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6896: $changes{'authorquota'}{$key} = 1;
6897: }
6898: } else {
6899: $changes{'authorquota'}{$key} = 1;
6900: }
6901: } else {
6902: $changes{'authorquota'}{$key} = 1;
6903: }
6904: }
6905: }
1.1 raeburn 6906: }
1.72 raeburn 6907:
1.163 raeburn 6908: if ($context eq 'requestauthor') {
6909: $domdefaults{'requestauthor'} = \%confhash;
6910: } else {
6911: foreach my $key (keys(%confhash)) {
1.216 raeburn 6912: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
6913: $domdefaults{$key} = $confhash{$key};
6914: }
1.163 raeburn 6915: }
1.72 raeburn 6916: }
1.163 raeburn 6917:
1.1 raeburn 6918: my %quotahash = (
1.86 raeburn 6919: $action => { %confhash }
1.1 raeburn 6920: );
6921: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6922: $dom);
6923: if ($putresult eq 'ok') {
6924: if (keys(%changes) > 0) {
1.72 raeburn 6925: my $cachetime = 24*60*60;
6926: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 6927: if (ref($lastactref) eq 'HASH') {
6928: $lastactref->{'domdefaults'} = 1;
6929: }
1.1 raeburn 6930: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6931: unless (($context eq 'requestcourses') ||
1.163 raeburn 6932: ($context eq 'requestauthor')) {
1.86 raeburn 6933: if (ref($changes{'defaultquota'}) eq 'HASH') {
6934: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6935: foreach my $type (@{$types},'default') {
6936: if (defined($changes{'defaultquota'}{$type})) {
6937: my $typetitle = $usertypes->{$type};
6938: if ($type eq 'default') {
6939: $typetitle = $othertitle;
6940: }
1.213 raeburn 6941: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6942: }
6943: }
1.86 raeburn 6944: $resulttext .= '</ul></li>';
1.72 raeburn 6945: }
1.197 raeburn 6946: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 6947: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 6948: foreach my $type (@{$types},'default') {
6949: if (defined($changes{'authorquota'}{$type})) {
6950: my $typetitle = $usertypes->{$type};
6951: if ($type eq 'default') {
6952: $typetitle = $othertitle;
6953: }
1.213 raeburn 6954: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 6955: }
6956: }
6957: $resulttext .= '</ul></li>';
6958: }
1.72 raeburn 6959: }
1.80 raeburn 6960: my %newenv;
1.72 raeburn 6961: foreach my $item (@usertools) {
1.163 raeburn 6962: my (%haschgs,%inconf);
6963: if ($context eq 'requestauthor') {
6964: %haschgs = %changes;
1.210 raeburn 6965: %inconf = %confhash;
1.163 raeburn 6966: } else {
6967: if (ref($changes{$item}) eq 'HASH') {
6968: %haschgs = %{$changes{$item}};
6969: }
6970: if (ref($confhash{$item}) eq 'HASH') {
6971: %inconf = %{$confhash{$item}};
6972: }
6973: }
6974: if (keys(%haschgs) > 0) {
1.80 raeburn 6975: my $newacc =
6976: &Apache::lonnet::usertools_access($env{'user.name'},
6977: $env{'user.domain'},
1.86 raeburn 6978: $item,'reload',$context);
1.210 raeburn 6979: if (($context eq 'requestcourses') ||
1.163 raeburn 6980: ($context eq 'requestauthor')) {
1.108 raeburn 6981: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6982: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6983: }
6984: } else {
6985: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6986: $newenv{'environment.availabletools.'.$item} = $newacc;
6987: }
1.80 raeburn 6988: }
1.163 raeburn 6989: unless ($context eq 'requestauthor') {
6990: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6991: }
1.72 raeburn 6992: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6993: if ($haschgs{$type}) {
1.72 raeburn 6994: my $typetitle = $usertypes->{$type};
6995: if ($type eq 'default') {
6996: $typetitle = $othertitle;
6997: } elsif ($type eq '_LC_adv') {
6998: $typetitle = 'LON-CAPA Advanced Users';
6999: }
1.163 raeburn 7000: if ($inconf{$type}) {
1.101 raeburn 7001: if ($context eq 'requestcourses') {
7002: my $cond;
1.163 raeburn 7003: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7004: if ($1 eq '') {
7005: $cond = &mt('(Automatic processing of any request).');
7006: } else {
7007: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7008: }
7009: } else {
1.163 raeburn 7010: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7011: }
7012: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7013: } elsif ($context eq 'requestauthor') {
7014: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7015: $titles{$inconf{$type}},$typetitle);
7016:
1.101 raeburn 7017: } else {
7018: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7019: }
1.72 raeburn 7020: } else {
1.104 raeburn 7021: if ($type eq '_LC_adv') {
1.163 raeburn 7022: if ($inconf{$type} eq '0') {
1.104 raeburn 7023: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7024: } else {
7025: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7026: }
7027: } else {
7028: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7029: }
1.72 raeburn 7030: }
7031: }
1.26 raeburn 7032: }
1.163 raeburn 7033: unless ($context eq 'requestauthor') {
7034: $resulttext .= '</ul></li>';
7035: }
1.26 raeburn 7036: }
1.1 raeburn 7037: }
1.163 raeburn 7038: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7039: if (ref($changes{'notify'}) eq 'HASH') {
7040: if ($changes{'notify'}{'approval'}) {
7041: if (ref($confhash{'notify'}) eq 'HASH') {
7042: if ($confhash{'notify'}{'approval'}) {
7043: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7044: } else {
1.163 raeburn 7045: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7046: }
7047: }
7048: }
7049: }
7050: }
1.216 raeburn 7051: if ($action eq 'requestcourses') {
7052: my @offon = ('off','on');
7053: if ($changes{'uniquecode'}) {
1.218 raeburn 7054: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7055: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7056: $resulttext .= '<li>'.
7057: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7058: '</li>';
7059: } else {
7060: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7061: '</li>';
7062: }
1.216 raeburn 7063: }
7064: if (ref($changes{'textbooks'}) eq 'HASH') {
7065: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
7066: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
7067: my %coursehash = &Apache::lonnet::coursedescription($key);
7068: my $coursetitle = $coursehash{'description'};
7069: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
7070: $resulttext .= '<li>';
7071: foreach my $item ('subject','title','author') {
7072: my $name = $item.':';
7073: $name =~ s/^(\w)/\U$1/;
7074: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
7075: }
7076: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7077: if ($confhash{'textbooks'}{$key}{'image'}) {
7078: $resulttext .= ' '.&mt('Image: [_1]',
7079: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
7080: ' alt="Textbook cover" />').'<br />';
7081: }
7082: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7083: }
7084: $resulttext .= '</ul></li>';
7085: }
1.235 ! raeburn 7086: if (ref($changes{'validation'}) eq 'HASH') {
! 7087: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
! 7088: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
! 7089: foreach my $item (@{$validationitemsref}) {
! 7090: if (exists($changes{'validation'}{$item})) {
! 7091: if ($item eq 'markup') {
! 7092: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
! 7093: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
! 7094: } else {
! 7095: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
! 7096: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
! 7097: }
! 7098: }
! 7099: }
! 7100: if (exists($changes{'validation'}{'dc'})) {
! 7101: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
! 7102: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
! 7103: }
! 7104: }
! 7105: }
1.216 raeburn 7106: }
1.1 raeburn 7107: $resulttext .= '</ul>';
1.80 raeburn 7108: if (keys(%newenv)) {
7109: &Apache::lonnet::appenv(\%newenv);
7110: }
1.1 raeburn 7111: } else {
1.86 raeburn 7112: if ($context eq 'requestcourses') {
7113: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7114: } elsif ($context eq 'requestauthor') {
7115: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7116: } else {
1.90 weissno 7117: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7118: }
1.1 raeburn 7119: }
7120: } else {
1.11 albertel 7121: $resulttext = '<span class="LC_error">'.
7122: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7123: }
1.216 raeburn 7124: if ($errors) {
7125: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7126: '<ul>'.$errors.'</ul></p>';
7127: }
1.3 raeburn 7128: return $resulttext;
1.1 raeburn 7129: }
7130:
1.216 raeburn 7131: sub process_textbook_image {
7132: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
7133: my $filename = $env{'form.'.$caller.'.filename'};
7134: my ($error,$url);
7135: my ($width,$height) = (50,50);
7136: if ($configuserok eq 'ok') {
7137: if ($switchserver) {
7138: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7139: $switchserver);
7140: } elsif ($author_ok eq 'ok') {
7141: my ($result,$imageurl) =
7142: &publishlogo($r,'upload',$caller,$dom,$confname,
7143: "textbooks/$dom/$cnum/cover",$width,$height);
7144: if ($result eq 'ok') {
7145: $url = $imageurl;
7146: } else {
7147: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7148: }
7149: } else {
7150: $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);
7151: }
7152: } else {
7153: $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);
7154: }
7155: return ($url,$error);
7156: }
7157:
1.3 raeburn 7158: sub modify_autoenroll {
1.205 raeburn 7159: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7160: my ($resulttext,%changes);
7161: my %currautoenroll;
7162: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7163: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7164: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7165: }
7166: }
7167: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7168: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7169: sender => 'Sender for notification messages',
7170: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7171: my @offon = ('off','on');
1.17 raeburn 7172: my $sender_uname = $env{'form.sender_uname'};
7173: my $sender_domain = $env{'form.sender_domain'};
7174: if ($sender_domain eq '') {
7175: $sender_uname = '';
7176: } elsif ($sender_uname eq '') {
7177: $sender_domain = '';
7178: }
1.129 raeburn 7179: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7180: my %autoenrollhash = (
1.129 raeburn 7181: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7182: 'sender_uname' => $sender_uname,
7183: 'sender_domain' => $sender_domain,
7184: 'co-owners' => $coowners,
1.1 raeburn 7185: }
7186: );
1.4 raeburn 7187: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7188: $dom);
1.1 raeburn 7189: if ($putresult eq 'ok') {
7190: if (exists($currautoenroll{'run'})) {
7191: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7192: $changes{'run'} = 1;
7193: }
7194: } elsif ($autorun) {
7195: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7196: $changes{'run'} = 1;
1.1 raeburn 7197: }
7198: }
1.17 raeburn 7199: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7200: $changes{'sender'} = 1;
7201: }
1.17 raeburn 7202: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7203: $changes{'sender'} = 1;
7204: }
1.129 raeburn 7205: if ($currautoenroll{'co-owners'} ne '') {
7206: if ($currautoenroll{'co-owners'} ne $coowners) {
7207: $changes{'coowners'} = 1;
7208: }
7209: } elsif ($coowners) {
7210: $changes{'coowners'} = 1;
7211: }
1.1 raeburn 7212: if (keys(%changes) > 0) {
7213: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7214: if ($changes{'run'}) {
1.1 raeburn 7215: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7216: }
7217: if ($changes{'sender'}) {
1.17 raeburn 7218: if ($sender_uname eq '' || $sender_domain eq '') {
7219: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7220: } else {
7221: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7222: }
1.1 raeburn 7223: }
1.129 raeburn 7224: if ($changes{'coowners'}) {
7225: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7226: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7227: if (ref($lastactref) eq 'HASH') {
7228: $lastactref->{'domainconfig'} = 1;
7229: }
1.129 raeburn 7230: }
1.1 raeburn 7231: $resulttext .= '</ul>';
7232: } else {
7233: $resulttext = &mt('No changes made to auto-enrollment settings');
7234: }
7235: } else {
1.11 albertel 7236: $resulttext = '<span class="LC_error">'.
7237: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7238: }
1.3 raeburn 7239: return $resulttext;
1.1 raeburn 7240: }
7241:
7242: sub modify_autoupdate {
1.3 raeburn 7243: my ($dom,%domconfig) = @_;
1.1 raeburn 7244: my ($resulttext,%currautoupdate,%fields,%changes);
7245: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7246: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7247: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7248: }
7249: }
7250: my @offon = ('off','on');
7251: my %title = &Apache::lonlocal::texthash (
7252: run => 'Auto-update:',
7253: classlists => 'Updates to user information in classlists?'
7254: );
1.44 raeburn 7255: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7256: my %fieldtitles = &Apache::lonlocal::texthash (
7257: id => 'Student/Employee ID',
1.20 raeburn 7258: permanentemail => 'E-mail address',
1.1 raeburn 7259: lastname => 'Last Name',
7260: firstname => 'First Name',
7261: middlename => 'Middle Name',
1.132 raeburn 7262: generation => 'Generation',
1.1 raeburn 7263: );
1.142 raeburn 7264: $othertitle = &mt('All users');
1.1 raeburn 7265: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7266: $othertitle = &mt('Other users');
1.1 raeburn 7267: }
7268: foreach my $key (keys(%env)) {
7269: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7270: my ($usertype,$item) = ($1,$2);
7271: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7272: if ($usertype eq 'default') {
7273: push(@{$fields{$1}},$2);
7274: } elsif (ref($types) eq 'ARRAY') {
7275: if (grep(/^\Q$usertype\E$/,@{$types})) {
7276: push(@{$fields{$1}},$2);
7277: }
7278: }
7279: }
1.1 raeburn 7280: }
7281: }
1.131 raeburn 7282: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7283: @lockablenames = sort(@lockablenames);
7284: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7285: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7286: if (@changed) {
7287: $changes{'lockablenames'} = 1;
7288: }
7289: } else {
7290: if (@lockablenames) {
7291: $changes{'lockablenames'} = 1;
7292: }
7293: }
1.1 raeburn 7294: my %updatehash = (
7295: autoupdate => { run => $env{'form.autoupdate_run'},
7296: classlists => $env{'form.classlists'},
7297: fields => {%fields},
1.131 raeburn 7298: lockablenames => \@lockablenames,
1.1 raeburn 7299: }
7300: );
7301: foreach my $key (keys(%currautoupdate)) {
7302: if (($key eq 'run') || ($key eq 'classlists')) {
7303: if (exists($updatehash{autoupdate}{$key})) {
7304: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7305: $changes{$key} = 1;
7306: }
7307: }
7308: } elsif ($key eq 'fields') {
7309: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7310: foreach my $item (@{$types},'default') {
1.1 raeburn 7311: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7312: my $change = 0;
7313: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7314: if (!exists($fields{$item})) {
7315: $change = 1;
1.132 raeburn 7316: last;
1.1 raeburn 7317: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7318: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7319: $change = 1;
1.132 raeburn 7320: last;
1.1 raeburn 7321: }
7322: }
7323: }
7324: if ($change) {
7325: push(@{$changes{$key}},$item);
7326: }
1.26 raeburn 7327: }
1.1 raeburn 7328: }
7329: }
1.131 raeburn 7330: } elsif ($key eq 'lockablenames') {
7331: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7332: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7333: if (@changed) {
7334: $changes{'lockablenames'} = 1;
7335: }
7336: } else {
7337: if (@lockablenames) {
7338: $changes{'lockablenames'} = 1;
7339: }
7340: }
7341: }
7342: }
7343: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7344: if (@lockablenames) {
7345: $changes{'lockablenames'} = 1;
1.1 raeburn 7346: }
7347: }
1.26 raeburn 7348: foreach my $item (@{$types},'default') {
7349: if (defined($fields{$item})) {
7350: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7351: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7352: my $change = 0;
7353: if (ref($fields{$item}) eq 'ARRAY') {
7354: foreach my $type (@{$fields{$item}}) {
7355: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7356: $change = 1;
7357: last;
7358: }
7359: }
7360: }
7361: if ($change) {
7362: push(@{$changes{'fields'}},$item);
7363: }
7364: } else {
1.26 raeburn 7365: push(@{$changes{'fields'}},$item);
7366: }
7367: } else {
7368: push(@{$changes{'fields'}},$item);
1.1 raeburn 7369: }
7370: }
7371: }
7372: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7373: $dom);
7374: if ($putresult eq 'ok') {
7375: if (keys(%changes) > 0) {
7376: $resulttext = &mt('Changes made:').'<ul>';
7377: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7378: if ($key eq 'lockablenames') {
7379: $resulttext .= '<li>';
7380: if (@lockablenames) {
7381: $usertypes->{'default'} = $othertitle;
7382: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7383: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7384: } else {
7385: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7386: }
7387: $resulttext .= '</li>';
7388: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7389: foreach my $item (@{$changes{$key}}) {
7390: my @newvalues;
7391: foreach my $type (@{$fields{$item}}) {
7392: push(@newvalues,$fieldtitles{$type});
7393: }
1.3 raeburn 7394: my $newvaluestr;
7395: if (@newvalues > 0) {
7396: $newvaluestr = join(', ',@newvalues);
7397: } else {
7398: $newvaluestr = &mt('none');
1.6 raeburn 7399: }
1.1 raeburn 7400: if ($item eq 'default') {
1.26 raeburn 7401: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7402: } else {
1.26 raeburn 7403: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7404: }
7405: }
7406: } else {
7407: my $newvalue;
7408: if ($key eq 'run') {
7409: $newvalue = $offon[$env{'form.autoupdate_run'}];
7410: } else {
7411: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7412: }
1.1 raeburn 7413: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7414: }
7415: }
7416: $resulttext .= '</ul>';
7417: } else {
1.3 raeburn 7418: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7419: }
7420: } else {
1.11 albertel 7421: $resulttext = '<span class="LC_error">'.
7422: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7423: }
1.3 raeburn 7424: return $resulttext;
1.1 raeburn 7425: }
7426:
1.125 raeburn 7427: sub modify_autocreate {
7428: my ($dom,%domconfig) = @_;
7429: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7430: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7431: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7432: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7433: }
7434: }
7435: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7436: req => 'Auto-creation of validated requests for official courses',
7437: xmldc => 'Identity of course creator of courses from XML files',
7438: );
7439: my @types = ('xml','req');
7440: foreach my $item (@types) {
7441: $newvals{$item} = $env{'form.autocreate_'.$item};
7442: $newvals{$item} =~ s/\D//g;
7443: $newvals{$item} = 0 if ($newvals{$item} eq '');
7444: }
7445: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7446: my %domcoords = &get_active_dcs($dom);
7447: unless (exists($domcoords{$newvals{'xmldc'}})) {
7448: $newvals{'xmldc'} = '';
7449: }
7450: %autocreatehash = (
7451: autocreate => { xml => $newvals{'xml'},
7452: req => $newvals{'req'},
7453: }
7454: );
7455: if ($newvals{'xmldc'} ne '') {
7456: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7457: }
7458: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7459: $dom);
7460: if ($putresult eq 'ok') {
7461: my @items = @types;
7462: if ($newvals{'xml'}) {
7463: push(@items,'xmldc');
7464: }
7465: foreach my $item (@items) {
7466: if (exists($currautocreate{$item})) {
7467: if ($currautocreate{$item} ne $newvals{$item}) {
7468: $changes{$item} = 1;
7469: }
7470: } elsif ($newvals{$item}) {
7471: $changes{$item} = 1;
7472: }
7473: }
7474: if (keys(%changes) > 0) {
7475: my @offon = ('off','on');
7476: $resulttext = &mt('Changes made:').'<ul>';
7477: foreach my $item (@types) {
7478: if ($changes{$item}) {
7479: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 7480: $resulttext .= '<li>'.
7481: &mt("$title{$item} set to [_1]$newtxt [_2]",
7482: '<b>','</b>').
7483: '</li>';
1.125 raeburn 7484: }
7485: }
7486: if ($changes{'xmldc'}) {
7487: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7488: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 7489: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7490: }
7491: $resulttext .= '</ul>';
7492: } else {
7493: $resulttext = &mt('No changes made to auto-creation settings');
7494: }
7495: } else {
7496: $resulttext = '<span class="LC_error">'.
7497: &mt('An error occurred: [_1]',$putresult).'</span>';
7498: }
7499: return $resulttext;
7500: }
7501:
1.23 raeburn 7502: sub modify_directorysrch {
7503: my ($dom,%domconfig) = @_;
7504: my ($resulttext,%changes);
7505: my %currdirsrch;
7506: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7507: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7508: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7509: }
7510: }
7511: my %title = ( available => 'Directory search available',
1.24 raeburn 7512: localonly => 'Other domains can search',
1.23 raeburn 7513: searchby => 'Search types',
7514: searchtypes => 'Search latitude');
7515: my @offon = ('off','on');
1.24 raeburn 7516: my @otherdoms = ('Yes','No');
1.23 raeburn 7517:
1.25 raeburn 7518: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7519: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7520: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7521:
1.44 raeburn 7522: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7523: if (keys(%{$usertypes}) == 0) {
7524: @cansearch = ('default');
7525: } else {
7526: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7527: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7528: if (!grep(/^\Q$type\E$/,@cansearch)) {
7529: push(@{$changes{'cansearch'}},$type);
7530: }
1.23 raeburn 7531: }
1.26 raeburn 7532: foreach my $type (@cansearch) {
7533: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7534: push(@{$changes{'cansearch'}},$type);
7535: }
1.23 raeburn 7536: }
1.26 raeburn 7537: } else {
7538: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7539: }
7540: }
7541:
7542: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7543: foreach my $by (@{$currdirsrch{'searchby'}}) {
7544: if (!grep(/^\Q$by\E$/,@searchby)) {
7545: push(@{$changes{'searchby'}},$by);
7546: }
7547: }
7548: foreach my $by (@searchby) {
7549: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7550: push(@{$changes{'searchby'}},$by);
7551: }
7552: }
7553: } else {
7554: push(@{$changes{'searchby'}},@searchby);
7555: }
1.25 raeburn 7556:
7557: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7558: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7559: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7560: push(@{$changes{'searchtypes'}},$type);
7561: }
7562: }
7563: foreach my $type (@searchtypes) {
7564: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7565: push(@{$changes{'searchtypes'}},$type);
7566: }
7567: }
7568: } else {
7569: if (exists($currdirsrch{'searchtypes'})) {
7570: foreach my $type (@searchtypes) {
7571: if ($type ne $currdirsrch{'searchtypes'}) {
7572: push(@{$changes{'searchtypes'}},$type);
7573: }
7574: }
7575: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7576: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7577: }
7578: } else {
7579: push(@{$changes{'searchtypes'}},@searchtypes);
7580: }
7581: }
7582:
1.23 raeburn 7583: my %dirsrch_hash = (
7584: directorysrch => { available => $env{'form.dirsrch_available'},
7585: cansearch => \@cansearch,
1.24 raeburn 7586: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7587: searchby => \@searchby,
1.25 raeburn 7588: searchtypes => \@searchtypes,
1.23 raeburn 7589: }
7590: );
7591: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7592: $dom);
7593: if ($putresult eq 'ok') {
7594: if (exists($currdirsrch{'available'})) {
7595: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7596: $changes{'available'} = 1;
7597: }
7598: } else {
7599: if ($env{'form.dirsrch_available'} eq '1') {
7600: $changes{'available'} = 1;
7601: }
7602: }
1.24 raeburn 7603: if (exists($currdirsrch{'localonly'})) {
7604: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7605: $changes{'localonly'} = 1;
7606: }
7607: } else {
7608: if ($env{'form.dirsrch_localonly'} eq '1') {
7609: $changes{'localonly'} = 1;
7610: }
7611: }
1.23 raeburn 7612: if (keys(%changes) > 0) {
7613: $resulttext = &mt('Changes made:').'<ul>';
7614: if ($changes{'available'}) {
7615: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7616: }
1.24 raeburn 7617: if ($changes{'localonly'}) {
7618: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7619: }
7620:
1.23 raeburn 7621: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7622: my $chgtext;
1.26 raeburn 7623: if (ref($usertypes) eq 'HASH') {
7624: if (keys(%{$usertypes}) > 0) {
7625: foreach my $type (@{$types}) {
7626: if (grep(/^\Q$type\E$/,@cansearch)) {
7627: $chgtext .= $usertypes->{$type}.'; ';
7628: }
7629: }
7630: if (grep(/^default$/,@cansearch)) {
7631: $chgtext .= $othertitle;
7632: } else {
7633: $chgtext =~ s/\; $//;
7634: }
1.210 raeburn 7635: $resulttext .=
1.178 raeburn 7636: '<li>'.
7637: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7638: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7639: '</li>';
1.23 raeburn 7640: }
7641: }
7642: }
7643: if (ref($changes{'searchby'}) eq 'ARRAY') {
7644: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7645: my $chgtext;
7646: foreach my $type (@{$titleorder}) {
7647: if (grep(/^\Q$type\E$/,@searchby)) {
7648: if (defined($searchtitles->{$type})) {
7649: $chgtext .= $searchtitles->{$type}.'; ';
7650: }
7651: }
7652: }
7653: $chgtext =~ s/\; $//;
7654: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7655: }
1.25 raeburn 7656: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7657: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7658: my $chgtext;
7659: foreach my $type (@{$srchtypeorder}) {
7660: if (grep(/^\Q$type\E$/,@searchtypes)) {
7661: if (defined($srchtypes_desc->{$type})) {
7662: $chgtext .= $srchtypes_desc->{$type}.'; ';
7663: }
7664: }
7665: }
7666: $chgtext =~ s/\; $//;
1.178 raeburn 7667: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7668: }
7669: $resulttext .= '</ul>';
7670: } else {
7671: $resulttext = &mt('No changes made to institution directory search settings');
7672: }
7673: } else {
7674: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7675: &mt('An error occurred: [_1]',$putresult).'</span>';
7676: }
7677: return $resulttext;
7678: }
7679:
1.28 raeburn 7680: sub modify_contacts {
1.205 raeburn 7681: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7682: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7683: if (ref($domconfig{'contacts'}) eq 'HASH') {
7684: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7685: $currsetting{$key} = $domconfig{'contacts'}{$key};
7686: }
7687: }
1.134 raeburn 7688: my (%others,%to,%bcc);
1.28 raeburn 7689: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7690: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 7691: 'requestsmail','updatesmail','idconflictsmail');
7692: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7693: foreach my $type (@mailings) {
7694: @{$newsetting{$type}} =
7695: &Apache::loncommon::get_env_multiple('form.'.$type);
7696: foreach my $item (@contacts) {
7697: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7698: $contacts_hash{contacts}{$type}{$item} = 1;
7699: } else {
7700: $contacts_hash{contacts}{$type}{$item} = 0;
7701: }
7702: }
7703: $others{$type} = $env{'form.'.$type.'_others'};
7704: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7705: if ($type eq 'helpdeskmail') {
7706: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7707: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7708: }
1.28 raeburn 7709: }
7710: foreach my $item (@contacts) {
7711: $to{$item} = $env{'form.'.$item};
7712: $contacts_hash{'contacts'}{$item} = $to{$item};
7713: }
1.203 raeburn 7714: foreach my $item (@toggles) {
7715: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7716: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7717: }
7718: }
1.28 raeburn 7719: if (keys(%currsetting) > 0) {
7720: foreach my $item (@contacts) {
7721: if ($to{$item} ne $currsetting{$item}) {
7722: $changes{$item} = 1;
7723: }
7724: }
7725: foreach my $type (@mailings) {
7726: foreach my $item (@contacts) {
7727: if (ref($currsetting{$type}) eq 'HASH') {
7728: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7729: push(@{$changes{$type}},$item);
7730: }
7731: } else {
7732: push(@{$changes{$type}},@{$newsetting{$type}});
7733: }
7734: }
7735: if ($others{$type} ne $currsetting{$type}{'others'}) {
7736: push(@{$changes{$type}},'others');
7737: }
1.134 raeburn 7738: if ($type eq 'helpdeskmail') {
7739: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7740: push(@{$changes{$type}},'bcc');
7741: }
7742: }
1.28 raeburn 7743: }
7744: } else {
7745: my %default;
7746: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7747: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7748: $default{'errormail'} = 'adminemail';
7749: $default{'packagesmail'} = 'adminemail';
7750: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7751: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7752: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 7753: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7754: foreach my $item (@contacts) {
7755: if ($to{$item} ne $default{$item}) {
7756: $changes{$item} = 1;
1.203 raeburn 7757: }
1.28 raeburn 7758: }
7759: foreach my $type (@mailings) {
7760: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7761:
7762: push(@{$changes{$type}},@{$newsetting{$type}});
7763: }
7764: if ($others{$type} ne '') {
7765: push(@{$changes{$type}},'others');
1.134 raeburn 7766: }
7767: if ($type eq 'helpdeskmail') {
7768: if ($bcc{$type} ne '') {
7769: push(@{$changes{$type}},'bcc');
7770: }
7771: }
1.28 raeburn 7772: }
7773: }
1.203 raeburn 7774: foreach my $item (@toggles) {
7775: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7776: $changes{$item} = 1;
7777: } elsif ((!$env{'form.'.$item}) &&
7778: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7779: $changes{$item} = 1;
7780: }
7781: }
1.28 raeburn 7782: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7783: $dom);
7784: if ($putresult eq 'ok') {
7785: if (keys(%changes) > 0) {
1.205 raeburn 7786: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7787: if (ref($lastactref) eq 'HASH') {
7788: $lastactref->{'domainconfig'} = 1;
7789: }
1.28 raeburn 7790: my ($titles,$short_titles) = &contact_titles();
7791: $resulttext = &mt('Changes made:').'<ul>';
7792: foreach my $item (@contacts) {
7793: if ($changes{$item}) {
7794: $resulttext .= '<li>'.$titles->{$item}.
7795: &mt(' set to: ').
7796: '<span class="LC_cusr_emph">'.
7797: $to{$item}.'</span></li>';
7798: }
7799: }
7800: foreach my $type (@mailings) {
7801: if (ref($changes{$type}) eq 'ARRAY') {
7802: $resulttext .= '<li>'.$titles->{$type}.': ';
7803: my @text;
7804: foreach my $item (@{$newsetting{$type}}) {
7805: push(@text,$short_titles->{$item});
7806: }
7807: if ($others{$type} ne '') {
7808: push(@text,$others{$type});
7809: }
7810: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7811: join(', ',@text).'</span>';
7812: if ($type eq 'helpdeskmail') {
7813: if ($bcc{$type} ne '') {
7814: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
7815: }
7816: }
7817: $resulttext .= '</li>';
1.28 raeburn 7818: }
7819: }
1.203 raeburn 7820: my @offon = ('off','on');
7821: if ($changes{'reporterrors'}) {
7822: $resulttext .= '<li>'.
7823: &mt('E-mail error reports to [_1] set to "'.
7824: $offon[$env{'form.reporterrors'}].'".',
7825: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7826: &mt('LON-CAPA core group - MSU'),600,500)).
7827: '</li>';
7828: }
7829: if ($changes{'reportupdates'}) {
7830: $resulttext .= '<li>'.
7831: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
7832: $offon[$env{'form.reportupdates'}].'".',
7833: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
7834: &mt('LON-CAPA core group - MSU'),600,500)).
7835: '</li>';
7836: }
1.28 raeburn 7837: $resulttext .= '</ul>';
7838: } else {
1.34 raeburn 7839: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 7840: }
7841: } else {
7842: $resulttext = '<span class="LC_error">'.
7843: &mt('An error occurred: [_1].',$putresult).'</span>';
7844: }
7845: return $resulttext;
7846: }
7847:
7848: sub modify_usercreation {
1.27 raeburn 7849: my ($dom,%domconfig) = @_;
1.224 raeburn 7850: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 7851: my $warningmsg;
1.27 raeburn 7852: if (ref($domconfig{'usercreation'}) eq 'HASH') {
7853: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 7854: if ($key eq 'cancreate') {
7855: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
7856: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
7857: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
7858: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
7859: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7860: } else {
7861: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
7862: }
7863: }
7864: }
7865: } elsif ($key eq 'email_rule') {
7866: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
7867: } else {
7868: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
7869: }
1.27 raeburn 7870: }
7871: }
7872: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 7873: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 7874: my @contexts = ('author','course','requestcrs');
1.34 raeburn 7875: foreach my $item(@contexts) {
1.224 raeburn 7876: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 7877: }
1.34 raeburn 7878: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
7879: foreach my $item (@contexts) {
1.224 raeburn 7880: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
7881: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 7882: }
1.27 raeburn 7883: }
1.34 raeburn 7884: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
7885: foreach my $item (@contexts) {
1.43 raeburn 7886: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 7887: if ($cancreate{$item} ne 'any') {
7888: push(@{$changes{'cancreate'}},$item);
7889: }
7890: } else {
7891: if ($cancreate{$item} ne 'none') {
7892: push(@{$changes{'cancreate'}},$item);
7893: }
1.27 raeburn 7894: }
7895: }
7896: } else {
1.43 raeburn 7897: foreach my $item (@contexts) {
1.34 raeburn 7898: push(@{$changes{'cancreate'}},$item);
7899: }
1.27 raeburn 7900: }
1.34 raeburn 7901:
1.27 raeburn 7902: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7903: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7904: if (!grep(/^\Q$type\E$/,@username_rule)) {
7905: push(@{$changes{'username_rule'}},$type);
7906: }
7907: }
7908: foreach my $type (@username_rule) {
7909: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7910: push(@{$changes{'username_rule'}},$type);
7911: }
7912: }
7913: } else {
7914: push(@{$changes{'username_rule'}},@username_rule);
7915: }
7916:
1.32 raeburn 7917: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7918: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7919: if (!grep(/^\Q$type\E$/,@id_rule)) {
7920: push(@{$changes{'id_rule'}},$type);
7921: }
7922: }
7923: foreach my $type (@id_rule) {
7924: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7925: push(@{$changes{'id_rule'}},$type);
7926: }
7927: }
7928: } else {
7929: push(@{$changes{'id_rule'}},@id_rule);
7930: }
7931:
1.43 raeburn 7932: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7933: my @authtypes = ('int','krb4','krb5','loc');
7934: my %authhash;
1.43 raeburn 7935: foreach my $item (@authen_contexts) {
1.28 raeburn 7936: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7937: foreach my $auth (@authtypes) {
7938: if (grep(/^\Q$auth\E$/,@authallowed)) {
7939: $authhash{$item}{$auth} = 1;
7940: } else {
7941: $authhash{$item}{$auth} = 0;
7942: }
7943: }
7944: }
7945: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7946: foreach my $item (@authen_contexts) {
1.28 raeburn 7947: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7948: foreach my $auth (@authtypes) {
7949: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7950: push(@{$changes{'authtypes'}},$item);
7951: last;
7952: }
7953: }
7954: }
7955: }
7956: } else {
1.43 raeburn 7957: foreach my $item (@authen_contexts) {
1.28 raeburn 7958: push(@{$changes{'authtypes'}},$item);
7959: }
7960: }
7961:
1.224 raeburn 7962: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
7963: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
7964: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
7965: $save_usercreate{'id_rule'} = \@id_rule;
7966: $save_usercreate{'username_rule'} = \@username_rule,
7967: $save_usercreate{'authtypes'} = \%authhash;
7968:
1.27 raeburn 7969: my %usercreation_hash = (
1.224 raeburn 7970: usercreation => \%save_usercreate,
7971: );
1.27 raeburn 7972:
7973: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7974: $dom);
1.50 raeburn 7975:
1.224 raeburn 7976: if ($putresult eq 'ok') {
7977: if (keys(%changes) > 0) {
7978: $resulttext = &mt('Changes made:').'<ul>';
7979: if (ref($changes{'cancreate'}) eq 'ARRAY') {
7980: my %lt = &usercreation_types();
7981: foreach my $type (@{$changes{'cancreate'}}) {
7982: my $chgtext = $lt{$type}.', ';
7983: if ($cancreate{$type} eq 'none') {
7984: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7985: } elsif ($cancreate{$type} eq 'any') {
7986: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7987: } elsif ($cancreate{$type} eq 'official') {
7988: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7989: } elsif ($cancreate{$type} eq 'unofficial') {
7990: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7991: }
7992: $resulttext .= '<li>'.$chgtext.'</li>';
7993: }
7994: }
7995: if (ref($changes{'username_rule'}) eq 'ARRAY') {
7996: my ($rules,$ruleorder) =
7997: &Apache::lonnet::inst_userrules($dom,'username');
7998: my $chgtext = '<ul>';
7999: foreach my $type (@username_rule) {
8000: if (ref($rules->{$type}) eq 'HASH') {
8001: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8002: }
8003: }
8004: $chgtext .= '</ul>';
8005: if (@username_rule > 0) {
8006: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8007: } else {
8008: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8009: }
8010: }
8011: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8012: my ($idrules,$idruleorder) =
8013: &Apache::lonnet::inst_userrules($dom,'id');
8014: my $chgtext = '<ul>';
8015: foreach my $type (@id_rule) {
8016: if (ref($idrules->{$type}) eq 'HASH') {
8017: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8018: }
8019: }
8020: $chgtext .= '</ul>';
8021: if (@id_rule > 0) {
8022: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8023: } else {
8024: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8025: }
8026: }
8027: my %authname = &authtype_names();
8028: my %context_title = &context_names();
8029: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8030: my $chgtext = '<ul>';
8031: foreach my $type (@{$changes{'authtypes'}}) {
8032: my @allowed;
8033: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8034: foreach my $auth (@authtypes) {
8035: if ($authhash{$type}{$auth}) {
8036: push(@allowed,$authname{$auth});
8037: }
8038: }
8039: if (@allowed > 0) {
8040: $chgtext .= join(', ',@allowed).'</li>';
8041: } else {
8042: $chgtext .= &mt('none').'</li>';
8043: }
8044: }
8045: $chgtext .= '</ul>';
8046: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8047: $resulttext .= '</li>';
8048: }
8049: $resulttext .= '</ul>';
8050: } else {
8051: $resulttext = &mt('No changes made to user creation settings');
8052: }
8053: } else {
8054: $resulttext = '<span class="LC_error">'.
8055: &mt('An error occurred: [_1]',$putresult).'</span>';
8056: }
8057: if ($warningmsg ne '') {
8058: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8059: }
8060: return $resulttext;
8061: }
8062:
8063: sub modify_selfcreation {
8064: my ($dom,%domconfig) = @_;
8065: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8066: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8067: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8068: if (ref($types) eq 'ARRAY') {
8069: $usertypes->{'default'} = $othertitle;
8070: push(@{$types},'default');
8071: }
1.224 raeburn 8072: #
8073: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8074: #
8075: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8076: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8077: if ($key eq 'cancreate') {
8078: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8079: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8080: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8081: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8082: ($item eq 'emailusername') || ($item eq 'notify')) {
8083: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8084: } else {
8085: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8086: }
8087: }
8088: }
8089: } elsif ($key eq 'email_rule') {
8090: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8091: } else {
8092: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8093: }
8094: }
8095: }
8096: #
8097: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8098: #
8099: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8100: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8101: if ($key eq 'selfcreate') {
8102: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8103: } else {
8104: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8105: }
8106: }
8107: }
8108:
8109: my @contexts = ('selfcreate');
8110: @{$cancreate{'selfcreate'}} = ();
8111: %{$cancreate{'emailusername'}} = ();
8112: @{$cancreate{'statustocreate'}} = ();
1.50 raeburn 8113: my %selfcreatetypes = (
8114: sso => 'users authenticated by institutional single sign on',
8115: login => 'users authenticated by institutional log-in',
1.224 raeburn 8116: email => 'users who provide a valid e-mail address for use as username (automatic creation)',
8117: emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50 raeburn 8118: );
1.224 raeburn 8119: #
8120: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8121: # is permitted.
8122: #
1.228 raeburn 8123: foreach my $item ('login','sso','email') {
1.224 raeburn 8124: if ($item eq 'email') {
8125: if ($env{'form.cancreate_email'} eq 'email') {
8126: push(@{$cancreate{'selfcreate'}},'email');
8127: } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
8128: push(@{$cancreate{'selfcreate'}},'emailapproval');
8129: }
8130: } else {
8131: if ($env{'form.cancreate_'.$item}) {
8132: push(@{$cancreate{'selfcreate'}},$item);
8133: }
8134: }
8135: }
8136: my (@email_rule,%userinfo,%savecaptcha);
8137: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8138: #
1.228 raeburn 8139: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8140: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8141: #
8142: if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
1.228 raeburn 8143: push(@contexts,'emailusername');
8144: if (ref($types) eq 'ARRAY') {
8145: foreach my $type (@{$types}) {
8146: if (ref($infofields) eq 'ARRAY') {
8147: foreach my $field (@{$infofields}) {
8148: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8149: $cancreate{'emailusername'}{$type}{$field} = $1;
8150: }
8151: }
1.224 raeburn 8152: }
8153: }
8154: }
8155: #
8156: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8157: # queued requests for self-creation of account using e-mail address as username
8158: #
8159:
8160: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8161: @approvalnotify = sort(@approvalnotify);
8162: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8163: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8164: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8165: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8166: push(@{$changes{'cancreate'}},'notify');
8167: }
8168: } else {
8169: if ($cancreate{'notify'}{'approval'}) {
8170: push(@{$changes{'cancreate'}},'notify');
8171: }
8172: }
8173: } elsif ($cancreate{'notify'}{'approval'}) {
8174: push(@{$changes{'cancreate'}},'notify');
8175: }
8176:
8177: #
8178: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8179: #
8180: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8181: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8182: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8183: if (@{$curr_usercreation{'email_rule'}} > 0) {
8184: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8185: if (!grep(/^\Q$type\E$/,@email_rule)) {
8186: push(@{$changes{'email_rule'}},$type);
8187: }
8188: }
8189: }
8190: if (@email_rule > 0) {
8191: foreach my $type (@email_rule) {
8192: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8193: push(@{$changes{'email_rule'}},$type);
8194: }
8195: }
8196: }
8197: } elsif (@email_rule > 0) {
8198: push(@{$changes{'email_rule'}},@email_rule);
8199: }
8200: }
8201: #
8202: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
8203: # institutional log-in.
8204: #
8205: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8206: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8207: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8208: ($domdefaults{'auth_def'} eq 'localauth'))) {
8209: $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.').' '.
8210: &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.');
8211: }
8212: }
8213: my @fields = ('lastname','firstname','middlename','generation',
8214: 'permanentemail','id');
8215: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8216: #
8217: # Where usernames may created for institutional log-in and/or institutional single sign on:
8218: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8219: # may self-create accounts
8220: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8221: # which the user may supply, if institutional data is unavailable.
8222: #
8223: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8224: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8225: if (@{$types} > 1) {
1.224 raeburn 8226: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8227: push(@contexts,'statustocreate');
8228: } else {
8229: undef($cancreate{'statustocreate'});
8230: }
8231: foreach my $type (@{$types}) {
8232: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8233: foreach my $field (@fields) {
8234: if (grep(/^\Q$field\E$/,@modifiable)) {
8235: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8236: } else {
8237: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8238: }
8239: }
8240: }
8241: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8242: foreach my $type (@{$types}) {
8243: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8244: foreach my $field (@fields) {
8245: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8246: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8247: push(@{$changes{'selfcreate'}},$type);
8248: last;
8249: }
8250: }
8251: }
8252: }
8253: } else {
8254: foreach my $type (@{$types}) {
8255: push(@{$changes{'selfcreate'}},$type);
8256: }
8257: }
8258: }
8259: }
8260: foreach my $item (@contexts) {
8261: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8262: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8263: if (ref($cancreate{$item}) eq 'ARRAY') {
8264: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8265: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8266: push(@{$changes{'cancreate'}},$item);
8267: }
8268: }
8269: }
8270: }
8271: if (ref($cancreate{$item}) eq 'ARRAY') {
8272: foreach my $type (@{$cancreate{$item}}) {
8273: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8274: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8275: push(@{$changes{'cancreate'}},$item);
8276: }
8277: }
8278: }
8279: }
8280: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8281: if (ref($cancreate{$item}) eq 'HASH') {
8282: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8283: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8284: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8285: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8286: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8287: push(@{$changes{'cancreate'}},$item);
8288: }
8289: }
8290: }
8291: } else {
8292: if (!$cancreate{$item}{$curr}) {
8293: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8294: push(@{$changes{'cancreate'}},$item);
8295: }
1.224 raeburn 8296: }
8297: }
8298: }
8299: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8300: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8301: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8302: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8303: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8304: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8305: push(@{$changes{'cancreate'}},$item);
8306: }
8307: }
8308: } else {
8309: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8310: push(@{$changes{'cancreate'}},$item);
8311: }
8312: }
8313: }
8314: } else {
8315: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8316: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8317: push(@{$changes{'cancreate'}},$item);
8318: }
1.224 raeburn 8319: }
8320: }
8321: }
8322: }
8323: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8324: if (ref($cancreate{$item}) eq 'ARRAY') {
8325: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8326: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8327: push(@{$changes{'cancreate'}},$item);
8328: }
8329: }
8330: } elsif (ref($cancreate{$item}) eq 'HASH') {
8331: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8332: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8333: push(@{$changes{'cancreate'}},$item);
8334: }
8335: }
8336: }
8337: } elsif ($item eq 'emailusername') {
1.228 raeburn 8338: if (ref($cancreate{$item}) eq 'HASH') {
8339: foreach my $type (keys(%{$cancreate{$item}})) {
8340: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8341: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8342: if ($cancreate{$item}{$type}{$field}) {
8343: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8344: push(@{$changes{'cancreate'}},$item);
8345: }
8346: last;
8347: }
8348: }
8349: }
8350: }
1.224 raeburn 8351: }
8352: }
8353: }
8354: #
8355: # Populate %save_usercreate hash with updates to self-creation configuration.
8356: #
8357: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8358: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8359: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8360: if (ref($cancreate{'notify'}) eq 'HASH') {
8361: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8362: }
8363: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8364: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8365: }
8366: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8367: $save_usercreate{'emailrule'} = \@email_rule;
8368:
8369: my %userconfig_hash = (
8370: usercreation => \%save_usercreate,
8371: usermodification => \%save_usermodify,
8372: );
8373: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8374: $dom);
8375: #
8376: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8377: #
1.27 raeburn 8378: if ($putresult eq 'ok') {
8379: if (keys(%changes) > 0) {
8380: $resulttext = &mt('Changes made:').'<ul>';
8381: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 8382: my %lt = &selfcreation_types();
1.34 raeburn 8383: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8384: my $chgtext;
1.45 raeburn 8385: if ($type eq 'selfcreate') {
1.50 raeburn 8386: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 8387: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8388: } else {
1.224 raeburn 8389: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8390: '<ul>';
1.50 raeburn 8391: foreach my $case (@{$cancreate{$type}}) {
8392: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8393: }
8394: $chgtext .= '</ul>';
1.100 raeburn 8395: if (ref($cancreate{$type}) eq 'ARRAY') {
8396: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8397: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8398: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 8399: $chgtext .= '<br />'.
8400: '<span class="LC_warning">'.
8401: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8402: '</span>';
1.100 raeburn 8403: }
8404: }
8405: }
8406: }
1.43 raeburn 8407: }
1.93 raeburn 8408: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8409: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8410: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8411: if (@{$cancreate{'selfcreate'}} > 0) {
8412: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8413: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8414: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8415: $chgtext .= '<br />'.
8416: '<span class="LC_warning">'.
8417: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8418: '</span>';
8419: }
1.96 raeburn 8420: } elsif (ref($usertypes) eq 'HASH') {
8421: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8422: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8423: } else {
8424: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8425: }
8426: $chgtext .= '<ul>';
8427: foreach my $case (@{$cancreate{$type}}) {
8428: if ($case eq 'default') {
8429: $chgtext .= '<li>'.$othertitle.'</li>';
8430: } else {
8431: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8432: }
8433: }
1.100 raeburn 8434: $chgtext .= '</ul>';
8435: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 8436: $chgtext .= '<br /><span class="LC_warning">'.
8437: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8438: '</span>';
1.100 raeburn 8439: }
8440: }
8441: } else {
8442: if (@{$cancreate{$type}} == 0) {
8443: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8444: } else {
8445: $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 8446: }
8447: }
8448: }
1.165 raeburn 8449: } elsif ($type eq 'captcha') {
1.224 raeburn 8450: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 8451: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8452: } else {
8453: my %captchas = &captcha_phrases();
1.224 raeburn 8454: if ($captchas{$savecaptcha{$type}}) {
8455: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 8456: } else {
1.210 raeburn 8457: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 8458: }
8459: }
8460: } elsif ($type eq 'recaptchakeys') {
8461: my ($privkey,$pubkey);
1.224 raeburn 8462: if (ref($savecaptcha{$type}) eq 'HASH') {
8463: $pubkey = $savecaptcha{$type}{'public'};
8464: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 8465: }
8466: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8467: if (!$pubkey) {
8468: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8469: } else {
8470: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8471: }
8472: if (!$privkey) {
8473: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8474: } else {
8475: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8476: }
8477: $chgtext .= '</ul>';
1.224 raeburn 8478: } elsif ($type eq 'emailusername') {
8479: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 8480: if (ref($types) eq 'ARRAY') {
8481: foreach my $type (@{$types}) {
8482: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8483: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8484: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8485: '<ul>';
8486: foreach my $field (@{$infofields}) {
8487: if ($cancreate{'emailusername'}{$type}{$field}) {
8488: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8489: }
8490: }
8491: }
8492: $chgtext .= '</ul>';
8493: } else {
8494: $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 8495: }
8496: }
8497: }
8498: }
8499: } elsif ($type eq 'notify') {
8500: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8501: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8502: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8503: if ($cancreate{'notify'}{'approval'}) {
8504: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8505: }
8506: }
1.43 raeburn 8507: }
1.34 raeburn 8508: }
1.224 raeburn 8509: if ($chgtext) {
8510: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8511: }
8512: }
8513: }
1.43 raeburn 8514: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8515: my ($emailrules,$emailruleorder) =
8516: &Apache::lonnet::inst_userrules($dom,'email');
8517: my $chgtext = '<ul>';
8518: foreach my $type (@email_rule) {
8519: if (ref($emailrules->{$type}) eq 'HASH') {
8520: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8521: }
8522: }
8523: $chgtext .= '</ul>';
8524: if (@email_rule > 0) {
1.224 raeburn 8525: $resulttext .= '<li>'.
8526: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8527: $chgtext.
8528: '</li>';
1.43 raeburn 8529: } else {
1.224 raeburn 8530: $resulttext .= '<li>'.
8531: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8532: '</li>';
1.43 raeburn 8533: }
8534: }
1.224 raeburn 8535: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8536: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8537: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8538: foreach my $type (@{$changes{'selfcreate'}}) {
8539: my $typename = $type;
8540: if (ref($usertypes) eq 'HASH') {
8541: if ($usertypes->{$type} ne '') {
8542: $typename = $usertypes->{$type};
8543: }
8544: }
8545: my @modifiable;
8546: $resulttext .= '<li>'.
8547: &mt('Self-creation of account by users with status: [_1]',
8548: '<span class="LC_cusr_emph">'.$typename.'</span>').
8549: ' - '.&mt('modifiable fields (if institutional data blank): ');
8550: foreach my $field (@fields) {
8551: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8552: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 8553: }
8554: }
1.224 raeburn 8555: if (@modifiable > 0) {
8556: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8557: } else {
1.224 raeburn 8558: $resulttext .= &mt('none');
1.43 raeburn 8559: }
1.224 raeburn 8560: $resulttext .= '</li>';
1.28 raeburn 8561: }
1.224 raeburn 8562: $resulttext .= '</ul></li>';
1.28 raeburn 8563: }
1.27 raeburn 8564: $resulttext .= '</ul>';
8565: } else {
1.224 raeburn 8566: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8567: }
8568: } else {
8569: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8570: &mt('An error occurred: [_1]',$putresult).'</span>';
8571: }
1.43 raeburn 8572: if ($warningmsg ne '') {
8573: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8574: }
1.23 raeburn 8575: return $resulttext;
8576: }
8577:
1.165 raeburn 8578: sub process_captcha {
8579: my ($container,$changes,$newsettings,$current) = @_;
8580: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8581: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8582: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8583: $newsettings->{'captcha'} = 'original';
8584: }
8585: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 8586: if ($container eq 'cancreate') {
1.169 raeburn 8587: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8588: push(@{$changes->{'cancreate'}},'captcha');
8589: } elsif (!defined($changes->{'cancreate'})) {
8590: $changes->{'cancreate'} = ['captcha'];
8591: }
8592: } else {
8593: $changes->{'captcha'} = 1;
1.165 raeburn 8594: }
8595: }
8596: my ($newpub,$newpriv,$currpub,$currpriv);
8597: if ($newsettings->{'captcha'} eq 'recaptcha') {
8598: $newpub = $env{'form.'.$container.'_recaptchapub'};
8599: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 8600: $newpub =~ s/\W//g;
8601: $newpriv =~ s/\W//g;
8602: $newsettings->{'recaptchakeys'} = {
8603: public => $newpub,
8604: private => $newpriv,
8605: };
1.165 raeburn 8606: }
8607: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8608: $currpub = $current->{'recaptchakeys'}{'public'};
8609: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 8610: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8611: $newsettings->{'recaptchakeys'} = {
8612: public => '',
8613: private => '',
8614: }
8615: }
1.165 raeburn 8616: }
8617: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 8618: if ($container eq 'cancreate') {
8619: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8620: push(@{$changes->{'cancreate'}},'recaptchakeys');
8621: } elsif (!defined($changes->{'cancreate'})) {
8622: $changes->{'cancreate'} = ['recaptchakeys'];
8623: }
8624: } else {
1.210 raeburn 8625: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 8626: }
8627: }
8628: return;
8629: }
8630:
1.33 raeburn 8631: sub modify_usermodification {
8632: my ($dom,%domconfig) = @_;
1.224 raeburn 8633: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8634: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8635: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 8636: if ($key eq 'selfcreate') {
8637: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8638: } else {
8639: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8640: }
1.33 raeburn 8641: }
8642: }
1.224 raeburn 8643: my @contexts = ('author','course');
1.33 raeburn 8644: my %context_title = (
8645: author => 'In author context',
8646: course => 'In course context',
8647: );
8648: my @fields = ('lastname','firstname','middlename','generation',
8649: 'permanentemail','id');
8650: my %roles = (
8651: author => ['ca','aa'],
8652: course => ['st','ep','ta','in','cr'],
8653: );
8654: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8655: foreach my $context (@contexts) {
8656: foreach my $role (@{$roles{$context}}) {
8657: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8658: foreach my $item (@fields) {
8659: if (grep(/^\Q$item\E$/,@modifiable)) {
8660: $modifyhash{$context}{$role}{$item} = 1;
8661: } else {
8662: $modifyhash{$context}{$role}{$item} = 0;
8663: }
8664: }
8665: }
8666: if (ref($curr_usermodification{$context}) eq 'HASH') {
8667: foreach my $role (@{$roles{$context}}) {
8668: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8669: foreach my $field (@fields) {
8670: if ($modifyhash{$context}{$role}{$field} ne
8671: $curr_usermodification{$context}{$role}{$field}) {
8672: push(@{$changes{$context}},$role);
8673: last;
8674: }
8675: }
8676: }
8677: }
8678: } else {
8679: foreach my $context (@contexts) {
8680: foreach my $role (@{$roles{$context}}) {
8681: push(@{$changes{$context}},$role);
8682: }
8683: }
8684: }
8685: }
8686: my %usermodification_hash = (
8687: usermodification => \%modifyhash,
8688: );
8689: my $putresult = &Apache::lonnet::put_dom('configuration',
8690: \%usermodification_hash,$dom);
8691: if ($putresult eq 'ok') {
8692: if (keys(%changes) > 0) {
8693: $resulttext = &mt('Changes made: ').'<ul>';
8694: foreach my $context (@contexts) {
8695: if (ref($changes{$context}) eq 'ARRAY') {
8696: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8697: if (ref($changes{$context}) eq 'ARRAY') {
8698: foreach my $role (@{$changes{$context}}) {
8699: my $rolename;
1.224 raeburn 8700: if ($role eq 'cr') {
8701: $rolename = &mt('Custom');
1.33 raeburn 8702: } else {
1.224 raeburn 8703: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8704: }
8705: my @modifiable;
1.224 raeburn 8706: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8707: foreach my $field (@fields) {
8708: if ($modifyhash{$context}{$role}{$field}) {
8709: push(@modifiable,$fieldtitles{$field});
8710: }
8711: }
8712: if (@modifiable > 0) {
8713: $resulttext .= join(', ',@modifiable);
8714: } else {
8715: $resulttext .= &mt('none');
8716: }
8717: $resulttext .= '</li>';
8718: }
8719: $resulttext .= '</ul></li>';
8720: }
8721: }
8722: }
8723: $resulttext .= '</ul>';
8724: } else {
8725: $resulttext = &mt('No changes made to user modification settings');
8726: }
8727: } else {
8728: $resulttext = '<span class="LC_error">'.
8729: &mt('An error occurred: [_1]',$putresult).'</span>';
8730: }
8731: return $resulttext;
8732: }
8733:
1.43 raeburn 8734: sub modify_defaults {
1.212 raeburn 8735: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8736: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 8737: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8738: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8739: my @authtypes = ('internal','krb4','krb5','localauth');
8740: foreach my $item (@items) {
8741: $newvalues{$item} = $env{'form.'.$item};
8742: if ($item eq 'auth_def') {
8743: if ($newvalues{$item} ne '') {
8744: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8745: push(@errors,$item);
8746: }
8747: }
8748: } elsif ($item eq 'lang_def') {
8749: if ($newvalues{$item} ne '') {
8750: if ($newvalues{$item} =~ /^(\w+)/) {
8751: my $langcode = $1;
1.103 raeburn 8752: if ($langcode ne 'x_chef') {
8753: if (code2language($langcode) eq '') {
8754: push(@errors,$item);
8755: }
1.43 raeburn 8756: }
8757: } else {
8758: push(@errors,$item);
8759: }
8760: }
1.54 raeburn 8761: } elsif ($item eq 'timezone_def') {
8762: if ($newvalues{$item} ne '') {
1.62 raeburn 8763: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 8764: push(@errors,$item);
8765: }
8766: }
1.68 raeburn 8767: } elsif ($item eq 'datelocale_def') {
8768: if ($newvalues{$item} ne '') {
8769: my @datelocale_ids = DateTime::Locale->ids();
8770: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
8771: push(@errors,$item);
8772: }
8773: }
1.141 raeburn 8774: } elsif ($item eq 'portal_def') {
8775: if ($newvalues{$item} ne '') {
8776: 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])\/?$/) {
8777: push(@errors,$item);
8778: }
8779: }
1.43 raeburn 8780: }
8781: if (grep(/^\Q$item\E$/,@errors)) {
8782: $newvalues{$item} = $domdefaults{$item};
8783: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
8784: $changes{$item} = 1;
8785: }
1.72 raeburn 8786: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 8787: }
8788: my %defaults_hash = (
1.72 raeburn 8789: defaults => \%newvalues,
8790: );
1.43 raeburn 8791: my $title = &defaults_titles();
8792: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
8793: $dom);
8794: if ($putresult eq 'ok') {
8795: if (keys(%changes) > 0) {
8796: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 8797: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 8798: 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";
8799: foreach my $item (sort(keys(%changes))) {
8800: my $value = $env{'form.'.$item};
8801: if ($value eq '') {
8802: $value = &mt('none');
8803: } elsif ($item eq 'auth_def') {
8804: my %authnames = &authtype_names();
8805: my %shortauth = (
8806: internal => 'int',
8807: krb4 => 'krb4',
8808: krb5 => 'krb5',
8809: localauth => 'loc',
8810: );
8811: $value = $authnames{$shortauth{$value}};
8812: }
8813: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
8814: $mailmsgtext .= "$title->{$item} set to $value\n";
8815: }
8816: $resulttext .= '</ul>';
8817: $mailmsgtext .= "\n";
8818: my $cachetime = 24*60*60;
1.72 raeburn 8819: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8820: if (ref($lastactref) eq 'HASH') {
8821: $lastactref->{'domdefaults'} = 1;
8822: }
1.68 raeburn 8823: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 8824: my $notify = 1;
8825: if (ref($domconfig{'contacts'}) eq 'HASH') {
8826: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
8827: $notify = 0;
8828: }
8829: }
8830: if ($notify) {
8831: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
8832: "LON-CAPA Domain Settings Change - $dom",
8833: $mailmsgtext);
8834: }
1.54 raeburn 8835: }
1.43 raeburn 8836: } else {
1.54 raeburn 8837: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 8838: }
8839: } else {
8840: $resulttext = '<span class="LC_error">'.
8841: &mt('An error occurred: [_1]',$putresult).'</span>';
8842: }
8843: if (@errors > 0) {
8844: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
8845: foreach my $item (@errors) {
8846: $resulttext .= ' "'.$title->{$item}.'",';
8847: }
8848: $resulttext =~ s/,$//;
8849: }
8850: return $resulttext;
8851: }
8852:
1.46 raeburn 8853: sub modify_scantron {
1.205 raeburn 8854: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 8855: my ($resulttext,%confhash,%changes,$errors);
8856: my $custom = 'custom.tab';
8857: my $default = 'default.tab';
8858: my $servadm = $r->dir_config('lonAdmEMail');
8859: my ($configuserok,$author_ok,$switchserver) =
8860: &config_check($dom,$confname,$servadm);
8861: if ($env{'form.scantronformat.filename'} ne '') {
8862: my $error;
8863: if ($configuserok eq 'ok') {
8864: if ($switchserver) {
1.130 raeburn 8865: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 8866: } else {
8867: if ($author_ok eq 'ok') {
8868: my ($result,$scantronurl) =
8869: &publishlogo($r,'upload','scantronformat',$dom,
8870: $confname,'scantron','','',$custom);
8871: if ($result eq 'ok') {
8872: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 8873: $changes{'scantronformat'} = 1;
1.46 raeburn 8874: } else {
8875: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
8876: }
8877: } else {
8878: $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);
8879: }
8880: }
8881: } else {
8882: $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);
8883: }
8884: if ($error) {
8885: &Apache::lonnet::logthis($error);
8886: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8887: }
8888: }
1.48 raeburn 8889: if (ref($domconfig{'scantron'}) eq 'HASH') {
8890: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
8891: if ($env{'form.scantronformat_del'}) {
8892: $confhash{'scantron'}{'scantronformat'} = '';
8893: $changes{'scantronformat'} = 1;
1.46 raeburn 8894: }
8895: }
8896: }
8897: if (keys(%confhash) > 0) {
8898: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
8899: $dom);
8900: if ($putresult eq 'ok') {
8901: if (keys(%changes) > 0) {
1.48 raeburn 8902: if (ref($confhash{'scantron'}) eq 'HASH') {
8903: $resulttext = &mt('Changes made:').'<ul>';
8904: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 8905: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 8906: } else {
1.130 raeburn 8907: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 8908: }
1.48 raeburn 8909: $resulttext .= '</ul>';
8910: } else {
1.130 raeburn 8911: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 8912: }
8913: $resulttext .= '</ul>';
8914: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8915: if (ref($lastactref) eq 'HASH') {
8916: $lastactref->{'domainconfig'} = 1;
8917: }
1.46 raeburn 8918: } else {
1.130 raeburn 8919: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8920: }
8921: } else {
8922: $resulttext = '<span class="LC_error">'.
8923: &mt('An error occurred: [_1]',$putresult).'</span>';
8924: }
8925: } else {
1.130 raeburn 8926: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 8927: }
8928: if ($errors) {
8929: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8930: $errors.'</ul>';
8931: }
8932: return $resulttext;
8933: }
8934:
1.48 raeburn 8935: sub modify_coursecategories {
8936: my ($dom,%domconfig) = @_;
1.57 raeburn 8937: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
8938: $cathash);
1.48 raeburn 8939: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 8940: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 8941: $cathash = $domconfig{'coursecategories'}{'cats'};
8942: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
8943: $changes{'togglecats'} = 1;
8944: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
8945: }
8946: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
8947: $changes{'categorize'} = 1;
8948: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
8949: }
1.120 raeburn 8950: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
8951: $changes{'togglecatscomm'} = 1;
8952: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
8953: }
8954: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
8955: $changes{'categorizecomm'} = 1;
8956: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
8957: }
1.57 raeburn 8958: } else {
8959: $changes{'togglecats'} = 1;
8960: $changes{'categorize'} = 1;
1.124 raeburn 8961: $changes{'togglecatscomm'} = 1;
8962: $changes{'categorizecomm'} = 1;
1.87 raeburn 8963: $domconfig{'coursecategories'} = {
8964: togglecats => $env{'form.togglecats'},
8965: categorize => $env{'form.categorize'},
1.124 raeburn 8966: togglecatscomm => $env{'form.togglecatscomm'},
8967: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 8968: };
1.57 raeburn 8969: }
8970: if (ref($cathash) eq 'HASH') {
8971: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 8972: push (@deletecategory,'instcode::0');
8973: }
1.120 raeburn 8974: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
8975: push(@deletecategory,'communities::0');
8976: }
1.48 raeburn 8977: }
1.57 raeburn 8978: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
8979: if (ref($cathash) eq 'HASH') {
1.48 raeburn 8980: if (@deletecategory > 0) {
8981: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 8982: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 8983: foreach my $item (@deletecategory) {
1.57 raeburn 8984: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
8985: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 8986: $deletions{$item} = 1;
1.57 raeburn 8987: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 8988: }
8989: }
8990: }
1.57 raeburn 8991: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 8992: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 8993: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 8994: $reorderings{$item} = 1;
1.57 raeburn 8995: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 8996: }
8997: if ($env{'form.addcategory_name_'.$item} ne '') {
8998: my $newcat = $env{'form.addcategory_name_'.$item};
8999: my $newdepth = $depth+1;
9000: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9001: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9002: $adds{$newitem} = 1;
9003: }
9004: if ($env{'form.subcat_'.$item} ne '') {
9005: my $newcat = $env{'form.subcat_'.$item};
9006: my $newdepth = $depth+1;
9007: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9008: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9009: $adds{$newitem} = 1;
9010: }
9011: }
9012: }
9013: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9014: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9015: my $newitem = 'instcode::0';
1.57 raeburn 9016: if ($cathash->{$newitem} eq '') {
9017: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9018: $adds{$newitem} = 1;
9019: }
9020: } else {
9021: my $newitem = 'instcode::0';
1.57 raeburn 9022: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9023: $adds{$newitem} = 1;
9024: }
9025: }
1.120 raeburn 9026: if ($env{'form.communities'} eq '1') {
9027: if (ref($cathash) eq 'HASH') {
9028: my $newitem = 'communities::0';
9029: if ($cathash->{$newitem} eq '') {
9030: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9031: $adds{$newitem} = 1;
9032: }
9033: } else {
9034: my $newitem = 'communities::0';
9035: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9036: $adds{$newitem} = 1;
9037: }
9038: }
1.48 raeburn 9039: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9040: if (($env{'form.addcategory_name'} ne 'instcode') &&
9041: ($env{'form.addcategory_name'} ne 'communities')) {
9042: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9043: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9044: $adds{$newitem} = 1;
9045: }
1.48 raeburn 9046: }
1.57 raeburn 9047: my $putresult;
1.48 raeburn 9048: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9049: if (keys(%deletions) > 0) {
9050: foreach my $key (keys(%deletions)) {
9051: if ($predelallitems{$key} ne '') {
9052: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9053: }
9054: }
9055: }
9056: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9057: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9058: if (ref($chkcats[0]) eq 'ARRAY') {
9059: my $depth = 0;
9060: my $chg = 0;
9061: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9062: my $name = $chkcats[0][$i];
9063: my $item;
9064: if ($name eq '') {
9065: $chg ++;
9066: } else {
9067: $item = &escape($name).'::0';
9068: if ($chg) {
1.57 raeburn 9069: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9070: }
9071: $depth ++;
1.57 raeburn 9072: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9073: $depth --;
9074: }
9075: }
9076: }
1.57 raeburn 9077: }
9078: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9079: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9080: if ($putresult eq 'ok') {
1.57 raeburn 9081: my %title = (
1.120 raeburn 9082: togglecats => 'Show/Hide a course in catalog',
9083: categorize => 'Assign a category to a course',
9084: togglecatscomm => 'Show/Hide a community in catalog',
9085: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9086: );
9087: my %level = (
1.120 raeburn 9088: dom => 'set in Domain ("Modify Course/Community")',
9089: crs => 'set in Course ("Course Configuration")',
9090: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 9091: );
1.48 raeburn 9092: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9093: if ($changes{'togglecats'}) {
9094: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9095: }
9096: if ($changes{'categorize'}) {
9097: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9098: }
1.120 raeburn 9099: if ($changes{'togglecatscomm'}) {
9100: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9101: }
9102: if ($changes{'categorizecomm'}) {
9103: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9104: }
1.57 raeburn 9105: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9106: my $cathash;
9107: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9108: $cathash = $domconfig{'coursecategories'}{'cats'};
9109: } else {
9110: $cathash = {};
9111: }
9112: my (@cats,@trails,%allitems);
9113: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9114: if (keys(%deletions) > 0) {
9115: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9116: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9117: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9118: }
9119: $resulttext .= '</ul></li>';
9120: }
9121: if (keys(%reorderings) > 0) {
9122: my %sort_by_trail;
9123: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9124: foreach my $key (keys(%reorderings)) {
9125: if ($allitems{$key} ne '') {
9126: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9127: }
1.48 raeburn 9128: }
1.57 raeburn 9129: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9130: $resulttext .= '<li>'.$trails[$trail].'</li>';
9131: }
9132: $resulttext .= '</ul></li>';
1.48 raeburn 9133: }
1.57 raeburn 9134: if (keys(%adds) > 0) {
9135: my %sort_by_trail;
9136: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9137: foreach my $key (keys(%adds)) {
9138: if ($allitems{$key} ne '') {
9139: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9140: }
9141: }
9142: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9143: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9144: }
1.57 raeburn 9145: $resulttext .= '</ul></li>';
1.48 raeburn 9146: }
9147: }
9148: $resulttext .= '</ul>';
9149: } else {
9150: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9151: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9152: }
9153: } else {
1.120 raeburn 9154: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9155: }
9156: return $resulttext;
9157: }
9158:
1.69 raeburn 9159: sub modify_serverstatuses {
9160: my ($dom,%domconfig) = @_;
9161: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9162: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9163: %currserverstatus = %{$domconfig{'serverstatuses'}};
9164: }
9165: my @pages = &serverstatus_pages();
9166: foreach my $type (@pages) {
9167: $newserverstatus{$type}{'namedusers'} = '';
9168: $newserverstatus{$type}{'machines'} = '';
9169: if (defined($env{'form.'.$type.'_namedusers'})) {
9170: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9171: my @okusers;
9172: foreach my $user (@users) {
9173: my ($uname,$udom) = split(/:/,$user);
9174: if (($udom =~ /^$match_domain$/) &&
9175: (&Apache::lonnet::domain($udom)) &&
9176: ($uname =~ /^$match_username$/)) {
9177: if (!grep(/^\Q$user\E/,@okusers)) {
9178: push(@okusers,$user);
9179: }
9180: }
9181: }
9182: if (@okusers > 0) {
9183: @okusers = sort(@okusers);
9184: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9185: }
9186: }
9187: if (defined($env{'form.'.$type.'_machines'})) {
9188: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9189: my @okmachines;
9190: foreach my $ip (@machines) {
9191: my @parts = split(/\./,$ip);
9192: next if (@parts < 4);
9193: my $badip = 0;
9194: for (my $i=0; $i<4; $i++) {
9195: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9196: $badip = 1;
9197: last;
9198: }
9199: }
9200: if (!$badip) {
9201: push(@okmachines,$ip);
9202: }
9203: }
9204: @okmachines = sort(@okmachines);
9205: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9206: }
9207: }
9208: my %serverstatushash = (
9209: serverstatuses => \%newserverstatus,
9210: );
9211: foreach my $type (@pages) {
1.83 raeburn 9212: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9213: my (@current,@new);
1.83 raeburn 9214: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9215: if ($currserverstatus{$type}{$setting} ne '') {
9216: @current = split(/,/,$currserverstatus{$type}{$setting});
9217: }
9218: }
9219: if ($newserverstatus{$type}{$setting} ne '') {
9220: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9221: }
9222: if (@current > 0) {
9223: if (@new > 0) {
9224: foreach my $item (@current) {
9225: if (!grep(/^\Q$item\E$/,@new)) {
9226: $changes{$type}{$setting} = 1;
1.82 raeburn 9227: last;
9228: }
9229: }
1.84 raeburn 9230: foreach my $item (@new) {
9231: if (!grep(/^\Q$item\E$/,@current)) {
9232: $changes{$type}{$setting} = 1;
9233: last;
1.82 raeburn 9234: }
9235: }
9236: } else {
1.83 raeburn 9237: $changes{$type}{$setting} = 1;
1.69 raeburn 9238: }
1.83 raeburn 9239: } elsif (@new > 0) {
9240: $changes{$type}{$setting} = 1;
1.69 raeburn 9241: }
9242: }
9243: }
9244: if (keys(%changes) > 0) {
1.81 raeburn 9245: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9246: my $putresult = &Apache::lonnet::put_dom('configuration',
9247: \%serverstatushash,$dom);
9248: if ($putresult eq 'ok') {
9249: $resulttext .= &mt('Changes made:').'<ul>';
9250: foreach my $type (@pages) {
1.84 raeburn 9251: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9252: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9253: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9254: if ($newserverstatus{$type}{'namedusers'} eq '') {
9255: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9256: } else {
9257: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9258: }
1.84 raeburn 9259: }
9260: if ($changes{$type}{'machines'}) {
1.69 raeburn 9261: if ($newserverstatus{$type}{'machines'} eq '') {
9262: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9263: } else {
9264: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9265: }
9266:
9267: }
9268: $resulttext .= '</ul></li>';
9269: }
9270: }
9271: $resulttext .= '</ul>';
9272: } else {
9273: $resulttext = '<span class="LC_error">'.
9274: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9275:
9276: }
9277: } else {
9278: $resulttext = &mt('No changes made to access to server status pages');
9279: }
9280: return $resulttext;
9281: }
9282:
1.118 jms 9283: sub modify_helpsettings {
1.122 jms 9284: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 9285: my ($resulttext,$errors,%changes,%helphash);
9286: my %defaultchecked = ('submitbugs' => 'on');
9287: my @offon = ('off','on');
1.118 jms 9288: my @toggles = ('submitbugs');
9289: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9290: foreach my $item (@toggles) {
1.166 raeburn 9291: if ($defaultchecked{$item} eq 'on') {
9292: if ($domconfig{'helpsettings'}{$item} eq '') {
9293: if ($env{'form.'.$item} eq '0') {
9294: $changes{$item} = 1;
9295: }
9296: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9297: $changes{$item} = 1;
9298: }
9299: } elsif ($defaultchecked{$item} eq 'off') {
9300: if ($domconfig{'helpsettings'}{$item} eq '') {
9301: if ($env{'form.'.$item} eq '1') {
9302: $changes{$item} = 1;
9303: }
9304: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9305: $changes{$item} = 1;
9306: }
9307: }
1.210 raeburn 9308: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 9309: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
9310: }
9311: }
1.118 jms 9312: }
1.123 jms 9313: my $putresult;
9314: if (keys(%changes) > 0) {
1.166 raeburn 9315: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 9316: if ($putresult eq 'ok') {
1.166 raeburn 9317: $resulttext = &mt('Changes made:').'<ul>';
9318: foreach my $item (sort(keys(%changes))) {
9319: if ($item eq 'submitbugs') {
9320: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9321: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9322: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9323: }
9324: }
9325: $resulttext .= '</ul>';
9326: } else {
9327: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 9328: $errors .= '<li><span class="LC_error">'.
9329: &mt('An error occurred storing the settings: [_1]',
9330: $putresult).'</span></li>';
1.166 raeburn 9331: }
1.118 jms 9332: }
9333: if ($errors) {
1.168 raeburn 9334: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9335: $errors.'</ul>';
9336: }
9337: return $resulttext;
9338: }
9339:
1.121 raeburn 9340: sub modify_coursedefaults {
1.212 raeburn 9341: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9342: my ($resulttext,$errors,%changes,%defaultshash);
9343: my %defaultchecked = ('canuse_pdfforms' => 'off');
9344: my @toggles = ('canuse_pdfforms');
1.198 raeburn 9345: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 9346: 'uploadquota_community','uploadquota_textbook');
9347: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 9348: my %staticdefaults = (
9349: anonsurvey_threshold => 10,
9350: uploadquota => 500,
9351: );
1.121 raeburn 9352:
9353: $defaultshash{'coursedefaults'} = {};
9354:
9355: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9356: if ($domconfig{'coursedefaults'} eq '') {
9357: $domconfig{'coursedefaults'} = {};
9358: }
9359: }
9360:
9361: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9362: foreach my $item (@toggles) {
9363: if ($defaultchecked{$item} eq 'on') {
9364: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9365: ($env{'form.'.$item} eq '0')) {
9366: $changes{$item} = 1;
1.192 raeburn 9367: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9368: $changes{$item} = 1;
9369: }
9370: } elsif ($defaultchecked{$item} eq 'off') {
9371: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9372: ($env{'form.'.$item} eq '1')) {
9373: $changes{$item} = 1;
9374: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9375: $changes{$item} = 1;
9376: }
9377: }
9378: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9379: }
1.198 raeburn 9380: foreach my $item (@numbers) {
9381: my ($currdef,$newdef);
1.208 raeburn 9382: $newdef = $env{'form.'.$item};
1.198 raeburn 9383: if ($item eq 'anonsurvey_threshold') {
9384: $currdef = $domconfig{'coursedefaults'}{$item};
9385: $newdef =~ s/\D//g;
9386: if ($newdef eq '' || $newdef < 1) {
9387: $newdef = 1;
9388: }
9389: $defaultshash{'coursedefaults'}{$item} = $newdef;
9390: } else {
9391: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9392: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9393: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9394: }
9395: $newdef =~ s/[^\w.\-]//g;
9396: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9397: }
9398: if ($currdef ne $newdef) {
9399: my $staticdef;
9400: if ($item eq 'anonsurvey_threshold') {
9401: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9402: $changes{$item} = 1;
9403: }
9404: } else {
9405: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9406: $changes{'uploadquota'} = 1;
9407: }
9408: }
1.139 raeburn 9409: }
9410: }
1.231 raeburn 9411:
1.192 raeburn 9412: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 9413: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 9414: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 9415: $unofficialcreds =~ s/[^\d.]+//g;
9416: my $textbookcreds = $env{'form.textbook_credits'};
9417: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 9418: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9419: ($env{'form.coursecredits'} eq '1')) {
9420: $changes{'coursecredits'} = 1;
9421: } else {
9422: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 9423: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9424: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 9425: $changes{'coursecredits'} = 1;
9426: }
9427: }
9428: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9429: official => $officialcreds,
9430: unofficial => $unofficialcreds,
1.216 raeburn 9431: textbook => $textbookcreds,
1.192 raeburn 9432: }
1.121 raeburn 9433: }
9434: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9435: $dom);
9436: if ($putresult eq 'ok') {
9437: if (keys(%changes) > 0) {
1.213 raeburn 9438: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 9439: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 9440: ($changes{'uploadquota'})) {
1.192 raeburn 9441: if ($changes{'canuse_pdfforms'}) {
9442: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9443: }
9444: if ($changes{'coursecredits'}) {
9445: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9446: $domdefaults{'officialcredits'} =
9447: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9448: $domdefaults{'unofficialcredits'} =
9449: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 9450: $domdefaults{'textbookcredits'} =
9451: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 9452: }
9453: }
1.198 raeburn 9454: if ($changes{'uploadquota'}) {
9455: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9456: foreach my $type (@types) {
9457: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9458: }
9459: }
9460: }
1.121 raeburn 9461: my $cachetime = 24*60*60;
9462: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9463: if (ref($lastactref) eq 'HASH') {
9464: $lastactref->{'domdefaults'} = 1;
9465: }
1.121 raeburn 9466: }
9467: $resulttext = &mt('Changes made:').'<ul>';
9468: foreach my $item (sort(keys(%changes))) {
9469: if ($item eq 'canuse_pdfforms') {
9470: if ($env{'form.'.$item} eq '1') {
9471: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9472: } else {
9473: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9474: }
1.139 raeburn 9475: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 9476: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 9477: } elsif ($item eq 'uploadquota') {
9478: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9479: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9480: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9481: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 9482: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9483:
1.198 raeburn 9484: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9485: '</ul>'.
9486: '</li>';
9487: } else {
9488: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9489: }
1.192 raeburn 9490: } elsif ($item eq 'coursecredits') {
9491: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9492: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 9493: ($domdefaults{'unofficialcredits'} eq '') &&
9494: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 9495: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9496: } else {
9497: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9498: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9499: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 9500: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 9501: '</ul>'.
9502: '</li>';
9503: }
9504: } else {
9505: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9506: }
1.140 raeburn 9507: }
1.121 raeburn 9508: }
9509: $resulttext .= '</ul>';
9510: } else {
9511: $resulttext = &mt('No changes made to course defaults');
9512: }
9513: } else {
9514: $resulttext = '<span class="LC_error">'.
9515: &mt('An error occurred: [_1]',$putresult).'</span>';
9516: }
9517: return $resulttext;
9518: }
9519:
1.231 raeburn 9520: sub modify_selfenrollment {
9521: my ($dom,$lastactref,%domconfig) = @_;
9522: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
9523: my @types = ('official','unofficial','community','textbook');
9524: my %titles = &tool_titles();
1.232 raeburn 9525: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
9526: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 9527: $ordered{'default'} = ['types','registered','approval','limit'];
9528:
9529: my (%roles,%shown,%toplevel);
9530: $roles{'0'} = &Apache::lonnet::plaintext('dc');
9531:
9532: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
9533: if ($domconfig{'selfenrollment'} eq '') {
9534: $domconfig{'selfenrollment'} = {};
9535: }
9536: }
9537: %toplevel = (
9538: admin => 'Configuration Rights',
9539: default => 'Default settings',
9540: validation => 'Validation of self-enrollment requests',
9541: );
1.233 raeburn 9542: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 9543:
9544: if (ref($ordered{'admin'}) eq 'ARRAY') {
9545: foreach my $item (@{$ordered{'admin'}}) {
9546: foreach my $type (@types) {
9547: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
9548: $selfenrollhash{'admin'}{$type}{$item} = 1;
9549: } else {
9550: $selfenrollhash{'admin'}{$type}{$item} = 0;
9551: }
9552: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
9553: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
9554: if ($selfenrollhash{'admin'}{$type}{$item} ne
9555: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
9556: push(@{$changes{'admin'}{$type}},$item);
9557: }
9558: } else {
9559: if (!$selfenrollhash{'admin'}{$type}{$item}) {
9560: push(@{$changes{'admin'}{$type}},$item);
9561: }
9562: }
9563: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
9564: push(@{$changes{'admin'}{$type}},$item);
9565: }
9566: }
9567: }
9568: }
9569:
9570: foreach my $item (@{$ordered{'default'}}) {
9571: foreach my $type (@types) {
9572: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
9573: if ($item eq 'types') {
9574: unless (($value eq 'all') || ($value eq 'dom')) {
9575: $value = '';
9576: }
9577: } elsif ($item eq 'registered') {
9578: unless ($value eq '1') {
9579: $value = 0;
9580: }
9581: } elsif ($item eq 'approval') {
9582: unless ($value =~ /^[012]$/) {
9583: $value = 0;
9584: }
9585: } else {
9586: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9587: $value = 'none';
9588: }
9589: }
9590: $selfenrollhash{'default'}{$type}{$item} = $value;
9591: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
9592: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9593: if ($selfenrollhash{'default'}{$type}{$item} ne
9594: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
9595: push(@{$changes{'default'}{$type}},$item);
9596: }
9597: } else {
9598: push(@{$changes{'default'}{$type}},$item);
9599: }
9600: } else {
9601: push(@{$changes{'default'}{$type}},$item);
9602: }
9603: if ($item eq 'limit') {
9604: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9605: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
9606: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
9607: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
9608: }
9609: } else {
9610: $selfenrollhash{'default'}{$type}{'cap'} = '';
9611: }
9612: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9613: if ($selfenrollhash{'default'}{$type}{'cap'} ne
9614: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
9615: push(@{$changes{'default'}{$type}},'cap');
9616: }
9617: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
9618: push(@{$changes{'default'}{$type}},'cap');
9619: }
9620: }
9621: }
9622: }
9623:
9624: foreach my $item (@{$itemsref}) {
9625: if ($item eq 'fields') {
9626: my @changed;
9627: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
9628: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
9629: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
9630: }
9631: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
9632: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
9633: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
9634: $domconfig{'selfenrollment'}{'validation'}{$item});
9635: } else {
9636: @changed = @{$selfenrollhash{'validation'}{$item}};
9637: }
9638: } else {
9639: @changed = @{$selfenrollhash{'validation'}{$item}};
9640: }
9641: if (@changed) {
9642: if ($selfenrollhash{'validation'}{$item}) {
9643: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
9644: } else {
9645: $changes{'validation'}{$item} = &mt('None');
9646: }
9647: }
9648: } else {
9649: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
9650: if ($item eq 'markup') {
9651: if ($env{'form.selfenroll_validation_'.$item}) {
9652: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9653: }
9654: }
9655: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
9656: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
9657: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
9658: }
9659: }
9660: }
9661: }
9662:
9663: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
9664: $dom);
9665: if ($putresult eq 'ok') {
9666: if (keys(%changes) > 0) {
9667: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9668: $resulttext = &mt('Changes made:').'<ul>';
9669: foreach my $key ('admin','default','validation') {
9670: if (ref($changes{$key}) eq 'HASH') {
9671: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
9672: if ($key eq 'validation') {
9673: foreach my $item (@{$itemsref}) {
9674: if (exists($changes{$key}{$item})) {
9675: if ($item eq 'markup') {
9676: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
9677: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
9678: } else {
9679: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
9680: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
9681: }
9682: }
9683: }
9684: } else {
9685: foreach my $type (@types) {
9686: if ($type eq 'community') {
9687: $roles{'1'} = &mt('Community personnel');
9688: } else {
9689: $roles{'1'} = &mt('Course personnel');
9690: }
9691: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 9692: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
9693: if ($key eq 'admin') {
9694: my @mgrdc = ();
9695: if (ref($ordered{$key}) eq 'ARRAY') {
9696: foreach my $item (@{$ordered{'admin'}}) {
9697: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
9698: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
9699: push(@mgrdc,$item);
9700: }
9701: }
9702: }
9703: if (@mgrdc) {
9704: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
9705: } else {
9706: delete($domdefaults{$type.'selfenrolladmdc'});
9707: }
9708: }
9709: } else {
9710: if (ref($ordered{$key}) eq 'ARRAY') {
9711: foreach my $item (@{$ordered{$key}}) {
9712: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
9713: $domdefaults{$type.'selfenroll'.$item} =
9714: $selfenrollhash{$key}{$type}{$item};
9715: }
9716: }
9717: }
9718: }
9719: }
1.231 raeburn 9720: $resulttext .= '<li>'.$titles{$type}.'<ul>';
9721: foreach my $item (@{$ordered{$key}}) {
9722: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
9723: $resulttext .= '<li>';
9724: if ($key eq 'admin') {
9725: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
9726: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
9727: } else {
9728: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
9729: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
9730: }
9731: $resulttext .= '</li>';
9732: }
9733: }
9734: $resulttext .= '</ul></li>';
9735: }
9736: }
9737: $resulttext .= '</ul></li>';
9738: }
9739: }
1.232 raeburn 9740: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
9741: my $cachetime = 24*60*60;
9742: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
9743: if (ref($lastactref) eq 'HASH') {
9744: $lastactref->{'domdefaults'} = 1;
9745: }
9746: }
1.231 raeburn 9747: }
9748: $resulttext .= '</ul>';
9749: } else {
9750: $resulttext = &mt('No changes made to self-enrollment settings');
9751: }
9752: } else {
9753: $resulttext = '<span class="LC_error">'.
9754: &mt('An error occurred: [_1]',$putresult).'</span>';
9755: }
9756: return $resulttext;
9757: }
9758:
1.137 raeburn 9759: sub modify_usersessions {
1.212 raeburn 9760: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 9761: my @hostingtypes = ('version','excludedomain','includedomain');
9762: my @offloadtypes = ('primary','default');
9763: my %types = (
9764: remote => \@hostingtypes,
9765: hosted => \@hostingtypes,
9766: spares => \@offloadtypes,
9767: );
9768: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 9769: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 9770: my (%by_ip,%by_location,@intdoms);
9771: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
9772: my @locations = sort(keys(%by_location));
1.137 raeburn 9773: my (%defaultshash,%changes);
9774: foreach my $prefix (@prefixes) {
9775: $defaultshash{'usersessions'}{$prefix} = {};
9776: }
1.212 raeburn 9777: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 9778: my $resulttext;
1.138 raeburn 9779: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 9780: foreach my $prefix (@prefixes) {
1.145 raeburn 9781: next if ($prefix eq 'spares');
9782: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 9783: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
9784: if ($type eq 'version') {
9785: my $value = $env{'form.'.$prefix.'_'.$type};
9786: my $okvalue;
9787: if ($value ne '') {
9788: if (grep(/^\Q$value\E$/,@lcversions)) {
9789: $okvalue = $value;
9790: }
9791: }
9792: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9793: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9794: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
9795: if ($inuse == 0) {
9796: $changes{$prefix}{$type} = 1;
9797: } else {
9798: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
9799: $changes{$prefix}{$type} = 1;
9800: }
9801: if ($okvalue ne '') {
9802: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9803: }
9804: }
9805: } else {
9806: if (($inuse == 1) && ($okvalue ne '')) {
9807: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9808: $changes{$prefix}{$type} = 1;
9809: }
9810: }
9811: } else {
9812: if (($inuse == 1) && ($okvalue ne '')) {
9813: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9814: $changes{$prefix}{$type} = 1;
9815: }
9816: }
9817: } else {
9818: if (($inuse == 1) && ($okvalue ne '')) {
9819: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
9820: $changes{$prefix}{$type} = 1;
9821: }
9822: }
9823: } else {
9824: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
9825: my @okvals;
9826: foreach my $val (@vals) {
1.138 raeburn 9827: if ($val =~ /:/) {
9828: my @items = split(/:/,$val);
9829: foreach my $item (@items) {
9830: if (ref($by_location{$item}) eq 'ARRAY') {
9831: push(@okvals,$item);
9832: }
9833: }
9834: } else {
9835: if (ref($by_location{$val}) eq 'ARRAY') {
9836: push(@okvals,$val);
9837: }
1.137 raeburn 9838: }
9839: }
9840: @okvals = sort(@okvals);
9841: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9842: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
9843: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9844: if ($inuse == 0) {
9845: $changes{$prefix}{$type} = 1;
9846: } else {
9847: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9848: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
9849: if (@changed > 0) {
9850: $changes{$prefix}{$type} = 1;
9851: }
9852: }
9853: } else {
9854: if ($inuse == 1) {
9855: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9856: $changes{$prefix}{$type} = 1;
9857: }
9858: }
9859: } else {
9860: if ($inuse == 1) {
9861: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9862: $changes{$prefix}{$type} = 1;
9863: }
9864: }
9865: } else {
9866: if ($inuse == 1) {
9867: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
9868: $changes{$prefix}{$type} = 1;
9869: }
9870: }
9871: }
9872: }
9873: }
1.145 raeburn 9874:
9875: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 9876: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 9877: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
9878: my $savespares;
9879:
9880: foreach my $lonhost (sort(keys(%servers))) {
9881: my $serverhomeID =
9882: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 9883: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 9884: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
9885: my %spareschg;
9886: foreach my $type (@{$types{'spares'}}) {
9887: my @okspares;
9888: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
9889: foreach my $server (@checked) {
1.152 raeburn 9890: if (&Apache::lonnet::hostname($server) ne '') {
9891: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
9892: unless (grep(/^\Q$server\E$/,@okspares)) {
9893: push(@okspares,$server);
9894: }
1.145 raeburn 9895: }
9896: }
9897: }
9898: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
9899: my $newspare;
1.152 raeburn 9900: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
9901: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 9902: $newspare = $new;
9903: }
9904: }
1.152 raeburn 9905: my @spares;
9906: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
9907: @spares = sort(@okspares,$newspare);
9908: } else {
9909: @spares = sort(@okspares);
9910: }
9911: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 9912: if (ref($spareid{$lonhost}) eq 'HASH') {
9913: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 9914: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 9915: if (@diffs > 0) {
9916: $spareschg{$type} = 1;
9917: }
9918: }
9919: }
9920: }
9921: if (keys(%spareschg) > 0) {
9922: $changes{'spares'}{$lonhost} = \%spareschg;
9923: }
9924: }
9925:
9926: if (ref($domconfig{'usersessions'}) eq 'HASH') {
9927: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
9928: if (ref($changes{'spares'}) eq 'HASH') {
9929: if (keys(%{$changes{'spares'}}) > 0) {
9930: $savespares = 1;
9931: }
9932: }
9933: } else {
9934: $savespares = 1;
9935: }
9936: }
9937:
1.147 raeburn 9938: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
9939: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 9940: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9941: $dom);
9942: if ($putresult eq 'ok') {
9943: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9944: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
9945: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
9946: }
9947: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
9948: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
9949: }
9950: }
9951: my $cachetime = 24*60*60;
9952: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9953: if (ref($lastactref) eq 'HASH') {
9954: $lastactref->{'domdefaults'} = 1;
9955: }
1.147 raeburn 9956: if (keys(%changes) > 0) {
9957: my %lt = &usersession_titles();
9958: $resulttext = &mt('Changes made:').'<ul>';
9959: foreach my $prefix (@prefixes) {
9960: if (ref($changes{$prefix}) eq 'HASH') {
9961: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
9962: if ($prefix eq 'spares') {
9963: if (ref($changes{$prefix}) eq 'HASH') {
9964: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
9965: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 9966: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 9967: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
9968: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 9969: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
9970: foreach my $type (@{$types{$prefix}}) {
9971: if ($changes{$prefix}{$lonhost}{$type}) {
9972: my $offloadto = &mt('None');
9973: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
9974: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
9975: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
9976: }
1.145 raeburn 9977: }
1.147 raeburn 9978: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 9979: }
1.137 raeburn 9980: }
9981: }
1.147 raeburn 9982: $resulttext .= '</li>';
1.137 raeburn 9983: }
9984: }
1.147 raeburn 9985: } else {
9986: foreach my $type (@{$types{$prefix}}) {
9987: if (defined($changes{$prefix}{$type})) {
9988: my $newvalue;
9989: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
9990: if (ref($defaultshash{'usersessions'}{$prefix})) {
9991: if ($type eq 'version') {
9992: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
9993: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
9994: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
9995: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
9996: }
1.145 raeburn 9997: }
9998: }
9999: }
1.147 raeburn 10000: if ($newvalue eq '') {
10001: if ($type eq 'version') {
10002: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10003: } else {
10004: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10005: }
1.145 raeburn 10006: } else {
1.147 raeburn 10007: if ($type eq 'version') {
10008: $newvalue .= ' '.&mt('(or later)');
10009: }
10010: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10011: }
1.137 raeburn 10012: }
10013: }
10014: }
1.147 raeburn 10015: $resulttext .= '</ul>';
1.137 raeburn 10016: }
10017: }
1.147 raeburn 10018: $resulttext .= '</ul>';
10019: } else {
10020: $resulttext = $nochgmsg;
1.137 raeburn 10021: }
10022: } else {
10023: $resulttext = '<span class="LC_error">'.
10024: &mt('An error occurred: [_1]',$putresult).'</span>';
10025: }
10026: } else {
1.147 raeburn 10027: $resulttext = $nochgmsg;
1.137 raeburn 10028: }
10029: return $resulttext;
10030: }
10031:
1.150 raeburn 10032: sub modify_loadbalancing {
10033: my ($dom,%domconfig) = @_;
10034: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10035: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10036: my ($othertitle,$usertypes,$types) =
10037: &Apache::loncommon::sorted_inst_types($dom);
10038: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10039: my @sparestypes = ('primary','default');
10040: my %typetitles = &sparestype_titles();
10041: my $resulttext;
1.171 raeburn 10042: my (%currbalancer,%currtargets,%currrules,%existing);
10043: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10044: %existing = %{$domconfig{'loadbalancing'}};
10045: }
10046: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10047: \%currtargets,\%currrules);
10048: my ($saveloadbalancing,%defaultshash,%changes);
10049: my ($alltypes,$othertypes,$titles) =
10050: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10051: my %ruletitles = &offloadtype_text();
10052: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10053: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10054: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10055: if ($balancer eq '') {
10056: next;
10057: }
1.210 raeburn 10058: if (!exists($servers{$balancer})) {
1.171 raeburn 10059: if (exists($currbalancer{$balancer})) {
10060: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10061: }
1.171 raeburn 10062: next;
10063: }
10064: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10065: push(@{$changes{'delete'}},$balancer);
10066: next;
10067: }
10068: if (!exists($currbalancer{$balancer})) {
10069: push(@{$changes{'add'}},$balancer);
10070: }
10071: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10072: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10073: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10074: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10075: $saveloadbalancing = 1;
10076: }
10077: foreach my $sparetype (@sparestypes) {
10078: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10079: my @offloadto;
10080: foreach my $target (@targets) {
10081: if (($servers{$target}) && ($target ne $balancer)) {
10082: if ($sparetype eq 'default') {
10083: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10084: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10085: }
10086: }
1.171 raeburn 10087: unless(grep(/^\Q$target\E$/,@offloadto)) {
10088: push(@offloadto,$target);
10089: }
1.150 raeburn 10090: }
1.171 raeburn 10091: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10092: }
10093: }
1.171 raeburn 10094: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10095: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10096: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10097: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10098: if (@targetdiffs > 0) {
1.171 raeburn 10099: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10100: }
1.171 raeburn 10101: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10102: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10103: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10104: }
10105: }
10106: }
10107: } else {
1.171 raeburn 10108: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10109: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10110: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10111: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10112: $changes{'curr'}{$balancer}{'targets'} = 1;
10113: }
1.150 raeburn 10114: }
10115: }
1.210 raeburn 10116: }
1.150 raeburn 10117: }
10118: my $ishomedom;
1.171 raeburn 10119: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10120: $ishomedom = 1;
1.150 raeburn 10121: }
10122: if (ref($alltypes) eq 'ARRAY') {
10123: foreach my $type (@{$alltypes}) {
10124: my $rule;
1.210 raeburn 10125: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10126: (!$ishomedom)) {
1.171 raeburn 10127: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10128: }
10129: if ($rule eq 'specific') {
10130: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10131: }
1.171 raeburn 10132: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10133: if (ref($currrules{$balancer}) eq 'HASH') {
10134: if ($rule ne $currrules{$balancer}{$type}) {
10135: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10136: }
10137: } elsif ($rule ne '') {
1.171 raeburn 10138: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10139: }
10140: }
10141: }
1.171 raeburn 10142: }
10143: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10144: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10145: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10146: $defaultshash{'loadbalancing'} = {};
10147: }
10148: my $putresult = &Apache::lonnet::put_dom('configuration',
10149: \%defaultshash,$dom);
10150: if ($putresult eq 'ok') {
10151: if (keys(%changes) > 0) {
10152: if (ref($changes{'delete'}) eq 'ARRAY') {
10153: foreach my $balancer (sort(@{$changes{'delete'}})) {
10154: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 10155: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10156: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10157: }
1.171 raeburn 10158: }
10159: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10160: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10161: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10162: }
10163: }
10164: if (ref($changes{'curr'}) eq 'HASH') {
10165: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10166: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10167: if ($changes{'curr'}{$balancer}{'targets'}) {
10168: my %offloadstr;
10169: foreach my $sparetype (@sparestypes) {
10170: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10171: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10172: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10173: }
10174: }
1.150 raeburn 10175: }
1.171 raeburn 10176: if (keys(%offloadstr) == 0) {
10177: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10178: } else {
1.171 raeburn 10179: my $showoffload;
10180: foreach my $sparetype (@sparestypes) {
10181: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10182: if (defined($offloadstr{$sparetype})) {
10183: $showoffload .= $offloadstr{$sparetype};
10184: } else {
10185: $showoffload .= &mt('None');
10186: }
10187: $showoffload .= (' 'x3);
10188: }
10189: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10190: }
10191: }
10192: }
1.171 raeburn 10193: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10194: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10195: foreach my $type (@{$alltypes}) {
10196: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10197: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10198: my $balancetext;
10199: if ($rule eq '') {
10200: $balancetext = $ruletitles{'default'};
1.209 raeburn 10201: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10202: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 10203: $balancetext = $ruletitles{$rule};
10204: } else {
10205: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10206: }
1.210 raeburn 10207: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10208: }
10209: }
10210: }
10211: }
1.215 raeburn 10212: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211 raeburn 10213: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10214: }
1.171 raeburn 10215: }
10216: if ($resulttext ne '') {
10217: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10218: } else {
10219: $resulttext = $nochgmsg;
10220: }
10221: } else {
1.171 raeburn 10222: $resulttext = $nochgmsg;
1.150 raeburn 10223: }
10224: } else {
1.171 raeburn 10225: $resulttext = '<span class="LC_error">'.
10226: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10227: }
10228: } else {
1.171 raeburn 10229: $resulttext = $nochgmsg;
1.150 raeburn 10230: }
10231: return $resulttext;
10232: }
10233:
1.48 raeburn 10234: sub recurse_check {
10235: my ($chkcats,$categories,$depth,$name) = @_;
10236: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10237: my $chg = 0;
10238: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10239: my $category = $chkcats->[$depth]{$name}[$j];
10240: my $item;
10241: if ($category eq '') {
10242: $chg ++;
10243: } else {
10244: my $deeper = $depth + 1;
10245: $item = &escape($category).':'.&escape($name).':'.$depth;
10246: if ($chg) {
10247: $categories->{$item} -= $chg;
10248: }
10249: &recurse_check($chkcats,$categories,$deeper,$category);
10250: $deeper --;
10251: }
10252: }
10253: }
10254: return;
10255: }
10256:
10257: sub recurse_cat_deletes {
10258: my ($item,$coursecategories,$deletions) = @_;
10259: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10260: my $subdepth = $depth + 1;
10261: if (ref($coursecategories) eq 'HASH') {
10262: foreach my $subitem (keys(%{$coursecategories})) {
10263: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10264: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10265: delete($coursecategories->{$subitem});
10266: $deletions->{$subitem} = 1;
10267: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 10268: }
1.48 raeburn 10269: }
10270: }
10271: return;
10272: }
10273:
1.125 raeburn 10274: sub get_active_dcs {
10275: my ($dom) = @_;
1.191 raeburn 10276: my $now = time;
10277: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10278: my %domcoords;
10279: my $numdcs = 0;
10280: foreach my $server (keys(%dompersonnel)) {
10281: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10282: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 10283: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10284: }
10285: }
10286: return %domcoords;
10287: }
10288:
10289: sub active_dc_picker {
1.191 raeburn 10290: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 ! raeburn 10291: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 10292: my @domcoord = keys(%domcoords);
10293: if (keys(%currhash)) {
10294: foreach my $dc (keys(%currhash)) {
10295: unless (exists($domcoords{$dc})) {
10296: push(@domcoord,$dc);
10297: }
10298: }
10299: }
10300: @domcoord = sort(@domcoord);
1.210 raeburn 10301: my $numdcs = scalar(@domcoord);
1.191 raeburn 10302: my $rows = 0;
10303: my $table;
1.125 raeburn 10304: if ($numdcs > 1) {
1.191 raeburn 10305: $table = '<table>';
10306: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10307: my $rem = $i%($numinrow);
10308: if ($rem == 0) {
10309: if ($i > 0) {
1.191 raeburn 10310: $table .= '</tr>';
1.125 raeburn 10311: }
1.191 raeburn 10312: $table .= '<tr>';
10313: $rows ++;
1.125 raeburn 10314: }
1.191 raeburn 10315: my $check = '';
10316: if ($inputtype eq 'radio') {
10317: if (keys(%currhash) == 0) {
10318: if (!$i) {
10319: $check = ' checked="checked"';
10320: }
10321: } elsif (exists($currhash{$domcoord[$i]})) {
10322: $check = ' checked="checked"';
10323: }
10324: } else {
10325: if (exists($currhash{$domcoord[$i]})) {
10326: $check = ' checked="checked"';
1.125 raeburn 10327: }
10328: }
1.191 raeburn 10329: if ($i == @domcoord - 1) {
1.125 raeburn 10330: my $colsleft = $numinrow - $rem;
10331: if ($colsleft > 1) {
1.191 raeburn 10332: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10333: } else {
1.191 raeburn 10334: $table .= '<td class="LC_left_item">';
1.125 raeburn 10335: }
10336: } else {
1.191 raeburn 10337: $table .= '<td class="LC_left_item">';
10338: }
10339: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10340: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10341: $table .= '<span class="LC_nobreak"><label>'.
10342: '<input type="'.$inputtype.'" name="'.$name.'"'.
10343: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10344: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 10345: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 10346: }
1.219 raeburn 10347: $table .= '</label></span></td>';
1.191 raeburn 10348: }
10349: $table .= '</tr></table>';
10350: } elsif ($numdcs == 1) {
1.219 raeburn 10351: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10352: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 10353: if ($inputtype eq 'radio') {
1.219 raeburn 10354: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10355: if ($user ne $dcname.':'.$dcdom) {
10356: $table .= ' ('.$dcname.':'.$dcdom.')';
10357: }
1.191 raeburn 10358: } else {
10359: my $check;
10360: if (exists($currhash{$domcoord[0]})) {
10361: $check = ' checked="checked"';
1.125 raeburn 10362: }
1.219 raeburn 10363: $table .= '<span class="LC_nobreak"><label>'.
10364: '<input type="checkbox" name="'.$name.'" '.
10365: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10366: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 10367: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 10368: }
1.220 raeburn 10369: $table .= '</label></span>';
1.191 raeburn 10370: $rows ++;
1.125 raeburn 10371: }
10372: }
1.191 raeburn 10373: return ($numdcs,$table,$rows);
1.125 raeburn 10374: }
10375:
1.137 raeburn 10376: sub usersession_titles {
10377: return &Apache::lonlocal::texthash(
10378: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10379: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10380: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10381: version => 'LON-CAPA version requirement',
1.138 raeburn 10382: excludedomain => 'Allow all, but exclude specific domains',
10383: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10384: primary => 'Primary (checked first)',
1.154 raeburn 10385: default => 'Default',
1.137 raeburn 10386: );
10387: }
10388:
1.152 raeburn 10389: sub id_for_thisdom {
10390: my (%servers) = @_;
10391: my %altids;
10392: foreach my $server (keys(%servers)) {
10393: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10394: if ($serverhome ne $server) {
10395: $altids{$serverhome} = $server;
10396: }
10397: }
10398: return %altids;
10399: }
10400:
1.150 raeburn 10401: sub count_servers {
10402: my ($currbalancer,%servers) = @_;
10403: my (@spares,$numspares);
10404: foreach my $lonhost (sort(keys(%servers))) {
10405: next if ($currbalancer eq $lonhost);
10406: push(@spares,$lonhost);
10407: }
10408: if ($currbalancer) {
10409: $numspares = scalar(@spares);
10410: } else {
10411: $numspares = scalar(@spares) - 1;
10412: }
10413: return ($numspares,@spares);
10414: }
10415:
10416: sub lonbalance_targets_js {
1.171 raeburn 10417: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 10418: my $select = &mt('Select');
10419: my ($alltargets,$allishome,$allinsttypes,@alltypes);
10420: if (ref($servers) eq 'HASH') {
10421: $alltargets = join("','",sort(keys(%{$servers})));
10422: my @homedoms;
10423: foreach my $server (sort(keys(%{$servers}))) {
10424: if (&Apache::lonnet::host_domain($server) eq $dom) {
10425: push(@homedoms,'1');
10426: } else {
10427: push(@homedoms,'0');
10428: }
10429: }
10430: $allishome = join("','",@homedoms);
10431: }
10432: if (ref($types) eq 'ARRAY') {
10433: if (@{$types} > 0) {
10434: @alltypes = @{$types};
10435: }
10436: }
10437: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
10438: $allinsttypes = join("','",@alltypes);
1.171 raeburn 10439: my (%currbalancer,%currtargets,%currrules,%existing);
10440: if (ref($settings) eq 'HASH') {
10441: %existing = %{$settings};
10442: }
10443: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
10444: \%currtargets,\%currrules);
1.210 raeburn 10445: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 10446: return <<"END";
10447:
10448: <script type="text/javascript">
10449: // <![CDATA[
10450:
1.171 raeburn 10451: currBalancers = new Array('$balancers');
10452:
10453: function toggleTargets(balnum) {
10454: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10455: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
10456: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
10457: var prevbalancer = prevhostitem.value;
10458: var baltotal = document.getElementById('loadbalancing_total').value;
10459: prevhostitem.value = balancer;
10460: if (prevbalancer != '') {
10461: var prevIdx = currBalancers.indexOf(prevbalancer);
10462: if (prevIdx != -1) {
10463: currBalancers.splice(prevIdx,1);
10464: }
10465: }
1.150 raeburn 10466: if (balancer == '') {
1.171 raeburn 10467: hideSpares(balnum);
1.150 raeburn 10468: } else {
1.171 raeburn 10469: var currIdx = currBalancers.indexOf(balancer);
10470: if (currIdx == -1) {
10471: currBalancers.push(balancer);
10472: }
1.150 raeburn 10473: var homedoms = new Array('$allishome');
1.171 raeburn 10474: var ishomedom = homedoms[lonhostitem.selectedIndex];
10475: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 10476: }
1.171 raeburn 10477: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 10478: return;
10479: }
10480:
1.171 raeburn 10481: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 10482: var alltargets = new Array('$alltargets');
10483: var insttypes = new Array('$allinsttypes');
1.151 raeburn 10484: var offloadtypes = new Array('primary','default');
10485:
1.171 raeburn 10486: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
10487: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 10488:
1.151 raeburn 10489: for (var i=0; i<offloadtypes.length; i++) {
10490: var count = 0;
10491: for (var j=0; j<alltargets.length; j++) {
10492: if (alltargets[j] != balancer) {
1.171 raeburn 10493: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
10494: item.value = alltargets[j];
10495: item.style.textAlign='left';
10496: item.style.textFace='normal';
10497: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
10498: if (currBalancers.indexOf(alltargets[j]) == -1) {
10499: item.disabled = '';
10500: } else {
10501: item.disabled = 'disabled';
10502: item.checked = false;
10503: }
1.151 raeburn 10504: count ++;
10505: }
1.150 raeburn 10506: }
10507: }
1.151 raeburn 10508: for (var k=0; k<insttypes.length; k++) {
10509: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 10510: if (ishomedom == 1) {
1.171 raeburn 10511: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10512: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10513: } else {
1.171 raeburn 10514: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10515: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 10516: }
10517: } else {
1.171 raeburn 10518: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10519: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10520: }
1.151 raeburn 10521: if ((insttypes[k] != '_LC_external') &&
10522: ((insttypes[k] != '_LC_internetdom') ||
10523: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 10524: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
10525: item.options.length = 0;
10526: item.options[0] = new Option("","",true,true);
1.210 raeburn 10527: var idx = 0;
1.151 raeburn 10528: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 10529: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
10530: idx ++;
10531: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 10532: }
10533: }
10534: }
10535: }
10536: return;
10537: }
10538:
1.171 raeburn 10539: function hideSpares(balnum) {
1.150 raeburn 10540: var alltargets = new Array('$alltargets');
10541: var insttypes = new Array('$allinsttypes');
10542: var offloadtypes = new Array('primary','default');
10543:
1.171 raeburn 10544: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
10545: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 10546:
10547: var total = alltargets.length - 1;
10548: for (var i=0; i<offloadtypes; i++) {
10549: for (var j=0; j<total; j++) {
1.171 raeburn 10550: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
10551: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
10552: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 10553: }
1.150 raeburn 10554: }
10555: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 10556: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10557: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 10558: if (insttypes[k] != '_LC_external') {
1.171 raeburn 10559: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
10560: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 10561: }
10562: }
10563: return;
10564: }
10565:
1.171 raeburn 10566: function checkOffloads(item,balnum,type) {
1.150 raeburn 10567: var alltargets = new Array('$alltargets');
10568: var offloadtypes = new Array('primary','default');
10569: if (item.checked) {
10570: var total = alltargets.length - 1;
10571: var other;
10572: if (type == offloadtypes[0]) {
1.151 raeburn 10573: other = offloadtypes[1];
1.150 raeburn 10574: } else {
1.151 raeburn 10575: other = offloadtypes[0];
1.150 raeburn 10576: }
10577: for (var i=0; i<total; i++) {
1.171 raeburn 10578: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 10579: if (server == item.value) {
1.171 raeburn 10580: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
10581: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 10582: }
10583: }
10584: }
10585: }
10586: return;
10587: }
10588:
1.171 raeburn 10589: function singleServerToggle(balnum,type) {
10590: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 10591: if (offloadtoSelIdx == 0) {
1.171 raeburn 10592: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
10593: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10594:
10595: } else {
1.171 raeburn 10596: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
10597: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 10598: }
10599: return;
10600: }
10601:
1.171 raeburn 10602: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 10603: if (type == '_LC_external') {
1.171 raeburn 10604: return;
1.150 raeburn 10605: }
1.171 raeburn 10606: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 10607: for (var i=0; i<typesRules.length; i++) {
10608: if (formname.elements[typesRules[i]].checked) {
10609: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 10610: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
10611: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10612: } else {
1.171 raeburn 10613: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10614: }
10615: }
10616: }
10617: return;
10618: }
10619:
10620: function balancerDeleteChange(balnum) {
10621: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10622: var baltotal = document.getElementById('loadbalancing_total').value;
10623: var addtarget;
10624: var removetarget;
10625: var action = 'delete';
10626: if (document.getElementById('loadbalancing_delete_'+balnum)) {
10627: var lonhost = hostitem.value;
10628: var currIdx = currBalancers.indexOf(lonhost);
10629: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
10630: if (currIdx != -1) {
10631: currBalancers.splice(currIdx,1);
10632: }
10633: addtarget = lonhost;
10634: } else {
10635: if (currIdx == -1) {
10636: currBalancers.push(lonhost);
10637: }
10638: removetarget = lonhost;
10639: action = 'undelete';
10640: }
10641: balancerChange(balnum,baltotal,action,addtarget,removetarget);
10642: }
10643: return;
10644: }
10645:
10646: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
10647: if (baltotal > 1) {
10648: var offloadtypes = new Array('primary','default');
10649: var alltargets = new Array('$alltargets');
10650: var insttypes = new Array('$allinsttypes');
10651: for (var i=0; i<baltotal; i++) {
10652: if (i != balnum) {
10653: for (var j=0; j<offloadtypes.length; j++) {
10654: var total = alltargets.length - 1;
10655: for (var k=0; k<total; k++) {
10656: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
10657: var server = serveritem.value;
10658: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10659: if (server == addtarget) {
10660: serveritem.disabled = '';
10661: }
10662: }
10663: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10664: if (server == removetarget) {
10665: serveritem.disabled = 'disabled';
10666: serveritem.checked = false;
10667: }
10668: }
10669: }
10670: }
10671: for (var j=0; j<insttypes.length; j++) {
10672: if (insttypes[j] != '_LC_external') {
10673: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
10674: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
10675: var currSel = singleserver.selectedIndex;
10676: var currVal = singleserver.options[currSel].value;
10677: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
10678: var numoptions = singleserver.options.length;
10679: var needsnew = 1;
10680: for (var k=0; k<numoptions; k++) {
10681: if (singleserver.options[k] == addtarget) {
10682: needsnew = 0;
10683: break;
10684: }
10685: }
10686: if (needsnew == 1) {
10687: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
10688: }
10689: }
10690: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
10691: singleserver.options.length = 0;
10692: if ((currVal) && (currVal != removetarget)) {
10693: singleserver.options[0] = new Option("","",false,false);
10694: } else {
10695: singleserver.options[0] = new Option("","",true,true);
10696: }
10697: var idx = 0;
10698: for (var m=0; m<alltargets.length; m++) {
10699: if (currBalancers.indexOf(alltargets[m]) == -1) {
10700: idx ++;
10701: if (currVal == alltargets[m]) {
10702: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
10703: } else {
10704: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
10705: }
10706: }
10707: }
10708: }
10709: }
10710: }
10711: }
1.150 raeburn 10712: }
10713: }
10714: }
10715: return;
10716: }
10717:
1.152 raeburn 10718: // ]]>
10719: </script>
10720:
10721: END
10722: }
10723:
10724: sub new_spares_js {
10725: my @sparestypes = ('primary','default');
10726: my $types = join("','",@sparestypes);
10727: my $select = &mt('Select');
10728: return <<"END";
10729:
10730: <script type="text/javascript">
10731: // <![CDATA[
10732:
10733: function updateNewSpares(formname,lonhost) {
10734: var types = new Array('$types');
10735: var include = new Array();
10736: var exclude = new Array();
10737: for (var i=0; i<types.length; i++) {
10738: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
10739: for (var j=0; j<spareboxes.length; j++) {
10740: if (formname.elements[spareboxes[j]].checked) {
10741: exclude.push(formname.elements[spareboxes[j]].value);
10742: } else {
10743: include.push(formname.elements[spareboxes[j]].value);
10744: }
10745: }
10746: }
10747: for (var i=0; i<types.length; i++) {
10748: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
10749: var selIdx = newSpare.selectedIndex;
10750: var currnew = newSpare.options[selIdx].value;
10751: var okSpares = new Array();
10752: for (var j=0; j<newSpare.options.length; j++) {
10753: var possible = newSpare.options[j].value;
10754: if (possible != '') {
10755: if (exclude.indexOf(possible) == -1) {
10756: okSpares.push(possible);
10757: } else {
10758: if (currnew == possible) {
10759: selIdx = 0;
10760: }
10761: }
10762: }
10763: }
10764: for (var k=0; k<include.length; k++) {
10765: if (okSpares.indexOf(include[k]) == -1) {
10766: okSpares.push(include[k]);
10767: }
10768: }
10769: okSpares.sort();
10770: newSpare.options.length = 0;
10771: if (selIdx == 0) {
10772: newSpare.options[0] = new Option("$select","",true,true);
10773: } else {
10774: newSpare.options[0] = new Option("$select","",false,false);
10775: }
10776: for (var m=0; m<okSpares.length; m++) {
10777: var idx = m+1;
10778: var selThis = 0;
10779: if (selIdx != 0) {
10780: if (okSpares[m] == currnew) {
10781: selThis = 1;
10782: }
10783: }
10784: if (selThis == 1) {
10785: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
10786: } else {
10787: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
10788: }
10789: }
10790: }
10791: return;
10792: }
10793:
10794: function checkNewSpares(lonhost,type) {
10795: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
10796: var chosen = newSpare.options[newSpare.selectedIndex].value;
10797: if (chosen != '') {
10798: var othertype;
10799: var othernewSpare;
10800: if (type == 'primary') {
10801: othernewSpare = document.getElementById('newspare_default_'+lonhost);
10802: }
10803: if (type == 'default') {
10804: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
10805: }
10806: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
10807: othernewSpare.selectedIndex = 0;
10808: }
10809: }
10810: return;
10811: }
10812:
10813: // ]]>
10814: </script>
10815:
10816: END
10817:
10818: }
10819:
10820: sub common_domprefs_js {
10821: return <<"END";
10822:
10823: <script type="text/javascript">
10824: // <![CDATA[
10825:
1.150 raeburn 10826: function getIndicesByName(formname,item) {
1.152 raeburn 10827: var group = new Array();
1.150 raeburn 10828: for (var i=0;i<formname.elements.length;i++) {
10829: if (formname.elements[i].name == item) {
1.152 raeburn 10830: group.push(formname.elements[i].id);
1.150 raeburn 10831: }
10832: }
1.152 raeburn 10833: return group;
1.150 raeburn 10834: }
10835:
10836: // ]]>
10837: </script>
10838:
10839: END
1.152 raeburn 10840:
1.150 raeburn 10841: }
10842:
1.165 raeburn 10843: sub recaptcha_js {
10844: my %lt = &captcha_phrases();
10845: return <<"END";
10846:
10847: <script type="text/javascript">
10848: // <![CDATA[
10849:
10850: function updateCaptcha(caller,context) {
10851: var privitem;
10852: var pubitem;
10853: var privtext;
10854: var pubtext;
10855: if (document.getElementById(context+'_recaptchapub')) {
10856: pubitem = document.getElementById(context+'_recaptchapub');
10857: } else {
10858: return;
10859: }
10860: if (document.getElementById(context+'_recaptchapriv')) {
10861: privitem = document.getElementById(context+'_recaptchapriv');
10862: } else {
10863: return;
10864: }
10865: if (document.getElementById(context+'_recaptchapubtxt')) {
10866: pubtext = document.getElementById(context+'_recaptchapubtxt');
10867: } else {
10868: return;
10869: }
10870: if (document.getElementById(context+'_recaptchaprivtxt')) {
10871: privtext = document.getElementById(context+'_recaptchaprivtxt');
10872: } else {
10873: return;
10874: }
10875: if (caller.checked) {
10876: if (caller.value == 'recaptcha') {
10877: pubitem.type = 'text';
10878: privitem.type = 'text';
10879: pubitem.size = '40';
10880: privitem.size = '40';
10881: pubtext.innerHTML = "$lt{'pub'}";
10882: privtext.innerHTML = "$lt{'priv'}";
10883: } else {
10884: pubitem.type = 'hidden';
10885: privitem.type = 'hidden';
10886: pubtext.innerHTML = '';
10887: privtext.innerHTML = '';
10888: }
10889: }
10890: return;
10891: }
10892:
10893: // ]]>
10894: </script>
10895:
10896: END
10897:
10898: }
10899:
1.192 raeburn 10900: sub credits_js {
10901: return <<"END";
10902:
10903: <script type="text/javascript">
10904: // <![CDATA[
10905:
10906: function toggleCredits(domForm) {
10907: if (document.getElementById('credits')) {
10908: creditsitem = document.getElementById('credits');
10909: var creditsLength = domForm.coursecredits.length;
10910: if (creditsLength) {
10911: var currval;
10912: for (var i=0; i<creditsLength; i++) {
10913: if (domForm.coursecredits[i].checked) {
10914: currval = domForm.coursecredits[i].value;
10915: }
10916: }
10917: if (currval == 1) {
10918: creditsitem.style.display = 'block';
10919: } else {
10920: creditsitem.style.display = 'none';
10921: }
10922: }
10923: }
10924: return;
10925: }
10926:
10927: // ]]>
10928: </script>
10929:
10930: END
10931:
10932: }
10933:
1.165 raeburn 10934: sub captcha_phrases {
10935: return &Apache::lonlocal::texthash (
10936: priv => 'Private key',
10937: pub => 'Public key',
10938: original => 'original (CAPTCHA)',
10939: recaptcha => 'successor (ReCAPTCHA)',
10940: notused => 'unused',
10941: );
10942: }
10943:
1.205 raeburn 10944: sub devalidate_remote_domconfs {
1.212 raeburn 10945: my ($dom,$cachekeys) = @_;
10946: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 10947: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10948: my %thismachine;
10949: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 10950: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 10951: if (keys(%servers) > 1) {
10952: foreach my $server (keys(%servers)) {
10953: next if ($thismachine{$server});
1.212 raeburn 10954: my @cached;
10955: foreach my $name (@posscached) {
10956: if ($cachekeys->{$name}) {
10957: push(@cached,&escape($name).':'.&escape($dom));
10958: }
10959: }
10960: if (@cached) {
10961: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
10962: }
1.205 raeburn 10963: }
10964: }
10965: return;
10966: }
10967:
1.3 raeburn 10968: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>