<?php
require_once('../redd/lib/table-traits.php');
require_once('../redd/lib/basic-function.php');
require_once('../' . $basicFunctn->admin_url . '/lib/mailing/emails.php');
require_once('../' . $basicFunctn->admin_url . '/lib/user-functions.php');
require_once('../' . $basicFunctn->admin_url . '/lib/deposit-functions.php');
require_once('../' . $basicFunctn->admin_url . '/lib/package-functions.php');
require_once('../' . $basicFunctn->admin_url . '/lib/withdraw-functions.php');
require_once('../' . $basicFunctn->admin_url . '/lib/support-functions.php');
// require_once('../' . $basicFunctn->admin_url . '/lib/kyc-functions.php');
// require_once('../' . $basicFunctn->admin_url . '/lib/testimonial-functions.php');
require_once('../' . $basicFunctn->admin_url . '/lib/wallet-functions.php');
require_once('../' . $basicFunctn->admin_url . '/lib/PurchaseController.php');

if (isset($_POST['edit_full_name']) && isset($_POST['edit_country'])) {
    $msg = $user->edit($_POST['edit_full_name'], $_POST['edit_country'], $_POST['edit_address'], $_POST['edit_email'], $_POST['edit_phone'], $_SESSION[$basicFunctn->user_session]);
    print_r(json_encode($msg));
}
if (isset($_POST['create_deposit_investment'])) {
    $msg = $deposit->create($_POST['create_deposit_investment'], $_POST['currency'], $_POST['package'], $_POST['amount']);
    print_r(json_encode($msg));
}
if (isset($_POST['create_withdrawal_invest'])) {
    $msg = $withdraw->interest($_POST['create_withdrawal_invest'], $_POST['amount']);
    print_r(json_encode($msg));
}
if (isset($_POST['create_withdrawal_bonus'])) {
    $referrer_exist = $basicFunctn->getDataDlt($_POST['create_withdrawal_bonus'], $basicFunctn->referrer_bonus_tb);
    if (count($referrer_exist) > 0) {
        $msg = $withdraw->referrer_bonus($_POST['create_withdrawal_bonus'], $_POST['amount']);
    } else {
        $msg = $withdraw->free_bonus($_POST['create_withdrawal_bonus'], $_POST['amount']);
    }
    print_r(json_encode($msg));
}
if (isset($_POST['create_ticket_title'])) {
    $msg = $support->create($_POST['create_ticket_title'], $_POST['message'], $_SESSION[$basicFunctn->user_session]);
    print_r(json_encode($msg));
}
if (isset($_FILES['user_profile_img'])) {
    if (!empty($_FILES['user_profile_img'])) {
        $msg = $user->profile_image($_FILES['user_profile_img'], $_POST['user_profile_id']);
        print_r(json_encode($msg));
    } else {
        $msg = $user->profile_image(null, $_POST['user_profile_id']);
        print_r(json_encode($msg));
    }
} elseif (empty($_FILES) && isset($_POST['user_profile_id'])) {
    $msg = $user->profile_image(null, $_POST['user_profile_id']);
    print_r(json_encode($msg));
}
if (isset($_POST['add_wallet_id'])) {
    $msg = $user->add_wallet_address($_POST['add_wallet_id'], $_POST['address']);
    print_r(json_encode($msg));
}
if (isset($_POST['reply_ticket_title'])) {
    $msg = $support->create_Reply($_POST['reply_ticket_title'], $_POST['message'], $_POST['main_id'], $_SESSION[$basicFunctn->user_session]);
    print_r(json_encode($msg));
}
// if (isset($_POST['kyc_label']) || isset($_FILES['kyc_file'])) {
//     $kyc_exist = $kyc->selectWhereDlt($basicFunctn->kyc_validation_tb, 'user_id', $_SESSION[$basicFunctn->user_session]);
//     if (count($kyc_exist) < 1) {
//         $msg = $kyc->create($_POST['kyc_label'], $_FILES['kyc_file'], $_SESSION[$basicFunctn->user_session]);
//         print_r(json_encode($msg));
//     } else {
//         $msg = $kyc->update($_POST['kyc_label'], $_FILES['kyc_file'], $_SESSION[$basicFunctn->user_session]);
//         print_r(json_encode($msg));
//     }
// }
if (isset($_POST['forgot_pass_email'])) {
    $user_exist = $user->forgot_password($_POST['forgot_pass_email']);
    if ($user_exist['error'] == 1) {
        print_r(json_encode($user_exist));
        return;
    } else {
        // print_r(json_encode($user_exist));return;
        $msg = $user->passwordRecovery($_POST['forgot_pass_email'], $user_exist['user_id']);
        print_r(json_encode($msg));
    }
}
if (isset($_FILES['testimonial_file'])) {
    $msg = $testimonial->create($_SESSION[$basicFunctn->user_session], $_FILES['testimonial_file']);
    print_r(json_encode($msg));
}

if (isset($_POST['top_up_coin_id'])) {
    $msg = $wallet->user_top_up($_POST['top_up_coin_id'], $_POST['amt_in_usd']);
    print_r(json_encode($msg));
}



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