<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/imgpro.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='axe_company.php';   
$cuPage='axe_company.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='company';
$menuh='Company';
$phead='setcom';
$page='Company Setup';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php
$sql="SELECT * FROM tbl_company WHERE id=1 LIMIT 1";
$comde = mysqli_query($con,$sql);
$com=mysqli_fetch_array($comde);

if(isset($_POST['upd_com'])){
$name = remove_junk(escape($_POST['name']));
$bname = remove_junk(escape($_POST['bname']));    
$dialog = remove_junk(escape($_POST['dialog']));
$bdialog = remove_junk(escape($_POST['bdialog']));
if(strlen($bdialog)<2){$bdialog='NULL';}else{$bdialog="'".$bdialog."'";}    
$mobile = remove_junk(escape($_POST['mobile']));
$phone = remove_junk(escape($_POST['phone']));
$fax = remove_junk(escape($_POST['fax']));
$email = remove_junk(escape($_POST['email']));
$web = remove_junk(escape($_POST['web']));
$tin = remove_junk(escape($_POST['tin']));
$vat = remove_junk(escape($_POST['vat']));
$address = remove_junk(escape($_POST['address']));
$baddress = remove_junk(escape($_POST['baddress']));    
$item = PATHINFO($_FILES["item"]["name"]);

$sql="UPDATE tbl_company SET name='$name', bname='$bname', dialog='$dialog', bdialog=$bdialog,mobile='$mobile',phone='$phone',fax='$fax',email='$email',web='$web',tin='$tin',vat='$vat',address='$address', baddress='$baddress' WHERE id='1'";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));   
if($result){
if (!empty($_FILES["item"]["name"])){
get_destroy('1','C');    
get_upload('1',$_FILES['item'],'C');    
}
    
$act =remove_junk(escape('Company Update: '.$name));    
write_activity($aid,'COM','Companyt has been Updated',$act); 
    
save_msg('s','Company Update Successfully!!!');
echo "<script>window.location='axe_company.php'</script>";	
}else{
save_msg('e','Company update fail!!!!');
echo "<script>window.location='axe_company.php'</script>";		
}    
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Update Company</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<form action="axe_company.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">    
<div class="col-md-12 popup_details_div">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="row">
<div class="col-md-12">
<div class="form-group" >
<label>Name (English)</label>
<div class="input-group">
<span class="input-group-addon">N</span>
<input type="text" maxlength="45" class="form-control" name="name" id="name" Value="<?php echo $com['name'];?>" placeholder="Company Name" autocomplete="off">
</div>
</div>
<div class="form-group" >
<label>নাম (বাংলা)</label>
<div class="input-group">
<span class="input-group-addon">ন</span>
<input type="text" maxlength="255" class="form-control" name="bname" id="bname" Value="<?php echo $com['bname'];?>" placeholder="কম্পানির নাম" autocomplete="off">
</div>
</div>    
<div class="form-group" >
<label>Slogan (English)</label>
<div class="input-group">
<span class="input-group-addon">D</span>
<input type="text" maxlength="75" class="form-control" name="dialog" id="dialog" Value="<?php echo $com['dialog'];?>" placeholder="Company Dialog" autocomplete="off">
</div>
</div>
<div class="form-group" >
<label>স্লোগান (বাংলা)</label>
<div class="input-group">
<span class="input-group-addon">D</span>
<input type="text" maxlength="350" class="form-control" name="bdialog" id="bdialog" Value="<?php echo $com['bdialog'];?>" placeholder="কম্পানির স্লোগান" autocomplete="off">
</div>
</div>    
</div>
</div>    
<div class="row">
<div class="col-md-6">
<div class="form-group" >
<label>Mobile</label>
<div class="input-group">
<span class="input-group-addon">MO</span>
<input type="text" maxlength="18" class="form-control" name="mobile" id="mobile" value="<?php echo $com['mobile'];?>" onkeypress="return isNumberKey(event)" placeholder="Mobile No:" autocomplete="off">
</div>
</div>
<div class="form-group" >
<label>Phone</label>
<div class="input-group">
<span class="input-group-addon">PH</span>
<input type="text" maxlength="14" class="form-control" name="phone" id="phone" Value="<?php echo $com['phone'];?>" onkeypress="return isNumberKey(event)" placeholder="Phone No:" autocomplete="off">
</div>
</div>        
</div>
<div class="col-md-6">
<div class="form-group" >
<label>Fax</label>
<div class="input-group">
<span class="input-group-addon">FN</span>
<input type="text" maxlength="14" class="form-control" name="fax" id="fax" value="<?php echo $com['fax'];?>" onkeypress="return isNumberKey(event)" placeholder="e. g 72178xx" autocomplete="off">
</div>
</div>
<div class="form-group" >
<label>Web</label>
<div class="input-group">
<span class="input-group-addon">W</span>
<input type="web" maxlength="35" class="form-control" name="web" id="web" value="<?php echo $com['web'];?>"  placeholder="e.g. https://www.axesgl.com" autocomplete="off">
</div>
</div>    
</div>    
</div>
<div class="row">
<div class="col-md-6">                                
<div class="form-group" >
<label>Email</label>
<div class="input-group">
<span class="input-group-addon">EM</span>
<input type="email" maxlength="45" class="form-control" name="email" id="email" value="<?php echo $com['email'];?>" placeholder="Email Address:" autocomplete="off">
</div>
</div>
<div class="form-group" >
<label>TIN</label>
<div class="input-group">
<span class="input-group-addon">T</span>
<input type="text" maxlength="15" class="form-control" name="tin" id="tin" value="<?php echo $com['tin'];?>" onkeypress="return isNumberKey(event)" placeholder="e. g 10-10-xxxxx" autocomplete="off">
</div>
</div>
<div class="form-group" >
<label>VAT</label>
<div class="input-group">
<span class="input-group-addon">V</span>
<input type="text" maxlength="15" class="form-control" name="vat" id="vat" value="<?php echo $com['vat'];?>" onkeypress="return isNumberKey(event)" placeholder="e. g 10-10-xxxxx" autocomplete="off">
</div>
</div>    
<div class="form-group">
<label>Address (English)</label>
<div class="input-group">
<span class="input-group-addon">AD</span>
<textarea class="form-control" name="address" id="address" maxlength="250" rows="5" placeholder="Address" required><?php echo $com['address'];?></textarea>
</div>    
</div>
<div class="form-group">
<label>ঠিকানা (বাংলা)</label>
<div class="input-group">
<span class="input-group-addon">AD</span>
<textarea class="form-control" name="baddress" id="baddress" maxlength="350" rows="5" placeholder="ঠিকানা" required><?php echo $com['baddress'];?></textarea>
</div>    
</div>    
</div>
<div class="col-md-6">
<div class="form-group">
<label>Image</label>
<div style="width:200px; height:245px;">
<img src="../img/<?php if(empty($com['logo'])) {echo "logo.png";}else{echo $com['logo'];} ?>" id="profile-img-tag" style="width: 100%; height: 100%; object-fit: contain;">
</div>
<br>    
<input type="file" class="btn btn-flat bg-purple btn-sm" name="item" id="profile-img" accept=".png, .gif, .jpg, .jpeg">       
</div>    
</div>    
</div>   
</div>    
<div class="col-md-1"></div>
</div>
    
</div>
<div class="clearfix" ></div>
<div class="col-md-12 nopadding widgets_area"></div>    
<div class="row"style="margin-top: 15px" >
<div class="col-md-8 ">
</div>
<div class="col-md-4 text-right" >
<input type="submit" name="upd_com" id="submit" class="btn btn-flat bg-purple btn-sm" value="Update"/>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['utype']=='1'){echo read_activity($aid,'COM','A');}else{echo read_activity($aid,'COM','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>
    
<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function () {  
var name = new LiveValidation('name');
name.add(Validate.Presence);
var address = new LiveValidation('address');
address.add(Validate.Presence);    
var mobile = new LiveValidation('mobile');
mobile.add(Validate.Presence);
mobile.add(Validate.Length, {minimum: 11, maximum: 14});
var email = new LiveValidation('email');
email.add(Validate.Email);
var web = new LiveValidation('web');
web.add(Validate.Web);    
});    
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
            
reader.onload = function (e) {
$('#profile-img-tag').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#profile-img").change(function(){
readURL(this);
});
$("#profile-img-tag").click(function() {
$("#profile-img").click();
}); 
</script>    
<!-- /page script -->
</html>    