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

/**
 * TS2WebAdmin - Lightweight TeamSpeak 2 Control Panel
 *
 * $Id: mod_serverset.php 2009/01/03 10:31:45 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-alpha
 * @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_Serverset
 * @category TS2WebAdmin_Module
 */
class TS2WebAdmin_Module_Serverset extends TS2WebAdmin_Module
{
  /**
   * Module requires SA permissions.
   * 
   * @return void
   */
  function checkLogin()
  {
    $this->isAuthorized(TS2WA_LOGIN_SERVERADMIN);
  }

  /**
   * Displays a form to modify server settings.
   * 
   * @return void
   */
  function indexAction()
  {
    $this->setSubMenu('server');
    
    $server_id = intval($this->_app->getSessionParam('server_id', 0));
    $server_info = $this->_ts2->sql_serverInfo($server_id);

    if(!$server_info)
    {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }

    $this->assign('serverinfo', $server_info);
  }
  
  /**
   * Updates server settings.
   * 
   * @return void
   */
  function do_updateAction()
  {
    $this->setNoRender();
    
    $server_id = intval($this->_app->getSessionParam('server_id', 0));
    $server_info = $this->_ts2->sql_serverInfo($server_id);
    $server_active = ($this->_app->getParam('server_active', 0) == 1) ? -1 : 0;

    if(!$server_info)
    {
      $this->_app->raiseError('Invalid virtual server ID', 500);
    }
        
    // change server settings
    if($this->_ts2->sadmin_serverStatus($server_id))
    {
      if($this->_ts2->udp != $server_info['i_server_udpport']) $this->_ts2->select($server_info['i_server_udpport']);
      
      $this->_ts2->sadmin_serverSet('server_name', $this->_app->getParam('server_name', 'TeamSpeak Server'));
      $this->_ts2->sadmin_serverSet('server_welcomemessage', $this->_app->getParam('server_welcomemessage', '[ Welcome to TeamSpeak, check www.teamspeak.com ]'));
      $this->_ts2->sadmin_serverSet('server_password', $this->_app->getParam('server_password', '#CLEAR#'));
      $this->_ts2->sadmin_serverSet('server_clan_server', $this->_app->getParam('server_clan_server', 0));
    }
    else
    {      
      $data = array(
        "servername"           => $this->_app->getParam('server_name', 'TeamSpeak Server'),
        "serverpassword"       => $this->_app->getParam('server_password', ''),
        "serverwelcomemessage" => $this->_app->getParam('server_welcomemessage', '[ Welcome to TeamSpeak, check www.teamspeak.com ]'),
        "serverwebpostposturl" => $this->_app->getParam('server_webpost_posturl', ''),
        "serverwebpostlinkurl" => $this->_app->getParam('server_webpost_linkurl', ''),
        "servertype"           => ($this->_app->getParam('server_clan_server', 0) ? 1 : 2),
      );
      
      $this->_ts2->sql_writeServerSettings($data, $server_id);
    }
    
    // change server status if necessary
    if($this->_ts2->sadmin_serverStatus($server_id) != $server_active)
    {
      if($server_active) {
        $this->_ts2->sadmin_serverStart($server_id);
      } else {
        $this->_ts2->sadmin_serverStop($server_id);
      }
    }

    // tsviewer settings
    if($this->_app->getParam('server_tsviewerid')) $this->_ts2->sql_setServerDescription($this->_app->getParam('server_tsviewerid'), $server_id);
    
    $this->_app->setLastEvent('The virtual server configuration has been changed successfully.');

    $this->redirect('serverset');
  }
}
Return current item: TS2WebAdmin