1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Common functions for generating lists of Routines, Triggers and Events.
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
/**
* Creates a list of items containing the relevant
* information and some action links.
*
* @param string $type One of ['routine'|'trigger'|'event']
* @param array $items An array of items
*
* @return string HTML code of the list of items
*/
function PMA_RTE_getList($type, $items)
{
global $table;
/**
* Conditional classes switch the list on or off
*/
$class1 = 'hide';
$class2 = '';
if (! $items) {
$class1 = '';
$class2 = ' hide';
}
/**
* Generate output
*/
$retval = "<!-- LIST OF " . PMA_RTE_getWord('docu') . " START -->\n";
$retval .= "<fieldset>\n";
$retval .= " <legend>\n";
$retval .= " " . PMA_RTE_getWord('title') . "\n";
$retval .= " " . PMA_Util::showMySQLDocu('SQL-Syntax', PMA_RTE_getWord('docu')) . "\n";
$retval .= " </legend>\n";
$retval .= " <div class='$class1' id='nothing2display'>\n";
$retval .= " " . PMA_RTE_getWord('nothing') . "\n";
$retval .= " </div>\n";
$retval .= " <table class='data$class2'>\n";
$retval .= " <!-- TABLE HEADERS -->\n";
$retval .= " <tr>\n";
// th cells with a colspan need corresponding td cells, according to W3C
switch ($type) {
case 'routine':
$retval .= " <th>" . __('Name') . "</th>\n";
$retval .= " <th colspan='4'>" . __('Action') . "</th>\n";
$retval .= " <th>" . __('Type') . "</th>\n";
$retval .= " <th>" . __('Returns') . "</th>\n";
$retval .= " </tr>\n";
$retval .= " <tr style='display: none'>\n"; // see comment above
for ($i = 0; $i < 7; $i++) {
$retval .= " <td></td>\n";
}
break;
case 'trigger':
$retval .= " <th>" . __('Name') . "</th>\n";
if (empty($table)) {
$retval .= " <th>" . __('Table') . "</th>\n";
}
$retval .= " <th colspan='3'>" . __('Action') . "</th>\n";
$retval .= " <th>" . __('Time') . "</th>\n";
$retval .= " <th>" . __('Event') . "</th>\n";
$retval .= " </tr>\n";
$retval .= " <tr style='display: none'>\n"; // see comment above
for ($i = 0; $i < (empty($table) ? 7 : 6); $i++) {
$retval .= " <td></td>\n";
}
break;
case 'event':
$retval .= " <th>" . __('Name') . "</th>\n";
$retval .= " <th>" . __('Status') . "</th>\n";
$retval .= " <th colspan='3'>" . __('Action') . "</th>\n";
$retval .= " <th>" . __('Type') . "</th>\n";
$retval .= " </tr>\n";
$retval .= " <tr style='display: none'>\n"; // see comment above
for ($i = 0; $i < 6; $i++) {
$retval .= " <td></td>\n";
}
break;
default:
break;
}
$retval .= " </tr>\n";
$retval .= " <!-- TABLE DATA -->\n";
$ct = 0;
foreach ($items as $item) {
$rowclass = ($ct % 2 == 0) ? 'odd' : 'even';
if ($GLOBALS['is_ajax_request']) {
$rowclass .= ' ajaxInsert hide';
}
// Get each row from the correct function
switch ($type) {
case 'routine':
$retval .= PMA_RTN_getRowForList($item, $rowclass);
break;
case 'trigger':
$retval .= PMA_TRI_getRowForList($item, $rowclass);
break;
case 'event':
$retval .= PMA_EVN_getRowForList($item, $rowclass);
break;
default:
break;
}
$ct++;
}
$retval .= " </table>\n";
$retval .= "</fieldset>\n";
$retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n";
return $retval;
} // end PMA_RTE_getList()
/**
* Creates the contents for a row in the list of routines
*
* @param array $routine An array of routine data
* @param string $rowclass Empty or one of ['even'|'odd']
*
* @return string HTML code of a row for the list of routines
*/
function PMA_RTN_getRowForList($routine, $rowclass = '')
{
global $ajax_class, $url_query, $db, $titles;
$sql_drop = sprintf(
'DROP %s IF EXISTS %s',
$routine['ROUTINE_TYPE'],
PMA_Util::backquote($routine['SPECIFIC_NAME'])
);
$type_link = "item_type={$routine['ROUTINE_TYPE']}";
$retval = " <tr class='noclick $rowclass'>\n";
$retval .= " <td>\n";
$retval .= " <span class='drop_sql hide'>$sql_drop</span>\n";
$retval .= " <strong>\n";
$retval .= " " . htmlspecialchars($routine['SPECIFIC_NAME']) . "\n";
$retval .= " </strong>\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
if ($routine['ROUTINE_DEFINITION'] !== null
&& PMA_Util::currentUserHasPrivilege('ALTER ROUTINE', $db)
&& PMA_Util::currentUserHasPrivilege('CREATE ROUTINE', $db)
) {
$retval .= ' <a ' . $ajax_class['edit']
. ' href="db_routines.php?'
. $url_query
. '&edit_item=1'
. '&item_name=' . urlencode($routine['SPECIFIC_NAME'])
. '&' . $type_link
. '">' . $titles['Edit'] . "</a>\n";
} else {
$retval .= " {$titles['NoEdit']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
if ($routine['ROUTINE_DEFINITION'] !== null
&& PMA_Util::currentUserHasPrivilege('EXECUTE', $db)
) {
// Check if he routine has any input parameters. If it does,
// we will show a dialog to get values for these parameters,
// otherwise we can execute it directly.
$routine_details = PMA_RTN_getDataFromName(
$routine['SPECIFIC_NAME'],
$routine['ROUTINE_TYPE'],
false
);
if ($routine !== false) {
$execute_action = 'execute_routine';
for ($i=0; $i<$routine_details['item_num_params']; $i++) {
if ($routine_details['item_type'] == 'PROCEDURE'
&& $routine_details['item_param_dir'][$i] == 'OUT'
) {
continue;
}
$execute_action = 'execute_dialog';
break;
}
$retval .= ' <a ' . $ajax_class['exec']
. ' href="db_routines.php?'
. $url_query
. '&' . $execute_action . '=1'
. '&item_name=' . urlencode($routine['SPECIFIC_NAME'])
. '&' . $type_link
. '">' . $titles['Execute'] . "</a>\n";
}
} else {
$retval .= " {$titles['NoExecute']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= ' <a ' . $ajax_class['export']
. ' href="db_routines.php?'
. $url_query
. '&export_item=1'
. '&item_name=' . urlencode($routine['SPECIFIC_NAME'])
. '&' . $type_link
. '">' . $titles['Export'] . "</a>\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
if (PMA_Util::currentUserHasPrivilege('ALTER ROUTINE', $db)) {
$retval .= ' <a ' . $ajax_class['drop']
. ' href="sql.php?'
. $url_query
. '&sql_query=' . urlencode($sql_drop)
. '&goto=db_routines.php' . urlencode("?db={$db}")
. '" >' . $titles['Drop'] . "</a>\n";
} else {
$retval .= " {$titles['NoDrop']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= " {$routine['ROUTINE_TYPE']}\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= " " . htmlspecialchars($routine['DTD_IDENTIFIER']) . "\n";
$retval .= " </td>\n";
$retval .= " </tr>\n";
return $retval;
} // end PMA_RTN_getRowForList()
/**
* Creates the contents for a row in the list of triggers
*
* @param array $trigger An array of routine data
* @param string $rowclass Empty or one of ['even'|'odd']
*
* @return string HTML code of a cell for the list of triggers
*/
function PMA_TRI_getRowForList($trigger, $rowclass = '')
{
global $ajax_class, $url_query, $db, $table, $titles;
$retval = " <tr class='noclick $rowclass'>\n";
$retval .= " <td>\n";
$retval .= " <span class='drop_sql hide'>{$trigger['drop']}</span>\n";
$retval .= " <strong>\n";
$retval .= " " . htmlspecialchars($trigger['name']) . "\n";
$retval .= " </strong>\n";
$retval .= " </td>\n";
if (empty($table)) {
$retval .= " <td>\n";
$retval .= " <a href='db_triggers.php?db={$db}"
. "&table={$trigger['table']}'>"
. $trigger['table'] . "</a>\n";
$retval .= " </td>\n";
}
$retval .= " <td>\n";
if (PMA_Util::currentUserHasPrivilege('TRIGGER', $db, $table)) {
$retval .= ' <a ' . $ajax_class['edit']
. ' href="db_triggers.php?'
. $url_query
. '&edit_item=1'
. '&item_name=' . urlencode($trigger['name'])
. '">' . $titles['Edit'] . "</a>\n";
} else {
$retval .= " {$titles['NoEdit']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= ' <a ' . $ajax_class['export']
. ' href="db_triggers.php?'
. $url_query
. '&export_item=1'
. '&item_name=' . urlencode($trigger['name'])
. '">' . $titles['Export'] . "</a>\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
if (PMA_Util::currentUserHasPrivilege('TRIGGER', $db)) {
$retval .= ' <a ' . $ajax_class['drop']
. ' href="sql.php?'
. $url_query
. '&sql_query=' . urlencode($trigger['drop'])
. '&goto=db_triggers.php' . urlencode("?db={$db}")
. '" >' . $titles['Drop'] . "</a>\n";
} else {
$retval .= " {$titles['NoDrop']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= " {$trigger['action_timing']}\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= " {$trigger['event_manipulation']}\n";
$retval .= " </td>\n";
$retval .= " </tr>\n";
return $retval;
} // end PMA_TRI_getRowForList()
/**
* Creates the contents for a row in the list of events
*
* @param array $event An array of routine data
* @param string $rowclass Empty or one of ['even'|'odd']
*
* @return string HTML code of a cell for the list of events
*/
function PMA_EVN_getRowForList($event, $rowclass = '')
{
global $ajax_class, $url_query, $db, $titles;
$sql_drop = sprintf(
'DROP EVENT IF EXISTS %s',
PMA_Util::backquote($event['EVENT_NAME'])
);
$retval = " <tr class='noclick $rowclass'>\n";
$retval .= " <td>\n";
$retval .= " <span class='drop_sql hide'>$sql_drop</span>\n";
$retval .= " <strong>\n";
$retval .= " " . htmlspecialchars($event['EVENT_NAME']) . "\n";
$retval .= " </strong>\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= " {$event['STATUS']}\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
if (PMA_Util::currentUserHasPrivilege('EVENT', $db)) {
$retval .= ' <a ' . $ajax_class['edit']
. ' href="db_events.php?'
. $url_query
. '&edit_item=1'
. '&item_name=' . urlencode($event['EVENT_NAME'])
. '">' . $titles['Edit'] . "</a>\n";
} else {
$retval .= " {$titles['NoEdit']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= ' <a ' . $ajax_class['export']
. ' href="db_events.php?'
. $url_query
. '&export_item=1'
. '&item_name=' . urlencode($event['EVENT_NAME'])
. '">' . $titles['Export'] . "</a>\n";
$retval .= " </td>\n";
$retval .= " <td>\n";
if (PMA_Util::currentUserHasPrivilege('EVENT', $db)) {
$retval .= ' <a ' . $ajax_class['drop']
. ' href="sql.php?'
. $url_query
. '&sql_query=' . urlencode($sql_drop)
. '&goto=db_events.php' . urlencode("?db={$db}")
. '" >' . $titles['Drop'] . "</a>\n";
} else {
$retval .= " {$titles['NoDrop']}\n";
}
$retval .= " </td>\n";
$retval .= " <td>\n";
$retval .= " {$event['EVENT_TYPE']}\n";
$retval .= " </td>\n";
$retval .= " </tr>\n";
return $retval;
} // end PMA_EVN_getRowForList()
?>
|