/**
  * Unban Users
  *
  * @param mixed $ids
  */
 public static function unbanUsers($ids)
 {
     global $db, $TNB_GLOBALS;
     if (!is_array($ids)) {
         $ids = [$ids];
     }
     //Check the user has lready been banned or not
     $rows = $db->getResultsArray("SELECT * FROM " . TABLE_BANNED_USERS . " WHERE bannedID IN (" . implode(', ', $ids) . ")");
     if ($rows) {
         foreach ($rows as $brow) {
             $userID = $brow['bannedUserID'];
             //Change User Table
             $db->query("UPDATE " . TABLE_USERS . " SET status=1 WHERE userID=" . $userID);
             //Change Posts table
             $db->query("UPDATE " . TABLE_POSTS . " SET post_status=1 WHERE poster=" . $userID);
             //Change Activities
             $db->query("UPDATE " . TABLE_MAIN_ACTIVITIES . " SET activityStatus=1 WHERE userID=" . $userID);
             //Change Messages
             $db->query("UPDATE " . TABLE_MESSAGES . " SET messageStatus=1 WHERE sender=" . $userID);
             //Fix Comments Count
             $query = $db->prepare("SELECT count(commentID) AS c, postID FROM " . TABLE_POSTS_COMMENTS . " WHERE commenter=%d AND commentStatus=0 GROUP BY postID", $userID);
             $pcRows = $db->getResultsArray($query);
             foreach ($pcRows as $row) {
                 $db->query("UPDATE " . TABLE_POSTS . " SET `comments` = `comments` + " . $row['c'] . " WHERE postID=" . $row['postID']);
             }
             //Unblock Comments
             $db->query("UPDATE " . TABLE_POSTS_COMMENTS . " SET commentStatus=1 WHERE commenter=" . $userID);
             //Fix Likes Count
             $query = $db->prepare("SELECT count(likeID) AS c, postID FROM " . TABLE_POSTS_LIKES . " WHERE userID=%d AND likeStatus=0 GROUP BY postID", $userID);
             $plRows = $db->getResultsArray($query);
             foreach ($plRows as $row) {
                 $db->query("UPDATE " . TABLE_POSTS . " SET `likes` = `likes` + " . $row['c'] . " WHERE postID=" . $row['postID']);
             }
             //Unblock Likes
             $db->query("UPDATE " . TABLE_POSTS_LIKES . " SET likeStatus=1 WHERE userID=" . $userID);
             //Unblock Votes for Moderator
             $query = $db->prepare("SELECT count(voteID) AS c, candidateID FROM " . TABLE_MODERATOR_VOTES . " WHERE voterID=%d AND voteStatus=0 GROUP BY candidateID", $userID);
             $vRows = $db->getResultsArray($query);
             foreach ($vRows as $row) {
                 $db->query("UPDATE " . TABLE_MODERATOR_CANDIDATES . " SET `votes` = `votes` + " . $row['c'] . " WHERE candidateID=" . $row['candidateID']);
             }
             $db->query("UPDATE " . TABLE_MODERATOR_VOTES . " SET voteStatus=1 WHERE voterID=" . $userID);
             //Unblock Replies
             $query = $db->prepare("SELECT count(r.replyID), r.topicID, t.categoryID FROM " . TABLE_FORUM_REPLIES . " AS r LEFT JOIN " . TABLE_FORUM_TOPICS . " AS t ON t.topicID=r.topicID WHERE r.status='suspended' AND r.creatorID=%d GROUP BY r.topicID", $userID);
             $rRows = $db->getResultsArray($query);
             $db->query("UPDATE " . TABLE_FORUM_REPLIES . " SET `status`='publish' WHERE creatorID=" . $userID . " AND `status`='suspended'");
             foreach ($rRows as $row) {
                 $db->query("UPDATE " . TABLE_FORUM_TOPICS . " SET `replies` = `replies` + " . $row['c'] . " WHERE topicID=" . $row['topicID']);
                 $db->query("UPDATE " . TABLE_FORUM_CATEGORIES . " SET `replies` = `replies` + " . $row['c'] . " WHERE categoryID=" . $row['categoryID']);
                 BuckysForumTopic::updateTopicLastReplyID($row['topicID']);
                 BuckysForumCategory::updateCategoryLastTopicID($row['categoryID']);
             }
             //unblock Topics
             $query = $db->prepare("SELECT count(topicID) AS tc, SUM(replies) AS rc, categoryID FROM " . TABLE_FORUM_TOPICS . " WHERE creatorID=%d AND `status`='suspended' GROUP BY categoryID", $userID);
             $tRows = $db->getResultsArray($query);
             $db->query("UPDATE " . TABLE_FORUM_TOPICS . " SET `status`='publish' WHERE creatorID=" . $userID . " AND `status`='suspended'");
             foreach ($tRows as $row) {
                 $db->query("UPDATE " . TABLE_FORUM_CATEGORIES . " SET `replies` = `replies` + " . $row['rc'] . ", `topics` = `topics` + " . $row['tc'] . " WHERE categoryID=" . $row['categoryID']);
                 BuckysForumCategory::updateCategoryLastTopicID($row['categoryID']);
             }
             //Unblock Reply Votes
             $query = $db->prepare("SELECT count(voteID) AS c, objectID FROM " . TABLE_FORUM_VOTES . " WHERE voterID=%d AND voteStatus=0 GROUP BY objectID", $userID);
             $vRows = $db->getResultsArray($query);
             foreach ($vRows as $row) {
                 $db->query("UPDATE " . TABLE_FORUM_REPLIES . " SET `votes` = `votes` + " . $row['c'] . " WHERE replyID=" . $row['objectID']);
             }
             $db->query("UPDATE " . TABLE_FORUM_VOTES . " SET voteStatus=1 WHERE voterID=" . $userID);
             //Unblock page section & Trade section
             $tradeItemIns = new BuckysTradeItem();
             $tradeOfferIns = new BuckysTradeOffer();
             $pageIns = new BuckysPage();
             $tradeItemIns->massStatusChange($userID, BuckysTradeItem::STATUS_ITEM_ACTIVE);
             $tradeOfferIns->massStatusChange($userID, BuckysTradeOffer::STATUS_OFFER_ACTIVE);
             $pageIns->massStatusChange($userID, BuckysPage::STATUS_ACTIVE);
             //enable Shop Products
             $shopProdIns = new BuckysShopProduct();
             $shopProdIns->massStatusChange($userID, BuckysShopProduct::STATUS_ACTIVE);
             //Remove From banned users table
             $db->query("DELETE FROM " . TABLE_BANNED_USERS . "  WHERE bannedID=" . $brow['bannedID']);
         }
     }
 }