<?php
error_reporting(0);
session_start();
include("../db_connect.php");
$resources = mysqli_query($db,"select * from resources");
if (isset($_POST['upload_file'])) {
    if ($_POST['action'] == "upload") {
      //header("location:vivek.php");
  /*    $uFile = $_FILES['file1']['name'];
      $tmp_dir = $_FILES['file1']['tmp_name'];
      $fileSize = $_FILES['file1']['size'];
      $fileType = $_FILES['file1']['type'];
      if (empty($uFile)) {
        $errMSG = "Please add file.";
      } else {
        $upload_dir = '../uploads/images/resources/media/'; // upload directory

        $fileExt = strtolower(pathinfo($uFile, PATHINFO_EXTENSION)); // get file extension

        $ufile = $fname . "." . $fileExt;

        $target_file = $upload_dir . $ufile;
       

            if ($fileSize < 10485760) {

              if (move_uploaded_file($tmp_dir, $upload_dir . $ufile)) {

                $uFile_cover = $_FILES['cover']['name'];
                $tmp_dir_cover = $_FILES['cover']['tmp_name'];
                $fileSize_cover = $_FILES['cover']['size'];
                $fileType_cover = $_FILES['cover']['type'];
                
                $location_cover = '../uploads/images/resources/';
                $fileExt_cover = strtolower(pathinfo($uFile_cover, PATHINFO_EXTENSION));
                 $ufile_cover = $fname . "." . $fileExt_cover;
                move_uploaded_file($tmp_dir_cover, $location_cover . $ufile_cover);
               
                // /$insertimage = ;
                 
               
                //echo mysqli_error($db);
                
              }
          } else{
          	
          }


      
      //
    
}*/

$fname = mysqli_real_escape_string($db, $_POST['filename']);
$link = mysqli_real_escape_string($db, $_POST['link']);

//echo 'hello'.$link;
 mysqli_query($db,"insert into resources(name,file) values ('$fname','$link')");
header("location:resources.php");
}

}

?>
<!DOCTYPE html>
<head>
<title>Resources</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Colored Responsive web template, Bootstrap Web Templates, Flat Web Templates, Android Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- bootstrap-css -->
<link rel="stylesheet" href="css/bootstrap.css">
<!-- //bootstrap-css -->
<!-- Custom CSS -->
<link href="css/style.css" rel='stylesheet' type='text/css' />
<!-- font CSS -->
<link href='//fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<!-- font-awesome icons -->
<link rel="stylesheet" href="css/font.css" type="text/css"/>
<link href="css/font-awesome.css" rel="stylesheet"> 
<!-- //font-awesome icons -->
<script src="js/jquery2.0.3.min.js"></script>
<script src="js/modernizr.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/screenfull.js"></script>
		<script>
		$(function () {
			$('#supported').text('Supported/allowed: ' + !!screenfull.enabled);

			if (!screenfull.enabled) {
				return false;
			}

			

			$('#toggle').click(function () {
				screenfull.toggle($('#container')[0]);
			});	
		});
		</script>
		
</head>
<body class="dashboard-page">

	<?php include ("header.php");?>
	<section class="wrapper scrollable">
		<nav class="user-menu">
			<a href="javascript:;" class="main-menu-access">
			<i class="icon-proton-logo"></i>
			<i class="icon-reorder"></i>
			</a>
		</nav>
	<?php include("topMenu.php");?>
			<div class="agile-grids">
			
				<div class="col-md-12s chart-left">
					<!-- updating-data -->
					<div class="agile-Updating-grids">
						
							<div class="w3l-table-info">

					 <h3>Other Resources</h3> <br> <a href="#" class="btn btn-hover btn-dark btn-block" style="width: 29%;" data-toggle="modal" data-target="#contactsModal">Add Resource
					 	</a>
					    <table id="table"> 
						<thead>
						  <tr>
							<th>Date</th>
							<th>Title</th>
							<th>Link</th>
							
							<th>Action</th>
							
							
						  </tr>
						</thead>
						<tbody>
							<?php
                                            
                            while($a = mysqli_fetch_array($resources))
                            { ?>
						  <tr>
							<td><?php echo $a['date'];?></td>
							<td><a href="<?php echo $a['file'];?>" target="_blank"><?php echo $a['name'];?></a></td>
							<td class="MyClass"><a href="<?php echo $a['file'];?>" target="_blank"><?php echo $a['file'];?></a></td>
						
							<td><a href="deleteResource.php?id=<?php echo $a['id'];?>">Delete</a></td>
						
							
						  </tr>
						 <?php } ?>
						</tbody>
					  </table>
					</div>
				  <code class="js">
					
				  </code>
						

					</div>
					<!-- //updating-data -->
				</div>
				<div class="clearfix"> </div>
			</div>
		
		<!-- footer -->
		<!-- <div class="footer">
			<p>© 2020 Colored . All Rights Reserved . Design by <a href="http://w3layouts.com/"></a></p>
		</div> -->
		<!-- //footer -->
	</section>
	<script src="js/bootstrap.js"></script>
	
	<!-- gallery -->
	<link rel="stylesheet" href="css/lsb.css">
	<script src="js/lsb.js"></script>
	<!-- //gallery -->
	<script src="js/proton.js"></script>
	<div class="modal fade" id="contactsModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add Resource</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form method="POST" action="" class="valida" autocomplete="off"  enctype="multipart/form-data">

										

										<label for="field-1">Name: (required)</label>
										<div class="form-group">
											<input type="text" name="filename" id="field-1" required class="form-control">
										</div>

										

											

												<label for="field-1-2">Link: (required)</label>
												<div class="form-group">
													<input type="text" name="link" id="field-1-4-1" required class="form-control" >
												</div>

											

										

									
                                        <input type="hidden" name="action" value="upload">
										<hr>
                     
										<p>
											<button type="submit" name="upload_file" class="btn btn-primary">Save</button>
											<input type="reset" name="res-1" id="res-1" value="Reset" class="btn btn-danger">
											
										</p>
									</form>
      </div>
      
    </div>
  </div>
</div>
</body>
</html>
