<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('16','edits','R');     
$_SESSION['cuPages']='mas_manlist.php';   
$cuPage='mas_manlist.php';    
$aid=$_SESSION['uid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='master';
$menuh='Master Process';
$phead='manlist';
$page='Manufacturer List';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php 
if(isset($_POST['update_manfa'])){
	$mid = remove_junk(escape($_POST['mid']));
    $name = remove_junk(escape($_POST['name']));
    $address = remove_junk(escape($_POST['address']));
    $cperson = remove_junk(escape($_POST['cperson']));
    $cmobile = remove_junk(escape($_POST['cmobile']));
    $email = remove_junk(escape($_POST['email']));
    $web = remove_junk(escape($_POST['web']));
    $rank = remove_junk(escape($_POST['rank']));
    $mainpro = remove_junk(escape($_POST['mainpro']));
    $description = remove_junk(escape($_POST['description']));
	
	if(isset($_POST['name'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_manfacturer WHERE name = '$name' AND id!='$mid'");
	}
	
	if($ducode->num_rows > 0) {
		save_msg('i','Manfacturer name alrady used! Plz try another');
		echo "<script>window.location='mas_manlist.php'</script>";
	}else{
    $sql="UPDATE tbl_manfacturer SET name='$name',address='$address',cperson='$cperson',cmobile='$cmobile',email='$email',web='$web',rank='$rank',mainpro='$mainpro',description='$description' WHERE id='$mid'";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
    $act =remove_junk(escape('Manfacturer name: '.$name));    
    write_activity($aid,'MAN','Manfacturer has been Updated',$act);    
    save_msg('s','Data Successfully Update!');
    }else{
    save_msg('w','Data fail to Update!');    
    }
    echo "<script>window.location='mas_manlist.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">Edit Manufacturer</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>  
<form action="mas_manedit.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-12">
<div class="col-md-1"></div>
<div class="col-md-10">
<?php 
if(isset($_POST['editman'])){
$ids = $_POST['editman'];
$sql="SELECT * FROM tbl_manfacturer WHERE id='".$ids."' ORDER BY id ASC LIMIT 1";    
$admin=mysqli_query($con,$sql) or die(mysqli_error($con));    
$adm=mysqli_fetch_array($admin);
?>     
<div class="row">
<div class="col-md-6">    
<div class="form-group">
<label>Manufacturer Name</label>
<input type="text" name="name" maxlength="45" value="<?php echo $adm['name'];?>" id="name" class="form-control" placeholder="e.g. Sun Sui Hong"/>
<input type="hidden" maxlength="11" value="<?php echo $adm['id'];?>" class="form-control" name="mid" autocomplete="off" readonly>    
</div>
</div>
<div class="col-md-6">    
<div class="form-group">
<label>Contact Person</label>
<input type="text" name="cperson" maxlength="45" value="<?php echo $adm['cperson'];?>" id="cperson" class="form-control" placeholder="e.g. Mr.Sumon"  />
</div>
</div>    
</div>    
<div class="row">
<div class="col-md-6">    
<div class="form-group">
<label>Contact Mobile</label>
<input type="text" name="cmobile" maxlength="18" value="<?php echo $adm['cmobile'];?>" id="cmobile" class="form-control" placeholder="e.g. 016161xxxx0"/>
</div>
</div>
<div class="col-md-6">    
<div class="form-group">
<label>Contact Email</label>
<input type="text" name="email" maxlength="45" value="<?php echo $adm['email'];?>" id="email" class="form-control" placeholder="e.g. info@axesgl.com"/>
</div>
</div>    
</div>
<div class="row">
<div class="col-md-6">    
<div class="form-group">
<label>Address</label>
<textarea class="form-control" maxlength="150" rows="5" name="address" id="address" placeholder="e.g. Address"><?php echo $adm['address'];?></textarea>
</div>
</div>
<div class="col-md-6">    
<div class="form-group">
<label>Main Product</label>
<textarea class="form-control" maxlength="250" rows="5" name="mainpro" id="mainpro" placeholder="Comma ',' use for multiple item e.g. Puma,Adidas etc."><?php echo $adm['mainpro'];?></textarea>
</div>
</div>    
</div>
<div class="row">
<div class="col-md-6">    
<div class="form-group">
<label>Description</label>
<textarea class="form-control" maxlength="250" rows="5" name="description" placeholder="Description"><?php echo $adm['description'];?></textarea>
</div>
</div>
<div class="col-md-6">    
<div class="form-group">
<label>Web</label>
<input type="text" name="web" maxlength="45" value="<?php echo $adm['web'];?>" id="web" class="form-control" placeholder="e.g. http://www.axesgl.com"/>   
</div>
<div class="form-group">
<label>Rank</label>
<input type="text" name="rank" maxlength="3" value="<?php echo $adm['rank'];?>" id="rank" class="form-control" onkeypress="return isNumberKey(event)" placeholder="e.g. 127"/>   
</div>
</div>    
</div>
<?php } ?>    
</div>    
<div class="col-md-1"></div>    
</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="update_manfa" id="submit" class="btn btn-flat bg-purple btn-sm " value="Update"/> <a href="mas_manlist.php" class="btn btn-flat bg-gray  ">Close</a>
</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['access']=='1'){echo read_activity($aid,'MAN','A');}else{echo read_activity($aid,'MAN','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 email = new LiveValidation('email');
email.add(Validate.Email);
var web = new LiveValidation('web');
web.add(Validate.Web);    
var rank = new LiveValidation('rank');
rank.add(Validate.Presence);     
rank.add(Validate.Numericality, { minimum: 0, onlyInteger: true });    
});
</script>    
<!-- /page script -->
</html>        