<?php
error_reporting(0);
ob_start();
session_start();
include_once("include/dbconnect.php");
if(isset($_POST['btn_sub_prod'])){
    $sql="INSERT INTO  `menu_all_products` (`mec_catid`, `mec_subid`, `mec_subsubid`, `pname`, `mec_brd_id`, `unit_type`, `quantity`, `prodimg1`, `prodimg2`, `prodimg3`,`prodimg4`,`prodimg5`,`price`,`mec_description`,`weight`,`mec_status`,`orderset`,`chckbox1`,`chckbox2`,`chckbox3`,`chckbox4`)
    VALUES ('".$_POST['mec_catid']."',  '0', '0', '".addslashes($_POST['pname'])."',  '0',  '".addslashes($_POST['unit_type'])."',  0,  '".$_FILES['image']['name']."', '".$_FILES['prodimg2']['name']."', '".$_FILES['prodimg3']['name']."', '".$_FILES['prodimg4']['name']."', '".$_FILES['prodimg5']['name']."','".$_POST['price']."','".addslashes($_POST['mec_description'])."','".$_POST['weight']."',0,0,0,0,0,0)";
  //echo $sql;
  //   exit;
      $result = mysqli_query($conn, $sql) or die('Cannot ' . mysql_error());
            $lastid=mysqli_insert_id($conn);
//=======================
if($_FILES['image']['name']!="") {


    $file = $_FILES['image']['tmp_name']; 
    $sourceProperties = getimagesize($file);
    $fileNewName = time();
    $folderPath = "../menuproducts/thumb/";
    $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
    $imageType = $sourceProperties[2];


    switch ($imageType) {


        case IMAGETYPE_PNG:
            $imageResourceId = imagecreatefrompng($file); 
            $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
            imagepng($targetLayer,$folderPath. $lastid. "_1.jpg");
            
             break;


        case IMAGETYPE_GIF:
            $imageResourceId = imagecreatefromgif($file); 
            $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
            imagegif($targetLayer,$folderPath. $lastid. "_1.jpg");

            break;


        case IMAGETYPE_JPEG:
            $imageResourceId = imagecreatefromjpeg($file); 
            $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
            imagejpeg($targetLayer,$folderPath. $lastid. "_1.jpg");

            break;
            


        default:
   exit;
            break;
    }


    move_uploaded_file($file, $folderPath. $lastid. ".jpg");
}
if($_FILES['prodimg2']['name']!="") {


  $file = $_FILES['prodimg2']['tmp_name']; 
  $sourceProperties = getimagesize($file);
  $fileNewName = time();
  $folderPath = "../menuproducts/thumb/";
  $ext = pathinfo($_FILES['prodimg2']['name'], PATHINFO_EXTENSION);
  $imageType = $sourceProperties[2];


  switch ($imageType) {


      case IMAGETYPE_PNG:
          $imageResourceId = imagecreatefrompng($file); 
          $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
          imagepng($targetLayer,$folderPath. $lastid. "_2.jpg");
  
           break;


      case IMAGETYPE_GIF:
          $imageResourceId = imagecreatefromgif($file); 
          $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
          imagegif($targetLayer,$folderPath. $lastid. "_2.jpg");

          break;


      case IMAGETYPE_JPEG:
          $imageResourceId = imagecreatefromjpeg($file); 
          $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
          imagejpeg($targetLayer,$folderPath. $lastid. "_2.jpg");

          break;
  


      default:
 exit;
          break;
  }


  move_uploaded_file($file, $folderPath. $lastid. "in2.jpg");
}
if($_FILES['prodimg3']['name']!="") {


$file = $_FILES['prodimg3']['tmp_name']; 
$sourceProperties = getimagesize($file);
$fileNewName = time();
$folderPath = "../menuproducts/thumb/";
$ext = pathinfo($_FILES['prodimg3']['name'], PATHINFO_EXTENSION);
$imageType = $sourceProperties[2];


switch ($imageType) {


    case IMAGETYPE_PNG:
        $imageResourceId = imagecreatefrompng($file); 
        $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
        imagepng($targetLayer,$folderPath. $lastid. "_3.jpg");

         break;


    case IMAGETYPE_GIF:
        $imageResourceId = imagecreatefromgif($file); 
        $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
        imagegif($targetLayer,$folderPath. $lastid. "_3.jpg");

        break;


    case IMAGETYPE_JPEG:
        $imageResourceId = imagecreatefromjpeg($file); 
        $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
        imagejpeg($targetLayer,$folderPath. $lastid. "_3.jpg");

        break;



    default:
   exit;
        break;
}


move_uploaded_file($file, $folderPath. $lastid. "in3.jpg");
}
if($_FILES['prodimg4']['name']!="") {


$file = $_FILES['prodimg4']['tmp_name']; 
$sourceProperties = getimagesize($file);
$fileNewName = time();
$folderPath = "../menuproducts/thumb/";
$ext = pathinfo($_FILES['prodimg4']['name'], PATHINFO_EXTENSION);
$imageType = $sourceProperties[2];


switch ($imageType) {


  case IMAGETYPE_PNG:
      $imageResourceId = imagecreatefrompng($file); 
      $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
      imagepng($targetLayer,$folderPath. $lastid. "_4.jpg");

       break;


  case IMAGETYPE_GIF:
      $imageResourceId = imagecreatefromgif($file); 
      $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
      imagegif($targetLayer,$folderPath. $lastid. "_4.jpg");

      break;


  case IMAGETYPE_JPEG:
      $imageResourceId = imagecreatefromjpeg($file); 
      $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
      imagejpeg($targetLayer,$folderPath. $lastid. "_4.jpg");

      break;



  default:
                exit;
      break;
}


move_uploaded_file($file, $folderPath. $lastid. "in4.jpg");
}
if($_FILES['prodimg5']['name']!="") {


$file = $_FILES['prodimg5']['tmp_name']; 
$sourceProperties = getimagesize($file);
$fileNewName = time();
$folderPath = "../menuproducts/thumb/";
$ext = pathinfo($_FILES['prodimg5']['name'], PATHINFO_EXTENSION);
$imageType = $sourceProperties[2];


switch ($imageType) {


  case IMAGETYPE_PNG:
      $imageResourceId = imagecreatefrompng($file); 
      $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
      imagepng($targetLayer,$folderPath. $lastid. "_5.jpg");

       break;


  case IMAGETYPE_GIF:
      $imageResourceId = imagecreatefromgif($file); 
      $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
      imagegif($targetLayer,$folderPath. $lastid. "_5.jpg");

      break;


  case IMAGETYPE_JPEG:
      $imageResourceId = imagecreatefromjpeg($file); 
      $targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
      imagejpeg($targetLayer,$folderPath. $lastid. "_5.jpg");

      break;



  default:
              exit;
      break;
}


move_uploaded_file($file, $folderPath. $lastid. "in5.jpg");
}
?>
<script > 
window.location.replace("menu-products.php?action=addsuc");
</script>
 <?php
 }
//======================
function imageResize($imageResourceId,$width,$height) {

    $targetWidth =721;
    $targetHeight =665;

    $targetLayer=imagecreatetruecolor($targetWidth,$targetHeight);
    imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$targetWidth,$targetHeight, $width,$height);

    return $targetLayer;
}


if(isset($_POST['btn_sub_prod']))
{
   ?>
   <script > 
  window.location.replace("menu-products.php?action=addsuc");
</script>
   <?php
}
?><!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
    <!-- meta data -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="author" content="pixelstrap">
    <link rel="icon" href="assets/images/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="assets/images/favicon.png" type="image/x-icon">
    <?php include_once("include/title.php"); ?>
    <!-- Google font -->
    <link href="../../css2?family=Public+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
    <!-- Linear Icon css -->
    <link rel="stylesheet" href="assets/css/linearicon.css">
    <!-- Fontawesome css -->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/font-awesome.css">
    <!-- Themify icon css -->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/themify.css">
    <!--Dropzon css -->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/dropzone.css">
    <!-- Feather icon css-->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/feather-icon.css">
    <!-- remixicon css -->
    <link rel="stylesheet" type="text/css" href="assets/css/remixicon.css">
    <!-- Select2 css -->
    <link rel="stylesheet" type="text/css" href="assets/css/select2.min.css">
    <!-- Plugins css -->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/scrollbar.css">
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/animate.css">
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/chartist.css">
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/date-picker.css">
    <!-- Bootstrap css -->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/bootstrap.css">
    <!-- Bootstrap-tag input css -->
    <link rel="stylesheet" type="text/css" href="assets/css/vendors/bootstrap-tagsinput.css">
    <!-- App css -->
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <script>
function getstate(val) {
	//alert(val);
	$.ajax({
	type: "POST",
	url: "get_state.php",
	data:'coutrycode='+val,
	success: function(data){
		$("#subcategory").html(data);
	}
	});
}

function getcity(val) {
	//alert(val);
	$.ajax({
	type: "POST",
	url: "get_city.php",
	data:'statecode='+val,
	success: function(data){
		$("#subsubcategory").html(data);
	}
	});
}

</script>
</head>

<body>
    <!-- tap on top start -->
    <div class="tap-top">
        <span class="lnr lnr-chevron-up"></span>
    </div>
    <!-- tap on tap end -->

    <!-- page-wrapper start -->
    <div class="page-wrapper compact-wrapper" id="pageWrapper">
        <!-- Page Header Start-->
        <?php include_once("include/header.php"); ?>
        <!-- Page Header Ends-->

        <!-- Page Body start -->
        <div class="page-body-wrapper">
            <!-- Page Sidebar Start-->
            <div class="sidebar-wrapper">
                <div id="sidebarEffect"></div>
                <div>
                <?php include_once("include/nav.php"); ?>
                </div>
            </div>
            <!-- Page Sidebar Ends-->

            <div class="page-body">

                <!-- New Product Add Start -->
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="row">
                                <div class="col-sm-8 m-auto">
                                <form action="add-menu-product.php?action=add" method="post" enctype="multipart/form-data" class="theme-form theme-form-2 mega-form">
                                    <div class="card">
                                        <div class="card-body">
                                            <div class="card-header-2">
                                                <h5>Item Information</h5>
                                            </div>

                                           
                                                <div class="mb-4 row align-items-center">
                                                    <label class="form-label-title col-sm-3 mb-0">Item Name</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control" name="pname" type="text" placeholder="Item Name">
                                                    </div>
                                                </div> 

                                                <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title">Item Category</label>
                                                    <div class="col-sm-9">
                                                        <select class="js-example-basic-single w-100" onChange="getstate(this.value);" name="mec_catid" id="category">
                                                            <option value="0">Select Item Category</option>
                   <?php
					$maincat=mysqli_query($conn, "select * from menu_main_category where mec_status=1 order by orderset");$k=0;
					while($maincat1=mysqli_fetch_array($maincat))
					{
                   $k++;
					?>
                                                            <option value="<?php echo $maincat1['mec_catid'];?>"><?php echo $maincat1['mec_category_name'];?></option>
                                                        <?php } ?>
                                                        </select>
                                                    </div>
                                                </div>  
                                        </div>
                                    </div>
                                     
                                 <input class="form-control" type="hidden" name="weight" placeholder="Month"> <input class="form-control" type="hidden" name="unit_type" placeholder="Date">
                                               
                                    <div class="card">
                                        <div class="card-body">
                                            
                                                <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 form-label-title">Price</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control" type="text" name="price" placeholder="Price">
                                                    </div>
                                                </div> 
                                        </div>
                                    </div> 
                                     <div class="card">
                                        <div class="card-body">
                                            
                                                <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 form-label-title">Description</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control" type="text" name="mec_description" placeholder="Description">
                                                    </div>
                                                </div> 
                                        </div>
                                    </div> 
                                    <div class="card">
                                        <div class="card-body">
                                            <div class="card-header-2">
                                                <h5>Product Images</h5>
                                            </div>
 
                                                <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title">Image 1</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control form-choose" type="file" name="image" id="formFile" multiple="">
                                                    </div>
                                                </div>

                                            
                                        </div>
                                    </div>  
                                    <div class="card-footer text-end border-0 m-b-25 pb-0 d-flex justify-content-end">
                                        <button type="submit" name="btn_sub_prod" class="btn btn-primary me-3">Submit</button>
                                        <a href="menu-products.php">  <button class="btn btn-outline" type="button">Cancel</button></a>
                                    </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- New Product Add End -->

                <!-- footer Start -->
                <div class="container-fluid">
                <?php include_once("include/footer.php"); ?>
                </div>
                <!-- footer En -->
            </div>
            <!-- Container-fluid End -->
        </div>
        <!-- Page Body End -->
    </div>
    <!-- page-wrapper End -->

    <!-- Modal Start -->
    <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
        <div class="modal-dialog  modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-body">
                    <h5 class="modal-title" id="staticBackdropLabel">Logging Out</h5>
                    <p>Are you sure you want to log out?</p>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

                    <div class="button-box">
                        <button type="button" class="btn btn--no" data-bs-dismiss="modal">No</button>
                        <button type="button" class="btn  btn--yes btn-primary">Yes</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Modal End -->

    <!-- latest js -->
    <script src="assets/js/jquery-3.6.0.min.js"></script>

    <!-- Bootstrap js -->
    <script src="assets/js/bootstrap/bootstrap.bundle.min.js"></script>

    <!-- feather icon js -->
    <script src="assets/js/icons/feather-icon/feather.min.js"></script>
    <script src="assets/js/icons/feather-icon/feather-icon.js"></script>

    <!-- scrollbar simplebar js -->
    <script src="assets/js/scrollbar/simplebar.js"></script>
    <script src="assets/js/scrollbar/custom.js"></script>

    <!-- Sidebar js -->
    <script src="assets/js/config.js"></script>

    <!-- bootstrap tag-input js -->
    <script src="assets/js/bootstrap-tagsinput.min.js"></script>
    <script src="assets/js/sidebar-menu.js"></script>

    <!-- customizer js -->
    <script src="assets/js/customizer.js"></script>

    <!--Dropzon js -->
    <script src="assets/js/dropzone/dropzone.js"></script>
    <script src="assets/js/dropzone/dropzone-script.js"></script>

    <!-- Plugins js -->
    <script src="assets/js/notify/bootstrap-notify.min.js"></script>
    <script src="assets/js/notify/index.js"></script>

    <!-- ck editor js -->
    <script src="assets/js/ckeditor.js"></script>
    <script src="assets/js/ckeditor-custom.js"></script>

    <!-- select2 js -->
    <script src="assets/js/select2.min.js"></script>
    <script src="assets/js/select2-custom.js"></script>

    <!-- sidebar effect -->
    <script src="assets/js/sidebareffect.js"></script>

    <!-- Theme js -->
    <script src="assets/js/script.js"></script>
    <?php
	if($_GET['mec_g_id']!=5 and $_GET['mec_g_id']!=1 and $_GET['mec_g_id']!=2){
	?>
 <script src="js/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script><?php } ?>
</body>
</html>