MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/sb_web/b744/yushibrentwood.com/mailhive/mailbeez/
File Upload :
Current < : /hermes/sb_web/b744/yushibrentwood.com/mailhive/mailbeez/recovercart.php

<?php
/*
  MailBeez Automatic Trigger Email Campaigns
  http://www.mailbeez.com

  Copyright (c) 2010 MailBeez
	
	inspired and in parts based on
  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

	// make path work from admin
  require_once(DIR_FS_CATALOG. 'mailhive/common/classes/mailbeez.php');	
	
	// could be in language-file
	// just easier to define it in the mailbee
	define('MAILBEEZ_RCART_TEXT_TITLE', 'Rcovery CART Customer Reactivation');
	define('TABLE_SCART', DB_PREFIX . 'scart');
	
	define('MAILBEEZ_RCART_TEXT_DESCRIPTION', 'Inquery your customers who have inprocessed cart.<br>
	<br>
	If you haven\'t had a customer has unprocessed shopping cart, activate this auto recovery sale MailBeez Module to inquery the reason.');
	
  class recovercart extends mailbeez {
		// class constructor
    function recovercart() {
			// call constructor
			mailbeez::mailbeez(); 
			
			// set some stuff:
      $this->code = 'recovercart';
			$this->module = 'recovercart'; // same as folder name
			$this->version = '1.0'; // float value
			$this->iteration = 100;
      $this->title = MAILBEEZ_RCART_TEXT_TITLE;
      $this->description = MAILBEEZ_RCART_TEXT_DESCRIPTION;
      $this->sort_order = MAILBEEZ_RCART_SORT_ORDER;
      $this->enabled = ((MAILBEEZ_RCART_STATUS == 'True') ? true : false);
			$this->sender = MAILBEEZ_RCART_SENDER;
			$this->sender_name = MAILBEEZ_RCART_SENDER_NAME;
			$this->status_key = 'MAILBEEZ_RCART_STATUS';
			
			//$this->icon = 'icon.png';
			
			$this->documentation_key = $this->module; // leave empty if no documentation available
			// $this->documentation_root = 'http:://yoursite.com/' // modify documentation root if necessary
			
			$this->htmlBodyTemplateResource = 'body_html.tpl'; // located in folder of this module
			$this->txtBodyTemplateResource = 'body_txt.tpl'; // located in folder of this module			
			$this->subjectTemplateResource = 'subject.tpl'; // located in folder of this module
			
			$this->audience = array();
			$this->additionalFields = array('customers_id' => '007', 'customers_email_address' => 'customer@mail.com', 'coupon_content' => 'Test coupon off',  
			//'order_id' => '123456', 
			//'order_date' => '12.12.2000', 
			'status_date' => '31.12.2000'); 
			// list of additional fields to show in listing with testvalues used for Test-Mail
	
    }

// class methods
    
		function getAudience() {
			global $languages_id;
			$status = MAILBEEZ_RCART_ORDER_STATUS_ID;
			//$day_of_week = date(l,time());
			//$expires_date = time() + 60 * 60 * 23 ;
		//exit if store is closed
		$current_time = time();
		$day_of_week = strtoupper(date(l,$current_time));
		$isopen = constant('MODULE_SHIPPING_STOREHOURS_OPCL_' . $day_of_week);
		if ( $isopen == 0 ) { exit;}
//coupon mail
	$cp_sql = "select coupon_amount, coupon_minimum_order, coupon_code, coupon_type
              from " . TABLE_COUPONS . "
              where coupon_start_date <= now()
			  and coupon_expire_date >= now()
			  and coupon_type in ('F','P')
			  and coupon_minimum_order <2000
              and coupon_active='Y'  ORDER BY RAND() LIMIT 1";
	 $query_c = mh_db_query($cp_sql);
	  $coupon_content = '';
	while ($cp_result = mh_db_fetch_array($query_c))  {	
	    $coupon_minimum_order = '$'. round ($cp_result['coupon_minimum_order'],2);
		$coupon_type = $cp_result['coupon_type'];
		 
		if ( $coupon_type == 'F') {
		  $coupon_amount = '$'. round ($cp_result['coupon_amount'], 2);
		  
		}else {
		   $coupon_amount = round($cp_result['coupon_amount'],4) .'%';
		}
		 
		  $coupon_content =  'Please use ' .$coupon_amount. ' off coupon code: <b>'.$cp_result['coupon_code'] . '</b> when you order online with minimum order of '. $coupon_minimum_order .' (with restrictions).'; 

		  break;	 
	}
//echo $coupon_content;
//eof coupon mail 022511 	
//free gift 
		if ( $coupon_content == '') {		
		$query_g =  mh_db_query("SELECT fg.*, pd.products_name FROM (" . TABLE_CARROT . " fg, " . TABLE_PRODUCTS . "  p)
		LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (pd.products_id=fg.products_id)
		WHERE pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
		AND p.products_id = fg.products_id
		ORDER BY RAND() LIMIT 1");
		
			while ($cp_result = mh_db_fetch_array($query_g))  {	
			$coupon_minimum_order = '$'. round ($cp_result['threshold'],2);
		 
			$coupon_content =  'You will get  <b>'. $cp_result['products_name'] . '</b> when you order online with minimum order of '. $coupon_minimum_order .' (with restrictions).'; 

			break;	 
			}
		
		}
//echo $coupon_content;
			// MAILBEEZ_RCART_PASSED_DAYS
			// MAILBEEZ_RCART_PASSED_DAYS_SKIP
			
      $date_skip = $this->dbdate(MAILBEEZ_RCART_PASSED_DAYS_SKIP);
      $date_passed = $this->dbdate(MAILBEEZ_RCART_PASSED_DAYS);

// See if a record for this customer already exists; if not create one and if so update it
	$customers = mh_db_query("SELECT customers_id FROM ". TABLE_CUSTOMERS_BASKET);
	$cid = '0';
	while ($idlist = mh_db_fetch_array($customers)) {
	    $cid = $idlist['customers_id'];
		$donequery = mh_db_fetch_array(mh_db_query("SELECT * FROM ". TABLE_SCART ." WHERE customers_id = '" . $cid . "'"));
		if (!$donequery[customers_id]) {
			mh_db_query("INSERT INTO " . TABLE_SCART . " (customers_id, dateadded, datemodified) VALUES ('" . $cid . "', '" . date('Ymd') . "', '19710101')");
         }			
	}		
	  $query_raw = "SELECT  cb.customers_id,
																 cus.customers_firstname,
																 cus.customers_lastname,
																 cus.customers_telephone,
																 DATE_FORMAT(cb.customers_basket_date_added, '%m/%d/%Y') customers_basket_date_added,
																 cus.customers_email_address
													FROM " . TABLE_CUSTOMERS_BASKET . " cb
														LEFT JOIN " . TABLE_CUSTOMERS . " cus ON (cb.customers_id = cus.customers_id)
														LEFT JOIN " . TABLE_SCART . " sc ON (cb.customers_id = sc.customers_id)
													WHERE cb.customers_basket_date_added > '" . $date_skip . "'
														and cb.customers_basket_date_added <= '" . $date_passed. "'
														and cb.customers_basket_date_added >= sc.datemodified
													";												  
			
			//echo "$query_raw";
			//mh_db_query("SET OPTION SQL_BIG_SELECTS=1");
			$query = mh_db_query($query_raw);
			$mycoupon_content ='';
			$mycount=0;
			while ($item = mh_db_fetch_array($query)) {
			// mandatory fields:
			// - firstname
			// - lastname
			// - email_address
			// - customers-id -> block
			
			// other keys are replaced while sending: $<key>
				$mycoupon_content = $coupon_content;		
			    //update the indicator email that has been sent.
				if ($item['customers_id']) {
			    mh_db_query("UPDATE " . TABLE_SCART . " SET datemodified = '" . date('Ymd') . "' WHERE customers_id = " . $item['customers_id'] );
				}
				$this->audience[$item['customers_id']] = array('firstname' => $item['customers_firstname'],
																											 'lastname' => $item['customers_lastname'],
																											 'coupon_content' => $mycoupon_content,
																											 'email_address' => $item['customers_email_address'],
																											 'customers_id' => $item['customers_id'],
																											 'storename' => STORE_NAME,
																											 'status_date' => $item['customers_basket_date_added']
																								 );	
			$mycount++;																					 
			if ($mycount == 1) {break;}																								 
			}
			return $this->audience;
		}
		
		
		
		// installation methods
		
    function keys() {
      return array('MAILBEEZ_RCART_STATUS', 'MAILBEEZ_RCART_PASSED_DAYS', 'MAILBEEZ_RCART_PASSED_DAYS_SKIP', 'MAILBEEZ_RCART_SENDER', 'MAILBEEZ_RCART_SENDER_NAME', 'MAILBEEZ_RCART_SORT_ORDER');
    }
		
    function install() {
			mh_insert_config_value(array('configuration_title' => 'Send RCART trigger email', 
																	 'configuration_key' => 'MAILBEEZ_RCART_STATUS', 
																	 'configuration_value' => 'False', 
																	 'configuration_description' => 'Do you want to send RCART emails?', 
																	 'set_function' => 'mh_cfg_select_option(array(\'True\', \'False\'), '
																	 ));

			mh_insert_config_value(array('configuration_title' => 'Set days passed', 
																	 'configuration_key' => 'MAILBEEZ_RCART_PASSED_DAYS', 
																	 'configuration_value' => '2', 
																	 'configuration_description' => 'number of days since last updated cart', 
																	 'set_function' => ''
																	 ));
																	 
			mh_insert_config_value(array('configuration_title' => 'Set days to skip after', 
																	 'configuration_key' => 'MAILBEEZ_RCART_PASSED_DAYS_SKIP', 
																	 'configuration_value' => '200', 
																	 'configuration_description' => 'number of days after which do skip the RCART email', 
																	 'set_function' => ''
																	 ));
																	 
			mh_insert_config_value(array('configuration_title' => 'sender email', 
																	 'configuration_key' => 'MAILBEEZ_RCART_SENDER', 
																	 'configuration_value' => STORE_OWNER_EMAIL_ADDRESS, 
																	 'configuration_description' => 'sender email', 
																	 'set_function' => ''
																	 ));
																	 
			mh_insert_config_value(array('configuration_title' => 'sender name', 
																	 'configuration_key' => 'MAILBEEZ_RCART_SENDER_NAME', 
																	 'configuration_value' => STORE_NAME, 
																	 'configuration_description' => 'sender email', 
																	 'set_function' => ''
																	 ));
																	 																	 
			mh_insert_config_value(array('configuration_title' => 'Sort order of display.', 
																	 'configuration_key' => 'MAILBEEZ_RCART_SORT_ORDER', 
																	 'configuration_value' => '30', 
																	 'configuration_description' => 'Sort order of display. Lowest is displayed first.', 
																	 'set_function' => ''
																	 ));
    }		
  }
?>