<?php 
include "includes/header.php"; 
include "includes/Mdme-functions.php";
$mdme = getMdmeCompany($db,'');
include_once "includes/pagepermission.php";


//check permission - START
if(!($res_modm_prm)){
	header("Location:".admin_public_url."error.php");
}
//check permission - END

$id=$_REQUEST['id'];
if($id!="")
{
	
//check edit permission - START	
if(trim($res_modm_prm['EditPrm'])=="0") {
?>
<script>
  window.location="error.php";
</script>
<?php	
}
//check edit permission - END	

$operation="Edit";
$act="update";
$btn='Update';

$str_ed = "select * from m_company where IsActive != '2' and company_id = '".base64_decode($id)."' ";
$res_ed = $db->get_a_line($str_ed);

$edit_id = $res_ed['company_id'];

$chk='';
if($res_ed['IsActive']=='1')
{
	$chk='checked';
}

}
else
{
	
//check edit permission - START	
if(trim($res_modm_prm['AddPrm'])=="0") {
?>
<script>
  window.location="error.php";
</script>
<?php	
}
//check edit permission - END
	$operation="Add";
	$act="insert";
	$btn='Save';
}
?>  

<div class="wrapper">
    <div class="container">        
		<!-- Page-Title - START -->
        <div class="row">
            <div class="col-sm-12">										
                <h4 class="page-title"><?php echo $operation; ?> Company Information</h4>				
            </div>
        </div>
		<!-- Page-Title - END -->	
					
		<div class="row">
			<div class="col-sm-12">
				<form id="jvalidate" name="frmCompany" role="form" class="form-horizontal" action="#" method="post" enctype="multipart/form-data" >
				<input type="hidden" name="action" value="<?php echo $act; ?>" />
				<input type="hidden" name="edit_id" id="edit_id" value="<?php echo $edit_id; ?>"  />
				
					<div class="card-box">						
						
						<div class="row">
							<div class="col-sm-6">
								
								<div class="form-group">
									<label>Company Name<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_companyname" id="txt_companyname" value="<?php echo $res_ed['company_name']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Proprietor Name<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_proprietor" id="txt_proprietor" value="<?php echo $res_ed['proprietor_name']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Address<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_address" id="txt_address" value="<?php echo $res_ed['c_address']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Country<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_country" id="txt_country" value="<?php echo $res_ed['c_country']; ?>" />
								</div>
								
								<div class="form-group">
									<label>State<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_state" id="txt_state" value="<?php echo $res_ed['c_state']; ?>" />
								</div>
								
								<div class="form-group">
									<label>City<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_city" id="txt_city" value="<?php echo $res_ed['c_city']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Postalcode<span class="text-danger">*</span></label>							
									<input type="text" class="form-control jsrequired" name="txt_postcode" id="txt_postcode" value="<?php echo $res_ed['c_postcode']; ?>" onKeyPress="return isNumberKey(event,this)" />
								</div>
								
							</div>
							
							<div class="col-sm-6">
							
								<div class="form-group">
									<label>Landline No</label>							
									<input type="text" class="form-control " name="txt_landline" id="txt_landline" value="<?php echo $res_ed['c_landline']; ?>" onKeyPress="return isNumberKey(event,this)" />
								</div>
								
								<div class="form-group">
									<label>Mobile No</label>							
									<input type="text" class="form-control " name="txt_mobile" id="txt_mobile" value="<?php echo $res_ed['c_mobile']; ?>" onKeyPress="return isNumberKey(event,this)" />
								</div>
								
								<div class="form-group">
									<label>GST No</label>							
									<input type="text" class="form-control " name="txt_gst" id="txt_gst" value="<?php echo $res_ed['gst_no']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Email Id<span class="text-danger">*</span></label>							
									<input type="email" class="form-control jsrequired" name="txt_email" id="txt_email" value="<?php echo $res_ed['c_email']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Website URL</label>							
									<input type="text" class="form-control" name="txt_websiteurl" id="txt_websiteurl" value="<?php echo $res_ed['c_website_url']; ?>" />
								</div>
								
								<div class="form-group">
									<label>Company Logo</label>							
									<input id="company_logo" name="company_logo" type="file" class="file form-control"  accept="image/jpeg,image/png,jpg|png" onchange="readURL_photo_preview(this);" /> Allowed Extension ( jpg, png, gif )
								</div>
								
								<div class="form-group">
									<?php
										$disp_img = 'NoImageAvailable.png';										
										if (!empty($res_ed['c_logo']) && ($act == 'update')) { 
											if(file_exists(CAAROOTADMIN_DIR."/uploads/company_logo/".$res_ed['c_logo']))
											{
												$disp_img = $res_ed['c_logo'];	
											}											
										}										
									?>
									 
									<img id="preview_img" src="uploads/company_logo/<?php echo $disp_img; ?>" width="50px" align="absmiddle"/>
								</div>
								
							</div>
							
						</div>
						
						<div class="row">
							<div class="col-sm-8">&nbsp;</div>
					
							<div class="col-sm-4">						
								<div class="form-group">
									<div class="btn-group pull-right m-t-15">
										<button class="btn btn-primary waves-effect waves-light" type="button" onClick="javascript:funSubmtWithImg('frmCompany','company_actions.php','jvalidate','company','company_mng.php');" >Submit</button>	
													 
										<button class="btn btn-secondary waves-effect m-l-5" type="button" onClick="javascript:funCancel('frmCompany','jvalidate','company','company_mng.php');" >Cancel</button>
									</div>
								</div>						
							</div>
							
						</div>
										
						
					</div>
					
				</form>
            </div>
        </div> <!-- end row -->	
			

<?php include "includes/footer.php";  ?> 
	 </div> <!-- container -->
</div> <!-- End wrapper -->

<?php include "includes/footer_script.php";  ?> 

<!-- Autocomplete -->
<script type="text/javascript" src="assets/plugins/autocomplete/jquery.autocomplete.min.js"></script>

<script type="text/javascript"> 

$("document").ready(function(){
    $("#user_photo").change(function() {
       // $("#preview_img").css("display","none");
    });
		
	<!-- autocomplete function - START -->		
	$('#txt_country').autocomplete({
		lookup: function (query, done) {				
			$.ajax({
				url  : "autocomplete_actions.php?pageaction=autocomplete_company&srch_type=country_search&srch_keyword="+$('#txt_country').val(),
				dataType: "json",						
				success: function (data)
				{					
				 done(data);
				}
			});			
		}		
	});
	
	$('#txt_state').autocomplete({
		lookup: function (query, done) {				
			$.ajax({
				url  : "autocomplete_actions.php?pageaction=autocomplete_company&srch_type=state_search&srch_keyword="+$('#txt_state').val(),
				dataType: "json",						
				success: function (data)
				{					
				 done(data);
				}
			});			
		}		
	});
	
	$('#txt_city').autocomplete({
		lookup: function (query, done) {				
			$.ajax({
				url  : "autocomplete_actions.php?pageaction=autocomplete_company&srch_type=city_search&srch_keyword="+$('#txt_city').val(),
				dataType: "json",						
				success: function (data)
				{					
				 done(data);
				}
			});			
		}		
	});

	<!-- autocomplete function - END -->
	
	
	
});



function readURL_photo_preview(input) { 
    if (input.files && input.files[0]) {				
        var reader = new FileReader();
        reader.onload = function (e) {
            $("[id*=preview_img]").attr("src", e.target.result);
        };
        reader.readAsDataURL(input.files[0]); 
    }
}

function bind_country(){
	$.ajax({
		url  : "autocomplete_actions.php?pageaction=autocomplete_company&srch_type=country_search&srch_keyword=aa",
		dataType: "json",						
		success: function (data){					
			//response(data);
			return data;
		}
	});
}


</script>



</body>
</html>
	  