示例#1
0
/**
 *  Create a category listing page showing the categories in block styling.
 *  @return string      HTML for category listing page
 */
function CLASSIFIEDS_catList_blocks()
{
    global $_CONF, $_TABLES, $LANG_ADVT, $_CONF_ADVT;
    global $CatListcolors;
    $T = new Template(CLASSIFIEDS_PI_PATH . '/templates');
    $T->set_file('page', 'catlist_blocks.thtml');
    $T->set_var('site_url', $_CONF['site_url']);
    $T->set_var('site_admin_url', $_CONF['site_admin_url']);
    // Get all the root categories
    $sql = "SELECT * FROM {$_TABLES['ad_category']} \n            WHERE papa_id='' " . COM_getPermSQL('AND', 0, 2) . " ORDER BY cat_name ASC";
    //echo $sql;die;
    $cats = DB_query($sql);
    if (!$cats) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
    }
    // If no root categories exist, display just return a message
    if (DB_numRows($cats) == 0) {
        $T->set_var('no_cat_found', "<p align=\"center\" class=\"headmsg\">\n            {$LANG_ADVT['no_cat_found']}</p>\n");
        $T->parse('output', 'page');
        return $T->finish($T->get_var('output'));
    }
    $max = count($CatListcolors);
    $i = 0;
    while ($catsrow = DB_fetchArray($cats)) {
        if ($catsrow['fgcolor'] == '' || $catsrow['bgcolor'] == '') {
            if ($i >= $max) {
                $i = 0;
            }
            $bgcolor = $CatListcolors[$i][0];
            $fgcolor = $CatListcolors[$i][1];
            $hdcolor = $CatListcolors[$i][2];
            $i++;
        } else {
            $fgcolor = $catsrow['fgcolor'];
            $bgcolor = $catsrow['bgcolor'];
        }
        // For each category, find the total ad count (including subcats)
        // and display the subcats below it.
        $T->set_block('page', 'CatDiv', 'Div');
        $T->set_var('bgcolor', $bgcolor);
        $T->set_var('fgcolor', $fgcolor);
        //$T->set_var('hdcolor', $hdcolor);
        $T->set_var('cat_url', CLASSIFIEDS_makeUrl('home', $catsrow['cat_id']));
        $T->set_var('cat_name', $catsrow['cat_name']);
        $T->set_var('cat_desc', $catsrow['description']);
        $T->set_var('cat_ad_count', findTotalAds($catsrow['cat_id']));
        if ($catsrow['image']) {
            $T->set_var('cat_image', CLASSIFIEDS_thumbUrl('cat/' . $catsrow['image']));
        } else {
            $T->set_var('cat_image', '');
        }
        $T->parse('Div', 'CatDiv', true);
    }
    $T->parse('output', 'page');
    return $T->finish($T->get_var('output'));
}
/**
*   Find the total number of ads for a category, including subcategories
*
*   @param  integer $id CategoryID
*   @return integer Total Ads
*/
function findTotalAds($id)
{
    global $_TABLES;
    $time = time();
    // to compare to ad expiration
    $totalAds = 0;
    // find all the subcategories
    $sql = "\n        SELECT\n            cat_id\n        FROM\n            {$_TABLES['ad_category']}\n        WHERE\n            papa_id={$id}\n    ";
    $result = DB_query($sql);
    if (!$result) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
    }
    // If there are subcategories, call this function recursively for each
    // one.
    while ($row = DB_fetchArray($result)) {
        $totalAds += findTotalAds($row['cat_id']);
    }
    // Now add in the count for this category itself
    $sql = "\n        SELECT\n            cat_id\n        FROM\n            {$_TABLES['ad_ads']}\n        WHERE\n            cat_id={$id}\n        AND\n            exp_date>{$time} " . COM_getPermSQL('AND', 0, 2);
    //echo $sql."<br />\n";
    $totalAds += DB_numRows(DB_query($sql));
    return $totalAds;
}