<?php
include("header.php");
include("left-nev.php");
$pagetitle="Gallery";
$table="tbl_gallery";
$conn=db();
?>
<!-- Customizer JavaScript File (remove if not needed) -->
<script type="text/javascript" src="jsfiles/pagetransfer.js"></script>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>
		<?php echo $pagetitle;?> Management
		<small>Add <?php echo $pagetitle;?></small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="dashboard.php"><i class="fa fa-dashboard"></i> Home</a></li>
			<li><a href="dashboard.php">Dashboard</a></li>
			<li><a href="add-gallery.php"><?php echo $pagetitle;?> Management</a></li>
			<li class="active">Add <?php echo $pagetitle;?></li>
		</ol>
	</section>
	<script>
	function updatebannerposition(id,position)
	{
	window.location="update_gallery_position.php?id="+id+"&position="+position;
	}
	</script>
	<!-- Main content -->
	<section class="content">
		<!-- Main row -->
		<div class="row">
			<!-- Left col -->
			
			<?php
			if($_GET['action']=="Delete")
			{
			$selsql=$user->FetchGalleryEdit($_REQUEST['bid']);
			$res=mysqli_fetch_array($selsql);
			$filename= $res['gallery_image'];
			unlink('../upload/banner/'.DIRECTORY_SEPARATOR.$filename); //delete it
			mysqli_query($conn,"delete from ".$table." where gallery_id='".$_REQUEST['bid']."'");
				$_SESSION['banner-position-msg']="Deleted Successfully";
			}
			if($_GET['action']=="Edit")
			{
			?>
			<section class="col-lg-7 connectedSortable">
				<!-- TO DO List -->
				
				<div class="box box-info">
					<?php
					if($_SESSION["update-banner-msg"]!=""){
					?>
					<div class="form-group has-success">
						<label class="control-label" for="inputSuccess"><i class="fa fa-check"></i> <?php echo $_SESSION["update-banner-msg"];?></label>
					</div>
					<?php
					unset($_SESSION["update-banner-msg"]);
					}
					$selsql=$user->FetchGalleryEdit($_REQUEST['bid']);
					$resbanner=mysqli_fetch_object($selsql);
					?>
					<div class="box-body">
						<form method="post" action="process-update-gallery.php?id=<?php echo $_REQUEST['bid'];?>" enctype="multipart/form-data">
							Title <span style="color:red;">*</span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_title" value="<?php echo $resbanner->gallery_title;?>" placeholder="Title" required>
							</div>
							<!--Banner Position <span style="color:red;"></span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_position" value="<?php// echo $resbanner->gallery_position;?>" placeholder="Banner Position">
							</div>
							Link <span style="color:red;"></span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_link" value="<?php echo $resbanner->gallery_link;?>" placeholder="Link">
							</div>-->
							Alt <span style="color:red;"></span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_alt" value="<?php echo $resbanner->gallery_alt;?>" placeholder="Alt">
							</div>
							
							Status <span style="color:red;"></span>
							<div class="radio">
								<label>
									<span><input type="radio" name="pg_status" value="Active" <?php if($resbanner->pg_status=="Active") {;?> checked="checked"<?php }?>/></span>
									<span>Active</span>  <span style="margin-left:30px;">
									<input type="radio" name="pg_status"  value="Inactive" <?php if($resbanner->pg_status=="Inactive") {;?> checked="checked"<?php }?> /></span><span>Inactive</span>
								</label>
							</div>
							
							<div class="form-group">
								<label for="exampleInputFile">Image <span style="color:red;">*</span></label>
								<input type="file" name="image" id="exampleInputFile">
								<img src="../upload/banner/<?php echo $resbanner->gallery_image;?>" title="<?php echo $resbanner->gallery_alt;?>" style="height:100px; width:40%;margin-top:15px;margin-bottom:15px;">
								<!--<p class="help-block">Plz upload image of 450*198</p>-->
							</div>
							
							<!--<div class="form-group">
								<label for="exampleInputFile">Logo Image <span style="color:red;">*</span></label>
								<input type="file" name="logo_image" id="exampleInputFile">
								<img src="../upload/banner/<?php echo $resbanner->logo_image;?>" title="<?php echo $resbanner->gallery_alt;?>" style="margin-bottom:15px;">
								<p class="help-block">Plz upload Logo of 163*90</p>
							</div>-->
						</div>
						<div class="box-footer">
							<button type="submit" name="Update" class="btn btn-primary">Update</button>
							&nbsp;&nbsp;&nbsp;&nbsp;
							<button type="reset" name="Reset" class="btn btn-primary">Reset</button>
						</div>
					</form>
				</div>
				<!-- /.box -->
			</section>
			
			<?php
			}
			else
			{
			?>
			<section class="col-lg-7 connectedSortable">
				<!-- TO DO List -->
				
				<div class="box box-info">
					<?php
					if($_SESSION["add-banner-msg"]!=""){
					?>
					<div class="form-group has-success">
						<label class="control-label" for="inputSuccess"><i class="fa fa-check"></i> <?php echo $_SESSION["add-banner-msg"];?></label>
					</div>
					<?php
					unset($_SESSION["add-banner-msg"]);
					}
					?>
					<div class="box-body">
						<form method="post" action="process-add-gallery.php" enctype="multipart/form-data">
							Title <span style="color:red;">*</span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_title" placeholder="Title" required>
							</div>
							<!-- Position <span style="color:red;"></span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_position" placeholder="Banner Position">
							</div>
							Link <span style="color:red;"></span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_link" placeholder="Link">
							</div>-->
							Alt <span style="color:red;"></span>
							<div class="form-group">
								<input type="text" class="form-control" name="gallery_alt" placeholder="Alt">
							</div>
							
							Status <span style="color:red;"></span>
							<div class="radio">
								<label>
									<span><input type="radio" name="pg_status" value="Active" checked="checked"/></span>
									<span>Active</span>  <span style="margin-left:30px;">
									<input type="radio" name="pg_status"  value="Inactive"  /></span><span>Inactive</span>
								</label>
							</div>
							
							<div class="form-group">
								<label for="exampleInputFile">Image <span style="color:red;">*</span></label>
								<input type="file" name="image" id="exampleInputFile">
								<!--<p class="help-block">Plz upload image of 450*198</p>-->
							</div>
							
							<!--<div class="form-group">
								<label for="exampleInputFile">Logo Image <span style="color:red;">*</span></label>
								<input type="file" name="logo_image" id="exampleInputFile">
								<p class="help-block">Plz upload Logo of 163*90</p>
							</div>-->
						</div>
						<div class="box-footer">
							<button type="submit" name="Submit" class="btn btn-primary">Submit</button>
							&nbsp;&nbsp;&nbsp;&nbsp;
							<button type="reset" name="Reset" class="btn btn-primary">Reset</button>
						</div>
					</form>
				</div>
				<!-- /.box -->
			</section>
			<?php } ?>
			<!-- /.Left col -->
			<!-- right col (We are only adding the ID to make the widgets sortable)-->
			<section class="col-lg-5 connectedSortable">
				<!-- Map box -->
				<div class="box box-info">
					<div class="box-body">
						<?php
						if($_SESSION["banner-position-msg"]!=""){
						?>
						<div class="form-group has-success">
							<label class="control-label" for="inputSuccess"><i class="fa fa-check"></i> <?php echo $_SESSION["banner-position-msg"];?></label>
						</div>
						<?php
						unset($_SESSION["banner-position-msg"]);
						}
						$selsql=$user->FetchGallery();
						?>
						<table>
							<?php
							while($resbanner=mysqli_fetch_object($selsql)){
							?>
							<tr><td>
								<select class="form-control" style="width:100px;" onchange="updatebannerposition(<?php echo $resbanner->gallery_id;?>,this.value)">
									<option value="">Position</option>
									<?php for($i=1;$i<=20;$i++)
									{?>
									<option <?php echo ($resbanner->gallery_position == $i) ? 'selected': ''; ?>><?php echo $i;?></option>
									<?php } ?>
								</select>
								
								<a href="?action=Edit&bid=<?php echo $resbanner->gallery_id;?>">
									<button type="submit" style="width:30px; height:30px;margin-top:10px;" title="Edit"><i class="fa fa-refresh" aria-hidden="true"></i></button>
								</a>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<a href="javascript:void(0);" title="Delete" onclick="checkdelete('?action=Delete&bid=<?php echo $resbanner->gallery_id;?>')">
									<button type="submit" style="width:30px; height:30px;margin-top:10px;" title="Delete"><i class="fa fa-trash" aria-hidden="true"></i></button>
								</a>
								
								</td><td style="width:40px;">&nbsp;</td><td><img src="../upload/banner/<?php echo $resbanner->gallery_image;?>" title="<?php echo $resbanner->gallery_title;?>" style="height:100px; width:100%;margin-bottom:15px;"></td></tr>
								<?php } ?>
							</table>
						</div>
						<!-- /.box -->
					</section>
					<!-- right col -->
				</div>
				<!-- /.row (main row) -->
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->
		<?php include("footer.php");?>
		<!-- Control Sidebar -->
		<aside class="control-sidebar control-sidebar-dark">
			<!-- Create the tabs -->
			<ul class="nav nav-tabs nav-justified control-sidebar-tabs">
				<li><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
				<li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
			</ul>
			<!-- Tab panes -->
			<div class="tab-content">
				<!-- Home tab content -->
				<div class="tab-pane" id="control-sidebar-home-tab">
					<h3 class="control-sidebar-heading">Recent Activity</h3>
					<ul class="control-sidebar-menu">
						<li>
							<a href="javascript:void(0)">
								<i class="menu-icon fa fa-birthday-cake bg-red"></i>
								<div class="menu-info">
									<h4 class="control-sidebar-subheading">Langdon's Birthday</h4>
									<p>Will be 23 on April 24th</p>
								</div>
							</a>
						</li>
						<li>
							<a href="javascript:void(0)">
								<i class="menu-icon fa fa-user bg-yellow"></i>
								<div class="menu-info">
									<h4 class="control-sidebar-subheading">Frodo Updated His Profile</h4>
									<p>New phone +1(800)555-1234</p>
								</div>
							</a>
						</li>
						<li>
							<a href="javascript:void(0)">
								<i class="menu-icon fa fa-envelope-o bg-light-blue"></i>
								<div class="menu-info">
									<h4 class="control-sidebar-subheading">Nora Joined Mailing List</h4>
									<p>nora@example.com</p>
								</div>
							</a>
						</li>
						<li>
							<a href="javascript:void(0)">
								<i class="menu-icon fa fa-file-code-o bg-green"></i>
								<div class="menu-info">
									<h4 class="control-sidebar-subheading">Cron Job 254 Executed</h4>
									<p>Execution time 5 seconds</p>
								</div>
							</a>
						</li>
					</ul>
					<!-- /.control-sidebar-menu -->
					<h3 class="control-sidebar-heading">Tasks Progress</h3>
					<ul class="control-sidebar-menu">
						<li>
							<a href="javascript:void(0)">
								<h4 class="control-sidebar-subheading">
								Custom Template Design
								<span class="label label-danger pull-right">70%</span>
								</h4>
								<div class="progress progress-xxs">
									<div class="progress-bar progress-bar-danger" style="width: 70%"></div>
								</div>
							</a>
						</li>
						<li>
							<a href="javascript:void(0)">
								<h4 class="control-sidebar-subheading">
								Update Resume
								<span class="label label-success pull-right">95%</span>
								</h4>
								<div class="progress progress-xxs">
									<div class="progress-bar progress-bar-success" style="width: 95%"></div>
								</div>
							</a>
						</li>
						<li>
							<a href="javascript:void(0)">
								<h4 class="control-sidebar-subheading">
								Laravel Integration
								<span class="label label-warning pull-right">50%</span>
								</h4>
								<div class="progress progress-xxs">
									<div class="progress-bar progress-bar-warning" style="width: 50%"></div>
								</div>
							</a>
						</li>
						<li>
							<a href="javascript:void(0)">
								<h4 class="control-sidebar-subheading">
								Back End Framework
								<span class="label label-primary pull-right">68%</span>
								</h4>
								<div class="progress progress-xxs">
									<div class="progress-bar progress-bar-primary" style="width: 68%"></div>
								</div>
							</a>
						</li>
					</ul>
					<!-- /.control-sidebar-menu -->
				</div>
				<!-- /.tab-pane -->
				<!-- Stats tab content -->
				<div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
				<!-- /.tab-pane -->
				<!-- Settings tab content -->
				<div class="tab-pane" id="control-sidebar-settings-tab">
					<form method="post">
						<h3 class="control-sidebar-heading">General Settings</h3>
						<div class="form-group">
							<label class="control-sidebar-subheading">
								Report panel usage
								<input type="checkbox" class="pull-right" checked>
							</label>
							<p>
								Some information about this general settings option
							</p>
						</div>
						<!-- /.form-group -->
						<div class="form-group">
							<label class="control-sidebar-subheading">
								Allow mail redirect
								<input type="checkbox" class="pull-right" checked>
							</label>
							<p>
								Other sets of options are available
							</p>
						</div>
						<!-- /.form-group -->
						<div class="form-group">
							<label class="control-sidebar-subheading">
								Expose author name in posts
								<input type="checkbox" class="pull-right" checked>
							</label>
							<p>
								Allow the user to show his name in blog posts
							</p>
						</div>
						<!-- /.form-group -->
						<h3 class="control-sidebar-heading">Chat Settings</h3>
						<div class="form-group">
							<label class="control-sidebar-subheading">
								Show me as online
								<input type="checkbox" class="pull-right" checked>
							</label>
						</div>
						<!-- /.form-group -->
						<div class="form-group">
							<label class="control-sidebar-subheading">
								Turn off notifications
								<input type="checkbox" class="pull-right">
							</label>
						</div>
						<!-- /.form-group -->
						<div class="form-group">
							<label class="control-sidebar-subheading">
								Delete chat history
								<a href="javascript:void(0)" class="text-red pull-right"><i class="fa fa-trash-o"></i></a>
							</label>
						</div>
						<!-- /.form-group -->
					</form>
				</div>
				<!-- /.tab-pane -->
			</div>
		</aside>
		<!-- /.control-sidebar -->
		<!-- Add the sidebar's background. This div must be placed
		immediately after the control sidebar -->
		<div class="control-sidebar-bg"></div>
	</div>
	<!-- ./wrapper -->
</body>
</html>