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 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* set of functions for structure section in pma
*
* @package PhpMyAdmin
*/
if (!defined('PHPMYADMIN')) {
exit;
}
/**
* Get the HTML links for action links
* Actions are, Browse, Search, Browse table label, empty table
*
* @param array $current_table current table
* @param boolean $table_is_view Is table view or not
* @param string $tbl_url_query table url query
* @param array $titles titles and icons for action links
* @param string $truename table name
* @param boolean $db_is_system_schema is database information schema or not
* @param string $url_query url query
*
* @return array ($browse_table, $search_table, $browse_table_label, $empty_table,
* $tracking_icon)
*/
function PMA_getHtmlForActionLinks($current_table, $table_is_view, $tbl_url_query,
$titles, $truename, $db_is_system_schema, $url_query
) {
$empty_table = '';
if ($current_table['TABLE_ROWS'] > 0 || $table_is_view) {
$may_have_rows = true;
} else {
$may_have_rows = false;
}
$browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">';
if ($may_have_rows) {
$browse_table .= $titles['Browse'];
} else {
$browse_table .= $titles['NoBrowse'];
}
$browse_table .= '</a>';
$search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">';
if ($may_have_rows) {
$search_table .= $titles['Search'];
} else {
$search_table .= $titles['NoSearch'];
}
$search_table .= '</a>';
$browse_table_label = '<a href="sql.php?' . $tbl_url_query
. '&pos=0" title="'
. htmlspecialchars($current_table['TABLE_COMMENT']) . '">'
. $truename . '</a>';
if (!$db_is_system_schema) {
$empty_table = '<a class="truncate_table_anchor ajax"';
$empty_table .= ' href="sql.php?' . $tbl_url_query
. '&sql_query=';
$empty_table .= urlencode(
'TRUNCATE ' . PMA_Util::backquote($current_table['TABLE_NAME'])
);
$empty_table .= '&message_to_show='
. urlencode(
sprintf(
__('Table %s has been emptied.'),
htmlspecialchars($current_table['TABLE_NAME'])
)
)
. '">';
if ($may_have_rows) {
$empty_table .= $titles['Empty'];
} else {
$empty_table .= $titles['NoEmpty'];
}
$empty_table .= '</a>';
// truncating views doesn't work
if ($table_is_view) {
$empty_table = ' ';
}
}
$tracking_icon = '';
if (PMA_Tracker::isActive()) {
if (PMA_Tracker::isTracked($GLOBALS["db"], $truename)) {
$tracking_icon = '<a href="tbl_tracking.php?' . $url_query
. '&table=' . $truename . '">'
. PMA_Util::getImage(
'eye.png', __('Tracking is active.')
)
. '</a>';
} elseif (PMA_Tracker::getVersion($GLOBALS["db"], $truename) > 0) {
$tracking_icon = '<a href="tbl_tracking.php?' . $url_query
. '&table=' . $truename . '">'
. PMA_Util::getImage(
'eye_grey.png', __('Tracking is not active.')
)
. '</a>';
}
}
return array($browse_table,
$search_table,
$browse_table_label,
$empty_table,
$tracking_icon
);
}
/**
* Get table drop query and drop message
*
* @param boolean $table_is_view Is table view or not
* @param string $current_table current table
*
* @return array ($drop_query, $drop_message)
*/
function PMA_getTableDropQueryAndMessage($table_is_view, $current_table)
{
$drop_query = 'DROP '
. (($table_is_view || $current_table['ENGINE'] == null) ? 'VIEW' : 'TABLE')
. ' ' . PMA_Util::backquote(
$current_table['TABLE_NAME']
);
$drop_message = sprintf(
(($table_is_view || $current_table['ENGINE'] == null)
? __('View %s has been dropped.')
: __('Table %s has been dropped.')),
str_replace(
' ',
' ',
htmlspecialchars($current_table['TABLE_NAME'])
)
);
return array($drop_query, $drop_message);
}
/**
* Get HTML body for table summery
*
* @param integer $num_tables number of tables
* @param boolean $server_slave_status server slave state
* @param boolean $db_is_system_schema whether database is information schema or not
* @param integer $sum_entries sum entries
* @param string $db_collation collation of given db
* @param boolean $is_show_stats whether stats is show or not
* @param double $sum_size sum size
* @param double $overhead_size overhead size
* @param string $create_time_all create time
* @param string $update_time_all update time
* @param string $check_time_all check time
* @param integer $sum_row_count_pre sum row count pre
*
* @return string $html_output
*/
function PMA_getHtmlBodyForTableSummary($num_tables, $server_slave_status,
$db_is_system_schema, $sum_entries, $db_collation, $is_show_stats,
$sum_size, $overhead_size, $create_time_all, $update_time_all,
$check_time_all, $sum_row_count_pre
) {
if ($is_show_stats) {
list($sum_formatted, $unit) = PMA_Util::formatByteDown(
$sum_size, 3, 1
);
list($overhead_formatted, $overhead_unit)
= PMA_Util::formatByteDown($overhead_size, 3, 1);
}
$html_output = '<tbody id="tbl_summary_row">'
. '<tr><th></th>';
$html_output .= '<th class="tbl_num nowrap">';
$html_output .= sprintf(
_ngettext('%s table', '%s tables', $num_tables),
PMA_Util::formatNumber($num_tables, 0)
);
$html_output .= '</th>';
if ($server_slave_status) {
$html_output .= '<th>' . __('Replication') . '</th>' . "\n";
}
$html_output .= '<th colspan="' . ($db_is_system_schema ? 4 : 7) . '">'
. __('Sum')
. '</th>';
$html_output .= '<th class="value tbl_rows">'
. $sum_row_count_pre . PMA_Util::formatNumber($sum_entries, 0)
. '</th>';
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
$default_engine = $GLOBALS['dbi']->fetchValue(
'SHOW VARIABLES LIKE \'storage_engine\';',
0,
1
);
$html_output .= '<th class="center">' . "\n"
. '<dfn title="'
. sprintf(
__('%s is the default storage engine on this MySQL server.'),
$default_engine
)
. '">' . $default_engine . '</dfn></th>' . "\n";
// we got a case where $db_collation was empty
$html_output .= '<th>' . "\n";
if (! empty($db_collation)) {
$html_output .= '<dfn title="'
. PMA_getCollationDescr($db_collation)
. ' (' . __('Default') . ')">'
. $db_collation
. '</dfn>';
}
$html_output .= '</th>';
}
if ($is_show_stats) {
$html_output .= '<th class="value tbl_size">'
. $sum_formatted . ' ' . $unit
. '</th>';
$html_output .= '<th class="value tbl_overhead">'
. $overhead_formatted . ' ' . $overhead_unit
. '</th>';
}
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
$html_output .= '<th class="value tbl_creation">' . "\n"
. ' '
. ($create_time_all
? PMA_Util::localisedDate(strtotime($create_time_all))
: '-'
)
. '</th>';
}
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
$html_output .= '<th class="value tbl_last_update">' . "\n"
. ' '
. ($update_time_all
? PMA_Util::localisedDate(strtotime($update_time_all))
: '-'
)
. '</th>';
}
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
$html_output .= '<th class="value tbl_last_check">' . "\n"
. ' '
. ($check_time_all
? PMA_Util::localisedDate(strtotime($check_time_all))
: '-'
)
. '</th>';
}
$html_output .= '</tr>'
. '</tbody>';
return $html_output;
}
/**
* Get HTML for "check all" check box with "with selected" dropdown
*
* @param string $pmaThemeImage pma theme image url
* @param string $text_dir url for text directory
* @param string $overhead_check overhead check
* @param boolean $db_is_system_schema whether database is information schema or not
* @param array $hidden_fields hidden fields
*
* @return string $html_output
*/
function PMA_getHtmlForCheckAllTables($pmaThemeImage, $text_dir,
$overhead_check, $db_is_system_schema, $hidden_fields
) {
$html_output = '<div class="clearfloat">';
$html_output .= '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
$html_output .= '<input type="checkbox" id="tablesForm_checkall" '
. 'class="checkall_box" title="' . __('Check All') . '" />';
$html_output .= '<label for="tablesForm_checkall">' . __('Check All')
. '</label>';
if ($overhead_check != '') {
$html_output .= PMA_getHtmlForCheckTablesHavingOverheadlink(
$overhead_check
);
}
$html_output .= '<select name="submit_mult" class="autosubmit" '
. 'style="margin: 0 3em 0 3em;">';
$html_output .= '<option value="' . __('With selected:')
. '" selected="selected">'
. __('With selected:') . '</option>' . "\n";
$html_output .= '<option value="export" >'
. __('Export') . '</option>' . "\n";
$html_output .= '<option value="print" >'
. __('Print view') . '</option>' . "\n";
if (!$db_is_system_schema
&& !$GLOBALS['cfg']['DisableMultiTableMaintenance']
) {
$html_output .= '<option value="empty_tbl" >'
. __('Empty') . '</option>' . "\n";
$html_output .= '<option value="drop_tbl" >'
. __('Drop') . '</option>' . "\n";
$html_output .= '<option value="check_tbl" >'
. __('Check table') . '</option>' . "\n";
if (!PMA_DRIZZLE) {
$html_output .= '<option value="optimize_tbl" >'
. __('Optimize table') . '</option>' . "\n";
$html_output .= '<option value="repair_tbl" >'
. __('Repair table') . '</option>' . "\n";
}
$html_output .= '<option value="analyze_tbl" >'
. __('Analyze table') . '</option>' . "\n";
$html_output .= '<option value="add_prefix_tbl" >'
. __('Add prefix to table') . '</option>' . "\n";
$html_output .= '<option value="replace_prefix_tbl" >'
. __('Replace table prefix') . '</option>' . "\n";
$html_output .= '<option value="copy_tbl_change_prefix" >'
. __('Copy table with prefix') . '</option>' . "\n";
}
$html_output .= '</select>'
. implode("\n", $hidden_fields) . "\n";
$html_output .= '</div>';
return $html_output;
}
/**
* Get HTML code for "Check tables having overhead" link
*
* @param string $overhead_check overhead check
*
* @return string $html_output
*/
function PMA_getHtmlForCheckTablesHavingOverheadlink($overhead_check)
{
return ' / '
. '<a href="#" onclick="unMarkAllRows(\'tablesForm\');'
. $overhead_check . 'return false;">'
. __('Check tables having overhead')
. '</a>';
}
/**
* Get HTML links for "Print view" options
*
* @param string $url_query url query
*
* @return string $html_output
*/
function PMA_getHtmlForTablePrintViewLink($url_query)
{
return '<p>'
. '<a href="db_printview.php?' . $url_query . '" target="print_view">'
. PMA_Util::getIcon(
'b_print.png',
__('Print view'),
true
) . '</a>';
}
/**
* Get HTML links "Data Dictionary" options
*
* @param string $url_query url query
*
* @return string $html_output
*/
function PMA_getHtmlForDataDictionaryLink($url_query)
{
return '<a href="db_datadict.php?' . $url_query . '" target="print_view">'
. PMA_Util::getIcon(
'b_tblanalyse.png',
__('Data Dictionary'),
true
) . '</a>'
. '</p>';
}
/**
* Get Time for Create time, update time and check time
*
* @param array $current_table current table
* @param string $time_label Create_time, Update_time, Check_time
* @param integer $time_all time
*
* @return array ($time, $time_all)
*/
function PMA_getTimeForCreateUpdateCheck($current_table, $time_label, $time_all)
{
$showtable = PMA_Table::sGetStatusInfo(
$GLOBALS['db'],
$current_table['TABLE_NAME'],
null,
true
);
$time = isset($showtable[$time_label])
? $showtable[$time_label]
: false;
// show oldest creation date in summary row
if ($time && (!$time_all || $time < $time_all)) {
$time_all = $time;
}
return array($time, $time_all);
}
/**
* Get HTML for each table row of the database structure table,
* And this function returns $odd_row param also
*
* @param integer $curr current entry
* @param boolean $odd_row whether row is odd or not
* @param boolean $table_is_view whether table is view or not
* @param array $current_table current table
* @param string $browse_table_label browse table label action link
* @param string $tracking_icon tracking icon
* @param boolean $server_slave_status server slave state
* @param string $browse_table browse table action link
* @param string $tbl_url_query table url query
* @param string $search_table search table action link
* @param boolean $db_is_system_schema whether db is information schema or not
* @param array $titles titles array
* @param string $empty_table empty table action link
* @param string $drop_query table dropt query
* @param string $drop_message table drop message
* @param string $collation collation
* @param string $formatted_size formatted size
* @param string $unit unit
* @param string $overhead overhead
* @param string $create_time create time
* @param string $update_time last update time
* @param string $check_time last check time
* @param boolean $is_show_stats whether stats is show or not
* @param boolean $ignored ignored
* @param boolean $do do
* @param integer $colspan_for_structure colspan for structure
*
* @return array $html_output, $odd_row
*/
function PMA_getHtmlForStructureTableRow(
$curr, $odd_row, $table_is_view, $current_table,
$browse_table_label, $tracking_icon,$server_slave_status,
$browse_table, $tbl_url_query, $search_table,
$db_is_system_schema,$titles, $empty_table, $drop_query, $drop_message,
$collation, $formatted_size, $unit, $overhead, $create_time, $update_time,
$check_time,$is_show_stats, $ignored, $do, $colspan_for_structure
) {
global $db;
$html_output = '<tr class="' . ($odd_row ? 'odd' : 'even');
$odd_row = ! $odd_row;
$html_output .= ($table_is_view ? ' is_view' : '')
. '" id="row_tbl_' . $curr . '">';
$html_output .= '<td class="center">'
. '<input type="checkbox" name="selected_tbl[]" class="checkall" '
. 'value="' . htmlspecialchars($current_table['TABLE_NAME']) . '" '
. 'id="checkbox_tbl_' . $curr . '" /></td>';
$html_output .= '<th>'
. $browse_table_label
. (! empty($tracking_icon) ? $tracking_icon : '')
. '</th>';
if ($server_slave_status) {
$html_output .= '<td class="center">'
. ($ignored
? PMA_Util::getImage('s_cancel.png', 'NOT REPLICATED')
: '')
. ($do
? PMA_Util::getImage('s_success.png', 'REPLICATED')
: '')
. '</td>';
}
//Favorite table anchor.
$html_output .= '<td class="center">'
. PMA_getHtmlForFavoriteAnchor($db, $current_table['TABLE_NAME'], $titles)
. '</td>';
$html_output .= '<td class="center">' . $browse_table . '</td>';
$html_output .= '<td class="center">'
. '<a href="tbl_structure.php?' . $tbl_url_query . '">'
. $titles['Structure'] . '</a></td>';
$html_output .= '<td class="center">' . $search_table . '</td>';
if (! $db_is_system_schema) {
$html_output .= PMA_getHtmlForInsertEmptyDropActionLinks(
$tbl_url_query, $table_is_view,
$titles, $empty_table, $current_table, $drop_query, $drop_message
);
} // end if (! $db_is_system_schema)
// there is a null value in the ENGINE
// - when the table needs to be repaired, or
// - when it's a view
// so ensure that we'll display "in use" below for a table
// that needs to be repaired
if (isset($current_table['TABLE_ROWS'])
&& ($current_table['ENGINE'] != null
|| $table_is_view)
) {
$html_output .= PMA_getHtmlForNotNullEngineViewTable(
$table_is_view, $current_table, $collation, $is_show_stats,
$tbl_url_query, $formatted_size, $unit, $overhead, $create_time,
$update_time, $check_time
);
} elseif ($table_is_view) {
$html_output .= PMA_getHtmlForViewTable($is_show_stats);
} else {
$html_output .= PMA_getHtmlForRepairtable(
$colspan_for_structure,
$db_is_system_schema
);
} // end if (isset($current_table['TABLE_ROWS'])) else
$html_output .= '</tr>';
return array($html_output, $odd_row);
}
/**
* Get HTML for Insert/Empty/Drop action links
*
* @param string $tbl_url_query table url query
* @param boolean $table_is_view whether table is view or not
* @param array $titles titles array
* @param string $empty_table HTML link for empty table
* @param array $current_table current table
* @param string $drop_query query for drop table
* @param string $drop_message table drop message
*
* @return string $html_output
*/
function PMA_getHtmlForInsertEmptyDropActionLinks($tbl_url_query, $table_is_view,
$titles, $empty_table, $current_table, $drop_query, $drop_message
) {
$html_output = '<td class="insert_table center">'
. '<a href="tbl_change.php?' . $tbl_url_query . '">'
. $titles['Insert']
. '</a></td>';
$html_output .= '<td class="center">' . $empty_table . '</td>';
$html_output .= '<td class="center">';
$html_output .= '<a ';
$html_output .= 'class="ajax drop_table_anchor';
if ($table_is_view || $current_table['ENGINE'] == null) {
// this class is used in db_structure.js to display the
// correct confirmation message
$html_output .= ' view';
}
$html_output .= '" ';
$html_output .= 'href="sql.php?' . $tbl_url_query
. '&reload=1&purge=1&sql_query='
. urlencode($drop_query) . '&message_to_show='
. urlencode($drop_message) . '" >'
. $titles['Drop'] . '</a></td>';
return $html_output;
}
/**
* Get HTML for show stats
*
* @param string $tbl_url_query tabel url query
* @param string $formatted_size formatted size
* @param string $unit unit
* @param string $overhead overhead
*
* @return string $html_output
*/
function PMA_getHtmlForShowStats($tbl_url_query, $formatted_size,
$unit, $overhead
) {
$html_output = '<td class="value tbl_size"><a '
. 'href="tbl_structure.php?' . $tbl_url_query . '#showusage" >'
. '<span>' . $formatted_size . '</span> '
. '<span class="unit">' . $unit . '</span>'
. '</a></td>';
$html_output .= '<td class="value tbl_overhead">' . $overhead . '</td>';
return $html_output;
}
/**
* Get HTML to show database structure creation, last update and last checkx time
*
* @param string $create_time create time
* @param string $update_time last update time
* @param string $check_time last check time
*
* @return string $html_output
*/
function PMA_getHtmlForStructureTimes($create_time, $update_time, $check_time)
{
$html_output = '';
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
$html_output .= '<td class="value tbl_creation">'
. ($create_time
? PMA_Util::localisedDate(strtotime($create_time))
: '-' )
. '</td>';
} // end if
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
$html_output .= '<td class="value tbl_last_update">'
. ($update_time
? PMA_Util::localisedDate(strtotime($update_time))
: '-' )
. '</td>';
} // end if
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
$html_output .= '<td class="value tbl_last_check">'
. ($check_time
? PMA_Util::localisedDate(strtotime($check_time))
: '-' )
. '</td>';
}
return $html_output;
}
/**
* Get HTML for ENGINE value not null or view tables that are not empty tables
*
* @param boolean $table_is_view whether table is view
* @param array $current_table current table
* @param string $collation collation
* @param boolean $is_show_stats whether atats show or not
* @param string $tbl_url_query table url query
* @param string $formatted_size formatted size
* @param string $unit unit
* @param string $overhead overhead
* @param string $create_time create time
* @param string $update_time update time
* @param string $check_time check time
*
* @return string $html_output
*/
function PMA_getHtmlForNotNullEngineViewTable($table_is_view, $current_table,
$collation, $is_show_stats, $tbl_url_query, $formatted_size, $unit,
$overhead, $create_time, $update_time, $check_time
) {
$html_output = '';
$row_count_pre = '';
$show_superscript = '';
if ($table_is_view) {
// Drizzle views use FunctionEngine, and the only place where they are
// available are I_S and D_D schemas, where we do exact counting
if ($current_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']
&& $current_table['ENGINE'] != 'FunctionEngine'
) {
$row_count_pre = '~';
$sum_row_count_pre = '~';
$show_superscript = PMA_Util::showHint(
PMA_sanitize(
sprintf(
__('This view has at least this number of rows. Please refer to %sdocumentation%s.'),
'[doc@cfg_MaxExactCountViews]',
'[/doc]'
)
)
);
}
} elseif ($current_table['ENGINE'] == 'InnoDB'
&& (! $current_table['COUNTED'])
) {
// InnoDB table: we did not get an accurate row count
$row_count_pre = '~';
$sum_row_count_pre = '~';
$show_superscript = '';
}
$html_output .= '<td class="value tbl_rows">'
. $row_count_pre . PMA_Util::formatNumber(
$current_table['TABLE_ROWS'], 0
)
. $show_superscript . '</td>';
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
$html_output .= '<td class="nowrap">'
. ($table_is_view ? __('View') : $current_table['ENGINE'])
. '</td>';
if (strlen($collation)) {
$html_output .= '<td class="nowrap">' . $collation . '</td>';
}
}
if ($is_show_stats) {
$html_output .= PMA_getHtmlForShowStats(
$tbl_url_query, $formatted_size, $unit, $overhead
);
}
$html_output .= PMA_getHtmlForStructureTimes(
$create_time, $update_time, $check_time
);
return $html_output;
}
/**
* Get HTML snippet view table
*
* @param boolean $is_show_stats whether stats show or not
*
* @return string $html_output
*/
function PMA_getHtmlForViewTable($is_show_stats)
{
$html_output = '<td class="value">-</td>'
. '<td>' . __('View') . '</td>'
. '<td>---</td>';
if ($is_show_stats) {
$html_output .= '<td class="value">-</td>'
. '<td class="value">-</td>';
}
return $html_output;
}
/**
* display "in use" below for a table that needs to be repaired
*
* @param integer $colspan_for_structure colspan for structure
* @param boolean $db_is_system_schema whether db is information schema or not
*
* @return string HTML snippet
*/
function PMA_getHtmlForRepairtable(
$colspan_for_structure,
$db_is_system_schema
) {
return '<td colspan="'
. ($colspan_for_structure - ($db_is_system_schema ? 5 : 8)) . '"'
. 'class="center">'
. __('in use')
. '</td>';
}
/**
* display table header (<table><thead>...</thead><tbody>)
*
* @param boolean $db_is_system_schema whether db is information schema or not
* @param boolean $replication whether to sho replication status
*
* @return string html data
*/
function PMA_tableHeader($db_is_system_schema = false, $replication = false)
{
$cnt = 0; // Let's count the columns...
if ($db_is_system_schema) {
$action_colspan = 4;
} else {
$action_colspan = 7;
}
$html_output = '<table class="data">' . "\n"
. '<thead>' . "\n"
. '<tr><th></th>' . "\n"
. '<th>'
. PMA_sortableTableHeader(__('Table'), 'table')
. '</th>' . "\n";
if ($replication) {
$html_output .= '<th>' . "\n"
. ' ' . __('Replication') . "\n"
. '</th>';
}
$html_output .= '<th colspan="' . $action_colspan . '">' . "\n"
. ' ' . __('Action') . "\n"
. '</th>'
// larger values are more interesting so default sort order is DESC
. '<th>' . PMA_sortableTableHeader(__('Rows'), 'records', 'DESC')
. PMA_Util::showHint(
PMA_sanitize(
__('May be approximate. See [doc@faq3-11]FAQ 3.11[/doc].')
)
) . "\n"
. '</th>' . "\n";
if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
$html_output .= '<th>' . PMA_sortableTableHeader(__('Type'), 'type')
. '</th>' . "\n";
$cnt++;
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Collation'), 'collation')
. '</th>' . "\n";
$cnt++;
}
if ($GLOBALS['is_show_stats']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Size'), 'size', 'DESC')
. '</th>' . "\n"
// larger values are more interesting so default sort order is DESC
. '<th>'
. PMA_sortableTableHeader(__('Overhead'), 'overhead', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Creation'), 'creation', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Last update'), 'last_update', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
// larger values are more interesting so default sort order is DESC
$html_output .= '<th>'
. PMA_sortableTableHeader(__('Last check'), 'last_check', 'DESC')
. '</th>' . "\n";
$cnt += 2;
}
$html_output .= '</tr>' . "\n";
$html_output .= '</thead>' . "\n";
$html_output .= '<tbody>' . "\n";
$GLOBALS['colspan_for_structure'] = $cnt + $action_colspan + 3;
return $html_output;
}
/**
* Creates a clickable column header for table information
*
* @param string $title title to use for the link
* @param string $sort corresponds to sortable data name mapped in
* libraries/db_info.inc.php
* @param string $initial_sort_order initial sort order
*
* @return string link to be displayed in the table header
*/
function PMA_sortableTableHeader($title, $sort, $initial_sort_order = 'ASC')
{
// Set some defaults
$requested_sort = 'table';
$requested_sort_order = $future_sort_order = $initial_sort_order;
// If the user requested a sort
if (isset($_REQUEST['sort'])) {
$requested_sort = $_REQUEST['sort'];
if (isset($_REQUEST['sort_order'])) {
$requested_sort_order = $_REQUEST['sort_order'];
}
}
$order_img = '';
$order_link_params = array();
$order_link_params['title'] = __('Sort');
// If this column was requested to be sorted.
if ($requested_sort == $sort) {
if ($requested_sort_order == 'ASC') {
$future_sort_order = 'DESC';
// current sort order is ASC
$order_img = ' ' . PMA_Util::getImage(
's_asc.png',
__('Ascending'),
array('class' => 'sort_arrow', 'title' => '')
);
$order_img .= ' ' . PMA_Util::getImage(
's_desc.png',
__('Descending'),
array('class' => 'sort_arrow hide', 'title' => '')
);
// but on mouse over, show the reverse order (DESC)
$order_link_params['onmouseover'] = "$('.sort_arrow').toggle();";
// on mouse out, show current sort order (ASC)
$order_link_params['onmouseout'] = "$('.sort_arrow').toggle();";
} else {
$future_sort_order = 'ASC';
// current sort order is DESC
$order_img = ' ' . PMA_Util::getImage(
's_asc.png',
__('Ascending'),
array('class' => 'sort_arrow hide', 'title' => '')
);
$order_img .= ' ' . PMA_Util::getImage(
's_desc.png',
__('Descending'),
array('class' => 'sort_arrow', 'title' => '')
);
// but on mouse over, show the reverse order (ASC)
$order_link_params['onmouseover'] = "$('.sort_arrow').toggle();";
// on mouse out, show current sort order (DESC)
$order_link_params['onmouseout'] = "$('.sort_arrow').toggle();";
}
}
$_url_params = array(
'db' => $_REQUEST['db'],
);
$url = 'db_structure.php' . PMA_URL_getCommon($_url_params);
// We set the position back to 0 every time they sort.
$url .= "&pos=0&sort=$sort&sort_order=$future_sort_order";
if (! empty($_REQUEST['tbl_type'])) {
$url .= "&tbl_type=" . $_REQUEST['tbl_type'];
}
if (! empty($_REQUEST['tbl_group'])) {
$url .= "&tbl_group=" . $_REQUEST['tbl_group'];
}
return PMA_Util::linkOrButton(
$url, $title . $order_img, $order_link_params
);
}
/**
* Get the alias ant truname
*
* @param string $tooltip_aliasname tooltip alias name
* @param array $current_table current table
* @param string $tooltip_truename tooltip true name
*
* @return array ($alias, $truename)
*/
function PMA_getAliasAndTrueName($tooltip_aliasname, $current_table,
$tooltip_truename
) {
$alias = (! empty($tooltip_aliasname)
&& isset($tooltip_aliasname[$current_table['TABLE_NAME']])
)
? str_replace(
' ', ' ',
htmlspecialchars($tooltip_truename[$current_table['TABLE_NAME']])
)
: str_replace(
' ', ' ',
htmlspecialchars($current_table['TABLE_NAME'])
);
$truename = (! empty($tooltip_truename)
&& isset($tooltip_truename[$current_table['TABLE_NAME']])
)
? str_replace(
' ', ' ',
htmlspecialchars($tooltip_truename[$current_table['TABLE_NAME']])
)
: str_replace(
' ', ' ',
htmlspecialchars($current_table['TABLE_NAME'])
);
return array($alias, $truename);
}
/**
* Get the server slave state
*
* @param boolean $server_slave_status server slave state
* @param string $truename true name
*
* @return array ($do, $ignored)
*/
function PMA_getServerSlaveStatus($server_slave_status, $truename)
{
$ignored = false;
$do = false;
include_once 'libraries/replication.inc.php';
if ($server_slave_status) {
$nbServerSlaveDoDb = count($server_slave_Do_DB);
$nbServerSlaveIgnoreDb = count($server_slave_Ignore_DB);
if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
|| (strlen(array_search($GLOBALS['db'], $server_slave_Do_DB)) > 0)
|| ($nbServerSlaveDoDb == 1 && $nbServerSlaveIgnoreDb == 1)
) {
$do = true;
}
foreach ($server_slave_Wild_Do_Table as $db_table) {
$table_part = PMA_extractDbOrTable($db_table, 'table');
$pattern = "@^" . substr($table_part, 0, strlen($table_part) - 1) . "@";
if (($GLOBALS['db'] == PMA_extractDbOrTable($db_table, 'db'))
&& (preg_match($pattern, $truename))
) {
$do = true;
}
}
if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0)
|| (strlen(array_search($GLOBALS['db'], $server_slave_Ignore_DB)) > 0)
) {
$ignored = true;
}
foreach ($server_slave_Wild_Ignore_Table as $db_table) {
$table_part = PMA_extractDbOrTable($db_table, 'table');
$pattern = "@^" . substr($table_part, 0, strlen($table_part) - 1) . "@";
if (($db == PMA_extractDbOrTable($db_table))
&& (preg_match($pattern, $truename))
) {
$ignored = true;
}
}
}
return array($do, $ignored);
}
/**
* Get the value set for ENGINE table,
* $current_table, $formatted_size, $unit, $formatted_overhead,
* $overhead_unit, $overhead_size, $table_is_view
*
* @param array $current_table current table
* @param boolean $db_is_system_schema whether db is information schema or not
* @param boolean $is_show_stats whether stats show or not
* @param boolean $table_is_view whether table is view or not
* @param double $sum_size totle table size
* @param double $overhead_size overhead size
*
* @return array
*/
function PMA_getStuffForEngineTypeTable($current_table, $db_is_system_schema,
$is_show_stats, $table_is_view, $sum_size, $overhead_size
) {
$formatted_size = '-';
$unit = '';
$formatted_overhead = '';
$overhead_unit = '';
switch ( $current_table['ENGINE']) {
// MyISAM, ISAM or Heap table: Row count, data size and index size
// are accurate; data size is accurate for ARCHIVE
case 'MyISAM' :
case 'ISAM' :
case 'HEAP' :
case 'MEMORY' :
case 'ARCHIVE' :
case 'Aria' :
case 'Maria' :
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size) = PMA_getValuesForAriaTable(
$db_is_system_schema, $current_table, $is_show_stats,
$sum_size, $overhead_size, $formatted_size, $unit,
$formatted_overhead, $overhead_unit
);
break;
case 'InnoDB' :
case 'PBMS' :
// InnoDB table: Row count is not accurate but data and index sizes are.
// PBMS table in Drizzle: TABLE_ROWS is taken from table cache,
// so it may be unavailable
list($current_table, $formatted_size, $unit, $sum_size)
= PMA_getValuesForInnodbTable($current_table, $is_show_stats, $sum_size);
//$display_rows = ' - ';
break;
// Mysql 5.0.x (and lower) uses MRG_MyISAM
// and MySQL 5.1.x (and higher) uses MRG_MYISAM
// Both are aliases for MERGE
case 'MRG_MyISAM' :
case 'MRG_MYISAM' :
case 'MERGE' :
case 'BerkeleyDB' :
// Merge or BerkleyDB table: Only row count is accurate.
if ($is_show_stats) {
$formatted_size = ' - ';
$unit = '';
}
break;
// for a view, the ENGINE is sometimes reported as null,
// or on some servers it's reported as "SYSTEM VIEW"
case null :
case 'SYSTEM VIEW' :
case 'FunctionEngine' :
// if table is broken, Engine is reported as null, so one more test
if ($current_table['TABLE_TYPE'] == 'VIEW') {
// countRecords() takes care of $cfg['MaxExactCountViews']
$current_table['TABLE_ROWS'] = PMA_Table::countRecords(
$GLOBALS['db'], $current_table['TABLE_NAME'],
true, true
);
$table_is_view = true;
}
break;
default :
// Unknown table type.
if ($is_show_stats) {
$formatted_size = __('unknown');
$unit = '';
}
} // end switch
return array($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $table_is_view, $sum_size
);
}
/**
* Get values for ARIA/MARIA tables
* $current_table, $formatted_size, $unit, $formatted_overhead,
* $overhead_unit, $overhead_size
*
* @param boolean $db_is_system_schema whether db is information schema or not
* @param array $current_table current table
* @param boolean $is_show_stats whether stats show or not
* @param double $sum_size sum size
* @param double $overhead_size overhead size
* @param number $formatted_size formatted size
* @param string $unit unit
* @param number $formatted_overhead overhead formatted
* @param string $overhead_unit overhead unit
*
* @return array
*/
function PMA_getValuesForAriaTable($db_is_system_schema, $current_table,
$is_show_stats, $sum_size, $overhead_size, $formatted_size, $unit,
$formatted_overhead, $overhead_unit
) {
if ($db_is_system_schema) {
$current_table['Rows'] = PMA_Table::countRecords(
$GLOBALS['db'], $current_table['Name']
);
}
if ($is_show_stats) {
$tblsize = doubleval($current_table['Data_length'])
+ doubleval($current_table['Index_length']);
$sum_size += $tblsize;
list($formatted_size, $unit) = PMA_Util::formatByteDown(
$tblsize, 3, ($tblsize > 0) ? 1 : 0
);
if (isset($current_table['Data_free']) && $current_table['Data_free'] > 0) {
list($formatted_overhead, $overhead_unit)
= PMA_Util::formatByteDown(
$current_table['Data_free'], 3,
(($current_table['Data_free'] > 0) ? 1 : 0)
);
$overhead_size += $current_table['Data_free'];
}
}
return array($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $sum_size
);
}
/**
* Get values for InnoDB table
* $current_table, $formatted_size, $unit, $sum_size
*
* @param array $current_table current table
* @param boolean $is_show_stats whether stats show or not
* @param double $sum_size sum size
*
* @return array
*/
function PMA_getValuesForInnodbTable($current_table, $is_show_stats, $sum_size)
{
$formatted_size = $unit = '';
if (($current_table['ENGINE'] == 'InnoDB'
&& $current_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount'])
|| !isset($current_table['TABLE_ROWS'])
) {
$current_table['COUNTED'] = true;
$current_table['TABLE_ROWS'] = PMA_Table::countRecords(
$GLOBALS['db'], $current_table['TABLE_NAME'],
true, false
);
} else {
$current_table['COUNTED'] = false;
}
// Drizzle doesn't provide data and index length, check for null
if ($is_show_stats && $current_table['Data_length'] !== null) {
$tblsize = $current_table['Data_length'] + $current_table['Index_length'];
$sum_size += $tblsize;
list($formatted_size, $unit) = PMA_Util::formatByteDown(
$tblsize, 3, (($tblsize > 0) ? 1 : 0)
);
}
return array($current_table, $formatted_size, $unit, $sum_size);
}
/**
* table structure
*/
/**
* Get the HTML snippet for structure table table header
*
* @param boolean $db_is_system_schema whether db is information schema or not
* @param boolean $tbl_is_view whether table is view or not
*
* @return string $html_output
*/
function PMA_getHtmlForTableStructureHeader(
$db_is_system_schema,
$tbl_is_view
) {
$html_output = '<thead>';
$html_output .= '<tr>';
$html_output .= '<th></th>'
. '<th>#</th>'
. '<th>' . __('Name') . '</th>'
. '<th>' . __('Type') . '</th>'
. '<th>' . __('Collation') . '</th>'
. '<th>' . __('Attributes') . '</th>'
. '<th>' . __('Null') . '</th>'
. '<th>' . __('Default') . '</th>'
. '<th>' . __('Extra') . '</th>';
if ($db_is_system_schema || $tbl_is_view) {
$html_output .= '<th>' . __('View') . '</th>';
} else { /* see tbl_structure.js, function moreOptsMenuResize() */
$colspan = 9;
if (PMA_DRIZZLE) {
$colspan -= 2;
}
if (PMA_Util::showIcons('ActionLinksMode')) {
$colspan--;
}
$html_output .= '<th colspan="' . $colspan . '" '
. 'class="action">' . __('Action') . '</th>';
}
$html_output .= '</tr>'
. '</thead>';
return $html_output;
}
/**
* Get HTML for structure table's rows and return $odd_row parameter also
* For "Action" Column, this function contains only HTML code for "Change"
* and "Drop"
*
* @param array $row current row
* @param string $rownum row number
* @param string $displayed_field_name displayed field name
* @param string $type_nowrap type nowrap
* @param array $extracted_columnspec associative array containing type,
* spec_in_brackets and possibly
* enum_set_values (another array)
* @param string $type_mime mime type
* @param string $field_charset field charset
* @param string $attribute attribute (BINARY, UNSIGNED,
* UNSIGNED ZEROFILL,
* on update CURRENT_TIMESTAMP)
* @param boolean $tbl_is_view whether tables is view or not
* @param boolean $db_is_system_schema whether db is information schema or not
* @param string $url_query url query
* @param string $field_encoded field encoded
* @param array $titles titles array
* @param string $table table
*
* @return array ($html_output, $odd_row)
*/
function PMA_getHtmlTableStructureRow($row, $rownum,
$displayed_field_name, $type_nowrap, $extracted_columnspec, $type_mime,
$field_charset, $attribute, $tbl_is_view, $db_is_system_schema,
$url_query, $field_encoded, $titles, $table
) {
$html_output = '<td class="center">'
. '<input type="checkbox" class="checkall" name="selected_fld[]" '
. 'value="' . htmlspecialchars($row['Field']) . '" '
. 'id="checkbox_row_' . $rownum . '"/>'
. '</td>';
$html_output .= '<td class="right">'
. $rownum
. '</td>';
$html_output .= '<th class="nowrap">'
. '<label for="checkbox_row_' . $rownum . '">'
. preg_replace(
'/[\x00-\x1F]/',
'⁑',
$displayed_field_name
) . '</label>'
. '</th>';
$html_output .= '<td' . $type_nowrap . '>'
. '<bdo dir="ltr" lang="en">'
. $extracted_columnspec['displayed_type'] . $type_mime
. '</bdo></td>';
$html_output .= '<td>' .
(empty($field_charset)
? ''
: '<dfn title="' . PMA_getCollationDescr($field_charset) . '">'
. $field_charset . '</dfn>'
)
. '</td>';
$html_output .= '<td class="column_attribute nowrap">'
. $attribute . '</td>';
$html_output .= '<td>'
. (($row['Null'] == 'YES') ? __('Yes') : __('No')) . ' </td>';
$html_output .= '<td class="nowrap">';
if (isset($row['Default'])) {
if ($extracted_columnspec['type'] == 'bit') {
// here, $row['Default'] contains something like b'010'
$html_output .= PMA_Util::convertBitDefaultValue($row['Default']);
} else {
$html_output .= $row['Default'];
}
} else {
$html_output .= '<i>' . _pgettext('None for default', 'None') . '</i>';
}
$html_output .= '</td>';
$html_output .= '<td class="nowrap">' . strtoupper($row['Extra']) . '</td>';
$html_output .= PMA_getHtmlForDropColumn(
$tbl_is_view, $db_is_system_schema,
$url_query, $field_encoded,
$titles, $table, $row
);
return $html_output;
}
/**
* Get HTML code for "Drop" Action link
*
* @param boolean $tbl_is_view whether tables is view or not
* @param boolean $db_is_system_schema whether db is information schema or not
* @param string $url_query url query
* @param string $field_encoded field encoded
* @param array $titles tittles array
* @param string $table table
* @param array $row current row
*
* @return string $html_output
*/
function PMA_getHtmlForDropColumn($tbl_is_view, $db_is_system_schema,
$url_query, $field_encoded, $titles, $table, $row
) {
$html_output = '';
if (! $tbl_is_view && ! $db_is_system_schema) {
$html_output .= '<td class="edit center">'
. '<a class="change_column_anchor ajax"'
. ' href="tbl_structure.php?'
. $url_query . '&field=' . $field_encoded
. '&change_column=1">'
. $titles['Change'] . '</a>' . '</td>';
$html_output .= '<td class="drop center">'
. '<a class="drop_column_anchor ajax"'
. ' href="sql.php?' . $url_query . '&sql_query='
. urlencode(
'ALTER TABLE ' . PMA_Util::backquote($table)
. ' DROP ' . PMA_Util::backquote($row['Field']) . ';'
)
. '&dropped_column=' . urlencode($row['Field'])
. '&message_to_show=' . urlencode(
sprintf(
__('Column %s has been dropped.'),
htmlspecialchars($row['Field'])
)
) . '" >'
. $titles['Drop'] . '</a>'
. '</td>';
}
return $html_output;
}
/**
* Get HTML for "check all" check box with "with selected" actions in table
* structure
*
* @param string $pmaThemeImage pma theme image url
* @param string $text_dir test directory
* @param boolean $tbl_is_view whether table is view or not
* @param boolean $db_is_system_schema whether db is information schema or not
* @param string $tbl_storage_engine table storage engine
*
* @return string $html_output
*/
function PMA_getHtmlForCheckAllTableColumn($pmaThemeImage, $text_dir,
$tbl_is_view, $db_is_system_schema, $tbl_storage_engine
) {
$html_output = '<img class="selectallarrow" '
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
$html_output .= '<input type="checkbox" id="fieldsForm_checkall" '
. 'class="checkall_box" title="' . __('Check All') . '" />'
. '<label for="fieldsForm_checkall">' . __('Check All') . '</label>';
$html_output .= '<i style="margin-left: 2em">'
. __('With selected:') . '</i>';
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_browse',
__('Browse'), 'b_browse.png', 'browse'
);
if (! $tbl_is_view && ! $db_is_system_schema) {
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit change_columns_anchor ajax',
'submit_mult_change', __('Change'), 'b_edit.png', 'change'
);
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_drop',
__('Drop'), 'b_drop.png', 'drop'
);
if ('ARCHIVE' != $tbl_storage_engine) {
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_primary',
__('Primary'), 'b_primary.png', 'primary'
);
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_unique',
__('Unique'), 'b_unique.png', 'unique'
);
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_index',
__('Index'), 'b_index.png', 'index'
);
}
if (! empty($tbl_storage_engine) && $tbl_storage_engine == 'MYISAM') {
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_spatial',
__('Spatial'), 'b_spatial.png', 'spatial'
);
}
if (! empty($tbl_storage_engine)
&& ($tbl_storage_engine == 'MYISAM'
|| $tbl_storage_engine == 'ARIA'
|| $tbl_storage_engine == 'MARIA')
) {
$html_output .= PMA_Util::getButtonOrImage(
'submit_mult', 'mult_submit', 'submit_mult_fulltext',
__('Fulltext'), 'b_ftext.png', 'ftext'
);
}
}
return $html_output;
}
/**
* Get HTML for move columns dialog
*
* @return string $html_output
*/
function PMA_getHtmlDivForMoveColumnsDialog()
{
$html_output = '<div id="move_columns_dialog" '
. 'title="' . __('Move columns') . '" style="display: none">';
$html_output .= '<p>'
. __('Move the columns by dragging them up and down.') . '</p>';
$html_output .= '<form action="tbl_structure.php">'
. '<div>'
. PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
. '<ul></ul>'
. '</div>'
. '</form>'
. '</div>';
return $html_output;
}
/**
* Get HTML for edit views'
*
* @param string $url_params URL parameters
*
* @return string $html_output
*/
function PMA_getHtmlForEditView($url_params)
{
$query = "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`, `SECURITY_TYPE`"
. " FROM `INFORMATION_SCHEMA`.`VIEWS`"
. " WHERE TABLE_SCHEMA='" . PMA_Util::sqlAddSlashes($GLOBALS['db']) . "'"
. " AND TABLE_NAME='" . PMA_Util::sqlAddSlashes($GLOBALS['table']) . "';";
$item = $GLOBALS['dbi']->fetchSingleRow($query);
$view = array(
'operation' => 'alter',
'definer' => $item['DEFINER'],
'sql_security' => $item['SECURITY_TYPE'],
'name' => $GLOBALS['table'],
'as' => $item['VIEW_DEFINITION'],
'with' => $item['CHECK_OPTION'],
);
$url = 'view_create.php' . PMA_URL_getCommon($url_params) . '&';
$url .= implode(
'&',
array_map(
function ($key, $val) {
return 'view[' . urlencode($key) . ']=' . urlencode($val);
},
array_keys($view),
$view
)
);
$html_output = PMA_Util::linkOrButton(
$url,
PMA_Util::getIcon('b_edit.png', __('Edit view'), true)
);
return $html_output;
}
/**
* Get HTML links for 'Print view', 'Relation view', 'Propose table structure',
* 'Track table' and 'Move columns'
*
* @param string $url_query url query
* @param boolean $tbl_is_view whether table is view or not
* @param boolean $db_is_system_schema whether db is information schema or not
* @param string $tbl_storage_engine table storage engine
* @param array $cfgRelation current relation parameters
*
* @return string $html_output
*/
function PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view,
$db_is_system_schema, $tbl_storage_engine, $cfgRelation
) {
$html_output = '<a href="tbl_printview.php?' . $url_query
. '" target="print_view">'
. PMA_Util::getIcon('b_print.png', __('Print view'), true)
. '</a>';
if (! $tbl_is_view && ! $db_is_system_schema) {
// if internal relations are available, or foreign keys are supported
// ($tbl_storage_engine comes from libraries/tbl_info.inc.php
if ($cfgRelation['relwork']
|| PMA_Util::isForeignKeySupported($tbl_storage_engine)
) {
$html_output .= '<a href="tbl_relation.php?' . $url_query . '">'
. PMA_Util::getIcon(
'b_relations.png', __('Relation view'), true
)
. '</a>';
}
if (!PMA_DRIZZLE) {
$html_output .= '<a href="sql.php?' . $url_query
. '&session_max_rows=all&sql_query=' . urlencode(
'SELECT * FROM ' . PMA_Util::backquote($GLOBALS['table'])
. ' PROCEDURE ANALYSE()'
) . '">'
. PMA_Util::getIcon(
'b_tblanalyse.png',
__('Propose table structure'),
true
)
. '</a>';
$html_output .= PMA_Util::showMySQLDocu('procedure_analyse') . "\n";
}
if (PMA_Tracker::isActive()) {
$html_output .= '<a href="tbl_tracking.php?' . $url_query . '">'
. PMA_Util::getIcon('eye.png', __('Track table'), true)
. '</a>';
}
$html_output .= '<a href="#" id="move_columns_anchor">'
. PMA_Util::getIcon('b_move.png', __('Move columns'), true)
. '</a>';
}
return $html_output;
}
/**
* Get HTML snippet for "Add column" feature in structure table
*
* @param array $columns_list column list array
*
* @return string $html_output
*/
function PMA_getHtmlForAddColumn($columns_list)
{
$html_output = '<form method="post" action="tbl_addfield.php" '
. 'id="addColumns" name="addColumns" '
. 'onsubmit="return checkFormElementInRange('
. 'this, \'num_fields\', \'' . str_replace(
'\'',
'\\\'',
__('You have to add at least one column.')
) . '\', 1)'
. '">';
$html_output .= PMA_URL_getHiddenInputs(
$GLOBALS['db'],
$GLOBALS['table']
);
if (PMA_Util::showIcons('ActionLinksMode')) {
$html_output .=PMA_Util::getImage(
'b_insrow.png',
__('Add column')
);
}
$num_fields = '<input type="number" name="num_fields" '
. 'value="1" onfocus="this.select()" '
. 'min="1" required />';
$html_output .= sprintf(__('Add %s column(s)'), $num_fields);
// I tried displaying the drop-down inside the label but with Firefox
// the drop-down was blinking
$column_selector = '<select name="after_field" '
. 'onclick="this.form.field_where[2].checked=true" '
. 'onchange="this.form.field_where[2].checked=true">';
foreach ($columns_list as $one_column_name) {
$column_selector .= '<option '
. 'value="' . htmlspecialchars($one_column_name) . '">'
. htmlspecialchars($one_column_name)
. '</option>';
}
$column_selector .= '</select>';
$choices = array(
'last' => __('At End of Table'),
'first' => __('At Beginning of Table'),
'after' => sprintf(__('After %s'), '')
);
$html_output .= PMA_Util::getRadioFields(
'field_where', $choices, 'last', false
);
$html_output .= $column_selector;
$html_output .= '<input type="submit" value="' . __('Go') . '" />'
. '</form>';
return $html_output;
}
/**
* Get HTML snippet for table rows in the Information ->Space usage table
*
* @param boolean $odd_row whether current row is odd or even
* @param string $name type of usage
* @param string $value value of usage
* @param string $unit unit
*
* @return string $html_output
*/
function PMA_getHtmlForSpaceUsageTableRow($odd_row, $name, $value, $unit)
{
$html_output = '<tr class="' . (($odd_row = !$odd_row) ? 'odd' : 'even') . '">';
$html_output .= '<th class="name">' . $name . '</th>';
$html_output .= '<td class="value">' . $value . '</td>';
$html_output .= '<td class="unit">' . $unit . '</td>';
$html_output .= '</tr>';
return $html_output;
}
/**
* Get HTML for Optimize link if overhead in Information fieldset
*
* @param string $url_query URL query
*
* @return string $html_output
*/
function PMA_getHtmlForOptimizeLink($url_query)
{
$html_output = '<tr class="tblFooters">';
$html_output .= '<td colspan="3" class="center">';
$html_output .= '<a href="sql.php?' . $url_query
. '&pos=0&sql_query=' . urlencode(
'OPTIMIZE TABLE ' . PMA_Util::backquote($GLOBALS['table'])
)
. '">'
. PMA_Util::getIcon('b_tbloptimize.png', __('Optimize table'))
. '</a>';
$html_output .= '</td>';
$html_output .= '</tr>';
return $html_output;
}
/**
* Get HTML for 'Row statistics' table row
*
* @param boolean $odd_row whether current row is odd or even
* @param string $name statement name
* @param mixed $value value
*
* @return string $html_output
*/
function PMA_getHtmlForRowStatsTableRow($odd_row, $name, $value)
{
$html_output = '<tr class="' . (($odd_row = !$odd_row) ? 'odd' : 'even') . '">';
$html_output .= '<th class="name">' . $name . '</th>';
$html_output .= '<td class="value">' . $value . '</td>';
$html_output .= '</tr>';
return $html_output;
}
/**
* Get HTML snippet for display Row statistics table
*
* @param array $showtable show table array
* @param string $tbl_collation table collation
* @param boolean $is_innodb whether table is innob or not
* @param boolean $mergetable Checks if current table is a merge table
* @param integer $avg_size average size
* @param string $avg_unit average unit
*
* @return string $html_output
*/
function getHtmlForRowStatsTable($showtable, $tbl_collation,
$is_innodb, $mergetable, $avg_size, $avg_unit
) {
$odd_row = false;
$html_output = '<table id="tablerowstats" class="data">';
$html_output .= '<caption class="tblHeaders">'
. __('Row statistics') . '</caption>';
$html_output .= '<tbody>';
if (isset($showtable['Row_format'])) {
if ($showtable['Row_format'] == 'Fixed') {
$value = __('static');
} elseif ($showtable['Row_format'] == 'Dynamic') {
$value = __('dynamic');
} else {
$value = $showtable['Row_format'];
}
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row, __('Format'), $value
);
$odd_row = !$odd_row;
}
if (! empty($showtable['Create_options'])) {
if ($showtable['Create_options'] == 'partitioned') {
$value = __('partitioned');
} else {
$value = $showtable['Create_options'];
}
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row, __('Options'), $value
);
$odd_row = !$odd_row;
}
if (!empty($tbl_collation)) {
$value = '<dfn title="' . PMA_getCollationDescr($tbl_collation) . '">'
. $tbl_collation . '</dfn>';
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row, __('Collation'), $value
);
$odd_row = !$odd_row;
}
if (!$is_innodb && isset($showtable['Rows'])) {
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Rows'),
PMA_Util::formatNumber($showtable['Rows'], 0)
);
$odd_row = !$odd_row;
}
if (!$is_innodb
&& isset($showtable['Avg_row_length'])
&& $showtable['Avg_row_length'] > 0
) {
list($avg_row_length_value, $avg_row_length_unit)
= PMA_Util::formatByteDown(
$showtable['Avg_row_length'],
6,
1
);
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Row length'),
($avg_row_length_value . ' ' . $avg_row_length_unit)
);
unset($avg_row_length_value, $avg_row_length_unit);
$odd_row = !$odd_row;
}
if (!$is_innodb
&& isset($showtable['Data_length'])
&& $showtable['Rows'] > 0
&& $mergetable == false
) {
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Row size'),
($avg_size . ' ' . $avg_unit)
);
$odd_row = !$odd_row;
}
if (isset($showtable['Auto_increment'])) {
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Next autoindex'),
PMA_Util::formatNumber($showtable['Auto_increment'], 0)
);
$odd_row = !$odd_row;
}
if (isset($showtable['Create_time'])) {
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Creation'),
PMA_Util::localisedDate(strtotime($showtable['Create_time']))
);
$odd_row = !$odd_row;
}
if (isset($showtable['Update_time'])) {
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Last update'),
PMA_Util::localisedDate(strtotime($showtable['Update_time']))
);
$odd_row = !$odd_row;
}
if (isset($showtable['Check_time'])) {
$html_output .= PMA_getHtmlForRowStatsTableRow(
$odd_row,
__('Last check'),
PMA_Util::localisedDate(strtotime($showtable['Check_time']))
);
}
$html_output .= '</tbody>'
. '</table>';
return $html_output;
}
/**
* Get HTML snippet for action row in structure table,
* This function returns common HTML <td> for Primary, Unique, Index,
* Spatial actions
*
* @param array $type column type
* @param array $tbl_storage_engine table storage engine
* @param string $class class attribute for <td>
* @param boolean $hasField has field
* @param boolean $hasLinkClass has <a> the class attribute
* @param string $url_query url query
* @param boolean $primary primary if set, false otherwise
* @param string $syntax Sql syntax
* @param string $message message to show
* @param string $action action
* @param array $titles titles array
* @param array $row current row
* @param boolean $isPrimary is primary action
*
* @return string $html_output
*/
function PMA_getHtmlForActionRowInStructureTable($type, $tbl_storage_engine,
$class, $hasField, $hasLinkClass, $url_query, $primary, $syntax,
$message, $action, $titles, $row, $isPrimary
) {
$html_output = '<li class="' . $class . '">';
if ($type == 'text'
|| $type == 'blob'
|| 'ARCHIVE' == $tbl_storage_engine
|| $hasField
) {
$html_output .= $titles['No' . $action];
} else {
$html_output .= '<a rel="samepage" '
. ($hasLinkClass ? 'class="ajax add_primary_key_anchor" ' :
($action=='Index' ? 'class="ajax add_index_anchor"' :
($action=='Unique' ? 'class="ajax add_unique_anchor"' : ' ')
)
)
. ' href="sql.php?' . $url_query . '&sql_query='
. urlencode(
'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table'])
. ($isPrimary ? ($primary ? ' DROP PRIMARY KEY,' : '') : '')
. ' ' . $syntax . '('
. PMA_Util::backquote($row['Field']) . ');'
)
. '&message_to_show=' . urlencode(
sprintf(
$message,
htmlspecialchars($row['Field'])
)
) . '" >'
. $titles[$action] . '</a>';
}
$html_output .= '</li>';
return $html_output;
}
/**
* Get HTML for fulltext action
*
* @param string $tbl_storage_engine table storage engine
* @param string $type column type
* @param string $url_query url query
* @param array $row current row
* @param array $titles titles array
*
* @return string $html_output
*/
function PMA_getHtmlForFullTextAction($tbl_storage_engine, $type, $url_query,
$row, $titles
) {
$html_output = '<li class="fulltext nowrap">';
if (! empty($tbl_storage_engine)
&& ($tbl_storage_engine == 'MYISAM'
|| $tbl_storage_engine == 'ARIA'
|| $tbl_storage_engine == 'MARIA'
|| ($tbl_storage_engine == 'INNODB' && PMA_MYSQL_INT_VERSION >= 50604))
&& (strpos($type, 'text') !== false || strpos($type, 'char') !== false)
) {
$html_output .= '<a rel="samepage" href="sql.php?' . $url_query
. '&sql_query='
. urlencode(
'ALTER TABLE ' . PMA_Util::backquote($GLOBALS['table'])
. ' ADD FULLTEXT(' . PMA_Util::backquote($row['Field'])
. ');'
)
. '&message_to_show='
. urlencode(
sprintf(
__('An index has been added on %s.'),
htmlspecialchars($row['Field'])
)
)
. '">';
$html_output .= $titles['IdxFulltext'] . '</a>';
} else {
$html_output .= $titles['NoIdxFulltext'];
}
$html_output .= '</li>';
return $html_output;
}
/**
* Get HTML snippet for "Distinc Value" action
*
* @param string $url_query url query
* @param array $row current row
* @param array $titles titles array
*
* @return string $html_output
*/
function PMA_getHtmlForDistinctValueAction($url_query, $row, $titles)
{
$html_output = '<li class="browse nowrap">';
$html_output .= '<a href="sql.php?' . $url_query . '&sql_query='
. urlencode(
'SELECT COUNT(*) AS ' . PMA_Util::backquote(__('Rows'))
. ', ' . PMA_Util::backquote($row['Field'])
. ' FROM ' . PMA_Util::backquote($GLOBALS['table'])
. ' GROUP BY ' . PMA_Util::backquote($row['Field'])
. ' ORDER BY ' . PMA_Util::backquote($row['Field'])
)
. '">'
. $titles['DistinctValues']
. '</a>';
$html_output .= '</li>';
return $html_output;
}
/**
* Get HTML snippet for Actions in table structure
*
* @param string $type column type
* @param string $tbl_storage_engine table storage engine
* @param boolean $primary primary if set, false otherwise
* @param string $field_name column name
* @param string $url_query url query
* @param array $titles titles array
* @param array $row current row
* @param string $rownum row number
* @param array $hidden_titles hidden titles
* @param array $columns_with_unique_index columns with unique index
*
* @return string $html_output;
*/
function PMA_getHtmlForActionsInTableStructure($type, $tbl_storage_engine,
$primary, $field_name, $url_query, $titles, $row, $rownum, $hidden_titles,
$columns_with_unique_index
) {
$html_output = '<td><ul class="table-structure-actions resizable-menu">';
$html_output .= PMA_getHtmlForActionRowInStructureTable(
$type, $tbl_storage_engine,
'primary nowrap',
($primary && $primary->hasColumn($field_name)),
true, $url_query, $primary,
'ADD PRIMARY KEY',
__('A primary key has been added on %s.'),
'Primary', $titles, $row, true
);
$html_output .= PMA_getHtmlForActionRowInStructureTable(
$type, $tbl_storage_engine,
'add_unique unique nowrap',
isset($columns_with_unique_index[$field_name]),
false, $url_query, $primary, 'ADD UNIQUE',
__('An index has been added on %s.'),
'Unique', $titles, $row, false
);
$html_output .= PMA_getHtmlForActionRowInStructureTable(
$type, $tbl_storage_engine,
'add_index nowrap', false, false, $url_query,
$primary, 'ADD INDEX', __('An index has been added on %s.'),
'Index', $titles, $row, false
);
if (!PMA_DRIZZLE) {
$spatial_types = array(
'geometry', 'point', 'linestring', 'polygon', 'multipoint',
'multilinestring', 'multipolygon', 'geomtrycollection'
);
$html_output .= PMA_getHtmlForActionRowInStructureTable(
$type, $tbl_storage_engine,
'spatial nowrap',
(! in_array($type, $spatial_types)
|| 'MYISAM' != $tbl_storage_engine
),
false, $url_query, $primary, 'ADD SPATIAL',
__('An index has been added on %s.'), 'Spatial',
$titles, $row, false
);
// FULLTEXT is possible on TEXT, CHAR and VARCHAR
$html_output .= PMA_getHtmlForFullTextAction(
$tbl_storage_engine, $type, $url_query, $row, $titles
);
}
$html_output .= PMA_getHtmlForDistinctValueAction($url_query, $row, $titles);
$html_output .= '</ul></td>';
return $html_output;
}
/**
* Get hidden action titles (image and string)
*
* @return array $hidden_titles
*/
function PMA_getHiddenTitlesArray()
{
$hidden_titles = array();
$hidden_titles['DistinctValues'] = PMA_Util::getIcon(
'b_browse.png', __('Distinct values'), true
);
$hidden_titles['Primary'] = PMA_Util::getIcon(
'b_primary.png', __('Add primary key'), true
);
$hidden_titles['NoPrimary'] = PMA_Util::getIcon(
'bd_primary.png', __('Add primary key'), true
);
$hidden_titles['Index'] = PMA_Util::getIcon(
'b_index.png', __('Add index'), true
);
$hidden_titles['NoIndex'] = PMA_Util::getIcon(
'bd_index.png', __('Add index'), true
);
$hidden_titles['Unique'] = PMA_Util::getIcon(
'b_unique.png', __('Add unique index'), true
);
$hidden_titles['NoUnique'] = PMA_Util::getIcon(
'bd_unique.png', __('Add unique index'), true
);
$hidden_titles['Spatial'] = PMA_Util::getIcon(
'b_spatial.png', __('Add SPATIAL index'), true
);
$hidden_titles['NoSpatial'] = PMA_Util::getIcon(
'bd_spatial.png', __('Add SPATIAL index'), true
);
$hidden_titles['IdxFulltext'] = PMA_Util::getIcon(
'b_ftext.png', __('Add FULLTEXT index'), true
);
$hidden_titles['NoIdxFulltext'] = PMA_Util::getIcon(
'bd_ftext.png', __('Add FULLTEXT index'), true
);
return $hidden_titles;
}
/**
* Get action titles (image or string array
*
* @return array $titles
*/
function PMA_getActionTitlesArray()
{
$titles = array();
$titles['Change']
= PMA_Util::getIcon('b_edit.png', __('Change'));
$titles['Drop']
= PMA_Util::getIcon('b_drop.png', __('Drop'));
$titles['NoDrop']
= PMA_Util::getIcon('b_drop.png', __('Drop'));
$titles['Primary']
= PMA_Util::getIcon('b_primary.png', __('Primary'));
$titles['Index']
= PMA_Util::getIcon('b_index.png', __('Index'));
$titles['Unique']
= PMA_Util::getIcon('b_unique.png', __('Unique'));
$titles['Spatial']
= PMA_Util::getIcon('b_spatial.png', __('Spatial'));
$titles['IdxFulltext']
= PMA_Util::getIcon('b_ftext.png', __('Fulltext'));
$titles['NoPrimary']
= PMA_Util::getIcon('bd_primary.png', __('Primary'));
$titles['NoIndex']
= PMA_Util::getIcon('bd_index.png', __('Index'));
$titles['NoUnique']
= PMA_Util::getIcon('bd_unique.png', __('Unique'));
$titles['NoSpatial']
= PMA_Util::getIcon('bd_spatial.png', __('Spatial'));
$titles['NoIdxFulltext']
= PMA_Util::getIcon('bd_ftext.png', __('Fulltext'));
$titles['DistinctValues']
= PMA_Util::getIcon('b_browse.png', __('Distinct values'));
return $titles;
}
/**
* Get HTML snippet for display table statistics
*
* @param array $showtable full table status info
* @param integer $table_info_num_rows table info number of rows
* @param boolean $tbl_is_view whether table is view or not
* @param boolean $db_is_system_schema whether db is information schema or not
* @param string $tbl_storage_engine table storage engine
* @param string $url_query url query
* @param string $tbl_collation table collation
*
* @return string $html_output
*/
function PMA_getHtmlForDisplayTableStats($showtable, $table_info_num_rows,
$tbl_is_view, $db_is_system_schema, $tbl_storage_engine, $url_query,
$tbl_collation
) {
$html_output = '<div id="tablestatistics">';
if (empty($showtable)) {
$showtable = PMA_Table::sGetStatusInfo(
$GLOBALS['db'], $GLOBALS['table'], null, true
);
}
$nonisam = false;
$is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
if (isset($showtable['Type'])
&& ! preg_match('@ISAM|HEAP@i', $showtable['Type'])
) {
$nonisam = true;
}
// Gets some sizes
$mergetable = PMA_Table::isMerge($GLOBALS['db'], $GLOBALS['table']);
// this is to display for example 261.2 MiB instead of 268k KiB
$max_digits = 3;
$decimals = 1;
list($data_size, $data_unit) = PMA_Util::formatByteDown(
$showtable['Data_length'], $max_digits, $decimals
);
if ($mergetable == false) {
list($index_size, $index_unit) = PMA_Util::formatByteDown(
$showtable['Index_length'], $max_digits, $decimals
);
}
// InnoDB returns a huge value in Data_free, do not use it
if (! $is_innodb
&& isset($showtable['Data_free'])
&& $showtable['Data_free'] > 0
) {
list($free_size, $free_unit) = PMA_Util::formatByteDown(
$showtable['Data_free'], $max_digits, $decimals
);
list($effect_size, $effect_unit) = PMA_Util::formatByteDown(
$showtable['Data_length'] + $showtable['Index_length']
- $showtable['Data_free'],
$max_digits, $decimals
);
} else {
list($effect_size, $effect_unit) = PMA_Util::formatByteDown(
$showtable['Data_length'] + $showtable['Index_length'],
$max_digits, $decimals
);
}
list($tot_size, $tot_unit) = PMA_Util::formatByteDown(
$showtable['Data_length'] + $showtable['Index_length'],
$max_digits, $decimals
);
if ($table_info_num_rows > 0) {
list($avg_size, $avg_unit) = PMA_Util::formatByteDown(
($showtable['Data_length'] + $showtable['Index_length'])
/ $showtable['Rows'],
6, 1
);
}
// Displays them
$odd_row = false;
$html_output .= '<fieldset>'
. '<legend>' . __('Information') . '</legend>'
. '<a id="showusage"></a>';
if (! $tbl_is_view && ! $db_is_system_schema) {
$html_output .= '<table id="tablespaceusage" class="data">'
. '<caption class="tblHeaders">' . __('Space usage') . '</caption>'
. '<tbody>';
$html_output .= PMA_getHtmlForSpaceUsageTableRow(
$odd_row, __('Data'), $data_size, $data_unit
);
$odd_row = !$odd_row;
if (isset($index_size)) {
$html_output .= PMA_getHtmlForSpaceUsageTableRow(
$odd_row, __('Index'), $index_size, $index_unit
);
$odd_row = !$odd_row;
}
if (isset($free_size)) {
$html_output .= PMA_getHtmlForSpaceUsageTableRow(
$odd_row, __('Overhead'), $free_size, $free_unit
);
$html_output .= PMA_getHtmlForSpaceUsageTableRow(
$odd_row, __('Effective'), $effect_size, $effect_unit
);
$odd_row = !$odd_row;
}
if (isset($tot_size) && $mergetable == false) {
$html_output .= PMA_getHtmlForSpaceUsageTableRow(
$odd_row, __('Total'), $tot_size, $tot_unit
);
$odd_row = !$odd_row;
}
// Optimize link if overhead
if (isset($free_size) && !PMA_DRIZZLE
&& ($tbl_storage_engine == 'MYISAM'
|| $tbl_storage_engine == 'ARIA'
|| $tbl_storage_engine == 'MARIA'
|| $tbl_storage_engine == 'BDB')
) {
$html_output .= PMA_getHtmlForOptimizeLink($url_query);
}
$html_output .= '</tbody>'
. '</table>';
}
$html_output .= getHtmlForRowStatsTable(
$showtable, $tbl_collation,
$is_innodb, $mergetable,
(isset ($avg_size) ? $avg_size : ''),
(isset ($avg_unit) ? $avg_unit : '')
);
$html_output .= '</fieldset>'
. '</div>';
return $html_output;
}
/**
* Displays HTML for changing one or more columns
*
* @param string $db database name
* @param string $table table name
* @param array $selected the selected columns
* @param string $action target script to call
*
* @return boolean $regenerate true if error occurred
*
*/
function PMA_displayHtmlForColumnChange($db, $table, $selected, $action)
{
// $selected comes from multi_submits.inc.php
if (empty($selected)) {
$selected[] = $_REQUEST['field'];
$selected_cnt = 1;
} else { // from a multiple submit
$selected_cnt = count($selected);
}
/**
* @todo optimize in case of multiple fields to modify
*/
$fields_meta = array();
for ($i = 0; $i < $selected_cnt; $i++) {
$fields_meta[] = $GLOBALS['dbi']->getColumns(
$db, $table, $selected[$i], true
);
}
$num_fields = count($fields_meta);
// set these globals because tbl_columns_definition_form.inc.php
// verifies them
// @todo: refactor tbl_columns_definition_form.inc.php so that it uses
// function params
$GLOBALS['action'] = 'tbl_structure.php';
$GLOBALS['num_fields'] = $num_fields;
// Get more complete field information.
// For now, this is done to obtain MySQL 4.1.2+ new TIMESTAMP options
// and to know when there is an empty DEFAULT value.
// Later, if the analyser returns more information, it
// could be executed to replace the info given by SHOW FULL COLUMNS FROM.
/**
* @todo put this code into a require()
* or maybe make it part of $GLOBALS['dbi']->getColumns();
*/
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25).
$show_create_table = $GLOBALS['dbi']->fetchValue(
'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
. PMA_Util::backquote($table),
0, 1
);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
unset($show_create_table);
/**
* Form for changing properties.
*/
include 'libraries/tbl_columns_definition_form.inc.php';
}
/**
* Verifies if some elements of a column have changed
*
* @param integer $i column index in the request
*
* @return boolean $alterTableNeeded true if we need to generate ALTER TABLE
*
*/
function PMA_columnNeedsAlterTable($i)
{
// these two fields are checkboxes so might not be part of the
// request; therefore we define them to avoid notices below
if (! isset($_REQUEST['field_null'][$i])) {
$_REQUEST['field_null'][$i] = 'NO';
}
if (! isset($_REQUEST['field_extra'][$i])) {
$_REQUEST['field_extra'][$i] = '';
}
// field_name does not follow the convention (corresponds to field_orig)
if ($_REQUEST['field_attribute'][$i] != $_REQUEST['field_attribute_orig'][$i]
|| $_REQUEST['field_collation'][$i] != $_REQUEST['field_collation_orig'][$i]
|| $_REQUEST['field_comments'][$i] != $_REQUEST['field_comments_orig'][$i]
|| $_REQUEST['field_default_value'][$i] != $_REQUEST['field_default_value_orig'][$i]
|| $_REQUEST['field_default_type'][$i] != $_REQUEST['field_default_type_orig'][$i]
|| $_REQUEST['field_extra'][$i] != $_REQUEST['field_extra_orig'][$i]
|| $_REQUEST['field_length'][$i] != $_REQUEST['field_length_orig'][$i]
|| $_REQUEST['field_name'][$i] != $_REQUEST['field_orig'][$i]
|| $_REQUEST['field_null'][$i] != $_REQUEST['field_null_orig'][$i]
|| $_REQUEST['field_type'][$i] != $_REQUEST['field_type_orig'][$i]
|| ! empty($_REQUEST['field_move_to'][$i])
) {
return true;
} else {
return false;
}
}
/**
* Update the table's structure based on $_REQUEST
*
* @param string $db database name
* @param string $table table name
*
* @return boolean $regenerate true if error occurred
*
*/
function PMA_updateColumns($db, $table)
{
$err_url = 'tbl_structure.php?' . PMA_URL_getCommon($db, $table);
$regenerate = false;
$field_cnt = count($_REQUEST['field_name']);
$key_fields = array();
$changes = array();
$pmatable = new PMA_Table($table, $db);
for ($i = 0; $i < $field_cnt; $i++) {
if (PMA_columnNeedsAlterTable($i)) {
$changes[] = 'CHANGE ' . PMA_Table::generateAlter(
isset($_REQUEST['field_orig'][$i])
? $_REQUEST['field_orig'][$i]
: '',
$_REQUEST['field_name'][$i],
$_REQUEST['field_type'][$i],
$_REQUEST['field_length'][$i],
$_REQUEST['field_attribute'][$i],
isset($_REQUEST['field_collation'][$i])
? $_REQUEST['field_collation'][$i]
: '',
isset($_REQUEST['field_null'][$i])
? $_REQUEST['field_null'][$i]
: 'NOT NULL',
$_REQUEST['field_default_type'][$i],
$_REQUEST['field_default_value'][$i],
isset($_REQUEST['field_extra'][$i])
? $_REQUEST['field_extra'][$i]
: false,
isset($_REQUEST['field_comments'][$i])
? $_REQUEST['field_comments'][$i]
: '',
$key_fields,
$i,
isset($_REQUEST['field_move_to'][$i])
? $_REQUEST['field_move_to'][$i]
: ''
);
// find the remembered sort expression
$sorted_col = $pmatable->getUiProp(PMA_Table::PROP_SORTED_COLUMN);
// if the old column name is part of the remembered sort expression
if (strpos(
$sorted_col,
PMA_Util::backquote($_REQUEST['field_orig'][$i])
) !== false) {
// delete the whole remembered sort expression
$pmatable->removeUiProp(PMA_Table::PROP_SORTED_COLUMN);
}
}
} // end for
$response = PMA_Response::getInstance();
if (count($changes) > 0) {
// Builds the primary keys statements and updates the table
$key_query = '';
/**
* this is a little bit more complex
*
* @todo if someone selects A_I when altering a column we need to check:
* - no other column with A_I
* - the column has an index, if not create one
*
*/
// To allow replication, we first select the db to use
// and then run queries on this db.
if (! $GLOBALS['dbi']->selectDb($db)) {
PMA_Util::mysqlDie(
$GLOBALS['dbi']->getError(),
'USE ' . PMA_Util::backquote($db) . ';',
'',
$err_url
);
}
$sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
$sql_query .= implode(', ', $changes) . $key_query;
$sql_query .= ';';
$result = $GLOBALS['dbi']->tryQuery($sql_query);
if ($result !== false) {
$message = PMA_Message::success(
__('Table %1$s has been altered successfully.')
);
$message->addParam($table);
$response->addHTML(
PMA_Util::getMessage($message, $sql_query, 'success')
);
} else {
// An error happened while inserting/updating a table definition
$response->isSuccess(false);
$response->addJSON(
'message',
PMA_Message::rawError(__('Query error') . ':<br />'.$GLOBALS['dbi']->getError())
);
$regenerate = true;
}
}
include_once 'libraries/transformations.lib.php';
// update field names in relation
if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) {
foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) {
if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) {
PMA_REL_renameField(
$db, $table, $fieldcontent,
$_REQUEST['field_name'][$fieldindex]
);
}
}
}
// update mime types
if (isset($_REQUEST['field_mimetype'])
&& is_array($_REQUEST['field_mimetype'])
&& $GLOBALS['cfg']['BrowseMIME']
) {
foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
if (isset($_REQUEST['field_name'][$fieldindex])
&& strlen($_REQUEST['field_name'][$fieldindex])
) {
PMA_setMIME(
$db, $table, $_REQUEST['field_name'][$fieldindex],
$mimetype,
$_REQUEST['field_transformation'][$fieldindex],
$_REQUEST['field_transformation_options'][$fieldindex]
);
}
}
}
return $regenerate;
}
/**
* Moves columns in the table's structure based on $_REQUEST
*
* @param string $db database name
* @param string $table table name
*
* @return void
*/
function PMA_moveColumns($db, $table)
{
$GLOBALS['dbi']->selectDb($db);
/*
* load the definitions for all columns
*/
$columns = $GLOBALS['dbi']->getColumnsFull($db, $table);
$column_names = array_keys($columns);
$changes = array();
$we_dont_change_keys = array();
// move columns from first to last
for ($i = 0, $l = count($_REQUEST['move_columns']); $i < $l; $i++) {
$column = $_REQUEST['move_columns'][$i];
// is this column already correctly placed?
if ($column_names[$i] == $column) {
continue;
}
// it is not, let's move it to index $i
$data = $columns[$column];
$extracted_columnspec = PMA_Util::extractColumnSpec($data['Type']);
if (isset($data['Extra'])
&& $data['Extra'] == 'on update CURRENT_TIMESTAMP'
) {
$extracted_columnspec['attribute'] = $data['Extra'];
unset($data['Extra']);
}
$current_timestamp = false;
if (($data['Type'] == 'timestamp' || $data['Type'] == 'datetime')
&& $data['Default'] == 'CURRENT_TIMESTAMP'
) {
$current_timestamp = true;
}
$default_type
= $data['Null'] === 'YES' && $data['Default'] === null
? 'NULL'
: ($current_timestamp
? 'CURRENT_TIMESTAMP'
: ($data['Default'] === null
? 'NONE'
: 'USER_DEFINED'));
$changes[] = 'CHANGE ' . PMA_Table::generateAlter(
$column,
$column,
strtoupper($extracted_columnspec['type']),
$extracted_columnspec['spec_in_brackets'],
$extracted_columnspec['attribute'],
isset($data['Collation']) ? $data['Collation'] : '',
$data['Null'] === 'YES' ? 'NULL' : 'NOT NULL',
$default_type,
$current_timestamp ? '' : $data['Default'],
isset($data['Extra']) && $data['Extra'] !== '' ? $data['Extra'] : false,
isset($data['COLUMN_COMMENT']) && $data['COLUMN_COMMENT'] !== ''
? $data['COLUMN_COMMENT'] : false,
$we_dont_change_keys,
$i,
$i === 0 ? '-first' : $column_names[$i - 1]
);
// update current column_names array, first delete old position
for ($j = 0, $ll = count($column_names); $j < $ll; $j++) {
if ($column_names[$j] == $column) {
unset($column_names[$j]);
}
}
// insert moved column
array_splice($column_names, $i, 0, $column);
}
$response = PMA_Response::getInstance();
if (empty($changes)) { // should never happen
$response->isSuccess(false);
exit;
}
$move_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ';
$move_query .= implode(', ', $changes);
// move columns
$GLOBALS['dbi']->tryQuery($move_query);
$tmp_error = $GLOBALS['dbi']->getError();
if ($tmp_error) {
$response->isSuccess(false);
$response->addJSON('message', PMA_Message::error($tmp_error));
} else {
$message = PMA_Message::success(
__('The columns have been moved successfully.')
);
$response->addJSON('message', $message);
$response->addJSON('columns', $column_names);
}
exit;
}
/**
* Get columns with unique index
*
* @param string $db database name
* @param string $table tablename
*
* @return array $columns_with_unique_index An array of columns with unique index,
* with $column name as the array key
*/
function PMA_getColumnsWithUniqueIndex($db ,$table)
{
$columns_with_unique_index = array();
foreach (PMA_Index::getFromTable($table, $db) as $index) {
if ($index->isUnique() && $index->getChoice() == 'UNIQUE') {
$columns = $index->getColumns();
foreach ($columns as $column_name => $dummy) {
$columns_with_unique_index[$column_name] = 1;
}
}
}
return $columns_with_unique_index;
}
/**
* Check column names for MySQL reserved words
*
* @param string $db database name
* @param string $table tablename
*
* @return array $messages array of PMA_Messages
*/
function PMA_getReservedWordColumnNameMessages($db ,$table)
{
$messages = array();
if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) {
$pma_table = new PMA_Table($table, $db);
$columns = $pma_table->getReservedColumnNames();
if (!empty($columns)) {
foreach ($columns as $column) {
$msg = PMA_message::notice(
__('The column name \'%s\' is a MySQL reserved keyword.')
);
$msg->addParam($column);
$messages[] = $msg;
}
}
}
return $messages;
}
/**
* Function to get the type of command for multiple field handling
*
* @return string
*/
function PMA_getMultipleFieldCommandType()
{
$submit_mult = null;
if (isset($_REQUEST['submit_mult_change_x'])) {
$submit_mult = 'change';
} elseif (isset($_REQUEST['submit_mult_drop_x'])) {
$submit_mult = 'drop';
} elseif (isset($_REQUEST['submit_mult_primary_x'])) {
$submit_mult = 'primary';
} elseif (isset($_REQUEST['submit_mult_index_x'])) {
$submit_mult = 'index';
} elseif (isset($_REQUEST['submit_mult_unique_x'])) {
$submit_mult = 'unique';
} elseif (isset($_REQUEST['submit_mult_spatial_x'])) {
$submit_mult = 'spatial';
} elseif (isset($_REQUEST['submit_mult_fulltext_x'])) {
$submit_mult = 'ftext';
} elseif (isset($_REQUEST['submit_mult_browse_x'])) {
$submit_mult = 'browse';
} elseif (isset($_REQUEST['submit_mult'])) {
$submit_mult = $_REQUEST['submit_mult'];
} elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == __('Yes')) {
$submit_mult = 'row_delete';
if (isset($_REQUEST['selected'])) {
$_REQUEST['selected_fld'] = $_REQUEST['selected'];
}
}
return $submit_mult;
}
/**
* Function to display table browse for selected columns
*
* @param string $db current database
* @param string $table current table
* @param string $goto goto page url
* @param string $pmaThemeImage URI of the pma theme image
*
* @return void
*/
function PMA_displayTableBrowseForSelectedColumns($db, $table, $goto,
$pmaThemeImage
) {
$GLOBALS['active_page'] = 'sql.php';
$sql_query = '';
foreach ($_REQUEST['selected_fld'] as $sval) {
if ($sql_query == '') {
$sql_query .= 'SELECT ' . PMA_Util::backquote($sval);
} else {
$sql_query .= ', ' . PMA_Util::backquote($sval);
}
}
$sql_query .= ' FROM ' . PMA_Util::backquote($db)
. '.' . PMA_Util::backquote($table);
// Parse and analyze the query
include_once 'libraries/parse_analyze.inc.php';
include_once 'libraries/sql.lib.php';
PMA_executeQueryAndSendQueryResponse(
$analyzed_sql_results, false, $db, $table, null, null, null, false,
null, null, null, null, $goto, $pmaThemeImage, null, null,
null, $sql_query, null, null
);
}
/**
* Function to check if a table is already in favorite list.
*
* @param string $db current database
* @param string $current_table current table
*
* @return true|false
*/
function PMA_checkFavoriteTable($db, $current_table)
{
foreach ($_SESSION['tmpval']['favorite_tables'][$GLOBALS['server']] as $key => $value) {
if ($value['db'] == $db && $value['table'] == $current_table) {
return true;
}
}
return false;
}
/**
* Get HTML for favorite anchor.
*
* @param string $db current database
* @param string $current_table current table
* @param array $titles titles
*
* @return $html_output
*/
function PMA_getHtmlForFavoriteAnchor($db, $current_table, $titles)
{
$html_output = '<a ';
$html_output .= 'id="' . md5($current_table)
. '_favorite_anchor" ';
$html_output .= 'class="ajax favorite_table_anchor';
// Check if current table is already in favorite list.
$already_favorite = PMA_checkFavoriteTable($db, $current_table);
$fav_params = array('db' => $db,
'ajax_request' => true,
'favorite_table' => $current_table,
(($already_favorite ? 'remove' : 'add') . '_favorite') => true
);
$fav_url = 'db_structure.php' . PMA_URL_getCommon($fav_params);
$html_output .= '" ';
$html_output .= 'href="' . $fav_url
. '" title="' . ($already_favorite ? __("Remove from Favorites")
: __("Add to Favorites"))
. '" data-favtargets="'
. md5($db . "." . $current_table)
. '" >'
. (!$already_favorite ? $titles['NoFavorite']
: $titles['Favorite']) . '</a>';
return $html_output;
}
?>
|