index.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. $altcfg = rcms_parse_ini_file(CONFIG_PATH . 'alter.ini');
  3. if ($altcfg['PER_CITY_ACTION']) {
  4. if (cfr('CITYACTION')) {
  5. $admin = whoami();
  6. $form = wf_Link(PerCityAction::MODULE_NAME, __('Clear'), true, 'ubButton');
  7. $form.= wf_tag('br');
  8. $form.= wf_Link(PerCityAction::MODULE_NAME . "&action=debtors", __('Debtors'), false, 'ubButton');
  9. $form.= wf_Link(PerCityAction::MODULE_NAME . "&action=city_payments", __('Payments per city'), false, 'ubButton');
  10. $form.= wf_Link(PerCityAction::MODULE_NAME . "&action=usersearch", __('User search'), false, 'ubButton');
  11. $form.= wf_Link(PerCityAction::MODULE_NAME . "&action=permission", __('Permission'), false, 'ubButton');
  12. $form.= wf_Link(PerCityAction::MODULE_NAME . "&action=analytics", __('Analytics'), true, 'ubButton');
  13. show_window(__('Actions'), $form);
  14. $perCityAction = new PerCityAction();
  15. if (isset($_GET['action'])) {
  16. $action = $_GET['action'];
  17. if ($action == 'debtors') {
  18. if (cfr('REPORTCITYDEBTORS')) {
  19. show_window(__('Payments'), $perCityAction->CitySelector($admin, $action));
  20. if (isset($_GET['citysearch'])) {
  21. $cityId = $_GET['citysearch'];
  22. if ($perCityAction->CheckRigts($cityId, $admin)) {
  23. $perCityAction->LoadAllData('', $cityId, 'debtors');
  24. if (isset($_GET['ajax'])) {
  25. die($perCityAction->ajaxData());
  26. }
  27. $report_name = __('Debtors by city') . wf_Link(PerCityAction::MODULE_NAME . "&action=debtors&citysel=$cityId&printable=true", wf_img("skins/printer_small.gif"));
  28. show_window(__($report_name), $perCityAction->PerCityDataShow());
  29. } else {
  30. show_error(__('You cant control this module'));
  31. }
  32. }
  33. if (isset($_GET['printable'])) {
  34. if ($_GET['printable']) {
  35. $query = "SELECT `address`.`login`,`users`.`cash` FROM `address` INNER JOIN users USING (login) WHERE `address`.`aptid` IN ( SELECT `id` FROM `apt` WHERE `buildid` IN ( SELECT `id` FROM `build` WHERE `streetid` IN ( SELECT `id` FROM `street` WHERE `cityid`='" . $_GET['citysel'] . "'))) and `users`.`cash`<0";
  36. $keys = array('cash', 'login');
  37. $titles = array('tariff', "Comment", 'Mac ONU', "Credited", "Cash", 'Login');
  38. $alldata = simple_queryall($query);
  39. web_ReportDebtorsShowPrintable($titles, $keys, $alldata, '1', '1', '1');
  40. }
  41. }
  42. }
  43. }
  44. if ($action == 'usersearch') {
  45. if (cfr('CITYUSERSEARCH')) {
  46. show_window(__('User search'), $perCityAction->CitySelector($admin, $action));
  47. if (isset($_GET['citysearch'])) {
  48. $cityId = $_GET['citysearch'];
  49. if ($perCityAction->CheckRigts($cityId, $admin)) {
  50. $perCityAction->LoadAllData('', $cityId, 'usersearch');
  51. $report_name = __('Search results') . wf_link(PerCityAction::MODULE_NAME . "&action=usersearch&printable=true&citysel=$cityId", wf_img("skins/printer_small.gif"));
  52. show_window(__($report_name), $perCityAction->PerCityDataShow());
  53. } else {
  54. show_error(__('You cant control this module'));
  55. }
  56. }
  57. if (isset($_GET['printable'])) {
  58. $City = $_GET['citysel'];
  59. $query = "SELECT `login` FROM `address` WHERE `aptid` IN (SELECT `id` FROM `apt` WHERE `buildid` IN (SELECT `id` FROM `build` WHERE `streetid` IN (SELECT `id` FROM `street` WHERE `cityid`='" . $City . "')))";
  60. $keys = array('login');
  61. $titles = array('tariff', 'Comment', 'MAC ONU', 'Credited', 'Login');
  62. $alldata = simple_queryall($query);
  63. web_ReportCityShowPrintable($titles, $keys, $alldata, '1', '1', '1');
  64. }
  65. }
  66. }
  67. if ($action == 'city_payments') {
  68. if (cfr('CITYPAYMENTS')) {
  69. show_window(__('Change month'), web_MonthSelector());
  70. show_window(__('Change year'), web_YearSelector());
  71. show_window(__('Payments'), $perCityAction->CitySelector($admin, $action));
  72. if (isset($_GET['citysearch'])) {
  73. $cityId = $_GET['citysearch'];
  74. if ($perCityAction->CheckRigts($cityId, $admin)) {
  75. if (!isset($_GET['monthsel'])) {
  76. $cur_month = $perCityAction->GetCurrentDate(true);
  77. rcms_redirect(PerCityAction::MODULE_NAME . "&action=city_payments&citysearch=" . $_GET['citysearch'] . "&monthsel=" . $cur_month);
  78. } else {
  79. $cur_month = $_GET['monthsel'];
  80. }
  81. if (isset($_GET['year'])) {
  82. $year = $_GET['year'];
  83. } else {
  84. $year = $perCityAction->GetCurrentDate(false, true);
  85. }
  86. $currentDate = $year . '-' . $cur_month;
  87. $perCityAction->LoadAllCredited($currentDate);
  88. $perCityAction->LoadAllData($currentDate, $cityId, 'payments');
  89. show_window(__('Payments by city'), $perCityAction->PaymentsShow());
  90. } else {
  91. show_error(__('You cant control this module'));
  92. }
  93. }
  94. }
  95. }
  96. if ($action == 'permission') {
  97. if (cfr('CITYPERMISSION')) {
  98. if (isset($_GET['edit'])) {
  99. show_window(__('Cities'), $perCityAction->CityChecker($_GET['edit']));
  100. if (isset($_POST['city'])) {
  101. $adminsPermission = '';
  102. foreach ($_POST['city'] as $eachCity) {
  103. if ($eachCity == end($_POST['city'])) {
  104. $adminsPermission.= $eachCity;
  105. } else {
  106. $adminsPermission.= $eachCity . ",";
  107. }
  108. }
  109. file_put_contents(PerCityAction::PERMISSION_PATH . $_GET['edit'], $adminsPermission);
  110. rcms_redirect(PerCityAction::MODULE_NAME . "&action=permission&edit=" . $_GET['edit']);
  111. }
  112. } else {
  113. show_window(__('Admins'), $perCityAction->ListAdmins());
  114. }
  115. if (isset($_GET['delete'])) {
  116. if (!empty($_GET['delete'])) {
  117. if (file_exists(PerCityAction::PERMISSION_PATH . $_GET['delete'])) {
  118. unlink(PerCityAction::PERMISSION_PATH . $_GET['delete']);
  119. rcms_redirect(PerCityAction::MODULE_NAME . "&action=permission");
  120. } else {
  121. rcms_redirect(PerCityAction::MODULE_NAME . "&action=permission");
  122. }
  123. } else {
  124. rcms_redirect(PerCityAction::MODULE_NAME . "&action=permission");
  125. }
  126. }
  127. } else {
  128. show_error(__('You cant control this module'));
  129. }
  130. }
  131. if ($action == 'analytics') {
  132. show_window(__('By date'), $perCityAction->CitySelector($admin, $action));
  133. show_window('', $perCityAction->ChooseDateForm($action));
  134. if (isset($_GET['from_date']) && isset($_GET['to_date']) && isset($_GET['citysearch'])) {
  135. $perCityAction->LoadAllData('', $_GET['citysearch'], 'analytics', $_GET['from_date'], $_GET['to_date']);
  136. show_window(__('Analytics'), $perCityAction->AnalyticsShow());
  137. } elseif (isset($_GET['by_day']) && isset($_GET['citysearch'])) {
  138. $perCityAction->LoadAllData('', $_GET['citysearch'], 'analytics', '', '', $_GET['by_day']);
  139. show_window(__('Analytics'), $perCityAction->AnalyticsShow());
  140. }
  141. }
  142. }
  143. } else {
  144. show_error(__('You cant control this module'));
  145. }
  146. } else {
  147. show_error(__('This module is disabled'));
  148. }