From a2a999305bc2f331df5009aa29dafbebda5c6aaa Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 17 Jul 2006 20:41:01 +0000 Subject: [PATCH] r899: Adding lots of pre and post processing methods for UserAPI to make all the counters line up, etc. --- admin/user.php | 31 +++------------------- includes/api_user.php | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 27 deletions(-) diff --git a/admin/user.php b/admin/user.php index 670daba..0abe215 100644 --- a/admin/user.php +++ b/admin/user.php @@ -38,29 +38,10 @@ if (empty($_REQUEST['do'])) if ($_REQUEST['do'] == 'kill') { - $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $bugsys->input_clean('userid', TYPE_UINT)); - if (!$user) - { - $admin->error($lang->getlex('error_invalid_id')); - } - - if ($user['userid'] == $bugsys->userinfo['userid']) - { - $admin->error($lang->string('You cannot delete your own account!')); - } - - if ($user['usergroupid'] == 6) - { - $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 6 AND userid <> $user[userid]"); - if ($count['count'] < 1) - { - $admin->error($lang->string('At least one other administrator needs to be present before you can delete this user')); - } - } - - $db->query("DELETE FROM " . TABLE_PREFIX . "user WHERE userid = $user[userid]"); - $db->query("DELETE FROM " . TABLE_PREFIX . "favourite WHERE userid = $user[userid]"); - $db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = $user[userid]"); + $user = new UserAPI($bugsys); + $user->set('userid', $bugsys->in['userid']); + $user->set_condition(); + $user->delete(); $admin->redirect('user.php'); } @@ -87,8 +68,6 @@ if ($_POST['do'] == 'insert') $user->set('password', $bugsys->in['password']); $user->insert(); - build_assignedto(); - $admin->redirect('user.php?do=edit&userid=' . $db->insert_id()); } @@ -109,8 +88,6 @@ if ($_POST['do'] == 'update') $user->set('password', $bugsys->in['password']); $user->update(); - build_assignedto(); - $admin->redirect('user.php?do=edit&userid=' . $user['userid']); } diff --git a/includes/api_user.php b/includes/api_user.php index 9a519e0..9cf39a0 100644 --- a/includes/api_user.php +++ b/includes/api_user.php @@ -21,6 +21,8 @@ $GLOBALS['isso:callback']->load('api', null); +require_once('./includes/functions_datastore.php'); + /** * API: User * @@ -98,6 +100,17 @@ class UserAPI extends API $this->set('password', md5(md5($this->values['password']) . md5($this->values['salt']))); } + // ################################################################### + /** + * Post-insert + * + * @access protected + */ + function post_insert() + { + build_assignedto(); + } + // ################################################################### /** * Verify: email @@ -172,6 +185,55 @@ class UserAPI extends API $this->set('password', md5(md5($this->values['password']) . md5($this->objdata['salt']))); } } + + // ################################################################### + /** + * Post-update + * + * @access protected + */ + function post_update() + { + build_assignedto(); + } + + // ################################################################### + /** + * Pre-delete + * + * @access protected + */ + function pre_delete() + { + if ($this->values['userid'] == $this->registry->userinfo['userid']) + { + $this->error($lang->string('You cannot delete your own account!')); + } + + if ($this->values['usergroupid'] == 6) + { + $count = $this->registry->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 6 AND userid <> " . $this->values['userid']); + if ($count['count'] < 1) + { + $this->error($lang->string('At least one other administrator needs to be present before you can delete this user')); + } + } + } + + // ################################################################### + /** + * Post-delete + * + * @access protected + */ + function post_delete() + { + $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "user WHERE userid = " . $this->values['userid']); + $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "favourite WHERE userid = " . $this->values['userid']); + $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid = " . $this->values['userid']); + + build_assignedto(); + } } /*=====================================================================*\ -- 2.22.5