Translation update done using Pootle.
[phpmyadmin/crack.git] / pmd_common.php
blobbb376fa9d62b0ad4786556a46a31eea3899e9faa
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @version $Id$
5 * @package phpMyAdmin-Designer
6 */
8 /**
11 require_once './libraries/common.inc.php';
12 // not understand
13 require_once './libraries/header_http.inc.php';
15 $GLOBALS['PMD']['STYLE'] = 'default';
17 require_once './libraries/relation.lib.php';
18 $cfgRelation = PMA_getRelationsParam();
20 $GLOBALS['script_display_field'] =
21 '<script type="text/javascript">' . "\n" .
22 '// <![CDATA[' . "\n" .
23 'var display_field = new Array();' . "\n";
25 /**
26 * retrieves table info and stores it in $GLOBALS['PMD']
28 * @uses $GLOBALS['script_display_field']
29 * @uses $GLOBALS['PMD'] to fill it
30 * @uses $GLOBALS['db']
31 * @uses PMA_DBI_get_tables_full()
32 * @uses PMA_DBI_select_db()
33 * @uses PMA_getDisplayField()
34 * @uses urlencode()
35 * @uses htmlspecialchars()
36 * @uses strtoupper()
37 * @uses urlencode()
39 function get_tabs()
41 $GLOBALS['PMD']['TABLE_NAME'] = array();// that foreach no error
42 $GLOBALS['PMD']['OWNER'] = array();
43 $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array();
45 $tables = PMA_DBI_get_tables_full($GLOBALS['db']);
46 // seems to be needed later
47 PMA_DBI_select_db($GLOBALS['db']);
48 $i = 0;
49 foreach ($tables as $one_table) {
50 $GLOBALS['PMD']['TABLE_NAME'][$i] = $GLOBALS['db'] . "." . $one_table['TABLE_NAME'];
51 $GLOBALS['PMD']['OWNER'][$i] = $GLOBALS['db'];
52 $GLOBALS['PMD']['TABLE_NAME_SMALL'][$i] = $one_table['TABLE_NAME'];
54 $GLOBALS['PMD_URL']['TABLE_NAME'][$i] = urlencode($GLOBALS['db'] . "." . $one_table['TABLE_NAME']);
55 $GLOBALS['PMD_URL']['OWNER'][$i] = urlencode($GLOBALS['db']);
56 $GLOBALS['PMD_URL']['TABLE_NAME_SMALL'][$i] = urlencode($one_table['TABLE_NAME']);
58 $GLOBALS['PMD_OUT']['TABLE_NAME'][$i] = htmlspecialchars($GLOBALS['db'] . "." . $one_table['TABLE_NAME'], ENT_QUOTES);
59 $GLOBALS['PMD_OUT']['OWNER'][$i] = htmlspecialchars($GLOBALS['db'], ENT_QUOTES);
60 $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$i] = htmlspecialchars($one_table['TABLE_NAME'], ENT_QUOTES);
62 $GLOBALS['PMD']['TABLE_TYPE'][$i] = strtoupper($one_table['ENGINE']);
64 $DF = PMA_getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
65 if ($DF != '') {
66 $GLOBALS['script_display_field'] .= " display_field['"
67 . $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . "'] = '"
68 . urlencode($DF) . "';\n";
71 $i++;
74 $GLOBALS['script_display_field'] .=
75 '// ]]>' . "\n" .
76 '</script>' . "\n";
77 // return $GLOBALS['PMD']; // many bases // not use ??????
80 /**
81 * retrieves table column info
83 * @uses $GLOBALS['db']
84 * @uses PMA_DBI_QUERY_STORE
85 * @uses PMA_DBI_select_db()
86 * @uses PMA_DBI_query()
87 * @uses PMA_DBI_num_rows()
88 * @uses PMA_backquote()
89 * @uses count()
90 * @return array table column nfo
92 function get_tab_info()
94 PMA_DBI_select_db($GLOBALS['db']);
95 $tab_column = array();
96 for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) {
97 $fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM '.PMA_backquote($GLOBALS['PMD']["TABLE_NAME_SMALL"][$i]), NULL, PMA_DBI_QUERY_STORE);
98 $j = 0;
99 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
100 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_ID'][$j] = $j;
101 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['COLUMN_NAME'][$j] = $row['Field'];
102 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['TYPE'][$j] = $row['Type'];
103 $tab_column[$GLOBALS['PMD']['TABLE_NAME'][$i]]['NULLABLE'][$j] = $row['Null'];
104 $j++;
107 return $tab_column;
111 * returns JavaScript code for intializing vars
113 * @uses $GLOBALS['db']
114 * @uses PMA_DBI_QUERY_STORE
115 * @uses PMA_DBI_select_db()
116 * @uses PMA_DBI_query()
117 * @uses PMA_backquote()
118 * @uses PMA_DBI_fetch_row()
119 * @uses PMA_getForeigners()
120 * @uses urlencode()
121 * @uses count()
122 * @uses in_array()
123 * @return string JavaScript code
125 function get_script_contr()
127 PMA_DBI_select_db($GLOBALS['db']);
128 $con["C_NAME"] = array();
129 $i = 0;
130 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($GLOBALS['db']), NULL, PMA_DBI_QUERY_STORE);
131 while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
132 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal');
133 //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - ";
134 //print_r($row);
135 if ($row !== false) {
136 foreach ($row as $field => $value) {
137 $con['C_NAME'][$i] = '';
138 $con['DTN'][$i] = urlencode($GLOBALS['db'] . "." . $val[0]);
139 $con['DCN'][$i] = urlencode($field);
140 $con['STN'][$i] = urlencode($value['foreign_db'] . "." . $value['foreign_table']);
141 $con['SCN'][$i] = urlencode($value['foreign_field']);
142 $i++;
145 $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'foreign');
146 //echo "<br> INNO ";
147 //print_r($row);
148 if ($row !== false) {
149 foreach ($row as $field => $value) {
150 $con['C_NAME'][$i] = '';
151 $con['DTN'][$i] = urlencode($GLOBALS['db'].".".$val[0]);
152 $con['DCN'][$i] = urlencode($field);
153 $con['STN'][$i] = urlencode($value['foreign_db'].".".$value['foreign_table']);
154 $con['SCN'][$i] = urlencode($value['foreign_field']);
155 $i++;
160 $ti = 0;
161 $script_contr =
162 '<script type="text/javascript">' . "\n" .
163 '// <![CDATA[' . "\n" .
164 'var contr = new Array();' . "\n";
165 for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
166 $js_var = ' contr[' . $ti . ']';
167 $script_contr .= $js_var . " = new Array();\n";
168 $js_var .= "['" . $con['C_NAME'][$i] . "']";
169 $script_contr .= $js_var . " = new Array();\n";
170 if (in_array($con['DTN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])
171 && in_array($con['STN'][$i], $GLOBALS['PMD_URL']["TABLE_NAME"])) {
172 $js_var .= "['" . $con['DTN'][$i] . "']";
173 $script_contr .= $js_var . " = new Array();\n";
174 $m_col = array();//}
175 $js_var .= "['" . $con['DCN'][$i] . "']";
176 $script_contr .= $js_var . " = new Array();\n";//}
177 $script_contr .= $js_var . "[0] = '" . $con['STN'][$i] . "';\n"; //
178 $script_contr .= $js_var . "[1] = '" . $con['SCN'][$i] . "';\n"; //
180 $ti++;
182 $script_contr .=
183 '// ]]>' . "\n" .
184 '</script>' . "\n";
185 return $script_contr;
189 * @uses get_all_keys()
190 * @return array unique or primary indizes
192 function get_pk_or_unique_keys()
194 return get_all_keys(true);
198 * returns all indizes
200 * @uses $GLOBALS['PMD']
201 * @uses PMA_Index::getFromTable()
202 * @uses PMA_Index->isUnique()
203 * @uses PMA_Index->getColumns()
204 * @param boolean whether to include ony unique ones
205 * @return array indizes
207 function get_all_keys($unique_only = false)
209 require_once './libraries/Index.class.php';
211 $keys = array();
213 foreach ($GLOBALS['PMD']['TABLE_NAME_SMALL'] as $I => $table) {
214 $schema = $GLOBALS['PMD']['OWNER'][$I];
215 // for now, take into account only the first index segment
216 foreach (PMA_Index::getFromTable($table, $schema) as $index) {
217 if ($unique_only && ! $index->isUnique()) {
218 continue;
220 $columns = $index->getColumns();
221 foreach ($columns as $column_name => $dummy) {
222 $keys[$schema . '.' .$table . '.' . $column_name] = 1;
226 return $keys;
232 * @uses $GLOBALS['PMD']
233 * @uses count()
234 * @uses in_array()
235 * @return array ???
237 function get_script_tabs()
239 $script_tabs =
240 '<script type="text/javascript">' . "\n" .
241 '// <![CDATA[' . "\n" .
242 'var j_tabs = new Array();' . "\n";
243 for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
244 $script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '"
245 . (PMA_foreignkey_supported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0') . "';\n";
247 $script_tabs .=
248 '// ]]>' . "\n" .
249 '</script>' . "\n";
250 return $script_tabs;
254 * @uses $GLOBALS['controllink']
255 * @uses $cfgRelation['designerwork']
256 * @uses $cfgRelation['db']
257 * @uses $cfgRelation['designer_coords']
258 * @uses PMA_DBI_QUERY_STORE
259 * @uses PMA_getRelationsParam()
260 * @uses PMA_backquote()
261 * @uses PMA_DBI_fetch_result()
262 * @uses count()
263 * @return array table positions and sizes
265 function get_tab_pos()
267 $cfgRelation = PMA_getRelationsParam();
269 if (! $cfgRelation['designerwork']) {
270 return null;
273 $query = "
274 SELECT CONCAT_WS('.', `db_name`, `table_name`) AS `name`,
275 `x` AS `X`,
276 `y` AS `Y`,
277 `v` AS `V`,
278 `h` AS `H`
279 FROM " . PMA_backquote($cfgRelation['db']) . "." . PMA_backquote($cfgRelation['designer_coords']);
280 $tab_pos = PMA_DBI_fetch_result($query, 'name', null, $GLOBALS['controllink'], PMA_DBI_QUERY_STORE);
281 return count($tab_pos) ? $tab_pos : null;
285 * returns distinct values from $GLOBALS['PMD']['OWNER']
287 * @uses array_values()
288 * @uses array_unique()
289 * @uses $GLOBALS['PMD']['OWNER']
290 * @return array owner
292 function get_owners()
294 return array_values(array_unique($GLOBALS['PMD']['OWNER']));
297 get_tabs();