<?php

include "main.php";

isconnected();

if(isset($_REQUEST['action']))
{
	$action = $_REQUEST['action'];
	if($action == 1)
	{
		$id = AntiInjectionSQL($_REQUEST['id']);
		
		$SQL = "DELETE FROM numero WHERE idgroupe = $id";
		$pdo->query($SQL);
		
		$SQL = "DELETE FROM groupe WHERE id = $id";
		$pdo->query($SQL);
		
		header("Location: groupe.php");
		exit;
	}
}

?>

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- The above 4 meta tags *must* come first in the head; any other head content must come *after* these tags -->

    <!-- Title -->
    <title>SMS Sender</title>

    <!-- Favicon -->
    <link rel="icon" href="img/core-img/favicon.png">

    <!-- Master Stylesheet [If you remove this CSS file, your file will be broken undoubtedly.] -->
    <link rel="stylesheet" href="style.css">

</head>

<body>
    <!-- Preloader Start -->
    <div id="preloader">
        <div class="preload-content">
            <div id="hasro-load"></div>
        </div>
    </div>
    <!-- Preloader End -->

    <!-- ======================================
    ******* Page Wrapper Area Start **********
    ======================================= -->
    <div class="ecaps-page-wrapper">
        <!-- Sidemenu Area -->
        <?php
		
		include "menu.php";
		
		$SQL = "SELECT COUNT(*) FROM groupe";
		$r = $pdo->query($SQL);
		$rr = $r->fetch();
		
		$count = $rr[0];
		
		?>

            <!-- Main Content Area -->
            <div class="main-content">
                <div class="container-fluid">
                    <div class="row justify-content-center">
                        <div class="col-sm-12 col-lg-12">
							<div class="card box-margin">
								<div class="card-body">
									<h3><i class="bx bx-user-circle"></i> Groupe</h3>
									<div style="margin-bottom:20px;">
									<a href="addgroupe.php" class="btn btn-primary mr-2"><i class="zmdi zmdi-collection-plus"></i> Créer un groupe</a>
									</div>
									<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100">
                                            <thead>
                                                <tr>
                                                    <th>Nom du groupe</th>
													<th>Nombre de numéro</th>
                                                    <th>Option</th>
                                                </tr>
                                            </thead>
											<?php
											if($count == 0)
											{
												?>
												</table>
												<div style="font-size: 23px;text-align: center;padding-top: 50px;padding-bottom: 50px;">Aucun groupe pour le moment<br><a href="addgroupe.php" class="btn btn-primary mr-2"><i class="zmdi zmdi-collection-plus"></i> Ajouter un nouveau Groupe</a></div>
												<?php
											}
											else
											{
											?>
											<tbody>
												<?php
												
												$SQL = "SELECT * FROM groupe";
												$reponse = $pdo->query($SQL);
												while($req = $reponse->fetch())
												{
													$idgroupe = $req['id'];
													$SQL = "SELECT COUNT(*) FROM numero WHERE idgroupe = $idgroupe";
													$r = $pdo->query($SQL);
													$rr = $r->fetch();
													$count = $rr[0];
													
													?>
													<tr>
														<td><?php echo $req['nom']; ?></td>
														<td><?php echo $count; ?></td>
														<td>
															<a href="groupe.php?action=1&id=<?php echo $idgroupe; ?>" class="btn btn-danger mb-2 mr-2"><i class="zmdi zmdi-delete"></i> Supprimer</a>
															<a href="editgroupe.php?id=<?php echo $idgroupe; ?>" class="btn btn-primary mb-2 mr-2"><i class="zmdi zmdi-edit"></i> Modifier</a>
															<a href="addnumbergroupe.php?id=<?php echo $req['id']; ?>" class="btn btn-info mb-2 mr-2"><i class="zmdi zmdi-phone"></i> Ajouter des numéros</a>
														</td>
													</tr>
													<?php
												}
												
												?>
											</tbody>
									</table>
											<?php
											}
											?>
								</div>
							</div>
                        </div>
                        
                    </div>

                    <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-modal="false">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title mt-0 font-16" id="myLargeModalLabel">Add New Customer</h5><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                </div>
                                <div class="modal-body">
                                    <form>
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group"><label for="LeadName">Name</label> <input type="text" class="form-control" id="LeadName" required=""></div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group"><label for="LeadEmail">Email</label> <input type="email" class="form-control" id="LeadEmail" required=""></div>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group"><label for="PhoneNo">Phone No</label> <input type="text" class="form-control" id="PhoneNo" required=""></div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group"><label for="status-select" class="mr-2">Country</label> <select class="custom-select" id="status-select">
                                                        <option selected="">Select</option>
                                                        <option value="1">India</option>
                                                        <option value="2">USA</option>
                                                        <option value="3">Japan</option>
                                                        <option value="4">China</option>
                                                        <option value="5">Germany</option>
                                                    </select></div>
                                            </div>
                                        </div><button type="button" class="btn btn-sm btn-primary">Save</button> <button type="button" class="btn btn-sm btn-danger">Delete</button>
                                    </form>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div>

                </div>

                <!-- Footer Area -->
            </div>
        </div>
    </div>

    <!-- ======================================
    ********* Page Wrapper Area End ***********
    ======================================= -->

    <!-- Must needed plugins to the run this Template -->
    <script src="js/jquery.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bundle.js"></script>
    <script src="js/default-assets/setting.js"></script>

    <!-- Active JS -->
    <script src="js/default-assets/active.js"></script>

    <script src="js/default-assets/ammap.min.js"></script>
    <script src="js/default-assets/radar.js"></script>
    <script src="js/default-assets/widget-page-chart-active.js"></script>

    <script src="js/default-assets/apexchart.min.js"></script>
    <script src="js/default-assets/dashboard-active.js"></script>


</body>

</html>