NEW : security check to avoid adding a parent warehouse chich is already a child of current one
This commit is contained in:
parent
805b65addd
commit
012be8e400
@ -62,6 +62,7 @@ ErrorCantLoadUserFromDolibarrDatabase=Failed to find user <b>%s</b> in Dolibarr
|
|||||||
ErrorNoVATRateDefinedForSellerCountry=Error, no vat rates defined for country '%s'.
|
ErrorNoVATRateDefinedForSellerCountry=Error, no vat rates defined for country '%s'.
|
||||||
ErrorNoSocialContributionForSellerCountry=Error, no social/fiscal taxes type defined for country '%s'.
|
ErrorNoSocialContributionForSellerCountry=Error, no social/fiscal taxes type defined for country '%s'.
|
||||||
ErrorFailedToSaveFile=Error, failed to save file.
|
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.
|
NotAuthorized=You are not authorized to do that.
|
||||||
SetDate=Set date
|
SetDate=Set date
|
||||||
SelectDate=Select a date
|
SelectDate=Select a date
|
||||||
|
|||||||
@ -172,6 +172,16 @@ class Entrepot extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function update($id, $user)
|
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->libelle=trim($this->libelle);
|
||||||
$this->description=trim($this->description);
|
$this->description=trim($this->description);
|
||||||
|
|
||||||
@ -635,4 +645,22 @@ class Entrepot extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user