public function displayForm() { global $smarty, $cookie; $errors = array(); $outputMain = ''; $smarty->assign("djl_mode", $this->dejalaConfig->mode); $smarty->assign("disabled", ''); if ($this->dejalaConfig->mode == 'PROD') { $smarty->assign("disabled", 'disabled="disabled"'); } if (true !== extension_loaded('curl')) { $errors[] = $this->l('This module requires php extension cURL to function properly. Please install the php extension "cURL" first.'); $smarty->assign("disabled", 'disabled="disabled"'); } $registered = TRUE; if (0 == strlen($this->dejalaConfig->login) || 0 == strlen($this->dejalaConfig->password)) { $registered = FALSE; } if ($registered) { $djlUtil = new DejalaUtils(); $responsePing = $djlUtil->ping($this->dejalaConfig, $this->dejalaConfig->mode); if (200 != $responsePing['status']) { if (401 == $responsePing['status']) { $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. Your credentials were not recognized.'); } else { $errors[] = $this->l('An error occurred while authenticating your account on Dejala.com. This may be due to a temporary network or platform problem. Please try again later or contact Dejala.com'); } unset($_GET['cat']); $registered = FALSE; } } $smarty->assign("registered", $registered ? "1" : "0"); if (!isset($_GET['cat']) || $_GET['cat'] === 'home' || $_GET['cat'] === '') { $currentTab = "home"; } else { $currentTab = $_GET['cat']; } $smarty->assign("currentTab", $currentTab); $smarty->assign("moduleConfigURL", 'index.php?tab=AdminModules&configure=dejala&token=' . $_GET['token']); $smarty->assign("formAction", Tools::safeOutput($_SERVER['REQUEST_URI'])); $outputMenu = $this->display(__FILE__, 'dejala_menu.tpl'); if ($currentTab === 'home') { $smarty->assign("login", html_entity_decode(Configuration::get('PS_SHOP_EMAIL'), ENT_COMPAT, 'UTF-8')); if ($registered) { $smarty->assign("visibility_status", $this->dejalaConfig->visibility_status); $smarty->assign("visible_users_list", $this->dejalaConfig->visible_users_list); $smarty->assign("store_login", html_entity_decode($this->dejalaConfig->login, ENT_COMPAT, 'UTF-8')); $smartifyErrors = $this->smartyfyStoreAttributes(); if (isset($smartifyErrors) && count($smartifyErrors)) { $errors = $smartifyErrors; } } else { $shopName = Configuration::get('PS_SHOP_NAME'); if (strlen($shopName) >= 15) { $shopName = substr($shopName, 0, 15); } $smarty->assign("store_name", html_entity_decode($shopName, ENT_COMPAT, 'UTF-8')); } $outputMain = $this->display(__FILE__, 'dejala_home.tpl'); } elseif ($currentTab === 'contacts') { $contacts = array(); $djlUtil = new DejalaUtils(); $responseArray = $djlUtil->getStoreContacts($this->dejalaConfig, $contacts); if ('200' == $responseArray['status']) { foreach ($contacts as $contactName => $contactData) { foreach ($contactData as $key => $value) { $smarty->assign($contactName . '_' . $key, $value); } } } $outputMain = $this->display(__FILE__, 'dejala_contacts.tpl'); } elseif ($currentTab === 'location') { $location = array(); $djlUtil = new DejalaUtils(); $responseArray = $djlUtil->getStoreLocation($this->dejalaConfig, $location); if ('200' == $responseArray['status']) { foreach ($location as $key => $value) { $smarty->assign($key, $value); } $outputMain = $this->display(__FILE__, 'dejala_location.tpl'); } } elseif ($currentTab === 'processes') { $processes = array(); $djlUtil = new DejalaUtils(); $responseArray = $djlUtil->getStoreProcesses($this->dejalaConfig, $processes); if ('200' == $responseArray['status']) { foreach ($processes as $key => $value) { $smarty->assign($key, $value); } $outputMain = $this->display(__FILE__, 'dejala_processes.tpl'); } } elseif ($currentTab === 'prices') { $products = array(); $djlUtil = new DejalaUtils(); $responseArray = $djlUtil->getStoreProducts($this->dejalaConfig, $products); if ('200' == $responseArray['status']) { //price = price_HT*(inv_vat) foreach ($products as &$product) { $vat_factor = 1 + $product['vat'] / 100; $product['price_notax'] = number_format($product['price'], 2, '.', ''); $product['price'] = number_format(round($product['price'] * $vat_factor, 2), 2, '.', ''); $product['public_price'] = number_format(round($product['price'] + $product['margin'], 2), 2, '.', ''); $product['public_price_notax'] = number_format(round($product['public_price'] / $vat_factor, 2), 2, '.', ''); } $smarty->assign('products', $products); $outputMain = $this->display(__FILE__, 'dejala_products.tpl'); } } elseif ($currentTab === 'accounting') { $smartifyErrors = $this->smartyfyStoreAttributes(); if (isset($smartifyErrors) && count($smartifyErrors)) { $errors = $smartifyErrors; } $djlUtil = new DejalaUtils(); $deliveries = array(); $responseArray = $djlUtil->getStoreDeliveries($this->dejalaConfig, $deliveries); if ('200' == $responseArray['status']) { foreach ($deliveries as &$delivery) { $delivery['creation_date'] = date('d/m/Y', $delivery['creation_utc']); $delivery['creation_time'] = date('H\\hi', $delivery['creation_utc']); if (isset($delivery['shipping_start_utc'])) { $delivery['shipping_date'] = date('d/m/Y', $delivery['shipping_start_utc']); $delivery['shipping_start'] = date('H\\hi', $delivery['shipping_start_utc']); $delivery['shipping_stop'] = date('H\\hi', (int) $delivery['shipping_start_utc'] + 3600 * (int) $delivery['timelimit']); } else { $delivery['shipping_date'] = ''; $delivery['shipping_start'] = ''; $delivery['shipping_stop'] = ''; } if (isset($delivery['delivery_utc'])) { $delivery['delivery_date'] = date('d/m/Y', $delivery['delivery_utc']); $delivery['delivery_time'] = date('H\\hi', $delivery['delivery_utc']); } } $smarty->assign('formAction', __PS_BASE_URI__ . 'modules/' . $this->name . '/deliveries_csv.php'); $smarty->assign('defaultDateFrom', date('01/m/Y')); $smarty->assign('defaultDateTo', date('d/m/Y')); $smarty->assign('deliveries', $deliveries); $outputMain = $this->display(__FILE__, 'dejala_deliveries.tpl'); } } elseif ($currentTab === 'delivery_options') { $outputMain = $this->displayDeliveryOptions(); } elseif ($_GET['cat'] === 'technical_options') { $states = $this->getOrderStates(); $triggers = explode(',', $this->dejalaConfig->trigerringStatuses); $orderStatuses = array(); foreach ($states as $status) { $m_status['id'] = (int) $status['id_order_state']; $m_status['label'] = $status['name']; if (in_array($status['id_order_state'], $triggers)) { $m_status['checked'] = '1'; } else { $m_status['checked'] = '0'; } $orderStatuses[] = $m_status; } $smarty->assign('statuses', $orderStatuses); $smarty->assign('trigerringStatuses', $this->dejalaConfig->trigerringStatuses); $outputMain = $this->display(__FILE__, 'dejala_technical_options.tpl'); } $outputErr = ''; if (count($errors)) { foreach ($errors as $err) { $outputErr .= '<div class="alert error">' . $err . '</div>'; } } $output = $outputErr; $output = $output . $outputMenu; $output = $output . $outputMain; $output = $output . $this->display(__FILE__, 'dejala_footer.tpl'); return $output; }