<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='blank_page.php';   
$cuPage='blank_page.php';    
$aid=$_SESSION['uid'];
$uty=$_SESSION['utype'];    
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='project';
$menuh='Manage Project';
$phead='ctlist';
$page='Edit Contractor';
$dtnow = date("Y-m-d h:i:s", time());
$today = strftime("%Y-%m-%d", time());
?>
<?php 
if(isset($_POST['update_contractor'])){
	$name = ucwords(remove_junk(escape($_POST['name'])));
    $coid = remove_junk(escape($_POST['coid']));
    $cnumber = remove_junk(escape($_POST['cnumber']));
    $cemail = remove_junk(escape($_POST['cemail']));
    $address = remove_junk(escape($_POST['address']));
    $note = remove_junk(escape($_POST['note']));
    $status = remove_junk(escape($_POST['status']));
    
// 	if(isset($_POST['cnumber'])){
// 	$ducode = mysqli_query($con,"SELECT * FROM tbl_contractor WHERE mobile = '$cnumber' AND id!='$coid'");
// 	}
	
// 	if($ducode->num_rows > 0) {
// 		save_msg('i','Mobile Number alrady used! Plz try another');
// 		echo "<script>window.location='prj_contruclist.php'</script>";
// 	}else{
    $sql="UPDATE tbl_contractor SET name='$name',mobile='$cnumber',email='$cemail',address='$address',note='$note',status='$status' WHERE id='$coid'";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
    $act =remove_junk(escape('Contractor name: '.$name));    
    write_activity($aid,'COT','Contractor has been Updated',$act);
    save_msg('s','Data Successfully Update!');    
    }else{
    save_msg('w','Data Fail to Update!');    
    }
    echo "<script>window.location='prj_contruclist.php'</script>";  
//	}  
}
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>

<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">

<div class="row">
<div class="col-md-9">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Edit Contractor</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<form action="prj_contructedit.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="col-md-12">
<?php 
if(isset($_POST['editcot'])){
$ids = $_POST['editcot'];
$sql="SELECT * FROM tbl_contractor 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>Name</label>    
<input type="text" name="name" maxlength="45" value="<?php echo $adm['name'];?>" id="name" class="form-control" placeholder="e.g. Md.Sumon Rahman"/>
<input type="hidden" maxlength="11" value="<?php echo $adm['id'];?>" class="form-control" name="coid" autocomplete="off" readonly>    
</div>    
</div>
<div class="col-md-3">
<div class="form-group">
<label>Status</label>    
<select class="form-control" name="status" id="status">
<option <?php if($adm['status']==1){echo 'selected';}?> value="1">Acive</option> 
<option <?php if($adm['status']==0){echo 'selected';}?> value="0">De-Acive</option>     
</select>
</div>    
</div>    
<div class="col-md-3">
<div class="form-group">
<label>Code</label>    
<input type="text" name="code" maxlength="15" value="<?php echo $adm['code'];?>" id="code" class="form-control" placeholder="e.g. ABA/CO/001" readonly/>
</div>    
</div>    
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>Contact Number</label>    
<input type="text" name="cnumber" maxlength="18" value="<?php echo $adm['mobile'];?>" id="cnumber" class="form-control" placeholder="e.g. +88016161xxxxx70"/>
</div>    
</div>
<div class="col-md-3">
<div class="form-group">
<label>Contact Email</label>    
<input type="text" name="cemail" maxlength="45" value="<?php echo $adm['email'];?>" id="cemail" class="form-control" placeholder="e.g. info@axesgl.com"/>
</div>    
</div>    
<div class="col-md-3">    

</div>    
</div>   
<div class="row">
<div class="col-md-6"> 
<div class="form-group">    
<label>Address</label>
<textarea class="form-control" name="address" id="address" maxlength="150" rows="4" placeholder="Address"><?php echo $adm['address'];?></textarea>    
</div>
</div>    
<div class="col-md-6">    
<div class="form-group">
<label>Note</label>
<textarea class="form-control" name="note" id="note" maxlength="150" rows="4" placeholder="About"><?php echo $adm['note'];?></textarea>   
</div>
</div>    
</div> 
<?php } ?>    
</div>    
</div>    
<div class="col-md-1"></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_contractor" id="submit" class="btn btn-flat bg-purple btn-sm" value="Update"/> <a href="prj_contruclist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-3">
<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,'COT','A');}else{echo read_activity($aid,'COT','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 cnumber = new LiveValidation('cnumber');
// cnumber.add(Validate.Presence);
// cnumber.add(Validate.Length, {minimum: 11, maximum: 14});
// var cemail = new LiveValidation('cemail');
// cemail.add(Validate.Email);    
});   
</script>    
<!-- /page script -->
</html>    