Merge pull request #15789 from frederic34/api_setup

fix unknown variable
This commit is contained in:
Laurent Destailleur 2020-12-21 18:16:56 +01:00 committed by GitHub
commit a04ee0897d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,10 +75,8 @@ class Setup extends DolibarrApi
$sql .= " FROM ".MAIN_DB_PREFIX."c_input_method as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_input_method as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -112,70 +110,68 @@ class Setup extends DolibarrApi
return $list; return $list;
} }
/** /**
* Get the list of ordering origins. * Get the list of ordering origins.
* *
* @param string $sortfield Sort field * @param string $sortfield Sort field
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Number of items per page * @param int $limit Number of items per page
* @param int $page Page number {@min 0} * @param int $page Page number {@min 0}
* @param int $active Payment type is active or not {@min 0} {@max 1} * @param int $active Payment type is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'OrderByWWW')" * @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'OrderByWWW')"
* *
* @url GET dictionary/ordering_origins * @url GET dictionary/ordering_origins
* *
* @return array [List of ordering reasons] * @return array [List of ordering reasons]
* *
* @throws RestException 400 * @throws RestException 400
*/ */
public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
if (!DolibarrApiAccess::$user->rights->commande->lire) { if (!DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401); throw new RestException(401);
} }
$sql = "SELECT rowid, code, label, module"; $sql = "SELECT rowid, code, label, module";
$sql .= " FROM ".MAIN_DB_PREFIX."c_input_reason as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_input_reason as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters)) throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
{ }
throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
} $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; }
$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
$sql .= $this->db->order($sortfield, $sortorder); $sql .= $this->db->order($sortfield, $sortorder);
if ($limit) { if ($limit) {
if ($page < 0) { if ($page < 0) {
$page = 0; $page = 0;
} }
$offset = $limit * $page; $offset = $limit * $page;
$sql .= $this->db->plimit($limit, $offset); $sql .= $this->db->plimit($limit, $offset);
} }
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit)); $min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) { for ($i = 0; $i < $min; $i++) {
$list[] = $this->db->fetch_object($result); $list[] = $this->db->fetch_object($result);
} }
} else { } else {
throw new RestException(400, $this->db->lasterror()); throw new RestException(400, $this->db->lasterror());
} }
return $list; return $list;
} }
/** /**
* Get the list of payments types. * Get the list of payments types.
@ -206,10 +202,8 @@ class Setup extends DolibarrApi
$sql .= " WHERE t.entity IN (".getEntity('c_paiement').")"; $sql .= " WHERE t.entity IN (".getEntity('c_paiement').")";
$sql .= " AND t.active = ".$active; $sql .= " AND t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -272,10 +266,8 @@ class Setup extends DolibarrApi
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_departements as t"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_departements as t";
$sql .= " WHERE 1 = 1"; $sql .= " WHERE 1 = 1";
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -374,10 +366,8 @@ class Setup extends DolibarrApi
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
$sql .= " WHERE 1 = 1"; $sql .= " WHERE 1 = 1";
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -551,10 +541,8 @@ class Setup extends DolibarrApi
$sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -659,10 +647,8 @@ class Setup extends DolibarrApi
$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -720,13 +706,15 @@ class Setup extends DolibarrApi
$sql = "SELECT id, code, type, libelle as label, module"; $sql = "SELECT id, code, type, libelle as label, module";
$sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'"; if ($type) {
if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
}
if ($module) {
$sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -784,12 +772,12 @@ class Setup extends DolibarrApi
$sql = "SELECT id, code, label, accountancy_code, active, module, position"; $sql = "SELECT id, code, label, accountancy_code, active, module, position";
$sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; if ($module) {
$sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -848,13 +836,15 @@ class Setup extends DolibarrApi
$sql = "SELECT rowid, code, element as type, libelle as label, source, module, position"; $sql = "SELECT rowid, code, element as type, libelle as label, source, module, position";
$sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
if ($type) $sql .= " AND type LIKE '%".$this->db->escape($type)."%'"; if ($type) {
if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; $sql .= " AND type LIKE '%".$this->db->escape($type)."%'";
}
if ($module) {
$sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -911,12 +901,12 @@ class Setup extends DolibarrApi
$sql = "SELECT rowid, code, label, module"; $sql = "SELECT rowid, code, label, module";
$sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; if ($module) {
$sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -970,7 +960,9 @@ class Setup extends DolibarrApi
{ {
$list = array(); $list = array();
$sql = "SELECT t.code_iso, t.label, t.unicode"; $sql = "SELECT t.code_iso, t.label, t.unicode";
if (!empty($multicurrency)) $sql .= " , cr.date_sync, cr.rate "; if (!empty($multicurrency)) {
$sql .= " , cr.date_sync, cr.rate ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
if (!empty($multicurrency)) { if (!empty($multicurrency)) {
$sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso"; $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso";
@ -985,10 +977,8 @@ class Setup extends DolibarrApi
} }
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1043,18 +1033,22 @@ class Setup extends DolibarrApi
throw new RestException(401, 'Only an admin user can get list of extrafields'); throw new RestException(401, 'Only an admin user can get list of extrafields');
} }
if ($type == 'thirdparty') $type = 'societe'; if ($type == 'thirdparty') {
if ($type == 'contact') $type = 'socpeople'; $type = 'societe';
}
if ($type == 'contact') {
$type = 'socpeople';
}
$sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed"; $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
$sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t"; $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
$sql .= " WHERE t.entity IN (".getEntity('extrafields').")"; $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
if (!empty($type)) $sql .= " AND t.elementtype = '".$this->db->escape($type)."'"; if (!empty($type)) {
$sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1064,12 +1058,9 @@ class Setup extends DolibarrApi
$sql .= $this->db->order($sortfield, $sortorder); $sql .= $this->db->order($sortfield, $sortorder);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql)) while ($tab = $this->db->fetch_object($resql)) {
{
while ($tab = $this->db->fetch_object($resql))
{
// New usage // New usage
$list[$tab->elementtype][$tab->name]['type'] = $tab->type; $list[$tab->elementtype][$tab->name]['type'] = $tab->type;
$list[$tab->elementtype][$tab->name]['label'] = $tab->label; $list[$tab->elementtype][$tab->name]['label'] = $tab->label;
@ -1090,8 +1081,7 @@ class Setup extends DolibarrApi
throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror()); throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
} }
if (!count($list)) if (!count($list)) {
{
throw new RestException(404, 'No extrafield found'); throw new RestException(404, 'No extrafield found');
} }
@ -1123,13 +1113,15 @@ class Setup extends DolibarrApi
$sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country"; $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
$sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
$sql .= " AND t.active = ".$active; $sql .= " AND t.active = ".$active;
if ($zipcode) $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'"; if ($zipcode) {
if ($town) $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'"; $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
}
if ($town) {
$sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1192,10 +1184,8 @@ class Setup extends DolibarrApi
$sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")"; $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
$sql .= " AND t.active = ".$active; $sql .= " AND t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1252,10 +1242,8 @@ class Setup extends DolibarrApi
$sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")"; $sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
$sql .= " AND t.active = ".$active; $sql .= " AND t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1313,10 +1301,8 @@ class Setup extends DolibarrApi
$sql .= " FROM ".MAIN_DB_PREFIX."c_units as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1380,10 +1366,8 @@ class Setup extends DolibarrApi
$sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")"; $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")";
$sql .= " AND t.active = ".$active; $sql .= " AND t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1440,10 +1424,8 @@ class Setup extends DolibarrApi
$sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1500,10 +1482,8 @@ class Setup extends DolibarrApi
$sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
$sql .= " WHERE t.active = ".$active; $sql .= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1562,10 +1542,8 @@ class Setup extends DolibarrApi
// if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'"; // if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
// if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; // if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{ if (!DolibarrApi::_checkFilters($sqlfilters)) {
if (!DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -1604,13 +1582,13 @@ class Setup extends DolibarrApi
* *
* @url GET /company * @url GET /company
* *
* @return array|mixed Data without useless information * @return array|mixed Mysoc object
* *
* @throws RestException 403 Forbidden * @throws RestException 403 Forbidden
*/ */
public function getCompany() public function getCompany()
{ {
global $mysoc; global $conf, $mysoc;
if (!DolibarrApiAccess::$user->admin if (!DolibarrApiAccess::$user->admin
&& (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) { && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
@ -1710,8 +1688,7 @@ class Setup extends DolibarrApi
global $langs, $conf; global $langs, $conf;
if (!DolibarrApiAccess::$user->admin if (!DolibarrApiAccess::$user->admin
&& (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK)) && (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK)) {
{
throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK'); throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK');
} }
@ -1731,10 +1708,16 @@ class Setup extends DolibarrApi
$xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile; $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile;
// Remote file to compare to // Remote file to compare to
$xmlremote = ($target == 'default' ? '' : $target); $xmlremote = ($target == 'default' ? '' : $target);
if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL; if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) {
$xmlremote = $conf->global->MAIN_FILECHECK_URL;
}
$param = 'MAIN_FILECHECK_URL_'.DOL_VERSION; $param = 'MAIN_FILECHECK_URL_'.DOL_VERSION;
if (empty($xmlremote) && !empty($conf->global->$param)) $xmlremote = $conf->global->$param; if (empty($xmlremote) && !empty($conf->global->$param)) {
if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml'; $xmlremote = $conf->global->$param;
}
if (empty($xmlremote)) {
$xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
}
if ($target == 'local') { if ($target == 'local') {
if (dol_is_file($xmlfile)) { if (dol_is_file($xmlfile)) {
@ -1756,8 +1739,7 @@ class Setup extends DolibarrApi
} }
} }
if ($xml) if ($xml) {
{
$checksumconcat = array(); $checksumconcat = array();
$file_list = array(); $file_list = array();
$out = ''; $out = '';
@ -1776,14 +1758,15 @@ class Setup extends DolibarrApi
$out .= '</tr>'."\n"; $out .= '</tr>'."\n";
$i = 0; $i = 0;
foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement foreach ($xml->dolibarr_constants[0]->constant as $constant) { // $constant is a simpleXMLElement
{
$constname = $constant['name']; $constname = $constant['name'];
$constvalue = (string) $constant; $constvalue = (string) $constant;
$constvalue = (empty($constvalue) ? '0' : $constvalue); $constvalue = (empty($constvalue) ? '0' : $constvalue);
// Value found // Value found
$value = ''; $value = '';
if ($constname && $conf->global->$constname != '') $value = $conf->global->$constname; if ($constname && $conf->global->$constname != '') {
$value = $conf->global->$constname;
}
$valueforchecksum = (empty($value) ? '0' : $value); $valueforchecksum = (empty($value) ? '0' : $value);
$checksumconcat[] = $valueforchecksum; $checksumconcat[] = $valueforchecksum;
@ -1797,8 +1780,7 @@ class Setup extends DolibarrApi
$out .= "</tr>\n"; $out .= "</tr>\n";
} }
if ($i == 0) if ($i == 0) {
{
$out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; $out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
} }
$out .= '</table>'; $out .= '</table>';
@ -1808,9 +1790,7 @@ class Setup extends DolibarrApi
} }
// Scan htdocs // Scan htdocs
if (is_object($xml->dolibarr_htdocs_dir[0])) if (is_object($xml->dolibarr_htdocs_dir[0])) {
{
//var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit;
$includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']); $includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']);
// Defined qualified files (must be same than into generate_filelist_xml.php) // Defined qualified files (must be same than into generate_filelist_xml.php)
@ -1821,11 +1801,9 @@ class Setup extends DolibarrApi
// Fill file_list with files in signature, new files, modified files // Fill file_list with files in signature, new files, modified files
$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
// Complete with list of new files // Complete with list of new files
foreach ($scanfiles as $keyfile => $valfile) foreach ($scanfiles as $keyfile => $valfile) {
{
$tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']); $tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
if (!in_array($tmprelativefilename, $file_list['insignature'])) if (!in_array($tmprelativefilename, $file_list['insignature'])) {
{
$md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file $md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
$file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile); $file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
} }
@ -1842,11 +1820,9 @@ class Setup extends DolibarrApi
$out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>'; $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
$out .= '</tr>'."\n"; $out .= '</tr>'."\n";
$tmpfilelist = dol_sort_array($file_list['missing'], 'filename'); $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
if (is_array($tmpfilelist) && count($tmpfilelist)) if (is_array($tmpfilelist) && count($tmpfilelist)) {
{
$i = 0; $i = 0;
foreach ($tmpfilelist as $file) foreach ($tmpfilelist as $file) {
{
$i++; $i++;
$out .= '<tr class="oddeven">'; $out .= '<tr class="oddeven">';
$out .= '<td>'.$i.'</td>'."\n"; $out .= '<td>'.$i.'</td>'."\n";
@ -1877,11 +1853,9 @@ class Setup extends DolibarrApi
$out .= '<td class="right">'.$langs->trans("DateModification").'</td>'; $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
$out .= '</tr>'."\n"; $out .= '</tr>'."\n";
$tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename'); $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
if (is_array($tmpfilelist2) && count($tmpfilelist2)) if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
{
$i = 0; $i = 0;
foreach ($tmpfilelist2 as $file) foreach ($tmpfilelist2 as $file) {
{
$i++; $i++;
$out .= '<tr class="oddeven">'; $out .= '<tr class="oddeven">';
$out .= '<td>'.$i.'</td>'."\n"; $out .= '<td>'.$i.'</td>'."\n";
@ -1925,11 +1899,9 @@ class Setup extends DolibarrApi
$out .= '<td class="right">'.$langs->trans("DateModification").'</td>'; $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
$out .= '</tr>'."\n"; $out .= '</tr>'."\n";
$tmpfilelist3 = dol_sort_array($file_list['added'], 'filename'); $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
if (is_array($tmpfilelist3) && count($tmpfilelist3)) if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
{
$i = 0; $i = 0;
foreach ($tmpfilelist3 as $file) foreach ($tmpfilelist3 as $file) {
{
$i++; $i++;
$out .= '<tr class="oddeven">'; $out .= '<tr class="oddeven">';
$out .= '<td>'.$i.'</td>'."\n"; $out .= '<td>'.$i.'</td>'."\n";
@ -1958,8 +1930,7 @@ class Setup extends DolibarrApi
// Show warning // Show warning
if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
{
//setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs'); //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
} else { } else {
//setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings'); //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
@ -1970,17 +1941,13 @@ class Setup extends DolibarrApi
// Scan scripts // Scan scripts
asort($checksumconcat); // Sort list of checksum asort($checksumconcat); // Sort list of checksum
//var_dump($checksumconcat);
$checksumget = md5(join(',', $checksumconcat)); $checksumget = md5(join(',', $checksumconcat));
$checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum); $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
$outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown")); $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
if ($checksumget == $checksumtoget) { if ($checksumget == $checksumtoget) {
if (count($file_list['added'])) if (count($file_list['added'])) {
{
$resultcode = 'warning'; $resultcode = 'warning';
$resultcomment = 'FileIntegrityIsOkButFilesWereAdded'; $resultcomment = 'FileIntegrityIsOkButFilesWereAdded';
//$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>'; //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
@ -2019,8 +1986,7 @@ class Setup extends DolibarrApi
global $conf; global $conf;
if (!DolibarrApiAccess::$user->admin if (!DolibarrApiAccess::$user->admin
&& (empty($conf->global->API_LOGIN_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_GET_MODULES)) && (empty($conf->global->API_LOGIN_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_GET_MODULES)) {
{
throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGIN_ALLOWED_FOR_GET_MODULES'); throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGIN_ALLOWED_FOR_GET_MODULES');
} }