query_first($sql);
$ptype = $row['prop_type'];
$stype = $row['search_type'];
$adv = $row['adv_id'];
$size = $row['sqft'];
$price_negotiable = $row['negotiable_price'];
$price = $row['price'];
$price_usd = $row['price_usd'];
$perches = $row['perches'];
$beds = $row['beds'];
$baths = $row['bathrooms'];
$number = $row['po_box'];
$street_name = $row['street_name'];
$city = $row['city'];
$postal_code = $row['postal_code'];
$image1 = $row['image1'];
$image2 = $row['image2'];
$image3 = $row['image3'];
$image4 = $row['image4'];
$image5 = $row['image5'];
$image6 = $row['image6'];
$image7 = $row['image7'];
$image8 = $row['image8'];
$image9 = $row['image9'];
$image10 = $row['image10'];
$banimage = $row['banimage'];
$long = $row['longitude'];
$lang = $row['latitude'];
$premium = $row['premium'];
$fplan = $row['fplan'];
$description = $row['description'];
$inner_description = $row['inner_description'];
$parking = $row['parking'];
$school1 = $row['school1'];
$school2 = $row['school2'];
$hospital1 = $row['hospital1'];
$hospital2 = $row['hospital2'];
$resturant1 = $row['resturant1'];
$resturant2 = $row['resturant2'];
$park1 = $row['park1'];
$park2 = $row['park2'];
$gros_supr1 = $row['gros_supr1'];
$gros_supr2 = $row['gros_supr2'];
$bank1 = $row['bank1'];
$bank2 = $row['bank2'];
$sql = "SELECT * FROM tbl_landlord_info WHERE prop_id ='" . $id . "'";
$landloard_info = $db->query_first($sql);
$landlord_name = $landloard_info['name'];
$landlord_contact_no1 = $landloard_info['contact_no1'];
$landlord_contact_no2 = $landloard_info['contact_no2'];
$landlord_contact_no3 = $landloard_info['contact_no3'];
$landlord_email = $landloard_info['email'];
$landlord_address = $landloard_info['address'];
$landlord_agent = $landloard_info['agent'];
$landlord_source = $landloard_info['source'];
//Meta Details
$property_meta_title = $row['meta_title'];
$property_meta_description = $row['meta_description'];
}
if (isset($_GET['id']) && $_GET['id'] != "" && is_numeric($_GET['id']) && isset($_GET['action']) && $_GET['action'] == "delete_image" && isset($_GET['image']) && $_GET['image'] != "" && isset($_GET['imageno'])) {
$id = $_GET['id'];
$data = array();
$data[$_GET['imageno']] = "";
$result = $db->query_update("tbl_properties", $data, "id=" . $id);
if (file_exists(DOC_ROOT . 'img/items/' . $_GET['image'])) {
$unlink = @unlink(DOC_ROOT . 'img/items/' . $_GET['image']);
}
//**************** generate log entry *******************
$logString = "delete buy image , buy id - " . $id . " / USER - " . $_SESSION['admin']['username'] . " ID - " . $_SESSION['admin']['id'];
$log = new Logging();
$log->lwrite($logString);
// **************************************************
if ($result) {
header("Location:add_buy.php?id=" . $id . "&msg=" . base64_encode(8) . "");
exit;
} else {
header("Location: add_buy.php?id=" . $id . "&msg=" . base64_encode(5) . "");
exit;
}
}
if ($_POST == true) {
$err = "";
$ptype = trim($_POST['ptype']);
$stype = trim($_POST['stype']);
$adv = trim($_POST['adv']);
$size = trim($_POST['size']);
$beds = trim($_POST['beds']);
$price = trim($_POST['price']);
$price_usd = trim($_POST['price_usd']);
$perches = trim($_POST['perches']);
$baths = trim($_POST['baths']);
$number = trim($_POST['number']);
$street_name = trim($_POST['street_name']);
$city = trim($_POST['city']);
$postal_code = trim($_POST['postal_code']);
$image1 = trim($_POST['image1']);
$image2 = trim($_POST['image2']);
$image3 = trim($_POST['image3']);
$image4 = trim($_POST['image4']);
$image5 = trim($_POST['image5']);
$image6 = trim($_POST['image6']);
$image7 = trim($_POST['image7']);
$image8 = trim($_POST['image8']);
$image9 = trim($_POST['image9']);
$image10 = trim($_POST['image10']);
$banimage = trim($_POST['banimage']);
$long = trim($_POST['long']);
$lang = trim($_POST['lang']);
$description = trim($_POST['description']);
$inner_description = $_POST['inner_description'];
$parking = trim($_POST['parking']);
$school1 = trim($_POST['school1']);
$school2 = trim($_POST['school2']);
$hospital1 = trim($_POST['hospital1']);
$hospital2 = trim($_POST['hospital2']);
$resturant1 = trim($_POST['resturant1']);
$resturant2 = trim($_POST['resturant2']);
$park1 = trim($_POST['park1']);
$park2 = trim($_POST['park2']);
$gros_supr1 = trim($_POST['gros_supr1']);
$gros_supr2 = trim($_POST['gros_supr2']);
$bank1 = trim($_POST['bank1']);
$bank2 = trim($_POST['bank2']);
//Landloard Information assignin
$landlord_name = trim($_POST['landlord_name']);
$landlord_contact_no1 = trim($_POST['landlord_contact_no1']);
$landlord_contact_no2 = trim($_POST['landlord_contact_no2']);
$landlord_contact_no3 = trim($_POST['landlord_contact_no3']);
$landlord_email = trim($_POST['landlord_email']);
$landlord_address = trim($_POST['landlord_address']);
$landlord_agent = trim($_POST['landlord_agent']);
$landlord_source = trim($_POST['landlord_source']);
//Meta Details
$property_meta_title = trim($_POST['property_meta_title']);
$property_meta_description = trim($_POST['property_meta_description']);
if (isset($_POST['premium'])) {
$premium = '1';
} else {
$premium = '0';
}
if (isset($_POST['price_negotiable'])) {
$price_negotiable = '1';
} else {
$price_negotiable = '0';
}
if (isset($id))
$adv_sql = "SELECT * FROM tbl_properties WHERE adv_id ='" . $adv . "' AND id != " . $id . "";
else
$adv_sql = "SELECT * FROM tbl_properties WHERE adv_id ='" . $adv . "'";
$adv_row = $db->query_first($adv_sql);
if (!empty($adv_row)) {
$err = $err . "
Please enter a unique advertisement ID";
}
if ($adv == "") {
$err = $err . "Please enter an advertisement ID";
}
if (isset($_POST['btnadd']) || isset($_POST['btnadd_fb']) || isset($_POST['btnedit_add'])) {
if ($ptype == "") {
$err = $err . "Please enter a property type";
}
if ($size == "") {
$err = $err . "Please enter size in sqft";
}
if ($banimage == "" && isset($_POST['btnadd'])) {
$err = $err . "Please Add Property Banner Image";
}
if ($price == "") {
$err = $err . "Please enter LKR Price";
} else {
if (!is_numeric($price)) {
$err = $err . "Please enter LKR price without (,) & only allowed numbers";
}
}
if ($price_usd == "") {
$err = $err . "Please enter USD Price";
} else {
if (!is_numeric($price_usd)) {
$err = $err . "Please enter USD price without (,) & only allowed numbers";
}
}
if ($city == "" || ($city == "" && $street_name == "" && $number == "")) {
$err = $err . "Please check the address";
}
if (isset($street_name)) {
if ((substr($street_name, -1) == ',') || (substr($street_name, -1) == '.')) {
$err = $err . "Please removed last (,) / (.) on street name";
}
}
if (isset($city)) {
if ((substr($city, -1) == ',') || (substr($city, -1) == '.')) {
$err = $err . "Please removed last (,) / (.) on City";
}
}
//Landloard Information & validation
if ($landlord_name == "") {
$err = $err . "Please enter Landloard Name";
}
if ($landlord_contact_no1 == "") {
$err = $err . "Please enter Landloard Contact Number 01";
}
if ($landlord_email == "") {
$err = $err . "Please enter Landloard Email";
}
if ($landlord_address == "") {
$err = $err . "Please enter Landloard Address";
}
if ($landlord_agent == "") {
$err = $err . "Please enter Agent Details";
}
}
if ($err == "") {
if($beds == ''){
$beds = 0;
}
if($baths == ''){
$baths = 0;
}
if($parking == ''){
$parking = 0;
}
$data_arr = array();
$data_arr['prop_type'] = $ptype;
$data_arr['search_type'] = $stype;
$data_arr['adv_id'] = $adv;
$data_arr['sqft'] = $size;
$data_arr['beds'] = $beds;
$data_arr['negotiable_price'] = $price_negotiable;
$data_arr['price'] = $price;
$data_arr['price_usd'] = $price_usd;
$data_arr['perches'] = $perches;
$data_arr['bathrooms'] = $baths;
$data_arr['po_box'] = $number;
$data_arr['street_name'] = $street_name;
$data_arr['city'] = $city;
$data_arr['postal_code'] = $postal_code;
$data_arr['longitude'] = $long;
$data_arr['latitude'] = $lang;
$data_arr['premium'] = $premium;
$data_arr['description'] = $description;
$data_arr['inner_description'] = $inner_description;
$data_arr['parking'] = $parking;
$data_arr['banimage'] = $banimage;
$data_arr['school1'] = $school1;
$data_arr['school2'] = $school2;
$data_arr['hospital1'] = $hospital1;
$data_arr['hospital2'] = $hospital2;
$data_arr['resturant1'] = $resturant1;
$data_arr['resturant2'] = $resturant2;
$data_arr['park1'] = $park1;
$data_arr['park2'] = $park2;
$data_arr['gros_supr1'] = $gros_supr1;
$data_arr['gros_supr2'] = $gros_supr2;
$data_arr['bank1'] = $bank1;
$data_arr['bank2'] = $bank2;
if ($_POST['view_mode_uploader'] == 'on') {
if ($_POST['uploader_0_status'] == 'done') {
$data_arr['image1'] = $_POST['uploader_0_name'];
}
if ($_POST['uploader_1_status'] == 'done') {
$data_arr['image2'] = $_POST['uploader_1_name'];
}
if ($_POST['uploader_2_status'] == 'done') {
$data_arr['image3'] = $_POST['uploader_2_name'];
}
if ($_POST['uploader_3_status'] == 'done') {
$data_arr['image4'] = $_POST['uploader_3_name'];
}
if ($_POST['uploader_4_status'] == 'done') {
$data_arr['image5'] = $_POST['uploader_4_name'];
}
if ($_POST['uploader_5_status'] == 'done') {
$data_arr['image6'] = $_POST['uploader_5_name'];
}
if ($_POST['uploader_6_status'] == 'done') {
$data_arr['image7'] = $_POST['uploader_6_name'];
}
if ($_POST['uploader_7_status'] == 'done') {
$data_arr['image8'] = $_POST['uploader_7_name'];
}
if ($_POST['uploader_8_status'] == 'done') {
$data_arr['image9'] = $_POST['uploader_8_name'];
}
if ($_POST['uploader_9_status'] == 'done') {
$data_arr['image10'] = $_POST['uploader_9_name'];
}
}
if (isset($_FILES) && $_FILES['fplan']['name'] != "") {
$upload_fplan = upload::upload_images(DOC_ROOT . 'img/items/', $_FILES['fplan']);
if ($upload_fplan) {
$data_arr['fplan'] = $upload_fplan;
}
}
//Landloard data array
$landloard_data = array();
$landloard_data['name'] = $landlord_name;
$landloard_data['contact_no1'] = $landlord_contact_no1;
$landloard_data['contact_no2'] = $landlord_contact_no2;
$landloard_data['contact_no3'] = $landlord_contact_no3;
$landloard_data['email'] = $landlord_email;
$landloard_data['address'] = $landlord_address;
$landloard_data['agent'] = $landlord_agent;
$landloard_data['source'] = $landlord_source;
//Meta Details
$data_arr['meta_title'] = $property_meta_title;
$data_arr['meta_description'] = $property_meta_description;
if (isset($_POST['btnadd']) == true || isset($_POST['btnsave']) == true || isset($_POST['btnadd_fb']) == true) {
if (isset($_POST['btnadd']) || isset($_POST['btnadd_fb'])) {
$data_arr['status'] = 1;
}
if (isset($_POST['btnsave'])) {
$data_arr['status'] = 0;
}
$data_arr['added_date'] = date('Y-m-d H:i:s');
$insert_id = $db->query_insert("tbl_properties", $data_arr);
if ($insert_id) {
$landloard_data['prop_id'] = $insert_id;
$insert_landloard_id = $db->query_insert("tbl_landlord_info", $landloard_data);
if (isset($_POST['btnadd_fb']) == true) {
$fb_property_id = $insert_id;
include_once './fb_auto_post.php';
}
//**************** generate log entry *******************
$logString = "Add buy property buy id - " . $insert_id . " / USER - " . $_SESSION['admin']['username'] . " ID - " . $_SESSION['admin']['id'];
$log = new Logging();
$log->lwrite($logString);
// **************************************************
if (isset($_POST['btnsave'])) {
header("Location:view_buy.php?msg=" . base64_encode(16) . "");
} else {
if ($postResult) {
header("Location:view_buy.php?msg=" . base64_encode(11) . "");
} elseif ($fb_upload_err_msg) {
header("Location:view_buy.php?msg=" . base64_encode(12) . "");
} else {
header("Location:view_buy.php?msg=" . base64_encode(7) . "");
}
}
exit;
} else {
$err = $err . "Not inserted";
}
}
if (isset($_POST['btnedit']) == true || isset($_POST['btnedit_fb']) == true || isset($_POST['btnedit_add']) == true) {
if (isset($_POST['btnedit_fb']) || isset($_POST['btnedit_add'])) {
$data_arr['status'] = 1;
}
$id = $_POST['id'];
$data_arr['updated_date'] = date('Y-m-d H:i:s');
$update = $db->query_update("tbl_properties", $data_arr, "id=" . $id);
$sql = "SELECT id FROM tbl_landlord_info WHERE prop_id ='" . $id . "'";
$landloard_old_id = $db->query_first($sql);
if ($landloard_old_id == '') {
$landloard_data['prop_id'] = $id;
$insert_landloard = $db->query_insert("tbl_landlord_info", $landloard_data);
} else {
$update_landloard = $db->query_update("tbl_landlord_info", $landloard_data, "prop_id=" . $id);
}
if ($update) {
if (isset($_POST['btnedit_fb']) == true) {
$fb_property_id = $id;
include_once './fb_auto_post.php';
}
//**************** generate log entry *******************
$logString = "Update buy property buy id - " . $id . " / USER - " . $_SESSION['admin']['username'] . " ID - " . $_SESSION['admin']['id'];
$log = new Logging();
$log->lwrite($logString);
// **************************************************
if ($postResult) {
header("Location:view_buy.php?id=$id&msg=" . base64_encode(14) . "");
} elseif ($fb_upload_err_msg) {
header("Location:view_buy.php?id=$id&msg=" . base64_encode(15) . "");
} else {
header("Location:add_buy.php?id=$id&msg=" . base64_encode(6) . "");
}
exit;
} else {
$err = $err . "Not Updated";
}
}
}
}
if (isset($_GET['id']) == true) {
$type = "Edit Sell Property";
} else {
$type = "Add Sell Property";
}
$breaddrum = " Home >> Sell >> $type";
$INCLUDE_FILE = "add_buy.tpl.php";
require_once('templates/template_main.php');
?>