<?php
// can load/export all of our common data bits
// SVN $Id$
chdir('./../');
require_once('./includes/init.php');
// ###################################################################
// list of things to export/import: array(displayname => array('table' => db table, 'rebuild' => rebuild function)
$THELIST = array(
'usergroups' => array(
'table' => 'usergroup',
'rebuild' => 'build_usergroups'
),
'statuses' => array(
'table' => 'status',
'rebuild' => 'build_statuses'
),
'severity' => array(
'table' => 'severity',
'rebuild' => 'build_severities'
),
'priorities' => array(
'table' => 'priority',
'rebuild' => 'build_priorities'
),
'resolutions' => array(
'table' => 'resolution',
'rebuild' => 'build_resolutions'
),
'user help' => array(
'table' => 'fieldhelp',
'rebuild' => 'build_user_help',
'orderfree' => true
)
);
?>
<h2>Data Tools</h2>
Here you can either export or import the standard data tables for Bugdar. These include things such as usergroups, priorities, etc.
<h3>[<strong><a href="datatools.php?do=export">Export</a></strong>] [<strong><a href="datatools.php?do=import">Import</a></strong>] [<strong><a href="datatools.php?do=view">View</a></strong>] [<strong><a href="datatools.php?do=settings">Dump Settings</a></strong>]</h3>
<hr />
<pre>
<?php
// ###################################################################
if ($_REQUEST['do'] == 'export')
{
foreach ($THELIST AS $display => $data)
{
$fetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "$data[table]" . (!$data['orderfree'] ? " ORDER BY {$data[table]}id ASC" : ""));
foreach ($fetch as $fitem)
{
$exportlist["$display"][] = $fitem;
}
$db->free_result($fetch);
echo "Exported $display\n";
}
$phpfile = '<?' . 'php
// stores exported data data
// SVN $' . 'Id: $
$DATASTORE = "' . addslashes(serialize($exportlist)) . '";
?' . '>';
if ($handle = fopen('./docs/datatools_store.php', 'w'))
{
if (fwrite($handle, $phpfile))
{
fclose($handle);
chmod('./docs/datatools_store.php', 0777);
}
else
{
echo 'Could not write the file';
exit;
}
}
else
{
echo 'Could not open the file with mode "w"';
exit;
}
echo "Wrote the file\n";
}
// ###################################################################
if ($_REQUEST['do'] == 'import')
{
require('./docs/datatools_store.php');
$DATASTORE = unserialize(stripslashes($DATASTORE));
foreach ($THELIST AS $display => $data)
{
$db->query("TRUNCATE TABLE " . TABLE_PREFIX . "$data[table]");
$fields = array();
$values = array();
foreach ($DATASTORE["$display"] AS $mainarray)
{
$fields = $values = array();
foreach ($mainarray AS $field => $value)
{
$fields[] = $field;
$values[] = "'" . $bugsys->escape($value) . "'";
}
$query = "INSERT INTO " . TABLE_PREFIX . "$data[table] (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $values) . ")";
echo str_replace(array('>', '<'), array('>', '<'), $query) . "\n";
$db->query($query);
}
$data['rebuild']();
echo "Rebuilding $data[table]\n\n";
}
}
// ###################################################################
if ($_REQUEST['do'] == 'view')
{
require_once('./docs/datatools_store.php');
$DATASTORE = unserialize(stripslashes($DATASTORE));
$build = '$data = array(';
foreach ($THELIST AS $display => $data)
{
$build .= "\n\t'$data[table]' => array(";
foreach ($DATASTORE["$display"] AS $mainarray)
{
$build .= "\n\t\tarray(";
foreach ($mainarray AS $field => $value)
{
$build .= "\n\t\t\t'" . addslashes($field) . "' => '" . addslashes($value) . "',";
}
$build = substr($build, 0, strlen($build) - 1);
$build .= "\n\t\t),";
}
$build = substr($build, 0, strlen($build) - 1);
$build .= "\n\t),";
}
$build = substr($build, 0, strlen($build) - 1);
$build .= "\n);";
echo '<textarea style="height: 500px; width: 100%">' . htmlspecialchars($build) . '</textarea>';
}
// ###################################################################
if ($_REQUEST['do'] == 'settings')
{
$fout = <<<FILE
<?php
/*=====================================================================*\
|| ###################################################################
|| # Bugdar
|| # Copyright (c)2004-2009 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/
// this stores all the settings for a new installation
\$settings = array(
FILE;
$settings = $db->query("SELECT * FROM " . TABLE_PREFIX . "setting");
foreach ($settings as $setting)
{
$fout .= "\n\t'$setting[varname]' => '" . str_replace("'", "\'", $setting['value']) . "',";
}
$fout .= <<<FILE
);
/*=====================================================================*\
|| ###################################################################
|| # \$HeadURL: \$
|| # \$Id: \$
|| ###################################################################
\*=====================================================================*/
?>
FILE;
file_put_contents('install/settings.php', $fout);
chmod('install/settings.php', 0777);
echo 'Dumping current settings into install/settings.php';
}
?>