widget_fastsms.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. class widget_fastsms extends TaskbarWidget {
  3. /**
  4. * Contains system alter config as key=>value
  5. *
  6. * @var array
  7. */
  8. protected $altCfg = array();
  9. /**
  10. * UbillingSMS object placeholder
  11. *
  12. * @var object
  13. */
  14. protected $sms = '';
  15. const TASKBAR_URL = '?module=taskbar';
  16. /**
  17. * Creates new widget_fastsms instance
  18. *
  19. * @return void
  20. */
  21. public function __construct() {
  22. $this->loadAlter();
  23. $this->initSMS();
  24. }
  25. /**
  26. * Loads system alter config into protected prop for further usage
  27. *
  28. * @global object $ubillingConfig
  29. *
  30. * @return void
  31. */
  32. protected function loadAlter() {
  33. global $ubillingConfig;
  34. $this->altCfg = $ubillingConfig->getAlter();
  35. }
  36. /**
  37. * Initalizes system SMS sending abstraction layer
  38. *
  39. * @return void
  40. */
  41. protected function initSMS() {
  42. $this->sms = new UbillingSMS();
  43. }
  44. /**
  45. * Returns SMS sending form
  46. *
  47. * @return string
  48. */
  49. protected function smsSendForm() {
  50. $result = '';
  51. $inputs = wf_TextInput('fastsmsnumber', __('Mobile'), '', true, '20');
  52. $inputs.= wf_TextArea('fastsmsmessage', '', '', true, '30x5');
  53. $inputs.= wf_CheckInput('fastsmstranslit', __('Forced transliteration'), true, true);
  54. $inputs.= wf_Submit(__('Create'));
  55. $form = wf_Form('', 'POST', $inputs, 'glamour');
  56. //displaying sending form as button or inline taskbar form
  57. if ($this->altCfg['WIDGET_FASTSMS'] == 1) {
  58. $result = wf_modalAuto(wf_img('skins/icon_mobile.gif', __('Create new SMS')) . ' ' . __('Send SMS'), __('Create new SMS'), $form, 'ubButton');
  59. }
  60. if ($this->altCfg['WIDGET_FASTSMS'] == 2) {
  61. $result = $form;
  62. }
  63. return ($result);
  64. }
  65. /**
  66. * Catches form sending request and performs SMS queue storing
  67. *
  68. * @return void
  69. */
  70. protected function catchSMSSending() {
  71. if (wf_CheckPost(array('fastsmsnumber', 'fastsmsmessage'))) {
  72. $translitFlag = (wf_CheckPost(array('fastsmstranslit'))) ? true : false;
  73. $this->sms->sendSMS($_POST['fastsmsnumber'], $_POST['fastsmsmessage'], $translitFlag, 'WIDGET_FASTSMS');
  74. //preventing sms resending on page refresh
  75. rcms_redirect(self::TASKBAR_URL);
  76. }
  77. }
  78. /**
  79. * Runs and renders widget code
  80. *
  81. * @return string
  82. */
  83. public function render() {
  84. $result = '';
  85. if ($this->altCfg['SENDDOG_ENABLED']) {
  86. //performs sms sending if required
  87. $this->catchSMSSending();
  88. //rendering sending form
  89. $result.=$this->widgetContainer($this->smsSendForm());
  90. } else {
  91. $messages = new UbillingMessageHelper();
  92. $result = $messages->getStyledMessage(__('SendDog') . ' ' . __('Disabled') . ' :(', 'error');
  93. }
  94. return ($result);
  95. }
  96. }
  97. ?>