<?php
/**
* TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
*
* $Id: mod_groups.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_Groups
* @category TS2WebAdmin_Module
*/
class TS2WebAdmin_Module_Groups extends TS2WebAdmin_Module
{
/**
* Module requires SA permissions.
*
* @return void
*/
function checkLogin()
{
$this->isAuthorized(TS2WA_LOGIN_SERVERADMIN);
}
/**
* Displays a list of available user categories and user counts.
*
* @return void
*/
function indexAction()
{
$this->setSubMenu('groups');
$server_id = intval($this->_app->getSessionParam('server_id', 0));
if(!$this->_ts2->sql_serverInfo($server_id))
{
$this->_app->raiseError('Invalid virtual server ID', 500);
}
$this->assign('server_id', $server_id);
$this->assign('groups', $this->_ts2->sql_groupList($server_id));
}
/**
* Displays a list of permissions for a specified usergroup.
*
* @return void
*/
function modifyAction()
{
$this->setSubMenu('groups');
$server_id = intval($this->_app->getSessionParam('server_id', 0));
$group_id = $this->_app->getParam('id', 'none');
if(!$this->_ts2->sql_serverInfo($server_id))
{
$this->_app->raiseError('Invalid virtual server ID', 500);
}
if(!$group_data = $this->_ts2->sql_groupInfo($group_id, $server_id))
{
$this->_app->raiseError($this->_ts2->debug_lastreply(), 500);
}
if($group_id == "r")
{
$group_name = "Registerred";
}
elseif($group_id == "u")
{
$group_name = "Anonymous";
}
else
{
$group_name = strtoupper($group_id);
}
$this->assign('server_id', $server_id);
$this->assign('group_id', $group_id);
$this->assign('group_name', $group_name);
$this->assign('group_perms', $group_data);
}
function do_modifyAction()
{
$this->setNoRender();
$server_id = intval($this->_app->getSessionParam('server_id', 0));
$group_id = $this->_app->getParam('group_id', 'none');
if(!$this->_ts2->sql_serverInfo($server_id))
{
$this->_app->raiseError('Invalid virtual server ID', 500);
}
if(!$group_data = $this->_ts2->sql_groupInfo($group_id, $server_id))
{
$this->_app->raiseError($this->_ts2->debug_lastreply(), 500);
}
if($group_id == "r")
{
$group_name = "Registerred";
}
elseif($group_id == "u")
{
$group_name = "Anonymous";
}
else
{
$group_name = strtoupper($group_id);
}
$perms = array();
foreach($group_data as $key => $val)
{
$perms["ug" . $group_name . "_up" . $key] = $this->_app->getParam($key, 0);
}
$this->_ts2->sql_writeGroupPermissions($group_id, $perms, $server_id);
$this->_app->setLastEvent('The group permissions for ' . strtoupper($group_id) . ' have been changed successfully.');
$this->redirect('groups', 'modify', array('id' => $group_id));
}
}