/**
 * Получаем данные оферов, все или только количество
 * @param string $cat_type тип категории (архив, избранное или все) 
 * @param int $category_id категория
 * @param int $start смещение
 * @param int $limit максимум строчек в выборке
 * @param int $only_total вернуть только количество, без данных
 * @return array 
 */
function get_offers_list($cat_type = 'all', $category_id = 0, $start = 0, $limit = 1000, $only_total = 0)
{
    global $offers_stats_array;
    $offers_stats_array = array();
    $category_name = '{empty}';
    $arr_offers = array();
    $offers_id = array();
    $total = 0;
    if ($category_id > 0) {
        $q = "select id, category_caption, category_name, category_type \n            from tbl_links_categories_list \n            where id='" . intval($category_id) . "'";
        $rs = db_query($q);
        $r = mysql_fetch_assoc($rs);
        if ($r['id'] > 0) {
            $category_name = $r['category_caption'];
        } else {
            return array('error' => 1);
        }
        switch ($r['category_type']) {
            case 'network':
                $page_type = 'network';
                // Get network ID
                $q = "select id \n                    from tbl_cpa_networks \n                    where network_category_name='" . mysql_real_escape_string($row['category_name']) . "'";
                $rs = db_query($q);
                $r = mysql_fetch_assoc($rs);
                $network_id = $r['id'];
                // Только количество
                if ($only_total) {
                    $q = "select count(`status`) as `cnt`\n                        from tbl_offers \n                        where network_id='" . mysql_real_escape_string($network_id) . "' \n                            and status in (0,3)";
                    $rs = db_query($q);
                    $r = mysql_fetch_assoc($rs);
                    $total = $r['cnt'];
                } else {
                    // Get list of offers from network
                    $q = "select SQL_CALC_FOUND_ROWS * \n                        from tbl_offers \n                        where network_id='" . mysql_real_escape_string($network_id) . "' \n                            and status in (0,3)\n                        order by date_add desc, id asc\n                        limit {$start}, {$limit}";
                    $rs = db_query($q);
                    $total = total_rows();
                    while ($r = mysql_fetch_assoc($result)) {
                        $arr_offers[] = $r;
                    }
                }
                break;
            default:
                // Только количество
                if ($only_total) {
                    $q = "select count(`status`) as `cnt`\n                        from tbl_offers \n                        left join tbl_links_categories on tbl_offers.id=tbl_links_categories.offer_id \n                        where tbl_links_categories.category_id='" . intval($category_id) . "' \n                            and tbl_offers.network_id = '0' \n                            and tbl_offers.status in (0,3)";
                    $rs = db_query($q);
                    $r = mysql_fetch_assoc($rs);
                    $total = $r['cnt'];
                } else {
                    // Get list of offers in category
                    $q = "select SQL_CALC_FOUND_ROWS tbl_offers.*, tbl_links_categories.category_id \n                        from tbl_offers \n                        left join tbl_links_categories on tbl_offers.id=tbl_links_categories.offer_id\n                        where tbl_links_categories.category_id='" . intval($category_id) . "' \n                            and tbl_offers.network_id='0' \n                            and tbl_offers.status in (0,3)\n                        order by tbl_offers.date_add desc, tbl_offers.id asc\n                        limit {$start}, {$limit}";
                    $rs = db_query($q);
                    $total = total_rows();
                    while ($r = mysql_fetch_assoc($rs)) {
                        $r['offer_id'] = $r['id'];
                        $r['category_id'] = intval($r['category_id']);
                        $offers_id[] = "'" . mysql_real_escape_string($r['id']) . "'";
                        $arr_offers[] = $r;
                    }
                    $offers_id_str = implode(',', $offers_id);
                    $q = "select out_id, count(id) as cnt \n                        from tbl_clicks \n                        where out_id in ({$offers_id_str}) \n                        group by out_id";
                    $rs = db_query($q);
                    while ($r = mysql_fetch_assoc($rs)) {
                        $offers_stats_array[$r['out_id']] = $r['cnt'];
                    }
                }
                break;
        }
    } else {
        switch ($cat_type) {
            case 'favorits':
                $cond_status = 'tbl_offers.status = 3';
                break;
            case 'archive':
                $cond_status = 'tbl_offers.status = 2';
                break;
            default:
                $cond_status = 'tbl_offers.status IN (0,3) and 
                    (tbl_links_categories.id IS NULL or tbl_links_categories_list.id IS NULL)';
                break;
        }
        // Только количество
        if ($only_total) {
            $q = "select count(tbl_offers.`status`) as `cnt`\n                from tbl_offers \n                left join tbl_links_categories on tbl_offers.id = tbl_links_categories.offer_id\n                left join tbl_links_categories_list on tbl_links_categories.category_id = tbl_links_categories_list.id \n                    and tbl_links_categories_list.status = '0'\n                where tbl_offers.network_id='0' \n                    and " . $cond_status;
            $rs = db_query($q);
            $r = mysql_fetch_assoc($rs);
            $total = $r['cnt'];
        } else {
            // Get list of offers without category
            $q = "select SQL_CALC_FOUND_ROWS tbl_offers.*, tbl_links_categories.category_id  \n                from tbl_offers \n                left join tbl_links_categories on tbl_offers.id=tbl_links_categories.offer_id\n                left join tbl_links_categories_list on tbl_links_categories.category_id = tbl_links_categories_list.id \n                    and tbl_links_categories_list.status = '0'\n                where tbl_offers.network_id='0' \n                    and " . $cond_status . " \n                order by tbl_offers.date_add desc, tbl_offers.id asc\n                limit {$start}, {$limit}";
            $rs = db_query($q);
            $total = total_rows();
            while ($r = mysql_fetch_assoc($rs)) {
                $r['offer_id'] = $r['id'];
                $r['category_id'] = intval($r['category_id']);
                $offers_id[] = "'" . mysql_real_escape_string($r['id']) . "'";
                $arr_offers[] = $r;
            }
            $offers_id_str = implode(',', $offers_id);
        }
    }
    return array('error' => 0, 'total' => intval($total), 'more' => $total > $offset + $limit ? 1 : 0, 'cat_name' => $category_name, 'data' => $arr_offers);
}
예제 #2
0
파일: index.php 프로젝트: cssguy/tds
        }
    }
}
?>
	<!-- welcome -->
	<?php 
if (empty($_GET['view'])) {
    echo "Добро пожаловать в админ панель, выберите необходимый пункт меню.";
} elseif ($_GET['view'] == 'transports') {
    include_once dir . "/transports_admin.php";
} elseif ($_GET['view'] == 'cargos') {
    include_once dir . "/cargos_admin.php";
} elseif ($_GET['view'] == 'drivers') {
    include_once dir . "/drivers_admin.php";
}
$total_pages = total_rows($view_list);
if ($total_pages > 1) {
    echo "Страницы<br>";
    for ($i = 1; $i <= $total_pages; $i++) {
        if ($i == $page + 1) {
            $now_page = " current_page";
        } else {
            $now_page = "";
        }
        echo '<a href="?page=' . $i . $query_string . '" class="pages' . $now_page . '">' . $i . '</a>';
    }
}
?>
    </div>

  </div>