= $Row['file_watermark']; $gallery[$k]['thumbnail'] = $Row['thumbnail']; $gallery[$k]['is_watermark'] = $Row['is_watermark']; $k++; } $list['gallery'] = $gallery; } $list['id'] = $aRow['id']; $trans = $aRow['transmission']; $trans = $this->get_name($trans, "transmission", "name"); $list['transmission'] = $trans["name"]; $color2 = $aRow['color']; if ($color2 == "") { $list['final_colors'] = ""; } else { $color_separate = explode(',', $color2); foreach ($color_separate as $valcolor) { $colo = $this->get_name($valcolor, "colors", "name_arabic,hex_code"); $final_color[] = $colo["name_arabic"] . "+" . $colo["hex_code"]; } $final_color2 = implode(",", $final_color); $list['final_colors'] = $final_color2; } $feature_k = $aRow['free_features']; if ($feature_k == "") { $list['final_feature'] = ""; } else { $feature_separate = explode(',', $feature_k); foreach ($feature_separate as $valfeature) { $fea = $this->get_name($valfeature, "free_features", "name_arabic,icons"); if ($fea["name_arabic"] != "") { $final_feature[] = $fea["name_arabic"] . "+" . $fea["icons"]; } } $final_feature2 = implode(",", $final_feature); $list['final_feature'] = $final_feature2; } //$pick_up=$aRow['pick_up']; //$pick_up=$this->get_name($pick_up,"pickup_policy","name"); //$list['pick_up'] = $pick_up["name"]; $list['pick_up'] = $aRow['pick_up']; $client_id = $aRow['client_id']; $client = $this->get_company($client_id, "clients", "logo,swf,company_name_arabic,company_name,description_arabic,airport_meetgreet,delivery_at_location,salik_toll_charges,client_currency,client_country,cost_of_delivery,minimum_cust_age,location,location_arabic,fast_delivery_locations"); $list['fast_delivery_locations'] = $client["fast_delivery_locations"]; $list['salik'] = $client["salik_toll_charges"]; $list['airport_meet'] = $client["airport_meetgreet"]; $list['delivery_location'] = $client["delivery_at_location"]; $list['company_logo'] = $client["logo"]; $list['company_swf'] = $client["swf"]; $list['client_country'] = $client["client_country"]; $list['client_currency'] = $client["client_currency"]; $list['cost_of_delivery'] = $client["cost_of_delivery"]; $list['minimum_cust_age'] = $client["minimum_cust_age"]; $list['location'] = $client["location"]; $list['location_arabic'] = $client["location_arabic"]; $list['company_name'] = $client["company_name_arabic"]; $list['company_name_anchor'] = $client["company_name"]; $list['company_desc'] = $client["description_arabic"]; // additional information for updated version of view. $list['driver'] = $aRow['driver']; $list['insurance_included'] = $aRow['insurance_included']; $list['security_deposit'] = $aRow['security_deposit']; $accepted = $aRow['accepted']; $accepted = $this->get_name($accepted, "accepted", "name"); $list['accepted'] = $accepted['name']; $list['colors'] = $aRow['color']; $fuel_type = $aRow['fuel_policy']; $fuel_type = $this->get_name($fuel_type, "fuel_policy", "name"); $list['fuel_type'] = $fuel_type["name"]; $engine_capacity = $aRow['engine_capacity']; $engine_capacity = $this->get_name($engine_capacity, "engine_capacity", "name"); // $list['engine_capacity'] = $engine_capacity["name"]; $engine_technology = $aRow['engine_technology']; $engine_technology = $this->get_name($engine_technology, "engine_technology", "name"); $list['engine_technology'] = $engine_technology["name"]; $list['branches'] = $aRow['branches']; $list['customer_note'] = $aRow['customer_note']; $list['delete_status'] = $aRow['delete_status']; // this will get the features from `listings` database // in form of "1,2,3,4" $list['features'] = $aRow['free_features']; } $this->memcached_library->add($key_cache, $list); $this->set_memcachekeys($key_cache); return $list; } else { return $getCarDetails_arabic; } } function get_fast_locations($location_ids) { $key_cache = 'get_fast_locations@' . $location_ids; $get_fast_locations = $this->memcached_library->get($key_cache); if (!$get_fast_locations && !is_numeric($get_fast_locations)) { $location_ids = explode(",", $location_ids); $locations = array(); foreach ($location_ids as $loc_id) { $qry = $this->db->query("SELECT * FROM delivery_locations WHERE id = ?", array("id" => $loc_id)); $result = $qry->row_array(); $locations[] = $result["location"]; } $this->memcached_library->add($key_cache, $locations, 86400); $this->set_memcachekeys($key_cache); return $locations; } else { return $get_fast_locations; } } function get_fast_locations_search($location_ids, $emirate) { $key_cache = 'get_fast_locations_search1@' . $location_ids.$emirate; $get_fast_locations = $this->memcached_library->get($key_cache); if (!$get_fast_locations && !is_numeric($get_fast_locations)) { $location_ids = explode(",", $location_ids); $locations = array(); foreach ($location_ids as $loc_id) { $qry = $this->db->query("SELECT * FROM delivery_locations WHERE emirate = '$emirate' AND id = ?", array("id" => $loc_id)); $result = $qry->row_array(); if(count($result) != 0){ $locations[] = $result["location"]; } } $this->memcached_library->add($key_cache, $locations, 86400); $this->set_memcachekeys($key_cache); return $locations; } else { return $get_fast_locations; } } function get_fast_locations_new($location_ids) { $key_cache = 'get_fast_locations_new@' . $location_ids; $get_fast_locations = $this->memcached_library->get($key_cache); if (!$get_fast_locations && !is_numeric($get_fast_locations)) { $location_ids = explode(",", $location_ids); $locations = array(); foreach ($location_ids as $loc_id) { $qry = $this->db->query("SELECT * FROM delivery_locations WHERE id = ?", array("id" => $loc_id)); $result = $qry->row_array(); $locations[] = $result["emirate"]."||".$result["location"]; } $this->memcached_library->add($key_cache, $locations, 86400); $this->set_memcachekeys($key_cache); return $locations; } else { return $get_fast_locations; } } function get_make_keyword_list() { $sql = "select id ,name,related_ids,complete_car_name,complete_car_name_ar from make where id NOT IN( SELECT car_model FROM `listings` group by car_model) and related_ids!='' group by complete_car_name ORDER BY `make`.`id` DESC"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $related_id = $aRow["related_ids"] . "," . $aRow["id"]; $list[] = $aRow["complete_car_name"] . "*****" . $related_id; } return $list; } function get_fast_locations_arabic($location_ids) { $location_ids = explode(",", $location_ids); $locations = array(); foreach ($location_ids as $loc_id) { $qry = $this->db->query("SELECT * FROM delivery_locations WHERE id = ?", array("id" => $loc_id)); $result = $qry->row_array(); $locations[] = $result["location_ar"]; } return $locations; } function get_extras($client_id) { $key_cache = 'get_extras@' . $client_id; $get_extras = $this->memcached_library->get($key_cache); if (!$get_extras && !is_numeric($get_extras) && !empty($get_extras)) { $sql = "select ep.price price , e.name name from extra_prices ep, extras e where e.id = ep.extras_id and client_id = $client_id"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $list[$aRow["name"]] = $aRow["price"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_extras; } } function get_name($id, $table, $cols) { $key_cache='get_name_lat@'.$id.'@'.$table.'@'.$cols; $get_name = $this->memcached_library->get($key_cache); if(!$get_name && !is_numeric($get_name)){ $sql = "select $cols from $table where id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row, 86400); $this->set_memcachekeys($key_cache); return $row; } else { return $get_name; } } function get_seo_url() { $sql = "select id, url from make where url != ''"; $result = mysql_query($sql); $list = []; $c= 0; while($row = mysql_fetch_array($result)){ $list[$c]['id'] = $row['id']; $list[$c]['url'] = $row['url']; $c++; } return $list; } function get_search_seo_url() { $sql = "SELECT s_id, dynamic_json FROM `seo_search` where dynamic_json != ''"; $result = mysql_query($sql); $list = []; $c= 0; while($row = mysql_fetch_array($result)){ $list[$c]['s_id'] = $row['s_id']; $list[$c]['dynamic_json'] = $row['dynamic_json']; $c++; } return $list; } function update_url($arr) { foreach($arr as $a){ $sql = "update make set url = '$a[url]' where id = $a[id]"; $result = mysql_query($sql); } return true; } function update_search_url($arr) { foreach($arr as $a){ $sql = "update seo_search set dynamic_json = '$a[dynamic_json]' where s_id = $a[s_id]"; $result = mysql_query($sql); } return true; } function get_related_id_model_brand($id, $table, $cols,$make) { $key_cache = 'get_related_id_model_brand@' . $id . '@' . $table . '@' . $cols.'@'.$make; $get_name = $this->memcached_library->get($key_cache); if (!$get_name && !is_numeric($get_name)) { $sql = "select $cols from $table where id = $id and model=$make limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row, 86400); $this->set_memcachekeys($key_cache); return $row; } else { return $get_name; } } function get_name_2($id, $table, $cols) { $key_cache = 'get_name_5123@' . $id . '@' . $table . '@' . $cols; $get_name = $this->memcached_library->get($key_cache); if (!$get_name && !is_numeric($get_name)) { $sql = "select $cols from $table where id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row, 86400); $this->set_memcachekeys($key_cache); return $row; } else { return $get_name; } } function get_refresh_date($refresh) { $sql = "select actual_time from refresh_history where refresh_time = $refresh and refresh_type=0"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return $row['actual_time']; } function get_refresh_date_2($refresh) { $key_cache = 'get_refresh_date_2@' . $refresh; $get_refresh_date_2 = $this->memcached_library->get($key_cache); if (!$get_refresh_date_2 && !is_numeric($get_refresh_date_2)) { $sql = "select actual_time from refresh_history where refresh_time = $refresh"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row['actual_time']); $this->set_memcachekeys($key_cache); return $row['actual_time']; } else { return $get_refresh_date_2; } } function get_client_detail_all($id, $table) { $sql = "select lease_limit_number,number_of_featured_listing,number_of_featured_listing_mobile from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return $row; } function is_premium($client_id) { $sql = mysql_query("SELECT count(*) as total FROM `premium_listing_client` WHERE client_id_1='$client_id' OR client_id_2='$client_id' OR client_id_3='$client_id'"); if (mysql_num_rows($sql) > 0) { $total = mysql_fetch_array($sql); $count = $total['total']; } else { $count = '0'; } return $count; } function get_client_detail($id, $table, $cols) { $key_cache = 'get_client_detail_lats@' . $id.'@'.$table.'@'.$cols; $get_client_detail = $this->memcached_library->get($key_cache); if (!$get_client_detail && !is_numeric($get_client_detail)) { $sql = "select $cols from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row[$cols], 86400); $this->set_memcachekeys($key_cache); return $row[$cols]; } else { return $get_client_detail; } } function get_client_detail_2($id, $table, $cols) { $sql = "select $cols from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return $row[$cols]; } function get_client_detail_admin($id, $table, $cols) { $sql = "select $cols from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return $row[$cols]; } function get_verification_status($list_id) { $qry = $this->db->query("SELECT images_verify FROM listings WHERE id = ?", array("id" => $list_id)); $result = $qry->result_array(); return $result['images_verify']; } function gel_all_emirate_locations($emirate, $fasts = 0) { $qry = $this->db->query("SELECT * FROM delivery_locations WHERE emirate = ? ORDER BY location ASC", array("emirate" => $emirate)); $result = $qry->result_array(); if(count($result) == "0" && $fasts != 0 && $fasts != ""){ $qry = $this->db->query("SELECT * FROM delivery_locations WHERE id in ($fasts) ORDER BY location ASC"); $result = $qry->result_array(); } return $result; } function get_all_languages_speak($emirate) { $qry = $this->db->query("SELECT * FROM languages_speak WHERE active = 1"); $result = $qry->result_array(); return $result; } function gel_delievry_terms($client_id) { $qry = $this->db->query("SELECT * FROM delivery_terms WHERE client_id = ?", array("client_id" => $client_id)); $result = $qry->result_array(); return $result; } function gel_delievry_terms_front($client_id) { $key_cache = "gel_delievry_terms_front@".$client_id; $gel_delievry_terms_front = $this->memcached_library->get($key_cache); if (!$gel_delievry_terms_front && $gel_delievry_terms_front!=0 && !empty($gel_delievry_terms_front)) { $qry = $this->db->query("SELECT * FROM delivery_terms WHERE client_id = ? AND delivery_term != 'Exclude' ORDER BY emirate ASC", array("client_id" => $client_id)); if($qry->num_rows()>0){ $result = $qry->result_array(); $this->memcached_library->add($key_cache, $result, 86400); $this->set_memcachekeys($key_cache); return $result; } else { $result = 0; $this->memcached_library->add($key_cache, $result, 86400); $this->set_memcachekeys($key_cache); return $result; } } else { return $gel_delievry_terms_front; } } function get_image_upload_status_step($list_id) { $qry = $this->db->query("SELECT COUNT(*) as count FROM mulkiya WHERE (`type` LIKE '%image%' OR `type` LIKE '%pdf%') and listing_id = ?", array("listing_id" => $list_id)); $result = $qry->row_array(); $reg_card = $result['count'];; $qry1 = $this->db->query("SELECT COUNT(*) as count FROM gallery WHERE listing_id = ?", array("listing_id" => $list_id)); $res1 = $qry1->row_array(); $new_image_count = $res1['count']; if ($reg_card == 0) { return array("No", $new_image_count); } else { return array("Yes", $new_image_count); } } function get_image_upload_status($list_id) { $emirate_qry = $this->db->query("SELECT c.emirate FROM clients c INNER JOIN listings l WHERE l.client_id = c.client_id and l.id = ?",array($list_id)); $emirate_res = $emirate_qry->row_array(); $emirate = $emirate_res["emirate"]; if($emirate == "Dubai"){ $qry = $this->db->query("SELECT COUNT(*) as count FROM mulkiya WHERE (`type` LIKE '%pdf%') and listing_id = ?", array("listing_id" => $list_id)); $result = $qry->row_array(); $reg_card = $result['count']; if($reg_card == 1){ $qry = $this->db->query("SELECT COUNT(*) as count FROM mulkiya WHERE (`type` LIKE '%image%') and listing_id = ?", array("listing_id" => $list_id)); $result = $qry->row_array(); $reg_card_check = $result['count']; if($reg_card_check > 0){ $reg_card = 0; } } }else{ $qry = $this->db->query("SELECT COUNT(*) as count FROM mulkiya WHERE (`type` LIKE '%image%' OR `type` LIKE '%pdf%') and listing_id = ?", array("listing_id" => $list_id)); $result = $qry->row_array(); $reg_card = $result['count']; } $qryv = $this->db->query("SELECT COUNT(*) as count FROM mulkiya WHERE `type` LIKE '%video%' and listing_id = ?", array("listing_id" => $list_id)); $resultv = $qryv->row_array(); $qclient = $this->db->query("SELECT clients.video_val as video_val, clients.image_val as image_val FROM listings inner join clients on clients.client_id = listings.client_id WHERE listings.id = ?", array("id" => $list_id)); $resultclient = $qclient->row_array(); $video_val = $resultclient["video_val"]; $image_val = $resultclient["image_val"]; $reg_cardv = $resultv['count']; $qry1 = $this->db->query("SELECT COUNT(*) as count FROM gallery WHERE listing_id = ?", array("listing_id" => $list_id)); $res1 = $qry1->row_array(); $new_image_count = $res1['count']; if ($reg_card > 0 && $reg_cardv > 0) { return array("Yes", $new_image_count); } else if (($reg_card == 0 && $image_val == 0) && $reg_cardv > 0) { return array("Yes", $new_image_count); } else if ($reg_card > 0 && ($reg_cardv == 0 && $video_val == 0)) { return array("Yes", $new_image_count); } else if (($reg_card == 0 && $image_val == 0) && ($reg_cardv == 0 && $video_val == 1)) { return array("No Videos", $new_image_count); } else if (($reg_card == 0 && $image_val == 1) && ($reg_cardv == 0 && $video_val == 0)) { return array("No Images", $new_image_count); } else if (($reg_card == 0 && $image_val == 1) && $reg_cardv > 0) { return array("No Images", $new_image_count); } else if ($reg_card > 0 && ($reg_cardv == 0 && $video_val == 1)) { return array("No Videos", $new_image_count); } else { return array("No", $new_image_count); } } function set_submit_status($list_id, $submit_time) { $qry = $this->db->query("update listings set submit_status = 1, no_expiry_date='1', submit_time = ? where id = ?", array("submit_time" => $submit_time, "id" => $list_id)); //return $this->db->last_query(); if ($qry) { return true; } else { return false; } } function set_listing_title($list_id, $listing_title) { $submit_time = date("Y-m-d H:i:s"); $qry = $this->db->query("update listings set listing_title = '$listing_title', listing_title_approve = 0, submit_time = '$submit_time' where id = ?", array("id" => $list_id)); //return $this->db->last_query(); if ($qry) { return true; } else { return false; } } function total_lease_client($client_id) { $sql = mysql_query("select * from email_lease where client_id='$client_id'"); return $sql2 = mysql_num_rows($sql); } function total_lease_client_thirty($client_id, $date_range) { $sql = mysql_query("select * from email_lease where client_id='$client_id' and ts BETWEEN DATE_SUB(NOW(), INTERVAL $date_range DAY) AND NOW()"); return $sql2 = mysql_num_rows($sql); } function total_lease_client_thirty_date($client_id, $startdate, $enddate) { $sql = mysql_query("select * from email_lease where client_id='$client_id' and ts BETWEEN '$startdate' AND '$enddate'"); // ts BETWEEN DATE_SUB(NOW(), INTERVAL $date_range DAY) AND NOW()"); return $sql2 = mysql_num_rows($sql); } function get_carlogo($id, $year) { $sql = "select $cols from make where id = $id"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return $row; } function get_company4($id, $table) { $key_cache='get_company4@'.$id.'@'.$table; // $this->memcached_library->delete($key_cache); $get_company = $this->memcached_library->get($key_cache); if(!$get_company && !is_numeric($get_company)){ $sql = "select * from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row, 86400); $this->set_memcachekeys($key_cache); return $row; } else { return $get_company; } } function get_company($id, $table, $cols) { $key_cache='get_company_lat1@'.$id.'@'.$table.'@'.$cols; $get_company = $this->memcached_library->get($key_cache); if(!$get_company && !is_numeric($get_company)){ $sql = "select $cols from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row, 86400); $this->set_memcachekeys($key_cache); return $row; } else { return $get_company; } } function get_company_no_mem($id, $table, $cols) { $sql = "select $cols from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); return $row; } function get_company_2($id, $table, $cols) { $key_cache = 'get_company_3@' . $id . '@' . $table . '@' . $cols; $get_company = $this->memcached_library->get($key_cache); if (!$get_company && !is_numeric($get_company)) { $sql = "select $cols from $table where client_id = $id limit 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $this->memcached_library->add($key_cache, $row, 86400); $this->set_memcachekeys($key_cache); return $row; } else { return $get_company; } } function get_features($id, $table, $cols) { $sql = "select $cols from $table where id in ($id)"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $list[] = $aRow['name']; } return $list; } function get_car_features($features) { $key_cache = 'get_car_features@' . $features; $get_car_features = $this->memcached_library->get($key_cache); if (!$get_car_features && !is_numeric($get_car_features) && !empty($get_car_features)) { $sql = "select name,icon from free_features where id in ($features)"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $list[] = $aRow['name'] . ',' . $aRow['icon']; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_car_features; } } function get_pickup_features($pickup_features) { $key_cache = 'get_pickup_features@' . $pickup_features; $get_pickup_features = $this->memcached_library->get($key_cache); if (!$get_pickup_features && !is_numeric($get_pickup_features)) { $sql = "select name,icon from pickup_policy where id in ($pickup_features)"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $list[] = $aRow['name'] . ',' . $aRow['icon']; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_pickup_features; } } function get_car_colors($colors) { $key_cache = 'get_car_colors@' . $colors; $get_car_colors = $this->memcached_library->get($key_cache); if (!$get_car_colors && !is_numeric($get_car_colors)) { $sql = "select name from colors where id in ($colors)"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $list[] = $aRow['name']; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_car_colors; } } function get_companycartype($client_id) { $key_cache = 'get_companycartype@' . $client_id; $get_companycartype = $this->memcached_library->get($key_cache); if (!$get_companycartype && !is_numeric($get_companycartype)) { $sql = mysql_query("select id,car_type from listings where client_id='$client_id' and publish_ocd='1' group by car_type"); while ($val = mysql_fetch_array($sql)) { $car_type = $val['car_type']; $cartype = $this->get_name($car_type, "car_types", "name,id"); $fin_cartype = $cartype["name"]; $list[$val['id']]['name'] = $fin_cartype; $list[$val['id']]['id'] = $cartype["id"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_companycartype; } } function get_companycartype_usedcar($client_id) { $key_cache = 'get_companycartype_usedcar@' . $client_id; $get_companycartype = $this->memcached_library->get($key_cache); if (!$get_companycartype && !is_numeric($get_companycartype)) { $sql = mysql_query("select id,car_type from usedcar_listings where client_id='$client_id' and publish_ocd='1' group by car_type"); while ($val = mysql_fetch_array($sql)) { $car_type = $val['car_type']; $cartype = $this->get_name($car_type, "car_types", "name,id"); $fin_cartype = $cartype["name"]; $list[$val['id']]['name'] = $fin_cartype; $list[$val['id']]['id'] = $cartype["id"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_companycartype; } } function get_brand_cartypes($brand_id, $emirate,$used_cars=0) { $key_cache = 'get_brand_cartypes@' . $brand_id . '@' . $emirate.$used_cars; $get_brand_cartypes = $this->memcached_library->get($key_cache); if (!$get_brand_cartypes && !is_numeric($get_brand_cartypes)) { if($used_cars==0){ $sql = mysql_query("select id,car_type from listings where car_model='$brand_id' AND client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and publish_ocd='1' group by car_type"); } else { $sql = mysql_query("select id,car_type from usedcar_listings where car_model='$brand_id' AND client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and publish_ocd='1' and used_cars='$used_cars' group by car_type"); } while ($val = mysql_fetch_array($sql)) { $car_type = $val['car_type']; $cartype = $this->get_name($car_type, "car_types", "name,id"); $fin_cartype = $cartype["name"]; $list[$val['id']]['name'] = $fin_cartype; $list[$val['id']]['id'] = $cartype["id"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_brand_cartypes; } } function get_brand_carmodels($brand_id, $emirate,$used_cars=0) { $key_cache = 'get_brand_carmodels@' . $brand_id . '@' . $emirate.$used_cars; $get_brand_carmodels = $this->memcached_library->get($key_cache); if (!$get_brand_carmodels && !is_numeric($get_brand_carmodels)) { if($used_cars==0) { $sql = mysql_query("select id,car_make from listings where car_model='$brand_id' AND client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and publish_ocd='1' group by car_make"); } else{ $sql = mysql_query("select id,car_make from usedcar_listings where car_model='$brand_id' AND client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and publish_ocd='1' and used_cars='$used_cars' group by car_make"); } while ($val = mysql_fetch_array($sql)) { $car_model = $val['car_make']; $carmodel = $this->get_name($car_model, "make", "name,id"); $fin_carmodel = $carmodel["name"]; $list[$val['id']]['name'] = $fin_carmodel; $list[$val['id']]['id'] = $carmodel["id"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_brand_carmodels; } } function get_brand_footer_details($brand_id, $emirate,$used_cars=0) { $key_cache = 'get_brand_footer_details4@' . $brand_id . '@' . $emirate.$used_cars; // $this->memcached_library->delete($key_cache); $get_brand_carmodels2 = $this->memcached_library->get($key_cache); //echo "select listings.id,car_make, MIN(listings.del_pick_charge) as min_del_pick_charge, MIN(min_days_booking) as min_days_booking, MIN(additional_mileage_charge) as additional_charge,MIN(mileage_day) as mileage_day,MIN(mileage_week) as mileage_week,MIN(mileage_month) as mileage_month, MIN(minimum_cust_age) as minimum_cust_age from listings inner join clients on listings.client_id=clients.client_id where car_model='$brand_id' AND clients.emirate='$emirate' and publish_ocd='1' and mileage_day!=0 and mileage_week!=0 and mileage_month!=0 and additional_mileage_charge!=0 group by car_model"; if (!$get_brand_carmodels2 && !is_numeric($get_brand_carmodels2)) { if($used_cars=="0") { $sql = mysql_query("select listings.id,car_make, MIN(CASE WHEN listings.del_pick_charge > 0 THEN listings.del_pick_charge ELSE NULL END) AS min_del_pick_charge, MIN(CASE WHEN min_days_booking > 0 THEN min_days_booking ELSE NULL END) AS min_days_booking, MIN(CASE WHEN additional_mileage_charge REGEXP '^[0-9]+$' AND CAST(additional_mileage_charge AS UNSIGNED) > 0 THEN CAST(additional_mileage_charge AS UNSIGNED) ELSE NULL END) AS additional_charge, MIN(CASE WHEN mileage_day > 0 THEN mileage_day ELSE NULL END) AS mileage_day, MIN(CASE WHEN clients.driving_license_age = 'New driving license accepted' THEN 1 WHEN clients.driving_license_age = 'Minimum 6 months old' THEN 2 WHEN clients.driving_license_age = 'Minimum 1 year old' THEN 3 ELSE 99 END) AS driving_license_age, MIN(CASE WHEN mileage_week > 0 THEN mileage_week ELSE NULL END) AS mileage_week, MIN(CASE WHEN mileage_month > 0 THEN mileage_month ELSE NULL END) AS mileage_month, MIN(CASE WHEN minimum_cust_age > 0 THEN minimum_cust_age ELSE NULL END) AS minimum_cust_age from listings inner join clients on listings.client_id=clients.client_id where car_model='$brand_id' AND clients.emirate='$emirate' and publish_ocd='1' group by car_model"); while ($val = mysql_fetch_array($sql)) { $list['min_days_booking'] = $val["min_days_booking"]; $list['additional_charge'] = $val["additional_charge"]; $list['mileage_day'] = $val["mileage_day"]; $list['mileage_week'] = $val["mileage_week"]; $list['mileage_month'] = $val["mileage_month"]; $list['minimum_cust_age'] = $val["minimum_cust_age"]; $list['min_del_pick_charge'] = $val["min_del_pick_charge"]; $list['driving_license_age'] = $val['driving_license_age']; } } else{ $sql = mysql_query("select id,car_make, MIN(km_driven) as km_driven from usedcar_listings where car_model='$brand_id' AND client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and publish_ocd='1' and km_driven!=0 and used_cars='$used_cars' group by car_model"); while ($val = mysql_fetch_array($sql)) { $list['name'] = $fin_carmodel; $list['id'] = $val["id"]; $list['km_driven'] = $val["km_driven"]; } } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_brand_carmodels2; } } function get_brand_carmodels_new($brand_id, $emirate,$used_cars=0) { $lang_code = $this->session->userdata("lang_code"); $key_cache = 'get_brand_carmodels_new3@' . $brand_id . '@' . $emirate.'@'.$lang_code.$used_cars; $get_brand_carmodels = $this->memcached_library->get($key_cache); if (!$get_brand_carmodels && !is_numeric($get_brand_carmodels)) { if($used_cars==0) { $sql = mysql_query("select count(*) as count,make.name from listings inner join make on make.id=listings.car_make where listings.car_model='$brand_id' AND listings.client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and listings.publish_ocd='1' group by listings.car_make order by count desc"); } else { $sql = mysql_query("select count(*) as count,make.name from usedcar_listings inner join make on make.id=usedcar_listings.car_make where usedcar_listings.car_model='$brand_id' and used_cars='$used_cars' AND usedcar_listings.client_id in (SELECT client_id FROM clients WHERE emirate='$emirate') and usedcar_listings.publish_ocd='1' group by usedcar_listings.car_make order by count desc"); } while ($val = mysql_fetch_array($sql)) { $car_model[] = translate($val['name'],$lang_code); } $model2=implode(", ",$car_model); if(strlen($model2)>18) $model=substr($model2, 0,16)."..."; else $model=$model2; $this->memcached_library->add($key_cache, $model, 86400); $this->set_memcachekeys($key_cache); return $model; } else { return $get_brand_carmodels; } } function get_brand_model_years($brand_id, $model_id, $emirate,$used_cars=0) { $key_cache = 'get_brand_model_years@' . $brand_id . '@' . $model_id . '@' . $emirate.$used_cars; $get_brand_model_years = $this->memcached_library->get($key_cache); if (!$get_brand_model_years && !is_numeric($get_brand_model_years)) { if($used_cars==0){ $query = $this->db->query( "SELECT DISTINCT year FROM listings WHERE car_model = ? AND car_make = ? AND client_id IN (SELECT client_id FROM clients WHERE emirate = ?) AND publish_ocd='1'", array("car_model" => $brand_id, "car_make" => $model_id, "emirate" => $emirate) ); } else { $query = $this->db->query( "SELECT DISTINCT year FROM usedcar_listings WHERE car_model = ? AND car_make = ? AND client_id IN (SELECT client_id FROM clients WHERE emirate = ?) AND used_cars='$used_cars' AND publish_ocd='1'", array("car_model" => $brand_id, "car_make" => $model_id, "emirate" => $emirate) ); } $result = $query->result_array(); $list = array(); foreach ($result as $res) { $list[] = $res["year"]; } rsort($list); $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_brand_model_years; } } function get_brand_model_places($brand_id, $model_id, $emirate,$used_cars=0) { $key_cache = 'get_brand_model_places@' . $brand_id . '@' . $model_id . '@' . $emirate.$used_cars; $get_brand_model_places = $this->memcached_library->get($key_cache); if (!$get_brand_model_places && !is_numeric($get_brand_model_places)) { if($used_cars==0) { $query = $this->db->query( "SELECT l.client_id, c.client_id, c.location, c.location_arabic FROM listings l, clients c WHERE l.car_model = ? AND l.car_make = ? AND l.client_id IN (SELECT client_id FROM clients WHERE emirate = ?) AND l.client_id = c.client_id AND publish_ocd='1'", array("car_model" => $brand_id, "car_make" => $model_id, "emirate" => $emirate) ); } else{ $query = $this->db->query( "SELECT l.client_id, c.client_id, c.location, c.location_arabic FROM usedcar_listings l, clients c WHERE l.car_model = ? AND l.car_make = ? AND l.client_id IN (SELECT client_id FROM clients WHERE emirate = ?) AND l.client_id = c.client_id AND used_cars='$used_cars' AND publish_ocd='1'", array("car_model" => $brand_id, "car_make" => $model_id, "emirate" => $emirate) ); } $result = $query->result_array(); $list = array(); $list_arabic = array(); foreach ($result as $res) { $location = str_replace("*", ",", $res['location']); $locs = explode(",", $location); $location_arabic = str_replace("*", ",", $res['location_arabic']); $locs_arabic = explode(",", $location_arabic); foreach ($locs as $loc) { if (!in_array($loc, $list)) { $list[] = $loc; } } foreach ($locs_arabic as $loc) { if (!in_array($loc, $list_arabic)) { $list_arabic[] = $loc; } } } $this->memcached_library->add($key_cache, array($list, $list_arabic, 86400)); $this->set_memcachekeys($key_cache); return array($list, $list_arabic); } else { return $get_brand_model_places; } } function get_supplier_car_list($company_id,$used_cars=0) { $key_cache = "get_supplier_car_list_11@" . $company_id.$used_cars; // $this->memcached_library->delete($key_cache); $get_supplier_car_list = $this->memcached_library->get($key_cache); if (!$get_supplier_car_list && !is_numeric($get_supplier_car_list)) { if($used_cars==0){ $query = $this->db->query("SELECT l.client_id, l.car_model, l.car_make, mo.id, mo.name as brand, ma.id, ma.name as model FROM listings l, models mo, make ma WHERE l.client_id = ? AND l.publish_ocd = '1' AND l.delete_status = '0' AND l.car_model = mo.id AND l.car_make = ma.id", array("client_id" => $company_id)); } else { $query = $this->db->query("SELECT l.client_id, l.car_model, l.car_make, mo.id, mo.name as brand, ma.id, ma.name as model FROM usedcar_listings l, models mo, make ma WHERE l.client_id = ? AND l.publish_ocd = '1' AND (l.used_cars='1' OR l.used_cars='2') AND l.delete_status = '0' AND l.car_model = mo.id AND l.car_make = ma.id", array("client_id" => $company_id)); } $result = $query->result_array(); $list = array(); foreach ($result as $res) { $list[] = $res["brand"] . " " . $res["model"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_supplier_car_list; } } function get_supplier_used_car_list($company_id) { $key_cache = "get_supplier_used_car_list_11@" . $company_id; // $this->memcached_library->delete($key_cache); $get_supplier_car_list = $this->memcached_library->get($key_cache); if (!$get_supplier_car_list && !is_numeric($get_supplier_car_list)) { $query = $this->db->query("SELECT l.client_id, l.car_model, l.car_make, mo.id, mo.name as brand, ma.id, ma.name as model FROM usedcar_listings l, models mo, make ma WHERE l.client_id = ? AND l.publish_ocd = '1' AND l.delete_status = '0' AND l.car_model = mo.id AND l.car_make = ma.id", array("client_id" => $company_id)); $result = $query->result_array(); $list = array(); foreach ($result as $res) { $list[] = $res["brand"] . " " . $res["model"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_supplier_car_list; } } function get_supplier_name_list($company_id) { $key_cache = "get_supplier_name_list@" . $company_id; $get_supplier_car_list = $this->memcached_library->get($key_cache); if (!$get_supplier_car_list && !is_numeric($get_supplier_car_list)) { $query = $this->db->query("SELECT c.company_name , c.emirate FROM clients c WHERE c.client_id = ?", array("client_id" => $company_id)); $result = $query->result_array(); $list = array(); foreach ($result as $res) { $list["company_name"] = $res["company_name"]; $list["emirate"] = $res["emirate"]; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_supplier_car_list; } } /* function get_passengers($where){ $sql = "select passengers , count(*) count from listings where $where group by passengers"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $list[$aRow['passengers']] = $aRow['count']; } return $list; } */ function getbuggy_passengers($where, $where_1) { $key_cache = 'getbuggy_passengers@' . $where . '@' . $where_1; //$this->memcached_library->delete($key_cache); $getbuggy_passengers = $this->memcached_library->get($key_cache); if (!$getbuggy_passengers && !is_numeric($getbuggy_passengers)) { $a = array('1,2', '3,4,5', '6,7', '8,9,10,11,12', '13'); $ao = new ArrayObject($a); foreach ($ao as $element) { if ($element == "13") { $sql2 = mysql_query("select passengers , count(*) count from buggy_listing inner join clients on clients.client_id = buggy_listing.client_id where buggy_listing.car_make IN ( select id from make where passengers >12 ) and $where and buggy_listing.publish_ocd='1'"); } else { $sql2 = mysql_query("select passengers , count(*) count from buggy_listing inner join clients on clients.client_id = buggy_listing.client_id where buggy_listing.car_make IN ( select id from make where passengers in ($element) ) and $where and buggy_listing.publish_ocd='1'"); } if ($element == "1,2") { $show_element = "1-2"; } else if ($element == "3,4,5") { $show_element = "4-5"; } else if ($element == "6,7") { $show_element = "6-7"; } else if ($element == "8,9,10,11,12") { $show_element = "8-12"; } else if ($element == "13") { $show_element = "13+"; } $aRow2 = mysql_fetch_array($sql2); if ($aRow2['count'] == "" || $aRow2['count'] == "0") { } else { $aRow2['count'] = $aRow2['count']; $list[$show_element] = $aRow2['count'] . "+" . $element; } //$list[$aRow['passengers']] = $aRow2['count']; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $getbuggy_passengers; } } function get_passengers($where, $where_1,$used_cars=0) { $key_cache = 'get_passengers7@' . $where . '@' . $where_1.$used_cars; //$this->memcached_library->delete($key_cache); $get_passengers = $this->memcached_library->get($key_cache); if (!$get_passengers && !is_numeric($get_passengers)) { $a = array('1,2', '3,4,5', '6,7', '8,9,10,11,12', '13'); $ao = new ArrayObject($a); foreach ($ao as $element) { if($used_cars==0){ if ($element == "13") { $sql2 = mysql_query("select passengers , count(*) count from listings where car_make IN ( select id from make where passengers >12 ) and $where and publish_ocd='1'"); } else { $sql2 = mysql_query("select passengers , count(*) count from listings where car_make IN ( select id from make where passengers in ($element) ) and $where and publish_ocd='1'"); } } else { if ($element == "13") { $sql2 = mysql_query("select passengers , count(*) count from usedcar_listings where car_make IN ( select id from make where passengers >12 ) and $where and usedcar_listings.used_cars='$used_cars' and publish_ocd='1'"); } else { $sql2 = mysql_query("select passengers , count(*) count from usedcar_listings where car_make IN ( select id from make where passengers in ($element) ) and $where and usedcar_listings.used_cars='$used_cars' and publish_ocd='1'"); } } if ($element == "1,2") { $show_element = "1-2"; } else if ($element == "3,4,5") { $show_element = "4-5"; } else if ($element == "6,7") { $show_element = "6-7"; } else if ($element == "8,9,10,11,12") { $show_element = "8-12"; } else if ($element == "13") { $show_element = "13+"; } $aRow2 = mysql_fetch_array($sql2); if ($aRow2['count'] == "" || $aRow2['count'] == "0") { } else { $aRow2['count'] = $aRow2['count']; $list[$show_element] = $aRow2['count'] . "+" . $element; } //$list[$aRow['passengers']] = $aRow2['count']; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_passengers; } } function get_brands_chauffeur($emirate) { $sql = mysql_query("select model_id from chefure_deals inner join chauffeur_offers_hours on chauffeur_offers_hours.deal_id=chefure_deals.id where chauffeur_offers_hours.emirate='$emirate' and publish_ocd='1' group by chefure_deals.model_id"); if (mysql_num_rows($sql) > 0) { while ($val = mysql_fetch_array($sql)) { $models = $val['model_id']; $model = $this->get_name($models, "models", "name"); $list[] = $model['name'] . "-" . $models; } return $list; } } function get_passengers_chauffeur($emirate) { $a = array('1,2', '3,4,5', '6,7', '8,9,10,11,12', '13,14,15,16,17,18,19,20,21,22,23,24,25,26,50,84,75'); $ao = new ArrayObject($a); foreach ($ao as $element) { if ($element == "13,14,15,16,17,18,19,20,21,22,23,24,25,26,50,84,75") { $sql2 = mysql_query("select passengers , count(*) count from chefure_deals inner join chauffeur_offers_hours on chauffeur_offers_hours.deal_id=chefure_deals.id where passengers > '12' and chauffeur_offers_hours.emirate='$emirate' and publish_ocd='1'"); } else { $sql2 = mysql_query("select passengers , count(*) count from chefure_deals inner join chauffeur_offers_hours on chauffeur_offers_hours.deal_id=chefure_deals.id where passengers in ($element) and chauffeur_offers_hours.emirate='$emirate' and publish_ocd='1'"); } if ($element == "1,2") { $show_element = "1-2"; } else if ($element == "3,4,5") { $show_element = "4-5"; } else if ($element == "6,7") { $show_element = "6-7"; } else if ($element == "8,9,10,11,12") { $show_element = "8-12"; } else if ($element == "13,14,15,16,17,18,19,20,21,22,23,24,25,26,50,84,75") { $show_element = "13+"; } $aRow2 = mysql_fetch_array($sql2); if ($aRow2['count'] == "" || $aRow2['count'] == "0") { } else { $aRow2['count'] = $aRow2['count']; $list[$show_element] = $aRow2['count'] . "+" . $element; } //$list[$aRow['passengers']] = $aRow2['count']; } return $list; } function get_make_bypassenger_count_chauffeur($pass_where) { $sql = "SELECT DISTINCT id FROM make WHERE passengers in (" . $pass_where . ")"; $qry = $this->db->query($sql); $result = $qry->result_array(); $list = array(); foreach ($result as $make) { array_push($list, $make["id"]); } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } function get_passengers_old($where, $where_1) { $sql = "select passengers from listings where $where_1 group by passengers"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $sql2 = mysql_query("select passengers , count(*) count from listings where passengers='" . $aRow['passengers'] . "' and $where and publish_ocd='1' group by passengers"); $aRow2 = mysql_fetch_array($sql2); if ($aRow2['count'] == "") { //$aRow2['count'] =0; } else { $aRow2['count'] = $aRow2['count']; $list[$aRow['passengers']] = $aRow2['count']; } //$list[$aRow['passengers']] = $aRow2['count']; } return $list; } function get_cartypes($where) { $key_cache = 'get_cartypes@'.$where; $get_cartypes = $this->memcached_library->get($key_cache); if (!$get_cartypes && !is_numeric($get_cartypes)) { $sql = "select car_type , count(*) count from listings where $where and publish_ocd='1' group by car_type"; $result = mysql_query($sql) or die(mysql_error()); while ($aRow = mysql_fetch_array($result)) { $car_type = $aRow['car_type']; $cartype = $this->get_name($car_type, "car_types", "name"); $list[$cartype["name"]] = $car_type . "-" . $aRow['count']; } $this->memcached_library->add($key_cache, $list, 86400); $this->set_memcachekeys($key_cache); return $list; } else { return $get_cartypes; } } function get_cartypes_arabic($where) { $sql = "select car_type , count(*) count from listings where $where and publish_ocd='1' group by car_type"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $car_type = $aRow['car_type']; $cartype = $this->get_name($car_type, "car_types", "name_arabic"); $list[$cartype["name_arabic"]] = $car_type . "-" . $aRow['count']; } return $list; } function get_cartypes_srch($where, $emirate) { $sql = "select car_type , count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1' and emirate='$emirate' group by car_type"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $car_type = $aRow['car_type']; $cartype = $this->get_name($car_type, "car_types", "name"); $list[$cartype["name"]] = $car_type . "-" . $aRow['count']; } return $list; } function get_cartypes_srcharabic($where, $emirate) { $sql = "select car_type , count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1' and emirate='$emirate' group by car_type"; $result = mysql_query($sql); while ($aRow = mysql_fetch_array($result)) { $car_type = $aRow['car_type']; $cartype = $this->get_name($car_type, "car_types", "name_arabic"); $list[$cartype["name_arabic"]] = $car_type . "-" . $aRow['count']; } return $list; } function get_count_convertible($where, $emirate,$used_cars=0) { $key_cache = 'get_count_convertible@' . $where . '@' . $emirate.$used_cars; $get_count_convertible = $this->memcached_library->get($key_cache); if (!$get_count_convertible && !is_numeric($get_count_convertible)) { if($used_cars==0) { $sql = "select * from listings where $where and (keywords like '%Convertible%' or keywords like '%gtc%' or keywords like '%dawn%' or keywords like '%cabriolet%' or keywords like '%grancabrio%' or keywords like '%spyder%' or car_make='481' or car_make='438') and client_id in (select client_id from `clients` where emirate like '%$emirate%') and publish_ocd='1'"; } else{ $sql = "select * from usedcar_listings where $where and (keywords like '%Convertible%' or keywords like '%gtc%' or keywords like '%dawn%' or keywords like '%cabriolet%' or keywords like '%grancabrio%' or keywords like '%spyder%' or car_make='481' or car_make='438') and client_id in (select client_id from `clients` where emirate like '%$emirate%') and usedcar_listings.used_cars='$used_cars' and publish_ocd='1'"; } $result = mysql_query($sql); $convertible_count = mysql_num_rows($result); $this->memcached_library->add($key_cache, $convertible_count, 86400); $this->set_memcachekeys($key_cache); return $convertible_count; } else { return $get_count_convertible; } } function get_count_coupe($where, $emirate,$used_cars=0) { $key_cache = 'get_count_coupe@' . $where . '@' . $emirate.$used_cars; $get_count_coupe = $this->memcached_library->get($key_cache); if (!$get_count_coupe && !is_numeric($get_count_coupe)) { if($used_cars==0) { $sql = "select * from listings where $where and car_make in (SELECT id from make where doors='2') and car_type NOT IN ('3','9','11','14') and client_id in (select client_id from `clients` where emirate like '%$emirate%') and publish_ocd='1'"; } else{ $sql = "select * from usedcar_listings where $where and car_make in (SELECT id from make where doors='2') and car_type NOT IN ('3','9','11','14') and usedcar_listings.used_cars='$used_cars' and client_id in (select client_id from `clients` where emirate like '%$emirate%') and publish_ocd='1'"; } $result = mysql_query($sql); $coupe_count = mysql_num_rows($result); $this->memcached_library->add($key_cache, $coupe_count, 86400); $this->set_memcachekeys($key_cache); return $coupe_count; } else { return $get_count_coupe; } } function get_cartype($name) { $key_cache = 'get_cartype@' . $name; $get_cartype = $this->memcached_library->get($key_cache); $id = 0; if (!$get_cartype && !is_numeric($get_cartype)) { $sql = mysql_query("select * from car_types where name = '$name'"); if(mysql_num_rows($sql)>0) { while ($aRow = mysql_fetch_array($sql)) { $id = $aRow['id']; } } $this->memcached_library->add($key_cache, $id, 86400); $this->set_memcachekeys($key_cache); return $id; } else { return $get_cartype; } } function get_color($name) { $key_cache = 'get_color@' . $name; $get_color = $this->memcached_library->get($key_cache); $id = 0; if (!$get_color && !is_numeric($get_color)) { $sql = mysql_query("select * from colors where name = '$name'"); if(mysql_num_rows($sql)>0) { while ($aRow = mysql_fetch_array($sql)) { $id = $aRow['id']; } } $this->memcached_library->add($key_cache, $id, 86400); $this->set_memcachekeys($key_cache); return $id; } else { return $get_color; } } function get_cartypes_srch_2($where, $emirate,$used_cars=0) { $carCategories = [ 'Crossover' => '10-*82-*Crossover cars are simply compact SUVs', 'Economy' => '28-*63-*Cheap, practical cars that make sense to hire', 'SUV' => '4-*58-*Sports Utility Vehicles are the most preferable in the UAE', 'Sports Car' => '7-*98-*Sports Utility Vehicles are the most preferable in the UAE', 'Luxury Car' => '8-*43-*Cars that complement Luxury Life', 'Monthly' => '36-*38-*Monthly Car Rental offers', 'Sedan' => '1-*32-*Sedans include comfy 4-door saloon cars', 'Compact' => '5-*15-*Looking for a small hatchback car?', 'Special Edition' => '29-*9-*Rent this limited edition rare car!', ]; return $carCategories; $key_cache = 'get_cartypes_srch_2023_new_1@' . $where . '@' . $emirate.$used_cars; // $this->memcached_library->delete($key_cache); $get_cartypes_srch_2 = $this->memcached_library->get($key_cache); if (!$get_cartypes_srch_2 && !is_numeric($get_cartypes_srch_2)) { // echo "select car_type , count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1' and emirate='$emirate' group by car_type order by count DESC"."
"; // exit(); try { $cartype_all = "select name,id,show_title from car_types "; $result = mysql_query($cartype_all); while ($aRow = mysql_fetch_array($result)) { $car_type_id = $aRow['id']; $car_type_name = $aRow['name']; $show_title = $aRow['show_title']; $count1 = 0; $count2 = 0; //echo "SELECT GROUP_CONCAT(id ) as id FROM `make` WHERE `cartype`='$car_type_id' or `cartype1`='$car_type_id' or `cartype2`='$car_type_id'"."
"; $query = $this->db->query("SELECT GROUP_CONCAT(id ) as id FROM `make` WHERE `cartype`='$car_type_id' or `cartype1`='$car_type_id' or `cartype2`='$car_type_id' or `cartype3`='$car_type_id'"); if ($query->num_rows() > 0) { $result2 = $query->row_array(); $makeid = trim($result2["id"], ","); // $makeid = trim($result2["id"],","); if ($makeid != "") { if($used_cars==0){ $cartypecount = "select count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1' and emirate='$emirate' and listings.client_id in (select client_id from `clients` where emirate like '%$emirate%') and ( car_make in ( SELECT id FROM `make` WHERE `cartype`='$car_type_id' or `cartype1`='$car_type_id' or `cartype2`='$car_type_id' or `cartype3`='$car_type_id' ) or (car_type=$car_type_id) ) "; } else { $cartypecount = "select count(*) count from usedcar_listings inner join clients on usedcar_listings.client_id=clients.client_id where $where and publish_ocd='1' and usedcar_listings.used_cars='$used_cars' and emirate='$emirate' and usedcar_listings.client_id in (select client_id from `clients` where emirate like '%$emirate%') and ( car_make in ( SELECT id FROM `make` WHERE `cartype`='$car_type_id' or `cartype1`='$car_type_id' or `cartype2`='$car_type_id' or `cartype3`='$car_type_id' ) or (car_type=$car_type_id) ) "; } //echo $cartypecount."
"; $query1 = $this->db->query($cartypecount); if ($query1->num_rows > 0) { $result3 = $query1->row_array(); $count2 = $result3["count"]; } } else { if($used_cars==0){ $cartypecount = "select count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1' and emirate='$emirate' and listings.client_id in (select client_id from `clients` where emirate like '%$emirate%') and (car_type=$car_type_id) "; } else { $cartypecount = "select count(*) count from usedcar_listings inner join clients on usedcar_listings.client_id=clients.client_id where $where and publish_ocd='1' and usedcar_listings.used_cars='$used_cars' and emirate='$emirate' and usedcar_listings.client_id in (select client_id from `clients` where emirate like '%$emirate%') and (car_type=$car_type_id) "; } $query1 = $this->db->query($cartypecount); if ($query1->num_rows > 0) { $result3 = $query1->row_array(); $count2 = $result3["count"]; } } } $count = $count1 + $count2; if ($count > 0) $list[$count][$car_type_name] = $car_type_id . "-*" . $count . "-*" . $show_title; } krsort($list); $data = []; foreach ($list as $res => $key) { foreach ($key as $keyarray => $dat) { $data[$keyarray] = $dat; } } } catch (Exception $e) { $data = []; } $this->memcached_library->add($key_cache, $data, 86400); $this->set_memcachekeys($key_cache); return $data; } else { return $get_cartypes_srch_2; } } function get_car_spec_list_search($where_all = 1,$usedcar = 0,$emirate="Dubai"){ $key_cache = 'get_car_spec_list2345453@' .$where_all.$usedcar.$emirate; // $get_client_detail = $this->memcached_library->get($key_cache); if (!$get_client_detail && !is_numeric($get_client_detail)) { $returnCarSpecs = []; $statement = "SELECT cs.car_spec_id specId, cs.car_spec_name specName, count(ul.id) listingCount FROM "; if($usedcar == 0){ $statement .= "`listings` ul "; }else{ $statement .= "`usedcar_listings` ul "; } $where_all= str_ireplace("usedcar_listings","ul",$where_all); $where_all= str_ireplace("listings","ul",$where_all); //added by nikhil to fix clients to cl as per above logic $where_all = str_replace("clients.airport_meetgreet", "cl.airport_meetgreet", $where_all); // Convert final where condition into query binding style for prevent the SQL Injection $where_final = $where_all ." and cl.emirate='$emirate' and ul.delete_status = 0 and ul.publish_ocd = 1 "; list($safe_conditions, $bind_array) = bind_where_condition($where_final); $statement .= " JOIN car_specs cs on cs.car_spec_id = ul.`car_spec_id` JOIN clients cl on cl.client_id=ul.client_id WHERE $safe_conditions GROUP by cs.car_spec_id ORDER BY CASE WHEN cs.car_spec_name = 'GCC Specs' THEN 0 ELSE 1 END, cs.car_spec_name ASC " ; // Run with with safe parmetrized query $query = $this->db->query($statement, $bind_array); echo $this->db->last_query(); die; $result = $query->result_array(); echo "\naaa".$statement; if(!empty($result)){ foreach($result as $record){ echo "
"; print_r($record); die;
                $returnCarSpecsTemp = [];
                $returnCarSpecsTemp['specId'] = $record['specId'];
                $returnCarSpecsTemp['specName'] = str_replace("Specs", "", $record['specName']);
                $returnCarSpecsTemp['listingCount'] = $record['listingCount'];

                array_push($returnCarSpecs, $returnCarSpecsTemp);
            }
        }

        $this->memcached_library->add($key_cache, $returnCarSpecs, 86400);
        $this->set_memcachekeys($key_cache);
        return $returnCarSpecs;
    }
    else
    {
        return $get_client_detail;
    }


       
        
    }
    function get_cartypes_srcharabic_2($where, $emirate)
    {
        $sql = "select car_type , count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1' and emirate='$emirate' group by car_type";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $car_type = $aRow['car_type'];

            $cartype = $this->get_name($car_type, "car_types", "name_arabic,show_title");
            $list[$cartype["name_arabic"]] = $car_type . "-*" . $aRow['count'] . "-*" . $cartype['show_title'];
        }

        return $list;
    }
    function get_cartypesid($where)
    {
        $sql = "select id from car_types where $where";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $ids[] = $aRow['id'];
        }

        return $ids;
    }
    function get_carmakeid($where)
    {
        $sql = "select id from models where $where";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $ids[] = $aRow['id'];
        }


        return $ids;
    }

    function get_caroptionid($where)
    {
        $sql = "select id from pickup_policy where $where";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $ids[] = $aRow['id'];
        }

        return $ids;
    }


    function get_carcompany($where)
    {
        $sql = "select client_id , count(*) count from listings where $where and publish_ocd='1' group by client_id";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $client_id = $aRow['client_id'];
            $client = $this->get_company($client_id, "clients", "company_name");
            $list[$client["company_name"]] = $client_id . "-" . $aRow['count'];
        }

        return $list;
    }
    function get_search_usedcar_carcompany($where, $emirate)
    {
        $key_cache = 'get_search_usedcar_carcompany1@' . $where . '@' . $emirate;
        $get_search_carcompany = $this->memcached_library->get($key_cache);
        if (!$get_search_carcompany && !is_numeric($get_search_carcompany)) {
           $sql = "select usedcar_listings.client_id , count(*) count from usedcar_listings INNER JOIN clients ON usedcar_listings.client_id=clients.client_id where $where and clients.emirate='$emirate' and publish_ocd='1' group by usedcar_listings.client_id";
            $result = mysql_query($sql) or die(mysql_error());
            while ($aRow = mysql_fetch_array($result)) {
                $client_id = $aRow['client_id'];
                $client = $this->get_company($client_id, "clients", "company_name");
                $list[$client["company_name"]] = $client_id . "-" . $aRow['count'];
            }
            $this->memcached_library->add($key_cache, $list, 86400);
            $this->set_memcachekeys($key_cache);
            return $list;
        } else {
            return $get_search_carcompany;
        }
    }
    function get_search_carcompany($where, $emirate,$used_cars=0)
    {
        $key_cache = 'get_search_carcompany3@' . $where . '@' . $emirate.$used_cars;
        $get_search_carcompany = $this->memcached_library->get($key_cache);
        if (!$get_search_carcompany && !is_numeric($get_search_carcompany)) {
            if($used_cars==0){
            $sql = "select listings.client_id , count(*) count from listings INNER JOIN clients ON listings.client_id=clients.client_id where $where and clients.emirate='$emirate' and publish_ocd='1' group by listings.client_id";
            }
            else {
                
                $sql = "select usedcar_listings.client_id , count(*) count from usedcar_listings INNER JOIN clients ON usedcar_listings.client_id=clients.client_id where $where and clients.emirate='$emirate' and (usedcar_listings.used_cars='1' OR usedcar_listings.used_cars='2') and publish_ocd='1' group by usedcar_listings.client_id";
                
            }
            $result = mysql_query($sql) or die(mysql_error());
            while ($aRow = mysql_fetch_array($result)) {
                $client_id = $aRow['client_id'];
                $client = $this->get_company($client_id, "clients", "company_name");
                $list[$client["company_name"]] = $client_id . "-" . $aRow['count'];
            }
            $this->memcached_library->add($key_cache, $list, 86400);
            $this->set_memcachekeys($key_cache);
            return $list;
        } else {
            return $get_search_carcompany;
        }
    }
    function get_client_more_rental($client) {
        $sql = "select more_rentals from clients where client_id = '$client'";
        $result = mysql_query($sql) or die(mysql_error());
        while ($aRow = mysql_fetch_array($result)) {
            $more_rentals = $aRow['more_rentals'];
        }

        return $more_rentals;
    }
    function get_search_carcompany_arabic($where, $emirate)
    {
        $sql = "select listings.client_id , count(*) count from listings INNER JOIN clients ON listings.client_id=clients.client_id where $where and clients.emirate='$emirate' and publish_ocd='1' group by listings.client_id";
        $result = mysql_query($sql) or die(mysql_error());
        while ($aRow = mysql_fetch_array($result)) {
            $client_id = $aRow['client_id'];
            $client = $this->get_company($client_id, "clients", "company_name_arabic");
            $list[$client["company_name_arabic"]] = $client_id . "-" . $aRow['count'];
        }

        return $list;
    }
    function get_carcompanyid($where)
    {
        $sql = "select id from clients where $where";
        $result = mysql_query($sql);
        $rows = mysql_fetch_assoc($result);
        return $rows;
    }
    function get_all_usedcar_clients($where = null)
    {
        if($where != null) {
            $sql = $this->db->query("SELECT `client_id`,`company_name`,`limit_number`,`emirate` FROM `clients` WHERE more_rentals = 5 $where");
        } else {
            $sql = $this->db->query("SELECT `client_id`,`company_name`,`limit_number`,`emirate` FROM `clients` WHERE more_rentals = 5");
        }
        $rows = [];
        $results = $sql->result();
        $k = 0;
        if ($results) {
            foreach ($results as $res) {
                $rows[$k]['client_id']     = $res->client_id;
                $rows[$k]['company_name'] = $res->company_name;
                $rows[$k]['emirate']     = $res->emirate;

                $sql8=mysql_query("select * from usedcar_listings where client_id='$res->client_id' and publish_ocd='1' and delete_status='0'") or die(mysql_error());
                $rows[$k]['total_listings']=mysql_num_rows($sql8);
                $rows[$k]['total_client_listing']=$res->limit_number;
                $k++;
            }
        }
        return $rows;
    }
    function get_all_clients()
    {
        $sql = $this->db->query("SELECT `client_id`,`company_name` FROM `clients`   ");
        $rows = [];
        $results = $sql->result();
        $k = 0;
        if ($results) {
            foreach ($results as $res) {
                $rows[$k]['client_id']     = $res->client_id;
                $rows[$k]['company_name'] = $res->company_name;

                $k++;
            }
        }
        return $rows;
    }
    function get_all_clients_display()
    {
        $sql = $this->db->query("SELECT `client_id`,`company_name` FROM `clients`   ");
        $rows = [];
        $results = $sql->result();
        $k = 0;
        if ($results) {
            foreach ($results as $res) {
                // $rows[$k]['client_id']     =$res->client_id;
                $rows[$res->client_id] = $res->company_name;

                $k++;
            }
        }
        return $rows;
    }

    function getbuggy_carscount($where)
    {
        $key_cache = 'getbuggy_carscount@' . $where;
        //$this->memcached_library->delete($key_cache);
        $getbuggy_carscount = $this->memcached_library->get($key_cache);
        if (!$getbuggy_carscount && !is_numeric($getbuggy_carscount)) {

            $sql = "select count(*) count from buggy_listing inner join clients on buggy_listing.client_id=clients.client_id where $where and car_type = '32' and publish_ocd='1'";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $getbuggy_carscount;
        }
    }
    function get_carscount($where=null,$used_cars=0)
    {
        $key_cache = 'get_carscount24@' . $where.$used_cars;
        //$this->memcached_library->delete($key_cache);
        $get_carscount = $this->memcached_library->get($key_cache);
        if (!$get_carscount && !is_numeric($get_carscount)) {
if($used_cars==0)
{
           $sql = "select count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and used_cars='$used_cars' and publish_ocd='1'";
           }
           else{
            $sql = "select count(*) count from usedcar_listings inner join clients on listings.client_id=clients.client_id where $where and used_cars='$used_cars' and publish_ocd='1'";
            }
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_carscount;
        }
    }
    function get_carscount_home($where)
    {
        $key_cache = 'get_carscounts1234@' . $where;
        $get_carscount = $this->memcached_library->get($key_cache);
        if (!$get_carscount && !is_numeric($get_carscount)) {
            //    $sql = "select count(*) count from listings where $where and  and publish_ocd='1' and delete_status='0'";
            $sql = "select count(*) count from listings where delete_status = 0 and car_type != 2 and daily_price_status='1' and listings.client_id in (select client_id from `clients` where emirate like '%Dubai%') and listings.client_id!=247 and publish_ocd='1'  ";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_carscount;
        }
    }
    function get_premcarscount()
    {
        $key_cache = 'get_premcarscount';
        $get_premcarscount = $this->memcached_library->get($key_cache);
        if (!$get_premcarscount && !is_numeric($get_premcarscount)) {
            $sql = "select count(*) count from listings INNER JOIN clients on listings.client_id=clients.client_id where  delete_status = 0 and publish_ocd='1' and daily_price >= 400 and emirate='Dubai'";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_premcarscount;
        }
    }
    function get_sportscount_home()
    {
        $key_cache = 'get_sportscount_home7';
        $get_sportscount = $this->memcached_library->get($key_cache);
        if (!$get_sportscount && !is_numeric($get_sportscount)) {

            /* $query_make      =   $this->db->query("SELECT GROUP_CONCAT(id ) as id FROM `make` WHERE  `cartype` in (7) or  `cartype1` in (7) or `cartype2` in (7) ");
        $makeid =  "";
        
        if($query_make->num_rows() > 0){
            $result =   $query_make->row_array();
          
            $makeid =  $result["id"];
        }
        
    $sql = "select  count(*) count from listings where delete_status = 0 and car_type != 2 and daily_price_status='1' and
    (car_make in ($makeid) or
      (car_type='7')or car_make in (SELECT id from make where doors='2') 
      and car_type NOT IN ('3','9','11','14')or
       (keywords like '%Convertible%' or keywords like '%gtc%' or keywords like '%dawn%' or keywords like '%cabriolet%' or
        keywords like '%grancabrio%' or keywords like '%spyder%' or car_make='481' or car_make='438')) and 
        listings.client_id in (select client_id from `clients` where emirate like '%Dubai%') and 
        listings.client_id!=247 and publish_ocd='1' ";
       
    $result = mysql_query($sql);
    $aRow = mysql_fetch_array($result);
    $count = $aRow['count']  ;
    $this->memcached_library->add($key_cache, $count, 3600);
    $this->set_memcachekeys($key_cache);
    return $count;*/
            //$sql = "select  count(*) count  from listings inner join make on listings.car_make=make.id where publish_ocd='1' and delete_status = 0 and listings.car_type != 2 and daily_price_status='1' and (make.cartype in (7) or  make.cartype1 in (7) or make.cartype2 in (7)) and client_id in (select client_id from clients where emirate='Dubai')";
            $sql = "select count(*) count from listings inner join clients on listings.client_id=clients.client_id where delete_status = 0 and car_type != 2 and daily_price_status='1' and (car_make in (SELECT id FROM `make` WHERE `cartype` in (7) or `cartype1` in (7) or `cartype2` in (7) or `cartype3` in (7)) or car_type='7' ) and clients.emirate like '%Dubai%' and ( IF(`daily_price_offer` != '=', daily_price_offer >='850', daily_price >= 850) and daily_price!='0') and listings.client_id!=247 and publish_ocd='1'";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_sportscount;
        }
    }

    function get_luxurycount()
    {
        $key_cache = 'get_luxurycount9';
        $get_premcarscount = $this->memcached_library->get($key_cache);
        if (!$get_premcarscount && !is_numeric($get_premcarscount)) {

            /*   $query_make      =   $this->db->query("SELECT GROUP_CONCAT(id ) as id FROM `make` WHERE  `cartype` in (4,8) or  `cartype1` in (4,8) or `cartype2` in (4,8) ");
			$makeid =  "";
			
			if($query_make->num_rows() > 0){
                $result =   $query_make->row_array();
              
                $makeid =  $result["id"];
            }
           $makeid=$makeid.'0'; 

        $sql = "select  count(*) count  from listings where delete_status = 0 and car_type != 2 and daily_price_status='1' and 
        (car_make in ($makeid)
         or (car_type='4,8') 
         or car_make in (SELECT id from make where doors='2') and car_type NOT IN ('3','9','11','14') or
          (keywords like '%Convertible%' or keywords like '%gtc%' or keywords like '%dawn%' or keywords like '%cabriolet%' or keywords like '%grancabrio%' or keywords like '%spyder%' or car_make='481' or car_make='438')) and
           listings.client_id in (select client_id from `clients` where emirate like '%Dubai%') and
            daily_price >= 800 and daily_price!='0' and listings.client_id!=247 and publish_ocd='1'";*/
            $sql = "select count(*) count from listings inner join clients on listings.client_id=clients.client_id where delete_status = 0 and car_type != 2 and daily_price_status='1' and (car_make in (SELECT id FROM `make` WHERE `cartype` in (8) or `cartype1` in (8) or `cartype2` in (8) or `cartype3` in (8)) or car_type='8' ) and clients.emirate like '%Dubai%' and ( IF(`daily_price_offer` != '=', daily_price_offer >='850', daily_price >= 850) and daily_price!='0') and listings.client_id!=247 and publish_ocd='1'";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_premcarscount;
        }
    }
    function get_sportscount()
    {
        $key_cache = 'get_sportscount';
        $get_sportscount = $this->memcached_library->get($key_cache);
        if (!$get_sportscount && !is_numeric($get_sportscount)) {
            $sql = "select count(*) count from listings INNER JOIN clients on listings.client_id=clients.client_id where  delete_status = 0 and publish_ocd='1' and car_type = '7' and emirate='Dubai'";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_sportscount;
        }
    }

    function get_carmake($where)
    {
        $key_cache = 'get_carmake@' . $where;
        $get_carmake = $this->memcached_library->get($key_cache);
        if (!$get_carmake && !is_numeric($get_carmake)) {
            $sql = "select car_model , count(*) count from listings where $where and publish_ocd='1' group by car_model";
            $result = mysql_query($sql);
            while ($aRow = mysql_fetch_array($result)) {
                $car_make = $aRow['car_model'];
                $carmake = $this->get_name($car_make, "models", "name");
                $list[$carmake["name"]] = $car_make . "-" . $aRow['count'];
            }
            $this->memcached_library->add($key_cache, $list, 86400);
            $this->set_memcachekeys($key_cache);
            return $list;
        } else {
            return $get_carmake;
        }
    }
    function get_carmake_arabic($where)
    {
        $sql = "select car_model , count(*) count from listings where $where and publish_ocd='1' group by car_model";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $car_make = $aRow['car_model'];
            $carmake = $this->get_name($car_make, "models", "name_arabic");
            $list[$carmake["name_arabic"]] = $car_make . "-" . $aRow['count'];
        }

        return $list;
    }
    function get_carmodel($id)
    {
        $sql = "select car_make , count(*) count from listings where car_model = '$id' and publish_ocd='1' group by car_make";
        $result = mysql_query($sql);
        while ($aRow = mysql_fetch_array($result)) {
            $car_make = $aRow['car_make'];
            $carmake = $this->get_name($car_make, "make", "name");
            $list[$carmake["name"]] = $car_make;
        }

        return $list;
    }
    function get_area($emirate,$used_cars=0)
    {
        $key_cache = 'get_area@' . $emirate.$used_cars;
        $get_area = $this->memcached_library->get($key_cache);
        if (!$get_area && !is_numeric($get_area)) {
            if($used_cars==0)
            {
            $sql = "select location from clients inner join listings on clients.client_id=listings.client_id where publish_ocd='1' and emirate ='$emirate' and location!='' group by location order by location asc";
            }
            else
            {
            $sql = "select location from clients inner join usedcar_listings on clients.client_id=usedcar_listings.client_id where publish_ocd='1' and emirate ='$emirate' and usedcar_listings.used_cars='$used_cars' and location!='' group by location order by location asc";
            }
            $result = mysql_query($sql);
            while ($aRow = mysql_fetch_array($result)) {
                $loc = $aRow['location'];
                $array =  explode('*', $loc);
                foreach ($array as $key => $value) {
                    if (in_array($value, $dup)) {
                        continue;
                    }
                    $list[$value] = $value;
                }
                $dup[] = $value;
            }
            $this->memcached_library->add($key_cache, $list, 86400);
            $this->set_memcachekeys($key_cache);
            return $list;
        } else {
            return $get_area;
        }
    }
    function get_cardelv($where,$used_cars=0)
    {
        $key_cache = 'get_cardelv@' . $where.$used_cars;
        $get_cardelv = $this->memcached_library->get($key_cache);
        if (!$get_cardelv && !is_numeric($get_cardelv)) {
            if($used_cars==0)
            {
            $sql = "select pick_up , count(*) count from listings where $where and publish_ocd='1' group by pick_up";
            }
            else
            {
                $sql = "select pick_up , count(*) count from usedcar_listings where $where and usedcar_listings.used_cars='$used_cars' and publish_ocd='1' group by pick_up";    
            }
            $result = mysql_query($sql);
            while ($aRow = mysql_fetch_array($result)) {
                $pick_up = $aRow['pick_up'];
                $pickup = $this->get_name($pick_up, "pickup_policy", "name");
                $list[$pickup["name"]] = $pick_up . "-" . $aRow['count'];
            }
            $this->memcached_library->add($key_cache, $list, 86400);
            $this->set_memcachekeys($key_cache);
            return $list;
        } else {
            return $get_cardelv;
        }
    }

    function get_transmission($where,$used_cars=0)
    {
        $key_cache = 'get_transmission@' . $where.$used_cars;
        $get_transmission = $this->memcached_library->get($key_cache);
        if (!$get_transmission && !is_numeric($get_transmission)) {
            if($used_cars==0)
            {
                $sql = "select transmission , count(*) count from listings where $where and publish_ocd='1' group by transmission";
            
            }
            else{
                $sql = "select transmission , count(*) count from usedcar_listings where $where and used_cars='$used_cars' and publish_ocd='1' group by transmission";
            
            }
           $result = mysql_query($sql);
            while ($aRow = mysql_fetch_array($result)) {
                $transmission = $aRow['transmission'];
                $transmission = $this->get_name($transmission, "transmission", "name");
                $list[$transmission["name"]] = $aRow['transmission'] . "-" . $aRow['count'];
            }
            $this->memcached_library->add($key_cache, $list, 86400);
            $this->set_memcachekeys($key_cache);
            return $list;
        } else {
            return $get_transmission;
        }
    }

    function getbuggy_cars_count($where)
    {
        $key_cache = 'getbuggy_cars_count@' . $where;
        $getbuggy_cars_count = $this->memcached_library->get($key_cache);
        // $this->memcached_library->delete($key_cache);
        if (!$getbuggy_cars_count && !is_numeric($getbuggy_cars_count)) {
            $sql = "select  count(*) count from buggy_listing inner join clients on buggy_listing.client_id=clients.client_id where $where and car_type = '32' and publish_ocd='1'";

            $result = mysql_query($sql) or die(mysql_error());
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $getbuggy_cars_count;
        }
    }

    function get_cars_count($where,$used_cars=0)
    {
        $key_cache = 'get_cars_count120@' . $where.$used_cars;
        $get_cars_count = $this->memcached_library->get($key_cache);
        // $this->memcached_library->delete($key_cache);
        if (!$get_cars_count && !is_numeric($get_cars_count)) {
            if($used_cars==0)
            {
            $sql = "select  count(*) count from listings inner join clients on listings.client_id=clients.client_id where $where and publish_ocd='1'";
            }
            else
            {
                $sql = "select  count(*) count from usedcar_listings inner join clients on usedcar_listings.client_id=clients.client_id where $where and usedcar_listings.used_cars='$used_cars' and publish_ocd='1'";   
            }
            $result = mysql_query($sql) or die(mysql_error());
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_cars_count;
        }
    }
    function get_cars_coupecount($emirate,$used_cars=0)
    {
        $key_cache = 'get_cars_coupecount@' . $emirate.$used_cars;
        $get_cars_coupecount = $this->memcached_library->get($key_cache);
        if (!$get_cars_coupecount && !is_numeric($get_cars_coupecount)) {
            if($used_cars==0)
            {
            $sql = "select  count(*) count from make inner join listings on make.id=listings.car_make inner join clients on clients.client_id=listings.client_id where make.doors='2' and listings.publish_ocd='1' and listings.delete_status='0' and clients.emirate='$emirate' ";
            }
            else
            {
            $sql = "select  count(*) count from make inner join usedcar_listings on make.id=usedcar_listings.car_make inner join clients on clients.client_id=usedcar_listings.client_id where make.doors='2' and usedcar_listings.used_cars='$used_cars' and usedcar_listings.publish_ocd='1' and usedcar_listings.delete_status='0' and clients.emirate='$emirate' ";
             }
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_cars_coupecount;
        }
    }
    function get_cars_convert($emirate,$used_cars=0)
    {
        $key_cache = "get_cars_convert@" . $emirate.$used_cars;
        $cars_convert = $this->memcached_library->get($key_cache);
        if (!$cars_convert && !is_numeric($cars_convert)) {
            if($used_cars==0)
            {
            $sql = "select  count(*) count from listings inner join clients on listings.client_id=clients.client_id where keywords like '%Convertible%' and publish_ocd='1' and delete_status='0' and emirate='$emirate'";
            }
            else
            {
                $sql = "select  count(*) count from usedcar_listings inner join clients on usedcar_listings.client_id=clients.client_id where keywords like '%Convertible%' and publish_ocd='1'and usedcar_listings.used_cars='$used_cars' and delete_status='0' and emirate='$emirate'";
            }
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['count'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $cars_convert;
        }
    }

    function get_cars_ids()
    {
        $key_cache = "get_cars_ids";
        $get_cars_ids = $this->memcached_library->get($key_cache);
        if (!$get_cars_ids && !is_numeric($get_cars_ids)) {
            $sql = "select ids from ids";
            $result = mysql_query($sql);
            $aRow = mysql_fetch_array($result);
            $count = $aRow['ids'];
            $this->memcached_library->add($key_cache, $count, 86400);
            $this->set_memcachekeys($key_cache);
            return $count;
        } else {
            return $get_cars_ids;
        }
    }

    function insert_newsletter($newsletter)
    {
        $sql = "insert into newsletter (email) values ('" . mysql_real_escape_string($newsletter) . "')";
        mysql_query($sql);
    }
    function insert_contact($post)
    {
        $ip = $this->get_your_ip();
        echo $sql = "insert into contact (id,name,email,phone,message,ip) values ('',
    '" . mysql_real_escape_string($post["NAME"]) . "',
    '" . mysql_real_escape_string($post["EMAIL"]) . "',
    '" . mysql_real_escape_string($post["MOBILE"]) . "',
    '" . mysql_real_escape_string($post["NOTE"]) . "',
    '" . mysql_real_escape_string($ip) . "'
    )";
        mysql_query($sql);
    }
    function check_ip_full_day($ip,$used_cars=0,$table='email_sms')
    {
        $date=date("Y-m-d");
   $sql = mysql_query("select count(*) as count from $table where ip='$ip' and usedcar='$used_cars' and date(`time`)='$date'") or die(mysql_error());
$count=mysql_fetch_array($sql);
return $count['count'];

    }
    function track_click_phone($listing_id, $client_id)
    {
        $date_today=date('Y-m-d');
        $ip = $this->get_your_ip();
        

       $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
       if($check_full_day_leads > 60)
       {
        $daily_spam='1'; 
       }
else if(!empty($ip))
        {
            $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and date(`time`)='$date_today'");
            if(mysql_num_rows($check_spam_ip)>0){
                $i=0;
            while($spam = mysql_fetch_array($check_spam_ip))
            {
               
                $expiry_time = new DateTime($spam['time']);
                $current_date = new DateTime();
                $diff = $expiry_time->diff($current_date);
               $hour=$diff->format('%h');
               $minute=$diff->format('%i'); 
             if(($hour==1 && $minute<5) || ($hour==0))
             {
             $i++;
             }
            }
            $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
    
    
        $sql = "insert into email_sms(client_id,listing_id,type,ip,daily_spam,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_phone2($listing_id, $client_id, $featured_listing, $best_offer_listing)
    {
        $ip = $this->get_your_ip();
        $date_today=date('Y-m-d');
        $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
        else if(!empty($ip))
        {
            $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and date(`time`)='$date_today'");
            if(mysql_num_rows($check_spam_ip)>0){
                $i=0;
            while($spam = mysql_fetch_array($check_spam_ip))
            {
               
                $expiry_time = new DateTime($spam['time']);
                $current_date = new DateTime();
                $diff = $expiry_time->diff($current_date);
               $hour=$diff->format('%h');
               $minute=$diff->format('%i'); 
             if(($hour==1 && $minute<5) || ( $hour==0))
             {
             $i++;
               }
            }
            $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        $sql = "insert into email_sms(client_id,listing_id,type,ip,featured_listing,best_offer_listing,daily_spam,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_phone5($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
        $date_today=date('Y-m-d');
        $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
        {
            $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and date(`time`)='$date_today'");
            if(mysql_num_rows($check_spam_ip)>0){
                $i=0;
            while($spam = mysql_fetch_array($check_spam_ip))
            {
               
                $expiry_time = new DateTime($spam['time']);
                $current_date = new DateTime();
                $diff = $expiry_time->diff($current_date);
               $hour=$diff->format('%h');
               $minute=$diff->format('%i'); 
             if(($hour==1 && $minute<5) || ( $hour==0))
             {
             $i++;
               }
            }
            $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
		  if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
			$user_id = $this->session->userdata("userr_id");
		}
        $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,daily_spam,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_phone55_usedcar($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium, $month_lead)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
        $date_today=date('Y-m-d');
       
        $check_full_day_leads= $this->check_ip_full_day($ip,1,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
        {
        $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and usedcar = '1' and ip='$ip' and date(`time`)='$date_today'");
        if(mysql_num_rows($check_spam_ip)>0){
            $i=0;
        while($spam = mysql_fetch_array($check_spam_ip))
        {
           
            $expiry_time = new DateTime($spam['time']);
            $current_date = new DateTime();
            $diff = $expiry_time->diff($current_date);
           $hour=$diff->format('%h');
           $minute=$diff->format('%i'); 
         if(($hour==1 && $minute<5) || ( $hour==0))
         {
         $i++;
           }
        }
        $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
            $user_id = $this->session->userdata("userr_id");
        }
        $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,month_lead,daily_spam,usedcar,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'" . mysql_real_escape_string($month_lead)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'1'" . ","
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_phone55($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium, $month_lead, $hourly = 0)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
        $date_today=date('Y-m-d');
       
        $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
        {
        $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and date(`time`)='$date_today'");
        if(mysql_num_rows($check_spam_ip)>0){
            $i=0;
        while($spam = mysql_fetch_array($check_spam_ip))
        {
           
            $expiry_time = new DateTime($spam['time']);
            $current_date = new DateTime();
            $diff = $expiry_time->diff($current_date);
           $hour=$diff->format('%h');
           $minute=$diff->format('%i'); 
         if(($hour==1 && $minute<5) || ( $hour==0))
         {
         $i++;
           }
        }
        $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
            $user_id = $this->session->userdata("userr_id");
        }
        $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,month_lead,daily_spam,time,is_hourly) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'" . mysql_real_escape_string($month_lead)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "',"
            ."'".$hourly."'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }

    function track_usedcar_click_phone55($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium, $month_lead)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
        $date_today=date('Y-m-d');
       
        $check_full_day_leads= $this->check_ip_full_day($ip,1,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
        {
        $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and usedcar = '1' and date(`time`)='$date_today'");
        if(mysql_num_rows($check_spam_ip)>0){
            $i=0;
        while($spam = mysql_fetch_array($check_spam_ip))
        {
           
            $expiry_time = new DateTime($spam['time']);
            $current_date = new DateTime();
            $diff = $expiry_time->diff($current_date);
           $hour=$diff->format('%h');
           $minute=$diff->format('%i'); 
         if(($hour==1 && $minute<5) || ( $hour==0))
         {
         $i++;
           }
        }
        $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
            $user_id = $this->session->userdata("userr_id");
        }
        $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,month_lead,daily_spam,usedcar,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'" . mysql_real_escape_string($month_lead)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'1'" . ","
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }

    function track_click_phone4($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat)
    {
        $ip = $this->get_your_ip();
        $date_today=date('Y-m-d');
        $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
        {
            $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and date(`time`)='$date_today'");
            if(mysql_num_rows($check_spam_ip)>0){
                $i=0;
            while($spam = mysql_fetch_array($check_spam_ip))
            {
               
                $expiry_time = new DateTime($spam['time']);
                $current_date = new DateTime();
                $diff = $expiry_time->diff($current_date);
               $hour=$diff->format('%h');
               $minute=$diff->format('%i'); 
             if(($hour==1 && $minute<5) || ( $hour==0))
             {
             $i++;
               }
            }
            $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        $sql = "insert into email_sms(client_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,daily_spam,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_phone3($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification)
    {
        $ip = $this->get_your_ip();
        $date_today=date('Y-m-d');
        $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
        {
            $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='2' and ip='$ip' and date(`time`)='$date_today'");
            if(mysql_num_rows($check_spam_ip)>0){
                $i=0;
            while($spam = mysql_fetch_array($check_spam_ip))
            {
               
                $expiry_time = new DateTime($spam['time']);
                $current_date = new DateTime();
                $diff = $expiry_time->diff($current_date);
               $hour=$diff->format('%h');
               $minute=$diff->format('%i'); 
             if(($hour==1 && $minute<5) || ( $hour==0))
             {
             $i++;
               }
            }
            $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        $sql = "insert into email_sms(client_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,daily_spam,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'2'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function check_user_lead_count()
    {
        $ip = $this->get_your_ip();
        $trackids = mysql_query("select id from email_sms  where ip='$ip' group by client_id");
        $trackid = mysql_fetch_array($trackids);
        return ($trackid);
    }
    function track_click_whatsapp5_offer($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
        if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
          $user_id = $this->session->userdata("userr_id");
      }
      $date_today=date('Y-m-d');
      $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
      {
        $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='5' and ip='$ip' and date(`time`)='$date_today'");
        if(mysql_num_rows($check_spam_ip)>0){
            $i=0;
        while($spam = mysql_fetch_array($check_spam_ip))
        {
           
            $expiry_time = new DateTime($spam['time']);
            $current_date = new DateTime();
            $diff = $expiry_time->diff($current_date);
           $hour=$diff->format('%h');
           $minute=$diff->format('%i'); 
         if(($hour==1 && $minute<5) || ( $hour==0))
         {
         $i++;
           }
        }
        $dailyspam = $i;
      if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
      $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,whatsapp_offer,daily_spam,time) values ("
          . "'" . mysql_real_escape_string($client_id) . "',"
          . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'5'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'1'" . ","
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_whatsapp5($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
		  if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
			$user_id = $this->session->userdata("userr_id");
		}
        $date_today=date('Y-m-d');
        $check_full_day_leads= $this->check_ip_full_day($ip,0,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
      {
        $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='5' and ip='$ip' and date(`time`)='$date_today'");
        if(mysql_num_rows($check_spam_ip)>0){
            $i=0;
        while($spam = mysql_fetch_array($check_spam_ip))
        {
           
            $expiry_time = new DateTime($spam['time']);
            $current_date = new DateTime();
            $diff = $expiry_time->diff($current_date);
           $hour=$diff->format('%h');
           $minute=$diff->format('%i'); 
         if(($hour==1 && $minute<5) || ( $hour==0))
         {
         $i++;
           }
        }
        $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,daily_spam,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'5'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_whatsapp_desert($id, $price, $name, $transfer_option, $adult_count, $child_count, $infant_count, $pickup){
        $ip = $this->get_your_ip();
        $user_id = 0;
		  if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
			$user_id = $this->session->userdata("userr_id");
		}
        
        $sql = "insert into email_sms_desert(user_id,listing_id,ip,price,safari_name,transfer_option,adult_count,child_count,infant_count,pickupdate,time) values ("
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($id) . "',"
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($price)  . "',"
            . "'" . mysql_real_escape_string($name)  . "',"
            . "'" . mysql_real_escape_string($transfer_option) . "',"
            . "'" . mysql_real_escape_string($adult_count) . "',"
            . "'" . mysql_real_escape_string($child_count)  . "',"
            . "'" . mysql_real_escape_string($infant_count)  . "',"
            . "'" . mysql_real_escape_string($pickup)  . "',"
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_whatsapp55_usedcar($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium,$month_lead)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
		  if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
			$user_id = $this->session->userdata("userr_id");
		}
        $date_today=date('Y-m-d');
        $check_full_day_leads= $this->check_ip_full_day($ip,1,'email_sms');
        if($check_full_day_leads > 60)
        {
         $daily_spam='1'; 
        }
 else if(!empty($ip))
      {
        $check_spam_ip=mysql_query("select time from `email_sms` where listing_id='$listing_id' and type='5' and ip='$ip' and usedcar = '1' and date(`time`)='$date_today'");
        if(mysql_num_rows($check_spam_ip)>0){
            $i=0;
        while($spam = mysql_fetch_array($check_spam_ip))
        {
           
            $expiry_time = new DateTime($spam['time']);
            $current_date = new DateTime();
            $diff = $expiry_time->diff($current_date);
           $hour=$diff->format('%h');
           $minute=$diff->format('%i'); 
         if(($hour==1 && $minute<5) || ( $hour==0))
         {
         $i++;
           }
        }
        $dailyspam = $i;
        if($dailyspam>=2)
      {
        $daily_spam='1';
      }
      else
      {
        $daily_spam='0';
      }
    }
    else
      {
        $daily_spam='0';
      }
     }
        else
        {
        $daily_spam='0';
        }
        $sql = "insert into email_sms(client_id,user_id,listing_id,type,ip,featured_listing,best_offer_listing,verified_listing,price_stat,premium_listing,month_lead,daily_spam,usedcar,time) values ("
            . "'" . mysql_real_escape_string($client_id) . "',"
            . "'" . mysql_real_escape_string($user_id) . "',"
            . "'" . mysql_real_escape_string($listing_id) . "',"
            . "'5'" . ","
            . "'" . mysql_real_escape_string($ip)  . "',"
            . "'" . mysql_real_escape_string($featured_listing)  . "',"
            . "'" . mysql_real_escape_string($best_offer_listing)  . "',"
            . "'" . mysql_real_escape_string($verification)  . "',"
            . "'" . mysql_real_escape_string($price_stat)  . "',"
            . "'" . mysql_real_escape_string($premium)  . "',"
            . "'" . mysql_real_escape_string($month_lead)  . "',"
            . "'" . mysql_real_escape_string($daily_spam)  . "',"
            . "'1'" . ","
            . "'" . date('Y-m-d H:i:s') . "'"

            . ")";
        //echo $sql;
        mysql_query($sql);
    }
    function track_click_whatsapp55($listing_id, $client_id, $featured_listing, $best_offer_listing, $verification, $price_stat, $premium,$month_lead,$hourly=0)
    {
        $ip = $this->get_your_ip();
        $user_id = 0;
		  if(isset($_COOKIE['void']) && $this->session->userdata("userr_id") != ""){
			$user_id = $this->session->userdata("userr_id")