Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / rte / rte_list.lib.php
blob19e8e64b1ee42634d3fb1486433c0f4a6b0bab00
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Common functions for generating lists of Routines, Triggers and Events.
6 * @package phpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
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)
23 global $table;
25 /**
26 * Conditional classes switch the list on or off
28 $class1 = 'hide';
29 $class2 = '';
30 if (! $items) {
31 $class1 = '';
32 $class2 = ' hide';
34 /**
35 * Generate output
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";
48 $retval .= " <tr>\n";
49 switch ($type) {
50 case 'routine':
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";
55 break;
56 case 'trigger':
57 $retval .= " <th>" . __('Name') . "</th>\n";
58 if (empty($table)) {
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";
64 break;
65 case 'event':
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";
70 break;
71 default:
72 break;
74 $retval .= " </tr>\n";
75 $retval .= " <!-- TABLE DATA -->\n";
76 $ct = 0;
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
83 switch ($type) {
84 case 'routine':
85 $retval .= PMA_RTN_getRowForList($item, $rowclass);
86 break;
87 case 'trigger':
88 $retval .= PMA_TRI_getRowForList($item, $rowclass);
89 break;
90 case 'event':
91 $retval .= PMA_EVN_getRowForList($item, $rowclass);
92 break;
93 default:
94 break;
96 $ct++;
98 $retval .= " </table>\n";
99 $retval .= "</fieldset>\n";
100 $retval .= "<!-- LIST OF " . PMA_RTE_getWord('docu') . " END -->\n";
102 return $retval;
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?'
136 . $url_query
137 . '&amp;edit_item=1'
138 . '&amp;item_name=' . urlencode($routine['SPECIFIC_NAME'])
139 . '&amp;' . $type_link
140 . '">' . $titles['Edit'] . "</a>\n";
141 } else {
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'],
155 false
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'
163 continue;
165 $execute_action = 'execute_dialog';
166 break;
168 $retval .= ' <a ' . $ajax_class['exec']
169 . ' href="db_routines.php?'
170 . $url_query
171 . '&amp;' . $execute_action . '=1'
172 . '&amp;item_name=' . urlencode($routine['SPECIFIC_NAME'])
173 . '&amp;' . $type_link
174 . '">' . $titles['Execute'] . "</a>\n";
176 } else {
177 $retval .= " {$titles['NoExecute']}\n";
179 $retval .= " </td>\n";
180 $retval .= " <td>\n";
181 $retval .= ' <a ' . $ajax_class['export']
182 . ' href="db_routines.php?'
183 . $url_query
184 . '&amp;export_item=1'
185 . '&amp;item_name=' . urlencode($routine['SPECIFIC_NAME'])
186 . '&amp;' . $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']
192 . ' href="sql.php?'
193 . $url_query
194 . '&amp;sql_query=' . urlencode($sql_drop)
195 . '&amp;goto=db_routines.php' . urlencode("?db={$db}")
196 . '" >' . $titles['Drop'] . "</a>\n";
197 } else {
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";
209 return $retval;
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";
231 if (empty($table)) {
232 $retval .= " <td>\n";
233 $retval .= " <a href='db_triggers.php?db={$db}"
234 . "&amp;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?'
242 . $url_query
243 . '&amp;edit_item=1'
244 . '&amp;item_name=' . urlencode($trigger['name'])
245 . '">' . $titles['Edit'] . "</a>\n";
246 } else {
247 $retval .= " {$titles['NoEdit']}\n";
249 $retval .= " </td>\n";
250 $retval .= " <td>\n";
251 $retval .= ' <a ' . $ajax_class['export']
252 . ' href="db_triggers.php?'
253 . $url_query
254 . '&amp;export_item=1'
255 . '&amp;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']
261 . ' href="sql.php?'
262 . $url_query
263 . '&amp;sql_query=' . urlencode($trigger['drop'])
264 . '&amp;goto=db_triggers.php' . urlencode("?db={$db}")
265 . '" >' . $titles['Drop'] . "</a>\n";
266 } else {
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";
278 return $retval;
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;
293 $sql_drop = sprintf(
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?'
312 . $url_query
313 . '&amp;edit_item=1'
314 . '&amp;item_name=' . urlencode($event['EVENT_NAME'])
315 . '">' . $titles['Edit'] . "</a>\n";
316 } else {
317 $retval .= " {$titles['NoEdit']}\n";
319 $retval .= " </td>\n";
320 $retval .= " <td>\n";
321 $retval .= ' <a ' . $ajax_class['export']
322 . ' href="db_events.php?'
323 . $url_query
324 . '&amp;export_item=1'
325 . '&amp;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']
331 . ' href="sql.php?'
332 . $url_query
333 . '&amp;sql_query=' . urlencode($sql_drop)
334 . '&amp;goto=db_events.php' . urlencode("?db={$db}")
335 . '" >' . $titles['Drop'] . "</a>\n";
336 } else {
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";
345 return $retval;
346 } // end PMA_EVN_getRowForList()