HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/faithlinkint/control-panel/post-and-get/
Upload File :
Current File : /home/islapiiu/sites/faithlinkint/control-panel/post-and-get/ingredients.php
<?php

include_once(dirname(__FILE__) . '/../../class/include.php');



if (isset($_POST['create'])) {

    $INGREDIENTS = new Ingredients(NULL);
    $VALID = new Validator();

    $INGREDIENTS->product = $_POST['id'];
    $INGREDIENTS->caption = $_POST['caption'];

    $dir_dest = '../../upload/product-type/product/ingredients/';
   
    $handle = new Upload($_FILES['image']);
    $imgName = null;
    $img = Helper::randamId();


    if ($handle->uploaded) {

        $handle->image_resize = true;

        $handle->file_new_name_body = TRUE;

        $handle->file_overwrite = TRUE;

        $handle->file_new_name_ext = 'jpg';

        $handle->image_ratio_crop = 'C';

        $handle->file_new_name_body = $img;

        $handle->image_x = 250;

        $handle->image_y = 230;



        $handle->Process($dir_dest);



        if ($handle->processed) {

            $info = getimagesize($handle->file_dst_pathname);

            $imgName = $handle->file_dst_name;
        }


    }



    $INGREDIENTS->image_name = $imgName;



    $VALID->check($INGREDIENTS, [
        'caption' => ['required' => TRUE],
        'image_name' => ['required' => TRUE]
    ]);



    if ($VALID->passed()) {

        $INGREDIENTS->create();



        if (!isset($_SESSION)) {

            session_start();
        }

        $VALID->addError("Your data was saved successfully", 'success');

        $_SESSION['ERRORS'] = $VALID->errors();



        header('Location: ' . $_SERVER['HTTP_REFERER']);
    } else {



        if (!isset($_SESSION)) {

            session_start();
        }



        $_SESSION['ERRORS'] = $VALID->errors();



        header('Location: ' . $_SERVER['HTTP_REFERER']);
    }
}



if (isset($_POST['update'])) {


    $dir_dest = '../../upload/product-type/product/ingredients/';
    

    $handle = new Upload($_FILES['image']);



    $img = $_POST ["oldImageName"];



    if ($handle->uploaded) {

        $handle->image_resize = true;

        $handle->file_new_name_body = TRUE;

        $handle->file_overwrite = TRUE;

        $handle->file_new_name_ext = FALSE;

        $handle->image_ratio_crop = 'C';

        $handle->file_new_name_body = $img;

        $handle->image_x = 250;

        $handle->image_y = 230;



        $handle->Process($dir_dest);



        if ($handle->processed) {

            $info = getimagesize($handle->file_dst_pathname);

            $img = $handle->file_dst_name;
        }

    }

    $INGREDIENTS = new Ingredients($_POST['id']);



    $INGREDIENTS->image_name = $_POST['oldImageName'];

    $INGREDIENTS->caption = $_POST['caption'];



    $VALID = new Validator();

    $VALID->check($INGREDIENTS, [
        'caption' => ['required' => TRUE],
        'image_name' => ['required' => TRUE]
    ]);



    if ($VALID->passed()) {

        $INGREDIENTS->update();



        if (!isset($_SESSION)) {

            session_start();
        }

        $VALID->addError("Your changes saved successfully", 'success');

        $_SESSION['ERRORS'] = $VALID->errors();



        header('Location: ' . $_SERVER['HTTP_REFERER']);
    } else {



        if (!isset($_SESSION)) {

            session_start();
        }



        $_SESSION['ERRORS'] = $VALID->errors();



        header('Location: ' . $_SERVER['HTTP_REFERER']);
    }
}



if (isset($_POST['save-data'])) {



    foreach ($_POST['sort'] as $key => $img) {

        $key = $key + 1;



        $INGREDIENTS = Ingredients::arrange($key, $img);



        header('Location: ' . $_SERVER['HTTP_REFERER']);
    }
}