function delete($ID) {
if(!(list($leftId, $rightId, $level) = $this->getNodeInfo($ID))) die("phpDbTree error: ".$this->db->error());
$this->db->query('BEGIN');
// Deleting record
$this->sql = 'DELETE FROM '.$this->table.' WHERE '.$this->id.'=\''.$ID.'\'';
if(!$this->db->query($this->sql)) {
$this->db->query('ROLLBACK');
die("phpDbTree error: ".$this->db->error());
}
// Clearing blank spaces in a tree
$this->sql = 'UPDATE '.$this->table.' SET '
. $this->left.'=IF('.$this->left.' BETWEEN '.$leftId.' AND '.$rightId.','.$this->left.'-1,'.$this->left.'),'
. $this->right.'=IF('.$this->right.' BETWEEN '.$leftId.' AND '.$rightId.','.$this->right.'-1,'.$this->right.'),'
. $this->level.'=IF('.$this->left.' BETWEEN '.$leftId.' AND '.$rightId.','.$this->level.'-1,'.$this->level.'),'
. $this->left.'=IF('.$this->left.'>'.$rightId.','.$this->left.'-2,'.$this->left.'),'
. $this->right.'=IF('.$this->right.'>'.$rightId.','.$this->right.'-2,'.$this->right.') '
. 'WHERE '.$this->right.'>'.$leftId
;
if(!$this->db->query($this->sql)) {
$this->db->query('ROLLBACK');
die("phpDbTree error: ".$this->db->error());
}
$this->db->query('COMMIT');
return true;
}