<?php
/////////////////////////////////
// Includes
/////////////////////////////////
define('root_path', '');
require ("inc/global.php");
////////////////////////////////////////////////
// Load Template
////////////////////////////////////////////////
$tpl = new template;
$tpl->load_file('main', "$skin_path/main.htm");
$que = "SELECT item_ort FROM instar_items WHERE item_ort LIKE 'A%' ORDER BY item_ort";
////////////////////////////////////////////////
// View Items
////////////////////////////////////////////////
if (!$offset) $offset=0;
// Paging
$que = "SELECT count(*) AS number FROM ".$tableprefix."_items";
$count_result = $site_db->query($que);
while ($count = $site_db->fetch_array($count_result))
$total_entries = $count["number"];
if ($total_entries > 0) {
$pages = $total_entries / $items_per_page;
if ($pages < 1) {
$pages = 1;
}
if ($pages / (int) $pages <> 1) {
$pages = (int) $pages + 1;
}
else {
$pages = $pages;
}
if ($total_entries>$items_per_page)
{
if (($offset > $total_entries) or (!is_numeric($offset)))
$offset = 0;
// current page number
$pagenow = ($offset/$items_per_page + 1);
$paging = $lang['page_display']." " . $pagenow . "/" . $pages;
// next/preview links
$next = $offset + $items_per_page;
$previous = $offset - $items_per_page;
if ($pages <> 1) {
$paging .= " || ";
if ($previous < 0) {
$paging .= "<a href=$PHP_SELF?id=$id&offset=" . $next . ">";
$paging .= "<acronym title='".$lang['page_next']." " . $items_per_page . "'>".$lang['page_next']."</acronym></a>";
}
elseif ($next >= $total_entries) {
$paging .= "<a href=$PHP_SELF?id=$id&offset=" . $previous . ">";
$paging .= "<acronym title='".$lang['page_prev']." " . $items_per_page . "'>".$lang['page_prev']."</acronym></a>";
}
else {
$paging .= "<a href=$PHP_SELF?id=$id&offset=" . $previous . ">";
$paging .= "<acronym title='".$lang['page_prev']." " . $items_per_page . "'>".$lang['page_prev']."</acronym></a>";
$paging .= " | ";
$paging .= "<a href=$PHP_SELF?id=$id&offset=" . $next . ">";
$paging .= "<acronym title='".$lang['page_next']." " . $items_per_page . "'>".$lang['page_next']."</acronym></a>";
}
}
// links to all pages
if ($pages>1)
{
$paging .= "<br>".$lang['page_goto'];
$i = 0;
while ($i < $pages) {
$ri = $i + 1;
$showpage = $i * $items_per_page;
if ($ri == $pagenow)
$paging .= $ri . " ";
else
$paging .= "<a href=$PHP_SELF?id=$id&offset=" . $showpage . ">" . $ri . "</a> ";
$i++;
}
}
}
if ($sort_order == "number")
$order_by = "reviews DESC";
elseif ($sort_order == "rating")
$order_by = "avg_rating/avg_total DESC";
elseif ($sort_order == "ort")
$order_by = "item_ort";
else
$order_by = "item_name";
$que = "SELECT * FROM ".$tableprefix."_items ORDER BY $order_by LIMIT $offset, $items_per_page";
$result = $site_db->query($que);
$item_list = array();
$record = 0;
while ($row = $site_db->fetch_array($result)){
$sql = "SELECT reviews, avg_rating, avg_total FROM ".$tableprefix."_items WHERE item_id = $row[item_id]";
$rev_result = $site_db->query($sql);
$rev_row = $site_db->fetch_array($rev_result);
$avg_total = $rev_row[avg_total];
$avg_rating = $rev_row[avg_rating];
$num_reviews = $rev_row[reviews];
if ($num_reviews)
$item_list[$record][read_reviews]="<a href=\"view.php?id=$row[item_id]\">$num_reviews $lang[reviews]</a>";
else
$item_list[$record][read_reviews]=$lang['no_reviews'];
$item_list[$record][item_name] = $row[item_name];
$item_list[$record][item_ort] = $row[item_ort];
$item_list[$record][item_tel] = $row[item_tel];
$item_list[$record][item_webseite] = $row[item_webseite];
$item_list[$record][reviews] = $row[reviews];
$item_list[$record][item_description] = $row['description'];
if (!$avg_total)
$rat=0;
else
$rat = round ($avg_rating/$avg_total,2);
if ($rat==0) {$avg_rating = "<img border=\"0\" alt=\"noch nicht bewertet\" src=\"$skin_path/images/b0.gif\">";}
elseif ($rat<=1) {$avg_rating = "<img border=\"0\" alt=\"$lang[avg_rating] $rat/5\" src=\"$skin_path/images/b1.gif\">";}
elseif ($rat<=2) {$avg_rating = "<img border=\"0\" alt=\"$lang[avg_rating] $rat/5\" src=\"$skin_path/images/b2.gif\">";}
elseif ($rat<=3) {$avg_rating = "<img border=\"0\" alt=\"$lang[avg_rating] $rat/5\" src=\"$skin_path/images/b3.gif\">";}
elseif ($rat<=4) {$avg_rating = "<img border=\"0\" alt=\"$lang[avg_rating] $rat/5\" src=\"$skin_path/images/b4.gif\">";}
elseif ($rat<=5) {$avg_rating = "<img border=\"0\" alt=\"$lang[avg_rating] $rat/5\" src=\"$skin_path/images/b5.gif\">";}
$item_list[$record][rating] = $avg_rating;
$item_list[$record][post_reviews]="<a href=\"post.php?id=$row[item_id]\">$lang[post]</a>";
$record++;
}
if ($total_entries > 1){
$sort_drop_down = "<form method=\"POST\" action=\"$PHP_SELF?id=$id&offset=$offset\">
".$lang['sort_text']."
<select name=\"sort_order\">
<option>".$lang['select_text']."</option>
<option value=\"alphabetical\">".$lang['alphabet']."</option>
<option value=\"ort\">".$lang['ort']."</option>
<option value=\"number\">".$lang['number']."</option>
<option value=\"rating\">".$lang['rating']."</option>
</select> <input type=\"submit\" value=\"".$lang['submit_text']."\" name=\"sort\">
</form>";
}
$tpl->parse_loop('main','item_list');
}
else
$tpl->parse_loop('main','item_list',1,$lang['no_items_found']);
$tpl->register('main','paging, sort_drop_down, copyright');
$site_db->close();
$tpl->pprint('main');
?>