From 4e9db1cf4ff897236bc146298d28aa611da5bbef Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 13 Jan 2019 21:55:22 +0100 Subject: [PATCH] fix image upload parse project_id and studio_id --- website/agenda/planung/imageUpload.cgi | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/website/agenda/planung/imageUpload.cgi b/website/agenda/planung/imageUpload.cgi index 402fb95..2fa6a9e 100755 --- a/website/agenda/planung/imageUpload.cgi +++ b/website/agenda/planung/imageUpload.cgi @@ -43,10 +43,16 @@ my $error = ''; #get image from multiform before anything else if ( defined $r ) { - + #$cgi = new CGI(); + #Apache2::Request my $apr = Apache2::Request->new( $r, POST_MAX => $upload_limit, TEMP_DIR => $tmp_dir ); + $params = { + studio_id => $apr->param('studio_id'), + project_id => $apr->param('project_id'), + }; + #copy params to hash my $body = $apr->body(); if ( defined $body ) { @@ -62,6 +68,7 @@ if ( defined $r ) { } else { $upload = $apr->upload('image') if ( defined $params->{image} ); } + print STDERR "apr\n"; } else { #CGI fallback @@ -71,7 +78,10 @@ if ( defined $r ) { $error = $cgi->cgi_error() || $error; my %params = $cgi->Vars(); $params = \%params; + print STDERR "fallback\n"; } + +print STDERR Dumper($params); print "Content-type:text/html; charset=UTF-8;\n\n"; my ( $user, $expires ) = auth::get_user( $config, $params, $cgi ); return if ( ( !defined $user ) || ( $user eq '' ) ); @@ -199,17 +209,24 @@ sub update_database { studio_id => $params->{studio_id}, licence => $params->{licence} }; + print STDERR Dumper($image); #connect $config->{access}->{write} = 1; my $dbh = db::connect($config); - my $entries = images::get( $config, { filename => $image->{filename} } ); + my $entries = images::get( $config, { + filename => $image->{filename}, + project_id => $image->{project_id} , + studio_id => $image->{studio_id} + } ); if ( ( defined $entries ) && ( scalar(@$entries) > 0 ) ) { + print STDERR "update image\n"; images::update( $dbh, $image ); my $entry = $entries->[0]; $params->{image_id} = $entry->{id}; } else { + print STDERR "insert image\n"; $image->{created_by} = $user; $params->{image_id} = images::insert( $dbh, $image ); }