--- loncom/lonnet/perl/lonnet.pm 2008/12/21 15:26:50 1.976.2.3 +++ loncom/lonnet/perl/lonnet.pm 2008/12/21 19:03:10 1.981 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.976.2.3 2008/12/21 15:26:50 raeburn Exp $ +# $Id: lonnet.pm,v 1.981 2008/12/21 19:03:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -73,6 +73,8 @@ package Apache::lonnet; use strict; use LWP::UserAgent(); use HTTP::Date; +use Image::Magick; + # use Date::Parse; use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir $_64bit %env %protocol); @@ -97,6 +99,8 @@ use LONCAPA::Configuration; my $readit; my $max_connection_retries = 10; # Or some such value. +my $upload_photo_form = 0; #Variable to check when user upload a photo 0=not 1=true + require Exporter; our @ISA = qw (Exporter); @@ -521,7 +525,7 @@ sub delenv { tie(my %disk_env,'GDBM_File',$env{'user.environment'}, (&GDBM_WRITER()|&GDBM_NOLOCK()),0640)) { foreach my $key (keys(%disk_env)) { - if ($key=~/^$delthis/) { + if ($key=~/^\Q$delthis\E/) { delete($env{$key}); delete($disk_env{$key}); } @@ -2011,6 +2015,14 @@ sub clean_filename { return $fname; } +#Wrapper function for userphotoupload +sub userphotoupload +{ + my($formname,$subdir) = @_; + $upload_photo_form = 1; + return &userfileupload($formname,undef,$subdir); +} + # --------------- Take an uploaded file and put it into the userfiles directory # input: $formname - the contents of the file are in $env{"form.$formname"} # the desired filenam is in $env{"form.$formname.filename"} @@ -2137,6 +2149,25 @@ sub finishuserfileupload { return '/adm/notfound.html'; } close(FH); + if($upload_photo_form==1) + { + my $ima = Image::Magick->new; + $ima->Read($filepath.'/'.$file); + if($ima->Get('width') > 300) + { + my $factor = $ima->Get('width')/300; + $ima->Scale( width=>300, height=>$ima->Get('height')/$factor ); + } + if($ima->Get('height') > 400) + { + my $factor = $ima->Get('height')/400; + $ima->Scale( width=>$ima->Get('width')/$factor, height=>400); + } + + + $ima->Write($filepath.'/'.$file); + $upload_photo_form = 0; + } } if ($parser eq 'parse') { my $parse_result = &extract_embedded_items($filepath.'/'.$file,$allfiles, @@ -4392,7 +4423,7 @@ sub usertools_access { if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) { if ($action ne 'reload') { return $env{'environment.availabletools.'.$tool}; - } + } } my ($toolstatus,$inststatus);