diff --git a/app/api/apiclient.php b/app/api/apiclient.php index 6abbcfb..6b8559d 100644 --- a/app/api/apiclient.php +++ b/app/api/apiclient.php @@ -105,7 +105,36 @@ function api_restore_hash($hash){ } +# подписчик или нет +function client_status_sub($client_id, $client_group = 3){ + if ($client_group == 1 or $client_group == 2){ + return True; + } + + $findsub = db_get("SELECT number_id FROM `anbuy` WHERE `client_id` = '$client_id' AND `number_id` = '486' AND `buy_status` = '1' LIMIT 1"); + + if (isset($findsub['number_id'])){ + return True; + } + +} + + +# куплена книжка или нет +function client_status_book($book_id, $client_id){ + + $book_sql = "SELECT buy_id FROM anbuy WHERE number_id = $book_id AND client_id = $client_id AND buy_status = 1"; + $book = db_get($book_sql); + + if (isset($book['buy_id'])){ + return True; + } + + + return False; + +} diff --git a/app/api/book.php b/app/api/book.php index e3a0076..92d4d10 100644 --- a/app/api/book.php +++ b/app/api/book.php @@ -3,9 +3,19 @@ * */ -function bookid_kuri($hash) { +function bookid_kuri($slug) { - $query = "SELECT `price_id`, `pricename`, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price` FROM `price` WHERE `pricehash` = '$hash' LIMIT 1"; + $query = " + SELECT + `price_id`, `pricename`, `categoryname`, `categoryslug`, price.category_id AS category_id, `BeginDate`, `priceanons`, `priceimg`, `pricehash`, `price`, `sub` + FROM + `price` + LEFT JOIN `pricecategory` + ON price.category_id = pricecategory.category_id + WHERE + `priceslug` = '$slug' + LIMIT 1 + "; $book = dbl_get($query); @@ -30,9 +40,9 @@ function bookid_kuri($hash) { /** * вернуть товары магазина (все или по фильтру) */ -function api_books_kuri($category = 'all', $page = 1){ +function api_books_kuri($category = 'knigi', $filter = 'all', $page = 1){ - $limit = 25; + $limit = 24; if ($page > 1){ $offset = $limit * ($page - 1); @@ -41,7 +51,7 @@ function api_books_kuri($category = 'all', $page = 1){ else { $offset_str = ''; } - + if ($category == 'all'){ $where = ''; } @@ -58,9 +68,98 @@ function api_books_kuri($category = 'all', $page = 1){ } - $sql_books = "SELECT * FROM `price` $where ORDER BY `price_id` DESC LIMIT $limit $offset_str"; + $db_count = db_get("SELECT COUNT(price_id) AS count FROM `price` $where LIMIT 1;"); - return db_get($sql_books); + if (isset($db_count['error'])) + return False; + + if (isset($db_count['count'])) + $count = $db_count['count']; + + $sql_books = "SELECT * FROM `price` $where ORDER BY `price_id` DESC LIMIT $limit $offset_str"; + $books = db_get($sql_books); + + if (!isset($books['error'])) { + + if ($count > $limit){ + $pages = ceil($count / $limit); + } + else{ + $pages = 1; + } + + $result['books'] = $books; + $result['count'] = $count; + $result['pages'] = $pages; + $result['page'] = $page; + } + + return $result; + +} + + +/** +все категории +*/ +function api_cats(){ + + $cats = db_get( + "SELECT * FROM pricecategory WHERE visibled = 1" + ); + + if (isset($cats['error'])) + return False; + + $result = []; + + foreach ($cats as $cat){ + $result[$cat['categoryslug']] = $cat; + } + + return $result; + +} + + +function book_slug($book){ + + $return = ''; + + if ($book['category_id'] == 1){ + + $name = $book['pricename']; + + $start = strpos($name, '('); + $end = strpos($name, ')'); + $end = $end -1; + + $number = substr($book['pricename'], $start + 1, $end - $start); + + $result = "argumenty-nedeli-$number"; + + } + else { + $result = transliturl($book['pricename']); + } + + return $result; + +} + + +function add_book_slug(){ + + $books = db_get( + "SELECT * FROM price;" + ); + + foreach ($books as $book){ + $slug = book_slug($book); + $sql = "UPDATE `price` SET `priceslug` = '$slug' WHERE price_id = ".$book['price_id'].';'; + echo "$sql
"; + + } } \ No newline at end of file diff --git a/app/confg.php b/app/confg.php index f964877..5170ec4 100644 --- a/app/confg.php +++ b/app/confg.php @@ -2,6 +2,7 @@ ini_set('display_errors', 0); ini_set('display_startup_errors', 0); +error_reporting(E_ALL); if (isset($_SERVER['HTTP_HOST'])) diff --git a/app/helpers/linkbook.php b/app/helpers/linkbook.php new file mode 100644 index 0000000..8fe0e3a --- /dev/null +++ b/app/helpers/linkbook.php @@ -0,0 +1,26 @@ + SITE.'category/'.$book['categoryslug'], + 'page' => $book['pricename'] + ]; + $title = $book['pricename'].' - Аргументы Недели'; $description = 'Читайте и покупайте '.$book['pricename'].'. Издательский дом "Аргументы Недели"'; + $maintitle = 'Книги Аргументы Недели'; + $subtitle = $book['pricename']; - $login = check_login_kuri(); // залогин или нет - + $buy_status = False; + + # книга входит в состав подписки + if ($book['sub'] == 1 && SUBSTATUS == 1){ + $buy_status = True; + } + else { + # купил ли эту книжку + $buy_status = client_status_book($books['book_id'], CLIENT_ID); + } + $tempcontent = VIEWPATH.'book.phtml'; include VIEWPATH.'layout.phtml'; - } -function books_kuri($category = 'all', $filter = 'all', $page = 1){ +function category_kuri($category = 'knigi', $filter = 'all', $page = 1){ - $books = api_books_kuri($category, $page); + $cats = api_cats(); + $books = api_books_kuri($category, $filter, $page); + $baseurl = SITE."category/$category/$filter/"; + + if ($books['pages'] > 1){ + $endurl = $baseurl.$books['pages']; + } + + if ($page > 1) { + $pagetitle = $cats[$category]['categoryname']." - страница $page"; + $prevpage = $page - 1 ; + $prevurl = $baseurl.$prevpage; + + } + else { + $pagetitle = $cats[$category]['categoryname']; + } + + if ($page < $books['pages']){ + $nextpage = $page+1; + $nexturl = $baseurl.$nextpage; + } + + if (isset($cats[$category])){ + $breadcrumbs['page'] = $pagetitle; + } + $tempcontent = VIEWPATH.'books.phtml'; include VIEWPATH.'layout.phtml'; diff --git a/app/views/blocks/auth.phtml b/app/views/blocks/auth.phtml deleted file mode 100644 index 3312539..0000000 --- a/app/views/blocks/auth.phtml +++ /dev/null @@ -1,11 +0,0 @@ - - -
- - Войти - - - Моя библиотека  - Выйти - -
\ No newline at end of file diff --git a/app/views/book.phtml b/app/views/book.phtml index 5531b84..3f85df7 100644 --- a/app/views/book.phtml +++ b/app/views/book.phtml @@ -2,10 +2,12 @@

- -

Режим pdf

-

Режим для чтения

-

Скачать PDF

+ +

Читать PDF

+ + +

Скачать PDF

+

руб.

diff --git a/app/views/books.phtml b/app/views/books.phtml index 6cec2bc..1db4786 100644 --- a/app/views/books.phtml +++ b/app/views/books.phtml @@ -1,13 +1,14 @@ -
- +
- + + <?=$book['pricename']?>

-

Купить

+

Подробнее

+
diff --git a/app/views/breadcrumbs.phtml b/app/views/breadcrumbs.phtml new file mode 100644 index 0000000..27fb586 --- /dev/null +++ b/app/views/breadcrumbs.phtml @@ -0,0 +1,27 @@ + + +
  • + +
  • + + $item):?> + + +
  • + +
  • + +
  • + +
  • +
  • + +
  • + + + + + + + + \ No newline at end of file diff --git a/app/views/header.phtml b/app/views/header.phtml new file mode 100644 index 0000000..af1b316 --- /dev/null +++ b/app/views/header.phtml @@ -0,0 +1,26 @@ + +
  • + +
  • +
  • + Моя библиотека +
  • + + +
  • + +
  • +
  • + +
  • + + +
  • + +
  • +
  • + +
  • + + + diff --git a/app/views/layout.phtml b/app/views/layout.phtml index 43c11d2..00cbb86 100644 --- a/app/views/layout.phtml +++ b/app/views/layout.phtml @@ -14,6 +14,7 @@ + @@ -61,36 +62,23 @@ _tmr.push({id: "1069168", type: "pageView", start: (new Date()).getTime()});
    - + + + +
    +
    diff --git a/app/views/layout_lite.phtml b/app/views/layout_lite.phtml index c30f4ab..05d0933 100644 --- a/app/views/layout_lite.phtml +++ b/app/views/layout_lite.phtml @@ -14,7 +14,7 @@
    diff --git a/app/views/menus/auth.phtml b/app/views/menus/auth.phtml new file mode 100644 index 0000000..badad4d --- /dev/null +++ b/app/views/menus/auth.phtml @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/app/views/menus/lkmenu.phtml b/app/views/menus/lkmenu.phtml index 24141df..a34b358 100644 --- a/app/views/menus/lkmenu.phtml +++ b/app/views/menus/lkmenu.phtml @@ -1,28 +1,12 @@ - -

    Вам доступен весь архив

    - -

    Всего покупок:

    - + 0):?> - -
    -

    - - -

    + + + - - - - + + diff --git a/app/views/menus/menucategory.phtml b/app/views/menus/menucategory.phtml index dc9ff43..35a4bb9 100644 --- a/app/views/menus/menucategory.phtml +++ b/app/views/menus/menucategory.phtml @@ -1,11 +1,22 @@ - \ No newline at end of file + + + + + + + + \ No newline at end of file