Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / pmd_common.php
blob5bf7c58bbebcf91c90e3b3f85a97148c20c1994d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package PhpMyAdmin-Designer
5 */
6 /**
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 $GLOBALS['PMD']['STYLE'] = 'default';
15 $cfgRelation = PMA_getRelationsParam();
17 /**
18 * retrieves table info and stores it in $GLOBALS['PMD']
20 * @return array with table info
22 function get_tables_info()
24 $retval = array();
26 $GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
27 $GLOBALS['PMD']['OWNER'] = array();
28 $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array();
30 $tables = PMA_DBI_get_tables_full($GLOBALS['db']);
31 // seems to be needed later
32 PMA_DBI_select_db($GLOBALS['db']);
33 $i = 0;
34 foreach ($tables as $one_table) {
35 $GLOBALS['PMD']['TABLE_NAME'][$i]
36 = $GLOBALS['db'] . "." . $one_table['TABLE_NAME'];
37 $GLOBALS['PMD']['OWNER'][$i] = $GLOBALS['db'];
38 $GLOBALS['PMD']['TABLE_NAME_SMALL'][$i] = $one_table['TABLE_NAME'];
40 $GLOBALS['PMD_URL']['TABLE_NAME'][$i]
41 = urlencode($GLOBALS['db'] . "." . $one_table['TABLE_NAME']);
42 $GLOBALS['PMD_URL']['OWNER'][$i] = urlencode($GLOBALS['db']);
43 $GLOBALS['PMD_URL']['TABLE_NAME_SMALL'][$i]
44 = urlencode($one_table['TABLE_NAME']);
46 $GLOBALS['PMD_OUT']['TABLE_NAME'][$i] = htmlspecialchars(
47 $GLOBALS['db'] . "." . $one_table['TABLE_NAME'], ENT_QUOTES
49 $GLOBALS['PMD_OUT']['OWNER'][$i] = htmlspecialchars(
50 $GLOBALS['db'], ENT_QUOTES
52 $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$i] = htmlspecialchars(
53 $one_table['TABLE_NAME'], ENT_QUOTES
56 $GLOBALS['PMD']['TABLE_TYPE'][$i] = strtoupper($one_table['ENGINE']);
58 $DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
59 if ($DF != '') {
60 $retval[$GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i]] = urlencode($DF);
63 $i++;
66 return $retval;
69 /**
70 * retrieves table column info
72 * @return array table column nfo
74 function get_columns_info()
76 PMA_DBI_select_db($GLOBALS['db']);
77 $tab_column = array();
78 for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) {
79 $fields_rs = PMA_DBI_query(
80 PMA_DBI_get_columns_sql(
81 $GLOBALS['db'],
82 $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i],
83 null,
84 true
86 null,
87 PMA_DBI_QUERY_STORE
89 $tbl_name_i = $GLOBALS['PMD']['TABLE_NAME'][$i];
90 $j = 0;
91 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
92 $tab_column[$tbl_name_i]['COLUMN_ID'][$j] = $j;
93 $tab_column[$tbl_name_i]['COLUMN_NAME'][$j] = $row['Field'];
94 $tab_column[$tbl_name_i]['TYPE'][$j] = $row['Type'];
95 $tab_column[$tbl_name_i]['NULLABLE'][$j] = $row['Null'];
96 $j++;
99 return $tab_column;
103 * returns JavaScript code for intializing vars
105 * @return string JavaScript code
107 function get_script_contr()
109 PMA_DBI_select_db($GLOBALS['db']);
110 $con["C_NAME"] = array();
111 $i = 0;
112 $alltab_rs = PMA_DBI_query(
113 'SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['db']),
114 null,
115 PMA_DBI_QUERY_STORE
117 while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
118 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
119 //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
120 //print_r($row);
121 if ($row !== false) {
122 foreach ($row as $field => $value) {
123 $con['C_NAME'][$i] = '';
124 $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
125 $con['DCN'][$i] = urlencode($field);
126 $con['STN'][$i] = urlencode(
127 $value['foreign_db'] . "." . $value['foreign_table']
129 $con['SCN'][$i] = urlencode($value['foreign_field']);
130 $i++;
133 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
134 //echo "<br> INNO ";
135 //print_r($row);
136 if ($row !== false) {
137 foreach ($row as $field => $value) {
138 $con['C_NAME'][$i] = '';
139 $con['DTN'][$i] = urlencode($GLOBALS['db'].".".$val[0]);
140 $con['DCN'][$i] = urlencode($field);
141 $con['STN'][$i] = urlencode(
142 $value['foreign_db'].".".$value['foreign_table']
144 $con['SCN'][$i] = urlencode($value['foreign_field']);
145 $i++;
150 $ti = 0;
151 $retval = array();
152 for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
153 $c_name_i = $con['C_NAME'][$i];
154 $dtn_i = $con['DTN'][$i];
155 $retval[$ti] = array();
156 $retval[$ti][$c_name_i] = array();
157 if (in_array($dtn_i, $GLOBALS['PMD_URL']["TABLE_NAME"])
158 && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])
160 $retval[$ti][$c_name_i][$dtn_i] = array();
161 $retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = array(
162 0 => $con['STN'][$i],
163 1 => $con['SCN'][$i]
166 $ti++;
168 return $retval;
172 * Returns UNIQUE and PRIMARY indices
174 * @return array unique or primary indices
176 function get_pk_or_unique_keys()
178 return get_all_keys(true);
182 * returns all indices
184 * @param bool $unique_only whether to include only unique ones
186 * @return array indices
188 function get_all_keys($unique_only = false)
190 include_once './libraries/Index.class.php';
192 $keys = array();
194 foreach ($GLOBALS['PMD']['TABLE_NAME_SMALL'] as $I => $table) {
195 $schema = $GLOBALS['PMD']['OWNER'][$I];
196 // for now, take into account only the first index segment
197 foreach (PMA_Index::getFromTable($table, $schema) as $index) {
198 if ($unique_only && ! $index->isUnique()) {
199 continue;
201 $columns = $index->getColumns();
202 foreach ($columns as $column_name => $dummy) {
203 $keys[$schema . '.' .$table . '.' . $column_name] = 1;
207 return $keys;
211 * Return script to create j_tab and h_tab arrays
213 * @return string
215 function get_script_tabs()
217 $script_tabs = 'var j_tabs = new Array();' . "\n"
218 . 'var h_tabs = new Array();' . "\n" ;
220 $retval = array(
221 'j_tabs' => array(),
222 'h_tabs' => array()
225 for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
226 $j = 0;
227 if (PMA_Util::isForeignKeySupported($GLOBALS['PMD']['TABLE_TYPE'][$i])) {
228 $j = 1;
230 $retval['j_tabs'][$GLOBALS['PMD_URL']['TABLE_NAME'][$i]] = $j;
231 $retval['h_tabs'][$GLOBALS['PMD_URL']['TABLE_NAME'][$i]] = 1;
233 return $retval;
237 * Returns table position
239 * @return array table positions and sizes
241 function get_tab_pos()
243 $cfgRelation = PMA_getRelationsParam();
245 if (! $cfgRelation['designerwork']) {
246 return null;
249 $query = "
250 SELECT CONCAT_WS('.', `db_name`, `table_name`) AS `name`,
251 `x` AS `X`,
252 `y` AS `Y`,
253 `v` AS `V`,
254 `h` AS `H`
255 FROM " . PMA_Util::backquote($cfgRelation['db'])
256 . "." . PMA_Util::backquote($cfgRelation['designer_coords']);
257 $tab_pos = PMA_DBI_fetch_result(
258 $query, 'name', null, $GLOBALS['controllink'], PMA_DBI_QUERY_STORE
260 return count($tab_pos) ? $tab_pos : null;