"; } });*/ require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php"); set_time_limit(0); ini_set('memory_limit', '8192M'); /*if(isset($_POST['dev'])){ ini_set('display_errors', 1); error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); }*/ $start = microtime(true); if ($_SESSION['id']) { $get = clearInputData($_GET); $post = clearInputData($_POST); // Определяем: запрос пришёл со страницы поиска (sale.php / main.php / new-main.php) $refererPath = isset($_SERVER['HTTP_REFERER']) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH) : ''; $searchPages = ['/sale.php', '/main.php', '/new-main.php']; if (in_array($refererPath, $searchPages)) { $isSearch = true; } $gmtmsk = get_time_zone_user(); $time_zone = ''; if($gmtmsk >= 0){ $time_zone = '+'.$gmtmsk.' hour'; } else { $time_zone = '-'.$gmtmsk.' hour'; } if ($post['view'] !== 'table') { $_SESSION['list_view'] = 1; unset($_SESSION['table_view']); } else { $_SESSION['table_view'] = 1; unset($_SESSION['list_view']); } $_SESSION['myObjectsView'] = 1; unset($_SESSION['agencyObjectsView']); $db_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306'); if (isset($post['id_agent']) && $post['id_agent']) { $user_view = new User; $user_view->get($post['id_agent']); } $currentUser = new User; $currentUser->get($_SESSION['id']); if (!isset($currentUser->agencyId)) { $currentUser->agencyId = $_SESSION['id']; $currentUser->agencyName = $currentUser->agency_name; } //архив типов договоров $contract = new Contract(); $contract->setAgencyId($currentUser->agencyId); $typesContracs = $contract->getTypesName(); $db = new MysqlPdo(hstsph, null, null, null, true, '9306'); $showAvitoSwitcher = false; $showCianSwitcher = false; $showEmslSwitcher = false; $showBnSwitcher = false; $showZipalSwitcher = true; $showYandexSwitcher = true; $showDomSwitcher = true; $sqlForAvitoSwitcher = "SELECT id FROM `users` WHERE id in (8771, 8681, 8702, 8669, 8519, 8499, 8524, 8271, 7945, 8410, 8307, 8222, 8317, 8259, 7929, 8133, 7846, 8128, 8080, 7941, 7927, 7949, 7920, 7933, 7730, 7861, 7811, 7828, 7811, 1543, 7705, 5274, 7605, 7598, 6755, 7441, 7225, 7322, 7325, 7321, 7161, 7255, 7254, 7253, 7252, 7251, 7249, 7289, 7248, 7245, 6531, 6841, 7156, 7102, 7078, 6998, 7142, 5530, 6995, 6793, 6935, 6916, 6876, 6917, 6858, 5427, 4, 93, 117, 4255, 4355, 920, 4826, 4112, 5598, 5766, 6007, 6358, 6370, 6730, 177, 6781, 6782) or id_manager in (8271, 7945, 8410, 8307, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5598, 93, 6858, 5530, 7248) or id_manager in (select id from users where id_manager in (8271, 7945, 8410, 8307, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5598, 93, 6858, 5530, 7248))"; $rezForAvitoSwitcher = mysql_query($sqlForAvitoSwitcher); while($userId = mysql_fetch_assoc($rezForAvitoSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showAvitoSwitcher = true; break; } } $sqlForCianSwitcher = "SELECT id FROM `users` WHERE id in (8771, 8681, 8702, 8669, 8519, 8499, 8524, 8271, 8410, 7507, 8307, 8285, 8222, 8317, 8259, 7929, 8133, 7846, 8128, 8080, 7941, 7927, 7949, 7920, 7933, 7730, 7861, 7811, 7828, 7811, 1543, 7705, 5274, 7605, 7598, 6755, 7441, 7225, 7325, 7321, 7161, 7255, 7254, 7253, 7252, 7251, 7249, 4101, 7248, 7245, 6531, 6841, 7156, 7102, 7078, 7142, 5530, 4, 93, 117) or id_manager in (8271, 8410, 7507, 8307, 8285, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5530, 7248) or id_manager in (select id from users where id_manager in (8271, 8410, 7507, 8307, 8285, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5530, 7248))"; $rezForCianSwitcher = mysql_query($sqlForCianSwitcher); while($userId = mysql_fetch_assoc($rezForCianSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showCianSwitcher = true; break; } } $sqlForEmslSwitcher = "SELECT id FROM `users` WHERE id in (8771, 8681, 8702, 8669, 8519, 8499, 8524, 8271, 7945, 8410, 8307, 8222, 8317, 8259, 7929, 8133, 7846, 8128, 8080, 7941, 7927, 7949, 7920, 7933, 7730, 7861, 7811, 7828, 7811, 1543, 7705, 5274, 7605, 7598, 5530, 6755, 7441, 7225, 7325, 7321, 7161, 7255, 7254, 7253, 7252, 7251, 7249, 7248, 7245, 6531, 6841, 6747, 7156, 7102, 7078, 7142, 6793, 6935, 6916, 6876, 6917, 6858, 5427, 4, 93, 117, 4255, 4355, 920, 4826, 4112, 5598, 5766, 6007, 6358, 6370, 6730, 177, 6781, 6782, 6842, 5238) or id_manager in (8271, 7945, 8410, 8307, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5598, 93, 6358, 6858, 7248) or id_manager in (select id from users where id_manager in (8271, 7945, 8410, 8307, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5598, 93, 6358, 6858, 7248))"; $rezForEmslSwitcher = mysql_query($sqlForEmslSwitcher); while($userId = mysql_fetch_assoc($rezForEmslSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showEmslSwitcher = true; break; } } $sqlForBnSwitcher = "SELECT id FROM `users` WHERE id in (8771, 8681, 8702, 8669, 8519, 8499, 8524, 8271, 8410, 8307, 8285, 8222, 8317, 8259, 7929, 8133, 7846, 8128, 8080, 7941, 7927, 7949, 7920, 7933, 7730, 7861, 7811, 7828, 7811, 1543, 7705, 5274, 7605, 7598, 5530, 6755, 7441, 7225, 7325, 7321, 7161, 7255, 7254, 7253, 7252, 7251, 7249, 7248, 7245, 6531, 6841, 7156, 7102, 7078, 7142, 6995, 6793, 6935, 6916, 6876, 6917, 6858, 5427, 4, 93, 117, 4255, 4355, 920, 4826, 4112, 5598, 5766, 6007, 6358, 6370, 6730, 177, 6781, 6782) or id_manager in (8271, 8410, 8307, 8285, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5598, 93, 6858, 7248) or id_manager in (select id from users where id_manager in (8271, 8410, 8307, 8285, 8222, 8259, 7929, 8133, 7846, 8080, 7941, 7927, 7920, 7861, 7811, 7828, 7811, 7705, 5274, 7441, 5598, 93, 6858, 7248))"; $rezForBnSwitcher = mysql_query($sqlForBnSwitcher); while($userId = mysql_fetch_assoc($rezForBnSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showBnSwitcher = true; break; } } $sqlForHideZipalSwitcher = "SELECT id FROM `users` WHERE id in (7226, 920, 4135) or id_manager in (7864, 920, 6543, 4135, 7507) or id_manager in (select id from users where id_manager in (7864, 920, 585, 6543, 4135, 7507))"; $rezForHideZipalSwitcher = mysql_query($sqlForHideZipalSwitcher); while($userId = mysql_fetch_assoc($rezForHideZipalSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showZipalSwitcher = false; break; } } if ($_SESSION['id'] == 6574 || $_SESSION['id'] == 6551 || $_SESSION['id'] == 6551 || $_SESSION['id'] == 6545 || $_SESSION['id'] == 7142 || $_SESSION['id'] == 5238) { $showZipalSwitcher = true; } $sqlForHideYandexSwitcher = "SELECT id FROM `users` WHERE id in (7226, 4135) or id_manager in (7864, 6007, 4135) or id_manager in (select id from users where id_manager in (7864, 6007, 4135))"; $rezForHideYandexSwitcher = mysql_query($sqlForHideYandexSwitcher); while($userId = mysql_fetch_assoc($rezForHideYandexSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showYandexSwitcher = false; break; } } if ($_SESSION['id'] == 7142) { $showYandexSwitcher = true; } $sqlForHideDomSwitcher = "SELECT id FROM `users` WHERE id in (7226, 4135) or id_manager in (7864, 6007, 4135) or id_manager in (select id from users where id_manager in (7864, 6007, 4135))"; $resForHideDomSwitcher = mysql_query($sqlForHideDomSwitcher); while($userId = mysql_fetch_assoc($resForHideDomSwitcher)) { if ($userId['id'] == $_SESSION['id']) { $showDomSwitcher = false; break; } } if ($_SESSION['id'] == 7142) { $showDomSwitcher = true; } if ($post['filter_ads_state_objects']) { $_SESSION['filter_ads_state_objects'] = $post['filter_ads_state_objects']; } else { unset($_SESSION['filter_ads_state_objects']); } $urlAdd = "sale=1&view=list"; if (isset($_GET['view'])) { $urlAdd = "sale=1&view=".$_GET['view']; } $depClass = new Department(); $adminDep = false; $searchUserId = $_SESSION['id']; $sql_check_permissions = "SELECT `menu_all_objects`, `menu_all_objects_edit` FROM user_permissions WHERE user_id = $searchUserId"; $q_check_permissions = mysql_query($sql_check_permissions); $r_check_permissions = mysql_fetch_assoc($q_check_permissions); if (!isset($user_view) && ($_SESSION['agency'] || $_SESSION['manager'] || $_SESSION['users_admin'] || $r_check_permissions['menu_all_objects'] == 1)) { $agentIds = []; if ($_SESSION['users_admin'] || $_SESSION['agency'] || $r_check_permissions['menu_all_objects'] == 1) { $user = new User; $user->checkPermissions(); $searchUserId = $user->agencyId; $agentIds[] = $user->agencyId; } else { $user = new User; $user->get((int)$_SESSION['id']); $dep_user = $depClass->getDepartment((int)$_SESSION['id']); if ($dep_user['role'] == 'manager_office') { $searchUserId = $dep_user['admin']; $adminDep = true; } else if ($dep_user['role'] == 'manager_office_menager') { $searchUserId = $user->id_manager; $adminDep = true; } else if($dep_user['role'] == 'admin_department'){ $adminDep = true; } } $agentIds[] = $searchUserId; $agentsOfAgency = User::getAllAgents($searchUserId); foreach ($agentsOfAgency as $agent) { if (!in_array($agent['id'], $agentIds)) { $agentIds[] = $agent['id']; } } if ($_SESSION['agency'] || $_SESSION['users_admin'] || $r_check_permissions['menu_all_objects'] == 1) { $sc = new SourcesConnection($user->agencyId); $agentIds = $sc->getAllUserAgency(); } else if ($adminDep) { $agentsOfManager = User::getAllManagers($searchUserId); foreach ($agentsOfManager as $agent) { if (!in_array($agent['id'], $agentIds)) { $agentIds[] = $agent['id']; } if((int)$agent['role_id'] > 0 && (int)$agent['department_id'] > 0){ $role_user = $depClass->getRole((int)$agent['role_id']); if($role_user['role'] == 'admin_department'){ $menagerDep = User::getDepManagers($role_user['department_id']); foreach($menagerDep as $md){ if(!in_array($md['id'], $agentIds)){ $agentIds[] = $md['id']; $thisAgents = User::getAgentsOfAgency($md['id'], true); foreach($thisAgents as $da){ if (!in_array($da['id'], $agentIds)) { $agentIds[] = $da['id']; } } } } } } } } } else { $agentIds = isset($user_view) ? [$user_view->id] : [$searchUserId]; $agentIds = array_merge($agentIds, $agentIds); } $favor = array(); $favorUserView = array(); $empWho = array(); $empArr = json_decode(html_entity_decode($post['filter_employee']), ENT_QUOTES); foreach($empArr as $empId) { if (strpos($empId, "all_") !== false) { $agencyId = str_replace('all_', '', $empId); $sql_u = "SELECT id FROM `users` WHERE id = $agencyId OR id_manager = $agencyId OR id_manager IN (SELECT id FROM users WHERE id_manager = $agencyId) OR id_manager in (select us.id from users us where us.id_manager in (select usrs.id from users usrs where usrs.id_manager=$agencyId))"; $q_u = mysql_query($sql_u); while($r_u = mysql_fetch_row($q_u)){ $empWho[] = $r_u[0]; } } else if(strpos($empId, "I_") !== false){ $empWho[] = str_replace('I_', '', $empId); } else { $empWho[] = $empId; } } $agentIds = array_merge($agentIds, $empWho); if (!isset($user_view)) { $sql_f = "SELECT id_obj FROM favor WHERE id_user IN (" . implode(',', $agentIds) . ")"; if (!empty($empWho)){ //$str_usl_bd .= " AND id_add_user IN (" . implode(", ", $empWho) . ")"; $sql_f = "SELECT id_obj FROM favor WHERE id_user IN (" . implode(',', $empWho) . ")"; } $q_f = mysql_query($sql_f); while($r_f = mysql_fetch_row($q_f)){ $favor[] = $r_f[0]; } if(!empty($favor)){ $sql = "SELECT count(*) FROM objects WHERE id in (".implode(',', $favor).")"; $rez = $db_sphinx->query($sql); $kol_favor = $db_sphinx->result($rez); } } else { $objFav = array(); $sql_f = "SELECT id_obj FROM favor WHERE id_user IN (" . implode(',', $agentIds) . ")"; if (!empty($empWho)){ //$str_usl_bd .= " AND id_add_user IN (" . implode(", ", $empWho) . ")"; $sql_f = "SELECT id_obj FROM favor WHERE id_user IN (" . implode(',', $empWho) . ")"; } $q_f = mysql_query($sql_f); while($r_f = mysql_fetch_row($q_f)){ $objFav[] = $r_f[0]; } if(!empty($objFav)){ $sql = "SELECT id FROM objects WHERE id in (".implode(',', $objFav).") LIMIT 100000 OPTION max_matches=100000"; $rez = $db_sphinx->query($sql); while ($f = $db_sphinx->fetch_assoc($rez)) $favorUserView[] = $f['id']; } if ($favorUserView) { $kol_favor = count($favorUserView); } if (isset($_GET['favor'])) { $favor = $favorUserView; } } $user = new User; $user->get($searchUserId); $use_advert_budget = boolval($_SESSION['use_advert_budget']); $needAd = false; $sqlForAd = "SELECT id FROM `users` WHERE id in (4, 93, 117, 4251, 5035, 585, 4147, 5350, 5355, 177, 5524, 5530, 5839) or id_manager in (4, 117, 4251, 5035, 585, 4147, 5350, 5355, 177, 5524, 5530, 5839) or id_manager in (select id from users where id_manager in (4, 117, 4251, 5035, 585, 4147, 5350, 5355, 177, 5524, 5530, 5839))"; $rezForAd = mysql_query($sqlForAd); while($userId=mysql_fetch_assoc($rezForAd)) { if ($userId['id'] == $_SESSION['id']) { $needAd = true; break; } } $isPotential = ($post['selected'] == 'potential'); $isArchive = ($post['selected'] == 'archive'); $isFavor = ($post['selected'] == 'favor'); list ($mas_usl_bd, $mas_url_add, $order) = search($post, false, $favor, true); $order = " ORDER BY date_add DESC "; $orderSql = " ORDER BY objects.date_add DESC "; $sortOrder = (isset($_POST['sort_order'])) ? $_POST['sort_order'] : null; if ($sortOrder == null && isset($_SESSION['my_objects_sort_order'])) $sortOrder = $_SESSION['my_objects_sort_order']; if (!isset($_SESSION['my_objects_sort_order'])) { $sortOrder = 0; } $additional_join = ''; $additional_select = ''; if (isset($sortOrder)) { $_SESSION['my_objects_sort_order'] = $sortOrder; switch (intval($sortOrder)) { case 0: $order = ' ORDER BY date_add DESC '; $orderSql = ' ORDER BY objects.date_add DESC '; break; case 1: $order = ' ORDER BY date_add ASC '; $orderSql = ' ORDER BY objects.date_add ASC '; break; case 2: $order = ' ORDER BY date_really_add DESC '; $orderSql = ' ORDER BY objects.date_really_add DESC '; break; case 3: $order = ' ORDER BY date_really_add ASC '; $orderSql = ' ORDER BY objects.date_really_add ASC '; break; case 4: $additional_join = 'LEFT JOIN object_prices ON object_prices.object_id = objects.id'; $additional_select = 'object_prices.currency, object_prices.price_avito, IF (object_prices.currency > 0, object_prices.price_avito, objects.stoim) AS sort_price,'; $order = ' ORDER BY sort_price ASC '; $orderSql = ' ORDER BY sort_price ASC '; break; case 5: $additional_join = 'LEFT JOIN object_prices ON object_prices.object_id = objects.id'; $additional_select = 'object_prices.currency, object_prices.price_avito, IF (object_prices.currency > 0, object_prices.price_avito, objects.stoim) AS sort_price,'; $order = ' ORDER BY sort_price DESC '; $orderSql = ' ORDER BY sort_price DESC '; break; } } if ($mas_usl_bd) { $str_usl_bd = implode(" AND ", $mas_usl_bd); } if ($post['selected'] == 'archive') { $str_usl_bd .= " AND archive = 1 AND id_add_user IN (" . implode(',', $agentIds) . ")"; } else { if ($post['selected'] == 'potential') { $sql_u_p = "SELECT distinct object_id from user_potential_objects where user_id IN (" . implode(',', $agentIds) . ")"; $q_u_p = mysql_query($sql_u_p); $agentIdsUP = array(); while($r_u_p = mysql_fetch_row($q_u_p)){ $agentIdsUP[] = $r_u_p[0]; } if(!empty($agentIdsUP)){ $str_usl_bd .= " AND id in (" . implode(',', $agentIdsUP) . ")"; } else { $str_usl_bd .= " AND id = 0"; } } else { if ($post['selected'] == 'favor') { if(!empty($favor)){ $str_usl_bd .= " AND id in (" . implode(',', $favor) . ")"; } else { $str_usl_bd .= " AND id = 0"; } } else { if ($post['selected'] == 'ad') { $str_usl_bd .= " AND use_in_advert = 1 AND id_add_user IN (" . implode(',', $agentIds) . ")"; } else { $str_usl_bd .= " AND archive <> 1 AND id_add_user IN (" . implode(',', $agentIds) . ")"; } // Фильтрация по доп. полям if (isset($_SESSION['filter_object_fields']['sql'])) { if($post['dev']){ var_dump($_SESSION['filter_object_fields']['sql']); } $fields_filter = $_SESSION['filter_object_fields']['sql']; if (count($fields_filter)) { $obj_ids = []; foreach ($fields_filter as $sql) { $sql = "SELECT `object_id` FROM `object_data` WHERE $sql"; $query = mysql_query($sql); $result = []; while($row = mysql_fetch_row($query)) { $result[] = $row[0]; } if (!empty($obj_ids)) $obj_ids = array_intersect($obj_ids, $result); else $obj_ids = $result; } $obj_ids = array_unique($obj_ids); if (count($obj_ids)) $str_usl_bd .= ' AND id IN ('.implode(',', $obj_ids).') '; else $str_usl_bd .= ' AND id < 0 '; // искусственно ограничиваем выборку, поскольку нет совпадений с кастомными полями } } //фильтрация по договорам if(isset($post['is_contract']) && $post['is_contract']=='true'){ $part_where = "SELECT object_id FROM contracts_object WHERE agency_id = {$currentUser->agencyId}"; if(isset($post['numder_contract']) && !empty($post['numder_contract'])){ $part_where .= " AND number like '%{$post['numder_contract']}%'"; } if(isset($post['type_contract']) && !empty($post['type_contract'])){ $part_where .= " AND type in (".implode(',',$post['type_contract']).")"; } if(isset($post['onDateContract']) && $post['onDateContract'] > 0){ $date_on = strtotime($post['onDateContract']." 00:00:00"); $part_where .= " AND date_end >= $date_on"; } if(isset($post['offDateContract']) && $post['offDateContract'] > 0){ $date_off = strtotime($post['offDateContract']." 23:59:59"); $part_where .= " AND date_end <= $date_off"; } $obj_ids = []; $query_fields = mysql_query($part_where); while($row = mysql_fetch_row($query_fields)) { $obj_ids[] = $row[0]; } if (count($obj_ids)) $str_usl_bd .= ' AND id IN ('.implode(',', $obj_ids).') '; else $str_usl_bd .= ' AND id < 0 '; // искусственно ограничиваем выборку, поскольку нет совпадений с кастомными полями } } } } $addToAvitoFilter = (int) $_POST['addToAvitoFilter']; $addToCianFilter = (int) $_POST['addToCianFilter']; $addToDomClickFilter = (int) $_POST['addToDomClickFilter']; $addToEMLSFilter = (int) $_POST['addToEMLSFilter']; $addToYandexFilter = (int) $_POST['addToYandexFilter']; if ($post['not_advert'] > 0 && $addToAvitoFilter <= 0 && $addToCianFilter <= 0 && $addToDomClickFilter <= 0 && $addToYandexFilter <= 0) { $str_usl_bd .= " AND archive <> 1 AND add_to_yandex_feed=0 AND add_to_zipal=0 AND add_to_avito_feed=0 AND add_to_cian_feed=0 AND add_to_domclick_feed=0 AND add_to_emls_feed=0 AND add_to_bn_feed=0 AND id_add_user IN (" . implode(',', $agentIds) . ") "; $arr_pac = array(); $sql_pac = "select object_id from advertising_package_object_publish where active = 1"; $q_pac = mysql_query($sql_pac); while($r_pac = mysql_fetch_row($q_pac)){ $arr_pac[] = $r_pac[0]; } if (!empty($arr_pac)) { $str_usl_bd .= ' AND id NOT IN (' . implode(',', $arr_pac) . ') '; } } if ($post['not_advert'] > 0 && ($addToAvitoFilter > 0 || $addToCianFilter > 0 || $addToDomClickFilter > 0 || $addToYandexFilter > 0)) { if ($addToAvitoFilter > 0) { $str_usl_bd .= ' AND add_to_avito_feed=0 '; } if ($addToCianFilter > 0) { $str_usl_bd .= ' AND add_to_cian_feed=0 '; } if ($addToDomClickFilter > 0) { $str_usl_bd .= ' AND add_to_domclick_feed=0 '; } if ($addToYandexFilter > 0) { $str_usl_bd .= ' AND add_to_bn_feed=0 '; } $str_usl_bd .= " AND id_add_user IN (" . implode(',', $agentIds) . ") "; $arr_pac = array(); $sql_pac = "select object_id from advertising_package_object_publish where active = 1"; $q_pac = mysql_query($sql_pac); while($r_pac = mysql_fetch_row($q_pac)){ $arr_pac[] = $r_pac[0]; } if (!empty($arr_pac)) { $str_usl_bd .= ' AND id NOT IN (' . implode(',', $arr_pac) . ') '; } } if ($post['filter_employee'] && $post['selected'] != 'favor') { $empWho = array(); $empArr = json_decode(html_entity_decode($post['filter_employee']), ENT_QUOTES); foreach($empArr as $empId) { if (strpos($empId, "all_") !== false) { $agencyId = str_replace('all_', '', $empId); $sql_u = "SELECT id FROM `users` WHERE id = $agencyId OR id_manager = $agencyId OR id_manager IN (SELECT id FROM users WHERE id_manager = $agencyId)"; $q_u = mysql_query($sql_u); while($r_u = mysql_fetch_row($q_u)){ $empWho[] = $r_u[0]; } } else if(strpos($empId, "I_") !== false){ $empWho[] = str_replace('I_', '', $empId); } else { $empWho[] = $empId; } } if (!empty($empWho)){ $str_usl_bd .= " AND id_add_user IN (" . implode(", ", $empWho) . ")"; } $_SESSION['filter_emp'] = $post['filter_employee']; } else { unset($_SESSION['filter_emp']); } if (isset($post['filter_type'])) { $filter_type = json_decode(html_entity_decode($post['filter_type']), ENT_QUOTES); $ob_types = []; foreach($filter_type as $type) { if ($indx = array_search($type, $OBJECT_TYPES)) { $ob_types[] = $indx; } } if (!empty($ob_types)) $str_usl_bd .= " AND type IN (" . implode(',', $ob_types) . ")"; $_SESSION['filter_object_type'] = $post['filter_type']; } else { unset($_SESSION['filter_object_type']); } if (!empty($post['filter_activities'])) { $activitiesArr = json_decode(html_entity_decode($post['filter_activities']), ENT_QUOTES); $noTagsKey = array_search('no_tags', $activitiesArr); $hasNoTags = ($noTagsKey !== false); if ($hasNoTags) { unset($activitiesArr[$noTagsKey]); } if ($hasNoTags && !empty($activitiesArr)) { // Получаем ID объектов с выбранными тегами из MySQL $objWithTags = array(); $sql_a = "SELECT object_id FROM objects_activities WHERE activity_id IN (" . implode(", ", $activitiesArr) . ")"; $q_a = mysql_query($sql_a); while($r_a = mysql_fetch_array($q_a)){ $objWithTags[] = $r_a[0]; } $base_conditions = preg_replace('/^\s*AND\s+/i', '', $str_usl_bd); $sql_no_tags_ids = "SELECT id FROM objects WHERE $base_conditions AND has_activities = 0 LIMIT 10000 OPTION max_matches=10000"; $result_no_tags = $db_sphinx->query($sql_no_tags_ids, true); $ids_no_tags = array(); while ($row = $db_sphinx->fetch_assoc($result_no_tags)) { $ids_no_tags[] = $row['id']; } // Объединяем объекты без тегов и объекты с выбранными тегами $allIds = array_merge($ids_no_tags, $objWithTags); $allIds = array_unique($allIds); if (!empty($allIds)) { $str_usl_bd .= " AND id IN (" . implode(", ", $allIds) . ")"; } else { $str_usl_bd .= " AND id IN (0)"; } } elseif ($hasNoTags) { // Только "Без тегов" $str_usl_bd .= " AND has_activities = 0"; } elseif (!empty($activitiesArr)) { // Только обычные теги (оригинальная логика) $objWithTags = array(); $sql_a = "SELECT object_id FROM objects_activities WHERE activity_id IN (" . implode(", ", $activitiesArr) . ")"; $q_a = mysql_query($sql_a); while($r_a = mysql_fetch_array($q_a)){ $objWithTags[] = $r_a[0]; } if (!empty($objWithTags)) { $str_usl_bd .= " AND id IN (" . implode(", ", $objWithTags) . ")"; } else { $str_usl_bd .= " AND id IN (0)"; } } $_SESSION['filter_activities'] = $post['filter_activities']; } else { unset($_SESSION['filter_activities']); } if (isset($post['object_commission']) && $post['object_commission']) { $str_usl_bd .= " AND commission >= " . $post['object_commission']; } if (isset($post['object_commission_to']) && $post['object_commission_to']) { $str_usl_bd .= " AND commission <= " . $post['object_commission_to']; } if (isset($post['object_cena_ot']) && $post['object_cena_ot']) { $str_usl_bd .= " AND price_for_order >= " . $post['object_cena_ot']; } if (isset($post['object_cena_do']) && $post['object_cena_do']) { $str_usl_bd .= " AND price_for_order <= " . $post['object_cena_do']; } $str_usl_dealType = ''; if (isset($post['dealTypes']) && $post['dealTypes']) { $dealTypeArr = json_decode(html_entity_decode($post['dealTypes']), ENT_QUOTES); if(!empty($dealTypeArr)){ $str_usl_dealType .= " AND deal_type IN (" . implode(", ", $dealTypeArr) . ")"; } } if (isset($post['object_komnat_from']) && $post['object_komnat_from']) { $str_usl_bd .= " AND komnat >= " . $post['object_komnat_from']; } if (isset($post['object_komnat_to']) && $post['object_komnat_to']) { $str_usl_bd .= " AND komnat <= " . $post['object_komnat_to']; } $sqlZipalErr = "SELECT object_id, error_text, sended, published FROM zipal_objects WHERE error_text IS NOT NULL"; $zipalErrResult = mysql_query($sqlZipalErr); $zipalObjectsWithError = array(); while ($res = mysql_fetch_array($zipalErrResult)) { $zipalObjectsWithError[] = $res; } $s_3 = ''; $arrayFids = array(); if ($post['ads_errors'] <= 0 && $post['ads_sended'] <= 0 && $post['ads_good_adv'] <= 0 && $post['not_advert'] <= 0 && $post['removed_publication'] <= 0) { // AND id_add_user IN (" . implode(',', $agentIds) . ")"; if ($addToAvitoFilter > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } if ($addToCianFilter > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } if ($addToDomClickFilter > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } if ($addToEMLSFilter > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_emls_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } if ($addToYandexFilter > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } $param7 = (int)$_POST['filter_is_package']; $s_7 = ''; if ($param7 > 0) { $arr_pac = array(); $sql_pac = "select object_id from advertising_package_object_publish where active = 1"; $q_pac = mysql_query($sql_pac); while ($r_pac = mysql_fetch_row($q_pac)) { $arrayFids[] = $r_pac[0]; } } $param3 = (int)$_POST['is_reports']; $s_4 = ''; if ($param3 > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_zipal=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } $param4 = (int)$_POST['is_free']; $s_5 = ''; if ($param4 > 0) { $sql1 = "SELECT id FROM objects WHERE add_to_yandex_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($post['ads_errors'] == '1' && $addToAvitoFilter <= 0 && $addToCianFilter <= 0 && $addToDomClickFilter <= 0 && $addToYandexFilter <= 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 1"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на авито и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 2"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на циан и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 4"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на домклик и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 3"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на яндекс и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } // статус С ошибкой и выбрана площадка if ($post['ads_errors'] == '1' && ($addToAvitoFilter > 0 || $addToCianFilter > 0 || $addToDomClickFilter > 0 || $addToYandexFilter > 0)) { if ($addToAvitoFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 1"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на авито и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToCianFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 2"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на циан и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToDomClickFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 4"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на домклик и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToYandexFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NOT NULL AND `service_id` = 3"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на яндекс и ошибка в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } } function getAllSendedAvito($db_sphinx, $user_view, $users_sp) { $arr_obj = array(); $s_local = ''; $arrayLocal = array(); $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 1"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на авито и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } return array_unique($arrayLocal); } function getAllSendedCian($db_sphinx, $user_view, $users_sp) { $arr_obj = array(); $s_local = ''; $arrayLocal = array(); $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 2"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на циан и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } return array_unique($arrayLocal); } function getAllSendedDom($db_sphinx, $user_view, $users_sp) { $arr_obj = array(); $s_local = ''; $arrayLocal = array(); $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 4"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на домклик и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } return array_unique($arrayLocal); } function getAllSendedYandex($db_sphinx, $user_view, $users_sp) { $arr_obj = array(); $s_local = ''; $arrayLocal = array(); $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 3"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на яндекс и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } return array_unique($arrayLocal); } function getAllSended($db_sphinx, $user_view, $users_sp) { $arr_obj = array(); $s_local = ''; $arrayLocal = array(); $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 1"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на авито и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 2"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на циан и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 4"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на домклик и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `service_id` = 3"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; } else { $s_local .= ''; } //то, что размещено на яндекс и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayLocal[] = $r1['id']; } return array_unique($arrayLocal); } function get_inter_avito($user_view, $users_sp, $db_sphinx, $sended) { $arr_obj_avito = array(); $arr_local = array(); $endSql = ""; if (count($sended) > 0) { $endSql = " AND `object_id` NOT IN (" . implode(',', $sended) . ")"; } $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL AND `object_id` NOT IN (SELECT s.`object_id` FROM `ads_stats` s WHERE s.`errors` IS NOT NULL AND s.`service_id` = 1) AND `service_id` = 1 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_avito[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_avito)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_avito) . ') '; //то, что размещено на авито и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } return array_unique($arr_local); } function get_inter_cian($user_view, $users_sp, $db_sphinx, $sended) { $arr_obj_cn = array(); $arr_local = array(); $endSql = ""; if (count($sended) > 0) { $endSql = " AND `object_id` NOT IN (" . implode(',', $sended) . ")"; } $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL AND `object_id` NOT IN (SELECT s.`object_id` FROM `ads_stats` s WHERE s.`errors` IS NOT NULL AND s.`service_id` = 2) AND `service_id` = 2 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_cn[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_cn)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_cn) . ') '; //то, что размещено на циан и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } return array_unique($arr_local); } function get_inter_dom($user_view, $users_sp, $db_sphinx, $sended) { $arr_obj_dc = array(); $arr_local = array(); $arr_obj_err = array(); $endSql = ""; $endSql2 = ""; $sql_ads_er = "SELECT DISTINCT(st.object_id) FROM ads_stats st WHERE st.agency_id = '$user_view->agencyId' AND st.errors IS NOT NULL AND st.service_id = 4"; $rezAdsErrors = mysql_query($sql_ads_er); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_err[] = $objAdsInfo['object_id']; } } if (count($arr_obj_err) > 0) { $endSql2 = " AND `object_id` NOT IN (" . implode(',', $arr_obj_err) . ")"; } if (count($sended) > 0) { $endSql = " AND `object_id` NOT IN (" . implode(',', $sended) . ")"; } $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL $endSql2 AND `service_id` = 4 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_dc[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_dc)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_dc) . ') '; //то, что размещено на домклик и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } return array_unique($arr_local); } function get_inter_yandex($user_view, $users_sp, $db_sphinx, $sended) { $arr_obj_ya = array(); $arr_local = array(); $endSql = ""; if (count($sended) > 0) { $endSql = " AND `object_id` NOT IN (" . implode(',', $sended) . ")"; } $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL AND `object_id` NOT IN (SELECT s.`object_id` FROM `ads_stats` s WHERE s.`errors` IS NOT NULL AND s.`service_id` = 3) AND `service_id` = 3 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_ya[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_ya)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_ya) . ') '; //то, что размещено на яндекс и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } return array_unique($arr_local); } function get_inter($user_view, $users_sp, $db_sphinx, $sended) { $arr_obj_avito = array(); $arr_obj_cn = array(); $arr_obj_dc = array(); $arr_obj_ya = array(); $arr_obj_err = array(); $arr_local = array(); $s_local = ''; $endSql = ""; $endSql2 = ""; $sql_ads_er = "SELECT DISTINCT(st.object_id) FROM ads_stats st WHERE st.agency_id = '$user_view->agencyId' AND st.errors IS NOT NULL"; $rezAdsErrors = mysql_query($sql_ads_er); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_err[] = $objAdsInfo['object_id']; } } if (count($arr_obj_err) > 0) { $endSql2 = " AND `object_id` NOT IN (" . implode(',', $arr_obj_err) . ")"; } if (count($sended) > 0) { $endSql = " AND `object_id` NOT IN (" . implode(',', $sended) . ")"; } $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL $endSql2 AND `service_id` = 1 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_avito[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_avito)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_avito) . ') '; //то, что размещено на авито и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL $endSql2 AND `service_id` = 2 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_cn[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_cn)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_cn) . ') '; //то, что размещено на циан и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL $endSql2 AND `service_id` = 4 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_dc[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_dc)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_dc) . ') '; //то, что размещено на домклик и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$user_view->agencyId' AND `errors` IS NULL $endSql2 AND `service_id` = 3 " . $endSql; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_ya[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj_ya)) { $s_local = ' AND id IN (' . implode(',', $arr_obj_ya) . ') '; //то, что размещено на яндекс и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $users_sp) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arr_local[] = $r1['id']; } } return array_unique($arr_local); } // статус Отправлен и не выбрана площадка if ($post['ads_sended'] == '1' && $addToAvitoFilter <= 0 && $addToCianFilter <= 0 && $addToDomClickFilter <= 0 && $addToYandexFilter <= 0) { $result = getAllSended($db_sphinx, $currentUser, $agentIds); foreach ($result as $val) { $arrayFids[] = $val; } } // статус Отправлен и выбрана площадка if ($post['ads_sended'] == '1' && ($addToAvitoFilter > 0 || $addToCianFilter > 0 || $addToDomClickFilter > 0 || $addToYandexFilter > 0)) { if ($addToAvitoFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `service_id` = 1"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { $s_local .= ' AND id NOT IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на авито и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToCianFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `service_id` = 2"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { //то, что размещено на циан и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToDomClickFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `service_id` = 4"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { //то, что размещено на домклик и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToYandexFilter > 0) { $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `service_id` = 3"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } if (!empty($arr_obj)) { //то, что размещено на яндекс и не появилось в ads_stats $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } } // статус Размещается и не выбрана площадка if ($post['ads_good_adv'] == '1' && $addToAvitoFilter <= 0 && $addToCianFilter <= 0 && $addToDomClickFilter <= 0 && $addToYandexFilter <= 0) { $result = getAllSended($db_sphinx, $currentUser, $agentIds); $intersection = get_inter($currentUser, $agentIds, $db_sphinx, $result); foreach ($intersection as $val) { $arrayFids[] = $val; } } // статус Размещается и выбрана площадка if ($post['ads_good_adv'] == '1' && ($addToAvitoFilter > 0 || $addToCianFilter > 0 || $addToDomClickFilter > 0 || $addToYandexFilter > 0)) { if ($addToAvitoFilter > 0) { $allSended = getAllSendedAvito($db_sphinx, $currentUser, $agentIds); $intersection = get_inter_avito($currentUser, $agentIds, $db_sphinx, $allSended); $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NULL AND `object_id` NOT IN (SELECT s.`object_id` FROM `ads_stats` s WHERE s.`errors` IS NOT NULL AND `service_id` = 1) AND `service_id` = 1"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } $arr_obj = array_intersect($arr_obj, $intersection); if (!empty($arr_obj)) { $s_local = ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на авито и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_avito_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToCianFilter > 0) { $allSended = getAllSendedCian($db_sphinx, $currentUser, $agentIds); $intersection = get_inter_cian($currentUser, $agentIds, $db_sphinx, $allSended); $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NULL AND `object_id` NOT IN (SELECT s.`object_id` FROM `ads_stats` s WHERE s.`errors` IS NOT NULL AND `service_id` = 2) AND `service_id` = 2"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } $arr_obj = array_intersect($arr_obj, $intersection); if (!empty($arr_obj)) { $s_local = ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на циан и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_cian_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToDomClickFilter > 0) { $allSended = getAllSendedDom($db_sphinx, $currentUser, $agentIds); $intersection = get_inter_dom($currentUser, $agentIds, $db_sphinx, $allSended); $arr_obj_err = array(); $endSql2 = ""; $sql_ads_er = "SELECT DISTINCT(st.object_id) FROM ads_stats st WHERE st.agency_id = '$currentUser->agencyId' AND st.errors IS NOT NULL AND st.service_id = 4"; $rezAdsErrors = mysql_query($sql_ads_er); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj_err[] = $objAdsInfo['object_id']; } } if (count($arr_obj_err) > 0) { $endSql2 = " AND `object_id` NOT IN (" . implode(',', $arr_obj_err) . ")"; } $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NULL $endSql2 AND `service_id` = 4"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } $arr_obj = array_intersect($arr_obj, $intersection); if (!empty($arr_obj)) { $s_local = ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на домклик и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_domclick_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } if ($addToYandexFilter > 0) { $allSended = getAllSendedYandex($db_sphinx, $currentUser, $agentIds); $intersection = get_inter_yandex($currentUser, $agentIds, $db_sphinx, $allSended); $arr_obj = array(); $s_local = ''; $sql_ads = "SELECT DISTINCT(`object_id`) FROM `ads_stats` WHERE `agency_id` = '$currentUser->agencyId' AND `errors` IS NULL AND `object_id` NOT IN (SELECT s.`object_id` FROM `ads_stats` s WHERE s.`errors` IS NOT NULL AND `service_id` = 3) AND `service_id` = 3"; $rezAdsErrors = mysql_query($sql_ads); if (mysql_num_rows($rezAdsErrors) > 0) { while ($objAdsInfo = mysql_fetch_assoc($rezAdsErrors)) { $arr_obj[] = $objAdsInfo['object_id']; } } $arr_obj = array_intersect($arr_obj, $intersection); if (!empty($arr_obj)) { $s_local = ' AND id IN (' . implode(',', $arr_obj) . ') '; //то, что размещено на яндекс и появилось в ads_stats без ошибок $sql1 = "SELECT id FROM objects WHERE add_to_bn_feed=1 AND id_add_user IN (" . implode(',', $agentIds) . ") $s_local LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while ($r1 = $db_sphinx->fetch_assoc($q1)) { $arrayFids[] = $r1['id']; } } } } //Статус Сняты с размещения if ($post['removed_publication'] == '1') { $objects_unpublish = $object_publish = array('DOMCLICK_JW_FEED'=>array(), 'CIAN_JW_FEED'=>array(), 'AVITO_JW_FEED'=>array(), 'YANDEX_JW_FEED'=>array(), 'EMLS_JW_FEED'=>array()); $publish_obj = array(); $sql_publish = "SELECT * FROM object_publish_statistic WHERE on_moderation = 0 AND user_owner_id IN (" . implode(',', $agentIds) . ")"; $q_publish = mysql_query($sql_publish); while($obj_publish = mysql_fetch_assoc($q_publish)){ if(isset($objects_unpublish[$obj_publish['destination']]) && !is_null($obj_publish['unpublish_user_id'])){ $objects_unpublish[$obj_publish['destination']][] = (int)$obj_publish['object_id']; } else if (isset($object_publish[$obj_publish['destination']])){ $object_publish[$obj_publish['destination']][] = (int)$obj_publish['object_id']; $publish_obj[] = (int)$obj_publish['object_id']; } } $time = microtime(true) - $start; if(isset($post['dev'])){ ///echo $sql_publish; echo 'Снято 1 --- '.$time." сек."; } if(!empty($publish_obj)){ $sql1 = "SELECT id, add_to_bn_feed, add_to_domclick_feed, add_to_cian_feed, add_to_avito_feed, add_to_emls_feed FROM objects WHERE id_add_user IN (" . implode(',', $agentIds) . ") AND id in (".implode(',', $publish_obj).") LIMIT 1000000 OPTION max_matches=1000000"; $q1 = $db_sphinx->query($sql1, true); while($r1 = $db_sphinx->fetch_assoc($q1)){ if($r1['add_to_bn_feed'] == 0){ if($index = array_search((int)$r1['id'], $object_publish['YANDEX_JW_FEED']) !== false){ $objects_unpublish['YANDEX_JW_FEED'][] = (int)$r1['id']; unset($object_publish['YANDEX_JW_FEED'][$index]); } } if($r1['add_to_domclick_feed'] == 0){ if($index = array_search((int)$r1['id'], $object_publish['DOMCLICK_JW_FEED']) !== false){ $objects_unpublish['DOMCLICK_JW_FEED'][] = (int)$r1['id']; unset($object_publish['DOMCLICK_JW_FEED'][$index]); } } if($r1['add_to_cian_feed'] == 0){ if($index = array_search((int)$r1['id'], $object_publish['CIAN_JW_FEED']) !== false){ $objects_unpublish['CIAN_JW_FEED'][] = (int)$r1['id']; unset($object_publish['CIAN_JW_FEED'][$index]); } } if($r1['add_to_avito_feed'] == 0){ if($index = array_search((int)$r1['id'], $object_publish['AVITO_JW_FEED']) !== false){ $objects_unpublish['AVITO_JW_FEED'][] = (int)$r1['id']; unset($object_publish['AVITO_JW_FEED'][$index]); } } if($r1['add_to_emls_feed'] == 0){ if($index = array_search((int)$r1['id'], $object_publish['EMLS_JW_FEED']) !== false){ $objects_unpublish['EMLS_JW_FEED'][] = (int)$r1['id']; unset($object_publish['EMLS_JW_FEED'][$index]); } } /* if($r1['add_to_yandex_feed'] == 0){ if($index = array_search((int)$r1['id'], $object_publish['FREE_JW_FEED']) !== false){ $objects_unpublish['FREE_JW_FEED'][] = (int)$r1['id']; unset($object_publish['FREE_JW_FEED'][$index]); } }*/ } $time = microtime(true) - $start; if(isset($post['dev'])){ echo 'Снято 2 --- '.$time." сек."; } } if($addToAvitoFilter <= 0 && $addToCianFilter <= 0 && $addToDomClickFilter <= 0 && $addToYandexFilter <= 0 && $addToEMLSFilter <= 0){ foreach($objects_unpublish as $plase => $objects){ foreach($objects as $object_ad){ if(!in_array($object_ad, $object_publish[$plase])){ $arrayFids[] = $object_ad; } } } } else { if ($addToAvitoFilter > 0) { foreach($objects_unpublish['AVITO_JW_FEED'] as $object_ad){ if(!in_array($object_ad, $object_publish['AVITO_JW_FEED'])){ $arrayFids[] = $object_ad; } } } if ($addToCianFilter > 0) { foreach($objects_unpublish['CIAN_JW_FEED'] as $object_ad){ if(!in_array($object_ad, $object_publish['CIAN_JW_FEED'])){ $arrayFids[] = $object_ad; } } } if ($addToDomClickFilter > 0) { foreach($objects_unpublish['DOMCLICK_JW_FEED'] as $object_ad){ if(!in_array($object_ad, $object_publish['DOMCLICK_JW_FEED'])){ $arrayFids[] = $object_ad; } } } if ($addToEMLSFilter > 0) { foreach($objects_unpublish['EMLS_JW_FEED'] as $object_ad){ if(!in_array($object_ad, $object_publish['EMLS_JW_FEED'])){ $arrayFids[] = $object_ad; } } } if ($addToYandexFilter > 0) { foreach($objects_unpublish['YANDEX_JW_FEED'] as $object_ad){ if(!in_array($object_ad, $object_publish['YANDEX_JW_FEED'])){ $arrayFids[] = $object_ad; } } } } $arrayFids = array_unique($arrayFids); } $time = microtime(true) - $start; if(isset($post['dev'])){ echo 'Cyznj --- '.$time." сек."; } if(!empty($arrayFids)){ $arrayFids = array_unique($arrayFids); $s_3 = " AND id IN (" . implode(',', $arrayFids) . ")"; } else if ($post['ads_errors'] > 0 || $post['ads_sended'] > 0 || $post['ads_good_adv'] > 0 || $post['removed_publication'] > 0){ $s_3 = " AND id IN (0)"; } $promotion = false; $sqlPr = ''; if(isset($_POST['avito_highlight']) && (int) $_POST['avito_highlight'] > 0){ $sqlPr .= ' avito_highlight=1 OR '; $promotion = true; } if(isset($_POST['avito_xl']) && (int) $_POST['avito_xl'] > 0){ $sqlPr .= ' avito_xl=1 OR '; $promotion = true; } if(isset($_POST['avito_x2_1']) && (int) $_POST['avito_x2_1'] > 0){ $sqlPr .= ' avito_x2_1=1 OR '; $promotion = true; } if(isset($_POST['avito_x2_7']) && (int) $_POST['avito_x2_7'] > 0){ $sqlPr .= ' avito_x2_7=1 OR '; $promotion = true; } if(isset($_POST['avito_x5_1']) && (int) $_POST['avito_x5_1'] > 0){ $sqlPr .= ' avito_x5_1=1 OR '; $promotion = true; } if(isset($_POST['avito_x5_7']) && (int) $_POST['avito_x5_7'] > 0){ $sqlPr .= ' avito_x5_7=1 OR '; $promotion = true; } if(isset($_POST['avito_x10_1']) && (int) $_POST['avito_x10_1'] > 0){ $sqlPr .= ' avito_x10_1=1 OR '; $promotion = true; } if(isset($_POST['avito_x10_7']) && (int) $_POST['avito_x10_7'] > 0){ $sqlPr .= ' avito_x10_7=1 OR '; $promotion = true; } if(isset($_POST['cian_highlight']) && (int) $_POST['cian_highlight'] > 0){ $sqlPr .= ' cian_highlight=1 OR '; $promotion = true; } if(isset($_POST['cian_standard']) && (int) $_POST['cian_standard'] > 0){ $sqlPr .= ' cian_standard=1 OR '; $promotion = true; } if(isset($_POST['cian_paid']) && (int) $_POST['cian_paid'] > 0){ $sqlPr .= ' cian_paid=1 OR '; $promotion = true; } if(isset($_POST['cian_premium']) && (int) $_POST['cian_premium'] > 0){ $sqlPr .= ' cian_premium=1 OR '; $promotion = true; } if(isset($_POST['cian_top3']) && (int) $_POST['cian_top3'] > 0){ $sqlPr .= ' cian_top3=1 OR '; $promotion = true; } if(isset($_POST['cian_bet']) && (int) $_POST['cian_bet'] > 0){ $sqlPr .= " cian_bet='".$_POST['cian_bet']."' OR "; $promotion = true; } if(isset($_POST['cian_ignore_pkg']) && (int) $_POST['cian_ignore_pkg'] > 0){ $sqlPr .= " cian_ignore_pkg=1 OR "; $promotion = true; } if(isset($_POST['yandex_premium']) && (int) $_POST['yandex_premium'] > 0){ $sqlPr .= " yandex_premium=1 OR "; $promotion = true; } if(isset($_POST['yandex_raise']) && (int) $_POST['yandex_raise'] > 0){ $sqlPr .= " yandex_raise=1 OR "; $promotion = true; } if(isset($_POST['yandex_promotion']) && (int) $_POST['yandex_promotion'] > 0){ $sqlPr .= " yandex_promotion=1 OR "; $promotion = true; } if(isset($_POST['domclick_express']) && (int) $_POST['domclick_express'] > 0){ $sqlPr .= " domclick_express=1 OR "; $promotion = true; } if(isset($_POST['domclick_premium']) && (int) $_POST['domclick_premium'] > 0){ $sqlPr .= " domclick_premium=1 OR "; $promotion = true; } if(isset($_POST['domclick_top']) && (int) $_POST['domclick_top'] > 0){ $sqlPr .= " domclick_top=1 OR "; $promotion = true; } if ($sqlPr !== '') { $sqlPr = substr($sqlPr, 0, strlen($sqlPr) - 3); $sqlPr = " ($sqlPr) "; } $arrPromo = array(); if($sqlPr !== ''){ $sqlPr = "SELECT object_id FROM ads_promo WHERE {$sqlPr} AND (agency_id={$user->agencyId} or created_by IN (" . implode(',', $agentIds) . "))"; $qpr = mysql_query($sqlPr); while($rpr = mysql_fetch_assoc($qpr)){ $arrPromo[] = (int)$rpr['object_id']; } } $s_9 = ''; if(!empty($arrPromo)){ $s_9 = " AND id IN (" . implode(',', $arrPromo) . ")"; } else if ($promotion){ $s_9 = " AND id IN (0)"; } /*if (((int) $_POST['param6']) && $s_3 === '' && $s_4 === '' && $s_5 === '') { $arr_pac = array(); $sql_pac = "select object_id from advertising_package_object_publish where active = 1"; $q_pac = mysql_query($sql_pac); while($r_pac = mysql_fetch_row($q_pac)){ $arr_pac[] = $r_pac[0]; } $s_3 .= ' AND add_to_yandex_feed=0 AND add_to_zipal=0 AND add_to_avito_feed=0 AND add_to_cian_feed=0 AND add_to_domclick_feed=0 AND add_to_emls_feed=0 AND add_to_bn_feed=0 '; if (!empty($arr_pac)) $s_3 .= ' AND id NOT IN ('.implode(',', $arr_pac).') '; }*/ $str_usl_bd .= $s_3.$s_4.$s_5.$s_7.$s_9; if (isset($post['search'])) { $post['search'] = mb_strtolower(trim($post['search']), "UTF-8"); if (preg_match('/^\d+$/', $post['search'])) $str_usl_bd .= " AND id = ".$post['search']; else $str_usl_bd .= " AND MATCH ('@adres ".str_replace("/","-",$post['search'])."')"; } $sql_count_sale = "SELECT id, IF(ads_avito_error = 1 OR ads_cian_error = 1 OR ads_yandex_error = 1 OR ads_domclick_error = 1, 1, 0) AS ads_error FROM objects WHERE del=0 and black <> 1 AND moder <> 1 AND operation_type = 1 $str_usl_bd $str_usl_dealType LIMIT 1000000 OPTION max_matches=1000000"; /*if($_SESSION['id'] == 8038){ // ini_set('display_errors', 1); //error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); echo $sql_count_sale; // die(); }*/ if(isset($post['dev'])){ echo $sql_count_sale; } $vsego_sale = $db_sphinx->num_rows($db_sphinx->query($sql_count_sale, true)); $sql_count_rent = "SELECT id, IF(ads_avito_error = 1 OR ads_cian_error = 1 OR ads_yandex_error = 1 OR ads_domclick_error = 1, 1, 0) AS ads_error FROM objects WHERE del=0 and black <> 1 AND moder <> 1 AND operation_type = 0 $str_usl_bd LIMIT 1000000 OPTION max_matches=1000000"; $vsego_rent = $db_sphinx->num_rows($db_sphinx->query($sql_count_rent, true)); $str_usl_bd = $str_usl_bd . $str_usl_dealType; if ($post['sale'] == 1) { $str_usl_bd = " AND operation_type = 1 ".$str_usl_bd; } else if ($post['rent'] == 1) { $str_usl_bd = " AND operation_type = 0 ".$str_usl_bd; } $per_page = 10; if (isset($post['view']) && $post['view'] == 'table'){ $per_page = 20; } if ($_SESSION['id'] == 93) { $per_page = 5; } $sql_count = "SELECT id, IF(ads_avito_error = 1 OR ads_cian_error = 1 OR ads_yandex_error = 1 OR ads_domclick_error = 1, 1, 0) AS ads_error FROM objects WHERE del=0 and black <> 1 AND moder <> 1 $str_usl_bd LIMIT 1000000 OPTION max_matches=1000000"; /*if($_SESSION['id'] == 8826){ echo $sql_count; }*/ $vsego = $db_sphinx->num_rows($db_sphinx->query($sql_count, true)); $all_pages = ceil($vsego / $per_page); if ($post['page']){ $page = intval($post['page']); if($all_pages < $page && $page > 0){ $page = $page - 1; } } else $page = 1; $limit = ($page - 1) * $per_page; /* $sql = "SELECT objects.*, rayon.rayon, ads_objects.ads_id, ads_objects.ads_source, ads_objects.ads_agent, ads_objects.ads_url, DATE_FORMAT(objects.date_add,'%d.%m.%Y %H:%i') as date_add, DATE_FORMAT(objects.date_really_add,'%d.%m.%Y %H:%i') as date_really_add, IF((SELECT count(id) FROM ads_stats WHERE object_id = o.id AND is_error = 1) > 0, 1, 0) as ads_error, lu.name as land_usage_name FROM objects objects LEFT JOIN rayon rayon on objects.rayon = rayon.id LEFT JOIN land_usage_type lu on objects.land_usage_type_id = lu.id LEFT JOIN ads_objects ON ads_objects.obj_id = objects.id WHERE objects.black <> 1 AND objects.moder <> 1 AND $str_usl_bd GROUP BY objects.id $order LIMIT $limit, $per_page";*/ if (isset($_SESSION['my_objects_export']) && isset($post['view']) && $post['view'] == 'table') { unset($_SESSION['my_objects_export']); } $sql = "SELECT *, IF(ads_avito_error = 1 OR ads_cian_error = 1 OR ads_yandex_error = 1 OR ads_domclick_error = 1, 1, 0) AS ads_error FROM objects WHERE del=0 and black <> 1 AND moder <> 1 $str_usl_bd $order LIMIT $limit, $per_page OPTION max_matches=1000000"; if($post['view'] == 'table'){ $sql = "SELECT *, IF(ads_avito_error = 1 OR ads_cian_error = 1 OR ads_yandex_error = 1 OR ads_domclick_error = 1, 1, 0) AS ads_error FROM objects WHERE del=0 and black <> 1 AND moder <> 1 $str_usl_bd $order LIMIT 1000000 OPTION max_matches=1000000"; } if(isset($post['dev'])){ echo $sql; } $rez = $db_sphinx->query($sql, true); if ($db_sphinx->num_rows($rez)) { $_SESSION['my_objects_export'] = "SELECT * FROM objects WHERE del=0 and black <> 1 AND moder <> 1 $str_usl_bd LIMIT 1000000 OPTION max_matches=1000000"; if($post['view'] != 'table'){ ?>
|
Сортировка:
|