first commit
This commit is contained in:
473
autoload/admin/factory/class.Articles.php
Normal file
473
autoload/admin/factory/class.Articles.php
Normal file
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class Articles
|
||||
{
|
||||
public static function gallery_order_save( $article_id, $order )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$order = explode( ';', $order );
|
||||
if ( is_array( $order ) and !empty( $order ) ) foreach ( $order as $image_id )
|
||||
{
|
||||
$mdb -> update( 'pp_articles_images', [
|
||||
'o' => $i++
|
||||
], [
|
||||
'AND' => [
|
||||
'article_id' => $article_id,
|
||||
'id' => $image_id
|
||||
]
|
||||
] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function image_alt_change( $image_id, $image_alt )
|
||||
{
|
||||
global $mdb;
|
||||
$result = $mdb -> update( 'pp_articles_images', [
|
||||
'alt' => $image_alt
|
||||
], [
|
||||
'id' => $image_id
|
||||
] );
|
||||
\S::delete_cache();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function article_url( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT seo_link FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = " . (int)$article_id . " AND seo_link != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = self::article_title( $article_id );
|
||||
return 'a-' . $article_id . '-' . \S::seo( $title );
|
||||
}
|
||||
else
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public static function articles_by_date_add( $date_start, $date_end )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'id '
|
||||
. 'FROM '
|
||||
. 'pp_articles '
|
||||
. 'WHERE '
|
||||
. 'status = 1 '
|
||||
. 'AND '
|
||||
. 'date_add BETWEEN \'' . $date_start . '\' AND \'' . $date_end . '\' '
|
||||
. 'ORDER BY '
|
||||
. 'date_add DESC' ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$articles[] = \front\factory\Articles::article_details( $row['id'], 'pl' );
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public static function article_pages( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT page_id FROM pp_articles_pages WHERE article_id = " . (int)$article_id ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( $out == '' )
|
||||
$out .= ' - ';
|
||||
|
||||
$out .= \admin\factory\Pages::page_title( $row['page_id'] );
|
||||
|
||||
if ( end( $results ) != $row )
|
||||
$out .= ' / ';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function article_title( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
$results = $mdb -> query( "SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = " . (int)$article_id . " AND title != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
return $results[0]['title'];
|
||||
}
|
||||
|
||||
public static function articles_set_archive( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_articles', [ 'status' => -1 ], [ 'id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
public static function file_name_change( $file_id, $file_name )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_files', [ 'name' => $file_name ], [ 'id' => (int)$file_id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delete_file( $file_id )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_files', [ 'to_delete' => 1 ], [ 'id' => (int)$file_id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delete_img( $image_id )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_images', [ 'to_delete' => 1 ], [ 'id' => (int)$image_id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function article_details( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] ) )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_articles_langs', '*', [ 'article_id' => (int)$article_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$article['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'DESC' ] ] );
|
||||
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
|
||||
$article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_articles_pages', 'o' );
|
||||
}
|
||||
|
||||
public static function article_save(
|
||||
$article_id, $title, $main_image, $entry, $text, $table_of_contents, $status, $show_title, $show_table_of_contents, $show_date_add, $date_add, $show_date_modify, $date_modify, $seo_link, $meta_title, $meta_description, $meta_keywords, $layout_id, $pages,
|
||||
$noindex, $repeat_entry, $copy_from, $social_icons, $block_direct_access )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$article_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles', [
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
|
||||
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
|
||||
'date_add' => date( 'Y-m-d H:i:s' ),
|
||||
'date_modify' => date( 'Y-m-d H:i:s' ),
|
||||
'modify_by' => $user['id'],
|
||||
'layout_id' => $layout_id ? (int)$layout_id : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeat_entry == 'on' ? 1 : 0,
|
||||
'social_icons' => $social_icons == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $show_table_of_contents == 'on' ? 1 : 0,
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'main_image' => $main_image[$key] != '' ? $main_image[$key] : null,
|
||||
'entry' => $entry[$key] != '' ? $entry[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'table_of_contents' => $table_of_contents[$key] != '' ? $table_of_contents[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key] == 'on' ? 1 : 0,
|
||||
'copy_from' => $copy_from[$key] != '' ? $copy_from[$key] : null,
|
||||
'block_direct_access' => $block_direct_access[$key] == 'on' ? 1 : 0
|
||||
] );
|
||||
}
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$pages,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_files/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => $id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
/* zdjęcia */
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_images/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '../' . $new_file_name ) )
|
||||
{
|
||||
$ext = strrpos( $new_file_name, '.' );
|
||||
$fileName_a = substr( $new_file_name, 0, $ext );
|
||||
$fileName_b = substr( $new_file_name, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
while ( file_exists( '../' . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
$new_file_name = $fileName_a . '_' . $count . $fileName_b;
|
||||
}
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_articles', [
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
|
||||
'date_add' => $date_add,
|
||||
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
|
||||
'date_modify' => $date_modify,
|
||||
'modify_by' => $user['id'],
|
||||
'layout_id' => $layout_id ? (int)$layout_id : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeat_entry == 'on' ? 1 : 0,
|
||||
'social_icons' => $social_icons == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $show_table_of_contents == 'on' ? 1 : 0,
|
||||
], [
|
||||
'id' => (int)$article_id
|
||||
] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_articles_langs', 'id', [ 'AND' => [ 'article_id' => $article_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_articles_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'main_image' => $main_image[$key] != '' ? $main_image[$key] : null,
|
||||
'entry' => $entry[$key] != '' ? $entry[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'table_of_contents' => $table_of_contents[$key] != '' ? $table_of_contents[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key] == 'on' ? 1 : 0,
|
||||
'copy_from' => $copy_from[$key] != '' ? $copy_from[$key] : null,
|
||||
'block_direct_access' => $block_direct_access[$key] == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$article_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'main_image' => $main_image[$key] != '' ? $main_image[$key] : null,
|
||||
'entry' => $entry[$key] != '' ? $entry[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'table_of_contents' => $table_of_contents[$key] != '' ? $table_of_contents[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key] == 'on' ? 1 : 0,
|
||||
'copy_from' => $copy_from[$key] != '' ? $copy_from[$key] : null,
|
||||
'block_direct_access' => $block_direct_access[$key] == 'on' ? 1 : 0
|
||||
] );
|
||||
}
|
||||
|
||||
$not_in = [ 0 ];
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
$not_in[] = $page;
|
||||
else if ( $pages )
|
||||
$not_in[] = $pages;
|
||||
|
||||
$mdb -> delete( 'pp_articles_pages', [ 'AND' => [ 'article_id' => (int)$article_id, 'page_id[!]' => $not_in ] ] );
|
||||
|
||||
$pages_tmp = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
if ( !is_array( $pages ) )
|
||||
$pages = [ $pages ];
|
||||
|
||||
$pages = array_diff( $pages, $pages_tmp );
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$article_id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $article_id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_files/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => (int)$article_id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
/* zdjęcia */
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $article_id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_images/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '../' . $new_file_name ) )
|
||||
{
|
||||
$ext = strrpos( $new_file_name, '.' );
|
||||
$fileName_a = substr( $new_file_name, 0, $ext );
|
||||
$fileName_b = substr( $new_file_name, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
while ( file_exists( '../' . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
$new_file_name = $fileName_a . '_' . $count . $fileName_b;
|
||||
}
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$article_id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_images', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_files', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
|
||||
\S::htacces();
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $article_id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function delete_nonassigned_files()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_files', [ 'article_id' => null ] );
|
||||
}
|
||||
|
||||
public static function delete_nonassigned_images()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_images', [ 'article_id' => null ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
27
autoload/admin/factory/class.ArticlesArchive.php
Normal file
27
autoload/admin/factory/class.ArticlesArchive.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class ArticlesArchive
|
||||
{
|
||||
public static function article_restore( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_articles', [ 'status' => 0 ], [ 'id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
public static function article_delete( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> delete( 'pp_articles_pages', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles_langs', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles_images', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles_files', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles', [ 'id' => (int)$article_id ] );
|
||||
|
||||
\S::delete_dir( '../upload/article_images/article_' . (int)$article_id . '/' );
|
||||
\S::delete_dir( '../upload/article_files/article_' . (int)$article_id . '/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
108
autoload/admin/factory/class.Banners.php
Normal file
108
autoload/admin/factory/class.Banners.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace admin\factory;
|
||||
|
||||
class Banners
|
||||
{
|
||||
public static function banner_delete( $banner_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> delete( 'pp_banners', [ 'id' => (int) $banner_id ] );
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function banner_save( $banner_id, $name, $status, $date_start, $date_end, $home_page, $src, $url, $html, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$banner_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_banners', [
|
||||
'name' => $name,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'date_start' => $date_start != '' ? $date_start : null,
|
||||
'date_end' => $date_end != '' ? $date_end : null,
|
||||
'home_page' => $home_page == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $src as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_banners_langs', [
|
||||
'id_banner' => (int)$id,
|
||||
'id_lang' => $key,
|
||||
'src' => $src[$key],
|
||||
'url' => $url[$key],
|
||||
'html' => $html[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_banners', [
|
||||
'name' => $name,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'date_start' => $date_start != '' ? $date_start : null,
|
||||
'date_end' => $date_end != '' ? $date_end : null,
|
||||
'home_page' => $home_page == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$banner_id
|
||||
] );
|
||||
|
||||
foreach ( $src as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_banners_langs', 'id', [ 'AND' => [ 'banner_id' => $banner_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_banners_langs', [
|
||||
'id_lang' => $key,
|
||||
'src' => $src[$key],
|
||||
'url' => $url[$key],
|
||||
'html' => $html[$key],
|
||||
'text' => $text[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_banners_langs', [
|
||||
'id_banner' => (int)$banner_id,
|
||||
'id_lang' => $key,
|
||||
'src' => $src[$key],
|
||||
'url' => $url[$key],
|
||||
'html' => $html[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $banner_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function banner_details( $id_banner )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$banner = $mdb -> get( 'pp_banners', '*', [ 'id' => (int)$id_banner ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_banners_langs', '*', [ 'id_banner' => (int)$id_banner ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$banner['languages'][$row['id_lang']] = $row;
|
||||
|
||||
return $banner;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
39
autoload/admin/factory/class.Baselinker.php
Normal file
39
autoload/admin/factory/class.Baselinker.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Baselinker {
|
||||
|
||||
// zapis wiązania produktów
|
||||
static public function bundling_products_save( $values ) {
|
||||
global $mdb;
|
||||
|
||||
foreach ( $values as $key => $val ) {
|
||||
$key = explode( '_', $key );
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $val ], [ 'id' => $key[1] ] );
|
||||
}
|
||||
}
|
||||
|
||||
// pobranie produktów z Baselinkera
|
||||
static public function products_list() {
|
||||
global $settings;
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $settings['baselinker_api'],
|
||||
"method" => "getProductsList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
return $response['products'];
|
||||
}
|
||||
}
|
||||
89
autoload/admin/factory/class.Dictionaries.php
Normal file
89
autoload/admin/factory/class.Dictionaries.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
class Dictionaries
|
||||
{
|
||||
static public function all_units()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_units', '*' );
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$resutls2 = $mdb -> query( 'SELECT text FROM pp_units_langs AS psl, pp_langs AS pl WHERE unit_id = ' . $row['id'] . ' AND lang_id = pl.id AND text != \'\' ORDER BY o ASC LIMIT 1' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$row['text'] = $resutls2[0]['text'];
|
||||
$units[ $row['id'] ] = $row;
|
||||
}
|
||||
return $units;
|
||||
}
|
||||
|
||||
static public function unit_details( $unit_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$unit = $mdb -> get( 'pp_units', '*', [ 'id' => (int)$unit_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_units_langs', '*', [ 'unit_id' => (int)$unit_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$unit['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
return $unit;
|
||||
|
||||
}
|
||||
|
||||
static public function unit_save( $unit_id, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$unit_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_units', array());
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $text as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_units_langs', [
|
||||
'unit_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( $text as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_units_langs', 'id', [ 'AND' => [ 'unit_id' => $unit_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_units_langs', [
|
||||
'lang_id' => $key,
|
||||
'text' => $text[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_units_langs', [
|
||||
'unit_id' => (int)$unit_id,
|
||||
'lang_id' => $key,
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/dictionaries' );
|
||||
|
||||
return $unit_id;
|
||||
}
|
||||
}
|
||||
|
||||
static public function unit_delete( $unit_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_units', [ 'id' => (int)$unit_id ] );
|
||||
}
|
||||
}
|
||||
264
autoload/admin/factory/class.Integrations.php
Normal file
264
autoload/admin/factory/class.Integrations.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Integrations {
|
||||
|
||||
// sellasist_product_select_delete
|
||||
static public function sellasist_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => null, 'sellasist_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// sellasist_product_select_save
|
||||
static public function sellasist_product_select_save( int $product_id, $sellasist_product_id, $sellasist_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => $sellasist_product_id, 'sellasist_product_name' => \S::remove_special_chars( $sellasist_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo delete product linking
|
||||
static public function apilo_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => null, 'apilo_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// baselinker delete product linking
|
||||
static public function baselinker_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => null, 'baselinker_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo product select save
|
||||
static public function apilo_product_select_save( int $product_id, $apilo_product_id, $apilo_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => $apilo_product_id, 'apilo_product_name' => \S::remove_special_chars( $apilo_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
static public function baselinker_product_select_save( int $product_id, $baselinker_product_id, $baselinker_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $baselinker_product_id, 'baselinker_product_name' => $baselinker_product_name ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// get settings for shoppro integration
|
||||
static public function shoppro_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_shoppro_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_shoppro_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the sellasist integration
|
||||
static public function sellasist_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_sellasist_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_sellasist_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the Baselinker integration
|
||||
static public function baselinker_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_baselinker_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_baselinker_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the APILO plugin
|
||||
static public function apilo_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_apilo_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_apilo_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// save settings for shoppro integration
|
||||
static public function shoppro_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_shoppro_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_shoppro_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_shoppro_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the sellasist integration
|
||||
static public function sellasist_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_sellasist_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_sellasist_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_sellasist_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the Baselinker integration
|
||||
static public function baselinker_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_baselinker_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_baselinker_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_baselinker_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the APILO plugin
|
||||
static public function apilo_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_apilo_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_apilo_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_apilo_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// authorization in apilo.com
|
||||
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/auth/token/";
|
||||
|
||||
$postData['grantType'] = 'authorization_code';
|
||||
$postData['token'] = $authorization_code;
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $client_id . ":" . $client_secret ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// get access token or refresh it apilo.com
|
||||
static public function apilo_get_access_token()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$apilo_settings = self::apilo_settings();
|
||||
|
||||
$date1 = new \DateTime( $apilo_settings['access-token-expire-at'] );
|
||||
$date2 = new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
if ( $date1 < $date2 )
|
||||
{
|
||||
$post_data = [
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $apilo_settings['refresh-token']
|
||||
];
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $apilo_settings['client-id'] . ":" . $apilo_settings['client-secret'] ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_POST, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post_data ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
if ( $access_token == '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
return $apilo_settings['access-token'];
|
||||
}
|
||||
}
|
||||
136
autoload/admin/factory/class.Languages.php
Normal file
136
autoload/admin/factory/class.Languages.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?
|
||||
|
||||
namespace admin\factory;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function translation_delete( $translation_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_langs_translations', [ 'id' => $translation_id ] );
|
||||
}
|
||||
|
||||
public static function translation_save( $translation_id, $text, $languages )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $translation_id )
|
||||
{
|
||||
$mdb -> update( 'pp_langs_translations', [ 'text' => $text ], [ 'id' => $translation_id ] );
|
||||
if ( is_array( $languages ) and !empty( $languages ) ): foreach ( $languages as $key => $val ):
|
||||
$mdb -> update( 'pp_langs_translations', [ $key => $val ], [ 'id' => $translation_id ] );
|
||||
endforeach; endif;
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $translation_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> insert( 'pp_langs_translations', [ 'text' => $text ] );
|
||||
if ( $translation_id = $mdb -> id() )
|
||||
{
|
||||
if ( is_array( $languages ) and !empty( $languages ) ): foreach ( $languages as $key => $val ):
|
||||
$mdb -> update( 'pp_langs_translations', [ $key => $val ], [ 'id' => $translation_id ] );
|
||||
endforeach; endif;
|
||||
}
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $translation_id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function translation_details( $translation_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_langs_translations', '*', [ 'id' => $translation_id ] );
|
||||
}
|
||||
|
||||
public static function language_delete( $language_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_langs' ) > 1 )
|
||||
{
|
||||
if ( $mdb -> query( 'ALTER TABLE pp_langs_translations DROP ' . $language_id )
|
||||
and
|
||||
$mdb -> delete( 'pp_langs', [ 'id' => $language_id ] )
|
||||
)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_langs', 'o' );
|
||||
}
|
||||
|
||||
public static function language_save( $language_id, $name, $status, $start, $o )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $start == 'on' )
|
||||
$mdb -> update( 'pp_langs', [
|
||||
'start' => 0
|
||||
], [
|
||||
'id[!]' => $language_id
|
||||
] );
|
||||
|
||||
if ( $mdb -> count( 'pp_langs', [ 'id' => $language_id ] ) )
|
||||
{
|
||||
$mdb -> update( 'pp_langs',
|
||||
[
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'name' => $name,
|
||||
'o' => $o
|
||||
], [
|
||||
'id' => $language_id
|
||||
] );
|
||||
|
||||
if ( !$mdb -> count( 'pp_langs', [ 'start' => 1 ] ) )
|
||||
{
|
||||
$id_tmp = $mdb -> get( 'pp_langs', 'id', [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
$mdb -> update( 'pp_langs', [ 'start' => 1 ], [ 'id' => $id_tmp ] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $language_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $mdb -> query( 'ALTER TABLE pp_langs_translations ADD ' . $language_id . ' TEXT NULL DEFAULT NULL' ) )
|
||||
{
|
||||
$mdb -> insert( 'pp_langs',
|
||||
[
|
||||
'id' => $language_id,
|
||||
'name' => $name,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'o' => $o
|
||||
] );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $language_id;
|
||||
}
|
||||
}
|
||||
|
||||
return faslse;
|
||||
}
|
||||
|
||||
public static function language_details( $language_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_langs', '*', [ 'id' => $language_id ] );
|
||||
}
|
||||
|
||||
public static function languages_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_langs', '*', [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
190
autoload/admin/factory/class.Layouts.php
Normal file
190
autoload/admin/factory/class.Layouts.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Layouts
|
||||
{
|
||||
public static function layout_delete( $layout_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_layouts' ) > 1 )
|
||||
return $mdb -> delete( 'pp_layouts', [ 'id' => (int)$layout_id ] );
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function layout_details( $layout_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'id' => (int)$layout_id ] );
|
||||
|
||||
$layout['pages'] = $mdb -> select( 'pp_layouts_pages', 'page_id', [ 'layout_id' => (int)$layout_id ] );
|
||||
$layout['categories'] = $mdb -> select( 'pp_layouts_categories', 'category_id', [ 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public static function layout_save( $layout_id, $name, $status, $pages, $html, $css, $js, $m_html, $m_css, $m_js, $categories, $categories_default )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$layout_id )
|
||||
{
|
||||
if ( $status == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'status' => 0 ] );
|
||||
|
||||
if ( $categories_default == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'categories_default' => 0 ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts', [
|
||||
'name' => $name,
|
||||
'html' => $html,
|
||||
'css' => $css,
|
||||
'js' => $js,
|
||||
'm_html' => $m_html,
|
||||
'm_css' => $m_css,
|
||||
'm_js' => $m_js,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'categories_default' => $categories_default == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$id,
|
||||
'page_id' => (int)$page
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$pages ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$id,
|
||||
'page_id' => (int)$pages
|
||||
] );
|
||||
}
|
||||
|
||||
if ( is_array( $categories ) ) foreach ( $categories as $category )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$category ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$id,
|
||||
'category_id' => (int)$category
|
||||
] );
|
||||
}
|
||||
else if ( $categories )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$categories ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$id,
|
||||
'category_id' => (int)$categories
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $status == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'status' => 0 ] );
|
||||
|
||||
if ( $categories_default == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'categories_default' => 0 ] );
|
||||
|
||||
$mdb -> update( 'pp_layouts', [
|
||||
'name' => $name,
|
||||
'html' => $html,
|
||||
'css' => $css,
|
||||
'js' => $js,
|
||||
'm_html' => $m_html,
|
||||
'm_css' => $m_css,
|
||||
'm_js' => $m_js,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'categories_default' => $categories_default == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $layout_id
|
||||
] );
|
||||
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'page_id' => (int)$page
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$pages ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'page_id' => (int)$pages
|
||||
] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
if ( is_array( $categories ) ) foreach ( $categories as $category )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$category ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'category_id' => (int)$category
|
||||
] );
|
||||
}
|
||||
else if ( $categories )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$categories ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'category_id' => (int)$categories
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $layout_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_menus', 'id', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$menu = \admin\factory\Pages::menu_details( $row );
|
||||
$menu['pages'] = \admin\factory\Pages::menu_pages( $row );
|
||||
|
||||
$menus[] = $menu;
|
||||
}
|
||||
return $menus;
|
||||
}
|
||||
|
||||
public static function layouts_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_layouts', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
76
autoload/admin/factory/class.Newsletter.php
Normal file
76
autoload/admin/factory/class.Newsletter.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function is_admin_template( $template_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_newsletter_templates', 'is_admin', [ 'id' => (int)$template_id ] );
|
||||
}
|
||||
|
||||
public static function newsletter_template_delete( $template_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_newsletter_templates', [ 'id' => (int)$template_id ] );
|
||||
}
|
||||
|
||||
public static function send( $dates, $template )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_newsletter', 'email', [ 'status' => 1 ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_newsletter_send', [
|
||||
'email' => $row,
|
||||
'dates' => $dates,
|
||||
'id_template' => $template ? $template : null
|
||||
] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function email_template_detalis ($id_template)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get ('pp_newsletter_templates', '*', [ 'id' => (int)$id_template ] );
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function template_save( $id, $name, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_newsletter_templates', [
|
||||
'name' => $name,
|
||||
'text' => $text
|
||||
] ) )
|
||||
{
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $mdb -> id();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_newsletter_templates', [
|
||||
'name' => $name,
|
||||
'text' => $text
|
||||
], [
|
||||
'id' => (int)$id
|
||||
] );
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function templates_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_newsletter_templates', '*', [ 'is_admin' => 0, 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
}
|
||||
407
autoload/admin/factory/class.Pages.php
Normal file
407
autoload/admin/factory/class.Pages.php
Normal file
@@ -0,0 +1,407 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Pages
|
||||
{
|
||||
public static $_page_types = [ 0 => 'pełne artykuły', 1 => 'wprowadzenia', 2 => 'miniaturki', 3 => 'link', 4 => 'kontakt', 5 => 'kategoria sklepu' ];
|
||||
public static $_sort_types = [
|
||||
0 => 'data dodania - najstarsze na początku',
|
||||
1 => 'data dodania - najnowsze na początku',
|
||||
2 => 'data modyfikacji - rosnąco',
|
||||
3 => 'data mofyfikacji - malejąco',
|
||||
4 => 'ręczne',
|
||||
5 => 'alfabetycznie - A - Z',
|
||||
6 => 'alfabetycznie - Z - A'
|
||||
];
|
||||
|
||||
public static function save_articles_order( $page_id, $articles )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $articles ) )
|
||||
{
|
||||
$mdb -> update( 'pp_articles_pages', [ 'o' => 0 ], [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $articles ); $i++ )
|
||||
{
|
||||
if ( $articles[$i]['item_id'] )
|
||||
{
|
||||
$x++;
|
||||
$mdb -> update( 'pp_articles_pages', [ 'o' => $x ], [ 'AND' => [ 'page_id' => (int)$page_id, 'article_id' => $articles[ $i ]['item_id'] ] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function page_articles( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'article_id, o, status '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'page_id = ' . (int)$page_id . ' AND status != -1 '
|
||||
. 'ORDER BY '
|
||||
. 'o ASC' ) -> fetchAll();
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = \admin\factory\Articles::article_title( $row['article_id'] );
|
||||
$articles[] = $row;
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function save_pages_order( $menu_id, $pages )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $pages ) )
|
||||
{
|
||||
$mdb -> update( 'pp_pages', [ 'o' => 0 ], [ 'menu_id' => (int)$menu_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $pages ); $i++ )
|
||||
{
|
||||
if ( $pages[$i]['item_id'] )
|
||||
{
|
||||
$pages[$i]['parent_id'] ? $parent_id = $pages[$i]['parent_id'] : $parent_id = 0;
|
||||
|
||||
if ( $pages[$i]['item_id'] && $pages[$i]['depth'] > 1 )
|
||||
{
|
||||
if ( $pages[$i]['depth'] == 2 )
|
||||
$parent_id = null;
|
||||
|
||||
$x++;
|
||||
|
||||
$mdb -> update( 'pp_pages', [ 'o' => $x, 'parent_id' => $parent_id ], [ 'id' => (int)$pages[ $i ]['item_id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function page_delete( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'parent_id' => (int)$page_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_pages', [ 'id' => (int)$page_id ] );
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_pages', 'o' );
|
||||
}
|
||||
|
||||
public static function page_save(
|
||||
$page_id, $title, $seo_link, $meta_title, $meta_description, $meta_keywords, $menu_id, $parent_id, $page_type, $sort_type, $layout_id, $articles_limit, $show_title, $status,
|
||||
$link, $noindex, $start, $page_title, $canonical, $category_id
|
||||
)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$parent_id )
|
||||
$parent_id = null;
|
||||
|
||||
if ( !$page_id )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_pages', [
|
||||
'menu_id' => (int)$menu_id,
|
||||
'page_type' => $page_type,
|
||||
'sort_type' => $sort_type,
|
||||
'articles_limit' => $articles_limit,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'o' => (int)$order,
|
||||
'parent_id' => $parent_id,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'category_id' => ( $category_id and $page_type == 5 ) ? $category_id : null
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( $start )
|
||||
$mdb -> update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int)$id ] );
|
||||
|
||||
if ( $layout_id )
|
||||
$mdb -> insert( 'pp_layouts_pages', [ 'page_id' => (int)$id, 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_pages_langs', [
|
||||
'page_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_pages', [
|
||||
'menu_id' => (int)$menu_id,
|
||||
'page_type' => $page_type,
|
||||
'sort_type' => $sort_type,
|
||||
'articles_limit' => $articles_limit,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'parent_id' => $parent_id,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'category_id' => ( $category_id and $page_type == 5 ) ? $category_id : null
|
||||
], [
|
||||
'id' => (int)$page_id
|
||||
] );
|
||||
|
||||
if ( $layout_id )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page_id ] );
|
||||
$mdb -> insert( 'pp_layouts_pages', [ 'layout_id' => (int)$layout_id, 'page_id' => (int)$page_id ] );
|
||||
}
|
||||
|
||||
if ( $start )
|
||||
$mdb -> update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int)$page_id ] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_pages_langs', 'id', [ 'AND' => [ 'page_id' => $page_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_pages_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_pages_langs', [
|
||||
'page_id' => (int)$page_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
self::update_supages_menu_id( $page_id, $menu_id );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $page_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function update_supages_menu_id( $parent_id, $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_pages', [ 'menu_id' => (int)$menu_id ], [ 'parent_id' => $parent_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_pages', [ 'id' ], [ 'parent_id' => $parent_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
self::update_supages_menu_id( $row['id'], $menu_id );
|
||||
}
|
||||
|
||||
public static function generate_seo_link( $title, $page_id, $article_id, $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$seo_link = \S::seo( $title );
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_pages_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'page_id[!]' => (int)$page_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
$seo_link_check = false;
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_articles_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'article_id[!]' => (int)$article_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
$seo_link_check = false;
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_shop_categories_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'category_id[!]' => (int)$category_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
return $seo_link;
|
||||
}
|
||||
|
||||
public static function menu_delete( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'menu_id' => (int)$menu_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_menus', [ 'id' => (int)$menu_id ] );
|
||||
}
|
||||
|
||||
public static function menu_details( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_menus', '*', [ 'id' => (int)$menu_id ] );
|
||||
}
|
||||
|
||||
public static function menu_save( $menu_id, $name, $status )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$status == 'on' ? $status = 1 : $status = 0;
|
||||
|
||||
if ( !$menu_id )
|
||||
{
|
||||
return $mdb -> insert( 'pp_menus', [
|
||||
'name' => $name,
|
||||
'status' => $status
|
||||
] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_menus', [
|
||||
'name' => $name,
|
||||
'status' => $status
|
||||
], [
|
||||
'id' => (int)$menu_id
|
||||
] );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function menu_lists()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function page_details( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$page = $mdb -> get( 'pp_pages', '*', [ 'id' => (int)$page_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_pages_langs', '*', [ 'page_id' => (int)$page_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$page['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$page['layout_id'] = $mdb -> get( 'pp_layouts_pages', 'layout_id', [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public static function page_url( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT seo_link FROM pp_pages_langs AS ppl, pp_langs AS pl WHERE lang_id = pl.id AND page_id = " . (int)$page_id . " AND seo_link != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = self::page_title( $article_id );
|
||||
return 's-' . $page_id . '-' . \S::seo( $title );
|
||||
}
|
||||
else
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public static function page_title( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> select( 'pp_pages_langs', [
|
||||
'[><]pp_langs' => [ 'lang_id' => 'id' ]
|
||||
], 'title', [
|
||||
'AND' => [
|
||||
'page_id' => (int)$page_id, 'title[!]' => ''
|
||||
],
|
||||
'ORDER' => [ 'o' => 'ASC' ],
|
||||
'LIMIT' => 1
|
||||
] );
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function page_languages( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_pages_langs', '*',
|
||||
[ 'AND' => [ 'page_id' => (int) $page_id, 'title[!]' => null ] ] );
|
||||
}
|
||||
|
||||
public static function menu_pages( $menu_id, $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_pages',
|
||||
[ 'id', 'menu_id', 'status', 'parent_id', 'start' ],
|
||||
[ 'AND' => [ 'menu_id' => $menu_id, 'parent_id' => $parent_id ], 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = self::page_title( $row['id'] );
|
||||
$row['languages'] = self::page_languages( $row['id'] );
|
||||
$row['subpages'] = self::menu_pages( $menu_id, $row['id'] );
|
||||
|
||||
$pages[] = $row;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
?>
|
||||
88
autoload/admin/factory/class.Scontainers.php
Normal file
88
autoload/admin/factory/class.Scontainers.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function container_delete( $container_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_scontainers', [ 'id' => (int)$container_id ] );
|
||||
}
|
||||
|
||||
public static function container_save( $container_id, $title, $text, $status, $show_title )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$container_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_scontainers', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_scontainers_langs', [
|
||||
'container_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_scontainers', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$container_id
|
||||
] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_scontainers_langs', 'id', [ 'AND' => [ 'container_id' => $container_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_scontainers_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key],
|
||||
'text' => $text[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_scontainers_langs', [
|
||||
'container_id' => (int)$container_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $container_id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function container_details( $container_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$container = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int)$container_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'container_id' => (int)$container_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$container['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
104
autoload/admin/factory/class.Settings.php
Normal file
104
autoload/admin/factory/class.Settings.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public static function settings_update( $param, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> delete( 'pp_settings', [ 'param' => $param ] );
|
||||
$mdb -> insert( 'pp_settings', [ 'param' => $param, 'value' => $value ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function settings_save(
|
||||
$firm_name, $firm_adress, $additional_info, $contact_form, $contact_email, $email_host, $email_port, $email_login, $email_password, $google_maps, $facebook_link, $statistic_code, $htaccess,
|
||||
$robots, $shop_bank_account_info, $update, $boot_animation, $newsletter_header, $newsletter_footer, $hotpay_api
|
||||
)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> query( 'TRUNCATE pp_settings' );
|
||||
|
||||
$mdb -> insert( 'pp_settings', [
|
||||
[
|
||||
'param' => 'firm_name',
|
||||
'value' => $firm_name,
|
||||
], [
|
||||
'param' => 'firm_adress',
|
||||
'value' => $firm_adress
|
||||
], [
|
||||
'param' => 'additional_info',
|
||||
'value' => $additional_info
|
||||
], [
|
||||
'param' => 'contact_form',
|
||||
'value' => $contact_form == 'on' ? 1 : 0
|
||||
], [
|
||||
'param' => 'contact_email',
|
||||
'value' => $contact_email
|
||||
], [
|
||||
'param' => 'email_host',
|
||||
'value' => $email_host
|
||||
], [
|
||||
'param' => 'email_port',
|
||||
'value' => $email_port
|
||||
], [
|
||||
'param' => 'email_login',
|
||||
'value' => $email_login
|
||||
], [
|
||||
'param' => 'email_password',
|
||||
'value' => $email_password
|
||||
], [
|
||||
'param' => 'google_maps',
|
||||
'value' => $google_maps
|
||||
], [
|
||||
"param" => 'facebook_link',
|
||||
'value' => $facebook_link
|
||||
], [
|
||||
'param' => 'statistic_code',
|
||||
'value' => $statistic_code
|
||||
], [
|
||||
'param' => 'htaccess',
|
||||
'value' => $htaccess
|
||||
], [
|
||||
'param' => 'robots',
|
||||
'value' => $robots
|
||||
], [
|
||||
'param' => 'shop_bank_account_info',
|
||||
'value' => $shop_bank_account_info
|
||||
], [
|
||||
'param' => 'update',
|
||||
'value' => $update == 'on' ? 1 : 0
|
||||
], [
|
||||
'param' => 'boot_animation',
|
||||
'value' => $boot_animation
|
||||
], [
|
||||
'param' => 'newsletter_header',
|
||||
'value' => $newsletter_header
|
||||
], [
|
||||
'param' => 'newsletter_footer',
|
||||
'value' => $newsletter_footer
|
||||
], [
|
||||
'param' => 'hotpay_api',
|
||||
'value' => $hotpay_api
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
\S::set_message( 'Ustawienia zostały zapisane' );
|
||||
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.' ];
|
||||
}
|
||||
|
||||
public static function settings_details()
|
||||
{
|
||||
global $mdb;
|
||||
$results = $mdb -> select( 'pp_settings', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$settings[ $row['param'] ] = $row['value'];
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
?>
|
||||
263
autoload/admin/factory/class.ShopAttribute.php
Normal file
263
autoload/admin/factory/class.ShopAttribute.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopAttribute
|
||||
{
|
||||
static public function get_attributes_list()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_attributes', '*', [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
{
|
||||
$attribute = \admin\factory\ShopAttribute::attribute_details( $row['id'] );
|
||||
$attribute['values'] = \admin\factory\ShopAttribute::get_attribute_values( $row['id'] );
|
||||
$attributes[] = $attribute;
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
// pobierz nazwę wartości atrybutu
|
||||
static public function get_attribute_value_by_id( int $value_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_attributes_values_langs', 'name', [ 'AND' => [ 'value_id' => $value_id, 'lang_id' => \front\factory\Languages::default_language() ] ] );
|
||||
}
|
||||
|
||||
//pobierz nazwę atrybutu
|
||||
static public function get_attribute_name_by_id( int $attribute_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_attributes_langs', 'name', [ 'AND' => [ 'attribute_id' => $attribute_id, 'lang_id' => \front\factory\Languages::default_language() ] ] );
|
||||
}
|
||||
|
||||
static public function values_save( int $attribute_id, $names, $values, $ids, $default_value = '', $impact_on_the_price )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$main_language = \front\factory\Languages::default_language();
|
||||
|
||||
if ( \S::is_array_fix( $ids[$main_language] ) )
|
||||
$ids_delete = implode( ',', $ids[$main_language] );
|
||||
else
|
||||
{
|
||||
if ( $ids[$main_language] )
|
||||
$ids_delete = $ids[$main_language];
|
||||
}
|
||||
|
||||
if ( $ids_delete )
|
||||
$mdb -> query( 'DELETE FROM pp_shop_attributes_values WHERE id NOT IN (' . $ids_delete . ') AND attribute_id = ' . $attribute_id );
|
||||
|
||||
for ( $i = 0; $i < count( $names[$main_language] ); ++$i )
|
||||
{
|
||||
if ( $ids[$main_language][$i] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values', [
|
||||
'impact_on_the_price' => $impact_on_the_price[$i] ? \S::normalize_decimal( $impact_on_the_price[$i] ) : null,
|
||||
], [
|
||||
'id' => $ids[$main_language][$i],
|
||||
] );
|
||||
|
||||
\admin\factory\ShopProduct::update_product_price_by_attribute_value_impact( $ids[$main_language][$i], $impact_on_the_price[$i] );
|
||||
|
||||
$langs = \admin\factory\Languages::languages_list();
|
||||
|
||||
foreach ( $langs as $lang )
|
||||
{
|
||||
if ( $names[$lang['id']][$i] and $mdb -> count( 'pp_shop_attributes_values_langs', [ 'AND' => [ 'value_id' => $ids[$main_language][$i], 'lang_id' => $lang['id'] ] ] ) )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values_langs', [
|
||||
'name' => $names[$lang['id']][$i],
|
||||
'value' => $values[$lang['id']][$i] ? $values[$lang['id']][$i] : null,
|
||||
], [
|
||||
'AND' => [
|
||||
'value_id' => $ids[$main_language][$i],
|
||||
'lang_id' => $lang['id'],
|
||||
],
|
||||
] );
|
||||
}
|
||||
elseif ( $names[$lang['id']][$i] and !$mdb -> count( 'pp_shop_attributes_values_langs', [ 'AND' => [ 'value_id' => $ids[$main_language][$i], 'lang_id' => $lang['id'] ] ] ) )
|
||||
{
|
||||
$mdb -> insert('pp_shop_attributes_values_langs', [
|
||||
'value_id' => $ids[$main_language][$i],
|
||||
'lang_id' => $lang['id'],
|
||||
'name' => $names[$lang['id']][$i],
|
||||
'value' => $values[$lang['id']][$i] ? $values[$lang['id']][$i] : null,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $default_value == $i )
|
||||
$default_value_id = $ids[$main_language][$i];
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_attributes_values', [ 'attribute_id' => $attribute_id ] );
|
||||
$value_id = $mdb -> id();
|
||||
|
||||
if ( $value_id )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values', [
|
||||
'impact_on_the_price' => $impact_on_the_price[$i] ? \S::normalize_decimal( $impact_on_the_price[$i] ) : null,
|
||||
], [
|
||||
'id' => $value_id,
|
||||
] );
|
||||
|
||||
if ( $impact_on_the_price[$i] )
|
||||
\admin\factory\ShopProduct::update_product_price_by_attribute_value_impact( $value_id, \S::normalize_decimal( $impact_on_the_price[$i] ) );
|
||||
|
||||
$langs = \admin\factory\Languages::languages_list();
|
||||
if ( \S::is_array_fix( $langs ) ) foreach ( $langs as $lang )
|
||||
{
|
||||
if ( $names[$lang['id']][$i] )
|
||||
{
|
||||
$mdb -> insert('pp_shop_attributes_values_langs', [
|
||||
'value_id' => $value_id,
|
||||
'lang_id' => $lang['id'],
|
||||
'name' => $names[$lang['id']][$i],
|
||||
'value' => $values[$lang['id']][$i] ? $values[$lang['id']][$i] : null,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $default_value == $i )
|
||||
$default_value_id = $value_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $default_value_id )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values', [ 'is_default' => 0 ], [ 'attribute_id' => $attribute_id ] );
|
||||
$mdb -> update( 'pp_shop_attributes_values', [ 'is_default' => 1 ], [ 'id' => $default_value_id ] );
|
||||
}
|
||||
|
||||
\S::delete_cache();
|
||||
|
||||
return $attribute_id;
|
||||
}
|
||||
|
||||
static public function get_attribute_values( int $attribute_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_attributes_values', [ 'id', 'is_default', 'impact_on_the_price' ], [ 'attribute_id' => $attribute_id ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$results2 = $mdb -> select( 'pp_shop_attributes_values_langs', [ 'lang_id', 'name', 'value' ], [ 'value_id' => $row['id'] ] );
|
||||
if ( \S::is_array_fix( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
$row['languages'][$row2['lang_id']] = $row2;
|
||||
|
||||
$values[] = $row;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
static public function delete_attribute( int $attribute_id )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( $mdb -> delete( 'pp_shop_attributes', [ 'id' => $attribute_id ] ) )
|
||||
{
|
||||
\Log::save_log( 'Atrybut został usunięty | ID: ' . $attribute_id, $user['id'] );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function attribute_save( int $attribute_id, $name, int $status, int $type, int $o )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$attribute_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_attributes', [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'o' => $o
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( !$id )
|
||||
return false;
|
||||
|
||||
\Log::save_log( 'Dodano nowy atrybut | ID: ' . $id, $user['id'] );
|
||||
|
||||
foreach ( $name as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_attributes_langs', [
|
||||
'attribute_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'name' => $name[$key],
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes', [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'o' => $o
|
||||
], [
|
||||
'id' => $attribute_id,
|
||||
] );
|
||||
|
||||
\Log::save_log( 'Zaktualizowano atrybut | ID: ' . $attribute_id, $user['id'] );
|
||||
|
||||
foreach ( $name as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_shop_attributes_langs', 'id', [ 'AND' => [ 'attribute_id' => $attribute_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_shop_attributes_langs', [
|
||||
'lang_id' => $key,
|
||||
'name' => $name[$key],
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_shop_attributes_langs', [
|
||||
'attribute_id' => (int)$attribute_id,
|
||||
'lang_id' => $key,
|
||||
'name' => $name[$key],
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $attribute_id;
|
||||
}
|
||||
}
|
||||
|
||||
static public function value_details( int $value_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$value = $mdb -> get( 'pp_shop_attributes_values', '*', [ 'id' => (int) $value_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_attributes_values_langs', [ 'lang_id', 'name', 'value' ], [ 'value_id' => (int) $value_id ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row)
|
||||
$value['languages'][$row['lang_id']] = $row;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
static public function attribute_details( int $attribute_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$attribute = $mdb -> get( 'pp_shop_attributes', '*', [ 'id' => (int) $attribute_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_attributes_langs', [ 'lang_id', 'name' ], [ 'attribute_id' => (int) $attribute_id ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row)
|
||||
$attribute['languages'][$row['lang_id']] = $row;
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
}
|
||||
245
autoload/admin/factory/class.ShopCategory.php
Normal file
245
autoload/admin/factory/class.ShopCategory.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopCategory
|
||||
{
|
||||
public static $_sort_types = [
|
||||
0 => 'data dodania - najstarsze na początku',
|
||||
1 => 'data dodania - najnowsze na początku',
|
||||
2 => 'data modyfikacji - rosnąco',
|
||||
3 => 'data mofyfikacji - malejąco',
|
||||
4 => 'ręczne',
|
||||
5 => 'alfabetycznie - A - Z',
|
||||
6 => 'alfabetycznie - Z - A'
|
||||
];
|
||||
|
||||
public static function save_product_order( $category_id, $products )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $products ) )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products_categories', [ 'o' => 0 ], [ 'category_id' => (int)$category_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $products ); $i++ )
|
||||
{
|
||||
if ( $products[$i]['item_id'] )
|
||||
{
|
||||
$x++;
|
||||
$mdb -> update( 'pp_shop_products_categories', [ 'o' => $x ], [ 'AND' => [ 'category_id' => (int)$category_id, 'product_id' => $products[ $i ]['item_id'] ] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function category_products( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'product_id, o, status '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'category_id = :category_id '
|
||||
. 'ORDER BY '
|
||||
. 'o ASC', [
|
||||
':category_id' => $category_id
|
||||
] ) -> fetchAll();
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['name'] = \admin\factory\ShopProduct::product_name( $row['product_id'] );
|
||||
$products[] = $row;
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
|
||||
public static function save_categories_order( $categories )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $categories ) )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_categories', [ 'o' => 0 ] );
|
||||
|
||||
for ( $i = 0; $i < count( $categories ); $i++ )
|
||||
{
|
||||
if ( $categories[$i]['item_id'] )
|
||||
{
|
||||
$categories[$i]['parent_id'] ? $parent_id = $categories[$i]['parent_id'] : $parent_id = null;
|
||||
|
||||
$x++;
|
||||
$mdb -> update( 'pp_shop_categories', [ 'o' => $x, 'parent_id' => $parent_id ], [ 'id' => (int)$categories[ $i ]['item_id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function category_delete( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_categories', [ 'parent_id' => (int)$category_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_shop_categories', [ 'id' => (int)$category_id ] );
|
||||
}
|
||||
|
||||
public static function category_languages( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_categories_langs', '*', [ 'AND' => [ 'category_id' => (int)$category_id, 'title[!]' => null ] ] );
|
||||
}
|
||||
|
||||
public static function category_title( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> select( 'pp_shop_categories_langs', [
|
||||
'[><]pp_langs' => [ 'lang_id' => 'id' ]
|
||||
], 'title', [
|
||||
'AND' => [
|
||||
'category_id' => (int)$category_id, 'title[!]' => ''
|
||||
],
|
||||
'ORDER' => [ 'o' => 'ASC' ],
|
||||
'LIMIT' => 1
|
||||
] );
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function subcategories( $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_categories', [ 'id' ], [ 'parent_id' => $parent_id, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$categories[] = self::category_details( $row['id'] );
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_shop_categories', 'o' );
|
||||
}
|
||||
|
||||
public static function save( $category_id, $title, $text, $text_hidden, $seo_link, $meta_title, $meta_description, $meta_keywords, $parent_id, $status, $noindex, $category_title, $sort_type, $additional_text, $view_subcategories )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$parent_id )
|
||||
$parent_id = null;
|
||||
|
||||
if ( !$category_id )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_shop_categories', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'o' => (int)$order,
|
||||
'parent_id' => $parent_id,
|
||||
'sort_type' => $sort_type,
|
||||
'view_subcategories' => $view_subcategories == 'on' ? 1 : 0,
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_categories_langs', [
|
||||
'category_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'text_hidden' => $text_hidden[$key] != '' ? $text_hidden[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'category_title' => $category_title[$key] != '' ? $category_title[$key] : null,
|
||||
'additional_text' => $additional_text[$key] != '' ? $additional_text[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_categories', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'parent_id' => $parent_id,
|
||||
'sort_type' => $sort_type,
|
||||
'view_subcategories' => $view_subcategories == 'on' ? 1 : 0,
|
||||
], [
|
||||
'id' => (int)$category_id
|
||||
] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_shop_categories_langs', 'id', [ 'AND' => [ 'category_id' => $category_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_shop_categories_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'text_hidden' => $text_hidden[$key] != '' ? $text_hidden[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'category_title' => $category_title[$key] != '' ? $category_title[$key] : null,
|
||||
'additional_text' => $additional_text[$key] != '' ? $additional_text[$key] : null
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_shop_categories_langs', [
|
||||
'category_id' => (int)$category_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'text_hidden' => $text_hidden[$key] != '' ? $text_hidden[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'category_title' => $category_title[$key] != '' ? $category_title[$key] : null,
|
||||
'additional_text' => $additional_text[$key] != '' ? $additional_text[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $category_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function category_details( $category_id = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$category = $mdb -> get( 'pp_shop_categories', '*', [ 'id' => (int)$category_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_categories_langs', '*', [ 'category_id' => (int)$category_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$category['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
17
autoload/admin/factory/class.ShopClients.php
Normal file
17
autoload/admin/factory/class.ShopClients.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopClients
|
||||
{
|
||||
public static function get_order_all_info($name, $surname, $email)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb->select('pp_shop_orders', '*', [
|
||||
'client_name' => $name,
|
||||
'client_surname' => $surname,
|
||||
'client_email' => $email
|
||||
]);
|
||||
|
||||
return $results;}
|
||||
}
|
||||
?>
|
||||
54
autoload/admin/factory/class.ShopCoupon.php
Normal file
54
autoload/admin/factory/class.ShopCoupon.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopCoupon
|
||||
{
|
||||
static public function details( int $coupon_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_coupon', '*', [ 'id' => $coupon_id ] );
|
||||
}
|
||||
|
||||
public static function coupon_delete( $coupon_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_shop_coupon', [ 'id' => $coupon_id ] );
|
||||
}
|
||||
|
||||
public static function save( $coupon_id, $name, $status, $send, $used, $type, $amount, $one_time, $include_discounted_product, $categories )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$coupon_id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_shop_coupon', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'used' => $used,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'one_time' => $one_time,
|
||||
'send' => $send,
|
||||
'include_discounted_product' => $include_discounted_product,
|
||||
'categories' => $categories
|
||||
] ) )
|
||||
return $mdb -> id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_coupon', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'used' => $used,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'one_time' => $one_time,
|
||||
'send' => $send,
|
||||
'include_discounted_product' => $include_discounted_product,
|
||||
'categories' => $categories
|
||||
], [
|
||||
'id' => $coupon_id
|
||||
] );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
autoload/admin/factory/class.ShopOrder.php
Normal file
24
autoload/admin/factory/class.ShopOrder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopOrder
|
||||
{
|
||||
static public function next_order_id( int $order_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$order_id )
|
||||
return false;
|
||||
|
||||
return $mdb -> get( 'pp_shop_orders', 'id', [ 'id[>]' => $order_id, 'ORDER' => [ 'id' => 'ASC' ], 'LIMIT' => 1 ] );
|
||||
}
|
||||
|
||||
static public function prev_order_id( int $order_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$order_id )
|
||||
return false;
|
||||
|
||||
return $mdb -> get( 'pp_shop_orders', 'id', [ 'id[<]' => $order_id, 'ORDER' => [ 'id' => 'DESC' ], 'LIMIT' => 1 ] );
|
||||
}
|
||||
}
|
||||
10
autoload/admin/factory/class.ShopPaymentMethod.php
Normal file
10
autoload/admin/factory/class.ShopPaymentMethod.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function payments_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_payment_methods', '*', [ 'ORDER' => [ 'name' => 'ASC'] ] );
|
||||
}
|
||||
}
|
||||
80
autoload/admin/factory/class.ShopProducer.php
Normal file
80
autoload/admin/factory/class.ShopProducer.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
class ShopProducer
|
||||
{
|
||||
static public function all()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_producer', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
static public function delete( int $producer_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_shop_producer', [ 'id' => $producer_id ] );
|
||||
}
|
||||
|
||||
static public function save( $producer_id, $name, int $status, $img, $description, $meta_title )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$producer_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_producer', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'img' => $img
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
foreach ( $description as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_producer_lang', [
|
||||
'producer_id' => $id,
|
||||
'lang_id' => $key,
|
||||
'description' => $val,
|
||||
'meta_title' => $meta_title[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_producer', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'img' => $img
|
||||
], [
|
||||
'id' => (int) $producer_id
|
||||
] );
|
||||
|
||||
foreach ( $description as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_shop_producer_lang', 'id', [ 'AND' => [ 'producer_id' => $producer_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_shop_producer_lang', [
|
||||
'description' => $val,
|
||||
'meta_title' => $meta_title[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_shop_producer_lang', [
|
||||
'producer_id' => $producer_id,
|
||||
'lang_id' => $key,
|
||||
'description' => $val,
|
||||
'meta_title' => $meta_title[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $producer_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
1540
autoload/admin/factory/class.ShopProduct.php
Normal file
1540
autoload/admin/factory/class.ShopProduct.php
Normal file
File diff suppressed because it is too large
Load Diff
68
autoload/admin/factory/class.ShopProductSet.php
Normal file
68
autoload/admin/factory/class.ShopProductSet.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopProductSet
|
||||
{
|
||||
// zapisywanie kompletu produktów
|
||||
static public function save( int $set_id, string $name, string $status, $set_products_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$set_id )
|
||||
{
|
||||
$mdb -> insert('pp_shop_product_sets', [
|
||||
'name' => $name,
|
||||
'status' => 'on' === $status ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $set_products_id == null )
|
||||
$not_in = [ 0 ];
|
||||
elseif ( !is_array( $set_products_id ) )
|
||||
$not_in = [ 0, $set_products_id ];
|
||||
elseif ( is_array( $set_products_id ) )
|
||||
$not_in = $set_products_id;
|
||||
|
||||
foreach ( $not_in as $product_id )
|
||||
{
|
||||
if ( $product_id != 0 )
|
||||
$mdb -> insert( 'pp_shop_product_sets_products', [ 'set_id' => $id, 'product_id' => $product_id ] );
|
||||
}
|
||||
|
||||
\S::delete_dir('../temp/');
|
||||
\S::delete_dir('../thumbs/');
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update('pp_shop_product_sets', [
|
||||
'name' => $name,
|
||||
'status' => 'on' === $status ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$set_id,
|
||||
] );
|
||||
|
||||
$mdb -> delete( 'pp_shop_product_sets_products', [ 'set_id' => $set_id ] );
|
||||
|
||||
if ( $set_products_id == null )
|
||||
$not_in = [ 0 ];
|
||||
elseif ( !is_array( $set_products_id ) )
|
||||
$not_in = [ 0, $set_products_id ];
|
||||
elseif ( is_array( $set_products_id ) )
|
||||
$not_in = $set_products_id;
|
||||
|
||||
foreach ( $not_in as $product_id )
|
||||
{
|
||||
if ( $product_id != 0 )
|
||||
$mdb -> insert( 'pp_shop_product_sets_products', [ 'set_id' => $set_id, 'product_id' => $product_id ] );
|
||||
}
|
||||
|
||||
\S::delete_dir('../temp/');
|
||||
\S::delete_dir('../thumbs/');
|
||||
|
||||
return $set_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
autoload/admin/factory/class.ShopPromotion.php
Normal file
55
autoload/admin/factory/class.ShopPromotion.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopPromotion
|
||||
{
|
||||
static public function promotion_details( int $promotion_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_promotion', '*', [ 'id' => $promotion_id ] );
|
||||
}
|
||||
|
||||
static public function save( $promotion_id, $name, $status, $condition_type, $discount_type, $amount, $date_to, $categories, $condition_categories, $include_coupon, $include_product_promo, $min_product_count, $price_cheapest_product )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$promotion_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_promotion', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'condition_type' => $condition_type,
|
||||
'discount_type' => $discount_type,
|
||||
'amount' => $amount,
|
||||
'date_to' => $date_to != '' ? $date_to : null,
|
||||
'categories' => $categories != null ? ( is_array( $categories ) ? json_encode( $categories ) : json_encode( [ $categories ] ) ) : null,
|
||||
'condition_categories' => $condition_categories != null ? ( is_array( $condition_categories ) ? json_encode( $condition_categories ) : json_encode( [ $condition_categories ] ) ) : null,
|
||||
'include_coupon' => $include_coupon,
|
||||
'include_product_promo' => $include_product_promo,
|
||||
'min_product_count' => $min_product_count ? $min_product_count : null,
|
||||
'price_cheapest_product' => $price_cheapest_product ? $price_cheapest_product : null
|
||||
] );
|
||||
|
||||
return $mdb -> id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_promotion', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'condition_type' => $condition_type,
|
||||
'discount_type' => $discount_type,
|
||||
'amount' => $amount,
|
||||
'date_to' => $date_to != '' ? $date_to : null,
|
||||
'categories' => $categories != null ? ( is_array( $categories ) ? json_encode( $categories ) : json_encode( [ $categories ] ) ) : null,
|
||||
'condition_categories' => $condition_categories != null ? ( is_array( $condition_categories ) ? json_encode( $condition_categories ) : json_encode( [ $condition_categories ] ) ) : null,
|
||||
'include_coupon' => $include_coupon,
|
||||
'include_product_promo' => $include_product_promo,
|
||||
'min_product_count' => $min_product_count ? $min_product_count : null,
|
||||
'price_cheapest_product' => $price_cheapest_product ? $price_cheapest_product : null
|
||||
], [
|
||||
'id' => $promotion_id
|
||||
] );
|
||||
return $promotion_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
autoload/admin/factory/class.ShopStatuses.php
Normal file
26
autoload/admin/factory/class.ShopStatuses.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopStatuses {
|
||||
// get_status
|
||||
public static function get_status( $id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', '*', [ 'id' => $id ] );
|
||||
}
|
||||
|
||||
// status_save
|
||||
public static function status_save( $status_id, $color, $apilo_status_id, $sellasi_status_id, $baselinker_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_shop_statuses', [
|
||||
'color' => $color,
|
||||
'apilo_status_id' => $apilo_status_id ? $apilo_status_id : null,
|
||||
'sellasist_status_id' => $sellasi_status_id ? $sellasi_status_id : null,
|
||||
'baselinker_status_id' => $baselinker_status_id ? $baselinker_status_id : null
|
||||
], [ 'id' => $status_id ] );
|
||||
|
||||
return $status_id;
|
||||
}
|
||||
}
|
||||
108
autoload/admin/factory/class.ShopTransport.php
Normal file
108
autoload/admin/factory/class.ShopTransport.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopTransport
|
||||
{
|
||||
public static function lowest_transport_price( $wp ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_transports', 'cost', [ 'AND' => [ 'status' => 1, 'id' => [ 2, 4, 6, 8 ], 'max_wp[>=]' => $wp ], 'ORDER' => [ 'cost' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $sellasist_shipment_method_id, $delivery_free )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$transport_id )
|
||||
{
|
||||
if ( $default == 'on' )
|
||||
$mdb -> update( 'pp_shop_transports', [ 'default' => '0' ] );
|
||||
|
||||
$mdb -> insert( 'pp_shop_transports', [
|
||||
'name' => $name,
|
||||
'name_visible' => $name_visible,
|
||||
'description' => $description,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'default' => $default == 'on' ? 1 : 0,
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( is_array( $payment_methods ) ) foreach ( $payment_methods as $payment_method )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_method,
|
||||
'id_transport' => (int)$id
|
||||
] );
|
||||
}
|
||||
else if ( $payment_methods )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_methods,
|
||||
'id_transport' => (int)$id
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $default == 'on' )
|
||||
$mdb -> update( 'pp_shop_transports', [ 'default' => '0' ] );
|
||||
|
||||
$mdb -> update( 'pp_shop_transports', [
|
||||
'name' => $name,
|
||||
'name_visible' => $name_visible,
|
||||
'description' => $description,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'default' => $default == 'on' ? 1 : 0,
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $transport_id
|
||||
] );
|
||||
|
||||
$mdb -> delete( 'pp_shop_transport_payment_methods', [ 'id_transport' => (int)$transport_id ] );
|
||||
|
||||
if ( is_array( $payment_methods ) ) foreach ( $payment_methods as $payment_method )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_method,
|
||||
'id_transport' => (int)$transport_id
|
||||
] );
|
||||
}
|
||||
else if ( $payment_methods )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_methods,
|
||||
'id_transport' => (int)$transport_id
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function transport_details( $transport_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$transport = $mdb -> get( 'pp_shop_transports', '*', [ 'id' => $transport_id ] );
|
||||
$transport['payment_methods'] = $mdb -> select( 'pp_shop_transport_payment_methods', 'id_payment_method', [ 'id_transport' => $transport_id ] );
|
||||
|
||||
return $transport;
|
||||
}
|
||||
}
|
||||
105
autoload/admin/factory/class.Update.php
Normal file
105
autoload/admin/factory/class.Update.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Update
|
||||
{
|
||||
public static function update()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
\S::delete_session( 'new-version' );
|
||||
|
||||
$versions = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'] );
|
||||
$versions = explode( PHP_EOL, $versions );
|
||||
|
||||
foreach ( $versions as $ver )
|
||||
{
|
||||
$ver = trim( $ver );
|
||||
if ( (float)$ver > (float)\S::get_version() )
|
||||
{
|
||||
if ( strlen( $ver ) == 5 )
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||
else
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
||||
|
||||
$file = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '.zip' );
|
||||
|
||||
$dlHandler = fopen( 'update.zip' , 'w' );
|
||||
if ( !fwrite( $dlHandler, $file ) )
|
||||
return false;
|
||||
fclose( $dlHandler );
|
||||
|
||||
if ( !file_exists( 'update.zip' ) )
|
||||
return false;
|
||||
else
|
||||
{
|
||||
/* aktualizacja bazy danych */
|
||||
$sql = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt' );
|
||||
$sql = explode( PHP_EOL, $sql );
|
||||
if ( is_array( $sql ) and !empty( $sql ) ) foreach ( $sql as $query )
|
||||
{
|
||||
if ( $sql )
|
||||
$result = $mdb -> query( $query );
|
||||
}
|
||||
|
||||
/* usuwanie zbędnych plików */
|
||||
$lines = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt' );
|
||||
$lines = explode( PHP_EOL, $lines );
|
||||
if ( is_array( $lines ) ) foreach ( $lines as $line )
|
||||
{
|
||||
if ( strpos( $line, 'F: ' ) !== false )
|
||||
{
|
||||
$file = substr( $line, 3, strlen( $line ) );
|
||||
if ( file_exists( $file ) )
|
||||
unlink( $file );
|
||||
}
|
||||
|
||||
if ( strpos( $line, 'D: ' ) !== false )
|
||||
{
|
||||
$dir = substr( $line, 3, strlen( $line ) );
|
||||
if ( is_dir( $dir ) )
|
||||
\S::delete_dir( $dir );
|
||||
}
|
||||
}
|
||||
|
||||
/* wgrywanie nowych plików */
|
||||
$file_name = 'update.zip';
|
||||
|
||||
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
||||
$path = substr( $path, 0, strlen( $path ) - 5 );
|
||||
$zip = new \ZipArchive;
|
||||
$res = $zip -> open( $file_name );
|
||||
if ( $res === TRUE )
|
||||
{
|
||||
$zip -> extractTo( $path );
|
||||
$zip -> close();
|
||||
unlink( $file_name );
|
||||
}
|
||||
|
||||
$updateThis = fopen( '../libraries/version.ini', 'w' );
|
||||
fwrite( $updateThis, $ver );
|
||||
fclose( $updateThis );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function update0197()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_order_products', [ 'id', 'product_id' ], [ 'parent_product_id' => null ] );
|
||||
foreach ( $rows as $row )
|
||||
{
|
||||
$parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $row['product_id'] ] );
|
||||
if ( $parent_id )
|
||||
$mdb -> update( 'pp_shop_order_products', [ 'parent_product_id' => $parent_id ], [ 'id' => $row['id'] ] );
|
||||
else
|
||||
$mdb -> update( 'pp_shop_order_products', [ 'parent_product_id' => $row['product_id'] ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_updates', [ 'done' => 1 ], [ 'name' => 'update0197' ] );
|
||||
}
|
||||
}
|
||||
110
autoload/admin/factory/class.Users.php
Normal file
110
autoload/admin/factory/class.Users.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Users
|
||||
{
|
||||
public static function user_delete( $user_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_users', [ 'id' => (int)$user_id ] );
|
||||
}
|
||||
|
||||
public static function user_details( $user_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_users', '*', [ 'id' => (int)$user_id ] );
|
||||
}
|
||||
|
||||
public static function user_save( $user_id = '', $login, $status, $password, $password_re, $admin )
|
||||
{
|
||||
global $mdb, $lang, $config;
|
||||
|
||||
if ( !$user_id )
|
||||
{
|
||||
if ( strlen( $password ) < 5 )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasło jest zbyt krótkie.' ];
|
||||
|
||||
if ( $password != $password_re )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasła są różne' ];
|
||||
|
||||
if ( $mdb -> insert( 'pp_users', [
|
||||
'login' => $login,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'admin' => $admin,
|
||||
'password' => md5( $password )
|
||||
] ) )
|
||||
{
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Użytkownik został zapisany.' ];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $password and strlen( $password ) < 5 )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasło jest zbyt krótkie.' ];
|
||||
|
||||
if ( $password and $password != $password_re )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasła są różne' ];
|
||||
|
||||
if ( $password )
|
||||
$mdb -> update( 'pp_users', [
|
||||
'password' => md5( $password )
|
||||
], [
|
||||
'id' => (int)$user_id
|
||||
] );
|
||||
|
||||
$mdb -> update( 'pp_users', [
|
||||
'login' => $login,
|
||||
'admin' => $admin,
|
||||
'status' => $status == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$user_id
|
||||
] );
|
||||
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Uzytkownik został zapisany.' ];
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_login( $login, $user_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> get( 'pp_users', 'login', [ 'AND' => [ 'login' => $login, 'id[!]' => (int)$user_id ] ] ) )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podany login jest już zajęty.' ];
|
||||
|
||||
return $response = [ 'status' => 'ok' ];
|
||||
}
|
||||
|
||||
public static function logon( $login, $password )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$mdb -> get( 'pp_users', '*', [ 'login' => $login ] ) )
|
||||
return 0;
|
||||
|
||||
if ( !$mdb -> get( 'pp_users', '*', [ 'AND' => [ 'login' => $login, 'status' => 1, 'error_logged_count[<]' => 5 ] ] ) )
|
||||
return -1;
|
||||
|
||||
if ( $mdb -> get( 'pp_users', '*', [ 'AND' => [ 'login' => $login, 'status' => 1, 'password' => md5( $password ) ] ] ) )
|
||||
{
|
||||
$mdb -> update( 'pp_users', [ 'last_logged' => date( 'Y-m-d H:i:s' ), 'error_logged_count' => 0 ], [ 'login' => $login ] );
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_users', [ 'last_error_logged' => date( 'Y-m-d H:i:s' ), 'error_logged_count[+]' => 1 ], [ 'login' => $login ] );
|
||||
if ( $mdb -> get( 'pp_users', 'error_logged_count', [ 'login' => $login ] ) >= 5 )
|
||||
{
|
||||
$mdb -> update( 'pp_users', [ 'status' => 0 ], [ 'login' => $login ] );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function details( $login )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_users', '*', [ 'login' => $login ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user