<?php 
session_start();
include '../db.php';
include("../all_query.php");
error_reporting(0);
include('common_header_file.php');

 if(isset($_SESSION['loan_crm_username']) && isset($_SESSION['loan_crm_password']))
{
	
	?>
	
	
<!DOCTYPE html>
 
<html lang="en" class="light-style layout-navbar-fixed layout-menu-fixed " dir="ltr" data-theme="theme-bordered" data-assets-path="../assets/" data-template="vertical-menu-template-bordered">
 
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />

    <title>CRM</title>
     
    <meta name="description" content="Start your development with a Dashboard for Bootstrap 5" />
    <meta name="keywords" content="dashboard, bootstrap 5 dashboard, bootstrap 5 design, bootstrap 5">
    <!-- Canonical SEO -->
    <link rel="canonical" href="https://1.envato.market/frest_admin">
    
    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="https://pixinvent.com/demo/frest-clean-bootstrap-admin-dashboard-template/assets/img/favicon/favicon.ico" />

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com/">
    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&amp;family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&amp;display=swap" rel="stylesheet">

    <!-- Icons -->
    <link rel="stylesheet" href="../assets/vendor/fonts/boxicons.css" />
    <link rel="stylesheet" href="../assets/vendor/fonts/fontawesome.css" />
    <link rel="stylesheet" href="../assets/vendor/fonts/flag-icons.css" />

    <!-- Core CSS -->
    <link rel="stylesheet" href="../assets/vendor/css/rtl/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="../assets/vendor/css/rtl/theme-bordered.css" class="template-customizer-theme-css" />
    <link rel="stylesheet" href="../assets/css/demo.css" />

    <!-- Vendors CSS -->
    <link rel="stylesheet" href="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
    <link rel="stylesheet" href="../assets/vendor/libs/typeahead-js/typeahead.css" />
    <link rel="stylesheet" href="../assets/vendor/libs/datatables-bs5/datatables.bootstrap5.css">
<link rel="stylesheet" href="../assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.css">
<link rel="stylesheet" href="../assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.css">


   
   
  <link rel="stylesheet" href="../assets/vendor/libs/select2/select2.css" />

		 
		 
    <!-- Page CSS -->
    
    <!-- Helpers -->
    <script src="../assets/vendor/js/helpers.js"></script>

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   
   
    <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
    <!--? Template customizer: To hide customizer set displayCustomizer value false in config.js.  -->
     <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
    <script src="../assets/js/config.js"></script>
	
		
	
	 <link rel="stylesheet" href="../assets/vendor/libs/toastr/toastr.css" />
	 <link rel="stylesheet" href="../assets/vendor/libs/animate-css/animate.css" />
<link rel="stylesheet" href="../assets/vendor/libs/sweetalert2/sweetalert2.css" />



	 
	  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js" integrity="sha384-FzT3vTVGXqf7wRfy8k4BiyzvbNfeYjK+frTVqZeNDFl8woCbF0CYG6g2fMEFFo/i" crossorigin="anonymous"></script>
   <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-JAW99MJVpJBGcbzEuXk4Az05s/XyDdBomFqNlM3ic+I=" crossorigin="anonymous"></script>
	
	
    	
   

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async="async" src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
    <script>
    window.dataLayer = window.dataLayer || [];

    function gtag() {
      dataLayer.push(arguments);
    }
    gtag('js', new Date());
    gtag('config', 'GA_MEASUREMENT_ID');
    </script>
    <!-- Custom notification for demo -->
    <!-- beautify ignore:end -->
</head>

<body>

  <!-- Layout wrapper -->
<div class="layout-wrapper layout-content-navbar  ">
  <div class="layout-container">

    
    




<!-- Menu -->

<?php include('left_sidebar.php'); ?>

<!-- / Menu -->

    

    <!-- Layout container -->
    <div class="layout-page">
      
      



<!-- Navbar -->

  
<?php include('header.php'); ?>



    <style>
	
	.mailbox .chat-scroll {
    height: calc(100vh - 100px);
}
.mailbox .message-center {
     overflow: auto;
    position: relative;
}


.mailbox .message-center .message-item {
    border-bottom: 1px solid #e9ecef;
    display: block;
    text-decoration: none;
    padding: 9px 15px;
}
ul.list-style-none li a {
    color: #3e5569;
    padding: 8px 0;
    display: block;
    text-decoration: none;
}
 
 .mailbox .message-center .message-item .mail-contnet {
    display: inline-block;
    width: 75%;
    padding-left: 10px;
    vertical-align: middle;
}
* {
    outline: 0;
}

.mailbox .message-center .message-item .user-img {
    width: 40px;
    position: relative;
    display: inline-block;
    margin: 0 0 15px 0;
}

.message_title
{
	font-size:14px !important;
}



.chat-list .chat-item .chat-content {
    width: calc(100% - 50px);
    display: inline-block;
    padding-left: 15px;
}



.scrollable {
    position: relative;
}
.chat-box .chat.active-chat {
    display: block;
}
.chat-box .chat {
    display: none;
}
.chat-list {
    margin: 0;
    padding: 0;
}
.chat-list {
    margin: 0;
    padding: 0;
}

.chat-list .chat-item {
    list-style: none;
    margin-top: 30px;
}


.chat-list .chat-item .chat-img {
    display: inline-block;
    width: 45px;
    vertical-align: top;
}


.chat-list .chat-item .chat-content {
    width: calc(100% - 50px);
    display: inline-block;
    padding-left: 15px;
}


.chat-list .chat-item .chat-time {
    display: block;
    font-size: 10px;
    color: #4f5467;
    margin: 5px 0 15px 65px;
}


.chat-list .chat-item.odd+.odd {
    margin-top: 0;
}


.chat-list .chat-item .chat-content .box {
    display: inline-block;
    padding: 10px;
    margin-bottom: 3px;
    color: #343a40;
    background: #f8f9fa;
}
.box {
    border-radius: 4px;
    padding: 10px;
}
.bg-light {
    --bs-bg-opacity: 1;
    background-color: rgba(var(--bs-light-rgb),var(--bs-bg-opacity))!important;
}


.chat-list .chat-item.odd .box {
    clear: both;
    color: #fff;
    background: #2962ff;
}
.chat-list .chat-item .chat-content .box {
    display: inline-block;
    padding: 10px;
    margin-bottom: 3px;
    color: #343a40;
    background: #f8f9fa;
}
.box {
    border-radius: 4px;
    padding: 10px;
}


.chat-list .chat-item.odd .box {
    clear: both;
    color: #fff;
    background: #2962ff;
}
.chat-list .chat-item .chat-content .box {
    display: inline-block;
    padding: 10px;
    margin-bottom: 3px;
    color: #343a40;
    background: #f8f9fa;
}


.chat-list .chat-item.odd .box {
    clear: both;
    color: #fff;
    background: #2962ff;
}
.chat-list .chat-item .chat-content .box {
    display: inline-block;
    padding: 10px;
    margin-bottom: 3px;
    color: #343a40;
    background: #f8f9fa;
}
.box {
    border-radius: 4px;
    padding: 10px;
}


.chat-list .chat-item.odd .chat-content {
    text-align: right;
    width: calc(100% - 0px);
}

.chat-list .chat-item.odd .chat-time {
    text-align: right;
}


.chat-list .chat-item.odd .box {
    clear: both;
    color: #fff;
    background: #2962ff;
}

	
	</style>

  
   
<!-- / Navbar -->








<script>


  var active_advisor_id = 0;

$( document ).ready(function() {
	
    getChatList();
	
});
</script>


<script>
	
	
	/******************   Check If Any New Meesage Come for this user ****************************/
	
	(function worker() {
		
		 
		
  $.get('get_if_new_chat_ajax.php', function(data) {
	  
    // Now that we've completed the request schedule the next one.
	if (!$.trim(data)){   
    //alert("What follows is blank: " + data);
}
else{   
     
    getChatList();
	   
}
	
 setTimeout(worker, 2000);
	 
	
  });
})();
	
	
	
	</script>



<script>
	
	
	/******************   Check If Any New Meesage Come for this user ****************************/
	
	(function worker() {
		
	 
		
  $.get('get_if_new_message_ajax.php?advisor_id='+active_advisor_id, function(data) {
	  
    // Now that we've completed the request schedule the next one.
	if (!$.trim(data)){   
    //alert("What follows is blank: " + data);
}
else{   
   //alert(data);
    getChatMessages();
	   
}
	
 setTimeout(worker, 2000);
	 
	
  });
  
  
  
  
  
})();
	
	
	
	</script>






<script>

 function getChatList()
 {
	 
	 
    var search_contact = document.getElementById('search_contact').value;
     
	 if(search_contact!='')
	 {
	  document.getElementById('ajax_spinner').style.display = 'block';
	 }
	  
	  
	 $.ajax({
      type: "GET",
      url: 'get_chat_list_ajax.php',
      data: ({search_contact:search_contact}),
      success: function(data) {
		  
 
        document.getElementById('chat_list_here').innerHTML=data;
		
		 document.getElementById('ajax_spinner').style.display = 'none';
		 
	
		 }
		  // <- this turns it into synchronous

		  }
	   );
 }

</script>







<script>


	function openChatWindow(advisor_id,name)
	{
		
		document.getElementById('chat_form_section').style.display = 'block';
		
		document.getElementById('chat_name').innerHTML = name+":";
		
		
		document.getElementById('advisor_id').value=advisor_id;
		
		active_advisor_id = advisor_id;
		
		
		
		getChatMessages();
		
		
		
		
	}



</script>




<script>


function getChatMessages()
{
	
	var advisor_id = document.getElementById('advisor_id').value;
	
	
	
	 $.ajax({
      type: "GET",
      url: 'get_chat_messages_ajax.php',
      data: ({advisor_id:advisor_id}),
      success: function(data) {
		  
		  
		  
 
        document.getElementById('chat_messages_here').innerHTML=data;
		
		 var objDiv = document.getElementById("chat_box");
	 
              objDiv.scrollTop = objDiv.scrollHeight;
			  
			  
			  var objDiv1 = document.getElementById("chat_list");
	 
              objDiv1.scrollTop = objDiv1.scrollHeight;
			  
			   
			  
			  
			  
			  
			  getChatList();
		
		  
	
		 }
		  // <- this turns it into synchronous

		  }
	   );
	
	
}



</script>




 
 
 <script>
 
 function openFileSelect(type)
 {
	 
	 var elem = document.getElementById('document');
	 
   if(elem && document.createEvent) {
      var evt = document.createEvent("MouseEvents");
      evt.initEvent("click", true, false);
      elem.dispatchEvent(evt);
   }
   
   
 }
 
 </script>
 
 <script>
 function showFile(type)
 {
	
  document.getElementById('select_file_icon').innerHTML = '<i class="fa fa-check"></i>';	
  
  $('#select_file_icon').removeClass('btn-secondary');
  $('#select_file_icon').addClass('btn-success');
	 
 }
 
 function clearFile(type)
 {
	  document.getElementById('select_file_icon').innerHTML = '<i class="fa fa-paperclip" ></i>';	
  
  $('#select_file_icon').removeClass('btn-success');
  $('#select_file_icon').addClass('btn-secondary');
  
 }
 
 
 
 </script>
 
 
 
 
 
 
 <script>
 
	 $(function () {
		 
		  sub();
		  
				 function sub(){
					 
					 
					 
$('#message_form').submit(function() { 


	  
	 $('#send_button').prop('disabled', true);
	 var form=$("#message_form");
  
    var vcfData = new FormData($('#message_form')[0]); 
	 
	 
	  var files = $('#document')[0].files;
      vcfData.append('document',files[0]);
	
	
	
	//alert(rem);
	 //alert("hello");
        $.ajax({ 
            
            type:"post",
            url:"send_chat_message_ajax.php?advisor_id="+active_advisor_id,
			data:vcfData,
		     contentType: false,
            cache: false,
            processData:false,
            success: function(data) {
				
				// alert('a'+data);
				
				$('#send_button').prop('disabled', false);
				
				 document.getElementById('message').value ='';
				 document.getElementById('document').value ='';
				 clearFile('document');
				 
				 getChatMessages();
				 
				 
				 
   
		      
			  }
        });
	  
	   return false; 
    });
				 }
	  
  });
 
 
 </script>
 
 


<script>

 function deleteMessage(message_id,delete_type)
 {
	 
	  
	  $.ajax({
      type: "GET",
      url: 'delete_message_ajax.php',
      data: ({delete_type:delete_type,message_id:message_id}),
      success: function(data) {
		  
	 getChatMessages();
	 
		 
		 }
		  // <- this turns it into synchronous

		  }
	   );
	 
 }


</script>	
	

<script>

 function copyContent(content)
 {
	 
	   /* Copy the text inside the text field */
  navigator.clipboard.writeText(document.getElementById(content).innerHTML);
	 
 }
	
</script>














      

      <!-- Content wrapper -->
      <div class="content-wrapper">

           <div class="row" style="margin: 10px;">
            <!-- ============================================================== -->
            <!-- Left Part  -->
            <!-- ============================================================== -->
            <div class="left-part bg-white fixed-left-part col-md-3">
                <!-- Mobile toggle button -->
                <a class="ti-menu ti-close btn btn-success show-left-part d-block d-md-none" href="javascript:void(0)"></a>
                <!-- Mobile toggle button -->
                 
                <div class="scrollable position-relative" style="height:100%;">
                    <div class="p-15">
                        <h5 class="card-title">Search Contact</h5>
                        <form>
                            <input onkeyUp="getChatList();" id="search_contact" class="form-control" type="text" placeholder="Search Contact">
                        </form>
                    </div>
                    <hr>
					 
					
					<center><div id="ajax_spinner" style="display:none;" class="spinner-border text-primary" role="status"></div></center>

					
					<div id="chat_list_here">
					
					</div>
					 
				
				</div>
            </div>
            <!-- ============================================================== -->
            <!-- End Left Part  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Right Part  Mail Compose -->
            <!-- ============================================================== -->
            <div class="right-part col-md-9">
                <div class="p-20">
				
				
				
                    <div class="card">
					
					
                        <div class="card-body">
						
						
                            <h4 class="card-title"><span id="chat_name"></span>Chat Messages</h4>
							
							
                            <div class="chat-box scrollable" id="chat_box" style="height:calc(100vh - 300px);">
							
							<div id="chat_messages_here">
							
							 
							</div>
							
							 </div>
                        </div>
						
                        <div id="chat_form_section" style="display:none;" class="card-body border-top">
						
						<form id="message_form" action="" method="post"   >
						
						<input type="hidden" id="advisor_id" value="0" />
						
                            <div class="row">
							
							  <div class="col-1">
							  <a href="#" onclick="openFileSelect('document');" id="select_file_icon"  class="btn btn-icon btn-secondary rounded" ><i class="fa fa-paperclip" ></i></a>
			
						<input type="file" onchange="showFile('document');" name="document" id="document" style="display:none;" />
			
							  </div>
							
                                <div class="col-10">
                                    <div class="input-field mt-0 mb-0">
                                        <input  name="message" id="message" placeholder="Type and enter" class="form-control border-0" type="text">
                                    </div>
                                </div>
                                <div class="col-1">
								
								 <button   type="submit" id="send_button" class="btn btn-icon btn-success rounded">
									<i class="fas fa-paper-plane"></i>
								</button>
                                     
                                </div>
                            </div>
							
						</form>
							
                        </div>
						
						
                    </div>
					
					
				
				
				
					
                </div>
            </div>
            
			
			
			
            <!-- ============================================================== -->
        </div>
      
		
      
         </div>
        <!-- Content wrapper -->
		
		
		
	 

 
		
		
		
      </div>
      <!-- / Layout page -->
    </div>

    
    
    
  </div>
  <!-- / Layout wrapper -->

 

  <!-- Core JS -->
  <!-- build:js assets/vendor/js/core.js -->
  <script src="../assets/vendor/libs/jquery/jquery.js"></script>
  <script src="../assets/vendor/libs/popper/popper.js"></script>
  <script src="../assets/vendor/js/bootstrap.js"></script>
  <script src="../assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>
  <script src="../assets/vendor/libs/hammer/hammer.js"></script>
  <script src="../assets/vendor/libs/i18n/i18n.js"></script>
  <script src="../assets/vendor/libs/typeahead-js/typeahead.js"></script>
  
  <script src="../assets/vendor/js/menu.js"></script>
    <script src="../assets/vendor/libs/select2/select2.js"></script>



    <script src="../assets/vendor/libs/toastr/toastr.js"></script>
	
	
         <script src="../assets/js/ui-toasts.js"></script>
	 
	   <script src="../assets/vendor/libs/sweetalert2/sweetalert2.js"></script>


  <!-- endbuild -->

  <!-- Vendors JS -->
  <script src="../assets/vendor/libs/moment/moment.js"></script>
<script src="../assets/vendor/libs/datatables/jquery.dataTables.js"></script>
<script src="../assets/vendor/libs/datatables-bs5/datatables-bootstrap5.js"></script>
<script src="../assets/vendor/libs/datatables-responsive/datatables.responsive.js"></script>
<script src="../assets/vendor/libs/datatables-responsive-bs5/responsive.bootstrap5.js"></script>
<script src="../assets/vendor/libs/datatables-buttons/datatables-buttons.js"></script>
<script src="../assets/vendor/libs/datatables-buttons-bs5/buttons.bootstrap5.js"></script>

  <!-- Main JS -->
  <script src="../assets/js/main.js"></script>

  <!-- Page JS -->
  <script src="../assets/js/app-invoice-list.js"></script>
</body>

 
</html>
  <?php  }  else { header("Location:login.php");  } ?>