<?php
$path_to_root = "../..";

//include_once($path_to_root."/modules/external/includes/db/.php");

function add_property($status,$doorno, $property_name, $plotno, $latitude, $longitude, $location, $address, 
        $city, $landload, $agentid, $category, $type, $rent, $floor, $bedrooms, $bathrooms, 
        $balcony, $distance_from_main_road, $buy_price, $deposit, $initial_rent,$amenities,$furnishings,$size,$goodwill,$stock_value,$period_in_business,$profit ) {
    $sql = "INSERT INTO " . TB_PREF . "property (status,doorno,property_name,plotno,latitude,longitude,location,address,
                                    city,landload,agentid,category,type,rent,floor,bedrooms,bathrooms,
                                    balcony,distance_from_main_road,buy_price,deposit,initial_rent,amenities,furnishings,size,goodwill,stock_value,period_in_business,profit)
		VALUES (" . db_escape($status) . ", " .  db_escape($doorno) . ", " . db_escape($property_name) . ", " . db_escape($plotno) . ", " . db_escape($latitude) . ", " . db_escape($longitude) . ", " . db_escape($location) . ", " . db_escape($address) . ","
            . " " . db_escape($city) . ", " . db_escape($landload) . ", " . db_escape($agentid) . ", " . db_escape($category) . ", " . db_escape($type) . ", " . db_escape($rent) . ", " . db_escape($floor) . ", " . db_escape($bedrooms) . ", " . db_escape($bathrooms) . ","
            . " " . db_escape($balcony) . ", " . db_escape($distance_from_main_road) . ", " . db_escape($buy_price) . ", " . db_escape($deposit) . ", " . db_escape($initial_rent) . ", " . db_escape($amenities) . ", " .db_escape($furnishings) . ", " .db_escape($size) . ", " .db_escape($goodwill) . ", " .db_escape($stock_value) . ", " .db_escape($period_in_business) . ", " .db_escape($profit)
            . " )";

    return db_query($sql, "could not add property ");
}


//-----------------------------------------------------------------------------------------------

function update_property($id,$status, $doorno, $property_name, $plotno, $latitude, $longitude, $location, $address, 
        $city, $landload, $agentid, $category, $type, $rent, $floor, $bedrooms, $bathrooms, 
        $balcony, $distance_from_main_road, $buy_price, $deposit, $initial_rent,$amenities,$furnishings,$size,$goodwill,$stock_value,$period_in_business,$profit ) {
    $sql = "UPDATE " . TB_PREF . "property SET "
            . " doorno=" . db_escape($doorno) . ",
                property_name=" . db_escape($property_name) . ",
                plotno=" . db_escape($plotno) . ",
                latitude=" . db_escape($latitude) . ",
                longitude=" . db_escape($longitude) . ",
                location=" . db_escape($location) . ",
                address=" . db_escape($address) . ",
                city=" . db_escape($city) . ",
                landload=" . db_escape($landload) . ",
                agentid=" . db_escape($agentid) . ",
                category=" . db_escape($category) . ",
                type=" . db_escape($type) . ",
                rent=" . db_escape($rent) . ",
                floor=" . db_escape($floor) . ",
                bedrooms=" . db_escape($bedrooms) . ",
                bathrooms=" . db_escape($bathrooms) . ",
                balcony=" . db_escape($balcony) . ",
                distance_from_main_road=" . db_escape($distance_from_main_road) . ",
                buy_price=" . db_escape($buy_price) . ",
                deposit=" . db_escape($deposit) . ",
                initial_rent=" . db_escape($initial_rent) . ",
                status=" . db_escape($status) .". 
                amenities=" .db_escape($amenities) . ", 
                furnishings=" .db_escape($furnishings) . ", 
                size=" .db_escape($size) . ", 
                goodwill=" .db_escape($goodwill) . ", 
                stock_value=" .db_escape($stock_value) . ", 
                period_in_business=" .db_escape($period_in_business) . ", 
                profit=" .db_escape($profit);
    return db_query($sql, "could not update property for $id");
}


//-----------------------------------------------------------------------------------------------


function get_properties() {
    $sql = "SELECT * FROM " . TB_PREF . "property  ";

    return db_query($sql, "could not get properties");
}

//-----------------------------------------------------------------------------------------------

function get_property($id) {
    $sql = "SELECT * FROM " . TB_PREF . "property WHERE id=" . db_escape($id);

    $result = db_query($sql, "could not get property $id");

    return db_fetch($result);
}

//-----------------------------------------------------------------------------------------------

function add_property_image($property_id,$file,$image_for ) {
    $sql = "INSERT INTO " . TB_PREF . "property_images (property_id,file,image_for,status)
		VALUES (" . db_escape($property_id) . ", " .  db_escape($file) . ", " . db_escape($image_for). ",'1' )";

    return db_query($sql, "could not add property image ");
}

//-----------------------------------------------------------------------------------------------

function delete_property_image($property_id,$image_for) {
    $sql = "UPDATE  " . TB_PREF . "property_images set
		status='0' where property_id=" . db_escape($property_id) . " AND image_for=" . db_escape($image_for) . " ";

    return db_query($sql, "could not delete property image ");
}
//-----------------------------------------------------------------------------------------------


function get_property_images($property_id) {
    $sql = "SELECT * FROM " . TB_PREF . "property_images  where property_id=".  db_escape($property_id);

    return db_query($sql, "could not get properties");
}