diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index a85766e1c99..c8640f9928f 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -127,6 +127,25 @@ function product_prepare_head($object) $h++; } } + + // Tab to link resources + if (!empty($conf->resource->enabled)) + { + if ($object->isProduct() && ! empty($conf->global->RESOURCE_ON_PRODUCTS)) + { + $head[$h][0] = DOL_URL_ROOT . '/resource/element_resource.php?element=product&ref=' . $object->ref; + $head[$h][1] = $langs->trans("Resources"); + $head[$h][2] = 'resources'; + $h++; + } + if ($object->isService() && ! empty($conf->global->RESOURCE_ON_SERVICES)) + { + $head[$h][0] = DOL_URL_ROOT . '/resource/element_resource.php?element=service&ref=' . $object->ref; + $head[$h][1] = $langs->trans("Resources"); + $head[$h][2] = 'resources'; + $h++; + } + } // Show more tabs from modules // Entries must be declared in modules descriptor with line diff --git a/htdocs/core/tpl/resource_add.tpl.php b/htdocs/core/tpl/resource_add.tpl.php index 2bd413deb70..34246bcf0b6 100644 --- a/htdocs/core/tpl/resource_add.tpl.php +++ b/htdocs/core/tpl/resource_add.tpl.php @@ -21,6 +21,7 @@ $out .= ''; $out .= ''; $out .= ''; $out .= ''; +$out .= ''; $out .= ''; diff --git a/htdocs/resource/element_resource.php b/htdocs/resource/element_resource.php index bba4d329c24..6ae7e4e36f2 100644 --- a/htdocs/resource/element_resource.php +++ b/htdocs/resource/element_resource.php @@ -31,6 +31,9 @@ if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; } +if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { + require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('resource', 'other', 'interventions')); @@ -79,7 +82,6 @@ if ($socid > 0) // Special for thirdparty if ($action == 'add_element_resource' && ! $cancel) { - $error++; $res = 0; if (! ($resource_id > 0)) { @@ -89,16 +91,20 @@ if ($action == 'add_element_resource' && ! $cancel) } else { - $objstat = fetchObjectByElement($element_id, $element); + $objstat = fetchObjectByElement($element_id, $element, $element_ref); $objstat->element = $element; // For externals module, we need to keep @xx $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); } if (! $error && $res > 0) { setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs'); - header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$element_id); + header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id); exit; } + else if ($objstat) + { + setEventMessages($objstat->error, $objstat->errors, 'errors'); + } } // Update ressource @@ -415,6 +421,31 @@ else dol_fiche_end(); } } + + // Specific to product/service module + if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; + + $product = new Product($db); + $product->fetch($element_id, $element_ref); + + if (is_object($product)) + { + + $head = product_prepare_head($product); + $titre=$langs->trans("CardProduct".$product->type); + $picto=($product->type==Product::TYPE_SERVICE?'service':'product'); + + dol_fiche_head($head, 'resources', $titre, -1, $picto); + + $shownav = 1; + if ($user->societe_id && ! in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; + dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element); + + dol_fiche_end(); + } + } // hook for other elements linked