1 | <?php |
||
2 | /* vim: set expandtab sw=4 ts=4 sts=4: */ |
||
3 | /** |
||
4 | * Tracking configuration for database |
||
5 | * |
||
6 | * @package PhpMyAdmin |
||
7 | */ |
||
8 | declare(strict_types=1); |
||
9 | |||
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; |
||
17 | |||
18 | /** |
||
19 | * Run common work |
||
20 | */ |
||
21 | require_once 'libraries/common.inc.php'; |
||
22 | |||
23 | //Get some js files needed for Ajax requests |
||
24 | $response = Response::getInstance(); |
||
25 | $header = $response->getHeader(); |
||
26 | $scripts = $header->getScripts(); |
||
27 | $scripts->addFile('vendor/jquery/jquery.tablesorter.js'); |
||
28 | $scripts->addFile('db_tracking.js'); |
||
29 | |||
30 | $tracking = new Tracking(); |
||
31 | |||
32 | /** |
||
33 | * If we are not in an Ajax request, then do the common work and show the links etc. |
||
34 | */ |
||
35 | require 'libraries/db_common.inc.php'; |
||
36 | $url_query .= '&goto=tbl_tracking.php&back=db_tracking.php'; |
||
37 | |||
38 | // Get the database structure |
||
39 | $sub_part = '_structure'; |
||
40 | |||
41 | list( |
||
42 | $tables, |
||
43 | $num_tables, |
||
44 | $total_num_tables, |
||
45 | $sub_part, |
||
46 | $is_show_stats, |
||
47 | $db_is_system_schema, |
||
48 | $tooltip_truename, |
||
49 | $tooltip_aliasname, |
||
50 | $pos |
||
51 | ) = Util::getDbInfo($db, is_null($sub_part) ? '' : $sub_part); |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
52 | |||
53 | // Work to do? |
||
54 | // (here, do not use $_REQUEST['db] as it can be crafted) |
||
55 | if (isset($_REQUEST['delete_tracking']) && isset($_REQUEST['table'])) { |
||
56 | Tracker::deleteTracking($GLOBALS['db'], $_REQUEST['table']); |
||
57 | Message::success( |
||
58 | __('Tracking data deleted successfully.') |
||
59 | )->display(); |
||
60 | } elseif (isset($_REQUEST['submit_create_version'])) { |
||
61 | $tracking->createTrackingForMultipleTables($_REQUEST['selected']); |
||
62 | Message::success( |
||
63 | sprintf( |
||
64 | __( |
||
65 | 'Version %1$s was created for selected tables,' |
||
66 | . ' tracking is active for them.' |
||
67 | ), |
||
68 | htmlspecialchars($_REQUEST['version']) |
||
69 | ) |
||
70 | )->display(); |
||
71 | } elseif (isset($_REQUEST['submit_mult'])) { |
||
72 | if (! empty($_REQUEST['selected_tbl'])) { |
||
73 | if ($_REQUEST['submit_mult'] == 'delete_tracking') { |
||
74 | foreach ($_REQUEST['selected_tbl'] as $table) { |
||
75 | Tracker::deleteTracking($GLOBALS['db'], $table); |
||
76 | } |
||
77 | Message::success( |
||
78 | __('Tracking data deleted successfully.') |
||
79 | )->display(); |
||
80 | } elseif ($_REQUEST['submit_mult'] == 'track') { |
||
81 | echo $tracking->getHtmlForDataDefinitionAndManipulationStatements( |
||
82 | 'db_tracking.php' . $url_query, |
||
83 | 0, |
||
84 | $GLOBALS['db'], |
||
85 | $_REQUEST['selected_tbl'] |
||
86 | ); |
||
87 | exit; |
||
88 | } |
||
89 | } else { |
||
90 | Message::notice( |
||
91 | __('No tables selected.') |
||
92 | )->display(); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | // Get tracked data about the database |
||
97 | $data = Tracker::getTrackedData($_REQUEST['db'], '', '1'); |
||
98 | |||
99 | // No tables present and no log exist |
||
100 | if ($num_tables == 0 && count($data['ddlog']) == 0) { |
||
101 | echo '<p>' , __('No tables found in database.') , '</p>' , "\n"; |
||
102 | |||
103 | if (empty($db_is_system_schema)) { |
||
104 | echo CreateTable::getHtml($db); |
||
105 | } |
||
106 | exit; |
||
107 | } |
||
108 | |||
109 | // --------------------------------------------------------------------------- |
||
110 | echo $tracking->getHtmlForDbTrackingTables( |
||
111 | $GLOBALS['db'], |
||
112 | $_REQUEST['db'], |
||
113 | $url_query, |
||
114 | $pmaThemeImage, |
||
115 | $text_dir |
||
116 | ); |
||
117 | |||
118 | // If available print out database log |
||
119 | if (count($data['ddlog']) > 0) { |
||
120 | $log = ''; |
||
121 | foreach ($data['ddlog'] as $entry) { |
||
122 | $log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n" |
||
123 | . $entry['statement'] . "\n"; |
||
124 | } |
||
125 | echo Util::getMessage(__('Database Log'), $log); |
||
126 | } |
||
127 |