Пример #1
0
	/**
	* DeleteUsers
	* Deletes a list of users from the database via the api. Each user is checked to make sure you're not going to accidentally delete your own account and that you're not going to delete the 'last' something (whether it's the last active user, admin user or other).
	* If you aren't an admin user, you can't do anything at all.
	*
	* @param integer[] $users An array of userid's to delete
	* @param boolean $deleteData Whether or not to delete data owned by user along
	*
	* @see GetUser
	* @see User_API::UserAdmin
	* @see DenyAccess
	* @see CheckUserSystem
	* @see PrintManageUsers
	*
	* @return Void Doesn't return anything. Works out the relevant message about who was/wasn't deleted and prints that out. Returns control to PrintManageUsers.
	*/
	function DeleteUsers($users = array(), $deleteData = false)
	{
		$thisuser = GetUser();
		if (!$thisuser->UserAdmin()) {
			$this->DenyAccess();
			return;
		}

		if (!is_array($users)) {
			$users = array($users);
		}

		$not_deleted_list = array();
		$not_deleted = $deleted = 0;
		foreach ($users as $p => $userid) {
			if ($userid == $thisuser->Get('userid')) {
				$not_deleted++;
				$not_deleted_list[$userid] = array('username' => $thisuser->Get('username'), 'reason' => GetLang('User_CantDeleteOwn'));
				continue;
			}

			$error = $this->CheckUserSystem($userid);
			if (!$error) {
				$result = API_USERS::deleteRecordByID($userid, $deleteData);

				if ($result) {
					$deleted++;
				} else {
					$not_deleted++;
					$user = GetUser($userid);
					if ($user instanceof User_API) {
						$not_deleted_list[$userid] = array('username' => $user->Get('username'), 'reason' => '');
					} else {
						$not_deleted_list[$userid] = array('username' => $userid, 'reason' => '');
					}
				}
			} else {
				$not_deleted++;
				$user = GetUser($userid);
				if ($user instanceof User_API) {
					$not_deleted_list[$userid] = array('username' => $user->Get('username'), 'reason' => $error);
				} else {
					$not_deleted_list[$userid] = array('username' => $userid, 'reason' => $error);
				}
			}
		}


		if ($not_deleted > 0) {
			foreach ($not_deleted_list as $uid => $details) {
				FlashMessage(sprintf(GetLang('UserDeleteFail'), htmlspecialchars($details['username'], ENT_QUOTES, SENDSTUDIO_CHARSET), htmlspecialchars($details['reason'], ENT_QUOTES, SENDSTUDIO_CHARSET)), SS_FLASH_MSG_ERROR);
			}
		}

		if ($deleted > 0) {
			if ($deleted == 1) {
				FlashMessage(GetLang('UserDeleteSuccess_One'), SS_FLASH_MSG_SUCCESS, IEM::urlFor('Users'));
			} else {
				FlashMessage(sprintf(GetLang('UserDeleteSuccess_Many'), $this->FormatNumber($deleted)), SS_FLASH_MSG_SUCCESS, IEM::urlFor('Users'));
			}
		}

		IEM::redirectTo('Users');
	}
Пример #2
0
    /**
     * Delete
     * Delete a user from the database and revokes all of their access. Checks are done elsewhere to make sure this isn't the last active user or last admin user.
     *
     * @see LastUser
     * @see LastActiveUser
     * @see LastAdminUser
     *
     * @param Int $userid Userid of the user to delete. If not passed in, it will delete 'this' user.
     *
     * @return Boolean True if it deleted the user, false otherwise.
     *
     */
    function Delete($userid=0) {
        if ($userid == 0) {
            $userid = $this->userid;
        }

        if (!API_USERS::deleteRecordByID($userid, false)) {
            return false;
        }

        $this->access = array('lists' => array(), 'templates' => array(), 'segments' => array());
        $this->permissions = array();

        $this->userid = 0;
        $this->username = '';
        $this->fullname = '';
        $this->emailaddress = '';
        $this->status = false;

        // admin permissions
        $this->systemadmin = false;
        $this->listadmin = false;
        $this->templateadmin = false;
        $this->segmentadmin = false;

        // admin types
        $this->admintype = 'c';
        $this->listadmintype = 'c';
        $this->templateadmintype = 'c';
        $this->segmentadmintype = 'c';

        $this->infotips = false;

        $this->editownsettings = false;
        $this->password = null;
        $this->usertimezone = false;
        $this->textfooter = '';
        $this->htmlfooter = '';
        $this->usewysiwyg = true;
        $this->enableactivitylog = false;
        $this->gettingstarted = 1;

        $this->xmlapi = false;
        $this->xmltoken = null;

        return true;
    }