<?php
@session_start();
include "control/activity.php";

 $dd = new activity();
 $loginStatus = $_SESSION['loginDetails'];


  if(isset($_SESSION['loginDetails'])){

  }else{
     header("Location:dashboard.php");
  }

  if($loginStatus == null){
    echo "<script>window.open('logout.php','_self')</script>";
  }



  $table = "admin_calculation";
  $condition = null;
  $getAdminDetails = $dd->single($table,$condition);
  
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title><?= $getAdminDetails['title']; ?></title>
</head>
<body>

    <div class="main" id="main">
		  <?php include "menu.php"; ?>
    <div class="right"> 
  <div class="tab-content">


   <?php include "headermenu.php"; ?>


        <!-- Overview -->
         <div id="overview" class="tab-pane active"  >
                <div class="content" >
                  
               <div class="content-wrapper">
                 <div class="container-fluid">

                      <!--======================================================  Content  ====================================================-->                                            
                          <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                              <a href="#"> Create Package</a>
                            </li>
                          </ol>

                          <div class="row">
                              <div class="col-xl-12 col-sm-12 mb-12">
                                 <table class="table table-bordered data-table">
                                    <form method="post">
                                    <tr>
                                        <td><input required name="packageName" class="form-control" placeholder="Package Name"/></td>
                                        <td><input required name="packamount" minlength="2" class="form-control" placeholder="Package Amount"/></td>
                                        <td><input required name="commission" class="form-control" placeholder="Commission in %"/></td>
                                        <td colspan="4px"> <button name="create_pack"  style="float:right;"> CREATED PACKAGE</button></td>
                                    </tr></form>
                                    <tr>
                                        <th>Sr</th>
                                        <th>Package Amount</th>
                                        <th>Created Date</th>
                                        <th>Commission</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    <?php
                                      $table = "create_package";
                                      $condition = null;
                                      $getPackage = $dd->fetch_multi($table,$condition);
                                      foreach($getPackage as $key){
                                        @$i++;
                                    ?>
                                     <tr>
                                        <td><?= $i; ?></td>
                                        <td><?= $key->package_amount; ?></td>
                                        <td><?= $key->created_date; ?></td>
                                        <td><?= $key->commission; ?>%</td>
                                        <td><?= $key->status_action; ?></td>
                                        <td><button onclick="getEditDetails(<?= $key->package_iid; ?>)" class="fa fa-edit"></button>
                                        <button onclick='delete_list("<?= $key->package_iid; ?>","<?= $key->status_action; ?>")' class="fa fa-trash"></button></td>
                                    </tr>

                                     <?php } ?>
                                 </table>
                              </div>
                          </div>
  
  
     
      </div>
      <!-- /.container-fluid-->
       </div>  <!-- /content-wrapper-->


                </div>
                </div>
             </div><!--Right panel-->
</div><!--Main-->

<script>
  function getEditDetails(a)
  {
     var ttt = confirm('Are you sure to Edit this..!!');
     if(ttt == true){
       window.open('getEditPackage.php?iid='+a,'_self');
     }
  }
</script>







<?php
 if(isset($_POST['create_pack']))
 {
     $packageName = $_POST['packageName'];
     $packamount = $_POST['packamount'];
     $commission = $_POST['commission'];
     $date = date("h:i d/m/Y");

     $table = "create_package";
     $value = "(`packageName`,`package_amount`, `created_date`, `commission`, `status_action`) 
     VALUES ('$packageName','$packamount','$date','$commission','Active')";
     $result = $dd->insertData($table,$value);
     if($result)
     {
        echo "<script>alert('Entry Successfully..!!'),window.open('?','_self')</script>";
     }
 }

?>

<script>
    function delete_list(a,b)
    {
        if(b == 'Active')
        {
            var rmrk = 'DEACTIVE';
        }
        else{
          var rmrk = 'ACTIVE';
        }

         var tttt = confirm('Are you sure to '+rmrk+' ..?');
         if(tttt == true)
         {
            window.open('deactive_package.php?iid='+a,'_self');
         }
    }
</script>






</body>
</html>

<?php include "style.php" ?>