Minor improvement to prior commit.
[openemr.git] / phpmyadmin / libraries / plugins / schema / Export_Relation_Schema.class.php
blob7faeeb06eb786007df5ba83ebf8895205232127b
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.
7 * @package PhpMyAdmin
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
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
18 * @package PhpMyAdmin
20 class PMA_Export_Relation_Schema
22 /**
23 * Constructor.
25 * @param string $db database name
26 * @param object $diagram schema diagram
28 public function __construct($db, $diagram)
30 $this->db = $db;
31 $this->diagram = $diagram;
32 $this->setPageNumber($_REQUEST['page_number']);
33 $this->setOffline(isset($_REQUEST['offline_export']));
36 protected $db;
37 protected $diagram;
39 protected $showColor;
40 protected $tableDimension;
41 protected $sameWide;
42 protected $showKeys;
43 protected $orientation;
44 protected $paper;
46 protected $pageNumber;
47 protected $offline;
49 /**
50 * Set Page Number
52 * @param integer $value Page Number of the document to be created
54 * @return void
56 public function setPageNumber($value)
58 $this->pageNumber = $value;
61 /**
62 * Returns the schema page number
64 * @return integer schema page number
66 public function getPageNumber()
68 return $this->pageNumber;
71 /**
72 * Sets showColor
74 * @param boolean $value whether to show colors
76 * @return void
78 public function setShowColor($value)
80 $this->showColor = $value;
83 /**
84 * Returns whether to show colors
86 * @return boolean whether to show colors
88 public function isShowColor()
90 return $this->showColor;
93 /**
94 * Set Table Dimension
96 * @param boolean $value show table co-ordinates or not
98 * @return void
100 public function setTableDimension($value)
102 $this->tableDimension = $value;
106 * Returns whether to show table dimensions
108 * @return boolean whether to show table dimensions
110 public function isTableDimension()
112 return $this->tableDimension;
116 * Set same width of All Tables
118 * @param boolean $value set same width of all tables or not
120 * @return void
122 public function setAllTablesSameWidth($value)
124 $this->sameWide = $value;
128 * Returns whether to use same width for all tables or not
130 * @return boolean whether to use same width for all tables or not
132 public function isAllTableSameWidth()
134 return $this->sameWide;
138 * Set Show only keys
140 * @param boolean $value show only keys or not
142 * @return void
144 * @access public
146 public function setShowKeys($value)
148 $this->showKeys = $value;
152 * Returns whether to show keys
154 * @return boolean whether to show keys
156 public function isShowKeys()
158 return $this->showKeys;
162 * Set Orientation
164 * @param string $value Orientation will be portrait or landscape
166 * @return void
168 * @access public
170 public function setOrientation($value)
172 $this->orientation = ($value == 'P') ? 'P' : 'L';
176 * Returns orientation
178 * @return string orientation
180 public function getOrientation()
182 return $this->orientation;
186 * Set type of paper
188 * @param string $value paper type can be A4 etc
190 * @return void
192 * @access public
194 public function setPaper($value)
196 $this->paper = $value;
200 * Returns the paper size
202 * @return string paper size
204 public function getPaper()
206 return $this->paper;
210 * Set whether the document is generated from client side DB
212 * @param boolean $value offline or not
214 * @return void
216 * @access public
218 public function setOffline($value)
220 $this->offline = $value;
224 * Returns whether the client side database is used
226 * @return boolean
228 * @access public
230 public function isOffline()
232 return $this->offline;
236 * Get the table names from the request
238 * @return array an array of table names
240 protected function getTablesFromRequest()
242 $tables = array();
243 $dbLength = mb_strlen($this->db);
244 foreach ($_REQUEST['t_h'] as $key => $value) {
245 if ($value) {
246 $tables[] = mb_substr($key, $dbLength + 1);
249 return $tables;
253 * Returns the file name
255 * @param String $extension file extension
257 * @return string file name
259 protected function getFileName($extension)
261 $filename = $this->db . $extension;
262 // Get the name of this page to use as filename
263 if ($this->pageNumber != -1 && ! $this->offline) {
264 $_name_sql = 'SELECT page_descr FROM '
265 . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.'
266 . PMA_Util::backquote($GLOBALS['cfgRelation']['pdf_pages'])
267 . ' WHERE page_nr = ' . $this->pageNumber;
268 $_name_rs = PMA_queryAsControlUser($_name_sql);
269 $_name_row = $GLOBALS['dbi']->fetchRow($_name_rs);
270 $filename = $_name_row[0] . $extension;
273 return $filename;
277 * Displays an error message
279 * @param integer $pageNumber ID of the chosen page
280 * @param string $type Schema Type
281 * @param string $error_message The error message
283 * @access public
285 * @return void
287 public static function dieSchema($pageNumber, $type = '', $error_message = '')
289 echo "<p><strong>" . __("SCHEMA ERROR: ") . $type . "</strong></p>" . "\n";
290 if (!empty($error_message)) {
291 $error_message = htmlspecialchars($error_message);
293 echo '<p>' . "\n";
294 echo ' ' . $error_message . "\n";
295 echo '</p>' . "\n";
296 echo '<a href="db_designer.php'
297 . PMA_URL_getCommon(array('db' => $GLOBALS['db']))
298 . '&page=' . htmlspecialchars($pageNumber) . '">' . __('Back') . '</a>';
299 echo "\n";
300 exit;