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: 2782: 2783: 2784: 2785: 2786: 2787: 2788: 2789: 2790: 2791: 2792: 2793: 2794: 2795: 2796: 2797: 2798: 2799: 2800: 2801: 2802: 2803: 2804: 2805: 2806: 2807: 2808: 2809: 2810: 2811: 2812: 2813: 2814: 2815: 2816: 2817: 2818: 2819: 2820: 2821: 2822: 2823: 2824: 2825: 2826: 2827: 2828: 2829: 2830: 2831: 2832: 2833: 2834: 2835: 2836: 2837: 2838: 2839: 2840: 2841: 2842: 2843: 2844: 2845: 2846: 2847: 2848: 2849: 2850: 2851: 2852: 2853: 2854: 2855: 2856: 2857: 2858: 2859: 2860: 2861: 2862: 2863: 2864: 2865: 2866: 2867: 2868: 2869: 2870: 2871: 2872: 2873: 2874: 2875: 2876: 2877: 2878: 2879: 2880: 2881: 2882: 2883: 2884: 2885: 2886: 2887: 2888: 2889: 2890: 2891: 2892: 2893: 2894: 2895: 2896: 2897: 2898: 2899: 2900: 2901: 2902: 2903: 2904: 2905: 2906: 2907: 2908: 2909: 2910: 2911: 2912: 2913: 2914: 2915: 2916: 2917: 2918: 2919: 2920: 2921: 2922: 2923: 2924: 2925: 2926: 2927: 2928: 2929: 2930: 2931: 2932: 2933: 2934: 2935: 2936: 2937: 2938: 2939: 2940: 2941: 2942: 2943: 2944: 2945: 2946: 2947: 2948: 2949: 2950: 2951: 2952: 2953: 2954: 2955: 2956: 2957: 2958: 2959: 2960: 2961: 2962: 2963: 2964: 2965: 2966: 2967: 2968: 2969: 2970: 2971: 2972: 2973: 2974: 2975: 2976: 2977: 2978: 2979: 2980: 2981: 2982: 2983: 2984: 2985: 2986: 2987: 2988: 2989: 2990: 2991: 2992: 2993: 2994: 2995: 2996: 2997: 2998: 2999: 3000: 3001: 3002: 3003: 3004: 3005: 3006: 3007: 3008: 3009: 3010: 3011: 3012: 3013: 3014: 3015: 3016: 3017: 3018: 3019: 3020: 3021: 3022: 3023: 3024: 3025: 3026: 3027: 3028: 3029: 3030: 3031: 3032: 3033: 3034: 3035: 3036: 3037: 3038: 3039: 3040: 3041: 3042: 3043: 3044: 3045: 3046: 3047: 3048: 3049: 3050: 3051: 3052: 3053: 3054: 3055: 3056: 3057: 3058: 3059: 3060: 3061: 3062: 3063: 3064: 3065: 3066: 3067: 3068: 3069: 3070: 3071: 3072: 3073: 3074: 3075: 3076: 3077: 3078: 3079: 3080: 3081: 3082: 3083: 3084: 3085: 3086: 3087: 3088: 3089: 3090: 3091: 3092: 3093: 3094: 3095: 3096: 3097: 3098: 3099: 3100: 3101: 3102: 3103: 3104: 3105: 3106: 3107: 3108: 3109: 3110: 3111: 3112: 3113: 3114: 3115: 3116: 3117: 3118: 3119: 3120: 3121: 3122: 3123: 3124: 3125: 3126: 3127: 3128: 3129: 3130: 3131: 3132: 3133: 3134: 3135: 3136: 3137: 3138: 3139: 3140: 3141: 3142: 3143: 3144: 3145: 3146: 3147: 3148: 3149: 3150: 3151: 3152: 3153: 3154: 3155: 3156: 3157: 3158: 3159: 3160: 3161: 3162: 3163: 3164: 3165: 3166: 3167: 3168: 3169: 3170: 3171: 3172: 3173: 3174: 3175: 3176: 3177: 3178: 3179: 3180: 3181: 3182: 3183: 3184: 3185: 3186: 3187: 3188: 3189: 3190: 3191: 3192: 3193: 3194: 3195: 3196: 3197: 3198: 3199: 3200: 3201: 3202: 3203: 3204: 3205: 3206: 3207: 3208: 3209: 3210: 3211: 3212: 3213: 3214: 3215: 3216: 3217: 3218: 3219: 3220: 3221: 3222: 3223: 3224: 3225: 3226: 3227: 3228: 3229: 3230: 3231: 3232: 3233: 3234: 3235: 3236: 3237: 3238: 3239: 3240: 3241: 3242: 3243: 3244: 3245: 3246: 3247: 3248: 3249: 3250: 3251: 3252: 3253: 3254: 3255: 3256: 3257: 3258: 3259: 3260: 3261: 3262: 3263: 3264: 3265: 3266: 3267: 3268: 3269: 3270: 3271: 3272: 3273: 3274: 3275: 3276: 3277: 3278: 3279: 3280: 3281: 3282: 3283: 3284: 3285: 3286: 3287: 3288: 3289: 3290: 3291: 3292: 3293: 3294: 3295: 3296: 3297: 3298: 3299: 3300: 3301: 3302: 3303: 3304: 3305: 3306: 3307: 3308: 3309: 3310: 3311: 3312: 3313: 3314: 3315: 3316: 3317: 3318: 3319: 3320: 3321: 3322: 3323: 3324: 3325: 3326: 3327: 3328: 3329: 3330: 3331: 3332: 3333: 3334: 3335: 3336: 3337: 3338: 3339: 3340: 3341: 3342: 3343: 3344: 3345: 3346: 3347: 3348: 3349: 3350: 3351: 3352: 3353: 3354: 3355: 3356: 3357: 3358: 3359: 3360: 3361: 3362: 3363: 3364: 3365: 3366: 3367: 3368: 3369: 3370: 3371: 3372: 3373: 3374: 3375: 3376: 3377: 3378: 3379: 3380: 3381: 3382: 3383: 3384: 3385: 3386: 3387: 3388: 3389: 3390: 3391: 3392: 3393: 3394: 3395: 3396: 3397: 3398: 3399: 3400: 3401: 3402: 3403: 3404: 3405: 3406: 3407: 3408: 3409: 3410: 3411: 3412: 3413: 3414: 3415: 3416: 3417: 3418: 3419: 3420: 3421: 3422: 3423: 3424: 3425: 3426: 3427: 3428: 3429: 3430: 3431: 3432: 3433: 3434: 3435: 3436: 3437: 3438: 3439: 3440: 3441: 3442: 3443: 3444: 3445: 3446: 3447: 3448: 3449: 3450: 3451: 3452: 3453: 3454: 3455: 3456: 3457: 3458: 3459: 3460: 3461: 3462: 3463: 3464: 3465: 3466: 3467: 3468: 3469: 3470: 3471: 3472: 3473: 3474: 3475: 3476: 3477: 3478: 3479: 3480: 3481: 3482: 3483: 3484: 3485: 3486: 3487: 3488: 3489: 3490:
<?php
if (!defined('SMF'))
die('No direct access...');
function summary($memID)
{
global $context, $memberContext, $txt, $modSettings, $user_profile, $sourcedir, $scripturl, $smcFunc;
if (!loadMemberContext($memID) || !isset($memberContext[$memID]))
fatal_lang_error('not_a_user', false, 404);
$context += array(
'page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']),
'can_send_pm' => allowedTo('pm_send'),
'can_have_buddy' => allowedTo('profile_extra_own') && !empty($modSettings['enable_buddylist']),
'can_issue_warning' => allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1,
'can_view_warning' => (allowedTo('moderate_forum') || allowedTo('issue_warning') || allowedTo('view_warning_any') || ($context['user']['is_owner'] && allowedTo('view_warning_own')) && $modSettings['warning_settings'][0] === 1)
);
$context['member'] = &$memberContext[$memID];
$context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
$context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['summary'],
'icon' => 'profile_hd.png'
);
list ($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning'])
$context['warning_status'] = $txt['profile_warning_is_muted'];
elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning'])
$context['warning_status'] = $txt['profile_warning_is_moderation'];
elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning'])
$context['warning_status'] = $txt['profile_warning_is_watch'];
$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
$context['member']['posts_per_day'] = $txt['not_applicable'];
else
$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
if (empty($context['member']['birth_date']) || substr($context['member']['birth_date'], 0, 4) < 1002)
{
$context['member'] += array(
'age' => $txt['not_applicable'],
'today_is_birthday' => false
);
}
else
{
list ($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
$datearray = getdate(forum_time());
$context['member'] += array(
'age' => $birth_year <= 1004 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - (($datearray['mon'] > $birth_month || ($datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day)) ? 0 : 1),
'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day && $birth_year > 1004
);
}
if (allowedTo('moderate_forum'))
{
if (preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup']))
$context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
else
$context['member']['hostname'] = '';
$context['can_see_ip'] = true;
}
else
$context['can_see_ip'] = false;
$context['member']['is_hidden'] = empty($user_profile[$memID]['show_online']);
$context['member']['show_last_login'] = allowedTo('admin_forum') || !$context['member']['is_hidden'];
if (!empty($modSettings['who_enabled']) && $context['member']['show_last_login'])
{
include_once($sourcedir . '/Who.php');
$action = determineActions($user_profile[$memID]['url']);
if ($action !== false)
$context['member']['action'] = $action;
}
if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum'))
{
$context['activate_type'] = $context['member']['is_activated'];
$context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
$context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
$context['token_check'] = 'profile-aa' . $memID;
createToken($context['token_check'], 'get');
$context['activate_link'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve;' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context[$context['token_check'] . '_token_var'] . '=' . $context[$context['token_check'] . '_token'];
}
$context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
if ($context['signature_enabled'])
{
list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
$sig_limits = explode(',', $sig_limits);
if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
addInlineCss('
.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
}
$context['member']['bans'] = array();
if (allowedTo('moderate_forum'))
{
$context['can_edit_ban'] = allowedTo('manage_bans');
$ban_query = array();
$ban_query_vars = array(
'time' => time(),
);
$ban_query[] = 'id_member = ' . $context['member']['id'];
$ban_query[] = ' {inet:ip} BETWEEN bi.ip_low and bi.ip_high';
$ban_query_vars['ip'] = $memberContext[$memID]['ip'];
if (!empty($context['member']['hostname']))
{
$ban_query[] = '({string:hostname} LIKE hostname)';
$ban_query_vars['hostname'] = $context['member']['hostname'];
}
if (strlen($context['member']['email']) != 0)
{
$ban_query[] = '({string:email} LIKE bi.email_address)';
$ban_query_vars['email'] = $context['member']['email'];
}
$request = $smcFunc['db_query']('', '
SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post,
bg.cannot_login, bg.reason
FROM {db_prefix}ban_items AS bi
INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
WHERE (' . implode(' OR ', $ban_query) . ')',
$ban_query_vars
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$ban_restrictions = array();
foreach (array('access', 'login', 'post') as $type)
if ($row['cannot_' . $type])
$ban_restrictions[] = $txt['ban_type_' . $type];
if (empty($ban_restrictions))
continue;
$ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
$context['member']['bans'][$row['id_ban_group']] = array(
'reason' => empty($row['reason']) ? '' : '<br><br><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'],
'cannot' => array(
'access' => !empty($row['cannot_access']),
'post' => !empty($row['cannot_post']),
'login' => !empty($row['cannot_login']),
),
'explanation' => $ban_explanation,
);
}
$smcFunc['db_free_result']($request);
}
loadCustomFields($memID);
$context['print_custom_fields'] = array();
if (!empty($context['custom_fields']))
foreach ($context['custom_fields'] as $custom)
$context['print_custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
}
function fetch_alerts($memID, $to_fetch = false, $limit = 0, $offset = 0, $with_avatar = false, $show_links = false)
{
global $smcFunc, $txt, $scripturl, $user_info, $user_profile, $modSettings, $context;
$alertIDs = is_bool($to_fetch) ? array() : array_filter(array_map('intval', (array) $to_fetch));
$memID = (int) $memID;
$unread = $to_fetch === false;
$limit = max(0, (int) $limit);
$offset = !empty($alertIDs) ? 0 : max(0, (int) $offset);
$with_avatar = !empty($with_avatar);
$show_links = !empty($show_links);
$alerts = array();
$senders = array();
$profiles = array();
$profile_alerts = array();
$possible_msgs = array();
$possible_topics = array();
$request = $smcFunc['db_query']('', '
SELECT a.id_alert, a.alert_time, a.is_read, a.extra,
a.content_type, a.content_id, a.content_action,
mem.id_member AS sender_id, COALESCE(mem.real_name, a.member_name) AS sender_name' . ($with_avatar ? ',
mem.email_address AS sender_email, mem.avatar AS sender_avatar, f.filename AS sender_filename' : '') . '
FROM {db_prefix}user_alerts AS a
LEFT JOIN {db_prefix}members AS mem ON (a.id_member_started = mem.id_member)' . ($with_avatar ? '
LEFT JOIN {db_prefix}attachments AS f ON (mem.id_member = f.id_member)' : '') . '
WHERE a.id_member = {int:id_member}' . ($unread ? '
AND a.is_read = 0' : '') . (!empty($alertIDs) ? '
AND a.id_alert IN ({array_int:alertIDs})' : '') . '
ORDER BY id_alert DESC' . (!empty($limit) ? '
LIMIT {int:limit}' : '') . (!empty($offset) ?'
OFFSET {int:offset}' : ''),
array(
'id_member' => $memID,
'alertIDs' => $alertIDs,
'limit' => $limit,
'offset' => $offset,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$id_alert = array_shift($row);
$row['time'] = timeformat($row['alert_time']);
$row['extra'] = !empty($row['extra']) ? $smcFunc['json_decode']($row['extra'], true) : array();
$alerts[$id_alert] = $row;
if (!empty($row['sender_email']))
{
$senders[$row['sender_id']] = array(
'email' => $row['sender_email'],
'avatar' => $row['sender_avatar'],
'filename' => $row['sender_filename'],
);
}
if ($row['content_type'] == 'profile')
{
$profiles[] = $row['content_id'];
$profile_alerts[] = $id_alert;
}
if ($row['content_type'] == 'msg')
{
$alerts[$id_alert]['visible'] = false;
$possible_msgs[$id_alert] = $row['content_id'];
}
elseif (in_array($row['content_type'], array('topic', 'board')))
{
$alerts[$id_alert]['visible'] = false;
$possible_topics[$id_alert] = $row['content_id'];
}
else
$alerts[$id_alert]['visible'] = true;
$alerts[$id_alert]['show_links'] = $show_links || (isset($row['extra']['show_links']) && $row['extra']['show_links']);
$alerts[$id_alert]['icon'] = set_alert_icon($alerts[$id_alert]);
}
$smcFunc['db_free_result']($request);
if (!empty($profiles))
loadMemberData($profiles, 'minimal');
if ($with_avatar)
{
foreach ($senders as $sender_id => $sender)
$senders[$sender_id]['avatar'] = set_avatar_data($sender);
$context['avatar_url'] = $modSettings['avatar_url'];
}
loadLanguage('Alerts');
$formats['msg_msg'] = array(
'required' => array('content_subject', 'topic', 'msg'),
'link' => '<a href="{scripturl}?topic=%2$d.msg%3$d#msg%3$d">%1$s</a>',
'text' => '<strong>%1$s</strong>',
);
$formats['topic_msg'] = array(
'required' => array('content_subject', 'topic', 'topic_suffix'),
'link' => '<a href="{scripturl}?topic=%2$d.%3$s">%1$s</a>',
'text' => '<strong>%1$s</strong>',
);
$formats['board_msg'] = array(
'required' => array('board_name', 'board'),
'link' => '<a href="{scripturl}?board=%2$d.0">%1$s</a>',
'text' => '<strong>%1$s</strong>',
);
$formats['profile_msg'] = array(
'required' => array('user_name', 'user_id'),
'link' => '<a href="{scripturl}?action=profile;u=%2$d">%1$s</a>',
'text' => '<strong>%1$s</strong>',
);
call_integration_hook('integrate_fetch_alerts', array(&$alerts, &$formats));
foreach ($formats as &$format_type)
$format_type = str_replace('{scripturl}', $scripturl, $format_type);
if ((!isset($user_info['query_see_board']) || $user_info['id'] != $memID) && (!empty($possible_msgs) || !empty($possible_topics)))
$qb = build_query_board($memID);
else
$qb['query_see_board'] = '{query_see_board}';
if (!empty($possible_msgs))
{
$flipped_msgs = array();
foreach ($possible_msgs as $id_alert => $id_msg)
{
if (!isset($flipped_msgs[$id_msg]))
$flipped_msgs[$id_msg] = array();
$flipped_msgs[$id_msg][] = $id_alert;
}
$request = $smcFunc['db_query']('', '
SELECT m.id_msg, m.id_topic, m.subject, b.id_board, b.name AS board_name
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
WHERE ' . $qb['query_see_board'] . '
AND m.id_msg IN ({array_int:msgs})
ORDER BY m.id_msg',
array(
'msgs' => $possible_msgs,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
foreach ($flipped_msgs[$row['id_msg']] as $id_alert)
{
$alerts[$id_alert]['content_data'] = $row;
$alerts[$id_alert]['visible'] = true;
}
}
$smcFunc['db_free_result']($request);
}
if (!empty($possible_topics))
{
$flipped_topics = array();
foreach ($possible_topics as $id_alert => $id_topic)
{
if (!isset($flipped_topics[$id_topic]))
$flipped_topics[$id_topic] = array();
$flipped_topics[$id_topic][] = $id_alert;
}
$request = $smcFunc['db_query']('', '
SELECT m.id_msg, t.id_topic, m.subject, b.id_board, b.name AS board_name
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
WHERE ' . $qb['query_see_board'] . '
AND t.id_topic IN ({array_int:topics})',
array(
'topics' => $possible_topics,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
foreach ($flipped_topics[$row['id_topic']] as $id_alert)
{
$alerts[$id_alert]['content_data'] = $row;
$alerts[$id_alert]['visible'] = true;
}
}
$smcFunc['db_free_result']($request);
}
foreach ($alerts as $id_alert => $dummy)
{
if (!$alerts[$id_alert]['visible'])
{
unset($alerts[$id_alert]);
continue;
}
else
unset($alerts[$id_alert]['visible']);
if (!empty($alerts[$id_alert]['text']))
continue;
$alert = &$alerts[$id_alert];
if (!empty($alert['content_data']))
{
$data = $alert['content_data'];
$patterns = array();
$replacements = array();
foreach (array('msg', 'topic', 'board') as $item)
{
if (isset($data['id_' . $item]))
{
$separator = $item == 'msg' ? '=?' : '=';
if (isset($alert['extra']['content_link']) && strpos($alert['extra']['content_link'], $item . $separator) !== false && strpos($alert['extra']['content_link'], $item . $separator . $data['id_' . $item]) === false)
{
$patterns[] = '/\b' . $item . $separator . '\d+/';
$replacements[] = $item . $separator . $data['id_' . $item];
}
$alert['extra'][$item] = $data['id_' . $item];
}
}
if (!empty($patterns))
$alert['extra']['content_link'] = preg_replace($patterns, $replacements, $alert['extra']['content_link']);
if (isset($data['subject']))
$alert['extra']['content_subject'] = $data['subject'];
if (isset($data['board_name']))
$alert['extra']['board_name'] = $data['board_name'];
unset($alert['content_data']);
}
if (isset($possible_topics[$id_alert]) && in_array($alert['content_action'], array('reply', 'topic', 'unapproved_reply')))
$alert['extra']['topic_suffix'] = 'new;topicseen#new';
elseif (isset($alert['extra']['topic']))
$alert['extra']['topic_suffix'] = '0';
if (in_array($id_alert, $profile_alerts))
{
if (empty($alert['extra']['user_id']))
$alert['extra']['user_id'] = $alert['content_id'];
if (isset($user_profile[$alert['extra']['user_id']]))
$alert['extra']['user_name'] = $user_profile[$alert['extra']['user_id']]['real_name'];
}
$sender_id = !empty($alert['sender_id']) ? $alert['sender_id'] : 0;
if (isset($user_profile[$sender_id]))
$alert['sender_name'] = $user_profile[$sender_id]['real_name'];
if ($with_avatar && !empty($senders[$sender_id]))
$alert['sender'] = $senders[$sender_id];
foreach ($formats as $msg_type => $format_info)
{
$msg_values = array_replace(
array_fill_keys($format_info['required'], ''),
array_intersect_key($alert['extra'], array_flip($format_info['required']))
);
if (!in_array('', $msg_values))
$alert['extra'][$msg_type] = vsprintf($formats[$msg_type][$alert['show_links'] ? 'link' : 'text'], $msg_values);
elseif (in_array($msg_type, array('msg_msg', 'topic_msg', 'board_msg')))
$alert['extra'][$msg_type] = $txt[$msg_type == 'board_msg' ? 'board_na' : 'topic_na'];
else
$alert['extra'][$msg_type] = '(' . $txt['not_applicable'] . ')';
}
if ($alert['content_type'] == 'paidsubs' && isset($alert['extra']['end_time']))
{
if ($alert['extra']['end_time'] < time())
$alert['content_action'] = 'expired';
$alert['extra']['end_time'] = timeformat($alert['extra']['end_time']);
}
$alert['target_href'] = '';
if (isset($alert['extra']['content_link']))
$alert['target_href'] = $alert['extra']['content_link'];
elseif (isset($alert['extra']['report_link']))
$alert['target_href'] = $scripturl . $alert['extra']['report_link'];
if (empty($alert['target_href']) && in_array($alert['content_action'], array('register_approval', 'group_request', 'buddy_request')))
{
switch ($alert['content_action'])
{
case 'register_approval':
$alert['target_href'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve';
break;
case 'group_request':
$alert['target_href'] = $scripturl . '?action=moderate;area=groups;sa=requests';
break;
case 'buddy_request':
if (!empty($alert['id_member_started']))
$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
break;
default:
break;
}
}
if (empty($alert['target_href']) && in_array($alert['content_type'], array('msg', 'member', 'event')))
{
switch ($alert['content_type'])
{
case 'msg':
if (!empty($alert['content_id']))
$alert['target_href'] = $scripturl . '?msg=' . $alert['content_id'];
break;
case 'member':
if (!empty($alert['id_member_started']))
$alert['target_href'] = $scripturl . '?action=profile;u=' . $alert['id_member_started'];
break;
case 'event':
if (!empty($alert['extra']['event_id']))
$alert['target_href'] = $scripturl . '?action=calendar;event=' . $alert['extra']['event_id'];
break;
default:
break;
}
}
$string = 'alert_' . $alert['content_type'] . '_' . $alert['content_action'];
if (!isset($txt[$string]))
{
if (strpos($alert['content_action'], 'unapproved_') === 0)
$string = 'alert_' . $alert['content_action'];
if ($alert['content_type'] === 'member' && in_array($alert['content_action'], array('report', 'report_reply')))
$string = 'alert_profile_' . $alert['content_action'];
if ($alert['content_type'] === 'member' && $alert['content_action'] === 'buddy_request')
$string = 'alert_buddy_' . $alert['content_action'];
}
if (isset($txt[$string]))
{
$substitutions = array(
'{scripturl}' => $scripturl,
'{member_link}' => !empty($sender_id) && $alert['show_links'] ? '<a href="' . $scripturl . '?action=profile;u=' . $sender_id . '">' . $alert['sender_name'] . '</a>' : '<strong>' . $alert['sender_name'] . '</strong>',
);
if (is_array($alert['extra']))
{
foreach ($alert['extra'] as $k => $v)
$substitutions['{' . $k . '}'] = $v;
}
$alert['text'] = strtr($txt[$string], $substitutions);
}
unset($alert);
}
return $alerts;
}
function showAlerts($memID)
{
global $context, $smcFunc, $txt, $sourcedir, $scripturl, $options;
require_once($sourcedir . '/Profile-Modify.php');
if (!empty($_REQUEST['alert']))
{
$alert_id = (int) $_REQUEST['alert'];
$alerts = fetch_alerts($memID, $alert_id);
$alert = array_pop($alerts);
if (empty($alert['target_href']))
redirectexit('action=profile;area=showalerts');
alert_mark($memID, $alert_id, 1);
redirectexit($alert['target_href']);
}
$maxIndex = 10;
$context['start'] = (int) isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$count = alert_count($memID);
if ($context['start'] > $count)
$context['start'] = $count - ($count % $maxIndex);
else
$context['start'] = $context['start'] - ($context['start'] % $maxIndex);
$context['alerts'] = fetch_alerts($memID, true, $maxIndex, $context['start'], true, true);
$toMark = false;
$action = '';
$context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1;
$context['pagination'] = constructPageIndex($scripturl . '?action=profile;area=showalerts;u=' . $memID, $context['start'], $count, $maxIndex, false);
if ($context['showCheckboxes'])
addInlineJavaScript('
$(function(){
$(\'#select_all\').on(\'change\', function() {
var checkboxes = $(\'ul.quickbuttons\').find(\':checkbox\');
if($(this).prop(\'checked\')) {
checkboxes.prop(\'checked\', true);
}
else {
checkboxes.prop(\'checked\', false);
}
});
});', true);
foreach ($context['alerts'] as $id => $alert)
{
$context['alerts'][$id]['quickbuttons'] = array(
'delete' => array(
'label' => $txt['delete'],
'href' => $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=remove;aid=' . $id . ';' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : ''),
'javascript' => 'class="you_sure"',
'icon' => 'remove_button'
),
'mark' => array(
'label' => $alert['is_read'] != 0 ? $txt['mark_unread'] : $txt['mark_read_short'],
'href' => $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=' . ($alert['is_read'] != 0 ? 'unread' : 'read') . ';aid=' . $id . ';' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : ''),
'icon' => $alert['is_read'] != 0 ? 'unread_button' : 'read_button',
),
'view' => array(
'label' => $txt['view'],
'href' => $alert['target_href'],
'icon' => 'move',
),
'quickmod' => array(
'content' => '<input type="checkbox" name="mark[' . $id . ']" value="' . $id . '">',
'show' => $context['showCheckboxes']
)
);
}
$context['alert_purge_link'] = $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=showalerts;do=purge;' . $context['session_var'] . '=' . $context['session_id'] . (!empty($context['start']) ? ';start=' . $context['start'] : '');
if (!empty($_SESSION['update_message']))
{
$context['update_message'] = $txt['profile_updated_own'];
unset($_SESSION['update_message']);
}
if (isset($_GET['save']) && !empty($_POST['mark']))
{
$toMark = array_map('intval', (array) $_POST['mark']);
$action = !empty($_POST['mark_as']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_POST['mark_as'])) : '';
}
if (!empty($_GET['do']) && !empty($_GET['aid']))
{
$toMark = (int) $_GET['aid'];
$action = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_GET['do']));
}
elseif (!empty($_GET['do']) && $_GET['do'] === 'purge')
$action = 'purge';
if (!empty($action) && (!empty($toMark) || $action === 'purge'))
{
checkSession('request');
if ($action == 'remove')
alert_delete($toMark, $memID);
elseif ($action == 'purge')
alert_purge($memID);
else
alert_mark($memID, $toMark, $action == 'read' ? 1 : 0);
$_SESSION['update_message'] = true;
redirectexit('action=profile;area=showalerts;u=' . $memID . (!empty($context['start']) ? ';start=' . $context['start'] : ''));
}
}
function showPosts($memID)
{
global $txt, $user_info, $scripturl, $modSettings, $options;
global $context, $user_profile, $sourcedir, $smcFunc, $board;
$context['start'] = (int) $_REQUEST['start'];
$context['current_member'] = $memID;
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['showPosts'],
'description' => $txt['showPosts_help'],
'icon' => 'profile_hd.png',
'tabs' => array(
'messages' => array(
),
'topics' => array(
),
'unwatchedtopics' => array(
),
'attach' => array(
),
),
);
$title = array(
'attach' => 'Attachments',
'unwatchedtopics' => 'Unwatched',
'topics' => 'Topics'
);
if (isset($_GET['sa']) && array_key_exists($_GET['sa'], $title))
$context['page_title'] = $txt['show' . $title[$_GET['sa']]];
else
$context['page_title'] = $txt['showPosts'];
$context['page_title'] .= ' - ' . $user_profile[$memID]['real_name'];
if (!empty($context['load_average']) && !empty($modSettings['loadavg_show_posts']) && $context['load_average'] >= $modSettings['loadavg_show_posts'])
fatal_lang_error('loadavg_show_posts_disabled', false);
if (isset($_GET['sa']) && $_GET['sa'] == 'attach')
return showAttachments($memID);
elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics')
return showUnwatched($memID);
$context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
if (isset($_GET['delete']) && !$context['is_topics'])
{
checkSession('get');
$request = $smcFunc['db_query']('', '
SELECT subject, id_member, id_topic, id_board
FROM {db_prefix}messages
WHERE id_msg = {int:id_msg}',
array(
'id_msg' => (int) $_GET['delete'],
)
);
$info = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if (empty($info))
redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
require_once($sourcedir . '/RemoveTopic.php');
removeMessage((int) $_GET['delete']);
if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
logAction('delete', array('topic' => $info[2], 'subject' => $info[0], 'member' => $info[1], 'board' => $info[3]));
redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
}
if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount']))
$_REQUEST['viewscount'] = '10';
if ($context['is_topics'])
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}topics AS t' . '
WHERE {query_see_topic_board}
AND t.id_member_started = {int:current_member}' . (!empty($board) ? '
AND t.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND t.approved = {int:is_approved}'),
array(
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
)
);
else
$request = $smcFunc['db_query']('', '
SELECT COUNT(id_msg)
FROM {db_prefix}messages AS m
WHERE {query_see_message_board} AND m.id_member = {int:current_member}' . (!empty($board) ? '
AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND m.approved = {int:is_approved}'),
array(
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
)
);
list ($msgCount) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
SELECT MIN(id_msg), MAX(id_msg)
FROM {db_prefix}messages AS m
WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
AND m.id_board = {int:board}' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND m.approved = {int:is_approved}'),
array(
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
)
);
list ($min_msg_member, $max_msg_member) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$range_limit = '';
if ($context['is_topics'])
$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
else
$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
$maxIndex = $maxPerPage;
$context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : '') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
$context['current_page'] = $context['start'] / $maxIndex;
$start = $context['start'];
$reverse = $_REQUEST['start'] > $msgCount / 2;
if ($reverse)
{
$maxIndex = $msgCount < $context['start'] + $maxPerPage + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : $maxPerPage;
$start = $msgCount < $context['start'] + $maxPerPage + 1 || $msgCount < $context['start'] + $maxPerPage ? 0 : $msgCount - $context['start'] - $maxPerPage;
}
if ($msgCount > 1000)
{
$margin = floor(($max_msg_member - $min_msg_member) * (($start + $maxPerPage) / $msgCount) + .1 * ($max_msg_member - $min_msg_member));
if ($context['is_topics'])
{
$margin *= 5;
$range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
}
else
$range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
}
$looped = false;
while (true)
{
if ($context['is_topics'])
{
$request = $smcFunc['db_query']('', '
SELECT
b.id_board, b.name AS bname, c.id_cat, c.name AS cname, t.id_member_started, t.id_first_msg, t.id_last_msg,
t.approved, m.body, m.smileys_enabled, m.subject, m.poster_time, m.id_topic, m.id_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE t.id_member_started = {int:current_member}' . (!empty($board) ? '
AND t.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
AND ' . $range_limit) . '
AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
ORDER BY t.id_first_msg ' . ($reverse ? 'ASC' : 'DESC') . '
LIMIT {int:start}, {int:max}',
array(
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
'start' => $start,
'max' => $maxIndex,
)
);
}
else
{
$request = $smcFunc['db_query']('', '
SELECT
b.id_board, b.name AS bname, c.id_cat, c.name AS cname, m.id_topic, m.id_msg,
t.id_member_started, t.id_first_msg, t.id_last_msg, m.body, m.smileys_enabled,
m.subject, m.poster_time, m.approved
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
AND b.id_board = {int:board}' : '') . (empty($range_limit) ? '' : '
AND ' . $range_limit) . '
AND {query_see_board}' . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND t.approved = {int:is_approved} AND m.approved = {int:is_approved}') . '
ORDER BY m.id_msg ' . ($reverse ? 'ASC' : 'DESC') . '
LIMIT {int:start}, {int:max}',
array(
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
'start' => $start,
'max' => $maxIndex,
)
);
}
if ($smcFunc['db_num_rows']($request) === $maxIndex || $looped || $range_limit == '')
break;
$looped = true;
$range_limit = '';
}
$counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
$context['posts'] = array();
$board_ids = array('own' => array(), 'any' => array());
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['body']);
censorText($row['subject']);
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
$context['posts'][$counter += $reverse ? -1 : 1] = array(
'body' => $row['body'],
'counter' => $counter,
'category' => array(
'name' => $row['cname'],
'id' => $row['id_cat']
),
'board' => array(
'name' => $row['bname'],
'id' => $row['id_board']
),
'topic' => $row['id_topic'],
'subject' => $row['subject'],
'start' => 'msg' . $row['id_msg'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'id' => $row['id_msg'],
'can_reply' => false,
'can_mark_notify' => !$context['user']['is_guest'],
'can_delete' => false,
'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()),
'approved' => $row['approved'],
'css_class' => $row['approved'] ? 'windowbg' : 'approvebg',
);
if ($user_info['id'] == $row['id_member_started'])
$board_ids['own'][$row['id_board']][] = $counter;
$board_ids['any'][$row['id_board']][] = $counter;
}
$smcFunc['db_free_result']($request);
if ($reverse)
$context['posts'] = array_reverse($context['posts'], true);
if ($context['is_topics'])
$permissions = array(
'own' => array(
'post_reply_own' => 'can_reply',
),
'any' => array(
'post_reply_any' => 'can_reply',
)
);
else
$permissions = array(
'own' => array(
'post_reply_own' => 'can_reply',
'delete_own' => 'can_delete',
),
'any' => array(
'post_reply_any' => 'can_reply',
'delete_any' => 'can_delete',
)
);
$boards_can = boardsAllowedTo(array_keys(iterator_to_array(
new RecursiveIteratorIterator(new RecursiveArrayIterator($permissions)))
), true, false);
foreach ($permissions as $type => $list)
{
foreach ($list as $permission => $allowed)
{
$boards = $boards_can[$permission];
if (!empty($boards) && $boards[0] == 0)
$boards = array_keys($board_ids[$type]);
foreach ($boards as $board_id)
{
if (!isset($board_ids[$type][$board_id]))
continue;
foreach ($board_ids[$type][$board_id] as $counter)
$context['posts'][$counter][$allowed] = true;
}
}
}
$quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
foreach ($context['posts'] as $counter => $dummy)
{
$context['posts'][$counter]['can_delete'] &= $context['posts'][$counter]['delete_possible'];
$context['posts'][$counter]['can_quote'] = $context['posts'][$counter]['can_reply'] && $quote_enabled;
}
call_integration_hook('integrate_profile_showPosts');
foreach ($context['posts'] as $key => $post)
{
$context['posts'][$key]['quickbuttons'] = array(
'reply' => array(
'label' => $txt['reply'],
'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'],
'icon' => 'reply_button',
'show' => $post['can_reply']
),
'quote' => array(
'label' => $txt['quote_action'],
'href' => $scripturl.'?action=post;topic='.$post['topic'].'.'.$post['start'].';quote='.$post['id'],
'icon' => 'quote',
'show' => $post['can_quote']
),
'remove' => array(
'label' => $txt['remove'],
'href' => $scripturl.'?action=deletemsg;msg='.$post['id'].';topic='.$post['topic'].';profile;u='.$context['member']['id'].';start='.$context['start'].';'.$context['session_var'].'='.$context['session_id'],
'javascript' => 'data-confirm="'.$txt['remove_message'].'" class="you_sure"',
'icon' => 'remove_button',
'show' => $post['can_delete']
)
);
}
}
function showAttachments($memID)
{
global $txt, $scripturl, $modSettings;
global $sourcedir;
$boardsAllowed = boardsAllowedTo('view_attachments');
if (empty($boardsAllowed))
$boardsAllowed = array(-1);
require_once($sourcedir . '/Subs-List.php');
$listOptions = array(
'id' => 'attachments',
'width' => '100%',
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['show_attachments_none'],
'base_href' => $scripturl . '?action=profile;area=showposts;sa=attach;u=' . $memID,
'default_sort_col' => 'filename',
'get_items' => array(
'function' => 'list_getAttachments',
'params' => array(
$boardsAllowed,
$memID,
),
),
'get_count' => array(
'function' => 'list_getNumAttachments',
'params' => array(
$boardsAllowed,
$memID,
),
),
'data_check' => array(
'class' => function($data)
{
return $data['approved'] ? '' : 'approvebg';
}
),
'columns' => array(
'filename' => array(
'header' => array(
'value' => $txt['show_attach_filename'],
'class' => 'lefttext',
'style' => 'width: 25%;',
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $scripturl . '?action=dlattach;topic=%1$d.0;attach=%2$d">%3$s</a>',
'params' => array(
'topic' => true,
'id' => true,
'filename' => false,
),
),
),
'sort' => array(
'default' => 'a.filename',
'reverse' => 'a.filename DESC',
),
),
'downloads' => array(
'header' => array(
'value' => $txt['show_attach_downloads'],
'style' => 'width: 12%;',
),
'data' => array(
'db' => 'downloads',
'comma_format' => true,
),
'sort' => array(
'default' => 'a.downloads',
'reverse' => 'a.downloads DESC',
),
),
'subject' => array(
'header' => array(
'value' => $txt['message'],
'class' => 'lefttext',
'style' => 'width: 30%;',
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $scripturl . '?msg=%1$d">%2$s</a>',
'params' => array(
'msg' => true,
'subject' => false,
),
),
),
'sort' => array(
'default' => 'm.subject',
'reverse' => 'm.subject DESC',
),
),
'posted' => array(
'header' => array(
'value' => $txt['show_attach_posted'],
'class' => 'lefttext',
),
'data' => array(
'db' => 'posted',
'timeformat' => true,
),
'sort' => array(
'default' => 'm.poster_time',
'reverse' => 'm.poster_time DESC',
),
),
),
);
createList($listOptions);
}
function list_getAttachments($start, $items_per_page, $sort, $boardsAllowed, $memID)
{
global $smcFunc, $board, $modSettings, $context;
$request = $smcFunc['db_query']('', '
SELECT a.id_attach, a.id_msg, a.filename, a.downloads, a.approved, m.id_msg, m.id_topic,
m.id_board, m.poster_time, m.subject, b.name
FROM {db_prefix}attachments AS a
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
WHERE a.attachment_type = {int:attachment_type}
AND a.id_msg != {int:no_message}
AND m.id_member = {int:current_member}' . (!empty($board) ? '
AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND m.approved = {int:is_approved}') . '
ORDER BY {raw:sort}
LIMIT {int:offset}, {int:limit}',
array(
'boards_list' => $boardsAllowed,
'attachment_type' => 0,
'no_message' => 0,
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
'sort' => $sort,
'offset' => $start,
'limit' => $items_per_page,
)
);
$attachments = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$attachments[] = array(
'id' => $row['id_attach'],
'filename' => $row['filename'],
'downloads' => $row['downloads'],
'subject' => censorText($row['subject']),
'posted' => $row['poster_time'],
'msg' => $row['id_msg'],
'topic' => $row['id_topic'],
'board' => $row['id_board'],
'board_name' => $row['name'],
'approved' => $row['approved'],
);
$smcFunc['db_free_result']($request);
return $attachments;
}
function list_getNumAttachments($boardsAllowed, $memID)
{
global $board, $smcFunc, $modSettings, $context;
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}attachments AS a
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})
WHERE a.attachment_type = {int:attachment_type}
AND a.id_msg != {int:no_message}
AND m.id_member = {int:current_member}' . (!empty($board) ? '
AND b.id_board = {int:board}' : '') . (!in_array(0, $boardsAllowed) ? '
AND b.id_board IN ({array_int:boards_list})' : '') . (!$modSettings['postmod_active'] || $context['user']['is_owner'] ? '' : '
AND m.approved = {int:is_approved}'),
array(
'boards_list' => $boardsAllowed,
'attachment_type' => 0,
'no_message' => 0,
'current_member' => $memID,
'is_approved' => 1,
'board' => $board,
)
);
list ($attachCount) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return $attachCount;
}
function showUnwatched($memID)
{
global $txt, $user_info, $scripturl, $modSettings, $context, $options, $sourcedir;
if ($user_info['id'] != $memID)
return;
require_once($sourcedir . '/Subs-List.php');
$listOptions = array(
'id' => 'unwatched_topics',
'width' => '100%',
'items_per_page' => (empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page'])) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'],
'no_items_label' => $txt['unwatched_topics_none'],
'base_href' => $scripturl . '?action=profile;area=showposts;sa=unwatchedtopics;u=' . $memID,
'default_sort_col' => 'started_on',
'get_items' => array(
'function' => 'list_getUnwatched',
'params' => array(
$memID,
),
),
'get_count' => array(
'function' => 'list_getNumUnwatched',
'params' => array(
$memID,
),
),
'columns' => array(
'subject' => array(
'header' => array(
'value' => $txt['subject'],
'class' => 'lefttext',
'style' => 'width: 30%;',
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $scripturl . '?topic=%1$d.0">%2$s</a>',
'params' => array(
'id_topic' => false,
'subject' => false,
),
),
),
'sort' => array(
'default' => 'm.subject',
'reverse' => 'm.subject DESC',
),
),
'started_by' => array(
'header' => array(
'value' => $txt['started_by'],
'style' => 'width: 15%;',
),
'data' => array(
'db' => 'started_by',
),
'sort' => array(
'default' => 'mem.real_name',
'reverse' => 'mem.real_name DESC',
),
),
'started_on' => array(
'header' => array(
'value' => $txt['on'],
'class' => 'lefttext',
'style' => 'width: 20%;',
),
'data' => array(
'db' => 'started_on',
'timeformat' => true,
),
'sort' => array(
'default' => 'm.poster_time',
'reverse' => 'm.poster_time DESC',
),
),
'last_post_by' => array(
'header' => array(
'value' => $txt['last_post'],
'style' => 'width: 15%;',
),
'data' => array(
'db' => 'last_post_by',
),
'sort' => array(
'default' => 'mem.real_name',
'reverse' => 'mem.real_name DESC',
),
),
'last_post_on' => array(
'header' => array(
'value' => $txt['on'],
'class' => 'lefttext',
'style' => 'width: 20%;',
),
'data' => array(
'db' => 'last_post_on',
'timeformat' => true,
),
'sort' => array(
'default' => 'm.poster_time',
'reverse' => 'm.poster_time DESC',
),
),
),
);
createList($listOptions);
$context['sub_template'] = 'show_list';
$context['default_list'] = 'unwatched_topics';
}
function list_getUnwatched($start, $items_per_page, $sort, $memID)
{
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT lt.id_topic
FROM {db_prefix}log_topics as lt
LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
LEFT JOIN {db_prefix}messages as m ON (t.id_first_msg = m.id_msg)' . (in_array($sort, array('mem.real_name', 'mem.real_name DESC', 'mem.poster_time', 'mem.poster_time DESC')) ? '
LEFT JOIN {db_prefix}members as mem ON (m.id_member = mem.id_member)' : '') . '
WHERE lt.id_member = {int:current_member}
AND unwatched = 1
AND {query_see_message_board}
ORDER BY {raw:sort}
LIMIT {int:offset}, {int:limit}',
array(
'current_member' => $memID,
'sort' => $sort,
'offset' => $start,
'limit' => $items_per_page,
)
);
$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topics[] = $row['id_topic'];
$smcFunc['db_free_result']($request);
$topicsInfo = array();
if (!empty($topics))
{
$request = $smcFunc['db_query']('', '
SELECT mf.subject, mf.poster_time as started_on, COALESCE(memf.real_name, mf.poster_name) as started_by, ml.poster_time as last_post_on, COALESCE(meml.real_name, ml.poster_name) as last_post_by, t.id_topic
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member)
WHERE t.id_topic IN ({array_int:topics})',
array(
'topics' => $topics,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$topicsInfo[] = $row;
$smcFunc['db_free_result']($request);
}
return $topicsInfo;
}
function list_getNumUnwatched($memID)
{
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}log_topics as lt
LEFT JOIN {db_prefix}topics as t ON (lt.id_topic = t.id_topic)
WHERE lt.id_member = {int:current_member}
AND lt.unwatched = 1
AND {query_see_topic_board}',
array(
'current_member' => $memID,
)
);
list ($unwatchedCount) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return $unwatchedCount;
}
function statPanel($memID)
{
global $txt, $scripturl, $context, $user_profile, $user_info, $modSettings, $smcFunc;
$context['page_title'] = $txt['statPanel_showStats'] . ' ' . $user_profile[$memID]['real_name'];
if (!empty($context['load_average']) && !empty($modSettings['loadavg_userstats']) && $context['load_average'] >= $modSettings['loadavg_userstats'])
fatal_lang_error('loadavg_userstats_disabled', false);
$timeDays = floor($user_profile[$memID]['total_time_logged_in'] / 86400);
$timeHours = floor(($user_profile[$memID]['total_time_logged_in'] % 86400) / 3600);
$context['time_logged_in'] = ($timeDays > 0 ? $timeDays . $txt['total_time_logged_days'] : '') . ($timeHours > 0 ? $timeHours . $txt['total_time_logged_hours'] : '') . floor(($user_profile[$memID]['total_time_logged_in'] % 3600) / 60) . $txt['total_time_logged_minutes'];
$context['num_posts'] = comma_format($user_profile[$memID]['posts']);
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['statPanel_generalStats'] . ' - ' . $context['member']['name'],
'icon' => 'stats_info.png'
);
$result = $smcFunc['db_query']('', '
SELECT COUNT(*), COUNT( CASE WHEN id_poll != {int:no_poll} THEN 1 ELSE NULL END )
FROM {db_prefix}topics
WHERE id_member_started = {int:current_member}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND id_board != {int:recycle_board}' : ''),
array(
'current_member' => $memID,
'recycle_board' => $modSettings['recycle_board'],
'no_poll' => 0,
)
);
list ($context['num_topics'], $context['num_polls']) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);
$result = $smcFunc['db_query']('distinct_poll_votes', '
SELECT COUNT(DISTINCT id_poll)
FROM {db_prefix}log_polls
WHERE id_member = {int:current_member}',
array(
'current_member' => $memID,
)
);
list ($context['num_votes']) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);
$context['num_topics'] = comma_format($context['num_topics']);
$context['num_polls'] = comma_format($context['num_polls']);
$context['num_votes'] = comma_format($context['num_votes']);
$result = $smcFunc['db_query']('', '
SELECT
b.id_board, MAX(b.name) AS name, MAX(b.num_posts) AS num_posts, COUNT(*) AS message_count
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
WHERE m.id_member = {int:current_member}
AND b.count_posts = {int:count_enabled}
AND {query_see_board}
GROUP BY b.id_board
ORDER BY message_count DESC
LIMIT 10',
array(
'current_member' => $memID,
'count_enabled' => 0,
)
);
$context['popular_boards'] = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$context['popular_boards'][$row['id_board']] = array(
'id' => $row['id_board'],
'posts' => $row['message_count'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
'posts_percent' => $user_profile[$memID]['posts'] == 0 ? 0 : ($row['message_count'] * 100) / $user_profile[$memID]['posts'],
'total_posts' => $row['num_posts'],
'total_posts_member' => $user_profile[$memID]['posts'],
);
}
$smcFunc['db_free_result']($result);
$result = $smcFunc['db_query']('profile_board_stats', '
SELECT
b.id_board, MAX(b.name) AS name, b.num_posts, COUNT(*) AS message_count,
CASE WHEN COUNT(*) > MAX(b.num_posts) THEN 1 ELSE COUNT(*) / MAX(b.num_posts) END * 100 AS percentage
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
WHERE m.id_member = {int:current_member}
AND {query_see_board}
GROUP BY b.id_board, b.num_posts
ORDER BY percentage DESC
LIMIT 10',
array(
'current_member' => $memID,
)
);
$context['board_activity'] = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$context['board_activity'][$row['id_board']] = array(
'id' => $row['id_board'],
'posts' => $row['message_count'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
'percent' => comma_format((float) $row['percentage'], 2),
'posts_percent' => (float) $row['percentage'],
'total_posts' => $row['num_posts'],
);
}
$smcFunc['db_free_result']($result);
$result = $smcFunc['db_query']('user_activity_by_time', '
SELECT
HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
COUNT(*) AS post_count
FROM {db_prefix}messages
WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
AND id_topic > {int:top_ten_thousand_topics}' : '') . '
GROUP BY hour',
array(
'current_member' => $memID,
'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
)
);
$maxPosts = $realPosts = 0;
$context['posts_by_time'] = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$row['hour'] = (int) $row['hour'];
$maxPosts = max($row['post_count'], $maxPosts);
$realPosts += $row['post_count'];
$context['posts_by_time'][$row['hour']] = array(
'hour' => $row['hour'],
'hour_format' => stripos($user_info['time_format'], '%p') === false ? $row['hour'] : date('g a', mktime($row['hour'])),
'posts' => $row['post_count'],
'posts_percent' => 0,
'is_last' => $row['hour'] == 23,
);
}
$smcFunc['db_free_result']($result);
if ($maxPosts > 0)
for ($hour = 0; $hour < 24; $hour++)
{
if (!isset($context['posts_by_time'][$hour]))
$context['posts_by_time'][$hour] = array(
'hour' => $hour,
'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
'posts' => 0,
'posts_percent' => 0,
'relative_percent' => 0,
'is_last' => $hour == 23,
);
else
{
$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $realPosts);
$context['posts_by_time'][$hour]['relative_percent'] = round(($context['posts_by_time'][$hour]['posts'] * 100) / $maxPosts);
}
}
ksort($context['posts_by_time']);
$context['text_stats'] = array(
'total_time_online' => array(
'text' => $context['time_logged_in'],
),
'total_posts' => array(
'text' => $context['num_posts'] . ' ' . $txt['statPanel_posts'],
'url' => $scripturl . '?action=profile;area=showposts;sa=messages;u=' . $memID
),
'total_topics' => array(
'text' => $context['num_topics'] . ' ' . $txt['statPanel_topics'],
'url' => $scripturl . '?action=profile;area=showposts;sa=topics;u=' . $memID
),
'users_polls' => array(
'text' => $context['num_polls'] . ' ' . $txt['statPanel_polls'],
),
'users_votes' => array(
'text' => $context['num_votes'] . ' ' . $txt['statPanel_votes']
)
);
call_integration_hook('integrate_profile_stats', array($memID, &$context['text_stats']));
}
function tracking($memID)
{
global $context, $txt, $modSettings, $user_profile;
$subActions = array(
'activity' => array('trackActivity', $txt['trackActivity'], 'moderate_forum'),
'ip' => array('TrackIP', $txt['trackIP'], 'moderate_forum'),
'edits' => array('trackEdits', $txt['trackEdits'], 'moderate_forum'),
'groupreq' => array('trackGroupReq', $txt['trackGroupRequests'], 'approve_group_requests'),
'logins' => array('TrackLogins', $txt['trackLogins'], 'moderate_forum'),
);
foreach ($subActions as $sa => $action)
{
if (!allowedTo($action[2]))
unset($subActions[$sa]);
}
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['tracking'],
'description' => $txt['tracking_description'],
'icon' => 'profile_hd.png',
'tabs' => array(
'activity' => array(),
'ip' => array(),
'edits' => array(),
'groupreq' => array(),
'logins' => array(),
),
);
if (empty($modSettings['userlog_enabled']))
unset($context[$context['profile_menu_name']]['tab_data']['edits'], $subActions['edits']);
if (empty($modSettings['show_group_membership']))
unset($context[$context['profile_menu_name']]['tab_data']['groupreq'], $subActions['groupreq']);
if (empty($subActions))
fatal_lang_error('no_access', false);
$keys = array_keys($subActions);
$default = array_shift($keys);
$context['tracking_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : $default;
$context['page_title'] = $txt['trackUser'] . ' - ' . $subActions[$context['tracking_area']][1] . ' - ' . $user_profile[$memID]['real_name'];
$context['sub_template'] = $subActions[$context['tracking_area']][0];
$call = call_helper($subActions[$context['tracking_area']][0], true);
if (!empty($call))
call_user_func($call, $memID);
}
function trackActivity($memID)
{
global $scripturl, $txt, $modSettings, $sourcedir;
global $user_profile, $context, $smcFunc;
isAllowedTo('moderate_forum');
$context['last_ip'] = $user_profile[$memID]['member_ip'];
if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
$context['member']['name'] = $user_profile[$memID]['real_name'];
$listOptions = array(
'id' => 'track_user_list',
'title' => $txt['errors_by'] . ' ' . $context['member']['name'],
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['no_errors_from_user'],
'base_href' => $scripturl . '?action=profile;area=tracking;sa=user;u=' . $memID,
'default_sort_col' => 'date',
'get_items' => array(
'function' => 'list_getUserErrors',
'params' => array(
'le.id_member = {int:current_member}',
array('current_member' => $memID),
),
),
'get_count' => array(
'function' => 'list_getUserErrorCount',
'params' => array(
'id_member = {int:current_member}',
array('current_member' => $memID),
),
),
'columns' => array(
'ip_address' => array(
'header' => array(
'value' => $txt['ip_address'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=%1$s;u=' . $memID . '">%1$s</a>',
'params' => array(
'ip' => false,
),
),
),
'sort' => array(
'default' => 'le.ip',
'reverse' => 'le.ip DESC',
),
),
'message' => array(
'header' => array(
'value' => $txt['message'],
),
'data' => array(
'sprintf' => array(
'format' => '%1$s<br><a href="%2$s">%2$s</a>',
'params' => array(
'message' => false,
'url' => false,
),
),
),
),
'date' => array(
'header' => array(
'value' => $txt['date'],
),
'data' => array(
'db' => 'time',
),
'sort' => array(
'default' => 'le.id_error DESC',
'reverse' => 'le.id_error',
),
),
),
'additional_rows' => array(
array(
'position' => 'after_title',
'value' => $txt['errors_desc'],
),
),
);
require_once($sourcedir . '/Subs-List.php');
createList($listOptions);
if ($modSettings['totalMessages'] > 50000 && $user_profile[$memID]['posts'] > 500)
{
$request = $smcFunc['db_query']('', '
SELECT MAX(id_msg)
FROM {db_prefix}messages AS m
WHERE m.id_member = {int:current_member}',
array(
'current_member' => $memID,
)
);
list ($max_msg_member) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$min_msg_member = max(0, $max_msg_member - $user_profile[$memID]['posts'] * 3);
}
$ips = array(
$user_profile[$memID]['member_ip'],
$user_profile[$memID]['member_ip2'],
);
$request = $smcFunc['db_query']('', '
SELECT poster_ip
FROM {db_prefix}messages
WHERE id_member = {int:current_member}
' . (isset($min_msg_member) ? '
AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
GROUP BY poster_ip',
array(
'current_member' => $memID,
'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
)
);
$context['ips'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . inet_dtop($row['poster_ip']) . ';u=' . $memID . '">' . inet_dtop($row['poster_ip']) . '</a>';
$ips[] = inet_dtop($row['poster_ip']);
}
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
SELECT COUNT(*) AS error_count, ip
FROM {db_prefix}log_errors
WHERE id_member = {int:current_member}
GROUP BY ip',
array(
'current_member' => $memID,
)
);
$context['error_ips'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['ip'] = inet_dtop($row['ip']);
$context['error_ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['ip'] . ';u=' . $memID . '">' . $row['ip'] . '</a>';
$ips[] = $row['ip'];
}
$smcFunc['db_free_result']($request);
$ips = array_unique($ips);
$context['members_in_range'] = array();
if (!empty($ips))
{
$request = $smcFunc['db_query']('', '
SELECT DISTINCT mem.id_member
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.poster_ip IN ({array_inet:ip_list})
AND mem.id_member != {int:current_member}',
array(
'current_member' => $memID,
'ip_list' => $ips,
)
);
$message_members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$message_members[] = $row['id_member'];
$smcFunc['db_free_result']($request);
if (!empty($message_members))
{
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name
FROM {db_prefix}members
WHERE id_member IN ({array_int:message_members})',
array(
'message_members' => $message_members,
'ip_list' => $ips,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
$smcFunc['db_free_result']($request);
}
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name
FROM {db_prefix}members
WHERE id_member != {int:current_member}
AND member_ip IN ({array_inet:ip_list})',
array(
'current_member' => $memID,
'ip_list' => $ips,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['members_in_range'][$row['id_member']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
$smcFunc['db_free_result']($request);
}
}
function list_getUserErrorCount($where, $where_vars = array())
{
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT COUNT(id_error)
FROM {db_prefix}log_errors
WHERE ' . $where,
$where_vars
);
list ($count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return (int) $count;
}
function list_getUserErrors($start, $items_per_page, $sort, $where, $where_vars = array())
{
global $smcFunc, $txt, $scripturl;
$request = $smcFunc['db_query']('', '
SELECT
le.log_time, le.ip, le.url, le.message, COALESCE(mem.id_member, 0) AS id_member,
COALESCE(mem.real_name, {string:guest_title}) AS display_name, mem.member_name
FROM {db_prefix}log_errors AS le
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = le.id_member)
WHERE ' . $where . '
ORDER BY {raw:sort}
LIMIT {int:start}, {int:max}',
array_merge($where_vars, array(
'guest_title' => $txt['guest_title'],
'sort' => $sort,
'start' => $start,
'max' => $items_per_page,
))
);
$error_messages = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$error_messages[] = array(
'ip' => inet_dtop($row['ip']),
'member_link' => $row['id_member'] > 0 ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>' : $row['display_name'],
'message' => strtr($row['message'], array('<span class="remove">' => '', '</span>' => '')),
'url' => $row['url'],
'time' => timeformat($row['log_time']),
'timestamp' => forum_time(true, $row['log_time']),
);
$smcFunc['db_free_result']($request);
return $error_messages;
}
function list_getIPMessageCount($where, $where_vars = array())
{
global $smcFunc, $user_info;
$request = $smcFunc['db_query']('', '
SELECT COUNT(id_msg)
FROM {db_prefix}messages AS m
WHERE {query_see_message_board} AND ' . $where,
$where_vars
);
list ($count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return (int) $count;
}
function list_getIPMessages($start, $items_per_page, $sort, $where, $where_vars = array())
{
global $smcFunc, $scripturl, $user_info;
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.poster_ip, COALESCE(mem.real_name, m.poster_name) AS display_name, mem.id_member,
m.subject, m.poster_time, m.id_topic, m.id_board
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE {query_see_message_board} AND ' . $where . '
ORDER BY {raw:sort}
LIMIT {int:start}, {int:max}',
array_merge($where_vars, array(
'sort' => $sort,
'start' => $start,
'max' => $items_per_page,
))
);
$messages = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$messages[] = array(
'ip' => inet_dtop($row['poster_ip']),
'member_link' => empty($row['id_member']) ? $row['display_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>',
'board' => array(
'id' => $row['id_board'],
'href' => $scripturl . '?board=' . $row['id_board']
),
'topic' => $row['id_topic'],
'id' => $row['id_msg'],
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time'])
);
$smcFunc['db_free_result']($request);
return $messages;
}
function TrackIP($memID = 0)
{
global $user_profile, $scripturl, $txt, $user_info, $modSettings, $sourcedir;
global $context, $options, $smcFunc;
isAllowedTo('moderate_forum');
if ($memID == 0)
{
$context['ip'] = ip2range($user_info['ip']);
loadTemplate('Profile');
loadLanguage('Profile');
$context['sub_template'] = 'trackIP';
$context['page_title'] = $txt['profile'];
$context['base_url'] = $scripturl . '?action=trackip';
}
else
{
$context['ip'] = ip2range($user_profile[$memID]['member_ip']);
$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
}
if (isset($_REQUEST['searchip']))
$context['ip'] = ip2range(trim($_REQUEST['searchip']));
if (count($context['ip']) !== 2)
fatal_lang_error('invalid_tracking_ip', false);
$ip_string = array('{inet:ip_address_low}', '{inet:ip_address_high}');
$fields = array(
'ip_address_low' => $context['ip']['low'],
'ip_address_high' => $context['ip']['high'],
);
$ip_var = $context['ip'];
if ($context['ip']['low'] !== $context['ip']['high'])
$context['ip'] = $context['ip']['low'] . ' - ' . $context['ip']['high'];
else
$context['ip'] = $context['ip']['low'];
if (empty($context['tracking_area']))
$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name AS display_name, member_ip
FROM {db_prefix}members
WHERE member_ip >= ' . $ip_string[0] . ' and member_ip <= ' . $ip_string[1],
$fields
);
$context['ips'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['ips'][inet_dtop($row['member_ip'])][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['display_name'] . '</a>';
$smcFunc['db_free_result']($request);
ksort($context['ips']);
$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
require_once($sourcedir . '/Subs-List.php');
$listOptions = array(
'id' => 'track_message_list',
'title' => $txt['messages_from_ip'] . ' ' . $context['ip'],
'start_var_name' => 'messageStart',
'items_per_page' => $maxPerPage,
'no_items_label' => $txt['no_messages_from_ip'],
'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
'default_sort_col' => 'date',
'get_items' => array(
'function' => 'list_getIPMessages',
'params' => array(
'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1],
$fields,
),
),
'get_count' => array(
'function' => 'list_getIPMessageCount',
'params' => array(
'm.poster_ip >= ' . $ip_string[0] . ' and m.poster_ip <= ' . $ip_string[1],
$fields,
),
),
'columns' => array(
'ip_address' => array(
'header' => array(
'value' => $txt['ip_address'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
'params' => array(
'ip' => false,
),
),
),
'sort' => array(
'default' => 'm.poster_ip',
'reverse' => 'm.poster_ip DESC',
),
),
'poster' => array(
'header' => array(
'value' => $txt['poster'],
),
'data' => array(
'db' => 'member_link',
),
),
'subject' => array(
'header' => array(
'value' => $txt['subject'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $scripturl . '?topic=%1$s.msg%2$s#msg%2$s" rel="nofollow">%3$s</a>',
'params' => array(
'topic' => false,
'id' => false,
'subject' => false,
),
),
),
),
'date' => array(
'header' => array(
'value' => $txt['date'],
),
'data' => array(
'db' => 'time',
),
'sort' => array(
'default' => 'm.id_msg DESC',
'reverse' => 'm.id_msg',
),
),
),
'additional_rows' => array(
array(
'position' => 'after_title',
'value' => $txt['messages_from_ip_desc'],
),
),
);
createList($listOptions);
$listOptions = array(
'id' => 'track_user_list',
'title' => $txt['errors_from_ip'] . ' ' . $context['ip'],
'start_var_name' => 'errorStart',
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['no_errors_from_ip'],
'base_href' => $context['base_url'] . ';searchip=' . $context['ip'],
'default_sort_col' => 'date2',
'get_items' => array(
'function' => 'list_getUserErrors',
'params' => array(
'le.ip >= ' . $ip_string[0] . ' and le.ip <= ' . $ip_string[1],
$fields,
),
),
'get_count' => array(
'function' => 'list_getUserErrorCount',
'params' => array(
'ip >= ' . $ip_string[0] . ' and ip <= ' . $ip_string[1],
$fields,
),
),
'columns' => array(
'ip_address2' => array(
'header' => array(
'value' => $txt['ip_address'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a>',
'params' => array(
'ip' => false,
),
),
),
'sort' => array(
'default' => 'le.ip',
'reverse' => 'le.ip DESC',
),
),
'display_name' => array(
'header' => array(
'value' => $txt['display_name'],
),
'data' => array(
'db' => 'member_link',
),
),
'message' => array(
'header' => array(
'value' => $txt['message'],
),
'data' => array(
'sprintf' => array(
'format' => '%1$s<br><a href="%2$s">%2$s</a>',
'params' => array(
'message' => false,
'url' => false,
),
),
),
),
'date2' => array(
'header' => array(
'value' => $txt['date'],
),
'data' => array(
'db' => 'time',
),
'sort' => array(
'default' => 'le.id_error DESC',
'reverse' => 'le.id_error',
),
),
),
'additional_rows' => array(
array(
'position' => 'after_title',
'value' => $txt['errors_from_ip_desc'],
),
),
);
createList($listOptions);
$context['additional_track_lists'] = array();
call_integration_hook('integrate_profile_trackip', array($ip_string, $ip_var));
$context['single_ip'] = ($ip_var['low'] === $ip_var['high']);
if ($context['single_ip'])
{
$context['whois_servers'] = array(
'apnic' => array(
'name' => $txt['whois_apnic'],
'url' => 'https://wq.apnic.net/apnic-bin/whois.pl?searchtext=' . $context['ip'],
),
'arin' => array(
'name' => $txt['whois_arin'],
'url' => 'https://whois.arin.net/rest/ip/' . $context['ip'],
),
'lacnic' => array(
'name' => $txt['whois_lacnic'],
'url' => 'https://lacnic.net/cgi-bin/lacnic/whois?query=' . $context['ip'],
),
'ripe' => array(
'name' => $txt['whois_ripe'],
'url' => 'https://apps.db.ripe.net/search/query.html?searchtext=' . $context['ip'],
),
);
}
}
function TrackLogins($memID = 0)
{
global $scripturl, $txt, $sourcedir, $context;
require_once($sourcedir . '/Subs-List.php');
if ($memID == 0)
$context['base_url'] = $scripturl . '?action=trackip';
else
$context['base_url'] = $scripturl . '?action=profile;area=tracking;sa=ip;u=' . $memID;
$listOptions = array(
'id' => 'track_logins_list',
'title' => $txt['trackLogins'],
'no_items_label' => $txt['trackLogins_none_found'],
'base_href' => $context['base_url'],
'get_items' => array(
'function' => 'list_getLogins',
'params' => array(
'id_member = {int:current_member}',
array('current_member' => $memID),
),
),
'get_count' => array(
'function' => 'list_getLoginCount',
'params' => array(
'id_member = {int:current_member}',
array('current_member' => $memID),
),
),
'columns' => array(
'time' => array(
'header' => array(
'value' => $txt['date'],
),
'data' => array(
'db' => 'time',
),
),
'ip' => array(
'header' => array(
'value' => $txt['ip_address'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . $context['base_url'] . ';searchip=%1$s">%1$s</a> (<a href="' . $context['base_url'] . ';searchip=%2$s">%2$s</a>) ',
'params' => array(
'ip' => false,
'ip2' => false
),
),
),
),
),
'additional_rows' => array(
array(
'position' => 'after_title',
'value' => $txt['trackLogins_desc'],
),
),
);
createList($listOptions);
$context['sub_template'] = 'show_list';
$context['default_list'] = 'track_logins_list';
}
function list_getLoginCount($where, $where_vars = array())
{
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT COUNT(*) AS message_count
FROM {db_prefix}member_logins
WHERE id_member = {int:id_member}',
array(
'id_member' => $where_vars['current_member'],
)
);
list ($count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return (int) $count;
}
function list_getLogins($start, $items_per_page, $sort, $where, $where_vars = array())
{
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT time, ip, ip2
FROM {db_prefix}member_logins
WHERE id_member = {int:id_member}
ORDER BY time DESC',
array(
'id_member' => $where_vars['current_member'],
)
);
$logins = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$logins[] = array(
'time' => timeformat($row['time']),
'ip' => inet_dtop($row['ip']),
'ip2' => inet_dtop($row['ip2']),
);
$smcFunc['db_free_result']($request);
return $logins;
}
function trackEdits($memID)
{
global $scripturl, $txt, $modSettings, $sourcedir, $context, $smcFunc;
require_once($sourcedir . '/Subs-List.php');
$request = $smcFunc['db_query']('', '
SELECT col_name, field_name, bbc
FROM {db_prefix}custom_fields',
array(
)
);
$context['custom_field_titles'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['custom_field_titles']['customfield_' . $row['col_name']] = array(
'title' => $row['field_name'],
'parse_bbc' => $row['bbc'],
);
$smcFunc['db_free_result']($request);
$listOptions = array(
'id' => 'edit_list',
'title' => $txt['trackEdits'],
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['trackEdit_no_edits'],
'base_href' => $scripturl . '?action=profile;area=tracking;sa=edits;u=' . $memID,
'default_sort_col' => 'time',
'get_items' => array(
'function' => 'list_getProfileEdits',
'params' => array(
$memID,
),
),
'get_count' => array(
'function' => 'list_getProfileEditCount',
'params' => array(
$memID,
),
),
'columns' => array(
'action' => array(
'header' => array(
'value' => $txt['trackEdit_action'],
),
'data' => array(
'db' => 'action_text',
),
),
'before' => array(
'header' => array(
'value' => $txt['trackEdit_before'],
),
'data' => array(
'db' => 'before',
),
),
'after' => array(
'header' => array(
'value' => $txt['trackEdit_after'],
),
'data' => array(
'db' => 'after',
),
),
'time' => array(
'header' => array(
'value' => $txt['date'],
),
'data' => array(
'db' => 'time',
),
'sort' => array(
'default' => 'id_action DESC',
'reverse' => 'id_action',
),
),
'applicator' => array(
'header' => array(
'value' => $txt['trackEdit_applicator'],
),
'data' => array(
'db' => 'member_link',
),
),
),
);
createList($listOptions);
$context['sub_template'] = 'show_list';
$context['default_list'] = 'edit_list';
}
function list_getProfileEditCount($memID)
{
global $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT COUNT(*) AS edit_count
FROM {db_prefix}log_actions
WHERE id_log = {int:log_type}
AND id_member = {int:owner}',
array(
'log_type' => 2,
'owner' => $memID,
)
);
list ($edit_count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return (int) $edit_count;
}
function list_getProfileEdits($start, $items_per_page, $sort, $memID)
{
global $smcFunc, $txt, $scripturl, $context;
$request = $smcFunc['db_query']('', '
SELECT
id_action, id_member, ip, log_time, action, extra
FROM {db_prefix}log_actions
WHERE id_log = {int:log_type}
AND id_member = {int:owner}
ORDER BY {raw:sort}
LIMIT {int:start}, {int:max}',
array(
'log_type' => 2,
'owner' => $memID,
'sort' => $sort,
'start' => $start,
'max' => $items_per_page,
)
);
$edits = array();
$members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$extra = $smcFunc['json_decode']($row['extra'], true);
if (!empty($extra['applicator']))
$members[] = $extra['applicator'];
if (isset($txt['trackEdit_action_' . $row['action']]))
$action_text = $txt['trackEdit_action_' . $row['action']];
elseif (isset($txt[$row['action']]))
$action_text = $txt[$row['action']];
elseif (isset($context['custom_field_titles'][$row['action']]))
$action_text = $context['custom_field_titles'][$row['action']]['title'];
else
$action_text = $row['action'];
$parse_bbc = isset($context['custom_field_titles'][$row['action']]) && $context['custom_field_titles'][$row['action']]['parse_bbc'] ? true : false;
$edits[] = array(
'id' => $row['id_action'],
'ip' => inet_dtop($row['ip']),
'id_member' => !empty($extra['applicator']) ? $extra['applicator'] : 0,
'member_link' => $txt['trackEdit_deleted_member'],
'action' => $row['action'],
'action_text' => $action_text,
'before' => !empty($extra['previous']) ? ($parse_bbc ? parse_bbc($extra['previous']) : $extra['previous']) : '',
'after' => !empty($extra['new']) ? ($parse_bbc ? parse_bbc($extra['new']) : $extra['new']) : '',
'time' => timeformat($row['log_time']),
);
}
$smcFunc['db_free_result']($request);
if (!empty($members))
{
$request = $smcFunc['db_query']('', '
SELECT
id_member, real_name
FROM {db_prefix}members
WHERE id_member IN ({array_int:members})',
array(
'members' => $members,
)
);
$members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$members[$row['id_member']] = $row['real_name'];
$smcFunc['db_free_result']($request);
foreach ($edits as $key => $value)
if (isset($members[$value['id_member']]))
$edits[$key]['member_link'] = '<a href="' . $scripturl . '?action=profile;u=' . $value['id_member'] . '">' . $members[$value['id_member']] . '</a>';
}
return $edits;
}
function trackGroupReq($memID)
{
global $scripturl, $txt, $modSettings, $sourcedir, $context;
require_once($sourcedir . '/Subs-List.php');
$listOptions = array(
'id' => 'request_list',
'title' => sprintf($txt['trackGroupRequests_title'], $context['member']['name']),
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['requested_none'],
'base_href' => $scripturl . '?action=profile;area=tracking;sa=groupreq;u=' . $memID,
'default_sort_col' => 'time_applied',
'get_items' => array(
'function' => 'list_getGroupRequests',
'params' => array(
$memID,
),
),
'get_count' => array(
'function' => 'list_getGroupRequestsCount',
'params' => array(
$memID,
),
),
'columns' => array(
'group' => array(
'header' => array(
'value' => $txt['requested_group'],
),
'data' => array(
'db' => 'group_name',
),
),
'group_reason' => array(
'header' => array(
'value' => $txt['requested_group_reason'],
),
'data' => array(
'db' => 'group_reason',
),
),
'time_applied' => array(
'header' => array(
'value' => $txt['requested_group_time'],
),
'data' => array(
'db' => 'time_applied',
'timeformat' => true,
),
'sort' => array(
'default' => 'time_applied DESC',
'reverse' => 'time_applied',
),
),
'outcome' => array(
'header' => array(
'value' => $txt['requested_group_outcome'],
),
'data' => array(
'db' => 'outcome',
),
),
),
);
createList($listOptions);
$context['sub_template'] = 'show_list';
$context['default_list'] = 'request_list';
}
function list_getGroupRequestsCount($memID)
{
global $smcFunc, $user_info;
$request = $smcFunc['db_query']('', '
SELECT COUNT(*) AS req_count
FROM {db_prefix}log_group_requests AS lgr
WHERE id_member = {int:memID}
AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']),
array(
'memID' => $memID,
)
);
list ($report_count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return (int) $report_count;
}
function list_getGroupRequests($start, $items_per_page, $sort, $memID)
{
global $smcFunc, $txt, $scripturl, $user_info;
$groupreq = array();
$request = $smcFunc['db_query']('', '
SELECT
lgr.id_group, mg.group_name, mg.online_color, lgr.time_applied, lgr.reason, lgr.status,
ma.id_member AS id_member_acted, COALESCE(ma.member_name, lgr.member_name_acted) AS act_name, lgr.time_acted, lgr.act_reason
FROM {db_prefix}log_group_requests AS lgr
LEFT JOIN {db_prefix}members AS ma ON (lgr.id_member_acted = ma.id_member)
INNER JOIN {db_prefix}membergroups AS mg ON (lgr.id_group = mg.id_group)
WHERE lgr.id_member = {int:memID}
AND ' . ($user_info['mod_cache']['gq'] == '1=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . '
ORDER BY {raw:sort}
LIMIT {int:start}, {int:max}',
array(
'memID' => $memID,
'sort' => $sort,
'start' => $start,
'max' => $items_per_page,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$this_req = array(
'group_name' => empty($row['online_color']) ? $row['group_name'] : '<span style="color:' . $row['online_color'] . '">' . $row['group_name'] . '</span>',
'group_reason' => $row['reason'],
'time_applied' => $row['time_applied'],
);
switch ($row['status'])
{
case 0:
$this_req['outcome'] = $txt['outcome_pending'];
break;
case 1:
$member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>';
$this_req['outcome'] = sprintf($txt['outcome_approved'], $member_link, timeformat($row['time_acted']));
break;
case 2:
$member_link = empty($row['id_member_acted']) ? $row['act_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_acted'] . '">' . $row['act_name'] . '</a>';
$this_req['outcome'] = sprintf(!empty($row['act_reason']) ? $txt['outcome_refused_reason'] : $txt['outcome_refused'], $member_link, timeformat($row['time_acted']), $row['act_reason']);
break;
}
$groupreq[] = $this_req;
}
$smcFunc['db_free_result']($request);
return $groupreq;
}
function showPermissions($memID)
{
global $txt, $board;
global $user_profile, $context, $sourcedir, $smcFunc;
isAllowedTo('manage_permissions');
loadLanguage('ManagePermissions');
loadLanguage('Admin');
loadTemplate('ManageMembers');
require_once($sourcedir . '/ManagePermissions.php');
loadPermissionProfiles();
$context['member']['id'] = $memID;
$context['member']['name'] = $user_profile[$memID]['real_name'];
$context['page_title'] = $txt['showPermissions'];
$board = empty($board) ? 0 : (int) $board;
$context['board'] = $board;
if (empty($user_profile[$memID]['additional_groups']))
$curGroups = array();
else
$curGroups = explode(',', $user_profile[$memID]['additional_groups']);
$curGroups[] = $user_profile[$memID]['id_group'];
$curGroups[] = $user_profile[$memID]['id_post_group'];
$request = $smcFunc['db_query']('order_by_board_order', '
SELECT b.id_board, b.name, b.id_profile, b.member_groups, COALESCE(mods.id_member, modgs.id_group, 0) AS is_mod
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:current_groups}))
WHERE {query_see_board}',
array(
'current_member' => $memID,
'current_groups' => $curGroups,
)
);
$context['boards'] = array();
$context['no_access_boards'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (count(array_intersect($curGroups, explode(',', $row['member_groups']))) === 0 && !$row['is_mod'])
$context['no_access_boards'][] = array(
'id' => $row['id_board'],
'name' => $row['name'],
'is_last' => false,
);
elseif ($row['id_profile'] != 1 || $row['is_mod'])
$context['boards'][$row['id_board']] = array(
'id' => $row['id_board'],
'name' => $row['name'],
'selected' => $board == $row['id_board'],
'profile' => $row['id_profile'],
'profile_name' => $context['profiles'][$row['id_profile']]['name'],
);
}
$smcFunc['db_free_result']($request);
require_once($sourcedir . '/Subs-Boards.php');
sortBoards($context['boards']);
if (!empty($context['no_access_boards']))
$context['no_access_boards'][count($context['no_access_boards']) - 1]['is_last'] = true;
$context['member']['permissions'] = array(
'general' => array(),
'board' => array()
);
$context['member']['has_all_permissions'] = in_array(1, $curGroups);
if ($context['member']['has_all_permissions'])
return;
$denied = array();
$result = $smcFunc['db_query']('', '
SELECT p.permission, p.add_deny, mg.group_name, p.id_group
FROM {db_prefix}permissions AS p
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = p.id_group)
WHERE p.id_group IN ({array_int:group_list})
ORDER BY p.add_deny DESC, p.permission, mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name',
array(
'group_list' => $curGroups,
'newbie_group' => 4,
)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
{
if (!isset($txt['permissionname_' . $row['permission']]))
continue;
if (empty($row['add_deny']))
$denied[] = $row['permission'];
if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
else
$name = $txt['permissionname_' . $row['permission']];
if (!isset($context['member']['permissions']['general'][$row['permission']]))
$context['member']['permissions']['general'][$row['permission']] = array(
'id' => $row['permission'],
'groups' => array(
'allowed' => array(),
'denied' => array()
),
'name' => $name,
'is_denied' => false,
'is_global' => true,
);
$context['member']['permissions']['general'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
$context['member']['permissions']['general'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
}
$smcFunc['db_free_result']($result);
$request = $smcFunc['db_query']('', '
SELECT
bp.add_deny, bp.permission, bp.id_group, mg.group_name' . (empty($board) ? '' : ',
b.id_profile, CASE WHEN (mods.id_member IS NULL AND modgs.id_group IS NULL) THEN 0 ELSE 1 END AS is_moderator') . '
FROM {db_prefix}board_permissions AS bp' . (empty($board) ? '' : '
INNER JOIN {db_prefix}boards AS b ON (b.id_board = {int:current_board})
LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_board = b.id_board AND mods.id_member = {int:current_member})
LEFT JOIN {db_prefix}moderator_groups AS modgs ON (modgs.id_board = b.id_board AND modgs.id_group IN ({array_int:group_list}))') . '
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = bp.id_group)
WHERE bp.id_profile = {raw:current_profile}
AND bp.id_group IN ({array_int:group_list}' . (empty($board) ? ')' : ', {int:moderator_group})
AND (mods.id_member IS NOT NULL OR modgs.id_group IS NOT NULL OR bp.id_group != {int:moderator_group})'),
array(
'current_board' => $board,
'group_list' => $curGroups,
'current_member' => $memID,
'current_profile' => empty($board) ? '1' : 'b.id_profile',
'moderator_group' => 3,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!isset($txt['permissionname_' . $row['permission']]))
continue;
if (in_array(substr($row['permission'], -4), array('_own', '_any')) && isset($txt['permissionname_' . substr($row['permission'], 0, -4)]))
$name = $txt['permissionname_' . substr($row['permission'], 0, -4)] . ' - ' . $txt['permissionname_' . $row['permission']];
else
$name = $txt['permissionname_' . $row['permission']];
if (!isset($context['member']['permissions']['board'][$row['permission']]))
$context['member']['permissions']['board'][$row['permission']] = array(
'id' => $row['permission'],
'groups' => array(
'allowed' => array(),
'denied' => array()
),
'name' => $name,
'is_denied' => false,
'is_global' => empty($board),
);
$context['member']['permissions']['board'][$row['permission']]['groups'][empty($row['add_deny']) ? 'denied' : 'allowed'][$row['id_group']] = $row['id_group'] == 0 ? $txt['membergroups_members'] : $row['group_name'];
$context['member']['permissions']['board'][$row['permission']]['is_denied'] |= empty($row['add_deny']);
}
$smcFunc['db_free_result']($request);
}
function viewWarning($memID)
{
global $modSettings, $context, $sourcedir, $txt, $scripturl;
if (!($context['user']['is_owner'] && allowedTo('view_warning_own')) && !allowedTo('view_warning_any') && !allowedTo('issue_warning') && !allowedTo('moderate_forum'))
fatal_lang_error('no_access', false);
$modSettings['warning_watch'] = !empty($modSettings['warning_watch']) ? $modSettings['warning_watch'] : 110;
$modSettings['warning_moderate'] = !empty($modSettings['warning_moderate']) && !empty($modSettings['postmod_active']) ? $modSettings['warning_moderate'] : 110;
$modSettings['warning_mute'] = !empty($modSettings['warning_mute']) ? $modSettings['warning_mute'] : 110;
require_once($sourcedir . '/Subs-List.php');
require_once($sourcedir . '/Profile-Actions.php');
$listOptions = array(
'id' => 'view_warnings',
'title' => $txt['profile_viewwarning_previous_warnings'],
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['profile_viewwarning_no_warnings'],
'base_href' => $scripturl . '?action=profile;area=viewwarning;sa=user;u=' . $memID,
'default_sort_col' => 'log_time',
'get_items' => array(
'function' => 'list_getUserWarnings',
'params' => array(
$memID,
),
),
'get_count' => array(
'function' => 'list_getUserWarningCount',
'params' => array(
$memID,
),
),
'columns' => array(
'log_time' => array(
'header' => array(
'value' => $txt['profile_warning_previous_time'],
),
'data' => array(
'db' => 'time',
),
'sort' => array(
'default' => 'lc.log_time DESC',
'reverse' => 'lc.log_time',
),
),
'reason' => array(
'header' => array(
'value' => $txt['profile_warning_previous_reason'],
'style' => 'width: 50%;',
),
'data' => array(
'db' => 'reason',
),
),
'level' => array(
'header' => array(
'value' => $txt['profile_warning_previous_level'],
),
'data' => array(
'db' => 'counter',
),
'sort' => array(
'default' => 'lc.counter DESC',
'reverse' => 'lc.counter',
),
),
),
'additional_rows' => array(
array(
'position' => 'after_title',
'value' => $txt['profile_viewwarning_desc'],
'class' => 'smalltext',
'style' => 'padding: 2ex;',
),
),
);
require_once($sourcedir . '/Subs-List.php');
createList($listOptions);
$context['level_effects'] = array(
0 => '',
$modSettings['warning_watch'] => $txt['profile_warning_effect_own_watched'],
$modSettings['warning_moderate'] => $txt['profile_warning_effect_own_moderated'],
$modSettings['warning_mute'] => $txt['profile_warning_effect_own_muted'],
);
$context['current_level'] = 0;
foreach ($context['level_effects'] as $limit => $dummy)
if ($context['member']['warning'] >= $limit)
$context['current_level'] = $limit;
}
function set_alert_icon($alert)
{
global $settings;
switch ($alert['content_type'])
{
case 'topic':
case 'board':
{
switch ($alert['content_action'])
{
case 'reply':
case 'topic':
$class = 'main_icons posts';
break;
case 'move':
$src = $settings['images_url'] . '/post/moved.png';
break;
case 'remove':
$class = 'main_icons delete';
break;
case 'lock':
case 'unlock':
$class = 'main_icons lock';
break;
case 'sticky':
case 'unsticky':
$class = 'main_icons sticky';
break;
case 'split':
$class = 'main_icons split_button';
break;
case 'merge':
$class = 'main_icons merge';
break;
case 'unapproved_topic':
case 'unapproved_post':
$class = 'main_icons post_moderation_moderate';
break;
default:
$class = 'main_icons posts';
break;
}
}
break;
case 'msg':
{
switch ($alert['content_action'])
{
case 'like':
$class = 'main_icons like';
break;
case 'mention':
$class = 'main_icons im_on';
break;
case 'quote':
$class = 'main_icons quote';
break;
case 'unapproved_attachment':
$class = 'main_icons post_moderation_attach';
break;
case 'report':
case 'report_reply':
$class = 'main_icons post_moderation_moderate';
break;
default:
$class = 'main_icons posts';
break;
}
}
break;
case 'member':
{
switch ($alert['content_action'])
{
case 'register_standard':
case 'register_approval':
case 'register_activation':
$class = 'main_icons members';
break;
case 'report':
case 'report_reply':
$class = 'main_icons members_watched';
break;
case 'buddy_request':
$class = 'main_icons people';
break;
case 'group_request':
$class = 'main_icons members_request';
break;
default:
$class = 'main_icons members';
break;
}
}
break;
case 'groupr':
$class = 'main_icons members_request';
break;
case 'event':
$class = 'main_icons calendar';
break;
case 'paidsubs':
$class = 'main_icons paid';
break;
case 'birthday':
$src = $settings['images_url'] . '/cake.png';
break;
default:
$class = 'main_icons alerts';
break;
}
if (isset($class))
return '<span class="alert_icon ' . $class . '"></span>';
elseif (isset($src))
return '<img class="alert_icon" src="' . $src . '">';
else
return '';
}
?>