Issues (1106)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

book.php (11 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
//  ------------------------------------------------------------------------ //
3
//                      BOOKSHOP - MODULE FOR XOOPS 2                        //
4
//                  Copyright (c) 2007, 2008 Instant Zero                    //
5
//                     <http://www.instant-zero.com/>                        //
6
// ------------------------------------------------------------------------- //
7
//  This program is free software; you can redistribute it and/or modify     //
8
//  it under the terms of the GNU General Public License as published by     //
9
//  the Free Software Foundation; either version 2 of the License, or        //
10
//  (at your option) any later version.                                      //
11
//                                                                           //
12
//  You may not change or alter any portion of this comment or credits       //
13
//  of supporting developers from this source code or any supporting         //
14
//  source code which is considered copyrighted (c) material of the          //
15
//  original comment or credit authors.                                      //
16
//                                                                           //
17
//  This program is distributed in the hope that it will be useful,          //
18
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
//  GNU General Public License for more details.                             //
21
//                                                                           //
22
//  You should have received a copy of the GNU General Public License        //
23
//  along with this program; if not, write to the Free Software              //
24
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
//  ------------------------------------------------------------------------ //
26
/**
27
 * Viewing a book
28
 */
29
include __DIR__ . '/header.php';
30
include_once XOOPS_ROOT_PATH . '/class/tree.php';
31
32
$book_id = 0;
33
// Tests **************************************************************************************
34
// Find the book #
35
if (isset($_GET['book_id'])) {
36
    $book_id = (int)$_GET['book_id'];
37
} else {
38
    bookshop_redirect(_BOOKSHOP_ERROR1, 'index.php', 5);
39
}
40
// The book exists?
41
$book = null;
42
$book = $h_bookshop_books->get($book_id);
43
if (!is_object($book)) {
44
    bookshop_redirect(_BOOKSHOP_ERROR1, 'index.php', 5);
45
}
46
47
// The book is online?
48
if ($book->getVar('book_online') == 0) {
49
    bookshop_redirect(_BOOKSHOP_ERROR2, 'index.php', 5);
50
}
51
52
// The book is published?
53 View Code Duplication
if (bookshop_getmoduleoption('show_unpublished') == 0 && $book->getVar('book_submitted') > time()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    bookshop_redirect(_BOOKSHOP_ERROR3, 'index.php', 5);
55
}
56
57
//  Should we view the books even when not in stock?
58 View Code Duplication
if (bookshop_getmoduleoption('nostock_display') == 0 && $book->getVar('book_stock') == 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    if (xoops_trim(bookshop_getmoduleoption('nostock_display')) != '') {
60
        bookshop_redirect(bookshop_getmoduleoption('nostock_display'), 'index.php', 5);
0 ignored issues
show
bookshop_getmoduleoption('nostock_display') is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
    }
62
}
63
// End of the tests, if it is still there is that everything is good ******************************** ******
64
$title = strip_tags($book->getVar('book_title')) . ' - ' . bookshop_get_module_name();
65
66
if (!isset($_GET['op'])) {
67
    $xoopsOption['template_main'] = 'bookshop_book.tpl';
68
    $GLOBALS['current_category']  = $book->getVar('book_cid');
69
    include_once XOOPS_ROOT_PATH . '/header.php';
70
} elseif (isset($_GET['op']) && $_GET['op'] === 'print') {    // Version imprimable de la page
71
    $GLOBALS['current_category'] = 0;
72
    $xoopsConfig['sitename']     = $title;
73
    xoops_header(false);
74
// Include the module's stylesheet
75
    $url = BOOKSHOP_URL . 'assets/css/bookshop.css';
76
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\" />";
77
    echo '</head><body>';
78
    if (!isset($xoopsTpl)) {
79
        include_once XOOPS_ROOT_PATH . '/class/template.php';
80
        $xoopsTpl = new XoopsTpl();
81
    }
82
}
83
84
if (isset($_GET['stock']) && $_GET['stock'] === 'add' && bookshop_isMemberOfGroup(bookshop_getmoduleoption('grp_qty'))) {
0 ignored issues
show
bookshop_getmoduleoption('grp_qty') is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
    $h_bookshop_books->increaseStock($book);
86
}
87
88
if (isset($_GET['stock']) && $_GET['stock'] === 'substract' && bookshop_isMemberOfGroup(bookshop_getmoduleoption('grp_qty'))) {
0 ignored issues
show
bookshop_getmoduleoption('grp_qty') is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
    $h_bookshop_books->decreaseStock($book);
90
    $h_bookshop_books->verifyLowStock($book);
91
}
92
93
if (!is_object($xoopsUser)) {
94
    $currentUser = 0;
95
} else {
96
    $currentUser = $xoopsUser->getVar('uid');
97
}
98
99
$baseurl = BOOKSHOP_URL . basename(__FILE__) . '?book_id=' . $book->getVar('book_id');
100
101
// Some options for template
102
$xoopsTpl->assign('baseurl', $baseurl);
103
$xoopsTpl->assign('nostock_msg', bookshop_getmoduleoption('nostock_msg'));
104
$xoopsTpl->assign('mod_pref', $mod_pref);    // Module Preferences
105
$xoopsTpl->assign('icones', $icones);
106
$xoopsTpl->assign('canRateBooks', bookshop_getmoduleoption('ratebooks'));    // Module Preferences
107
$xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_BOOKSHOP_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_BOOKSHOP_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/bookshop/book.php?book_id=' . $book_id);
108
$xoopsTpl->assign('canChangeQuantity', bookshop_isMemberOfGroup(bookshop_getmoduleoption('grp_qty')));    // Groupe autoris� � modifier les quantit�s depuis la page
0 ignored issues
show
bookshop_getmoduleoption('grp_qty') is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
109
$xoopsTpl->assign('BookStockQuantity', sprintf(_BOOKSHOP_QUANTITY_STOCK, $book->getVar('book_stock')));
110
111
// Recherche de la cat�gorie du livre
112
$tbl_tmp        = $tbl_categories = $tbl_ancestors = array();
113
$tbl_categories = $h_bookshop_cat->GetAllCategories();
114
$book_category  = null;
115
$book_category  = isset($tbl_categories[$book->getVar('book_cid')]) ? $tbl_categories[$book->getVar('book_cid')] : null;
116
if (!is_object($book_category)) {
117
    bookshop_redirect(_BOOKSHOP_ERROR4, 'index.php', 5);
118
}
119
120
// Search for language
121
$book_langue = null;
122
$book_langue = $h_bookshop_lang->get($book->getVar('book_lang_id'));
123
if (!is_object($book_langue)) {
124
    bookshop_redirect(_BOOKSHOP_ERROR5, 'index.php', 5);
125
}
126
127
// Load all VAT
128
$tblVat = array();
129
$tblVat = $h_bookshop_vat->GetAllVats();
130
131
// Search of his VAT
132
$book_vat = null;
133
if (isset($tblVat[$book->getVar('book_vat_id')])) {
134
    $book_vat = $tblVat[$book->getVar('book_vat_id')];
135
}
136
if (!is_object($book_vat)) {
137
    bookshop_redirect(_BOOKSHOP_ERROR6, 'index.php', 5);
138
}
139
140
// User Search has submitted this book
141
$book_user    = null;
142
$user_handler = $member_handler = xoops_getHandler('user');
143
$book_user    = $user_handler->get($book->getVar('book_submitter'), true);
144
$xoopsTpl->assign('book_submitter', $book_user);
145
146
// Scan the book translators and translators ***************************************** *****
147
$tbl_auteurs = $tbl_translators = $tbl_tmp = $tbl_tmp2 = $tbl_join1 = $tbl_join2 = array();
148
$criteria    = new Criteria('ba_book_id', $book->getVar('book_id'), '=');
149
$tbl_tmp     = $h_bookshop_booksauthors->getObjects($criteria, true);
150
foreach ($tbl_tmp as $id => $item) {
151
    $tbl_tmp2[] = $item->getVar('ba_auth_id');
152
}
153
if (count($tbl_tmp2) > 0) {
154
    $tbl_books_auteurs = array();
155
    $tbl_auteurs       = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tbl_tmp2) . ')', 'IN'), true);
156
    foreach ($tbl_auteurs as $item) {
157
        if ($item->getVar('auth_type') == 1) {    //Author
158
            $xoopsTpl->append('book_authors', $item->toArray());
159
            $tbl_join1[] =
160
                "<a href='" . $h_bookshop_authors->GetAuthorLink($item->getVar('auth_id'), $item->getVar('auth_name'), $item->getVar('auth_firstname')) . "' title='" . bookshop_makeHrefTitle($item->getVar('auth_firstname') . ' ' . $item->getVar('auth_name')) . "'>" . $item->getVar('auth_firstname')
161
                . ' ' . $item->getVar('auth_name') . '</a>';
162
        } else {        // translator
163
            $xoopsTpl->append('book_translators', $item->toArray());
164
            $tbl_join2[] =
165
                "<a href='" . $h_bookshop_authors->GetAuthorLink($item->getVar('auth_id'), $item->getVar('auth_name'), $item->getVar('auth_firstname')) . "' title='" . bookshop_makeHrefTitle($item->getVar('auth_firstname') . ' ' . $item->getVar('auth_name')) . "'>" . $item->getVar('auth_firstname')
166
                . ' ' . $item->getVar('auth_name') . '</a>';
167
        }
168
    }
169
}
170
if (count($tbl_join1) > 0) {
171
    $xoopsTpl->assign('book_joined_authors', implode(', ', $tbl_join1));
172
}
173
if (count($tbl_join2) > 0) {
174
    $xoopsTpl->assign('book_joined_translators', implode(', ', $tbl_join2));
175
}
176
177
// Search for related books ******************************************** **********************
178
$tbl_tmp  = $tbl_tmp2 = array();
179
$criteria = new Criteria('related_book_id', $book->getVar('book_id'), '=');
180
$tbl_tmp  = $h_bookshop_related->getObjects($criteria);
181
if (count($tbl_tmp) > 0) {
182
    foreach ($tbl_tmp as $item) {
183
        $tbl_tmp2[] = $item->getVar('related_book_related');
184
    }
185
    $tbl_related_books = array();
186
    $tbl_related_books = $h_bookshop_books->getObjects(new Criteria('book_id', '(' . implode(',', $tbl_tmp2) . ')', 'IN'), true);
187
    if (count($tbl_related_books) > 0) {
188
        $cpt = 1;
189
        foreach ($tbl_related_books as $item) {
190
            $tbl_tmp                            = $item->toArray();
191
            $tbl_tmp['count']                   = $cpt;
192
            $tbl_tmp['book_category']           = isset($tbl_categories[$item->getVar('book_cid')]) ? $tbl_categories[$item->getVar('book_cid')]->toArray() : null;
193
            $tbl_tmp['book_price_ttc']          = bookshop_getTTC($item->getVar('book_price'), $tblVat[$item->getVar('book_vat_id')]->getVar('vat_rate'));
194
            $tbl_tmp['book_discount_price_ttc'] = bookshop_getTTC($item->getVar('book_discount_price'), $tblVat[$item->getVar('book_vat_id')]->getVar('vat_rate'));
195
            $xoopsTpl->append('book_related_books', $tbl_tmp);
196
            ++$cpt;
197
        }
198
    }
199
}
200
201
// Information Book ********************************************* *****************************
202
$tbl_tmp                  = array();
203
$tbl_tmp                  = $book->toArray();
204
$tbl_tmp['book_category'] = $book_category->toArray();
205
$tbl_tmp['book_language'] = $book_langue->toArray();
206
if (xoops_trim($book_user->getVar('name')) != '') {
207
    $name = $book_user->getVar('name');
208
} else {
209
    $name = $book_user->getVar('uname');
210
}
211
$tbl_tmp['book_submiter_name']      = $name;
212
$linkeduser                         = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $book_user->getVar('uid') . '">' . $name . '</a>';
213
$tbl_tmp['book_submiter_link']      = $name;
214
$tbl_tmp['book_vat_rate']           = $book_vat->toArray();
215
$tbl_tmp['book_price_ttc']          = bookshop_getTTC($book->getVar('book_price'), $book_vat->getVar('vat_rate'));
216
$tbl_tmp['book_discount_price_ttc'] = bookshop_getTTC($book->getVar('book_discount_price'), $book_vat->getVar('vat_rate'));
217
218
$tbl_tmp['book_rating_formated'] = number_format($book->getVar('book_rating'), 2);
219
if ($book->getVar('book_votes') == 1) {
220
    $tbl_tmp['book_votes_count'] = _BOOKSHOP_ONEVOTE;
221
} else {
222
    $tbl_tmp['book_votes_count'] = sprintf(_BOOKSHOP_NUMVOTES, $book->getVar('book_votes'));
223
}
224
// Assignment Book
225
$xoopsTpl->assign('book', $tbl_tmp);
226
227
// Breadcrumb *************************************************************************************
228
$tbl_tmp       = array();
229
$mytree        = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid');
230
$tbl_ancestors = $mytree->getAllParent($book->getVar('book_cid'));
231
$tbl_ancestors = array_reverse($tbl_ancestors);
232
$tbl_tmp[]     = "<a href='" . BOOKSHOP_URL . "index.php' title='" . bookshop_makeHrefTitle(bookshop_get_module_name()) . "'>" . bookshop_get_module_name() . '</a>';
233 View Code Duplication
foreach ($tbl_ancestors as $item) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
234
    $tbl_tmp[] = "<a href='" . $h_bookshop_cat->GetCategoryLink($item->getVar('cat_cid'), $item->getVar('cat_title')) . "' title='" . bookshop_makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>';
235
}
236
// Add the current category
237
$tbl_tmp[]  = "<a href='" . $h_bookshop_cat->GetCategoryLink($book_category->getVar('cat_cid'), $book_category->getVar('cat_title')) . "' title='" . bookshop_makeHrefTitle($book_category->getVar('cat_title')) . "'>" . $book_category->getVar('cat_title') . '</a>';
238
$tbl_tmp[]  = $book->getVar('book_title');
239
$breadcrumb = implode(' &raquo; ', $tbl_tmp);
240
$xoopsTpl->assign('breadcrumb', $breadcrumb);
241
242
// Shift counter readings ******************************************** ***************************
243
if ($book->getVar('book_submitter') != $currentUser) {
244
    $h_bookshop_books->addCounter($book_id);
245
}
246
247
// Previous and subsequent books ******************************************** **********************
248
if (bookshop_getmoduleoption('showprevnextlink') == 1) {
249
    $xoopsTpl->assign('showprevnextlink', true);
250
    //  Book Search following the current book.
251
    $criteria = new CriteriaCompo();
252
    $criteria->add(new Criteria('book_online', 1, '='));
253
    if (bookshop_getmoduleoption('show_unpublished') == 0) {    // Ne pas afficher les livres qui ne sont pas publi�s
254
        $criteria->add(new Criteria('book_submitted', time(), '<='));
255
    }
256
    if (bookshop_getmoduleoption('nostock_display') == 0) {    // Se limiter aux seuls livres encore en stock
257
        $criteria->add(new Criteria('book_stock', 0, '>'));
258
    }
259
    $criteria->add(new Criteria('book_id', $book->getVar('book_id'), '>'));
260
    $criteria->setOrder('DESC');
261
    $criteria->setSort('book_submitted');
262
    $criteria->setLimit(1);
263
    $tbl = array();
264
    $tbl = $h_bookshop_books->getObjects($criteria);
265 View Code Duplication
    if (count($tbl) == 1) {    // Trouv�
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
266
        $tmpBook = null;
267
        $tmpBook = $tbl[0];
268
        $xoopsTpl->assign('next_book_id', $tmpBook->getVar('book_id'));
269
        $xoopsTpl->assign('next_book_title', $tmpBook->getVar('book_title'));
270
        $xoopsTpl->assign('next_book_url_rewrited', $h_bookshop_books->GetBookLink($tmpBook->getVar('book_id'), $tmpBook->getVar('book_title')));
271
        $xoopsTpl->assign('next_book_href_title', bookshop_makeHrefTitle($tmpBook->getVar('book_title')));
272
    } else {
273
        $xoopsTpl->assign('next_book_id', 0);
274
    }
275
276
    // Book Search preceding the current book.
277
    $criteria = new CriteriaCompo();
278
    $criteria->add(new Criteria('book_online', 1, '='));
279
    if (bookshop_getmoduleoption('show_unpublished') == 0) {    // // Do not display books that are not published
280
        $criteria->add(new Criteria('book_submitted', time(), '<='));
281
    }
282
    if (bookshop_getmoduleoption('nostock_display') == 0) {    // If limited only to books still in stock
283
        $criteria->add(new Criteria('book_stock', 0, '>'));
284
    }
285
    $criteria->add(new Criteria('book_id', $book->getVar('book_id'), '<'));
286
    $criteria->setOrder('DESC');
287
    $criteria->setSort('book_submitted');
288
    $criteria->setLimit(1);
289
    $tbl = array();
290
    $tbl = $h_bookshop_books->getObjects($criteria);
291 View Code Duplication
    if (count($tbl) == 1) {    // Trouv�
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
292
        $tmpBook = null;
293
        $tmpBook = $tbl[0];
294
        $xoopsTpl->assign('previous_book_id', $tmpBook->getVar('book_id'));
295
        $xoopsTpl->assign('previous_book_title', $tmpBook->getVar('book_title'));
296
        $xoopsTpl->assign('previous_book_url_rewrited', $h_bookshop_books->GetBookLink($tmpBook->getVar('book_id'), $tmpBook->getVar('book_title')));
297
        $xoopsTpl->assign('previous_book_href_title', bookshop_makeHrefTitle($tmpBook->getVar('book_title')));
298
    } else {
299
        $xoopsTpl->assign('previous_book_id', 0);
300
    }
301
} else {
302
    $xoopsTpl->assign('showprevnextlink', false);
303
}
304
// X latest books all categories ****************************************** *******
305
$count = bookshop_getmoduleoption('summarylast');
306
$xoopsTpl->assign('summarylast', $count);
307 View Code Duplication
if ($count > 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
308
    $tblTmp = array();
309
    $tblTmp = $h_bookshop_books->getRecentBooks(0, $count);
310
    foreach ($tblTmp as $item) {
311
        $datas = array(
312
            'last_categs_book_title'        => $item->getVar('book_title'),
313
            'last_categs_book_url_rewrited' => $h_bookshop_books->GetBookLink($item->getVar('book_id'), $item->getVar('book_title')),
314
            'last_categs_book_href_title'   => bookshop_makeHrefTitle($item->getVar('book_title'))
315
        );
316
        $xoopsTpl->append('book_all_categs', $datas);
317
    }
318
    unset($tblTmp);
319
}
320
321
// X latest books in this category ****************************************** ***************
322
$count = bookshop_getmoduleoption('summarycategory');
323
$xoopsTpl->assign('summarycategory', $count);
324 View Code Duplication
if ($count > 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
325
    $tblTmp = array();
326
    $tblTmp = $h_bookshop_books->getRecentBooks(0, $count, $book->getVar('book_cid'));
327
    foreach ($tblTmp as $item) {
328
        $datas = array(
329
            'last_categ_book_title'        => $item->getVar('book_title'),
330
            'last_categ_book_url_rewrited' => $h_bookshop_books->GetBookLink($item->getVar('book_id'), $item->getVar('book_title')),
331
            'last_categ_book_href_title'   => bookshop_makeHrefTitle($item->getVar('book_title'))
332
        );
333
        $xoopsTpl->append('book_current_categ', $datas);
334
    }
335
    unset($tblTmp);
336
}
337
338
// Two is better ******************************************* ************************************
339
$count = bookshop_getmoduleoption('better_together');
340
$xoopsTpl->assign('better_together', $count);
341
if ($count > 0) {
342
    $bookWith = 0;
343
    // Search for the book that has sold the most with this book
344
    $bookWith = $h_bookshop_caddy->getBestWith($book->getVar('book_id'));
345
    if ($bookWith > 0) {
346
        $tmpBook = null;
347
        $tmpBook = $h_bookshop_books->get($bookWith);
348
        if (is_object($tmpBook)) {
349
            $tmp                            = array();
350
            $tmp                            = $tmpBook->toArray();
351
            $tmp['book_price_ttc']          = bookshop_getTTC($tmpBook->getVar('book_price'), $tblVat[$tmpBook->getVar('book_vat_id')]->getVar('vat_rate'));
352
            $tmp['book_discount_price_ttc'] = bookshop_getTTC($tmpBook->getVar('book_discount_price'), $tblVat[$tmpBook->getVar('book_vat_id')]->getVar('vat_rate'));
353
            $xoopsTpl->assign('bestwith', $tmp);
354
        }
355
    }
356
}
357
358
// Book Notation ********************************************** ***********************************
359
if (bookshop_getmoduleoption('ratebooks') == 1) {
360
    $ip      = bookshop_IP();
361
    $canRate = true;
362
    if ($currentUser != 0) {
363
        $criteria = new CriteriaCompo();
364
        $criteria->add(new Criteria('vote_book_id', $book->getVar('book_id'), '='));
365
        $criteria->add(new Criteria('vote_uid', $currentUser, '='));
366
        $cnt = 0;
367
        $cnt = $h_bookshop_votedata->getCount($criteria);
368
        if ($cnt > 0) {
369
            $canRate = false;
370
        }
371
    } else {
372
        $criteria = new CriteriaCompo();
373
        $criteria->add(new Criteria('vote_book_id', $book->getVar('book_id'), '='));
374
        $criteria->add(new Criteria('vote_uid', 0, '='));
375
        $criteria->add(new Criteria('vote_ratinghostname', $ip, '='));
376
        $criteria->add(new Criteria('vote_ratingtimestamp', $yesterday, '>'));
377
        $cnt = $h_bookshop_votedata->getCount($criteria);
378
        if ($cnt > 0) {
379
            $canRate = false;
380
        }
381
    }
382
    $xoopsTpl->assign('userCanRate', $canRate);
383
}
384
385
// Meta and CSS ********************************************* ***************************************
386
bookshop_setCSS();
387
388
if (bookshop_getmoduleoption('manual_meta')) {
389
    $pageTitle       = xoops_trim($book->getVar('book_metatitle')) == '' ? $title : $book->getVar('book_metatitle');
390
    $metaDescription = xoops_trim($book->getVar('book_metadescription')) != '' ? $book->getVar('book_metadescription') : $title;
391
    $metaKeywords    = xoops_trim($book->getVar('book_metakeywords')) != '' ? $book->getVar('book_metakeywords') : bookshop_createmeta_keywords($book->getVar('book_title') . ' ' . $book->getVar('book_summary') . ' ' . $book->getVar('book_description'));
392
    bookshop_set_metas($pageTitle, $metaDescription, $metaKeywords);
393
} else {
394
    bookshop_set_metas($title, $title, bookshop_createmeta_keywords($book->getVar('book_title') . ' ' . $book->getVar('book_summary') . ' ' . $book->getVar('book_description')));
395
}
396
397
if (!isset($_GET['op'])) {
398
    include_once XOOPS_ROOT_PATH . '/include/comment_view.php';
399
    include_once XOOPS_ROOT_PATH . '/footer.php';
400
} elseif (isset($_GET['op']) && $_GET['op'] === 'print') {    // // Print the page
401
    $xoopsTpl->display('db:bookshop_book.tpl');
402
    xoops_footer();
403
}
404