new image show system, allowing dynamic preview images

This commit is contained in:
Thomas Weinhold 2020-09-26 21:32:58 +02:00
commit dfda07ae1c
8 changed files with 193 additions and 53 deletions

View file

@ -28,4 +28,4 @@ $GlobalPictureDir = "./pictures";
$GlobalDecimalPoint="."
?>
?>

View file

@ -23,9 +23,9 @@ function LangSpellHtml ( $Sentence )
function LangSpell ( $Sentence )
{
global $GlobalLanguage;
$ReturnValue="";
if (file_exists("./languages/$GlobalLanguage.lng"))
$Language = file ("./languages/$GlobalLanguage.lng");
else
@ -38,17 +38,17 @@ function LangSpell ( $Sentence )
$FileSentence=explode("=",$i,2);
if ( trim( $FileSentence[0] ) == $Sentence )
{
$ReturnValue=trim($FileSentence[1]);
$ReturnValue=trim($FileSentence[1]);
break;
}
}
if (!$ReturnValue)
{
ErrorLog("[$GlobalLanguage.lng] Sentence \"$Sentence\" not found!");
$ReturnValue=$Sentence;
}
return $ReturnValue;
}
@ -65,4 +65,4 @@ function LangGetAvailableLanguages ()
}
return $ReturnValue;
}
?>
?>

View file

@ -110,7 +110,7 @@ function OtherGetIcon ($IconName,$CssClass)
$IconDirectory='./templates/'.$GlobalTemplate.'/icons/';
$Error = 0;
$RetVal = "";
if (file_exists($IconDirectory.$IconName.".png")) $IconFile=$IconName.".png";
elseif (file_exists($IconDirectory.$IconName.".jpg")) $IconFile=$IconName.".jpg";
elseif (file_exists($IconDirectory.$IconName.".gif")) $IconFile=$IconName.".gif";
@ -120,13 +120,35 @@ function OtherGetIcon ($IconName,$CssClass)
//log if template directory is existing - if not, anyone else will report this
if (file_exists("./templates/".$GlobalTemplate)) ErrorLog("Icon '$IconName' +[.png|.jpg|.gif] not found!");
}
if (!$Error)
{
$RetVal = "<img src=\"$IconDirectory$IconFile\"".(($CssClass)? " class=\"$CssClass\"":"").">";
}
return $RetVal;
}
?>
// Returns a html <img> tag
function OtherGetPictureImg($part_id, $max_width=0, $max_height=0) {
// create anchor tag
$tag = "<a href=\"part_picture.php?PartId=$part_id\">";
// create img tag
$tag .= "<img src=\"part_picture.php?PartId=$part_id";
if ($max_width > 0) $tag .= "&MaxWidth=$max_width";
if ($max_height > 0) $tag .= "&MaxHeight=$max_height";
$tag .= "\""; // finish src attribute
$tag .= " alt=\"picture of part $part_id\"";
$tag .= ">"; // finish img tag
// close link
$tag .= '</a>';
return $tag;
}
?>

View file

@ -139,6 +139,8 @@ PartsObsolete = Obsolete
PartsObsoleteOnly = Only Obsolete
PartsObsoleteNon = Non Obsolete
PartsObsoleteAll = All Parts
PartsPreviewImageYes = Show Preview Images
PartsPreviewImageNo = Hide Preview Images
PartsType = Type
PartsStorage = Store
PartsValues = Values

View file

@ -139,6 +139,8 @@ PartsObsolete = Obsolet
PartsObsoleteOnly = nur Obsolet
PartsObsoleteNon = keine Obsolete
PartsObsoleteAll = alle Bauteile
PartsPreviewImageYes = Vorschaubilder anzeigen
PartsPreviewImageNo = keine Vorschaubilder
PartsType = Typ
PartsStorage = Lager
PartsValues = Werte

View file

@ -7,14 +7,14 @@ function WriteTypeSelector ($ParentId)
global $GlobalMysqlHandler;
global $GlobalContent;
global $GlobalTemplate;
$ListQuery="SELECT * FROM `Types` WHERE `ParentId` =$ParentId";
$ListQuery=mysqli_query($GlobalMysqlHandler, $ListQuery);
if (!$ParentId || NestedListVisibilityIsSet($ParentId, 'PartTypeSelector'))
$GlobalContent .= "<ul style=\"display:block;\">\n";
$GlobalContent .= "<ul style=\"display:block;\">\n";
else
$GlobalContent .= "<ul style=\"display:none;\">\n";
$GlobalContent .= "<ul style=\"display:none;\">\n";
if (mysqli_num_rows($ListQuery))
{
@ -106,6 +106,13 @@ $GlobalContent .= '</div>'."\n";
/////////
// Filter
$GlobalContent .= '<div id="PartFilter">'."\n";
//ShowImage
if (!isset($_SESSION['FilterShowPreviewImage'])) $_SESSION['FilterShowPreviewImage'] = "TRUE";
if (isset($_POST['FilterShowPreviewImage'])) $_SESSION['FilterShowPreviewImage']=$_POST['FilterShowPreviewImage'];
$GlobalContent .= ' <form action="index.php?Page=PartsByType" method="post">'."\n";
$GlobalContent .= ' <input type="radio" name="FilterShowPreviewImage" value="TRUE" onClick="javascript:this.form.submit()" '.(($_SESSION['FilterShowPreviewImage']=="TRUE")? "checked":"").'>'.LangSpellHtml('PartsPreviewImageYes')."\n";
$GlobalContent .= ' <input type="radio" name="FilterShowPreviewImage" value="FALSE" onClick="javascript:this.form.submit()" '.(($_SESSION['FilterShowPreviewImage']!="TRUE")? "checked":"").'>'.LangSpellHtml('PartsPreviewImageNo')."\n";
$GlobalContent .= ' </form>'."<br>\n";
//Obsolete Filter
if (!isset($_SESSION['FilterObsolete'])) $_SESSION['FilterObsolete']="NonObsolete";
if (isset($_POST['FilterObsolete'])) $_SESSION['FilterObsolete']=$_POST['FilterObsolete'];
@ -143,19 +150,23 @@ $GlobalContent .= '<table>'."\n";
// PartList Table Head
$GlobalContent .= '<tr>';
// PreviewImage
if ($_SESSION['FilterShowPreviewImage'] == "TRUE") {
$GlobalContent .= '<th>Image</th>';
}
//Name
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Name" target="_top">';
$GlobalContent .= LangSpellHtml('PartsName')." ";
if ($_SESSION['SortPartListBy']=="Name" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Name" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="Name" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Name" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
//Value 1
if (isset($TypeValues[0][0]) && $TypeValues[0][0])
{
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Value1" target="_top">';
$GlobalContent .= $TypeValues[0][0]." ";
if ($_SESSION['SortPartListBy']=="Value1" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Value1" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="Value1" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Value1" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
}
//Value2
@ -163,8 +174,8 @@ if (isset($TypeValues[1][0]) && $TypeValues[1][0])
{
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Value2" target="_top">';
$GlobalContent .= $TypeValues[1][0]." ";
if ($_SESSION['SortPartListBy']=="Value2" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Value2" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="Value2" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Value2" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
}
//Value3
@ -172,27 +183,27 @@ if (isset($TypeValues[2][0]) && $TypeValues[2][0])
{
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Value3" target="_top">';
$GlobalContent .= $TypeValues[2][0]." ";
if ($_SESSION['SortPartListBy']=="Value3" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Value3" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="Value3" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Value3" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
}
//Package
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=PackageId" target="_top">';
$GlobalContent .= LangSpellHtml('PartsPackage')." ";
if ($_SESSION['SortPartListBy']=="PackageId" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="PackageId" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="PackageId" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="PackageId" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
//Quantity
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Qty" target="_top">';
$GlobalContent .= LangSpellHtml('PartsQuantity')." ";
if ($_SESSION['SortPartListBy']=="Qty" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Qty" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="Qty" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Qty" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
//Price
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Price" target="_top">';
$GlobalContent .= LangSpellHtml('PartsPrice')." ";
if ($_SESSION['SortPartListBy']=="Price" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Price" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
if ($_SESSION['SortPartListBy']=="Price" && $_SESSION['SortPartListOrder']=="ASC") $GlobalContent .= OtherGetIcon('SortUp',0);
if ($_SESSION['SortPartListBy']=="Price" && $_SESSION['SortPartListOrder']=="DESC") $GlobalContent .= OtherGetIcon('SortDown',0);
$GlobalContent .= '</a></th>';
//Obsolete
$GlobalContent .= '<th>'.LangSpellHtml('PartsObsolete').'</th>';
@ -211,28 +222,37 @@ $PartListQuery .= " ORDER BY `".$_SESSION['SortPartListBy']."` ".$_SESSION['Sort
$PartListQuery = mysqli_query($GlobalMysqlHandler, $PartListQuery);
while ($Parts = mysqli_fetch_array($PartListQuery))
{
$GlobalContent .= ' <tr>';
$GlobalContent .= ' <td><a href="index.php?Page=ShowPart&PartId='.$Parts['Id'].'" target="_top"><strong>'.$Parts['Name'].'</strong></a> '.$Parts['ShortDesc'].' </td>';
if (isset($TypeValues[0][0]) && $TypeValues[0][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value1']).$TypeValues[0][1].'</td>';
if (isset($TypeValues[1][0]) && $TypeValues[1][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value2']).$TypeValues[1][1].'</td>';
if (isset($TypeValues[2][0]) && $TypeValues[2][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value3']).$TypeValues[2][1].'</td>';
//////////
// Package
$PackageQuery = "SELECT `Name` FROM `Packages` WHERE `Id` = ".$Parts['PackageId'];
$PackageQuery = mysqli_query($GlobalMysqlHandler, $PackageQuery);
if (mysqli_num_rows($PackageQuery))
{
$Package=mysqli_fetch_array($PackageQuery);
$GlobalContent .= '<td>'.$Package['Name'].'</td>';
}
else
{
$GlobalContent .= '<td>-</td>';
}
$GlobalContent .= '<td>'.$Parts['Qty'].(($Parts['MinQty'])? "/".$Parts['MinQty']:"").'</td>';
$GlobalContent .= '<td>'.OtherFormatPrice($Parts['Price']).'</td>';
$GlobalContent .= '<td>'.((strtolower($Parts['Obsolete'])=="true")? LangSpellHtml('PartsObsolete'):"").'</td>';
$GlobalContent .= ' </tr>';
$GlobalContent .= ' <tr>';
// PreviewImage
if ($_SESSION['FilterShowPreviewImage'] == "TRUE") {
$GlobalContent .= '<td>';
if ($Parts['PicturePath'] != "") {
$GlobalContent .= OtherGetPictureImg($Parts['Id'], 100, 50);
}
$GlobalContent .= '</td>';
}
// Name, Value1, Value2, Value3
$GlobalContent .= ' <td><a href="index.php?Page=ShowPart&PartId='.$Parts['Id'].'" target="_top"><strong>'.$Parts['Name'].'</strong></a> '.$Parts['ShortDesc'].' </td>';
if (isset($TypeValues[0][0]) && $TypeValues[0][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value1']).$TypeValues[0][1].'</td>';
if (isset($TypeValues[1][0]) && $TypeValues[1][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value2']).$TypeValues[1][1].'</td>';
if (isset($TypeValues[2][0]) && $TypeValues[2][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value3']).$TypeValues[2][1].'</td>';
//////////
// Package
$PackageQuery = "SELECT `Name` FROM `Packages` WHERE `Id` = ".$Parts['PackageId'];
$PackageQuery = mysqli_query($GlobalMysqlHandler, $PackageQuery);
if (mysqli_num_rows($PackageQuery)) {
$Package=mysqli_fetch_array($PackageQuery);
$GlobalContent .= '<td>'.$Package['Name'].'</td>';
} else {
$GlobalContent .= '<td>-</td>';
}
$GlobalContent .= '<td>'.$Parts['Qty'].(($Parts['MinQty'])? "/".$Parts['MinQty']:"").'</td>';
$GlobalContent .= '<td>'.OtherFormatPrice($Parts['Price']).'</td>';
$GlobalContent .= '<td>'.((strtolower($Parts['Obsolete'])=="true")? LangSpellHtml('PartsObsolete'):"").'</td>';
$GlobalContent .= ' </tr>';
}
$GlobalContent .= '</table>'."\n";

View file

@ -79,10 +79,9 @@ global $GlobalMysqlHandler;
$GlobalContent .= '<input type="submit" value="'.LangSpellHtml('ButtonUpload').'"class="Button">';
$GlobalContent .= '</form><br>';
}
$GlobalContent .= '<img src="'.$GlobalPictureDir.'/'.$Part['PicturePath'].'"><br><br>';
echo "IMAGE: " . $Part['PicturePath'] . "<br>\n";
$GlobalContent .= OtherGetPictureImg($PartId, 300, 600);
$GlobalContent .= '</div>'."\n";
////////////////
// Detail Values
$GlobalContent .= '<div id="ShowPartValues" style="float:left; margin-left:10px;">'."\n";

95
part_picture.php Normal file
View file

@ -0,0 +1,95 @@
<?php
// Script that generates image data for a requested part in fbsql_database
//
// possible GET valiables:
// PartId (required) - Id of part in databse
// MaxWidth (optional) - When given, image is scaled down to that maximum width
// MaxHeight (optional) - When given, image is scaled down to that maximum height
//main include code
include ("./includes/globals.php");
include ("./includes/load_config.php");
include ("./includes/log.php");
include ("./includes/language.php");
include ("./includes/mysql.php");
include ("./includes/other_functions.php");
// get part Id
if (!isset($_GET['PartId'])) {
exit("ERROR: PartId no given!");
}
$part_id = intval($_GET['PartId']);
// get picture path
$db_query = "SELECT PicturePath FROM `Parts` WHERE `Id` = $part_id;";
$db_result = mysqli_query($GlobalMysqlHandler, $db_query);
if ($db_result->num_rows == 0) {
exit("ERROR: PartId not found!");
}
$source_path = $GlobalPictureDir . "/" . $db_result->fetch_array()['PicturePath'];
// get image info
list($source_width, $source_height) = getimagesize($source_path);
$mime_type = mime_content_type($source_path);
// calculate new With and Height
$output_width = $source_width;
$output_height = $source_height;
$max_width = 0;
if (isset($_GET['MaxWidth'])) {
$max_width = intval($_GET['MaxWidth']);
if ($output_width > $max_width) {
$scale_factor = $max_width / $output_width;
$output_width *= $scale_factor;
$output_height *= $scale_factor;
}
}
$max_height = 0;
if (isset($_GET['MaxHeight'])) {
$max_height = intval($_GET['MaxHeight']);
if ($output_height > $max_height) {
$scale_factor = $max_height / $output_height;
$output_width *= $scale_factor;
$output_height *= $scale_factor;
}
}
// load image
if ($mime_type == 'image/jpeg') {
$source_image = imagecreatefromjpeg($source_path);
$output_image = imagecreatetruecolor($output_width, $output_height);
} else if ($mime_type == 'image/png') {
$source_image = imagecreatefrompng($source_path);
imagealphablending($source_image, true);
imagesavealpha($source_image, true);
$output_image = imagecreate($output_width, $output_height);
} else {
ErrorLog("Unkown mime type: " . $mime_type . "!");
exit("Can't handle requested mime-type.");
}
// resize
$res = imagecopyresized($output_image, $source_image, 0, 0, 0, 0, $output_width, $output_height, $source_width, $source_height);
if ($res !== True) {
$msg = "Cannot resize image: " . $source_path . "\n";
$msg .= "source: " . $source_width . "x" . $source_height;
$msg .= ", max: " . $max_width . "x" . $max_height;
$msg .= ", output: " . $output_width . "x" . $output_height;
ErrorLog($msg);
exit("Cannot resize image!");
}
// output as png
header('Content-Type: image/png');
imagepng($output_image);
imagedestroy($output_image);
imagedestroy($source_width);
?>