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

 if(isset($_SESSION['loan_crm_username']) && isset($_SESSION['loan_crm_password']))
{
		
	 $advisor_id = $_SESSION['loan_crm_userid'];
	$login_name = $_SESSION['login_name'];
	
	 
	
	
	 
   $today_date = date('Y-m-d');
    
	     $sender_id = $_REQUEST['advisor_id'];
	   
	     $advisorQ = mysqli_query($conn,"select *  from `advisors` where id=$sender_id  ");
							   
		 $advisorData = mysqli_fetch_assoc($advisorQ);
		
	
	
	
	
	
	
   
   $message = $_POST['message'];
 
 
 
   $MESSAGE_DATA['sender_id'] = $advisor_id;
   $MESSAGE_DATA['sender_name'] = $login_name;
   $MESSAGE_DATA['receiver_id'] = $sender_id;
   $MESSAGE_DATA['receiver_name'] = $advisorData['name'];
   $MESSAGE_DATA['sender'] = $login_name;
    $MESSAGE_DATA['sender'] = "lead_owner";
   $MESSAGE_DATA['message'] = $message;
   $MESSAGE_DATA['is_read'] = '0';
 
 
 
       
               // Check is Document
				    if(isset($_FILES['document']['name']))
				   {
					  
               
                       $document_name = $_FILES['document']['name'];
					  
					   if($document_name!='')
					   {
					   
					   
                       $document_name = mktime().str_replace(" ","_",$document_name);					   
					   
					   move_uploaded_file($_FILES['document']['tmp_name'],"../images/".$document_name);
					   
					   
					   $MESSAGE_DATA['document'] = $document_name;
					   
					   }
					   
				   }
 
 
 
 
  
  
 
 
  	insertTable($conn,'messages',$MESSAGE_DATA,'add_submit');
	
	
	
	
	
	
	/****************** Send Message Notification **************************/
	/*
	$firebase_lead_id = $lead_id;
	$title = $_SESSION['login_name'];
	
	$notification_message = substr($message,0,50);
	if(strlen($message) > 50)
	{
		$notification_message = $notification_message.'..';
	}
	
	$image_url='';
	
	if($document_name!='')
	 {
		 if(strpos($document_name,'.png') != false || strpos($document_name,'.jpg') != false || strpos($document_name,'.jpeg') != false || strpos($document_name,'.gif') != false) {
			 
		 $image_url =  "http://visalynk.com/images/".$document_name;
		 
		 }
	 }
	 
	 
	 $for = 'redirect_page=chat_window_'.$lead_owner_type.'&redirect_id='.$lead_owner_id;
	 
	 sendFirebaseNotification($conn,$firebase_lead_id,$title,$notification_message,$image_url,$for);
	
	
	*/
	
	
	 
	
	
	
     
	 echo mysqli_error($conn); 
	 
	 
	 
	 
	 
	 
	 
	
	
	
	
	
	
	
	
	
	
	
	
 }
 
 ?>