 <script>
$(function() {
$( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
$( "#tabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
});
</script>
<style>
.ui-tabs-vertical { width: 45em; }
.ui-tabs-vertical .ui-tabs-nav { padding: .2em .1em .2em .2em; float: left; width: 12em; }
.ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; }
.ui-tabs-vertical .ui-tabs-nav li a { display:block; }
.ui-tabs-vertical .ui-tabs-nav li.ui-tabs-active { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; border-right-width: 1px; }
.ui-tabs-vertical .ui-tabs-panel { padding: 1em; float: right; width: 39em; padding-top:0;}
</style>
<?
	$res=mysql_query("select * from invoices where id='".$_SESSION['invoice']."'")or die(mysql_error());
		$info=mysql_fetch_array($res);
			$_GET['id']=$_SESSION['invoice'];
			include "inc/invoice_save.php";
			
	if(isset($_POST['sendinvoice'])){
			$link="http://".$_SERVER['HTTP_HOST'].str_replace('add.php','',$_SERVER['SCRIPT_NAME'])."inc/invoicehtml.php?id=".encrypt($_SESSION['invoice']."-".md5($_SESSION['invoice']));
			$_POST['mesajul']=str_replace("[LINK]","<a href='".$link."'>".$link."</a>",$_POST['message']);
				
		$to=$_POST['to'];
		if($to==''){
			echo "<div class='errormsg'>Please enter a valid Email</div>";
		}else{
			$subject=$_POST['subject'];
			$message=$_POST['mesajul'];
			
			$invoiceloc=str_replace(array('inc','mobile/'),'',dirname(__FILE__))."inc/invoices/".$_SESSION['invoice'].".pdf";
			if(mailer($to,$subject,$message,$invoiceloc)){
				echo "<div class='successmsg'>Email has been Sent</div>";
			}else{
				echo "<div class='errormsg'>Oops! Something went wrong!</div>";
			}
		}	
}
		
?>
<?if(1==0){?>
<table align='center' style='margin-top:40px; margin-bottom:40px;'>
	<tr>
		<td class='alldone' onclick="window.open('inc/invoicepdf.php?id=<?=encrypt($_SESSION['invoice']."-".md5($_SESSION['invoice']))?>')"><img src='style/images/save_pdf.png'/><br>Download PDF</td>
		<td class='alldone' onclick="window.open('inc/invoicehtml.php?id=<?=encrypt($_SESSION['invoice']."-".md5($_SESSION['invoice']))?>')"><img src='style/images/save_html.png'/><br>View HTML</td>
	</tr>
	<tr>
	<td class='alldone' colspan='2' onclick="$('#emailtoclient').slideDown(); 	$('html, body').animate({scrollTop: 300}, 1000);"><img src='style/images/send_email.png' style='width:120px;'/><br>Send as Attachment via Email</td>
	</tr>	
</table>
<form action='' method='post'>
<table width='310' style='background:#fff; display:none;' align='center' id='emailtoclient'>
	<tr>
		<td>Subject:</td>
		<td><input type='text' class='settings' style='width:235px;' name='subject' value='Invoice #<?=$_SESSION['invoice']?> from <?=$cfg['name']?>'></td>
	</tr>	
	<tr>
		<td>To:</td>
		<td><input type='text' class='settings' style='width:235px;' name='to' value='<?=$info['client_email']?>'></td>
	</tr>	
	<tr>
		<td colspan='2'><textarea class='settings' name='message' style='widtH:300px; height:200px;'>Dear <?=$info['client_name']?>,
We have attached an invoice in the amount of <?=$info['total']?><?=$info['currency']?>.
			
You may pay, view and print the invoice online by visiting the following link: 
http://<?=$_SERVER['HTTP_HOST']?><?=str_replace('add.php','',$_SERVER['SCRIPT_NAME'])?>inc/invoicehtml.php?id=<?=encrypt($_SESSION['invoice']."-".md5($_SESSION['invoice']))?>			
Best Regards,
<?=$cfg['name']?>
		</textarea></td>
	</tr>
	<tr>
		<td colspan='2' align='center'><input type='submit' name='sendinvoice' class='button' value='Email invoice to Client'/></td>
	</tr>
</table>
</form>
<?}?>

<div id="tabs" style='border:0; width:100%;'>
	<ul>
		<li><a href="#tabs-1">Download PDF</a></li>
		<li><a href="#tabs-2">View HTML</a></li>
		<li><a href="#tabs-3">Send Email</a></li>
	</ul>
	<div id="tabs-1">
		<h2>View PDF <div style='float:right;'><a href='inc/invoices/<?=$_SESSION['invoice']?>.pdf' target='_blank' style='color:red; text-decoration:none;'>Open in new file</a></div></h2>
		<iframe src='inc/invoices/<?=$_SESSION['invoice']?>.pdf' style='width:100%; height:600px;' frameborder='0'></iframe>
	</div>
	<div id="tabs-2">
		<h2>View HTML <div style='float:right;'><a href='inc/invoicehtml.php?id=<?=encrypt($_SESSION['invoice']."-".md5($_SESSION['invoice']))?>' target='_blank' style='color:red; text-decoration:none;'>Open in new file</a></div></h2>
		<iframe src='inc/invoicehtml.php?id=<?=encrypt($_SESSION['invoice']."-".md5($_SESSION['invoice']))?>' style='width:100%; height:600px;' frameborder='0'></iframe>
	</div>
	<div id="tabs-3">
		<h2>Send email</h2>
		<form action='' method='post'>
<table width='310' align='center' id='emailtoclient'>
	<tr>
		<td>Subject:</td>
		<td><input type='text' class='settings' style='width:435px;' name='subject' value='Invoice #<?=$_SESSION['invoice']?> from <?=$cfg['name']?>'></td>
	</tr>	
	<tr>
		<td>To:</td>
		<td><input type='text' class='settings' style='width:435px;' name='to' value='<?=$info['client_email']?>'></td>
	</tr>	
	<tr>
		<td colspan='2'><textarea class='settings' name='message' style='widtH:492px; height:200px;'>Dear <?=$info['client_name']?>,
We have attached an invoice in the amount of <?=$info['total']?><?=$info['currency']?>.
			
You may pay, view and print the invoice online by visiting the following link: 
[LINK]
		
Best Regards,
<?=$cfg['name']?>
		</textarea></td>
	</tr>
	<tr>
		<td colspan='2' align='center'><input type='submit' name='sendinvoice' class='button' value='Email invoice to Client'/></td>
	</tr>
</table>
</form>
	</div>
</div>