Footer.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Common functions for generating the footer for Routines, Triggers and Events.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Rte;
  9. use PhpMyAdmin\Rte\Words;
  10. use PhpMyAdmin\Util;
  11. /**
  12. * PhpMyAdmin\Rte\Footer class
  13. *
  14. * @package PhpMyAdmin
  15. */
  16. class Footer
  17. {
  18. /**
  19. * Creates a fieldset for adding a new item, if the user has the privileges.
  20. *
  21. * @param string $docu String used to create a link to the MySQL docs
  22. * @param string $priv Privilege to check for adding a new item
  23. * @param string $name MySQL name of the item
  24. *
  25. * @return string An HTML snippet with the link to add a new item
  26. */
  27. private static function getLinks($docu, $priv, $name)
  28. {
  29. global $db, $table, $url_query;
  30. $icon = mb_strtolower($name) . '_add';
  31. $retval = "";
  32. $retval .= "<!-- ADD " . $name . " FORM START -->\n";
  33. $retval .= "<fieldset class='left'>\n";
  34. $retval .= "<legend>" . _pgettext('Create new procedure', 'New') . "</legend>\n";
  35. $retval .= " <div class='wrap'>\n";
  36. if (Util::currentUserHasPrivilege($priv, $db, $table)) {
  37. $retval .= ' <a class="ajax add_anchor" ';
  38. $retval .= "href='db_" . mb_strtolower($name) . "s.php";
  39. $retval .= "$url_query&amp;add_item=1' ";
  40. $retval .= "onclick='$.datepicker.initialized = false;'>";
  41. $icon = 'b_' . $icon;
  42. $retval .= Util::getIcon($icon);
  43. $retval .= Words::get('add') . "</a>\n";
  44. } else {
  45. $icon = 'bd_' . $icon;
  46. $retval .= Util::getIcon($icon);
  47. $retval .= Words::get('add') . "\n";
  48. }
  49. $retval .= " " . Util::showMySQLDocu($docu) . "\n";
  50. $retval .= " </div>\n";
  51. $retval .= "</fieldset>\n";
  52. $retval .= "<!-- ADD " . $name . " FORM END -->\n\n";
  53. return $retval;
  54. } // end self::getLinks()
  55. /**
  56. * Creates a fieldset for adding a new routine, if the user has the privileges.
  57. *
  58. * @return string HTML code with containing the footer fieldset
  59. */
  60. public static function routines()
  61. {
  62. return self::getLinks('CREATE_PROCEDURE', 'CREATE ROUTINE', 'ROUTINE');
  63. }// end self::routines()
  64. /**
  65. * Creates a fieldset for adding a new trigger, if the user has the privileges.
  66. *
  67. * @return string HTML code with containing the footer fieldset
  68. */
  69. public static function triggers()
  70. {
  71. return self::getLinks('CREATE_TRIGGER', 'TRIGGER', 'TRIGGER');
  72. } // end self::triggers()
  73. /**
  74. * Creates a fieldset for adding a new event, if the user has the privileges.
  75. *
  76. * @return string HTML code with containing the footer fieldset
  77. */
  78. public static function events()
  79. {
  80. global $db, $url_query;
  81. /**
  82. * For events, we show the usual 'Add event' form and also
  83. * a form for toggling the state of the event scheduler
  84. */
  85. // Init options for the event scheduler toggle functionality
  86. $es_state = $GLOBALS['dbi']->fetchValue(
  87. "SHOW GLOBAL VARIABLES LIKE 'event_scheduler'",
  88. 0,
  89. 1
  90. );
  91. $es_state = mb_strtolower($es_state);
  92. $options = array(
  93. 0 => array(
  94. 'label' => __('OFF'),
  95. 'value' => "SET GLOBAL event_scheduler=\"OFF\"",
  96. 'selected' => ($es_state != 'on')
  97. ),
  98. 1 => array(
  99. 'label' => __('ON'),
  100. 'value' => "SET GLOBAL event_scheduler=\"ON\"",
  101. 'selected' => ($es_state == 'on')
  102. )
  103. );
  104. // Generate output
  105. $retval = "<!-- FOOTER LINKS START -->\n";
  106. $retval .= "<div class='doubleFieldset'>\n";
  107. // show the usual footer
  108. $retval .= self::getLinks('CREATE_EVENT', 'EVENT', 'EVENT');
  109. $retval .= " <fieldset class='right'>\n";
  110. $retval .= " <legend>\n";
  111. $retval .= " " . __('Event scheduler status') . "\n";
  112. $retval .= " </legend>\n";
  113. $retval .= " <div class='wrap'>\n";
  114. // show the toggle button
  115. $retval .= Util::toggleButton(
  116. "sql.php$url_query&amp;goto=db_events.php" . urlencode("?db=$db"),
  117. 'sql_query',
  118. $options,
  119. 'PMA_slidingMessage(data.sql_query);'
  120. );
  121. $retval .= " </div>\n";
  122. $retval .= " </fieldset>\n";
  123. $retval .= " <div class='clearfloat'></div>\n";
  124. $retval .= "</div>";
  125. $retval .= "<!-- FOOTER LINKS END -->\n";
  126. return $retval;
  127. } // end self::events()
  128. }