<?php
include_once"config.php";
session_start();

if($_SESSION['loginuser']!='admin'){
	header("location:index.php");
}
$q = mysqli_query($con, "select * from add_special_category  ");
$edit_id = isset($_GET['id'])?$_GET['id']:null;
if($edit_id){
$query = mysqli_query($con,"select * from add_special_category as esc  where  id = $edit_id");
$d = mysqli_fetch_array($query);
}
$status = isset($d['status'])?$d['status']:null;
 $id = isset($d['id'])?$d['id']:null;
$per = isset($d['percent'])?$d['percent']:0;
$name = isset($d['name'])?$d['name']:null;
$na = isset($d['na'])?$d['na']:null;
$pid = isset($d['pid'])?$d['pid']:0;
$try = isset($_SESSION['try'])?$_SESSION['try']:null;

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Twitter -->
    <meta name="twitter:site" content="@themepixels">
    <meta name="twitter:creator" content="@themepixels">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="Starlight">
    <meta name="twitter:description" content="Premium Quality and Responsive UI for Dashboard.">
    <meta name="twitter:image" content="http://themepixels.me/starlight/img/starlight-social.png">

    <!-- Facebook -->
    <meta property="og:url" content="http://themepixels.me/starlight">
    <meta property="og:title" content="Starlight">
    <meta property="og:description" content="Premium Quality and Responsive UI for Dashboard.">

    <meta property="og:image" content="http://themepixels.me/starlight/img/starlight-social.png">
    <meta property="og:image:secure_url" content="http://themepixels.me/starlight/img/starlight-social.png">
    <meta property="og:image:type" content="image/png">
    <meta property="og:image:width" content="1200">
    <meta property="og:image:height" content="600">

    <!-- Meta -->
    <meta name="description" content="Premium Quality and Responsive UI for Dashboard.">
    <meta name="author" content="ThemePixels">

   <title> :: SMS DataTable ::</title>

    <!-- vendor css -->
    <link href="lib/font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="lib/Ionicons/css/ionicons.css" rel="stylesheet">
    <link href="lib/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet">
    <link href="lib/highlightjs/github.css" rel="stylesheet">
    <link href="lib/select2/css/select2.min.css" rel="stylesheet">

    <link href="lib/datatables/jquery.dataTables.css" rel="stylesheet">
    <!-- Starlight CSS -->
    <link rel="stylesheet" href="css/starlight.css">
	
	
  </head>

  <body>

    <!-- ########## START: LEFT PANEL ########## -->
    <?php include_once"menu.php"; ?>
    <!-- ########## END: LEFT PANEL ########## -->

    <!-- ########## START: HEAD PANEL ########## -->
    <?php include_once"header.php";?>
    <!-- ########## END: HEAD PANEL ########## -->

    <!-- ########## START: RIGHT PANEL ########## -->
    
    <!-- ########## END: RIGHT PANEL ########## --->

    <!-- ########## START: MAIN PANEL ########## -->
    <div class="sl-mainpanel">
      <nav class="breadcrumb sl-breadcrumb">
        <a class="breadcrumb-item" href="index.html">SMS DATABASE </a>
        <a class="breadcrumb-item" href="index.html">Categories</a>
        <span class="breadcrumb-item active">Categories</span>
      </nav>

      <div class="sl-pagebody" id="add-category">
        <div class="sl-page-title">
          <h5>Add Category</h5>
         
		 </div><!-- sl-page-title -->
<?php if($try == 1){success_insert();}elseif($try == 2){update();}elseif($try == 3){ deleted();}elseif($try == 4){ tryagain();} unset($_SESSION['try']); ?>
        <div class="card pd-20 pd-sm-40">
          <h6 class="card-body-title">Add Category</h6>
		  <p class="mg-b-20 mg-sm-b-30"></p>
          <!--<p class="mg-b-20 mg-sm-b-30">A form with a label on top of each form control.</p>-->
<form method="post" action="query/add_category.php" data-parsley-validate >

<input type="hidden" name="id" value="<?= $id ; ?>">
          <div class="form-layout">
            <div class="row mg-b-25">
              <div class="col-lg-4">
                <div class="form-group">
                  <label class="form-control-label">Category Name: <span class="tx-danger">*</span></label>
                  <input class="form-control" type="text" id="name" name="name" value="<?= $name; ?>" placeholder="Enter Category" required>
                </div>
              </div><!-- col-4 -->
			  
			 
              
              
              <div class="col-lg-4">
                <div class="form-group mg-b-10-force">
                  <label class="form-control-label">Status: <span class="tx-danger">*</span></label>
                  <select class="form-control select" name="status" data-placeholder="Choose Status" required>
                   
                    <option value="1" <?php if($status == 1){echo 'selected';}?>>Active</option>
                    <option value="2"  <?php if($status == 2){echo 'selected';}?>>Inactive</option>
                  </select>
                </div>
              </div><!-- col-4 -->
            </div><!-- row -->

            <div class="form-layout-footer">
           <?php if(!$id){ ?>
			<input type="submit" name="submit" class="btn btn-info mg-r-5" value="Save">
			<?php }else{ ?>
			<input type="submit" name="update" class="btn btn-info mg-r-5" value="Update">
			<?php } ?>
              <button class="btn btn-secondary">Cancel</button>
            </div><!-- form-layout-footer -->
          </div><!-- form-layout -->
		  </form>
		  
		  
		  
        </div><!-- card -->

        
      </div><!-- sl-pagebody -->
	  
	  <div class="sl-pagebody" id="all_categories">
        <div class="sl-page-title" >
          <h5>All Categories</h5>
         
        </div><!-- sl-page-title -->

        <div class="card pd-20 pd-sm-40">
         
          <div class="table-wrapper">
            <table id="datatable1" class="table display responsive nowrap">
              <thead>
                <tr>
                  <th class="wd-35p">Categories Name</th>
                  <th class="wd-20p">Status</th>
				   <th class="wd-15p" align="center">Action</th>
                </tr>
              </thead>
              <tbody>
			   <?php while($ar = mysqli_fetch_object($q)){ ?>
                <tr>
                  <td><?= $ar->name; ?></td>
                  <td><?php if($ar->status == 1){echo 'Active';}elseif($ar->status == 2){echo 'Inactive';}?></td>
				  <td align="left"><a href="?id=<?= $ar->id;?>" title="Delete">Edit  <i class="icon ion-edit tx-16"></i> </a> | <a href="query/add_category.php?delete=<?= $ar->id; ?>" title="Delete" onclick="return confirm(' you want to delete?');"> Delete <i class="icon ion-ios-trash-outline tx-16"></i> </a> </td>
			   </tr><?php } ?>
              </tbody>
            </table>
          </div><!-- table-wrapper -->
        </div><!-- card -->

       

        

      </div><!-- sl-pagebody -->
	  
      <footer class="sl-footer">
        
      </footer>
    </div><!-- sl-mainpanel -->
    <!-- ########## END: MAIN PANEL ########## -->

    <script src="lib/jquery/jquery.js"></script>
    <script src="lib/popper.js/popper.js"></script>
    <script src="lib/bootstrap/bootstrap.js"></script>
    <script src="lib/jquery-ui/jquery-ui.js"></script>
    <script src="lib/perfect-scrollbar/js/perfect-scrollbar.jquery.js"></script>
    <script src="lib/highlightjs/highlight.pack.js"></script>
    <script src="lib/select2/js/select2.min.js"></script>
	
	
    <script src="lib/datatables/jquery.dataTables.js"></script>
    <script src="lib/datatables-responsive/dataTables.responsive.js"></script>

    <script src="js/starlight.js"></script>
    <script>
      $(function(){
        'use strict';

        $('.select2').select2({
          minimumResultsForSearch: Infinity
        });
      })
    </script>
	 <script>
      $(function(){
        'use strict';

        $('#datatable1').DataTable({
          responsive: true,
          language: {
            searchPlaceholder: 'Search...',
            sSearch: '',
            lengthMenu: '_MENU_ items/page',
          }
        });

        $('#datatable2').DataTable({
          bLengthChange: false,
          searching: false,
          responsive: true
        });

        // Select2
        $('.dataTables_length select').select2({ minimumResultsForSearch: Infinity });

      });
    </script>
	
	<script src="lib/parsleyjs/parsley.js"></script>
  </body>
</html>
