table = 'expeditor'; $this->className = 'ExpeditorModule'; parent::__construct(); } private function _treatCsvFile($file) { global $cookie; /* * get all informations of CSV file */ $row = 0; $infos = array(); $handle = fopen($file, "r"); while (($data = fgetcsv($handle, 1000, ';', '"')) !== FALSE) { for ($c=0; $c < sizeof($data); $c++) { $infos[$row][$c] = $data[$c]; } $row++; } /* * Extract all needings informations */ if (($keyId = array_search($this->columnName, $infos[0])) === false) return false; $keyShippingNumber = array_search('NumeroColis', $infos[0]); echo '

' . $this->l('List of orders recognized') . '

'; echo ''; echo '

'; return true; } private function _importNumber() { $file = $_FILES['file']['tmp_name']; if ($html = $this->_treatCsvFile($file)) { $this->displayInfos = false; return true; } return false; } private function _generateCsvFile() { foreach($_POST['order'] as $field) { if (is_numeric($field['weight']) AND $field['weight'] > 0) { $id_expeditor = ExpeditorModule::getByIdOrder($field['id']); $expeditor = new ExpeditorModule($id_expeditor); $expeditor->id_order = $field['id']; $expeditor->weight = $field['weight']; $expeditor->standard_size = 0; if ($field['standard_size'] == '0') $expeditor->standard_size = 1; $expeditor->save(); } } header('Location: http://'. htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ .'modules/expeditor/getCsv.php'); } private function _postProcess() { if (isset($_POST['generate'])) { $this->_generateCsvFile(); } else if (isset($_POST['import'])) { if (empty($_FILES['file']['tmp_name']) OR !isset($_FILES['file'])) { return '

' . $this->l('Please upload a CSV file.') . '

'; } else { if (!$this->_importNumber()) return '

'.$this->l('Column').' '.$this->columnName.' '.$this->l('is required').'.'.'

'; } } } private function displayOrdersTable() { global $cookie; $order_state = new OrderState(Configuration::get('EXPEDITOR_STATE_EXP')); $html = ''; $html.= '

'.$this->l('All orders which have the state').' "'.$order_state->name[$cookie->id_lang].'"'; foreach(explode(',',Configuration::get('EXPEDITOR_CARRIER')) as $val ) { $carrier = new Carrier($val); if ($carrier->id) $html.= ' '.$this->l('or the carrier').' "'.$carrier->name.'"'; } $html.= '. 

' . $this->l('Change configuration') . '

'; $orders = ExpeditorModule::getOrders(); if (empty($orders)) { $html.= '

' . $this->l('No orders with this state.') . '

'; } else { $html.= '
'; $html.= "\n"; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; foreach ($orders as $order) { $oOrder = new Order($order['id_order']); $products = $oOrder->getProducts(); $total_weight = 0; /* Antadis */ $in_data = Db::getInstance()->ExecuteS('SELECT weight FROM `'._DB_PREFIX_.'expeditor` WHERE id_order = '.$order['id_order']); if(count($in_data) > 0) { $total_weight = $in_data[0]['weight']; } else { foreach($products AS $product) $total_weight += $product['product_weight'] * $product['product_quantity']; } $html.= "\n"; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; $html.= ''; } $html.= '
' . $this->l('Order ID') . '' . $this->l('Customer') . '' . $this->l('Total price') . '' . $this->l('Total shipping') . '' . $this->l('Date') . '' . $this->l('Weight (grams)') . '' . $this->l('Non-standard size') . '' . $this->l('Detail') . '
' . $order['id_order'] . '' . $order['customer'] . '' . Tools::displayPrice($order['total'], new Currency($order['id_currency'])) . '' . Tools::displayPrice($order['shipping'], new Currency($order['id_currency'])) . '' . Tools::displayDate($order['date'], $order['id_lang']) . ' '.$this->l('View').'

'; $html.= ''; $html.= '
'; } return $html; } public function displayImportForm() { $_html = '
'; $_html.= '
'; $_html.= '' . $this->l('Import Shipping Number') . ''; $_html.= '

'; $_html.= ''; $_html.= ''; $_html.= '

'; $_html.= '
'; $_html.= '
'; return $_html; } public function display() { $html = ''; if (!empty($_POST)) $html.= $this->_postProcess(); if ($this->displayInfos) { $html.= $this->displayOrdersTable(); $html.= '

'; $html.= $this->displayImportForm(); } echo $html; } } ?>