<?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');
/* Data access object for backup configuration.
* Weekday and time parameters, which have several fields, are passed in & out in arrays.
*/
class BackupDao
{
var $data = array('serverconf' => 'f', 'userconf' => 'f', 'voicemail' => 'f', 'schedule' => 'none',
'days' => array('mon' => 'f', 'tue' => 'f', 'wed' => 'f', 'thu' => 'f', 'fri' => 'f', 'sat' => 'f', 'sun' => 'f'),
'time' => array('hour' => '1', 'min' => '0'), 'schedftp' => '');
function get(&$values)
{
global $db;
$result = $db->query("SELECT * FROM backup");
if ( $result->numRows() == 1 )
{
$row = $result->fetchRow();
foreach(array_keys($this->data) as $key)
{
if ($key == 'days')
{
$days = $this->data['days'];
foreach(array_keys($days) as $day)
$days[$day] = ($row[$day] == 't') ? TRUE : FALSE;
$values[$key] = $days;
}
else if ($key == 'time')
{
$time = $this->data['time'];
foreach(array_keys($time) as $t)
$time[$t] = $row[$t];
$values[$key] = $time;
}
else if ($key == 'serverconf' || $key == 'userconf' || $key == 'voicemail')
$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 ( isset($values[$key]) )
{
if ($key == 'days')
{
$days = $this->data['days'];
foreach(array_keys($days) as $day)
$this->data[$key][$day] = ($values[$key][$day] == TRUE) ? 't' : 'f';
}
else if ($key == 'time')
{
$time = $this->data['time'];
foreach(array_keys($time) as $t)
$this->data[$key][$t] = $values[$key][$t];
}
else if ($key == 'serverconf' || $key == 'userconf' || $key == 'voicemail')
$this->data[$key] = ($values[$key] == TRUE) ? 't' : 'f';
else
$this->data[$key] = $values[$key];
}
}
$query = "UPDATE backup
SET serverconf=?, userconf=?, voicemail=?, schedule=?,
mon=?, tue=?, wed=?, thu=?, fri=?, sat=?, sun=?,
hour=?, min=?,
schedftp=?";
$stmt = $db->prepare($query);
$querydata = array($this->data['serverconf'], $this->data['userconf'], $this->data['voicemail'], $this->data['schedule'],
$this->data['days']['mon'], $this->data['days']['tue'], $this->data['days']['wed'], $this->data['days']['thu'],
$this->data['days']['fri'], $this->data['days']['sat'], $this->data['days']['sun'],
$this->data['time']['hour'], $this->data['time']['min'],
$this->data['schedftp'],);
$result = $db->execute($stmt, $querydata);
return DB::isError ($result);
}
}
?>