Current File : /home/users/barii/public_html/finansenl.com.pl/wodki/admin/api.php
<?php
include('config.php');


//print_r($_POST);
//print_r($_GET);

if(isset($_GET['TheGenerujPaczke'])) {
      include('classes/the_api.php');
              $checkout_id = $_POST['checkout_id'];
              $e_id_static = $_POST['trans'];
              $imie = $_POST['imie'];
              $adres = $_POST['adres'];
              $miasto = $_POST['miasto'];
              $kod = $_POST['kod'];
              $paczkomat = $_POST['paczkomat'];
              $email = $_POST['email'];   
              $tel = $_POST['tel'];     
              $konto = $_POST['konto'];
              $przesylkanazwa = $_POST['metoda'];


require_once '../api/demo/Resource.php'; //classes
require_once '../api/demo/Api.php';    //classes
require_once '../api/demo/api_login'.$konto.'.php'; //login and allegro conection tokens

$accessToken = file_get_contents('../api/demo/accessToken'.$konto); 
$refreshToken= file_get_contents('../api/demo/refreshToken'.$konto);
$access_token = $accessToken;
           if ($konto == 0) {
            $konto_test = '';
           }  else {
            $konto_test = $konto;
           }
$api = new Api($clientId, $clientSecret, $apiKey, $redirectUri.'/api/demo/ApiTest'.$konto_test.'.php', $accessToken, $refreshToken);       


$response=$api->order('checkout-forms/'.$checkout_id)->get(); 


                        $response=json_decode($response,true);
                        
            
      
          



    $trans = array($_POST['id']);
    
                                
                                if($response['delivery']['address']['phoneNumber']) $tel = $response['delivery']['address']['phoneNumber'];
                                else $tel = $response['buyer']['phoneNumber'];
                                
                                $field7 = $tel;
                                $przesylkanazwa = $response['delivery']['method']['name'];
                                
                                      $field1 = $imie;
                                      $field2 = $adres;
                                      $field4 = $kod;
                                      $field3 = $miasto;
                                      $field6 = $response['buyer']['email'];     
                                      $field5 = '';

                                      if(strpos($przesylkanazwa, 'Paczkomat') !== false) {
                                          $field5 = $paczkomat;
                                          $url = 'https://www.etykietyweselne.pl/admin/api.php?AllegroPaczkomaty&nowysystem&niewysylajemail';
                                              $field8 = $dane['id'];

    $fields = array(
       'imie' => $field1,
       'adres' => $field2,   
       'miasto' => $field3,    
       'kod' => $field4,     
       'paczkomat' => $field5,      
       'email' => $field6,            
       'tel' => $field7,
       'trans' =>   $field8,
    );   

    $postvars = http_build_query($fields);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
    curl_setopt($ch, CURLOPT_HEADER, 0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch);
    curl_close($ch); 
    
    
            $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='$result',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
            mysql_query($sql);
            $zmienn=array('<p><a href="https://twoj.inpost.pl/pl/znajdz-przesylke?parcel='.str_replace('K','',$result).'" target="_blank">'.str_replace('K','',$result).'</a></p>',$dane['order']['buyer']['login']);
                                      }   
                                      elseif(strpos($przesylkanazwa, 'Allegro Kurier DPD') !== false) {
 $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', 30, 20, 10, 1, 0, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);
                                      }
                                      elseif(strpos($przesylkanazwa, 'Allegro One Box') !== false) {
                                        $field5 = $paczkomat;

                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', 30, 20, 10, 1, 0, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel, $paczkomat);
                                          
                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);   

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);
                                      }
                                      elseif(strpos($przesylkanazwa, 'Allegro One Punkt') !== false) {
                                        $field5 = $paczkomat;

                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', 30, 20, 10, 1, 0, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel, $paczkomat);
                                          
                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);   

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);
                                      }
                                      elseif(strpos($przesylkanazwa, 'Allegro One Kurier') !== false) {
                                        
                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', 30, 20, 10, 1, 0, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://allegro.pl/kampania/one/kurier/sledzenie-paczki?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);
                                      }
                                      elseif(strpos($przesylkanazwa, 'Allegro Kurier UPS') !== false) {
                                        
                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', '30', '20', '10', '1', '0', $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://www.ups.com/track?tracknum='.$shipment_number.'&loc=pl_PL&requester=ST/trackdetails" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);
                                      }
                                      elseif(strpos($przesylkanazwa, 'Allegro Odbiór w Punkcie UPS') !== false) {
                                        $field5 = $paczkomat;
                                        
                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', 30, 20, 10, 1, 0, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel, $paczkomat);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://www.ups.com/track?tracknum='.$shipment_number.'&loc=pl_PL&requester=ST/trackdetails" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);

                                      }
                                       elseif(strpos($przesylkanazwa, 'Allegro Przesyłka polecona') !== false) {
                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'DOX', 20, 10, 2, 1, 275199, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://emonitoring.poczta-polska.pl/?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);
                                      
                                      } elseif(strpos($przesylkanazwa, 'Allegro MiniPrzesyłka') !== false) {
                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'DOX', 14, 25, 2, 0.5, 275199, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://emonitoring.poczta-polska.pl/?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);

                                      }

                                      elseif(strpos($przesylkanazwa, 'Allegro Kurier Pocztex') !== false) {
                                        $new_shipment = createShipment($access_token, $response['delivery']['method']['id'], 'PACKAGE', 30, 20, 10, 1, 0, $response['buyer']['email'], $imie, $response['delivery']['companyName'], $adres, $kod, $miasto, $tel);

                                        $shipment_info = displayShipmentStatus($access_token, $new_shipment['commandId']);
                                        $shipment_number = getAllegroOrderShipmentsNumber($access_token, $response['id']);
                                        pobierzEtykiete($access_token, $shipment_info['shipmentId'], $shipment_number);
                                        updateOrderStatus($response['id'], $access_token, 'SENT');

                                        $url = 'https://www.etykietyweselne.pl/admin/api.php?TheSystem&nowysystem&niewysylajemail&numer_przesylki='.$shipment_number;

                                        $field8 = $dane['id'];

                                        $fields = array('imie' => $field1, 'adres' => $field2, 'miasto' => $field3, 'kod' => $field4, 'paczkomat' => $field5, 'email' => $field6, 'tel' => $field7, 'trans' =>   $field8,);    

                                        $postvars = http_build_query($fields);
                                        $ch = curl_init();
                                        curl_setopt($ch, CURLOPT_URL, $url);
                                        curl_setopt($ch, CURLOPT_POST, count($fields));
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
                                        curl_setopt($ch, CURLOPT_HEADER, 0);  
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
                                        $result = curl_exec($ch);
                                        curl_close($ch); 

                                        $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='".$shipment_number."',eventtype='6' WHERE email = '".$dane['order']['buyer']['email']."' ORDER BY id DESC LIMIT 1";
                                        mysql_query($sql);
                                        $zmienn=array('<p><a href="https://emonitoring.poczta-polska.pl/?numer='.$shipment_number.'" target="_blank">Sprawdź śledzenie przesyłki ('.$shipment_number.')</a></p>', $response['buyer']['login']);

                                      } else{
                                          $url = 'https://www.etykietyweselne.pl/admin/api.php?kurierinpost&nowysystem&niewysylajemail';

                                              $field8 = $e_id_static;;

        $fields = array(
       'imie' => $imie,
       'adres' => $adres,   
       'miasto' => $miasto,    
       'kod' => $kod,     
       'paczkomat' => $paczkomat,      
       'email' => $email,            
       'tel' => $tel,
       'trans' =>   $e_id_static,
    );   

    $postvars = http_build_query($fields);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);     
    curl_setopt($ch, CURLOPT_HEADER, 0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch);
    curl_close($ch); 
    
    
            $sql = "UPDATE all_sprzedaze SET dostawa='".$response['delivery']['method']['name']."',numerwysylki='$result',eventtype='6' WHERE email = '".$response['buyer']['email']."' ORDER BY id DESC LIMIT 1";
            mysql_query($sql);

                                      }


//Alegro One Punkt: echo getSpecificDeliveryMethodId($access_token, 98);
//Allegro One Kurier: echo getSpecificDeliveryMethodId($access_token, 95);
//Polecona: echo getSpecificDeliveryMethodId($access_token, 30);
//UPS Kurier: echo getSpecificDeliveryMethodId($access_token, 26);
//UPS Paczkomaty: echo getSpecificDeliveryMethodId($access_token, 28);
//Pocztex Kurier: echo getSpecificDeliveryMethodId($access_token, 31);
//Allegro One Box 99 
file_put_contents('the.log', var_export($shipment_info,true));

}

     if(isset($_GET['Paczkomaty'])){
      include('inpost/inpost.php');
          if($_POST['paczkomat']!=''){
              $obj = new Admin();
              
              //$dane = $obj->setDate('kupione',$_POST['trans']);
              $shipping['imie'] = $_POST['imie'];
              $shipping['adres'] = $_POST['adres'];
              $shipping['miasto'] = $_POST['miasto'];
              $shipping['kod'] = $_POST['kod'];
              $shipping['paczkomat'] = $_POST['paczkomat'];
              $shipping['email'] = $_POST['email'];
              $shipping['tel'] = $_POST['tel'];             
              $ddd = $obj->setDate4($_POST['trans']);
              
              
              
              $no = create_packs($shipping, $payment, $order_total, $order_id);
              if($no != 'error'){
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,1);                    
                    echo $no; 
                    $wysylka = 1;  
                                    
              }
          }
      }

      elseif(isset($_GET['TheSystem'])){

          
              $obj = new Admin();
              $numer_przesylki = $_GET['numer_przesylki'];
              //$dane = $obj->setDate('kupione',$_POST['trans']);
              $shipping['imie'] = $_POST['imie'];
              $shipping['adres'] = $_POST['adres'];
              $shipping['miasto'] = $_POST['miasto'];
              $shipping['kod'] = $_POST['kod'];

              if (isset($_POST['paczkomat'])) {
                $shipping['paczkomat'] = $_POST['paczkomat'];
              } else {
                $shipping['paczkomat'] = '';
              }
              
              $shipping['email'] = $_POST['email'];
              $shipping['tel'] = $_POST['tel'];             
              $ddd = $obj->setDate4($_POST['trans']);
              
              $obj->zmienStatusAllegro($_POST['email'],$numer_przesylki);             
              echo $numer_przesylki; 
              $wysylka = 1;  
                                    
             
         
      }

      elseif(isset($_GET['AllegroOneBox'])){


      
      }
      elseif(isset($_GET['AllegroPaczkomaty'])){
      include('inpost/inpost.php');
          if($_POST['paczkomat']!=''){ 
              $obj = new Admin();
              
              //$dane = $obj->setDate('kupione',$_POST['trans']);
              $shipping['imie'] = $_POST['imie'];
              $shipping['adres'] = $_POST['adres'];
              $shipping['miasto'] = $_POST['miasto'];
              $shipping['kod'] = $_POST['kod'];
              $shipping['paczkomat'] = $_POST['paczkomat'];
              $shipping['email'] = $_POST['email'];
              $shipping['tel'] = $_POST['tel'];             
              $ddd = $obj->setDate4($_POST['trans']);
              
              if($ddd['kontoallegro']=='0')$shipping['userid'] = '3144989'; 
              elseif($ddd['kontoallegro']=='1') $shipping['userid'] = '44947030';                          
              if($ddd['transactionid'])$shipping['trans'] = $ddd['transactionid'];
              
              
              
              $no = create_packs($shipping, $payment, $order_total, $order_id);
              if($no != 'error'){
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,1);                    
                    echo $no; 
                    $wysylka = 1;  
                                    
              }
          }
      }  
     elseif(isset($_GET['kurierinpost'])){
     
              $obj = new Admin();
              
     
$client = new SoapClient('https://api-kurier.inpost.pl/api/api.asmx?WSDL', array('trace' => 1));

if($_POST['pobranie']) {
                
$wysylka = array(
	'ServiceId' => '38',
	'ShipTo'    => array(
		'Name'        => trim($_POST['imie']),
		'Address'    => trim($_POST['adres']),
		'City'        => trim($_POST['miasto']),
		'PostCode'    => trim($_POST['kod']),
		'Person'    => trim($_POST['imie']),
		'Contact'    => trim($_POST['tel']),
		'Email'        => trim($_POST['email']),
		'CountryCode' =>'PL',
		'IsPrivatePerson'=> true              
	),
	'Parcels'    => array(
		array(
			'Type'        => 'Package',
			'Weight'    => 1
		)
	), 
	'ShipFrom'    => array(
		'Name'        => 'Prolabel',
		'Address'    => 'ul. Mydlana 1',
		'City'        => 'Wrocław',
		'PostCode'    => '51-502',
		'Person'    => 'Prolabel',
		'Contact'    => '512 512 661',
		'Email'        => 'kontakt@fotomagnesy.pl',
		'IsPrivatePerson'=> false,
		'CountryCode' =>'PL'                  
	),    
	'InsuranceAmount' => str_replace(',','.',$_POST['pobranie']),  
	'COD'    => array(
			'Amount'        => str_replace(',','.',$_POST['pobranie'])
	),
	'LabelFormat'=> 'PDF',
	'ContentDescription'=>'AAABC'
);
}
else{     
$wysylka = array(
	'ServiceId' => '38',
	'ShipTo'    => array(
		'Name'        => trim($_POST['imie']),
		'Address'    => trim($_POST['adres']),
		'City'        => trim($_POST['miasto']),
		'PostCode'    => trim($_POST['kod']),
		'Person'    => trim($_POST['imie']),
		'Contact'    => trim($_POST['tel']),
		'Email'        => trim($_POST['email']),
		'CountryCode' =>'PL',
		'IsPrivatePerson'=> true              
	),
	'Parcels'    => array(
		array(
			'Type'        => 'Package',
			'Weight'    => 1
		)
	),
	'ShipFrom'    => array(
		'Name'        => 'Prolabel',
		'Address'    => 'ul. Mydlana 1',
		'City'        => 'Wrocław',
		'PostCode'    => '51-502',
		'Person'    => 'Prolabel',
		'Contact'    => '512 512 661',
		'Email'        => 'kontakt@fotomagnesy.pl',
		'IsPrivatePerson'=> false,
		'CountryCode' =>'PL'                  
	),
	'InsuranceAmount' => 0,
	'LabelFormat'=> 'PDF',
	'ContentDescription'=>'AAABC'
);   
}

$params = array(
	"token" => array(
		"UserName" => 'allegro@prolabel.pl',
		"Password" => 'Kali#fornia3'
	),
	"ShipmentRequest" => $wysylka    
);

$response= $client->CreateShipment($params);
$shippingLabelContent = $response->CreateShipmentResult->ParcelData->Label->MimeData;
$response->CreateShipmentResult->ParcelData->Label->MimeData = "[" . strlen($shippingLabelContent) . "]";	
file_put_contents('/home/users/barii/public_html/finansenl.com.pl/wodki/admin/downloads/etykiety/K'.$response->CreateShipmentResult->PackageNo.'.pdf', $shippingLabelContent);
$no = 'K'.$response->CreateShipmentResult->PackageNo;
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,5);   
                    echo $no;
$wysylka = 5;



     }
     elseif(isset($_GET['ecommerce'])){
      include('inpost/inpost.php');
              $obj = new Admin();
              //$dane = $obj->setDate('kupione',$_POST['trans']);
              $shipping['imie'] = 'bartek';
              $shipping['adres'] = 'Bacciarellego';
              $shipping['nrdomu'] = '48/2';
              $shipping['miasto'] = 'Wrocław';
              $shipping['kod'] = '51-649';
              $shipping['email'] = 'barii@wp.pl';
              $shipping['tel'] = '664427296';         
              $no = create_letters($shipping, $payment, $order_total, $order_id);
      }elseif(isset($_GET['ListEkonomiczny'])){
      
include "poczta/en.php";
class client
{

protected $guid= null;

public function makeTests()
{
$no = $this->DodaniaListu();
$this->testPobraniaNalepki();
return $no;
}


protected function DodaniaListu()
{
$E = new ElektronicznyNadawca();
$P = new przesylkaPoleconaKrajowaType();
$A = new adresType();
$tmp = new addShipment();
$A->nazwa = $_POST['imie'];
$A->ulica = $_POST['adres'];
$A->miejscowosc = $_POST['miasto'];
$A->kodPocztowy = $_POST['kod'];
$P->adres = $A;
$P->kategoria = kategoriaType::EKONOMICZNA;
//$P->gabaryt = gabarytType::GABARYT_A;
$P->format = formatType::S;
$P->masa = 300;// masa w gramach
$this->guid = getGuid();
$P->guid = $this->guid;
$tmp->przesylki[] = $P;
$dane = $E->addShipment($tmp); // wysłanie zapytania
return $dane->retval->numerNadania;
echo $E->__getLastRequest();
}


protected function testPobraniaNalepki()
{
$E = new ElektronicznyNadawca();
$parameters= new getAddresLabelByGuid();
$parameters->guid = array($this->guid);
$retval = $E->getAddresLabelByGuid($parameters);
if(!is_array($retval->content))
{
$retval->content = array($retval->content);
}
foreach ($retval->content as $c) /* @var $c addressLabelContent */
{
$h = fopen($c->nrNadania.".pdf", "w");
fwrite($h, $c->pdfContent);
fclose($h);
}

}
// -------------------------------------------------------------------------
protected function hr()
{
echo "<hr>\n";
flush();
}
// -------------------------------------------------------------------------
}
// -----------------------------------------------------------------------------
function getGuid()
{
mt_srand((double)microtime()*10000);
$charid = strtoupper(md5(uniqid(rand(), true)));
$retval = substr($charid, 0, 32);
return $retval;
}
// -----------------------------------------------------------------------------
ini_set ("max_execution_time","1800");

$c = new client();
$no = $c->makeTests();  


              $obj = new Admin();
              if($no != 'error'){
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,3);                    
                    echo $no;  
                    $wysylka = 3;                  
              }
      }
      elseif(isset($_GET['AllegroPolecony'])){
include "poczta/enallegro.php";

class client
{

protected $guid= null;

public function makeTests()
{
$no = $this->DodaniaListu();
$this->testPobraniaNalepki();
return $no;
}


protected function DodaniaListu()
{
$E = new ElektronicznyNadawca();
$P = new przesylkaFirmowaPoleconaType();
$A = new adresType();
$tmp = new addShipment(); 
$A->nazwa = $_POST['imie'];
$A->ulica = $_POST['adres'];
$A->miejscowosc = $_POST['miasto'];
$A->kodPocztowy = $_POST['kod'];
$A->mobile = trim($_POST['tel']);
$A->email = trim($_POST['email']);
//$P->relatedToAllegro = $allegro;
$P->adres = $A;
//$P->kategoria = kategoriaType::PRIORYTETOWA;
$P->gabaryt = gabarytType::XXL;       
//$P->format = formatType::S;
$P->masa = 1000;// masa w gramach
$this->guid = getGuid();
$P->guid = $this->guid;
$tmp->przesylki[] = $P;
//print_r($P);
$dane = $E->addShipment($tmp); // wysłanie zapytania
//print_r($dane);
return $dane->retval->numerNadania;
echo $E->__getLastRequest();
}


protected function testPobraniaNalepki()
{
$E = new ElektronicznyNadawca();
$parameters= new getAddresLabelByGuid();
$parameters->guid = array($this->guid);
$retval = $E->getAddresLabelByGuid($parameters);
if(!is_array($retval->content))
{
$retval->content = array($retval->content);
}
foreach ($retval->content as $c) /* @var $c addressLabelContent */
{
$h = fopen($c->nrNadania.".pdf", "w");
fwrite($h, $c->pdfContent);
fclose($h);
}

}
// -------------------------------------------------------------------------
protected function hr()
{
echo "<hr>\n";
flush();
}
// -------------------------------------------------------------------------
}
// -----------------------------------------------------------------------------
function getGuid()
{
mt_srand((double)microtime()*10000);
$charid = strtoupper(md5(uniqid(rand(), true)));
$retval = substr($charid, 0, 32);
return $retval;
}
// -----------------------------------------------------------------------------
ini_set ("max_execution_time","1800");

$c = new client();
$no = $c->makeTests();


              $obj = new Admin();
              if($no != 'error'){
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,3);                    
                    echo $no;  
                    $wysylka = 3;                  
              }
      }
      elseif(isset($_GET['ListPriorytetowy'])){
      
include "poczta/en.php";
class client
{

protected $guid= null;

public function makeTests()
{
$no = $this->DodaniaListu();
$this->testPobraniaNalepki();
return $no;
}


protected function DodaniaListu()
{
$E = new ElektronicznyNadawca();
$P = new przesylkaPoleconaKrajowaType();
$A = new adresType();
$tmp = new addShipment();
$A->nazwa = $_POST['imie'];
$A->ulica = $_POST['adres'];
$A->miejscowosc = $_POST['miasto'];
$A->kodPocztowy = $_POST['kod'];
$P->adres = $A;
$P->kategoria = kategoriaType::PRIORYTETOWA;
//$P->gabaryt = gabarytType::GABARYT_A;       
$P->format = formatType::S;
$P->masa = 300;// masa w gramach
$this->guid = getGuid();
$P->guid = $this->guid;
$tmp->przesylki[] = $P;
$dane = $E->addShipment($tmp); // wysłanie zapytania
return $dane->retval->numerNadania;
echo $E->__getLastRequest();
}


protected function testPobraniaNalepki()
{
$E = new ElektronicznyNadawca();
$parameters= new getAddresLabelByGuid();
$parameters->guid = array($this->guid);
$retval = $E->getAddresLabelByGuid($parameters);
if(!is_array($retval->content))
{
$retval->content = array($retval->content);
}
foreach ($retval->content as $c) /* @var $c addressLabelContent */
{
$h = fopen($c->nrNadania.".pdf", "w");
fwrite($h, $c->pdfContent);
fclose($h);
}

}
// -------------------------------------------------------------------------
protected function hr()
{
echo "<hr>\n";
flush();
}
// -------------------------------------------------------------------------
}
// -----------------------------------------------------------------------------
function getGuid()
{
mt_srand((double)microtime()*10000);
$charid = strtoupper(md5(uniqid(rand(), true)));
$retval = substr($charid, 0, 32);
return $retval;
}
// -----------------------------------------------------------------------------
ini_set ("max_execution_time","1800");

$c = new client();
$no = $c->makeTests();
              $obj = new Admin();
              if($no != 'error'){
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,4);                    
                    echo $no;  
                    $wysylka = 4;                  
              }
      }elseif(isset($_GET['ecommerce2'])){
      include('inpost/inpost.php');
              $obj = new Admin();
              
              //$dane = $obj->setDate('kupione',$_POST['trans']);
              $shipping['imie'] = 'bartek';
              $shipping['adres'] = 'Bacciarellego';
              $shipping['nrdomu'] = '48/2';
              $shipping['miasto'] = 'Wrocław';
              $shipping['kod'] = '51-649';
              $shipping['email'] = 'barii@wp.pl';
              $shipping['tel'] = '664427296';
              $no = create_letters($shipping, $payment, $order_total, $order_id);
              if($no != 'error'){
                    if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
                    else $obj->NadanieID($_POST['trans'],$no,1);                    
                    echo $no;   
                                    
              }
          
      }
     elseif(isset($_GET['GLS'])){
      //include('inpost/inpost.php');
              $obj = new Admin();
              $hClient = new SoapClient( 'https://adeplus.gls-poland.com/adeplus/pm1/ade_webapi2.php?wsdl' ); 
   
$oCredit = new stdClass();
$oCredit->user_name = '54002596.api';
$oCredit->user_password = '14qbW@Qb';     
     
$oClient = $hClient->adeLogin( $oCredit ); 
$szSession = $oClient->return->session;


$oSess = new stdClass();
$oSess->session = $szSession;
$oClient = $hClient->adeProfile_GetIDs( $oSess );     

    // ustaw profil
	$tablicaProfila= new stdClass();
	$tablicaProfila->session=$szSession;
	$tablicaProfila->id='45832';
    $aktualnyProfil=$hClient->adeProfile_Change($tablicaProfila);


$oCons = new stdClass();    
$oCons->session = $szSession;
$oCons->consign_prep_data = new stdClass();
$oCons->consign_prep_data->rname1 = $_POST['imie'];
    
$oCons->consign_prep_data->rcountry = 'PL';
$oCons->consign_prep_data->rzipcode = $_POST['kod'];
$oCons->consign_prep_data->rcity = $_POST['miasto'];
$oCons->consign_prep_data->rstreet = $_POST['adres'];
    
$oCons->consign_prep_data->rphone = $_POST['tel'];
$oCons->consign_prep_data->rcontact = $_POST['email'];
    
$oCons->consign_prep_data->notes = 'Dodane z Administratora prolabel.pl';    
$oCons->consign_prep_data->weight = 1; 
$oCons->consign_prep_data->quantity = 1; // overwrited by ParcelsArray



$oCons->consign_prep_data->parcels = new stdClass();
    
$oParcel = new stdClass();
$oParcel->weight = '1';    
$oCons->consign_prep_data->parcels->items[] = $oParcel;

  

    
$oClient = $hClient->adePreparingBox_Insert( $oCons );  
                    $no =  $oClient->return->id;                
if(isset($_GET['nowysystem']))$obj->zmienStatusAllegro($_POST['email'],$no);   
else $obj->NadanieID($_POST['trans'],$oClient->return->id,2);   
                    echo $no;
                    $wysylka = 2;
                                    
              
      }

             if(isset($_GET['nowysystem']) and isset($_GET['TheSystem'])){  
          $obj = new Admin();
          $dane = $_POST;
          $obj->DodajWysylkeThe($dane, $_GET['numer_przesylki']); 
       } elseif(isset($_GET['nowysystem']) and $no!='error'){  
          $obj = new Admin();
          $dane = $_POST;
          $dane['numer'] = $no;
          $obj->DodajWysylke($dane); 
       } else {

       }
       
                //$user = $this->setDate('kupione',$e);
                require '../class.phpmailer.php';

                $mail = new PHPMailer;
                                                                      
                $mail->addAddress($_POST['email'],$_POST['email']);
                $mail->setFrom('kontakt@fotomagnesy.pl','FotoMagnesy | Obsługa');
                $mail->isHTML(true);                                  // Set email format to HTML   
                $mail->SetLanguage("pl", "classes/language/");
                $mail->CharSet = "utf-8";
                
                //:<br>'.$user['adres'].'
                
                $mail->Subject = 'Twoje zamówienie zostało wysłane';
                $mail->Body    = '<p>Tutaj Fotomagnesy.pl,</p><p>Zamówione produkty zostały zapakowane i wysyłane pod wskazany przez Ciebie adres.
                <p><strong>Link do śledzenia przesyłki:</strong> <a href="';
                          if($wysylka==1){$mail->Body    .= 'https://twoj.inpost.pl/pl/znajdz-przesylke?parcel='.$no;}
                          elseif($wysylka==2){$mail->Body    .= 'https://gls-group.eu/PL/pl/sledzenie-paczek?match='.$no;}
                          elseif($wysylka==3){$mail->Body    .= 'http://emonitoring.poczta-polska.pl/?numer='.$no;}
                          elseif($wysylka==4){$mail->Body    .= 'http://emonitoring.poczta-polska.pl/?numer='.$no;}
                          elseif($wysylka==5){$mail->Body    .= 'https://twoj.inpost.pl/pl/znajdz-przesylke?parcel='.str_replace('K','',$no);}
                          
                $mail->Body    .= '" target="_blank">'.str_replace('K','',$no).'</a></p><br>Dziękujemy za skorzystanie z naszych usług i zachęcamy do dalszych zakupów, jednocześnie w ramach dalszej współpracy przekazujemy informację odnośnie naszych pozostałych produktów</p>
                
                <p><a href="http://www.fotomagnesy.pl/">KLIKNIJ I PERSONALIZUJ NOWE PRODUKTY<br>STWÓRZ NOWE ZAMÓWIENIE</a></p>
                <p><strong>W razie pytań pozostajemy pod telefonem :</strong></p>
<p>Mydlana 1, 51-502 Wrocław <br>tel. +48 512 512 661   pon-pt od 10.00 - 16.00<br>Email: allegro@prolabel.pl</p>
<p><strong>Dane konta bankowego :</strong><br>Nazwa banku :  ING BANK POLSKI<br>Nr konta :         80 1050 1575 1000 0090 9452 6051<br>PROLABEL GRZEGORZ MĄCZYŃSKI<br>CANALETTA 5   51-650 WROCŁAW</p>
<p><strong>Linki do sklepu Allegro  :</strong><br><a href="http://allegro.pl/listing/user/listing.php?us_id=3144989">http://allegro.pl/listing/user/listing.php?us_id=3144989</a><br><a href="https://allegro.pl/uzytkownik/fotomagnesy_pl">https://allegro.pl/uzytkownik/fotomagnesy_pl</a></p>
<p>&nbsp;&nbsp;<a href="http://www.fotomagnesy.pl/" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=pl&amp;q=http://www.fotomagnesy.pl&amp;source=gmail&amp;ust=1487766014439000&amp;usg=AFQjCNGP3XU0BiWbeMKJJwaHl_pLMAQJ3w"><img class="CToWUd" src="http://www.magnesy.fotomagnesy.pl/fotomagnesy_new_logo.png" alt="" width="137" height="44" /></a>&nbsp;&nbsp;<a href="https://www.facebook.com/fotomagnesyPL"><img style="height: 35px;" src="http://www.etykietyweselne.pl/img/fbicon.png" alt="" width="35" height="50" /></a>&nbsp;&nbsp;&nbsp;<a href="https://www.youtube.com/watch?v=8Mi3_ckh8Sg&amp;t"><img style="height: 35px;" src="http://www.etykietyweselne.pl/img/youtubelogo.jpg" alt="" width="83" height="50" /></a>&nbsp;&nbsp;</p>';
                
                //if(!isset($_GET['niewysylajemail']))$mail->send();
       
       if(isset($_GET['TheGenerujPaczke']) && isset($shipment_number)) {  
        header('Content-type: application/json');
          echo json_encode(array('shipment_number' => $shipment_number, 'fileUrl' => 'https://www.etykietyweselne.pl/admin/the-sticker.php?id='.$shipment_number));

      
       } 

?>