NEW : security check to avoid adding a parent warehouse chich is already a child of current one

This commit is contained in:
gauthier 2016-10-14 12:42:42 +02:00
parent 805b65addd
commit 012be8e400
2 changed files with 29 additions and 0 deletions

View File

@ -62,6 +62,7 @@ ErrorCantLoadUserFromDolibarrDatabase=Failed to find user <b>%s</b> in Dolibarr
ErrorNoVATRateDefinedForSellerCountry=Error, no vat rates defined for country '%s'.
ErrorNoSocialContributionForSellerCountry=Error, no social/fiscal taxes type defined for country '%s'.
ErrorFailedToSaveFile=Error, failed to save file.
ErrorCannotAddThisParentWarehouse=You are trying to add a parent warehouse which is already a child of current one
NotAuthorized=You are not authorized to do that.
SetDate=Set date
SelectDate=Select a date

View File

@ -172,6 +172,16 @@ class Entrepot extends CommonObject
*/
function update($id, $user)
{
// Check if new parent is already a child of current warehouse
if(!empty($this->fk_parent)) {
$TChildWarehouses = array();
$TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
if(in_array($this->fk_parent, $TChildWarehouses)) {
$this->error = 'ErrorCannotAddThisParentWarehouse';
return -2;
}
}
$this->libelle=trim($this->libelle);
$this->description=trim($this->description);
@ -634,5 +644,23 @@ class Entrepot extends CommonObject
return implode(' >> ', array_reverse($TArbo));
}
function get_children_warehouses($id, &$TChildWarehouses) {
$sql = 'SELECT rowid
FROM '.MAIN_DB_PREFIX.'entrepot
WHERE fk_parent = '.$id;
$resql = $this->db->query($sql);
if($resql) {
while($res = $this->db->fetch_object($resql)) {
$TChildWarehouses[] = $res->rowid;
$this->get_children_warehouses($res->rowid, $TChildWarehouses);
}
}
return $TChildWarehouses;
}
}