Completed
Branch master (9d3fbd)
by Michael
02:59
created

search.php (1 issue)

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 http://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
 * Recherche dans les produits
22
 */
23
require __DIR__ . '/header.php';
24
require_once OLEDRION_PATH . 'class/tree.php';
25
$GLOBALS['current_category']             = -1; // Pour le bloc des catégories
26
$GLOBALS['xoopsOption']['template_main'] = 'oledrion_search.tpl';
27
require_once XOOPS_ROOT_PATH . '/header.php';
28
29
$limit      = Oledrion_utils::getModuleOption('newproducts'); // Nombre maximum d'éléments à afficher
30
$categories = $manufacturers = $vendors = array();
31
$baseurl    = OLEDRION_URL . basename(__FILE__); // URL de ce script (sans son nom)
32
33
$xoopsTpl->assign('mod_pref', $mod_pref); // Préférences du module
34
$xoopsTpl->assign('columnsCount', Oledrion_utils::getModuleOption('catagory_colums'));
35
36
$categories    = $h_oledrion_cat->getAllCategories(new Oledrion_parameters());
37
$vendors       = $h_oledrion_vendors->getAllVendors(new Oledrion_parameters());
38
$manufacturers = $h_oledrion_manufacturer->getItems(0, 0, 'manu_name', 'ASC', false);
39
40
if ((isset($_POST['op']) && $_POST['op'] === 'go') || isset($_GET['start'])) { // Recherche des résultats
41
    $xoopsTpl->assign('search_results', true);
42
    $xoopsTpl->assign('global_advert', Oledrion_utils::getModuleOption('advertisement'));
43
    $xoopsTpl->assign('breadcrumb', Oledrion_utils::breadcrumb(array(OLEDRION_URL . basename(__FILE__) => _OLEDRION_SEARCHRESULTS)));
44
    Oledrion_utils::setMetas(Oledrion_utils::getModuleName() . ' - ' . _OLEDRION_SEARCHRESULTS, Oledrion_utils::getModuleName() . ' - ' . _OLEDRION_SEARCHRESULTS);
45
46
    if (!isset($_GET['start'])) {
47
        $sql = 'SELECT b.product_id, b.product_title, b.product_submitted, b.product_submitter, b.product_thumb_url, b.product_price, b.product_property1, b.product_property2, b.product_property3, b.product_property4, b.product_property5, b.product_property6, b.product_property7, b.product_property8, b.product_property9, b.product_property10, b.product_stock, b.product_summary FROM '
48
               . $xoopsDB->prefix('oledrion_products') . ' b, ' . $xoopsDB->prefix('oledrion_productsmanu') . ' a WHERE (b.product_id = a.pm_product_id AND b.product_online = 1 ';
49
        if (Oledrion_utils::getModuleOption('show_unpublished') == 0) { // Ne pas afficher les produits qui ne sont pas publiés
50
            $sql .= ' AND b.product_submitted <= ' . time();
51
        }
52
        if (Oledrion_utils::getModuleOption('nostock_display') == 0) { // Se limiter aux seuls produits encore en stock
53
            $sql .= ' AND b.product_stock > 0';
54
        }
55
        $sql .= ') ';
56
57
        // Recherche sur une catégorie
58
        if (isset($_POST['product_category'])) {
59
            $cat_cid = (int)$_POST['product_category'];
60
            if ($cat_cid > 0) {
61
                $sql .= 'AND (b.product_cid = ' . $cat_cid . ')';
62
            }
63
        }
64
65
        // Recherche sur les fabricants
66
        if (isset($_POST['product_manufacturers'])) {
67
            $submittedManufacturers = null;
68
            $submittedManufacturers = $_POST['product_manufacturers'];
69
            if (is_array($submittedManufacturers) && (int)$submittedManufacturers[0] == 0) {
70
                $submittedManufacturers = array_shift($submittedManufacturers);
71
            }
72
            if (is_array($submittedManufacturers) && count($submittedManufacturers) > 0) {
73
                array_walk($submittedManufacturers, 'intval');
74
                $sql .= ' AND (a.pm_manu_id IN ( ' . implode(',', $submittedManufacturers) . '))';
75
            } else {
76
                $submittedManufacturer = (int)$submittedManufacturers;
77
                if ($submittedManufacturer > 0) {
78
                    $sql .= ' AND (a.pm_manu_id = ' . $submittedManufacturer . ')';
79
                }
80
            }
81
        }
82
83
        // Recherche sur les vendeurs
84
        if (isset($_POST['product_vendors'])) {
85
            $vendor = (int)$_POST['product_vendors'];
86
            if ($vendor > 0) {
87
                $sql .= ' AND (product_vendor_id = ' . $vendor . ')';
88
            }
89
        }
90
91
        // set from
92 View Code Duplication
        if (isset($_POST['product_from'])) {
93
            $product_from = (int)$_POST['product_from'];
94
            if ($product_from > 0) {
95
                $sql .= ' AND (product_price > ' . $product_from . ')';
96
            }
97
        }
98
99
        // set to
100 View Code Duplication
        if (isset($_POST['product_to'])) {
101
            $product_to = (int)$_POST['product_to'];
102
            if ($product_to > 0) {
103
                $sql .= ' AND (product_price < ' . $product_to . ')';
104
            }
105
        }
106
107
        if ($_POST['product_stock'] == 2) {
108
            $sql .= ' AND (product_stock > 0)';
109
        } elseif ($_POST['product_stock'] == 0) {
110
            $sql .= ' AND (product_stock = 0)';
111
        }
112
113
        if (isset($_POST['product_property1'])) {
114
            if ($_POST['product_property1']) {
115
                $sql .= ' AND (b.product_property1 = "' . $_POST['product_property1'] . '")';
116
            }
117
        }
118
119
        if (isset($_POST['product_property2'])) {
120
            if ($_POST['product_property2']) {
121
                $sql .= ' AND (b.product_property2 = "' . $_POST['product_property2'] . '")';
122
            }
123
        }
124
125
        if (isset($_POST['product_property3'])) {
126
            if ($_POST['product_property3']) {
127
                $sql .= ' AND (b.product_property3 = "' . $_POST['product_property3'] . '")';
128
            }
129
        }
130
131
        if (isset($_POST['product_property4'])) {
132
            if ($_POST['product_property4']) {
133
                $sql .= ' AND (b.product_property4 = "' . $_POST['product_property4'] . '")';
134
            }
135
        }
136
137
        if (isset($_POST['product_property5'])) {
138
            if ($_POST['product_property5']) {
139
                $sql .= ' AND (b.product_property5 = "' . $_POST['product_property5'] . '")';
140
            }
141
        }
142
143
        if (isset($_POST['product_property6'])) {
144
            if ($_POST['product_property6']) {
145
                $sql .= ' AND (b.product_property6 = "' . $_POST['product_property6'] . '")';
146
            }
147
        }
148
149
        if (isset($_POST['product_property7'])) {
150
            if ($_POST['product_property7']) {
151
                $sql .= ' AND (b.product_property7 = "' . $_POST['product_property7'] . '")';
152
            }
153
        }
154
155
        if (isset($_POST['product_property8'])) {
156
            if ($_POST['product_property8']) {
157
                $sql .= ' AND (b.product_property8 = "' . $_POST['product_property8'] . '")';
158
            }
159
        }
160
161
        if (isset($_POST['product_property9'])) {
162
            if ($_POST['product_property9']) {
163
                $sql .= ' AND (b.product_property9 = "' . $_POST['product_property9'] . '")';
164
            }
165
        }
166
167
        if (isset($_POST['product_property10'])) {
168
            if ($_POST['product_property10']) {
169
                $sql .= ' AND (b.product_property10 = "' . $_POST['product_property10'] . '")';
170
            }
171
        }
172
173
        // Recherche sur du texte
174
        if (isset($_POST['product_text']) && xoops_trim($_POST['product_text']) != '') {
175
            $temp_queries = $queries = array();
176
            $temp_queries = preg_split('/[\s,]+/', $_POST['product_text']);
177
178
            foreach ($temp_queries as $q) {
179
                $q         = trim($q);
180
                $queries[] = $myts->addSlashes($q);
181
            }
182
            if (count($queries) > 0) {
183
                $tmpObject = new oledrion_products();
184
                $datas     =& $tmpObject->getVars();
185
                $fields    = array();
186
                $cnt       = 0;
187 View Code Duplication
                foreach ($datas as $key => $value) {
188
                    if ($value['data_type'] == XOBJ_DTYPE_TXTBOX || $value['data_type'] == XOBJ_DTYPE_TXTAREA) {
189
                        if ($cnt == 0) {
190
                            $fields[] = 'b.' . $key;
191
                        } else {
192
                            $fields[] = ' OR b.' . $key;
193
                        }
194
                        ++$cnt;
195
                    }
196
                }
197
                $count = count($queries);
198
                $cnt   = 0;
199
                $sql .= ' AND ';
200
                $searchType = (int)$_POST['search_type'];
201
                $andor      = ' OR ';
202
                foreach ($queries as $oneQuery) {
203
                    $sql .= '(';
204
                    switch ($searchType) {
205
                        case 0: // Commence par
206
                            $cond = " LIKE '" . $oneQuery . "%' ";
207
                            break;
208
                        case 1: // Finit par
209
                            $cond = " LIKE '%" . $oneQuery . "' ";
210
                            break;
211
                        case 2: // Correspond à
212
                            $cond = " = '" . $oneQuery . "' ";
213
                            break;
214
                        case 3: // Contient
215
                            $cond = " LIKE '%" . $oneQuery . "%' ";
216
                            break;
217
                    }
218
                    $sql .= implode($cond, $fields) . $cond . ')';
219
                    ++$cnt;
220
                    if ($cnt != $count) {
221
                        $sql .= ' ' . $andor . ' ';
222
                    }
223
                }
224
            }
225
        }
226
        $_SESSION['criteria_oledrion'] = serialize($sql);
227
    } else { // $_GET['start'] est en place, on a cliqué sur un chevron pour aller voir les autres pages, il faut travailler à partir des informations de la session
228
        if (isset($_SESSION['criteria_oledrion'])) {
229
            $sql = unserialize($_SESSION['criteria_oledrion']);
230
        }
231
    }
232
    $start    = isset($_GET['start']) ? (int)$_GET['start'] : 0;
233
    $sqlCount = str_replace('b.product_id, b.product_title, b.product_submitted, b.product_submitter', 'Count(*) as cpt', $sql);
234
    $result   = $xoopsDB->query($sqlCount);
235
    $rowCount = $xoopsDB->fetchArray($result);
236
    if ($rowCount['cpt'] > $limit) {
237
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
238
        $pagenav = new XoopsPageNav($rowCount['cpt'], $limit, $start, 'start');
239
        $xoopsTpl->assign('pagenav', $pagenav->renderNav());
240
    }
241
242
    $sql .= ' GROUP BY b.product_id ORDER BY product_submitted DESC';
243
    $result      = $xoopsDB->query($sql, $limit, $start);
244
    $ret         = array();
245
    $tempProduct = $h_oledrion_products->create(true);
246
    $count       = 1;
247
    while ($myrow = $xoopsDB->fetchArray($result)) {
248
        $ret                           = array();
249
        $ret['product_url_rewrited']   = $tempProduct->getLink($myrow['product_id'], $myrow['product_title']);
250
        $ret['product_title']          = $myts->htmlSpecialChars($myrow['product_title']);
251
        $ret['product_href_title']     = Oledrion_utils::makeHrefTitle($myts->htmlSpecialChars($myrow['product_title']));
252
        $ret['product_time']           = $myrow['product_submitted'];
253
        $ret['product_uid']            = $myrow['product_submitter'];
254
        $ret['product_id']             = $myrow['product_id'];
255
        $ret['product_thumb_url']      = $myrow['product_thumb_url'];
256
        $ret['product_thumb_full_url'] = OLEDRION_PICTURES_URL . '/' . $myrow['product_thumb_url'];
257
        $ret['product_property1']      = $myrow['product_property1'];
258
        $ret['product_property2']      = $myrow['product_property2'];
259
        $ret['product_property3']      = $myrow['product_property3'];
260
        $ret['product_property4']      = $myrow['product_property4'];
261
        $ret['product_property5']      = $myrow['product_property5'];
262
        $ret['product_property6']      = $myrow['product_property6'];
263
        $ret['product_property7']      = $myrow['product_property7'];
264
        $ret['product_property8']      = $myrow['product_property8'];
265
        $ret['product_property9']      = $myrow['product_property9'];
266
        $ret['product_property10']     = $myrow['product_property10'];
267
        $ret['product_price']          = $myrow['product_price'];
268
        if ($myrow['product_price'] == 0) {
269
            $criteria = new CriteriaCompo();
270
            $criteria->add(new Criteria('attribute_product_id', $myrow['product_id']));
271
            $attribute = OledrionHandler::getInstance()->h_oledrion_attributes->getObjects($criteria, false);
0 ignored issues
show
The property h_oledrion_attributes does not exist on object<OledrionHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
272
            foreach ($attribute as $root) {
273
                $ret['product_price'] = $root->getVar('attribute_default_value');
274
            }
275
        }
276
        $ret['product_stock']     = $myrow['product_stock'];
277
        $ret['product_price_ttc'] = Oledrion_utils::getTTC($ret['product_price'], '');
278
        $ret['product_count']     = $count;
279
        $ret['product_summary']   = $myrow['product_summary'];
280
        $xoopsTpl->append('products', $ret);
281
        ++$count;
282
    }
283
    unset($tempProduct);
284
} else {
285
    $xoopsTpl->assign('search_results', false);
286
    $xoopsTpl->assign('global_advert', Oledrion_utils::getModuleOption('advertisement'));
287
    $xoopsTpl->assign('breadcrumb', Oledrion_utils::breadcrumb(array(OLEDRION_URL . basename(__FILE__) => _OLEDRION_SEARCHFOR)));
288
    Oledrion_utils::setMetas(Oledrion_utils::getModuleName() . ' - ' . _OLEDRION_SEARCHFOR, Oledrion_utils::getModuleName() . ' - ' . _OLEDRION_SEARCHFOR);
289
}
290
291
require_once OLEDRION_PATH . 'include/product_search_form.php';
292
$sform =& Oledrion_utils::formMarkRequiredFields($sform);
293
$xoopsTpl->assign('search_form', $sform->render());
294
295
Oledrion_utils::setCSS();
296
Oledrion_utils::setLocalCSS($xoopsConfig['language']);
297
298
require_once XOOPS_ROOT_PATH . '/footer.php';
299