0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; } if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; } if (!$res && file_exists("../main.inc.php")) { $res = @include "../main.inc.php"; } if (!$res && file_exists("../../main.inc.php")) { $res = @include "../../main.inc.php"; } if (!$res && file_exists("../../../main.inc.php")) { $res = @include "../../../main.inc.php"; } if (!$res) { die("Include of main fails"); } require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; dol_include_once('/importzugferd/class/productmapping.class.php'); dol_include_once('/importzugferd/lib/importzugferd.lib.php'); // Load translation files $langs->loadLangs(array("importzugferd@importzugferd", "products", "companies")); // Security check if (!$user->hasRight('importzugferd', 'mapping', 'write')) { accessforbidden(); } // Get parameters $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $id = GETPOST('id', 'int'); $supplier_id = GETPOST('supplier_id', 'int'); // Form fields $supplier_ref = GETPOST('supplier_ref', 'alpha'); $product_id = GETPOST('product_id', 'int'); $ean = GETPOST('ean', 'alpha'); $manufacturer_ref = GETPOST('manufacturer_ref', 'alpha'); $description = GETPOST('description', 'alpha'); $priority = GETPOST('priority', 'int'); // Initialize objects $mapping = new ProductMapping($db); $form = new Form($db); $error = 0; /* * Actions */ // Add mapping if ($action == 'add') { if (empty($supplier_id) || $supplier_id <= 0) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors'); $error++; } if (empty($supplier_ref)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('SupplierRef')), null, 'errors'); $error++; } if (empty($product_id) || $product_id <= 0) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Product')), null, 'errors'); $error++; } if (!$error) { $mapping->fk_soc = $supplier_id; $mapping->supplier_ref = $supplier_ref; $mapping->fk_product = $product_id; $mapping->ean = $ean; $mapping->manufacturer_ref = $manufacturer_ref; $mapping->description = $description; $mapping->priority = $priority; $result = $mapping->create($user); if ($result > 0) { setEventMessages($langs->trans('MappingCreated'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?supplier_id='.$supplier_id); exit; } else { setEventMessages($mapping->error, null, 'errors'); } } $action = ''; } // Delete mapping if ($action == 'confirm_delete' && $confirm == 'yes') { $mapping->fetch($id); $save_supplier_id = $mapping->fk_soc; $result = $mapping->delete($user); if ($result > 0) { setEventMessages($langs->trans('MappingDeleted'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?supplier_id='.$save_supplier_id); exit; } else { setEventMessages($mapping->error, null, 'errors'); } } /* * View */ $title = $langs->trans('ProductMapping'); llxHeader('', $title, '', '', 0, 0, '', '', '', 'mod-importzugferd page-mapping'); print load_fiche_titre($title, '', 'fa-exchange-alt'); // Confirm delete if ($action == 'delete') { print $form->formconfirm( $_SERVER['PHP_SELF'].'?id='.$id.'&supplier_id='.$supplier_id, $langs->trans('DeleteMapping'), $langs->trans('ConfirmDeleteMapping'), 'confirm_delete', '', 0, 1 ); } // Supplier selection print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('SelectSupplier').'
'.$langs->trans('Supplier').''; print $form->select_company($supplier_id, 'supplier_id', 's.fournisseur = 1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); print ' '; print '
'; print '
'; print '
'; // If supplier selected, show mappings and add form if ($supplier_id > 0) { $supplier = new Societe($db); $supplier->fetch($supplier_id); print '
'; // Add new mapping form print '
'; print ''; print ''; print ''; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('AddMapping').' - '.$supplier->getNomUrl(1).'
'.$langs->trans('SupplierRef').''.$langs->trans('Product').''.$form->select_produits($product_id, 'product_id', '', 0, 0, -1, 2, '', 0, array(), 0, '1', 0, 'minwidth300', 0, '', null, 1).''.$langs->trans('EAN').'
'.$langs->trans('ManufacturerRef').''.$langs->trans('Description').''.$langs->trans('Priority').'
'; print ''; print '
'; print '
'; print '
'; // Existing mappings print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $mappings = $mapping->fetchAllBySupplier($supplier_id); if (count($mappings) > 0) { foreach ($mappings as $m) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } } else { print ''; } print '
'.$langs->trans('SupplierRef').''.$langs->trans('Product').''.$langs->trans('EAN').''.$langs->trans('ManufacturerRef').''.$langs->trans('Description').''.$langs->trans('Priority').''.$langs->trans('Active').''.$langs->trans('Action').'
'.dol_escape_htmltag($m['supplier_ref']).''; $product = new Product($db); $product->fetch($m['fk_product']); print $product->getNomUrl(1); print ''.dol_escape_htmltag($m['ean']).''.dol_escape_htmltag($m['manufacturer_ref']).''.dol_escape_htmltag($m['description']).''.$m['priority'].''; print $m['active'] ? img_picto($langs->trans('Active'), 'statut4') : img_picto($langs->trans('Inactive'), 'statut5'); print ''; print ''; print img_picto($langs->trans('Delete'), 'delete'); print ''; print '
'.$langs->trans('NoMappingsFound').'
'; print '
'; } llxFooter(); $db->close();