Code:
function getRandomImage()
{
global $use_listing_approval;
global $random_image_limit;
$limit = $random_image_limit;
$approved = '';
if ($use_listing_approval) {
if (!isset($_SESSION["admin"])) {
if (isset($_SESSION["seller"])) {
$approved = "";
} else {
$approved = "listings.approved = 1 AND listimages.approved = 1 AND ";
}
}
}
//get max id for list images so we can get random images
$sql = "SELECT COUNT(id) FROM listimages";
$max_res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
$row = sqlFetchRow($max_res);
//check if the results are less than the initial $limit if so
//set the limit to the results
if ($row['0'] < $limit) {
$limit = $row['0'];
}
$returned_ids = array();
//get the id for the list images as long as it passes our checks
$sql = "SELECT listimages.listingid FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listimages.mainimage = 1 AND listings.sold != 1";
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
while ($id_res = sqlFetchArray($res)) {
$returned_ids[] = $id_res["listingid"];
}
//check if the results are less than the initial $limit if so
//set the limit to the results
if (count($returned_ids) < $limit) {
$limit = count($returned_ids);
}
//if we have results set the rand var else return false
$random_id_keys = array();
if ($returned_ids) {
$random_id_keys = array_rand($returned_ids, $limit);
$c=0;
foreach ($returned_ids as $key => $value) {
if (is_array($random_id_keys)) {
if (in_array($key, $random_id_keys, TRUE)) {
//print "$key => $value<br />";
$random_ids[] = "$value";
++$c;
}
if ($c == $limit) break;
} else {
return false;
}
}
$rand = implode(',', $random_ids);
//print "<br />$rand";
} else {
return false;
}
//random id checks are succesfull do a query
//$sql = "SELECT * FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listings.sold !=1 AND listimages.mainimage = 1 ORDER BY RAND() LIMIT $limit";
$sql = "SELECT * FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listings.sold !=1 AND listimages.mainimage = 1 ORDER BY added_on DESC LIMIT $limit";
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
$c=0;
while ($a_row = sqlFetchArray($res)) {
$records[$c]["ad_title"] = $a_row["ad_title"];
$records[$c]["make"] = $a_row["make"];
$records[$c]["model"] = $a_row["model"];
$records[$c]["listingid"] = $a_row["listingid"];
$records[$c]["imagepath"] = $a_row["imagepath"];
$records[$c]["imagethumbpath"] = $a_row["imagethumbpath"];
$records[$c]["price"] = $a_row["price"];
$records[$c]["year"] = $a_row["year"];
++$c;
}
if (isset($records))
return $records;
return false;
}
function getRandomImage()
{
global $use_listing_approval;
global $random_image_limit;
$limit = $random_image_limit;
$approved = '';
if ($use_listing_approval) {
if (!isset($_SESSION["admin"])) {
if (isset($_SESSION["seller"])) {
$approved = "";
} else {
$approved = "listings.approved = 1 AND listimages.approved = 1 AND ";
}
}
}
//get max id for list images so we can get random images
$sql = "SELECT COUNT(id) FROM listimages";
$max_res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
$row = sqlFetchRow($max_res);
//check if the results are less than the initial $limit if so
//set the limit to the results
if ($row['0'] < $limit) {
$limit = $row['0'];
}
$returned_ids = array();
//get the id for the list images as long as it passes our checks
$sql = "SELECT listimages.listingid FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listimages.mainimage = 1 AND listings.sold != 1";
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
while ($id_res = sqlFetchArray($res)) {
$returned_ids[] = $id_res["listingid"];
}
//check if the results are less than the initial $limit if so
//set the limit to the results
if (count($returned_ids) < $limit) {
$limit = count($returned_ids);
}
//if we have results set the rand var else return false
$random_id_keys = array();
if ($returned_ids) {
$random_id_keys = array_rand($returned_ids, $limit);
$c=0;
foreach ($returned_ids as $key => $value) {
if (is_array($random_id_keys)) {
if (in_array($key, $random_id_keys, TRUE)) {
//print "$key => $value<br />";
$random_ids[] = "$value";
++$c;
}
if ($c == $limit) break;
} else {
return false;
}
}
$rand = implode(',', $random_ids);
//print "<br />$rand";
} else {
return false;
}
//random id checks are succesfull do a query
//$sql = "SELECT * FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listings.sold !=1 AND listimages.mainimage = 1 ORDER BY RAND() LIMIT $limit";
$sql = "SELECT * FROM listimages, listings WHERE $approved listings.id = listimages.listingid AND listings.sold !=1 AND listimages.mainimage = 1 ORDER BY added_on DESC LIMIT $limit";
$res = sqlQuery($sql); if(sqlErrorReturn()) sqlDebug(__FILE__,__LINE__,sqlErrorReturn());
$c=0;
while ($a_row = sqlFetchArray($res)) {
$records[$c]["ad_title"] = $a_row["ad_title"];
$records[$c]["make"] = $a_row["make"];
$records[$c]["model"] = $a_row["model"];
$records[$c]["listingid"] = $a_row["listingid"];
$records[$c]["imagepath"] = $a_row["imagepath"];
$records[$c]["imagethumbpath"] = $a_row["imagethumbpath"];
$records[$c]["price"] = $a_row["price"];
$records[$c]["year"] = $a_row["year"];
++$c;
}
if (isset($records))
return $records;
return false;
}
index.tpl
Code:
{foreach item="image" from=$records}
<p>
{if $use_fancy_urls}
<a onmouseover="Tip('{$image.make} {$image.model} {$image.year} {$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}€')" onmouseout="UnTip()" href="listings/view/{$image.make|strip:"-"}/{$image.model|strip:"-"}/{$image.listingid}/"><img src="{$image.imagethumbpath}" title="" alt="" /></a>
{else}
<a onmouseover="Tip('{$image.make} {$image.model} {$image.year} {$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}€')" onmouseout="UnTip()" href="listings.php?make={$image.make|strip:"-"}&model={$image.model|strip:"-"}&id={$image.listingid}"><img src="{$image.imagethumbpath}" title="" alt="" /></a>
{/if}
<br /><span style="font-weight:bold;">{$image.make} {$image.model} </span><span style="color: #0000FF; font-weight: bold;"><br />{$image.year}</span> <span style="color: #FFFFFF; background-color: #CE1618;font-weight: bold;"> {$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}€ </span>
</p>
{/foreach}
</div>
{foreach item="image" from=$records}
<p>
{if $use_fancy_urls}
<a onmouseover="Tip('{$image.make} {$image.model} {$image.year} {$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}€')" onmouseout="UnTip()" href="listings/view/{$image.make|strip:"-"}/{$image.model|strip:"-"}/{$image.listingid}/"><img src="{$image.imagethumbpath}" title="" alt="" /></a>
{else}
<a onmouseover="Tip('{$image.make} {$image.model} {$image.year} {$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}€')" onmouseout="UnTip()" href="listings.php?make={$image.make|strip:"-"}&model={$image.model|strip:"-"}&id={$image.listingid}"><img src="{$image.imagethumbpath}" title="" alt="" /></a>
{/if}
<br /><span style="font-weight:bold;">{$image.make} {$image.model} </span><span style="color: #0000FF; font-weight: bold;"><br />{$image.year}</span> <span style="color: #FFFFFF; background-color: #CE1618;font-weight: bold;"> {$image.price|number_format:0:"`$smarty.const.CURRENCY_SYMBOLS_DECIMAL_SEPARATOR`":"`$smarty.const.CURRENCY_SYMBOLS_THOUSANDS_SEPARATOR`"}€ </span>
</p>
{/foreach}
</div>
index.php
Code:
<? php
require_once './Includes/configs/functions.php';
require_once './Includes/libs/Smarty.class.php';
if (file_exists("./Includes/language/$site_lang/global.php")) {
include_once "./Includes/language/$site_lang/global.php";
} else {
include_once "./Includes/language/en/global.php";
}
if (file_exists("./Includes/language/$site_lang/".basename(__FILE__)."")) {
include_once "./Includes/language/$site_lang/".basename(__FILE__)."";
}
$smarty = new Smarty;
$smarty->force_compile = $force_compile_enabled;
$file = basename(__FILE__, ".php");
if (file_exists("templates/$template/$file.tpl")) {
$smarty->template_dir="templates/$template";
} else {
$smarty->template_dir="templates/Default";
}
//$smarty->template_dir="templates/$template";
$smarty->assign("manufacturerslist",getSearchList("make"));
$smarty->assign("modelslist",getSearchList("model"));
$smarty->assign("typeslist",getSearchList("vehicle_type"));
$smarty->assign("sellerslist",getSellers());
$smarty->assign("total_vehicle_count_sold",getTotalVehicleCount('sold'));
$smarty->assign("total_vehicle_count",getTotalVehicleCount('active'));
$smarty->assign("vehicle_count_stats",getVehicleCountStats());
//$smarty->assign("conditionslist",getSearchList("listing_condition"));
//Check if single user mode 1 or multi-user mode 0
if ($site_mode == 0) {
$smarty->assign("site_mode",1);
}
//The user is already logged in.
if (isset($_SESSION["logged_in"])){
$smarty->assign("logged_in",1);
//check privs to find out if user
//is a seller, admin or user
$status = checkPrivs();
$smarty->assign("$status",1);
}
if ($use_fancy_urls) {
$smarty->assign("use_fancy_urls",1);
}
//get random images for the frontpage
$smarty->assign("records",getRandomImage());
$smarty->assign("index",1);
$smarty->display('index.tpl');
?>
<? php
require_once './Includes/configs/functions.php';
require_once './Includes/libs/Smarty.class.php';
if (file_exists("./Includes/language/$site_lang/global.php")) {
include_once "./Includes/language/$site_lang/global.php";
} else {
include_once "./Includes/language/en/global.php";
}
if (file_exists("./Includes/language/$site_lang/".basename(__FILE__)."")) {
include_once "./Includes/language/$site_lang/".basename(__FILE__)."";
}
$smarty = new Smarty;
$smarty->force_compile = $force_compile_enabled;
$file = basename(__FILE__, ".php");
if (file_exists("templates/$template/$file.tpl")) {
$smarty->template_dir="templates/$template";
} else {
$smarty->template_dir="templates/Default";
}
//$smarty->template_dir="templates/$template";
$smarty->assign("manufacturerslist",getSearchList("make"));
$smarty->assign("modelslist",getSearchList("model"));
$smarty->assign("typeslist",getSearchList("vehicle_type"));
$smarty->assign("sellerslist",getSellers());
$smarty->assign("total_vehicle_count_sold",getTotalVehicleCount('sold'));
$smarty->assign("total_vehicle_count",getTotalVehicleCount('active'));
$smarty->assign("vehicle_count_stats",getVehicleCountStats());
//$smarty->assign("conditionslist",getSearchList("listing_condition"));
//Check if single user mode 1 or multi-user mode 0
if ($site_mode == 0) {
$smarty->assign("site_mode",1);
}
//The user is already logged in.
if (isset($_SESSION["logged_in"])){
$smarty->assign("logged_in",1);
//check privs to find out if user
//is a seller, admin or user
$status = checkPrivs();
$smarty->assign("$status",1);
}
if ($use_fancy_urls) {
$smarty->assign("use_fancy_urls",1);
}
//get random images for the frontpage
$smarty->assign("records",getRandomImage());
$smarty->assign("index",1);
$smarty->display('index.tpl');
?>
zlatko nikolic