TurboSms.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. class TurboSms extends SMSServiceApi {
  3. public function __construct($smsServiceId, $smsPack = array()) {
  4. parent::__construct($smsServiceId, $smsPack);
  5. }
  6. public function getBalance() {
  7. $this->showErrorFeatureIsNotSupported();
  8. }
  9. public function getSMSQueue() {
  10. $result = '';
  11. $smsArray = array();
  12. $total = 0;
  13. $tsms_db = 'users';
  14. $TsmsDB = new DbConnect($this->serviceGatewayAddr, $this->serviceLogin, $this->servicePassword, $tsms_db, $error_reporting = true, $persistent = false);
  15. $TsmsDB->open() or die($TsmsDB->error());
  16. $TsmsDB->query('SET NAMES utf8;');
  17. if (wf_CheckPost(array('showdate'))) {
  18. $date = mysql_real_escape_string($_POST['showdate']);
  19. } else {
  20. $date = '';
  21. }
  22. if (!empty($date)) {
  23. $where = " WHERE `send_time` LIKE '" . $date . "%' ORDER BY `id` DESC;";
  24. } else {
  25. $where = ' ORDER BY `id` DESC LIMIT 50;';
  26. }
  27. $query = "SELECT * from `" . $this->serviceLogin . "`" . $where;
  28. $TsmsDB->query($query);
  29. while ($row = $TsmsDB->fetchassoc()) {
  30. $smsArray[] = $row;
  31. }
  32. //close old datalink
  33. $TsmsDB->close();
  34. //rendering result
  35. $formInputId = wf_InputId();
  36. $tableBlockId = wf_InputId();
  37. $inputs= wf_DatePickerPreset('showdate', curdate(), false, '', '__DatePickerSMS');
  38. $inputs.= wf_Submit(__('Show'));
  39. $dateform = wf_Form($this->instanceSendDog->getBaseUrl(), 'POST', $inputs, 'glamour __TSMSGetQueue', '', $formInputId);
  40. $cells = wf_TableCell(__('ID'));
  41. $cells.= wf_TableCell(__('Msg ID'));
  42. $cells.= wf_TableCell(__('Mobile'));
  43. $cells.= wf_TableCell(__('Sign'));
  44. $cells.= wf_TableCell(__('Message'));
  45. $cells.= wf_TableCell(__('Balance'));
  46. $cells.= wf_TableCell(__('Cost'));
  47. $cells.= wf_TableCell(__('Send time'));
  48. $cells.= wf_TableCell(__('Sended'));
  49. $cells.= wf_TableCell(__('Status'));
  50. $rows = wf_TableRow($cells, 'row1');
  51. if (!empty($smsArray)) {
  52. foreach ($smsArray as $io => $each) {
  53. $cells = wf_TableCell($each['id']);
  54. $cells.= wf_TableCell($each['msg_id']);
  55. $cells.= wf_TableCell($each['number']);
  56. $cells.= wf_TableCell($each['sign']);
  57. $msg = wf_modal(__('Show'), __('SMS'), $each['message'], '', '300', '200');
  58. $cells.= wf_TableCell($msg);
  59. $cells.= wf_TableCell($each['balance']);
  60. $cells.= wf_TableCell($each['cost']);
  61. $cells.= wf_TableCell($each['send_time']);
  62. $cells.= wf_TableCell($each['sended']);
  63. $cells.= wf_TableCell($each['status']);
  64. $rows.=wf_TableRow($cells, 'row5');
  65. $total++;
  66. }
  67. }
  68. $result.= $dateform;
  69. $result.= wf_tag('div', false, '', 'id="' . $tableBlockId . '"');
  70. $result.= wf_TableBody($rows, '100%', '0', 'sortable');
  71. $result.= __('Total') . ': ' . $total;
  72. $result.= wf_tag('div', true);
  73. $result.= wf_tag('script', false, '', 'type="text/javascript"');
  74. $result.= ' $(\'#' . $_POST['ModalWBID'] . '\').append($(\'#' . $formInputId .'\'));
  75. $(\'#' . $_POST['ModalWBID'] . '\').append($(\'#' . $tableBlockId .'\'));
  76. $(document).on("submit", ".__TSMSGetQueue", function(evt) {
  77. var FrmData = $(".__TSMSGetQueue").serialize() + \'&SMSAPIName=' . get_class($this) . '&smssrvid=' . $this->serviceId . '&modalWindowId=' . $_POST['modalWindowId'] . '&ModalWBID=' . $_POST['ModalWBID'] . '&action=getSMSQueue' . '\';
  78. var FrmAction = $(".__TSMSGetQueue").attr("action");
  79. evt.preventDefault();
  80. $.ajax({
  81. type: "POST",
  82. url: FrmAction,
  83. data: FrmData,
  84. success: function(result) {
  85. $(\'#' . $_POST['ModalWBID'] . '\').html(result);
  86. }
  87. });
  88. });
  89. ';
  90. $result.= wf_tag('script', true);
  91. $modalForm = wf_modalAutoForm(__('View SMS sending queue'), '', $_POST['modalWindowId'], $_POST['ModalWBID'], true, 'false', '888');
  92. die($result . $modalForm);
  93. }
  94. public function pushMessages() {
  95. $sign = $this->instanceSendDog->safeEscapeString($this->serviceAlphaName);
  96. $date = date("Y-m-d H:i:s");
  97. //$allSmsQueue = $this->smsQueue->getQueueData();
  98. $allSmsQueue = $this->smsMessagePack;
  99. if (!empty($allSmsQueue)) {
  100. //open new database connection
  101. $TsmsDB = new DbConnect($this->serviceGatewayAddr, $this->serviceLogin, $this->servicePassword, 'users', $error_reporting = true, $persistent = false);
  102. $TsmsDB->open() or die($TsmsDB->error());
  103. $TsmsDB->query('SET NAMES utf8;');
  104. foreach ($allSmsQueue as $eachsms) {
  105. if ((isset($eachsms['number'])) AND ( isset($eachsms['message']))) {
  106. $query = "INSERT INTO `" . $this->serviceLogin . "` ( `number`, `sign`, `message`, `wappush`, `send_time`)
  107. VALUES ('" . $eachsms['number'] . "', '" . $sign . "', '" . $eachsms['message'] . "', '', '" . $date . "');
  108. ";
  109. //push new sms to database
  110. $TsmsDB->query($query);
  111. }
  112. //remove old sent message
  113. $this->instanceSendDog->getSmsQueueInstance()->deleteSms($eachsms['filename']);
  114. }
  115. //close old datalink
  116. $TsmsDB->close();
  117. }
  118. }
  119. public function checkMessagesStatuses() {
  120. log_register('Checking statuses for [' . get_class($this) . '] SMS service is not implemented');
  121. }
  122. }
  123. ?>