<?php
ob_start();
include_once "../../common/connect.php";
include_once "../../common/db.php";
include_once "../../common/defines.php";
include_once "../../common/db_defines.php";

////////////////////// CORE FUNCTION | MODULE FUNCTION (c) i2d Technologies //////////////////////////////////
$rec_id = $_REQUEST['id'];
$refno = $rec_id;
$case="1";

$array_cols=array(id_col,company_name,address,owner_name,dotcom,ref,url);

$tdsettings=array(
	'table'=>i2d_table,
	'id_col'=>id_col,
	'fields_array'=>$array_cols,
	'status_vaue'=>'Active',
	'type'=>'1c',
	'where_col'=>id_col,
	'where_value'=>$rec_id,
	'ref_col'=>ref,
	'ref_value'=>"'market_entry'",
	'order'=>"ASC",
    'limit'=>1);

$printitem=db_fetch($tdsettings);



//$printitem=db_select_all3("leads","sys_leads_id",$rec_id);


foreach ($printitem as $item)
{
$company_name=$item[company_name];
$person_name=$item[owner_name];
$address=$item[address];
$domain1=(base64_decode($item[dotcom]));
}

$person_name=strtoupper($person_name);
$company_name=strtoupper($company_name);
$address=strtoupper($address);

$dated1=date("l F j, Y");
$dte = strtotime("+5 day");
$dated2= date("l F j, Y", $dte);

require_once('tcpdf_include.php');


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	//Page header
	public function Header() {
		// Logo
/*		if (count($this->pages) === 2) {
		$image_file = K_PATH_IMAGES.'2014.jpg';
		$this->Image($image_file, 10, 10, 190, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		// Set font
		$this->SetFont('helvetica', 'B', 20);}
		if (count($this->pages) === 1) {
		$img_file = K_PATH_IMAGES.'2gb.jpg';
        $this->Image($img_file, 0, 25, 210, 250, 'JPG', '', '', false, 300, 'C', false, false, 0);
		}
		if (count($this->pages) === 3) {
		$img_file = K_PATH_IMAGES.'1gbback.jpg';
        $this->Image($img_file, 0, 25, 210, 250, 'JPG', '', '', false, 300, 'C', false, false, 0);
		}
	*/	
		
		
		}

	// Page footer
	public function Footer() {
/* if (count($this->pages) === 2) {
	// Position at 15 mm from bottom
		$this->SetY(-15);
		
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
		$image_file = K_PATH_IMAGES.'2015.jpg';
		$this->Image($image_file, 10, 250, 190, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		
	}
	*/
	
	}
	
	
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('i2d Technologies');
$pdf->SetTitle('i2d Hosting Invoice-'.$rec_id);
$pdf->SetSubject('Cloud Linux Hosting');
$pdf->SetKeywords('web hosting');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------
$you90="67811";
// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 9);

// add a page

//$pdf->AddPage();

//$pdf->Image('images/2gb.jpg', 15, 140, 75, 113, 'JPG', '', '', true, 150, '', false, false, false, false, false);


// create some HTML content

$pdf->AddPage();

// create some HTML content




/// PART 2

$html = '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>

<table width="660" border="0" align="center" cellpadding="2" cellspacing="2">
  <tr>
    <td colspan="2" align="right"></td>
  </tr>
  <tr>
    <td width="412" rowspan="3"><p align="left"><br /><br /><br />ATTN : <br />
      '. $person_name .'<br />
      '. $company_name .'<br />
      '. $address .',<br /></p></td>
    <td width="252" align="right">
	<h2>INVOICE :
	<br /><u>WEB REGISTRATION</u></h2>
	<br />
	<h4>Tracking / Ref: CL-101'. $refno .'</h4></td>
  </tr>
  <tr>
    <td align="right">Dated :  '. $dated1 .'<br />
	Valid Till :  '. $dated2 .'
	</td>
  </tr>
</table>


<table width="660" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" color="#111111">
  <tr>
  

    <td align="center"><br /><br /><br />
    <h2>'. $domain1 .'</h2><b>(*available for purchase on '. $dated1 .')</b></td>
  </tr>
	 <tr>
     <td align="left">&nbsp;</td>
    </tr>
</table>


<table width="660" border="0" align="center" cellpadding="10" cellspacing="1">
  <tr>
  <td colspan="2" align="center"></td>
  </tr>
  <tr>
    <td align="left" bgcolor="#000000"><p style="color:white;"><strong>Package Name</strong></p></td>
    <td align="right" bgcolor="#000000"><p style="color:white;"><strong>Payment Details* (In case of Online / Cheque)</strong></p></td>
  </tr>
  <tr>
    <td align="left"><br /><ul>
      <li><b>Cloud Linux 500 MB (12 Months Subscription)</b></li>
      <li><b>.com</b> Internet Brand Name (12 Months Validity)</li>
      <li>Unlimited Branded Email Redirects to (Gmail , Hotmail , Yahoo etc.)</li>
      <li>Email App</li>
      <li>Secured & PIN Code Based Web Space Control Panel</li>
      <li>12 Months ONLINE Support</li>
         </ul>
    <p></p></td>
    <td align="right"><br /><br />Pay to Company Account Title:<br />
<b>"i2d Technologies"</b><br />
<b>Account No. : 0408-1004458344</b><br />
Bank ALFALAH Ltd.<br /> Hub Commercial Branch, Bahria Town Phase-8.<br /> Rawalpindi.</td>
  </tr>
  
    <tr>
    <td align="center" style="border-top: 1px solid black; border-bottom: 1px solid black;"><h4>&nbsp;&nbsp;&nbsp;Total Charges :</h4></td>
    <td align="center" style="border-top: 1px solid black; border-bottom: 1px solid black;"><h4>PKR : 6,500 / Year</h4></td>
  </tr>
  <tr>
      <td align="left"><b>*IMPORTANT NOTE : Domain Availability is subject to International Market Purchases & Global Company Name Competition</b></td>
      <td align="left"></td>
  </tr>
  <tr>
    <td align="left"><img src="images/i2dbar.png"></td>
    <td align="right"><h4><i>Prepared By :</i><br/>
      i2d Billing & Accounts<br />
      billing@i2dtechnologies.com</h4></td>
  </tr>
</table>

<!--HEY-->
';

// output the HTML content
$pdf->writeHTML(utf8_encode($html), true, 0, true, 0);
   
//$pdf->AddPage();
// reset pointer to the last page
$pdf->lastPage();

$file="i2d_hosting_invoice"."-".$refno."-".$domain1."-".$dated1.".pdf";

// ---------------------------------------------------------

if($case=="1"){//Close and output PDF document
ob_end_clean();
$pdf->Output($file , 'I');}

if($case=="2"){
	// force print dialog
$js = 'print(true);';

// set javascript
$pdf->IncludeJS($js);
ob_end_clean();
//Close and output PDF document
$pdf->Output($file , 'I');
	
}



//============================================================+
// END OF FILE
//============================================================+


/////////////////////////// function ends /////////////////////////////////












?>