0) { $minDays = 100000; $minId = null; foreach ($packages as $pack) { $days = ceil(((strtotime($pack['publish_date']) + $pack['days'] * 86400) - time()) / 86400); if ($days < $minDays && $days > 0) { $minDays = $days; $minId = $pack['id']; } } if ($minId) { $otherPackText = ''; foreach ($packages as $pack) { $days = ceil(((strtotime($pack['publish_date']) + $pack['days'] * 86400) - time()) / 86400); $otherDecled = declOfNum($days, array('%d день', '%d дня', '%d дней')); $otherPackText = $otherPackText . $pack['pack_name'] . ': ' .$otherDecled . ';
'; } $decled = declOfNum($minDays, array('Остался %d день', 'Осталось %d дня', 'Осталось %d дней')); if ($minDays >= 1 && $minDays <= 5) { return ' ' .$otherPackText .''; } elseif ($minDays > 5) { return ' ' .$otherPackText .''; } else { return ''; } } else { return ''; } } else { return ''; } } function zipalPackageCountText($objectId, $packageId) { $ojb = array(); $zipalObj = mysql_fetch_assoc(mysql_query("SELECT id, days, created_at, publish_date, error_text from advertising_package_object_publish where object_id = $objectId and advertising_package_id = $packageId")); $ojb['zipal_active'] = 0; if ($zipalObj['publish_date'] == NULL || preg_match("|0000|", $zipalObj['publish_date'])) { $ojb['zipal_active'] = 1; } $ojb['zipal_day'] = ceil(((strtotime($zipalObj['publish_date']) + $zipalObj['days'] * 86400) - time()) / 86400); if ($ojb['zipal_day'] > 0) { $ojb['zipal_day_text'] = declOfNum($ojb['zipal_day'], array('Остался %d день', 'Осталось %d дня', 'Осталось %d дней')); } else { $ojb['zipal_day_text'] = ""; } if ($ojb['zipal_day'] >= 1 && $ojb['zipal_day'] <= 5) { $ojb['zipal_active'] = 1; $html = ''.$ojb['zipal_day_text'].''; } elseif ($ojb['zipal_day'] > 5) { $ojb['zipal_active'] = 1; $html = ''.$ojb['zipal_day_text'].''; } else { $html = ''; if (!$zipalObj && $ojb['add_to_zipal'] == 1) { $ojb['zipal_active'] = 1; } } $ojb['error_text'] = null; if (!empty($zipalObj['error_text'])) { $error = json_decode(str_replace("\n", '', str_replace("\r", '', trim($zipalObj['error_text']))), true); if ($error['result']['status'] == 'ErrorPropertyResponseType') { $ojb['error_text'] = (array)$error['result']['error']; } } return [ 'html' => $html, 'error_text' => $ojb['error_text'], 'zipal_days' => $ojb['zipal_day'], 'zipal_days_text' => $ojb['zipal_day_text'], 'zipal_active' => $ojb['zipal_active'] ]; } function ZipalCountText($id) { $ojb = array(); $zipalObj = mysql_fetch_assoc(mysql_query("SELECT id, days, created_at, add_to_zipal_at, error_text from zipal_objects where object_id = $id")); //Test data // $zipalObj['add_to_zipal_at'] = "2020-03-05 10:10:10"; // $zipalObj['days'] = 43; // //unset($zipalObj); // $ojb['zipal_active'] = 0; // $ojb['add_to_zipal'] = 1; $ojb['zipal_active'] = 0; if ($zipalObj['add_to_zipal_at'] == NULL || preg_match("|0000|",$zipalObj['add_to_zipal_at'])) { //$zipalObj['add_to_zipal_at'] = $zipalObj['created_at']; $ojb['zipal_active'] = 1; } $ojb['zipal_day'] = ceil(((strtotime($zipalObj['add_to_zipal_at']) + $zipalObj['days'] * 86400) - time()) / 86400); //$ojb['zipal_day']=10;//exit; if ($ojb['zipal_day'] > 0) { $ojb['zipal_day_text'] = declOfNum($ojb['zipal_day'], array('Остался %d день', 'Осталось %d дня', 'Осталось %d дней')); } else { $ojb['zipal_day_text'] = ""; } if ($ojb['zipal_day'] >= 1 && $ojb['zipal_day'] <= 5) { $ojb['zipal_active'] = 1; $html = ''.$ojb['zipal_day_text'].''; } elseif ($ojb['zipal_day'] > 5) { $ojb['zipal_active'] = 1; $html = ''.$ojb['zipal_day_text'].''; } else { $html = ''; if (!$zipalObj && $ojb['add_to_zipal'] == 1) { $ojb['zipal_active'] = 1; } } $ojb['error_text'] = null; if (!empty($zipalObj['error_text'])) { $error = json_decode(str_replace("\n", '', str_replace("\r", '', trim($zipalObj['error_text']))), true); if ($error['result']['status'] == 'ErrorPropertyResponseType') { $ojb['error_text'] = (array)$error['result']['error']; } } return [ 'html' => $html, 'error_text' => $ojb['error_text'], 'zipal_days' => $ojb['zipal_day'], 'zipal_days_text' => $ojb['zipal_day_text'], 'zipal_active' => $ojb['zipal_active'] ]; } /** * https://gist.github.com/Neolot/3964380 * $titles = array('Сидит %d котик', 'Сидят %d котика', 'Сидит %d котиков'); * * Функция склонения числительных в русском языке * * @param int $number Число которое нужно просклонять * @param array $titles Массив слов для склонения * @return string **/ function declOfNum($number, $titles) { $cases = array (2, 0, 1, 1, 1, 2); $format = $titles[ ($number%100 > 4 && $number %100 < 20) ? 2 : $cases[min($number%10, 5)] ]; return sprintf($format, $number); } function getNoImage() { echo '
'; } function clearInputData($mas) // очистка входящего массива { $mas2 = []; while (list($k, $el) = each($mas)) { if (!is_array($el)) { if($k != 'opis'){ $el = strip_tags($el); // от тегов $el = htmlspecialchars($el); // от кавычек и прочего $el = str_replace("\n", "
", $el); $el = str_replace("\r", "", $el); $el = stripslashes($el); // от слэшей } else { $el = str_replace("\n", "", $el); $el = str_replace("\r", "", $el); } $el = mysql_real_escape_string($el); // от MySQL-инъекций $el = trim($el); // от лишних пробелов } $mas2[$k] = $el; } return $mas2; } /* для домена joywork.ru: robot@joywork.ru/Niut3swec[ */ function mailClientById($userId, $address, $subject, $body, $paths = [], $adresses = [], $test = false) { require_once($_SERVER['DOCUMENT_ROOT'] . "/engine/mailer/PHPMailerAutoload.php"); $mail = new PHPMailer(); $user = new User; $user->get($userId); $mail->IsSMTP(); $mail->SMTPAuth = true; if ($user->smtp and $user->smtp_check != 2) { $mail->Host = $user->smtp; $mail->Port = $user->smtp_port; if ($user->smtp_ssl) { if ($user->smtp == 'smtp.gmail.com') { $mail->SMTPSecure = 'tls'; $mail->Port = 587; } else { $mail->SMTPSecure = 'ssl'; } } $lg = $user->smtp_lg; $pass = $user->smtp_pwd; $mail->From = $user->smtp_from; $mail->FromName = $user->smtp_fromname; $mail->Username = $lg; $mail->Password = $pass; } else { $lg = "robot@joywork.ru"; $mail->From = "robot@joywork.ru"; $mail->FromName = "JoyWork.ru"; $mail->Username = $lg; $mail->Password = '6@tMRdQbJbllKz#Y'; $mail->Port = 465; $mail->Host = 'smtp.yandex.ru'; $mail->SMTPSecure = 'ssl'; } //if($test) $mail->SMTPDebug = 1; // функция с параметром test используется в настройках почты $mail->isHTML(true); $mail->AddCustomHeader('X-Mailru-Msgtype: ' . md5($lg) . ';'); $mail->AddCustomHeader('X-Postmaster-Msgtype: ' . md5($lg) . ';'); //$mail->AddCustomHeader('Date: ' . date("D, d M y H:i:s O") . ';'); $mail->CharSet = "utf-8"; $mail->addAddress($address); $mail->Subject = $subject; $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->Body = $body; $mail->AltBody = "Это письмо сгенерировано в формате HTML. Ваш клиент не поддерживает HTML или эта функция выключена."; $mail->ClearAttachments(); foreach ($paths as $i => $path) { $num = $i + 1; $name = "$adresses[$i].pdf"; $mail->AddAttachment($path, $name); } if ($test) if ($mail->Send()) return true; else return $mail->ErrorInfo; else if ($mail->Send()) return true; else return mailClientPDF($mail->From, $address, $subject, $body, $paths, $adresses); } function mailClientByIdWithConfirm($userId, $address, $subject, $body, $paths = [], $adresses = [], $test = false, $pathAsPdf = true) { require_once($_SERVER['DOCUMENT_ROOT'] . "/engine/mailer/PHPMailerAutoload.php"); $mail = new PHPMailer(); $user = new User; $user->get($userId); $mail->IsSMTP(); $mail->SMTPAuth = true; if ($user->smtp and $user->smtp_check != 2) { $mail->Host = $user->smtp; $mail->Port = $user->smtp_port; if ($user->smtp_ssl) { if ($user->smtp == 'smtp.gmail.com') { $mail->SMTPSecure = 'tls'; $mail->Port = 587; } else { $mail->SMTPSecure = 'ssl'; } } $lg = $user->smtp_lg; $pass = $user->smtp_pwd; $mail->From = $user->smtp_from; $mail->FromName = $user->smtp_fromname; $mail->Username = $lg; $mail->Password = $pass; } else { $lg = "robot@joywork.ru"; $mail->From = "robot@joywork.ru"; $mail->FromName = "JoyWork.ru"; $mail->Username = $lg; $mail->Password = '6@tMRdQbJbllKz#Y'; $mail->Port = 465; $mail->Host = 'smtp.yandex.ru'; $mail->SMTPSecure = 'ssl'; } //if($test) $mail->SMTPDebug = 1; // функция с параметром test используется в настройках почты $mail->isHTML(true); $mail->AddCustomHeader('X-Mailru-Msgtype: ' . md5($lg) . ';'); $mail->AddCustomHeader('X-Postmaster-Msgtype: ' . md5($lg) . ';'); //$mail->AddCustomHeader('Date: ' . date("D, d M y H:i:s O") . ';'); $mail->CharSet = "utf-8"; $mail->addAddress($address); $mail->ConfirmReadingTo = $mail->From; $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->Subject = $subject; $mail->Body = $body; $mail->AltBody = "Это письмо сгенерировано в формате HTML. Ваш клиент не поддерживает HTML или эта функция выключена."; $mail->ClearAttachments(); foreach ($paths as $i => $path) { $num = $i + 1; if ($pathAsPdf) { $name = "$adresses[$i].pdf"; } else { $name = "$adresses[$i]"; } $mail->AddAttachment($path, $name); } if ($test) if ($mail->Send()) return true; else return $mail->ErrorInfo; else if ($mail->Send()) return true; else return mailClientPDF($mail->From, $address, $subject, $body, $paths, $adresses); } function mailClient($address, $subject, $body, $paths = [], $adresses = [], $test = false) { require_once($_SERVER['DOCUMENT_ROOT'] . "/engine/mailer/PHPMailerAutoload.php"); $mail = new PHPMailer(); $user = new User; $user->get($_SESSION['id']); $mail->IsSMTP(); $mail->SMTPAuth = true; if ($user->smtp and $user->smtp_check != 2) { $mail->Host = $user->smtp; $mail->Port = $user->smtp_port; if ($user->smtp_ssl) { if ($user->smtp == 'smtp.gmail.com') { $mail->SMTPSecure = 'tls'; $mail->Port = 587; } else { $mail->SMTPSecure = 'ssl'; } } $lg = $user->smtp_lg; $pass = $user->smtp_pwd; $mail->From = $user->smtp_from; $mail->FromName = $user->smtp_fromname; $mail->Username = $lg; $mail->Password = $pass; } else { $lg = "robot@joywork.ru"; $mail->From = "robot@joywork.ru"; $mail->FromName = "JoyWork.ru"; $mail->Username = $lg; $mail->Password = '6@tMRdQbJbllKz#Y'; $mail->Port = 465; $mail->Host = 'smtp.yandex.ru'; $mail->SMTPSecure = 'ssl'; } //if($test) $mail->SMTPDebug = 1; // функция с параметром test используется в настройках почты $mail->isHTML(true); $mail->AddCustomHeader('X-Mailru-Msgtype: ' . md5($lg) . ';'); $mail->AddCustomHeader('X-Postmaster-Msgtype: ' . md5($lg) . ';'); //$mail->AddCustomHeader('Date: ' . date("D, d M y H:i:s O") . ';'); $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->CharSet = "utf-8"; $mail->addAddress($address); $mail->Subject = $subject; $mail->Body = $body; $mail->AltBody = "Это письмо сгенерировано в формате HTML. Ваш клиент не поддерживает HTML или эта функция выключена."; $mail->ClearAttachments(); foreach ($paths as $i => $path) { $num = $i + 1; $name = "$adresses[$i].pdf"; $mail->AddAttachment($path, $name); } if ($test) if ($mail->Send()) return true; else return $mail->ErrorInfo; else if ($mail->Send()) return true; else return mailClientPDF($mail->From, $address, $subject, $body, $paths, $adresses); } function mailClientFromJoywork($address, $subject, $body, $paths = [], $adresses = [], $test = false) { require_once($_SERVER['DOCUMENT_ROOT'] . "/engine/mailer/PHPMailerAutoload.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $lg = "robot@joywork.ru"; $mail->From = "robot@joywork.ru"; $mail->FromName = "JoyWork.ru"; $mail->Username = $lg; $mail->Password = '6@tMRdQbJbllKz#Y'; $mail->Port = 465; $mail->Host = 'smtp.yandex.ru'; $mail->SMTPSecure = 'ssl'; if($test) $mail->SMTPDebug = 3; // функция с параметром test используется в настройках почты $mail->isHTML(true); $mail->AddCustomHeader('X-Mailru-Msgtype: ' . md5($lg) . ';'); $mail->AddCustomHeader('X-Postmaster-Msgtype: ' . md5($lg) . ';'); //$mail->AddCustomHeader('Date: ' . date("D, d M y H:i:s O") . ';'); $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->CharSet = "utf-8"; $mail->addAddress($address); $mail->Subject = $subject; $mail->Body = $body; $mail->AltBody = "Это письмо сгенерировано в формате HTML. Ваш клиент не поддерживает HTML или эта функция выключена."; $mail->ClearAttachments(); if (isset($paths) && $paths != null) { foreach ($paths as $i => $path) { $num = $i + 1; $name = "$adresses[$i].pdf"; $mail->AddAttachment($path, $name); } } return true; /*if ($test) if ($mail->Send()) return true; else return $mail->ErrorInfo; else if ($mail->Send()) return true; else return mailClientPDF($mail->From, $address, $subject, $body, $paths, $adresses);*/ } function mailClientPDF($from, $mail_to, $thema, $html, $paths = [], $adresses = []) { $from = '=?utf-8?B?' . base64_encode($from) . '?='; $thema = '=?utf-8?B?' . base64_encode($thema) . '?='; $EOL = "\r\n"; // ограничитель строк, некоторые почтовые сервера требуют \n - подобрать опытным путём $boundary = "--" . md5(uniqid(time())); // любая строка, которой не будет ниже в потоке данных. $headers = "MIME-Version: 1.0;$EOL"; $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"$EOL"; $headers .= "From: $from"; $multipart = "--$boundary$EOL"; $multipart .= "Content-Type: text/html; charset=utf-8$EOL"; $multipart .= "Content-Transfer-Encoding: base64$EOL"; $multipart .= $EOL; // раздел между заголовками и телом html-части $multipart .= chunk_split(base64_encode($html)); foreach ($paths as $i => $path) { $num = $i + 1; if ($path) { $fp = fopen($path, "rb"); $file = fread($fp, filesize($path)); fclose($fp); } $name = "$num.pdf"; // в этой переменной надо сформировать имя файла (без всякого пути) $multipart .= "$EOL--$boundary$EOL"; $multipart .= "Content-Type: application/octet-stream; name=\"$name\"$EOL"; $multipart .= "Content-Transfer-Encoding: base64$EOL"; $multipart .= "Content-Disposition: attachment; filename=\"$name\"$EOL"; $multipart .= $EOL; // раздел между заголовками и телом прикрепленного файла $multipart .= chunk_split(base64_encode($file)); } $multipart .= "$EOL--$boundary--$EOL"; if (!mail($mail_to, $thema, $multipart, $headers)) return False; else return True; exit; } function checkMail($address, $subject, $body) { require_once($_SERVER['DOCUMENT_ROOT'] . "/engine/mailer/PHPMailerAutoload.php"); $mail = new PHPMailer(); $user = new User; $user->get($_SESSION['id']); if ($_SESSION['id'] == 93) { $mail->SMTPDebug = 2; ini_set('display_errors', 1); error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); } $lg = $user->smtp_lg; $mail->IsSMTP(); if ($user->smtp) { $mail->Host = $user->smtp; $mail->Port = $user->smtp_port; if ($user->smtp_ssl) { if ($user->smtp == 'smtp.gmail.com') { $mail->SMTPSecure = 'tls'; $mail->Port = 587; } else { if ($user->smtp == 'smtp.office365.com') { $mail->SMTPSecure = 'tls'; } else { $mail->SMTPSecure = 'ssl'; } } } $mail->From = $user->smtp_from; $mail->FromName = $user->smtp_fromname; $mail->SMTPAuth = true; $mail->Username = $user->smtp_lg; $mail->Password = $user->smtp_pwd; $mail->isHTML(true); $mail->AddCustomHeader('X-Mailru-Msgtype: ' . md5($lg) . ';'); $mail->AddCustomHeader('X-Postmaster-Msgtype: ' . md5($lg) . ';'); //$mail->AddCustomHeader('Date: ' . date("D, d M y H:i:s O") . ';'); $mail->smtpConnect([ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ]); $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->CharSet = "utf-8"; $mail->addAddress($address); $mail->Subject = $subject; $mail->Body = $body; $mail->AltBody = "Это письмо сгенерировано в формате HTML. Ваш клиент не поддерживает HTML или эта функция выключена."; logf($mail); if ($mail->Send()) return true; else return $mail->ErrorInfo; } else return false; } function slugify($string) { $string = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $string); $string = preg_replace('/[-\s]+/', '-', $string); return trim($string, '-'); } function generatePass() { $arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9']; // Генерируем пароль $pass = ""; for ($i = 0; $i < 10; $i++) { // Вычисляем случайный индекс массива $index = rand(0, count($arr) - 1); $pass .= $arr[$index]; } return $pass; } function num_of_pages($page, $all_pages, $param = false) { if ($page == 1) { echo "
  • 1
  • "; } else { $prev = $page - 1; echo "
  • «
  • "; echo "
  • 1
  • "; } if ($all_pages > 8) { if ($page > 4) { $ot = $page - 3; echo "
  • ...
  • "; } else { $ot = 2; } if ($page < $all_pages - 4) { $do = $page + 3; } else { $do = $all_pages; } } else { $ot = 2; $do = $all_pages; } for ($i = $ot; $i < $do; $i++) { if ($i == $page) $cl = "active"; else $cl = ""; echo "
  • $i
  • "; } if ($all_pages > 8 and $page < $all_pages - 4) { echo "
  • ...
  • "; } if ($page == $all_pages) echo "
  • $all_pages
  • "; else { echo "
  • $all_pages
  • "; $nxt = $page + 1; echo "
  • »
  • "; } } function num_of_pages_for_ajax_with_class($page, $all_pages, $cssClass = '') { if ($page == 1) { echo "
  • 1
  • "; } else { $prev = $page - 1; echo "
  • «
  • "; echo "
  • 1
  • "; } if ($all_pages > 8) { if ($page > 4) { $ot = $page - 3; echo "
  • ...
  • "; } else { $ot = 2; } if ($page < $all_pages - 4) { $do = $page + 3; } else { $do = $all_pages; } } else { $ot = 2; $do = $all_pages; } for ($i = $ot; $i < $do; $i++) { if ($i == $page) { $cl = "active"; $clLink = ""; } else { $clLink = $cssClass; $cl = ""; } echo "
  • $i
  • "; } if ($all_pages > 8 and $page < $all_pages - 4) { echo "
  • ...
  • "; } if ($page == $all_pages) { echo "
  • $all_pages
  • "; } else { echo "
  • $all_pages
  • "; $nxt = $page + 1; echo "
  • »
  • "; } } function num_of_pages_for_ajax($page, $all_pages, $param = false) { if ($page == 1) { echo "
  • 1
  • "; } else { $prev = $page - 1; echo "
  • «
  • "; echo "
  • 1
  • "; } if ($all_pages > 8) { if ($page > 4) { $ot = $page - 3; echo "
  • ...
  • "; } else { $ot = 2; } if ($page < $all_pages - 4) { $do = $page + 3; } else { $do = $all_pages; } } else { $ot = 2; $do = $all_pages; } for ($i = $ot; $i < $do; $i++) { if ($i == $page) $cl = "active"; else $cl = ""; echo "
  • $i
  • "; } if ($all_pages > 8 and $page < $all_pages - 4) { echo "
  • ...
  • "; } if ($page == $all_pages) echo "
  • $all_pages
  • "; else { echo "
  • $all_pages
  • "; $nxt = $page + 1; echo "
  • »
  • "; } } function search_newbuildings($get) { $mas_usl_bd = ["1"]; $mas_url_add = array(); if (isset($get['stoim_ot']) && $get['stoim_ot']) { $stoim_ot = intval(str_replace(' ', '', $get['stoim_ot'])); $mas_usl_bd[] = "a.price >= " . $stoim_ot; $mas_url_add[] = "stoim_ot=$stoim_ot"; } if (isset($get['stoim_do']) && $get['stoim_do']) { $stoim_do = intval(str_replace(' ', '', $get['stoim_do'])); $mas_usl_bd[] = "a.price <= " . $stoim_do; $mas_url_add[] = "stoim_do=$stoim_do"; } if (isset($get['sq_all_ot']) && $get['sq_all_ot']) { $mas_usl_bd[] = "a.space_total >= " . $get['sq_all_ot']; $mas_url_add[] = "sq_all_ot=" . $get['sq_all_ot']; } if (isset($get['sq_all_do']) && $get['sq_all_do']) { $mas_usl_bd[] = "a.space_total <= " . $get['sq_all_do']; $mas_url_add[] = "sq_all_do=" . $get['sq_all_do']; } if (isset($get['flat_floor_ot']) && $get['flat_floor_ot']) { $mas_usl_bd[] = "a.flat_floor >= " . $get['flat_floor_ot']; $mas_url_add[] = "flat_floor_ot=" . $get['flat_floor_ot']; } if (isset($get['flat_floor_do']) && $get['flat_floor_do']) { $mas_usl_bd[] = "a.flat_floor <= " . $get['flat_floor_do']; $mas_url_add[] = "flat_floor_do=" . $get['flat_floor_do']; } if (isset($get['subway']) && $get['subway']) { $mas_usl_bd[] = "b.id in (select s.block_id from block_subways s where s.subway_id in (" . implode(",",$get['subway']) . "))"; foreach($get['subway'] as $subway) { $mas_url_add[] = "subway[]=" . $subway; } } if (isset($get['district']) && $get['district']) { $mas_usl_bd[] = "b.region_id in (" . implode(",",$get['district']) . ")"; foreach($get['district'] as $district) { $mas_url_add[] = "district[]=" . $district; } } if (isset($get['block']) && $get['block']) { $mas_usl_bd[] = "b.id in (" . implode(",",$get['block']) . ")"; foreach($get['block'] as $block) { $mas_url_add[] = "block[]=" . $block; } } if (isset($get['decoration']) && $get['decoration']) { $mas_usl_bd[] = "a.decoration_id in (" . implode(",",$get['decoration']) . ")"; foreach($get['decoration'] as $decoration) { $mas_url_add[] = "decoration[]=" . $decoration; } } if (isset($get['builder']) && $get['builder']) { $mas_usl_bd[] = "b.builder_id in (" . implode(",",$get['builder']) . ")"; foreach($get['builder'] as $builder) { $mas_url_add[] = "builder[]=" . $builder; } } if (isset($get['type']) && $get['type']) { $mas_usl_bd[] = "a.room_type_id in (" . implode(",",$get['type']) . ")"; foreach($get['type'] as $type) { $mas_url_add[] = "type[]=" . $type; } } if (isset($get['variant']) && $get['variant']) { $mas_usl_bd[] = "a.flat_type_id in (" . implode(",",$get['variant']) . ")"; foreach($get['variant'] as $variant) { $mas_url_add[] = "variant[]=" . $variant; } } if (isset($get['bank']) && $get['bank']) { $mas_usl_bd[] = "a.building_id in (select m.building_id from mortgages m where m.program_id in (select bp.id from bank_programs bp where bank_id in (" . implode(",",$get['bank']) . ")))"; foreach($get['bank'] as $bank) { $mas_url_add[] = "bank[]=" . $bank; } } if (isset($get['period']) && $get['period'] && $get['period'] > 0) { $mas_usl_bd[] = "a.building_id in (select bd.id from buildings bd where UNIX_TIMESTAMP(bd.deadline) <=" . $get['period'] . ")"; $mas_url_add[] = "period=" . $get['period']; } if (isset($get['adres']) && $get['adres']) { $get['adres'] = mb_strtolower($get['adres'], "UTF-8"); $mas_usl_bd[] = "b.address LIKE '%".$get['adres']."%'"; $mas_url_add[] = "adres=".$get['adres']; } $order = " ORDER BY b.id DESC "; return [$mas_usl_bd, $mas_url_add, $order]; } function search($get, $cron = false, $favor = [], $sphinx = false) { $mas_usl_bd = ["1"]; $mas_url_add = []; $mas_usl_sph = []; if ($get['object_id']) { $mas_usl_bd[] = "objects.id = " . $get['object_id']; $mas_url_add[] = "object_id = " . $get['object_id']; $mas_usl_sph[] = "id = " . $get['object_id']; } if ($get['type']) { $mas_usl_bd[] = "objects.type = " . $get['type']; $mas_url_add[] = "type=" . $get['type']; $mas_usl_sph[] = "type=" . $get['type']; } if ($_GET['metro']) { $metro = clearInputData($_GET['metro']); $usl_metro2 = []; foreach ($metro as $k => $v) { $mas_url_add[] = "metro[$k]=$v"; $usl_metro[] = "sp_metro.id_metro=" . $v; $usl_metro2[] = $v; } $usl_metro2 = array_unique($usl_metro2); $mas_usl_bd[] = "(" . implode(" OR ", $usl_metro) . ")"; $mas_usl_sph[] = "id_metro in (" . implode(",", $usl_metro2) . ")"; } if ($_GET['raion']) { $rayon = clearInputData($_GET['raion']); $usl_rayon2 = []; foreach ($rayon as $k => $v) { $mas_url_add[] = "raion[$k]=$v"; if($v == 0){ $usl_rayon[] = "objects.id_rf_region = $_GET[region_type]"; }else{ $usl_rayon[] = "objects.rayon = $v"; } $usl_rayon2[] = $v; } $usl_rayon2 = array_unique($usl_rayon2); $mas_usl_bd[] = "(" . implode(" OR ", $usl_rayon) . ")"; $mas_usl_sph[] = "rayon_id in (" . implode(",", $usl_rayon2) . ")"; } if ($_GET['renovation'] && ($get['type'] == 1 || $get['type'] == 3)) { $renovation = clearInputData($_GET['renovation']); $usl_renovation2 = []; foreach ($renovation as $k => $v) { $mas_url_add[] = "renovation[$k]=$v"; if($v == 0){ $usl_renovation[] = "objects.renovation = $_GET[renovation]"; }else{ $usl_renovation[] = "objects.renovation = $v"; } $usl_renovation2[] = $v; } $usl_renovation2 = array_unique($usl_renovation2); $mas_usl_bd[] = "(" . implode(" OR ", $usl_renovation) . ")"; $mas_usl_sph[] = "renovation in (" . implode(",", $usl_renovation2) . ")"; } if($_GET['commission']){ $commission = clearInputData($_GET['commission']); $mas_usl_bd[] = 'commission > 0'; $mas_usl_sph[] = 'commission > 0'; } // if($get['region_type']){ // $mas_usl_bd[] = "objects.id_rf_region = $get[region_type]"; // } if ($get['etazh']) { $mas_usl_bd[] = "objects.etazh > 1"; $mas_url_add[] = "etazh=1"; $mas_usl_sph[] = "etazh > 1"; $etazh = 1; } if ($get['house_type'] && $get['operation_type'] == 1) { if ($get['house_type'] != -1) { $mas_usl_bd[] = "sale_objects.house_type = " . $get['house_type']; $mas_url_add[] = "house_type=" . $get['house_type']; $mas_usl_sph[] = "house_type=" . $get['house_type']; } } if ($get['house_year'] && $get['operation_type'] == 1) { $mas_usl_bd[] = "sale_objects.build_year <= ".$get['house_year']; $mas_url_add[] = "house_year=".$get['house_year']; $mas_usl_sph[] = "build_year <= ".$get['house_year']; } if ($get['adres']) { $get['adres'] = mb_strtolower($get['adres'], "UTF-8"); $mas_usl_bd[] = "objects.adres LIKE '%".$get['adres']."%'"; $mas_url_add[] = "adres=".$get['adres']; $mas_url_add[] = "adres=" . $get['adres']; $adres_mas = explode(" ",$get['adres']); for($a = 0; $a < count($adres_mas); $a++){ if($adres_mas[$a]) { $mas_usl_sph['match'][] = "@adres " .trim(str_replace("/","-",$adres_mas[$a])); } } } if ($get['srok'] && $get['operation_type'] == 0) { $mas_usl_bd[] = "objects.srok = " . $get['srok']; $mas_url_add[] = "srok=" . $get['srok']; $mas_usl_sph[] = "srok=" . $get['srok']; } if ($get['minut']) { $mas_url_add[] = "minut=" . $get['minut']; $mas_url_add[] = "minut_t=" . $get['minut_t']; if ($get['minut_t'] == "peshkom") { $peshkom = $get['minut']; $mas_usl_bd[] = "objects.peshkom <= " . $get['minut'] . " AND transport = 0"; $mas_usl_sph[] = "peshkom <= " . $get['minut'] . " AND transport = 0"; } else { $transport = $get['minut']; $mas_usl_bd[] = "objects.transport <= " . $get['minut']; $mas_usl_sph[] = "transport <= " . $get['minut']; } } if ($get['sq_all_ot']) { if($get['type'] == 7) { $mas_usl_bd[] = "objects.land_area >= " . $get['sq_all_ot']; $mas_usl_sph[] = "land_area >= " . $get['sq_all_ot']; } else { $mas_usl_bd[] = "objects.ploshad >= " . $get['sq_all_ot']; $mas_usl_sph[] = "ploshad >= " . $get['sq_all_ot']; } $mas_url_add[] = "sq_all_ot=" . $get['sq_all_ot']; } if ($get['sq_all_do']) { if($get['type'] == 7) { $mas_usl_bd[] = "objects.land_area <= " . $get['sq_all_do']; $mas_usl_sph[] = "land_area <= " . $get['sq_all_do']; } else { $mas_usl_bd[] = "objects.ploshad <= " . $get['sq_all_do']; $mas_usl_sph[] = "ploshad <= " . $get['sq_all_do']; } $mas_url_add[] = "sq_all_do=" . $get['sq_all_do']; } if ($get['sq_land_ot']) { $mas_usl_bd[] = "objects.land_area >= " . $get['sq_land_ot']; $mas_usl_sph[] = "land_area >= " . $get['sq_land_ot']; $mas_url_add[] = "sq_land_ot=" . $get['sq_land_ot']; } if ($get['sq_land_do']) { $mas_usl_bd[] = "objects.land_area <= " . $get['sq_land_do']; $mas_usl_sph[] = "land_area <= " . $get['sq_land_do']; $mas_url_add[] = "sq_land_do=" . $get['sq_land_do']; } if ($get['etazh_ot'] || $get['etazh_ot_commerc']) { $etazh_ot = $get['etazh_ot']; if($get['etazh_ot_commerc']){ $etazh_ot = $get['etazh_ot_commerc']; $mas_url_add[] = "etazh_ot_commerc=" . $etazh_ot; } $mas_usl_bd[] = "objects.etazh >= " . $etazh_ot; $mas_usl_sph[] = "etazh >= " . $etazh_ot; if($get['etazh_ot']) { $mas_url_add[] = "etazh_ot=" . $etazh_ot; } } if ($get['etazh_do'] || $get['etazh_do_commerc']) { $etazh_do = $get['etazh_do']; if($get['etazh_do_commerc']){ $etazh_do = $get['etazh_do_commerc']; $mas_url_add[] = "etazh_do_commerc=" . $etazh_do; } $mas_usl_bd[] = "objects.etazh <= " . $etazh_do; $mas_usl_sph[] = "etazh <= " . $etazh_do; if($get['etazh_do']) { $mas_url_add[] = "etazh_do=" . $etazh_do; } } if ($get['year_ot']) { $mas_usl_bd[] = "sale_objects.build_year >= " . $get['year_ot']; $mas_usl_sph[] = "build_year >= " . $get['year_ot']; if($get['year_ot']) { $mas_url_add[] = "year_ot=" . $get['year_ot']; } } if ($get['year_do']) { $mas_usl_bd[] = "sale_objects.build_year <= " . $get['year_do']; $mas_usl_sph[] = "build_year <= " . $get['year_do']; if($get['year_do']) { $mas_url_add[] = "year_do=" . $get['year_do']; } } if ($get['etazh_not_first']) { $mas_usl_bd[] = "objects.etazh <> 1"; $mas_url_add[] = "etazh_not_first=1"; $mas_usl_sph[] = "etazh <> 1"; } if ($get['etazh_not_last']) { $mas_usl_bd[] = "objects.etazh <> objects.etazh_iz"; $mas_url_add[] = "etazh_not_last=1"; $mas_usl_sph[] = "not_last_floor = 1"; } if ($get['sq_live_ot'] && $get['operation_type'] == 1) { $mas_usl_bd[] = "objects.ploshad_komn >= " . $get['sq_live_ot']; $mas_usl_sph[] = "ploshad_komn >= " . $get['sq_live_ot']; $mas_url_add[] = "sq_live_ot=" . $get['sq_live_ot']; } if ($get['sq_live_do'] && $get['operation_type'] == 1) { $mas_usl_bd[] = "objects.ploshad_komn <= " . $get['sq_live_do']; $mas_usl_sph[] = "ploshad_komn <= " . $get['sq_live_do']; $mas_url_add[] = "sq_live_do=" . $get['sq_live_do']; } if ($get['sq_kitch_ot'] && $get['operation_type'] == 1) { $mas_usl_bd[] = "objects.ploshad_k >= " . $get['sq_kitch_ot']; $mas_usl_sph[] = "ploshad_k >= " . $get['sq_kitch_ot']; $mas_url_add[] = "sq_kitch_ot=" . $get['sq_kitch_ot']; } if ($get['sq_kitch_do'] && $get['operation_type'] == 1) { $mas_usl_bd[] = "objects.ploshad_k <= " . $get['sq_kitch_do']; $mas_usl_sph[] = "ploshad_k <= " . $get['sq_kitch_do']; $mas_url_add[] = "sq_kitch_do=" . $get['sq_kitch_do']; } //фильтр в сфинксе - в части SELECT, см search_form.php if ($get['rn1'] || $get['rn2'] || $get['rn3'] || $get['rn4'] || $get['rnStudio']) { if (!$get['rnStudio']) { //ищем только по количеству комнат, не студии $numKomn = array(); if ($get['rn1']) { $numKomn[] = 1; $mas_url_add[] = "rn1=1"; } if ($get['rn2']) { $numKomn[] = 2; $mas_url_add[] = "rn2=1"; } if ($get['rn3']) { $numKomn[] = 3; $mas_url_add[] = "rn3=1"; } if ($get['rn4']) { for ($i = 4; $i <= 127; $i++) { $numKomn[] = $i; } $mas_url_add[] = "rn4=1"; } $mas_usl_bd[] = "objects.komnat in (" .implode(',', $numKomn).")"; } else { if ($get['rn1'] || $get['rn2'] || $get['rn3'] || $get['rn4']) { //формируем комнаты $numKomn = array(); if ($get['rn1']) { $numKomn[] = 1; $mas_url_add[] = "rn1=1"; } if ($get['rn2']) { $numKomn[] = 2; $mas_url_add[] = "rn2=1"; } if ($get['rn3']) { $numKomn[] = 3; $mas_url_add[] = "rn3=1"; } if ($get['rn4']) { for ($i = 4; $i <= 127; $i++) { $numKomn[] = $i; } $mas_url_add[] = "rn4=1"; } $mas_usl_bd[] = "(objects.studio_flag=1 OR objects.komnat in (" .implode(',', $numKomn)."))"; } else { $mas_usl_bd[] = "objects.studio_flag=1"; } $mas_url_add[] = "rnStudio=1"; } } if ($get['komn_ot']) { $mas_usl_bd[] = "objects.komnat >= " . $get['komn_ot']; $mas_usl_sph[] = "komnat >= " . $get['komn_ot']; $mas_url_add[] = "komn_ot=" . $get['komn_ot']; } if ($get['komn_do']) { $mas_usl_bd[] = "objects.komnat <= " . $get['komn_do']; $mas_usl_sph[] = "komnat <= " . $get['komn_do']; $mas_url_add[] = "komn_do=" . $get['komn_do']; } if ($get['ploshad']) { $get['ploshad'] = str_replace(",", ".", $get['ploshad']); $mas_usl_bd[] = "objects.ploshad >= " . $get['ploshad']; $mas_usl_sph[] = "ploshad >= " . $get['ploshad']; $mas_url_add[] = "ploshad=" . $get['ploshad']; } if ($get['ploshad_k']) { $get['ploshad_k'] = str_replace(",", ".", $get['ploshad_k']); $mas_usl_bd[] = "objects.ploshad_k >= " . $get['ploshad_k']; $mas_usl_sph[] = "ploshad_k >= " . $get['ploshad_k']; $mas_url_add[] = "ploshad_k=" . $get['ploshad_k']; } if ($get['holod']) { //$mas_usl_bd[] = "objects.holod = 1"; $mas_url_add[] = "holod=1"; $holod = 1; } else $holod = 0; if ($get['stirka']) { ///$mas_usl_bd[] = "objects.stirka = 1"; $mas_url_add[] = "stirka=1"; $stirka = 1; } else $stirka = 0; if ($get['tv']) { //$mas_usl_bd[] = "objects.tv = 1"; $mas_url_add[] = "tv=1"; $tv = 1; } else $tv = 0; if ($get['mebel']) { //$mas_usl_bd[] = "objects.mebel = 1"; $mas_url_add[] = "mebel=1"; $mebel = 1; } else $mebel = 0; if ($get['holod'] or $get['stirka'] or $get['tv'] or $get['mebel']) { $mas_usl_bd[] = "objects.mebel = '$mebel' AND objects.tv = '$tv' AND objects.stirka = '$stirka' AND objects.holod = '$holod'"; $mas_usl_sph[] = "mebel = '$mebel' AND tv = '$tv' AND stirka = '$stirka' AND holod = '$holod'"; } if($get['use_area_price']) { if ($get['stoim_ot']) { $stoim_ot = intval(str_replace(' ', '', $get['stoim_ot'])); $mas_usl_bd[] = "objects.stoim / objects.ploshad >= " . $stoim_ot; $mas_usl_sph[] = "area_price >= " . $stoim_ot; $mas_url_add[] = "stoim_ot=$stoim_ot"; } if ($get['stoim_do']) { $stoim_do = intval(str_replace(' ', '', $get['stoim_do'])); $mas_usl_bd[] = "objects.stoim / objects.ploshad <= " . $stoim_do; $mas_usl_sph[] = "area_price <= " . $stoim_do; $mas_url_add[] = "stoim_do=$stoim_do"; } } else { if ($get['stoim_ot']) { $stoim_ot = intval(str_replace(' ', '', $get['stoim_ot'])); $mas_usl_bd[] = "objects.stoim >= " . $stoim_ot; $mas_usl_sph[] = "price_for_order >= " . $stoim_ot; $mas_url_add[] = "stoim_ot=$stoim_ot"; } if ($get['stoim_do']) { $stoim_do = intval(str_replace(' ', '', $get['stoim_do'])); $mas_usl_bd[] = "objects.stoim <= " . $stoim_do; $mas_usl_sph[] = "price_for_order <= " . $stoim_do; $mas_url_add[] = "stoim_do=$stoim_do"; } } if ($get['date_add']) { list($d, $m, $y) = explode(".", $get['date_add']); $date_tm = mktime(0, 0, 0, $m, $d, $y); $date_ot = "$y-$m-$d"; $mas_usl_bd[] = "UNIX_TIMESTAMP(objects.date_add) >= " . $date_tm; $mas_usl_sph[] = "date_add >= " . $date_tm; $mas_url_add[] = "date_add=" . $get['date_add']; } if ($get['date_from']) { list($d, $m, $y) = explode(".", $get['date_from']); $date_tm = mktime(0, 0, 0, $m, $d, $y); $mas_usl_bd[] = "UNIX_TIMESTAMP(objects.date_add) >= " . $date_tm; $mas_usl_sph[] = "date_add >= " . $date_tm; $mas_url_add[] = "date_from=" . $get['date_from']; } if ($get['credit'] && $get['operation_type'] == 1) { $mas_usl_bd[] = "objects.stoim_prim like '%ипотека%'"; $mas_usl_sph['match'][] = "@stoim_prim ипотека"; $mas_url_add[] = "credit=1"; } //&& $get['operation_type'] == 1 if ($get['withCommission']) { $mas_usl_bd[] = "objects.commission > 0"; $mas_usl_sph[] = "commission > 0"; $mas_url_add[] = "withCommission=1"; } if ($get['photo']) { $ph = []; for ($i = 1; $i <= 20; $i++) $ph[] = "objects.photo$i<>''"; $mas_usl_bd[] = "(" . implode(" OR ", $ph) . ")"; $mas_usl_sph[] = "is_photo=1"; $mas_url_add[] = "photo=1"; $photo = 1; } if ($get['favor']) { if (isset($favor) && count($favor) > 0) { $mas_usl_bd[] = "(objects.id=" . implode(" OR objects.id=", $favor) . ")"; } else { $mas_usl_bd[] = "objects.id < 0"; } $mas_url_add[] = "favor=1"; } if ($get['compObj']) { $mas_usl_bd[] = "(objects.id_add_user in (SELECT id FROM `users` WHERE id = '$get[agencyId]' or id_manager = '$get[agencyId]' or id_manager in (select id from users where id_manager = '$get[agencyId]')))"; if($sphinx){ //$users_sp = array(); $depClass = new Department(); $adminDep = false; $searchUserId = $get['agencyId']; $agentIds = []; $user = new User; $user->get($searchUserId); $searchUserId = $user->agencyId; $agentIds[] = $user->agencyId; /*$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; }*/ //$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'] || $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']; } } } } } } } //} /*$sql_usr = "SELECT id FROM `users` WHERE id = '$get[agencyId]' or id_manager = '$get[agencyId]' or id_manager in (select id from users where id_manager = '$get[agencyId]')"; if($_SESSION['id'] == 11583){ echo $sql_usr; } $q_usr = mysql_query($sql_usr); $rows = mysql_num_rows($q_usr); if($rows > 0){ while($row = mysql_fetch_assoc($q_usr)){ $users_sp[] = $row['id']; } }*/ //if(empty($users_sp)) $users_sp[] = $get['agencyId']; $mas_usl_sph[] = "id_add_user in (".implode(',', $agentIds).")"; } $mas_url_add[] = "compObj=1"; } if ($get['compObj'] && $get['inAdvert']) { $mas_usl_bd[] = "objects.use_in_advert > 0"; $mas_usl_sph[] = "use_in_advert > 0"; $mas_url_add[] = "inAdvert=1"; } if ($get['compObj'] && $get['search_obj_filter_emp']) { $empWho = array(); foreach($get['search_obj_filter_emp'] 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 { $empWho[] = $empId; } $mas_url_add[] = "search_obj_filter_emp[]=$empId"; } if (!empty($empWho)) { $mas_usl_sph[] = "id_add_user IN (" . implode(", ", $empWho) . ")"; $mas_usl_bd[] = " objects.id_add_user IN (" . implode(", ", $empWho) . ")"; } } if ($get['compObj'] && $get['search_filter_object_activities']) { $activities = $get['search_filter_object_activities']; // Проверяем наличие "no_tags" $noTagsKey = array_search('no_tags', $activities); $hasNoTags = ($noTagsKey !== false); if ($hasNoTags) { unset($activities[$noTagsKey]); } $db_sphinx_local = new MysqlPdo(hstsph, null, null, null, true, '9306'); if ($hasNoTags && !empty($activities)) { $objWithTags = array(); if (!empty($activities)) { $sql_a = "SELECT object_id FROM objects_activities WHERE activity_id IN (" . implode(", ", $activities) . ")"; $q_a = mysql_query($sql_a); if ($q_a) { while($r_a = mysql_fetch_row($q_a)){ $objWithTags[] = $r_a[0]; } } } $base_sphinx_conditions = implode(" ", $mas_usl_sph); $base_sphinx_conditions = trim($base_sphinx_conditions); $where_clause = ""; if ($base_sphinx_conditions !== '') { $where_clause = $base_sphinx_conditions . " AND has_activities = 0"; } else { $where_clause = "has_activities = 0"; } $sql_no_tags_ids = "SELECT id FROM objects WHERE $where_clause AND has_activities = 0 LIMIT 10000 OPTION max_matches=10000"; $result_no_tags = $db_sphinx_local->query($sql_no_tags_ids, true); $ids_no_tags = array(); if ($result_no_tags) { while ($row = $db_sphinx_local->fetch_assoc($result_no_tags)) { $ids_no_tags[] = $row['id']; } } $allIds = array_merge($ids_no_tags, $objWithTags); $allIds = array_unique($allIds); if (!empty($allIds)) { $mas_usl_sph[] = "id IN (" . implode(", ", $allIds) . ")"; $mas_usl_bd[] = " objects.id IN (" . implode(", ", $allIds) . ")"; } else { $mas_usl_sph[] = "id IN (0)"; $mas_usl_bd[] = " objects.id IN (0)"; } } elseif ($hasNoTags) { $mas_usl_sph[] = "has_activities = 0"; $sql_no_tags_ids_mysql = "SELECT id FROM objects WHERE has_activities = 0 LIMIT 10000 OPTION max_matches=10000"; $result_no_tags_mysql = $db_sphinx_local->query($sql_no_tags_ids_mysql, true); $ids_no_tags_mysql = array(); if ($result_no_tags_mysql) { while ($row = $db_sphinx_local->fetch_assoc($result_no_tags_mysql)) { $ids_no_tags_mysql[] = $row['id']; } } if (!empty($ids_no_tags_mysql)) { $mas_usl_bd[] = " objects.id IN (" . implode(", ", $ids_no_tags_mysql) . ")"; } else { $mas_usl_bd[] = " objects.id IN (0)"; } } elseif (!empty($activities)) { $a_arr = array(); $sql_a = "SELECT object_id FROM objects_activities WHERE activity_id IN (" . implode(", ", $activities) . ")"; $q_a = mysql_query($sql_a); if ($q_a) { while($r_a = mysql_fetch_row($q_a)){ $a_arr[] = $r_a[0]; } } if (!empty($a_arr)) { $mas_usl_sph[] = "id IN (" . implode(", ", $a_arr) . ")"; $mas_usl_bd[] = " objects.id IN (" . implode(", ", $a_arr) . ")"; } else { $mas_usl_sph[] = "id IN (0)"; $mas_usl_bd[] = " objects.id IN (0)"; } } } if ($get['compObj'] && $get['search_filter_object_villages']) { $villages = $get['search_filter_object_villages']; if (!empty($villages)) { $mas_usl_sph[] = "cottage_village_id IN (" . implode(", ", $villages) . ")"; $mas_usl_bd[] = " objects.cottage_village_id IN (" . implode(", ", $villages) . ")"; } } if ($get['compObj'] && $get['search_filter_object_highways']) { $highways = $get['search_filter_object_highways']; if (!empty($highways)) { $mas_usl_sph[] = "highway_id IN (" . implode(", ", $highways) . ")"; $mas_usl_bd[] = " objects.highway_id IN (" . implode(", ", $highways) . ")"; } } if ($get['compObj'] && $get['house_category']) { $house_category = $get['house_category']; if (!empty($house_category)) { $mas_usl_sph[] = "house_category IN (" . implode(", ", $house_category) . ")"; $mas_usl_bd[] = " objects.house_category IN (" . implode(", ", $house_category) . ")"; } } if($get['parent_region']){ $mas_usl_bd[] = "objects.id_rf_region IN (SELECT id FROM rf_regions WHERE id=$get[parent_region] or parent=$get[parent_region])"; if($get['country']){ if($get['country'] == 171){ $mas_usl_sph['match'][] = "@(id_rf_region,parent) $get[parent_region]"; $mas_usl_sph[] = "country_id = 171"; } else { $mas_usl_sph['match'][] = "@(id_rf_region,parent) 0"; $mas_usl_sph[] = "country_id = {$get['country']}"; } $mas_url_add[] = "country=".$get['country']; } else { $mas_usl_sph['match'][] = "@(id_rf_region,parent) $get[parent_region]"; $mas_usl_sph[] = "country_id = 171"; } } /*if($get['country']){ $listCountry = clearInputData($_GET['country']); if(!in_array(171, $listCountry)){ $idOBJC = array(); $sql_c = "SELECT object_id FROM object_country WHERE country_id in (".implode(',', $listCountry).")"; $q_c = mysql_query($sql_c); while($r_c = mysql_fetch_assoc($q_c)){ $idOBJC[] = $r_c['object_id']; } if(!empty($idOBJC)){ $mas_usl_sph[] = "id in (".implode(',',$idOBJC).")"; } else { $mas_usl_sph[] = "id in (0)"; } } }*/ if ($get['typeCategory'] && $get['type'] == 4) { $mas_usl_bd[] = "objects.type_category IN (". implode(", ", $get['typeCategory']) . ")"; $mas_usl_sph[] = "type_category IN (". implode(", ", $get['typeCategory']) . ")"; foreach ($get['typeCategory'] as $category) { $mas_url_add[] = "typeCategory[]=$category"; } } if($get['opis']){ $mas_usl_sph['match'][] = "@opis " . $get['opis']; $mas_url_add[] = "opis=$get[opis]"; } if($get['type'] == 4 ){ if($get['tax_number']){ $mas_usl_bd[] = "a.tax_number = " . $get['tax_number']; $mas_usl_sph['match'][] = "@tax_number " . $get['tax_number']; } if($get['legal_address']){ $mas_usl_bd[] = "a.legal_address = " .$get['legal_address']; $mas_usl_sph[] = "legal_address = " .$get['legal_address']; } if($get['etazh']){ $mas_usl_bd[] = "objects.etazh = " . $get['etazh']; $mas_usl_sph[] = "etazh = " . $get['etazh']; } if($get['isOccupied']){ $mas_usl_bd[] = "a.isOccupied = " .($get['isOccupied']-1); $mas_usl_sph[] = "isOccupied = " .($get['isOccupied']-1); } if($get['layout_id']){ $mas_usl_bd[] = "a.layout_id = " .$get['layout_id']; $mas_usl_sph[] = "layout_id = " .$get['layout_id']; } if($get['number_wet_spots']){ $mas_usl_bd[] = "a.number_wet_spots = " .$get['number_wet_spots']; $mas_usl_sph[] = "number_wet_spots = " .$get['number_wet_spots']; } if($get['electricity_power_ot']){ $mas_usl_bd[] = "a.electricity_power >= " .$get['electricity_power_ot']; $mas_usl_sph[] = "electricity_power >= " .$get['electricity_power_ot']; } if($get['electricity_power_do']){ $mas_usl_bd[] = "a.electricity_power <= " .$get['electricity_power_do']; $mas_usl_sph[] = "electricity_power <= " .$get['electricity_power_do']; } if($get['commer_condition']){ $mas_usl_bd[] = "a.commer_condition in (".implode(',',$get['commer_condition']).")"; $mas_usl_sph[] = "commer_condition in (".implode(',',$get['commer_condition']).")"; } if($get['isFurniture']){ $mas_usl_bd[] = "a.isFurniture = " .($get['isFurniture']-1); $mas_usl_sph[] = "isFurniture = " .($get['isFurniture']-1); } if($get['commer_access']){ $mas_usl_bd[] = "a.commer_access = " .$get['commer_access']; $mas_usl_sph[] = "commer_access = " .$get['commer_access']; } if($get['cadastral_number']){ $mas_usl_bd[] = "objects.cadastral_number = " .$get['cadastral_number']; $mas_usl_sph['match'][] = "@cadastral_number " .$get['cadastral_number']; } if($get['parking_type_id']){ $mas_usl_bd[] = "objects.parking_type_id in (".implode(',',$get['parking_type_id']).")"; $mas_usl_sph[] = "parking_type_id in (".implode(',',$get['parking_type_id']).")"; } if($get['parking_price']){ $mas_usl_bd[] = "a.parking_price = " .$get['parking_price']; $mas_usl_sph[] = "parking_price = " .$get['parking_price']; } if($get['parkingIsFree']){ $mas_usl_bd[] = "a.parkingIsFree = " .$get['parkingIsFree']; $mas_usl_sph[] = "parkingIsFree = " .$get['parkingIsFree']; } if (isset($get['ceiling_height_ot']) && $get['ceiling_height_ot']) { $mas_usl_bd[] = "a.ceiling_height >= " . $get['ceiling_height_ot']; $mas_usl_sph[] = "ceiling_height >= " . $get['ceiling_height_ot']; $mas_url_add[] = "ceiling_height_ot=" . $get['ceiling_height_ot']; } if (isset($get['ceiling_height_do']) && $get['ceiling_height_do']) { $mas_usl_bd[] = "a.ceiling_height <= " . $get['ceiling_height_do']; $mas_usl_sph[] = "ceiling_height <= " . $get['ceiling_height_do']; $mas_url_add[] = "ceiling_height_do=" . $get['ceiling_height_do']; } if($get['column_grid']){ $mas_usl_bd[] = "a.column_grid = ".$get['column_grid']; $mas_usl_sph[] = "column_grid = ".$get['column_grid']; } if($get['vat_type_id']){ $mas_usl_bd[] = "a.vat_type_id = ".$get['vat_type_id']; $mas_usl_sph[] = "vat_type_id = ".$get['vat_type_id']; } if($get['commerc_site']){ $mas_usl_bd[] = "a.commerc_site = ".$get['commerc_site']; $mas_usl_sph[] = "commerc_site = ".$get['commerc_site']; } if(isset($get['commerc_owned'])){ $mas_usl_bd[] = "a.commerc_owned = ".$get['commerc_owned']; $mas_usl_sph[] = "commerc_owned = ".$get['commerc_owned']; } if($get['floor_material_id']){ $mas_usl_bd[] = "a.floor_material_id in (".implode(',',$get['floor_material_id']).")"; $mas_usl_sph[] = "floor_material_id in (".implode(',',$get['floor_material_id']).")"; } if($get['commerc_portal_id']){ $mas_usl_bd[] = "a.commerc_portal_id in (".implode(',',$get['commerc_portal_id']).")"; $mas_usl_sph[] = "commerc_portal_id in (".implode(',',$get['commerc_portal_id']).")"; } if($get['commerc_land_category_id']){ $mas_usl_bd[] = "a.commerc_land_category_id in (".implode(',',$get['commerc_land_category_id']).")"; $mas_usl_sph[]= "commerc_land_category_id in (".implode(',',$get['commerc_land_category_id']).")"; } if($get['commerc_permitted_use_id']){ $mas_usl_bd[] = "a.commerc_permitted_use_id in (".implode(',',$get['commerc_permitted_use_id']).")"; $mas_usl_sph[] = "commerc_permitted_use_id in (".implode(',',$get['commerc_permitted_use_id']).")"; } if($get['commerc_lift1']){ $mas_usl_bd[] = "a.commerc_lift1 = ".$get['commerc_lift1']; $mas_usl_sph[] = "commerc_lift1 = ".$get['commerc_lift1']; } if($get['lift1_carrying']){ $mas_usl_bd[] = "a.lift1_carrying = ".$get['lift1_carrying']; $mas_usl_sph[] = "lift1_carrying = ".$get['lift1_carrying']; } if($get['commerc_lift2']){ $mas_usl_bd[] = "a.commerc_lift2 = ".$get['commerc_lift2']; $mas_usl_sph[] = "commerc_lift2 = ".$get['commerc_lift2']; } if($get['lift2_carrying']){ $mas_usl_bd[] = "a.lift2_carrying = ".$get['lift2_carrying']; $mas_usl_sph[] = "lift2_carrying = ".$get['lift2_carrying']; } if($get['commerc_lift3']){ $mas_usl_bd[] = "a.commerc_lift3 = ".$get['commerc_lift3']; $mas_usl_sph[] = "commerc_lift3 = ".$get['commerc_lift3']; } if($get['lift3_carrying']){ $mas_usl_bd[] = "a.lift3_carrying = ".$get['lift3_carrying']; $mas_usl_sph[] = "lift3_carrying = ".$get['lift3_carrying']; } if($get['commerc_crane1']){ $mas_usl_bd[] = "a.commerc_crane1 = ".$get['commerc_crane1']; $mas_usl_sph[] = "commerc_crane1 = ".$get['commerc_crane1']; } if($get['crane1_carrying']){ $mas_usl_bd[] = "a.crane1_carrying = ".$get['crane1_carrying']; $mas_usl_sph[] = "crane1_carrying = ".$get['crane1_carrying']; } if($get['commerc_crane2']){ $mas_usl_bd[] = "a.commerc_crane2 = ".$get['commerc_crane2']; $mas_usl_sph[] = "commerc_crane2 = ".$get['commerc_crane2']; } if($get['crane2_carrying']){ $mas_usl_bd[] = "a.crane2_carrying = ".$get['crane2_carrying']; $mas_usl_sph[] = "crane2_carrying = ".$get['crane2_carrying']; } if($get['commerc_crane3']){ $mas_usl_bd[] = "a.commerc_crane3 = ".$get['commerc_crane3']; $mas_usl_sph[] = "commerc_crane3 = ".$get['commerc_crane3']; } if($get['crane3_carrying']){ $mas_usl_bd[] = "a.crane3_carrying = ".$get['crane3_carrying']; $mas_usl_sph[] = "crane3_carrying = ".$get['crane3_carrying']; } if($get['commerc_crane4']){ $mas_usl_bd[] = "a.commerc_crane4 = ".$get['commerc_crane4']; $mas_usl_sph[] = "commerc_crane4 = ".$get['commerc_crane4']; } if($get['crane4_carrying']){ $mas_usl_bd[] = "a.crane4_carrying = ".$get['crane4_carrying']; $mas_usl_sph[] = "crane4_carrying = ".$get['crane4_carrying']; } if($get['commerc_electricity_id']){ $mas_usl_bd[] = "a.commerc_electricity_id = ".$get['commerc_electricity_id']; $mas_usl_sph[] = "commerc_electricity_id = ".$get['commerc_electricity_id']; } if($get['commerc_gas_id']){ $mas_usl_bd[] = "a.commerc_gas_id = ".$get['commerc_gas_id']; $mas_usl_sph[] = "commerc_gas_id = ".$get['commerc_gas_id']; } if($get['commerc_water_id']){ $mas_usl_bd[] = "a.commerc_water_id = ".$get['commerc_water_id']; $mas_usl_sph[] = "commerc_water_id = ".$get['commerc_water_id']; } if($get['commerc_sewage_id']){ $mas_usl_bd[] = "a.commerc_sewage_id = ".$get['commerc_sewage_id']; $mas_usl_sph[] = "commerc_sewage_id = ".$get['commerc_sewage_id']; } if($get['commerc_driveways_id']){ $mas_usl_bd[] = "a.commerc_driveways_id = ".$get['commerc_driveways_id']; $mas_usl_sph[] = "commerc_driveways_id = ".$get['commerc_driveways_id']; } if($get['commerc_year_ot']){ $mas_usl_bd[] = "a.commerc_year >= " .$get['commerc_year_ot']; $mas_usl_sph[] = "commerc_year >= " .$get['commerc_year_ot']; } if($get['commerc_year_do']){ $mas_usl_bd[] = "a.commerc_year <= " .$get['commerc_year_do']; $mas_usl_sph[] = "commerc_year <= " .$get['commerc_year_do']; } if($get['commerc_building_type_id']){ $mas_usl_bd[] = "a.commerc_building_type_id in (".implode(',',$get['commerc_building_type_id']).")"; $mas_usl_sph[] = "commerc_building_type_id in (".implode(',',$get['commerc_building_type_id']).")"; } if($get['commerc_building_class_id']){ $mas_usl_bd[] = "a.commerc_building_class_id in (".implode(',',$get['commerc_building_class_id']).")"; $mas_usl_sph[] = "commerc_building_class_id in (".implode(',',$get['commerc_building_class_id']).")"; } if($get['commerc_specifications']){ $mas_usl_bd[] = "(commerc_specifications like '%".implode('%\' or commerc_specifications like \'%' ,$get['commerc_specifications'])."%')"; $mas_usl_sph['match'][] = "@commerc_specifications (".implode(' | ', $get['commerc_specifications']).")"; } if($get['commerc_purpose']){ $mas_usl_bd[] = "(a.commerc_purpose like '%\"".implode('"%\' or commerc_purpose like \'%"' ,$get['commerc_purpose'])."\"%')"; $mas_usl_sph['match'][] = "@commerc_purpose (".implode(' | ' ,$get['commerc_purpose']).")"; } if($get['commerc_infrastructure']){ $mas_usl_bd[] = "(a.commerc_infrastructure like '%\"".implode('"%\' or commerc_infrastructure like \'%"' ,$get['commerc_infrastructure'])."\"%')"; $mas_usl_sph['match'][] = "@commerc_infrastructure ".implode(' | ',$get['commerc_infrastructure']).")"; } if($get['commerc_infrastructure1']){ $mas_usl_bd[] = "(a.commerc_infrastructure like '%\"".implode('"%\' or commerc_infrastructure like \'%"' ,$get['commerc_infrastructure1'])."\"%')"; $mas_usl_sph['match'][] = "@commerc_infrastructure ".implode(' | ',$get['commerc_infrastructure']).")"; } if($get['commerc_infrastructure2']){ $mas_usl_bd[] = "(a.commerc_infrastructure like '%\"".implode('"%\' or commerc_infrastructure like \'%"' ,$get['commerc_infrastructure2'])."\"%')"; $mas_usl_sph['match'][] = "@commerc_infrastructure ".implode(' | ',$get['commerc_infrastructure']).")"; } if (isset($get['building_area_ot']) && $get['building_area_ot']) { $mas_usl_bd[] = "a.building_area >= " . $get['building_area_ot']; $mas_usl_sph[] = "building_area >= " . $get['building_area_ot']; $mas_url_add[] = "building_area_ot=" . $get['building_area_ot']; } if (isset($get['building_area_do']) && $get['building_area_do']) { $mas_usl_bd[] = "a.building_area <= " . $get['building_area_do']; $mas_usl_sph[] = "building_area <= " . $get['building_area_do']; $mas_url_add[] = "building_area_do=" . $get['building_area_do']; } if($get['commerc_houseLineType_id']){ $mas_usl_bd[] = "a.commerc_houseLineType_id in (".implode(',',$get['commerc_houseLineType_id']).")"; $mas_usl_sph[] = "commerc_houseLineType_id in (".implode(',',$get['commerc_houseLineType_id']).")"; } if($get['commerc_building_category_id']){ $mas_usl_bd[] = "a.commerc_building_category_id = ".$get['commerc_building_category_id']; $mas_usl_sph[] = "commerc_building_category_id = ".$get['commerc_building_category_id']; } if($get['commerc_opened_id']){ $mas_usl_bd[] = "a.commerc_opened_id in (".implode(',',$get['commerc_opened_id']).")"; $mas_usl_sph[] = "commerc_opened_id in (".implode(',',$get['commerc_opened_id']).")"; } if($get['commerc_building_ventilation']){ $mas_usl_bd[] = "a.commerc_building_ventilation = ".$get['commerc_building_ventilation']; $mas_usl_sph[] = "commerc_building_ventilation = ".$get['commerc_building_ventilation']; } if($get['commerc_building_conditioning']){ $mas_usl_bd[] = "a.commerc_building_conditioning = ".$get['commerc_building_conditioning']; $mas_usl_sph[] = "commerc_building_conditioning = ".$get['commerc_building_conditioning']; } if($get['commerc_building_heating']){ $mas_usl_bd[] = "a.commerc_building_heating = ".$get['commerc_building_heating']; $mas_usl_sph[] = "commerc_building_heating = ".$get['commerc_building_heating']; } if($get['commerc_building_fire']){ $mas_usl_bd[] = "a.commerc_building_fire = ".$get['commerc_building_fire']; $mas_usl_sph[] = "commerc_building_fire = ".$get['commerc_building_fire']; } if($get['garage_type_id']){ $mas_usl_bd[] = "a.garage_type_id = ".$get['garage_type_id']; $mas_usl_sph[] = "garage_type_id = ".$get['garage_type_id']; } if($get['garage_vid_id']){ $mas_usl_bd[] = "a.garage_vid_id = ".$get['garage_vid_id']; $mas_usl_sph[] = "garage_vid_id = ".$get['garage_vid_id']; } if($get['boks_vid_id']){ $mas_usl_bd[] = "a.boks_vid_id = ".$get['boks_vid_id']; $mas_usl_sph[] = "boks_vid_id = ".$get['boks_vid_id']; } if($get['commerc_status_id']){ $mas_usl_bd[] = "a.commerc_status_id = ".$get['commerc_status_id']; $mas_usl_sph[] = "commerc_status_id = ".$get['commerc_status_id']; } } // 1. Дата доб. от нового к старому // 2. Дата доб. от старого к новому // 3. Дешевле // 4. Дороже switch ($get['order']) { case '2': $order = "ORDER BY objects.date_add"; if($sphinx){ $order = "ORDER BY date_add ASC"; } $mas_url_add[] = "order=2"; break; case '3': $order = "ORDER BY objects.stoim"; if($sphinx){ $order = "ORDER BY price_for_order ASC"; } $mas_url_add[] = "order=3"; break; case '4': $order = "ORDER BY objects.stoim"; if($sphinx){ $order = "ORDER BY price_for_order DESC"; } $mas_url_add[] = "order=4"; break; default: $order = "ORDER BY objects.date_add"; if($sphinx){ $order = "ORDER BY date_add DESC"; } $mas_url_add[] = "order=1"; break; } if ($sphinx){ return [$mas_usl_sph, $mas_url_add, $order]; } return [$mas_usl_bd, $mas_url_add, $order]; } function getWord($number, $suffix) { $keys = [2, 0, 1, 1, 1, 2]; $mod = $number % 100; $suffix_key = ($mod > 7 && $mod < 20) ? 2 : $keys[min($mod % 10, 5)]; return $suffix[$suffix_key]; } function padezh($kol, $word) { $ost = $kol % 100; if ($ost > 20) $ost %= 10; switch ($ost) { case 1: $end = ""; break; case 2: $end = "а"; break; case 3: $end = "а"; break; case 4: $end = "а"; break; default: $end = "ов"; break; } return $word . $end; } function padezh2($kol, $word) { $ost = $kol % 100; if ($ost > 20) $ost %= 10; switch ($ost) { case 1: $end = ""; break; case 2: $end = "а"; break; case 3: $end = "а"; break; case 4: $end = "а"; break; default: $end = "ев"; break; } return $word . $end; } function padezh3($kol, $word) { $ost = $kol % 100; if ($ost > 20) $ost %= 10; switch ($ost) { case 1: $end = "а"; break; case 2: $end = "ы"; break; case 3: $end = "ы"; break; case 4: $end = "ы"; break; default: $end = ""; break; } return $word . $end; } function padezh_day($kol) { $ost = $kol % 100; if ($ost > 20) $ost %= 10; switch ($ost) { case 1: $end = "день"; break; case 2: $end = "дня"; break; case 3: $end = "дня"; break; case 4: $end = "дня"; break; default: $end = "дней"; break; } return $end; } function setOnline() { $sql = "SELECT * FROM online WHERE id_user = $_SESSION[id]"; $rez = mysql_query($sql); if (mysql_num_rows($rez)) { $sql = "UPDATE online SET last_activity = NOW() WHERE id_user = $_SESSION[id]"; } else { $sql = "INSERT INTO online(id_user, last_activity, entry) VALUES($_SESSION[id], NOW(), NOW())"; } mysql_query($sql); } function to_archive($id,$val) { if($val) { $sql="UPDATE objects SET archive = '1' WHERE id=$id"; mysql_query($sql); return true; } else { $sql="UPDATE objects SET archive = '0', phone_search = '$num_search' WHERE id=$id"; mysql_query($sql); return true; } } function getAdresSearch($insert) { $replase = ["Санкт-Петербург" => "", "СПб" => "", "ул." => "", "ул" => "", "улица" => "", "/" => " ", "д." => "", "д " => "", " г " => "", "г " => "", "г. " => "", " г. " => "", "," => " ", "." => " ", "пр-кт" => "", "к." => "", "ш." => "", "п." => "", "пл." => "", "наб." => "", ]; $insert = strtr($insert, $replase); $insert = trim(mb_strtolower($insert, 'UTF-8')); return $insert; } function getAdresSearchNoLower($insert) { $replase = ["Санкт-Петербург" => "", "СПб" => "", "ул." => "", "ул" => "", "улица" => "", "/" => " ", "д." => "", "д " => "", " г " => "", "г " => "", "г. " => "", " г. " => "", "," => " ", "." => " ", "пр-кт" => "", "к." => "", "ш." => "", "п." => "", "пл." => "", "наб." => "", ]; $insert = strtr($insert, $replase); $insert = trim($insert); return $insert; } function img_resize($src, $dest, $width, $height, $rgb = 0xFFFFFF, $quality = 100) { if (!file_exists($src)) return false; $size = getimagesize($src); if ($size === false) return false; $format = strtolower(substr($size['mime'], strpos($size['mime'], '/') + 1)); $icfunc = "imagecreatefrom" . $format; if (!function_exists($icfunc)) return false; if ($height == 100) { if ($size[0] > $size[1]) { $width_temp = $height; $height = $width; $width = $width_temp; } } if ($size[0] > $size[1]) { $size[0] = ($size[1] * $width) / $height; $size[1] = ($size[0] * $height) / $width; } else { $size[1] = ($size[0] * $height) / $width; $size[0] = ($size[1] * $width) / $height; } $x_ratio = $width / $size[0]; $y_ratio = $height / $size[1]; $ratio = min($x_ratio, $y_ratio); $use_x_ratio = ($x_ratio == $ratio); $new_width = $use_x_ratio ? $width : floor($size[0] * $ratio); $new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio); $new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2); $new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2); $isrc = $icfunc($src); $idest = imagecreatetruecolor($width, $height); imagefill($idest, 0, 0, $rgb); imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]); imagejpeg($idest, $dest, $quality); imagedestroy($isrc); imagedestroy($idest); return true; } function LoadJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreatetruecolor(150, 30); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; } function LoadPNG($imgname) { $im = @imagecreatefrompng($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreatetruecolor(150, 30); /* Create a blank image */ $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; } /** * Обрезка изображения * * Функция работает с PNG, GIF и JPEG изображениями. * Обрезка идёт как с указанием абсоютной длины, так и относительной (отрицательной). * * @param string Расположение исходного файла * @param string Расположение конечного файла * @param array Координаты обрезки * @param bool Размеры даны в пискелях или в процентах * @return bool */ function cropLogo($file_input, $file_output, $crop = 'square', $percent = false) { list($w_i, $h_i, $type) = getimagesize($file_input); if (!$w_i || !$h_i) { echo 'Невозможно получить длину и ширину изображения'; return false; } $types = ['', 'gif', 'jpeg', 'png']; $ext = $types[$type]; if ($ext) { $func = 'imagecreatefrom' . $ext; $img = $func($file_input); } else { echo 'Некорректный формат файла'; return false; } if ($crop == 'square') { $min = $w_i; if ($w_i > $h_i) $min = $h_i; $w_o = $h_o = $min; } else { list($x_o, $y_o, $w_o, $h_o) = $crop; if ($percent) { $w_o *= $w_i / 100; $h_o *= $h_i / 100; $x_o *= $w_i / 100; $y_o *= $h_i / 100; } if ($w_o < 0) $w_o += $w_i; $w_o -= $x_o; if ($h_o < 0) $h_o += $h_i; $h_o -= $y_o; } $img_o = imagecreatetruecolor($w_o, $h_o); imagecopy($img_o, $img, 0, 0, $x_o, $y_o, $w_o, $h_o); if ($type == 2) { return imagejpeg($img_o, $file_output, 100); } else { $func = 'image' . $ext; return $func($img_o, $file_output); } } function getRusMonth($month) { $rus_month = ["", "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"]; $month *= 1; return $rus_month[$month]; } function cleanHtml($html, $strip_tags = false, $encode = false) { $html = html_entity_decode(trim($html)); $html = preg_replace('/(


    <\/p>)+/', '', $html); $html = str_replace("

     ","

    ", $html); $html = str_replace(" 

    ","

    ", $html); $html = str_replace(" "," ", $html); $html = str_replace([ "


    ", "


    ", "

    ", "

     

    ", ],"", $html); $html = preg_replace('/(

    <\/p>)/', '

    ', $html); $html = preg_replace('/(\s+)/', '

    ', $html); $html = preg_replace('/()/', '
    ', $html); $html = preg_replace('/(){3,}/', '

    ', $html); $html = str_replace("