ExportRelationSchema.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Contains PhpMyAdmin\Plugins\Schema\ExportRelationSchema class which is
  5. * inherited by all schema classes.
  6. *
  7. * @package PhpMyAdmin
  8. */
  9. declare(strict_types=1);
  10. namespace PhpMyAdmin\Plugins\Schema;
  11. use PhpMyAdmin\Relation;
  12. use PhpMyAdmin\Url;
  13. use PhpMyAdmin\Util;
  14. use function rawurldecode;
  15. /**
  16. * This class is inherited by all schema classes
  17. * It contains those methods which are common in them
  18. * it works like factory pattern
  19. *
  20. * @package PhpMyAdmin
  21. */
  22. class ExportRelationSchema
  23. {
  24. protected $db;
  25. protected $diagram;
  26. protected $showColor;
  27. protected $tableDimension;
  28. protected $sameWide;
  29. protected $showKeys;
  30. protected $orientation;
  31. protected $paper;
  32. protected $pageNumber;
  33. protected $offline;
  34. /**
  35. * @var Relation
  36. */
  37. protected $relation;
  38. /**
  39. * Constructor.
  40. *
  41. * @param string $db database name
  42. * @param Pdf\Pdf|Svg\Svg|Eps\Eps|Dia\Dia|Pdf\Pdf|null $diagram schema diagram
  43. */
  44. public function __construct($db, $diagram)
  45. {
  46. $this->db = $db;
  47. $this->diagram = $diagram;
  48. $this->setPageNumber($_REQUEST['page_number']);
  49. $this->setOffline(isset($_REQUEST['offline_export']));
  50. $this->relation = new Relation($GLOBALS['dbi']);
  51. }
  52. /**
  53. * Set Page Number
  54. *
  55. * @param integer $value Page Number of the document to be created
  56. *
  57. * @return void
  58. */
  59. public function setPageNumber($value)
  60. {
  61. $this->pageNumber = intval($value);
  62. }
  63. /**
  64. * Returns the schema page number
  65. *
  66. * @return integer schema page number
  67. */
  68. public function getPageNumber()
  69. {
  70. return $this->pageNumber;
  71. }
  72. /**
  73. * Sets showColor
  74. *
  75. * @param boolean $value whether to show colors
  76. *
  77. * @return void
  78. */
  79. public function setShowColor($value)
  80. {
  81. $this->showColor = $value;
  82. }
  83. /**
  84. * Returns whether to show colors
  85. *
  86. * @return boolean whether to show colors
  87. */
  88. public function isShowColor()
  89. {
  90. return $this->showColor;
  91. }
  92. /**
  93. * Set Table Dimension
  94. *
  95. * @param boolean $value show table co-ordinates or not
  96. *
  97. * @return void
  98. */
  99. public function setTableDimension($value)
  100. {
  101. $this->tableDimension = $value;
  102. }
  103. /**
  104. * Returns whether to show table dimensions
  105. *
  106. * @return boolean whether to show table dimensions
  107. */
  108. public function isTableDimension()
  109. {
  110. return $this->tableDimension;
  111. }
  112. /**
  113. * Set same width of All Tables
  114. *
  115. * @param boolean $value set same width of all tables or not
  116. *
  117. * @return void
  118. */
  119. public function setAllTablesSameWidth($value)
  120. {
  121. $this->sameWide = $value;
  122. }
  123. /**
  124. * Returns whether to use same width for all tables or not
  125. *
  126. * @return boolean whether to use same width for all tables or not
  127. */
  128. public function isAllTableSameWidth()
  129. {
  130. return $this->sameWide;
  131. }
  132. /**
  133. * Set Show only keys
  134. *
  135. * @param boolean $value show only keys or not
  136. *
  137. * @return void
  138. *
  139. * @access public
  140. */
  141. public function setShowKeys($value)
  142. {
  143. $this->showKeys = $value;
  144. }
  145. /**
  146. * Returns whether to show keys
  147. *
  148. * @return boolean whether to show keys
  149. */
  150. public function isShowKeys()
  151. {
  152. return $this->showKeys;
  153. }
  154. /**
  155. * Set Orientation
  156. *
  157. * @param string $value Orientation will be portrait or landscape
  158. *
  159. * @return void
  160. *
  161. * @access public
  162. */
  163. public function setOrientation($value)
  164. {
  165. $this->orientation = $value == 'P' ? 'P' : 'L';
  166. }
  167. /**
  168. * Returns orientation
  169. *
  170. * @return string orientation
  171. */
  172. public function getOrientation()
  173. {
  174. return $this->orientation;
  175. }
  176. /**
  177. * Set type of paper
  178. *
  179. * @param string $value paper type can be A4 etc
  180. *
  181. * @return void
  182. *
  183. * @access public
  184. */
  185. public function setPaper($value)
  186. {
  187. $this->paper = $value;
  188. }
  189. /**
  190. * Returns the paper size
  191. *
  192. * @return string paper size
  193. */
  194. public function getPaper()
  195. {
  196. return $this->paper;
  197. }
  198. /**
  199. * Set whether the document is generated from client side DB
  200. *
  201. * @param boolean $value offline or not
  202. *
  203. * @return void
  204. *
  205. * @access public
  206. */
  207. public function setOffline($value)
  208. {
  209. $this->offline = $value;
  210. }
  211. /**
  212. * Returns whether the client side database is used
  213. *
  214. * @return boolean
  215. *
  216. * @access public
  217. */
  218. public function isOffline()
  219. {
  220. return $this->offline;
  221. }
  222. /**
  223. * Get the table names from the request
  224. *
  225. * @return array an array of table names
  226. */
  227. protected function getTablesFromRequest()
  228. {
  229. $tables = [];
  230. if (isset($_POST['t_tbl'])) {
  231. foreach ($_POST['t_tbl'] as $table) {
  232. $tables[] = rawurldecode($table);
  233. }
  234. }
  235. return $tables;
  236. }
  237. /**
  238. * Returns the file name
  239. *
  240. * @param String $extension file extension
  241. *
  242. * @return string file name
  243. */
  244. protected function getFileName($extension)
  245. {
  246. $filename = $this->db . $extension;
  247. // Get the name of this page to use as filename
  248. if ($this->pageNumber != -1 && ! $this->offline) {
  249. $_name_sql = 'SELECT page_descr FROM '
  250. . Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
  251. . Util::backquote($GLOBALS['cfgRelation']['pdf_pages'])
  252. . ' WHERE page_nr = ' . $this->pageNumber;
  253. $_name_rs = $this->relation->queryAsControlUser($_name_sql);
  254. $_name_row = $GLOBALS['dbi']->fetchRow($_name_rs);
  255. $filename = $_name_row[0] . $extension;
  256. }
  257. return $filename;
  258. }
  259. /**
  260. * Displays an error message
  261. *
  262. * @param integer $pageNumber ID of the chosen page
  263. * @param string $type Schema Type
  264. * @param string $error_message The error message
  265. *
  266. * @access public
  267. *
  268. * @return void
  269. */
  270. public static function dieSchema($pageNumber, $type = '', $error_message = '')
  271. {
  272. echo "<p><strong>" , __("SCHEMA ERROR: ") , $type , "</strong></p>" , "\n";
  273. if (! empty($error_message)) {
  274. $error_message = htmlspecialchars($error_message);
  275. }
  276. echo '<p>' , "\n";
  277. echo ' ' , $error_message , "\n";
  278. echo '</p>' , "\n";
  279. echo '<a href="db_designer.php'
  280. , Url::getCommon(['db' => $GLOBALS['db'], 'server' => $GLOBALS['server']])
  281. , '&page=' . htmlspecialchars($pageNumber) , '">' , __('Back') , '</a>';
  282. echo "\n";
  283. exit;
  284. }
  285. }