<?php require('includes/head.php');
require 'connection/conn.php';
 if(isset($_POST['submit']))
 {
     $c=$_POST['code'];
	 
	 $check="select * from `items` where `code`='$c'";
	 $check_r=$conn->query($check);
	 $check_num=mysqli_num_rows($check_r);
	 if($check_num==0)
	{
	$n=$_POST['name'];
	//$n2=$_POST['name2'];
	//$set=$_POST['set'];
	//$num=$_POST['num'];
	//$p_p=$_POST['p_price'];
	//$s_p=$_POST['s_price'];
	$target_dir = "item_image/";
    $timestamp = date("Y-m-d_H-i-s"); 
    $file_name = $timestamp . "_" . basename($_FILES["image"]["name"]);
    if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_dir . $file_name)) {
        $image = $file_name; 
    } else {
        $image = ""; 
    }
	 
	$add="insert into  `items`    (`code`,`name`,`item_image`)
	values ('$c','$n','$image')";
	$conn->query($add);
	}
	else{
		echo " <script type='text/javascript'>
              alert ('ئەم کۆدە بەکارهاتووە')
		  </script>";
	}
	echo "<script type='text/javascript'>
		           window.location.href='item_list.php'
		        </script>";
 }
 
 
?>


<div class="container">
          <div class="page-inner">
            <div class="page-header">
              <h3 class="fw-bold mb-3">کاڵای تازە</h3>
              <ul class="breadcrumbs mb-3">
                <li class="nav-home">
                  <a href="home.php">
                    <i class="icon-home"></i>
                  </a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="#"></a>
                </li>
                <li class="separator">
                  <i class="icon-arrow-right"></i>
                </li>
                <li class="nav-item">
                  <a href="#"></a>
                </li>
              </ul>
            </div>
            <div class="row">
              <div class="col-md-12">
                <div class="card">
                  
                  <div class="card-body">
                    <div class="table-responsive">
                      <table
                        id="basic-datatables"
                        class="display table table-striped table-hover"
                      >
<form action="" method="post" enctype="multipart/form-data">
	<tr style="border: solid 1px red; ">
		<td style=" font-size:22pt">کۆد</td><td><input type="text" name="code" required class="form-control" style="width:300px"></td>
	</tr>
	<tr style="border: solid 1px red; ">
		<td style=" font-size:22pt">ناو</td><td><input type="text" name="name" required class="form-control" style="width:300px"></td>
	</tr>
	<!--<tr >
		<td>ناوی لاتینی</td><td><input type="text" name="name2" required ></td>
	</tr>-->
	<tr style="border: solid 1px red; ">
		<td style=" font-size:22pt">وێنە</td><td> <input type="file"  name="image" class="form-control" style="width:300px"></td>
	</tr>
	<!--<tr style="border: solid 1px red; ">
		<td style=" font-size:22pt">ژمارەی سێت</td><td><input type="number" name="set" required class="form-control" style="width:300px"></td>
	</tr>
	
	<tr style="border: solid 1px red; ">
		<td style=" font-size:22pt">نرخی کڕین</td><td><input type="number" step="0.01" name="p_price" required class="form-control" style="width:300px"></td>
	</tr>
	<tr style="border: solid 1px red; ">
		<td style=" font-size:22pt">نرخی فرۆشتن</td><td><input type="number" step="0.01" name="s_price" required class="form-control" style="width:300px"></td>
	</tr>-->
	<tr style="border: solid 1px red; ">
		<td></td><td><input type="submit" name="submit" value="زیادکردن" class="form-control" style="width:300px"></td>
	</tr>
  </table>
 
</form>

</div>
                  </div>
                </div>
              </div>
			  
			  </div>
          </div>
        </div>
<?php require'includes/foot.php';?>