Annotation of loncom/interface/domainprefs.pm, revision 1.14
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.14 ! raeburn 4: # $Id: domainprefs.pm,v 1.13 2007/05/02 01:33:48 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>');
1.13 albertel 148: &print_footer($r,$phase,'process','Save changes');
1.3 raeburn 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: }
1.14 ! raeburn 767: } else {
! 768: if ($autorun) {
! 769: $runon = ' checked="checked" ';
! 770: $runoff = ' ';
! 771: } else {
! 772: $runoff = ' checked="checked" ';
! 773: $runon = ' ';
! 774: }
1.3 raeburn 775: }
776: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
777: my $datatable='<tr class="LC_odd_row">'.
778: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 779: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 780: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 781: $runon.' value="1" />'.&mt('Yes').'</label> '.
782: '<label><input type="radio" name="autoenroll_run"'.
1.14 ! raeburn 783: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 784: '</tr><tr>'.
785: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 786: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 787: &mt('username').': '.
788: '<input type="text" name="sender_uname" value="'.
789: $settings->{'sender_uname'}.
790: '" size="10" /> '.&mt('domain').
1.8 raeburn 791: ': '.$domform.'</span></td></tr>';
1.3 raeburn 792: return $datatable;
793: }
794:
795: sub print_autoupdate {
796: my ($position,$dom,$settings) = @_;
797: my $datatable;
798: if ($position eq 'top') {
799: my $updateon = ' ';
800: my $updateoff = ' checked="checked" ';
801: my $classlistson = ' ';
802: my $classlistsoff = ' checked="checked" ';
803: if (ref($settings) eq 'HASH') {
804: if ($settings->{'run'} eq '1') {
805: $updateon = $updateoff;
806: $updateoff = ' ';
807: }
808: if ($settings->{'classlists'} eq '1') {
809: $classlistson = $classlistsoff;
810: $classlistsoff = ' ';
811: }
812: }
813: my %title = (
814: run => 'Auto-update active?',
815: classlists => 'Update information in classlists?',
816: );
817: $datatable = '<tr class="LC_odd_row">'.
818: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 819: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 820: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 821: $updateon.' value="1" />'.&mt('Yes').'</label> '.
822: '<label><input type="radio" name="autoupdate_run"'.
823: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 824: '</tr><tr>'.
825: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 826: '<td class="LC_right_item"><span class="LC_nobreak">'.
827: '<label><input type="radio" name="classlists"'.
828: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
829: '<label><input type="radio" name="classlists"'.
830: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 831: '</tr>';
832: } else {
833: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
834: my @types;
835: if (ref($order) eq 'ARRAY') {
836: @types = @{$order};
837: }
838: if (@types == 0) {
839: if (ref($usertypes) eq 'HASH') {
840: @types = sort(keys(%{$usertypes}));
841: }
842: }
843: my $othertitle = &mt('All users');
844: if (keys(%{$usertypes}) > 0) {
845: $othertitle = &mt('Other users');
846: }
847: my @fields = ('lastname','firstname','middlename','gen','email','id');
848: my %fieldtitles = &Apache::lonlocal::texthash (
849: id => 'Student/Employee ID',
850: email => 'E-mail address',
851: lastname => 'Last Name',
852: firstname => 'First Name',
853: middlename => 'Middle Name',
854: gen => 'Generation',
855: );
856: my $numrows = 0;
857: if (@types > 0) {
858: $datatable =
859: &usertype_update_row($settings,$usertypes,\%fieldtitles,
860: \@fields,\@types,\$numrows);
861: }
862: $datatable .=
863: &usertype_update_row($settings,{'default' => $othertitle},
864: \%fieldtitles,\@fields,['default'],
865: \$numrows);
866: }
867: return $datatable;
868: }
869:
870: sub usertype_update_row {
871: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
872: my $datatable;
873: my $numinrow = 4;
874: foreach my $type (@{$types}) {
875: if (defined($usertypes->{$type})) {
876: $$rownums ++;
877: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
878: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
879: '</td><td class="LC_left_item"><table>';
880: for (my $i=0; $i<@{$fields}; $i++) {
881: my $rem = $i%($numinrow);
882: if ($rem == 0) {
883: if ($i > 0) {
884: $datatable .= '</tr>';
885: }
886: $datatable .= '<tr>';
887: }
888: my $check = ' ';
889: if (ref($settings->{'fields'}) eq 'HASH') {
890: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
891: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
892: $check = ' checked="checked" ';
893: }
894: }
895: }
896:
897: if ($i == @{$fields}-1) {
898: my $colsleft = $numinrow - $rem;
899: if ($colsleft > 1) {
900: $datatable .= '<td colspan="'.$colsleft.'">';
901: } else {
902: $datatable .= '<td>';
903: }
904: } else {
905: $datatable .= '<td>';
906: }
1.8 raeburn 907: $datatable .= '<span class="LC_nobreak"><label>'.
908: '<input type="checkbox" name="updateable_'.$type.
909: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
910: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 911: }
912: $datatable .= '</tr></table></td></tr>';
913: }
914: }
915: return $datatable;
1.1 raeburn 916: }
917:
918: sub modify_login {
1.9 raeburn 919: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 920: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 921: my %title = ( coursecatalog => 'Display course catalog',
922: adminmail => 'Display administrator E-mail address');
1.3 raeburn 923: my @offon = ('off','on');
1.6 raeburn 924: my %loginhash;
1.9 raeburn 925: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
926: \%domconfig,\%loginhash);
1.6 raeburn 927: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
928: $loginhash{login}{adminmail} = $env{'form.adminmail'};
929: if (ref($colchanges{'login'}) eq 'HASH') {
930: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
931: \%loginhash);
932: }
1.1 raeburn 933: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
934: $dom);
935: if ($putresult eq 'ok') {
1.3 raeburn 936: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 937: ($env{'form.coursecatalog'} eq '1')) {
938: $changes{'coursecatalog'} = 1;
1.3 raeburn 939: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
940: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 941: ($env{'form.coursecatalog'} eq '0')) {
942: $changes{'coursecatalog'} = 1;
943: }
1.3 raeburn 944: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 945: ($env{'form.adminmail'} eq '0')) {
946: $changes{'adminmail'} = 1;
947: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
948: $domconfig{'login'}{'adminmail'} eq '0') &&
949: ($env{'form.adminmail'} eq '1')) {
950: $changes{'adminmail'} = 1;
951: }
1.6 raeburn 952: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 953: $resulttext = &mt('Changes made:').'<ul>';
954: foreach my $item (sort(keys(%changes))) {
955: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
956: }
1.6 raeburn 957: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 958: } else {
959: $resulttext = &mt('No changes made to log-in page settings');
960: }
961: } else {
1.11 albertel 962: $resulttext = '<span class="LC_error">'.
963: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 964: }
1.6 raeburn 965: if ($errors) {
1.9 raeburn 966: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 967: $errors.'</ul>';
968: }
969: return $resulttext;
970: }
971:
972: sub color_font_choices {
973: my %choices =
974: &Apache::lonlocal::texthash (
975: img => "Header",
976: bgs => "Background colors",
977: links => "Link colors",
978: font => "Font color",
979: pgbg => "Page",
980: tabbg => "Header",
981: sidebg => "Border",
982: link => "Link",
983: alink => "Active link",
984: vlink => "Visited link",
985: );
986: return %choices;
987: }
988:
989: sub modify_rolecolors {
1.9 raeburn 990: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 991: my ($resulttext,%rolehash);
992: $rolehash{'rolecolors'} = {};
1.9 raeburn 993: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 994: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
995: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
996: $dom);
997: if ($putresult eq 'ok') {
998: if (keys(%changes) > 0) {
999: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1000: $rolehash{'rolecolors'});
1001: } else {
1002: $resulttext = &mt('No changes made to default color schemes');
1003: }
1004: } else {
1.11 albertel 1005: $resulttext = '<span class="LC_error">'.
1006: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1007: }
1008: if ($errors) {
1009: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1010: $errors.'</ul>';
1011: }
1012: return $resulttext;
1013: }
1014:
1015: sub modify_colors {
1.9 raeburn 1016: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1017: my (%changes,%choices);
1.6 raeburn 1018: my @bgs = ('pgbg','mainbg','sidebg');
1019: my @links = ('link','alink','vlink');
1020: my @images;
1021: my $servadm = $r->dir_config('lonAdmEMail');
1022: my $errors;
1023: foreach my $role (@{$roles}) {
1024: if ($role eq 'login') {
1.12 raeburn 1025: %choices = &login_choices();
1026: } else {
1027: %choices = &color_font_choices();
1028: }
1029: if ($role eq 'login') {
1.6 raeburn 1030: @images = ('img','logo','domlogo');
1031: } else {
1032: @images = ('img');
1033: }
1034: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1035: foreach my $item (@bgs,@links) {
1036: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1037: }
1.9 raeburn 1038: my ($configuserok,$author_ok,$switchserver,%currroles);
1039: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1040: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1041: $confname,$servadm);
1042: if ($configuserok eq 'ok') {
1043: $switchserver = &check_switchserver($dom,$confname);
1044: if ($switchserver eq '') {
1045: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1046: }
1047: }
1048: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1049: foreach my $img (@images) {
1.6 raeburn 1050: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1051: my $error;
1.6 raeburn 1052: if ($configuserok eq 'ok') {
1.9 raeburn 1053: if ($switchserver) {
1.12 raeburn 1054: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1055: } else {
1056: if ($author_ok eq 'ok') {
1057: my ($result,$logourl) =
1058: &publishlogo($r,'upload',$role.'_'.$img,
1059: $dom,$confname,$img,$width,$height);
1060: if ($result eq 'ok') {
1061: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1062: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1063: } else {
1.12 raeburn 1064: $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 1065: }
1066: } else {
1.12 raeburn 1067: $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 1068: }
1069: }
1070: } else {
1.12 raeburn 1071: $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 1072: }
1073: if ($error) {
1.8 raeburn 1074: &Apache::lonnet::logthis($error);
1.11 albertel 1075: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1076: }
1077: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1078: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1079: my $error;
1080: if ($configuserok eq 'ok') {
1081: # is confname an author?
1082: if ($switchserver eq '') {
1083: if ($author_ok eq 'ok') {
1084: my ($result,$logourl) =
1085: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1086: $dom,$confname,$img,$width,$height);
1087: if ($result eq 'ok') {
1088: $confhash->{$role}{$img} = $logourl;
1089: }
1090: }
1091: }
1092: }
1.6 raeburn 1093: }
1094: }
1095: }
1096: if (ref($domconfig) eq 'HASH') {
1097: if (ref($domconfig->{$role}) eq 'HASH') {
1098: foreach my $img (@images) {
1099: if ($domconfig->{$role}{$img} ne '') {
1100: if ($env{'form.'.$role.'_del_'.$img}) {
1101: $confhash->{$role}{$img} = '';
1.12 raeburn 1102: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1103: } else {
1.9 raeburn 1104: if ($confhash->{$role}{$img} eq '') {
1105: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1106: }
1.6 raeburn 1107: }
1108: } else {
1109: if ($env{'form.'.$role.'_del_'.$img}) {
1110: $confhash->{$role}{$img} = '';
1.12 raeburn 1111: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1112: }
1113: }
1114: }
1115: if ($domconfig->{$role}{'font'} ne '') {
1116: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1117: $changes{$role}{'font'} = 1;
1118: }
1119: } else {
1120: if ($confhash->{$role}{'font'}) {
1121: $changes{$role}{'font'} = 1;
1122: }
1123: }
1124: foreach my $item (@bgs) {
1125: if ($domconfig->{$role}{$item} ne '') {
1126: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1127: $changes{$role}{'bgs'}{$item} = 1;
1128: }
1129: } else {
1130: if ($confhash->{$role}{$item}) {
1131: $changes{$role}{'bgs'}{$item} = 1;
1132: }
1133: }
1134: }
1135: foreach my $item (@links) {
1136: if ($domconfig->{$role}{$item} ne '') {
1137: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1138: $changes{$role}{'links'}{$item} = 1;
1139: }
1140: } else {
1141: if ($confhash->{$role}{$item}) {
1142: $changes{$role}{'links'}{$item} = 1;
1143: }
1144: }
1145: }
1146: } else {
1147: &default_change_checker($role,\@images,\@links,\@bgs,
1148: $confhash,\%changes);
1149: }
1150: } else {
1151: &default_change_checker($role,\@images,\@links,\@bgs,
1152: $confhash,\%changes);
1153: }
1154: }
1155: return ($errors,%changes);
1156: }
1157:
1158: sub default_change_checker {
1159: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1160: foreach my $item (@{$links}) {
1161: if ($confhash->{$role}{$item}) {
1162: $changes->{$role}{'links'}{$item} = 1;
1163: }
1164: }
1165: foreach my $item (@{$bgs}) {
1166: if ($confhash->{$role}{$item}) {
1167: $changes->{$role}{'bgs'}{$item} = 1;
1168: }
1169: }
1170: foreach my $img (@{$images}) {
1171: if ($env{'form.'.$role.'_del_'.$img}) {
1172: $confhash->{$role}{$img} = '';
1.12 raeburn 1173: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1174: }
1175: }
1176: if ($confhash->{$role}{'font'}) {
1177: $changes->{$role}{'font'} = 1;
1178: }
1179: }
1180:
1181: sub display_colorchgs {
1182: my ($dom,$changes,$roles,$confhash) = @_;
1183: my (%choices,$resulttext);
1.7 albertel 1184: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1185: if (!grep(/^login$/,@{$roles})) {
1186: $resulttext = &mt('Changes made:').'<br />';
1187: }
1188: foreach my $role (@{$roles}) {
1189: if ($role eq 'login') {
1190: %choices = &login_choices();
1191: } else {
1192: %choices = &color_font_choices();
1193: }
1194: if (ref($changes->{$role}) eq 'HASH') {
1195: if ($role ne 'login') {
1196: $resulttext .= '<h4>'.&mt($role).'</h4>';
1197: }
1198: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1199: if ($role ne 'login') {
1200: $resulttext .= '<ul>';
1201: }
1202: if (ref($changes->{$role}{$key}) eq 'HASH') {
1203: if ($role ne 'login') {
1204: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1205: }
1206: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1207: if ($confhash->{$role}{$item} eq '') {
1208: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1209: } else {
1.12 raeburn 1210: my $newitem = $confhash->{$role}{$item};
1211: if ($key eq 'images') {
1212: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
1213: }
1214: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1215: }
1216: }
1217: if ($role ne 'login') {
1218: $resulttext .= '</ul></li>';
1219: }
1220: } else {
1221: if ($confhash->{$role}{$key} eq '') {
1222: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1223: } else {
1224: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1225: }
1226: }
1227: if ($role ne 'login') {
1228: $resulttext .= '</ul>';
1229: }
1230: }
1231: }
1232: }
1.3 raeburn 1233: return $resulttext;
1.1 raeburn 1234: }
1235:
1.9 raeburn 1236: sub thumb_dimensions {
1237: return ('200','50');
1238: }
1239:
1240: sub check_configuser {
1241: my ($uhome,$dom,$confname,$servadm) = @_;
1242: my ($configuserok,%currroles);
1243: if ($uhome eq 'no_host') {
1244: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1245: my $configpass = &LONCAPA::Enrollment::create_password();
1246: $configuserok =
1247: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1248: $configpass,'','','','','',undef,$servadm);
1249: } else {
1250: $configuserok = 'ok';
1251: %currroles =
1252: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1253: }
1254: return ($configuserok,%currroles);
1255: }
1256:
1257: sub check_authorstatus {
1258: my ($dom,$confname,%currroles) = @_;
1259: my $author_ok;
1260: if (!$currroles{':'.$dom.':au'}) {
1261: my $start = time;
1262: my $end = 0;
1263: $author_ok =
1264: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1265: 'au',$end,$start);
1266: } else {
1267: $author_ok = 'ok';
1268: }
1269: return $author_ok;
1270: }
1271:
1272: sub publishlogo {
1273: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1274: my ($output,$fname,$logourl);
1275: if ($action eq 'upload') {
1276: $fname=$env{'form.'.$formname.'.filename'};
1277: chop($env{'form.'.$formname});
1278: } else {
1279: ($fname) = ($formname =~ /([^\/]+)$/);
1280: }
1281: $fname=&Apache::lonnet::clean_filename($fname);
1282: # See if there is anything left
1283: unless ($fname) { return ('error: no uploaded file'); }
1284: $fname="$subdir/$fname";
1285: my $filepath='/home/'.$confname.'/public_html';
1286: my ($fnamepath,$file,$fetchthumb);
1287: $file=$fname;
1288: if ($fname=~m|/|) {
1289: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1290: }
1291: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1292: my $count;
1293: for ($count=4;$count<=$#parts;$count++) {
1294: $filepath.="/$parts[$count]";
1295: if ((-e $filepath)!=1) {
1296: mkdir($filepath,02770);
1297: }
1298: }
1299: # Check for bad extension and disallow upload
1300: if ($file=~/\.(\w+)$/ &&
1301: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1302: $output =
1303: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
1304: } elsif ($file=~/\.(\w+)$/ &&
1305: !defined(&Apache::loncommon::fileembstyle($1))) {
1306: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1307: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1308: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1309: } elsif (-d "$filepath/$file") {
1310: $output = &mt('File name is a directory name - rename the file and re-upload');
1311: } else {
1312: my $source = $filepath.'/'.$file;
1313: my $logfile;
1314: if (!open($logfile,">>$source".'.log')) {
1315: return (&mt('No write permission to Construction Space'));
1316: }
1317: print $logfile
1318: "\n================= Publish ".localtime()." ================\n".
1319: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1320: # Save the file
1321: if (!open(FH,'>'.$source)) {
1322: &Apache::lonnet::logthis('Failed to create '.$source);
1323: return (&mt('Failed to create file'));
1324: }
1325: if ($action eq 'upload') {
1326: if (!print FH ($env{'form.'.$formname})) {
1327: &Apache::lonnet::logthis('Failed to write to '.$source);
1328: return (&mt('Failed to write file'));
1329: }
1330: } else {
1331: my $original = &Apache::lonnet::filelocation('',$formname);
1332: if(!copy($original,$source)) {
1333: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1334: return (&mt('Failed to write file'));
1335: }
1336: }
1337: close(FH);
1338: chmod(0660, $source); # Permissions to rw-rw---.
1339:
1340: my $docroot=$r->dir_config('lonDocRoot');
1341: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1342: my $copyfile=$targetdir.'/'.$file;
1343:
1344: my @parts=split(/\//,$targetdir);
1345: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1346: for (my $count=5;$count<=$#parts;$count++) {
1347: $path.="/$parts[$count]";
1348: if (!-e $path) {
1349: print $logfile "\nCreating directory ".$path;
1350: mkdir($path,02770);
1351: }
1352: }
1353: my $versionresult;
1354: if (-e $copyfile) {
1355: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1356: } else {
1357: $versionresult = 'ok';
1358: }
1359: if ($versionresult eq 'ok') {
1360: if (copy($source,$copyfile)) {
1361: print $logfile "\nCopied original source to ".$copyfile."\n";
1362: $output = 'ok';
1363: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1364: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1365: } else {
1366: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1367: $output = &mt('Failed to copy file to RES space').", $!";
1368: }
1369: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1370: my $inputfile = $filepath.'/'.$file;
1371: my $outfile = $filepath.'/'.'tn-'.$file;
1372: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1373: system("convert -sample $thumbsize $inputfile $outfile");
1374: chmod(0660, $filepath.'/tn-'.$file);
1375: if (-e $outfile) {
1376: my $copyfile=$targetdir.'/tn-'.$file;
1377: if (copy($outfile,$copyfile)) {
1378: print $logfile "\nCopied source to ".$copyfile."\n";
1379: &write_metadata($dom,$confname,$formname,$targetdir,
1380: 'tn-'.$file,$logfile);
1381: } else {
1382: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1383: }
1384: }
1385: }
1386: } else {
1387: $output = $versionresult;
1388: }
1389: }
1390: return ($output,$logourl);
1391: }
1392:
1393: sub logo_versioning {
1394: my ($targetdir,$file,$logfile) = @_;
1395: my $target = $targetdir.'/'.$file;
1396: my ($maxversion,$fn,$extn,$output);
1397: $maxversion = 0;
1398: if ($file =~ /^(.+)\.(\w+)$/) {
1399: $fn=$1;
1400: $extn=$2;
1401: }
1402: opendir(DIR,$targetdir);
1403: while (my $filename=readdir(DIR)) {
1404: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1405: $maxversion=($1>$maxversion)?$1:$maxversion;
1406: }
1407: }
1408: $maxversion++;
1409: print $logfile "\nCreating old version ".$maxversion."\n";
1410: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1411: if (copy($target,$copyfile)) {
1412: print $logfile "Copied old target to ".$copyfile."\n";
1413: $copyfile=$copyfile.'.meta';
1414: if (copy($target.'.meta',$copyfile)) {
1415: print $logfile "Copied old target metadata to ".$copyfile."\n";
1416: $output = 'ok';
1417: } else {
1418: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1419: $output = &mt('Failed to copy old meta').", $!, ";
1420: }
1421: } else {
1422: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1423: $output = &mt('Failed to copy old target').", $!, ";
1424: }
1425: return $output;
1426: }
1427:
1428: sub write_metadata {
1429: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1430: my (%metadatafields,%metadatakeys,$output);
1431: $metadatafields{'title'}=$formname;
1432: $metadatafields{'creationdate'}=time;
1433: $metadatafields{'lastrevisiondate'}=time;
1434: $metadatafields{'copyright'}='public';
1435: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1436: $env{'user.domain'};
1437: $metadatafields{'authorspace'}=$confname.':'.$dom;
1438: $metadatafields{'domain'}=$dom;
1439: {
1440: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1441: my $mfh;
1442: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1443: $output = &mt('Could not write metadata');
1444: }
1445: foreach (sort keys %metadatafields) {
1446: unless ($_=~/\./) {
1447: my $unikey=$_;
1448: $unikey=~/^([A-Za-z]+)/;
1449: my $tag=$1;
1450: $tag=~tr/A-Z/a-z/;
1451: print $mfh "\n\<$tag";
1452: foreach (split(/\,/,$metadatakeys{$unikey})) {
1453: my $value=$metadatafields{$unikey.'.'.$_};
1454: $value=~s/\"/\'\'/g;
1455: print $mfh ' '.$_.'="'.$value.'"';
1456: }
1457: print $mfh '>'.
1458: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1459: .'</'.$tag.'>';
1460: }
1461: }
1462: $output = 'ok';
1463: print $logfile "\nWrote metadata";
1464: close($mfh);
1465: }
1466: }
1467:
1468: sub check_switchserver {
1469: my ($dom,$confname) = @_;
1470: my ($allowed,$switchserver);
1471: my $home = &Apache::lonnet::homeserver($confname,$dom);
1472: if ($home eq 'no_host') {
1473: $home = &Apache::lonnet::domain($dom,'primary');
1474: }
1475: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 1476: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1477: if (!$allowed) {
1478: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 1479: }
1480: return $switchserver;
1481: }
1482:
1.1 raeburn 1483: sub modify_quotas {
1.3 raeburn 1484: my ($dom,%domconfig) = @_;
1.1 raeburn 1485: my ($resulttext,%changes);
1.3 raeburn 1486: my ($usertypes,$order) =
1487: &Apache::lonnet::retrieve_inst_usertypes($dom);
1.1 raeburn 1488: my %formhash;
1489: foreach my $key (keys(%env)) {
1490: if ($key =~ /^form\.quota_(.+)$/) {
1491: $formhash{$1} = $env{$key};
1492: }
1493: }
1494: if (ref($domconfig{'quotas'}) eq 'HASH') {
1495: foreach my $key (keys(%{$domconfig{'quotas'}})) {
1496: if (exists($formhash{$key})) {
1497: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
1498: $changes{$key} = 1;
1499: }
1500: } else {
1501: $formhash{$key} = $domconfig{'quotas'}{$key};
1502: }
1503: }
1504: }
1505: foreach my $key (keys(%formhash)) {
1506: if ($formhash{$key} ne '') {
1.3 raeburn 1507: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 1508: $changes{$key} = 1;
1509: }
1510: }
1511: }
1512: my %quotahash = (
1.3 raeburn 1513: quotas => {%formhash},
1.1 raeburn 1514: );
1515: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
1516: $dom);
1517: if ($putresult eq 'ok') {
1518: if (keys(%changes) > 0) {
1519: $resulttext = &mt('Changes made:').'<ul>';
1520: foreach my $item (sort(keys(%changes))) {
1521: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
1522: }
1523: $resulttext .= '</ul>';
1524: } else {
1525: $resulttext = &mt('No changes made to default quotas');
1526: }
1527: } else {
1.11 albertel 1528: $resulttext = '<span class="LC_error">'.
1529: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1530: }
1.3 raeburn 1531: return $resulttext;
1.1 raeburn 1532: }
1533:
1.3 raeburn 1534: sub modify_autoenroll {
1535: my ($dom,%domconfig) = @_;
1.1 raeburn 1536: my ($resulttext,%changes);
1537: my %currautoenroll;
1538: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1539: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
1540: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
1541: }
1542: }
1543: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1544: my %title = ( run => 'Auto-enrollment active',
1545: sender => 'Sender for notification messages');
1546: my @offon = ('off','on');
1547: my %autoenrollhash = (
1548: autoenroll => { run => $env{'form.autoenroll_run'},
1549: sender_uname => $env{'form.sender_uname'},
1550: sender_domain => $env{'form.sender_domain'},
1551:
1552: }
1553: );
1.4 raeburn 1554: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
1555: $dom);
1.1 raeburn 1556: if ($putresult eq 'ok') {
1557: if (exists($currautoenroll{'run'})) {
1558: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
1559: $changes{'run'} = 1;
1560: }
1561: } elsif ($autorun) {
1562: if ($env{'form.autoenroll_run'} ne '1') {
1563: $changes{'run'} = 1;
1564: }
1565: }
1566: if (exists($currautoenroll{sender_uname})) {
1567: if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
1568: $changes{'sender'} = 1;
1569: }
1570: } else {
1571: $changes{'sender'} = 1;
1572: }
1573: if (exists($currautoenroll{sender_domain})) {
1574: if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
1575: $changes{'sender'} = 1;
1576: }
1577: } else {
1578: $changes{'sender'} = 1;
1579: }
1580: if (keys(%changes) > 0) {
1581: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 1582: if ($changes{'run'}) {
1.1 raeburn 1583: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
1584: }
1585: if ($changes{'sender'}) {
1586: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
1587: }
1588: $resulttext .= '</ul>';
1589: } else {
1590: $resulttext = &mt('No changes made to auto-enrollment settings');
1591: }
1592: } else {
1.11 albertel 1593: $resulttext = '<span class="LC_error">'.
1594: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1595: }
1.3 raeburn 1596: return $resulttext;
1.1 raeburn 1597: }
1598:
1599: sub modify_autoupdate {
1.3 raeburn 1600: my ($dom,%domconfig) = @_;
1.1 raeburn 1601: my ($resulttext,%currautoupdate,%fields,%changes);
1602: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
1603: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
1604: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
1605: }
1606: }
1607: my @offon = ('off','on');
1608: my %title = &Apache::lonlocal::texthash (
1609: run => 'Auto-update:',
1610: classlists => 'Updates to user information in classlists?'
1611: );
1612: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1613: my %fieldtitles = &Apache::lonlocal::texthash (
1614: id => 'Student/Employee ID',
1615: email => 'E-mail address',
1616: lastname => 'Last Name',
1617: firstname => 'First Name',
1618: middlename => 'Middle Name',
1619: gen => 'Generation',
1620: );
1621: my $othertitle = &mt('All users');
1622: if (keys(%{$usertypes}) > 0) {
1623: $othertitle = "Other users";
1624: }
1625: foreach my $key (keys(%env)) {
1626: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1627: push(@{$fields{$1}},$2);
1628: }
1629: }
1630: my %updatehash = (
1631: autoupdate => { run => $env{'form.autoupdate_run'},
1632: classlists => $env{'form.classlists'},
1633: fields => {%fields},
1634: }
1635: );
1636: foreach my $key (keys(%currautoupdate)) {
1637: if (($key eq 'run') || ($key eq 'classlists')) {
1638: if (exists($updatehash{autoupdate}{$key})) {
1639: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
1640: $changes{$key} = 1;
1641: }
1642: }
1643: } elsif ($key eq 'fields') {
1644: if (ref($currautoupdate{$key}) eq 'HASH') {
1645: foreach my $item (keys(%{$currautoupdate{$key}})) {
1646: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
1647: my $change = 0;
1648: foreach my $type (@{$currautoupdate{$key}{$item}}) {
1649: if (!exists($fields{$item})) {
1650: $change = 1;
1651: } elsif (ref($fields{$item}) eq 'ARRAY') {
1652: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
1653: $change = 1;
1654: }
1655: }
1656: }
1657: if ($change) {
1658: push(@{$changes{$key}},$item);
1659: }
1660: }
1661: }
1662: }
1663: }
1664: }
1665: foreach my $key (keys(%fields)) {
1666: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1667: if (!exists($currautoupdate{'fields'}{$key})) {
1668: push(@{$changes{'fields'}},$key);
1669: }
1670: } else {
1671: push(@{$changes{'fields'}},$key);
1672: }
1673: }
1674: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
1675: $dom);
1676: if ($putresult eq 'ok') {
1677: if (keys(%changes) > 0) {
1678: $resulttext = &mt('Changes made:').'<ul>';
1679: foreach my $key (sort(keys(%changes))) {
1680: if (ref($changes{$key}) eq 'ARRAY') {
1681: foreach my $item (@{$changes{$key}}) {
1682: my @newvalues;
1683: foreach my $type (@{$fields{$item}}) {
1684: push(@newvalues,$fieldtitles{$type});
1685: }
1.3 raeburn 1686: my $newvaluestr;
1687: if (@newvalues > 0) {
1688: $newvaluestr = join(', ',@newvalues);
1689: } else {
1690: $newvaluestr = &mt('none');
1.6 raeburn 1691: }
1.1 raeburn 1692: if ($item eq 'default') {
1693: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
1694: } else {
1695: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
1696: }
1697: }
1698: } else {
1699: my $newvalue;
1700: if ($key eq 'run') {
1701: $newvalue = $offon[$env{'form.autoupdate_run'}];
1702: } else {
1703: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 1704: }
1.1 raeburn 1705: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
1706: }
1707: }
1708: $resulttext .= '</ul>';
1709: } else {
1.3 raeburn 1710: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 1711: }
1712: } else {
1.11 albertel 1713: $resulttext = '<span class="LC_error">'.
1714: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1715: }
1.3 raeburn 1716: return $resulttext;
1.1 raeburn 1717: }
1718:
1.3 raeburn 1719: 1;
1.1 raeburn 1720:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>