1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functions used for database and table tracking
*
* @package PhpMyAdmin
*/
use PMA\libraries\Message;
use PMA\libraries\Response;
use PMA\libraries\Tracker;
/**
* Filters tracking entries
*
* @param array $data the entries to filter
* @param string $filter_ts_from "from" date
* @param string $filter_ts_to "to" date
* @param array $filter_users users
*
* @return array filtered entries
*/
function PMA_filterTracking(
$data, $filter_ts_from, $filter_ts_to, $filter_users
) {
$tmp_entries = array();
$id = 0;
foreach ($data as $entry) {
$timestamp = strtotime($entry['date']);
$filtered_user = in_array($entry['username'], $filter_users);
if ($timestamp >= $filter_ts_from
&& $timestamp <= $filter_ts_to
&& (in_array('*', $filter_users) || $filtered_user)
) {
$tmp_entries[] = array(
'id' => $id,
'timestamp' => $timestamp,
'username' => $entry['username'],
'statement' => $entry['statement']
);
}
$id++;
}
return($tmp_entries);
}
/**
* Function to get html for data definition and data manipulation statements
*
* @param string $url_query url query
* @param int $last_version last version
* @param string $db database
* @param array $selected selected tables
* @param string $type type of the table; table, view or both
*
* @return string
*/
function PMA_getHtmlForDataDefinitionAndManipulationStatements($url_query,
$last_version, $db, $selected, $type = 'both'
) {
$html = '<div id="div_create_version">';
$html .= '<form method="post" action="' . $url_query . '">';
$html .= PMA_URL_getHiddenInputs($db);
foreach ($selected as $selected_table) {
$html .= '<input type="hidden" name="selected[]"'
. ' value="' . htmlspecialchars($selected_table) . '" />';
}
$html .= '<fieldset>';
$html .= '<legend>';
if (count($selected) == 1) {
$html .= sprintf(
__('Create version %1$s of %2$s'),
($last_version + 1),
htmlspecialchars($db . '.' . $selected[0])
);
} else {
$html .= sprintf(__('Create version %1$s'), ($last_version + 1));
}
$html .= '</legend>';
$html .= '<input type="hidden" name="version" value="' . ($last_version + 1)
. '" />';
$html .= '<p>' . __('Track these data definition statements:')
. '</p>';
if ($type == 'both' || $type == 'table') {
$html .= '<input type="checkbox" name="alter_table" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'ALTER TABLE'
) !== false ? ' checked="checked"' : '')
. ' /> ALTER TABLE<br/>';
$html .= '<input type="checkbox" name="rename_table" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'RENAME TABLE'
) !== false ? ' checked="checked"' : '')
. ' /> RENAME TABLE<br/>';
$html .= '<input type="checkbox" name="create_table" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'CREATE TABLE'
) !== false ? ' checked="checked"' : '')
. ' /> CREATE TABLE<br/>';
$html .= '<input type="checkbox" name="drop_table" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'DROP TABLE'
) !== false ? ' checked="checked"' : '')
. ' /> DROP TABLE<br/>';
}
if ($type == 'both') {
$html .= '<br/>';
}
if ($type == 'both' || $type == 'view') {
$html .= '<input type="checkbox" name="alter_view" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'ALTER VIEW'
) !== false ? ' checked="checked"' : '')
. ' /> ALTER VIEW<br/>';
$html .= '<input type="checkbox" name="create_view" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'CREATE VIEW'
) !== false ? ' checked="checked"' : '')
. ' /> CREATE VIEW<br/>';
$html .= '<input type="checkbox" name="drop_view" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'DROP VIEW'
) !== false ? ' checked="checked"' : '')
. ' /> DROP VIEW<br/>';
}
$html .= '<br/>';
$html .= '<input type="checkbox" name="create_index" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'CREATE INDEX'
) !== false ? ' checked="checked"' : '')
. ' /> CREATE INDEX<br/>';
$html .= '<input type="checkbox" name="drop_index" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'DROP INDEX'
) !== false ? ' checked="checked"' : '')
. ' /> DROP INDEX<br/>';
$html .= '<p>' . __('Track these data manipulation statements:') . '</p>';
$html .= '<input type="checkbox" name="insert" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'INSERT'
) !== false ? ' checked="checked"' : '')
. ' /> INSERT<br/>';
$html .= '<input type="checkbox" name="update" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'UPDATE'
) !== false ? ' checked="checked"' : '')
. ' /> UPDATE<br/>';
$html .= '<input type="checkbox" name="delete" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'DELETE'
) !== false ? ' checked="checked"' : '')
. ' /> DELETE<br/>';
$html .= '<input type="checkbox" name="truncate" value="true"'
. (mb_stripos(
$GLOBALS['cfg']['Server']['tracking_default_statements'],
'TRUNCATE'
) !== false ? ' checked="checked"' : '')
. ' /> TRUNCATE<br/>';
$html .= '</fieldset>';
$html .= '<fieldset class="tblFooters">';
$html .= '<input type="hidden" name="submit_create_version" value="1" />';
$html .= '<input type="submit" value="' . __('Create version') . '" />';
$html .= '</fieldset>';
$html .= '</form>';
$html .= '</div>';
return $html;
}
/**
* Function to get html for activate/deactivate tracking
*
* @param string $action activate|deactivate
* @param string $url_query url query
* @param int $last_version last version
*
* @return string
*/
function PMA_getHtmlForActivateDeactivateTracking(
$action, $url_query, $last_version
) {
$html = '<div>';
$html .= '<form method="post" action="tbl_tracking.php' . $url_query . '">';
$html .= '<fieldset>';
$html .= '<legend>';
switch($action) {
case 'activate':
$legend = __('Activate tracking for %s');
$value = "activate_now";
$button = __('Activate now');
break;
case 'deactivate':
$legend = __('Deactivate tracking for %s');
$value = "deactivate_now";
$button = __('Deactivate now');
break;
default:
$legend = '';
$value = '';
$button = '';
}
$html .= sprintf(
$legend,
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
);
$html .= '</legend>';
$html .= '<input type="hidden" name="version" value="' . $last_version . '" />';
$html .= '<input type="hidden" name="toggle_activation" value="' . $value
. '" />';
$html .= '<input type="submit" value="' . $button . '" />';
$html .= '</fieldset>';
$html .= '</form>';
$html .= '</div>';
return $html;
}
/**
* Function to get the list versions of the table
*
* @return array
*/
function PMA_getListOfVersionsOfTable()
{
$cfgRelation = PMA_getRelationsParam();
$sql_query = " SELECT * FROM " .
PMA\libraries\Util::backquote($cfgRelation['db']) . "." .
PMA\libraries\Util::backquote($cfgRelation['tracking']) .
" WHERE db_name = '" . $GLOBALS['dbi']->escapeString($_REQUEST['db']) .
"' " .
" AND table_name = '" .
$GLOBALS['dbi']->escapeString($_REQUEST['table']) . "' " .
" ORDER BY version DESC ";
return PMA_queryAsControlUser($sql_query);
}
/**
* Function to get html for displaying last version number
*
* @param array $sql_result sql result
* @param int $last_version last version
* @param array $url_params url parameters
* @param string $url_query url query
* @param string $pmaThemeImage path to theme's image folder
* @param string $text_dir text direction
*
* @return string
*/
function PMA_getHtmlForTableVersionDetails(
$sql_result, $last_version, $url_params,
$url_query, $pmaThemeImage, $text_dir
) {
$tracking_active = false;
$html = '<form method="post" action="tbl_tracking.php" name="versionsForm"'
. ' id="versionsForm" class="ajax">';
$html .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
$html .= '<table id="versions" class="data">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th></th>';
$html .= '<th>' . __('Version') . '</th>';
$html .= '<th>' . __('Created') . '</th>';
$html .= '<th>' . __('Updated') . '</th>';
$html .= '<th>' . __('Status') . '</th>';
$html .= '<th>' . __('Action') . '</th>';
$html .= '<th>' . __('Show') . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$style = 'odd';
$GLOBALS['dbi']->dataSeek($sql_result, 0);
$delete = PMA\libraries\Util::getIcon('b_drop.png', __('Delete version'));
$report = PMA\libraries\Util::getIcon('b_report.png', __('Tracking report'));
$structure = PMA\libraries\Util::getIcon(
'b_props.png',
__('Structure snapshot')
);
while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
if ($version['version'] == $last_version) {
if ($version['tracking_active'] == 1) {
$tracking_active = true;
} else {
$tracking_active = false;
}
}
$delete_link = 'tbl_tracking.php' . $url_query . '&version='
. htmlspecialchars($version['version'])
. '&submit_delete_version=true';
$checkbox_id = 'selected_versions_' . htmlspecialchars($version['version']);
$html .= '<tr class="' . $style . '">';
$html .= '<td class="center">';
$html .= '<input type="checkbox" name="selected_versions[]"'
. ' class="checkall" id="' . $checkbox_id . '"'
. ' value="' . htmlspecialchars($version['version']) . '"/>';
$html .= '</td>';
$html .= '<th class="floatright">';
$html .= '<label for="' . $checkbox_id . '">'
. htmlspecialchars($version['version']) . '</label>';
$html .= '</th>';
$html .= '<td>' . htmlspecialchars($version['date_created']) . '</td>';
$html .= '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
$html .= '<td>' . PMA_getVersionStatus($version) . '</td>';
$html .= '<td><a class="delete_version_anchor ajax"'
. ' href="' . $delete_link . '" >' . $delete . '</a></td>';
$html .= '<td><a href="tbl_tracking.php';
$html .= PMA_URL_getCommon(
$url_params + array(
'report' => 'true', 'version' => $version['version']
)
);
$html .= '">' . $report . '</a>';
$html .= ' ';
$html .= '<a href="tbl_tracking.php';
$html .= PMA_URL_getCommon(
$url_params + array(
'snapshot' => 'true', 'version' => $version['version']
)
);
$html .= '">' . $structure . '</a>';
$html .= '</td>';
$html .= '</tr>';
if ($style == 'even') {
$style = 'odd';
} else {
$style = 'even';
}
}
$html .= '</tbody>';
$html .= '</table>';
$html .= PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"versionsForm"
);
$html .= PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_delete_version',
__('Delete version'), 'b_drop.png', 'delete_version'
);
$html .= '</form>';
if ($tracking_active) {
$html .= PMA_getHtmlForActivateDeactivateTracking(
'deactivate', $url_query, $last_version
);
} else {
$html .= PMA_getHtmlForActivateDeactivateTracking(
'activate', $url_query, $last_version
);
}
return $html;
}
/**
* Function to get the last version number of a table
*
* @param array $sql_result sql result
*
* @return int
*/
function PMA_getTableLastVersionNumber($sql_result)
{
$maxversion = $GLOBALS['dbi']->fetchArray($sql_result);
return intval($maxversion['version']);
}
/**
* Function to get sql results for selectable tables
*
* @return array
*/
function PMA_getSQLResultForSelectableTables()
{
include_once 'libraries/relation.lib.php';
$cfgRelation = PMA_getRelationsParam();
$sql_query = " SELECT DISTINCT db_name, table_name FROM " .
PMA\libraries\Util::backquote($cfgRelation['db']) . "." .
PMA\libraries\Util::backquote($cfgRelation['tracking']) .
" WHERE db_name = '" . $GLOBALS['dbi']->escapeString($GLOBALS['db']) .
"' " .
" ORDER BY db_name, table_name";
return PMA_queryAsControlUser($sql_query);
}
/**
* Function to get html for selectable table rows
*
* @param array $selectable_tables_sql_result sql results for selectable rows
* @param string $url_query url query
*
* @return string
*/
function PMA_getHtmlForSelectableTables($selectable_tables_sql_result, $url_query)
{
$html = '<form method="post" action="tbl_tracking.php' . $url_query . '">';
$html .= '<select name="table" class="autosubmit">';
while ($entries = $GLOBALS['dbi']->fetchArray($selectable_tables_sql_result)) {
if (Tracker::isTracked($entries['db_name'], $entries['table_name'])) {
$status = ' (' . __('active') . ')';
} else {
$status = ' (' . __('not active') . ')';
}
if ($entries['table_name'] == $_REQUEST['table']) {
$s = ' selected="selected"';
} else {
$s = '';
}
$html .= '<option value="' . htmlspecialchars($entries['table_name'])
. '"' . $s . '>' . htmlspecialchars($entries['db_name']) . ' . '
. htmlspecialchars($entries['table_name']) . $status . '</option>'
. "\n";
}
$html .= '</select>';
$html .= '<input type="hidden" name="show_versions_submit" value="1" />';
$html .= '</form>';
return $html;
}
/**
* Function to get html for tracking report and tracking report export
*
* @param string $url_query url query
* @param array $data data
* @param array $url_params url params
* @param boolean $selection_schema selection schema
* @param boolean $selection_data selection data
* @param boolean $selection_both selection both
* @param int $filter_ts_to filter time stamp from
* @param int $filter_ts_from filter time stamp tp
* @param array $filter_users filter users
*
* @return string
*/
function PMA_getHtmlForTrackingReport($url_query, $data, $url_params,
$selection_schema, $selection_data, $selection_both, $filter_ts_to,
$filter_ts_from, $filter_users
) {
$html = '<h3>' . __('Tracking report')
. ' [<a href="tbl_tracking.php' . $url_query . '">' . __('Close')
. '</a>]</h3>';
$html .= '<small>' . __('Tracking statements') . ' '
. htmlspecialchars($data['tracking']) . '</small><br/>';
$html .= '<br/>';
list($str1, $str2, $str3, $str4, $str5) = PMA_getHtmlForElementsOfTrackingReport(
$selection_schema, $selection_data, $selection_both
);
// Prepare delete link content here
$drop_image_or_text = '';
if (PMA\libraries\Util::showIcons('ActionLinksMode')) {
$drop_image_or_text .= PMA\libraries\Util::getImage(
'b_drop.png', __('Delete tracking data row from report')
);
}
if (PMA\libraries\Util::showText('ActionLinksMode')) {
$drop_image_or_text .= __('Delete');
}
/*
* First, list tracked data definition statements
*/
if (count($data['ddlog']) == 0 && count($data['dmlog']) == 0) {
$msg = Message::notice(__('No data'));
$msg->display();
}
$html .= PMA_getHtmlForTrackingReportExportForm1(
$data, $url_params, $selection_schema, $selection_data, $selection_both,
$filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3,
$str4, $str5, $drop_image_or_text
);
$html .= PMA_getHtmlForTrackingReportExportForm2(
$url_params, $str1, $str2, $str3, $str4, $str5
);
$html .= "<br/><br/><hr/><br/>\n";
return $html;
}
/**
* Generate HTML element for report form
*
* @param boolean $selection_schema selection schema
* @param boolean $selection_data selection data
* @param boolean $selection_both selection both
*
* @return array
*/
function PMA_getHtmlForElementsOfTrackingReport(
$selection_schema, $selection_data, $selection_both
) {
$str1 = '<select name="logtype">'
. '<option value="schema"'
. ($selection_schema ? ' selected="selected"' : '') . '>'
. __('Structure only') . '</option>'
. '<option value="data"'
. ($selection_data ? ' selected="selected"' : '') . '>'
. __('Data only') . '</option>'
. '<option value="schema_and_data"'
. ($selection_both ? ' selected="selected"' : '') . '>'
. __('Structure and data') . '</option>'
. '</select>';
$str2 = '<input type="text" name="date_from" value="'
. htmlspecialchars($_REQUEST['date_from']) . '" size="19" />';
$str3 = '<input type="text" name="date_to" value="'
. htmlspecialchars($_REQUEST['date_to']) . '" size="19" />';
$str4 = '<input type="text" name="users" value="'
. htmlspecialchars($_REQUEST['users']) . '" />';
$str5 = '<input type="hidden" name="list_report" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />';
return array($str1, $str2, $str3, $str4, $str5);
}
/**
* Generate HTML for export form
*
* @param array $data data
* @param array $url_params url params
* @param boolean $selection_schema selection schema
* @param boolean $selection_data selection data
* @param boolean $selection_both selection both
* @param int $filter_ts_to filter time stamp from
* @param int $filter_ts_from filter time stamp tp
* @param array $filter_users filter users
* @param string $str1 HTML for logtype select
* @param string $str2 HTML for "from date"
* @param string $str3 HTML for "to date"
* @param string $str4 HTML for user
* @param string $str5 HTML for "list report"
* @param string $drop_image_or_text HTML for image or text
*
* @return string HTML for form
*/
function PMA_getHtmlForTrackingReportExportForm1(
$data, $url_params, $selection_schema, $selection_data, $selection_both,
$filter_ts_to, $filter_ts_from, $filter_users, $str1, $str2, $str3,
$str4, $str5, $drop_image_or_text
) {
$ddlog_count = 0;
$html = '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array(
'report' => 'true', 'version' => $_REQUEST['version']
)
)
. '">';
$html .= sprintf(
__('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
$str1, $str2, $str3, $str4, $str5
);
if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
list($temp, $ddlog_count) = PMA_getHtmlForDataDefinitionStatements(
$data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
$drop_image_or_text
);
$html .= $temp;
unset($temp);
} //endif
/*
* Secondly, list tracked data manipulation statements
*/
if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
$html .= PMA_getHtmlForDataManipulationStatements(
$data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
$ddlog_count, $drop_image_or_text
);
}
$html .= '</form>';
return $html;
}
/**
* Generate HTML for export form
*
* @param array $url_params Parameters
* @param string $str1 HTML for logtype select
* @param string $str2 HTML for "from date"
* @param string $str3 HTML for "to date"
* @param string $str4 HTML for user
* @param string $str5 HTML for "list report"
*
* @return string HTML for form
*/
function PMA_getHtmlForTrackingReportExportForm2(
$url_params, $str1, $str2, $str3, $str4, $str5
) {
$html = '<form method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array(
'report' => 'true', 'version' => $_REQUEST['version']
)
)
. '">';
$html .= sprintf(
__('Show %1$s with dates from %2$s to %3$s by user %4$s %5$s'),
$str1, $str2, $str3, $str4, $str5
);
$html .= '</form>';
$html .= '<form class="disableAjax" method="post" action="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params
+ array('report' => 'true', 'version' => $_REQUEST['version'])
)
. '">';
$html .= '<input type="hidden" name="logtype" value="'
. htmlspecialchars($_REQUEST['logtype']) . '" />';
$html .= '<input type="hidden" name="date_from" value="'
. htmlspecialchars($_REQUEST['date_from']) . '" />';
$html .= '<input type="hidden" name="date_to" value="'
. htmlspecialchars($_REQUEST['date_to']) . '" />';
$html .= '<input type="hidden" name="users" value="'
. htmlspecialchars($_REQUEST['users']) . '" />';
$str_export1 = '<select name="export_type">'
. '<option value="sqldumpfile">' . __('SQL dump (file download)')
. '</option>'
. '<option value="sqldump">' . __('SQL dump') . '</option>'
. '<option value="execution" onclick="alert(\''
. PMA_escapeJsString(
__('This option will replace your table and contained data.')
)
. '\')">' . __('SQL execution') . '</option>' . '</select>';
$str_export2 = '<input type="hidden" name="report_export" value="1" />'
. '<input type="submit" value="' . __('Go') . '" />';
$html .= "<br/>" . sprintf(__('Export as %s'), $str_export1)
. $str_export2 . "<br/>";
$html .= '</form>';
return $html;
}
/**
* Function to get html for data manipulation statements
*
* @param array $data data
* @param array $filter_users filter users
* @param int $filter_ts_from filter time staml from
* @param int $filter_ts_to filter time stamp to
* @param array $url_params url parameters
* @param int $ddlog_count data definition log count
* @param string $drop_image_or_text drop image or text
*
* @return string
*/
function PMA_getHtmlForDataManipulationStatements($data, $filter_users,
$filter_ts_from, $filter_ts_to, $url_params, $ddlog_count,
$drop_image_or_text
) {
// no need for the secondth returned parameter
list($html,) = PMA_getHtmlForDataStatements(
$data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
$drop_image_or_text, 'dmlog', __('Data manipulation statement'),
$ddlog_count, 'dml_versions'
);
return $html;
}
/**
* Function to get html for one data manipulation statement
*
* @param array $entry entry
* @param array $filter_users filter users
* @param int $filter_ts_from filter time stamp from
* @param int $filter_ts_to filter time stamp to
* @param string $style style
* @param int $line_number line number
* @param array $url_params url parameters
* @param int $offset line number offset
* @param string $drop_image_or_text drop image or text
* @param string $delete_param parameter for delete
*
* @return string
*/
function PMA_getHtmlForOneStatement($entry, $filter_users,
$filter_ts_from, $filter_ts_to, $style, $line_number, $url_params, $offset,
$drop_image_or_text, $delete_param
) {
$statement = PMA\libraries\Util::formatSql($entry['statement'], true);
$timestamp = strtotime($entry['date']);
$filtered_user = in_array($entry['username'], $filter_users);
$html = null;
if ($timestamp >= $filter_ts_from
&& $timestamp <= $filter_ts_to
&& (in_array('*', $filter_users) || $filtered_user)
) {
$html = '<tr class="noclick ' . $style . '">';
$html .= '<td class="right"><small>' . $line_number . '</small></td>';
$html .= '<td><small>'
. htmlspecialchars($entry['date']) . '</small></td>';
$html .= '<td><small>'
. htmlspecialchars($entry['username']) . '</small></td>';
$html .= '<td>' . $statement . '</td>';
$html .= '<td class="nowrap"><a class="delete_entry_anchor ajax"'
. ' href="tbl_tracking.php'
. PMA_URL_getCommon(
$url_params + array(
'report' => 'true',
'version' => $_REQUEST['version'],
$delete_param => ($line_number - $offset),
)
)
. '">'
. $drop_image_or_text
. '</a></td>';
$html .= '</tr>';
}
return $html;
}
/**
* Function to get html for data definition statements in schema snapshot
*
* @param array $data data
* @param array $filter_users filter users
* @param int $filter_ts_from filter time stamp from
* @param int $filter_ts_to filter time stamp to
* @param array $url_params url parameters
* @param string $drop_image_or_text drop image or text
*
* @return array
*/
function PMA_getHtmlForDataDefinitionStatements($data, $filter_users,
$filter_ts_from, $filter_ts_to, $url_params, $drop_image_or_text
) {
list($html, $line_number) = PMA_getHtmlForDataStatements(
$data, $filter_users, $filter_ts_from, $filter_ts_to, $url_params,
$drop_image_or_text, 'ddlog', __('Data definition statement'),
1, 'ddl_versions'
);
return array($html, $line_number);
}
/**
* Function to get html for data statements in schema snapshot
*
* @param array $data data
* @param array $filter_users filter users
* @param int $filter_ts_from filter time stamp from
* @param int $filter_ts_to filter time stamp to
* @param array $url_params url parameters
* @param string $drop_image_or_text drop image or text
* @param string $which_log dmlog|ddlog
* @param string $header_message message for this section
* @param int $line_number line number
* @param string $table_id id for the table element
*
* @return array
*/
function PMA_getHtmlForDataStatements($data, $filter_users,
$filter_ts_from, $filter_ts_to, $url_params, $drop_image_or_text,
$which_log, $header_message, $line_number, $table_id
) {
$offset = $line_number;
$html = '<table id="' . $table_id . '" class="data" width="100%">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th width="18">#</th>';
$html .= '<th width="100">' . __('Date') . '</th>';
$html .= '<th width="60">' . __('Username') . '</th>';
$html .= '<th>' . $header_message . '</th>';
$html .= '<th>' . __('Action') . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$style = 'odd';
foreach ($data[$which_log] as $entry) {
$html .= PMA_getHtmlForOneStatement(
$entry, $filter_users, $filter_ts_from, $filter_ts_to, $style,
$line_number, $url_params, $offset, $drop_image_or_text,
'delete_' . $which_log
);
if ($style == 'even') {
$style = 'odd';
} else {
$style = 'even';
}
$line_number++;
}
$html .= '</tbody>';
$html .= '</table>';
return array($html, $line_number);
}
/**
* Function to get html for schema snapshot
*
* @param string $url_query url query
*
* @return string
*/
function PMA_getHtmlForSchemaSnapshot($url_query)
{
$html = '<h3>' . __('Structure snapshot')
. ' [<a href="tbl_tracking.php' . $url_query . '">' . __('Close')
. '</a>]</h3>';
$data = Tracker::getTrackedData(
$_REQUEST['db'], $_REQUEST['table'], $_REQUEST['version']
);
// Get first DROP TABLE/VIEW and CREATE TABLE/VIEW statements
$drop_create_statements = $data['ddlog'][0]['statement'];
if (mb_strstr($data['ddlog'][0]['statement'], 'DROP TABLE')
|| mb_strstr($data['ddlog'][0]['statement'], 'DROP VIEW')
) {
$drop_create_statements .= $data['ddlog'][1]['statement'];
}
// Print SQL code
$html .= PMA\libraries\Util::getMessage(
sprintf(
__('Version %s snapshot (SQL code)'),
htmlspecialchars($_REQUEST['version'])
),
$drop_create_statements
);
// Unserialize snapshot
$temp = PMA_safeUnserialize($data['schema_snapshot']);
if ($temp === null) {
$temp = array('COLUMNS' => array(), 'INDEXES' => array());
}
$columns = $temp['COLUMNS'];
$indexes = $temp['INDEXES'];
$html .= PMA_getHtmlForColumns($columns);
if (count($indexes) > 0) {
$html .= PMA_getHtmlForIndexes($indexes);
} // endif
$html .= '<br /><hr /><br />';
return $html;
}
/**
* Function to get html for displaying columns in the schema snapshot
*
* @param array $columns columns
*
* @return string
*/
function PMA_getHtmlForColumns($columns)
{
$html = '<h3>' . __('Structure') . '</h3>';
$html .= '<table id="tablestructure" class="data">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>' . __('#') . '</th>';
$html .= '<th>' . __('Column') . '</th>';
$html .= '<th>' . __('Type') . '</th>';
$html .= '<th>' . __('Collation') . '</th>';
$html .= '<th>' . __('Null') . '</th>';
$html .= '<th>' . __('Default') . '</th>';
$html .= '<th>' . __('Extra') . '</th>';
$html .= '<th>' . __('Comment') . '</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$style = 'odd';
$index = 1;
foreach ($columns as $field) {
$html .= PMA_getHtmlForField($index++, $field, $style);
if ($style == 'even') {
$style = 'odd';
} else {
$style = 'even';
}
}
$html .= '</tbody>';
$html .= '</table>';
return $html;
}
/**
* Function to get html for field
*
* @param int $index index
* @param array $field field
* @param string $style style
*
* @return string
*/
function PMA_getHtmlForField($index, $field, $style)
{
$html = '<tr class="noclick ' . $style . '">';
$html .= '<td>' . $index . '</td>';
$html .= '<td><b>' . htmlspecialchars($field['Field']);
if ($field['Key'] == 'PRI') {
$html .= ' ' . PMA\libraries\Util::getImage(
'b_primary.png', __('Primary')
);
} elseif (! empty($field['Key'])) {
$html .= ' ' . PMA\libraries\Util::getImage(
'bd_primary.png', __('Index')
);
}
$html .= '</b></td>';
$html .= "\n";
$html .= '<td>' . htmlspecialchars($field['Type']) . '</td>';
$html .= '<td>' . htmlspecialchars($field['Collation']) . '</td>';
$html .= '<td>' . (($field['Null'] == 'YES') ? __('Yes') : __('No')) . '</td>';
$html .= '<td>';
if (isset($field['Default'])) {
$extracted_columnspec = PMA\libraries\Util::extractColumnSpec(
$field['Type']
);
if ($extracted_columnspec['type'] == 'bit') {
// here, $field['Default'] contains something like b'010'
$html .= PMA\libraries\Util::convertBitDefaultValue($field['Default']);
} else {
$html .= htmlspecialchars($field['Default']);
}
} else {
if ($field['Null'] == 'YES') {
$html .= '<i>NULL</i>';
} else {
$html .= '<i>' . _pgettext('None for default', 'None') . '</i>';
}
}
$html .= '</td>';
$html .= '<td>' . htmlspecialchars($field['Extra']) . '</td>';
$html .= '<td>' . htmlspecialchars($field['Comment']) . '</td>';
$html .= '</tr>';
return $html;
}
/**
* Function to get html for the indexes in schema snapshot
*
* @param array $indexes indexes
*
* @return string
*/
function PMA_getHtmlForIndexes($indexes)
{
$html = '<h3>' . __('Indexes') . '</h3>';
$html .= '<table id="tablestructure_indexes" class="data">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>' . __('Keyname') . '</th>';
$html .= '<th>' . __('Type') . '</th>';
$html .= '<th>' . __('Unique') . '</th>';
$html .= '<th>' . __('Packed') . '</th>';
$html .= '<th>' . __('Column') . '</th>';
$html .= '<th>' . __('Cardinality') . '</th>';
$html .= '<th>' . __('Collation') . '</th>';
$html .= '<th>' . __('Null') . '</th>';
$html .= '<th>' . __('Comment') . '</th>';
$html .= '</tr>';
$html .= '<tbody>';
$style = 'odd';
foreach ($indexes as $index) {
$html .= PMA_getHtmlForIndex($index, $style);
if ($style == 'even') {
$style = 'odd';
} else {
$style = 'even';
}
}
$html .= '</tbody>';
$html .= '</table>';
return $html;
}
/**
* Function to get html for an index in schema snapshot
*
* @param array $index index
* @param string $style style
*
* @return string
*/
function PMA_getHtmlForIndex($index, $style)
{
if ($index['Non_unique'] == 0) {
$str_unique = __('Yes');
} else {
$str_unique = __('No');
}
if ($index['Packed'] != '') {
$str_packed = __('Yes');
} else {
$str_packed = __('No');
}
$html = '<tr class="noclick ' . $style . '">';
$html .= '<td><b>' . htmlspecialchars($index['Key_name']) . '</b></td>';
$html .= '<td>' . htmlspecialchars($index['Index_type']) . '</td>';
$html .= '<td>' . $str_unique . '</td>';
$html .= '<td>' . $str_packed . '</td>';
$html .= '<td>' . htmlspecialchars($index['Column_name']) . '</td>';
$html .= '<td>' . htmlspecialchars($index['Cardinality']) . '</td>';
$html .= '<td>' . htmlspecialchars($index['Collation']) . '</td>';
$html .= '<td>' . htmlspecialchars($index['Null']) . '</td>';
$html .= '<td>' . htmlspecialchars($index['Comment']) . '</td>';
$html .= '</tr>';
return $html;
}
/**
* Function to handle the tracking report
*
* @param array &$data tracked data
*
* @return string HTML for the message
*/
function PMA_deleteTrackingReportRows(&$data)
{
$html = '';
if (isset($_REQUEST['delete_ddlog'])) {
// Delete ddlog row data
$html .= PMA_deleteFromTrackingReportLog(
$data,
'ddlog',
'DDL',
__('Tracking data definition successfully deleted')
);
}
if (isset($_REQUEST['delete_dmlog'])) {
// Delete dmlog row data
$html .= PMA_deleteFromTrackingReportLog(
$data,
'dmlog',
'DML',
__('Tracking data manipulation successfully deleted')
);
}
return $html;
}
/**
* Function to delete from a tracking report log
*
* @param array &$data tracked data
* @param string $which_log ddlog|dmlog
* @param string $type DDL|DML
* @param string $message success message
*
* @return string HTML for the message
*/
function PMA_deleteFromTrackingReportLog(&$data, $which_log, $type, $message)
{
$html = '';
$delete_id = $_REQUEST['delete_' . $which_log];
// Only in case of valid id
if ($delete_id == (int)$delete_id) {
unset($data[$which_log][$delete_id]);
$successfullyDeleted = Tracker::changeTrackingData(
$_REQUEST['db'],
$_REQUEST['table'],
$_REQUEST['version'],
$type,
$data[$which_log]
);
if ($successfullyDeleted) {
$msg = Message::success($message);
} else {
$msg = Message::rawError(__('Query error'));
}
$html .= $msg->getDisplay();
}
return $html;
}
/**
* Function to export as sql dump
*
* @param array $entries entries
*
* @return string HTML SQL query form
*/
function PMA_exportAsSQLDump($entries)
{
$html = '';
$new_query = "# "
. __(
'You can execute the dump by creating and using a temporary database. '
. 'Please ensure that you have the privileges to do so.'
)
. "\n"
. "# " . __('Comment out these two lines if you do not need them.') . "\n"
. "\n"
. "CREATE database IF NOT EXISTS pma_temp_db; \n"
. "USE pma_temp_db; \n"
. "\n";
foreach ($entries as $entry) {
$new_query .= $entry['statement'];
}
$msg = Message::success(
__('SQL statements exported. Please copy the dump or execute it.')
);
$html .= $msg->getDisplay();
$db_temp = $GLOBALS['db'];
$table_temp = $GLOBALS['table'];
$GLOBALS['db'] = $GLOBALS['table'] = '';
include_once './libraries/sql_query_form.lib.php';
$html .= PMA_getHtmlForSqlQueryForm($new_query, 'sql');
$GLOBALS['db'] = $db_temp;
$GLOBALS['table'] = $table_temp;
return $html;
}
/**
* Function to export as sql execution
*
* @param array $entries entries
*
* @return array
*/
function PMA_exportAsSQLExecution($entries)
{
$sql_result = array();
foreach ($entries as $entry) {
$sql_result = $GLOBALS['dbi']->query("/*NOTRACK*/\n" . $entry['statement']);
}
return $sql_result;
}
/**
* Function to export as entries
*
* @param array $entries entries
*
* @return void
*/
function PMA_exportAsFileDownload($entries)
{
@ini_set('url_rewriter.tags', '');
// Replace all multiple whitespaces by a single space
$table = htmlspecialchars(preg_replace('/\s+/', ' ', $_REQUEST['table']));
$dump = "# " . sprintf(
__('Tracking report for table `%s`'), $table
)
. "\n" . "# " . date('Y-m-d H:i:s') . "\n";
foreach ($entries as $entry) {
$dump .= $entry['statement'];
}
$filename = 'log_' . $table . '.sql';
PMA\libraries\Response::getInstance()->disable();
PMA_downloadHeader(
$filename,
'text/x-sql',
strlen($dump)
);
echo $dump;
exit();
}
/**
* Function to activate or deactivate tracking
*
* @param string $action activate|deactivate
*
* @return string HTML for the success message
*/
function PMA_changeTracking($action)
{
$html = '';
if ($action == 'activate') {
$method = 'activateTracking';
$message = __('Tracking for %1$s was activated at version %2$s.');
} else {
$method = 'deactivateTracking';
$message = __('Tracking for %1$s was deactivated at version %2$s.');
}
$status = Tracker::$method(
$GLOBALS['db'], $GLOBALS['table'], $_REQUEST['version']
);
if ($status) {
$msg = Message::success(
sprintf(
$message,
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table']),
htmlspecialchars($_REQUEST['version'])
)
);
$html .= $msg->getDisplay();
}
return $html;
}
/**
* Function to get tracking set
*
* @return string
*/
function PMA_getTrackingSet()
{
$tracking_set = '';
// a key is absent from the request if it has been removed from
// tracking_default_statements in the config
if (isset($_REQUEST['alter_table']) && $_REQUEST['alter_table'] == true) {
$tracking_set .= 'ALTER TABLE,';
}
if (isset($_REQUEST['rename_table']) && $_REQUEST['rename_table'] == true) {
$tracking_set .= 'RENAME TABLE,';
}
if (isset($_REQUEST['create_table']) && $_REQUEST['create_table'] == true) {
$tracking_set .= 'CREATE TABLE,';
}
if (isset($_REQUEST['drop_table']) && $_REQUEST['drop_table'] == true) {
$tracking_set .= 'DROP TABLE,';
}
if (isset($_REQUEST['alter_view']) && $_REQUEST['alter_view'] == true) {
$tracking_set .= 'ALTER VIEW,';
}
if (isset($_REQUEST['create_view']) && $_REQUEST['create_view'] == true) {
$tracking_set .= 'CREATE VIEW,';
}
if (isset($_REQUEST['drop_view']) && $_REQUEST['drop_view'] == true) {
$tracking_set .= 'DROP VIEW,';
}
if (isset($_REQUEST['create_index']) && $_REQUEST['create_index'] == true) {
$tracking_set .= 'CREATE INDEX,';
}
if (isset($_REQUEST['drop_index']) && $_REQUEST['drop_index'] == true) {
$tracking_set .= 'DROP INDEX,';
}
if (isset($_REQUEST['insert']) && $_REQUEST['insert'] == true) {
$tracking_set .= 'INSERT,';
}
if (isset($_REQUEST['update']) && $_REQUEST['update'] == true) {
$tracking_set .= 'UPDATE,';
}
if (isset($_REQUEST['delete']) && $_REQUEST['delete'] == true) {
$tracking_set .= 'DELETE,';
}
if (isset($_REQUEST['truncate']) && $_REQUEST['truncate'] == true) {
$tracking_set .= 'TRUNCATE,';
}
$tracking_set = rtrim($tracking_set, ',');
return $tracking_set;
}
/**
* Deletes a tracking version
*
* @param string $version tracking version
*
* @return string HTML of the success message
*/
function PMA_deleteTrackingVersion($version)
{
$html = '';
$versionDeleted = Tracker::deleteTracking(
$GLOBALS['db'],
$GLOBALS['table'],
$version
);
if ($versionDeleted) {
$msg = Message::success(
sprintf(
__('Version %1$s of %2$s was deleted.'),
htmlspecialchars($version),
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
)
);
$html .= $msg->getDisplay();
}
return $html;
}
/**
* Function to create the tracking version
*
* @return string HTML of the success message
*/
function PMA_createTrackingVersion()
{
$html = '';
$tracking_set = PMA_getTrackingSet();
$versionCreated = Tracker::createVersion(
$GLOBALS['db'],
$GLOBALS['table'],
$_REQUEST['version'],
$tracking_set,
$GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])->isView()
);
if ($versionCreated) {
$msg = Message::success(
sprintf(
__('Version %1$s was created, tracking for %2$s is active.'),
htmlspecialchars($_REQUEST['version']),
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
)
);
$html .= $msg->getDisplay();
}
return $html;
}
/**
* Create tracking version for multiple tables
*
* @param array $selected list of selected tables
*
* @return void
*/
function PMA_createTrackingForMultipleTables($selected)
{
$tracking_set = PMA_getTrackingSet();
foreach ($selected as $selected_table) {
Tracker::createVersion(
$GLOBALS['db'],
$selected_table,
$_REQUEST['version'],
$tracking_set,
$GLOBALS['dbi']->getTable($GLOBALS['db'], $selected_table)->isView()
);
}
}
/**
* Function to get the entries
*
* @param array $data data
* @param int $filter_ts_from filter time stamp from
* @param int $filter_ts_to filter time stamp to
* @param array $filter_users filter users
*
* @return array
*/
function PMA_getEntries($data, $filter_ts_from, $filter_ts_to, $filter_users)
{
$entries = array();
// Filtering data definition statements
if ($_REQUEST['logtype'] == 'schema'
|| $_REQUEST['logtype'] == 'schema_and_data'
) {
$entries = array_merge(
$entries,
PMA_filterTracking(
$data['ddlog'], $filter_ts_from, $filter_ts_to, $filter_users
)
);
}
// Filtering data manipulation statements
if ($_REQUEST['logtype'] == 'data'
|| $_REQUEST['logtype'] == 'schema_and_data'
) {
$entries = array_merge(
$entries,
PMA_filterTracking(
$data['dmlog'], $filter_ts_from, $filter_ts_to, $filter_users
)
);
}
// Sort it
$ids = $timestamps = $usernames = $statements = array();
foreach ($entries as $key => $row) {
$ids[$key] = $row['id'];
$timestamps[$key] = $row['timestamp'];
$usernames[$key] = $row['username'];
$statements[$key] = $row['statement'];
}
array_multisort(
$timestamps, SORT_ASC, $ids, SORT_ASC, $usernames,
SORT_ASC, $statements, SORT_ASC, $entries
);
return $entries;
}
/**
* Function to get version status
*
* @param array $version version info
*
* @return string $version_status The status message
*/
function PMA_getVersionStatus($version)
{
if ($version['tracking_active'] == 1) {
return __('active');
} else {
return __('not active');
}
}
/**
* Display untracked tables
*
* @param string $db current database
* @param array $untracked_tables untracked tables
* @param string $url_query url query string
* @param string $pmaThemeImage path to theme's image folder
* @param string $text_dir text direction
*
* @return void
*/
function PMA_displayUntrackedTables(
$db, $untracked_tables, $url_query, $pmaThemeImage, $text_dir
) {
?>
<h3><?php echo __('Untracked tables');?></h3>
<form method="post" action="db_tracking.php" name="untrackedForm"
id="untrackedForm" class="ajax">
<?php
echo PMA_URL_getHiddenInputs($db)
?>
<table id="noversions" class="data">
<thead>
<tr>
<th></th>
<th style="width: 300px"><?php echo __('Table');?></th>
<th><?php echo __('Action');?></th>
</tr>
</thead>
<tbody>
<?php
// Print out list of untracked tables
$style = 'odd';
foreach ($untracked_tables as $key => $tablename) {
$style = PMA_displayOneUntrackedTable($db, $tablename, $url_query, $style);
}
?>
</tbody>
</table>
<?php
echo PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"untrackedForm"
);
echo PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_track',
__('Track table'), 'eye.png', 'track'
);
?>
</form>
<?php
}
/**
* Display one untracked table
*
* @param string $db current database
* @param string $tablename the table name for which to display a line
* @param string $url_query url query string
* @param string $style odd|even
*
* @return string $style changed style (even|odd)
*/
function PMA_displayOneUntrackedTable($db, $tablename, $url_query, $style)
{
$checkbox_id = "selected_tbl_"
. htmlspecialchars($tablename);
if (Tracker::getVersion($db, $tablename) == -1) {
$my_link = '<a href="tbl_tracking.php' . $url_query
. '&table=' . htmlspecialchars($tablename) . '">';
$my_link .= PMA\libraries\Util::getIcon('eye.png', __('Track table'));
$my_link .= '</a>';
?>
<tr class="<?php echo $style;?>">
<td class="center">
<input type="checkbox" name="selected_tbl[]"
class="checkall" id="<?php echo $checkbox_id;?>"
value="<?php echo htmlspecialchars($tablename);?>"/>
</td>
<th>
<label for="<?php echo $checkbox_id;?>">
<?php echo htmlspecialchars($tablename);?>
</label>
</th>
<td><?php echo $my_link;?></td>
</tr>
<?php
if ($style == 'even') {
$style = 'odd';
} else {
$style = 'even';
}
}
return $style;
}
/**
* Get untracked tables
*
* @param string $db current database
*
* @return array $untracked_tables
*/
function PMA_getUntrackedTables($db)
{
$untracked_tables = array();
$sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
// Get list of tables
$table_list = PMA\libraries\Util::getTableList($db);
// For each table try to get the tracking version
foreach ($table_list as $key => $value) {
// If $value is a table group.
if (array_key_exists(('is' . $sep . 'group'), $value)
&& $value['is' . $sep . 'group']
) {
foreach ($value as $temp_table) {
// If $temp_table is a table with the value for 'Name' is set,
// rather than a property of the table group.
if (is_array($temp_table)
&& array_key_exists('Name', $temp_table)
) {
$tracking_version = Tracker::getVersion(
$db,
$temp_table['Name']
);
if ($tracking_version == -1) {
$untracked_tables[] = $temp_table['Name'];
}
}
}
} else { // If $value is a table.
if (Tracker::getVersion($db, $value['Name']) == -1) {
$untracked_tables[] = $value['Name'];
}
}
}
return $untracked_tables;
}
/**
* Display tracked tables
*
* @param string $db current database
* @param object $all_tables_result result set of tracked tables
* @param string $url_query url query string
* @param string $pmaThemeImage path to theme's image folder
* @param string $text_dir text direction
* @param array $cfgRelation configuration storage info
*
* @return void
*/
function PMA_displayTrackedTables(
$db, $all_tables_result, $url_query, $pmaThemeImage, $text_dir, $cfgRelation
) {
?>
<div id="tracked_tables">
<h3><?php echo __('Tracked tables');?></h3>
<form method="post" action="db_tracking.php" name="trackedForm"
id="trackedForm" class="ajax">
<?php
echo PMA_URL_getHiddenInputs($db)
?>
<table id="versions" class="data">
<thead>
<tr>
<th></th>
<th><?php echo __('Table');?></th>
<th><?php echo __('Last version');?></th>
<th><?php echo __('Created');?></th>
<th><?php echo __('Updated');?></th>
<th><?php echo __('Status');?></th>
<th><?php echo __('Action');?></th>
<th><?php echo __('Show');?></th>
</tr>
</thead>
<tbody>
<?php
// Print out information about versions
$delete = PMA\libraries\Util::getIcon('b_drop.png', __('Delete tracking'));
$versions = PMA\libraries\Util::getIcon('b_versions.png', __('Versions'));
$report = PMA\libraries\Util::getIcon('b_report.png', __('Tracking report'));
$structure = PMA\libraries\Util::getIcon(
'b_props.png',
__('Structure snapshot')
);
$style = 'odd';
while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
list($table_name, $version_number) = $one_result;
$table_query = ' SELECT * FROM ' .
PMA\libraries\Util::backquote($cfgRelation['db']) . '.' .
PMA\libraries\Util::backquote($cfgRelation['tracking']) .
' WHERE `db_name` = \''
. $GLOBALS['dbi']->escapeString($_REQUEST['db'])
. '\' AND `table_name` = \''
. $GLOBALS['dbi']->escapeString($table_name)
. '\' AND `version` = \'' . $version_number . '\'';
$table_result = PMA_queryAsControlUser($table_query);
$version_data = $GLOBALS['dbi']->fetchArray($table_result);
$tbl_link = 'tbl_tracking.php' . $url_query . '&table='
. htmlspecialchars($version_data['table_name']);
$delete_link = 'db_tracking.php' . $url_query . '&table='
. htmlspecialchars($version_data['table_name'])
. '&delete_tracking=true&';
$checkbox_id = "selected_tbl_"
. htmlspecialchars($version_data['table_name']);
?>
<tr class="<?php echo $style;?>">
<td class="center">
<input type="checkbox" name="selected_tbl[]"
class="checkall" id="<?php echo $checkbox_id;?>"
value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
</td>
<th>
<label for="<?php echo $checkbox_id;?>">
<?php echo htmlspecialchars($version_data['table_name']);?>
</label>
</th>
<td class="right"><?php echo $version_data['version'];?></td>
<td><?php echo $version_data['date_created'];?></td>
<td><?php echo $version_data['date_updated'];?></td>
<td>
<?php
PMA_displayStatusButton($version_data, $tbl_link);
?>
</td>
<td>
<a class="delete_tracking_anchor ajax"
href="<?php echo $delete_link;?>" >
<?php echo $delete; ?></a>
<?php
echo '</td>'
, '<td>'
, '<a href="' , $tbl_link , '">' , $versions , '</a>'
, ' '
, '<a href="' , $tbl_link , '&report=true&version='
, $version_data['version'] , '">' , $report , '</a>'
, ' '
, '<a href="' . $tbl_link , '&snapshot=true&version='
, $version_data['version'] , '">' , $structure , '</a>'
, '</td>'
, '</tr>';
if ($style == 'even') {
$style = 'odd';
} else {
$style = 'even';
}
}
?>
</tbody>
</table>
<?php
echo PMA\libraries\Util::getWithSelected(
$pmaThemeImage,
$text_dir,
"trackedForm"
);
echo PMA\libraries\Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_delete_tracking',
__('Delete tracking'), 'b_drop.png', 'delete_tracking'
);
?>
</form>
</div>
<?php
}
/**
* Display tracking status button
*
* @param array $version_data data about tracking versions
* @param string $tbl_link link for tbl_tracking.php
*
* @return void
*/
function PMA_displayStatusButton($version_data, $tbl_link)
{
$state = PMA_getVersionStatus($version_data);
$options = array(
0 => array(
'label' => __('not active'),
'value' => 'deactivate_now',
'selected' => ($state != 'active')
),
1 => array(
'label' => __('active'),
'value' => 'activate_now',
'selected' => ($state == 'active')
)
);
echo PMA\libraries\Util::toggleButton(
$tbl_link . '&version=' . $version_data['version'],
'toggle_activation',
$options,
null
);
}
|