<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/ //
//$Id: SaleTrackingModel.php, v 1.0 2012/06/12 20:52:11
//
class SaleTrackingModel extends Model {
    //Function to save Tracking Code Details
    public function saveTrackingCodeDetails($POST, $trackingID = 0) {
        if ($trackingID > 0) {
            // Update Tracking Code Details
            $sql = "
				UPDATE `" . DB_PREFIX . "sales_tracking`
				SET
					trackingTypeID='" . $POST['trackingTypeID'] . "',
					remarketingCodeStart='" . $this->escape($POST['remarketingCodeStart']) . "',
					remarketingCodeEnd='" . $this->escape($POST['remarketingCodeEnd']) . "',
					conversionCode='" . $this->escape($POST['conversionCode']) . "',
					trackingType='" . $this->escape($POST['trackingType']) . "'
				WHERE
					trackingID='" . $trackingID . "'  LIMIT 1";
            return $this->ObjDatabase->setQuery($sql);
        } else if ($this->escape($POST['remarketingCodeStart']) || $this->escape($POST['remarketingCodeEnd']) || $this->escape($POST['conversionCode'])) {
            // Insert Tracking Code Details
            $sql = "
					INSERT INTO " . DB_PREFIX . "sales_tracking
					(
						 `trackingTypeID`,
						`remarketingCodeStart`,
						`remarketingCodeEnd`,
						`conversionCode`,
						`trackingType`
					)
					VALUES
					(
						'" . $POST['trackingTypeID'] . "',
						'" . $this->escape($POST['remarketingCodeStart']) . "',
						'" . $this->escape($POST['remarketingCodeEnd']) . "',
						'" . $this->escape($POST['conversionCode']) . "',
						'" . $this->escape($POST['trackingType']) . "'
					)";
            return $this->ObjDatabase->setQuery($sql);
        }
    }
    //End of function  
    //function to list Tracking codes for a Page
    public function listTrackingCodesForPage($trackingTypeID, $trackingType) {
        $sql            = "
			SELECT
				*
			FROM 
				" . DB_PREFIX . "sales_tracking
			WHERE
				trackingTypeID='" . $trackingTypeID . "'
				AND trackingType='" . $trackingType . "'";
        $resSelectPages = $this->ObjDatabase->readValue($sql);
        return $resSelectPages;
    }
}
