diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index dd858b28db..c900d96ef4 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -1107,3 +1107,78 @@ function PMA_getExportDisplay( $html .= ''; return $html; } + +/** + * Handles export template actions + * + * @param array $cfgRelation Relation configuration + * + * @return void + */ +function PMA_handleExportTemplateActions($cfgRelation) +{ + if (isset($_REQUEST['templateId'])) { + $templateId = $_REQUEST['templateId']; + $id = PMA\libraries\Util::sqlAddSlashes($templateId); + } + + $templateTable = PMA\libraries\Util::backquote($cfgRelation['db']) . '.' + . PMA\libraries\Util::backquote($cfgRelation['export_templates']); + $user = PMA\libraries\Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']); + + switch ($_REQUEST['templateAction']) { + case 'create': + $query = "INSERT INTO " . $templateTable . "(" + . " `username`, `export_type`," + . " `template_name`, `template_data`" + . ") VALUES (" + . "'" . $user . "', " + . "'" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['exportType']) + . "', '" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateName']) + . "', '" . PMA\libraries\Util::sqlAddSlashes($_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` = " + . "'" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateData']) . "'" + . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; + break; + case 'delete': + $query = "DELETE FROM " . $templateTable + . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; + break; + default: + break; + } + + $result = PMA_queryAsControlUser($query, false); + + $response = PMA\libraries\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); +} diff --git a/tbl_export.php b/tbl_export.php index 5831971a5c..deac625dc9 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -28,71 +28,7 @@ $cfgRelation = PMA_getRelationsParam(); // handling export template actions if (isset($_REQUEST['templateAction']) && $cfgRelation['exporttemplateswork']) { - - if (isset($_REQUEST['templateId'])) { - $templateId = $_REQUEST['templateId']; - $id = PMA\libraries\Util::sqlAddSlashes($templateId); - } - - $templateTable = PMA\libraries\Util::backquote($cfgRelation['db']) . '.' - . PMA\libraries\Util::backquote($cfgRelation['export_templates']); - $user = PMA\libraries\Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']); - - switch ($_REQUEST['templateAction']) { - case 'create': - $query = "INSERT INTO " . $templateTable . "(" - . " `username`, `export_type`," - . " `template_name`, `template_data`" - . ") VALUES (" - . "'" . $user . "', " - . "'" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['exportType']) - . "', '" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateName']) - . "', '" . PMA\libraries\Util::sqlAddSlashes($_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` = " - . "'" . PMA\libraries\Util::sqlAddSlashes($_REQUEST['templateData']) . "'" - . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; - break; - case 'delete': - $query = "DELETE FROM " . $templateTable - . " WHERE `id` = " . $id . " AND `username` = '" . $user . "'"; - break; - default: - break; - } - - $result = PMA_queryAsControlUser($query, false); - - $response = PMA\libraries\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); + PMA_handleExportTemplateActions($cfgRelation); exit; }