<?php
require_once 'session.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require '../../PHPMailer/src/Exception.php';
require '../../PHPMailer/src/PHPMailer.php';
require '../../PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);



//Handle profile update ajax
if(isset($_FILES['image'])){
    //  print_r($_FILES);
    //  print_r($_POST);
    $firstname = $cuser->test_input($_POST['firstname']);
    $lastname = $cuser->test_input($_POST['lastname']);
    $gender = $cuser->test_input($_POST['gender']);
    $country = $cuser->test_input($_POST['country']);
    
     $oldImage = $_POST['oldimage'];
     $folder = 'uploads/';

     if(isset($_FILES['image']['name']) && ($_FILES['image']['name'] != "")){
         $newImage = $folder.$_FILES['image']['name'];
         move_uploaded_file($_FILES['image']['tmp_name'], $newImage);

         if($oldImage != null){
             unlink($oldImage);
         }
     }else{
         $newImage = $oldImage;
     }
     $cuser->update_profile($firstname,$lastname,$gender,$country,$newImage,$cid);
      $cuser->notification($cid, 'user', 'Profile Updated');
      
}

     // handle chnage passsword ajax request
     if(isset($_POST['action']) && $_POST['action'] == 'change_pass'){
        // print_r($_POST);
        $currentPass = $_POST['curpass'];
        $newPass = $_POST['newpass'];
        $cnewPass = $_POST['cnewpass'];
 
        $hnewPass = password_hash($newPass, PASSWORD_DEFAULT);
 
        if($newPass != $cnewPass){
            echo $cuser->showMessage('danger', 'Password did not match!');
        }else{
            if(password_verify($currentPass,$cpass)){
                $cuser->change_password($hnewPass,$cid);
                echo $cuser->showMessage('success','Password Changed Successfully');
                 $cuser->notification($cid, 'user', 'Password Changed');
            }else{
                echo $cuser->showMessage('danger','Current Password is Wrong!');
            }
        }
     }


     //Handle verify email ajax request
     if(isset($_POST['action']) && $_POST['action'] == 'verify_email'){
        try {
            //Server settings
            $mail->SMTPOptions = array(
                'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
                )
                );
           
        

           // $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      // Enable verbose debug output
           $mail->isSMTP();                                            // Send using SMTP
            $mail->Host       = 'xmombo.com';                    // Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
            $mail->Username   =  Database::USERNAME;                        // SMTP username
            $mail->Password   =  Database::PASSWORD;                              // SMTP password
            $mail->SMTPSecure =  PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port       =   587;    
            
                        //Recipients
            $mail->setFrom(Database::USERNAME, 'XMombo');
            $mail->addAddress($cemail);     // Add a recipient

            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = 'XMombo- Confirm your email';
            $mail->Body    = '<table class="body-wrap" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6">
            <tbody>
                <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                    <td style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
                    <td class="container" width="600" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important; max-width: 600px !important; clear: both !important; margin: 0 auto;"
                        valign="top">
                        <div class="content" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;">
                            <table class="main" width="100%" cellpadding="0" cellspacing="0" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;"
                                bgcolor="#fff">
                                <tbody>
                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                        <td class="" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 16px; vertical-align: top; color: #fff; font-weight: 500; text-align: center; border-radius: 3px 3px 0 0; background-color: #38414a; margin: 0; padding: 20px;"
                                            align="center" bgcolor="#71b6f9" valign="top">
                                            <a href="www.xmombo.com" style="font-size:32px;color:#fff;"> Xmombo</a> <br>
                                            <span style="margin-top: 10px;display: block;">Auto BUY low & SELL high</span>
                                        </td>
                                    </tr>
                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                        <td class="content-wrap" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 20px;" valign="top">
                                            <table width="100%" cellpadding="0" cellspacing="0" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                                <tbody>
                                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                                        <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
                                                            Dear  <strong style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">'.$cusername.'
                                        </strong> ,
                                                        </td>
                                                    </tr>
                                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                                        <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
                                                        Please confirm your email address by clicking the link below or copy the link and paste it in your browser address bar:
                                                        </td>
                                                    </tr>
                                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                                        <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
                                                            <p class="btn-primary" style="font-family: ,Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; color: #FFF; text-decoration: none; line-height: 2em; font-weight: bold; text-align: center; cursor: pointer; display: inline-block; border-radius: 5px; text-transform: capitalize; background-color: #f1556c; margin: 0; border-color: #f1556c; border-style: solid; border-width: 8px 16px;">
                                             Copy the link below and paste it in your browser</p>
                                                        </td>
                                                    </tr>
                                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                                        <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
                                                        www.xmombo.com/verify-email.php?email='.$cemail.'
                                                        </td>
                                                    </tr>
                                                    <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                                        <td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
                                                        Regards,<br>XMombo Team.
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <div class="footer" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
                                <table width="100%" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                    <tbody>
                                        <tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
                                            <td class="aligncenter content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; vertical-align: top; color: #999; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top"><a href="www.xmombo.com" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;">www.xmombo.com</a> 
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </td>
                    <td style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
                </tr>
            </tbody>
        </table>';

            $mail->send();
            echo $cuser->showMessage('success', 'A verification link has been sent to your email!');
            $cuser->notification($cid, 'user', 'A verification link has been sent to your email!');
        }
        catch(Exception $e){
            echo $cuser->showMessage('danger', 'Something went wrong, please try again!');
        }
    }


    //Request for api account linkng
    if(isset($_POST['action']) && $_POST['action'] == 'register'){
           print_r($_POST);
    }

    //Request for Sportarb Bot
    if(isset($_POST['action']) && $_POST['action'] == 'surebet'){
        //   print_r($_POST);
        $currentbalance = $cuser->test_input($_POST['currentbalance']);
        $amount = $cuser->test_input($_POST['amount']);
        $profit_range = $cuser->test_input($_POST['p_range']);
        $sports = $cuser->test_input($_POST['sports']);
        $outcome = $cuser->test_input($_POST['outcome2']);
        $outcomee = $cuser->test_input($_POST['outcome3']);

        $n=4;
        function getName($n) {
            $characters = '0123456789';
            $randomString = 'ARB';
            for ($i = 0; $i < $n; $i++) {
                $index = rand(0, strlen($characters) - 1);
                $randomString .= $characters[$index];
            }
            return $randomString;
        }
        
        $invest_id=getName($n);

        if($currentbalance >= $amount){
        $sportarb = $cuser->sportdep($cid,$invest_id,$amount,$profit_range,$sports,$outcome,$outcomee,'2');
        if($sportarb){
            echo 'surebet';
        }
            
        }else{
            echo $cuser->showMessage('danger','Insufficient Balance for order!');
        }

    }


    // Handle Fectch Sports bot
if(isset($_POST['action']) && $_POST['action'] == 'fetchAllSBot'){
    // echo 'Working';
    $output = '';
    $data = $cuser->fetchSportsArb($cid);
    
    
        // echo $profit;
  
    if($data){
        $output .= '<table class="table text-start align-middle table-bordered table-hover mb-0">
                        <thead>
                            <tr class="text-white text-center">
                                <th scope="col"><input class="form-check-input" type="checkbox"></th>
                                <th scope="col">Bot ID</th>
                                <th scope="col">Amount</th>
                                <th scope="col">($)Profit</th>
                                <th scope="col">Fee(40%)</th>
                                <th scope="col">Status</th>
                                <th scope="col">Action</th>
                            </tr>
                        </thead>
                        <tbody>';
                     foreach($data as $row) {
                        $invId = $row['invest_id'];
                        $profit = $cuser->get_totalprofit($invId);
                        $percent = 40/100 * $profit;
                        if($row['flag'] == 2){
                            $status = "<span class='badge bg-info text-dark'>Initializing</span>";
                        }elseif($row['flag'] == 1){
                            $status = "<span class='badge bg-success text-dark'>Running</span>";
                        }else{
                            $status = "<span class='badge bg-primary text-dark'>Stopped</span>";
                        }
                        
                         $output .= '<tr class=" text-center">
                                        <td><input class="form-check-input" type="checkbox"></td>
                                        <td>'.$row['invest_id'].'</td>
                                        <td>$'.$row['amount'].'</td>
                                        <td>'.number_format($profit,2).'</td>
                                        <td>$'.number_format($percent,2).'</td>
                                        <td>'.$status.'</td>
                                        <td class=" text-center">
                                        <a uid="'.$row['uid'].'" invest_id="'.$row['invest_id'].'" title="View Details" data-toggle="modal" data-target="#showSBotDetailsModal" class="btn btn-sm btn-primary sBotDetailsIcon" href="#">Detail</a>
                                        <a  id="'.$row['id'].'" title="Stop Arbsbet Bot"class="btn btn-sm btn-primary stopSBotIcon" href="#">Stop Bot</a>
                                        </td>
                                    </tr>';
                     }
                     $output .= '</tbody>
                            </table>';
                     echo $output;
    }else{
        echo '<h3 class="text-center text-white">No Data</h3>'; 
    }
 }

    
 //HAndle stop sport bot ajax request
 if(isset($_POST['del_id'])){
    $id = $_POST['del_id'];
    // print_r($id);
    $cuser->stopSBot($id, 0);
}

// Handle display Sports bot details
if(isset($_POST['uid']) && isset($_POST['detailsBot_id']) != null){
    // print_r($_POST);
    $uid = $_POST['uid'];
    $invest_id = $_POST['detailsBot_id'];
    $output = '';
    // echo $uid;
    // echo $invest_id;
    // print_r($invest_id);
    // echo $invest_id;

    $dataa = $cuser->fetchSBotDetails($uid,$invest_id);
  
    // foreach($dataa as $row) {
    //     print_r($row);
    //  }


     if($dataa){
        $output .= '<table class=" app-table app-wide" id="surebets-table" data-au="true">
        <tr>
        <th colspan="2"><a class=" tablesort" title="Profit: Sort ascending" href="?order=profit_asc&amp;utm_campaign=affiliate&amp;utm_medium=referral&amp;utm_source=ssb">▼Profit</a></th>
        <th>Sport</th>
        <th class="text-center"><a class="tablesort" title="Start time: Sort descending" href="?order=start_at_desc&amp;utm_campaign=affiliate&amp;utm_medium=referral&amp;utm_source=ssb"><span class="arrow">▲▼</span></a></th>
        <th>Event</th>
        <th>Market</th>
        <th class="break-header text-right">Odds</th>
        <th></th>
      </tr>
      
      
      
      <tbody id="surebet_record_GL2IERjrNf8" class="surebet_record" data-signature="7b1613a902dfa964ae485dca37cf8815">';
                     foreach($dataa as $row) {
                        
                         $output .= '<tr>
                         <td rowspan="3" class="info_td" data-toggle="tooltip" title=""></td>    <td rowspan="3" class="profit-box">
                           <a class="profit" data-profit="0.9976" title="ROI 2497%">'.number_format($row['percentage'],2).' %</a><br>
                           <span  class="text-white">$'.$row['profit'].'</span>      <div class="btn-group">
                           <br>
                               </td>
                         
                         <td class="booker">'.$row['sports'].'</td>
                         <td class="time" data-utc="1696127400000">'.$row['date'].'<br>'.$row['time'].'</td>
                         <td class="event event-DRK9GA"><a target="_blank" href="#">'.$row['team1'].'</a><br><span class="minor">'.$row['league'].'</span></td>
                         <td class="coeff"><abbr title="Republic of Korea to win with a handicap of −2.5 (Asian handicap) - points 1st set">'.$row['market1'].'</abbr></td>
                         <td class="value odd_record_EYi9GA"><a target="_blank" href="#">'.$row['odd1'].'</a></td>
                     
                         </tr>
                         <tr>
                         <td class="booker">'.$row['sports'].'</td>
                         <td class="time" data-utc="1696127400000">'.$row['date'].'<br>'.$row['time'].'</td>
                         <td class="event event-DRK9GA"><a target="_blank" href="#">'.$row['team2'].'</a><br><span class="minor">'.$row['league'].'</span></td>
                         <td class="coeff"><abbr title="Republic of Korea to win with a handicap of −2.5 (Asian handicap) - points 1st set">'.$row['market2'].'</abbr></td>
                         <td class="value odd_record_EYi9GA"><a target="_blank" href="#">'.$row['odd2'].'</a></td>
                     
                         </tr>
                       <tr>
                         <td colspan="6" class="extra"><a class="text-white " href="#">$'.$row['amount'].' total stake for this event</a></td>
                       </tr>';
                     }
                     $output .= '</tbody>
                            </table>';
                     echo $output;
    }else{
        echo '<h3 class="text-center text-white">No Data</h3>'; 
    }
   

    // print_r($invest_id);
    
    // echo json_encode($data);
}


 //Request for Xmb Bot
 if(isset($_POST['action']) && $_POST['action'] == 'xmbot'){
    //  print_r($_POST);
     $currentbalance = $cuser->test_input($_POST['currentbalance']);
    $amount = $cuser->test_input($_POST['amount']);
    $duration = $cuser->test_input($_POST['duration']);
    $target = $cuser->test_input($_POST['target']);
    
    $n=4;
    function getName($n) {
        $characters = '0123456789';
        $randomString = 'XMB';
        for ($i = 0; $i < $n; $i++) {
            $index = rand(0, strlen($characters) - 1);
            $randomString .= $characters[$index];
        }
        return $randomString;
    }
    
    $invest_id=getName($n);

    if($currentbalance>=$amount){
    $xmbdep = $cuser->xmbdep($cid,$invest_id,$amount,$duration,$target,'2');
    if($xmbdep){
        echo 'xmbot';
    }
    }else{
        echo $cuser->showMessage('danger','Insufficient Balance for order!');
    }

}

 // Handle Fectch XMB
 if(isset($_POST['action']) && $_POST['action'] == 'fetchXMB'){
    // echo 'Working';
    $output = '';
    $data = $cuser->fetchXMB($cid);
    
    
        // echo $profit;
  
    if($data){
        $output .= '<table class="table text-start align-middle table-bordered table-hover mb-0">
                        <thead>
                            <tr class="text-white text-center">
                                <th scope="col"><input class="form-check-input" type="checkbox"></th>
                                <th scope="col">Bot ID</th>
                                <th scope="col">Amount</th>
                                <th scope="col">($)Profit</th>
                                <th scope="col">Fee(15%)</th>
                                <th scope="col">Duration</th>
                                <th scope="col">Status</th>
                                <th scope="col">Action</th>
                            </tr>
                        </thead>
                        <tbody>';
                     foreach($data as $row) {
                        $invId = $row['invest_id'];
                        $profit = $cuser->xmb_totalprofit($invId);
                        $percent = 15/100 * $profit;
                        if($row['flag'] == 2){
                            $status = "<span class='badge bg-info text-dark'>Initializing</span>";
                        }elseif($row['flag'] == 1){
                            $status = "<span class='badge bg-success text-dark'>Running</span>";
                        }else{
                            $status = "<span class='badge bg-primary text-dark'>Stopped</span>";
                        }
                        
                         $output .= '<tr class=" text-center">
                                        <td><input class="form-check-input" type="checkbox"></td>
                                        <td>'.$row['invest_id'].'</td>
                                        <td>$'.$row['amount'].'</td>
                                        <td>'.number_format($profit,2).'</td>
                                        <td>$'.number_format($percent,2).'</td>
                                        <td>'.$row['duration'].'</td>
                                        <td>'.$status.'</td>
                                        <td class=" text-center">
                                        <a uid="'.$row['uid'].'" invest_id="'.$row['invest_id'].'" title="View Details" data-toggle="modal" data-target="#showXmbDetailsModal" class="btn btn-sm btn-primary xmbDetailsIcon" href="#">Detail</a>
                                        
                                        </td>
                                    </tr>';
                     }
                     $output .= '</tbody>
                            </table>';
                     echo $output;
    }else{
        echo '<h3 class="text-center text-white">No Data</h3>'; 
    }
 }

// Handle display Sports bot details

if(isset($_POST['detailxBot_id'])){
    //  print_r($_POST);
    // $uid = $_POST['uid'];
    $invest_id = $_POST['detailxBot_id'];
    
    
    // $data = $cuser->fetchXmxtDetails($cid,$invest_id);
    $data = $cuser->fetchXmxtDetails($invest_id);
    
    echo json_encode($data);
}


//HAndle delete user ajax request
if(isset($_POST['del_id'])){
    $id = $_POST['del_id'];
    $cuser>userAction($id, 0);
}



   //Handle deposit bitcoin
   if(isset($_POST['action']) && $_POST['action'] == 'btclink'){
    $btcamount = $cuser->test_input($_POST['btcamount']);
    // $btctran = $cuser->test_input($_POST['btctran']);
    // $paymentway = "btc";
    $time = time();
    
    $n=10;
        function getName($n) {
            $characters = '0123456789';
            $randomString = 'TRB';
            for ($i = 0; $i < $n; $i++) {
                $index = rand(0, strlen($characters) - 1);
                $randomString .= $characters[$index];
            }
            return $randomString;
        }
        
        $trac_id=getName($n);
  
 $btctopup = $cuser->topup($cid,$btcamount,'BITCOIN (Crypto Currency)',$trac_id,$time);
//   $cuser->notification($cid, 'admin', 'Deposit Submitted');
 if($btctopup = true){
     echo $cuser->showMessage('success', 'Awaiting Payment...');
      echo '<a href="topuphistory" class="text-center text-danger mt-3 mb-4">View Payment History</a>';

      if(($btcamount) >=500){
      $upline = $cuser->get_refid($cid);
 if(is_array($upline)){
     $uplinemember = $upline['referid'];
 }
$commission = 25;
$time = time();
$commissiondata = $cuser->ref_com($uplinemember,$cid,$btcamount,$trac_id,$commission,$time);
}
 }else{
     echo $cuser->showMessage('warning', 'Something went wrong, Try Again!');
 }

 
 }


   //Handle deposit usdt
if(isset($_POST['action']) && $_POST['action'] == 'usdtlink'){
    $usdtamount = $cuser->test_input($_POST['usdtamount']);
    // $usdttran = $cuser->test_input($_POST['usdttran']);
    // $paymentway = "btc";
    $time = time();

    $n=10;
        function getName($n) {
            $characters = '0123456789';
            $randomString = 'TRU';
            for ($i = 0; $i < $n; $i++) {
                $index = rand(0, strlen($characters) - 1);
                $randomString .= $characters[$index];
            }
            return $randomString;
        }
        
        $trac_id=getName($n);

    
   
  //  print_r($_POST);
  
 $usdttopup = $cuser->topup($cid,$usdtamount,'USDT (Crypto Currency)',$trac_id,$time);
//  $cuser->notification($cid, 'admin', 'Deposit Submitted');
 if($usdttopup = true){
     echo $cuser->showMessage('success', 'Awaiting Payment...');
     echo '<a href="topuphistory" class="text-center text-danger mt-3 mb-4">View Payment History</a>';
     if(($usdtamount) >=500){
     $upline = $cuser->get_refid($cid);
 if(is_array($upline)){
     $uplinemember = $upline['referid'];
 }
$commission = 25;
$time = time();
$commissiondata = $cuser->ref_com($uplinemember,$cid,$usdtamount,$trac_id,$commission,$time);
     }
 }else{
     echo $cuser->showMessage('warning', 'Something went wrong, Try Again!');
 }

 }



 //withdraw request
 if(isset($_POST['action']) && $_POST['action'] == 'withdrawrequest'){
     
    $currentbalance = $cuser->test_input($_POST['currentbalance']);
    $gateway = $cuser->test_input($_POST['gateway']);
    $account = $cuser->test_input($_POST['account']);
   $amount = $cuser->test_input($_POST['amount']);
//    $time = time();
   $time = date('Y-m-d');
  if($currentbalance>=$amount){
      $action = $cuser->withdraw($cid, $gateway,$account, $amount,$time);
    //   $cuser->notification($cid, 'admin', 'Withdraw Requested');
      if($action){
        echo $cuser->showMessage('success', 'Your request is been processed!');
    }else{
        echo $cuser->showMessage('warning', 'Information not set Correctly!');
    }
  }else{
    echo $cuser->showMessage('info', 'Insufficient Balance for request!');

  }

}



        //handle fetch notification
        if(isset($_POST['action']) && $_POST['action'] == 'fetchNotification'){
            $notification = $cuser->fetchNotification($cid);
            $output = '';

            if($notification){
                foreach($notification as $row){
                    $output .= '<a href="#" class="dropdown-item ">
                    <button id="'.$row['id'].'" class="close bg-dark  border-0" data-dismiss="alert" aria-label="Close">
                    <h6 class="fw-normal mb-0" > '.$row['message'].'</h6>
                    <small>'.$cuser->timeInAgo($row['created_at']).'</small>
                    <div class="clearfix"></div>
                </a>';                 
                    
                }
                echo $output;
            }else{
                echo '<a href="#" class="dropdown-item">
                <h6 class="fw-normal mb-0">No new notification</h6>
            </a>';
            }
        }

        // Check Notification
        if(isset($_POST['action']) && $_POST['action'] == 'checkNotification'){
            if($cuser->fetchNotification($cid)){
                echo ' <i class="fa fa-bell me-lg-2 text-info"></i>';
            }
            else{
                echo '<i class="fa fa-bell me-lg-2 "></i>';
            }
        }

          //remove notification
          if(isset($_POST['notification_id'])){
            $id = $_POST['notification_id'];
            $cuser->removeNotification($id);
        }























?>