<?php session_start();
ob_start();
?>

<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

ini_set('memory_limit', '512M');


	include("../php/configi.php");

$reportemailto 			= $_REQUEST['reportemailto'];
$reportemailsubject 	=  $_REQUEST['reportemailsubject'];
$reportemailmessage 	=  $_REQUEST['reportemailmessage'];
$reportcompname		 	=  $_REQUEST['reportcompname'];

$supp_id		 		=  $_REQUEST['supp_id'];

$reportemailto 			= $reportemailto;
$reportemailsubject 	= $reportemailsubject;
$reportemailmessage 	= $reportemailmessage."&nbsp;";
$reportcompname		 	= $reportcompname;

$reportemailto 			= str_replace("#$#$#$?", "&", $reportemailto);
$reportemailsubject 	= str_replace("#$#$#$?", "&", $reportemailsubject);
$reportemailmessage 	= str_replace("#$#$#$?", "&", $reportemailmessage);
$reportcompname		 	= str_replace("#$#$#$?", "&", $reportcompname);

//echo "Search option is " . $search_option;


//echo $_REQUEST['suppid'];
//$suppid =  $_REQUEST['suppid'];

//695

$ac = 0;



$msg = "";



	$query_pag_data = "select * from " . $_COOKIE["phxcrmclient_id"] . "_client where uid_client = " . $supp_id;

//	echo $query_pag_data;

$result_pag_data = mysqli_query($conn, $query_pag_data);
while ($row = mysqli_fetch_array($result_pag_data)) {
$prod_suppname = $row["comp_name"];
}
	

$msg = "";

$report =  '<table style="width: 735px">
<tr>
  <td class="auto-style1"><img src="http://app.phoenixcrm.co.nz/crm/images/logo/142.jpg"/></td>
  <td valign="top">I Love Labels<br />
      5 Margaret Rd<br />
      Raumati Beach<br />
      Ph: (027) 578 1692 <br />
      email: <a href="mailto:info@ilovelabels.nz">info@ilovelabels.nz</a><br />
    </td>
</tr>
<tr>
  <td class="auto-style1">&nbsp;</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td style="text-align: center; font-size: 16px;" colspan="2">Active Items Report</td>
</tr>
<tr>
  <td style="text-align: center;" colspan="2"><span style="font-size: 14px;">Supplier of goods: ' . $prod_suppname . ' </span> </td>
</tr>
<tr>
<td>
<br>
<br>
</td>
</tr>

</table>



<table border="0" bgcolor="white">

<tr>
<td width="50px" valign="top">

</td>

<td width="80px" valign="top" align="left">
Prod Code:
</td>

<td width="300px" valign="top" align="left">
Title:
</td>
<td width="80px" valign="top" align="left">
Buy price for you$:
</td>
<td width="80px" valign="top" align="left">
Status:
</td>
<td width="80px" valign="top" align="left">
Received Date:
</td>

</tr>


<tr>

 ';



$i = 0;
$d = 0;
 
		$query_pag_data = "select * from " . $_COOKIE["phxcrmclient_id"] . "_prod_search where prod_suppid = " . $supp_id . " and prod_status = 'Active' order by sel_uid desc";

//	$report = $report .  $query_pag_data;
//echo $query_pag_data;
 
$i2 = 1;
$result_pag_data = mysqli_query($conn, $query_pag_data);
while ($row = mysqli_fetch_array($result_pag_data)) {
 // echo "row";
 
 				  $prod_date_received2 = date('d-m-Y', strtotime($row["prod_date_received"])); 

  $payvar = "";


  $report = $report . ' <tr>
  <td>
</td>


<td width="60px" valign="top">

' .  $row["sel_uid"] . ' 
		
			</td>

<td  width="200px" valign="top">

  ' .  $row["title"] . '

			</td>
			
			
			

						   <td valign="top">
			

						   
				$ ' . number_format($row["prod_cost_price"],2,".",",") . '

			
			</td>
						   <td valign="top">
	
			' . $row["prod_status"] . '
				
			</td>
									   <td valign="top">
	
			' . $prod_date_received2 . '
				
			</td>

</tr>  </tr>';
 
  


  $i2 = $i2 + 1;
  

  $i = $i + 1;
  
  }

  
 $report = $report . ' </table>    <br>     <br>   <br>';


 
  $i2 = $i2 + 1;
  
  $i = $i + 1;
  

 $report = $report . '</tbody> </table>';


/* --------------------------------------------- */
//echo $report;
//==============================================================
//==============================================================
//==============================================================
//echo $report;


$uid = md5(uniqid(time())); 

$uid = md5(uniqid(time())); 
$filename = 'activereport.pdf';

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;



include("mpdflatest/mpdf.php");


$mpdf=new mPDF('','', 0, '', 6, 6, 10, 10, 9, 9, 'P');

$mpdf->SetDisplayMode('fullpage');

$mpdf->WriteHTML($report);	// Separate Paragraphs  defined by font

//$content = $mpdf->Output('', 'S');

$content = $mpdf->Output($filename, 'F');

//$content = chunk_split(base64_encode($content));

//$filename2 = 'termsandconditions.pdf';

 
require 'PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.ilovelabels.nz";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";

$mail->Username = "info@ilovelabels.nz";
//Password to use for SMTP authentication
$mail->Password = "2021ilovelabels!";


//$mail->SMTPSecure = "ssl";$mail->Username = "ilovelabels@phoenixsoftware.co";//Password to use for SMTP authentication$mail->Password = "Ilovelabels1";
//Set who the message is to be sent from
//echo "point3";
$mail->setFrom("info@ilovelabels.nz", "Coral");
//Set an alternative reply-to address
$mail->addReplyTo("info@ilovelabels.nz", "Coral");
//Set who the message is to be sent to
$mail->addAddress($reportemailto);
$mail->AddCC("info@ilovelabels.nz");
//Set the subject line
$mail->Subject = $reportemailsubject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($reportemailmessage);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment($filename);
//$mail->addAttachment($filename2);
//send the message, check for errors

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message Sent";
}
exit;