include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
include_once '../classes/Logger.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$log = new Logger(basename($_SERVER['PHP_SELF']));
$response = array();
$log->arrayLogger($_POST, "POST Req Data");
$item_per_page = 5;
//item to display per page
if (isset($_POST['page_index'])) {
    $page_start = $_POST['page_index'];
    $page_position = ($page_start - 1) * $item_per_page;
} else {
    $page_position = $utilities->replaceZero($_POST['page_start']);
}
$chef_id = $utilities->replaceDefault($_POST['chef_id']);
$dateTime = $utilities->replaceNow();
//print_r($_POST);
try {
    $query = " SELECT food_item.item_id,\n                        food_item.`name` AS food_name,\n                        food_item.description,\n                        food_item.ingredients,\n                        food_item.preparation_method,\n                        food_item.rating AS food_rating,\n                        category.category_id,\n                        category.category_name,\n                        food_item.price,\n                        currency.currency_id,\n                        currency.currency_name,\n                        currency.currency_symbol,\n                        chef.chef_id,\n                        CONCAT(chef.f_name, ' ', chef.l_name) AS chef_name,\n                        CONCAT(chef.country_code, chef.phone_number) AS chef_phone_number,\n                        chef.image_url AS chef_image,\n                        chef.rating AS chef_rating,\n                        food_item.nutrition,\n                        COALESCE(food_item.food_image_1, '') AS food_image_1,\n                        COALESCE(food_item.food_image_2, '') AS food_image_2,\n                        COALESCE(food_item.food_image_3, '') AS food_image_3,\n                        COALESCE(food_item.food_image_4, '') AS food_image_4,\n                        food_item.log_datetime\n                FROM food_item INNER JOIN category ON food_item.category_id = category.category_id\n                         INNER JOIN currency ON food_item.currency_id = currency.currency_id\n                         INNER JOIN chef ON food_item.chef_id = chef.chef_id ";
    $query .= $chef_id > 0 ? " WHERE food_item.chef_id = {$chef_id} " : " ";
    $query .= " ORDER BY food_name ASC\n                LIMIT {$page_position}, {$item_per_page};";
    //echo $query;
    $log->info("Query:" . $query);
    $statement = $dbConnection->prepare($query);
    $sql = "SELECT * FROM food_item";
    $result = $dbConnection->query($sql);
    $row = $result->fetchAll();
    $numOfRows = count($row);
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$name = $utilities->clean($_POST['name']);
$area = $utilities->clean($_POST['area']);
$pincode = $utilities->clean($_POST['pincode']);
$latitude = $utilities->replaceZero($_POST['latitude']);
$longitude = $utilities->replaceZero($_POST['longitude']);
$log_datetime = $utilities->replaceNow();
$kitchenId = -1;
try {
    $insertQuery = "INSERT INTO " . " `kitchen` (name, area, pincode, latitude, longitude, log_datetime) " . " VALUES ('{$name}', '{$area}', '{$pincode}', '{$latitude}', '{$longitude}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $kitchenId = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $kitchenId, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
            $response = array('status' => $status, 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $status = -7;
        $error = "Exception: " . $e->getMessage();
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$user_id = $utilities->replaceZero($_POST['user_id']);
$dateTime = $utilities->replaceNow();
try {
    $query = "SELECT address.address_id,\n                    CONCAT(address.street_address, '; ', address.city, '; ',  address.state, '; ', address.country, '; ') AS address,\n                    address.landmark,\n                    address.pincode,\n                    CONCAT(address.country_code, address.phone_number) AS address_phone_number,\n                    address.is_default,\n                    `user`.user_id,\n                    CONCAT(`user`.f_name, `user`.l_name) AS user_name,\n                    `user`.image_url AS user_image\n            FROM address INNER JOIN `user` ON address.user_id = `user`.user_id\n            WHERE address.user_id  = '{$user_id}'";
    $statement = $dbConnection->prepare($query);
    try {
        if ($statement->execute($bindParams)) {
            $data = $statement->fetchAll(PDO::FETCH_ASSOC);
            $statement->closeCursor();
            $response = array('status' => 0, 'data' => $data, 'desc' => 'success');
        } else {
            $errorCode = -99;
            $dbError = $statement->errorInfo();
            $statement->closeCursor();
            $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $errorCode = -7;
        $statement->closeCursor();
        $error = "Exception: " . $e->getMessage();
        $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'PDO exception occured' . $error);
    }
} catch (PDOExecption $e) {
    $errorCode = -8;
$basket_code = uniqid("BSKT_");
/*
 * Json array with id, qunatity in this format.
 * [
 *  {'item':1,'name': 'xyz','quantity':2,'price':200},
 *  {'item':2,'name': 'abc','quantity':1,'price':150},
 *  {'item':3,'name': 'qwert','quantity':1,'price':20},
 *  {'item':4,'name': 'poiuyt','quantity':1,'price':30}
 * ]
 */
$item_quantity_price_json = $utilities->clean($_POST['item_quantity_price_json']);
$user_id = $utilities->replaceOne($_POST['user_id']);
$time_slot_id = $utilities->replaceOne($_POST['time_slot_id']);
$status = $utilities->replaceOne($_POST['status']);
$date = $utilities->replaceToday($_POST['date']);
$address_id = $utilities->replaceZero($_POST['address_id']);
$order_type_id = $utilities->replaceZero($_POST['order_type_id']);
$log_datetime = $utilities->replaceNow();
$order_id = -1;
try {
    $insertQuery = "INSERT INTO " . " `order` (basket_code, user_id, item_quantity_price_json, time_slot_id, status, date, address_id, log_datetime) " . " VALUES ('{$basket_code}', '{$user_id}', '{$item_quantity_price_json}', '{$time_slot_id}', '{$status}', '{$date}', '{$address_id}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $order_id = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $order_id, 'basket_code' => $basket_code, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$street_address = $utilities->clean($_POST['street_address']);
$landmark = $utilities->clean($_POST['landmark']);
$city = $utilities->clean($_POST['city']);
$state = $utilities->clean($_POST['state']);
$country = $utilities->clean($_POST['country']);
$pincode = $utilities->clean($_POST['pincode']);
$phone_number = $utilities->clean($_POST['phone_number']);
$country_code = $utilities->clean($_POST['country_code']);
$is_default = $utilities->replaceZero($_POST['is_default']);
$user_id = $utilities->replaceZero($_POST['user_id']);
$log_datetime = $utilities->replaceNow();
$addressId = -1;
try {
    $insertQuery = "INSERT INTO " . " `address` (street_address, landmark, city, state, country, pincode, phone_number, country_code, is_default, user_id, log_datetime) " . " VALUES ('{$street_address}', '{$landmark}', '{$city}', '{$state}', '{$country}', '{$pincode}', '{$phone_number}', '{$country_code}', '{$is_default}', '{$user_id}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $addressId = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $addressId, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$f_name = $utilities->clean($_POST['f_name']);
$l_name = $utilities->clean($_POST['l_name']);
$country_code = $utilities->replaceDefaultCountryCode($_POST['country_code']);
$phone_number = $utilities->clean($_POST['phone_number']);
$image_url = $utilities->clean($_POST['image_url']);
$rating = $utilities->replaceZero($_POST['rating']);
$log_datetime = $utilities->replaceNow();
$chefId = -1;
try {
    $insertQuery = "INSERT INTO " . " `chef` (f_name, l_name, country_code, phone_number, image_url, rating, log_datetime) " . " VALUES ('{$f_name}', '{$l_name}', '{$country_code}', '{$phone_number}', '{$image_url}', '{$rating}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $chefId = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $chefId, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
            $response = array('status' => $status, 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $status = -7;
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$food_item_id = $utilities->clean($_POST['food_id']);
$user_id = $utilities->clean($_POST['user_id']);
$rating = $utilities->replaceZero($_POST['rating']);
$review = $utilities->replaceZero($_POST['review']);
$review_detail = $utilities->replaceZero($_POST['review_detail']);
$log_datetime = $utilities->replaceNow();
$likeId = -1;
$dataReviewd = array();
try {
    $query = "SELECT COUNT(*) AS is_reviewed\n                FROM `likes`\n                WHERE user_id = '{$user_id}'\n                    AND food_item_id = '{$food_item_id}';";
    $statement = $dbConnection->prepare($query);
    try {
        if ($statement->execute($bindParams)) {
            $dataReviewd = $statement->fetchAll(PDO::FETCH_ASSOC);
            $statement->closeCursor();
        } else {
            $errorCode = -99;
            $dbError = $statement->errorInfo();
            $statement->closeCursor();
            $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $errorCode = -7;
        $statement->closeCursor();
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$isUpdate = $utilities->replaceZero($_POST['is_update_address']);
$address_id = $utilities->clean($_POST['address_id']);
$street_address = $utilities->clean($_POST['street_address']);
$landmark = $utilities->clean($_POST['landmark']);
$city = $utilities->clean($_POST['city']);
$state = $utilities->clean($_POST['state']);
$pincode = $utilities->clean($_POST['pincode']);
$phone_number = $utilities->clean($_POST['phone_number']);
$is_default = $utilities->replaceZero($_POST['is_default']);
$user_id = $utilities->clean($_POST['user_id']);
$log_datetime = $utilities->replaceNow();
$addressId = -1;
try {
    if ($isUpdate == 0) {
        $query = "INSERT INTO " . " `address` (street_address, landmark, city, state, country, pincode, phone_number, country_code, is_default, user_id, log_datetime) " . " VALUES ('{$street_address}', '{$landmark}', '{$city}','{$state}', 'country', '{$pincode}', '{$phone_number}', '+91', '{$is_default}', '{$user_id}' ,'{$log_datetime}')";
    } else {
        $query = "UPDATE `address` SET" . " street_address = '{$street_address}', " . " landmark = '{$landmark}', " . " city = '{$city}', " . " state = '{$state}', " . " country = '{$country}', " . " pincode = '{$pincode}', " . " phone_number = '{$phone_number}', " . " country_code = '+91', " . " is_default = '{$is_default}', " . " log_datetime = '{$log_datetime}'  " . " WHERE address_id = '{$address_id}';";
    }
    $statement = $dbConnection->prepare($query);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $addressId = $isUpdate == 0 ? $dbConnection->lastInsertId() : $address_id;
            $dbConnection->commit();
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$item_id = $utilities->replaceZero($_POST['item_id']);
$serving_id = $utilities->replaceZero($_POST['serving_id']);
$available_for = $utilities->replaceZero($_POST['available_for']);
$order_count = $utilities->replaceZero($_POST['order_count']);
$date = $utilities->replaceZero($_POST['date']);
$log_datetime = $utilities->replaceNow();
$itemServingMappingId = -1;
try {
    $insertQuery = "INSERT INTO " . " `item_serving_mapping` (item_id, serving_id, available_for, order_count, date, log_datetime) " . " VALUES ('{$item_id}', '{$serving_id}', '{$available_for}', '{$order_count}', '{$date}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $itemServingMappingId = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $itemServingMappingId, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
            $response = array('status' => $status, 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $status = -7;
        $error = "Exception: " . $e->getMessage();
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$name = $utilities->clean($_POST['name']);
$description = $utilities->clean($_POST['description']);
$ingredients = $utilities->clean($_POST['ingredients']);
$preparation_method = $utilities->clean($_POST['preparation_method']);
$nutrition = $utilities->clean($_POST['nutrition']);
$food_image_1 = $utilities->clean($_POST['food_image_1']);
$food_image_2 = $utilities->clean($_POST['food_image_2']);
$food_image_3 = $utilities->clean($_POST['food_image_3']);
$food_image_4 = $utilities->clean($_POST['food_image_4']);
$food_image_5 = $utilities->clean($_POST['food_image_5']);
$food_image_6 = $utilities->clean($_POST['food_image_6']);
$rating = $utilities->replaceZero($_POST['rating']);
$price = $utilities->replaceZero($_POST['price']);
$currency_id = $utilities->replaceOne($_POST['currency_id']);
$chef_id = $utilities->replaceZero($_POST['chef_id']);
$category_id = $utilities->replaceOne($_POST['category_id']);
$log_datetime = $utilities->replaceNow();
$foodId = -1;
try {
    $insertQuery = "INSERT INTO " . " `food_item` (name, description, ingredients, preparation_method, nutrition, food_image_1,food_image_2,food_image_3, food_image_4, food_image_5, food_image_6, rating, price, currency_id, chef_id, category_id, log_datetime) " . " VALUES ('{$name}', '{$description}', '{$ingredients}', '{$preparation_method}', '{$nutrition}', '{$food_image_1}', '{$food_image_2}','{$food_image_3}','{$food_image_4}','{$food_image_5}','{$food_image_6}', '{$rating}', '{$price}', '{$currency_id}', '{$chef_id}', '{$category_id}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $foodId = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $foodId, 'desc' => 'Success');
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$user_id = $utilities->replaceZero($_POST['user_id']);
$item_d = $utilities->replaceZero($_POST['item_d']);
$rating = $utilities->replaceZero($_POST['rating']);
$log_datetime = $utilities->replaceNow();
$user_item_rating = -1;
try {
    $insertQuery = "INSERT INTO " . " `user_item_rating` (user_id, item_d, rating, log_datetime) " . " VALUES ('{$user_id}', '{$item_d}', '{$rating}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $user_item_rating = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $user_item_rating, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
            $response = array('status' => $status, 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $status = -7;
        $error = "Exception: " . $e->getMessage();
        $response = array('status' => $status, 'desc' => 'PDO exception occured' . $error);
    }
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$user_id = $utilities->replaceZero($_POST['user_id']);
$item_id = $utilities->replaceZero($_POST['item_id']);
$serving_id = $utilities->replaceZero($_POST['serving_id']);
$preferredId = -1;
try {
    $insertQuery = "INSERT INTO " . " `preffered_list` (user_id, item_id, serving_id, log_datetime) " . " VALUES ('{$user_id}', '{$item_id}', '{$serving_id}', '{$log_datetime}')";
    $statement = $dbConnection->prepare($insertQuery);
    try {
        $dbConnection->beginTransaction();
        if ($statement->execute()) {
            $preferredId = $dbConnection->lastInsertId();
            $dbConnection->commit();
            $response = array('status' => $preferredId, 'desc' => 'Success');
        } else {
            $status = -99;
            $dbError = $statement->errorInfo();
            $response = array('status' => $status, 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $status = -7;
        $error = "Exception: " . $e->getMessage();
        $response = array('status' => $status, 'desc' => 'PDO exception occured' . $error);
    }
    $statement->closeCursor();
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$page_start = $utilities->replaceZero($_POST['page_start']);
$order_date = $utilities->replaceToday($_POST['order_date']);
$flag_category = $utilities->replaceZero($_POST['flag_category']);
try {
    $query = "SELECT `order`.basket_code,\n                        `user`.user_id,\n                        CONCAT(`user`.f_name, ' ', `user`.l_name) AS user_name,\n                        CONCAT(`user`.country_code, `user`.phone_number) AS user_phone_number,\n                        `user`.image_url AS user_image_url,\n                        `order`.item_quantity_price_json,\n                        `order`.date,\n                        `order`.flag_category,\n                        address.street_address,\n                        address.landmark,\n                        address.city,\n                        address.state,\n                        address.country,\n                        address.pincode,\n                        CONCAT(address.country_code, address.phone_number) AS delivery_address_phone_number,\n                        time_slot.time_slot_name,\n                        time_slot.time_slot_start,\n                        time_slot.time_slot_end,\n                        `order`.log_datetime AS order_placed_datetime,\n                        `status`.status_id,\n                        `status`.`status`\n                FROM `order` INNER JOIN `user` ON `order`.user_id = `user`.user_id\n                         INNER JOIN address ON `order`.address_id = address.address_id\n                         INNER JOIN time_slot ON `order`.time_slot_id = time_slot.time_slot_id\n                         INNER JOIN `status` ON `order`.`status` = `status`.status_id\n                WHERE `order`.date = '{$order_date}'";
    $query .= $flag_category == 0 ? "" : " AND flag_category = '{$flag_category}' ";
    $query .= "ORDER BY order_placed_datetime DESC\n                LIMIT {$page_start}, 25";
    $statement = $dbConnection->prepare($query);
    try {
        if ($statement->execute($bindParams)) {
            $data = $statement->fetchAll(PDO::FETCH_ASSOC);
            $statement->closeCursor();
            $response = array('status' => 0, 'data' => $data, 'desc' => 'success');
        } else {
            $errorCode = -99;
            $dbError = $statement->errorInfo();
            $statement->closeCursor();
            $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $errorCode = -7;
        $statement->closeCursor();
        $error = "Exception: " . $e->getMessage();
        $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'PDO exception occured' . $error);
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$bill_code = uniqid("BILL_");
$bill_pay_through = $utilities->clean($_POST['bill_pay_through']);
$bill_date = $utilities->replaceToday($_POST['bill_date']);
$bill_discount = $utilities->clean($_POST['bill_discount']);
$bill_total_amount = $utilities->clean($_POST['bill_total_amount']);
$user_name = $utilities->clean($_POST['user_name']);
$user_email = $utilities->clean($_POST['user_email']);
$user_phone_number = $utilities->clean($_POST['user_phone_number']);
$use_delivery_address = $utilities->clean($_POST['use_delivery_address']);
$basket_code = $utilities->clean($_POST['basket_code']);
$item_quantity_price_json = $utilities->clean($_POST['item_quantity_price_json']);
$is_bill_payed = $utilities->replaceZero($_POST['is_bill_payed']);
$log_datetime = $utilities->replaceNow();
//Calculating bill amount...
$basketQunatityArray = array();
$totalAmount = 0;
$bill_item_count = 0;
$orderJSONArray = json_decode($item_quantity_price_json);
foreach ($orderJSONArray as $foodItem) {
    $subTotalPrice = $foodItem['qunatity'] * $foodItem['price'];
    $bill_item_count++;
    array_push($basketQunatityArray, array('item_name' => $foodItem['name'], 'qunatity' => $foodItem['qunatity'], 'unit_price' => $foodItem['price'], 'sub_total_price' => $subTotalPrice));
    $totalAmount += $subTotalPrice;
}
$bill_amount = $totalAmount;
$item_quantity_bill_json = json_encode($basketQunatityArray);
$billId = -1;