<?php 

class SPC_BuyButton {
	
	function getId() {
		return $this->id;
	}
	function setId($o) {
		$this->id = $o;
	}
	
	function getCId() {
		return $this->c_id;
	}
	function setCId($o) {
		$this->c_id = $o;
	}
	
	function getName() {
		return $this->name;
	}
	function setName($o) {
		$this->name = $o;
	}
	
	function getSalesPage() {
		return $this->sales_page;
	}
	function setSalesPage($o) {
		$this->sales_page = $o;
	}
	
	function getProductId() {
		return $this->p_id;
	}
	function setProductId($o) {
		$this->p_id = $o;
	}
	 
	function getProductName() {
		return $this->product_name;
	}
	function setProductName($o) {
		$this->product_name = $o;
	}
	
	function getButtonId() {
		return $this->button_id;
	}
	function setButtonId($o) {
		$this->button_id = $o;
	}
	
	function getCurrencySymbol() {
		return $this->currency_symbol;
	}
	function setCurrencySymbol($o) {
		$this->currency_symbol = $o;
	}
	
	function getCurrencyText() {
		return $this->currency_text;
	}
	function setCurrencyText($o) {
		$this->currency_text = $o;
	}
	
	function getBumpOffer() {
		return $this->bump_offer;
	}
	function setBumpOffer($o) {
		$this->bump_offer = $o;
	}
	
	function getBumpId() {
		return $this->bump_id;
	}
	function setBumpId($o) {
		$this->bump_id = $o;
	}
	
	function getBumpProductName() {
		return $this->bump_prod_name;
	}
	function setBumpProductName($o) {
		$this->bump_prod_name = $o;
	}
	
	function getBumpHtml() {
		return $this->bump_html;
	}
	function setBumpHtml($o) {
		$this->bump_html = $o;
	}

	function getBumpTemp() {
		return $this->bump_temp;
	}
	function setBumpTemp($o) {
		$this->bump_temp = $o;
	}	

	function getCheckoutId() {
		return $this->checkout_id;
	}
	function setCheckoutId($o) {
		$this->checkout_id = $o;
	}
		
	function getProductTemp() {
		return $this->product_temp;
	}
	function setProductTemp($o) {
		$this->product_temp = $o;
	}
	
	function getOrderSumTemp() {
		return $this->order_sum_temp;
	}
	function setOrderSumTemp($o) {
		$this->order_sum_temp = $o;
	}
	
	function getFId() {
		return $this->f_id;
	}
	function setFId($o) {
		$this->f_id = $o;
	}
	
	function getLandingPage() {
		return $this->landing_page;
	}
	function setLandingPage($o) {
		$this->landing_page = $o;
	}
	
	function getBtnCode() {
		return $this->btn_code;
	}
	function setBtnCode($o) {
		$this->btn_code = $o;
	}

	function getBtnStyles() {
		return $this->btn_styles;
	}
	function setBtnStyles($o) {
		$this->btn_styles = $o;
	}
	
	function getViewBtn() {
		return $this->view_btn;
	}
	function setViewBtn($o) {
		$this->view_btn = $o;
	}
	
	function getLiveMode() {
		return $this->live_mode;
	}
	function setLiveMode($o) {
		$this->live_mode = $o;
	}
	
	function getStatus() {
		return $this->status;
	}
	function setStatus($o) {
		$this->status = $o;
	}
	
	function getType() {
		return $this->type;
	}
	function setType($o) {
		$this->type = $o;
	}
	
	
	function getNoPopup() {
		return $this->nopopup;
	}
	
	function setNoPopup($o) {
		$this->nopopup = $o;
	}
	function getPaymentId() {
		return $this->payment_id;
	}
	function setPaymentId($o) {
		$this->payment_id = $o;
	}
	
	function getCouponStrikeout() {
		return $this->coupon_strikeout;
	}
	function setCouponStrikeout($o) {
		$this->coupon_strikeout = $o;
	}
	
	function getCouponId() {
		return $this->coupon_id;
	}
	function setCouponId($o) {
		$this->coupon_id = $o;
	}
	
	function getCouponOptions() {
		return $this->coupon_options;
	}
	function setCouponOptions($o) {
		$this->coupon_options = $o;
	}
		
	function getEditDapPrice() {
		return $this->edit_dap_price;
	}
	function setEditDapPrice($o) {
		$this->edit_dap_price = $o;
	}
		
	function getNewSpcPrice() {
		return $this->new_spc_price;
	}
	function setNewSpcPrice($o) {
		$this->new_spc_price = $o;
	}
		
	function getEditBumpDapPrice() {
		return $this->edit_bump_dap_price;
	}
	function setEditBumpDapPrice($o) {
		$this->edit_bump_dap_price = $o;
	}
	function getNewBumpSpcPrice() {
		return $this->new_bump_spc_price;
	}
	function setNewBumpSpcPrice($o) {
		$this->new_bump_spc_price = $o;
	}
		
	
	function getEditDapTrialDays() {
		return $this->edit_dap_trial_days;
	}
	function setEditDapTrialDays($o) {
		$this->edit_dap_trial_days = $o;
	}
	
	function getNewSpcTrialDays() {
		return $this->new_spc_trial_days;
	}
	function setNewSpcTrialDays($o) {
		$this->new_spc_trial_days = $o;
	}
	
	function getCouponPlace() {
		return $this->coupon_place;
	}
	function setCouponPlace($o) {
		$this->coupon_place = $o;
	}
	
	function getTagName() {
		return $this->tag_name;
	}
	function setTagName($o) {
		$this->tag_name = $o;
	}
	
	function getEuVatTemp() {
		return $this->eu_vat_temp;
	}
	function setEuVatTemp($o) {
		$this->eu_vat_temp = $o;
	}

	function getEnableTaxjar() {
		return $this->enable_taxjar;
	}
	function setEnableTaxjar($o) {
		$this->enable_taxjar = $o;
	}
	
	
	function getDate() {
		return $this->date;
	}
	function setDate($o) {
		$this->date = $o;
	}

	function getSpcShippingRate() {
		return $this->spc_shipping_rate;
	}
	function setSpcShippingRate($o) {
		$this->spc_shipping_rate = $o;
	}

	function getOrderBumpPosition() {
		return $this->order_bump_position;
	}
	function setOrderBumpPosition($o) {
		$this->order_bump_position = $o;
	}
	
	
	function getBumpMainHeading() {
		return $this->bump_main_heading;
	}
	function setBumpMainHeading($o) {
		$this->bump_main_heading = $o;
	}
		
	function getInvoiceEmail() {
		return $this->invoice_email;
	}
	function setInvoiceEmail($o) {
		$this->invoice_email = $o;
	}
		
	function getInvoiceId() {
		return $this->invoice_id;
	}
	function setInvoiceId($o) {
		$this->invoice_id = $o;
	}
	    
	function getContinueShoppingUrl() {
		return $this->continue_shopping_url;
	}
	function setContinueShoppingUrl($o) {
		$this->continue_shopping_url = $o;
	}
	
	function getInvoicEmail() {
		return $this->invoice_email;
	}
	function setInvoicEmail($o) {
		$this->invoice_email = $o;
	}
	
	function getPaymentPlanId() {
		return $this->payment_plan_id;
	}
	function setPaymentPlanId($o) {
		$this->payment_plan_id = $o;
	}
 	
	function getFreeTrial() {
		return $this->free_trial;
	}
	function setFreeTrial($o) {
		$this->free_trial = $o;
	}
	
	function getFreeTrialTerms() {
		return $this->free_trial_terms;
	}
	function setFreeTrialTerms($o) {
		$this->free_trial_terms = $o;
	}
	
	function getAllowPurchaseUsingCredits() {
		return $this->allow_purchase_using_credits;
	}
	function setAllowPurchaseUsingCredits($o) {
		$this->allow_purchase_using_credits = $o;
	}

	function getSPCShippingOption() {
		return $this->spc_shipping_options;
	}
	function setSPCShippingOption($o) {
		$this->spc_shipping_options = $o;
	}
	
	
	
 	
	public function create(){
		try {
		//	spcwpLogToFile("SPCWP_BuyButton.class.php:create(), Entered", "debug");
			global $wpdb, $smartpaycart_product_details;
			$tableName = $smartpaycart_product_details;
			$data = array(
				'c_id'=> $this->getCId(),
				'sales_page'=> $this->getSalesPage(),
				'p_id'=> $this->getProductId(),
				'product_name'=> $this->getProductName(),
				'button_name'=> $this->getName(),				
				'button_id'=> $this->getButtonId(),
				'currency_symbol'=> $this->getCurrencySymbol(),
				'currency_text'=> $this->getCurrencyText(),
				'bump_offer'=> $this->getBumpOffer(),
				'bump_id'=> $this->getBumpId(),
				'bump_prod_name'=> $this->getBumpProductName(),
				'bump_html'=> $this->getBumpHtml(),				
				'bump_temp'=> $this->getBumpTemp(),
				'checkout_id'=> $this->getCheckoutId(),
				'product_temp'=> $this->getProductTemp(),
				'order_sum_temp'=> $this->getOrderSumTemp(),
				'f_id'=> $this->getFId(),
				'landing_page'=> $this->getLandingPage(),
				'btn_code'=> $this->getBtnCode(),	
				'btn_styles'=> $this->getBtnStyles(),				
				'view_btn'=> $this->getViewBtn(),
				'live_mode'=> $this->getLiveMode(),
				'status'=> $this->getStatus(),
				'type'=> $this->getType(),
				'nopopup'=> $this->getNoPopup(),
				'payment_id'=> $this->getPaymentPlanId(),
				'coupon_strikeout'=> $this->getCouponStrikeout(),
				'coupon_id'=> $this->getCouponId(),
				'coupon_options'=> $this->getCouponOptions(),				
				'edit_dap_price'=> $this->getEditDapPrice(),
				'new_spc_price'=> $this->getNewSpcPrice(),
				'edit_bump_dap_price'=> $this->getEditBumpDapPrice(),
				'new_bump_spc_price'=> $this->getNewBumpSpcPrice(),
				'edit_dap_trial_days'=> $this->getEditDapTrialDays(),
				'new_spc_trial_days'=> $this->getNewSpcTrialDays(),
				'coupon_place'=> $this->getCouponPlace(),
				'tag_name'=> $this->getTagName(),
				'eu_vat_temp'=> $this->getEuVatTemp(),				
				'enable_taxjar'=> $this->getEnableTaxjar(),				
				'date'=> $this->getDate(),
				'spc_shipping_rate'=> $this->getSpcShippingRate(),
				'order_bump_position'=> $this->getOrderBumpPosition(),
				'bump_main_heading'=> $this->getBumpMainHeading(),
				'invoice_email'=> $this->getInvoicEmail(),
				'invoice_id'=> $this->getInvoiceId(),
				'continue_shopping_url'=> $this->getContinueShoppingUrl(),	
				'free_trial'=> $this->getFreeTrial(),	
				'free_trial_terms'=> $this->getFreeTrialTerms(),	
				'allow_purchase_using_credits'=> $this->getAllowPurchaseUsingCredits(),	
				'spc_shipping_options'=> $this->getSPCShippingOption(),	
			 
			);
			
			$wpdb->insert($tableName, $data);
			
			
			$id = $wpdb->insert_id;
			//spcwpLogToFile("SPCWP_BuyButton.class.php:create(), inserted successfully, returning", "debug");
			return $lastid = $id;
		}catch (Exception $e) {
			//spcwpLogToFile($e->getMessage(),'error');
			throw $e;
		}	
	}
	
	
	
	public function update(){
		try {
		//	spcwpLogToFile("SPCWP_BuyButton.class.php:update(), Entered", "debug");
			global $wpdb, $smartpaycart_product_details;
			$tableName = $smartpaycart_product_details;
			$data = array(
				'c_id'=> $this->getCId(),
				'sales_page'=> $this->getSalesPage(),
				'p_id'=> $this->getProductId(),
				'product_name'=> $this->getProductName(),
				'button_name'=> $this->getName(),				
				'button_id'=> $this->getButtonId(),
				'currency_symbol'=> $this->getCurrencySymbol(),
				'currency_text'=> $this->getCurrencyText(),
				'bump_offer'=> $this->getBumpOffer(),
				'bump_id'=> $this->getBumpId(),
				'bump_prod_name'=> $this->getBumpProductName(),
				'bump_html'=> $this->getBumpHtml(),				
				'bump_temp'=> $this->getBumpTemp(),
				'checkout_id'=> $this->getCheckoutId(),
				'product_temp'=> $this->getProductTemp(),
				'order_sum_temp'=> $this->getOrderSumTemp(),
				'f_id'=> $this->getFId(),
				'landing_page'=> $this->getLandingPage(),
				'btn_code'=> $this->getBtnCode(),	
				'btn_styles'=> $this->getBtnStyles(),				
				'view_btn'=> $this->getViewBtn(),
				'live_mode'=> $this->getLiveMode(),
				'status'=> $this->getStatus(),
				'type'=> $this->getType(),
				'nopopup'=> $this->getNoPopup(),
				'payment_id'=> $this->getPaymentPlanId(),
				'coupon_strikeout'=> $this->getCouponStrikeout(),
				'coupon_id'=> $this->getCouponId(),
				'coupon_options'=> $this->getCouponOptions(),				
				'edit_dap_price'=> $this->getEditDapPrice(),
				'new_spc_price'=> $this->getNewSpcPrice(),
				'edit_bump_dap_price'=> $this->getEditBumpDapPrice(),
				'new_bump_spc_price'=> $this->getNewBumpSpcPrice(),
				'edit_dap_trial_days'=> $this->getEditDapTrialDays(),
				'new_spc_trial_days'=> $this->getNewSpcTrialDays(),
				'coupon_place'=> $this->getCouponPlace(),
				'tag_name'=> $this->getTagName(),
				'eu_vat_temp'=> $this->getEuVatTemp(),	
				'enable_taxjar'=> $this->getEnableTaxjar(),			
				'date'=> $this->getDate(),
				'spc_shipping_rate'=> $this->getSpcShippingRate(),
				'order_bump_position'=> $this->getOrderBumpPosition(),
				'bump_main_heading'=> $this->getBumpMainHeading(),
				'invoice_email'=> $this->getInvoicEmail(),
				'invoice_id'=> $this->getInvoiceId(),
				'continue_shopping_url'=> $this->getContinueShoppingUrl(),
				'free_trial'=> $this->getFreeTrial(),	
				'free_trial_terms'=> $this->getFreeTrialTerms(),	
				'allow_purchase_using_credits'=> $this->getAllowPurchaseUsingCredits(),
				'spc_shipping_options'=> $this->getSPCShippingOption(),	
			);
			$wpdb->update($tableName,$data,array('button_id'=>$this->getButtonId()),null,null);
			$id = $this->getId();
			//spcwpLogToFile("SPCWP_BuyButton.class.php:update(), inserted successfully, returning", "debug");
			return $lastid = $id;
		}catch (Exception $e) {
			//spcwpLogToFile($e->getMessage(),'error');
			throw $e;
		}	
	}
		
	public static function loadAllButtons() {
		try {
		//spcwpLogToFile("SPCWP_BuyButton.class.php:loadAllButtons(), entered", "debug");
			global $wpdb, $smartpaycart_product_details;
			$tableName = $smartpaycart_product_details;
			$sql = "SELECT * FROM " . $tableName ;
			$rows = $wpdb->get_results($sql, ARRAY_A);

			$allButtons = array();
			if(isset($rows)){
				foreach($rows as $row) {
					
					$buyButton = new SPC_BuyButton();
										
					$buyButton->setId($row['id']);
					$buyButton->setCId($row['c_id']);
					$buyButton->setSalesPage($row['sales_page']);
					$buyButton->setProductId($row['p_id']);
					$buyButton->setProductName($row['product_name']);
					$buyButton->setName($row['button_name']);				
					$buyButton->setButtonId($row['button_id']);
					$buyButton->setCurrencySymbol($row['currency_symbol']);
					$buyButton->setCurrencyText($row['currency_text']);
					$buyButton->setBumpOffer($row['bump_offer']);
					$buyButton->setBumpId($row['bump_id']);
					$buyButton->setBumpProductName($row['bump_prod_name']);
					$buyButton->setBumpHtml($row['bump_html']);				
					$buyButton->setBumpTemp($row['bump_temp']);
					$buyButton->setCheckoutId($row['checkout_id']);
					$buyButton->setProductTemp($row['product_temp']);
					$buyButton->setOrderSumTemp($row['order_sum_temp']);
					$buyButton->setFId($row['f_id']);
					$buyButton->setLandingPage($row['landing_page']);
					$buyButton->setBtnCode($row['btn_code']);	
					$buyButton->setBtnStyles($row['btn_styles']);				
					$buyButton->setViewBtn($row['view_btn']);
					$buyButton->setLiveMode($row['live_mode']);
					$buyButton->setStatus($row['status']);
					$buyButton->setType($row['type']);
					$buyButton->setNoPopup($row['nopopup']);
					$buyButton->setPaymentPlanId($row['payment_id']);
					$buyButton->setCouponStrikeout($row['coupon_strikeout']);
					$buyButton->setCouponId($row['coupon_id']);
					$buyButton->setCouponOptions($row['coupon_options']);				
					$buyButton->setEditDapPrice($row['edit_dap_price']);
					$buyButton->setNewSpcPrice($row['new_spc_price']);
					$buyButton->setEditBumpDapPrice($row['edit_bump_dap_price']);
					$buyButton->setNewBumpSpcPrice($row['new_bump_spc_price']);
					$buyButton->setEditDapTrialDays($row['edit_dap_trial_days']);
					$buyButton->setNewSpcTrialDays($row['new_spc_trial_days']);
					$buyButton->setCouponPlace($row['coupon_place']);
					$buyButton->setTagName($row['tag_name']);
					$buyButton->setEuVatTemp($row['eu_vat_temp']);				
					$buyButton->setEnableTaxjar($row['enable_taxjar']);				
					$buyButton->setDate($row['date']);
					$buyButton->setSpcShippingRate($row['spc_shipping_rate']);
					$buyButton->setOrderBumpPosition($row['order_bump_position']);
					$buyButton->setBumpMainHeading($row['bump_main_heading']);
					$buyButton->setInvoicEmail($row['invoice_email']);
					$buyButton->setInvoiceId($row['invoice_id']);
					$buyButton->setContinueShoppingUrl($row['continue_shopping_url']);
					$buyButton->setFreeTrial($row['free_trial']);	
					$buyButton->setFreeTrialTerms($row['free_trial_terms']);	
					$buyButton->setAllowPurchaseUsingCredits($row['allow_purchase_using_credits']);	
					$buyButton->setSPCShippingOption($row['spc_shipping_options']);	
					
					
					$allButtons[] = $buyButton;
				}
				//spcwpLogToFile("SPCWP_BuyButton.class.php:loadAllButtons(), returning", "debug");
				return 	$allButtons;
			}
			
		}catch (Exception $e) {
		//	spcwpLogToFile($e->getMessage(),'error');
			throw $e;
		}
	}
	
	
	public static function loadButtonDetailsById($b_id, $type) {
		try {
		//spcwpLogToFile("SPCWP_BuyButton.class.php:loadButtonDetailsById(), entered", "debug");
			global $wpdb, $smartpaycart_product_details;
			$tableName = $smartpaycart_product_details;
			
			//$sql = "SELECT * FROM " . $tableName . " WHERE `button_id` ='".$b_id."' AND `type`='$type'" ;
			
			if($type=="addtocart")
				$sql = "SELECT * FROM " . $tableName . " WHERE `button_id` ='".$b_id."' AND `type`='$type'" ;
			else 
				$sql = "SELECT * FROM " . $tableName . " WHERE `button_id` ='".$b_id."'" ;
			
			$rows = $wpdb->get_results($sql, ARRAY_A);
			if(isset($rows)){
					$row = $rows[0];
					$buyButton = new SPC_BuyButton();
					$buyButton->setId($row['id']);
					$buyButton->setName($row['button_name']);
					$buyButton->setSalesPage($row['sales_page']);
					$buyButton->setButtonId($row['button_id']);
					$buyButton->setProductId($row['p_id']);
					$buyButton->setCurrencySymbol($row['currency_symbol']);
					$buyButton->setCurrencyText($row['currency_text']);
					$buyButton->setBumpOffer($row['bump_offer']);
					$buyButton->setBumpId($row['bump_id']);
					
					$buyButton->setCheckoutId($row['checkout_id']);
					$buyButton->setProductTemp($row['product_temp']);
					$buyButton->setOrderSumTemp($row['order_sum_temp']);
					$buyButton->setFId($row['f_id']);
					$buyButton->setLandingPage($row['landing_page']);
					$buyButton->setLiveMode($row['live_mode']);
					$buyButton->setStatus($row['status']);
					$buyButton->setType($row['type']);
					$buyButton->setCouponStrikeout($row['coupon_strikeout']);
					$buyButton->setCouponId($row['coupon_id']);
					$buyButton->setCouponOptions($row['coupon_options']);
					$buyButton->setEditDapPrice($row['edit_dap_price']);
					$buyButton->setNewSpcPrice($row['new_spc_price']);
					$buyButton->setEditDapTrialDays($row['edit_dap_trial_days']);
					$buyButton->setNewSpcTrialDays($row['new_spc_trial_days']);
					$buyButton->setCouponPlace($row['coupon_place']);
					$buyButton->setTagName($row['tag_name']);
					$buyButton->setEuVatTemp($row['eu_vat_temp']);
					$buyButton->setEnableTaxjar($row['enable_taxjar']);
					$buyButton->setOrderBumpPosition($row['order_bump_position']);
					$buyButton->setBumpMainHeading($row['bump_main_heading']);
					$buyButton->setPaymentPlanId($row['payment_id']);
					$buyButton->setFreeTrial($row['free_trial']);	
					$buyButton->setFreeTrialTerms($row['free_trial_terms']);	
					$buyButton->setInvoicEmail($row['invoice_email']);
					$buyButton->setInvoiceId($row['invoice_id']);
					$buyButton->setAllowPurchaseUsingCredits($row['allow_purchase_using_credits']);	
					$buyButton->setContinueShoppingUrl($row['continue_shopping_url']);	
					$buyButton->setSPCShippingOption($row['spc_shipping_options']);	
				
				//spcwpLogToFile("SPCWP_BuyButton.class.php:loadButtonDetailsById(), returning", "debug");
				return 	$buyButton;
			}
			
		}catch (Exception $e) {
		//	spcwpLogToFile($e->getMessage(),'error');
			throw $e;
		}
	}
	
	public static function loadButtonCodeById($b_id) {
		 
		try {
			global $wpdb, $smartpaycart_product_details;
			$tableName = $smartpaycart_product_details;
			$sql = "SELECT * FROM " . $tableName . " WHERE `id` ='".$b_id."'" ;
			$rows = $wpdb->get_results($sql, ARRAY_A);

			if(isset($rows)){
					$row = $rows[0];
					$buyButton = new SPC_BuyButton();
					$buyButton->setId($row['id']);
					$buyButton->setCId($row['c_id']);
					$buyButton->setSalesPage($row['sales_page']);
					$buyButton->setProductId($row['p_id']);
					$buyButton->setProductName($row['product_name']);
					$buyButton->setName($row['button_name']);				
					$buyButton->setButtonId($row['button_id']);
					$buyButton->setCurrencySymbol($row['currency_symbol']);
					$buyButton->setCurrencyText($row['currency_text']);
					$buyButton->setBumpOffer($row['bump_offer']);
					$buyButton->setBumpId($row['bump_id']);
					$buyButton->setBumpProductName($row['bump_prod_name']);
					$buyButton->setBumpHtml($row['bump_html']);				
					$buyButton->setBumpTemp($row['bump_temp']);
					$buyButton->setCheckoutId($row['checkout_id']);
					$buyButton->setProductTemp($row['product_temp']);
					$buyButton->setOrderSumTemp($row['order_sum_temp']);
					$buyButton->setFId($row['f_id']);
					$buyButton->setLandingPage($row['landing_page']);
					$buyButton->setBtnCode($row['btn_code']);	
					$buyButton->setBtnStyles($row['btn_styles']);				
					$buyButton->setViewBtn($row['view_btn']);
					$buyButton->setLiveMode($row['live_mode']);
					$buyButton->setStatus($row['status']);
					$buyButton->setType($row['type']);
					$buyButton->setNoPopup($row['nopopup']);
					$buyButton->setPaymentPlanId($row['payment_id']);
					$buyButton->setCouponStrikeout($row['coupon_strikeout']);
					$buyButton->setCouponId($row['coupon_id']);
					$buyButton->setCouponOptions($row['coupon_options']);				
					$buyButton->setEditDapPrice($row['edit_dap_price']);
					$buyButton->setNewSpcPrice($row['new_spc_price']);
					$buyButton->setEditBumpDapPrice($row['edit_bump_dap_price']);
					$buyButton->setNewBumpSpcPrice($row['new_bump_spc_price']);
					$buyButton->setEditDapTrialDays($row['edit_dap_trial_days']);
					$buyButton->setNewSpcTrialDays($row['new_spc_trial_days']);
					$buyButton->setCouponPlace($row['coupon_place']);
					$buyButton->setTagName($row['tag_name']);
					$buyButton->setEuVatTemp($row['eu_vat_temp']);			
					$buyButton->setEnableTaxjar($row['enable_taxjar']);	
					$buyButton->setDate($row['date']);
					$buyButton->setSpcShippingRate($row['spc_shipping_rate']);
					$buyButton->setOrderBumpPosition($row['order_bump_position']);
					$buyButton->setBumpMainHeading($row['bump_main_heading']);
					$buyButton->setInvoicEmail($row['invoice_email']);
					$buyButton->setInvoiceId($row['invoice_id']);
					$buyButton->setContinueShoppingUrl($row['continue_shopping_url']);
					$buyButton->setAllowPurchaseUsingCredits($row['allow_purchase_using_credits']);	
					$buyButton->setSPCShippingOption($row['spc_shipping_options']);	
				return $buyButton;
			}
			
		}catch (Exception $e) {
			throw $e;
		}
	}
	
	public function loadButtonIdByName() {
		try {
		
			global $wpdb, $smartpaycart_product_details;
			$table_name = $smartpaycart_product_details;
			$sql = "SELECT id FROM ".$table_name." WHERE button_name = '".trim($this->getName())."'";
			$row = $wpdb->get_row($sql, ARRAY_A);
            if($row){
				return 'button_error';
			}else{
				return '';
			}
			
		}catch (Exception $e) {
		//	spcwpLogToFile($e->getMessage(),'error');
			throw $e;
		}
	}
	
	public static function delete($id) {
		try {

			global $wpdb, $smartpaycart_product_details;
			$tableName = $smartpaycart_product_details;

			$wpdb->delete( $tableName, array('id'=>$id) );	
			return "deleted";

		}catch (Exception $e) {	
			echo $e->getMessage();
		}
	}
	
	public static function loadAllData(){
		
		global $wpdb, $smartpaycart_product_details, $smartpaycart_funnel;
		
		$tableName = $smartpaycart_product_details;

		$table_Name = $smartpaycart_funnel;		

		$sfpd= 'SELECT sf.id, pd.bump_offer , pd.bump_id, sf.landingpage, pd.button_name, pd.id, pd.button_id, pd.product_name, pd.sales_page, pd.checkout_id, pd.c_id, pd.bump_prod_name,

		pd.landing_page, pd.f_id, pd.live_mode, pd.date, pd.btn_code, pd.type FROM '.$table_Name.' sf

		RIGHT JOIN '.$tableName.' pd ON sf.id=pd.f_id WHERE pd.type="buynow" ORDER BY date DESC';

		return  $wpdb->get_results($sfpd, ARRAY_A);
		
	}
	
	public static function loadAllDataAddToCart(){
		
		global $wpdb, $smartpaycart_product_details, $smartpaycart_funnel;
		
		$tableName = $smartpaycart_product_details;

		$table_Name = $smartpaycart_funnel;		

		$sfpd= 'SELECT sf.id, pd.bump_offer , pd.bump_id, sf.landingpage, pd.button_name, pd.id, pd.button_id, pd.product_name, pd.sales_page, pd.checkout_id, pd.c_id, pd.bump_prod_name,

		pd.landing_page, pd.f_id, pd.live_mode, pd.date, pd.btn_code, pd.type FROM '.$table_Name.' sf

		RIGHT JOIN '.$tableName.' pd ON sf.id=pd.f_id WHERE pd.type="addtocart" ORDER BY date DESC';

		return  $wpdb->get_results($sfpd, ARRAY_A);
		
	}
	
	public static function loadTemplateById( $checkout_id, $checkout_num){
		
		global $wpdb, $smartpaycart_checkout;
		$tableName = $smartpaycart_checkout;
		
		if($checkout_num == "n"){
			$sql = "SELECT a.* FROM ". $tableName. " a INNER JOIN  (SELECT checkout_page,   MAX(id) as id   FROM ". $tableName. " WHERE checkout_page = ".$checkout_id."  GROUP BY checkout_page ) 
			AS b ON a.checkout_page = b.checkout_page   AND a.id = b.id";
		}else{	
			$sql = "SELECT * FROM ". $tableName. " WHERE id = ".$checkout_id."";
		}
		$rows = $wpdb->get_results($sql, ARRAY_A);
		return  $rows;
	}
	public static function loadDonationData(){
		
		global $wpdb, $smartpaycart_product_details, $smartpaycart_funnel;
		
		$tableName = $smartpaycart_product_details;

		$table_Name = $smartpaycart_funnel;		

		$sfpd= 'SELECT sf.id,  sf.landingpage, pd.button_name, pd.id, pd.button_id, pd.product_name, pd.sales_page, pd.checkout_id, pd.c_id, 

		pd.landing_page,   pd.live_mode, pd.date, pd.btn_code, pd.type FROM '.$table_Name.' sf

		RIGHT JOIN '.$tableName.' pd ON sf.id=pd.f_id WHERE pd.type="donation" ORDER BY date DESC';

		return  $wpdb->get_results($sfpd, ARRAY_A);
		
	}
	
		
}
