Translation update done using Pootle.
[phpmyadmin/dkf.git] / pmd_common.php
blob2cb2213ce433bed8cb01daac442cebf51f939a51
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @package phpMyAdmin-Designer
5 */
7 /**
9 */
10 require_once './libraries/common.inc.php';
11 // not understand
12 require_once './libraries/header_http.inc.php';
14 $GLOBALS['PMD']['STYLE'] = 'default';
16 $cfgRelation = PMA_getRelationsParam();
18 $GLOBALS['script_display_field'] =
19 '<script type="text/javascript">' . "\n" .
20 '// <![CDATA[' . "\n" .
21 'var display_field = new Array();' . "\n";
23 /**
24 * retrieves table info and stores it in $GLOBALS['PMD']
26 * @uses $GLOBALS['script_display_field']
27 * @uses $GLOBALS['PMD'] to fill it
28 * @uses $GLOBALS['db']
29 * @uses PMA_DBI_get_tables_full()
30 * @uses PMA_DBI_select_db()
31 * @uses PMA_getDisplayField()
32 * @uses urlencode()
33 * @uses htmlspecialchars()
34 * @uses strtoupper()
35 * @uses urlencode()
37 function get_tabs()
39 $GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
40 $GLOBALS['PMD']['OWNER'] = array();
41 $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array();
43 $tables = PMA_DBI_get_tables_full($GLOBALS['db']);
44 // seems to be needed later
45 PMA_DBI_select_db($GLOBALS['db']);
46 $i = 0;
47 foreach ($tables as $one_table) {
48 $GLOBALS['PMD']['TABLE_NAME'][$i] = $GLOBALS['db'] . "." . $one_table['TABLE_NAME'];
49 $GLOBALS['PMD']['OWNER'][$i] = $GLOBALS['db'];
50 $GLOBALS['PMD']['TABLE_NAME_SMALL'][$i] = $one_table['TABLE_NAME'];
52 $GLOBALS['PMD_URL']['TABLE_NAME'][$i] = urlencode($GLOBALS['db'] . "." . $one_table['TABLE_NAME']);
53 $GLOBALS['PMD_URL']['OWNER'][$i] = urlencode($GLOBALS['db']);
54 $GLOBALS['PMD_URL']['TABLE_NAME_SMALL'][$i] = urlencode($one_table['TABLE_NAME']);
56 $GLOBALS['PMD_OUT']['TABLE_NAME'][$i] = htmlspecialchars($GLOBALS['db'] . "." . $one_table['TABLE_NAME'], ENT_QUOTES);
57 $GLOBALS['PMD_OUT']['OWNER'][$i] = htmlspecialchars($GLOBALS['db'], ENT_QUOTES);
58 $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$i] = htmlspecialchars($one_table['TABLE_NAME'], ENT_QUOTES);
60 $GLOBALS['PMD']['TABLE_TYPE'][$i] = strtoupper($one_table['ENGINE']);
62 $DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
63 if ($DF != '') {
64 $GLOBALS['script_display_field'] .= " display_field['"
65 . $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . "'] = '"
66 . urlencode($DF) . "';\n";
69 $i++;
72 $GLOBALS['script_display_field'] .=
73 '// ]]>' . "\n" .
74 '</script>' . "\n";
75 // return $GLOBALS['PMD']; // many bases // not use ??????
78 /**
79 * retrieves table column info
81 * @uses $GLOBALS['db']
82 * @uses PMA_DBI_QUERY_STORE
83 * @uses PMA_DBI_select_db()
84 * @uses PMA_DBI_query()
85 * @uses PMA_DBI_num_rows()
86 * @uses PMA_backquote()
87 * @uses count()
88 * @return array table column nfo
90 function get_tab_info()
92 PMA_DBI_select_db($GLOBALS['db']);
93 $tab_column = array();
94 for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) {
95 $fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM '.PMA_backquote($GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]), NULL, PMA_DBI_QUERY_STORE);
96 $j = 0;
97 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
98 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_ID'][$j] = $j;
99 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_NAME'][$j] = $row['Field'];
100 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['TYPE'][$j] = $row['Type'];
101 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['NULLABLE'][$j] = $row['Null'];
102 $j++;
105 return $tab_column;
109 * returns JavaScript code for intializing vars
111 * @uses $GLOBALS['db']
112 * @uses PMA_DBI_QUERY_STORE
113 * @uses PMA_DBI_select_db()
114 * @uses PMA_DBI_query()
115 * @uses PMA_backquote()
116 * @uses PMA_DBI_fetch_row()
117 * @uses PMA_getForeigners()
118 * @uses urlencode()
119 * @uses count()
120 * @uses in_array()
121 * @return string JavaScript code
123 function get_script_contr()
125 PMA_DBI_select_db($GLOBALS['db']);
126 $con["C_NAME"] = array();
127 $i = 0;
128 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($GLOBALS['db']), NULL, PMA_DBI_QUERY_STORE);
129 while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
130 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
131 //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
132 //print_r($row);
133 if ($row !== false) {
134 foreach ($row as $field => $value) {
135 $con['C_NAME'][$i] = '';
136 $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
137 $con['DCN'][$i] = urlencode($field);
138 $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
139 $con['SCN'][$i] = urlencode($value['foreign_field']);
140 $i++;
143 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
144 //echo "<br> INNO ";
145 //print_r($row);
146 if ($row !== false) {
147 foreach ($row as $field => $value) {
148 $con['C_NAME'][$i] = '';
149 $con['DTN'][$i] = urlencode($GLOBALS['db'].".".$val[0]);
150 $con['DCN'][$i] = urlencode($field);
151 $con['STN'][$i] = urlencode($value['foreign_db'].".".$value['foreign_table']);
152 $con['SCN'][$i] = urlencode($value['foreign_field']);
153 $i++;
158 $ti = 0;
159 $script_contr =
160 '<script type="text/javascript">' . "\n" .
161 '// <![CDATA[' . "\n" .
162 'var contr = new Array();' . "\n";
163 for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
164 $js_var = ' contr[' . $ti . ']';
165 $script_contr .= $js_var . " = new Array();\n";
166 $js_var .= "['" . $con['C_NAME'][$i] . "']";
167 $script_contr .= $js_var . " = new Array();\n";
168 if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])
169 && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
170 $js_var .= "['" . $con['DTN'][$i] . "']";
171 $script_contr .= $js_var . " = new Array();\n";
172 $m_col = array();//}
173 $js_var .= "['" . $con['DCN'][$i] . "']";
174 $script_contr .= $js_var . " = new Array();\n";//}
175 $script_contr .= $js_var . "[0] = '" . $con['STN'][$i] . "';\n"; //
176 $script_contr .= $js_var . "[1] = '" . $con['SCN'][$i] . "';\n"; //
178 $ti++;
180 $script_contr .=
181 '// ]]>' . "\n" .
182 '</script>' . "\n";
183 return $script_contr;
187 * @uses get_all_keys()
188 * @return array unique or primary indizes
190 function get_pk_or_unique_keys()
192 return get_all_keys(true);
196 * returns all indizes
198 * @uses $GLOBALS['PMD']
199 * @uses PMA_Index::getFromTable()
200 * @uses PMA_Index->isUnique()
201 * @uses PMA_Index->getColumns()
202 * @param boolean whether to include ony unique ones
203 * @return array indizes
205 function get_all_keys($unique_only = false)
207 require_once './libraries/Index.class.php';
209 $keys = array();
211 foreach ($GLOBALS['PMD']['TABLE_NAME_SMALL'] as $I => $table) {
212 $schema = $GLOBALS['PMD']['OWNER'][$I];
213 // for now, take into account only the first index segment
214 foreach (PMA_Index::getFromTable($table, $schema) as $index) {
215 if ($unique_only && ! $index->isUnique()) {
216 continue;
218 $columns = $index->getColumns();
219 foreach ($columns as $column_name => $dummy) {
220 $keys[$schema . '.' .$table . '.' . $column_name] = 1;
224 return $keys;
230 * @uses $GLOBALS['PMD']
231 * @uses count()
232 * @uses in_array()
233 * @return array ???
235 function get_script_tabs()
237 $script_tabs =
238 '<script type="text/javascript">' . "\n" .
239 '// <![CDATA[' . "\n" .
240 'var j_tabs = new Array();' . "\n";
241 for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
242 $script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '"
243 . (PMA_foreignkey_supported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0') . "';\n";
245 $script_tabs .=
246 '// ]]>' . "\n" .
247 '</script>' . "\n";
248 return $script_tabs;
252 * @uses $GLOBALS['controllink']
253 * @uses $cfgRelation['designerwork']
254 * @uses $cfgRelation['db']
255 * @uses $cfgRelation['designer_coords']
256 * @uses PMA_DBI_QUERY_STORE
257 * @uses PMA_getRelationsParam()
258 * @uses PMA_backquote()
259 * @uses PMA_DBI_fetch_result()
260 * @uses count()
261 * @return array table positions and sizes
263 function get_tab_pos()
265 $cfgRelation = PMA_getRelationsParam();
267 if (! $cfgRelation['designerwork']) {
268 return null;
271 $query = "
272 SELECT CONCAT_WS('.', `db_name`, `table_name`) AS `name`,
273 `x` AS `X`,
274 `y` AS `Y`,
275 `v` AS `V`,
276 `h` AS `H`
277 FROM " . PMA_backquote($cfgRelation['db']) . "." . PMA_backquote($cfgRelation['designer_coords']);
278 $tab_pos = PMA_DBI_fetch_result($query, 'name', null, $GLOBALS['controllink'], PMA_DBI_QUERY_STORE);
279 return count($tab_pos) ? $tab_pos : null;
283 * returns distinct values from $GLOBALS['PMD']['OWNER']
285 * @uses array_values()
286 * @uses array_unique()
287 * @uses $GLOBALS['PMD']['OWNER']
288 * @return array owner
290 function get_owners()
292 return array_values(array_unique($GLOBALS['PMD']['OWNER']));
295 get_tabs();