Annotation of loncom/interface/domainprefs.pm, revision 1.16
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.16 ! raeburn 4: # $Id: domainprefs.pm,v 1.15 2007/05/27 16:31:54 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: package Apache::domainprefs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::lonnet;
36: use Apache::loncommon();
37: use Apache::lonhtmlcommon();
38: use Apache::lonlocal;
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/[^/]+)/([^/]+)$-) {
1.16 ! raeburn 553: $showfile = $imgfile;
1.6 raeburn 554: my $imgdir = $1;
555: my $filename = $2;
556: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
557: $showfile = "/$imgdir/tn-".$filename;
558: } else {
559: my $input = "/home/httpd/html".$imgfile;
560: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
561: if (!-e $output) {
1.9 raeburn 562: my ($width,$height) = &thumb_dimensions();
1.16 ! raeburn 563: my ($fullwidth,$fullheight) = &check_dimensions($input);
! 564: if ($fullwidth ne '' && $fullheight ne '') {
! 565: if ($fullwidth > $width && $fullheight > $height) {
! 566: my $size = $width.'x'.$height;
! 567: system("convert -sample $size $input $output");
! 568: $showfile = '/'.$imgdir.'/tn-'.$filename;
! 569: }
! 570: }
1.6 raeburn 571: }
572: }
1.16 ! raeburn 573: }
1.6 raeburn 574: if ($showfile) {
1.9 raeburn 575: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
576: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1.6 raeburn 577: $datatable.= '<td>';
578: if (!$is_custom->{$img}) {
579: $datatable .= &mt('Default in use:').'<br />';
580: }
1.9 raeburn 581: $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
582: $showfile.'" alt="'.$alt_text->{$img}.
583: '" border="0" /></a></td>';
1.6 raeburn 584: if ($is_custom->{$img}) {
1.8 raeburn 585: $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
586: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
587: '</label> '.&mt('Replace:').'</span><br />';
1.6 raeburn 588: } else {
589: $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
590: }
591: } else {
592: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
593: &mt('Upload:');
594: }
595: } else {
596: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
597: &mt('Upload:');
598: }
1.9 raeburn 599: if ($switchserver) {
600: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
601: } else {
602: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
603: }
604: $datatable .= '</td></tr>';
1.6 raeburn 605: }
606: $itemcount ++;
607: $css_class = $itemcount%2?' class="LC_odd_row"':'';
608: $datatable .= '<tr'.$css_class.'>'.
609: '<td>'.$choices->{'bgs'}.'</td>';
610: my $bgs_def;
611: foreach my $item (@{$bgs}) {
612: if (!$is_custom->{$item}) {
613: $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
614: }
615: }
616: if ($bgs_def) {
1.8 raeburn 617: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 618: } else {
619: $datatable .= '<td> </td>';
620: }
621: $datatable .= '<td class="LC_right_item">'.
622: '<table border="0"><tr>';
623: foreach my $item (@{$bgs}) {
624: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
625: $datatable .= '<td align="center">'.$link;
626: if ($designs->{'bgs'}{$item}) {
627: $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px"> </span>';
628: }
629: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
630: '" /></td>';
631: }
632: $datatable .= '</tr></table></td></tr>';
633: $itemcount ++;
634: $css_class = $itemcount%2?' class="LC_odd_row"':'';
635: $datatable .= '<tr'.$css_class.'>'.
636: '<td>'.$choices->{'links'}.'</td>';
637: my $links_def;
638: foreach my $item (@{$links}) {
639: if (!$is_custom->{$item}) {
640: $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
641: }
642: }
643: if ($links_def) {
1.8 raeburn 644: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 645: } else {
646: $datatable .= '<td> </td>';
647: }
648: $datatable .= '<td class="LC_right_item">'.
649: '<table border="0"><tr>';
650: foreach my $item (@{$links}) {
651: $datatable .= '<td align="center">';
652: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
653: if ($designs->{'links'}{$item}) {
654: $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
655: $link.'</span>';
656: } else {
657: $datatable .= $link;
658: }
659: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
660: '" /></td>';
661: }
1.3 raeburn 662: return $datatable;
663: }
664:
1.6 raeburn 665: sub color_pick {
666: my ($phase,$role,$item,$desc,$curcol) = @_;
667: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
668: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
669: ');">'.$desc.'</a>';
670: return $link;
671: }
672:
673: sub color_pick_js {
674: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
675: my $output = <<"ENDCOL";
676: function pclose() {
677: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
678: parmwin.close();
679: }
680:
681: $pjump_def
682:
683: function psub() {
684: pclose();
685: if (document.parmform.pres_marker.value!='') {
686: if (document.parmform.pres_type.value!='') {
687: eval('document.display.'+
688: document.parmform.pres_marker.value+
689: '.value=document.parmform.pres_value.value;');
690: }
691: } else {
692: document.parmform.pres_value.value='';
693: document.parmform.pres_marker.value='';
694: }
695: }
696: ENDCOL
697: return $output;
698: }
699:
1.3 raeburn 700: sub print_quotas {
701: my ($dom,$settings) = @_;
702: my $datatable;
703: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
704: my $othertitle = "All users";
705: my @types;
706: if (ref($order) eq 'ARRAY') {
707: @types = @{$order};
708: }
709: if (@types == 0) {
710: if (ref($usertypes) eq 'HASH') {
711: @types = sort(keys(%{$usertypes}));
712: }
713: }
714: my $typecount = 0;
715: my $css_class;
716: if (@types > 0) {
717: foreach my $type (@types) {
718: if (defined($usertypes->{$type})) {
719: $typecount ++;
720: $css_class = $typecount%2?' class="LC_odd_row"':'';
721: $datatable .= '<tr'.$css_class.'>'.
722: '<td>'.$usertypes->{$type}.'</td>'.
1.8 raeburn 723: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 724: '<input type="text" name="quota_'.$type.
725: '" value="'.$settings->{$type}.
1.8 raeburn 726: '" size="5" /> Mb</span></td></tr>';
1.3 raeburn 727: }
728: }
729: $othertitle = "Other users";
730: }
731: my $defaultquota = '20';
732: if (ref($settings) eq 'HASH') {
733: if (defined($settings->{'default'})) {
734: $defaultquota = $settings->{'default'};
735: }
736: }
737: $typecount ++;
738: $css_class = $typecount%2?' class="LC_odd_row"':'';
739: $datatable .= '<tr'.$css_class.'>'.
740: '<td>'.&mt($othertitle).'</td>'.
1.8 raeburn 741: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15 raeburn 742: '<input type="text" name="defaultquota" value="'.
1.8 raeburn 743: $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.3 raeburn 744: return $datatable;
745: }
746:
747: sub print_autoenroll {
748: my ($dom,$settings) = @_;
749: my $defdom = $dom;
750: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
751: my ($runon,$runoff);
752: if (ref($settings) eq 'HASH') {
753: if (exists($settings->{'run'})) {
754: if ($settings->{'run'} eq '0') {
755: $runoff = ' checked="checked" ';
756: $runon = ' ';
757: } else {
758: $runon = ' checked="checked" ';
759: $runoff = ' ';
760: }
761: } else {
762: if ($autorun) {
763: $runon = ' checked="checked" ';
764: $runoff = ' ';
765: } else {
766: $runoff = ' checked="checked" ';
767: $runon = ' ';
768: }
769: }
770: if (exists($settings->{'sender_domain'})) {
771: $defdom = $settings->{'sender_domain'};
772: }
1.14 raeburn 773: } else {
774: if ($autorun) {
775: $runon = ' checked="checked" ';
776: $runoff = ' ';
777: } else {
778: $runoff = ' checked="checked" ';
779: $runon = ' ';
780: }
1.3 raeburn 781: }
782: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
783: my $datatable='<tr class="LC_odd_row">'.
784: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 785: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 786: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 787: $runon.' value="1" />'.&mt('Yes').'</label> '.
788: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 789: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 790: '</tr><tr>'.
791: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 792: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 793: &mt('username').': '.
794: '<input type="text" name="sender_uname" value="'.
795: $settings->{'sender_uname'}.
796: '" size="10" /> '.&mt('domain').
1.8 raeburn 797: ': '.$domform.'</span></td></tr>';
1.3 raeburn 798: return $datatable;
799: }
800:
801: sub print_autoupdate {
802: my ($position,$dom,$settings) = @_;
803: my $datatable;
804: if ($position eq 'top') {
805: my $updateon = ' ';
806: my $updateoff = ' checked="checked" ';
807: my $classlistson = ' ';
808: my $classlistsoff = ' checked="checked" ';
809: if (ref($settings) eq 'HASH') {
810: if ($settings->{'run'} eq '1') {
811: $updateon = $updateoff;
812: $updateoff = ' ';
813: }
814: if ($settings->{'classlists'} eq '1') {
815: $classlistson = $classlistsoff;
816: $classlistsoff = ' ';
817: }
818: }
819: my %title = (
820: run => 'Auto-update active?',
821: classlists => 'Update information in classlists?',
822: );
823: $datatable = '<tr class="LC_odd_row">'.
824: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 825: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 826: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 827: $updateon.' value="1" />'.&mt('Yes').'</label> '.
828: '<label><input type="radio" name="autoupdate_run"'.
829: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 830: '</tr><tr>'.
831: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 832: '<td class="LC_right_item"><span class="LC_nobreak">'.
833: '<label><input type="radio" name="classlists"'.
834: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
835: '<label><input type="radio" name="classlists"'.
836: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 837: '</tr>';
838: } else {
839: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
840: my @types;
841: if (ref($order) eq 'ARRAY') {
842: @types = @{$order};
843: }
844: if (@types == 0) {
845: if (ref($usertypes) eq 'HASH') {
846: @types = sort(keys(%{$usertypes}));
847: }
848: }
849: my $othertitle = &mt('All users');
850: if (keys(%{$usertypes}) > 0) {
851: $othertitle = &mt('Other users');
852: }
853: my @fields = ('lastname','firstname','middlename','gen','email','id');
854: my %fieldtitles = &Apache::lonlocal::texthash (
855: id => 'Student/Employee ID',
856: email => 'E-mail address',
857: lastname => 'Last Name',
858: firstname => 'First Name',
859: middlename => 'Middle Name',
860: gen => 'Generation',
861: );
862: my $numrows = 0;
863: if (@types > 0) {
864: $datatable =
865: &usertype_update_row($settings,$usertypes,\%fieldtitles,
866: \@fields,\@types,\$numrows);
867: }
868: $datatable .=
869: &usertype_update_row($settings,{'default' => $othertitle},
870: \%fieldtitles,\@fields,['default'],
871: \$numrows);
872: }
873: return $datatable;
874: }
875:
876: sub usertype_update_row {
877: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
878: my $datatable;
879: my $numinrow = 4;
880: foreach my $type (@{$types}) {
881: if (defined($usertypes->{$type})) {
882: $$rownums ++;
883: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
884: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
885: '</td><td class="LC_left_item"><table>';
886: for (my $i=0; $i<@{$fields}; $i++) {
887: my $rem = $i%($numinrow);
888: if ($rem == 0) {
889: if ($i > 0) {
890: $datatable .= '</tr>';
891: }
892: $datatable .= '<tr>';
893: }
894: my $check = ' ';
895: if (ref($settings->{'fields'}) eq 'HASH') {
896: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
897: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
898: $check = ' checked="checked" ';
899: }
900: }
901: }
902:
903: if ($i == @{$fields}-1) {
904: my $colsleft = $numinrow - $rem;
905: if ($colsleft > 1) {
906: $datatable .= '<td colspan="'.$colsleft.'">';
907: } else {
908: $datatable .= '<td>';
909: }
910: } else {
911: $datatable .= '<td>';
912: }
1.8 raeburn 913: $datatable .= '<span class="LC_nobreak"><label>'.
914: '<input type="checkbox" name="updateable_'.$type.
915: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
916: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 917: }
918: $datatable .= '</tr></table></td></tr>';
919: }
920: }
921: return $datatable;
1.1 raeburn 922: }
923:
924: sub modify_login {
1.9 raeburn 925: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 926: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 927: my %title = ( coursecatalog => 'Display course catalog',
928: adminmail => 'Display administrator E-mail address');
1.3 raeburn 929: my @offon = ('off','on');
1.6 raeburn 930: my %loginhash;
1.9 raeburn 931: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
932: \%domconfig,\%loginhash);
1.6 raeburn 933: $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
934: $loginhash{login}{adminmail} = $env{'form.adminmail'};
935: if (ref($colchanges{'login'}) eq 'HASH') {
936: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
937: \%loginhash);
938: }
1.1 raeburn 939: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
940: $dom);
941: if ($putresult eq 'ok') {
1.3 raeburn 942: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1 raeburn 943: ($env{'form.coursecatalog'} eq '1')) {
944: $changes{'coursecatalog'} = 1;
1.3 raeburn 945: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
946: $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1 raeburn 947: ($env{'form.coursecatalog'} eq '0')) {
948: $changes{'coursecatalog'} = 1;
949: }
1.3 raeburn 950: if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1 raeburn 951: ($env{'form.adminmail'} eq '0')) {
952: $changes{'adminmail'} = 1;
953: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
954: $domconfig{'login'}{'adminmail'} eq '0') &&
955: ($env{'form.adminmail'} eq '1')) {
956: $changes{'adminmail'} = 1;
957: }
1.6 raeburn 958: if (keys(%changes) > 0 || $colchgtext) {
1.1 raeburn 959: $resulttext = &mt('Changes made:').'<ul>';
960: foreach my $item (sort(keys(%changes))) {
961: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
962: }
1.6 raeburn 963: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 964: } else {
965: $resulttext = &mt('No changes made to log-in page settings');
966: }
967: } else {
1.11 albertel 968: $resulttext = '<span class="LC_error">'.
969: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 970: }
1.6 raeburn 971: if ($errors) {
1.9 raeburn 972: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 973: $errors.'</ul>';
974: }
975: return $resulttext;
976: }
977:
978: sub color_font_choices {
979: my %choices =
980: &Apache::lonlocal::texthash (
981: img => "Header",
982: bgs => "Background colors",
983: links => "Link colors",
984: font => "Font color",
985: pgbg => "Page",
986: tabbg => "Header",
987: sidebg => "Border",
988: link => "Link",
989: alink => "Active link",
990: vlink => "Visited link",
991: );
992: return %choices;
993: }
994:
995: sub modify_rolecolors {
1.9 raeburn 996: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 997: my ($resulttext,%rolehash);
998: $rolehash{'rolecolors'} = {};
1.9 raeburn 999: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 1000: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
1001: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
1002: $dom);
1003: if ($putresult eq 'ok') {
1004: if (keys(%changes) > 0) {
1005: $resulttext = &display_colorchgs($dom,\%changes,$roles,
1006: $rolehash{'rolecolors'});
1007: } else {
1008: $resulttext = &mt('No changes made to default color schemes');
1009: }
1010: } else {
1.11 albertel 1011: $resulttext = '<span class="LC_error">'.
1012: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 1013: }
1014: if ($errors) {
1015: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
1016: $errors.'</ul>';
1017: }
1018: return $resulttext;
1019: }
1020:
1021: sub modify_colors {
1.9 raeburn 1022: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 1023: my (%changes,%choices);
1.6 raeburn 1024: my @bgs = ('pgbg','mainbg','sidebg');
1025: my @links = ('link','alink','vlink');
1026: my @images;
1027: my $servadm = $r->dir_config('lonAdmEMail');
1028: my $errors;
1029: foreach my $role (@{$roles}) {
1030: if ($role eq 'login') {
1.12 raeburn 1031: %choices = &login_choices();
1032: } else {
1033: %choices = &color_font_choices();
1034: }
1035: if ($role eq 'login') {
1.6 raeburn 1036: @images = ('img','logo','domlogo');
1037: } else {
1038: @images = ('img');
1039: }
1040: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1041: foreach my $item (@bgs,@links) {
1042: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
1043: }
1.9 raeburn 1044: my ($configuserok,$author_ok,$switchserver,%currroles);
1045: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
1046: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
1047: $confname,$servadm);
1048: if ($configuserok eq 'ok') {
1049: $switchserver = &check_switchserver($dom,$confname);
1050: if ($switchserver eq '') {
1051: $author_ok = &check_authorstatus($dom,$confname,%currroles);
1052: }
1053: }
1054: my ($width,$height) = &thumb_dimensions();
1.8 raeburn 1055: foreach my $img (@images) {
1.6 raeburn 1056: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 1057: my $error;
1.6 raeburn 1058: if ($configuserok eq 'ok') {
1.9 raeburn 1059: if ($switchserver) {
1.12 raeburn 1060: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 1061: } else {
1062: if ($author_ok eq 'ok') {
1063: my ($result,$logourl) =
1064: &publishlogo($r,'upload',$role.'_'.$img,
1065: $dom,$confname,$img,$width,$height);
1066: if ($result eq 'ok') {
1067: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 1068: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 1069: } else {
1.12 raeburn 1070: $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 1071: }
1072: } else {
1.12 raeburn 1073: $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 1074: }
1075: }
1076: } else {
1.12 raeburn 1077: $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 1078: }
1079: if ($error) {
1.8 raeburn 1080: &Apache::lonnet::logthis($error);
1.11 albertel 1081: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 1082: }
1083: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 1084: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1085: my $error;
1086: if ($configuserok eq 'ok') {
1087: # is confname an author?
1088: if ($switchserver eq '') {
1089: if ($author_ok eq 'ok') {
1090: my ($result,$logourl) =
1091: &publishlogo($r,'copy',$domconfig->{$role}{$img},
1092: $dom,$confname,$img,$width,$height);
1093: if ($result eq 'ok') {
1094: $confhash->{$role}{$img} = $logourl;
1095: }
1096: }
1097: }
1098: }
1.6 raeburn 1099: }
1100: }
1101: }
1102: if (ref($domconfig) eq 'HASH') {
1103: if (ref($domconfig->{$role}) eq 'HASH') {
1104: foreach my $img (@images) {
1105: if ($domconfig->{$role}{$img} ne '') {
1106: if ($env{'form.'.$role.'_del_'.$img}) {
1107: $confhash->{$role}{$img} = '';
1.12 raeburn 1108: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1109: } else {
1.9 raeburn 1110: if ($confhash->{$role}{$img} eq '') {
1111: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
1112: }
1.6 raeburn 1113: }
1114: } else {
1115: if ($env{'form.'.$role.'_del_'.$img}) {
1116: $confhash->{$role}{$img} = '';
1.12 raeburn 1117: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 1118: }
1119: }
1120: }
1121: if ($domconfig->{$role}{'font'} ne '') {
1122: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
1123: $changes{$role}{'font'} = 1;
1124: }
1125: } else {
1126: if ($confhash->{$role}{'font'}) {
1127: $changes{$role}{'font'} = 1;
1128: }
1129: }
1130: foreach my $item (@bgs) {
1131: if ($domconfig->{$role}{$item} ne '') {
1132: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1133: $changes{$role}{'bgs'}{$item} = 1;
1134: }
1135: } else {
1136: if ($confhash->{$role}{$item}) {
1137: $changes{$role}{'bgs'}{$item} = 1;
1138: }
1139: }
1140: }
1141: foreach my $item (@links) {
1142: if ($domconfig->{$role}{$item} ne '') {
1143: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
1144: $changes{$role}{'links'}{$item} = 1;
1145: }
1146: } else {
1147: if ($confhash->{$role}{$item}) {
1148: $changes{$role}{'links'}{$item} = 1;
1149: }
1150: }
1151: }
1152: } else {
1153: &default_change_checker($role,\@images,\@links,\@bgs,
1154: $confhash,\%changes);
1155: }
1156: } else {
1157: &default_change_checker($role,\@images,\@links,\@bgs,
1158: $confhash,\%changes);
1159: }
1160: }
1161: return ($errors,%changes);
1162: }
1163:
1164: sub default_change_checker {
1165: my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
1166: foreach my $item (@{$links}) {
1167: if ($confhash->{$role}{$item}) {
1168: $changes->{$role}{'links'}{$item} = 1;
1169: }
1170: }
1171: foreach my $item (@{$bgs}) {
1172: if ($confhash->{$role}{$item}) {
1173: $changes->{$role}{'bgs'}{$item} = 1;
1174: }
1175: }
1176: foreach my $img (@{$images}) {
1177: if ($env{'form.'.$role.'_del_'.$img}) {
1178: $confhash->{$role}{$img} = '';
1.12 raeburn 1179: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 1180: }
1181: }
1182: if ($confhash->{$role}{'font'}) {
1183: $changes->{$role}{'font'} = 1;
1184: }
1185: }
1186:
1187: sub display_colorchgs {
1188: my ($dom,$changes,$roles,$confhash) = @_;
1189: my (%choices,$resulttext);
1.7 albertel 1190: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 1191: if (!grep(/^login$/,@{$roles})) {
1192: $resulttext = &mt('Changes made:').'<br />';
1193: }
1194: foreach my $role (@{$roles}) {
1195: if ($role eq 'login') {
1196: %choices = &login_choices();
1197: } else {
1198: %choices = &color_font_choices();
1199: }
1200: if (ref($changes->{$role}) eq 'HASH') {
1201: if ($role ne 'login') {
1202: $resulttext .= '<h4>'.&mt($role).'</h4>';
1203: }
1204: foreach my $key (sort(keys(%{$changes->{$role}}))) {
1205: if ($role ne 'login') {
1206: $resulttext .= '<ul>';
1207: }
1208: if (ref($changes->{$role}{$key}) eq 'HASH') {
1209: if ($role ne 'login') {
1210: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
1211: }
1212: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1213: if ($confhash->{$role}{$item} eq '') {
1214: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
1215: } else {
1.12 raeburn 1216: my $newitem = $confhash->{$role}{$item};
1217: if ($key eq 'images') {
1218: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
1219: }
1220: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 1221: }
1222: }
1223: if ($role ne 'login') {
1224: $resulttext .= '</ul></li>';
1225: }
1226: } else {
1227: if ($confhash->{$role}{$key} eq '') {
1228: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
1229: } else {
1230: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
1231: }
1232: }
1233: if ($role ne 'login') {
1234: $resulttext .= '</ul>';
1235: }
1236: }
1237: }
1238: }
1.3 raeburn 1239: return $resulttext;
1.1 raeburn 1240: }
1241:
1.9 raeburn 1242: sub thumb_dimensions {
1243: return ('200','50');
1244: }
1245:
1.16 ! raeburn 1246: sub check_dimensions {
! 1247: my ($inputfile) = @_;
! 1248: my ($fullwidth,$fullheight);
! 1249: if ($inputfile =~ m|^[/\w.\-]+$|) {
! 1250: if (open(PIPE,"identify $inputfile 2>&1 |")) {
! 1251: my $imageinfo = <PIPE>;
! 1252: if (!close(PIPE)) {
! 1253: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
! 1254: }
! 1255: chomp($imageinfo);
! 1256: my ($fullsize) =
! 1257: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)\s+/);
! 1258: if ($fullsize) {
! 1259: ($fullwidth,$fullheight) = split(/x/,$fullsize);
! 1260: }
! 1261: }
! 1262: }
! 1263: return ($fullwidth,$fullheight);
! 1264: }
! 1265:
1.9 raeburn 1266: sub check_configuser {
1267: my ($uhome,$dom,$confname,$servadm) = @_;
1268: my ($configuserok,%currroles);
1269: if ($uhome eq 'no_host') {
1270: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1271: my $configpass = &LONCAPA::Enrollment::create_password();
1272: $configuserok =
1273: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
1274: $configpass,'','','','','',undef,$servadm);
1275: } else {
1276: $configuserok = 'ok';
1277: %currroles =
1278: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
1279: }
1280: return ($configuserok,%currroles);
1281: }
1282:
1283: sub check_authorstatus {
1284: my ($dom,$confname,%currroles) = @_;
1285: my $author_ok;
1286: if (!$currroles{':'.$dom.':au'}) {
1287: my $start = time;
1288: my $end = 0;
1289: $author_ok =
1290: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1291: 'au',$end,$start);
1292: } else {
1293: $author_ok = 'ok';
1294: }
1295: return $author_ok;
1296: }
1297:
1298: sub publishlogo {
1299: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
1300: my ($output,$fname,$logourl);
1301: if ($action eq 'upload') {
1302: $fname=$env{'form.'.$formname.'.filename'};
1303: chop($env{'form.'.$formname});
1304: } else {
1305: ($fname) = ($formname =~ /([^\/]+)$/);
1306: }
1307: $fname=&Apache::lonnet::clean_filename($fname);
1308: # See if there is anything left
1309: unless ($fname) { return ('error: no uploaded file'); }
1310: $fname="$subdir/$fname";
1311: my $filepath='/home/'.$confname.'/public_html';
1312: my ($fnamepath,$file,$fetchthumb);
1313: $file=$fname;
1314: if ($fname=~m|/|) {
1315: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1316: }
1317: my @parts=split(/\//,$filepath.'/'.$fnamepath);
1318: my $count;
1319: for ($count=4;$count<=$#parts;$count++) {
1320: $filepath.="/$parts[$count]";
1321: if ((-e $filepath)!=1) {
1322: mkdir($filepath,02770);
1323: }
1324: }
1325: # Check for bad extension and disallow upload
1326: if ($file=~/\.(\w+)$/ &&
1327: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1328: $output =
1329: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
1330: } elsif ($file=~/\.(\w+)$/ &&
1331: !defined(&Apache::loncommon::fileembstyle($1))) {
1332: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1333: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1334: $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1335: } elsif (-d "$filepath/$file") {
1336: $output = &mt('File name is a directory name - rename the file and re-upload');
1337: } else {
1338: my $source = $filepath.'/'.$file;
1339: my $logfile;
1340: if (!open($logfile,">>$source".'.log')) {
1341: return (&mt('No write permission to Construction Space'));
1342: }
1343: print $logfile
1344: "\n================= Publish ".localtime()." ================\n".
1345: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1346: # Save the file
1347: if (!open(FH,'>'.$source)) {
1348: &Apache::lonnet::logthis('Failed to create '.$source);
1349: return (&mt('Failed to create file'));
1350: }
1351: if ($action eq 'upload') {
1352: if (!print FH ($env{'form.'.$formname})) {
1353: &Apache::lonnet::logthis('Failed to write to '.$source);
1354: return (&mt('Failed to write file'));
1355: }
1356: } else {
1357: my $original = &Apache::lonnet::filelocation('',$formname);
1358: if(!copy($original,$source)) {
1359: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1360: return (&mt('Failed to write file'));
1361: }
1362: }
1363: close(FH);
1364: chmod(0660, $source); # Permissions to rw-rw---.
1365:
1366: my $docroot=$r->dir_config('lonDocRoot');
1367: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1368: my $copyfile=$targetdir.'/'.$file;
1369:
1370: my @parts=split(/\//,$targetdir);
1371: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1372: for (my $count=5;$count<=$#parts;$count++) {
1373: $path.="/$parts[$count]";
1374: if (!-e $path) {
1375: print $logfile "\nCreating directory ".$path;
1376: mkdir($path,02770);
1377: }
1378: }
1379: my $versionresult;
1380: if (-e $copyfile) {
1381: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1382: } else {
1383: $versionresult = 'ok';
1384: }
1385: if ($versionresult eq 'ok') {
1386: if (copy($source,$copyfile)) {
1387: print $logfile "\nCopied original source to ".$copyfile."\n";
1388: $output = 'ok';
1389: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1390: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1391: } else {
1392: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1393: $output = &mt('Failed to copy file to RES space').", $!";
1394: }
1395: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1396: my $inputfile = $filepath.'/'.$file;
1397: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 ! raeburn 1398: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
! 1399: if ($fullwidth ne '' && $fullheight ne '') {
! 1400: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
! 1401: my $thumbsize = $thumbwidth.'x'.$thumbheight;
! 1402: system("convert -sample $thumbsize $inputfile $outfile");
! 1403: chmod(0660, $filepath.'/tn-'.$file);
! 1404: if (-e $outfile) {
! 1405: my $copyfile=$targetdir.'/tn-'.$file;
! 1406: if (copy($outfile,$copyfile)) {
! 1407: print $logfile "\nCopied source to ".$copyfile."\n";
! 1408: &write_metadata($dom,$confname,$formname,
! 1409: $targetdir,'tn-'.$file,$logfile);
! 1410: } else {
! 1411: print $logfile "\nUnable to write ".$copyfile.
! 1412: ':'.$!."\n";
! 1413: }
! 1414: }
1.9 raeburn 1415: }
1416: }
1417: }
1418: } else {
1419: $output = $versionresult;
1420: }
1421: }
1422: return ($output,$logourl);
1423: }
1424:
1425: sub logo_versioning {
1426: my ($targetdir,$file,$logfile) = @_;
1427: my $target = $targetdir.'/'.$file;
1428: my ($maxversion,$fn,$extn,$output);
1429: $maxversion = 0;
1430: if ($file =~ /^(.+)\.(\w+)$/) {
1431: $fn=$1;
1432: $extn=$2;
1433: }
1434: opendir(DIR,$targetdir);
1435: while (my $filename=readdir(DIR)) {
1436: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1437: $maxversion=($1>$maxversion)?$1:$maxversion;
1438: }
1439: }
1440: $maxversion++;
1441: print $logfile "\nCreating old version ".$maxversion."\n";
1442: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1443: if (copy($target,$copyfile)) {
1444: print $logfile "Copied old target to ".$copyfile."\n";
1445: $copyfile=$copyfile.'.meta';
1446: if (copy($target.'.meta',$copyfile)) {
1447: print $logfile "Copied old target metadata to ".$copyfile."\n";
1448: $output = 'ok';
1449: } else {
1450: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1451: $output = &mt('Failed to copy old meta').", $!, ";
1452: }
1453: } else {
1454: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1455: $output = &mt('Failed to copy old target').", $!, ";
1456: }
1457: return $output;
1458: }
1459:
1460: sub write_metadata {
1461: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1462: my (%metadatafields,%metadatakeys,$output);
1463: $metadatafields{'title'}=$formname;
1464: $metadatafields{'creationdate'}=time;
1465: $metadatafields{'lastrevisiondate'}=time;
1466: $metadatafields{'copyright'}='public';
1467: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1468: $env{'user.domain'};
1469: $metadatafields{'authorspace'}=$confname.':'.$dom;
1470: $metadatafields{'domain'}=$dom;
1471: {
1472: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1473: my $mfh;
1474: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1475: $output = &mt('Could not write metadata');
1476: }
1477: foreach (sort keys %metadatafields) {
1478: unless ($_=~/\./) {
1479: my $unikey=$_;
1480: $unikey=~/^([A-Za-z]+)/;
1481: my $tag=$1;
1482: $tag=~tr/A-Z/a-z/;
1483: print $mfh "\n\<$tag";
1484: foreach (split(/\,/,$metadatakeys{$unikey})) {
1485: my $value=$metadatafields{$unikey.'.'.$_};
1486: $value=~s/\"/\'\'/g;
1487: print $mfh ' '.$_.'="'.$value.'"';
1488: }
1489: print $mfh '>'.
1490: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1491: .'</'.$tag.'>';
1492: }
1493: }
1494: $output = 'ok';
1495: print $logfile "\nWrote metadata";
1496: close($mfh);
1497: }
1498: }
1499:
1500: sub check_switchserver {
1501: my ($dom,$confname) = @_;
1502: my ($allowed,$switchserver);
1503: my $home = &Apache::lonnet::homeserver($confname,$dom);
1504: if ($home eq 'no_host') {
1505: $home = &Apache::lonnet::domain($dom,'primary');
1506: }
1507: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 1508: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1509: if (!$allowed) {
1510: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 1511: }
1512: return $switchserver;
1513: }
1514:
1.1 raeburn 1515: sub modify_quotas {
1.3 raeburn 1516: my ($dom,%domconfig) = @_;
1.1 raeburn 1517: my ($resulttext,%changes);
1.3 raeburn 1518: my ($usertypes,$order) =
1519: &Apache::lonnet::retrieve_inst_usertypes($dom);
1.1 raeburn 1520: my %formhash;
1521: foreach my $key (keys(%env)) {
1522: if ($key =~ /^form\.quota_(.+)$/) {
1523: $formhash{$1} = $env{$key};
1524: }
1525: }
1.15 raeburn 1526: $formhash{'default'} = $env{'form.defaultquota'};
1.1 raeburn 1527: if (ref($domconfig{'quotas'}) eq 'HASH') {
1528: foreach my $key (keys(%{$domconfig{'quotas'}})) {
1529: if (exists($formhash{$key})) {
1530: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
1531: $changes{$key} = 1;
1532: }
1533: } else {
1534: $formhash{$key} = $domconfig{'quotas'}{$key};
1535: }
1536: }
1537: }
1538: foreach my $key (keys(%formhash)) {
1539: if ($formhash{$key} ne '') {
1.3 raeburn 1540: if (!exists($domconfig{'quotas'}{$key})) {
1.1 raeburn 1541: $changes{$key} = 1;
1542: }
1543: }
1544: }
1545: my %quotahash = (
1.3 raeburn 1546: quotas => {%formhash},
1.1 raeburn 1547: );
1548: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
1549: $dom);
1550: if ($putresult eq 'ok') {
1551: if (keys(%changes) > 0) {
1552: $resulttext = &mt('Changes made:').'<ul>';
1553: foreach my $item (sort(keys(%changes))) {
1554: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
1555: }
1556: $resulttext .= '</ul>';
1557: } else {
1558: $resulttext = &mt('No changes made to default quotas');
1559: }
1560: } else {
1.11 albertel 1561: $resulttext = '<span class="LC_error">'.
1562: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1563: }
1.3 raeburn 1564: return $resulttext;
1.1 raeburn 1565: }
1566:
1.3 raeburn 1567: sub modify_autoenroll {
1568: my ($dom,%domconfig) = @_;
1.1 raeburn 1569: my ($resulttext,%changes);
1570: my %currautoenroll;
1571: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
1572: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
1573: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
1574: }
1575: }
1576: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1577: my %title = ( run => 'Auto-enrollment active',
1578: sender => 'Sender for notification messages');
1579: my @offon = ('off','on');
1580: my %autoenrollhash = (
1581: autoenroll => { run => $env{'form.autoenroll_run'},
1582: sender_uname => $env{'form.sender_uname'},
1583: sender_domain => $env{'form.sender_domain'},
1584:
1585: }
1586: );
1.4 raeburn 1587: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
1588: $dom);
1.1 raeburn 1589: if ($putresult eq 'ok') {
1590: if (exists($currautoenroll{'run'})) {
1591: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
1592: $changes{'run'} = 1;
1593: }
1594: } elsif ($autorun) {
1595: if ($env{'form.autoenroll_run'} ne '1') {
1596: $changes{'run'} = 1;
1597: }
1598: }
1599: if (exists($currautoenroll{sender_uname})) {
1600: if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
1601: $changes{'sender'} = 1;
1602: }
1603: } else {
1604: $changes{'sender'} = 1;
1605: }
1606: if (exists($currautoenroll{sender_domain})) {
1607: if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
1608: $changes{'sender'} = 1;
1609: }
1610: } else {
1611: $changes{'sender'} = 1;
1612: }
1613: if (keys(%changes) > 0) {
1614: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 1615: if ($changes{'run'}) {
1.1 raeburn 1616: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
1617: }
1618: if ($changes{'sender'}) {
1619: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
1620: }
1621: $resulttext .= '</ul>';
1622: } else {
1623: $resulttext = &mt('No changes made to auto-enrollment settings');
1624: }
1625: } else {
1.11 albertel 1626: $resulttext = '<span class="LC_error">'.
1627: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1628: }
1.3 raeburn 1629: return $resulttext;
1.1 raeburn 1630: }
1631:
1632: sub modify_autoupdate {
1.3 raeburn 1633: my ($dom,%domconfig) = @_;
1.1 raeburn 1634: my ($resulttext,%currautoupdate,%fields,%changes);
1635: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
1636: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
1637: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
1638: }
1639: }
1640: my @offon = ('off','on');
1641: my %title = &Apache::lonlocal::texthash (
1642: run => 'Auto-update:',
1643: classlists => 'Updates to user information in classlists?'
1644: );
1645: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1646: my %fieldtitles = &Apache::lonlocal::texthash (
1647: id => 'Student/Employee ID',
1648: email => 'E-mail address',
1649: lastname => 'Last Name',
1650: firstname => 'First Name',
1651: middlename => 'Middle Name',
1652: gen => 'Generation',
1653: );
1654: my $othertitle = &mt('All users');
1655: if (keys(%{$usertypes}) > 0) {
1656: $othertitle = "Other users";
1657: }
1658: foreach my $key (keys(%env)) {
1659: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1660: push(@{$fields{$1}},$2);
1661: }
1662: }
1663: my %updatehash = (
1664: autoupdate => { run => $env{'form.autoupdate_run'},
1665: classlists => $env{'form.classlists'},
1666: fields => {%fields},
1667: }
1668: );
1669: foreach my $key (keys(%currautoupdate)) {
1670: if (($key eq 'run') || ($key eq 'classlists')) {
1671: if (exists($updatehash{autoupdate}{$key})) {
1672: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
1673: $changes{$key} = 1;
1674: }
1675: }
1676: } elsif ($key eq 'fields') {
1677: if (ref($currautoupdate{$key}) eq 'HASH') {
1678: foreach my $item (keys(%{$currautoupdate{$key}})) {
1679: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
1680: my $change = 0;
1681: foreach my $type (@{$currautoupdate{$key}{$item}}) {
1682: if (!exists($fields{$item})) {
1683: $change = 1;
1684: } elsif (ref($fields{$item}) eq 'ARRAY') {
1685: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
1686: $change = 1;
1687: }
1688: }
1689: }
1690: if ($change) {
1691: push(@{$changes{$key}},$item);
1692: }
1693: }
1694: }
1695: }
1696: }
1697: }
1698: foreach my $key (keys(%fields)) {
1699: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1700: if (!exists($currautoupdate{'fields'}{$key})) {
1701: push(@{$changes{'fields'}},$key);
1702: }
1703: } else {
1704: push(@{$changes{'fields'}},$key);
1705: }
1706: }
1707: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
1708: $dom);
1709: if ($putresult eq 'ok') {
1710: if (keys(%changes) > 0) {
1711: $resulttext = &mt('Changes made:').'<ul>';
1712: foreach my $key (sort(keys(%changes))) {
1713: if (ref($changes{$key}) eq 'ARRAY') {
1714: foreach my $item (@{$changes{$key}}) {
1715: my @newvalues;
1716: foreach my $type (@{$fields{$item}}) {
1717: push(@newvalues,$fieldtitles{$type});
1718: }
1.3 raeburn 1719: my $newvaluestr;
1720: if (@newvalues > 0) {
1721: $newvaluestr = join(', ',@newvalues);
1722: } else {
1723: $newvaluestr = &mt('none');
1.6 raeburn 1724: }
1.1 raeburn 1725: if ($item eq 'default') {
1726: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
1727: } else {
1728: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
1729: }
1730: }
1731: } else {
1732: my $newvalue;
1733: if ($key eq 'run') {
1734: $newvalue = $offon[$env{'form.autoupdate_run'}];
1735: } else {
1736: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 1737: }
1.1 raeburn 1738: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
1739: }
1740: }
1741: $resulttext .= '</ul>';
1742: } else {
1.3 raeburn 1743: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 1744: }
1745: } else {
1.11 albertel 1746: $resulttext = '<span class="LC_error">'.
1747: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 1748: }
1.3 raeburn 1749: return $resulttext;
1.1 raeburn 1750: }
1751:
1.3 raeburn 1752: 1;
1.1 raeburn 1753:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>