<?php
require "afritlk/vendor/autoload.php";

use AfricasTalking\SDK\AfricasTalking;

$username = AFRI_USERNAME;
$apiKey   = AFRI_API_KEY;
$AT = new AfricasTalking($username, $apiKey);
$sms = $AT->sms();
$voice = $AT->voice();
function sendSMS($receiver, $message)
{
    global $sms;
    $sms->send(['to' => $receiver, 'message' => $message, 'from' => '34461']);
}
include "PHPMailer/PHPMailerAutoload.php";
$mail = new PHPMailer();
function sendMail($from, $from_name, $subject, $body)
{
    global $mail;
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';
    $mail->Host = MAILER_HOST;
    $mail->Port = 465;
    $mail->Username = MAILER_EMAIL;
    $mail->Password = MAILER_PASSWORD;
    $mail->IsHTML(true);
    $mail->From = MAILER_EMAIL;
    $mail->FromName = $from_name;
    $mail->Sender = $from;
    $mail->AddReplyTo($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;

    return $mail;
}
function getCallToken($user)
{
    $url = "https://webrtc.africastalking.com/capability-token/request";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $headers = array(
        "apiKey: " . AFRI_API_KEY,
        "Content-Type: application/json",
    );
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $data = json_encode([
        "username" => AFRI_USERNAME,
        "clientName" => $user,
        "phoneNumber" => "+23417003477"
    ]);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $resp = curl_exec($curl);
    curl_close($curl);
    file_put_contents("callLogs", $resp . "\n");
    $respo = json_decode($resp);
    if (isset($respo->token)) {
        return $respo->token;
    } else {
        return "";
    }
}
function getBal($user)
{
    global $conn;
    $checkBal = mysqli_query($conn, "SELECT amount FROM balance WHERE user = '$user'");
    $r = mysqli_fetch_array($checkBal);
    return $r['amount'];
}
function isTransactionPinCorrect($pin1, $pin2)
{
    if ($pin1 == $pin2)
        return true;
    else
        return false;
}
function getUserDetails($user)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM users WHERE email = '$user'");
    $r = mysqli_fetch_array($checkDet);
    return $r;
}
function getUserDetailsByPhoneNumber($user)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM users WHERE phone = '$user'");
    if (mysqli_num_rows($checkDet) == 1) {
        $r = mysqli_fetch_array($checkDet);
        return $r;
    } else
        return false;
}
function getPlanDetails($plan_id)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM plans WHERE id = '$plan_id'");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getCablePlanDetails($plan_id)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM cableplans WHERE cable_id = '$plan_id'");
    $r = mysqli_fetch_assoc($checkDet);
    return $r;
}
function getAvalability($service)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM availability");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r[$service];
    } else {
        return false;
    }
}
function getRolePrice($role)
{
    if ($role == "SMART") {
        $price = "pamount";
    } elseif ($role == "API") {
        $price = "pamount_api";
    } elseif ($role == "VENDOR") {
        $price = "pamount_vendor";
    } else {
        $price = "pamount";
    }

    return $price;
}
function checkPriority($service)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM prioritySelection");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r[$service];
    } else {
        return false;
    }
}
function getWebConfigs()
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM webconfiguration");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getPaymentsConfigs()
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM paymentconfigs");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getCharges()
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM charges");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getBill($id)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM `disco` WHERE vtpass = '$id'");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function vendingRange()
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM vendingRange");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getNetworkID($archi, $networkName)
{
    if ($archi == "WIAXY") {
        if ($networkName == "mtn")
            $networkID = "mtn";
        elseif ($networkName == "glo")
            $networkID = "glo";
        elseif ($networkName == "etisalat")
            $networkID = "etisalat";
        elseif ($networkName == "airtel")
            $networkID = "airtel";
        else
            $networkID = "";
    } elseif ($archi == "MSORG") {
        if ($networkName == "mtn")
            $networkID = 1;
        elseif ($networkName == "glo")
            $networkID = 2;
        elseif ($networkName == "etisalat")
            $networkID = 3;
        elseif ($networkName == "airtel")
            $networkID = 4;
        else
            $networkID = 0;
    } elseif ($archi == "VTPASS") {
        if ($networkName == "mtn")
            $networkID = "mtn";
        elseif ($networkName == "glo")
            $networkID = "glo";
        elseif ($networkName == "etisalat")
            $networkID = "etisalat";
        elseif ($networkName == "airtel")
            $networkID = "airtel";
        else
            $networkID = "";
    } else {
        if ($networkName == "mtn")
            $networkID = 1;
        elseif ($networkName == "glo")
            $networkID = 3;
        elseif ($networkName == "etisalat")
            $networkID = 4;
        elseif ($networkName == "airtel")
            $networkID = 2;
        else
            $networkID = 0;
    }
    return $networkID;
}
function getCableID($archi, $cableName)
{
    if ($archi == "WIAXY") {
        if ($cableName == "startimes")
            $cableID = "startimes";
        elseif ($cableName == "dstv")
            $cableID = "dstv";
        elseif ($cableName == "gotv")
            $cableID = "gotv";
        else
            $cableID = "";
    } elseif ($archi == "MSORG") {
        if ($cableName == "startimes")
            $cableID = "STARTIME";
        elseif ($cableName == "dstv")
            $cableID = "DSTV";
        elseif ($cableName == "gotv")
            $cableID = "GOTV";
        else
            $cableID = "";
    } elseif ($archi == "VTPASS") {
        if ($cableName == "startimes")
            $cableID = "startimes";
        elseif ($cableName == "dstv")
            $cableID = "dstv";
        elseif ($cableName == "gotv")
            $cableID = "gotv";
        else
            $cableID = "";
    } else {
        if ($cableName == "startimes")
            $cableID = 3;
        elseif ($cableName == "dstv")
            $cableID = 2;
        elseif ($cableName == "gotv")
            $cableID = 1;
        else
            $cableID = 0;
    }
    return $cableID;
}
function getExamRolePrice($role)
{
    if ($role == "SMART") {
        $price = "eamount";
    } elseif ($role == "API") {
        $price = "eamount_api";
    } elseif ($role == "VENDOR") {
        $price = "eamount_vendor";
    } else {
        $price = "eamount";
    }

    return $price;
}
function getExams($id)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM exams_providers WHERE eslug = '$id'");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getExamID($archi, $cableName)
{
    if ($archi == "WIAXY") {
        if ($cableName == "waec")
            $cableID = "waec";
        elseif ($cableName == "neco")
            $cableID = "neco";
        elseif ($cableName == "nabteb")
            $cableID = "nabteb";
        else
            $cableID = "";
    } elseif ($archi == "MSORG") {
        if ($cableName == "startimes")
            $cableID = "STARTIME";
        elseif ($cableName == "dstv")
            $cableID = "DSTV";
        elseif ($cableName == "gotv")
            $cableID = "GOTV";
        else
            $cableID = "";
    } elseif ($archi == "VTPASS") {
        if ($cableName == "waec")
            $cableID = "waecdirect";
        elseif ($cableName == "neco")
            $cableID = "";
        elseif ($cableName == "nabteb")
            $cableID = "";
        else
            $cableID = "";
    } else {
        if ($cableName == "startimes")
            $cableID = 3;
        elseif ($cableName == "dstv")
            $cableID = 2;
        elseif ($cableName == "gotv")
            $cableID = 1;
        else
            $cableID = 0;
    }
    return $cableID;
}

function checkArchi($init)
{
    if (substr($init, 0, 4) == "msor") {
        return "MSORG";
    } elseif (substr($init, 0, 4) == "wiax") {
        return "WIAXY";
    } elseif (substr($init, 0, 4) == "adex") {
        return "ADEX";
    } elseif (substr($init, 0, 4) == "vtpa") {
        return "VTPASS";
    } elseif (substr($init, 0, 3) == "sna") {
        return "SNA";
    } elseif (substr($init, 0, 3) == "sto") {
        return "STORE";
    } else {
        return false;
    }
}
function getBankImg($code)
{
    if ($code == "070010") {
        $img = "img/assets/abbey.png";
    } elseif ($code == "044") {
        $img = "img/assets/access.png";
    } elseif ($code == "090134") {
        $img = "img/assets/accion.png";
    } elseif ($code == "090188") {
        $img = "img/assets/bainescredit.png";
    } elseif ($code == "50931") {
        $img = "img/assets/bowen.png";
    } elseif ($code == "919") {
        $img = "img/assets/cellulant.png";
    } elseif ($code == "023") {
        $img = "img/assets/citibank.png";
    } elseif ($code == "100032") {
        $img = "img/assets/contech.png";
    } elseif ($code == "090365") {
        $img = "img/assets/corestep.png";
    } elseif ($code == "946") {
        $img = "img/assets/coronation.png";
    } elseif ($code == "050") {
        $img = "img/assets/ecobank.png";
    } elseif ($code == "090097") {
        $img = "img/assets/ekondo.png";
    } elseif ($code == "50126") {
        $img = "img/assets/eyowo.png";
    } elseif ($code == "011") {
        $img = "img/assets/fbn.png";
    } elseif ($code == "214") {
        $img = "img/assets/fcmb.png";
    } elseif ($code == "090153") {
        $img = "img/assets/ffs.png";
    } elseif ($code == "070") {
        $img = "img/assets/fidelity.png";
    } elseif ($code == "400001") {
        $img = "img/assets/fsdh.png";
    } elseif ($code == "103") {
        $img = "img/assets/globus.png";
    } elseif ($code == "058") {
        $img = "img/assets/gtb.png";
    } elseif ($code == "030") {
        $img = "img/assets/heritage.png";
    } elseif ($code == "301") {
        $img = "img/assets/jaiz.png";
    } elseif ($code == "906") {
        $img = "img/assets/jubilee.png";
    } elseif ($code == "082") {
        $img = "img/assets/keystone.png";
    } elseif ($code == "090267") {
        $img = "img/assets/kuda.png";
    } elseif ($code == "090171") {
        $img = "img/assets/mainstreet.png";
    } elseif ($code == "090383") {
        $img = "img/assets/manny.png";
    } elseif ($code == "090281") {
        $img = "img/assets/mint.png";
    } elseif ($code == "50515") {
        $img = "img/assets/moniepoint.png";
    } elseif ($code == "327") {
        $img = "img/assets/paga.png";
    } elseif ($code == "100033") {
        $img = "img/assets/palmpay.png";
    } elseif ($code == "907") {
        $img = "img/assets/parallex.png";
    } elseif ($code == "917") {
        $img = "img/assets/parkway.png";
    } elseif ($code == "090317") {
        $img = "img/assets/patrickgold.png";
    } elseif ($code == "943") {
        $img = "img/assets/payattitude.png";
    } elseif ($code == "304") {
        $img = "img/assets/paycom.png";
    } elseif ($code == "076") {
        $img = "img/assets/polaris.png";
    } elseif ($code == "101") {
        $img = "img/assets/providus.png";
    } elseif ($code == "502") {
        $img = "img/assets/rand.png";
    } elseif ($code == "125") {
        $img = "img/assets/rubies.png";
    } elseif ($code == "090286") {
        $img = "img/assets/safe.png";
    } elseif ($code == "090369") {
        $img = "img/assets/seedvest.png";
    } elseif ($code == "51310") {
        $img = "img/assets/sparkle.png";
    } elseif ($code == "221") {
        $img = "img/assets/stanbic.png";
    } elseif ($code == "068") {
        $img = "img/assets/standard.png";
    } elseif ($code == "090262") {
        $img = "img/assets/stellas.png";
    } elseif ($code == "232") {
        $img = "img/assets/sterling.png";
    } elseif ($code == "100") {
        $img = "img/assets/suntrust.png";
    } elseif ($code == "302") {
        $img = "img/assets/taj.png";
    } elseif ($code == "102") {
        $img = "img/assets/titan.png";
    } elseif ($code == "033") {
        $img = "img/assets/uba.png";
    } elseif ($code == "032") {
        $img = "img/assets/union.png";
    } elseif ($code == "215") {
        $img = "img/assets/unity.png";
    } elseif ($code == "566") {
        $img = "img/assets/vfd.png";
    } elseif ($code == "035") {
        $img = "img/assets/wema.png";
    } elseif ($code == "057") {
        $img = "img/assets/zenith.png";
    } else {
        $img = "img/assets/bank.png";
    }
    return $img;
}
function getWiaxyNuban() {}
function getPayvesselNuban($psb9_config, $email, $ref, $fisrtName, $lastName, $phone)
{
    global $conn;
    $psb = json_decode($psb9_config);
    if (isset($psb->api) && !empty($psb->api)) {
        $headers = ["api-key: " . $psb->api, "api-secret: Bearer " . $psb->secret, "Content-Type: application/json"];
        $data = json_encode([
            "email" =>  $email,
            "name" => $fisrtName . ' ' . $lastName,
            "phoneNumber" => $phone,
            "bankcode" => ["120001"],
            "account_type" => "STATIC",
            "businessid" => $psb->id,
            "nin" => $psb->nin
        ]);
        $ch = curl_init();
        curl_setopt_array($ch, [CURLOPT_URL => 'https://api.payvessel.com/api/external/request/customerReservedAccount/', CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => $headers, CURLOPT_RETURNTRANSFER => true]);
        $psb9Q = json_decode(curl_exec($ch), true);
        file_put_contents('9psbs.txt', json_encode($psb9Q));
        if ($psb9Q["status"]) {
            $accs["bankCode"] = "120001";
            $accs["accountNumber"] = $psb9Q["banks"][0]["accountNumber"];
            $accs["accountName"] = $psb9Q["banks"][0]["accountName"];
            $accs["bankName"] = $psb9Q["banks"][0]["bankName"];
            $accs["bankImage"] = "/assets/img/banks/psb9.png";
            $Eaccounts = json_encode($accs);
            mysqli_query($conn, "INSERT INTO reserveaccounts (email, psb9, status) VALUES ('$email', '$Eaccounts', 'ACTIVE') ON DUPLICATE KEY UPDATE psb9 = VALUES(psb9), status = VALUES(status)");
            // mysqli_query($conn, "INSERT INTO reserveAccounts(email,psb9,status) VALUES('$email','$Eaccounts','ACTIVE')");
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
function getWiaxyNuban2($wiaxy_api, $email, $ref, $fisrtName, $lastName, $phone, $webhook)
{
    $load = json_encode([
        "email" => $email,
        "reference" => $ref,
        "firstName" => $fisrtName,
        "lastName" => $lastName,
        "phone" => $phone,
        "webhookUrl" => $webhook,
    ]);
    $curl = curl_init();
    curl_setopt_array($curl, [
        CURLOPT_URL => "https://api-v1.aspfiy.com/reserve-account/",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => $load,
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . $wiaxy_api,
            "Content-Type: application/json",
            "accept: application/json"
        ],
    ]);
    $response = curl_exec($curl);
    file_put_contents("nuban", $response);
    $err = curl_error($curl);
    curl_close($curl);
    $resp = json_decode($response);
    if (isset($resp->status) &&  $resp->status === true) {
        $data = json_decode(json_encode($resp->data->account), true);
        return $data;
    } else {
        return false;
    }
}
function getVFD($wiaxy_api, $email, $ref, $fisrtName, $lastName, $phone)
{
    $url = "https://services2.vpay.africa/api/service/v1/query/merchant/login";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $headers = array(
        "publicKey: eee0fbf2-05a2-4cc7-bae2-9e81df0dc557",
        "Content-Type: application/json",
    );
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

    curl_setopt(
        $curl,
        CURLOPT_POSTFIELDS,
        '
            {
              "username" : "",
              "password" : ""
            }'
    );

    $json = curl_exec($curl);
    curl_close($curl);

    file_put_contents("vfd1", $json . "\n", FILE_APPEND);
    $result = json_decode($json, true);
    if (isset($result['status']) && $result['status'] == true) {
        $accessToken = $result['token'];
    } else {
        $accessToken = null;
    }


    $url = "https://services2.vpay.africa/api/service/v1/query/customer/add";

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $headers = array(
        "Content-Type: application/json",
        "publicKey: ",
        "b-access-token: " . $accessToken,
    );
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $data = <<<DATA
{
  "email" : "$email",
  "phone" : "$phone",
  "contactfirstname" : "$fisrtName",
  "contactlastname" : "$lastName"
}
DATA;
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $resp = curl_exec($curl);
    curl_close($curl);
    file_put_contents("vfd2", $resp . "\n", FILE_APPEND);
    $value = json_decode($resp, true);
    if (isset($value["id"])) {
        $customerId = $value["id"];
        $url = "https://services2.vpay.africa/api/service/v1/query/customer/{$customerId}/show";
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        $headers = array(
            "Content-Type: application/json",
            "publicKey: ",
            "b-access-token: " . $accessToken,
        );
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        $resp = curl_exec($curl);
        curl_close($curl);
        $raw = json_decode($resp, true);
        if (isset($raw["nuban"])) {
            $v = $raw["nuban"];
            return $v;
        }
    } else {
        return false;
    }
}
function getStatusSlug($status)
{
    if ($status == "SUCCESS") {
        $stat = "Completed";
    }
    if ($status == "SUCCESSFUL") {
        $stat = "Completed";
    }
    if ($status == "PENDING") {
        $stat = "Pending";
    }
    if ($status == "INITIATED") {
        $stat = "Pending";
    }
    if ($status == "IN_PROGRESS") {
        $stat = "Processing";
    }
    if ($status == "FAILED") {
        $stat = "Failed";
    }
    return $stat;
}
function getSite()
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM sitesettings");
    if (mysqli_num_rows($checkDet) > 0) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r;
    } else {
        return false;
    }
}
function getR2Cash($service)
{
    global $conn;
    $checkDet = mysqli_query($conn, "SELECT * FROM r2cashNumbers");
    if ($checkDet) {
        $r = mysqli_fetch_assoc($checkDet);
        return $r[$service];
    } else {
        return false;
    }
}
function convertNumberToWord($num = false)
{
    $num = str_replace(array(',', ' '), '', trim($num));
    if (!$num) {
        return false;
    }
    $num = (int) $num;
    $words = array();
    $list1 = array(
        '',
        'one',
        'two',
        'three',
        'four',
        'five',
        'six',
        'seven',
        'eight',
        'nine',
        'ten',
        'eleven',
        'twelve',
        'thirteen',
        'fourteen',
        'fifteen',
        'sixteen',
        'seventeen',
        'eighteen',
        'nineteen'
    );
    $list2 = array('', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety', 'hundred');
    $list3 = array(
        '',
        'thousand',
        'million',
        'billion',
        'trillion',
        'quadrillion',
        'quintillion',
        'sextillion',
        'septillion',
        'octillion',
        'nonillion',
        'decillion',
        'undecillion',
        'duodecillion',
        'tredecillion',
        'quattuordecillion',
        'quindecillion',
        'sexdecillion',
        'septendecillion',
        'octodecillion',
        'novemdecillion',
        'vigintillion'
    );
    $num_length = strlen($num);
    $levels = (int) (($num_length + 2) / 3);
    $max_length = $levels * 3;
    $num = substr('00' . $num, -$max_length);
    $num_levels = str_split($num, 3);
    for ($i = 0; $i < count($num_levels); $i++) {
        $levels--;
        $hundreds = (int) ($num_levels[$i] / 100);
        $hundreds = ($hundreds ? ' ' . $list1[$hundreds] . ' hundred' . ' ' : '');
        $tens = (int) ($num_levels[$i] % 100);
        $singles = '';
        if ($tens < 20) {
            $tens = ($tens ? ' ' . $list1[$tens] . ' ' : '');
        } else {
            $tens = (int)($tens / 10);
            $tens = ' ' . $list2[$tens] . ' ';
            $singles = (int) ($num_levels[$i] % 10);
            $singles = ' ' . $list1[$singles] . ' ';
        }
        $words[] = $hundreds . $tens . $singles . (($levels && (int) ($num_levels[$i])) ? ' ' . $list3[$levels] . ' ' : '');
    } //end for loop
    $commas = count($words);
    if ($commas > 1) {
        $commas = $commas - 1;
    }
    return implode(' ', $words);
}

function getReportCount($email)
{
    global $conn;
    $email_escaped = mysqli_real_escape_string($conn, $email);
    $result = mysqli_query($conn, "SELECT COUNT(*) AS reportCount FROM reports WHERE user = '$email_escaped'");
    if ($result) {
        $row = mysqli_fetch_assoc($result);
        return $row['reportCount'];
    } else {
        return 0;
    }
}

function getTransCount($email)
{
    global $conn;
    $email_escaped = mysqli_real_escape_string($conn, $email);
    $result = mysqli_query($conn, "SELECT COUNT(*) AS reportCount FROM transactions WHERE user = '$email_escaped'");
    if ($result) {
        $row = mysqli_fetch_assoc($result);
        return $row['reportCount'];
    } else {
        return 0;
    }
}
function getApiTransCount($email, $status)
{
    global $conn;
    $email_escaped = mysqli_real_escape_string($conn, $email);
    $result = mysqli_query($conn, "SELECT COUNT(*) AS reportCount FROM transactions WHERE user = '$email_escaped' AND api= 'YES' AND status='$status' ");
    if ($result) {
        $row = mysqli_fetch_assoc($result);
        return $row['reportCount'];
    } else {
        return 0;
    }
}

function getPass($user)
{
    global $conn;
    $checkBal = mysqli_query($conn, "SELECT password FROM users WHERE email = '$user' OR phone = '$user'");
    if ($checkBal && mysqli_num_rows($checkBal) > 0) {
        $r = mysqli_fetch_array($checkBal);
        return $r['password'];
    } else {
        return false;
    }
}

$siteKon = getSite();
$site_title = $siteKon['site_title'];
