<?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_plant']))
{
$plant_id = $_POST['plant_id'];
$select_plant_edit = $con->prepare("SELECT * FROM tbl_plants WHERE id=:plant_id");
$select_plant_edit->bindParam(':plant_id', $plant_id);
$select_plant_edit->execute();
$fetch_edit_plant = $select_plant_edit->fetch(PDO::FETCH_ASSOC);
?>
<div class="panel panel-primary" id="edit_plant_panel">
<div class="panel-heading">
<h3>Edit Plant : <?php echo $fetch_edit_plant['pl_name']; ?> </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="plant_id" value="<?php echo $plant_id ?>">
<div class="row">
<div class="col-md-12">
<h4 class="header_separator"><i class="fa fa-pagelines" aria-hidden="true"></i> Plant Details</h4>
<hr>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Plant Name</label>
<input type="text" class="form-control" name="pl_name" value="<?php echo $fetch_edit_plant['pl_name']; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Plant Family Name</label>
<input type="text" class="form-control" name="pl_family_name" value="<?php echo $fetch_edit_plant['pl_family_name']; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Plant Slogan</label>
<input type="text" class="form-control" name="pl_slogan" value="<?php echo $fetch_edit_plant['pl_slogan']; ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Plant Category</label>
<select class="form-control" name="pl_category">
<?php
$select_plant_categories = $con->prepare("SELECT * FROM tbl_plant_categories");
$select_plant_categories->execute();
while($fetch_categories = $select_plant_categories->fetch(PDO::FETCH_ASSOC))
{ ?>
<option <?php if($fetch_edit_plant['pl_category']==$fetch_categories['id']){ echo 'selected'; } ?> value="<?php echo $fetch_categories['id']; ?>"><?php echo $fetch_categories['cat_name']; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4 class="header_separator"><i class="fa fa-area-chart" aria-hidden="true"></i> Plant Features</h4>
<hr>
</div>
<div class="col-md-12">
<label>Plant Maintenance :</label>
<div class="form-group">
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['maint_low']==1){ echo 'checked'; } ?> value="1" name="maint_low"> Low</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['maint_medium']==1){ echo 'checked'; } ?> value="1" name="maint_medium"> Medium</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['maint_high']==1){ echo 'checked'; } ?> value="1" name="maint_high"> High</label>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-12">
<label>Plant Lighting :</label>
<div class="form-group">
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['light_low_light']==1){ echo 'checked'; } ?> value="1" name="light_low_light"> indoors: low light</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['light_medium_light']==1){ echo 'checked'; } ?> value="1" name="light_medium_light"> indoors: medium light</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['light_high_light']==1){ echo 'checked'; } ?> value="1" name="light_high_light"> indoors: high light</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['light_out_sun']==1){ echo 'checked'; } ?> value="1" name="light_out_sun"> outside: sun</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['light_out_part_sun']==1){ echo 'checked'; } ?> value="1" name="light_out_part_sun"> outside: part sun</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['light_out_shade']==1){ echo 'checked'; } ?> value="1" name="light_out_shade"> outside: shade</label>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-12">
<label>Plant Shade :</label>
<div class="form-group">
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['shade_low']==1){ echo 'checked'; } ?> value="1" name="shade_low"> Low</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['shade_medium']==1){ echo 'checked'; } ?> value="1" name="shade_medium"> Medium</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" <?php if($fetch_edit_plant['shade_high']==1){ echo 'checked'; } ?> value="1" name="shade_high"> High</label>
</div>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-12">
<label>Other </label>
<div class="form-group">
</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> Plant Description</h4>
<hr>
</div>
<div class="col-md-12">
<div class="form-group">
<label>Plant Features</label>
<textarea rows="4" style="width: 100%" name="pl_features"><?php echo htmlspecialchars_decode ($fetch_edit_plant['pl_features']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Growing Instruction</label>
<textarea rows="4" style="width: 100%" name="pl_growing_instr"><?php echo htmlspecialchars_decode ($fetch_edit_plant['pl_growing_instr']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Store Address 1</label>
<textarea rows="4" style="width: 100%" name="store_address1"><?php echo htmlspecialchars_decode($fetch_edit_plant['store_address1']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Store Address 2</label>
<textarea rows="4" style="width: 100%" name="store_address2"><?php echo htmlspecialchars_decode($fetch_edit_plant['store_address2']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Store Address 3</label>
<textarea rows="4" style="width: 100%" name="store_address3"><?php echo htmlspecialchars_decode($fetch_edit_plant['store_address3']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Store Address 4</label>
<textarea rows="4" style="width: 100%" name="store_address4"><?php echo htmlspecialchars_decode($fetch_edit_plant['store_address4']); ?></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Price</label>
<input type="text" class="form-control" name="plant_price" value="<?php echo $fetch_edit_plant['plant_price']; ?>" required>
</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 Plant</h4>
<hr>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Related Plants </label>
<?php
$array_plant=array();
$pl_related_plants = $fetch_edit_plant['pl_related_plants'];
foreach(explode(',' , $pl_related_plants) as $eachplant)
{
$array_plant[] = $eachplant;
}
?>
<select class="form-control" required multiple name="pl_related_plants[]">
<?php
$select_related_plants= $con->prepare("SELECT id, pl_name FROM tbl_plants WHERE id!=:plant_id ORDER BY id DESC");
$select_related_plants->bindParam(':plant_id', $plant_id);
$select_related_plants->execute();
while($fetch_related_plants = $select_related_plants->fetch(PDO::FETCH_ASSOC))
{ ?>
<option <?php if(in_array($fetch_related_plants['id'], $array_plant)){ echo "selected";} ?> value="<?php echo $fetch_related_plants['id']; ?>"><?php echo $fetch_related_plants['pl_name']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Related Plants </label>
<?php
$array_plant=array();
$pl_varities_plants= $fetch_edit_plant['pl_varities_plants'];
foreach(explode(',' , $pl_varities_plants) as $eachplant)
{
$array_plant[] = $eachplant;
}
?>
<select class="form-control" required multiple name="pl_varities_plants[]">
<?php
$select_varities_plants= $con->prepare("SELECT id, pl_name FROM tbl_plants WHERE id!=:plant_id ORDER BY id DESC");
$select_varities_plants->bindParam(':plant_id', $plant_id);
$select_varities_plants->execute();
while($fetch_varities_plants = $select_varities_plants->fetch(PDO::FETCH_ASSOC))
{ ?>
<option <?php if(in_array($fetch_varities_plants ['id'], $array_plant)){ echo "selected";} ?> value="<?php echo $fetch_varities_plants ['id']; ?>"><?php echo $fetch_varities_plants ['pl_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> Plant Status</h4>
<hr>
</div>
<div class="col-md-12">
<div class="form-group">
<select class="form-control" name="pl_status">
<option <?php if($fetch_edit_plant['pl_status']==1){ echo 'selected'; } ?> value="1">Enable</option>
<option <?php if($fetch_edit_plant['pl_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_plant">Update Plant</button>
<button type="button" class="btn btn-danger" id="cancel" >Cancel</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- end edit Plant -->
<?php
}
if(isset($_POST['udpate_edited_plant']))
{
$plant_id = $_POST['plant_id'];
$pl_family_name= $_POST['pl_family_name'];
$maint_low=$maint_medium=$maint_high= $light_low_light=$light_medium_light=$light_high_light=$light_out_sun=$shade_high=$light_out_part_sun=$light_out_shade=$shade_medium=$shade_low=0;
//Start Maintenance
if(isset($_POST['maint_low']))
{
$maint_low=1;
}
if(isset($_POST['maint_medium']))
{
$maint_medium=1;
}
if(isset($_POST['maint_high']))
{
$maint_high=1;
}
//End Maintenance
//Start Lighting
if(isset($_POST['light_low_light']))
{
$light_low_light=1;
}
if(isset($_POST['light_medium_light']))
{
$light_medium_light=1;
}
if(isset($_POST['light_high_light']))
{
$light_high_light=1;
}
if(isset($_POST['light_out_sun']))
{
$light_out_sun=1;
}
if(isset($_POST['light_out_part_sun']))
{
$light_out_part_sun=1;
}
if(isset($_POST['light_out_shade']))
{
$light_out_shade=1;
}
//End Lighting
//Start Shade
if(isset($_POST['shade_low']))
{
$shade_low=1;
}
if(isset($_POST['shade_medium']))
{
$shade_medium=1;
}
if(isset($_POST['shade_high']))
{
$shade_high=1;
}
//End Shade
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['pl_related_plants']))
{
$pl_related_plants = filters_fun($_POST['pl_related_plants']);
}
else
{
$pl_related_plants='';
}
if(isset($_POST['pl_varities_plants']))
{
$pl_varities_plants= filters_fun($_POST['pl_varities_plants']);
}
else
{
$pl_varities_plants='';
}
$pl_name = $_POST['pl_name'];
$pl_slogan = $_POST['pl_slogan'];
$pl_category_id = $_POST['pl_category'];
$pl_features = htmlspecialchars($_POST['pl_features']);
$pl_growing_instr = htmlspecialchars($_POST['pl_growing_instr']);
if(isset($_POST['store_address1']))
{
$store_address1 = htmlspecialchars($_POST['store_address1']);
}
if(isset($_POST['store_address2']))
{
$store_address2 = htmlspecialchars($_POST['store_address2']);
}
if(isset($_POST['store_address3']))
{
$store_address3 = htmlspecialchars($_POST['store_address3']);
}
if(isset($_POST['store_address4']))
{
$store_address4 = htmlspecialchars($_POST['store_address4']);
}
$plant_price = $_POST['plant_price'];
$pl_status = $_POST['pl_status'];
$added_date = date('M d, Y');
$add_new_plant = $con->prepare("UPDATE tbl_plants SET pl_name=:pl_name, pl_family_name=:pl_family_name, pl_slogan=:pl_slogan, pl_category=:pl_category, maint_low=:maint_low, maint_medium=:maint_medium,
maint_high=:maint_high, light_low_light=:light_low_light, light_medium_light=:light_medium_light,
light_high_light=:light_high_light, light_out_sun=:light_out_sun, light_out_part_sun=:light_out_part_sun, light_out_shade=:light_out_shade,
shade_low=:shade_low,
shade_medium=:shade_medium, shade_high=:shade_high, pl_features=:pl_features, pl_growing_instr=:pl_growing_instr,
store_address1=:store_address1, store_address2=:store_address2, store_address3=:store_address3, store_address4=:store_address4,
plant_price=:plant_price,
pl_related_plants=:pl_related_plants, pl_varities_plants=:pl_varities_plants, pl_status=:pl_status, added_date=:added_date WHERE id=:plant_id ");
$add_new_plant->bindParam(":pl_name", $pl_name);
$add_new_plant->bindParam(":pl_family_name", $pl_family_name);
$add_new_plant->bindParam(":pl_slogan", $pl_slogan);
$add_new_plant->bindParam(":pl_category", $pl_category_id);
$add_new_plant->bindParam(":maint_low", $maint_low);
$add_new_plant->bindParam(":maint_medium", $maint_medium);
$add_new_plant->bindParam(":maint_high", $maint_high);
$add_new_plant->bindParam(":light_low_light", $light_low_light);
$add_new_plant->bindParam(":light_medium_light", $light_medium_light);
$add_new_plant->bindParam(":light_high_light", $light_high_light);
$add_new_plant->bindParam(":light_out_sun", $light_out_sun);
$add_new_plant->bindParam(":light_out_part_sun", $light_out_part_sun);
$add_new_plant->bindParam(":light_out_shade", $light_out_shade);
$add_new_plant->bindParam(":shade_low", $shade_low);
$add_new_plant->bindParam(":shade_medium", $shade_medium);
$add_new_plant->bindParam(":shade_high", $shade_high);
$add_new_plant->bindParam(":pl_features", $pl_features);
$add_new_plant->bindParam(":pl_growing_instr", $pl_growing_instr);
$add_new_plant->bindParam(":store_address1", $store_address1);
$add_new_plant->bindParam(":store_address2", $store_address2);
$add_new_plant->bindParam(":store_address3", $store_address3);
$add_new_plant->bindParam(":store_address4", $store_address4);
$add_new_plant->bindParam(":plant_price", $plant_price);
$add_new_plant->bindParam(":pl_related_plants", $pl_related_plants);
$add_new_plant->bindParam(":pl_varities_plants", $pl_varities_plants);
$add_new_plant->bindParam(":pl_status", $pl_status);
$add_new_plant->bindParam(":added_date", $added_date);
$add_new_plant->bindParam(":plant_id", $plant_id);
if($add_new_plant->execute())
{
echo "<script> alert('Plant has been updated successfully');</script>";
}
else
{
echo "<script> alert('Please try agin.');</script>";
}
}
if(isset($_POST['delete_plant']))
{
$plant_id = $_POST['plant_id'];
$delete_plant = $con->prepare("DELETE FROM tbl_plants WHERE id=:pla_id ");
$delete_plant->bindParam(":pla_id", $plant_id);
if($delete_plant->execute())
{
echo "<script> alert('Plant 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>Plant Name</th>
<th>Category Name</th>
<th>Plant Image</th>
<th>Price</th>
<th>Created On</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sl=1;
$select_all_plants = $con->prepare("SELECT * FROM tbl_plants ORDER BY id DESC");
$select_all_plants->execute();
while($fetch_all_plants = $select_all_plants->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $sl; ?></td>
<td><?php echo $fetch_all_plants['pl_name']; ?></td>
<td>
<?php
$pl_category = $fetch_all_plants['pl_category'];
$select_category = $con->prepare("SELECT * FROM tbl_plant_categories WHERE id=:id");
$select_category->bindParam(':id', $pl_category);
$select_category->execute();
$fetch_category = $select_category->fetch(PDO::FETCH_ASSOC);
echo $fetch_category['cat_name'];
?></td>
<td><img src="../plant_images/<?php echo $fetch_all_plants['plant_image']; ?>" style="width:100px;height:100px; border: 1px solid #c1c1c1;"></td>
<td><?php echo $fetch_all_plants['plant_price']; ?></td>
<td><?php echo $fetch_all_plants['added_date']; ?></td>
<td><?php if($fetch_all_plants['pl_status']){ echo 'Enable'; } else { echo 'Disable'; } ?></td>
<td>
<form action="" method="post">
<input type="hidden" name="plant_id" value="<?php echo $fetch_all_plants['id']; ?>">
<button type="submit" name="edit_plant" class="btn btn-info">Edit Plant</button>
<a href="edit_media_centre.php?plant_id=<?php echo $fetch_all_plants['id']; ?>" class="btn btn-info">Edit Media</a>
<button type="submit" name="delete_plant" 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"
});
$("#cancel").click(function(){
$("#edit_plant_panel").hide();
});
</script>
|