#!/usr/bin/perl --
#!C:/Web_Applications/perl/bin/perl

#Modified 02/06/10 - changed name of sport folio and bio .pl
#Modified 05/08/10 - change top menu to add rates and remove link to categories
#Modified 28/08/10 - change length of acceptable stock link length to 20 from 30
#Modified 28/08/10 - Moved menu items around to put folios at start
#Modified 02/10/10 - Added google analytics
#Modified 08/01/11 - change title to portfolio
#Modified 07/03/11 - add photo and image to description for title.
#Modified 02/07/11 - added link to heart shapes if portfolio = 4 or motorcycles if portfolio = 3
#Created  10/03/12 - a test version of large_image.pl with no Google analytics.
#Modified 11/03/12 - added a licence this image button.
#Modified 11/03/12 - added a button to link to the other related portfolios.
#modified 27/04/12 - remove google analytics for cookie law complience
#Modified 11/05/12 - added page hit count
#Modified 19/05/12 - re-enabled the alternative photography button
#Modified 24/05/12 - Sorted the alternative images in to the most popular on the first left
#Modified 13/07/12 - amended the heading text of the alernatives to indicate the sub_category
#Modified 14/08/12 - added back google analytics
#Modified 30/11/12 - to remove the 'more food' category atthe bottom of the page. (Since the major clearout of images and re-watermarking)
#Modified 09/08/13 - Changed copyright year to a variable
#Modified 06/12/13 - to pick up new database following migarion/upgrade of hosting.
#Modified 19/01/15 - added the viewport meta
#Modified 24/04/15 - mobile-friendly mods
#Modified 28/07/15 - additional EU cookie law mods
#Modified 30/05/16 - new folio layout.
#Modified 22/09/16 - added licence image and buy print buttons.
#Modified 10/02/19 - new database details from LCN
#Modified 03/02/22 - change the showreel link

#This will display a large image 

use DBI;

use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);

use Time::gmtime;
$ct = gmtime();
$realyear = $ct->year + 1900;

my ($cgi) = new CGI;

#To pick out the data sent from the thumbnail review page.

@pairs=split(/&/,$ENV{'QUERY_STRING'});


print $cgi->header;

foreach $pair(@pairs)
{
($name,$image_id) = split (/=/,$pair);



$name=~ s/\+/ /g;
$name=~ s/%(..)/pack("C", hex($1))/ge;

$value=~ s/\+/ /g;
$value=~ s/%(..)/pack("C", hex($1))/ge;
$value=~s/<!--(.|\n)*-->//g;
}

#To get the details of the image from the database.
my ($sth);
my (@image);
my ($licence_type);
my ($stock_link);
my ($length_test);
my ($page_title);
my ($restriction);

#To get the alternative photographs
my ($sth1);
my (@photograph);

my ($host_name)="d32742-peterhattercomdbnew94e0.db.tb-hosting.com";
my ($user_name,$password) = ("d32742_lcn104139ne26b2","7n53qGwmhSfuJhv8TNaJmQLzYSpbALW5");
my ($db_name) = "d32742_peterhattercomdbnew94e0";
my ($dsn) = "DBI:mysql:$db_name:$host_name";
my ($dbh) = DBI->connect ($dsn, $user_name, $password);

$sth = $dbh->prepare (qq{SELECT * FROM image_mstr where image_id = "$image_id";});
$sth->execute ();
@image = $sth -> fetchrow_array ();


#to set the licence type for display purposes
$licence_type="licenced from stock agent";

if (@image[8] eq "r")
{
$licence_type = "RF purchase from stock agent"
}
elsif (@image[10] eq "p")
{
$licence_type = "n/a"
}
;

#to create the full link to the stock agency but check that there is a link to start with.
$stock_link="@image[4]";

$length_test=length($stock_link);
if ($length_test < 20)
{
$stock_link = "none"
};

#to test if there is a link to the print purchase option.
$print_link="@image[13]";

#To stop the print link working, set the test to catch everything as if there's no link. November 2018
$length_test=length($print_link);
if ($length_test < 200)
{
$print_link = "none"
};

#added to test if another portfolio is available to view. (3=motorcycle. 4 = heart shapes 5 = heart shape only 6 = motorcycle only)
$portfolio_link = "none";
if (@image[5] eq "3" or @image[5] eq "6")
{
$portfolio_text = "Want to see more motorcycle photography?";
$portfolio_link = "<a href=\"/cgi-bin/motorcycle_photography.pl\"><img src=\"/more_photography_here.jpg\" alt=\"more photography here\"></a>"
}
elsif (@image[5] eq "4" or @image[5] eq "5")
{
$portfolio_text = "Want to see more heart shapes?";
$portfolio_link ="<a href=\"/cgi-bin/heart_shape_photography.pl\"><img src=\"/more_photography_here.jpg\" alt=\"more photography here\"></a>"
}
#removed 30/11/12
#elsif (@image[5] eq "7" or @image[5] eq "8" or @image[1] eq "food")
#{
#$portfolio_text = "Want to see more food photography?";
#$portfolio_link ="<a href=\"/cgi-bin/stock_food_photography.pl\"><img src=\"/more_photography_here.jpg\" alt=\"more photography here\"></a>"
#};

#end of modification added 02/07/11 + 21/10/11

#To select a title based upon the catgory of the image
$page_title="/title_portfolio.gif";
#if (@image[1] eq "food")
#{
#$page_title="/title_foodanddrink.gif"
#}
#elsif (@image[1] eq "sport")
#{
#$page_title="/title_sport.gif"
#};

#To set up the restrictions information
$restriction = "editorial only";
if (@image[10] eq  "s" or @image[3] !~ /peter hatter/i)    # checking the new field restriction
{
$restriction = "see stock agent"
}
elsif (@image[10] eq "e" )   # checking the licence status editorial only
{
$restriction = "editorial only"
}
elsif (@image[8] eq "r" )   # checking the licence status 
{
$restriction = "none"
}
elsif (@image[10] eq "n") # no restriction
{
$restriction = "none"
}
elsif (@image[10] eq "p") # portfolio only not for sale
{
$restriction = "portfolio only - not available for licencing"
}
elsif (@image[10] eq "x") # review only not for sale
{
$restriction = "review only - not available for sale or licencing"
};

$photography_page_title = "@image[6]";
if (@image[1] eq "food")
{
$photography_page_title = "@image[6]" . " food stock photography"
}
elsif (@image[2] eq "motorcycles")
{
$photography_page_title = "@image[6]" . " motorcycle stock photography"
}

;

print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
print"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
print"<head>\n";
print"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n";
print"<title>$photography_page_title</title>\n";
print"<meta name=\"description\"
content=\"@image[6]\">";
print"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
print"<link rel=\"stylesheet\" media=\"(max-width: 640px)\" href=\"/global-max-640px.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
print"<link rel=\"stylesheet\" media=\"(min-width: 640px)\" href=\"/global.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
#print"<link href=\"/global.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
print"<link rel=\"icon\" type=\"image/gif\" href=\"http://www.peterhatter.com/sports_photography.gif\"/>\n";


#if ($x < 641)
#{
#print"<style type=\"text/css\">";
#print"#large_image_2 {clear: both; background-image: url(\"/full_size/@image[1]/@image[9]\"); background-repeat: no-repeat; background-position: center center; float: left; margin: 0 auto; margin-top: 10px; margin-left: 0px; height: 400px; width: 300px; background-color: #C1C1C1;}\n";
#print"</style>";
#}
#elsif ($x > 640}
#{
#print"<style type=\"text/css\">";
#print"#large_image_2 {clear: both; background-image: url(\"/full_size/@image[1]/@image[9]\"); background-repeat: no-repeat; background-position: center center; float: left; margin: 0 auto; margin-top: 10px; margin-left: 0px; height: 400px; width: 459px; background-color: #C1C1C1;}\n";
#print"</style>";
#}
#;



print"<script type=\"text/javascript\">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-18865309-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>\n";

print"<script type=\"text/javascript\">
function myF() {
	if (screen.width < 500) {
		document.getElementById(\"title\").width=\"80\";
		document.getElementById(\"twitter_logo\").width=\"30\";
		document.getElementById(\"fb_logo\").width=\"30\";
	}
}

function myF1() {
	if (screen.width < 500) {
		
		document.getElementById(\"large_image\").width=\"290\";
	}
}
</script>\n";

print"<!--Cookie compliance code from https://silktide.com/tools/cookie-consent/download/-->

<!-- Begin Cookie Consent plugin by Silktide - http://silktide.com/cookieconsent -->
<script type=\"text/javascript\">
    window.cookieconsent_options = {\"message\":\"This website uses cookies to ensure you get the best experience on our website\",\"dismiss\":\"Got it!\",\"learnMore\":\"More info\",\"link\":\"http://www.peterhatter.com/cgi-bin/privacy_policy.pl\",\"theme\":\"dark-top\"};
</script>

<script type=\"text/javascript\" src=\"//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/1.0.9/cookieconsent.min.js\"></script>
<!-- End Cookie Consent plugin -->\n";



print"</head>\n";
print"<body>\n";
print"<div class=\"body\">\n";
print"<div class=\"banner\">\n";
print"<div class = \"page_title\">\n";
print"<img src = \"$page_title\" width=\"230\" alt = \"portfolio image\" id =\"title\" onload=\"myF()\">\n";
print"</div>\n";
print"</div>\n";


print"<div class=\"new_mainNav\">\n";
print"  	<ul>\n";
print"  	 	<li><a href=javascript:history.back();>back</a></li>\n";
print"    		<li><a href=\"/index.html\">home</a></li>\n";
print"			<li><a href=\"/cgi-bin/rates.pl\">rates</a></li>\n";
print"			<li><a href=\"/cgi-bin/testimonials.pl\">testimonials</a></li>\n";
print"    		<li><a href=\"/cgi-bin/contact.pl\">contact</a></li>\n";
print"			<li><a href=\"/nottingham_commercial_freelance_photographer_bio.html\">bio</a></li>\n";
print"			<li><a href=\"/films_sport_documentary_promotion_video.html\">film</a></li>\n";
print"			<li><a href=\"/cgi-bin/sports_photography_portfolio.pl\">sport folio</a></li>\n";
print"			<li><a href=\"/sport_motorsport_cinematography_2021_showreel_video.html\">showreel</a></li>\n";
print"	</ul>\n";
print"</div>\n";




print"<div class=\"large_image\">\n";
print"<div class=\"large_image_3\">\n";	
print"<img src=\"/full_size/@image[1]/@image[9]\" width=\"\" height=\"\" alt=\"@image[6]\" id=\"large_image\" onload=\"myF1()\">\n";
			
print"</div>\n";
print"</div>\n";

#28/05/16 remove the details so there's only the image.
#print"<div class=\"large_image_details\">";
#print"<h2>Image Details</h2>";
	
#print"<h3>image ID</h3><p>@image[0]</p><h3>description</h3><p>@image[6]</p></p><h3>licence type</h3><p>$licence_type</p><h3>restrictions</h3><p>$restriction</p><h3>stock agent</h3><p>@image[3]</p>";

#if ($stock_link ne "none")
#{
#print"<br><h3>Would you like to use this image?</h3><p><a href = \"$stock_link\" target=\"_blank\"><img src=\"/licence_this_photograph.jpg\" alt=\"Licence this photograph\"></a></p>";
#}
#elsif (@image[10] ne "p" and @image[10] ne "x")
#{
#print "<h3>digital file details</h3>";
#print "<p>this image is available as a tiff file</p>\n\n";
#
#}
#amended 28/04/12
#print"</div>\n";
#end of amendments 28/04/12
#
#added 27/04/12 - Contact Peter button
#print"<div class=\"contact_peter\">\n";
#print"<br><p><a href = \"/cgi-bin/contact.pl\"><img src=\"/contact_peter.jpg\" alt=\"Contact Peter\"></a>";
#print"</div>\n";
#end of additions 27/04/12
#end of changes 28/05/16




#to get the display count from display_mstr.image_id & display_count
$query="SELECT display_count from display_mstr WHERE display_mstr.image_id = \"@image[0]\"";
$rct =$dbh->prepare (qq{SELECT * from display_mstr where display_mstr.image_id = "@image[0]";});
$rct->execute ();
@display_count = $rct -> fetchrow_array ();
$count_image_id =@display_count[0];
$display_count=@display_count[1];

if (!defined ($count_image_id))
{
$display_count=1;
$query="INSERT display_mstr(image_id,display_count) VALUES (\"@image[0]\",\"$display_count\")";
$rct = $dbh-> prepare (qq{$query});
$rct->execute();
}
else
{
$display_count = $display_count + 1;
$query="UPDATE display_mstr SET display_count = \"$display_count\" WHERE image_id = \"@image[0]\"";
$rct = $dbh-> prepare (qq{$query;});
$rct->execute();
}
#End of the display count updates.

$sth->finish();
$dbh->disconnect ();


#Addition 22/09/16 - Licencing and print purchase button option added.
if ($stock_link ne "none" and $print_link eq "none")
{
print"<div class=\"licencing_options\">\n";
print"<br><h3>Image licence options.</h3><p><a href = \"$stock_link\" target=\"_blank\"><img src=\"/licence_this_image.jpg\" alt=\"Licence this photograph.\"></a></p>";
print"</div>\n";
}
elsif ($stock_link eq "none" and $print_link ne "none")
{
print"<div class=\"licencing_options\">\n";
print"<br><h3>Print purchase options.</h3><p><a href = \"$print_link\" target=\"_blank\"><img src=\"/buy_a_print.jpg\" alt=\"Buy a print of this photograph.\"></a></p>";
print"</div>\n";
}
elsif ($stock_link ne "none" and $print_link ne "none")
{
print"<div class=\"licencing_options\">\n";
print"<br><h3>Print or licence options.</h3><p><a href = \"$print_link\" target=\"_blank\">
<img src=\"/buy_a_print.jpg\" alt=\"Buy a print of this photograph.\"></a><a href = \"$stock_link\" target=\"_blank\"><img src=\"/licence_this_image.jpg\" alt=\"Licence this photograph.\" style=\"padding-left: 20px;\"></a></p>";
print"</div>\n";
};
#End of licencing and print purchase addition


#Addition 11/05/12 - Alternative photographs in the panal underneath the main photograph.

my ($dbh1) = DBI->connect ($dsn, $user_name, $password);
$alt =$dbh1->prepare (qq{SELECT image_mstr.*, display_mstr.* FROM image_mstr,display_mstr WHERE image_mstr.category = "@image[1]" and image_mstr.sub_category = "@image[2]" and image_mstr.image_id <> "@image[0]" and display_mstr.image_id = image_mstr.image_id ORDER BY display_mstr.display_count DESC LIMIT 0,5;});
$alt->execute ();

$row_count = $alt->rows;

print"<div class=\"alternative_photography\">\n";

print"<h2>Other images of @image[2]</h2>\n";

print"<ul>\n";
while (@photograph = $alt -> fetchrow_array ())
{
print"	<li><a href=\"/cgi-bin/large_image.pl?image_id=@photograph[0]\"><img src=\"/thumbnails/@photograph[1]/@photograph[9]\" alt=\"@photograph[6]\"></a></li>";
}
print"	</ul>\n";

#added 11/03/12 as part of additional selection to allow the user to see more similar images
if ($portfolio_link ne "none")
{
print"<div class=\"alternative_photography_button\">\n";
print "<h3>$portfolio_text</h3>\n";
print "<p>$portfolio_link</p>\n";
print"</div>\n";
}
#end of additions 11/05/12

print"</div>\n"; 
		
#print"<div class=\"footer_2\">\n";
#print"	<p>&copy; 2007-".$realyear." Peter Hatter Photography Ltd. All photography and design by Peter Hatter </p>\n";
#print"</div>\n";

print"<div class=\"bottom_of_page\">
<br/>
<a href=\"/index.html\">Home </a>
<a href=\"legal.pl\">Legal   </a>
<a href=\"privacy_policy.pl\">   Privacy</a>
<p>? ".$realyear." Peter Hatter Photography Ltd. All rights reserved.</p>
<a href=\"http://www.twitter.com/peterhatter\"><img src=\"/Twitter_logo_blue.jpg\" id=\"twitter_logo\" onload=\"myF()\" width=\"60\"></a>
<a href=\"https://www.facebook.com/peterhatterfilmphoto/\"><img src=\"/fb_logo.jpg\" id=\"fb_logo\" width=\"50\" target=\"_blank\"></a>
</div>\n";


print"<div class=\"preload\">&nbsp;</div>\n";
print"</div>\n";
print"</body>\n";
print"</html>\n";

# 11/05/12 - to get the page hit count from page_hit_mstr.page_id & count

my ($dsn) = "DBI:mysql:$db_name:$host_name";
my ($dbh) = DBI->connect ($dsn, $user_name, $password);

$page_name="large_image";

$query="SELECT count from page_hit_mstr WHERE page_hit_mstr.page_id = \"$page_name\"";
$rct =$dbh->prepare (qq{SELECT * from page_hit_mstr where page_hit_mstr.page_id = "$page_name";});
$rct->execute ();
@page_hit = $rct -> fetchrow_array ();
$page_hit_id = @page_hit[0];
$page_hit_count = @page_hit[1];

if (!defined ($page_hit_id))
{
$page_hit_count=1;
$query="INSERT page_hit_mstr(page_id,page_count) VALUES (\"$page_name\",\"$page_hit_count\")";
$rct = $dbh-> prepare (qq{$query});
$rct->execute();
}
else
{
$page_hit_count = $page_hit_count + 1;
$query="UPDATE page_hit_mstr SET page_count = \"$page_hit_count\" WHERE page_id = \"$page_name\"";
$rct = $dbh-> prepare (qq{$query;});
$rct->execute();
}
#End of the display count updates


# To finish off here now.

$DBI::err == 0;




