<?php error_reporting(E_ALL);
ini_set('display_errors', 1); include 'header.php';?>
<style>
.bottom30
{
margin-bottom: 30px;
}
hr
{
margin-top: 10px;
}
.col-md-4 label
{
font-weight: normal;
}
</style>
<div class="col-md-10 content">
<div class="col-md-12" style=" z-index:99;">
<div class="alert" id="success_message"> <a href="#" class="close" data-dismiss="alert" aria-label="close" style="color:white;opacity: 1;">×</a> Record has been saved successfully </div>
</div>
<div class="row">
<div class="col-md-12 ">
<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" >
<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" required>
</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" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Plant Slogan</label>
<input type="text" class="form-control" name="pl_slogan" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Plant Category</label>
<select class="form-control" name="pl_category_id" required>
<?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 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-4">
<div class="form-group">
<label>Plant Image</label>
<input type="file" accept="image/*" class="form-control" name="plant_image" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Plant Main Image</label>
<input type="file" accept="image/*" class="form-control" name="pl_main_image" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Plant Slider Images</label>
<input type="file" accept="image/*" multiple class="form-control" name="pl_slider_images[]" required>
</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" value="1" name="maint_low"> Low</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" value="1" name="maint_medium"> Medium</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" 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" value="1" name="light_low_light"> indoors: low light</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" value="1" name="light_medium_light"> indoors: medium light</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" value="1" name="light_high_light"> indoors: high light</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" value="1" name="light_out_sun"> outside: sun</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" value="1" name="light_out_part_sun"> outside: part sun</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" 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" value="1" name="shade_low"> Low</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" value="1" name="shade_medium"> Medium</label>
</div>
<div class="col-md-4">
<label><input type="checkbox" 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"></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"></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"></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"></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"></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"></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" 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>
<select class="form-control" multiple name="pl_related_plants[]" required>
<?php
$select_related_plants= $con->prepare("SELECT id, pl_name FROM tbl_plants ORDER BY id DESC");
$select_related_plants->execute();
while($fetch_related_plants = $select_related_plants->fetch(PDO::FETCH_ASSOC))
{ ?>
<option 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>Plant Varities </label>
<select class="form-control" multiple name="pl_varities_plants[]" required>
<?php
$select_related_plants= $con->prepare("SELECT id, pl_name FROM tbl_plants ORDER BY id DESC");
$select_related_plants->execute();
while($fetch_related_plants = $select_related_plants->fetch(PDO::FETCH_ASSOC))
{ ?>
<option value="<?php echo $fetch_related_plants['id']; ?>"><?php echo $fetch_related_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" required>
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary" type="submit" name="create_new_plants">Create Plant</button>
<button type="reset" class="btn btn-danger" id="cancel" >Reset</button>
</div>
</div>
</form>
</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">
$('#create_product').validate();
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>
<?php
if(isset($_POST['create_new_plants']))
{
$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='';
}
}
$pl_related_plants = filters_fun($_POST['pl_related_plants']);
$pl_varities_plants = filters_fun($_POST['pl_varities_plants']);
//start plant_image
define ("MAX_SIZE","4000");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
$image =$_FILES["plant_image"]["name"];
if(isset($image))
{
$uploadedfile = $_FILES['plant_image']['tmp_name'];
if ($image)
{
$filename = stripslashes($_FILES['plant_image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$change='<div class="msgdiv">Unknown Image extension </div> ';
$errors=1;
}
else
{
$size=filesize($_FILES['plant_image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
$errors=1;
}
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['plant_image']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['plant_image']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth=280;
$newheight=307;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$four_digit = 6;
$rand_number = rand(pow(10, $four_digit-1), pow(10, $four_digit)-1);
$plant_image = $rand_number.$_FILES['plant_image']['name'];
$filename = "../plant_images/".$plant_image;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
}
}
//echo $plant_image;
// end plant_image
//Plant Main Image
$errors=0;
$image =$_FILES["pl_main_image"]["name"];
if(isset($image))
{
$uploadedfile = $_FILES['pl_main_image']['tmp_name'];
if ($image)
{
$filename = stripslashes($_FILES['pl_main_image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$change='<div class="msgdiv">Unknown Image extension </div> ';
$errors=1;
}
else
{
$size=filesize($_FILES['pl_main_image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
$errors=1;
}
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['pl_main_image']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['pl_main_image']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth=1140;
$newheight=443;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$four_digit = 6;
$rand_number = rand(pow(10, $four_digit-1), pow(10, $four_digit)-1);
$plant_main_image = $rand_number.$_FILES['pl_main_image']['name'];
$filename = "../plant_main_image/".$plant_main_image;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
}
}
//echo $plant_main_image;
$pl_name = $_POST['pl_name'];
$pl_slogan = $_POST['pl_slogan'];
$banner_image_name;
$plant_main_image;
$pl_category_id = $_POST['pl_category_id'];
//$pl_facebook = $_POST['pl_facebook'];
//$pl_twitter = $_POST['pl_twitter'];
//$pl_pinterest = $_POST['pl_pinterest'];
//$pl_gplus = $_POST['pl_gplus'];
$pl_features = htmlspecialchars($_POST['pl_features']);
$pl_growing_instr = htmlspecialchars($_POST['pl_growing_instr']);
$pl_status = $_POST['pl_status'];
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'];
$added_date = date('M d, Y');
$add_new_plant = $con->prepare("INSERT INTO tbl_plants SET pl_name=:pl_name, pl_family_name=:pl_family_name, pl_slogan=:pl_slogan, pl_category=:pl_category,pl_main_image=:pl_main_image,
plant_image=:plant_image,
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 ");
$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(":pl_main_image", $plant_main_image);
$add_new_plant->bindParam(":plant_image", $plant_image);
$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);
if($add_new_plant->execute())
{
echo "<script> alert('Plant has been added successfully');</script>";
//slide show images
$plant_id = $con->lastInsertId();
if(isset($_FILES['pl_slider_images'])){
foreach ($_FILES["pl_slider_images"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK) {
$four_digit = 6;
$rand = rand(pow(10, $four_digit-1), pow(10, $four_digit)-1);
$tmp_name = $_FILES["pl_slider_images"]["tmp_name"][$key];
$name = $_FILES["pl_slider_images"]["name"][$key];
$image = imagecreatefromstring(file_get_contents(($tmp_name)));
$filename1 = '../plant_resized_image/'.$rand.$name;
$thumb_width = 276;
$thumb_height = 232;
$width = imagesx($image);
$height = imagesy($image);
$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;
if ( $original_aspect >= $thumb_aspect )
{
$new_height = $thumb_height;
$new_width = $width / ($height / $thumb_height);
}
else
{
$new_width = $thumb_width;
$new_height = $height / ($width / $thumb_width);
}
$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width) / 2,
0 - ($new_height - $thumb_height) / 2,
0, 0,
$new_width, $new_height,
$width, $height);
imagejpeg($thumb, $filename1, 100);
$images_path =$rand.$name;
move_uploaded_file($tmp_name, '../plant_original_image/'.$rand.$name);
$add_new_slider_images = $con->prepare("INSERT INTO tbl_slider_images SET plant_id=:plant_id, image_name=:image_name");
$add_new_slider_images->bindParam(":plant_id", $plant_id);
$add_new_slider_images->bindParam(":image_name", $images_path);
$add_new_slider_images->execute();
}
}
}
//End slide show images
}
else
{
echo "<script> alert('Please try agin.');</script>";
}
}
?>
|