 <?php include('partials/menu.php'); ?>

     <!--main content section starts here-->
     <div class="main-content">
       <div class="wrapper">
         <h1>Manage Admin</h1>
         <br></br><br>
         <?php
            if (isset($_SESSION['add'])) {
              echo $_SESSION['add'];//displaying session msg
              unset($_SESSION['add']);//REMOVING SESSION MSG
              // code...
            }
            if (isset($_SESSION['delete'])) {
              echo $_SESSION['delete'];//displaying session msg
              unset($_SESSION['delete']);//REMOVING SESSION MSG
              // code...
            }
            if (isset($_SESSION['update'])) {
              echo $_SESSION['update'];//displaying session msg
              unset($_SESSION['update']);//REMOVING SESSION MSG
              // code...
            }
            if (isset($_SESSION['user-not-found'])) {
              echo $_SESSION['user-not-found'];//displaying session msg
              unset($_SESSION['user-not-found']);//REMOVING SESSION MSG
              // code...
            }
            if (isset($_SESSION['new-password-and-confirm-pasword-does-not-match'])) {
              echo $_SESSION['new-password-and-confirm-pasword-does-not-match'];//displaying session msg
              unset($_SESSION['new-password-and-confirm-pasword-does-not-match']);//REMOVING SESSION MSG
              // code...
            }
            if (isset($_SESSION['update-password'])) {
              echo $_SESSION['update-password'];//displaying session msg
              unset($_SESSION['update-password']);//REMOVING SESSION MSG
              // code...
            }

          ?>
          <br></br><br>
         <!--btn to add admin-->
         <a href="add-admin.php" class="btnprimary">Add Admin</a>
         <br></br><br>
         <table class="full">
           <tr>
             <th>S.N</th>
             <th>Fullname</th>
             <th>Username</th>
             <th>Actions</th>
           </tr>
           <?php
              //query to get all admin frm db
              $sql = "SELECT * FROM tbl_admin";
              //execute the querry
              $res = mysqli_query($conn, $sql);
              //check whether the querry is executed or not
              if($res==TRUE){
                //COUNT ROWS TO TO CHECK whether WE HAVE DATA IN DB OR NOT
                $count = mysqli_num_rows($res);//function to get all rows in db
                $sn=1; //create a var and assign the value
                //check the num of rows
                if($count>0){
                  //we have data in db
                  while($rows=mysqli_fetch_assoc($res)){
                    //using while loop to get data frm db
                    //while loop will only run as long there is data in the db

                    //get individual data
                    $id = $rows['id'];
                    $fullname = $rows['fullname'];
                    $username = $rows['username'];

                    //displaying the values in the table
                    ?>
                    <tr>
                      <td><?php echo $sn++; ?></td>
                      <td><?php echo $fullname ?></td>
                      <td><?php echo $username; ?></td>
                      <td>
                        <a href="<?php echo SITEURL; ?>backend/update-password.php?id=<?php echo $id; ?>" class="btnprimary">Change Password</a>
                        <a href="<?php echo SITEURL; ?>backend/updateadmin.php?id=<?php echo $id; ?>" class="btnsecondary">Update Admin</a>
                        <a href="<?php echo SITEURL; ?>backend/deleteadmin.php?id=<?php echo $id; ?>" class="btndanger">Delete Admin</a>


                      </td>
                    </tr>
                    <?php
                  }
                }
                else{
                  //we do not have data in the db

                }
              }
            ?>

         </table>

       </div>

     </div>
     <!--main content section ends here-->
<?php include('partials/footer.php'); ?>
