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


if(isset($_REQUEST['check'])) { 
			
				
			include("upload_pix.php");
			$title = mysqli_escape_string($conn, $_REQUEST['title']);
			$sql1 = "INSERT INTO post_more_picture (detail, filename) VALUE ('$title','$fn')";
			mysqli_query($conn, $sql1) or die(mysqli_error($conn));	
			
			
					
			$msg="<font color=\"green\"><b>Record added</b></font>			
			";
		
		
					
				
}

if((isset($_REQUEST['action']))&&($_REQUEST['action']=="del")){
	$id = mysqli_escape_string($conn, $_REQUEST['id']);
	
				// DELETE PHYSICAL FILE 
				$query  = "SELECT filename FROM post_more_picture WHERE id ='$id'";
				$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
				$info = mysqli_fetch_array($result);
				$f_name= $info['filename'];
				
				if(file_exists("piks/".$f_name)) { 
					unlink("piks/".$f_name);
				}else{
					
				}
				
				
	$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>";
	
	
}

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

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

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

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



if(isset($_REQUEST['edit_id'])){
	
			$edit_id = mysqli_escape_string($conn, $_REQUEST['edit_id']);
			
			$title = mysqli_escape_string($conn, $_REQUEST['title']);
			
				$sql1 = "UPDATE  post_more_picture SET  			 	
						detail = '$title'
					WHERE id = '$edit_id'";
			mysqli_query($conn, $sql1) or die(mysqli_error($conn));	
					
					
					//Update 
			$msg="<font color=\"green\"><b>EDITING WAS SUCCESSFUL</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">
                             Document
                             
						  </header>
                          <div class="panel-body">
                          
						<?php
						if(isset($msg)){
							print $msg;
						}
						?>                         
                          
                          
                        <div class="form">
                                  <form class="form-validate form-horizontal" method="POST" action="" enctype="multipart/form-data">
                                  
								  <?php
								  if( (!isset($_REQUEST['editing']))&&(!isset($_REQUEST['edit_id'])) ){
									//if((!$_REQUEST['action'])&&(!$_REQUEST['action']=="do_upload")){
								  ?> 
                                    <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>
                                  <?php
									}
								  ?>
                                    
                                     
									  
									  <div class="form-group ">
                                          <label for="cname" class="control-label col-lg-2">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=\"$title\""; } ?> required />
                                          </div>
                                      </div>
									  
									 
                                      <div class="form-group">
                                          <div class="col-lg-offset-2 col-lg-10">
                                          
											  
											 
											  
											   <?php
											
											  
											  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 type="hidden" name="action" value="do_upload" />
													<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

$query  = "SELECT * FROM post_more_picture WHERE art_id = ''  AND art_id='' 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\">
<tr>	
	<th>Title</th>
	<th><b>File name</b></th>	
	<th></th>
</tr>
";
// print the random numbers
while($info = mysqli_fetch_array($result))
{
 		 
	$id=$info['id'];
	$detail=$info['detail'];
	$filename=$info['filename'];
			
		
		 
	print " 
	<tr>
	<td>$detail</td>	
	<td>$filename</td>
	<td><a href=\"?id=$id&action=del\">Delete</a> | <a href=\"?id=$id&editing=1\">Edit</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>

