diff --git a/dev/skeletons/skeleton_page.php b/dev/skeletons/skeleton_page.php
index ac329318ae5..482208e8ab1 100644
--- a/dev/skeletons/skeleton_page.php
+++ b/dev/skeletons/skeleton_page.php
@@ -353,7 +353,7 @@ if ($id && (empty($action) || $action == 'view'))
// Example 2 : Adding links to objects
// The class must extends CommonObject class to have this method available
- //$somethingshown=$object->showLinkedObjectBlock();
+ //$somethingshown=$form->showLinkedObjectBlock($object);
}
diff --git a/htdocs/cashdesk/admin/cashdesk.php b/htdocs/cashdesk/admin/cashdesk.php
index a8ef98b0b0b..48804958b20 100644
--- a/htdocs/cashdesk/admin/cashdesk.php
+++ b/htdocs/cashdesk/admin/cashdesk.php
@@ -102,7 +102,7 @@ print "\n";
$var=!$var;
print '
| '.$langs->trans("CashDeskIdWareHouse").' | '; // Force warehouse (this is not a default value)
print '';
diff --git a/htdocs/comm/askpricesupplier/card.php b/htdocs/comm/askpricesupplier/card.php
index 6759ae22196..939d874a0f2 100644
--- a/htdocs/comm/askpricesupplier/card.php
+++ b/htdocs/comm/askpricesupplier/card.php
@@ -1712,7 +1712,7 @@ if ($action == 'create')
/*
* Linked object block
*/
- $somethingshown = $object->showLinkedObjectBlock();
+ $somethingshown = $form->showLinkedObjectBlock($object);
print '';
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index ce22d192f81..ccdcd850493 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -2310,7 +2310,7 @@ if ($action == 'create')
/*
* Linked object block
*/
- $somethingshown = $object->showLinkedObjectBlock();
+ $somethingshown = $form->showLinkedObjectBlock($object);
print ' | ';
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index fcd96f8c898..04ea05d3f5d 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -2308,7 +2308,7 @@ if ($action == 'create' && $user->rights->commande->creer)
/*
* Linked object block
*/
- $somethingshown = $object->showLinkedObjectBlock();
+ $somethingshown = $form->showLinkedObjectBlock($object);
print ' | ';
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 379d2d2ee5d..3abe4fc6c99 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3776,7 +3776,7 @@ if ($action == 'create')
$somethingshown = $formfile->numoffiles;
// Linked object block
- $somethingshown = $object->showLinkedObjectBlock();
+ $somethingshown = $form->showLinkedObjectBlock($object);
$linktoelem='';
diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index 192a2d16b17..3df24e4e667 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -1874,7 +1874,7 @@ else
/*
* Linked object block
*/
- $somethingshown=$object->showLinkedObjectBlock();
+ $somethingshown=$form->showLinkedObjectBlock($object);
print '';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 4c511726979..3ea0e010eb5 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -135,8 +135,8 @@ abstract class CommonObject
$sql = "SELECT rowid, ref, ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX.$element;
- $sql.= " WHERE entity IN (".getEntity($element).")" ;
-
+ $sql.= " WHERE entity IN (".getEntity($element).")" ;
+
if ($id > 0) $sql.= " AND rowid = ".$db->escape($id);
else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'";
else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
@@ -2580,88 +2580,19 @@ abstract class CommonObject
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions
// --------------------
- /* This is to show linked object block */
-
/**
- * Show linked object block
- * TODO Move this into html.class.php
- * But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
+ * Show linked object block.
*
- * @return int
+ * @return int <0 if KO, >0 if OK
+ * @deprecated Use instead $form->shoLinkedObjectBlock($object)
*/
function showLinkedObjectBlock()
{
- global $conf,$langs,$hookmanager;
- global $bc;
-
- $this->fetchObjectLinked();
-
- // Bypass the default method
- $hookmanager->initHooks(array('commonobject'));
- $parameters=array();
- $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$this,$action); // Note that $action and $object may have been modified by hook
-
- if (empty($reshook))
- {
- $num = count($this->linkedObjects);
-
- foreach($this->linkedObjects as $objecttype => $objects)
- {
- $tplpath = $element = $subelement = $objecttype;
-
- if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
- $tplpath = $element.'/'.$subelement;
- }
-
- // To work with non standard path
- if ($objecttype == 'facture') {
- $tplpath = 'compta/'.$element;
- if (empty($conf->facture->enabled)) continue; // Do not show if module disabled
- }
- else if ($objecttype == 'propal') {
- $tplpath = 'comm/'.$element;
- if (empty($conf->propal->enabled)) continue; // Do not show if module disabled
- }
- else if ($objecttype == 'askpricesupplier') {
- $tplpath = 'comm/'.$element;
- if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled
- }
- else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
- $tplpath = 'expedition';
- if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
- }
- else if ($objecttype == 'delivery') {
- $tplpath = 'livraison';
- if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
- }
- else if ($objecttype == 'invoice_supplier') {
- $tplpath = 'fourn/facture';
- }
- else if ($objecttype == 'order_supplier') {
- $tplpath = 'fourn/commande';
- }
-
- global $linkedObjectBlock;
- $linkedObjectBlock = $objects;
-
- // Output template part (modules that overwrite templates must declare this into descriptor)
- $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl'));
- foreach($dirtpls as $reldir)
- {
- $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php');
- if ($res) break;
- }
- }
-
- return $num;
- }
+ global $form;
+ return $form->showLinkedObjectBlock($this);
}
-
/* This is to show add lines */
/**
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index bdb4f57a4cc..dfb310c20f8 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -803,11 +803,28 @@ class Form
* @param array $ajaxoptions Options for ajax_autocompleter
* @param int $forcecombo Force to use combo box
* @return string Return select box for thirdparty.
+ * @deprecated Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0)
*/
function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0)
{
- global $langs,$conf;
+ return $this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit);
+ }
+ /**
+ * Output html form to select a third party
+ *
+ * @param string $selected Preselected type
+ * @param string $htmlname Name of field in form
+ * @param string $filter optional filters criteras (example: 's.rowid <> x')
+ * @param int $showempty Add an empty field
+ * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
+ * @param int $forcecombo Force to use combo box
+ * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
+ * @param int $limit Maximum number of elements
+ * @return string HTML string with select box for thirdparty.
+ */
+ function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0)
+ {
$out='';
/* TODO Use ajax_autocompleter like for products (not finished)
@@ -840,32 +857,12 @@ class Form
}
else
{*/
- $out.=$this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit);
+ $out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit);
//}
return $out;
}
- /**
- * Output html form to select a third party
- *
- * @param string $selected Preselected type
- * @param string $htmlname Name of field in form
- * @param string $filter optional filters criteras (example: 's.rowid <> x')
- * @param int $showempty Add an empty field
- * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
- * @param int $forcecombo Force to use combo box
- * @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
- * @param int $limit Maximum number of elements
- * @return string HTML string with
- * @deprecated Use select_thirdparty instead
- * @see select_thirdparty()
- */
- function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0)
- {
- return $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit);
- }
-
/**
* Output html form to select a third party
*
@@ -4620,6 +4617,84 @@ class Form
}
+ /**
+ * Show linked object block.
+ *
+ * @param CommonObject $object Object we want to show links to
+ * @return int <0 if KO, >0 if OK
+ */
+ function showLinkedObjectBlock($object)
+ {
+ global $conf,$langs,$hookmanager;
+ global $bc;
+
+ $object->fetchObjectLinked();
+
+ // Bypass the default method
+ $hookmanager->initHooks(array('commonobject'));
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
+ if (empty($reshook))
+ {
+ $num = count($object->linkedObjects);
+
+ foreach($object->linkedObjects as $objecttype => $objects)
+ {
+ $tplpath = $element = $subelement = $objecttype;
+
+ if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
+ {
+ $element = $regs[1];
+ $subelement = $regs[2];
+ $tplpath = $element.'/'.$subelement;
+ }
+
+ // To work with non standard path
+ if ($objecttype == 'facture') {
+ $tplpath = 'compta/'.$element;
+ if (empty($conf->facture->enabled)) continue; // Do not show if module disabled
+ }
+ else if ($objecttype == 'propal') {
+ $tplpath = 'comm/'.$element;
+ if (empty($conf->propal->enabled)) continue; // Do not show if module disabled
+ }
+ else if ($objecttype == 'askpricesupplier') {
+ $tplpath = 'comm/'.$element;
+ if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled
+ }
+ else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
+ $tplpath = 'expedition';
+ if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
+ }
+ else if ($objecttype == 'delivery') {
+ $tplpath = 'livraison';
+ if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
+ }
+ else if ($objecttype == 'invoice_supplier') {
+ $tplpath = 'fourn/facture';
+ }
+ else if ($objecttype == 'order_supplier') {
+ $tplpath = 'fourn/commande';
+ }
+
+ global $linkedObjectBlock;
+ $linkedObjectBlock = $objects;
+
+ // Output template part (modules that overwrite templates must declare this into descriptor)
+ $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl'));
+ foreach($dirtpls as $reldir)
+ {
+ $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php');
+ if ($res) break;
+ }
+ }
+
+ return $num;
+ }
+ }
+
+
/**
* Return an html string with a select combo box to choose yes or no
*
diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php
index 8ebdc547cc8..fd2a3cd4099 100644
--- a/htdocs/core/lib/agenda.lib.php
+++ b/htdocs/core/lib/agenda.lib.php
@@ -103,7 +103,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh
print ' ';
print $langs->trans("ThirdParty").' ';
print ' | ';
- print $form->select_thirdparty($socid, 'socid');
+ print $form->select_company($socid, 'socid');
print ' | |
';
}
diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php
index 2475f420dd0..85380907bbf 100644
--- a/htdocs/expedition/card.php
+++ b/htdocs/expedition/card.php
@@ -1505,7 +1505,7 @@ else if ($id || $ref)
/*
* Linked object block
*/
- $somethingshown=$object->showLinkedObjectBlock();
+ $somethingshown=$form->showLinkedObjectBlock($object);
if ($genallowed && ! $somethingshown) $somethingshown=1;
diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php
index dac78d9ae3b..ad224ab9fe2 100644
--- a/htdocs/fichinter/card.php
+++ b/htdocs/fichinter/card.php
@@ -1019,7 +1019,7 @@ if ($action == 'create')
print '