added japanese language
[openemr.git] / phpmyadmin / libraries / pmd_common.php
blob2b3067c9f6a100608a909aefd9c96ffc393cd218
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Common functions for Designer
6 * @package PhpMyAdmin-Designer
7 */
8 /**
9 * Block attempts to directly run this script
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 $GLOBALS['PMD']['STYLE'] = 'default';
17 $cfgRelation = PMA_getRelationsParam();
19 /**
20 * Retrieves table info and stores it in $GLOBALS['PMD']
22 * @return array with table info
24 function PMA_getTablesInfo()
26 $retval = array();
28 $GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
29 $GLOBALS['PMD']['OWNER'] = array();
30 $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array();
32 $tables = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']);
33 // seems to be needed later
34 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
35 $i = 0;
36 foreach ($tables as $one_table) {
37 $GLOBALS['PMD']['TABLE_NAME'][$i]
38 = $GLOBALS['db'] . "." . $one_table['TABLE_NAME'];
39 $GLOBALS['PMD']['OWNER'][$i] = $GLOBALS['db'];
40 $GLOBALS['PMD']['TABLE_NAME_SMALL'][$i] = $one_table['TABLE_NAME'];
42 $GLOBALS['PMD_URL']['TABLE_NAME'][$i]
43 = urlencode($GLOBALS['db'] . "." . $one_table['TABLE_NAME']);
44 $GLOBALS['PMD_URL']['OWNER'][$i] = urlencode($GLOBALS['db']);
45 $GLOBALS['PMD_URL']['TABLE_NAME_SMALL'][$i]
46 = urlencode($one_table['TABLE_NAME']);
48 $GLOBALS['PMD_OUT']['TABLE_NAME'][$i] = htmlspecialchars(
49 $GLOBALS['db'] . "." . $one_table['TABLE_NAME'], ENT_QUOTES
51 $GLOBALS['PMD_OUT']['OWNER'][$i] = htmlspecialchars(
52 $GLOBALS['db'], ENT_QUOTES
54 $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$i] = htmlspecialchars(
55 $one_table['TABLE_NAME'], ENT_QUOTES
58 $GLOBALS['PMD']['TABLE_TYPE'][$i] = strtoupper($one_table['ENGINE']);
60 $DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
61 if ($DF != '') {
62 $retval[$GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i]] = urlencode($DF);
65 $i++;
68 return $retval;
71 /**
72 * Retrieves table column info
74 * @return array table column nfo
76 function PMA_getColumnsInfo()
78 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
79 $tab_column = array();
80 for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) {
81 $fields_rs = $GLOBALS['dbi']->query(
82 $GLOBALS['dbi']->getColumnsSql(
83 $GLOBALS['db'],
84 $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i],
85 null,
86 true
88 null,
89 PMA_DatabaseInterface::QUERY_STORE
91 $tbl_name_i = $GLOBALS['PMD']['TABLE_NAME'][$i];
92 $j = 0;
93 while ($row = $GLOBALS['dbi']->fetchAssoc($fields_rs)) {
94 $tab_column[$tbl_name_i]['COLUMN_ID'][$j] = $j;
95 $tab_column[$tbl_name_i]['COLUMN_NAME'][$j] = $row['Field'];
96 $tab_column[$tbl_name_i]['TYPE'][$j] = $row['Type'];
97 $tab_column[$tbl_name_i]['NULLABLE'][$j] = $row['Null'];
98 $j++;
101 return $tab_column;
105 * Returns JavaScript code for initializing vars
107 * @return string JavaScript code
109 function PMA_getScriptContr()
111 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
112 $con = array();
113 $con["C_NAME"] = array();
114 $i = 0;
115 $alltab_rs = $GLOBALS['dbi']->query(
116 'SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['db']),
117 null,
118 PMA_DatabaseInterface::QUERY_STORE
120 while ($val = @$GLOBALS['dbi']->fetchRow($alltab_rs)) {
121 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
122 //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
123 //print_r($row);
124 if ($row !== false) {
125 foreach ($row as $field => $value) {
126 $con['C_NAME'][$i] = '';
127 $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
128 $con['DCN'][$i] = urlencode($field);
129 $con['STN'][$i] = urlencode(
130 $value['foreign_db'] . "." . $value['foreign_table']
132 $con['SCN'][$i] = urlencode($value['foreign_field']);
133 $i++;
136 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
137 //echo "<br> INNO ";
138 //print_r($row);
139 if ($row !== false) {
140 foreach ($row as $field => $value) {
141 $con['C_NAME'][$i] = '';
142 $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
143 $con['DCN'][$i] = urlencode($field);
144 $con['STN'][$i] = urlencode(
145 $value['foreign_db'] . "." . $value['foreign_table']
147 $con['SCN'][$i] = urlencode($value['foreign_field']);
148 $i++;
153 $ti = 0;
154 $retval = array();
155 for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
156 $c_name_i = $con['C_NAME'][$i];
157 $dtn_i = $con['DTN'][$i];
158 $retval[$ti] = array();
159 $retval[$ti][$c_name_i] = array();
160 if (in_array($dtn_i, $GLOBALS['PMD_URL']["TABLE_NAME"])
161 && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])
163 $retval[$ti][$c_name_i][$dtn_i] = array();
164 $retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = array(
165 0 => $con['STN'][$i],
166 1 => $con['SCN'][$i]
169 $ti++;
171 return $retval;
175 * Returns UNIQUE and PRIMARY indices
177 * @return array unique or primary indices
179 function PMA_getPKOrUniqueKeys()
181 return PMA_getAllKeys(true);
185 * Returns all indices
187 * @param bool $unique_only whether to include only unique ones
189 * @return array indices
191 function PMA_getAllKeys($unique_only = false)
193 include_once './libraries/Index.class.php';
195 $keys = array();
197 foreach ($GLOBALS['PMD']['TABLE_NAME_SMALL'] as $I => $table) {
198 $schema = $GLOBALS['PMD']['OWNER'][$I];
199 // for now, take into account only the first index segment
200 foreach (PMA_Index::getFromTable($table, $schema) as $index) {
201 if ($unique_only && ! $index->isUnique()) {
202 continue;
204 $columns = $index->getColumns();
205 foreach ($columns as $column_name => $dummy) {
206 $keys[$schema . '.' . $table . '.' . $column_name] = 1;
210 return $keys;
214 * Return script to create j_tab and h_tab arrays
216 * @return string
218 function PMA_getScriptTabs()
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 PMA_getTabPos()
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 = $GLOBALS['dbi']->fetchResult(
258 $query,
259 'name',
260 null,
261 $GLOBALS['controllink'],
262 PMA_DatabaseInterface::QUERY_STORE
264 return count($tab_pos) ? $tab_pos : null;
268 * Prepares XML output for js/pmd/ajax.js to display a message
270 * @param string $b b attribute value
271 * @param string $ret Return attribute value
273 * @return void
275 function PMA_returnUpd($b, $ret)
277 // not sure where this was defined...
278 global $K;
280 header("Content-Type: text/xml; charset=utf-8");
281 header("Cache-Control: no-cache");
282 die(
283 '<root act="relation_upd" return="' . $ret . '" b="'
284 . $b . '" K="' . $K . '"></root>'