Exemplo n.º 1
0
/**
 *  Display the ads under the given category ID.  Also puts in the
 *  subscription link and breadcrumbs.
 *  @param integer $cat Category number to list
 *  @return string  HTML for category list
 */
function adListCat($cat = '')
{
    global $_TABLES, $LANG_ADVT, $_CONF, $_USER, $_CONF_ADVT, $_GROUPS;
    global $CatListcolors;
    if ($cat == '') {
        return;
    }
    if (CLASSIFIEDS_checkCatAccess($cat) < 2) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['cat_unavailable'], 'alert');
    }
    $T = new Template(CLASSIFIEDS_PI_PATH . '/templates');
    $T->set_file('header', CLASSIFIEDS_getTemplate('adlisthdrCat'));
    $T->set_var('pi_url', $_CONF['site_url'] . '/' . $_CONF_ADVT['pi_name']);
    $sql = "SELECT image, owner_id, group_id, papa_id\n                perm_owner, perm_group, perm_members, perm_anon\n            FROM {$_TABLES['ad_category']}\n            WHERE cat_id={$cat}";
    $r = DB_query($sql);
    if (!$r || DB_numRows($r) < 1) {
        return;
    }
    $row = DB_fetchArray($r);
    $img_name = $row['image'];
    if ($img_name != '') {
        $T->set_var('catimg_url', CLASSIFIEDS_thumbUrl($img_name));
    }
    // Set the breadcrumb navigation
    //$T->set_var('breadcrumbs', CLASSIFIEDS_BreadCrumbs($cat), true);
    USES_classifieds_class_category();
    $T->set_var('breadcrumbs', adCategory::BreadCrumbs($cat), true);
    // if non-anonymous, allow the user to subscribe to this category
    if (!COM_isAnonUser()) {
        $result = DB_getItem($_TABLES['ad_notice'], 'count(*)', "uid = {$_USER['uid']} AND cat_id = {$cat}");
        // Determine whether the user is subscribed to notifications for
        // this category and display a message and or link accordingly
        $subscribed = $result > 0 ? 1 : 0;
        if ($subscribed) {
            $T->set_var('subscribe_msg', '<a href="' . CLASSIFIEDS_makeURL('del_notice', $cat) . '">' . COM_createImage(CLASSIFIEDS_URL . '/images/unsubscribe.png', $LANG_ADVT['remove'], array('title' => $LANG_ADVT['you_are_subscribed'], 'class' => 'gl_mootip')));
        } else {
            $T->set_var('subscribe_msg', '<a href="' . CLASSIFIEDS_makeURL('add_notice', $cat) . '">' . COM_createImage(CLASSIFIEDS_URL . '/images/subscribe.png', $LANG_ADVT['subscribe'], array('title' => $LANG_ADVT['subscribe'], 'class' => 'gl_mootip')));
        }
        // Display a link to submit an ad to the current category
        $submit_url = '';
        if (SEC_hasRights($_CONF_ADVT['pi_name'] . '.admin')) {
            $submit_url = $_CONF['site_admin_url'] . '/plugins/' . $_CONF_ADVT['pi_name'] . '/index.php?mode=edit&cat=' . $cat;
        } elseif (CLASSIFIEDS_checkCatAccess($cat, false, $row) == 3) {
            $submit_url = $_CONF['site_url'] . '/submit.php?type=' . $_CONF_ADVT['pi_name'] . '&cat=' . $cat;
        }
        $T->set_var('submit_url', $submit_url);
    } else {
        // Not-logged-in users can't subscribe or submit.
        $T->set_var('subscribe_msg', '');
        $T->set_var('submit_msg', '');
    }
    // This is a comma-separated string of category IDs for a SQL "IN" clause.
    // Start with the current category
    $cat_for_adlist = $cat;
    // Get the sub-categories which have this category as their parent
    USES_classifieds_class_category();
    $subcats = adCategory::SubCats($cat);
    $listvals = '';
    $max = count($CatListcolors);
    $i = 0;
    foreach ($subcats as $row) {
        // for each sub-category, add it to the list for getting ads
        $cat_for_adlist .= ",{$row['cat_id']}";
        // only show the category selection for immediate children.
        if ($row['papa_id'] != $cat) {
            continue;
        }
        $T->set_block('header', 'SubCat', 'sCat');
        if ($row['fgcolor'] == '' || $row['bgcolor'] == '') {
            if ($i >= $max) {
                $i = 0;
            }
            $T->set_var('bgcolor', $CatListcolors[$i][0]);
            $T->set_var('fgcolor', $CatListcolors[$i][1]);
            $i++;
        } else {
            $T->set_var('bgcolor', $row['bgcolor']);
            $T->set_var('fgcolor', $row['fgcolor']);
        }
        $T->set_var('subcat_url', CLASSIFIEDS_makeURL('list', $row['cat_id']));
        $T->set_var('subcat_name', $row['cat_name']);
        $T->set_var('subcat_count', adCategory::TotalAds($row['cat_id']));
        $T->parse('sCat', 'SubCat', true);
    }
    // Get the count of ads under this category
    $time = time();
    $sql = "SELECT cat_id FROM {$_TABLES['ad_ads']}\n            WHERE cat_id IN ({$cat_for_adlist})\n                AND exp_date > {$time} " . COM_getPermSQL('AND', 0, 2);
    //echo $sql;
    $result = DB_query($sql);
    if (!$result) {
        return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
    }
    $totalAds = DB_numRows($result);
    $where_clause = " ad.cat_id IN ({$cat_for_adlist})\n        AND ad.exp_date > {$time} ";
    $T->parse('output', 'header');
    $retval = $T->finish($T->get_var('output'));
    $retval .= adExpList('', $cat, $where_clause);
    return $retval;
}
Exemplo n.º 2
0
 /**
  *   Calls itself recursively to find all sub-categories.
  *   Stores an array of category information in $subcats.
  *
  *   @param  integer $id         Current Category ID
  *   @param  integer $master_id  ID of top-level category being searched
  *   @return string              HTML for breadcrumbs
  */
 public static function SubCats($id, $master_id = 0)
 {
     global $_TABLES, $LANG_ADVT;
     static $subcats = array();
     $id = (int) $id;
     if ($id == 0) {
         return array();
     }
     // must have a valid category ID
     // On the initial call, $master_id is normally blank so set it to
     // the current $id. For recursive calls, $master_id will be provided.
     $master_id = (int) $master_id;
     if ($master_id == 0) {
         $master_id = $id;
     }
     if (isset($subcats[$id])) {
         return $subcats[$id];
     } else {
         $subcats[$id] = array();
     }
     $sql = "SELECT cat_name, cat_id, fgcolor, bgcolor, papa_id\n                FROM {$_TABLES['ad_category']} \n                WHERE papa_id={$id}";
     //echo $sql;die;
     $result = DB_query($sql);
     if (!$result) {
         return CLASSIFIEDS_errorMsg($LANG_ADVT['database_error'], 'alert');
     }
     while ($row = DB_fetchArray($result, false)) {
         $subcats[$master_id][$row['cat_id']] = $row;
         $subcats[$id][$row['cat_id']]['total_ads'] = adCategory::TotalAds($row['cat_id']);
         $A = adCategory::SubCats($row['cat_id'], $master_id);
         if (!empty($A)) {
             array_merge($subcats[$id], $A);
         }
     }
     return $subcats[$master_id];
 }