set_filenames(array('adverts_page' => 'adverts.tpl')); // SQL for adverts table $sql = "SELECT category, sub_category AS number FROM ". ADS_ADVERTS_TABLE ." WHERE expiry_date > $current_time GROUP BY category, sub_category"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $sub_category_ar[$row['category'].'_'.$row['sub_category']] = $row['number']; } $sql = 'SELECT * FROM '. ADS_CATEGORIES_TABLE .' ORDER BY cat_category, cat_sub_category ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $category = $row['cat_category']; $sub_category = $row['cat_sub_category']; // Encode the fields $u_category = urlencode(stripslashes(htmlspecialchars_decode_php4(str_replace("''", "\'", $category)))); $u_sub_category = urlencode(stripslashes(htmlspecialchars_decode_php4(str_replace("''", "\'", $sub_category)))); if ( $category != $save_category ) { $category_url = append_sid("adverts.$phpEx?category=$u_category"); $template->assign_block_vars('categoryrow', array('CATEGORY' => "$category
")); $save_category = $category; } $sub_category_temp = "$sub_category"; if ( $sub_category_ar[$save_category.'_'.$sub_category] ) { $sub_category_temp .= ' ('.$sub_category_ar[$save_category.'_'.$sub_category].')'; } $template->assign_block_vars('categoryrow', array('CATEGORY' => $sub_category_temp)); } // Set the start page if ( $HTTP_GET_VARS['start'] ) { $start = intval($HTTP_GET_VARS['start']); } else { $start = 0; } // Get the total number of ads if ( $inp_category and $inp_sub_category ) { $sql = "SELECT * FROM ". ADS_ADVERTS_TABLE ." WHERE expiry_date > $current_time AND category = '$inp_category' AND sub_category = '$inp_sub_category'"; } else if ( $inp_category ) { $sql = "SELECT * FROM ". ADS_ADVERTS_TABLE ." WHERE expiry_date > $current_time AND category = '$inp_category'";} else { $sql = "SELECT * FROM ". ADS_ADVERTS_TABLE ." WHERE expiry_date > $current_time"; } $result = $db->sql_query($sql); $ads_count = $db->sql_numrows($result); // Get the ads for this page if ( $inp_category and $inp_sub_category ) { $sql = "SELECT * FROM ". ADS_ADVERTS_TABLE ." WHERE category = '$inp_category' AND sub_category = '$inp_sub_category' AND expiry_date > $current_time ORDER BY premium_ad_ind DESC, id DESC LIMIT ".$start.", ".$ads_config['ads_per_page']; } else if ( $inp_category ) { $sql = "SELECT * FROM ". ADS_ADVERTS_TABLE ." WHERE category = '$inp_category' AND expiry_date > $current_time ORDER BY premium_ad_ind DESC, id DESC LIMIT ".$start.", ".$ads_config['ads_per_page']; } else { $sql = "SELECT * FROM ". ADS_ADVERTS_TABLE ." WHERE expiry_date > $current_time ORDER BY premium_ad_ind DESC, id DESC LIMIT ".$start.", ".$ads_config['ads_per_page']; } $result = $db->sql_query($sql); if ( $db->sql_numrows($result) > 0 ) { while ($row = $db->sql_fetchrow($result)) { $id = $row['id']; $user_id = $row['user_id']; $profiledata = get_userdata($user_id); if ( $user_id != ANONYMOUS ) { $profile = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id"); } else { $profile = ''; } if ( $row['status'] == 'sold' ) { $status = $lang['sold']; } elseif ( $row['status'] == 'expired' ) { $status = $lang['expired']; } elseif ( $row['status'] == 'active' ) { $status = ''; } if ( $row['ad_type_code'] == '4' ) { $premium_ad = '['.$lang['premium_ad'].']
'; } else { $premium_ad = ''; } // Count the comments $sql2 = "SELECT COUNT(comment_id) AS comments_count FROM ". ADS_COMMENTS_TABLE ." WHERE comment_ad_id = '$id' GROUP BY comment_ad_id LIMIT 1"; $result2 = $db->sql_query($sql2); $row2 = $db->sql_fetchrow($result2); if ( empty($row2) ) { $total_comments = 0; } else { $total_comments = $row2['comments_count']; } // Check to see if an image exists for this ad if ( $ads_config['images'] == 1 ) { $sql2 = "SELECT * FROM ". ADS_IMAGES_TABLE ." WHERE id = '$id' AND img_deleted_ind = 0 LIMIT 0,1"; $result2 = $db->sql_query($sql2); if ( $db->sql_numrows($result2) > 0 ) { while ($row2 = $db->sql_fetchrow($result2)) { $img_url = ADS_IMAGES_PATH ."ad".$id."_img".$row2["img_seq_no"]."_thumb.jpg"; } } else { $img_url = $images['noimage']; } $template->assign_block_vars('imagerow', array( 'U_ADS_ITEM' => append_sid("ads_item.$phpEx?id=".$row['id']), 'U_PROFILE' => $profile, 'USERNAME' => $profiledata['username'], 'TITLE' => $row['title'], 'SHORT_DESC' => $premium_ad.nl2br($row['short_desc']), 'DATE_ADDED' => date($lang['DATE_FORMAT'],$row['time']), 'STATUS' => $status, 'PRICE' => $row['price'], 'VIEWS' => $row['views'], 'COMMENTS' => $total_comments, 'IMAGE' => $img_url)); } else { $template->assign_block_vars('noimagerow', array( 'U_ADS_ITEM' => append_sid("ads_item.$phpEx?id=".$row['id']), 'U_PROFILE' => $profile, 'USERNAME' => $profiledata['username'], 'TITLE' => $premium_ad.$row['title'], 'SHORT_DESC' => nl2br($row['short_desc']), 'DATE_ADDED' => date($lang['DATE_FORMAT'],$row['time']), 'STATUS' => $status, 'PRICE' => $row['price'], 'VIEWS' => $row['views'], 'COMMENTS' => $total_comments)); } } } else { $template->assign_block_vars('switch_no_items_found',array()); } if ( $ads_config['images'] == 1 ) { $template->assign_block_vars('switch_images_enabled',array()); } if ( $inp_category ) { $pointer= ' -> '; } if ( $inp_sub_category ) { $pointer2 = ' -> '; } if ( $ads_count == 0 ) { $ads_count = 1; } // Encode the fields $u_category = urlencode(stripslashes(htmlspecialchars_decode_php4(str_replace("''", "\'", $inp_category)))); $u_sub_category = urlencode(stripslashes(htmlspecialchars_decode_php4(str_replace("''", "\'", $inp_sub_category)))); $goto_string = generate_pagination("adverts.$phpEx?category=$u_category&sub_category=$u_sub_category", $ads_count, $ads_config[ads_per_page], $start); $page_string = sprintf($lang['Page_of'], ( floor( $start / $ads_config[ads_per_page] ) + 1 ), ceil( $ads_count / $ads_config[ads_per_page] )); $template->assign_vars(array( 'U_ADS_INDEX' => append_sid("adverts.$phpEx"), 'U_CATEGORY' => append_sid("adverts.php?category=$u_category"), 'U_SUB_CATEGORY' => append_sid("adverts.php?category=$u_category&sub_category=$u_sub_category"), 'U_RSS2' => "ads_rss2.$phpEx", 'U_CREATE_AD' => append_sid("ads_create.$phpEx"), 'L_ADS_INDEX' => $lang['ads_index'], 'L_CATEGORIES' => $lang['categories'], 'L_TITLE' => $lang['title'], 'L_SHORT_DESC' => $lang['short_desc'], 'L_DATE_ADDED' => $lang['date_added'], 'L_AD_STATUS' => $lang['ad_status'], 'L_PRICE' => $lang['price'], 'L_USERNAME' => $lang['username'], 'L_IMAGE' => $lang['image'], 'L_STATS' => $lang['stats'], 'L_VIEWS' => $lang['views'], 'L_COMMENTS' => $lang['comments'], 'L_NO_ITEMS_FOUND' => $lang['no_items_found'], 'SITE_NAME' => $board_config['sitename'], 'MSG_NEWAD' => $images['msg_newad'], 'GOTO_STRING' => $goto_string, 'PAGE_STRING' => $page_string, 'POINTER' => $pointer, 'POINTER2' => $pointer2, 'CATEGORY' => stripslashes(str_replace("''", "\'", $inp_category)), 'SUB_CATEGORY' => stripslashes(str_replace("''", "\'", $inp_sub_category)))); $template->pparse('adverts_page'); include($phpbb_root_path . 'includes/page_tail.'.$phpEx); ?>