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 SequencesController extends BaseController |
15
|
|
|
{ |
16
|
|
|
public $controller_name = 'SequencesController'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Default method to render the controller according to the action parameter. |
20
|
|
|
*/ |
21
|
|
|
public function render() |
22
|
|
|
{ |
23
|
|
|
$lang = $this->lang; |
24
|
|
|
|
25
|
|
|
$action = $this->action; |
26
|
|
|
if ('tree' == $action) { |
27
|
|
|
return $this->doTree(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// Print header |
31
|
|
|
$this->printHeader($lang['strsequences']); |
32
|
|
|
$this->printBody(); |
33
|
|
|
|
34
|
|
|
switch ($action) { |
35
|
|
|
case 'create': |
36
|
|
|
$this->doCreateSequence(); |
37
|
|
|
|
38
|
|
|
break; |
39
|
|
|
case 'save_create_sequence': |
40
|
|
|
if (isset($_POST['create'])) { |
41
|
|
|
$this->doSaveCreateSequence(); |
42
|
|
|
} else { |
43
|
|
|
$this->doDefault(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
break; |
47
|
|
|
case 'properties': |
48
|
|
|
$this->doProperties(); |
49
|
|
|
|
50
|
|
|
break; |
51
|
|
|
case 'drop': |
52
|
|
|
if (isset($_POST['drop'])) { |
53
|
|
|
$this->doDrop(false); |
54
|
|
|
} else { |
55
|
|
|
$this->doDefault(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
break; |
59
|
|
|
case 'confirm_drop': |
60
|
|
|
$this->doDrop(true); |
61
|
|
|
|
62
|
|
|
break; |
63
|
|
|
case 'restart': |
64
|
|
|
$this->doRestart(); |
65
|
|
|
|
66
|
|
|
break; |
67
|
|
|
case 'reset': |
68
|
|
|
$this->doReset(); |
69
|
|
|
|
70
|
|
|
break; |
71
|
|
|
case 'nextval': |
72
|
|
|
$this->doNextval(); |
73
|
|
|
|
74
|
|
|
break; |
75
|
|
|
case 'setval': |
76
|
|
|
if (isset($_POST['setval'])) { |
77
|
|
|
$this->doSaveSetval(); |
78
|
|
|
} else { |
79
|
|
|
$this->doDefault(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
break; |
83
|
|
|
case 'confirm_setval': |
84
|
|
|
$this->doSetval(); |
85
|
|
|
|
86
|
|
|
break; |
87
|
|
|
case 'alter': |
88
|
|
|
if (isset($_POST['alter'])) { |
89
|
|
|
$this->doSaveAlter(); |
90
|
|
|
} else { |
91
|
|
|
$this->doDefault(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
break; |
95
|
|
|
case 'confirm_alter': |
96
|
|
|
$this->doAlter(); |
97
|
|
|
|
98
|
|
|
break; |
99
|
|
|
default: |
100
|
|
|
$this->doDefault(); |
101
|
|
|
|
102
|
|
|
break; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// Print footer |
106
|
|
|
return $this->printFooter(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Display list of all sequences in the database/schema. |
111
|
|
|
* |
112
|
|
|
* @param mixed $msg |
|
|
|
|
113
|
|
|
*/ |
114
|
|
|
public function doDefault($msg = '') |
115
|
|
|
{ |
116
|
|
|
$lang = $this->lang; |
117
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
118
|
|
|
|
119
|
|
|
$this->printTrail('schema'); |
120
|
|
|
$this->printTabs('schema', 'sequences'); |
121
|
|
|
$this->printMsg($msg); |
122
|
|
|
|
123
|
|
|
// Get all sequences |
124
|
|
|
$sequences = $data->getSequences(); |
125
|
|
|
|
126
|
|
|
$columns = [ |
127
|
|
|
'sequence' => [ |
128
|
|
|
'title' => $lang['strsequence'], |
129
|
|
|
'field' => Decorator::field('seqname'), |
130
|
|
|
'url' => "sequences.php?action=properties&{$this->misc->href}&", |
131
|
|
|
'vars' => ['sequence' => 'seqname'], |
132
|
|
|
], |
133
|
|
|
'owner' => [ |
134
|
|
|
'title' => $lang['strowner'], |
135
|
|
|
'field' => Decorator::field('seqowner'), |
136
|
|
|
], |
137
|
|
|
'actions' => [ |
138
|
|
|
'title' => $lang['stractions'], |
139
|
|
|
], |
140
|
|
|
'comment' => [ |
141
|
|
|
'title' => $lang['strcomment'], |
142
|
|
|
'field' => Decorator::field('seqcomment'), |
143
|
|
|
], |
144
|
|
|
]; |
145
|
|
|
|
146
|
|
|
$actions = [ |
147
|
|
|
'multiactions' => [ |
148
|
|
|
'keycols' => ['sequence' => 'seqname'], |
149
|
|
|
'url' => 'sequences.php', |
150
|
|
|
], |
151
|
|
|
'alter' => [ |
152
|
|
|
'content' => $lang['stralter'], |
153
|
|
|
'attr' => [ |
154
|
|
|
'href' => [ |
155
|
|
|
'url' => 'sequences.php', |
156
|
|
|
'urlvars' => [ |
157
|
|
|
'action' => 'confirm_alter', |
158
|
|
|
'subject' => 'sequence', |
159
|
|
|
'sequence' => Decorator::field('seqname'), |
160
|
|
|
], |
161
|
|
|
], |
162
|
|
|
], |
163
|
|
|
], |
164
|
|
|
'drop' => [ |
165
|
|
|
'content' => $lang['strdrop'], |
166
|
|
|
'attr' => [ |
167
|
|
|
'href' => [ |
168
|
|
|
'url' => 'sequences.php', |
169
|
|
|
'urlvars' => [ |
170
|
|
|
'action' => 'confirm_drop', |
171
|
|
|
'sequence' => Decorator::field('seqname'), |
172
|
|
|
], |
173
|
|
|
], |
174
|
|
|
], |
175
|
|
|
'multiaction' => 'confirm_drop', |
176
|
|
|
], |
177
|
|
|
'privileges' => [ |
178
|
|
|
'content' => $lang['strprivileges'], |
179
|
|
|
'attr' => [ |
180
|
|
|
'href' => [ |
181
|
|
|
'url' => 'privileges.php', |
182
|
|
|
'urlvars' => [ |
183
|
|
|
'subject' => 'sequence', |
184
|
|
|
'sequence' => Decorator::field('seqname'), |
185
|
|
|
], |
186
|
|
|
], |
187
|
|
|
], |
188
|
|
|
], |
189
|
|
|
]; |
190
|
|
|
|
191
|
|
|
echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $lang['strnosequences']); |
192
|
|
|
|
193
|
|
|
$this->printNavLinks(['create' => [ |
|
|
|
|
194
|
|
|
'attr' => [ |
195
|
|
|
'href' => [ |
196
|
|
|
'url' => 'sequences.php', |
197
|
|
|
'urlvars' => [ |
198
|
|
|
'action' => 'create', |
199
|
|
|
'server' => $_REQUEST['server'], |
200
|
|
|
'database' => $_REQUEST['database'], |
201
|
|
|
'schema' => $_REQUEST['schema'], |
202
|
|
|
], |
203
|
|
|
], |
204
|
|
|
], |
205
|
|
|
'content' => $lang['strcreatesequence'], |
206
|
|
|
]], 'sequences-sequences', get_defined_vars()); |
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Generate XML for the browser tree. |
211
|
|
|
*/ |
212
|
|
|
public function doTree() |
213
|
|
|
{ |
214
|
|
|
$lang = $this->lang; |
|
|
|
|
215
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
216
|
|
|
|
217
|
|
|
$sequences = $data->getSequences(); |
218
|
|
|
|
219
|
|
|
$reqvars = $this->misc->getRequestVars('sequence'); |
220
|
|
|
|
221
|
|
|
$attrs = [ |
222
|
|
|
'text' => Decorator::field('seqname'), |
223
|
|
|
'icon' => 'Sequence', |
224
|
|
|
'toolTip' => Decorator::field('seqcomment'), |
225
|
|
|
'action' => Decorator::actionurl( |
226
|
|
|
'sequences.php', |
227
|
|
|
$reqvars, |
228
|
|
|
[ |
229
|
|
|
'action' => 'properties', |
230
|
|
|
'sequence' => Decorator::field('seqname'), |
231
|
|
|
] |
232
|
|
|
), |
233
|
|
|
]; |
234
|
|
|
|
235
|
|
|
return $this->printTree($sequences, $attrs, 'sequences'); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Display the properties of a sequence. |
240
|
|
|
* |
241
|
|
|
* @param mixed $msg |
|
|
|
|
242
|
|
|
*/ |
243
|
|
|
public function doProperties($msg = '') |
244
|
|
|
{ |
245
|
|
|
$lang = $this->lang; |
246
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
247
|
|
|
$this->printTrail('sequence'); |
248
|
|
|
$this->printTitle($lang['strproperties'], 'pg.sequence'); |
249
|
|
|
$this->printMsg($msg); |
250
|
|
|
|
251
|
|
|
// Fetch the sequence information |
252
|
|
|
$sequence = $data->getSequence($_REQUEST['sequence']); |
253
|
|
|
|
254
|
|
|
if (is_object($sequence) && $sequence->recordCount() > 0) { |
255
|
|
|
$sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); |
256
|
|
|
$sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']); |
257
|
|
|
|
258
|
|
|
// Show comment if any |
259
|
|
|
if (null !== $sequence->fields['seqcomment']) { |
260
|
|
|
echo '<p class="comment">', $this->misc->printVal($sequence->fields['seqcomment']), "</p>\n"; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
echo '<table border="0">'; |
264
|
|
|
echo "<tr><th class=\"data\">{$lang['strname']}</th>"; |
265
|
|
|
if ($data->hasAlterSequenceStart()) { |
266
|
|
|
echo "<th class=\"data\">{$lang['strstartvalue']}</th>"; |
267
|
|
|
} |
268
|
|
|
echo "<th class=\"data\">{$lang['strlastvalue']}</th>"; |
269
|
|
|
echo "<th class=\"data\">{$lang['strincrementby']}</th>"; |
270
|
|
|
echo "<th class=\"data\">{$lang['strmaxvalue']}</th>"; |
271
|
|
|
echo "<th class=\"data\">{$lang['strminvalue']}</th>"; |
272
|
|
|
echo "<th class=\"data\">{$lang['strcachevalue']}</th>"; |
273
|
|
|
echo "<th class=\"data\">{$lang['strlogcount']}</th>"; |
274
|
|
|
echo "<th class=\"data\">{$lang['strcancycle']}</th>"; |
275
|
|
|
echo "<th class=\"data\">{$lang['striscalled']}</th></tr>"; |
276
|
|
|
echo '<tr>'; |
277
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['seqname']), '</td>'; |
278
|
|
|
if ($data->hasAlterSequenceStart()) { |
279
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['start_value']), '</td>'; |
280
|
|
|
} |
281
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['last_value']), '</td>'; |
282
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['increment_by']), '</td>'; |
283
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['max_value']), '</td>'; |
284
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['min_value']), '</td>'; |
285
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['cache_value']), '</td>'; |
286
|
|
|
echo '<td class="data1">', $this->misc->printVal($sequence->fields['log_cnt']), '</td>'; |
287
|
|
|
echo '<td class="data1">', ($sequence->fields['is_cycled'] ? $lang['stryes'] : $lang['strno']), '</td>'; |
288
|
|
|
echo '<td class="data1">', ($sequence->fields['is_called'] ? $lang['stryes'] : $lang['strno']), '</td>'; |
289
|
|
|
echo '</tr>'; |
290
|
|
|
echo '</table>'; |
291
|
|
|
|
292
|
|
|
$navlinks = [ |
293
|
|
|
'alter' => [ |
294
|
|
|
'attr' => [ |
295
|
|
|
'href' => [ |
296
|
|
|
'url' => 'sequences.php', |
297
|
|
|
'urlvars' => [ |
298
|
|
|
'action' => 'confirm_alter', |
299
|
|
|
'server' => $_REQUEST['server'], |
300
|
|
|
'database' => $_REQUEST['database'], |
301
|
|
|
'schema' => $_REQUEST['schema'], |
302
|
|
|
'sequence' => $sequence->fields['seqname'], |
303
|
|
|
], |
304
|
|
|
], |
305
|
|
|
], |
306
|
|
|
'content' => $lang['stralter'], |
307
|
|
|
], |
308
|
|
|
'setval' => [ |
309
|
|
|
'attr' => [ |
310
|
|
|
'href' => [ |
311
|
|
|
'url' => 'sequences.php', |
312
|
|
|
'urlvars' => [ |
313
|
|
|
'action' => 'confirm_setval', |
314
|
|
|
'server' => $_REQUEST['server'], |
315
|
|
|
'database' => $_REQUEST['database'], |
316
|
|
|
'schema' => $_REQUEST['schema'], |
317
|
|
|
'sequence' => $sequence->fields['seqname'], |
318
|
|
|
], |
319
|
|
|
], |
320
|
|
|
], |
321
|
|
|
'content' => $lang['strsetval'], |
322
|
|
|
], |
323
|
|
|
'nextval' => [ |
324
|
|
|
'attr' => [ |
325
|
|
|
'href' => [ |
326
|
|
|
'url' => 'sequences.php', |
327
|
|
|
'urlvars' => [ |
328
|
|
|
'action' => 'nextval', |
329
|
|
|
'server' => $_REQUEST['server'], |
330
|
|
|
'database' => $_REQUEST['database'], |
331
|
|
|
'schema' => $_REQUEST['schema'], |
332
|
|
|
'sequence' => $sequence->fields['seqname'], |
333
|
|
|
], |
334
|
|
|
], |
335
|
|
|
], |
336
|
|
|
'content' => $lang['strnextval'], |
337
|
|
|
], |
338
|
|
|
'restart' => [ |
339
|
|
|
'attr' => [ |
340
|
|
|
'href' => [ |
341
|
|
|
'url' => 'sequences.php', |
342
|
|
|
'urlvars' => [ |
343
|
|
|
'action' => 'restart', |
344
|
|
|
'server' => $_REQUEST['server'], |
345
|
|
|
'database' => $_REQUEST['database'], |
346
|
|
|
'schema' => $_REQUEST['schema'], |
347
|
|
|
'sequence' => $sequence->fields['seqname'], |
348
|
|
|
], |
349
|
|
|
], |
350
|
|
|
], |
351
|
|
|
'content' => $lang['strrestart'], |
352
|
|
|
], |
353
|
|
|
'reset' => [ |
354
|
|
|
'attr' => [ |
355
|
|
|
'href' => [ |
356
|
|
|
'url' => 'sequences.php', |
357
|
|
|
'urlvars' => [ |
358
|
|
|
'action' => 'reset', |
359
|
|
|
'server' => $_REQUEST['server'], |
360
|
|
|
'database' => $_REQUEST['database'], |
361
|
|
|
'schema' => $_REQUEST['schema'], |
362
|
|
|
'sequence' => $sequence->fields['seqname'], |
363
|
|
|
], |
364
|
|
|
], |
365
|
|
|
], |
366
|
|
|
'content' => $lang['strreset'], |
367
|
|
|
], |
368
|
|
|
'showall' => [ |
369
|
|
|
'attr' => [ |
370
|
|
|
'href' => [ |
371
|
|
|
'url' => 'sequences.php', |
372
|
|
|
'urlvars' => [ |
373
|
|
|
'server' => $_REQUEST['server'], |
374
|
|
|
'database' => $_REQUEST['database'], |
375
|
|
|
'schema' => $_REQUEST['schema'], |
376
|
|
|
], |
377
|
|
|
], |
378
|
|
|
], |
379
|
|
|
'content' => $lang['strshowallsequences'], |
380
|
|
|
], |
381
|
|
|
]; |
382
|
|
|
|
383
|
|
|
if (!$data->hasAlterSequenceStart()) { |
384
|
|
|
unset($navlinks['restart']); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
$this->printNavLinks($navlinks, 'sequences-properties', get_defined_vars()); |
388
|
|
|
} else { |
389
|
|
|
echo "<p>{$lang['strnodata']}</p>\n"; |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Drop a sequence. |
395
|
|
|
* |
396
|
|
|
* @param mixed $confirm |
|
|
|
|
397
|
|
|
* @param mixed $msg |
|
|
|
|
398
|
|
|
*/ |
399
|
|
|
public function doDrop($confirm, $msg = '') |
400
|
|
|
{ |
401
|
|
|
$lang = $this->lang; |
402
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
403
|
|
|
|
404
|
|
|
if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) { |
405
|
|
|
return $this->doDefault($lang['strspecifysequencetodrop']); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
if ($confirm) { |
409
|
|
|
$this->printTrail('sequence'); |
410
|
|
|
$this->printTitle($lang['strdrop'], 'pg.sequence.drop'); |
411
|
|
|
$this->printMsg($msg); |
412
|
|
|
|
413
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
414
|
|
|
|
415
|
|
|
//If multi drop |
416
|
|
|
if (isset($_REQUEST['ma'])) { |
417
|
|
|
foreach ($_REQUEST['ma'] as $v) { |
418
|
|
|
$a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
419
|
|
|
echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($a['sequence'])), "</p>\n"; |
420
|
|
|
printf('<input type="hidden" name="sequence[]" value="%s" />', htmlspecialchars($a['sequence'])); |
421
|
|
|
} |
422
|
|
|
} else { |
423
|
|
|
echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($_REQUEST['sequence'])), "</p>\n"; |
424
|
|
|
echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
428
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
429
|
|
|
echo $this->misc->form; |
430
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
431
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
432
|
|
|
echo "</form>\n"; |
433
|
|
|
} else { |
434
|
|
|
if (is_array($_POST['sequence'])) { |
435
|
|
|
$msg = ''; |
436
|
|
|
$status = $data->beginTransaction(); |
437
|
|
|
if (0 == $status) { |
438
|
|
|
foreach ($_POST['sequence'] as $s) { |
439
|
|
|
$status = $data->dropSequence($s, isset($_POST['cascade'])); |
440
|
|
|
if (0 == $status) { |
441
|
|
|
$msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedropped']); |
442
|
|
|
} else { |
443
|
|
|
$data->endTransaction(); |
444
|
|
|
$this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedroppedbad'])); |
445
|
|
|
|
446
|
|
|
return; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
} |
450
|
|
|
if (0 == $data->endTransaction()) { |
451
|
|
|
// Everything went fine, back to the Default page.... |
452
|
|
|
$this->misc->setReloadBrowser(true); |
453
|
|
|
$this->doDefault($msg); |
454
|
|
|
} else { |
455
|
|
|
$this->doDefault($lang['strsequencedroppedbad']); |
456
|
|
|
} |
457
|
|
|
} else { |
458
|
|
|
$status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade'])); |
459
|
|
|
if (0 == $status) { |
460
|
|
|
$this->misc->setReloadBrowser(true); |
461
|
|
|
$this->doDefault($lang['strsequencedropped']); |
462
|
|
|
} else { |
463
|
|
|
$this->doDrop(true, $lang['strsequencedroppedbad']); |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Displays a screen where they can enter a new sequence. |
471
|
|
|
* |
472
|
|
|
* @param mixed $msg |
|
|
|
|
473
|
|
|
*/ |
474
|
|
|
public function doCreateSequence($msg = '') |
475
|
|
|
{ |
476
|
|
|
$lang = $this->lang; |
477
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
478
|
|
|
|
479
|
|
|
if (!isset($_POST['formSequenceName'])) { |
480
|
|
|
$_POST['formSequenceName'] = ''; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
if (!isset($_POST['formIncrement'])) { |
484
|
|
|
$_POST['formIncrement'] = ''; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
if (!isset($_POST['formMinValue'])) { |
488
|
|
|
$_POST['formMinValue'] = ''; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
if (!isset($_POST['formMaxValue'])) { |
492
|
|
|
$_POST['formMaxValue'] = ''; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
if (!isset($_POST['formStartValue'])) { |
496
|
|
|
$_POST['formStartValue'] = ''; |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
if (!isset($_POST['formCacheValue'])) { |
500
|
|
|
$_POST['formCacheValue'] = ''; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
$this->printTrail('schema'); |
504
|
|
|
$this->printTitle($lang['strcreatesequence'], 'pg.sequence.create'); |
505
|
|
|
$this->printMsg($msg); |
506
|
|
|
|
507
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
508
|
|
|
echo "<table>\n"; |
509
|
|
|
|
510
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
511
|
|
|
echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
512
|
|
|
htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n"; |
513
|
|
|
|
514
|
|
|
echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n"; |
515
|
|
|
echo '<td class="data1"><input name="formIncrement" size="5" value="', |
516
|
|
|
htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n"; |
517
|
|
|
|
518
|
|
|
echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n"; |
519
|
|
|
echo '<td class="data1"><input name="formMinValue" size="5" value="', |
520
|
|
|
htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n"; |
521
|
|
|
|
522
|
|
|
echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n"; |
523
|
|
|
echo '<td class="data1"><input name="formMaxValue" size="5" value="', |
524
|
|
|
htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n"; |
525
|
|
|
|
526
|
|
|
echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n"; |
527
|
|
|
echo '<td class="data1"><input name="formStartValue" size="5" value="', |
528
|
|
|
htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n"; |
529
|
|
|
|
530
|
|
|
echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n"; |
531
|
|
|
echo '<td class="data1"><input name="formCacheValue" size="5" value="', |
532
|
|
|
htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n"; |
533
|
|
|
|
534
|
|
|
echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n"; |
535
|
|
|
echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ', |
536
|
|
|
(isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
537
|
|
|
|
538
|
|
|
echo "</table>\n"; |
539
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n"; |
540
|
|
|
echo $this->misc->form; |
541
|
|
|
echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
542
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
543
|
|
|
echo "</form>\n"; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* Actually creates the new sequence in the database. |
548
|
|
|
*/ |
549
|
|
|
public function doSaveCreateSequence() |
550
|
|
|
{ |
551
|
|
|
$lang = $this->lang; |
552
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
553
|
|
|
|
554
|
|
|
// Check that they've given a name and at least one column |
555
|
|
|
if ('' == $_POST['formSequenceName']) { |
556
|
|
|
$this->doCreateSequence($lang['strsequenceneedsname']); |
557
|
|
|
} else { |
558
|
|
|
$status = $data->createSequence( |
559
|
|
|
$_POST['formSequenceName'], |
560
|
|
|
$_POST['formIncrement'], |
561
|
|
|
$_POST['formMinValue'], |
562
|
|
|
$_POST['formMaxValue'], |
563
|
|
|
$_POST['formStartValue'], |
564
|
|
|
$_POST['formCacheValue'], |
565
|
|
|
isset($_POST['formCycledValue']) |
566
|
|
|
); |
567
|
|
|
if (0 == $status) { |
568
|
|
|
$this->doDefault($lang['strsequencecreated']); |
569
|
|
|
} else { |
570
|
|
|
$this->doCreateSequence($lang['strsequencecreatedbad']); |
571
|
|
|
} |
572
|
|
|
} |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/** |
576
|
|
|
* Restarts a sequence. |
577
|
|
|
*/ |
578
|
|
|
public function doRestart() |
579
|
|
|
{ |
580
|
|
|
$lang = $this->lang; |
581
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
582
|
|
|
|
583
|
|
|
$status = $data->restartSequence($_REQUEST['sequence']); |
584
|
|
|
if (0 == $status) { |
585
|
|
|
$this->doProperties($lang['strsequencerestart']); |
586
|
|
|
} else { |
587
|
|
|
$this->doProperties($lang['strsequencerestartbad']); |
588
|
|
|
} |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* Resets a sequence. |
593
|
|
|
*/ |
594
|
|
|
public function doReset() |
595
|
|
|
{ |
596
|
|
|
$lang = $this->lang; |
597
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
598
|
|
|
|
599
|
|
|
$status = $data->resetSequence($_REQUEST['sequence']); |
600
|
|
|
if (0 == $status) { |
601
|
|
|
$this->doProperties($lang['strsequencereset']); |
602
|
|
|
} else { |
603
|
|
|
$this->doProperties($lang['strsequenceresetbad']); |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* Set Nextval of a sequence. |
609
|
|
|
*/ |
610
|
|
|
public function doNextval() |
611
|
|
|
{ |
612
|
|
|
$lang = $this->lang; |
613
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
614
|
|
|
|
615
|
|
|
$status = $data->nextvalSequence($_REQUEST['sequence']); |
616
|
|
|
if (0 == $status) { |
617
|
|
|
$this->doProperties($lang['strsequencenextval']); |
618
|
|
|
} else { |
619
|
|
|
$this->doProperties($lang['strsequencenextvalbad']); |
620
|
|
|
} |
621
|
|
|
} |
622
|
|
|
|
623
|
|
|
/** |
624
|
|
|
* Function to save after 'setval'ing a sequence. |
625
|
|
|
*/ |
626
|
|
|
public function doSaveSetval() |
627
|
|
|
{ |
628
|
|
|
$lang = $this->lang; |
629
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
630
|
|
|
|
631
|
|
|
$status = $data->setvalSequence($_POST['sequence'], $_POST['nextvalue']); |
632
|
|
|
if (0 == $status) { |
633
|
|
|
$this->doProperties($lang['strsequencesetval']); |
634
|
|
|
} else { |
635
|
|
|
$this->doProperties($lang['strsequencesetvalbad']); |
636
|
|
|
} |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Function to allow 'setval'ing of a sequence. |
641
|
|
|
* |
642
|
|
|
* @param mixed $msg |
|
|
|
|
643
|
|
|
*/ |
644
|
|
|
public function doSetval($msg = '') |
645
|
|
|
{ |
646
|
|
|
$lang = $this->lang; |
647
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
648
|
|
|
|
649
|
|
|
$this->printTrail('sequence'); |
650
|
|
|
$this->printTitle($lang['strsetval'], 'pg.sequence'); |
651
|
|
|
$this->printMsg($msg); |
652
|
|
|
|
653
|
|
|
// Fetch the sequence information |
654
|
|
|
$sequence = $data->getSequence($_REQUEST['sequence']); |
655
|
|
|
|
656
|
|
|
if (is_object($sequence) && $sequence->recordCount() > 0) { |
657
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
658
|
|
|
echo '<table border="0">'; |
659
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strlastvalue']}</th>\n"; |
660
|
|
|
echo '<td class="data1">'; |
661
|
|
|
echo "<input name=\"nextvalue\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
662
|
|
|
$this->misc->printVal($sequence->fields['last_value']), "\" /></td></tr>\n"; |
663
|
|
|
echo "</table>\n"; |
664
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"setval\" />\n"; |
665
|
|
|
echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
666
|
|
|
echo $this->misc->form; |
667
|
|
|
echo "<input type=\"submit\" name=\"setval\" value=\"{$lang['strsetval']}\" />\n"; |
668
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
669
|
|
|
echo "</form>\n"; |
670
|
|
|
} else { |
671
|
|
|
echo "<p>{$lang['strnodata']}</p>\n"; |
672
|
|
|
} |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* Function to save after altering a sequence. |
677
|
|
|
*/ |
678
|
|
|
public function doSaveAlter() |
679
|
|
|
{ |
680
|
|
|
$lang = $this->lang; |
681
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
682
|
|
|
|
683
|
|
|
if (!isset($_POST['owner'])) { |
684
|
|
|
$_POST['owner'] = null; |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
if (!isset($_POST['newschema'])) { |
688
|
|
|
$_POST['newschema'] = null; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
if (!isset($_POST['formIncrement'])) { |
692
|
|
|
$_POST['formIncrement'] = null; |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
if (!isset($_POST['formMinValue'])) { |
696
|
|
|
$_POST['formMinValue'] = null; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
if (!isset($_POST['formMaxValue'])) { |
700
|
|
|
$_POST['formMaxValue'] = null; |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
if (!isset($_POST['formStartValue'])) { |
704
|
|
|
$_POST['formStartValue'] = null; |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
if (!isset($_POST['formRestartValue'])) { |
708
|
|
|
$_POST['formRestartValue'] = null; |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
if (!isset($_POST['formCacheValue'])) { |
712
|
|
|
$_POST['formCacheValue'] = null; |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
if (!isset($_POST['formCycledValue'])) { |
716
|
|
|
$_POST['formCycledValue'] = null; |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
$status = $data->alterSequence( |
720
|
|
|
$_POST['sequence'], |
721
|
|
|
$_POST['name'], |
722
|
|
|
$_POST['comment'], |
723
|
|
|
$_POST['owner'], |
724
|
|
|
$_POST['newschema'], |
725
|
|
|
$_POST['formIncrement'], |
726
|
|
|
$_POST['formMinValue'], |
727
|
|
|
$_POST['formMaxValue'], |
728
|
|
|
$_POST['formRestartValue'], |
729
|
|
|
$_POST['formCacheValue'], |
730
|
|
|
isset($_POST['formCycledValue']), |
731
|
|
|
$_POST['formStartValue'] |
732
|
|
|
); |
733
|
|
|
|
734
|
|
|
if (0 == $status) { |
735
|
|
|
if ($_POST['sequence'] != $_POST['name']) { |
736
|
|
|
// Jump them to the new view name |
737
|
|
|
$_REQUEST['sequence'] = $_POST['name']; |
738
|
|
|
// Force a browser reload |
739
|
|
|
$this->misc->setReloadBrowser(true); |
740
|
|
|
} |
741
|
|
|
if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { |
742
|
|
|
// Jump them to the new sequence schema |
743
|
|
|
$this->misc->setCurrentSchema($_POST['newschema']); |
744
|
|
|
$this->misc->setReloadBrowser(true); |
745
|
|
|
} |
746
|
|
|
$this->doProperties($lang['strsequencealtered']); |
747
|
|
|
} else { |
748
|
|
|
$this->doProperties($lang['strsequencealteredbad']); |
749
|
|
|
} |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
/** |
753
|
|
|
* Function to allow altering of a sequence. |
754
|
|
|
* |
755
|
|
|
* @param mixed $msg |
|
|
|
|
756
|
|
|
*/ |
757
|
|
|
public function doAlter($msg = '') |
758
|
|
|
{ |
759
|
|
|
$lang = $this->lang; |
760
|
|
|
$data = $this->misc->getDatabaseAccessor(); |
761
|
|
|
|
762
|
|
|
$this->printTrail('sequence'); |
763
|
|
|
$this->printTitle($lang['stralter'], 'pg.sequence.alter'); |
764
|
|
|
$this->printMsg($msg); |
765
|
|
|
|
766
|
|
|
// Fetch the sequence information |
767
|
|
|
$sequence = $data->getSequence($_REQUEST['sequence']); |
768
|
|
|
|
769
|
|
|
if (is_object($sequence) && $sequence->recordCount() > 0) { |
770
|
|
|
if (!isset($_POST['name'])) { |
771
|
|
|
$_POST['name'] = $_REQUEST['sequence']; |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
if (!isset($_POST['comment'])) { |
775
|
|
|
$_POST['comment'] = $sequence->fields['seqcomment']; |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
if (!isset($_POST['owner'])) { |
779
|
|
|
$_POST['owner'] = $sequence->fields['seqowner']; |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
if (!isset($_POST['newschema'])) { |
783
|
|
|
$_POST['newschema'] = $sequence->fields['nspname']; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
// Handle Checkbox Value |
787
|
|
|
$sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); |
788
|
|
|
if ($sequence->fields['is_cycled']) { |
789
|
|
|
$_POST['formCycledValue'] = 'on'; |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
793
|
|
|
echo "<table>\n"; |
794
|
|
|
|
795
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
796
|
|
|
echo '<td class="data1">'; |
797
|
|
|
echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
798
|
|
|
htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
799
|
|
|
|
800
|
|
|
if ($data->isSuperUser()) { |
801
|
|
|
// Fetch all users |
802
|
|
|
$users = $data->getUsers(); |
803
|
|
|
|
804
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; |
805
|
|
|
echo '<td class="data1"><select name="owner">'; |
806
|
|
|
while (!$users->EOF) { |
807
|
|
|
$uname = $users->fields['usename']; |
808
|
|
|
echo '<option value="', htmlspecialchars($uname), '"', |
809
|
|
|
($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
810
|
|
|
$users->moveNext(); |
811
|
|
|
} |
812
|
|
|
echo "</select></td></tr>\n"; |
813
|
|
|
} |
814
|
|
|
|
815
|
|
|
if ($data->hasAlterSequenceSchema()) { |
816
|
|
|
$schemas = $data->getSchemas(); |
817
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n"; |
818
|
|
|
echo '<td class="data1"><select name="newschema">'; |
819
|
|
|
while (!$schemas->EOF) { |
820
|
|
|
$schema = $schemas->fields['nspname']; |
821
|
|
|
echo '<option value="', htmlspecialchars($schema), '"', |
822
|
|
|
($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
823
|
|
|
$schemas->moveNext(); |
824
|
|
|
} |
825
|
|
|
echo "</select></td></tr>\n"; |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n"; |
829
|
|
|
echo '<td class="data1">'; |
830
|
|
|
echo '<textarea rows="3" cols="32" name="comment">', |
831
|
|
|
htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; |
832
|
|
|
|
833
|
|
|
if ($data->hasAlterSequenceStart()) { |
834
|
|
|
echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n"; |
835
|
|
|
echo '<td class="data1"><input name="formStartValue" size="5" value="', |
836
|
|
|
htmlspecialchars($sequence->fields['start_value']), "\" /></td></tr>\n"; |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
echo "<tr><th class=\"data left\">{$lang['strrestartvalue']}</th>\n"; |
840
|
|
|
echo '<td class="data1"><input name="formRestartValue" size="5" value="', |
841
|
|
|
htmlspecialchars($sequence->fields['last_value']), "\" /></td></tr>\n"; |
842
|
|
|
|
843
|
|
|
echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n"; |
844
|
|
|
echo '<td class="data1"><input name="formIncrement" size="5" value="', |
845
|
|
|
htmlspecialchars($sequence->fields['increment_by']), "\" /> </td></tr>\n"; |
846
|
|
|
|
847
|
|
|
echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n"; |
848
|
|
|
echo '<td class="data1"><input name="formMaxValue" size="5" value="', |
849
|
|
|
htmlspecialchars($sequence->fields['max_value']), "\" /></td></tr>\n"; |
850
|
|
|
|
851
|
|
|
echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n"; |
852
|
|
|
echo '<td class="data1"><input name="formMinValue" size="5" value="', |
853
|
|
|
htmlspecialchars($sequence->fields['min_value']), "\" /></td></tr>\n"; |
854
|
|
|
|
855
|
|
|
echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n"; |
856
|
|
|
echo '<td class="data1"><input name="formCacheValue" size="5" value="', |
857
|
|
|
htmlspecialchars($sequence->fields['cache_value']), "\" /></td></tr>\n"; |
858
|
|
|
|
859
|
|
|
echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n"; |
860
|
|
|
echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ', |
861
|
|
|
(isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
862
|
|
|
|
863
|
|
|
echo "</table>\n"; |
864
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
865
|
|
|
echo $this->misc->form; |
866
|
|
|
echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
867
|
|
|
echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
868
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
869
|
|
|
echo "</form>\n"; |
870
|
|
|
} else { |
871
|
|
|
echo "<p>{$lang['strnodata']}</p>\n"; |
872
|
|
|
} |
873
|
|
|
} |
874
|
|
|
} |
875
|
|
|
|