Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stats.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php
  2. /*
  3. Copyright (C) 2012 Otto Kekäläinen <otto@fsfe.org> for Free Software Foundation Europe
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as
  6. published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. // report errors
  16. //error_reporting(E_ALL);
  17. //ini_set('display_errors', 'On');
  18. /*
  19. TODO:
  20. - refactor to use standard FSFE header and footer
  21. - restrict access to FSFE Fellows
  22. - sort countries by sum of last date, not on sum of first date like is done now
  23. */
  24. try {
  25. // open the database
  26. $db = new PDO( 'sqlite:../../../db/support.sqlite' );
  27. }
  28. catch(PDOException $e) {
  29. print 'Error while connecting to Database: '.$e->getMessage();
  30. }
  31. // total supporters ever, including unconfirmed
  32. try {
  33. $sql = "SELECT *, COUNT(*) AS supporters FROM t1 ";
  34. // enable stats for single referrers
  35. if (isset($_GET['ref_id'])) {
  36. $sql .= "WHERE ref_id = '". sqlite_escape_string($_GET['ref_id']) ."' ";
  37. }
  38. if (isset($_GET['ref_url'])) {
  39. $sql .= "WHERE ref_url LIKE '%". sqlite_escape_string($_GET['ref_url']) ."%' ";
  40. }
  41. if (isset($_GET['country_code'])) {
  42. $sql .= "WHERE country_code = '". sqlite_escape_string($_GET['country_code']) ."' ";
  43. }
  44. $query = $db->prepare($sql);
  45. $query->execute();
  46. }
  47. catch(PDOException $e) {
  48. print "Database Error: \n";
  49. print_r($db->errorInfo());
  50. }
  51. $row = $query->fetch(PDO::FETCH_ASSOC);
  52. $total = $row['supporters'];
  53. function ts_days_ago($days) {
  54. $days_ago = mktime(0, 0, 0, date("m"), date("d")-$days, date("Y"));
  55. return date("Y-m-d", $days_ago) . " 23:59:59";
  56. }
  57. function epoc_days_ago($days) {
  58. return mktime(0, 0, 0, date("m"), date("d")-$days, date("Y"));
  59. }
  60. $series = array();
  61. for ($i = 90; $i >= 0; $i--) {
  62. try {
  63. // check data
  64. $sql = "SELECT *, COUNT(*) AS supporters FROM t1 WHERE confirmed != '' AND time <= Datetime('". ts_days_ago($i) ."') ";
  65. // enable stats for single referrers
  66. if (isset($_GET['ref_id'])) {
  67. $sql .= "AND ref_id = '". sqlite_escape_string($_GET['ref_id']) ."' ";
  68. }
  69. if (isset($_GET['ref_url'])) {
  70. $sql .= "AND ref_url LIKE '%". sqlite_escape_string($_GET['ref_url']) ."%' ";
  71. }
  72. if (isset($_GET['country_code'])) {
  73. $sql .= "AND country_code = '". sqlite_escape_string($_GET['country_code']) ."' ";
  74. }
  75. $sql .= "GROUP BY country_code ORDER BY supporters DESC";
  76. //echo $sql;
  77. $query = $db->prepare($sql);
  78. $query->execute();
  79. }
  80. catch(PDOException $e) {
  81. print "Database Error: \n";
  82. print_r($db->errorInfo());
  83. }
  84. if ($i == 0) { $total_confirmed = 0; }
  85. if ($i == 90) { $total_confirmed_at_beginning = 0; }
  86. while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
  87. // true if at least one row to return
  88. if ($row["country_code"] == "") { continue; } // skip to next row if country empty
  89. $series[$row["country_code"]][] = array(
  90. "x" => epoc_days_ago($i),
  91. "y" => $row["supporters"]
  92. );
  93. /* print_r($row);
  94. example: Array
  95. (
  96. [id] => 157
  97. [time] => 2012-07-13 05:27:41
  98. [firstname] => Krrtrtta
  99. [lastname] => Toirtrla
  100. [email] => krifgfga.tofgfgla@luukku.com
  101. [country_code] => FI
  102. [secret] => 7c016a4ab30efa2899a0ec76a92fg6b
  103. [signed] =>
  104. [confirmed] =>
  105. [updated] =>
  106. [supporters] => 116
  107. )
  108. */
  109. if ($i == 0) { $total_confirmed += $row["supporters"]; } // at the end of the time period, equals totals now
  110. if ($i == 90) { $total_confirmed_at_beginning += $row["supporters"]; }
  111. }
  112. }
  113. $growth = $total_confirmed - $total_confirmed_at_beginning;
  114. $estimate = $total_confirmed + $growth*4;
  115. // country list
  116. $countries = array (
  117. 'AD' => 'Andorra',
  118. 'AE' => 'United Arab Emirates',
  119. 'AF' => 'Afghanistan',
  120. 'AG' => 'Antigua and Barbuda',
  121. 'AI' => 'Anguilla',
  122. 'AL' => 'Albania',
  123. 'AM' => 'Armenia',
  124. 'AN' => 'Netherlands Antilles',
  125. 'AO' => 'Angola',
  126. 'AQ' => 'Antarctica',
  127. 'AR' => 'Argentina',
  128. 'AS' => 'American Samoa',
  129. 'AT' => 'Austria',
  130. 'AU' => 'Australia',
  131. 'AW' => 'Aruba',
  132. 'AX' => 'Åland Islands',
  133. 'AZ' => 'Azerbaijan',
  134. 'BA' => 'Bosnia and Herzegovina',
  135. 'BB' => 'Barbados',
  136. 'BD' => 'Bangladesh',
  137. 'BE' => 'Belgium',
  138. 'BF' => 'Burkina Faso',
  139. 'BG' => 'Bulgaria',
  140. 'BH' => 'Bahrain',
  141. 'BI' => 'Burundi',
  142. 'BJ' => 'Benin',
  143. 'BL' => 'Saint Barthélemy',
  144. 'BM' => 'Bermuda',
  145. 'BN' => 'Brunei',
  146. 'BO' => 'Bolivia',
  147. 'BQ' => 'British Antarctic Territory',
  148. 'BR' => 'Brazil',
  149. 'BS' => 'Bahamas',
  150. 'BT' => 'Bhutan',
  151. 'BV' => 'Bouvet Island',
  152. 'BW' => 'Botswana',
  153. 'BY' => 'Belarus',
  154. 'BZ' => 'Belize',
  155. 'CA' => 'Canada',
  156. 'CC' => 'Cocos [Keeling] Islands',
  157. 'CD' => 'Congo - Kinshasa',
  158. 'CF' => 'Central African Republic',
  159. 'CG' => 'Congo - Brazzaville',
  160. 'CH' => 'Switzerland',
  161. 'CI' => 'Côte d’Ivoire',
  162. 'CK' => 'Cook Islands',
  163. 'CL' => 'Chile',
  164. 'CM' => 'Cameroon',
  165. 'CN' => 'China',
  166. 'CO' => 'Colombia',
  167. 'CR' => 'Costa Rica',
  168. 'CS' => 'Serbia and Montenegro',
  169. 'CT' => 'Canton and Enderbury Islands',
  170. 'CU' => 'Cuba',
  171. 'CV' => 'Cape Verde',
  172. 'CX' => 'Christmas Island',
  173. 'CY' => 'Cyprus',
  174. 'CZ' => 'Czech Republic',
  175. 'DD' => 'East Germany',
  176. 'DE' => 'Germany',
  177. 'DJ' => 'Djibouti',
  178. 'DK' => 'Denmark',
  179. 'DM' => 'Dominica',
  180. 'DO' => 'Dominican Republic',
  181. 'DZ' => 'Algeria',
  182. 'EC' => 'Ecuador',
  183. 'EE' => 'Estonia',
  184. 'EG' => 'Egypt',
  185. 'EH' => 'Western Sahara',
  186. 'ER' => 'Eritrea',
  187. 'ES' => 'Spain',
  188. 'ET' => 'Ethiopia',
  189. 'FI' => 'Finland',
  190. 'FJ' => 'Fiji',
  191. 'FK' => 'Falkland Islands',
  192. 'FM' => 'Micronesia',
  193. 'FO' => 'Faroe Islands',
  194. 'FQ' => 'French Southern and Antarctic Territories',
  195. 'FR' => 'France',
  196. 'FX' => 'Metropolitan France',
  197. 'GA' => 'Gabon',
  198. 'GB' => 'United Kingdom',
  199. 'GD' => 'Grenada',
  200. 'GE' => 'Georgia',
  201. 'GF' => 'French Guiana',
  202. 'GG' => 'Guernsey',
  203. 'GH' => 'Ghana',
  204. 'GI' => 'Gibraltar',
  205. 'GL' => 'Greenland',
  206. 'GM' => 'Gambia',
  207. 'GN' => 'Guinea',
  208. 'GP' => 'Guadeloupe',
  209. 'GQ' => 'Equatorial Guinea',
  210. 'GR' => 'Greece',
  211. 'GS' => 'South Georgia and the South Sandwich Islands',
  212. 'GT' => 'Guatemala',
  213. 'GU' => 'Guam',
  214. 'GW' => 'Guinea-Bissau',
  215. 'GY' => 'Guyana',
  216. 'HK' => 'Hong Kong SAR China',
  217. 'HM' => 'Heard Island and McDonald Islands',
  218. 'HN' => 'Honduras',
  219. 'HR' => 'Croatia',
  220. 'HT' => 'Haiti',
  221. 'HU' => 'Hungary',
  222. 'ID' => 'Indonesia',
  223. 'IE' => 'Ireland',
  224. 'IL' => 'Israel',
  225. 'IM' => 'Isle of Man',
  226. 'IN' => 'India',
  227. 'IO' => 'British Indian Ocean Territory',
  228. 'IQ' => 'Iraq',
  229. 'IR' => 'Iran',
  230. 'IS' => 'Iceland',
  231. 'IT' => 'Italy',
  232. 'JE' => 'Jersey',
  233. 'JM' => 'Jamaica',
  234. 'JO' => 'Jordan',
  235. 'JP' => 'Japan',
  236. 'JT' => 'Johnston Island',
  237. 'KE' => 'Kenya',
  238. 'KG' => 'Kyrgyzstan',
  239. 'KH' => 'Cambodia',
  240. 'KI' => 'Kiribati',
  241. 'KM' => 'Comoros',
  242. 'KN' => 'Saint Kitts and Nevis',
  243. 'KP' => 'North Korea',
  244. 'KR' => 'South Korea',
  245. 'KW' => 'Kuwait',
  246. 'KY' => 'Cayman Islands',
  247. 'KZ' => 'Kazakhstan',
  248. 'LA' => 'Laos',
  249. 'LB' => 'Lebanon',
  250. 'LC' => 'Saint Lucia',
  251. 'LI' => 'Liechtenstein',
  252. 'LK' => 'Sri Lanka',
  253. 'LR' => 'Liberia',
  254. 'LS' => 'Lesotho',
  255. 'LT' => 'Lithuania',
  256. 'LU' => 'Luxembourg',
  257. 'LV' => 'Latvia',
  258. 'LY' => 'Libya',
  259. 'MA' => 'Morocco',
  260. 'MC' => 'Monaco',
  261. 'MD' => 'Moldova',
  262. 'ME' => 'Montenegro',
  263. 'MF' => 'Saint Martin',
  264. 'MG' => 'Madagascar',
  265. 'MH' => 'Marshall Islands',
  266. 'MI' => 'Midway Islands',
  267. 'MK' => 'Macedonia',
  268. 'ML' => 'Mali',
  269. 'MM' => 'Myanmar [Burma]',
  270. 'MN' => 'Mongolia',
  271. 'MO' => 'Macau SAR China',
  272. 'MP' => 'Northern Mariana Islands',
  273. 'MQ' => 'Martinique',
  274. 'MR' => 'Mauritania',
  275. 'MS' => 'Montserrat',
  276. 'MT' => 'Malta',
  277. 'MU' => 'Mauritius',
  278. 'MV' => 'Maldives',
  279. 'MW' => 'Malawi',
  280. 'MX' => 'Mexico',
  281. 'MY' => 'Malaysia',
  282. 'MZ' => 'Mozambique',
  283. 'NA' => 'Namibia',
  284. 'NC' => 'New Caledonia',
  285. 'NE' => 'Niger',
  286. 'NF' => 'Norfolk Island',
  287. 'NG' => 'Nigeria',
  288. 'NI' => 'Nicaragua',
  289. 'NL' => 'Netherlands',
  290. 'NO' => 'Norway',
  291. 'NP' => 'Nepal',
  292. 'NQ' => 'Dronning Maud Land',
  293. 'NR' => 'Nauru',
  294. 'NT' => 'Neutral Zone',
  295. 'NU' => 'Niue',
  296. 'NZ' => 'New Zealand',
  297. 'OM' => 'Oman',
  298. 'PA' => 'Panama',
  299. 'PC' => 'Pacific Islands Trust Territory',
  300. 'PE' => 'Peru',
  301. 'PF' => 'French Polynesia',
  302. 'PG' => 'Papua New Guinea',
  303. 'PH' => 'Philippines',
  304. 'PK' => 'Pakistan',
  305. 'PL' => 'Poland',
  306. 'PM' => 'Saint Pierre and Miquelon',
  307. 'PN' => 'Pitcairn Islands',
  308. 'PR' => 'Puerto Rico',
  309. 'PS' => 'Palestinian Territories',
  310. 'PT' => 'Portugal',
  311. 'PU' => 'U.S. Miscellaneous Pacific Islands',
  312. 'PW' => 'Palau',
  313. 'PY' => 'Paraguay',
  314. 'PZ' => 'Panama Canal Zone',
  315. 'QA' => 'Qatar',
  316. 'RE' => 'Réunion',
  317. 'RO' => 'Romania',
  318. 'RS' => 'Serbia',
  319. 'RU' => 'Russia',
  320. 'RW' => 'Rwanda',
  321. 'SA' => 'Saudi Arabia',
  322. 'SB' => 'Solomon Islands',
  323. 'SC' => 'Seychelles',
  324. 'SD' => 'Sudan',
  325. 'SE' => 'Sweden',
  326. 'SG' => 'Singapore',
  327. 'SH' => 'Saint Helena',
  328. 'SI' => 'Slovenia',
  329. 'SJ' => 'Svalbard and Jan Mayen',
  330. 'SK' => 'Slovakia',
  331. 'SL' => 'Sierra Leone',
  332. 'SM' => 'San Marino',
  333. 'SN' => 'Senegal',
  334. 'SO' => 'Somalia',
  335. 'SR' => 'Suriname',
  336. 'ST' => 'São Tomé and Príncipe',
  337. 'SU' => 'Union of Soviet Socialist Republics',
  338. 'SV' => 'El Salvador',
  339. 'SY' => 'Syria',
  340. 'SZ' => 'Swaziland',
  341. 'TC' => 'Turks and Caicos Islands',
  342. 'TD' => 'Chad',
  343. 'TF' => 'French Southern Territories',
  344. 'TG' => 'Togo',
  345. 'TH' => 'Thailand',
  346. 'TJ' => 'Tajikistan',
  347. 'TK' => 'Tokelau',
  348. 'TL' => 'Timor-Leste',
  349. 'TM' => 'Turkmenistan',
  350. 'TN' => 'Tunisia',
  351. 'TO' => 'Tonga',
  352. 'TR' => 'Turkey',
  353. 'TT' => 'Trinidad and Tobago',
  354. 'TV' => 'Tuvalu',
  355. 'TW' => 'Taiwan',
  356. 'TZ' => 'Tanzania',
  357. 'UA' => 'Ukraine',
  358. 'UG' => 'Uganda',
  359. 'UM' => 'U.S. Minor Outlying Islands',
  360. 'US' => 'United States',
  361. 'UY' => 'Uruguay',
  362. 'UZ' => 'Uzbekistan',
  363. 'VA' => 'Vatican City',
  364. 'VC' => 'Saint Vincent and the Grenadines',
  365. 'VD' => 'North Vietnam',
  366. 'VE' => 'Venezuela',
  367. 'VG' => 'British Virgin Islands',
  368. 'VI' => 'U.S. Virgin Islands',
  369. 'VN' => 'Vietnam',
  370. 'VU' => 'Vanuatu',
  371. 'WF' => 'Wallis and Futuna',
  372. 'WK' => 'Wake Island',
  373. 'WS' => 'Samoa',
  374. 'YD' => 'People\'s Democratic Republic of Yemen',
  375. 'YE' => 'Yemen',
  376. 'YT' => 'Mayotte',
  377. 'ZA' => 'South Africa',
  378. 'ZM' => 'Zambia',
  379. 'ZW' => 'Zimbabwe',
  380. 'ZZ' => 'Unknown or Invalid Region',
  381. 'XK' => 'Kosovo',
  382. );
  383. $series_json = "";
  384. foreach ($series as $k => $v) {
  385. $series_json .= '
  386. {
  387. name: "'. $countries[$k] .'",
  388. data: [ ';
  389. foreach ($v as $subk => $subv) {
  390. $series_json .= '{ x: '. $subv["x"] .', y: '. $subv["y"] .' },';
  391. }
  392. $series_json .= ' ],
  393. color: palette.color()
  394. },
  395. ';
  396. }
  397. ?>
  398. <!doctype html public "✰">
  399. <head>
  400. <meta charset="utf-8">
  401. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  402. <title dir="ltr">FSFE Supporter statistics</title>
  403. <meta name="viewport" content="width=device-width">
  404. <link type="text/css" rel="stylesheet" href="rickshaw.min.css">
  405. <script src="d3.min.js"></script>
  406. <script src="d3.layout.min.js"></script>
  407. <script src="rickshaw.min.js"></script>
  408. <style>
  409. body {
  410. font-family: Arial, Helvetica, sans-serif;
  411. color: #555;
  412. padding: 1em;
  413. }
  414. #chart_container {
  415. position: relative;
  416. display: inline-block;
  417. left: 14em;
  418. }
  419. #chart {
  420. display: inline-block;
  421. margin-left: 40px;
  422. }
  423. #y_axis {
  424. position: absolute;
  425. top: 0;
  426. bottom: 0;
  427. width: 40px;
  428. }
  429. #legend {
  430. display: inline-block;
  431. vertical-align: top;
  432. margin: 0 0 0 10px;
  433. }
  434. .statusbox {
  435. width: 12em;
  436. border: 1px solid #ccc;
  437. background: #eee;
  438. padding: 1em;
  439. font-size: 15px;
  440. position: absolute;
  441. left: 2em;
  442. }
  443. .statusbox h3 {
  444. font-size: 17px;
  445. }
  446. .statusbox p {
  447. margin: 0;
  448. }
  449. .statusbox strong {
  450. font-size: 80px;
  451. }
  452. .statusbox em {
  453. font-size: 16px;
  454. font-weight: bold;
  455. }
  456. #lastlog {
  457. background: #ccc;
  458. font-size: 10pt;
  459. }
  460. #lastlog th {
  461. text-align: left;
  462. }
  463. #lastlog td {
  464. background: #eee;
  465. padding: 6px;
  466. }
  467. </style>
  468. </head>
  469. <body>
  470. <h1>Supporter count status
  471. <?php
  472. if (isset($_GET['ref_url'])) { echo " for referrer URLs containing ". htmlspecialchars($_GET['ref_url']); }
  473. if (isset($_GET['ref_id'])) { echo " for referrer fsfe.org/support?". htmlspecialchars($_GET['ref_id']); }
  474. ?>
  475. <small><?php date("Y-m-d") ?></small></h1>
  476. <div class="statusbox">
  477. <h3>Total supporters</h3>
  478. <p><strong><?php echo $total_confirmed; ?></strong></p>
  479. <p>with e-mail confirmed.</p>
  480. <p>Total with unconfirmed included is <em><?php echo $total; ?></em>.</p>
  481. </div>
  482. <div class="statusbox" style="top:26em;">
  483. <p>Three months ago there where <em><?php echo $total_confirmed_at_beginning; ?></em> supporters, so growth was <em><?php echo $growth; ?></em> supporters. If growth continues at the same pace, we'll have <em><?php echo $estimate; ?></em> supporters in a year from now!</p>
  484. </div>
  485. <div id="chart_container">
  486. <div id="y_axis"></div>
  487. <div id="chart"></div>
  488. <div id="legend"></div>
  489. </div>
  490. <script>
  491. var palette = new Rickshaw.Color.Palette();
  492. var seriesData = [ <?php echo $series_json; ?> ];
  493. Rickshaw.Series.zeroFill(seriesData);
  494. var graph = new Rickshaw.Graph( {
  495. element: document.querySelector("#chart"),
  496. width: 700,
  497. height: 700,
  498. renderer: 'bar',
  499. series: seriesData
  500. } );
  501. var x_axis = new Rickshaw.Graph.Axis.Time( { graph: graph } );
  502. var y_axis = new Rickshaw.Graph.Axis.Y( {
  503. graph: graph,
  504. orientation: 'left',
  505. tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
  506. element: document.getElementById('y_axis'),
  507. } );
  508. var legend = new Rickshaw.Graph.Legend( {
  509. element: document.querySelector('#legend'),
  510. graph: graph
  511. } );
  512. var hoverDetail = new Rickshaw.Graph.HoverDetail( {
  513. graph: graph,
  514. yFormatter: function(y) { return Math.floor(y) + " supporters" }
  515. } );
  516. /*
  517. // does not work, result area becomes white!
  518. // assume issue is missing jquery libs and extra css stuff
  519. var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({
  520. graph: graph,
  521. legend: legend
  522. });
  523. */
  524. graph.render();
  525. // reverse list to match legend sorting
  526. seriesData.reverse()
  527. legendlist = document.querySelectorAll('#legend li');
  528. // iterate all and add count in legend
  529. for (i = 0; i < seriesData.length; i++) {
  530. sum = document.createElement("span");
  531. sum.innerHTML = ": " + seriesData[i].data.slice(-1)[0].y;
  532. legendlist[i].appendChild(sum);
  533. }
  534. </script>
  535. <h3>Latest 20 sign ups</h3>
  536. <table id="lastlog">
  537. <tr>
  538. <th>Date</th>
  539. <th>Country</th>
  540. <th>Referrer url</th>
  541. <th>Referrer id (support?xxxx)</th>
  542. <th>E-mail confirmed</th>
  543. </tr>
  544. <?php
  545. try {
  546. $sql = "SELECT * FROM t1 ";
  547. // enable stats for single referrers
  548. if (isset($_GET['ref_id'])) {
  549. $sql .= "WHERE ref_id = '". sqlite_escape_string($_GET['ref_id']) ."' ";
  550. }
  551. if (isset($_GET['ref_url'])) {
  552. $sql .= "WHERE ref_url LIKE '". sqlite_escape_string($_GET['ref_url']) ."%' ";
  553. }
  554. if (isset($_GET['country_code'])) {
  555. $sql .= "WHERE country_code = '". sqlite_escape_string($_GET['country_code']) ."' ";
  556. }
  557. $sql .= "ORDER BY time DESC LIMIT 0,20";
  558. $query = $db->prepare($sql);
  559. $query->execute();
  560. }
  561. catch(PDOException $e) {
  562. print "Database Error: \n";
  563. print_r($db->errorInfo());
  564. }
  565. while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
  566. echo '<tr>
  567. <td>'. substr($row["time"], 0, 10) .'</td>
  568. <td><a href="?country_code='. $row["country_code"] .'">'. $row["country_code"] .'</a></td>
  569. <td><a href="?ref_url='. $row["ref_url"] .'">'. $row["ref_url"] .'</a></td>
  570. <td><a href="?ref_id='. $row["ref_id"] .'">'. $row["ref_id"] .'</a></td>
  571. <td>'. substr($row["confirmed"], 0, 10) .'</td>
  572. </tr>';
  573. }
  574. ?>
  575. </table>
  576. <?php
  577. // close the database connection
  578. $db = NULL;
  579. ?>
  580. <br>
  581. <timestamp>$Date$ $Author$</timestamp>
  582. </body>
  583. </html>
  584. <!--
  585. Local Variables: ***
  586. mode: xml ***
  587. End: ***
  588. -->