<?PHP

class users_SQL extends SqlRequest{

	var $table = 'users';

	function users($add_sql = '', $execute = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select("select * from users ".
			$add_sql,
			$execute
		);
	}

	function users_and_roles($add_sql = '', $execute = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select(
			"SELECT p1.*, p2.`name` AS role FROM users p1 ".
			"JOIN roles p2 on p2.id=p1.role_id  ".
		$add_sql,
		$execute
		);
	}

	function users_join_clients_details_roles($add_sql = '', $execute = false){

		$this->LINE = __FILE__.' '.__LINE__;
		return $this->Select(
			"SELECT p1.*, ".$this->columns('clients', 'p2', array('id'), true).",
			p3.id AS client_detail_id, ".$this->columns('client_details', 'p3', array('id'), true)." FROM users p1 ".
			"JOIN clients p2 on p2.user_id=p1.id ".
			"JOIN client_details p3 on p3.client_id=p2.id ".
			"JOIN roles p4 on p4.id=p1.role_id  ".
		$add_sql,
		$execute
		);
	}
}
?>