/**
  * This function supposes that delivery ref is always in the 17th column
  */
 public function importFileAction()
 {
     $i = 0;
     $con = Propel::getWriteConnection(OrderTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $form = $this->createForm('dpdclassic.import');
     try {
         $vForm = $this->validateForm($form);
         // Get file
         $importedFile = $vForm->getData()['import_file'];
         // Check extension
         if (!in_array(strtolower($importedFile->getClientOriginalExtension()), ['csv', 'txt'])) {
             throw new FormValidationException(Translator::getInstance()->trans('Bad file format. Plain text or CSV expected.', [], DpdClassic::DOMAIN_NAME));
         }
         $csvData = file_get_contents($importedFile);
         $lines = explode(PHP_EOL, $csvData);
         // For each line, parse columns
         foreach ($lines as $line) {
             $parsedLine = str_getcsv($line, "\t");
             // Check if there are enough columns to include order ref
             if (count($parsedLine) > DpdClassic::ORDER_REF_COLUMN) {
                 // Get delivery and order ref
                 $deliveryRef = $parsedLine[DpdClassic::DELIVERY_REF_COLUMN];
                 $orderRef = $parsedLine[DpdClassic::ORDER_REF_COLUMN];
                 // Save delivery ref if there is one
                 if (!empty($deliveryRef)) {
                     $this->importDeliveryRef($deliveryRef, $orderRef, $i);
                 }
             }
         }
         $con->commit();
         // Get number of affected rows to display
         $this->getSession()->getFlashBag()->add('update-orders-result', Translator::getInstance()->trans('Operation successful. %i orders affected.', ['%i' => $i], DpdClassic::DOMAIN_NAME));
         // Redirect
         return $this->generateRedirect(URL::getInstance()->absoluteUrl($form->getSuccessUrl(), ['current_tab' => 'import_exaprint']));
     } catch (FormValidationException $e) {
         $con->rollback();
         $this->setupFormErrorContext(null, $e->getMessage(), $form);
         return $this->render('module-configure', ['module_code' => DpdClassic::getModuleCode(), 'current_tab' => 'import_exaprint']);
     }
 }
 public function updateSenderAction()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('DpdClassic'), AccessManager::UPDATE))) {
         return $response;
     }
     $form = new ExportExaprintForm($this->getRequest());
     $error_message = null;
     try {
         $vform = $this->validateForm($form);
         $file_path = self::getJSONpath();
         if (file_exists($file_path) ? is_writable($file_path) : is_writable(__DIR__ . "/../Config/")) {
             $file = fopen(self::getJSONpath(), 'w');
             fwrite($file, json_encode(array("name" => $vform->get('name')->getData(), "addr" => $vform->get('addr')->getData(), "addr2" => $vform->get('addr2')->getData(), "zipcode" => $vform->get('zipcode')->getData(), "city" => $vform->get('city')->getData(), "tel" => $vform->get('tel')->getData(), "mobile" => $vform->get('mobile')->getData(), "mail" => $vform->get('mail')->getData(), "expcode" => $vform->get('expcode')->getData())));
             fclose($file);
             return $this->generateRedirectFromRoute("admin.module.configure", [], ['module_code' => "DpdClassic", 'current_tab' => "configure_export_exaprint", '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction']);
         } else {
             throw new \Exception(Translator::getInstance()->trans("Can't write DpdClassic/Config/sender.json. Please change the rights on the file and/or the directory.", [], DpdClassic::DOMAIN_NAME));
         }
     } catch (\Exception $e) {
         $error_message = $e->getMessage();
     }
     $this->setupFormErrorContext(Translator::getInstance()->trans("Error while updating the file with sender information", [], DpdClassic::DOMAIN_NAME), $error_message, $form);
     return $this->render('module-configure', ['module_code' => DpdClassic::getModuleCode(), 'current_tab' => "configure_export_exaprint"]);
 }