<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>

<body>
<?php
define('DATE_FORMAT_LONG', '%A %d %B, %Y');
echo tep_date_long('2007-10-9 1:1:1').'<hr>';
//      tep_mail($name, $email_address, EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
  function tep_date_long($raw_date) {
    if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;

    $year = (int)substr($raw_date, 0, 4);
    $month = (int)substr($raw_date, 5, 2);
    $day = (int)substr($raw_date, 8, 2);
    $hour = (int)substr($raw_date, 11, 2);
    $minute = (int)substr($raw_date, 14, 2);
    $second = (int)substr($raw_date, 17, 2);

    return strftime(DATE_FORMAT_LONG, mktime($hour,$minute,$second,$month,$day,$year));
  }

include('includes/configure.php');

define('EMAIL','sales@monde-tech.com');
define('WEBSITE','<a href="http://www.monde-tech.com">www.monde-tech.com</a>');
define('AUTHOR','Service clientèle de monde-tech.com');

define('business_email','sales@monde-tech.com');
define('invoice_sitename','monde-');
define('WEBSITENAME','monde-tech.com');

/*
define('DB_SERVER','xq2328');
define('DB_SERVER_USERNAME','root');
define('DB_SERVER_PASSWORD','');
define('DB_DATABASE','com_up3');		*/

echo('send paypal:'.mailto_nopay_paypal(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD,DB_DATABASE,7));
echo('<br><br>');
echo('<br>send ckeck:'.mailto_nopay_check(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD,DB_DATABASE,7));

function check_had_pay($dbserver,$dbuser,$dbpass,$db,$c_id,$n)
{
	$result=false;

	$str="select * from orders";
	$str.=" where `orders_status` in ('2','3') and customers_id='".$c_id."' ";
	$str.=" and (to_days(current_date)-to_days(date_purchased)>$n) and (to_days(current_date)-to_days(date_purchased)<($n+3))";
	//echo($str ."<br>");
	$conn=mysql_connect($dbserver,$dbuser,$dbpass) or die("databae error");
	//echo($str);
	mysql_select_db($db);
	
	$qu=mysql_query($str) ;//or die("query error");

	if (mysql_num_rows($qu)>0) $result=true;

	return $result;
}

function update_ismailto($dbserver,$dbuser,$dbpass,$db,$c_id,$n)
{
	$str="update orders set is_mailto=1 ";
	$str.=" where orders_status not in (2,3) and is_mailto=0 and customers_id='".$c_id."' ";
	$str.=" and (to_days(current_date)-to_days(date_purchased)>$n) and (to_days(current_date)-to_days(date_purchased)<($n+3))";
	//echo($str ."<br>");
	$conn=mysql_connect($dbserver,$dbuser,$dbpass) or die("databae error");
	//echo($str);
	mysql_select_db($db);
	mysql_query($str) ;
}

function mailto_nopay_paypal($dbserver,$dbuser,$dbpass,$db,$n)
{
	$str="select * from orders";
	$str.=" where (payment_method ='paypal') and (orders_status in (4)) and is_mailto=0 ";
	$str.=" and (to_days(current_date)-to_days(date_purchased)>$n) and (to_days(current_date)-to_days(date_purchased)<($n+3))";
	//echo($str ."<br>");
	$conn=mysql_connect($dbserver,$dbuser,$dbpass) or die("databae error");
	//echo($str);
	mysql_select_db($db);
	
	$qu=mysql_query($str) ;//or die("query error");
	$i=0;
	$from = EMAIL;
	//$headers = "From: $from";
	$headers = "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/html; charset=utf-8\n";
	$headers .= "From: $from\n";
	$headers .= "Reply-To: ".EMAIL."\n"; 
	
	while($re=mysql_fetch_object($qu))
	{
		if (check_had_pay($dbserver,$dbuser,$dbpass,$db,$re->customers_id,$n)) {update_ismailto($dbserver,$dbuser,$dbpass,$db,$re->customers_id,$n);continue;}
		//check status,if 0 excute;else not excute;
		$status=0;
		$sta_orderid=$re->orders_id;
		$sta_str="select count(*) from orders_status_history where orders_id=$sta_orderid and  (orders_status_id=2 or orders_status_id=3)";
		//echo($sta_str . "<br>$sta_orderid<br>");
		$sta_query=mysql_query($sta_str);
		$sta_re=mysql_fetch_array($sta_query);
		$status=$sta_re[0];
		//echo $status."<br>";
		if ($status==0)
		{		
				$order_info="select * from orders where orders_id=$sta_orderid";
				$order_info_query=mysql_query($order_info);
				$order_info_re=mysql_fetch_array($order_info_query);
				$customer_firstname=$order_info_re['customers_name'];
				$invoiceid=invoice_sitename.$sta_orderid;
				$currency_value=$order_info_re['currency_value'];
				$currency_code=$order_info_re['currency'];
				$order_date=tep_date_long($order_info_re['date_purchased']);

				$order_total_info="select * from orders_total where orders_id=$sta_orderid and class='ot_total'";
				$order_total_info_query=mysql_query($order_total_info);
				$order_total_info_re=mysql_fetch_array($order_total_info_query);
				$order_total=round($order_total_info_re['value']*$currency_value,2);

/* get order info end */

	
			$subject="Customer Support";
						$message='<p>Dear '.$customer_firstname.',</p>
<p>Thanks again for ordering at '.WEBSITE.'.</p>
<p>My name is Selina, and I will be your personal manager here at '.WEBSITE.'</p>
<p>I have noticed that you placed an order on '.$order_date.' for '.$currency_code.' '.$order_total.' including shipping, but we did not receive your payment yet.</p>
<p>'.$customer_firstname.', you can still send the payment for this order and activate the shipping process to your delivery address.</p>
<p>There are two possible payment methods you can use: </p>
<p>(1) PayPal<br>
  (a) Just click this link to send '.$currency_code.' '.$order_total.' to '.WEBSITENAME.':</p>
<p>https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business='.urlencode(business_email).'&amp;amount='.urlencode($order_total).'&amp;item_name=Invoice+ID%3A+'.$invoiceid.'&amp;currency_code='.$currency_code.'&amp;notify_url=http://www.'.WEBSITENAME.'/ext/modules/payment/paypal_ipn/ipn.php&amp;no_shipping=1&amp;pbtype=general&amp;bn=paywiz4mso-001.000&amp;mrb=R-4VT64848FL959270J <br>
</p>
<p>(2) Bank Account<br>
  1.If you have an account in a German bank, please transfer the money to</p>
<p>payment to:Account holder: Bin Li<br>
  Account number: 7387264005<br>
  Bank code: 10090000<br>
  Bank: Berliner-Volksbank eG,Germany </p>
<p>2.If you don&rsquo;t have an account in a German bank, please transfer the money to</p>
<p>our international bank account</p>
<p>Owner of account: Bin Li<br>
  Iban: DE35 1009 0000 7387 2640 05 <br>
  Bic/swift code: BEVODEBB <br>
  Bank: Berliner-Volksbank eG, Germany <br>
  Our Address: '.WEBSITENAME.' Corporation, Room 2101,21/F,Yat Chau building, 262 Des<br>
  Voeux Road Central, Hong Kong <br>
</p>
<p>If you have any questions, please contact us via email '.EMAIL.', stating your order number.</p>
<p>If you want to check your order and items, please Log into '.WEBSITE.' and click on &quot;My Account&quot;:<br>
  http://www.'.WEBSITENAME.'/login.php </p>
<p>If you have decided that you don\'t want these items any more, your order will be automatically cancelled after 20 days upon the ordering date.</p>
<p>If you want to make a new order feel free to visit the online shop now: <br>
  http://www.'.WEBSITENAME.'</p>
<p>Best regards,</p>
<p>Selina<br>
  http://www.'.WEBSITENAME.'</p>
<p>https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business='.urlencode(business_email).'&amp;amount='.urlencode($order_total).'&amp;item_name=Invoice+ID%3A+'.$invoiceid.'&amp;currency_code='.$currency_code.'&amp;notify_url=http://www.'.WEBSITENAME.'/ext/modules/payment/paypal_ipn/ipn.php&amp;no_shipping=1&amp;pbtype=general&amp;bn=paywiz4mso-001.000&amp;mrb=R-4VT64848FL959270J</p>';
			//$subject = $re->customers_name.":Customer Support";
			$arr_email[$i]=$re->customers_email_address;
			//echo($arr_email[$i] . '<br>'); //.$re->orders_id.'<br>');
			//send to paypal/update!
			//echo($arr_email[$i]."<br>");
			if(mail($arr_email[$i],$subject,$message,$headers))
			{
				echo($re->orders_id.' '.$arr_email[$i].'<br>');
				mysql_query("update orders set is_mailto=1 where orders_id=$sta_orderid") or die("update error!not update!");
				$i++;
			}	
		}
	}
	mysql_close($conn);
	return $i;
}

function mailto_nopay_check($dbserver,$dbuser,$dbpass,$db,$n)
{
	$str="select * from orders";
	$str.=" where is_mailto=0 and (`payment_method`='Check/Money Order') and (`orders_status`='1')";
	$str.=" and (to_days(current_date)-to_days(date_purchased)>$n) and (to_days(current_date)-to_days(date_purchased)<($n+3))";
	$conn=mysql_connect($dbserver,$dbuser,$dbpass) or die("databae error");
	//echo("<br><br><br>".$str);
	//$str="select * from orders where to_days('2005-10-14')-to_days(date_purchased)=1";
	//echo($str);
	mysql_select_db($db);
	
	$qu=mysql_query($str) or die("query error");
	$i=0;
	$from = EMAIL;
	//$headers = "From: $from";
	$headers = "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/html; charset=utf-8\n";
	$headers .= "From: $from\n";
	$headers .= "Reply-To: ".EMAIL."\n"; 

	while($re=mysql_fetch_object($qu))
	{
		if (check_had_pay($dbserver,$dbuser,$dbpass,$db,$re->customers_id,$n)) {update_ismailto($dbserver,$dbuser,$dbpass,$db,$re->customers_id,$n);continue;}
		$sta_orderid=$re->orders_id;
				$order_info="select * from orders where orders_id=$sta_orderid";
				$order_info_query=mysql_query($order_info);
				$order_info_re=mysql_fetch_array($order_info_query);
				$customer_firstname=$order_info_re['customers_name'];
				$invoiceid=invoice_sitename.$sta_orderid;
				$currency_value=$order_info_re['currency_value'];
				$currency_code=$order_info_re['currency'];
				$order_date=tep_date_long($order_info_re['date_purchased']);

				$order_total_info="select * from orders_total where orders_id=$sta_orderid and class='ot_total'";
				$order_total_info_query=mysql_query($order_total_info);
				$order_total_info_re=mysql_fetch_array($order_total_info_query);
				$order_total=round($order_total_info_re['value']*$currency_value,2);

/* get order info end */

	
			$subject="Customer Support";
						$message='<p>Dear '.$customer_firstname.',</p>
<p>Thanks again for ordering at '.WEBSITE.'.</p>
<p>My name is Selina, and I will be your personal manager here at '.WEBSITE.'</p>
<p>I have noticed that you placed an order on '.$order_date.' for '.$currency_code.' '.$order_total.' including shipping, but we did not receive your payment yet.</p>
<p>'.$customer_firstname.', you can still send the payment for this order and activate the shipping process to your delivery address.</p>
<p>There are two possible payment methods you can use: </p>
<p>(1) PayPal<br>
  (a) Just click this link to send '.$currency_code.' '.$order_total.' to '.WEBSITENAME.':</p>
<p>https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business='.urlencode(business_email).'&amp;amount='.urlencode($order_total).'&amp;item_name=Invoice+ID%3A+'.$invoiceid.'&amp;currency_code='.$currency_code.'&amp;notify_url=http://www.'.WEBSITENAME.'/ext/modules/payment/paypal_ipn/ipn.php&amp;no_shipping=1&amp;pbtype=general&amp;bn=paywiz4mso-001.000&amp;mrb=R-4VT64848FL959270J <br>
</p>
<p>(2) Bank Account<br>
  1.If you have an account in a German bank, please transfer the money to</p>
<p>payment to:Account holder: Bin Li<br>
  Account number: 7387264005<br>
  Bank code: 10090000<br>
  Bank: Berliner-Volksbank eG,Germany </p>
<p>2.If you don&rsquo;t have an account in a German bank, please transfer the money to</p>
<p>our international bank account</p>
<p>Owner of account: Bin Li<br>
  Iban: DE35 1009 0000 7387 2640 05 <br>
  Bic/swift code: BEVODEBB <br>
  Bank: Berliner-Volksbank eG, Germany <br>
  Our Address: '.WEBSITENAME.' Corporation, Room 2101,21/F,Yat Chau building, 262 Des<br>
  Voeux Road Central, Hong Kong <br>
</p>
<p>If you have any questions, please contact us via email '.EMAIL.', stating your order number.</p>
<p>If you want to check your order and items, please Log into '.WEBSITE.' and click on &quot;My Account&quot;:<br>
  http://www.'.WEBSITENAME.'/login.php </p>
<p>If you have decided that you don\'t want these items any more, your order will be automatically cancelled after 20 days upon the ordering date.</p>
<p>If you want to make a new order feel free to visit the online shop now: <br>
  http://www.'.WEBSITENAME.'</p>
<p>Best regards,</p>
<p>Selina<br>
  http://www.'.WEBSITENAME.'</p>
<p>https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business='.urlencode(business_email).'&amp;amount='.urlencode($order_total).'&amp;item_name=Invoice+ID%3A+'.$invoiceid.'&amp;currency_code='.$currency_code.'&amp;notify_url=http://www.'.WEBSITENAME.'/ext/modules/payment/paypal_ipn/ipn.php&amp;no_shipping=1&amp;pbtype=general&amp;bn=paywiz4mso-001.000&amp;mrb=R-4VT64848FL959270J</p>';
		//$subject = $re->customers_name.":Customer Support";
		$arr_email[$i]=$re->customers_email_address;
		//echo("send to check<br>update!<br>");
		//echo($arr_email[$i]."<br>");
		if (mail($arr_email[$i],$subject,$message,$headers))
		{
			echo($re->orders_id.' '.$arr_email[$i].'<br>');
			mysql_query("update orders set is_mailto=1 where orders_id=$sta_orderid") or die("update error!not update!");
			$i++;
		}
	}
	mysql_close($conn);
	return $i;
}
?>
</body>
</html>
