first commit

This commit is contained in:
2024-10-23 12:55:46 +02:00
commit 85c92aa932
8453 changed files with 1186172 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
namespace admin;
class Site
{
public static function special_actions()
{
$sa = \S::get( 's-action' );
switch ( $sa )
{
case 'user-logon':
$result = \admin\factory\Users::logon( \S::get( 'login' ), \S::get( 'password' ) );
if ( $result == 1 )
\S::set_session( 'user', \admin\factory\Users::details( \S::get( 'login' ) ) );
else
{
if ( $result == -1 )
\S::alert( 'Z powodu nieudanych 5 prób logowania Twoje konto zostało zablokowane.' );
else
\S::alert( 'Podane hasło jest nieprawidłowe, lub brak użytkownika o podanym loginie.' );
}
header( 'Location: /admin/dashboard/main_view/' );
exit;
break;
case 'user-logout':
session_destroy();
header( 'Location: /admin/' );
exit;
break;
}
}
public static function route()
{
$_SESSION['admin'] = true;
if ( \S::get( 'p' ) )
\S::set_session( 'p' , \S::get( 'p' ) );
$page = \S::get_session( 'p' );
$class = '\admin\controls\\';
$results = explode( '_', \S::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$action = \S::get( 'action' );
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
else
{
\S::alert( 'Nieprawidłowy adres url.' );
return false;
}
}
static public function update()
{
global $mdb;
if ( $results = $mdb -> select( 'pp_updates', [ 'name' ], [ 'done' => 0 ] ) )
{
foreach ( $results as $row )
{
$class = '\admin\factory\Update';
$method = $row['name'];
if ( class_exists( $class ) and method_exists( new $class, $method ) )
call_user_func_array( array( $class, $method ), array() );
}
}
}
}

View File

@@ -0,0 +1,25 @@
<?
namespace admin\controls;
class Archive {
static public function products_list() {
$current_page = \S::get_session( 'archive_products_list_current_page' );
if ( !$current_page ) {
$current_page = 1;
\S::set_session( 'archive_products_list_current_page', $current_page );
}
$query = \S::get_session( 'archive_products_list_query' );
if ( $query ) {
$query_array = [];
parse_str( $query, $query_array );
}
return \Tpl::view( 'archive/products-list', [
'current_page' => $current_page,
'query_array' => $query_array,
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product() / 10 )
] );
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace admin\controls;
class Articles
{
public static function gallery_order_save()
{
if ( \admin\factory\Articles::gallery_order_save( \S::get( 'article_id' ), \S::get( 'order' ) ) )
echo json_encode( [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.' ] );
exit;
}
public static function browse_list()
{
return \admin\view\Articles::browse_list();
}
public static function article_delete()
{
if ( \admin\factory\Articles::articles_set_archive( \S::get( 'id' ) ) )
\S::alert( 'Artykuł został przeniesiony do archiwum.' );
header( 'Location: /admin/articles/view_list/' );
exit;
}
public static function article_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania artykułu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Articles::article_save(
$values['id'], $values['title'], $values['main_image'], $values['entry'], $values['text'], $values['table_of_contents'], $values['status'], $values['show_title'], $values['show_table_of_contents'], $values['show_date_add'], $values['date_add'], $values['show_date_modify'], $values['date_modify'], $values['seo_link'], $values['meta_title'],
$values['meta_description'], $values['meta_keywords'], $values['layout_id'], $values['pages'], $values['noindex'], $values['repeat_entry'], $values['copy_from'], $values['social_icons'], $values['block_direct_access']
) )
$response = [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function article_edit()
{
\admin\factory\Articles::delete_nonassigned_images();
\admin\factory\Articles::delete_nonassigned_files();
return \admin\view\Articles::article_edit(
\admin\factory\Articles::article_details(
\S::get( 'id' )
),
\admin\factory\Pages::menus_list(),
\admin\factory\Languages::languages_list(),
\admin\factory\Layouts::layouts_list()
);
}
public static function view_list()
{
return \admin\view\Articles::articles_list();
}
}
?>

View File

@@ -0,0 +1,26 @@
<?php
namespace admin\controls;
class ArticlesArchive
{
public static function article_restore()
{
if ( \admin\factory\ArticlesArchive::article_restore( \S::get( 'id' ) ) )
\S::alert( 'Artykuł został przywrócony.' );
header( 'Location: /admin/articles_archive/view_list/' );
exit;
}
public static function article_delete()
{
if ( \admin\factory\ArticlesArchive::article_delete( \S::get( 'id' ) ) )
\S::alert( 'Artykuł został usunięty.' );
header( 'Location: /admin/articles_archive/view_list/' );
exit;
}
public static function view_list()
{
return \admin\view\ArticlesArchive::articles_list();
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace admin\controls;
class Banners
{
public static function banner_delete()
{
if ( \admin\factory\Banners::banner_delete( \S::get( 'id' ) ) )
\S::alert( 'Baner został usunięty.' );
header( 'Location: /admin/banners/view_list/' );
exit;
}
public static function banner_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania baneru wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $banner_id = \admin\factory\Banners::banner_save( $values['id'], $values['name'], $values['status'], $values['date_start'], $values['date_end'],
$values['home_page'], $values['src'], $values['url'], $values['html'], $values['text'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Baner został zapisany.', 'id' => $banner_id ];
echo json_encode( $response );
exit;
}
public static function banner_edit()
{
return \admin\view\Banners::banner_edit(
\admin\factory\Banners::banner_details(
\S::get( 'id' )
),
\admin\factory\Languages::languages_list()
);
}
public static function view_list()
{
return \admin\view\Banners::banners_list();
}
}
?>

View File

@@ -0,0 +1,20 @@
<?php
namespace admin\controls;
class Baselinker {
// widok wiązania produktów
static public function bundling_products() {
return \Tpl::view( 'baselinker/bundling-products', [
'products' => \admin\factory\ShopProduct::products_list_for_baselinker(),
'baselinker_products' => \admin\factory\Baselinker::products_list()
] );
}
// zapis wiązania produktów
static public function bundling_products_save() {
\admin\factory\Baselinker::bundling_products_save( $_POST );
header( 'Location: /admin/baselinker/bundling_products/' );
exit;
}
}

View File

@@ -0,0 +1,18 @@
<?
namespace admin\controls;
class Dashboard
{
static public function main_view()
{
return \Tpl::view( 'dashboard/main-view', [
'last_orders' => \shop\Dashboard::last_orders(),
'order_statuses' => \shop\Order::order_statuses(),
'sales' => \shop\Dashboard::last_24_months_sales(),
'best_sales_products' => \shop\Dashboard::best_sales_products(),
'most_view_products' => \shop\Dashboard::most_view_products(),
'sales_grid' => \shop\Dashboard::sales_grid(),
'summary_sales' => \shop\Dashboard::summary_sales(),
'summary_orders' => \shop\Dashboard::summary_orders(),
] );
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace admin\controls;
class Dictionaries {
public static function view_list()
{
return \Tpl::view( 'dictionaries/units-list' );
}
public static function unit_edit()
{
return \Tpl::view( 'dictionaries/unit-edit', [
'unit' => \admin\factory\Dictionaries::unit_details( \S::get( 'id' )),
'languages' => \admin\factory\Languages::languages_list(),
] );
}
static public function unit_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania jednostki miary wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Dictionaries::unit_save( $values['id'], $values['text']) )
$response = [ 'status' => 'ok', 'msg' => 'Jednostka miary została zapisana.', 'id' => $id ];
echo json_encode( $response );
exit;
}
static public function unit_delete()
{
if ( \admin\factory\Dictionaries::unit_delete( \S::get( 'id' ) ) )
\S::alert( 'Jesdnostka miary została usunięta.' );
header( 'Location: /admin/dictionaries/view_list/' );
exit;
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace admin\controls;
class Filemanager
{
public function draw()
{
return \admin\view\FileManager::filemanager();
}
}
?>

View File

@@ -0,0 +1,846 @@
<?
namespace admin\controls;
class Integrations {
// apilo_create_product
static public function apilo_create_product()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$product_id = \S::get( 'product_id' );
$product = new \shop\Product( $product_id );
$methodParams = [
"sku" => $product -> sku,
"ean" => $product -> ean,
"name" => $product -> language['name'],
"tax" => (int) $product -> vat,
'status' => 1,
"quantity" => (int) $product -> quantity,
"priceWithTax" => $product -> price_brutto,
'description' => $product -> language['description'] . '<br>' . $product -> language['short_description'],
'shortDescription' => '',
'images' => []
];
foreach ($product->images as $image) {
$methodParams["images"][] = "https://" . $_SERVER['HTTP_HOST'] . $image['src'];
}
$ch = curl_init( "https://projectpro.apilo.com/rest/api/warehouse/product/" );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [ $methodParams ] ) );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Content-Type: application/json",
"Accept: application/json"
] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData['products'] )
{
$mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => reset( $responseData['products'] ), 'apilo_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
}
\S::alert( 'Produkt został dodany do magazynu APILO.' );
}
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
// baselinker_create_product
static public function baselinker_create_product()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$product_id = \S::get( 'product_id' );
$product = \shop\Product::getFromCache( $product_id, 'pl' );
$methodParams = [
"storage_id" => \admin\factory\Integrations::baselinker_settings('storage_id'),
"ean" => $product->ean,
"sku" => $product->sku,
"name" => $product->language['name'],
"quantity" => "0",
"price_brutto" => $product->price_brutto,
"tax_rate" => $product->vat,
"description" => $product->language['short_description'],
"description_extra1" => $product->language['description'],
"images" => []
];
foreach ($product->images as $image) {
$methodParams["images"][] = "url:https://" . $_SERVER['HTTP_HOST'] . $image['src'];
}
$methodParams = json_encode( $methodParams, JSON_UNESCAPED_SLASHES );
$apiParams = [
"token" => $api_code,
"method" => "addProduct",
"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' )
{
if ( $response['product_id'] )
{
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $response['product_id'], 'baselinker_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
}
\S::alert( 'Produkt został dodany do magazynu Baselinker.' );
}
else
{
\S::alert( 'Podczas dodawania produktu wystąpił błąd.' );
}
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
// baselinker pobierz listę magazynów
static public function baselinker_get_storages_list()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$methodParams = '{
"storage_id": "bl_1"
}';
$apiParams = [
"token" => $api_code,
"method" => "getStoragesList",
"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' )
{
\admin\factory\Integrations::baselinker_settings_save( 'storages_list', $response['storages'] );
\S::alert( 'Lista magazynów została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/baselinker_settings/' );
exit;
}
// baselinker_get_order_status_list
static public function baselinker_get_order_status_list()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$apiParams = [
"token" => $api_code,
"method" => "getOrderStatusList",
"parameters" => []
];
$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' )
{
\admin\factory\Integrations::baselinker_settings_save( 'order_status_list', $response['statuses'] );
\S::alert( 'Lista statusów została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/baselinker_settings/' );
exit;
}
// get_sellasist_carriers_list
static public function get_sellasist_shipments_list()
{
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/shipments" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
else {
if ( $responseData ) {
\admin\factory\Integrations::sellasist_settings_save( 'shipments_methods', $responseData );
\S::alert( 'Lista przewoźników została pobrana.' );
} else
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/sellasist_settings/' );
exit;
}
// get_sellasist_payment_types_list
static public function get_sellasist_payment_types_list()
{
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/payments" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
else {
if ( $responseData ) {
\admin\factory\Integrations::sellasist_settings_save( 'payment_types_list', $responseData );
\S::alert( 'Lista metod płatności została pobrana.' );
} else
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/sellasist_settings/' );
exit;
}
static public function get_sellasist_status_types_list()
{
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/statuses" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
else {
if ( $responseData ) {
\admin\factory\Integrations::sellasist_settings_save( 'status_types_list', $responseData );
\S::alert( 'Lista statusów została pobrana.' );
} else
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/sellasist_settings/' );
exit;
}
// get_platform_list
static public function get_platform_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/platform/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'platform-list', $responseData );
\S::alert( 'Lista platform została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// get_status_types_list
static public function get_status_types_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/status/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'status-types-list', $responseData );
\S::alert( 'Lista statusów została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// get_carrier_account_list
static public function get_carrier_account_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/carrier-account/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'carrier-account-list', $responseData );
\S::alert( 'Lista kont przewoźników została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// get_payment_types_list
static public function get_payment_types_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/payment/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'payment-types-list', $responseData );
\S::alert( 'Lista metod płatności została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// settings for the sellasist integration
static public function sellasist_settings()
{
return \Tpl::view( 'integrations/sellasist-settings', [
'settings' => \admin\factory\Integrations::sellasist_settings(),
] );
}
// settings for the Baselinker integration
static public function baselinker_settings()
{
return \Tpl::view( 'integrations/baselinker-settings', [
'settings' => \admin\factory\Integrations::baselinker_settings(),
] );
}
// settings for shoppro
static public function shoppro_settings()
{
return \Tpl::view( 'integrations/shoppro-settings', [
'settings' => \admin\factory\Integrations::shoppro_settings(),
] );
}
// Settings for the APILO plugin
static public function apilo_settings()
{
return \Tpl::view( 'integrations/apilo-settings', [
'settings' => \admin\factory\Integrations::apilo_settings(),
] );
}
// save settings for the shoppro integration
static public function shoppro_settings_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::shoppro_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// save settings for the sellasist integration
static public function sellasist_settings_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::sellasist_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// save settings for the Baselinker integration
static public function baselinker_settings_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::baselinker_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// Save settings for the APILO plugin
static public function apilo_settings_save() {
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::apilo_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// Authorization in apilo.com
static public function apilo_authorization() {
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
$settings = \admin\factory\Integrations::apilo_settings();
if ( \admin\factory\Integrations::apilo_authorization( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
echo json_encode( $response );
exit;
}
// sellasist product search by sku
static public function sellasist_product_search() {
global $mdb, $settings;
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
$url = "https://projectpro.sellasist.pl/api/v1/products";
$params['symbol '] = $sku;
$url .= '?' . http_build_query( $params );
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
echo 'Błąd cURL: ' . curl_error( $ch );
}
else
{
if ( $responseData['error'] )
{
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
exit;
}
else
{
$return_data = array();
$return_data['status'] = 'SUCCESS';
$return_data['products'] = $responseData;
echo json_encode( $return_data );
exit;
}
}
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
exit;
}
// apilo product search by sku
static public function apilo_product_search() {
global $mdb, $settings;
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/warehouse/product/";
$params['sku'] = $sku;
$url .= '?' . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) ) {
echo 'Błąd cURL: ' . curl_error( $ch );
} else {
if ( $responseData && isset( $responseData['products'] ) ) {
$responseData['status'] = 'SUCCESS';
echo json_encode( $responseData );
exit;
} else {
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
exit;
}
}
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
exit;
}
// wyszukiwanie produktu w bazie baselinkera
static public function baselinker_product_search()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
$methodParams = '{
"storage_id": "bl_1",
"filter_sku": "' . $sku . '"
}';
$apiParams = [
"token" => $api_code,
"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 );
echo json_encode( $response );
exit;
}
// sellasist_product_select_delete
static public function sellasist_product_select_delete()
{
global $mdb;
if ( \admin\factory\Integrations::sellasist_product_select_delete( \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// apilo product select delete
static public function apilo_product_select_delete()
{
global $mdb;
if ( \admin\factory\Integrations::apilo_product_select_delete( \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// baselinker delete product linking
static public function baselinker_product_select_delete()
{
global $mdb;
if ( \admin\factory\Integrations::baselinker_product_select_delete( \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// sellasist_product_select_save
static public function sellasist_product_select_save()
{
global $mdb;
if ( \admin\factory\Integrations::sellasist_product_select_save( \S::get( 'product_id' ), \S::get( 'sellasist_product_id' ), \S::get( 'sellasist_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// apilo product select save
static public function apilo_product_select_save()
{
global $mdb;
if ( \admin\factory\Integrations::apilo_product_select_save( \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
static public function baselinker_product_select_save() {
global $mdb;
if ( \admin\factory\Integrations::baselinker_product_select_save( \S::get( 'product_id' ), \S::get( 'baselinker_product_id' ), \S::get( 'baselinker_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// shoppro_product_import
static public function shoppro_product_import()
{
global $mdb;
$shoppro_settings = \admin\factory\Integrations::shoppro_settings();
$mdb2 = new \medoo( [
'database_type' => 'mysql',
'database_name' => $shoppro_settings[ 'db_name' ],
'server' => $shoppro_settings[ 'db_host' ],
'username' => $shoppro_settings[ 'db_user' ],
'password' => $shoppro_settings[ 'db_password' ],
'charset' => 'utf8'
] );
$product_id = \S::get( 'product_id' );
$product = $mdb2 -> get( 'pp_shop_products', '*', [ 'id' => $product_id ] );
if ( $product )
{
$mdb -> insert( 'pp_shop_products', [
'price_netto' => $product[ 'price_netto' ],
'price_brutto' => $product[ 'price_brutto' ],
'vat' => $product[ 'vat' ],
'stock_0_buy' => $product[ 'stock_0_buy' ],
'quantity' => $product[ 'quantity' ],
'wp' => $product[ 'wp' ],
'sku' => $product[ 'sku' ],
'ean' => $product[ 'ean' ],
'custom_label_0' => $product[ 'custom_label_0' ],
'custom_label_1' => $product[ 'custom_label_1' ],
'custom_label_2' => $product[ 'custom_label_2' ],
'custom_label_3' => $product[ 'custom_label_3' ],
'custom_label_4' => $product[ 'custom_label_4' ],
'additional_message' => $product[ 'additional_message' ],
'additional_message_text' => $product[ 'additional_message_text' ],
'additional_message_required' => $product[ 'additional_message_required' ],
'weight' => $product[ 'weight' ]
] );
$new_product_id = $mdb -> id();
if ( $new_product_id )
{
$languages = $mdb2 -> select( 'pp_shop_products_langs', '*', [ 'product_id' => $product_id ] );
if ( is_array( $languages ) )
{
foreach ( $languages as $language )
{
$mdb -> insert( 'pp_shop_products_langs', [
'product_id' => $new_product_id,
'lang_id' => $language['lang_id'],
'name' => $language['name'],
'short_description' => $language['short_description'],
'description' => $language['description'],
'tab_name_1' => $language['tab_name_1'],
'tab_description_1' => $language['tab_description_1'],
'tab_name_2' => $language['tab_name_2'],
'tab_description_2' => $language['tab_description_2'],
'meta_title' => $language['meta_title'],
'meta_description' => $language['meta_description'],
'meta_keywords' => $language['meta_keywords'],
'seo_link' => $language['seo_link'],
'copy_from' => $language['copy_from'],
'warehouse_message_zero' => $language['warehouse_message_zero'],
'warehouse_message_nonzero' => $language['warehouse_message_nonzero'],
'canonical' => $language['canonical'],
'xml_name' => $language['xml_name']
] );
}
}
$images = $mdb2 -> select( 'pp_shop_products_images', '*', [ 'product_id' => $product_id ] );
if ( is_array( $images ) )
{
foreach ( $images as $image )
{
$image_url = 'https://' . $shoppro_settings['domain'] . $image['src'];
// pobierz zdjęcie za pomocą curl
$ch = curl_init( $image_url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
$image_data = curl_exec( $ch );
$image_data;
curl_close( $ch );
// ścieżdka do nowego zdjęcia to "/upload/product_images/product_[product_id]/[nazwa_zdjęcia]
$image_name = basename( $image_url );
$image_path = '../upload/product_images/product_' . $new_product_id . '/' . $image_name;
// utwórz katalog dla zdjęć produktu jeśli nie istnieje
if ( !file_exists( '../upload/product_images/product_' . $new_product_id ) )
mkdir( '../upload/product_images/product_' . $new_product_id, 0777, true );
// zapisz zdjęcie
file_put_contents( $image_path, $image_data );
// zapisz zdjęcie w bazie danych
$mdb -> insert( 'pp_shop_products_images', [
'product_id' => $new_product_id,
'src' => '/upload/product_images/product_' . $new_product_id . '/' . $image_name,
'o' => $image['o']
] );
}
}
\S::alert( 'Produkt został zaimportowany.' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
}
\S::alert( 'Podczas importowania produktu wystąpił błąd.' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
}

View File

@@ -0,0 +1,83 @@
<?
namespace admin\controls;
class Languages
{
public static function language_delete()
{
if ( \admin\factory\Languages::language_delete( \S::get( 'id' ) ) )
\S::alert( 'Język został usunięty.' );
header( 'Location: /admin/languages/view_list/' );
exit;
}
public static function language_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania języka wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( \admin\factory\Languages::language_save(
$values['id'], $values['name'], $values['status'],
$values['start'], $values['o'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Język został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function language_edit()
{
return \admin\view\Languages::language_edit(
\admin\factory\Languages::language_details(
\S::get( 'id' )
), \admin\factory\Languages::max_order()
);
}
public static function view_list()
{
return \admin\view\Languages::languages_list();
}
public static function translation_delete()
{
if ( \admin\factory\Languages::translation_delete( \S::get( 'id' ) ) )
\S::alert( 'Tłumaczenie zostało usunięte.' );
header( 'Location: /admin/languages/translation_list/' );
exit;
}
public static function translation_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania tłumaczenia wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
$languages_list = \admin\factory\Languages::languages_list();
if ( is_array( $languages_list ) and !empty( $languages_list ) ) foreach ( $languages_list as $language )
{
\S::delete_session( 'lang-' . $language['id'] );
$languages[ $language['id'] ] = $values[ $language['id'] ];
}
if ( $id = \admin\factory\Languages::translation_save( $values['id'], $values['text'], $languages ) )
$response = [ 'status' => 'ok', 'msg' => 'Tłumaczenie zostało zapisane.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function translation_edit()
{
return \admin\view\Languages::translation_edit(
\admin\factory\Languages::translation_details( \S::get( 'id' ) ),
\admin\factory\Languages::languages_list()
);
}
public static function translation_list()
{
return \admin\view\Languages::translations_list();
}
}
?>

View File

@@ -0,0 +1,43 @@
<?php
namespace admin\controls;
class Layouts
{
public static function layout_delete()
{
if ( \admin\factory\Layouts::layout_delete( \S::get( 'id' ) ) )
\S::alert( 'Szablon został usunięty.' );
header( 'Location: /admin/layouts/view_list/' );
exit;
}
public static function layout_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania szablonu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Layouts::layout_save( $values['id'], $values['name'], $values['status'], $values['pages'], $values['html'], $values['css'], $values['js'], $values['m_html'],
$values['m_css'], $values['m_js'], $values['categories'], $values['categories_default'] )
)
$response = [ 'status' => 'ok', 'msg' => 'Szablon został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function layout_edit()
{
return \Tpl::view( 'layouts/layout-edit', [
'layout' => \admin\factory\Layouts::layout_details( \S::get( 'id' ) ),
'menus' => \admin\factory\Layouts::menus_list(),
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'dlang' => \front\factory\Languages::default_language()
] );
}
public static function view_list()
{
return \admin\view\Layouts::layouts_list();
}
}
?>

View File

@@ -0,0 +1,92 @@
<?php
namespace admin\controls;
class Newsletter
{
public static function emails_list()
{
return \admin\view\Newsletter::emails_list();
}
public static function send()
{
if ( \admin\factory\Newsletter::send( \S::get( 'dates' ), \S::get('template')) )
\S::alert( 'Newsletter został dodany do kolejki wysyłania.' );
header( 'Location: /admin/newsletter/prepare/' );
exit;
}
public static function prepare()
{
return \admin\view\Newsletter::prepare(
\admin\factory\Newsletter::templates_list()
);
}
public static function settings_save()
{
$settings = \admin\factory\Settings::settings_details();
$values = json_decode( \S::get( 'values' ), true );
\admin\factory\Settings::settings_update( 'newsletter_footer', $values['newsletter_footer'] );
\admin\factory\Settings::settings_update( 'newsletter_header', $values['newsletter_header'] );
\S::alert( 'Ustawienia zostały zapisane.' );
echo json_encode( [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.' ] );
exit;
}
public static function settings()
{
return \admin\view\Newsletter::settings(
\admin\factory\Settings::settings_details()
);
}
public static function email_templates_user()
{
return \admin\view\Newsletter::email_templates_user();
}
public static function email_templates_admin()
{
return \admin\view\Newsletter::email_templates_admin();
}
public static function email_template_delete()
{
$is_admin = \admin\factory\Newsletter::is_admin_template( \S::get( 'id' ) );
if ( !$is_admin and \admin\factory\Newsletter::newsletter_template_delete( \S::get( 'id' ) ) )
\S::alert( 'Szablon newslettera został usunięty.' );
if ( $is_admin )
header( 'Location: /admin/newsletter/email_templates_admin/' );
else
header( 'Location: /admin/newsletter/email_templates_user/' );
exit;
}
public static function email_template_edit()
{
return \admin\view\Newsletter::email_template_edit(
\admin\factory\Newsletter::email_template_detalis(
\S::get( 'id' )
)
);
}
public static function template_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Newsletter::template_save( $values['id'], $values['name'], $values['text'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Zmiany zostały zapisane.', 'id' => $id ];
echo json_encode( $response );
exit;
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace admin\controls;
class Pages
{
public static function pages_url_browser()
{
echo \Tpl::view( 'pages/pages-browse-list', [
'menus' => \admin\factory\Pages::menus_list(),
'modal' => \S::get( 'modal' )
] );
exit;
}
public static function browse_list()
{
return \admin\view\Pages::browse_list(
\admin\factory\Pages::menus_list()
);
}
public static function menu_delete()
{
if ( \admin\factory\Pages::menu_delete( \S::get( 'id' ) ) )
\S::set_message( 'Menu zostało usunięte.' );
else
\S::alert( 'Podczas usuwania menu wystąpił błąd. Aby usunąć menu nie może ono posiadać przypiętych stron.' );
header( 'Location: /admin/pages/view_list/' );
exit;
}
public static function page_delete()
{
if ( \admin\factory\Pages::page_delete( \S::get( 'id' ) ) )
\S::set_message( 'Strona została usunięta.' );
else
\S::alert( 'Podczas usuwania strony wystąpił błąd. Aby usunąć stronę nie może ona posiadać przypiętych podstron.' );
header( 'Location: /admin/pages/view_list/' );
exit;
}
public static function page_articles()
{
return \admin\view\Pages::page_articles( \S::get( 'id' ), \admin\factory\Pages::page_articles( \S::get( 'id' ) ) );
}
public static function page_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania strony wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Pages::page_save(
$values['id'], $values['title'], $values['seo_link'], $values['meta_title'], $values['meta_description'], $values['meta_keywords'], $values['menu_id'], $values['parent_id'], $values['page_type'],
$values['sort_type'], $values['layout_id'], $values['articles_limit'], $values['show_title'], $values['status'], $values['link'], $values['noindex'], $values['start'], $values['page_title'],
$values['canonical'], $values['category_id']
) )
$response = [ 'status' => 'ok', 'msg' => 'Strona została zapisana.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function page_edit()
{
return \Tpl::view( 'pages/page-edit', [
'page' => \admin\factory\Pages::page_details( \S::get( 'id' ) ),
'parent_id' => \S::get( 'pid' ),
'menu_id' => \S::get( 'menu_id' ),
'menus' => \admin\factory\Pages::menu_lists(),
'layouts' => \admin\factory\Layouts::layouts_list(),
'languages' => \admin\factory\Languages::languages_list()
] );
}
public static function menu_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania menu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( \admin\factory\Pages::menu_save( $values['id'], $values['name'], $values['status'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Menu zostało zapisane.' ];
echo json_encode( $response );
exit;
}
public static function menu_edit()
{
return \admin\view\Pages::menu_edit(
\admin\factory\Pages::menu_details( \S::get( 'id' ) )
);
}
public static function view_list()
{
return \Tpl::view( 'pages/pages-list', [
'menus' => \admin\factory\Pages::menus_list()
] );
}
}
?>

View File

@@ -0,0 +1,40 @@
<?php
namespace admin\controls;
class Scontainers
{
public static function container_delete()
{
if ( \admin\factory\Scontainers::container_delete( \S::get( 'id' ) ) )
\S::alert( 'Kontener został usunięty.' );
header( 'Location: /admin/scontainers/view_list/' );
exit;
}
public static function container_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kontenera wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Scontainers::container_save( $values['id'], $values['title'], $values['text'], $values['status'], $values['show_title'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Kontener został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function container_edit()
{
return \admin\view\Scontainers::container_edit(
\admin\factory\Scontainers::container_details(
\S::get( 'id' )
),
\admin\factory\Languages::languages_list()
);
}
public static function view_list()
{
return \admin\view\Scontainers::containers_list();
}
}

View File

@@ -0,0 +1,60 @@
<?
namespace admin\controls;
class Settings
{
public static function settings_save()
{
$values = json_decode( \S::get( 'values' ), true );
$settings = \admin\factory\Settings::settings_details( true );
$response = \admin\factory\Settings::settings_save(
$values['firm_name'], $values['firm_adress'], $values['additional_info'], $values['contact_form'], $values['contact_email'], $values['email_host'],
$values['email_port'], $values['email_login'], $values['email_password'], $values['google_maps'], $values['facebook_link'], $values['statistic_code'], $values['htaccess'],
$values['robots'], $values['shop_bank_account_info'], $values['update'], $values['boot_animation'], $settings['newsletter_header'], $settings['newsletter_footer'], $values['hotpay_api']
);
\admin\factory\Settings::settings_update( 'devel', $values['devel'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'ssl', $values['ssl'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'htaccess_cache', $values['htaccess_cache'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'free_delivery', $values['free_delivery'] );
\admin\factory\Settings::settings_update( 'przelewy24_sandbox', $values['przelewy24_sandbox'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'przelewy24_merchant_id', $values['przelewy24_merchant_id'] );
\admin\factory\Settings::settings_update( 'przelewy24_crc_key', $values['przelewy24_crc_key'] );
\admin\factory\Settings::settings_update( 'update_key', $values['update_key'] );
\admin\factory\Settings::settings_update( 'tpay_id', $values['tpay_id'] );
\admin\factory\Settings::settings_update( 'tpay_sandbox', $values['tpay_sandbox'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'tpay_security_code', $values['tpay_security_code'] );
\admin\factory\Settings::settings_update( 'piksel', $values['piksel'] );
\admin\factory\Settings::settings_update( 'generate_webp', $values['generate_webp'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'lazy_loading', $values['lazy_loading'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'ekomi_survey', $values['ekomi_survey'] );
\admin\factory\Settings::settings_update( 'google_tag_manager_id', $values['google_tag_manager_id'] );
\admin\factory\Settings::settings_update( 'infinitescroll', $values['infinitescroll'] == 'on' ? 1 : 0 );
// own_gtm_js
\admin\factory\Settings::settings_update( 'own_gtm_js', $values['own_gtm_js'] );
// own_gtm_html
\admin\factory\Settings::settings_update( 'own_gtm_html', $values['own_gtm_html'] );
foreach ( $values[ 'warehouse_message_zero'] as $key => $val )
\admin\factory\Settings::settings_update( 'warehouse_message_zero_' . $key, $val );
foreach ( $values[ 'warehouse_message_nonzero'] as $key => $val )
\admin\factory\Settings::settings_update( 'warehouse_message_nonzero_' . $key, $val );
\S::delete_dir( '../temp/' );
\S::htacces();
echo json_encode( $response );
exit;
}
public static function view()
{
return \Tpl::view( 'settings/settings', [
'languages' => \admin\factory\Languages::languages_list(),
'settings' => \admin\factory\Settings::settings_details()
] );
}
}
?>

View File

@@ -0,0 +1,71 @@
<?php
namespace admin\controls;
class ShopAttribute
{
static public function attribute_value_tpl()
{
$html = \Tpl::view( 'shop-attribute/_partials/value', [
'i' => \S::get( 'i' ),
'value' => \S::get( 'value' ),
'languages' => \S::get( 'languages' ),
'attribute' => \S::get( 'attribute' ),
] );
echo $html;
exit;
}
static public function values_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania wartości atrybutu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
;
if ( $id = \admin\factory\ShopAttribute::values_save( (int) \S::get( 'attribute_id' ), $values['name'], $values['value'], $values['ids'], $values['default_value'], $values['impact_on_the_price'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Wartości atrybutu zostały zapisane.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function values_edit()
{
return \Tpl::view( 'shop-attribute/values-edit', [
'attribute' => \admin\factory\ShopAttribute::attribute_details( (int) \S::get( 'attribute-id' ) ),
'values' => \admin\factory\ShopAttribute::get_attribute_values( (int) \S::get( 'attribute-id' ) ),
'languages' => \admin\factory\Languages::languages_list()
] );
}
public static function delete_attribute()
{
if ( \admin\factory\ShopAttribute::delete_attribute( (int) \S::get( 'id' ) ) )
\S::alert( 'Atrybut został usunięty.' );
header( 'Location: /admin/shop_attribute/view_list/' );
exit;
}
public static function attribute_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania atrybutu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopAttribute::attribute_save( (int) $values['id'], $values['name'], $values['status'] == 'on' ? 1 : 0, (int) $values['type'], (int) $values['o'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Atrybut został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
static public function attribute_edit()
{
return \Tpl::view( 'shop-attribute/attribute-edit', [
'attribute' => \admin\factory\ShopAttribute::attribute_details( (int) \S::get( 'id' ) ),
'languages' => \admin\factory\Languages::languages_list()
] );
}
public static function view_list()
{
return \Tpl::view( 'shop-attribute/attributes-list' );
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace admin\controls;
class ShopCategory
{
public static function category_products()
{
return \Tpl::view( 'shop-category/category-products', [
'category_id' => \S::get( 'id' ),
'products' => \admin\factory\ShopCategory::category_products( (int)\S::get( 'id' ) )
] );
}
public static function category_url_browser() {
echo \Tpl::view( 'shop-category/category-browse-list', [
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'level' => 0,
'dlang' => \front\factory\Languages::default_language()
] );
exit;
}
public static function category_delete()
{
if ( \admin\factory\ShopCategory::category_delete( \S::get( 'id' ) ) )
\S::set_message( 'Kategoria została usunięta.' );
else
\S::alert( 'Podczas usuwania kategorii wystąpił błąd. Aby usunąć kategorię nie może ona posiadać przypiętych podkategorii.' );
header( 'Location: /admin/shop_category/view_list/' );
exit;
}
static public function save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kategorii wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopCategory::save(
$values['id'], $values['title'], $values['text'], $values['text_hidden'], $values['seo_link'], $values['meta_title'], $values['meta_description'], $values['meta_keywords'], $values['parent_id'], $values['status'],
$values['noindex'], $values['category_title'], $values['sort_type'], $values['additional_text'], $values['view_subcategories']
) )
$response = [ 'status' => 'ok', 'msg' => 'Kategoria została zapisana.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function category_edit()
{
return \admin\view\ShopCategory::category_edit(
\admin\factory\ShopCategory::category_details(
\S::get( 'id' )
),
\S::get( 'pid' ),
\admin\factory\Languages::languages_list()
);
}
public static function view_list()
{
return \Tpl::view( 'shop-category/categories-list', [
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'level' => 0,
'dlang' => \front\factory\Languages::default_language()
] );
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace admin\controls;
class ShopClients
{
public static function view_list()
{
return \Tpl::view(
'shop-clients/view-list'
);
}
public static function clients_details()
{
$query_string = $_SERVER['REDIRECT_QUERY_STRING'];
parse_str($query_string, $query_array);
$orders_info = \admin\factory\ShopClients::get_order_all_info( $query_array['name'], $query_array['surname'], $query_array['email'] );
return \Tpl::view('shop-clients/clients-details', [
'name' => $query_array['name'],
'surname' => $query_array['surname'],
'email' => $query_array['email'],
'total_spent' => $query_array['total_spent'],
'orders_info' => $orders_info
]);
}
}
?>

View File

@@ -0,0 +1,58 @@
<?php
namespace admin\controls;
class ShopCoupon
{
public static function coupon_delete()
{
$coupon = new \shop\Coupon( (int)\S::get( 'id' ) );
if ( $coupon -> delete() )
\S::alert( 'Kupon został usunięty.' );
header( 'Location: /admin/shop_coupon/view_list/' );
exit;
}
public static function coupon_save()
{
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania kuponu wystąpił błąd. Proszę spróbować ponownie.'];
$values = json_decode( \S::get( 'values' ), true );
if ( $values['categories'] != null )
$categories = is_array( $values['categories'] ) ? json_encode( $values['categories'] ) : json_encode( [ $values['categories'] ] );
else
$categories = null;
if ( \admin\factory\ShopCoupon::save(
$values['id'],
$values['name'],
$values['status'] == 'on' ? 1 : 0,
$values['send'] == 'on' ? 1 : 0,
$values['used'] == 'on' ? 1 : 0,
$values['type'],
$values['amount'],
$values['one_time'] == 'on' ? 1 : 0,
$values['include_discounted_product'] == 'on' ? 1 : 0,
$categories
)
)
$response = [ 'status' => 'ok', 'msg' => 'Kupon został zapisany.', 'id' => $values['id'] ];
echo json_encode( $response );
exit;
}
public static function coupon_edit()
{
return \Tpl::view( 'shop-coupon/coupon-edit', [
'coupon' => \admin\factory\ShopCoupon::details( (int)\S::get( 'id' ) ),
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'dlang' => \front\factory\Languages::default_language()
] );
}
public static function view_list()
{
return \Tpl::view( 'shop-coupon/view-list' );
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace admin\controls;
class ShopOrder
{
static public function order_resend_confirmation_email()
{
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
$response = $order -> order_resend_confirmation_email();
echo json_encode( [ 'result' => $response ] );
exit;
}
static public function notes_save()
{
\shop\Order::notes_save( \S::get( 'order_id' ), \S::get( 'notes' ) );
}
static public function order_save()
{
if ( \shop\Order::order_save_by_admin(
\S::get( 'order_id' ), \S::get( 'client_name' ), \S::get( 'client_surname' ), \S::get( 'client_firm' ), \S::get( 'client_street' ), \S::get( 'client_postal_code' ), \S::get( 'client_city' ), \S::get( 'client_email' ),
\S::get( 'transport_id' ), \S::get( 'inpost_paczkomat' ), \S::get( 'payment_method_id' )
) )
\S::alert( 'Zamówienie zostało zapisane.' );
header( 'Location: /admin/shop_order/order_details/order_id=' . \S::get( 'order_id' ) );
exit;
}
static public function order_edit()
{
return \Tpl::view( 'shop-order/order-edit', [
'order' => new \shop\Order( (int)\S::get( 'order_id' ) ),
'order_statuses' => \shop\Order::order_statuses(),
'transport' => \shop\Transport::transport_list(),
'payment_methods' => \shop\PaymentMethod::method_list()
] );
}
public static function order_details()
{
return \Tpl::view( 'shop-order/order-details', [
'order' => new \shop\Order( (int)\S::get( 'order_id' ) ),
'order_statuses' => \shop\Order::order_statuses(),
'next_order_id' => \admin\factory\ShopOrder::next_order_id( (int)\S::get( 'order_id' ) ),
'prev_order_id' => \admin\factory\ShopOrder::prev_order_id( (int)\S::get( 'order_id' ) ),
] );
}
public static function view_list()
{
return \Tpl::view(
'shop-order/view-list'
);
}
public static function order_status_change()
{
global $mdb;
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
$response = $order -> update_status( (int)\S::get( 'status' ), \S::get( 'email' ) == 'true' ? 1 : 0 );
echo json_encode( $response );
exit;
}
public static function order_delete()
{
global $user;
if ( \shop\Order::order_delete( (int)\S::get( 'id' ) ) )
{
\S::alert( 'Zamówienie zostało usunięte' );
\Log::save_log( 'Usunięcie zamówienia | ID: ' . (int)\S::get( 'id' ), $user['id'] );
}
header( 'Location: /admin/shop_order/view_list/' );
exit;
}
// set_order_as_unpaid
public static function set_order_as_unpaid()
{
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
$order -> set_as_unpaid();
header( 'Location: /admin/shop_order/order_details/order_id=' . (int)\S::get( 'order_id' ) );
exit;
}
// set_order_as_paid
public static function set_order_as_paid()
{
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
if ( $order -> set_as_paid() )
{
$order -> update_status( 4, (int)\S::get( 'send_mail' ) );
}
header( 'Location: /admin/shop_order/order_details/order_id=' . (int)\S::get( 'order_id' ) );
exit;
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace admin\controls;
class ShopPaymentMethod
{
public static function view_list()
{
return \Tpl::view( 'shop-payment-method/view-list', [
'apilo_payment_types_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'payment-types-list' ) ),
'sellasist_payment_types_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'payment_types_list' ) ),
] );
}
}

View File

@@ -0,0 +1,37 @@
<?
namespace admin\controls;
class ShopProducer
{
static public function delete()
{
if ( \admin\factory\ShopProducer::delete( \S::get( 'id' ) ) )
\S::alert( 'Producent został usunięty' );
header( 'Location: /admin/shop_producer/list/' );
exit;
}
static public function save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania producenta wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $producer_id = \admin\factory\ShopProducer::save( $values['id'], $values['name'], $values['status'] == 'on' ? 1 : 0, $values['img'], $values['description'], $values['meta_title'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Producent został zapisany.', 'id' => $producer_id ];
echo json_encode( $response );
exit;
}
static public function edit()
{
return \Tpl::view( 'shop-producer/edit', [
'producer' => \S::get( 'id' ) ? new \shop\Producer( \S::get( 'id' ) ) : null,
'languages' => \admin\factory\Languages::languages_list()
] );
}
static public function list()
{
return \Tpl::view( 'shop-producer/list' );
}
}

View File

@@ -0,0 +1,419 @@
<?php
namespace admin\controls;
class ShopProduct
{
static public function mass_edit_save()
{
global $mdb;
if ( \S::get( 'discount_percent' ) != '' and \S::get( 'products' ) )
{
$product_details = \admin\factory\ShopProduct::product_details( \S::get( 'products' )[0] );
$vat = $product_details['vat'];
$price_brutto = $product_details['price_brutto'];
$price_brutto_promo = $price_brutto - ( $price_brutto * ( \S::get( 'discount_percent' ) / 100 ) );
$price_netto = $product_details['price_netto'];
$price_netto_promo = $price_netto - ( $price_netto * ( \S::get( 'discount_percent' ) / 100 ) );
if ( $price_brutto == $price_brutto_promo)
$price_brutto_promo = null;
if ( $price_netto == $price_netto_promo )
$price_netto_promo = null;
$mdb -> update( 'pp_shop_products', [ 'price_brutto_promo' => $price_brutto_promo, 'price_netto_promo' => $price_netto_promo ], [ 'id' => \S::get( 'products' )[0] ] );
\admin\factory\ShopProduct::update_product_combinations_prices( \S::get( 'products' )[0], $price_netto, $vat, $price_netto_promo );
echo json_encode( [ 'status' => 'ok', 'price_brutto_promo' => $price_brutto_promo, 'price_brutto' => $price_brutto ] );
exit;
}
echo json_encode( [ 'status' => 'error' ] );
exit;
}
// get_products_by_category
static public function get_products_by_category() {
global $mdb;
$products = $mdb -> select( 'pp_shop_products_categories', 'product_id', [ 'category_id' => \S::get( 'category_id' ) ] );
echo json_encode( [ 'status' => 'ok', 'products' => $products ] );
exit;
}
static public function mass_edit()
{
return \Tpl::view( 'shop-product/mass-edit', [
'products' => \admin\factory\ShopProduct::products_list(),
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'dlang' => \front\factory\Languages::default_language()
] );
}
static public function generate_combination()
{
foreach ( $_POST as $key => $val )
{
if ( strpos( $key, 'attribute_' ) !== false )
{
$attribute = explode( 'attribute_', $key );
$attributes[ $attribute[1] ] = $val;
}
}
if ( \admin\factory\ShopProduct::generate_permutation( (int) \S::get( 'product_id' ), $attributes ) )
\S::alert( 'Kombinacje produktu zostały wygenerowane.' );
header( 'Location: /admin/shop_product/product_combination/product_id=' . (int) \S::get( 'product_id' ) );
exit;
}
//usunięcie kombinacji produktu
static public function delete_combination()
{
if ( \admin\factory\ShopProduct::delete_combination( (int)\S::get( 'combination_id' ) ) )
\S::alert( 'Kombinacja produktu została usunięta' );
else
\S::alert( 'Podczas usuwania kombinacji produktu wystąpił błąd. Proszę spróbować ponownie' );
header( 'Location: /admin/shop_product/product_combination/product_id=' . \S::get( 'product_id' ) );
exit;
}
static public function duplicate_product()
{
if ( \admin\factory\ShopProduct::duplicate_product( (int)\S::get( 'product-id' ), (int)\S::get( 'combination' ) ) )
\S::set_message( 'Produkt został zduplikowany.' );
else
\S::alert( 'Podczas duplikowania produktu wystąpił błąd. Proszę spróbować ponownie' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
public static function image_delete()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas usuwania zdjecia wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \admin\factory\ShopProduct::delete_img( \S::get( 'image_id' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
public static function images_order_save()
{
if ( \admin\factory\ShopProduct::images_order_save( \S::get( 'product_id' ), \S::get( 'order' ) ) )
echo json_encode( [ 'status' => 'ok', 'msg' => 'Produkt został zapisany.' ] );
exit;
}
public static function image_alt_change()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany atrybutu alt zdjęcia wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \admin\factory\ShopProduct::image_alt_change( \S::get( 'image_id' ), \S::get( 'image_alt' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
// szybka zmiana statusu produktu
static public function change_product_status() {
if ( \admin\factory\ShopProduct::change_product_status( (int)\S::get( 'product-id' ) ) )
\S::set_message( 'Status produktu został zmieniony' );
header( 'Location: ' . $_SERVER['HTTP_REFERER'] );
exit;
}
// szybka zmiana google xml label
static public function product_change_custom_label()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany google xml label wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \admin\factory\ShopProduct::product_change_custom_label( (int) \S::get( 'product_id' ), \S::get( 'custom_label' ), \S::get( 'value' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
// szybka zmiana ceny promocyjnej
static public function product_change_price_brutto_promo()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany ceny wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \admin\factory\ShopProduct::product_change_price_brutto_promo( (int) \S::get( 'product_id' ), \S::get( 'price' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
// szybka zmiana ceny
static public function product_change_price_brutto()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany ceny wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \admin\factory\ShopProduct::product_change_price_brutto( (int) \S::get( 'product_id' ), \S::get( 'price' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
// pobierz bezpośredni url produktu
static public function ajax_product_url()
{
echo json_encode( [ 'url' => \shop\Product::getProductUrl( \S::get( 'product_id' ) ) ] );
exit;
}
// zapisanie produktu
public static function save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopProduct::save(
$values['id'], $values['name'], $values['short_description'], $values['description'], $values['status'], $values['meta_description'], $values['meta_keywords'], $values['seo_link'],
$values['copy_from'], $values['categories'], $values['price_netto'], $values['price_brutto'], $values['vat'], $values['promoted'], $values['warehouse_message_zero'], $values['warehouse_message_nonzero'], $values['tab_name_1'],
$values['tab_description_1'], $values['tab_name_2'], $values['tab_description_2'], $values['layout_id'], $values['products_related'], (int) $values['set'], $values['price_netto_promo'], $values['price_brutto_promo'],
$values['new_to_date'], $values['stock_0_buy'], $values['wp'], $values['custom_label_0'], $values['custom_label_1'], $values['custom_label_2'], $values['custom_label_3'], $values['custom_label_4'], $values['additional_message'], (int)$values['quantity'], $values['additional_message_text'], $values['additional_message_required'] == 'on' ? 1 : 0, $values['canonical'], $values['meta_title'], $values['producer_id'], $values['sku'], $values['ean'], $values['product_unit'], $values['weight'], $values['xml_name'], $values['custom_field_name']
) ) {
$response = [ 'status' => 'ok', 'msg' => 'Produkt został zapisany.', 'id' => $id ];
}
echo json_encode( $response );
exit;
}
// product_unarchive
static public function product_unarchive()
{
if ( \admin\factory\ShopProduct::product_unarchive( (int) \S::get( 'product_id' ) ) )
\S::alert( 'Produkt został przywrócony z archiwum.' );
else
\S::alert( 'Podczas przywracania produktu z archiwum wystąpił błąd. Proszę spróbować ponownie' );
header( 'Location: /admin/archive/products_list/' );
exit;
}
static public function product_archive()
{
if ( \admin\factory\ShopProduct::product_archive( (int) \S::get( 'product_id' ) ) )
\S::alert( 'Produkt został przeniesiony do archiwum.' );
else
\S::alert( 'Podczas przenoszenia produktu do archiwum wystąpił błąd. Proszę spróbować ponownie' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
public static function product_delete()
{
if ( \admin\factory\ShopProduct::product_delete( (int) \S::get( 'id' ) ) )
\S::set_message( 'Produkt został usunięty.' );
else
\S::alert( 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
// edycja produktu
public static function product_edit()
{
\admin\factory\ShopProduct::delete_nonassigned_images();
\admin\factory\ShopProduct::delete_nonassigned_files();
return \Tpl::view( 'shop-product/product-edit', [
'product' => \admin\factory\ShopProduct::product_details( (int) \S::get( 'id' ) ),
'languages' => \admin\factory\Languages::languages_list(),
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'layouts' => \admin\factory\Layouts::layouts_list(),
'products' => \admin\factory\ShopProduct::products_list(),
'dlang' => \front\factory\Languages::default_language(),
'sets' => \shop\ProductSet::sets_list(),
'producers' => \admin\factory\ShopProducer::all(),
'units' => \admin\factory\Dictionaries::all_units()
] );
}
// ajax_load_products ARCHIVE
static public function ajax_load_products_archive()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas ładowania produktów wystąpił błąd. Proszę spróbować ponownie.' ];
\S::set_session( 'products_list_current_page', \S::get( 'current_page' ) );
\S::set_session( 'products_list_query', \S::get( 'query' ) );
if ( $products = \admin\factory\ShopProduct::ajax_products_list_archive( \S::get_session( 'products_list_current_page' ), \S::get_session( 'products_list_query' ) ) ) {
$response = [
'status' => 'ok',
'pagination_max' => ceil( $products['products_count'] / 10 ),
'html' => \Tpl::view( 'archive/products-list-table', [
'products' => $products['products'],
'current_page' => \S::get( 'current_page' ),
] )
];
}
echo json_encode( $response );
exit;
}
// ajax_load_products
static public function ajax_load_products() {
$response = [ 'status' => 'error', 'msg' => 'Podczas ładowania produktów wystąpił błąd. Proszę spróbować ponownie.' ];
\S::set_session( 'products_list_current_page', \S::get( 'current_page' ) );
\S::set_session( 'products_list_query', \S::get( 'query' ) );
if ( $products = \admin\factory\ShopProduct::ajax_products_list( \S::get_session( 'products_list_current_page' ), \S::get_session( 'products_list_query' ) ) ) {
$response = [
'status' => 'ok',
'pagination_max' => ceil( $products['products_count'] / 10 ),
'html' => \Tpl::view( 'shop-product/products-list-table', [
'products' => $products['products'],
'current_page' => \S::get( 'current_page' ),
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
'show_xml_data' => \S::get_session( 'show_xml_data' )
] )
];
}
echo json_encode( $response );
exit;
}
static public function view_list()
{
$current_page = \S::get_session( 'products_list_current_page' );
if ( !$current_page ) {
$current_page = 1;
\S::set_session( 'products_list_current_page', $current_page );
}
$query = \S::get_session( 'products_list_query' );
if ( $query ) {
$query_array = [];
parse_str( $query, $query_array );
}
if ( \S::get( 'show_xml_data' ) === 'true' ) {
\S::set_session( 'show_xml_data', true );
} else if ( \S::get( 'show_xml_data' ) === 'false' ) {
\S::set_session( 'show_xml_data', false );
}
return \Tpl::view( 'shop-product/products-list', [
'current_page' => $current_page,
'query_array' => $query_array,
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product() / 10 ),
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
'show_xml_data' => \S::get_session( 'show_xml_data' ),
'shoppro_enabled' => \admin\factory\Integrations::shoppro_settings( 'enabled' )
] );
}
//
// KOMBINACJE PRODUKTU
//
// zapisanie możliwości zakupu przy stanie 0 w kombinacji produktu
static public function product_combination_stock_0_buy_save()
{
\admin\factory\ShopProduct::product_combination_stock_0_buy_save( (int)\S::get( 'product_id' ), \S::get( 'stock_0_buy' ) );
exit;
}
// zapisanie sku w kombinacji produktu
static public function product_combination_sku_save()
{
\admin\factory\ShopProduct::product_combination_sku_save( (int)\S::get( 'product_id' ), \S::get( 'sku' ) );
exit;
}
// zapisanie ilości w kombinacji produktu
static public function product_combination_quantity_save()
{
\admin\factory\ShopProduct::product_combination_quantity_save( (int)\S::get( 'product_id' ), \S::get( 'quantity' ) );
exit;
}
// zapisanie ceny w kombinacji produktu
static public function product_combination_price_save()
{
\admin\factory\ShopProduct::product_combination_price_save( (int)\S::get( 'product_id' ), \S::get( 'price' ) );
exit;
}
//wyświetlenie kombinacji produktu
static public function product_combination()
{
return \Tpl::view( 'shop-product/product-combination', [
'product' => \admin\factory\ShopProduct::product_details( (int) \S::get( 'product_id' ) ),
'attributes' => \admin\factory\ShopAttribute::get_attributes_list(),
'default_language' => \front\factory\Languages::default_language(),
'product_permutations' => \admin\factory\ShopProduct::get_product_permutations( (int) \S::get( 'product_id' ) )
] );
}
// generate_sku_code
static public function generate_sku_code() {
$response = [ 'status' => 'error', 'msg' => 'Podczas generowania kodu sku wystąpił błąd. Proszę spróbować ponownie.' ];
if ( $sku = \shop\Product::generate_sku_code( \S::get( 'product_id' ) ) )
$response = [ 'status' => 'ok', 'sku' => $sku ];
echo json_encode( $response );
exit;
}
// product_xml_name_save
static public function product_xml_name_save() {
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania nazwy produktu wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \shop\Product::product_xml_name_save( \S::get( 'product_id' ), \S::get( 'product_xml_name' ), \S::get( 'lang_id' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
// product_custom_label_suggestions
static public function product_custom_label_suggestions() {
$response = [ 'status' => 'error', 'msg' => 'Podczas pobierania sugestii dla custom label wystąpił błąd. Proszę spróbować ponownie.' ];
if ( $suggestions = \shop\Product::product_custom_label_suggestions( \S::get( 'custom_label' ), \S::get( 'label_type' ) ) )
$response = [ 'status' => 'ok', 'suggestions' => $suggestions ];
echo json_encode( $response );
exit;
}
// product_custom_label_save
static public function product_custom_label_save() {
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania custom label wystąpił błąd. Proszę spróbować ponownie.' ];
if ( \shop\Product::product_custom_label_save( \S::get( 'product_id' ), \S::get( 'custom_label' ), \S::get( 'label_type' ) ) )
$response = [ 'status' => 'ok' ];
echo json_encode( $response );
exit;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace admin\controls;
class ShopProductSets
{
static public function set_delete()
{
if ( \shop\ProductSet::set_delete( \S::get( 'id' ) ) )
\S::set_message( 'Komplet produktów usunięty.' );
else
\S::alert( 'Podczas usuwania kompletu produktów wystąpił błąd. Proszę spróbować ponownie' );
header( 'Location: /admin/shop_product_sets/view_list/' );
exit;
}
static public function save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kompletu produktów wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopProductSet::save(
(int)$values['id'], $values['name'], (string) $values['status'], $values['set_products_id']
) ) {
$response = [ 'status' => 'ok', 'msg' => 'Komplet produktów został zapisany.', 'id' => $id ];
}
echo json_encode( $response );
exit;
}
static public function set_edit()
{
return \Tpl::view( 'shop-product-sets/set-edit', [
'set' => new \shop\ProductSet( (int) \S::get( 'id' ) ),
'products' => \admin\factory\ShopProduct::products_list()
] );
}
static public function view_list()
{
return \Tpl::view( 'shop-product-sets/view-list' );
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace admin\controls;
class ShopPromotion
{
// usunięcie promocji
static public function promotion_delete()
{
$promotion = \R::load( 'pp_shop_promotion', (int)\S::get( 'id' ) );
if ( \R::trash( $promotion ) )
\S::alert( 'Promocja została usunięta' );
header( 'Location: /admin/shop_promotion/view_list/' );
exit;
}
// zapisanie promocji
static public function save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania promocji wystąpił błąd. Proszę spróbować ponownie' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopPromotion::save(
$values['id'],
$values['name'],
$values['status'] == 'on' ? 1 : 0,
$values['condition_type'],
$values['discount_type'],
$values['amount'],
$values['date_to'],
$values['categories'],
$values['condition_categories'],
$values['include_coupon'] == 'on' ? 1 : 0,
$values['include_product_promo'] == 'on' ? 1 : 0,
$values['min_product_count'],
$values['price_cheapest_product']
) )
$response = [ 'status' => 'ok', 'msg' => 'Promocja została zapisana', 'id' => $id ];
echo json_encode( $response );
exit;
}
// edycja promocji
static public function edit()
{
return \Tpl::view( 'shop-promotion/promotion-edit', [
'promotion' => \admin\factory\ShopPromotion::promotion_details( (int)\S::get( 'id' ) ),
'categories' => \admin\factory\ShopCategory::subcategories( null ),
'dlang' => \front\factory\Languages::default_language()
] );
}
// lista promocji
public static function view_list()
{
return \Tpl::view( 'shop-promotion/view-list' );
}
}

View File

@@ -0,0 +1,38 @@
<?
namespace admin\controls;
class ShopStatuses {
// status_save
public static function status_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania statusu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'], $values['sellasist_status_id'], $values['baselinker_status_id'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Status został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
// status_edit
public static function status_edit()
{
return \Tpl::view( 'shop-statuses/status-edit', [
'status' => \admin\factory\ShopStatuses::get_status( \S::get( 'id' ) ),
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
] );
}
static public function view_list()
{
return \Tpl::view( 'shop-statuses/view-list', [
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
] );
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace admin\controls;
class ShopTransport
{
public static function transport_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania rodzaju transportu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopTransport::transport_save(
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['sellasist_shipment_method_id'], $values['delivery_free']
) )
$response = [ 'status' => 'ok', 'msg' => 'Rodzaj transportu został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function transport_edit()
{
return \Tpl::view( 'shop-transport/transport-edit', [
'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
'payments_list' => \admin\factory\ShopPaymentMethod::payments_list(),
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
] );
}
public static function view_list()
{
return \Tpl::view( 'shop-transport/view-list', [
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
] );
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace admin\controls;
class Update
{
public static function update()
{
if ( !\admin\factory\Update::update() )
\S::alert( 'W trakcie aktualizacji systemu wystąpił błąd. Proszę spróbować ponownie.' );
else
\S::set_message( 'Aktualizacja przebiegła pomyślnie.' );
header( 'Location: /admin/update/main_view/' );
exit;
}
public static function updateAll()
{
$response['status'] = \admin\factory\Update::update();
$response['version'] = number_format( \S::get('version_current') + 0.001, 3, '.', '' );
echo json_encode( $response );
exit;
}
public static function main_view()
{
return \admin\view\Update::main_view();
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace admin\controls;
class Users
{
public static function user_delete()
{
if ( \admin\factory\Users::user_delete( \S::get( 'id' ) ) )
\S::alert( 'Użytkownik został usunięty.' );
header( 'Location: /admin/users/view_list/' );
exit;
}
public static function user_save()
{
$values = json_decode( \S::get( 'values' ), true );
$response = \admin\factory\Users::user_save( $values['id'], $values['login'], $values['status'], $values['password'], $values['password_re'], $values['admin'] );
echo json_encode( $response );
exit;
}
public static function user_edit()
{
return \admin\view\Users::user_edit(
\admin\factory\Users::user_details(
\S::get( 'id' )
)
);
}
public static function view_list()
{
return \admin\view\Users::users_list();
}
}
?>

View 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 ] );
}
}
?>

View 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;
}
}

View 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;
}
}
?>

View 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'];
}
}

View 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 ] );
}
}

View 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'];
}
}

View 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' ] ] );
}
}
?>

View 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' ] ] );
}
}
?>

View 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' ] ] );
}
}

View 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;
}
}
?>

View 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;
}
}

View 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;
}
}
?>

View 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;
}
}

View 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;
}
}

View 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;}
}
?>

View 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;
}
}
}

View 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 ] );
}
}

View 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'] ] );
}
}

View 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;
}
}

File diff suppressed because it is too large Load Diff

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}

View 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;
}
}

View 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' ] );
}
}

View 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 ] );
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
namespace admin\view;
class Articles
{
public static function browse_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'articles/articles-browse-list' );
}
public static function subpages_list( $pages, $article_pages, $parent_id = 0, $step = 1 )
{
$tpl = new \Tpl();
$tpl -> pages = $pages;
$tpl -> parent_id = $parent_id;
$tpl -> step = $step;
$tpl -> article_pages = $article_pages;
return $tpl -> render( 'articles/subpages-list' );
}
public static function articles_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'articles/articles-list' );
}
public static function article_edit( $article, $menus, $languages, $layouts )
{
$tpl = new \Tpl;
$tpl -> article = $article;
$tpl -> menus = $menus;
$tpl -> languages = $languages;
$tpl -> layouts = $layouts;
return $tpl -> render( 'articles/article-edit' );
}
}
?>

View File

@@ -0,0 +1,11 @@
<?php
namespace admin\view;
class ArticlesArchive
{
public static function articles_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'articles/articles-archive-list' );
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace admin\view;
class Banners
{
public static function banners_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'banners/banners-list' );
}
public static function banner_edit( $banner, $languages )
{
$tpl = new \Tpl;
$tpl -> banner = $banner;
$tpl -> languages = $languages;
return $tpl -> render( 'banners/banner-edit' );
}
}
?>

View File

@@ -0,0 +1,12 @@
<?php
namespace admin\view;
class FileManager
{
public function filemanager()
{
$tpl = new \Tpl;
return $tpl -> render( 'filemanager/filemanager' );
}
}
?>

View File

@@ -0,0 +1,34 @@
<?
namespace admin\view;
class Languages
{
public static function translation_edit( $translation, $languages )
{
$tpl = new \Tpl;
$tpl -> languages = $languages;
$tpl -> translation = $translation;
return $tpl -> render( 'languages/translation-edit' );
}
public static function language_edit( $language, $order )
{
$tpl = new \Tpl;
$tpl -> language = $language;
$tpl -> order = $order;
return $tpl -> render( 'languages/language-edit' );
}
public static function translations_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'languages/translations-list' );
}
public static function languages_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'languages/languages-list' );
}
}
?>

View File

@@ -0,0 +1,21 @@
<?php
namespace admin\view;
class Layouts
{
public static function subpages_list( $pages, $layout_pages, $parent_id = null, $step = 1 )
{
$tpl = new \Tpl;
$tpl -> pages = $pages;
$tpl -> step = $step;
$tpl -> layout_pages = $layout_pages;
return $tpl -> render( 'layouts/subpages-list' );
}
public static function layouts_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'layouts/layouts-list' );
}
}
?>

View File

@@ -0,0 +1,55 @@
<?php
namespace admin\view;
class Newsletter
{
public static function emails_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'newsletter/emails-list' );
}
public static function preview( $articles, $settings, $template, $dates = '' )
{
$tpl = new \Tpl;
$tpl -> articles = $articles;
$tpl -> settings = $settings;
$tpl -> template = $template;
$tpl -> dates = $dates;
return $tpl -> render( 'newsletter/preview' );
}
public static function prepare( $templates )
{
$tpl = new \Tpl;
$tpl -> templates = $templates;
return $tpl -> render( 'newsletter/prepare' );
}
public static function settings( $settings )
{
$tpl = new \Tpl;
$tpl -> settings = $settings;
return $tpl -> render( 'newsletter/settings' );
}
public static function email_templates_user()
{
$tpl = new \Tpl;
return $tpl -> render( 'newsletter/email-templates-user' );
}
public static function email_templates_admin()
{
$tpl = new \Tpl;
return $tpl -> render( 'newsletter/email-templates-admin' );
}
public static function email_template_edit($template)
{
$tpl = new \Tpl;
$tpl -> email_template = $template;
return $tpl -> render( 'newsletter/email-template-edit' );
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace admin\view;
class Page {
public static function show()
{
global $user;
if ( !$user || !$user['admin'] )
return \admin\view\Users::login_form();
$tpl = new \Tpl;
$tpl -> content = \admin\Site::route();
return $tpl -> render( 'site/main-layout' );
}
}
?>

View File

@@ -0,0 +1,21 @@
<?php
namespace admin\view;
class PagePanel {
public static function show( $add = false, $save = false, $cancel = false, $title = '', $form = 'formularz', $back = false, $update = false, $save_ajax = false, $delete_ajax = false )
{
$tpl = new \Tpl();
$tpl -> _add = $add;
$tpl -> _save = $save;
$tpl -> _cancel = $cancel;
$tpl -> _id_form = $form;
$tpl -> _title = $title;
$tpl -> _back = $back;
$tpl -> _update = $update;
$tpl -> _save_ajax = $save_ajax;
$tpl -> _delete_ajax = $delete_ajax;
return $tpl -> render( 'other/page-panel' );
}
}
?>

View File

@@ -0,0 +1,37 @@
<?
namespace admin\view;
class Pages
{
public static function subpages_browse_list( $pages, $parent_id = null, $step = 1 )
{
$tpl = new \Tpl();
$tpl -> pages = $pages;
$tpl -> parent_id = $parent_id;
$tpl -> step = $step;
return $tpl -> render( 'pages/subpages-browse-list' );
}
public static function browse_list( $menus )
{
$tpl = new \Tpl;
$tpl -> menus = $menus;
return $tpl -> render( 'pages/pages-browse-list' );
}
public static function page_articles( $page_id, $articles )
{
$tpl = new \Tpl;
$tpl -> page_id = $page_id;
$tpl -> articles = $articles;
return $tpl -> render( 'pages/page-articles' );
}
public static function menu_edit( $menu )
{
$tpl = new \Tpl;
$tpl -> menu = $menu;
return $tpl -> render( 'pages/menu-edit' );
}
}
?>

View File

@@ -0,0 +1,20 @@
<?php
namespace admin\view;
class Scontainers
{
public static function container_edit( $container, $languages )
{
$tpl = new \Tpl;
$tpl -> container = $container;
$tpl -> languages = $languages;
return $tpl -> render( 'scontainers/container-edit' );
}
public static function containers_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'scontainers/containers-list' );
}
}

View File

@@ -0,0 +1,13 @@
<?
namespace admin\view;
class Settings
{
public static function view( $settings )
{
$tpl = new \Tpl;
$tpl -> settings = $settings;
return $tpl -> render( 'settings/settings' );
}
}
?>

View File

@@ -0,0 +1,13 @@
<?php
namespace admin\view;
class ShopAttribute
{
public static function values_edit( $attribute, $values, $languages )
{
$tpl = new \Tpl;
$tpl -> attribute = $attribute;
$tpl -> values = $values;
$tpl -> languages = $languages;
return $tpl -> render( 'shop-attribute/values-edit' );
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace admin\view;
class ShopCategory
{
public static function category_edit( $category, $pid = '', $languages )
{
$tpl = new \Tpl;
$tpl -> languages = $languages;
$tpl -> pid = $pid;
$tpl -> category = $category;
return $tpl -> render( 'shop-category/category-edit' );
}
public static function subcategories_list( $categories_list, $level )
{
$tpl = new \Tpl;
$tpl -> level = $level;
$tpl -> categories = $categories_list;
return $tpl -> render( 'shop-category/subcategories-list' );
}
}

View File

@@ -0,0 +1,6 @@
<?php
namespace admin\view;
class ShopPaymentMethod
{
}

View File

@@ -0,0 +1,11 @@
<?php
namespace admin\view;
class ShopProduct
{
public static function products_list()
{
$tpl = new \Tpl();
return $tpl -> render('shop-product/products-list');
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace admin\view;
class ShopTransport
{
}

View File

@@ -0,0 +1,13 @@
<?php
namespace admin\view;
class Update
{
public static function main_view()
{
$tpl = new \Tpl;
$tpl -> ver = \S::get_version();
$tpl -> new_ver = \S::get_new_version();
return $tpl -> render( 'update/main-view' );
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace admin\view;
class Users
{
public static function login_form()
{
$tpl = new \Tpl;
return $tpl -> render( 'site/unlogged-layout' );
}
public static function users_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'users/users-list' );
}
public static function user_edit( $user )
{
$tpl = new \Tpl;
$tpl -> user = $user;
return $tpl -> render( 'users/user-edit' );
}
}
?>