<?php
    
    include("../include/header.php");
    if ( isset( $_POST['newsSubmitBtn'] ) ) {
        $akdate=date("d-M-Y");
   		$images_name ="";
   		$uploads_dir="newsgallery";
   		 $txtname=$_POST['txtname'];
    foreach ($_FILES["files"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["files"]["tmp_name"][$key];
            $name = $_FILES["files"]["name"][$key];
            move_uploaded_file($tmp_name, "$uploads_dir/$name");
           
            $images_name =$images_name.",".$name;

    }

    }
    $slug = preg_replace('/[^a-z0-9]+/i', '-', trim(strtolower($_POST["txtname"])));
   $slug =  trim($slug,"-");
    $images_name= ltrim($images_name,',');
    $query="insert into news(title,url,images,upload_on)values('$txtname','$slug','$images_name','$akdate')";
  $query_execute=mysqli_query($conn,$query);
  if($query_execute){

echo "<script>alert('news created successfully')
window.location.href='';</script>";

  	echo "data inserted succeffuly";
  }else{

  echo "<script>alert('news created successfully');
window.location.href='';</script>";
  }
    }
    
?>

<style>
	#testimonials ul li:nth-child(3) {
		background-color: #eb6a4e;
	}

	#testimonials ul li:nth-child(3) a {
		color: #fff;
	}

	#testimonials ul li:nth-child(3) a:hover {
		background-color: #eb6a4e;
	}

	#testimonials .course-detailsa img{
		width: 100% !important;
		max-height: 250px !important;
	}
</style>
<script>
	window.onload = function() {
		document.getElementById('testimonials').classList.add("active");
		document.getElementById('testimonials1').classList.add("in");
	};

</script>

<div class="small-header">
	<div class="hpanel">
		<div class="panel-body">
			<div id="hbreadcrumb" class="pull-right">
				<ol class="hbreadcrumb breadcrumb">
					<li><a href="<?php echo $admin_baseurl . 'dashboard.php';?>">Dashboard</a></li>
					<li class="active">
						<span>news</span>
					</li>
				</ol>
			</div>
			<h2 class="font-light m-b-xs">
				news Details
			</h2>

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


<div class="content">
	<div class="hpanel">
		<div class="hpanel">
			<div class="panel-heading hbuilt">
				<div class="panel-tools">
					<a class="showhide"><i class="fa fa-chevron-up"></i></a>
					<a class="fullscreen"><i class="fa fa-expand"></i></a>
				</div>
				Add News Details
			</div>
			<div class="panel-body">
				<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
					<div class="form-group">
						<div class="col-md-12">
							<label class="control-label">News Title</label>
							<input type="text" name="txtname" class="form-control" placeholder="News Title" required>
						</div>
						

					
						<div class="col-md-12">
							<label class="control-label">News Image</label>
							<input type="file" id="file" class="form-control" name="files[]" multiple="multiple" accept="image/*" required>
						</div>
					


						<div class="col-md-12">
							<div class="form-group" style="padding:0 20px;">
								<br>
								<div class="text-right">
									<button type="reset" class="btn btn-default">Cancel</button>
									<button type="submit" name="newsSubmitBtn" class="btn btn-primary">Submit</button>
								</div>
							</div>
						</div>
					</div>


				</form>
			</div>

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




<br>
<!--show news-->
        <div class="content">



	<div class="hpanel">
		<div class="panel-heading hbuilt">
			<div class="panel-tools">
				<a class="showhide"><i class="fa fa-chevron-up"></i></a>
				<a class="fullscreen"><i class="fa fa-expand"></i></a>
			</div>
			View All Tutorials Library Course
		</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table id="userPermission_dataTable11" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th>#</th>
							<th>Title</th>
							<th>Posted Date</th>
							<th>Gallery</th>
								<th>Action</th>
						</tr>
					</thead>
					<tbody>

						<?php
						$admin_base_url="https://afsarebrahim.com/admin/news/newsgallery/";
        $srno = 0;
        $sqlAssign1 = "SELECT * FROM `news` ORDER BY `news`.`id` DESC";			
//                   echo $sqlAssign1;     
        $resultAssign1 = mysqli_query($conn, $sqlAssign1);											
        if (mysqli_num_rows($resultAssign1) > 0) {
            while($rows = mysqli_fetch_assoc($resultAssign1)) { 
                
                $id = $rows['id'];
                $title = $rows['title'];
                $date_add = $rows['images'];
                $upload_on=$rows['upload_on'];
			
                
                
      
                
?>
						<tr>
							<th scope="row"><?php echo $srno += 1;?></th>

							<td><?php echo $title;?></td>
							<td><?php echo $upload_on;?></td>

							<td>
							
							<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal<?php echo $id;?>">Show Gallery</button>
							</td>
							
                            <td><a href="delete-new.php?id=<?php echo $id; ?>" class="btn btn-danger">Delete</a>&nbsp;&nbsp;<a href="edit-new.php?id=<?php echo $id; ?>" class="btn btn-danger">Edit</a></td>

						
						</tr>
												<div id="myModal<?php echo $id; ?>" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"><?php echo $title; ?></h4>
      </div>
      <div class="modal-body">
          <div class="row">
          <?php
          
         $imgdata= explode(",",$date_add);
         foreach($imgdata as $simg){
             
            ?>
            <div class="col-sm-4"><img class="img-responsive" src="<?php echo $admin_base_url.$simg; ?>" alt="Chania"></div>
            <?php
             
         }
          
          ?>
       </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
						<?php
						
						
						}}?>

					</tbody>
				</table>
			</div>
		</div>

	</div>
</div>
<!--show news end -->
<?php 
    include('../include/footer.php');
?>
 
       
