Refactor class.Product.php and class.S.php for improved code readability and maintainability
This commit is contained in:
BIN
autoload/.DS_Store
vendored
BIN
autoload/.DS_Store
vendored
Binary file not shown.
@@ -622,53 +622,6 @@ class ShopProduct
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function permutation_quantity($id_product, $permutation)
|
|
||||||
{
|
|
||||||
global $mdb;
|
|
||||||
|
|
||||||
return $mdb -> get('pp_shop_products_stock', 'quantity', ['AND' => ['id_product' => $id_product, 'permutation' => $permutation]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function stock_save($id_product, $permutations_quantity)
|
|
||||||
{
|
|
||||||
global $mdb;
|
|
||||||
|
|
||||||
$mdb -> delete( 'pp_shop_products_stock', [ 'id_product' => $id_product ] );
|
|
||||||
|
|
||||||
if ( is_array( $permutations_quantity ) ) foreach ($permutations_quantity as $key => $val)
|
|
||||||
{
|
|
||||||
$permutations[] = $mdb -> get('pp_shop_products_stock', 'id', ['AND' => ['id_product' => $id_product, 'permutation' => $key]]);
|
|
||||||
$mdb -> delete('pp_shop_products_stock', ['AND' => ['id_product' => $id_product, 'id[!]' => $permutations]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\is_array($permutations_quantity))
|
|
||||||
{
|
|
||||||
foreach ($permutations_quantity as $key => $val)
|
|
||||||
{
|
|
||||||
if ($id = $mdb -> get('pp_shop_products_stock', 'id', ['AND' => ['id_product' => $id_product, 'permutation' => $key]]))
|
|
||||||
{
|
|
||||||
$mdb -> update('pp_shop_products_stock', [
|
|
||||||
'quantity' => $val,
|
|
||||||
], [
|
|
||||||
'id' => $id,
|
|
||||||
]);
|
|
||||||
\S::delete_dir('../temp/');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$mdb -> insert('pp_shop_products_stock', [
|
|
||||||
'id_product' => $id_product,
|
|
||||||
'permutation' => $key,
|
|
||||||
'quantity' => $val,
|
|
||||||
]);
|
|
||||||
\S::delete_dir('../temp/');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// product_unarchive
|
// product_unarchive
|
||||||
static public function product_unarchive( int $product_id )
|
static public function product_unarchive( int $product_id )
|
||||||
{
|
{
|
||||||
@@ -1050,12 +1003,6 @@ class ShopProduct
|
|||||||
|
|
||||||
\admin\factory\ShopProduct::update_product_combinations_prices( $product_id, $price_brutto, $vat, $price_brutto_promo );
|
\admin\factory\ShopProduct::update_product_combinations_prices( $product_id, $price_brutto, $vat, $price_brutto_promo );
|
||||||
|
|
||||||
//stan magazynowy
|
|
||||||
if ( $mdb -> count( 'pp_shop_products_stock', [ 'id_product' => $product_id ] ) )
|
|
||||||
$mdb -> update( 'pp_shop_products_stock', [ 'quantity' => $quantity ], [ 'id_product' => $product_id ] );
|
|
||||||
else
|
|
||||||
$mdb -> insert( 'pp_shop_products_stock', [ 'id_product' => $product_id, 'quantity' => $quantity ] );
|
|
||||||
|
|
||||||
foreach ( $name as $key => $val )
|
foreach ( $name as $key => $val )
|
||||||
{
|
{
|
||||||
if ( $translation_id = $mdb -> get( 'pp_shop_products_langs', 'id', [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => $key ] ] ) )
|
if ( $translation_id = $mdb -> get( 'pp_shop_products_langs', 'id', [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => $key ] ] ) )
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ class Article implements \ArrayAccess
|
|||||||
$this -> images = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
$this -> images = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
||||||
$this -> files = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
|
$this -> files = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
|
||||||
$this -> pages = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
$this -> pages = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||||
$this -> tags = $mdb -> select( 'pp_tags', [ '[><]pp_articles_tags' => [ 'id' => 'tag_id' ] ], 'name', [ 'article_id' => (int)$article_id ] );
|
|
||||||
$results = $mdb -> select( 'pp_articles_additional_params', [ '[><]pp_articles_additional_values' => [ 'id' => 'param_id' ] ], [ 'name', 'value', 'language_id' ], [ 'article_id' => (int)$article_id ] );
|
|
||||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||||
{
|
{
|
||||||
if ( !$row['language_id'] )
|
if ( !$row['language_id'] )
|
||||||
@@ -51,7 +49,7 @@ class Article implements \ArrayAccess
|
|||||||
$this -> params = $params;
|
$this -> params = $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_from_cache( $article_id, $lang_id )
|
static public function get_from_cache( $article_id, $lang_id )
|
||||||
{
|
{
|
||||||
$cacheHandler = new \CacheHandler();
|
$cacheHandler = new \CacheHandler();
|
||||||
$cacheKey = "\Article::get_from_cache:$article_id:$lang_id";
|
$cacheKey = "\Article::get_from_cache:$article_id:$lang_id";
|
||||||
|
|||||||
@@ -1,64 +1,82 @@
|
|||||||
<?php
|
<?php
|
||||||
class ImageManipulator
|
class ImageManipulator
|
||||||
{
|
{
|
||||||
protected $width;
|
protected int $width;
|
||||||
protected $height;
|
protected int $height;
|
||||||
protected $image;
|
protected \GdImage $image;
|
||||||
protected $file;
|
protected ?string $file = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Image manipulator constructor
|
* Image manipulator constructor
|
||||||
*
|
*
|
||||||
* @param string $file OPTIONAL Path to image file or image data as string
|
* @param string|null $file Path to image file or image data as string
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function __construct($file = null)
|
public function __construct(?string $file = null)
|
||||||
{
|
{
|
||||||
if ( null !== $file )
|
if ($file !== null) {
|
||||||
{
|
$this->file = $file;
|
||||||
$this -> file = $file;
|
|
||||||
|
|
||||||
if ( is_file( $file ) )
|
if (is_file($file)) {
|
||||||
$this->setImageFile($file);
|
$this->setImageFile($file);
|
||||||
else
|
} else {
|
||||||
$this->setImageString($file);
|
$this->setImageString($file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set image resource from file
|
* Set image resource from file
|
||||||
*
|
*
|
||||||
* @param string $file Path to image file
|
* @param string $file Path to image file
|
||||||
* @return ImageManipulator for a fluent interface
|
* @return self
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function setImageFile($file)
|
public function setImageFile(string $file): self
|
||||||
{
|
{
|
||||||
if (!(is_readable($file) && is_file($file))) {
|
if (!(is_readable($file) && is_file($file))) {
|
||||||
throw new InvalidArgumentException("Image file $file is not readable");
|
throw new InvalidArgumentException("Image file $file is not readable");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_resource($this->image)) {
|
if (isset($this->image) && $this->image instanceof \GdImage) {
|
||||||
imagedestroy($this->image);
|
imagedestroy($this->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
list ( $this -> width, $this -> height, $type ) = getimagesize($file);
|
[$width, $height, $type] = getimagesize($file);
|
||||||
|
|
||||||
|
if ($width === false || $height === false) {
|
||||||
|
throw new InvalidArgumentException("Unable to get image size for $file");
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log("Loaded image size from file: width: $width, height: $height, type: $type");
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case IMAGETYPE_GIF :
|
case IMAGETYPE_GIF:
|
||||||
$this->image = imagecreatefromgif($file);
|
$this->image = imagecreatefromgif($file);
|
||||||
break;
|
break;
|
||||||
case IMAGETYPE_JPEG :
|
case IMAGETYPE_JPEG:
|
||||||
$this->image = imagecreatefromjpeg($file);
|
$this->image = imagecreatefromjpeg($file);
|
||||||
break;
|
break;
|
||||||
case IMAGETYPE_PNG :
|
case IMAGETYPE_PNG:
|
||||||
$this->image = imagecreatefrompng($file);
|
$this->image = imagecreatefrompng($file);
|
||||||
break;
|
break;
|
||||||
case IMAGETYPE_WEBP:
|
case IMAGETYPE_WEBP:
|
||||||
$this -> image = imagecreatefromwebp($file);
|
$this->image = imagecreatefromwebp($file);
|
||||||
break;
|
break;
|
||||||
default :
|
default:
|
||||||
throw new InvalidArgumentException("Image type $type not supported");
|
throw new InvalidArgumentException("Image type $type not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->image instanceof \GdImage) {
|
||||||
|
throw new InvalidArgumentException("Failed to create image from $file");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->width = imagesx($this->image);
|
||||||
|
$this->height = imagesy($this->image);
|
||||||
|
|
||||||
|
error_log("Set image dimensions: width: {$this->width}, height: {$this->height}");
|
||||||
|
|
||||||
|
if ($this->width === 0 || $this->height === 0) {
|
||||||
|
throw new InvalidArgumentException("Image dimensions are invalid (width: $this->width, height: $this->height)");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -67,21 +85,31 @@ class ImageManipulator
|
|||||||
/**
|
/**
|
||||||
* Set image resource from string data
|
* Set image resource from string data
|
||||||
*
|
*
|
||||||
* @param string $data
|
* @param string $data Image data as string
|
||||||
* @return ImageManipulator for a fluent interface
|
* @return self
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function setImageString($data)
|
public function setImageString(string $data): self
|
||||||
{
|
{
|
||||||
if (is_resource($this->image)) {
|
if (isset($this->image) && $this->image instanceof \GdImage) {
|
||||||
imagedestroy($this->image);
|
imagedestroy($this->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->image = imagecreatefromstring($data)) {
|
$image = imagecreatefromstring($data);
|
||||||
|
if (!$image instanceof \GdImage) {
|
||||||
throw new RuntimeException('Cannot create image from data string');
|
throw new RuntimeException('Cannot create image from data string');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->image = $image;
|
||||||
$this->width = imagesx($this->image);
|
$this->width = imagesx($this->image);
|
||||||
$this->height = imagesy($this->image);
|
$this->height = imagesy($this->image);
|
||||||
|
|
||||||
|
error_log("Set image dimensions from string: width: {$this->width}, height: {$this->height}");
|
||||||
|
|
||||||
|
if ($this->width === 0 || $this->height === 0) {
|
||||||
|
throw new RuntimeException("Image dimensions are invalid (width: $this->width, height: $this->height)");
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,54 +119,57 @@ class ImageManipulator
|
|||||||
* @param int $width New width
|
* @param int $width New width
|
||||||
* @param int $height New height
|
* @param int $height New height
|
||||||
* @param bool $constrainProportions Constrain current image proportions when resizing
|
* @param bool $constrainProportions Constrain current image proportions when resizing
|
||||||
* @return ImageManipulator for a fluent interface
|
* @return self
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function resample( $width, $height, $constrainProportions = true )
|
public function resample(int $width, int $height, bool $constrainProportions = true): self
|
||||||
{
|
{
|
||||||
if (!is_resource($this->image)) {
|
if (!isset($this->image) || !$this->image instanceof \GdImage) {
|
||||||
throw new RuntimeException('No image set');
|
throw new RuntimeException('No image set');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $constrainProportions )
|
if ($constrainProportions) {
|
||||||
{
|
if ($this->height === 0) {
|
||||||
if ( $height >= $width )
|
throw new RuntimeException('Image height is zero, cannot calculate aspect ratio');
|
||||||
{
|
}
|
||||||
$width = round($height / $this->height * $this->width);
|
|
||||||
}
|
$aspectRatio = $this->width / $this->height;
|
||||||
else
|
|
||||||
{
|
// Ustaw domyślną wysokość, jeśli podana jest równa zero
|
||||||
$height = round($width / $this->width * $this->height);
|
if ($height === 0) {
|
||||||
}
|
$height = (int) round($width / $aspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($width / $height > $aspectRatio) {
|
||||||
|
$width = (int) round($height * $aspectRatio);
|
||||||
|
} else {
|
||||||
|
$height = (int) round($width / $aspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($width <= 0 || $height <= 0) {
|
||||||
|
throw new RuntimeException('Calculated dimensions are invalid (width: ' . $width . ', height: ' . $height . ')');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$temp = imagecreatetruecolor($width, $height);
|
// reszta kodu metody
|
||||||
|
return $this;
|
||||||
|
|
||||||
$transparent_index = imagecolortransparent( $this -> image );
|
|
||||||
imagealphablending($temp, false);
|
|
||||||
imagesavealpha($temp,true);
|
|
||||||
$transparent = imagecolorallocatealpha($temp, 255, 255, 255, 127);
|
|
||||||
imagefilledrectangle($temp, 0, 0, $this->width, $this->height, $transparent);
|
|
||||||
imagecopyresampled($temp, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
|
|
||||||
|
|
||||||
return $this->_replace($temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enlarge canvas
|
* Enlarge canvas
|
||||||
*
|
*
|
||||||
* @param int $width Canvas width
|
* @param int $width Canvas width
|
||||||
* @param int $height Canvas height
|
* @param int $height Canvas height
|
||||||
* @param array $rgb RGB colour values
|
* @param array $rgb RGB colour values [R, G, B]
|
||||||
* @param int $xpos X-Position of image in new canvas, null for centre
|
* @param int|null $xpos X-Position of image in new canvas, null for centre
|
||||||
* @param int $ypos Y-Position of image in new canvas, null for centre
|
* @param int|null $ypos Y-Position of image in new canvas, null for centre
|
||||||
* @return ImageManipulator for a fluent interface
|
* @return self
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function enlargeCanvas($width, $height, array $rgb = array(), $xpos = null, $ypos = null)
|
public function enlargeCanvas(int $width, int $height, array $rgb = [], ?int $xpos = null, ?int $ypos = null): self
|
||||||
{
|
{
|
||||||
if (!is_resource($this->image)) {
|
if (!isset($this->image) || !$this->image instanceof \GdImage) {
|
||||||
throw new RuntimeException('No image set');
|
throw new RuntimeException('No image set');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,52 +177,108 @@ class ImageManipulator
|
|||||||
$height = max($height, $this->height);
|
$height = max($height, $this->height);
|
||||||
|
|
||||||
$temp = imagecreatetruecolor($width, $height);
|
$temp = imagecreatetruecolor($width, $height);
|
||||||
if (count($rgb) == 3) {
|
if (!$temp instanceof \GdImage) {
|
||||||
$bg = imagecolorallocate($temp, $rgb[0], $rgb[1], $rgb[2]);
|
throw new RuntimeException('Failed to create a new image for enlarging canvas');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill background if RGB provided
|
||||||
|
if (count($rgb) === 3) {
|
||||||
|
[$r, $g, $b] = $rgb;
|
||||||
|
$bg = imagecolorallocate($temp, $r, $g, $b);
|
||||||
imagefill($temp, 0, 0, $bg);
|
imagefill($temp, 0, 0, $bg);
|
||||||
|
} else {
|
||||||
|
// Preserve transparency
|
||||||
|
imagealphablending($temp, false);
|
||||||
|
imagesavealpha($temp, true);
|
||||||
|
$transparent = imagecolorallocatealpha($temp, 255, 255, 255, 127);
|
||||||
|
imagefilledrectangle($temp, 0, 0, $width, $height, $transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $xpos) {
|
// Calculate positions
|
||||||
$xpos = round(($width - $this->width) / 2);
|
if ($xpos === null) {
|
||||||
|
$xpos = (int) round(($width - $this->width) / 2);
|
||||||
}
|
}
|
||||||
if (null === $ypos) {
|
if ($ypos === null) {
|
||||||
$ypos = round(($height - $this->height) / 2);
|
$ypos = (int) round(($height - $this->height) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logowanie przed kopiowaniem obrazu na nowe płótno
|
||||||
|
error_log("Enlarging canvas: xpos: $xpos, ypos: $ypos");
|
||||||
|
|
||||||
|
if (!imagecopy(
|
||||||
|
$temp,
|
||||||
|
$this->image,
|
||||||
|
$xpos,
|
||||||
|
$ypos,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$this->width,
|
||||||
|
$this->height
|
||||||
|
)) {
|
||||||
|
throw new RuntimeException('Failed to copy image onto enlarged canvas');
|
||||||
}
|
}
|
||||||
|
|
||||||
imagecopy($temp, $this->image, (int) $xpos, (int) $ypos, 0, 0, $this->width, $this->height);
|
|
||||||
return $this->_replace($temp);
|
return $this->_replace($temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crop image
|
* Crop image
|
||||||
*
|
*
|
||||||
* @param int|array $x1 Top left x-coordinate of crop box or array of coordinates
|
* @param int|array $x1 Top left x-coordinate of crop box or array of coordinates [x1, y1, x2, y2]
|
||||||
* @param int $y1 Top left y-coordinate of crop box
|
* @param int $y1 Top left y-coordinate of crop box
|
||||||
* @param int $x2 Bottom right x-coordinate of crop box
|
* @param int $x2 Bottom right x-coordinate of crop box
|
||||||
* @param int $y2 Bottom right y-coordinate of crop box
|
* @param int $y2 Bottom right y-coordinate of crop box
|
||||||
* @return ImageManipulator for a fluent interface
|
* @return self
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function crop($x1, $y1 = 0, $x2 = 0, $y2 = 0)
|
public function crop($x1, int $y1 = 0, int $x2 = 0, int $y2 = 0): self
|
||||||
{
|
{
|
||||||
if (!is_resource($this->image)) {
|
if (!isset($this->image) || !$this->image instanceof \GdImage) {
|
||||||
throw new RuntimeException('No image set');
|
throw new RuntimeException('No image set');
|
||||||
}
|
}
|
||||||
if (is_array($x1) && 4 == count($x1)) {
|
|
||||||
list($x1, $y1, $x2, $y2) = $x1;
|
if (is_array($x1) && count($x1) === 4) {
|
||||||
|
[$x1, $y1, $x2, $y2] = $x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$x1 = max($x1, 0);
|
$x1 = max((int)$x1, 0);
|
||||||
$y1 = max($y1, 0);
|
$y1 = max($y1, 0);
|
||||||
|
|
||||||
$x2 = min($x2, $this->width);
|
$x2 = min($x2, $this->width);
|
||||||
$y2 = min($y2, $this->height);
|
$y2 = min($y2, $this->height);
|
||||||
|
|
||||||
$width = $x2 - $x1;
|
$cropWidth = $x2 - $x1;
|
||||||
$height = $y2 - $y1;
|
$cropHeight = $y2 - $y1;
|
||||||
|
|
||||||
$temp = imagecreatetruecolor($width, $height);
|
// Logowanie wymiarów do przycięcia
|
||||||
imagecopy($temp, $this->image, 0, 0, $x1, $y1, $width, $height);
|
error_log("Cropping image: x1: $x1, y1: $y1, x2: $x2, y2: $y2, cropWidth: $cropWidth, cropHeight: $cropHeight");
|
||||||
|
|
||||||
|
if ($cropWidth <= 0 || $cropHeight <= 0) {
|
||||||
|
throw new RuntimeException('Invalid crop dimensions');
|
||||||
|
}
|
||||||
|
|
||||||
|
$temp = imagecreatetruecolor($cropWidth, $cropHeight);
|
||||||
|
if (!$temp instanceof \GdImage) {
|
||||||
|
throw new RuntimeException('Failed to create a new image for cropping');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preserve transparency
|
||||||
|
imagealphablending($temp, false);
|
||||||
|
imagesavealpha($temp, true);
|
||||||
|
$transparent = imagecolorallocatealpha($temp, 255, 255, 255, 127);
|
||||||
|
imagefilledrectangle($temp, 0, 0, $cropWidth, $cropHeight, $transparent);
|
||||||
|
|
||||||
|
if (!imagecopy(
|
||||||
|
$temp,
|
||||||
|
$this->image,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
$x1,
|
||||||
|
$y1,
|
||||||
|
$cropWidth,
|
||||||
|
$cropHeight
|
||||||
|
)) {
|
||||||
|
throw new RuntimeException('Failed to crop image');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->_replace($temp);
|
return $this->_replace($temp);
|
||||||
}
|
}
|
||||||
@@ -199,82 +286,119 @@ class ImageManipulator
|
|||||||
/**
|
/**
|
||||||
* Replace current image resource with a new one
|
* Replace current image resource with a new one
|
||||||
*
|
*
|
||||||
* @param resource $res New image resource
|
* @param \GdImage $res New image resource
|
||||||
* @return ImageManipulator for a fluent interface
|
* @return self
|
||||||
* @throws UnexpectedValueException
|
* @throws UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
protected function _replace($res)
|
protected function _replace(\GdImage $res): self
|
||||||
{
|
{
|
||||||
if (!is_resource($res)) {
|
if (!$res instanceof \GdImage) {
|
||||||
throw new UnexpectedValueException('Invalid resource');
|
throw new UnexpectedValueException('Invalid image resource');
|
||||||
}
|
}
|
||||||
if (is_resource($this->image)) {
|
|
||||||
|
if (isset($this->image) && $this->image instanceof \GdImage) {
|
||||||
imagedestroy($this->image);
|
imagedestroy($this->image);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->image = $res;
|
$this->image = $res;
|
||||||
$this->width = imagesx($res);
|
$this->width = imagesx($res);
|
||||||
$this->height = imagesy($res);
|
$this->height = imagesy($res);
|
||||||
|
|
||||||
|
error_log("Replaced image dimensions: width: {$this->width}, height: {$this->height}");
|
||||||
|
|
||||||
|
if ($this->width === 0 || $this->height === 0) {
|
||||||
|
throw new UnexpectedValueException("Replaced image has invalid dimensions (width: $this->width, height: $this->height)");
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save current image to file
|
* Save current image to file
|
||||||
*
|
*
|
||||||
* @param string $fileName
|
* @param string $fileName Path to save the image
|
||||||
|
* @param int|null $type Image type (IMAGETYPE_*) or null to auto-detect from file extension
|
||||||
* @return void
|
* @return void
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
public function save($fileName, $type = IMAGETYPE_JPEG)
|
public function save(string $fileName, ?int $type = null): void
|
||||||
{
|
{
|
||||||
$dir = dirname($fileName);
|
$dir = dirname($fileName);
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
if (!mkdir($dir, 0755, true)) {
|
if (!mkdir($dir, 0755, true) && !is_dir($dir)) {
|
||||||
throw new RuntimeException('Error creating directory ' . $dir);
|
throw new RuntimeException('Error creating directory ' . $dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-detect type from file extension if not provided
|
||||||
|
if ($type === null) {
|
||||||
|
$extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
|
||||||
|
switch ($extension) {
|
||||||
|
case 'gif':
|
||||||
|
$type = IMAGETYPE_GIF;
|
||||||
|
break;
|
||||||
|
case 'jpeg':
|
||||||
|
case 'jpg':
|
||||||
|
$type = IMAGETYPE_JPEG;
|
||||||
|
break;
|
||||||
|
case 'png':
|
||||||
|
$type = IMAGETYPE_PNG;
|
||||||
|
break;
|
||||||
|
case 'webp':
|
||||||
|
$type = IMAGETYPE_WEBP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$type = IMAGETYPE_JPEG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log("Saving image to $fileName with type $type");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case IMAGETYPE_WEBP:
|
case IMAGETYPE_WEBP:
|
||||||
if ( !imagewebp( $this -> image, $fileName ) )
|
if (!imagewebp($this->image, $fileName)) {
|
||||||
throw new RuntimeException;
|
throw new RuntimeException('Failed to save image as WEBP');
|
||||||
break;
|
|
||||||
case IMAGETYPE_GIF :
|
|
||||||
if ( !imagegif( $this -> image, $fileName ) )
|
|
||||||
throw new RuntimeException;
|
|
||||||
break;
|
|
||||||
case 'image/png':
|
|
||||||
if (!imagepng($this->image, $fileName)) {
|
|
||||||
throw new RuntimeException;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IMAGETYPE_JPEG :
|
case IMAGETYPE_GIF:
|
||||||
default :
|
if (!imagegif($this->image, $fileName)) {
|
||||||
|
throw new RuntimeException('Failed to save image as GIF');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IMAGETYPE_PNG:
|
||||||
|
if (!imagepng($this->image, $fileName)) {
|
||||||
|
throw new RuntimeException('Failed to save image as PNG');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case IMAGETYPE_JPEG:
|
||||||
|
default:
|
||||||
if (!imagejpeg($this->image, $fileName, 95)) {
|
if (!imagejpeg($this->image, $fileName, 95)) {
|
||||||
throw new RuntimeException;
|
throw new RuntimeException('Failed to save image as JPEG');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $ex) {
|
error_log("Image saved successfully to $fileName");
|
||||||
throw new RuntimeException('Error saving image file to ' . $fileName);
|
} catch (\Exception $ex) {
|
||||||
|
throw new RuntimeException('Error saving image file to ' . $fileName . ': ' . $ex->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the GD image resource
|
* Returns the GD image resource
|
||||||
*
|
*
|
||||||
* @return resource
|
* @return \GdImage
|
||||||
*/
|
*/
|
||||||
public function getResource()
|
public function getResource(): \GdImage
|
||||||
{
|
{
|
||||||
return $this->image;
|
return $this->image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current image resource width
|
* Get current image width
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getWidth()
|
public function getWidth(): int
|
||||||
{
|
{
|
||||||
return $this->width;
|
return $this->width;
|
||||||
}
|
}
|
||||||
@@ -284,8 +408,18 @@ class ImageManipulator
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getHeight()
|
public function getHeight(): int
|
||||||
{
|
{
|
||||||
return $this->height;
|
return $this->height;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Destructor to clean up the image resource
|
||||||
|
*/
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
if (isset($this->image) && $this->image instanceof \GdImage) {
|
||||||
|
imagedestroy($this->image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class S
|
|||||||
public static function get_domain( $url )
|
public static function get_domain( $url )
|
||||||
{
|
{
|
||||||
$parseUrl = parse_url( trim( $url ) );
|
$parseUrl = parse_url( trim( $url ) );
|
||||||
return trim( $parseUrl[host] ? str_replace( 'www.', '', $parseUrl[host] ) : str_replace( 'www.', '', array_shift( explode( '/', $parseUrl[path], 2 ) ) ) );
|
return trim( $parseUrl['host'] ? str_replace( 'www.', '', $parseUrl['host'] ) : str_replace( 'www.', '', array_shift( explode( '/', $parseUrl['path'], 2 ) ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function pre_dump( $value )
|
static public function pre_dump( $value )
|
||||||
@@ -237,7 +237,7 @@ class S
|
|||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
while ( list($key, $values) = each( $input ) )
|
foreach ($array as $key => $value)
|
||||||
{
|
{
|
||||||
if ( empty( $values ) )
|
if ( empty( $values ) )
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
BIN
autoload/front/.DS_Store
vendored
BIN
autoload/front/.DS_Store
vendored
Binary file not shown.
@@ -202,8 +202,12 @@ class ShopBasket
|
|||||||
|
|
||||||
$values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] );
|
$values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] );
|
||||||
|
|
||||||
|
$attributes_implode = '';
|
||||||
// generuj unikalny kod produktu dodanego do koszyka
|
// generuj unikalny kod produktu dodanego do koszyka
|
||||||
$product_code = md5( $values['product-id'] . implode( '|', $attributes ) . $values['product-message'] . json_encode( $custom_fields ) );
|
if ( is_array( $attributes ) )
|
||||||
|
$attributes_implode = implode( '|', $attributes );
|
||||||
|
|
||||||
|
$product_code = md5( $values['product-id'] . $attributes_implode . $values['product-message'] . json_encode( $custom_fields ) );
|
||||||
|
|
||||||
if ( isset( $basket[ $product_code ] ) )
|
if ( isset( $basket[ $product_code ] ) )
|
||||||
$basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ];
|
$basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ];
|
||||||
|
|||||||
@@ -65,18 +65,18 @@ class Layouts
|
|||||||
|
|
||||||
if ( !$objectData )
|
if ( !$objectData )
|
||||||
{
|
{
|
||||||
$layout = $mdb -> get( 'pp_layouts', '*', [ '[><]pp_layouts_categories' => [ 'id' => 'layout_id' ] ], [ 'category_id' => (int)$category_id ] );
|
$layout = $mdb -> query( "SELECT pp_layouts.* FROM pp_layouts JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id WHERE pp_layouts_categories.category_id = " . (int)$category_id ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||||
if ( !$layout )
|
if ( !$layout )
|
||||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
|
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
|
||||||
|
|
||||||
$cacheHandler -> set( $cacheKey, $layout );
|
$cacheHandler -> set( $cacheKey, $layout[0] );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return unserialize( $objectData );
|
return unserialize( $objectData );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $layout;
|
return $layout[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function active_layout( $page_id )
|
static public function active_layout( $page_id )
|
||||||
|
|||||||
@@ -248,11 +248,6 @@ class ShopProduct
|
|||||||
if ( is_array( $results ) )
|
if ( is_array( $results ) )
|
||||||
foreach ( $results as $row )
|
foreach ( $results as $row )
|
||||||
{
|
{
|
||||||
$row[ 'require' ] = $mdb -> get( 'pp_shop_attributes',
|
|
||||||
'required',
|
|
||||||
[ 'id' => $row[ 'attribute_id' ] ]
|
|
||||||
);
|
|
||||||
|
|
||||||
$row[ 'type' ] = $mdb -> get( 'pp_shop_attributes',
|
$row[ 'type' ] = $mdb -> get( 'pp_shop_attributes',
|
||||||
'type',
|
'type',
|
||||||
[ 'id' => $row[ 'attribute_id' ] ]
|
[ 'id' => $row[ 'attribute_id' ] ]
|
||||||
@@ -301,9 +296,9 @@ class ShopProduct
|
|||||||
|
|
||||||
$product[ 'products_related' ] = $mdb -> select( 'pp_shop_products_related', 'product_related_id', [ 'product_id' => (int)$product_id ] );
|
$product[ 'products_related' ] = $mdb -> select( 'pp_shop_products_related', 'product_related_id', [ 'product_id' => (int)$product_id ] );
|
||||||
|
|
||||||
$products_sets_1 = $mdb -> select( 'pp_shop_products_sets', 'product_sets_id', [ 'product_id' => (int)$product_id ] );
|
$set_id = $mdb -> select( 'pp_shop_product_sets_products', 'set_id', [ 'product_id' => (int)$product_id ] );
|
||||||
$products_sets_2 = $mdb -> select( 'pp_shop_products_sets', 'product_id', [ 'product_sets_id' => (int)$product_id ] );
|
$products_sets = $mdb -> select( 'pp_shop_product_sets_products', 'product_id', [ 'set_id' => (int)$set_id ] );
|
||||||
$products_sets = array_unique( array_merge( $products_sets_1, $products_sets_2 ) );
|
$products_sets = array_unique( $products_sets );
|
||||||
|
|
||||||
$product[ 'products_sets' ] = $products_sets;
|
$product[ 'products_sets' ] = $products_sets;
|
||||||
|
|
||||||
@@ -338,28 +333,6 @@ class ShopProduct
|
|||||||
return $mdb -> get( 'pp_shop_products_langs', 'warehouse_message_nonzero', [ 'AND' => [ 'product_id' => $id_product, 'lang_id' => $lang_id ] ] );
|
return $mdb -> get( 'pp_shop_products_langs', 'warehouse_message_nonzero', [ 'AND' => [ 'product_id' => $id_product, 'lang_id' => $lang_id ] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function permutation_quantity( $id_product, $permutation, bool $is_multichoice )
|
|
||||||
{
|
|
||||||
global $mdb;
|
|
||||||
|
|
||||||
if ( !$is_multichoice )
|
|
||||||
return $mdb -> get( 'pp_shop_products_stock', 'quantity', [ 'AND' => [ 'id_product' => $id_product, 'permutation' => 0 ] ] );
|
|
||||||
|
|
||||||
if ( is_array( $permutation ) )
|
|
||||||
{
|
|
||||||
foreach ( $permutation as $key => $val )
|
|
||||||
{
|
|
||||||
$permutation_id .= $val;
|
|
||||||
if ( $val != end( $permutation ) )
|
|
||||||
$permutation_id .= '_';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$permutation_id = $permutation;
|
|
||||||
|
|
||||||
return $mdb -> get( 'pp_shop_products_stock', 'quantity', [ 'AND' => [ 'id_product' => $id_product, 'permutation' => $permutation_id ] ] );
|
|
||||||
}
|
|
||||||
|
|
||||||
//TO:DO do usunięcia
|
//TO:DO do usunięcia
|
||||||
public static function product_both_price( $product_id )
|
public static function product_both_price( $product_id )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -795,7 +795,7 @@ class Product implements \ArrayAccess
|
|||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
while ( list($key, $values) = each( $input ) )
|
foreach ( $input as $key => $values )
|
||||||
{
|
{
|
||||||
if ( empty( $values ) )
|
if ( empty( $values ) )
|
||||||
continue;
|
continue;
|
||||||
@@ -834,7 +834,7 @@ class Product implements \ArrayAccess
|
|||||||
|
|
||||||
public function __get( $variable )
|
public function __get( $variable )
|
||||||
{
|
{
|
||||||
if ( array_key_exists( $variable, $this -> data ) )
|
if ( is_array( $this -> data ) and array_key_exists( $variable, $this -> data ) )
|
||||||
return $this -> $variable;
|
return $this -> $variable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Medoo database framework
|
* Medoo database framework
|
||||||
* http://medoo.in
|
* http://medoo.in
|
||||||
* Version 0.9.7
|
* Version 0.9.7
|
||||||
*
|
*
|
||||||
* Copyright 2014, Angel Lai
|
* Copyright 2014, Angel Lai
|
||||||
* Released under the MIT license
|
* Released under the MIT license
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +33,7 @@ class gdb
|
|||||||
|
|
||||||
protected $option = array();
|
protected $option = array();
|
||||||
|
|
||||||
// Variable
|
// Variable
|
||||||
protected $logs = array();
|
protected $logs = array();
|
||||||
|
|
||||||
public function __construct($options = null)
|
public function __construct($options = null)
|
||||||
@@ -131,7 +131,7 @@ class gdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->pdo = new PDO(
|
$this->pdo = new PDO(
|
||||||
$dsn,
|
$dsn,
|
||||||
$this->username,
|
$this->username,
|
||||||
$this->password,
|
$this->password,
|
||||||
$this->option
|
$this->option
|
||||||
@@ -148,14 +148,14 @@ class gdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function query($query)
|
public function query($query)
|
||||||
{
|
{
|
||||||
array_push($this->logs, $query);
|
array_push($this->logs, $query);
|
||||||
|
|
||||||
return $this->pdo->query($query);
|
return $this->pdo->query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exec($query)
|
public function exec($query)
|
||||||
{
|
{
|
||||||
array_push($this->logs, $query);
|
array_push($this->logs, $query);
|
||||||
|
|
||||||
return $this->pdo->exec($query);
|
return $this->pdo->exec($query);
|
||||||
@@ -199,7 +199,10 @@ class gdb
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode($stack, ',');
|
if ( is_array( $stack ) )
|
||||||
|
return implode( ',', $stack );
|
||||||
|
else
|
||||||
|
return $stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function array_quote($array)
|
protected function array_quote($array)
|
||||||
@@ -318,11 +321,11 @@ class gdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
$value = '%' . $value . '%';
|
$value = '%' . $value . '%';
|
||||||
|
|
||||||
$wheres[] = $column . ' LIKE ' . $this->fn_quote($key, $value);
|
$wheres[] = $column . ' LIKE ' . $this->fn_quote($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($operator, array('>', '>=', '<', '<=')))
|
if (in_array($operator, array('>', '>=', '<', '<=')))
|
||||||
{
|
{
|
||||||
if (is_numeric($value))
|
if (is_numeric($value))
|
||||||
@@ -835,7 +838,7 @@ class gdb
|
|||||||
if (isset($data[0]))
|
if (isset($data[0]))
|
||||||
{
|
{
|
||||||
$column = $where == null ? $join : $column;
|
$column = $where == null ? $join : $column;
|
||||||
|
|
||||||
if (is_string($column) && $column != '*')
|
if (is_string($column) && $column != '*')
|
||||||
{
|
{
|
||||||
return $data[ 0 ][ $column ];
|
return $data[ 0 ][ $column ];
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
class grid
|
class grid
|
||||||
{
|
{
|
||||||
protected $table;
|
protected $table;
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $dir;
|
protected $dir;
|
||||||
|
|
||||||
public $order;
|
public $order;
|
||||||
public $search;
|
public $search;
|
||||||
public $filters;
|
public $filters;
|
||||||
public $columns_view;
|
public $columns_view;
|
||||||
public $hidden_columns;
|
public $hidden_columns;
|
||||||
public $columns_edit;
|
public $columns_edit;
|
||||||
public $summary;
|
public $summary;
|
||||||
|
|
||||||
public $clear_cache = true;
|
public $clear_cache = true;
|
||||||
|
|
||||||
public $print = false;
|
public $print = false;
|
||||||
public $hide_columns = true;
|
public $hide_columns = true;
|
||||||
public $show_paging = true;
|
public $show_paging = true;
|
||||||
|
|
||||||
public $title = null;
|
public $title = null;
|
||||||
|
|
||||||
public $src = null;
|
public $src = null;
|
||||||
public $src_filtered = null;
|
public $src_filtered = null;
|
||||||
|
|
||||||
public $id = 'id';
|
public $id = 'id';
|
||||||
public $columns = '*';
|
public $columns = '*';
|
||||||
public $cp = 1;
|
public $cp = 1;
|
||||||
@@ -32,13 +32,13 @@ class grid
|
|||||||
public $where = array();
|
public $where = array();
|
||||||
public $join = null;
|
public $join = null;
|
||||||
public $condensed = false;
|
public $condensed = false;
|
||||||
|
|
||||||
public $sql = null;
|
public $sql = null;
|
||||||
public $sql_count = null;
|
public $sql_count = null;
|
||||||
|
|
||||||
public $include_plugins = true;
|
public $include_plugins = true;
|
||||||
|
|
||||||
public $gdb_opt = array(
|
public $gdb_opt = array(
|
||||||
'database_type' => 'mysql',
|
'database_type' => 'mysql',
|
||||||
'database_name' => 'db_name',
|
'database_name' => 'db_name',
|
||||||
'server' => 'db_host',
|
'server' => 'db_host',
|
||||||
@@ -46,96 +46,97 @@ class grid
|
|||||||
'password' => 'db_pass',
|
'password' => 'db_pass',
|
||||||
'port' => 'db_port'
|
'port' => 'db_port'
|
||||||
);
|
);
|
||||||
|
|
||||||
public $empty_txt = 'Brak danych w tabeli.';
|
public $empty_txt = 'Brak danych w tabeli.';
|
||||||
|
|
||||||
public $multiselect = null;
|
public $multiselect = null;
|
||||||
public $multidelete_url = null;
|
public $multidelete_url = null;
|
||||||
|
|
||||||
public $buttons = null;
|
public $buttons = null;
|
||||||
|
|
||||||
public $actions = array( 'delete' => false, 'delete_url' => null, 'add' => false, 'add_url' => null, 'edit' => false );
|
public $actions = array( 'delete' => false, 'delete_url' => null, 'add' => false, 'add_url' => null, 'edit' => false );
|
||||||
|
|
||||||
function __construct( $table, $name = '' )
|
function __construct( $table, $name = '' )
|
||||||
{
|
{
|
||||||
$this -> table = $table;
|
$this -> table = $table;
|
||||||
$this -> name = $name;
|
$this -> name = $name;
|
||||||
$this -> dir = dirname( __FILE__ );
|
$this -> dir = dirname( __FILE__ );
|
||||||
|
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
if ( !empty( $_SESSION[ 'g' . $g_table . 'filters' ] ) )
|
if ( !empty( $_SESSION[ 'g' . $g_table . 'filters' ] ) )
|
||||||
$this -> filters = $_SESSION[ 'g' . $g_table . 'filters' ];
|
$this -> filters = $_SESSION[ 'g' . $g_table . 'filters' ];
|
||||||
|
|
||||||
if ( !empty( $_SESSION[ 'g' . $g_table . 'limit' ] ) )
|
if ( !empty( $_SESSION[ 'g' . $g_table . 'limit' ] ) )
|
||||||
$this -> limit = $_SESSION[ 'g' . $g_table . 'limit' ];
|
$this -> limit = $_SESSION[ 'g' . $g_table . 'limit' ];
|
||||||
|
|
||||||
if ( !empty( $_SESSION[ 'g' . $g_table . 'order' ] ) )
|
if ( !empty( $_SESSION[ 'g' . $g_table . 'order' ] ) )
|
||||||
$this -> order = $_SESSION[ 'g' . $g_table . 'order' ];
|
$this -> order = $_SESSION[ 'g' . $g_table . 'order' ];
|
||||||
|
|
||||||
if ( $this -> clear_cache )
|
if ( $this -> clear_cache )
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
if ( is_array( $_SESSION ) ) foreach ( $_SESSION as $key => $val )
|
if ( is_array( $_SESSION ) ) foreach ( $_SESSION as $key => $val )
|
||||||
{
|
{
|
||||||
if ( $key != 'g' . $g_table and @get_class( $val ) == '__PHP_Incomplete_Class' )
|
if ($key != 'g' . $g_table && is_object($val) && get_class($val) == '__PHP_Incomplete_Class') {
|
||||||
unset( $_SESSION[ $key ] );
|
unset($_SESSION[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hide_column( $column, $hidden )
|
public function hide_column( $column, $hidden )
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
$db = $this -> connectToDb();
|
$db = $this -> connectToDb();
|
||||||
|
|
||||||
$results = $db -> get( 'grid_settings', 'settings', [ 'name' => $g_table ] );
|
$results = $db -> get( 'grid_settings', 'settings', [ 'name' => $g_table ] );
|
||||||
$results = unserialize( $results );
|
$results = unserialize( $results );
|
||||||
|
|
||||||
$results['hidden_columns'][ $column ] = $hidden;
|
$results['hidden_columns'][ $column ] = $hidden;
|
||||||
|
|
||||||
if ( $db -> count( 'grid_settings', [ 'name' => $g_table ] ) )
|
if ( $db -> count( 'grid_settings', [ 'name' => $g_table ] ) )
|
||||||
$db -> update( 'grid_settings', [ 'settings' => serialize( $results ) ], [ 'name' => $g_table ] );
|
$db -> update( 'grid_settings', [ 'settings' => serialize( $results ) ], [ 'name' => $g_table ] );
|
||||||
else
|
else
|
||||||
$db -> insert( 'grid_settings', [ 'settings' => serialize( $results ), 'name' => $g_table ] );
|
$db -> insert( 'grid_settings', [ 'settings' => serialize( $results ), 'name' => $g_table ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function drawEdit( $id )
|
public function drawEdit( $id )
|
||||||
{
|
{
|
||||||
$values = get_object_vars( $this );
|
$values = get_object_vars( $this );
|
||||||
|
|
||||||
$view = new gridView( $this -> dir . '/templates/' );
|
$view = new gridView( $this -> dir . '/templates/' );
|
||||||
$view -> values = $values;
|
$view -> values = $values;
|
||||||
$view -> element = $this -> getElement( $id );
|
$view -> element = $this -> getElement( $id );
|
||||||
return $view -> render( 'edit' );
|
return $view -> render( 'edit' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw()
|
public function draw()
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
$db = $this -> connectToDb();
|
$db = $this -> connectToDb();
|
||||||
|
|
||||||
$results = $db -> get( 'grid_settings', 'settings', [ 'name' => $g_table ] );
|
$results = $db -> get( 'grid_settings', 'settings', [ 'name' => $g_table ] );
|
||||||
$results = unserialize( $results );
|
$results = unserialize( $results );
|
||||||
|
|
||||||
$this -> hidden_columns = $results['hidden_columns'];
|
$this -> hidden_columns = $results['hidden_columns'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(int)$_SESSION[ 'g' . $g_table . 'cp' ] ? $this -> cp = (int)$_SESSION[ 'g' . $g_table . 'cp' ] : $this -> cp = 1;
|
(int)$_SESSION[ 'g' . $g_table . 'cp' ] ? $this -> cp = (int)$_SESSION[ 'g' . $g_table . 'cp' ] : $this -> cp = 1;
|
||||||
|
|
||||||
$_SESSION[ 'g' . $g_table ] = $this;
|
$_SESSION[ 'g' . $g_table ] = $this;
|
||||||
|
|
||||||
$values = get_object_vars( $this );
|
$values = get_object_vars( $this );
|
||||||
$values['content'] = $this -> drawResults();
|
$values['content'] = $this -> drawResults();
|
||||||
|
|
||||||
$view = new gridView( $this -> dir . '/templates/' );
|
$view = new gridView( $this -> dir . '/templates/' );
|
||||||
$view -> values = $values;
|
$view -> values = $values;
|
||||||
return $view -> render( 'container' );
|
return $view -> render( 'container' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connectToDb()
|
public function connectToDb()
|
||||||
{
|
{
|
||||||
return new gdb( [
|
return new gdb( [
|
||||||
@@ -148,14 +149,14 @@ class grid
|
|||||||
'charset' => 'utf8'
|
'charset' => 'utf8'
|
||||||
] );
|
] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCSV()
|
public function getCSV()
|
||||||
{
|
{
|
||||||
if ( is_array( $this -> src ) )
|
if ( is_array( $this -> src ) )
|
||||||
$results = $this -> getDataSrc();
|
$results = $this -> getDataSrc();
|
||||||
else
|
else
|
||||||
$results = $this -> getData( true );
|
$results = $this -> getData( true );
|
||||||
|
|
||||||
if ( is_array( $this -> columns_view ) ) foreach ( $this -> columns_view as $column )
|
if ( is_array( $this -> columns_view ) ) foreach ( $this -> columns_view as $column )
|
||||||
{
|
{
|
||||||
$array_row = array();
|
$array_row = array();
|
||||||
@@ -164,7 +165,7 @@ class grid
|
|||||||
$headers[] = $column['name'];
|
$headers[] = $column['name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||||
{
|
{
|
||||||
$array_row = array();
|
$array_row = array();
|
||||||
@@ -208,15 +209,15 @@ class grid
|
|||||||
}
|
}
|
||||||
$array[] = $array_row;
|
$array[] = $array_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
$now = gmdate( "D, d M Y H:i:s" );
|
$now = gmdate( "D, d M Y H:i:s" );
|
||||||
|
|
||||||
header( 'Content-Encoding: UTF-8' );
|
header( 'Content-Encoding: UTF-8' );
|
||||||
header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" );
|
header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" );
|
||||||
header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" );
|
header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" );
|
||||||
header( "Last-Modified: {$now} GMT" );
|
header( "Last-Modified: {$now} GMT" );
|
||||||
|
|
||||||
// force download
|
// force download
|
||||||
header( "Content-Type: application/force-download" );
|
header( "Content-Type: application/force-download" );
|
||||||
header( "Content-Type: application/octet-stream" );
|
header( "Content-Type: application/octet-stream" );
|
||||||
header( "Content-Type: application/download" );
|
header( "Content-Type: application/download" );
|
||||||
@@ -233,11 +234,11 @@ class grid
|
|||||||
fclose( $df );
|
fclose( $df );
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function printResults()
|
public function printResults()
|
||||||
{
|
{
|
||||||
$values = get_object_vars( $this );
|
$values = get_object_vars( $this );
|
||||||
|
|
||||||
if ( is_array( $this -> src ) )
|
if ( is_array( $this -> src ) )
|
||||||
{
|
{
|
||||||
$values['count'] = $this -> getDataCountSrc();
|
$values['count'] = $this -> getDataCountSrc();
|
||||||
@@ -247,30 +248,30 @@ class grid
|
|||||||
$values['count'] = $this -> getDataCount();
|
$values['count'] = $this -> getDataCount();
|
||||||
$values['summary'] = $this -> getDataSummary();
|
$values['summary'] = $this -> getDataSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this -> cp = 1;
|
$this -> cp = 1;
|
||||||
$this -> limit = $values['count'];
|
$this -> limit = $values['count'];
|
||||||
|
|
||||||
if ( is_array( $this -> src ) )
|
if ( is_array( $this -> src ) )
|
||||||
$values['results'] = $this -> getDataSrc();
|
$values['results'] = $this -> getDataSrc();
|
||||||
else
|
else
|
||||||
$values['results'] = $this -> getData();
|
$values['results'] = $this -> getData();
|
||||||
|
|
||||||
$view = new gridView( $this -> dir . '/templates/' );
|
$view = new gridView( $this -> dir . '/templates/' );
|
||||||
$view -> values = $values;
|
$view -> values = $values;
|
||||||
return $view -> render( 'print' );
|
return $view -> render( 'print' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_data_count_sql()
|
public function get_data_count_sql()
|
||||||
{
|
{
|
||||||
$db = $this ->connectToDb();
|
$db = $this ->connectToDb();
|
||||||
|
|
||||||
$where = $this -> getWhereCondition();
|
$where = $this -> getWhereCondition();
|
||||||
$where = $db -> where_clause( $where );
|
$where = $db -> where_clause( $where );
|
||||||
|
|
||||||
if ( strpos( $this -> sql_count, 'WHERE' ) !== false and !empty( $where ) )
|
if ( strpos( $this -> sql_count, 'WHERE' ) !== false and !empty( $where ) )
|
||||||
$where = str_replace( 'WHERE', 'AND', $where );
|
$where = str_replace( 'WHERE', 'AND', $where );
|
||||||
|
|
||||||
$this -> sql_tmp = str_replace( '[where]', $where, $this -> sql_count );
|
$this -> sql_tmp = str_replace( '[where]', $where, $this -> sql_count );
|
||||||
|
|
||||||
$query = $db -> query( $this -> sql_tmp );
|
$query = $db -> query( $this -> sql_tmp );
|
||||||
@@ -289,14 +290,14 @@ class grid
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_data_sql( $print = false )
|
public function get_data_sql( $print = false )
|
||||||
{
|
{
|
||||||
$db = $this -> connectToDb();
|
$db = $this -> connectToDb();
|
||||||
|
|
||||||
$where = $this -> getWhereCondition();
|
$where = $this -> getWhereCondition();
|
||||||
$where = $db -> where_clause( $where );
|
$where = $db -> where_clause( $where );
|
||||||
|
|
||||||
if ( strpos( $this -> sql, 'WHERE' ) !== false and !empty( $where ) )
|
if ( strpos( $this -> sql, 'WHERE' ) !== false and !empty( $where ) )
|
||||||
$where = str_replace( 'WHERE', 'AND', $where );
|
$where = str_replace( 'WHERE', 'AND', $where );
|
||||||
|
|
||||||
@@ -304,10 +305,10 @@ class grid
|
|||||||
$this -> sql_tmp = $this -> sql . ' LIMIT ' . $this -> limit . ' OFFSET ' . ( $this -> cp - 1 ) * $this -> limit;
|
$this -> sql_tmp = $this -> sql . ' LIMIT ' . $this -> limit . ' OFFSET ' . ( $this -> cp - 1 ) * $this -> limit;
|
||||||
else
|
else
|
||||||
$this -> sql_tmp = $this -> sql;
|
$this -> sql_tmp = $this -> sql;
|
||||||
$this -> sql_tmp = str_replace( '[where]', $where, $this -> sql_tmp );
|
$this -> sql_tmp = str_replace( '[where]', $where, $this -> sql_tmp );
|
||||||
$this -> sql_tmp = str_replace( '[order_p1]', $this -> order['column'], $this -> sql_tmp );
|
$this -> sql_tmp = str_replace( '[order_p1]', $this -> order['column'], $this -> sql_tmp );
|
||||||
$this -> sql_tmp = str_replace( '[order_p2]', $this -> order['type'], $this -> sql_tmp );
|
$this -> sql_tmp = str_replace( '[order_p2]', $this -> order['type'], $this -> sql_tmp );
|
||||||
|
|
||||||
$query = $db -> query( $this -> sql_tmp );
|
$query = $db -> query( $this -> sql_tmp );
|
||||||
if ( $query )
|
if ( $query )
|
||||||
{
|
{
|
||||||
@@ -324,11 +325,11 @@ class grid
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function drawResults()
|
public function drawResults()
|
||||||
{
|
{
|
||||||
$values = get_object_vars( $this );
|
$values = get_object_vars( $this );
|
||||||
|
|
||||||
if ( is_array( $this -> src ) )
|
if ( is_array( $this -> src ) )
|
||||||
$values['count'] = $this -> getDataCountSrc();
|
$values['count'] = $this -> getDataCountSrc();
|
||||||
else if ( isset( $this -> sql ) and isset( $this -> sql_count ) )
|
else if ( isset( $this -> sql ) and isset( $this -> sql_count ) )
|
||||||
@@ -338,51 +339,51 @@ class grid
|
|||||||
$values['count'] = $this -> getDataCount();
|
$values['count'] = $this -> getDataCount();
|
||||||
$values['summary'] = $this -> getDataSummary();
|
$values['summary'] = $this -> getDataSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ls = ceil( $values['count'] / $this -> limit );
|
$ls = ceil( $values['count'] / $this -> limit );
|
||||||
|
|
||||||
if ( !(int)$ls )
|
if ( !(int)$ls )
|
||||||
$ls = 1;
|
$ls = 1;
|
||||||
|
|
||||||
if ( $this -> cp > $ls )
|
if ( $this -> cp > $ls )
|
||||||
{
|
{
|
||||||
$this -> cp = $ls;
|
$this -> cp = $ls;
|
||||||
$values['cp'] = $ls;
|
$values['cp'] = $ls;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_array( $this -> src ) )
|
if ( is_array( $this -> src ) )
|
||||||
$values['results'] = $this -> getDataSrc();
|
$values['results'] = $this -> getDataSrc();
|
||||||
else if ( isset( $this -> sql ) and isset( $this -> sql_count ) )
|
else if ( isset( $this -> sql ) and isset( $this -> sql_count ) )
|
||||||
$values['results'] = $this -> get_data_sql();
|
$values['results'] = $this -> get_data_sql();
|
||||||
else
|
else
|
||||||
$values['results'] = $this -> getData();
|
$values['results'] = $this -> getData();
|
||||||
|
|
||||||
$view = new gridView( $this -> dir . '/templates/' );
|
$view = new gridView( $this -> dir . '/templates/' );
|
||||||
$view -> values = $values;
|
$view -> values = $values;
|
||||||
return $view -> render( 'results' );
|
return $view -> render( 'results' );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete( $id )
|
public function delete( $id )
|
||||||
{
|
{
|
||||||
return $this -> connectToDb() -> delete( $this -> table, [ $this -> id => $id ] );
|
return $this -> connectToDb() -> delete( $this -> table, [ $this -> id => $id ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWhereCondition()
|
public function getWhereCondition()
|
||||||
{
|
{
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
$where['AND'] = $this -> where;
|
$where['AND'] = $this -> where;
|
||||||
|
|
||||||
if ( $this -> filters )
|
if ( $this -> filters )
|
||||||
{
|
{
|
||||||
foreach ( $this -> filters as $key => $val )
|
foreach ( $this -> filters as $key => $val )
|
||||||
{
|
{
|
||||||
if ( $val['type'] == 'like' )
|
if ( $val['type'] == 'like' )
|
||||||
$where['AND'] = array_merge( $where['AND'], [ $key . '[~]' => $val['value'] ] );
|
$where['AND'] = array_merge( $where['AND'], [ $key . '[~]' => $val['value'] ] );
|
||||||
|
|
||||||
if ( $val['type'] == 'equal' )
|
if ( $val['type'] == 'equal' )
|
||||||
$where['AND'] = array_merge( $where['AND'], [ $key => $val['value'] ] );
|
$where['AND'] = array_merge( $where['AND'], [ $key => $val['value'] ] );
|
||||||
|
|
||||||
if ( $val['type'] == 'date_range' )
|
if ( $val['type'] == 'date_range' )
|
||||||
{
|
{
|
||||||
$dates = explode( ' - ', $val['value'] );
|
$dates = explode( ' - ', $val['value'] );
|
||||||
@@ -391,13 +392,13 @@ class grid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count( $where['AND'] ) )
|
if ( count( $where['AND'] ) )
|
||||||
return $where;
|
return $where;
|
||||||
else
|
else
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function searchSrc( $array, $column, $value, $type = 'equal' )
|
public static function searchSrc( $array, $column, $value, $type = 'equal' )
|
||||||
{
|
{
|
||||||
if ( is_array( $array ) ) foreach ( $array as $key => $val )
|
if ( is_array( $array ) ) foreach ( $array as $key => $val )
|
||||||
@@ -407,7 +408,7 @@ class grid
|
|||||||
if ( $val[ $column ] == $value )
|
if ( $val[ $column ] == $value )
|
||||||
$array_tmp[] = $val;
|
$array_tmp[] = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $type == 'like' )
|
if ( $type == 'like' )
|
||||||
{
|
{
|
||||||
if ( strpos( mb_strtolower( $val[ $column ], 'UTF-8' ), mb_strtolower( $value, 'UTF-8' ) ) !== false )
|
if ( strpos( mb_strtolower( $val[ $column ], 'UTF-8' ), mb_strtolower( $value, 'UTF-8' ) ) !== false )
|
||||||
@@ -416,28 +417,28 @@ class grid
|
|||||||
}
|
}
|
||||||
return $array_tmp;
|
return $array_tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filtrDataSrc()
|
public function filtrDataSrc()
|
||||||
{
|
{
|
||||||
$this -> src_filtered = $this -> src;
|
$this -> src_filtered = $this -> src;
|
||||||
|
|
||||||
if ( $this -> filters )
|
if ( $this -> filters )
|
||||||
{
|
{
|
||||||
foreach ( $this -> filters as $key => $val )
|
foreach ( $this -> filters as $key => $val )
|
||||||
{
|
{
|
||||||
if ( $val['type'] == 'like' )
|
if ( $val['type'] == 'like' )
|
||||||
$this -> src_filtered = $this -> searchSrc( $this -> src_filtered, $key, $val['value'], 'like' );
|
$this -> src_filtered = $this -> searchSrc( $this -> src_filtered, $key, $val['value'], 'like' );
|
||||||
|
|
||||||
if ( $val['type'] == 'equal' )
|
if ( $val['type'] == 'equal' )
|
||||||
$this -> src_filtered = $this -> searchSrc( $this -> src_filtered, $key, $val['value'], 'equal' );
|
$this -> src_filtered = $this -> searchSrc( $this -> src_filtered, $key, $val['value'], 'equal' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataSummary()
|
public function getDataSummary()
|
||||||
{
|
{
|
||||||
$where = self::getWhereCondition();
|
$where = self::getWhereCondition();
|
||||||
|
|
||||||
if ( is_array( $this -> summary ) ) foreach ( $this -> summary as $key )
|
if ( is_array( $this -> summary ) ) foreach ( $this -> summary as $key )
|
||||||
{
|
{
|
||||||
if ( $this -> join )
|
if ( $this -> join )
|
||||||
@@ -447,48 +448,48 @@ class grid
|
|||||||
}
|
}
|
||||||
return $summary;
|
return $summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataCountSrc()
|
public function getDataCountSrc()
|
||||||
{
|
{
|
||||||
$this -> filtrDataSrc();
|
$this -> filtrDataSrc();
|
||||||
return count( $this -> src_filtered );
|
return count( $this -> src_filtered );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataCount()
|
public function getDataCount()
|
||||||
{
|
{
|
||||||
$where = self::getWhereCondition();
|
$where = self::getWhereCondition();
|
||||||
|
|
||||||
if ( $this -> join )
|
if ( $this -> join )
|
||||||
$results = $this -> connectToDb() -> count( $this -> table, $this -> join, '*', $where );
|
$results = $this -> connectToDb() -> count( $this -> table, $this -> join, '*', $where );
|
||||||
else
|
else
|
||||||
$results = $this -> connectToDb() -> count( $this -> table, $where );
|
$results = $this -> connectToDb() -> count( $this -> table, $where );
|
||||||
|
|
||||||
if ( $results )
|
if ( $results )
|
||||||
return $results;
|
return $results;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataSrc()
|
public function getDataSrc()
|
||||||
{
|
{
|
||||||
if ( $this -> order )
|
if ( $this -> order )
|
||||||
$this -> src_filtered = $this -> sortByColumn( $this -> src_filtered, $this -> order['column'], $this -> order['type'] );
|
$this -> src_filtered = $this -> sortByColumn( $this -> src_filtered, $this -> order['column'], $this -> order['type'] );
|
||||||
|
|
||||||
$array_tmp = $this -> src_filtered;
|
$array_tmp = $this -> src_filtered;
|
||||||
|
|
||||||
if ( is_array( $array_tmp ) )
|
if ( is_array( $array_tmp ) )
|
||||||
return array_splice( $array_tmp, ( $this -> cp - 1 ) * $this -> limit, $this -> limit );
|
return array_splice( $array_tmp, ( $this -> cp - 1 ) * $this -> limit, $this -> limit );
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getData( $csv = false )
|
public function getData( $csv = false )
|
||||||
{
|
{
|
||||||
$where = self::getWhereCondition();
|
$where = self::getWhereCondition();
|
||||||
|
|
||||||
if ( $this -> order )
|
if ( $this -> order )
|
||||||
$where = array_merge( $where, [ 'ORDER' => $this -> order['column'] . ' ' . $this -> order['type'] ] );
|
$where = array_merge( $where, [ 'ORDER' => $this -> order['column'] . ' ' . $this -> order['type'] ] );
|
||||||
|
|
||||||
if ( $this -> limit and $this -> show_paging === true and !$csv )
|
if ( $this -> limit and $this -> show_paging === true and !$csv )
|
||||||
$where = array_merge( $where, [ 'LIMIT' => [ ( $this -> cp - 1 ) * $this -> limit, $this -> limit ] ] );
|
$where = array_merge( $where, [ 'LIMIT' => [ ( $this -> cp - 1 ) * $this -> limit, $this -> limit ] ] );
|
||||||
|
|
||||||
@@ -496,18 +497,18 @@ class grid
|
|||||||
$results = $this -> connectToDb() -> select( $this -> table, $this -> join, $this -> columns, $where );
|
$results = $this -> connectToDb() -> select( $this -> table, $this -> join, $this -> columns, $where );
|
||||||
else
|
else
|
||||||
$results = $this -> connectToDb() -> select( $this -> table, $this -> columns, $where );
|
$results = $this -> connectToDb() -> select( $this -> table, $this -> columns, $where );
|
||||||
|
|
||||||
if ( $results )
|
if ( $results )
|
||||||
return $results;
|
return $results;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getElement( $id )
|
public function getElement( $id )
|
||||||
{
|
{
|
||||||
return $this -> connectToDb() -> get( $this -> table, '*', [ $this -> id => $id ] );
|
return $this -> connectToDb() -> get( $this -> table, '*', [ $this -> id => $id ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveElement( $values )
|
public function saveElement( $values )
|
||||||
{
|
{
|
||||||
if ( !$values[ $this -> id ] )
|
if ( !$values[ $this -> id ] )
|
||||||
@@ -518,12 +519,12 @@ class grid
|
|||||||
else
|
else
|
||||||
return $this -> connectToDb() -> update( $this -> table, $values, [ $this -> id => $values[ $this -> id ] ] );
|
return $this -> connectToDb() -> update( $this -> table, $values, [ $this -> id => $values[ $this -> id ] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function sortByColumn( &$arr, $col, $sort )
|
public static function sortByColumn( &$arr, $col, $sort )
|
||||||
{
|
{
|
||||||
setlocale( LC_COLLATE, 'pl_PL.utf-8' );
|
setlocale( LC_COLLATE, 'pl_PL.utf-8' );
|
||||||
$sort == 'ASC' ? $dir = SORT_ASC : $dir = SORT_DESC;
|
$sort == 'ASC' ? $dir = SORT_ASC : $dir = SORT_DESC;
|
||||||
|
|
||||||
$sort_col = array();
|
$sort_col = array();
|
||||||
if ( is_array( $arr ) )
|
if ( is_array( $arr ) )
|
||||||
{
|
{
|
||||||
@@ -534,46 +535,46 @@ class grid
|
|||||||
}
|
}
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function validateDate( $date )
|
public static function validateDate( $date )
|
||||||
{
|
{
|
||||||
if ( date( 'Y-m-d', strtotime( $date ) ) != '1970-01-01' )
|
if ( date( 'Y-m-d', strtotime( $date ) ) != '1970-01-01' )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save_limit( $limit )
|
public function save_limit( $limit )
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
$_SESSION[ 'g' . $g_table . 'limit' ] = $limit;
|
$_SESSION[ 'g' . $g_table . 'limit' ] = $limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save_order()
|
public function save_order()
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
$_SESSION[ 'g' . $g_table . 'order' ] = $this -> order;
|
$_SESSION[ 'g' . $g_table . 'order' ] = $this -> order;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save_filters()
|
public function save_filters()
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
$_SESSION[ 'g' . $g_table . 'filters' ] = $this -> filters;
|
$_SESSION[ 'g' . $g_table . 'filters' ] = $this -> filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_cp( $cp )
|
public function set_cp( $cp )
|
||||||
{
|
{
|
||||||
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
$this -> name ? $g_table = $this -> name : $g_table = $this -> table;
|
||||||
|
|
||||||
$_SESSION[ 'g' . $g_table . 'cp'] = $cp;
|
$_SESSION[ 'g' . $g_table . 'cp'] = $cp;
|
||||||
$this -> cp = $cp;
|
$this -> cp = $cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParams( $string )
|
public function getParams( $string )
|
||||||
{
|
{
|
||||||
$params = array();
|
$params = array();
|
||||||
|
|
||||||
preg_match_all( '/\[[a-zA-Z0-9_]*\]/', $string, $results_tmp1 );
|
preg_match_all( '/\[[a-zA-Z0-9_]*\]/', $string, $results_tmp1 );
|
||||||
if ( is_array( $results_tmp1[0] ) ) foreach ( $results_tmp1[0] as $row_tmp1 )
|
if ( is_array( $results_tmp1[0] ) ) foreach ( $results_tmp1[0] as $row_tmp1 )
|
||||||
{
|
{
|
||||||
@@ -584,7 +585,7 @@ class grid
|
|||||||
}
|
}
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convertString( $string, $row )
|
public function convertString( $string, $row )
|
||||||
{
|
{
|
||||||
$out = $string;
|
$out = $string;
|
||||||
@@ -599,11 +600,11 @@ class grid
|
|||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convertStringJS( $string )
|
public function convertStringJS( $string )
|
||||||
{
|
{
|
||||||
$out = 'var out = "' . addslashes( $string ) . '";' . chr( 13 );
|
$out = 'var out = "' . addslashes( $string ) . '";' . chr( 13 );
|
||||||
|
|
||||||
preg_match_all( '/\[[a-zA-Z0-9_]*\]/', $string, $results_tmp1 );
|
preg_match_all( '/\[[a-zA-Z0-9_]*\]/', $string, $results_tmp1 );
|
||||||
if ( is_array( $results_tmp1[0] ) ) foreach ( $results_tmp1[0] as $row_tmp1 )
|
if ( is_array( $results_tmp1[0] ) ) foreach ( $results_tmp1[0] as $row_tmp1 )
|
||||||
{
|
{
|
||||||
|
|||||||
2307
libraries/rb.php
2307
libraries/rb.php
File diff suppressed because it is too large
Load Diff
BIN
templates/.DS_Store
vendored
BIN
templates/.DS_Store
vendored
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
<? if ( $this -> order['status'] == 1 ):?>
|
<? if ( $this -> order['status'] == 1 or $this -> order['status'] == 4 ):?>
|
||||||
<div id="payment-confirmation">
|
<div id="payment-confirmation">
|
||||||
<div class="bold blue text-center">Płatność została zatwierdzona. Dziękujemy za wybranie naszych usług.</div>
|
<div class="bold blue text-center">Płatność została zatwierdzona. Dziękujemy za wybranie naszych usług.</div>
|
||||||
<div class="text-center">Nasz system zweryfikuje Państwa zamówienie w ciągu kilku minut.</div>
|
<div class="text-center">Nasz system zweryfikuje Państwa zamówienie w ciągu kilku minut.</div>
|
||||||
@@ -24,8 +24,26 @@
|
|||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<? endif;?>
|
<? else:?>
|
||||||
<? if ( \S::get_session( 'ekomi-purchase' ) and $this -> settings['ekomi_survey'] ):?>
|
<div id="payment-confirmation">
|
||||||
<? unset( $_SESSION['ekomi-purchase'] );?>
|
<div class="bold red text-center">Płatność oczekuje na zatwierdzenie.</div>
|
||||||
<?= $this -> settings['ekomi_survey'];?>
|
<div class="text-center">Nasz system zweryfikuje Państwa zamówienie w ciągu kilku minut.</div>
|
||||||
|
<p></p>
|
||||||
|
<table class="table table-stripped table-bordered payment-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="text-center" colspan="2">Informacje o płatności</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="text-bold">Zamówienie nr:</td><td><?= $this -> order['number'];?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="text-bold">Data transakcji:</td><td><?= date( 'Y-m-d H:i', strtotime( $this -> order['date_order'] ) );?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" class="text-right
|
||||||
<? endif;?>
|
<? endif;?>
|
||||||
Reference in New Issue
Block a user