2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Functions used to generate table tracking
10 * Filters tracking entries
12 * @param array $data the entries to filter
13 * @param string $filter_ts_from "from" date
14 * @param string $filter_ts_to "to" date
15 * @param string $filter_users users
17 * @return array filtered entries
19 function PMA_filterTracking(
20 $data, $filter_ts_from, $filter_ts_to, $filter_users
22 $tmp_entries = array();
24 foreach ($data as $entry) {
25 $timestamp = strtotime($entry['date']);
26 $filtered_user = in_array($entry['username'], $filter_users);
27 if ($timestamp >= $filter_ts_from
28 && $timestamp <= $filter_ts_to
29 && (in_array('*', $filter_users) ||
$filtered_user)
31 $tmp_entries[] = array(
33 'timestamp' => $timestamp,
34 'username' => $entry['username'],
35 'statement' => $entry['statement']
44 * Function to get html for data definition and data manipulation statements
46 * @param string $url_query url query
47 * @param int $last_version last version
51 function PMA_getHtmlForDataDefinitionAndManipulationStatements($url_query,
54 $html = '<div id="div_create_version">';
55 $html .= '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
56 $html .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
57 $html .= '<fieldset>';
60 __('Create version %1$s of %2$s'),
62 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
65 $html .= '<input type="hidden" name="version" value="' . ($last_version +
1)
67 $html .= '<p>' . __('Track these data definition statements:')
69 $html .= '<input type="checkbox" name="alter_table" value="true"'
70 . ' checked="checked" /> ALTER TABLE<br/>';
71 $html .= '<input type="checkbox" name="rename_table" value="true"'
72 . ' checked="checked" /> RENAME TABLE<br/>';
73 $html .= '<input type="checkbox" name="create_table" value="true"'
74 . ' checked="checked" /> CREATE TABLE<br/>';
75 $html .= '<input type="checkbox" name="drop_table" value="true"'
76 . ' checked="checked" /> DROP TABLE<br/>';
78 $html .= '<input type="checkbox" name="create_index" value="true"'
79 . ' checked="checked" /> CREATE INDEX<br/>';
80 $html .= '<input type="checkbox" name="drop_index" value="true"'
81 . ' checked="checked" /> DROP INDEX<br/>';
82 $html .= '<p>' . __('Track these data manipulation statements:') . '</p>';
83 $html .= '<input type="checkbox" name="insert" value="true"'
84 . ' checked="checked" /> INSERT<br/>';
85 $html .= '<input type="checkbox" name="update" value="true"'
86 . ' checked="checked" /> UPDATE<br/>';
87 $html .= '<input type="checkbox" name="delete" value="true"'
88 . ' checked="checked" /> DELETE<br/>';
89 $html .= '<input type="checkbox" name="truncate" value="true"'
90 . ' checked="checked" /> TRUNCATE<br/>';
91 $html .= '</fieldset>';
93 $html .= '<fieldset class="tblFooters">';
94 $html .= '<input type="hidden" name="submit_create_version" value="1" />';
95 $html .= '<input type="submit" value="' . __('Create version') . '" />';
96 $html .= '</fieldset>';
105 * Function to get html for activate tracking
107 * @param string $url_query url query
108 * @param int $last_version last version
112 function PMA_getHtmlForActivateTracking($url_query, $last_version)
114 $html = '<div id="div_activate_tracking">';
115 $html .= '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
116 $html .= '<fieldset>';
119 __('Activate tracking for %s'),
120 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
122 $html .= '</legend>';
123 $html .= '<input type="hidden" name="version" value="' . $last_version . '" />';
124 $html .= '<input type="hidden" name="submit_activate_now" value="1" />';
125 $html .= '<input type="submit" value="' . __('Activate now') . '" />';
126 $html .= '</fieldset>';
134 * Function to get html for deactivating tracking
136 * @param string $url_query url query
137 * @param int $last_version last version
141 function PMA_getHtmlForDeactivateTracking($url_query, $last_version)
143 $html = '<div id="div_deactivate_tracking">';
144 $html .= '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
145 $html .= '<fieldset>';
148 __('Deactivate tracking for %s'),
149 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
151 $html .= '</legend>';
152 $html .= '<input type="hidden" name="version" value="' . $last_version . '" />';
153 $html .= '<input type="hidden" name="submit_deactivate_now" value="1" />';
154 $html .= '<input type="submit" value="' . __('Deactivate now') . '" />';
155 $html .= '</fieldset>';
163 * Function to get the list versions of the table
167 function PMA_getListOfVersionsOfTable()
169 $sql_query = " SELECT * FROM " .
170 PMA_Util
::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
171 PMA_Util
::backquote($GLOBALS['cfg']['Server']['tracking']) .
172 " WHERE db_name = '" . PMA_Util
::sqlAddSlashes($_REQUEST['db']) . "' ".
173 " AND table_name = '" . PMA_Util
::sqlAddSlashes($_REQUEST['table']) ."' ".
174 " ORDER BY version DESC ";
176 return PMA_queryAsControlUser($sql_query);
180 * Function to get html for displaying last version number
182 * @param array $sql_result sql result
183 * @param int $last_version last version
184 * @param array $url_params url parameters
185 * @param string $url_query url query
189 function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_params,
192 $html = '<table id="versions" class="data">';
195 $html .= '<th>' . __('Database') . '</th>';
196 $html .= '<th>' . __('Table') . '</th>';
197 $html .= '<th>' . __('Version') . '</th>';
198 $html .= '<th>' . __('Created') . '</th>';
199 $html .= '<th>' . __('Updated') . '</th>';
200 $html .= '<th>' . __('Status') . '</th>';
201 $html .= '<th>' . __('Show') . '</th>';
207 $GLOBALS['dbi']->dataSeek($sql_result, 0);
208 while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
209 if ($version['tracking_active'] == 1) {
210 $version_status = __('active');
212 $version_status = __('not active');
214 if ($version['version'] == $last_version) {
215 if ($version['tracking_active'] == 1) {
216 $tracking_active = true;
218 $tracking_active = false;
221 $html .= '<tr class="noclick ' . $style . '">';
222 $html .= '<td>' . htmlspecialchars($version['db_name']) . '</td>';
223 $html .= '<td>' . htmlspecialchars($version['table_name']) . '</td>';
224 $html .= '<td>' . htmlspecialchars($version['version']) . '</td>';
225 $html .= '<td>' . htmlspecialchars($version['date_created']) . '</td>';
226 $html .= '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
227 $html .= '<td>' . $version_status . '</td>';
228 $html .= '<td><a href="tbl_tracking.php';
229 $html .= PMA_URL_getCommon(
231 'report' => 'true', 'version' => $version['version']
234 $html .= '">' . __('Tracking report') . '</a>';
235 $html .= '| <a href="tbl_tracking.php';
236 $html .= PMA_URL_getCommon(
238 'snapshot' => 'true', 'version' => $version['version']
241 $html .= '">' . __('Structure snapshot') . '</a>';
245 if ($style == 'even') {
255 if ($tracking_active) {
256 $html .= PMA_getHtmlForDeactivateTracking($url_query, $last_version);
258 $html .= PMA_getHtmlForActivateTracking($url_query, $last_version);
265 * Function to get the last version number of a table
267 * @param array $sql_result sql result
271 function PMA_getTableLastVersionNumber($sql_result)
273 $maxversion = $GLOBALS['dbi']->fetchArray($sql_result);
274 $last_version = $maxversion['version'];
276 return $last_version;
280 * Function to get sql results for selectable tables
284 function PMA_getSQLResultForSelectableTables()
286 include_once 'libraries/relation.lib.php';
288 $sql_query = " SELECT DISTINCT db_name, table_name FROM " .
289 PMA_Util
::backquote($GLOBALS['cfg']['Server']['pmadb']) . "." .
290 PMA_Util
::backquote($GLOBALS['cfg']['Server']['tracking']) .
291 " WHERE db_name = '" . PMA_Util
::sqlAddSlashes($GLOBALS['db']) . "' " .
292 " ORDER BY db_name, table_name";
294 return PMA_queryAsControlUser($sql_query);
298 * Function to get html for selectable table rows
300 * @param array $selectable_tables_sql_result sql results for selectable rows
301 * @param string $url_query url query
305 function PMA_getHtmlForSelectableTables($selectable_tables_sql_result, $url_query)
307 $html = '<form method="post" action="tbl_tracking.php?' . $url_query . '">';
308 $html .= '<select name="table">';
309 while ($entries = $GLOBALS['dbi']->fetchArray($selectable_tables_sql_result)) {
310 if (PMA_Tracker
::isTracked($entries['db_name'], $entries['table_name'])) {
311 $status = ' (' . __('active') . ')';
313 $status = ' (' . __('not active') . ')';
315 if ($entries['table_name'] == $_REQUEST['table']) {
316 $s = ' selected="selected"';
320 $html .= '<option value="' . htmlspecialchars($entries['table_name'])
321 . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . '
322 . htmlspecialchars($entries['table_name']) . $status . '</option>'
325 $html .= '</select>';
326 $html .= '<input type="hidden" name="show_versions_submit" value="1" />';
327 $html .= '<input type="submit" value="' . __('Show versions') . '" />';
334 * Function to get html for tracking report and tracking report export
336 * @param string $url_query url query
337 * @param array $data data
338 * @param array $url_params url params
339 * @param array $selection_schema selection schema
340 * @param array $selection_data selection data
341 * @param bool $selection_both selection both
342 * @param int $filter_ts_to filter time stamp from
343 * @param int $filter_ts_from filter time stamp tp
344 * @param array $filter_users filter users
348 function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
349 $selection_schema, $selection_data, $selection_both, $filter_ts_to,
350 $filter_ts_from, $filter_users
352 $html = '<h3>' . __('Tracking report')
353 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
356 $html .= '<small>' . __('Tracking statements') . ' '
357 . htmlspecialchars($data['tracking']) . '</small><br/>';
360 $html .= '<form method="post" action="tbl_tracking.php'
363 'report' => 'true', 'version' => $_REQUEST['version']
368 $str1 = '<select name="logtype">'
369 . '<option value="schema"'
370 . ($selection_schema ?
' selected="selected"' : '') . '>'
371 . __('Structure only') . '</option>'
372 . '<option value="data"'
373 . ($selection_data ?
' selected="selected"' : ''). '>'
374 . __('Data only') . '</option>'
375 . '<option value="schema_and_data"'
376 . ($selection_both ?
' selected="selected"' : '') . '>'
377 . __('Structure and data') . '</option>'
379 $str2 = '<input type="text" name="date_from" value="'
380 . htmlspecialchars($_REQUEST['date_from']) . '" size="19" />';
381 $str3 = '<input type="text" name="date_to" value="'
382 . htmlspecialchars($_REQUEST['date_to']) . '" size="19" />';
383 $str4 = '<input type="text" name="users" value="'
384 . htmlspecialchars($_REQUEST['users']) . '" />';
385 $str5 = '<input type="hidden" name="list_report" value="1" />'
386 . '<input type="submit" value="' . __('Go') . '" />';
389 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
390 $str1, $str2, $str3, $str4, $str5
393 // Prepare delete link content here
394 $drop_image_or_text = '';
395 if (PMA_Util
::showIcons('ActionsLinksMode')) {
396 $drop_image_or_text .= PMA_Util
::getImage(
397 'b_drop.png', __('Delete tracking data row from report')
400 if (PMA_Util
::showText('ActionLinksMode')) {
401 $drop_image_or_text .= __('Delete');
405 * First, list tracked data definition statements
407 if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
408 $msg = PMA_Message
::notice(__('No data'));
412 if ($selection_schema ||
$selection_both && count($data['ddlog']) > 0) {
413 list($temp, $ddlog_count) = PMA_getHtmlForDataDefinitionStatements(
414 $data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
422 * Secondly, list tracked data manipulation statements
424 if (($selection_data ||
$selection_both) && count($data['dmlog']) > 0) {
425 $html .= PMA_getHtmlForDataManipulationStatements(
426 $data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
427 $ddlog_count, $drop_image_or_text
431 $html .= '<form method="post" action="tbl_tracking.php'
434 'report' => 'true', 'version' => $_REQUEST['version']
439 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
440 $str1, $str2, $str3, $str4, $str5
443 $str_export1 = '<select name="export_type">'
444 . '<option value="sqldumpfile">' . __('SQL dump (file download)')
446 . '<option value="sqldump">' . __('SQL dump') . '</option>'
447 . '<option value="execution" onclick="alert(\''
448 . PMA_escapeJsString(
449 __('This option will replace your table and contained data.')
451 .'\')">' . __('SQL execution') . '</option>' . '</select>';
453 $str_export2 = '<input type="hidden" name="report_export" value="1" />'
454 . '<input type="submit" value="' . __('Go') .'" />';
456 $html .= '<form class="disableAjax" method="post" action="tbl_tracking.php'
459 +
array('report' => 'true', 'version' => $_REQUEST['version'])
462 $html .= '<input type="hidden" name="logtype" value="'
463 . htmlspecialchars($_REQUEST['logtype']) . '" />';
464 $html .= '<input type="hidden" name="date_from" value="'
465 . htmlspecialchars($_REQUEST['date_from']) . '" />';
466 $html .= '<input type="hidden" name="date_to" value="'
467 . htmlspecialchars($_REQUEST['date_to']) . '" />';
468 $html .= '<input type="hidden" name="users" value="'
469 . htmlspecialchars($_REQUEST['users']) . '" />';
470 $html .= "<br/>" . sprintf(__('Export as %s'), $str_export1)
471 . $str_export2 . "<br/>";
473 $html .= "<br/><br/><hr/><br/>\n";
478 * Function to get html for data manipulation statements
480 * @param array $data data
481 * @param array $filter_users filter users
482 * @param int $filter_ts_from filter time staml from
483 * @param int $filter_ts_to filter time stamp to
484 * @param array $url_params url parameters
485 * @param int $ddlog_count data definition log count
486 * @param string $drop_image_or_text drop image or text
490 function PMA_getHtmlForDataManipulationStatements($data, $filter_users,
491 $filter_ts_from, $filter_ts_to, $url_params, $ddlog_count,
495 $html = '<table id="dml_versions" class="data" width="100%">';
498 $html .= '<th width="18">#</th>';
499 $html .= '<th width="100">' . __('Date') . '</th>';
500 $html .= '<th width="60">' . __('Username') . '</th>';
501 $html .= '<th>' . __('Data manipulation statement') . '</th>';
502 $html .= '<th>' . __('Delete') . '</th>';
508 foreach ($data['dmlog'] as $entry) {
509 $html .= PMA_getHtmlForDataManipulationStatement(
510 $entry, $filter_users, $filter_ts_from, $filter_ts_to, $style, $i,
511 $url_params, $ddlog_count, $drop_image_or_text
513 if ($style == 'even') {
527 * Function to get html for one data manipulation statement
529 * @param array $entry entry
530 * @param array $filter_users filter users
531 * @param int $filter_ts_from filter time stamp from
532 * @param int $filter_ts_to filter time stamp to
533 * @param string $style style
534 * @param int $i field number
535 * @param array $url_params url parameters
536 * @param int $ddlog_count data definition log count
537 * @param string $drop_image_or_text drop image or text
541 function PMA_getHtmlForDataManipulationStatement($entry, $filter_users,
542 $filter_ts_from, $filter_ts_to, $style, $i, $url_params, $ddlog_count,
545 $statement = PMA_Util
::formatSql($entry['statement'], true);
546 $timestamp = strtotime($entry['date']);
547 $filtered_user = in_array($entry['username'], $filter_users);
548 if ($timestamp >= $filter_ts_from
549 && $timestamp <= $filter_ts_to
550 && (in_array('*', $filter_users) ||
$filtered_user)
552 $html = '<tr class="noclick ' . $style . '">';
553 $html .= '<td><small>' . $i . '</small></td>';
554 $html .= '<td><small>'
555 . htmlspecialchars($entry['date']) . '</small></td>';
556 $html .= '<td><small>'
557 . htmlspecialchars($entry['username']) . '</small></td>';
558 $html .= '<td>' . $statement . '</td>';
559 $html .= '<td class="nowrap"><a href="tbl_tracking.php?'
563 'version' => $_REQUEST['version'],
564 'delete_dmlog' => ($i - $ddlog_count),
568 . $drop_image_or_text
576 * Function to get html for data definition statements in schema snapshot
578 * @param array $data data
579 * @param array $filter_users filter users
580 * @param int $filter_ts_from filter time stamp from
581 * @param int $filter_ts_to filter time stamp to
582 * @param array $url_params url parameters
583 * @param string $drop_image_or_text drop image or text
587 function PMA_getHtmlForDataDefinitionStatements($data, $filter_users,
588 $filter_ts_from, $filter_ts_to, $url_params, $drop_image_or_text
591 $html = '<table id="ddl_versions" class="data" width="100%">';
594 $html .= '<th width="18">#</th>';
595 $html .= '<th width="100">' . __('Date') . '</th>';
596 $html .= '<th width="60">' . __('Username') . '</th>';
597 $html .= '<th>' . __('Data definition statement') . '</th>';
598 $html .= '<th>' . __('Delete') . '</th>';
604 foreach ($data['ddlog'] as $entry) {
605 $html .= PMA_getHtmlForDataDefinitionStatement(
606 $entry, $filter_users, $filter_ts_from, $filter_ts_to, $style, $i,
607 $url_params, $drop_image_or_text
609 if ($style == 'even') {
619 return array($html, $i);
622 * Function to get html for a data definition statement in schema snapshot
624 * @param array $entry entry
625 * @param array $filter_users filter users
626 * @param int $filter_ts_from filter time stamp from
627 * @param int $filter_ts_to filter time stamp to
628 * @param string $style style
629 * @param int $i column number
630 * @param array $url_params url parameters
631 * @param string $drop_image_or_text drop image or text
635 function PMA_getHtmlForDataDefinitionStatement($entry, $filter_users,
636 $filter_ts_from, $filter_ts_to, $style, $i, $url_params, $drop_image_or_text
638 $statement = PMA_Util
::formatSql($entry['statement'], true);
639 $timestamp = strtotime($entry['date']);
640 $filtered_user = in_array($entry['username'], $filter_users);
641 if ($timestamp >= $filter_ts_from
642 && $timestamp <= $filter_ts_to
643 && (in_array('*', $filter_users) ||
$filtered_user)
645 $html = '<tr class="noclick ' . $style . '">';
646 $html .= '<td><small>' . $i . '</small></td>';
647 $html .= '<td><small>'
648 . htmlspecialchars($entry['date']) . '</small></td>';
649 $html .= '<td><small>'
650 . htmlspecialchars($entry['username']) . '</small></td>';
651 $html .= '<td>' . $statement . '</td>';
652 $html .= '<td class="nowrap"><a href="tbl_tracking.php'
656 'version' => $_REQUEST['version'],
657 'delete_ddlog' => ($i - 1),
660 . '">' . $drop_image_or_text
668 * Function to get html for schema snapshot
670 * @param string $url_query url query
674 function PMA_getHtmlForSchemaSnapshot($url_query)
676 $html = '<h3>' . __('Structure snapshot')
677 . ' [<a href="tbl_tracking.php?' . $url_query . '">' . __('Close')
679 $data = PMA_Tracker
::getTrackedData(
680 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
683 // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements
684 $drop_create_statements = $data['ddlog'][0]['statement'];
686 if (strstr($data['ddlog'][0]['statement'], 'DROP TABLE')
687 ||
strstr($data['ddlog'][0]['statement'], 'DROP VIEW')
689 $drop_create_statements .= $data['ddlog'][1]['statement'];
692 $html .= PMA_Util
::getMessage(
694 __('Version %s snapshot (SQL code)'),
695 htmlspecialchars($_REQUEST['version'])
697 $drop_create_statements
700 // Unserialize snapshot
701 $temp = unserialize($data['schema_snapshot']);
702 $columns = $temp['COLUMNS'];
703 $indexes = $temp['INDEXES'];
704 $html .= PMA_getHtmlForColumns($columns);
706 if (count($indexes) > 0) {
707 $html .= PMA_getHtmlForIndexes($indexes);
709 $html .= '<br /><hr /><br />';
715 * Function to get html for displaying columns in the schema snapshot
717 * @param array $columns columns
721 function PMA_getHtmlForColumns($columns)
723 $html = '<h3>' . __('Structure') . '</h3>';
724 $html .= '<table id="tablestructure" class="data">';
727 $html .= '<th>' . __('Column') . '</th>';
728 $html .= '<th>' . __('Type') . '</th>';
729 $html .= '<th>' . __('Collation') . '</th>';
730 $html .= '<th>' . __('Null') . '</th>';
731 $html .= '<th>' . __('Default') . '</th>';
732 $html .= '<th>' . __('Extra') . '</th>';
733 $html .= '<th>' . __('Comment') . '</th>';
738 foreach ($columns as $field) {
739 $html .= PMA_getHtmlForField($field, $style);
740 if ($style == 'even') {
754 * Function to get html for field
756 * @param array $field field
757 * @param string $style style
761 function PMA_getHtmlForField($field, $style)
763 $html = '<tr class="noclick ' . $style . '">';
764 if ($field['Key'] == 'PRI') {
765 $html .= '<td><b><u>' . htmlspecialchars($field['Field']) . '</u></b></td>';
767 $html .= '<td><b>' . htmlspecialchars($field['Field']) . '</b></td>';
770 $html .= '<td>' . htmlspecialchars($field['Type']) . '</td>';
771 $html .= '<td>' . htmlspecialchars($field['Collation']) . '</td>';
772 $html .= '<td>' . (($field['Null'] == 'YES') ?
__('Yes') : __('No')) . '</td>';
774 if (isset($field['Default'])) {
775 $extracted_columnspec = PMA_Util
::extractColumnSpec($field['Type']);
776 if ($extracted_columnspec['type'] == 'bit') {
777 // here, $field['Default'] contains something like b'010'
778 $html .= PMA_Util
::convertBitDefaultValue($field['Default']);
780 $html .= htmlspecialchars($field['Default']);
783 if ($field['Null'] == 'YES') {
784 $html .= '<i>NULL</i>';
786 $html .= '<i>' . _pgettext('None for default', 'None') . '</i>';
790 $html .= '<td>' . htmlspecialchars($field['Extra']) . '</td>';
791 $html .= '<td>' . htmlspecialchars($field['Comment']) . '</td>';
798 * Fuunction to get html for the indexes in schema snapshot
800 * @param array $indexes indexes
804 function PMA_getHtmlForIndexes($indexes)
806 $html = '<h3>' . __('Indexes') . '</h3>';
807 $html .= '<table id="tablestructure_indexes" class="data">';
810 $html .= '<th>' . __('Keyname') . '</th>';
811 $html .= '<th>' . __('Type') . '</th>';
812 $html .= '<th>' . __('Unique') . '</th>';
813 $html .= '<th>' . __('Packed') . '</th>';
814 $html .= '<th>' . __('Column') . '</th>';
815 $html .= '<th>' . __('Cardinality') . '</th>';
816 $html .= '<th>' . __('Collation') . '</th>';
817 $html .= '<th>' . __('Null') . '</th>';
818 $html .= '<th>' . __('Comment') . '</th>';
823 foreach ($indexes as $index) {
824 $html .= PMA_getHtmlForIndex($index, $style);
825 if ($style == 'even') {
837 * Funtion to get html for an index in schema snapshot
839 * @param array $index index
840 * @param string $style style
844 function PMA_getHtmlForIndex($index, $style)
846 if ($index['Non_unique'] == 0) {
847 $str_unique = __('Yes');
849 $str_unique = __('No');
851 if ($index['Packed'] != '') {
852 $str_packed = __('Yes');
854 $str_packed = __('No');
857 $html = '<tr class="noclick ' . $style . '">';
858 $html .= '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
859 $html .= '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
860 $html .= '<td>' . $str_unique . '</td>';
861 $html .= '<td>' . $str_packed . '</td>';
862 $html .= '<td>' . htmlspecialchars($index['Column_name']) . '</td>';
863 $html .= '<td>' . htmlspecialchars($index['Cardinality']) . '</td>';
864 $html .= '<td>' . htmlspecialchars($index['Collation']) . '</td>';
865 $html .= '<td>' . htmlspecialchars($index['Null']) . '</td>';
866 $html .= '<td>' . htmlspecialchars($index['Comment']) . '</td>';
873 * Function to handle the tracking report
875 * @param array &$data tracked data
879 function PMA_deleteTrackingReportRows(&$data)
881 if (isset($_REQUEST['delete_ddlog'])) {
882 // Delete ddlog row data
883 PMA_handleDeleteDataDefinitionsLog($data);
886 if (isset($_REQUEST['delete_dmlog'])) {
887 // Delete dmlog row data
888 PMA_handleDeleteDataManipulationLog($data);
893 * Function to handle the delete ddlog row data
895 * @param array &$data tracked data
899 function PMA_handleDeleteDataDefinitionsLog(&$data)
901 $delete_id = $_REQUEST['delete_ddlog'];
903 // Only in case of valable id
904 if ($delete_id == (int)$delete_id) {
905 unset($data['ddlog'][$delete_id]);
907 $successfullyDeleted = PMA_Tracker
::changeTrackingData(
908 $_REQUEST['db'], $_REQUEST['table'],
909 $_REQUEST['version'], 'DDL', $data['ddlog']
911 if ($successfullyDeleted) {
912 $msg = PMA_Message
::success(
913 __('Tracking data definition successfully deleted')
916 $msg = PMA_Message
::rawError(__('Query error'));
923 * Function to handle the delete of fmlog rows
925 * @param array &$data tracked data
929 function PMA_handleDeleteDataManipulationLog(&$data)
931 $delete_id = $_REQUEST['delete_dmlog'];
933 // Only in case of valable id
934 if ($delete_id == (int)$delete_id) {
935 unset($data['dmlog'][$delete_id]);
937 $successfullyDeleted = PMA_Tracker
::changeTrackingData(
938 $_REQUEST['db'], $_REQUEST['table'],
939 $_REQUEST['version'], 'DML', $data['dmlog']
941 if ($successfullyDeleted) {
942 $msg = PMA_Message
::success(
943 __('Tracking data manipulation successfully deleted')
946 $msg = PMA_Message
::rawError(__('Query error'));
953 * Function to export as sql dump
955 * @param array $entries entries
959 function PMA_exportAsSQLDump($entries)
963 'You can execute the dump by creating and using a temporary database. '
964 . 'Please ensure that you have the privileges to do so.'
967 . "# " . __('Comment out these two lines if you do not need them.') . "\n"
969 . "CREATE database IF NOT EXISTS pma_temp_db; \n"
970 . "USE pma_temp_db; \n"
973 foreach ($entries as $entry) {
974 $new_query .= $entry['statement'];
976 $msg = PMA_Message
::success(
977 __('SQL statements exported. Please copy the dump or execute it.')
981 $db_temp = $GLOBALS['db'];
982 $table_temp = $GLOBALS['table'];
984 $GLOBALS['db'] = $GLOBALS['table'] = '';
985 include_once './libraries/sql_query_form.lib.php';
987 PMA_getHtmlForSqlQueryForm($new_query, 'sql');
989 $GLOBALS['db'] = $db_temp;
990 $GLOBALS['table'] = $table_temp;
994 * Function to export as sql execution
996 * @param array $entries entries
1000 function PMA_exportAsSQLExecution($entries)
1002 foreach ($entries as $entry) {
1003 $sql_result = $GLOBALS['dbi']->query("/*NOTRACK*/\n" . $entry['statement']);
1005 $msg = PMA_Message
::success(__('SQL statements executed.'));
1012 * Function to export as entries
1014 * @param array $entries entries
1018 function PMA_exportAsFileDownload($entries)
1020 @ini_set
('url_rewriter.tags', '');
1022 $dump = "# " . sprintf(
1023 __('Tracking report for table `%s`'), htmlspecialchars($_REQUEST['table'])
1025 . "\n" . "# " . date('Y-m-d H:i:s') . "\n";
1026 foreach ($entries as $entry) {
1027 $dump .= $entry['statement'];
1029 $filename = 'log_' . htmlspecialchars($_REQUEST['table']) . '.sql';
1030 PMA_downloadHeader($filename, 'text/x-sql', strlen($dump));
1032 $response = PMA_Response
::getInstance();
1033 $response->addHTML($dump);
1039 * Function to activate tracking
1043 function PMA_activateTracking()
1045 $activated = PMA_Tracker
::activateTracking(
1046 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
1049 $msg = PMA_Message
::success(
1051 __('Tracking for %1$s was activated at version %2$s.'),
1052 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
1053 htmlspecialchars($_REQUEST['version'])
1061 * Function to deactivate tracking
1065 function PMA_deactivateTracking()
1067 $deactivated = PMA_Tracker
::deactivateTracking(
1068 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
1071 $msg = PMA_Message
::success(
1073 __('Tracking for %1$s was deactivated at version %2$s.'),
1074 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
1075 htmlspecialchars($_REQUEST['version'])
1083 * Function to get tracking set
1087 function PMA_getTrackingSet()
1091 if ($_REQUEST['alter_table'] == true) {
1092 $tracking_set .= 'ALTER TABLE,';
1094 if ($_REQUEST['rename_table'] == true) {
1095 $tracking_set .= 'RENAME TABLE,';
1097 if ($_REQUEST['create_table'] == true) {
1098 $tracking_set .= 'CREATE TABLE,';
1100 if ($_REQUEST['drop_table'] == true) {
1101 $tracking_set .= 'DROP TABLE,';
1103 if ($_REQUEST['create_index'] == true) {
1104 $tracking_set .= 'CREATE INDEX,';
1106 if ($_REQUEST['drop_index'] == true) {
1107 $tracking_set .= 'DROP INDEX,';
1109 if ($_REQUEST['insert'] == true) {
1110 $tracking_set .= 'INSERT,';
1112 if ($_REQUEST['update'] == true) {
1113 $tracking_set .= 'UPDATE,';
1115 if ($_REQUEST['delete'] == true) {
1116 $tracking_set .= 'DELETE,';
1118 if ($_REQUEST['truncate'] == true) {
1119 $tracking_set .= 'TRUNCATE,';
1121 $tracking_set = rtrim($tracking_set, ',');
1123 return $tracking_set;
1127 * Function to create the tracking version
1131 function PMA_createTrackingVersion()
1133 $tracking_set = PMA_getTrackingSet();
1135 $versionCreated = PMA_Tracker
::createVersion(
1138 $_REQUEST['version'],
1140 PMA_Table
::isView($GLOBALS['db'], $GLOBALS['table'])
1142 if ($versionCreated) {
1143 $msg = PMA_Message
::success(
1145 __('Version %1$s was created, tracking for %2$s is active.'),
1146 htmlspecialchars($_REQUEST['version']),
1147 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
1155 * Function to get the entries
1157 * @param array $data data
1158 * @param int $filter_ts_from filter time stamp from
1159 * @param int $filter_ts_to filter time stamp to
1160 * @param array $filter_users filter users
1164 function PMA_getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users)
1167 // Filtering data definition statements
1168 if ($_REQUEST['logtype'] == 'schema'
1169 ||
$_REQUEST['logtype'] == 'schema_and_data'
1171 $entries = array_merge(
1174 $data['ddlog'], $filter_ts_from, $filter_ts_to, $filter_users
1179 // Filtering data manipulation statements
1180 if ($_REQUEST['logtype'] == 'data'
1181 ||
$_REQUEST['logtype'] == 'schema_and_data'
1183 $entries = array_merge(
1186 $data['dmlog'], $filter_ts_from, $filter_ts_to, $filter_users
1192 foreach ($entries as $key => $row) {
1193 $ids[$key] = $row['id'];
1194 $timestamps[$key] = $row['timestamp'];
1195 $usernames[$key] = $row['username'];
1196 $statements[$key] = $row['statement'];
1200 $timestamps, SORT_ASC
, $ids, SORT_ASC
, $usernames,
1201 SORT_ASC
, $statements, SORT_ASC
, $entries