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'
43 Here you can either export
or import the standard data tables
for BugStrike
. These
include things such
as usergroups
, priorities
, etc
.
45 <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
>]</h3
>
53 // ###################################################################
55 if ($_REQUEST['do'] == 'export')
57 foreach ($THELIST AS $display => $data)
59 $fetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "$data[table] ORDER BY {$data[table]}id ASC");
60 while ($fitem = $db->fetch_array($fetch))
62 $exportlist["$display"][] = $fitem;
64 $db->free_result($fetch);
66 echo "Exported
$display\n";
69 $phpfile = '<?' . 'php
71 // stores exported data data
74 $DATASTORE = "' . addslashes(serialize($exportlist)) . '";
78 if ($handle = fopen('./docs/datatools_store.php', 'w'))
80 if (fwrite($handle, $phpfile))
86 echo 'Could not write the file';
92 echo 'Could not open the file with mode "w
"';
96 echo "Wrote the file\n
";
99 // ###################################################################
101 if ($_REQUEST['do'] == 'import')
103 require('./docs/datatools_store.php');
104 $DATASTORE = unserialize(stripslashes($DATASTORE));
106 foreach ($THELIST AS $display => $data)
108 $db->query("TRUNCATE TABLE
" . TABLE_PREFIX . "$data[table
]");
112 foreach ($DATASTORE["$display"] AS $mainarray)
114 $fields = $values = array();
115 foreach ($mainarray AS $field => $value)
118 $values[] = "'" . $bugsys->escape($value) . "'";
120 $query = "INSERT INTO " . TABLE_PREFIX
. "$data[table] (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $values) . ")";
121 echo str_replace(array('>', '<'), array('>', '<'), $query) . "\n";
126 echo "Rebuilding $data[table]\n\n";
130 // ###################################################################
132 if ($_REQUEST['do'] == 'view')
134 require_once('./docs/datatools_store.php');
135 $DATASTORE = unserialize(stripslashes($DATASTORE));
137 $build = '$data = array(';
139 foreach ($THELIST AS $display => $data)
141 $build .= "\n\t'$data[table]' => array(";
142 foreach ($DATASTORE["$display"] AS $mainarray)
144 $build .= "\n\t\tarray
(";
145 foreach ($mainarray AS $field => $value)
147 $build .= "\n\t\t\t
'" . addslashes($field) . "' => '" . addslashes($value) . "',";
149 $build = substr($build, 0, strlen($build) - 1);
150 $build .= "\n\t\t
),";
152 $build = substr($build, 0, strlen($build) - 1);
155 $build = substr($build, 0, strlen($build) - 1);
159 echo '<textarea style="height
: 500px
; width
: 100%
">' . htmlspecialchars($build) . '</textarea>';