rte_general.lib.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * General functions.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Check result
  13. *
  14. * @param resource|bool $result Query result
  15. * @param string $error Error to add
  16. * @param string $createStatement Query
  17. * @param array $errors Errors
  18. *
  19. * @return array
  20. */
  21. function checkResult($result, $error, $createStatement, $errors)
  22. {
  23. if ($result) {
  24. return $errors;
  25. }
  26. // OMG, this is really bad! We dropped the query,
  27. // failed to create a new one
  28. // and now even the backup query does not execute!
  29. // This should not happen, but we better handle
  30. // this just in case.
  31. $errors[] = $error . '<br />'
  32. . __('The backed up query was:')
  33. . "\"" . htmlspecialchars($createStatement) . "\"" . '<br />'
  34. . __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
  35. return $errors;
  36. }
  37. /**
  38. * Send TRI or EVN editor via ajax or by echoing.
  39. *
  40. * @param string $type TRI or EVN
  41. * @param string $mode Editor mode 'add' or 'edit'
  42. * @param array $item Data necessary to create the editor
  43. * @param string $title Title of the editor
  44. * @param string $db Database
  45. * @param string $operation Operation 'change' or ''
  46. *
  47. * @return void
  48. */
  49. function PMA_RTE_sendEditor($type, $mode, $item, $title, $db, $operation = null)
  50. {
  51. if ($item !== false) {
  52. // Show form
  53. if ($type == 'TRI') {
  54. $editor = PMA_TRI_getEditorForm($mode, $item);
  55. } else { // EVN
  56. $editor = PMA_EVN_getEditorForm($mode, $operation, $item);
  57. }
  58. if ($GLOBALS['is_ajax_request']) {
  59. $response = PMA_Response::getInstance();
  60. $response->addJSON('message', $editor);
  61. $response->addJSON('title', $title);
  62. } else {
  63. echo "\n\n<h2>$title</h2>\n\n$editor";
  64. unset($_POST);
  65. }
  66. exit;
  67. } else {
  68. $message = __('Error in processing request:') . ' ';
  69. $message .= sprintf(
  70. PMA_RTE_getWord('not_found'),
  71. htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])),
  72. htmlspecialchars(PMA_Util::backquote($db))
  73. );
  74. $message = PMA_message::error($message);
  75. if ($GLOBALS['is_ajax_request']) {
  76. $response = PMA_Response::getInstance();
  77. $response->isSuccess(false);
  78. $response->addJSON('message', $message);
  79. exit;
  80. } else {
  81. $message->display();
  82. }
  83. }
  84. }