2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Common functions for generating lists of Routines, Triggers and Events.
8 if (! defined('PHPMYADMIN')) {
13 * Creates a list of items containing the relevant
14 * information and some action links.
16 * @param string $type One of ['routine'|'trigger'|'event']
17 * @param array $items An array of items
19 * @return string HTML code of the list of items
21 function PMA_RTE_getList($type, $items)
26 * Conditional classes switch the list on or off
37 $retval = "<!-- LIST OF " . PMA_RTE_getWord('docu') . " START -->\n";
38 $retval .= "<fieldset>\n";
39 $retval .= " <legend>\n";
40 $retval .= " " . PMA_RTE_getWord('title') . "\n";
41 $retval .= " " . PMA_showMySQLDocu('SQL-Syntax', PMA_RTE_getWord('docu')) . "\n";
42 $retval .= " </legend>\n";
43 $retval .= " <div class='$class1' id='nothing2display'>\n";
44 $retval .= " " . PMA_RTE_getWord('nothing') . "\n";
45 $retval .= " </div>\n";
46 $retval .= " <table class='data$class2'>\n";
47 $retval .= " <!-- TABLE HEADERS -->\n";
51 $retval .= " <th>" . __('Name') . "</th>\n";
52 $retval .= " <th colspan='4'>" . __('Action') . "</th>\n";
53 $retval .= " <th>" . __('Type') . "</th>\n";
54 $retval .= " <th>" . __('Returns') . "</th>\n";
57 $retval .= " <th>" . __('Name') . "</th>\n";
59 $retval .= " <th>" . __('Table') . "</th>\n";
61 $retval .= " <th colspan='3'>" . __('Action') . "</th>\n";
62 $retval .= " <th>" . __('Time') . "</th>\n";
63 $retval .= " <th>" . __('Event') . "</th>\n";
66 $retval .= " <th>" . __('Name') . "</th>\n";
67 $retval .= " <th>" . __('Status') . "</th>\n";
68 $retval .= " <th colspan='3'>" . __('Action') . "</th>\n";
69 $retval .= " <th>" . __('Type') . "</th>\n";
74 $retval .= " </tr>\n";
75 $retval .= " <!-- TABLE DATA -->\n";
77 foreach ($items as $item) {
78 $rowclass = ($ct %
2 == 0) ?
'even' : 'odd';
79 if ($GLOBALS['is_ajax_request']) {
80 $rowclass .= ' ajaxInsert hide';
82 // Get each row from the correct function
85 $retval .= PMA_RTN_getRowForList($item, $rowclass);
88 $retval .= PMA_TRI_getRowForList($item, $rowclass);
91 $retval .= PMA_EVN_getRowForList($item, $rowclass);
98 $retval .= " </table>\n";
99 $retval .= "</fieldset>\n";
100 $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n";
103 } // end PMA_RTE_getList()
106 * Creates the contents for a row in the list of routines
108 * @param array $routine An array of routine data
109 * @param string $rowclass Empty or one of ['even'|'odd']
111 * @return string HTML code of a row for the list of routines
113 function PMA_RTN_getRowForList($routine, $rowclass = '')
115 global $ajax_class, $url_query, $db, $titles;
117 $sql_drop = sprintf('DROP %s IF EXISTS %s',
118 $routine['ROUTINE_TYPE'],
119 PMA_backquote($routine['SPECIFIC_NAME']));
120 $type_link = "item_type={$routine['ROUTINE_TYPE']}";
122 $retval = " <tr class='noclick $rowclass'>\n";
123 $retval .= " <td>\n";
124 $retval .= " <span class='drop_sql hide'>$sql_drop</span>\n";
125 $retval .= " <strong>\n";
126 $retval .= " " . htmlspecialchars($routine['SPECIFIC_NAME']) . "\n";
127 $retval .= " </strong>\n";
128 $retval .= " </td>\n";
129 $retval .= " <td>\n";
130 if ($routine['ROUTINE_DEFINITION'] !== null
131 && PMA_currentUserHasPrivilege('ALTER ROUTINE', $db)
132 && PMA_currentUserHasPrivilege('CREATE ROUTINE', $db)
134 $retval .= ' <a ' . $ajax_class['edit']
135 . ' href="db_routines.php?'
138 . '&item_name=' . urlencode($routine['SPECIFIC_NAME'])
139 . '&' . $type_link
140 . '">' . $titles['Edit'] . "</a>\n";
142 $retval .= " {$titles['NoEdit']}\n";
144 $retval .= " </td>\n";
145 $retval .= " <td>\n";
146 if ($routine['ROUTINE_DEFINITION'] !== null
147 && PMA_currentUserHasPrivilege('EXECUTE', $db)
149 // Check if he routine has any input parameters. If it does,
150 // we will show a dialog to get values for these parameters,
151 // otherwise we can execute it directly.
152 $routine_details = PMA_RTN_getDataFromName(
153 $routine['SPECIFIC_NAME'],
154 $routine['ROUTINE_TYPE'],
157 if ($routine !== false) {
158 $execute_action = 'execute_routine';
159 for ($i=0; $i<$routine_details['item_num_params']; $i++
) {
160 if ($routine_details['item_type'] == 'PROCEDURE'
161 && $routine_details['item_param_dir'][$i] == 'OUT'
165 $execute_action = 'execute_dialog';
168 $retval .= ' <a ' . $ajax_class['exec']
169 . ' href="db_routines.php?'
171 . '&' . $execute_action . '=1'
172 . '&item_name=' . urlencode($routine['SPECIFIC_NAME'])
173 . '&' . $type_link
174 . '">' . $titles['Execute'] . "</a>\n";
177 $retval .= " {$titles['NoExecute']}\n";
179 $retval .= " </td>\n";
180 $retval .= " <td>\n";
181 $retval .= ' <a ' . $ajax_class['export']
182 . ' href="db_routines.php?'
184 . '&export_item=1'
185 . '&item_name=' . urlencode($routine['SPECIFIC_NAME'])
186 . '&' . $type_link
187 . '">' . $titles['Export'] . "</a>\n";
188 $retval .= " </td>\n";
189 $retval .= " <td>\n";
190 if (PMA_currentUserHasPrivilege('ALTER ROUTINE', $db)) {
191 $retval .= ' <a ' . $ajax_class['drop']
194 . '&sql_query=' . urlencode($sql_drop)
195 . '&goto=db_routines.php' . urlencode("?db={$db}")
196 . '" >' . $titles['Drop'] . "</a>\n";
198 $retval .= " {$titles['NoDrop']}\n";
200 $retval .= " </td>\n";
201 $retval .= " <td>\n";
202 $retval .= " {$routine['ROUTINE_TYPE']}\n";
203 $retval .= " </td>\n";
204 $retval .= " <td>\n";
205 $retval .= " " . htmlspecialchars($routine['DTD_IDENTIFIER']) . "\n";
206 $retval .= " </td>\n";
207 $retval .= " </tr>\n";
210 } // end PMA_RTN_getRowForList()
213 * Creates the contents for a row in the list of triggers
215 * @param array $trigger An array of routine data
216 * @param string $rowclass Empty or one of ['even'|'odd']
218 * @return string HTML code of a cell for the list of triggers
220 function PMA_TRI_getRowForList($trigger, $rowclass = '')
222 global $ajax_class, $url_query, $db, $table, $titles;
224 $retval = " <tr class='noclick $rowclass'>\n";
225 $retval .= " <td>\n";
226 $retval .= " <span class='drop_sql hide'>{$trigger['drop']}</span>\n";
227 $retval .= " <strong>\n";
228 $retval .= " " . htmlspecialchars($trigger['name']) . "\n";
229 $retval .= " </strong>\n";
230 $retval .= " </td>\n";
232 $retval .= " <td>\n";
233 $retval .= " <a href='db_triggers.php?db={$db}"
234 . "&table={$trigger['table']}'>"
235 . $trigger['table'] . "</a>\n";
236 $retval .= " </td>\n";
238 $retval .= " <td>\n";
239 if (PMA_currentUserHasPrivilege('TRIGGER', $db, $table)) {
240 $retval .= ' <a ' . $ajax_class['edit']
241 . ' href="db_triggers.php?'
244 . '&item_name=' . urlencode($trigger['name'])
245 . '">' . $titles['Edit'] . "</a>\n";
247 $retval .= " {$titles['NoEdit']}\n";
249 $retval .= " </td>\n";
250 $retval .= " <td>\n";
251 $retval .= ' <a ' . $ajax_class['export']
252 . ' href="db_triggers.php?'
254 . '&export_item=1'
255 . '&item_name=' . urlencode($trigger['name'])
256 . '">' . $titles['Export'] . "</a>\n";
257 $retval .= " </td>\n";
258 $retval .= " <td>\n";
259 if (PMA_currentUserHasPrivilege('TRIGGER', $db)) {
260 $retval .= ' <a ' . $ajax_class['drop']
263 . '&sql_query=' . urlencode($trigger['drop'])
264 . '&goto=db_triggers.php' . urlencode("?db={$db}")
265 . '" >' . $titles['Drop'] . "</a>\n";
267 $retval .= " {$titles['NoDrop']}\n";
269 $retval .= " </td>\n";
270 $retval .= " <td>\n";
271 $retval .= " {$trigger['action_timing']}\n";
272 $retval .= " </td>\n";
273 $retval .= " <td>\n";
274 $retval .= " {$trigger['event_manipulation']}\n";
275 $retval .= " </td>\n";
276 $retval .= " </tr>\n";
279 } // end PMA_TRI_getRowForList()
282 * Creates the contents for a row in the list of events
284 * @param array $event An array of routine data
285 * @param string $rowclass Empty or one of ['even'|'odd']
287 * @return string HTML code of a cell for the list of events
289 function PMA_EVN_getRowForList($event, $rowclass = '')
291 global $ajax_class, $url_query, $db, $titles;
294 'DROP EVENT IF EXISTS %s',
295 PMA_backquote($event['EVENT_NAME'])
298 $retval = " <tr class='noclick $rowclass'>\n";
299 $retval .= " <td>\n";
300 $retval .= " <span class='drop_sql hide'>$sql_drop</span>\n";
301 $retval .= " <strong>\n";
302 $retval .= " " . htmlspecialchars($event['EVENT_NAME']) . "\n";
303 $retval .= " </strong>\n";
304 $retval .= " </td>\n";
305 $retval .= " <td>\n";
306 $retval .= " {$event['STATUS']}\n";
307 $retval .= " </td>\n";
308 $retval .= " <td>\n";
309 if (PMA_currentUserHasPrivilege('EVENT', $db)) {
310 $retval .= ' <a ' . $ajax_class['edit']
311 . ' href="db_events.php?'
314 . '&item_name=' . urlencode($event['EVENT_NAME'])
315 . '">' . $titles['Edit'] . "</a>\n";
317 $retval .= " {$titles['NoEdit']}\n";
319 $retval .= " </td>\n";
320 $retval .= " <td>\n";
321 $retval .= ' <a ' . $ajax_class['export']
322 . ' href="db_events.php?'
324 . '&export_item=1'
325 . '&item_name=' . urlencode($event['EVENT_NAME'])
326 . '">' . $titles['Export'] . "</a>\n";
327 $retval .= " </td>\n";
328 $retval .= " <td>\n";
329 if (PMA_currentUserHasPrivilege('EVENT', $db)) {
330 $retval .= ' <a ' . $ajax_class['drop']
333 . '&sql_query=' . urlencode($sql_drop)
334 . '&goto=db_events.php' . urlencode("?db={$db}")
335 . '" >' . $titles['Drop'] . "</a>\n";
337 $retval .= " {$titles['NoDrop']}\n";
339 $retval .= " </td>\n";
340 $retval .= " <td>\n";
341 $retval .= " {$event['EVENT_TYPE']}\n";
342 $retval .= " </td>\n";
343 $retval .= " </tr>\n";
346 } // end PMA_EVN_getRowForList()