Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExportTrait.php « traits « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 72ab9ffc673a594c89aef31de5a59021a536db3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php

/**
 * PHPPgAdmin v6.0.0-RC7
 */

namespace PHPPgAdmin\Traits;

/**
 * Common trait for exporting tables, views or materialized views.
 */
trait ExportTrait
{
    public $href = '';
    public $misc;

    /**
     * prints the dataOnly option when exporting a table, view or materialized view.
     *
     * @param bool $hasID          Indicates if the object has has an object ID
     * @param bool $onlyCopyAndSQL when exporting schema or DB, only copy or SQL formats are offered
     *
     * @return string html table row
     */
    public function dataOnly($hasID, $onlyCopyAndSQL = false)
    {
        $content = '<tr>';
        $content .= '<th class="data left" rowspan="'.($hasID ? 2 : 1).'">';
        $content .= '<input type="radio" id="what1" name="what" value="dataonly" checked="checked" />';
        $content .= sprintf(
            '<label for="what1">%s</label></th>%s',
            $this->lang['strdataonly'],
            PHP_EOL
        );
        $content .= sprintf(
            '<td>%s</td>%s',
            $this->lang['strformat'],
            PHP_EOL
        );
        $content .= '<td><select name="d_format">'.PHP_EOL;
        $content .= '<option value="copy">COPY</option>'.PHP_EOL;
        $content .= '<option value="sql">SQL</option>'.PHP_EOL;

        if (!$onlyCopyAndSQL) {
            $content .= '<option value="csv">CSV</option>'.PHP_EOL;
            $content .= "<option value=\"tab\">{$this->lang['strtabbed']}</option>".PHP_EOL;
            $content .= '<option value="html">XHTML</option>'.PHP_EOL;
            $content .= '<option value="xml">XML</option>'.PHP_EOL;
        }

        $content .= sprintf(
            '</select>%s</td>%s</tr>%s',
            PHP_EOL,
            PHP_EOL,
            PHP_EOL
        );

        if ($hasID) {
            $content .= sprintf(
                '<tr><td><label for="d_oids">%s</td>',
                $this->lang['stroids']
            );
            $content .= sprintf(
                '<td><input type="checkbox" id="d_oids" name="d_oids" /></td>%s</tr>%s',
                PHP_EOL,
                PHP_EOL
            );
        }

        return $content;
    }

    /**
     * prints the structureAndData option when exporting a table, view or materialized view.
     *
     * @param bool $hasID Indicates if the object has an object ID
     *
     * @return string html table row
     */
    public function structureAndData($hasID)
    {
        $content = '<tr>';
        $content .= '<th class="data left" rowspan="'.($hasID ? 3 : 2).'">';
        $content .= '<input type="radio" id="what3" name="what" value="structureanddata" />';
        $content .= sprintf(
            '<label for="what3">%s</label></th>%s',
            $this->lang['strstructureanddata'],
            PHP_EOL
        );
        $content .= sprintf(
            '<td>%s</td>%s',
            $this->lang['strformat'],
            PHP_EOL
        );
        $content .= '<td><select name="sd_format">'.PHP_EOL;
        $content .= '<option value="copy">COPY</option>'.PHP_EOL;
        $content .= '<option value="sql">SQL</option>'.PHP_EOL;
        $content .= sprintf(
            '</select>%s</td>%s</tr>%s',
            PHP_EOL,
            PHP_EOL,
            PHP_EOL
        );

        $content .= sprintf(
            '<tr><td><label for="sd_clean">%s</label></td>',
            $this->lang['strdrop']
        );
        $content .= sprintf(
            '<td><input type="checkbox" id="sd_clean" name="sd_clean" /></td>%s</tr>%s',
            PHP_EOL,
            PHP_EOL
        );
        if ($hasID) {
            $content .= sprintf(
                '<tr><td><label for="sd_oids">%s</label></td>',
                $this->lang['stroids']
            );
            $content .= sprintf(
                '<td><input type="checkbox" id="sd_oids" name="sd_oids" /></td>%s</tr>%s',
                PHP_EOL,
                PHP_EOL
            );
        }

        return $content;
    }

    /**
     * prints the structureAndData option when exporting a table, view or
     * materialized view.
     *
     * @param bool $checked Tell if this option should be checked
     *
     * @return string html table row
     */
    public function structureOnly($checked = false)
    {
        $content = '<tr><th class="data left">';
        $content .= sprintf(
            '<input type="radio" id="what2" name="what" value="structureonly" %s />',
            $checked ? 'checked="checked"' : ''
        );
        $content .= sprintf(
            '<label for="what2">%s</label></th>',
            $this->lang['strstructureonly'],
            PHP_EOL
        );
        $content .= sprintf(
            '<td><label for="no_role_info">%s</label></td>',
            $this->lang['strdrop']
        );
        $content .= sprintf(
            '<td><input type="checkbox" id="no_role_info" name="no_role_info" /></td>%s</tr>%s',
            PHP_EOL,
            PHP_EOL
        );

        return $content;
    }

    /**
     * Returns the export form header.
     *
     * @param string $endpoint The endpoint to send the request to (dataexport or dbexport)
     *
     * @return string the html for the form header
     */
    public function formHeader($endpoint = 'dataexport')
    {
        $content = sprintf(
            '<form id="export_form" action="%s/%s" method="post">%s',
            \SUBFOLDER.'/src/views',
            $endpoint,
            PHP_EOL
        );
        $content .= '<table>'.PHP_EOL;
        $content .= sprintf(
            '<tr><th class="data">%s</th>',
            $this->lang['strformat']
        );
        $content .= sprintf(
            '<th class="data" colspan="2">%s</th></tr>%s',
            $this->lang['stroptions'],
            PHP_EOL
        );

        return $content;
    }

    /**
     * prints the formFooter section when exporting a table, view or materialized view.
     *
     * @param string $subject either table, view or matview
     * @param string $object  name of the table, view or matview
     *
     * @return string html table row
     */
    public function formFooter($subject, $object)
    {
        $content = '<p><input type="hidden" name="action" value="export" />'.PHP_EOL;

        $content .= $this->misc->form;
        $content .= sprintf(
            '<input type="hidden" name="subject" value="%s" />%s',
            $subject,
            PHP_EOL
        );
        $content .= sprintf(
            '<input type="hidden" name="%s" value="%s" />',
            $subject,
            htmlspecialchars($object),
            PHP_EOL
        );
        $content .= sprintf(
            '<input type="submit" value="%s" /></p>%s',
            $this->lang['strexport'],
            PHP_EOL
        );
        $content .= sprintf(
            '</form>%s',
            PHP_EOL
        );

        return $content;
    }

    /**
     * Offers the option of display, download and conditionally download gzipped.
     *
     * @param bool $offerGzip Offer to download gzipped
     *
     * @return string the html of the display or download section
     */
    public function displayOrDownload($offerGzip = false)
    {
        $content = sprintf(
            '</table>%s',
            PHP_EOL
        );
        $content .= sprintf(
            '<h3>%s</h3>%s',
            $this->lang['stroptions'],
            PHP_EOL
        );
        $content .= '<p><input type="radio" id="output1" name="output" value="show" checked="checked" />';
        $content .= sprintf(
            '<label for="output1">%s</label>',
            $this->lang['strshow'],
            PHP_EOL
        );
        $content .= '<br/><input type="radio" id="output2" name="output" value="download" />';
        $content .= sprintf(
            '<label for="output2">%s</label>',
            $this->lang['strdownload']
        );

        if ($offerGzip) {
            $content .= '<br /><input type="radio" id="output3" name="output" value="gzipped" />';
            $content .= sprintf(
                '<label for="output3">%s</label>%s',
                $this->lang['strdownloadgzipped'],
                PHP_EOL
            );
        }
        $content .= sprintf(
            '</p>%s',
            PHP_EOL
        );

        return $content;
    }

    /**
     * Offers the option of export database without user credentials. When running in Amazon RDS this is the workaround
     * to make pg_dumpall work at all.
     *
     * @param mixed $version10orMore
     *
     * @return string the html of the options snipper
     */
    public function offerNoRoleExport($version10orMore)
    {
        $this->prtrace($version10orMore);
        if (!$version10orMore) {
            return '';
        }
        $content = '<tr>'.PHP_EOL;
        $content .= sprintf(
            '<tr>%s<td colspan="3">&nbsp</td></tr>%s',
            PHP_EOL,
            PHP_EOL
        );
        $content .= sprintf(
            '<tr>%s<th class="data left" colspan="3"><h3>%s <br> %s</h3></th></tr>%s',
            PHP_EOL,
            'Use the option below if your platform prevents dumping DBs',
            'with role info (e.g. Amazon RDS)',
            PHP_EOL
        );
        $content .= sprintf(
            '<tr>%s<td colspan="2"><label for="no_role_passwords">%s</label><a href="%s">?</></td>%s',
            PHP_EOL,
            'Avoid dumping roles',
            'https://www.postgresql.org/docs/10/app-pg-dumpall.html',
            PHP_EOL
        );
        $content .= sprintf(
            '<td><input type="checkbox" id="no_role_passwords" name="no_role_passwords" /></td>%s</tr>%s',
            PHP_EOL,
            PHP_EOL
        );

        return $content;
    }
}