';
+ $ret .= '
';
if ($search_component_params_hidden) {
// Split the criteria on each AND
@@ -10804,6 +10804,27 @@ class Form
// We repost the form
$(this).closest(\'form\').submit();
});
+
+ jQuery("#search_component_params_input").keydown(function(e) {
+ console.log("We press a key on the filter field that is "+jQuery("#search_component_params_input").val());
+ console.log(e.which);
+ if (jQuery("#search_component_params_input").val() == "" && e.which == 8) {
+ /* We click on back when the input field is already empty */
+ event.preventDefault();
+ jQuery("#divsearch_component_params .tagsearch").last().remove();
+ /* Regenerate content of search_component_params_hidden from remaining .tagsearch */
+ var s = "";
+ jQuery("#divsearch_component_params .tagsearch").each(function( index ) {
+ if (s != "") {
+ s = s + " AND ";
+ }
+ s = s + $(this).attr("data-ufilter");
+ });
+ console.log("New value for search_component_params_hidden = "+s);
+ jQuery("#search_component_params_hidden").val(s);
+ }
+ });
+
';
diff --git a/htdocs/core/class/link.class.php b/htdocs/core/class/link.class.php
index b8a54ec53c7..34f05db4c11 100644
--- a/htdocs/core/class/link.class.php
+++ b/htdocs/core/class/link.class.php
@@ -237,7 +237,7 @@ class Link extends CommonObject
$sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix()."links";
$sql .= " WHERE objecttype = '".$this->db->escape($objecttype)."' AND objectid = ".((int) $objectid);
if ($conf->entity != 0) {
- $sql .= " AND entity = ".$conf->entity;
+ $sql .= " AND entity = ".((int) $conf->entity);
}
if ($sortfield) {
if (empty($sortorder)) {
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index 9d7b2222040..d07f1960e15 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -1840,6 +1840,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess
// var_dump($result);exit;
if ($result >= 0) {
$TFile = $_FILES[$varfiles];
+ // Convert value of $TFile
if (!is_array($TFile['name'])) {
foreach ($TFile as $key => &$val) {
$val = array($val);
@@ -1854,13 +1855,13 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess
}
// Define $destfull (path to file including filename) and $destfile (only filename)
- $destfull = $upload_dir."/".$TFile['name'][$i];
- $destfile = $TFile['name'][$i];
+ $destfile = trim($TFile['name'][$i]);
+ $destfull = $upload_dir."/".$destfile;
$destfilewithoutext = preg_replace('/\.[^\.]+$/', '', $destfile);
if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
- $destfull = $upload_dir."/".preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
- $destfile = preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
+ $destfile = trim(preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask));
+ $destfull = $upload_dir."/".$destfile;
}
$filenameto = basename($destfile);
@@ -1869,7 +1870,6 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess
setEventMessages($langs->trans("ErrorFilenameCantStartWithDot", $filenameto), null, 'errors');
break;
}
-
// dol_sanitizeFileName the file name and lowercase extension
$info = pathinfo($destfull);
$destfull = $info['dirname'].'/'.dol_sanitizeFileName($info['filename'].($info['extension'] != '' ? ('.'.strtolower($info['extension'])) : ''));
@@ -2307,7 +2307,7 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz", &$errorstring
// Zip archive will be created only after closing object
$zip->close();
- dol_syslog("dol_compress_file success - ".count($zip->numFiles)." files");
+ dol_syslog("dol_compress_file success - ".$zip->numFiles." files");
return 1;
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 57f785261ea..556917bc2a0 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4369,7 +4369,7 @@ function dol_substr($string, $start, $length = null, $stringencoding = '', $trun
global $langs;
if (empty($stringencoding)) {
- $stringencoding = $langs->charset_output;
+ $stringencoding = (empty($langs) ? 'UTF-8' : $langs->charset_output);
}
$ret = '';
diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php
index 9e6a39c63f9..faf5068d403 100644
--- a/htdocs/core/lib/invoice.lib.php
+++ b/htdocs/core/lib/invoice.lib.php
@@ -177,7 +177,7 @@ function invoice_admin_prepare_head()
$h = 0;
$head = array();
- $head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
+ $head[$h][0] = DOL_URL_ROOT.'/admin/invoice.php';
$head[$h][1] = $langs->trans("Miscellaneous");
$head[$h][2] = 'general';
$h++;
@@ -193,7 +193,7 @@ function invoice_admin_prepare_head()
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
- $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
+ $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoice_cust_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
$nbExtrafields = $extrafields->attributes['facture']['count'];
if ($nbExtrafields > 0) {
@@ -202,7 +202,7 @@ function invoice_admin_prepare_head()
$head[$h][2] = 'attributes';
$h++;
- $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
+ $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoicedet_cust_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsLines");
$nbExtrafields = $extrafields->attributes['facturedet']['count'];
if ($nbExtrafields > 0) {
@@ -211,7 +211,7 @@ function invoice_admin_prepare_head()
$head[$h][2] = 'attributeslines';
$h++;
- $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_rec_cust_extrafields.php';
+ $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoice_rec_cust_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
$nbExtrafields = $extrafields->attributes['facture_rec']['count'];
if ($nbExtrafields > 0) {
@@ -220,7 +220,7 @@ function invoice_admin_prepare_head()
$head[$h][2] = 'attributesrec';
$h++;
- $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_rec_cust_extrafields.php';
+ $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoicedet_rec_cust_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
$nbExtrafields = $extrafields->attributes['facturedet_rec']['count'];
if ($nbExtrafields > 0) {
@@ -230,7 +230,7 @@ function invoice_admin_prepare_head()
$h++;
if (getDolGlobalInt('INVOICE_USE_SITUATION') > 0) { // Warning, implementation with value 1 is seriously bugged and a new one not compatible is expected to become stable
- $head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php';
+ $head[$h][0] = DOL_URL_ROOT.'/admin/invoice_situation.php';
$head[$h][1] = $langs->trans("InvoiceSituation");
$head[$h][2] = 'situation';
$h++;
diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php
index 4d90ba8252b..7cd9dacaefa 100644
--- a/htdocs/core/modules/modFacture.class.php
+++ b/htdocs/core/modules/modFacture.class.php
@@ -73,7 +73,7 @@ class modFacture extends DolibarrModules
$this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text')
// Config pages
- $this->config_page_url = array("facture.php");
+ $this->config_page_url = array("invoice.php");
// Constants
$this->const = array();
diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php
index b9fef39837f..b3b8177be87 100644
--- a/htdocs/cron/class/cronjob.class.php
+++ b/htdocs/cron/class/cronjob.class.php
@@ -513,16 +513,16 @@ class Cronjob extends CommonObject
/**
* Load list of cron jobs in a memory array from the database
*
- * @param string $sortorder sort order
- * @param string $sortfield sort field
- * @param int $limit limit page
- * @param int $offset page
- * @param int $status display active or not
- * @param array $filter filter output
- * @param int $processing Processing or not
- * @return int if KO: <0 || if OK: >0
+ * @param string $sortorder Sort order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit page
+ * @param int $offset Offset ppage
+ * @param int $status Display active or not
+ * @param string|array $filter Filter USF.
+ * @param int $processing Processing or not
+ * @return int if KO: <0 || if OK: >0
*/
- public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowid', int $limit = 0, int $offset = 0, int $status = 1, array $filter = [], int $processing = -1)
+ public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowid', int $limit = 0, int $offset = 0, int $status = 1, $filter = '', int $processing = -1)
{
$this->lines = array();
@@ -573,14 +573,27 @@ class Cronjob extends CommonObject
}
// Manage filter
- if (is_array($filter) && count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.rowid') {
- $sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value);
- } else {
- $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value);
+ } else {
+ $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
}
+
+ $filter = '';
+ }
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
$sql .= $this->db->order($sortfield, $sortorder);
diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php
index 0f622d01370..de254170431 100644
--- a/htdocs/ecm/class/ecmfiles.class.php
+++ b/htdocs/ecm/class/ecmfiles.class.php
@@ -530,15 +530,15 @@ class EcmFiles extends CommonObject
/**
* Load object in memory from the database
*
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset offset limit
- * @param array $filter filter array
- * @param string $filtermode filter mode (AND or OR)
- * @return int Return integer <0 if KO, >0 if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset limit
+ * @param string|array $filter filter array
+ * @param string $filtermode filter mode (AND or OR)
+ * @return int Return integer <0 if KO, >0 if OK
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -564,27 +564,40 @@ class EcmFiles extends CommonObject
$sql .= " t.src_object_type,";
$sql .= " t.src_object_id";
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
+ $sql .= ' WHERE 1 = 1';
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.src_object_id') {
- $sqlwhere[] = $key." = ".((int) $value);
- } else {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.src_object_id') {
+ $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
+ } else {
+ $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
}
+ if (count($sqlwhere) > 0) {
+ $sql .= ' AND '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
+ }
+
+ $filter = '';
+ }
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
- $sql .= ' WHERE 1 = 1';
/* Fetching this table depends on filepath+filename, it must not depends on entity
if (isModEnabled('multicompany')) {
$sql .= " AND entity IN (" . getEntity('ecmfiles') . ")";
}*/
- if (count($sqlwhere) > 0) {
- $sql .= ' AND '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
- }
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
diff --git a/htdocs/knowledgemanagement/class/knowledgerecord.class.php b/htdocs/knowledgemanagement/class/knowledgerecord.class.php
index 5e6ed1b5ebb..530395f5bf6 100644
--- a/htdocs/knowledgemanagement/class/knowledgerecord.class.php
+++ b/htdocs/knowledgemanagement/class/knowledgerecord.class.php
@@ -369,18 +369,16 @@ class KnowledgeRecord extends CommonObject
/**
* Load list of objects in memory from the database.
*
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset Offset
- * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
- * @param string $filtermode Filter mode (AND or OR)
- * @return array|int int <0 if KO, array of pages if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset
+ * @param string|array $filter Filter USF.
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
- global $conf;
-
dol_syslog(__METHOD__, LOG_DEBUG);
$records = array();
@@ -393,23 +391,37 @@ class KnowledgeRecord extends CommonObject
} else {
$sql .= ' WHERE 1 = 1';
}
+
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.rowid') {
- $sqlwhere[] = $key." = ".((int) $value);
- } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
- $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
- } elseif (strpos($value, '%') === false) {
- $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
- } else {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
+ } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $this->db->sanitize($key).' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
}
+ if (count($sqlwhere) > 0) {
+ $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+ }
+
+ $filter = '';
}
- if (count($sqlwhere) > 0) {
- $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
if (!empty($sortfield)) {
diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php
index 13e7e3d46d0..906cdc3d0e2 100644
--- a/htdocs/modulebuilder/template/class/myobject.class.php
+++ b/htdocs/modulebuilder/template/class/myobject.class.php
@@ -468,7 +468,7 @@ class MyObject extends CommonObject
$sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
if ($errormessage) {
$this->errors[] = $errormessage;
- dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
return -1;
}
@@ -502,7 +502,7 @@ class MyObject extends CommonObject
return $records;
} else {
$this->errors[] = 'Error '.$this->db->lasterror();
- dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
return -1;
}
diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php
index 4b91802fd5a..6af9a6941d9 100644
--- a/htdocs/mrp/class/mo.class.php
+++ b/htdocs/mrp/class/mo.class.php
@@ -474,15 +474,15 @@ class Mo extends CommonObject
/**
* Load list of objects in memory from the database.
*
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset Offset
- * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
- * @param string $filtermode Filter mode (AND or OR)
- * @return array|int int <0 if KO, array of pages if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset
+ * @param string|array $filter Filter USF.
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -496,21 +496,35 @@ class Mo extends CommonObject
} else {
$sql .= ' WHERE 1 = 1';
}
+
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.rowid') {
- $sqlwhere[] = $key." = ".((int) $value);
- } elseif (strpos($key, 'date') !== false) {
- $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
- } else {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
+ } elseif (strpos($key, 'date') !== false) {
+ $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
+ } else {
+ $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
}
+ if (count($sqlwhere) > 0) {
+ $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+ }
+
+ $filter = '';
}
- if (count($sqlwhere) > 0) {
- $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
if (!empty($sortfield)) {
diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php
index 1b47c556e7f..525214a4398 100644
--- a/htdocs/partnership/class/partnership.class.php
+++ b/htdocs/partnership/class/partnership.class.php
@@ -424,15 +424,15 @@ class Partnership extends CommonObject
/**
* Load list of objects in memory from the database.
*
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset Offset
- * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
- * @param string $filtermode Filter mode (AND or OR)
- * @return array|int int <0 if KO, array of pages if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset page
+ * @param string|array $filter Filter USF.
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -446,23 +446,37 @@ class Partnership extends CommonObject
} else {
$sql .= ' WHERE 1 = 1';
}
+
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.rowid') {
- $sqlwhere[] = $key." = ".((int) $value);
- } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
- $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
- } elseif (strpos($value, '%') === false) {
- $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
- } else {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $this->db->sanitize($key)." = ".((int) $value);
+ } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $this->db->sanitize($key)." = '".$this->db->idate($value)."'";
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $this->db->sanitize($key)." IN (".$this->db->sanitize($this->db->escape($value)).")";
+ } else {
+ $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
}
+ if (count($sqlwhere) > 0) {
+ $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+ }
+
+ $filter = '';
}
- if (count($sqlwhere) > 0) {
- $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
if (!empty($sortfield)) {
diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php
index 39dda63688f..224de17eb28 100644
--- a/htdocs/product/class/productcustomerprice.class.php
+++ b/htdocs/product/class/productcustomerprice.class.php
@@ -368,15 +368,15 @@ class ProductCustomerPrice extends CommonObject
/**
* Load all customer prices in memory from database
*
- * @param string $sortorder order
- * @param string $sortfield field
- * @param int $limit page
- * @param int $offset offset
- * @param array $filter Filter for select
- * @return int Return integer <0 if KO, >0 if OK
+ * @param string $sortorder Sort order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit page
+ * @param int $offset offset
+ * @param string|array $filter Filter USF.
+ * @return int Return integer <0 if KO, >0 if OK
* @since dolibarr v17
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = array())
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '')
{
if (empty($sortfield)) {
$sortfield = "t.rowid";
@@ -418,21 +418,35 @@ class ProductCustomerPrice extends CommonObject
$sql .= " AND t.entity IN (".getEntity('productprice').")";
// Manage filter
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
- $sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape($value)."'";
- } elseif ($key == 'soc.nom') {
- $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
- } elseif ($key == 'prod.ref' || $key == 'prod.label') {
- $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
- } elseif ($key == 't.price' || $key == 't.price_ttc') {
- $sql .= " AND ".$this->db->sanitize($key)." = ".((float) price2num($value));
- } else {
- $sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value);
+ if (is_array($filter)) {
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
+ $sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape($value)."'";
+ } elseif ($key == 'soc.nom') {
+ $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ } elseif ($key == 'prod.ref' || $key == 'prod.label') {
+ $sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ } elseif ($key == 't.price' || $key == 't.price_ttc') {
+ $sql .= " AND ".$this->db->sanitize($key)." = ".((float) price2num($value));
+ } else {
+ $sql .= " AND ".$this->db->sanitize($key)." = ".((int) $value);
+ }
}
}
+
+ $filter = '';
}
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
+ }
+
$sql .= $this->db->order($sortfield, $sortorder);
if (!empty($limit)) {
$sql .= $this->db->plimit($limit + 1, $offset);
diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php
index b0a30b3d41a..dae70705c88 100644
--- a/htdocs/product/class/productfournisseurprice.class.php
+++ b/htdocs/product/class/productfournisseurprice.class.php
@@ -318,18 +318,16 @@ class ProductFournisseurPrice extends CommonObject
/**
* Load list of objects in memory from the database.
*
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset Offset
- * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
- * @param string $filtermode Filter mode (AND or OR)
- * @return array|int int <0 if KO, array of pages if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset
+ * @param string|array $filter Filter USF.
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
- global $conf;
-
dol_syslog(__METHOD__, LOG_DEBUG);
$records = array();
@@ -342,23 +340,37 @@ class ProductFournisseurPrice extends CommonObject
} else {
$sql .= " WHERE 1 = 1";
}
+
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- if ($key == 't.rowid') {
- $sqlwhere[] = $key." = ".((int) $value);
- } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
- $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
- } elseif (strpos($value, '%') === false) {
- $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
- } else {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ if ($key == 't.rowid') {
+ $sqlwhere[] = $key." = ".((int) $value);
+ } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
+ $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
+ } elseif (strpos($value, '%') === false) {
+ $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')';
+ } else {
+ $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
}
+ if (count($sqlwhere) > 0) {
+ $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+ }
+
+ $filter = '';
}
- if (count($sqlwhere) > 0) {
- $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
if (!empty($sortfield)) {
diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php
index a8937fced52..87b8ba077d1 100644
--- a/htdocs/product/stock/class/productstockentrepot.class.php
+++ b/htdocs/product/stock/class/productstockentrepot.class.php
@@ -232,15 +232,15 @@ class ProductStockEntrepot extends CommonObject
*
* @param int $fk_product Product from which we want to get limit and desired stock by warehouse
* @param int $fk_entrepot Warehouse in which we want to get products limit and desired stock
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit limit
- * @param int $offset offset limit
- * @param array $filter filter array
- * @param string $filtermode filter mode (AND or OR)
- * @return int|array Return integer <0 if KO, array if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset limit
+ * @param string|array $filter Filter USF.
+ * @param string $filtermode Filter mode (AND or OR)
+ * @return int|array Return integer <0 if KO, array if OK
*/
- public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -256,14 +256,27 @@ class ProductStockEntrepot extends CommonObject
$sql .= " WHERE 1=1";
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ $sqlwhere[] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
+ }
}
+ if (count($sqlwhere) > 0) {
+ $sql .= " AND ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
+ }
+
+ $filter = '';
}
- if (count($sqlwhere) > 0) {
- $sql .= " AND ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
if (!empty($fk_product) && $fk_product > 0) {
diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php
index e679a3e180f..d4d8f9135d7 100644
--- a/htdocs/public/payment/newpayment.php
+++ b/htdocs/public/payment/newpayment.php
@@ -1258,7 +1258,7 @@ if ($source == 'invoice') {
// Tag
print '
| '.$langs->trans("PaymentCode");
print ' | '.$fulltag.'';
- print '';
+ print '';
print '';
print ' |
'."\n";
diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php
index cce2244df42..2e15cc1ad18 100644
--- a/htdocs/resource/class/dolresource.class.php
+++ b/htdocs/resource/class/dolresource.class.php
@@ -599,14 +599,14 @@ class Dolresource extends CommonObject
/**
* Load resource objects into $this->lines
*
- * @param string $sortorder sort order
- * @param string $sortfield sort field
- * @param int $limit limit page
- * @param int $offset page
- * @param array $filter filter output
- * @return int if KO: <0 || if OK number of lines loaded
+ * @param string $sortorder Sort order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit page
+ * @param int $offset Offset page
+ * @param string|array $filter Filter USF.
+ * @return int If KO: <0 || if OK number of lines loaded
*/
- public function fetchAll(string $sortorder, string $sortfield, int $limit, int $offset, array $filter = [])
+ public function fetchAll(string $sortorder, string $sortfield, int $limit, int $offset, $filter = '')
{
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
@@ -641,16 +641,27 @@ class Dolresource extends CommonObject
$sql .= " WHERE t.entity IN (".getEntity('resource').")";
// Manage filter
- if (!empty($filter)) {
+ if (is_array($filter)) {
foreach ($filter as $key => $value) {
if (strpos($key, 'date')) {
$sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->idate($value)."'";
} elseif (strpos($key, 'ef.') !== false) {
- $sql .= ((float) $value);
+ $sql .= " AND ".$this->db->sanitize($key)." = ".((float) $value);
} else {
$sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
}
}
+
+ $filter = '';
+ }
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
$sql .= $this->db->order($sortfield, $sortorder);
diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php
index 5b29d73fefb..7b85ba94863 100644
--- a/htdocs/societe/card.php
+++ b/htdocs/societe/card.php
@@ -1748,7 +1748,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($canvasdisplayactio
print '';
$userlist = $form->select_dolusers('', '', 0, null, 0, '', '', '0', 0, 0, 'AND u.statut = 1', 0, '', '', 0, 2);
// Note: If user has no right to "see all thirdparties", we force selection of sale representative to him, so after creation he can see the record.
- $selected = (count(GETPOSTINT('commercial')) > 0 ? GETPOSTINT('commercial') : (GETPOSTINT('commercial') > 0 ? array(GETPOSTINT('commercial')) : (!$user->hasRight('societe', 'client', 'voir') ? array($user->id) : array())));
+ $selected = (GETPOSTISARRAY('commercial') ? GETPOST('commercial', 'array:int') : (GETPOSTINT('commercial') > 0 ? array(GETPOSTINT('commercial')) : (!$user->hasRight('societe', 'client', 'voir') ? array($user->id) : array())));
print img_picto('', 'user').$form->multiselectarray('commercial', $userlist, $selected, null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
print ' | ';
diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php
index 4980565b264..c4435e13cae 100644
--- a/htdocs/ticket/class/ticket.class.php
+++ b/htdocs/ticket/class/ticket.class.php
@@ -782,16 +782,16 @@ class Ticket extends CommonObject
/**
* Load all objects in memory from database
*
- * @param User $user User for action
- * @param string $sortorder Sort order
- * @param string $sortfield Sort field
- * @param int $limit page number
- * @param int $offset Offset for query
- * @param int $arch archive or not (not used)
- * @param array $filter Filter for query
- * @return int Return integer <0 if KO, >0 if OK
+ * @param User $user User for action
+ * @param string $sortorder Sort order
+ * @param string $sortfield Sort field
+ * @param int $limit Limit
+ * @param int $offset Offset page
+ * @param int $arch Archive or not (not used)
+ * @param string|array $filter Filter for query
+ * @return int Return integer <0 if KO, >0 if OK
*/
- public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $limit = 0, $offset = 0, $arch = 0, $filter = [])
+ public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $limit = 0, $offset = 0, $arch = 0, $filter = '')
{
global $langs, $extrafields;
@@ -845,7 +845,7 @@ class Ticket extends CommonObject
$sql .= " WHERE t.entity IN (".getEntity('ticket').")";
// Manage filter
- if (!empty($filter)) {
+ if (is_array($filter)) {
foreach ($filter as $key => $value) {
if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
$sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape($value)."'";
@@ -863,6 +863,17 @@ class Ticket extends CommonObject
$sql .= " AND ".$this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
}
}
+
+ $filter = '';
+ }
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
// Case of external user
diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php
index a4b80193d02..47d572654be 100644
--- a/htdocs/website/class/website.class.php
+++ b/htdocs/website/class/website.class.php
@@ -403,15 +403,15 @@ class Website extends CommonObject
/**
* Load all object in memory ($this->records) from the database
*
- * @param string $sortorder Sort Order
- * @param string $sortfield Sort field
- * @param int $limit offset limit
- * @param int $offset offset limit
- * @param array $filter filter array
- * @param string $filtermode filter mode (AND or OR)
- * @return array|int int <0 if KO, array of pages if OK
+ * @param string $sortorder Sort Order
+ * @param string $sortfield Sort field
+ * @param int $limit limit
+ * @param int $offset offset limit
+ * @param string|array $filter filter array
+ * @param string $filtermode filter mode (AND or OR)
+ * @return array|int int <0 if KO, array of pages if OK
*/
- public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
+ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
dol_syslog(__METHOD__, LOG_DEBUG);
@@ -433,15 +433,29 @@ class Website extends CommonObject
$sql .= " t.tms as date_modification";
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
$sql .= " WHERE t.entity IN (".getEntity('website').")";
+
// Manage filter
- $sqlwhere = array();
- if (count($filter) > 0) {
- foreach ($filter as $key => $value) {
- $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
+ if (is_array($filter)) {
+ $sqlwhere = array();
+ if (count($filter) > 0) {
+ foreach ($filter as $key => $value) {
+ $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
+ }
}
+ if (count($sqlwhere) > 0) {
+ $sql .= ' AND '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
+ }
+
+ $filter = '';
}
- if (count($sqlwhere) > 0) {
- $sql .= ' AND '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
+
+ // Manage filter
+ $errormessage = '';
+ $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
+ if ($errormessage) {
+ $this->errors[] = $errormessage;
+ dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
+ return -1;
}
if (!empty($sortfield)) {
diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php
index fd684229dd1..7a0a42a0f9f 100644
--- a/htdocs/website/class/websitepage.class.php
+++ b/htdocs/website/class/websitepage.class.php
@@ -515,6 +515,7 @@ class WebsitePage extends CommonObject
$sql = 'SELECT COUNT(t.rowid) as nb';
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.fk_website = '.((int) $websiteid);
+
// Manage filter (same than into fetchAll)
$sqlwhere = array();
if (count($filter) > 0) {
diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php
index 9848ac2185e..633b0b61216 100644
--- a/test/phpunit/AllTests.php
+++ b/test/phpunit/AllTests.php
@@ -27,8 +27,10 @@
print "PHP Version: ".phpversion()."\n";
print "Memory limit: ". ini_get('memory_limit')."\n";
-// Workaround for false security issue with main.inc.php in tests:
-$_SERVER['PHP_SELF'] = "phpunit";
+// Workaround for false security issue with main.inc.php on Windows in tests:
+if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ $_SERVER['PHP_SELF'] = "phpunit";
+}
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver