<?php
date_default_timezone_set('Australia/Sydney');
$label = 'Backup Database';
$homeFolder = 'attitudedancecen';
set_include_path('/home/'.$homeFolder.'/public_html/backup/');
$full_path = '/home/'.$homeFolder.'/public_html/backup'; 
							
// cron job commmand example: /opt/php52/bin/php-cgi /home/####/public_html/backup/index.php

$company            = 'Attitude Dance Centre';
$website            = 'attitudedancecentre.com.au'; //domain that this file resides on
$send_to            = 'info@attitudedancecentre.com.au';
//$send_to 		    = 'info@ignitemarketing.com.au';
$from 		        = 'postmaster@' . $website; // SMTP username
$SMTPpassword       = "+U,jzLA.6u7,"; // SMTP password



error_reporting(E_ALL);
?>
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
	<head>
		<title>Ignite Marketing Backup</title>
		<style type="text/css">body { background: #000; color: #0f0; font-family: \'Courier New\', Courier; }</style>
	</head>
	<body>
        <h2>Backing Up The Database</h2>
<?php



//require("phpmailer/class.phpmailer.php");
require 'phpmailer/PHPMailerAutoload.php';

function send_attachment($file){
	global $company, $from, $SMTPpassword, $send_to, $full_path;
    $fromCompany = 'Ignite Marketing';
    $mySubject = 'Database backup from '.$fromCompany;
    $companyPhone = '0408 826 455';
    $fromEmail = 'info@ignitemarketing.com.au';
    $domain = 'www.ignitemarketing.com.au';
    $shopAddress = '23 Dangar CCT Medowie 2318';
    $stationeryPrefix = 'ignite';
    $Host = 'localhost';
    $Port = 26;
    
    
    $stationeryHeader = "<body bgcolor='#999999' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><style>
    body {
          font-family: Arial;
           font-size: 12pt;
    }
    </style>
    <br>
    <table id='Table_01' border='0' cellpadding='0' align='center' bgcolor='#FFFFFF' width='800'>
    <tr><td colspan='3'><img src=\"cid:igniteHeader\" /></td></tr>
    <tr><td width='20'></td><td><br>";

    $stationeryFooter = "</td><td width='20'></td></tr>
    <tr><td></td><td><hr><span style='color:#666; line-height:150%;'>".$fromCompany."<br>Phone: ".$companyPhone."<br>".$fromEmail."<br>".$domain."</span></td><td></td></tr>
    <tr><td colspan='3'><img src=\"cid:igniteFooter\" /></td></tr>
    </table></body>";

	$mail = new PHPMailer();
	$mail->IsHTML(true);
	$mail->Host = $Host;
	$mail->Port = $Port;
	$mail->Username = $from; 
	$mail->Password = $SMTPpassword; 
	$mail->From = $fromEmail;
	$mail->FromName = $fromCompany;
	$mail->AddReplyTo($fromEmail, $company); //if the visitor replys to their message it will return to the vendor
	$mail->AddAddress($send_to, $company);//send a copy to the company receigving the backup
	//$mail->AddAddress('brent@flashme.com.au', 'Brent');//send a copy to me for testing
	$mail->Subject = $mySubject;
	$mail->WordWrap = 80;
	$mail->AddEmbeddedImage($full_path.'/images/igniteHeader.jpg', 'igniteHeader', 'igniteHeader.jpg');
	$mail->AddEmbeddedImage($full_path.'/images/igniteFooter.jpg', 'igniteFooter', 'igniteFooter.jpg');
	$mail->Body = $stationeryHeader;
	$mail->Body .= '<h1>Database Backup File</h1>
	<p>Dear '.$company.'</p>
    <p>Your website database backup file is attached.('.$file.')</p>
    <p>Please save that file for safe keeping.</p>';
	$mail->Body .= $stationeryFooter;
    $mail->addAttachment($file, $file); //$mail->addAttachment($path, $name, $encoding, $type);
	if(!$mail->Send()){
		$reportArray[0] = 'emailFailed';
		echo '<p>Message FAILED to '.$send_to.'</p>';
	}else{
		echo '<p>Message successfully sent to '.$send_to.'</p>';
	}//end if mail>send
}//end function sendMyEmail


$toDay = 'backup'.date('d-m-Y-H-i-s').'sql.gz';
$dbhost = 'localhost';
$dbname = 'attitudedancecen_wpr01';
$dbuser = 'attitudedancecen_ignite';
$dbpass = 'W)Og0O5AO%Bv';


exec("mysqldump --user=$dbuser --password='$dbpass' --host=$dbhost $dbname | gzip > ".$toDay);

send_attachment($toDay);

?>
    </body>
</html>

