Annotation of loncom/interface/domainprefs.pm, revision 1.102.2.12
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.102.2.12! raeburn 4: # $Id: domainprefs.pm,v 1.102.2.11 2010/03/11 02:51:44 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
48: for use by individuals affliated with the institution. Accordingly, each domain
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
89: number of rows displayed on the page, and $action is the context (either quotas
90: or requestcourses).
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,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
1.102.2.2 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
1.102.2.2 raeburn 119: approval
1.101 raeburn 120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
143: - course requests will be processed autoatically up to a limit of
144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
174: sub handler {
175: my $r=shift;
176: if ($r->header_only) {
177: &Apache::loncommon::content_type($r,'text/html');
178: $r->send_http_header;
179: return OK;
180: }
181:
1.91 raeburn 182: my $context = 'domain';
1.1 raeburn 183: my $dom = $env{'request.role.domain'};
1.5 albertel 184: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 185: if (&Apache::lonnet::allowed('mau',$dom)) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: } else {
189: $env{'user.error.msg'}=
190: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
191: return HTTP_NOT_ACCEPTABLE;
192: }
193: &Apache::lonhtmlcommon::clear_breadcrumbs();
194: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 195: ['phase','actions']);
1.30 raeburn 196: my $phase = 'pickactions';
1.3 raeburn 197: if ( exists($env{'form.phase'}) ) {
198: $phase = $env{'form.phase'};
199: }
200: my %domconfig =
1.6 raeburn 201: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.102.2.9 raeburn 202: 'quotas','autoenroll','autoupdate','autocreate',
203: 'directorysrch','usercreation','usermodification',
204: 'contacts','defaults','scantron','coursecategories',
205: 'serverstatuses','requestcourses','coursedefaults'],$dom);
1.43 raeburn 206: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.102.2.9 raeburn 207: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 208: 'usercreation','usermodification','scantron',
1.102.2.7 raeburn 209: 'requestcourses','coursecategories','serverstatuses',
210: 'coursedefaults');
1.30 raeburn 211: my %prefs = (
212: 'rolecolors' =>
213: { text => 'Default color schemes',
1.67 raeburn 214: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 215: header => [{col1 => 'Student Settings',
216: col2 => '',},
217: {col1 => 'Coordinator Settings',
218: col2 => '',},
219: {col1 => 'Author Settings',
220: col2 => '',},
221: {col1 => 'Administrator Settings',
222: col2 => '',}],
223: },
224: 'login' =>
225: { text => 'Log-in page options',
1.67 raeburn 226: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 227: header => [{col1 => 'Item',
228: col2 => '',}],
229: },
1.43 raeburn 230: 'defaults' =>
1.54 raeburn 231: { text => 'Default authentication/language/timezone',
1.67 raeburn 232: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 233: header => [{col1 => 'Setting',
234: col2 => 'Value'}],
235: },
1.30 raeburn 236: 'quotas' =>
1.102.2.12! raeburn 237: { text => 'User blogs, personal information pages, portfolios',
1.67 raeburn 238: help => 'Domain_Configuration_Quotas',
1.77 raeburn 239: header => [{col1 => 'User affiliation',
1.72 raeburn 240: col2 => 'Available tools',
241: col3 => 'Portfolio quota',}],
1.30 raeburn 242: },
243: 'autoenroll' =>
244: { text => 'Auto-enrollment settings',
1.67 raeburn 245: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 246: header => [{col1 => 'Configuration setting',
247: col2 => 'Value(s)'}],
248: },
249: 'autoupdate' =>
250: { text => 'Auto-update settings',
1.67 raeburn 251: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 252: header => [{col1 => 'Setting',
253: col2 => 'Value',},
1.102.2.12! raeburn 254: {col1 => 'Setting',
! 255: col2 => 'Affiliation'},
1.43 raeburn 256: {col1 => 'User population',
1.102.2.12! raeburn 257: col2 => 'Updateable user data'}],
1.30 raeburn 258: },
1.102.2.9 raeburn 259: 'autocreate' =>
260: { text => 'Auto-course creation settings',
261: help => 'Domain_Configuration_Auto_Creation',
262: header => [{col1 => 'Configuration Setting',
263: col2 => 'Value',}],
264: },
1.30 raeburn 265: 'directorysrch' =>
266: { text => 'Institutional directory searches',
1.67 raeburn 267: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 268: header => [{col1 => 'Setting',
269: col2 => 'Value',}],
270: },
271: 'contacts' =>
272: { text => 'Contact Information',
1.67 raeburn 273: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 274: header => [{col1 => 'Setting',
275: col2 => 'Value',}],
276: },
277:
278: 'usercreation' =>
279: { text => 'User creation',
1.67 raeburn 280: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 281: header => [{col1 => 'Format rule type',
282: col2 => 'Format rules in force'},
1.34 raeburn 283: {col1 => 'User account creation',
284: col2 => 'Usernames which may be created',},
1.30 raeburn 285: {col1 => 'Context',
1.43 raeburn 286: col2 => 'Assignable authentication types'}],
1.30 raeburn 287: },
1.69 raeburn 288: 'usermodification' =>
1.33 raeburn 289: { text => 'User modification',
1.67 raeburn 290: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 291: header => [{col1 => 'Target user has role',
292: col2 => 'User information updateable in author context'},
293: {col1 => 'Target user has role',
1.63 raeburn 294: col2 => 'User information updateable in course context'},
295: {col1 => "Status of user",
296: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 297: },
1.69 raeburn 298: 'scantron' =>
1.95 www 299: { text => 'Bubblesheet format file',
1.67 raeburn 300: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 301: header => [ {col1 => 'Item',
302: col2 => '',
303: }],
304: },
1.86 raeburn 305: 'requestcourses' =>
306: {text => 'Request creation of courses',
307: help => 'Domain_Configuration_Request_Courses',
308: header => [{col1 => 'User affiliation',
1.102 raeburn 309: col2 => 'Availability/Processing of requests',},
310: {col1 => 'Setting',
311: col2 => 'Value'}],
1.86 raeburn 312: },
1.69 raeburn 313: 'coursecategories' =>
1.102.2.6 raeburn 314: { text => 'Cataloging of courses/communities',
1.67 raeburn 315: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 316: header => [{col1 => 'Category settings',
1.57 raeburn 317: col2 => '',},
318: {col1 => 'Categories',
319: col2 => '',
320: }],
1.69 raeburn 321: },
322: 'serverstatuses' =>
1.77 raeburn 323: {text => 'Access to server status pages',
1.69 raeburn 324: help => 'Domain_Configuration_Server_Status',
325: header => [{col1 => 'Status Page',
326: col2 => 'Other named users',
327: col3 => 'Specific IPs',
328: }],
329: },
1.102.2.7 raeburn 330: 'coursedefaults' =>
331: {text => 'Course/Community defaults',
332: help => 'Domain_Configuration_Course_Defaults',
333: header => [{col1 => 'Setting',
334: col2 => 'Value',}],
335: },
1.3 raeburn 336: );
1.102.2.10 raeburn 337: my %servers = &dom_servers($dom);
338: if (keys(%servers) > 1) {
339: $prefs{'login'} = { text => 'Log-in page options',
340: help => 'Domain_Configuration_Login_Page',
341: header => [{col1 => 'Log-in Service',
342: col2 => 'Server Setting',},
343: {col1 => 'Log-in Page Items',
344: col2 => ''}],
345: };
346: }
1.6 raeburn 347: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 348: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 349: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 350: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.102.2.12! raeburn 351: text=>"Settings to display/modify"});
1.9 raeburn 352: my $confname = $dom.'-domainconfig';
1.3 raeburn 353: if ($phase eq 'process') {
1.91 raeburn 354: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 355: } elsif ($phase eq 'display') {
1.91 raeburn 356: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
1.1 raeburn 357: } else {
1.21 raeburn 358: if (keys(%domconfig) == 0) {
359: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 360: my @ids=&Apache::lonnet::current_machine_ids();
361: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 362: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 363: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 364: my $custom_img_count = 0;
365: foreach my $img (@loginimages) {
366: if ($designhash{$dom.'.login.'.$img} ne '') {
367: $custom_img_count ++;
368: }
369: }
370: foreach my $role (@roles) {
371: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
372: $custom_img_count ++;
373: }
374: }
375: if ($custom_img_count > 0) {
1.94 raeburn 376: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 377: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 378: $r->print(
379: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
380: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
381: &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 />'.
382: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
383: if ($switch_server) {
1.30 raeburn 384: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 385: }
1.91 raeburn 386: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 387: return OK;
388: }
389: }
390: }
1.91 raeburn 391: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 392: }
393: return OK;
394: }
395:
396: sub process_changes {
1.92 raeburn 397: my ($r,$dom,$confname,$action,$roles,$values) = @_;
398: my %domconfig;
399: if (ref($values) eq 'HASH') {
400: %domconfig = %{$values};
401: }
1.3 raeburn 402: my $output;
403: if ($action eq 'login') {
1.9 raeburn 404: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 405: } elsif ($action eq 'rolecolors') {
1.9 raeburn 406: $output = &modify_rolecolors($r,$dom,$confname,$roles,
407: %domconfig);
1.3 raeburn 408: } elsif ($action eq 'quotas') {
1.86 raeburn 409: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 410: } elsif ($action eq 'autoenroll') {
411: $output = &modify_autoenroll($dom,%domconfig);
412: } elsif ($action eq 'autoupdate') {
413: $output = &modify_autoupdate($dom,%domconfig);
1.102.2.9 raeburn 414: } elsif ($action eq 'autocreate') {
415: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 416: } elsif ($action eq 'directorysrch') {
417: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 418: } elsif ($action eq 'usercreation') {
1.28 raeburn 419: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 420: } elsif ($action eq 'usermodification') {
421: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 422: } elsif ($action eq 'contacts') {
423: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 424: } elsif ($action eq 'defaults') {
425: $output = &modify_defaults($dom,$r);
1.46 raeburn 426: } elsif ($action eq 'scantron') {
1.48 raeburn 427: $output = &modify_scantron($r,$dom,$confname,%domconfig);
428: } elsif ($action eq 'coursecategories') {
429: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 430: } elsif ($action eq 'serverstatuses') {
431: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 432: } elsif ($action eq 'requestcourses') {
433: $output = &modify_quotas($dom,$action,%domconfig);
1.102.2.7 raeburn 434: } elsif ($action eq 'coursedefaults') {
435: $output = &modify_coursedefaults($dom,%domconfig);
1.3 raeburn 436: }
437: return $output;
438: }
439:
440: sub print_config_box {
1.9 raeburn 441: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 442: my $rowtotal = 0;
1.49 raeburn 443: my $output;
444: if ($action eq 'coursecategories') {
445: $output = &coursecategories_javascript($settings);
1.91 raeburn 446: }
1.49 raeburn 447: $output .=
1.30 raeburn 448: '<table class="LC_nested_outer">
1.3 raeburn 449: <tr>
1.66 raeburn 450: <th align="left" valign="middle"><span class="LC_nobreak">'.
451: &mt($item->{text}).' '.
452: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
453: '</tr>';
1.30 raeburn 454: $rowtotal ++;
1.102.2.9 raeburn 455: my $numheaders = 1;
456: if (ref($item->{'header'}) eq 'ARRAY') {
457: $numheaders = scalar(@{$item->{'header'}});
458: }
459: if ($numheaders > 1) {
1.64 raeburn 460: my $colspan = '';
461: if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
462: $colspan = ' colspan="2"';
463: }
1.30 raeburn 464: $output .= '
1.3 raeburn 465: <tr>
466: <td>
467: <table class="LC_nested">
468: <tr class="LC_info_row">
1.59 bisitz 469: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
470: <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 471: </tr>';
1.69 raeburn 472: $rowtotal ++;
1.6 raeburn 473: if ($action eq 'autoupdate') {
1.30 raeburn 474: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 475: } elsif ($action eq 'usercreation') {
1.33 raeburn 476: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
477: } elsif ($action eq 'usermodification') {
478: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 479: } elsif ($action eq 'coursecategories') {
480: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.102.2.10 raeburn 481: } elsif ($action eq 'login') {
482: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
483: $colspan = ' colspan="2"';
1.102 raeburn 484: } elsif ($action eq 'requestcourses') {
485: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.6 raeburn 486: } else {
1.30 raeburn 487: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 488: }
1.30 raeburn 489: $output .= '
1.6 raeburn 490: </table>
491: </td>
492: </tr>
493: <tr>
494: <td>
495: <table class="LC_nested">
496: <tr class="LC_info_row">
1.59 bisitz 497: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 498: $output .= '
1.59 bisitz 499: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 500: </tr>';
501: $rowtotal ++;
1.6 raeburn 502: if ($action eq 'autoupdate') {
1.102.2.12! raeburn 503: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
! 504: </table>
! 505: </td>
! 506: </tr>
! 507: <tr>
! 508: <td>
! 509: <table class="LC_nested">
! 510: <tr class="LC_info_row">
! 511: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
! 512: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
! 513: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
! 514: $rowtotal ++;
1.28 raeburn 515: } elsif ($action eq 'usercreation') {
1.34 raeburn 516: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
517: </table>
518: </td>
519: </tr>
520: <tr>
521: <td>
522: <table class="LC_nested">
523: <tr class="LC_info_row">
1.59 bisitz 524: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
525: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 526: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
527: $rowtotal ++;
1.33 raeburn 528: } elsif ($action eq 'usermodification') {
1.63 raeburn 529: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
530: </table>
531: </td>
532: </tr>
533: <tr>
534: <td>
535: <table class="LC_nested">
536: <tr class="LC_info_row">
537: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.102.2.12! raeburn 538: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.63 raeburn 539: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
540: $rowtotal ++;
1.57 raeburn 541: } elsif ($action eq 'coursecategories') {
542: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.102.2.10 raeburn 543: } elsif ($action eq 'login') {
544: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 545: } elsif ($action eq 'requestcourses') {
546: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.6 raeburn 547: } else {
1.30 raeburn 548: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 549: </table>
550: </td>
551: </tr>
552: <tr>
553: <td>
554: <table class="LC_nested">
555: <tr class="LC_info_row">
1.69 raeburn 556: <td class="LC_left_item"'.$colspan.' valign="top">'.
557: &mt($item->{'header'}->[2]->{'col1'}).'</td>
558: <td class="LC_right_item" valign="top">'.
559: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 560: </tr>'.
1.30 raeburn 561: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 562: </table>
563: </td>
564: </tr>
565: <tr>
566: <td>
567: <table class="LC_nested">
568: <tr class="LC_info_row">
1.59 bisitz 569: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
570: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 571: </tr>'.
1.30 raeburn 572: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
573: $rowtotal += 2;
1.6 raeburn 574: }
1.3 raeburn 575: } else {
1.30 raeburn 576: $output .= '
1.3 raeburn 577: <tr>
578: <td>
579: <table class="LC_nested">
1.30 raeburn 580: <tr class="LC_info_row">';
1.24 raeburn 581: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 582: $output .= '
1.59 bisitz 583: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 584: } elsif ($action eq 'serverstatuses') {
585: $output .= '
586: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
587: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
588:
1.6 raeburn 589: } else {
1.30 raeburn 590: $output .= '
1.69 raeburn 591: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
592: }
1.72 raeburn 593: if (defined($item->{'header'}->[0]->{'col3'})) {
594: $output .= '<td class="LC_left_item" valign="top">'.
595: &mt($item->{'header'}->[0]->{'col2'});
596: if ($action eq 'serverstatuses') {
597: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
598: }
1.69 raeburn 599: } else {
600: $output .= '<td class="LC_right_item" valign="top">'.
601: &mt($item->{'header'}->[0]->{'col2'});
602: }
603: $output .= '</td>';
604: if ($item->{'header'}->[0]->{'col3'}) {
605: $output .= '<td class="LC_right_item" valign="top">'.
606: &mt($item->{'header'}->[0]->{'col3'});
607: if ($action eq 'serverstatuses') {
608: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
609: }
610: $output .= '</td>';
1.6 raeburn 611: }
1.69 raeburn 612: $output .= '</tr>';
1.48 raeburn 613: $rowtotal ++;
1.3 raeburn 614: if ($action eq 'login') {
1.102.2.10 raeburn 615: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
616: \$rowtotal);
1.3 raeburn 617: } elsif ($action eq 'quotas') {
1.86 raeburn 618: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 619: } elsif ($action eq 'autoenroll') {
1.30 raeburn 620: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.102.2.9 raeburn 621: } elsif ($action eq 'autocreate') {
622: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 623: } elsif ($action eq 'directorysrch') {
1.30 raeburn 624: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 625: } elsif ($action eq 'contacts') {
1.30 raeburn 626: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 627: } elsif ($action eq 'defaults') {
628: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 629: } elsif ($action eq 'scantron') {
630: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 631: } elsif ($action eq 'serverstatuses') {
632: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.102.2.7 raeburn 633: } elsif ($action eq 'coursedefaults') {
634: $output .= &print_coursedefaults($dom,$settings,\$rowtotal);
1.27 raeburn 635: }
1.3 raeburn 636: }
1.30 raeburn 637: $output .= '
1.3 raeburn 638: </table>
639: </td>
640: </tr>
1.30 raeburn 641: </table><br />';
642: return ($output,$rowtotal);
1.1 raeburn 643: }
644:
1.3 raeburn 645: sub print_login {
1.102.2.10 raeburn 646: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
647: my ($css_class,$datatable);
1.6 raeburn 648: my %choices = &login_choices();
1.102.2.10 raeburn 649:
650: if ($position eq 'top') {
651: my %servers = &dom_servers($dom);
652: my $choice = $choices{'disallowlogin'};
653: $css_class = ' class="LC_odd_row"';
654: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
655: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
656: '<th>'.$choices{'server'}.'</th>'.
657: '<th>'.$choices{'serverpath'}.'</th>'.
658: '<th>'.$choices{'custompath'}.'</th>'.
659: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
660: my %disallowed;
661: if (ref($settings) eq 'HASH') {
662: if (ref($settings->{'loginvia'}) eq 'HASH') {
663: %disallowed = %{$settings->{'loginvia'}};
664: }
665: }
666: foreach my $lonhost (sort(keys(%servers))) {
667: my $direct = 'selected="selected"';
668: if (ref($disallowed{$lonhost}) eq 'HASH') {
669: if ($disallowed{$lonhost}{'server'} ne '') {
670: $direct = '';
671: }
672: }
673: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
674: '<td><select name="'.$lonhost.'_server">'.
675: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
676: '</option>';
677: foreach my $hostid (keys(%servers)) {
678: next if ($servers{$hostid} eq $servers{$lonhost});
679: my $selected = '';
680: if (ref($disallowed{$lonhost}) eq 'HASH') {
681: if ($hostid eq $disallowed{$lonhost}{'server'}) {
682: $selected = 'selected="selected"';
683: }
684: }
685: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
686: $servers{$hostid}.'</option>';
687: }
688: $datatable .= '</select></td>'.
689: '<td><select name="'.$lonhost.'_serverpath">';
690: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
691: my $pathname = $path;
692: if ($path eq 'custom') {
693: $pathname = &mt('Custom Path').' ->';
694: }
695: my $selected = '';
696: if (ref($disallowed{$lonhost}) eq 'HASH') {
697: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
698: $selected = 'selected="selected"';
699: }
700: } elsif ($path eq '') {
701: $selected = 'selected="selected"';
702: }
703: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
704: }
705: $datatable .= '</select></td>';
706: my ($custom,$exempt);
707: if (ref($disallowed{$lonhost}) eq 'HASH') {
708: $custom = $disallowed{$lonhost}{'custompath'};
709: $exempt = $disallowed{$lonhost}{'exempt'};
710: }
711: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
712: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
713: '</tr>';
714: }
715: $datatable .= '</table></td></tr>';
716: return $datatable;
717: }
718:
1.42 raeburn 719: my %defaultchecked = (
1.43 raeburn 720: 'coursecatalog' => 'on',
721: 'adminmail' => 'off',
722: 'newuser' => 'off',
723: );
724: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 725: my (%checkedon,%checkedoff);
726: foreach my $item (@toggles) {
727: if ($defaultchecked{$item} eq 'on') {
728: $checkedon{$item} = ' checked="checked" ';
729: $checkedoff{$item} = ' ';
730: } elsif ($defaultchecked{$item} eq 'off') {
731: $checkedoff{$item} = ' checked="checked" ';
732: $checkedon{$item} = ' ';
733: }
734: }
735: my $loginheader = 'image';
1.41 raeburn 736: my @images = ('img','logo','domlogo','login');
737: my @logintext = ('textcol','bgcol');
1.6 raeburn 738: my @bgs = ('pgbg','mainbg','sidebg');
739: my @links = ('link','alink','vlink');
1.7 albertel 740: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 741: my %defaultdesign = %Apache::loncommon::defaultdesign;
742: my (%is_custom,%designs);
743: my %defaults = (
744: font => $defaultdesign{'login.font'},
745: );
746: foreach my $item (@images) {
747: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 748: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 749: }
750: foreach my $item (@bgs) {
751: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
752: }
1.41 raeburn 753: foreach my $item (@logintext) {
754: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
755: }
1.6 raeburn 756: foreach my $item (@links) {
757: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
758: }
1.3 raeburn 759: if (ref($settings) eq 'HASH') {
1.42 raeburn 760: foreach my $item (@toggles) {
761: if ($settings->{$item} eq '1') {
762: $checkedon{$item} = ' checked="checked" ';
763: $checkedoff{$item} = ' ';
764: } elsif ($settings->{$item} eq '0') {
765: $checkedoff{$item} = ' checked="checked" ';
766: $checkedon{$item} = ' ';
767: }
1.1 raeburn 768: }
1.6 raeburn 769: foreach my $item (@images) {
1.70 raeburn 770: if (defined($settings->{$item})) {
1.6 raeburn 771: $designs{$item} = $settings->{$item};
772: $is_custom{$item} = 1;
773: }
1.70 raeburn 774: if (defined($settings->{'showlogo'}{$item})) {
775: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
776: }
1.6 raeburn 777: }
1.41 raeburn 778: foreach my $item (@logintext) {
779: if ($settings->{$item} ne '') {
780: $designs{'logintext'}{$item} = $settings->{$item};
781: $is_custom{$item} = 1;
782: }
783: }
784: if ($settings->{'loginheader'} ne '') {
785: $loginheader = $settings->{'loginheader'};
786: }
1.6 raeburn 787: if ($settings->{'font'} ne '') {
788: $designs{'font'} = $settings->{'font'};
789: $is_custom{'font'} = 1;
790: }
791: foreach my $item (@bgs) {
792: if ($settings->{$item} ne '') {
793: $designs{'bgs'}{$item} = $settings->{$item};
794: $is_custom{$item} = 1;
795: }
796: }
797: foreach my $item (@links) {
798: if ($settings->{$item} ne '') {
799: $designs{'links'}{$item} = $settings->{$item};
800: $is_custom{$item} = 1;
801: }
802: }
803: } else {
804: if ($designhash{$dom.'.login.font'} ne '') {
805: $designs{'font'} = $designhash{$dom.'.login.font'};
806: $is_custom{'font'} = 1;
807: }
1.8 raeburn 808: foreach my $item (@images) {
809: if ($designhash{$dom.'.login.'.$item} ne '') {
810: $designs{$item} = $designhash{$dom.'.login.'.$item};
811: $is_custom{$item} = 1;
812: }
813: }
1.6 raeburn 814: foreach my $item (@bgs) {
815: if ($designhash{$dom.'.login.'.$item} ne '') {
816: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
817: $is_custom{$item} = 1;
818: }
819: }
820: foreach my $item (@links) {
821: if ($designhash{$dom.'.login.'.$item} ne '') {
822: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
823: $is_custom{$item} = 1;
824: }
825: }
1.1 raeburn 826: }
1.6 raeburn 827: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
828: logo => 'Institution Logo',
1.41 raeburn 829: domlogo => 'Domain Logo',
830: login => 'Login box');
1.6 raeburn 831: my $itemcount = 1;
1.42 raeburn 832: my ($css_class,$datatable);
833: foreach my $item (@toggles) {
834: $css_class = $itemcount%2?' class="LC_odd_row"':'';
835: $datatable .=
836: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
837: '</td><td>'.
838: '<span class="LC_nobreak"><label><input type="radio" name="'.
839: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
840: '</label> <label><input type="radio" name="'.$item.'"'.
841: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
842: '</tr>';
843: $itemcount ++;
844: }
1.41 raeburn 845: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
1.6 raeburn 846: $datatable .= '</tr></table></td></tr>';
847: return $datatable;
848: }
849:
850: sub login_choices {
851: my %choices =
852: &Apache::lonlocal::texthash (
1.102.2.6 raeburn 853: coursecatalog => 'Display Course/Community Catalog link?',
1.6 raeburn 854: adminmail => "Display Administrator's E-mail Address?",
1.102.2.10 raeburn 855: disallowlogin => "Login page requests redirected",
856: hostid => "Server",
857: server => "Redirect to:",
858: serverpath => "Path",
859: custompath => "Custom",
860: exempt => "Exempt IP(s)",
861: directlogin => "No redirect",
1.43 raeburn 862: newuser => "Link to create a user account",
1.6 raeburn 863: img => "Header",
864: logo => "Main Logo",
865: domlogo => "Domain Logo",
1.41 raeburn 866: login => "Log-in Header",
867: textcol => "Text color",
868: bgcol => "Box color",
1.6 raeburn 869: bgs => "Background colors",
870: links => "Link colors",
871: font => "Font color",
1.71 muellerd 872: pgbg => "Header",
873: mainbg => "Page",
1.74 muellerd 874: sidebg => "Login box",
1.6 raeburn 875: link => "Link",
876: alink => "Active link",
877: vlink => "Visited link",
878: );
879: return %choices;
880: }
881:
882: sub print_rolecolors {
1.30 raeburn 883: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 884: my %choices = &color_font_choices();
885: my @bgs = ('pgbg','tabbg','sidebg');
886: my @links = ('link','alink','vlink');
887: my @images = ('img');
888: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 889: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 890: my %defaultdesign = %Apache::loncommon::defaultdesign;
891: my (%is_custom,%designs);
892: my %defaults = (
893: img => $defaultdesign{$role.'.img'},
894: font => $defaultdesign{$role.'.font'},
895: );
896: foreach my $item (@bgs) {
897: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
898: }
899: foreach my $item (@links) {
900: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
901: }
902: if (ref($settings) eq 'HASH') {
903: if (ref($settings->{$role}) eq 'HASH') {
904: if ($settings->{$role}->{'img'} ne '') {
905: $designs{'img'} = $settings->{$role}->{'img'};
906: $is_custom{'img'} = 1;
907: }
908: if ($settings->{$role}->{'font'} ne '') {
909: $designs{'font'} = $settings->{$role}->{'font'};
910: $is_custom{'font'} = 1;
911: }
912: foreach my $item (@bgs) {
913: if ($settings->{$role}->{$item} ne '') {
914: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
915: $is_custom{$item} = 1;
916: }
917: }
918: foreach my $item (@links) {
919: if ($settings->{$role}->{$item} ne '') {
920: $designs{'links'}{$item} = $settings->{$role}->{$item};
921: $is_custom{$item} = 1;
922: }
923: }
924: }
925: } else {
926: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
927: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
928: $is_custom{'img'} = 1;
929: }
930: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
931: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
932: $is_custom{'font'} = 1;
933: }
934: foreach my $item (@bgs) {
935: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
936: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
937: $is_custom{$item} = 1;
938:
939: }
940: }
941: foreach my $item (@links) {
942: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
943: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
944: $is_custom{$item} = 1;
945: }
946: }
947: }
948: my $itemcount = 1;
1.30 raeburn 949: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 950: $datatable .= '</tr></table></td></tr>';
951: return $datatable;
952: }
953:
954: sub display_color_options {
1.9 raeburn 955: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.41 raeburn 956: $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
1.6 raeburn 957: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.102.2.1 raeburn 958: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 959: '<td>'.$choices->{'font'}.'</td>';
960: if (!$is_custom->{'font'}) {
1.30 raeburn 961: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 962: } else {
963: $datatable .= '<td> </td>';
964: }
965: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 966: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 967: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 968: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 969: ' <span id="css_'.$role.'_font" style="background-color: '.
970: $designs->{'font'}.';"> </span>'.
1.8 raeburn 971: '</span></td></tr>';
1.9 raeburn 972: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 973: foreach my $img (@{$images}) {
1.18 albertel 974: $itemcount ++;
1.6 raeburn 975: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 976: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 977: '<td>'.$choices->{$img};
1.41 raeburn 978: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 979: if ($role eq 'login') {
980: if ($img eq 'login') {
981: $login_hdr_pick =
982: &login_header_options($img,$role,$defaults,$is_custom,$choices,
983: $loginheader);
984: $logincolors =
985: &login_text_colors($img,$role,$logintext,$phase,$choices,
986: $designs);
987: } elsif ($img ne 'domlogo') {
988: $datatable.= &logo_display_options($img,$defaults,$designs);
989: }
990: }
991: $datatable .= '</td>';
1.6 raeburn 992: if ($designs->{$img} ne '') {
993: $imgfile = $designs->{$img};
1.18 albertel 994: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 995: } else {
996: $imgfile = $defaults->{$img};
997: }
998: if ($imgfile) {
1.9 raeburn 999: my ($showfile,$fullsize);
1000: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1001: my $urldir = $1;
1002: my $filename = $2;
1003: my @info = &Apache::lonnet::stat_file($designs->{$img});
1004: if (@info) {
1005: my $thumbfile = 'tn-'.$filename;
1006: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1007: if (@thumb) {
1008: $showfile = $urldir.'/'.$thumbfile;
1009: } else {
1010: $showfile = $imgfile;
1011: }
1012: } else {
1013: $showfile = '';
1014: }
1015: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1016: $showfile = $imgfile;
1.6 raeburn 1017: my $imgdir = $1;
1018: my $filename = $2;
1019: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
1020: $showfile = "/$imgdir/tn-".$filename;
1021: } else {
1022: my $input = "/home/httpd/html".$imgfile;
1023: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
1024: if (!-e $output) {
1.9 raeburn 1025: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1026: my ($fullwidth,$fullheight) = &check_dimensions($input);
1027: if ($fullwidth ne '' && $fullheight ne '') {
1028: if ($fullwidth > $width && $fullheight > $height) {
1029: my $size = $width.'x'.$height;
1030: system("convert -sample $size $input $output");
1031: $showfile = '/'.$imgdir.'/tn-'.$filename;
1032: }
1033: }
1.6 raeburn 1034: }
1035: }
1.16 raeburn 1036: }
1.6 raeburn 1037: if ($showfile) {
1.40 raeburn 1038: if ($showfile =~ m{^/(adm|res)/}) {
1039: if ($showfile =~ m{^/res/}) {
1040: my $local_showfile =
1041: &Apache::lonnet::filelocation('',$showfile);
1042: &Apache::lonnet::repcopy($local_showfile);
1043: }
1044: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1045: }
1046: if ($imgfile) {
1047: if ($imgfile =~ m{^/(adm|res)/}) {
1048: if ($imgfile =~ m{^/res/}) {
1049: my $local_imgfile =
1050: &Apache::lonnet::filelocation('',$imgfile);
1051: &Apache::lonnet::repcopy($local_imgfile);
1052: }
1053: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1054: } else {
1055: $fullsize = $imgfile;
1056: }
1057: }
1.41 raeburn 1058: $datatable .= '<td>';
1059: if ($img eq 'login') {
1060: $datatable .= $login_hdr_pick;
1.6 raeburn 1061: }
1.41 raeburn 1062: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1063: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1064: } else {
1065: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1066: &mt('Upload:');
1067: }
1068: } else {
1069: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1070: &mt('Upload:');
1071: }
1.9 raeburn 1072: if ($switchserver) {
1073: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1074: } else {
1075: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1076: }
1077: $datatable .= '</td></tr>';
1.6 raeburn 1078: }
1079: $itemcount ++;
1080: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1081: $datatable .= '<tr'.$css_class.'>'.
1082: '<td>'.$choices->{'bgs'}.'</td>';
1083: my $bgs_def;
1084: foreach my $item (@{$bgs}) {
1085: if (!$is_custom->{$item}) {
1.70 raeburn 1086: $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 1087: }
1088: }
1089: if ($bgs_def) {
1.8 raeburn 1090: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1091: } else {
1092: $datatable .= '<td> </td>';
1093: }
1094: $datatable .= '<td class="LC_right_item">'.
1095: '<table border="0"><tr>';
1096: foreach my $item (@{$bgs}) {
1097: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1098: $datatable .= '<td align="center">'.$link;
1099: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1100: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1101: }
1102: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1103: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1104: }
1105: $datatable .= '</tr></table></td></tr>';
1106: $itemcount ++;
1107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1108: $datatable .= '<tr'.$css_class.'>'.
1109: '<td>'.$choices->{'links'}.'</td>';
1110: my $links_def;
1111: foreach my $item (@{$links}) {
1112: if (!$is_custom->{$item}) {
1.30 raeburn 1113: $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 1114: }
1115: }
1116: if ($links_def) {
1.8 raeburn 1117: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1118: } else {
1119: $datatable .= '<td> </td>';
1120: }
1121: $datatable .= '<td class="LC_right_item">'.
1122: '<table border="0"><tr>';
1123: foreach my $item (@{$links}) {
1.30 raeburn 1124: $datatable .= '<td align="center">'."\n".
1125: &color_pick($phase,$role,$item,$choices->{$item},
1126: $designs->{'links'}{$item});
1.6 raeburn 1127: if ($designs->{'links'}{$item}) {
1.30 raeburn 1128: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1129: }
1130: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1131: '" /></td>';
1132: }
1.30 raeburn 1133: $$rowtotal += $itemcount;
1.3 raeburn 1134: return $datatable;
1135: }
1136:
1.70 raeburn 1137: sub logo_display_options {
1138: my ($img,$defaults,$designs) = @_;
1139: my $checkedon;
1140: if (ref($defaults) eq 'HASH') {
1141: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1142: if ($defaults->{'showlogo'}{$img}) {
1143: $checkedon = 'checked="checked" ';
1144: }
1145: }
1146: }
1147: if (ref($designs) eq 'HASH') {
1148: if (ref($designs->{'showlogo'}) eq 'HASH') {
1149: if (defined($designs->{'showlogo'}{$img})) {
1150: if ($designs->{'showlogo'}{$img} == 0) {
1151: $checkedon = '';
1152: } elsif ($designs->{'showlogo'}{$img} == 1) {
1153: $checkedon = 'checked="checked" ';
1154: }
1155: }
1156: }
1157: }
1158: return '<br /><label> <input type="checkbox" name="'.
1159: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1160: &mt('show').'</label>'."\n";
1161: }
1162:
1.41 raeburn 1163: sub login_header_options {
1164: my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
1165: my $image_checked = ' checked="checked" ';
1166: my $text_checked = ' ';
1167: if ($loginheader eq 'text') {
1168: $image_checked = ' ';
1169: $text_checked = ' checked="checked" ';
1170: }
1171: my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
1172: 'loginheader" value="image" '.$image_checked.'/>'.
1173: &mt('use image').'</label> '.
1174: '<label><input type="radio" name="loginheader" value="text"'.
1175: $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
1176: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1177: $output .= &mt('Text default(s)').':<br />';
1178: if (!$is_custom->{'textcol'}) {
1179: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1180: ' ';
1181: }
1182: if (!$is_custom->{'bgcol'}) {
1183: $output .= $choices->{'bgcol'}.': '.
1184: '<span id="css_'.$role.'_font" style="background-color: '.
1185: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1186: }
1187: $output .= '<br />';
1188: }
1189: $output .='<br />';
1190: return $output;
1191: }
1192:
1193: sub login_text_colors {
1194: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1195: my $color_menu = '<table border="0"><tr>';
1196: foreach my $item (@{$logintext}) {
1197: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1198: $color_menu .= '<td align="center">'.$link;
1199: if ($designs->{'logintext'}{$item}) {
1200: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1201: }
1202: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1203: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1204: '<td> </td>';
1205: }
1206: $color_menu .= '</tr></table><br />';
1207: return $color_menu;
1208: }
1209:
1210: sub image_changes {
1211: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1212: my $output;
1213: if (!$is_custom) {
1.70 raeburn 1214: if ($img ne 'domlogo') {
1.41 raeburn 1215: $output .= &mt('Default image:').'<br />';
1216: } else {
1217: $output .= &mt('Default in use:').'<br />';
1218: }
1219: }
1220: if ($img_import) {
1221: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1222: }
1223: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1224: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1225: if ($is_custom) {
1226: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1227: '<input type="checkbox" name="'.
1228: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1229: '</label> '.&mt('Replace:').'</span><br />';
1230: } else {
1231: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1232: }
1233: return $output;
1234: }
1235:
1.6 raeburn 1236: sub color_pick {
1237: my ($phase,$role,$item,$desc,$curcol) = @_;
1238: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1239: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1240: ');">'.$desc.'</a>';
1241: return $link;
1242: }
1243:
1.3 raeburn 1244: sub print_quotas {
1.86 raeburn 1245: my ($dom,$settings,$rowtotal,$action) = @_;
1246: my $context;
1247: if ($action eq 'quotas') {
1248: $context = 'tools';
1249: } else {
1250: $context = $action;
1251: }
1.101 raeburn 1252: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1253: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1254: my $typecount = 0;
1.101 raeburn 1255: my ($css_class,%titles);
1.86 raeburn 1256: if ($context eq 'requestcourses') {
1.98 raeburn 1257: @usertools = ('official','unofficial','community');
1.102.2.9 raeburn 1258: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1259: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1260: %titles = &courserequest_titles();
1.86 raeburn 1261: } else {
1262: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1263: %titles = &tool_titles();
1.86 raeburn 1264: }
1.26 raeburn 1265: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1266: foreach my $type (@{$types}) {
1.72 raeburn 1267: my $currdefquota;
1.86 raeburn 1268: unless ($context eq 'requestcourses') {
1269: if (ref($settings) eq 'HASH') {
1270: if (ref($settings->{defaultquota}) eq 'HASH') {
1271: $currdefquota = $settings->{defaultquota}->{$type};
1272: } else {
1273: $currdefquota = $settings->{$type};
1274: }
1.78 raeburn 1275: }
1.72 raeburn 1276: }
1.3 raeburn 1277: if (defined($usertypes->{$type})) {
1278: $typecount ++;
1279: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1280: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1281: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1282: '<td class="LC_left_item">';
1.101 raeburn 1283: if ($context eq 'requestcourses') {
1284: $datatable .= '<table><tr>';
1285: }
1286: my %cell;
1.72 raeburn 1287: foreach my $item (@usertools) {
1.101 raeburn 1288: if ($context eq 'requestcourses') {
1289: my ($curroption,$currlimit);
1290: if (ref($settings) eq 'HASH') {
1291: if (ref($settings->{$item}) eq 'HASH') {
1292: $curroption = $settings->{$item}->{$type};
1293: if ($curroption =~ /^autolimit=(\d*)$/) {
1294: $currlimit = $1;
1295: }
1296: }
1297: }
1298: if (!$curroption) {
1299: $curroption = 'norequest';
1300: }
1301: $datatable .= '<th>'.$titles{$item}.'</th>';
1302: foreach my $option (@options) {
1303: my $val = $option;
1304: if ($option eq 'norequest') {
1305: $val = 0;
1306: }
1307: if ($option eq 'validate') {
1308: my $canvalidate = 0;
1309: if (ref($validations{$item}) eq 'HASH') {
1310: if ($validations{$item}{$type}) {
1311: $canvalidate = 1;
1312: }
1313: }
1314: next if (!$canvalidate);
1315: }
1316: my $checked = '';
1317: if ($option eq $curroption) {
1318: $checked = ' checked="checked"';
1319: } elsif ($option eq 'autolimit') {
1320: if ($curroption =~ /^autolimit/) {
1321: $checked = ' checked="checked"';
1322: }
1323: }
1324: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1325: '<input type="radio" name="crsreq_'.$item.
1326: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.102.2.9 raeburn 1327: $titles{$option}.'</label>';
1.101 raeburn 1328: if ($option eq 'autolimit') {
1.102.2.9 raeburn 1329: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1330: $item.'_limit_'.$type.'" size="1" '.
1.102.2.2 raeburn 1331: 'value="'.$currlimit.'" />';
1332: }
1.102.2.9 raeburn 1333: $cell{$item} .= '</span> ';
1.102.2.2 raeburn 1334: if ($option eq 'autolimit') {
1335: $cell{$item} .= $titles{'unlimited'};
1.101 raeburn 1336: }
1337: }
1338: } else {
1339: my $checked = 'checked="checked" ';
1340: if (ref($settings) eq 'HASH') {
1341: if (ref($settings->{$item}) eq 'HASH') {
1342: if ($settings->{$item}->{$type} == 0) {
1343: $checked = '';
1344: } elsif ($settings->{$item}->{$type} == 1) {
1345: $checked = 'checked="checked" ';
1346: }
1.78 raeburn 1347: }
1.72 raeburn 1348: }
1.101 raeburn 1349: $datatable .= '<span class="LC_nobreak"><label>'.
1350: '<input type="checkbox" name="'.$context.'_'.$item.
1351: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1352: '</label></span> ';
1.72 raeburn 1353: }
1.101 raeburn 1354: }
1355: if ($context eq 'requestcourses') {
1356: $datatable .= '</tr><tr>';
1357: foreach my $item (@usertools) {
1.102.2.2 raeburn 1358: $datatable .= '<td style="vertical-align: top;">'.$cell{$item}.'</td>';
1.101 raeburn 1359: }
1360: $datatable .= '</tr></table>';
1.72 raeburn 1361: }
1.86 raeburn 1362: $datatable .= '</td>';
1363: unless ($context eq 'requestcourses') {
1364: $datatable .=
1365: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1366: '<input type="text" name="quota_'.$type.
1.72 raeburn 1367: '" value="'.$currdefquota.
1.86 raeburn 1368: '" size="5" /> Mb</span></td>';
1369: }
1370: $datatable .= '</tr>';
1.3 raeburn 1371: }
1372: }
1373: }
1.86 raeburn 1374: unless ($context eq 'requestcourses') {
1375: $defaultquota = '20';
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1378: $defaultquota = $settings->{'defaultquota'}->{'default'};
1379: } elsif (defined($settings->{'default'})) {
1380: $defaultquota = $settings->{'default'};
1381: }
1.3 raeburn 1382: }
1383: }
1384: $typecount ++;
1385: $css_class = $typecount%2?' class="LC_odd_row"':'';
1386: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1387: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1388: '<td class="LC_left_item">';
1.101 raeburn 1389: if ($context eq 'requestcourses') {
1390: $datatable .= '<table><tr>';
1391: }
1392: my %defcell;
1.72 raeburn 1393: foreach my $item (@usertools) {
1.101 raeburn 1394: if ($context eq 'requestcourses') {
1395: my ($curroption,$currlimit);
1396: if (ref($settings) eq 'HASH') {
1397: if (ref($settings->{$item}) eq 'HASH') {
1398: $curroption = $settings->{$item}->{'default'};
1399: if ($curroption =~ /^autolimit=(\d*)$/) {
1400: $currlimit = $1;
1401: }
1402: }
1403: }
1404: if (!$curroption) {
1405: $curroption = 'norequest';
1406: }
1407: $datatable .= '<th>'.$titles{$item}.'</th>';
1408: foreach my $option (@options) {
1409: my $val = $option;
1410: if ($option eq 'norequest') {
1411: $val = 0;
1412: }
1413: if ($option eq 'validate') {
1414: my $canvalidate = 0;
1415: if (ref($validations{$item}) eq 'HASH') {
1416: if ($validations{$item}{'default'}) {
1417: $canvalidate = 1;
1418: }
1419: }
1420: next if (!$canvalidate);
1421: }
1422: my $checked = '';
1423: if ($option eq $curroption) {
1424: $checked = ' checked="checked"';
1425: } elsif ($option eq 'autolimit') {
1426: if ($curroption =~ /^autolimit/) {
1427: $checked = ' checked="checked"';
1428: }
1429: }
1430: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1431: '<input type="radio" name="crsreq_'.$item.
1432: '_default" value="'.$val.'"'.$checked.' />'.
1433: $titles{$option}.'</label>';
1434: if ($option eq 'autolimit') {
1.102.2.9 raeburn 1435: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1436: $item.'_limit_default" size="1" '.
1437: 'value="'.$currlimit.'" />';
1438: }
1.102.2.9 raeburn 1439: $defcell{$item} .= '</span> ';
1.102.2.2 raeburn 1440: if ($option eq 'autolimit') {
1441: $defcell{$item} .= $titles{'unlimited'};
1442: }
1.101 raeburn 1443: }
1444: } else {
1445: my $checked = 'checked="checked" ';
1446: if (ref($settings) eq 'HASH') {
1447: if (ref($settings->{$item}) eq 'HASH') {
1448: if ($settings->{$item}->{'default'} == 0) {
1449: $checked = '';
1450: } elsif ($settings->{$item}->{'default'} == 1) {
1451: $checked = 'checked="checked" ';
1452: }
1.78 raeburn 1453: }
1.72 raeburn 1454: }
1.101 raeburn 1455: $datatable .= '<span class="LC_nobreak"><label>'.
1456: '<input type="checkbox" name="'.$context.'_'.$item.
1457: '" value="default" '.$checked.'/>'.$titles{$item}.
1458: '</label></span> ';
1459: }
1460: }
1461: if ($context eq 'requestcourses') {
1462: $datatable .= '</tr><tr>';
1463: foreach my $item (@usertools) {
1.102.2.2 raeburn 1464: $datatable .= '<td style="vertical-align: top;">'.$defcell{$item}.'</td>';
1.72 raeburn 1465: }
1.101 raeburn 1466: $datatable .= '</tr></table>';
1.72 raeburn 1467: }
1.86 raeburn 1468: $datatable .= '</td>';
1469: unless ($context eq 'requestcourses') {
1470: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1471: '<input type="text" name="defaultquota" value="'.
1472: $defaultquota.'" size="5" /> Mb</span></td>';
1473: }
1474: $datatable .= '</tr>';
1.72 raeburn 1475: $typecount ++;
1476: $css_class = $typecount%2?' class="LC_odd_row"':'';
1477: $datatable .= '<tr'.$css_class.'>'.
1.102.2.2 raeburn 1478: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1479: if ($context eq 'requestcourses') {
1.102.2.3 raeburn 1480: $datatable .= &mt('(overrides affiliation, if set)').
1481: '</td>'.
1482: '<td class="LC_left_item">'.
1483: '<table><tr>';
1.101 raeburn 1484: } else {
1.102.2.3 raeburn 1485: $datatable .= &mt('(overrides affiliation, if checked)').
1486: '</td>'.
1487: '<td class="LC_left_item" colspan="2">'.
1488: '<br />';
1.101 raeburn 1489: }
1490: my %advcell;
1.72 raeburn 1491: foreach my $item (@usertools) {
1.101 raeburn 1492: if ($context eq 'requestcourses') {
1493: my ($curroption,$currlimit);
1494: if (ref($settings) eq 'HASH') {
1495: if (ref($settings->{$item}) eq 'HASH') {
1496: $curroption = $settings->{$item}->{'_LC_adv'};
1497: if ($curroption =~ /^autolimit=(\d*)$/) {
1498: $currlimit = $1;
1499: }
1500: }
1501: }
1502: $datatable .= '<th>'.$titles{$item}.'</th>';
1.102.2.2 raeburn 1503: my $checked = '';
1504: if ($curroption eq '') {
1505: $checked = ' checked="checked"';
1506: }
1507: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1508: '<input type="radio" name="crsreq_'.$item.
1509: '__LC_adv" value=""'.$checked.' />'.
1510: &mt('No override set').'</label></span> ';
1.101 raeburn 1511: foreach my $option (@options) {
1512: my $val = $option;
1513: if ($option eq 'norequest') {
1514: $val = 0;
1515: }
1516: if ($option eq 'validate') {
1517: my $canvalidate = 0;
1518: if (ref($validations{$item}) eq 'HASH') {
1519: if ($validations{$item}{'_LC_adv'}) {
1520: $canvalidate = 1;
1521: }
1522: }
1523: next if (!$canvalidate);
1524: }
1525: my $checked = '';
1.102.2.2 raeburn 1526: if ($val eq $curroption) {
1.101 raeburn 1527: $checked = ' checked="checked"';
1528: } elsif ($option eq 'autolimit') {
1529: if ($curroption =~ /^autolimit/) {
1530: $checked = ' checked="checked"';
1531: }
1532: }
1533: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1534: '<input type="radio" name="crsreq_'.$item.
1535: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1536: $titles{$option}.'</label>';
1537: if ($option eq 'autolimit') {
1.102.2.9 raeburn 1538: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1539: $item.'_limit__LC_adv" size="1" '.
1540: 'value="'.$currlimit.'" />';
1541: }
1.102.2.9 raeburn 1542: $advcell{$item} .= '</span> ';
1.102.2.2 raeburn 1543: if ($option eq 'autolimit') {
1544: $advcell{$item} .= $titles{'unlimited'};
1545: }
1.101 raeburn 1546: }
1547: } else {
1548: my $checked = 'checked="checked" ';
1549: if (ref($settings) eq 'HASH') {
1550: if (ref($settings->{$item}) eq 'HASH') {
1551: if ($settings->{$item}->{'_LC_adv'} == 0) {
1552: $checked = '';
1553: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1554: $checked = 'checked="checked" ';
1555: }
1.79 raeburn 1556: }
1.72 raeburn 1557: }
1.101 raeburn 1558: $datatable .= '<span class="LC_nobreak"><label>'.
1559: '<input type="checkbox" name="'.$context.'_'.$item.
1560: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1561: '</label></span> ';
1562: }
1563: }
1564: if ($context eq 'requestcourses') {
1565: $datatable .= '</tr><tr>';
1566: foreach my $item (@usertools) {
1.102.2.2 raeburn 1567: $datatable .= '<td style="vertical-align: top;">'.$advcell{$item}.'</td>';
1.72 raeburn 1568: }
1.101 raeburn 1569: $datatable .= '</tr></table>';
1.72 raeburn 1570: }
1.98 raeburn 1571: $datatable .= '</td></tr>';
1.30 raeburn 1572: $$rowtotal += $typecount;
1.3 raeburn 1573: return $datatable;
1574: }
1575:
1.102 raeburn 1576: sub print_courserequestmail {
1577: my ($dom,$settings,$rowtotal) = @_;
1.102.2.2 raeburn 1578: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1579: $now = time;
1580: $rows = 0;
1581: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1582: foreach my $server (keys(%dompersonnel)) {
1583: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1584: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1585: if (!grep(/^$uname:$udom$/,@domcoord)) {
1586: push(@domcoord,$uname.':'.$udom);
1587: }
1588: }
1589: }
1590: if (ref($settings) eq 'HASH') {
1591: if (ref($settings->{'notify'}) eq 'HASH') {
1592: if ($settings->{'notify'}{'approval'} ne '') {
1.102.2.2 raeburn 1593: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1594: }
1595: }
1596: }
1.102.2.2 raeburn 1597: if (@currapproval) {
1598: foreach my $dc (@currapproval) {
1.102 raeburn 1599: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1600: push(@domcoord,$dc);
1601: }
1602: }
1603: }
1604: @domcoord = sort(@domcoord);
1605: my $numinrow = 4;
1606: my $numdc = @domcoord;
1607: my $css_class = 'class="LC_odd_row"';
1608: $datatable = '<tr'.$css_class.'>'.
1609: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1610: ' </td>'.
1611: ' <td class="LC_left_item">';
1612: if (@domcoord > 0) {
1613: $datatable .= '<table>';
1614: for (my $i=0; $i<$numdc; $i++) {
1615: my $rem = $i%($numinrow);
1616: if ($rem == 0) {
1617: if ($i > 0) {
1618: $datatable .= '</tr>';
1619: }
1620: $datatable .= '<tr>';
1621: $rows ++;
1622: }
1623: my $check = ' ';
1.102.2.2 raeburn 1624: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1625: $check = ' checked="checked" ';
1626: }
1627: my ($uname,$udom) = split(':',$domcoord[$i]);
1628: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1629: if ($i == $numdc-1) {
1630: my $colsleft = $numinrow-$rem;
1631: if ($colsleft > 1) {
1632: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1633: } else {
1634: $datatable .= '<td class="LC_left_item">';
1635: }
1636: } else {
1637: $datatable .= '<td class="LC_left_item">';
1638: }
1639: $datatable .= '<span class="LC_nobreak"><label>'.
1640: '<input type="checkbox" name="reqapprovalnotify" '.
1641: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1642: $fullname.'</label></span></td>';
1643: }
1644: $datatable .= '</tr></table>';
1645: } else {
1646: $datatable .= &mt('There are no active Domain Coordinators');
1647: $rows ++;
1648: }
1649: $datatable .='</td></tr>';
1650: $$rowtotal += $rows;
1651: return $datatable;
1652: }
1653:
1.3 raeburn 1654: sub print_autoenroll {
1.30 raeburn 1655: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1656: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.102.2.11 raeburn 1657: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1658: if (ref($settings) eq 'HASH') {
1659: if (exists($settings->{'run'})) {
1660: if ($settings->{'run'} eq '0') {
1661: $runoff = ' checked="checked" ';
1662: $runon = ' ';
1663: } else {
1664: $runon = ' checked="checked" ';
1665: $runoff = ' ';
1666: }
1667: } else {
1668: if ($autorun) {
1669: $runon = ' checked="checked" ';
1670: $runoff = ' ';
1671: } else {
1672: $runoff = ' checked="checked" ';
1673: $runon = ' ';
1674: }
1675: }
1.102.2.11 raeburn 1676: if (exists($settings->{'co-owners'})) {
1677: if ($settings->{'co-owners'} eq '0') {
1678: $coownersoff = ' checked="checked" ';
1679: $coownerson = ' ';
1680: } else {
1681: $coownerson = ' checked="checked" ';
1682: $coownersoff = ' ';
1683: }
1684: } else {
1685: $coownersoff = ' checked="checked" ';
1686: $coownerson = ' ';
1687: }
1.3 raeburn 1688: if (exists($settings->{'sender_domain'})) {
1689: $defdom = $settings->{'sender_domain'};
1690: }
1.14 raeburn 1691: } else {
1692: if ($autorun) {
1693: $runon = ' checked="checked" ';
1694: $runoff = ' ';
1695: } else {
1696: $runoff = ' checked="checked" ';
1697: $runon = ' ';
1698: }
1.3 raeburn 1699: }
1700: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1701: my $notif_sender;
1702: if (ref($settings) eq 'HASH') {
1703: $notif_sender = $settings->{'sender_uname'};
1704: }
1.3 raeburn 1705: my $datatable='<tr class="LC_odd_row">'.
1706: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1707: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1708: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1709: $runon.' value="1" />'.&mt('Yes').'</label> '.
1710: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1711: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1712: '</tr><tr>'.
1713: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1714: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1715: &mt('username').': '.
1716: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1717: $notif_sender.'" size="10" /> '.&mt('domain').
1.102.2.11 raeburn 1718: ': '.$domform.'</span></td></tr>'.
1719: '<tr class="LC_odd_row">'.
1720: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1721: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1722: '<input type="radio" name="autoassign_coowners"'.
1723: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1724: '<label><input type="radio" name="autoassign_coowners"'.
1725: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1726: '</tr>';
1727: $$rowtotal += 3;
1.3 raeburn 1728: return $datatable;
1729: }
1730:
1731: sub print_autoupdate {
1.30 raeburn 1732: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1733: my $datatable;
1734: if ($position eq 'top') {
1735: my $updateon = ' ';
1736: my $updateoff = ' checked="checked" ';
1737: my $classlistson = ' ';
1738: my $classlistsoff = ' checked="checked" ';
1739: if (ref($settings) eq 'HASH') {
1740: if ($settings->{'run'} eq '1') {
1741: $updateon = $updateoff;
1742: $updateoff = ' ';
1743: }
1744: if ($settings->{'classlists'} eq '1') {
1745: $classlistson = $classlistsoff;
1746: $classlistsoff = ' ';
1747: }
1748: }
1749: my %title = (
1750: run => 'Auto-update active?',
1751: classlists => 'Update information in classlists?',
1752: );
1753: $datatable = '<tr class="LC_odd_row">'.
1754: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1755: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1756: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1757: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1758: '<label><input type="radio" name="autoupdate_run"'.
1759: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1760: '</tr><tr>'.
1761: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1762: '<td class="LC_right_item"><span class="LC_nobreak">'.
1763: '<label><input type="radio" name="classlists"'.
1764: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1765: '<label><input type="radio" name="classlists"'.
1766: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1767: '</tr>';
1.30 raeburn 1768: $$rowtotal += 2;
1.102.2.12! raeburn 1769: } elsif ($position eq 'middle') {
! 1770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 1771: my $numinrow = 3;
! 1772: my $locknamesettings;
! 1773: $datatable .= &insttypes_row($settings,$types,$usertypes,
! 1774: $dom,$numinrow,$othertitle,
! 1775: 'lockablenames');
! 1776: $$rowtotal ++;
1.3 raeburn 1777: } else {
1.44 raeburn 1778: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.102.2.12! raeburn 1779: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1780: 'permanentemail','id');
1.33 raeburn 1781: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1782: my $numrows = 0;
1.26 raeburn 1783: if (ref($types) eq 'ARRAY') {
1784: if (@{$types} > 0) {
1785: $datatable =
1786: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1787: \@fields,$types,\$numrows);
1.30 raeburn 1788: $$rowtotal += @{$types};
1.26 raeburn 1789: }
1.3 raeburn 1790: }
1791: $datatable .=
1792: &usertype_update_row($settings,{'default' => $othertitle},
1793: \%fieldtitles,\@fields,['default'],
1794: \$numrows);
1.30 raeburn 1795: $$rowtotal ++;
1.3 raeburn 1796: }
1797: return $datatable;
1798: }
1799:
1.102.2.9 raeburn 1800: sub print_autocreate {
1801: my ($dom,$settings,$rowtotal) = @_;
1802: my (%createon,%createoff);
1803: my $curr_dc;
1804: my @types = ('xml','req');
1805: if (ref($settings) eq 'HASH') {
1806: foreach my $item (@types) {
1807: $createoff{$item} = ' checked="checked" ';
1808: $createon{$item} = ' ';
1809: if (exists($settings->{$item})) {
1810: if ($settings->{$item}) {
1811: $createon{$item} = ' checked="checked" ';
1812: $createoff{$item} = ' ';
1813: }
1814: }
1815: }
1816: $curr_dc = $settings->{'xmldc'};
1817: } else {
1818: foreach my $item (@types) {
1819: $createoff{$item} = ' checked="checked" ';
1820: $createon{$item} = ' ';
1821: }
1822: }
1823: $$rowtotal += 2;
1824: my $datatable='<tr class="LC_odd_row">'.
1825: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1826: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1827: '<input type="radio" name="autocreate_xml"'.
1828: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1829: '<label><input type="radio" name="autocreate_xml"'.
1830: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>';
1831: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1832: if ($numdc > 1) {
1833: $datatable .= '</td><tr><td>'.
1834: &mt('XML files processed as: (choose Dom. Coord.)').
1835: '</td><td class="LC_left_item">'.$dctable.'</td></tr>'.
1836: '<tr class="LC_odd_row">';
1837: $$rowtotal ++ ;
1838: } else {
1839: $datatable .= '</td></tr><tr>';
1840: }
1841: $datatable .= '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1843: '<input type="radio" name="autocreate_req"'.
1844: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1845: '<label><input type="radio" name="autocreate_req"'.
1846: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span></td>'.
1847: '</tr>';
1848: return $datatable;
1849: }
1850:
1.23 raeburn 1851: sub print_directorysrch {
1.30 raeburn 1852: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1853: my $srchon = ' ';
1854: my $srchoff = ' checked="checked" ';
1.25 raeburn 1855: my ($exacton,$containson,$beginson);
1.24 raeburn 1856: my $localon = ' ';
1857: my $localoff = ' checked="checked" ';
1.23 raeburn 1858: if (ref($settings) eq 'HASH') {
1859: if ($settings->{'available'} eq '1') {
1860: $srchon = $srchoff;
1861: $srchoff = ' ';
1862: }
1.24 raeburn 1863: if ($settings->{'localonly'} eq '1') {
1864: $localon = $localoff;
1865: $localoff = ' ';
1866: }
1.25 raeburn 1867: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1868: foreach my $type (@{$settings->{'searchtypes'}}) {
1869: if ($type eq 'exact') {
1870: $exacton = ' checked="checked" ';
1871: } elsif ($type eq 'contains') {
1872: $containson = ' checked="checked" ';
1873: } elsif ($type eq 'begins') {
1874: $beginson = ' checked="checked" ';
1875: }
1876: }
1877: } else {
1878: if ($settings->{'searchtypes'} eq 'exact') {
1879: $exacton = ' checked="checked" ';
1880: } elsif ($settings->{'searchtypes'} eq 'contains') {
1881: $containson = ' checked="checked" ';
1882: } elsif ($settings->{'searchtypes'} eq 'specify') {
1883: $exacton = ' checked="checked" ';
1884: $containson = ' checked="checked" ';
1885: }
1.23 raeburn 1886: }
1887: }
1888: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1889: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1890:
1891: my $numinrow = 4;
1.26 raeburn 1892: my $cansrchrow = 0;
1.23 raeburn 1893: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1894: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1895: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1896: '<input type="radio" name="dirsrch_available"'.
1897: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1898: '<label><input type="radio" name="dirsrch_available"'.
1899: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1900: '</tr><tr>'.
1.30 raeburn 1901: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1902: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1903: '<input type="radio" name="dirsrch_localonly"'.
1904: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1905: '<label><input type="radio" name="dirsrch_localonly"'.
1906: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1907: '</tr>';
1.30 raeburn 1908: $$rowtotal += 2;
1.26 raeburn 1909: if (ref($usertypes) eq 'HASH') {
1910: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1911: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1912: $numinrow,$othertitle,'cansearch');
1.26 raeburn 1913: $cansrchrow = 1;
1914: }
1915: }
1916: if ($cansrchrow) {
1.30 raeburn 1917: $$rowtotal ++;
1.26 raeburn 1918: $datatable .= '<tr>';
1919: } else {
1920: $datatable .= '<tr class="LC_odd_row">';
1921: }
1.30 raeburn 1922: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1923: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1924: foreach my $title (@{$titleorder}) {
1925: if (defined($searchtitles->{$title})) {
1926: my $check = ' ';
1.93 raeburn 1927: if (ref($settings) eq 'HASH') {
1.39 raeburn 1928: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1929: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1930: $check = ' checked="checked" ';
1931: }
1.25 raeburn 1932: }
1933: }
1934: $datatable .= '<td class="LC_left_item">'.
1935: '<span class="LC_nobreak"><label>'.
1936: '<input type="checkbox" name="searchby" '.
1937: 'value="'.$title.'"'.$check.'/>'.
1938: $searchtitles->{$title}.'</label></span></td>';
1939: }
1940: }
1.26 raeburn 1941: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1942: $$rowtotal ++;
1.26 raeburn 1943: if ($cansrchrow) {
1944: $datatable .= '<tr class="LC_odd_row">';
1945: } else {
1946: $datatable .= '<tr>';
1947: }
1.30 raeburn 1948: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1949: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1950: '<span class="LC_nobreak"><label>'.
1951: '<input type="checkbox" name="searchtypes" '.
1952: $exacton.' value="exact" />'.&mt('Exact match').
1953: '</label> '.
1954: '<label><input type="checkbox" name="searchtypes" '.
1955: $beginson.' value="begins" />'.&mt('Begins with').
1956: '</label> '.
1957: '<label><input type="checkbox" name="searchtypes" '.
1958: $containson.' value="contains" />'.&mt('Contains').
1959: '</label></span></td></tr>';
1.30 raeburn 1960: $$rowtotal ++;
1.25 raeburn 1961: return $datatable;
1962: }
1963:
1.28 raeburn 1964: sub print_contacts {
1.30 raeburn 1965: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1966: my $datatable;
1967: my @contacts = ('adminemail','supportemail');
1968: my (%checked,%to,%otheremails);
1.102 raeburn 1969: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1970: 'requestsmail');
1.28 raeburn 1971: foreach my $type (@mailings) {
1972: $otheremails{$type} = '';
1973: }
1974: if (ref($settings) eq 'HASH') {
1975: foreach my $item (@contacts) {
1976: if (exists($settings->{$item})) {
1977: $to{$item} = $settings->{$item};
1978: }
1979: }
1980: foreach my $type (@mailings) {
1981: if (exists($settings->{$type})) {
1982: if (ref($settings->{$type}) eq 'HASH') {
1983: foreach my $item (@contacts) {
1984: if ($settings->{$type}{$item}) {
1985: $checked{$type}{$item} = ' checked="checked" ';
1986: }
1987: }
1988: $otheremails{$type} = $settings->{$type}{'others'};
1989: }
1.89 raeburn 1990: } elsif ($type eq 'lonstatusmail') {
1991: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1992: }
1993: }
1994: } else {
1995: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1996: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1997: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1998: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 1999: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2000: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2001: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2002: }
2003: my ($titles,$short_titles) = &contact_titles();
2004: my $rownum = 0;
2005: my $css_class;
2006: foreach my $item (@contacts) {
1.69 raeburn 2007: $rownum ++;
2008: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2009: $datatable .= '<tr'.$css_class.'>'.
2010: '<td><span class="LC_nobreak">'.$titles->{$item}.
2011: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2012: '<input type="text" name="'.$item.'" value="'.
2013: $to{$item}.'" /></td></tr>';
2014: }
2015: foreach my $type (@mailings) {
1.69 raeburn 2016: $rownum ++;
2017: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2018: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2019: '<td><span class="LC_nobreak">'.
2020: $titles->{$type}.': </span></td>'.
1.28 raeburn 2021: '<td class="LC_left_item">'.
2022: '<span class="LC_nobreak">';
2023: foreach my $item (@contacts) {
2024: $datatable .= '<label>'.
2025: '<input type="checkbox" name="'.$type.'"'.
2026: $checked{$type}{$item}.
2027: ' value="'.$item.'" />'.$short_titles->{$item}.
2028: '</label> ';
2029: }
2030: $datatable .= '</span><br />'.&mt('Others').': '.
2031: '<input type="text" name="'.$type.'_others" '.
2032: 'value="'.$otheremails{$type}.'" />'.
2033: '</td></tr>'."\n";
2034: }
1.30 raeburn 2035: $$rowtotal += $rownum;
1.28 raeburn 2036: return $datatable;
2037: }
2038:
1.102.2.7 raeburn 2039: sub radiobutton_prefs {
2040: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2041: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2042: (ref($choices) eq 'HASH'));
2043:
2044: my (%checkedon,%checkedoff,$datatable,$css_class);
2045:
2046: foreach my $item (@{$toggles}) {
2047: if ($defaultchecked->{$item} eq 'on') {
2048: $checkedon{$item} = ' checked="checked" ';
2049: $checkedoff{$item} = ' ';
2050: } elsif ($defaultchecked->{$item} eq 'off') {
2051: $checkedoff{$item} = ' checked="checked" ';
2052: $checkedon{$item} = ' ';
2053: }
2054: }
2055: if (ref($settings) eq 'HASH') {
2056: foreach my $item (@{$toggles}) {
2057: if ($settings->{$item} eq '1') {
2058: $checkedon{$item} = ' checked="checked" ';
2059: $checkedoff{$item} = ' ';
2060: } elsif ($settings->{$item} eq '0') {
2061: $checkedoff{$item} = ' checked="checked" ';
2062: $checkedon{$item} = ' ';
2063: }
2064: }
2065: }
2066: foreach my $item (@{$toggles}) {
2067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2068: $datatable .=
2069: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
2070: '</span></td>'.
2071: '<td class="LC_right_item"><span class="LC_nobreak">'.
2072: '<label><input type="radio" name="'.
2073: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2074: '</label> <label><input type="radio" name="'.$item.'" '.
2075: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2076: '</span></td>'.
2077: '</tr>';
2078: $itemcount ++;
2079: }
2080: return ($datatable,$itemcount);
2081: }
2082:
2083: sub print_coursedefaults {
2084: my ($dom,$settings,$rowtotal) = @_;
2085: my ($css_class,$datatable);
2086: my $itemcount = 1;
2087: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2088: %choices =
2089: &Apache::lonlocal::texthash (
2090: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2091: );
2092: %defaultchecked = ('canuse_pdfforms' => 'off');
2093: @toggles = ('canuse_pdfforms',);
2094: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2095: \%choices,$itemcount);
2096: $$rowtotal += $itemcount;
2097: return $datatable;
2098: }
2099:
1.28 raeburn 2100: sub contact_titles {
2101: my %titles = &Apache::lonlocal::texthash (
2102: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2103: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2104: 'errormail' => 'Error reports to be e-mailed to',
2105: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2106: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2107: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2108: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2109: );
2110: my %short_titles = &Apache::lonlocal::texthash (
2111: adminemail => 'Admin E-mail address',
2112: supportemail => 'Support E-mail',
2113: );
2114: return (\%titles,\%short_titles);
2115: }
2116:
1.72 raeburn 2117: sub tool_titles {
2118: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2119: aboutme => 'Personal Information Page',
1.86 raeburn 2120: blog => 'Blog',
2121: portfolio => 'Portfolio',
1.88 bisitz 2122: official => 'Official courses (with institutional codes)',
2123: unofficial => 'Unofficial courses',
1.98 raeburn 2124: community => 'Communities',
1.86 raeburn 2125: );
1.72 raeburn 2126: return %titles;
2127: }
2128:
1.101 raeburn 2129: sub courserequest_titles {
2130: my %titles = &Apache::lonlocal::texthash (
2131: official => 'Official',
2132: unofficial => 'Unofficial',
2133: community => 'Communities',
2134: norequest => 'Not allowed',
1.102.2.2 raeburn 2135: approval => 'Approval by Dom. Coord.',
1.101 raeburn 2136: validate => 'With validation',
2137: autolimit => 'Numerical limit',
1.102.2.2 raeburn 2138: unlimited => '(blank for unlimited)',
1.101 raeburn 2139: );
2140: return %titles;
2141: }
2142:
2143: sub courserequest_conditions {
2144: my %conditions = &Apache::lonlocal::texthash (
1.102.2.2 raeburn 2145: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 2146: validate => '(Processing of request subject to instittutional validation).',
2147: );
2148: return %conditions;
2149: }
2150:
2151:
1.27 raeburn 2152: sub print_usercreation {
1.30 raeburn 2153: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 2154: my $numinrow = 4;
1.28 raeburn 2155: my $datatable;
2156: if ($position eq 'top') {
1.30 raeburn 2157: $$rowtotal ++;
1.34 raeburn 2158: my $rowcount = 0;
1.32 raeburn 2159: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 2160: if (ref($rules) eq 'HASH') {
2161: if (keys(%{$rules}) > 0) {
1.32 raeburn 2162: $datatable .= &user_formats_row('username',$settings,$rules,
2163: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 2164: $$rowtotal ++;
1.32 raeburn 2165: $rowcount ++;
2166: }
2167: }
2168: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
2169: if (ref($idrules) eq 'HASH') {
2170: if (keys(%{$idrules}) > 0) {
2171: $datatable .= &user_formats_row('id',$settings,$idrules,
2172: $idruleorder,$numinrow,$rowcount);
2173: $$rowtotal ++;
2174: $rowcount ++;
1.28 raeburn 2175: }
2176: }
1.43 raeburn 2177: my ($emailrules,$emailruleorder) =
2178: &Apache::lonnet::inst_userrules($dom,'email');
2179: if (ref($emailrules) eq 'HASH') {
2180: if (keys(%{$emailrules}) > 0) {
2181: $datatable .= &user_formats_row('email',$settings,$emailrules,
2182: $emailruleorder,$numinrow,$rowcount);
2183: $$rowtotal ++;
2184: $rowcount ++;
2185: }
2186: }
1.39 raeburn 2187: if ($rowcount == 0) {
2188: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
2189: $$rowtotal ++;
2190: $rowcount ++;
2191: }
1.34 raeburn 2192: } elsif ($position eq 'middle') {
1.100 raeburn 2193: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 2194: my ($rules,$ruleorder) =
2195: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 2196: my %lt = &usercreation_types();
2197: my %checked;
1.50 raeburn 2198: my @selfcreate;
1.34 raeburn 2199: if (ref($settings) eq 'HASH') {
2200: if (ref($settings->{'cancreate'}) eq 'HASH') {
2201: foreach my $item (@creators) {
2202: $checked{$item} = $settings->{'cancreate'}{$item};
2203: }
1.50 raeburn 2204: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
2205: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
2206: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
2207: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
2208: @selfcreate = ('email','login','sso');
2209: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
2210: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
2211: }
2212: }
1.34 raeburn 2213: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
2214: foreach my $item (@creators) {
2215: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
2216: $checked{$item} = 'none';
2217: }
2218: }
2219: }
2220: }
2221: my $rownum = 0;
2222: foreach my $item (@creators) {
2223: $rownum ++;
1.50 raeburn 2224: if ($item ne 'selfcreate') {
2225: if ($checked{$item} eq '') {
1.43 raeburn 2226: $checked{$item} = 'any';
2227: }
1.34 raeburn 2228: }
2229: my $css_class;
2230: if ($rownum%2) {
2231: $css_class = '';
2232: } else {
2233: $css_class = ' class="LC_odd_row" ';
2234: }
2235: $datatable .= '<tr'.$css_class.'>'.
2236: '<td><span class="LC_nobreak">'.$lt{$item}.
2237: '</span></td><td align="right">';
1.50 raeburn 2238: my @options;
1.45 raeburn 2239: if ($item eq 'selfcreate') {
1.43 raeburn 2240: push(@options,('email','login','sso'));
2241: } else {
1.50 raeburn 2242: @options = ('any');
1.43 raeburn 2243: if (ref($rules) eq 'HASH') {
2244: if (keys(%{$rules}) > 0) {
2245: push(@options,('official','unofficial'));
2246: }
1.37 raeburn 2247: }
1.50 raeburn 2248: push(@options,'none');
1.37 raeburn 2249: }
2250: foreach my $option (@options) {
1.50 raeburn 2251: my $type = 'radio';
1.34 raeburn 2252: my $check = ' ';
1.50 raeburn 2253: if ($item eq 'selfcreate') {
2254: $type = 'checkbox';
2255: if (grep(/^\Q$option\E$/,@selfcreate)) {
2256: $check = ' checked="checked" ';
2257: }
2258: } else {
2259: if ($checked{$item} eq $option) {
2260: $check = ' checked="checked" ';
2261: }
1.34 raeburn 2262: }
2263: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 2264: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 2265: $item.'" value="'.$option.'"'.$check.'/> '.
2266: $lt{$option}.'</label> </span>';
2267: }
2268: $datatable .= '</td></tr>';
2269: }
1.93 raeburn 2270: my ($othertitle,$usertypes,$types) =
2271: &Apache::loncommon::sorted_inst_types($dom);
2272: if (ref($usertypes) eq 'HASH') {
2273: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 2274: my $createsettings;
2275: if (ref($settings) eq 'HASH') {
2276: $createsettings = $settings->{cancreate};
2277: }
2278: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 2279: $dom,$numinrow,$othertitle,
2280: 'statustocreate');
2281: $$rowtotal ++;
2282: }
2283: }
1.28 raeburn 2284: } else {
2285: my @contexts = ('author','course','domain');
2286: my @authtypes = ('int','krb4','krb5','loc');
2287: my %checked;
2288: if (ref($settings) eq 'HASH') {
2289: if (ref($settings->{'authtypes'}) eq 'HASH') {
2290: foreach my $item (@contexts) {
2291: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
2292: foreach my $auth (@authtypes) {
2293: if ($settings->{'authtypes'}{$item}{$auth}) {
2294: $checked{$item}{$auth} = ' checked="checked" ';
2295: }
2296: }
2297: }
2298: }
1.27 raeburn 2299: }
1.35 raeburn 2300: } else {
2301: foreach my $item (@contexts) {
1.36 raeburn 2302: foreach my $auth (@authtypes) {
1.35 raeburn 2303: $checked{$item}{$auth} = ' checked="checked" ';
2304: }
2305: }
1.27 raeburn 2306: }
1.28 raeburn 2307: my %title = &context_names();
2308: my %authname = &authtype_names();
2309: my $rownum = 0;
2310: my $css_class;
2311: foreach my $item (@contexts) {
2312: if ($rownum%2) {
2313: $css_class = '';
2314: } else {
2315: $css_class = ' class="LC_odd_row" ';
2316: }
1.30 raeburn 2317: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 2318: '<td>'.$title{$item}.
2319: '</td><td class="LC_left_item">'.
2320: '<span class="LC_nobreak">';
2321: foreach my $auth (@authtypes) {
2322: $datatable .= '<label>'.
2323: '<input type="checkbox" name="'.$item.'_auth" '.
2324: $checked{$item}{$auth}.' value="'.$auth.'" />'.
2325: $authname{$auth}.'</label> ';
2326: }
2327: $datatable .= '</span></td></tr>';
2328: $rownum ++;
1.27 raeburn 2329: }
1.30 raeburn 2330: $$rowtotal += $rownum;
1.27 raeburn 2331: }
2332: return $datatable;
2333: }
2334:
1.32 raeburn 2335: sub user_formats_row {
2336: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
2337: my $output;
2338: my %text = (
2339: 'username' => 'new usernames',
2340: 'id' => 'IDs',
1.45 raeburn 2341: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 2342: );
2343: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2344: $output = '<tr '.$css_class.'>'.
1.63 raeburn 2345: '<td><span class="LC_nobreak">';
2346: if ($type eq 'email') {
2347: $output .= &mt("Formats disallowed for $text{$type}: ");
2348: } else {
2349: $output .= &mt("Format rules to check for $text{$type}: ");
2350: }
2351: $output .= '</span></td>'.
2352: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 2353: my $rem;
2354: if (ref($ruleorder) eq 'ARRAY') {
2355: for (my $i=0; $i<@{$ruleorder}; $i++) {
2356: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
2357: my $rem = $i%($numinrow);
2358: if ($rem == 0) {
2359: if ($i > 0) {
2360: $output .= '</tr>';
2361: }
2362: $output .= '<tr>';
2363: }
2364: my $check = ' ';
1.39 raeburn 2365: if (ref($settings) eq 'HASH') {
2366: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
2367: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
2368: $check = ' checked="checked" ';
2369: }
1.27 raeburn 2370: }
2371: }
2372: $output .= '<td class="LC_left_item">'.
2373: '<span class="LC_nobreak"><label>'.
1.32 raeburn 2374: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 2375: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
2376: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
2377: }
2378: }
2379: $rem = @{$ruleorder}%($numinrow);
2380: }
2381: my $colsleft = $numinrow - $rem;
2382: if ($colsleft > 1 ) {
2383: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2384: ' </td>';
2385: } elsif ($colsleft == 1) {
2386: $output .= '<td class="LC_left_item"> </td>';
2387: }
2388: $output .= '</tr></table></td></tr>';
2389: return $output;
2390: }
2391:
1.34 raeburn 2392: sub usercreation_types {
2393: my %lt = &Apache::lonlocal::texthash (
2394: author => 'When adding a co-author',
2395: course => 'When adding a user to a course',
1.100 raeburn 2396: requestcrs => 'When requesting a course',
1.45 raeburn 2397: selfcreate => 'User creates own account',
1.34 raeburn 2398: any => 'Any',
2399: official => 'Institutional only ',
2400: unofficial => 'Non-institutional only',
1.85 schafran 2401: email => 'E-mail address',
1.43 raeburn 2402: login => 'Institutional Login',
2403: sso => 'SSO',
1.34 raeburn 2404: none => 'None',
2405: );
2406: return %lt;
1.48 raeburn 2407: }
1.34 raeburn 2408:
1.28 raeburn 2409: sub authtype_names {
2410: my %lt = &Apache::lonlocal::texthash(
2411: int => 'Internal',
2412: krb4 => 'Kerberos 4',
2413: krb5 => 'Kerberos 5',
2414: loc => 'Local',
2415: );
2416: return %lt;
2417: }
2418:
2419: sub context_names {
2420: my %context_title = &Apache::lonlocal::texthash(
2421: author => 'Creating users when an Author',
2422: course => 'Creating users when in a course',
2423: domain => 'Creating users when a Domain Coordinator',
2424: );
2425: return %context_title;
2426: }
2427:
1.33 raeburn 2428: sub print_usermodification {
2429: my ($position,$dom,$settings,$rowtotal) = @_;
2430: my $numinrow = 4;
2431: my ($context,$datatable,$rowcount);
2432: if ($position eq 'top') {
2433: $rowcount = 0;
2434: $context = 'author';
2435: foreach my $role ('ca','aa') {
2436: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2437: $numinrow,$rowcount);
2438: $$rowtotal ++;
2439: $rowcount ++;
2440: }
1.63 raeburn 2441: } elsif ($position eq 'middle') {
1.33 raeburn 2442: $context = 'course';
2443: $rowcount = 0;
2444: foreach my $role ('st','ep','ta','in','cr') {
2445: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2446: $numinrow,$rowcount);
2447: $$rowtotal ++;
2448: $rowcount ++;
2449: }
1.63 raeburn 2450: } elsif ($position eq 'bottom') {
2451: $context = 'selfcreate';
2452: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2453: $usertypes->{'default'} = $othertitle;
2454: if (ref($types) eq 'ARRAY') {
2455: push(@{$types},'default');
2456: $usertypes->{'default'} = $othertitle;
2457: foreach my $status (@{$types}) {
2458: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2459: $numinrow,$rowcount,$usertypes);
2460: $$rowtotal ++;
2461: $rowcount ++;
2462: }
2463: }
1.33 raeburn 2464: }
2465: return $datatable;
2466: }
2467:
1.43 raeburn 2468: sub print_defaults {
2469: my ($dom,$rowtotal) = @_;
1.68 raeburn 2470: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
2471: 'datelocale_def');
1.43 raeburn 2472: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
2473: my $titles = &defaults_titles();
2474: my $rownum = 0;
2475: my ($datatable,$css_class);
2476: foreach my $item (@items) {
2477: if ($rownum%2) {
2478: $css_class = '';
2479: } else {
2480: $css_class = ' class="LC_odd_row" ';
2481: }
2482: $datatable .= '<tr'.$css_class.'>'.
2483: '<td><span class="LC_nobreak">'.$titles->{$item}.
2484: '</span></td><td class="LC_right_item">';
2485: if ($item eq 'auth_def') {
2486: my @authtypes = ('internal','krb4','krb5','localauth');
2487: my %shortauth = (
2488: internal => 'int',
2489: krb4 => 'krb4',
2490: krb5 => 'krb5',
2491: localauth => 'loc'
2492: );
2493: my %authnames = &authtype_names();
2494: foreach my $auth (@authtypes) {
2495: my $checked = ' ';
2496: if ($domdefaults{$item} eq $auth) {
2497: $checked = ' checked="checked" ';
2498: }
2499: $datatable .= '<label><input type="radio" name="'.$item.
2500: '" value="'.$auth.'"'.$checked.'/>'.
2501: $authnames{$shortauth{$auth}}.'</label> ';
2502: }
1.54 raeburn 2503: } elsif ($item eq 'timezone_def') {
2504: my $includeempty = 1;
2505: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2506: } elsif ($item eq 'datelocale_def') {
2507: my $includeempty = 1;
2508: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2509: } else {
2510: $datatable .= '<input type="text" name="'.$item.'" value="'.
2511: $domdefaults{$item}.'" />';
2512: }
2513: $datatable .= '</td></tr>';
2514: $rownum ++;
2515: }
2516: $$rowtotal += $rownum;
2517: return $datatable;
2518: }
2519:
2520: sub defaults_titles {
2521: my %titles = &Apache::lonlocal::texthash (
2522: 'auth_def' => 'Default authentication type',
2523: 'auth_arg_def' => 'Default authentication argument',
2524: 'lang_def' => 'Default language',
1.54 raeburn 2525: 'timezone_def' => 'Default timezone',
1.68 raeburn 2526: 'datelocale_def' => 'Default locale for dates',
1.43 raeburn 2527: );
2528: return (\%titles);
2529: }
2530:
1.46 raeburn 2531: sub print_scantronformat {
2532: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2533: my $itemcount = 1;
1.60 raeburn 2534: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2535: %confhash);
1.46 raeburn 2536: my $switchserver = &check_switchserver($dom,$confname);
2537: my %lt = &Apache::lonlocal::texthash (
1.95 www 2538: default => 'Default bubblesheet format file error',
2539: custom => 'Custom bubblesheet format file error',
1.46 raeburn 2540: );
2541: my %scantronfiles = (
2542: default => 'default.tab',
2543: custom => 'custom.tab',
2544: );
2545: foreach my $key (keys(%scantronfiles)) {
2546: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2547: .$scantronfiles{$key};
2548: }
2549: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2550: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2551: if (!$switchserver) {
2552: my $servadm = $r->dir_config('lonAdmEMail');
2553: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2554: if ($configuserok eq 'ok') {
2555: if ($author_ok eq 'ok') {
2556: my %legacyfile = (
2557: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2558: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2559: );
2560: my %md5chk;
2561: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2562: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2563: chomp($md5chk{$type});
1.46 raeburn 2564: }
2565: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2566: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2567: ($scantronurls{$type},my $error) =
1.46 raeburn 2568: &legacy_scantronformat($r,$dom,$confname,
2569: $type,$legacyfile{$type},
2570: $scantronurls{$type},
2571: $scantronfiles{$type});
1.60 raeburn 2572: if ($error ne '') {
2573: $error{$type} = $error;
2574: }
2575: }
2576: if (keys(%error) == 0) {
2577: $is_custom = 1;
2578: $confhash{'scantron'}{'scantronformat'} =
2579: $scantronurls{'custom'};
2580: my $putresult =
2581: &Apache::lonnet::put_dom('configuration',
2582: \%confhash,$dom);
2583: if ($putresult ne 'ok') {
2584: $error{'custom'} =
2585: '<span class="LC_error">'.
2586: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2587: }
1.46 raeburn 2588: }
2589: } else {
1.60 raeburn 2590: ($scantronurls{'default'},my $error) =
1.46 raeburn 2591: &legacy_scantronformat($r,$dom,$confname,
2592: 'default',$legacyfile{'default'},
2593: $scantronurls{'default'},
2594: $scantronfiles{'default'});
1.60 raeburn 2595: if ($error eq '') {
2596: $confhash{'scantron'}{'scantronformat'} = '';
2597: my $putresult =
2598: &Apache::lonnet::put_dom('configuration',
2599: \%confhash,$dom);
2600: if ($putresult ne 'ok') {
2601: $error{'default'} =
2602: '<span class="LC_error">'.
2603: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2604: }
2605: } else {
2606: $error{'default'} = $error;
2607: }
1.46 raeburn 2608: }
2609: }
2610: }
2611: } else {
1.95 www 2612: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 2613: }
2614: }
2615: if (ref($settings) eq 'HASH') {
2616: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2617: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2618: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2619: $scantronurl = '';
2620: } else {
2621: $scantronurl = $settings->{'scantronformat'};
2622: }
2623: $is_custom = 1;
2624: } else {
2625: $scantronurl = $scantronurls{'default'};
2626: }
2627: } else {
1.60 raeburn 2628: if ($is_custom) {
2629: $scantronurl = $scantronurls{'custom'};
2630: } else {
2631: $scantronurl = $scantronurls{'default'};
2632: }
1.46 raeburn 2633: }
2634: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2635: $datatable .= '<tr'.$css_class.'>';
2636: if (!$is_custom) {
1.65 raeburn 2637: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
2638: '<span class="LC_nobreak">';
1.46 raeburn 2639: if ($scantronurl) {
2640: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.102.2.12! raeburn 2641: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 2642: } else {
2643: $datatable = &mt('File unavailable for display');
2644: }
1.65 raeburn 2645: $datatable .= '</span></td>';
1.60 raeburn 2646: if (keys(%error) == 0) {
2647: $datatable .= '<td valign="bottom">';
2648: if (!$switchserver) {
2649: $datatable .= &mt('Upload:').'<br />';
2650: }
2651: } else {
2652: my $errorstr;
2653: foreach my $key (sort(keys(%error))) {
2654: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2655: }
2656: $datatable .= '<td>'.$errorstr;
2657: }
1.46 raeburn 2658: } else {
2659: if (keys(%error) > 0) {
2660: my $errorstr;
2661: foreach my $key (sort(keys(%error))) {
2662: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2663: }
1.60 raeburn 2664: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 2665: } elsif ($scantronurl) {
1.65 raeburn 2666: $datatable .= '<td><span class="LC_nobreak">'.
2667: '<a href="'.$scantronurl.'" target="_blank">'.
1.102.2.12! raeburn 2668: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 2669: '<input type="checkbox" name="scantronformat_del"'.
2670: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
2671: '<td><span class="LC_nobreak"> '.
2672: &mt('Replace:').'</span><br />';
1.46 raeburn 2673: }
2674: }
2675: if (keys(%error) == 0) {
2676: if ($switchserver) {
2677: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2678: } else {
1.65 raeburn 2679: $datatable .='<span class="LC_nobreak"> '.
2680: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 2681: }
2682: }
2683: $datatable .= '</td></tr>';
2684: $$rowtotal ++;
2685: return $datatable;
2686: }
2687:
2688: sub legacy_scantronformat {
2689: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2690: my ($url,$error);
2691: my @statinfo = &Apache::lonnet::stat_file($newurl);
2692: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2693: (my $result,$url) =
2694: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2695: '','',$newfile);
2696: if ($result ne 'ok') {
1.102.2.12! raeburn 2697: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 2698: }
2699: }
2700: return ($url,$error);
2701: }
1.43 raeburn 2702:
1.49 raeburn 2703: sub print_coursecategories {
1.57 raeburn 2704: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2705: my $datatable;
2706: if ($position eq 'top') {
2707: my $toggle_cats_crs = ' ';
2708: my $toggle_cats_dom = ' checked="checked" ';
2709: my $can_cat_crs = ' ';
2710: my $can_cat_dom = ' checked="checked" ';
1.102.2.6 raeburn 2711: my $toggle_catscomm_comm = ' ';
2712: my $toggle_catscomm_dom = ' checked="checked" ';
2713: my $can_catcomm_comm = ' ';
2714: my $can_catcomm_dom = ' checked="checked" ';
2715:
1.57 raeburn 2716: if (ref($settings) eq 'HASH') {
2717: if ($settings->{'togglecats'} eq 'crs') {
2718: $toggle_cats_crs = $toggle_cats_dom;
2719: $toggle_cats_dom = ' ';
2720: }
2721: if ($settings->{'categorize'} eq 'crs') {
2722: $can_cat_crs = $can_cat_dom;
2723: $can_cat_dom = ' ';
2724: }
1.102.2.6 raeburn 2725: if ($settings->{'togglecatscomm'} eq 'comm') {
2726: $toggle_catscomm_comm = $toggle_catscomm_dom;
2727: $toggle_catscomm_dom = ' ';
2728: }
2729: if ($settings->{'categorizecomm'} eq 'comm') {
2730: $can_catcomm_comm = $can_catcomm_dom;
2731: $can_catcomm_dom = ' ';
2732: }
1.57 raeburn 2733: }
2734: my %title = &Apache::lonlocal::texthash (
1.102.2.6 raeburn 2735: togglecats => 'Show/Hide a course in catalog',
2736: togglecatscomm => 'Show/Hide a community in catalog',
2737: categorize => 'Assign a category to a course',
2738: categorizecomm => 'Assign a category to a community',
1.57 raeburn 2739: );
2740: my %level = &Apache::lonlocal::texthash (
1.102.2.6 raeburn 2741: dom => 'Set in Domain',
2742: crs => 'Set in Course',
2743: comm => 'Set in Community',
1.57 raeburn 2744: );
2745: $datatable = '<tr class="LC_odd_row">'.
2746: '<td>'.$title{'togglecats'}.'</td>'.
2747: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2748: '<input type="radio" name="togglecats"'.
2749: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2750: '<label><input type="radio" name="togglecats"'.
2751: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2752: '</tr><tr>'.
2753: '<td>'.$title{'categorize'}.'</td>'.
2754: '<td class="LC_right_item"><span class="LC_nobreak">'.
2755: '<label><input type="radio" name="categorize"'.
2756: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2757: '<label><input type="radio" name="categorize"'.
2758: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.102.2.6 raeburn 2759: '</tr><tr class="LC_odd_row">'.
2760: '<td>'.$title{'togglecatscomm'}.'</td>'.
2761: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2762: '<input type="radio" name="togglecatscomm"'.
2763: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2764: '<label><input type="radio" name="togglecatscomm"'.
2765: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
2766: '</tr><tr>'.
2767: '<td>'.$title{'categorizecomm'}.'</td>'.
2768: '<td class="LC_right_item"><span class="LC_nobreak">'.
2769: '<label><input type="radio" name="categorizecomm"'.
2770: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2771: '<label><input type="radio" name="categorizecomm"'.
2772: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 2773: '</tr>';
1.102.2.6 raeburn 2774: $$rowtotal += 4;
1.57 raeburn 2775: } else {
2776: my $css_class;
2777: my $itemcount = 1;
2778: my $cathash;
2779: if (ref($settings) eq 'HASH') {
2780: $cathash = $settings->{'cats'};
2781: }
2782: if (ref($cathash) eq 'HASH') {
2783: my (@cats,@trails,%allitems,%idx,@jsarray);
2784: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2785: \%allitems,\%idx,\@jsarray);
2786: my $maxdepth = scalar(@cats);
2787: my $colattrib = '';
2788: if ($maxdepth > 2) {
2789: $colattrib = ' colspan="2" ';
2790: }
2791: my @path;
2792: if (@cats > 0) {
2793: if (ref($cats[0]) eq 'ARRAY') {
2794: my $numtop = @{$cats[0]};
2795: my $maxnum = $numtop;
1.102.2.6 raeburn 2796: my %default_names = (
2797: instcode => &mt('Official courses'),
2798: communities => &mt('Communities'),
2799: );
2800:
2801: if ((!grep(/^instcode$/,@{$cats[0]})) ||
2802: ($cathash->{'instcode::0'} eq '') ||
2803: (!grep(/^communities$/,@{$cats[0]})) ||
2804: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 2805: $maxnum ++;
2806: }
2807: my $lastidx;
2808: for (my $i=0; $i<$numtop; $i++) {
2809: my $parent = $cats[0][$i];
2810: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2811: my $item = &escape($parent).'::0';
2812: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2813: $lastidx = $idx{$item};
2814: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2815: .'<select name="'.$item.'"'.$chgstr.'>';
2816: for (my $k=0; $k<=$maxnum; $k++) {
2817: my $vpos = $k+1;
2818: my $selstr;
2819: if ($k == $i) {
2820: $selstr = ' selected="selected" ';
2821: }
2822: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2823: }
2824: $datatable .= '</select></td><td>';
1.102.2.6 raeburn 2825: if ($parent eq 'instcode' || $parent eq 'communities') {
1.102.2.8 raeburn 2826: $datatable .= '<span class="LC_nobreak">'
1.102.2.6 raeburn 2827: .$default_names{$parent}.'</span>';
2828: if ($parent eq 'instcode') {
2829: $datatable .= '<br /><span class="LC_nobreak">('
2830: .&mt('with institutional codes')
2831: .')</span></td><td'.$colattrib.'>';
2832: } else {
2833: $datatable .= '<table><tr><td>';
2834: }
2835: $datatable .= '<span class="LC_nobreak">'
2836: .'<label><input type="radio" name="'
2837: .$parent.'" value="1" checked="checked" />'
2838: .&mt('Display').'</label>';
2839: if ($parent eq 'instcode') {
2840: $datatable .= ' ';
2841: } else {
2842: $datatable .= '</span></td></tr><tr><td>'
2843: .'<span class="LC_nobreak">';
2844: }
2845: $datatable .= '<label><input type="radio" name="'
2846: .$parent.'" value="0" />'
2847: .&mt('Do not display').'</label></span>';
2848: if ($parent eq 'communities') {
2849: $datatable .= '</td></tr></table>';
2850: }
2851: $datatable .= '</td>';
1.57 raeburn 2852: } else {
2853: $datatable .= $parent
2854: .' <label><input type="checkbox" name="deletecategory" '
2855: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2856: }
2857: my $depth = 1;
2858: push(@path,$parent);
2859: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2860: pop(@path);
2861: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2862: $itemcount ++;
2863: }
1.48 raeburn 2864: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2865: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2866: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2867: for (my $k=0; $k<=$maxnum; $k++) {
2868: my $vpos = $k+1;
2869: my $selstr;
1.57 raeburn 2870: if ($k == $numtop) {
1.48 raeburn 2871: $selstr = ' selected="selected" ';
2872: }
2873: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2874: }
1.59 bisitz 2875: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2876: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2877: .'</tr>'."\n";
1.48 raeburn 2878: $itemcount ++;
1.102.2.6 raeburn 2879: foreach my $default ('instcode','communities') {
2880: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
2881: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2882: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
2883: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2884: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
2885: for (my $k=0; $k<=$maxnum; $k++) {
2886: my $vpos = $k+1;
2887: my $selstr;
2888: if ($k == $maxnum) {
2889: $selstr = ' selected="selected" ';
2890: }
2891: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 2892: }
1.102.2.6 raeburn 2893: $datatable .= '</select></span></td>'.
2894: '<td><span class="LC_nobreak">'.
2895: $default_names{$default}.'</span>';
2896: if ($default eq 'instcode') {
2897: $datatable .= '<br /><span class="LC_nobreak">('
2898: .&mt('with institutional codes').')</span>';
2899: }
2900: $datatable .= '</td>'
2901: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
2902: .&mt('Display').'</label> '
2903: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
2904: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2905: }
2906: }
2907: }
1.57 raeburn 2908: } else {
2909: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2910: }
2911: } else {
1.57 raeburn 2912: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2913: .&initialize_categories($itemcount);
1.48 raeburn 2914: }
1.57 raeburn 2915: $$rowtotal += $itemcount;
1.48 raeburn 2916: }
2917: return $datatable;
2918: }
2919:
1.69 raeburn 2920: sub print_serverstatuses {
2921: my ($dom,$settings,$rowtotal) = @_;
2922: my $datatable;
2923: my @pages = &serverstatus_pages();
2924: my (%namedaccess,%machineaccess);
2925: foreach my $type (@pages) {
2926: $namedaccess{$type} = '';
2927: $machineaccess{$type}= '';
2928: }
2929: if (ref($settings) eq 'HASH') {
2930: foreach my $type (@pages) {
2931: if (exists($settings->{$type})) {
2932: if (ref($settings->{$type}) eq 'HASH') {
2933: foreach my $key (keys(%{$settings->{$type}})) {
2934: if ($key eq 'namedusers') {
2935: $namedaccess{$type} = $settings->{$type}->{$key};
2936: } elsif ($key eq 'machines') {
2937: $machineaccess{$type} = $settings->{$type}->{$key};
2938: }
2939: }
2940: }
2941: }
2942: }
2943: }
1.81 raeburn 2944: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 2945: my $rownum = 0;
2946: my $css_class;
2947: foreach my $type (@pages) {
2948: $rownum ++;
2949: $css_class = $rownum%2?' class="LC_odd_row"':'';
2950: $datatable .= '<tr'.$css_class.'>'.
2951: '<td><span class="LC_nobreak">'.
2952: $titles->{$type}.'</span></td>'.
2953: '<td class="LC_left_item">'.
2954: '<input type="text" name="'.$type.'_namedusers" '.
2955: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
2956: '<td class="LC_right_item">'.
2957: '<span class="LC_nobreak">'.
2958: '<input type="text" name="'.$type.'_machines" '.
2959: 'value="'.$machineaccess{$type}.'" size="10" />'.
2960: '</td></tr>'."\n";
2961: }
2962: $$rowtotal += $rownum;
2963: return $datatable;
2964: }
2965:
2966: sub serverstatus_pages {
2967: return ('userstatus','lonstatus','loncron','server-status','codeversions',
2968: 'clusterstatus','metadata_keywords','metadata_harvest',
1.102.2.5 raeburn 2969: 'takeoffline','takeonline','showenv','toggledebug');
1.69 raeburn 2970: }
2971:
1.49 raeburn 2972: sub coursecategories_javascript {
2973: my ($settings) = @_;
1.57 raeburn 2974: my ($output,$jstext,$cathash);
1.49 raeburn 2975: if (ref($settings) eq 'HASH') {
1.57 raeburn 2976: $cathash = $settings->{'cats'};
2977: }
2978: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2979: my (@cats,@jsarray,%idx);
1.57 raeburn 2980: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2981: if (@jsarray > 0) {
2982: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2983: for (my $i=0; $i<@jsarray; $i++) {
2984: if (ref($jsarray[$i]) eq 'ARRAY') {
2985: my $catstr = join('","',@{$jsarray[$i]});
2986: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2987: }
2988: }
2989: }
2990: } else {
2991: $jstext = ' var categories = Array(1);'."\n".
2992: ' categories[0] = Array("instcode_pos");'."\n";
2993: }
1.102.2.6 raeburn 2994: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
2995: my $communities_reserved = &mt('The name: "communities" is a reserved category');
2996: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 2997: $output = <<"ENDSCRIPT";
2998: <script type="text/javascript">
1.102.2.3 raeburn 2999: // <![CDATA[
1.49 raeburn 3000: function reorderCats(form,parent,item,idx) {
3001: var changedVal;
3002: $jstext
3003: var newpos = 'addcategory_pos';
3004: var current = new Array;
3005: if (parent == '') {
3006: var has_instcode = 0;
3007: var maxtop = categories[idx].length;
3008: for (var j=0; j<maxtop; j++) {
3009: if (categories[idx][j] == 'instcode::0') {
3010: has_instcode == 1;
3011: }
3012: }
3013: if (has_instcode == 0) {
3014: categories[idx][maxtop] = 'instcode_pos';
3015: }
3016: } else {
3017: newpos += '_'+parent;
3018: }
3019: var maxh = 1 + categories[idx].length;
3020: var current = new Array;
3021: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3022: if (item == newpos) {
3023: changedVal = newitemVal;
3024: } else {
3025: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3026: current[newitemVal] = newpos;
3027: }
3028: for (var i=0; i<categories[idx].length; i++) {
3029: var elementName = categories[idx][i];
3030: if (elementName != item) {
3031: if (form.elements[elementName]) {
3032: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3033: current[currVal] = elementName;
3034: }
3035: }
3036: }
3037: var oldVal;
3038: for (var j=0; j<maxh; j++) {
3039: if (current[j] == undefined) {
3040: oldVal = j;
3041: }
3042: }
3043: if (oldVal < changedVal) {
3044: for (var k=oldVal+1; k<=changedVal ; k++) {
3045: var elementName = current[k];
3046: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3047: }
3048: } else {
3049: for (var k=changedVal; k<oldVal; k++) {
3050: var elementName = current[k];
3051: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3052: }
3053: }
3054: return;
3055: }
1.102.2.6 raeburn 3056:
3057: function categoryCheck(form) {
3058: if (form.elements['addcategory_name'].value == 'instcode') {
3059: alert('$instcode_reserved\\n$choose_again');
3060: return false;
3061: }
3062: if (form.elements['addcategory_name'].value == 'communities') {
3063: alert('$communities_reserved\\n$choose_again');
3064: return false;
3065: }
3066: return true;
3067: }
3068:
1.102.2.3 raeburn 3069: // ]]>
1.49 raeburn 3070: </script>
3071:
3072: ENDSCRIPT
3073: return $output;
3074: }
3075:
1.48 raeburn 3076: sub initialize_categories {
3077: my ($itemcount) = @_;
1.102.2.6 raeburn 3078: my ($datatable,$css_class,$chgstr);
3079: my %default_names = (
3080: instcode => 'Official courses (with institutional codes)',
3081: communities => 'Communities',
3082: );
3083: my $select0 = ' selected="selected"';
3084: my $select1 = '';
3085: foreach my $default ('instcode','communities') {
3086: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3087: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3088: if ($default eq 'communities') {
3089: $select1 = $select0;
3090: $select0 = '';
3091: }
3092: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3093: .'<select name="'.$default.'_pos">'
3094: .'<option value="0"'.$select0.'>1</option>'
3095: .'<option value="1"'.$select1.'>2</option>'
3096: .'<option value="2">3</option></select> '
3097: .$default_names{$default}
3098: .'</span></td><td><span class="LC_nobreak">'
3099: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3100: .&mt('Display').'</label> <label>'
3101: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3102: .'</label></span></td></tr>';
1.102.2.6 raeburn 3103: $itemcount ++;
3104: }
1.48 raeburn 3105: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3106: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3107: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.102.2.6 raeburn 3108: .'<select name="addcategory_pos"'.$chgstr.'>'
3109: .'<option value="0">1</option>'
3110: .'<option value="1">2</option>'
3111: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 3112: .&mt('Add category').'</td><td>'.&mt('Name:')
3113: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3114: return $datatable;
3115: }
3116:
3117: sub build_category_rows {
1.49 raeburn 3118: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3119: my ($text,$name,$item,$chgstr);
1.48 raeburn 3120: if (ref($cats) eq 'ARRAY') {
3121: my $maxdepth = scalar(@{$cats});
3122: if (ref($cats->[$depth]) eq 'HASH') {
3123: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3124: my $numchildren = @{$cats->[$depth]{$parent}};
3125: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3126: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 3127: my ($idxnum,$parent_name,$parent_item);
3128: my $higher = $depth - 1;
3129: if ($higher == 0) {
3130: $parent_name = &escape($parent).'::'.$higher;
3131: } else {
3132: if (ref($path) eq 'ARRAY') {
3133: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3134: }
3135: }
3136: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 3137: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 3138: if ($j < $numchildren) {
1.48 raeburn 3139: $name = $cats->[$depth]{$parent}[$j];
3140: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 3141: $idxnum = $idx->{$item};
3142: } else {
3143: $name = $parent_name;
3144: $item = $parent_item;
1.48 raeburn 3145: }
1.49 raeburn 3146: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
3147: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 3148: for (my $i=0; $i<=$numchildren; $i++) {
3149: my $vpos = $i+1;
3150: my $selstr;
3151: if ($j == $i) {
3152: $selstr = ' selected="selected" ';
3153: }
3154: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
3155: }
3156: $text .= '</select> ';
3157: if ($j < $numchildren) {
3158: my $deeper = $depth+1;
3159: $text .= $name.' '
3160: .'<label><input type="checkbox" name="deletecategory" value="'
3161: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
3162: if(ref($path) eq 'ARRAY') {
3163: push(@{$path},$name);
1.49 raeburn 3164: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 3165: pop(@{$path});
3166: }
3167: } else {
1.59 bisitz 3168: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 3169: if ($j == $numchildren) {
3170: $text .= $name;
3171: } else {
3172: $text .= $item;
3173: }
3174: $text .= '" value="" />';
3175: }
3176: $text .= '</td></tr>';
3177: }
3178: $text .= '</table></td>';
3179: } else {
3180: my $higher = $depth-1;
3181: if ($higher == 0) {
3182: $name = &escape($parent).'::'.$higher;
3183: } else {
3184: if (ref($path) eq 'ARRAY') {
3185: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3186: }
3187: }
3188: my $colspan;
3189: if ($parent ne 'instcode') {
3190: $colspan = $maxdepth - $depth - 1;
3191: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
3192: }
3193: }
3194: }
3195: }
3196: return $text;
3197: }
3198:
1.33 raeburn 3199: sub modifiable_userdata_row {
1.63 raeburn 3200: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 3201: my $rolename;
1.63 raeburn 3202: if ($context eq 'selfcreate') {
3203: if (ref($usertypes) eq 'HASH') {
3204: $rolename = $usertypes->{$role};
3205: } else {
3206: $rolename = $role;
3207: }
1.33 raeburn 3208: } else {
1.63 raeburn 3209: if ($role eq 'cr') {
3210: $rolename = &mt('Custom role');
3211: } else {
3212: $rolename = &Apache::lonnet::plaintext($role);
3213: }
1.33 raeburn 3214: }
3215: my @fields = ('lastname','firstname','middlename','generation',
3216: 'permanentemail','id');
3217: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3218: my $output;
3219: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3220: $output = '<tr '.$css_class.'>'.
3221: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
3222: '<td class="LC_left_item" colspan="2"><table>';
3223: my $rem;
3224: my %checks;
3225: if (ref($settings) eq 'HASH') {
3226: if (ref($settings->{$context}) eq 'HASH') {
3227: if (ref($settings->{$context}->{$role}) eq 'HASH') {
3228: foreach my $field (@fields) {
3229: if ($settings->{$context}->{$role}->{$field}) {
3230: $checks{$field} = ' checked="checked" ';
3231: }
3232: }
3233: }
3234: }
3235: }
3236: for (my $i=0; $i<@fields; $i++) {
3237: my $rem = $i%($numinrow);
3238: if ($rem == 0) {
3239: if ($i > 0) {
3240: $output .= '</tr>';
3241: }
3242: $output .= '<tr>';
3243: }
3244: my $check = ' ';
3245: if (exists($checks{$fields[$i]})) {
3246: $check = $checks{$fields[$i]}
3247: } else {
3248: if ($role eq 'st') {
3249: if (ref($settings) ne 'HASH') {
3250: $check = ' checked="checked" ';
3251: }
3252: }
3253: }
3254: $output .= '<td class="LC_left_item">'.
3255: '<span class="LC_nobreak"><label>'.
3256: '<input type="checkbox" name="canmodify_'.$role.'" '.
3257: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
3258: '</label></span></td>';
3259: $rem = @fields%($numinrow);
3260: }
3261: my $colsleft = $numinrow - $rem;
3262: if ($colsleft > 1 ) {
3263: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3264: ' </td>';
3265: } elsif ($colsleft == 1) {
3266: $output .= '<td class="LC_left_item"> </td>';
3267: }
3268: $output .= '</tr></table></td></tr>';
3269: return $output;
3270: }
1.28 raeburn 3271:
1.93 raeburn 3272: sub insttypes_row {
3273: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
3274: my %lt = &Apache::lonlocal::texthash (
3275: cansearch => 'Users allowed to search',
3276: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.102.2.12! raeburn 3277: lockablenames => 'User preference to lock name',
1.93 raeburn 3278: );
3279: my $showdom;
3280: if ($context eq 'cansearch') {
3281: $showdom = ' ('.$dom.')';
3282: }
1.25 raeburn 3283: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 3284: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 3285: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 3286: my $rem;
3287: if (ref($types) eq 'ARRAY') {
3288: for (my $i=0; $i<@{$types}; $i++) {
3289: if (defined($usertypes->{$types->[$i]})) {
3290: my $rem = $i%($numinrow);
3291: if ($rem == 0) {
3292: if ($i > 0) {
3293: $output .= '</tr>';
3294: }
3295: $output .= '<tr>';
1.23 raeburn 3296: }
1.26 raeburn 3297: my $check = ' ';
1.99 raeburn 3298: if (ref($settings) eq 'HASH') {
3299: if (ref($settings->{$context}) eq 'ARRAY') {
3300: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
3301: $check = ' checked="checked" ';
3302: }
3303: } elsif ($context eq 'statustocreate') {
1.26 raeburn 3304: $check = ' checked="checked" ';
3305: }
1.23 raeburn 3306: }
1.26 raeburn 3307: $output .= '<td class="LC_left_item">'.
3308: '<span class="LC_nobreak"><label>'.
1.93 raeburn 3309: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 3310: 'value="'.$types->[$i].'"'.$check.'/>'.
3311: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 3312: }
3313: }
1.26 raeburn 3314: $rem = @{$types}%($numinrow);
1.23 raeburn 3315: }
3316: my $colsleft = $numinrow - $rem;
1.102.2.12! raeburn 3317: if (($rem == 0) && (@{$types} > 0)) {
! 3318: $output .= '<tr>';
! 3319: }
1.23 raeburn 3320: if ($colsleft > 1) {
1.25 raeburn 3321: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 3322: } else {
1.25 raeburn 3323: $output .= '<td class="LC_left_item">';
1.23 raeburn 3324: }
3325: my $defcheck = ' ';
1.99 raeburn 3326: if (ref($settings) eq 'HASH') {
3327: if (ref($settings->{$context}) eq 'ARRAY') {
3328: if (grep(/^default$/,@{$settings->{$context}})) {
3329: $defcheck = ' checked="checked" ';
3330: }
3331: } elsif ($context eq 'statustocreate') {
1.26 raeburn 3332: $defcheck = ' checked="checked" ';
3333: }
1.23 raeburn 3334: }
1.25 raeburn 3335: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 3336: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 3337: 'value="default"'.$defcheck.'/>'.
3338: $othertitle.'</label></span></td>'.
3339: '</tr></table></td></tr>';
3340: return $output;
1.23 raeburn 3341: }
3342:
3343: sub sorted_searchtitles {
3344: my %searchtitles = &Apache::lonlocal::texthash(
3345: 'uname' => 'username',
3346: 'lastname' => 'last name',
3347: 'lastfirst' => 'last name, first name',
3348: );
3349: my @titleorder = ('uname','lastname','lastfirst');
3350: return (\%searchtitles,\@titleorder);
3351: }
3352:
1.25 raeburn 3353: sub sorted_searchtypes {
3354: my %srchtypes_desc = (
3355: exact => 'is exact match',
3356: contains => 'contains ..',
3357: begins => 'begins with ..',
3358: );
3359: my @srchtypeorder = ('exact','begins','contains');
3360: return (\%srchtypes_desc,\@srchtypeorder);
3361: }
3362:
1.3 raeburn 3363: sub usertype_update_row {
3364: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
3365: my $datatable;
3366: my $numinrow = 4;
3367: foreach my $type (@{$types}) {
3368: if (defined($usertypes->{$type})) {
3369: $$rownums ++;
3370: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
3371: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
3372: '</td><td class="LC_left_item"><table>';
3373: for (my $i=0; $i<@{$fields}; $i++) {
3374: my $rem = $i%($numinrow);
3375: if ($rem == 0) {
3376: if ($i > 0) {
3377: $datatable .= '</tr>';
3378: }
3379: $datatable .= '<tr>';
3380: }
3381: my $check = ' ';
1.39 raeburn 3382: if (ref($settings) eq 'HASH') {
3383: if (ref($settings->{'fields'}) eq 'HASH') {
3384: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
3385: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
3386: $check = ' checked="checked" ';
3387: }
1.3 raeburn 3388: }
3389: }
3390: }
3391:
3392: if ($i == @{$fields}-1) {
3393: my $colsleft = $numinrow - $rem;
3394: if ($colsleft > 1) {
3395: $datatable .= '<td colspan="'.$colsleft.'">';
3396: } else {
3397: $datatable .= '<td>';
3398: }
3399: } else {
3400: $datatable .= '<td>';
3401: }
1.8 raeburn 3402: $datatable .= '<span class="LC_nobreak"><label>'.
3403: '<input type="checkbox" name="updateable_'.$type.
3404: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
3405: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 3406: }
3407: $datatable .= '</tr></table></td></tr>';
3408: }
3409: }
3410: return $datatable;
1.1 raeburn 3411: }
3412:
3413: sub modify_login {
1.9 raeburn 3414: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 3415: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 3416: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 3417: adminmail => 'Display administrator E-mail address',
1.43 raeburn 3418: newuser => 'Link for visitors to create a user account',
1.41 raeburn 3419: loginheader => 'Log-in box header');
1.3 raeburn 3420: my @offon = ('off','on');
1.102.2.10 raeburn 3421: my %curr_loginvia;
3422: if (ref($domconfig{login}) eq 'HASH') {
3423: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
3424: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
3425: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
3426: }
3427: }
3428: }
1.6 raeburn 3429: my %loginhash;
1.9 raeburn 3430: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
3431: \%domconfig,\%loginhash);
1.43 raeburn 3432: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3433: foreach my $item (@toggles) {
3434: $loginhash{login}{$item} = $env{'form.'.$item};
3435: }
1.41 raeburn 3436: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 3437: if (ref($colchanges{'login'}) eq 'HASH') {
3438: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
3439: \%loginhash);
3440: }
1.102.2.10 raeburn 3441:
3442: my %servers = &dom_servers($dom);
3443: my @loginvia_attribs = ('serverpath','custompath','exempt');
3444: if (keys(%servers) > 1) {
3445: foreach my $lonhost (keys(%servers)) {
3446: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
3447: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
3448: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
3449: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
3450: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
3451: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3452: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3453: $changes{'loginvia'}{$lonhost} = 1;
3454: } else {
3455: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
3456: $changes{'loginvia'}{$lonhost} = 1;
3457: }
3458: } else {
3459: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3460: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3461: $changes{'loginvia'}{$lonhost} = 1;
3462: }
3463: }
3464: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
3465: foreach my $item (@loginvia_attribs) {
3466: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
3467: }
3468: } else {
3469: foreach my $item (@loginvia_attribs) {
3470: my $new = $env{'form.'.$lonhost.'_'.$item};
3471: if (($item eq 'serverpath') && ($new eq 'custom')) {
3472: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
3473: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
3474: $new = '/';
3475: }
3476: }
3477: if (($item eq 'custompath') &&
3478: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
3479: $new = '';
3480: }
3481: if ($new ne $curr_loginvia{$lonhost}{$item}) {
3482: $changes{'loginvia'}{$lonhost} = 1;
3483: }
3484: if ($item eq 'exempt') {
3485: $new =~ s/^\s+//;
3486: $new =~ s/\s+$//;
3487: my @poss_ips = split(/\s*[,:]\s*/,$new);
3488: my @okips;
3489: foreach my $ip (@poss_ips) {
3490: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
3491: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
3492: push(@okips,$ip);
3493: }
3494: }
3495: }
3496: if (@okips > 0) {
3497: $new = join(',',@okips);
3498: } else {
3499: $new = '';
3500: }
3501: }
3502:
3503: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
3504: }
3505: }
3506: } else {
3507: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3508: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3509: $changes{'loginvia'}{$lonhost} = 1;
3510: foreach my $item (@loginvia_attribs) {
3511: my $new = $env{'form.'.$lonhost.'_'.$item};
3512: if (($item eq 'serverpath') && ($new eq 'custom')) {
3513: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
3514: $new = '/';
3515: }
3516: }
3517: if (($item eq 'custompath') &&
3518: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
3519: $new = '';
3520: }
3521: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
3522: }
3523: }
3524: }
3525: }
3526: }
3527:
1.1 raeburn 3528: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
3529: $dom);
3530: if ($putresult eq 'ok') {
1.43 raeburn 3531: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3532: my %defaultchecked = (
3533: 'coursecatalog' => 'on',
3534: 'adminmail' => 'off',
1.43 raeburn 3535: 'newuser' => 'off',
1.42 raeburn 3536: );
1.55 raeburn 3537: if (ref($domconfig{'login'}) eq 'HASH') {
3538: foreach my $item (@toggles) {
3539: if ($defaultchecked{$item} eq 'on') {
3540: if (($domconfig{'login'}{$item} eq '0') &&
3541: ($env{'form.'.$item} eq '1')) {
3542: $changes{$item} = 1;
3543: } elsif (($domconfig{'login'}{$item} eq '' ||
3544: $domconfig{'login'}{$item} eq '1') &&
3545: ($env{'form.'.$item} eq '0')) {
3546: $changes{$item} = 1;
3547: }
3548: } elsif ($defaultchecked{$item} eq 'off') {
3549: if (($domconfig{'login'}{$item} eq '1') &&
3550: ($env{'form.'.$item} eq '0')) {
3551: $changes{$item} = 1;
3552: } elsif (($domconfig{'login'}{$item} eq '' ||
3553: $domconfig{'login'}{$item} eq '0') &&
3554: ($env{'form.'.$item} eq '1')) {
3555: $changes{$item} = 1;
3556: }
1.42 raeburn 3557: }
3558: }
1.55 raeburn 3559: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
3560: ($env{'form.loginheader'} eq 'image')) {
3561: $changes{'loginheader'} = 1;
3562: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
3563: $domconfig{'login'}{'loginheader'} eq 'image') &&
3564: ($env{'form.loginheader'} eq 'text')) {
3565: $changes{'loginheader'} = 1;
3566: }
1.41 raeburn 3567: }
1.6 raeburn 3568: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 3569: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 3570: $resulttext = &mt('Changes made:').'<ul>';
3571: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 3572: if ($item eq 'loginheader') {
3573: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
1.102.2.10 raeburn 3574: } elsif ($item eq 'loginvia') {
3575: if (ref($changes{$item}) eq 'HASH') {
3576: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
3577: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
3578: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
3579: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
3580: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
3581: $protocol = 'http' if ($protocol ne 'https');
3582: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
3583:
3584: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
3585: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
3586: } else {
3587: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
3588: }
3589: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
3590: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
3591: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
3592: }
3593: $resulttext .= '</li>';
3594: } else {
3595: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
3596: }
3597: } else {
3598: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
3599: }
3600: }
3601: $resulttext .= '</ul></li>';
3602: }
1.41 raeburn 3603: } else {
3604: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
3605: }
1.1 raeburn 3606: }
1.6 raeburn 3607: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 3608: } else {
3609: $resulttext = &mt('No changes made to log-in page settings');
3610: }
3611: } else {
1.11 albertel 3612: $resulttext = '<span class="LC_error">'.
3613: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3614: }
1.6 raeburn 3615: if ($errors) {
1.9 raeburn 3616: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 3617: $errors.'</ul>';
3618: }
3619: return $resulttext;
3620: }
3621:
3622: sub color_font_choices {
3623: my %choices =
3624: &Apache::lonlocal::texthash (
3625: img => "Header",
3626: bgs => "Background colors",
3627: links => "Link colors",
1.55 raeburn 3628: images => "Images",
1.6 raeburn 3629: font => "Font color",
1.76 raeburn 3630: pgbg => "Page",
1.6 raeburn 3631: tabbg => "Header",
3632: sidebg => "Border",
3633: link => "Link",
3634: alink => "Active link",
3635: vlink => "Visited link",
3636: );
3637: return %choices;
3638: }
3639:
3640: sub modify_rolecolors {
1.9 raeburn 3641: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 3642: my ($resulttext,%rolehash);
3643: $rolehash{'rolecolors'} = {};
1.55 raeburn 3644: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
3645: if ($domconfig{'rolecolors'} eq '') {
3646: $domconfig{'rolecolors'} = {};
3647: }
3648: }
1.9 raeburn 3649: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 3650: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
3651: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
3652: $dom);
3653: if ($putresult eq 'ok') {
3654: if (keys(%changes) > 0) {
1.41 raeburn 3655: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 3656: $resulttext = &display_colorchgs($dom,\%changes,$roles,
3657: $rolehash{'rolecolors'});
3658: } else {
3659: $resulttext = &mt('No changes made to default color schemes');
3660: }
3661: } else {
1.11 albertel 3662: $resulttext = '<span class="LC_error">'.
3663: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 3664: }
3665: if ($errors) {
3666: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
3667: $errors.'</ul>';
3668: }
3669: return $resulttext;
3670: }
3671:
3672: sub modify_colors {
1.9 raeburn 3673: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 3674: my (%changes,%choices);
1.51 raeburn 3675: my @bgs;
1.6 raeburn 3676: my @links = ('link','alink','vlink');
1.41 raeburn 3677: my @logintext;
1.6 raeburn 3678: my @images;
3679: my $servadm = $r->dir_config('lonAdmEMail');
3680: my $errors;
3681: foreach my $role (@{$roles}) {
3682: if ($role eq 'login') {
1.12 raeburn 3683: %choices = &login_choices();
1.41 raeburn 3684: @logintext = ('textcol','bgcol');
1.12 raeburn 3685: } else {
3686: %choices = &color_font_choices();
3687: }
3688: if ($role eq 'login') {
1.41 raeburn 3689: @images = ('img','logo','domlogo','login');
1.51 raeburn 3690: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 3691: } else {
3692: @images = ('img');
1.51 raeburn 3693: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 3694: }
3695: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 3696: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 3697: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
3698: }
1.46 raeburn 3699: my ($configuserok,$author_ok,$switchserver) =
3700: &config_check($dom,$confname,$servadm);
1.9 raeburn 3701: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 3702: if (ref($domconfig->{$role}) ne 'HASH') {
3703: $domconfig->{$role} = {};
3704: }
1.8 raeburn 3705: foreach my $img (@images) {
1.70 raeburn 3706: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
3707: if (defined($env{'form.login_showlogo_'.$img})) {
3708: $confhash->{$role}{'showlogo'}{$img} = 1;
3709: } else {
3710: $confhash->{$role}{'showlogo'}{$img} = 0;
3711: }
3712: }
1.18 albertel 3713: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
3714: && !defined($domconfig->{$role}{$img})
3715: && !$env{'form.'.$role.'_del_'.$img}
3716: && $env{'form.'.$role.'_import_'.$img}) {
3717: # import the old configured image from the .tab setting
3718: # if they haven't provided a new one
3719: $domconfig->{$role}{$img} =
3720: $env{'form.'.$role.'_import_'.$img};
3721: }
1.6 raeburn 3722: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 3723: my $error;
1.6 raeburn 3724: if ($configuserok eq 'ok') {
1.9 raeburn 3725: if ($switchserver) {
1.12 raeburn 3726: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 3727: } else {
3728: if ($author_ok eq 'ok') {
3729: my ($result,$logourl) =
3730: &publishlogo($r,'upload',$role.'_'.$img,
3731: $dom,$confname,$img,$width,$height);
3732: if ($result eq 'ok') {
3733: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 3734: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3735: } else {
1.12 raeburn 3736: $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 3737: }
3738: } else {
1.46 raeburn 3739: $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 3740: }
3741: }
3742: } else {
1.46 raeburn 3743: $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 3744: }
3745: if ($error) {
1.8 raeburn 3746: &Apache::lonnet::logthis($error);
1.11 albertel 3747: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 3748: }
3749: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 3750: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
3751: my $error;
3752: if ($configuserok eq 'ok') {
3753: # is confname an author?
3754: if ($switchserver eq '') {
3755: if ($author_ok eq 'ok') {
3756: my ($result,$logourl) =
3757: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3758: $dom,$confname,$img,$width,$height);
3759: if ($result eq 'ok') {
3760: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3761: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3762: }
3763: }
3764: }
3765: }
1.6 raeburn 3766: }
3767: }
3768: }
3769: if (ref($domconfig) eq 'HASH') {
3770: if (ref($domconfig->{$role}) eq 'HASH') {
3771: foreach my $img (@images) {
3772: if ($domconfig->{$role}{$img} ne '') {
3773: if ($env{'form.'.$role.'_del_'.$img}) {
3774: $confhash->{$role}{$img} = '';
1.12 raeburn 3775: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3776: } else {
1.9 raeburn 3777: if ($confhash->{$role}{$img} eq '') {
3778: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3779: }
1.6 raeburn 3780: }
3781: } else {
3782: if ($env{'form.'.$role.'_del_'.$img}) {
3783: $confhash->{$role}{$img} = '';
1.12 raeburn 3784: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3785: }
3786: }
1.70 raeburn 3787: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3788: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3789: if ($confhash->{$role}{'showlogo'}{$img} ne
3790: $domconfig->{$role}{'showlogo'}{$img}) {
3791: $changes{$role}{'showlogo'}{$img} = 1;
3792: }
3793: } else {
3794: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3795: $changes{$role}{'showlogo'}{$img} = 1;
3796: }
3797: }
3798: }
3799: }
1.6 raeburn 3800: if ($domconfig->{$role}{'font'} ne '') {
3801: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3802: $changes{$role}{'font'} = 1;
3803: }
3804: } else {
3805: if ($confhash->{$role}{'font'}) {
3806: $changes{$role}{'font'} = 1;
3807: }
3808: }
3809: foreach my $item (@bgs) {
3810: if ($domconfig->{$role}{$item} ne '') {
3811: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3812: $changes{$role}{'bgs'}{$item} = 1;
3813: }
3814: } else {
3815: if ($confhash->{$role}{$item}) {
3816: $changes{$role}{'bgs'}{$item} = 1;
3817: }
3818: }
3819: }
3820: foreach my $item (@links) {
3821: if ($domconfig->{$role}{$item} ne '') {
3822: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3823: $changes{$role}{'links'}{$item} = 1;
3824: }
3825: } else {
3826: if ($confhash->{$role}{$item}) {
3827: $changes{$role}{'links'}{$item} = 1;
3828: }
3829: }
3830: }
1.41 raeburn 3831: foreach my $item (@logintext) {
3832: if ($domconfig->{$role}{$item} ne '') {
3833: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3834: $changes{$role}{'logintext'}{$item} = 1;
3835: }
3836: } else {
3837: if ($confhash->{$role}{$item}) {
3838: $changes{$role}{'logintext'}{$item} = 1;
3839: }
3840: }
3841: }
1.6 raeburn 3842: } else {
3843: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3844: \@logintext,$confhash,\%changes);
1.6 raeburn 3845: }
3846: } else {
3847: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3848: \@logintext,$confhash,\%changes);
1.6 raeburn 3849: }
3850: }
3851: return ($errors,%changes);
3852: }
3853:
1.46 raeburn 3854: sub config_check {
3855: my ($dom,$confname,$servadm) = @_;
3856: my ($configuserok,$author_ok,$switchserver,%currroles);
3857: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3858: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3859: $confname,$servadm);
3860: if ($configuserok eq 'ok') {
3861: $switchserver = &check_switchserver($dom,$confname);
3862: if ($switchserver eq '') {
3863: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3864: }
3865: }
3866: return ($configuserok,$author_ok,$switchserver);
3867: }
3868:
1.6 raeburn 3869: sub default_change_checker {
1.41 raeburn 3870: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3871: foreach my $item (@{$links}) {
3872: if ($confhash->{$role}{$item}) {
3873: $changes->{$role}{'links'}{$item} = 1;
3874: }
3875: }
3876: foreach my $item (@{$bgs}) {
3877: if ($confhash->{$role}{$item}) {
3878: $changes->{$role}{'bgs'}{$item} = 1;
3879: }
3880: }
1.41 raeburn 3881: foreach my $item (@{$logintext}) {
3882: if ($confhash->{$role}{$item}) {
3883: $changes->{$role}{'logintext'}{$item} = 1;
3884: }
3885: }
1.6 raeburn 3886: foreach my $img (@{$images}) {
3887: if ($env{'form.'.$role.'_del_'.$img}) {
3888: $confhash->{$role}{$img} = '';
1.12 raeburn 3889: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3890: }
1.70 raeburn 3891: if ($role eq 'login') {
3892: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3893: $changes->{$role}{'showlogo'}{$img} = 1;
3894: }
3895: }
1.6 raeburn 3896: }
3897: if ($confhash->{$role}{'font'}) {
3898: $changes->{$role}{'font'} = 1;
3899: }
1.48 raeburn 3900: }
1.6 raeburn 3901:
3902: sub display_colorchgs {
3903: my ($dom,$changes,$roles,$confhash) = @_;
3904: my (%choices,$resulttext);
3905: if (!grep(/^login$/,@{$roles})) {
3906: $resulttext = &mt('Changes made:').'<br />';
3907: }
3908: foreach my $role (@{$roles}) {
3909: if ($role eq 'login') {
3910: %choices = &login_choices();
3911: } else {
3912: %choices = &color_font_choices();
3913: }
3914: if (ref($changes->{$role}) eq 'HASH') {
3915: if ($role ne 'login') {
3916: $resulttext .= '<h4>'.&mt($role).'</h4>';
3917: }
3918: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3919: if ($role ne 'login') {
3920: $resulttext .= '<ul>';
3921: }
3922: if (ref($changes->{$role}{$key}) eq 'HASH') {
3923: if ($role ne 'login') {
3924: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3925: }
3926: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3927: if (($role eq 'login') && ($key eq 'showlogo')) {
3928: if ($confhash->{$role}{$key}{$item}) {
3929: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3930: } else {
3931: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3932: }
3933: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3934: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3935: } else {
1.12 raeburn 3936: my $newitem = $confhash->{$role}{$item};
3937: if ($key eq 'images') {
3938: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3939: }
3940: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3941: }
3942: }
3943: if ($role ne 'login') {
3944: $resulttext .= '</ul></li>';
3945: }
3946: } else {
3947: if ($confhash->{$role}{$key} eq '') {
3948: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3949: } else {
3950: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3951: }
3952: }
3953: if ($role ne 'login') {
3954: $resulttext .= '</ul>';
3955: }
3956: }
3957: }
3958: }
1.3 raeburn 3959: return $resulttext;
1.1 raeburn 3960: }
3961:
1.9 raeburn 3962: sub thumb_dimensions {
3963: return ('200','50');
3964: }
3965:
1.16 raeburn 3966: sub check_dimensions {
3967: my ($inputfile) = @_;
3968: my ($fullwidth,$fullheight);
3969: if ($inputfile =~ m|^[/\w.\-]+$|) {
3970: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3971: my $imageinfo = <PIPE>;
3972: if (!close(PIPE)) {
3973: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3974: }
3975: chomp($imageinfo);
3976: my ($fullsize) =
1.21 raeburn 3977: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3978: if ($fullsize) {
3979: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3980: }
3981: }
3982: }
3983: return ($fullwidth,$fullheight);
3984: }
3985:
1.9 raeburn 3986: sub check_configuser {
3987: my ($uhome,$dom,$confname,$servadm) = @_;
3988: my ($configuserok,%currroles);
3989: if ($uhome eq 'no_host') {
3990: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3991: my $configpass = &LONCAPA::Enrollment::create_password();
3992: $configuserok =
3993: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3994: $configpass,'','','','','',undef,$servadm);
3995: } else {
3996: $configuserok = 'ok';
3997: %currroles =
3998: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3999: }
4000: return ($configuserok,%currroles);
4001: }
4002:
4003: sub check_authorstatus {
4004: my ($dom,$confname,%currroles) = @_;
4005: my $author_ok;
1.40 raeburn 4006: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4007: my $start = time;
4008: my $end = 0;
4009: $author_ok =
4010: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4011: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4012: } else {
4013: $author_ok = 'ok';
4014: }
4015: return $author_ok;
4016: }
4017:
4018: sub publishlogo {
1.46 raeburn 4019: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4020: my ($output,$fname,$logourl);
4021: if ($action eq 'upload') {
4022: $fname=$env{'form.'.$formname.'.filename'};
4023: chop($env{'form.'.$formname});
4024: } else {
4025: ($fname) = ($formname =~ /([^\/]+)$/);
4026: }
1.46 raeburn 4027: if ($savefileas ne '') {
4028: $fname = $savefileas;
4029: }
1.9 raeburn 4030: $fname=&Apache::lonnet::clean_filename($fname);
4031: # See if there is anything left
4032: unless ($fname) { return ('error: no uploaded file'); }
4033: $fname="$subdir/$fname";
4034: my $filepath='/home/'.$confname.'/public_html';
4035: my ($fnamepath,$file,$fetchthumb);
4036: $file=$fname;
4037: if ($fname=~m|/|) {
4038: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4039: }
4040: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4041: my $count;
4042: for ($count=4;$count<=$#parts;$count++) {
4043: $filepath.="/$parts[$count]";
4044: if ((-e $filepath)!=1) {
4045: mkdir($filepath,02770);
4046: }
4047: }
4048: # Check for bad extension and disallow upload
4049: if ($file=~/\.(\w+)$/ &&
4050: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4051: $output =
4052: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4053: } elsif ($file=~/\.(\w+)$/ &&
4054: !defined(&Apache::loncommon::fileembstyle($1))) {
4055: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4056: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4057: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 4058: } elsif (-d "$filepath/$file") {
4059: $output = &mt('File name is a directory name - rename the file and re-upload');
4060: } else {
4061: my $source = $filepath.'/'.$file;
4062: my $logfile;
4063: if (!open($logfile,">>$source".'.log')) {
4064: return (&mt('No write permission to Construction Space'));
4065: }
4066: print $logfile
4067: "\n================= Publish ".localtime()." ================\n".
4068: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4069: # Save the file
4070: if (!open(FH,'>'.$source)) {
4071: &Apache::lonnet::logthis('Failed to create '.$source);
4072: return (&mt('Failed to create file'));
4073: }
4074: if ($action eq 'upload') {
4075: if (!print FH ($env{'form.'.$formname})) {
4076: &Apache::lonnet::logthis('Failed to write to '.$source);
4077: return (&mt('Failed to write file'));
4078: }
4079: } else {
4080: my $original = &Apache::lonnet::filelocation('',$formname);
4081: if(!copy($original,$source)) {
4082: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4083: return (&mt('Failed to write file'));
4084: }
4085: }
4086: close(FH);
4087: chmod(0660, $source); # Permissions to rw-rw---.
4088:
4089: my $docroot=$r->dir_config('lonDocRoot');
4090: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4091: my $copyfile=$targetdir.'/'.$file;
4092:
4093: my @parts=split(/\//,$targetdir);
4094: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4095: for (my $count=5;$count<=$#parts;$count++) {
4096: $path.="/$parts[$count]";
4097: if (!-e $path) {
4098: print $logfile "\nCreating directory ".$path;
4099: mkdir($path,02770);
4100: }
4101: }
4102: my $versionresult;
4103: if (-e $copyfile) {
4104: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4105: } else {
4106: $versionresult = 'ok';
4107: }
4108: if ($versionresult eq 'ok') {
4109: if (copy($source,$copyfile)) {
4110: print $logfile "\nCopied original source to ".$copyfile."\n";
4111: $output = 'ok';
4112: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4113: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
4114: } else {
4115: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4116: $output = &mt('Failed to copy file to RES space').", $!";
4117: }
4118: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
4119: my $inputfile = $filepath.'/'.$file;
4120: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 4121: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
4122: if ($fullwidth ne '' && $fullheight ne '') {
4123: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
4124: my $thumbsize = $thumbwidth.'x'.$thumbheight;
4125: system("convert -sample $thumbsize $inputfile $outfile");
4126: chmod(0660, $filepath.'/tn-'.$file);
4127: if (-e $outfile) {
4128: my $copyfile=$targetdir.'/tn-'.$file;
4129: if (copy($outfile,$copyfile)) {
4130: print $logfile "\nCopied source to ".$copyfile."\n";
4131: &write_metadata($dom,$confname,$formname,
4132: $targetdir,'tn-'.$file,$logfile);
4133: } else {
4134: print $logfile "\nUnable to write ".$copyfile.
4135: ':'.$!."\n";
4136: }
4137: }
1.9 raeburn 4138: }
4139: }
4140: }
4141: } else {
4142: $output = $versionresult;
4143: }
4144: }
4145: return ($output,$logourl);
4146: }
4147:
4148: sub logo_versioning {
4149: my ($targetdir,$file,$logfile) = @_;
4150: my $target = $targetdir.'/'.$file;
4151: my ($maxversion,$fn,$extn,$output);
4152: $maxversion = 0;
4153: if ($file =~ /^(.+)\.(\w+)$/) {
4154: $fn=$1;
4155: $extn=$2;
4156: }
4157: opendir(DIR,$targetdir);
4158: while (my $filename=readdir(DIR)) {
4159: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
4160: $maxversion=($1>$maxversion)?$1:$maxversion;
4161: }
4162: }
4163: $maxversion++;
4164: print $logfile "\nCreating old version ".$maxversion."\n";
4165: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
4166: if (copy($target,$copyfile)) {
4167: print $logfile "Copied old target to ".$copyfile."\n";
4168: $copyfile=$copyfile.'.meta';
4169: if (copy($target.'.meta',$copyfile)) {
4170: print $logfile "Copied old target metadata to ".$copyfile."\n";
4171: $output = 'ok';
4172: } else {
4173: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
4174: $output = &mt('Failed to copy old meta').", $!, ";
4175: }
4176: } else {
4177: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
4178: $output = &mt('Failed to copy old target').", $!, ";
4179: }
4180: return $output;
4181: }
4182:
4183: sub write_metadata {
4184: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
4185: my (%metadatafields,%metadatakeys,$output);
4186: $metadatafields{'title'}=$formname;
4187: $metadatafields{'creationdate'}=time;
4188: $metadatafields{'lastrevisiondate'}=time;
4189: $metadatafields{'copyright'}='public';
4190: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
4191: $env{'user.domain'};
4192: $metadatafields{'authorspace'}=$confname.':'.$dom;
4193: $metadatafields{'domain'}=$dom;
4194: {
4195: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
4196: my $mfh;
4197: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
4198: $output = &mt('Could not write metadata');
4199: }
4200: foreach (sort keys %metadatafields) {
4201: unless ($_=~/\./) {
4202: my $unikey=$_;
4203: $unikey=~/^([A-Za-z]+)/;
4204: my $tag=$1;
4205: $tag=~tr/A-Z/a-z/;
4206: print $mfh "\n\<$tag";
4207: foreach (split(/\,/,$metadatakeys{$unikey})) {
4208: my $value=$metadatafields{$unikey.'.'.$_};
4209: $value=~s/\"/\'\'/g;
4210: print $mfh ' '.$_.'="'.$value.'"';
4211: }
4212: print $mfh '>'.
4213: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
4214: .'</'.$tag.'>';
4215: }
4216: }
4217: $output = 'ok';
4218: print $logfile "\nWrote metadata";
4219: close($mfh);
4220: }
4221: }
4222:
4223: sub check_switchserver {
4224: my ($dom,$confname) = @_;
4225: my ($allowed,$switchserver);
4226: my $home = &Apache::lonnet::homeserver($confname,$dom);
4227: if ($home eq 'no_host') {
4228: $home = &Apache::lonnet::domain($dom,'primary');
4229: }
4230: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 4231: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
4232: if (!$allowed) {
4233: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 4234: }
4235: return $switchserver;
4236: }
4237:
1.1 raeburn 4238: sub modify_quotas {
1.86 raeburn 4239: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 4240: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
4241: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 4242: if ($action eq 'quotas') {
4243: $context = 'tools';
4244: } else {
4245: $context = $action;
4246: }
4247: if ($context eq 'requestcourses') {
1.98 raeburn 4248: @usertools = ('official','unofficial','community');
1.102.2.9 raeburn 4249: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 4250: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
4251: %titles = &courserequest_titles();
4252: $toolregexp = join('|',@usertools);
4253: %conditions = &courserequest_conditions();
1.86 raeburn 4254: } else {
4255: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 4256: %titles = &tool_titles();
1.86 raeburn 4257: }
1.72 raeburn 4258: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 4259: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4260: foreach my $key (keys(%env)) {
1.101 raeburn 4261: if ($context eq 'requestcourses') {
4262: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
4263: my $item = $1;
4264: my $type = $2;
4265: if ($type =~ /^limit_(.+)/) {
4266: $limithash{$item}{$1} = $env{$key};
4267: } else {
4268: $confhash{$item}{$type} = $env{$key};
4269: }
4270: }
4271: } else {
1.86 raeburn 4272: if ($key =~ /^form\.quota_(.+)$/) {
4273: $confhash{'defaultquota'}{$1} = $env{$key};
4274: }
1.101 raeburn 4275: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
4276: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
4277: }
1.72 raeburn 4278: }
4279: }
1.102 raeburn 4280: if ($context eq 'requestcourses') {
4281: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
4282: @approvalnotify = sort(@approvalnotify);
4283: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
4284: if (ref($domconfig{$action}) eq 'HASH') {
4285: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
4286: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
4287: $changes{'notify'}{'approval'} = 1;
4288: }
4289: } else {
4290: if ($domconfig{$action}{'notify'}{'approval'}) {
4291: $changes{'notify'}{'approval'} = 1;
4292: }
4293: }
4294: } else {
4295: if ($domconfig{$action}{'notify'}{'approval'}) {
4296: $changes{'notify'}{'approval'} = 1;
4297: }
4298: }
4299: } else {
1.86 raeburn 4300: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
4301: }
1.72 raeburn 4302: foreach my $item (@usertools) {
4303: foreach my $type (@{$types},'default','_LC_adv') {
1.102.2.2 raeburn 4304: my $unset;
1.101 raeburn 4305: if ($context eq 'requestcourses') {
1.102.2.2 raeburn 4306: $unset = '0';
4307: if ($type eq '_LC_adv') {
4308: $unset = '';
4309: }
1.101 raeburn 4310: if ($confhash{$item}{$type} eq 'autolimit') {
4311: $confhash{$item}{$type} .= '=';
4312: unless ($limithash{$item}{$type} =~ /\D/) {
4313: $confhash{$item}{$type} .= $limithash{$item}{$type};
4314: }
4315: }
1.72 raeburn 4316: } else {
1.101 raeburn 4317: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
4318: $confhash{$item}{$type} = 1;
4319: } else {
4320: $confhash{$item}{$type} = 0;
4321: }
1.72 raeburn 4322: }
1.86 raeburn 4323: if (ref($domconfig{$action}) eq 'HASH') {
4324: if (ref($domconfig{$action}{$item}) eq 'HASH') {
4325: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
4326: $changes{$item}{$type} = 1;
4327: }
4328: } else {
4329: if ($context eq 'requestcourses') {
1.102.2.2 raeburn 4330: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 4331: $changes{$item}{$type} = 1;
4332: }
4333: } else {
4334: if (!$confhash{$item}{$type}) {
4335: $changes{$item}{$type} = 1;
4336: }
4337: }
4338: }
4339: } else {
4340: if ($context eq 'requestcourses') {
1.102.2.2 raeburn 4341: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 4342: $changes{$item}{$type} = 1;
4343: }
4344: } else {
4345: if (!$confhash{$item}{$type}) {
4346: $changes{$item}{$type} = 1;
4347: }
4348: }
4349: }
1.1 raeburn 4350: }
4351: }
1.86 raeburn 4352: unless ($context eq 'requestcourses') {
4353: if (ref($domconfig{'quotas'}) eq 'HASH') {
4354: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
4355: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
4356: if (exists($confhash{'defaultquota'}{$key})) {
4357: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
4358: $changes{'defaultquota'}{$key} = 1;
4359: }
4360: } else {
4361: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 4362: }
4363: }
1.86 raeburn 4364: } else {
4365: foreach my $key (keys(%{$domconfig{'quotas'}})) {
4366: if (exists($confhash{'defaultquota'}{$key})) {
4367: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
4368: $changes{'defaultquota'}{$key} = 1;
4369: }
4370: } else {
4371: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 4372: }
1.1 raeburn 4373: }
4374: }
4375: }
1.86 raeburn 4376: if (ref($confhash{'defaultquota'}) eq 'HASH') {
4377: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
4378: if (ref($domconfig{'quotas'}) eq 'HASH') {
4379: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
4380: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
4381: $changes{'defaultquota'}{$key} = 1;
4382: }
4383: } else {
4384: if (!exists($domconfig{'quotas'}{$key})) {
4385: $changes{'defaultquota'}{$key} = 1;
4386: }
1.72 raeburn 4387: }
4388: } else {
1.86 raeburn 4389: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 4390: }
1.1 raeburn 4391: }
4392: }
4393: }
1.72 raeburn 4394:
4395: foreach my $key (keys(%confhash)) {
4396: $domdefaults{$key} = $confhash{$key};
4397: }
4398:
1.1 raeburn 4399: my %quotahash = (
1.86 raeburn 4400: $action => { %confhash }
1.1 raeburn 4401: );
4402: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
4403: $dom);
4404: if ($putresult eq 'ok') {
4405: if (keys(%changes) > 0) {
1.72 raeburn 4406: my $cachetime = 24*60*60;
4407: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
4408:
1.1 raeburn 4409: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 4410: unless ($context eq 'requestcourses') {
4411: if (ref($changes{'defaultquota'}) eq 'HASH') {
4412: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
4413: foreach my $type (@{$types},'default') {
4414: if (defined($changes{'defaultquota'}{$type})) {
4415: my $typetitle = $usertypes->{$type};
4416: if ($type eq 'default') {
4417: $typetitle = $othertitle;
4418: }
4419: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 4420: }
4421: }
1.86 raeburn 4422: $resulttext .= '</ul></li>';
1.72 raeburn 4423: }
4424: }
1.80 raeburn 4425: my %newenv;
1.72 raeburn 4426: foreach my $item (@usertools) {
4427: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 4428: my $newacc =
4429: &Apache::lonnet::usertools_access($env{'user.name'},
4430: $env{'user.domain'},
1.86 raeburn 4431: $item,'reload',$context);
4432: if ($context eq 'requestcourses') {
1.102.2.2 raeburn 4433: if ($env{'environment.canrequest.'.$item} ne $newacc) {
4434: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 4435: }
4436: } else {
4437: if ($env{'environment.availabletools.'.$item} ne $newacc) {
4438: $newenv{'environment.availabletools.'.$item} = $newacc;
4439: }
1.80 raeburn 4440: }
1.72 raeburn 4441: $resulttext .= '<li>'.$titles{$item}.'<ul>';
4442: foreach my $type (@{$types},'default','_LC_adv') {
4443: if ($changes{$item}{$type}) {
4444: my $typetitle = $usertypes->{$type};
4445: if ($type eq 'default') {
4446: $typetitle = $othertitle;
4447: } elsif ($type eq '_LC_adv') {
4448: $typetitle = 'LON-CAPA Advanced Users';
4449: }
4450: if ($confhash{$item}{$type}) {
1.101 raeburn 4451: if ($context eq 'requestcourses') {
4452: my $cond;
4453: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
4454: if ($1 eq '') {
4455: $cond = &mt('(Automatic processing of any request).');
4456: } else {
4457: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
4458: }
4459: } else {
4460: $cond = $conditions{$confhash{$item}{$type}};
4461: }
4462: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
4463: } else {
4464: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
4465: }
1.72 raeburn 4466: } else {
1.102.2.2 raeburn 4467: if ($type eq '_LC_adv') {
4468: if ($confhash{$item}{$type} eq '0') {
4469: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4470: } else {
4471: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
4472: }
4473: } else {
4474: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4475: }
1.72 raeburn 4476: }
4477: }
1.26 raeburn 4478: }
1.72 raeburn 4479: $resulttext .= '</ul></li>';
1.26 raeburn 4480: }
1.1 raeburn 4481: }
1.102 raeburn 4482: if ($action eq 'requestcourses') {
4483: if (ref($changes{'notify'}) eq 'HASH') {
4484: if ($changes{'notify'}{'approval'}) {
4485: if (ref($confhash{'notify'}) eq 'HASH') {
4486: if ($confhash{'notify'}{'approval'}) {
4487: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
4488: } else {
4489: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
4490: }
4491: }
4492: }
4493: }
4494: }
1.1 raeburn 4495: $resulttext .= '</ul>';
1.80 raeburn 4496: if (keys(%newenv)) {
4497: &Apache::lonnet::appenv(\%newenv);
4498: }
1.1 raeburn 4499: } else {
1.86 raeburn 4500: if ($context eq 'requestcourses') {
4501: $resulttext = &mt('No changes made to rights to request creation of courses.');
4502: } else {
1.90 weissno 4503: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 4504: }
1.1 raeburn 4505: }
4506: } else {
1.11 albertel 4507: $resulttext = '<span class="LC_error">'.
4508: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4509: }
1.3 raeburn 4510: return $resulttext;
1.1 raeburn 4511: }
4512:
1.3 raeburn 4513: sub modify_autoenroll {
4514: my ($dom,%domconfig) = @_;
1.1 raeburn 4515: my ($resulttext,%changes);
4516: my %currautoenroll;
4517: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4518: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
4519: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
4520: }
4521: }
4522: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
4523: my %title = ( run => 'Auto-enrollment active',
1.102.2.11 raeburn 4524: sender => 'Sender for notification messages',
4525: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 4526: my @offon = ('off','on');
1.17 raeburn 4527: my $sender_uname = $env{'form.sender_uname'};
4528: my $sender_domain = $env{'form.sender_domain'};
4529: if ($sender_domain eq '') {
4530: $sender_uname = '';
4531: } elsif ($sender_uname eq '') {
4532: $sender_domain = '';
4533: }
1.102.2.11 raeburn 4534: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 4535: my %autoenrollhash = (
4536: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 4537: sender_uname => $sender_uname,
4538: sender_domain => $sender_domain,
1.102.2.11 raeburn 4539: 'co-owners' => $coowners,
1.1 raeburn 4540: }
4541: );
1.4 raeburn 4542: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
4543: $dom);
1.1 raeburn 4544: if ($putresult eq 'ok') {
4545: if (exists($currautoenroll{'run'})) {
4546: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
4547: $changes{'run'} = 1;
4548: }
4549: } elsif ($autorun) {
4550: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 4551: $changes{'run'} = 1;
1.1 raeburn 4552: }
4553: }
1.17 raeburn 4554: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 4555: $changes{'sender'} = 1;
4556: }
1.17 raeburn 4557: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 4558: $changes{'sender'} = 1;
4559: }
1.102.2.11 raeburn 4560: if ($currautoenroll{'co-owners'} ne '') {
4561: if ($currautoenroll{'co-owners'} ne $coowners) {
4562: $changes{'coowners'} = 1;
4563: }
4564: } elsif ($coowners) {
4565: $changes{'coowners'} = 1;
4566: }
1.1 raeburn 4567: if (keys(%changes) > 0) {
4568: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 4569: if ($changes{'run'}) {
1.1 raeburn 4570: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
4571: }
4572: if ($changes{'sender'}) {
1.17 raeburn 4573: if ($sender_uname eq '' || $sender_domain eq '') {
4574: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
4575: } else {
4576: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
4577: }
1.1 raeburn 4578: }
1.102.2.11 raeburn 4579: if ($changes{'coowners'}) {
4580: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
4581: &Apache::loncommon::devalidate_domconfig_cache($dom);
4582: }
1.1 raeburn 4583: $resulttext .= '</ul>';
4584: } else {
4585: $resulttext = &mt('No changes made to auto-enrollment settings');
4586: }
4587: } else {
1.11 albertel 4588: $resulttext = '<span class="LC_error">'.
4589: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4590: }
1.3 raeburn 4591: return $resulttext;
1.1 raeburn 4592: }
4593:
4594: sub modify_autoupdate {
1.3 raeburn 4595: my ($dom,%domconfig) = @_;
1.1 raeburn 4596: my ($resulttext,%currautoupdate,%fields,%changes);
4597: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
4598: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
4599: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
4600: }
4601: }
4602: my @offon = ('off','on');
4603: my %title = &Apache::lonlocal::texthash (
4604: run => 'Auto-update:',
4605: classlists => 'Updates to user information in classlists?'
4606: );
1.44 raeburn 4607: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4608: my %fieldtitles = &Apache::lonlocal::texthash (
4609: id => 'Student/Employee ID',
1.20 raeburn 4610: permanentemail => 'E-mail address',
1.1 raeburn 4611: lastname => 'Last Name',
4612: firstname => 'First Name',
4613: middlename => 'Middle Name',
1.102.2.12! raeburn 4614: generation => 'Generation',
1.1 raeburn 4615: );
4616: my $othertitle = &mt('All users');
4617: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 4618: $othertitle = &mt('Other users');
1.1 raeburn 4619: }
4620: foreach my $key (keys(%env)) {
4621: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.102.2.12! raeburn 4622: my ($usertype,$item) = ($1,$2);
! 4623: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
! 4624: if ($usertype eq 'default') {
! 4625: push(@{$fields{$1}},$2);
! 4626: } elsif (ref($types) eq 'ARRAY') {
! 4627: if (grep(/^\Q$usertype\E$/,@{$types})) {
! 4628: push(@{$fields{$1}},$2);
! 4629: }
! 4630: }
! 4631: }
! 4632: }
! 4633: }
! 4634: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
! 4635: @lockablenames = sort(@lockablenames);
! 4636: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
! 4637: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
! 4638: if (@changed) {
! 4639: $changes{'lockablenames'} = 1;
! 4640: }
! 4641: } else {
! 4642: if (@lockablenames) {
! 4643: $changes{'lockablenames'} = 1;
1.1 raeburn 4644: }
4645: }
4646: my %updatehash = (
4647: autoupdate => { run => $env{'form.autoupdate_run'},
4648: classlists => $env{'form.classlists'},
4649: fields => {%fields},
1.102.2.12! raeburn 4650: lockablenames => \@lockablenames,
1.1 raeburn 4651: }
4652: );
4653: foreach my $key (keys(%currautoupdate)) {
4654: if (($key eq 'run') || ($key eq 'classlists')) {
4655: if (exists($updatehash{autoupdate}{$key})) {
4656: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
4657: $changes{$key} = 1;
4658: }
4659: }
4660: } elsif ($key eq 'fields') {
4661: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 4662: foreach my $item (@{$types},'default') {
1.1 raeburn 4663: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
4664: my $change = 0;
4665: foreach my $type (@{$currautoupdate{$key}{$item}}) {
4666: if (!exists($fields{$item})) {
4667: $change = 1;
1.102.2.12! raeburn 4668: last;
1.1 raeburn 4669: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 4670: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 4671: $change = 1;
1.102.2.12! raeburn 4672: last;
1.1 raeburn 4673: }
4674: }
4675: }
4676: if ($change) {
4677: push(@{$changes{$key}},$item);
4678: }
1.26 raeburn 4679: }
1.1 raeburn 4680: }
4681: }
1.102.2.12! raeburn 4682: } elsif ($key eq 'lockablenames') {
! 4683: if (ref($currautoupdate{$key}) eq 'ARRAY') {
! 4684: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
! 4685: if (@changed) {
! 4686: $changes{'lockablenames'} = 1;
! 4687: }
! 4688: } else {
! 4689: if (@lockablenames) {
! 4690: $changes{'lockablenames'} = 1;
! 4691: }
! 4692: }
! 4693: }
! 4694: }
! 4695: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
! 4696: if (@lockablenames) {
! 4697: $changes{'lockablenames'} = 1;
1.1 raeburn 4698: }
4699: }
1.26 raeburn 4700: foreach my $item (@{$types},'default') {
4701: if (defined($fields{$item})) {
4702: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.102.2.12! raeburn 4703: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
! 4704: my $change = 0;
! 4705: if (ref($fields{$item}) eq 'ARRAY') {
! 4706: foreach my $type (@{$fields{$item}}) {
! 4707: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
! 4708: $change = 1;
! 4709: last;
! 4710: }
! 4711: }
! 4712: }
! 4713: if ($change) {
! 4714: push(@{$changes{'fields'}},$item);
! 4715: }
! 4716: } else {
1.26 raeburn 4717: push(@{$changes{'fields'}},$item);
4718: }
4719: } else {
4720: push(@{$changes{'fields'}},$item);
1.1 raeburn 4721: }
4722: }
4723: }
4724: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
4725: $dom);
4726: if ($putresult eq 'ok') {
4727: if (keys(%changes) > 0) {
4728: $resulttext = &mt('Changes made:').'<ul>';
4729: foreach my $key (sort(keys(%changes))) {
1.102.2.12! raeburn 4730: if ($key eq 'lockablenames') {
! 4731: $resulttext .= '<li>';
! 4732: if (@lockablenames) {
! 4733: $usertypes->{'default'} = $othertitle;
! 4734: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
! 4735: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
! 4736: } else {
! 4737: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
! 4738: }
! 4739: $resulttext .= '</li>';
! 4740: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 4741: foreach my $item (@{$changes{$key}}) {
4742: my @newvalues;
4743: foreach my $type (@{$fields{$item}}) {
4744: push(@newvalues,$fieldtitles{$type});
4745: }
1.3 raeburn 4746: my $newvaluestr;
4747: if (@newvalues > 0) {
4748: $newvaluestr = join(', ',@newvalues);
4749: } else {
4750: $newvaluestr = &mt('none');
1.6 raeburn 4751: }
1.1 raeburn 4752: if ($item eq 'default') {
1.26 raeburn 4753: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 4754: } else {
1.26 raeburn 4755: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 4756: }
4757: }
4758: } else {
4759: my $newvalue;
4760: if ($key eq 'run') {
4761: $newvalue = $offon[$env{'form.autoupdate_run'}];
4762: } else {
4763: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 4764: }
1.1 raeburn 4765: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
4766: }
4767: }
4768: $resulttext .= '</ul>';
4769: } else {
1.3 raeburn 4770: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 4771: }
4772: } else {
1.11 albertel 4773: $resulttext = '<span class="LC_error">'.
4774: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4775: }
1.3 raeburn 4776: return $resulttext;
1.1 raeburn 4777: }
4778:
1.102.2.9 raeburn 4779: sub modify_autocreate {
4780: my ($dom,%domconfig) = @_;
4781: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
4782: if (ref($domconfig{'autocreate'}) eq 'HASH') {
4783: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
4784: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
4785: }
4786: }
4787: my %title= ( xml => 'Auto-creation of courses in XML course description files',
4788: req => 'Auto-creation of validated requests for official courses',
4789: xmldc => 'Identity of course creator of courses from XML files',
4790: );
4791: my @types = ('xml','req');
4792: foreach my $item (@types) {
4793: $newvals{$item} = $env{'form.autocreate_'.$item};
4794: $newvals{$item} =~ s/\D//g;
4795: $newvals{$item} = 0 if ($newvals{$item} eq '');
4796: }
4797: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
4798: my %domcoords = &get_active_dcs($dom);
4799: unless (exists($domcoords{$newvals{'xmldc'}})) {
4800: $newvals{'xmldc'} = '';
4801: }
4802: %autocreatehash = (
4803: autocreate => { xml => $newvals{'xml'},
4804: req => $newvals{'req'},
4805: }
4806: );
4807: if ($newvals{'xmldc'} ne '') {
4808: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
4809: }
4810: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
4811: $dom);
4812: if ($putresult eq 'ok') {
4813: my @items = @types;
4814: if ($newvals{'xml'}) {
4815: push(@items,'xmldc');
4816: }
4817: foreach my $item (@items) {
4818: if (exists($currautocreate{$item})) {
4819: if ($currautocreate{$item} ne $newvals{$item}) {
4820: $changes{$item} = 1;
4821: }
4822: } elsif ($newvals{$item}) {
4823: $changes{$item} = 1;
4824: }
4825: }
4826: if (keys(%changes) > 0) {
4827: my @offon = ('off','on');
4828: $resulttext = &mt('Changes made:').'<ul>';
4829: foreach my $item (@types) {
4830: if ($changes{$item}) {
4831: my $newtxt = $offon[$newvals{$item}];
4832: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
4833: }
4834: }
4835: if ($changes{'xmldc'}) {
4836: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
4837: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
4838: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
4839: }
4840: $resulttext .= '</ul>';
4841: } else {
4842: $resulttext = &mt('No changes made to auto-creation settings');
4843: }
4844: } else {
4845: $resulttext = '<span class="LC_error">'.
4846: &mt('An error occurred: [_1]',$putresult).'</span>';
4847: }
4848: return $resulttext;
4849: }
4850:
1.23 raeburn 4851: sub modify_directorysrch {
4852: my ($dom,%domconfig) = @_;
4853: my ($resulttext,%changes);
4854: my %currdirsrch;
4855: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4856: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
4857: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
4858: }
4859: }
4860: my %title = ( available => 'Directory search available',
1.24 raeburn 4861: localonly => 'Other domains can search',
1.23 raeburn 4862: searchby => 'Search types',
4863: searchtypes => 'Search latitude');
4864: my @offon = ('off','on');
1.24 raeburn 4865: my @otherdoms = ('Yes','No');
1.23 raeburn 4866:
1.25 raeburn 4867: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 4868: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
4869: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
4870:
1.44 raeburn 4871: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 4872: if (keys(%{$usertypes}) == 0) {
4873: @cansearch = ('default');
4874: } else {
4875: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
4876: foreach my $type (@{$currdirsrch{'cansearch'}}) {
4877: if (!grep(/^\Q$type\E$/,@cansearch)) {
4878: push(@{$changes{'cansearch'}},$type);
4879: }
1.23 raeburn 4880: }
1.26 raeburn 4881: foreach my $type (@cansearch) {
4882: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
4883: push(@{$changes{'cansearch'}},$type);
4884: }
1.23 raeburn 4885: }
1.26 raeburn 4886: } else {
4887: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 4888: }
4889: }
4890:
4891: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
4892: foreach my $by (@{$currdirsrch{'searchby'}}) {
4893: if (!grep(/^\Q$by\E$/,@searchby)) {
4894: push(@{$changes{'searchby'}},$by);
4895: }
4896: }
4897: foreach my $by (@searchby) {
4898: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
4899: push(@{$changes{'searchby'}},$by);
4900: }
4901: }
4902: } else {
4903: push(@{$changes{'searchby'}},@searchby);
4904: }
1.25 raeburn 4905:
4906: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
4907: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
4908: if (!grep(/^\Q$type\E$/,@searchtypes)) {
4909: push(@{$changes{'searchtypes'}},$type);
4910: }
4911: }
4912: foreach my $type (@searchtypes) {
4913: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
4914: push(@{$changes{'searchtypes'}},$type);
4915: }
4916: }
4917: } else {
4918: if (exists($currdirsrch{'searchtypes'})) {
4919: foreach my $type (@searchtypes) {
4920: if ($type ne $currdirsrch{'searchtypes'}) {
4921: push(@{$changes{'searchtypes'}},$type);
4922: }
4923: }
4924: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
4925: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
4926: }
4927: } else {
4928: push(@{$changes{'searchtypes'}},@searchtypes);
4929: }
4930: }
4931:
1.23 raeburn 4932: my %dirsrch_hash = (
4933: directorysrch => { available => $env{'form.dirsrch_available'},
4934: cansearch => \@cansearch,
1.24 raeburn 4935: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 4936: searchby => \@searchby,
1.25 raeburn 4937: searchtypes => \@searchtypes,
1.23 raeburn 4938: }
4939: );
4940: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
4941: $dom);
4942: if ($putresult eq 'ok') {
4943: if (exists($currdirsrch{'available'})) {
4944: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
4945: $changes{'available'} = 1;
4946: }
4947: } else {
4948: if ($env{'form.dirsrch_available'} eq '1') {
4949: $changes{'available'} = 1;
4950: }
4951: }
1.24 raeburn 4952: if (exists($currdirsrch{'localonly'})) {
4953: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
4954: $changes{'localonly'} = 1;
4955: }
4956: } else {
4957: if ($env{'form.dirsrch_localonly'} eq '1') {
4958: $changes{'localonly'} = 1;
4959: }
4960: }
1.23 raeburn 4961: if (keys(%changes) > 0) {
4962: $resulttext = &mt('Changes made:').'<ul>';
4963: if ($changes{'available'}) {
4964: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
4965: }
1.24 raeburn 4966: if ($changes{'localonly'}) {
4967: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
4968: }
4969:
1.23 raeburn 4970: if (ref($changes{'cansearch'}) eq 'ARRAY') {
4971: my $chgtext;
1.26 raeburn 4972: if (ref($usertypes) eq 'HASH') {
4973: if (keys(%{$usertypes}) > 0) {
4974: foreach my $type (@{$types}) {
4975: if (grep(/^\Q$type\E$/,@cansearch)) {
4976: $chgtext .= $usertypes->{$type}.'; ';
4977: }
4978: }
4979: if (grep(/^default$/,@cansearch)) {
4980: $chgtext .= $othertitle;
4981: } else {
4982: $chgtext =~ s/\; $//;
4983: }
4984: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 4985: }
4986: }
4987: }
4988: if (ref($changes{'searchby'}) eq 'ARRAY') {
4989: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4990: my $chgtext;
4991: foreach my $type (@{$titleorder}) {
4992: if (grep(/^\Q$type\E$/,@searchby)) {
4993: if (defined($searchtitles->{$type})) {
4994: $chgtext .= $searchtitles->{$type}.'; ';
4995: }
4996: }
4997: }
4998: $chgtext =~ s/\; $//;
4999: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5000: }
1.25 raeburn 5001: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5002: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5003: my $chgtext;
5004: foreach my $type (@{$srchtypeorder}) {
5005: if (grep(/^\Q$type\E$/,@searchtypes)) {
5006: if (defined($srchtypes_desc->{$type})) {
5007: $chgtext .= $srchtypes_desc->{$type}.'; ';
5008: }
5009: }
5010: }
5011: $chgtext =~ s/\; $//;
5012: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5013: }
5014: $resulttext .= '</ul>';
5015: } else {
5016: $resulttext = &mt('No changes made to institution directory search settings');
5017: }
5018: } else {
5019: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5020: &mt('An error occurred: [_1]',$putresult).'</span>';
5021: }
5022: return $resulttext;
5023: }
5024:
1.28 raeburn 5025: sub modify_contacts {
5026: my ($dom,%domconfig) = @_;
5027: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5028: if (ref($domconfig{'contacts'}) eq 'HASH') {
5029: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5030: $currsetting{$key} = $domconfig{'contacts'}{$key};
5031: }
5032: }
5033: my (%others,%to);
5034: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5035: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5036: 'requestsmail');
1.28 raeburn 5037: foreach my $type (@mailings) {
5038: @{$newsetting{$type}} =
5039: &Apache::loncommon::get_env_multiple('form.'.$type);
5040: foreach my $item (@contacts) {
5041: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5042: $contacts_hash{contacts}{$type}{$item} = 1;
5043: } else {
5044: $contacts_hash{contacts}{$type}{$item} = 0;
5045: }
5046: }
5047: $others{$type} = $env{'form.'.$type.'_others'};
5048: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
5049: }
5050: foreach my $item (@contacts) {
5051: $to{$item} = $env{'form.'.$item};
5052: $contacts_hash{'contacts'}{$item} = $to{$item};
5053: }
5054: if (keys(%currsetting) > 0) {
5055: foreach my $item (@contacts) {
5056: if ($to{$item} ne $currsetting{$item}) {
5057: $changes{$item} = 1;
5058: }
5059: }
5060: foreach my $type (@mailings) {
5061: foreach my $item (@contacts) {
5062: if (ref($currsetting{$type}) eq 'HASH') {
5063: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
5064: push(@{$changes{$type}},$item);
5065: }
5066: } else {
5067: push(@{$changes{$type}},@{$newsetting{$type}});
5068: }
5069: }
5070: if ($others{$type} ne $currsetting{$type}{'others'}) {
5071: push(@{$changes{$type}},'others');
5072: }
5073: }
5074: } else {
5075: my %default;
5076: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
5077: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
5078: $default{'errormail'} = 'adminemail';
5079: $default{'packagesmail'} = 'adminemail';
5080: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 5081: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 5082: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 5083: foreach my $item (@contacts) {
5084: if ($to{$item} ne $default{$item}) {
5085: $changes{$item} = 1;
5086: }
5087: }
5088: foreach my $type (@mailings) {
5089: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
5090:
5091: push(@{$changes{$type}},@{$newsetting{$type}});
5092: }
5093: if ($others{$type} ne '') {
5094: push(@{$changes{$type}},'others');
5095: }
5096: }
5097: }
5098: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
5099: $dom);
5100: if ($putresult eq 'ok') {
5101: if (keys(%changes) > 0) {
5102: my ($titles,$short_titles) = &contact_titles();
5103: $resulttext = &mt('Changes made:').'<ul>';
5104: foreach my $item (@contacts) {
5105: if ($changes{$item}) {
5106: $resulttext .= '<li>'.$titles->{$item}.
5107: &mt(' set to: ').
5108: '<span class="LC_cusr_emph">'.
5109: $to{$item}.'</span></li>';
5110: }
5111: }
5112: foreach my $type (@mailings) {
5113: if (ref($changes{$type}) eq 'ARRAY') {
5114: $resulttext .= '<li>'.$titles->{$type}.': ';
5115: my @text;
5116: foreach my $item (@{$newsetting{$type}}) {
5117: push(@text,$short_titles->{$item});
5118: }
5119: if ($others{$type} ne '') {
5120: push(@text,$others{$type});
5121: }
5122: $resulttext .= '<span class="LC_cusr_emph">'.
5123: join(', ',@text).'</span></li>';
5124: }
5125: }
5126: $resulttext .= '</ul>';
5127: } else {
1.34 raeburn 5128: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 5129: }
5130: } else {
5131: $resulttext = '<span class="LC_error">'.
5132: &mt('An error occurred: [_1].',$putresult).'</span>';
5133: }
5134: return $resulttext;
5135: }
5136:
5137: sub modify_usercreation {
1.27 raeburn 5138: my ($dom,%domconfig) = @_;
1.34 raeburn 5139: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 5140: my $warningmsg;
1.27 raeburn 5141: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5142: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
5143: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
5144: }
5145: }
5146: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 5147: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 5148: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 5149: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 5150: foreach my $item(@contexts) {
1.45 raeburn 5151: if ($item eq 'selfcreate') {
1.50 raeburn 5152: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 5153: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5154: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 5155: if (ref($cancreate{$item}) eq 'ARRAY') {
5156: if (grep(/^login$/,@{$cancreate{$item}})) {
5157: $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.').' '.&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.');
5158: }
1.43 raeburn 5159: }
5160: }
1.50 raeburn 5161: } else {
5162: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 5163: }
1.34 raeburn 5164: }
1.93 raeburn 5165: my ($othertitle,$usertypes,$types) =
5166: &Apache::loncommon::sorted_inst_types($dom);
5167: if (ref($types) eq 'ARRAY') {
5168: if (@{$types} > 0) {
5169: @{$cancreate{'statustocreate'}} =
5170: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.102.2.2 raeburn 5171: } else {
5172: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 5173: }
5174: push(@contexts,'statustocreate');
5175: }
1.34 raeburn 5176: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
5177: foreach my $item (@contexts) {
1.93 raeburn 5178: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
5179: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 5180: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.102.2.2 raeburn 5181: if (ref($cancreate{$item}) eq 'ARRAY') {
5182: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
5183: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5184: push(@{$changes{'cancreate'}},$item);
5185: }
1.50 raeburn 5186: }
5187: }
5188: }
5189: } else {
5190: if ($curr_usercreation{'cancreate'}{$item} eq '') {
5191: if (@{$cancreate{$item}} > 0) {
5192: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5193: push(@{$changes{'cancreate'}},$item);
5194: }
5195: }
5196: } else {
5197: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
5198: if (@{$cancreate{$item}} < 3) {
5199: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5200: push(@{$changes{'cancreate'}},$item);
5201: }
5202: }
5203: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
5204: if (@{$cancreate{$item}} > 0) {
5205: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5206: push(@{$changes{'cancreate'}},$item);
5207: }
5208: }
5209: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
5210: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5211: push(@{$changes{'cancreate'}},$item);
5212: }
5213: }
5214: }
5215: }
5216: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5217: foreach my $type (@{$cancreate{$item}}) {
5218: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
5219: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
5220: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5221: push(@{$changes{'cancreate'}},$item);
5222: }
5223: }
5224: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
5225: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
5226: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
5227: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5228: push(@{$changes{'cancreate'}},$item);
5229: }
5230: }
5231: }
5232: }
5233: }
5234: } else {
5235: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
5236: push(@{$changes{'cancreate'}},$item);
5237: }
5238: }
1.27 raeburn 5239: }
1.34 raeburn 5240: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
5241: foreach my $item (@contexts) {
1.43 raeburn 5242: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 5243: if ($cancreate{$item} ne 'any') {
5244: push(@{$changes{'cancreate'}},$item);
5245: }
5246: } else {
5247: if ($cancreate{$item} ne 'none') {
5248: push(@{$changes{'cancreate'}},$item);
5249: }
1.27 raeburn 5250: }
5251: }
5252: } else {
1.43 raeburn 5253: foreach my $item (@contexts) {
1.34 raeburn 5254: push(@{$changes{'cancreate'}},$item);
5255: }
1.27 raeburn 5256: }
1.34 raeburn 5257:
1.27 raeburn 5258: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
5259: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
5260: if (!grep(/^\Q$type\E$/,@username_rule)) {
5261: push(@{$changes{'username_rule'}},$type);
5262: }
5263: }
5264: foreach my $type (@username_rule) {
5265: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
5266: push(@{$changes{'username_rule'}},$type);
5267: }
5268: }
5269: } else {
5270: push(@{$changes{'username_rule'}},@username_rule);
5271: }
5272:
1.32 raeburn 5273: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
5274: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
5275: if (!grep(/^\Q$type\E$/,@id_rule)) {
5276: push(@{$changes{'id_rule'}},$type);
5277: }
5278: }
5279: foreach my $type (@id_rule) {
5280: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
5281: push(@{$changes{'id_rule'}},$type);
5282: }
5283: }
5284: } else {
5285: push(@{$changes{'id_rule'}},@id_rule);
5286: }
5287:
1.43 raeburn 5288: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
5289: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
5290: if (!grep(/^\Q$type\E$/,@email_rule)) {
5291: push(@{$changes{'email_rule'}},$type);
5292: }
5293: }
5294: foreach my $type (@email_rule) {
5295: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
5296: push(@{$changes{'email_rule'}},$type);
5297: }
5298: }
5299: } else {
5300: push(@{$changes{'email_rule'}},@email_rule);
5301: }
5302:
5303: my @authen_contexts = ('author','course','domain');
1.28 raeburn 5304: my @authtypes = ('int','krb4','krb5','loc');
5305: my %authhash;
1.43 raeburn 5306: foreach my $item (@authen_contexts) {
1.28 raeburn 5307: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
5308: foreach my $auth (@authtypes) {
5309: if (grep(/^\Q$auth\E$/,@authallowed)) {
5310: $authhash{$item}{$auth} = 1;
5311: } else {
5312: $authhash{$item}{$auth} = 0;
5313: }
5314: }
5315: }
5316: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 5317: foreach my $item (@authen_contexts) {
1.28 raeburn 5318: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
5319: foreach my $auth (@authtypes) {
5320: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
5321: push(@{$changes{'authtypes'}},$item);
5322: last;
5323: }
5324: }
5325: }
5326: }
5327: } else {
1.43 raeburn 5328: foreach my $item (@authen_contexts) {
1.28 raeburn 5329: push(@{$changes{'authtypes'}},$item);
5330: }
5331: }
5332:
1.27 raeburn 5333: my %usercreation_hash = (
1.28 raeburn 5334: usercreation => {
1.34 raeburn 5335: cancreate => \%cancreate,
1.27 raeburn 5336: username_rule => \@username_rule,
1.32 raeburn 5337: id_rule => \@id_rule,
1.43 raeburn 5338: email_rule => \@email_rule,
1.32 raeburn 5339: authtypes => \%authhash,
1.27 raeburn 5340: }
5341: );
5342:
5343: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
5344: $dom);
1.50 raeburn 5345:
5346: my %selfcreatetypes = (
5347: sso => 'users authenticated by institutional single sign on',
5348: login => 'users authenticated by institutional log-in',
5349: email => 'users who provide a valid e-mail address for use as the username',
5350: );
1.27 raeburn 5351: if ($putresult eq 'ok') {
5352: if (keys(%changes) > 0) {
5353: $resulttext = &mt('Changes made:').'<ul>';
5354: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 5355: my %lt = &usercreation_types();
5356: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 5357: my $chgtext;
5358: unless ($type eq 'statustocreate') {
5359: $chgtext = $lt{$type}.', ';
5360: }
1.45 raeburn 5361: if ($type eq 'selfcreate') {
1.50 raeburn 5362: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 5363: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 5364: } else {
1.100 raeburn 5365: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 5366: foreach my $case (@{$cancreate{$type}}) {
5367: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
5368: }
5369: $chgtext .= '</ul>';
1.100 raeburn 5370: if (ref($cancreate{$type}) eq 'ARRAY') {
5371: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
5372: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
5373: if (@{$cancreate{'statustocreate'}} == 0) {
5374: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
5375: }
5376: }
5377: }
5378: }
1.43 raeburn 5379: }
1.93 raeburn 5380: } elsif ($type eq 'statustocreate') {
1.96 raeburn 5381: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
5382: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
5383: if (@{$cancreate{'selfcreate'}} > 0) {
5384: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 5385:
5386: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 5387: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 5388: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
5389: }
1.96 raeburn 5390: } elsif (ref($usertypes) eq 'HASH') {
5391: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 5392: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
5393: } else {
5394: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
5395: }
5396: $chgtext .= '<ul>';
5397: foreach my $case (@{$cancreate{$type}}) {
5398: if ($case eq 'default') {
5399: $chgtext .= '<li>'.$othertitle.'</li>';
5400: } else {
5401: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 5402: }
5403: }
1.100 raeburn 5404: $chgtext .= '</ul>';
5405: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
5406: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
5407: }
5408: }
5409: } else {
5410: if (@{$cancreate{$type}} == 0) {
5411: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
5412: } else {
5413: $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 5414: }
5415: }
5416: }
1.43 raeburn 5417: } else {
5418: if ($cancreate{$type} eq 'none') {
5419: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
5420: } elsif ($cancreate{$type} eq 'any') {
5421: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
5422: } elsif ($cancreate{$type} eq 'official') {
5423: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
5424: } elsif ($cancreate{$type} eq 'unofficial') {
5425: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
5426: }
1.34 raeburn 5427: }
5428: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 5429: }
5430: }
5431: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 5432: my ($rules,$ruleorder) =
5433: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 5434: my $chgtext = '<ul>';
5435: foreach my $type (@username_rule) {
5436: if (ref($rules->{$type}) eq 'HASH') {
5437: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
5438: }
5439: }
5440: $chgtext .= '</ul>';
5441: if (@username_rule > 0) {
5442: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
5443: } else {
1.28 raeburn 5444: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 5445: }
5446: }
1.32 raeburn 5447: if (ref($changes{'id_rule'}) eq 'ARRAY') {
5448: my ($idrules,$idruleorder) =
5449: &Apache::lonnet::inst_userrules($dom,'id');
5450: my $chgtext = '<ul>';
5451: foreach my $type (@id_rule) {
5452: if (ref($idrules->{$type}) eq 'HASH') {
5453: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
5454: }
5455: }
5456: $chgtext .= '</ul>';
5457: if (@id_rule > 0) {
5458: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
5459: } else {
5460: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
5461: }
5462: }
1.43 raeburn 5463: if (ref($changes{'email_rule'}) eq 'ARRAY') {
5464: my ($emailrules,$emailruleorder) =
5465: &Apache::lonnet::inst_userrules($dom,'email');
5466: my $chgtext = '<ul>';
5467: foreach my $type (@email_rule) {
5468: if (ref($emailrules->{$type}) eq 'HASH') {
5469: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
5470: }
5471: }
5472: $chgtext .= '</ul>';
5473: if (@email_rule > 0) {
5474: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
5475: } else {
5476: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
5477: }
5478: }
5479:
1.28 raeburn 5480: my %authname = &authtype_names();
5481: my %context_title = &context_names();
5482: if (ref($changes{'authtypes'}) eq 'ARRAY') {
5483: my $chgtext = '<ul>';
5484: foreach my $type (@{$changes{'authtypes'}}) {
5485: my @allowed;
5486: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
5487: foreach my $auth (@authtypes) {
5488: if ($authhash{$type}{$auth}) {
5489: push(@allowed,$authname{$auth});
5490: }
5491: }
1.43 raeburn 5492: if (@allowed > 0) {
5493: $chgtext .= join(', ',@allowed).'</li>';
5494: } else {
5495: $chgtext .= &mt('none').'</li>';
5496: }
1.28 raeburn 5497: }
5498: $chgtext .= '</ul>';
5499: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
5500: $resulttext .= '</li>';
5501: }
1.27 raeburn 5502: $resulttext .= '</ul>';
5503: } else {
1.28 raeburn 5504: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 5505: }
5506: } else {
5507: $resulttext = '<span class="LC_error">'.
1.23 raeburn 5508: &mt('An error occurred: [_1]',$putresult).'</span>';
5509: }
1.43 raeburn 5510: if ($warningmsg ne '') {
5511: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
5512: }
1.23 raeburn 5513: return $resulttext;
5514: }
5515:
1.33 raeburn 5516: sub modify_usermodification {
5517: my ($dom,%domconfig) = @_;
5518: my ($resulttext,%curr_usermodification,%changes);
5519: if (ref($domconfig{'usermodification'}) eq 'HASH') {
5520: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
5521: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
5522: }
5523: }
1.63 raeburn 5524: my @contexts = ('author','course','selfcreate');
1.33 raeburn 5525: my %context_title = (
5526: author => 'In author context',
5527: course => 'In course context',
1.63 raeburn 5528: selfcreate => 'When self creating account',
1.33 raeburn 5529: );
5530: my @fields = ('lastname','firstname','middlename','generation',
5531: 'permanentemail','id');
5532: my %roles = (
5533: author => ['ca','aa'],
5534: course => ['st','ep','ta','in','cr'],
5535: );
1.63 raeburn 5536: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5537: if (ref($types) eq 'ARRAY') {
5538: push(@{$types},'default');
5539: $usertypes->{'default'} = $othertitle;
5540: }
5541: $roles{'selfcreate'} = $types;
1.33 raeburn 5542: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5543: my %modifyhash;
5544: foreach my $context (@contexts) {
5545: foreach my $role (@{$roles{$context}}) {
5546: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
5547: foreach my $item (@fields) {
5548: if (grep(/^\Q$item\E$/,@modifiable)) {
5549: $modifyhash{$context}{$role}{$item} = 1;
5550: } else {
5551: $modifyhash{$context}{$role}{$item} = 0;
5552: }
5553: }
5554: }
5555: if (ref($curr_usermodification{$context}) eq 'HASH') {
5556: foreach my $role (@{$roles{$context}}) {
5557: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
5558: foreach my $field (@fields) {
5559: if ($modifyhash{$context}{$role}{$field} ne
5560: $curr_usermodification{$context}{$role}{$field}) {
5561: push(@{$changes{$context}},$role);
5562: last;
5563: }
5564: }
5565: }
5566: }
5567: } else {
5568: foreach my $context (@contexts) {
5569: foreach my $role (@{$roles{$context}}) {
5570: push(@{$changes{$context}},$role);
5571: }
5572: }
5573: }
5574: }
5575: my %usermodification_hash = (
5576: usermodification => \%modifyhash,
5577: );
5578: my $putresult = &Apache::lonnet::put_dom('configuration',
5579: \%usermodification_hash,$dom);
5580: if ($putresult eq 'ok') {
5581: if (keys(%changes) > 0) {
5582: $resulttext = &mt('Changes made: ').'<ul>';
5583: foreach my $context (@contexts) {
5584: if (ref($changes{$context}) eq 'ARRAY') {
5585: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
5586: if (ref($changes{$context}) eq 'ARRAY') {
5587: foreach my $role (@{$changes{$context}}) {
5588: my $rolename;
1.63 raeburn 5589: if ($context eq 'selfcreate') {
5590: $rolename = $role;
5591: if (ref($usertypes) eq 'HASH') {
5592: if ($usertypes->{$role} ne '') {
5593: $rolename = $usertypes->{$role};
5594: }
5595: }
1.33 raeburn 5596: } else {
1.63 raeburn 5597: if ($role eq 'cr') {
5598: $rolename = &mt('Custom');
5599: } else {
5600: $rolename = &Apache::lonnet::plaintext($role);
5601: }
1.33 raeburn 5602: }
5603: my @modifiable;
1.63 raeburn 5604: if ($context eq 'selfcreate') {
1.102.2.9 raeburn 5605: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 5606: } else {
5607: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
5608: }
1.33 raeburn 5609: foreach my $field (@fields) {
5610: if ($modifyhash{$context}{$role}{$field}) {
5611: push(@modifiable,$fieldtitles{$field});
5612: }
5613: }
5614: if (@modifiable > 0) {
5615: $resulttext .= join(', ',@modifiable);
5616: } else {
5617: $resulttext .= &mt('none');
5618: }
5619: $resulttext .= '</li>';
5620: }
5621: $resulttext .= '</ul></li>';
5622: }
5623: }
5624: }
5625: $resulttext .= '</ul>';
5626: } else {
5627: $resulttext = &mt('No changes made to user modification settings');
5628: }
5629: } else {
5630: $resulttext = '<span class="LC_error">'.
5631: &mt('An error occurred: [_1]',$putresult).'</span>';
5632: }
5633: return $resulttext;
5634: }
5635:
1.43 raeburn 5636: sub modify_defaults {
5637: my ($dom,$r) = @_;
5638: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
5639: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 5640: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 5641: my @authtypes = ('internal','krb4','krb5','localauth');
5642: foreach my $item (@items) {
5643: $newvalues{$item} = $env{'form.'.$item};
5644: if ($item eq 'auth_def') {
5645: if ($newvalues{$item} ne '') {
5646: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
5647: push(@errors,$item);
5648: }
5649: }
5650: } elsif ($item eq 'lang_def') {
5651: if ($newvalues{$item} ne '') {
5652: if ($newvalues{$item} =~ /^(\w+)/) {
5653: my $langcode = $1;
1.102.2.2 raeburn 5654: if ($langcode ne 'x_chef') {
5655: if (code2language($langcode) eq '') {
5656: push(@errors,$item);
5657: }
1.43 raeburn 5658: }
5659: } else {
5660: push(@errors,$item);
5661: }
5662: }
1.54 raeburn 5663: } elsif ($item eq 'timezone_def') {
5664: if ($newvalues{$item} ne '') {
1.62 raeburn 5665: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 5666: push(@errors,$item);
5667: }
5668: }
1.68 raeburn 5669: } elsif ($item eq 'datelocale_def') {
5670: if ($newvalues{$item} ne '') {
5671: my @datelocale_ids = DateTime::Locale->ids();
5672: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
5673: push(@errors,$item);
5674: }
5675: }
1.43 raeburn 5676: }
5677: if (grep(/^\Q$item\E$/,@errors)) {
5678: $newvalues{$item} = $domdefaults{$item};
5679: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
5680: $changes{$item} = 1;
5681: }
1.72 raeburn 5682: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 5683: }
5684: my %defaults_hash = (
1.72 raeburn 5685: defaults => \%newvalues,
5686: );
1.43 raeburn 5687: my $title = &defaults_titles();
5688: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
5689: $dom);
5690: if ($putresult eq 'ok') {
5691: if (keys(%changes) > 0) {
5692: $resulttext = &mt('Changes made:').'<ul>';
5693: my $version = $r->dir_config('lonVersion');
5694: 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";
5695: foreach my $item (sort(keys(%changes))) {
5696: my $value = $env{'form.'.$item};
5697: if ($value eq '') {
5698: $value = &mt('none');
5699: } elsif ($item eq 'auth_def') {
5700: my %authnames = &authtype_names();
5701: my %shortauth = (
5702: internal => 'int',
5703: krb4 => 'krb4',
5704: krb5 => 'krb5',
5705: localauth => 'loc',
5706: );
5707: $value = $authnames{$shortauth{$value}};
5708: }
5709: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
5710: $mailmsgtext .= "$title->{$item} set to $value\n";
5711: }
5712: $resulttext .= '</ul>';
5713: $mailmsgtext .= "\n";
5714: my $cachetime = 24*60*60;
1.72 raeburn 5715: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 5716: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 5717: my $sysmail = $r->dir_config('lonSysEMail');
5718: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
5719: }
1.43 raeburn 5720: } else {
1.54 raeburn 5721: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 5722: }
5723: } else {
5724: $resulttext = '<span class="LC_error">'.
5725: &mt('An error occurred: [_1]',$putresult).'</span>';
5726: }
5727: if (@errors > 0) {
5728: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
5729: foreach my $item (@errors) {
5730: $resulttext .= ' "'.$title->{$item}.'",';
5731: }
5732: $resulttext =~ s/,$//;
5733: }
5734: return $resulttext;
5735: }
5736:
1.46 raeburn 5737: sub modify_scantron {
1.48 raeburn 5738: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 5739: my ($resulttext,%confhash,%changes,$errors);
5740: my $custom = 'custom.tab';
5741: my $default = 'default.tab';
5742: my $servadm = $r->dir_config('lonAdmEMail');
5743: my ($configuserok,$author_ok,$switchserver) =
5744: &config_check($dom,$confname,$servadm);
5745: if ($env{'form.scantronformat.filename'} ne '') {
5746: my $error;
5747: if ($configuserok eq 'ok') {
5748: if ($switchserver) {
1.102.2.12! raeburn 5749: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 5750: } else {
5751: if ($author_ok eq 'ok') {
5752: my ($result,$scantronurl) =
5753: &publishlogo($r,'upload','scantronformat',$dom,
5754: $confname,'scantron','','',$custom);
5755: if ($result eq 'ok') {
5756: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 5757: $changes{'scantronformat'} = 1;
1.46 raeburn 5758: } else {
5759: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
5760: }
5761: } else {
5762: $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);
5763: }
5764: }
5765: } else {
5766: $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);
5767: }
5768: if ($error) {
5769: &Apache::lonnet::logthis($error);
5770: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5771: }
5772: }
1.48 raeburn 5773: if (ref($domconfig{'scantron'}) eq 'HASH') {
5774: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5775: if ($env{'form.scantronformat_del'}) {
5776: $confhash{'scantron'}{'scantronformat'} = '';
5777: $changes{'scantronformat'} = 1;
1.46 raeburn 5778: }
5779: }
5780: }
5781: if (keys(%confhash) > 0) {
5782: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
5783: $dom);
5784: if ($putresult eq 'ok') {
5785: if (keys(%changes) > 0) {
1.48 raeburn 5786: if (ref($confhash{'scantron'}) eq 'HASH') {
5787: $resulttext = &mt('Changes made:').'<ul>';
5788: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.102.2.12! raeburn 5789: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 5790: } else {
1.102.2.12! raeburn 5791: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 5792: }
1.48 raeburn 5793: $resulttext .= '</ul>';
5794: } else {
1.102.2.12! raeburn 5795: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 5796: }
5797: $resulttext .= '</ul>';
5798: &Apache::loncommon::devalidate_domconfig_cache($dom);
5799: } else {
1.102.2.12! raeburn 5800: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 5801: }
5802: } else {
5803: $resulttext = '<span class="LC_error">'.
5804: &mt('An error occurred: [_1]',$putresult).'</span>';
5805: }
5806: } else {
1.102.2.12! raeburn 5807: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 5808: }
5809: if ($errors) {
5810: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5811: $errors.'</ul>';
5812: }
5813: return $resulttext;
5814: }
5815:
1.48 raeburn 5816: sub modify_coursecategories {
5817: my ($dom,%domconfig) = @_;
1.57 raeburn 5818: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
5819: $cathash);
1.48 raeburn 5820: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 5821: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 5822: $cathash = $domconfig{'coursecategories'}{'cats'};
5823: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
5824: $changes{'togglecats'} = 1;
5825: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
5826: }
5827: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
5828: $changes{'categorize'} = 1;
5829: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
5830: }
1.102.2.6 raeburn 5831: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
5832: $changes{'togglecatscomm'} = 1;
5833: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
5834: }
5835: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
5836: $changes{'categorizecomm'} = 1;
5837: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
5838: }
1.57 raeburn 5839: } else {
5840: $changes{'togglecats'} = 1;
5841: $changes{'categorize'} = 1;
1.102.2.6 raeburn 5842: $changes{'togglecatscomm'} = 1;
5843: $changes{'categorizecomm'} = 1;
1.87 raeburn 5844: $domconfig{'coursecategories'} = {
5845: togglecats => $env{'form.togglecats'},
5846: categorize => $env{'form.categorize'},
1.102.2.6 raeburn 5847: togglecatscomm => $env{'form.togglecatscomm'},
5848: categorizecomm => $env{'form.categorizecomm'},
1.87 raeburn 5849: };
1.57 raeburn 5850: }
5851: if (ref($cathash) eq 'HASH') {
5852: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 5853: push (@deletecategory,'instcode::0');
5854: }
1.102.2.6 raeburn 5855: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
5856: push(@deletecategory,'communities::0');
5857: }
1.48 raeburn 5858: }
1.57 raeburn 5859: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
5860: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5861: if (@deletecategory > 0) {
5862: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 5863: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 5864: foreach my $item (@deletecategory) {
1.57 raeburn 5865: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
5866: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 5867: $deletions{$item} = 1;
1.57 raeburn 5868: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 5869: }
5870: }
5871: }
1.57 raeburn 5872: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 5873: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 5874: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 5875: $reorderings{$item} = 1;
1.57 raeburn 5876: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 5877: }
5878: if ($env{'form.addcategory_name_'.$item} ne '') {
5879: my $newcat = $env{'form.addcategory_name_'.$item};
5880: my $newdepth = $depth+1;
5881: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5882: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 5883: $adds{$newitem} = 1;
5884: }
5885: if ($env{'form.subcat_'.$item} ne '') {
5886: my $newcat = $env{'form.subcat_'.$item};
5887: my $newdepth = $depth+1;
5888: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5889: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 5890: $adds{$newitem} = 1;
5891: }
5892: }
5893: }
5894: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 5895: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5896: my $newitem = 'instcode::0';
1.57 raeburn 5897: if ($cathash->{$newitem} eq '') {
5898: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5899: $adds{$newitem} = 1;
5900: }
5901: } else {
5902: my $newitem = 'instcode::0';
1.57 raeburn 5903: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5904: $adds{$newitem} = 1;
5905: }
5906: }
1.102.2.6 raeburn 5907: if ($env{'form.communities'} eq '1') {
5908: if (ref($cathash) eq 'HASH') {
5909: my $newitem = 'communities::0';
5910: if ($cathash->{$newitem} eq '') {
5911: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
5912: $adds{$newitem} = 1;
5913: }
5914: } else {
5915: my $newitem = 'communities::0';
5916: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
5917: $adds{$newitem} = 1;
5918: }
5919: }
1.48 raeburn 5920: if ($env{'form.addcategory_name'} ne '') {
1.102.2.6 raeburn 5921: if (($env{'form.addcategory_name'} ne 'instcode') &&
5922: ($env{'form.addcategory_name'} ne 'communities')) {
5923: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
5924: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
5925: $adds{$newitem} = 1;
5926: }
1.48 raeburn 5927: }
1.57 raeburn 5928: my $putresult;
1.48 raeburn 5929: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5930: if (keys(%deletions) > 0) {
5931: foreach my $key (keys(%deletions)) {
5932: if ($predelallitems{$key} ne '') {
5933: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
5934: }
5935: }
5936: }
5937: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 5938: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 5939: if (ref($chkcats[0]) eq 'ARRAY') {
5940: my $depth = 0;
5941: my $chg = 0;
5942: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
5943: my $name = $chkcats[0][$i];
5944: my $item;
5945: if ($name eq '') {
5946: $chg ++;
5947: } else {
5948: $item = &escape($name).'::0';
5949: if ($chg) {
1.57 raeburn 5950: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 5951: }
5952: $depth ++;
1.57 raeburn 5953: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 5954: $depth --;
5955: }
5956: }
5957: }
1.57 raeburn 5958: }
5959: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5960: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 5961: if ($putresult eq 'ok') {
1.57 raeburn 5962: my %title = (
1.102.2.6 raeburn 5963: togglecats => 'Show/Hide a course in catalog',
5964: categorize => 'Assign a category to a course',
5965: togglecatscomm => 'Show/Hide a community in catalog',
5966: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5967: );
5968: my %level = (
1.102.2.6 raeburn 5969: dom => 'set in Domain ("Modify Course/Community")',
5970: crs => 'set in Course ("Course Configuration")',
5971: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 5972: );
1.48 raeburn 5973: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 5974: if ($changes{'togglecats'}) {
5975: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
5976: }
5977: if ($changes{'categorize'}) {
5978: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 5979: }
1.102.2.6 raeburn 5980: if ($changes{'togglecatscomm'}) {
5981: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
5982: }
5983: if ($changes{'categorizecomm'}) {
5984: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
5985: }
1.57 raeburn 5986: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5987: my $cathash;
5988: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5989: $cathash = $domconfig{'coursecategories'}{'cats'};
5990: } else {
5991: $cathash = {};
5992: }
5993: my (@cats,@trails,%allitems);
5994: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
5995: if (keys(%deletions) > 0) {
5996: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
5997: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
5998: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
5999: }
6000: $resulttext .= '</ul></li>';
6001: }
6002: if (keys(%reorderings) > 0) {
6003: my %sort_by_trail;
6004: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6005: foreach my $key (keys(%reorderings)) {
6006: if ($allitems{$key} ne '') {
6007: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6008: }
1.48 raeburn 6009: }
1.57 raeburn 6010: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6011: $resulttext .= '<li>'.$trails[$trail].'</li>';
6012: }
6013: $resulttext .= '</ul></li>';
1.48 raeburn 6014: }
1.57 raeburn 6015: if (keys(%adds) > 0) {
6016: my %sort_by_trail;
6017: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6018: foreach my $key (keys(%adds)) {
6019: if ($allitems{$key} ne '') {
6020: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6021: }
6022: }
6023: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6024: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6025: }
1.57 raeburn 6026: $resulttext .= '</ul></li>';
1.48 raeburn 6027: }
6028: }
6029: $resulttext .= '</ul>';
6030: } else {
6031: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6032: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6033: }
6034: } else {
1.102.2.6 raeburn 6035: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6036: }
6037: return $resulttext;
6038: }
6039:
1.69 raeburn 6040: sub modify_serverstatuses {
6041: my ($dom,%domconfig) = @_;
6042: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
6043: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
6044: %currserverstatus = %{$domconfig{'serverstatuses'}};
6045: }
6046: my @pages = &serverstatus_pages();
6047: foreach my $type (@pages) {
6048: $newserverstatus{$type}{'namedusers'} = '';
6049: $newserverstatus{$type}{'machines'} = '';
6050: if (defined($env{'form.'.$type.'_namedusers'})) {
6051: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
6052: my @okusers;
6053: foreach my $user (@users) {
6054: my ($uname,$udom) = split(/:/,$user);
6055: if (($udom =~ /^$match_domain$/) &&
6056: (&Apache::lonnet::domain($udom)) &&
6057: ($uname =~ /^$match_username$/)) {
6058: if (!grep(/^\Q$user\E/,@okusers)) {
6059: push(@okusers,$user);
6060: }
6061: }
6062: }
6063: if (@okusers > 0) {
6064: @okusers = sort(@okusers);
6065: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
6066: }
6067: }
6068: if (defined($env{'form.'.$type.'_machines'})) {
6069: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
6070: my @okmachines;
6071: foreach my $ip (@machines) {
6072: my @parts = split(/\./,$ip);
6073: next if (@parts < 4);
6074: my $badip = 0;
6075: for (my $i=0; $i<4; $i++) {
6076: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
6077: $badip = 1;
6078: last;
6079: }
6080: }
6081: if (!$badip) {
6082: push(@okmachines,$ip);
6083: }
6084: }
6085: @okmachines = sort(@okmachines);
6086: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
6087: }
6088: }
6089: my %serverstatushash = (
6090: serverstatuses => \%newserverstatus,
6091: );
6092: my %changes;
6093: foreach my $type (@pages) {
1.83 raeburn 6094: foreach my $setting ('namedusers','machines') {
1.84 raeburn 6095: my (@current,@new);
1.83 raeburn 6096: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 6097: if ($currserverstatus{$type}{$setting} ne '') {
6098: @current = split(/,/,$currserverstatus{$type}{$setting});
6099: }
6100: }
6101: if ($newserverstatus{$type}{$setting} ne '') {
6102: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 6103: }
6104: if (@current > 0) {
6105: if (@new > 0) {
6106: foreach my $item (@current) {
6107: if (!grep(/^\Q$item\E$/,@new)) {
6108: $changes{$type}{$setting} = 1;
1.82 raeburn 6109: last;
6110: }
6111: }
1.84 raeburn 6112: foreach my $item (@new) {
6113: if (!grep(/^\Q$item\E$/,@current)) {
6114: $changes{$type}{$setting} = 1;
6115: last;
1.82 raeburn 6116: }
6117: }
6118: } else {
1.83 raeburn 6119: $changes{$type}{$setting} = 1;
1.69 raeburn 6120: }
1.83 raeburn 6121: } elsif (@new > 0) {
6122: $changes{$type}{$setting} = 1;
1.69 raeburn 6123: }
6124: }
6125: }
6126: if (keys(%changes) > 0) {
1.81 raeburn 6127: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6128: my $putresult = &Apache::lonnet::put_dom('configuration',
6129: \%serverstatushash,$dom);
6130: if ($putresult eq 'ok') {
6131: $resulttext .= &mt('Changes made:').'<ul>';
6132: foreach my $type (@pages) {
1.84 raeburn 6133: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 6134: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 6135: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 6136: if ($newserverstatus{$type}{'namedusers'} eq '') {
6137: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
6138: } else {
6139: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
6140: }
1.84 raeburn 6141: }
6142: if ($changes{$type}{'machines'}) {
1.69 raeburn 6143: if ($newserverstatus{$type}{'machines'} eq '') {
6144: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
6145: } else {
6146: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
6147: }
6148:
6149: }
6150: $resulttext .= '</ul></li>';
6151: }
6152: }
6153: $resulttext .= '</ul>';
6154: } else {
6155: $resulttext = '<span class="LC_error">'.
6156: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
6157:
6158: }
6159: } else {
6160: $resulttext = &mt('No changes made to access to server status pages');
6161: }
6162: return $resulttext;
6163: }
6164:
1.102.2.7 raeburn 6165: sub modify_coursedefaults {
6166: my ($dom,%domconfig) = @_;
6167: my ($resulttext,$errors,%changes,%defaultshash);
6168: my %defaultchecked = ('canuse_pdfforms' => 'off');
6169: my @offon = ('off','on');
6170: my @toggles = ('canuse_pdfforms');
6171:
6172: $defaultshash{'coursedefaults'} = {};
6173:
6174: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
6175: if ($domconfig{'coursedefaults'} eq '') {
6176: $domconfig{'coursedefaults'} = {};
6177: }
6178: }
6179:
6180: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
6181: foreach my $item (@toggles) {
6182: if ($defaultchecked{$item} eq 'on') {
6183: if (($domconfig{'coursedefaults'}{$item} eq '') &&
6184: ($env{'form.'.$item} eq '0')) {
6185: $changes{$item} = 1;
6186: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
6187: $changes{$item} = 1;
6188: }
6189: } elsif ($defaultchecked{$item} eq 'off') {
6190: if (($domconfig{'coursedefaults'}{$item} eq '') &&
6191: ($env{'form.'.$item} eq '1')) {
6192: $changes{$item} = 1;
6193: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
6194: $changes{$item} = 1;
6195: }
6196: }
6197: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
6198: }
6199: }
6200: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
6201: $dom);
6202: if ($putresult eq 'ok') {
6203: if (keys(%changes) > 0) {
6204: if ($changes{'canuse_pdfforms'}) {
6205: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6206: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
6207: my $cachetime = 24*60*60;
6208: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6209: }
6210: $resulttext = &mt('Changes made:').'<ul>';
6211: foreach my $item (sort(keys(%changes))) {
6212: if ($item eq 'canuse_pdfforms') {
6213: if ($env{'form.'.$item} eq '1') {
6214: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
6215: } else {
6216: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
6217: }
6218: }
6219: }
6220: $resulttext .= '</ul>';
6221: } else {
6222: $resulttext = &mt('No changes made to course defaults');
6223: }
6224: } else {
6225: $resulttext = '<span class="LC_error">'.
6226: &mt('An error occurred: [_1]',$putresult).'</span>';
6227: }
6228: return $resulttext;
6229: }
6230:
1.48 raeburn 6231: sub recurse_check {
6232: my ($chkcats,$categories,$depth,$name) = @_;
6233: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
6234: my $chg = 0;
6235: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
6236: my $category = $chkcats->[$depth]{$name}[$j];
6237: my $item;
6238: if ($category eq '') {
6239: $chg ++;
6240: } else {
6241: my $deeper = $depth + 1;
6242: $item = &escape($category).':'.&escape($name).':'.$depth;
6243: if ($chg) {
6244: $categories->{$item} -= $chg;
6245: }
6246: &recurse_check($chkcats,$categories,$deeper,$category);
6247: $deeper --;
6248: }
6249: }
6250: }
6251: return;
6252: }
6253:
6254: sub recurse_cat_deletes {
6255: my ($item,$coursecategories,$deletions) = @_;
6256: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
6257: my $subdepth = $depth + 1;
6258: if (ref($coursecategories) eq 'HASH') {
6259: foreach my $subitem (keys(%{$coursecategories})) {
6260: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
6261: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
6262: delete($coursecategories->{$subitem});
6263: $deletions->{$subitem} = 1;
6264: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
6265: }
6266: }
6267: }
6268: return;
6269: }
6270:
1.102.2.10 raeburn 6271: sub dom_servers {
6272: my ($dom) = @_;
6273: my (%uniqservers,%servers);
6274: my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
6275: my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
6276: foreach my $mdom (@machinedoms) {
6277: my %currservers = %servers;
6278: my %server = &Apache::lonnet::get_servers($mdom);
6279: %servers = (%currservers,%server);
6280: }
6281: my %by_hostname;
6282: foreach my $id (keys(%servers)) {
6283: push(@{$by_hostname{$servers{$id}}},$id);
6284: }
6285: foreach my $hostname (sort(keys(%by_hostname))) {
6286: if (@{$by_hostname{$hostname}} > 1) {
6287: my $match = 0;
6288: foreach my $id (@{$by_hostname{$hostname}}) {
6289: if (&Apache::lonnet::host_domain($id) eq $dom) {
6290: $uniqservers{$id} = $hostname;
6291: $match = 1;
6292: }
6293: }
6294: unless ($match) {
6295: $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
6296: }
6297: } else {
6298: $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
6299: }
6300: }
6301: return %uniqservers;
6302: }
6303:
1.102.2.9 raeburn 6304: sub get_active_dcs {
6305: my ($dom) = @_;
6306: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
6307: my %domcoords;
6308: my $numdcs = 0;
6309: my $now = time;
6310: foreach my $server (keys(%dompersonnel)) {
6311: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
6312: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
6313: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
6314: if (($end eq '') || ($end == 0) || ($end > $now)) {
6315: if ($start <= $now) {
6316: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
6317: }
6318: }
6319: }
6320: }
6321: return %domcoords;
6322: }
6323:
6324: sub active_dc_picker {
6325: my ($dom,$curr_dc) = @_;
6326: my %domcoords = &get_active_dcs($dom);
6327: my @dcs = sort(keys(%domcoords));
6328: my $numdcs = scalar(@dcs);
6329: my $datatable;
6330: my $numinrow = 2;
6331: if ($numdcs > 1) {
6332: $datatable = '<table>';
6333: for (my $i=0; $i<@dcs; $i++) {
6334: my $rem = $i%($numinrow);
6335: if ($rem == 0) {
6336: if ($i > 0) {
6337: $datatable .= '</tr>';
6338: }
6339: $datatable .= '<tr>';
6340: }
6341: my $check = ' ';
6342: if ($curr_dc eq '') {
6343: if (!$i) {
6344: $check = ' checked="checked" ';
6345: }
6346: } elsif ($dcs[$i] eq $curr_dc) {
6347: $check = ' checked="checked" ';
6348: }
6349: if ($i == @dcs - 1) {
6350: my $colsleft = $numinrow - $rem;
6351: if ($colsleft > 1) {
6352: $datatable .= '<td colspan="'.$colsleft.'">';
6353: } else {
6354: $datatable .= '<td>';
6355: }
6356: } else {
6357: $datatable .= '<td>';
6358: }
6359: my ($dcname,$dcdom) = split(':',$dcs[$i]);
6360: $datatable .= '<span class="LC_nobreak"><label>'.
6361: '<input type="radio" name="autocreate_xmldc"'.
6362: ' value="'.$dcs[$i].'"'.$check.'/>'.
6363: &Apache::loncommon::plainname($dcname,$dcdom).
6364: '</label></span></td>';
6365: }
6366: $datatable .= '</tr></table>';
6367: } elsif (@dcs) {
6368: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
6369: $dcs[0].'" />';
6370: }
6371: return ($numdcs,$datatable);
6372: }
6373:
1.3 raeburn 6374: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>