<?php

require 'admin-login.php';

$type = $_GET['type'];

if($type == "plan"){
    $id = $_GET['id'];
    $plan = $_POST['plan'];
    mysqli_query($link, "UPDATE user SET accounttype = '$plan' WHERE id = '$id' ");

header("Location: user-details.php?id=$id");
}

if($type == "cr/dr"){
    $id = $_GET['id'];
    $amount = $_POST['amount'];
    $type = $_POST['type'];
    $t_type = $_POST['t_type'];
    
    $man = mysqli_query($link, "SELECT * FROM user WHERE id = '$id'");
    $god = mysqli_fetch_array($man);
    
    if($type == "Deposit" && $t_type == "Debit"){
        $_SESSION['error'] = "You Cannot Debit Deposit";
        header("Location: user-details.php?id=$id");
    }else{
        if($t_type == "Credit"){
            if($type == "Deposit"){
                $total = $god['invested'] + $amount;
                $totall = $god['balance'] + $amount;
                $date = date("y-m-d");
                 mysqli_query($link, "UPDATE user SET invested = '$total', balance = '$totall' WHERE id = '$id' ");
                 mysqli_query($link, "INSERT INTO transactions (email, type, amount, status, date) VALUES ('".$god['email']."', 'Deposit', '$amount', 'Approved', '$date') ");
                 $to = $god['email'];
                 $subject = "Your Trading Account Has Just Been Credited";
                 $message = "<meta name='viewport' content='width=device-width, initial-scale=1.0'>
         <div style='background-color: #4c516d; padding: 20px'>
         <img src='https://altrexcoinzap.com/img/in-logo-1.png' alt='...' style='display: block; margin-left: auto; margin-right: auto; width: 50%'>
         <h1 style='font-size: 15px'>Your Trading Account Has Just Been Credited</h1></br>
         <p>The Sum Of $amount Has Been Credited Into Your Trading Account.</p></br><p>Your Balance Is $totall</p></div>
         <div style='background-color: #4c516d; padding: 5px; text-align: center'>
         
         
         <a href=\"altrexcoinzap.com/account/login.html?activation=" . $_SESSION['activation'] . "&type=active\" style='color: white; text-align: center; padding: 20px; background-color: #32CD32; border-radius: 5px'>VERIFY EMAIL</a>
         </div>
         <div style='background-color: #4c516d; padding: 20px'>
         
         <p>Should you have any questions or concerns, please contact us via support@altrexcoinzap.com with your email or visit our contact page or use the live chat in our website.</p>
         </div>
         
         </div>";
               //  require '../PHPMailer/PHPMailerAutoload.php';

     //    $mail = new PHPMailer;
         
         //$mail->SMTPDebug = 2;                               // Enable verbose debug output
         
  //       $mail->isSMTP();                                      // Set mailer to use SMTP
  //       $mail->Host = 'altrexcoinzap.com';  // Specify main and backup SMTP servers
    //     $mail->SMTPAuth = true;                               // Enable SMTP authentication
    //     $mail->Username = 'support@altrexcoinzap.com';                 // SMTP username
     //    $mail->Password = 'Ironman54$';                           // SMTP password
         //$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
  //       $mail->Port = 465;                                    // TCP port to connect to
         
       //  $mail->setFrom('support@altrexcoinzap.com', 'ALTREX COIN ZAP');
         //$mail->addAddress($to);               // Name is optional
        // $mail->addReplyTo('support@altrexcoinzap.com', 'ALTREX COIN ZAP');
         //$mail->addCC('cc@example.com');
         //$mail->addBCC('bcc@example.com');
         
         //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    
                 header("Location: user-details.php?id=$id");
            }elseif($type == "Bonus"){
                $total = $god['bonus'] + $amount;
                $date = date("y-m-d");
                mysqli_query($link, "UPDATE user SET bonus = '$total' WHERE id = '$id' ");
                mysqli_query($link, "INSERT INTO transactions (email, type, amount, status, date) VALUES ('".$god['email']."', 'Bonus', '$amount', 'Approved', '$date') ");
                header("Location: user-details.php?id=$id");
            }elseif($type == "Profit"){
                $total = $god['profit'] + $amount;
                $totall = $god['balance'] + $amount;
                $date = date("y-m-d");
                mysqli_query($link, "UPDATE user SET profit = '$total', balance = '$totall' WHERE id = '$id' ");
                mysqli_query($link, "INSERT INTO transactions (email, type, amount, status, date) VALUES ('".$god['email']."', 'Profit', '$amount', 'Approved', '$date') ");
                header("Location: user-details.php?id=$id");
            }elseif($type == "Ref_Bonus"){
                $total = $god['referal'] + $amount;
                $date = date("y-m-d");
                mysqli_query($link, "UPDATE user SET referal = '$total' WHERE id = '$id' ");
                mysqli_query($link, "INSERT INTO transactions (email, type, amount, status, date) VALUES ('".$god['email']."', 'Referral', '$amount', 'Approved', '$date') ");
                header("Location: user-details.php?id=$id");
            }elseif($type == "Balance"){
                $total = $god['balance'] + $amount;
                mysqli_query($link, "UPDATE user SET balance = '$total' WHERE id = '$id' ");
                header("Location: user-details.php?id=$id");
            }
        
    }
    }
    if($t_type == "Debit"){
            if($type == "Bonus"){
                    $total = intval($god['bonus']) - $amount;
                mysqli_query($link, "UPDATE user SET bonus = '$total' WHERE id = '$id' ");
                header("Location: user-details.php?id=$id");
                }elseif($type == "Profit"){
                    $total = intval($god['profit']) - $amount;
                $totall = intval($god['balance']) - $amount;
                $to = $god['email'];
                 $subject = "Your Trading Account Has Just Been Debited";
                 $message = "<meta name='viewport' content='width=device-width, initial-scale=1.0'>
         <div style='background-color: #4c516d; padding: 20px'>
         <img src='https://altrexcoinzap.com/img/in-logo-1.png' alt='...' style='display: block; margin-left: auto; margin-right: auto; width: 50%'>
         <h1 style='font-size: 15px'>Your Trading Account Has Just Been Debited</h1></br>
         <p>The Sum Of $amount Has Been Debited From Your Trading Account.</p></br><p>Your Balance Is $totall</p></div>
         <div style='background-color: #4c516d; padding: 5px; text-align: center'>
         
         
         <a href=\"altrexcoinzap.com/account/login.html?activation=" . $_SESSION['activation'] . "&type=active\" style='color: white; text-align: center; padding: 20px; background-color: #32CD32; border-radius: 5px'>VERIFY EMAIL</a>
         </div>
         <div style='background-color: #4c516d; padding: 20px'>
         
         <p>Should you have any questions or concerns, please contact us via support@altrexcoinzap.com with your email or visit our contact page or use the live chat in our website.</p>
         </div>
         
         </div>";
 //                require '../PHPMailer/PHPMailerAutoload.php';

  //       $mail = new PHPMailer;
         
         //$mail->SMTPDebug = 2;                               // Enable verbose debug output
         
 //        $mail->isSMTP();                                      // Set mailer to use SMTP
   //      $mail->Host = 'altrexcoinzap.com';  // Specify main and backup SMTP servers
 //        $mail->SMTPAuth = true;                               // Enable SMTP authentication
  //       $mail->Username = 'support@altrexcoinzap.com';                 // SMTP username
  //       $mail->Password = 'Ironman54$';                           // SMTP password
 //        $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    //     $mail->Port = 465;                                    // TCP port to connect to
         
   //      $mail->setFrom('support@altrexcoinzap.com', 'ALTREX COIN ZAP');
   //      $mail->addAddress($to);               // Name is optional
    //     $mail->addReplyTo('support@altrexcoinzap.com', 'ALTREX COIN ZAP');
         //$mail->addCC('cc@example.com');
         //$mail->addBCC('bcc@example.com');
         
         //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
         //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
       //  $mail->isHTML(true);                                  // Set email format to HTML
         
         //$mail->Subject = $subject;
   //      $mail->Body    = $message;
      //   $mail->send();
                mysqli_query($link, "UPDATE user SET profit = '$total', balance = '$totall' WHERE id = '$id' ");
                header("Location: user-details.php?id=$id");
                }elseif($type == "Ref_Bonus"){
                    $total = intval($god['referal']) - $amount;
                mysqli_query($link, "UPDATE user SET referal = '$total' WHERE id = '$id' ");
                header("Location: user-details.php?id=$id");
                }elseif($type == "Balance"){
                $total = intval($god['balance']) - $amount;
                mysqli_query($link, "UPDATE user SET balance = '$total' WHERE id = '$id' ");
                header("Location: user-details.php?id=$id");
                }
    }
}


?>