<?php 
/*include_once "../ichat/admin/route.php";
require_once 'database.php';
if(isset($_SESSION[$elhash]) && $_SESSION[$elhash] != "") { 
    $random_hash = $_SESSION[$elhash];
} else {
    $random_hash = uniqid();
    $_SESSION[$elhash] = $random_hash;
}*/

session_start();
require_once "check_admin.php";
require_once 'database.php';
class add_devices extends database
{
   public function index($data)
    {
		return $this->insert('device',$data);
	}
}
$dev = new add_devices();	
$msg="";
if(isset($_GET['message']))
{
	$msg=$_GET['message'];
}
if(isset($_POST['data']))
{
	$data=$_POST['data'];
	if(trim($data['name']) == '')
	{
		$msg.= "Device name is required<br/>";
	}
        if(trim($data['description']) == '')
	{
		$msg.= "Description is required<br/>";
	}
	if($msg=="")
	{
		 $res = $dev->index($data);
            if($res)
            {
                    header('Location:devices.php?message=Device Added Successfully');
            }
            else {
                $msg = 'Something Went Wrong';
            }
	}
}
include 'header.php';
?>
<div class="ordes-content">
    <div class="container midle-order">
        <div class="row">
        	<?php include 'menu.php'; ?>
            <div class="col-md-9">
                <div class="order-wraper">
                	<div class="col-md-12">
                    	<h1>Add Devices</h1>
						<?php if($msg !=''){echo '<span class="alert alert-danger pull-left">'.$msg.'</span>';}?>
                    </div>
                    <div class="clearfix"></div>
                    <div class="col-sm-12">
                    	<div class="order-contact">
                        	
                            <div class="row">
							
							<form method="post">
                            	<div class="col-md-12">
                                	<label>Device Name</label>
                                    <input type="text" name="data[name]" placeholder="Device Name" />
                                </div>
                            	<div class="col-md-12">
                                	<label>Description</label>
                                   <input name="data[description]" placeholder="Description"/>
                                </div>
                            	
                            	
                                <div class="col-md-12 botm-cont">
                                	<button type="submit" class="track-btn">Add</button>
                                </div>
							</form>
                            </div>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
	</div>
</div>

<script>
    $(document).ready(function(){
        $('.activ-cat').removeClass('activ-cat');
        $('#device-menu').addClass('activ-cat');
    }); 
</script>

<?php include 'footer.php';?>