index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. if (cfr('CREDIT')) {
  3. $altCfg = $ubillingConfig->getAlter();
  4. if ($altCfg['SCREP_ENABLED']) {
  5. class ZBSSC {
  6. /**
  7. * System message helper object placeholder
  8. *
  9. * @var object
  10. */
  11. protected $messages = '';
  12. /**
  13. * current instance user login
  14. *
  15. * @var string
  16. */
  17. protected $userLogin = '';
  18. /**
  19. * Self credit log data source
  20. *
  21. * @var object
  22. */
  23. protected $scLog = '';
  24. /**
  25. * System manual credit data source
  26. *
  27. * @var object
  28. */
  29. protected $eventLog = '';
  30. /**
  31. * Contains raw report data loaded from datasource
  32. *
  33. * @var array
  34. */
  35. protected $allData = array();
  36. /**
  37. * Some other predefined stuff
  38. */
  39. const COLOR_MONTH = '#ed9c00';
  40. const COLOR_TODAY = '#ba0000';
  41. /**
  42. * Creates new report instance
  43. *
  44. * @param string $userLogin
  45. *
  46. * @return void
  47. */
  48. public function __construct($userLogin) {
  49. $this->setLogin($userLogin);
  50. $this->initMessages();
  51. $this->initDataSource();
  52. }
  53. /**
  54. * Inits system message helper
  55. *
  56. * @return void
  57. */
  58. protected function initMessages() {
  59. $this->messages = new UbillingMessageHelper();
  60. }
  61. /**
  62. * Inits data sources abstraction layers
  63. *
  64. * @return void
  65. */
  66. protected function initDataSource() {
  67. $this->scLog = new NyanORM('zbssclog');
  68. $this->eventLog = new NyanORM('weblogs');
  69. }
  70. /**
  71. * Sets current instance user login
  72. *
  73. * @param string $userLogin
  74. *
  75. * @return void
  76. */
  77. protected function setLogin($userLogin) {
  78. $this->userLogin = ubRouting::filters($userLogin, 'mres');
  79. }
  80. /**
  81. * Loads data from datasources into protected prop for further processing
  82. *
  83. * @return void
  84. */
  85. protected function loadData() {
  86. $this->scLog->where('login', '=', $this->userLogin);
  87. $tmpScData = $this->scLog->getAll('date');
  88. $this->eventLog->where('event', 'LIKE', '%CHANGE Credit (' . $this->userLogin . ')%');
  89. $tmpEventData = $this->eventLog->getAll('date');
  90. $dataTmp = $tmpScData + $tmpEventData;
  91. if (!empty($dataTmp)) {
  92. ksort($dataTmp); //normal ordering
  93. $this->allData = array_reverse($dataTmp);
  94. }
  95. }
  96. /**
  97. * Performs current day/month hilighting
  98. *
  99. * @param string $date
  100. * @param string $currentMonth
  101. * @param string $currentDay
  102. *
  103. * @return string
  104. */
  105. protected function colorize($date, $currentMonth, $currentDay) {
  106. $result = $date;
  107. if (ispos($date, $currentMonth)) {
  108. $result = wf_tag('font', false, '', 'color="' . self::COLOR_MONTH . '"') . $date . wf_tag('font', 'true');
  109. }
  110. if (ispos($date, $currentDay)) {
  111. $result = wf_tag('font', false, '', 'color="' . self::COLOR_TODAY . '"') . $date . wf_tag('font', 'true');
  112. }
  113. return($result);
  114. }
  115. /**
  116. * Renders self credit service report
  117. *
  118. * @return string
  119. */
  120. public function render() {
  121. $result = '';
  122. $curMonth = curmonth();
  123. $curDay = curdate();
  124. @$employeeNames = unserialize(ts_GetAllEmployeeLoginsCached());
  125. if (!empty($this->userLogin)) {
  126. $this->loadData();
  127. }
  128. if (!empty($this->allData)) {
  129. $cells = wf_TableCell(__('Date'));
  130. $cells .= wf_TableCell(__('Administrator'));
  131. $rows = wf_TableRow($cells, 'row1');
  132. foreach ($this->allData as $io => $each) {
  133. $cells = wf_TableCell($this->colorize($each['date'], $curMonth, $curDay));
  134. $adminLogin = 'external';
  135. if (isset($each['admin'])) {
  136. $adminLogin = $each['admin'];
  137. //existing employee admin
  138. if (isset($employeeNames[$adminLogin])) {
  139. $adminLogin = $employeeNames[$adminLogin];
  140. }
  141. }
  142. //userstats credit service
  143. if ($adminLogin == 'guest' OR $adminLogin == 'external') {
  144. $adminLogin = __('Userstats');
  145. }
  146. //dooms day tariffs optional credit on first month fee charge
  147. if (isset($each['event'])) {
  148. if (ispos($each['event'], 'DDT ')) {
  149. $adminLogin = __('Doomsday tariffs');
  150. }
  151. }
  152. $cells .= wf_TableCell($adminLogin);
  153. $rows .= wf_TableRow($cells, 'row5');
  154. }
  155. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  156. } else {
  157. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  158. }
  159. $result .= wf_delimiter();
  160. $result .= web_UserControls($this->userLogin);
  161. return($result);
  162. }
  163. }
  164. if (ubRouting::checkGet('username')) {
  165. $report = new ZBSSC(ubRouting::get('username'));
  166. show_window(__('Credits report'), $report->render());
  167. } else {
  168. show_error(__('Something went wrong') . ': ' . __('User not exists'));
  169. }
  170. } else {
  171. show_error(__('This module is disabled'));
  172. }
  173. } else {
  174. show_error(__('Permission denied'));
  175. }