public function updateFromObject($obj) { global $DBO; if ($obj->id == -1) { $sql = file_get_contents(FS_VAR . 'new_customer.sql'); $sql = str_replace("_SPACE_", "_" . $DBO->escape($obj->space) . "_", $sql); $DBO->query($sql); } $obj = parent::_updateFromObject($obj); return $this->get("id"); }
public function updateFromObject($obj) { global $DBO; if (isset($obj->address)) { $address = $obj->address; unset($obj->address); } else { $address = array(); } $obj = parent::_updateFromObject($obj); $par = $obj; $ids = array(); foreach ($address as $obj) { if (is_null($obj)) { continue; } $change_type = "modify"; if ($obj->id == -1) { $obj->id = $DBO->nextId($this->table() . "_address"); $sql = "INSERT INTO `" . $this->table() . "_address` (`id`,`entity_id`) VALUES('" . $obj->id . "','" . $par->id . "');"; $DBO->query($sql); $change_type = "create"; } $sql = "SELECT * FROM `" . $this->table() . "_address` WHERE `id`='" . $DBO->escape($obj->id) . "';"; $DBO->query($sql); if ($DBO->result_count !== 1) { return false; } $original = $DBO->result("object"); $update = array(); $change = array(); $exclude = array("id", "deleted", "disabled"); foreach ($original as $field => $value) { if (in_array($field, $exclude)) { continue; } if (isset($obj->{$field}) && $DBO->escape($obj->{$field}) != $value) { $update[] = "`" . $field . "`='" . $obj->{$field} . "'"; $change[] = "('" . $change_type . "','" . $this->table() . "_address','" . $field . "','" . $obj->id . "','" . $_SESSION["auth::id"] . "','" . $value . "','" . $obj->{$field} . "')"; } } if (count($update) > 0) { $sql = "UPDATE `" . $this->table() . "_address` SET " . implode(",", $update) . " WHERE `id`='" . $DBO->escape($obj->id) . "';"; $DBO->query($sql); $sql = "INSERT INTO `##_" . $this->space() . "_logging` (`type`,`table`,`column`,`entry_id`,`owner_id`,`old`,`new`) VALUES " . implode(",", $change) . ";"; $DBO->query($sql); } $ids[] = $DBO->escape($obj->id); } $ids[] = -1; $sql = "UPDATE `" . $this->table() . "_address` SET `deleted`='1' WHERE `entity_id`='" . $par->id . "' AND `id` NOT IN ('" . implode("','", $ids) . "');"; $DBO->query($sql); $sql = "SELECT `id` FROM `" . $this->table() . "_address` WHERE `entity_id`='" . $par->id . "' AND `id` NOT IN ('" . implode("','", $ids) . "');"; $DBO->query($sql); $dids = $DBO->result("objectlist"); $change = array(); foreach ($dids as $id) { $change[] = "('delete','" . $this->table() . "_address','n/a','" . $id->id . "','" . $_SESSION["auth::id"] . "','n/a','n/a')"; } if (count($change) > 0) { $sql = "INSERT INTO `##_" . $this->space() . "_logging` (`type`,`table`,`column`,`entry_id`,`owner_id`,`old`,`new`) VALUES " . implode(",", $change) . ";"; $DBO->query($sql); } return $this->get("id"); }
public function updateFromObject($obj) { global $DBO; if (isset($obj->user_id)) { $user_id = $obj->user_id; unset($obj->user_id); } else { $user_id = array(); } if (isset($obj->ace_id)) { $ace_id = $obj->ace_id; unset($obj->ace_id); } else { $ace_id = array(); } $obj = parent::_updateFromObject($obj); foreach ($user_id as $k => $v) { if (is_null($v)) { unset($user_id[$k]); } } $user_id = $this->cleanPropertyArray($user_id); $sql = "SELECT `auth_user_id` FROM `##_auth_user_role` WHERE `auth_role_id`='" . $this->get("id") . "' AND `deleted`='0';"; $DBO->query($sql); $aur = array(); foreach ($DBO->result("objectlist") as $v) { $aur[] = $v->auth_user_id; } $d = array_diff($aur, $user_id); if (count($d) > 0) { $sql = "UPDATE `##_auth_user_role` SET `deleted`='1' WHERE `auth_role_id`='" . $this->get("id") . "' AND `auth_user_id` IN ('" . implode("','", $d) . "');"; echo $sql; $DBO->query($sql); } $d = array_diff($user_id, $aur); if (count($d) > 0) { $change = array(); foreach ($d as $did) { $change[] = "('" . $this->get("id") . "','{$did}')"; } $sql = "INSERT INTO `##_auth_user_role` (`auth_role_id`,`auth_user_id`) VALUES " . implode(",", $change) . ";"; echo $sql; $DBO->query($sql); } $ace_id = $this->cleanPropertyArray($ace_id); $sql = "SELECT `auth_ace_id` FROM `##_auth_acl` WHERE `auth_role_id`='" . $this->get("id") . "' AND `deleted`='0';"; $DBO->query($sql); $ac = array(); foreach ($DBO->result("objectlist") as $v) { $ac[] = $v->auth_ace_id; } $d = array_diff($ac, $ace_id); if (count($d) > 0) { $sql = "UPDATE `##_auth_acl` SET `deleted`='1' WHERE `auth_role_id`='" . $this->get("id") . "' AND `auth_ace_id` IN ('" . implode("','", $d) . "');"; $DBO->query($sql); } $d = array_diff($ace_id, $ac); if (count($d) > 0) { $change = array(); foreach ($d as $did) { $change[] = "('" . $this->get("id") . "','{$did}')"; } $sql = "INSERT INTO `##_auth_acl` (`auth_role_id`,`auth_ace_id`) VALUES " . implode(",", $change) . ";"; $DBO->query($sql); } return $this->get("id"); }
public function updateFromObject($obj) { global $DBO; if (isset($obj->role_id)) { $role_id = $obj->role_id; unset($obj->role_id); } else { $role_id = array(); } $password = ""; if (isset($obj->password)) { $pass = $obj->password; unset($obj->password); } $obj = parent::_updateFromObject($obj); if ($password !== "") { $this->setPassword($password); } foreach ($role_id as $k => $v) { if (is_null($v)) { unset($role_id[$k]); } } $sql = "SELECT `auth_role_id` FROM `##_auth_user_role` WHERE `auth_user_id`='" . $this->get("id") . "' AND `deleted`='0';"; $DBO->query($sql); $aui = array(); foreach ($DBO->result("objectlist") as $r) { $aui[] = $r->auth_role_id; } $d = array_diff($aui, $role_id); if (count($d) > 0) { $sql = "UPDATE `##_auth_user_role` SET `deleted`='1' WHERE `auth_user_id`='" . $this->get("id") . "' AND `auth_role_id` IN ('" . implode("','", $d) . "');"; $DBO->query($sql); } $d = array_diff($role_id, $aui); if (count($d) > 0) { $change = array(); foreach ($d as $did) { $change[] = "('" . $this->get("id") . "','{$did}')"; } $sql = "INSERT INTO `##_auth_user_role` (`auth_user_id`,`auth_role_id`) VALUES " . implode(",", $change) . ";"; $DBO->query($sql); } return $this->get("id"); }