Source

wcf-shoutbox / files / lib / acp / page / ShoutboxMessageListPage.class.php

Full commit
<?php
// wcf imports
require_once(WCF_DIR.'lib/page/AbstractPage.class.php');

/**
 * Displays a list of all messages in the shoutbox-table for deletion.
 *
 * @author	Christian Fischer
 * @package	net.northshirebund.wbb.shoutbox
 */
class ShoutboxMessageListPage extends AbstractPage {
	public $templateName	= 'shoutboxMessageList';

	/**
	 * @see Page::assignVariables()
	 */
	public function assignVariables() {
		parent::assignVariables();
		$messages = array();
		$users    = array();
		
		// delete selected messages
		if(isset($_POST['selectedMessages'])) {
			$selectedMessages = '';
			
			if (is_array($_POST['selectedMessages'])) {
				$selectedMessages = join(',', ArrayUtil::toIntegerArray($_POST['selectedMessages']));
			}
			else {
				$selectedMessages = intval($_POST['selectedMessages']);
			}
			
			if($selectedMessages != '') {
				WCFACP::getDB()->sendQuery('DELETE FROM wcf'.WCF_N.'_shoutbox WHERE message_id IN('.$selectedMessages.')');
			}
		}
		
		// delete messages from user
		if(isset($_POST['selectedUser'])) {
			$selectedUser = intval($_POST['selectedUser']);
			
			if($selectedUser != 0) {
				WCFACP::getDB()->sendQuery('DELETE FROM wcf'.WCF_N.'_shoutbox WHERE userID='.$selectedUser);
			}
		}
		
		// get messages in the shoutbox
		$sql = 'SELECT * FROM wcf'.WCF_N.'_shoutbox sb LEFT JOIN wcf'.WCF_N.'_user u USING(userid) WHERE to_user=0 ORDER BY message_time ASC';
		$result = WCFACP::getDB()->sendQuery($sql);
		
		while($row = WCFACP::getDB()->fetchArray($result)) {
			array_push($messages, $row);
		}
		
		// get all users who had posted
		$sql = 'SELECT u.userID, u.username FROM wcf'.WCF_N.'_shoutbox sb LEFT JOIN wcf'.WCF_N.'_user u USING(userid) WHERE u.userID>0 GROUP BY userID ORDER BY username ASC';
		$result = WCFACP::getDB()->sendQuery($sql);
		
		while($row = WCFACP::getDB()->fetchArray($result)) {
			array_push($users, $row);
		}
		
		WCFACP::getTPL()->assign(array(
			'messages' => $messages,
			'users'    => $users
		));
	}

	/**
	 * @see Page::show()
	 */
	public function show() {

		// activate menu item
		WCFACP::getMenu()->setActiveMenuItem('wcf.acp.menu.link.content.shoutbox');

		parent::show();
	}
}
?>