<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* NETBEANS - Code Completion Keys
* @property CI_Form_validation $form_validation
* @property CI_Input $input
* @property CI_Session $session
* @property CI_DB_active_record $db 
*/ 
class users_setting_model extends Model
{
    var $table = "d_users_setting"; // table name
    var $tableNamePrefix = "d_"; // table name
    var $prefix = "us_";
    function __construct()
    {
       parent::__construct();
    }

    function update_setting()
    {
        $this->db->set("us_view_location",$this->input->post("view_location"));
        $this->db->set("us_view_trips_to_fiends", $this->input->post("view_trips_to_friends"));
        $this->db->set("us_view_trips_public", $this->input->post("view_trips_to_visitors"));
        $this->db->where("us_email",$this->session->userdata("email"));
        $this->db->update("d_users_setting");
        //echo $this->db->last_query();
        return true;
    }
    
    function update_location_setting()
    {
        $this->db->set("us_country ",$this->input->post("country"));
        $this->db->set("us_lang ", $this->input->post("language"));
        $this->db->set("us_city", $this->input->post("CityID"));
        $this->db->where("us_email",$this->session->userdata("email"));
        $this->db->update("d_users_setting");
        return true;
    }

    function get_user_setting_data()
    {
        $result = $this->db->query("select * from $this->table where ".$this->prefix."email = '".$this->session->userdata("email")."'");
        return $result->row();
    }
    /**
     * @param Integer $UserID
     */
    function get_information($UserID)
    {
       $this->db->where("us_user_id",$UserID);
       return $this->db->get($this->table)->row();
    }
    /**
     *
     * @param Integer $UserID
     * @return Boolean
     * 
     */
    function delete($UserID)
    {
        $this->db->where($this->prefix."user_id", $UserID);
        $this->db->delete($this->table);
        return true;
    }

    function haveProfilePhoto()
    {
        $exist = $this->db->query("SELECT us_pic,us_user_id from $this->table  where us_user_id = '".$this->session->userdata("userid")."'");
        $exist = $exist->row();
        if(isset($exist->us_pic) and $exist->us_pic != "")
        {
           return true;
        }else{
           return false;
        }
    }

    function exist_profile_photo($UserID)
    {
        $exist = $this->db->query("SELECT us_pic,us_user_id from $this->table  where us_user_id = '".$UserID."'");
        $exist = $exist->row();
        
        if(is_object($exist) && $exist->us_pic)
        {
           return true;
        }else{
           return false;
        }
    }

    function getMemberPhoto()
    {
        $row = $this->db->query("SELECT us_pic,us_user_id from $this->table where us_user_id = '".$this->session->userdata("userid")."'");
        $row = $row->row();
        return $row->us_pic;
    }

    function get_member_photo($UserID)
    {
        $row = $this->db->query("SELECT us_pic,us_user_id from $this->table where us_user_id = '".$UserID."'");
        $row = $row->row();
        return $row->us_pic;
    }

    function changeMemberPhoto($image)
    {
       $this->db->set("us_pic",$image);
       $this->db->where("us_user_id",$this->session->userdata("userid"));
       $this->db->update("d_users_setting");
    }

    function deleteMemberPhoto()
    {
       $this->db->set("us_pic",null);
       $this->db->where("us_user_id",$this->session->userdata("userid"));
       $this->db->update("d_users_setting");
    }

    function get_user_data_by_email($email)
    {
        $result = $this->db->query("select * from $this->table where us_email = '".$email."'");
        return $result->row();
    } 

    function get_user_setting_data_by_id($UserID)
    {
       $this->db->where("us_user_id", $UserID);        
       return $this->db->get($this->table)->row();
    }
}