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

$gtp=mysql_query("select * from employee 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;">
                            
                            Executive : <?php echo $gtp1['name']; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->

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

<script src="assets/js/jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>

<script>

$(".customer").live('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;
	});
	
});	

</script>                                
								
                                        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css">
 <style>
    /* Custom CSS for Chosen select */
    .chosen-container {
      width: 25ch;
    }

    .chosen-container-single .chosen-single {
      border-radius: 4px;
      border: 1px solid #f0f0f0; /* Change the border color here */
      height:34px;
	  margin-bottom:10px;
      background-color: #fff;
      background-image: none;
      box-shadow: 0 0 0 1px #c0c0c0;
    }

    .chosen-container-single .chosen-single span {
      padding: 5px;
      text-transform: uppercase;
    }

    .chosen-container-single .chosen-search input[type="text"] {
      border-radius: 4px;
      border: 1px solid #c0c0c0;
      height: 34px;
    }

    .chosen-container-active .chosen-single {
      border-color: #7f7f7f;
      box-shadow: 0 0 0 1px #7f7f7f;
    }

    .chosen-container-active .chosen-single:hover {
      border-color: #7f7f7f;
      box-shadow: 0 0 0 1px #7f7f7f;
    }

    .chosen-container-active .chosen-search input[type="text"] {
      border-color: #7f7f7f;
    }
  </style>                    
                                
<?php        

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

$customer = $_POST['customer'];

$date = $_POST['date'];

$time=$_POST['time'];

$remarks = $_POST['remarks'];

//$executive=$_POST['executive'];

// now we insert it into the database

$executive=$gtp1['ID'];

$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>';				  
		 }
	}
 
?>

<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="*" /></td></tr>

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

<?php

if($gtp1['designation']==2)
{

$r='';	
$tl=mysql_query("select * from team_allocation where team_leader='$gtp1[ID]'");
while($tl1=mysql_fetch_array($tl))
{
$r.=$tl1['ID'].',';
}
$r=rtrim(",",$r);
	
$cust=mysql_query("select * from customer where executive IN ($r) order by ID asc");
}
else
{
$cust=mysql_query("select * from customer where executive='$gtp1[ID]' order by ID asc");
}

while($cust1=mysql_fetch_array($cust))
{
	echo"<option value='".$cust1['ID']."'>".$cust1['name']."</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><input type="text" name="time" /></td></tr>

<tr><td>Remarks <span class="red">*</span></td><td>:</td><td><textarea name="remarks" rows="2" cols="22" id="required" title="*" style="width:220px;"></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();
?>