<?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>Create New Community </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> 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" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Community Image</label>
<input type="file" accept="image/*" class="form-control" name="com_image" >
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Community Main Image</label>
<input type="file" accept="image/*" class="form-control" name="com_main_image" >
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>Community Slider Images</label>
<input type="file" accept="image/*" multiple class="form-control" name="com_slider_images[]" >
</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"></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>
<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 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 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 Community</button>
<button type="reset" class="btn btn-danger" id="cancel" >Cancel</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">
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']))
{
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='';
}
}
//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["com_image"]["name"];
if(isset($image))
{
$uploadedfile = $_FILES['com_image']['tmp_name'];
if ($image)
{
$filename = stripslashes($_FILES['com_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['com_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['com_image']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['com_image']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth=390;
$newheight=322;
$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);
$com_image = $rand_number.$_FILES['com_image']['name'];
$filename = "../com_images/".$com_image;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
}
}
//echo $com_image;
// end plant_image
//Plant Main Image
$errors=0;
$image =$_FILES["com_main_image"]["name"];
if(isset($image))
{
$uploadedfile = $_FILES['com_main_image']['tmp_name'];
if ($image)
{
$filename = stripslashes($_FILES['com_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['com_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['com_main_image']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['com_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);
$com_main_image = $rand_number.$_FILES['com_main_image']['name'];
$filename = "../com_main_images/".$com_main_image;
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
}
}
}
//echo $com_main_image;
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("INSERT INTO tbl_community SET com_name=:com_name, com_main_image=:com_main_image, com_image=:com_image, com_details=:com_details,
related_com=:related_com, com_status=:com_status, added_date=:added_date ");
$add_new_community->bindParam(":com_name", $com_name);
$add_new_community->bindParam(":com_main_image", $com_main_image);
$add_new_community->bindParam(":com_image", $com_image);
$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);
if($add_new_community->execute())
{
echo "<script> alert('Cummunity created successfully');</script>";
//slide show images
$plant_id = $con->lastInsertId();
if(isset($_FILES['com_slider_images'])){
foreach ($_FILES["com_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["com_slider_images"]["tmp_name"][$key];
$name = $_FILES["com_slider_images"]["name"][$key];
$image = imagecreatefromstring(file_get_contents(($tmp_name)));
$filename1 = '../com_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, '../com_original_image/'.$rand.$name);
$add_new_slider_images = $con->prepare("INSERT INTO tbl_com_slider_images SET com_id=:com_id, image_name=:image_name");
$add_new_slider_images->bindParam(":com_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>";
}
}
?>
|