<?php 
include('header.php'); 


if(isset($_REQUEST['check'])) { 
			
			
			
			$title = mysqli_escape_string($conn, $_REQUEST['title']);
			$body = mysqli_escape_string($conn, $_REQUEST['body']);
			$type = 'members';
			
			
			
				
					$sql="INSERT INTO series (series_name, series_detail, status) 
					VALUES 
					('$title', '$body', '$type')"; 		
					mysqli_query($conn, $sql) or die(mysqli_error($conn));	
					$msg="<font color=\"blue\"><b>Entry created</b></font>";
					
				
}

if((isset($_REQUEST['action']))&&($_REQUEST['action']=="del")){
	
	$del_id = mysqli_escape_string($conn, $_REQUEST['id']);	
	
	$query  = "DELETE FROM series WHERE id = '$del_id'";
	mysqli_query($conn, $query) or die(mysqli_error($conn));
	$msg="<font color=\"delete\"><b>Record deleted</b></font>";

	$msg="<font color=\"delete\"><b>Entry deleted</b></font>";
	
	
}


if(isset($_REQUEST['edit_id'])){
	
			$edit_id = mysqli_escape_string($conn, $_REQUEST['edit_id']);
			
			$artist = mysqli_escape_string($conn, $_REQUEST['artist']);
			$title = mysqli_escape_string($conn, $_REQUEST['title']);
			$body = mysqli_escape_string($conn, $_REQUEST['body']);
			$type = 'members';
			
			
				$sql1 = "UPDATE series SET  			 	
						series_name = '$title',
						status = '$type',
						series_detail = '$body'
					WHERE id = '$edit_id'";
			mysqli_query($conn, $sql1) or die(mysqli_error($conn));	
					
					
					//Update 
			$msg="<font color=\"green\"><b>Enry updated</b></font>";
			
			
}

if(isset($_REQUEST['editing'])){
	
	$select_id = mysqli_escape_string($conn, $_REQUEST['id']);

	$sql = "SELECT * FROM series WHERE id='$select_id'";

	$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));

	$info = mysqli_fetch_array($result);
		$id=$info['id'];
		$series_name=$info['series_name'];		
		$series_detail=strip_tags($info['series_detail']);
		$artist_id=$info['artist_id'];
		$cat_type=$info['status'];
}
?>


      <!--main content start-->
      <section id="main-content">
        <section class="wrapper">
		 
			  
              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                              <b>Category</b>
						  </header>
                          <div class="panel-body">
                          
						<?php
						if(isset($msg)){
							print $msg;
						}
						
						?>                         
                          
                          
                        <div class="form">
                                  <form class="form-validate form-horizontal" method="POST" action="">
                                  
                                  
                                  		
                                                                                                       
                                      
                                      
                                                                 
									  <div class="form-group ">
                                          <label for="cname" class="control-label col-lg-2">Category Title <span class="required">*</span></label>
                                          <div class="col-lg-5">
                                              <input class="form-control" name="title" minlength="1" type="text" <?php if(isset($_REQUEST['editing'])){ print "value=\"$series_name\""; } ?> required />
                                          </div>
                                      </div>
                                                                                                           
                                      <div class="form-group ">
                                          <label for="body" class="control-label col-lg-2">Detail</label>
                                          <div class="col-lg-5">
                                              <textarea class="form-control "  name="body" rows="10"><?php if(isset($_REQUEST['editing'])){ print $series_detail; } ?> </textarea>
                                          </div>
                                      </div>
                                      
                                      
                                      
                                      
                                      <div class="form-group">
                                          <div class="col-lg-offset-2 col-lg-10">
                                              
                                             
											  
											  <?php
											  	if(isset($_REQUEST['artist_id'])){
													$artist_id= mysqli_escape_string($conn, $_REQUEST['artist_id']);  
													print "<input name=\"artist_id\" type=\"hidden\" value=\"$artist_id\" />";
												}

											  if(isset($_REQUEST['editing'])){
												  $select_id = mysqli_escape_string($conn, $_REQUEST['id']);
												  print "<input name=\"edit_id\" type=\"hidden\" value=\"$select_id\" />";
												  print '<button class="btn btn-warning" type="submit">Update</button>';
											  }else{
												  print '
												  <button class="btn btn-primary" type="submit">Save</button>
													<input name="check" type="hidden" id="check" value="yes" />
												  ';
											  }
											  ?>
                                          </div>
                                      </div>
                                      
                                     
                                  </form>
                              </div>

                          </div>
                      </section>
                  </div>
              </div>
			  
			  
	

              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                         <header class="panel-heading">
                                                         
                            Record
                             </header>
                          <div class="panel-body">
<?php
if(isset($_REQUEST['artist_id'])){
	$artist_id= mysqli_escape_string($conn, $_REQUEST['artist_id']);    
    $query  = "SELECT * FROM series WHERE status <> 'D' AND artist_id = '$artist_id' ORDER BY id DESC";
}else{
	$query  = "SELECT * FROM series WHERE status <> 'D' ORDER BY id DESC";
}											  

$result = mysqli_query($conn,$query) or die(mysqli_error($conn));


print "
<table class=\"table table-striped table-advance table-hover\">
<tr>
	<th><b>Id</b></th>
	<th><b>Category</b></th>
	<th><b>Detail</b></th>
	<th><b>Type</b></th>
	<th></th>
</tr>
";
// print the random numbers
while($info = mysqli_fetch_array($result))
{
 		 
	$id=$info['id'];
	
	$title=$info['series_name'];
	$body=$info['series_detail'];
	$status=$info['status'];
		
		
		 
	print " 
	<tr>
		<td>$id</td>
		<td>$title</td>
		<td>$body</td>
		<td>$status</td>
		<td>
		";
			
			print "<a href=\"category.php?id=$id&editing=1\">Edit</a> <!-- | <a href=\"category.php?id=$id&action=del\">Delete</a>-->";
		
		print "
		</td>
	</tr>
	";
	}

	print "</table>";

	

?>
                          </div>
                      </section>
                  </div>
              </div>	
			  
			  
              <!-- page end-->
          </section>
      </section>
      <!--main content end-->
  </section>
  <!-- container section end -->

    <!-- javascripts -->
    <script src="../js/jquery.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <!-- nice scroll -->
    <script src="../js/jquery.scrollTo.min.js"></script>
    <script src="../js/jquery.nicescroll.js" type="text/javascript"></script>
    <!-- jquery validate js -->
    <script type="text/javascript" src="../js/jquery.validate.min.js"></script>

    <!-- custom form validation script for this page-->
    <script src="../js/form-validation-script.js"></script>
    <!--custome script for all page-->
    <script src="../js/scripts.js"></script>    


  </body>
</html>
