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
>]</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 while ($fitem = $db->fetch_array($fetch))
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))
92 echo 'Could not write the file';
98 echo 'Could not open the file with mode "w
"';
102 echo "Wrote the file\n
";
105 // ###################################################################
107 if ($_REQUEST['do'] == 'import')
109 require('./docs/datatools_store.php');
110 $DATASTORE = unserialize(stripslashes($DATASTORE));
112 foreach ($THELIST AS $display => $data)
114 $db->query("TRUNCATE TABLE
" . TABLE_PREFIX . "$data[table
]");
118 foreach ($DATASTORE["$display"] AS $mainarray)
120 $fields = $values = array();
121 foreach ($mainarray AS $field => $value)
124 $values[] = "'" . $bugsys->escape($value) . "'";
126 $query = "INSERT INTO " . TABLE_PREFIX
. "$data[table] (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $values) . ")";
127 echo str_replace(array('>', '<'), array('>', '<'), $query) . "\n";
132 echo "Rebuilding $data[table]\n\n";
136 // ###################################################################
138 if ($_REQUEST['do'] == 'view')
140 require_once('./docs/datatools_store.php');
141 $DATASTORE = unserialize(stripslashes($DATASTORE));
143 $build = '$data = array(';
145 foreach ($THELIST AS $display => $data)
147 $build .= "\n\t'$data[table]' => array(";
148 foreach ($DATASTORE["$display"] AS $mainarray)
150 $build .= "\n\t\tarray
(";
151 foreach ($mainarray AS $field => $value)
153 $build .= "\n\t\t\t
'" . addslashes($field) . "' => '" . addslashes($value) . "',";
155 $build = substr($build, 0, strlen($build) - 1);
156 $build .= "\n\t\t
),";
158 $build = substr($build, 0, strlen($build) - 1);
161 $build = substr($build, 0, strlen($build) - 1);
165 echo '<textarea style="height
: 500px
; width
: 100%
">' . htmlspecialchars($build) . '</textarea>';