<?php
error_reporting(0);
ob_start();
session_start();
include_once("include/dbconnect.php");
if(isset($_POST['btn_submit']))
{
    $mec_g_id = $_POST['mec_g_id'];
    $mec_title1 = $_POST['mec_title1'];
    $mec_date = $_POST['mec_date'];
    $mec_title2 = $_POST['mec_title2'];
    $mec_description1 = $_POST['mec_description1'];
    $mec_description2 = $_POST['mec_description2'];
    $gall_img1 = $_FILES['gall_img1']['name'];
    $gall_img2 = $_FILES['gall_img2']['name'];
$gall_img3 = $_FILES['gall_img3']['name'];

mysqli_query($conn, "update mec_gallery set 
mec_title1='".addslashes($_POST['mec_title1'])."',
mec_date='".addslashes($_POST['mec_date'])."',
mec_title2='".addslashes($_POST['mec_title2'])."',
mec_description1='".addslashes($_POST['mec_description1'])."',
mec_description2='".addslashes($_POST['mec_description2'])."' where mec_p_id='".$_POST['mec_p_id']."'");
 $lastid = $_POST['mec_p_id'];
 //=======================start
if($_FILES['gall_img1']['name']!="") {
    $file = $_FILES['gall_img1']['tmp_name']; 
    $sourceProperties = getimagesize($file);
    $fileNewName = time();
    $folderPath = "../products/gallery/";
    $ext = pathinfo($_FILES['gall_img1']['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['gall_img2']['name']!="") {


  $file = $_FILES['gall_img2']['tmp_name']; 
  $sourceProperties = getimagesize($file);
  $fileNewName = time();
  $folderPath = "../products/gallery/";
  $ext = pathinfo($_FILES['gall_img2']['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['gall_img3']['name']!="") {


$file = $_FILES['gall_img3']['tmp_name']; 
$sourceProperties = getimagesize($file);
$fileNewName = time();
$folderPath = "../products/gallery/";
$ext = pathinfo($_FILES['gall_img3']['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");
}
//======================end

   
header("location: category.php?action=editsuc");
}
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_submit']))
{
   ?>
   <script > 
 window.location.replace("gallery.php?mec_g_id=<?=$_POST['mec_g_id'];?>&action=editsuc");
</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">
</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">
                                    <div class="card">
                                        <div class="card-body">
                                            <div class="card-header-2">
                                            <?php
					                $cms_upt=mysqli_query($conn, "select * from mec_gall_category  where mec_g_id=".$_GET['mec_g_id']." order by orderset");
					                $cms_upt1=mysqli_fetch_array($cms_upt);
                                            ?>
                                        <h5><?php echo $cms_upt1['mec_page_tile']; ?></h5>
                                            </div>
                                            <form action="edit-gallery.php" method="post" enctype="multipart/form-data" class="theme-form theme-form-2 mega-form">
                                            <?php
	                                $edit=mysqli_query($conn, "select * from mec_gallery where mec_p_id=".$_GET['mec_p_id']); 
                                $edit1=mysqli_fetch_array($edit);
                                            ?>
<?php
if($cms_upt1['mec_title1_status']==1){
?>
                                                <div class="mb-4 row align-items-center">
                                                    <label class="form-label-title col-sm-3 mb-0">Title</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control" type="text" name="mec_title1" value="<?php echo $edit1['mec_title1']; ?>" placeholder="Title">
                                                    </div>
                                                </div> <?php } ?>
                                                <?php
if($cms_upt1['mec_title2_status']==1){
?>
                                                <div class="mb-4 row align-items-center">
                                                    <label class="form-label-title col-sm-3 mb-0">Title</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control" type="text" name="mec_title2" value="<?php echo $edit1['mec_title2']; ?>" placeholder="Title">
                                                    </div>
                                                </div> <?php } ?>
                                                <?php
if($_GET['mec_g_id']==7){
?>
                                                <div class="mb-4 row align-items-center">
                                                    <label class="form-label-title col-sm-3 mb-0">Date</label>
                                                    <div class="col-sm-9">
                                                        <input class="form-control" type="text" name="mec_date" value="<?php echo $edit1['mec_date']; ?>" placeholder="Title">
                                                    </div>
                                                </div> <?php } ?>
                                                <?php
if($cms_upt1['mec_description1_status']==1){

   if($_GET['mec_p_id']!=281 and $_GET['mec_p_id']!=27){
?>

                                                <div class="mb-4 row align-items-center">
                                                    <label class="form-label-title col-sm-3 mb-0">Description</label>
                                                    <div class="col-sm-9">
                                                        <textarea class="form-control" type="text" name="mec_description1" placeholder="Description"><?php echo $edit1['mec_description1']; ?></textarea>
                                                    </div>
                                                </div> <?php } ?> <?php } ?>
                                                <?php
if($_GET['mec_p_id']==71){
?> <div class="mb-4 row align-items-center">
<label class="form-label-title col-sm-3 mb-0">Description</label>
<div class="col-sm-9">
    <textarea class="form-control" type="text" name="mec_description2" placeholder="Description"><?php echo $edit1['mec_description2']; ?></textarea>
</div>
</div> <?php } ?>
                                                <?php
if($cms_upt1['mec_description2_status']==1){
?>
                                                <div class="mb-4 row align-items-center">
                                                    <label class="form-label-title col-sm-3 mb-0">Description</label>
                                                    <div class="col-sm-9">
                                                        <textarea class="form-control" type="text" name="mec_description2" placeholder="Description"><?php echo $edit1['mec_description2']; ?></textarea>
                                                    </div>
                                                </div> <?php } ?>
                                                <?php
if($cms_upt1['mec_img1_status']==1){
?>
                                                <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title"> Image</label>
                                                    <div class="form-group col-sm-6">
                                                        <div class="dropzone-wrapper">
                                                            <div class="dropzone-desc">
                                                                <i class="ri-upload-2-line"></i>
                                                                <p>Choose an image file or drag it here.</p>
                                                            </div>
                                                            <input type="file" name="gall_img1">
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-3">
                                                    <img src="../products/gallery/<?php echo $edit1['mec_p_id']; ?>.jpg" class="img-fluid" alt="">
</div>
                                                </div>
                                                <?php } ?>
                                                <?php
if($_GET['mec_p_id']==8 or $_GET['mec_p_id']==31 or $_GET['mec_p_id']==191 or $_GET['mec_p_id']==271 or $_GET['mec_p_id']==281){
?>
  <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title"> Image</label>
                                                    <div class="form-group col-sm-6">
                                                        <div class="dropzone-wrapper">
                                                            <div class="dropzone-desc">
                                                                <i class="ri-upload-2-line"></i>
                                                                <p>Choose an image file or drag it here.</p>
                                                            </div>
                                                            <input type="file" name="gall_img1">
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-3">
                                                    <img src="../products/gallery/<?php echo $edit1['mec_p_id']; ?>.jpg" class="img-fluid" alt="">
</div>
                                                </div>

<?php } ?>                                        <?php
if($cms_upt1['mec_img2_status']==1){
?>
<div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title"> Image 2</label>
                                                    <div class="form-group col-sm-6">
                                                        <div class="dropzone-wrapper">
                                                            <div class="dropzone-desc">
                                                                <i class="ri-upload-2-line"></i>
                                                                <p>Choose an image file or drag it here.</p>
                                                            </div>
                                                            <input type="file" name="gall_img2">
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-3">
                                                    <img src="../products/gallery/<?php echo $edit1['mec_p_id']; ?>in2.jpg" class="img-fluid" alt="">
</div>
                                                </div>
<?php } ?>
<?php
if($_GET['mec_p_id']==113){
?>
<div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title"> Image 2</label>
                                                    <div class="form-group col-sm-6">
                                                        <div class="dropzone-wrapper">
                                                            <div class="dropzone-desc">
                                                                <i class="ri-upload-2-line"></i>
                                                                <p>Choose an image file or drag it here.</p>
                                                            </div>
                                                            <input type="file" name="gall_img2">
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-3">
                                                    <img src="../products/gallery/<?php echo $edit1['mec_p_id']; ?>_2.jpg" class="img-fluid" alt="">
</div>
                                                </div>
<?php } ?>
  <?php
if($cms_upt1['mec_img3_status']==1){
?>
                                                <div class="mb-4 row align-items-center">
                                                    <label class="col-sm-3 col-form-label form-label-title"> Image 3</label>
                                                    <div class="form-group col-sm-6">
                                                        <div class="dropzone-wrapper">
                                                            <div class="dropzone-desc">
                                                                <i class="ri-upload-2-line"></i>
                                                                <p>Choose an image file or drag it here.</p>
                                                            </div>
                                                            <input type="file" name="gall_img3">
                                                        </div>
                                                    </div>
                                                    <div class="form-group col-sm-3">
                                                    <img src="../products/gallery/<?php echo $edit1['mec_p_id']; ?>_3.jpg" class="img-fluid" alt="">
</div>
                                                </div>
                                                <?php } ?>
                                                <input type="hidden" name="mec_g_id" value="<?php echo $_GET['mec_g_id'];?>">
                                                <input type="hidden" name="mec_p_id" value="<?php echo $_GET['mec_p_id'];?>">
                                                <div class="mb-4 row align-items-center"> 
                                                    <div class="col-12">
                                                        <div class="card-footer text-end border-0 pb-0 d-flex justify-content-end">
                                                            <button class="btn btn-primary me-3" type="submit" name="btn_submit">Save</button>
                                                          <a href="gallery.php?mec_g_id=<?php echo $_GET['mec_g_id'];?>">  <button type="button" class="btn btn-outline">Cancel</button></a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </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>

    <!-- 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']!="6" and $_GET['mec_g_id']!="10"){ ?> 
    <script src="nicEdit-latest.js" type="text/javascript"></script> 
 <script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
 <?php } ?>
</body>

</html>