PageRenderTime 60ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/stat.php

https://github.com/intelliants/elitius
PHP | 79 lines | 39 code | 8 blank | 32 comment | 3 complexity | 27aefc969f8cd83e7ca8892c6b8e9ba2 MD5 | raw file
  1. <?php
  2. /***************************************************************************
  3. *
  4. * PROJECT: eLitius Open Source Affiliate Software
  5. * VERSION: 1.0
  6. * LISENSE: GNU GPL (http://www.opensource.org/licenses/gpl-license.html)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation.
  11. *
  12. * Link to eLitius.com can not be removed from the software pages without
  13. * permission of the eLitius respective owners. It is the only requirement
  14. * for using this software.
  15. *
  16. * Copyright 2009 Intelliants LLC
  17. * http://www.intelliants.com/
  18. *
  19. ***************************************************************************/
  20. $dateInterval = 30; // interval date
  21. $curentDate = date('Y-m-d'); // current DATE;
  22. /** create array and fill array date parameter between (current DATE) - (interval $dateInterval) **/
  23. $arrayDate = Array();
  24. for($d=$dateInterval-1; $d>=0; $d--)
  25. {
  26. $diffDay = $d==0? date('Mj') : date('Mj',strtotime($curentDate." -".$d." day"));
  27. $arrayDate[$diffDay] = 0;
  28. }
  29. /** create stat sales **/
  30. $sql = "SELECT date_format(`date`,'%b%e') `date_new`, `date`, COUNT(id) num FROM `".$gXpConfig['prefix']."sales` WHERE `date` >= DATE_SUB(NOW(), INTERVAL ".$dateInterval." DAY) GROUP BY `date` ORDER BY `date`";
  31. $salesLast = $gXpAdmin->mDb->getAll($sql);
  32. $arrayDateSales = arrayFillDate($salesLast, $arrayDate, 'num', 'date_new');
  33. $salesDate = array_keys($arrayDateSales);
  34. $salesNum = array_values($arrayDateSales);
  35. regularSetSpase($salesDate);
  36. /** create stat trafic **/
  37. $sql2 = "CREATE TEMPORARY TABLE stat SELECT `date`, `uid` FROM `".$gXpConfig['prefix']."tracking` WHERE `date` >= DATE_SUB(NOW(), INTERVAL ".$dateInterval." DAY) GROUP BY `date`, `uid` ORDER BY `date`";
  38. $gXpAdmin->mDb->query($sql2);
  39. $sql = "SELECT date_format(`date`,'%b%e') `date_new`,COUNT(`uid`) `total` FROM `stat` GROUP BY `date` ORDER BY `date`";
  40. $trackingLast = $gXpAdmin->mDb->getAll($sql);
  41. $arrayDateTracking = arrayFillDate($trackingLast, $arrayDate, 'total', 'date_new');
  42. $trackingDate = array_keys($arrayDateTracking);
  43. $trackingNum = array_values($arrayDateTracking);
  44. regularSetSpase($trackingDate);
  45. /**
  46. * fill new parameter to $arrayDate
  47. *
  48. * @param arr $arrayIn data from base
  49. * @param arr $arrayDate array contents date parameter
  50. * @param str $fieldNameIn field name from base
  51. * @param str $fieldNameOut output name parameter
  52. *
  53. *
  54. * @return array
  55. */
  56. function arrayFillDate($arrayIn, $arrayDate, $fieldNameIn, $fieldNameOut)
  57. {
  58. for( $i=0; $i<count($arrayIn); $i++ )
  59. {
  60. $arrayDate[$arrayIn[$i][$fieldNameOut]] = $arrayIn[$i][$fieldNameIn];
  61. }
  62. return $arrayDate;
  63. }
  64. function regularSetSpase(&$array)
  65. {
  66. for( $i=0; $i<count($array); $i++ )
  67. {
  68. $array[$i] = ($i%2)? $array[$i] : '';
  69. }
  70. }
  71. ?>