/** * Handles export template actions * * @param array $cfgRelation Relation configuration * * @return void */ function PMA_handleExportTemplateActions($cfgRelation) { if (isset($_REQUEST['templateId'])) { $id = $GLOBALS['dbi']->escapeString($_REQUEST['templateId']); } else { $id = ''; } $templateTable = PMA\libraries\Util::backquote($cfgRelation['db']) . '.' . PMA\libraries\Util::backquote($cfgRelation['export_templates']); $user = $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']); switch ($_REQUEST['templateAction']) { case 'create': $query = "INSERT INTO " . $templateTable . "(" . " `username`, `export_type`," . " `template_name`, `template_data`" . ") VALUES (" . "'" . $user . "', " . "'" . $GLOBALS['dbi']->escapeString($_REQUEST['exportType']) . "', '" . $GLOBALS['dbi']->escapeString($_REQUEST['templateName']) . "', '" . $GLOBALS['dbi']->escapeString($_REQUEST['templateData']) . "');"; break; case 'load': $query = "SELECT `template_data` FROM " . $templateTable . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; case 'update': $query = "UPDATE " . $templateTable . " SET `template_data` = " . "'" . $GLOBALS['dbi']->escapeString($_REQUEST['templateData']) . "'" . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; case 'delete': $query = "DELETE FROM " . $templateTable . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; default: $query = ''; break; } $result = PMA_queryAsControlUser($query, false); $response = Response::getInstance(); if (!$result) { $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']); $response->setRequestStatus(false); $response->addJSON('message', $error); exit; } $response->setRequestStatus(true); if ('create' == $_REQUEST['templateAction']) { $response->addJSON('data', PMA_getOptionsForExportTemplates($_REQUEST['exportType'])); } elseif ('load' == $_REQUEST['templateAction']) { $data = null; while ($row = $GLOBALS['dbi']->fetchAssoc($result, $GLOBALS['controllink'])) { $data = $row['template_data']; } $response->addJSON('data', $data); } $GLOBALS['dbi']->freeResult($result); }
/** * Returns HTML for export template operations * * @param string $export_type export type - server, database, or table * * @return string HTML for export template operations */ function PMA_getHtmlForExportTemplateLoading($export_type) { $html = '<div class="exportoptions" id="export_templates">'; $html .= '<h3>' . __('Export templates:') . '</h3>'; $html .= '<div class="floatleft">'; $html .= '<form method="post" action="tbl_export.php" id="newTemplateForm"' . ' class="ajax">'; $html .= '<h4>' . __('New template:') . '</h4>'; $html .= '<input type="text" name="templateName" id="templateName" ' . 'maxlength="64"' . 'required="required" ' . 'placeholder="' . __('Template name') . '" />'; $html .= '<input type="submit" name="createTemplate" id="createTemplate" ' . 'value="' . __('Create') . '" />'; $html .= '</form>'; $html .= '</div>'; $html .= '<div class="floatleft" style="margin-left: 50px;">'; $html .= '<form method="post" action="tbl_export.php"' . ' id="existingTemplatesForm" class="ajax">'; $html .= '<h4>' . __('Existing templates:') . '</h4>'; $html .= '<label for="template">' . __('Template:') . '</label>'; $html .= '<select required="required" name="template" id="template">'; $html .= PMA_getOptionsForExportTemplates($export_type); $html .= '</select>'; $html .= '<input type="submit" name="updateTemplate" ' . 'id="updateTemplate" value="' . __('Update') . '" />'; $html .= '<input type="submit" name="deleteTemplate" ' . 'id="deleteTemplate" value="' . __('Delete') . '" />'; $html .= '</form>'; $html .= '</div>'; $html .= '<div class="clearfloat"></div>'; $html .= '</div>'; return $html; }
$query = "DELETE FROM " . $templateTable . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; break; default: break; } $result = PMA_queryAsControlUser($query, false); $response = PMA_Response::getInstance(); if (!$result) { $error = $GLOBALS['dbi']->getError($GLOBALS['controllink']); $response->isSuccess(false); $response->addJSON('message', $error); exit; } $response->isSuccess(true); if ('create' == $_REQUEST['templateAction']) { $response->addJSON('data', PMA_getOptionsForExportTemplates($_REQUEST['exportType'])); } elseif ('load' == $_REQUEST['templateAction']) { $data = null; while ($row = $GLOBALS['dbi']->fetchAssoc($result, $GLOBALS['controllink'])) { $data = $row['template_data']; } $response->addJSON('data', $data); } $GLOBALS['dbi']->freeResult($result); exit; } /** * Gets tables information and displays top links */ require_once 'libraries/tbl_common.inc.php'; $url_query .= '&goto=tbl_export.php&back=tbl_export.php';