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

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
 * Script pour tout ce qui est relatif à Ajax et JSON
22
 *
23
 * @since 2.3.2009.03.17
24
 */
25
require_once __DIR__ . '/header.php';
26
error_reporting(0);
27
@$xoopsLogger->activated = false;
28
29
$op = isset($_POST['op']) ? $_POST['op'] : '';
30
if ($op == '') {
31
    $op = isset($_GET['op']) ? $_GET['op'] : '';
32
}
33
$return  = '';
34
$uid     = Oledrion_utils::getCurrentUserID();
35
$isAdmin = Oledrion_utils::isAdmin();
36
37
switch ($op) {
38
    // ****************************************************************************************************************
39
    case 'updatePrice': // Mise à jour du prix du produit en fonction des attributs sélectionnés
40
        // ****************************************************************************************************************
41
        $product_id = isset($_POST['product_id']) ? (int)$_POST['product_id'] : 0;
42
        if (isset($_POST['formcontent']) && $product_id > 0) {
43
            $data     = $data = $attributesIds = $attributes = $templateProduct = array();
44
            $handlers = OledrionHandler::getInstance();
45
            $product  = null;
46
            $product  = $handlers->h_oledrion_products->get($product_id);
0 ignored issues
show
The property h_oledrion_products 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...
47
            if (!is_object($product)) {
48
                return _OLEDRION_NA;
49
            }
50
            if (!$product->isProductVisible()) {
51
                return _OLEDRION_NA;
52
            }
53
            $vat_id = $product->getVar('product_vat_id');
54
55 View Code Duplication
            if ((int)$product->getVar('product_discount_price', '') != 0) {
56
                $productPrice = (float)$product->getVar('product_discount_price', 'e');
57
            } else {
58
                $productPrice = (float)$product->getVar('product_price', 'e');
59
            }
60
61
            parse_str(urldecode($_POST['formcontent']), $data);
62
            /*
63
                        require_once __DIR__ . '/FirePHPCore/FirePHP.class.php';
64
                        $firephp = FirePHP::getInstance(true);
65
                        $firephp->log($data, 'Iterators');
66
            */
67
            // On récupère les ID des attributs valorisés
68
            foreach ($data as $key => $value) {
69
                $attributesIds[] = Oledrion_utils::getId($key);
70
            }
71
            if (count($attributesIds) == 0) {
72
                return _OLEDRION_NA;
73
            }
74
            // Puis les attributs
75
            $attributes = $handlers->h_oledrion_attributes->getItemsFromIds($attributesIds);
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...
76
            if (count($attributes) == 0) {
77
                return _OLEDRION_NA;
78
            }
79
80
            // Et on recalcule le prix
81
            foreach ($attributes as $attribute) {
82
                $attributeNameInForm = xoops_trim($attribute->getVar('attribute_name') . '_' . $attribute->getVar('attribute_id'));
83
                if (isset($data[$attributeNameInForm])) {
84
                    $attributeValues = $data[$attributeNameInForm];
85
                    if (is_array($attributeValues)) {
86
                        foreach ($attributeValues as $attributeValue) {
87
                            $optionName  = Oledrion_utils::getName($attributeValue);
88
                            $optionPrice = $attribute->getOptionPriceFromValue($optionName);
89
                            $productPrice += $optionPrice;
90
                        }
91
                    } else {
92
                        $optionPrice = $attribute->getOptionPriceFromValue(Oledrion_utils::getName($attributeValues));
93
                        $productPrice += $optionPrice;
94
                    }
95
                }
96
            }
97
            // Mise en template
98
            include_once XOOPS_ROOT_PATH . '/class/template.php';
99
            $template        = new XoopsTpl();
100
            $vat             = null;
101
            $vat             = $handlers->h_oledrion_vat->get($vat_id);
0 ignored issues
show
The property h_oledrion_vat 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...
102
            $productPriceTTC = Oledrion_utils::getAmountWithVat($productPrice, $vat_id);
103
104
            $oledrion_Currency = Oledrion_Currency::getInstance();
105
106
            $templateProduct                                          = $product->toArray();
107
            $templateProduct['product_final_price_ht_formated_long']  = $oledrion_Currency->amountForDisplay($productPrice, 'l');
108
            $templateProduct['product_final_price_ttc_formated_long'] = $oledrion_Currency->amountForDisplay($productPriceTTC, 'l');
109
            if (is_object($vat)) {
110
                $templateProduct['product_vat_rate'] = $vat->toArray();
111
            }
112
            $templateProduct['product_vat_amount_formated_long'] = $oledrion_Currency->amountForDisplay($productPriceTTC - $productPrice, 'l');
113
            $template->assign('product', $templateProduct);
114
            $return = $template->fetch('db:oledrion_product_price.tpl');
115
        }
116
        break;
117
    // ajax search
118
    case 'search': // ajax search
119
        $key = $_GET['part'];
120
        if (isset($key) && $key != '') {
121
            // Set captul
122
            $i = 1;
123
            // Query 1
124
            $query  = 'SELECT `product_id` AS `id` , `product_cid` AS `cid`, `product_title` AS `title`, `product_thumb_url` AS `image`, `product_price` AS `price` FROM `' . $xoopsDB->prefix('oledrion_products')
125
                      . "` WHERE (`product_online` = 1) AND (`product_title` LIKE '%" . $key . "%' OR `product_title` LIKE '%" . ucfirst($key) . "%') LIMIT 0, 10";
126
            $result = $xoopsDB->query($query);
127
            while ($row = $xoopsDB->fetchArray($result)) {
128
                $items[$i]['title'] = $row['title'];
129
                $items[$i]['type']  = 'product';
130
                $items[$i]['link']  = XOOPS_URL . '/modules/oledrion/product.php?product_id=' . $row['id'];
131
                $items[$i]['image'] = OLEDRION_PICTURES_URL . '/' . $row['image'];
132
                //$items[$i]['price'] = Oledrion_utils::getTTC($row['price']);
133
                $category               = $h_oledrion_cat->get($row['cid']);
134
                $items[$i]['cat_cid']   = $category->getVar('cat_cid');
135
                $items[$i]['cat_title'] = $category->getVar('cat_title');
136
                ++$i;
137
            }
138
            // Query 2
139
            $query  = 'SELECT `cat_cid` AS `id` , `cat_title` AS `title`, `cat_imgurl` AS `image`  FROM `' . $xoopsDB->prefix('oledrion_cat') . "` WHERE (`cat_title` LIKE '%" . $key . "%') OR (`cat_title` LIKE '%" . ucfirst($key) . "%') LIMIT 0, 5";
140
            $result = $xoopsDB->query($query);
141
            while ($row = $xoopsDB->fetchArray($result)) {
142
                $items[$i]['title'] = $row['title'];
143
                $items[$i]['type']  = 'cat';
144
                $items[$i]['link']  = XOOPS_URL . '/modules/oledrion/category.php?cat_cid=' . $row['id'];
145
                $items[$i]['image'] = OLEDRION_PICTURES_URL . '/' . $row['image'];
146
                $items[$i]['price'] = '';
147
                ++$i;
148
            }
149
            // Set array
150
            $results = array();
151
            // search colors
152
            foreach ($items as $item) {
153
                // if it starts with 'part' add to results
154
                //if ( strpos($item['title'], $key) === 0 || strpos($item['title'], ucfirst($key)) === 0 ) {
155
                if ($item['type'] === 'product') {
156
                    $results[] = '<div class="searchbox">
157
                         <div class="searchboxright"><a href="' . $item['link'] . '"><img src="' . $item['image'] . '" alt="" /></a></div>
158
                         <div class="searchboxleft">
159
                             <div class="searchboxitem"><a href="' . $item['link'] . '">' . $item['title'] . '</a></div>
160
                             <div class="searchboxcat"><a href="' . XOOPS_URL . '/modules/oledrion/category.php?cat_cid=' . $item['cat_cid'] . '">' . $item['cat_title'] . '</a></div>
161
                         </div>
162
                         <div class="clear"></div>
163
                     </div>';
164
                } else {
165
                    $results[] = '<div class="searchbox">
166
                         <div class="searchboxright"><a href="' . $item['link'] . '"><img src="' . $item['image'] . '" alt="" /></a></div>
167
                         <div class="searchboxleft">
168
                             <div class="searchboxitem"><a href="' . $item['link'] . '">' . $item['title'] . '</a></div>
169
                         </div>
170
                         <div class="clear"></div>
171
                     </div>';
172
                }
173
                //}
174
            }
175
            $return = json_encode($results);
176
        }
177
        break;
178
    // Product output as json
179
    case 'product':
180
        $start = (int)$_GET['start'];
181
        $limit = (int)$_GET['limit'];
182
        if (isset($start) && $start != '') {
183
            $ret      = array();
184
            $criteria = new CriteriaCompo();
185
            $criteria->add(new Criteria('product_id', $start, '>='));
186
            $criteria->add(new Criteria('product_online', 1));
187
            $criteria->setSort('product_id');
188
            $criteria->setOrder('ASC');
189
            $criteria->setLimit($limit);
190
            $obj = $h_oledrion_products->getObjects($criteria, false);
191
            if ($obj) {
192
                foreach ($obj as $root) {
193
                    $tab                         = array();
194
                    $tab                         = $root->toArray();
195
                    $json['product_id']          = $tab['product_id'];
196
                    $json['product_cid']         = $tab['product_cid'];
197
                    $json['product_title']       = preg_replace('/,/', ';', $tab['product_title']);
198
                    $json['product_description'] = preg_replace('/,/', ';', $tab['product_description']);
199
                    $json['product_image_url']   = $tab['product_image_url'];
200
                    $json['product_thumb_url']   = $tab['product_thumb_url'];
201
                    $json['product_property1']   = $tab['product_property1'];
202
                    $json['product_property2']   = $tab['product_property2'];
203
                    $json['product_property3']   = $tab['product_property3'];
204
                    $json['product_property4']   = $tab['product_property4'];
205
                    $json['product_submitted']   = $tab['product_submitted'];
206
                    unset($tab);
207
                    $ret[] = $json;
208
                }
209
            }
210
            $return = json_encode($ret);
211
        }
212
        break;
213
    // Product output as json
214
    case 'category':
215
        $start = (int)$_GET['start'];
216
        if (isset($start) && $start != '') {
217
            $ret      = array();
218
            $criteria = new CriteriaCompo();
219
            $criteria->add(new Criteria('cat_cid', $start, '>='));
220
            $criteria->setSort('cat_cid');
221
            $criteria->setOrder('DESC');
222
            $obj = $h_oledrion_cat->getObjects($criteria, false);
223
            if ($obj) {
224
                foreach ($obj as $root) {
225
                    $tab                = array();
226
                    $tab                = $root->toArray();
227
                    $json['cat_cid']    = $tab['cat_cid'];
228
                    $json['cat_pid']    = $tab['cat_pid'];
229
                    $json['cat_title']  = preg_replace('/,/', ';', $tab['cat_title']);
230
                    $json['cat_imgurl'] = $tab['cat_imgurl'];
231
                    unset($tab);
232
                    $ret[] = $json;
233
                }
234
            }
235
            $return = json_encode($ret);
236
        }
237
        break;
238
239
    // Product output as json
240
    case 'price':
241
        $product_id = (int)$_GET['product_id'];
242
        $product    = $h_oledrion_products->get($product_id);
243
        if (is_object($product)) {
244
            if ($product->getVar('product_online') && $product->getVar('product_stock') > 0) {
245
                $product_price = $product->getVar('product_price');
246 View Code Duplication
                if ($h_oledrion_attributes->getProductAttributesCount($product->getVar('product_id')) > 0) {
247
                    $criteria = new CriteriaCompo();
248
                    $criteria->add(new Criteria('attribute_product_id', $product->getVar('product_id')));
249
                    $attribute = $h_oledrion_attributes->getObjects($criteria, false);
250
                    foreach ($attribute as $root) {
251
                        $product_price = $root->getVar('attribute_default_value');
252
                    }
253
                }
254
                $ret = array(
255
                    'product_id'    => $product->getVar('product_id'),
256
                    'product_price' => $product_price
257
                );
258
            } else {
259
                $ret = array(
260
                    'product_id'    => $product->getVar('product_id'),
261
                    'product_price' => 0
262
                );
263
            }
264
        } else {
265
            $ret = array(
266
                'product_id'    => 0,
267
                'product_price' => 0
268
            );
269
        }
270
        $return = json_encode($ret);
271
        break;
272
273
    // Ajax rate
274
    case 'rate':
275
        if (isset($_POST['product_id'])) {
276
            $product_id = (int)$_POST['product_id'];
277
            $product    = null;
278
            $product    = $h_oledrion_products->get($product_id);
279
            if (is_object($product)
280
                && $product->getVar('product_online')
281
                && !Oledrion_utils::getModuleOption('show_unpublished')
282
                && $product->getVar('product_submitted') < time()
283
                && Oledrion_utils::getModuleOption('nostock_display')
284
                && $product->getVar('product_stock')
285
            ) {
286
                $GLOBALS['current_category'] = -1;
287
                $ratinguser                  = Oledrion_utils::getCurrentUserID();
288
                $canRate                     = true;
289
                if ($ratinguser != 0) {
290
                    if ($h_oledrion_votedata->hasUserAlreadyVoted($ratinguser, $product->getVar('product_id'))) {
291
                        $canRate = false;
292
                    }
293
                } else {
294
                    if ($h_oledrion_votedata->hasAnonymousAlreadyVoted('', $product->getVar('product_id'))) {
295
                        $canRate = false;
296
                    }
297
                }
298
                if ($canRate) {
299
                    /* if ($_POST['rating'] == '--') {
300
                        Oledrion_utils::redirect(_OLEDRION_NORATING, OLEDRION_URL . 'product.php?product_id=' . $product->getVar('product_id'), 4);
301
                    } */
302
                    $rating = (int)$_POST['rating'];
303
                    /* if ($rating < 1 || $rating > 10) {
304
                        exit(_ERRORS);
305
                    } */
306
                    if ($rating == 1 || $rating == -1) {
307
                        $result = $h_oledrion_votedata->createRating($product->getVar('product_id'), $ratinguser, $rating);
308
309
                        $totalVotes = 0;
310
                        $sumRating  = 0;
311
                        $ret        = 0;
312
                        $ret        = $h_oledrion_votedata->getCountRecordSumRating($product->getVar('product_id'), $totalVotes, $sumRating);
313
314
                        //$finalrating = $sumRating / $totalVotes;
315
                        //$finalrating = number_format($finalrating, 4);
316
317
                        $h_oledrion_products->updateRating($product_id, $sumRating, $totalVotes);
318
                        //$ratemessage = _OLEDRION_VOTEAPPRE . '<br>' . sprintf(_OLEDRION_THANKYOU, $xoopsConfig['sitename']);
319
                        //Oledrion_utils::redirect($ratemessage, OLEDRION_URL . 'product.php?product_id=' . $product->getVar('product_id'), 2);
320
                    } else {
321
                        $return = false;
322
                    }
323
                } else {
324
                    $return = false;
325
                }
326
            }
327
        }
328
        break;
329
330
    case 'order':
331
        $ret            = array();
332
        $ret['status']  = 0;
333
        $ret['message'] = 'error';
334
        if (isset($_POST['product_id']) && is_numeric($_POST['product_id'])) {
335
            // Set from post
336
            $product_id    = isset($_POST['product_id']) ? $_POST['product_id'] : '';
337
            $cmd_lastname  = isset($_POST['cmd_lastname']) ? $_POST['cmd_lastname'] : '';
338
            $cmd_firstname = isset($_POST['cmd_firstname']) ? $_POST['cmd_firstname'] : '';
339
            $cmd_adress    = isset($_POST['cmd_adress']) ? $_POST['cmd_adress'] : '';
340
            $cmd_zip       = isset($_POST['cmd_zip']) ? $_POST['cmd_zip'] : '';
341
            $cmd_town      = isset($_POST['cmd_town']) ? $_POST['cmd_town'] : '';
342
            $cmd_country   = isset($_POST['cmd_country']) ? $_POST['cmd_country'] : '';
343
            $cmd_telephone = isset($_POST['cmd_telephone']) ? $_POST['cmd_telephone'] : '';
344
            $cmd_mobile    = isset($_POST['cmd_mobile']) ? $_POST['cmd_mobile'] : '';
345
            $cmd_email     = isset($_POST['cmd_email']) ? $_POST['cmd_email'] : '';
346
            //$cmd_total = isset($_POST['cmd_total']) ? $_POST['cmd_total'] : '';
347
            //$cmd_shipping = isset($_POST['cmd_shipping']) ? $_POST['cmd_shipping'] : '';
348
            $cmd_packing_price = isset($_POST['cmd_packing_price']) ? $_POST['cmd_packing_price'] : '';
349
            $cmd_bill          = isset($_POST['cmd_bill']) ? $_POST['cmd_bill'] : '';
350
            $cmd_text          = isset($_POST['cmd_text']) ? $_POST['cmd_text'] : '';
351
            $cmd_comment       = isset($_POST['cmd_comment']) ? $_POST['cmd_comment'] : '';
352
            $cmd_vat_number    = isset($_POST['cmd_vat_number']) ? $_POST['cmd_vat_number'] : '';
353
            $cmd_packing       = isset($_POST['cmd_packing']) ? $_POST['cmd_packing'] : '';
354
            $cmd_packing_id    = isset($_POST['cmd_packing_id']) ? $_POST['cmd_packing_id'] : '';
355
            $cmd_location      = isset($_POST['cmd_location']) ? $_POST['cmd_location'] : '';
356
            $cmd_location_id   = isset($_POST['cmd_location_id']) ? $_POST['cmd_location_id'] : '';
357
            $cmd_delivery      = isset($_POST['cmd_delivery']) ? $_POST['cmd_delivery'] : '';
358
            $cmd_delivery_id   = isset($_POST['cmd_delivery_id']) ? $_POST['cmd_delivery_id'] : '';
359
            $cmd_payment       = isset($_POST['cmd_payment']) ? $_POST['cmd_payment'] : '';
360
            $cmd_payment_id    = isset($_POST['cmd_payment_id']) ? $_POST['cmd_payment_id'] : '';
361
            $cmd_track         = isset($_POST['cmd_track']) ? $_POST['cmd_track'] : '';
362
            $cmd_gift          = isset($_POST['cmd_gift']) ? $_POST['cmd_gift'] : '';
363
            $attributes        = isset($_POST['attributes']) ? $_POST['attributes'] : '';
364
            // Get product
365
            $product       = $h_oledrion_products->get($product_id);
366
            $product_price = $product->getVar('product_price');
367 View Code Duplication
            if ($h_oledrion_attributes->getProductAttributesCount($product->getVar('product_id')) > 0) {
368
                $criteria = new CriteriaCompo();
369
                $criteria->add(new Criteria('attribute_product_id', $product->getVar('product_id')));
370
                $attribute = $h_oledrion_attributes->getObjects($criteria, false);
371
                foreach ($attribute as $root) {
372
                    $product_price = $root->getVar('attribute_default_value');
373
                }
374
            }
375
            if ($product->getVar('product_online') && $product->getVar('product_stock') > 0) {
376
                // Set parameter
377
                $password       = md5(xoops_makepass());
378
                $passwordCancel = md5(xoops_makepass());
379
                $uid            = Oledrion_utils::getCurrentUserID();
380
                $cmd_total      = $product_price;
381
                $cmd_shipping   = 0;
382
                // Save command
383
                $commande = $h_oledrion_commands->create(true);
384
                $commande->setVar('cmd_uid', $uid);
385
                $commande->setVar('cmd_date', date('Y-m-d'));
386
                $commande->setVar('cmd_create', time());
387
                $commande->setVar('cmd_state', OLEDRION_STATE_NOINFORMATION);
388
                $commande->setVar('cmd_ip', Oledrion_utils::IP());
389
                $commande->setVar('cmd_lastname', $cmd_lastname);
390
                $commande->setVar('cmd_firstname', $cmd_firstname);
391
                $commande->setVar('cmd_adress', $cmd_adress);
392
                $commande->setVar('cmd_zip', $cmd_zip);
393
                $commande->setVar('cmd_town', $cmd_town);
394
                $commande->setVar('cmd_country', $cmd_country);
395
                $commande->setVar('cmd_telephone', $cmd_telephone);
396
                $commande->setVar('cmd_mobile', $cmd_mobile);
397
                $commande->setVar('cmd_email', $cmd_email);
398
                $commande->setVar('cmd_articles_count', 1);
399
                $commande->setVar('cmd_total', Oledrion_utils::formatFloatForDB($cmd_total));
400
                $commande->setVar('cmd_shipping', Oledrion_utils::formatFloatForDB($cmd_shipping));
401
                $commande->setVar('cmd_packing_price', $cmd_packing_price);
402
                $commande->setVar('cmd_bill', $cmd_bill);
403
                $commande->setVar('cmd_password', $password);
404
                $commande->setVar('cmd_text', $cmd_text);
405
                $commande->setVar('cmd_cancel', $passwordCancel);
406
                $commande->setVar('cmd_comment', $cmd_comment);
407
                $commande->setVar('cmd_vat_number', $cmd_vat_number);
408
                $commande->setVar('cmd_packing', $cmd_packing);
409
                $commande->setVar('cmd_packing_id', $cmd_packing_id);
410
                $commande->setVar('cmd_location', $cmd_location);
411
                $commande->setVar('cmd_location_id', $cmd_location_id);
412
                $commande->setVar('cmd_delivery', $cmd_delivery);
413
                $commande->setVar('cmd_delivery_id', $cmd_delivery_id);
414
                $commande->setVar('cmd_payment', $cmd_payment);
415
                $commande->setVar('cmd_payment_id', $cmd_payment_id);
416
                $commande->setVar('cmd_status', 2);
417
                $commande->setVar('cmd_track', $cmd_track);
418
                $commande->setVar('cmd_gift', $cmd_gift);
419
                $res1 = $h_oledrion_commands->insert($commande, true);
420
                // Save caddy
421
                $caddy = $h_oledrion_caddy->create(true);
422
                $caddy->setVar('caddy_product_id', $product_id);
423
                $caddy->setVar('caddy_qte', $product->getVar('product_qty'));
424
                $caddy->setVar('caddy_price', Oledrion_utils::formatFloatForDB($cmd_total));
425
                $caddy->setVar('caddy_cmd_id', $commande->getVar('cmd_id'));
426
                $caddy->setVar('caddy_shipping', Oledrion_utils::formatFloatForDB($cmd_shipping));
427
                $caddy->setVar('caddy_pass', md5(xoops_makepass()));
428
                $res2 = $h_oledrion_caddy->insert($caddy, true);
429
                // Attributs
430
                /* if ($res2 && is_array($attributes) && count($attributes) > 0) {
431
                    foreach ($attributes as $attributeId => $attributeInformation) {
432
                        $caddyAttribute = $handlers->h_oledrion_caddy_attributes->create(true);
433
                        $caddyAttribute->setVar('ca_cmd_id', $commande->getVar('cmd_id'));
434
                        $caddyAttribute->setVar('ca_caddy_id', $caddy->getVar('caddy_id'));
435
                        $caddyAttribute->setVar('ca_attribute_id', $attributeId);
436
                        $selectedOptions = $attributeInformation['attribute_options'];
437
                        $msgCommande .= '- ' . $attributeInformation['attribute_title'] . "\n";
438
                        foreach ($selectedOptions as $selectedOption) {
439
                            $caddyAttribute ->addOption($selectedOption['option_name'], $selectedOption['option_value'], $selectedOption['option_price']);
440
                            $msgCommande .= '    ' . $selectedOption['option_name'] . ' : ' . $selectedOption['option_ttc_formated'] . "\n";
441
                        }
442
                        $handlers->h_oledrion_caddy_attributes->insert($caddyAttribute, true);
443
                    }
444
                } */
445
                if (!$res1) {
446
                    $ret['status']  = 0;
447
                    $ret['message'] = _OLEDRION_ERROR10;
448
                } else {
449
                    $ret['status']  = 1;
450
                    $ret['message'] = 'ok';
451
                    // Send mail
452
                    /* $msgCommande = '';
453
                    $msgCommande .= str_pad($product_id, 5, ' ') . ' ';
454
                    $msgCommande .= str_pad('', 10, ' ', STR_PAD_LEFT) . ' ';
455
                    $msgCommande .= str_pad($product->getVar('product_title'), 19, ' ', STR_PAD_LEFT) . ' ';
456
                    $msgCommande .= str_pad($product->getVar('product_qty'), 8, ' ', STR_PAD_LEFT) . ' ';
457
                    $msgCommande .= str_pad($oledrion_Currency->amountForDisplay($product_price), 15, ' ', STR_PAD_LEFT) . ' ';+
458
                    $msgCommande .= "\n";
459
                    $msgCommande .= "\n\n" . _OLEDRION_TOTAL . " " . $oledrion_Currency->mountForDisplay($cmd_total) . "\n";
460
                    $msg = array();
461
                    $msg['COMMANDE'] = $msgCommande;
462
                    $msg['NUM_COMMANDE'] = $commande->getVar('cmd_id');
463
                    $msg['NOM'] = $commande->getVar('cmd_lastname');
464
                    $msg['PRENOM'] = $commande->getVar('cmd_firstname');
465
                    $msg['ADRESSE'] = $commande->getVar('cmd_adress', 'n');
466
                    $msg['CP'] = $commande->getVar('cmd_zip');
467
                    $msg['VILLE'] = $commande->getVar('cmd_town');
468
                    $msg['PAYS'] = $countries[$commande->getVar('cmd_country')];
469
                    $msg['TELEPHONE'] = $commande->getVar('cmd_telephone');
470
                    $msg['EMAIL'] = $commande->getVar('cmd_email');
471
                    $msg['URL_BILL'] = OLEDRION_URL . 'invoice.php?id=' . $commande->getVar('cmd_id') . '&pass=' . $commande->getVar('cmd_password');
472
                    $msg['IP'] = Oledrion_utils::IP();
473
                    if ($commande->getVar('cmd_bill') == 1) {
474
                        $msg['FACTURE'] = _YES;
475
                    } else {
476
                        $msg['FACTURE'] = _NO;
477
                    }
478
                    // Send mail to client
479
                    Oledrion_utils::sendEmailFromTpl('command_client.tpl', $commande -> getVar('cmd_email'), sprintf(_OLEDRION_THANKYOU_CMD, $xoopsConfig['sitename']), $msg);
480
                    // Send mail to admin
481
                    Oledrion_utils::sendEmailFromTpl('command_shop.tpl', Oledrion_utils::getEmailsFromGroup(Oledrion_utils::getModuleOption('grp_sold')), _OLEDRION_NEW_COMMAND, $msg);
482
                    */
483
                    // Send SMS
484
                    if (Oledrion_utils::getModuleOption('sms_checkout')) {
485
                        $information['to']   = ltrim($commande->getVar('cmd_mobile'), 0);
486
                        $information['text'] = Oledrion_utils::getModuleOption('sms_checkout_text');
487
                        $sms                 = Oledrion_sms::sendSms($information);
488
                    }
489
                }
490
            } else {
491
                $ret['status']  = 0;
492
                $ret['message'] = _OLEDRION_ERROR10;
493
            }
494
        }
495
        $return = json_encode($ret);
496
        break;
497
}
498
echo $return;
499