public function loadAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $searche = $_POST['filter']; $newId = intval($_POST['newid']); if ($dateStart = K_Date::dateParse($_POST['date-start'])) { $dateStart = mktime(0, 0, 0, $dateStart['m'], $dateStart['d'], $dateStart['y']); } if ($dateStop = K_Date::dateParse($_POST['date-stop'])) { $dateStop = mktime(23, 59, 59, $dateStop['m'], $dateStop['d'], $dateStop['y']); } if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } if ($dateStart && $dateStop) { if ($dateStart > $dateStop) { $where[] = "UNIX_TIMESTAMP(comment_date) >= " . K_Db_Quote::quote($dateStart); } else { $where[] = "(UNIX_TIMESTAMP(comment_date) BETWEEN " . K_Db_Quote::quote($dateStart) . " AND " . K_Db_Quote::quote($dateStop) . ")"; } } else { if ($dateStart) { $where[] = "UNIX_TIMESTAMP(comment_date) >= " . K_Db_Quote::quote($dateStart); } else { if ($dateStop) { $where[] = "UNIX_TIMESTAMP(comment_date) <= " . K_Db_Quote::quote($dateStop); } } } if ($newId) { $where[] = " comment_new = " . K_Db_Quote::quote($newId); } if ($searche) { $where[] = " (comment_name like " . K_Db_Quote::quote($searche . '%') . " OR comment_email like " . K_Db_Quote::quote($searche . '%') . ")"; } if ($_POST['comments-status']) { $where[] = " comment_status = " . K_Db_Quote::quote($_POST['comments-status']); } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS * from comments {$where} order by comment_date DESC LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); foreach ($itemsRes as $v) { $itemRow['id'] = $v['comment_id']; $itemRow['date'] = $v['comment_date']; $itemRow['name'] = strip_tags(htmlspecialchars($v['comment_name'])); $itemRow['content'] = strip_tags(htmlspecialchars($v['comment_content'])); $itemRow['status'] = $v['comment_status']; $itemRow['ip'] = long2ip($v['comment_ip']); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }
public function loadAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $searche = $_POST['filter']; $blogId = intval($_POST['blogid']); if ($dateStart = K_Date::dateParse($_POST['date-start'])) { $dateStart = mktime(0, 0, 0, $dateStart['m'], $dateStart['d'], $dateStart['y']); } if ($dateStop = K_Date::dateParse($_POST['date-stop'])) { $dateStop = mktime(23, 59, 59, $dateStop['m'], $dateStop['d'], $dateStop['y']); } if (is_numeric($_POST['price-start'])) { $priceStart = $_POST['price-start']; } if (is_numeric($_POST['price-stop'])) { $priceStop = $_POST['price-stop']; } if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } $where = ''; // перечень полей из пост запроса для проверки $fields = array('id' => 'o.id', 'idc1' => 'o.idc1', 'type' => 'o.type', 'filial' => 'o.filial', 'adres' => 'o.adres', 'comnati' => 'o.comnati'); $where = K_Afunc::where($fields, $_POST); // var_dump($where); // цена объекта if ($priceStart && $priceStop) { if ($priceStart > $priceStop) { $where[] = "UNIX_TIMESTAMP(o.price) >= " . K_Db_Quote::quote($priceStart); } else { $where[] = "(UNIX_TIMESTAMP(o.price) BETWEEN " . K_Db_Quote::quote($priceStart) . " AND " . K_Db_Quote::quote($priceStop) . ")"; } } else { if ($priceStart) { $where[] = "UNIX_TIMESTAMP(o.price) >= " . K_Db_Quote::quote($priceStart); } else { if ($priceStop) { $where[] = "UNIX_TIMESTAMP(o.price) <= " . K_Db_Quote::quote($priceStop); } } } // дата публикации объекта if ($dateStart && $dateStop) { if ($dateStart > $dateStop) { $where[] = "UNIX_TIMESTAMP(o.date_publication) >= " . K_Db_Quote::quote($dateStart); } else { $where[] = "(UNIX_TIMESTAMP(o.date_publication) BETWEEN " . K_Db_Quote::quote($dateStart) . " AND " . K_Db_Quote::quote($dateStop) . ")"; } } else { if ($dateStart) { $where[] = "UNIX_TIMESTAMP(o.date_publication) >= " . K_Db_Quote::quote($dateStart); } else { if ($dateStop) { $where[] = "UNIX_TIMESTAMP(o.date_publication) <= " . K_Db_Quote::quote($dateStop); } } } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS o.*, b.symbol letter, t.name typename, t.color color, o.branchID filial_info, b.symbol letter, b.phone, b.address, b.email, b.title filial FROM `obj_objects` o\n \n LEFT JOIN obj_rooms r ON r.id = o.id \n LEFT JOIN obj_types t ON t.id = o.type \n LEFT JOIN obj_branches b ON b.id = o.branchID \n \n {$where} ORDER BY date_publication DESC LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); // сделать вывод планировок. // var_dump($itemRow); $this->view->objectRow = $itemRow; foreach ($itemsRes as $v) { $itemRow['id'] = $v['id']; $itemRow['id1c'] = $v['id1c']; $itemRow['type'] = $v['typename']; $itemRow['filial'] = strip_tags(htmlspecialchars($v['filial'])); $itemRow['adress'] = strip_tags($v['city'] . ' ' . $v['city'] . ' ' . $v['street']); $itemRow['rooms'] = strip_tags(htmlentities($v['rooms'])); $itemRow['price'] = $v['price']; $itemRow['color'] = strtoupper($v['color']); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }
public function loadAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $searche = $_POST['filter']; $newId = intval($_POST['newid']); if ($dateStart = K_Date::dateParse($_POST['date-start'])) { $dateStart = mktime(0, 0, 0, $dateStart['m'], $dateStart['d'], $dateStart['y']); } if ($dateStop = K_Date::dateParse($_POST['date-stop'])) { $dateStop = mktime(23, 59, 59, $dateStop['m'], $dateStop['d'], $dateStop['y']); } if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } if ($dateStart && $dateStop) { if ($dateStart > $dateStop) { $where[] = "UNIX_TIMESTAMP(type_news_date) >= " . K_Db_Quote::quote($dateStart); } else { $where[] = "(UNIX_TIMESTAMP(type_news_date) BETWEEN " . K_Db_Quote::quote($dateStart) . " AND " . K_Db_Quote::quote($dateStop) . ")"; } } else { if ($dateStart) { $where[] = "UNIX_TIMESTAMP(type_news_date) >= " . K_Db_Quote::quote($dateStart); } else { if ($dateStop) { $where[] = "UNIX_TIMESTAMP(type_news_date) <= " . K_Db_Quote::quote($dateStop); } } } if ($_POST['news-lang']) { $where[] = " type_news_lang = " . K_Db_Quote::quote($_POST['news-lang']); } if ($section = intval($_POST['section'])) { $where[] = " tree_pid = " . K_Db_Quote::quote($section); } if ($searche && mb_strlen($searche) > 2) { if ($searche) { $where[] = "(type_news_title LIKE " . K_Db_Quote::quote('%' . $searche . '%') . ' OR type_news_author LIKE ' . K_Db_Quote::quote($searche . '%') . ")"; } } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS type_news.*,type_section_ua_name from type_news\n LEFT JOIN tree ON tree_id = type_news_id \n LEFT JOIN type_section ON type_section_id = tree_pid \n {$where} order by type_news_date DESC LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); foreach ($itemsRes as $v) { $itemRow['id'] = $v['type_news_id']; $itemRow['date'] = $v['type_news_date']; $itemRow['title'] = strip_tags(htmlspecialchars($v['type_news_title'])); $itemRow['lang'] = strip_tags($v['type_news_lang']); $itemRow['section'] = strip_tags($v['type_section_ua_name']); $itemRow['author'] = strip_tags(htmlentities($v['type_news_author'])); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }