General.php 3.0 KB

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