|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin 6.1.3 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
|
10
|
|
|
use PHPPgAdmin\XHtml\XHtmlOption; |
|
11
|
|
|
use PHPPgAdmin\XHtml\XHtmlSelect; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Base controller class. |
|
15
|
|
|
*/ |
|
16
|
|
|
class TriggersController extends BaseController |
|
17
|
|
|
{ |
|
18
|
|
|
public $controller_title = 'strtables'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Default method to render the controller according to the action parameter. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function render() |
|
24
|
|
|
{ |
|
25
|
|
|
if ('tree' === $this->action) { |
|
26
|
|
|
return $this->doTree(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$this->printHeader($this->headerTitle('', '', $_REQUEST['table'] . ' - ' . $this->lang['strtriggers'])); |
|
30
|
|
|
$this->printBody(); |
|
31
|
|
|
|
|
32
|
|
|
switch ($this->action) { |
|
33
|
|
|
case 'alter': |
|
34
|
|
|
if (null !== $this->getPostParam('alter')) { |
|
35
|
|
|
$this->doSaveAlter(); |
|
36
|
|
|
} else { |
|
37
|
|
|
$this->doDefault(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
break; |
|
41
|
|
|
case 'confirm_alter': |
|
42
|
|
|
$this->doAlter(); |
|
43
|
|
|
|
|
44
|
|
|
break; |
|
45
|
|
|
case 'confirm_enable': |
|
46
|
|
|
$this->doEnable(true); |
|
47
|
|
|
|
|
48
|
|
|
break; |
|
49
|
|
|
case 'confirm_disable': |
|
50
|
|
|
$this->doDisable(true); |
|
51
|
|
|
|
|
52
|
|
|
break; |
|
53
|
|
|
case 'save_create': |
|
54
|
|
|
if (null !== $this->getPostParam('cancel')) { |
|
55
|
|
|
$this->doDefault(); |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->doSaveCreate(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
break; |
|
61
|
|
|
case 'create': |
|
62
|
|
|
$this->doCreate(); |
|
63
|
|
|
|
|
64
|
|
|
break; |
|
65
|
|
|
case 'drop': |
|
66
|
|
|
if (isset($_POST['yes'])) { |
|
67
|
|
|
$this->doDrop(false); |
|
68
|
|
|
} else { |
|
69
|
|
|
$this->doDefault(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
break; |
|
73
|
|
|
case 'confirm_drop': |
|
74
|
|
|
$this->doDrop(true); |
|
75
|
|
|
|
|
76
|
|
|
break; |
|
77
|
|
|
case 'enable': |
|
78
|
|
|
if (isset($_POST['yes'])) { |
|
79
|
|
|
$this->doEnable(false); |
|
80
|
|
|
} else { |
|
81
|
|
|
$this->doDefault(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
break; |
|
85
|
|
|
case 'disable': |
|
86
|
|
|
if (isset($_POST['yes'])) { |
|
87
|
|
|
$this->doDisable(false); |
|
88
|
|
|
} else { |
|
89
|
|
|
$this->doDefault(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
break; |
|
93
|
|
|
|
|
94
|
|
|
default: |
|
95
|
|
|
$this->doDefault(); |
|
96
|
|
|
|
|
97
|
|
|
break; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $this->printFooter(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* List all the triggers on the table. |
|
105
|
|
|
* |
|
106
|
|
|
* @param mixed $msg |
|
107
|
|
|
*/ |
|
108
|
|
|
public function doDefault($msg = ''): void |
|
109
|
|
|
{ |
|
110
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
111
|
|
|
|
|
112
|
|
|
$tgPre = static function (&$rowdata, $actions) use ($data) { |
|
113
|
|
|
// toggle enable/disable trigger per trigger |
|
114
|
|
|
if (!$data->phpBool($rowdata->fields['tgenabled'])) { |
|
115
|
|
|
unset($actions['disable']); |
|
116
|
|
|
} else { |
|
117
|
|
|
unset($actions['enable']); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $actions; |
|
121
|
|
|
}; |
|
122
|
|
|
|
|
123
|
|
|
$this->printTrail('table'); |
|
124
|
|
|
$this->printTabs('table', 'triggers'); |
|
125
|
|
|
$this->printMsg($msg); |
|
126
|
|
|
|
|
127
|
|
|
$triggers = $data->getTriggers($_REQUEST['table']); |
|
128
|
|
|
|
|
129
|
|
|
$columns = [ |
|
130
|
|
|
'trigger' => [ |
|
131
|
|
|
'title' => $this->lang['strname'], |
|
132
|
|
|
'field' => Decorator::field('tgname'), |
|
133
|
|
|
], |
|
134
|
|
|
'definition' => [ |
|
135
|
|
|
'title' => $this->lang['strdefinition'], |
|
136
|
|
|
'field' => Decorator::field('tgdef'), |
|
137
|
|
|
], |
|
138
|
|
|
'function' => [ |
|
139
|
|
|
'title' => $this->lang['strfunction'], |
|
140
|
|
|
'field' => Decorator::field('proproto'), |
|
141
|
|
|
'url' => \sprintf( |
|
142
|
|
|
'functions?action=properties&server=%s&database=%s&', |
|
143
|
|
|
$_REQUEST['server'], |
|
144
|
|
|
$_REQUEST['database'] |
|
145
|
|
|
), |
|
146
|
|
|
'vars' => [ |
|
147
|
|
|
'schema' => 'pronamespace', |
|
148
|
|
|
'function' => 'proproto', |
|
149
|
|
|
'function_oid' => 'prooid', |
|
150
|
|
|
], |
|
151
|
|
|
], |
|
152
|
|
|
'actions' => [ |
|
153
|
|
|
'title' => $this->lang['stractions'], |
|
154
|
|
|
], |
|
155
|
|
|
]; |
|
156
|
|
|
|
|
157
|
|
|
$actions = [ |
|
158
|
|
|
'alter' => [ |
|
159
|
|
|
'content' => $this->lang['stralter'], |
|
160
|
|
|
'attr' => [ |
|
161
|
|
|
'href' => [ |
|
162
|
|
|
'url' => 'triggers', |
|
163
|
|
|
'urlvars' => [ |
|
164
|
|
|
'action' => 'confirm_alter', |
|
165
|
|
|
'table' => $_REQUEST['table'], |
|
166
|
|
|
'trigger' => Decorator::field('tgname'), |
|
167
|
|
|
], |
|
168
|
|
|
], |
|
169
|
|
|
], |
|
170
|
|
|
], |
|
171
|
|
|
'drop' => [ |
|
172
|
|
|
'content' => $this->lang['strdrop'], |
|
173
|
|
|
'attr' => [ |
|
174
|
|
|
'href' => [ |
|
175
|
|
|
'url' => 'triggers', |
|
176
|
|
|
'urlvars' => [ |
|
177
|
|
|
'action' => 'confirm_drop', |
|
178
|
|
|
'table' => $_REQUEST['table'], |
|
179
|
|
|
'trigger' => Decorator::field('tgname'), |
|
180
|
|
|
], |
|
181
|
|
|
], |
|
182
|
|
|
], |
|
183
|
|
|
], |
|
184
|
|
|
]; |
|
185
|
|
|
|
|
186
|
|
|
if ($data->hasDisableTriggers()) { |
|
187
|
|
|
$actions['enable'] = [ |
|
188
|
|
|
'content' => $this->lang['strenable'], |
|
189
|
|
|
'attr' => [ |
|
190
|
|
|
'href' => [ |
|
191
|
|
|
'url' => 'triggers', |
|
192
|
|
|
'urlvars' => [ |
|
193
|
|
|
'action' => 'confirm_enable', |
|
194
|
|
|
'table' => $_REQUEST['table'], |
|
195
|
|
|
'trigger' => Decorator::field('tgname'), |
|
196
|
|
|
], |
|
197
|
|
|
], |
|
198
|
|
|
], |
|
199
|
|
|
]; |
|
200
|
|
|
$actions['disable'] = [ |
|
201
|
|
|
'content' => $this->lang['strdisable'], |
|
202
|
|
|
'attr' => [ |
|
203
|
|
|
'href' => [ |
|
204
|
|
|
'url' => 'triggers', |
|
205
|
|
|
'urlvars' => [ |
|
206
|
|
|
'action' => 'confirm_disable', |
|
207
|
|
|
'table' => $_REQUEST['table'], |
|
208
|
|
|
'trigger' => Decorator::field('tgname'), |
|
209
|
|
|
], |
|
210
|
|
|
], |
|
211
|
|
|
], |
|
212
|
|
|
]; |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
echo $this->printTable($triggers, $columns, $actions, 'triggers-triggers', $this->lang['strnotriggers'], $tgPre); |
|
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
$this->printNavLinks(['create' => [ |
|
218
|
|
|
'attr' => [ |
|
219
|
|
|
'href' => [ |
|
220
|
|
|
'url' => 'triggers', |
|
221
|
|
|
'urlvars' => [ |
|
222
|
|
|
'action' => 'create', |
|
223
|
|
|
'server' => $_REQUEST['server'], |
|
224
|
|
|
'database' => $_REQUEST['database'], |
|
225
|
|
|
'schema' => $_REQUEST['schema'], |
|
226
|
|
|
'table' => $_REQUEST['table'], |
|
227
|
|
|
], |
|
228
|
|
|
], |
|
229
|
|
|
], |
|
230
|
|
|
'content' => $this->lang['strcreatetrigger'], |
|
231
|
|
|
]], 'triggers-triggers', \get_defined_vars()); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function doTree() |
|
235
|
|
|
{ |
|
236
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
237
|
|
|
|
|
238
|
|
|
$triggers = $data->getTriggers($_REQUEST['table']); |
|
239
|
|
|
|
|
240
|
|
|
$attrs = [ |
|
241
|
|
|
'text' => Decorator::field('tgname'), |
|
242
|
|
|
'icon' => 'Trigger', |
|
243
|
|
|
]; |
|
244
|
|
|
|
|
245
|
|
|
return $this->printTree($triggers, $attrs, 'triggers'); |
|
|
|
|
|
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Function to save after altering a trigger. |
|
250
|
|
|
*/ |
|
251
|
|
|
public function doSaveAlter(): void |
|
252
|
|
|
{ |
|
253
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
254
|
|
|
|
|
255
|
|
|
$status = $data->alterTrigger($_POST['table'], $_POST['trigger'], $_POST['name']); |
|
256
|
|
|
|
|
257
|
|
|
if (0 === $status) { |
|
258
|
|
|
$this->doDefault($this->lang['strtriggeraltered']); |
|
259
|
|
|
} else { |
|
260
|
|
|
$this->doAlter($this->lang['strtriggeralteredbad']); |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* Function to allow altering of a trigger. |
|
266
|
|
|
* |
|
267
|
|
|
* @param mixed $msg |
|
268
|
|
|
*/ |
|
269
|
|
|
public function doAlter($msg = ''): void |
|
270
|
|
|
{ |
|
271
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
272
|
|
|
|
|
273
|
|
|
$this->printTrail('trigger'); |
|
274
|
|
|
$this->printTitle($this->lang['stralter'], 'pg.trigger.alter'); |
|
275
|
|
|
$this->printMsg($msg); |
|
276
|
|
|
|
|
277
|
|
|
$triggerdata = $data->getTrigger($_REQUEST['table'], $_REQUEST['trigger']); |
|
278
|
|
|
|
|
279
|
|
|
if (0 < $triggerdata->recordCount()) { |
|
280
|
|
|
$this->coalesceArr($_POST, 'name', $triggerdata->fields['tgname']); |
|
281
|
|
|
|
|
282
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/triggers" method="post">' . \PHP_EOL; |
|
283
|
|
|
echo '<table>' . \PHP_EOL; |
|
284
|
|
|
echo \sprintf( |
|
285
|
|
|
'<tr><th class="data">%s</th>', |
|
286
|
|
|
$this->lang['strname'] |
|
287
|
|
|
) . \PHP_EOL; |
|
288
|
|
|
echo '<td class="data1">'; |
|
289
|
|
|
echo \sprintf( |
|
290
|
|
|
'<input name="name" size="32" maxlength="%s" value="', |
|
291
|
|
|
$data->_maxNameLen |
|
292
|
|
|
), |
|
293
|
|
|
\htmlspecialchars($_POST['name']), '" />' . \PHP_EOL; |
|
294
|
|
|
echo '</table>' . \PHP_EOL; |
|
295
|
|
|
echo '<p><input type="hidden" name="action" value="alter" />' . \PHP_EOL; |
|
296
|
|
|
echo \sprintf( |
|
297
|
|
|
'<input type="hidden" name="table" value="%s" />%s', |
|
298
|
|
|
\htmlspecialchars($_REQUEST['table']), |
|
299
|
|
|
\PHP_EOL |
|
300
|
|
|
); |
|
301
|
|
|
echo '<input type="hidden" name="trigger" value="', \htmlspecialchars($_REQUEST['trigger']), '" />' . \PHP_EOL; |
|
302
|
|
|
echo $this->view->form; |
|
303
|
|
|
echo \sprintf( |
|
304
|
|
|
'<input type="submit" name="alter" value="%s" />', |
|
305
|
|
|
$this->lang['strok'] |
|
306
|
|
|
) . \PHP_EOL; |
|
307
|
|
|
echo \sprintf( |
|
308
|
|
|
'<input type="submit" name="cancel" value="%s" /></p>%s', |
|
309
|
|
|
$this->lang['strcancel'], |
|
310
|
|
|
\PHP_EOL |
|
311
|
|
|
); |
|
312
|
|
|
echo '</form>' . \PHP_EOL; |
|
313
|
|
|
} else { |
|
314
|
|
|
echo \sprintf( |
|
315
|
|
|
'<p>%s</p>', |
|
316
|
|
|
$this->lang['strnodata'] |
|
317
|
|
|
) . \PHP_EOL; |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* Show confirmation of drop and perform actual drop. |
|
323
|
|
|
* |
|
324
|
|
|
* @param mixed $confirm |
|
325
|
|
|
*/ |
|
326
|
|
|
public function doDrop($confirm): void |
|
327
|
|
|
{ |
|
328
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
329
|
|
|
|
|
330
|
|
|
if ($confirm) { |
|
331
|
|
|
$this->printTrail('trigger'); |
|
332
|
|
|
$this->printTitle($this->lang['strdrop'], 'pg.trigger.drop'); |
|
333
|
|
|
|
|
334
|
|
|
echo '<p>', \sprintf( |
|
335
|
|
|
$this->lang['strconfdroptrigger'], |
|
336
|
|
|
$this->misc->printVal($_REQUEST['trigger']), |
|
337
|
|
|
$this->misc->printVal($_REQUEST['table']) |
|
338
|
|
|
), '</p>' . \PHP_EOL; |
|
339
|
|
|
|
|
340
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/triggers" method="post">' . \PHP_EOL; |
|
341
|
|
|
echo '<input type="hidden" name="action" value="drop" />' . \PHP_EOL; |
|
342
|
|
|
echo \sprintf( |
|
343
|
|
|
'<input type="hidden" name="table" value="%s" />%s', |
|
344
|
|
|
\htmlspecialchars($_REQUEST['table']), |
|
345
|
|
|
\PHP_EOL |
|
346
|
|
|
); |
|
347
|
|
|
echo '<input type="hidden" name="trigger" value="', \htmlspecialchars($_REQUEST['trigger']), '" />' . \PHP_EOL; |
|
348
|
|
|
echo $this->view->form; |
|
349
|
|
|
echo \sprintf( |
|
350
|
|
|
'<p><input type="checkbox" id="cascade" name="cascade" /> <label for="cascade">%s</label></p>', |
|
351
|
|
|
$this->lang['strcascade'] |
|
352
|
|
|
) . \PHP_EOL; |
|
353
|
|
|
echo \sprintf( |
|
354
|
|
|
'<input type="submit" name="yes" value="%s" />', |
|
355
|
|
|
$this->lang['stryes'] |
|
356
|
|
|
) . \PHP_EOL; |
|
357
|
|
|
echo \sprintf( |
|
358
|
|
|
'<input type="submit" name="no" value="%s" />', |
|
359
|
|
|
$this->lang['strno'] |
|
360
|
|
|
) . \PHP_EOL; |
|
361
|
|
|
echo '</form>' . \PHP_EOL; |
|
362
|
|
|
} else { |
|
363
|
|
|
$status = $data->dropTrigger($_POST['trigger'], $_POST['table'], isset($_POST['cascade'])); |
|
364
|
|
|
|
|
365
|
|
|
if (0 === $status) { |
|
366
|
|
|
$this->doDefault($this->lang['strtriggerdropped']); |
|
367
|
|
|
} else { |
|
368
|
|
|
$this->doDefault($this->lang['strtriggerdroppedbad']); |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** |
|
374
|
|
|
* Show confirmation of enable trigger and perform enabling the trigger. |
|
375
|
|
|
* |
|
376
|
|
|
* @param mixed $confirm |
|
377
|
|
|
*/ |
|
378
|
|
|
public function doEnable($confirm): void |
|
379
|
|
|
{ |
|
380
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
381
|
|
|
|
|
382
|
|
|
if ($confirm) { |
|
383
|
|
|
$this->printTrail('trigger'); |
|
384
|
|
|
$this->printTitle($this->lang['strenable'], 'pg.table.alter'); |
|
385
|
|
|
|
|
386
|
|
|
echo '<p>', \sprintf( |
|
387
|
|
|
$this->lang['strconfenabletrigger'], |
|
388
|
|
|
$this->misc->printVal($_REQUEST['trigger']), |
|
389
|
|
|
$this->misc->printVal($_REQUEST['table']) |
|
390
|
|
|
), '</p>' . \PHP_EOL; |
|
391
|
|
|
|
|
392
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/triggers" method="post">' . \PHP_EOL; |
|
393
|
|
|
echo '<input type="hidden" name="action" value="enable" />' . \PHP_EOL; |
|
394
|
|
|
echo \sprintf( |
|
395
|
|
|
'<input type="hidden" name="table" value="%s" />%s', |
|
396
|
|
|
\htmlspecialchars($_REQUEST['table']), |
|
397
|
|
|
\PHP_EOL |
|
398
|
|
|
); |
|
399
|
|
|
echo '<input type="hidden" name="trigger" value="', \htmlspecialchars($_REQUEST['trigger']), '" />' . \PHP_EOL; |
|
400
|
|
|
echo $this->view->form; |
|
401
|
|
|
echo \sprintf( |
|
402
|
|
|
'<input type="submit" name="yes" value="%s" />', |
|
403
|
|
|
$this->lang['stryes'] |
|
404
|
|
|
) . \PHP_EOL; |
|
405
|
|
|
echo \sprintf( |
|
406
|
|
|
'<input type="submit" name="no" value="%s" />', |
|
407
|
|
|
$this->lang['strno'] |
|
408
|
|
|
) . \PHP_EOL; |
|
409
|
|
|
echo '</form>' . \PHP_EOL; |
|
410
|
|
|
} else { |
|
411
|
|
|
$status = $data->enableTrigger($_POST['trigger'], $_POST['table']); |
|
412
|
|
|
|
|
413
|
|
|
if (0 === $status) { |
|
414
|
|
|
$this->doDefault($this->lang['strtriggerenabled']); |
|
415
|
|
|
} else { |
|
416
|
|
|
$this->doDefault($this->lang['strtriggerenabledbad']); |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Show confirmation of disable trigger and perform disabling the trigger. |
|
423
|
|
|
* |
|
424
|
|
|
* @param mixed $confirm |
|
425
|
|
|
*/ |
|
426
|
|
|
public function doDisable($confirm): void |
|
427
|
|
|
{ |
|
428
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
429
|
|
|
|
|
430
|
|
|
if ($confirm) { |
|
431
|
|
|
$this->printTrail('trigger'); |
|
432
|
|
|
$this->printTitle($this->lang['strdisable'], 'pg.table.alter'); |
|
433
|
|
|
|
|
434
|
|
|
echo '<p>', \sprintf( |
|
435
|
|
|
$this->lang['strconfdisabletrigger'], |
|
436
|
|
|
$this->misc->printVal($_REQUEST['trigger']), |
|
437
|
|
|
$this->misc->printVal($_REQUEST['table']) |
|
438
|
|
|
), '</p>' . \PHP_EOL; |
|
439
|
|
|
|
|
440
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/triggers" method="post">' . \PHP_EOL; |
|
441
|
|
|
echo '<input type="hidden" name="action" value="disable" />' . \PHP_EOL; |
|
442
|
|
|
echo \sprintf( |
|
443
|
|
|
'<input type="hidden" name="table" value="%s" />%s', |
|
444
|
|
|
\htmlspecialchars($_REQUEST['table']), |
|
445
|
|
|
\PHP_EOL |
|
446
|
|
|
); |
|
447
|
|
|
echo '<input type="hidden" name="trigger" value="', \htmlspecialchars($_REQUEST['trigger']), '" />' . \PHP_EOL; |
|
448
|
|
|
echo $this->view->form; |
|
449
|
|
|
echo \sprintf( |
|
450
|
|
|
'<input type="submit" name="yes" value="%s" />', |
|
451
|
|
|
$this->lang['stryes'] |
|
452
|
|
|
) . \PHP_EOL; |
|
453
|
|
|
echo \sprintf( |
|
454
|
|
|
'<input type="submit" name="no" value="%s" />', |
|
455
|
|
|
$this->lang['strno'] |
|
456
|
|
|
) . \PHP_EOL; |
|
457
|
|
|
echo '</form>' . \PHP_EOL; |
|
458
|
|
|
} else { |
|
459
|
|
|
$status = $data->disableTrigger($_POST['trigger'], $_POST['table']); |
|
460
|
|
|
|
|
461
|
|
|
if (0 === $status) { |
|
462
|
|
|
$this->doDefault($this->lang['strtriggerdisabled']); |
|
463
|
|
|
} else { |
|
464
|
|
|
$this->doDefault($this->lang['strtriggerdisabledbad']); |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* Let them create s.th. |
|
471
|
|
|
* |
|
472
|
|
|
* @param mixed $msg |
|
473
|
|
|
*/ |
|
474
|
|
|
public function doCreate($msg = ''): void |
|
475
|
|
|
{ |
|
476
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
477
|
|
|
|
|
478
|
|
|
$this->printTrail('table'); |
|
479
|
|
|
$this->printTitle($this->lang['strcreatetrigger'], 'pg.trigger.create'); |
|
480
|
|
|
$this->printMsg($msg); |
|
481
|
|
|
|
|
482
|
|
|
// Get all the functions that can be used in triggers |
|
483
|
|
|
$funcs = $data->getTriggerFunctions(); |
|
484
|
|
|
|
|
485
|
|
|
if (0 === $funcs->recordCount()) { |
|
486
|
|
|
$this->doDefault($this->lang['strnofunctions']); |
|
487
|
|
|
|
|
488
|
|
|
return; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
// Populate functions |
|
492
|
|
|
$sel0 = new XHtmlSelect('formFunction'); |
|
493
|
|
|
|
|
494
|
|
|
while (!$funcs->EOF) { |
|
495
|
|
|
$sel0->add(new XHtmlOption($funcs->fields['proname'])); |
|
496
|
|
|
$funcs->moveNext(); |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
// Populate times |
|
500
|
|
|
$sel1 = new XHtmlSelect('formExecTime'); |
|
501
|
|
|
$sel1->set_data($data->triggerExecTimes); |
|
502
|
|
|
|
|
503
|
|
|
// Populate events |
|
504
|
|
|
$sel2 = new XHtmlSelect('formEvent'); |
|
505
|
|
|
$sel2->set_data($data->triggerEvents); |
|
506
|
|
|
|
|
507
|
|
|
// Populate occurences |
|
508
|
|
|
$sel3 = new XHtmlSelect('formFrequency'); |
|
509
|
|
|
$sel3->set_data($data->triggerFrequency); |
|
510
|
|
|
|
|
511
|
|
|
echo '<form action="' . \containerInstance()->subFolder . '/src/views/triggers" method="post">' . \PHP_EOL; |
|
512
|
|
|
echo '<table>' . \PHP_EOL; |
|
513
|
|
|
echo '<tr>' . \PHP_EOL; |
|
514
|
|
|
echo \sprintf( |
|
515
|
|
|
' <th class="data">%s</th>', |
|
516
|
|
|
$this->lang['strname'] |
|
517
|
|
|
) . \PHP_EOL; |
|
518
|
|
|
echo \sprintf( |
|
519
|
|
|
' <th class="data">%s</th>', |
|
520
|
|
|
$this->lang['strwhen'] |
|
521
|
|
|
) . \PHP_EOL; |
|
522
|
|
|
echo '</tr>' . \PHP_EOL; |
|
523
|
|
|
echo '<tr>' . \PHP_EOL; |
|
524
|
|
|
echo ' <td class="data1"> <input type="text" name="formTriggerName" size="32" /></td>' . \PHP_EOL; |
|
525
|
|
|
echo ' <td class="data1"> ', $sel1->fetch(), '</td>' . \PHP_EOL; |
|
526
|
|
|
echo '</tr>' . \PHP_EOL; |
|
527
|
|
|
echo '<tr>' . \PHP_EOL; |
|
528
|
|
|
echo \sprintf( |
|
529
|
|
|
' <th class="data">%s</th>', |
|
530
|
|
|
$this->lang['strevent'] |
|
531
|
|
|
) . \PHP_EOL; |
|
532
|
|
|
echo \sprintf( |
|
533
|
|
|
' <th class="data">%s</th>', |
|
534
|
|
|
$this->lang['strforeach'] |
|
535
|
|
|
) . \PHP_EOL; |
|
536
|
|
|
echo '</tr>' . \PHP_EOL; |
|
537
|
|
|
echo '<tr>' . \PHP_EOL; |
|
538
|
|
|
echo ' <td class="data1"> ', $sel2->fetch(), '</td>' . \PHP_EOL; |
|
539
|
|
|
echo ' <td class="data1"> ', $sel3->fetch(), '</td>' . \PHP_EOL; |
|
540
|
|
|
echo '</tr>' . \PHP_EOL; |
|
541
|
|
|
echo \sprintf( |
|
542
|
|
|
'<tr><th class="data"> %s</th>', |
|
543
|
|
|
$this->lang['strfunction'] |
|
544
|
|
|
) . \PHP_EOL; |
|
545
|
|
|
echo \sprintf( |
|
546
|
|
|
'<th class="data"> %s</th></tr>', |
|
547
|
|
|
$this->lang['strarguments'] |
|
548
|
|
|
) . \PHP_EOL; |
|
549
|
|
|
echo '<tr><td class="data1">', $sel0->fetch(), '</td>' . \PHP_EOL; |
|
550
|
|
|
echo '<td class="data1">(<input type="text" name="formTriggerArgs" size="32" />)</td>' . \PHP_EOL; |
|
551
|
|
|
echo '</tr></table>' . \PHP_EOL; |
|
552
|
|
|
echo \sprintf( |
|
553
|
|
|
'<p><input type="submit" value="%s" />', |
|
554
|
|
|
$this->lang['strcreate'] |
|
555
|
|
|
) . \PHP_EOL; |
|
556
|
|
|
echo \sprintf( |
|
557
|
|
|
'<input type="submit" name="cancel" value="%s" /></p>%s', |
|
558
|
|
|
$this->lang['strcancel'], |
|
559
|
|
|
\PHP_EOL |
|
560
|
|
|
); |
|
561
|
|
|
echo '<input type="hidden" name="action" value="save_create" />' . \PHP_EOL; |
|
562
|
|
|
echo \sprintf( |
|
563
|
|
|
'<input type="hidden" name="table" value="%s" />%s', |
|
564
|
|
|
\htmlspecialchars($_REQUEST['table']), |
|
565
|
|
|
\PHP_EOL |
|
566
|
|
|
); |
|
567
|
|
|
echo $this->view->form; |
|
568
|
|
|
echo '</form>' . \PHP_EOL; |
|
569
|
|
|
} |
|
570
|
|
|
|
|
571
|
|
|
/** |
|
572
|
|
|
* Actually creates the new trigger in the database. |
|
573
|
|
|
*/ |
|
574
|
|
|
public function doSaveCreate(): void |
|
575
|
|
|
{ |
|
576
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
|
577
|
|
|
|
|
578
|
|
|
// Check that they've given a name and a definition |
|
579
|
|
|
|
|
580
|
|
|
if ('' === $_POST['formFunction']) { |
|
581
|
|
|
$this->doCreate($this->lang['strtriggerneedsfunc']); |
|
582
|
|
|
} elseif ('' === $_POST['formTriggerName']) { |
|
583
|
|
|
$this->doCreate($this->lang['strtriggerneedsname']); |
|
584
|
|
|
} elseif ('' === $_POST['formEvent']) { |
|
585
|
|
|
$this->doCreate(); |
|
586
|
|
|
} else { |
|
587
|
|
|
$status = $data->createTrigger( |
|
588
|
|
|
$_POST['formTriggerName'], |
|
589
|
|
|
$_POST['table'], |
|
590
|
|
|
$_POST['formFunction'], |
|
591
|
|
|
$_POST['formExecTime'], |
|
592
|
|
|
$_POST['formEvent'], |
|
593
|
|
|
$_POST['formFrequency'], |
|
594
|
|
|
$_POST['formTriggerArgs'] |
|
595
|
|
|
); |
|
596
|
|
|
|
|
597
|
|
|
if (0 === $status) { |
|
598
|
|
|
$this->doDefault($this->lang['strtriggercreated']); |
|
599
|
|
|
} else { |
|
600
|
|
|
$this->doCreate($this->lang['strtriggercreatedbad']); |
|
601
|
|
|
} |
|
602
|
|
|
} |
|
603
|
|
|
} |
|
604
|
|
|
} |
|
605
|
|
|
|