/**
  * Toggle the posts approve thingy
  *
  * @access	private
  * @return	void
  **/
 private function _postApproveToggle()
 {
     /* INIT */
     $topicID = intval($this->request['t']);
     $postID = intval($this->request['p']);
     $approve = $this->request['approve'] == 1 ? TRUE : FALSE;
     $_yoGo = FALSE;
     require IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
     $_modLibrary = new moderatorLibrary($this->registry);
     /* Load topic */
     $topic = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'topics', 'where' => 'tid=' . $topicID));
     if (!$topic['tid']) {
         $this->returnJsonArray(array('error' => 'notopic'));
     }
     /* Permission Checks */
     if ($this->memberData['g_is_supmod']) {
         $_yoGo = TRUE;
     } else {
         if (is_array($this->memberData['forumsModeratorData']) and $this->memberData['forumsModeratorData'][$topic['forum_id']]['post_q']) {
             $_yoGo = TRUE;
         }
     }
     if (!$_yoGo) {
         $this->returnJsonArray(array('error' => 'nopermission'));
     }
     $_modLibrary->postToggleApprove(array($postID), $approve, $topicID);
     $this->returnJsonArray(array('status' => 'ok', 'postApproved' => $approve));
 }
 /**
  * Delete a forum
  *
  * @access	public
  * @return	void		Outputs to screen
  **/
 public function doDelete()
 {
     //-----------------------------------------
     // Auth check...
     //-----------------------------------------
     $this->registry->adminFunctions->checkSecurityKey();
     //-----------------------------------------
     // Continue
     //-----------------------------------------
     $this->request['f'] = intval($this->request['f']);
     $this->request['MOVE_ID'] = intval($this->request['MOVE_ID']);
     $this->request['new_parent_id'] = intval($this->request['new_parent_id']);
     $forum = $this->registry->class_forums->forum_by_id[$this->request['f']];
     if (!$forum['id']) {
         $this->registry->output->showError($this->lang->words['for_noid_source'], 11313);
     }
     if (!$this->request['new_parent_id']) {
         $this->request['new_parent_id'] = -1;
     } else {
         if ($this->request['new_parent_id'] == $this->request['f']) {
             $this->registry->output->global_message = $this->lang->words['for_child_no_parent'];
             $this->deleteForm();
             return;
         }
     }
     //-----------------------------------------
     // Would deleting this category orphan the only
     // remaining forums?
     //-----------------------------------------
     if ($forum['parent_id'] == -1) {
         $otherParent = 0;
         foreach ($this->registry->class_forums->forum_by_id as $id => $data) {
             if ($data['parent_id'] == -1) {
                 $otherParent = $id;
                 break;
             }
         }
         if (!$otherParent) {
             $this->registry->output->showError($this->lang->words['nodelete_last_cat'], 11364);
         }
     }
     //-----------------------------------------
     // Get library
     //-----------------------------------------
     require_once IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
     $modfunc = new moderatorLibrary($this->registry);
     //-----------------------------------------
     // Move stuff
     //-----------------------------------------
     if ($this->request['MOVE_ID']) {
         if ($this->request['MOVE_ID'] == $this->request['f']) {
             $this->registry->output->global_message = $this->lang->words['for_wherewhatwhy'];
             $this->deleteForm();
         }
         //-----------------------------------------
         // Move topics...
         //-----------------------------------------
         $this->DB->update('topics', array('forum_id' => $this->request['MOVE_ID']), 'forum_id=' . $this->request['f']);
         //-----------------------------------------
         // Move polls...
         //-----------------------------------------
         $this->DB->update('polls', array('forum_id' => $this->request['MOVE_ID']), 'forum_id=' . $this->request['f']);
         //-----------------------------------------
         // Move voters...
         //-----------------------------------------
         $this->DB->update('voters', array('forum_id' => $this->request['MOVE_ID']), 'forum_id=' . $this->request['f']);
         $modfunc->forumRecount($this->request['MOVE_ID']);
     }
     //-----------------------------------------
     // Delete the forum
     //-----------------------------------------
     $this->DB->delete('forums', "id=" . $this->request['f']);
     $this->DB->delete('permission_index', "app='forums' AND perm_type='forum' AND perm_type_id=" . $this->request['f']);
     //-----------------------------------------
     // Remove moderators from this forum
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'moderators', 'where' => "forum_id LIKE '%,{$this->request['f']},%'"));
     $outer = $this->DB->execute();
     while ($r = $this->DB->fetch($outer)) {
         $forums = explode(',', IPSText::cleanPermString($r['forum_id']));
         $newForums = array();
         foreach ($forums as $aForumId) {
             if ($aForumId != $this->request['f']) {
                 $newForums[] = $aForumId;
             }
         }
         if (!count($newForums)) {
             $this->DB->delete('moderators', "mid=" . $r['mid']);
         } else {
             $this->DB->update('moderators', array('forum_id' => ',' . implode(',', $newForums) . ','), 'mid=' . $r['mid']);
         }
     }
     //-----------------------------------------
     // Delete forum subscriptions
     //-----------------------------------------
     $this->DB->delete('forum_tracker', "forum_id=" . $this->request['f']);
     //-----------------------------------------
     // Update children
     //-----------------------------------------
     $this->DB->update('forums', array('parent_id' => $this->request['new_parent_id']), "parent_id=" . $this->request['f']);
     //-----------------------------------------
     // Rebuild forum cache
     //-----------------------------------------
     $this->recacheForums();
     //-----------------------------------------
     // Rebuild moderator cache
     //-----------------------------------------
     require_once IPSLib::getAppDir('forums') . '/modules_admin/forums/moderator.php';
     $moderator = new admin_forums_forums_moderator($this->registry);
     $moderator->makeRegistryShortcuts($this->registry);
     $moderator->rebuildModeratorCache();
     $this->registry->adminFunctions->saveAdminLog(sprintf($this->lang->words['for_removedlog'], $forum['name']));
     $this->registry->output->doneScreen($this->lang->words['for_removed'], $this->lang->words['for_control'], $this->form_code, 'redirect');
 }
 /**
  * Manage spam requests
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _unSpam()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $ids = array();
     //-----------------------------------------
     // GET checkboxes
     //-----------------------------------------
     foreach ($this->request as $k => $v) {
         if (preg_match("/^mid_(\\d+)\$/", $k, $match)) {
             if ($v) {
                 $ids[] = $match[1];
             }
         }
     }
     $ids = IPSLib::cleanIntArray($ids);
     //-----------------------------------------
     // Check
     //-----------------------------------------
     if (count($ids) < 1) {
         $this->registry->output->showError($this->lang->words['t_nomemunspammed'], 11248);
     }
     //-----------------------------------------
     // Unspam
     //-----------------------------------------
     if ($this->request['type'] == 'unspam' or $this->request['type'] == 'unspam_posts') {
         try {
             foreach ($ids as $i) {
                 IPSMember::save($i, array('core' => array('bw_is_spammer' => 0, 'restrict_post' => 0, 'members_disable_pm' => 0)));
             }
         } catch (Exception $error) {
             $this->registry->output->showError($error->getMessage(), 11247);
         }
         if ($this->request['type'] == 'unspam_posts') {
             /* Toggle their content */
             require IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
             $modLibrary = new moderatorLibrary($this->registry);
             foreach ($ids as $id) {
                 $modLibrary->toggleApproveMemberContent($id, TRUE, 'all', intval($this->settings['spm_post_days']) * 24);
             }
         }
         ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_memunspammed']);
         $this->registry->output->global_message = count($ids) . $this->lang->words['t_memunspammed'];
         $this->_viewQueue('spam');
         return;
     } else {
         if ($this->request['type'] == 'ban' or $this->request['type'] == 'ban_blacklist') {
             try {
                 foreach ($ids as $i) {
                     IPSMember::save($i, array('core' => array('bw_is_spammer' => 0, 'member_banned' => 1)));
                 }
             } catch (Exception $error) {
                 $this->registry->output->showError($error->getMessage(), 11247);
             }
             if ($this->request['type'] == 'ban_blacklist') {
                 /* Load Members */
                 $members = IPSMember::load($ids);
                 $ips = array();
                 $email = array();
                 $ban = array('ip' => array(), 'email' => array());
                 if (is_array($members) and count($members)) {
                     foreach ($members as $id => $data) {
                         $ips[] = $data['ip_address'];
                         $email[] = $data['email'];
                     }
                     if (count($ips)) {
                         /* IPS: Check for duplicate */
                         $this->DB->build(array('select' => '*', 'from' => 'banfilters', 'where' => "ban_content IN ('" . implode("','", $ips) . "') and ban_type='ip'"));
                         $this->DB->execute();
                         while ($row = $this->DB->fetch()) {
                             $ban['ip'][] = $row['ban_content'];
                         }
                         /* Now insert.. */
                         foreach ($ips as $i) {
                             if (!in_array($i, $ban['ip'])) {
                                 /* Insert the new ban filter */
                                 $this->DB->insert('banfilters', array('ban_type' => 'ip', 'ban_content' => $i, 'ban_date' => time(), 'ban_nocache' => 1));
                             }
                         }
                     }
                     if (count($email)) {
                         /* IPS: Check for duplicate */
                         $this->DB->build(array('select' => '*', 'from' => 'banfilters', 'where' => "ban_content IN ('" . implode("','", $email) . "') and ban_type='email'"));
                         $this->DB->execute();
                         while ($row = $this->DB->fetch()) {
                             $ban['email'][] = $row['ban_content'];
                         }
                         /* Now insert.. */
                         foreach ($email as $e) {
                             if (!in_array($e, $ban['email'])) {
                                 /* Insert the new ban filter */
                                 $this->DB->insert('banfilters', array('ban_type' => 'email', 'ban_content' => $e, 'ban_date' => time(), 'ban_nocache' => 1));
                             }
                         }
                     }
                 }
             }
             ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_membanned']);
             $this->registry->output->global_message = count($ids) . $this->lang->words['t_membanned'];
             $this->_viewQueue('spam');
             return;
         }
     }
 }
 /**
  * Add a new arn entry
  *
  * @access	private
  * @return	void		[Outputs to screen/redirects]
  */
 private function _doWarn()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $save = array();
     $err = 0;
     $topicPosts_type = trim($this->request['topicPosts_type']);
     $topicPosts_topics = intval($this->request['topicPosts_topics']);
     $topicPosts_replies = intval($this->request['topicPosts_replies']);
     $topicPosts_lastx = intval($this->request['topicPosts_lastx']);
     $topicPosts_lastxunits = trim($this->request['topicPosts_lastxunits']);
     $level_custom = intval($this->request['level_custom']);
     $ban_indef = intval($this->request['ban_indef']);
     $member_banned = intval($this->warn_member['member_banned']);
     $warn_level = intval($this->warn_member['warn_level']);
     //-----------------------------------------
     // Load Mod Squad
     //-----------------------------------------
     require_once IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
     $moderatorLibrary = new moderatorLibrary($this->registry);
     //-----------------------------------------
     // Security checks
     //-----------------------------------------
     if ($this->type == 'member') {
         $this->registry->output->showError('warn_member_notes', 2028);
     }
     //-----------------------------------------
     // Check security fang
     //-----------------------------------------
     if ($this->request['key'] != $this->member->form_hash) {
         $this->registry->output->showError('warn_bad_key', 3020);
     }
     //-----------------------------------------
     // As Celine Dion once squawked, "Show me the reason"
     //-----------------------------------------
     if (trim($this->request['reason']) == "") {
         $this->_showForm('we_no_reason');
         return;
     }
     //-----------------------------------------
     // Other checks
     //-----------------------------------------
     if (!$this->settings['warn_past_max'] && $this->request['level'] != 'nochange') {
         if ($this->request['level'] == 'custom') {
             if ($level_custom > $this->settings['warn_max']) {
                 $err = 1;
             } else {
                 if ($level_custom < $this->settings['warn_min']) {
                     $err = 2;
                 }
             }
         } else {
             if ($this->request['level'] == 'add') {
                 if ($warn_level >= $this->settings['warn_max']) {
                     $err = 1;
                 }
             } else {
                 if ($warn_level <= $this->settings['warn_min']) {
                     $err = 2;
                 }
             }
         }
         if ($err) {
             $this->registry->output->showError($err == 1 ? 'warn_past_max_high' : 'warn_past_max_low', 10251);
         }
     }
     //-----------------------------------------
     // Plussy - minussy?
     //-----------------------------------------
     if ($this->request['level'] == 'nochange') {
         $save['wlog_type'] = 'nochan';
     } else {
         $save['wlog_type'] = $this->request['level'] == 'custom' ? 'custom' : ($this->request['level'] == 'add' ? 'neg' : 'pos');
     }
     $save['wlog_date'] = time();
     //-----------------------------------------
     // Contacting the member?
     //-----------------------------------------
     $test_content = trim(IPSText::br2nl($_POST['contact']));
     if ($test_content != "") {
         if (trim($this->request['subject']) == "") {
             $this->_showForm('we_no_subject');
             return;
         }
         unset($test_content);
         if (IPSText::getTextClass('editor')->method == 'rte') {
             $this->request['contact'] = IPSText::getTextClass('editor')->processRawPost('contact');
         }
         IPSText::getTextClass('bbcode')->parse_smilies = 1;
         IPSText::getTextClass('bbcode')->parse_html = 0;
         IPSText::getTextClass('bbcode')->parse_bbcode = 1;
         IPSText::getTextClass('bbcode')->parsing_section = 'warn';
         $save['wlog_contact'] = $this->request['contactmethod'];
         $save['wlog_contact_content'] = "<subject>" . $this->request['subject'] . "</subject><content>" . $this->request['contact'] . "</content>";
         $save['wlog_contact_content'] = IPSText::getTextClass('bbcode')->preDbParse($save['wlog_contact_content']);
         if ($this->request['contactmethod'] == 'email') {
             IPSText::getTextClass('bbcode')->parse_smilies = 0;
             IPSText::getTextClass('bbcode')->parse_html = 1;
             IPSText::getTextClass('bbcode')->parse_bbcode = 1;
             IPSText::getTextClass('bbcode')->parsing_section = 'warn';
             IPSText::getTextClass('bbcode')->parsing_mgroup = $this->memberData['member_group_id'];
             IPSText::getTextClass('bbcode')->parsing_mgroup_others = $this->memberData['mgroup_others'];
             $this->request['contact'] = IPSText::getTextClass('bbcode')->preDisplayParse(IPSText::getTextClass('bbcode')->preDbParse($this->request['contact']));
             //-----------------------------------------
             // Send the email
             //-----------------------------------------
             IPSText::getTextClass('email')->getTemplate("email_member");
             IPSText::getTextClass('email')->buildMessage(array('MESSAGE' => IPSText::br2nl($this->request['contact']), 'MEMBER_NAME' => $this->warn_member['members_display_name'], 'FROM_NAME' => $this->memberData['members_display_name']));
             IPSText::getTextClass('email')->subject = $this->request['subject'];
             IPSText::getTextClass('email')->to = $this->warn_member['email'];
             IPSText::getTextClass('email')->from = $this->settings['email_out'];
             IPSText::getTextClass('email')->sendMail();
         } else {
             //-----------------------------------------
             // Grab PM class
             //-----------------------------------------
             require_once IPSLib::getAppDir('members') . '/sources/classes/messaging/messengerFunctions.php';
             $messengerFunctions = new messengerFunctions($this->registry);
             try {
                 $messengerFunctions->sendNewPersonalTopic($this->warn_member['member_id'], $this->memberData['member_id'], array(), $this->request['subject'], IPSText::getTextClass('editor')->method == 'rte' ? nl2br($_POST['contact']) : $_POST['contact'], array('origMsgID' => 0, 'fromMsgID' => 0, 'postKey' => md5(microtime()), 'trackMsg' => 0, 'addToSentFolder' => 0, 'hideCCUser' => 0, 'forcePm' => 1));
             } catch (Exception $error) {
                 $msg = $error->getMessage();
                 $toMember = IPSMember::load($this->warn_member['member_id'], 'core');
                 if (strstr($msg, 'BBCODE_')) {
                     $msg = str_replace('BBCODE_', '', $msg);
                     $this->registry->output->showError($msg, 10252);
                 } else {
                     if (isset($this->lang->words['err_' . $msg])) {
                         $this->lang->words['err_' . $msg] = $this->lang->words['err_' . $msg];
                         $this->lang->words['err_' . $msg] = str_replace('#NAMES#', implode(",", $messengerFunctions->exceptionData), $this->lang->words['err_' . $msg]);
                         $this->lang->words['err_' . $msg] = str_replace('#TONAME#', $toMember['members_display_name'], $this->lang->words['err_' . $msg]);
                         $this->lang->words['err_' . $msg] = str_replace('#FROMNAME#', $this->memberData['members_display_name'], $this->lang->words['err_' . $msg]);
                         $this->registry->output->showError('err_' . $msg, 10253);
                     } else {
                         if ($msg != 'CANT_SEND_TO_SELF') {
                             $_msgString = $this->lang->words['err_UNKNOWN'] . ' ' . $msg;
                             $this->registry->output->showError($_msgString, 10254);
                         }
                     }
                 }
             }
         }
     } else {
         unset($test_content);
     }
     //-----------------------------------------
     // Right - is we banned or wha?
     //-----------------------------------------
     $restrict_post = '';
     $mod_queue = '';
     $susp = '';
     $_notes = array();
     $_notes['content'] = $this->request['reason'];
     $_notes['mod'] = $this->request['mod_value'];
     $_notes['post'] = $this->request['post_value'];
     $_notes['susp'] = $this->request['susp_value'];
     $_notes['ban'] = $ban_indef;
     $_notes['topicPosts_type'] = $topicPosts_type;
     $_notes['topicPosts_topics'] = $topicPosts_topics;
     $_notes['topicPosts_replies'] = $topicPosts_replies;
     $_notes['topicPosts_lastx'] = $topicPosts_lastx;
     $_notes['topicPosts_lastxunits'] = $topicPosts_lastxunits;
     $save['wlog_notes'] = serialize($_notes);
     //-----------------------------------------
     // Member Content
     //-----------------------------------------
     if ($topicPosts_type == 'unapprove' or $topicPosts_type == 'approve') {
         $time = $topicPosts_lastxunits == 'd' ? $topicPosts_lastx * 24 : $topicPosts_lastx;
         $approve = $topicPosts_type == 'approve' ? TRUE : FALSE;
         if ($topicPosts_topics and $this->canApproveTopics and ($topicPosts_replies and $this->canApprovePosts)) {
             $moderatorLibrary->toggleApproveMemberContent($this->warn_member['member_id'], $approve, 'all', $time);
         } else {
             if ($topicPosts_topics and $this->canApproveTopics) {
                 $moderatorLibrary->toggleApproveMemberContent($this->warn_member['member_id'], $approve, 'topics', $time);
             } else {
                 if ($topicPosts_replies and $this->canApprovePosts) {
                     $moderatorLibrary->toggleApproveMemberContent($this->warn_member['member_id'], $approve, 'replies', $time);
                 }
             }
         }
     } else {
         if ($topicPosts_type == 'delete') {
             $time = $topicPosts_lastxunits == 'd' ? $topicPosts_lastx * 24 : $topicPosts_lastx;
             if ($topicPosts_topics and $this->canDeleteTopics and ($topicPosts_replies and $this->canDeletePosts)) {
                 $moderatorLibrary->deleteMemberContent($this->warn_member['member_id'], 'all', $time);
             } else {
                 if ($topicPosts_topics and $this->canDeleteTopics) {
                     $moderatorLibrary->deleteMemberContent($this->warn_member['member_id'], 'topics', $time);
                 } else {
                     if ($topicPosts_replies and $this->canDeletePosts) {
                         $moderatorLibrary->deleteMemberContent($this->warn_member['member_id'], 'replies', $time);
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Member Suspension
     //-----------------------------------------
     if ($this->canModQueue) {
         if ($this->request['mod_indef'] == 1) {
             $mod_queue = 1;
         } elseif ($this->request['mod_value'] > 0) {
             $mod_queue = IPSMember::processBanEntry(array('timespan' => intval($this->request['mod_value']), 'unit' => $this->request['mod_unit']));
         }
     }
     if ($this->canRemovePostAbility) {
         if ($this->request['post_indef'] == 1) {
             $restrict_post = 1;
         } elseif ($this->request['post_value'] > 0) {
             $restrict_post = IPSMember::processBanEntry(array('timespan' => intval($this->request['post_value']), 'unit' => $this->request['post_unit']));
         }
     }
     if ($this->canSuspend) {
         if ($ban_indef) {
             $member_banned = 1;
         } else {
             if ($this->request['susp_value'] > 0) {
                 $susp = IPSMember::processBanEntry(array('timespan' => intval($this->request['susp_value']), 'unit' => $this->request['susp_unit']));
             }
         }
         /* Were banned but now unticked? */
         if (!$ban_indef and $member_banned) {
             $member_banned = 0;
         }
     }
     $save['wlog_mid'] = $this->warn_member['member_id'];
     $save['wlog_addedby'] = $this->memberData['member_id'];
     //-----------------------------------------
     // Enter into warn loggy poos (eeew - poo)
     //-----------------------------------------
     $this->DB->insert('warn_logs', $save);
     //-----------------------------------------
     // Update member
     //-----------------------------------------
     if ($this->request['level'] != 'nochange') {
         if ($this->request['level'] == 'custom') {
             $warn_level = $level_custom;
         } else {
             if ($this->request['level'] == 'add') {
                 $warn_level++;
             } else {
                 $warn_level--;
             }
         }
         if ($warn_level > $this->settings['warn_max']) {
             $warn_level = $this->settings['warn_max'];
         }
         if ($warn_level < intval($this->settings['warn_min'])) {
             $warn_level = intval($this->settings['warn_min']);
         }
     }
     IPSMember::save($this->warn_member['member_id'], array('core' => array('mod_posts' => $mod_queue, 'restrict_post' => $restrict_post, 'temp_ban' => $susp, 'member_banned' => $member_banned, 'warn_level' => $warn_level, 'warn_lastwarn' => time())));
     //-----------------------------------------
     // Now what? Show success screen, that's what!!
     //-----------------------------------------
     $this->lang->words['w_done_te'] = sprintf($this->lang->words['w_done_te'], $this->warn_member['members_display_name']);
     $tid = intval($this->request['t']);
     $topic = array();
     if ($tid > 0) {
         $topic = $this->DB->buildAndFetch(array('select' => 't.tid, t.title, t.title_seo', 'from' => array('topics' => 't'), 'where' => "t.tid={$tid}", 'add_join' => array(array('select' => 'f.id, f.name, f.name_seo', 'from' => array('forums' => 'f'), 'where' => 'f.id=t.forum_id', 'type' => 'left'))));
     }
     $this->output .= $this->registry->getClass('output')->getTemplate('mod')->warn_success($topic);
 }
 /**
  * Resyncronize forum data
  *
  * @access	public
  * @return	void
  */
 public function resyncForums()
 {
     require_once IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
     $modfunc = new moderatorLibrary($this->registry);
     //-----------------------------------------
     // Set up
     //-----------------------------------------
     $done = 0;
     $start = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $end = intval($this->request['pergo']) ? intval($this->request['pergo']) : 100;
     $dis = $end + $start;
     $output = array();
     //-----------------------------------------
     // Got any more?
     //-----------------------------------------
     $tmp = $this->DB->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'forums', 'limit' => array($dis, 1)));
     $max = intval($tmp['count']);
     //-----------------------------------------
     // Avoid limit...
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'forums', 'order' => 'id ASC', 'limit' => array($start, $end)));
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Process...
     //-----------------------------------------
     while ($r = $this->DB->fetch($outer)) {
         $modfunc->forumRecount($r['id']);
         $output[] = "Processed forum " . $r['name'];
         $done++;
     }
     //-----------------------------------------
     // Finish - or more?...
     //-----------------------------------------
     if (!$done and !$max) {
         //-----------------------------------------
         // Done..
         //-----------------------------------------
         $text = $this->lang->words['re_rebuildcomp'] . implode("<br />", $output);
         $url = "{$this->settings['base_url']}{$this->form_code}";
         $time = 2;
     } else {
         //-----------------------------------------
         // More..
         //-----------------------------------------
         $thisgoeshere = sprintf($this->lang->words['re_thisgoeshere'], $dis);
         $text = $thisgoeshere . implode("<br />", $output);
         $url = "{$this->settings['base_url']}{$this->form_code}&do={$this->request['do']}&pergo={$this->request['pergo']}&st={$dis}";
         $time = 0;
     }
     //-----------------------------------------
     // Bye....
     //-----------------------------------------
     $this->registry->output->redirect($url, $text, $time);
 }
 /**
  * Delete a member's posts [process]
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _deletePostsDo()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $member_id = intval($this->request['member_id']);
     $delete_posts = intval($this->request['dposts']);
     $delete_topics = intval($this->request['dtopics']);
     $end = intval($this->request['dpergo']) ? intval($this->request['dpergo']) : 50;
     $init = intval($this->request['init']);
     $done = 0;
     $start = intval($this->request['st']) >= 0 ? intval($this->request['st']) : 0;
     $forums_affected = array();
     $topics_affected = array();
     $img = '<img src="' . $this->settings['skin_acp_url'] . '/images/aff_tick_small.png" border="0" alt="-" /> ';
     $posts_deleted = 0;
     $topics_deleted = 0;
     //--------------------------------------------
     // NOT INIT YET?
     //--------------------------------------------
     if (!$init) {
         $url = $this->settings['base_url'] . '&' . $this->form_code_js . "&do=deleteposts_process&dpergo=" . $this->request['dpergo'] . "&st=0" . "&init=1" . "&dposts={$delete_posts}" . "&dtopics={$delete_topics}" . "&use_trash_can=" . intval($this->request['use_trash_can']) . "&member_id={$member_id}";
         $this->registry->output->multipleRedirectInit($url);
     }
     //--------------------------------------------
     // Not loaded the func?
     //--------------------------------------------
     if (!is_object($mod_func)) {
         require_once IPS_ROOT_PATH . 'sources/classes/itemmarking/classItemMarking.php';
         $this->registry->setClass('classItemMarking', new classItemMarking($this->registry));
         require_once IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
         $mod_func = new moderatorLibrary($this->registry);
     }
     //-----------------------------------------
     // Trash-can set up
     //-----------------------------------------
     $trash_append = '';
     if ($this->settings['forum_trash_can_enable'] and $this->settings['forum_trash_can_id']) {
         if ($this->registry->class_forums->forum_by_id[$this->settings['forum_trash_can_id']]['sub_can_post']) {
             if ($this->request['use_trash_can']) {
                 $this->trash_forum = $this->settings['forum_trash_can_id'];
                 $trash_append = " AND forum_id<>{$this->trash_forum}";
             }
         }
     }
     //-----------------------------------------
     // Get member
     //-----------------------------------------
     $member = IPSMember::load($member_id, 'core');
     //-----------------------------------------
     // Avoid limit...
     //-----------------------------------------
     $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => "p.author_id={$member_id}{$trash_append}", 'order' => 'p.pid ASC', 'limit' => array($start, $end), 'add_join' => array(array('select' => 't.*', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'))));
     $outer = $this->DB->execute();
     //-----------------------------------------
     // Process...
     //-----------------------------------------
     while ($r = $this->DB->fetch($outer)) {
         //-----------------------------------------
         // Copy record to topic array
         //-----------------------------------------
         $topic = $r;
         //-----------------------------------------
         // No longer a topic?
         //-----------------------------------------
         if (!$topic['tid']) {
             continue;
         }
         $done++;
         //-----------------------------------------
         // Get number of MID posters
         //-----------------------------------------
         $topic_i_posted = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'posts', 'where' => 'author_id=' . $member_id . ' AND topic_id=' . $r['topic_id']));
         //-----------------------------------------
         // Aready deleted this topic?
         //-----------------------------------------
         if (!$topic_i_posted['count']) {
             continue;
         }
         //-----------------------------------------
         // First check: Our topic and no other replies?
         //-----------------------------------------
         if ($topic['starter_id'] == $member_id and $topic_i_posted['count'] == $topic['posts'] + 1) {
             //-----------------------------------------
             // Ok, deleting topics or posts?
             //-----------------------------------------
             if (($delete_posts or $delete_topics) and ($this->trash_forum and $this->trash_forum != $topic['forum_id'])) {
                 //-----------------------------------------
                 // Move, don't delete
                 //-----------------------------------------
                 $mod_func->topicMove($r['topic_id'], $topic['forum_id'], $this->trash_forum);
                 $forums_affected[$topic['forum_id']] = $topic['forum_id'];
                 $forums_affected[$this->trash_forum] = $this->trash_forum;
                 $topics_deleted++;
                 $posts_deleted += $topic_i_posted['count'];
             } else {
                 if ($delete_posts or $delete_topics) {
                     $this->DB->delete('posts', 'author_id=' . $member_id . ' AND topic_id=' . $r['topic_id']);
                     $this->DB->delete('topics', 'tid=' . $r['topic_id']);
                     $forums_affected[$topic['forum_id']] = $topic['forum_id'];
                     $topics_deleted++;
                     $posts_deleted += $topic_i_posted['count'];
                 }
             }
         } else {
             if ($topic['starter_id'] == $member_id and $delete_topics) {
                 if ($this->trash_forum and $this->trash_forum != $topic['forum_id']) {
                     //-----------------------------------------
                     // Move, don't delete
                     //-----------------------------------------
                     $mod_func->topicMove($r['topic_id'], $topic['forum_id'], $this->trash_forum);
                     $forums_affected[$topic['forum_id']] = $topic['forum_id'];
                     $forums_affected[$this->trash_forum] = $this->trash_forum;
                     $topics_deleted++;
                     $posts_deleted += $topic_i_posted['count'];
                 } else {
                     $this->DB->delete('posts', 'topic_id=' . $r['topic_id']);
                     $this->DB->delete('topics', 'tid=' . $r['topic_id']);
                     $forums_affected[$topic['forum_id']] = $topic['forum_id'];
                     $topics_deleted++;
                     $posts_deleted += $topic['posts'] + 1;
                 }
             } else {
                 if ($delete_posts and !$r['new_topic']) {
                     if ($this->trash_forum and $this->trash_forum != $topic['forum_id']) {
                         //-----------------------------------------
                         // Set up and pass to split topic handler
                         //-----------------------------------------
                         $new_title = $this->lang->words['acp_posts_deleted_from'] . $topic['title'];
                         $new_desc = $this->lang->words['acp_posts_deleted_from_tid'] . $topic['tid'];
                         //-----------------------------------------
                         // Is first post queued?
                         //-----------------------------------------
                         $topic_approved = 1;
                         $first_post = $this->DB->buildAndFetch(array('select' => 'pid, queued', 'from' => 'posts', 'where' => "pid=" . $r['pid']));
                         if ($first_post['queued']) {
                             $topic_approved = 0;
                             $this->DB->update('posts', array('queued' => 0), 'pid=' . $first_post['pid']);
                         }
                         //-----------------------------------------
                         // Complete a new dummy topic
                         //-----------------------------------------
                         $this->DB->insert('topics', array('title' => $new_title, 'description' => $new_desc, 'state' => 'open', 'posts' => 0, 'starter_id' => $member_id, 'starter_name' => $member['members_display_name'], 'start_date' => time(), 'last_poster_id' => $member_id, 'last_poster_name' => $member['members_display_name'], 'last_post' => time(), 'icon_id' => 0, 'author_mode' => 1, 'poll_state' => 0, 'last_vote' => 0, 'views' => 0, 'forum_id' => $this->trash_forum, 'approved' => $topic_approved, 'pinned' => 0));
                         $new_topic_id = $this->DB->getInsertId();
                         //-----------------------------------------
                         // Move the posts
                         //-----------------------------------------
                         $this->DB->update('posts', array('topic_id' => $new_topic_id, 'new_topic' => 0, 'queued' => 0), "pid={$r['pid']}");
                         $this->DB->update('posts', array('new_topic' => 0), "topic_id={$topic['tid']}");
                         $forums_affected[$topic['forum_id']] = $topic['forum_id'];
                         $forums_affected[$this->trash_forum] = $this->trash_forum;
                         $topics_affected[$topic['tid']] = $topic['tid'];
                         $topics_affected[$new_topic_id] = $new_topic_id;
                         $posts_deleted++;
                     } else {
                         $this->DB->delete('posts', 'pid=' . $r['pid']);
                         $forums_affected[$topic['forum_id']] = $topic['forum_id'];
                         $topics_affected[$topic['tid']] = $topic['tid'];
                         $posts_deleted++;
                     }
                 }
             }
         }
     }
     //-----------------------------------------
     // Rebuild topics and forums
     //-----------------------------------------
     if (count($topics_affected)) {
         foreach ($topics_affected as $tid) {
             $mod_func->rebuildTopic($tid, 0);
         }
     }
     if (count($forums_affected)) {
         foreach ($forums_affected as $fid) {
             $mod_func->forumRecount($fid);
         }
     }
     //-----------------------------------------
     // Finish - or more?...
     //-----------------------------------------
     if (!$done) {
         //-----------------------------------------
         // Recount stats..
         //-----------------------------------------
         $mod_func->statsRecount();
         //-----------------------------------------
         // Reset member's posts
         //-----------------------------------------
         $forums = array();
         foreach ($this->registry->class_forums->forum_by_id as $data) {
             if (!$data['inc_postcount']) {
                 $forums[] = $data['id'];
             }
         }
         if (!count($forums)) {
             $count = $this->DB->buildAndFetch(array('select' => 'count(*) as count', 'from' => 'posts', 'where' => 'queued != 1 AND author_id=' . $member_id));
         } else {
             $count = $this->DB->buildAndFetch(array('select' => 'count(p.pid) as count', 'from' => array('posts' => 'p'), 'where' => 'p.queued <> 1 AND p.author_id=' . $member_id . ' AND t.forum_id NOT IN (' . implode(",", $forums) . ')', 'add_join' => array(array('type' => 'left', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id'))));
         }
         $new_post_count = intval($count['count']);
         $this->registry->adminFunctions->saveAdminLog(sprintf($this->lang->words['member_posts_deleted'], $member['members_display_name']));
         IPSMember::save($member_id, array('core' => array('posts' => $new_post_count)));
         $this->registry->output->multipleRedirectFinish($this->lang->words['mem_posts_process_done']);
     } else {
         //-----------------------------------------
         // More..
         //-----------------------------------------
         $next = $start + $end;
         $url = $this->settings['base_url'] . '&' . $this->form_code_js . "&do=deleteposts_process&dpergo={$end}" . "&st={$next}" . "&init=1" . "&dposts={$delete_posts}" . "&dtopics={$delete_topics}" . "&use_trash_can=" . intval($this->request['use_trash_can']) . "&member_id={$member_id}";
         $text = sprintf($this->lang->words['mem_posts_process_more'], $end, $posts_deleted, $topics_deleted);
         $this->registry->output->multipleRedirectHit($url, $img . ' ' . $text);
     }
 }