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