1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Manage sequences in a database
|
5
|
*
|
6
|
* $Id: sequences.php,v 1.30 2005/10/18 03:45:16 chriskl Exp $
|
7
|
*/
|
8
|
|
9
|
// Include application functions
|
10
|
include_once('./libraries/lib.inc.php');
|
11
|
|
12
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
13
|
if (!isset($msg)) $msg = '';
|
14
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
15
|
|
16
|
/**
|
17
|
* Display list of all sequences in the database/schema
|
18
|
*/
|
19
|
function doDefault($msg = '') {
|
20
|
global $data, $conf, $misc;
|
21
|
global $PHP_SELF, $lang;
|
22
|
|
23
|
$misc->printTrail('schema');
|
24
|
$misc->printTabs('schema', 'sequences');
|
25
|
$misc->printMsg($msg);
|
26
|
|
27
|
// Get all sequences
|
28
|
$sequences = $data->getSequences();
|
29
|
|
30
|
$columns = array(
|
31
|
'sequence' => array(
|
32
|
'title' => $lang['strsequence'],
|
33
|
'field' => 'seqname',
|
34
|
),
|
35
|
'owner' => array(
|
36
|
'title' => $lang['strowner'],
|
37
|
'field' => 'seqowner',
|
38
|
),
|
39
|
'actions' => array(
|
40
|
'title' => $lang['stractions'],
|
41
|
),
|
42
|
'comment' => array(
|
43
|
'title' => $lang['strcomment'],
|
44
|
'field' => 'seqcomment',
|
45
|
),
|
46
|
);
|
47
|
|
48
|
$actions = array(
|
49
|
'properties' => array(
|
50
|
'title' => $lang['strproperties'],
|
51
|
'url' => "{$PHP_SELF}?action=properties&{$misc->href}&",
|
52
|
'vars' => array('sequence' => 'seqname'),
|
53
|
),
|
54
|
'drop' => array(
|
55
|
'title' => $lang['strdrop'],
|
56
|
'url' => "{$PHP_SELF}?action=confirm_drop&{$misc->href}&",
|
57
|
'vars' => array('sequence' => 'seqname'),
|
58
|
),
|
59
|
'privileges' => array(
|
60
|
'title' => $lang['strprivileges'],
|
61
|
'url' => "privileges.php?{$misc->href}&subject=sequence&",
|
62
|
'vars' => array('sequence' => 'seqname'),
|
63
|
),
|
64
|
);
|
65
|
|
66
|
$misc->printTable($sequences, $columns, $actions, $lang['strnosequences']);
|
67
|
|
68
|
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatesequence']}</a></p>\n";
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Generate XML for the browser tree.
|
73
|
*/
|
74
|
function doTree() {
|
75
|
global $misc, $data;
|
76
|
|
77
|
$sequences = $data->getSequences();
|
78
|
|
79
|
$reqvars = $misc->getRequestVars('sequence');
|
80
|
|
81
|
$attrs = array(
|
82
|
'text' => field('seqname'),
|
83
|
'icon' => 'sequences',
|
84
|
'toolTip'=> field('seqcomment'),
|
85
|
'action' => url('sequences.php',
|
86
|
$reqvars,
|
87
|
array (
|
88
|
'action' => 'properties',
|
89
|
'sequence' => field('seqname')
|
90
|
)
|
91
|
)
|
92
|
);
|
93
|
|
94
|
$misc->printTreeXML($sequences, $attrs);
|
95
|
exit;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* Display the properties of a sequence
|
100
|
*/
|
101
|
function doProperties($msg = '') {
|
102
|
global $data, $misc, $PHP_SELF;
|
103
|
global $lang;
|
104
|
|
105
|
$misc->printTrail('sequence');
|
106
|
$misc->printTitle($lang['strproperties'],'pg.sequence');
|
107
|
$misc->printMsg($msg);
|
108
|
|
109
|
// Fetch the sequence information
|
110
|
$sequence = $data->getSequence($_REQUEST['sequence']);
|
111
|
|
112
|
if (is_object($sequence) && $sequence->recordCount() > 0) {
|
113
|
$sequence->f['is_cycled'] = $data->phpBool($sequence->f['is_cycled']);
|
114
|
$sequence->f['is_called'] = $data->phpBool($sequence->f['is_called']);
|
115
|
|
116
|
// Show comment if any
|
117
|
if ($sequence->f['seqcomment'] !== null)
|
118
|
echo "<p class=\"comment\">", $misc->printVal($sequence->f['seqcomment']), "</p>\n";
|
119
|
|
120
|
echo "<table border=\"0\">";
|
121
|
echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strlastvalue']}</th>";
|
122
|
echo "<th class=\"data\">{$lang['strincrementby']}</th><th class=\"data\">{$lang['strmaxvalue']}</th>";
|
123
|
echo "<th class=\"data\">{$lang['strminvalue']}</th><th class=\"data\">{$lang['strcachevalue']}</th>";
|
124
|
// PostgreSQL 7.0 and below don't have logcount
|
125
|
if (isset($sequence->f['log_cnt'])) {
|
126
|
echo "<th class=\"data\">{$lang['strlogcount']}</th>";
|
127
|
}
|
128
|
echo "<th class=\"data\">{$lang['striscycled']}</th><th class=\"data\">{$lang['striscalled']}</th></tr>";
|
129
|
echo "<tr>";
|
130
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['seqname']), "</td>";
|
131
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['last_value']), "</td>";
|
132
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['increment_by']), "</td>";
|
133
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['max_value']), "</td>";
|
134
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['min_value']), "</td>";
|
135
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['cache_value']), "</td>";
|
136
|
// PostgreSQL 7.0 and below don't have logcount
|
137
|
if (isset($sequence->f['log_cnt'])) {
|
138
|
echo "<td class=\"data1\">", $misc->printVal($sequence->f['log_cnt']), "</td>";
|
139
|
}
|
140
|
echo "<td class=\"data1\">", ($sequence->f['is_cycled'] ? $lang['stryes'] : $lang['strno']), "</td>";
|
141
|
echo "<td class=\"data1\">", ($sequence->f['is_called'] ? $lang['stryes'] : $lang['strno']), "</td>";
|
142
|
echo "</tr>";
|
143
|
echo "</table>";
|
144
|
|
145
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=reset&{$misc->href}&sequence=", urlencode($sequence->f['seqname']), "\">{$lang['strreset']}</a> |\n";
|
146
|
echo "<a class=\"navlink\" href=\"{$PHP_SELF}?{$misc->href}\">{$lang['strshowallsequences']}</a></p>\n";
|
147
|
}
|
148
|
else echo "<p>{$lang['strnodata']}</p>\n";
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Drop a sequence
|
153
|
*/
|
154
|
function doDrop($confirm, $msg = '') {
|
155
|
global $data, $misc;
|
156
|
global $PHP_SELF, $lang;
|
157
|
|
158
|
if ($confirm) {
|
159
|
$misc->printTrail('sequence');
|
160
|
$misc->printTitle($lang['strdrop'],'pg.sequence.drop');
|
161
|
$misc->printMsg($msg);
|
162
|
|
163
|
echo "<p>", sprintf($lang['strconfdropsequence'], $misc->printVal($_REQUEST['sequence'])), "</p>\n";
|
164
|
|
165
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
166
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
|
167
|
echo "<input type=\"hidden\" name=\"sequence\" value=\"", htmlspecialchars($_REQUEST['sequence']), "\" />\n";
|
168
|
echo $misc->form;
|
169
|
// Show cascade drop option if supportd
|
170
|
if ($data->hasDropBehavior()) {
|
171
|
echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
|
172
|
}
|
173
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
|
174
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
175
|
echo "</form>\n";
|
176
|
}
|
177
|
else {
|
178
|
$status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade']));
|
179
|
if ($status == 0)
|
180
|
doDefault($lang['strsequencedropped']);
|
181
|
else
|
182
|
doDrop(true, $lang['strsequencedroppedbad']);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
/**
|
187
|
* Displays a screen where they can enter a new sequence
|
188
|
*/
|
189
|
function doCreateSequence($msg = '') {
|
190
|
global $data, $misc;
|
191
|
global $PHP_SELF, $lang;
|
192
|
|
193
|
if (!isset($_POST['formSequenceName'])) $_POST['formSequenceName'] = '';
|
194
|
if (!isset($_POST['formIncrement'])) $_POST['formIncrement'] = '';
|
195
|
if (!isset($_POST['formMinValue'])) $_POST['formMinValue'] = '';
|
196
|
if (!isset($_POST['formMaxValue'])) $_POST['formMaxValue'] = '';
|
197
|
if (!isset($_POST['formStartValue'])) $_POST['formStartValue'] = '';
|
198
|
if (!isset($_POST['formCacheValue'])) $_POST['formCacheValue'] = '';
|
199
|
|
200
|
$misc->printTrail('schema');
|
201
|
$misc->printTitle($lang['strcreatesequence'],'pg.sequence.create');
|
202
|
$misc->printMsg($msg);
|
203
|
|
204
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
205
|
echo "<table>\n";
|
206
|
|
207
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
|
208
|
echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
209
|
htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n";
|
210
|
|
211
|
echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n";
|
212
|
echo "<td class=\"data1\"><input name=\"formIncrement\" size=\"5\" value=\"",
|
213
|
htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n";
|
214
|
|
215
|
echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n";
|
216
|
echo "<td class=\"data1\"><input name=\"formMinValue\" size=\"5\" value=\"",
|
217
|
htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n";
|
218
|
|
219
|
echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n";
|
220
|
echo "<td class=\"data1\"><input name=\"formMaxValue\" size=\"5\" value=\"",
|
221
|
htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n";
|
222
|
|
223
|
echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n";
|
224
|
echo "<td class=\"data1\"><input name=\"formStartValue\" size=\"5\" value=\"",
|
225
|
htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n";
|
226
|
|
227
|
echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n";
|
228
|
echo "<td class=\"data1\"><input name=\"formCacheValue\" size=\"5\" value=\"",
|
229
|
htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n";
|
230
|
|
231
|
echo "<tr><th class=\"data left\">{$lang['striscycled']}</th>\n";
|
232
|
echo "<td class=\"data1\"><input type=\"checkbox\" name=\"formCycledValue\" value=\"",
|
233
|
(isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), "\" /></td></tr>\n";
|
234
|
|
235
|
echo "</table>\n";
|
236
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n";
|
237
|
echo $misc->form;
|
238
|
echo "<input type=\"hidden\" name=\"sequence\" value=\"", htmlspecialchars($_REQUEST['sequence']), "\" />\n";
|
239
|
echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
|
240
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
241
|
echo "</form>\n";
|
242
|
}
|
243
|
|
244
|
/**
|
245
|
* Actually creates the new sequence in the database
|
246
|
*/
|
247
|
function doSaveCreateSequence() {
|
248
|
global $data;
|
249
|
global $lang;
|
250
|
|
251
|
// Check that they've given a name and at least one column
|
252
|
if ($_POST['formSequenceName'] == '') doCreateSequence($lang['strsequenceneedsname']);
|
253
|
else {
|
254
|
$status = $data->createSequence($_POST['formSequenceName'],
|
255
|
$_POST['formIncrement'], $_POST['formMinValue'],
|
256
|
$_POST['formMaxValue'], $_POST['formStartValue'],
|
257
|
$_POST['formCacheValue'], isset($_POST['formCycledValue']));
|
258
|
if ($status == 0) {
|
259
|
doDefault($lang['strsequencecreated']);
|
260
|
} else {
|
261
|
doCreateSequence($lang['strsequencecreatedbad']);
|
262
|
}
|
263
|
}
|
264
|
}
|
265
|
|
266
|
/**
|
267
|
* Resets a sequence
|
268
|
*/
|
269
|
function doReset() {
|
270
|
global $data;
|
271
|
global $PHP_SELF, $lang;
|
272
|
|
273
|
$status = $data->resetSequence($_REQUEST['sequence']);
|
274
|
if ($status == 0)
|
275
|
doProperties($lang['strsequencereset']);
|
276
|
else
|
277
|
doProperties($lang['strsequenceresetbad']);
|
278
|
}
|
279
|
|
280
|
if ($action == 'tree') doTree();
|
281
|
|
282
|
// Print header
|
283
|
$misc->printHeader($lang['strsequences']);
|
284
|
$misc->printBody();
|
285
|
|
286
|
switch($action) {
|
287
|
case 'create':
|
288
|
doCreateSequence();
|
289
|
break;
|
290
|
case 'save_create_sequence':
|
291
|
if (isset($_POST['create'])) doSaveCreateSequence();
|
292
|
else doDefault();
|
293
|
break;
|
294
|
case 'properties':
|
295
|
doProperties();
|
296
|
break;
|
297
|
case 'drop':
|
298
|
if (isset($_POST['drop'])) doDrop(false);
|
299
|
else doDefault();
|
300
|
break;
|
301
|
case 'confirm_drop':
|
302
|
doDrop(true);
|
303
|
break;
|
304
|
case 'reset':
|
305
|
doReset();
|
306
|
break;
|
307
|
default:
|
308
|
doDefault();
|
309
|
break;
|
310
|
}
|
311
|
|
312
|
// Print footer
|
313
|
$misc->printFooter();
|
314
|
|
315
|
?>
|