<?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 'user voicemail' table
*/
class UserVmDao
{
var $data = array('userid' => '', 'mailbox' => '',
'recordname' => '', 'recordgreeting' => '',
'playenv' => '', 'emailnotification' => '',
'emailaddress' => '', 'emailattach' => '', 'autodelete' => '');
function get($uid, &$values)
{
global $db;
$query = "SELECT * FROM uservm WHERE userid = ?";
$stmt = $db->prepare($query);
$querydata = array($uid);
$result = $db->execute($stmt, $querydata);
if ( $result->numRows() == 1 )
{
$row = $result->fetchRow();
foreach(array_keys($this->data) as $key)
{
if ($key == 'recordname' ||
$key == 'recordgreeting' ||
$key == 'playenv' ||
$key == 'emailnotification' ||
$key == 'emailattach' ||
$key == 'autodelete' )
$values[$key] = ($row[$key] == 't') ? TRUE : FALSE;
else
$values[$key] = $row[$key];
}
return TRUE;
}
return FALSE;
}
function insert(&$values)
{
global $db;
foreach(array_keys($this->data) as $key)
{
if (isset($values[$key]))
{
if ($key == 'recordname' ||
$key == 'recordgreeting' ||
$key == 'playenv' ||
$key == 'emailnotification' ||
$key == 'emailattach' ||
$key == 'autodelete' )
$this->data[$key] = ($values[$key] == TRUE) ? 't' : 'f';
else
$this->data[$key] = $values[$key];
}
}
$query = "INSERT INTO uservm (userid, mailbox, recordname, recordgreeting, playenv,
emailnotification, emailaddress, emailattach, autodelete)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $db->prepare($query);
$querydata = array($this->data['userid'], $this->data['mailbox'], $this->data['recordname'],
$this->data['recordgreeting'], $this->data['playenv'],
$this->data['emailnotification'], $this->data['emailaddress'],
$this->data['emailattach'], $this->data['autodelete']);
$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 == 'recordname' ||
$key == 'recordgreeting' ||
$key == 'playenv' ||
$key == 'emailnotification' ||
$key == 'emailattach' ||
$key == 'autodelete' )
$this->data[$key] = ($values[$key] == TRUE) ? 't' : 'f';
else
$this->data[$key] = $values[$key];
}
}
$query = "UPDATE uservm SET mailbox = ?, recordname = ?, recordgreeting = ?, playenv = ?,
emailnotification = ?, emailaddress = ?, emailattach = ?, autodelete = ?
WHERE userid = ?";
$stmt = $db->prepare($query);
$querydata = array($this->data['mailbox'], $this->data['recordname'],
$this->data['recordgreeting'], $this->data['playenv'],
$this->data['emailnotification'], $this->data['emailaddress'],
$this->data['emailattach'], $this->data['autodelete'],
$this->data['userid']);
$result = $db->execute($stmt, $querydata);
return DB::isError ($result);
}
}
?>