Refresh .po files
[phpmyadmin.git] / libraries / schema / User_Schema.class.php
blob399341247fccdf7249367801ad9aa98b8a7f5252
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
8 /**
9 * This Class interacts with the user to gather the information
10 * about their tables for which they want to export the relational schema
11 * export options are shown to user from they can choose
14 class PMA_User_Schema
17 public $chosenPage;
18 public $autoLayoutForeign;
19 public $autoLayoutInternal;
20 public $pageNumber;
21 public $c_table_rows;
22 public $action;
24 public function setAction($value)
26 $this->action = $value;
28 /**
29 * This function will process the user defined pages
30 * and tables which will be exported as Relational schema
31 * you can set the table positions on the paper via scratchboard
32 * for table positions, put the x,y co-ordinates
34 * $this->action tells what the Schema is supposed to do
35 * create and select a page, generate schema etc
37 * @access public
38 * @return void
40 public function processUserChoice()
42 global $action_choose, $db, $cfgRelation;
44 if (isset($this->action)) {
45 switch ($this->action) {
46 case 'selectpage':
47 $this->chosenPage = $_REQUEST['chpage'];
48 if ($action_choose=="1") {
49 $this->deleteCoordinates(
50 $db,
51 $cfgRelation,
52 $this->chosenPage
54 $this->deletePages(
55 $db,
56 $cfgRelation,
57 $this->chosenPage
59 $this->chosenPage = 0;
61 break;
62 case 'createpage':
63 $this->pageNumber = PMA_REL_create_page(
64 $_POST['newpage'],
65 $cfgRelation,
66 $db
68 $this->autoLayoutForeign = isset($_POST['auto_layout_foreign'])
69 ? "1"
70 : null;
71 $this->autoLayoutInternal = isset($_POST['auto_layout_internal'])
72 ? "1"
73 : null;
74 $this->processRelations(
75 $db,
76 $this->pageNumber,
77 $cfgRelation
79 break;
80 case 'edcoord':
81 $this->chosenPage = $_POST['chpage'];
82 $this->c_table_rows = $_POST['c_table_rows'];
83 $this->_editCoordinates($db, $cfgRelation);
84 break;
85 case 'delete_old_references':
86 $this->_deleteTableRows(
87 $_POST['delrow'],
88 $cfgRelation,
89 $db,
90 $_POST['chpage']
92 break;
93 case 'process_export':
94 $this->_processExportSchema();
95 break;
97 } // end switch
98 } // end if (isset($do))
103 * shows/displays the HTML FORM to create the page
105 * @param string $db name of the selected database
107 * @return void
108 * @access public
110 public function showCreatePageDialog($db)
113 <form method="post" action="schema_edit.php" name="frm_create_page">
114 <fieldset>
115 <legend>
116 <?php echo __('Create a page') . "\n"; ?>
117 </legend>
118 <?php echo PMA_generate_common_hidden_inputs($db); ?>
119 <input type="hidden" name="do" value="createpage" />
120 <table>
121 <tr>
122 <td><label for="id_newpage"><?php echo __('Page name'); ?></label></td>
123 <td><input type="text" name="newpage" id="id_newpage" size="20" maxlength="50" /></td>
124 </tr>
125 <tr>
126 <td><?php echo __('Automatic layout based on'); ?></td>
127 <td>
128 <input type="checkbox" name="auto_layout_internal" id="id_auto_layout_internal" /><label for="id_auto_layout_internal">
129 <?php echo __('Internal relations'); ?></label><br />
130 <?php
132 * Check to see whether INNODB and PBXT storage engines are Available in MYSQL PACKAGE
133 * If available, then provide AutoLayout for Foreign Keys in Schema View
136 if (PMA_StorageEngine::isValid('InnoDB') || PMA_StorageEngine::isValid('PBXT')) {
138 <input type="checkbox" name="auto_layout_foreign" id="id_auto_layout_foreign" /><label for="id_auto_layout_foreign">
139 <?php echo __('FOREIGN KEY'); ?></label><br />
140 <?php
143 </td></tr>
144 </table>
145 </fieldset>
146 <fieldset class="tblFooters">
147 <input type="submit" value="<?php echo __('Go'); ?>" />
148 </fieldset>
149 </form>
150 <?php
154 * shows/displays the created page names in a drop down list
155 * User can select any page number and edit it using dashboard etc
157 * @return void
158 * @access public
160 public function selectPage()
162 global $db,$table,$cfgRelation;
163 $page_query = 'SELECT * FROM '
164 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
165 . PMA_backquote($cfgRelation['pdf_pages'])
166 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'';
167 $page_rs = PMA_query_as_controluser($page_query, false, PMA_DBI_QUERY_STORE);
168 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
170 <form method="get" action="schema_edit.php" name="frm_select_page">
171 <fieldset>
172 <legend>
173 <?php echo __('Please choose a page to edit') . "\n"; ?>
174 </legend>
175 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
176 <input type="hidden" name="do" value="selectpage" />
177 <select name="chpage" id="chpage" class="autosubmit">
178 <option value="0"><?php echo __('Select page'); ?></option>
179 <?php
180 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
181 echo "\n" . ' '
182 . '<option value="' . $curr_page['page_nr'] . '"';
183 if (isset($this->chosenPage)
184 && $this->chosenPage == $curr_page['page_nr']
186 echo ' selected="selected"';
188 echo '>' . $curr_page['page_nr'] . ': '
189 . htmlspecialchars($curr_page['page_descr']) . '</option>';
190 } // end while
191 echo "\n";
193 </select>
194 <?php
195 $choices = array(
196 '0' => __('Edit'),
197 '1' => __('Delete')
199 PMA_display_html_radio('action_choose', $choices, '0', false);
200 unset($choices);
202 </fieldset>
203 <fieldset class="tblFooters">
204 <input type="submit" value="<?php echo __('Go'); ?>" /><br />
205 </fieldset>
206 </form>
207 <?php
208 } // end IF
209 echo "\n";
210 } // end function
213 * A dashboard is displayed to AutoLayout the position of tables
214 * users can drag n drop the tables and change their positions
216 * @return void
217 * @access public
219 public function showTableDashBoard()
221 global $db, $cfgRelation, $table, $with_field_names;
223 * We will need an array of all tables in this db
225 $selectboxall = array('--');
226 $alltab_rs = PMA_DBI_query(
227 'SHOW TABLES FROM ' . PMA_backquote($db) . ';',
228 null,
229 PMA_DBI_QUERY_STORE
231 while ($val = @PMA_DBI_fetch_row($alltab_rs)) {
232 $selectboxall[] = $val[0];
235 $tabExist = array();
238 * Now if we already have chosen a page number then we should
239 * show the tables involved
241 if (isset($this->chosenPage) && $this->chosenPage > 0) {
242 echo "\n";
244 <h2><?php echo __('Select Tables'); ?></h2>
245 <?php
246 $page_query = 'SELECT * FROM '
247 . PMA_backquote($GLOBALS['cfgRelation']['db'])
248 . '.' . PMA_backquote($cfgRelation['table_coords'])
249 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
250 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\'';
251 $page_rs = PMA_query_as_controluser($page_query, false);
252 $array_sh_page = array();
253 while ($temp_sh_page = @PMA_DBI_fetch_assoc($page_rs)) {
254 $array_sh_page[] = $temp_sh_page;
257 * Display WYSIWYG parts
260 if (! isset($_POST['with_field_names']) && ! isset($_POST['showwysiwyg'])) {
261 $with_field_names = true;
263 $this->_displayScratchboardTables($array_sh_page);
266 <form method="post" action="schema_edit.php" name="edcoord">
267 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
268 <input type="hidden" name="chpage" value="<?php echo htmlspecialchars($this->chosenPage); ?>" />
269 <input type="hidden" name="do" value="edcoord" />
270 <table border="0">
271 <tr>
272 <th><?php echo __('Table'); ?></th>
273 <th><?php echo __('Delete'); ?></th>
274 <th>X</th>
275 <th>Y</th>
276 </tr>
277 <?php
278 if (isset($ctable)) {
279 unset($ctable);
282 $i = 0;
283 $odd_row = true;
284 foreach ($array_sh_page as $dummy_sh_page => $sh_page) {
285 $_mtab = $sh_page['table_name'];
286 $tabExist[$_mtab] = false;
287 echo "\n" . ' <tr class="noclick ';
288 if ($odd_row) {
289 echo 'odd';
290 } else {
291 echo 'even';
293 echo '">';
294 $odd_row != $odd_row;
295 echo "\n" . ' <td>'
296 . "\n" . ' <select name="c_table_' . $i . '[name]">';
297 foreach ($selectboxall as $key => $value) {
298 echo "\n" . ' <option value="' . htmlspecialchars($value) . '"';
299 if ($value == $sh_page['table_name']) {
300 echo ' selected="selected"';
301 $tabExist[$_mtab] = true;
303 echo '>' . htmlspecialchars($value) . '</option>';
305 echo "\n" . ' </select>'
306 . "\n" . ' </td>';
307 echo "\n" . ' <td>'
308 . "\n" . ' <input type="checkbox" id="id_c_table_' . $i .'" name="c_table_' . $i . '[delete]" value="y" /><label for="id_c_table_' . $i .'">' . __('Delete') . '</label>';
309 echo "\n" . ' </td>';
310 echo "\n" . ' <td>'
311 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'x\', this.value)" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
312 echo "\n" . ' </td>';
313 echo "\n" . ' <td>'
314 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'y\', this.value)" name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
315 echo "\n" . ' </td>';
316 echo "\n" . ' </tr>';
317 $i++;
320 * Add one more empty row
322 echo "\n" . ' <tr class="noclick ';
323 if ($odd_row) {
324 echo 'odd';
325 } else {
326 echo 'even';
328 $odd_row != $odd_row;
329 echo '">';
330 echo "\n" . ' <td>'
331 . "\n" . ' <select name="c_table_' . $i . '[name]">';
332 foreach ($selectboxall as $key => $value) {
333 echo "\n" . ' <option value="' . htmlspecialchars($value) . '">' . htmlspecialchars($value) . '</option>';
335 echo "\n" . ' </select>'
336 . "\n" . ' </td>';
337 echo "\n" . ' <td>'
338 . "\n" . ' <input type="checkbox" id="id_c_table_' . $i .'" name="c_table_' . $i . '[delete]" value="y" /><label for="id_c_table_' . $i .'">' . __('Delete') . '</label>';
339 echo "\n" . ' </td>';
340 echo "\n" . ' <td>'
341 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?$sh_page['x']:'') . '" />';
342 echo "\n" . ' </td>';
343 echo "\n" . ' <td>'
344 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?$sh_page['y']:'') . '" />';
345 echo "\n" . ' </td>';
346 echo "\n" . ' </tr>';
347 echo "\n" . ' </table>' . "\n";
349 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i + 1) . '" />';
350 echo "\n" . ' <input type="hidden" id="showwysiwyg" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ? '1' : '0') . '" />';
351 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ? 'checked="checked"' : ''). ' />' . __('Column names') . '<br />';
352 echo "\n" . ' <input type="submit" value="' . __('Save') . '" />';
353 echo "\n" . '</form>' . "\n\n";
354 } // end if
356 if (isset($tabExist)) {
357 $this->_deleteTables($db, $this->chosenPage, $tabExist);
362 * show Export relational schema generation options
363 * user can select export type of his own choice
364 * and the attributes related to it
366 * @return void
367 * @access public
370 public function displaySchemaGenerationOptions()
372 global $cfg,$pmaThemeImage,$db,$test_rs,$chpage;
374 <form method="post" action="schema_export.php">
375 <fieldset>
376 <legend>
377 <?php
378 echo PMA_generate_common_hidden_inputs($db);
379 if ($cfg['PropertiesIconic']) {
380 echo PMA_getImage('b_views.png');
382 echo __('Display relational schema');
384 </legend>
385 <select name="export_type" id="export_type">
386 <option value="pdf" selected="selected">PDF</option>
387 <option value="svg">SVG</option>
388 <option value="dia">DIA</option>
389 <option value="visio">Visio</option>
390 <option value="eps">EPS</option>
391 </select>
392 <label><?php echo __('Select Export Relational Type');?></label><br />
393 <?php
394 if (isset($test_rs)) {
396 <label for="pdf_page_number_opt"><?php echo __('Page number:'); ?></label>
397 <select name="pdf_page_number" id="pdf_page_number_opt">
398 <?php
399 while ($pages = @PMA_DBI_fetch_assoc($test_rs)) {
400 echo ' <option value="' . $pages['page_nr'] . '">'
401 . $pages['page_nr'] . ': ' . htmlspecialchars($pages['page_descr']) . '</option>' . "\n";
402 } // end while
403 PMA_DBI_free_result($test_rs);
404 unset($test_rs);
406 </select><br />
407 <?php } else { ?>
408 <input type="hidden" name="pdf_page_number" value="<?php echo htmlspecialchars($this->chosenPage); ?>" />
409 <?php } ?>
410 <input type="hidden" name="do" value="process_export" />
411 <input type="hidden" name="chpage" value="<?php echo $chpage; ?>" />
412 <input type="checkbox" name="show_grid" id="show_grid_opt" />
413 <label for="show_grid_opt"><?php echo __('Show grid'); ?></label><br />
414 <input type="checkbox" name="show_color" id="show_color_opt" checked="checked" />
415 <label for="show_color_opt"><?php echo __('Show color'); ?></label><br />
416 <input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" />
417 <label for="show_table_dim_opt"><?php echo __('Show dimension of tables'); ?>
418 </label><br />
419 <input type="checkbox" name="all_table_same_wide" id="all_table_same_wide" />
420 <label for="all_table_same_wide"><?php echo __('Display all tables with the same width'); ?>
421 </label><br />
422 <input type="checkbox" name="with_doc" id="with_doc" checked="checked" />
423 <label for="with_doc"><?php echo __('Data Dictionary'); ?></label><br />
424 <input type="checkbox" name="show_keys" id="show_keys" />
425 <label for="show_keys"><?php echo __('Only show keys'); ?></label><br />
426 <select name="orientation" id="orientation_opt" onchange="refreshDragOption('pdflayout');" >
427 <option value="L"><?php echo __('Landscape');?></option>
428 <option value="P"><?php echo __('Portrait');?></option>
429 </select>
430 <label for="orientation_opt"><?php echo __('Orientation'); ?></label>
431 <br />
432 <select name="paper" id="paper_opt" onchange="refreshDragOption('pdflayout');">
433 <?php
434 foreach ($cfg['PDFPageSizes'] as $key => $val) {
435 echo '<option value="' . $val . '"';
436 if ($val == $cfg['PDFDefaultPageSize']) {
437 echo ' selected="selected"';
439 echo ' >' . $val . '</option>' . "\n";
442 </select>
443 <label for="paper_opt"><?php echo __('Paper size'); ?></label>
444 </fieldset>
445 <fieldset class="tblFooters">
446 <input type="submit" value="<?php echo __('Go'); ?>" />
447 </fieldset>
448 </form>
449 <?php
453 * Check if there are tables that need to be deleted in dashboard,
454 * if there are, ask the user for allowance
456 * @param string $db name of database selected
457 * @param integer $chpage selected page
458 * @param array $tabExist
460 * @return void
461 * @access private
463 private function _deleteTables($db, $chpage, $tabExist)
465 global $table;
466 $_strtrans = '';
467 $_strname = '';
468 $shoot = false;
469 if (! empty($tabExist) && is_array($tabExist)) {
470 foreach ($tabExist as $key => $value) {
471 if (! $value) {
472 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . htmlspecialchars($key) . '" />' . "\n";
473 $_strname .= '<li>' . htmlspecialchars($key) . '</li>' . "\n";
474 $shoot = true;
477 if ($shoot) {
478 echo '<form action="schema_edit.php" method="post">' . "\n"
479 . PMA_generate_common_hidden_inputs($db)
480 . '<input type="hidden" name="do" value="delete_old_references" />' . "\n"
481 . '<input type="hidden" name="chpage" value="' . htmlspecialchars($chpage) . '" />' . "\n"
482 . __('The current page has references to tables that no longer exist. Would you like to delete those references?')
483 . '<ul>' . "\n"
484 . $_strname
485 . '</ul>' . "\n"
486 . $_strtrans
487 . '<input type="submit" value="' . __('Go') . '" />' . "\n"
488 . '</form>';
495 * Check if there are tables that need to be deleted in dashboard,
496 * if there are, ask the user for allowance
498 * @return void
499 * @access private
501 private function _displayScratchboardTables($array_sh_page)
503 global $with_field_names, $db;
505 <script type="text/javascript" src="./js/dom-drag.js"></script>
506 <form method="post" action="schema_edit.php" name="dragdrop">
507 <input type="button" name="dragdrop" value="<?php echo __('Toggle scratchboard'); ?>" onclick="ToggleDragDrop('pdflayout');" />
508 <input type="button" name="dragdropreset" value="<?php echo __('Reset'); ?>" onclick="resetDrag();" />
509 </form>
510 <div id="pdflayout" class="pdflayout" style="visibility: hidden;">
511 <?php
512 $draginit = '';
513 $draginit2 = '';
514 $reset_draginit = '';
515 $i = 0;
516 foreach ($array_sh_page as $key => $temp_sh_page) {
517 $drag_x = $temp_sh_page['x'];
518 $drag_y = $temp_sh_page['y'];
520 $draginit2 .= ' Drag.init($("#table_' . $i . '")[0], null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
521 $draginit2 .= ' $("#table_' . $i . '")[0].onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n";
522 $draginit .= ' $("#table_' . $i . '")[0].style.left = "' . $drag_x . 'px";' . "\n";
523 $draginit .= ' $("#table_' . $i . '")[0].style.top = "' . $drag_y . 'px";' . "\n";
524 $reset_draginit .= ' $("#table_' . $i . '")[0].style.left = "2px";' . "\n";
525 $reset_draginit .= ' $("#table_' . $i . '")[0].style.top = "' . (15 * $i) . 'px";' . "\n";
526 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
527 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
529 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
530 if (isset($with_field_names)) {
531 $fields = PMA_DBI_get_columns($db, $temp_sh_page['table_name']);
532 // if the table has been dropped from outside phpMyAdmin,
533 // we can no longer obtain its columns list
534 if ($fields) {
535 foreach ($fields as $row) {
536 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
540 echo '</div>' . "\n";
541 $i++;
544 </div>
545 <script type="text/javascript">
546 //<![CDATA[
547 function PDFinit() {
548 refreshLayout();
549 myid = $('#pdflayout')[0];
550 <?php echo $draginit; ?>
551 TableDragInit();
554 function TableDragInit() {
555 myid = $('#pdflayout')[0];
556 <?php echo $draginit2; ?>
559 function resetDrag() {
560 <?php echo $reset_draginit; ?>
562 //]]>
563 </script>
564 <?php
568 * delete the table rows with table co-ordinates
570 * @param int $delrow delete selected table from list of tables
571 * @param array $cfgRelation relation settings
572 * @param string $db database name
573 * @param integer $chpage selected page for adding relations etc
575 * @return void
576 * @access private
578 private function _deleteTableRows($delrow,$cfgRelation,$db,$chpage)
580 foreach ($delrow as $current_row) {
581 $del_query = 'DELETE FROM '
582 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
583 . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
584 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'' . "\n"
585 . ' AND table_name = \'' . PMA_sqlAddSlashes($current_row) . '\'' . "\n"
586 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($chpage) . '\'';
587 echo $del_query;
588 PMA_query_as_controluser($del_query, false);
593 * get all the export options and verify
594 * call and include the appropriate Schema Class depending on $export_type
596 * @return void
597 * @access private
599 private function _processExportSchema()
602 * Settings for relation stuff
604 include_once './libraries/transformations.lib.php';
605 include_once './libraries/Index.class.php';
607 * default is PDF, otherwise validate it's only letters a-z
609 global $db,$export_type;
610 if (!isset($export_type) || !preg_match('/^[a-zA-Z]+$/', $export_type)) {
611 $export_type = 'pdf';
614 PMA_DBI_select_db($db);
616 include "./libraries/schema/" . ucfirst($export_type) . "_Relation_Schema.class.php";
617 $obj_schema = eval("new PMA_" . ucfirst($export_type) . "_Relation_Schema();");
621 * delete X and Y coordinates
623 * @param string $db The database name
624 * @param array $cfgRelation relation settings
625 * @param integer $choosePage selected page for adding relations etc
627 * @return void
628 * @access private
630 public function deleteCoordinates($db, $cfgRelation, $choosePage)
632 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
633 . PMA_backquote($cfgRelation['table_coords'])
634 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
635 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($choosePage) . '\'';
636 PMA_query_as_controluser($query, false);
640 * delete pages
642 * @param string $db The database name
643 * @param array $cfgRelation relation settings
644 * @param integer $choosePage selected page for adding relations etc
646 * @return void
647 * @access private
649 public function deletePages($db, $cfgRelation, $choosePage)
651 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
652 . PMA_backquote($cfgRelation['pdf_pages'])
653 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
654 . ' AND page_nr = \'' . PMA_sqlAddSlashes($choosePage) . '\'';
655 PMA_query_as_controluser($query, false);
659 * process internal and foreign key relations
661 * @param string $db The database name
662 * @param integer $pageNumber document number/Id
663 * @param array $cfgRelation relation settings
665 * @return void
666 * @access private
668 public function processRelations($db, $pageNumber, $cfgRelation)
671 * A u t o m a t i c l a y o u t
673 * There are 2 kinds of relations in PMA
674 * 1) Internal Relations 2) Foreign Key Relations
676 if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) {
677 $all_tables = array();
680 if (isset($this->autoLayoutForeign)) {
682 * get the tables list
683 * who support FOREIGN KEY, it's not
684 * important that we group together InnoDB tables
685 * and PBXT tables, as this logic is just to put
686 * the tables on the layout, not to determine relations
688 $tables = PMA_DBI_get_tables_full($db);
689 $foreignkey_tables = array();
690 foreach ($tables as $table_name => $table_properties) {
691 if (PMA_foreignkey_supported($table_properties['ENGINE'])) {
692 $foreignkey_tables[] = $table_name;
695 $all_tables = $foreignkey_tables;
697 * could be improved by finding the tables which have the
698 * most references keys and placing them at the beginning
699 * of the array (so that they are all center of schema)
701 unset($tables, $foreignkey_tables);
704 if (isset($this->autoLayoutInternal)) {
706 * get the tables list who support Internal Relations;
707 * This type of relations will be created when
708 * you setup the PMA tables correctly
710 $master_tables = 'SELECT COUNT(master_table), master_table'
711 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
712 . PMA_backquote($cfgRelation['relation'])
713 . ' WHERE master_db = \'' . PMA_sqlAddSlashes($db) . '\''
714 . ' GROUP BY master_table'
715 . ' ORDER BY COUNT(master_table) DESC';
716 $master_tables_rs = PMA_query_as_controluser(
717 $master_tables, false, PMA_DBI_QUERY_STORE
719 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
720 /* first put all the master tables at beginning
721 * of the list, so they are near the center of
722 * the schema
724 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
725 $all_tables[] = $master_table;
728 /* Now for each master, add its foreigns into an array
729 * of foreign tables, if not already there
730 * (a foreign might be foreign for more than
731 * one table, and might be a master itself)
734 $foreign_tables = array();
735 foreach ($all_tables as $master_table) {
736 $foreigners = PMA_getForeigners($db, $master_table);
737 foreach ($foreigners as $foreigner) {
738 if (! in_array($foreigner['foreign_table'], $foreign_tables)) {
739 $foreign_tables[] = $foreigner['foreign_table'];
745 * Now merge the master and foreign arrays/tables
747 foreach ($foreign_tables as $foreign_table) {
748 if (! in_array($foreign_table, $all_tables)) {
749 $all_tables[] = $foreign_table;
755 if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) {
756 $this->addRelationCoordinates(
757 $all_tables, $pageNumber, $db, $cfgRelation
761 $this->chosenPage = $pageNumber;
765 * Add X and Y coordinates for a table
767 * @param array $all_tables A list of all tables involved
768 * @param integer $pageNumber document number/Id
769 * @param string $db The database name
770 * @param array $cfgRelation relation settings
772 * @return void
773 * @access private
775 public function addRelationCoordinates($all_tables, $pageNumber, $db, $cfgRelation)
778 * Now generate the coordinates for the schema
779 * in a clockwise spiral and add to co-ordinates table
781 $pos_x = 300;
782 $pos_y = 300;
783 $delta = 110;
784 $delta_mult = 1.10;
785 $direction = "right";
786 foreach ($all_tables as $current_table) {
788 * save current table's coordinates
790 $insert_query = 'INSERT INTO '
791 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
792 . PMA_backquote($cfgRelation['table_coords']) . ' '
793 . '(db_name, table_name, pdf_page_number, x, y) '
794 . 'VALUES (\'' . PMA_sqlAddSlashes($db) . '\', \''
795 . PMA_sqlAddSlashes($current_table) . '\',' . $pageNumber
796 . ',' . $pos_x . ',' . $pos_y . ')';
797 PMA_query_as_controluser($insert_query, false);
800 * compute for the next table
802 switch ($direction) {
803 case 'right':
804 $pos_x += $delta;
805 $direction = "down";
806 $delta *= $delta_mult;
807 break;
808 case 'down':
809 $pos_y += $delta;
810 $direction = "left";
811 $delta *= $delta_mult;
812 break;
813 case 'left':
814 $pos_x -= $delta;
815 $direction = "up";
816 $delta *= $delta_mult;
817 break;
818 case 'up':
819 $pos_y -= $delta;
820 $direction = "right";
821 $delta *= $delta_mult;
822 break;
828 * update X and Y coordinates for a table
830 * @param string $db The database name
831 * @param array $cfgRelation relation settings
833 * @return void
834 * @access private
836 private function _editCoordinates($db, $cfgRelation)
838 for ($i = 0; $i < $this->c_table_rows; $i++) {
839 $arrvalue = 'c_table_' . $i;
840 global $$arrvalue;
841 $arrvalue = $$arrvalue;
842 if (! isset($arrvalue['x']) || $arrvalue['x'] == '') {
843 $arrvalue['x'] = 0;
845 if (! isset($arrvalue['y']) || $arrvalue['y'] == '') {
846 $arrvalue['y'] = 0;
848 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
849 $test_query = 'SELECT * FROM '
850 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
851 . PMA_backquote($cfgRelation['table_coords'])
852 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
853 . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\''
854 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\'';
855 $test_rs = PMA_query_as_controluser($test_query, false, PMA_DBI_QUERY_STORE);
856 //echo $test_query;
857 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
858 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
859 $ch_query = 'DELETE FROM '
860 . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.'
861 . PMA_backquote($cfgRelation['table_coords'])
862 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
863 . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\''
864 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\'';
865 } else {
866 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db'])
867 . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
868 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
869 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
870 . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\''
871 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage) . '\'';
873 } else {
874 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db'])
875 . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
876 . '(db_name, table_name, pdf_page_number, x, y) '
877 . 'VALUES (\'' . PMA_sqlAddSlashes($db) . '\', \''
878 . PMA_sqlAddSlashes($arrvalue['name']) . '\', \''
879 . PMA_sqlAddSlashes($this->chosenPage) . '\','
880 . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
882 //echo $ch_query;
883 PMA_query_as_controluser($ch_query, false);
884 } // end if
885 } // end for