query('DELETE FROM apps_application WHERE id = '.intval($_GET['delete'])); header('location: /apps/'); } $offersPerPage = 10; if (isset($_GET['page'])) { $page = (int)$_GET['page']; } else { $page = 1; } $searchQuery = ''; $where = ''; $filterValue = ''; if (isset($_GET['filter'])) { list($filterKey, $filterValue) = explode('/', $_GET['filter']); if (!in_array($filterKey, array('category', 'device'))) { header('location: /apps/'); exit; } if ($filterKey == 'category') { if (isset($categories[$filterValue])) { $filterUrl = '/filter/'.$filterKey.'/'.$filterValue; $where = 'AND category_id = '.$filterValue; $category_id = $filterValue; } else { header('location: /apps/'); exit; } } if ($filterKey == 'device') { if (in_array($filterValue, array('iphone','ipad','iphoneipad'))) { $offerType = $filterValue; $filterUrl = '/filter/'.$filterKey.'/'.$filterValue; if($filterValue == 'iphoneipad') { $where = 'AND device = \'iphone&ipad\''; } else { $where = 'AND device = \''.$filterValue.'\''; } } else { header('location: /apps/'); exit; } } } else { $filterUrl = ''; $where = ''; } if (!empty($sortBy)) { $sortByUrl = '/'.$sortBy; } else { $sortByUrl = ''; } if (!empty($filterUrl)) { $sortByUrl = $filterUrl; } else { $sortByUrl = ''; } $page = max($page, 1); $limit = 'LIMIT '.(($page - 1) * $offersPerPage).' , '.$offersPerPage; $sql = ' SELECT SQL_CALC_FOUND_ROWS apps.*, apps.id as apps_id, u.login, '.(LOGIN ? 'IF (w.comment_count IS NOT NULL, apps.comments_num - w.comment_count, apps.comments_num) new_comments_num, ' : '').' c.category_id FROM apps_application apps INNER JOIN id_users u ON u.id = apps.user_id LEFT JOIN apps_category c ON c.application_id = apps.id '.(LOGIN ? 'LEFT JOIN apps_comments_views w ON w.app_id = apps.id AND w.user_id = '.USER_ID : '').' WHERE apps.is_activated = 1 AND created_at < NOW() '.$where.' ORDER BY created_at DESC '.$limit ; if(SUPER_USER) { // echo $sql; } $result = $mysqli->query($sql); $apps = array(); while ($row = $result->fetch_assoc()) { $row['category'] = (!$row['category_id'] ? null : $categories[$row['category_id']]); $row['images'] = array(); $apps[$row['id']] = $row; } $sql = ' SELECT name, extension, application_id FROM apps_images WHERE application_id IN ('.implode(',', array_keys($apps)).') '; $result = $mysqli->query($sql); $imgs = array(); while ($row = $result->fetch_assoc()) { $apps[$row['application_id']]['images'][] = $row; } $result = $mysqli->query('SELECT COUNT(*) FROM apps_application apps LEFT JOIN apps_category c ON c.application_id = apps.id WHERE apps.is_activated = 1 AND created_at < NOW() '.$where); //print_r($result->fetch_row()); list($count) = $result->fetch_row(); $maxPage = max(ceil($count / $offersPerPage), 1); if ($page > $maxPage) { header('location: /apps/'.$maxPage.$filterUrl); exit; } $from = max($page - 5, 1); $to = min($page + 5, $maxPage); $pages = range($from, $to); require './templates/index.php'; ?>