Location: PHPKode > projects > astwebpanel > web/dao/ServerNetworkDao.php
<?php
/**
 * Copyright (C) 2004 - 2006, John Tarlton.
 *
 * This file is part of AstWebPanel - A web management user interface for Asterisk.
 *
 * AstWebPanel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation. See the LICENSE file distributed
 * with AstWebPanel.
 *
 * Database access object.
 */

require_once('./php/dbase.php');

/* Database access object for server's network configuration.
*/
class ServerNetworkDao
{
	var $data = array('hostname' => '', 'domain' => '', 'dns1' => '', 'dns2' => '', 
					  'dhcp_eth0' => '', 'addr_eth0' => '', 'mask_eth0' => '', 'gateway_eth0' => '', 
				      'eth1' => '', 'dhcp_eth1' => '', 'addr_eth1' => '', 'mask_eth1' => '', 'gateway_eth1' => '');

	function get(&$values)
	{
    	global $db;

		$result = $db->query("SELECT * FROM servernetwork");; 
		if ( $result->numRows() == 1 )
		{
        	$row = $result->fetchRow();
	        foreach(array_keys($this->data) as $key) 
			{
				if ($key == 'dhcp_eth0' || $key == 'eth1' || $key == 'dhcp_eth1')
					$values[$key] = ($row[$key] == 't') ? TRUE : FALSE;
				else
					$values[$key] = $row[$key];
    	    }
			$result->free();
			return TRUE;
		}
		$result->free();
		return FALSE;
	}

	function update(&$values)
	{
    	global $db;

        foreach(array_keys($this->data) as $key) 
		{
			if ($key == 'dhcp_eth0' || $key == 'eth1' || $key == 'dhcp_eth1')
					$this->data[$key] = ($values[$key] == TRUE) ? 't' : 'f';
				else
					$this->data[$key] = $values[$key];
   	    }
		$query = "UPDATE servernetwork 
				  SET hostname = ?, domain = ?, dns1 = ?, dns2 = ?,
				  dhcp_eth0 = ?, addr_eth0 = ?, mask_eth0 = ?, gateway_eth0 = ?,
				  eth1 = ?, dhcp_eth1 = ?, addr_eth1 = ?, mask_eth1 = ?, gateway_eth1 = ?"; 

  		$stmt = $db->prepare($query);	
		$querydata = array($this->data['hostname'], $this->data['domain'], 
					  	   $this->data['dns1'], $this->data['dns2'], 
						   $this->data['dhcp_eth0'], $this->data['addr_eth0'], 
						   $this->data['mask_eth0'], $this->data['gateway_eth0'], 
						   $this->data['eth1'], $this->data['dhcp_eth1'], 
						   $this->data['addr_eth1'], $this->data['mask_eth1'], 
                      	   $this->data['gateway_eth1']);

   		$result = $db->execute($stmt, $querydata); 
		return DB::isError ($result);
	}
}


?>
Return current item: astwebpanel