Fix PHP error when exporting without php-zip
[phpmyadmin.git] / db_tracking.php
blobfb508b500464dab8e7bc8f431be92c58b01396b0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Tracking configuration for database
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Display\CreateTable;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Relation;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\Tracker;
15 use PhpMyAdmin\Tracking;
16 use PhpMyAdmin\Util;
18 if (! defined('ROOT_PATH')) {
19 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
22 global $db, $pmaThemeImage, $text_dir, $url_query;
24 require_once ROOT_PATH . 'libraries/common.inc.php';
26 //Get some js files needed for Ajax requests
27 $response = Response::getInstance();
28 $header = $response->getHeader();
29 $scripts = $header->getScripts();
30 $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
31 $scripts->addFile('database/tracking.js');
33 /** @var Tracking $tracking */
34 $tracking = $containerBuilder->get('tracking');
36 /**
37 * If we are not in an Ajax request, then do the common work and show the links etc.
39 require ROOT_PATH . 'libraries/db_common.inc.php';
40 $url_query .= '&amp;goto=tbl_tracking.php&amp;back=db_tracking.php';
41 $url_params['goto'] = 'tbl_tracking.php';
42 $url_params['back'] = 'db_tracking.php';
44 // Get the database structure
45 $sub_part = '_structure';
47 list(
48 $tables,
49 $num_tables,
50 $total_num_tables,
51 $sub_part,
52 $is_show_stats,
53 $db_is_system_schema,
54 $tooltip_truename,
55 $tooltip_aliasname,
56 $pos
57 ) = Util::getDbInfo($db, $sub_part === null ? '' : $sub_part);
59 if (isset($_POST['delete_tracking']) && isset($_POST['table'])) {
60 Tracker::deleteTracking($db, $_POST['table']);
61 Message::success(
62 __('Tracking data deleted successfully.')
63 )->display();
64 } elseif (isset($_POST['submit_create_version'])) {
65 $tracking->createTrackingForMultipleTables($_POST['selected']);
66 Message::success(
67 sprintf(
68 __(
69 'Version %1$s was created for selected tables,'
70 . ' tracking is active for them.'
72 htmlspecialchars($_POST['version'])
74 )->display();
75 } elseif (isset($_POST['submit_mult'])) {
76 if (! empty($_POST['selected_tbl'])) {
77 if ($_POST['submit_mult'] == 'delete_tracking') {
78 foreach ($_POST['selected_tbl'] as $table) {
79 Tracker::deleteTracking($db, $table);
81 Message::success(
82 __('Tracking data deleted successfully.')
83 )->display();
84 } elseif ($_POST['submit_mult'] == 'track') {
85 echo $tracking->getHtmlForDataDefinitionAndManipulationStatements(
86 'db_tracking.php' . $url_query,
88 $db,
89 $_POST['selected_tbl']
91 exit;
93 } else {
94 Message::notice(
95 __('No tables selected.')
96 )->display();
100 // Get tracked data about the database
101 $data = Tracker::getTrackedData($db, '', '1');
103 // No tables present and no log exist
104 if ($num_tables == 0 && count($data['ddlog']) === 0) {
105 echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
107 if (empty($db_is_system_schema)) {
108 echo CreateTable::getHtml($db);
110 exit;
113 // ---------------------------------------------------------------------------
114 echo $tracking->getHtmlForDbTrackingTables(
115 $db,
116 $url_query,
117 $pmaThemeImage,
118 $text_dir
121 // If available print out database log
122 if (count($data['ddlog']) > 0) {
123 $log = '';
124 foreach ($data['ddlog'] as $entry) {
125 $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
126 . $entry['statement'] . "\n";
128 echo Util::getMessage(__('Database Log'), $log);