<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Follow Up</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>
                        
                        <table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Follow Up
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->

<script src="assets/js/jquery.js"></script>

<script>

$(document).ready(function(){

$(".executive").change(function() {

		  var executive=$(this).val();

		  var dataString = 'executive='+ executive;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getcust1.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
			  
			  //alert(resp);
		  
		  $('.customer').html($('#customer',resp).html());

		  }

		  });

});



$(".customer").change(function() {

          $('.contactrow').show();

		  var customer=$(this).val();

		  var dataString = 'customer='+ customer;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getcontact.php",

		  data: dataString,

		  cache: false,

		  success: function(html)

		  {
		  
		  //alert(html);	

			//var contact=$(html).filter('#contact').text();
			
			$('.contact').html(html);

		  }

		  });

});

});

</script>

<script>
	
jQuery(function($){

	// simple jQuery validation script
	$('#course').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>



<?php        

if (isset($_POST['submit'])) { 

$customer = $_POST['customer'];

$date = $_POST['date'];

$time=$_POST['time'];

$remarks = $_POST['remarks'];

$executive=$_POST['executive'];



$date=date('Y-m-d',strtotime($date));

if($customer)
{ 

$in= "INSERT INTO followup(date,customer,remarks,executive,time)

			VALUES('$date','$customer','$remarks','$executive','$time')";

$in1 = mysql_query($in) or die(mysql_error());

if($in1)
{

 header("location:followup.php?s=1");

}

}

else
{

 header("location:followup.php?s=2");

}

}


else 
{

	if(isset($_GET['s']))
	{
	 $status=$_GET['s'];
		
		 if($status=='1')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Follow Up Added Successfully.
				  </div>';				  
		 }
		 if($status=='2')
		 {
			 echo'<div class="alert alert-block alert-danger">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Values Not Inserted. Please try again.
				  </div>';				  
		 }
	}


$sel=mysql_query("select * from admin where username='$user'");
$nmrw=mysql_num_rows($sel);
$sel1=mysql_fetch_array($sel);
 
?>

<form id="course" action="followup.php" method="post">

<table width="70%" style="margin:auto; line-height:35px;">

<tr><td>Date <span class="red">*</span></td><td>:</td><td><input type="text" name="date" class="datepicker" id="required" title="*" autocomplete='off' /></td></tr>

<?php

if($nmrw>0)
{

echo'<tr><td>Executive <span class="red">*</span></td><td>:</td><td><select name="executive" class="executive chosen"><option value="">-- Select --</option>';

$exec=mysql_query("select employee.ID as ID, employee.name as name from employee left join department on employee.department=department.ID where department.crm='1' order by employee.ID asc");
while($exec1=mysql_fetch_array($exec))
{
	echo"<option value='".$exec1['ID']."'>".$exec1['name']."</option>";
}

echo'</select></td></tr>';

}
else
{

$empd=mysql_query("select * from employee where username='$user'");
$empd1=mysql_fetch_array($empd);

$usr=$empd1['ID'];

echo"<input type='hidden' name='executive' class='executive' value='".$usr."' />";

}

?>

<tr><td>Customer <span class="red">*</span></td><td>:</td><td><select name="customer" class="customer chosen" style="width:220px;" id="required" title="*"><option value="" selected="selected">-- Select --</option>

<?php

if($nmrw==0)
{

$eem=mysql_query("select * from employee where username='$user'");
$eem1=mysql_fetch_array($eem);

$cust=mysql_query("select * from crm_customer where executive='$eem1[ID]' order by ID asc");
while($cust1=mysql_fetch_array($cust))
{
	echo"<option value='".$cust1['ID']."'>".$cust1['name']." (".$cust1['mobile'].")</option>";
}
	
}

?>

</select></td></tr>

<tr style="display:none;" class="contactrow"><td>Contact No.</td><td>:</td><td><div class="contact"></div></td></tr>

<tr><td>Time</td><td>:</td><td><select name="time" class="select2"><option value="">-- Select --</option>

<?php

$st=mysql_query("select * from time_vl order by ID asc");
while($st1=mysql_fetch_array($st))
{
	echo"<option value='".$st1['time']."'>".$st1['time']."</option>";
}

?>

</select></td></tr>

<tr><td>Remarks <span class="red">*</span></td><td>:</td><td style="padding-top:5px;"><textarea name="remarks" rows="2" cols="22" style="width:220px; height:70px;" id="required" title="*"></textarea></td></tr>

<tr><td colspan="3" style="text-align:center; padding-top:7px;"><button type="submit" name="submit" class="btn btn-sm btn-primary">Submit</button></td></tr>

</table>

</form>

<?php

}

?>




										<!-- PAGE CONTENT ENDS -->
									</div><!-- /.col -->
								</div><!-- /.row -->
							</div><!-- /.page-content -->
						</div>
					</div><!-- /.main-content -->


<?php


include 'bottom.php';

}
else
{

 header("location:login.php");
 
}

ob_flush();


?>