<?php include 'header.php';?>
<div class="col-md-10 content">
<div class="row">
<div class="col-md-12 ">
<!-- edit Plant -->
<?php
if(isset($_POST['edit_community']))
{
$com_id = $_POST['com_id'];
$select_community_edit = $con->prepare("SELECT * FROM tbl_community WHERE id=:com_id");
$select_community_edit->bindParam(':com_id', $com_id);
$select_community_edit->execute();
$fetch_edit_community = $select_community_edit->fetch(PDO::FETCH_ASSOC);
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3>Add New Plant </h3>
</div>
<div class="panel-body">
<div class="col-md-8">
<form id="create_product" method="POST" enctype="multipart/form-data" >
<input type="hidden" class="form-control" name="com_id" value="<?php echo $com_id ?>">
<div class="row">
<div class="col-md-12">
<h4 class="header_separator"><i class="fa fa-pagelines" aria-hidden="true"></i> Community Details</h4>
<hr>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Community Name</label>
<input type="text" class="form-control" name="com_name" value="<?php echo $fetch_edit_community['com_name']; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4 class="header_separator"><i class="fa fa-file-text" aria-hidden="true"></i> Community Description</h4>
<hr>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Community Description</label>
<textarea rows="4" style="width: 100%" name="com_details"><?php echo htmlspecialchars_decode($fetch_edit_community['com_details']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4 class="header_separator"><i class="fa fa-user" aria-hidden="true"></i> Related Community</h4>
<hr>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Related Community </label>
<?php
$array_community=array();
$pl_related_community= $fetch_edit_community['related_com'];
foreach(explode(',' , $pl_related_community) as $eachcommunity)
{
$array_community[] = $eachcommunity;
}
?>
<select class="form-control" multiple name="related_com[]">
<?php
$select_related_community= $con->prepare("SELECT * FROM tbl_community ORDER BY id DESC");
$select_related_community->execute();
while($fetch_related_community = $select_related_community->fetch(PDO::FETCH_ASSOC))
{ ?>
<option <?php if(in_array($fetch_related_community['id'], $array_community)){ echo "selected";} ?> value="<?php echo $fetch_related_community['id']; ?>"><?php echo $fetch_related_community['com_name']; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4 class="header_separator"><i class="fa fa-user" aria-hidden="true"></i> Community Status</h4>
<hr>
</div>
<div class="col-md-12">
<div class="form-group">
<select class="form-control" name="com_status">
<option <?php if($fetch_edit_community['com_status']==1){ echo 'selected'; } ?> value="1">Enable</option>
<option <?php if($fetch_edit_community['com_status']==0){ echo 'selected'; } ?> value="0">Disable</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary" type="submit" name="udpate_edited_community">Update Community</button>
<button type="reset" class="btn btn-danger" id="cancel" >Cancel</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- end edit Plant -->
<?php
}
if(isset($_POST['udpate_edited_community']))
{
$com_id = $_POST['com_id'];
function filters_fun($pl_filter)
{
if(isset($pl_filter) && !empty($pl_filter))
{
$plant_filter='';
foreach ($pl_filter as $each_type)
{
$plant_filter = $plant_filter.','.$each_type;
}
$plant_filter = substr($plant_filter, 1);
return $plant_filter;
}
else
{
return $plant_filter='';
}
}
if(isset($_POST['related_com']))
{
$related_com = filters_fun($_POST['related_com']);
}
else
{
$related_com = '';
}
$com_name = $_POST['com_name'];
$com_details = htmlspecialchars($_POST['com_details']);
$com_status = $_POST['com_status'];
$added_date = date('M d, Y');
$add_new_community = $con->prepare("UPDATE tbl_community SET com_name=:com_name, com_details=:com_details,
related_com=:related_com, com_status=:com_status, added_date=:added_date WHERE id=:id");
$add_new_community->bindParam(":com_name", $com_name);
$add_new_community->bindParam(":com_details", $com_details);
$add_new_community->bindParam(":related_com", $related_com);
$add_new_community->bindParam(":com_status", $com_status);
$add_new_community->bindParam(":added_date", $added_date);
$add_new_community->bindParam(":id", $com_id);
if($add_new_community->execute())
{
echo "<script> alert('Community has been updated successfully');</script>";
}
else
{
echo "<script> alert('Please try agin.');</script>";
}
}
if(isset($_POST['delete_community']))
{
$com_id = $_POST['com_id'];
$delete_plant = $con->prepare("DELETE FROM tbl_community WHERE id=:com_id ");
$delete_plant->bindParam(":com_id", $com_id);
if($delete_plant->execute())
{
echo "<script> alert('Community has been deleted successfully');</script>";
}
else
{
echo "<script> alert('Please try agin.');</script>";
}
}
?>
<div class="panel panel-primary">
<div class="panel-heading">
<h3>Plant List</h3>
</div>
<div class="panel-body">
<div class="col-md-12 ">
<div class="table-responsive">
<table id="example" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SL No</th>
<th>Community Name</th>
<th>Community Image</th>
<th>Created On</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sl=1;
$select_all_community = $con->prepare("SELECT * FROM tbl_community ORDER BY id DESC");
$select_all_community->execute();
while($fetch_all_community = $select_all_community->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $sl; ?></td>
<td><?php echo $fetch_all_community['com_name']; ?></td>
<td><img src="../com_images/<?php echo $fetch_all_community['com_image']; ?>" style="width:100px;height:100px; border: 1px solid #c1c1c1;"></td>
<td><?php echo $fetch_all_community['added_date']; ?></td>
<td><?php if($fetch_all_community['com_status']){ echo 'Enable'; } else { echo 'Disable'; } ?></td>
<td>
<form action="" method="post">
<input type="hidden" name="com_id" value="<?php echo $fetch_all_community['id']; ?>">
<button type="submit" name="edit_community" class="btn btn-info">Edit Community</button>
<a href="community_media_centre.php?com_id=<?php echo $fetch_all_community['id']; ?>" class="btn btn-info">Edit Media</a>
<button type="submit" name="delete_community" onclick="if(!confirm('Are you sure you want to delete this ?')) {return false;}" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
<?php
$sl++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer.php';?>
<script type="text/javascript" src="js/tinymce_js/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>
|