1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.43 |
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
|
|
|
* prints the dataOnly option when exporting a table, view or materialized view |
18
|
|
|
* |
19
|
|
|
* @param boolean $hasID Indicates if the object has has an object ID |
20
|
|
|
* |
21
|
|
|
* @return string html table row |
22
|
|
|
*/ |
23
|
|
|
public function dataOnly($hasID) |
24
|
|
|
{ |
25
|
|
|
$content = '<tr>'; |
26
|
|
|
$content .= '<th class="data left" rowspan="' . ($hasID ? 2 : 1) . '">'; |
27
|
|
|
$content .= '<input type="radio" id="what1" name="what" value="dataonly" checked="checked" />'; |
28
|
|
|
$content .= sprintf('<label for="what1">%s</label></th>%s', $this->lang['strdataonly'], "\n"); |
29
|
|
|
$content .= sprintf('<td>%s</td>%s', $this->lang['strformat'], "\n"); |
30
|
|
|
$content .= '<td><select name="d_format">' . "\n"; |
31
|
|
|
$content .= '<option value="copy">COPY</option>' . "\n"; |
32
|
|
|
$content .= '<option value="sql">SQL</option>' . "\n"; |
33
|
|
|
$content .= '<option value="csv">CSV</option>' . "\n"; |
34
|
|
|
$content .= "<option value=\"tab\">{$this->lang['strtabbed']}</option>" . "\n"; |
35
|
|
|
$content .= '<option value="html">XHTML</option>' . "\n"; |
36
|
|
|
$content .= '<option value="xml">XML</option>' . "\n"; |
37
|
|
|
$content .= sprintf('</select>%s</td>%s</tr>%s', "\n", "\n", "\n"); |
38
|
|
|
|
39
|
|
|
if ($hasID) { |
40
|
|
|
$content .= sprintf('<tr><td><label for="d_oids">%s</td>', $this->lang['stroids']); |
41
|
|
|
$content .= sprintf('<td><input type="checkbox" id="d_oids" name="d_oids" /></td>%s</tr>%s', "\n", "\n"); |
42
|
|
|
} |
43
|
|
|
return $content; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* prints the structureAndData option when exporting a table, view or materialized view |
48
|
|
|
* |
49
|
|
|
* @param boolean $hasID Indicates if the object has an object ID |
50
|
|
|
* |
51
|
|
|
* @return string html table row |
52
|
|
|
*/ |
53
|
|
|
public function structureAndData($hasID) |
54
|
|
|
{ |
55
|
|
|
$content = '<tr>'; |
56
|
|
|
$content .= '<th class="data left" rowspan="' . ($hasID ? 3 : 2) . '">'; |
57
|
|
|
$content .= '<input type="radio" id="what3" name="what" value="structureanddata" />'; |
58
|
|
|
$content .= sprintf('<label for="what3">%s</label></th>%s', $this->lang['strstructureanddata'], "\n"); |
59
|
|
|
$content .= sprintf('<td>%s</td>%s', $this->lang['strformat'], "\n"); |
60
|
|
|
$content .= '<td><select name="sd_format">' . "\n"; |
61
|
|
|
$content .= '<option value="copy">COPY</option>' . "\n"; |
62
|
|
|
$content .= '<option value="sql">SQL</option>' . "\n"; |
63
|
|
|
$content .= sprintf('</select>%s</td>%s</tr>%s', "\n", "\n", "\n"); |
64
|
|
|
|
65
|
|
|
$content .= sprintf('<tr><td><label for="sd_clean">%s</label></td>', $this->lang['strdrop']); |
66
|
|
|
$content .= sprintf('<td><input type="checkbox" id="sd_clean" name="sd_clean" /></td>%s</tr>%s', "\n", "\n"); |
67
|
|
|
if ($hasID) { |
68
|
|
|
$content .= sprintf('<tr><td><label for="sd_oids">%s</label></td>', $this->lang['stroids']); |
69
|
|
|
$content .= sprintf('<td><input type="checkbox" id="sd_oids" name="sd_oids" /></td>%s</tr>%s', "\n", "\n"); |
70
|
|
|
} |
71
|
|
|
return $content; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* prints the structureAndData option when exporting a table, view or |
76
|
|
|
* materialized view |
77
|
|
|
* |
78
|
|
|
* @param boolean $checked Tell if this option should be checked |
79
|
|
|
* |
80
|
|
|
* @return string html table row |
81
|
|
|
*/ |
82
|
|
|
public function structureOnly($checked = false) |
83
|
|
|
{ |
84
|
|
|
$content = '<tr><th class="data left">'; |
85
|
|
|
$content .= sprintf('<input type="radio" id="what2" name="what" value="structureonly" %s />', $checked ? 'checked="checked"' : ''); |
86
|
|
|
$content .= sprintf('<label for="what2">%s</label></th>', $this->lang['strstructureonly'], "\n"); |
87
|
|
|
$content .= sprintf('<td><label for="s_clean">%s</label></td>', $this->lang['strdrop']); |
88
|
|
|
$content .= sprintf('<td><input type="checkbox" id="s_clean" name="s_clean" /></td>%s</tr>%s', "\n", "\n"); |
89
|
|
|
return $content; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function formHeader() |
93
|
|
|
{ |
94
|
|
|
$content = sprintf('<form action="%s" method=\"post\">%s', \SUBFOLDER . '/src/views/dataexport', "\n"); |
95
|
|
|
$content .= "<table>\n"; |
96
|
|
|
$content .= sprintf('<tr><th class="data">%s</th>', $this->lang['strformat']); |
97
|
|
|
$content .= sprintf('<th class="data" colspan="2">%s</th></tr>%s', $this->lang['stroptions'], "\n"); |
98
|
|
|
return $content; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* prints the formFooter section when exporting a table, view or materialized view |
103
|
|
|
* |
104
|
|
|
* @param string $subject either table, view or matview |
105
|
|
|
* @param string $object name of the table, view or matview |
106
|
|
|
* |
107
|
|
|
* @return string html table row |
108
|
|
|
*/ |
109
|
|
|
public function formFooter($subject, $object) |
110
|
|
|
{ |
111
|
|
|
$content = '<p><input type="hidden" name="action" value="export" />' . "\n"; |
112
|
|
|
$content .= $this->misc->form; |
113
|
|
|
$content .= sprintf('<input type="hidden" name="subject" value="%s" />%s', $subject, "\n"); |
114
|
|
|
$content .= sprintf('<input type="hidden" name="%s" value="%s" />', $subject, htmlspecialchars($object), "\n"); |
115
|
|
|
$content .= sprintf('<input type="submit" value="%s" /></p>%s', $this->lang['strexport'], "\n"); |
116
|
|
|
$content .= sprintf('</form>%s', "\n"); |
117
|
|
|
|
118
|
|
|
return $content; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function displayOrDownload() |
122
|
|
|
{ |
123
|
|
|
$content = sprintf('<h3>%s</h3>%s', $this->lang['stroptions'], "\n"); |
124
|
|
|
$content .= '<p><input type="radio" id="output1" name="output" value="show" checked="checked" />'; |
125
|
|
|
$content .= sprintf('<label for="output1">%s</label>', $this->lang['strshow'], "\n"); |
126
|
|
|
$content .= '<br/><input type="radio" id="output2" name="output" value="download" />'; |
127
|
|
|
$content .= sprintf('<label for="output2">%s</label></p>%s', $this->lang['strdownload'], "\n"); |
128
|
|
|
|
129
|
|
|
return $content; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|