Export_Relation_Schema.class.php 6.6 KB

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