ExportRelationSchema.php 6.7 KB

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