<?php include('site-header.php'); ?>
  <!-- end of LOGO CONTAINER -->
  <!-- - - - - - - - - - - - - -->
  <!-- start of SIDEBAR        -->
  <!-- - - - - - - - - - - - - -->
  <?php include('left-nevigation.php'); ?>
  
  <!-- - - - - - - - - - - - - -->
  <!-- end of SIDEBAR          -->
  <!-- - - - - - - - - - - - - -->
  <main id="playground">
    <!-- - - - - - - - - - - - - -->
    <!-- start of TOP NAVIGATION -->
    <!-- - - - - - - - - - - - - -->
 <?php include('site-top-header.php'); ?>
    <?php
    $id  = mysqli_real_escape_string($link,$_GET['del']);
    if(isset($_GET['del']))
    {
        if(mysqli_query($link,"DELETE FROM `tbl_application` WHERE app_id=$id"))
        {
          echo "<script>window.location.href='show-application.php';</script>";
        }
    }
    ?>
    <!-- Add Home Page Application -->
    <?php
    if(isset($_POST['add']))
    {
      $hid = $_POST['hid'];
      $add = $_POST['add'];
      mysqli_query($link,"update tbl_application set app_home='$add' where app_id=$hid");
    }
    ?>
    <!-- Remove From Home page Application -->
    <?php
     if(isset($_POST['remove']))
    {
      $hid = $_POST['hid'];
      $remove = $_POST['remove'];
      mysqli_query($link,"update tbl_application set app_home='$remove' where app_id=$hid");
    }
    ?>
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Dashboard</h1>
        <p class="lead">Update your application below</strong>.</p>
      </div>
      <div class="col-md-4">
        <ol class="breadcrumb pull-right no-margin-bottom">
         
          <li><a href="dashboard.html">Dashboard</a></li>
          <li class="active">Add Application</li>
        </ol>
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-4">
          <section class="panel tasks-widget"></section>
        </div>
        <div class="col-md-4">
          <div class="panel-body"> <form method="post">
          
           
             <div class="form-group text-center"> <button class="btn btn-primary" name="send"><a href="add-application.php">Add New Application</a></button> </div>
           
          </form>
          </div>
        </div>
        <div class="col-md-4">
          <section class="panel tasks-widget"></section>
        </div>
      </div>
   
      
      <!-- / row -->
      <div class="row">
        <div class="col-md-12">
          <section class="panel panel-primary">
            <header class="panel-heading">
              <h3 class="panel-title">Existing Categories</h3>
            </header>
            
            <table class="table table-hover table-responsive" width="100%">
            <tbody>
              <tr>
                <th scope="row" style="color:black;">S. No</th>
                <th style="color:black;">Application Name</th>
                <th style="color:black;">Application Desc</th>
                <th style="color:black;">Add Home Application</th>
                <th style="color:black;">Action</th>
              </tr>
              <?php
              $sn=0;
              $sel = mysqli_query($link,"select * from tbl_application");
              while($arr = mysqli_fetch_assoc($sel))
              {
                $sn++;
              ?>
              <tr>
                  <td><?=$sn?></td>
                  <td><?=$arr['app_name']?></td>
                  <td style="width:500px;"><?=mb_strimwidth($arr['app_desc'],0,200,"....");?></td>
                  <td>
                    <?php
                    if($arr['app_home']=="Home")
                    {
                      ?>
                      <form method="post">
                        <input type="hidden" name="hid" value="<?=$arr['app_id'];?>">
                        <input type="submit" name="remove" value="Remove" class="btn btn-danger">
                      </form>
                      <?php
                    }
                    else
                    {
                      ?>
                      <form method="post">
                        <input type="hidden" name="hid" value="<?=$arr['app_id'];?>">
                        <input type="submit" name="add" value="Home" class="btn btn-success">
                      </form>
                      <?php
                    }
                    ?>
                  </td>
                  <td><a class="btn btn-success"  href="add-application.php?edit=<?=$arr['app_id'];?>">Edit</a>&nbsp;<a class="btn btn-danger" href="?del=<?=$arr['app_id'];?>">Delete</a></td>
              </tr>
              <?php
              }
              ?>
          </tbody>
            </table>
            
              
          </section>
        </div>
      </div>
    </div>
    <!-- / container-fluid -->
 <?php include('site-footer.php'); ?>