<?php

class Location_Model extends MY_Model {

    function __construct() {
        parent::__construct();
    }

    function checkcountry($column, $value, $update = 'no') {
        if ($update == 'yes') {
            $old = $this->input->post('old');
            if (trim(strtolower($old)) === trim(strtolower($value))) {
                return false;
            } else {
                return $this->exists('lcountry', $column, $value);
            }
        } else {
            return $this->exists('lcountry', $column, $value);
        }
    }

    public function save_country($data, $id = NULL) {
        $this->_table_name = 'lcountry';
        $this->_primary_key = 'id';
        if ($id !== NULL && $id > 0) {
            $data['updated_by'] = 1;
        } else {
            $data['created_by'] = 1;
        }
        return parent::save($data, $id);
    }

    public function save_region($data, $id = NULL) {
        $this->_table_name = 'lregion';
        $this->_primary_key = 'id';
        if ($id !== NULL && $id > 0) {
            $data['updated_by'] = 1;
        } else {
            $data['created_by'] = 1;
        }
        return parent::save($data, $id);
    }

    public function save_city($data, $id = NULL) {
        $this->_table_name = 'lcity';
        $this->_primary_key = 'id';
        if ($id !== NULL && $id > 0) {
            $data['updated_by'] = 1;
        } else {
            $data['created_by'] = 1;
        }
        return parent::save($data, $id);
    }

    public function save_area($data, $id = NULL) {
        $this->_table_name = 'larea';
        $this->_primary_key = 'id';
        if ($id !== NULL && $id > 0) {
            $data['updated_by'] = 1;
        } else {
            $data['created_by'] = 1;
        }
        return parent::save($data, $id);
    }
    public function save_postcode($data, $id = NULL) {
        $this->_table_name = 'lpostcode';
        $this->_primary_key = 'id';
        if ($id !== NULL && $id > 0) {
            $data['updated_by'] = 1;
        } else {
            $data['created_by'] = 1;
        }
        return parent::save($data, $id);
    }
    public function save_postcodeDooraddress($data, $id = NULL) {
        $this->_table_name = 'ldooraddress';
        $this->_primary_key = 'id';
        if ($id !== NULL && $id > 0) {
            $data['updated_by'] = 1;
        } else {
            $data['created_by'] = 1;
        }
        return parent::save($data, $id);
    }

}
