<?php
$pageClass = "ads";
$pageTitle = "Search Results";
include("header.php");
$ads = new Ad();
$adsList = $ads->GetList(array(array("adId",">",0)));
$top_results = array();
$other_results = array();
$bottom_results = array();
$used_values = array();
?>
<div id="content">
<?php
foreach ($adsList as $theAd) {
$tags_array = explode(",",$theAd->tags);
foreach($tags_array as $theTag) {
$tag = new Tag();
$tag->Get($theTag);
if (strtolower($tag->tagText) == strtolower($_GET['s']) || strtolower($theAd->companyName) == strtolower($_GET['s'])) {
array_push($top_results,$theAd);
array_push($used_values,$theAd->adId);
}//close if
}//close foreach tag
}//close if in tags or company name
foreach ($adsList as $theAd) {
if (strpos(strtolower($theAd->Title), strtolower($_GET['s'])) || strpos(strtolower($theAd->Description), strtolower($_GET['s']))) {
if (!in_array($theAd->adId,$used_values)) {
array_push($other_results,$theAd);
array_push($used_values,$theAd->adId);
}//close if
}//close if in title or description
}//close foreach
$search_terms = explode(" ", $_GET['s']);
foreach ($adsList as $theAd) {
foreach($search_terms as $term) {
if (strpos(strtolower($theAd->Title), strtolower($term)) || strpos(strtolower($theAd->Description), strtolower($term))) {
if (!in_array($theAd->adId,$used_values)) {
array_push($bottom_results,$theAd);
array_push($used_values,$theAd->adId);
}//close if
}//close if in title or description
}//close foreach search term
}//close foreach
$all_results = array_merge($top_results,$other_results);
?>
<?php
if (count($all_results) > 0 && count($bottom_results) > 0) {
?>
<h3>Top Results for <?php echo $_GET['s'] . " (" . count($all_results); ?>)</h3>
<?php
}//close if
elseif (count($all_results) > 0) {
?>
<h3>Search Results for <?php echo $_GET['s'] . " (" . count($all_results); ?>)</h3>
<?php
}
foreach ($all_results as $theAd) {
$ratings = new Rating();
$ratingsList = $ratings->GetList(array(array("AdId","=",$theAd->adId)));
$submitter = new User();
$submitter->Get($theAd->PostedBy);
?>
<dl>
<dt><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>"><?php echo $theAd->Title; ?></a></dt>
<dd class="image"><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>">
<?php
if ($theAd->Type == "0") {
embed_video_thumbnail($theAd->URL);
}//close if video
if ($theAd->Type == "1") {
embed_image_thumbnail($theAd->URL, $theAd->Title);
}//close if image
?>
</a></dd>
<dd class="date"><?php echo date("F j, Y", strtotime($theAd->PostedDate)); ?></dd>
<dd class="user">Submitted by <span><?php echo $submitter->Username; ?></span></dd>
<dd>Greenwashing Index Rating: <span><?php if ($theAd->AvgRating != 0) { echo round($theAd->AvgRating,2); } else {echo "Not yet rated"; } ?></span></dd>
<?php if ($theAd->AvgRating != 0) {?>
<dd><a href="ad_single.php?id=<?php echo $theAd->adId; ?>#ratings" title="Number of ratings"><?php echo count($ratingsList) + 1; ?> rating<?php if (count($ratingsList) != 0) {?>s<?php }?></a></dd>
<?php } ?>
</dl>
<?php
}//close for each ad
if (count($bottom_results) > 0) {
if (count($all_results) <= 0) {
?>
<h3>Search Results for <?php echo $_GET['s'] . " (" . count($bottom_results); ?>)</h3>
<?php
}//close if
else {
?>
<h3><a href="#" title="Show All Results" id="show_all_results">Show All Results (<?php echo count($bottom_results); ?>)</a></h3>
<?php
}//close else
?>
<div id="more_results" <?php if (count($all_results) > 0) { echo "class='initial_hide'"; } ?>>
<?php
foreach ($bottom_results as $theAd) {
$ratings = new Rating();
$ratingsList = $ratings->GetList(array(array("AdId","=",$theAd->adId)));
$submitter = new User();
$submitter->Get($theAd->PostedBy);
?>
<dl>
<dt><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>"><?php echo $theAd->Title; ?></a></dt>
<dd class="image"><a href="ad_single.php?id=<?php echo $theAd->adId; ?>" title="<?php echo $theAd->Title; ?>">
<?php
if ($theAd->Type == "0") {
embed_video_thumbnail($theAd->URL);
}//close if video
if ($theAd->Type == "1") {
embed_image_thumbnail($theAd->URL, $theAd->Title);
}//close if image
?>
</a></dd>
<dd class="date"><?php echo date("F j, Y", strtotime($theAd->PostedDate)); ?></dd>
<dd class="user">Submitted by <span><?php echo $submitter->Username; ?></span></dd>
<!--<dd><?php echo $theAd->Description; ?></dd>-->
<dd>Greenwashing Index Rating: <span><?php if ($theAd->AvgRating != 0) { echo round($theAd->AvgRating,2); } else {echo "Not yet rated"; } ?></span></dd>
<?php if ($theAd->AvgRating != 0) {?>
<dd><a href="ad_single.php?id=<?php echo $theAd->adId; ?>#ratings" title="Number of ratings"><?php echo count($ratingsList) + 1; ?> rating<?php if (count($ratingsList) != 0) {?>s<?php }?></a></dd>
<?php } ?>
</dl>
<?php
}//close for each ad
?>
</div><!--close #more_results-->
<?php
}//close if more results
if (count($all_results) <= 0 && count($bottom_results) <= 0) {
?>
<h3>No search results</h3>
<?php
}//close if
?>
</div><!--close content-->
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>
|