<?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');
require_once('./dao/Dao.php');
/* Data Access Object for group configuration.
*/
class GroupDao extends DBDao
{
var $table = 'groups';
var $data = array('groupid' => '', 'groupname' => '', 'description' => '', 'grouptype' => '', 'partitionid' => '', 'enable' => '');
function get($groupname, &$values)
{
global $db;
$query = "SELECT * FROM {$this->table} WHERE groupname = ?";
$stmt = $db->prepare($query);
$querydata = array($groupname);
$result = $db->execute($stmt, $querydata);
if ( $result->numRows() == 1 )
{
$row = $result->fetchRow();
foreach(array_keys($this->data) as $key)
{
if ($key == 'enable')
$values[$key] = ($row[$key] == 't') ? TRUE : FALSE;
else
$values[$key] = $row[$key];
}
$result->free();
return TRUE;
}
$result->free();
return FALSE;
}
function insert(&$values)
{
global $db;
foreach(array_keys($this->data) as $key)
{
if (isset($values[$key]))
{
if ($key == 'enable')
$this->data[$key] = ($values[$key] == TRUE) ? 't' : 'f';
else
$this->data[$key] = $values[$key];
}
}
$query = "INSERT INTO {$this->table} (groupname, description, grouptype, partitionid, enable)
VALUES (?, ?, ?, ?, ?)";
$stmt = $db->prepare($query);
$querydata = array($this->data['groupname'], $this->data['description'],
$this->data['grouptype'], $this->data['partitionid'],
$this->data['enable']);
$result = $db->execute($stmt, $querydata);
return DB::isError ($result);
}
function update(&$values)
{
global $db;
foreach(array_keys($this->data) as $key)
{
if (isset($values[$key]))
{
if ($key == 'enable')
$this->data[$key] = ($values[$key] == TRUE) ? 't' : 'f';
else
$this->data[$key] = $values[$key];
}
}
$query = "UPDATE {$this->table} SET description = ?, enable = ?
WHERE groupname = ?";
$stmt = $db->prepare($query);
$querydata = array($this->data['description'], $this->data['enable'], $this->data['groupname']);
$result = $db->execute($stmt, $querydata);
return DB::isError ($result);
}
function delete($groupname)
{
global $db;
$query = "DELETE FROM {$this->table} WHERE groupname = ?";
$stmt = $db->prepare($query);
$querydata = array($groupname);
$result = $db->execute($stmt, $querydata);
return DB::isError ($result);
}
function getCount(&$pattern)
{
global $db;
$sql = "SELECT count(*)";
$from = "FROM {$this->table} ";
$where = $this->buildWhere($pattern);
$result = $db->query("$sql $from $where");
$row = $result->fetchRow();
return $row['count'];
}
function getMultiple( &$pattern, $offset, $limit, &$values)
{
global $db;
$sql = "SELECT *";
$from = "FROM {$this->table} ";
$where = $this->buildWhere($pattern);
$query = "$sql $from $where OFFSET $offset LIMIT $limit";
$result = $db->query($query);
while ($row = $result->fetchRow())
{
$values[] = $row;
}
$result->free();
}
}
?>