<?php include('site-header.php'); ?>
  <!-- end of LOGO CONTAINER -->
  <!-- - - - - - - - - - - - - -->
  <!-- start of SIDEBAR        -->
  <!-- - - - - - - - - - - - - -->
<?php include('left-nevigation.php'); ?>
  <!-- - - - - - - - - - - - - -->
  <!-- end of SIDEBAR          -->
  <!-- - - - - - - - - - - - - -->
<script src="ckeditor/ckeditor.js"></script>
  <main id="playground">
    <!-- - - - - - - - - - - - - -->
    <!-- start of TOP NAVIGATION -->
    <!-- - - - - - - - - - - - - -->
<?php include('site-top-header.php'); ?>
    <!-- - - - - - - - - - - - - -->
    <!-- end of TOP NAVIGATION   -->
    <!-- - - - - - - - - - - - - -->
    <!-- PAGE TITLE -->
<?php
    extract($_POST);
    $tmp = $_FILES['att']['tmp_name'];
    $fn = $_FILES['att']['name'];
    $ext = explode(".",$fn);
    $extt = end($ext);
    $fnn = rand().".$extt";


$testi_id=$_REQUEST['testi_id'];


if(isset($_REQUEST['send']))
{     

    if($_FILES['att']['name']!="")
     {
       $sql_insert ="INSERT INTO `tbl_news`(`name`, `A_name`, `time`, `image`,`desc`) VALUES ('$name','$A_name','$time','$fnn','$desc')";
                if(mysqli_query($link,$sql_insert))
                 {
                   move_uploaded_file($tmp, "../gallery-image/$fnn");
                   $img = "<p style='color:green;'>Add news successfully!!!!!</p>";
                 } 
      }else
      {
        $sql_insert ="INSERT INTO `tbl_news`(`name`, `A_name`, `time`, `desc`) VALUES ('$name','$A_name','$time','$desc')";
                if(mysqli_query($link,$sql_insert))
                 {
                   $img = "<p style='color:green;'>Add news successfully!!!!!</p>";
                 }
      }
}


if(isset($_POST['Updt'])!="")
{
    if($_FILES['att']['name']!="")
     {
      $sql_insert ="UPDATE `tbl_news` SET 
                                `name`='$name',
                                `A_name`='$A_name',
                                `time`='$time',
                                `image`='$fnn',
                                `desc`='$desc' 
                                WHERE `id`='$new_id'";
                if(mysqli_query($link,$sql_insert))
                 {
                   move_uploaded_file($tmp, "../gallery-image/$fnn");
                   $img = "<p style='color:green;'>Update news successfully!!!!!</p>";
                 } 
      }
      else
      {
         $sql_insert ="UPDATE `tbl_news` SET 
                                `name`='$name',
                                `A_name`='$A_name',
                                `time`='$time',
                                `desc`='$desc' 
                                WHERE `id`='$new_id'";
                if(mysqli_query($link,$sql_insert))
                 {
                   $img = "<p style='color:green;'>Update news successfully!!!!!</p>";
                 }
      }

      
}
?>

<?php
if(isset($_GET['Updt_id'])!="")
{
$sql="select * from tbl_news where id='$_GET[Updt_id]'";
$data=mysqli_query($link,$sql);
$result=mysqli_fetch_array($data);
}
?>  



    <section id="page-title" class="row">
      <div class="col-md-8">
        <h1>Activities</h1>
        <p class="lead">Add your Activities below</strong>.</p>
        <?=$img;?>
      </div>
      <div class="col-md-4">
        <ol class="breadcrumb pull-right no-margin-bottom">
        
          <li><a href="dashboard.php">Activities</a></li>
          <li class="active">Add Activities</li>
        </ol>
      </div>
    </section>
    <!-- / PAGE TITLE -->
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12"><a href="update-news.php" class="btn btn-primary">Back</a></div>
      	<form method="post" enctype="multipart/form-data">
          <div class="col-md-6">
            <div class="form-group">
              <label for="">Name</label>
              <input type="text" class="form-control" name="name" value="<?php echo $result['name'];?>" placeholder="Enter Your customer Name">
              <label for="">Author</label>
              <input type="text" class="form-control" name="A_name" value="<?php echo $result['A_name'];?>" placeholder="Enter Your customer Name">
              <label for="">Time</label>
              <input type="text" class="form-control" name="time" value="<?php echo $result['time'];?>" placeholder="Enter Your customer Name">
               <label>Image for Product Page (Size :290 X 315 pixels)</label>
                <img src="../gallery-image/<?=$result['image'];?>" alt="" style="width:100px;height:100px;">
                <input type="file" name="att" value="">
                <input type="hidden" name="new_id" value="<?=$result['id'];?>">
            </div>
        </div>
      <div class="row">
        <div class="col-md-6">
        <h3>Description</h3>
          <section class="panel tasks-widget">
            <textarea id="ckeditor1" name="desc"><?php echo $result['desc']; ?></textarea>
          </section>
        </div>
      </div>
      <?php if(isset($_REQUEST['Updt_id']))
      { 
        ?>
      <div class="text-center">
       <button class="btn btn-primary" name="Updt">Update</button></ </div>
      <?php 
      }
      else
			  { 
          ?>
      <div class="text-center"> <button class="btn btn-primary" name="send">Submit</button></ </div>
       <?php } ?>
      </form>
    </div>
    </div>
  
    <script>
      CKEDITOR.replace(ckeditor1)  
    </script>
    
    <!-- / container-fluid -->
 <?php include('site-footer.php'); ?>