3 // can load/export all of our common data bits
7 require_once('./includes/init.php');
9 // ###################################################################
10 // list of things to export/import: array(displayname => array('table' => db table, 'rebuild' => rebuild function)
13 'usergroups' => array(
14 'table' => 'usergroup',
15 'rebuild' => 'build_usergroups'
20 'rebuild' => 'build_statuses'
24 'table' => 'severity',
25 'rebuild' => 'build_severities'
28 'priorities' => array(
29 'table' => 'priority',
30 'rebuild' => 'build_priorities'
33 'resolutions' => array(
34 'table' => 'resolution',
35 'rebuild' => 'build_resolutions'
39 'table' => 'fieldhelp',
40 'rebuild' => 'build_user_help',
49 Here you can either export
or import the standard data tables
for Bugdar
. These
include things such
as usergroups
, priorities
, etc
.
51 <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
>
59 // ###################################################################
61 if ($_REQUEST['do'] == 'export')
63 foreach ($THELIST AS $display => $data)
65 $fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "$data[table]" . (!$data['orderfree'] ? " ORDER BY {$data[table]}id ASC" : ""));
66 foreach ($fetch as $fitem)
68 $exportlist["$display"][] = $fitem;
70 $db->free_result($fetch);
72 echo "Exported
$display\n";
75 $phpfile = '<?' . 'php
77 // stores exported data data
80 $DATASTORE = "' . addslashes(serialize($exportlist)) . '";
84 if ($handle = fopen('./docs/datatools_store.php', 'w'))
86 if (fwrite($handle, $phpfile))
89 chmod('./docs/datatools_store.php', 0777);
93 echo 'Could not write the file';
99 echo 'Could not open the file with mode "w
"';
103 echo "Wrote the file\n
";
106 // ###################################################################
108 if ($_REQUEST['do'] == 'import')
110 require('./docs/datatools_store.php');
111 $DATASTORE = unserialize(stripslashes($DATASTORE));
113 foreach ($THELIST AS $display => $data)
115 $db->query("TRUNCATE TABLE
" . TABLE_PREFIX . "$data[table
]");
119 foreach ($DATASTORE["$display"] AS $mainarray)
121 $fields = $values = array();
122 foreach ($mainarray AS $field => $value)
125 $values[] = "'" . $bugsys->escape($value) . "'";
127 $query = "INSERT INTO " . TABLE_PREFIX
. "$data[table] (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $values) . ")";
128 echo str_replace(array('>', '<'), array('>', '<'), $query) . "\n";
133 echo "Rebuilding $data[table]\n\n";
137 // ###################################################################
139 if ($_REQUEST['do'] == 'view')
141 require_once('./docs/datatools_store.php');
142 $DATASTORE = unserialize(stripslashes($DATASTORE));
144 $build = '$data = array(';
146 foreach ($THELIST AS $display => $data)
148 $build .= "\n\t'$data[table]' => array(";
149 foreach ($DATASTORE["$display"] AS $mainarray)
151 $build .= "\n\t\tarray
(";
152 foreach ($mainarray AS $field => $value)
154 $build .= "\n\t\t\t
'" . addslashes($field) . "' => '" . addslashes($value) . "',";
156 $build = substr($build, 0, strlen($build) - 1);
157 $build .= "\n\t\t
),";
159 $build = substr($build, 0, strlen($build) - 1);
162 $build = substr($build, 0, strlen($build) - 1);
166 echo '<textarea style="height
: 500px
; width
: 100%
">' . htmlspecialchars($build) . '</textarea>';
169 // ###################################################################
171 if ($_REQUEST['do'] == 'settings')
175 /*=====================================================================*\
176 || ###################################################################
178 || # Copyright (c)2004-2009 Blue Static
180 || # This program is free software; you can redistribute it and/or modify
181 || # it under the terms of the GNU General Public License as published by
182 || # the Free Software Foundation; version 2 of the License.
184 || # This program is distributed in the hope that it will be useful, but
185 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
186 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
189 || # You should have received a copy of the GNU General Public License along
190 || # with this program; if not, write to the Free Software Foundation, Inc.,
191 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
192 || ###################################################################
193 \*=====================================================================*/
195 // this stores all the settings for a new installation
200 $settings = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "setting
");
201 foreach ($settings as $setting)
203 $fout .= "\n\t
'$setting[varname]' => '" . str_replace("'", "\'
", $setting['value']) . "',";
210 /*=====================================================================*\
211 || ###################################################################
214 || ###################################################################
215 \*=====================================================================*/
219 file_put_contents('install
/settings
.php
', $fout);
220 chmod('install
/settings
.php
', 0777);
222 echo 'Dumping current settings into install
/settings
.php
';