Completed
Push — master ( 9d3fbd...af269e )
by Michael
09:48
created

admin/productsselector.php (2 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
 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
 * Sélecteur de produits
22
 */
23
require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
24
require_once dirname(__DIR__) . '/include/common.php';
25
require_once XOOPS_ROOT_PATH . '/class/template.php';
26
require_once OLEDRION_PATH . 'class/tree.php';
27
28
if (!isset($xoopsUser) || !is_object($xoopsUser)) {
29
    exit;
30
}
31
if (!OledrionUtility::isAdmin()) {
32
    exit;
33
}
34
$xoopsTpl = new XoopsTpl();
35
$ts       = MyTextSanitizer::getInstance();
36
$limit    = OledrionUtility::getModuleOption('items_count'); // Nombre maximum d'éléments à afficher dans l'admin
37
38
$oledrionHandlers = OledrionHandler::getInstance();
39
$searchFields     = array(
40
    'product_title'       => _OLEDRION_TITLE,
41
    'product_summary'     => _OLEDRION_SUMMARY,
42
    'product_description' => _OLEDRION_DESCRIPTION,
43
    'product_id'          => _AM_OLEDRION_ID,
44
    'product_sku'         => _OLEDRION_NUMBER,
45
    'product_extraid'     => _OLEDRION_EXTRA_ID
46
);
47
$searchCriterias  = array(
48
    XOOPS_MATCH_START   => _STARTSWITH,
49
    XOOPS_MATCH_END     => _ENDSWITH,
50
    XOOPS_MATCH_EQUAL   => _MATCHES,
51
    XOOPS_MATCH_CONTAIN => _CONTAINS
52
);
53
54
$vendors    = array();
55
$vendors    = $oledrionHandlers->h_oledrion_vendors->getList();
56
$vendors[0] = '---';
57
sort($vendors);
58
$categories           = $oledrionHandlers->h_oledrion_cat->getAllCategories(new Oledrion_parameters());
59
$mytree               = new Oledrion_XoopsObjectTree($categories, 'cat_cid', 'cat_pid');
60
$searchVendorSelected = $selectedCategory = $selectedSearchField = 0;
61
62
$start         = isset($_REQUEST['start']) ? (int)$_REQUEST['start'] : 0;
63
$mutipleSelect = isset($_REQUEST['mutipleSelect']) ? (int)$_REQUEST['mutipleSelect'] : 0;
64
$callerName    = isset($_REQUEST['callerName']) ? $_REQUEST['callerName'] : '';
65
66
if (isset($_REQUEST['op']) && $_REQUEST['op'] === 'search') {
67
    $searchField    = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : '';
68
    $searchCriteria = isset($_REQUEST['searchCriteria']) ? (int)$_REQUEST['searchCriteria'] : '';
69
    $searchText     = isset($_REQUEST['searchText']) ? trim($_REQUEST['searchText']) : '';
70
    $searchVendor   = isset($_REQUEST['searchVendor']) ? (int)$_REQUEST['searchVendor'] : 0;
71
    $product_cid    = isset($_REQUEST['product_cid']) ? (int)$_REQUEST['product_cid'] : 0;
72
73
    $selectedSearchField = $searchField;
74
    $xoopsTpl->assign('searchCriteriaSelected', $searchCriteria);
75
    $searchVendorSelected  = $searchVendor;
76
    $selectedCategory      = $product_cid;
77
    $additionnalParameters = array();
78
79
    $additionnalParameters['op']             = 'search';
80
    $additionnalParameters['mutipleSelect']  = $mutipleSelect;
81
    $additionnalParameters['callerName']     = $callerName;
82
    $additionnalParameters['searchField']    = $searchField;
83
    $additionnalParameters['searchField']    = $searchField;
84
    $additionnalParameters['searchCriteria'] = $searchCriteria;
85
    $additionnalParameters['searchText']     = $searchText;
86
    $additionnalParameters['searchVendor']   = $searchVendor;
87
    $additionnalParameters['product_cid']    = $product_cid;
88
89
    $criteria = new CriteriaCompo();
90
    if ($searchText != '') {
91
        $xoopsTpl->assign('searchTextValue', $ts->htmlSpecialChars($searchText));
92
        if (array_key_exists($searchField, $searchFields)) {
93
            switch ($searchCriteria) {
94
                case XOOPS_MATCH_START:
95
                    $criteria->add(new Criteria($searchField, $searchText . '%', 'LIKE'));
96
                    break;
97
                case XOOPS_MATCH_END:
98
                    $criteria->add(new Criteria($searchField, '%' . $searchText, 'LIKE'));
99
                    break;
100
                case XOOPS_MATCH_EQUAL:
101
                    $criteria->add(new Criteria($searchField, $searchText, '='));
102
                    break;
103
                case XOOPS_MATCH_CONTAIN:
104
                    $criteria->add(new Criteria($searchField, '%' . $searchText . '%', 'LIKE'));
105
                    break;
106
            }
107
        }
108
    }
109
110
    if ($searchVendor > 0) {
111
        $criteria->add(new Criteria('product_vendor_id', $searchVendor, '='));
112
    }
113
    if ($product_cid > 0) {
114
        $criteria->add(new Criteria('product_cid', $product_cid, '='));
115
    }
116
    $itemsCount = $oledrionHandlers->h_oledrion_products->getcount($criteria);
117
    $xoopsTpl->assign('productsCount', $itemsCount);
118
    if ($itemsCount > $limit) {
119
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
120
        $pagenav = new XoopsPageNav($itemsCount, $limit, $start, 'start', http_build_query($additionnalParameters));
121
        $xoopsTpl->assign('pagenav', $pagenav->renderNav());
122
    }
123
    $criteria->setStart($start);
124
    $criteria->setLimit($limit);
125
    $products          = array();
126
    $products          = $oledrionHandlers->h_oledrion_products->getObjects($criteria);
127
    $javascriptSearch  = array("'", '"');
128
    $javascriptReplace = array(' ', ' ');
129
130
    if (count($products) > 0) {
131
        foreach ($products as $product) {
132
            $productData                             = $product->toArray();
133
            $productData['product_title_javascript'] = str_replace($javascriptSearch, $javascriptReplace, $product->getVar('product_title', 'n'));
134
            //$productData['product_title_javascript'] = $product->getVar('product_title', 'n');
135
            $xoopsTpl->append('products', $productData);
136
        }
137
    }
138
}
139
140
OledrionUtility::loadLanguageFile('modinfo.php');
141
OledrionUtility::loadLanguageFile('main.php');
142
143
if (OledrionUtility::checkVerXoops($module, '2.5.9')) {
0 ignored issues
show
The method checkVerXoops() does not seem to exist on object<OledrionUtility>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
    $categoriesSelect = $mytree->makeSelectElement('product_cid', 'cat_title', '-', $selectedCategory, true, 0, '', '');
145
    $xoopsTpl->assign('searchCategory', $categoriesSelect->render());
146
} else {
147
    $categoriesSelect = $mytree->makeSelBox('product_cid', 'cat_title', '-', $selectedCategory, '---', 0, "class='selectLists'");
0 ignored issues
show
Deprecated Code introduced by
The method Oledrion_XoopsObjectTree::makeSelBox() has been deprecated with message: since 2.5.9, please use makeSelectElement()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
148
    $xoopsTpl->assign('searchCategory', $categoriesSelect);
149
}
150
$xoopsTpl->assign('callerName', $callerName);
151
$xoopsTpl->assign('sart', $start);
152
$xoopsTpl->assign('theme_set', xoops_getcss($xoopsConfig['theme_set']));
153
$xoopsTpl->assign('xoopsConfig', $xoopsConfig);
154
$xoopsTpl->assign('mutipleSelect', $mutipleSelect);
155
$xoopsTpl->assign('searchVendorSelected', $searchVendorSelected);
156
$xoopsTpl->assign('baseurl', OLEDRION_URL . 'admin/' . basename(__FILE__)); // URL de ce script
157
$xoopsTpl->assign('searchVendor', $vendors);
158
$xoopsTpl->assign('searchCriteria', $searchCriterias);
159
$xoopsTpl->assign('searchField', $searchFields);
160
$xoopsTpl->assign('searchCategory', $categoriesSelect);
161
$xoopsTpl->assign('searchFieldSelected', $selectedSearchField);
162
163
echo $xoopsTpl->fetch('db:oledrion_productsselector.tpl');
164