1
|
|
|
<?php |
2
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
3
|
|
|
/** |
4
|
|
|
* Contains PhpMyAdmin\Plugins\Schema\ExportRelationSchema class which is |
5
|
|
|
* inherited by all schema classes. |
6
|
|
|
* |
7
|
|
|
* @package PhpMyAdmin |
8
|
|
|
*/ |
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace PhpMyAdmin\Plugins\Schema; |
12
|
|
|
|
13
|
|
|
use PhpMyAdmin\Relation; |
14
|
|
|
use PhpMyAdmin\Url; |
15
|
|
|
use PhpMyAdmin\Util; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* This class is inherited by all schema classes |
19
|
|
|
* It contains those methods which are common in them |
20
|
|
|
* it works like factory pattern |
21
|
|
|
* |
22
|
|
|
* @package PhpMyAdmin |
23
|
|
|
*/ |
24
|
|
|
class ExportRelationSchema |
25
|
|
|
{ |
26
|
|
|
protected $db; |
27
|
|
|
protected $diagram; |
28
|
|
|
protected $showColor; |
29
|
|
|
protected $tableDimension; |
30
|
|
|
protected $sameWide; |
31
|
|
|
protected $showKeys; |
32
|
|
|
protected $orientation; |
33
|
|
|
protected $paper; |
34
|
|
|
protected $pageNumber; |
35
|
|
|
protected $offline; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Relation |
39
|
|
|
*/ |
40
|
|
|
protected $relation; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Constructor. |
44
|
|
|
* |
45
|
|
|
* @param string $db database name |
46
|
|
|
* @param Pdf\Pdf|Svg\Svg|Eps\Eps|Dia\Dia|Pdf\Pdf|null $diagram schema diagram |
47
|
|
|
*/ |
48
|
|
|
public function __construct($db, $diagram) |
49
|
|
|
{ |
50
|
|
|
$this->db = $db; |
51
|
|
|
$this->diagram = $diagram; |
52
|
|
|
$this->setPageNumber($_REQUEST['page_number']); |
53
|
|
|
$this->setOffline(isset($_REQUEST['offline_export'])); |
54
|
|
|
$this->relation = new Relation($GLOBALS['dbi']); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set Page Number |
59
|
|
|
* |
60
|
|
|
* @param integer $value Page Number of the document to be created |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function setPageNumber($value) |
65
|
|
|
{ |
66
|
|
|
$this->pageNumber = intval($value); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the schema page number |
71
|
|
|
* |
72
|
|
|
* @return integer schema page number |
73
|
|
|
*/ |
74
|
|
|
public function getPageNumber() |
75
|
|
|
{ |
76
|
|
|
return $this->pageNumber; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Sets showColor |
81
|
|
|
* |
82
|
|
|
* @param boolean $value whether to show colors |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function setShowColor($value) |
87
|
|
|
{ |
88
|
|
|
$this->showColor = $value; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns whether to show colors |
93
|
|
|
* |
94
|
|
|
* @return boolean whether to show colors |
95
|
|
|
*/ |
96
|
|
|
public function isShowColor() |
97
|
|
|
{ |
98
|
|
|
return $this->showColor; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Set Table Dimension |
103
|
|
|
* |
104
|
|
|
* @param boolean $value show table co-ordinates or not |
105
|
|
|
* |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
|
|
public function setTableDimension($value) |
109
|
|
|
{ |
110
|
|
|
$this->tableDimension = $value; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns whether to show table dimensions |
115
|
|
|
* |
116
|
|
|
* @return boolean whether to show table dimensions |
117
|
|
|
*/ |
118
|
|
|
public function isTableDimension() |
119
|
|
|
{ |
120
|
|
|
return $this->tableDimension; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Set same width of All Tables |
125
|
|
|
* |
126
|
|
|
* @param boolean $value set same width of all tables or not |
127
|
|
|
* |
128
|
|
|
* @return void |
129
|
|
|
*/ |
130
|
|
|
public function setAllTablesSameWidth($value) |
131
|
|
|
{ |
132
|
|
|
$this->sameWide = $value; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Returns whether to use same width for all tables or not |
137
|
|
|
* |
138
|
|
|
* @return boolean whether to use same width for all tables or not |
139
|
|
|
*/ |
140
|
|
|
public function isAllTableSameWidth() |
141
|
|
|
{ |
142
|
|
|
return $this->sameWide; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Set Show only keys |
147
|
|
|
* |
148
|
|
|
* @param boolean $value show only keys or not |
149
|
|
|
* |
150
|
|
|
* @return void |
151
|
|
|
* |
152
|
|
|
* @access public |
153
|
|
|
*/ |
154
|
|
|
public function setShowKeys($value) |
155
|
|
|
{ |
156
|
|
|
$this->showKeys = $value; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Returns whether to show keys |
161
|
|
|
* |
162
|
|
|
* @return boolean whether to show keys |
163
|
|
|
*/ |
164
|
|
|
public function isShowKeys() |
165
|
|
|
{ |
166
|
|
|
return $this->showKeys; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Set Orientation |
171
|
|
|
* |
172
|
|
|
* @param string $value Orientation will be portrait or landscape |
173
|
|
|
* |
174
|
|
|
* @return void |
175
|
|
|
* |
176
|
|
|
* @access public |
177
|
|
|
*/ |
178
|
|
|
public function setOrientation($value) |
179
|
|
|
{ |
180
|
|
|
$this->orientation = $value == 'P' ? 'P' : 'L'; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Returns orientation |
185
|
|
|
* |
186
|
|
|
* @return string orientation |
187
|
|
|
*/ |
188
|
|
|
public function getOrientation() |
189
|
|
|
{ |
190
|
|
|
return $this->orientation; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Set type of paper |
195
|
|
|
* |
196
|
|
|
* @param string $value paper type can be A4 etc |
197
|
|
|
* |
198
|
|
|
* @return void |
199
|
|
|
* |
200
|
|
|
* @access public |
201
|
|
|
*/ |
202
|
|
|
public function setPaper($value) |
203
|
|
|
{ |
204
|
|
|
$this->paper = $value; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Returns the paper size |
209
|
|
|
* |
210
|
|
|
* @return string paper size |
211
|
|
|
*/ |
212
|
|
|
public function getPaper() |
213
|
|
|
{ |
214
|
|
|
return $this->paper; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Set whether the document is generated from client side DB |
219
|
|
|
* |
220
|
|
|
* @param boolean $value offline or not |
221
|
|
|
* |
222
|
|
|
* @return void |
223
|
|
|
* |
224
|
|
|
* @access public |
225
|
|
|
*/ |
226
|
|
|
public function setOffline($value) |
227
|
|
|
{ |
228
|
|
|
$this->offline = $value; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Returns whether the client side database is used |
233
|
|
|
* |
234
|
|
|
* @return boolean |
235
|
|
|
* |
236
|
|
|
* @access public |
237
|
|
|
*/ |
238
|
|
|
public function isOffline() |
239
|
|
|
{ |
240
|
|
|
return $this->offline; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Get the table names from the request |
245
|
|
|
* |
246
|
|
|
* @return array an array of table names |
247
|
|
|
*/ |
248
|
|
|
protected function getTablesFromRequest() |
249
|
|
|
{ |
250
|
|
|
$tables = []; |
251
|
|
|
$dbLength = mb_strlen($this->db); |
252
|
|
|
foreach ($_REQUEST['t_h'] as $key => $value) { |
253
|
|
|
if ($value) { |
254
|
|
|
$tables[] = mb_substr($key, $dbLength + 1); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
return $tables; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Returns the file name |
263
|
|
|
* |
264
|
|
|
* @param String $extension file extension |
265
|
|
|
* |
266
|
|
|
* @return string file name |
267
|
|
|
*/ |
268
|
|
|
protected function getFileName($extension) |
269
|
|
|
{ |
270
|
|
|
$filename = $this->db . $extension; |
271
|
|
|
// Get the name of this page to use as filename |
272
|
|
|
if ($this->pageNumber != -1 && ! $this->offline) { |
273
|
|
|
$_name_sql = 'SELECT page_descr FROM ' |
274
|
|
|
. Util::backquote($GLOBALS['cfgRelation']['db']) . '.' |
|
|
|
|
275
|
|
|
. Util::backquote($GLOBALS['cfgRelation']['pdf_pages']) |
|
|
|
|
276
|
|
|
. ' WHERE page_nr = ' . $this->pageNumber; |
277
|
|
|
$_name_rs = $this->relation->queryAsControlUser($_name_sql); |
278
|
|
|
$_name_row = $GLOBALS['dbi']->fetchRow($_name_rs); |
279
|
|
|
$filename = $_name_row[0] . $extension; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return $filename; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Displays an error message |
287
|
|
|
* |
288
|
|
|
* @param integer $pageNumber ID of the chosen page |
289
|
|
|
* @param string $type Schema Type |
290
|
|
|
* @param string $error_message The error message |
291
|
|
|
* |
292
|
|
|
* @access public |
293
|
|
|
* |
294
|
|
|
* @return void |
295
|
|
|
*/ |
296
|
|
|
public static function dieSchema($pageNumber, $type = '', $error_message = '') |
297
|
|
|
{ |
298
|
|
|
echo "<p><strong>" , __("SCHEMA ERROR: ") , $type , "</strong></p>" , "\n"; |
299
|
|
|
if (! empty($error_message)) { |
300
|
|
|
$error_message = htmlspecialchars($error_message); |
301
|
|
|
} |
302
|
|
|
echo '<p>' , "\n"; |
303
|
|
|
echo ' ' , $error_message , "\n"; |
304
|
|
|
echo '</p>' , "\n"; |
305
|
|
|
echo '<a href="'; |
306
|
|
|
echo Url::getFromRoute('/database/designer', [ |
307
|
|
|
'db' => $GLOBALS['db'], |
308
|
|
|
'page' => $pageNumber, |
309
|
|
|
]); |
310
|
|
|
echo '">' . __('Back') . '</a>'; |
311
|
|
|
echo "\n"; |
312
|
|
|
exit; |
|
|
|
|
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
|