1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* PHPPgAdmin v6.0.0-beta.30 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
8
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Base controller class. |
13
|
|
|
*/ |
|
|
|
|
14
|
|
|
class ViewsController extends BaseController |
15
|
|
|
{ |
16
|
|
|
public $script = 'views.php'; |
17
|
|
|
public $controller_name = 'ViewsController'; |
18
|
|
|
public $table_place = 'views-views'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Default method to render the controller according to the action parameter. |
22
|
|
|
*/ |
23
|
|
|
public function render() |
24
|
|
|
{ |
25
|
|
|
$lang = $this->lang; |
26
|
|
|
$action = $this->action; |
27
|
|
|
|
28
|
|
|
if ('tree' == $action) { |
29
|
|
|
return $this->doTree(); |
30
|
|
|
} |
31
|
|
|
if ('subtree' == $action) { |
32
|
|
|
return $this->doSubTree(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$this->printHeader($lang['strviews']); |
38
|
|
|
$this->printBody(); |
39
|
|
|
|
40
|
|
|
switch ($action) { |
41
|
|
|
case 'selectrows': |
42
|
|
|
if (!isset($_REQUEST['cancel'])) { |
43
|
|
|
$this->doSelectRows(false); |
44
|
|
|
} else { |
45
|
|
|
$this->doDefault(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
break; |
49
|
|
|
case 'confselectrows': |
50
|
|
|
$this->doSelectRows(true); |
51
|
|
|
|
52
|
|
|
break; |
53
|
|
|
case 'save_create_wiz': |
54
|
|
|
if (isset($_REQUEST['cancel'])) { |
55
|
|
|
$this->doDefault(); |
56
|
|
|
} else { |
57
|
|
|
$this->doSaveCreateWiz(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
break; |
61
|
|
|
case 'wiz_create': |
62
|
|
|
$this->doWizardCreate(); |
63
|
|
|
|
64
|
|
|
break; |
65
|
|
|
case 'set_params_create': |
66
|
|
|
if (isset($_POST['cancel'])) { |
67
|
|
|
$this->doDefault(); |
68
|
|
|
} else { |
69
|
|
|
$this->doSetParamsCreate(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
break; |
73
|
|
|
case 'save_create': |
74
|
|
|
if (isset($_REQUEST['cancel'])) { |
75
|
|
|
$this->doDefault(); |
76
|
|
|
} else { |
77
|
|
|
$this->doSaveCreate(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
break; |
81
|
|
|
case 'create': |
82
|
|
|
$this->doCreate(); |
83
|
|
|
|
84
|
|
|
break; |
85
|
|
|
case 'drop': |
86
|
|
|
if (isset($_POST['drop'])) { |
87
|
|
|
$this->doDrop(false); |
88
|
|
|
} else { |
89
|
|
|
$this->doDefault(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
break; |
93
|
|
|
case 'confirm_drop': |
94
|
|
|
$this->doDrop(true); |
95
|
|
|
|
96
|
|
|
break; |
97
|
|
|
default: |
98
|
|
|
$this->doDefault(); |
99
|
|
|
|
100
|
|
|
break; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->printFooter(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Show default list of views in the database. |
108
|
|
|
* |
109
|
|
|
* @param mixed $msg |
|
|
|
|
110
|
|
|
*/ |
111
|
|
|
public function doDefault($msg = '') |
112
|
|
|
{ |
113
|
|
|
$lang = $this->lang; |
114
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
115
|
|
|
|
116
|
|
|
$this->printTrail('schema'); |
117
|
|
|
$this->printTabs('schema', 'views'); |
118
|
|
|
$this->printMsg($msg); |
119
|
|
|
|
120
|
|
|
$views = $data->getViews(); |
121
|
|
|
|
122
|
|
|
$columns = [ |
123
|
|
|
'view' => [ |
124
|
|
|
'title' => $lang['strview'], |
125
|
|
|
'field' => Decorator::field('relname'), |
126
|
|
|
'url' => \SUBFOLDER . "/redirect/view?{$this->misc->href}&", |
127
|
|
|
'vars' => ['view' => 'relname'], |
128
|
|
|
], |
129
|
|
|
'owner' => [ |
130
|
|
|
'title' => $lang['strowner'], |
131
|
|
|
'field' => Decorator::field('relowner'), |
132
|
|
|
], |
133
|
|
|
'actions' => [ |
134
|
|
|
'title' => $lang['stractions'], |
135
|
|
|
], |
136
|
|
|
'comment' => [ |
137
|
|
|
'title' => $lang['strcomment'], |
138
|
|
|
'field' => Decorator::field('relcomment'), |
139
|
|
|
], |
140
|
|
|
]; |
141
|
|
|
|
142
|
|
|
$actions = [ |
143
|
|
|
'multiactions' => [ |
144
|
|
|
'keycols' => ['view' => 'relname'], |
145
|
|
|
'url' => 'views.php', |
146
|
|
|
], |
147
|
|
|
'browse' => [ |
148
|
|
|
'content' => $lang['strbrowse'], |
149
|
|
|
'attr' => [ |
150
|
|
|
'href' => [ |
151
|
|
|
'url' => 'display.php', |
152
|
|
|
'urlvars' => [ |
153
|
|
|
'action' => 'confselectrows', |
154
|
|
|
'subject' => 'view', |
155
|
|
|
'return' => 'schema', |
156
|
|
|
'view' => Decorator::field('relname'), |
157
|
|
|
], |
158
|
|
|
], |
159
|
|
|
], |
160
|
|
|
], |
161
|
|
|
'select' => [ |
162
|
|
|
'content' => $lang['strselect'], |
163
|
|
|
'attr' => [ |
164
|
|
|
'href' => [ |
165
|
|
|
'url' => 'views.php', |
166
|
|
|
'urlvars' => [ |
167
|
|
|
'action' => 'confselectrows', |
168
|
|
|
'view' => Decorator::field('relname'), |
169
|
|
|
], |
170
|
|
|
], |
171
|
|
|
], |
172
|
|
|
], |
173
|
|
|
|
174
|
|
|
// Insert is possible if the relevant rule for the view has been created. |
175
|
|
|
// 'insert' => array( |
176
|
|
|
// 'title' => $lang['strinsert'], |
177
|
|
|
// 'url' => "views.php?action=confinsertrow&{$this->misc->href}&", |
178
|
|
|
// 'vars' => array('view' => 'relname'), |
179
|
|
|
// ), |
180
|
|
|
|
181
|
|
|
'alter' => [ |
182
|
|
|
'content' => $lang['stralter'], |
183
|
|
|
'attr' => [ |
184
|
|
|
'href' => [ |
185
|
|
|
'url' => 'viewproperties.php', |
186
|
|
|
'urlvars' => [ |
187
|
|
|
'action' => 'confirm_alter', |
188
|
|
|
'view' => Decorator::field('relname'), |
189
|
|
|
], |
190
|
|
|
], |
191
|
|
|
], |
192
|
|
|
], |
193
|
|
|
'drop' => [ |
194
|
|
|
'multiaction' => 'confirm_drop', |
195
|
|
|
'content' => $lang['strdrop'], |
196
|
|
|
'attr' => [ |
197
|
|
|
'href' => [ |
198
|
|
|
'url' => 'views.php', |
199
|
|
|
'urlvars' => [ |
200
|
|
|
'action' => 'confirm_drop', |
201
|
|
|
'view' => Decorator::field('relname'), |
202
|
|
|
], |
203
|
|
|
], |
204
|
|
|
], |
205
|
|
|
], |
206
|
|
|
]; |
207
|
|
|
|
208
|
|
|
echo $this->printTable($views, $columns, $actions, $this->table_place, $lang['strnoviews']); |
209
|
|
|
|
210
|
|
|
$navlinks = [ |
211
|
|
|
'create' => [ |
212
|
|
|
'attr' => [ |
213
|
|
|
'href' => [ |
214
|
|
|
'url' => 'views.php', |
215
|
|
|
'urlvars' => [ |
216
|
|
|
'action' => 'create', |
217
|
|
|
'server' => $_REQUEST['server'], |
218
|
|
|
'database' => $_REQUEST['database'], |
219
|
|
|
'schema' => $_REQUEST['schema'], |
220
|
|
|
], |
221
|
|
|
], |
222
|
|
|
], |
223
|
|
|
'content' => $lang['strcreateview'], |
224
|
|
|
], |
225
|
|
|
'createwiz' => [ |
226
|
|
|
'attr' => [ |
227
|
|
|
'href' => [ |
228
|
|
|
'url' => 'views.php', |
229
|
|
|
'urlvars' => [ |
230
|
|
|
'action' => 'wiz_create', |
231
|
|
|
'server' => $_REQUEST['server'], |
232
|
|
|
'database' => $_REQUEST['database'], |
233
|
|
|
'schema' => $_REQUEST['schema'], |
234
|
|
|
], |
235
|
|
|
], |
236
|
|
|
], |
237
|
|
|
'content' => $lang['strcreateviewwiz'], |
238
|
|
|
], |
239
|
|
|
]; |
240
|
|
|
$this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Generate XML for the browser tree. |
245
|
|
|
*/ |
246
|
|
|
public function doTree() |
247
|
|
|
{ |
248
|
|
|
$lang = $this->lang; |
|
|
|
|
249
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
250
|
|
|
|
251
|
|
|
$views = $data->getViews(); |
252
|
|
|
|
253
|
|
|
$reqvars = $this->misc->getRequestVars('view'); |
254
|
|
|
|
255
|
|
|
$attrs = [ |
256
|
|
|
'text' => Decorator::field('relname'), |
257
|
|
|
'icon' => 'View', |
258
|
|
|
'iconAction' => Decorator::url('display.php', $reqvars, ['view' => Decorator::field('relname')]), |
259
|
|
|
'toolTip' => Decorator::field('relcomment'), |
260
|
|
|
'action' => Decorator::redirecturl('redirect.php', $reqvars, ['view' => Decorator::field('relname')]), |
261
|
|
|
'branch' => Decorator::url('views.php', $reqvars, ['action' => 'subtree', 'view' => Decorator::field('relname')]), |
262
|
|
|
]; |
263
|
|
|
|
264
|
|
|
return $this->printTree($views, $attrs, 'views'); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
public function doSubTree() |
|
|
|
|
268
|
|
|
{ |
269
|
|
|
$lang = $this->lang; |
|
|
|
|
270
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
|
|
|
271
|
|
|
|
272
|
|
|
$tabs = $this->misc->getNavTabs('view'); |
273
|
|
|
$items = $this->adjustTabsForTree($tabs); |
274
|
|
|
$reqvars = $this->misc->getRequestVars('view'); |
275
|
|
|
|
276
|
|
|
$attrs = [ |
277
|
|
|
'text' => Decorator::field('title'), |
278
|
|
|
'icon' => Decorator::field('icon'), |
279
|
|
|
'action' => Decorator::actionurl(Decorator::field('url'), $reqvars, Decorator::field('urlvars'), ['view' => $_REQUEST['view']]), |
280
|
|
|
'branch' => Decorator::ifempty( |
281
|
|
|
Decorator::field('branch'), |
282
|
|
|
'', |
283
|
|
|
Decorator::url( |
284
|
|
|
Decorator::field('url'), |
285
|
|
|
Decorator::field('urlvars'), |
286
|
|
|
$reqvars, |
287
|
|
|
[ |
288
|
|
|
'action' => 'tree', |
289
|
|
|
'view' => $_REQUEST['view'], |
290
|
|
|
] |
291
|
|
|
) |
292
|
|
|
), |
293
|
|
|
]; |
294
|
|
|
|
295
|
|
|
return $this->printTree($items, $attrs, 'view'); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Ask for select parameters and perform select. |
300
|
|
|
* |
301
|
|
|
* @param mixed $confirm |
|
|
|
|
302
|
|
|
* @param mixed $msg |
|
|
|
|
303
|
|
|
*/ |
304
|
|
|
public function doSelectRows($confirm, $msg = '') |
305
|
|
|
{ |
306
|
|
|
$lang = $this->lang; |
307
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
308
|
|
|
|
309
|
|
|
if ($confirm) { |
310
|
|
|
$this->printTrail('view'); |
311
|
|
|
$this->printTabs('view', 'select'); |
312
|
|
|
$this->printMsg($msg); |
313
|
|
|
|
314
|
|
|
$attrs = $data->getTableAttributes($_REQUEST['view']); |
315
|
|
|
|
316
|
|
|
echo '<form action="' . \SUBFOLDER . '/src/views/' . $this->script . '" method="post" id="selectform">'; |
317
|
|
|
echo "\n"; |
318
|
|
|
|
319
|
|
|
if ($attrs->recordCount() > 0) { |
320
|
|
|
// JavaScript for select all feature |
321
|
|
|
echo "<script type=\"text/javascript\">\n"; |
322
|
|
|
echo "//<![CDATA[\n"; |
323
|
|
|
echo " function selectAll() {\n"; |
324
|
|
|
echo " for (var i=0; i<document.getElementById('selectform').elements.length; i++) {\n"; |
325
|
|
|
echo " var e = document.getElementById('selectform').elements[i];\n"; |
326
|
|
|
echo " if (e.name.indexOf('show') == 0) { \n "; |
327
|
|
|
echo " e.checked = document.getElementById('selectform').selectall.checked;\n"; |
328
|
|
|
echo " }\n"; |
329
|
|
|
echo " }\n"; |
330
|
|
|
echo " }\n"; |
331
|
|
|
echo "//]]>\n"; |
332
|
|
|
echo "</script>\n"; |
333
|
|
|
|
334
|
|
|
echo "<table>\n"; |
335
|
|
|
|
336
|
|
|
// Output table header |
337
|
|
|
echo "<tr><th class=\"data\">{$lang['strshow']}</th><th class=\"data\">{$lang['strcolumn']}</th>"; |
338
|
|
|
echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['stroperator']}</th>"; |
339
|
|
|
echo "<th class=\"data\">{$lang['strvalue']}</th></tr>"; |
340
|
|
|
|
341
|
|
|
$i = 0; |
342
|
|
|
while (!$attrs->EOF) { |
343
|
|
|
$attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
344
|
|
|
// Set up default value if there isn't one already |
345
|
|
|
if (!isset($_REQUEST['values'][$attrs->fields['attname']])) { |
346
|
|
|
$_REQUEST['values'][$attrs->fields['attname']] = null; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
if (!isset($_REQUEST['ops'][$attrs->fields['attname']])) { |
350
|
|
|
$_REQUEST['ops'][$attrs->fields['attname']] = null; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
// Continue drawing row |
354
|
|
|
$id = (0 == ($i % 2) ? '1' : '2'); |
355
|
|
|
echo "<tr class=\"data{$id}\">\n"; |
356
|
|
|
echo '<td style="white-space:nowrap;">'; |
357
|
|
|
echo '<input type="checkbox" name="show[', htmlspecialchars($attrs->fields['attname']), ']"', |
358
|
|
|
isset($_REQUEST['show'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></td>'; |
359
|
|
|
echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
360
|
|
|
echo '<td style="white-space:nowrap;">', $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])), '</td>'; |
361
|
|
|
echo '<td style="white-space:nowrap;">'; |
362
|
|
|
echo "<select name=\"ops[{$attrs->fields['attname']}]\">\n"; |
363
|
|
|
foreach (array_keys($data->selectOps) as $v) { |
364
|
|
|
echo '<option value="', htmlspecialchars($v), '"', ($_REQUEST['ops'][$attrs->fields['attname']] == $v) ? ' selected="selected"' : '', |
365
|
|
|
'>', htmlspecialchars($v), "</option>\n"; |
366
|
|
|
} |
367
|
|
|
echo "</select></td>\n"; |
368
|
|
|
echo '<td style="white-space:nowrap;">', $data->printField( |
369
|
|
|
"values[{$attrs->fields['attname']}]", |
370
|
|
|
$_REQUEST['values'][$attrs->fields['attname']], |
371
|
|
|
$attrs->fields['type'] |
372
|
|
|
), '</td>'; |
373
|
|
|
echo "</tr>\n"; |
374
|
|
|
++$i; |
375
|
|
|
$attrs->moveNext(); |
376
|
|
|
} |
377
|
|
|
// Select all checkbox |
378
|
|
|
echo "<tr><td colspan=\"5\"><input type=\"checkbox\" id=\"selectall\" name=\"selectall\" accesskey=\"a\" onclick=\"javascript:selectAll()\" /><label for=\"selectall\">{$lang['strselectallfields']}</label></td></tr>"; |
379
|
|
|
echo "</table>\n"; |
380
|
|
|
} else { |
381
|
|
|
echo "<p>{$lang['strinvalidparam']}</p>\n"; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n"; |
385
|
|
|
echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['view']), "\" />\n"; |
386
|
|
|
echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
387
|
|
|
echo $this->misc->form; |
388
|
|
|
echo "<input type=\"submit\" name=\"select\" accesskey=\"r\" value=\"{$lang['strselect']}\" />\n"; |
389
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
390
|
|
|
echo "</form>\n"; |
391
|
|
|
|
392
|
|
|
return; |
393
|
|
|
} |
394
|
|
|
if (!isset($_POST['show'])) { |
395
|
|
|
$_POST['show'] = []; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
if (!isset($_POST['values'])) { |
399
|
|
|
$_POST['values'] = []; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
if (!isset($_POST['nulls'])) { |
403
|
|
|
$_POST['nulls'] = []; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
// Verify that they haven't supplied a value for unary operators |
407
|
|
|
foreach ($_POST['ops'] as $k => $v) { |
408
|
|
|
if ('p' == $data->selectOps[$v] && $_POST['values'][$k] != '') { |
409
|
|
|
$this->doSelectRows(true, $lang['strselectunary']); |
410
|
|
|
|
411
|
|
|
return; |
412
|
|
|
} |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
if (0 == sizeof($_POST['show'])) { |
416
|
|
|
return $this->doSelectRows(true, $lang['strselectneedscol']); |
417
|
|
|
} |
418
|
|
|
// Generate query SQL |
419
|
|
|
$query = $data->getSelectSQL($_REQUEST['view'], array_keys($_POST['show']), $_POST['values'], $_POST['ops']); |
420
|
|
|
|
421
|
|
|
$_REQUEST['query'] = $query; |
422
|
|
|
$_REQUEST['return'] = 'schema'; |
423
|
|
|
|
424
|
|
|
$this->setNoOutput(true); |
425
|
|
|
|
426
|
|
|
$display_controller = new DisplayController($this->getContainer()); |
427
|
|
|
|
428
|
|
|
return $display_controller->render(); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Show confirmation of drop and perform actual drop. |
433
|
|
|
* |
434
|
|
|
* @param mixed $confirm |
|
|
|
|
435
|
|
|
*/ |
436
|
|
|
public function doDrop($confirm) |
437
|
|
|
{ |
438
|
|
|
$lang = $this->lang; |
439
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
440
|
|
|
|
441
|
|
|
if (empty($_REQUEST['view']) && empty($_REQUEST['ma'])) { |
442
|
|
|
return $this->doDefault($lang['strspecifyviewtodrop']); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
if ($confirm) { |
446
|
|
|
$this->printTrail('view'); |
447
|
|
|
$this->printTitle($lang['strdrop'], 'pg.view.drop'); |
448
|
|
|
|
449
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
450
|
|
|
|
451
|
|
|
//If multi drop |
452
|
|
|
if (isset($_REQUEST['ma'])) { |
453
|
|
|
foreach ($_REQUEST['ma'] as $v) { |
454
|
|
|
$a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
455
|
|
|
echo '<p>', sprintf($lang['strconfdropview'], $this->misc->printVal($a['view'])), "</p>\n"; |
456
|
|
|
echo '<input type="hidden" name="view[]" value="', htmlspecialchars($a['view']), "\" />\n"; |
457
|
|
|
} |
458
|
|
|
} else { |
459
|
|
|
echo '<p>', sprintf($lang['strconfdropview'], $this->misc->printVal($_REQUEST['view'])), "</p>\n"; |
460
|
|
|
echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['view']), "\" />\n"; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
464
|
|
|
|
465
|
|
|
echo $this->misc->form; |
466
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
467
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
468
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
469
|
|
|
echo "</form>\n"; |
470
|
|
|
} else { |
471
|
|
|
if (is_array($_POST['view'])) { |
472
|
|
|
$msg = ''; |
473
|
|
|
$status = $data->beginTransaction(); |
474
|
|
|
if (0 == $status) { |
475
|
|
|
foreach ($_POST['view'] as $s) { |
476
|
|
|
$status = $data->dropView($s, isset($_POST['cascade'])); |
477
|
|
|
if (0 == $status) { |
478
|
|
|
$msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strviewdropped']); |
479
|
|
|
} else { |
480
|
|
|
$data->endTransaction(); |
481
|
|
|
$this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strviewdroppedbad'])); |
482
|
|
|
|
483
|
|
|
return; |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
if (0 == $data->endTransaction()) { |
488
|
|
|
// Everything went fine, back to the Default page.... |
489
|
|
|
$this->misc->setReloadBrowser(true); |
490
|
|
|
$this->doDefault($msg); |
491
|
|
|
} else { |
492
|
|
|
$this->doDefault($lang['strviewdroppedbad']); |
493
|
|
|
} |
494
|
|
|
} else { |
495
|
|
|
$status = $data->dropView($_POST['view'], isset($_POST['cascade'])); |
496
|
|
|
if (0 == $status) { |
497
|
|
|
$this->misc->setReloadBrowser(true); |
498
|
|
|
$this->doDefault($lang['strviewdropped']); |
499
|
|
|
} else { |
500
|
|
|
$this->doDefault($lang['strviewdroppedbad']); |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Sets up choices for table linkage, and which fields to select for the view we're creating. |
508
|
|
|
* |
509
|
|
|
* @param mixed $msg |
|
|
|
|
510
|
|
|
*/ |
511
|
|
|
public function doSetParamsCreate($msg = '') |
512
|
|
|
{ |
513
|
|
|
$lang = $this->lang; |
514
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
515
|
|
|
|
516
|
|
|
// Check that they've chosen tables for the view definition |
517
|
|
|
if (!isset($_POST['formTables'])) { |
518
|
|
|
$this->doWizardCreate($lang['strviewneedsdef']); |
519
|
|
|
} else { |
520
|
|
|
// Initialise variables |
521
|
|
|
if (!isset($_REQUEST['formView'])) { |
522
|
|
|
$_REQUEST['formView'] = ''; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
if (!isset($_REQUEST['formComment'])) { |
526
|
|
|
$_REQUEST['formComment'] = ''; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
$this->printTrail('schema'); |
530
|
|
|
$this->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); |
531
|
|
|
$this->printMsg($msg); |
532
|
|
|
|
533
|
|
|
$tblCount = sizeof($_POST['formTables']); |
534
|
|
|
//unserialize our schema/table information and store in arrSelTables |
535
|
|
|
for ($i = 0; $i < $tblCount; ++$i) { |
536
|
|
|
$arrSelTables[] = unserialize($_POST['formTables'][$i]); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
$linkCount = $tblCount; |
|
|
|
|
540
|
|
|
|
541
|
|
|
//get linking keys |
542
|
|
|
$rsLinkKeys = $data->getLinkingKeys($arrSelTables); |
|
|
|
|
543
|
|
|
$linkCount = $rsLinkKeys->recordCount() > $tblCount ? $rsLinkKeys->recordCount() : $tblCount; |
544
|
|
|
|
545
|
|
|
$arrFields = []; //array that will hold all our table/field names |
546
|
|
|
|
547
|
|
|
//if we have schemas we need to specify the correct schema for each table we're retrieiving |
548
|
|
|
//with getTableAttributes |
549
|
|
|
$curSchema = $data->_schema; |
550
|
|
|
for ($i = 0; $i < $tblCount; ++$i) { |
551
|
|
|
if ($arrSelTables[$i]['schemaname'] != $data->_schema) { |
552
|
|
|
$data->setSchema($arrSelTables[$i]['schemaname']); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
$attrs = $data->getTableAttributes($arrSelTables[$i]['tablename']); |
556
|
|
|
while (!$attrs->EOF) { |
557
|
|
|
$arrFields["{$arrSelTables[$i]['schemaname']}.{$arrSelTables[$i]['tablename']}.{$attrs->fields['attname']}"] = serialize( |
558
|
|
|
[ |
559
|
|
|
'schemaname' => $arrSelTables[$i]['schemaname'], |
560
|
|
|
'tablename' => $arrSelTables[$i]['tablename'], |
561
|
|
|
'fieldname' => $attrs->fields['attname']] |
562
|
|
|
); |
563
|
|
|
$attrs->moveNext(); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
$data->setSchema($curSchema); |
567
|
|
|
} |
568
|
|
|
asort($arrFields); |
569
|
|
|
|
570
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
571
|
|
|
echo "<table>\n"; |
572
|
|
|
echo "<tr><th class=\"data\">{$lang['strviewname']}</th></tr>"; |
573
|
|
|
echo "<tr>\n<td class=\"data1\">\n"; |
574
|
|
|
// View name |
575
|
|
|
echo '<input name="formView" value="', htmlspecialchars($_REQUEST['formView']), "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
576
|
|
|
echo "</td>\n</tr>\n"; |
577
|
|
|
echo "<tr><th class=\"data\">{$lang['strcomment']}</th></tr>"; |
578
|
|
|
echo "<tr>\n<td class=\"data1\">\n"; |
579
|
|
|
// View comments |
580
|
|
|
echo '<textarea name="formComment" rows="3" cols="32">', |
581
|
|
|
htmlspecialchars($_REQUEST['formComment']), "</textarea>\n"; |
582
|
|
|
echo "</td>\n</tr>\n"; |
583
|
|
|
echo "</table>\n"; |
584
|
|
|
|
585
|
|
|
// Output selector for fields to be retrieved from view |
586
|
|
|
echo "<table>\n"; |
587
|
|
|
echo "<tr><th class=\"data\">{$lang['strcolumns']}</th></tr>"; |
588
|
|
|
echo "<tr>\n<td class=\"data1\">\n"; |
589
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, 'formFields[]', false, '', true); |
590
|
|
|
echo "</td>\n</tr>"; |
591
|
|
|
echo "<tr><td><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth1\" value=\"rename\" /><label for=\"dblFldMeth1\">{$lang['strrenamedupfields']}</label>"; |
592
|
|
|
echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth2\" value=\"drop\" /><label for=\"dblFldMeth2\">{$lang['strdropdupfields']}</label>"; |
593
|
|
|
echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth3\" value=\"\" checked=\"checked\" /><label for=\"dblFldMeth3\">{$lang['strerrordupfields']}</label></td></tr></table><br />"; |
594
|
|
|
|
595
|
|
|
// Output the Linking keys combo boxes |
596
|
|
|
echo "<table>\n"; |
597
|
|
|
echo "<tr><th class=\"data\">{$lang['strviewlink']}</th></tr>"; |
598
|
|
|
$rowClass = 'data1'; |
599
|
|
|
for ($i = 0; $i < $linkCount; ++$i) { |
600
|
|
|
// Initialise variables |
601
|
|
|
if (!isset($formLink[$i]['operator'])) { |
602
|
|
|
$formLink[$i]['operator'] = 'INNER JOIN'; |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
echo "<tr>\n<td class=\"${rowClass}\">\n"; |
606
|
|
|
|
607
|
|
|
if (!$rsLinkKeys->EOF) { |
608
|
|
|
$curLeftLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['p_schema'], 'tablename' => $rsLinkKeys->fields['p_table'], 'fieldname' => $rsLinkKeys->fields['p_field']])); |
609
|
|
|
$curRightLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['f_schema'], 'tablename' => $rsLinkKeys->fields['f_table'], 'fieldname' => $rsLinkKeys->fields['f_field']])); |
610
|
|
|
$rsLinkKeys->moveNext(); |
611
|
|
|
} else { |
612
|
|
|
$curLeftLink = ''; |
613
|
|
|
$curRightLink = ''; |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][leftlink]", true, $curLeftLink, false); |
617
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($data->joinOps, "formLink[${i}][operator]", true, $formLink[$i]['operator']); |
|
|
|
|
618
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][rightlink]", true, $curRightLink, false); |
619
|
|
|
echo "</td>\n</tr>\n"; |
620
|
|
|
$rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
621
|
|
|
} |
622
|
|
|
echo "</table>\n<br />\n"; |
623
|
|
|
|
624
|
|
|
// Build list of available operators (infix only) |
625
|
|
|
$arrOperators = []; |
626
|
|
|
foreach ($data->selectOps as $k => $v) { |
627
|
|
|
if ('i' == $v) { |
628
|
|
|
$arrOperators[$k] = $k; |
629
|
|
|
} |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
// Output additional conditions, note that this portion of the wizard treats the right hand side as literal values |
633
|
|
|
//(not as database objects) so field names will be treated as strings, use the above linking keys section to perform joins |
634
|
|
|
echo "<table>\n"; |
635
|
|
|
echo "<tr><th class=\"data\">{$lang['strviewconditions']}</th></tr>"; |
636
|
|
|
$rowClass = 'data1'; |
637
|
|
|
for ($i = 0; $i < $linkCount; ++$i) { |
638
|
|
|
echo "<tr>\n<td class=\"${rowClass}\">\n"; |
639
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formCondition[${i}][field]"); |
640
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrOperators, "formCondition[${i}][operator]", false, false); |
|
|
|
|
641
|
|
|
echo "<input type=\"text\" name=\"formCondition[${i}][txt]\" />\n"; |
642
|
|
|
echo "</td>\n</tr>\n"; |
643
|
|
|
$rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
644
|
|
|
} |
645
|
|
|
echo "</table>\n"; |
646
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_wiz\" />\n"; |
647
|
|
|
|
648
|
|
|
foreach ($arrSelTables as $curTable) { |
649
|
|
|
echo '<input type="hidden" name="formTables[]" value="' . htmlspecialchars(serialize($curTable)) . "\" />\n"; |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
echo $this->misc->form; |
653
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
654
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
655
|
|
|
echo "</form>\n"; |
656
|
|
|
} |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
660
|
|
|
* Display a wizard where they can enter a new view. |
661
|
|
|
* |
662
|
|
|
* @param mixed $msg |
|
|
|
|
663
|
|
|
*/ |
664
|
|
|
public function doWizardCreate($msg = '') |
665
|
|
|
{ |
666
|
|
|
$lang = $this->lang; |
667
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
668
|
|
|
|
669
|
|
|
$tables = $data->getTables(true); |
670
|
|
|
|
671
|
|
|
$this->printTrail('schema'); |
672
|
|
|
$this->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); |
673
|
|
|
$this->printMsg($msg); |
674
|
|
|
|
675
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
676
|
|
|
echo "<table>\n"; |
677
|
|
|
echo "<tr><th class=\"data\">{$lang['strtables']}</th></tr>"; |
678
|
|
|
echo "<tr>\n<td class=\"data1\">\n"; |
679
|
|
|
|
680
|
|
|
$arrTables = []; |
681
|
|
|
while (!$tables->EOF) { |
682
|
|
|
$arrTmp = []; |
683
|
|
|
$arrTmp['schemaname'] = $tables->fields['nspname']; |
684
|
|
|
$arrTmp['tablename'] = $tables->fields['relname']; |
685
|
|
|
$arrTables[$tables->fields['nspname'] . '.' . $tables->fields['relname']] = serialize($arrTmp); |
686
|
|
|
$tables->moveNext(); |
687
|
|
|
} |
688
|
|
|
echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrTables, 'formTables[]', false, '', true); |
689
|
|
|
|
690
|
|
|
echo "</td>\n</tr>\n"; |
691
|
|
|
echo "</table>\n"; |
692
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"set_params_create\" />\n"; |
693
|
|
|
echo $this->misc->form; |
694
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n"; |
695
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
696
|
|
|
echo "</form>\n"; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
/** |
700
|
|
|
* Displays a screen where they can enter a new view. |
701
|
|
|
* |
702
|
|
|
* @param mixed $msg |
|
|
|
|
703
|
|
|
*/ |
704
|
|
|
public function doCreate($msg = '') |
705
|
|
|
{ |
706
|
|
|
$lang = $this->lang; |
707
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
708
|
|
|
|
709
|
|
|
if (!isset($_REQUEST['formView'])) { |
710
|
|
|
$_REQUEST['formView'] = ''; |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
if (!isset($_REQUEST['formDefinition'])) { |
714
|
|
|
if (isset($_SESSION['sqlquery'])) { |
715
|
|
|
$_REQUEST['formDefinition'] = $_SESSION['sqlquery']; |
716
|
|
|
} else { |
717
|
|
|
$_REQUEST['formDefinition'] = 'SELECT '; |
718
|
|
|
} |
719
|
|
|
} |
720
|
|
|
if (!isset($_REQUEST['formComment'])) { |
721
|
|
|
$_REQUEST['formComment'] = ''; |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
$this->printTrail('schema'); |
725
|
|
|
$this->printTitle($lang['strcreateview'], 'pg.view.create'); |
726
|
|
|
$this->printMsg($msg); |
727
|
|
|
|
728
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
729
|
|
|
echo "<table style=\"width: 100%\">\n"; |
730
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
731
|
|
|
echo "\t<td class=\"data1\"><input name=\"formView\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
732
|
|
|
htmlspecialchars($_REQUEST['formView']), "\" /></td>\n\t</tr>\n"; |
733
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n"; |
734
|
|
|
echo "\t<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"10\" cols=\"50\" name=\"formDefinition\">", |
735
|
|
|
htmlspecialchars($_REQUEST['formDefinition']), "</textarea></td>\n\t</tr>\n"; |
736
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
737
|
|
|
echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
738
|
|
|
htmlspecialchars($_REQUEST['formComment']), "</textarea></td>\n\t</tr>\n"; |
739
|
|
|
echo "</table>\n"; |
740
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
741
|
|
|
echo $this->misc->form; |
742
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
743
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
744
|
|
|
echo "</form>\n"; |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
/** |
748
|
|
|
* Actually creates the new view in the database. |
749
|
|
|
*/ |
750
|
|
|
public function doSaveCreate() |
751
|
|
|
{ |
752
|
|
|
$lang = $this->lang; |
753
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
754
|
|
|
|
755
|
|
|
// Check that they've given a name and a definition |
756
|
|
|
if ('' == $_POST['formView']) { |
757
|
|
|
$this->doCreate($lang['strviewneedsname']); |
758
|
|
|
} elseif ('' == $_POST['formDefinition']) { |
759
|
|
|
$this->doCreate($lang['strviewneedsdef']); |
760
|
|
|
} else { |
761
|
|
|
$status = $data->createView($_POST['formView'], $_POST['formDefinition'], false, $_POST['formComment']); |
762
|
|
|
if (0 == $status) { |
763
|
|
|
$this->misc->setReloadBrowser(true); |
764
|
|
|
$this->doDefault($lang['strviewcreated']); |
765
|
|
|
} else { |
766
|
|
|
$this->doCreate($lang['strviewcreatedbad']); |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* Actually creates the new wizard view in the database. |
773
|
|
|
*/ |
774
|
|
|
public function doSaveCreateWiz() |
775
|
|
|
{ |
776
|
|
|
$lang = $this->lang; |
777
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
778
|
|
|
|
779
|
|
|
// Check that they've given a name and fields they want to select |
780
|
|
|
|
781
|
|
|
if (!strlen($_POST['formView'])) { |
782
|
|
|
$this->doSetParamsCreate($lang['strviewneedsname']); |
783
|
|
|
} elseif (!isset($_POST['formFields']) || !count($_POST['formFields'])) { |
784
|
|
|
$this->doSetParamsCreate($lang['strviewneedsfields']); |
785
|
|
|
} else { |
786
|
|
|
$selFields = ''; |
787
|
|
|
|
788
|
|
|
if (!empty($_POST['dblFldMeth'])) { |
789
|
|
|
$tmpHsh = []; |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
foreach ($_POST['formFields'] as $curField) { |
793
|
|
|
$arrTmp = unserialize($curField); |
794
|
|
|
$data->fieldArrayClean($arrTmp); |
795
|
|
|
if (!empty($_POST['dblFldMeth'])) { |
796
|
|
|
// doublon control |
797
|
|
|
if (empty($tmpHsh[$arrTmp['fieldname']])) { |
798
|
|
|
// field does not exist |
799
|
|
|
$selFields .= "\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\", "; |
800
|
|
|
$tmpHsh[$arrTmp['fieldname']] = 1; |
801
|
|
|
} elseif ('rename' == $_POST['dblFldMeth']) { |
802
|
|
|
// field exist and must be renamed |
803
|
|
|
++$tmpHsh[$arrTmp['fieldname']]; |
804
|
|
|
$selFields .= "\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" AS \"{$arrTmp['schemaname']}_{$arrTmp['tablename']}_{$arrTmp['fieldname']}{$tmpHsh[$arrTmp['fieldname']]}\", "; |
805
|
|
|
} |
806
|
|
|
// field already exist, just ignore this one |
807
|
|
|
} else { |
808
|
|
|
// no doublon control |
809
|
|
|
$selFields .= "\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\", "; |
810
|
|
|
} |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
$selFields = substr($selFields, 0, -2); |
814
|
|
|
unset($arrTmp, $tmpHsh); |
815
|
|
|
$linkFields = ''; |
816
|
|
|
|
817
|
|
|
// If we have links, out put the JOIN ... ON statements |
818
|
|
|
if (is_array($_POST['formLink'])) { |
819
|
|
|
// Filter out invalid/blank entries for our links |
820
|
|
|
$arrLinks = []; |
821
|
|
|
foreach ($_POST['formLink'] as $curLink) { |
822
|
|
|
if (strlen($curLink['leftlink']) && strlen($curLink['rightlink']) && strlen($curLink['operator'])) { |
823
|
|
|
$arrLinks[] = $curLink; |
824
|
|
|
} |
825
|
|
|
} |
826
|
|
|
// We must perform some magic to make sure that we have a valid join order |
827
|
|
|
$count = sizeof($arrLinks); |
828
|
|
|
$arrJoined = []; |
829
|
|
|
$arrUsedTbls = []; |
830
|
|
|
|
831
|
|
|
// If we have at least one join condition, output it |
832
|
|
|
if ($count > 0) { |
833
|
|
|
$j = 0; |
834
|
|
|
while ($j < $count) { |
835
|
|
|
foreach ($arrLinks as $curLink) { |
836
|
|
|
$arrLeftLink = unserialize($curLink['leftlink']); |
837
|
|
|
$arrRightLink = unserialize($curLink['rightlink']); |
838
|
|
|
$data->fieldArrayClean($arrLeftLink); |
839
|
|
|
$data->fieldArrayClean($arrRightLink); |
840
|
|
|
|
841
|
|
|
$tbl1 = "\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\""; |
842
|
|
|
$tbl2 = "\"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\""; |
843
|
|
|
|
844
|
|
|
if ((!in_array($curLink, $arrJoined, true) && in_array($tbl1, $arrUsedTbls, true)) || !count($arrJoined)) { |
845
|
|
|
// Make sure for multi-column foreign keys that we use a table alias tables joined to more than once |
846
|
|
|
// This can (and should be) more optimized for multi-column foreign keys |
847
|
|
|
$adj_tbl2 = in_array($tbl2, $arrUsedTbls, true) ? "${tbl2} AS alias_ppa_" . mktime() : $tbl2; |
848
|
|
|
|
849
|
|
|
$linkFields .= strlen($linkFields) ? "{$curLink['operator']} ${adj_tbl2} ON (\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\".\"{$arrLeftLink['fieldname']}\" = \"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\".\"{$arrRightLink['fieldname']}\") " |
850
|
|
|
: "${tbl1} {$curLink['operator']} ${adj_tbl2} ON (\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\".\"{$arrLeftLink['fieldname']}\" = \"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\".\"{$arrRightLink['fieldname']}\") "; |
851
|
|
|
|
852
|
|
|
$arrJoined[] = $curLink; |
853
|
|
|
if (!in_array($tbl1, $arrUsedTbls, true)) { |
854
|
|
|
$arrUsedTbls[] = $tbl1; |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
if (!in_array($tbl2, $arrUsedTbls, true)) { |
858
|
|
|
$arrUsedTbls[] = $tbl2; |
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
} |
862
|
|
|
++$j; |
863
|
|
|
} |
864
|
|
|
} |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
//if linkfields has no length then either _POST['formLink'] was not set, or there were no join conditions |
868
|
|
|
//just select from all seleted tables - a cartesian join do a |
869
|
|
|
if (!strlen($linkFields)) { |
870
|
|
|
foreach ($_POST['formTables'] as $curTable) { |
871
|
|
|
$arrTmp = unserialize($curTable); |
872
|
|
|
$data->fieldArrayClean($arrTmp); |
873
|
|
|
$linkFields .= strlen($linkFields) ? ", \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\"" : "\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\""; |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
$addConditions = ''; |
878
|
|
|
if (is_array($_POST['formCondition'])) { |
879
|
|
|
foreach ($_POST['formCondition'] as $curCondition) { |
880
|
|
|
if (strlen($curCondition['field']) && strlen($curCondition['txt'])) { |
881
|
|
|
$arrTmp = unserialize($curCondition['field']); |
882
|
|
|
$data->fieldArrayClean($arrTmp); |
883
|
|
|
$addConditions .= strlen($addConditions) ? " AND \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' " |
884
|
|
|
: " \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' "; |
885
|
|
|
} |
886
|
|
|
} |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
$viewQuery = "SELECT ${selFields} FROM ${linkFields} "; |
890
|
|
|
|
891
|
|
|
//add where from additional conditions |
892
|
|
|
if (strlen($addConditions)) { |
893
|
|
|
$viewQuery .= ' WHERE ' . $addConditions; |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
$status = $data->createView($_POST['formView'], $viewQuery, false, $_POST['formComment']); |
897
|
|
|
if (0 == $status) { |
898
|
|
|
$this->misc->setReloadBrowser(true); |
899
|
|
|
$this->doDefault($lang['strviewcreated']); |
900
|
|
|
} else { |
901
|
|
|
$this->doSetParamsCreate($lang['strviewcreatedbad']); |
902
|
|
|
} |
903
|
|
|
} |
904
|
|
|
} |
905
|
|
|
} |
906
|
|
|
|