Exemple #1
0
/**
 * Replace the placeholders in the bookmark query with variables
 *
 * @param string $query bookmarked query
 *
 * @return string query with variables applied
 */
function PMA_Bookmark_applyVariables($query)
{
    // remove comments that encloses a variable placeholder
    $query = preg_replace('|/\\*(.*\\[VARIABLE[0-9]*\\].*)\\*/|imsU', '${1}', $query);
    // replace variable placeholders with values
    $number_of_variables = PMA_Bookmark_getVariableCount($query);
    for ($i = 1; $i <= $number_of_variables; $i++) {
        $var = '';
        if (!empty($_REQUEST['bookmark_variable'][$i])) {
            $var = $GLOBALS['dbi']->escapeString($_REQUEST['bookmark_variable'][$i]);
        }
        $query = str_replace('[VARIABLE' . $i . ']', $var, $query);
        // backward compatibility
        if ($i == 1) {
            $query = str_replace('[VARIABLE]', $var, $query);
        }
    }
    return $query;
}
/**
 * return HTML for sql Query Form Bookmark
 *
 * @return string|null
 *
 * @usedby  PMA_getHtmlForSqlQueryForm()
 */
function PMA_getHtmlForSqlQueryFormBookmark()
{
    $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
    if (!$bookmark_list || count($bookmark_list) < 1) {
        return null;
    }
    $html = '<fieldset id="fieldsetBookmarkOptions">';
    $html .= '<legend>';
    $html .= __('Bookmarked SQL query') . '</legend>' . "\n";
    $html .= '<div class="formelement">';
    $html .= '<select name="id_bookmark" id="id_bookmark">' . "\n";
    $html .= '<option value="">&nbsp;</option>' . "\n";
    foreach ($bookmark_list as $key => $value) {
        $html .= '<option value="' . htmlspecialchars($key) . '"' . ' data-varcount="' . PMA_Bookmark_getVariableCount($value['query']) . '">' . htmlspecialchars($value['label']) . '</option>' . "\n";
    }
    // &nbsp; is required for correct display with styles/line height
    $html .= '</select>&nbsp;' . "\n";
    $html .= '</div>' . "\n";
    $html .= '<div class="formelement">' . "\n";
    $html .= '<input type="radio" name="action_bookmark" value="0"' . ' id="radio_bookmark_exe" checked="checked" />' . '<label for="radio_bookmark_exe">' . __('Submit') . '</label>' . "\n";
    $html .= '<input type="radio" name="action_bookmark" value="1"' . ' id="radio_bookmark_view" />' . '<label for="radio_bookmark_view">' . __('View only') . '</label>' . "\n";
    $html .= '<input type="radio" name="action_bookmark" value="2"' . ' id="radio_bookmark_del" />' . '<label for="radio_bookmark_del">' . __('Delete') . '</label>' . "\n";
    $html .= '</div>' . "\n";
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '<div class="formelement hide">' . "\n";
    $html .= __('Variables');
    $html .= PMA_Util::showDocu('faq', 'faqbookmark');
    $html .= '<div id="bookmark_variables"></div>';
    $html .= '</div>' . "\n";
    $html .= '</fieldset>' . "\n";
    $html .= '<fieldset id="fieldsetBookmarkOptionsFooter" class="tblFooters">';
    $html .= '<input type="submit" name="SQL" id="button_submit_bookmark" value="' . __('Go') . '" />';
    $html .= '<div class="clearfloat"></div>' . "\n";
    $html .= '</fieldset>' . "\n";
    return $html;
}
/**
 * Replace the placeholders in the bookmark query with variables
 *
 * @param string $query     bookmarked query
 * @param array  $variables variables to apply
 *
 * @return string query with variables applied
 */
function PMA_Bookmark_applyVariables($query, $variables)
{
    // remove comments that encloses a variable placeholder
    $query = preg_replace('|/\\*(.*\\[VARIABLE[0-9]*\\].*)\\*/|imsU', '${1}', $query);
    // replace variable placeholders with values
    for ($i = 1; $i <= PMA_Bookmark_getVariableCount($query); $i++) {
        $var = '';
        if (!empty($_REQUEST['bookmark_variable'][$i])) {
            $var = PMA_Util::sqlAddSlashes($_REQUEST['bookmark_variable'][$i]);
        }
        $query = str_replace('[VARIABLE' . $i . ']', $var, $query);
        // backward compatibility
        if ($i == 1) {
            $query = str_replace('[VARIABLE]', $var, $query);
        }
    }
    return $query;
}