#!/usr/bin/perl ########################################################################## # COPYRIGHT NOTICE # # # # The contents of this file is protected under the United States # # copyright laws as an unpublished work, and is confidential and # # proprietary to Planetography. Its use or disclosure in whole or in # # part without the expressed written permission of Planetography is # # prohibited. # # # # (c) Copyright 1999-2018 by Planetography. All rights reserved. # ########################################################################## # ########################################################################### # create_detail # Input - one image number # Output - Detail page # Processing - # - Replace markers in html template file with image number # to generate html page. # # 1/29/99 Created # 6/11/03 Major changes of flow, defaults, keywords # ########################################################################### use lib "../perl_modules"; use CGI; use pl_globalvars qw($LOG_DIR $DATA_DIR $TEMPLATE_DIR); # Declare global variables my $image_title = " "; my $image_placename = " "; my $image_desc = " "; my $film_type = " "; my $print_format = " "; my $max_size = " "; my $default_size = " "; my $image_keywords = " "; my $image_state = " "; my %linehash; ######################################## sub lookup_keyword_data { my $separator = ""; if ($lineHash{'chkArch'} eq "on") { $image_keywords = $image_keywords . $separator . "Arch"; $separator = ", "; } if ($lineHash{'chkBadland'} eq "on") { $image_keywords = $image_keywords . $separator . "Badland"; $separator = ", "; } if ($lineHash{'chkBeach'} eq "on") { $image_keywords = $image_keywords . $separator . "Beach"; $separator = ", "; } if ($lineHash{'chkCanyon'} eq "on") { $image_keywords = $image_keywords . $separator . "Canyon"; $separator = ", "; } if ($lineHash{'chkCliff'} eq "on") { $image_keywords = $image_keywords . $separator . "Cliff"; $separator = ", "; } if ($lineHash{'chkDesert'} eq "on") { $image_keywords = $image_keywords . $separator . "Desert"; $separator = ", "; } if ($lineHash{'chkDune'} eq "on") { $image_keywords = $image_keywords . $separator . "Dune"; $separator = ", "; } if ($lineHash{'chkField'} eq "on") { $image_keywords = $image_keywords . $separator . "Field"; $separator = ", "; } if ($lineHash{'chkHoodoo'} eq "on") { $image_keywords = $image_keywords . $separator . "Hoodoo"; $separator = ", "; } if ($lineHash{'chkMountain'} eq "on") { $image_keywords = $image_keywords . $separator . "Mountain"; $separator = ", "; } if ($lineHash{'chkMud'} eq "on") { $image_keywords = $image_keywords . $separator . "Mud"; $separator = ", "; } if ($lineHash{'chkPetrified'} eq "on") { $image_keywords = $image_keywords . $separator . "Petrified Wood"; $separator = ", "; } if ($lineHash{'chkRocks'} eq "on") { $image_keywords = $image_keywords . $separator . "Rocks"; $separator = ", "; } if ($lineHash{'chkSand'} eq "on") { $image_keywords = $image_keywords . $separator . "Sand"; $separator = ", "; } if ($lineHash{'chkSlotCanyon'} eq "on") { $image_keywords = $image_keywords . $separator . "Slot Canyon"; $separator = ", "; } # if ($lineHash{'chkWater'} eq "on") { # $image_keywords = $image_keywords . $separator . "Water"; # $separator = ", "; # } if ($lineHash{'chkCreek'} eq "on") { $image_keywords = $image_keywords . $separator . "Creek"; $separator = ", "; } if ($lineHash{'chkGeyser'} eq "on") { $image_keywords = $image_keywords . $separator . "Geyser"; $separator = ", "; } if ($lineHash{'chkLake'} eq "on") { $image_keywords = $image_keywords . $separator . "Lake"; $separator = ", "; } if ($lineHash{'chkOcean'} eq "on") { $image_keywords = $image_keywords . $separator . "Ocean"; $separator = ", "; } if ($lineHash{'chkPond'} eq "on") { $image_keywords = $image_keywords . $separator . "Pond"; $separator = ", "; } if ($lineHash{'chkRiver'} eq "on") { $image_keywords = $image_keywords . $separator . "River"; $separator = ", "; } if ($lineHash{'chkWaterfall'} eq "on") { $image_keywords = $image_keywords . $separator . "Waterfall"; $separator = ", "; } if ($lineHash{'chkFrost'} eq "on") { $image_keywords = $image_keywords . $separator . "Frost"; $separator = ", "; } if ($lineHash{'chkGlacier'} eq "on") { $image_keywords = $image_keywords . $separator . "Glacier"; $separator = ", "; } if ($lineHash{'chkIce'} eq "on") { $image_keywords = $image_keywords . $separator . "Ice"; $separator = ", "; } if ($lineHash{'chkSnow'} eq "on") { $image_keywords = $image_keywords . $separator . "Snow"; $separator = ", "; } if ($lineHash{'chkReflection'} eq "on") { $image_keywords = $image_keywords . $separator . "Reflection"; $separator = ", "; } # if ($lineHash{'chkPlant'} eq "on") { # $image_keywords = $image_keywords . $separator . "Plant"; # $separator = ", "; # } if ($lineHash{'chkCactus'} eq "on") { $image_keywords = $image_keywords . $separator . "Cactus"; $separator = ", "; } if ($lineHash{'chkFall'} eq "on") { $image_keywords = $image_keywords . $separator . "Fall Color"; $separator = ", "; } if ($lineHash{'chkFlower'} eq "on") { $image_keywords = $image_keywords . $separator . "Flower"; $separator = ", "; } if ($lineHash{'chkGrass'} eq "on") { $image_keywords = $image_keywords . $separator . "Grass"; $separator = ", "; } if ($lineHash{'chkLeaves'} eq "on") { $image_keywords = $image_keywords . $separator . "Leaves"; $separator = ", "; } if ($lineHash{'chkLichen'} eq "on") { $image_keywords = $image_keywords . $separator . "Lichen/Moss"; $separator = ", "; } if ($lineHash{'chkMushroom'} eq "on") { $image_keywords = $image_keywords . $separator . "Mushroom"; $separator = ", "; } if ($lineHash{'chkSeaPlant'} eq "on") { $image_keywords = $image_keywords . $separator . "Water Plant"; $separator = ", "; } if ($lineHash{'chkShrub'} eq "on") { $image_keywords = $image_keywords . $separator . "Shrub"; $separator = ", "; } if ($lineHash{'chkTree'} eq "on") { $image_keywords = $image_keywords . $separator . "Tree"; $separator = ", "; } # if ($lineHash{'chkSky'} eq "on") { # $image_keywords = $image_keywords . $separator . "Sky"; # $separator = ", "; # } if ($lineHash{'chkCloud'} eq "on") { $image_keywords = $image_keywords . $separator . "Cloud"; $separator = ", "; } if ($lineHash{'chkFog'} eq "on") { $image_keywords = $image_keywords . $separator . "Fog"; $separator = ", "; } if ($lineHash{'chkLightning'} eq "on") { $image_keywords = $image_keywords . $separator . "Lightning"; $separator = ", "; } if ($lineHash{'chkRainbow'} eq "on") { $image_keywords = $image_keywords . $separator . "Rainbow"; $separator = ", "; } if ($lineHash{'chkStorm'} eq "on") { $image_keywords = $image_keywords . $separator . "Storm"; $separator = ", "; } if ($lineHash{'chkSundog'} eq "on") { $image_keywords = $image_keywords . $separator . "Sundog"; $separator = ", "; } if ($lineHash{'chkSunrise'} eq "on") { $image_keywords = $image_keywords . $separator . "Sunrise/Sunset"; $separator = ", "; } # if ($lineHash{'chkAstronomical'} eq "on") { # $image_keywords = $image_keywords . $separator . "Astronomical"; # $separator = ", "; # } if ($lineHash{'chkAurora'} eq "on") { $image_keywords = $image_keywords . $separator . "Aurora"; $separator = ", "; } if ($lineHash{'chkComet'} eq "on") { $image_keywords = $image_keywords . $separator . "Comet"; $separator = ", "; } if ($lineHash{'chkEclipse'} eq "on") { $image_keywords = $image_keywords . $separator . "Eclipse"; $separator = ", "; } if ($lineHash{'chkMoon'} eq "on") { $image_keywords = $image_keywords . $separator . "Moon"; $separator = ", "; } if ($lineHash{'chkStars'} eq "on") { $image_keywords = $image_keywords . $separator . "Stars"; $separator = ", "; } if ($lineHash{'chkSun'} eq "on") { $image_keywords = $image_keywords . $separator . "Sun"; $separator = ", "; } if ($lineHash{'chkRockArt'} eq "on") { $image_keywords = $image_keywords . $separator . "Rock Art"; $separator = ", "; } if ($lineHash{'chkStructure'} eq "on") { $image_keywords = $image_keywords . $separator . "Manmade"; $separator = ", "; } # if ($lineHash{'chkWildlife'} eq "on") { # $image_keywords = $image_keywords . $separator . "Wildlife"; # $separator = ", "; # } if ($lineHash{'chkBird'} eq "on") { $image_keywords = $image_keywords . $separator . "Bird"; $separator = ", "; } if ($lineHash{'chkBug'} eq "on") { $image_keywords = $image_keywords . $separator . "Bug"; $separator = ", "; } if ($lineHash{'chkMammal'} eq "on") { $image_keywords = $image_keywords . $separator . "Mammal"; $separator = ", "; } if ($lineHash{'chkReptile'} eq "on") { $image_keywords = $image_keywords . $separator . "Reptile/Amphibian"; $separator = ", "; } if ($lineHash{'chkShell'} eq "on") { $image_keywords = $image_keywords . $separator . "Shell"; $separator = ", "; } if ($lineHash{'chkTrack'} eq "on") { $image_keywords = $image_keywords . $separator . "Animal Track"; $separator = ", "; } } ######################################## sub lookup_data # Lookup the values in the data file # If a value doesn't exist set the string to   # Assign values to global variables { # Open the data file open(image_data_fh, $DATA_DIR . "image_hash_data.txt") || die ("Couldn't find image hash data file"); # Find the row that begins with the desired image number followed by a comma my $pattern='^image#' . $image_num . '#'; while ($line = ) { if ($line =~ m/$pattern/) { chop($line); # Remove the carriage return from the end of the line my @lineArray = split('#',$line); # Separate elements into an array %lineHash = @lineArray; # Convert array into hash # Extract the fixed elements $image_title = $lineHash{'title'}; $image_placename = $lineHash{'placename'}; $image_desc = $lineHash{'locdetail'}; $image_state = $lineHash{'state'}; my $msize = $lineHash{'maxsize'}; # 1=square 2=standard 3 = proportional my $pformat = $lineHash{'pformat'}; # Depending on the print format, determine the maximum size # for the image from the DB, and also set the default size. # The only default that is done in this script is the default size, since we needed to do the logic # for the maximum image size here. Other default values are found in the detail_add_cookie.js script if ($pformat eq "1") { $print_format = 'Square'; $default_size = '2020'; if ($msize == 1) {$max_size = 'NA';} elsif ($msize == 2) {$max_size = '8x8';} elsif ($msize == 3) {$max_size = '12x12';} elsif ($msize == 4) {$max_size = '16x16';} elsif ($msize == 5) {$max_size = '20x20';} elsif ($msize == 6) {$max_size = '24x24';} elsif ($msize == 7) {$max_size = '28x28';} elsif ($msize == 8) {$max_size = '32x32';} elsif ($msize == 9) {$max_size = '36x36';} elsif ($msize == 10) {$max_size = '40x40';} # If the maximum size is less than the default, reduce the default size if ($msize < 5) { $default_size = "1212"; } } elsif ($pformat eq "2") { $print_format = 'Standard (example 8x10)'; $default_size = '2025'; if ($msize == 1) {$max_size = 'NA';} elsif ($msize == 2) {$max_size = '8x10';} elsif ($msize == 3) {$max_size = '12x15';} elsif ($msize == 4) {$max_size = '16x20';} elsif ($msize == 5) {$max_size = '20x25';} elsif ($msize == 6) {$max_size = '24x30';} elsif ($msize == 7) {$max_size = '28x35';} elsif ($msize == 8) {$max_size = '32x40';} elsif ($msize == 9) {$max_size = '36x45';} elsif ($msize == 10) {$max_size = '40x50';} # If the maximum size is less than the default, reduce the default size if ($msize < 5) { $default_size = "1215"; } } elsif ($pformat eq "3") { $print_format = 'Proportional (example 8x12)'; $default_size = '2030'; if ($msize == 1) {$max_size = 'NA';} elsif ($msize == 2) {$max_size = '8x12';} elsif ($msize == 3) {$max_size = '12x18';} elsif ($msize == 4) {$max_size = '16x24';} elsif ($msize == 5) {$max_size = '20x30';} elsif ($msize == 6) {$max_size = '24x36';} elsif ($msize == 7) {$max_size = '28x42';} elsif ($msize == 8) {$max_size = '32x48';} elsif ($msize == 9) {$max_size = '36x54';} elsif ($msize == 10) {$max_size = '40x60';} # If the maximum size is less than the default, reduce the default size if ($msize < 5) { $default_size = "1218"; } } lookup_keyword_data (); # exit from the while loop last; } #end if } #end while close(image_data_fh); } #end sub lookup_data ######################################## sub log_detail_access # Log the lookup for this image { my $image_num = shift; # Log format is image_num,access_count (e.g.).....912,.......4 $openstr = $LOG_DIR . "track_detail_access.txt"; if (!open(ACCESS_LOG_FD,">>".$openstr)) { #print DEBUG_FD ("Could not open/create detail access file\n"); return; } if (!open(ACCESS_LOG_FD,"+<".$openstr)) { #print DEBUG_FD ("Could not open detail access file\n"); return; } if (pl_globalvars::file_locking (ACCESS_LOG_FD, LOCK_EX) != 0) { #print DEBUG_FD ("Could not lock detail access file\n"); # close (ACCESS_LOG_FD): # return; } my @image_nums = ; my $array_length = @image_nums; my $i=0; my $access_count=0; my $reg_exp = sprintf("%8s, *(.*)",$image_num); #print ACCESS_LOG_FD ("REGEXP = $reg_exp\n"); for($i=0; $i < $array_length; $i++) { if ($image_nums[$i] =~ m/$reg_exp/) { $access_count = $1 + 1; #print ACCESS_LOG_FD ("MATCH ON ROW $i, $image_nums[$i], $reg_exp\n"); last; } } if ($i == $array_length) { # # No entry found for image number, add one # printf ACCESS_LOG_FD ("%8s,%8s\n",$image_num,1); } else { # # Figure out the position. Each line is 19 (18) characters cccccccc,cccccccc # # NOTE CHANGE THIS TO *18 AFTER UPDATED FOR UNIX BASED SYSTEMS. my $file_pos = ($i*19) + 9; # # The first zero is the position, the second zero means SEEKSET and tells it to set to the specified position # seek(ACCESS_LOG_FD,$file_pos,0); # # Increment the counter # printf ACCESS_LOG_FD ("%8s",$access_count); } if (pl_globalvars::file_locking (ACCESS_LOG_FD, LOCK_UN) != 0) { #print DEBUG_FD ("Could not unlock detail access file\n"); } close(ACCESS_LOG_FD); } ######################################## # Main code section ######################################## #my $openstr = ""; #$openstr = ">" . $LOG_DIR . "log_detail.txt"; #open(DEBUG_FD,$openstr); # parses input from GET or POST methods my $query = new CGI; my $add_tag_flag = " "; $image_num = $query->param('image'); # assigns paramater named image to global var $add_tag_flag = $query->param('add_tag'); #Log that the image has been accessed $result_var = log_detail_access($image_num); # Print out the header print $query->header; print("\n"); print("\n"); print("' . "\n"); print DEBUG_FD ("IN IT ID IP IS "+image_number+" "+image_title+" "+image_description+" "+image_place_name+" "+image_state); print DEBUG_FD ("IK MS FT AT DS "+image_keywords+" "+max_size+" "+film_type+" "+add_tag_flag+" "+default_size); $openstr = $TEMPLATE_DIR . "detail_partial.htm"; open(TEMPLATE_FD, $openstr) || die "Unable to open template file."; print ; close(TEMPLATE_FD); #close(DEBUG_FD); #DEBUG