<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('21','edits','R');      
$_SESSION['cuPages']='mas_colorlist.php';   
$cuPage='mas_colorlist.php';    
$aid=$_SESSION['uid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='master';
$menuh='Master Process';
$phead='colorlist';
$page='Edit Color';
$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_color'])){
    $colid = remove_junk(escape($_POST['colid']));
	$name = ucwords(remove_junk(escape($_POST['name'])));
    $colval = remove_junk(escape($_POST['colval']));
	
	if(isset($_POST['name'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_color WHERE name = '$name' AND id!='$colid'");
	}
	
	if($ducode->num_rows > 0) {
		save_msg('i','Color name alrady used! Plz try another');
		echo "<script>window.location='mas_colorlist.php'</script>";
	}else{
    $sql="UPDATE tbl_color SET name='$name',sval='$colval' WHERE id='$colid'";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
    $act =remove_junk(escape('Color name: '.$name));    
    write_activity($aid,'COL','Color has been Updated',$act);
    save_msg('s','Data Successfully Update!');    
    }else{
    save_msg('w','Data Fail to Update!');    
    }
    echo "<script>window.location='mas_colorlist.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 Color</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>  
<form action="mas_coloredit.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-3"></div>
<div class="col-md-6">
<?php 
if(isset($_POST['editcol'])){
$ids = $_POST['editcol'];
$sql="SELECT * FROM tbl_color 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="col-md-12">
<div class="row">
<div class="col-md-9">    
<div class="form-group">
<label>Name</label>
<input type="text" name="name" maxlength="25" value="<?php echo $adm['name'];?>" id="name" class="form-control" placeholder="e.g. Green"  />
<input type="hidden" maxlength="11" value="<?php echo $adm['id'];?>" class="form-control" name="colid" autocomplete="off" readonly>    
</div>
</div>
<div class="col-md-3">     
<div class="form-group">
<label>Color</label>
<br>    
<input type="text" class="basic" id="basic" data-preferred-format="hex" value="<?php echo $adm['sval'];?>" data-fouc />
<input type="hidden" name="colval" id="colval">
</div>
</div>
    
</div>
</div>
<?php } ?>    
</div>    
<div class="col-md-3"></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_color" id="submit" class="btn btn-flat bg-purple btn-sm " value="Update"/> <a href="mas_colorlist.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['utype']=='1'){echo read_activity($aid,'COL','A');}else{echo read_activity($aid,'COL','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 col = $("#basic").val();
	$(".basic").spectrum({	
    color: col,
	showInput: true,
    change: function(color) {
	$("#colval").val(color.toHexString());
    }
	});
</script>    
<!-- /page script -->
</html>        