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
22 public $autoLayoutForeign;
23 public $autoLayoutInternal;
28 public function setAction($value)
30 $this->action
= $value;
33 * This function will process the user defined pages
34 * and tables which will be exported as Relational schema
35 * you can set the table positions on the paper via scratchboard
36 * for table positions, put the x,y co-ordinates
38 * @param string $this->action It tells what the Schema is supposed to do
39 * create and select a page, generate schema etc
43 public function processUserChoice()
45 global $action_choose,$db,$cfgRelation,$cfg,$query_default_option;
47 if (isset($this->action
)) {
48 switch ($this->action
) {
50 $this->chosenPage
= $_REQUEST['chpage'];
51 if ($action_choose=="1") {
52 $this->deleteCoordinates($db, $cfgRelation, $this->chosenPage
, $query_default_option);
53 $this->deletePages($db, $cfgRelation, $this->chosenPage
, $query_default_option);
54 $this->chosenPage
= 0;
58 $this->pageNumber
= PMA_REL_create_page($_POST['newpage'], $cfgRelation, $db, $query_default_option);
59 $this->autoLayoutForeign
= isset($_POST['auto_layout_foreign']) ?
"1":NULL;
60 $this->autoLayoutInternal
= isset($_POST['auto_layout_internal']) ?
"1":NULL;
61 $this->processRelations($db, $this->pageNumber
,$cfgRelation,$query_default_option);
64 $this->chosenPage
= $_POST['chpage'];
65 $this->c_table_rows
= $_POST['c_table_rows'];
66 $this->_editCoordinates($db, $cfgRelation,$query_default_option);
68 case 'delete_old_references':
69 $this->_deleteTableRows($delrow,$cfgRelation,$db,$this->chosenPage
);
71 case 'process_export':
72 $this->_processExportSchema();
76 } // end if (isset($do))
81 * shows/displays the HTML FORM to create the page
83 * @param string db name of the selected database
87 public function showCreatePageDialog($db)
90 <form method
="post" action
="schema_edit.php" name
="frm_create_page">
93 <?php
echo __('Create a page') . "\n"; ?
>
95 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
96 <input type
="hidden" name
="do" value
="createpage" />
99 <td
><label
for="id_newpage"><?php
echo __('Page name'); ?
></label
></td
>
100 <td
><input type
="text" name
="newpage" id
="id_newpage" size
="20" maxlength
="50" /></td
>
103 <td
><?php
echo __('Automatic layout based on'); ?
></td
>
105 <input type
="checkbox" name
="auto_layout_internal" id
="id_auto_layout_internal" /><label
for="id_auto_layout_internal">
106 <?php
echo __('Internal relations'); ?
></label
><br
/>
109 * Check to see whether INNODB and PBXT storage engines are Available in MYSQL PACKAGE
110 * If available, then provide AutoLayout for Foreign Keys in Schema View
113 if (PMA_StorageEngine
::isValid('InnoDB') || PMA_StorageEngine
::isValid('PBXT')) {
115 <input type
="checkbox" name
="auto_layout_foreign" id
="id_auto_layout_foreign" /><label
for="id_auto_layout_foreign">
116 <?php
echo __('FOREIGN KEY'); ?
></label
><br
/>
123 <fieldset
class="tblFooters">
124 <input type
="submit" value
="<?php echo __('Go'); ?>" />
131 * shows/displays the created page names in a drop down list
132 * User can select any page number and edit it using dashboard etc
137 public function selectPage()
139 global $db,$table,$query_default_option,$cfgRelation;
140 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
141 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
142 $page_rs = PMA_query_as_controluser($page_query, FALSE, $query_default_option);
143 if ($page_rs && PMA_DBI_num_rows($page_rs) > 0) {
145 <form method
="get" action
="schema_edit.php" name
="frm_select_page">
148 <?php
echo __('Please choose a page to edit') . "\n"; ?
>
150 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
151 <input type
="hidden" name
="do" value
="selectpage" />
152 <select name
="chpage" id
="chpage" onchange
="this.form.submit()">
153 <option value
="0"><?php
echo __('Select page'); ?
></option
>
155 while ($curr_page = PMA_DBI_fetch_assoc($page_rs)) {
157 . '<option value="' . $curr_page['page_nr'] . '"';
158 if (isset($this->chosenPage
) && $this->chosenPage
== $curr_page['page_nr']) {
159 echo ' selected="selected"';
161 echo '>' . $curr_page['page_nr'] . ': ' . htmlspecialchars($curr_page['page_descr']) . '</option>';
171 PMA_display_html_radio('action_choose', $choices, '0', false);
175 <fieldset
class="tblFooters">
176 <input type
="submit" value
="<?php echo __('Go'); ?>" /><br
/>
185 * A dashboard is displayed to AutoLayout the position of tables
186 * users can drag n drop the tables and change their positions
191 public function showTableDashBoard()
193 global $db,$cfgRelation,$table,$cfg,$with_field_names,$query_default_option;
195 * We will need an array of all tables in this db
197 $selectboxall = array('--');
198 $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
199 while ($val = @PMA_DBI_fetch_row
($alltab_rs)) {
200 $selectboxall[] = $val[0];
204 * Now if we already have chosen a page number then we should
205 * show the tables involved
208 if (isset($this->chosenPage
) && $this->chosenPage
> 0) {
211 <h2
><?php
echo __('Select Tables') ;?
></h2
>
213 $page_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
214 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
215 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->chosenPage
) . '\'';
216 $page_rs = PMA_query_as_controluser($page_query, FALSE, $query_default_option);
217 $array_sh_page = array();
218 while ($temp_sh_page = @PMA_DBI_fetch_assoc
($page_rs)) {
219 $array_sh_page[] = $temp_sh_page;
222 * Display WYSIWYG parts
225 if (!isset($_POST['with_field_names']) && !isset($_POST['showwysiwyg'])) {
226 $with_field_names = TRUE;
228 $this->_displayScratchboardTables($array_sh_page);
231 <form method
="post" action
="schema_edit.php" name
="edcoord">
232 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
233 <input type
="hidden" name
="chpage" value
="<?php echo htmlspecialchars($this->chosenPage); ?>" />
234 <input type
="hidden" name
="do" value
="edcoord" />
237 <th
><?php
echo __('Table'); ?
></th
>
238 <th
><?php
echo __('Delete'); ?
></th
>
243 if (isset($ctable)) {
249 foreach ($array_sh_page as $dummy_sh_page => $sh_page) {
250 $_mtab = $sh_page['table_name'];
251 $tabExist[$_mtab] = FALSE;
252 echo "\n" . ' <tr class="noclick ';
259 $odd_row != $odd_row;
261 . "\n" . ' <select name="c_table_' . $i . '[name]">';
262 foreach ($selectboxall as $key => $value) {
263 echo "\n" . ' <option value="' . htmlspecialchars($value) . '"';
264 if ($value == $sh_page['table_name']) {
265 echo ' selected="selected"';
266 $tabExist[$_mtab] = TRUE;
268 echo '>' . htmlspecialchars($value) . '</option>';
270 echo "\n" . ' </select>'
273 . "\n" . ' <input type="checkbox" id="id_c_table_' . $i .'" name="c_table_' . $i . '[delete]" value="y" /><label for="id_c_table_' . $i .'">' . __('Delete') . '</label>';
274 echo "\n" . ' </td>';
276 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'x\', this.value)" name="c_table_' . $i . '[x]" value="' . $sh_page['x'] . '" />';
277 echo "\n" . ' </td>';
279 . "\n" . ' <input type="text" onchange="dragPlace(' . $i . ', \'y\', this.value)" name="c_table_' . $i . '[y]" value="' . $sh_page['y'] . '" />';
280 echo "\n" . ' </td>';
281 echo "\n" . ' </tr>';
285 * Add one more empty row
287 echo "\n" . ' <tr class="noclick ';
293 $odd_row != $odd_row;
296 . "\n" . ' <select name="c_table_' . $i . '[name]">';
297 foreach ($selectboxall as $key => $value) {
298 echo "\n" . ' <option value="' . htmlspecialchars($value) . '">' . htmlspecialchars($value) . '</option>';
300 echo "\n" . ' </select>'
303 . "\n" . ' <input type="checkbox" id="id_c_table_' . $i .'" name="c_table_' . $i . '[delete]" value="y" /><label for="id_c_table_' . $i .'">' . __('Delete') . '</label>';
304 echo "\n" . ' </td>';
306 . "\n" . ' <input type="text" name="c_table_' . $i . '[x]" value="' . (isset($sh_page['x'])?
$sh_page['x']:'') . '" />';
307 echo "\n" . ' </td>';
309 . "\n" . ' <input type="text" name="c_table_' . $i . '[y]" value="' . (isset($sh_page['y'])?
$sh_page['y']:'') . '" />';
310 echo "\n" . ' </td>';
311 echo "\n" . ' </tr>';
312 echo "\n" . ' </table>' . "\n";
314 echo "\n" . ' <input type="hidden" name="c_table_rows" value="' . ($i +
1) . '" />';
315 echo "\n" . ' <input type="hidden" id="showwysiwyg" name="showwysiwyg" value="' . ((isset($showwysiwyg) && $showwysiwyg == '1') ?
'1' : '0') . '" />';
316 echo "\n" . ' <input type="checkbox" name="with_field_names" ' . (isset($with_field_names) ?
'checked="checked"' : ''). ' />' . __('Column names') . '<br />';
317 echo "\n" . ' <input type="submit" value="' . __('Save') . '" />';
318 echo "\n" . '</form>' . "\n\n";
321 $this->_deleteTables($db, $this->chosenPage
, isset($tabExist));
325 * show Export relational schema generation options
326 * user can select export type of his own choice
327 * and the attributes related to it
333 public function displaySchemaGenerationOptions()
335 global $cfg,$pmaThemeImage,$db,$test_rs,$chpage;
337 <form method
="post" action
="schema_export.php">
341 echo PMA_generate_common_hidden_inputs($db);
342 if ($cfg['PropertiesIconic']) {
343 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
344 .' alt="" width="16" height="16" />';
346 echo __('Display relational schema');
349 <select name
="export_type" id
="export_type">
350 <option value
="pdf" selected
="selected">PDF
</option
>
351 <option value
="svg">SVG
</option
>
352 <option value
="dia">DIA
</option
>
353 <option value
="visio">Visio
</option
>
354 <option value
="eps">EPS
</option
>
356 <label
><?php
echo __('Select Export Relational Type');?
></label
><br
/>
358 if (isset($test_rs)) {
360 <label
for="pdf_page_number_opt"><?php
echo __('Page number:'); ?
></label
>
361 <select name
="pdf_page_number" id
="pdf_page_number_opt">
363 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
364 echo ' <option value="' . $pages['page_nr'] . '">'
365 . $pages['page_nr'] . ': ' . htmlspecialchars($pages['page_descr']) . '</option>' . "\n";
367 PMA_DBI_free_result($test_rs);
372 <input type
="hidden" name
="pdf_page_number" value
="<?php echo htmlspecialchars($this->chosenPage); ?>" />
374 <input type
="hidden" name
="do" value
="process_export" />
375 <input type
="hidden" name
="chpage" value
="<?php echo $chpage; ?>" />
376 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
377 <label
for="show_grid_opt"><?php
echo __('Show grid'); ?
></label
><br
/>
378 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
379 <label
for="show_color_opt"><?php
echo __('Show color'); ?
></label
><br
/>
380 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
381 <label
for="show_table_dim_opt"><?php
echo __('Show dimension of tables'); ?
>
383 <input type
="checkbox" name
="all_table_same_wide" id
="all_table_same_wide" />
384 <label
for="all_table_same_wide"><?php
echo __('Display all tables with the same width'); ?
>
386 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
387 <label
for="with_doc"><?php
echo __('Data Dictionary'); ?
></label
><br
/>
388 <input type
="checkbox" name
="show_keys" id
="show_keys" />
389 <label
for="show_keys"><?php
echo __('Only show keys'); ?
></label
><br
/>
390 <select name
="orientation" id
="orientation_opt" onchange
="refreshDragOption('pdflayout');" >
391 <option value
="L"><?php
echo __('Landscape');?
></option
>
392 <option value
="P"><?php
echo __('Portrait');?
></option
>
394 <label
for="orientation_opt"><?php
echo __('Orientation'); ?
></label
>
396 <select name
="paper" id
="paper_opt" onchange
="refreshDragOption('pdflayout');">
398 foreach ($cfg['PDFPageSizes'] as $key => $val) {
399 echo '<option value="' . $val . '"';
400 if ($val == $cfg['PDFDefaultPageSize']) {
401 echo ' selected="selected"';
403 echo ' >' . $val . '</option>' . "\n";
407 <label
for="paper_opt"><?php
echo __('Paper size'); ?
></label
>
409 <fieldset
class="tblFooters">
410 <input type
="submit" value
="<?php echo __('Go'); ?>" />
417 * Check if there are tables that need to be deleted in dashboard,
418 * if there are, ask the user for allowance
420 * @param string db name of database selected
421 * @param integer chpage selected page
422 * @param array tabExist
426 private function _deleteTables($db, $chpage, $tabExist)
431 if (!empty($tabExist) && is_array($tabExist)) {
432 foreach ($tabExist as $key => $value) {
434 $_strtrans .= '<input type="hidden" name="delrow[]" value="' . htmlspecialchars($key) . '" />' . "\n";
435 $_strname .= '<li>' . htmlspecialchars($key) . '</li>' . "\n";
440 echo '<form action="schema_edit.php" method="post">' . "\n"
441 . PMA_generate_common_hidden_inputs($db, $table)
442 . '<input type="hidden" name="do" value="delete_old_references" />' . "\n"
443 . '<input type="hidden" name="chpage" value="' . htmlspecialchars($chpage) . '" />' . "\n"
444 . __('The current page has references to tables that no longer exist. Would you like to delete those references?')
449 . '<input type="submit" value="' . __('Go') . '" />' . "\n"
457 * Check if there are tables that need to be deleted in dashboard,
458 * if there are, ask the user for allowance
463 private function _displayScratchboardTables($array_sh_page)
465 global $with_field_names,$cfg,$db;
467 <script type
="text/javascript" src
="./js/dom-drag.js"></script
>
468 <form method
="post" action
="schema_edit.php" name
="dragdrop">
469 <input type
="button" name
="dragdrop" value
="<?php echo __('Toggle scratchboard'); ?>" onclick
="ToggleDragDrop('pdflayout');" />
470 <input type
="button" name
="dragdropreset" value
="<?php echo __('Reset'); ?>" onclick
="resetDrag();" />
472 <div id
="pdflayout" class="pdflayout" style
="visibility: hidden;">
476 $reset_draginit = '';
478 foreach ($array_sh_page as $key => $temp_sh_page) {
479 $drag_x = $temp_sh_page['x'];
480 $drag_y = $temp_sh_page['y'];
482 $draginit2 .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n";
483 $draginit2 .= ' 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";
484 $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n";
485 $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n";
486 $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n";
487 $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . (15 * $i) . 'px";' . "\n";
488 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n";
489 $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . (15 * $i) . '"' . "\n";
491 $local_query = 'SHOW FIELDS FROM '
492 . PMA_backquote($temp_sh_page['table_name'])
493 . ' FROM ' . PMA_backquote($db);
494 $fields_rs = PMA_DBI_try_query($local_query);
496 // the table has been dropped from outside phpMyAdmin
497 if (PMA_DBI_getError()) {
500 echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>';
501 if (isset($with_field_names)) {
502 while ($row = PMA_DBI_fetch_assoc($fields_rs)) {
503 echo '<br />' . htmlspecialchars($row['Field']) . "\n";
506 echo '</div>' . "\n";
507 PMA_DBI_free_result($fields_rs);
513 <script type
="text/javascript">
517 myid
= getElement('pdflayout');
518 <?php
echo $draginit; ?
>
522 function TableDragInit() {
523 myid
= getElement('pdflayout');
524 <?php
echo $draginit2; ?
>
527 function resetDrag() {
528 <?php
echo $reset_draginit; ?
>
536 * delete the table rows with table co-ordinates
538 * @param int delrow delete selected table from list of tables
539 * @param array cfgRelation relation settings
540 * @param string db database name
541 * @param integer chpage selected page for adding relations etc
545 private function _deleteTableRows($delrow,$cfgRelation,$db,$chpage)
547 foreach ($delrow as $current_row) {
548 $del_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' ' . "\n"
549 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . "\n"
550 . ' AND table_name = \'' . PMA_sqlAddslashes($current_row) . '\'' . "\n"
551 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($chpage) . '\'';
553 PMA_query_as_controluser($del_query, FALSE, $query_default_option);
558 * get all the export options and verify
559 * call and include the appropriate Schema Class depending on $export_type
564 private function _processExportSchema()
567 * Settings for relation stuff
569 require_once './libraries/transformations.lib.php';
570 require_once './libraries/Index.class.php';
572 * default is PDF, otherwise validate it's only letters a-z
574 global $db,$export_type;
575 if (!isset($export_type) ||
!preg_match('/^[a-zA-Z]+$/', $export_type)) {
576 $export_type = 'pdf';
579 PMA_DBI_select_db($db);
581 include("./libraries/schema/".ucfirst($export_type)."_Relation_Schema.class.php");
582 $obj_schema = eval("new PMA_".ucfirst($export_type)."_Relation_Schema();");
586 * delete X and Y coordinates
588 * @param string db The database name
589 * @param array cfgRelation relation settings
590 * @param integer choosePage selected page for adding relations etc
594 public function deleteCoordinates($db, $cfgRelation, $choosePage, $query_default_option)
596 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
597 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
598 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($choosePage) . '\'';
599 PMA_query_as_controluser($query, FALSE, $query_default_option);
605 * @param string db The database name
606 * @param array cfgRelation relation settings
607 * @param integer choosePage selected page for adding relations etc
611 public function deletePages($db, $cfgRelation, $choosePage, $query_default_option)
613 $query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages'])
614 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
615 . ' AND page_nr = \'' . PMA_sqlAddslashes($choosePage) . '\'';
616 PMA_query_as_controluser($query, FALSE, $query_default_option);
620 * process internal and foreign key relations
622 * @param string db The database name
623 * @param array cfgRelation relation settings
624 * @param integer pageNumber document number/Id
628 public function processRelations($db, $pageNumber, $cfgRelation, $query_default_option)
631 * A u t o m a t i c l a y o u t
633 * There are 2 kinds of relations in PMA
634 * 1) Internal Relations 2) Foreign Key Relations
636 if (isset($this->autoLayoutInternal
) ||
isset($this->autoLayoutForeign
)) {
637 $all_tables = array();
640 if (isset($this->autoLayoutForeign
)) {
642 * get the tables list
643 * who support FOREIGN KEY, it's not
644 * important that we group together InnoDB tables
645 * and PBXT tables, as this logic is just to put
646 * the tables on the layout, not to determine relations
648 $tables = PMA_DBI_get_tables_full($db);
649 $foreignkey_tables = array();
650 foreach($tables as $table_name => $table_properties) {
651 if (PMA_foreignkey_supported($table_properties['ENGINE'])) {
652 $foreignkey_tables[] = $table_name;
655 $all_tables = $foreignkey_tables;
657 * could be improved by finding the tables which have the
658 * most references keys and placing them at the beginning
659 * of the array (so that they are all center of schema)
661 unset($tables, $foreignkey_tables);
664 if (isset($this->autoLayoutInternal
)) {
666 * get the tables list who support Internal Relations;
667 * This type of relations will be created when
668 * you setup the PMA tables correctly
670 $master_tables = 'SELECT COUNT(master_table), master_table'
671 . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation'])
672 . ' WHERE master_db = \'' . $db . '\''
673 . ' GROUP BY master_table'
674 . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC ';
675 $master_tables_rs = PMA_query_as_controluser($master_tables, FALSE, $query_default_option);
676 if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) {
677 /* first put all the master tables at beginning
678 * of the list, so they are near the center of
681 while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) {
682 $all_tables[] = $master_table;
685 /* Now for each master, add its foreigns into an array
686 * of foreign tables, if not already there
687 * (a foreign might be foreign for more than
688 * one table, and might be a master itself)
691 $foreign_tables = array();
692 foreach ($all_tables as $master_table) {
693 $foreigners = PMA_getForeigners($db, $master_table);
694 foreach ($foreigners as $foreigner) {
695 if (!in_array($foreigner['foreign_table'], $foreign_tables)) {
696 $foreign_tables[] = $foreigner['foreign_table'];
702 * Now merge the master and foreign arrays/tables
704 foreach ($foreign_tables as $foreign_table) {
705 if (!in_array($foreign_table, $all_tables)) {
706 $all_tables[] = $foreign_table;
712 if (isset($this->autoLayoutInternal
) ||
isset($this->autoLayoutForeign
)) {
713 $this->addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation,$query_default_option);
716 $this->chosenPage
= $pageNumber;
720 * Add X and Y coordinates for a table
722 * @param string db The database name
723 * @param array cfgRelation relation settings
724 * @param integer pageNumber document number/Id
725 * @param array all_tables A list of all tables involved
729 public function addRelationCoordinates($all_tables,$pageNumber,$db, $cfgRelation,$query_default_option)
732 * Now generate the coordinates for the schema
733 * in a clockwise spiral and add to co-ordinates table
739 $direction = "right";
740 foreach ($all_tables as $current_table) {
742 * save current table's coordinates
744 $insert_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
745 . '(db_name, table_name, pdf_page_number, x, y) '
746 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($current_table) . '\',' . $pageNumber . ',' . $pos_x . ',' . $pos_y . ')';
747 PMA_query_as_controluser($insert_query, FALSE, $query_default_option);
750 * compute for the next table
752 switch ($direction) {
756 $delta *= $delta_mult;
761 $delta *= $delta_mult;
766 $delta *= $delta_mult;
770 $direction = "right";
771 $delta *= $delta_mult;
778 * update X and Y coordinates for a table
780 * @param string db The database name
781 * @param array cfgRelation relation settings
785 private function _editCoordinates($db, $cfgRelation,$query_default_option)
787 for ($i = 0; $i < $this->c_table_rows
; $i++
) {
788 $arrvalue = 'c_table_' . $i;
790 $arrvalue = $
$arrvalue;
791 if (!isset($arrvalue['x']) ||
$arrvalue['x'] == '') {
794 if (!isset($arrvalue['y']) ||
$arrvalue['y'] == '') {
797 if (isset($arrvalue['name']) && $arrvalue['name'] != '--') {
798 $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
799 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
800 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
801 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->chosenPage
) . '\'';
802 $test_rs = PMA_query_as_controluser($test_query, FALSE, $query_default_option);
804 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
805 if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') {
806 $ch_query = 'DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords'])
807 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
808 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
809 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->chosenPage
) . '\'';
811 $ch_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
812 . 'SET x = ' . $arrvalue['x'] . ', y= ' . $arrvalue['y']
813 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''
814 . ' AND table_name = \'' . PMA_sqlAddslashes($arrvalue['name']) . '\''
815 . ' AND pdf_page_number = \'' . PMA_sqlAddslashes($this->chosenPage
) . '\'';
818 $ch_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' '
819 . '(db_name, table_name, pdf_page_number, x, y) '
820 . 'VALUES (\'' . PMA_sqlAddslashes($db) . '\', \'' . PMA_sqlAddslashes($arrvalue['name']) . '\', \'' . PMA_sqlAddslashes($this->chosenPage
) . '\',' . $arrvalue['x'] . ',' . $arrvalue['y'] . ')';
823 PMA_query_as_controluser($ch_query, FALSE, $query_default_option);