index.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. if (cfr('TICKETING')) {
  3. class ReportUsersTicketing {
  4. /**
  5. * Contains all previous tickets data by some user
  6. *
  7. * @var array
  8. */
  9. protected $alltickets = array();
  10. public function __construct($login) {
  11. $this->alltickets = $this->loadTickets($login);
  12. }
  13. /*
  14. * load all previous user tickets from database
  15. *
  16. * @param $login existing user login
  17. *
  18. * @return array
  19. */
  20. protected function loadTickets($login) {
  21. $login = mysql_real_escape_string($login);
  22. $query = "SELECT `id`,`date`,`status`,`text` from `ticketing` WHERE `to` IS NULL AND `replyid` IS NULL AND `from`='" . $login . "' ORDER BY `date` DESC";
  23. $result = simple_queryall($query);
  24. return ($result);
  25. }
  26. /*
  27. * Renders report as normal grid
  28. *
  29. * @return string
  30. */
  31. public function render() {
  32. $result = '';
  33. if (!empty($this->alltickets)) {
  34. $cells = wf_TableCell(__('ID'));
  35. $cells .= wf_TableCell(__('Date'));
  36. $cells .= wf_TableCell(__('Text'));
  37. $cells .= wf_TableCell(__('Processed'));
  38. $cells .= wf_TableCell(__('Actions'));
  39. $rows = wf_TableRow($cells, 'row1');
  40. foreach ($this->alltickets as $io => $each) {
  41. $cells = wf_TableCell($each['id']);
  42. $cells .= wf_TableCell($each['date']);
  43. if (strlen($each['text']) > 140) {
  44. $textPreview = mb_substr(strip_tags($each['text']), 0, 140, 'utf-8') . '...';
  45. } else {
  46. $textPreview = strip_tags($each['text']);
  47. }
  48. $cells .= wf_TableCell($textPreview);
  49. $cells .= wf_TableCell(web_bool_led($each['status']));
  50. $cells .= wf_TableCell(wf_Link('?module=ticketing&showticket=' . $each['id'], wf_img_sized('skins/icon_search_small.gif', '', '12') . ' ' . __('Show'), false, 'ubButton'));
  51. $rows .= wf_TableRow($cells, 'row3');
  52. }
  53. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  54. } else {
  55. $messages = new UbillingMessageHelper();
  56. $result = $messages->getStyledMessage(__('Nothing found'), 'info');
  57. }
  58. return ($result);
  59. }
  60. /*
  61. * Renders report as fullcalendar widget
  62. *
  63. * @return string
  64. */
  65. public function renderCalendar() {
  66. $calendarData = '';
  67. if (!empty($this->alltickets)) {
  68. foreach ($this->alltickets as $io => $each) {
  69. $timestamp = strtotime($each['date']);
  70. $date = date("Y, n-1, j", $timestamp);
  71. $rawTime = date("H:i:s", $timestamp);
  72. $calendarData .= "
  73. {
  74. title: '" . $rawTime . "',
  75. url: '?module=ticketing&showticket=" . $each['id'] . "',
  76. start: new Date(" . $date . "),
  77. end: new Date(" . $date . "),
  78. },
  79. ";
  80. }
  81. }
  82. $result = wf_FullCalendar($calendarData);
  83. return ($result);
  84. }
  85. }
  86. if (wf_CheckGet(array('username'))) {
  87. $login = $_GET['username'];
  88. $reportTicketing = new ReportUsersTicketing($login);
  89. //controls
  90. $actionLinks = wf_Link('?module=pl_ticketing&username=' . $login, wf_img('skins/icon_table.png') . ' ' . __('Grid view'), false, 'ubButton');
  91. $actionLinks .= wf_Link('?module=pl_ticketing&username=' . $login . '&calendarview=true', wf_img('skins/icon_calendar.gif') . ' ' . __('As calendar'), false, 'ubButton');
  92. if (cfr('PLSENDMESSAGE')) {
  93. $actionLinks .= wf_Link('?module=pl_sendmessage&username=' . $login, wf_img('skins/icon_chat_small.png') . ' ' . __('Send message'), false, 'ubButton');
  94. }
  95. show_window('', $actionLinks);
  96. //display results
  97. if (!wf_CheckGet(array('calendarview'))) {
  98. show_window(__('Previous user tickets'), $reportTicketing->render());
  99. } else {
  100. show_window(__('Previous user tickets'), $reportTicketing->renderCalendar());
  101. }
  102. show_window('', web_UserControls($login));
  103. } else {
  104. show_error(__('User not exist'));
  105. }
  106. } else {
  107. show_error(__('You cant control this module'));
  108. }
  109. ?>