diff --git a/SECURITY.md b/SECURITY.md
index 6dc6e0f33b5..08ca64e4a4c 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -55,8 +55,7 @@ ONLY vulnerabilities discovered, when the following setup on test platform is us
* $dolibarr_nocsrfcheck must be kept to the value 0 into conf.php (this is the default value)
* $dolibarr_main_force_https must be set to something else than 0.
* The constant MAIN_SECURITY_CSRF_WITH_TOKEN must be set to 1 into backoffice menu Home - Setup - Other (this protection should be set to 1 soon by default)
-* The module DebugBar must NOT be enabled (by default, this module is not enabled. This is a developer tool)
-* The module ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool)
+* The module DebugBar and ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool)
* ONLY security reports on modules provided by default and with the "stable" status are valid (troubles into "experimental", "developement" or external modules are not valid vulnerabilities).
* The root of web server must link to htdocs and the documents directory must be outside of the web server root (this is the default when using the default installer but may differs with external installer).
* The web server setup must be done so only the documents directory is in write mode. The root directory called htdocs must be readonly.
diff --git a/htdocs/admin/agenda_reminder.php b/htdocs/admin/agenda_reminder.php
index 27c6bbeed73..36f0c572de4 100644
--- a/htdocs/admin/agenda_reminder.php
+++ b/htdocs/admin/agenda_reminder.php
@@ -187,14 +187,14 @@ print '
'."\n";
print '
'."\n";
if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
- if (! getIsHTTPS()) {
+ if (!isHTTPS()) {
$langs->load("errors");
print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' ';
}
print ''.img_picto($langs->trans('Disabled'), 'switch_off').'';
print '
';
} elseif (!empty($object->socialnetworks[$key])) {
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 0aeb64aa427..4c25a002a8f 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -784,17 +784,24 @@ class Societe extends CommonObject
$error = 0;
// Clean parameters
- if (empty($this->status)) $this->status = 0;
+ if (empty($this->status)) {
+ $this->status = 0;
+ }
$this->name = $this->name ?trim($this->name) : trim($this->nom);
$this->setUpperOrLowerCase();
$this->nom = $this->name; // For backward compatibility
- if (empty($this->client)) $this->client = 0;
- if (empty($this->fournisseur)) $this->fournisseur = 0;
+ if (empty($this->client)) {
+ $this->client = 0;
+ }
+ if (empty($this->fournisseur)) {
+ $this->fournisseur = 0;
+ }
$this->import_key = trim($this->import_key);
- if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
- if (empty($this->fk_multicurrency))
- {
+ if (!empty($this->multicurrency_code)) {
+ $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
+ }
+ if (empty($this->fk_multicurrency)) {
$this->multicurrency_code = '';
$this->fk_multicurrency = 0;
}
@@ -806,15 +813,18 @@ class Societe extends CommonObject
$this->db->begin();
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
- if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0);
- if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
+ if ($this->code_client == -1 || $this->code_client === 'auto') {
+ $this->get_codeclient($this, 0);
+ }
+ if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
+ $this->get_codefournisseur($this, 1);
+ }
// Check more parameters (including mandatory setup
// If error, this->errors[] is filled
$result = $this->verify();
- if ($result >= 0)
- {
+ if ($result >= 0) {
$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
@@ -832,44 +842,42 @@ class Societe extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$result = $this->db->query($sql);
- if ($result)
- {
+ if ($result) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
$ret = $this->update($this->id, $user, 0, 1, 1, 'add');
// Ajout du commercial affecte
- if ($this->commercial_id != '' && $this->commercial_id != -1)
- {
+ if ($this->commercial_id != '' && $this->commercial_id != -1) {
$this->add_commercial($user, $this->commercial_id);
}
// si un commercial cree un client il lui est affecte automatiquement
- elseif (empty($user->rights->societe->client->voir))
- {
+ elseif (empty($user->rights->societe->client->voir)) {
$this->add_commercial($user, $user->id);
}
- if ($ret >= 0)
- {
+ if ($ret >= 0) {
// Call trigger
$result = $this->call_trigger('COMPANY_CREATE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
- } else $error++;
+ } else {
+ $error++;
+ }
- if (!$error)
- {
+ if (!$error) {
dol_syslog(get_class($this)."::Create success id=".$this->id);
$this->db->commit();
return $this->id;
} else {
- dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR);
+ dol_syslog(get_class($this)."::Create echec update ".$this->error.(empty($this->errors) ? '' : ' '.join(',', $this->errors)), LOG_ERR);
$this->db->rollback();
return -4;
}
} else {
- if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
+ if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...)
$result = -1;
} else {
@@ -916,8 +924,7 @@ class Societe extends CommonObject
$contact->phone_pro = $this->phone;
$result = $contact->create($user);
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $contact->error;
$this->errors = $contact->errors;
dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR);
@@ -943,28 +950,21 @@ class Societe extends CommonObject
$this->name = trim($this->name);
$this->nom = $this->name; // For backward compatibility
- if (!$this->name)
- {
+ if (!$this->name) {
$this->errors[] = 'ErrorBadThirdPartyName';
$result = -2;
}
- if ($this->client)
- {
+ if ($this->client) {
$rescode = $this->check_codeclient();
- if ($rescode <> 0)
- {
- if ($rescode == -1)
- {
+ if ($rescode != 0 && $rescode != -5) {
+ if ($rescode == -1) {
$this->errors[] = 'ErrorBadCustomerCodeSyntax';
- } elseif ($rescode == -2)
- {
+ } elseif ($rescode == -2) {
$this->errors[] = 'ErrorCustomerCodeRequired';
- } elseif ($rescode == -3)
- {
+ } elseif ($rescode == -3) {
$this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
- } elseif ($rescode == -4)
- {
+ } elseif ($rescode == -4) {
$this->errors[] = 'ErrorPrefixRequired';
} else {
$this->errors[] = 'ErrorUnknownOnCustomerCodeCheck';
@@ -974,22 +974,16 @@ class Societe extends CommonObject
}
}
- if ($this->fournisseur)
- {
+ if ($this->fournisseur) {
$rescode = $this->check_codefournisseur();
- if ($rescode <> 0)
- {
- if ($rescode == -1)
- {
+ if ($rescode != 0 && $rescode != -5) {
+ if ($rescode == -1) {
$this->errors[] = 'ErrorBadSupplierCodeSyntax';
- } elseif ($rescode == -2)
- {
+ } elseif ($rescode == -2) {
$this->errors[] = 'ErrorSupplierCodeRequired';
- } elseif ($rescode == -3)
- {
+ } elseif ($rescode == -3) {
$this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
- } elseif ($rescode == -4)
- {
+ } elseif ($rescode == -4) {
$this->errors[] = 'ErrorPrefixRequired';
} else {
$this->errors[] = 'ErrorUnknownOnSupplierCodeCheck';
@@ -1000,22 +994,17 @@ class Societe extends CommonObject
// Check for duplicate or mandatory fields defined into setup
$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL');
- foreach ($array_to_check as $key)
- {
+ foreach ($array_to_check as $key) {
$keymin = strtolower($key);
$i = (int) preg_replace('/[^0-9]/', '', $key);
$vallabel = $this->$keymin;
- if ($i > 0)
- {
- if ($this->isACompany())
- {
+ if ($i > 0) {
+ if ($this->isACompany()) {
// Check for mandatory prof id (but only if country is same than ours)
- if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
- {
+ if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) {
$idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY';
- if (!$vallabel && !empty($conf->global->$idprof_mandatory))
- {
+ if (!$vallabel && !empty($conf->global->$idprof_mandatory)) {
$langs->load("errors");
$error++;
$this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
@@ -1024,10 +1013,8 @@ class Societe extends CommonObject
}
// Check for unicity on profid
- if (!$error && $vallabel && $this->id_prof_verifiable($i))
- {
- if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
- {
+ if (!$error && $vallabel && $this->id_prof_verifiable($i)) {
+ if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) {
$langs->load("errors");
$error++;
$this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
@@ -1036,21 +1023,17 @@ class Societe extends CommonObject
} else {
//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
- if ($key == 'EMAIL')
- {
+ if ($key == 'EMAIL') {
// Check for mandatory
- if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email))
- {
+ if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) {
$langs->load("errors");
$error++;
$this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
// Check for unicity
- if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE))
- {
- if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
- {
+ if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) {
+ if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) {
$langs->load("errors");
$error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
}
@@ -1059,7 +1042,9 @@ class Societe extends CommonObject
}
}
- if ($error) $result = -4;
+ if ($error) {
+ $result = -4;
+ }
return $result;
}
@@ -1082,7 +1067,9 @@ class Societe extends CommonObject
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
- if (empty($id)) $id = $this->id;
+ if (empty($id)) {
+ $id = $this->id;
+ }
$error = 0;
@@ -1126,11 +1113,14 @@ class Societe extends CommonObject
$this->tva_assuj = trim($this->tva_assuj);
$this->tva_intra = dol_sanitizeFileName($this->tva_intra, '');
- if (empty($this->status)) $this->status = 0;
+ if (empty($this->status)) {
+ $this->status = 0;
+ }
- if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
- if (empty($this->fk_multicurrency))
- {
+ if (!empty($this->multicurrency_code)) {
+ $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
+ }
+ if (empty($this->fk_multicurrency)) {
$this->multicurrency_code = '';
$this->fk_multicurrency = 0;
}
@@ -1142,8 +1132,12 @@ class Societe extends CommonObject
$this->localtax1_value = trim($this->localtax1_value);
$this->localtax2_value = trim($this->localtax2_value);
- if ($this->capital != '') $this->capital = price2num(trim($this->capital));
- if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef
+ if ($this->capital != '') {
+ $this->capital = price2num(trim($this->capital));
+ }
+ if (!is_numeric($this->capital)) {
+ $this->capital = ''; // '' = undef
+ }
$this->effectif_id = trim($this->effectif_id);
$this->forme_juridique_code = trim($this->forme_juridique_code);
@@ -1152,41 +1146,44 @@ class Societe extends CommonObject
$this->barcode = trim($this->barcode);
// For automatic creation
- if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0);
- if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
+ if ($this->code_client == -1 || $this->code_client === 'auto') {
+ $this->get_codeclient($this, 0);
+ }
+ if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
+ $this->get_codefournisseur($this, 1);
+ }
$this->code_compta = trim($this->code_compta);
$this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
// Check parameters. More tests are done later in the ->verify()
- if (!is_numeric($this->client) && !is_numeric($this->fournisseur))
- {
+ if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) {
$langs->load("errors");
$this->error = $langs->trans("BadValueForParameterClientOrSupplier");
return -1;
}
$customer = false;
- if (!empty($allowmodcodeclient) && !empty($this->client))
- {
+ if (!empty($allowmodcodeclient) && !empty($this->client)) {
// Attention get_codecompta peut modifier le code suivant le module utilise
- if (empty($this->code_compta))
- {
+ if (empty($this->code_compta)) {
$ret = $this->get_codecompta('customer');
- if ($ret < 0) return -1;
+ if ($ret < 0) {
+ return -1;
+ }
}
$customer = true;
}
$supplier = false;
- if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur))
- {
+ if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) {
// Attention get_codecompta peut modifier le code suivant le module utilise
- if ($this->code_compta_fournisseur == "")
- {
+ if ($this->code_compta_fournisseur == "") {
$ret = $this->get_codecompta('supplier');
- if ($ret < 0) return -1;
+ if ($ret < 0) {
+ return -1;
+ }
}
$supplier = true;
@@ -1205,33 +1202,31 @@ class Societe extends CommonObject
// Check name is required and codes are ok or unique.
// If error, this->errors[] is filled
$result = 0;
- if ($action != 'add' && $action != 'merge')
- {
+ if ($action != 'add' && $action != 'merge') {
// We don't check when update called during a create because verify was already done.
// For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error
$result = $this->verify();
// If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update
// So we can update record that were using and old numbering rule.
- if (is_array($this->errors))
- {
- if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
- {
- if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message
+ if (is_array($this->errors)) {
+ if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
+ if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) {
+ unset($this->errors[$key]); // Remove error message
+ }
}
- if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
- {
- if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message
+ if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
+ if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) {
+ unset($this->errors[$key]); // Remove error message
+ }
}
- if (empty($this->errors)) // If there is no more error, we can make like if there is no error at all
- {
+ if (empty($this->errors)) { // If there is no more error, we can make like if there is no error at all
$result = 0;
}
}
}
- if ($result >= 0)
- {
+ if ($result >= 0) {
dol_syslog(get_class($this)."::update verify ok or not done");
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
@@ -1272,29 +1267,32 @@ class Societe extends CommonObject
// Local taxes
$sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null");
$sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null");
- if ($this->localtax1_assuj == 1)
- {
- if ($this->localtax1_value != '')
- {
+ if ($this->localtax1_assuj == 1) {
+ if ($this->localtax1_value != '') {
$sql .= ",localtax1_value =".$this->localtax1_value;
- } else $sql .= ",localtax1_value =0.000";
- } else $sql .= ",localtax1_value =0.000";
+ } else {
+ $sql .= ",localtax1_value =0.000";
+ }
+ } else {
+ $sql .= ",localtax1_value =0.000";
+ }
- if ($this->localtax2_assuj == 1)
- {
- if ($this->localtax2_value != '')
- {
+ if ($this->localtax2_assuj == 1) {
+ if ($this->localtax2_value != '') {
$sql .= ",localtax2_value =".$this->localtax2_value;
- } else $sql .= ",localtax2_value =0.000";
- } else $sql .= ",localtax2_value =0.000";
+ } else {
+ $sql .= ",localtax2_value =0.000";
+ }
+ } else {
+ $sql .= ",localtax2_value =0.000";
+ }
$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
$sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null");
$sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null");
- if (isset($this->stcomm_id))
- {
+ if (isset($this->stcomm_id)) {
$sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0");
}
$sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0");
@@ -1327,14 +1325,12 @@ class Societe extends CommonObject
$sql .= ", fk_incoterms = ".$this->fk_incoterms;
$sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null");
- if ($customer)
- {
+ if ($customer) {
$sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null");
$sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null");
}
- if ($supplier)
- {
+ if ($supplier) {
$sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null");
$sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null");
}
@@ -1345,17 +1341,13 @@ class Societe extends CommonObject
$sql .= " WHERE rowid = ".(int) $id;
$resql = $this->db->query($sql);
- if ($resql)
- {
- if (is_object($this->oldcopy)) // If we have information on old values
- {
- if ($this->oldcopy->country_id != $this->country_id)
- {
+ if ($resql) {
+ if (is_object($this->oldcopy)) { // If we have information on old values
+ if ($this->oldcopy->country_id != $this->country_id) {
unset($this->country_code);
unset($this->country);
}
- if ($this->oldcopy->state_id != $this->state_id)
- {
+ if ($this->oldcopy->state_id != $this->state_id) {
unset($this->state_code);
unset($this->state);
}
@@ -1368,11 +1360,9 @@ class Societe extends CommonObject
$nbrowsaffected = $this->db->affected_rows($resql);
- if (!$error && $nbrowsaffected)
- {
+ if (!$error && $nbrowsaffected) {
// Update information on linked member if it is an update
- if (!$nosyncmember && !empty($conf->adherent->enabled))
- {
+ if (!$nosyncmember && !empty($conf->adherent->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
dol_syslog(get_class($this)."::update update linked member");
@@ -1380,8 +1370,7 @@ class Societe extends CommonObject
$lmember = new Adherent($this->db);
$result = $lmember->fetch(0, 0, $this->id);
- if ($result > 0)
- {
+ if ($result > 0) {
$lmember->company = $this->name;
//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname; // We keep firstname and lastname of member unchanged
//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged
@@ -1395,15 +1384,13 @@ class Societe extends CommonObject
$lmember->country_id = $this->country_id;
$result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates
- if ($result < 0)
- {
+ if ($result < 0) {
$this->error = $lmember->error;
$this->errors = array_merge($this->errors, $lmember->errors);
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
$error++;
}
- } elseif ($result < 0)
- {
+ } elseif ($result < 0) {
$this->error = $lmember->error;
$error++;
}
@@ -1413,34 +1400,30 @@ class Societe extends CommonObject
$action = 'update';
// Actions on extra fields
- if (!$error)
- {
+ if (!$error) {
$result = $this->insertExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
// Actions on extra languages
- if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) // For avoid conflicts if trigger used
- {
+ if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) { // For avoid conflicts if trigger used
$result = $this->insertExtraLanguages();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error && $call_trigger)
- {
+ if (!$error && $call_trigger) {
// Call trigger
$result = $this->call_trigger('COMPANY_MODIFY', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
dol_syslog(get_class($this)."::Update success");
$this->db->commit();
return 1;
@@ -1449,8 +1432,7 @@ class Societe extends CommonObject
return -1;
}
} else {
- if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
+ if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
// Doublon
$this->error = $langs->trans("ErrorDuplicateField");
$result = -1;
@@ -1490,7 +1472,9 @@ class Societe extends CommonObject
global $langs;
global $conf;
- if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
+ if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
+ return -1;
+ }
$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.address, s.datec as date_creation, s.prefix_comm';
$sql .= ', s.status';
@@ -1533,30 +1517,51 @@ class Societe extends CommonObject
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_remise as sr ON sr.rowid = (SELECT MAX(rowid) FROM '.MAIN_DB_PREFIX.'societe_remise WHERE fk_soc = s.rowid AND entity IN ('.getEntity('discount').'))';
$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
- if ($rowid) $sql .= ' AND s.rowid = '.$rowid;
- if ($ref) $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
- if ($ref_alias) $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'";
- if ($ref_ext) $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
- if ($barcode) $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'";
- if ($idprof1) $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
- if ($idprof2) $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
- if ($idprof3) $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
- if ($idprof4) $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
- if ($idprof5) $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
- if ($idprof6) $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
- if ($email) $sql .= " AND s.email = '".$this->db->escape($email)."'";
+ if ($rowid) {
+ $sql .= ' AND s.rowid = '.$rowid;
+ }
+ if ($ref) {
+ $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
+ }
+ if ($ref_alias) {
+ $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'";
+ }
+ if ($ref_ext) {
+ $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
+ }
+ if ($barcode) {
+ $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'";
+ }
+ if ($idprof1) {
+ $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
+ }
+ if ($idprof2) {
+ $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
+ }
+ if ($idprof3) {
+ $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
+ }
+ if ($idprof4) {
+ $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
+ }
+ if ($idprof5) {
+ $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
+ }
+ if ($idprof6) {
+ $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
+ }
+ if ($email) {
+ $sql .= " AND s.email = '".$this->db->escape($email)."'";
+ }
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
- if ($num > 1)
- {
+ if ($num > 1) {
$this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.';
dol_syslog($this->error, LOG_ERR);
$result = -2;
- } elseif ($num) // $num = 1
- {
+ } elseif ($num) { // $num = 1
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@@ -1642,7 +1647,7 @@ class Societe extends CommonObject
$this->prefix_comm = $obj->prefix_comm;
- $this->remise_percent = price2num($obj->remise_client); // 0.000000 must be 0
+ $this->remise_percent = $obj->remise_client ? price2num($obj->remise_client) : 0; // 0.000000 must be 0
$this->remise_supplier_percent = $obj->remise_supplier;
$this->mode_reglement_id = $obj->mode_reglement;
$this->cond_reglement_id = $obj->cond_reglement;
@@ -1702,7 +1707,9 @@ class Societe extends CommonObject
}
// Use first price level if level not defined for third party
- if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) $this->price_level = 1;
+ if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) {
+ $this->price_level = 1;
+ }
return $result;
}
@@ -1719,7 +1726,9 @@ class Societe extends CommonObject
{
global $langs, $conf, $user;
- if (empty($fuser)) $fuser = $user;
+ if (empty($fuser)) {
+ $fuser = $user;
+ }
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -1730,49 +1739,42 @@ class Societe extends CommonObject
// Test if child exists
$objectisused = $this->isObjectUsed($id);
- if (empty($objectisused))
- {
+ if (empty($objectisused)) {
$this->db->begin();
// User is mandatory for trigger call
- if (!$error && $call_trigger)
- {
+ if (!$error && $call_trigger) {
// Call trigger
$result = $this->call_trigger('COMPANY_DELETE', $fuser);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
// End call triggers
}
- if (!$error)
- {
+ if (!$error) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
$static_cat = new Categorie($this->db);
$toute_categs = array();
// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
- if ($this->client || $this->prospect)
- {
+ if ($this->client || $this->prospect) {
$toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER);
}
- if ($this->fournisseur)
- {
+ if ($this->fournisseur) {
$toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER);
}
// Remove each "Categorie"
- foreach ($toute_categs as $type => $categs_type)
- {
- foreach ($categs_type as $cat)
- {
+ foreach ($toute_categs as $type => $categs_type) {
+ foreach ($categs_type as $cat) {
$cat->del_type($this, $type);
}
}
}
- if (!$error)
- {
- foreach ($this->childtablesoncascade as $tabletodelete)
- {
+ if (!$error) {
+ foreach ($this->childtablesoncascade as $tabletodelete) {
$deleteFromObject = explode(':', $tabletodelete);
if (count($deleteFromObject) >= 2) {
$className = str_replace('@', '', $deleteFromObject[0]);
@@ -1804,51 +1806,42 @@ class Societe extends CommonObject
}
// Removed extrafields
- if (!$error)
- {
+ if (!$error) {
$result = $this->deleteExtraFields();
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
}
}
// Remove links to subsidiaries companies
- if (!$error)
- {
+ if (!$error) {
$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
$sql .= " SET parent = NULL";
$sql .= " WHERE parent = ".$id;
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
$error++;
$this->errors[] = $this->db->lasterror();
}
}
// Remove third party
- if (!$error)
- {
+ if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
$sql .= " WHERE rowid = ".$id;
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
$error++;
$this->errors[] = $this->db->lasterror();
}
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
// Delete directory
- if (!empty($conf->societe->multidir_output[$entity]))
- {
+ if (!empty($conf->societe->multidir_output[$entity])) {
$docdir = $conf->societe->multidir_output[$entity]."/".$id;
- if (dol_is_dir($docdir))
- {
+ if (dol_is_dir($docdir)) {
dol_delete_dir_recursive($docdir);
}
}
@@ -1859,7 +1852,9 @@ class Societe extends CommonObject
$this->db->rollback();
return -1;
}
- } else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
+ } else {
+ dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
+ }
return 0;
}
@@ -1872,20 +1867,22 @@ class Societe extends CommonObject
public function set_as_client()
{
// phpcs:enable
- if ($this->id)
- {
+ if ($this->id) {
$newclient = 1;
- if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag
+ if ($this->client == 2 || $this->client == 3) {
+ $newclient = 3; //If prospect, we keep prospect tag
+ }
$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
$sql .= " SET client = ".$newclient;
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$this->client = $newclient;
return 1;
- } else return -1;
+ } else {
+ return -1;
+ }
}
return 0;
}
@@ -1906,16 +1903,14 @@ class Societe extends CommonObject
// Parameter cleaning
$note = trim($note);
- if (!$note)
- {
+ if (!$note) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason"));
return -2;
}
dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id);
- if ($this->id)
- {
+ if ($this->id) {
$this->db->begin();
$now = dol_now();
@@ -1925,8 +1920,7 @@ class Societe extends CommonObject
$sql .= " SET remise_client = '".$this->db->escape($remise)."'";
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->db->rollback();
$this->error = $this->db->error();
return -1;
@@ -1941,8 +1935,7 @@ class Societe extends CommonObject
$sql .= ")";
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->db->rollback();
$this->error = $this->db->lasterror();
return -1;
@@ -1969,16 +1962,14 @@ class Societe extends CommonObject
// Parameter cleaning
$note = trim($note);
- if (!$note)
- {
+ if (!$note) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason"));
return -2;
}
dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id);
- if ($this->id)
- {
+ if ($this->id) {
$this->db->begin();
$now = dol_now();
@@ -1988,8 +1979,7 @@ class Societe extends CommonObject
$sql .= " SET remise_supplier = '".$this->db->escape($remise)."'";
$sql .= " WHERE rowid = ".$this->id;
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->db->rollback();
$this->error = $this->db->error();
return -1;
@@ -2004,8 +1994,7 @@ class Societe extends CommonObject
$sql .= ")";
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
$this->db->rollback();
$this->error = $this->db->lasterror();
return -1;
@@ -2037,24 +2026,20 @@ class Societe extends CommonObject
$desc = trim($desc);
// Check parameters
- if (!$remise > 0)
- {
+ if (!$remise > 0) {
$this->error = $langs->trans("ErrorWrongValueForParameter", "1");
return -1;
}
- if (!$desc)
- {
+ if (!$desc) {
$this->error = $langs->trans("ErrorWrongValueForParameter", "3");
return -2;
}
- if ($this->id > 0)
- {
+ if ($this->id > 0) {
// Clean vat code
$reg = array();
$vat_src_code = '';
- if (preg_match('/\((.*)\)/', $vatrate, $reg))
- {
+ if (preg_match('/\((.*)\)/', $vatrate, $reg)) {
$vat_src_code = $reg[1];
$vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate.
}
@@ -2076,14 +2061,15 @@ class Societe extends CommonObject
$discount->description = $desc;
$result = $discount->create($user);
- if ($result > 0)
- {
+ if ($result > 0) {
return $result;
} else {
$this->error = $discount->error;
return -3;
}
- } else return 0;
+ } else {
+ return 0;
+ }
}
/**
@@ -2101,8 +2087,7 @@ class Societe extends CommonObject
$discountstatic = new DiscountAbsolute($this->db);
$result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
- if ($result >= 0)
- {
+ if ($result >= 0) {
return $result;
} else {
$this->error = $discountstatic->error;
@@ -2127,13 +2112,14 @@ class Societe extends CommonObject
$sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo";
$sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
- if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
- {
+ if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
$sql .= " WHERE ((ug.fk_user = sc.fk_user";
$sql .= " AND ug.entity = ".$conf->entity.")";
$sql .= " OR u.admin = 1)";
- } else $sql .= " WHERE entity in (0, ".$conf->entity.")";
+ } else {
+ $sql .= " WHERE entity in (0, ".$conf->entity.")";
+ }
$sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
if (empty($sortfield) && empty($sortorder)) {
@@ -2143,16 +2129,13 @@ class Societe extends CommonObject
$sql .= $this->db->order($sortfield, $sortorder);
$resql = $this->db->query($sql);
- if ($resql)
- {
+ if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
- while ($i < $num)
- {
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
- if (empty($mode))
- {
+ if (empty($mode)) {
$reparray[$i]['id'] = $obj->rowid;
$reparray[$i]['lastname'] = $obj->lastname;
$reparray[$i]['firstname'] = $obj->firstname;
@@ -2187,16 +2170,14 @@ class Societe extends CommonObject
public function set_price_level($price_level, User $user)
{
// phpcs:enable
- if ($this->id)
- {
+ if ($this->id) {
$now = dol_now();
$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
$sql .= " SET price_level = '".$this->db->escape($price_level)."'";
$sql .= " WHERE rowid = ".$this->id;
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
dol_print_error($this->db);
return -1;
}
@@ -2205,8 +2186,7 @@ class Societe extends CommonObject
$sql .= " (datec, fk_soc, price_level, fk_user_author)";
$sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
dol_print_error($this->db);
return -1;
}
@@ -2228,50 +2208,42 @@ class Societe extends CommonObject
// phpcs:enable
$error = 0;
- if ($this->id > 0 && $commid > 0)
- {
+ if ($this->id > 0 && $commid > 0) {
$this->db->begin();
- if (!$error)
- {
+ if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux";
$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror());
$error++;
}
}
- if (!$error)
- {
+ if (!$error) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
$sql .= " (fk_soc, fk_user)";
$sql .= " VALUES (".$this->id.", ".$commid.")";
$resql = $this->db->query($sql);
- if (!$resql)
- {
+ if (!$resql) {
dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror());
$error++;
}
}
- if (!$error)
- {
+ if (!$error) {
$this->context = array('commercial_modified'=>$commid);
$result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user);
- if ($result < 0)
- {
+ if ($result < 0) {
$error++;
}
}
- if (!$error)
- {
+ if (!$error) {
$this->db->commit();
return 1;
} else {
@@ -2298,15 +2270,15 @@ class Societe extends CommonObject
$this->context = array('commercial_modified'=>$commid);
$result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
- if ($result < 0) $error++;
+ if ($result < 0) {
+ $error++;
+ }
- if ($this->id > 0 && $commid > 0)
- {
+ if ($this->id > 0 && $commid > 0) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux ";
$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
- if (!$this->db->query($sql))
- {
+ if (!$this->db->query($sql)) {
dol_syslog(get_class($this)."::del_commercial Erreur");
}
}
@@ -2327,17 +2299,22 @@ class Societe extends CommonObject
{
global $conf, $langs, $hookmanager;
- if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
+ if (!empty($conf->dol_no_mouse_hover)) {
+ $notooltip = 1; // Force disable tooltips
+ }
$name = $this->name ? $this->name : $this->nom;
if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
- if (empty($option) && $this->client > 0) $option = 'customer';
- if (empty($option) && $this->fournisseur > 0) $option = 'supplier';
+ if (empty($option) && $this->client > 0) {
+ $option = 'customer';
+ }
+ if (empty($option) && $this->fournisseur > 0) {
+ $option = 'supplier';
+ }
}
- if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
- {
+ if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) {
$code = '';
if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) {
$code = $this->code_client.' - ';
@@ -2356,18 +2333,18 @@ class Societe extends CommonObject
}
}
- if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
+ if (!empty($this->name_alias)) {
+ $name .= ' ('.$this->name_alias.')';
+ }
$result = ''; $label = '';
$linkstart = ''; $linkend = '';
- if (!empty($this->logo) && class_exists('Form'))
- {
+ if (!empty($this->logo) && class_exists('Form')) {
$label .= '
';
$label .= Form::showphoto('societe', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label .= '
';
$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$label.= '