'', 1 => '', 2 => '', 3 => '', 4 => ''); $parsed_param = PMA_SQP_parse($value); $pos = 0; if (in_array(strtoupper($parsed_param[$pos]['data']), $param_directions)) { $retval[0] = strtoupper($parsed_param[0]['data']); $pos++; } if ($parsed_param[$pos]['type'] == 'alpha_identifier' || $parsed_param[$pos]['type'] == 'quote_backtick') { $retval[1] = PMA_unQuote($parsed_param[$pos]['data']); $pos++; } $depth = 0; $param_length = ''; $param_opts = array(); for ($i=$pos; $i<$parsed_param['len']; $i++) { if (($parsed_param[$i]['type'] == 'alpha_columnType' || $parsed_param[$i]['type'] == 'alpha_functionName') // "CHAR" seems to be mistaken for a function by the parser && $depth == 0) { $retval[2] = strtoupper($parsed_param[$i]['data']); } else if ($parsed_param[$i]['type'] == 'punct_bracket_open_round' && $depth == 0) { $depth = 1; } else if ($parsed_param[$i]['type'] == 'punct_bracket_close_round' && $depth == 1) { $depth = 0; } else if ($depth == 1) { $param_length .= $parsed_param[$i]['data']; } else if ($parsed_param[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_param[$i]['data']) == 'CHARSET' && $depth == 0) { if ($parsed_param[$i+1]['type'] == 'alpha_charset' || $parsed_param[$i+1]['type'] == 'alpha_identifier') { $param_opts[] = strtolower($parsed_param[$i+1]['data']); } } else if ($parsed_param[$i]['type'] == 'alpha_columnAttrib' && $depth == 0) { $param_opts[] = strtoupper($parsed_param[$i]['data']); } } $retval[3] = $param_length; sort($param_opts); $retval[4] = implode(' ', $param_opts); return $retval; } // end PMA_RTN_parseOneParameter() /** * This function looks through the contents of a parsed * SHOW CREATE [PROCEDURE | FUNCTION] query and extracts * information about the routine's parameters. * * @param array $parsed_query Parsed query, returned by by PMA_SQP_parse() * @param string $routine_type Routine type: 'PROCEDURE' or 'FUNCTION' * * @return array Information about the parameteres of a routine. * */ function PMA_RTN_parseAllParameters($parsed_query, $routine_type) { global $param_directions; $retval = array(); $retval['num'] = 0; // First get the list of parameters from the query $buffer = ''; $params = array(); $fetching = false; $depth = 0; for ($i=0; $i<$parsed_query['len']; $i++) { if ($parsed_query[$i]['type'] == 'alpha_reservedWord' && $parsed_query[$i]['data'] == $routine_type) { $fetching = true; } else if ($fetching == true && $parsed_query[$i]['type'] == 'punct_bracket_open_round') { $depth++; if ($depth > 1) { $buffer .= $parsed_query[$i]['data'] . ' '; } } else if ($fetching == true && $parsed_query[$i]['type'] == 'punct_bracket_close_round') { $depth--; if ($depth > 0) { $buffer .= $parsed_query[$i]['data'] . ' '; } else { break; } } else if ($parsed_query[$i]['type'] == 'punct_listsep' && $depth == 1) { $params[] = $buffer; $retval['num']++; $buffer = ''; } else if ($fetching == true && $depth > 0) { $buffer .= $parsed_query[$i]['data'] . ' '; } } if (! empty($buffer)) { $params[] = $buffer; $retval['num']++; } // Now parse each parameter individually foreach ($params as $key => $value) { list($retval['dir'][], $retval['name'][], $retval['type'][], $retval['length'][], $retval['opts'][]) = PMA_RTN_parseOneParameter($value); } // Since some indices of $retval may be still undefined, we fill // them each with an empty array to avoid E_ALL errors in PHP. foreach (array('dir', 'name', 'type', 'length', 'opts') as $key => $index) { if (! isset($retval[$index])) { $retval[$index] = array(); } } return $retval; } // end PMA_RTN_parseAllParameters() /** * This function looks through the contents of a parsed * SHOW CREATE [PROCEDURE | FUNCTION] query and extracts * information about the routine's definer. * * @param array $parsed_query Parsed query, returned by PMA_SQP_parse() * * @return string The definer of a routine. * */ function PMA_RTN_parseRoutineDefiner($parsed_query) { $retval = ''; $fetching = false; for ($i=0; $i<$parsed_query['len']; $i++) { if ($parsed_query[$i]['type'] == 'alpha_reservedWord' && $parsed_query[$i]['data'] == 'DEFINER') { $fetching = true; } else if ($fetching == true && ($parsed_query[$i]['type'] != 'quote_backtick' && substr($parsed_query[$i]['type'], 0, 5) != 'punct')) { break; } else if ($fetching == true && $parsed_query[$i]['type'] == 'quote_backtick') { $retval .= PMA_unQuote($parsed_query[$i]['data']); } else if ($fetching == true && $parsed_query[$i]['type'] == 'punct_user') { $retval .= $parsed_query[$i]['data']; } } return $retval; } // end PMA_RTN_parseRoutineDefiner() /** * This function will generate the values that are required to complete * the "Edit routine" form given the name of a routine. * * @param string $db The database that the routine belogs to. * @param string $name The name of the routine. * @param bool $all Whether to return all data or just * the info about parameters. * * @return array Data necessary to create the routine editor. * */ function PMA_RTN_getRoutineDataFromName($db, $name, $all = true) { global $param_directions, $param_sqldataaccess; $retval = array(); // Build and execute the query $fields = "SPECIFIC_NAME, ROUTINE_TYPE, DTD_IDENTIFIER, " . "ROUTINE_DEFINITION, IS_DETERMINISTIC, SQL_DATA_ACCESS, " . "ROUTINE_COMMENT, SECURITY_TYPE"; $where = "ROUTINE_SCHEMA='" . PMA_sqlAddSlashes($db) . "' " . "AND SPECIFIC_NAME='" . PMA_sqlAddSlashes($name) . "'"; $query = "SELECT $fields FROM INFORMATION_SCHEMA.ROUTINES WHERE $where;"; $routine = PMA_DBI_fetch_single_row($query); if (! $routine) { return false; } // Get required data $retval['name'] = $routine['SPECIFIC_NAME']; $retval['type'] = $routine['ROUTINE_TYPE']; $parsed_query = PMA_SQP_parse( PMA_DBI_get_definition( $db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME'] ) ); $params = PMA_RTN_parseAllParameters($parsed_query, $routine['ROUTINE_TYPE']); $retval['num_params'] = $params['num']; $retval['param_dir'] = $params['dir']; $retval['param_name'] = $params['name']; $retval['param_type'] = $params['type']; $retval['param_length'] = $params['length']; $retval['param_opts_num'] = $params['opts']; $retval['param_opts_text'] = $params['opts']; // Get extra data if ($all) { if ($retval['type'] == 'FUNCTION') { $retval['type_toggle'] = 'PROCEDURE'; } else { $retval['type_toggle'] = 'FUNCTION'; } $retval['returntype'] = ''; $retval['returnlength'] = ''; $retval['returnopts_num'] = ''; $retval['returnopts_text'] = ''; if (! empty($routine['DTD_IDENTIFIER'])) { if (strlen($routine['DTD_IDENTIFIER']) > 63) { // If the DTD_IDENTIFIER string from INFORMATION_SCHEMA is // at least 64 characters, then it may actually have been // chopped because that column is a varchar(64), so we will // parse the output of SHOW CREATE query to get accurate // information about the return variable. $dtd = ''; $fetching = false; for ($i=0; $i<$parsed_query['len']; $i++) { if ($parsed_query[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_query[$i]['data']) == 'RETURNS') { $fetching = true; } else if ($fetching == true && $parsed_query[$i]['type'] == 'alpha_reservedWord') { // We will not be looking for options such as UNSIGNED // or ZEROFILL because there is no way that a numeric // field's DTD_IDENTIFIER can be longer than 64 // characters. We can safely assume that the return // datatype is either ENUM or SET, so we only look // for CHARSET. $word = strtoupper($parsed_query[$i]['data']); if ($word == 'CHARSET' && ($parsed_query[$i+1]['type'] == 'alpha_charset' || $parsed_query[$i+1]['type'] == 'alpha_identifier')) { $dtd .= $word . ' ' . $parsed_query[$i+1]['data']; } break; } else if ($fetching == true) { $dtd .= $parsed_query[$i]['data'] . ' '; } } $routine['DTD_IDENTIFIER'] = $dtd; } $returnparam = PMA_RTN_parseOneParameter($routine['DTD_IDENTIFIER']); $retval['returntype'] = $returnparam[2]; $retval['returnlength'] = $returnparam[3]; $retval['returnopts_num'] = $returnparam[4]; $retval['returnopts_text'] = $returnparam[4]; } $retval['definer'] = PMA_RTN_parseRoutineDefiner($parsed_query); $retval['definition'] = $routine['ROUTINE_DEFINITION']; $retval['isdeterministic'] = ''; if ($routine['IS_DETERMINISTIC'] == 'YES') { $retval['isdeterministic'] = " checked='checked'"; } $retval['securitytype_definer'] = ''; $retval['securitytype_invoker'] = ''; if ($routine['SECURITY_TYPE'] == 'DEFINER') { $retval['securitytype_definer'] = " selected='selected'"; } else if ($routine['SECURITY_TYPE'] == 'INVOKER') { $retval['securitytype_invoker'] = " selected='selected'"; } $retval['sqldataaccess'] = $routine['SQL_DATA_ACCESS']; $retval['comment'] = $routine['ROUTINE_COMMENT']; } return $retval; } // PMA_RTN_getRoutineDataFromName() /** * This function will generate the values that are required to complete the "Add new routine" form * It is especially necessary to handle the 'Add another parameter', 'Remove last parameter' * and 'Change routine type' functionalities when JS is disabled. * * @return array Data necessary to create the routine editor. * */ function PMA_RTN_getRoutineDataFromRequest() { global $_REQUEST, $param_directions, $param_sqldataaccess; $retval = array(); $retval['name'] = ''; if (isset($_REQUEST['routine_name'])) { $retval['name'] = $_REQUEST['routine_name']; } $retval['original_name'] = ''; if (isset($_REQUEST['routine_original_name'])) { $retval['original_name'] = $_REQUEST['routine_original_name']; } $retval['type'] = 'PROCEDURE'; $retval['type_toggle'] = 'FUNCTION'; if (isset($_REQUEST['routine_type']) && $_REQUEST['routine_type'] == 'FUNCTION') { $retval['type'] = 'FUNCTION'; $retval['type_toggle'] = 'PROCEDURE'; } $retval['original_type'] = 'PROCEDURE'; if (isset($_REQUEST['routine_original_type']) && $_REQUEST['routine_original_type'] == 'FUNCTION') { $retval['original_type'] = 'FUNCTION'; } $retval['num_params'] = 0; $retval['param_dir'] = array(); $retval['param_name'] = array(); $retval['param_type'] = array(); $retval['param_length'] = array(); $retval['param_opts_num'] = array(); $retval['param_opts_text'] = array(); if (isset($_REQUEST['routine_param_name']) && isset($_REQUEST['routine_param_type']) && isset($_REQUEST['routine_param_length']) && isset($_REQUEST['routine_param_opts_num']) && isset($_REQUEST['routine_param_opts_text']) && is_array($_REQUEST['routine_param_name']) && is_array($_REQUEST['routine_param_type']) && is_array($_REQUEST['routine_param_length']) && is_array($_REQUEST['routine_param_opts_num']) && is_array($_REQUEST['routine_param_opts_text'])) { if ($_REQUEST['routine_type'] == 'PROCEDURE') { $temp_num_params = 0; $retval['param_dir'] = $_REQUEST['routine_param_dir']; foreach ($retval['param_dir'] as $key => $value) { if (! in_array($value, $param_directions, true)) { $retval['param_dir'][$key] = ''; } $retval['num_params']++; } if ($temp_num_params > $retval['num_params']) { $retval['num_params'] = $temp_num_params; } } $temp_num_params = 0; $retval['param_name'] = $_REQUEST['routine_param_name']; foreach ($retval['param_name'] as $key => $value) { $retval['param_name'][$key] = $value; $temp_num_params++; } if ($temp_num_params > $retval['num_params']) { $retval['num_params'] = $temp_num_params; } $temp_num_params = 0; $retval['param_type'] = $_REQUEST['routine_param_type']; foreach ($retval['param_type'] as $key => $value) { if (! in_array($value, PMA_getSupportedDatatypes(), true)) { $retval['param_type'][$key] = ''; } $temp_num_params++; } if ($temp_num_params > $retval['num_params']) { $retval['num_params'] = $temp_num_params; } $temp_num_params = 0; $retval['param_length'] = $_REQUEST['routine_param_length']; foreach ($retval['param_length'] as $key => $value) { $retval['param_length'][$key] = $value; $temp_num_params++; } if ($temp_num_params > $retval['num_params']) { $retval['num_params'] = $temp_num_params; } $temp_num_params = 0; $retval['param_opts_num'] = $_REQUEST['routine_param_opts_num']; foreach ($retval['param_opts_num'] as $key => $value) { $retval['param_opts_num'][$key] = $value; $temp_num_params++; } if ($temp_num_params > $retval['num_params']) { $retval['num_params'] = $temp_num_params; } $temp_num_params = 0; $retval['param_opts_text'] = $_REQUEST['routine_param_opts_text']; foreach ($retval['param_opts_text'] as $key => $value) { $retval['param_opts_text'][$key] = $value; $temp_num_params++; } if ($temp_num_params > $retval['num_params']) { $retval['num_params'] = $temp_num_params; } } $retval['returntype'] = ''; if (isset($_REQUEST['routine_returntype']) && in_array($_REQUEST['routine_returntype'], PMA_getSupportedDatatypes(), true)) { $retval['returntype'] = $_REQUEST['routine_returntype']; } $retval['returnlength'] = ''; if (isset($_REQUEST['routine_returnlength'])) { $retval['returnlength'] = $_REQUEST['routine_returnlength']; } $retval['returnopts_num'] = ''; if (isset($_REQUEST['routine_returnopts_num'])) { $retval['returnopts_num'] = $_REQUEST['routine_returnopts_num']; } $retval['returnopts_text'] = ''; if (isset($_REQUEST['routine_returnopts_text'])) { $retval['returnopts_text'] = $_REQUEST['routine_returnopts_text']; } $retval['definition'] = ''; if (isset($_REQUEST['routine_definition'])) { $retval['definition'] = $_REQUEST['routine_definition']; } $retval['isdeterministic'] = ''; if (isset($_REQUEST['routine_isdeterministic']) && strtolower($_REQUEST['routine_isdeterministic']) == 'on') { $retval['isdeterministic'] = " checked='checked'"; } $retval['definer'] = ''; if (isset($_REQUEST['routine_definer'])) { $retval['definer'] = $_REQUEST['routine_definer']; } $retval['securitytype_definer'] = ''; $retval['securitytype_invoker'] = ''; if (isset($_REQUEST['routine_securitytype'])) { if ($_REQUEST['routine_securitytype'] === 'DEFINER') { $retval['securitytype_definer'] = " selected='selected'"; } else if ($_REQUEST['routine_securitytype'] === 'INVOKER') { $retval['securitytype_invoker'] = " selected='selected'"; } } $retval['sqldataaccess'] = ''; if (isset($_REQUEST['routine_sqldataaccess']) && in_array($_REQUEST['routine_sqldataaccess'], $param_sqldataaccess, true)) { $retval['sqldataaccess'] = $_REQUEST['routine_sqldataaccess']; } $retval['comment'] = ''; if (isset($_REQUEST['routine_comment'])) { $retval['comment'] = $_REQUEST['routine_comment']; } return $retval; } // end function PMA_RTN_getRoutineDataFromRequest() /** * Creates one row for the parameter table used in the routine editor. * * @param array $routine Data for the routine returned by * PMA_RTN_getRoutineDataFromRequest() or * PMA_RTN_getRoutineDataFromName() * @param mixed $index Either a numeric index of the row being processed * or NULL to create a template row for AJAX request * @param string $class Class used to hide the direction column, if the * row is for a stored function. * * @return string HTML code of one row of parameter table for the routine editor. * */ function PMA_RTN_getParameterRow($routine = array(), $index = null, $class = '') { global $param_directions, $param_opts_num, $titles; if ($index === null) { // template row for AJAX request $i = 0; $index = '%s'; $drop_class = ''; $routine = array( 'param_dir' => array(0 => ''), 'param_name' => array(0 => ''), 'param_type' => array(0 => ''), 'param_length' => array(0 => ''), 'param_opts_num' => array(0 => ''), 'param_opts_text' => array(0 => '') ); } else if (! empty($routine)) { // regular row for routine editor $drop_class = ' hide'; $i = $index; } else { // No input data. This shouldn't happen, // but better be safe than sorry. return ''; } // Create the output $retval = ""; $retval .= " \n"; $retval .= " \n"; $retval .= " $value) { $selected = ""; if (! empty($routine['param_opts_num'][$i]) && $routine['param_opts_num'][$i] == $value) { $selected = " selected='selected'"; } $retval .= "$value"; } $retval .= "\n \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " {$titles['Drop']}\n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; return $retval; } // end PMA_RTN_getParameterRow() /** * Displays a form used to add/edit a routine * * @param string $mode If the editor will be used edit a routine * or add a new one: 'edit' or 'add'. * @param string $operation If the editor was previously invoked with * JS turned off, this will hold the name of * the current operation: 'add', remove', 'change' * @param array $routine Data for the routine returned by * PMA_RTN_getRoutineDataFromRequest() or * PMA_RTN_getRoutineDataFromName() * @param array $errors If the editor was already invoked and there * has been an error while processing the request * this array will hold the errors. * @param bool $is_ajax True, if called from an ajax request * * @return string HTML code for the routine editor. * */ function PMA_RTN_getEditorForm($mode, $operation, $routine, $errors, $is_ajax) { global $db, $titles, $param_directions, $param_sqldataaccess, $param_opts_num; // Escape special characters $need_escape = array( 'original_name', 'name', 'returnlength', 'definition', 'definer', 'comment' ); foreach($need_escape as $key => $index) { $routine[$index] = htmlentities($routine[$index], ENT_QUOTES); } for ($i=0; $i<$routine['num_params']; $i++) { $routine['param_name'][$i] = htmlentities($routine['param_name'][$i], ENT_QUOTES); $routine['param_length'][$i] = htmlentities($routine['param_length'][$i], ENT_QUOTES); } // Handle some logic first if ($operation == 'change') { if ($routine['type'] == 'PROCEDURE') { $routine['type'] = 'FUNCTION'; $routine['type_toggle'] = 'PROCEDURE'; } else { $routine['type'] = 'PROCEDURE'; $routine['type_toggle'] = 'FUNCTION'; } } else if ($operation == 'add' || ($routine['num_params'] == 0 && $mode == 'add' && ! $errors)) { $routine['param_dir'][] = ''; $routine['param_name'][] = ''; $routine['param_type'][] = ''; $routine['param_length'][] = ''; $routine['param_opts_num'][] = ''; $routine['param_opts_text'][] = ''; $routine['num_params']++; } else if ($operation == 'remove') { unset($routine['param_dir'][$routine['num_params']-1]); unset($routine['param_name'][$routine['num_params']-1]); unset($routine['param_type'][$routine['num_params']-1]); unset($routine['param_length'][$routine['num_params']-1]); unset($routine['param_opts_num'][$routine['num_params']-1]); unset($routine['param_opts_text'][$routine['num_params']-1]); $routine['num_params']--; } $disable_remove_parameter = ''; if (! $routine['num_params']) { $disable_remove_parameter = " color: gray;' disabled='disabled"; } $original_routine = ''; if ($mode == 'edit') { $original_routine = "\n" . "\n"; } $isfunction_class = ''; $isprocedure_class = ''; $isfunction_select = ''; $isprocedure_select = ''; if ($routine['type'] == 'PROCEDURE') { $isfunction_class = ' hide'; $isprocedure_select = " selected='selected'"; } else { $isprocedure_class = ' hide'; $isfunction_select = " selected='selected'"; } // Create the output $retval = ""; $retval .= "\n\n"; $retval .= "
\n"; $retval .= "\n"; $retval .= $original_routine; $retval .= PMA_generate_common_hidden_inputs($db) . "\n"; $retval .= "
\n"; $retval .= "" . __('Details') . "\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"; $retval .= "\n"; $retval .= " \n"; $retval .= " \n"; $retval .= "\n"; // parameter handling end $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"; $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"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; return $retval; } // end PMA_RTN_getRowForRoutinesList() /** * Creates a list of available routines for the specified database * * @return string An HTML snippet with the list of routines. * */ function PMA_RTN_getRoutinesList() { global $db; /** * Get the routines */ $columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, `DTD_IDENTIFIER`, `ROUTINE_DEFINITION`"; $where = "ROUTINE_SCHEMA='" . PMA_sqlAddSlashes($db) . "'"; $routines = PMA_DBI_fetch_result("SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;"); /** * Conditional classes switch the list on or off */ $class1 = 'hide'; $class2 = ''; if (! $routines) { $class1 = ''; $class2 = ' hide'; } /** * Generate output */ $retval = ""; $retval .= "\n\n\n\n"; $retval .= "\n"; $retval .= "
\n"; $retval .= " " . __('Routines') . "\n"; $retval .= "
\n"; $retval .= " " . __('There are no routines to display.') . "\n"; $retval .= "
\n"; $retval .= "
" . __('Routine name') . "
" . __('Type') . "\n"; if ($is_ajax) { $retval .= " \n"; } else { $retval .= " \n"; $retval .= "
\n"; $retval .= " {$routine['type']}\n"; $retval .= "
\n"; $retval .= " \n"; } $retval .= "
" . __('Parameters') . "\n"; // parameter handling start $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " \n"; $retval .= " "; for ($i=0; $i<$routine['num_params']; $i++) { // each parameter $retval .= PMA_RTN_getParameterRow($routine, $i, $isprocedure_class); } $retval .= "
" . __('Direction') . "" . __('Name') . "" . __('Type') . "" . __('Length/Values') . "" . __('Options') . " 
\n"; $retval .= "
 \n"; $retval .= " \n"; $retval .= " \n"; $retval .= "
" . __('Return type') . "
" . __('Return length/values') . "\n"; $retval .= "
\n"; $retval .= PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, "routine_returnopts_text", null, $routine['returnopts_text']) . "\n"; $retval .= "
\n"; $retval .= "
" . __('Definition') . "
" . __('Is deterministic') . "
" . __('Definer') . "\n"; $retval .= "
" . __('SQL data access') . "
" . __('Comment') . "\n"; $retval .= "\n"; } $retval .= "\n\n"; $retval .= "\n\n"; return $retval; } // end PMA_RTN_getEditorForm() /** * Creates the HTML code that shows the routine execution dialog. * * @param array $routine Data for the routine returned by * PMA_RTN_getRoutineDataFromName() * @param bool $is_ajax True, if called from an ajax request * * @return string HTML code for the routine execution dialog. * */ function PMA_RTN_getExecuteForm($routine, $is_ajax) { global $db, $cfg; // Escape special characters $routine['name'] = htmlentities($routine['name'], ENT_QUOTES); for ($i=0; $i<$routine['num_params']; $i++) { $routine['param_name'][$i] = htmlentities($routine['param_name'][$i], ENT_QUOTES); } // Create the output $retval = ""; $retval .= "\n\n"; $retval .= "
\n"; $retval .= "\n"; $retval .= PMA_generate_common_hidden_inputs($db) . "\n"; $retval .= "
\n"; if ($is_ajax != true) { $retval .= "{$routine['name']}\n"; $retval .= "\n"; $retval .= "\n"; } else { $retval .= "" . __('Routine parameters') . "\n"; $retval .= "
\n"; $retval .= __('Routine parameters'); $retval .= "
\n"; } $retval .= "\n"; $retval .= "\n"; $retval .= "\n"; if ($cfg['ShowFunctionFields']) { $retval .= "\n"; } $retval .= "\n"; $retval .= "\n"; for ($i=0; $i<$routine['num_params']; $i++) { // Each parameter if ($routine['type'] == 'PROCEDURE' && $routine['param_dir'][$i] == 'OUT') { continue; } $rowclass = ($i % 2 == 0) ? 'even' : 'odd'; $retval .= "\n\n"; $retval .= "\n"; $retval .= "\n"; if ($cfg['ShowFunctionFields']) { $retval .= "\n"; } // Append a class to date/time fields so that // jQuery can attach a datepicker to them $class = ''; if (in_array($routine['param_type'][$i], array('DATETIME', 'TIMESTAMP'))) { $class = 'datetimefield'; } else if ($routine['param_type'][$i] == 'DATE') { $class = 'datefield'; } $retval .= "\n"; $retval .= "\n"; } $retval .= "\n
" . __('Name') . "" . __('Type') . "" . __('Function') . "" . __('Value') . "
{$routine['param_name'][$i]}{$routine['param_type'][$i]}\n"; // Get a list of data types that are not yet supported. $no_support_types = PMA_unsupportedDatatypes(); if (stristr($routine['param_type'][$i], 'enum') || stristr($routine['param_type'][$i], 'set') || in_array(strtolower($routine['param_type'][$i]), $no_support_types)) { $retval .= "--\n"; } else { $field = array( 'True_Type' => strtolower($routine['param_type'][$i]), 'Type' => '', 'Key' => '', 'Field' => '', 'Default' => '', 'first_timestamp' => false ); $retval .= ""; } $retval .= "\n"; if (in_array($routine['param_type'][$i], array('ENUM', 'SET'))) { $tokens = PMA_SQP_parse($routine['param_length'][$i]); if ($routine['param_type'][$i] == 'ENUM') { $input_type = 'radio'; } else { $input_type = 'checkbox'; } for ($j=0; $j<$tokens['len']; $j++) { if ($tokens[$j]['type'] != 'punct_listsep') { $tokens[$j]['data'] = htmlentities(PMA_unquote($tokens[$j]['data']), ENT_QUOTES); $retval .= "" . "{$tokens[$j]['data']}
\n"; } } } else if (in_array(strtolower($routine['param_type'][$i]), $no_support_types)) { $retval .= "\n"; } else { $retval .= "\n"; } $retval .= "
\n"; if ($is_ajax != true) { $retval .= "
\n\n"; $retval .= "
\n"; $retval .= " \n"; $retval .= "
\n"; } else { $retval .= ""; $retval .= ""; } $retval .= "
\n\n"; $retval .= "\n\n"; return $retval; } // end PMA_RTN_getExecuteForm() /** * Composes the query necessary to create a routine from an HTTP request. * * @return string The CREATE [ROUTINE | PROCEDURE] query. * */ function PMA_RTN_getQueryFromRequest() { global $_REQUEST, $cfg, $routine_errors, $param_sqldataaccess; $query = 'CREATE '; if (! empty($_REQUEST['routine_definer']) && strpos($_REQUEST['routine_definer'], '@') !== false) { $arr = explode('@', $_REQUEST['routine_definer']); $query .= 'DEFINER=' . PMA_backquote($arr[0]) . '@' . PMA_backquote($arr[1]) . ' '; } if ($_REQUEST['routine_type'] == 'FUNCTION' || $_REQUEST['routine_type'] == 'PROCEDURE') { $query .= $_REQUEST['routine_type'] . ' '; } else { $routine_errors[] = sprintf(__('Invalid routine type: "%s"'), htmlspecialchars($_REQUEST['routine_type'])); } if (! empty($_REQUEST['routine_name'])) { $query .= PMA_backquote($_REQUEST['routine_name']) . ' '; } else { $routine_errors[] = __('You must provide a routine name'); } $params = ''; $warned_about_dir = false; $warned_about_name = false; $warned_about_length = false; if ( ! empty($_REQUEST['routine_param_name']) && ! empty($_REQUEST['routine_param_type']) && ! empty($_REQUEST['routine_param_length']) && is_array($_REQUEST['routine_param_name']) && is_array($_REQUEST['routine_param_type']) && is_array($_REQUEST['routine_param_length'])) { for ($i=0; $i' . $titles['Edit'] . ''; } if ($routine['ROUTINE_DEFINITION'] !== NULL && PMA_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_getRoutineDataFromName($db, $routine['SPECIFIC_NAME'], false); if ($routine !== false) { $execute_action = 'execute_routine'; for ($i=0; $i<$routine_details['num_params']; $i++) { if ($routine_details['type'] == 'PROCEDURE' && $routine_details['param_dir'][$i] == 'OUT') { continue; } $execute_action = 'execute_dialog'; break; } $execlink = '' . $titles['Execute'] . ''; } } if ($routine['ROUTINE_DEFINITION'] !== NULL) { $exprlink = '' . $titles['Export'] . ''; } if (PMA_currentUserHasPrivilege('ALTER ROUTINE', $db)) { $droplink = '' . $titles['Drop'] . ''; } // Display a row of data $retval = "
\n"; $retval .= " $sql_drop\n"; $retval .= " " . htmlspecialchars($routine['ROUTINE_NAME']) . "\n"; $retval .= " $editlink$execlink$exprlink$droplink{$routine['ROUTINE_TYPE']}" . htmlspecialchars($routine['DTD_IDENTIFIER']) . "
\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 .= PMA_RTN_getRowForRoutinesList($routine, $ct); $ct++; } $retval .= "
" . __('Name') . "" . __('Action') . "" . __('Type') . "" . __('Return type') . "
\n"; $retval .= "
\n"; $retval .= "\n\n"; return $retval; } // end PMA_RTN_getRoutinesList() /** * 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. * */ function PMA_RTN_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 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 PMA_RTN_getAddRoutineLink() ?>