send.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  3. * Copyright (C) 2020 Andreu Bisquerra Gaya <jove@bisquerra.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/takepos/send.php
  20. * \ingroup takepos
  21. * \brief Page with the content of the popup to enter payments
  22. */
  23. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
  24. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
  25. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
  27. if (!defined('NOTOKENRENEWAL')) {
  28. define('NOTOKENRENEWAL', '1');
  29. }
  30. if (!defined('NOREQUIREMENU')) {
  31. define('NOREQUIREMENU', '1');
  32. }
  33. if (!defined('NOREQUIREHTML')) {
  34. define('NOREQUIREHTML', '1');
  35. }
  36. if (!defined('NOREQUIREAJAX')) {
  37. define('NOREQUIREAJAX', '1');
  38. }
  39. // Load Dolibarr environment
  40. require '../main.inc.php'; // Load $user and permissions
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  42. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  43. $facid = GETPOST('facid', 'int');
  44. $action = GETPOST('action', 'aZ09');
  45. $email = GETPOST('email', 'alpha');
  46. if (!$user->hasRight('takepos', 'run')) {
  47. accessforbidden();
  48. }
  49. $langs->loadLangs(array("main", "bills", "cashdesk"));
  50. $invoice = new Facture($db);
  51. $invoice->fetch($facid);
  52. $customer = new Societe($db);
  53. $customer->fetch($invoice->socid);
  54. /*
  55. * Actions
  56. */
  57. if ($action == "send") {
  58. include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  59. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  60. $formmail = new FormMail($db);
  61. $outputlangs = new Translate('', $conf);
  62. $model_id = getDolGlobalString('TAKEPOS_EMAIL_TEMPLATE_INVOICE');
  63. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'facture_send', $user, $outputlangs, $model_id);
  64. $subject = $arraydefaultmessage->topic;
  65. ob_start(); // turn on output receipt
  66. include DOL_DOCUMENT_ROOT.'/takepos/receipt.php';
  67. $receipt = ob_get_contents(); // get the contents of the output buffer
  68. ob_end_clean();
  69. $msg = "<html>".$arraydefaultmessage->content."<br>".$receipt."</html>";
  70. $sendto = $email;
  71. $from = $mysoc->email;
  72. $mail = new CMailFile($subject, $sendto, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', '', '', '', '', DOL_DOCUMENT_ROOT.'/documents/takepos/temp');
  73. if ($mail->error || !empty($mail->errors)) {
  74. setEventMessages($mail->error, $mail->errors, 'errors');
  75. } else {
  76. $result = $mail->sendfile();
  77. }
  78. exit;
  79. }
  80. /*
  81. * View
  82. */
  83. $arrayofcss = array('/takepos/css/pos.css.php');
  84. $arrayofjs = array();
  85. top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
  86. ?>
  87. <body class="center">
  88. <script>
  89. function SendMail() {
  90. $.ajax({
  91. type: "GET",
  92. data: { token: '<?php echo currentToken(); ?>' },
  93. url: "<?php print DOL_URL_ROOT.'/takepos/send.php?action=send&token='.newToken().'&facid='.$facid.'&email='; ?>" + $("#email"). val(),
  94. });
  95. parent.$.colorbox.close();
  96. }
  97. </script>
  98. <div class="center">
  99. <center>
  100. <center>
  101. <input type="email" id="email" name="email" style="width:60%;font-size: 200%;" value="<?php echo $customer->email; ?>"></center>
  102. </center>
  103. </div>
  104. <br>
  105. <div class="center">
  106. <button type="button" class="calcbutton" onclick="SendMail()"><?php print $langs->trans("SendTicket"); ?></button>
  107. </div>
  108. </body>
  109. </html>