Exemplo n.º 1
0
 /**
  * Return location objects as array
  * 
  * @param string $loc_name location name
  * @param array $order_by sorting data
  * @param integer $lang_id language identifier
  * @param array $languages languages data
  * @param integer $country country identifier
  * @param integer $region region identifier
  * @param integer $city city identifier
  * @return array
  */
 public function get_locations($loc_name, $order_by = array(), $lang_id = false, $languages = array(), $country = null, $region = null, $city = null)
 {
     $return = array();
     if ($loc_name) {
         $where_str = '';
         $loc_names = array();
         if (!is_array($loc_name)) {
             $loc_name = trim($loc_name);
             $filter = array(',', '.', '?', '!', '+', '-', '–', '—', '/', '\\', '-');
             $loc_names[] = $loc_name;
             $loc_names[] = preg_replace('/\\s+/', ' ', str_ireplace($filter, ' ', $loc_name));
         }
         //$loc_names = array_unique(explode(' ', $loc_name));
         foreach ($loc_names as $loc_subname) {
             if (empty($loc_subname)) {
                 continue;
             }
             if (strlen($where_str) > 0) {
                 $where_str .= " OR";
             }
             $where_str .= " name like " . $this->DB->escape($loc_subname . '%') . " ";
             $query_string_for_langs = $this->getQueryStringForLangs($loc_subname, $languages);
             if ($query_string_for_langs) {
                 $where_str .= 'OR ' . $query_string_for_langs;
             }
         }
     }
     // Search in countries
     if (!$country) {
         $select_attrs = $this->attrs_country;
         if ($lang_id) {
             $select_attrs = array_diff($select_attrs, array('name'));
             $select_attrs[] = 'lang_' . $lang_id . ' as name';
         }
         $this->DB->select(implode(", ", $select_attrs))->from(COUNTRIES_TABLE);
         if ($where_str) {
             $this->DB->where($where_str, null, false);
         }
         $this->DB->limit(50);
         if (is_array($order_by) && count($order_by) > 0) {
             foreach ($order_by as $field => $dir) {
                 if (in_array($field, $this->attrs_country)) {
                     $this->DB->order_by($field . " " . $dir);
                 }
             }
         }
         $results = $this->DB->get()->result_array();
         $return['countries'] = $results ? $results : array();
         if (!empty($return['countries'])) {
             $this->CI->load->helper('countries');
             $locations_ids = array();
             foreach ($return['countries'] as $key => $row_countries) {
                 $locations_ids[$key] = array('country' => $row_countries['code']);
                 $list_locations = countries_output_format($locations_ids);
                 $return['countries'][$key]['name'] = $list_locations[$key];
             }
         }
     } else {
         $return['countries'] = array();
     }
     // Search in regions
     if (!$region) {
         $select_attrs = $this->attrs_region;
         if ($lang_id) {
             $select_attrs = array_diff($select_attrs, array('name'));
             $select_attrs[] = 'lang_' . $lang_id . ' as name';
         }
         $this->DB->select(implode(", ", $select_attrs))->from(REGIONS_TABLE);
         if ($country) {
             $this->DB->where('country_code', $country);
         }
         if ($where_str) {
             $this->DB->where('(' . $where_str . ')', null, false);
         }
         $this->DB->limit(50);
         if (is_array($order_by) && count($order_by) > 0) {
             foreach ($order_by as $field => $dir) {
                 if (in_array($field, $this->attrs_region)) {
                     $this->DB->order_by($field . " " . $dir);
                 }
             }
         }
         $results = $this->DB->get()->result_array();
         $return['regions'] = $results ? $results : array();
         if (!empty($return['regions'])) {
             $this->CI->load->helper('countries');
             $locations_ids = array();
             foreach ($return['regions'] as $key => $row_region) {
                 $locations_ids[$key] = array('country' => $row_region['country_code'], 'region' => $row_region['id']);
                 $list_locations = regions_output_format($locations_ids);
                 $return['regions'][$key]['name'] = $list_locations[$key];
             }
         }
     } else {
         $return['regions'] = array();
     }
     // Search in cities
     if (!$city) {
         $select_attrs = $this->attrs_city;
         if ($lang_id) {
             $select_attrs = array_diff($select_attrs, array('name'));
             $select_attrs[] = 'lang_' . $lang_id . ' as name';
         }
         $this->DB->select(implode(", ", $select_attrs))->from(CITIES_TABLE);
         if ($country) {
             $this->DB->where('country_code', $country);
         }
         if ($region) {
             $this->DB->where('id_region', $region);
         }
         if ($where_str) {
             $this->DB->where('(' . $where_str . ')', null, false);
         }
         $this->DB->limit(50);
         if (is_array($order_by) && count($order_by) > 0) {
             foreach ($order_by as $field => $dir) {
                 if (in_array($field, $this->attrs_city)) {
                     $this->DB->order_by($field . " " . $dir);
                 }
             }
         }
         $results = $this->DB->get()->result_array();
         $return['cities'] = $results ? $results : array();
         if (!empty($return['cities'])) {
             $this->CI->load->helper('countries');
             $locations_ids = array();
             foreach ($return['cities'] as $key => $row_cities) {
                 $locations_ids[$key] = array('country' => $row_cities['country_code'], 'region' => $row_cities['id_region'], 'city' => $row_cities['id']);
                 $list_locations = cities_output_format($locations_ids);
                 $return['cities'][$key]['name'] = $list_locations[$key];
             }
         }
     } else {
         $return['cities'] = array();
     }
     // Search in districts
     $use_district = $this->CI->pg_module->get_module_config('countries', 'use_district');
     if ($use_district) {
         $select_attrs = $this->attrs_district;
         if ($lang_id) {
             $select_attrs = array_diff($select_attrs, array('name'));
             $select_attrs[] = 'lang_' . $lang_id . ' as name';
         }
         $this->DB->select(implode(", ", $select_attrs))->from(DISTRICTS_TABLE);
         if ($country) {
             $this->DB->where('country_code', $country);
         }
         if ($region) {
             $this->DB->where('id_region', $region);
         }
         if ($city) {
             $this->DB->where('id_city', $city);
         }
         if ($where_str) {
             $this->DB->where('(' . $where_str . ')', null, false);
         }
         $this->DB->limit(50);
         if (is_array($order_by) && count($order_by) > 0) {
             foreach ($order_by as $field => $dir) {
                 if (in_array($field, $this->attrs_city)) {
                     $this->DB->order_by($field . " " . $dir);
                 }
             }
         }
         $results = $this->DB->get()->result_array();
         $return['districts'] = $results ? $results : array();
         if (!empty($return['districts'])) {
             $this->CI->load->helper('countries');
             $locations_ids = array();
             foreach ($return['districts'] as $key => $row_districts) {
                 $locations_ids[$key] = array('country' => $row_districts['country_code'], 'region' => $row_districts['id_region'], 'city' => $row_districts['id_city'], 'district' => $row_districts['id']);
                 $list_locations = districts_output_format($locations_ids);
                 $return['districts'][$key]['name'] = $list_locations[$key];
             }
         }
     } else {
         $return['districts'] = array();
     }
     return $return;
 }
Exemplo n.º 2
0
 function format_filters($data)
 {
     $locations = array();
     foreach ($data as $key => $filter) {
         $locations[$key] = array($filter['search_data']['id_country'], $filter['search_data']['id_region'], $filter['search_data']['id_city']);
         $data[$key]['search_data']['subscription'] = l("subscription_{$filter['search_data']['id_subscription']}", 'subscriptions');
     }
     // Format locations
     if (!empty($locations)) {
         $this->CI->load->helper('countries');
         $user_friendly_location = cities_output_format($locations);
         foreach ($data as $key => $filter) {
             $data[$key]['location'] = isset($user_friendly_location[$key]) ? $user_friendly_location[$key] : '';
         }
     }
     return $data;
 }
Exemplo n.º 3
0
 public function get_fulltext_data($id, $fields)
 {
     $return = array('main_fields' => array(), 'fe_fields' => array(), 'default_lang_id' => $this->CI->pg_language->get_default_lang_id(), 'object_lang_id' => 1);
     $this->set_additional_fields($fields);
     $data = $this->get_user_by_id($id);
     $hide_user_names = $this->pg_module->get_module_config('users', 'hide_user_names');
     $return['object_lang_id'] = $data["lang_id"];
     $return['main_fields'] = array('fname' => $hide_user_names ? '' : $data['fname'], 'sname' => $hide_user_names ? '' : $data['sname'], 'nickname' => $data['nickname'], 'phone' => $data['phone'], 'address' => $data['address'], 'postal_code' => $data['postal_code']);
     $user_for_location[$data["id"]] = array($data["id_country"], $data["id_region"], $data["id_city"]);
     $this->CI->load->helper('countries');
     $user_locations = cities_output_format($user_for_location);
     $return['main_fields']["location"] = isset($user_locations[$data["id"]]) ? $user_locations[$data["id"]] : '';
     foreach ($fields as $field) {
         $return['fe_fields'][$field] = $data[$field];
     }
     return $return;
 }
Exemplo n.º 4
0
 public function call_login($email, $password)
 {
     $LOGIN_SUCCESS = 0;
     $LOGIN_PASSWD_ERROR = 1;
     $LOGIN_NICK_EXIST = 2;
     $LOGIN_ERROR = 3;
     $LOGIN_ERROR_NOUSERID = 4;
     $LOGIN_SUCCESS_ADMIN = 5;
     $LOGIN_NOT_ALLOW_GUEST = 6;
     $LOGIN_USER_BANED = 7;
     if (empty($email) || empty($password)) {
         echo $LOGIN_ERROR_NOUSERID;
         return false;
     }
     $this->load->model("users/models/Auth_model");
     $validate = $this->CI->Auth_model->validate_login_data(array('email' => $email, 'password', $password));
     if (empty($validate['errors'])) {
         echo $LOGIN_ERROR, '|', implode(', ', $validate['errors']);
         return false;
     }
     $pw_array = array($password, md5($password));
     $this->CI->load->model('Users_model');
     $flag = false;
     foreach ($pw_array as $passwd) {
         $user = $this->CI->Users_model->get_user_by_email_password($email, $passwd);
         $flag = !$user ? true : false;
         if (!$flag) {
             break;
         }
     }
     if ($flag) {
         echo $LOGIN_PASSWD_ERROR;
         return false;
     }
     $this->CI->load->model('Uploads_model');
     $logo = $this->CI->Uploads_model->format_upload($this->CI->Users_model->upload_config_id, $user["id"], $user["user_logo"]);
     $this->CI->load->helper('countries');
     $location = cities_output_format(array($user['id'] => array($user['id_country'], $user['id_region'], $user['id_city'])), $user['lang_id']);
     echo "{$LOGIN_SUCCESS}|" . "eml={$user['email']}&" . "a={$user['age']}&" . "s={$user['user_type']}&" . "l={$location[$user['id']]}&" . "avt={$logo['thumbs']['small']}";
     return true;
 }