Exemple #1
0
 public static function getFlatList2($where, $order, $direction, $per_page = 10, $current_page = 1, $action = 'sales', $user_id = NULL)
 {
     $start_pos = ($current_page - 1) * $per_page;
     $limit = " LIMIT {$start_pos},{$per_page}";
     //$amount = Flat::getAmountInList($where);
     $sort = $order == '' ? "f.updated_on" : $order;
     $where_param = $where . " GROUP BY f.id ORDER BY " . $sort . " " . $direction . $limit;
     $params = '';
     if (isset($_GET['rooms'])) {
         $params .= '&rooms=' . intval($_GET['rooms']);
     }
     if (isset($_REQUEST['f_rooms'])) {
         $params .= '&rooms=' . intval($_REQUEST['f_rooms']) . '&f_rooms=' . intval($_REQUEST['f_rooms']);
     }
     $price_min = 0;
     $price_max = 0;
     if (isset($_REQUEST['f_price'])) {
         $f_price = intval($_REQUEST['f_price']);
         $params .= '&f_price=' . $f_price;
         switch ($f_price) {
             case 1:
                 $price_max = 1000000;
                 break;
             case 2:
                 $price_min = 1000000;
                 $price_max = 1500000;
                 break;
             case 3:
                 $price_min = 1500000;
                 $price_max = 2000000;
                 break;
             case 4:
                 $price_min = 2000000;
                 $price_max = 3000000;
                 break;
             case 5:
                 $price_min = 3000000;
                 break;
         }
     } else {
         if (isset($_REQUEST['price_min']) && $_REQUEST['price_min'] > 0) {
             $price_min = intval($_REQUEST['price_min']);
         } else {
             $price_min = 0;
         }
         if (isset($_REQUEST['price_max']) && $_REQUEST['price_max'] > 0) {
             $price_max = intval($_REQUEST['price_max']);
         } else {
             $price_max = 0;
         }
         if ($price_min > 0) {
             $params .= '&price_min=' . $price_min;
         }
         if ($price_max > 0) {
             $params .= '&price_max=' . $price_max;
         }
     }
     if (isset($_REQUEST['f_date'])) {
         $params .= '&f_date=' . clearTextData($_REQUEST['f_date']);
     }
     if (isset($_REQUEST['f_price_sq'])) {
         $params .= '&f_price_sq=' . intval($_REQUEST['f_price_sq']);
     }
     if (isset($_REQUEST['f_tenement'])) {
         $params .= '&f_tenement=' . intval($_REQUEST['f_tenement']);
     }
     if (isset($_REQUEST['f_kitchen'])) {
         $params .= '&f_kitchen=' . intval($_REQUEST['f_kitchen']);
     }
     if (isset($_REQUEST['f_total_area'])) {
         $params .= '&f_total_area=' . intval($_REQUEST['f_total_area']);
     }
     if (isset($_REQUEST['f_total_area'])) {
         $params .= '&f_total_area=' . intval($_REQUEST['f_total_area']);
     }
     if (isset($_REQUEST['f_balcon'])) {
         $params .= '&f_balcon=' . intval($_REQUEST['f_balcon']);
     }
     if (isset($_REQUEST['f_no_corner'])) {
         $params .= '&f_no_corner=' . intval($_REQUEST['f_no_corner']);
     }
     if (isset($_REQUEST['f_storey_no_first'])) {
         $params .= '&f_storey_no_first=' . intval($_REQUEST['f_storey_no_first']);
     }
     if (isset($_REQUEST['f_storey_no_last'])) {
         $params .= '&f_storey_no_last=' . intval($_REQUEST['f_storey_no_last']);
     }
     if (isset($_REQUEST['f_bath'])) {
         $params .= '&f_bath=' . intval($_REQUEST['f_bath']);
     }
     if (isset($_REQUEST['f_photo'])) {
         $params .= '&f_photo=' . intval($_REQUEST['f_photo']);
     }
     if (isset($_REQUEST['f_regions'])) {
         $params .= '&f_regions=' . intval($_REQUEST['f_regions']);
     }
     if (isset($_REQUEST['f_newt'])) {
         $params .= '&f_newt=' . intval($_REQUEST['f_newt']);
     }
     if (isset($_REQUEST['f_street']) && isset($_REQUEST['f_street_id'])) {
         $params .= '&f_street=' . clearTextData($_REQUEST['f_street']);
         $params .= '&f_street_id=' . intval($_REQUEST['f_street_id']);
     }
     if (isset($_REQUEST['f_heating'])) {
         $params .= '&f_heating=' . intval($_REQUEST['f_heating']);
     }
     if (isset($_REQUEST['f_is_owner'])) {
         $params .= '&f_is_owner=' . intval($_REQUEST['f_is_owner']);
     }
     if (isset($_SESSION['direction'])) {
         $direction = $_SESSION['direction'] == 'ASC' ? 'ASC' : 'DESC';
         $arrow = $direction == 'ASC' ? '↓' : '↑';
         $direction = 'direction=' . $direction;
     } else {
         $direction = '';
         $arrow = '';
     }
     $arrow_date = '';
     $arrow_price = '';
     if ($sort == 'updated_on') {
         $arrow_date = $arrow;
     } else {
         if ($sort == 'price') {
             $arrow_price = $arrow;
         }
     }
     $amount = Flat::getAmountInList($where . " GROUP BY f.id");
     $paginator = self::paginator("flat.html?action={$action}" . $params, $amount, $per_page, $current_page);
     $html = "\n\t\tНайдено {$amount} объявлений:\n\t\t<br>\t\t\t\t\t\t\n\t\t<table class='table table-striped table-bordered table-condensed'>\n\t\t<thead>\n\t\t <tr>\t\t \n\t\t <th>Комнат</th>\n\t\t <th><a href='/flat.html?action={$action}&sort=price" . $params . "'><b>Цена(руб.)</b></a>{$arrow_price}<br>руб./м<sup>2</sup></th>\n\t\t <th>Этаж</th>\t\t \n\t\t <th>Адрес</th>\t\t \t\t \t\t \n\t\t <th>Общая/кухня м<sup>2</sup></th>\n\t\t <th>Балкон</th>\t\t \n\t\t <th>Описание</th>\n\t\t <th>Тел.</th>\n\t\t <th><a href='/flat.html?action={$action}&sort=updated_on" . $params . "'><b>Дата</b></a>{$arrow_date}</th>\n\t\t <th></th> \t\t \n\t\t </tr>\n\t\t</thead>\n\t\t<tbody>\n\t\t";
     $ids = array();
     $db_res = Flat::getFullListLink($where_param);
     $tenement_icons = array('kirpich', 'panel', 'monolit', 'block', 'derevo');
     while ($row = $db_res->fetchRow()) {
         $ids[] = $row['id'];
         $type_name = Tenement::$TYPE[$row['ttype']];
         $type = $tenement_icons[$row['ttype']];
         $type = "<img src='/images/icon_{$type}.png' title='{$type_name}'>";
         $price = number_format($row['price'], 0);
         $price_m = number_format($row['price_m'], 0);
         $city = $row['city_id'] == 0 ? '' : $row['city'] . ',';
         $addr = "{$city} {$row['street']}";
         if ($row['show_address']) {
             $addr .= ", {$row['tnum']}";
         }
         $is_corner = $row['is_corner'] ? '<br><b>Угловая</b>' : '';
         $bath = $row['type_bathroom'] ? '<br><b>С/у совмещен</b>' : '';
         $is_new = $row['is_new'] ? '<br><b>Новостройка</b>' : '';
         $is_owner = $row['is_owner'] ? '<br><b>Собственник</b>' : '';
         $desc = Realty::prepareDescription($row['description']);
         $desc_all = truncate_utf8($desc, 300, true, true) . $is_corner . $bath;
         $description = $desc_all . $is_new . $is_owner;
         $tel = truncate_utf8($row['contacts'], 100, true, false);
         $flat_url = "/flat.html?action=view&id={$row['id']}";
         $photo_html = $row['photo_tenement'] != '' ? "<a href='{$flat_url}'  title='{$row['rooms']}-комнатная, {$price} руб.'><img src='/" . PHOTOS_WEBPATH . TENEMENT . "/" . $row['tenement_id'] . "/" . $row['photo_tenement'] . "_prev' class='border_const'></a>" : 'Нет фото';
         $photo_html2 = $row['photo_flat'] != '' ? "<a href='{$flat_url}'  title='{$row['rooms']}-комнатная, {$price} руб.'><img src='/" . PHOTOS_WEBPATH . FLAT . "/" . $row['id'] . "/" . $row['photo_flat'] . "_prev' class='border_const'></a>" : '';
         if ($photo_html2 != '') {
             $photo_html = $photo_html2;
         }
         $date = explode(' ', $row['updated_on']);
         $dates = explode('-', $date[0]);
         $date = $dates[2] . '.' . $dates[1];
         //.'.'.$dates[0]
         $url_del = !isset($_SESSION['admin']) ? '' : '<br><br><a href="javascript:delFlat(' . $row['id'] . ');">Удалить</a>';
         if ($user_id) {
             $url_del .= ' <a href="javascript:update(' . $row['id'] . ');" title="Обновить дату на текущую"><img src="/images/icon_update.png" title="Обновить дату на сегодняшнюю"></a>';
             $url_del .= ' <a href="flat.html?action=edit&id=' . $row['id'] . '"><img src="/images/icon_edit.png" title="Редактировать"></a>';
             $url_del .= ' <a href="javascript:remove(' . $row['id'] . ');"><img src="/images/icon_delete.png" title="Снять"></a>';
             $url_del .= ' <a href="javascript:sold(' . $row['id'] . ');"><img src="/images/icon_sold.png" title="Продано"></a>';
         }
         if ($row['balcony'] > 0) {
             $balcon = 'балкон ' . $row['balcony'] . 'м<sup>2</sup>';
         } elseif ($row['loggia'] > 0) {
             $balcon = 'лоджия ' . $row['loggia'] . 'м<sup>2</sup>';
         } else {
             $balcon = 'балкона нет';
         }
         $html .= "<tr>\t\t\t\n\t\t\t<td style='text-align:right;'><b>{$row['rooms']}-к.</b></td>\n\t\t\t<td><b>{$price}</b><br><br>{$price_m}</td>\n\t\t\t<td>{$row['storey']}/{$row['storeys']}<br><a href='/tenement.html?action=view&id={$row['tenement_id']}' target='_blank'>{$type}</a></td>\n\t\t\t<td><a href='{$flat_url}'>{$addr}</a></td>\t\t\t\t\t\t\n\t\t\t<td>{$row['total_area']}/{$row['kitchen_area']}</td>\n\t\t\t<td>{$balcon}</td>\t\t\t\n\t\t\t<td>{$description}</td>\n\t\t\t<td>{$tel}</td>\n\t\t\t<td>{$date}</td>\t\t\t\n\t\t\t<td><a href='{$flat_url}'><img src='/images/icon_view.png' title='Смотреть'></a>{$url_del}</td>\n\t\t\t</tr>\t\t\t\n\t\t\t";
     }
     $html .= "</tbody></table>\n\t\t<div>{$paginator}</div>\t\t\n\t\t";
     return array('html' => $html, 'ids' => $ids);
 }