<?php
include '../_plugins/medoo.php';

// drmaterac.pl
// Połączenie z bazą danych
// $mdb = new medoo([
//     'database_type' => 'mysql',
//     'database_name' => 'admin_drmaterac',
//     'server' => 'dedyk8.cyber-folks.pl',
//     'username' => 'admin_drmaterac',
//     'password' => 'eRbZ]Ioh-0-2]fM+',
//     'charset' => 'utf8'
// ] );

// $mdb2 = new medoo([
//     'database_type' => 'mysql',
//     'database_name' => 'admin_drbck',
//     'server' => 'dedyk8.cyber-folks.pl',
//     'username' => 'admin_drbck',
//     'password' => '87d.N7#RSk-G@Pl-',
//     'charset' => 'utf8'
// ] );

// // get status (active) from materac_product from mdb2
// // $results = $mdb2 -> select( 'materac_product', '*', [ 'id_product' => 23418 ] );
// // foreach ( $results as $row )
// // {
// //   $mdb -> update( 'materac_product', [ 'active' => $row['active'] ], [ 'id_product' => $row['id_product'] ] );
// // }

// // copy price from materac_product from mdb2 to drmaterac.pl
// $results = $mdb2 -> select( 'materac_product', '*' );
// foreach ( $results as $row )
// {
//   // update price in materac_product
//   $mdb -> update( 'materac_product', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'] ] );
// }

// // copy price from materac_product_shop from mdb2 to drmaterac.pl
// $results = $mdb2 -> select( 'materac_product_shop', '*', [ 'id_shop' => 1 ] );
// foreach ( $results as $row )
// {
//   // update price in materac_product_shop
//   $mdb -> update( 'materac_product_shop', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'], 'id_shop' => $row['id_shop'] ] );
// }

// // copy price from materac_product_attribute from mdb2 to drmaterac.pl
// $results = $mdb2 -> select( 'materac_product_attribute', '*' );
// foreach ( $results as $row )
// {
//   // update price in materac_product_attribute
//   $mdb -> update( 'materac_product_attribute', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'], 'id_product_attribute' => $row['id_product_attribute'] ] );
// }

// // copy price from materac_product_attribute_shop from mdb2 to drmaterac.pl
// $results = $mdb2 -> select( 'materac_product_attribute_shop', '*', [ 'id_shop' => 1 ] );
// foreach ( $results as $row )
// {
//   // update price in materac_product_attribute_shop
//   $mdb -> update( 'materac_product_attribute_shop', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'], 'id_product_attribute' => $row['id_product_attribute'] ] );
// }
// ECHO 'Import zakończony sukcesem! drmaterac.pl<br>';

// // get status (active) from materac_product_shop from mdb2
// $results = $mdb2 -> select( 'materac_product_shop', '*' );
// foreach ( $results as $row )
// {
//   $mdb -> update( 'materac_product_shop', [ 'active' => $row['active'] ], [ 'id_product' => $row['id_product'] ] );
// }

// $results = $mdb -> select( 'materac_product', '*', [ 'price' => '0.0' ] );
// foreach ( $results as $row )
// {
//   $price = $mdb2 -> get( 'materac_product', 'price', [ 'id_product' => $row['id_product'] ] );
//   $mdb -> update( 'materac_product', [ 'price' => $price ], [ 'id_product' => $row['id_product'] ] );
// }

// // table materac_product_shop
// $results = $mdb -> select( 'materac_product_shop', '*', [ 'price' => '0.0' ] );
// foreach ( $results as $row )
// {
//   $price = $mdb2 -> get( 'materac_product_shop', 'price', [ 'id_product' => $row['id_product'], 'id_shop' => $row['id_shop'] ] );
//   $mdb -> update( 'materac_product_shop', [ 'price' => $price ], [ 'id_product' => $row['id_product'], 'id_shop' => $row['id_shop'] ] );
// }

// lulandia.pl
// Połączenie z bazą danych
$mdb = new medoo([
    'database_type' => 'mysql',
    'database_name' => 'admin_lulandia',
    'server' => 'dedyk8.cyber-folks.pl',
    'username' => 'admin_lulandia',
    'password' => '6_atdQ-N#xlN-t#0',
    'charset' => 'utf8'
] );

$mdb2 = new medoo([
    'database_type' => 'mysql',
    'database_name' => 'admin_lulbck',
    'server' => 'dedyk8.cyber-folks.pl',
    'username' => 'admin_lulbck',
    'password' => 'DjUH7lY(I5V-nW1-',
    'charset' => 'utf8'
] );
// copy price from materac_product from mdb2 to drmaterac.pl
$results = $mdb2 -> select( 'materac_product', [ 'id_product', 'price' ], [ 'id_product[!]' => 0 ] );
foreach ( $results as $row )
{
  $mdb -> update( 'materac_product', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'] ], [ 'id_product[!]' => 0 ] );
}

// copy price from materac_product_shop from mdb2 to drmaterac.pl
$results = $mdb2 -> select( 'materac_product_shop', [ 'id_product', 'price' ], [ 'AND' => [ 'id_shop' => 2, 'id_product[!]' => 0 ] ] );
foreach ( $results as $row )
{
  $mdb -> update( 'materac_product_shop', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'] ] );
}

// copy price from materac_product_attribute from mdb2 to drmaterac.pl
$results = $mdb2 -> select( 'materac_product_attribute', [ 'id_product', 'price', 'id_product_attribute' ], [ 'id_product[!]' => 0 ] );
foreach ( $results as $row )
{
  $mdb -> update( 'materac_product_attribute', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'], 'id_product_attribute' => $row['id_product_attribute'] ] );
}

// copy price from materac_product_attribute_shop from mdb2 to drmaterac.pl
$results = $mdb2 -> select( 'materac_product_attribute_shop', [ 'id_product', 'price', 'id_product_attribute' ], [ 'AND' => [ 'id_shop' => 2, 'id_product[!]' => 0 ] ] );
foreach ( $results as $row )
{
  $mdb -> update( 'materac_product_attribute_shop', [ 'price' => $row['price'] ], [ 'id_product' => $row['id_product'], 'id_product_attribute' => $row['id_product_attribute'] ] );
}

ECHO 'Import zakończony sukcesem! lulandia.pl<br>';