assign('country_id', $_GET['country_id']); $url_base .= ($url_base == $url_base_original) ? "?" : "&"; $url_base .= "country_id=" . $_GET['country_id']; } if ($_GET['category_id'] != "") { $condition .= " t.category_id=$_GET[category_id] AND "; $smarty->assign('category_id', $_GET['category_id']); $url_base .= ($url_base == $url_base_original) ? "?" : "&"; $url_base .= "category_id=" . $_GET['category_id']; } $limit = 10; $start = (!isset($_GET['start'])) ? 0 : $_GET['start'] - 1; $order = ($_GET['order'] == 'updated') ? "updated_on DESC" : "t.rank, t.created_on DESC"; $db->query("SELECT SQL_CALC_FOUND_ROWS u.username, t.toolbar_id, t.name, t.description, t.country_id, t.icon_url, t.version, t.category_id, t.category, c.name AS category_name, r.name AS country_name FROM toolbars t, users u, categories c, countries r WHERE $condition t.user_id=u.user_id AND t.public=1 AND t.verified=1 AND t.category_id=c.category_id AND t.country_id=r.country_id ORDER BY $order LIMIT $start, $limit"); $toolbars = array(); while ($row = $db->fetch_array()) { $toolbars[] = $row; } $db->free_result(); $r = $db->query_first("SELECT FOUND_ROWS() AS cnt"); $count = $r['cnt']; $pages = array(); $url_base .= ($url_base == $url_base_original) ? "?" : "&"; if ($count > $limit) { $page_max = 15; $page_count = 0; $page_current = ($start / $limit) + 1; $page_middle = ceil($page_max / 2) * $limit; $page_start = $page_current - $page_middle; if ($start + floor($page_max / 2) * $limit > $count + 1) { $page_start = (floor($count / $limit) + 1) - $page_max; $page_start = $page_start * $limit + 1; } $page_start = ($page_start < 0) ? 1 : $page_start; for ($i = $page_start; $i < $count + 1; $i += $limit) { $page_no = (($i - 1) / $limit) + 1; $pages[$page_no] = $url_base . "start=" . urlencode($i); $page_count++; if ($page_count == $page_max) { break; } } $smarty->assign("pages", $pages); $smarty->assign("page_current", $page_current); if ($page_current != 1) { $smarty->assign('prev_url', $pages[$page_current - 1]); } if ($page_current != count($pages)) { $smarty->assign('next_url', $pages[$page_current + 1]); } } $smarty->assign('page_title', 'Groowe toolbars'); $smarty->assign('toolbars', $toolbars); $smarty->assign('categories', $categories); $smarty->assign('countries', $countries); $smarty->display('index.tpl'); function ReadCategories() { global $db; $categories = array(); $categories[""] = "All"; $db->query("SELECT * FROM categories"); while ($row = $db->fetch_array()) { $categories[$row['category_id']] = $row['name']; } $db->free_result(); return $categories; } function ReadCountries() { global $db; $countries = array(); $db->query("SELECT DISTINCT c.country_id, c.name FROM countries c, toolbars t WHERE t.public=1 AND t.country_id=c.country_id"); while ($row = $db->fetch_array()) { $countries[$row['country_id']] = $row['name']; } $db->free_result(); return $countries; } ?>