Issues (608)

Security Analysis    not enabled

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

product.php (3 issues)

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
/**
21
 * Showing a product
22
 */
23
24
use XoopsModules\Oledrion;
25
26
require_once __DIR__ . '/header.php';
27
require_once XOOPS_ROOT_PATH . '/class/tree.php';
28
29
$product_id = 0;
30
// Tests **************************************************************************************
31
// Product number search
32
if (\Xmf\Request::hasVar('product_id', 'GET')) {
33
    $product_id = \Xmf\Request::getInt('product_id', 0, 'GET');
34
} else {
35
    Oledrion\Utility::redirect(_OLEDRION_ERROR1, 'index.php', 5);
36
}
37
// Does product exist ?
38
$product = null;
39
/** @var Oledrion\Products $product */
40
$product = $productsHandler->get($product_id);
41
if (!is_object($product)) {
42
    Oledrion\Utility::redirect(_OLEDRION_ERROR1, 'index.php', 5);
43
}
44
45
// Le produit est en ligne ?
46
if (0 == $product->getVar('product_online')) {
47
    Oledrion\Utility::redirect(_OLEDRION_ERROR2, 'index.php', 5);
48
}
49
50
// The product is published ?
51
if (0 == Oledrion\Utility::getModuleOption('show_unpublished') && $product->getVar('product_submitted') > time()) {
52
    Oledrion\Utility::redirect(_OLEDRION_ERROR3, 'index.php', 5);
53
}
54
55
// Must display products even when they are no longer in stock ?
56
if (0 == Oledrion\Utility::getModuleOption('nostock_display') && 0 == $product->getVar('product_stock')) {
57
    if ('' !== xoops_trim(Oledrion\Utility::getModuleOption('nostock_display'))) {
58
        Oledrion\Utility::redirect(Oledrion\Utility::getModuleOption('nostock_display'), 'main.php', 5);
59
    }
60
}
61
62
// End of the tests, if we are still there it is that everything is good **************************************
63
//$title = strip_tags($product->getVar('product_title')) . ' - ' . Oledrion\Utility::getModuleName();
64
$title = strip_tags($product->getVar('product_title'));
65
//$handlers = HandlerManager::getInstance();
66
$db           = \XoopsDatabaseFactory::getDatabaseConnection();
67
$caddyHandler = new Oledrion\CaddyHandler($db);
68
$op           = isset($_GET['op']) ? $_GET['op'] : 'default';
69
switch ($op) {
70
    // product Print
71
    case 'print':
72
73
        require_once XOOPS_ROOT_PATH . '/header.php';
74
75
        $GLOBALS['current_category'] = 0;
76
        $xoopsConfig['sitename']     = $title;
77
        // product to array
78
        $product = $product->toArray();
79
        // Set local style
80
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css')) {
81
            $xoopsTpl->assign('localstyle', XOOPS_URL . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css');
82
        } else {
83
            $xoopsTpl->assign('localstyle', XOOPS_URL . '/language/english/style.css');
84
        }
85
        // Index Variable
86
        $xoopsTpl->assign('xoops_sitename', $xoopsConfig['sitename']);
87
        $xoopsTpl->assign('xoops_pagetitle', $title);
88
        $xoopsTpl->assign('product', $product);
89
        // Display print page
90
        echo $xoopsTpl->fetch(OLEDRION_PATH . '/templates/oledrion_product_print.tpl');
91
92
        break;
93
    // product view
94
    case 'default':
95
96
    default:
97
        // VAT reading ********************************************************************************
98
99
        //        $vatArray = [];
100
        $vatArray = $vatHandler->getAllVats(new Oledrion\Parameters());
101
102
        $GLOBALS['xoopsOption']['template_main'] = 'oledrion_product.tpl';
103
        $GLOBALS['current_category']             = $product->getVar('product_cid');
104
        require_once XOOPS_ROOT_PATH . '/header.php';
105
106
        if (!OLEDRION_MY_THEME_USES_JQUERY) {
107
            $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
108
        }
109
        //Oledrion\Utility::callJavascriptFile('noconflict.js');
110
        // Add lightbox
111
        //$xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
112
        //$xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
113
114
        if (\Xmf\Request::hasVar('stock', 'GET') && 'add' === $_GET['stock'] && Oledrion\Utility::isMemberOfGroup(Oledrion\Utility::getModuleOption('grp_qty'))) {
115
            $productsHandler->increaseStock($product);
116
        }
117
118
        if (\Xmf\Request::hasVar('stock', 'GET') && 'substract' === $_GET['stock'] && Oledrion\Utility::isMemberOfGroup(Oledrion\Utility::getModuleOption('grp_qty'))) {
119
            $productsHandler->decreaseStock($product);
120
            $productsHandler->verifyLowStock($product);
121
        }
122
123
        $currentUser = Oledrion\Utility::getCurrentUserID();
124
        $xoopsTpl->assign('currentUserId', $currentUser);
125
126
        $baseurl = OLEDRION_URL . basename(__FILE__) . '?product_id=' . $product->getVar('product_id');
127
128
        if (Oledrion\Utility::getModuleOption('use_tags')) {
129
            require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
130
            $xoopsTpl->assign('tagbar', tagBar($product_id, 0));
131
        }
132
133
        // Some options for the template
134
        $xoopsTpl->assign('baseurl', $baseurl);
135
        $xoopsTpl->assign('nostock_msg', Oledrion\Utility::getModuleOption('nostock_msg'));
136
        $xoopsTpl->assign('mod_pref', $mod_pref);
137
        // Module Preferences
138
        $xoopsTpl->assign('columnsCount', Oledrion\Utility::getModuleOption('category_colums'));
139
        $xoopsTpl->assign('icons', $icons);
140
        $xoopsTpl->assign('canRateProducts', Oledrion\Utility::getModuleOption('rateproducts'));
141
        // Module Preferences
142
        $xoopsTpl->assign('mail_link', 'mailto:?subject=' . sprintf(_OLEDRION_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_OLEDRION_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/oledrion/product.php?product_id=' . $product_id);
143
        $xoopsTpl->assign('canChangeQuantity', Oledrion\Utility::isMemberOfGroup(Oledrion\Utility::getModuleOption('grp_qty')));
144
        // Group allowed to change quantities from page
145
        $xoopsTpl->assign('ProductStockQuantity', sprintf(_OLEDRION_QUANTITY_STOCK, $product->getVar('product_stock')));
146
147
        // Product category search
148
        $tbl_tmp          = $tbl_categories = $tbl_ancestors = [];
149
        $tbl_categories   = $categoryHandler->getAllCategories(new Oledrion\Parameters());
150
        $product_category = null;
151
        $product_category = isset($tbl_categories[$product->getVar('product_cid')]) ? $tbl_categories[$product->getVar('product_cid')] : null;
152
        if (!is_object($product_category)) {
153
            Oledrion\Utility::redirect(_OLEDRION_ERROR4, 'index.php', 5);
154
        }
155
156
        // Search for your language
157
        $product_vendor = null;
158
        $product_vendor = $vendorsHandler->get($product->getVar('product_vendor_id'));
159
        if (!is_object($product_vendor)) {
160
            Oledrion\Utility::redirect(_OLEDRION_ERROR5, 'index.php', 5);
161
        }
162
163
        // Loading all VAT
164
        $tblVat = [];
165
        $tblVat = $vatHandler->getAllVats(new Oledrion\Parameters());
166
167
        // Search for VAT
168
        $product_vat = null;
169
        if (isset($tblVat[$product->getVar('product_vat_id')])) {
170
            $product_vat = $tblVat[$product->getVar('product_vat_id')];
171
        }
172
        if (!is_object($product_vat) && Oledrion\Utility::getModuleOption('use_price')) {
173
            Oledrion\Utility::redirect(_OLEDRION_ERROR6, 'index.php', 5);
174
        }
175
176
        // Search for the user who submitted this product
177
        $product_user = null;
178
        $userHandler  = $memberHandler = xoops_getHandler('user');
179
        $product_user = $userHandler->get($product->getVar('product_submitter'), true);
0 ignored issues
show
The call to XoopsObjectHandler::get() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

179
        /** @scrutinizer ignore-call */ 
180
        $product_user = $userHandler->get($product->getVar('product_submitter'), true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Are you sure the assignment to $product_user is correct as $userHandler->get($produ...duct_submitter'), true) targeting XoopsObjectHandler::get() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
180
        $xoopsTpl->assign('product_submitter', $product_user);
181
182
        // Image of the "Add to cart" button
183
        if (file_exists(OLEDRION_PATH . 'language/' . $xoopsConfig['language'] . '/image/addtocart.png')) {
184
            $addToCart     = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/addtocart.png';
185
            $addToWishList = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/addtowishlist.png';
186
        } else {
187
            // Fallback
188
            $addToCart     = OLEDRION_URL . 'language/english/image/addtocart.png';
189
            $addToWishList = OLEDRION_URL . 'language/english/image/addtowishlist.png';
190
        }
191
        $xoopsTpl->assign('addToCartImage', $addToCart);
192
        $xoopsTpl->assign('addToWishList', $addToWishList);
193
194
        // Search for the product manufacturers **********************************************
195
        $tbl_auteurs = $tbl_translators = $tbl_tmp = $tbl_tmp2 = $tbl_join1 = $tbl_join2 = [];
196
        $criteria    = new \Criteria('pm_product_id', $product->getVar('product_id'), '=');
197
        $tbl_tmp     = $productsmanuHandler->getObjects($criteria, true);
198
        foreach ($tbl_tmp as $id => $item) {
199
            $tbl_tmp2[] = $item->getVar('pm_manu_id');
200
        }
201
        if (count($tbl_tmp2) > 0) {
202
            $tbl_product_manufacturers = [];
203
            $tbl_auteurs               = $manufacturerHandler->getObjects(new \Criteria('manu_id', '(' . implode(',', $tbl_tmp2) . ')', 'IN'), true);
204
            foreach ($tbl_auteurs as $item) {
205
                $xoopsTpl->append('product_manufacturers', $item->toArray());
206
                $tbl_join1[] = "<a href='" . $item->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($item->getVar('manu_commercialname') . ' ' . $item->getVar('manu_name')) . "'>" . $item->getVar('manu_commercialname') . ' ' . $item->getVar('manu_name') . '</a>';
207
            }
208
        }
209
        if (count($tbl_join1) > 0) {
210
            $xoopsTpl->assign('product_joined_manufacturers', implode(', ', $tbl_join1));
211
        }
212
        if (count($tbl_join2) > 0) {
213
            $xoopsTpl->assign('product_joined_vendors', implode(', ', $tbl_join2));
214
        }
215
216
        // Search related products ******************************************************************
217
        $revertRelated = false;
218
        $tbl_tmp       = $tbl_tmp2 = [];
219
        $criteria      = new \Criteria('related_product_id', $product->getVar('product_id'), '=');
220
        $tbl_tmp       = $relatedHandler->getObjects($criteria);
221
222
        // If there are no related products and the right option is activated,
223
        // we search for products "in the other direction"
224
        // (the cases where the current product is marked as a relative product)
225
        if (OLEDRION_RELATED_BOTH && 0 === count($tbl_tmp)) {
226
            unset($criteria);
227
            $tbl_tmp       = [];
228
            $criteria      = new \Criteria('related_product_related', $product->getVar('product_id'), '=');
229
            $tbl_tmp       = $relatedHandler->getObjects($criteria);
230
            $revertRelated = true;
231
        }
232
233
        if (count($tbl_tmp) > 0) {
234
            foreach ($tbl_tmp as $item) {
235
                if (!$revertRelated) {
236
                    $tbl_tmp2[] = $item->getVar('related_product_related');
237
                } else {
238
                    $tbl_tmp2[] = $item->getVar('related_product_id');
239
                }
240
            }
241
            $criteria = new \Criteria('product_id', '(' . implode(',', $tbl_tmp2) . ')', 'IN');
242
            $criteria->setLimit(Oledrion\Utility::getModuleOption('related_limit'));
243
            $criteria->setOrder('DESC');
244
            $criteria->setSort('product_id');
245
            //  $tbl_related_products = [];
246
            $tbl_related_products = $productsHandler->getObjects($criteria, true);
247
            if (count($tbl_related_products) > 0) {
248
                $cpt = 1;
249
                foreach ($tbl_related_products as $item) {
250
                    $tbl_tmp                     = $item->toArray();
251
                    $tbl_tmp['count']            = $cpt;
252
                    $tbl_tmp['product_category'] = isset($tbl_categories[$item->getVar('product_cid')]) ? $tbl_categories[$item->getVar('product_cid')]->toArray() : null;
253
                    $xoopsTpl->append('product_related_products', $tbl_tmp);
254
                    ++$cpt;
255
                }
256
            }
257
        }
258
259
        // Finding files attached to the product *******************************************************
260
        $attachedFiles      = $mp3AttachedFilesList = $attachedFilesForTemplate = [];
261
        $attachedFilesCount = $filesHandler->getProductFilesCount($product->getVar('product_id'));
262
        if ($attachedFilesCount > 0) {
263
            $attachedFiles = $filesHandler->getProductFiles($product->getVar('product_id'));
264
            foreach ($attachedFiles as $attachedFile) {
265
                // File search MP3
266
                if ($attachedFile->isMP3()) {
267
                    $mp3AttachedFilesList[] = $attachedFile->getURL();
268
                }
269
                $attachedFilesForTemplate[] = $attachedFile->toArray();
270
            }
271
            if (count($mp3AttachedFilesList) > 0) {
272
                Oledrion\Utility::callJavascriptFile('jquery.swfobject/jquery.swfobject.min.js');
273
                $xoopsTpl->assign('mp3FilesList', implode('|', $mp3AttachedFilesList));
274
            }
275
        }
276
277
        // Product Information **************************************************************************
278
        $tbl_tmp = [];
279
        $tbl_tmp = $product->toArray();
280
        // Attached files
281
        $tbl_tmp['attached_mp3_count']     = count($mp3AttachedFilesList);
282
        $tbl_tmp['attached_non_mp3_count'] = count($attachedFilesForTemplate) - count($mp3AttachedFilesList);
283
        $tbl_tmp['attached_files']         = $attachedFilesForTemplate;
284
        // The complete list of all attached files
285
286
        $tbl_tmp['product_category'] = $product_category->toArray();
287
        $tbl_tmp['product_vendor']   = $product_vendor->toArray();
288
        if ('' !== xoops_trim($product_user->getVar('name'))) {
289
            $name = $product_user->getVar('name');
290
        } else {
291
            $name = $product_user->getVar('uname');
292
        }
293
        $tbl_tmp['product_submiter_name'] = $name;
294
        $linkeduser                       = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $product_user->getVar('uid') . '">' . $name . '</a>';
295
        $tbl_tmp['product_submiter_link'] = $name;
296
        if (is_object($product_vat)) {
297
            $tbl_tmp['product_vat_rate'] = $product_vat->toArray();
298
        }
299
300
        $tbl_tmp['product_rating_formated'] = number_format($product->getVar('product_rating'), 2);
301
        if (1 == $product->getVar('product_votes')) {
302
            $tbl_tmp['product_votes_count'] = _OLEDRION_ONEVOTE;
303
        } else {
304
            $tbl_tmp['product_votes_count'] = sprintf(_OLEDRION_NUMVOTES, $product->getVar('product_votes'));
305
        }
306
        // Attributs
307
        if ($attributesHandler->getProductAttributesCount($product_id) > 0) {
308
            $attributes           = [];
309
            $mandatoryFieldsCount = 0;
310
            if ($caddyHandler->isInCart($product_id)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $caddyHandler->isInCart($product_id) of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
311
            }
312
            $attributes = $attributesHandler->constructHtmlProductAttributes($product, $mandatoryFieldsCount);
313
            if (count($attributes) > 0) {
314
                Oledrion\Utility::callJavascriptFile('validate/jquery.validate.min.js');
315
                Oledrion\Utility::setCSS(OLEDRION_URL . 'assets/css/validate.css');
316
                $tbl_tmp['product_attributes'] = $attributes;
317
                $xoopsTpl->assign('mandatoryFieldsCount', $mandatoryFieldsCount);
318
            }
319
        }
320
        // Product
321
        $tbl_tmp['product_property1_title']  = Oledrion\Utility::getModuleOption('product_property1_title');
322
        $tbl_tmp['product_property2_title']  = Oledrion\Utility::getModuleOption('product_property2_title');
323
        $tbl_tmp['product_property3_title']  = Oledrion\Utility::getModuleOption('product_property3_title');
324
        $tbl_tmp['product_property4_title']  = Oledrion\Utility::getModuleOption('product_property4_title');
325
        $tbl_tmp['product_property5_title']  = Oledrion\Utility::getModuleOption('product_property5_title');
326
        $tbl_tmp['product_property6_title']  = Oledrion\Utility::getModuleOption('product_property6_title');
327
        $tbl_tmp['product_property7_title']  = Oledrion\Utility::getModuleOption('product_property7_title');
328
        $tbl_tmp['product_property8_title']  = Oledrion\Utility::getModuleOption('product_property8_title');
329
        $tbl_tmp['product_property9_title']  = Oledrion\Utility::getModuleOption('product_property9_title');
330
        $tbl_tmp['product_property10_title'] = Oledrion\Utility::getModuleOption('product_property10_title');
331
332
        $xoopsTpl->assign('product', $tbl_tmp);
333
334
        // Breadcrumb *************************************************************************************
335
        $tbl_tmp       = [];
336
        $mytree        = new Oledrion\XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid');
337
        $tbl_ancestors = array_reverse($mytree->getAllParent($product->getVar('product_cid')));
338
        $tbl_tmp[]     = "<a href='" . OLEDRION_URL . "index.php' title='" . Oledrion\Utility::makeHrefTitle(Oledrion\Utility::getModuleName()) . "'>" . Oledrion\Utility::getModuleName() . '</a>';
339
        foreach ($tbl_ancestors as $item) {
340
            $tbl_tmp[] = "<a href='" . $item->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>';
341
        }
342
        // Adding the current category
343
        $tbl_tmp[]  = "<a href='" . $product_category->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($product_category->getVar('cat_title')) . "'>" . $product_category->getVar('cat_title') . '</a>';
344
        $tbl_tmp[]  = $product->getVar('product_title');
345
        $breadcrumb = implode(' &raquo; ', $tbl_tmp);
346
        $xoopsTpl->assign('breadcrumb', $breadcrumb);
347
348
        // Shift counter readings ***********************************************************************
349
        if ($product->getVar('product_submitter') != $currentUser) {
350
            $productsHandler->addCounter($product_id);
351
        }
352
353
        // previous and next products ******************************************************************
354
        if (1 == Oledrion\Utility::getModuleOption('showprevnextlink')) {
355
            $xoopsTpl->assign('showprevnextlink', true);
356
            // Search for the product according to the current product.
357
            $criteria = new \CriteriaCompo();
358
            $criteria->add(new \Criteria('product_online', 1, '='));
359
            if (0 == Oledrion\Utility::getModuleOption('show_unpublished')) {
360
                // Do not display products that are not published
361
                $criteria->add(new \Criteria('product_submitted', time(), '<='));
362
            }
363
            if (0 == Oledrion\Utility::getModuleOption('nostock_display')) {
364
                // Limit to only products still in stock
365
                $criteria->add(new \Criteria('product_stock', 0, '>'));
366
            }
367
            $criteria->add(new \Criteria('product_id', $product->getVar('product_id'), '>'));
368
            $criteria->setOrder('DESC');
369
            $criteria->setSort('product_submitted');
370
            $criteria->setLimit(1);
371
            //            $tbl = [];
372
            $tbl = $productsHandler->getObjects($criteria);
373
            if (1 == count($tbl)) {
374
                // Found
375
                $tmpProduct = null;
376
                $tmpProduct = $tbl[0];
377
                $xoopsTpl->assign('next_product_id', $tmpProduct->getVar('product_id'));
378
                $xoopsTpl->assign('next_product_title', $tmpProduct->getVar('product_title'));
379
                $xoopsTpl->assign('next_product_url_rewrited', $tmpProduct->getLink());
380
                $xoopsTpl->assign('next_product_href_title', Oledrion\Utility::makeHrefTitle($tmpProduct->getVar('product_title')));
381
            } else {
382
                $xoopsTpl->assign('next_product_id', 0);
383
            }
384
385
            // Search for the product preceding the current product.
386
            $criteria = new \CriteriaCompo();
387
            $criteria->add(new \Criteria('product_online', 1, '='));
388
            if (0 == Oledrion\Utility::getModuleOption('show_unpublished')) {
389
                // Do not display products that are not published
390
                $criteria->add(new \Criteria('product_submitted', time(), '<='));
391
            }
392
            if (0 == Oledrion\Utility::getModuleOption('nostock_display')) {
393
                // Limit to only products still in stock
394
                $criteria->add(new \Criteria('product_stock', 0, '>'));
395
            }
396
            $criteria->add(new \Criteria('product_id', $product->getVar('product_id'), '<'));
397
            $criteria->setOrder('DESC');
398
            $criteria->setSort('product_submitted');
399
            $criteria->setLimit(1);
400
            $tbl = [];
401
            $tbl = $productsHandler->getObjects($criteria);
402
            if (1 == count($tbl)) {
403
                // Found
404
                $tmpProduct = null;
405
                $tmpProduct = $tbl[0];
406
                $xoopsTpl->assign('previous_product_id', $tmpProduct->getVar('product_id'));
407
                $xoopsTpl->assign('previous_product_title', $tmpProduct->getVar('product_title'));
408
                $xoopsTpl->assign('previous_product_url_rewrited', $tmpProduct->getLink());
409
                $xoopsTpl->assign('previous_product_href_title', Oledrion\Utility::makeHrefTitle($tmpProduct->getVar('product_title')));
410
            } else {
411
                $xoopsTpl->assign('previous_product_id', 0);
412
            }
413
        } else {
414
            $xoopsTpl->assign('showprevnextlink', false);
415
        }
416
        // x latest products in all categories *************************************************
417
        $count = Oledrion\Utility::getModuleOption('summarylast');
418
        $xoopsTpl->assign('summarylast', $count);
419
        if ($count > 0) {
420
            $tblTmp = [];
421
            $tblTmp = $productsHandler->getRecentProducts(new Oledrion\Parameters([
422
                                                                                      'start'    => 0,
423
                                                                                      'limit'    => $count,
424
                                                                                      'category' => 0,
425
                                                                                      'sort'     => 'product_submitted DESC, product_title',
426
                                                                                      'order'    => '',
427
                                                                                      'excluded' => $product_id,
428
                                                                                  ]));
429
            foreach ($tblTmp as $item) {
430
                $product_price     = $item->getVar('product_price');
431
                $product_price_ttc = Oledrion\Utility::getTTC($item->getVar('product_price'), 0);
432
                if ($attributesHandler->getProductAttributesCount($item->getVar('product_id')) > 0) {
433
                    $criteria = new \CriteriaCompo();
434
                    $criteria->add(new \Criteria('attribute_product_id', $item->getVar('product_id')));
435
                    $attribute = $attributesHandler->getObjects($criteria, false);
436
                    foreach ($attribute as $root) {
437
                        $product_price     = $root->getVar('attribute_default_value');
438
                        $product_price_ttc = Oledrion\Utility::getTTC($root->getVar('attribute_default_value'), 0);
439
                    }
440
                }
441
                $datas = [
442
                    'last_categ_product_title'        => $item->getVar('product_title'),
443
                    'last_categ_product_url_rewrited' => $item->getLink(),
444
                    'last_categ_product_href_title'   => Oledrion\Utility::makeHrefTitle($item->getVar('product_title')),
445
                    'product_thumb_url'               => $item->getVar('product_thumb_url'),
446
                    'product_thumb_full_url'          => $item->getThumbUrl(),
447
                    'product_url_rewrited'            => $item->getLink(),
448
                    'product_href_title'              => Oledrion\Utility::makeHrefTitle($item->getVar('product_title')),
449
                    'product_title'                   => $item->getVar('product_title'),
450
                    'product_property1'               => $item->getVar('product_property1'),
451
                    'product_property2'               => $item->getVar('product_property2'),
452
                    'product_property3'               => $item->getVar('product_property3'),
453
                    'product_property4'               => $item->getVar('product_property4'),
454
                    'product_property5'               => $item->getVar('product_property5'),
455
                    'product_property6'               => $item->getVar('product_property6'),
456
                    'product_property7'               => $item->getVar('product_property7'),
457
                    'product_property8'               => $item->getVar('product_property8'),
458
                    'product_property9'               => $item->getVar('product_property9'),
459
                    'product_property10'              => $item->getVar('product_property10'),
460
                    'product_id'                      => $item->getVar('product_id'),
461
                    'product_new'                     => $item->isNewProduct(),
462
                    'product_stock'                   => $item->getVar('product_stock'),
463
                    'product_price'                   => $product_price,
464
                    'product_price_ttc'               => $product_price_ttc,
465
                ];
466
                $xoopsTpl->append('product_all_categs', $datas);
467
            }
468
            unset($tblTmp);
469
        }
470
471
        // x latest products in this category *********************************************************
472
        $count = Oledrion\Utility::getModuleOption('summarycategory');
473
        $xoopsTpl->assign('summarycategory', $count);
474
        if ($count > 0) {
475
            $tblTmp = [];
476
            $tblTmp = $productsHandler->getRecentProducts(new Oledrion\Parameters([
477
                                                                                      'start'    => 0,
478
                                                                                      'limit'    => $count,
479
                                                                                      'category' => $product->getVar('product_cid'),
480
                                                                                      'sort'     => 'product_submitted DESC, product_title',
481
                                                                                      'order'    => '',
482
                                                                                      'excluded' => $product_id,
483
                                                                                  ]));
484
            foreach ($tblTmp as $item) {
485
                $product_price     = $item->getVar('product_price');
486
                $product_price_ttc = Oledrion\Utility::getTTC($item->getVar('product_price'), 0);
487
                if ($attributesHandler->getProductAttributesCount($item->getVar('product_id')) > 0) {
488
                    $criteria = new \CriteriaCompo();
489
                    $criteria->add(new \Criteria('attribute_product_id', $item->getVar('product_id')));
490
                    $attribute = $attributesHandler->getObjects($criteria, false);
491
                    foreach ($attribute as $root) {
492
                        $product_price     = $root->getVar('attribute_default_value');
493
                        $product_price_ttc = Oledrion\Utility::getTTC($root->getVar('attribute_default_value'), 0);
494
                    }
495
                }
496
                $datas = [
497
                    'last_categ_product_title'        => $item->getVar('product_title'),
498
                    'last_categ_product_url_rewrited' => $item->getLink(),
499
                    'last_categ_product_href_title'   => Oledrion\Utility::makeHrefTitle($item->getVar('product_title')),
500
                    'product_thumb_url'               => $item->getVar('product_thumb_url'),
501
                    'product_thumb_full_url'          => $item->getThumbUrl(),
502
                    'product_url_rewrited'            => $item->getLink(),
503
                    'product_href_title'              => Oledrion\Utility::makeHrefTitle($item->getVar('product_title')),
504
                    'product_title'                   => $item->getVar('product_title'),
505
                    'product_property1'               => $item->getVar('product_property1'),
506
                    'product_property2'               => $item->getVar('product_property2'),
507
                    'product_property3'               => $item->getVar('product_property3'),
508
                    'product_property4'               => $item->getVar('product_property4'),
509
                    'product_property5'               => $item->getVar('product_property5'),
510
                    'product_property6'               => $item->getVar('product_property6'),
511
                    'product_property7'               => $item->getVar('product_property7'),
512
                    'product_property8'               => $item->getVar('product_property8'),
513
                    'product_property9'               => $item->getVar('product_property9'),
514
                    'product_property10'              => $item->getVar('product_property10'),
515
                    'product_id'                      => $item->getVar('product_id'),
516
                    'product_new'                     => $item->isNewProduct(),
517
                    'product_stock'                   => $item->getVar('product_stock'),
518
                    'product_price'                   => $product_price,
519
                    'product_price_ttc'               => $product_price_ttc,
520
                ];
521
                $xoopsTpl->append('product_current_categ', $datas);
522
            }
523
            unset($tblTmp);
524
        }
525
526
        // Two is better *******************************************************************************
527
        $count = Oledrion\Utility::getModuleOption('better_together');
528
        $xoopsTpl->assign('better_together', $count);
529
        if ($count > 0) {
530
            $productWith = 0;
531
            // We are looking for the product that sold the best with this product
532
            $productWith = $caddyHandler->getBestWith($product->getVar('product_id'));
533
            if ($productWith > 0) {
534
                $tmpProduct = null;
535
                $tmpProduct = $productsHandler->get($productWith);
536
                if (is_object($tmpProduct)) {
537
                    $tmp                               = [];
538
                    $tmp                               = $tmpProduct->toArray();
539
                    $tmp['product_price_ttc']          = Oledrion\Utility::getTTC($tmpProduct->getVar('product_price'), $tblVat[$tmpProduct->getVar('product_vat_id')]->getVar('vat_rate'));
540
                    $tmp['product_discount_price_ttc'] = Oledrion\Utility::getTTC($tmpProduct->getVar('product_discount_price'), $tblVat[$tmpProduct->getVar('product_vat_id')]->getVar('vat_rate'));
541
                    $xoopsTpl->assign('bestwith', $tmp);
542
                }
543
            }
544
        }
545
546
        // Product rating *********************************************************************************
547
        if (1 == Oledrion\Utility::getModuleOption('rateproducts')) {
548
            $canRate = true;
549
            if (0 != $currentUser) {
550
                $canRate = !$votedataHandler->hasUserAlreadyVoted($currentUser, $product->getVar('product_id'));
551
            } else {
552
                $canRate = !$votedataHandler->hasAnonymousAlreadyVoted('', $product->getVar('product_id'));
553
            }
554
            $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
555
            Oledrion\Utility::callJavascriptFile('rateit.js');
556
            Oledrion\Utility::setCSS(OLEDRION_URL . 'assets/css/rateit.css');
557
558
            $xoopsTpl->assign('userCanRate', $canRate);
559
        }
560
561
        // Meta and CSS ************************************************************************************
562
        Oledrion\Utility::setCSS();
563
        Oledrion\Utility::setLocalCSS($xoopsConfig['language']);
564
        if (Oledrion\Utility::getModuleOption('manual_meta')) {
565
            $pageTitle       = '' === xoops_trim($product->getVar('product_metatitle')) ? $title : $product->getVar('product_metatitle');
566
            $metaDescription = '' !== xoops_trim($product->getVar('product_metadescription')) ? $product->getVar('product_metadescription') : $title;
567
            $metaKeywords    = '' !== xoops_trim($product->getVar('product_metakeywords')) ? $product->getVar('product_metakeywords') : Oledrion\Utility::createMetaKeywords($product->getVar('product_title') . ' ' . $product->getVar('product_summary') . ' ' . $product->getVar('product_description'));
568
            Oledrion\Utility::setMetas($pageTitle, $metaDescription, $metaKeywords);
569
        } else {
570
            Oledrion\Utility::setMetas($title, $title, Oledrion\Utility::createMetaKeywords($product->getVar('product_title') . ' ' . $product->getVar('product_summary') . ' ' . $product->getVar('product_description')));
571
        }
572
573
        require_once XOOPS_ROOT_PATH . '/include/comment_view.php';
574
        require_once XOOPS_ROOT_PATH . '/footer.php';
575
576
        break;
577
}
578