Location: PHPKode > projects > astwebpanel > web/dao/SiteInfoDao.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 the 'siteinfo' table
*/
class SiteInfoDao
{
	var	$data = array('reference' => '', 'name' => '',
					  'street' => '','city' => '', 'county' => '', 
					  'postcode' => '',	'country' => '',
				      'contact' => '', 'tel' => '',	'fax' => '', 'email' => '',
				      'notes' => '');

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

        $result = $db->query("SELECT * FROM siteinfo");
		if ( $result->numRows() == 1 )
		{
        	$row = $result->fetchRow();
	        foreach(array_keys($this->data) as $key) 
			{
				$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 (isset($values[$key]))
			{
				$this->data[$key] = $values[$key];
			}
	   	}

		$query = "UPDATE siteinfo SET reference = ?, name = ?, street = ?, city = ?, county = ?, postcode = ?, country = ?, 
				  contact = ?, tel = ?, fax = ?, email = ?, notes = ?"; 

 		$stmt = $db->prepare($query);	
		$querydata = array($this->data['reference'], $this->data['name'],
						   $this->data['street'], $this->data['city'], $this->data['county'], 
						   $this->data['postcode'], $this->data['country'],
						   $this->data['contact'], $this->data['tel'], $this->data['fax'], $this->data['email'],
						   $this->data['notes']);

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


?>
Return current item: astwebpanel