diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php
index cb72c321118..41cce96995f 100644
--- a/htdocs/accountancy/class/accountingjournal.class.php
+++ b/htdocs/accountancy/class/accountingjournal.class.php
@@ -29,7 +29,7 @@ class AccountingJournal extends CommonObject
public $element='accounting_journal';
public $table_element='accounting_journal';
public $fk_element = '';
- protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $rowid;
diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index 33be4abb8e6..81167eebc5e 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -43,7 +43,7 @@ class Adherent extends CommonObject
{
public $element='member';
public $table_element='adherent';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $mesgs;
diff --git a/htdocs/admin/modulehelp.php b/htdocs/admin/modulehelp.php
index ff0f7a58099..a7b461ea9b9 100644
--- a/htdocs/admin/modulehelp.php
+++ b/htdocs/admin/modulehelp.php
@@ -421,9 +421,13 @@ if ($mode == 'feature')
$i=0;
foreach($objMod->tabs as $val)
{
- $tmp=explode(':',$val,3);
- $text.=($i?', ':'').$tmp[0].':'.$tmp[1];
- $i++;
+ if (is_array($val)) $val=$val['data'];
+ if (is_string($val))
+ {
+ $tmp=explode(':',$val,3);
+ $text.=($i?', ':'').$tmp[0].':'.$tmp[1];
+ $i++;
+ }
}
}
else $text.=$langs->trans("No");
diff --git a/htdocs/bookmarks/class/bookmark.class.php b/htdocs/bookmarks/class/bookmark.class.php
index b72089e61b8..1beb4b36871 100644
--- a/htdocs/bookmarks/class/bookmark.class.php
+++ b/htdocs/bookmarks/class/bookmark.class.php
@@ -30,7 +30,7 @@ class Bookmark extends CommonObject
{
public $element='bookmark';
public $table_element='bookmark';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto = 'bookmark';
var $db;
diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index 36d551ea577..a89608654fd 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -36,7 +36,7 @@ class ActionComm extends CommonObject
public $element='action';
public $table_element = 'actioncomm';
public $table_rowid = 'id';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='action';
/**
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index 19e70235e9e..6827a3b0a4e 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -48,7 +48,7 @@ class Propal extends CommonObject
public $table_element='propal';
public $table_element_line='propaldet';
public $fk_element='fk_propal';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='propal';
/**
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index e475615a3d1..00032262c70 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -46,7 +46,7 @@ class Commande extends CommonOrder
public $table_element_line = 'commandedet';
public $class_element_line = 'OrderLine';
public $fk_element = 'fk_commande';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto = 'order';
/**
diff --git a/htdocs/compta/deplacement/class/deplacement.class.php b/htdocs/compta/deplacement/class/deplacement.class.php
index c0a4ef94613..c67fce127c2 100644
--- a/htdocs/compta/deplacement/class/deplacement.class.php
+++ b/htdocs/compta/deplacement/class/deplacement.class.php
@@ -35,7 +35,7 @@ class Deplacement extends CommonObject
public $table_element='deplacement';
public $table_element_line = '';
public $fk_element = '';
- protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $datec; // Creation date
var $dated;
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index a1997318aad..0104bfd903e 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -52,7 +52,7 @@ class Facture extends CommonInvoice
public $table_element='facture';
public $table_element_line = 'facturedet';
public $fk_element = 'fk_facture';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='bill';
/**
diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php
index 7e9437f5442..8dba39b4b54 100644
--- a/htdocs/contact/class/contact.class.php
+++ b/htdocs/contact/class/contact.class.php
@@ -39,7 +39,7 @@ class Contact extends CommonObject
{
public $element='contact';
public $table_element='socpeople';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $civility_id; // In fact we store civility_code
public $civility_code;
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index 5ff8dd182bb..86c85b19d0a 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -44,7 +44,7 @@ class Contrat extends CommonObject
public $table_element='contrat';
public $table_element_line='contratdet';
public $fk_element='fk_contrat';
- protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
+ public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto='contract';
/**
diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php
index 91d5b29dce6..c7e57641c29 100644
--- a/htdocs/core/actions_addupdatedelete.inc.php
+++ b/htdocs/core/actions_addupdatedelete.inc.php
@@ -46,7 +46,11 @@ if ($action == 'add' && ! empty($permissiontoadd))
{
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
- $object->$key=GETPOST($key,'alpha');
+ $value = GETPOST($key,'alpha');
+ if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field
+ if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field
+
+ $object->$key=$value;
if ($val['notnull'] > 0 && $object->$key == '')
{
$error++;
@@ -85,7 +89,11 @@ if ($action == 'update' && ! empty($permissiontoadd))
{
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue; // Ignore special fields
- $object->$key=GETPOST($key,'alpha');
+ $value = GETPOST($key,'alpha');
+ if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value=''; // This is an implicit foreign key field
+ if (! empty($object->fields[$key]['foreignkey']) && $value == '-1') $value=''; // This is an explicit foreign key field
+
+ $object->$key=$value;
if ($val['notnull'] > 0 && $object->$key == '')
{
$error++;
diff --git a/htdocs/core/ajax/selectobject.php b/htdocs/core/ajax/selectobject.php
new file mode 100644
index 00000000000..0c52c490512
--- /dev/null
+++ b/htdocs/core/ajax/selectobject.php
@@ -0,0 +1,86 @@
+
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/core/ajax/selectobject.php
+ * \brief File to return Ajax response on a selection list request
+ */
+
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
+if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
+if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
+if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
+if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
+if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
+
+require '../../main.inc.php';
+
+$objectdesc=GETPOST('objectdesc', 'alpha');
+$htmlname=GETPOST('htmlname', 'aZ09');
+$sqlfilter=GETPOST('sqlfilter', 'alpha');
+$outjson=(GETPOST('outjson', 'int') ? GETPOST('outjson', 'int') : 0);
+$action=GETPOST('action', 'alpha');
+$id=GETPOST('id', 'int');
+
+
+/*
+ * View
+ */
+
+//print ''."\n";
+
+dol_syslog(join(',', $_GET));
+//print_r($_GET);
+
+
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+$form = new Form($db);
+
+//$langs->load("companies");
+
+top_httphead();
+
+if (empty($htmlname)) return;
+
+
+$InfoFieldList = explode(":", $objectdesc);
+$classname=$InfoFieldList[0];
+$classpath=$InfoFieldList[1];
+if (! empty($classpath))
+{
+ dol_include_once($classpath);
+ if ($classname && class_exists($classname))
+ {
+ $objecttmp = new $classname($db);
+ }
+}
+if (! is_object($objecttmp))
+{
+ dol_syslog('Error bad param objectdesc', LOG_WARNING);
+ print 'Error bad param objectdesc';
+}
+
+// When used from jQuery, the search term is added as GET param "term".
+$searchkey=(($id && GETPOST($id, 'alpha'))?GETPOST($id, 'alpha'):(($htmlname && GETPOST($htmlname, 'alpha'))?GETPOST($htmlname, 'alpha'):''));
+
+// TODO Add a security test to avoid to get content of all tables
+
+$arrayresult=$form->selectForFormsList($objecttmp, $htmlname, '', 0, $searchkey, '', '', '', 0, 1);
+
+$db->close();
+
+if ($outjson) print json_encode($arrayresult);
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index fb42e1bfbde..8f2842b4651 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -4663,12 +4663,19 @@ abstract class CommonObject
* @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names)
* @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names)
* @param mixed $showsize Value for css to define size. May also be a numeric.
- * @param int $objectid Current object id
* @return string
*/
- function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0, $objectid=0)
+ function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0)
{
- global $conf,$langs;
+ global $conf,$langs,$form;
+
+ if (! is_object($form))
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
+ $form=new Form($this->db);
+ }
+
+ $objectid = $this->id;
$label=$val['label'];
$type =$val['type'];
@@ -4696,7 +4703,6 @@ abstract class CommonObject
$hidden=(abs($val['visible'])!=1 ? 1 : 0);
$help=$val['help'];
-
if ($computed)
{
if (! preg_match('/^search_/', $keyprefix)) return ''.$langs->trans("AutomaticallyCalculated").'';
@@ -4756,10 +4762,6 @@ abstract class CommonObject
// Do not show current date when field not required (see select_date() method)
if (!$required && $value == '') $value = '-1';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
- global $form;
- if (! is_object($form)) $form=new Form($this->db);
-
// TODO Must also support $moreparam
$out = $form->select_date($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1);
}
@@ -4817,7 +4819,7 @@ abstract class CommonObject
}
$out.='