<?php session_name('CAKEPHP'); session_start();
include('../exportconfig.php');
function GetValue($table, $condition, $field)
{
	global $db;
	$sql = mysqli_query($db, "select " . $field . " from " . $table . " where  $condition  ");
	$r = mysqli_fetch_array($sql);
	return ($r[$field]);
}
$leadRes = "Select * from crm_leads";
$data = '';
$data .= '<table width="100%"  border="0" cellpadding="2" cellspacing="1">
   <tr>
	<td width="10%" colspan="8"><center><h2>Report Lead Register</h2></center></td>
 	</tr>
	<tr>
		<td width="10%">SNo.</td>
		<td  width="10%">Lead No</td>
		<td width="10%">Date</td>
		<td width="10%">Subject   </td>
		<td  width="10%">Company Name </td>
		<td width="10%" >Contact Person Name</td>
		
		<td width="10%">Assigned user</td>
		<td  width="10%">Lead Type</td>
	</tr>';

$mainRes = mysqli_query($db, $leadRes);
while ($mainRow = mysqli_fetch_array($mainRes)) {

	$data .= '<tr>
<td >' . $i . '</td>
<td > ' . $mainRow['leadcode'] . '</td>
<td > ' . $mainRow['leads_date'] . '</td>
<td >' . $mainRow['lead_subject'] . ' </td>
<td >' . GetValue('clientmaster', "id='" . $mainRow['company_name'] . "'", 'c_name') . ' </td>
<td >' . $mainRow['contact_name'] . ' </td>';
	$user = explode(',', $mainRow['leaduserid']);
	$User1 = implode("','", $user);
	$Username = "select * from www_users where id IN('" . $User1 . "')";
	$UserSql = mysqli_query($db, $Username);
	$UserRow = mysqli_fetch_array($UserSql);

	$data .= '<td >' . $UserRow['userid'] . ' </td>';
	$data .= '<td >' . $mainRow['lead_status'] . '</td>
</tr>';

	$i++;
}

$data .= '</table>';
$header = '';
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=Report-LeadRegister.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
