<?php
require_once('../lib/table-traits.php');
require_once('../lib/basic-function.php');
require_once('../lib/mailing/emails.php');
require_once('../lib/user-functions.php');
require_once('../lib/investment-plan-functions.php');
require_once('../lib/deposit-functions.php');
require_once('../lib/package-functions.php');
require_once('../lib/currency-functions.php');
require_once('../lib/withdraw-functions.php');
require_once('../lib/support-functions.php');
require_once('../lib/settings-functions.php');
require_once('../lib/admin-functions.php');
require_once('../lib/wallet-functions.php');
require_once('../lib/CategoryController.php');
require_once('../lib/SubCategoryController.php');
require_once('../lib/ProductController.php');
require_once('../lib/PurchaseController.php');

// print_r(json_encode($_POST));return;

if (isset($_POST['sign_in_email'])) {
    $msg = $basicFunctn->OneWayLoginAuth($_POST['sign_in_email'], $_POST['password'], $basicFunctn->admin_session, $basicFunctn->admin_tb);
    print_r(json_encode($msg));
}

if (isset($_POST['create_investment_plan'])) {
    $msg = $investment_plan->create($_POST['create_investment_plan']);
    print_r(json_encode($msg));
}
if (isset($_POST['create_package_name'])) {
    $msg = $package->create($_POST['create_package_name'], $_POST['investment'], $_POST['min'], $_POST['max'], $_POST['total_percentage'], $_POST['no_of_days']);
    print_r(json_encode($msg));
}
if (isset($_POST['create_currency'])) {
    $msg = $currency->create($_POST['create_currency'], $_POST['address'], $_POST['symbol']);
    print_r(json_encode($msg));
}
if (isset($_POST['confirm_deposit_id'])) {
    $msg = $deposit->confirm($_POST['confirm_deposit_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['end_txn_id'])) {
    $msg = $deposit->end_txn($_POST['end_txn_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['unconfirm_txn_id'])) {
    $msg = $deposit->unconfirm($_POST['unconfirm_txn_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_txn_id'])) {
    $msg = $deposit->delete($_POST['delete_txn_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['edit_deposit_txn_id'])) {
    $msg = $deposit->edit($_POST['edit_deposit_txn_id'], $_POST['status'], $_POST['interest']);
    print_r(json_encode($msg));
}
if (isset($_POST['block_user_id'])) {
    $msg = $user->block($_POST['block_user_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['unblock_user_id'])) {
    $msg = $user->unblock($_POST['unblock_user_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_user_id'])) {
    $msg = $user->delete($_POST['delete_user_id']);
    print_r(json_encode($msg));
}

if (isset($_POST['edit_user_name'])) {
    $msg = $user->edit($_POST['edit_user_name'], $_POST['country'], $_POST['address'], $_POST['email'], $_POST['phone'], $_POST['user_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['reply_ticket_title'])) {
    $msg = $support->create_reply_admin($_POST['reply_ticket_title'], $_POST['message'], $_POST['main_id'], $_POST['user_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['set_referrer_percent'])) {
    $msg = $settings->affiliate_percent($_POST['set_referrer_percent']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_coin_id'])) {
    $msg = $currency->delete($_POST['delete_coin_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['edit_coin_id'])) {
    $msg = $currency->edit($_POST['edit_coin_id'], $_POST['name'], $_POST['symbol'], $_POST['address']);
    print_r(json_encode($msg));
}
if (isset($_POST['edit_invest_id'])) {
    $msg = $investment_plan->edit($_POST['edit_invest_id'], $_POST['name']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_investment_id'])) {
    $msg = $investment_plan->delete($_POST['delete_investment_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_package_id'])) {
    $msg = $package->delete($_POST['delete_package_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['edit_package_id'])) {
    $msg = $package->edit($_POST['edit_package_id'], $_POST['name'], $_POST['investment'], $_POST['min'], $_POST['max'], $_POST['total_percentage'], $_POST['no_of_days']);
    print_r(json_encode($msg));
}
if (isset($_POST['create_admin_name'])) {
    $msg = $admin->create($_POST['create_admin_name'], $_POST['email'], $_POST['password'], $_POST['c_password'], $_POST['level']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_admin_id'])) {
    $msg = $admin->delete($_POST['delete_admin_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['block_admin_id'])) {
    $msg = $admin->block($_POST['block_admin_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['unblock_admin_id'])) {
    $msg = $admin->unblock($_POST['unblock_admin_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['top_up_user_id'])) {
    $msg = $wallet->admin_top_up($_POST['amount'], $_POST['top_up_user_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['withdraw_balance_user_id'])) {
    $msg = $wallet->admin_withdraw_from_balance($_POST['amount'], $_POST['withdraw_balance_user_id']);
    print_r(json_encode($msg));
}

if (isset($_POST['wallet_confirm_deposit_id'])) {
    $msg = $wallet->confirm($_POST['wallet_confirm_deposit_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['wallet_unconfirm_txn_id'])) {
    $msg = $wallet->unconfirm($_POST['wallet_unconfirm_txn_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['wallet_delete_txn_id'])) {
    $msg = $wallet->delete($_POST['wallet_delete_txn_id']);
    print_r(json_encode($msg));
}

if (isset($_POST['withdraw_paid_id'])) {
    $msg = $wallet->confirm_withdrawal($_POST['withdraw_paid_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['withdraw_pending_id'])) {
    $msg = $wallet->unconfirm($_POST['withdraw_pending_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['withdraw_delete_id'])) {
    $msg = $wallet->delete($_POST['withdraw_delete_id']);
    print_r(json_encode($msg));
}


if (isset($_POST['create_category_name'])) {
    $msg = $category->create($_POST['create_category_name']);
    print_r(json_encode($msg));
}
if (isset($_POST['update_category_id']) && isset($_POST['update_category_name'])) {
    $msg = $category->update($_POST['update_category_id'], $_POST['update_category_name']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_category_id'])) {
    $msg = $category->delete($_POST['delete_category_id']);
    print_r(json_encode($msg));
}


if (isset($_POST['create_subcategory_name'])) {
    $msg = $subCategory->create($_POST['create_subcategory_name'], $_POST['create_category_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['update_subcategory_id']) && isset($_POST['update_subcategory_name'])) {
    $msg = $subCategory->update($_POST['update_subcategory_id'], $_POST['update_subcategory_name'], $_POST['update_category_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_subcategory_id'])) {
    $msg = $subCategory->delete($_POST['delete_subcategory_id']);
    print_r(json_encode($msg));
}



if (isset($_POST['create_product_status'])) {
    $msg = $product->create($_POST['create_category_id'], $_POST['create_subcategory_id'], $_POST['create_product_status'], $_POST['type'], $_POST['includes'], $_POST['balance'], $_POST['price']);
    print_r(json_encode($msg));
}
if (isset($_POST['update_product_id'])) {
    $msg = $product->update($_POST['update_product_id'], $_POST['update_category_id'], $_POST['update_subcategory_id'], $_POST['status'], $_POST['type'], $_POST['includes'], $_POST['balance'], $_POST['price']);
    print_r(json_encode($msg));
}
if (isset($_POST['delete_product_id'])) {
    $msg = $product->delete($_POST['delete_product_id']);
    print_r(json_encode($msg));
}


if (isset($_POST['get_category_id'])) {
    $msg = $category->get_sub_categories($_POST['get_category_id']);
    print_r(json_encode($msg));
}

if (isset($_POST['purchase_status_id'])) {
    $msg = $purchase->status($_POST['purchase_status_id']);
    print_r(json_encode($msg));
}

if (isset($_FILES['user_profile_img'])) {
    if (!empty($_FILES['user_profile_img'])) {
        $msg = $product->upload_log($_FILES['user_profile_img'], $_POST['product_id']);
        print_r(json_encode($msg));
    } else {
        $msg = $product->upload_log(null, $_POST['product_id']);
        print_r(json_encode($msg));
    }
} elseif (empty($_FILES) && isset($_POST['product_id'])) {
    $msg = $product->upload_log(null, $_POST['product_id']);
    print_r(json_encode($msg));
}