';
// print '
';
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index e28a9b328d4..f8e728f31b6 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -2589,9 +2589,9 @@ if ($action == 'create' && $user->rights->commande->creer)
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- //$linktoelem = $form->showLinkToObjectBlock($object);
- //if ($linktoelem) print ' '.$linktoelem;
-
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
+
print '';
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 8313fc5022e..252fa872e6f 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -134,14 +134,6 @@ if (empty($reshook))
include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
- // Link invoice to order
- if (GETPOST('linkedOrder') && empty($cancel) && $id > 0)
- {
- $object->fetch($id);
- $object->fetch_thirdparty();
- $result = $object->add_object_linked('commande', GETPOST('linkedOrder'));
- }
-
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer) {
// if (1 == 0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) {
@@ -4030,9 +4022,9 @@ else if ($id > 0 || ! empty($ref))
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- $linktoelem = $form->showLinkToObjectBlock($object,array('order'));
- if ($linktoelem) print ' '.$linktoelem;
-
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
+
// Link for paypal payment
if (! empty($conf->paypal->enabled) && $object->statut != 0) {
include_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php';
diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index 0f7ffb8c72f..8415b6dfbad 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -1996,8 +1996,8 @@ else
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- $linktoelem = $form->showLinkToObjectBlock($object);
- if ($linktoelem) print ' '.$linktoelem;
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
print ' ';
diff --git a/htdocs/core/actions_dellink.inc.php b/htdocs/core/actions_dellink.inc.php
index 45fb8c5f9ec..63218dde739 100644
--- a/htdocs/core/actions_dellink.inc.php
+++ b/htdocs/core/actions_dellink.inc.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2015-2016 Laurent Destailleur
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,22 +18,29 @@
/**
* \file htdocs/core/actions_dellink.inc.php
- * \brief Code for actions on deleting link between elements
+ * \brief Code for actions on linking and deleting link between elements
*/
// $action must be defined
// $object must be defined
// $permissiondellink must be defined
-// $uploaddir (example $conf->projet->dir_output . "/";)
$dellinkid = GETPOST('dellinkid','int');
+$addlinkid = GETPOST('idtolinkto','int');
-// Set public note
+// Link invoice to order
+if ($action == 'addlink' && ! empty($permissiondellink) && ! GETPOST('cancel') && $id > 0 && $addlinkid > 0)
+{
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $result = $object->add_object_linked(GETPOST('addlink'), $addlinkid);
+}
+
+// Delete link
if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel') && $dellinkid > 0)
{
$result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid);
if ($result < 0) setEventMessages($object->error,$object->errors,'errors');
}
-
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index d3eff2f8173..f3dd64e6838 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2380,6 +2380,10 @@ abstract class CommonObject
$origin = (! empty($origin) ? $origin : $this->origin);
$origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id);
+ // Special case
+ if ($origin == 'order') $origin='commande';
+ if ($origin == 'invoice') $origin='facture';
+
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@@ -2564,7 +2568,10 @@ abstract class CommonObject
// Set classfile
$classfile = strtolower($subelement); $classname = ucfirst($subelement);
- if ($objecttype == 'invoice_supplier') {
+ if ($objecttype == 'order') {
+ $classfile = 'commande'; $classname = 'Commande';
+ }
+ else if ($objecttype == 'invoice_supplier') {
$classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur';
}
else if ($objecttype == 'order_supplier') {
@@ -2584,15 +2591,18 @@ abstract class CommonObject
if ($conf->$module->enabled && (($element != $this->element) || $alsosametype))
{
dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
-
- foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element
+ //print '/'.$classpath.'/'.$classfile.'.class.php';
+ if (class_exists($classname))
{
- $object = new $classname($this->db);
- $ret = $object->fetch($objectid);
- if ($ret >= 0)
- {
- $this->linkedObjects[$objecttype][$i] = $object;
- }
+ foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element
+ {
+ $object = new $classname($this->db);
+ $ret = $object->fetch($objectid);
+ if ($ret >= 0)
+ {
+ $this->linkedObjects[$objecttype][$i] = $object;
+ }
+ }
}
}
}
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index fbc544b2a14..83f10b469c0 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -5267,12 +5267,13 @@ class Form
/**
* Show block with links to link to other objects.
- *
+ *
* @param CommonObject $object Object we want to show links to
- * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order')
- * @return string <0 if KO, >0 if OK
+ * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order'). null or array() if no restriction.
+ * @param array $excludelinksto Do not show links of this type, for exemple array('order') or array('supplier_order'). null or array() if no exclusion.
+ * @return string <0 if KO, >0 if OK
*/
- function showLinkToObjectBlock($object, $restrictlinksto=array())
+ function showLinkToObjectBlock($object, $restrictlinksto=array(), $excludelinksto=array())
{
global $conf, $langs, $hookmanager;
global $bc;
@@ -5281,202 +5282,90 @@ class Form
if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
-
- if (((! is_array($restrictlinksto)) || in_array('order',$restrictlinksto))
- && ! empty($conf->commande->enabled))
+ $possiblelinks=array(
+ 'propal'=>array('enabled'=>$conf->propale->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'invoice'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.facnumber as ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'contrat'=>array('enabled'=>$conf->contrat->enabled , 'perms'=>1, 'label'=>'LinkToContract', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'fichinter'=>array('enabled'=>$conf->ficheinter->enabled, 'perms'=>1, 'label'=>'LinkToIntervention', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled , 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'order_supplier'=>array('enabled'=>$conf->fournisseur->commande->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id),
+ 'invoice_supplier'=>array('enabled'=>$conf->fournisseur->facture->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id)
+ );
+
+ foreach($possiblelinks as $key => $possiblelink)
{
- $linktoelem.=($linktoelem?' ':'').'' . $langs->trans('LinkedOrder') . '';
-
- print '
-
- ';
-
- print 'global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>';
-
- $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht";
- $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
- $sql .= ", " . MAIN_DB_PREFIX . "commande as c";
- $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id . '';
-
- $resqlorderlist = $this->db->query($sql);
- if ($resqlorderlist)
+ $num = 0;
+
+ if (! empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || ! in_array($key, $excludelinksto)))
{
- $num = $this->db->num_rows($resqlorderlist);
- $i = 0;
-
- print ' ';
- $this->db->free($resqlorderlist);
- } else {
- dol_print_error($this->db);
- }
-
- print ' ';
- }
-
- if ((in_array('fichinter',$restrictlinksto)) && ! empty($conf->ficheinter->enabled))
- {
- $linktoelem.=($linktoelem?' ':'').'' . $langs->trans('LinkedFichinter') . '';
-
- print '
-
- ';
-
- print '';
}
- if (((! is_array($restrictlinksto)) || in_array('supplier_order',$restrictlinksto))
- && ! empty($conf->fournisseur->enabled))
- {
- $linktoelem.=($linktoelem?' ':'').'' . $langs->trans('LinkedOrder') . '';
-
- print '
-
- ';
-
- print '';
- }
-
-
return $linktoelem;
}
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index d434e7df6c1..87179b9840f 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1836,8 +1836,8 @@ else if ($id || $ref)
// Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object);
- //if ($linktoelem) print ' '.$linktoelem;
-
+ //if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
+
print '';
// List of actions on element
diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php
index 25688bf6e6e..77be2af8635 100644
--- a/htdocs/expensereport/card.php
+++ b/htdocs/expensereport/card.php
@@ -2068,11 +2068,9 @@ if ($action != 'create' && $action != 'edit' && ($id || $ref))
// Show links to link elements
$linktoelements=array();
- if($conf->global->EXPENSES_LINK_TO_INTERVENTION) $linktoelements[]='fichinter';
- $linktoelem='';
- $linktoelem = $form->showLinkToObjectBlock($object,$linktoelements);
- if ($linktoelem) print ' '.$linktoelem;
-
+ if (! empty($conf->global->EXPENSES_LINK_TO_INTERVENTION)) $linktoelements[]='fichinter';
+ $linktoelem = $form->showLinkToObjectBlock($object, $linktoelements, array('expensereport'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
}
llxFooter();
diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php
index 7472906dc58..79e0687c372 100644
--- a/htdocs/fichinter/card.php
+++ b/htdocs/fichinter/card.php
@@ -1681,9 +1681,9 @@ else if ($id > 0 || ! empty($ref))
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- //$linktoelem = $form->showLinkToObjectBlock($object);
- //if ($linktoelem) print ' '.$linktoelem;
-
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('fichinter'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
+
print ' ';
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index a316aaf0f6a..2afc7df171f 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -2834,8 +2834,8 @@ elseif (! empty($object->id))
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- //$linktoelem = $form->showLinkToObjectBlock($object);
- //if ($linktoelem) print ' '.$linktoelem;
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('order_supplier'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
print ' ';
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 163f6e8bdb7..cafb67b50f3 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -2240,9 +2240,9 @@ else
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- $linktoelem = $form->showLinkToObjectBlock($object,array('supplier_order'));
- if ($linktoelem) print ' '.$linktoelem;
-
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice_supplier'));
+ if ($linktoelem) print ($somethingshown?'':' ').$linktoelem;
+
print ' | ';
diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang
index e4dca048a78..506707a294f 100644
--- a/htdocs/langs/fr_FR/main.lang
+++ b/htdocs/langs/fr_FR/main.lang
@@ -641,6 +641,14 @@ NewAttribute=Nouvel attribut
AttributeCode=Code de l'attribut
URLPhoto=URL de la photo/logo
SetLinkToAnotherThirdParty=Lier vers un autre tiers
+LinkToProposal=Link to proposal
+LinkToOrder=Link to order
+LinkToInvoice=Link to invoice
+LinkToSupplierOrder=Link to supplier order
+LinkToSupplierProposal=Link to supplier proposal
+LinkToSupplierInvoice=Link to supplier invoice
+LinkToContract=Link to contract
+LinkToIntervention=Link to intervention
CreateDraft=Créer brouillon
SetToDraft=Retour en brouillon
ClickToEdit=Cliquer ici pour éditer
diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php
index 4af5b8a4d59..d1346088692 100644
--- a/htdocs/product/stock/productlot_card.php
+++ b/htdocs/product/stock/productlot_card.php
@@ -366,8 +366,8 @@ print ' | | '.$langs->trans("Fieldimport_key").' | showLinkedObjectBlock($object);
//$linktoelem = $form->showLinkToObjectBlock($object);
- //if ($linktoelem) print '
'.$linktoelem;
-
+ //if ($linktoelem) print ($somethingshown?'':'
').$linktoelem;
+
}
diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php
index 481981bdabd..e461d6d42ac 100644
--- a/htdocs/supplier_proposal/card.php
+++ b/htdocs/supplier_proposal/card.php
@@ -1809,9 +1809,10 @@ if ($action == 'create')
$somethingshown = $form->showLinkedObjectBlock($object);
// Show links to link elements
- //$linktoelem = $form->showLinkToObjectBlock($object);
- //if ($linktoelem) print '
'.$linktoelem;
+ $linktoelem = $form->showLinkToObjectBlock($object, null, array('supplier_proposal'));
+ if ($linktoelem) print ($somethingshown?'':'
').$linktoelem;
+
print '';
// List of actions on element