Annotation of loncom/interface/domainprefs.pm, revision 1.46
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.46 ! raeburn 4: # $Id: domainprefs.pm,v 1.45 2008/02/29 21:01:36 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:
31: package Apache::domainprefs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::lonlocal;
1.43 raeburn 39: use Apache::lonmsg();
1.1 raeburn 40: use LONCAPA();
1.6 raeburn 41: use LONCAPA::Enrollment;
1.9 raeburn 42: use File::Copy;
1.43 raeburn 43: use Locale::Language;
1.1 raeburn 44:
45: sub handler {
46: my $r=shift;
47: if ($r->header_only) {
48: &Apache::loncommon::content_type($r,'text/html');
49: $r->send_http_header;
50: return OK;
51: }
52:
53: my $dom = $env{'request.role.domain'};
1.5 albertel 54: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 55: if (&Apache::lonnet::allowed('mau',$dom)) {
56: &Apache::loncommon::content_type($r,'text/html');
57: $r->send_http_header;
58: } else {
59: $env{'user.error.msg'}=
60: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
61: return HTTP_NOT_ACCEPTABLE;
62: }
63: &Apache::lonhtmlcommon::clear_breadcrumbs();
64: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
65: ['phase']);
1.30 raeburn 66: my $phase = 'pickactions';
1.3 raeburn 67: if ( exists($env{'form.phase'}) ) {
68: $phase = $env{'form.phase'};
69: }
70: my %domconfig =
1.6 raeburn 71: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.27 raeburn 72: 'quotas','autoenroll','autoupdate','directorysrch',
1.46 ! raeburn 73: 'usercreation','usermodification','contacts','defaults','scantron'],
! 74: $dom);
1.43 raeburn 75: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.30 raeburn 76: 'autoupdate','directorysrch','contacts',
1.46 ! raeburn 77: 'usercreation','usermodification','scantron');
1.30 raeburn 78: my %prefs = (
79: 'rolecolors' =>
80: { text => 'Default color schemes',
81: help => 'Default_Color_Schemes',
82: header => [{col1 => 'Student Settings',
83: col2 => '',},
84: {col1 => 'Coordinator Settings',
85: col2 => '',},
86: {col1 => 'Author Settings',
87: col2 => '',},
88: {col1 => 'Administrator Settings',
89: col2 => '',}],
90: },
91: 'login' =>
92: { text => 'Log-in page options',
93: help => 'Domain_Log-in_Page',
94: header => [{col1 => 'Item',
95: col2 => '',}],
96: },
1.43 raeburn 97: 'defaults' =>
98: { text => 'Default authentication/language',
99: help => '',
100: header => [{col1 => 'Setting',
101: col2 => 'Value'}],
102: },
1.30 raeburn 103: 'quotas' =>
104: { text => 'Default quotas for user portfolios',
105: help => 'Default_User_Quota',
106: header => [{col1 => 'User type',
107: col2 => 'Default quota'}],
108: },
109: 'autoenroll' =>
110: { text => 'Auto-enrollment settings',
111: help => 'Domain_Auto_Enrollment',
112: header => [{col1 => 'Configuration setting',
113: col2 => 'Value(s)'}],
114: },
115: 'autoupdate' =>
116: { text => 'Auto-update settings',
117: help => 'Domain_Auto_Update',
118: header => [{col1 => 'Setting',
119: col2 => 'Value',},
1.43 raeburn 120: {col1 => 'User population',
1.30 raeburn 121: col2 => 'Updataeable user data'}],
122: },
123: 'directorysrch' =>
124: { text => 'Institutional directory searches',
125: help => 'Domain_Directory_Search',
126: header => [{col1 => 'Setting',
127: col2 => 'Value',}],
128: },
129: 'contacts' =>
130: { text => 'Contact Information',
131: help => 'Domain_Contact_Information',
132: header => [{col1 => 'Setting',
133: col2 => 'Value',}],
134: },
135:
136: 'usercreation' =>
137: { text => 'User creation',
138: help => 'Domain_User_Creation',
1.43 raeburn 139: header => [{col1 => 'Format rule type',
140: col2 => 'Format rules in force'},
1.34 raeburn 141: {col1 => 'User account creation',
142: col2 => 'Usernames which may be created',},
1.30 raeburn 143: {col1 => 'Context',
1.43 raeburn 144: col2 => 'Assignable authentication types'}],
1.30 raeburn 145: },
1.33 raeburn 146: 'usermodification' =>
147: { text => 'User modification',
148: help => 'Domain_User_Modification',
149: header => [{col1 => 'Target user has role',
150: col2 => 'User information updateable in author context'},
151: {col1 => 'Target user has role',
152: col2 => 'User information updateable in course context'}],
153: },
1.46 ! raeburn 154: 'scantron' =>
! 155: { text => 'Scantron format file',
! 156: help => 'Domain_Scantron_Formats',
! 157: header => [ {col1 => 'Item',
! 158: col2 => '',
! 159: }],
! 160: },
1.3 raeburn 161: );
1.6 raeburn 162: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 163: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 164: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 165: ({href=>"javascript:changePage(document.$phase,'pickactions')",
166: text=>"Pick functionality"});
1.9 raeburn 167: my $confname = $dom.'-domainconfig';
1.3 raeburn 168: if ($phase eq 'process') {
1.1 raeburn 169: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 170: ({href=>"javascript:changePage(document.$phase,'display')",
171: text=>"Domain Configuration"},
172: {href=>"javascript:changePage(document.$phase,'$phase')",
1.3 raeburn 173: text=>"Updated"});
174: &print_header($r,$phase);
1.30 raeburn 175: foreach my $item (@prefs_order) {
176: if (grep(/^\Q$item\E$/,@actions)) {
177: $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
178: &process_changes($r,$dom,$confname,$item,
179: \@roles,%domconfig));
180: }
1.3 raeburn 181: }
182: $r->print('<p>');
1.30 raeburn 183: &print_footer($r,$phase,'display','Back to configuration display',
184: \@actions);
1.3 raeburn 185: $r->print('</p>');
1.30 raeburn 186: } elsif ($phase eq 'display') {
187: &Apache::lonhtmlcommon::add_breadcrumb
188: ({href=>"javascript:changePage(document.$phase,'display')",
189: text=>"Domain Configuration"});
190: &print_header($r,$phase);
191: if (@actions > 0) {
192: my $rowsum = 0;
193: my (%output,%rowtotal,@items);
194: my $halfway = @actions/2;
195: foreach my $item (@prefs_order) {
196: if (grep(/^\Q$item\E$/,@actions)) {
197: push(@items,$item);
198: ($output{$item},$rowtotal{$item}) =
199: &print_config_box($r,$dom,$confname,$phase,
200: $item,$prefs{$item},
201: $domconfig{$item});
202: $rowsum += $rowtotal{$item};
203: }
204: }
205: my $colend;
206: my $halfway = $rowsum/2;
207: my $aggregate = 0;
208: my $sumleft = 0;
209: my $sumright = 0;
210: my $crossover;
211: for (my $i=0; $i<@items; $i++) {
212: $aggregate += $rowtotal{$items[$i]};
213: if ($aggregate > $halfway) {
214: $crossover = $i;
215: last;
216: }
217: }
218: for (my $i=0; $i<$crossover; $i++) {
219: $sumleft += $rowtotal{$items[$i]};
220: }
221: for (my $i=$crossover+1; $i<@items; $i++) {
222: $sumright += $rowtotal{$items[$i]};
223: }
224: if ((@items > 1) && ($env{'form.numcols'} == 2)) {
225: my $sumdiff = $sumright - $sumleft;
226: if ($sumdiff > 0) {
227: $colend = $crossover + 1;
228: } else {
229: $colend = $crossover;
230: }
231: } else {
232: $colend = @items;
233: }
234: $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
235: for (my $i=0; $i<$colend; $i++) {
236: $r->print($output{$items[$i]});
237: }
238: $r->print('</td><td></td><td class="LC_right_col">');
239: if ($colend < @items) {
240: for (my $i=$colend; $i<@items; $i++) {
241: $r->print($output{$items[$i]});
242: }
243: }
244: $r->print('</td></tr></table></p>');
245: $r->print(&print_footer($r,$phase,'process','Save',\@actions));
246: } else {
247: $r->print('<input type="hidden" name="phase" value="" />'.
248: '<input type="hidden" name="numcols" value="'.
249: $env{'form.numcols'}.'" />'."\n".
250: '<span clas="LC_error">'.&mt('No settings chosen').
251: '</span>');
252: }
253: $r->print('</form>');
254: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 255: } else {
1.3 raeburn 256: if ($phase eq '') {
1.30 raeburn 257: $phase = 'pickactions';
1.1 raeburn 258: }
1.30 raeburn 259: my %helphash;
1.3 raeburn 260: &print_header($r,$phase);
1.21 raeburn 261: if (keys(%domconfig) == 0) {
262: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 263: my @ids=&Apache::lonnet::current_machine_ids();
264: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 265: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 266: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 267: my $custom_img_count = 0;
268: foreach my $img (@loginimages) {
269: if ($designhash{$dom.'.login.'.$img} ne '') {
270: $custom_img_count ++;
271: }
272: }
273: foreach my $role (@roles) {
274: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
275: $custom_img_count ++;
276: }
277: }
278: if ($custom_img_count > 0) {
279: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 280: $r->print(
281: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
282: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
283: &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 />'.
284: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
285: if ($switch_server) {
1.30 raeburn 286: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 287: }
1.21 raeburn 288: return OK;
289: }
290: }
291: }
1.30 raeburn 292: $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
293: $r->print('<script type="text/javascript">'."\n".
294: &Apache::loncommon::check_uncheck_jscript()."\n".
295: '</script>'."\n".'<p><input type="button" value="check all" '.
296: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
297: ' /> '.
298: '<input type="button" value="uncheck all" '.
299: 'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
1.38 raeburn 300: ' /></p><div class="LC_left_float">');
301: my ($numitems,$midpoint,$seconddiv,$count);
302: $numitems = @prefs_order;
303: $midpoint = int($numitems/2);
304: if ($numitems%2) {
305: $midpoint ++;
306: }
307: $count = 0;
1.30 raeburn 308: foreach my $item (@prefs_order) {
1.38 raeburn 309: $r->print('<h4><label><input type="checkbox" name="actions" value="'.$item.'" /> '.$prefs{$item}->{'text'}.'</label></h4>');
310: $count ++;
311: if ((!$seconddiv) && ($count >= $midpoint)) {
312: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
313: $seconddiv = 1;
314: }
1.30 raeburn 315: }
1.38 raeburn 316: $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
317: &mt('Display options').'</h3>'."\n".
1.30 raeburn 318: '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
319: '<label><input type="radio" name="numcols" value="1">'.
320: &mt('one column').'</label> '.
321: '<input type="radio" name="numcols" value="2">'.
322: &mt('two columns').'</label></span></p>');
323: $r->print(&print_footer($r,$phase,'display','Go'));
324: $r->print('</form>');
325: $r->print(&Apache::loncommon::end_page());
1.3 raeburn 326: }
327: return OK;
328: }
329:
330: sub process_changes {
1.9 raeburn 331: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 332: my $output;
333: if ($action eq 'login') {
1.9 raeburn 334: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 335: } elsif ($action eq 'rolecolors') {
1.9 raeburn 336: $output = &modify_rolecolors($r,$dom,$confname,$roles,
337: %domconfig);
1.3 raeburn 338: } elsif ($action eq 'quotas') {
339: $output = &modify_quotas($dom,%domconfig);
340: } elsif ($action eq 'autoenroll') {
341: $output = &modify_autoenroll($dom,%domconfig);
342: } elsif ($action eq 'autoupdate') {
343: $output = &modify_autoupdate($dom,%domconfig);
1.23 raeburn 344: } elsif ($action eq 'directorysrch') {
345: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 346: } elsif ($action eq 'usercreation') {
1.28 raeburn 347: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 348: } elsif ($action eq 'usermodification') {
349: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 350: } elsif ($action eq 'contacts') {
351: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 352: } elsif ($action eq 'defaults') {
353: $output = &modify_defaults($dom,$r);
1.46 ! raeburn 354: } elsif ($action eq 'scantron') {
! 355: $output = &modify_scantron($r,$dom,$confname,\%domconfig);
1.3 raeburn 356: }
357: return $output;
358: }
359:
360: sub print_config_box {
1.9 raeburn 361: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 362: my $rowtotal = 0;
363: my $output =
364: '<table class="LC_nested_outer">
1.3 raeburn 365: <tr>
1.30 raeburn 366: <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).
367: ' </span></th></tr>';
1.22 raeburn 368: #
369: # FIXME - put the help link back in when the help files exist
370: # <th>'.&mt($item->{text}).' '.
371: # &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
372: # </tr>');
1.30 raeburn 373: $rowtotal ++;
1.28 raeburn 374: if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||
1.33 raeburn 375: ($action eq 'usercreation') || ($action eq 'usermodification')) {
1.6 raeburn 376: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.30 raeburn 377: $output .= '
1.3 raeburn 378: <tr>
379: <td>
380: <table class="LC_nested">
381: <tr class="LC_info_row">
1.6 raeburn 382: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 383: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30 raeburn 384: </tr>';
385: $rowtotal ++;
1.6 raeburn 386: if ($action eq 'autoupdate') {
1.30 raeburn 387: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 388: } elsif ($action eq 'usercreation') {
1.33 raeburn 389: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
390: } elsif ($action eq 'usermodification') {
391: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.6 raeburn 392: } else {
1.30 raeburn 393: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 394: }
1.30 raeburn 395: $output .= '
1.6 raeburn 396: </table>
397: </td>
398: </tr>
399: <tr>
400: <td>
401: <table class="LC_nested">
402: <tr class="LC_info_row">
403: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
404: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
1.30 raeburn 405: </tr>';
406: $rowtotal ++;
1.6 raeburn 407: if ($action eq 'autoupdate') {
1.30 raeburn 408: $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
1.28 raeburn 409: } elsif ($action eq 'usercreation') {
1.34 raeburn 410: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
411: </table>
412: </td>
413: </tr>
414: <tr>
415: <td>
416: <table class="LC_nested">
417: <tr class="LC_info_row">
418: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
419: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td> </tr>'.
420: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
421: $rowtotal ++;
1.33 raeburn 422: } elsif ($action eq 'usermodification') {
423: $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
1.6 raeburn 424: } else {
1.30 raeburn 425: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 426: </table>
427: </td>
428: </tr>
429: <tr>
430: <td>
431: <table class="LC_nested">
432: <tr class="LC_info_row">
433: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
434: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 435: </tr>'.
1.30 raeburn 436: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 437: </table>
438: </td>
439: </tr>
440: <tr>
441: <td>
442: <table class="LC_nested">
443: <tr class="LC_info_row">
1.6 raeburn 444: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
445: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 446: </tr>'.
1.30 raeburn 447: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
448: $rowtotal += 2;
1.6 raeburn 449: }
1.3 raeburn 450: } else {
1.30 raeburn 451: $output .= '
1.3 raeburn 452: <tr>
453: <td>
454: <table class="LC_nested">
1.30 raeburn 455: <tr class="LC_info_row">';
1.24 raeburn 456: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 457: $output .= '
458: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6 raeburn 459: } else {
1.30 raeburn 460: $output .= '
461: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6 raeburn 462: }
1.30 raeburn 463: $output .= '
1.3 raeburn 464: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30 raeburn 465: </tr>';
466: $rowtotal ++;
1.3 raeburn 467: if ($action eq 'login') {
1.30 raeburn 468: $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
1.3 raeburn 469: } elsif ($action eq 'quotas') {
1.30 raeburn 470: $output .= &print_quotas($dom,$settings,\$rowtotal);
1.3 raeburn 471: } elsif ($action eq 'autoenroll') {
1.30 raeburn 472: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.23 raeburn 473: } elsif ($action eq 'directorysrch') {
1.30 raeburn 474: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 475: } elsif ($action eq 'contacts') {
1.30 raeburn 476: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 477: } elsif ($action eq 'defaults') {
478: $output .= &print_defaults($dom,\$rowtotal);
1.46 ! raeburn 479: } elsif ($action eq 'scantron') {
! 480: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.27 raeburn 481: }
1.3 raeburn 482: }
1.30 raeburn 483: $output .= '
1.3 raeburn 484: </table>
485: </td>
486: </tr>
1.30 raeburn 487: </table><br />';
488: return ($output,$rowtotal);
1.1 raeburn 489: }
490:
491: sub print_header {
1.3 raeburn 492: my ($r,$phase) = @_;
1.30 raeburn 493: my $alert = &mt('You must select at least one functionality type to display.');
1.6 raeburn 494: my $js = '
1.1 raeburn 495: <script type="text/javascript">
496: function changePage(formname,newphase) {
497: formname.phase.value = newphase;
1.30 raeburn 498: numchecked = 0;
499: if (formname == document.pickactions) {
500: if (formname.actions.length > 0) {
501: for (var i = 0; i <formname.actions.length; i++) {
502: if (formname.actions[i].checked) {
503: numchecked ++;
504: }
505: }
506: } else {
507: if (formname.actions.checked) {
508: numchecked ++;
509: }
510: }
511: if (numchecked > 0) {
512: formname.submit();
513: } else {
514: alert("'.$alert.'");
515: return;
516: }
517: }
1.1 raeburn 518: formname.submit();
1.30 raeburn 519: }'."\n";
520: if ($phase eq 'pickactions') {
521: $js .=
522: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
523: &javascript_set_colnums();
524: } elsif ($phase eq 'display') {
525: $js .= &color_pick_js()."\n";
526: }
1.31 raeburn 527: $js .= &Apache::loncommon::viewport_size_js().'
1.1 raeburn 528: </script>
1.6 raeburn 529: ';
1.30 raeburn 530: my $additem;
531: if ($phase eq 'pickactions') {
532: my %loaditems = (
1.31 raeburn 533: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
1.30 raeburn 534: );
535: $additem = {'add_entries' => \%loaditems,};
536: } else {
537: my %loaditems = (
1.31 raeburn 538: 'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
1.30 raeburn 539: );
540: $additem = {'add_entries' => \%loaditems,};
541: }
1.2 albertel 542: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.30 raeburn 543: $js,$additem));
1.3 raeburn 544: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 545: $r->print('
1.8 raeburn 546: <form name="parmform" action="">
1.6 raeburn 547: <input type="hidden" name="pres_marker" />
548: <input type="hidden" name="pres_type" />
549: <input type="hidden" name="pres_value" />
550: </form>
551: ');
552: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
553: ' enctype="multipart/form-data">');
1.1 raeburn 554: return;
555: }
556:
557: sub print_footer {
1.30 raeburn 558: my ($r,$phase,$newphase,$button_text,$actions) = @_;
1.3 raeburn 559: $button_text = &mt($button_text);
1.30 raeburn 560: $r->print('<input type="hidden" name="phase" value="" />'.
561: '<input type="hidden" name="width" value="'.
562: $env{'form.width'}.'" />'.
563: '<input type="hidden" name="height" value="'.
564: $env{'form.height'}.'" />');
565: if (($phase eq 'display') || ($phase eq 'process')) {
566: if (ref($actions) eq 'ARRAY') {
567: foreach my $item (@{$actions}) {
568: $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
569: }
570: }
571: $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
572: }
1.3 raeburn 573: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
574: if ($phase eq 'process') {
1.30 raeburn 575: $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
1.3 raeburn 576: } else {
1.30 raeburn 577: my $onclick;
578: if ($phase eq 'display') {
579: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
580: } else {
581: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
582: }
583: $r->print('<p><input type="button" name="store" value="'.
584: $button_text.'" onclick='.$onclick.' /></p>');
585: }
586: if ($phase eq 'process') {
587: $r->print('</form>'.&Apache::loncommon::end_page());
1.3 raeburn 588: }
1.1 raeburn 589: return;
590: }
591:
1.3 raeburn 592: sub print_login {
1.30 raeburn 593: my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
1.6 raeburn 594: my %choices = &login_choices();
1.42 raeburn 595: my %defaultchecked = (
1.43 raeburn 596: 'coursecatalog' => 'on',
597: 'adminmail' => 'off',
598: 'newuser' => 'off',
599: );
600: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 601: my (%checkedon,%checkedoff);
602: foreach my $item (@toggles) {
603: if ($defaultchecked{$item} eq 'on') {
604: $checkedon{$item} = ' checked="checked" ';
605: $checkedoff{$item} = ' ';
606: } elsif ($defaultchecked{$item} eq 'off') {
607: $checkedoff{$item} = ' checked="checked" ';
608: $checkedon{$item} = ' ';
609: }
610: }
611: my $loginheader = 'image';
1.41 raeburn 612: my @images = ('img','logo','domlogo','login');
613: my @logintext = ('textcol','bgcol');
1.6 raeburn 614: my @bgs = ('pgbg','mainbg','sidebg');
615: my @links = ('link','alink','vlink');
1.7 albertel 616: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 617: my %defaultdesign = %Apache::loncommon::defaultdesign;
618: my (%is_custom,%designs);
619: my %defaults = (
620: font => $defaultdesign{'login.font'},
621: );
622: foreach my $item (@images) {
623: $defaults{$item} = $defaultdesign{'login.'.$item};
624: }
625: foreach my $item (@bgs) {
626: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
627: }
1.41 raeburn 628: foreach my $item (@logintext) {
629: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
630: }
1.6 raeburn 631: foreach my $item (@links) {
632: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
633: }
1.3 raeburn 634: if (ref($settings) eq 'HASH') {
1.42 raeburn 635: foreach my $item (@toggles) {
636: if ($settings->{$item} eq '1') {
637: $checkedon{$item} = ' checked="checked" ';
638: $checkedoff{$item} = ' ';
639: } elsif ($settings->{$item} eq '0') {
640: $checkedoff{$item} = ' checked="checked" ';
641: $checkedon{$item} = ' ';
642: }
1.1 raeburn 643: }
1.6 raeburn 644: foreach my $item (@images) {
645: if ($settings->{$item} ne '') {
646: $designs{$item} = $settings->{$item};
647: $is_custom{$item} = 1;
648: }
649: }
1.41 raeburn 650: foreach my $item (@logintext) {
651: if ($settings->{$item} ne '') {
652: $designs{'logintext'}{$item} = $settings->{$item};
653: $is_custom{$item} = 1;
654: }
655: }
656: if ($settings->{'loginheader'} ne '') {
657: $loginheader = $settings->{'loginheader'};
658: }
1.6 raeburn 659: if ($settings->{'font'} ne '') {
660: $designs{'font'} = $settings->{'font'};
661: $is_custom{'font'} = 1;
662: }
663: foreach my $item (@bgs) {
664: if ($settings->{$item} ne '') {
665: $designs{'bgs'}{$item} = $settings->{$item};
666: $is_custom{$item} = 1;
667: }
668: }
669: foreach my $item (@links) {
670: if ($settings->{$item} ne '') {
671: $designs{'links'}{$item} = $settings->{$item};
672: $is_custom{$item} = 1;
673: }
674: }
675: } else {
676: if ($designhash{$dom.'.login.font'} ne '') {
677: $designs{'font'} = $designhash{$dom.'.login.font'};
678: $is_custom{'font'} = 1;
679: }
1.8 raeburn 680: foreach my $item (@images) {
681: if ($designhash{$dom.'.login.'.$item} ne '') {
682: $designs{$item} = $designhash{$dom.'.login.'.$item};
683: $is_custom{$item} = 1;
684: }
685: }
1.6 raeburn 686: foreach my $item (@bgs) {
687: if ($designhash{$dom.'.login.'.$item} ne '') {
688: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
689: $is_custom{$item} = 1;
690: }
691: }
692: foreach my $item (@links) {
693: if ($designhash{$dom.'.login.'.$item} ne '') {
694: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
695: $is_custom{$item} = 1;
696: }
697: }
1.1 raeburn 698: }
1.6 raeburn 699: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
700: logo => 'Institution Logo',
1.41 raeburn 701: domlogo => 'Domain Logo',
702: login => 'Login box');
1.6 raeburn 703: my $itemcount = 1;
1.42 raeburn 704: my ($css_class,$datatable);
705: foreach my $item (@toggles) {
706: $css_class = $itemcount%2?' class="LC_odd_row"':'';
707: $datatable .=
708: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
709: '</td><td>'.
710: '<span class="LC_nobreak"><label><input type="radio" name="'.
711: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
712: '</label> <label><input type="radio" name="'.$item.'"'.
713: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
714: '</tr>';
715: $itemcount ++;
716: }
1.41 raeburn 717: $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 718: $datatable .= '</tr></table></td></tr>';
719: return $datatable;
720: }
721:
722: sub login_choices {
723: my %choices =
724: &Apache::lonlocal::texthash (
725: coursecatalog => 'Display Course Catalog link?',
726: adminmail => "Display Administrator's E-mail Address?",
1.43 raeburn 727: newuser => "Link to create a user account",
1.6 raeburn 728: img => "Header",
729: logo => "Main Logo",
730: domlogo => "Domain Logo",
1.41 raeburn 731: login => "Log-in Header",
732: textcol => "Text color",
733: bgcol => "Box color",
1.6 raeburn 734: bgs => "Background colors",
735: links => "Link colors",
736: font => "Font color",
737: pgbg => "Page",
738: mainbg => "Main panel",
739: sidebg => "Side panel",
740: link => "Link",
741: alink => "Active link",
742: vlink => "Visited link",
743: );
744: return %choices;
745: }
746:
747: sub print_rolecolors {
1.30 raeburn 748: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 749: my %choices = &color_font_choices();
750: my @bgs = ('pgbg','tabbg','sidebg');
751: my @links = ('link','alink','vlink');
752: my @images = ('img');
753: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 754: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 755: my %defaultdesign = %Apache::loncommon::defaultdesign;
756: my (%is_custom,%designs);
757: my %defaults = (
758: img => $defaultdesign{$role.'.img'},
759: font => $defaultdesign{$role.'.font'},
760: );
761: foreach my $item (@bgs) {
762: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
763: }
764: foreach my $item (@links) {
765: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
766: }
767: if (ref($settings) eq 'HASH') {
768: if (ref($settings->{$role}) eq 'HASH') {
769: if ($settings->{$role}->{'img'} ne '') {
770: $designs{'img'} = $settings->{$role}->{'img'};
771: $is_custom{'img'} = 1;
772: }
773: if ($settings->{$role}->{'font'} ne '') {
774: $designs{'font'} = $settings->{$role}->{'font'};
775: $is_custom{'font'} = 1;
776: }
777: foreach my $item (@bgs) {
778: if ($settings->{$role}->{$item} ne '') {
779: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
780: $is_custom{$item} = 1;
781: }
782: }
783: foreach my $item (@links) {
784: if ($settings->{$role}->{$item} ne '') {
785: $designs{'links'}{$item} = $settings->{$role}->{$item};
786: $is_custom{$item} = 1;
787: }
788: }
789: }
790: } else {
791: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
792: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
793: $is_custom{'img'} = 1;
794: }
795: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
796: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
797: $is_custom{'font'} = 1;
798: }
799: foreach my $item (@bgs) {
800: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
801: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
802: $is_custom{$item} = 1;
803:
804: }
805: }
806: foreach my $item (@links) {
807: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
808: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
809: $is_custom{$item} = 1;
810: }
811: }
812: }
813: my $itemcount = 1;
1.30 raeburn 814: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 815: $datatable .= '</tr></table></td></tr>';
816: return $datatable;
817: }
818:
819: sub display_color_options {
1.9 raeburn 820: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.41 raeburn 821: $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
1.6 raeburn 822: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
823: my $datatable = '<tr'.$css_class.'>'.
824: '<td>'.$choices->{'font'}.'</td>';
825: if (!$is_custom->{'font'}) {
1.30 raeburn 826: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 827: } else {
828: $datatable .= '<td> </td>';
829: }
830: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 831: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 832: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 833: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 834: ' <span id="css_'.$role.'_font" style="background-color: '.
835: $designs->{'font'}.';"> </span>'.
1.8 raeburn 836: '</span></td></tr>';
1.9 raeburn 837: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 838: foreach my $img (@{$images}) {
1.18 albertel 839: $itemcount ++;
1.6 raeburn 840: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 841: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 842: '<td>'.$choices->{$img}.'</td>';
1.41 raeburn 843: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.6 raeburn 844: if ($designs->{$img} ne '') {
845: $imgfile = $designs->{$img};
1.18 albertel 846: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 847: } else {
848: $imgfile = $defaults->{$img};
849: }
1.41 raeburn 850: if ($img eq 'login') {
851: $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices,
852: $loginheader);
853: $logincolors =
854: &login_text_colors($img,$role,$logintext,$phase,$choices,$designs);
855: }
1.6 raeburn 856: if ($imgfile) {
1.9 raeburn 857: my ($showfile,$fullsize);
858: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 859: my $urldir = $1;
860: my $filename = $2;
861: my @info = &Apache::lonnet::stat_file($designs->{$img});
862: if (@info) {
863: my $thumbfile = 'tn-'.$filename;
864: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
865: if (@thumb) {
866: $showfile = $urldir.'/'.$thumbfile;
867: } else {
868: $showfile = $imgfile;
869: }
870: } else {
871: $showfile = '';
872: }
873: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 874: $showfile = $imgfile;
1.6 raeburn 875: my $imgdir = $1;
876: my $filename = $2;
877: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
878: $showfile = "/$imgdir/tn-".$filename;
879: } else {
880: my $input = "/home/httpd/html".$imgfile;
881: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
882: if (!-e $output) {
1.9 raeburn 883: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 884: my ($fullwidth,$fullheight) = &check_dimensions($input);
885: if ($fullwidth ne '' && $fullheight ne '') {
886: if ($fullwidth > $width && $fullheight > $height) {
887: my $size = $width.'x'.$height;
888: system("convert -sample $size $input $output");
889: $showfile = '/'.$imgdir.'/tn-'.$filename;
890: }
891: }
1.6 raeburn 892: }
893: }
1.16 raeburn 894: }
1.6 raeburn 895: if ($showfile) {
1.40 raeburn 896: if ($showfile =~ m{^/(adm|res)/}) {
897: if ($showfile =~ m{^/res/}) {
898: my $local_showfile =
899: &Apache::lonnet::filelocation('',$showfile);
900: &Apache::lonnet::repcopy($local_showfile);
901: }
902: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
903: }
904: if ($imgfile) {
905: if ($imgfile =~ m{^/(adm|res)/}) {
906: if ($imgfile =~ m{^/res/}) {
907: my $local_imgfile =
908: &Apache::lonnet::filelocation('',$imgfile);
909: &Apache::lonnet::repcopy($local_imgfile);
910: }
911: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
912: } else {
913: $fullsize = $imgfile;
914: }
915: }
1.41 raeburn 916: $datatable .= '<td>';
917: if ($img eq 'login') {
918: $datatable .= $login_hdr_pick;
1.6 raeburn 919: }
1.41 raeburn 920: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
921: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 922: } else {
923: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
924: &mt('Upload:');
925: }
926: } else {
927: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
928: &mt('Upload:');
929: }
1.9 raeburn 930: if ($switchserver) {
931: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
932: } else {
933: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
934: }
935: $datatable .= '</td></tr>';
1.6 raeburn 936: }
937: $itemcount ++;
938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
939: $datatable .= '<tr'.$css_class.'>'.
940: '<td>'.$choices->{'bgs'}.'</td>';
941: my $bgs_def;
942: foreach my $item (@{$bgs}) {
943: if (!$is_custom->{$item}) {
1.30 raeburn 944: $bgs_def .= '<td>'.$choices->{$item}.' <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 945: }
946: }
947: if ($bgs_def) {
1.8 raeburn 948: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 949: } else {
950: $datatable .= '<td> </td>';
951: }
952: $datatable .= '<td class="LC_right_item">'.
953: '<table border="0"><tr>';
954: foreach my $item (@{$bgs}) {
955: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
956: $datatable .= '<td align="center">'.$link;
957: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 958: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 959: }
960: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 961: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 962: }
963: $datatable .= '</tr></table></td></tr>';
964: $itemcount ++;
965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
966: $datatable .= '<tr'.$css_class.'>'.
967: '<td>'.$choices->{'links'}.'</td>';
968: my $links_def;
969: foreach my $item (@{$links}) {
970: if (!$is_custom->{$item}) {
1.30 raeburn 971: $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 972: }
973: }
974: if ($links_def) {
1.8 raeburn 975: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 976: } else {
977: $datatable .= '<td> </td>';
978: }
979: $datatable .= '<td class="LC_right_item">'.
980: '<table border="0"><tr>';
981: foreach my $item (@{$links}) {
1.30 raeburn 982: $datatable .= '<td align="center">'."\n".
983: &color_pick($phase,$role,$item,$choices->{$item},
984: $designs->{'links'}{$item});
1.6 raeburn 985: if ($designs->{'links'}{$item}) {
1.30 raeburn 986: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 987: }
988: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
989: '" /></td>';
990: }
1.30 raeburn 991: $$rowtotal += $itemcount;
1.3 raeburn 992: return $datatable;
993: }
994:
1.41 raeburn 995: sub login_header_options {
996: my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
997: my $image_checked = ' checked="checked" ';
998: my $text_checked = ' ';
999: if ($loginheader eq 'text') {
1000: $image_checked = ' ';
1001: $text_checked = ' checked="checked" ';
1002: }
1003: my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
1004: 'loginheader" value="image" '.$image_checked.'/>'.
1005: &mt('use image').'</label> '.
1006: '<label><input type="radio" name="loginheader" value="text"'.
1007: $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
1008: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1009: $output .= &mt('Text default(s)').':<br />';
1010: if (!$is_custom->{'textcol'}) {
1011: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1012: ' ';
1013: }
1014: if (!$is_custom->{'bgcol'}) {
1015: $output .= $choices->{'bgcol'}.': '.
1016: '<span id="css_'.$role.'_font" style="background-color: '.
1017: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1018: }
1019: $output .= '<br />';
1020: }
1021: $output .='<br />';
1022: return $output;
1023: }
1024:
1025: sub login_text_colors {
1026: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1027: my $color_menu = '<table border="0"><tr>';
1028: foreach my $item (@{$logintext}) {
1029: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1030: $color_menu .= '<td align="center">'.$link;
1031: if ($designs->{'logintext'}{$item}) {
1032: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1033: }
1034: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1035: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1036: '<td> </td>';
1037: }
1038: $color_menu .= '</tr></table><br />';
1039: return $color_menu;
1040: }
1041:
1042: sub image_changes {
1043: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1044: my $output;
1045: if (!$is_custom) {
1046: if ($img eq 'login') {
1047: $output .= &mt('Default image:').'<br />';
1048: } else {
1049: $output .= &mt('Default in use:').'<br />';
1050: }
1051: }
1052: if ($img_import) {
1053: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1054: }
1055: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1056: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1057: if ($is_custom) {
1058: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1059: '<input type="checkbox" name="'.
1060: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1061: '</label> '.&mt('Replace:').'</span><br />';
1062: } else {
1063: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1064: }
1065: return $output;
1066: }
1067:
1.6 raeburn 1068: sub color_pick {
1069: my ($phase,$role,$item,$desc,$curcol) = @_;
1070: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1071: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1072: ');">'.$desc.'</a>';
1073: return $link;
1074: }
1075:
1076: sub color_pick_js {
1077: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1078: my $output = <<"ENDCOL";
1079: function pclose() {
1080: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
1081: parmwin.close();
1082: }
1083:
1084: $pjump_def
1085:
1086: function psub() {
1087: pclose();
1088: if (document.parmform.pres_marker.value!='') {
1089: if (document.parmform.pres_type.value!='') {
1090: eval('document.display.'+
1091: document.parmform.pres_marker.value+
1092: '.value=document.parmform.pres_value.value;');
1093: }
1094: } else {
1095: document.parmform.pres_value.value='';
1096: document.parmform.pres_marker.value='';
1097: }
1098: }
1.41 raeburn 1099:
1100: function get_id (span_id) {
1101: if (document.getElementById) {
1102: return document.getElementById(span_id);
1103: }
1104: if (document.all) {
1105: return document.all[span_id];
1106: }
1107: return false;
1108: }
1109:
1110: function colchg_span (span_id_str,new_color_item) {
1111: var span_ref = get_id(span_id_str);
1112: if (span_ref.style) { span_ref = span_ref.style; }
1113: span_ref.background = new_color_item.value;
1114: span_ref.backgroundColor = new_color_item.value;
1115: span_ref.bgColor = new_color_item.value;
1116: }
1117:
1.6 raeburn 1118: ENDCOL
1119: return $output;
1120: }
1121:
1.3 raeburn 1122: sub print_quotas {
1.30 raeburn 1123: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1124: my $datatable;
1.44 raeburn 1125: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1126: my $typecount = 0;
1127: my $css_class;
1.26 raeburn 1128: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1129: foreach my $type (@{$types}) {
1.3 raeburn 1130: if (defined($usertypes->{$type})) {
1131: $typecount ++;
1132: $css_class = $typecount%2?' class="LC_odd_row"':'';
1133: $datatable .= '<tr'.$css_class.'>'.
1134: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 1135: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1136: '<input type="text" name="quota_'.$type.
1137: '" value="'.$settings->{$type}.
1.8 raeburn 1138: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 1139: }
1140: }
1141: }
1142: my $defaultquota = '20';
1143: if (ref($settings) eq 'HASH') {
1144: if (defined($settings->{'default'})) {
1145: $defaultquota = $settings->{'default'};
1146: }
1147: }
1148: $typecount ++;
1149: $css_class = $typecount%2?' class="LC_odd_row"':'';
1150: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1151: '<td>'.$othertitle.'</td>'.
1.8 raeburn 1152: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 1153: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 1154: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.30 raeburn 1155: $$rowtotal += $typecount;
1.3 raeburn 1156: return $datatable;
1157: }
1158:
1159: sub print_autoenroll {
1.30 raeburn 1160: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1161: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1162: my ($defdom,$runon,$runoff);
1.3 raeburn 1163: if (ref($settings) eq 'HASH') {
1164: if (exists($settings->{'run'})) {
1165: if ($settings->{'run'} eq '0') {
1166: $runoff = ' checked="checked" ';
1167: $runon = ' ';
1168: } else {
1169: $runon = ' checked="checked" ';
1170: $runoff = ' ';
1171: }
1172: } else {
1173: if ($autorun) {
1174: $runon = ' checked="checked" ';
1175: $runoff = ' ';
1176: } else {
1177: $runoff = ' checked="checked" ';
1178: $runon = ' ';
1179: }
1180: }
1181: if (exists($settings->{'sender_domain'})) {
1182: $defdom = $settings->{'sender_domain'};
1183: }
1.14 raeburn 1184: } else {
1185: if ($autorun) {
1186: $runon = ' checked="checked" ';
1187: $runoff = ' ';
1188: } else {
1189: $runoff = ' checked="checked" ';
1190: $runon = ' ';
1191: }
1.3 raeburn 1192: }
1193: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1194: my $notif_sender;
1195: if (ref($settings) eq 'HASH') {
1196: $notif_sender = $settings->{'sender_uname'};
1197: }
1.3 raeburn 1198: my $datatable='<tr class="LC_odd_row">'.
1199: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1200: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1201: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1202: $runon.' value="1" />'.&mt('Yes').'</label> '.
1203: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1204: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1205: '</tr><tr>'.
1206: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1207: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1208: &mt('username').': '.
1209: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1210: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1211: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1212: $$rowtotal += 2;
1.3 raeburn 1213: return $datatable;
1214: }
1215:
1216: sub print_autoupdate {
1.30 raeburn 1217: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1218: my $datatable;
1219: if ($position eq 'top') {
1220: my $updateon = ' ';
1221: my $updateoff = ' checked="checked" ';
1222: my $classlistson = ' ';
1223: my $classlistsoff = ' checked="checked" ';
1224: if (ref($settings) eq 'HASH') {
1225: if ($settings->{'run'} eq '1') {
1226: $updateon = $updateoff;
1227: $updateoff = ' ';
1228: }
1229: if ($settings->{'classlists'} eq '1') {
1230: $classlistson = $classlistsoff;
1231: $classlistsoff = ' ';
1232: }
1233: }
1234: my %title = (
1235: run => 'Auto-update active?',
1236: classlists => 'Update information in classlists?',
1237: );
1238: $datatable = '<tr class="LC_odd_row">'.
1239: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1240: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1241: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1242: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1243: '<label><input type="radio" name="autoupdate_run"'.
1244: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1245: '</tr><tr>'.
1246: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1247: '<td class="LC_right_item"><span class="LC_nobreak">'.
1248: '<label><input type="radio" name="classlists"'.
1249: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1250: '<label><input type="radio" name="classlists"'.
1251: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1252: '</tr>';
1.30 raeburn 1253: $$rowtotal += 2;
1.3 raeburn 1254: } else {
1.44 raeburn 1255: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.20 raeburn 1256: my @fields = ('lastname','firstname','middlename','gen',
1257: 'permanentemail','id');
1.33 raeburn 1258: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1259: my $numrows = 0;
1.26 raeburn 1260: if (ref($types) eq 'ARRAY') {
1261: if (@{$types} > 0) {
1262: $datatable =
1263: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1264: \@fields,$types,\$numrows);
1.30 raeburn 1265: $$rowtotal += @{$types};
1.26 raeburn 1266: }
1.3 raeburn 1267: }
1268: $datatable .=
1269: &usertype_update_row($settings,{'default' => $othertitle},
1270: \%fieldtitles,\@fields,['default'],
1271: \$numrows);
1.30 raeburn 1272: $$rowtotal ++;
1.3 raeburn 1273: }
1274: return $datatable;
1275: }
1276:
1.23 raeburn 1277: sub print_directorysrch {
1.30 raeburn 1278: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1279: my $srchon = ' ';
1280: my $srchoff = ' checked="checked" ';
1.25 raeburn 1281: my ($exacton,$containson,$beginson);
1.24 raeburn 1282: my $localon = ' ';
1283: my $localoff = ' checked="checked" ';
1.23 raeburn 1284: if (ref($settings) eq 'HASH') {
1285: if ($settings->{'available'} eq '1') {
1286: $srchon = $srchoff;
1287: $srchoff = ' ';
1288: }
1.24 raeburn 1289: if ($settings->{'localonly'} eq '1') {
1290: $localon = $localoff;
1291: $localoff = ' ';
1292: }
1.25 raeburn 1293: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1294: foreach my $type (@{$settings->{'searchtypes'}}) {
1295: if ($type eq 'exact') {
1296: $exacton = ' checked="checked" ';
1297: } elsif ($type eq 'contains') {
1298: $containson = ' checked="checked" ';
1299: } elsif ($type eq 'begins') {
1300: $beginson = ' checked="checked" ';
1301: }
1302: }
1303: } else {
1304: if ($settings->{'searchtypes'} eq 'exact') {
1305: $exacton = ' checked="checked" ';
1306: } elsif ($settings->{'searchtypes'} eq 'contains') {
1307: $containson = ' checked="checked" ';
1308: } elsif ($settings->{'searchtypes'} eq 'specify') {
1309: $exacton = ' checked="checked" ';
1310: $containson = ' checked="checked" ';
1311: }
1.23 raeburn 1312: }
1313: }
1314: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1316:
1317: my $numinrow = 4;
1.26 raeburn 1318: my $cansrchrow = 0;
1.23 raeburn 1319: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1320: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1321: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1322: '<input type="radio" name="dirsrch_available"'.
1323: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1324: '<label><input type="radio" name="dirsrch_available"'.
1325: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1326: '</tr><tr>'.
1.30 raeburn 1327: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1328: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1329: '<input type="radio" name="dirsrch_localonly"'.
1330: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1331: '<label><input type="radio" name="dirsrch_localonly"'.
1332: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1333: '</tr>';
1.30 raeburn 1334: $$rowtotal += 2;
1.26 raeburn 1335: if (ref($usertypes) eq 'HASH') {
1336: if (keys(%{$usertypes}) > 0) {
1337: $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
1338: $numinrow,$othertitle);
1339: $cansrchrow = 1;
1340: }
1341: }
1342: if ($cansrchrow) {
1.30 raeburn 1343: $$rowtotal ++;
1.26 raeburn 1344: $datatable .= '<tr>';
1345: } else {
1346: $datatable .= '<tr class="LC_odd_row">';
1347: }
1.30 raeburn 1348: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1349: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1350: foreach my $title (@{$titleorder}) {
1351: if (defined($searchtitles->{$title})) {
1352: my $check = ' ';
1.39 raeburn 1353: if (ref($settings) eq 'HASH') {
1354: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1355: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1356: $check = ' checked="checked" ';
1357: }
1.25 raeburn 1358: }
1359: }
1360: $datatable .= '<td class="LC_left_item">'.
1361: '<span class="LC_nobreak"><label>'.
1362: '<input type="checkbox" name="searchby" '.
1363: 'value="'.$title.'"'.$check.'/>'.
1364: $searchtitles->{$title}.'</label></span></td>';
1365: }
1366: }
1.26 raeburn 1367: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1368: $$rowtotal ++;
1.26 raeburn 1369: if ($cansrchrow) {
1370: $datatable .= '<tr class="LC_odd_row">';
1371: } else {
1372: $datatable .= '<tr>';
1373: }
1.30 raeburn 1374: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1375: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1376: '<span class="LC_nobreak"><label>'.
1377: '<input type="checkbox" name="searchtypes" '.
1378: $exacton.' value="exact" />'.&mt('Exact match').
1379: '</label> '.
1380: '<label><input type="checkbox" name="searchtypes" '.
1381: $beginson.' value="begins" />'.&mt('Begins with').
1382: '</label> '.
1383: '<label><input type="checkbox" name="searchtypes" '.
1384: $containson.' value="contains" />'.&mt('Contains').
1385: '</label></span></td></tr>';
1.30 raeburn 1386: $$rowtotal ++;
1.25 raeburn 1387: return $datatable;
1388: }
1389:
1.28 raeburn 1390: sub print_contacts {
1.30 raeburn 1391: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1392: my $datatable;
1393: my @contacts = ('adminemail','supportemail');
1394: my (%checked,%to,%otheremails);
1395: my @mailings = ('errormail','packagesmail','helpdeskmail');
1396: foreach my $type (@mailings) {
1397: $otheremails{$type} = '';
1398: }
1399: if (ref($settings) eq 'HASH') {
1400: foreach my $item (@contacts) {
1401: if (exists($settings->{$item})) {
1402: $to{$item} = $settings->{$item};
1403: }
1404: }
1405: foreach my $type (@mailings) {
1406: if (exists($settings->{$type})) {
1407: if (ref($settings->{$type}) eq 'HASH') {
1408: foreach my $item (@contacts) {
1409: if ($settings->{$type}{$item}) {
1410: $checked{$type}{$item} = ' checked="checked" ';
1411: }
1412: }
1413: $otheremails{$type} = $settings->{$type}{'others'};
1414: }
1415: }
1416: }
1417: } else {
1418: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1419: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1420: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1421: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1422: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1423: }
1424: my ($titles,$short_titles) = &contact_titles();
1425: my $rownum = 0;
1426: my $css_class;
1427: foreach my $item (@contacts) {
1428: if ($rownum%2) {
1429: $css_class = '';
1430: } else {
1431: $css_class = ' class="LC_odd_row" ';
1432: }
1.30 raeburn 1433: $datatable .= '<tr'.$css_class.'>'.
1434: '<td><span class="LC_nobreak">'.$titles->{$item}.
1435: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1436: '<input type="text" name="'.$item.'" value="'.
1437: $to{$item}.'" /></td></tr>';
1438: $rownum ++;
1439: }
1440: foreach my $type (@mailings) {
1441: if ($rownum%2) {
1442: $css_class = '';
1443: } else {
1444: $css_class = ' class="LC_odd_row" ';
1445: }
1446: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1447: '<td><span class="LC_nobreak">'.
1448: $titles->{$type}.': </span></td>'.
1.28 raeburn 1449: '<td class="LC_left_item">'.
1450: '<span class="LC_nobreak">';
1451: foreach my $item (@contacts) {
1452: $datatable .= '<label>'.
1453: '<input type="checkbox" name="'.$type.'"'.
1454: $checked{$type}{$item}.
1455: ' value="'.$item.'" />'.$short_titles->{$item}.
1456: '</label> ';
1457: }
1458: $datatable .= '</span><br />'.&mt('Others').': '.
1459: '<input type="text" name="'.$type.'_others" '.
1460: 'value="'.$otheremails{$type}.'" />'.
1461: '</td></tr>'."\n";
1462: $rownum ++;
1463: }
1.30 raeburn 1464: $$rowtotal += $rownum;
1.28 raeburn 1465: return $datatable;
1466: }
1467:
1468: sub contact_titles {
1469: my %titles = &Apache::lonlocal::texthash (
1470: 'supportemail' => 'Support E-mail address',
1471: 'adminemail' => 'Default Server Admin E-mail address',
1472: 'errormail' => 'Error reports to be e-mailed to',
1473: 'packagesmail' => 'Package update alerts to be e-mailed to',
1474: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
1475: );
1476: my %short_titles = &Apache::lonlocal::texthash (
1477: adminemail => 'Admin E-mail address',
1478: supportemail => 'Support E-mail',
1479: );
1480: return (\%titles,\%short_titles);
1481: }
1482:
1.27 raeburn 1483: sub print_usercreation {
1.30 raeburn 1484: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1485: my $numinrow = 4;
1.28 raeburn 1486: my $datatable;
1487: if ($position eq 'top') {
1.30 raeburn 1488: $$rowtotal ++;
1.34 raeburn 1489: my $rowcount = 0;
1.32 raeburn 1490: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1491: if (ref($rules) eq 'HASH') {
1492: if (keys(%{$rules}) > 0) {
1.32 raeburn 1493: $datatable .= &user_formats_row('username',$settings,$rules,
1494: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1495: $$rowtotal ++;
1.32 raeburn 1496: $rowcount ++;
1497: }
1498: }
1499: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1500: if (ref($idrules) eq 'HASH') {
1501: if (keys(%{$idrules}) > 0) {
1502: $datatable .= &user_formats_row('id',$settings,$idrules,
1503: $idruleorder,$numinrow,$rowcount);
1504: $$rowtotal ++;
1505: $rowcount ++;
1.28 raeburn 1506: }
1507: }
1.43 raeburn 1508: my ($emailrules,$emailruleorder) =
1509: &Apache::lonnet::inst_userrules($dom,'email');
1510: if (ref($emailrules) eq 'HASH') {
1511: if (keys(%{$emailrules}) > 0) {
1512: $datatable .= &user_formats_row('email',$settings,$emailrules,
1513: $emailruleorder,$numinrow,$rowcount);
1514: $$rowtotal ++;
1515: $rowcount ++;
1516: }
1517: }
1.39 raeburn 1518: if ($rowcount == 0) {
1519: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1520: $$rowtotal ++;
1521: $rowcount ++;
1522: }
1.34 raeburn 1523: } elsif ($position eq 'middle') {
1.45 raeburn 1524: my @creators = ('author','course','selfcreate');
1.37 raeburn 1525: my ($rules,$ruleorder) =
1526: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1527: my %lt = &usercreation_types();
1528: my %checked;
1529: if (ref($settings) eq 'HASH') {
1530: if (ref($settings->{'cancreate'}) eq 'HASH') {
1531: foreach my $item (@creators) {
1532: $checked{$item} = $settings->{'cancreate'}{$item};
1533: }
1534: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1535: foreach my $item (@creators) {
1536: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1537: $checked{$item} = 'none';
1538: }
1539: }
1540: }
1541: }
1542: my $rownum = 0;
1543: foreach my $item (@creators) {
1544: $rownum ++;
1545: if ($checked{$item} eq '') {
1.45 raeburn 1546: if ($item eq 'selfcreate') {
1.43 raeburn 1547: $checked{$item} = 'none';
1548: } else {
1549: $checked{$item} = 'any';
1550: }
1.34 raeburn 1551: }
1552: my $css_class;
1553: if ($rownum%2) {
1554: $css_class = '';
1555: } else {
1556: $css_class = ' class="LC_odd_row" ';
1557: }
1558: $datatable .= '<tr'.$css_class.'>'.
1559: '<td><span class="LC_nobreak">'.$lt{$item}.
1560: '</span></td><td align="right">';
1.37 raeburn 1561: my @options = ('any');
1.45 raeburn 1562: if ($item eq 'selfcreate') {
1.43 raeburn 1563: push(@options,('email','login','sso'));
1564: } else {
1565: if (ref($rules) eq 'HASH') {
1566: if (keys(%{$rules}) > 0) {
1567: push(@options,('official','unofficial'));
1568: }
1.37 raeburn 1569: }
1570: }
1571: push(@options,'none');
1572: foreach my $option (@options) {
1.34 raeburn 1573: my $check = ' ';
1574: if ($checked{$item} eq $option) {
1575: $check = ' checked="checked" ';
1576: }
1577: $datatable .= '<span class="LC_nobreak"><label>'.
1578: '<input type="radio" name="can_createuser_'.
1579: $item.'" value="'.$option.'"'.$check.'/> '.
1580: $lt{$option}.'</label> </span>';
1581: }
1582: $datatable .= '</td></tr>';
1583: }
1.28 raeburn 1584: } else {
1585: my @contexts = ('author','course','domain');
1586: my @authtypes = ('int','krb4','krb5','loc');
1587: my %checked;
1588: if (ref($settings) eq 'HASH') {
1589: if (ref($settings->{'authtypes'}) eq 'HASH') {
1590: foreach my $item (@contexts) {
1591: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
1592: foreach my $auth (@authtypes) {
1593: if ($settings->{'authtypes'}{$item}{$auth}) {
1594: $checked{$item}{$auth} = ' checked="checked" ';
1595: }
1596: }
1597: }
1598: }
1.27 raeburn 1599: }
1.35 raeburn 1600: } else {
1601: foreach my $item (@contexts) {
1.36 raeburn 1602: foreach my $auth (@authtypes) {
1.35 raeburn 1603: $checked{$item}{$auth} = ' checked="checked" ';
1604: }
1605: }
1.27 raeburn 1606: }
1.28 raeburn 1607: my %title = &context_names();
1608: my %authname = &authtype_names();
1609: my $rownum = 0;
1610: my $css_class;
1611: foreach my $item (@contexts) {
1612: if ($rownum%2) {
1613: $css_class = '';
1614: } else {
1615: $css_class = ' class="LC_odd_row" ';
1616: }
1.30 raeburn 1617: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 1618: '<td>'.$title{$item}.
1619: '</td><td class="LC_left_item">'.
1620: '<span class="LC_nobreak">';
1621: foreach my $auth (@authtypes) {
1622: $datatable .= '<label>'.
1623: '<input type="checkbox" name="'.$item.'_auth" '.
1624: $checked{$item}{$auth}.' value="'.$auth.'" />'.
1625: $authname{$auth}.'</label> ';
1626: }
1627: $datatable .= '</span></td></tr>';
1628: $rownum ++;
1.27 raeburn 1629: }
1.30 raeburn 1630: $$rowtotal += $rownum;
1.27 raeburn 1631: }
1632: return $datatable;
1633: }
1634:
1.32 raeburn 1635: sub user_formats_row {
1636: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
1637: my $output;
1638: my %text = (
1639: 'username' => 'new usernames',
1640: 'id' => 'IDs',
1.45 raeburn 1641: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 1642: );
1643: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1644: $output = '<tr '.$css_class.'>'.
1645: '<td><span class="LC_nobreak">'.
1646: &mt("Format rules to check for $text{$type}: ").
1647: '</span></td>'.
1648: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 1649: my $rem;
1650: if (ref($ruleorder) eq 'ARRAY') {
1651: for (my $i=0; $i<@{$ruleorder}; $i++) {
1652: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
1653: my $rem = $i%($numinrow);
1654: if ($rem == 0) {
1655: if ($i > 0) {
1656: $output .= '</tr>';
1657: }
1658: $output .= '<tr>';
1659: }
1660: my $check = ' ';
1.39 raeburn 1661: if (ref($settings) eq 'HASH') {
1662: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
1663: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1664: $check = ' checked="checked" ';
1665: }
1.27 raeburn 1666: }
1667: }
1668: $output .= '<td class="LC_left_item">'.
1669: '<span class="LC_nobreak"><label>'.
1.32 raeburn 1670: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 1671: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
1672: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
1673: }
1674: }
1675: $rem = @{$ruleorder}%($numinrow);
1676: }
1677: my $colsleft = $numinrow - $rem;
1678: if ($colsleft > 1 ) {
1679: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1680: ' </td>';
1681: } elsif ($colsleft == 1) {
1682: $output .= '<td class="LC_left_item"> </td>';
1683: }
1684: $output .= '</tr></table></td></tr>';
1685: return $output;
1686: }
1687:
1.34 raeburn 1688: sub usercreation_types {
1689: my %lt = &Apache::lonlocal::texthash (
1690: author => 'When adding a co-author',
1691: course => 'When adding a user to a course',
1.45 raeburn 1692: selfcreate => 'User creates own account',
1.34 raeburn 1693: any => 'Any',
1694: official => 'Institutional only ',
1695: unofficial => 'Non-institutional only',
1.43 raeburn 1696: email => 'Email address',
1697: login => 'Institutional Login',
1698: sso => 'SSO',
1.34 raeburn 1699: none => 'None',
1700: );
1701: return %lt;
1702: }
1703:
1.28 raeburn 1704: sub authtype_names {
1705: my %lt = &Apache::lonlocal::texthash(
1706: int => 'Internal',
1707: krb4 => 'Kerberos 4',
1708: krb5 => 'Kerberos 5',
1709: loc => 'Local',
1710: );
1711: return %lt;
1712: }
1713:
1714: sub context_names {
1715: my %context_title = &Apache::lonlocal::texthash(
1716: author => 'Creating users when an Author',
1717: course => 'Creating users when in a course',
1718: domain => 'Creating users when a Domain Coordinator',
1719: );
1720: return %context_title;
1721: }
1722:
1.33 raeburn 1723: sub print_usermodification {
1724: my ($position,$dom,$settings,$rowtotal) = @_;
1725: my $numinrow = 4;
1726: my ($context,$datatable,$rowcount);
1727: if ($position eq 'top') {
1728: $rowcount = 0;
1729: $context = 'author';
1730: foreach my $role ('ca','aa') {
1731: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1732: $numinrow,$rowcount);
1733: $$rowtotal ++;
1734: $rowcount ++;
1735: }
1736: } else {
1737: $context = 'course';
1738: $rowcount = 0;
1739: foreach my $role ('st','ep','ta','in','cr') {
1740: $datatable .= &modifiable_userdata_row($context,$role,$settings,
1741: $numinrow,$rowcount);
1742: $$rowtotal ++;
1743: $rowcount ++;
1744: }
1745: }
1746: return $datatable;
1747: }
1748:
1.43 raeburn 1749: sub print_defaults {
1750: my ($dom,$rowtotal) = @_;
1751: my @items = ('auth_def','auth_arg_def','lang_def');
1752: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1753: my $titles = &defaults_titles();
1754: my $rownum = 0;
1755: my ($datatable,$css_class);
1756: foreach my $item (@items) {
1757: if ($rownum%2) {
1758: $css_class = '';
1759: } else {
1760: $css_class = ' class="LC_odd_row" ';
1761: }
1762: $datatable .= '<tr'.$css_class.'>'.
1763: '<td><span class="LC_nobreak">'.$titles->{$item}.
1764: '</span></td><td class="LC_right_item">';
1765: if ($item eq 'auth_def') {
1766: my @authtypes = ('internal','krb4','krb5','localauth');
1767: my %shortauth = (
1768: internal => 'int',
1769: krb4 => 'krb4',
1770: krb5 => 'krb5',
1771: localauth => 'loc'
1772: );
1773: my %authnames = &authtype_names();
1774: foreach my $auth (@authtypes) {
1775: my $checked = ' ';
1776: if ($domdefaults{$item} eq $auth) {
1777: $checked = ' checked="checked" ';
1778: }
1779: $datatable .= '<label><input type="radio" name="'.$item.
1780: '" value="'.$auth.'"'.$checked.'/>'.
1781: $authnames{$shortauth{$auth}}.'</label> ';
1782: }
1783: } else {
1784: $datatable .= '<input type="text" name="'.$item.'" value="'.
1785: $domdefaults{$item}.'" />';
1786: }
1787: $datatable .= '</td></tr>';
1788: $rownum ++;
1789: }
1790: $$rowtotal += $rownum;
1791: return $datatable;
1792: }
1793:
1794: sub defaults_titles {
1795: my %titles = &Apache::lonlocal::texthash (
1796: 'auth_def' => 'Default authentication type',
1797: 'auth_arg_def' => 'Default authentication argument',
1798: 'lang_def' => 'Default language',
1799: );
1800: return (\%titles);
1801: }
1802:
1.46 ! raeburn 1803: sub print_scantronformat {
! 1804: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
! 1805: my $itemcount = 1;
! 1806: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls);
! 1807: my $switchserver = &check_switchserver($dom,$confname);
! 1808: my %lt = &Apache::lonlocal::texthash (
! 1809: default => 'Default scantron format file error',
! 1810: custom => 'Custom scantron format file error',
! 1811: );
! 1812: my %scantronfiles = (
! 1813: default => 'default.tab',
! 1814: custom => 'custom.tab',
! 1815: );
! 1816: foreach my $key (keys(%scantronfiles)) {
! 1817: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
! 1818: .$scantronfiles{$key};
! 1819: }
! 1820: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
! 1821: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
! 1822: if (!$switchserver) {
! 1823: my $servadm = $r->dir_config('lonAdmEMail');
! 1824: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
! 1825: if ($configuserok eq 'ok') {
! 1826: if ($author_ok eq 'ok') {
! 1827: my %legacyfile = (
! 1828: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
! 1829: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
! 1830: );
! 1831: my %md5chk;
! 1832: foreach my $type (keys(%legacyfile)) {
! 1833: $md5chk{$type} = split(/ /,`md5sum $legacyfile{$type}`);
! 1834: chop($md5chk{$type});
! 1835: }
! 1836: if ($md5chk{'default'} ne $md5chk{'custom'}) {
! 1837: foreach my $type (keys(%legacyfile)) {
! 1838: ($scantronurls{$type},$error{$type}) =
! 1839: &legacy_scantronformat($r,$dom,$confname,
! 1840: $type,$legacyfile{$type},
! 1841: $scantronurls{$type},
! 1842: $scantronfiles{$type});
! 1843: }
! 1844: } else {
! 1845: ($scantronurls{'default'},$error{'default'}) =
! 1846: &legacy_scantronformat($r,$dom,$confname,
! 1847: 'default',$legacyfile{'default'},
! 1848: $scantronurls{'default'},
! 1849: $scantronfiles{'default'});
! 1850: }
! 1851: }
! 1852: }
! 1853: } else {
! 1854: $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
! 1855: }
! 1856: }
! 1857: if (ref($settings) eq 'HASH') {
! 1858: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
! 1859: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
! 1860: if ((!@info) || ($info[0] eq 'no_such_dir')) {
! 1861: $scantronurl = '';
! 1862: } else {
! 1863: $scantronurl = $settings->{'scantronformat'};
! 1864: }
! 1865: $is_custom = 1;
! 1866: } else {
! 1867: $scantronurl = $scantronurls{'default'};
! 1868: }
! 1869: } else {
! 1870: $scantronurl = $scantronurls{'default'};
! 1871: }
! 1872: $css_class = $itemcount%2?' class="LC_odd_row"':'';
! 1873: $datatable .= '<tr'.$css_class.'>';
! 1874: if (!$is_custom) {
! 1875: $datatable .= '<td>'.&mt('Default in use:').'<br />';
! 1876: if ($scantronurl) {
! 1877: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
! 1878: &mt('Default scantron format file').'</a>';
! 1879: } else {
! 1880: $datatable = &mt('File unavailable for display');
! 1881: }
! 1882: $datatable .= '</td><td valign="bottom">'.&mt('Upload:').'<br />';
! 1883: } else {
! 1884: if (keys(%error) > 0) {
! 1885: my $errorstr;
! 1886: foreach my $key (sort(keys(%error))) {
! 1887: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
! 1888: }
! 1889: $datatable .= '<td>'.$errorstr.'</td><td>';
! 1890: } elsif ($scantronurl) {
! 1891: $datatable .= '<td><a href="'.$scantronurl.'" target="_blank">' .&mt('Custom scantron format file').'</a>'
! 1892: .'<span class="LC_nobreak"><label>'
! 1893: .'<input type="checkbox" name="scantronformat_del"'
! 1894: .'" value="1" />'.&mt('Delete?').'</label></td>'
! 1895: .'<td>'.&mt('Replace:').'</span><br />';
! 1896: }
! 1897: }
! 1898: if (keys(%error) == 0) {
! 1899: if ($switchserver) {
! 1900: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 1901: } else {
! 1902: $datatable .=' <input type="file" name="scantronformat" />';
! 1903: }
! 1904: }
! 1905: $datatable .= '</td></tr>';
! 1906: $$rowtotal ++;
! 1907: return $datatable;
! 1908: }
! 1909:
! 1910: sub legacy_scantronformat {
! 1911: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
! 1912: my ($url,$error);
! 1913: my @statinfo = &Apache::lonnet::stat_file($newurl);
! 1914: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
! 1915: (my $result,$url) =
! 1916: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
! 1917: '','',$newfile);
! 1918: if ($result ne 'ok') {
! 1919: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
! 1920: }
! 1921: }
! 1922: return ($url,$error);
! 1923: }
1.43 raeburn 1924:
1.33 raeburn 1925: sub modifiable_userdata_row {
1926: my ($context,$role,$settings,$numinrow,$rowcount) = @_;
1927: my $rolename;
1928: if ($role eq 'cr') {
1929: $rolename = &mt('Custom role');
1930: } else {
1931: $rolename = &Apache::lonnet::plaintext($role);
1932: }
1933: my @fields = ('lastname','firstname','middlename','generation',
1934: 'permanentemail','id');
1935: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1936: my $output;
1937: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
1938: $output = '<tr '.$css_class.'>'.
1939: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
1940: '<td class="LC_left_item" colspan="2"><table>';
1941: my $rem;
1942: my %checks;
1943: if (ref($settings) eq 'HASH') {
1944: if (ref($settings->{$context}) eq 'HASH') {
1945: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1946: foreach my $field (@fields) {
1947: if ($settings->{$context}->{$role}->{$field}) {
1948: $checks{$field} = ' checked="checked" ';
1949: }
1950: }
1951: }
1952: }
1953: }
1954: for (my $i=0; $i<@fields; $i++) {
1955: my $rem = $i%($numinrow);
1956: if ($rem == 0) {
1957: if ($i > 0) {
1958: $output .= '</tr>';
1959: }
1960: $output .= '<tr>';
1961: }
1962: my $check = ' ';
1963: if (exists($checks{$fields[$i]})) {
1964: $check = $checks{$fields[$i]}
1965: } else {
1966: if ($role eq 'st') {
1967: if (ref($settings) ne 'HASH') {
1968: $check = ' checked="checked" ';
1969: }
1970: }
1971: }
1972: $output .= '<td class="LC_left_item">'.
1973: '<span class="LC_nobreak"><label>'.
1974: '<input type="checkbox" name="canmodify_'.$role.'" '.
1975: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
1976: '</label></span></td>';
1977: $rem = @fields%($numinrow);
1978: }
1979: my $colsleft = $numinrow - $rem;
1980: if ($colsleft > 1 ) {
1981: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
1982: ' </td>';
1983: } elsif ($colsleft == 1) {
1984: $output .= '<td class="LC_left_item"> </td>';
1985: }
1986: $output .= '</tr></table></td></tr>';
1987: return $output;
1988: }
1.28 raeburn 1989:
1.25 raeburn 1990: sub users_cansearch_row {
1991: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
1992: my $output = '<tr class="LC_odd_row">'.
1.24 raeburn 1993: '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
1994: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 1995: my $rem;
1996: if (ref($types) eq 'ARRAY') {
1997: for (my $i=0; $i<@{$types}; $i++) {
1998: if (defined($usertypes->{$types->[$i]})) {
1999: my $rem = $i%($numinrow);
2000: if ($rem == 0) {
2001: if ($i > 0) {
2002: $output .= '</tr>';
2003: }
2004: $output .= '<tr>';
1.23 raeburn 2005: }
1.26 raeburn 2006: my $check = ' ';
2007: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
2008: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
2009: $check = ' checked="checked" ';
2010: }
1.23 raeburn 2011: }
1.26 raeburn 2012: $output .= '<td class="LC_left_item">'.
2013: '<span class="LC_nobreak"><label>'.
2014: '<input type="checkbox" name="cansearch" '.
2015: 'value="'.$types->[$i].'"'.$check.'/>'.
2016: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2017: }
2018: }
1.26 raeburn 2019:
2020: $rem = @{$types}%($numinrow);
1.23 raeburn 2021: }
2022: my $colsleft = $numinrow - $rem;
2023: if ($colsleft > 1) {
1.25 raeburn 2024: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2025: } else {
1.25 raeburn 2026: $output .= '<td class="LC_left_item">';
1.23 raeburn 2027: }
2028: my $defcheck = ' ';
2029: if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26 raeburn 2030: if (grep(/^default$/,@{$settings->{'cansearch'}})) {
2031: $defcheck = ' checked="checked" ';
2032: }
1.23 raeburn 2033: }
1.25 raeburn 2034: $output .= '<span class="LC_nobreak"><label>'.
2035: '<input type="checkbox" name="cansearch" '.
2036: 'value="default"'.$defcheck.'/>'.
2037: $othertitle.'</label></span></td>'.
2038: '</tr></table></td></tr>';
2039: return $output;
1.23 raeburn 2040: }
2041:
2042: sub sorted_searchtitles {
2043: my %searchtitles = &Apache::lonlocal::texthash(
2044: 'uname' => 'username',
2045: 'lastname' => 'last name',
2046: 'lastfirst' => 'last name, first name',
2047: );
2048: my @titleorder = ('uname','lastname','lastfirst');
2049: return (\%searchtitles,\@titleorder);
2050: }
2051:
1.25 raeburn 2052: sub sorted_searchtypes {
2053: my %srchtypes_desc = (
2054: exact => 'is exact match',
2055: contains => 'contains ..',
2056: begins => 'begins with ..',
2057: );
2058: my @srchtypeorder = ('exact','begins','contains');
2059: return (\%srchtypes_desc,\@srchtypeorder);
2060: }
2061:
1.3 raeburn 2062: sub usertype_update_row {
2063: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
2064: my $datatable;
2065: my $numinrow = 4;
2066: foreach my $type (@{$types}) {
2067: if (defined($usertypes->{$type})) {
2068: $$rownums ++;
2069: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
2070: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
2071: '</td><td class="LC_left_item"><table>';
2072: for (my $i=0; $i<@{$fields}; $i++) {
2073: my $rem = $i%($numinrow);
2074: if ($rem == 0) {
2075: if ($i > 0) {
2076: $datatable .= '</tr>';
2077: }
2078: $datatable .= '<tr>';
2079: }
2080: my $check = ' ';
1.39 raeburn 2081: if (ref($settings) eq 'HASH') {
2082: if (ref($settings->{'fields'}) eq 'HASH') {
2083: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
2084: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
2085: $check = ' checked="checked" ';
2086: }
1.3 raeburn 2087: }
2088: }
2089: }
2090:
2091: if ($i == @{$fields}-1) {
2092: my $colsleft = $numinrow - $rem;
2093: if ($colsleft > 1) {
2094: $datatable .= '<td colspan="'.$colsleft.'">';
2095: } else {
2096: $datatable .= '<td>';
2097: }
2098: } else {
2099: $datatable .= '<td>';
2100: }
1.8 raeburn 2101: $datatable .= '<span class="LC_nobreak"><label>'.
2102: '<input type="checkbox" name="updateable_'.$type.
2103: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
2104: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 2105: }
2106: $datatable .= '</tr></table></td></tr>';
2107: }
2108: }
2109: return $datatable;
1.1 raeburn 2110: }
2111:
2112: sub modify_login {
1.9 raeburn 2113: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 2114: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 2115: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 2116: adminmail => 'Display administrator E-mail address',
1.43 raeburn 2117: newuser => 'Link for visitors to create a user account',
1.41 raeburn 2118: loginheader => 'Log-in box header');
1.3 raeburn 2119: my @offon = ('off','on');
1.6 raeburn 2120: my %loginhash;
1.9 raeburn 2121: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
2122: \%domconfig,\%loginhash);
1.43 raeburn 2123: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2124: foreach my $item (@toggles) {
2125: $loginhash{login}{$item} = $env{'form.'.$item};
2126: }
1.41 raeburn 2127: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 2128: if (ref($colchanges{'login'}) eq 'HASH') {
2129: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
2130: \%loginhash);
2131: }
1.1 raeburn 2132: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
2133: $dom);
2134: if ($putresult eq 'ok') {
1.43 raeburn 2135: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 2136: my %defaultchecked = (
2137: 'coursecatalog' => 'on',
2138: 'adminmail' => 'off',
1.43 raeburn 2139: 'newuser' => 'off',
1.42 raeburn 2140: );
2141: foreach my $item (@toggles) {
2142: if ($defaultchecked{$item} eq 'on') {
2143: if (($domconfig{'login'}{$item} eq '0') &&
2144: ($env{'form.'.$item} eq '1')) {
2145: $changes{$item} = 1;
2146: } elsif (($domconfig{'login'}{$item} eq '' ||
2147: $domconfig{'login'}{$item} eq '1') &&
2148: ($env{'form.'.$item} eq '0')) {
2149: $changes{$item} = 1;
2150: }
2151: } elsif ($defaultchecked{$item} eq 'off') {
2152: if (($domconfig{'login'}{$item} eq '1') &&
2153: ($env{'form.'.$item} eq '0')) {
2154: $changes{$item} = 1;
2155: } elsif (($domconfig{'login'}{$item} eq '' ||
2156: $domconfig{'login'}{$item} eq '0') &&
2157: ($env{'form.'.$item} eq '1')) {
2158: $changes{$item} = 1;
2159: }
2160: }
1.1 raeburn 2161: }
1.41 raeburn 2162: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
2163: ($env{'form.loginheader'} eq 'image')) {
2164: $changes{'loginheader'} = 1;
2165: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
2166: $domconfig{'login'}{'loginheader'} eq 'image') &&
2167: ($env{'form.loginheader'} eq 'text')) {
2168: $changes{'loginheader'} = 1;
2169: }
1.6 raeburn 2170: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 2171: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 2172: $resulttext = &mt('Changes made:').'<ul>';
2173: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 2174: if ($item eq 'loginheader') {
2175: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
2176: } else {
2177: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
2178: }
1.1 raeburn 2179: }
1.6 raeburn 2180: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 2181: } else {
2182: $resulttext = &mt('No changes made to log-in page settings');
2183: }
2184: } else {
1.11 albertel 2185: $resulttext = '<span class="LC_error">'.
2186: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2187: }
1.6 raeburn 2188: if ($errors) {
1.9 raeburn 2189: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 2190: $errors.'</ul>';
2191: }
2192: return $resulttext;
2193: }
2194:
2195: sub color_font_choices {
2196: my %choices =
2197: &Apache::lonlocal::texthash (
2198: img => "Header",
2199: bgs => "Background colors",
2200: links => "Link colors",
2201: font => "Font color",
2202: pgbg => "Page",
2203: tabbg => "Header",
2204: sidebg => "Border",
2205: link => "Link",
2206: alink => "Active link",
2207: vlink => "Visited link",
2208: );
2209: return %choices;
2210: }
2211:
2212: sub modify_rolecolors {
1.9 raeburn 2213: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 2214: my ($resulttext,%rolehash);
2215: $rolehash{'rolecolors'} = {};
1.9 raeburn 2216: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 2217: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
2218: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
2219: $dom);
2220: if ($putresult eq 'ok') {
2221: if (keys(%changes) > 0) {
1.41 raeburn 2222: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 2223: $resulttext = &display_colorchgs($dom,\%changes,$roles,
2224: $rolehash{'rolecolors'});
2225: } else {
2226: $resulttext = &mt('No changes made to default color schemes');
2227: }
2228: } else {
1.11 albertel 2229: $resulttext = '<span class="LC_error">'.
2230: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 2231: }
2232: if ($errors) {
2233: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
2234: $errors.'</ul>';
2235: }
2236: return $resulttext;
2237: }
2238:
2239: sub modify_colors {
1.9 raeburn 2240: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 2241: my (%changes,%choices);
1.6 raeburn 2242: my @bgs = ('pgbg','mainbg','sidebg');
2243: my @links = ('link','alink','vlink');
1.41 raeburn 2244: my @logintext;
1.6 raeburn 2245: my @images;
2246: my $servadm = $r->dir_config('lonAdmEMail');
2247: my $errors;
2248: foreach my $role (@{$roles}) {
2249: if ($role eq 'login') {
1.12 raeburn 2250: %choices = &login_choices();
1.41 raeburn 2251: @logintext = ('textcol','bgcol');
1.12 raeburn 2252: } else {
2253: %choices = &color_font_choices();
2254: }
2255: if ($role eq 'login') {
1.41 raeburn 2256: @images = ('img','logo','domlogo','login');
1.6 raeburn 2257: } else {
2258: @images = ('img');
2259: }
2260: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 2261: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 2262: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
2263: }
1.46 ! raeburn 2264: my ($configuserok,$author_ok,$switchserver) =
! 2265: &config_check($dom,$confname,$servadm);
1.9 raeburn 2266: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 2267: if (ref($domconfig->{$role}) ne 'HASH') {
2268: $domconfig->{$role} = {};
2269: }
1.8 raeburn 2270: foreach my $img (@images) {
1.18 albertel 2271: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
2272: && !defined($domconfig->{$role}{$img})
2273: && !$env{'form.'.$role.'_del_'.$img}
2274: && $env{'form.'.$role.'_import_'.$img}) {
2275: # import the old configured image from the .tab setting
2276: # if they haven't provided a new one
2277: $domconfig->{$role}{$img} =
2278: $env{'form.'.$role.'_import_'.$img};
2279: }
1.6 raeburn 2280: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 2281: my $error;
1.6 raeburn 2282: if ($configuserok eq 'ok') {
1.9 raeburn 2283: if ($switchserver) {
1.12 raeburn 2284: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 2285: } else {
2286: if ($author_ok eq 'ok') {
2287: my ($result,$logourl) =
2288: &publishlogo($r,'upload',$role.'_'.$img,
2289: $dom,$confname,$img,$width,$height);
2290: if ($result eq 'ok') {
2291: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 2292: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2293: } else {
1.12 raeburn 2294: $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 2295: }
2296: } else {
1.46 ! raeburn 2297: $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 2298: }
2299: }
2300: } else {
1.46 ! raeburn 2301: $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 2302: }
2303: if ($error) {
1.8 raeburn 2304: &Apache::lonnet::logthis($error);
1.11 albertel 2305: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 2306: }
2307: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 2308: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
2309: my $error;
2310: if ($configuserok eq 'ok') {
2311: # is confname an author?
2312: if ($switchserver eq '') {
2313: if ($author_ok eq 'ok') {
2314: my ($result,$logourl) =
2315: &publishlogo($r,'copy',$domconfig->{$role}{$img},
2316: $dom,$confname,$img,$width,$height);
2317: if ($result eq 'ok') {
2318: $confhash->{$role}{$img} = $logourl;
1.18 albertel 2319: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 2320: }
2321: }
2322: }
2323: }
1.6 raeburn 2324: }
2325: }
2326: }
2327: if (ref($domconfig) eq 'HASH') {
2328: if (ref($domconfig->{$role}) eq 'HASH') {
2329: foreach my $img (@images) {
2330: if ($domconfig->{$role}{$img} ne '') {
2331: if ($env{'form.'.$role.'_del_'.$img}) {
2332: $confhash->{$role}{$img} = '';
1.12 raeburn 2333: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2334: } else {
1.9 raeburn 2335: if ($confhash->{$role}{$img} eq '') {
2336: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
2337: }
1.6 raeburn 2338: }
2339: } else {
2340: if ($env{'form.'.$role.'_del_'.$img}) {
2341: $confhash->{$role}{$img} = '';
1.12 raeburn 2342: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 2343: }
2344: }
2345: }
2346: if ($domconfig->{$role}{'font'} ne '') {
2347: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
2348: $changes{$role}{'font'} = 1;
2349: }
2350: } else {
2351: if ($confhash->{$role}{'font'}) {
2352: $changes{$role}{'font'} = 1;
2353: }
2354: }
2355: foreach my $item (@bgs) {
2356: if ($domconfig->{$role}{$item} ne '') {
2357: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2358: $changes{$role}{'bgs'}{$item} = 1;
2359: }
2360: } else {
2361: if ($confhash->{$role}{$item}) {
2362: $changes{$role}{'bgs'}{$item} = 1;
2363: }
2364: }
2365: }
2366: foreach my $item (@links) {
2367: if ($domconfig->{$role}{$item} ne '') {
2368: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2369: $changes{$role}{'links'}{$item} = 1;
2370: }
2371: } else {
2372: if ($confhash->{$role}{$item}) {
2373: $changes{$role}{'links'}{$item} = 1;
2374: }
2375: }
2376: }
1.41 raeburn 2377: foreach my $item (@logintext) {
2378: if ($domconfig->{$role}{$item} ne '') {
2379: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
2380: $changes{$role}{'logintext'}{$item} = 1;
2381: }
2382: } else {
2383: if ($confhash->{$role}{$item}) {
2384: $changes{$role}{'logintext'}{$item} = 1;
2385: }
2386: }
2387: }
1.6 raeburn 2388: } else {
2389: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2390: \@logintext,$confhash,\%changes);
1.6 raeburn 2391: }
2392: } else {
2393: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 2394: \@logintext,$confhash,\%changes);
1.6 raeburn 2395: }
2396: }
2397: return ($errors,%changes);
2398: }
2399:
1.46 ! raeburn 2400: sub config_check {
! 2401: my ($dom,$confname,$servadm) = @_;
! 2402: my ($configuserok,$author_ok,$switchserver,%currroles);
! 2403: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
! 2404: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
! 2405: $confname,$servadm);
! 2406: if ($configuserok eq 'ok') {
! 2407: $switchserver = &check_switchserver($dom,$confname);
! 2408: if ($switchserver eq '') {
! 2409: $author_ok = &check_authorstatus($dom,$confname,%currroles);
! 2410: }
! 2411: }
! 2412: return ($configuserok,$author_ok,$switchserver);
! 2413: }
! 2414:
1.6 raeburn 2415: sub default_change_checker {
1.41 raeburn 2416: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 2417: foreach my $item (@{$links}) {
2418: if ($confhash->{$role}{$item}) {
2419: $changes->{$role}{'links'}{$item} = 1;
2420: }
2421: }
2422: foreach my $item (@{$bgs}) {
2423: if ($confhash->{$role}{$item}) {
2424: $changes->{$role}{'bgs'}{$item} = 1;
2425: }
2426: }
1.41 raeburn 2427: foreach my $item (@{$logintext}) {
2428: if ($confhash->{$role}{$item}) {
2429: $changes->{$role}{'logintext'}{$item} = 1;
2430: }
2431: }
1.6 raeburn 2432: foreach my $img (@{$images}) {
2433: if ($env{'form.'.$role.'_del_'.$img}) {
2434: $confhash->{$role}{$img} = '';
1.12 raeburn 2435: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 2436: }
2437: }
2438: if ($confhash->{$role}{'font'}) {
2439: $changes->{$role}{'font'} = 1;
2440: }
2441: }
2442:
2443: sub display_colorchgs {
2444: my ($dom,$changes,$roles,$confhash) = @_;
2445: my (%choices,$resulttext);
2446: if (!grep(/^login$/,@{$roles})) {
2447: $resulttext = &mt('Changes made:').'<br />';
2448: }
2449: foreach my $role (@{$roles}) {
2450: if ($role eq 'login') {
2451: %choices = &login_choices();
2452: } else {
2453: %choices = &color_font_choices();
2454: }
2455: if (ref($changes->{$role}) eq 'HASH') {
2456: if ($role ne 'login') {
2457: $resulttext .= '<h4>'.&mt($role).'</h4>';
2458: }
2459: foreach my $key (sort(keys(%{$changes->{$role}}))) {
2460: if ($role ne 'login') {
2461: $resulttext .= '<ul>';
2462: }
2463: if (ref($changes->{$role}{$key}) eq 'HASH') {
2464: if ($role ne 'login') {
2465: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
2466: }
2467: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
2468: if ($confhash->{$role}{$item} eq '') {
2469: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
2470: } else {
1.12 raeburn 2471: my $newitem = $confhash->{$role}{$item};
2472: if ($key eq 'images') {
2473: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
2474: }
2475: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 2476: }
2477: }
2478: if ($role ne 'login') {
2479: $resulttext .= '</ul></li>';
2480: }
2481: } else {
2482: if ($confhash->{$role}{$key} eq '') {
2483: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
2484: } else {
2485: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
2486: }
2487: }
2488: if ($role ne 'login') {
2489: $resulttext .= '</ul>';
2490: }
2491: }
2492: }
2493: }
1.3 raeburn 2494: return $resulttext;
1.1 raeburn 2495: }
2496:
1.9 raeburn 2497: sub thumb_dimensions {
2498: return ('200','50');
2499: }
2500:
1.16 raeburn 2501: sub check_dimensions {
2502: my ($inputfile) = @_;
2503: my ($fullwidth,$fullheight);
2504: if ($inputfile =~ m|^[/\w.\-]+$|) {
2505: if (open(PIPE,"identify $inputfile 2>&1 |")) {
2506: my $imageinfo = <PIPE>;
2507: if (!close(PIPE)) {
2508: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
2509: }
2510: chomp($imageinfo);
2511: my ($fullsize) =
1.21 raeburn 2512: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 2513: if ($fullsize) {
2514: ($fullwidth,$fullheight) = split(/x/,$fullsize);
2515: }
2516: }
2517: }
2518: return ($fullwidth,$fullheight);
2519: }
2520:
1.9 raeburn 2521: sub check_configuser {
2522: my ($uhome,$dom,$confname,$servadm) = @_;
2523: my ($configuserok,%currroles);
2524: if ($uhome eq 'no_host') {
2525: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
2526: my $configpass = &LONCAPA::Enrollment::create_password();
2527: $configuserok =
2528: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
2529: $configpass,'','','','','',undef,$servadm);
2530: } else {
2531: $configuserok = 'ok';
2532: %currroles =
2533: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
2534: }
2535: return ($configuserok,%currroles);
2536: }
2537:
2538: sub check_authorstatus {
2539: my ($dom,$confname,%currroles) = @_;
2540: my $author_ok;
1.40 raeburn 2541: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 2542: my $start = time;
2543: my $end = 0;
2544: $author_ok =
2545: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
2546: 'au',$end,$start);
2547: } else {
2548: $author_ok = 'ok';
2549: }
2550: return $author_ok;
2551: }
2552:
2553: sub publishlogo {
1.46 ! raeburn 2554: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 2555: my ($output,$fname,$logourl);
2556: if ($action eq 'upload') {
2557: $fname=$env{'form.'.$formname.'.filename'};
2558: chop($env{'form.'.$formname});
2559: } else {
2560: ($fname) = ($formname =~ /([^\/]+)$/);
2561: }
1.46 ! raeburn 2562: if ($savefileas ne '') {
! 2563: $fname = $savefileas;
! 2564: }
1.9 raeburn 2565: $fname=&Apache::lonnet::clean_filename($fname);
2566: # See if there is anything left
2567: unless ($fname) { return ('error: no uploaded file'); }
2568: $fname="$subdir/$fname";
2569: my $filepath='/home/'.$confname.'/public_html';
2570: my ($fnamepath,$file,$fetchthumb);
2571: $file=$fname;
2572: if ($fname=~m|/|) {
2573: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
2574: }
2575: my @parts=split(/\//,$filepath.'/'.$fnamepath);
2576: my $count;
2577: for ($count=4;$count<=$#parts;$count++) {
2578: $filepath.="/$parts[$count]";
2579: if ((-e $filepath)!=1) {
2580: mkdir($filepath,02770);
2581: }
2582: }
2583: # Check for bad extension and disallow upload
2584: if ($file=~/\.(\w+)$/ &&
2585: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
2586: $output =
2587: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
2588: } elsif ($file=~/\.(\w+)$/ &&
2589: !defined(&Apache::loncommon::fileembstyle($1))) {
2590: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
2591: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 ! raeburn 2592: $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 2593: } elsif (-d "$filepath/$file") {
2594: $output = &mt('File name is a directory name - rename the file and re-upload');
2595: } else {
2596: my $source = $filepath.'/'.$file;
2597: my $logfile;
2598: if (!open($logfile,">>$source".'.log')) {
2599: return (&mt('No write permission to Construction Space'));
2600: }
2601: print $logfile
2602: "\n================= Publish ".localtime()." ================\n".
2603: $env{'user.name'}.':'.$env{'user.domain'}."\n";
2604: # Save the file
2605: if (!open(FH,'>'.$source)) {
2606: &Apache::lonnet::logthis('Failed to create '.$source);
2607: return (&mt('Failed to create file'));
2608: }
2609: if ($action eq 'upload') {
2610: if (!print FH ($env{'form.'.$formname})) {
2611: &Apache::lonnet::logthis('Failed to write to '.$source);
2612: return (&mt('Failed to write file'));
2613: }
2614: } else {
2615: my $original = &Apache::lonnet::filelocation('',$formname);
2616: if(!copy($original,$source)) {
2617: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
2618: return (&mt('Failed to write file'));
2619: }
2620: }
2621: close(FH);
2622: chmod(0660, $source); # Permissions to rw-rw---.
2623:
2624: my $docroot=$r->dir_config('lonDocRoot');
2625: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
2626: my $copyfile=$targetdir.'/'.$file;
2627:
2628: my @parts=split(/\//,$targetdir);
2629: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
2630: for (my $count=5;$count<=$#parts;$count++) {
2631: $path.="/$parts[$count]";
2632: if (!-e $path) {
2633: print $logfile "\nCreating directory ".$path;
2634: mkdir($path,02770);
2635: }
2636: }
2637: my $versionresult;
2638: if (-e $copyfile) {
2639: $versionresult = &logo_versioning($targetdir,$file,$logfile);
2640: } else {
2641: $versionresult = 'ok';
2642: }
2643: if ($versionresult eq 'ok') {
2644: if (copy($source,$copyfile)) {
2645: print $logfile "\nCopied original source to ".$copyfile."\n";
2646: $output = 'ok';
2647: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
2648: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
2649: } else {
2650: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
2651: $output = &mt('Failed to copy file to RES space').", $!";
2652: }
2653: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
2654: my $inputfile = $filepath.'/'.$file;
2655: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 2656: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
2657: if ($fullwidth ne '' && $fullheight ne '') {
2658: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
2659: my $thumbsize = $thumbwidth.'x'.$thumbheight;
2660: system("convert -sample $thumbsize $inputfile $outfile");
2661: chmod(0660, $filepath.'/tn-'.$file);
2662: if (-e $outfile) {
2663: my $copyfile=$targetdir.'/tn-'.$file;
2664: if (copy($outfile,$copyfile)) {
2665: print $logfile "\nCopied source to ".$copyfile."\n";
2666: &write_metadata($dom,$confname,$formname,
2667: $targetdir,'tn-'.$file,$logfile);
2668: } else {
2669: print $logfile "\nUnable to write ".$copyfile.
2670: ':'.$!."\n";
2671: }
2672: }
1.9 raeburn 2673: }
2674: }
2675: }
2676: } else {
2677: $output = $versionresult;
2678: }
2679: }
2680: return ($output,$logourl);
2681: }
2682:
2683: sub logo_versioning {
2684: my ($targetdir,$file,$logfile) = @_;
2685: my $target = $targetdir.'/'.$file;
2686: my ($maxversion,$fn,$extn,$output);
2687: $maxversion = 0;
2688: if ($file =~ /^(.+)\.(\w+)$/) {
2689: $fn=$1;
2690: $extn=$2;
2691: }
2692: opendir(DIR,$targetdir);
2693: while (my $filename=readdir(DIR)) {
2694: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
2695: $maxversion=($1>$maxversion)?$1:$maxversion;
2696: }
2697: }
2698: $maxversion++;
2699: print $logfile "\nCreating old version ".$maxversion."\n";
2700: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
2701: if (copy($target,$copyfile)) {
2702: print $logfile "Copied old target to ".$copyfile."\n";
2703: $copyfile=$copyfile.'.meta';
2704: if (copy($target.'.meta',$copyfile)) {
2705: print $logfile "Copied old target metadata to ".$copyfile."\n";
2706: $output = 'ok';
2707: } else {
2708: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
2709: $output = &mt('Failed to copy old meta').", $!, ";
2710: }
2711: } else {
2712: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
2713: $output = &mt('Failed to copy old target').", $!, ";
2714: }
2715: return $output;
2716: }
2717:
2718: sub write_metadata {
2719: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
2720: my (%metadatafields,%metadatakeys,$output);
2721: $metadatafields{'title'}=$formname;
2722: $metadatafields{'creationdate'}=time;
2723: $metadatafields{'lastrevisiondate'}=time;
2724: $metadatafields{'copyright'}='public';
2725: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
2726: $env{'user.domain'};
2727: $metadatafields{'authorspace'}=$confname.':'.$dom;
2728: $metadatafields{'domain'}=$dom;
2729: {
2730: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
2731: my $mfh;
2732: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
2733: $output = &mt('Could not write metadata');
2734: }
2735: foreach (sort keys %metadatafields) {
2736: unless ($_=~/\./) {
2737: my $unikey=$_;
2738: $unikey=~/^([A-Za-z]+)/;
2739: my $tag=$1;
2740: $tag=~tr/A-Z/a-z/;
2741: print $mfh "\n\<$tag";
2742: foreach (split(/\,/,$metadatakeys{$unikey})) {
2743: my $value=$metadatafields{$unikey.'.'.$_};
2744: $value=~s/\"/\'\'/g;
2745: print $mfh ' '.$_.'="'.$value.'"';
2746: }
2747: print $mfh '>'.
2748: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
2749: .'</'.$tag.'>';
2750: }
2751: }
2752: $output = 'ok';
2753: print $logfile "\nWrote metadata";
2754: close($mfh);
2755: }
2756: }
2757:
2758: sub check_switchserver {
2759: my ($dom,$confname) = @_;
2760: my ($allowed,$switchserver);
2761: my $home = &Apache::lonnet::homeserver($confname,$dom);
2762: if ($home eq 'no_host') {
2763: $home = &Apache::lonnet::domain($dom,'primary');
2764: }
2765: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 2766: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2767: if (!$allowed) {
2768: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 2769: }
2770: return $switchserver;
2771: }
2772:
1.30 raeburn 2773: sub javascript_set_colnums {
2774: return <<END;
2775: function setDisplayColumns() {
2776: if (document.pickactions.width.value > 1100) {
2777: document.pickactions.numcols[1].checked = true;
2778: } else {
2779: document.pickactions.numcols[0].checked = true;
2780: }
2781: }
2782: END
2783: }
2784:
1.1 raeburn 2785: sub modify_quotas {
1.3 raeburn 2786: my ($dom,%domconfig) = @_;
1.1 raeburn 2787: my ($resulttext,%changes);
1.44 raeburn 2788: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 2789: my %formhash;
2790: foreach my $key (keys(%env)) {
2791: if ($key =~ /^form\.quota_(.+)$/) {
2792: $formhash{$1} = $env{$key};
2793: }
2794: }
1.15 raeburn 2795: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 2796: if (ref($domconfig{'quotas'}) eq 'HASH') {
2797: foreach my $key (keys(%{$domconfig{'quotas'}})) {
2798: if (exists($formhash{$key})) {
2799: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
2800: $changes{$key} = 1;
2801: }
2802: } else {
2803: $formhash{$key} = $domconfig{'quotas'}{$key};
2804: }
2805: }
2806: }
2807: foreach my $key (keys(%formhash)) {
2808: if ($formhash{$key} ne '') {
1.3 raeburn 2809: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 2810: $changes{$key} = 1;
2811: }
2812: }
2813: }
2814: my %quotahash = (
1.3 raeburn 2815: quotas => {%formhash},
1.1 raeburn 2816: );
2817: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
2818: $dom);
2819: if ($putresult eq 'ok') {
2820: if (keys(%changes) > 0) {
2821: $resulttext = &mt('Changes made:').'<ul>';
1.26 raeburn 2822: foreach my $type (@{$types},'default') {
2823: if (defined($changes{$type})) {
2824: my $typetitle = $usertypes->{$type};
2825: if ($type eq 'default') {
2826: $typetitle = $othertitle;
2827: }
2828: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
2829: }
1.1 raeburn 2830: }
2831: $resulttext .= '</ul>';
2832: } else {
2833: $resulttext = &mt('No changes made to default quotas');
2834: }
2835: } else {
1.11 albertel 2836: $resulttext = '<span class="LC_error">'.
2837: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2838: }
1.3 raeburn 2839: return $resulttext;
1.1 raeburn 2840: }
2841:
1.3 raeburn 2842: sub modify_autoenroll {
2843: my ($dom,%domconfig) = @_;
1.1 raeburn 2844: my ($resulttext,%changes);
2845: my %currautoenroll;
2846: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
2847: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
2848: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
2849: }
2850: }
2851: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
2852: my %title = ( run => 'Auto-enrollment active',
2853: sender => 'Sender for notification messages');
2854: my @offon = ('off','on');
1.17 raeburn 2855: my $sender_uname = $env{'form.sender_uname'};
2856: my $sender_domain = $env{'form.sender_domain'};
2857: if ($sender_domain eq '') {
2858: $sender_uname = '';
2859: } elsif ($sender_uname eq '') {
2860: $sender_domain = '';
2861: }
1.1 raeburn 2862: my %autoenrollhash = (
2863: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 2864: sender_uname => $sender_uname,
2865: sender_domain => $sender_domain,
1.1 raeburn 2866:
2867: }
2868: );
1.4 raeburn 2869: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
2870: $dom);
1.1 raeburn 2871: if ($putresult eq 'ok') {
2872: if (exists($currautoenroll{'run'})) {
2873: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
2874: $changes{'run'} = 1;
2875: }
2876: } elsif ($autorun) {
2877: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 2878: $changes{'run'} = 1;
1.1 raeburn 2879: }
2880: }
1.17 raeburn 2881: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 2882: $changes{'sender'} = 1;
2883: }
1.17 raeburn 2884: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 2885: $changes{'sender'} = 1;
2886: }
2887: if (keys(%changes) > 0) {
2888: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 2889: if ($changes{'run'}) {
1.1 raeburn 2890: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
2891: }
2892: if ($changes{'sender'}) {
1.17 raeburn 2893: if ($sender_uname eq '' || $sender_domain eq '') {
2894: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
2895: } else {
2896: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
2897: }
1.1 raeburn 2898: }
2899: $resulttext .= '</ul>';
2900: } else {
2901: $resulttext = &mt('No changes made to auto-enrollment settings');
2902: }
2903: } else {
1.11 albertel 2904: $resulttext = '<span class="LC_error">'.
2905: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 2906: }
1.3 raeburn 2907: return $resulttext;
1.1 raeburn 2908: }
2909:
2910: sub modify_autoupdate {
1.3 raeburn 2911: my ($dom,%domconfig) = @_;
1.1 raeburn 2912: my ($resulttext,%currautoupdate,%fields,%changes);
2913: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
2914: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
2915: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
2916: }
2917: }
2918: my @offon = ('off','on');
2919: my %title = &Apache::lonlocal::texthash (
2920: run => 'Auto-update:',
2921: classlists => 'Updates to user information in classlists?'
2922: );
1.44 raeburn 2923: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 2924: my %fieldtitles = &Apache::lonlocal::texthash (
2925: id => 'Student/Employee ID',
1.20 raeburn 2926: permanentemail => 'E-mail address',
1.1 raeburn 2927: lastname => 'Last Name',
2928: firstname => 'First Name',
2929: middlename => 'Middle Name',
2930: gen => 'Generation',
2931: );
2932: my $othertitle = &mt('All users');
2933: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 2934: $othertitle = &mt('Other users');
1.1 raeburn 2935: }
2936: foreach my $key (keys(%env)) {
2937: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
2938: push(@{$fields{$1}},$2);
2939: }
2940: }
2941: my %updatehash = (
2942: autoupdate => { run => $env{'form.autoupdate_run'},
2943: classlists => $env{'form.classlists'},
2944: fields => {%fields},
2945: }
2946: );
2947: foreach my $key (keys(%currautoupdate)) {
2948: if (($key eq 'run') || ($key eq 'classlists')) {
2949: if (exists($updatehash{autoupdate}{$key})) {
2950: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
2951: $changes{$key} = 1;
2952: }
2953: }
2954: } elsif ($key eq 'fields') {
2955: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 2956: foreach my $item (@{$types},'default') {
1.1 raeburn 2957: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
2958: my $change = 0;
2959: foreach my $type (@{$currautoupdate{$key}{$item}}) {
2960: if (!exists($fields{$item})) {
2961: $change = 1;
2962: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 2963: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 2964: $change = 1;
2965: }
2966: }
2967: }
2968: if ($change) {
2969: push(@{$changes{$key}},$item);
2970: }
1.26 raeburn 2971: }
1.1 raeburn 2972: }
2973: }
2974: }
2975: }
1.26 raeburn 2976: foreach my $item (@{$types},'default') {
2977: if (defined($fields{$item})) {
2978: if (ref($currautoupdate{'fields'}) eq 'HASH') {
2979: if (!exists($currautoupdate{'fields'}{$item})) {
2980: push(@{$changes{'fields'}},$item);
2981: }
2982: } else {
2983: push(@{$changes{'fields'}},$item);
1.1 raeburn 2984: }
2985: }
2986: }
2987: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
2988: $dom);
2989: if ($putresult eq 'ok') {
2990: if (keys(%changes) > 0) {
2991: $resulttext = &mt('Changes made:').'<ul>';
2992: foreach my $key (sort(keys(%changes))) {
2993: if (ref($changes{$key}) eq 'ARRAY') {
2994: foreach my $item (@{$changes{$key}}) {
2995: my @newvalues;
2996: foreach my $type (@{$fields{$item}}) {
2997: push(@newvalues,$fieldtitles{$type});
2998: }
1.3 raeburn 2999: my $newvaluestr;
3000: if (@newvalues > 0) {
3001: $newvaluestr = join(', ',@newvalues);
3002: } else {
3003: $newvaluestr = &mt('none');
1.6 raeburn 3004: }
1.1 raeburn 3005: if ($item eq 'default') {
1.26 raeburn 3006: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 3007: } else {
1.26 raeburn 3008: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 3009: }
3010: }
3011: } else {
3012: my $newvalue;
3013: if ($key eq 'run') {
3014: $newvalue = $offon[$env{'form.autoupdate_run'}];
3015: } else {
3016: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 3017: }
1.1 raeburn 3018: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
3019: }
3020: }
3021: $resulttext .= '</ul>';
3022: } else {
1.3 raeburn 3023: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 3024: }
3025: } else {
1.11 albertel 3026: $resulttext = '<span class="LC_error">'.
3027: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3028: }
1.3 raeburn 3029: return $resulttext;
1.1 raeburn 3030: }
3031:
1.23 raeburn 3032: sub modify_directorysrch {
3033: my ($dom,%domconfig) = @_;
3034: my ($resulttext,%changes);
3035: my %currdirsrch;
3036: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
3037: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
3038: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
3039: }
3040: }
3041: my %title = ( available => 'Directory search available',
1.24 raeburn 3042: localonly => 'Other domains can search',
1.23 raeburn 3043: searchby => 'Search types',
3044: searchtypes => 'Search latitude');
3045: my @offon = ('off','on');
1.24 raeburn 3046: my @otherdoms = ('Yes','No');
1.23 raeburn 3047:
1.25 raeburn 3048: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 3049: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
3050: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
3051:
1.44 raeburn 3052: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 3053: if (keys(%{$usertypes}) == 0) {
3054: @cansearch = ('default');
3055: } else {
3056: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
3057: foreach my $type (@{$currdirsrch{'cansearch'}}) {
3058: if (!grep(/^\Q$type\E$/,@cansearch)) {
3059: push(@{$changes{'cansearch'}},$type);
3060: }
1.23 raeburn 3061: }
1.26 raeburn 3062: foreach my $type (@cansearch) {
3063: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
3064: push(@{$changes{'cansearch'}},$type);
3065: }
1.23 raeburn 3066: }
1.26 raeburn 3067: } else {
3068: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 3069: }
3070: }
3071:
3072: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
3073: foreach my $by (@{$currdirsrch{'searchby'}}) {
3074: if (!grep(/^\Q$by\E$/,@searchby)) {
3075: push(@{$changes{'searchby'}},$by);
3076: }
3077: }
3078: foreach my $by (@searchby) {
3079: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
3080: push(@{$changes{'searchby'}},$by);
3081: }
3082: }
3083: } else {
3084: push(@{$changes{'searchby'}},@searchby);
3085: }
1.25 raeburn 3086:
3087: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
3088: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
3089: if (!grep(/^\Q$type\E$/,@searchtypes)) {
3090: push(@{$changes{'searchtypes'}},$type);
3091: }
3092: }
3093: foreach my $type (@searchtypes) {
3094: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
3095: push(@{$changes{'searchtypes'}},$type);
3096: }
3097: }
3098: } else {
3099: if (exists($currdirsrch{'searchtypes'})) {
3100: foreach my $type (@searchtypes) {
3101: if ($type ne $currdirsrch{'searchtypes'}) {
3102: push(@{$changes{'searchtypes'}},$type);
3103: }
3104: }
3105: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
3106: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
3107: }
3108: } else {
3109: push(@{$changes{'searchtypes'}},@searchtypes);
3110: }
3111: }
3112:
1.23 raeburn 3113: my %dirsrch_hash = (
3114: directorysrch => { available => $env{'form.dirsrch_available'},
3115: cansearch => \@cansearch,
1.24 raeburn 3116: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 3117: searchby => \@searchby,
1.25 raeburn 3118: searchtypes => \@searchtypes,
1.23 raeburn 3119: }
3120: );
3121: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
3122: $dom);
3123: if ($putresult eq 'ok') {
3124: if (exists($currdirsrch{'available'})) {
3125: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
3126: $changes{'available'} = 1;
3127: }
3128: } else {
3129: if ($env{'form.dirsrch_available'} eq '1') {
3130: $changes{'available'} = 1;
3131: }
3132: }
1.24 raeburn 3133: if (exists($currdirsrch{'localonly'})) {
3134: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
3135: $changes{'localonly'} = 1;
3136: }
3137: } else {
3138: if ($env{'form.dirsrch_localonly'} eq '1') {
3139: $changes{'localonly'} = 1;
3140: }
3141: }
1.23 raeburn 3142: if (keys(%changes) > 0) {
3143: $resulttext = &mt('Changes made:').'<ul>';
3144: if ($changes{'available'}) {
3145: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
3146: }
1.24 raeburn 3147: if ($changes{'localonly'}) {
3148: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
3149: }
3150:
1.23 raeburn 3151: if (ref($changes{'cansearch'}) eq 'ARRAY') {
3152: my $chgtext;
1.26 raeburn 3153: if (ref($usertypes) eq 'HASH') {
3154: if (keys(%{$usertypes}) > 0) {
3155: foreach my $type (@{$types}) {
3156: if (grep(/^\Q$type\E$/,@cansearch)) {
3157: $chgtext .= $usertypes->{$type}.'; ';
3158: }
3159: }
3160: if (grep(/^default$/,@cansearch)) {
3161: $chgtext .= $othertitle;
3162: } else {
3163: $chgtext =~ s/\; $//;
3164: }
3165: $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 3166: }
3167: }
3168: }
3169: if (ref($changes{'searchby'}) eq 'ARRAY') {
3170: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3171: my $chgtext;
3172: foreach my $type (@{$titleorder}) {
3173: if (grep(/^\Q$type\E$/,@searchby)) {
3174: if (defined($searchtitles->{$type})) {
3175: $chgtext .= $searchtitles->{$type}.'; ';
3176: }
3177: }
3178: }
3179: $chgtext =~ s/\; $//;
3180: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
3181: }
1.25 raeburn 3182: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
3183: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
3184: my $chgtext;
3185: foreach my $type (@{$srchtypeorder}) {
3186: if (grep(/^\Q$type\E$/,@searchtypes)) {
3187: if (defined($srchtypes_desc->{$type})) {
3188: $chgtext .= $srchtypes_desc->{$type}.'; ';
3189: }
3190: }
3191: }
3192: $chgtext =~ s/\; $//;
3193: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 3194: }
3195: $resulttext .= '</ul>';
3196: } else {
3197: $resulttext = &mt('No changes made to institution directory search settings');
3198: }
3199: } else {
3200: $resulttext = '<span class="LC_error">'.
1.27 raeburn 3201: &mt('An error occurred: [_1]',$putresult).'</span>';
3202: }
3203: return $resulttext;
3204: }
3205:
1.28 raeburn 3206: sub modify_contacts {
3207: my ($dom,%domconfig) = @_;
3208: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
3209: if (ref($domconfig{'contacts'}) eq 'HASH') {
3210: foreach my $key (keys(%{$domconfig{'contacts'}})) {
3211: $currsetting{$key} = $domconfig{'contacts'}{$key};
3212: }
3213: }
3214: my (%others,%to);
3215: my @contacts = ('supportemail','adminemail');
3216: my @mailings = ('errormail','packagesmail','helpdeskmail');
3217: foreach my $type (@mailings) {
3218: @{$newsetting{$type}} =
3219: &Apache::loncommon::get_env_multiple('form.'.$type);
3220: foreach my $item (@contacts) {
3221: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
3222: $contacts_hash{contacts}{$type}{$item} = 1;
3223: } else {
3224: $contacts_hash{contacts}{$type}{$item} = 0;
3225: }
3226: }
3227: $others{$type} = $env{'form.'.$type.'_others'};
3228: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
3229: }
3230: foreach my $item (@contacts) {
3231: $to{$item} = $env{'form.'.$item};
3232: $contacts_hash{'contacts'}{$item} = $to{$item};
3233: }
3234: if (keys(%currsetting) > 0) {
3235: foreach my $item (@contacts) {
3236: if ($to{$item} ne $currsetting{$item}) {
3237: $changes{$item} = 1;
3238: }
3239: }
3240: foreach my $type (@mailings) {
3241: foreach my $item (@contacts) {
3242: if (ref($currsetting{$type}) eq 'HASH') {
3243: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
3244: push(@{$changes{$type}},$item);
3245: }
3246: } else {
3247: push(@{$changes{$type}},@{$newsetting{$type}});
3248: }
3249: }
3250: if ($others{$type} ne $currsetting{$type}{'others'}) {
3251: push(@{$changes{$type}},'others');
3252: }
3253: }
3254: } else {
3255: my %default;
3256: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3257: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3258: $default{'errormail'} = 'adminemail';
3259: $default{'packagesmail'} = 'adminemail';
3260: $default{'helpdeskmail'} = 'supportemail';
3261: foreach my $item (@contacts) {
3262: if ($to{$item} ne $default{$item}) {
3263: $changes{$item} = 1;
3264: }
3265: }
3266: foreach my $type (@mailings) {
3267: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
3268:
3269: push(@{$changes{$type}},@{$newsetting{$type}});
3270: }
3271: if ($others{$type} ne '') {
3272: push(@{$changes{$type}},'others');
3273: }
3274: }
3275: }
3276: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
3277: $dom);
3278: if ($putresult eq 'ok') {
3279: if (keys(%changes) > 0) {
3280: my ($titles,$short_titles) = &contact_titles();
3281: $resulttext = &mt('Changes made:').'<ul>';
3282: foreach my $item (@contacts) {
3283: if ($changes{$item}) {
3284: $resulttext .= '<li>'.$titles->{$item}.
3285: &mt(' set to: ').
3286: '<span class="LC_cusr_emph">'.
3287: $to{$item}.'</span></li>';
3288: }
3289: }
3290: foreach my $type (@mailings) {
3291: if (ref($changes{$type}) eq 'ARRAY') {
3292: $resulttext .= '<li>'.$titles->{$type}.': ';
3293: my @text;
3294: foreach my $item (@{$newsetting{$type}}) {
3295: push(@text,$short_titles->{$item});
3296: }
3297: if ($others{$type} ne '') {
3298: push(@text,$others{$type});
3299: }
3300: $resulttext .= '<span class="LC_cusr_emph">'.
3301: join(', ',@text).'</span></li>';
3302: }
3303: }
3304: $resulttext .= '</ul>';
3305: } else {
1.34 raeburn 3306: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 3307: }
3308: } else {
3309: $resulttext = '<span class="LC_error">'.
3310: &mt('An error occurred: [_1].',$putresult).'</span>';
3311: }
3312: return $resulttext;
3313: }
3314:
3315: sub modify_usercreation {
1.27 raeburn 3316: my ($dom,%domconfig) = @_;
1.34 raeburn 3317: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 3318: my $warningmsg;
1.27 raeburn 3319: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3320: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
3321: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
3322: }
3323: }
3324: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 3325: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 3326: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.45 raeburn 3327: my @contexts = ('author','course','selfcreate');
1.34 raeburn 3328: foreach my $item(@contexts) {
3329: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.45 raeburn 3330: if ($item eq 'selfcreate') {
1.43 raeburn 3331: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3332: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
3333: if (($cancreate{$item} eq 'any') || ($cancreate{$item} eq 'login')) {
3334: $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.');
3335: }
3336: }
3337: }
1.34 raeburn 3338: }
3339: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
3340: foreach my $item (@contexts) {
3341: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
3342: push(@{$changes{'cancreate'}},$item);
3343: }
1.27 raeburn 3344: }
1.34 raeburn 3345: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
3346: foreach my $item (@contexts) {
1.43 raeburn 3347: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 3348: if ($cancreate{$item} ne 'any') {
3349: push(@{$changes{'cancreate'}},$item);
3350: }
3351: } else {
3352: if ($cancreate{$item} ne 'none') {
3353: push(@{$changes{'cancreate'}},$item);
3354: }
1.27 raeburn 3355: }
3356: }
3357: } else {
1.43 raeburn 3358: foreach my $item (@contexts) {
1.34 raeburn 3359: push(@{$changes{'cancreate'}},$item);
3360: }
1.27 raeburn 3361: }
1.34 raeburn 3362:
1.27 raeburn 3363: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
3364: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
3365: if (!grep(/^\Q$type\E$/,@username_rule)) {
3366: push(@{$changes{'username_rule'}},$type);
3367: }
3368: }
3369: foreach my $type (@username_rule) {
3370: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
3371: push(@{$changes{'username_rule'}},$type);
3372: }
3373: }
3374: } else {
3375: push(@{$changes{'username_rule'}},@username_rule);
3376: }
3377:
1.32 raeburn 3378: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
3379: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
3380: if (!grep(/^\Q$type\E$/,@id_rule)) {
3381: push(@{$changes{'id_rule'}},$type);
3382: }
3383: }
3384: foreach my $type (@id_rule) {
3385: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
3386: push(@{$changes{'id_rule'}},$type);
3387: }
3388: }
3389: } else {
3390: push(@{$changes{'id_rule'}},@id_rule);
3391: }
3392:
1.43 raeburn 3393: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
3394: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
3395: if (!grep(/^\Q$type\E$/,@email_rule)) {
3396: push(@{$changes{'email_rule'}},$type);
3397: }
3398: }
3399: foreach my $type (@email_rule) {
3400: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
3401: push(@{$changes{'email_rule'}},$type);
3402: }
3403: }
3404: } else {
3405: push(@{$changes{'email_rule'}},@email_rule);
3406: }
3407:
3408: my @authen_contexts = ('author','course','domain');
1.28 raeburn 3409: my @authtypes = ('int','krb4','krb5','loc');
3410: my %authhash;
1.43 raeburn 3411: foreach my $item (@authen_contexts) {
1.28 raeburn 3412: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
3413: foreach my $auth (@authtypes) {
3414: if (grep(/^\Q$auth\E$/,@authallowed)) {
3415: $authhash{$item}{$auth} = 1;
3416: } else {
3417: $authhash{$item}{$auth} = 0;
3418: }
3419: }
3420: }
3421: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 3422: foreach my $item (@authen_contexts) {
1.28 raeburn 3423: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
3424: foreach my $auth (@authtypes) {
3425: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
3426: push(@{$changes{'authtypes'}},$item);
3427: last;
3428: }
3429: }
3430: }
3431: }
3432: } else {
1.43 raeburn 3433: foreach my $item (@authen_contexts) {
1.28 raeburn 3434: push(@{$changes{'authtypes'}},$item);
3435: }
3436: }
3437:
1.27 raeburn 3438: my %usercreation_hash = (
1.28 raeburn 3439: usercreation => {
1.34 raeburn 3440: cancreate => \%cancreate,
1.27 raeburn 3441: username_rule => \@username_rule,
1.32 raeburn 3442: id_rule => \@id_rule,
1.43 raeburn 3443: email_rule => \@email_rule,
1.32 raeburn 3444: authtypes => \%authhash,
1.27 raeburn 3445: }
3446: );
3447:
3448: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
3449: $dom);
3450: if ($putresult eq 'ok') {
3451: if (keys(%changes) > 0) {
3452: $resulttext = &mt('Changes made:').'<ul>';
3453: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 3454: my %lt = &usercreation_types();
3455: foreach my $type (@{$changes{'cancreate'}}) {
1.43 raeburn 3456: my $chgtext = $lt{$type}.', ';
1.45 raeburn 3457: if ($type eq 'selfcreate') {
1.43 raeburn 3458: if ($cancreate{$type} eq 'none') {
3459: $chgtext .= &mt('creation of a new user account is not permitted.');
3460: } elsif ($cancreate{$type} eq 'any') {
3461: $chgtext .= &mt('creation of a new account is permitted for users authenticated by institutional log-in and SSO, and also for e-mail addresses used as usernames.');
3462: } elsif ($cancreate{$type} eq 'login') {
3463: $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional log-in.');
3464: } elsif ($cancreate{$type} eq 'sso') {
3465: $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional single sign on.');
3466: } elsif ($cancreate{$type} eq 'email') {
3467: $chgtext .= &mt('creation of a new account is only permitted for users who provide a valid e-mail address for use as the username.');
3468: }
3469: } else {
3470: if ($cancreate{$type} eq 'none') {
3471: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
3472: } elsif ($cancreate{$type} eq 'any') {
3473: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
3474: } elsif ($cancreate{$type} eq 'official') {
3475: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
3476: } elsif ($cancreate{$type} eq 'unofficial') {
3477: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
3478: }
1.34 raeburn 3479: }
3480: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 3481: }
3482: }
3483: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 3484: my ($rules,$ruleorder) =
3485: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 3486: my $chgtext = '<ul>';
3487: foreach my $type (@username_rule) {
3488: if (ref($rules->{$type}) eq 'HASH') {
3489: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
3490: }
3491: }
3492: $chgtext .= '</ul>';
3493: if (@username_rule > 0) {
3494: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3495: } else {
1.28 raeburn 3496: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 3497: }
3498: }
1.32 raeburn 3499: if (ref($changes{'id_rule'}) eq 'ARRAY') {
3500: my ($idrules,$idruleorder) =
3501: &Apache::lonnet::inst_userrules($dom,'id');
3502: my $chgtext = '<ul>';
3503: foreach my $type (@id_rule) {
3504: if (ref($idrules->{$type}) eq 'HASH') {
3505: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
3506: }
3507: }
3508: $chgtext .= '</ul>';
3509: if (@id_rule > 0) {
3510: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
3511: } else {
3512: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
3513: }
3514: }
1.43 raeburn 3515: if (ref($changes{'email_rule'}) eq 'ARRAY') {
3516: my ($emailrules,$emailruleorder) =
3517: &Apache::lonnet::inst_userrules($dom,'email');
3518: my $chgtext = '<ul>';
3519: foreach my $type (@email_rule) {
3520: if (ref($emailrules->{$type}) eq 'HASH') {
3521: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
3522: }
3523: }
3524: $chgtext .= '</ul>';
3525: if (@email_rule > 0) {
3526: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
3527: } else {
3528: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
3529: }
3530: }
3531:
1.28 raeburn 3532: my %authname = &authtype_names();
3533: my %context_title = &context_names();
3534: if (ref($changes{'authtypes'}) eq 'ARRAY') {
3535: my $chgtext = '<ul>';
3536: foreach my $type (@{$changes{'authtypes'}}) {
3537: my @allowed;
3538: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
3539: foreach my $auth (@authtypes) {
3540: if ($authhash{$type}{$auth}) {
3541: push(@allowed,$authname{$auth});
3542: }
3543: }
1.43 raeburn 3544: if (@allowed > 0) {
3545: $chgtext .= join(', ',@allowed).'</li>';
3546: } else {
3547: $chgtext .= &mt('none').'</li>';
3548: }
1.28 raeburn 3549: }
3550: $chgtext .= '</ul>';
3551: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
3552: $resulttext .= '</li>';
3553: }
1.27 raeburn 3554: $resulttext .= '</ul>';
3555: } else {
1.28 raeburn 3556: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 3557: }
3558: } else {
3559: $resulttext = '<span class="LC_error">'.
1.23 raeburn 3560: &mt('An error occurred: [_1]',$putresult).'</span>';
3561: }
1.43 raeburn 3562: if ($warningmsg ne '') {
3563: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
3564: }
1.23 raeburn 3565: return $resulttext;
3566: }
3567:
1.33 raeburn 3568: sub modify_usermodification {
3569: my ($dom,%domconfig) = @_;
3570: my ($resulttext,%curr_usermodification,%changes);
3571: if (ref($domconfig{'usermodification'}) eq 'HASH') {
3572: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
3573: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
3574: }
3575: }
3576: my @contexts = ('author','course');
3577: my %context_title = (
3578: author => 'In author context',
3579: course => 'In course context',
3580: );
3581: my @fields = ('lastname','firstname','middlename','generation',
3582: 'permanentemail','id');
3583: my %roles = (
3584: author => ['ca','aa'],
3585: course => ['st','ep','ta','in','cr'],
3586: );
3587: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3588: my %modifyhash;
3589: foreach my $context (@contexts) {
3590: foreach my $role (@{$roles{$context}}) {
3591: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
3592: foreach my $item (@fields) {
3593: if (grep(/^\Q$item\E$/,@modifiable)) {
3594: $modifyhash{$context}{$role}{$item} = 1;
3595: } else {
3596: $modifyhash{$context}{$role}{$item} = 0;
3597: }
3598: }
3599: }
3600: if (ref($curr_usermodification{$context}) eq 'HASH') {
3601: foreach my $role (@{$roles{$context}}) {
3602: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
3603: foreach my $field (@fields) {
3604: if ($modifyhash{$context}{$role}{$field} ne
3605: $curr_usermodification{$context}{$role}{$field}) {
3606: push(@{$changes{$context}},$role);
3607: last;
3608: }
3609: }
3610: }
3611: }
3612: } else {
3613: foreach my $context (@contexts) {
3614: foreach my $role (@{$roles{$context}}) {
3615: push(@{$changes{$context}},$role);
3616: }
3617: }
3618: }
3619: }
3620: my %usermodification_hash = (
3621: usermodification => \%modifyhash,
3622: );
3623: my $putresult = &Apache::lonnet::put_dom('configuration',
3624: \%usermodification_hash,$dom);
3625: if ($putresult eq 'ok') {
3626: if (keys(%changes) > 0) {
3627: $resulttext = &mt('Changes made: ').'<ul>';
3628: foreach my $context (@contexts) {
3629: if (ref($changes{$context}) eq 'ARRAY') {
3630: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
3631: if (ref($changes{$context}) eq 'ARRAY') {
3632: foreach my $role (@{$changes{$context}}) {
3633: my $rolename;
3634: if ($role eq 'cr') {
3635: $rolename = &mt('Custom');
3636: } else {
3637: $rolename = &Apache::lonnet::plaintext($role);
3638: }
3639: my @modifiable;
3640: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
3641: foreach my $field (@fields) {
3642: if ($modifyhash{$context}{$role}{$field}) {
3643: push(@modifiable,$fieldtitles{$field});
3644: }
3645: }
3646: if (@modifiable > 0) {
3647: $resulttext .= join(', ',@modifiable);
3648: } else {
3649: $resulttext .= &mt('none');
3650: }
3651: $resulttext .= '</li>';
3652: }
3653: $resulttext .= '</ul></li>';
3654: }
3655: }
3656: }
3657: $resulttext .= '</ul>';
3658: } else {
3659: $resulttext = &mt('No changes made to user modification settings');
3660: }
3661: } else {
3662: $resulttext = '<span class="LC_error">'.
3663: &mt('An error occurred: [_1]',$putresult).'</span>';
3664: }
3665: return $resulttext;
3666: }
3667:
1.43 raeburn 3668: sub modify_defaults {
3669: my ($dom,$r) = @_;
3670: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
3671: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
3672: my @items = ('auth_def','auth_arg_def','lang_def');
3673: my @authtypes = ('internal','krb4','krb5','localauth');
3674: foreach my $item (@items) {
3675: $newvalues{$item} = $env{'form.'.$item};
3676: if ($item eq 'auth_def') {
3677: if ($newvalues{$item} ne '') {
3678: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
3679: push(@errors,$item);
3680: }
3681: }
3682: } elsif ($item eq 'lang_def') {
3683: if ($newvalues{$item} ne '') {
3684: if ($newvalues{$item} =~ /^(\w+)/) {
3685: my $langcode = $1;
3686: if (code2language($langcode) eq '') {
3687: push(@errors,$item);
3688: }
3689: } else {
3690: push(@errors,$item);
3691: }
3692: }
3693: }
3694: if (grep(/^\Q$item\E$/,@errors)) {
3695: $newvalues{$item} = $domdefaults{$item};
3696: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
3697: $changes{$item} = 1;
3698: }
3699: }
3700: my %defaults_hash = (
3701: defaults => { auth_def => $newvalues{'auth_def'},
3702: auth_arg_def => $newvalues{'auth_arg_def'},
3703: lang_def => $newvalues{'lang_def'},
3704: }
3705: );
3706: my $title = &defaults_titles();
3707: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
3708: $dom);
3709: if ($putresult eq 'ok') {
3710: if (keys(%changes) > 0) {
3711: $resulttext = &mt('Changes made:').'<ul>';
3712: my $version = $r->dir_config('lonVersion');
3713: 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";
3714: foreach my $item (sort(keys(%changes))) {
3715: my $value = $env{'form.'.$item};
3716: if ($value eq '') {
3717: $value = &mt('none');
3718: } elsif ($item eq 'auth_def') {
3719: my %authnames = &authtype_names();
3720: my %shortauth = (
3721: internal => 'int',
3722: krb4 => 'krb4',
3723: krb5 => 'krb5',
3724: localauth => 'loc',
3725: );
3726: $value = $authnames{$shortauth{$value}};
3727: }
3728: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
3729: $mailmsgtext .= "$title->{$item} set to $value\n";
3730: }
3731: $resulttext .= '</ul>';
3732: $mailmsgtext .= "\n";
3733: my $cachetime = 24*60*60;
3734: &Apache::lonnet::do_cache_new('domdefaults',$dom,
3735: $defaults_hash{'defaults'},$cachetime);
3736: my $sysmail = $r->dir_config('lonSysEMail');
3737: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
3738: } else {
3739: $resulttext = &mt('No changes made to default authentication/language settings');
3740: }
3741: } else {
3742: $resulttext = '<span class="LC_error">'.
3743: &mt('An error occurred: [_1]',$putresult).'</span>';
3744: }
3745: if (@errors > 0) {
3746: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
3747: foreach my $item (@errors) {
3748: $resulttext .= ' "'.$title->{$item}.'",';
3749: }
3750: $resulttext =~ s/,$//;
3751: }
3752: return $resulttext;
3753: }
3754:
1.46 ! raeburn 3755: sub modify_scantron {
! 3756: my ($r,$dom,$confname,$domconfig) = @_;
! 3757: my ($resulttext,%confhash,%changes,$errors);
! 3758: my $custom = 'custom.tab';
! 3759: my $default = 'default.tab';
! 3760: my $servadm = $r->dir_config('lonAdmEMail');
! 3761: my ($configuserok,$author_ok,$switchserver) =
! 3762: &config_check($dom,$confname,$servadm);
! 3763: if ($env{'form.scantronformat.filename'} ne '') {
! 3764: my $error;
! 3765: if ($configuserok eq 'ok') {
! 3766: if ($switchserver) {
! 3767: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
! 3768: } else {
! 3769: if ($author_ok eq 'ok') {
! 3770: my ($result,$scantronurl) =
! 3771: &publishlogo($r,'upload','scantronformat',$dom,
! 3772: $confname,'scantron','','',$custom);
! 3773: if ($result eq 'ok') {
! 3774: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
! 3775: $changes{'scantron'}{'scantronformat'} = 1;
! 3776: } else {
! 3777: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
! 3778: }
! 3779: } else {
! 3780: $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);
! 3781: }
! 3782: }
! 3783: } else {
! 3784: $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);
! 3785: }
! 3786: if ($error) {
! 3787: &Apache::lonnet::logthis($error);
! 3788: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 3789: }
! 3790: }
! 3791: if (ref($domconfig) eq 'HASH') {
! 3792: if (ref($domconfig->{'scantron'}) eq 'HASH') {
! 3793: if ($domconfig->{'scantron'}{'scantronformat'} ne '') {
! 3794: if ($env{'form.scantronformat_del'}) {
! 3795: $confhash{'scantron'}{'scantronformat'} = '';
! 3796: $changes{'scantron'}{'scantronformat'} = 1;
! 3797: }
! 3798: }
! 3799: }
! 3800: }
! 3801: if (keys(%confhash) > 0) {
! 3802: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
! 3803: $dom);
! 3804: if ($putresult eq 'ok') {
! 3805: if (keys(%changes) > 0) {
! 3806: $resulttext = &mt('Changes made:').'<ul>';
! 3807: if (ref($changes{'scantron'}) eq 'HASH') {
! 3808: if ($changes{'scantron'}{'scantronformat'}) {
! 3809: if ($confhash{'scantron'}{'scantronformat'} eq '') {
! 3810: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
! 3811: } else {
! 3812: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
! 3813: }
! 3814: }
! 3815: }
! 3816: $resulttext .= '</ul>';
! 3817: &Apache::loncommon::devalidate_domconfig_cache($dom);
! 3818: } else {
! 3819: $resulttext = &mt('No changes made to scantron format file');
! 3820: }
! 3821: } else {
! 3822: $resulttext = '<span class="LC_error">'.
! 3823: &mt('An error occurred: [_1]',$putresult).'</span>';
! 3824: }
! 3825: } else {
! 3826: $resulttext = &mt('No changes made to scantron format file');
! 3827: }
! 3828: if ($errors) {
! 3829: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
! 3830: $errors.'</ul>';
! 3831: }
! 3832: return $resulttext;
! 3833: }
! 3834:
1.3 raeburn 3835: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>