<!DOCTYPE html>
<html lang="en">
<head>
<?php

include "header.php";

?>		
</head>
<body data-background-color="dark">
    <div id="app">
        
        <!--/PayPal-->
            
        <!--Start of Tawk.to Script-->
        <script type="text/javascript">
        {tawk to codess}
        </script>
        <!--End of Tawk.to Script-->
		<div class="wrapper">
			        <div class="main-header">
    <!-- Logo Header -->
<div class="logo-header" data-background-color="blue">
        <a href="/" class="logo" style="font-size: 27px; color:#fff;">
            P.S.M
        </a>
    <button class="ml-auto navbar-toggler sidenav-toggler" type="button" data-toggle="collapse" data-target="collapse" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon">
                <i class="icon-menu "></i>
            </span>
        </button>
        <button class="topbar-toggler more"><i class="icon-options-vertical "></i></button>
        <div class="nav-toggle">
            <button class="btn btn-toggle toggle-sidebar">
                <i class="icon-menu "></i>
            </button>
        </div>
        
    </div>
    <!-- End Logo Header -->

    <!-- Navbar Header -->
    <nav class="navbar navbar-header navbar-expand-lg" data-background-color="blue">
        
        <div class="container-fluid">
            <div class="collapse" id="search-nav">
                
                <script>
                    document.getElementById('searchform').addEventListener('subit' searchuser);
                   function searchuser(){
                       console.log('ddj');
                       let url = "https://platinumsignalmarket.com/trader/admin/dashboard/manageusers";
                       window.location.href = url;
                   }
               </script>
            </div>
            <ul class="navbar-nav topbar-nav ml-md-auto align-items-center">
                <li>
                    <form action="javascript:void(0)" method="post" id="styleform">
                        <div class="form-group">
                            <label class="style_switch">
                                <input name="style" id="style" type="checkbox" value="true" class="modes">
                                <span class="slider round"></span>
                            </label>
                        </div> 
                                                <input type="hidden" name="_token" value="yK4ImZn4tFp3FCzhv1hy9ADjxOMulCa9eCDdVVZt">
                    </form>
                    
                </li>
                                <li class="nav-item dropdown hidden-caret">
                    <a class="nav-link" data-toggle="dropdown" href="#" aria-expanded="false">
                        <i class="text-white fas fa-user"></i>
                    </a>
                   
                    <ul class="dropdown-menu dropdown-user animated fadeIn">
                        <div class="dropdown-user-scroll scrollbar-outer">
                            <li>
                                <a class="dropdown-item" href="adminchangepassword.php">Change Password</a>
                                <div class="dropdown-divider"></div>
                                <a class="dropdown-item" href="logout.php">
                                Logout
                                </a>
                            </li>
                        </div>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
    <!-- End Navbar -->
</div>


<script type="text/javascript">
    //create investment
        $("#styleform").on('change',function(){
        $.ajax({
            url: "https://platinumsignalmarket.com/trader/admin/dashboard/changestyle",
            type: 'POST',
            data:$("#styleform").serialize(),
            success: function (data) {
				location.reload(true);
            },
            error: function (data) {
                console.log('Something went wrong');
            },

        });
    });
    
</script>
        <!-- Stored in resources/views/child.blade.php -->

<!-- Sidebar -->
<?php

    include "sidebar.php";

?>

<!-- End Sidebar -->
        <div class="main-panel">
			<div class="content bg-light">
				<div class="page-inner">
					<div class="mt-2 mb-4">
						<h1 class="title1 text-dark">P.S.M users list</h1>
					</div>
					
					<div>
    </div>                    <div>
    </div>					<div class="row">
						<div class="col-12">
														<a href="" data-toggle="modal" data-target="#adduser" class="btn btn-warning btn-lg">ADD TRADER</a>
							 
							
							<!-- Modal -->
							<div class="modal fade" id="adduser" tabindex="-1" aria-h6ledby="exampleModalh6" aria-hidden="true">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header bg-light">
											<h3 class="mb-2 d-inline text-dark">Manually Add Traders</h3>
											<button type="button" class="close text-dark" data-dismiss="modal" aria-h6="Close">
											<span aria-hidden="true">&times;</span>
											</button>
										</div>
										<div class="modal-body bg-light">
											<div>
												<form method="POST" action="add_trader.php" enctype="multipart/form-data">
													<input type="hidden" name="_token" value="yK4ImZn4tFp3FCzhv1hy9ADjxOMulCa9eCDdVVZt">													<div class="form-row">
														<div class="form-group col-md-12">
															<h6 class="text-dark">Name</h6>
															<input type="text" class="form-control bg-light text-dark" name="name" required>
														</div>
														<div class="form-group col-md-12">
															<h6 class="text-dark">Experience</h6>
															<input type="text" class="form-control bg-light text-dark" name="experience" required>
														</div>
														<div class="form-group col-md-12">
															<h6 class="text-dark">Trader Image</h6>
															<input type="file" class="form-control bg-light text-dark" name="fileToUpload" id="fileToUpload">
														</div>
													</div>
													<button type="submit" class="px-4 btn btn-primary">Add User</button>
												</form>  
											</div>
											
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="mb-5 row">
						
						<div class="col-md-12 shadow card p-4 bg-light">
							<div class="row">
								<div class="col-12">
									<form class=" form-inline">
										<div class="">
											<select class="form-control bg-light text-dark" id="numofrecord">
												<option>10</option>
												<option>20</option>
												<option>30</option>
												<option>40</option>
												<option>50</option>
												<option>100</option>
												<option>200</option>
												<option>300</option>
												<option>400</option>
												<option>500</option>
												<option>600</option>
												<option>700</option>
												<option>800</option>
												<option>900</option>
												<option>1000</option>
											</select>
										</div>
										<div class="">
											<select class="form-control bg-light text-dark" id="order">
												<option value="desc">Descending</option>
												<option value="asc">Ascending</option>
											</select>
										</div>
										<div>
											<input type="text" id="searchitem" placeholder="Search by name or email" class="float-rightmb-2 mr-sm-2 form-control bg-light text-dark">
											<small id="errorsearch"></small>	
										</div>
										
									</form>
								</div>
							</div>
							<div class="table-responsive" data-example-id="hoverable-table"> 
								<table class="table table-hover text-dark"> 
									<thead> 
										<tr> 
											<th>ID</th>
											<th>name</th> 
											<th>experience</th>
											<th>image</th>
											<th>Action</th> 
										</tr> 
									</thead> 
									<tbody id="userslisttbl"> 
										<?php
                                                            $rs= mysqli_query($link, "SELECT * FROM copy_traders ");
                                                            if ($rs AND mysqli_num_rows($rs) > 0) {
                                                                while ($row = mysqli_fetch_assoc($rs)){
                                                                    $sn++;
                                                                    
                                                                    echo "
                                                                       <tr> 
											<td>".$row['id']."</td>
											<td>".$row['name']."</td> 
											<td>".$row['experience']."</td>
											<td>".$row['image']."</td> 
											<td> 
												<a href='trader-delete.php?id=".$row['id']."' class='m-1 btn btn-danger btn-sm'>DELETE</a> 

																							</td> 
										</tr> ";
                                                                }
                                                            }

                                                        ?>
									</tbody> 
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
			<script>
				$('#input1').on('keypress', function(e) {
					return e.which !== 32;
				});
			</script>
	<script>
		function getallusers(){
			let number = document.querySelector('#numofrecord').value;
			let searchvalue = document.querySelector('#searchitem').value;
			let ordervalue = document.querySelector('#order').value;
			let table = document.querySelector('#userslisttbl');
			
			if (searchvalue == "") {
				searchvalue = "query";
			} else {
				searchvalue = searchvalue;
			}

			let url = "https://platinumsignalmarket.com/trader/admin/dashboard/getusers" + '/' + number + '/' + searchvalue + '/' + ordervalue;

			fetch(url)
			.then(function(res){
				return res.json();
			})
			.then(function (response){
				if(response.status === 200){
					table.innerHTML = response.data;
					document.querySelector('#searchitem').style.borderColor = '';
				}
				if(response.status === 201){
					table.innerHTML = response.data;
					document.querySelector('#searchitem').style.borderColor = 'red';
				}
			})
			.catch(function(err){
				console.log(err);
			});
			
		}

		let numberopt = document.querySelector('#numofrecord');
		let searchbox = document.querySelector('#searchitem');
		let order = document.querySelector('#order');
		numberopt.addEventListener('change', getallusers);
		order.addEventListener('change', getallusers);
		searchbox.addEventListener('keyup', getallusers);
		getallusers();

		function viewuser(id){
			let url = "https://platinumsignalmarket.com/trader/admin/dashboard/user-details" + '/' + id;
			window.location.href = url;
		}
	</script>
	<!-- send all users email -->
	<div id="sendmailModal" class="modal fade" role="dialog">
		<div class="modal-dialog">

		  <!-- Modal content-->
		  <div class="modal-content">
			<div class="modal-header bg-light">
			  <h4 class="modal-title text-dark">This message will be sent to all your users.</h4>
			  <button type="button" class="close text-dark" data-dismiss="modal">&times;</button>
			</div>
			<div class="modal-body bg-light">
				  <form method="post" action="https://platinumsignalmarket.com/trader/admin/dashboard/sendmailtoall">
					<input type="hidden" name="_token" value="yK4ImZn4tFp3FCzhv1hy9ADjxOMulCa9eCDdVVZt">					
					<div class=" form-group">
						<input type="text" name="subject" class="form-control bg-light text-dark" placeholder="Subject" required>
					</div>
					<div class=" form-group">
						<textarea placeholder="Type your message here" class="form-control bg-light text-dark" name="message" row="8" placeholder="Type your message here" required></textarea>
					</div>
					<div class=" form-group">
						<input type="submit" class="btn btn-dark" value="Send">
					</div>
				 </form>
			</div>
		  </div>
		</div>
	  </div>
	  <!-- /send all users email Modal -->
				<footer class="footer bg-dark text-light">
					<div class="container-fluid">
						<div class="text-center row copyright text-align-center">
							<p>All Rights Reserved &copy; P.S.M 2022</p>
						</div>
					</div>
				</footer>
			</div>
		</div>
	</div>

				<!--   Core JS Files   -->
				<?php

include "footer.php";

?>
</body>
</html>


