]> src.bluestatic.org Git - bugdar.git/blob - docs/datatools.php
r1406: Moving the rest of the email body texts (from class_notification.php) to templates
[bugdar.git] / docs / datatools.php
1 <?php
2
3 // can load/export all of our common data bits
4 // SVN $Id$
5
6 chdir('./../');
7 require_once('./includes/init.php');
8
9 // ###################################################################
10 // list of things to export/import: array(displayname => array('table' => db table, 'rebuild' => rebuild function)
11
12 $THELIST = array(
13 'usergroups' => array(
14 'table' => 'usergroup',
15 'rebuild' => 'build_usergroups'
16 ),
17
18 'statuses' => array(
19 'table' => 'status',
20 'rebuild' => 'build_statuses'
21 ),
22
23 'severity' => array(
24 'table' => 'severity',
25 'rebuild' => 'build_severities'
26 ),
27
28 'priorities' => array(
29 'table' => 'priority',
30 'rebuild' => 'build_priorities'
31 ),
32
33 'resolutions' => array(
34 'table' => 'resolution',
35 'rebuild' => 'build_resolutions'
36 ),
37
38 'user help' => array(
39 'table' => 'fieldhelp',
40 'rebuild' => 'build_user_help',
41 'orderfree' => true
42 )
43 );
44
45 ?>
46
47 <h2>Data Tools</h2>
48
49 Here you can either export or import the standard data tables for Bugdar. These include things such as usergroups, priorities, etc.
50
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>
52
53 <hr />
54
55 <pre>
56
57 <?php
58
59 // ###################################################################
60
61 if ($_REQUEST['do'] == 'export')
62 {
63 foreach ($THELIST AS $display => $data)
64 {
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))
67 {
68 $exportlist["$display"][] = $fitem;
69 }
70 $db->free_result($fetch);
71
72 echo "Exported $display\n";
73 }
74
75 $phpfile = '<?' . 'php
76
77 // stores exported data data
78 // SVN $' . 'Id: $
79
80 $DATASTORE = "' . addslashes(serialize($exportlist)) . '";
81
82 ?' . '>';
83
84 if ($handle = fopen('./docs/datatools_store.php', 'w'))
85 {
86 if (fwrite($handle, $phpfile))
87 {
88 fclose($handle);
89 }
90 else
91 {
92 echo 'Could not write the file';
93 exit;
94 }
95 }
96 else
97 {
98 echo 'Could not open the file with mode "w"';
99 exit;
100 }
101
102 echo "Wrote the file\n";
103 }
104
105 // ###################################################################
106
107 if ($_REQUEST['do'] == 'import')
108 {
109 require('./docs/datatools_store.php');
110 $DATASTORE = unserialize(stripslashes($DATASTORE));
111
112 foreach ($THELIST AS $display => $data)
113 {
114 $db->query("TRUNCATE TABLE " . TABLE_PREFIX . "$data[table]");
115
116 $fields = array();
117 $values = array();
118 foreach ($DATASTORE["$display"] AS $mainarray)
119 {
120 $fields = $values = array();
121 foreach ($mainarray AS $field => $value)
122 {
123 $fields[] = $field;
124 $values[] = "'" . $bugsys->escape($value) . "'";
125 }
126 $query = "INSERT INTO " . TABLE_PREFIX . "$data[table] (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $values) . ")";
127 echo str_replace(array('>', '<'), array('&gt;', '&lt;'), $query) . "\n";
128 $db->query($query);
129 }
130
131 $data['rebuild']();
132 echo "Rebuilding $data[table]\n\n";
133 }
134 }
135
136 // ###################################################################
137
138 if ($_REQUEST['do'] == 'view')
139 {
140 require_once('./docs/datatools_store.php');
141 $DATASTORE = unserialize(stripslashes($DATASTORE));
142
143 $build = '$data = array(';
144
145 foreach ($THELIST AS $display => $data)
146 {
147 $build .= "\n\t'$data[table]' => array(";
148 foreach ($DATASTORE["$display"] AS $mainarray)
149 {
150 $build .= "\n\t\tarray(";
151 foreach ($mainarray AS $field => $value)
152 {
153 $build .= "\n\t\t\t'" . addslashes($field) . "' => '" . addslashes($value) . "',";
154 }
155 $build = substr($build, 0, strlen($build) - 1);
156 $build .= "\n\t\t),";
157 }
158 $build = substr($build, 0, strlen($build) - 1);
159 $build .= "\n\t),";
160 }
161 $build = substr($build, 0, strlen($build) - 1);
162
163 $build .= "\n);";
164
165 echo '<textarea style="height: 500px; width: 100%">' . htmlspecialchars($build) . '</textarea>';
166 }
167
168 ?>