api.messagesqueue.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <?php
  2. /**
  3. * System-wide outcoming messages queue for SMS/Telegram/Emails etc..
  4. */
  5. class MessagesQueue {
  6. /**
  7. * Message helper object placeholder
  8. *
  9. * @var object
  10. */
  11. protected $messages = '';
  12. /**
  13. * SMS system queue object placeholder
  14. *
  15. * @var object
  16. */
  17. protected $sms = '';
  18. /**
  19. * Email queue object placeholder
  20. *
  21. * @var object
  22. */
  23. protected $email = '';
  24. /**
  25. * PHPMail queue object placeholder
  26. *
  27. * @var object
  28. */
  29. protected $phpMail = '';
  30. /**
  31. * Telegram system queue object placeholder
  32. *
  33. * @var object
  34. */
  35. protected $telegram = '';
  36. /**
  37. * System json helper object placeholder
  38. *
  39. * @var object
  40. */
  41. protected $json = '';
  42. /**
  43. * Base module URL and another routes here
  44. */
  45. const URL_ME = '?module=tsmsqueue';
  46. const ROUTE_SMSFLUSH = 'flushallsms';
  47. const ROUTE_TLGFLUSH = 'flushalltelegram';
  48. public function __construct() {
  49. $this->initMessages();
  50. $this->initJson();
  51. $this->initSystemQueues();
  52. }
  53. /**
  54. * Inits default messages helper object
  55. *
  56. * @return void
  57. */
  58. protected function initMessages() {
  59. $this->messages = new UbillingMessageHelper();
  60. }
  61. /**
  62. * Creates protected instances of UbillingSMS, UbillingMail and UbillingTelegram classes for further usage
  63. *
  64. * @return void
  65. */
  66. protected function initSystemQueues() {
  67. $this->sms = new UbillingSMS();
  68. $this->email = new UbillingMail();
  69. $this->phpMail = new UbillingPHPMail();
  70. $this->telegram = new UbillingTelegram();
  71. }
  72. /**
  73. * Inits json datatables helper object
  74. *
  75. * @return void
  76. */
  77. protected function initJson() {
  78. $this->json = new wf_JqDtHelper();
  79. }
  80. /**
  81. * Renders one sms data into human readeble preview
  82. *
  83. * @param array $data
  84. *
  85. * @return string
  86. */
  87. protected function smsPreview($data) {
  88. $result = '';
  89. if (!empty($data)) {
  90. $smsDataCells = wf_TableCell(__('Mobile'), '', 'row2');
  91. $smsDataCells .= wf_TableCell($data['number']);
  92. $smsDataRows = wf_TableRow($smsDataCells, 'row3');
  93. $smsDataCells = wf_TableCell(__('Message'), '', 'row2');
  94. $smsDataCells .= wf_TableCell($data['message']);
  95. $smsDataRows .= wf_TableRow($smsDataCells, 'row3');
  96. $result = wf_TableBody($smsDataRows, '100%', '0', 'glamour');
  97. }
  98. return ($result);
  99. }
  100. /**
  101. * Renders one email queue element in human readeble preview
  102. *
  103. * @param array $data
  104. *
  105. * @return string
  106. */
  107. protected function emailPreview($data) {
  108. $result = '';
  109. if (!empty($data)) {
  110. $dataCells = wf_TableCell(__('Email'), '', 'row2');
  111. $dataCells .= wf_TableCell($data['email']);
  112. $dataRows = wf_TableRow($dataCells, 'row3');
  113. $dataCells = wf_TableCell(__('Subject'), '', 'row2');
  114. $dataCells .= wf_TableCell($data['subj']);
  115. $dataRows .= wf_TableRow($dataCells, 'row3');
  116. $dataCells = wf_TableCell(__('Message'), '', 'row2');
  117. $dataCells .= wf_TableCell($data['message']);
  118. $dataRows .= wf_TableRow($dataCells, 'row3');
  119. $result = wf_TableBody($dataRows, '100%', '0', 'glamour');
  120. }
  121. return ($result);
  122. }
  123. /**
  124. * Renders one telegram queue element in human readeble preview
  125. *
  126. * @param array $data
  127. *
  128. * @return string
  129. */
  130. protected function telegramPreview($data) {
  131. $result = '';
  132. if (!empty($data)) {
  133. $messageText = nl2br($data['message']);
  134. $dataCells = wf_TableCell(__('Chat ID'), '', 'row2');
  135. $dataCells .= wf_TableCell($data['chatid']);
  136. $dataRows = wf_TableRow($dataCells, 'row3');
  137. $dataCells = wf_TableCell(__('Message'), '', 'row2', 'valign="top"');
  138. $dataCells .= wf_TableCell($messageText);
  139. $dataRows .= wf_TableRow($dataCells, 'row3');
  140. $result = wf_TableBody($dataRows, '100%', '0', 'glamour');
  141. }
  142. return ($result);
  143. }
  144. /**
  145. * Renders list of available SMS in queue container
  146. *
  147. * @return string
  148. */
  149. public function renderSmsQueue() {
  150. $result = '';
  151. $smsQueueCount = $this->sms->getQueueCount();
  152. if ($smsQueueCount > 0) {
  153. if ($this->sms->smsRoutingFlag) {
  154. $columns = array('Date', 'Mobile', __('SMS service'), 'Actions');
  155. } else {
  156. $columns = array('Date', 'Mobile', 'Actions');
  157. }
  158. $result .= wf_JqDtLoader($columns, self::URL_ME . '&ajaxsms=true', false, __('SMS'), 100, '"order": [[ 0, "desc" ]]');
  159. } else {
  160. $result .= $this->messages->getStyledMessage(__('Nothing found'), 'info');
  161. }
  162. return ($result);
  163. }
  164. /**
  165. * Renders JSON list of available SMS in queue with some controls
  166. *
  167. * @return void
  168. */
  169. public function renderSMSAjaxQueue() {
  170. $smsQueue = $this->sms->getQueueData();
  171. if (!empty($smsQueue)) {
  172. /**
  173. * dakara ima ichibyou goto ni sekaisen wo koete
  174. * kimi no sono egao mamoritai no sa
  175. * soshite mata kanashimi no nai jikan no RUUPU e to
  176. * nomikomarete yuku kodoku no kansokusha
  177. */
  178. foreach ($smsQueue as $io => $each) {
  179. $actLinks = wf_modalAuto(wf_img('skins/icon_search_small.gif', __('Preview')), __('Preview'), $this->smsPreview($each), '');
  180. $actLinks .= wf_JSAlert(self::URL_ME . '&deletesms=' . $each['filename'], web_delete_icon(), $this->messages->getDeleteAlert());
  181. $data[] = $each['date'];
  182. $data[] = $each['number'];
  183. if ($this->sms->smsRoutingFlag) {
  184. $data[] = $this->sms->smsDirections->getDirectionNameById($each['smssrvid']);
  185. }
  186. $data[] = $actLinks;
  187. $this->json->addRow($data);
  188. unset($data);
  189. }
  190. }
  191. $this->json->getJson();
  192. }
  193. /**
  194. * Renders list of available emails in queue container
  195. *
  196. * @return string
  197. */
  198. public function renderEmailQueue() {
  199. $result = '';
  200. $queueCount = $this->email->getQueueCount();
  201. if ($queueCount > 0) {
  202. $columns = array('Date', 'Email', 'Actions');
  203. $result .= wf_JqDtLoader($columns, self::URL_ME . '&showqueue=email&ajaxmail=true', false, __('Email'), 100, '"order": [[ 0, "desc" ]]');
  204. } else {
  205. $result .= $this->messages->getStyledMessage(__('Nothing found'), 'info');
  206. }
  207. return ($result);
  208. }
  209. /**
  210. * Renders JSON list of available emails in queue with some control
  211. *
  212. * @return void
  213. */
  214. public function renderEmailAjaxQueue() {
  215. $queue = $this->email->getQueueData();
  216. if (!empty($queue)) {
  217. foreach ($queue as $io => $each) {
  218. $actLinks = wf_modalAuto(wf_img('skins/icon_search_small.gif', __('Preview')), __('Preview'), $this->emailPreview($each), '');
  219. $actLinks .= wf_JSAlert(self::URL_ME . '&showqueue=email&deleteemail=' . $each['filename'], web_delete_icon(), $this->messages->getDeleteAlert());
  220. $data[] = $each['date'];
  221. $data[] = $each['email'];
  222. $data[] = $actLinks;
  223. $this->json->addRow($data);
  224. unset($data);
  225. }
  226. }
  227. $this->json->getJson();
  228. }
  229. /**
  230. * Renders list of available telegram messages in queue container
  231. *
  232. * @return string
  233. */
  234. public function renderTelegramQueue() {
  235. $result = '';
  236. $queueCount = $this->telegram->getQueueCount();
  237. if ($queueCount > 0) {
  238. $columns = array('Date', 'Chat ID', 'Actions');
  239. $result .= wf_JqDtLoader($columns, self::URL_ME . '&showqueue=telegram&ajaxtelegram=true', false, __('Message'), 100, '"order": [[ 0, "desc" ]]');
  240. } else {
  241. $result .= $this->messages->getStyledMessage(__('Nothing found'), 'info');
  242. }
  243. return ($result);
  244. }
  245. /**
  246. * Renders JSON list of available telegram messages in queue with some controls
  247. *
  248. * @return void
  249. */
  250. public function renderTelegramAjaxQueue() {
  251. $queue = $this->telegram->getQueueData();
  252. if (!empty($queue)) {
  253. foreach ($queue as $io => $each) {
  254. $actLinks = wf_modalAuto(wf_img('skins/icon_search_small.gif', __('Preview')), __('Preview'), $this->telegramPreview($each), '');
  255. $actLinks .= wf_JSAlert(self::URL_ME . '&showqueue=telegram&deletetelegram=' . $each['filename'], web_delete_icon(), $this->messages->getDeleteAlert());
  256. $data[] = $each['date'];
  257. $data[] = $each['chatid'];
  258. $data[] = $actLinks;
  259. $this->json->addRow($data);
  260. unset($data);
  261. }
  262. }
  263. $this->json->getJson();
  264. }
  265. /**
  266. * Deletes SMS from local queue
  267. *
  268. * @param string $filename Existing sms filename
  269. *
  270. * @return int 0 - ok, 1 - deletion unsuccessful, 2 - file not found
  271. */
  272. public function deleteSms($filename) {
  273. $result = $this->sms->deleteSms($filename);
  274. return ($result);
  275. }
  276. /**
  277. * Flushes all available messages from SMS queue
  278. *
  279. * @return void
  280. */
  281. public function flushSmsQueue() {
  282. $allMessages = $this->sms->getQueueData();
  283. $cleanupCount = 0;
  284. if (!empty($allMessages)) {
  285. foreach ($allMessages as $io => $each) {
  286. $deletionResult = $this->sms->deleteSms($each['filename']);
  287. if ($deletionResult == 0) {
  288. $cleanupCount++;
  289. log_register('USMS FLUSH MESSAGE FOR `' . $each['number'] . '` AS `' . $each['filename'] . '`');
  290. }
  291. }
  292. }
  293. log_register('USMS FLUSHED `' . $cleanupCount . '` MESSAGES');
  294. }
  295. /**
  296. * Returns SMS queue messages count
  297. *
  298. * @return int
  299. */
  300. public function getSmsQueueCount() {
  301. return($this->sms->getQueueCount());
  302. }
  303. /**
  304. * Deletes email from local queue
  305. *
  306. * @param string $filename Existing email filename
  307. *
  308. * @return int
  309. */
  310. public function deleteEmail($filename) {
  311. $result = $this->email->deleteEmail($filename);
  312. return ($result);
  313. }
  314. /**
  315. * Deletes existing telegram message from queue
  316. *
  317. * @param string $filename
  318. *
  319. * @return int
  320. */
  321. public function deleteTelegram($filename) {
  322. $result = $this->telegram->deleteMessage($filename);
  323. return ($result);
  324. }
  325. /**
  326. * Flushes all available messages from SMS queue
  327. *
  328. * @return void
  329. */
  330. public function flushTelegramQueue() {
  331. $allMessages = $this->telegram->getQueueData();
  332. $cleanupCount = 0;
  333. if (!empty($allMessages)) {
  334. foreach ($allMessages as $io => $each) {
  335. $deletionResult = $this->telegram->deleteMessage($each['filename']);
  336. if ($deletionResult == 0) {
  337. $cleanupCount++;
  338. log_register('UTLG FLUSH MESSAGE FOR `' . $each['chatid'] . '` AS `' . $each['filename'] . '`');
  339. }
  340. }
  341. }
  342. log_register('UTLG FLUSHED `' . $cleanupCount . '` MESSAGES');
  343. }
  344. /**
  345. * Returns Telegram messages queue count
  346. *
  347. * @return int
  348. */
  349. public function getTelegramQueueCount() {
  350. return($this->telegram->getQueueCount());
  351. }
  352. /**
  353. * Deletes SendDog PID file
  354. *
  355. * @return void
  356. */
  357. public function calmTheDog() {
  358. $sendogPidFile = SendDog::PID_PATH;
  359. if (file_exists($sendogPidFile)) {
  360. unlink($sendogPidFile);
  361. log_register('SENDDOG PID DESTROY');
  362. }
  363. }
  364. /**
  365. * Runs SendDog queues processing
  366. *
  367. * @return int 1 - ok, 0 - already running
  368. */
  369. public function runTheDog() {
  370. $result = 1;
  371. $sendogPidFile = SendDog::PID_PATH;
  372. //senddog isnt running now?
  373. if (!file_exists($sendogPidFile)) {
  374. //im to lazy to do this in normal way
  375. $command = '/bin/ubapi senddog';
  376. shell_exec($command);
  377. log_register('SENDDOG MANUAL RUN');
  378. } else {
  379. $result = 0;
  380. log_register('SENDDOG ALREADY RUNS');
  381. }
  382. return($result);
  383. }
  384. /**
  385. * Renders module control panel
  386. *
  387. * @return string
  388. */
  389. public function renderPanel($phpMailerOn = false) {
  390. $result = '';
  391. $result .= wf_Link(self::URL_ME, wf_img('skins/icon_sms_micro.gif') . ' ' . __('SMS in queue'), false, 'ubButton');
  392. $result .= wf_Link(self::URL_ME . '&showqueue=email', wf_img('skins/icon_mail.gif') . ' ' . __('Emails in queue'), false, 'ubButton');
  393. $result .= ($phpMailerOn) ? wf_Link(self::URL_ME . '&showqueue=phpmail', wf_img('skins/icon_mail.gif') . ' PHPMailer: ' . __('Emails in queue'), false, 'ubButton') : '';
  394. $result .= wf_Link(self::URL_ME . '&showqueue=telegram', wf_img_sized('skins/icon_telegram_small.png', '', '10', '10') . ' ' . __('Telegram messages queue'), false, 'ubButton') . ' ';
  395. $sendogPidFile = SendDog::PID_PATH;
  396. $indicatorStyle = 'float:right;';
  397. $dogIndicator = '';
  398. if (file_exists($sendogPidFile)) {
  399. $lastDogWalkTime = @file_get_contents($sendogPidFile);
  400. $dogIndicator = wf_img('skins/dog_stand.png', __('SendDog is working') . ' ' . __('from') . ' ' . $lastDogWalkTime, $indicatorStyle);
  401. if (cfr('ROOT')) {
  402. $stopForm = '';
  403. $stopForm .= wf_tag('center') . wf_img('skins/dog_stand.png') . wf_tag('center', true);
  404. $stopForm .= __('SendDog is working') . ' ' . __('from') . ' ' . $lastDogWalkTime;
  405. $stopForm .= wf_CleanDiv();
  406. $stopForm .= wf_delimiter(0);
  407. $inputs = wf_HiddenInput('calmthedog', 'true');
  408. $inputs .= wf_Submit(__('Calm the dog'));
  409. $stopForm .= wf_Form('', 'POST', $inputs, 'glamour');
  410. $dogIndicator = wf_modalAuto($dogIndicator, __('Manage'), $stopForm);
  411. }
  412. } else {
  413. $dogIndicator = wf_img('skins/dog_sleep.png', __('SendDog is sleeping'), $indicatorStyle);
  414. if (cfr('ROOT')) {
  415. $runForm = '';
  416. $runForm .= wf_tag('center') . wf_img('skins/dog_sleep.png') . wf_tag('center', true);
  417. $runForm .= __('SendDog is sleeping');
  418. $runForm .= wf_CleanDiv();
  419. $runForm .= wf_delimiter(0);
  420. $inputs = wf_HiddenInput('runthedog', 'true');
  421. $inputs .= wf_Submit(__('Run the dog'));
  422. $runForm .= wf_Form('', 'POST', $inputs, 'glamour');
  423. $dogIndicator = wf_modalAuto($dogIndicator, __('Manage'), $runForm);
  424. }
  425. }
  426. $result .= $dogIndicator;
  427. return ($result);
  428. }
  429. /**
  430. * Returns modal window with SMS creation form
  431. *
  432. * @return string
  433. */
  434. public function smsCreateForm() {
  435. $result = '';
  436. $inputs = wf_TextInput('newsmsnumber', __('Mobile'), '', true, '20');
  437. $inputs .= wf_TextArea('newsmsmessage', '', '', true, '30x5');
  438. $inputs .= wf_CheckInput('newsmstranslit', __('Forced transliteration'), true, true);
  439. $inputs .= wf_Submit(__('Create'));
  440. $form = wf_Form('', 'POST', $inputs, 'glamour');
  441. $result = wf_modalAuto(wf_img('skins/add_icon.png', __('Create new SMS')), __('Create new SMS'), $form, '');
  442. return ($result);
  443. }
  444. /**
  445. * Creates new SMS for queue
  446. *
  447. * @param string $number
  448. * @param string $message
  449. *
  450. * @return string/void
  451. */
  452. public function createSMS($number, $message) {
  453. $result = '';
  454. $translit = (wf_CheckPost(array('newsmstranslit'))) ? true : false;
  455. if (ispos($number, '+')) {
  456. $this->sms->sendSMS($number, $message, $translit, 'TQUEUE');
  457. } else {
  458. $result = __('Number must be in international format');
  459. }
  460. return ($result);
  461. }
  462. /**
  463. * Returns modal window with email creation form
  464. *
  465. * @return string
  466. */
  467. public function emailCreateForm() {
  468. $result = '';
  469. $inputs = wf_TextInput('newemailaddress', __('Email'), '', true, '20');
  470. $inputs .= wf_TextInput('newemailsubj', __('Subject'), '', true, '40');
  471. $inputs .= wf_TextArea('newemailmessage', '', '', true, '50x10');
  472. $inputs .= wf_Submit(__('Create'));
  473. $form = wf_Form('', 'POST', $inputs, 'glamour');
  474. $result = wf_modalAuto(wf_img('skins/add_icon.png', __('Create new email')), __('Create new email'), $form, '');
  475. return ($result);
  476. }
  477. /**
  478. * Creates new email message in queue
  479. *
  480. *
  481. * @param string $email
  482. * @param string $subj
  483. * @param string $messages
  484. *
  485. * @return string/void
  486. */
  487. public function createEmail($email, $subj, $message) {
  488. $result = '';
  489. if ((!empty($email)) AND ( !empty($message)) AND ( !empty($subj))) {
  490. $this->email->sendEmail($email, $subj, $message, 'TQUEUE');
  491. } else {
  492. $result = __('Not all of required fields are filled');
  493. }
  494. return ($result);
  495. }
  496. /**
  497. * Returns modal window with telegram message creation form
  498. *
  499. * @return string
  500. */
  501. public function telegramCreateForm() {
  502. $result = '';
  503. $inputs = wf_TextInput('newtelegramchatid', __('Chat ID'), '', true, '20');
  504. $inputs .= wf_TextArea('newtelegrammessage', '', '', true, '50x10');
  505. $inputs .= wf_Submit(__('Create'));
  506. $form = wf_Form('', 'POST', $inputs, 'glamour');
  507. $result = wf_modalAuto(wf_img('skins/add_icon.png', __('Create new Telegram message')), __('Create new Telegram message'), $form, '');
  508. return ($result);
  509. }
  510. /**
  511. * Creates new telegram message in queue
  512. *
  513. * @param string $chatid
  514. * @param string $message
  515. *
  516. * @return string
  517. */
  518. public function createTelegram($chatid, $message) {
  519. $result = '';
  520. if ((!empty($chatid)) AND ( !empty($message))) {
  521. $this->telegram->sendMessage($chatid, $message, false, 'TQUEUE');
  522. } else {
  523. $result = __('Not all of required fields are filled');
  524. }
  525. return ($result);
  526. }
  527. /**
  528. * Renders one PHPMailer queue element in human readable preview
  529. *
  530. * @param array $data
  531. *
  532. * @return string
  533. */
  534. protected function phpMailPreview($data) {
  535. $result = '';
  536. if (!empty($data)) {
  537. $dataCells = wf_TableCell(__('Email'), '', 'row2');
  538. $dataCells .= wf_TableCell($data['email']);
  539. $dataRows = wf_TableRow($dataCells, 'row3');
  540. $dataCells = wf_TableCell(__('Subject'), '', 'row2');
  541. $dataCells .= wf_TableCell($data['subj']);
  542. $dataRows .= wf_TableRow($dataCells, 'row3');
  543. $dataCells = wf_TableCell(__('Message'), '', 'row2');
  544. $dataCells .= wf_TableCell($data['message']);
  545. $dataRows .= wf_TableRow($dataCells, 'row3');
  546. $dataCells = wf_TableCell(__('Attach path'), '', 'row2');
  547. $dataCells .= wf_TableCell($data['attachpath']);
  548. $dataRows .= wf_TableRow($dataCells, 'row3');
  549. $dataCells = wf_TableCell(__('Body as HTML'), '', 'row2');
  550. $dataCells .= wf_TableCell(($data['bodyashtml']) ? web_green_led() : web_red_led());
  551. $dataRows .= wf_TableRow($dataCells, 'row3');
  552. $dataCells = wf_TableCell(__('From'), '', 'row2');
  553. $dataCells .= wf_TableCell($data['from']);
  554. $dataRows .= wf_TableRow($dataCells, 'row3');
  555. $dataCells = wf_TableCell(__('Custom headers'), '', 'row2');
  556. $dataCells .= wf_TableCell((empty($data['customheaders'])) ? web_red_led() : web_green_led());
  557. $dataRows .= wf_TableRow($dataCells, 'row3');
  558. $result = wf_TableBody($dataRows, '100%', '0', 'glamour');
  559. }
  560. return ($result);
  561. }
  562. /**
  563. * Renders list of available PHPMailer emails in queue container
  564. *
  565. * @return string
  566. */
  567. public function renderPHPMailQueue() {
  568. $result = '';
  569. $queueCount = $this->phpMail->getQueueCount();
  570. $ajaxURL = '&showqueue=phpmail&ajaxphpmail=true';
  571. if ($queueCount > 0) {
  572. $columns = array('Date', 'Email', 'Actions');
  573. $result .= wf_JqDtLoader($columns, self::URL_ME . $ajaxURL, false, __('Email'), 100, '"order": [[ 0, "desc" ]]');
  574. } else {
  575. $result .= $this->messages->getStyledMessage(__('Nothing found'), 'info');
  576. }
  577. return ($result);
  578. }
  579. /**
  580. * Renders JSON list of available PHPMailer emails in queue with some controls
  581. *
  582. * @return void
  583. */
  584. public function renderPHPMailAjaxQueue() {
  585. $queue = $this->phpMail->getQueueData();
  586. $delURL = '&showqueue=phpmail&deletephpmail=';
  587. if (!empty($queue)) {
  588. foreach ($queue as $io => $each) {
  589. $actLinks = wf_modalAuto(wf_img('skins/icon_search_small.gif', __('Preview')), __('Preview'), $this->phpMailPreview($each), '');
  590. $actLinks .= wf_JSAlert(self::URL_ME . $delURL . $each['filename'], web_delete_icon(), $this->messages->getDeleteAlert());
  591. $data[] = $each['date'];
  592. $data[] = $each['email'];
  593. $data[] = $actLinks;
  594. $this->json->addRow($data);
  595. unset($data);
  596. }
  597. }
  598. $this->json->getJson();
  599. }
  600. /**
  601. * Deletes email from local queue
  602. *
  603. * @param string $filename Existing email filename
  604. *
  605. * @return int
  606. */
  607. public function deletePHPMail($filename) {
  608. $result = $this->phpMail->deleteEmail($filename);
  609. return ($result);
  610. }
  611. /**
  612. * Returns modal window with email creation form
  613. *
  614. * @return string
  615. */
  616. public function phpMailCreateForm() {
  617. $result = '';
  618. $inputs = wf_TextInput('newemailaddress', __('Email'), '', true, '20');
  619. $inputs .= wf_TextInput('newemailfrom', __('From'), '', true, '20');
  620. $inputs .= wf_CheckInput('newmailbodyashtml', __('Body as HTML'), true);
  621. $inputs .= wf_TextInput('newemailsubj', __('Subject'), '', true, '40');
  622. $inputs .= wf_TextArea('newemailmessage', '', '', true, '50x10');
  623. $inputs .= __('Add attachment') . ' <input id="fileselector" type="file" name="newmailattach" size="10" />' . wf_delimiter(0);
  624. $inputs .= wf_delimiter(0);
  625. $inputs .= wf_Submit(__('Create'));
  626. $form = bs_UploadFormBody('', 'POST', $inputs, 'glamour');
  627. $result = wf_modalAuto(wf_img('skins/add_icon.png', __('Create new email')), __('Create new email'), $form, '');
  628. return ($result);
  629. }
  630. /**
  631. * Creates new PHPMail message in queue
  632. *
  633. * @param string $email
  634. * @param string $subj
  635. * @param string $messages
  636. * @param string $attachPath
  637. * @param bool $bodyAsHTML
  638. * @param string $from
  639. *
  640. * @return string/void
  641. */
  642. public function createPHPMail($email, $subj, $message, $attachPath = '', $bodyAsHTML = false, $from = '') {
  643. $result = '';
  644. if ((!empty($email)) AND ( !empty($message)) AND ( !empty($subj))) {
  645. $this->phpMail->sendEmail($email, $subj, $message, $attachPath, $bodyAsHTML, $from, array(), 'TQUEUE');
  646. } else {
  647. $result = __('Not all of required fields are filled');
  648. }
  649. return ($result);
  650. }
  651. /**
  652. * Uploads attachment file for further processing
  653. *
  654. * @return string
  655. */
  656. public function uploadAttach() {
  657. $result = '';
  658. $uploaddir = $this->phpMail->mailerAttachPath;
  659. $uploadfile = $uploaddir . vf($_FILES['newmailattach']['name']);
  660. if (move_uploaded_file($_FILES['newmailattach']['tmp_name'], $uploadfile)) {
  661. $result = $uploadfile;
  662. }
  663. return ($result);
  664. }
  665. }
  666. ?>