index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // check for right of current admin on this module
  3. if (cfr('CARDREPORT')) {
  4. $altcfg = rcms_parse_ini_file(CONFIG_PATH . "alter.ini");
  5. if ($altcfg['PAYMENTCARDS_ENABLED']) {
  6. /**
  7. * Renders year-month search interface
  8. *
  9. * @return void
  10. */
  11. function web_CardShowDateForm() {
  12. $curmonth = (wf_CheckPost(array('monthsel'))) ? vf($_POST['monthsel'], 3) : date("m");
  13. $curyear = (wf_CheckPost(array('yearsel'))) ? vf($_POST['yearsel'], 3) : date("Y");
  14. $inputs = wf_YearSelectorPreset('yearsel', __('Year'), false, $curyear).' ';
  15. $inputs.=wf_MonthSelector('monthsel', 'Month', $curmonth, false);
  16. $inputs.=wf_Submit('Show');
  17. $form = wf_Form("", 'POST', $inputs, 'glamour');
  18. show_window(__('Date'), $form);
  19. }
  20. /**
  21. * Renders search results for used cards
  22. *
  23. * @param int $year
  24. * @param string $month
  25. *
  26. * @return void
  27. */
  28. function web_CardShowUsageByMonth($year, $month) {
  29. $month = mysql_real_escape_string($month);
  30. $year = mysql_real_escape_string($year);
  31. $query = "SELECT * from `cardbank` WHERE `usedate` LIKE '%" . $year . "-" . $month . "-%'";
  32. $allusedcards = simple_queryall($query);
  33. $allrealnames = zb_UserGetAllRealnames();
  34. $alladdress = zb_AddressGetFulladdresslist();
  35. $totalsumm = 0;
  36. $totalcount = 0;
  37. $csvdata = '';
  38. $tablecells = wf_TableCell(__('ID'));
  39. $tablecells.=wf_TableCell(__('Serial number'));
  40. $tablecells.=wf_TableCell(__('Cash'));
  41. $tablecells.=wf_TableCell(__('Usage date'));
  42. $tablecells.=wf_TableCell(__('Used login'));
  43. $tablecells.=wf_TableCell(__('Full address'));
  44. $tablecells.=wf_TableCell(__('Real name'));
  45. $tablerows = wf_TableRow($tablecells, 'row1');
  46. if (!empty($allusedcards)) {
  47. $csvdata = __('ID') . ';' . __('Serial number') . ';' . __('Cash') . ';' . __('Usage date') . ';' . __('Used login') . ';' . __('Full address') . ';' . __('Real name') . "\n";
  48. foreach ($allusedcards as $io => $eachcard) {
  49. $tablecells = wf_TableCell($eachcard['id']);
  50. $tablecells.=wf_TableCell($eachcard['serial']);
  51. $tablecells.=wf_TableCell($eachcard['cash']);
  52. $tablecells.=wf_TableCell($eachcard['usedate']);
  53. $profilelink = wf_Link("?module=userprofile&username=" . $eachcard['usedlogin'], web_profile_icon() . ' ' . $eachcard['usedlogin'], false);
  54. $tablecells.=wf_TableCell($profilelink);
  55. @$useraddress = $alladdress[$eachcard['usedlogin']];
  56. $tablecells.=wf_TableCell($useraddress);
  57. @$userrealname = $allrealnames[$eachcard['usedlogin']];
  58. $tablecells.=wf_TableCell($userrealname);
  59. $tablerows.=wf_TableRow($tablecells, 'row3');
  60. $totalcount++;
  61. $totalsumm = $totalsumm + $eachcard['cash'];
  62. $csvdata.=$eachcard['id'] . ';' . $eachcard['serial'] . ';' . $eachcard['cash'] . ';' . $eachcard['usedate'] . ';' . $eachcard['usedlogin'] . ';' . $useraddress . ';' . $userrealname . "\n";
  63. }
  64. }
  65. if (!empty($csvdata)) {
  66. $exportFilename = 'exports/cardreport_' . $year . '-' . $month . '.csv';
  67. $csvdata = iconv('utf-8', 'windows-1251', $csvdata);
  68. file_put_contents($exportFilename, $csvdata);
  69. $exportLink = wf_Link('?module=cardreport&dloadcsv=' . base64_encode($exportFilename), wf_img('skins/excel.gif', __('Export')), false, '');
  70. } else {
  71. $exportLink = '';
  72. }
  73. $result = wf_TableBody($tablerows, '100%', '0', 'sortable');
  74. $result.=__('Total') . ': ' . $totalcount . ' ' . __('payments') . ', ' . __('with total amount') . ': ' . $totalsumm;
  75. show_window(__('Payment cards usage report') . ' ' . $exportLink, $result);
  76. }
  77. web_CardShowDateForm();
  78. //selecting month and date
  79. if (wf_CheckPost(array('yearsel', 'monthsel'))) {
  80. $needyear = $_POST['yearsel'];
  81. $needmonth = $_POST['monthsel'];
  82. } else {
  83. $needyear = curyear();
  84. $needmonth = date("m");
  85. }
  86. //download exported search
  87. if (wf_CheckGet(array('dloadcsv'))) {
  88. zb_DownloadFile(base64_decode($_GET['dloadcsv']), 'docx');
  89. }
  90. web_CardShowUsageByMonth($needyear, $needmonth);
  91. } else {
  92. show_error(__('This module is disabled'));
  93. }
  94. } else {
  95. show_error(__('You cant control this module'));
  96. }
  97. ?>