<?php include('site-header.php'); ?>
  <!-- end of LOGO CONTAINER -->
  <!-- - - - - - - - - - - - - -->
  <!-- start of SIDEBAR        -->
  <!-- - - - - - - - - - - - - -->
<?php include('left-nevigation.php'); ?>
  <!-- - - - - - - - - - - - - -->
  <!-- end of SIDEBAR          -->
  <!-- - - - - - - - - - - - - -->
  <main id="playground">
  <script src="ckeditor/ckeditor.js"></script>
    <!-- - - - - - - - - - - - - -->
    <!-- start of TOP NAVIGATION -->
    <!-- - - - - - - - - - - - - -->
    <nav class="navbar navbar-top navbar-static-top">
      <div class="container-fluid">
        <!-- sidebar collapse and toggle buttons get grouped for better mobile display -->
        <div class="navbar-header nav">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-top"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="navbar-top">
          <ul class="nav navbar-nav navbar-right">
            <li class="dropdown user-profile"> <a href="#logout.php" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
              <div class="user-img-container"> <img src="demofiles/demoimage.gif" alt=""> </div>
              Sign Out <span class="chat-status success"></span> </a> </li>
          </ul>
        </div>
      </div>
      <!-- end of container-fluid -->
    </nav>
    <!-- - - - - - - - - - - - - -->
    <!-- end of TOP NAVIGATION   -->
    <!-- - - - - - - - - - - - - -->
    <!-- PAGE TITLE -->
    <?php
    if (isset($_POST['add'])) {
        $list_name = $_POST['add_one'];
        if(mysqli_query($link,"INSERT INTO tbl_add_list(list_name) VALUES('$list_name')"))
        {
          $msg = "<p>Add on list Successfully...</p>";
        }
        else
        {
          $msg = "<p>Not inserted...</p>";
        }
    }
    ?>
    <!-- Delete Table -->
    <?php
    if(isset($_POST['delete']))
    {
      $id = $_POST['eid'];
      $tbl_list = mysqli_query($link, "DELETE FROM tbl_add_list WHERE id=$id");
      $tbl_arr1 = mysqli_fetch_assoc($tbl_list);
    }
    ?>
    <!-- Edit Table -->
     <?php
    if (isset($_POST['update'])) {
        $list_id = $_POST['hid'];
        $list_name = $_POST['add_one'];
        if(mysqli_query($link,"UPDATE tbl_add_list SET list_name='$list_name' WHERE id=$list_id"))
        {
          $msg = "<p>Update list Successfully...</p>";
        }
        else
        {
          $msg = "<p>Not inserted...</p>";
        }
    }
    ?>
    <?php
    if(isset($_POST['edit']))
    {
      $id = $_POST['eid'];
      $tbl_list = mysqli_query($link, "select * from tbl_add_list where id=$id");
      $tbl_arr1 = mysqli_fetch_assoc($tbl_list);
    }
    $tbl_list = mysqli_query($link, "select * from tbl_add_list");
    $list_rows = mysqli_num_rows($tbl_list);
    ?>
    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>GRC LISTING</h1>
        <p class="lead">Add/Update your listing below</strong>.</p>
      </div>
      <div class="col-md-4">
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div class="row"><?=@$msg1;?></div>
      <div class="col-md-12"><a href="update-grc.php" class="btn btn-primary">Back</a></div>
      <div class="col-md-4">
        <form method="post">
            <?php
            if($list_rows<=9)
            {
            ?>
              <div class="form-group">
                <input type="text" value="<?=$tbl_arr1['list_name'];?>" name="add_one" class="form-control" placeholder="Enter listing name..."><br>
              </div>
              <div class="form-group">
                <?php
                if(isset($_POST['edit']))
                {
                  ?>
                  <input type="hidden" name="hid" value="<?=$tbl_arr1['id'];?>">
                  <button class="btn btn-info" name="update">Update</button>
                  <?php
                }
                else
                {
                  ?>
                  <button class="btn btn-info" name="add">Add</button>
                  <?php
                }
                ?>
            <?php
            }
             else
                {
                  ?>
                  <div class="form-group">
                    <input type="text" value="<?=$tbl_arr1['list_name'];?>" name="add_one" class="form-control" placeholder="Enter listing name..."><br>
                    <input type="hidden" name="hid" value="<?=$tbl_arr1['id'];?>">
                    <button class="btn btn-info" name="update">Update</button>
                  <?php
                }
            ?>
          </div>
        </form>
      </div>
      <!-- Fetching Data -->
      <div class="col-md-8">
        <table class="table table-responsive">
          <thead>
            <tr>
              <th>Sn.</th>
              <th>List Name</th>
              <th>Action</th>
            </tr>
          </thead>
         <tbody>
          <?php
          $sn = 1;
          $tbl_list = mysqli_query($link, "select * from tbl_add_list");
          while($tbl_arr = mysqli_fetch_assoc($tbl_list))
          {
          ?>
           <tr>
              <td><?=$sn;?></td>
              <td><?php echo $tbl_arr['list_name'];?></td>
              <td><form method="post"><input type="hidden" name="eid" value="<?=$tbl_arr['id'];?>"><input type="submit" name="edit" value="edit"  class="btn btn-success btn-xs">&nbsp;<input type="submit" name="delete" value="delete" class="btn btn-danger btn-xs"></form></td>
            </tr>
          <?php
          $sn++;
          }
          ?>

         </tbody>
        </table>
      </div>
    </div>
 <?php include('site-footer.php'); ?>