1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.52 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Traits; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Common trait for exporting tables, views or materialized views. |
11
|
|
|
*/ |
12
|
|
|
trait ExportTrait |
13
|
|
|
{ |
14
|
|
|
public $href = ''; |
15
|
|
|
public $misc; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* prints the dataOnly option when exporting a table, view or materialized view. |
19
|
|
|
* |
20
|
|
|
* @param bool $hasID Indicates if the object has has an object ID |
21
|
|
|
* @param bool $onlyCopyAndSQL when exporting schema or DB, only copy or SQL formats are offered |
22
|
|
|
* |
23
|
|
|
* @return string html table row |
24
|
|
|
*/ |
25
|
|
|
public function dataOnly($hasID, $onlyCopyAndSQL = false) |
26
|
|
|
{ |
27
|
|
|
$content = '<tr>'; |
28
|
|
|
$content .= '<th class="data left" rowspan="'.($hasID ? 2 : 1).'">'; |
29
|
|
|
$content .= '<input type="radio" id="what1" name="what" value="dataonly" checked="checked" />'; |
30
|
|
|
$content .= sprintf( |
31
|
|
|
'<label for="what1">%s</label></th>%s', |
32
|
|
|
$this->lang['strdataonly'], |
33
|
|
|
PHP_EOL |
34
|
|
|
); |
35
|
|
|
$content .= sprintf( |
36
|
|
|
'<td>%s</td>%s', |
37
|
|
|
$this->lang['strformat'], |
38
|
|
|
PHP_EOL |
39
|
|
|
); |
40
|
|
|
$content .= '<td><select name="d_format">'.PHP_EOL; |
41
|
|
|
$content .= '<option value="copy">COPY</option>'.PHP_EOL; |
42
|
|
|
$content .= '<option value="sql">SQL</option>'.PHP_EOL; |
43
|
|
|
|
44
|
|
|
if (!$onlyCopyAndSQL) { |
45
|
|
|
$content .= '<option value="csv">CSV</option>'.PHP_EOL; |
46
|
|
|
$content .= "<option value=\"tab\">{$this->lang['strtabbed']}</option>".PHP_EOL; |
47
|
|
|
$content .= '<option value="html">XHTML</option>'.PHP_EOL; |
48
|
|
|
$content .= '<option value="xml">XML</option>'.PHP_EOL; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$content .= sprintf( |
52
|
|
|
'</select>%s</td>%s</tr>%s', |
53
|
|
|
PHP_EOL, |
54
|
|
|
PHP_EOL, |
55
|
|
|
PHP_EOL |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
if ($hasID) { |
59
|
|
|
$content .= sprintf( |
60
|
|
|
'<tr><td><label for="d_oids">%s</td>', |
61
|
|
|
$this->lang['stroids'] |
62
|
|
|
); |
63
|
|
|
$content .= sprintf( |
64
|
|
|
'<td><input type="checkbox" id="d_oids" name="d_oids" /></td>%s</tr>%s', |
65
|
|
|
PHP_EOL, |
66
|
|
|
PHP_EOL |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $content; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* prints the structureAndData option when exporting a table, view or materialized view. |
75
|
|
|
* |
76
|
|
|
* @param bool $hasID Indicates if the object has an object ID |
77
|
|
|
* |
78
|
|
|
* @return string html table row |
79
|
|
|
*/ |
80
|
|
|
public function structureAndData($hasID) |
81
|
|
|
{ |
82
|
|
|
$content = '<tr>'; |
83
|
|
|
$content .= '<th class="data left" rowspan="'.($hasID ? 3 : 2).'">'; |
84
|
|
|
$content .= '<input type="radio" id="what3" name="what" value="structureanddata" />'; |
85
|
|
|
$content .= sprintf( |
86
|
|
|
'<label for="what3">%s</label></th>%s', |
87
|
|
|
$this->lang['strstructureanddata'], |
88
|
|
|
PHP_EOL |
89
|
|
|
); |
90
|
|
|
$content .= sprintf( |
91
|
|
|
'<td>%s</td>%s', |
92
|
|
|
$this->lang['strformat'], |
93
|
|
|
PHP_EOL |
94
|
|
|
); |
95
|
|
|
$content .= '<td><select name="sd_format">'.PHP_EOL; |
96
|
|
|
$content .= '<option value="copy">COPY</option>'.PHP_EOL; |
97
|
|
|
$content .= '<option value="sql">SQL</option>'.PHP_EOL; |
98
|
|
|
$content .= sprintf( |
99
|
|
|
'</select>%s</td>%s</tr>%s', |
100
|
|
|
PHP_EOL, |
101
|
|
|
PHP_EOL, |
102
|
|
|
PHP_EOL |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$content .= sprintf( |
106
|
|
|
'<tr><td><label for="sd_clean">%s</label></td>', |
107
|
|
|
$this->lang['strdrop'] |
108
|
|
|
); |
109
|
|
|
$content .= sprintf( |
110
|
|
|
'<td><input type="checkbox" id="sd_clean" name="sd_clean" /></td>%s</tr>%s', |
111
|
|
|
PHP_EOL, |
112
|
|
|
PHP_EOL |
113
|
|
|
); |
114
|
|
|
if ($hasID) { |
115
|
|
|
$content .= sprintf( |
116
|
|
|
'<tr><td><label for="sd_oids">%s</label></td>', |
117
|
|
|
$this->lang['stroids'] |
118
|
|
|
); |
119
|
|
|
$content .= sprintf( |
120
|
|
|
'<td><input type="checkbox" id="sd_oids" name="sd_oids" /></td>%s</tr>%s', |
121
|
|
|
PHP_EOL, |
122
|
|
|
PHP_EOL |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $content; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* prints the structureAndData option when exporting a table, view or |
131
|
|
|
* materialized view. |
132
|
|
|
* |
133
|
|
|
* @param bool $checked Tell if this option should be checked |
134
|
|
|
* |
135
|
|
|
* @return string html table row |
136
|
|
|
*/ |
137
|
|
|
public function structureOnly($checked = false) |
138
|
|
|
{ |
139
|
|
|
$content = '<tr><th class="data left">'; |
140
|
|
|
$content .= sprintf( |
141
|
|
|
'<input type="radio" id="what2" name="what" value="structureonly" %s />', |
142
|
|
|
$checked ? 'checked="checked"' : '' |
143
|
|
|
); |
144
|
|
|
$content .= sprintf( |
145
|
|
|
'<label for="what2">%s</label></th>', |
146
|
|
|
$this->lang['strstructureonly'], |
147
|
|
|
PHP_EOL |
148
|
|
|
); |
149
|
|
|
$content .= sprintf( |
150
|
|
|
'<td><label for="no_role_info">%s</label></td>', |
151
|
|
|
$this->lang['strdrop'] |
152
|
|
|
); |
153
|
|
|
$content .= sprintf( |
154
|
|
|
'<td><input type="checkbox" id="no_role_info" name="no_role_info" /></td>%s</tr>%s', |
155
|
|
|
PHP_EOL, |
156
|
|
|
PHP_EOL |
157
|
|
|
); |
158
|
|
|
|
159
|
|
|
return $content; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Returns the export form header. |
164
|
|
|
* |
165
|
|
|
* @param string $endpoint The endpoint to send the request to (dataexport or dbexport) |
166
|
|
|
* |
167
|
|
|
* @return string the html for the form header |
168
|
|
|
*/ |
169
|
|
|
public function formHeader($endpoint = 'dataexport') |
170
|
|
|
{ |
171
|
|
|
$content = sprintf( |
172
|
|
|
'<form id="export_form" action="%s/%s" method="post">%s', |
173
|
|
|
\SUBFOLDER.'/src/views', |
174
|
|
|
$endpoint, |
175
|
|
|
PHP_EOL |
176
|
|
|
); |
177
|
|
|
$content .= '<table>'.PHP_EOL; |
178
|
|
|
$content .= sprintf( |
179
|
|
|
'<tr><th class="data">%s</th>', |
180
|
|
|
$this->lang['strformat'] |
181
|
|
|
); |
182
|
|
|
$content .= sprintf( |
183
|
|
|
'<th class="data" colspan="2">%s</th></tr>%s', |
184
|
|
|
$this->lang['stroptions'], |
185
|
|
|
PHP_EOL |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
return $content; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* prints the formFooter section when exporting a table, view or materialized view. |
193
|
|
|
* |
194
|
|
|
* @param string $subject either table, view or matview |
195
|
|
|
* @param string $object name of the table, view or matview |
196
|
|
|
* |
197
|
|
|
* @return string html table row |
198
|
|
|
*/ |
199
|
|
|
public function formFooter($subject, $object) |
200
|
|
|
{ |
201
|
|
|
$content = '<p><input type="hidden" name="action" value="export" />'.PHP_EOL; |
202
|
|
|
|
203
|
|
|
$content .= $this->misc->form; |
204
|
|
|
$content .= sprintf( |
205
|
|
|
'<input type="hidden" name="subject" value="%s" />%s', |
206
|
|
|
$subject, |
207
|
|
|
PHP_EOL |
208
|
|
|
); |
209
|
|
|
$content .= sprintf( |
210
|
|
|
'<input type="hidden" name="%s" value="%s" />', |
211
|
|
|
$subject, |
212
|
|
|
htmlspecialchars($object), |
213
|
|
|
PHP_EOL |
214
|
|
|
); |
215
|
|
|
$content .= sprintf( |
216
|
|
|
'<input type="submit" value="%s" /></p>%s', |
217
|
|
|
$this->lang['strexport'], |
218
|
|
|
PHP_EOL |
219
|
|
|
); |
220
|
|
|
$content .= sprintf( |
221
|
|
|
'</form>%s', |
222
|
|
|
PHP_EOL |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
return $content; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Offers the option of display, download and conditionally download gzipped. |
230
|
|
|
* |
231
|
|
|
* @param bool $offerGzip Offer to download gzipped |
232
|
|
|
* |
233
|
|
|
* @return string the html of the display or download section |
234
|
|
|
*/ |
235
|
|
|
public function displayOrDownload($offerGzip = false) |
236
|
|
|
{ |
237
|
|
|
$content = sprintf( |
238
|
|
|
'</table>%s', |
239
|
|
|
PHP_EOL |
240
|
|
|
); |
241
|
|
|
$content .= sprintf( |
242
|
|
|
'<h3>%s</h3>%s', |
243
|
|
|
$this->lang['stroptions'], |
244
|
|
|
PHP_EOL |
245
|
|
|
); |
246
|
|
|
$content .= '<p><input type="radio" id="output1" name="output" value="show" checked="checked" />'; |
247
|
|
|
$content .= sprintf( |
248
|
|
|
'<label for="output1">%s</label>', |
249
|
|
|
$this->lang['strshow'], |
250
|
|
|
PHP_EOL |
251
|
|
|
); |
252
|
|
|
$content .= '<br/><input type="radio" id="output2" name="output" value="download" />'; |
253
|
|
|
$content .= sprintf( |
254
|
|
|
'<label for="output2">%s</label>', |
255
|
|
|
$this->lang['strdownload'] |
256
|
|
|
); |
257
|
|
|
|
258
|
|
|
if ($offerGzip) { |
259
|
|
|
$content .= '<br /><input type="radio" id="output3" name="output" value="gzipped" />'; |
260
|
|
|
$content .= sprintf( |
261
|
|
|
'<label for="output3">%s</label>%s', |
262
|
|
|
$this->lang['strdownloadgzipped'], |
263
|
|
|
PHP_EOL |
264
|
|
|
); |
265
|
|
|
} |
266
|
|
|
$content .= sprintf( |
267
|
|
|
'</p>%s', |
268
|
|
|
PHP_EOL |
269
|
|
|
); |
270
|
|
|
|
271
|
|
|
return $content; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Offers the option of export database without user credentials. When running in Amazon RDS this is the workaround |
276
|
|
|
* to make pg_dumpall work at all. |
277
|
|
|
* |
278
|
|
|
* |
279
|
|
|
* @param mixed $version10orMore |
280
|
|
|
* |
281
|
|
|
* @return string the html of the options snipper |
282
|
|
|
*/ |
283
|
|
|
public function offerNoRoleExport($version10orMore) |
284
|
|
|
{ |
285
|
|
|
$this->prtrace($version10orMore); |
|
|
|
|
286
|
|
|
if (!$version10orMore) { |
287
|
|
|
return ''; |
288
|
|
|
} |
289
|
|
|
$content = '<tr>'.PHP_EOL; |
290
|
|
|
$content .= sprintf( |
291
|
|
|
'<tr>%s<td colspan="3"> </td></tr>%s', |
292
|
|
|
PHP_EOL, |
293
|
|
|
PHP_EOL |
294
|
|
|
); |
295
|
|
|
$content .= sprintf( |
296
|
|
|
'<tr>%s<th class="data left" colspan="3"><h3>%s <br> %s</h3></th></tr>%s', |
297
|
|
|
PHP_EOL, |
298
|
|
|
'Use the option below if your platform prevents dumping DBs', |
299
|
|
|
'with role info (e.g. Amazon RDS)', |
300
|
|
|
PHP_EOL |
301
|
|
|
); |
302
|
|
|
$content .= sprintf( |
303
|
|
|
'<tr>%s<td colspan="2"><label for="no_role_passwords">%s</label><a href="%s">?</></td>%s', |
304
|
|
|
PHP_EOL, |
305
|
|
|
'Avoid dumping roles', |
306
|
|
|
'https://www.postgresql.org/docs/10/app-pg-dumpall.html', |
307
|
|
|
PHP_EOL |
308
|
|
|
); |
309
|
|
|
$content .= sprintf( |
310
|
|
|
'<td><input type="checkbox" id="no_role_passwords" name="no_role_passwords" /></td>%s</tr>%s', |
311
|
|
|
PHP_EOL, |
312
|
|
|
PHP_EOL |
313
|
|
|
); |
314
|
|
|
|
315
|
|
|
return $content; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|