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/nopurchase.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_NOPURCHASE_TEXT_TITLE', 'Contact Customers without Purchase');
	
	
	define('MAILBEEZ_NOPURCHASE_TEXT_DESCRIPTION', 'Contact customers with account but no orders.<br>
	<br>');
	
  class nopurchase extends mailbeez {
		// class constructor
    function nopurchase() {
			// call constructor
			mailbeez::mailbeez(); 
			
			// set some stuff:
      $this->code = 'nopurchase';
			$this->module = 'nopurchase'; // same as folder name
			$this->version = '1.1'; // float value
			$this->iteration = 1;
      $this->title = MAILBEEZ_NOPURCHASE_TEXT_TITLE;
      $this->description = MAILBEEZ_NOPURCHASE_TEXT_DESCRIPTION;
      $this->sort_order = MAILBEEZ_NOPURCHASE_SORT_ORDER;
      $this->enabled = ((MAILBEEZ_NOPURCHASE_STATUS == 'True') ? true : false);
			$this->sender = MAILBEEZ_NOPURCHASE_SENDER;
			$this->sender_name = MAILBEEZ_NOPURCHASE_SENDER_NAME;
			$this->status_key = 'MAILBEEZ_NOPURCHASE_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'); 
			// list of additional fields to show in listing with testvalues used for Test-Mail
	
    }
	

	// class methods
    
		function getAudience() {
			global $languages_id;
			$status = MAILBEEZ_NOPURCHASE_ORDER_STATUS_ID;
// For security cover up the cc_number on table 7/01/2011 JOE.
     $update_cc = "update  " . TABLE_ORDERS . "
	 set cc_number = concat(substring(cc_number,1,4), repeat('X', (char_length(cc_number)-8)),substring(cc_number, -4) )  
	 where cc_number !='' 
	 and cc_number not like '%XXXX%' 
	 and date_purchased < DATE_SUB(CURRENT_DATE,INTERVAL 1 DAY)";	 
	 mh_db_query($update_cc);
// update order status //orders_status_history
     $update_status = "update  " . TABLE_ORDERS_STATUS_HISTORY . "
	 set orders_status_id = '3' 
	 where orders_status_id in ('1','2')
	 and date_added < DATE_SUB(CURRENT_DATE,INTERVAL 1 DAY)";	 
	 mh_db_query($update_status);
// update order status //orders_status_history
     $update_status = "update  " . TABLE_ORDERS . "
	 set orders_status = '3' 
	 where orders_status in ('1','2')
	 and date_purchased < DATE_SUB(CURRENT_DATE,INTERVAL 1 DAY)";	 
	 mh_db_query($update_status);
	 
//clean up and resend some old listing

     $delete_track = "delete  from " . TABLE_MAILBEEZ_TRACKING . "
	 where module ='" . $this->module . "' 
	 and date_sent < DATE_SUB(CURRENT_DATE,INTERVAL 195 DAY) ";	 
	 mh_db_query($delete_track);
	 
//purge order and order history older then 12 months
$order_list ='1';
	$order_list_sql = "select orders_id
              from " . TABLE_ORDERS . "
              where date_purchased < DATE_SUB(CURRENT_DATE,INTERVAL 12 MONTH) ORDER BY date_purchased DESC";
	 $query_order_list = mh_db_query($order_list_sql);
     while ($order_result = mh_db_fetch_array($query_order_list))  {
        $order_list .= $order_result['orders_id'] . ',';
     }
     $order_list = rtrim($order_list, ',');
  if ($order_list != '1') {
	 $del_sql = "delete from " . TABLE_ORDERS_TOTAL . " where orders_id in (" . $order_list . ")";
	 mh_db_query($del_sql);
	 $del_sql = "delete from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id in (" . $order_list . ")";
	 mh_db_query($del_sql);
	 $del_sql = "delete from " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " where orders_id in (" . $order_list . ")";
	 mh_db_query($del_sql);
	 $del_sql = "delete from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id in (" . $order_list . ")";
	 mh_db_query($del_sql);
	 $del_sql = "delete from " . TABLE_ORDERS_PRODUCTS . " where orders_id in (" . $order_list . ")";
	 mh_db_query($del_sql);
	 $del_sql = "delete from " . TABLE_ORDERS . " where orders_id in (" . $order_list . ")";
	 mh_db_query($del_sql);	 
	} 
//end of purge

//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 =  'We would like to send you ' .$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_NOPURCHASE_PASSED_DAYS
			// MAILBEEZ_NOPURCHASE_PASSED_DAYS_SKIP
			
      $date_skip = $this->dbdate(MAILBEEZ_NOPURCHASE_PASSED_DAYS_SKIP);
      $date_passed = $this->dbdate(MAILBEEZ_NOPURCHASE_PASSED_DAYS);
	 // mh_db_query("SET SQL_BIG_SELECTS=1");		
      $query_raw = "select c.customers_firstname, c.customers_lastname, 
														c.customers_id, c.customers_email_address
											      from " . TABLE_CUSTOMERS. " c, " . TABLE_CUSTOMERS_INFO . " ci
											        left join " . TABLE_ORDERS . " o
											          on (o.customers_id = ci.customers_info_id) " . 
														  ( (MAILBEEZ_NOPURCHASE_CB == 'True') ? 
														  " left join  " . TABLE_CUSTOMERS_BASKET . " cb
											          on (cb.customers_id = ci.customers_info_id) " : '' ) . "
											      where o.customers_id is NULL  " .
															( (MAILBEEZ_NOPURCHASE_CB == 'True') ? 
															" and cb.customers_id is NULL  " : '' ) . "
															and ci.customers_info_id = c.customers_id
											        and ci.customers_info_date_account_created <= '" . $date_passed . "' 
											        and ci.customers_info_date_account_created > '" . $date_skip . "' ";		
			
			//echo  $query_raw;
			
			$query = mh_db_query($query_raw);
			
			// for early check
			$mb_chk = new mailbeez_mailer($this);			
			$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>
			
				// early check to avoid processing when email was already sent
				$chk_result = $mb_chk->check($this->module, $this->iteration, $item['customers_id']);
				if ($chk_result != false) {
					// this iteration for this customer was already sent -> skip
					
					continue;
				}			
			
			
				$this->audience[$item['customers_id']] = array('firstname' => $item['customers_firstname'],
																											 'lastname' => $item['customers_lastname'],
																											 'coupon_content' => $coupon_content,
			                                                 'email_address' => $item['customers_email_address'],
															 'customers_id' => $item['customers_id']
																								 );
				$mycount++;
				if ($mycount == 1 ) { break;}	
			}
			return $this->audience;
		}
		
		
		
		// installation methods
		
    function keys() {
      return array('MAILBEEZ_NOPURCHASE_STATUS', 'MAILBEEZ_NOPURCHASE_PASSED_DAYS', 'MAILBEEZ_NOPURCHASE_PASSED_DAYS_SKIP', 'MAILBEEZ_NOPURCHASE_SENDER', 'MAILBEEZ_NOPURCHASE_CB', 'MAILBEEZ_NOPURCHASE_SENDER_NAME', 'MAILBEEZ_NOPURCHASE_SORT_ORDER');
    }
		
    function install() {
			mh_insert_config_value(array('configuration_title' => 'Send nopurchase email', 
																	 'configuration_key' => 'MAILBEEZ_NOPURCHASE_STATUS', 
																	 'configuration_value' => 'False', 
																	 'configuration_description' => 'Do you want to send nopurchase emails?', 
																	 'set_function' => 'mh_cfg_select_option(array(\'True\', \'False\'), '
																	 ));

			mh_insert_config_value(array('configuration_title' => 'Set days passed after account created', 
																	 'configuration_key' => 'MAILBEEZ_NOPURCHASE_PASSED_DAYS', 
																	 'configuration_value' => '5', 
																	 'configuration_description' => 'number of days since customer signed for an account', 
																	 'set_function' => ''
																	 ));
																	 
			mh_insert_config_value(array('configuration_title' => 'Set days to skip after', 
																	 'configuration_key' => 'MAILBEEZ_NOPURCHASE_PASSED_DAYS_SKIP', 
																	 'configuration_value' => '10', 
																	 'configuration_description' => 'number of days after which do skip the nopurchase email', 
																	 'set_function' => ''
																	 ));
																	 
			mh_insert_config_value(array('configuration_title' => 'check for empty customer basket', 
																	 'configuration_key' => 'MAILBEEZ_NOPURCHASE_CB', 
																	 'configuration_value' => 'False', 
																	 'configuration_description' => 'send only when customer basket is empty?', 
																	 'set_function' => 'mh_cfg_select_option(array(\'True\', \'False\'), '
																	 ));																	 
																	 
			mh_insert_config_value(array('configuration_title' => 'sender email', 
																	 'configuration_key' => 'MAILBEEZ_NOPURCHASE_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_NOPURCHASE_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_NOPURCHASE_SORT_ORDER', 
																	 'configuration_value' => '50', 
																	 'configuration_description' => 'Sort order of display. Lowest is displayed first.', 
																	 'set_function' => ''
																	 ));
    }		
  }
?>