Translation update done using Pootle.
[phpmyadmin/ammar_yasir.git] / pmd_common.php
blobdf8fdf2b0b0a37d7e958bab1f9d58b634e6c3f9d
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 'var h_tabs = new Array();' . "\n" ;
242 for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) {
243 $script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '"
244 . (PMA_foreignkey_supported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0') . "';\n";
245 $script_tabs .="h_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = 1;"."\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();