dolibarr  17.0.3
send.php
Go to the documentation of this file.
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 
25 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
26 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
27 //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
28 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
29 if (!defined('NOTOKENRENEWAL')) {
30  define('NOTOKENRENEWAL', '1');
31 }
32 if (!defined('NOREQUIREMENU')) {
33  define('NOREQUIREMENU', '1');
34 }
35 if (!defined('NOREQUIREHTML')) {
36  define('NOREQUIREHTML', '1');
37 }
38 if (!defined('NOREQUIREAJAX')) {
39  define('NOREQUIREAJAX', '1');
40 }
41 
42 // Load Dolibarr environment
43 require '../main.inc.php'; // Load $user and permissions
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
45 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
46 
47 $facid = GETPOST('facid', 'int');
48 $action = GETPOST('action', 'aZ09');
49 $email = GETPOST('email', 'alpha');
50 
51 if (empty($user->rights->takepos->run)) {
53 }
54 
55 $langs->loadLangs(array("main", "bills", "cashdesk"));
56 
57 $invoice = new Facture($db);
58 $invoice->fetch($facid);
59 $customer = new Societe($db);
60 $customer->fetch($invoice->socid);
61 
62 
63 /*
64  * Actions
65  */
66 
67 if ($action == "send") {
68  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
69  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
70  $formmail = new FormMail($db);
71  $outputlangs = new Translate('', $conf);
72  $model_id = getDolGlobalString('TAKEPOS_EMAIL_TEMPLATE_INVOICE');
73  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'facture_send', $user, $outputlangs, $model_id);
74  $subject = $arraydefaultmessage->topic;
75 
76  ob_start(); // turn on output receipt
77  include DOL_DOCUMENT_ROOT.'/takepos/receipt.php';
78  $receipt = ob_get_contents(); // get the contents of the output buffer
79  ob_end_clean();
80 
81  $msg = "<html>".$arraydefaultmessage->content."<br>".$receipt."</html>";
82  $sendto = $email;
83  $from = $mysoc->email;
84  $mail = new CMailFile($subject, $sendto, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', '', '', '', '', DOL_DOCUMENT_ROOT.'/documents/takepos/temp');
85  if ($mail->error || !empty($mail->errors)) {
86  setEventMessages($mail->error, $mail->errors, 'errors');
87  } else {
88  $result = $mail->sendfile();
89  }
90  exit;
91 }
92 
93 
94 /*
95  * View
96  */
97 
98 $arrayofcss = array('/takepos/css/pos.css.php');
99 $arrayofjs = array();
100 top_htmlhead($head, '', 0, 0, $arrayofjs, $arrayofcss);
101 
102 ?>
103 <body class="center">
104 
105 <script>
106 function SendMail() {
107  $.ajax({
108  type: "GET",
109  data: { token: '<?php echo currentToken(); ?>' },
110  url: "<?php print DOL_URL_ROOT.'/takepos/send.php?action=send&token='.newToken().'&facid='.$facid.'&email='; ?>" + $("#email"). val(),
111  });
112  parent.$.colorbox.close();
113 }
114 
115 </script>
116 
117 <div class="center">
118 <center>
119 <center>
120 <input type="email" id="email" name="email" style="width:60%;font-size: 200%;" value="<?php echo $customer->email; ?>"></center>
121 </center>
122 </div>
123 <br>
124 <div class="center">
125 
126 <button type="button" class="calcbutton" onclick="SendMail()"><?php print $langs->trans("SendTicket"); ?></button>
127 
128 </div>
129 
130 </body>
131 </html>
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
Translate
Class to manage translations.
Definition: translate.class.php:30
button
table tableforfield button
Definition: style.css.php:843
top_htmlhead
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1571
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:41
name
$conf db name
Definition: repair.php:122
Facture
Class to manage invoices.
Definition: facture.class.php:60
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8466
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1125
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119