XoopsModules25x /
oledrion
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 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 | * Entering customer data + displaying information entered for validation with redirection to the payment gateway |
||
| 22 | */ |
||
| 23 | |||
| 24 | use XoopsModules\Oledrion; |
||
| 25 | use XoopsModules\Oledrion\Constants; |
||
| 26 | |||
| 27 | require_once __DIR__ . '/header.php'; |
||
| 28 | |||
| 29 | $GLOBALS['current_category'] = -1; |
||
| 30 | $GLOBALS['xoopsOption']['template_main'] = 'oledrion_command.tpl'; |
||
| 31 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 32 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 33 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
| 34 | require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
| 35 | // require_once OLEDRION_PATH . 'class/Registryfile.php'; |
||
| 36 | |||
| 37 | // Get user id |
||
| 38 | $uid = Oledrion\Utility::getCurrentUserID(); |
||
| 39 | // Get checkout level |
||
| 40 | $checkout_level = Oledrion\Utility::getModuleOption('checkout_level'); |
||
| 41 | // Ordering reserved for registered users |
||
| 42 | if (0 == $uid && 1 == Oledrion\Utility::getModuleOption('restrict_orders', false)) { |
||
| 43 | $registry = new Oledrion\Registryfile(); |
||
| 44 | $text = $registry->getfile(OLEDRION_TEXTFILE5); |
||
| 45 | Oledrion\Utility::redirect(xoops_trim($text), 'index.php', 5); |
||
| 46 | } |
||
| 47 | // Get option |
||
| 48 | $op = \Xmf\Request::getCmd('op', 'default'); |
||
| 49 | // Get action |
||
| 50 | $action = 'default'; |
||
| 51 | if (\Xmf\Request::hasVar('action', 'POST')) { |
||
| 52 | $action = $_POST['action']; |
||
| 53 | } elseif (\Xmf\Request::hasVar('action', 'GET')) { |
||
| 54 | $action = $_GET['action']; |
||
| 55 | } |
||
| 56 | // Get commend id |
||
| 57 | if (\Xmf\Request::hasVar('commend_id', 'POST')) { |
||
| 58 | $commend_id = \Xmf\Request::getInt('commend_id', 0, 'POST'); |
||
| 59 | } else { |
||
| 60 | $commend_id = \Xmf\Request::getInt('commend_id', 0, 'GET'); |
||
| 61 | } |
||
| 62 | |||
| 63 | $xoopsTpl->assign('op', $op); |
||
| 64 | $xoopsTpl->assign('mod_pref', $mod_pref); |
||
| 65 | $cartForTemplate = []; |
||
| 66 | $emptyCart = false; |
||
| 67 | $shippingAmount = $commandAmount = $vatAmount = $commandAmountTTC = $discountsCount = $commandAmountVAT = 0; |
||
| 68 | $goOn = ''; |
||
| 69 | $discountsDescription = []; |
||
| 70 | // B.R. New |
||
| 71 | $checkoutAttributes = []; |
||
| 72 | // Assume optional checkout steps skipped (listCart updates) |
||
| 73 | $checkoutAttributes['skip_packing'] = 1; |
||
| 74 | $checkoutAttributes['skip_location'] = 1; |
||
| 75 | $checkoutAttributes['skip_delivery'] = 1; |
||
| 76 | // B.R. End |
||
| 77 | |||
| 78 | function listCart() |
||
| 79 | { |
||
| 80 | // B.R. global $cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription; |
||
| 81 | global $cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $checkoutAttributes; |
||
| 82 | $reductions = new Oledrion\Reductions(); |
||
| 83 | // B.R. $reductions->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $discountsCount); |
||
| 84 | $reductions->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $discountsCount, $checkoutAttributes); |
||
| 85 | } |
||
| 86 | |||
| 87 | $oledrionCurrency = Oledrion\Currency::getInstance(); |
||
| 88 | $countries = Oledrion\Utility::getCountriesList(); |
||
| 89 | |||
| 90 | // B.R. New |
||
| 91 | listCart(); |
||
| 92 | // End New |
||
| 93 | |||
| 94 | switch ($op) { |
||
| 95 | case 'save': |
||
| 96 | |||
| 97 | if (empty($_POST)) { |
||
| 98 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 99 | } |
||
| 100 | if ($caddyHandler->isCartEmpty()) { |
||
| 101 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 102 | } |
||
| 103 | // B.R. listCart(); |
||
| 104 | |||
| 105 | switch ($action) { |
||
| 106 | case 'make': |
||
| 107 | |||
| 108 | $commandAmountTTC += $commandAmountVAT; |
||
| 109 | $password = md5(xoops_makepass()); |
||
| 110 | $passwordCancel = md5(xoops_makepass()); |
||
| 111 | $commande = $commandsHandler->create(true); |
||
| 112 | $commande->setVars($_POST); |
||
| 113 | $commande->setVar('cmd_uid', $uid); |
||
| 114 | $commande->setVar('cmd_date', date('Y-m-d')); |
||
| 115 | $commande->setVar('cmd_create', time()); |
||
| 116 | $commande->setVar('cmd_state', Constants::OLEDRION_STATE_NOINFORMATION); |
||
| 117 | $commande->setVar('cmd_ip', Oledrion\Utility::IP()); |
||
| 118 | $commande->setVar('cmd_articles_count', count($cartForTemplate)); |
||
| 119 | $commande->setVar('cmd_total', Oledrion\Utility::formatFloatForDB($commandAmountTTC)); |
||
| 120 | $commande->setVar('cmd_shipping', Oledrion\Utility::formatFloatForDB($shippingAmount)); |
||
| 121 | $commande->setVar('cmd_password', $password); |
||
| 122 | $commande->setVar('cmd_cancel', $passwordCancel); |
||
| 123 | $commande->setVar('cmd_text', implode("\n", $discountsDescription)); |
||
| 124 | $commande->setVar('cmd_status', 2); |
||
| 125 | $res = $commandsHandler->insert($commande, true); |
||
| 126 | if (!$res) { |
||
| 127 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 128 | } |
||
| 129 | // Check checkout level |
||
| 130 | if (1 == $checkout_level) { |
||
| 131 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 132 | } elseif (2 == $checkout_level) { |
||
| 133 | Oledrion\Utility::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 134 | } else { |
||
| 135 | Oledrion\Utility::redirect(_OLEDRION_SELECT_PACKING, OLEDRION_URL . 'checkout.php?op=packing&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 136 | } |
||
| 137 | |||
| 138 | break; |
||
| 139 | case 'find': |
||
| 140 | |||
| 141 | if (0 == $commend_id) { |
||
| 142 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 143 | } |
||
| 144 | $commandAmountTTC += $commandAmountVAT; |
||
| 145 | $commande = $commandsHandler->get($commend_id); |
||
| 146 | $commande->setVars($_POST); |
||
| 147 | $commande->setVar('cmd_state', Constants::OLEDRION_STATE_NOINFORMATION); |
||
| 148 | $commande->setVar('cmd_ip', Oledrion\Utility::IP()); |
||
| 149 | $commande->setVar('cmd_articles_count', count($cartForTemplate)); |
||
| 150 | $commande->setVar('cmd_total', Oledrion\Utility::formatFloatForDB($commandAmountTTC)); |
||
| 151 | $commande->setVar('cmd_shipping', Oledrion\Utility::formatFloatForDB($shippingAmount)); |
||
| 152 | $commande->setVar('cmd_text', implode("\n", $discountsDescription)); |
||
| 153 | $commande->setVar('cmd_status', 2); |
||
| 154 | $res = $commandsHandler->insert($commande, true); |
||
| 155 | if (!$res) { |
||
| 156 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 157 | } |
||
| 158 | Oledrion\Utility::redirect(_OLEDRION_SELECT_PACKING, OLEDRION_URL . 'checkout.php?op=packing&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 159 | |||
| 160 | break; |
||
| 161 | case 'packing': |
||
| 162 | |||
| 163 | $packing_id = \Xmf\Request::getInt('packing_id', 0, 'POST'); |
||
| 164 | |||
| 165 | if (0 == $packing_id) { |
||
| 166 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 167 | } |
||
| 168 | if (0 == $commend_id) { |
||
| 169 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 170 | } |
||
| 171 | // Check checkout level |
||
| 172 | if (1 == $checkout_level) { |
||
| 173 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 174 | } elseif (2 == $checkout_level) { |
||
| 175 | Oledrion\Utility::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commend_id, 1); |
||
| 176 | } |
||
| 177 | |||
| 178 | $packing = $packingHandler->get($packing_id); |
||
| 179 | if (!$packing->getVar('packing_id')) { |
||
| 180 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 181 | } |
||
| 182 | $commande = $commandsHandler->get($commend_id); |
||
| 183 | $commande->setVar('cmd_packing', $packing->getVar('packing_title')); |
||
| 184 | $commande->setVar('cmd_packing_id', $packing->getVar('packing_id')); |
||
| 185 | $commande->setVar('cmd_packing_price', $packing->getVar('packing_price')); |
||
| 186 | $res = $commandsHandler->insert($commande, true); |
||
| 187 | if (!$res) { |
||
| 188 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 189 | } |
||
| 190 | Oledrion\Utility::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 191 | |||
| 192 | break; |
||
| 193 | case 'location': |
||
| 194 | |||
| 195 | $location_id = \Xmf\Request::getInt('location_id', 0, 'POST'); |
||
| 196 | |||
| 197 | if (0 == $location_id) { |
||
| 198 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 199 | } |
||
| 200 | if (0 == $commend_id) { |
||
| 201 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 202 | } |
||
| 203 | // Check checkout level |
||
| 204 | if (1 == $checkout_level) { |
||
| 205 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 206 | } |
||
| 207 | $location = $locationHandler->get($location_id); |
||
| 208 | $commande = $commandsHandler->get($commend_id); |
||
| 209 | $commande->setVar('cmd_location', $location->getVar('location_title')); |
||
| 210 | $commande->setVar('cmd_location_id', $location->getVar('location_id')); |
||
| 211 | $res = $commandsHandler->insert($commande, true); |
||
| 212 | if (!$res) { |
||
| 213 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 214 | } |
||
| 215 | |||
| 216 | if ($locationHandler->haveChild($location->getVar('location_id'))) { |
||
| 217 | Oledrion\Utility::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&action=select&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 218 | } else { |
||
| 219 | Oledrion\Utility::redirect(_OLEDRION_SELECT_DELIVERY, OLEDRION_URL . 'checkout.php?op=delivery&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 220 | } |
||
| 221 | |||
| 222 | break; |
||
| 223 | case 'delivery': |
||
| 224 | |||
| 225 | $delivery_id = \Xmf\Request::getInt('delivery_id', 0, 'POST'); |
||
| 226 | |||
| 227 | if (0 == $delivery_id) { |
||
| 228 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 229 | } |
||
| 230 | if (0 == $commend_id) { |
||
| 231 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 232 | } |
||
| 233 | // Check checkout level |
||
| 234 | if (1 == $checkout_level) { |
||
| 235 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 236 | } |
||
| 237 | $commande = $commandsHandler->get($commend_id); |
||
| 238 | $delivery = $deliveryHandler->getThisLocationThisDelivery($delivery_id, $commande->getVar('cmd_location_id')); |
||
| 239 | |||
| 240 | $shipping_price = ''; |
||
| 241 | $shipping_price_op = Oledrion\Utility::getModuleOption('checkout_shipping', false); |
||
| 242 | switch ($shipping_price_op) { |
||
| 243 | case 1: |
||
| 244 | |||
| 245 | $shipping_price = $shippingAmount + $delivery['delivery_price']; |
||
| 246 | |||
| 247 | break; |
||
| 248 | case 2: |
||
| 249 | |||
| 250 | $shipping_price = $shippingAmount; |
||
| 251 | |||
| 252 | break; |
||
| 253 | case 3: |
||
| 254 | |||
| 255 | $shipping_price = $delivery['delivery_price']; |
||
| 256 | |||
| 257 | break; |
||
| 258 | case 4: |
||
| 259 | |||
| 260 | $shipping_price = 0; |
||
| 261 | |||
| 262 | break; |
||
| 263 | } |
||
| 264 | $commande->setVar('cmd_delivery', $delivery['delivery_title']); |
||
| 265 | $commande->setVar('cmd_delivery_id', $delivery['delivery_id']); |
||
| 266 | $commande->setVar('cmd_shipping', $shipping_price); |
||
| 267 | $res = $commandsHandler->insert($commande, true); |
||
| 268 | if (!$res) { |
||
| 269 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 270 | } |
||
| 271 | Oledrion\Utility::redirect(_OLEDRION_SELECT_PAYMENT, OLEDRION_URL . 'checkout.php?op=payment&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 272 | |||
| 273 | break; |
||
| 274 | case 'payment': |
||
| 275 | |||
| 276 | $payment_id = \Xmf\Request::getInt('payment_id', 0, 'POST'); |
||
| 277 | |||
| 278 | if (0 == $payment_id) { |
||
| 279 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 280 | } |
||
| 281 | if (0 == $commend_id) { |
||
| 282 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 283 | } |
||
| 284 | // Check checkout level |
||
| 285 | if (1 == $checkout_level) { |
||
| 286 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 287 | } |
||
| 288 | $payment = $paymentHandler->get($payment_id); |
||
| 289 | $commande = $commandsHandler->get($commend_id); |
||
| 290 | $commande->setVar('cmd_payment', $payment->getVar('payment_title')); |
||
| 291 | $commande->setVar('cmd_payment_id', $payment->getVar('payment_id')); |
||
| 292 | $res = $commandsHandler->insert($commande, true); |
||
| 293 | if (!$res) { |
||
| 294 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 295 | } |
||
| 296 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 297 | |||
| 298 | break; |
||
| 299 | } |
||
| 300 | |||
| 301 | break; |
||
| 302 | // **************************************************************************************************************** |
||
| 303 | case 'default': |
||
| 304 | // Presentation of the form |
||
| 305 | |||
| 306 | // **************************************************************************************************************** |
||
| 307 | if ($caddyHandler->isCartEmpty()) { |
||
| 308 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 309 | } |
||
| 310 | // B.R. listCart(); |
||
| 311 | $notFound = true; |
||
| 312 | $commande = null; |
||
| 313 | |||
| 314 | if ($uid > 0) { |
||
| 315 | // If it is a registered user, one looks in the old commands to pre-fill the fields |
||
| 316 | $commande = $commandsHandler->getLastUserOrder($uid); |
||
| 317 | if (is_object($commande)) { |
||
| 318 | $notFound = false; |
||
| 319 | } |
||
| 320 | } |
||
| 321 | |||
| 322 | if ($notFound) { |
||
| 323 | $commande = $commandsHandler->create(true); |
||
| 324 | $commande->setVar('cmd_country', OLEDRION_DEFAULT_COUNTRY); |
||
| 325 | } |
||
| 326 | |||
| 327 | // Text to display |
||
| 328 | $registry = new Oledrion\Registryfile(); |
||
| 329 | $text = $registry->getfile(OLEDRION_TEXTFILE6); |
||
| 330 | $xoopsTpl->assign('text', xoops_trim($text)); |
||
| 331 | |||
| 332 | $sform = new \XoopsThemeForm(_OLEDRION_PLEASE_ENTER, 'informationfrm', OLEDRION_URL . 'checkout.php', 'post', true); |
||
| 333 | $sform->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 334 | if ($commande->getVar('cmd_id') && $commande->getVar('cmd_id') > 0) { |
||
| 335 | $sform->addElement(new \XoopsFormHidden('action', 'find')); |
||
| 336 | $sform->addElement(new \XoopsFormHidden('commend_id', $commande->getVar('cmd_id'))); |
||
| 337 | } else { |
||
| 338 | $sform->addElement(new \XoopsFormHidden('action', 'make')); |
||
| 339 | } |
||
| 340 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_TOTAL, $oledrionCurrency->amountForDisplay($commandAmountTTC))); |
||
| 341 | // By voltan |
||
| 342 | if ($shippingAmount > 0 && in_array(Oledrion\Utility::getModuleOption('checkout_shipping'), [1, 2])) { |
||
| 343 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_SHIPPING_PRICE, $oledrionCurrency->amountForDisplay($shippingAmount))); |
||
| 344 | } |
||
| 345 | $sform->addElement(new \XoopsFormText(_OLEDRION_LASTNAME, 'cmd_lastname', 50, 255, $commande->getVar('cmd_lastname', 'e')), true); |
||
| 346 | // B.R. New |
||
| 347 | if (0 == $checkoutAttributes['skip_delivery']) { |
||
| 348 | // Assume that select delivery implies also need first name, physical address and phone numbers |
||
| 349 | $mandatory = true; |
||
| 350 | } else { |
||
| 351 | $mandatory = false; |
||
| 352 | } |
||
| 353 | // B.R. $sform->addElement(new \XoopsFormText(_OLEDRION_FIRSTNAME, 'cmd_firstname', 50, 255, $commande->getVar('cmd_firstname', 'e')), false); |
||
| 354 | $sform->addElement(new \XoopsFormText(_OLEDRION_FIRSTNAME, 'cmd_firstname', 50, 255, $commande->getVar('cmd_firstname', 'e')), $mandatory); |
||
| 355 | if ($uid > 0) { |
||
| 356 | $sform->addElement(new \XoopsFormText(_OLEDRION_EMAIL, 'cmd_email', 50, 255, $xoopsUser->getVar('email', 'e')), true); |
||
| 357 | } else { |
||
| 358 | $sform->addElement(new \XoopsFormText(_OLEDRION_EMAIL, 'cmd_email', 50, 255, ''), true); |
||
| 359 | } |
||
| 360 | $sform->addElement(new \XoopsFormText(_OLEDRION_CITY, 'cmd_town', 50, 255, $commande->getVar('cmd_town', 'e')), true); |
||
| 361 | // By voltan |
||
| 362 | if (Oledrion\Utility::getModuleOption('checkout_country')) { |
||
| 363 | $countriesList = new \XoopsFormSelect(_OLEDRION_COUNTRY, 'cmd_country', $commande->getVar('cmd_country', ' e')); |
||
| 364 | $countriesList->addOptionArray($countries); |
||
| 365 | $sform->addElement($countriesList, true); |
||
| 366 | } else { |
||
| 367 | $sform->addElement(new \XoopsFormHidden('cmd_country', OLEDRION_DEFAULT_COUNTRY)); |
||
| 368 | } |
||
| 369 | $sform->addElement(new \XoopsFormText(_OLEDRION_CP, 'cmd_zip', 15, 30, $commande->getVar('cmd_zip', 'e')), true); |
||
| 370 | // B.R. $sform->addElement(new \XoopsFormText(_OLEDRION_MOBILE, 'cmd_mobile', 15, 50, $commande->getVar('cmd_mobile', 'e')), true); |
||
| 371 | // B.R. $sform->addElement(new \XoopsFormText(_OLEDRION_PHONE, 'cmd_telephone', 15, 50, $commande->getVar('cmd_telephone', 'e')), true); |
||
| 372 | $sform->addElement(new \XoopsFormText(_OLEDRION_MOBILE, 'cmd_mobile', 15, 50, $commande->getVar('cmd_mobile', 'e')), $mandatory); |
||
| 373 | $sform->addElement(new \XoopsFormText(_OLEDRION_PHONE, 'cmd_telephone', 15, 50, $commande->getVar('cmd_telephone', 'e')), $mandatory); |
||
| 374 | if (Oledrion\Utility::getModuleOption('ask_vatnumber')) { |
||
| 375 | $sform->addElement(new \XoopsFormText(_OLEDRION_VAT_NUMBER, 'cmd_vat_number', 50, 255, $commande->getVar('cmd_vat_number', 'e')), false); |
||
| 376 | } |
||
| 377 | if (Oledrion\Utility::getModuleOption('ask_bill')) { |
||
| 378 | // B.R. $sform->addElement(new \XoopsFormRadioYN(_OLEDRION_INVOICE, 'cmd_bill', 0), true); |
||
| 379 | $sform->addElement(new \XoopsFormRadioYN(_OLEDRION_INVOICE, 'cmd_bill', 0), false); |
||
| 380 | } |
||
| 381 | // B.R. $sform->addElement(new XoopsFormTextArea(_OLEDRION_STREET, 'cmd_adress', $commande->getVar('cmd_adress', 'e'), 3, 50), true); |
||
| 382 | $sform->addElement(new \XoopsFormTextArea(_OLEDRION_STREET, 'cmd_adress', $commande->getVar('cmd_adress', 'e'), 3, 50), $mandatory); |
||
| 383 | $sform->addElement(new \XoopsFormText(_OLEDRION_GIFT, 'cmd_gift', 15, 30, $commande->getVar('cmd_gift', 'e')), false); |
||
| 384 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 385 | $submit_btn = new \XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit'); |
||
| 386 | $buttonTray->addElement($submit_btn); |
||
| 387 | $sform->addElement($buttonTray); |
||
| 388 | $sform = Oledrion\Utility::formMarkRequiredFields($sform); |
||
| 389 | $xoopsTpl->assign('form', $sform->render()); |
||
| 390 | |||
| 391 | break; |
||
| 392 | case 'packing': |
||
| 393 | |||
| 394 | if ($caddyHandler->isCartEmpty()) { |
||
| 395 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 396 | } |
||
| 397 | if (0 == $commend_id) { |
||
| 398 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 399 | } |
||
| 400 | // Check checkout level |
||
| 401 | if (1 == $checkout_level) { |
||
| 402 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 403 | // B.R. Start |
||
| 404 | } elseif (1 == $checkoutAttributes['skip_packing']) { |
||
| 405 | Oledrion\Utility::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commend_id, 1); |
||
| 406 | // B.R. End |
||
| 407 | } elseif (2 == $checkout_level) { |
||
| 408 | Oledrion\Utility::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commend_id, 1); |
||
| 409 | } |
||
| 410 | // B.R. listCart(); |
||
| 411 | $packings = $packingHandler->getPacking(); |
||
| 412 | |||
| 413 | $sform = new \XoopsThemeForm(_OLEDRION_PACKING_FORM, 'informationfrm', OLEDRION_URL . 'checkout.php', 'post', true); |
||
| 414 | $sform->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 415 | $sform->addElement(new \XoopsFormHidden('action', 'packing')); |
||
| 416 | $sform->addElement(new \XoopsFormHidden('commend_id', $commend_id)); |
||
| 417 | $packingSelect = new \XoopsFormRadio(_OLEDRION_SELECT_PACKING, 'packing_id', ''); |
||
| 418 | foreach ($packings as $packing) { |
||
| 419 | $packingSelect->addOption($packing['packing_id'], Oledrion\Utility::packingHtmlSelect($packing)); |
||
| 420 | } |
||
| 421 | $sform->addElement($packingSelect, true); |
||
| 422 | $sform->addElement(new \XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit')); |
||
| 423 | $sform = Oledrion\Utility::formMarkRequiredFields($sform); |
||
| 424 | $xoopsTpl->assign('form', $sform->render()); |
||
| 425 | |||
| 426 | // Text to display |
||
| 427 | $registry = new Oledrion\Registryfile(); |
||
| 428 | $text = $registry->getfile(OLEDRION_TEXTFILE6); |
||
| 429 | $xoopsTpl->assign('text', xoops_trim($text)); |
||
| 430 | |||
| 431 | break; |
||
| 432 | case 'location': |
||
| 433 | |||
| 434 | if ($caddyHandler->isCartEmpty()) { |
||
| 435 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 436 | } |
||
| 437 | if (0 == $commend_id) { |
||
| 438 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 439 | } |
||
| 440 | // Check checkout level |
||
| 441 | if (1 == $checkout_level) { |
||
| 442 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 443 | // B.R. Start |
||
| 444 | } elseif (1 == $checkoutAttributes['skip_location']) { |
||
| 445 | //$commande = $h_oledrion_commands->get($commend_id); |
||
| 446 | //Oledrion\Utility::redirect(_OLEDRION_SELECT_DELIVERY, OLEDRION_URL . 'checkout.php?op=delivery&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 447 | Oledrion\Utility::redirect(_OLEDRION_SELECT_DELIVERY, OLEDRION_URL . 'checkout.php?op=delivery&commend_id=' . $commend_id, 1); |
||
| 448 | // B.R. End |
||
| 449 | } |
||
| 450 | // B.R. listCart(); |
||
| 451 | switch ($action) { |
||
| 452 | case 'default': |
||
| 453 | |||
| 454 | $sform = new \XoopsThemeForm(_OLEDRION_LOCATION_FORM, 'informationfrm', OLEDRION_URL . 'checkout.php', 'post', true); |
||
| 455 | $sform->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 456 | $sform->addElement(new \XoopsFormHidden('action', 'location')); |
||
| 457 | $sform->addElement(new \XoopsFormHidden('commend_id', $commend_id)); |
||
| 458 | $pids = $locationHandler->getAllPid(new Oledrion\Parameters()); |
||
| 459 | $location_pid = new \XoopsFormRadio(_OLEDRION_SELECT_LOCATION, 'location_id'); |
||
| 460 | foreach ($pids as $pid) { |
||
| 461 | $location_pid->addOption($pid->getVar('location_id'), $pid->getVar('location_title')); |
||
| 462 | } |
||
| 463 | $sform->addElement($location_pid, true); |
||
| 464 | $sform->addElement(new \XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit')); |
||
| 465 | $sform = Oledrion\Utility::formMarkRequiredFields($sform); |
||
| 466 | $xoopsTpl->assign('form', $sform->render()); |
||
| 467 | |||
| 468 | break; |
||
| 469 | case 'select': |
||
| 470 | |||
| 471 | $commande = $commandsHandler->get($commend_id); |
||
| 472 | $sform = new \XoopsThemeForm(_OLEDRION_LOCATION_FORM, 'informationfrm', OLEDRION_URL . 'checkout.php', 'post', true); |
||
| 473 | $sform->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 474 | $sform->addElement(new \XoopsFormHidden('action', 'location')); |
||
| 475 | $sform->addElement(new \XoopsFormHidden('commend_id', $commend_id)); |
||
| 476 | $locations = $locationHandler->getLocation($commande->getVar('cmd_location_id')); |
||
| 477 | $location_select = new \XoopsFormSelect(_OLEDRION_SELECT_LOCATION, 'location_id', ''); |
||
| 478 | foreach ($locations as $location) { |
||
| 479 | $location_select->addOption($location->getVar('location_id'), $location->getVar('location_title')); |
||
| 480 | } |
||
| 481 | $sform->addElement($location_select, true); |
||
| 482 | $sform->addElement(new \XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit')); |
||
| 483 | $sform = Oledrion\Utility::formMarkRequiredFields($sform); |
||
| 484 | $xoopsTpl->assign('form', $sform->render()); |
||
| 485 | |||
| 486 | break; |
||
| 487 | } |
||
| 488 | |||
| 489 | // Text to display |
||
| 490 | $registry = new Oledrion\Registryfile(); |
||
| 491 | $text = $registry->getfile(OLEDRION_TEXTFILE6); |
||
| 492 | $xoopsTpl->assign('text', xoops_trim($text)); |
||
| 493 | |||
| 494 | break; |
||
| 495 | case 'delivery': |
||
| 496 | |||
| 497 | if ($caddyHandler->isCartEmpty()) { |
||
| 498 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 499 | } |
||
| 500 | if (0 == $commend_id) { |
||
| 501 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 502 | } |
||
| 503 | // Check checkout level |
||
| 504 | if (1 == $checkout_level) { |
||
| 505 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 506 | // B.R. Start |
||
| 507 | } elseif (1 == $checkoutAttributes['skip_delivery']) { |
||
| 508 | //$commande = $h_oledrion_commands->get($commend_id); |
||
| 509 | //Oledrion\Utility::redirect(_OLEDRION_SELECT_PAYMENT, OLEDRION_URL . 'checkout.php?op=payment&commend_id=' . $commande->getVar('cmd_id'), 1); |
||
| 510 | Oledrion\Utility::redirect(_OLEDRION_SELECT_PAYMENT, OLEDRION_URL . 'checkout.php?op=payment&commend_id=' . $commend_id, 1); |
||
| 511 | // B.R. End |
||
| 512 | } |
||
| 513 | // B.R. listCart(); |
||
| 514 | $commande = $commandsHandler->get($commend_id); |
||
| 515 | $location_id = $commande->getVar('cmd_location_id'); |
||
| 516 | $deliveres = $deliveryHandler->getThisLocationDelivery($location_id); |
||
| 517 | |||
| 518 | $sform = new \XoopsThemeForm(_OLEDRION_DELIVERY_FORM, 'informationfrm', OLEDRION_URL . 'checkout.php', 'post', true); |
||
| 519 | $sform->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 520 | $sform->addElement(new \XoopsFormHidden('action', 'delivery')); |
||
| 521 | $sform->addElement(new \XoopsFormHidden('commend_id', $commend_id)); |
||
| 522 | $delivery_options = new \XoopsFormRadio(_OLEDRION_SELECT_DELIVERY, 'delivery_id'); |
||
| 523 | foreach ($deliveres as $delivery) { |
||
| 524 | $delivery_options->addOption($delivery['delivery_id'], Oledrion\Utility::deliveryHtmlSelect($delivery)); |
||
| 525 | } |
||
| 526 | $sform->addElement($delivery_options, true); |
||
| 527 | $sform->addElement(new \XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit')); |
||
| 528 | $sform = Oledrion\Utility::formMarkRequiredFields($sform); |
||
| 529 | $xoopsTpl->assign('form', $sform->render()); |
||
| 530 | |||
| 531 | // Text to display |
||
| 532 | $registry = new Oledrion\Registryfile(); |
||
| 533 | $text = $registry->getfile(OLEDRION_TEXTFILE6); |
||
| 534 | $xoopsTpl->assign('text', xoops_trim($text)); |
||
| 535 | |||
| 536 | break; |
||
| 537 | case 'payment': |
||
| 538 | |||
| 539 | if ($caddyHandler->isCartEmpty()) { |
||
| 540 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 541 | } |
||
| 542 | if (0 == $commend_id) { |
||
| 543 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 544 | } |
||
| 545 | // Check checkout level |
||
| 546 | if (1 == $checkout_level) { |
||
| 547 | Oledrion\Utility::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1); |
||
| 548 | } |
||
| 549 | // B.R. listCart(); |
||
| 550 | // B.R. Start |
||
| 551 | $commande = $commandsHandler->get($commend_id); |
||
| 552 | if (1 == $checkoutAttributes['skip_delivery']) { |
||
| 553 | // Assumes first deliery method is free shipping (else, why skip?) |
||
| 554 | // TODO: Consider pre-configuring free shipping as #1 |
||
| 555 | $delivery_id = 1; |
||
| 556 | } else { |
||
| 557 | // B.R. End |
||
| 558 | $delivery_id = $commande->getVar('cmd_delivery_id'); |
||
| 559 | } |
||
| 560 | $payments = $paymentHandler->getThisDeliveryPayment($delivery_id); |
||
| 561 | |||
| 562 | $sform = new \XoopsThemeForm(_OLEDRION_PAYMENT_FORM, 'informationfrm', OLEDRION_URL . 'checkout.php', 'post', true); |
||
| 563 | $sform->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 564 | $sform->addElement(new \XoopsFormHidden('action', 'payment')); |
||
| 565 | $sform->addElement(new \XoopsFormHidden('commend_id', $commend_id)); |
||
| 566 | $payment_options = new \XoopsFormRadio(_OLEDRION_SELECT_PAYMENT, 'payment_id'); |
||
| 567 | foreach ($payments as $payment) { |
||
| 568 | $payment_options->addOption($payment['payment_id'], Oledrion\Utility::paymentHtmlSelect($payment)); |
||
| 569 | } |
||
| 570 | $sform->addElement($payment_options, true); |
||
| 571 | $sform->addElement(new \XoopsFormButton('', 'post', _OLEDRION_SAVE_CONFIRM, 'submit')); |
||
| 572 | $sform = Oledrion\Utility::formMarkRequiredFields($sform); |
||
| 573 | $xoopsTpl->assign('form', $sform->render()); |
||
| 574 | |||
| 575 | // Text to display |
||
| 576 | $registry = new Oledrion\Registryfile(); |
||
| 577 | $text = $registry->getfile(OLEDRION_TEXTFILE6); |
||
| 578 | $xoopsTpl->assign('text', xoops_trim($text)); |
||
| 579 | |||
| 580 | break; |
||
| 581 | // **************************************************************************************************************** |
||
| 582 | case 'confirm': |
||
| 583 | // Final validation before sending to the payment gateway (or stop) |
||
| 584 | |||
| 585 | // **************************************************************************************************************** |
||
| 586 | if ($caddyHandler->isCartEmpty()) { |
||
| 587 | Oledrion\Utility::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4); |
||
| 588 | } |
||
| 589 | if (0 == $commend_id) { |
||
| 590 | Oledrion\Utility::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4); |
||
| 591 | } |
||
| 592 | // B.R. listCart(); |
||
| 593 | |||
| 594 | $commandAmountTTC += $commandAmountVAT; |
||
| 595 | |||
| 596 | $commande = $commandsHandler->get($commend_id); |
||
| 597 | if (1 == $commande->getVar('cmd_status')) { |
||
| 598 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL . 'invoice.php?id=' . $commande->getVar('cmd_id') . '&pass=' . $commande->getVar('cmd_password'), 6); |
||
| 599 | } |
||
| 600 | $commande->setVar('cmd_create', time()); |
||
| 601 | $commande->setVar('cmd_date', date('Y-m-d')); |
||
| 602 | $commande->setVar('cmd_state', Constants::OLEDRION_STATE_NOINFORMATION); |
||
| 603 | $commande->setVar('cmd_ip', Oledrion\Utility::IP()); |
||
| 604 | $commande->setVar('cmd_status', 1); |
||
| 605 | $res = $commandsHandler->insert($commande, true); |
||
| 606 | if (!$res) { |
||
| 607 | Oledrion\Utility::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6); |
||
| 608 | } |
||
| 609 | |||
| 610 | // Save command and empty cart |
||
| 611 | $caddyHandler->emptyCart(); |
||
| 612 | |||
| 613 | // Registering the Cart |
||
| 614 | $msgCommande = ''; |
||
| 615 | // $handlers = HandlerManager::getInstance(); |
||
| 616 | foreach ($cartForTemplate as $line) { |
||
| 617 | $panier = $caddyHandler->create(true); |
||
| 618 | $panier->setVar('caddy_product_id', $line['product_id']); |
||
| 619 | $panier->setVar('caddy_qte', $line['product_qty']); |
||
| 620 | $panier->setVar('caddy_price', Oledrion\Utility::formatFloatForDB($line['totalPrice'])); |
||
| 621 | // Attention, price including all taxes |
||
| 622 | $panier->setVar('caddy_cmd_id', $commande->getVar('cmd_id')); |
||
| 623 | $panier->setVar('caddy_shipping', Oledrion\Utility::formatFloatForDB($line['discountedShipping'])); |
||
| 624 | $panier->setVar('caddy_pass', md5(xoops_makepass())); |
||
| 625 | // For download |
||
| 626 | $res = $caddyHandler->insert($panier, true); |
||
| 627 | // Make msg |
||
| 628 | $cat = $categoryHandler->get($line['product_cid'])->toArray(); |
||
| 629 | $msgCommande .= str_pad($line['product_id'], 5, ' ') . ' '; |
||
| 630 | $msgCommande .= str_pad($cat['cat_title'], 10, ' ', STR_PAD_LEFT) . ' '; |
||
| 631 | $msgCommande .= str_pad($line['product_title'], 19, ' ', STR_PAD_LEFT) . ' '; |
||
| 632 | $msgCommande .= str_pad($line['product_qty'], 8, ' ', STR_PAD_LEFT) . ' '; |
||
| 633 | $msgCommande .= str_pad($oledrionCurrency->amountForDisplay($line['product_price']), 15, ' ', STR_PAD_LEFT) . ' '; |
||
| 634 | //$msgCommande .= str_pad($line['totalPriceFormated'],10,' ', STR_PAD_LEFT) . ' '; |
||
| 635 | $msgCommande .= "\n"; |
||
| 636 | // Attributs |
||
| 637 | if ($res && is_array($line['attributes']) && count($line['attributes']) > 0) { |
||
| 638 | // Registering attributes for this product |
||
| 639 | foreach ($line['attributes'] as $attributeId => $attributeInformation) { |
||
| 640 | $caddyAttribute = $caddyAttributesHandler->create(true); |
||
| 641 | $caddyAttribute->setVar('ca_cmd_id', $commande->getVar('cmd_id')); |
||
| 642 | $caddyAttribute->setVar('ca_caddy_id', $panier->getVar('caddy_id')); |
||
| 643 | $caddyAttribute->setVar('ca_attribute_id', $attributeId); |
||
| 644 | $selectedOptions = $attributeInformation['attribute_options']; |
||
| 645 | $msgCommande .= '- ' . $attributeInformation['attribute_title'] . "\n"; |
||
| 646 | foreach ($selectedOptions as $selectedOption) { |
||
| 647 | $caddyAttribute->addOption($selectedOption['option_name'], $selectedOption['option_value'], $selectedOption['option_price']); |
||
| 648 | $msgCommande .= ' ' . $selectedOption['option_name'] . ' : ' . $selectedOption['option_ttc_formated'] . "\n"; |
||
| 649 | } |
||
| 650 | $caddyAttributesHandler->insert($caddyAttribute, true); |
||
| 651 | } |
||
| 652 | } |
||
| 653 | } |
||
| 654 | |||
| 655 | // General totals |
||
| 656 | //$msgCommande .= "\n\n"._OLEDRION_SHIPPING_PRICE.' '.$oledrionCurrency->amountForDisplay($shippingAmount)."\n"; |
||
| 657 | $msgCommande .= "\n\n" . _OLEDRION_TOTAL . ' ' . $oledrionCurrency->amountForDisplay($commandAmountTTC) . "\n"; |
||
| 658 | if (count($discountsDescription) > 0) { |
||
| 659 | $msgCommande .= "\n\n" . _OLEDRION_CART4 . "\n"; |
||
| 660 | $msgCommande .= implode("\n", $discountsDescription); |
||
| 661 | $msgCommande .= "\n"; |
||
| 662 | } |
||
| 663 | |||
| 664 | $msg = []; |
||
| 665 | $msg['COMMANDE'] = $msgCommande; |
||
| 666 | $msg['NUM_COMMANDE'] = $commande->getVar('cmd_id'); |
||
| 667 | $msg['NOM'] = $commande->getVar('cmd_lastname'); |
||
| 668 | $msg['PRENOM'] = $commande->getVar('cmd_firstname'); |
||
| 669 | $msg['ADRESSE'] = $commande->getVar('cmd_adress', 'n'); |
||
| 670 | $msg['CP'] = $commande->getVar('cmd_zip'); |
||
| 671 | $msg['VILLE'] = $commande->getVar('cmd_town'); |
||
| 672 | $msg['PAYS'] = $countries[$commande->getVar('cmd_country')]; |
||
| 673 | $msg['TELEPHONE'] = $commande->getVar('cmd_telephone'); |
||
| 674 | $msg['EMAIL'] = $commande->getVar('cmd_email'); |
||
| 675 | $msg['URL_BILL'] = OLEDRION_URL . 'invoice.php?id=' . $commande->getVar('cmd_id') . '&pass=' . $commande->getVar('cmd_password'); |
||
| 676 | $msg['IP'] = Oledrion\Utility::IP(); |
||
| 677 | if (1 == $commande->getVar('cmd_bill')) { |
||
| 678 | $msg['FACTURE'] = _YES; |
||
| 679 | } else { |
||
| 680 | $msg['FACTURE'] = _NO; |
||
| 681 | } |
||
| 682 | // Send mail to client |
||
| 683 | // B.R. New Rather than sending message before payment approval, save parameters in OLEDRION_UPLOAD_PATH/${cmd_id}_conf_email.serialize |
||
| 684 | // TODO: Make a configuration option? |
||
| 685 | // Then, based on payment approval / disapproval, send email at payment gatewayNotify callback |
||
| 686 | $email_name = sprintf('%s/%d%s', OLEDRION_UPLOAD_PATH, $commande->getVar('cmd_id'), OLEDRION_CONFIRMATION_EMAIL_FILENAME_SUFFIX); |
||
| 687 | file_put_contents($email_name, serialize($msg)); |
||
| 688 | //Oledrion\Utility::sendEmailFromTpl('command_client.tpl', $commande->getVar('cmd_email'), sprintf(_OLEDRION_THANKYOU_CMD, $xoopsConfig['sitename']), $msg); |
||
| 689 | // Send mail to admin |
||
| 690 | //Oledrion\Utility::sendEmailFromTpl('command_shop.tpl', Oledrion\Utility::getEmailsFromGroup(Oledrion\Utility::getModuleOption('grp_sold')), _OLEDRION_NEW_COMMAND, $msg); |
||
| 691 | // End New |
||
| 692 | |||
| 693 | // Presentation of the form to send to the payment gateway |
||
| 694 | // Final presentation with Cart in hidden variables ****************************** |
||
| 695 | $registry = new Oledrion\Registryfile(); |
||
| 696 | $text = $registry->getfile(OLEDRION_TEXTFILE7); |
||
| 697 | $xoopsTpl->assign('text', xoops_trim($text)); |
||
| 698 | |||
| 699 | if (1 == $checkout_level) { |
||
| 700 | $text = $registry->getfile(OLEDRION_TEXTFILE4); |
||
| 701 | $xoopsTpl->append('text', '<br>' . xoops_trim($text)); |
||
| 702 | $payURL = OLEDRION_URL . 'invoice.php?id=' . $commande->getVar('cmd_id') . '&pass=' . $commande->getVar('cmd_password'); |
||
| 703 | $sform = new \XoopsThemeForm(_OLEDRION_FINISH, 'payform', $payURL, 'post', true); |
||
| 704 | } else { |
||
| 705 | // B.R. New |
||
| 706 | $payment_id = $commande->getVar('cmd_payment_id'); |
||
| 707 | $payment = $paymentHandler->get($payment_id); |
||
| 708 | // End new |
||
| 709 | // B.R. if (!isset($payment) || $payment['payment_type'] === 'offline' || $commandAmountTTC == 0) { |
||
| 710 | if (0 == $commandAmountTTC || !isset($payment) || 'offline' === $payment->getVar('payment_type')) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 711 | $text = $registry->getfile(OLEDRION_TEXTFILE4); |
||
| 712 | $xoopsTpl->append('text', '<br>' . xoops_trim($text)); |
||
| 713 | $payURL = OLEDRION_URL . 'invoice.php?id=' . $commande->getVar('cmd_id') . '&pass=' . $commande->getVar('cmd_password'); |
||
| 714 | $sform = new \XoopsThemeForm(_OLEDRION_FINISH, 'payform', $payURL, 'post', true); |
||
| 715 | } else { |
||
| 716 | // Set gateway |
||
| 717 | // B.R. $gateway = \XoopsModules\Oledrion\Gateways::getGatewayObject($payment['payment_gateway']); |
||
| 718 | |||
| 719 | $gatewayName = \XoopsModules\Oledrion\Gateways::getCurrentGateway(); |
||
| 720 | $gatewayClassName = '\XoopsModules\Oledrion\Gateways\\' . $gatewayName . '\\' . $gatewayName . 'Gateway'; |
||
| 721 | if (class_exists($gatewayClassName)) { |
||
| 722 | $gateway = new $gatewayClassName(); |
||
| 723 | } |
||
| 724 | if (!is_object($gateway)) { |
||
| 725 | die(_OLEDRION_ERROR28); |
||
| 726 | } |
||
| 727 | if (is_object($gateway)) { |
||
| 728 | $payURL = $gateway->getRedirectURL($commande->getVar('cmd_total'), $commande->getVar('cmd_id')); |
||
| 729 | } else { |
||
| 730 | $payURL = OLEDRION_URL . 'invoice.php?id=' . $commande->getVar('cmd_id') . '&pass=' . $commande->getVar('cmd_password'); |
||
| 731 | } |
||
| 732 | $sform = new \XoopsThemeForm(_OLEDRION_PAY_GATEWAY, 'payform', $payURL, 'post', true); |
||
| 733 | $elements = []; |
||
| 734 | if (is_object($gateway)) { |
||
| 735 | $elements = $gateway->getCheckoutFormContent($commande); |
||
| 736 | } |
||
| 737 | foreach ($elements as $key => $value) { |
||
| 738 | $sform->addElement(new \XoopsFormHidden($key, $value)); |
||
| 739 | } |
||
| 740 | } |
||
| 741 | } |
||
| 742 | |||
| 743 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_AMOUNT_PRICE, $oledrionCurrency->amountForDisplay($commandAmountTTC))); |
||
| 744 | if ($commande->getVar('cmd_shipping') > 0) { |
||
| 745 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_SHIPPING_PRICE, $oledrionCurrency->amountForDisplay($commande->getVar('cmd_shipping')))); |
||
| 746 | } |
||
| 747 | if ($commande->getVar('cmd_packing_price') > 0) { |
||
| 748 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_PACKING_PRICE, $oledrionCurrency->amountForDisplay($commande->getVar('cmd_packing_price')))); |
||
| 749 | } |
||
| 750 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_TOTAL, $oledrionCurrency->amountForDisplay($commandAmountTTC + $commande->getVar('cmd_shipping') + $commande->getVar('cmd_packing_price')))); |
||
| 751 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_LASTNAME, $commande->getVar('cmd_lastname'))); |
||
| 752 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_FIRSTNAME, $commande->getVar('cmd_firstname'))); |
||
| 753 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_STREET, $commande->getVar('cmd_adress'))); |
||
| 754 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_CP, $commande->getVar('cmd_zip'))); |
||
| 755 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_CITY, $commande->getVar('cmd_town'))); |
||
| 756 | if (Oledrion\Utility::getModuleOption('checkout_country')) { |
||
| 757 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_COUNTRY, $countries[$commande->getVar('cmd_country')])); |
||
| 758 | } |
||
| 759 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_PHONE, $commande->getVar('cmd_telephone'))); |
||
| 760 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_MOBILE, $commande->getVar('cmd_mobile'))); |
||
| 761 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_EMAIL, $commande->getVar('cmd_email'))); |
||
| 762 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_GIFT, $commande->getVar('cmd_gift'))); |
||
| 763 | if ($commande->getVar('cmd_packing')) { |
||
| 764 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_PACKING, $commande->getVar('cmd_packing'))); |
||
| 765 | } |
||
| 766 | if ($commande->getVar('cmd_location')) { |
||
| 767 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_LOCATION, $commande->getVar('cmd_location'))); |
||
| 768 | } |
||
| 769 | if ($commande->getVar('cmd_delivery')) { |
||
| 770 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_DELIVERY, $commande->getVar('cmd_delivery'))); |
||
| 771 | } |
||
| 772 | if ($commande->getVar('cmd_payment')) { |
||
| 773 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_PAYMENT, $commande->getVar('cmd_payment'))); |
||
| 774 | } |
||
| 775 | if (Oledrion\Utility::getModuleOption('ask_vatnumber')) { |
||
| 776 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_VAT_NUMBER, $commande->getVar('cmd_vat_number'))); |
||
| 777 | } |
||
| 778 | if (Oledrion\Utility::getModuleOption('ask_bill')) { |
||
| 779 | if (0 == $commande->getVar('cmd_bill')) { |
||
| 780 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_INVOICE, _NO)); |
||
| 781 | } else { |
||
| 782 | $sform->addElement(new \XoopsFormLabel(_OLEDRION_INVOICE, _YES)); |
||
| 783 | } |
||
| 784 | } |
||
| 785 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 786 | //B.R. if (!isset($payment) || $payment['payment_type'] === 'offline' || $commandAmountTTC == 0 || $checkout_level == 1 ) { |
||
| 787 | if (0 == $commandAmountTTC || !isset($payment) || 'offline' === $payment->getVar('payment_type') || 1 == $checkout_level) { |
||
|
0 ignored issues
–
show
|
|||
| 788 | $submit_btn = new \XoopsFormButton('', 'post', _OLEDRION_FINISH, 'submit'); |
||
| 789 | } else { |
||
| 790 | $submit_btn = new \XoopsFormButton('', 'post', _OLEDRION_PAY_GATEWAY, 'submit'); |
||
| 791 | } |
||
| 792 | $buttonTray->addElement($submit_btn); |
||
| 793 | $sform->addElement($buttonTray); |
||
| 794 | $xoopsTpl->assign('form', $sform->render()); |
||
| 795 | |||
| 796 | // Send sms |
||
| 797 | if (Oledrion\Utility::getModuleOption('sms_checkout')) { |
||
| 798 | $information['to'] = ltrim($commande->getVar('cmd_mobile'), 0); |
||
| 799 | $information['text'] = Oledrion\Utility::getModuleOption('sms_checkout_text'); |
||
| 800 | $sms = \XoopsModules\Oledrion\Sms::sendSms($information); |
||
| 801 | } |
||
| 802 | |||
| 803 | break; |
||
| 804 | } |
||
| 805 | |||
| 806 | $xoopsTpl->assign('breadcrumb', Oledrion\Utility::breadcrumb([OLEDRION_URL . basename(__FILE__) => _OLEDRION_VALIDATE_CMD])); |
||
| 807 | |||
| 808 | // Image icons |
||
| 809 | if (file_exists(OLEDRION_PATH . 'language/' . $xoopsConfig['language'] . '/image/step1.png')) { |
||
| 810 | $step1 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step1.png'; |
||
| 811 | $step2 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step2.png'; |
||
| 812 | $step3 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step3.png'; |
||
| 813 | } else { |
||
| 814 | // Fallback |
||
| 815 | $step1 = OLEDRION_URL . 'language/english/image/step1.png'; |
||
| 816 | $step2 = OLEDRION_URL . 'language/english/image/step2.png'; |
||
| 817 | $step3 = OLEDRION_URL . 'language/english/image/step3.png'; |
||
| 818 | } |
||
| 819 | $xoopsTpl->assign('step1', $step1); |
||
| 820 | $xoopsTpl->assign('step2', $step2); |
||
| 821 | $xoopsTpl->assign('step3', $step3); |
||
| 822 | |||
| 823 | $title = _OLEDRION_VALIDATE_CMD . ' - ' . Oledrion\Utility::getModuleName(); |
||
| 824 | Oledrion\Utility::setMetas($title, $title); |
||
| 825 | Oledrion\Utility::setCSS(); |
||
| 826 | Oledrion\Utility::setLocalCSS($xoopsConfig['language']); |
||
| 827 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 828 |