45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
ini_set('display_errors', 0);
|
|
function ekr($text)
|
|
{ // ФУНКЦИЯ очистки кода
|
|
$old1 = array(" "); #Ищем вредное ">",, "<"
|
|
$new1 = array("%"); #Меняем на полезное">", , "<"
|
|
$text = str_replace($old1, $new1, $text); #Собсно сама замена =)
|
|
return $text;
|
|
}
|
|
$massiv = \DB::getAll(
|
|
"SELECT tovar.id, tovar.title, tovar.cena, tovar_img.filename AS img
|
|
FROM `tovar`
|
|
JOIN `tovar_img`
|
|
ON tovar_img.tovar_id=tovar.id
|
|
WHERE
|
|
tovar.title LIKE '%" . ekr($_POST['txt']) . "%'
|
|
OR tovar.artikul LIKE '%" . $_POST['txt'] . "%'
|
|
OR tovar.id IN (SELECT `tovar_id` FROM `tovar_barcode` WHERE `barcode`='" . $_POST['txt'] . "')",
|
|
$_POST['txt']
|
|
);
|
|
$smarty->assign('title', "Поиск по сайту - " . $_POST['txt']);
|
|
$massiv2 = \core::array_unique_key($massiv, 'id');
|
|
$smarty->assign('list', $massiv2); //уникализируем массив и выводим в шаблон
|
|
$count = count($massiv2);
|
|
$c = \DB::getValue("SELECT `c` FROM `find_history` WHERE `txt`=? LIMIT 1", $_POST['txt']);
|
|
if ($c) {
|
|
$c++;
|
|
\DB::set("UPDATE `find_history` SET `c`=?, `t`=?, `countq`=? WHERE `txt`=?", array(
|
|
$c,
|
|
time(),
|
|
$count, $_POST['txt']
|
|
)
|
|
);
|
|
} else {
|
|
$c = 1;
|
|
\DB::add(
|
|
"INSERT INTO `find_history` (`c`, `t`, `countq`, `txt`) VALUES (?, ?, ?, ?)",
|
|
array(
|
|
$c,
|
|
time(),
|
|
$count, $_POST['txt']
|
|
)
|
|
);
|
|
}
|
|
?>
|