<?php
/**
* TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
*
* $Id: mod_globalmsg.php 2009-09-03 20:23:12 sven $
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package TS2WebAdmin
* @version 2.0.0-alpha2
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2009 by Planet TeamSpeak. All rights reserved.
*/
/* check if file is included correctly */
defined('TS2WA_VALID') || die('Access denied...');
/**
* @package TS2WebAdmin_Module_Globalmsg
* @category TS2WebAdmin_Module
*/
class TS2WebAdmin_Module_Globalmsg extends TS2WebAdmin_Module
{
/**
* Module requires SSA permissions.
*
* @return void
*/
function checkLogin()
{
$this->isAuthorized(TS2WA_LOGIN_SUPERADMIN);
}
/**
* Displays a form to send global messages.
*
* @return void
*/
function indexAction()
{
$this->setSubMenu('global');
}
/**
* Send global messages.
*
* @return void
*/
function do_sendAction()
{
$this->setNoRender();
$sendMessage = trim($this->_app->getParam('send_message', ''));
$sendToAdmins = intval($this->_app->getParam('send_admins', 0));
$sendAnonymous = intval($this->_app->getParam('send_anonymous', 0));
if(!empty($sendMessage))
{
$messages = explode("\n", str_replace("\r\n", "\n", $sendMessage));
$prefix = ($sendAnonymous) ?'' : 'web.' . $this->_app->getSessionParam('login_name', 'Anonymous') . ': ';
if(!$sendToAdmins) {
foreach($messages as $message) $this->_ts2->sadmin_messageAll($prefix . trim($message), TRUE);
} else {
foreach($this->_ts2->info_extendServerPlayerList() as $server => $players) {
$this->_ts2->select($server);
foreach($players as $player) {
if(in_array("SA", $this->_ts2->info_translatePlayerFlag($player))) {
foreach($messages as $message) $this->_ts2->sadmin_messageUser($player['p_id'], $prefix . trim($message), TRUE);
}
}
}
}
}
$this->_app->setLastEvent('Global message has been sent successfully.');
$this->redirect('globalmsg');
}
}