2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 * This Class interacts with the user to gather the information
11 * about their tables for which they want to export the relational schema
12 * export options are shown to user from they can choose
23 public $autoLayoutForeign;
24 public $autoLayoutInternal;
29 public function setAction($value)
31 $this->action
= $value;
34 * This function will process the user defined pages
35 * and tables which will be exported as Relational schema
36 * you can set the table positions on the paper via scratchboard
37 * for table positions, put the x,y co-ordinates
39 * @param string $this->action It tells what the Schema is supposed to do
40 * create and select a page, generate schema etc
44 public function processUserPreferences()
46 global $action_choose,$db,$cfgRelation,$cfg,$query_default_option;
48 if (isset($this->action
)) {
49 switch ($this->action
) {
51 $this->choosenPage
= $_REQUEST['chpage'];
52 if ($action_choose=="1") {
53 $this->deleteCoordinates($db, $cfgRelation, $this->choosenPage
, $query_default_option);
54 $this->deletePages($db, $cfgRelation, $this->choosenPage
, $query_default_option);
55 $this->choosenPage
= 0;
59 $this->pageNumber
= PMA_REL_create_page($_POST['newpage'], $cfgRelation, $db, $query_default_option);
60 $this->autoLayoutForeign
= isset($_POST['auto_layout_foreign']) ?
"1":NULL;
61 $this->autoLayoutInternal
= isset($_POST['auto_layout_internal']) ?
"1":NULL;
62 $this->processRelations($db, $this->pageNumber
,$cfgRelation,$query_default_option);
65 $this->choosenPage
= $_POST['chpage'];
66 $this->c_table_rows
= $_POST['c_table_rows'];
67 $this->_editCoordinates($db, $cfgRelation,$query_default_option);
70 $this->_deleteTableRows($delrow,$cfgRelation,$db,$this->choosenPage
);
72 case 'process_export':
73 $this->_processExportSchema();
77 } // end if (isset($do))
82 * shows/displays the HTML FORM to create the page
84 * @param string db name of the selected database
88 public function createPage($db)
91 <form method
="post" action
="schema_edit.php" name
="frm_create_page">
94 <?php
echo __('Create a page') . "\n"; ?
>
96 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
97 <input type
="hidden" name
="do" value
="createpage" />
100 <td
><label
for="id_newpage"><?php
echo __('Page name'); ?
></label
></td
>
101 <td
><input type
="text" name
="newpage" id
="id_newpage" size
="20" maxlength
="50" /></td
>
104 <td
><?php
echo __('Automatic layout based on'); ?
></td
>
106 <input type
="checkbox" name
="auto_layout_internal" id
="id_auto_layout_internal" /><label
for="id_auto_layout_internal">
107 <?php
echo __('Internal relations'); ?
></label
><br
/>
110 * Check to see whether INNODB and PBXT storage engines are Available in MYSQL PACKAGE
111 * If available, then provide AutoLayout for Foreign Keys in Schema View
114 if (PMA_StorageEngine
::isValid('InnoDB') || PMA_StorageEngine
::isValid('PBXT')) {
116 <input type
="checkbox" name
="auto_layout_foreign" id
="id_auto_layout_foreign" /><label
for="id_auto_layout_foreign">
117 <?php
echo __('FOREIGN KEY'); ?
></label
><br
/>
124 <fieldset
class="tblFooters">
125 <input type
="submit" value
="<?php echo __('Go'); ?>" />
132 * shows/displays the created page names in a drop down list
133 * User can select any page number and edit it using dashboard etc
138 public function selectPage()
140 global $db,$table,$query_default_option,$cfgRelation;
141 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
142 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
143 $page_rs = PMA_query_as_controluser($page_query, FALSE, $query_default_option);
144 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
146 <form method
="get" action
="schema_edit.php" name
="frm_select_page">
149 <?php
echo __('Please choose a page to edit') . "\n"; ?
>
151 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
152 <input type
="hidden" name
="do" value
="selectpage" />
153 <select name
="chpage" id
="chpage" onchange
="this.form.submit()">
154 <option value
="0"><?php
echo __('Select page'); ?
></option
>
156 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
158 . '<option value="' . $curr_page['page_nr'] . '"';
159 if (isset($this->choosenPage
) && $this->choosenPage
== $curr_page['page_nr']) {
160 echo ' selected="selected"';
162 echo '>' . $curr_page['page_nr'] . ': ' . htmlspecialchars($curr_page['page_descr']) . '</option>';
172 PMA_display_html_radio('action_choose', $choices, '0', false);
176 <fieldset
class="tblFooters">
177 <input type
="submit" value
="<?php echo __('Go'); ?>" /><br
/>
186 * A dashboard is displayed to AutoLayout the position of tables
187 * users can drag n drop the tables and change their positions
192 public function showTableDashBoard()
194 global $db,$cfgRelation,$table,$cfg,$with_field_names,$query_default_option;
196 * We will need an array of all tables in this db
198 $selectboxall = array('--');
199 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
200 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
201 $selectboxall[] = $val[0];
205 * Now if we already have chosen a page number then we should
206 * show the tables involved
209 if (isset($this->choosenPage
) && $this->choosenPage
> 0) {
212 <h2
><?php
echo __('Select Tables') ;?
></h2
>
214 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
215 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
216 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->choosenPage
) . '\'';
217 $page_rs = PMA_query_as_controluser($page_query, FALSE, $query_default_option);
218 $array_sh_page = array();
219 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
220 $array_sh_page[] = $temp_sh_page;
223 * Display WYSIWYG parts
226 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
227 $with_field_names = TRUE;
229 $this->_displayScratchboardTables($array_sh_page);
232 <form method
="post" action
="schema_edit.php" name
="edcoord">
233 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
234 <input type
="hidden" name
="chpage" value
="<?php echo htmlspecialchars($this->choosenPage); ?>" />
235 <input type
="hidden" name
="do" value
="edcoord" />
238 <th
><?php
echo __('Table'); ?
></th
>
239 <th
><?php
echo __('Delete'); ?
></th
>
244 if (isset($ctable)) {
250 foreach ($array_sh_page as $dummy_sh_page => $sh_page) {
251 $_mtab = $sh_page['table_name'];
252 $tabExist[$_mtab] = FALSE;
253 echo "\n" . ' <tr class="';
260 $odd_row != $odd_row;
262 . "\n" . ' <select name="c_table_' . $i . '[name]">';
263 foreach ($selectboxall as $key => $value) {
264 echo "\n" . ' <option value="' . htmlspecialchars($value) . '"';
265 if ($value == $sh_page['table_name']) {
266 echo ' selected="selected"';
267 $tabExist[$_mtab] = TRUE;
269 echo '>' . htmlspecialchars($value) . '</option>';
271 echo "\n" . ' </select>'
274 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . __('Delete');
275 echo "\n" . ' </td>';
277 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'x\', this.value)" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
278 echo "\n" . ' </td>';
280 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'y\', this.value)" name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
281 echo "\n" . ' </td>';
282 echo "\n" . ' </tr>';
286 * Add one more empty row
288 echo "\n" . ' <tr class="';
294 $odd_row != $odd_row;
297 . "\n" . ' <select name="c_table_' . $i . '[name]">';
298 foreach ($selectboxall as $key => $value) {
299 echo "\n" . ' <option value="' . htmlspecialchars($value) . '">' . htmlspecialchars($value) . '</option>';
301 echo "\n" . ' </select>'
304 . "\n" . ' <input type="checkbox" name="c_table_' . $i . '[delete]" value="y" />' . __('Delete');
305 echo "\n" . ' </td>';
307 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
308 echo "\n" . ' </td>';
310 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
311 echo "\n" . ' </td>';
312 echo "\n" . ' </tr>';
313 echo "\n" . ' </table>' . "\n";
315 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
316 echo "\n" . ' <input type="hidden" id="showwysiwyg" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />';
317 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . __('Column names') . '<br />';
318 echo "\n" . ' <input type="submit" value="' . __('Save') . '" />';
319 echo "\n" . '</form>' . "\n\n";
322 $this->_deleteTables($db, $this->choosenPage
, isset($tabExist));
326 * show Export relational schema generation options
327 * user can select export type of his own choice
328 * and the attributes related to it
334 public function displaySchemaGenerationOptions()
336 global $cfg,$pmaThemeImage,$db,$test_rs,$chpage;
338 <form method
="post" action
="schema_export.php">
342 echo PMA_generate_common_hidden_inputs($db);
343 if ($cfg['PropertiesIconic']) {
344 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
345 .' alt="" width="16" height="16" />';
347 echo __('Display relational schema');
350 <select name
="export_type" id
="export_type">
351 <option value
="pdf" selected
="selected"><?php
echo __('PDF');?
></option
>
352 <option value
="svg"><?php
echo __('SVG');?
></option
>
353 <option value
="dia"><?php
echo __('DIA');?
></option
>
354 <option value
="visio"><?php
echo __('VISIO');?
></option
>
355 <option value
="eps"><?php
echo __('EPS');?
></option
>
357 <label
><?php
echo __('Select Export Relational Type');?
></label
><br
/>
359 if (isset($test_rs)) {
361 <label
for="pdf_page_number_opt"><?php
echo __('Page number:'); ?
></label
>
362 <select name
="pdf_page_number" id
="pdf_page_number_opt">
364 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
365 echo ' <option value="' . $pages['page_nr'] . '">'
366 . $pages['page_nr'] . ': ' . htmlspecialchars($pages['page_descr']) . '</option>' . "\n";
368 PMA_DBI_free_result($test_rs);
373 <input type
="hidden" name
="pdf_page_number" value
="<?php echo htmlspecialchars($this->choosenPage); ?>" />
375 <input type
="hidden" name
="do" value
="process_export" />
376 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
377 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
378 <label
for="show_grid_opt"><?php
echo __('Show grid'); ?
></label
><br
/>
379 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
380 <label
for="show_color_opt"><?php
echo __('Show color'); ?
></label
><br
/>
381 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
382 <label
for="show_table_dim_opt"><?php
echo __('Show dimension of tables'); ?
>
384 <input type
="checkbox" name
="all_table_same_wide" id
="all_table_same_wide" />
385 <label
for="all_table_same_wide"><?php
echo __('Display all tables with the same width'); ?
>
387 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
388 <label
for="with_doc"><?php
echo __('Data Dictionary'); ?
></label
><br
/>
389 <input type
="checkbox" name
="show_keys" id
="show_keys" />
390 <label
for="show_keys"><?php
echo __('Only show keys'); ?
></label
><br
/>
391 <select name
="orientation" id
="orientation_opt" onchange
="refreshDragOption('pdflayout');" >
392 <option value
="L"><?php
echo __('Landscape');?
></option
>
393 <option value
="P"><?php
echo __('Portrait');?
></option
>
395 <label
for="orientation_opt"><?php
echo __('Orientation'); ?
></label
>
397 <select name
="paper" id
="paper_opt" onchange
="refreshDragOption('pdflayout');">
399 foreach ($cfg['PDFPageSizes'] as $key => $val) {
400 echo '<option value="' . $val . '"';
401 if ($val == $cfg['PDFDefaultPageSize']) {
402 echo ' selected="selected"';
404 echo ' >' . $val . '</option>' . "\n";
408 <label
for="paper_opt"><?php
echo __('Paper size'); ?
></label
>
410 <fieldset
class="tblFooters">
411 <input type
="submit" value
="<?php echo __('Go'); ?>" />
418 * Check if there are tables that need to be deleted in dashboard,
419 * if there are, ask the user for allowance
421 * @param string db name of database selected
422 * @param integer chpage selected page
423 * @param array tabExist
427 private function _deleteTables($db, $chpage, $tabExist)
432 if (!empty($tabExist) && is_array($tabExist)) {
433 foreach ($tabExist as $key => $value) {
435 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . htmlspecialchars($key) . '" />' . "\n";
436 $_strname .= '<li>' . htmlspecialchars($key) . '</li>' . "\n";
441 echo '<form action="schema_edit.php" method="post">' . "\n"
442 . PMA_generate_common_hidden_inputs($db, $table)
443 . '<input type="hidden" name="do" value="deleteCrap" />' . "\n"
444 . '<input type="hidden" name="chpage" value="' . htmlspecialchars($chpage) . '" />' . "\n"
445 . __('The current page has references to tables that no longer exist. Would you like to delete those references?')
450 . '<input type="submit" value="' . __('Go') . '" />' . "\n"
458 * Check if there are tables that need to be deleted in dashboard,
459 * if there are, ask the user for allowance
464 private function _displayScratchboardTables($array_sh_page)
466 global $with_field_names,$cfg,$db;
468 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
469 <form method
="post" action
="schema_edit.php" name
="dragdrop">
470 <input type
="button" name
="dragdrop" value
="<?php echo __('Toggle scratchboard'); ?>" onclick
="ToggleDragDrop('pdflayout');" />
471 <input type
="button" name
="dragdropreset" value
="<?php echo __('Reset'); ?>" onclick
="resetDrag();" />
473 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
477 $reset_draginit = '';
479 foreach ($array_sh_page as $key => $temp_sh_page) {
480 $drag_x = $temp_sh_page['x'];
481 $drag_y = $temp_sh_page['y'];
483 $draginit2 .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
484 $draginit .= ' getElement("table_' . $i . '").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";
485 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
486 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
487 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
488 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
489 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
490 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
492 $local_query = 'SHOW FIELDS FROM '
493 . PMA_backquote($temp_sh_page['table_name'])
494 . ' FROM ' . PMA_backquote($db);
495 $fields_rs = PMA_DBI_query($local_query);
497 $fields_cnt = PMA_DBI_num_rows($fields_rs);
499 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
500 if (isset($with_field_names)) {
501 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
502 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
505 echo '</div>' . "\n";
506 PMA_DBI_free_result($fields_rs);
512 <script type
="text/javascript">
516 myid
= getElement('pdflayout');
517 <?php
echo $draginit; ?
>
521 function TableDragInit() {
522 myid
= getElement('pdflayout');
523 <?php
echo $draginit2; ?
>
526 function resetDrag() {
527 <?php
echo $reset_draginit; ?
>
535 * delete the table rows with table co-ordinates
537 * @param int delrow delete selected table from list of tables
538 * @param array cfgRelation relation settings
539 * @param string db database name
540 * @param integer chpage selected page for adding relations etc
544 private function _deleteTableRows($delrow,$cfgRelation,$db,$chpage)
546 foreach ($delrow as $current_row) {
547 $del_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
548 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
549 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
550 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($chpage) . '\'';
552 PMA_query_as_controluser($del_query, FALSE, $query_default_option);
557 * get all the export options and verify
558 * call and include the appropriate Schema Class depending on $export_type
563 private function _processExportSchema()
566 * Settings for relation stuff
568 require_once './libraries/transformations.lib.php';
569 require_once './libraries/Index.class.php';
573 global $db,$export_type;
574 $export_type = isset($export_type) ?
$export_type : 'pdf';
575 PMA_DBI_select_db($db);
577 include("./libraries/schema/".ucfirst($export_type)."_Relation_Schema.class.php");
578 $obj_schema = eval("new PMA_".ucfirst($export_type)."_Relation_Schema();");
582 * delete X and Y coordinates
584 * @param string db The database name
585 * @param array cfgRelation relation settings
586 * @param integer choosePage selected page for adding relations etc
590 public function deleteCoordinates($db, $cfgRelation, $choosePage, $query_default_option)
592 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
593 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
594 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($choosePage) . '\'';
595 PMA_query_as_controluser($query, FALSE, $query_default_option);
601 * @param string db The database name
602 * @param array cfgRelation relation settings
603 * @param integer choosePage selected page for adding relations etc
607 public function deletePages($db, $cfgRelation, $choosePage, $query_default_option)
609 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
610 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
611 . ' AND page_nr = \'' . PMA_sqlAddslashes($choosePage) . '\'';
612 PMA_query_as_controluser($query, FALSE, $query_default_option);
616 * process internal and foreign key relations
618 * @param string db The database name
619 * @param array cfgRelation relation settings
620 * @param integer pageNumber document number/Id
624 public function processRelations($db, $pageNumber, $cfgRelation, $query_default_option)
627 * A u t o m a t i c l a y o u t
629 * There are 2 kinds of relations in PMA
630 * 1) Internal Relations 2) Foreign Key Relations
632 if (isset($this->autoLayoutInternal
) ||
isset($this->autoLayoutForeign
)) {
633 $all_tables = array();
636 if (isset($this->autoLayoutForeign
)) {
638 * get the tables list
639 * who support FOREIGN KEY, it's not
640 * important that we group together InnoDB tables
641 * and PBXT tables, as this logic is just to put
642 * the tables on the layout, not to determine relations
644 $tables = PMA_DBI_get_tables_full($db);
645 $foreignkey_tables = array();
646 foreach($tables as $table_name => $table_properties) {
647 if (PMA_foreignkey_supported($table_properties['ENGINE'])) {
648 $foreignkey_tables[] = $table_name;
651 $all_tables = $foreignkey_tables;
653 * could be improved by finding the tables which have the
654 * most references keys and placing them at the beginning
655 * of the array (so that they are all center of schema)
657 unset($tables, $foreignkey_tables);
660 if (isset($this->autoLayoutInternal
)) {
662 * get the tables list who support Internal Relations;
663 * This type of relations will be created when
664 * you setup the PMA tables correctly
666 $master_tables = 'SELECT COUNT(master_table), master_table'
667 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
668 . ' WHERE master_db = \'' . $db . '\''
669 . ' GROUP BY master_table'
670 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
671 $master_tables_rs = PMA_query_as_controluser($master_tables, FALSE, $query_default_option);
672 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
673 /* first put all the master tables at beginning
674 * of the list, so they are near the center of
677 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
678 $all_tables[] = $master_table;
681 /* Now for each master, add its foreigns into an array
682 * of foreign tables, if not already there
683 * (a foreign might be foreign for more than
684 * one table, and might be a master itself)
687 $foreign_tables = array();
688 foreach ($all_tables as $master_table) {
689 $foreigners = PMA_getForeigners($db, $master_table);
690 foreach ($foreigners as $foreigner) {
691 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
692 $foreign_tables[] = $foreigner['foreign_table'];
698 * Now merge the master and foreign arrays/tables
700 foreach ($foreign_tables as $foreign_table) {
701 if (!in_array($foreign_table, $all_tables)) {
702 $all_tables[] = $foreign_table;
708 if (isset($this->autoLayoutInternal
) ||
isset($this->autoLayoutForeign
)) {
709 $this->addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation,$query_default_option);
712 $this->choosenPage
= $pageNumber;
716 * Add X and Y coordinates for a table
718 * @param string db The database name
719 * @param array cfgRelation relation settings
720 * @param integer pageNumber document number/Id
721 * @param array all_tables A list of all tables involved
725 public function addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation,$query_default_option)
728 * Now generate the coordinates for the schema
729 * in a clockwise spiral and add to co-ordinates table
735 $direction = "right";
736 foreach ($all_tables as $current_table) {
738 * save current table's coordinates
740 $insert_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
741 . '(db_name, table_name, pdf_page_number, x, y) '
742 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pageNumber . ',' . $pos_x . ',' . $pos_y . ')';
743 PMA_query_as_controluser($insert_query, FALSE, $query_default_option);
746 * compute for the next table
748 switch ($direction) {
752 $delta *= $delta_mult;
757 $delta *= $delta_mult;
762 $delta *= $delta_mult;
766 $direction = "right";
767 $delta *= $delta_mult;
774 * update X and Y coordinates for a table
776 * @param string db The database name
777 * @param array cfgRelation relation settings
781 private function _editCoordinates($db, $cfgRelation,$query_default_option)
783 for ($i = 0; $i < $this->c_table_rows
; $i++
) {
784 $arrvalue = 'c_table_' . $i;
786 $arrvalue = $
$arrvalue;
787 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
790 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
793 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
794 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
795 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
796 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
797 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->choosenPage
) . '\'';
798 $test_rs = PMA_query_as_controluser($test_query, FALSE, $query_default_option);
800 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
801 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
802 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
803 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
804 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
805 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->choosenPage
) . '\'';
807 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
808 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
809 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
810 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
811 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->choosenPage
) . '\'';
814 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
815 . '(db_name, table_name, pdf_page_number, x, y) '
816 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\', \'' . PMA_sqlAddslashes($this->choosenPage
) . '\',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
819 PMA_query_as_controluser($ch_query, FALSE, $query_default_option);