2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
18 public $autoLayoutForeign;
19 public $autoLayoutInternal;
24 public function setAction($value)
26 $this->action
= $value;
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 * @param string $this->action It tells what the Schema is supposed to do
35 * create and select a page, generate schema etc
39 public function processUserChoice()
41 global $action_choose, $db, $cfgRelation;
43 if (isset($this->action
)) {
44 switch ($this->action
) {
46 $this->chosenPage
= $_REQUEST['chpage'];
47 if ($action_choose=="1") {
48 $this->deleteCoordinates(
58 $this->chosenPage
= 0;
62 $this->pageNumber
= PMA_REL_create_page(
67 $this->autoLayoutForeign
= isset($_POST['auto_layout_foreign']) ?
"1":NULL;
68 $this->autoLayoutInternal
= isset($_POST['auto_layout_internal']) ?
"1":NULL;
69 $this->processRelations(
76 $this->chosenPage
= $_POST['chpage'];
77 $this->c_table_rows
= $_POST['c_table_rows'];
78 $this->_editCoordinates($db, $cfgRelation);
80 case 'delete_old_references':
81 $this->_deleteTableRows(
88 case 'process_export':
89 $this->_processExportSchema();
93 } // end if (isset($do))
98 * shows/displays the HTML FORM to create the page
100 * @param string db name of the selected database
104 public function showCreatePageDialog($db)
107 <form method
="post" action
="schema_edit.php" name
="frm_create_page">
110 <?php
echo __('Create a page') . "\n"; ?
>
112 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
113 <input type
="hidden" name
="do" value
="createpage" />
116 <td
><label
for="id_newpage"><?php
echo __('Page name'); ?
></label
></td
>
117 <td
><input type
="text" name
="newpage" id
="id_newpage" size
="20" maxlength
="50" /></td
>
120 <td
><?php
echo __('Automatic layout based on'); ?
></td
>
122 <input type
="checkbox" name
="auto_layout_internal" id
="id_auto_layout_internal" /><label
for="id_auto_layout_internal">
123 <?php
echo __('Internal relations'); ?
></label
><br
/>
126 * Check to see whether INNODB and PBXT storage engines are Available in MYSQL PACKAGE
127 * If available, then provide AutoLayout for Foreign Keys in Schema View
130 if (PMA_StorageEngine
::isValid('InnoDB') || PMA_StorageEngine
::isValid('PBXT')) {
132 <input type
="checkbox" name
="auto_layout_foreign" id
="id_auto_layout_foreign" /><label
for="id_auto_layout_foreign">
133 <?php
echo __('FOREIGN KEY'); ?
></label
><br
/>
140 <fieldset
class="tblFooters">
141 <input type
="submit" value
="<?php echo __('Go'); ?>" />
148 * shows/displays the created page names in a drop down list
149 * User can select any page number and edit it using dashboard etc
154 public function selectPage()
156 global $db,$table,$cfgRelation;
157 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
158 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'';
159 $page_rs = PMA_query_as_controluser($page_query, false, PMA_DBI_QUERY_STORE
);
160 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
162 <form method
="get" action
="schema_edit.php" name
="frm_select_page">
165 <?php
echo __('Please choose a page to edit') . "\n"; ?
>
167 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
168 <input type
="hidden" name
="do" value
="selectpage" />
169 <select name
="chpage" id
="chpage" class="autosubmit">
170 <option value
="0"><?php
echo __('Select page'); ?
></option
>
172 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
174 . '<option value="' . $curr_page['page_nr'] . '"';
175 if (isset($this->chosenPage
) && $this->chosenPage
== $curr_page['page_nr']) {
176 echo ' selected="selected"';
178 echo '>' . $curr_page['page_nr'] . ': ' . htmlspecialchars($curr_page['page_descr']) . '</option>';
188 PMA_display_html_radio('action_choose', $choices, '0', false);
192 <fieldset
class="tblFooters">
193 <input type
="submit" value
="<?php echo __('Go'); ?>" /><br
/>
202 * A dashboard is displayed to AutoLayout the position of tables
203 * users can drag n drop the tables and change their positions
208 public function showTableDashBoard()
210 global $db, $cfgRelation, $table, $with_field_names;
212 * We will need an array of all tables in this db
214 $selectboxall = array('--');
215 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
216 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
217 $selectboxall[] = $val[0];
221 * Now if we already have chosen a page number then we should
222 * show the tables involved
225 if (isset($this->chosenPage
) && $this->chosenPage
> 0) {
228 <h2
><?php
echo __('Select Tables') ;?
></h2
>
230 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
231 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
232 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage
) . '\'';
233 $page_rs = PMA_query_as_controluser($page_query, false);
234 $array_sh_page = array();
235 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
236 $array_sh_page[] = $temp_sh_page;
239 * Display WYSIWYG parts
242 if (! isset($_POST['with_field_names']) && ! isset($_POST['showwysiwyg'])) {
243 $with_field_names = true;
245 $this->_displayScratchboardTables($array_sh_page);
248 <form method
="post" action
="schema_edit.php" name
="edcoord">
249 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
250 <input type
="hidden" name
="chpage" value
="<?php echo htmlspecialchars($this->chosenPage); ?>" />
251 <input type
="hidden" name
="do" value
="edcoord" />
254 <th
><?php
echo __('Table'); ?
></th
>
255 <th
><?php
echo __('Delete'); ?
></th
>
260 if (isset($ctable)) {
266 foreach ($array_sh_page as $dummy_sh_page => $sh_page) {
267 $_mtab = $sh_page['table_name'];
268 $tabExist[$_mtab] = false;
269 echo "\n" . ' <tr class="noclick ';
276 $odd_row != $odd_row;
278 . "\n" . ' <select name="c_table_' . $i . '[name]">';
279 foreach ($selectboxall as $key => $value) {
280 echo "\n" . ' <option value="' . htmlspecialchars($value) . '"';
281 if ($value == $sh_page['table_name']) {
282 echo ' selected="selected"';
283 $tabExist[$_mtab] = true;
285 echo '>' . htmlspecialchars($value) . '</option>';
287 echo "\n" . ' </select>'
290 . "\n" . ' <input type="checkbox" id="id_c_table_' . $i .'" name="c_table_' . $i . '[delete]" value="y" /><label for="id_c_table_' . $i .'">' . __('Delete') . '</label>';
291 echo "\n" . ' </td>';
293 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'x\', this.value)" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
294 echo "\n" . ' </td>';
296 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'y\', this.value)" name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
297 echo "\n" . ' </td>';
298 echo "\n" . ' </tr>';
302 * Add one more empty row
304 echo "\n" . ' <tr class="noclick ';
310 $odd_row != $odd_row;
313 . "\n" . ' <select name="c_table_' . $i . '[name]">';
314 foreach ($selectboxall as $key => $value) {
315 echo "\n" . ' <option value="' . htmlspecialchars($value) . '">' . htmlspecialchars($value) . '</option>';
317 echo "\n" . ' </select>'
320 . "\n" . ' <input type="checkbox" id="id_c_table_' . $i .'" name="c_table_' . $i . '[delete]" value="y" /><label for="id_c_table_' . $i .'">' . __('Delete') . '</label>';
321 echo "\n" . ' </td>';
323 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
324 echo "\n" . ' </td>';
326 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
327 echo "\n" . ' </td>';
328 echo "\n" . ' </tr>';
329 echo "\n" . ' </table>' . "\n";
331 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
332 echo "\n" . ' <input type="hidden" id="showwysiwyg" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />';
333 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . __('Column names') . '<br />';
334 echo "\n" . ' <input type="submit" value="' . __('Save') . '" />';
335 echo "\n" . '</form>' . "\n\n";
338 $this->_deleteTables($db, $this->chosenPage
, isset($tabExist));
342 * show Export relational schema generation options
343 * user can select export type of his own choice
344 * and the attributes related to it
350 public function displaySchemaGenerationOptions()
352 global $cfg,$pmaThemeImage,$db,$test_rs,$chpage;
354 <form method
="post" action
="schema_export.php">
358 echo PMA_generate_common_hidden_inputs($db);
359 if ($cfg['PropertiesIconic']) {
360 echo '<img class="icon ic_b_views" src="themes/dot.gif" />';
362 echo __('Display relational schema');
365 <select name
="export_type" id
="export_type">
366 <option value
="pdf" selected
="selected">PDF
</option
>
367 <option value
="svg">SVG
</option
>
368 <option value
="dia">DIA
</option
>
369 <option value
="visio">Visio
</option
>
370 <option value
="eps">EPS
</option
>
372 <label
><?php
echo __('Select Export Relational Type');?
></label
><br
/>
374 if (isset($test_rs)) {
376 <label
for="pdf_page_number_opt"><?php
echo __('Page number:'); ?
></label
>
377 <select name
="pdf_page_number" id
="pdf_page_number_opt">
379 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
380 echo ' <option value="' . $pages['page_nr'] . '">'
381 . $pages['page_nr'] . ': ' . htmlspecialchars($pages['page_descr']) . '</option>' . "\n";
383 PMA_DBI_free_result($test_rs);
388 <input type
="hidden" name
="pdf_page_number" value
="<?php echo htmlspecialchars($this->chosenPage); ?>" />
390 <input type
="hidden" name
="do" value
="process_export" />
391 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
392 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
393 <label
for="show_grid_opt"><?php
echo __('Show grid'); ?
></label
><br
/>
394 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
395 <label
for="show_color_opt"><?php
echo __('Show color'); ?
></label
><br
/>
396 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
397 <label
for="show_table_dim_opt"><?php
echo __('Show dimension of tables'); ?
>
399 <input type
="checkbox" name
="all_table_same_wide" id
="all_table_same_wide" />
400 <label
for="all_table_same_wide"><?php
echo __('Display all tables with the same width'); ?
>
402 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
403 <label
for="with_doc"><?php
echo __('Data Dictionary'); ?
></label
><br
/>
404 <input type
="checkbox" name
="show_keys" id
="show_keys" />
405 <label
for="show_keys"><?php
echo __('Only show keys'); ?
></label
><br
/>
406 <select name
="orientation" id
="orientation_opt" onchange
="refreshDragOption('pdflayout');" >
407 <option value
="L"><?php
echo __('Landscape');?
></option
>
408 <option value
="P"><?php
echo __('Portrait');?
></option
>
410 <label
for="orientation_opt"><?php
echo __('Orientation'); ?
></label
>
412 <select name
="paper" id
="paper_opt" onchange
="refreshDragOption('pdflayout');">
414 foreach ($cfg['PDFPageSizes'] as $key => $val) {
415 echo '<option value="' . $val . '"';
416 if ($val == $cfg['PDFDefaultPageSize']) {
417 echo ' selected="selected"';
419 echo ' >' . $val . '</option>' . "\n";
423 <label
for="paper_opt"><?php
echo __('Paper size'); ?
></label
>
425 <fieldset
class="tblFooters">
426 <input type
="submit" value
="<?php echo __('Go'); ?>" />
433 * Check if there are tables that need to be deleted in dashboard,
434 * if there are, ask the user for allowance
436 * @param string db name of database selected
437 * @param integer chpage selected page
438 * @param array tabExist
442 private function _deleteTables($db, $chpage, $tabExist)
448 if (!empty($tabExist) && is_array($tabExist)) {
449 foreach ($tabExist as $key => $value) {
451 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . htmlspecialchars($key) . '" />' . "\n";
452 $_strname .= '<li>' . htmlspecialchars($key) . '</li>' . "\n";
457 echo '<form action="schema_edit.php" method="post">' . "\n"
458 . PMA_generate_common_hidden_inputs($db, $table)
459 . '<input type="hidden" name="do" value="delete_old_references" />' . "\n"
460 . '<input type="hidden" name="chpage" value="' . htmlspecialchars($chpage) . '" />' . "\n"
461 . __('The current page has references to tables that no longer exist. Would you like to delete those references?')
466 . '<input type="submit" value="' . __('Go') . '" />' . "\n"
474 * Check if there are tables that need to be deleted in dashboard,
475 * if there are, ask the user for allowance
480 private function _displayScratchboardTables($array_sh_page)
482 global $with_field_names, $db;
484 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
485 <form method
="post" action
="schema_edit.php" name
="dragdrop">
486 <input type
="button" name
="dragdrop" value
="<?php echo __('Toggle scratchboard'); ?>" onclick
="ToggleDragDrop('pdflayout');" />
487 <input type
="button" name
="dragdropreset" value
="<?php echo __('Reset'); ?>" onclick
="resetDrag();" />
489 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
493 $reset_draginit = '';
495 foreach ($array_sh_page as $key => $temp_sh_page) {
496 $drag_x = $temp_sh_page['x'];
497 $drag_y = $temp_sh_page['y'];
499 $draginit2 .= ' Drag.init($("#table_' . $i . '")[0], null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
500 $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";
501 $draginit .= ' $("#table_' . $i . '")[0].style.left = "' . $drag_x . 'px";' . "\n";
502 $draginit .= ' $("#table_' . $i . '")[0].style.top = "' . $drag_y . 'px";' . "\n";
503 $reset_draginit .= ' $("#table_' . $i . '")[0].style.left = "2px";' . "\n";
504 $reset_draginit .= ' $("#table_' . $i . '")[0].style.top = "' . (15 * $i) . 'px";' . "\n";
505 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
506 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
508 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
509 if (isset($with_field_names)) {
510 $fields = PMA_DBI_get_columns($db, $temp_sh_page['table_name']);
511 foreach ($fields as $row) {
512 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
515 echo '</div>' . "\n";
520 <script type
="text/javascript">
524 myid
= $
('#pdflayout')[0];
525 <?php
echo $draginit; ?
>
529 function TableDragInit() {
530 myid
= $
('#pdflayout')[0];
531 <?php
echo $draginit2; ?
>
534 function resetDrag() {
535 <?php
echo $reset_draginit; ?
>
543 * delete the table rows with table co-ordinates
545 * @param int delrow delete selected table from list of tables
546 * @param array cfgRelation relation settings
547 * @param string db database name
548 * @param integer chpage selected page for adding relations etc
552 private function _deleteTableRows($delrow,$cfgRelation,$db,$chpage)
554 foreach ($delrow as $current_row) {
555 $del_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
556 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\'' . "\n"
557 . ' AND table_name = \'' . PMA_sqlAddSlashes($current_row) . '\'' . "\n"
558 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($chpage) . '\'';
560 PMA_query_as_controluser($del_query, false);
565 * get all the export options and verify
566 * call and include the appropriate Schema Class depending on $export_type
571 private function _processExportSchema()
574 * Settings for relation stuff
576 require_once './libraries/transformations.lib.php';
577 require_once './libraries/Index.class.php';
579 * default is PDF, otherwise validate it's only letters a-z
581 global $db,$export_type;
582 if (!isset($export_type) ||
!preg_match('/^[a-zA-Z]+$/', $export_type)) {
583 $export_type = 'pdf';
586 PMA_DBI_select_db($db);
588 include("./libraries/schema/".ucfirst($export_type)."_Relation_Schema.class.php");
589 $obj_schema = eval("new PMA_".ucfirst($export_type)."_Relation_Schema();");
593 * delete X and Y coordinates
595 * @param string db The database name
596 * @param array cfgRelation relation settings
597 * @param integer choosePage selected page for adding relations etc
601 public function deleteCoordinates($db, $cfgRelation, $choosePage)
603 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
604 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
605 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($choosePage) . '\'';
606 PMA_query_as_controluser($query, false);
612 * @param string db The database name
613 * @param array cfgRelation relation settings
614 * @param integer choosePage selected page for adding relations etc
618 public function deletePages($db, $cfgRelation, $choosePage)
620 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
621 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
622 . ' AND page_nr = \'' . PMA_sqlAddSlashes($choosePage) . '\'';
623 PMA_query_as_controluser($query, false);
627 * process internal and foreign key relations
629 * @param string db The database name
630 * @param array cfgRelation relation settings
631 * @param integer pageNumber document number/Id
635 public function processRelations($db, $pageNumber, $cfgRelation)
638 * A u t o m a t i c l a y o u t
640 * There are 2 kinds of relations in PMA
641 * 1) Internal Relations 2) Foreign Key Relations
643 if (isset($this->autoLayoutInternal
) ||
isset($this->autoLayoutForeign
)) {
644 $all_tables = array();
647 if (isset($this->autoLayoutForeign
)) {
649 * get the tables list
650 * who support FOREIGN KEY, it's not
651 * important that we group together InnoDB tables
652 * and PBXT tables, as this logic is just to put
653 * the tables on the layout, not to determine relations
655 $tables = PMA_DBI_get_tables_full($db);
656 $foreignkey_tables = array();
657 foreach ($tables as $table_name => $table_properties) {
658 if (PMA_foreignkey_supported($table_properties['ENGINE'])) {
659 $foreignkey_tables[] = $table_name;
662 $all_tables = $foreignkey_tables;
664 * could be improved by finding the tables which have the
665 * most references keys and placing them at the beginning
666 * of the array (so that they are all center of schema)
668 unset($tables, $foreignkey_tables);
671 if (isset($this->autoLayoutInternal
)) {
673 * get the tables list who support Internal Relations;
674 * This type of relations will be created when
675 * you setup the PMA tables correctly
677 $master_tables = 'SELECT COUNT(master_table), master_table'
678 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
679 . ' WHERE master_db = \'' . PMA_sqlAddSlashes($db) . '\''
680 . ' GROUP BY master_table'
681 . ' ORDER BY COUNT(master_table) DESC';
682 $master_tables_rs = PMA_query_as_controluser($master_tables, false, PMA_DBI_QUERY_STORE
);
683 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
684 /* first put all the master tables at beginning
685 * of the list, so they are near the center of
688 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
689 $all_tables[] = $master_table;
692 /* Now for each master, add its foreigns into an array
693 * of foreign tables, if not already there
694 * (a foreign might be foreign for more than
695 * one table, and might be a master itself)
698 $foreign_tables = array();
699 foreach ($all_tables as $master_table) {
700 $foreigners = PMA_getForeigners($db, $master_table);
701 foreach ($foreigners as $foreigner) {
702 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
703 $foreign_tables[] = $foreigner['foreign_table'];
709 * Now merge the master and foreign arrays/tables
711 foreach ($foreign_tables as $foreign_table) {
712 if (!in_array($foreign_table, $all_tables)) {
713 $all_tables[] = $foreign_table;
719 if (isset($this->autoLayoutInternal
) ||
isset($this->autoLayoutForeign
)) {
720 $this->addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation);
723 $this->chosenPage
= $pageNumber;
727 * Add X and Y coordinates for a table
729 * @param string db The database name
730 * @param array cfgRelation relation settings
731 * @param integer pageNumber document number/Id
732 * @param array all_tables A list of all tables involved
736 public function addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation)
739 * Now generate the coordinates for the schema
740 * in a clockwise spiral and add to co-ordinates table
746 $direction = "right";
747 foreach ($all_tables as $current_table) {
749 * save current table's coordinates
751 $insert_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
752 . '(db_name, table_name, pdf_page_number, x, y) '
753 . 'VALUES (\'' . PMA_sqlAddSlashes($db) . '\', \'' . PMA_sqlAddSlashes($current_table) . '\',' . $pageNumber . ',' . $pos_x . ',' . $pos_y . ')';
754 PMA_query_as_controluser($insert_query, false);
757 * compute for the next table
759 switch ($direction) {
763 $delta *= $delta_mult;
768 $delta *= $delta_mult;
773 $delta *= $delta_mult;
777 $direction = "right";
778 $delta *= $delta_mult;
785 * update X and Y coordinates for a table
787 * @param string db The database name
788 * @param array cfgRelation relation settings
792 private function _editCoordinates($db, $cfgRelation)
794 for ($i = 0; $i < $this->c_table_rows
; $i++
) {
795 $arrvalue = 'c_table_' . $i;
797 $arrvalue = $
$arrvalue;
798 if (! isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
801 if (! isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
804 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
805 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
806 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
807 . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\''
808 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage
) . '\'';
809 $test_rs = PMA_query_as_controluser($test_query, false, PMA_DBI_QUERY_STORE
);
811 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
812 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
813 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
814 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
815 . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\''
816 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage
) . '\'';
818 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
819 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
820 . ' WHERE db_name = \'' . PMA_sqlAddSlashes($db) . '\''
821 . ' AND table_name = \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\''
822 . ' AND pdf_page_number = \'' . PMA_sqlAddSlashes($this->chosenPage
) . '\'';
825 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
826 . '(db_name, table_name, pdf_page_number, x, y) '
827 . 'VALUES (\'' . PMA_sqlAddSlashes($db) . '\', \'' . PMA_sqlAddSlashes($arrvalue['name']) . '\', \'' . PMA_sqlAddSlashes($this->chosenPage
) . '\',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
830 PMA_query_as_controluser($ch_query, false);