diff --git a/libraries/db_routines.inc.php b/libraries/db_routines.inc.php index 293f479e35..d1a3f55dba 100644 --- a/libraries/db_routines.inc.php +++ b/libraries/db_routines.inc.php @@ -1111,7 +1111,7 @@ function createQueryFromRequest() { * @uses getFormInputFromRoutineName() * @uses urlencode() */ -function routineMakeRowForList($routine, $ct = 0) { +function getRowForListOfRoutines($routine, $ct = 0) { global $titles, $db, $url_query, $ajax_class; // Do the logic first @@ -1176,7 +1176,99 @@ function routineMakeRowForList($routine, $ct = 0) { $retval .= " {$routine['DTD_IDENTIFIER']}\n"; $retval .= " \n"; return $retval; -} // end routineMakeRowForList() +} // end getRowForListOfRoutines() + +/** + * Creates a list of available routines for the specified database + * + * @return string An HTML snippet with the list of routines. + * + * @uses PMA_sqlAddslashes() + * @uses PMA_DBI_fetch_result() + * @uses getRowForListOfRoutines() + */ +function getListOfRoutines() +{ + global $db; + + /** + * Get the routines + */ + $columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, `DTD_IDENTIFIER`, `ROUTINE_DEFINITION`"; + $where = "ROUTINE_SCHEMA='" . PMA_sqlAddslashes($db,true) . "'"; + $routines = PMA_DBI_fetch_result("SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;"); + + /** + * Generate output + */ + $retval = ""; + $retval .= "\n\n\n\n"; + $retval .= "\n"; + $retval .= "
\n"; + $retval .= " " . __('Routines') . "\n"; + if (! $routines) { + $retval .= " " . __('There are no routines to display.') . "\n"; + } else { + $retval .= "
\n"; + $retval .= " " . __('There are no routines to display.') . "\n"; + $retval .= "
\n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $retval .= " \n"; + $ct = 0; + // Display each routine + foreach ($routines as $routine) { + $retval .= getRowForListOfRoutines($routine, $ct); + $ct++; + } + $retval .= "
" . __('Name') . "    " . __('Type') . "" . __('Return type') . "
\n"; + } + $retval .= "
\n"; + $retval .= "\n\n"; + + return $retval; +} // end getListOfRoutines() + +/** + * Creates a fieldset for adding a new routine, if the user has the privileges. + * + * @return string An HTML snippet with the link to add a new routine. + * + * @uses PMA_currentUserHasPrivilege() + * @uses PMA_getIcon() + * @uses PMA_showMySQLDocu() + */ +function getAddRoutineLink() +{ + global $db, $url_query, $ajax_class; + + $retval = ""; + $retval .= "\n"; + $retval .= "
\n"; + if (PMA_currentUserHasPrivilege('CREATE ROUTINE', $db)) { + $retval .= "\n"; + $retval .= PMA_getIcon('b_routine_add.png') . "\n"; + $retval .= __('Add a new Routine') . "\n"; + } else { + $retval .= PMA_getIcon('b_routine_add.png') . "\n"; + $retval .= __('You do not have the necessary privileges to create a new Routine') . "\n"; + } + $retval .= PMA_showMySQLDocu('SQL-Syntax', 'CREATE_PROCEDURE') . "\n"; + $retval .= "
\n"; + $retval .= "\n\n"; + + return $retval; +} // end getAddRoutineLink() /** * ### MAIN ########################################################################################################## @@ -1452,7 +1544,7 @@ if (! empty($_REQUEST['execute_routine']) && ! empty($_REQUEST['routine_name'])) $where = "ROUTINE_SCHEMA='" . PMA_sqlAddslashes($db,true) . "' AND ROUTINE_NAME='" . PMA_sqlAddslashes($_REQUEST['routine_name'],true) . "'"; $routine = PMA_DBI_fetch_single_row("SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;"); $extra_data['name'] = htmlspecialchars(strtoupper($_REQUEST['routine_name'])); - $extra_data['new_row'] = routineMakeRowForList($routine); + $extra_data['new_row'] = getRowForListOfRoutines($routine); $extra_data['sql_query'] = $output; $response = PMA_message::success(); } else { @@ -1509,6 +1601,7 @@ if (count($routine_errors) || ( empty($_REQUEST['routine_process_addroutine']) & // Show form $editor = displayRoutineEditor($mode, $operation, $routine, $routine_errors, $GLOBALS['is_ajax_request']); if ($GLOBALS['is_ajax_request']) { + // TODO: this needs to be refactored $template = " \n"; $template .= "