<?php
session_start();
$companyname=$_SESSION['companyname'];
$adminemailid=$_SESSION['emailid'];
if(($adminemailid !="")&&($companyname!="")){
require_once('../Control/address.php');
$objaddress=new addressctrl();
require_once('../Control/sales.php');
$objsales=new salesctrl();
require_once('../Control/contact.php');
$objcontact=new contactctrl();
?>

<!doctype html>
<html>
<head>

<link rel="icon" href="../Images/cloud-icon-27.png">
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  
     
    <!-- data Table -->
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/buttons.bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/dataTables.bootstrap.min.css"/>

<!-- Hide Some Data In + symbol -->
<!--<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/bootstrap.3.3.7.min.css"/>
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/Css/dataTables.bootstrap.1.10.13.min.css"/>-->
<link rel="stylesheet" type="text/css" href="http://www.fieldcloud.in/Web/DataTable/hide/responsive.bootstrap.min.css"/>

<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/jszip.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/pdfmake.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/vfs_fonts.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.html5.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.print.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/Js/buttons.colVis.min.js"></script>

<!-- Hide Some Data In + symbol -->
<!--<script type="text/javascript" src="//code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js"></script>-->
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/hide/dataTables.responsive.min.js"></script>
<script type="text/javascript" src="http://www.fieldcloud.in/Web/DataTable/hide/responsive.bootstrap.min.js"></script>
  

<script>
$(document).ready(function() {
    var table = $('#example').DataTable( {
"order": [[ 11, 'desc' ]],
//"aLengthMenu": [[10, 20, 40, 80, 160, -1] , ["10/page", "20/page", "40/page", "80/page", "160/page" , "All"]],
"dom": "<'row'<'col-md-2'l><'col-md-7'B><'col-md-3'f>><'row'<'col-md-12't>><'row'<'col-md-6'i><'col-md-6'p>>",/*<'row'<'col-md-12't>><'row'<'col-md-12'i>>*/
"processing": true,
       "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],

        buttons: [ 'copy', 'excel','csv', 'pdf','print', 'colvis' ]
       
    } );
 
    table.buttons().container()
        .appendTo( '#example_wrapper .col-sm-6:eq(0)' );
} );

</script>
<style>
body {
    font-family: "Calibri ",Helvetica,Arial,sans-serif;
    font-size: 10px;
    line-height: 1.42857143;
    color: #333;
    background-color: #fff;
}
</style>

<style>


/* 
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
@media 
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)  {

	/* Force table to not be like tables anymore */
	table, thead, tbody, th, td, tr { 
		display: block; 
	}
	
	/* Hide table headers (but not display: none;, for accessibility) */
	thead tr { 
		position: absolute;
		top: -9999px;
		left: -9999px;
	}
	
	tr { border: 1px solid #ccc; }
	
	
	
	td { 
		/* Behave  like a "row" */
		border: none;
		border-bottom: 1px solid #eee; 
		position: relative;
		padding-left: 50%; 
	}
	
	td:before { 
		
	}
	
	/*
	Label the data
	*/
	td:nth-of-type(1):before { content: "Name: "; }
	td:nth-of-type(2):before { content: "Name: "; }
	td:nth-of-type(3):before { content: "Organization: "; }
	td:nth-of-type(4):before { content: "Emailid: "; }
	td:nth-of-type(5):before { content: "Phone Number: "; }
	td:nth-of-type(6):before { content: "Url: "; }
	td:nth-of-type(7):before { content: "Address "; }
	td:nth-of-type(8):before { content: "Status "; }
	td:nth-of-type(9):before { content: "Tag "; }
	td:nth-of-type(10):before { content: "Lead Scource "; }
	td:nth-of-type(11):before { content: "Birthday "; }
	td:nth-of-type(12):before { content: "Date & Time "; }
}
</style>
<script>
    $(document).on("click", "#addcontactpagecont", function(){
        //alert("hi");
       window.location.assign("employee_addcontactpage.php"); 
    });
</script>
</head>
<body> 
<div class="edit">
<div class="view" style="padding-top:20px;">
<div style="margin:50px 10px 10px 10px;border-style: solid;">
<div class="navbar-inverse">

<span style="color:white;padding-top: 5%;"><i style="align:center;font-size:2em;">List Contact</i><span style="cursor:pointer" id="addcontactpagecont"><img src="../../Images/add.jpg" class="img-circle pull-right" style="align:right;" width="30px" height="30px"></span><br></span>
</div>


<div style="padding:3%;">
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%" style="font-family: 'Calibri',Helvetica,Arial,sans-serif;
    font-size: 10px;">
				<thead >
					<tr><b>
					    <th></th>
                        <th style="align: center;"><center>Name</center></th>        
                        <th style="align: center;"><center>Organization</center></th>
                        <th style="align: center;"><center>Emailid</center></th>
                        <th style="align: center;"><center>Phone Number</center></th>
                        <th style="align: center;"><center>Url</center></th>
                        <th style="align: center;"><center>Address</center></th>
                        <th style="align: center;"><center>Status</center></th>
                        <th style="align: center;"><center>Tag</center></th>
                        <th style="align: center;"><center>Lead Scource</center></th>
                        <th style="align: center;"><center>Birthday</center></th>
                        <th style="align: center;"><center>Date & Time</center></th>

 					</b></tr>
				</thead>
<tbody>
	
<?php
$resultcontact=$objsales->salesselectallemployee($companyname, $adminemailid, "sales_contact", "no");
//print_r($resultcontact);
//echo $resultcontact->rowcount();
foreach($resultcontact as $rowcontact){
    $cont_id=$rowcontact['cont_id'];
    $cont_name_title="";
    $cont_name_title=$rowcontact['cont_name_title'];
    $cont_first_name="";
    $cont_first_name=$rowcontact['cont_first_name'];
    $cont_last_name="";
    $cont_last_name=$rowcontact['cont_last_name'];
    $cont_job_title="";
    $cont_job_title=$rowcontact['cont_job_title'];
    $cont_address_line="";
    $cont_address_line=$rowcontact['cont_address_line'];
    $cont_address_city="";
    $cont_address_city=$rowcontact['cont_address_city'];
    $cont_address_state="";
    $cont_address_state=$rowcontact['cont_address_state'];
    $cont_address_country="";
    $cont_address_country=$rowcontact['cont_address_country'];
    $cont_address_pincode="";
    $cont_address_pincode=$rowcontact['cont_address_pincode'];
    $cont_status="";
    $cont_status=$rowcontact['cont_status'];
    $cont_tag="";
    $cont_tag=$rowcontact['cont_tag'];
    $cont_lead_source="";
    $cont_lead_source=$rowcontact['cont_lead_source'];
    $cont_background="";
    $cont_background=$rowcontact['cont_background'];
    $cont_owner="";
    $cont_owner=$rowcontact['cont_owner'];
    $cont_make_private="";
    $cont_make_private=$rowcontact['cont_make_private'];
    $cont_birthdate="";
    $cont_birthdate=$rowcontact['cont_birthdate'];
    $cont_datetime="";
    $cont_datetime=$rowcontact['cont_datetime'];
    
$resultorganization=$objsales->salesselectcontid("sales_organization", $cont_id);
//print_r($resultorganization);
$org_name="";
foreach($resultorganization as $roworganization){
    $org_id=$roworganization['org_id'];
    $org_name=$roworganization['org_name'];
    $org_desc=$roworganization['org_desc'];
    $org_phone=$roworganization['org_phone'];
    $org_url=$roworganization['org_url'];
    $org_add=$roworganization['org_add'];
    $org_city=$roworganization['org_city'];
    $org_state=$roworganization['org_state'];
    $org_country=$roworganization['org_country'];
    $org_pincode=$roworganization['org_pincode'];
    $org_created_by=$roworganization['org_created_by'];
    $org_created_type=$roworganization['org_created_type'];
    $org_datetime=$roworganization['org_datetime'];
}
?>
				

					<tr>
                    <td><img src="../../Images/editicon.jpg" width="20px" height="20px" style="cursor: pointer;" title="Edit Contact" class="sample" id="<?php echo $cont_id?>,1">
                    <br><img src="../../Images/document.png" width="20px" height="20px" style="cursor: pointer;" title="View Contact" class="sample" id="<?php echo $cont_id;?>,2">
                    <br><img src="../../Images/close.png" width="20px" height="20px" style="cursor: pointer;" title="Delete Contact" class="sample" id="<?php echo $cont_id;?>,3"></td>
                    
                    <td><?php echo $cont_name_title."<br>".$cont_first_name."<br>".$cont_last_name;?></td>
                    <td><?php echo $org_name;?></td>
                    <td><?php
    
$resultemail=$objsales->salesselectcontid("sales_email", $cont_id);
//print_r($resultorganization);
foreach($resultemail as $rowemail){
echo $rowemail['email_name']."<br>";
}
?></td>
                    <td><?php
    
$resultphone=$objsales->salesselectcontid("sales_phone", $cont_id);
//print_r($resultorganization);
foreach($resultphone as $rowphone){
echo $rowphone['phone_number']."<br>";
}
?></td>
                    <td><?php
    
$resulturl=$objsales->salesselectcontid("sales_url", $cont_id);
//print_r($resultorganization);
foreach($resulturl as $rowurl){
echo $rowurl['url_name']."<br>";
}
?></td>
                    <td><?php echo $cont_address_line."<br>".$cont_address_city."<br>".$cont_address_state."<br>".$cont_address_country."-".$cont_address_pincode;?></td>
                    <td><?php 
$resultstatus=$objsales->salesselectedid("sales_status", $cont_status);
//print_r($resultorganization);
foreach($resultstatus as $rowstatus){
echo $rowstatus['status_name'];
}
?></td>
                    <td><?php 
$resulttag=$objsales->salesselectedid("sales_tag", $cont_tag);
//print_r($resultorganization);
foreach($resulttag as $rowtag){
echo $rowtag['tag_name'];
} 
?></td>
                    <td><?php 
$resultlead_source=$objsales->salesselectedid("sales_lead_source", $cont_lead_source);
//print_r($resultorganization);
foreach($resultlead_source as $rowlead_source){
echo $rowlead_source['lead_name'];
}  
?></td>
                    <td><?php if(($cont_birthdate!="")&&($cont_birthdate!="0000-00-00")){ echo $cont_birthdate; }?></td>
                    <td><?php echo $cont_datetime;?></td>
						



					</tr>

<?php
}
?>
				</tbody>
			</table>
<script>
$(function() {
//$(".sample").click(function() {
$('#example tbody').on('click', '.sample', function () {
var element = $(this);
var rowid = element.attr("id");
var row=rowid.split(",");
//alert(row[1]);
if(row[1]==2){
   conid=row[0];
$.ajax({

	  type: "POST",
	  url: "viewcontact.php",
	  data:{sales_contact_id: conid},
	   success: function(respond){
	       //alert(respond);
	      $('.edit').html(respond);
		// alert(rowid)
	        }
	});
}
if(row[1]==1){
   conid=row[0];
$.ajax({

	  type: "POST",
	  url: "updatecontact.php",
	  data:{sales_contact_id: conid},
	   success: function(respond){
	       //alert(respond);
	      $('.edit').html(respond);
		// alert(rowid)
	        }
	});
}
//alert('PENDING ISSUES OF :   '+ rowid);

});
});



</script>
</div>
			</div>
	</div>
</div>

<?php
}else{
echo "<script> location.replace('http://fieldcloud.in/Login.php') </script>";
}?>