<?php
	include "admin_top_menu.php";
	include "admin_side_menu.php";
	
	if($temp_id = isset($_GET['temp_id']) ? $_GET['temp_id'] : '')
	{
	   $row=mysqli_query($conn,"SELECT * FROM `category` WHERE ctid='$temp_id'");
		$data=mysqli_fetch_array($row);
	}
	else{
		$data['ctid']="";
		$data['ctname']="";
		$data['ctstatus']="";
	}
?>
  
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Category
        <small>Category List</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Category</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
	<form name="frmfabric" action="code.php" method="post" enctype="multipart/form-data">
      <!--<div class="panel-body" align="right">
        <a href="" data-toggle="tooltip" class="btn btn-primary btn-md"><i class="fa fa-book"></i> Create Category</a>
      </div>-->
	  <div class="box box-info">
        <div class="box-header with-border">
          <h3 class="box-title">Category List</h3>
		  
          <div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
          </div>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
          <div class="row">
            <div class="col-md-4">
              <div class="form-group">
                <label>Category Name</label>
				<input type="hidden" name="txt_ctid" value="<?php echo $data['ctid'];?>">
                <input type="text" class="form-control" name="txt_ctname" value="<?php echo $data['ctname'];?>" required="" >
              </div>
            </div>
			
			<div class="col-md-4">
              <div class="form-group">
                <label>Status</label>
				<select class="form-control" name="txt_ctstatus">
					<option value="<?php echo $data['ctstatus'];?>"><?php echo $data['ctstatus'];?></option>
					<option value="Active">Active</option>
					<option value="Deactive">Deactive</option>
				</select>
              </div>
            </div>
			
		  </div>
		</div>
		
		<div class="box-footer">
		<?php if($data['ctid']==''){ ?>
            <button type="submit" name="btn_ctsubmit" class="btn btn-info pull-right">Submit</button>
		<?php } else {?>
			<button type="submit" name="btn_ctupdate" class="btn btn-info pull-right">Update</button>
		<?php } ?>
        </div>
	</div>
		<?php   
			if(isset($_GET['status'])&&$_GET['status']==1)
			echo "<font color=green>Data Successfully Insert..</font>";
				
			if(isset($_GET['status'])&&$_GET['status']==2)
			echo "<font color=green>Data Successfully Update..</font>";
				
			if(isset($_GET['status'])&&$_GET['status']==3)
			echo "<font color=red>Wrong click...</font>";   
		?>
	</form>
	

        <div class="box">
            <div class="box-header">
              <h3 class="box-title">Category List</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Id</th> 
				  <th>Category Name</th> 
				  <th>Status</th> 
				  <th>Edit</th> 
				  <th>Delete</th> 
                </tr>
                </thead>
                <tbody>
                  <?php 
					$qry=mysqli_query($conn,"SELECT * FROM `category`")or die(mysqli_error($conn));
					$count=1;
					while($row=mysqli_fetch_array($qry))
					{?>
                    <tr>
						<td><?php echo $count++;?></td>
						<td><?php echo $row['ctname'];?></td>
						<td><?php echo $row['ctstatus'];?></td>
						<td><?php echo "<a href='category.php?temp_id=".$row['ctid']."'><i class='fa fa-edit fa-fw'></i></a>"; ?> </td>
						<td><?php echo "<a href='delete_code.php?dct_id=".$row['ctid']."' onClick=\"javascript:return confirm('are you sure you want to delete this?');\"><i class='fa fa-times fa-fw'></i></a>"; ?></td>
					</tr>              
             <?php  } ?>
                </tbody>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->


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