Translated using Weblate (Estonian)
[phpmyadmin.git] / libraries / tracking.lib.php
blobd532d9cce5b14074fbd8657e8338c247e3bb399f
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functions used for database and table tracking
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\Message;
9 use PMA\libraries\Response;
10 use PMA\libraries\Tracker;
11 use PMA\libraries\URL;
12 use PMA\libraries\Sanitize;
14 /**
15 * Filters tracking entries
17 * @param array $data the entries to filter
18 * @param string $filter_ts_from "from" date
19 * @param string $filter_ts_to "to" date
20 * @param array $filter_users users
22 * @return array filtered entries
24 function PMA_filterTracking(
25 $data, $filter_ts_from, $filter_ts_to, $filter_users
26 ) {
27 $tmp_entries = array();
28 $id = 0;
29 foreach ($data as $entry) {
30 $timestamp = strtotime($entry['date']);
31 $filtered_user = in_array($entry['username'], $filter_users);
32 if ($timestamp >= $filter_ts_from
33 && $timestamp <= $filter_ts_to
34 && (in_array('*', $filter_users) || $filtered_user)
35 ) {
36 $tmp_entries[] = array(
37 'id' => $id,
38 'timestamp' => $timestamp,
39 'username' => $entry['username'],
40 'statement' => $entry['statement']
43 $id++;
45 return($tmp_entries);
48 /**
49 * Function to get html for data definition and data manipulation statements
51 * @param string $url_query url query
52 * @param int $last_version last version
53 * @param string $db database
54 * @param array $selected selected tables
55 * @param string $type type of the table; table, view or both
57 * @return string
59 function PMA_getHtmlForDataDefinitionAndManipulationStatements($url_query,
60 $last_version, $db, $selected, $type = 'both'
61 ) {
62 $html = '<div id="div_create_version">';
63 $html .= '<form method="post" action="' . $url_query . '">';
64 $html .= URL::getHiddenInputs($db);
65 foreach ($selected as $selected_table) {
66 $html .= '<input type="hidden" name="selected[]"'
67 . ' value="' . htmlspecialchars($selected_table) . '" />';
70 $html .= '<fieldset>';
71 $html .= '<legend>';
72 if (count($selected) == 1) {
73 $html .= sprintf(
74 __('Create version %1$s of %2$s'),
75 ($last_version + 1),
76 htmlspecialchars($db . '.' . $selected[0])
78 } else {
79 $html .= sprintf(__('Create version %1$s'), ($last_version + 1));
81 $html .= '</legend>';
82 $html .= '<input type="hidden" name="version" value="' . ($last_version + 1)
83 . '" />';
84 $html .= '<p>' . __('Track these data definition statements:')
85 . '</p>';
87 if ($type == 'both' || $type == 'table') {
88 $html .= '<input type="checkbox" name="alter_table" value="true"'
89 . (mb_stripos(
90 $GLOBALS['cfg']['Server']['tracking_default_statements'],
91 'ALTER TABLE'
92 ) !== false ? ' checked="checked"' : '')
93 . ' /> ALTER TABLE<br/>';
94 $html .= '<input type="checkbox" name="rename_table" value="true"'
95 . (mb_stripos(
96 $GLOBALS['cfg']['Server']['tracking_default_statements'],
97 'RENAME TABLE'
98 ) !== false ? ' checked="checked"' : '')
99 . ' /> RENAME TABLE<br/>';
100 $html .= '<input type="checkbox" name="create_table" value="true"'
101 . (mb_stripos(
102 $GLOBALS['cfg']['Server']['tracking_default_statements'],
103 'CREATE TABLE'
104 ) !== false ? ' checked="checked"' : '')
105 . ' /> CREATE TABLE<br/>';
106 $html .= '<input type="checkbox" name="drop_table" value="true"'
107 . (mb_stripos(
108 $GLOBALS['cfg']['Server']['tracking_default_statements'],
109 'DROP TABLE'
110 ) !== false ? ' checked="checked"' : '')
111 . ' /> DROP TABLE<br/>';
113 if ($type == 'both') {
114 $html .= '<br/>';
116 if ($type == 'both' || $type == 'view') {
117 $html .= '<input type="checkbox" name="alter_view" value="true"'
118 . (mb_stripos(
119 $GLOBALS['cfg']['Server']['tracking_default_statements'],
120 'ALTER VIEW'
121 ) !== false ? ' checked="checked"' : '')
122 . ' /> ALTER VIEW<br/>';
123 $html .= '<input type="checkbox" name="create_view" value="true"'
124 . (mb_stripos(
125 $GLOBALS['cfg']['Server']['tracking_default_statements'],
126 'CREATE VIEW'
127 ) !== false ? ' checked="checked"' : '')
128 . ' /> CREATE VIEW<br/>';
129 $html .= '<input type="checkbox" name="drop_view" value="true"'
130 . (mb_stripos(
131 $GLOBALS['cfg']['Server']['tracking_default_statements'],
132 'DROP VIEW'
133 ) !== false ? ' checked="checked"' : '')
134 . ' /> DROP VIEW<br/>';
136 $html .= '<br/>';
138 $html .= '<input type="checkbox" name="create_index" value="true"'
139 . (mb_stripos(
140 $GLOBALS['cfg']['Server']['tracking_default_statements'],
141 'CREATE INDEX'
142 ) !== false ? ' checked="checked"' : '')
143 . ' /> CREATE INDEX<br/>';
144 $html .= '<input type="checkbox" name="drop_index" value="true"'
145 . (mb_stripos(
146 $GLOBALS['cfg']['Server']['tracking_default_statements'],
147 'DROP INDEX'
148 ) !== false ? ' checked="checked"' : '')
149 . ' /> DROP INDEX<br/>';
150 $html .= '<p>' . __('Track these data manipulation statements:') . '</p>';
151 $html .= '<input type="checkbox" name="insert" value="true"'
152 . (mb_stripos(
153 $GLOBALS['cfg']['Server']['tracking_default_statements'],
154 'INSERT'
155 ) !== false ? ' checked="checked"' : '')
156 . ' /> INSERT<br/>';
157 $html .= '<input type="checkbox" name="update" value="true"'
158 . (mb_stripos(
159 $GLOBALS['cfg']['Server']['tracking_default_statements'],
160 'UPDATE'
161 ) !== false ? ' checked="checked"' : '')
162 . ' /> UPDATE<br/>';
163 $html .= '<input type="checkbox" name="delete" value="true"'
164 . (mb_stripos(
165 $GLOBALS['cfg']['Server']['tracking_default_statements'],
166 'DELETE'
167 ) !== false ? ' checked="checked"' : '')
168 . ' /> DELETE<br/>';
169 $html .= '<input type="checkbox" name="truncate" value="true"'
170 . (mb_stripos(
171 $GLOBALS['cfg']['Server']['tracking_default_statements'],
172 'TRUNCATE'
173 ) !== false ? ' checked="checked"' : '')
174 . ' /> TRUNCATE<br/>';
175 $html .= '</fieldset>';
177 $html .= '<fieldset class="tblFooters">';
178 $html .= '<input type="hidden" name="submit_create_version" value="1" />';
179 $html .= '<input type="submit" value="' . __('Create version') . '" />';
180 $html .= '</fieldset>';
182 $html .= '</form>';
183 $html .= '</div>';
185 return $html;
189 * Function to get html for activate/deactivate tracking
191 * @param string $action activate|deactivate
192 * @param string $url_query url query
193 * @param int $last_version last version
195 * @return string
197 function PMA_getHtmlForActivateDeactivateTracking(
198 $action, $url_query, $last_version
200 $html = '<div>';
201 $html .= '<form method="post" action="tbl_tracking.php' . $url_query . '">';
202 $html .= URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
203 $html .= '<fieldset>';
204 $html .= '<legend>';
206 switch($action) {
207 case 'activate':
208 $legend = __('Activate tracking for %s');
209 $value = "activate_now";
210 $button = __('Activate now');
211 break;
212 case 'deactivate':
213 $legend = __('Deactivate tracking for %s');
214 $value = "deactivate_now";
215 $button = __('Deactivate now');
216 break;
217 default:
218 $legend = '';
219 $value = '';
220 $button = '';
223 $html .= sprintf(
224 $legend,
225 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
227 $html .= '</legend>';
228 $html .= '<input type="hidden" name="version" value="' . $last_version . '" />';
229 $html .= '<input type="hidden" name="toggle_activation" value="' . $value
230 . '" />';
231 $html .= '<input type="submit" value="' . $button . '" />';
232 $html .= '</fieldset>';
233 $html .= '</form>';
234 $html .= '</div>';
236 return $html;
240 * Function to get the list versions of the table
242 * @return array
244 function PMA_getListOfVersionsOfTable()
246 $cfgRelation = PMA_getRelationsParam();
247 $sql_query = " SELECT * FROM " .
248 PMA\libraries\Util::backquote($cfgRelation['db']) . "." .
249 PMA\libraries\Util::backquote($cfgRelation['tracking']) .
250 " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($_REQUEST['db']) .
251 "' " .
252 " AND table_name = '" .
253 $GLOBALS['dbi']->escapeString($_REQUEST['table']) . "' " .
254 " ORDER BY version DESC ";
256 return PMA_queryAsControlUser($sql_query);
260 * Function to get html for displaying last version number
262 * @param array $sql_result sql result
263 * @param int $last_version last version
264 * @param array $url_params url parameters
265 * @param string $url_query url query
266 * @param string $pmaThemeImage path to theme's image folder
267 * @param string $text_dir text direction
269 * @return string
271 function PMA_getHtmlForTableVersionDetails(
272 $sql_result, $last_version, $url_params,
273 $url_query, $pmaThemeImage, $text_dir
275 $tracking_active = false;
277 $html = '<form method="post" action="tbl_tracking.php" name="versionsForm"'
278 . ' id="versionsForm" class="ajax">';
279 $html .= URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
280 $html .= '<table id="versions" class="data">';
281 $html .= '<thead>';
282 $html .= '<tr>';
283 $html .= '<th></th>';
284 $html .= '<th>' . __('Version') . '</th>';
285 $html .= '<th>' . __('Created') . '</th>';
286 $html .= '<th>' . __('Updated') . '</th>';
287 $html .= '<th>' . __('Status') . '</th>';
288 $html .= '<th>' . __('Action') . '</th>';
289 $html .= '<th>' . __('Show') . '</th>';
290 $html .= '</tr>';
291 $html .= '</thead>';
292 $html .= '<tbody>';
294 $GLOBALS['dbi']->dataSeek($sql_result, 0);
295 $delete = PMA\libraries\Util::getIcon('b_drop.png', __('Delete version'));
296 $report = PMA\libraries\Util::getIcon('b_report.png', __('Tracking report'));
297 $structure = PMA\libraries\Util::getIcon(
298 'b_props.png',
299 __('Structure snapshot')
302 while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
303 if ($version['version'] == $last_version) {
304 if ($version['tracking_active'] == 1) {
305 $tracking_active = true;
306 } else {
307 $tracking_active = false;
310 $delete_link = 'tbl_tracking.php' . $url_query . '&amp;version='
311 . htmlspecialchars($version['version'])
312 . '&amp;submit_delete_version=true';
313 $checkbox_id = 'selected_versions_' . htmlspecialchars($version['version']);
315 $html .= '<tr>';
316 $html .= '<td class="center">';
317 $html .= '<input type="checkbox" name="selected_versions[]"'
318 . ' class="checkall" id="' . $checkbox_id . '"'
319 . ' value="' . htmlspecialchars($version['version']) . '"/>';
320 $html .= '</td>';
321 $html .= '<th class="floatright">';
322 $html .= '<label for="' . $checkbox_id . '">'
323 . htmlspecialchars($version['version']) . '</label>';
324 $html .= '</th>';
325 $html .= '<td>' . htmlspecialchars($version['date_created']) . '</td>';
326 $html .= '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
327 $html .= '<td>' . PMA_getVersionStatus($version) . '</td>';
328 $html .= '<td><a class="delete_version_anchor ajax"'
329 . ' href="' . $delete_link . '" >' . $delete . '</a></td>';
330 $html .= '<td><a href="tbl_tracking.php';
331 $html .= URL::getCommon(
332 $url_params + array(
333 'report' => 'true', 'version' => $version['version']
336 $html .= '">' . $report . '</a>';
337 $html .= '&nbsp;&nbsp;';
338 $html .= '<a href="tbl_tracking.php';
339 $html .= URL::getCommon(
340 $url_params + array(
341 'snapshot' => 'true', 'version' => $version['version']
344 $html .= '">' . $structure . '</a>';
345 $html .= '</td>';
346 $html .= '</tr>';
349 $html .= '</tbody>';
350 $html .= '</table>';
352 $html .= PMA\libraries\Template::get('select_all')
353 ->render(
354 array(
355 'pmaThemeImage' => $pmaThemeImage,
356 'text_dir' => $text_dir,
357 'formName' => 'versionsForm',
360 $html .= PMA\libraries\Util::getButtonOrImage(
361 'submit_mult', 'mult_submit',
362 __('Delete version'), 'b_drop.png', 'delete_version'
365 $html .= '</form>';
367 if ($tracking_active) {
368 $html .= PMA_getHtmlForActivateDeactivateTracking(
369 'deactivate', $url_query, $last_version
371 } else {
372 $html .= PMA_getHtmlForActivateDeactivateTracking(
373 'activate', $url_query, $last_version
377 return $html;
381 * Function to get the last version number of a table
383 * @param array $sql_result sql result
385 * @return int
387 function PMA_getTableLastVersionNumber($sql_result)
389 $maxversion = $GLOBALS['dbi']->fetchArray($sql_result);
390 return intval($maxversion['version']);
394 * Function to get sql results for selectable tables
396 * @return array
398 function PMA_getSQLResultForSelectableTables()
400 include_once 'libraries/relation.lib.php';
401 $cfgRelation = PMA_getRelationsParam();
403 $sql_query = " SELECT DISTINCT db_name, table_name FROM " .
404 PMA\libraries\Util::backquote($cfgRelation['db']) . "." .
405 PMA\libraries\Util::backquote($cfgRelation['tracking']) .
406 " WHERE db_name = '" . $GLOBALS['dbi']->escapeString($GLOBALS['db']) .
407 "' " .
408 " ORDER BY db_name, table_name";
410 return PMA_queryAsControlUser($sql_query);
414 * Function to get html for selectable table rows
416 * @param array $selectable_tables_sql_result sql results for selectable rows
417 * @param string $url_query url query
419 * @return string
421 function PMA_getHtmlForSelectableTables($selectable_tables_sql_result, $url_query)
423 $html = '<form method="post" action="tbl_tracking.php' . $url_query . '">';
424 $html .= URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
425 $html .= '<select name="table" class="autosubmit">';
426 while ($entries = $GLOBALS['dbi']->fetchArray($selectable_tables_sql_result)) {
427 if (Tracker::isTracked($entries['db_name'], $entries['table_name'])) {
428 $status = ' (' . __('active') . ')';
429 } else {
430 $status = ' (' . __('not active') . ')';
432 if ($entries['table_name'] == $_REQUEST['table']) {
433 $s = ' selected="selected"';
434 } else {
435 $s = '';
437 $html .= '<option value="' . htmlspecialchars($entries['table_name'])
438 . '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . '
439 . htmlspecialchars($entries['table_name']) . $status . '</option>'
440 . "\n";
442 $html .= '</select>';
443 $html .= '<input type="hidden" name="show_versions_submit" value="1" />';
444 $html .= '</form>';
446 return $html;
450 * Function to get html for tracking report and tracking report export
452 * @param string $url_query url query
453 * @param array $data data
454 * @param array $url_params url params
455 * @param boolean $selection_schema selection schema
456 * @param boolean $selection_data selection data
457 * @param boolean $selection_both selection both
458 * @param int $filter_ts_to filter time stamp from
459 * @param int $filter_ts_from filter time stamp tp
460 * @param array $filter_users filter users
462 * @return string
464 function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
465 $selection_schema, $selection_data, $selection_both, $filter_ts_to,
466 $filter_ts_from, $filter_users
468 $html = '<h3>' . __('Tracking report')
469 . ' [<a href="tbl_tracking.php' . $url_query . '">' . __('Close')
470 . '</a>]</h3>';
472 $html .= '<small>' . __('Tracking statements') . ' '
473 . htmlspecialchars($data['tracking']) . '</small><br/>';
474 $html .= '<br/>';
476 list($str1, $str2, $str3, $str4, $str5) = PMA_getHtmlForElementsOfTrackingReport(
477 $selection_schema, $selection_data, $selection_both
480 // Prepare delete link content here
481 $drop_image_or_text = '';
482 if (PMA\libraries\Util::showIcons('ActionLinksMode')) {
483 $drop_image_or_text .= PMA\libraries\Util::getImage(
484 'b_drop.png', __('Delete tracking data row from report')
487 if (PMA\libraries\Util::showText('ActionLinksMode')) {
488 $drop_image_or_text .= __('Delete');
492 * First, list tracked data definition statements
494 if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
495 $msg = Message::notice(__('No data'));
496 $msg->display();
499 $html .= PMA_getHtmlForTrackingReportExportForm1(
500 $data, $url_params, $selection_schema, $selection_data, $selection_both,
501 $filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3,
502 $str4, $str5, $drop_image_or_text
505 $html .= PMA_getHtmlForTrackingReportExportForm2(
506 $url_params, $str1, $str2, $str3, $str4, $str5
509 $html .= "<br/><br/><hr/><br/>\n";
511 return $html;
515 * Generate HTML element for report form
517 * @param boolean $selection_schema selection schema
518 * @param boolean $selection_data selection data
519 * @param boolean $selection_both selection both
521 * @return array
523 function PMA_getHtmlForElementsOfTrackingReport(
524 $selection_schema, $selection_data, $selection_both
526 $str1 = '<select name="logtype">'
527 . '<option value="schema"'
528 . ($selection_schema ? ' selected="selected"' : '') . '>'
529 . __('Structure only') . '</option>'
530 . '<option value="data"'
531 . ($selection_data ? ' selected="selected"' : '') . '>'
532 . __('Data only') . '</option>'
533 . '<option value="schema_and_data"'
534 . ($selection_both ? ' selected="selected"' : '') . '>'
535 . __('Structure and data') . '</option>'
536 . '</select>';
537 $str2 = '<input type="text" name="date_from" value="'
538 . htmlspecialchars($_REQUEST['date_from']) . '" size="19" />';
539 $str3 = '<input type="text" name="date_to" value="'
540 . htmlspecialchars($_REQUEST['date_to']) . '" size="19" />';
541 $str4 = '<input type="text" name="users" value="'
542 . htmlspecialchars($_REQUEST['users']) . '" />';
543 $str5 = '<input type="hidden" name="list_report" value="1" />'
544 . '<input type="submit" value="' . __('Go') . '" />';
545 return array($str1, $str2, $str3, $str4, $str5);
549 * Generate HTML for export form
551 * @param array $data data
552 * @param array $url_params url params
553 * @param boolean $selection_schema selection schema
554 * @param boolean $selection_data selection data
555 * @param boolean $selection_both selection both
556 * @param int $filter_ts_to filter time stamp from
557 * @param int $filter_ts_from filter time stamp tp
558 * @param array $filter_users filter users
559 * @param string $str1 HTML for logtype select
560 * @param string $str2 HTML for "from date"
561 * @param string $str3 HTML for "to date"
562 * @param string $str4 HTML for user
563 * @param string $str5 HTML for "list report"
564 * @param string $drop_image_or_text HTML for image or text
566 * @return string HTML for form
568 function PMA_getHtmlForTrackingReportExportForm1(
569 $data, $url_params, $selection_schema, $selection_data, $selection_both,
570 $filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3,
571 $str4, $str5, $drop_image_or_text
573 $ddlog_count = 0;
575 $html = '<form method="post" action="tbl_tracking.php'
576 . URL::getCommon(
577 $url_params + array(
578 'report' => 'true', 'version' => $_REQUEST['version']
581 . '">';
582 $html .= URL::getHiddenInputs();
584 $html .= sprintf(
585 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
586 $str1, $str2, $str3, $str4, $str5
589 if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
590 list($temp, $ddlog_count) = PMA_getHtmlForDataDefinitionStatements(
591 $data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
592 $drop_image_or_text
594 $html .= $temp;
595 unset($temp);
596 } //endif
599 * Secondly, list tracked data manipulation statements
601 if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
602 $html .= PMA_getHtmlForDataManipulationStatements(
603 $data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
604 $ddlog_count, $drop_image_or_text
607 $html .= '</form>';
608 return $html;
612 * Generate HTML for export form
614 * @param array $url_params Parameters
615 * @param string $str1 HTML for logtype select
616 * @param string $str2 HTML for "from date"
617 * @param string $str3 HTML for "to date"
618 * @param string $str4 HTML for user
619 * @param string $str5 HTML for "list report"
621 * @return string HTML for form
623 function PMA_getHtmlForTrackingReportExportForm2(
624 $url_params, $str1, $str2, $str3, $str4, $str5
626 $html = '<form method="post" action="tbl_tracking.php'
627 . URL::getCommon(
628 $url_params + array(
629 'report' => 'true', 'version' => $_REQUEST['version']
632 . '">';
633 $html .= URL::getHiddenInputs();
634 $html .= sprintf(
635 __('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
636 $str1, $str2, $str3, $str4, $str5
638 $html .= '</form>';
640 $html .= '<form class="disableAjax" method="post" action="tbl_tracking.php'
641 . URL::getCommon(
642 $url_params
643 + array('report' => 'true', 'version' => $_REQUEST['version'])
645 . '">';
646 $html .= URL::getHiddenInputs();
647 $html .= '<input type="hidden" name="logtype" value="'
648 . htmlspecialchars($_REQUEST['logtype']) . '" />';
649 $html .= '<input type="hidden" name="date_from" value="'
650 . htmlspecialchars($_REQUEST['date_from']) . '" />';
651 $html .= '<input type="hidden" name="date_to" value="'
652 . htmlspecialchars($_REQUEST['date_to']) . '" />';
653 $html .= '<input type="hidden" name="users" value="'
654 . htmlspecialchars($_REQUEST['users']) . '" />';
656 $str_export1 = '<select name="export_type">'
657 . '<option value="sqldumpfile">' . __('SQL dump (file download)')
658 . '</option>'
659 . '<option value="sqldump">' . __('SQL dump') . '</option>'
660 . '<option value="execution" onclick="alert(\''
661 . Sanitize::escapeJsString(
662 __('This option will replace your table and contained data.')
664 . '\')">' . __('SQL execution') . '</option>' . '</select>';
666 $str_export2 = '<input type="hidden" name="report_export" value="1" />'
667 . '<input type="submit" value="' . __('Go') . '" />';
669 $html .= "<br/>" . sprintf(__('Export as %s'), $str_export1)
670 . $str_export2 . "<br/>";
671 $html .= '</form>';
672 return $html;
676 * Function to get html for data manipulation statements
678 * @param array $data data
679 * @param array $filter_users filter users
680 * @param int $filter_ts_from filter time staml from
681 * @param int $filter_ts_to filter time stamp to
682 * @param array $url_params url parameters
683 * @param int $ddlog_count data definition log count
684 * @param string $drop_image_or_text drop image or text
686 * @return string
688 function PMA_getHtmlForDataManipulationStatements($data, $filter_users,
689 $filter_ts_from, $filter_ts_to, $url_params, $ddlog_count,
690 $drop_image_or_text
692 // no need for the secondth returned parameter
693 list($html,) = PMA_getHtmlForDataStatements(
694 $data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
695 $drop_image_or_text, 'dmlog', __('Data manipulation statement'),
696 $ddlog_count, 'dml_versions'
699 return $html;
703 * Function to get html for one data manipulation statement
705 * @param array $entry entry
706 * @param array $filter_users filter users
707 * @param int $filter_ts_from filter time stamp from
708 * @param int $filter_ts_to filter time stamp to
709 * @param int $line_number line number
710 * @param array $url_params url parameters
711 * @param int $offset line number offset
712 * @param string $drop_image_or_text drop image or text
713 * @param string $delete_param parameter for delete
715 * @return string
717 function PMA_getHtmlForOneStatement($entry, $filter_users,
718 $filter_ts_from, $filter_ts_to, $line_number, $url_params, $offset,
719 $drop_image_or_text, $delete_param
721 $statement = PMA\libraries\Util::formatSql($entry['statement'], true);
722 $timestamp = strtotime($entry['date']);
723 $filtered_user = in_array($entry['username'], $filter_users);
724 $html = null;
726 if ($timestamp >= $filter_ts_from
727 && $timestamp <= $filter_ts_to
728 && (in_array('*', $filter_users) || $filtered_user)
730 $html = '<tr class="noclick">';
731 $html .= '<td class="right"><small>' . $line_number . '</small></td>';
732 $html .= '<td><small>'
733 . htmlspecialchars($entry['date']) . '</small></td>';
734 $html .= '<td><small>'
735 . htmlspecialchars($entry['username']) . '</small></td>';
736 $html .= '<td>' . $statement . '</td>';
737 $html .= '<td class="nowrap"><a class="delete_entry_anchor ajax"'
738 . ' href="tbl_tracking.php'
739 . URL::getCommon(
740 $url_params + array(
741 'report' => 'true',
742 'version' => $_REQUEST['version'],
743 $delete_param => ($line_number - $offset),
746 . '">'
747 . $drop_image_or_text
748 . '</a></td>';
749 $html .= '</tr>';
752 return $html;
755 * Function to get html for data definition statements in schema snapshot
757 * @param array $data data
758 * @param array $filter_users filter users
759 * @param int $filter_ts_from filter time stamp from
760 * @param int $filter_ts_to filter time stamp to
761 * @param array $url_params url parameters
762 * @param string $drop_image_or_text drop image or text
764 * @return array
766 function PMA_getHtmlForDataDefinitionStatements($data, $filter_users,
767 $filter_ts_from, $filter_ts_to, $url_params, $drop_image_or_text
769 list($html, $line_number) = PMA_getHtmlForDataStatements(
770 $data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
771 $drop_image_or_text, 'ddlog', __('Data definition statement'),
772 1, 'ddl_versions'
775 return array($html, $line_number);
779 * Function to get html for data statements in schema snapshot
781 * @param array $data data
782 * @param array $filter_users filter users
783 * @param int $filter_ts_from filter time stamp from
784 * @param int $filter_ts_to filter time stamp to
785 * @param array $url_params url parameters
786 * @param string $drop_image_or_text drop image or text
787 * @param string $which_log dmlog|ddlog
788 * @param string $header_message message for this section
789 * @param int $line_number line number
790 * @param string $table_id id for the table element
792 * @return array
794 function PMA_getHtmlForDataStatements($data, $filter_users,
795 $filter_ts_from, $filter_ts_to, $url_params, $drop_image_or_text,
796 $which_log, $header_message, $line_number, $table_id
798 $offset = $line_number;
799 $html = '<table id="' . $table_id . '" class="data" width="100%">';
800 $html .= '<thead>';
801 $html .= '<tr>';
802 $html .= '<th width="18">#</th>';
803 $html .= '<th width="100">' . __('Date') . '</th>';
804 $html .= '<th width="60">' . __('Username') . '</th>';
805 $html .= '<th>' . $header_message . '</th>';
806 $html .= '<th>' . __('Action') . '</th>';
807 $html .= '</tr>';
808 $html .= '</thead>';
809 $html .= '<tbody>';
811 foreach ($data[$which_log] as $entry) {
812 $html .= PMA_getHtmlForOneStatement(
813 $entry, $filter_users, $filter_ts_from, $filter_ts_to,
814 $line_number, $url_params, $offset, $drop_image_or_text,
815 'delete_' . $which_log
817 $line_number++;
819 $html .= '</tbody>';
820 $html .= '</table>';
822 return array($html, $line_number);
826 * Function to get html for schema snapshot
828 * @param string $url_query url query
830 * @return string
832 function PMA_getHtmlForSchemaSnapshot($url_query)
834 $html = '<h3>' . __('Structure snapshot')
835 . ' [<a href="tbl_tracking.php' . $url_query . '">' . __('Close')
836 . '</a>]</h3>';
837 $data = Tracker::getTrackedData(
838 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
841 // Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements
842 $drop_create_statements = $data['ddlog'][0]['statement'];
844 if (mb_strstr($data['ddlog'][0]['statement'], 'DROP TABLE')
845 || mb_strstr($data['ddlog'][0]['statement'], 'DROP VIEW')
847 $drop_create_statements .= $data['ddlog'][1]['statement'];
849 // Print SQL code
850 $html .= PMA\libraries\Util::getMessage(
851 sprintf(
852 __('Version %s snapshot (SQL code)'),
853 htmlspecialchars($_REQUEST['version'])
855 $drop_create_statements
858 // Unserialize snapshot
859 $temp = PMA_safeUnserialize($data['schema_snapshot']);
860 if ($temp === null) {
861 $temp = array('COLUMNS' => array(), 'INDEXES' => array());
863 $columns = $temp['COLUMNS'];
864 $indexes = $temp['INDEXES'];
865 $html .= PMA_getHtmlForColumns($columns);
867 if (count($indexes) > 0) {
868 $html .= PMA_getHtmlForIndexes($indexes);
869 } // endif
870 $html .= '<br /><hr /><br />';
872 return $html;
876 * Function to get html for displaying columns in the schema snapshot
878 * @param array $columns columns
880 * @return string
882 function PMA_getHtmlForColumns($columns)
884 $html = '<h3>' . __('Structure') . '</h3>';
885 $html .= '<table id="tablestructure" class="data">';
886 $html .= '<thead>';
887 $html .= '<tr>';
888 $html .= '<th>' . __('#') . '</th>';
889 $html .= '<th>' . __('Column') . '</th>';
890 $html .= '<th>' . __('Type') . '</th>';
891 $html .= '<th>' . __('Collation') . '</th>';
892 $html .= '<th>' . __('Null') . '</th>';
893 $html .= '<th>' . __('Default') . '</th>';
894 $html .= '<th>' . __('Extra') . '</th>';
895 $html .= '<th>' . __('Comment') . '</th>';
896 $html .= '</tr>';
897 $html .= '</thead>';
898 $html .= '<tbody>';
899 $index = 1;
900 foreach ($columns as $field) {
901 $html .= PMA_getHtmlForField($index++, $field);
904 $html .= '</tbody>';
905 $html .= '</table>';
907 return $html;
911 * Function to get html for field
913 * @param int $index index
914 * @param array $field field
916 * @return string
918 function PMA_getHtmlForField($index, $field)
920 $html = '<tr class="noclick">';
921 $html .= '<td>' . $index . '</td>';
922 $html .= '<td><b>' . htmlspecialchars($field['Field']);
923 if ($field['Key'] == 'PRI') {
924 $html .= ' ' . PMA\libraries\Util::getImage(
925 'b_primary.png', __('Primary')
927 } elseif (! empty($field['Key'])) {
928 $html .= ' ' . PMA\libraries\Util::getImage(
929 'bd_primary.png', __('Index')
932 $html .= '</b></td>';
933 $html .= "\n";
934 $html .= '<td>' . htmlspecialchars($field['Type']) . '</td>';
935 $html .= '<td>' . htmlspecialchars($field['Collation']) . '</td>';
936 $html .= '<td>' . (($field['Null'] == 'YES') ? __('Yes') : __('No')) . '</td>';
937 $html .= '<td>';
938 if (isset($field['Default'])) {
939 $extracted_columnspec = PMA\libraries\Util::extractColumnSpec(
940 $field['Type']
942 if ($extracted_columnspec['type'] == 'bit') {
943 // here, $field['Default'] contains something like b'010'
944 $html .= PMA\libraries\Util::convertBitDefaultValue($field['Default']);
945 } else {
946 $html .= htmlspecialchars($field['Default']);
948 } else {
949 if ($field['Null'] == 'YES') {
950 $html .= '<i>NULL</i>';
951 } else {
952 $html .= '<i>' . _pgettext('None for default', 'None') . '</i>';
955 $html .= '</td>';
956 $html .= '<td>' . htmlspecialchars($field['Extra']) . '</td>';
957 $html .= '<td>' . htmlspecialchars($field['Comment']) . '</td>';
958 $html .= '</tr>';
960 return $html;
964 * Function to get html for the indexes in schema snapshot
966 * @param array $indexes indexes
968 * @return string
970 function PMA_getHtmlForIndexes($indexes)
972 $html = '<h3>' . __('Indexes') . '</h3>';
973 $html .= '<table id="tablestructure_indexes" class="data">';
974 $html .= '<thead>';
975 $html .= '<tr>';
976 $html .= '<th>' . __('Keyname') . '</th>';
977 $html .= '<th>' . __('Type') . '</th>';
978 $html .= '<th>' . __('Unique') . '</th>';
979 $html .= '<th>' . __('Packed') . '</th>';
980 $html .= '<th>' . __('Column') . '</th>';
981 $html .= '<th>' . __('Cardinality') . '</th>';
982 $html .= '<th>' . __('Collation') . '</th>';
983 $html .= '<th>' . __('Null') . '</th>';
984 $html .= '<th>' . __('Comment') . '</th>';
985 $html .= '</tr>';
986 $html .= '<tbody>';
988 foreach ($indexes as $index) {
989 $html .= PMA_getHtmlForIndex($index);
991 $html .= '</tbody>';
992 $html .= '</table>';
993 return $html;
997 * Function to get html for an index in schema snapshot
999 * @param array $index index
1001 * @return string
1003 function PMA_getHtmlForIndex($index)
1005 if ($index['Non_unique'] == 0) {
1006 $str_unique = __('Yes');
1007 } else {
1008 $str_unique = __('No');
1010 if ($index['Packed'] != '') {
1011 $str_packed = __('Yes');
1012 } else {
1013 $str_packed = __('No');
1016 $html = '<tr class="noclick">';
1017 $html .= '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
1018 $html .= '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
1019 $html .= '<td>' . $str_unique . '</td>';
1020 $html .= '<td>' . $str_packed . '</td>';
1021 $html .= '<td>' . htmlspecialchars($index['Column_name']) . '</td>';
1022 $html .= '<td>' . htmlspecialchars($index['Cardinality']) . '</td>';
1023 $html .= '<td>' . htmlspecialchars($index['Collation']) . '</td>';
1024 $html .= '<td>' . htmlspecialchars($index['Null']) . '</td>';
1025 $html .= '<td>' . htmlspecialchars($index['Comment']) . '</td>';
1026 $html .= '</tr>';
1028 return $html;
1032 * Function to handle the tracking report
1034 * @param array &$data tracked data
1036 * @return string HTML for the message
1038 function PMA_deleteTrackingReportRows(&$data)
1040 $html = '';
1041 if (isset($_REQUEST['delete_ddlog'])) {
1042 // Delete ddlog row data
1043 $html .= PMA_deleteFromTrackingReportLog(
1044 $data,
1045 'ddlog',
1046 'DDL',
1047 __('Tracking data definition successfully deleted')
1051 if (isset($_REQUEST['delete_dmlog'])) {
1052 // Delete dmlog row data
1053 $html .= PMA_deleteFromTrackingReportLog(
1054 $data,
1055 'dmlog',
1056 'DML',
1057 __('Tracking data manipulation successfully deleted')
1060 return $html;
1064 * Function to delete from a tracking report log
1066 * @param array &$data tracked data
1067 * @param string $which_log ddlog|dmlog
1068 * @param string $type DDL|DML
1069 * @param string $message success message
1071 * @return string HTML for the message
1073 function PMA_deleteFromTrackingReportLog(&$data, $which_log, $type, $message)
1075 $html = '';
1076 $delete_id = $_REQUEST['delete_' . $which_log];
1078 // Only in case of valid id
1079 if ($delete_id == (int)$delete_id) {
1080 unset($data[$which_log][$delete_id]);
1082 $successfullyDeleted = Tracker::changeTrackingData(
1083 $_REQUEST['db'],
1084 $_REQUEST['table'],
1085 $_REQUEST['version'],
1086 $type,
1087 $data[$which_log]
1089 if ($successfullyDeleted) {
1090 $msg = Message::success($message);
1091 } else {
1092 $msg = Message::rawError(__('Query error'));
1094 $html .= $msg->getDisplay();
1096 return $html;
1100 * Function to export as sql dump
1102 * @param array $entries entries
1104 * @return string HTML SQL query form
1106 function PMA_exportAsSQLDump($entries)
1108 $html = '';
1109 $new_query = "# "
1110 . __(
1111 'You can execute the dump by creating and using a temporary database. '
1112 . 'Please ensure that you have the privileges to do so.'
1114 . "\n"
1115 . "# " . __('Comment out these two lines if you do not need them.') . "\n"
1116 . "\n"
1117 . "CREATE database IF NOT EXISTS pma_temp_db; \n"
1118 . "USE pma_temp_db; \n"
1119 . "\n";
1121 foreach ($entries as $entry) {
1122 $new_query .= $entry['statement'];
1124 $msg = Message::success(
1125 __('SQL statements exported. Please copy the dump or execute it.')
1127 $html .= $msg->getDisplay();
1129 $db_temp = $GLOBALS['db'];
1130 $table_temp = $GLOBALS['table'];
1132 $GLOBALS['db'] = $GLOBALS['table'] = '';
1133 include_once './libraries/sql_query_form.lib.php';
1135 $html .= PMA_getHtmlForSqlQueryForm($new_query, 'sql');
1137 $GLOBALS['db'] = $db_temp;
1138 $GLOBALS['table'] = $table_temp;
1140 return $html;
1144 * Function to export as sql execution
1146 * @param array $entries entries
1148 * @return array
1150 function PMA_exportAsSQLExecution($entries)
1152 $sql_result = array();
1153 foreach ($entries as $entry) {
1154 $sql_result = $GLOBALS['dbi']->query("/*NOTRACK*/\n" . $entry['statement']);
1157 return $sql_result;
1161 * Function to export as entries
1163 * @param array $entries entries
1165 * @return void
1167 function PMA_exportAsFileDownload($entries)
1169 @ini_set('url_rewriter.tags', '');
1171 // Replace all multiple whitespaces by a single space
1172 $table = htmlspecialchars(preg_replace('/\s+/', ' ', $_REQUEST['table']));
1173 $dump = "# " . sprintf(
1174 __('Tracking report for table `%s`'), $table
1176 . "\n" . "# " . date('Y-m-d H:i:s') . "\n";
1177 foreach ($entries as $entry) {
1178 $dump .= $entry['statement'];
1180 $filename = 'log_' . $table . '.sql';
1181 Response::getInstance()->disable();
1182 PMA_downloadHeader(
1183 $filename,
1184 'text/x-sql',
1185 strlen($dump)
1187 echo $dump;
1189 exit();
1193 * Function to activate or deactivate tracking
1195 * @param string $action activate|deactivate
1197 * @return string HTML for the success message
1199 function PMA_changeTracking($action)
1201 $html = '';
1202 if ($action == 'activate') {
1203 $method = 'activateTracking';
1204 $message = __('Tracking for %1$s was activated at version %2$s.');
1205 } else {
1206 $method = 'deactivateTracking';
1207 $message = __('Tracking for %1$s was deactivated at version %2$s.');
1209 $status = Tracker::$method(
1210 $GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
1212 if ($status) {
1213 $msg = Message::success(
1214 sprintf(
1215 $message,
1216 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
1217 htmlspecialchars($_REQUEST['version'])
1220 $html .= $msg->getDisplay();
1223 return $html;
1227 * Function to get tracking set
1229 * @return string
1231 function PMA_getTrackingSet()
1233 $tracking_set = '';
1235 // a key is absent from the request if it has been removed from
1236 // tracking_default_statements in the config
1237 if (isset($_REQUEST['alter_table']) && $_REQUEST['alter_table'] == true) {
1238 $tracking_set .= 'ALTER TABLE,';
1240 if (isset($_REQUEST['rename_table']) && $_REQUEST['rename_table'] == true) {
1241 $tracking_set .= 'RENAME TABLE,';
1243 if (isset($_REQUEST['create_table']) && $_REQUEST['create_table'] == true) {
1244 $tracking_set .= 'CREATE TABLE,';
1246 if (isset($_REQUEST['drop_table']) && $_REQUEST['drop_table'] == true) {
1247 $tracking_set .= 'DROP TABLE,';
1249 if (isset($_REQUEST['alter_view']) && $_REQUEST['alter_view'] == true) {
1250 $tracking_set .= 'ALTER VIEW,';
1252 if (isset($_REQUEST['create_view']) && $_REQUEST['create_view'] == true) {
1253 $tracking_set .= 'CREATE VIEW,';
1255 if (isset($_REQUEST['drop_view']) && $_REQUEST['drop_view'] == true) {
1256 $tracking_set .= 'DROP VIEW,';
1258 if (isset($_REQUEST['create_index']) && $_REQUEST['create_index'] == true) {
1259 $tracking_set .= 'CREATE INDEX,';
1261 if (isset($_REQUEST['drop_index']) && $_REQUEST['drop_index'] == true) {
1262 $tracking_set .= 'DROP INDEX,';
1264 if (isset($_REQUEST['insert']) && $_REQUEST['insert'] == true) {
1265 $tracking_set .= 'INSERT,';
1267 if (isset($_REQUEST['update']) && $_REQUEST['update'] == true) {
1268 $tracking_set .= 'UPDATE,';
1270 if (isset($_REQUEST['delete']) && $_REQUEST['delete'] == true) {
1271 $tracking_set .= 'DELETE,';
1273 if (isset($_REQUEST['truncate']) && $_REQUEST['truncate'] == true) {
1274 $tracking_set .= 'TRUNCATE,';
1276 $tracking_set = rtrim($tracking_set, ',');
1278 return $tracking_set;
1282 * Deletes a tracking version
1284 * @param string $version tracking version
1286 * @return string HTML of the success message
1288 function PMA_deleteTrackingVersion($version)
1290 $html = '';
1291 $versionDeleted = Tracker::deleteTracking(
1292 $GLOBALS['db'],
1293 $GLOBALS['table'],
1294 $version
1296 if ($versionDeleted) {
1297 $msg = Message::success(
1298 sprintf(
1299 __('Version %1$s of %2$s was deleted.'),
1300 htmlspecialchars($version),
1301 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
1304 $html .= $msg->getDisplay();
1307 return $html;
1311 * Function to create the tracking version
1313 * @return string HTML of the success message
1315 function PMA_createTrackingVersion()
1317 $html = '';
1318 $tracking_set = PMA_getTrackingSet();
1320 $versionCreated = Tracker::createVersion(
1321 $GLOBALS['db'],
1322 $GLOBALS['table'],
1323 $_REQUEST['version'],
1324 $tracking_set,
1325 $GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])->isView()
1327 if ($versionCreated) {
1328 $msg = Message::success(
1329 sprintf(
1330 __('Version %1$s was created, tracking for %2$s is active.'),
1331 htmlspecialchars($_REQUEST['version']),
1332 htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
1335 $html .= $msg->getDisplay();
1338 return $html;
1342 * Create tracking version for multiple tables
1344 * @param array $selected list of selected tables
1346 * @return void
1348 function PMA_createTrackingForMultipleTables($selected)
1350 $tracking_set = PMA_getTrackingSet();
1352 foreach ($selected as $selected_table) {
1353 Tracker::createVersion(
1354 $GLOBALS['db'],
1355 $selected_table,
1356 $_REQUEST['version'],
1357 $tracking_set,
1358 $GLOBALS['dbi']->getTable($GLOBALS['db'], $selected_table)->isView()
1364 * Function to get the entries
1366 * @param array $data data
1367 * @param int $filter_ts_from filter time stamp from
1368 * @param int $filter_ts_to filter time stamp to
1369 * @param array $filter_users filter users
1371 * @return array
1373 function PMA_getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users)
1375 $entries = array();
1376 // Filtering data definition statements
1377 if ($_REQUEST['logtype'] == 'schema'
1378 || $_REQUEST['logtype'] == 'schema_and_data'
1380 $entries = array_merge(
1381 $entries,
1382 PMA_filterTracking(
1383 $data['ddlog'], $filter_ts_from, $filter_ts_to, $filter_users
1388 // Filtering data manipulation statements
1389 if ($_REQUEST['logtype'] == 'data'
1390 || $_REQUEST['logtype'] == 'schema_and_data'
1392 $entries = array_merge(
1393 $entries,
1394 PMA_filterTracking(
1395 $data['dmlog'], $filter_ts_from, $filter_ts_to, $filter_users
1400 // Sort it
1401 $ids = $timestamps = $usernames = $statements = array();
1402 foreach ($entries as $key => $row) {
1403 $ids[$key] = $row['id'];
1404 $timestamps[$key] = $row['timestamp'];
1405 $usernames[$key] = $row['username'];
1406 $statements[$key] = $row['statement'];
1409 array_multisort(
1410 $timestamps, SORT_ASC, $ids, SORT_ASC, $usernames,
1411 SORT_ASC, $statements, SORT_ASC, $entries
1414 return $entries;
1418 * Function to get version status
1420 * @param array $version version info
1422 * @return string $version_status The status message
1424 function PMA_getVersionStatus($version)
1426 if ($version['tracking_active'] == 1) {
1427 return __('active');
1428 } else {
1429 return __('not active');
1434 * Display untracked tables
1436 * @param string $db current database
1437 * @param array $untracked_tables untracked tables
1438 * @param string $url_query url query string
1439 * @param string $pmaThemeImage path to theme's image folder
1440 * @param string $text_dir text direction
1442 * @return void
1444 function PMA_displayUntrackedTables(
1445 $db, $untracked_tables, $url_query, $pmaThemeImage, $text_dir
1448 <h3><?php echo __('Untracked tables');?></h3>
1449 <form method="post" action="db_tracking.php" name="untrackedForm"
1450 id="untrackedForm" class="ajax">
1451 <?php
1452 echo URL::getHiddenInputs($db)
1454 <table id="noversions" class="data">
1455 <thead>
1456 <tr>
1457 <th></th>
1458 <th style="width: 300px"><?php echo __('Table');?></th>
1459 <th><?php echo __('Action');?></th>
1460 </tr>
1461 </thead>
1462 <tbody>
1463 <?php
1465 // Print out list of untracked tables
1466 foreach ($untracked_tables as $key => $tablename) {
1467 PMA_displayOneUntrackedTable($db, $tablename, $url_query);
1470 </tbody>
1471 </table>
1472 <?php
1473 echo PMA\libraries\Template::get('select_all')
1474 ->render(
1475 array(
1476 'pmaThemeImage' => $pmaThemeImage,
1477 'text_dir' => $text_dir,
1478 'formName' => 'untrackedForm',
1481 echo PMA\libraries\Util::getButtonOrImage(
1482 'submit_mult', 'mult_submit',
1483 __('Track table'), 'eye.png', 'track'
1486 </form>
1487 <?php
1491 * Display one untracked table
1493 * @param string $db current database
1494 * @param string $tablename the table name for which to display a line
1495 * @param string $url_query url query string
1497 * @return void
1499 function PMA_displayOneUntrackedTable($db, $tablename, $url_query)
1501 $checkbox_id = "selected_tbl_"
1502 . htmlspecialchars($tablename);
1503 if (Tracker::getVersion($db, $tablename) == -1) {
1504 $my_link = '<a href="tbl_tracking.php' . $url_query
1505 . '&amp;table=' . htmlspecialchars($tablename) . '">';
1506 $my_link .= PMA\libraries\Util::getIcon('eye.png', __('Track table'));
1507 $my_link .= '</a>';
1509 <tr>
1510 <td class="center">
1511 <input type="checkbox" name="selected_tbl[]"
1512 class="checkall" id="<?php echo $checkbox_id;?>"
1513 value="<?php echo htmlspecialchars($tablename);?>"/>
1514 </td>
1515 <th>
1516 <label for="<?php echo $checkbox_id;?>">
1517 <?php echo htmlspecialchars($tablename);?>
1518 </label>
1519 </th>
1520 <td><?php echo $my_link;?></td>
1521 </tr>
1522 <?php
1527 * Helper function: Recursive function for getting table names from $table_list
1529 * @param string $db current database
1531 * @return array $untracked_tables
1533 function PMA_extractTableNames($table_list, $db, $testing=false) {
1534 $untracked_tables = array();
1535 $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
1537 foreach ($table_list as $key => $value) {
1538 if (is_array($value) && array_key_exists(('is' . $sep . 'group'), $value)
1539 && $value['is' . $sep . 'group']
1541 $untracked_tables = array_merge(PMA_extractTableNames($value, $db), $untracked_tables); //Recursion step
1543 else {
1544 if (is_array($value) && ($testing || Tracker::getVersion($db, $value['Name']) == -1)) {
1545 $untracked_tables[] = $value['Name'];
1549 return $untracked_tables;
1554 * Get untracked tables
1556 * @param string $db current database
1558 * @return array $untracked_tables
1560 function PMA_getUntrackedTables($db)
1562 $table_list = PMA\libraries\Util::getTableList($db);
1563 $untracked_tables = PMA_extractTableNames($table_list, $db); //Use helper function to get table list recursively.
1564 return $untracked_tables;
1568 * Display tracked tables
1570 * @param string $db current database
1571 * @param object $all_tables_result result set of tracked tables
1572 * @param string $url_query url query string
1573 * @param string $pmaThemeImage path to theme's image folder
1574 * @param string $text_dir text direction
1575 * @param array $cfgRelation configuration storage info
1577 * @return void
1579 function PMA_displayTrackedTables(
1580 $db, $all_tables_result, $url_query, $pmaThemeImage, $text_dir, $cfgRelation
1583 <div id="tracked_tables">
1584 <h3><?php echo __('Tracked tables');?></h3>
1586 <form method="post" action="db_tracking.php" name="trackedForm"
1587 id="trackedForm" class="ajax">
1588 <?php
1589 echo URL::getHiddenInputs($db)
1591 <table id="versions" class="data">
1592 <thead>
1593 <tr>
1594 <th></th>
1595 <th><?php echo __('Table');?></th>
1596 <th><?php echo __('Last version');?></th>
1597 <th><?php echo __('Created');?></th>
1598 <th><?php echo __('Updated');?></th>
1599 <th><?php echo __('Status');?></th>
1600 <th><?php echo __('Action');?></th>
1601 <th><?php echo __('Show');?></th>
1602 </tr>
1603 </thead>
1604 <tbody>
1605 <?php
1607 // Print out information about versions
1609 $delete = PMA\libraries\Util::getIcon('b_drop.png', __('Delete tracking'));
1610 $versions = PMA\libraries\Util::getIcon('b_versions.png', __('Versions'));
1611 $report = PMA\libraries\Util::getIcon('b_report.png', __('Tracking report'));
1612 $structure = PMA\libraries\Util::getIcon(
1613 'b_props.png',
1614 __('Structure snapshot')
1617 while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
1618 list($table_name, $version_number) = $one_result;
1619 $table_query = ' SELECT * FROM ' .
1620 PMA\libraries\Util::backquote($cfgRelation['db']) . '.' .
1621 PMA\libraries\Util::backquote($cfgRelation['tracking']) .
1622 ' WHERE `db_name` = \''
1623 . $GLOBALS['dbi']->escapeString($_REQUEST['db'])
1624 . '\' AND `table_name` = \''
1625 . $GLOBALS['dbi']->escapeString($table_name)
1626 . '\' AND `version` = \'' . $version_number . '\'';
1628 $table_result = PMA_queryAsControlUser($table_query);
1629 $version_data = $GLOBALS['dbi']->fetchArray($table_result);
1631 $tbl_link = 'tbl_tracking.php' . $url_query . '&amp;table='
1632 . htmlspecialchars($version_data['table_name']);
1633 $delete_link = 'db_tracking.php' . $url_query . '&amp;table='
1634 . htmlspecialchars($version_data['table_name'])
1635 . '&amp;delete_tracking=true&amp';
1636 $checkbox_id = "selected_tbl_"
1637 . htmlspecialchars($version_data['table_name']);
1639 <tr>
1640 <td class="center">
1641 <input type="checkbox" name="selected_tbl[]"
1642 class="checkall" id="<?php echo $checkbox_id;?>"
1643 value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
1644 </td>
1645 <th>
1646 <label for="<?php echo $checkbox_id;?>">
1647 <?php echo htmlspecialchars($version_data['table_name']);?>
1648 </label>
1649 </th>
1650 <td class="right"><?php echo $version_data['version'];?></td>
1651 <td><?php echo $version_data['date_created'];?></td>
1652 <td><?php echo $version_data['date_updated'];?></td>
1653 <td>
1654 <?php
1655 PMA_displayStatusButton($version_data, $tbl_link);
1657 </td>
1658 <td>
1659 <a class="delete_tracking_anchor ajax"
1660 href="<?php echo $delete_link;?>" >
1661 <?php echo $delete; ?></a>
1662 <?php
1663 echo '</td>'
1664 , '<td>'
1665 , '<a href="' , $tbl_link , '">' , $versions , '</a>'
1666 , '&nbsp;&nbsp;'
1667 , '<a href="' , $tbl_link , '&amp;report=true&amp;version='
1668 , $version_data['version'] , '">' , $report , '</a>'
1669 , '&nbsp;&nbsp;'
1670 , '<a href="' . $tbl_link , '&amp;snapshot=true&amp;version='
1671 , $version_data['version'] , '">' , $structure , '</a>'
1672 , '</td>'
1673 , '</tr>';
1676 </tbody>
1677 </table>
1678 <?php
1679 echo PMA\libraries\Template::get('select_all')
1680 ->render(
1681 array(
1682 'pmaThemeImage' => $pmaThemeImage,
1683 'text_dir' => $text_dir,
1684 'formName' => 'trackedForm',
1687 echo PMA\libraries\Util::getButtonOrImage(
1688 'submit_mult', 'mult_submit',
1689 __('Delete tracking'), 'b_drop.png', 'delete_tracking'
1692 </form>
1693 </div>
1694 <?php
1698 * Display tracking status button
1700 * @param array $version_data data about tracking versions
1701 * @param string $tbl_link link for tbl_tracking.php
1703 * @return void
1705 function PMA_displayStatusButton($version_data, $tbl_link)
1707 $state = PMA_getVersionStatus($version_data);
1708 $options = array(
1709 0 => array(
1710 'label' => __('not active'),
1711 'value' => 'deactivate_now',
1712 'selected' => ($state != 'active')
1714 1 => array(
1715 'label' => __('active'),
1716 'value' => 'activate_now',
1717 'selected' => ($state == 'active')
1720 echo PMA\libraries\Util::toggleButton(
1721 $tbl_link . '&amp;version=' . $version_data['version'],
1722 'toggle_activation',
1723 $options,
1724 null