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


if(isset($_REQUEST['art'])){
	
	$art = mysqli_escape_string($conn, $_REQUEST['art']);

	$sql = "SELECT * FROM post WHERE id='$art'";

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

	$info = mysqli_fetch_array($result);
		$id=$info['id'];
		$image_name=$info['image_name'];
		$title=$info['title'];
		$category=$info['category'];
		
}

if(isset($_REQUEST['check'])) { 
			
			
			$art = mysqli_escape_string($conn, $_REQUEST['art']);
			$topic = mysqli_escape_string($conn, $_REQUEST['topic']);
			include("upload_pix.php");
				
					$sql="INSERT INTO post_more_picture (art_id , filename, detail) VALUES ('$art', '$fn', '$topic')"; 		
					mysqli_query($conn, $sql) or die(mysqli_error($conn));	
					$msg="<font color=\"blue\"><b>POSTING WAS SUCCESSFUL</b></font>";					
					
					
					
				
}

if((isset($_REQUEST['action']))&&($_REQUEST['action']=="del")){

	$id = mysqli_escape_string($conn, $_REQUEST['id']);
	$query  = "DELETE FROM post_more_picture WHERE id = '$id'";
	mysqli_query($conn, $query) or die(mysqli_error($conn));
	$msg="<font color=\"delete\"><b>RECORD DELETED</b></font>";
	

}
?>


      <!--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>Post More</b>
						  </header>
                          <div class="panel-body">
                          
						<?php
						if(isset($msg)){
							print $msg;
						}
					
						?>                         
                          
                          
                        <div class="form">
                                  <form class="form-validate form-horizontal" method="POST" action="more.php" enctype="multipart/form-data">
                                  
								 
                                  <div class="form-group ">
                                          <label for="cname" class="control-label col-lg-2">Picture</label>
                                          <div class="col-lg-5">
                                             
                                              <input class="form-control" name="userfile" type="file" id="userfile" />
                                          Format: PNG, BMP, GIV, JPG or JPEG </div>
                                    </div>
                                 
                                      
                                      
                                      <div class="form-group ">
                                          <label for="body" class="control-label col-lg-2">Caption <span class="required">*</span></label>
                                          <div class="col-lg-5">
                                              <textarea class="form-control "  name="topic" rows="10"></textarea>
                                          </div>
                                      </div>
                                           
									 
									  
                                      
                                      
                                      <div class="form-group">
                                          <div class="col-lg-offset-2 col-lg-10">
                                              <button class="btn btn-primary" type="submit">Save</button>
                                             
											  
											  <?php
											
												  print '
													<input type="hidden" name="action" value="do_upload" />
													<input name="check" type="hidden" id="check" value="yes" />
												  ';
												   print "<input name=\"art\" type=\"hidden\" value=\"$_REQUEST[art]\" />";
											
											  ?>
                                          </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
$query  = "SELECT * FROM post_more_picture WHERE art_id = '$art' ORDER BY id DESC";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));

if (mysqli_num_rows($result) == 0) {
 print "SORRY: no data...";
 exit;
}

print "
<table class=\"table table-striped table-advance table-hover\">
";
// print the random numbers
while($info = mysqli_fetch_array($result))
{
 		 
	$id=$info['id'];
	$filename=$info['filename'];
	$detail=$info['detail'];
	
	if($filename != ""){
		$img="<img src=\"piks/$filename\" width='300'>";
	}else{
		$img="";
	}
		
	print " 
	<tr>
	<td>$id</td>
	<td>$filename</td>
	<td>$detail</td>
	<td>$img</td>
	<td><a href=\"more.php?id=$id&action=del&art=$art\">Delete</a></td>	
	</tr>
	
	";
	}
	
	//close up ther table

	print "</table><p>";


?>
                          </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>
