Annotation of loncom/interface/domainprefs.pm, revision 1.12
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.12 ! raeburn 4: # $Id: domainprefs.pm,v 1.11 2007/04/12 20:33:31 albertel 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;
39: use LONCAPA();
1.6 raeburn 40: use LONCAPA::Enrollment;
1.9 raeburn 41: use File::Copy;
1.1 raeburn 42:
43: sub handler {
44: my $r=shift;
45: if ($r->header_only) {
46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK;
49: }
50:
51: my $dom = $env{'request.role.domain'};
1.5 albertel 52: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 53: if (&Apache::lonnet::allowed('mau',$dom)) {
54: &Apache::loncommon::content_type($r,'text/html');
55: $r->send_http_header;
56: } else {
57: $env{'user.error.msg'}=
58: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
59: return HTTP_NOT_ACCEPTABLE;
60: }
61: &Apache::lonhtmlcommon::clear_breadcrumbs();
62: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
63: ['phase']);
1.3 raeburn 64: my $phase = "display";
65: if ( exists($env{'form.phase'}) ) {
66: $phase = $env{'form.phase'};
67: }
68: my %domconfig =
1.6 raeburn 69: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
70: 'quotas','autoenroll','autoupdate'],$dom);
1.3 raeburn 71: my @prefs = (
1.6 raeburn 72: { text => 'Default color schemes',
73: help => 'Default_Color_Schemes',
74: action => 'rolecolors',
75: header => [{col1 => 'Student Settings',
76: col2 => '',},
77: {col1 => 'Coordinator Settings',
78: col2 => '',},
79: {col1 => 'Author Settings',
80: col2 => '',},
81: {col1 => 'Administrator Settings',
82: col2 => '',}],
83: },
1.3 raeburn 84: { text => 'Log-in page options',
85: help => 'Domain_Log-in_Page',
86: action => 'login',
87: header => [{col1 => 'Item',
1.6 raeburn 88: col2 => '',}],
1.3 raeburn 89: },
90: { text => 'Default quotas for user portfolios',
91: help => 'Default_User_Quota',
92: action => 'quotas',
93: header => [{col1 => 'User type',
94: col2 => 'Default quota'}],
95: },
96: { text => 'Auto-enrollment settings',
97: help => 'Domain_Auto_Enrollment',
98: action => 'autoenroll',
99: header => [{col1 => 'Configuration setting',
100: col2 => 'Value(s)'}],
101: },
102: { text => 'Auto-update settings',
103: help => 'Domain_Auto_Update',
104: action => 'autoupdate',
105: header => [{col1 => 'Setting',
106: col2 => 'Value',},
107: {col1 => 'User Population',
108: col2 => 'Updataeable user data'}],
109: },
110: );
1.6 raeburn 111: my @roles = ('student','coordinator','author','admin');
1.3 raeburn 112: &Apache::lonhtmlcommon::add_breadcrumb
113: ({href=>"javascript:changePage(document.$phase,'display')",
114: text=>"Domain Configuration"});
1.9 raeburn 115: my $confname = $dom.'-domainconfig';
1.3 raeburn 116: if ($phase eq 'process') {
1.1 raeburn 117: &Apache::lonhtmlcommon::add_breadcrumb
1.3 raeburn 118: ({href=>"javascript:changePage(document.$phase,'$phase')",
119: text=>"Updated"});
120: &print_header($r,$phase);
121: foreach my $item (@prefs) {
122: $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
1.9 raeburn 123: &process_changes($r,$dom,$confname,
124: $item->{'action'},\@roles,%domconfig));
1.3 raeburn 125: }
126: $r->print('<p>');
127: &print_footer($r,$phase,'display','Back to actions menu');
128: $r->print('</p>');
1.1 raeburn 129: } else {
1.3 raeburn 130: if ($phase eq '') {
131: $phase = 'display';
1.1 raeburn 132: }
1.3 raeburn 133: my %helphash;
134: my $numprefs = @prefs;
135: &print_header($r,$phase);
136: $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
137: foreach my $item (@prefs) {
1.6 raeburn 138: if ($item->{'action'} eq 'login') {
1.3 raeburn 139: $r->print('</td><td width="6%"> </td><td align="left" valign="top" width="47%">');
140: }
1.9 raeburn 141: &print_config_box($r,$dom,$confname,$phase,$item->{'action'},
1.6 raeburn 142: $item,$domconfig{$item->{'action'}});
1.3 raeburn 143: }
144: $r->print('
145: </td>
146: </tr>
147: </table>');
148: &print_footer($r,$phase,'process','Store changes');
149: }
150: return OK;
151: }
152:
153: sub process_changes {
1.9 raeburn 154: my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3 raeburn 155: my $output;
156: if ($action eq 'login') {
1.9 raeburn 157: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 158: } elsif ($action eq 'rolecolors') {
1.9 raeburn 159: $output = &modify_rolecolors($r,$dom,$confname,$roles,
160: %domconfig);
1.3 raeburn 161: } elsif ($action eq 'quotas') {
162: $output = &modify_quotas($dom,%domconfig);
163: } elsif ($action eq 'autoenroll') {
164: $output = &modify_autoenroll($dom,%domconfig);
165: } elsif ($action eq 'autoupdate') {
166: $output = &modify_autoupdate($dom,%domconfig);
167: }
168: return $output;
169: }
170:
171: sub print_config_box {
1.9 raeburn 172: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.3 raeburn 173: $r->print('
174: <table class="LC_nested_outer">
175: <tr>
176: <th>'.&mt($item->{text}).' '.
177: &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
178: </tr>');
1.6 raeburn 179: if (($action eq 'autoupdate') || ($action eq 'rolecolors')) {
180: my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.3 raeburn 181: $r->print('
182: <tr>
183: <td>
184: <table class="LC_nested">
185: <tr class="LC_info_row">
1.6 raeburn 186: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3 raeburn 187: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.6 raeburn 188: </tr>');
189: if ($action eq 'autoupdate') {
190: $r->print(&print_autoupdate('top',$dom,$settings));
191: } else {
1.9 raeburn 192: $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings));
1.6 raeburn 193: }
194: $r->print('
195: </table>
196: </td>
197: </tr>
198: <tr>
199: <td>
200: <table class="LC_nested">
201: <tr class="LC_info_row">
202: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
203: <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
204: </tr>');
205: if ($action eq 'autoupdate') {
206: $r->print(&print_autoupdate('bottom',$dom,$settings));
207: } else {
1.9 raeburn 208: $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).'
1.6 raeburn 209: </table>
210: </td>
211: </tr>
212: <tr>
213: <td>
214: <table class="LC_nested">
215: <tr class="LC_info_row">
216: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
217: <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3 raeburn 218: </tr>'.
1.9 raeburn 219: &print_rolecolors($phase,'author',$dom,$confname,$settings).'
1.3 raeburn 220: </table>
221: </td>
222: </tr>
223: <tr>
224: <td>
225: <table class="LC_nested">
226: <tr class="LC_info_row">
1.6 raeburn 227: <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
228: <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3 raeburn 229: </tr>'.
1.9 raeburn 230: &print_rolecolors($phase,'admin',$dom,$confname,$settings));
1.6 raeburn 231: }
1.3 raeburn 232: } else {
233: $r->print('
234: <tr>
235: <td>
236: <table class="LC_nested">
1.6 raeburn 237: <tr class="LC_info_row">');
238: if ($action eq 'login') {
239: $r->print('
240: <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
241: } else {
242: $r->print('
243: <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
244: }
245: $r->print('
1.3 raeburn 246: <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
247: </tr>');
248: if ($action eq 'login') {
1.9 raeburn 249: $r->print(&print_login($dom,$confname,$phase,$settings));
1.3 raeburn 250: } elsif ($action eq 'quotas') {
251: $r->print(&print_quotas($dom,$settings));
252: } elsif ($action eq 'autoenroll') {
253: $r->print(&print_autoenroll($dom,$settings));
254: }
255: }
256: $r->print('
257: </table>
258: </td>
259: </tr>
260: </table><br />');
1.1 raeburn 261: return;
262: }
263:
264: sub print_header {
1.3 raeburn 265: my ($r,$phase) = @_;
1.6 raeburn 266: my $js = '
1.1 raeburn 267: <script type="text/javascript">
268: function changePage(formname,newphase) {
269: formname.phase.value = newphase;
270: formname.submit();
271: }
1.6 raeburn 272: '.
273: &color_pick_js().'
1.1 raeburn 274: </script>
1.6 raeburn 275: ';
1.2 albertel 276: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.3 raeburn 277: $js));
278: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6 raeburn 279: $r->print('
1.8 raeburn 280: <form name="parmform" action="">
1.6 raeburn 281: <input type="hidden" name="pres_marker" />
282: <input type="hidden" name="pres_type" />
283: <input type="hidden" name="pres_value" />
284: </form>
285: ');
286: $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
287: ' enctype="multipart/form-data">');
1.1 raeburn 288: return;
289: }
290:
291: sub print_footer {
1.3 raeburn 292: my ($r,$phase,$newphase,$button_text) = @_;
293: $button_text = &mt($button_text);
294: $r->print('<input type="hidden" name="phase" value="" />');
295: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
296: if ($phase eq 'process') {
297: $r->print('<a href='.$dest.'>'.$button_text.'</a>');
298: } else {
299: $r->print('<input type="button" name="store" value="'.
300: $button_text.'" onclick='.$dest.' />');
301: }
302: $r->print('</form>');
1.1 raeburn 303: $r->print('<br />'.&Apache::loncommon::end_page());
304: return;
305: }
306:
1.3 raeburn 307: sub print_login {
1.9 raeburn 308: my ($dom,$confname,$phase,$settings) = @_;
1.6 raeburn 309: my %choices = &login_choices();
310: my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
311: $catalogon = ' checked="checked" ';
312: $adminmailoff = ' checked="checked" ';
313: my @images = ('img','logo','domlogo');
314: my @bgs = ('pgbg','mainbg','sidebg');
315: my @links = ('link','alink','vlink');
1.7 albertel 316: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 317: my %defaultdesign = %Apache::loncommon::defaultdesign;
318: my (%is_custom,%designs);
319: my %defaults = (
320: font => $defaultdesign{'login.font'},
321: );
322: foreach my $item (@images) {
323: $defaults{$item} = $defaultdesign{'login.'.$item};
324: }
325: foreach my $item (@bgs) {
326: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
327: }
328: foreach my $item (@links) {
329: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
330: }
1.3 raeburn 331: if (ref($settings) eq 'HASH') {
332: if ($settings->{'coursecatalog'} eq '0') {
1.1 raeburn 333: $catalogoff = $catalogon;
334: $catalogon = ' ';
335: }
1.3 raeburn 336: if ($settings->{'adminmail'} eq '1') {
1.1 raeburn 337: $adminmailon = $adminmailoff;
338: $adminmailoff = ' ';
339: }
1.6 raeburn 340: foreach my $item (@images) {
341: if ($settings->{$item} ne '') {
342: $designs{$item} = $settings->{$item};
343: $is_custom{$item} = 1;
344: }
345: }
346: if ($settings->{'font'} ne '') {
347: $designs{'font'} = $settings->{'font'};
348: $is_custom{'font'} = 1;
349: }
350: foreach my $item (@bgs) {
351: if ($settings->{$item} ne '') {
352: $designs{'bgs'}{$item} = $settings->{$item};
353: $is_custom{$item} = 1;
354: }
355: }
356: foreach my $item (@links) {
357: if ($settings->{$item} ne '') {
358: $designs{'links'}{$item} = $settings->{$item};
359: $is_custom{$item} = 1;
360: }
361: }
362: } else {
363: if ($designhash{$dom.'.login.font'} ne '') {
364: $designs{'font'} = $designhash{$dom.'.login.font'};
365: $is_custom{'font'} = 1;
366: }
1.8 raeburn 367: foreach my $item (@images) {
368: if ($designhash{$dom.'.login.'.$item} ne '') {
369: $designs{$item} = $designhash{$dom.'.login.'.$item};
370: $is_custom{$item} = 1;
371: }
372: }
1.6 raeburn 373: foreach my $item (@bgs) {
374: if ($designhash{$dom.'.login.'.$item} ne '') {
375: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
376: $is_custom{$item} = 1;
377: }
378: }
379: foreach my $item (@links) {
380: if ($designhash{$dom.'.login.'.$item} ne '') {
381: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
382: $is_custom{$item} = 1;
383: }
384: }
1.1 raeburn 385: }
1.6 raeburn 386: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
387: logo => 'Institution Logo',
388: domlogo => 'Domain Logo');
389: my $itemcount = 1;
390: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3 raeburn 391: my $datatable =
1.6 raeburn 392: '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
393: '</td><td>'.
1.8 raeburn 394: '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
395: $catalogon.' value="1" />'.&mt('Yes').'</label> '.
396: '<label><input type="radio" name="coursecatalog"'.
397: $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6 raeburn 398: '</tr>';
399: $itemcount ++;
400: $css_class = $itemcount%2?' class="LC_odd_row"':'';
401: $datatable .= '<tr'.$css_class.'>'.
402: '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8 raeburn 403: '<td><span class="LC_nobreak">'.
404: '<label><input type="radio" name="adminmail"'.
405: $adminmailon.' value="1" />'.&mt('Yes').'</label> '.
406: '<label><input type="radio" name="adminmail"'.
407: $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6 raeburn 408: $itemcount ++;
1.9 raeburn 409: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 410: $datatable .= '</tr></table></td></tr>';
411: return $datatable;
412: }
413:
414: sub login_choices {
415: my %choices =
416: &Apache::lonlocal::texthash (
417: coursecatalog => 'Display Course Catalog link?',
418: adminmail => "Display Administrator's E-mail Address?",
419: img => "Header",
420: logo => "Main Logo",
421: domlogo => "Domain Logo",
422: bgs => "Background colors",
423: links => "Link colors",
424: font => "Font color",
425: pgbg => "Page",
426: mainbg => "Main panel",
427: sidebg => "Side panel",
428: link => "Link",
429: alink => "Active link",
430: vlink => "Visited link",
431: );
432: return %choices;
433: }
434:
435: sub print_rolecolors {
1.9 raeburn 436: my ($phase,$role,$dom,$confname,$settings) = @_;
1.6 raeburn 437: my %choices = &color_font_choices();
438: my @bgs = ('pgbg','tabbg','sidebg');
439: my @links = ('link','alink','vlink');
440: my @images = ('img');
441: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 442: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 443: my %defaultdesign = %Apache::loncommon::defaultdesign;
444: my (%is_custom,%designs);
445: my %defaults = (
446: img => $defaultdesign{$role.'.img'},
447: font => $defaultdesign{$role.'.font'},
448: );
449: foreach my $item (@bgs) {
450: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
451: }
452: foreach my $item (@links) {
453: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
454: }
455: if (ref($settings) eq 'HASH') {
456: if (ref($settings->{$role}) eq 'HASH') {
457: if ($settings->{$role}->{'img'} ne '') {
458: $designs{'img'} = $settings->{$role}->{'img'};
459: $is_custom{'img'} = 1;
460: }
461: if ($settings->{$role}->{'font'} ne '') {
462: $designs{'font'} = $settings->{$role}->{'font'};
463: $is_custom{'font'} = 1;
464: }
465: foreach my $item (@bgs) {
466: if ($settings->{$role}->{$item} ne '') {
467: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
468: $is_custom{$item} = 1;
469: }
470: }
471: foreach my $item (@links) {
472: if ($settings->{$role}->{$item} ne '') {
473: $designs{'links'}{$item} = $settings->{$role}->{$item};
474: $is_custom{$item} = 1;
475: }
476: }
477: }
478: } else {
479: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
480: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
481: $is_custom{'img'} = 1;
482: }
483: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
484: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
485: $is_custom{'font'} = 1;
486: }
487: foreach my $item (@bgs) {
488: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
489: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
490: $is_custom{$item} = 1;
491:
492: }
493: }
494: foreach my $item (@links) {
495: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
496: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
497: $is_custom{$item} = 1;
498: }
499: }
500: }
501: my $itemcount = 1;
1.9 raeburn 502: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
1.6 raeburn 503: $datatable .= '</tr></table></td></tr>';
504: return $datatable;
505: }
506:
507: sub display_color_options {
1.9 raeburn 508: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.6 raeburn 509: $images,$bgs,$links,$alt_text) = @_;
510: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
511: my $datatable = '<tr'.$css_class.'>'.
512: '<td>'.$choices->{'font'}.'</td>';
513: if (!$is_custom->{'font'}) {
514: $datatable .= '<td>'.&mt('Default in use:').' '.$defaults->{'font'}.'</td>';
515: } else {
516: $datatable .= '<td> </td>';
517: }
518: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 519: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 520: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 521: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
522: '</span></td></tr>';
1.9 raeburn 523: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 524: foreach my $img (@{$images}) {
525: $itemcount ++;
526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 527: $datatable .= '<tr'.$css_class.'>'.
1.6 raeburn 528: '<td>'.$choices->{$img}.'</td>';
529: my $imgfile;
530: if ($designs->{$img} ne '') {
531: $imgfile = $designs->{$img};
532: } else {
533: $imgfile = $defaults->{$img};
534: }
535: if ($imgfile) {
1.9 raeburn 536: my ($showfile,$fullsize);
537: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 538: my $urldir = $1;
539: my $filename = $2;
540: my @info = &Apache::lonnet::stat_file($designs->{$img});
541: if (@info) {
542: my $thumbfile = 'tn-'.$filename;
543: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
544: if (@thumb) {
545: $showfile = $urldir.'/'.$thumbfile;
546: } else {
547: $showfile = $imgfile;
548: }
549: } else {
550: $showfile = '';
551: }
552: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
553: my $imgdir = $1;
554: my $filename = $2;
555: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
556: $showfile = "/$imgdir/tn-".$filename;
557: } else {
558: my $input = "/home/httpd/html".$imgfile;
559: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
560: if (!-e $output) {
1.9 raeburn 561: my ($width,$height) = &thumb_dimensions();
562: my $size = $width.'x'.$height;
563: system("convert -sample $size $input $output");
1.6 raeburn 564: }
565: $showfile = '/'.$imgdir.'/tn-'.$filename;
566: }
567: }
568: if ($showfile) {
1.9 raeburn 569: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
570: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1.6 raeburn 571: $datatable.= '<td>';
572: if (!$is_custom->{$img}) {
573: $datatable .= &mt('Default in use:').'<br />';
574: }
1.9 raeburn 575: $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
576: $showfile.'" alt="'.$alt_text->{$img}.
577: '" border="0" /></a></td>';
1.6 raeburn 578: if ($is_custom->{$img}) {
1.8 raeburn 579: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
580: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
581: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 582: } else {
583: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
584: }
585: } else {
586: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
587: &mt('Upload:');
588: }
589: } else {
590: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
591: &mt('Upload:');
592: }
1.9 raeburn 593: if ($switchserver) {
594: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
595: } else {
596: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
597: }
598: $datatable .= '</td></tr>';
1.6 raeburn 599: }
600: $itemcount ++;
601: $css_class = $itemcount%2?' class="LC_odd_row"':'';
602: $datatable .= '<tr'.$css_class.'>'.
603: '<td>'.$choices->{'bgs'}.'</td>';
604: my $bgs_def;
605: foreach my $item (@{$bgs}) {
606: if (!$is_custom->{$item}) {
607: $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
608: }
609: }
610: if ($bgs_def) {
1.8 raeburn 611: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 612: } else {
613: $datatable .= '<td> </td>';
614: }
615: $datatable .= '<td class="LC_right_item">'.
616: '<table border="0"><tr>';
617: foreach my $item (@{$bgs}) {
618: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
619: $datatable .= '<td align="center">'.$link;
620: if ($designs->{'bgs'}{$item}) {
621: $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px"> </span>';
622: }
623: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
624: '" /></td>';
625: }
626: $datatable .= '</tr></table></td></tr>';
627: $itemcount ++;
628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
629: $datatable .= '<tr'.$css_class.'>'.
630: '<td>'.$choices->{'links'}.'</td>';
631: my $links_def;
632: foreach my $item (@{$links}) {
633: if (!$is_custom->{$item}) {
634: $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
635: }
636: }
637: if ($links_def) {
1.8 raeburn 638: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 639: } else {
640: $datatable .= '<td> </td>';
641: }
642: $datatable .= '<td class="LC_right_item">'.
643: '<table border="0"><tr>';
644: foreach my $item (@{$links}) {
645: $datatable .= '<td align="center">';
646: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
647: if ($designs->{'links'}{$item}) {
648: $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
649: $link.'</span>';
650: } else {
651: $datatable .= $link;
652: }
653: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
654: '" /></td>';
655: }
1.3 raeburn 656: return $datatable;
657: }
658:
1.6 raeburn 659: sub color_pick {
660: my ($phase,$role,$item,$desc,$curcol) = @_;
661: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
662: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
663: ');">'.$desc.'</a>';
664: return $link;
665: }
666:
667: sub color_pick_js {
668: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
669: my $output = <<"ENDCOL";
670: function pclose() {
671: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
672: parmwin.close();
673: }
674:
675: $pjump_def
676:
677: function psub() {
678: pclose();
679: if (document.parmform.pres_marker.value!='') {
680: if (document.parmform.pres_type.value!='') {
681: eval('document.display.'+
682: document.parmform.pres_marker.value+
683: '.value=document.parmform.pres_value.value;');
684: }
685: } else {
686: document.parmform.pres_value.value='';
687: document.parmform.pres_marker.value='';
688: }
689: }
690: ENDCOL
691: return $output;
692: }
693:
1.3 raeburn 694: sub print_quotas {
695: my ($dom,$settings) = @_;
696: my $datatable;
697: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
698: my $othertitle = "All users";
699: my @types;
700: if (ref($order) eq 'ARRAY') {
701: @types = @{$order};
702: }
703: if (@types == 0) {
704: if (ref($usertypes) eq 'HASH') {
705: @types = sort(keys(%{$usertypes}));
706: }
707: }
708: my $typecount = 0;
709: my $css_class;
710: if (@types > 0) {
711: foreach my $type (@types) {
712: if (defined($usertypes->{$type})) {
713: $typecount ++;
714: $css_class = $typecount%2?' class="LC_odd_row"':'';
715: $datatable .= '<tr'.$css_class.'>'.
716: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 717: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 718: '<input type="text" name="quota_'.$type.
719: '" value="'.$settings->{$type}.
1.8 raeburn 720: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 721: }
722: }
723: $othertitle = "Other users";
724: }
725: my $defaultquota = '20';
726: if (ref($settings) eq 'HASH') {
727: if (defined($settings->{'default'})) {
728: $defaultquota = $settings->{'default'};
729: }
730: }
731: $typecount ++;
732: $css_class = $typecount%2?' class="LC_odd_row"':'';
733: $datatable .= '<tr'.$css_class.'>'.
734: '<td>'.&mt($othertitle).'</td>'.
1.8 raeburn 735: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 736: '<input type="text" name="default" value="'.
1.8 raeburn 737: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.3 raeburn 738: return $datatable;
739: }
740:
741: sub print_autoenroll {
742: my ($dom,$settings) = @_;
743: my $defdom = $dom;
744: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
745: my ($runon,$runoff);
746: if (ref($settings) eq 'HASH') {
747: if (exists($settings->{'run'})) {
748: if ($settings->{'run'} eq '0') {
749: $runoff = ' checked="checked" ';
750: $runon = ' ';
751: } else {
752: $runon = ' checked="checked" ';
753: $runoff = ' ';
754: }
755: } else {
756: if ($autorun) {
757: $runon = ' checked="checked" ';
758: $runoff = ' ';
759: } else {
760: $runoff = ' checked="checked" ';
761: $runon = ' ';
762: }
763: }
764: if (exists($settings->{'sender_domain'})) {
765: $defdom = $settings->{'sender_domain'};
766: }
767: }
768: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
769: my $datatable='<tr class="LC_odd_row">'.
770: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 771: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 772: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 773: $runon.' value="1" />'.&mt('Yes').'</label> '.
774: '<label><input type="radio" name="autoenroll_run"'.
775: $runoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 776: '</tr><tr>'.
777: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 778: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 779: &mt('username').': '.
780: '<input type="text" name="sender_uname" value="'.
781: $settings->{'sender_uname'}.
782: '" size="10" /> '.&mt('domain').
1.8 raeburn 783: ': '.$domform.'</span></td></tr>';
1.3 raeburn 784: return $datatable;
785: }
786:
787: sub print_autoupdate {
788: my ($position,$dom,$settings) = @_;
789: my $datatable;
790: if ($position eq 'top') {
791: my $updateon = ' ';
792: my $updateoff = ' checked="checked" ';
793: my $classlistson = ' ';
794: my $classlistsoff = ' checked="checked" ';
795: if (ref($settings) eq 'HASH') {
796: if ($settings->{'run'} eq '1') {
797: $updateon = $updateoff;
798: $updateoff = ' ';
799: }
800: if ($settings->{'classlists'} eq '1') {
801: $classlistson = $classlistsoff;
802: $classlistsoff = ' ';
803: }
804: }
805: my %title = (
806: run => 'Auto-update active?',
807: classlists => 'Update information in classlists?',
808: );
809: $datatable = '<tr class="LC_odd_row">'.
810: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 811: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 812: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 813: $updateon.' value="1" />'.&mt('Yes').'</label> '.
814: '<label><input type="radio" name="autoupdate_run"'.
815: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 816: '</tr><tr>'.
817: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 818: '<td class="LC_right_item"><span class="LC_nobreak">'.
819: '<label><input type="radio" name="classlists"'.
820: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
821: '<label><input type="radio" name="classlists"'.
822: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 823: '</tr>';
824: } else {
825: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
826: my @types;
827: if (ref($order) eq 'ARRAY') {
828: @types = @{$order};
829: }
830: if (@types == 0) {
831: if (ref($usertypes) eq 'HASH') {
832: @types = sort(keys(%{$usertypes}));
833: }
834: }
835: my $othertitle = &mt('All users');
836: if (keys(%{$usertypes}) > 0) {
837: $othertitle = &mt('Other users');
838: }
839: my @fields = ('lastname','firstname','middlename','gen','email','id');
840: my %fieldtitles = &Apache::lonlocal::texthash (
841: id => 'Student/Employee ID',
842: email => 'E-mail address',
843: lastname => 'Last Name',
844: firstname => 'First Name',
845: middlename => 'Middle Name',
846: gen => 'Generation',
847: );
848: my $numrows = 0;
849: if (@types > 0) {
850: $datatable =
851: &usertype_update_row($settings,$usertypes,\%fieldtitles,
852: \@fields,\@types,\$numrows);
853: }
854: $datatable .=
855: &usertype_update_row($settings,{'default' => $othertitle},
856: \%fieldtitles,\@fields,['default'],
857: \$numrows);
858: }
859: return $datatable;
860: }
861:
862: sub usertype_update_row {
863: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
864: my $datatable;
865: my $numinrow = 4;
866: foreach my $type (@{$types}) {
867: if (defined($usertypes->{$type})) {
868: $$rownums ++;
869: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
870: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
871: '</td><td class="LC_left_item"><table>';
872: for (my $i=0; $i<@{$fields}; $i++) {
873: my $rem = $i%($numinrow);
874: if ($rem == 0) {
875: if ($i > 0) {
876: $datatable .= '</tr>';
877: }
878: $datatable .= '<tr>';
879: }
880: my $check = ' ';
881: if (ref($settings->{'fields'}) eq 'HASH') {
882: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
883: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
884: $check = ' checked="checked" ';
885: }
886: }
887: }
888:
889: if ($i == @{$fields}-1) {
890: my $colsleft = $numinrow - $rem;
891: if ($colsleft > 1) {
892: $datatable .= '<td colspan="'.$colsleft.'">';
893: } else {
894: $datatable .= '<td>';
895: }
896: } else {
897: $datatable .= '<td>';
898: }
1.8 raeburn 899: $datatable .= '<span class="LC_nobreak"><label>'.
900: '<input type="checkbox" name="updateable_'.$type.
901: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
902: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 903: }
904: $datatable .= '</tr></table></td></tr>';
905: }
906: }
907: return $datatable;
1.1 raeburn 908: }
909:
910: sub modify_login {
1.9 raeburn 911: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 912: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 913: my %title = ( coursecatalog => 'Display course catalog',
914: adminmail => 'Display administrator E-mail address');
1.3 raeburn 915: my @offon = ('off','on');
1.6 raeburn 916: my %loginhash;
1.9 raeburn 917: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
918: \%domconfig,\%loginhash);
1.6 raeburn 919: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
920: $loginhash{login}{adminmail} = $env{'form.adminmail'};
921: if (ref($colchanges{'login'}) eq 'HASH') {
922: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
923: \%loginhash);
924: }
1.1 raeburn 925: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
926: $dom);
927: if ($putresult eq 'ok') {
1.3 raeburn 928: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 929: ($env{'form.coursecatalog'} eq '1')) {
930: $changes{'coursecatalog'} = 1;
1.3 raeburn 931: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
932: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 933: ($env{'form.coursecatalog'} eq '0')) {
934: $changes{'coursecatalog'} = 1;
935: }
1.3 raeburn 936: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 937: ($env{'form.adminmail'} eq '0')) {
938: $changes{'adminmail'} = 1;
939: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
940: $domconfig{'login'}{'adminmail'} eq '0') &&
941: ($env{'form.adminmail'} eq '1')) {
942: $changes{'adminmail'} = 1;
943: }
1.6 raeburn 944: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 945: $resulttext = &mt('Changes made:').'<ul>';
946: foreach my $item (sort(keys(%changes))) {
947: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
948: }
1.6 raeburn 949: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 950: } else {
951: $resulttext = &mt('No changes made to log-in page settings');
952: }
953: } else {
1.11 albertel 954: $resulttext = '<span class="LC_error">'.
955: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 956: }
1.6 raeburn 957: if ($errors) {
1.9 raeburn 958: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 959: $errors.'</ul>';
960: }
961: return $resulttext;
962: }
963:
964: sub color_font_choices {
965: my %choices =
966: &Apache::lonlocal::texthash (
967: img => "Header",
968: bgs => "Background colors",
969: links => "Link colors",
970: font => "Font color",
971: pgbg => "Page",
972: tabbg => "Header",
973: sidebg => "Border",
974: link => "Link",
975: alink => "Active link",
976: vlink => "Visited link",
977: );
978: return %choices;
979: }
980:
981: sub modify_rolecolors {
1.9 raeburn 982: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 983: my ($resulttext,%rolehash);
984: $rolehash{'rolecolors'} = {};
1.9 raeburn 985: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 986: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
987: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
988: $dom);
989: if ($putresult eq 'ok') {
990: if (keys(%changes) > 0) {
991: $resulttext = &display_colorchgs($dom,\%changes,$roles,
992: $rolehash{'rolecolors'});
993: } else {
994: $resulttext = &mt('No changes made to default color schemes');
995: }
996: } else {
1.11 albertel 997: $resulttext = '<span class="LC_error">'.
998: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 999: }
1000: if ($errors) {
1001: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1002: $errors.'</ul>';
1003: }
1004: return $resulttext;
1005: }
1006:
1007: sub modify_colors {
1.9 raeburn 1008: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 ! raeburn 1009: my (%changes,%choices);
1.6 raeburn 1010: my @bgs = ('pgbg','mainbg','sidebg');
1011: my @links = ('link','alink','vlink');
1012: my @images;
1013: my $servadm = $r->dir_config('lonAdmEMail');
1014: my $errors;
1015: foreach my $role (@{$roles}) {
1016: if ($role eq 'login') {
1.12 ! raeburn 1017: %choices = &login_choices();
! 1018: } else {
! 1019: %choices = &color_font_choices();
! 1020: }
! 1021: if ($role eq 'login') {
1.6 raeburn 1022: @images = ('img','logo','domlogo');
1023: } else {
1024: @images = ('img');
1025: }
1026: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1027: foreach my $item (@bgs,@links) {
1028: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1029: }
1.9 raeburn 1030: my ($configuserok,$author_ok,$switchserver,%currroles);
1031: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1032: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1033: $confname,$servadm);
1034: if ($configuserok eq 'ok') {
1035: $switchserver = &check_switchserver($dom,$confname);
1036: if ($switchserver eq '') {
1037: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1038: }
1039: }
1040: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1041: foreach my $img (@images) {
1.6 raeburn 1042: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1043: my $error;
1.6 raeburn 1044: if ($configuserok eq 'ok') {
1.9 raeburn 1045: if ($switchserver) {
1.12 ! raeburn 1046: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1047: } else {
1048: if ($author_ok eq 'ok') {
1049: my ($result,$logourl) =
1050: &publishlogo($r,'upload',$role.'_'.$img,
1051: $dom,$confname,$img,$width,$height);
1052: if ($result eq 'ok') {
1053: $confhash->{$role}{$img} = $logourl;
1.12 ! raeburn 1054: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1055: } else {
1.12 ! raeburn 1056: $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 1057: }
1058: } else {
1.12 ! raeburn 1059: $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuation user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6 raeburn 1060: }
1061: }
1062: } else {
1.12 ! raeburn 1063: $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9 raeburn 1064: }
1065: if ($error) {
1.8 raeburn 1066: &Apache::lonnet::logthis($error);
1.11 albertel 1067: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1068: }
1069: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1070: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1071: my $error;
1072: if ($configuserok eq 'ok') {
1073: # is confname an author?
1074: if ($switchserver eq '') {
1075: if ($author_ok eq 'ok') {
1076: my ($result,$logourl) =
1077: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1078: $dom,$confname,$img,$width,$height);
1079: if ($result eq 'ok') {
1080: $confhash->{$role}{$img} = $logourl;
1081: }
1082: }
1083: }
1084: }
1.6 raeburn 1085: }
1086: }
1087: }
1088: if (ref($domconfig) eq 'HASH') {
1089: if (ref($domconfig->{$role}) eq 'HASH') {
1090: foreach my $img (@images) {
1091: if ($domconfig->{$role}{$img} ne '') {
1092: if ($env{'form.'.$role.'_del_'.$img}) {
1093: $confhash->{$role}{$img} = '';
1.12 ! raeburn 1094: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1095: } else {
1.9 raeburn 1096: if ($confhash->{$role}{$img} eq '') {
1097: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1098: }
1.6 raeburn 1099: }
1100: } else {
1101: if ($env{'form.'.$role.'_del_'.$img}) {
1102: $confhash->{$role}{$img} = '';
1.12 ! raeburn 1103: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1104: }
1105: }
1106: }
1107: if ($domconfig->{$role}{'font'} ne '') {
1108: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1109: $changes{$role}{'font'} = 1;
1110: }
1111: } else {
1112: if ($confhash->{$role}{'font'}) {
1113: $changes{$role}{'font'} = 1;
1114: }
1115: }
1116: foreach my $item (@bgs) {
1117: if ($domconfig->{$role}{$item} ne '') {
1118: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1119: $changes{$role}{'bgs'}{$item} = 1;
1120: }
1121: } else {
1122: if ($confhash->{$role}{$item}) {
1123: $changes{$role}{'bgs'}{$item} = 1;
1124: }
1125: }
1126: }
1127: foreach my $item (@links) {
1128: if ($domconfig->{$role}{$item} ne '') {
1129: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1130: $changes{$role}{'links'}{$item} = 1;
1131: }
1132: } else {
1133: if ($confhash->{$role}{$item}) {
1134: $changes{$role}{'links'}{$item} = 1;
1135: }
1136: }
1137: }
1138: } else {
1139: &default_change_checker($role,\@images,\@links,\@bgs,
1140: $confhash,\%changes);
1141: }
1142: } else {
1143: &default_change_checker($role,\@images,\@links,\@bgs,
1144: $confhash,\%changes);
1145: }
1146: }
1147: return ($errors,%changes);
1148: }
1149:
1150: sub default_change_checker {
1151: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1152: foreach my $item (@{$links}) {
1153: if ($confhash->{$role}{$item}) {
1154: $changes->{$role}{'links'}{$item} = 1;
1155: }
1156: }
1157: foreach my $item (@{$bgs}) {
1158: if ($confhash->{$role}{$item}) {
1159: $changes->{$role}{'bgs'}{$item} = 1;
1160: }
1161: }
1162: foreach my $img (@{$images}) {
1163: if ($env{'form.'.$role.'_del_'.$img}) {
1164: $confhash->{$role}{$img} = '';
1.12 ! raeburn 1165: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1166: }
1167: }
1168: if ($confhash->{$role}{'font'}) {
1169: $changes->{$role}{'font'} = 1;
1170: }
1171: }
1172:
1173: sub display_colorchgs {
1174: my ($dom,$changes,$roles,$confhash) = @_;
1175: my (%choices,$resulttext);
1.7 albertel 1176: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1177: if (!grep(/^login$/,@{$roles})) {
1178: $resulttext = &mt('Changes made:').'<br />';
1179: }
1180: foreach my $role (@{$roles}) {
1181: if ($role eq 'login') {
1182: %choices = &login_choices();
1183: } else {
1184: %choices = &color_font_choices();
1185: }
1186: if (ref($changes->{$role}) eq 'HASH') {
1187: if ($role ne 'login') {
1188: $resulttext .= '<h4>'.&mt($role).'</h4>';
1189: }
1190: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1191: if ($role ne 'login') {
1192: $resulttext .= '<ul>';
1193: }
1194: if (ref($changes->{$role}{$key}) eq 'HASH') {
1195: if ($role ne 'login') {
1196: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1197: }
1198: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1199: if ($confhash->{$role}{$item} eq '') {
1200: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1201: } else {
1.12 ! raeburn 1202: my $newitem = $confhash->{$role}{$item};
! 1203: if ($key eq 'images') {
! 1204: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
! 1205: }
! 1206: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1207: }
1208: }
1209: if ($role ne 'login') {
1210: $resulttext .= '</ul></li>';
1211: }
1212: } else {
1213: if ($confhash->{$role}{$key} eq '') {
1214: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1215: } else {
1216: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1217: }
1218: }
1219: if ($role ne 'login') {
1220: $resulttext .= '</ul>';
1221: }
1222: }
1223: }
1224: }
1.3 raeburn 1225: return $resulttext;
1.1 raeburn 1226: }
1227:
1.9 raeburn 1228: sub thumb_dimensions {
1229: return ('200','50');
1230: }
1231:
1232: sub check_configuser {
1233: my ($uhome,$dom,$confname,$servadm) = @_;
1234: my ($configuserok,%currroles);
1235: if ($uhome eq 'no_host') {
1236: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1237: my $configpass = &LONCAPA::Enrollment::create_password();
1238: $configuserok =
1239: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1240: $configpass,'','','','','',undef,$servadm);
1241: } else {
1242: $configuserok = 'ok';
1243: %currroles =
1244: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1245: }
1246: return ($configuserok,%currroles);
1247: }
1248:
1249: sub check_authorstatus {
1250: my ($dom,$confname,%currroles) = @_;
1251: my $author_ok;
1252: if (!$currroles{':'.$dom.':au'}) {
1253: my $start = time;
1254: my $end = 0;
1255: $author_ok =
1256: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1257: 'au',$end,$start);
1258: } else {
1259: $author_ok = 'ok';
1260: }
1261: return $author_ok;
1262: }
1263:
1264: sub publishlogo {
1265: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1266: my ($output,$fname,$logourl);
1267: if ($action eq 'upload') {
1268: $fname=$env{'form.'.$formname.'.filename'};
1269: chop($env{'form.'.$formname});
1270: } else {
1271: ($fname) = ($formname =~ /([^\/]+)$/);
1272: }
1273: $fname=&Apache::lonnet::clean_filename($fname);
1274: # See if there is anything left
1275: unless ($fname) { return ('error: no uploaded file'); }
1276: $fname="$subdir/$fname";
1277: my $filepath='/home/'.$confname.'/public_html';
1278: my ($fnamepath,$file,$fetchthumb);
1279: $file=$fname;
1280: if ($fname=~m|/|) {
1281: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1282: }
1283: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1284: my $count;
1285: for ($count=4;$count<=$#parts;$count++) {
1286: $filepath.="/$parts[$count]";
1287: if ((-e $filepath)!=1) {
1288: mkdir($filepath,02770);
1289: }
1290: }
1291: # Check for bad extension and disallow upload
1292: if ($file=~/\.(\w+)$/ &&
1293: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1294: $output =
1295: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
1296: } elsif ($file=~/\.(\w+)$/ &&
1297: !defined(&Apache::loncommon::fileembstyle($1))) {
1298: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1299: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1300: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1301: } elsif (-d "$filepath/$file") {
1302: $output = &mt('File name is a directory name - rename the file and re-upload');
1303: } else {
1304: my $source = $filepath.'/'.$file;
1305: my $logfile;
1306: if (!open($logfile,">>$source".'.log')) {
1307: return (&mt('No write permission to Construction Space'));
1308: }
1309: print $logfile
1310: "\n================= Publish ".localtime()." ================\n".
1311: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1312: # Save the file
1313: if (!open(FH,'>'.$source)) {
1314: &Apache::lonnet::logthis('Failed to create '.$source);
1315: return (&mt('Failed to create file'));
1316: }
1317: if ($action eq 'upload') {
1318: if (!print FH ($env{'form.'.$formname})) {
1319: &Apache::lonnet::logthis('Failed to write to '.$source);
1320: return (&mt('Failed to write file'));
1321: }
1322: } else {
1323: my $original = &Apache::lonnet::filelocation('',$formname);
1324: if(!copy($original,$source)) {
1325: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1326: return (&mt('Failed to write file'));
1327: }
1328: }
1329: close(FH);
1330: chmod(0660, $source); # Permissions to rw-rw---.
1331:
1332: my $docroot=$r->dir_config('lonDocRoot');
1333: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1334: my $copyfile=$targetdir.'/'.$file;
1335:
1336: my @parts=split(/\//,$targetdir);
1337: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1338: for (my $count=5;$count<=$#parts;$count++) {
1339: $path.="/$parts[$count]";
1340: if (!-e $path) {
1341: print $logfile "\nCreating directory ".$path;
1342: mkdir($path,02770);
1343: }
1344: }
1345: my $versionresult;
1346: if (-e $copyfile) {
1347: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1348: } else {
1349: $versionresult = 'ok';
1350: }
1351: if ($versionresult eq 'ok') {
1352: if (copy($source,$copyfile)) {
1353: print $logfile "\nCopied original source to ".$copyfile."\n";
1354: $output = 'ok';
1355: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1356: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1357: } else {
1358: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1359: $output = &mt('Failed to copy file to RES space').", $!";
1360: }
1361: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1362: my $inputfile = $filepath.'/'.$file;
1363: my $outfile = $filepath.'/'.'tn-'.$file;
1364: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1365: system("convert -sample $thumbsize $inputfile $outfile");
1366: chmod(0660, $filepath.'/tn-'.$file);
1367: if (-e $outfile) {
1368: my $copyfile=$targetdir.'/tn-'.$file;
1369: if (copy($outfile,$copyfile)) {
1370: print $logfile "\nCopied source to ".$copyfile."\n";
1371: &write_metadata($dom,$confname,$formname,$targetdir,
1372: 'tn-'.$file,$logfile);
1373: } else {
1374: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1375: }
1376: }
1377: }
1378: } else {
1379: $output = $versionresult;
1380: }
1381: }
1382: return ($output,$logourl);
1383: }
1384:
1385: sub logo_versioning {
1386: my ($targetdir,$file,$logfile) = @_;
1387: my $target = $targetdir.'/'.$file;
1388: my ($maxversion,$fn,$extn,$output);
1389: $maxversion = 0;
1390: if ($file =~ /^(.+)\.(\w+)$/) {
1391: $fn=$1;
1392: $extn=$2;
1393: }
1394: opendir(DIR,$targetdir);
1395: while (my $filename=readdir(DIR)) {
1396: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1397: $maxversion=($1>$maxversion)?$1:$maxversion;
1398: }
1399: }
1400: $maxversion++;
1401: print $logfile "\nCreating old version ".$maxversion."\n";
1402: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1403: if (copy($target,$copyfile)) {
1404: print $logfile "Copied old target to ".$copyfile."\n";
1405: $copyfile=$copyfile.'.meta';
1406: if (copy($target.'.meta',$copyfile)) {
1407: print $logfile "Copied old target metadata to ".$copyfile."\n";
1408: $output = 'ok';
1409: } else {
1410: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1411: $output = &mt('Failed to copy old meta').", $!, ";
1412: }
1413: } else {
1414: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1415: $output = &mt('Failed to copy old target').", $!, ";
1416: }
1417: return $output;
1418: }
1419:
1420: sub write_metadata {
1421: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1422: my (%metadatafields,%metadatakeys,$output);
1423: $metadatafields{'title'}=$formname;
1424: $metadatafields{'creationdate'}=time;
1425: $metadatafields{'lastrevisiondate'}=time;
1426: $metadatafields{'copyright'}='public';
1427: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1428: $env{'user.domain'};
1429: $metadatafields{'authorspace'}=$confname.':'.$dom;
1430: $metadatafields{'domain'}=$dom;
1431: {
1432: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1433: my $mfh;
1434: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1435: $output = &mt('Could not write metadata');
1436: }
1437: foreach (sort keys %metadatafields) {
1438: unless ($_=~/\./) {
1439: my $unikey=$_;
1440: $unikey=~/^([A-Za-z]+)/;
1441: my $tag=$1;
1442: $tag=~tr/A-Z/a-z/;
1443: print $mfh "\n\<$tag";
1444: foreach (split(/\,/,$metadatakeys{$unikey})) {
1445: my $value=$metadatafields{$unikey.'.'.$_};
1446: $value=~s/\"/\'\'/g;
1447: print $mfh ' '.$_.'="'.$value.'"';
1448: }
1449: print $mfh '>'.
1450: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1451: .'</'.$tag.'>';
1452: }
1453: }
1454: $output = 'ok';
1455: print $logfile "\nWrote metadata";
1456: close($mfh);
1457: }
1458: }
1459:
1460: sub check_switchserver {
1461: my ($dom,$confname) = @_;
1462: my ($allowed,$switchserver);
1463: my $home = &Apache::lonnet::homeserver($confname,$dom);
1464: if ($home eq 'no_host') {
1465: $home = &Apache::lonnet::domain($dom,'primary');
1466: }
1467: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 1468: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1469: if (!$allowed) {
1470: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 1471: }
1472: return $switchserver;
1473: }
1474:
1.1 raeburn 1475: sub modify_quotas {
1.3 raeburn 1476: my ($dom,%domconfig) = @_;
1.1 raeburn 1477: my ($resulttext,%changes);
1.3 raeburn 1478: my ($usertypes,$order) =
1479: &Apache::lonnet::retrieve_inst_usertypes($dom);
1.1 raeburn 1480: my %formhash;
1481: foreach my $key (keys(%env)) {
1482: if ($key =~ /^form\.quota_(.+)$/) {
1483: $formhash{$1} = $env{$key};
1484: }
1485: }
1486: if (ref($domconfig{'quotas'}) eq 'HASH') {
1487: foreach my $key (keys(%{$domconfig{'quotas'}})) {
1488: if (exists($formhash{$key})) {
1489: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
1490: $changes{$key} = 1;
1491: }
1492: } else {
1493: $formhash{$key} = $domconfig{'quotas'}{$key};
1494: }
1495: }
1496: }
1497: foreach my $key (keys(%formhash)) {
1498: if ($formhash{$key} ne '') {
1.3 raeburn 1499: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 1500: $changes{$key} = 1;
1501: }
1502: }
1503: }
1504: my %quotahash = (
1.3 raeburn 1505: quotas => {%formhash},
1.1 raeburn 1506: );
1507: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
1508: $dom);
1509: if ($putresult eq 'ok') {
1510: if (keys(%changes) > 0) {
1511: $resulttext = &mt('Changes made:').'<ul>';
1512: foreach my $item (sort(keys(%changes))) {
1513: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
1514: }
1515: $resulttext .= '</ul>';
1516: } else {
1517: $resulttext = &mt('No changes made to default quotas');
1518: }
1519: } else {
1.11 albertel 1520: $resulttext = '<span class="LC_error">'.
1521: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1522: }
1.3 raeburn 1523: return $resulttext;
1.1 raeburn 1524: }
1525:
1.3 raeburn 1526: sub modify_autoenroll {
1527: my ($dom,%domconfig) = @_;
1.1 raeburn 1528: my ($resulttext,%changes);
1529: my %currautoenroll;
1530: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1531: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
1532: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
1533: }
1534: }
1535: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1536: my %title = ( run => 'Auto-enrollment active',
1537: sender => 'Sender for notification messages');
1538: my @offon = ('off','on');
1539: my %autoenrollhash = (
1540: autoenroll => { run => $env{'form.autoenroll_run'},
1541: sender_uname => $env{'form.sender_uname'},
1542: sender_domain => $env{'form.sender_domain'},
1543:
1544: }
1545: );
1.4 raeburn 1546: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
1547: $dom);
1.1 raeburn 1548: if ($putresult eq 'ok') {
1549: if (exists($currautoenroll{'run'})) {
1550: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
1551: $changes{'run'} = 1;
1552: }
1553: } elsif ($autorun) {
1554: if ($env{'form.autoenroll_run'} ne '1') {
1555: $changes{'run'} = 1;
1556: }
1557: }
1558: if (exists($currautoenroll{sender_uname})) {
1559: if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
1560: $changes{'sender'} = 1;
1561: }
1562: } else {
1563: $changes{'sender'} = 1;
1564: }
1565: if (exists($currautoenroll{sender_domain})) {
1566: if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
1567: $changes{'sender'} = 1;
1568: }
1569: } else {
1570: $changes{'sender'} = 1;
1571: }
1572: if (keys(%changes) > 0) {
1573: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 1574: if ($changes{'run'}) {
1.1 raeburn 1575: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
1576: }
1577: if ($changes{'sender'}) {
1578: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
1579: }
1580: $resulttext .= '</ul>';
1581: } else {
1582: $resulttext = &mt('No changes made to auto-enrollment settings');
1583: }
1584: } else {
1.11 albertel 1585: $resulttext = '<span class="LC_error">'.
1586: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1587: }
1.3 raeburn 1588: return $resulttext;
1.1 raeburn 1589: }
1590:
1591: sub modify_autoupdate {
1.3 raeburn 1592: my ($dom,%domconfig) = @_;
1.1 raeburn 1593: my ($resulttext,%currautoupdate,%fields,%changes);
1594: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
1595: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
1596: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
1597: }
1598: }
1599: my @offon = ('off','on');
1600: my %title = &Apache::lonlocal::texthash (
1601: run => 'Auto-update:',
1602: classlists => 'Updates to user information in classlists?'
1603: );
1604: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1605: my %fieldtitles = &Apache::lonlocal::texthash (
1606: id => 'Student/Employee ID',
1607: email => 'E-mail address',
1608: lastname => 'Last Name',
1609: firstname => 'First Name',
1610: middlename => 'Middle Name',
1611: gen => 'Generation',
1612: );
1613: my $othertitle = &mt('All users');
1614: if (keys(%{$usertypes}) > 0) {
1615: $othertitle = "Other users";
1616: }
1617: foreach my $key (keys(%env)) {
1618: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1619: push(@{$fields{$1}},$2);
1620: }
1621: }
1622: my %updatehash = (
1623: autoupdate => { run => $env{'form.autoupdate_run'},
1624: classlists => $env{'form.classlists'},
1625: fields => {%fields},
1626: }
1627: );
1628: foreach my $key (keys(%currautoupdate)) {
1629: if (($key eq 'run') || ($key eq 'classlists')) {
1630: if (exists($updatehash{autoupdate}{$key})) {
1631: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
1632: $changes{$key} = 1;
1633: }
1634: }
1635: } elsif ($key eq 'fields') {
1636: if (ref($currautoupdate{$key}) eq 'HASH') {
1637: foreach my $item (keys(%{$currautoupdate{$key}})) {
1638: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
1639: my $change = 0;
1640: foreach my $type (@{$currautoupdate{$key}{$item}}) {
1641: if (!exists($fields{$item})) {
1642: $change = 1;
1643: } elsif (ref($fields{$item}) eq 'ARRAY') {
1644: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
1645: $change = 1;
1646: }
1647: }
1648: }
1649: if ($change) {
1650: push(@{$changes{$key}},$item);
1651: }
1652: }
1653: }
1654: }
1655: }
1656: }
1657: foreach my $key (keys(%fields)) {
1658: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1659: if (!exists($currautoupdate{'fields'}{$key})) {
1660: push(@{$changes{'fields'}},$key);
1661: }
1662: } else {
1663: push(@{$changes{'fields'}},$key);
1664: }
1665: }
1666: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
1667: $dom);
1668: if ($putresult eq 'ok') {
1669: if (keys(%changes) > 0) {
1670: $resulttext = &mt('Changes made:').'<ul>';
1671: foreach my $key (sort(keys(%changes))) {
1672: if (ref($changes{$key}) eq 'ARRAY') {
1673: foreach my $item (@{$changes{$key}}) {
1674: my @newvalues;
1675: foreach my $type (@{$fields{$item}}) {
1676: push(@newvalues,$fieldtitles{$type});
1677: }
1.3 raeburn 1678: my $newvaluestr;
1679: if (@newvalues > 0) {
1680: $newvaluestr = join(', ',@newvalues);
1681: } else {
1682: $newvaluestr = &mt('none');
1.6 raeburn 1683: }
1.1 raeburn 1684: if ($item eq 'default') {
1685: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
1686: } else {
1687: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
1688: }
1689: }
1690: } else {
1691: my $newvalue;
1692: if ($key eq 'run') {
1693: $newvalue = $offon[$env{'form.autoupdate_run'}];
1694: } else {
1695: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 1696: }
1.1 raeburn 1697: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
1698: }
1699: }
1700: $resulttext .= '</ul>';
1701: } else {
1.3 raeburn 1702: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 1703: }
1704: } else {
1.11 albertel 1705: $resulttext = '<span class="LC_error">'.
1706: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1707: }
1.3 raeburn 1708: return $resulttext;
1.1 raeburn 1709: }
1710:
1.3 raeburn 1711: 1;
1.1 raeburn 1712:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>