403Webshell
Server IP : 85.158.181.41  /  Your IP : 216.73.217.12
Web Server : Apache
System : Linux cloud9-vm129 6.1.178+1-ph #ph SMP PREEMPT_DYNAMIC Wed Jul 29 09:00:54 UTC 2026 x86_64
User : moncbefd ( 1024)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/moncbefd/www.moneta.at/GXMainComponents/Controllers/Api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/moncbefd/www.moneta.at/GXMainComponents/Controllers/Api/AFSyncApiV2Controller.inc.php
<?php

/* --------------------------------------------------------------
  Amicron Faktura Controller for Gambio
  --------------------------------------------------------------
 */

MainFactory::load_class('HttpApiV2Controller');

class AFSyncApiV2Controller extends HttpApiV2Controller {

  private $db; // CI_DB_query_builder

  private $verge41; // Gambio ab 4.1

  protected function __initialize() {
    $this->db = StaticGXCoreLoader::getDatabaseQueryBuilder();
    $this->verge41 =
      version_compare(
        gm_get_conf('INSTALLED_VERSION'),
        'v4.1.0') >= 0;
  }

  private function getConfiguration($configurationKey) {
    if ($this->verge41) {
      $query = $this->db
        ->select('value')
        ->from('gx_configurations')
        ->where('key', 'configuration/' . $configurationKey);

      return $query->get()->row_array()['value'];
    } else {
      $query = $this->db
        ->select('configuration_value')
        ->from('configuration')
        ->where('configuration_key', $configurationKey);

      return $query->get()->row_array()['configuration_value'];
    }
  }

  private function getRequestParam($name) {
    if ($this->verge41) {
      return $this->request->getParam($name);
    } else {
      return $this->api->request->get($name);
    }
  }

  private function getRequestJsonBody() {
    if ($this->verge41) {
      return json_decode($this->request->getBody());
    } else {
      return json_decode($this->api->request->getBody());
    }
  }

  private function ReadVersion() {
    $version_major = 13;
    $version_minor = 5;

    $this->_writeResponse(
      array(
        'SCRIPT_VERSION_MAJOR' => $version_major,
        'SCRIPT_VERSION_MINOR' => $version_minor,
        'Shop-Version' => gm_get_conf('INSTALLED_VERSION')));
  }

  private function ReadLanguages() {
    $query = $this->db
      ->select(array(
        'languages_id as id',
        'name',
        'code'))
      ->from('languages')
      ->order_by(
        'sort_order,' .
        'languages_id',
        'ASC');

    $this->_writeResponse($query->get()->result_array());
  }

  private function ReadShopData() {
    $defaultLanguageId = MainFactory::create('LanguageProvider', $this->db)->getDefaultLanguageId();

    $response = array();

    $taxratesquery = $this->db
      ->select(array(
        'tax_rates.tax_class_id as id',
        'tax_rates.tax_rate as rate'))
      ->from('tax_rates')
      ->join(
        'geo_zones',
        'tax_rates.tax_zone_id=geo_zones.geo_zone_id',
        'inner')
      ->where('geo_zones.geo_zone_name', 'Steuerzone EU')
      ->order_by(
        'tax_rates.tax_class_id',
        'ASC');

    $response['taxrates'] = $taxratesquery->get()->result_array();


    $shippingstatusquery = $this->db
      ->select(array(
        'shipping_status_id as id',
        'language_id as languageId',
        'shipping_status_name as name'))
      ->from('shipping_status')
      ->where('language_id', $defaultLanguageId)
      ->order_by(
        'shipping_status_id',
        'ASC');

    $response['shippingstatus'] = $shippingstatusquery->get()->result_array();


    $customersstatusquery = $this->db
      ->select(array(
        'customers_status_id as id',
        'language_id as languageId',
        'customers_status_name as name'))
      ->from('customers_status')
      ->where('language_id', $defaultLanguageId)
      ->order_by(
        'customers_status_id',
        'ASC');

    $response['customersstatus'] = $customersstatusquery->get()->result_array();


    $productsvpequery = $this->db
      ->select(array(
        'products_vpe_id as id',
        'products_vpe_name as name'))
      ->from('products_vpe')
      ->where('language_id', $defaultLanguageId)
      ->order_by(
        'products_vpe_id',
        'ASC');

    $response['productsvpe'] = $productsvpequery->get()->result_array();


    $response['configuration'] = array();


    $url = preg_split('#/api.php/#i', (empty($_SERVER['HTTPS']) ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])[0];
    $response['settings'] = array(
      'imagepath' => $url . '/' . DIR_WS_ORIGINAL_IMAGES);


    $this->_writeResponse($response);
  }

  private function ReadCategories() {
    $response = array();

    $categoryquery = $this->db
      ->select(array(
        'categories_id',
        'parent_id'))
      ->from('categories')
      ->order_by(
        'parent_id,' .
        'sort_order,' .
        'categories_id',
        'ASC');

    foreach ($categoryquery->get()->result_array() as $categoryrow) {
      $languagequery = $this->db
        ->select(array(
          'language_id as languageId',
          'categories_name as name',
          'categories_heading_title as title',
          'categories_description as description'))
        ->from('categories_description')
        ->where('categories_id', $categoryrow['categories_id'])
        ->order_by(
          'language_id',
          'ASC');

      $response[] = array(
        'id' => $categoryrow['categories_id'],
        'parentId' => $categoryrow['parent_id'],
        'names' => $languagequery->get()->result_array());
    }

    $this->_writeResponse($response);
  }

  private function ReadManufacturers() {
    $manufacturersquery = $this->db
      ->select(array(
        'manufacturers_id as id',
        'manufacturers_name as name'))
      ->from('manufacturers')
      ->order_by(
        'manufacturers_id',
        'ASC');

    $this->_writeResponse($manufacturersquery->get()->result_array());
  }


  private function ReadProducts() {
    $response = array();

    $productsquery = $this->db
      ->select('products.*')
      ->from('products')
      ->order_by(
        'products_id',
        'ASC');

    if ($this->getRequestParam('AbDatum') !== null) {
      $productsquery
        ->where('products.products_last_modified>=', $this->getRequestParam('AbDatum'));
    }

    if ($this->getRequestParam('LimitOffset') !== null && $this->getRequestParam('LimitRowCount') !== null) {
      $productsquery->limit($this->getRequestParam('LimitRowCount'), $this->getRequestParam('LimitOffset'));
    }

    if (isset($this->uri[2])) {
      if ($this->getRequestParam('useModelAsId') !== null) {
        $productsquery
          ->where('products.products_model', $this->uri[2]);
      }
      else {
        $productsquery
          ->where('products.products_id', $this->uri[2]);
      }
    }

    foreach ($productsquery->get()->result_array() as $item) {
      $responseitem = array();
      $id = $item['products_id'];

      $responseitem['product'] = $item;


      $productsdescriptionquery = $this->db
        ->select('products_description.*')
        ->from('products_description')
        ->where('products_id', $id);

      $responseitem['descriptions'] = $productsdescriptionquery->get()->result_array();


      $productstocategoriesquery = $this->db
        ->select('categories_id')
        ->from('products_to_categories')
        ->where('products_id', $id);

      $responseitem['categories'] = array_column($productstocategoriesquery->get()->result_array(), 'categories_id');


      $preise = array();
      $customersstatusquery = $this->db
        ->select('customers_status_id')
        ->distinct()
        ->from('customers_status');
      foreach ($customersstatusquery->get()->result_array() as $row) {
        $personaloffersquery = $this->db
          ->select(array(
            '*',
            $row['customers_status_id'] . ' as customers_status_id'))
          ->from('personal_offers_by_customers_status_' . $row['customers_status_id'])
          ->where('products_id', $id);
        $preis = $personaloffersquery->get()->result_array();
        if (count($preis) > 0) {
          $preise = array_merge($preise, $preis);
        }
      }

      $responseitem['prices'] = $preise;


      $productsimagesquery = $this->db
        ->select('products_images.*')
        ->from('products_images')
        ->where('products_id', $id);
      $images = $productsimagesquery->get()->result_array();

      $responseitem['images'] = $images;


      $response[] = $responseitem;
    }

    $this->_writeResponse($response);
  }


  private function ReadSimpleProducts() {
    $response = array();

    $productsquery = $this->db
      ->select(array(
        'products.products_id',
        'products.products_model',
        'products.products_image'))
      ->from('products')
      ->order_by(
        'products_id',
        'ASC');

    foreach ($productsquery->get()->result_array() as $item) {
      $id = $item['products_id'];

      $responseitem = $item;

      if ($responseitem['products_image'] == '') {
        unset($responseitem['products_image']);
      }


      $productstocategoriesquery = $this->db
        ->select('categories_id')
        ->from('products_to_categories')
        ->where('products_id', $id);

      $responseitem['categories'] = array_column($productstocategoriesquery->get()->result_array(), 'categories_id');

      if (count($responseitem['categories']) == 0) {
        unset($responseitem['categories']);
      }


      $productsimagesquery = $this->db
        ->select('image_name')
        ->from('products_images')
        ->where('products_id', $id);

      $responseitem['images'] =  array_column($productsimagesquery->get()->result_array(), 'image_name');

      if (count($responseitem['images']) == 0) {
        unset($responseitem['images']);
      }


      $response[] = $responseitem;
    }

    $this->_writeResponse($response);
  }

  private function ReadOrders() {
    $orderReadService = StaticGXCoreLoader::getService('OrderRead');
    $orderJsonSerializer = MainFactory::create('OrderJsonSerializer');

    $countryService = StaticGXCoreLoader::getService('Country');

    $defaultLanguageId = MainFactory::create('LanguageProvider', $this->db)->getDefaultLanguageId();

    $existsPaypalTransactions = $this->db->table_exists('paypal_transactions');
    $existsOrdersPaypalPayments = $this->db->table_exists('orders_paypal_payments');

    $response = array();

    $ordersquery = $this->db
      ->select('orders_id')
      ->from('orders')
      ->order_by(
        'orders_id',
        'ASC');

    if ($this->getRequestParam('order_from') !== null) {
      $ordersquery
        ->where('orders.orders_id>=', $this->getRequestParam('order_from'));
    }

    if ($this->getRequestParam('order_to') !== null) {
      $ordersquery
        ->where('orders.orders_id<=', $this->getRequestParam('order_to'));
    }

    if (isset($this->uri[2]) && is_numeric($this->uri[2])) {
      $ordersquery
        ->where('orders.orders_id=', $this->uri[2]);
    }

    foreach ($ordersquery->get()->result_array() as $orderid) {
      $id = $orderid['orders_id'];

      $orderobj = $orderReadService->getOrderById(new IdType($id));
      $order = $orderJsonSerializer->serialize($orderobj, false);


      $order['addresses']['customer']['country'] = (string) ($countryService->getCountryById(
          new IdType($order['addresses']['customer']['countryId']))->getIso2());

      $order['addresses']['billing']['country'] = (string) ($countryService->getCountryById(
          new IdType($order['addresses']['billing']['countryId']))->getIso2());

      $order['addresses']['delivery']['country'] = (string) ($countryService->getCountryById(
          new IdType($order['addresses']['delivery']['countryId']))->getIso2());


      $shipping_method = strtoupper(explode('_', $order['shippingType']['module'])[0]);
      $taxClass = $this->getConfiguration('MODULE_SHIPPING_' . $shipping_method . '_TAX_CLASS');
      $order['shippingType']['tax'] = xtc_get_tax_rate($taxClass, $order['addresses']['customer']['countryId'], $order['addresses']['customer']['zoneId']);


      $otmodul = array(
        'ot_cod_fee' => array('conf' => 'MODULE_ORDER_TOTAL_COD_FEE_TAX_CLASS', 'prefix' => '0'),
        'ot_loworderfee' => array('conf' => 'MODULE_ORDER_TOTAL_LOWORDERFEE_TAX_CLASS', 'prefix' => '0'),
        'ot_ps_fee' => array('conf' => 'MODULE_ORDER_TOTAL_PS_FEE_TAX_CLASS', 'prefix' => '0'),
        'ot_coupon' => array('conf' => 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', 'prefix' => '0'),
        'ot_gv' => array('conf' => 'MODULE_ORDER_TOTAL_GV_TAX_CLASS', 'prefix' => '0'));

      foreach ($order['totals'] as $key => $value) {
        $classname = $value['class'];
        if (isset($otmodul[$classname])) {
          $taxid = $this->getConfiguration($otmodul[$classname]['conf']);
          $order['totals'][$key]['tax'] = xtc_get_tax_rate($taxid, $order['addresses']['customer']['countryId'], $order['addresses']['customer']['zoneId']);
          $order['totals'][$key]['prefix'] = $otmodul[$classname]['prefix'];
        }
      }


      $ptdata = [];
      switch ($order['paymentType']['module']) {
        case 'sepa':
          $ptdata  = $this->db
            ->select('*')
            ->from('sepa')
            ->where('orders_id', $id)
            ->get()
            ->row_array();
          break;
        case 'banktransfer':
          $ptdata = $this->db
            ->select('*')
            ->from('banktransfer')
            ->where('orders_id', $id)
            ->get()
            ->row_array();
          break;
        case 'paypal':
        case 'paypal3':
          if ($existsPaypalTransactions) {
            $ptdata = $this->db
              ->select('transaction_id transactionID')
              ->from('paypal_transactions')
              ->where('orders_id', $id)
              ->order_by(
                'ecresponse_id',
                'DESC')
              ->get()
              ->row_array();
          }
          else if ($existsOrdersPaypalPayments) {
            $ptdata = $this->db
              ->select('payment_id transactionID')
              ->from('orders_paypal_payments')
              ->where('orders_id', $id)
              ->order_by(
                'payment_id',
                'DESC')
              ->get()
              ->row_array();
          }
          break;
      }
      if (count($ptdata) > 0) {
        foreach ($ptdata as $key => $value) {
          $order['paymentType'][$key] = $value;
        }
      }


      $row = $this->db
        ->select('*')
        ->from('orders_parcel_tracking_codes')
        ->where('order_id', $id)
        ->where('language_id', $defaultLanguageId)
        ->order_by(
          'orders_parcel_tracking_code_id',
          'DESC')
        ->get()
        ->row_array();
      if (isset($row)) {
        $order['parcel_service'] = $row;
      }


      $response[] = $order;
    }

    $this->_writeResponse($response);
  }

  private function UpdateOrderStatus() {
    $json = $this->getRequestJsonBody();

    $orderId = $json->orderId;
    $statusId = $json->statusId;
    $trackingId = $json->trackingId;
    $trackingCarrier = $json->trackingCarrier;
    $statusEMail = $json->statusEMail;

    if ($trackingId != '' && $trackingCarrier != '') {
      $languageProvider = MainFactory::create('LanguageProvider', $this->db);

      foreach ($languageProvider->getIds()->getIntArray() as $languageId) {
        $parcelservicesquery = $this->db
          ->select(array(
            'parcel_services.parcel_service_id',
            'parcel_services.name',
            'parcel_services_description.url',
            'parcel_services_description.comment'))
          ->from('parcel_services')
          ->join(
            'parcel_services_description',
            'parcel_services.parcel_service_id=parcel_services_description.parcel_service_id',
            'INNER')
          ->where('parcel_services_description.language_id', $languageId)
          ->like('parcel_services.name', $trackingCarrier, 'after');

        foreach ($parcelservicesquery->get()->result_array() as $row) {
          $this->db
            ->insert(
              'orders_parcel_tracking_codes',
              array(
                'order_id' => $orderId,
                'tracking_code' => $trackingId,
                'parcel_service_id' => $row['parcel_service_id'],
                'parcel_service_name' => $row['name'],
                'language_id' => $languageId,
                'url' => preg_replace('/{TRACKING_NUMBER}/', $trackingId, $row['url']),
                'comment' => $row['comment']));
        }
      }
    }

    require_once(DIR_FS_INC . 'xtc_date_long.inc.php');

    $orderActions = MainFactory::create('OrderActions');
    $orderActions->changeOrderStatus(
      new IdType((int)$orderId),
      new IdType((int)$statusId),
      new StringType(''),
      new BoolType($statusEMail),
      new BoolType($trackingId != '' && $trackingCarrier != ''),
      new BoolType(false));


    $response = array(
      'code' => 200,
      'status' => 'success',
      'action' => 'insert',
      'resource' => 'TrackingId',
      'orderId' => (int) $orderId,
      'trackingId' => (int) $trackingId,
      'trackingCarrier' => (int) $trackingCarrier);

    $this->_writeResponse($response);
  }

  private function DeleteProduct() {
    $json = $this->getRequestJsonBody();

    $productId = $json->productId;


    $productWriteService = StaticGXCoreLoader::getService('ProductWrite');
    $productWriteService->deleteProductById(new IdType($productId));


    $customersstatusquery = $this->db
      ->select('customers_status_id')
      ->distinct()
      ->from('customers_status');
    foreach ($customersstatusquery->get()->result_array() as $row) {
      $this->db
        ->where('products_id', $productId)
        ->delete('personal_offers_by_customers_status_' . $row['customers_status_id']);
    }


    $response = array(
      'code' => 200,
      'status' => 'success',
      'action' => 'delete',
      'resource' => 'Product',
      'productId' => (int) $productId);

    $this->_writeResponse($response);
  }

  private function InsertManufacturer() {
    $json = $this->getRequestJsonBody();

    $name = $json->name;

    $this->db
      ->select('manufacturers_id')
      ->from('manufacturers')
      ->where('manufacturers_name', $name);

    $row = $this->db->get()->row();
    if (isset($row)) {
      $id = $row->manufacturers_id;
      $isnew = false;
    }
    else {
      $this->db
        ->insert(
          'manufacturers',
          array(
            'manufacturers_name' => $name));
      $id = $this->db->insert_id();
      $isnew = true;
    }

    $response = array(
      'code' => 200,
      'status' => 'success',
      'new' => $isnew,
      'resource' => 'Manufacturer',
      'name' => $name,
      'id' => $id);

    $this->_writeResponse($response);
  }

  private function InsertShippingStatus() {
    $json = $this->getRequestJsonBody();

    $name = $json->name;

    $languageProvider = MainFactory::create('LanguageProvider', $this->db);
    $defaultLanguageId = $languageProvider->getDefaultLanguageId();

    $query = $this->db
      ->select('shipping_status_id')
      ->from('shipping_status')
      ->where('shipping_status_name', $name)
      ->where('language_id', $defaultLanguageId);

    $row = $query->get()->row();
    if (isset($row)) {
      $id = $row->shipping_status_id;
      $isnew = false;
    }
    else {
      $id = $this->db
        ->select_max('shipping_status_id')
        ->from('shipping_status')
        ->get()
        ->row()->shipping_status_id + 1;

      foreach ($languageProvider->getIds()->getIntArray() as $languageId) {
        $this->db
          ->insert(
            'shipping_status',
            array(
              'shipping_status_id' => $id,
              'shipping_status_name' => $name,
              'language_id' => $languageId));
      }

      $isnew = true;
    }

    $response = array(
      'code' => 200,
      'status' => 'success',
      'new' => $isnew,
      'resource' => 'ShippingStatus',
      'name' => $name,
      'id' => $id);

    $this->_writeResponse($response);
  }

  private function InsertProductsVpe() {
    $json = $this->getRequestJsonBody();

    $name = $json->name;

    $languageProvider = MainFactory::create('LanguageProvider', $this->db);
    $defaultLanguageId = $languageProvider->getDefaultLanguageId();

    $query = $this->db
      ->select('products_vpe_id')
      ->from('products_vpe')
      ->where('products_vpe_name', $name)
      ->where('language_id', $defaultLanguageId);

    $row = $query->get()->row();
    if (isset($row)) {
      $id = $row->products_vpe_id;
      $isnew = false;
    }
    else {
      $id = $this->db
        ->select_max('products_vpe_id')
        ->from('products_vpe')
        ->get()
        ->row()->products_vpe_id + 1;

      foreach ($languageProvider->getIds()->getIntArray() as $languageId) {
        $this->db
          ->insert(
            'products_vpe',
            array(
              'products_vpe_id' => $id,
              'products_vpe_name' => $name,
              'language_id' => $languageId));
      }

      $isnew = true;
    }

    $response = array(
      'code' => 200,
      'status' => 'success',
      'new' => $isnew,
      'resource' => 'ProductsVpe',
      'name' => $name,
      'id' => $id);

    $this->_writeResponse($response);
  }

  private function InsertPersonalOffers() {
    $json = $this->getRequestJsonBody();

    $productId = $json->productId;

    $customersstatusquery = $this->db
      ->select('customers_status_id')
      ->distinct()
      ->from('customers_status');
    foreach ($customersstatusquery->get()->result_array() as $row) {
      $this->db
        ->where('products_id', $productId)
        ->delete('personal_offers_by_customers_status_' . $row['customers_status_id']);
    }

    if (isset($json->offers)) {
      foreach ($json->offers as $offer) {
        $this->db
          ->insert(
            'personal_offers_by_customers_status_' . $offer->offerId,
            array(
              'products_id' => $productId,
              'quantity' => $offer->quantity,
              'personal_offer' => $offer->price));
      }
    }

    $response = array(
      'code' => 200,
      'status' => 'success',
      'resource' => 'ProductsOffers',
      'ProductId' => $productId);

    $this->_writeResponse($response);
  }

  public function get() {
    $action = isset($this->uri[1]) ? $this->uri[1] : '';

    switch ($action) {
      case 'languages':
        $this->ReadLanguages();
        break;
      case 'shopdata':
        $this->ReadShopData();
        break;
      case 'categories':
        $this->ReadCategories();
        break;
      case 'manufacturers':
        $this->ReadManufacturers();
        break;
      case 'products':
        $this->ReadProducts();
        break;
      case 'simpleproducts':
        $this->ReadSimpleProducts();
        break;
      case 'orders':
        $this->ReadOrders();
        break;
      default:
        $this->ReadVersion();
        break;
    }
  }

  public function post() {
    $action = isset($this->uri[1]) ? $this->uri[1] : '';

    switch ($action) {
      case 'orderstatus':
        $this->UpdateOrderStatus();
        break;
      case 'manufacturers':
        $this->InsertManufacturer();
        break;
      case 'shippingstatus':
        $this->InsertShippingStatus();
        break;
      case 'productsvpe':
        $this->InsertProductsVpe();
        break;
      case 'personaloffers':
        $this->InsertPersonalOffers();
        break;
    }
  }

  public function delete() {
    $action = isset($this->uri[1]) ? $this->uri[1] : '';

    switch ($action) {
      case 'products':
        $this->DeleteProduct();
        break;
    }
  }

}

Youez - 2016 - github.com/yon3zu
LinuXploit