require_once("../common/includes/settings.php");
require_once("config.php");
include_once('../bikeshops/classes/bikeshop_review.class.php');
$MENU_ID="BIKESHOPS";
//redirect to new url
$http_host = $_SERVER['HTTP_HOST'];
$url = 'http://'.$http_host.'/bikeshops/promotions.php';
if (!empty($_SERVER["QUERY_STRING"])) $url.="?".$_SERVER['QUERY_STRING'];
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit;
$sid = 0;
if(isset($_REQUEST['sid']) && is_numeric($_REQUEST['sid']) && $_REQUEST['sid']>0) {
$sid = $_REQUEST['sid'];
$theMerchant = new Merchant(3, $sid);
/*
if(!$theMerchant->isPaidValidMerchant()) {
$adminMsg = 'Merchant cccount is expired, This is not visible to public.';
}
echo('p='.$theMerchant->isPaidValidMerchant().'
');
echo('ex='.$theMerchant->isExMerchant().'
');
*/
if(!$theMerchant->isPaidValidMerchant() && !isMerchantAdmin()) {
header("Location: /shopping/fmnlist.php");
}
$shop = new Shop($sid); // for merchant header
}
$countrycode = getCountryCodeSelected();
$keyword='';
$e_keyword='';
if($_REQUEST['keyword'] != "") {
$keyword = $_REQUEST['keyword'];
$e_keyword = mysql_escape($_REQUEST['keyword']);
}
// begin assembling query. Join 4 tables.
$sql = "SELECT DISTINCT * FROM merchants AS M, merchant_news AS N, bikeshops_sg AS BS WHERE M.merchantid = N.merchantid AND M.shopid = BS.sid and paystartdate < NOW() and payenddate > NOW() AND BS.country = '$countrycode'";
if ((int)$sid > 0) $sql = $sql . " AND BS.sid='" . $sid . "'";
if ($e_keyword != "") $sql = $sql . " AND (N.title LIKE '%" . $e_keyword ."%' OR N.content LIKE '%". $e_keyword ."%')";
if ($sortid == "1") {
$sql .= " ORDER BY N.datecreated";
} else if ($sortid == "2") {
$sql .= " ORDER BY BS.shopname";
} else if ($sortid == "3") {
$sql .= " ORDER BY RAND()";
} else {
$sql .= " ORDER BY N.datecreated";
}
if ($order == "D") {
$sql = $sql . " DESC";
} else if ($order == "A") {
$sql = $sql . " ASC";
} else {
$sql = $sql . " DESC";
}
//pages definitions
$NO_OF_ITM_PER_PAGE = 10;
$NO_OF_PGS_PER_SHEET = 10;
$COLS = 1;
$ROWS = 10;
//image size definitions
$PWIDTH = 120;
$PHEIGHT = 160;
//page sanity check
if ((!$page_id) || $page_id < 1 ) $page_id=1;
//calculate pages
$limit = $NO_OF_ITM_PER_PAGE;
$sql_nrows = "SELECT DISTINCT COUNT(*) FROM merchants as M, merchant_news as N, bikeshops_sg AS BS WHERE M.merchantid = N.merchantid AND M.shopid = BS.sid and paystartdate < NOW() and payenddate > NOW() AND BS.country = '$countrycode'";
if ($sid > 0) $sql_nrows = $sql_nrows . " AND BS.sid='" . $sid . "'";
if ($e_keyword != "") $sql_nrows = $sql_nrows . " AND (N.title LIKE '%" . $e_keyword ."%' OR N.content LIKE '%". $e_keyword ."%')";
$r_nrows = mysql_query($sql_nrows, $link);
$row_nrows = mysql_fetch_row($r_nrows);
$no_of_rows = $row_nrows[0];
$no_of_pages = $no_of_rows/$limit;
$no_of_pages = ceil($no_of_pages);
//page sanity check
if ($page_id > $no_of_pages) $page_id = $no_of_pages;
$offset=$limit*($page_id-1);
//10 pages per sheet
$sno = ceil($page_id/$NO_OF_PGS_PER_SHEET);
//calculate total no. of sheets
$no_of_sheets = ceil($no_of_pages/$NO_OF_PGS_PER_SHEET);
$sql = $sql . " LIMIT $offset, $limit";
//add pageviews and reset resource pointer to front
//echo($sql); exit;
$r = mysql_query($sql);
if($r) {
if (mysql_num_rows($r) > 0) {
while($row_news = mysql_fetch_array($r)) {
mysql_query("UPDATE merchant_news SET views = views + 1 WHERE nid = '".$row_news["nid"]."'");
}
if (!mysql_data_seek($r,0)) {
$r = mysql_query($sql);
}
}
}
//define vars
$toggle = 0;
$sn = (($page_id-1) * $NO_OF_ITM_PER_PAGE) + 1;
//assemble GET string
$getstr = "";
if ($sortid) { $getstr = $getstr . urlencode("&sortid=") . urlencode($sortid);}
if ($order) { $getstr = $getstr . urlencode("&order=") . urlencode($order);}
if ($sid) { $getstr = $getstr . urlencode("&sid=") . urlencode($sid);}
//plain unencoded string for links
$getpstr = "";
if ($sortid) { $getpstr = $getpstr . "&sortid=" . urlencode($sortid);}
if ($order) { $getpstr = $getpstr . "&order=" . urlencode($order);}
if ($sid) { $getpstr = $getpstr . "&sid=" . urlencode($sid);}
$WEBPAGE_TITLE = $sid > 0 ? $shop->getShopname() . ' Promotions ' .getCountrySelected(). ' | Togoparts.com' : 'Togoparts.com - '.getCountrySelected().' Bike Shop Promotions and News';
$meta_description = "";
$meta_keywords = "";
?>