Location: PHPKode > projects > TS2WebAdmin > ts2webadmin/app/mod_channels.php
<?php

/**
 * TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
 *
 * $Id: mod_channels.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_Channels
 * @category TS2WebAdmin_Module
 */
class TS2WebAdmin_Module_Channels extends TS2WebAdmin_Module
{
  /**
   * Module requires SA permissions.
   * 
   * @return void
   */
  function checkLogin()
  {
    $this->isAuthorized(TS2WA_LOGIN_SERVERADMIN);
  }
  
  /**
   * Displays a list of registered channels from the database.
   * 
   * @return void
   */
  function indexAction()
  {
    $server_id = (int) $this->_app->getSessionParam('server_id', 0);
    
    if(!$server_info = $this->_ts2->sql_serverInfo($server_id))
    {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    $this->assign('serverinfo', $server_info);
    $this->assign('channels', $this->_ts2->sql_dbChannelList($server_id));
  }
  
  /**
   * Performs selected actions on multiple users.
   * 
   * @return void
   */
  function do_actionsAction()
  {
    $this->setNoRender();
    
    $this->_app->raiseError('currently in development', 500);
  }
  
  /**
   * Displays a form to edit a channel in the database.
   *
   * @return void
   */
  function editAction()
  {
    $server_id = (int) $this->_app->getSessionParam('server_id', 0);

    if(!$server_info = $this->_ts2->sql_serverInfo($server_id)) {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    $channel_id = (int) $this->_app->getParam('id', 0);

    if(!$channel_info = $this->_ts2->sql_dbChannelInfo($channel_id, $server_id))
    {
      $this->_app->raiseError('Invalid channel ID', 500);
    }
    
    $this->assign('serverinfo', $server_info);
    $this->assign('channelinfo', $channel_info);
  }
  
  /**
   * Edits a channel in the database.
   * 
   * @return void
   */
  function do_editAction()
  {
    $this->setNoRender();
    
    $server_id = (int) $this->_app->getSessionParam('server_id', 0);

    if(!$server_info = $this->_ts2->sql_serverInfo($server_id)) {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    $channel_id = (int) $this->_app->getParam('channel_id', 0);

    if(!$channel_info = $this->_ts2->sql_dbChannelInfo($channel_id, $server_id))
    {
      $this->_app->raiseError('Invalid channel ID', 500);
    }
    
    $props = array(
      'b_channel_flag_default' => $this->_app->getParam('b_channel_flag_default', ($channel_info['b_channel_flag_default'] == -1) ? 1 : 0),
      'b_channel_flag_hierarchical' => $this->_app->getParam('b_channel_flag_hierarchical', 0),
      'b_channel_flag_moderated' => $this->_app->getParam('b_channel_flag_moderated', 0),
    );
    
    if($channel_info['s_channel_name'] != $this->_app->getParam('s_channel_name'))
    {
      $props['s_channel_name'] = $this->_app->getParam('s_channel_name', $channel_info['s_channel_name']);
    }
    
    if(!$this->_ts2->sql_dbChannelEdit($channel_id, array_merge($props, $this->_app->clientParams), $server_id))
    {
      $this->_app->raiseError('Error modifying registered channel', 500, $this->_ts2->debug_lastreply());
    }
    
    $this->_app->setLastEvent('The registered channel with ID ' . $channel_id . ' has been modified.');
    
    $this->redirect('channels');
  }
  
  /**
   * Displays a form to create a channel in the database.
   *
   * @return void
   */
  function createAction()
  {
    $server_id = (int) $this->_app->getSessionParam('server_id', 0);

    if(!$server_info = $this->_ts2->sql_serverInfo($server_id)) {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    $this->assign('serverinfo', $server_info);
  }
  
  /**
   * Creates a channel in the database.
   * 
   * @return void
   */
  function do_createAction()
  {
    $this->setNoRender();
    
    $server_id = (int) $this->_app->getSessionParam('server_id', 0);

    if(!$server_info = $this->_ts2->sql_serverInfo($server_id)) {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
    
    if(!$this->_app->getParam('s_channel_name'))
    {
      $this->_app->raiseError('Channelname is missing or invalid', 500);
    }
    
    if(!$this->_ts2->sql_dbChannelAdd($this->_app->getParam('s_channel_name'), $this->_app->clientParams, $server_id))
    {
      $this->_app->raiseError('Error creating registered channel', 500, $this->_ts2->debug_lastreply());
    }
    
    $channel_id = $this->_ts2->sql_lastInsertId($this->_app->getConfigParam('server_issqlite', TRUE));
    
    $this->_app->setLastEvent('A new registered channel has been created with ID ' . $channel_id . '.');
    
    $this->redirect('channels');
  }
}
Return current item: TS2WebAdmin