<?php 
session_start();
require('connect.php');
// require '../app/assist.php';
// $assist = new assist;
$alert_msg = '';
$updatealert = '';
if($_SESSION['goodlogin'] != true){
  header('location:../login');
}else{
// if(isset($_REQUEST['client_email']) || isset($_SESSION['client_email'])){
// if(isset($_REQUEST['client_email'])){
// $_SESSION['client_email'] = $_REQUEST['client_email'];
// }
	$client_id = $_SESSION['client_email'];
  if(isset($_POST['create_signals'])){
	 $signal_pair = $_REQUEST['signal_pair'];
	 $signal_percentage = $_REQUEST['signal_percentage'];
	 $signal_time = $_REQUEST['signal_time'];
	 $signal_type = $_REQUEST['signal_type'];
	 $signal_result = $_REQUEST['signal_result'];
$sendtoData = "INSERT INTO trade_signals (signal_pair,signal_percentage,signal_time,signal_type,signal_result) VALUES ('$signal_pair','$signal_percentage','$signal_time','$signal_type','$signal_result')";
$querytoData = mysqli_query($cxn, $sendtoData);
if($querytoData){
	$alert_msg = '<div class="alert alert-success">SIGNAL CREATED SUCCESSFULLY</div>';
}else{
	$alert_msg = '<div class="alert alert-danger">SIGNAL NOT SUCCESSFUL</div>';
}
}
				// 	}	
				// else{
				// 	header('location:view_account.php');
			 // }
			}
$marketData = '[
    {
        "market": "Crypto",
        "tradingPairs": [
            { "pair": "BITSTAMP:BTCUSD", "description": "Bitcoin to US Dollar" },
            { "pair": "COINBASE:ETHUSD", "description": "Ethereum to US Dollar" },
            { "pair": "BINANCE:BNBUSDT", "description": "Binance Coin to USDT" },
            { "pair": "KRAKEN:XRPUSD", "description": "Ripple to US Dollar" }
        ]
    },
    {
        "market": "Forex",
        "tradingPairs": [
            { "pair": "OANDA:EURUSD", "description": "Euro to US Dollar" },
            { "pair": "OANDA:GBPJPY", "description": "British Pound to Japanese Yen" },
            { "pair": "OANDA:USDCHF", "description": "US Dollar to Swiss Franc" },
            { "pair": "OANDA:AUDCAD", "description": "Australian Dollar to Canadian Dollar" }
        ]
    },
    {
        "market": "Commodities",
        "tradingPairs": [
            { "pair": "TVC:GOLD", "description": "Gold to US Dollar" },
            { "pair": "TVC:SILVER", "description": "Silver to US Dollar" },
            { "pair": "TVC:USOIL", "description": "Crude Oil to US Dollar" },
            { "pair": "TVC:COPPER", "description": "Copper to US Dollar" }
        ]
    },
    {
        "market": "Stocks",
        "tradingPairs": [
            { "pair": "NASDAQ:AAPL", "description": "Apple Inc." },
            { "pair": "NASDAQ:TSLA", "description": "Tesla Inc." },
            { "pair": "NASDAQ:AMZN", "description": "Amazon Inc." },
            { "pair": "NASDAQ:GOOGL", "description": "Alphabet Inc." }
        ]
    },
    {
        "market": "Indices",
        "tradingPairs": [
            { "pair": "TVC:SPX", "description": "S&P 500 Index" },
            { "pair": "TVC:IXIC", "description": "NASDAQ Composite" },
            { "pair": "TVC:DJI", "description": "Dow Jones Industrial Average" },
            { "pair": "TVC:FTSE", "description": "FTSE 100 Index" }
        ]
    }
]';
  ?>
<!DOCTYPE html>
<html lang="en">

<head>
<title>DASHBOARD - CONTROL PANEL</title>
	<link rel="shortcut icon" href="images/bicon.png">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script>
		addEventListener("load", function () {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0, 1);
		}
	</script>
	<!-- css files -->
	<link href="css/bootstrap.css" rel='stylesheet' type='text/css' /><!-- bootstrap css -->
	<link href="css/istyle.css" rel='stylesheet' type='text/css' /><!-- custom css -->
	<link href="css/style.css" rel='stylesheet' type='text/css' /><!-- custom css -->
	<link href="css/font-awesome.min.css" rel="stylesheet"><!-- fontawesome css -->
	<!-- //css files -->

	<!-- google fonts -->
	<link
		href="//fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&amp;subset=devanagari,latin-ext"
		rel="stylesheet">

	<!-- //google fonts -->

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/popper.min.js"></script>
</head>

<body>
	<!-- //header -->
	<header>
		<div class="container">
			<!-- nav -->
			<nav class="pt-3">
				<div id="logo">
					<h1> <a href="index.php" class="text-white">CONTROL PANEL</a></h1>
				</div>
				<label for="drop" class="toggle">Menu</label>
				<input type="checkbox" id="drop" />
				<ul class="menu mt-md-2 ml-auto">
					<li class="mr-lg-4 mr-2"><a href="index.php" class="text-white">Dashboard</a></li>
					<li class="mr-lg-4 mr-2"><a href="view_account.php" class="text-white"><div class="badge badge-dark p-2">View accounts</div></a></li>
					<li class="mr-lg-4 mr-2"><a href="view_messages.php" class="text-white">View Messages</a></li>
					<li class="mr-lg-4 mr-2"><a href="logout.php" class="text-white">Logout</a></li>
				</ul>
			</nav>
			<!-- //nav -->
		</div>
	</header>
	<!-- //header -->
	<!-- inner banner -->
	<div class="inner-banner2" id="home">
		<div class="container">
		</div>
	</div>
	<!-- inner banner -->

	<!-- TRACKING ORDER -->
	<section class="py-5" id="">
		<div class="container py-md-3">
			<h4 class="heading text-center text-white"> <span class="fa fa-bar-chart"></span>TRADE SIGNALS</h4>
			<div class="row">
			<center><?php echo $alert_msg;?></center>
				<div class="col-lg-12 acct-wrapper">
				<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" class="form-inline  w-100 my-3" style="border:1px grey solid; background-color:#00150f; padding:20px; margin:20px;">
							<div class="form-group form-inline w-100 mb-2">
                                        <label style="padding-right: 10px;margin-right:10px;"> Trading Pair:</label>
                                                                <div class="input-group">
                                                                    <select class="form-control" style="height: 40px !important; border:1px grey solid; background-color: #00150f; color:white" id="signal_pair" name="signal_pair">
                                                                        <?php 
                                                                        $marketData = json_decode($marketData, TRUE);
                                                                        foreach($marketData as $market){ 
                                                                        foreach($market['tradingPairs'] as $tradingPairs){ 
                                                                        ?>
                                                                        <option value="<?php echo $tradingPairs['pair']; ?>" selected><?php echo $tradingPairs['pair']; ?></option>
                                                                        <?php }} ?>
                                                                    </select>
                                                                </div>
                                                            </div>
															<div class="form-group form-inline w-100 mb-2">
                                        <label style="padding-right: 10px;margin-right:10px;"> Trading Result:</label>
                                                                <div class="input-group">
                                                                    <select class="form-control" style="height: 40px !important; border:1px grey solid; background-color: #00150f; color:white" id="signal_result" name="signal_result">
                                                                        <option value="profit" selected>Profit</option>
                                                                        <option value="loss">Loss</option>
                                                                    </select>
                                                                </div>
                                                            </div>
															<div class="form-group form-inline w-100 mb-2">
                                        <label style="padding-right: 10px;margin-right:10px;"> Trading Type:</label>
                                                                <div class="input-group">
                                                                    <select class="form-control" style="height: 40px !important; border:1px grey solid; background-color: #00150f; color:white" id="signal_type" name="signal_type">
                                                                        <option value="buy" selected>Buy</option>
                                                                        <option value="sell">Sell</option>
                                                                    </select>
                                                                </div>
                                                            </div>
							<div class="form-group form-inline w-100 mb-2">
                                        <label style="padding-right: 10px;margin-right:10px;">Expiration Time</label>
                                                                <div class="input-group">
                                                                    <select class="form-control" style="height: 40px !important; border:1px grey solid; background-color: #00150f; color:white" id="signal_time" name="signal_time">
                                                                        <?php
                                                                        
                                                                           for($x = 1; $x<=60; $x++){
                                                                        ?>
                                                                        <option value="<?php echo $x; ?>"><?php echo $x; ?> Minutes</option>
                                                                            <?php } ?>
                                                                    </select>
                                                                </div>
                                                            </div>
															<div class="form-group form-inline w-100 mb-2">
                                        <label style="padding-right: 10px;margin-right:10px;">Percentage Profit</label>
                                                                <div class="input-group">
                                                                    <select class="form-control w-100" style="height: 40px !important; border:1px grey solid; background-color: #00150f; color:white" id="signal_percentage" name="signal_percentage">
                                                                        <?php
                                                                        
                                                                           for($x = 1; $x<=100; $x++){
                                                                        ?>
                                                                        <option value="<?php echo $x; ?>"><?php echo $x; ?> %</option>
                                                                            <?php } ?>
                                                                    </select>
                                                                </div>
                                                            </div>
							<!-- <input type="hidden" class="" value="<?php //echo $sendData['customer_email']; ?>" name="investment_email"> -->
							<button type="submit" name="create_signals" value="true" class="btn btn-sm btn-success">Add Signal</button>
							</form>	
					<table class="table">
						<thead>
							<td>signal pair</td>
							<td>signal percentage</td>
							<td>signal type</td>
							<td>signal time</td>
							<td>signal result</td>
							<td>Action</td>
						</thead>
						<?php
						$getData = "SELECT * FROM trade_signals";
						$retrieveData = mysqli_query($cxn, $getData);
						if($retrieveData){
					
							$countall = mysqli_num_rows($retrieveData);
							while($sendData = mysqli_fetch_array($retrieveData)){
						?>			
						<tr>
							<td><?php echo $sendData['signal_pair']; ?></td>
							<td>
							<?php echo $sendData['signal_percentage']; ?>%</td>
							<td><?php echo $sendData['signal_type']; ?></td>
							<td><?php echo $sendData['signal_time']; ?> Minutes</td>
							<td><?php echo $sendData['signal_result']; ?></td>
							<td>
							<a href="delete.php?signal_id=<?php echo $sendData['signal_id']; ?>" class="btn btn-sm btn-danger">Delete Signal</a></td>
						</tr>
						<?php }} ?>
					</table>
				</div>
			</div>
		</div>
		</div>
	</section>

</body>

</html>