<?php
/*
* Created on Sep 25, 2008
* 2.0
*/
require_once 'include/IPage.php';
class AdminBackupDatabasePage implements IPage
{
private $userCount, $tagCount, $locationCount;
private $peopleCount, $trashCount;
function GetHead(& $title)
{
if (false == USER_IS_ADMIN)
return;
header('Content-type: text/plain; charset=utf-8;');
header('Content-Disposition: attachment; filename="kwalbum_backup_'.date('Y-m-d').'.sql"');
$this->EchoQueries(USER_TABLE);
$this->EchoQueries(ITEM_TABLE);
$this->EchoQueries(DATE_TABLE);
$this->EchoQueries(LOCATION_TABLE);
$this->EchoQueries(TAG_TABLE);
$this->EchoQueries(TAG_MAP_TABLE);
$this->EchoQueries(PEOPLE_TABLE);
$this->EchoQueries(PEOPLE_MAP_TABLE);
$this->EchoQueries(COMMENT_TABLE);
$this->EchoQueries(FAVORITE_TABLE);
exit;
}
function ShowBody()
{
}
private function EchoQueries($table)
{
global $DB;
$query = 'SELECT * FROM '.$table;
$result = $DB->Query($query);
echo "# restoring $table\n";
echo "TRUNCATE TABLE $table;\n";
while ($row = $result->fetch_array(MYSQLI_ASSOC))
{
$i = 0;
echo 'INSERT INTO '.$table.' VALUES (';
foreach ($row as $val)
{
if (1 == $i)
echo ', ';
else
$i++;
echo '\''.$DB->FilterString($val, true).'\'';
}
echo ");\n";
}
}
}
?>